Skip to content

Commit 6309412

Browse files
committed
support configuring a header interceptor (web)
and avoid using `useOptions` for legacy web-apps
1 parent c328295 commit 6309412

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"generate.spec.node": "./node_modules/.bin/openapi --input openapi.yaml --output ./src/api --useOptions --useUnionTypes --client node",
9-
"generate.spec.browser": "./node_modules/.bin/openapi --input openapi.yaml --output ./src/api --useOptions --useUnionTypes --client xhr",
9+
"generate.spec.browser": "./node_modules/.bin/openapi --input openapi.yaml --output ./src/api --useUnionTypes --client xhr",
1010
"webpack": "npm run generate.spec.browser && npx webpack --mode=development && npx webpack --mode=production && npm run generate.spec.node"
1111
},
1212
"keywords": [],

src/sideload.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Docupilot from './docupilot';
22

33
import * as _API from './api';
4+
import { ApiRequestOptions } from './api/core/ApiRequestOptions';
45

56
class _Docupilot extends Docupilot {
67
readonly AuthTokensService = _API.AuthTokensService;
@@ -15,6 +16,13 @@ class _Docupilot extends Docupilot {
1516
readonly TemplateDeliveryService = _API.TemplateDeliveryService;
1617
readonly TemplatesService = _API.TemplatesService;
1718
readonly UsersService = _API.UsersService;
19+
20+
configureHeadersInterceptor(getHeaders: () => Record<string, string>) {
21+
_API.OpenAPI.HEADERS = async (options: ApiRequestOptions) => {
22+
const headers = getHeaders();
23+
return Object.assign({}, options.headers || {}, headers);
24+
};
25+
}
1826
}
1927

2028
export const client = new _Docupilot();

0 commit comments

Comments
 (0)