axiam-sdk 1.0.0-alpha2 → 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 +219 -8
- 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-xwmCivHH.d.ts → authzCore-DtSN59if.d.ts} +19 -2
- package/dist/{authzCore-CV-Td-V1.d.cts → authzCore-DuRI1aJf.d.cts} +19 -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 +113 -6
- package/dist/grpc/index.d.ts +113 -6
- package/dist/grpc/index.js +435 -18
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +434 -19
- 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 +209 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +204 -14
- 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 +208 -8
- package/dist/middleware/index.d.ts +208 -8
- 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 -94
- package/dist/node/index.d.ts +50 -94
- package/dist/node/index.js +1039 -15
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +1023 -16
- 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 +209 -13
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +204 -14
- 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/session-BWUWhhyB.d.cts +154 -0
- package/dist/session-BWUWhhyB.d.ts +154 -0
- package/package.json +2 -2
- package/dist/client-BPg9kfKV.d.ts +0 -150
- package/dist/client-CAeQw1a-.d.cts +0 -150
- package/dist/jwks-CX-nhD6A.d.cts +0 -29
- package/dist/jwks-CX-nhD6A.d.ts +0 -29
- 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
|
}
|
|
@@ -105,6 +153,33 @@ function mapHttpStatusToError(status, message, ctx) {
|
|
|
105
153
|
return new NetworkError(message, sanitizeAxiosError(ctx?.cause));
|
|
106
154
|
}
|
|
107
155
|
|
|
156
|
+
// src/core/sensitive.ts
|
|
157
|
+
var REDACTED = "[SENSITIVE]";
|
|
158
|
+
var NODE_INSPECT_CUSTOM = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
159
|
+
var Sensitive = class {
|
|
160
|
+
#value;
|
|
161
|
+
/** Wrap `value` so it can never be logged or serialized by accident. */
|
|
162
|
+
constructor(value) {
|
|
163
|
+
this.#value = value;
|
|
164
|
+
}
|
|
165
|
+
/** @internal package-only accessor. Never pass the return value to a log/serialize sink. */
|
|
166
|
+
expose() {
|
|
167
|
+
return this.#value;
|
|
168
|
+
}
|
|
169
|
+
/** Returns the `"[SENSITIVE]"` placeholder — never the wrapped value. */
|
|
170
|
+
toString() {
|
|
171
|
+
return REDACTED;
|
|
172
|
+
}
|
|
173
|
+
/** Makes `JSON.stringify()` emit the `"[SENSITIVE]"` placeholder. */
|
|
174
|
+
toJSON() {
|
|
175
|
+
return REDACTED;
|
|
176
|
+
}
|
|
177
|
+
/** Makes `console.log`/`util.inspect` print the `"[SENSITIVE]"` placeholder. */
|
|
178
|
+
[NODE_INSPECT_CUSTOM]() {
|
|
179
|
+
return REDACTED;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
108
183
|
// src/core/csrf.ts
|
|
109
184
|
var CSRF_METHODS = /* @__PURE__ */ new Set(["post", "put", "patch", "delete"]);
|
|
110
185
|
var CSRF_COOKIE_REGEX = /(?:^|;\s*)axiam_csrf=([^;]*)/;
|
|
@@ -143,9 +218,34 @@ createRefreshGuard();
|
|
|
143
218
|
|
|
144
219
|
// src/core/config.ts
|
|
145
220
|
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
221
|
+
var CERT_PEM_MARKER = "-----BEGIN CERTIFICATE-----";
|
|
222
|
+
var PRIVATE_KEY_PEM_RE = /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY-----/;
|
|
223
|
+
function resolveClientIdentity(options) {
|
|
224
|
+
const hasCert = options.clientCert !== void 0;
|
|
225
|
+
const hasKey = options.clientKey !== void 0;
|
|
226
|
+
if (hasCert !== hasKey) {
|
|
227
|
+
throw new Error(
|
|
228
|
+
"clientCert and clientKey must be provided together for mutual TLS (one was given without the other) (CONTRACT.md \xA76.1)."
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
if (!hasCert || !hasKey) {
|
|
232
|
+
return void 0;
|
|
233
|
+
}
|
|
234
|
+
if (!options.clientCert.includes(CERT_PEM_MARKER)) {
|
|
235
|
+
throw new Error(
|
|
236
|
+
'clientCert must be a PEM-encoded certificate chain (expected to contain "-----BEGIN CERTIFICATE-----") (CONTRACT.md \xA76.1).'
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
if (!PRIVATE_KEY_PEM_RE.test(options.clientKey)) {
|
|
240
|
+
throw new Error(
|
|
241
|
+
'clientKey must be a PEM-encoded private key (expected to contain "-----BEGIN PRIVATE KEY-----" or "-----BEGIN RSA PRIVATE KEY-----") (CONTRACT.md \xA76.1).'
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
return { cert: options.clientCert, key: new Sensitive(options.clientKey) };
|
|
245
|
+
}
|
|
146
246
|
|
|
147
247
|
// src/rest/session.ts
|
|
148
|
-
var PEM_MARKER =
|
|
248
|
+
var PEM_MARKER = CERT_PEM_MARKER;
|
|
149
249
|
var SharedSession = class {
|
|
150
250
|
/** The underlying axios instance this session's requests are issued through, pre-configured with `baseUrl`, credential forwarding, and (Node) an optional custom-CA `httpsAgent`. */
|
|
151
251
|
axios;
|
|
@@ -153,6 +253,28 @@ var SharedSession = class {
|
|
|
153
253
|
baseUrl;
|
|
154
254
|
/** The resolved tenant identifier (`tenantSlug` or `tenantId`) injected as the `X-Tenant-ID` header on every same-origin request (§5.2). */
|
|
155
255
|
tenantHeaderValue;
|
|
256
|
+
/** Configured tenant UUID (`AxiamClientOptions.tenantId`), if the client was built with the UUID form. */
|
|
257
|
+
tenantId;
|
|
258
|
+
/** Configured tenant slug (`AxiamClientOptions.tenantSlug`), if the client was built with the slug form. */
|
|
259
|
+
tenantSlug;
|
|
260
|
+
/** Configured organization UUID (`AxiamClientOptions.orgId`), if supplied (§5). */
|
|
261
|
+
orgId;
|
|
262
|
+
/** Configured organization slug (`AxiamClientOptions.orgSlug`), if supplied (§5). */
|
|
263
|
+
orgSlug;
|
|
264
|
+
/**
|
|
265
|
+
* Resolved tenant UUID used to build the `refresh` body (`RefreshRequest`
|
|
266
|
+
* requires the UUID form, not a slug). Seeded from `orgId`/`tenantId` config
|
|
267
|
+
* when the UUID was supplied, then updated from the access-token `tenant_id`
|
|
268
|
+
* claim after each successful login/refresh (Node persona only — the browser
|
|
269
|
+
* cannot read the httpOnly access-token cookie).
|
|
270
|
+
*/
|
|
271
|
+
resolvedTenantId;
|
|
272
|
+
/**
|
|
273
|
+
* Resolved organization UUID used to build the `refresh` body. Seeded from
|
|
274
|
+
* `orgId` config, then updated from the access-token `org_id` claim after a
|
|
275
|
+
* successful login (Node persona). Mirrors the Rust SDK's `resolved_org_id`.
|
|
276
|
+
*/
|
|
277
|
+
resolvedOrgId;
|
|
156
278
|
/** Mutable CSRF token store — populated by the request/response interceptors (D-05). */
|
|
157
279
|
csrfToken;
|
|
158
280
|
/** Set true once a successful login/verifyMfa has completed. */
|
|
@@ -172,8 +294,55 @@ var SharedSession = class {
|
|
|
172
294
|
this.axios = axiosInstance;
|
|
173
295
|
this.baseUrl = options.baseUrl;
|
|
174
296
|
this.tenantHeaderValue = tenantHeaderValue;
|
|
297
|
+
this.tenantId = options.tenantId;
|
|
298
|
+
this.tenantSlug = options.tenantSlug;
|
|
299
|
+
this.orgId = options.orgId;
|
|
300
|
+
this.orgSlug = options.orgSlug;
|
|
301
|
+
this.resolvedTenantId = options.tenantId;
|
|
302
|
+
this.resolvedOrgId = options.orgId;
|
|
175
303
|
this.refreshGuard = createRefreshGuard();
|
|
176
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* Build the `POST /api/v1/auth/refresh` request body (§1). The server's
|
|
307
|
+
* `RefreshRequest` requires both `tenant_id` and `org_id` as UUIDs, so this
|
|
308
|
+
* emits the resolved UUIDs — from the access-token claims after login, or
|
|
309
|
+
* from UUID-form construction options as a fallback. Fields that could not
|
|
310
|
+
* be resolved are omitted (the server then answers with a clear 400), rather
|
|
311
|
+
* than sending a slug where a UUID is required.
|
|
312
|
+
*/
|
|
313
|
+
buildRefreshBody() {
|
|
314
|
+
const body = {};
|
|
315
|
+
if (this.resolvedTenantId) {
|
|
316
|
+
body.tenant_id = this.resolvedTenantId;
|
|
317
|
+
}
|
|
318
|
+
if (this.resolvedOrgId) {
|
|
319
|
+
body.org_id = this.resolvedOrgId;
|
|
320
|
+
}
|
|
321
|
+
return body;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Build the `POST /api/v1/auth/login` request body (§1/§5). Carries the
|
|
325
|
+
* configured tenant and organization identifiers (UUID or slug form) in
|
|
326
|
+
* addition to the credentials — the server resolves the workspace from the
|
|
327
|
+
* body, not the `X-Tenant-ID` header, and rejects a login that omits org
|
|
328
|
+
* context. Undefined identifiers are omitted.
|
|
329
|
+
*/
|
|
330
|
+
buildLoginBody(email, password) {
|
|
331
|
+
const body = { username_or_email: email, password };
|
|
332
|
+
if (this.tenantId) {
|
|
333
|
+
body.tenant_id = this.tenantId;
|
|
334
|
+
}
|
|
335
|
+
if (this.tenantSlug) {
|
|
336
|
+
body.tenant_slug = this.tenantSlug;
|
|
337
|
+
}
|
|
338
|
+
if (this.orgId) {
|
|
339
|
+
body.org_id = this.orgId;
|
|
340
|
+
}
|
|
341
|
+
if (this.orgSlug) {
|
|
342
|
+
body.org_slug = this.orgSlug;
|
|
343
|
+
}
|
|
344
|
+
return body;
|
|
345
|
+
}
|
|
177
346
|
/**
|
|
178
347
|
* Host-isolation guard (3A, defense in depth): returns `true` when `url`
|
|
179
348
|
* targets a host other than this session's base origin — an absolute
|
|
@@ -207,11 +376,12 @@ function resolveTenantHeaderValue(options) {
|
|
|
207
376
|
"AxiamClient construction requires a tenant: provide either tenantSlug or tenantId (CONTRACT.md \xA75)."
|
|
208
377
|
);
|
|
209
378
|
}
|
|
210
|
-
function maybeBuildHttpsAgent(customCa) {
|
|
379
|
+
function maybeBuildHttpsAgent(customCa, identity) {
|
|
211
380
|
if (!customCa) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
381
|
+
if (!identity) {
|
|
382
|
+
return void 0;
|
|
383
|
+
}
|
|
384
|
+
} else if (!customCa.includes(PEM_MARKER)) {
|
|
215
385
|
throw new Error(
|
|
216
386
|
'customCa must be a PEM-encoded certificate (expected to contain "-----BEGIN CERTIFICATE-----") (CONTRACT.md \xA76).'
|
|
217
387
|
);
|
|
@@ -220,7 +390,11 @@ function maybeBuildHttpsAgent(customCa) {
|
|
|
220
390
|
return void 0;
|
|
221
391
|
}
|
|
222
392
|
const https = __require("https");
|
|
223
|
-
return new https.Agent({
|
|
393
|
+
return new https.Agent({
|
|
394
|
+
...customCa ? { ca: customCa } : {},
|
|
395
|
+
// rejectUnauthorized is intentionally left at its secure default (true).
|
|
396
|
+
...identity ? { cert: identity.cert, key: identity.key.expose() } : {}
|
|
397
|
+
});
|
|
224
398
|
}
|
|
225
399
|
function createSession(options) {
|
|
226
400
|
const tenantHeaderValue = resolveTenantHeaderValue(options);
|
|
@@ -229,7 +403,8 @@ function createSession(options) {
|
|
|
229
403
|
'customCa must be a PEM-encoded certificate (expected to contain "-----BEGIN CERTIFICATE-----") (CONTRACT.md \xA76).'
|
|
230
404
|
);
|
|
231
405
|
}
|
|
232
|
-
const
|
|
406
|
+
const clientIdentity = resolveClientIdentity(options);
|
|
407
|
+
const httpsAgent = maybeBuildHttpsAgent(options.customCa, clientIdentity);
|
|
233
408
|
const axiosInstance = axios__default.default.create({
|
|
234
409
|
baseURL: options.baseUrl,
|
|
235
410
|
withCredentials: true,
|
|
@@ -249,7 +424,14 @@ function createSession(options) {
|
|
|
249
424
|
}
|
|
250
425
|
|
|
251
426
|
// src/rest/interceptors.ts
|
|
252
|
-
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
|
+
];
|
|
253
435
|
function installCsrfInterceptor(axiosInstance, session) {
|
|
254
436
|
axiosInstance.interceptors.request.use((config) => {
|
|
255
437
|
if (session.isForeignHost(config.url)) {
|
|
@@ -280,7 +462,8 @@ function installRefreshInterceptor(axiosInstance, session) {
|
|
|
280
462
|
originalRequest._retry = true;
|
|
281
463
|
try {
|
|
282
464
|
await session.refreshGuard(async () => {
|
|
283
|
-
await session.axios.post("/api/v1/auth/refresh",
|
|
465
|
+
await session.axios.post("/api/v1/auth/refresh", session.buildRefreshBody());
|
|
466
|
+
await session.onAuthenticated?.();
|
|
284
467
|
});
|
|
285
468
|
return axiosInstance(originalRequest);
|
|
286
469
|
} catch (refreshError) {
|
|
@@ -294,7 +477,13 @@ function installRefreshInterceptor(axiosInstance, session) {
|
|
|
294
477
|
}
|
|
295
478
|
}
|
|
296
479
|
if (status === 401 && isSkipRefresh) {
|
|
297
|
-
return Promise.reject(
|
|
480
|
+
return Promise.reject(
|
|
481
|
+
mapHttpStatusToError(401, "authentication failed", {
|
|
482
|
+
url,
|
|
483
|
+
body: error.response.data,
|
|
484
|
+
cause: error
|
|
485
|
+
})
|
|
486
|
+
);
|
|
298
487
|
}
|
|
299
488
|
return Promise.reject(error);
|
|
300
489
|
}
|
|
@@ -332,7 +521,7 @@ function extractErrorMessage(err) {
|
|
|
332
521
|
return "request failed";
|
|
333
522
|
}
|
|
334
523
|
async function login(client, email, password) {
|
|
335
|
-
const body =
|
|
524
|
+
const body = client.session.buildLoginBody(email, password);
|
|
336
525
|
try {
|
|
337
526
|
const response = await client.session.axios.post(
|
|
338
527
|
LOGIN_PATH,
|
|
@@ -373,7 +562,8 @@ async function verifyMfa(client, mfaToken, code) {
|
|
|
373
562
|
}
|
|
374
563
|
async function refresh(client) {
|
|
375
564
|
try {
|
|
376
|
-
await client.session.axios.post(REFRESH_PATH,
|
|
565
|
+
await client.session.axios.post(REFRESH_PATH, client.session.buildRefreshBody());
|
|
566
|
+
await client.session.onAuthenticated?.();
|
|
377
567
|
} catch (err) {
|
|
378
568
|
const status = extractAxiosStatus(err);
|
|
379
569
|
if (status !== void 0) {
|
|
@@ -553,8 +743,14 @@ async function withRetry(fn, options) {
|
|
|
553
743
|
throw lastError;
|
|
554
744
|
}
|
|
555
745
|
|
|
746
|
+
exports.AuthError = AuthError;
|
|
747
|
+
exports.AuthzError = AuthzError;
|
|
556
748
|
exports.AxiamClient = AxiamClient;
|
|
749
|
+
exports.AxiamError = AxiamError;
|
|
750
|
+
exports.NetworkError = NetworkError;
|
|
751
|
+
exports.OAuthProtocolError = OAuthProtocolError;
|
|
557
752
|
exports.SKIP_REFRESH = SKIP_REFRESH;
|
|
753
|
+
exports.Sensitive = Sensitive;
|
|
558
754
|
exports.SharedSession = SharedSession;
|
|
559
755
|
exports.withRetry = withRetry;
|
|
560
756
|
//# sourceMappingURL=index.js.map
|