@sebspark/openapi-client 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ module.exports = __toCommonJS(index_exports);
39
39
  var import_openapi_core = require("@sebspark/openapi-core");
40
40
  var import_retry = require("@sebspark/retry");
41
41
  var import_axios = __toESM(require("axios"));
42
+ var import_axios_auth_refresh = __toESM(require("axios-auth-refresh"));
42
43
 
43
44
  // src/paramsSerializer.ts
44
45
  var encodeParam = (param) => encodeURIComponent(param);
@@ -92,6 +93,34 @@ var paramsSerializer = (format) => (params) => {
92
93
 
93
94
  // src/client.ts
94
95
  var TypedClient = (baseURL, globalOptions, logger) => {
96
+ if (globalOptions?.authorizationTokenGenerator) {
97
+ import_axios.default.interceptors.request.use(async (request) => {
98
+ if (globalOptions?.authorizationTokenGenerator) {
99
+ const authorizationTokenHeaders = await globalOptions.authorizationTokenGenerator(request.url);
100
+ if (authorizationTokenHeaders) {
101
+ for (const [key, value] of Object.entries(
102
+ authorizationTokenHeaders
103
+ )) {
104
+ request.headers.set(key, value);
105
+ }
106
+ }
107
+ }
108
+ return request;
109
+ });
110
+ }
111
+ if (globalOptions?.authorizationTokenRefresh) {
112
+ const refreshAuthLogic = async (failedRequest) => {
113
+ if (!import_axios.default.isAxiosError(failedRequest)) {
114
+ return;
115
+ }
116
+ const axiosError = failedRequest;
117
+ const url = `${axiosError.config?.baseURL}${axiosError.config?.url}`;
118
+ if (globalOptions?.authorizationTokenRefresh && url) {
119
+ await globalOptions?.authorizationTokenRefresh(axiosError.request.url);
120
+ }
121
+ };
122
+ (0, import_axios_auth_refresh.default)(import_axios.default, refreshAuthLogic);
123
+ }
95
124
  if (logger) {
96
125
  import_axios.default.interceptors.request.use((request) => {
97
126
  const requestObject = {
package/dist/index.mjs CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  } from "@sebspark/openapi-core";
5
5
  import { retry } from "@sebspark/retry";
6
6
  import axios from "axios";
7
+ import createAuthRefreshInterceptor from "axios-auth-refresh";
7
8
 
8
9
  // src/paramsSerializer.ts
9
10
  var encodeParam = (param) => encodeURIComponent(param);
@@ -57,6 +58,34 @@ var paramsSerializer = (format) => (params) => {
57
58
 
58
59
  // src/client.ts
59
60
  var TypedClient = (baseURL, globalOptions, logger) => {
61
+ if (globalOptions?.authorizationTokenGenerator) {
62
+ axios.interceptors.request.use(async (request) => {
63
+ if (globalOptions?.authorizationTokenGenerator) {
64
+ const authorizationTokenHeaders = await globalOptions.authorizationTokenGenerator(request.url);
65
+ if (authorizationTokenHeaders) {
66
+ for (const [key, value] of Object.entries(
67
+ authorizationTokenHeaders
68
+ )) {
69
+ request.headers.set(key, value);
70
+ }
71
+ }
72
+ }
73
+ return request;
74
+ });
75
+ }
76
+ if (globalOptions?.authorizationTokenRefresh) {
77
+ const refreshAuthLogic = async (failedRequest) => {
78
+ if (!axios.isAxiosError(failedRequest)) {
79
+ return;
80
+ }
81
+ const axiosError = failedRequest;
82
+ const url = `${axiosError.config?.baseURL}${axiosError.config?.url}`;
83
+ if (globalOptions?.authorizationTokenRefresh && url) {
84
+ await globalOptions?.authorizationTokenRefresh(axiosError.request.url);
85
+ }
86
+ };
87
+ createAuthRefreshInterceptor(axios, refreshAuthLogic);
88
+ }
60
89
  if (logger) {
61
90
  axios.interceptors.request.use((request) => {
62
91
  const requestObject = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/openapi-client",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -19,11 +19,14 @@
19
19
  },
20
20
  "devDependencies": {
21
21
  "@sebspark/openapi-typegen": "*",
22
- "tsconfig": "*"
22
+ "nock": "14.0.1",
23
+ "tsconfig": "*",
24
+ "vitest": "^3.0.7"
23
25
  },
24
26
  "dependencies": {
25
27
  "@sebspark/openapi-core": "*",
26
28
  "@sebspark/retry": "*",
27
- "axios": "1.7.9"
29
+ "axios": "1.8.1",
30
+ "axios-auth-refresh": "3.3.6"
28
31
  }
29
32
  }