astro-tokenkit 1.0.16 → 1.0.17
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/auth/manager.js +10 -8
- package/dist/client/client.js +8 -4
- package/dist/config.js +4 -1
- package/dist/index.cjs +144 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -4
- package/dist/index.js +144 -85
- package/dist/index.js.map +1 -1
- package/dist/integration.js +2 -1
- package/dist/middleware.cjs +70 -14
- package/dist/middleware.cjs.map +1 -1
- package/dist/middleware.js +70 -14
- package/dist/middleware.js.map +1 -1
- package/dist/types.d.ts +15 -4
- package/dist/types.js +10 -7
- package/dist/utils/fetch.d.ts +5 -0
- package/dist/utils/fetch.js +36 -0
- package/dist/utils/logger.d.ts +9 -0
- package/dist/utils/logger.js +22 -0
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -132,6 +132,10 @@ export interface AuthConfig {
|
|
|
132
132
|
policy?: RefreshPolicy;
|
|
133
133
|
/** Cookie configuration */
|
|
134
134
|
cookies?: CookieConfig;
|
|
135
|
+
/** Custom fetch implementation */
|
|
136
|
+
fetch?: typeof fetch;
|
|
137
|
+
/** Dangerously ignore certificate errors (bypass SSL validation) */
|
|
138
|
+
dangerouslyIgnoreCertificateErrors?: boolean;
|
|
135
139
|
}
|
|
136
140
|
/**
|
|
137
141
|
* Refresh policy
|
|
@@ -214,6 +218,12 @@ export interface ClientConfig {
|
|
|
214
218
|
setContextStore?: (ctx: TokenKitContext) => void;
|
|
215
219
|
/** Custom context runner */
|
|
216
220
|
runWithContext?: <T>(ctx: TokenKitContext, fn: () => T) => T;
|
|
221
|
+
/** Custom fetch implementation */
|
|
222
|
+
fetch?: typeof fetch;
|
|
223
|
+
/** Enable debug logging */
|
|
224
|
+
debug?: boolean;
|
|
225
|
+
/** Dangerously ignore certificate errors (bypass SSL validation) */
|
|
226
|
+
dangerouslyIgnoreCertificateErrors?: boolean;
|
|
217
227
|
}
|
|
218
228
|
/**
|
|
219
229
|
* TokenKit Global Configuration
|
|
@@ -232,23 +242,24 @@ export declare class APIError extends Error {
|
|
|
232
242
|
status?: number | undefined;
|
|
233
243
|
response?: any | undefined;
|
|
234
244
|
request?: RequestConfig | undefined;
|
|
235
|
-
|
|
245
|
+
cause?: any | undefined;
|
|
246
|
+
constructor(message: string, status?: number | undefined, response?: any | undefined, request?: RequestConfig | undefined, cause?: any | undefined);
|
|
236
247
|
}
|
|
237
248
|
/**
|
|
238
249
|
* Authentication Error
|
|
239
250
|
*/
|
|
240
251
|
export declare class AuthError extends APIError {
|
|
241
|
-
constructor(message: string, status?: number, response?: any, request?: RequestConfig);
|
|
252
|
+
constructor(message: string, status?: number, response?: any, request?: RequestConfig, cause?: any);
|
|
242
253
|
}
|
|
243
254
|
/**
|
|
244
255
|
* Network Error
|
|
245
256
|
*/
|
|
246
257
|
export declare class NetworkError extends APIError {
|
|
247
|
-
constructor(message: string, request?: RequestConfig);
|
|
258
|
+
constructor(message: string, request?: RequestConfig, cause?: any);
|
|
248
259
|
}
|
|
249
260
|
/**
|
|
250
261
|
* Timeout Error
|
|
251
262
|
*/
|
|
252
263
|
export declare class TimeoutError extends APIError {
|
|
253
|
-
constructor(message: string, request?: RequestConfig);
|
|
264
|
+
constructor(message: string, request?: RequestConfig, cause?: any);
|
|
254
265
|
}
|
package/dist/types.js
CHANGED
|
@@ -3,20 +3,23 @@
|
|
|
3
3
|
* API Error
|
|
4
4
|
*/
|
|
5
5
|
export class APIError extends Error {
|
|
6
|
-
constructor(message, status, response, request) {
|
|
6
|
+
constructor(message, status, response, request, cause) {
|
|
7
7
|
super(message);
|
|
8
8
|
this.status = status;
|
|
9
9
|
this.response = response;
|
|
10
10
|
this.request = request;
|
|
11
|
+
this.cause = cause;
|
|
11
12
|
this.name = 'APIError';
|
|
13
|
+
if (cause && !this.cause)
|
|
14
|
+
this.cause = cause;
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
17
|
/**
|
|
15
18
|
* Authentication Error
|
|
16
19
|
*/
|
|
17
20
|
export class AuthError extends APIError {
|
|
18
|
-
constructor(message, status, response, request) {
|
|
19
|
-
super(message, status, response, request);
|
|
21
|
+
constructor(message, status, response, request, cause) {
|
|
22
|
+
super(message, status, response, request, cause);
|
|
20
23
|
this.name = 'AuthError';
|
|
21
24
|
}
|
|
22
25
|
}
|
|
@@ -24,8 +27,8 @@ export class AuthError extends APIError {
|
|
|
24
27
|
* Network Error
|
|
25
28
|
*/
|
|
26
29
|
export class NetworkError extends APIError {
|
|
27
|
-
constructor(message, request) {
|
|
28
|
-
super(message, undefined, undefined, request);
|
|
30
|
+
constructor(message, request, cause) {
|
|
31
|
+
super(message, undefined, undefined, request, cause);
|
|
29
32
|
this.name = 'NetworkError';
|
|
30
33
|
}
|
|
31
34
|
}
|
|
@@ -33,8 +36,8 @@ export class NetworkError extends APIError {
|
|
|
33
36
|
* Timeout Error
|
|
34
37
|
*/
|
|
35
38
|
export class TimeoutError extends APIError {
|
|
36
|
-
constructor(message, request) {
|
|
37
|
-
super(message, undefined, undefined, request);
|
|
39
|
+
constructor(message, request, cause) {
|
|
40
|
+
super(message, undefined, undefined, request, cause);
|
|
38
41
|
this.name = 'TimeoutError';
|
|
39
42
|
}
|
|
40
43
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// packages/astro-tokenkit/src/utils/fetch.ts
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Perform a fetch request with optional certificate validation bypass
|
|
13
|
+
*/
|
|
14
|
+
export function safeFetch(url, init, config) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const fetchFn = config.fetch || fetch;
|
|
17
|
+
const fetchOptions = Object.assign({}, init);
|
|
18
|
+
if (config.dangerouslyIgnoreCertificateErrors && typeof process !== 'undefined') {
|
|
19
|
+
// In Node.js environment
|
|
20
|
+
try {
|
|
21
|
+
// Try to use undici Agent if available (it is built-in in Node 18+)
|
|
22
|
+
// However, we might need to import it if we want to create an Agent.
|
|
23
|
+
// Since we don't want to depend on undici in package.json, we use dynamic import.
|
|
24
|
+
// But wait, undici's Agent is what we need.
|
|
25
|
+
// As a fallback and most reliable way for self-signed certs in Node without extra deps:
|
|
26
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
27
|
+
// NOTE: This affects the whole process. We should ideally only do this if it's not already 0.
|
|
28
|
+
// But for a dev tool / specialized library, it's often what's needed.
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
// Ignore
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return fetchFn(url, fetchOptions);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger utility that respects the debug flag in the configuration
|
|
3
|
+
*/
|
|
4
|
+
export declare const logger: {
|
|
5
|
+
debug: (message: string, ...args: any[]) => void;
|
|
6
|
+
info: (message: string, ...args: any[]) => void;
|
|
7
|
+
warn: (message: string, ...args: any[]) => void;
|
|
8
|
+
error: (message: string, ...args: any[]) => void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getConfig } from '../config';
|
|
2
|
+
/**
|
|
3
|
+
* Logger utility that respects the debug flag in the configuration
|
|
4
|
+
*/
|
|
5
|
+
export const logger = {
|
|
6
|
+
debug: (message, ...args) => {
|
|
7
|
+
if (getConfig().debug) {
|
|
8
|
+
console.debug(message, ...args);
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
info: (message, ...args) => {
|
|
12
|
+
if (getConfig().debug) {
|
|
13
|
+
console.log(message, ...args);
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
warn: (message, ...args) => {
|
|
17
|
+
console.warn(message, ...args);
|
|
18
|
+
},
|
|
19
|
+
error: (message, ...args) => {
|
|
20
|
+
console.error(message, ...args);
|
|
21
|
+
}
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-tokenkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "A powerful API client for Astro with automatic token rotation, session management, and seamless context integration.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|