axiam-sdk 1.0.0-alpha19 → 1.0.0-alpha21
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/README.md +155 -4
- package/dist/amqp/index.d.cts +1 -1
- package/dist/amqp/index.d.ts +1 -1
- package/dist/amqp/index.js +4 -0
- package/dist/amqp/index.js.map +1 -1
- package/dist/amqp/index.mjs +4 -0
- package/dist/amqp/index.mjs.map +1 -1
- package/dist/{authzCore-CcTdIf78.d.ts → authzCore-DtSN59if.d.ts} +2 -2
- package/dist/{authzCore-B7GSd3-t.d.cts → authzCore-DuRI1aJf.d.cts} +2 -2
- package/dist/client-B_FqmZ0i.d.cts +72 -0
- package/dist/client-Dn1fs5MH.d.ts +72 -0
- package/dist/cookieJar-BTDnjjbL.d.cts +122 -0
- package/dist/cookieJar-Cl8Lq9dL.d.ts +122 -0
- package/dist/grpc/index.d.cts +6 -5
- package/dist/grpc/index.d.ts +6 -5
- package/dist/grpc/index.js +178 -4
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +178 -4
- package/dist/grpc/index.mjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +76 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -4
- package/dist/index.mjs.map +1 -1
- package/dist/jwks-BgojMGC5.d.cts +152 -0
- package/dist/jwks-BgojMGC5.d.ts +152 -0
- package/dist/middleware/index.d.cts +194 -4
- package/dist/middleware/index.d.ts +194 -4
- package/dist/middleware/index.js +1107 -1
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs +1100 -3
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/nestjs/index.d.cts +2 -2
- package/dist/nestjs/index.d.ts +2 -2
- package/dist/nestjs/index.js +3 -0
- package/dist/nestjs/index.js.map +1 -1
- package/dist/nestjs/index.mjs +3 -0
- package/dist/nestjs/index.mjs.map +1 -1
- package/dist/node/index.d.cts +50 -113
- package/dist/node/index.d.ts +50 -113
- package/dist/node/index.js +873 -4
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +857 -5
- package/dist/node/index.mjs.map +1 -1
- package/dist/oidcState-BGxqWUun.d.cts +598 -0
- package/dist/oidcState-CkFuCjpM.d.ts +598 -0
- package/dist/rest/index.d.cts +107 -5
- package/dist/rest/index.d.ts +107 -5
- package/dist/rest/index.js +76 -3
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +71 -4
- package/dist/rest/index.mjs.map +1 -1
- package/dist/sensitive-BC_s7Rrd.d.cts +39 -0
- package/dist/sensitive-BC_s7Rrd.d.ts +39 -0
- package/dist/{client-Co_baHgU.d.ts → session-BWUWhhyB.d.cts} +1 -70
- package/dist/{client-CzhzwRGg.d.cts → session-BWUWhhyB.d.ts} +1 -70
- package/package.json +2 -2
- package/dist/jwks-B8dPy2c6.d.cts +0 -36
- package/dist/jwks-B8dPy2c6.d.ts +0 -36
- package/dist/sensitive-CWBH_tHr.d.cts +0 -12
- package/dist/sensitive-CWBH_tHr.d.ts +0 -12
package/dist/rest/index.d.cts
CHANGED
|
@@ -1,11 +1,113 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { A as AxiamClient } from '../client-B_FqmZ0i.cjs';
|
|
2
|
+
export { A as AxiamClientOptions, S as SharedSession } from '../session-BWUWhhyB.cjs';
|
|
2
3
|
export { A as AccessCheck, a as AccessDecision, b as AxiamUserInfo, L as LoginResult } from '../types-BVkMoqLU.cjs';
|
|
4
|
+
export { S as Sensitive } from '../sensitive-BC_s7Rrd.cjs';
|
|
3
5
|
import 'axios';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
8
|
+
* Base class of every error this SDK throws (CONTRACT.md §2).
|
|
9
|
+
*
|
|
10
|
+
* Catch this to handle any AXIAM failure uniformly; catch one of the three
|
|
11
|
+
* concrete subclasses — {@link AuthError}, {@link AuthzError},
|
|
12
|
+
* {@link NetworkError} — to distinguish authentication, authorization and
|
|
13
|
+
* transport failures.
|
|
14
|
+
*/
|
|
15
|
+
declare abstract class AxiamError extends Error {
|
|
16
|
+
protected constructor(message: string);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Authentication failure (CONTRACT.md §2): wrong credentials, an expired
|
|
20
|
+
* session, a failed MFA challenge, a `401` on refresh, or a failed ID-token
|
|
21
|
+
* validation.
|
|
22
|
+
*/
|
|
23
|
+
declare class AuthError extends AxiamError {
|
|
24
|
+
/**
|
|
25
|
+
* Optional stable, machine-readable reason code for the failure.
|
|
26
|
+
*
|
|
27
|
+
* Populated by the CONTRACT.md §12.4 ID-token validation checklist with
|
|
28
|
+
* one of the seven codes §12.3 rule 3 enumerates (see
|
|
29
|
+
* {@link IdTokenFailureReason}); `undefined` for every other `AuthError`.
|
|
30
|
+
* It is a *code*, never free text, so callers can branch on it without
|
|
31
|
+
* parsing `message`.
|
|
32
|
+
*/
|
|
33
|
+
readonly reason?: string;
|
|
34
|
+
constructor(message: string, reason?: string);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The seven stable reason codes CONTRACT.md §12.3 rule 3 defines for
|
|
38
|
+
* ID-token validation failures, one per §12.4 rule. Surfaced on
|
|
39
|
+
* {@link AuthError.reason}.
|
|
40
|
+
*/
|
|
41
|
+
type IdTokenFailureReason = 'invalid_alg' | 'unknown_kid' | 'invalid_signature' | 'invalid_issuer' | 'invalid_audience' | 'token_expired' | 'nonce_mismatch';
|
|
42
|
+
/**
|
|
43
|
+
* An RFC 6749 protocol error returned by an `/oauth2/*` endpoint as an
|
|
44
|
+
* `OAuth2ErrorResponse` body (CONTRACT.md §2 sub-type table, §12.3 rule 3).
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* A **sub-type of {@link AuthError}**, not a replacement for it: existing
|
|
48
|
+
* `catch (e) { if (e instanceof AuthError) … }` code keeps working unchanged.
|
|
49
|
+
* Raised for a `400` from `POST /oauth2/token` (e.g. `invalid_grant`) and for
|
|
50
|
+
* a `401` from `POST /oauth2/introspect` / `POST /oauth2/revoke` (client
|
|
51
|
+
* authentication failed) — neither of which may collapse into the generic
|
|
52
|
+
* §2 `400 → NetworkError` / `401 → AuthError` rows.
|
|
53
|
+
*
|
|
54
|
+
* `message` is always exactly `"<error>: <error_description>"`, built from
|
|
55
|
+
* the two wire fields, which are also exposed individually.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* try {
|
|
60
|
+
* await oidc.oidcExchange({ code, codeVerifier, nonce, redirectUri });
|
|
61
|
+
* } catch (err) {
|
|
62
|
+
* if (err instanceof OAuthProtocolError && err.error === 'invalid_grant') {
|
|
63
|
+
* // the authorization code was replayed, expired, or bound to another client
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
declare class OAuthProtocolError extends AuthError {
|
|
69
|
+
/** The RFC 6749 `error` code (e.g. `"invalid_grant"`, `"invalid_client"`, `"unsupported_grant_type"`). */
|
|
70
|
+
readonly error: string;
|
|
71
|
+
/** The server's human-readable `error_description`. Never contains token material. */
|
|
72
|
+
readonly errorDescription: string;
|
|
73
|
+
constructor(error: string, errorDescription: string);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Authorization failure (CONTRACT.md §2): the caller is authenticated but
|
|
77
|
+
* lacks permission for the requested operation (`403`, or `409` for a
|
|
78
|
+
* resource-level denial).
|
|
79
|
+
*/
|
|
80
|
+
declare class AuthzError extends AxiamError {
|
|
81
|
+
/** The denied action, when the server reported it. */
|
|
82
|
+
readonly action?: string;
|
|
83
|
+
/** The resource the denied action targeted, when the server reported it. */
|
|
84
|
+
readonly resourceId?: string;
|
|
85
|
+
constructor(message: string, action?: string, resourceId?: string);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Transport-level failure (CONTRACT.md §2): connection refused, timeout, TLS
|
|
89
|
+
* or DNS error, a malformed request (`400`), rate limiting (`429`), or a `5xx`
|
|
90
|
+
* server error.
|
|
91
|
+
*/
|
|
92
|
+
declare class NetworkError extends AxiamError {
|
|
93
|
+
/** The underlying transport error, with every non-allowlisted response header redacted (§2, X-3). */
|
|
94
|
+
readonly cause?: unknown;
|
|
95
|
+
constructor(message: string, cause?: unknown);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Endpoints that must never trigger a silent refresh (§9.3, §12.3 rule 3).
|
|
100
|
+
*
|
|
101
|
+
* Two groups:
|
|
102
|
+
* - the refresh endpoint itself plus login/logout — not
|
|
103
|
+
* authenticated-session-continuation calls, so refreshing would only build
|
|
104
|
+
* an infinite loop;
|
|
105
|
+
* - the `/oauth2/*` endpoints — they authenticate the *client* with
|
|
106
|
+
* `client_id`/`client_secret`, not the user session. A `401` there is a
|
|
107
|
+
* client-credential failure, not a session expiry, so retrying after a
|
|
108
|
+
* session refresh cannot help and MUST NOT enter the §9 guard
|
|
109
|
+
* (CONTRACT.md §12.3 rule 3). `oidcRefresh` reaches the §9 guard through
|
|
110
|
+
* its own explicit call path instead (`OidcClient.oidcRefresh`).
|
|
9
111
|
*/
|
|
10
112
|
declare const SKIP_REFRESH: string[];
|
|
11
113
|
|
|
@@ -25,4 +127,4 @@ interface RetryOptions {
|
|
|
25
127
|
*/
|
|
26
128
|
declare function withRetry<T>(fn: () => Promise<T>, options: RetryOptions): Promise<T>;
|
|
27
129
|
|
|
28
|
-
export { type RetryOptions, SKIP_REFRESH, withRetry };
|
|
130
|
+
export { AuthError, AuthzError, AxiamError, type IdTokenFailureReason, NetworkError, OAuthProtocolError, type RetryOptions, SKIP_REFRESH, withRetry };
|
package/dist/rest/index.d.ts
CHANGED
|
@@ -1,11 +1,113 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { A as AxiamClient } from '../client-Dn1fs5MH.js';
|
|
2
|
+
export { A as AxiamClientOptions, S as SharedSession } from '../session-BWUWhhyB.js';
|
|
2
3
|
export { A as AccessCheck, a as AccessDecision, b as AxiamUserInfo, L as LoginResult } from '../types-BVkMoqLU.js';
|
|
4
|
+
export { S as Sensitive } from '../sensitive-BC_s7Rrd.js';
|
|
3
5
|
import 'axios';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
8
|
+
* Base class of every error this SDK throws (CONTRACT.md §2).
|
|
9
|
+
*
|
|
10
|
+
* Catch this to handle any AXIAM failure uniformly; catch one of the three
|
|
11
|
+
* concrete subclasses — {@link AuthError}, {@link AuthzError},
|
|
12
|
+
* {@link NetworkError} — to distinguish authentication, authorization and
|
|
13
|
+
* transport failures.
|
|
14
|
+
*/
|
|
15
|
+
declare abstract class AxiamError extends Error {
|
|
16
|
+
protected constructor(message: string);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Authentication failure (CONTRACT.md §2): wrong credentials, an expired
|
|
20
|
+
* session, a failed MFA challenge, a `401` on refresh, or a failed ID-token
|
|
21
|
+
* validation.
|
|
22
|
+
*/
|
|
23
|
+
declare class AuthError extends AxiamError {
|
|
24
|
+
/**
|
|
25
|
+
* Optional stable, machine-readable reason code for the failure.
|
|
26
|
+
*
|
|
27
|
+
* Populated by the CONTRACT.md §12.4 ID-token validation checklist with
|
|
28
|
+
* one of the seven codes §12.3 rule 3 enumerates (see
|
|
29
|
+
* {@link IdTokenFailureReason}); `undefined` for every other `AuthError`.
|
|
30
|
+
* It is a *code*, never free text, so callers can branch on it without
|
|
31
|
+
* parsing `message`.
|
|
32
|
+
*/
|
|
33
|
+
readonly reason?: string;
|
|
34
|
+
constructor(message: string, reason?: string);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The seven stable reason codes CONTRACT.md §12.3 rule 3 defines for
|
|
38
|
+
* ID-token validation failures, one per §12.4 rule. Surfaced on
|
|
39
|
+
* {@link AuthError.reason}.
|
|
40
|
+
*/
|
|
41
|
+
type IdTokenFailureReason = 'invalid_alg' | 'unknown_kid' | 'invalid_signature' | 'invalid_issuer' | 'invalid_audience' | 'token_expired' | 'nonce_mismatch';
|
|
42
|
+
/**
|
|
43
|
+
* An RFC 6749 protocol error returned by an `/oauth2/*` endpoint as an
|
|
44
|
+
* `OAuth2ErrorResponse` body (CONTRACT.md §2 sub-type table, §12.3 rule 3).
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* A **sub-type of {@link AuthError}**, not a replacement for it: existing
|
|
48
|
+
* `catch (e) { if (e instanceof AuthError) … }` code keeps working unchanged.
|
|
49
|
+
* Raised for a `400` from `POST /oauth2/token` (e.g. `invalid_grant`) and for
|
|
50
|
+
* a `401` from `POST /oauth2/introspect` / `POST /oauth2/revoke` (client
|
|
51
|
+
* authentication failed) — neither of which may collapse into the generic
|
|
52
|
+
* §2 `400 → NetworkError` / `401 → AuthError` rows.
|
|
53
|
+
*
|
|
54
|
+
* `message` is always exactly `"<error>: <error_description>"`, built from
|
|
55
|
+
* the two wire fields, which are also exposed individually.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* try {
|
|
60
|
+
* await oidc.oidcExchange({ code, codeVerifier, nonce, redirectUri });
|
|
61
|
+
* } catch (err) {
|
|
62
|
+
* if (err instanceof OAuthProtocolError && err.error === 'invalid_grant') {
|
|
63
|
+
* // the authorization code was replayed, expired, or bound to another client
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
declare class OAuthProtocolError extends AuthError {
|
|
69
|
+
/** The RFC 6749 `error` code (e.g. `"invalid_grant"`, `"invalid_client"`, `"unsupported_grant_type"`). */
|
|
70
|
+
readonly error: string;
|
|
71
|
+
/** The server's human-readable `error_description`. Never contains token material. */
|
|
72
|
+
readonly errorDescription: string;
|
|
73
|
+
constructor(error: string, errorDescription: string);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Authorization failure (CONTRACT.md §2): the caller is authenticated but
|
|
77
|
+
* lacks permission for the requested operation (`403`, or `409` for a
|
|
78
|
+
* resource-level denial).
|
|
79
|
+
*/
|
|
80
|
+
declare class AuthzError extends AxiamError {
|
|
81
|
+
/** The denied action, when the server reported it. */
|
|
82
|
+
readonly action?: string;
|
|
83
|
+
/** The resource the denied action targeted, when the server reported it. */
|
|
84
|
+
readonly resourceId?: string;
|
|
85
|
+
constructor(message: string, action?: string, resourceId?: string);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Transport-level failure (CONTRACT.md §2): connection refused, timeout, TLS
|
|
89
|
+
* or DNS error, a malformed request (`400`), rate limiting (`429`), or a `5xx`
|
|
90
|
+
* server error.
|
|
91
|
+
*/
|
|
92
|
+
declare class NetworkError extends AxiamError {
|
|
93
|
+
/** The underlying transport error, with every non-allowlisted response header redacted (§2, X-3). */
|
|
94
|
+
readonly cause?: unknown;
|
|
95
|
+
constructor(message: string, cause?: unknown);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Endpoints that must never trigger a silent refresh (§9.3, §12.3 rule 3).
|
|
100
|
+
*
|
|
101
|
+
* Two groups:
|
|
102
|
+
* - the refresh endpoint itself plus login/logout — not
|
|
103
|
+
* authenticated-session-continuation calls, so refreshing would only build
|
|
104
|
+
* an infinite loop;
|
|
105
|
+
* - the `/oauth2/*` endpoints — they authenticate the *client* with
|
|
106
|
+
* `client_id`/`client_secret`, not the user session. A `401` there is a
|
|
107
|
+
* client-credential failure, not a session expiry, so retrying after a
|
|
108
|
+
* session refresh cannot help and MUST NOT enter the §9 guard
|
|
109
|
+
* (CONTRACT.md §12.3 rule 3). `oidcRefresh` reaches the §9 guard through
|
|
110
|
+
* its own explicit call path instead (`OidcClient.oidcRefresh`).
|
|
9
111
|
*/
|
|
10
112
|
declare const SKIP_REFRESH: string[];
|
|
11
113
|
|
|
@@ -25,4 +127,4 @@ interface RetryOptions {
|
|
|
25
127
|
*/
|
|
26
128
|
declare function withRetry<T>(fn: () => Promise<T>, options: RetryOptions): Promise<T>;
|
|
27
129
|
|
|
28
|
-
export { type RetryOptions, SKIP_REFRESH, withRetry };
|
|
130
|
+
export { AuthError, AuthzError, AxiamError, type IdTokenFailureReason, NetworkError, OAuthProtocolError, type RetryOptions, SKIP_REFRESH, withRetry };
|
package/dist/rest/index.js
CHANGED
|
@@ -21,14 +21,40 @@ var AxiamError = class extends Error {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
var AuthError = class _AuthError extends AxiamError {
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Optional stable, machine-readable reason code for the failure.
|
|
26
|
+
*
|
|
27
|
+
* Populated by the CONTRACT.md §12.4 ID-token validation checklist with
|
|
28
|
+
* one of the seven codes §12.3 rule 3 enumerates (see
|
|
29
|
+
* {@link IdTokenFailureReason}); `undefined` for every other `AuthError`.
|
|
30
|
+
* It is a *code*, never free text, so callers can branch on it without
|
|
31
|
+
* parsing `message`.
|
|
32
|
+
*/
|
|
33
|
+
reason;
|
|
34
|
+
constructor(message, reason) {
|
|
25
35
|
super(message);
|
|
26
36
|
this.name = "AuthError";
|
|
37
|
+
this.reason = reason;
|
|
27
38
|
Object.setPrototypeOf(this, _AuthError.prototype);
|
|
28
39
|
}
|
|
29
40
|
};
|
|
41
|
+
var OAuthProtocolError = class _OAuthProtocolError extends AuthError {
|
|
42
|
+
/** The RFC 6749 `error` code (e.g. `"invalid_grant"`, `"invalid_client"`, `"unsupported_grant_type"`). */
|
|
43
|
+
error;
|
|
44
|
+
/** The server's human-readable `error_description`. Never contains token material. */
|
|
45
|
+
errorDescription;
|
|
46
|
+
constructor(error, errorDescription) {
|
|
47
|
+
super(`${error}: ${errorDescription}`);
|
|
48
|
+
this.name = "OAuthProtocolError";
|
|
49
|
+
this.error = error;
|
|
50
|
+
this.errorDescription = errorDescription;
|
|
51
|
+
Object.setPrototypeOf(this, _OAuthProtocolError.prototype);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
30
54
|
var AuthzError = class _AuthzError extends AxiamError {
|
|
55
|
+
/** The denied action, when the server reported it. */
|
|
31
56
|
action;
|
|
57
|
+
/** The resource the denied action targeted, when the server reported it. */
|
|
32
58
|
resourceId;
|
|
33
59
|
constructor(message, action, resourceId) {
|
|
34
60
|
super(message);
|
|
@@ -39,6 +65,7 @@ var AuthzError = class _AuthzError extends AxiamError {
|
|
|
39
65
|
}
|
|
40
66
|
};
|
|
41
67
|
var NetworkError = class _NetworkError extends AxiamError {
|
|
68
|
+
/** The underlying transport error, with every non-allowlisted response header redacted (§2, X-3). */
|
|
42
69
|
cause;
|
|
43
70
|
constructor(message, cause) {
|
|
44
71
|
super(message);
|
|
@@ -58,6 +85,24 @@ function extractAuthzFieldsFromBody(body) {
|
|
|
58
85
|
const resourceId = typeof record.resource_id === "string" ? record.resource_id : void 0;
|
|
59
86
|
return { action, resourceId };
|
|
60
87
|
}
|
|
88
|
+
var OAUTH2_PATH_PREFIX = "/oauth2/";
|
|
89
|
+
function isOAuth2EndpointUrl(url) {
|
|
90
|
+
if (!url) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
return new URL(url).pathname.startsWith(OAUTH2_PATH_PREFIX);
|
|
95
|
+
} catch {
|
|
96
|
+
return url.startsWith(OAUTH2_PATH_PREFIX) || url.includes(OAUTH2_PATH_PREFIX);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function isOAuth2ErrorBody(body) {
|
|
100
|
+
if (body === null || typeof body !== "object") {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const record = body;
|
|
104
|
+
return typeof record.error === "string" && typeof record.error_description === "string";
|
|
105
|
+
}
|
|
61
106
|
var SAFE_RESPONSE_HEADERS = /* @__PURE__ */ new Set([
|
|
62
107
|
"content-type",
|
|
63
108
|
"content-length",
|
|
@@ -95,6 +140,9 @@ function sanitizeAxiosError(err) {
|
|
|
95
140
|
};
|
|
96
141
|
}
|
|
97
142
|
function mapHttpStatusToError(status, message, ctx) {
|
|
143
|
+
if ((status === 400 || status === 401) && isOAuth2EndpointUrl(ctx?.url) && isOAuth2ErrorBody(ctx?.body)) {
|
|
144
|
+
return new OAuthProtocolError(ctx.body.error, ctx.body.error_description);
|
|
145
|
+
}
|
|
98
146
|
if (status === 401) {
|
|
99
147
|
return new AuthError(message);
|
|
100
148
|
}
|
|
@@ -110,6 +158,7 @@ var REDACTED = "[SENSITIVE]";
|
|
|
110
158
|
var NODE_INSPECT_CUSTOM = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
111
159
|
var Sensitive = class {
|
|
112
160
|
#value;
|
|
161
|
+
/** Wrap `value` so it can never be logged or serialized by accident. */
|
|
113
162
|
constructor(value) {
|
|
114
163
|
this.#value = value;
|
|
115
164
|
}
|
|
@@ -117,12 +166,15 @@ var Sensitive = class {
|
|
|
117
166
|
expose() {
|
|
118
167
|
return this.#value;
|
|
119
168
|
}
|
|
169
|
+
/** Returns the `"[SENSITIVE]"` placeholder — never the wrapped value. */
|
|
120
170
|
toString() {
|
|
121
171
|
return REDACTED;
|
|
122
172
|
}
|
|
173
|
+
/** Makes `JSON.stringify()` emit the `"[SENSITIVE]"` placeholder. */
|
|
123
174
|
toJSON() {
|
|
124
175
|
return REDACTED;
|
|
125
176
|
}
|
|
177
|
+
/** Makes `console.log`/`util.inspect` print the `"[SENSITIVE]"` placeholder. */
|
|
126
178
|
[NODE_INSPECT_CUSTOM]() {
|
|
127
179
|
return REDACTED;
|
|
128
180
|
}
|
|
@@ -372,7 +424,14 @@ function createSession(options) {
|
|
|
372
424
|
}
|
|
373
425
|
|
|
374
426
|
// src/rest/interceptors.ts
|
|
375
|
-
var SKIP_REFRESH = [
|
|
427
|
+
var SKIP_REFRESH = [
|
|
428
|
+
"/api/v1/auth/refresh",
|
|
429
|
+
"/api/v1/auth/login",
|
|
430
|
+
"/api/v1/auth/logout",
|
|
431
|
+
"/oauth2/token",
|
|
432
|
+
"/oauth2/introspect",
|
|
433
|
+
"/oauth2/revoke"
|
|
434
|
+
];
|
|
376
435
|
function installCsrfInterceptor(axiosInstance, session) {
|
|
377
436
|
axiosInstance.interceptors.request.use((config) => {
|
|
378
437
|
if (session.isForeignHost(config.url)) {
|
|
@@ -404,6 +463,7 @@ function installRefreshInterceptor(axiosInstance, session) {
|
|
|
404
463
|
try {
|
|
405
464
|
await session.refreshGuard(async () => {
|
|
406
465
|
await session.axios.post("/api/v1/auth/refresh", session.buildRefreshBody());
|
|
466
|
+
await session.onAuthenticated?.();
|
|
407
467
|
});
|
|
408
468
|
return axiosInstance(originalRequest);
|
|
409
469
|
} catch (refreshError) {
|
|
@@ -417,7 +477,13 @@ function installRefreshInterceptor(axiosInstance, session) {
|
|
|
417
477
|
}
|
|
418
478
|
}
|
|
419
479
|
if (status === 401 && isSkipRefresh) {
|
|
420
|
-
return Promise.reject(
|
|
480
|
+
return Promise.reject(
|
|
481
|
+
mapHttpStatusToError(401, "authentication failed", {
|
|
482
|
+
url,
|
|
483
|
+
body: error.response.data,
|
|
484
|
+
cause: error
|
|
485
|
+
})
|
|
486
|
+
);
|
|
421
487
|
}
|
|
422
488
|
return Promise.reject(error);
|
|
423
489
|
}
|
|
@@ -497,6 +563,7 @@ async function verifyMfa(client, mfaToken, code) {
|
|
|
497
563
|
async function refresh(client) {
|
|
498
564
|
try {
|
|
499
565
|
await client.session.axios.post(REFRESH_PATH, client.session.buildRefreshBody());
|
|
566
|
+
await client.session.onAuthenticated?.();
|
|
500
567
|
} catch (err) {
|
|
501
568
|
const status = extractAxiosStatus(err);
|
|
502
569
|
if (status !== void 0) {
|
|
@@ -676,8 +743,14 @@ async function withRetry(fn, options) {
|
|
|
676
743
|
throw lastError;
|
|
677
744
|
}
|
|
678
745
|
|
|
746
|
+
exports.AuthError = AuthError;
|
|
747
|
+
exports.AuthzError = AuthzError;
|
|
679
748
|
exports.AxiamClient = AxiamClient;
|
|
749
|
+
exports.AxiamError = AxiamError;
|
|
750
|
+
exports.NetworkError = NetworkError;
|
|
751
|
+
exports.OAuthProtocolError = OAuthProtocolError;
|
|
680
752
|
exports.SKIP_REFRESH = SKIP_REFRESH;
|
|
753
|
+
exports.Sensitive = Sensitive;
|
|
681
754
|
exports.SharedSession = SharedSession;
|
|
682
755
|
exports.withRetry = withRetry;
|
|
683
756
|
//# sourceMappingURL=index.js.map
|