You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+83-14
Original file line number
Diff line number
Diff line change
@@ -100,17 +100,28 @@ import express from "express";
100
100
101
101
const app =express();
102
102
103
-
// Configure a speakeasy SDK instance
104
-
const cfg:Config= {
105
-
apiKey: "YOUR API KEY HERE", // retrieve from Speakeasy API dashboard.
106
-
apiID: "YOUR API ID HERE", // custom Api ID to associate captured requests with.
107
-
versionID: "YOUR VERSION ID HERE", // custom Version ID to associate captured requests
108
-
port: 3000, // The port number your express app is listening on (required to build full URLs on non-standard ports)
109
-
};
110
-
const sdk =newSpeakeasySDK(cfg);
103
+
// Configure a new instance of the SDK for the store API
104
+
const storeSDK =newSpeakeasySDK({
105
+
apiKey: "YOUR API KEY HERE", // retrieved from Speakeasy API dashboard.
106
+
apiID: "store_api", // this is an ID you provide that you would like to associate captured requests with.
107
+
versionID: "1.0.0", // this is a Version you provide that you would like to associate captured requests with.
108
+
port: 3000, // The port number your express app is listening on (required to build full URLs on non-standard ports)
109
+
});
110
+
111
+
// Configure a new instance of the SDK for the product AP
112
+
const productSDK =newSpeakeasySDK({
113
+
apiKey: "YOUR API KEY HERE", // retrieved from Speakeasy API dashboard.
114
+
apiID: "product_api", // this is an ID you provide that you would like to associate captured requests with.
115
+
versionID: "1.0.0", // this is a Version you provide that you would like to associate captured requests with.
116
+
port: 3000, // The port number your express app is listening on (required to build full URLs on non-standard ports)
117
+
});
111
118
112
-
// Add the speakeasy middleware to your express app/router
113
-
app.use(sdk.expressMiddleware());
119
+
// The different instances of the SDK (with differnt IDs or even versions assigned) can be used to associate requests with different APIs and Versions.
@@ -252,9 +263,7 @@ Create a file called `expressmonkeypatch.ts` or similar and import it into your
252
263
253
264
## Capturing Customer IDs
254
265
255
-
To help associate requests with customers/users of your APIs you can provide a customer ID per request handler:
256
-
257
-
266
+
To help associate requests with customers/users of your APIs you can provide a customer ID per request handler:
258
267
259
268
```typescript
260
269
const app =express();
@@ -267,4 +276,64 @@ app.all("/", (req, res) => {
267
276
});
268
277
```
269
278
270
-
Note: This is not required, but is highly recommended. By setting a customer ID you can easily associate requests with your customers/users in the Speakeasy Dashboard, powering filters in the [Request Viewer](https://docs.speakeasyapi.dev/speakeasy-user-guide/request-viewer-coming-soon).
279
+
Note: This is not required, but is highly recommended. By setting a customer ID you can easily associate requests with your customers/users in the Speakeasy Dashboard, powering filters in the [Request Viewer](https://docs.speakeasyapi.dev/speakeasy-user-guide/request-viewer-coming-soon).
280
+
281
+
## Masking sensitive data
282
+
283
+
Speakeasy can mask sensitive data in the query string parameters, headers, cookies and request/response bodies captured by the SDK. This is useful for maintaining sensitive data isolation, and retaining control over the data that is captured.
284
+
285
+
Using the `Advanced Configuration` section above you can completely ignore certain routes by not assigning the middleware to their router, causing the SDK to not capture any requests to that router.
286
+
287
+
But if you would like to be more selective you can mask certain sensitive data using our middleware controller allowing you to mask fields as needed in different handlers:
ctrl.setMaskingOpts(Masking.withRequestHeaderMask("authorization")) // Mask the authorization header in the request
297
+
298
+
// the rest of your handlers code
299
+
}
300
+
```
301
+
302
+
The `Masking` function takes a number of different options to mask sensitive data in the request:
303
+
304
+
* `Masking.withQueryStringMask` - **withQueryStringMask** will mask the specified query strings with an optional mask string.
305
+
* `Masking.withRequestHeaderMask` - **withRequestHeaderMask** will mask the specified request headers with an optional mask string.
306
+
* `Masking.withResponseHeaderMask` - **withResponseHeaderMask** will mask the specified response headers with an optional mask string.
307
+
* `Masking.withRequestCookieMask` - **withRequestCookieMask** will mask the specified request cookies with an optional mask string.
308
+
* `Masking.withResponseCookieMask` - **withResponseCookieMask** will mask the specified response cookies with an optional mask string.
309
+
* `Masking.withRequestFieldMaskString` - **withRequestFieldMaskString** will mask the specified request body fields with an optional mask. Supports string fields only. Matches using regex.
310
+
* `Masking.withRequestFieldMaskNumber` - **withRequestFieldMaskNumber** will mask the specified request body fields with an optional mask. Supports number fields only. Matches using regex.
311
+
* `Masking.withResponseFieldMaskString` - **withResponseFieldMaskString** will mask the specified response body fields with an optional mask. Supports string fields only. Matches using regex.
312
+
* `Masking.withResponseFieldMaskNumber` - **withResponseFieldMaskNumber** will mask the specified response body fields with an optional mask. Supports number fields only. Matches using regex.
313
+
314
+
Masking can also be done more globally on all routes or a selection of routes by taking advantage of middleware. Here is an example:
0 commit comments