axiam-sdk 1.0.0-alpha12 → 1.0.0-alpha8
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 +4 -38
- package/dist/{client-Co_baHgU.d.ts → client-BPg9kfKV.d.ts} +0 -73
- package/dist/{client-CzhzwRGg.d.cts → client-CAeQw1a-.d.cts} +0 -73
- package/dist/grpc/index.d.cts +1 -5
- package/dist/grpc/index.d.ts +1 -5
- package/dist/grpc/index.js +14 -181
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +14 -181
- package/dist/grpc/index.mjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -133
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -133
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.d.cts +1 -16
- package/dist/node/index.d.ts +1 -16
- package/dist/node/index.js +11 -164
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +11 -164
- package/dist/node/index.mjs.map +1 -1
- package/dist/rest/index.d.cts +1 -1
- package/dist/rest/index.d.ts +1 -1
- package/dist/rest/index.js +10 -133
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +10 -133
- package/dist/rest/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Official TypeScript/JavaScript client SDK for [AXIAM](https://github.com/ilpanic
|
|
|
17
17
|
|
|
18
18
|
## Contract conformance
|
|
19
19
|
|
|
20
|
-
This SDK conforms to CONTRACT.md §1–§11
|
|
20
|
+
This SDK conforms to CONTRACT.md §1–§11.
|
|
21
21
|
|
|
22
22
|
See [`CONTRACT.md`](./CONTRACT.md) for the full cross-language behavioral contract.
|
|
23
23
|
|
|
@@ -58,43 +58,11 @@ import { AxiamClient } from 'axiam-sdk';
|
|
|
58
58
|
const client = new AxiamClient({
|
|
59
59
|
baseUrl: 'https://iam.example.com',
|
|
60
60
|
tenantSlug: 'acme',
|
|
61
|
-
// Organization context is required for login/refresh — a tenant slug is only
|
|
62
|
-
// unique within an organization (CONTRACT.md §5.1). Pass orgSlug (or orgId).
|
|
63
|
-
orgSlug: 'acme',
|
|
64
61
|
// customCa is optional — PEM-encoded CA cert for self-signed dev environments (§6)
|
|
65
62
|
// customCa: pemString,
|
|
66
63
|
});
|
|
67
64
|
```
|
|
68
65
|
|
|
69
|
-
### mTLS / client certificates (Node only)
|
|
70
|
-
|
|
71
|
-
For IoT devices and service accounts authenticated by **mutual TLS** (CONTRACT.md §6.1),
|
|
72
|
-
pass a PEM client-certificate chain and its PEM private key. The identity is presented on
|
|
73
|
-
**both** the REST and gRPC transports of the same client. Presenting a client certificate
|
|
74
|
-
**never** relaxes server verification — strict TLS stays on.
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
import { readFileSync } from 'node:fs';
|
|
78
|
-
import { AxiamClient } from 'axiam-sdk';
|
|
79
|
-
|
|
80
|
-
const client = new AxiamClient({
|
|
81
|
-
baseUrl: 'https://iam.example.com',
|
|
82
|
-
tenantSlug: 'acme',
|
|
83
|
-
orgSlug: 'acme', // organization context required for login/refresh (CONTRACT.md §5.1)
|
|
84
|
-
clientCert: readFileSync('device.crt', 'utf8'), // PEM certificate chain
|
|
85
|
-
clientKey: readFileSync('device.key', 'utf8'), // PEM private key (PKCS#8 or PKCS#1)
|
|
86
|
-
// customCa: readFileSync('ca.crt', 'utf8'), // optional server-trust CA (§6)
|
|
87
|
-
});
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
- `clientCert` and `clientKey` are **all-or-nothing** — providing exactly one throws at
|
|
91
|
-
construction, and each is validated to be PEM-shaped (as `customCa` is).
|
|
92
|
-
- The private key is secret material: it is passed straight to the Node TLS stack and is
|
|
93
|
-
never retained on a public property, logged, or serialized (CONTRACT.md §7).
|
|
94
|
-
- **Node only.** Browsers cannot present a client certificate from JavaScript, so the
|
|
95
|
-
browser build validates the PEM shape then ignores `clientCert`/`clientKey` — exactly as
|
|
96
|
-
it already ignores `customCa`.
|
|
97
|
-
|
|
98
66
|
## Usage per persona
|
|
99
67
|
|
|
100
68
|
### Browser — login + authz (`axiam-sdk` / `axiam-sdk/rest`)
|
|
@@ -102,7 +70,7 @@ const client = new AxiamClient({
|
|
|
102
70
|
```typescript
|
|
103
71
|
import { AxiamClient } from 'axiam-sdk';
|
|
104
72
|
|
|
105
|
-
const client = new AxiamClient({ baseUrl: 'https://iam.example.com', tenantSlug: 'acme'
|
|
73
|
+
const client = new AxiamClient({ baseUrl: 'https://iam.example.com', tenantSlug: 'acme' });
|
|
106
74
|
|
|
107
75
|
const result = await client.login(email, password);
|
|
108
76
|
switch (result.status) {
|
|
@@ -343,10 +311,8 @@ try {
|
|
|
343
311
|
- Token-carrying values are wrapped in `Sensitive<T>` — `toString()`/`toJSON()`/
|
|
344
312
|
`util.inspect` all redact to `[SENSITIVE]`; the raw value is only reachable via an
|
|
345
313
|
explicit accessor (CONTRACT.md §7).
|
|
346
|
-
- Strict TLS verification is always on; the only
|
|
347
|
-
|
|
348
|
-
- Optional mutual TLS (mTLS): a PEM `clientCert`/`clientKey` client identity (Node only) is
|
|
349
|
-
presented on both REST and gRPC without ever relaxing server verification (CONTRACT.md §6.1).
|
|
314
|
+
- Strict TLS verification is always on; the only escape hatch is the constructor's
|
|
315
|
+
`customCa` option for self-signed development environments (CONTRACT.md §6).
|
|
350
316
|
- AMQP messages are HMAC-SHA256 verified before your handler ever sees them; verification
|
|
351
317
|
failures are nacked without requeue (CONTRACT.md §8).
|
|
352
318
|
|
|
@@ -21,42 +21,8 @@ interface AxiamClientOptions {
|
|
|
21
21
|
tenantSlug?: string;
|
|
22
22
|
/** Tenant UUID. At least one of tenantSlug/tenantId is required at runtime. */
|
|
23
23
|
tenantId?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Human-readable organization identifier (CONTRACT.md §5). Optional at
|
|
26
|
-
* construction, but the server REQUIRES an org context on login — a tenant
|
|
27
|
-
* slug is only unique *within* an organization — so a client that omits both
|
|
28
|
-
* `orgSlug` and `orgId` will fail login with a 400/401. Forwarded as
|
|
29
|
-
* `org_slug` in the login body. Mutually exclusive with {@link orgId}
|
|
30
|
-
* (if both are given, `orgId` wins, mirroring how `tenantSlug`/`tenantId`
|
|
31
|
-
* resolve).
|
|
32
|
-
*/
|
|
33
|
-
orgSlug?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Organization UUID (CONTRACT.md §5). Optional at construction (see
|
|
36
|
-
* {@link orgSlug}). When supplied it is forwarded as `org_id` on login and
|
|
37
|
-
* used to build the `refresh` body; otherwise the resolved organization UUID
|
|
38
|
-
* is decoded from the authenticated session's access-token `org_id` claim
|
|
39
|
-
* after the first successful login. Mutually exclusive with {@link orgSlug}.
|
|
40
|
-
*/
|
|
41
|
-
orgId?: string;
|
|
42
24
|
/** PEM-encoded custom CA certificate, for self-signed/dev environments (§6). */
|
|
43
25
|
customCa?: string;
|
|
44
|
-
/**
|
|
45
|
-
* PEM-encoded client-certificate chain for mutual TLS (§6.1). Presented to
|
|
46
|
-
* the server to authenticate an IoT device / service account. MUST be
|
|
47
|
-
* provided together with {@link AxiamClientOptions.clientKey}. Node only —
|
|
48
|
-
* ignored in the browser (browsers cannot present a client certificate from
|
|
49
|
-
* JS). Presenting a client certificate NEVER relaxes server verification.
|
|
50
|
-
*/
|
|
51
|
-
clientCert?: string;
|
|
52
|
-
/**
|
|
53
|
-
* PEM-encoded private key (PKCS#8 or PKCS#1) matching {@link
|
|
54
|
-
* AxiamClientOptions.clientCert} (§6.1). Secret material: it is passed
|
|
55
|
-
* straight to the Node TLS stack and is never retained on a public property,
|
|
56
|
-
* logged, or serialized (§7). MUST be provided together with `clientCert`.
|
|
57
|
-
* Node only — ignored in the browser.
|
|
58
|
-
*/
|
|
59
|
-
clientKey?: string;
|
|
60
26
|
/** Connection timeout in milliseconds. Defaults to DEFAULT_CONNECT_TIMEOUT_MS. */
|
|
61
27
|
connectTimeoutMs?: number;
|
|
62
28
|
/** Request timeout in milliseconds. Defaults to DEFAULT_REQUEST_TIMEOUT_MS. */
|
|
@@ -75,28 +41,6 @@ declare class SharedSession {
|
|
|
75
41
|
readonly baseUrl: string;
|
|
76
42
|
/** The resolved tenant identifier (`tenantSlug` or `tenantId`) injected as the `X-Tenant-ID` header on every same-origin request (§5.2). */
|
|
77
43
|
readonly tenantHeaderValue: string;
|
|
78
|
-
/** Configured tenant UUID (`AxiamClientOptions.tenantId`), if the client was built with the UUID form. */
|
|
79
|
-
readonly tenantId: string | undefined;
|
|
80
|
-
/** Configured tenant slug (`AxiamClientOptions.tenantSlug`), if the client was built with the slug form. */
|
|
81
|
-
readonly tenantSlug: string | undefined;
|
|
82
|
-
/** Configured organization UUID (`AxiamClientOptions.orgId`), if supplied (§5). */
|
|
83
|
-
readonly orgId: string | undefined;
|
|
84
|
-
/** Configured organization slug (`AxiamClientOptions.orgSlug`), if supplied (§5). */
|
|
85
|
-
readonly orgSlug: string | undefined;
|
|
86
|
-
/**
|
|
87
|
-
* Resolved tenant UUID used to build the `refresh` body (`RefreshRequest`
|
|
88
|
-
* requires the UUID form, not a slug). Seeded from `orgId`/`tenantId` config
|
|
89
|
-
* when the UUID was supplied, then updated from the access-token `tenant_id`
|
|
90
|
-
* claim after each successful login/refresh (Node persona only — the browser
|
|
91
|
-
* cannot read the httpOnly access-token cookie).
|
|
92
|
-
*/
|
|
93
|
-
resolvedTenantId: string | undefined;
|
|
94
|
-
/**
|
|
95
|
-
* Resolved organization UUID used to build the `refresh` body. Seeded from
|
|
96
|
-
* `orgId` config, then updated from the access-token `org_id` claim after a
|
|
97
|
-
* successful login (Node persona). Mirrors the Rust SDK's `resolved_org_id`.
|
|
98
|
-
*/
|
|
99
|
-
resolvedOrgId: string | undefined;
|
|
100
44
|
/** Mutable CSRF token store — populated by the request/response interceptors (D-05). */
|
|
101
45
|
csrfToken: string | undefined;
|
|
102
46
|
/** Set true once a successful login/verifyMfa has completed. */
|
|
@@ -113,23 +57,6 @@ declare class SharedSession {
|
|
|
113
57
|
*/
|
|
114
58
|
readonly refreshGuard: RefreshGuard;
|
|
115
59
|
constructor(options: AxiamClientOptions, axiosInstance: AxiosInstance, tenantHeaderValue: string);
|
|
116
|
-
/**
|
|
117
|
-
* Build the `POST /api/v1/auth/refresh` request body (§1). The server's
|
|
118
|
-
* `RefreshRequest` requires both `tenant_id` and `org_id` as UUIDs, so this
|
|
119
|
-
* emits the resolved UUIDs — from the access-token claims after login, or
|
|
120
|
-
* from UUID-form construction options as a fallback. Fields that could not
|
|
121
|
-
* be resolved are omitted (the server then answers with a clear 400), rather
|
|
122
|
-
* than sending a slug where a UUID is required.
|
|
123
|
-
*/
|
|
124
|
-
buildRefreshBody(): Record<string, string>;
|
|
125
|
-
/**
|
|
126
|
-
* Build the `POST /api/v1/auth/login` request body (§1/§5). Carries the
|
|
127
|
-
* configured tenant and organization identifiers (UUID or slug form) in
|
|
128
|
-
* addition to the credentials — the server resolves the workspace from the
|
|
129
|
-
* body, not the `X-Tenant-ID` header, and rejects a login that omits org
|
|
130
|
-
* context. Undefined identifiers are omitted.
|
|
131
|
-
*/
|
|
132
|
-
buildLoginBody(email: string, password: string): Record<string, string>;
|
|
133
60
|
/**
|
|
134
61
|
* Optional session-level hook invoked by rest/auth.ts after a successful
|
|
135
62
|
* login()/verifyMfa() (CR-01, D-05). The base SharedSession (browser
|
|
@@ -21,42 +21,8 @@ interface AxiamClientOptions {
|
|
|
21
21
|
tenantSlug?: string;
|
|
22
22
|
/** Tenant UUID. At least one of tenantSlug/tenantId is required at runtime. */
|
|
23
23
|
tenantId?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Human-readable organization identifier (CONTRACT.md §5). Optional at
|
|
26
|
-
* construction, but the server REQUIRES an org context on login — a tenant
|
|
27
|
-
* slug is only unique *within* an organization — so a client that omits both
|
|
28
|
-
* `orgSlug` and `orgId` will fail login with a 400/401. Forwarded as
|
|
29
|
-
* `org_slug` in the login body. Mutually exclusive with {@link orgId}
|
|
30
|
-
* (if both are given, `orgId` wins, mirroring how `tenantSlug`/`tenantId`
|
|
31
|
-
* resolve).
|
|
32
|
-
*/
|
|
33
|
-
orgSlug?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Organization UUID (CONTRACT.md §5). Optional at construction (see
|
|
36
|
-
* {@link orgSlug}). When supplied it is forwarded as `org_id` on login and
|
|
37
|
-
* used to build the `refresh` body; otherwise the resolved organization UUID
|
|
38
|
-
* is decoded from the authenticated session's access-token `org_id` claim
|
|
39
|
-
* after the first successful login. Mutually exclusive with {@link orgSlug}.
|
|
40
|
-
*/
|
|
41
|
-
orgId?: string;
|
|
42
24
|
/** PEM-encoded custom CA certificate, for self-signed/dev environments (§6). */
|
|
43
25
|
customCa?: string;
|
|
44
|
-
/**
|
|
45
|
-
* PEM-encoded client-certificate chain for mutual TLS (§6.1). Presented to
|
|
46
|
-
* the server to authenticate an IoT device / service account. MUST be
|
|
47
|
-
* provided together with {@link AxiamClientOptions.clientKey}. Node only —
|
|
48
|
-
* ignored in the browser (browsers cannot present a client certificate from
|
|
49
|
-
* JS). Presenting a client certificate NEVER relaxes server verification.
|
|
50
|
-
*/
|
|
51
|
-
clientCert?: string;
|
|
52
|
-
/**
|
|
53
|
-
* PEM-encoded private key (PKCS#8 or PKCS#1) matching {@link
|
|
54
|
-
* AxiamClientOptions.clientCert} (§6.1). Secret material: it is passed
|
|
55
|
-
* straight to the Node TLS stack and is never retained on a public property,
|
|
56
|
-
* logged, or serialized (§7). MUST be provided together with `clientCert`.
|
|
57
|
-
* Node only — ignored in the browser.
|
|
58
|
-
*/
|
|
59
|
-
clientKey?: string;
|
|
60
26
|
/** Connection timeout in milliseconds. Defaults to DEFAULT_CONNECT_TIMEOUT_MS. */
|
|
61
27
|
connectTimeoutMs?: number;
|
|
62
28
|
/** Request timeout in milliseconds. Defaults to DEFAULT_REQUEST_TIMEOUT_MS. */
|
|
@@ -75,28 +41,6 @@ declare class SharedSession {
|
|
|
75
41
|
readonly baseUrl: string;
|
|
76
42
|
/** The resolved tenant identifier (`tenantSlug` or `tenantId`) injected as the `X-Tenant-ID` header on every same-origin request (§5.2). */
|
|
77
43
|
readonly tenantHeaderValue: string;
|
|
78
|
-
/** Configured tenant UUID (`AxiamClientOptions.tenantId`), if the client was built with the UUID form. */
|
|
79
|
-
readonly tenantId: string | undefined;
|
|
80
|
-
/** Configured tenant slug (`AxiamClientOptions.tenantSlug`), if the client was built with the slug form. */
|
|
81
|
-
readonly tenantSlug: string | undefined;
|
|
82
|
-
/** Configured organization UUID (`AxiamClientOptions.orgId`), if supplied (§5). */
|
|
83
|
-
readonly orgId: string | undefined;
|
|
84
|
-
/** Configured organization slug (`AxiamClientOptions.orgSlug`), if supplied (§5). */
|
|
85
|
-
readonly orgSlug: string | undefined;
|
|
86
|
-
/**
|
|
87
|
-
* Resolved tenant UUID used to build the `refresh` body (`RefreshRequest`
|
|
88
|
-
* requires the UUID form, not a slug). Seeded from `orgId`/`tenantId` config
|
|
89
|
-
* when the UUID was supplied, then updated from the access-token `tenant_id`
|
|
90
|
-
* claim after each successful login/refresh (Node persona only — the browser
|
|
91
|
-
* cannot read the httpOnly access-token cookie).
|
|
92
|
-
*/
|
|
93
|
-
resolvedTenantId: string | undefined;
|
|
94
|
-
/**
|
|
95
|
-
* Resolved organization UUID used to build the `refresh` body. Seeded from
|
|
96
|
-
* `orgId` config, then updated from the access-token `org_id` claim after a
|
|
97
|
-
* successful login (Node persona). Mirrors the Rust SDK's `resolved_org_id`.
|
|
98
|
-
*/
|
|
99
|
-
resolvedOrgId: string | undefined;
|
|
100
44
|
/** Mutable CSRF token store — populated by the request/response interceptors (D-05). */
|
|
101
45
|
csrfToken: string | undefined;
|
|
102
46
|
/** Set true once a successful login/verifyMfa has completed. */
|
|
@@ -113,23 +57,6 @@ declare class SharedSession {
|
|
|
113
57
|
*/
|
|
114
58
|
readonly refreshGuard: RefreshGuard;
|
|
115
59
|
constructor(options: AxiamClientOptions, axiosInstance: AxiosInstance, tenantHeaderValue: string);
|
|
116
|
-
/**
|
|
117
|
-
* Build the `POST /api/v1/auth/refresh` request body (§1). The server's
|
|
118
|
-
* `RefreshRequest` requires both `tenant_id` and `org_id` as UUIDs, so this
|
|
119
|
-
* emits the resolved UUIDs — from the access-token claims after login, or
|
|
120
|
-
* from UUID-form construction options as a fallback. Fields that could not
|
|
121
|
-
* be resolved are omitted (the server then answers with a clear 400), rather
|
|
122
|
-
* than sending a slug where a UUID is required.
|
|
123
|
-
*/
|
|
124
|
-
buildRefreshBody(): Record<string, string>;
|
|
125
|
-
/**
|
|
126
|
-
* Build the `POST /api/v1/auth/login` request body (§1/§5). Carries the
|
|
127
|
-
* configured tenant and organization identifiers (UUID or slug form) in
|
|
128
|
-
* addition to the credentials — the server resolves the workspace from the
|
|
129
|
-
* body, not the `X-Tenant-ID` header, and rejects a login that omits org
|
|
130
|
-
* context. Undefined identifiers are omitted.
|
|
131
|
-
*/
|
|
132
|
-
buildLoginBody(email: string, password: string): Record<string, string>;
|
|
133
60
|
/**
|
|
134
61
|
* Optional session-level hook invoked by rest/auth.ts after a successful
|
|
135
62
|
* login()/verifyMfa() (CR-01, D-05). The base SharedSession (browser
|
package/dist/grpc/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ export { ACCESS_COOKIE, CSRF_COOKIE, REFRESH_COOKIE, TokenManager, createJar, cr
|
|
|
5
5
|
import { a as AccessDecision } from '../types-BVkMoqLU.cjs';
|
|
6
6
|
export { A as AxiamClaims, J as JWKS_PATH, V as Verifier, c as createVerifier } from '../jwks-B8dPy2c6.cjs';
|
|
7
7
|
import 'tough-cookie';
|
|
8
|
-
import '../client-
|
|
8
|
+
import '../client-CAeQw1a-.cjs';
|
|
9
9
|
import 'axios';
|
|
10
10
|
import '../sensitive-CWBH_tHr.cjs';
|
|
11
11
|
|
|
@@ -95,10 +95,6 @@ declare class AuthzGrpcClient {
|
|
|
95
95
|
baseUrl: string;
|
|
96
96
|
customCa?: string;
|
|
97
97
|
allowInsecure?: boolean;
|
|
98
|
-
/** PEM client-certificate chain for mutual TLS (§6.1); pair with `clientKey`. */
|
|
99
|
-
clientCert?: string;
|
|
100
|
-
/** PEM private key for mutual TLS (§6.1); pair with `clientCert`. Secret (§7). */
|
|
101
|
-
clientKey?: string;
|
|
102
98
|
}, clientFactory?: AuthorizationServiceClientFactory);
|
|
103
99
|
/** `CheckAccess` over gRPC (SC#2 Node half). UNAUTHENTICATED triggers exactly one shared-guard refresh + one retry (§9.3). */
|
|
104
100
|
checkAccess(request: CheckAccessRequest): Promise<AccessDecision>;
|
package/dist/grpc/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { ACCESS_COOKIE, CSRF_COOKIE, REFRESH_COOKIE, TokenManager, createJar, cr
|
|
|
5
5
|
import { a as AccessDecision } from '../types-BVkMoqLU.js';
|
|
6
6
|
export { A as AxiamClaims, J as JWKS_PATH, V as Verifier, c as createVerifier } from '../jwks-B8dPy2c6.js';
|
|
7
7
|
import 'tough-cookie';
|
|
8
|
-
import '../client-
|
|
8
|
+
import '../client-BPg9kfKV.js';
|
|
9
9
|
import 'axios';
|
|
10
10
|
import '../sensitive-CWBH_tHr.js';
|
|
11
11
|
|
|
@@ -95,10 +95,6 @@ declare class AuthzGrpcClient {
|
|
|
95
95
|
baseUrl: string;
|
|
96
96
|
customCa?: string;
|
|
97
97
|
allowInsecure?: boolean;
|
|
98
|
-
/** PEM client-certificate chain for mutual TLS (§6.1); pair with `clientKey`. */
|
|
99
|
-
clientCert?: string;
|
|
100
|
-
/** PEM private key for mutual TLS (§6.1); pair with `clientCert`. Secret (§7). */
|
|
101
|
-
clientKey?: string;
|
|
102
98
|
}, clientFactory?: AuthorizationServiceClientFactory);
|
|
103
99
|
/** `CheckAccess` over gRPC (SC#2 Node half). UNAUTHENTICATED triggers exactly one shared-guard refresh + one retry (§9.3). */
|
|
104
100
|
checkAccess(request: CheckAccessRequest): Promise<AccessDecision>;
|
package/dist/grpc/index.js
CHANGED
|
@@ -215,31 +215,6 @@ createRefreshGuard();
|
|
|
215
215
|
|
|
216
216
|
// src/core/config.ts
|
|
217
217
|
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
218
|
-
var CERT_PEM_MARKER = "-----BEGIN CERTIFICATE-----";
|
|
219
|
-
var PRIVATE_KEY_PEM_RE = /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY-----/;
|
|
220
|
-
function resolveClientIdentity(options) {
|
|
221
|
-
const hasCert = options.clientCert !== void 0;
|
|
222
|
-
const hasKey = options.clientKey !== void 0;
|
|
223
|
-
if (hasCert !== hasKey) {
|
|
224
|
-
throw new Error(
|
|
225
|
-
"clientCert and clientKey must be provided together for mutual TLS (one was given without the other) (CONTRACT.md \xA76.1)."
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
if (!hasCert || !hasKey) {
|
|
229
|
-
return void 0;
|
|
230
|
-
}
|
|
231
|
-
if (!options.clientCert.includes(CERT_PEM_MARKER)) {
|
|
232
|
-
throw new Error(
|
|
233
|
-
'clientCert must be a PEM-encoded certificate chain (expected to contain "-----BEGIN CERTIFICATE-----") (CONTRACT.md \xA76.1).'
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
if (!PRIVATE_KEY_PEM_RE.test(options.clientKey)) {
|
|
237
|
-
throw new Error(
|
|
238
|
-
'clientKey must be a PEM-encoded private key (expected to contain "-----BEGIN PRIVATE KEY-----" or "-----BEGIN RSA PRIVATE KEY-----") (CONTRACT.md \xA76.1).'
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
return { cert: options.clientCert, key: new Sensitive(options.clientKey) };
|
|
242
|
-
}
|
|
243
218
|
|
|
244
219
|
// src/grpc/callWithRefresh.ts
|
|
245
220
|
function isGrpcServiceError(err) {
|
|
@@ -293,7 +268,7 @@ function promisifyUnary(call, request) {
|
|
|
293
268
|
});
|
|
294
269
|
});
|
|
295
270
|
}
|
|
296
|
-
function buildCredentials(baseUrl, customCa, allowInsecure
|
|
271
|
+
function buildCredentials(baseUrl, customCa, allowInsecure) {
|
|
297
272
|
const isSecure = baseUrl.startsWith("https://") || baseUrl.startsWith("grpcs://");
|
|
298
273
|
if (!isSecure) {
|
|
299
274
|
if (!allowInsecure) {
|
|
@@ -306,16 +281,8 @@ function buildCredentials(baseUrl, customCa, allowInsecure, identity) {
|
|
|
306
281
|
);
|
|
307
282
|
return grpc2__namespace.ChannelCredentials.createInsecure();
|
|
308
283
|
}
|
|
309
|
-
const rootCerts = customCa ? Buffer.from(customCa, "utf8") : null;
|
|
310
|
-
if (identity) {
|
|
311
|
-
return grpc2__namespace.ChannelCredentials.createSsl(
|
|
312
|
-
rootCerts,
|
|
313
|
-
Buffer.from(identity.key.expose(), "utf8"),
|
|
314
|
-
Buffer.from(identity.cert, "utf8")
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
284
|
if (customCa) {
|
|
318
|
-
return grpc2__namespace.ChannelCredentials.createSsl(
|
|
285
|
+
return grpc2__namespace.ChannelCredentials.createSsl(Buffer.from(customCa, "utf8"));
|
|
319
286
|
}
|
|
320
287
|
return grpc2__namespace.ChannelCredentials.createSsl();
|
|
321
288
|
}
|
|
@@ -364,13 +331,7 @@ var AuthzGrpcClient = class {
|
|
|
364
331
|
#inner;
|
|
365
332
|
constructor(session, options, clientFactory = buildAuthorizationServiceClient) {
|
|
366
333
|
this.#session = session;
|
|
367
|
-
const
|
|
368
|
-
const credentials = buildCredentials(
|
|
369
|
-
options.baseUrl,
|
|
370
|
-
options.customCa,
|
|
371
|
-
options.allowInsecure ?? false,
|
|
372
|
-
identity
|
|
373
|
-
);
|
|
334
|
+
const credentials = buildCredentials(options.baseUrl, options.customCa, options.allowInsecure ?? false);
|
|
374
335
|
this.#inner = clientFactory(options.baseUrl, credentials, [authInterceptor(session)]);
|
|
375
336
|
}
|
|
376
337
|
/** `CheckAccess` over gRPC (SC#2 Node half). UNAUTHENTICATED triggers exactly one shared-guard refresh + one retry (§9.3). */
|
|
@@ -396,7 +357,7 @@ var AuthzGrpcClient = class {
|
|
|
396
357
|
this.#inner.close();
|
|
397
358
|
}
|
|
398
359
|
};
|
|
399
|
-
var PEM_MARKER =
|
|
360
|
+
var PEM_MARKER = "-----BEGIN CERTIFICATE-----";
|
|
400
361
|
var SharedSession = class {
|
|
401
362
|
/** The underlying axios instance this session's requests are issued through, pre-configured with `baseUrl`, credential forwarding, and (Node) an optional custom-CA `httpsAgent`. */
|
|
402
363
|
axios;
|
|
@@ -404,28 +365,6 @@ var SharedSession = class {
|
|
|
404
365
|
baseUrl;
|
|
405
366
|
/** The resolved tenant identifier (`tenantSlug` or `tenantId`) injected as the `X-Tenant-ID` header on every same-origin request (§5.2). */
|
|
406
367
|
tenantHeaderValue;
|
|
407
|
-
/** Configured tenant UUID (`AxiamClientOptions.tenantId`), if the client was built with the UUID form. */
|
|
408
|
-
tenantId;
|
|
409
|
-
/** Configured tenant slug (`AxiamClientOptions.tenantSlug`), if the client was built with the slug form. */
|
|
410
|
-
tenantSlug;
|
|
411
|
-
/** Configured organization UUID (`AxiamClientOptions.orgId`), if supplied (§5). */
|
|
412
|
-
orgId;
|
|
413
|
-
/** Configured organization slug (`AxiamClientOptions.orgSlug`), if supplied (§5). */
|
|
414
|
-
orgSlug;
|
|
415
|
-
/**
|
|
416
|
-
* Resolved tenant UUID used to build the `refresh` body (`RefreshRequest`
|
|
417
|
-
* requires the UUID form, not a slug). Seeded from `orgId`/`tenantId` config
|
|
418
|
-
* when the UUID was supplied, then updated from the access-token `tenant_id`
|
|
419
|
-
* claim after each successful login/refresh (Node persona only — the browser
|
|
420
|
-
* cannot read the httpOnly access-token cookie).
|
|
421
|
-
*/
|
|
422
|
-
resolvedTenantId;
|
|
423
|
-
/**
|
|
424
|
-
* Resolved organization UUID used to build the `refresh` body. Seeded from
|
|
425
|
-
* `orgId` config, then updated from the access-token `org_id` claim after a
|
|
426
|
-
* successful login (Node persona). Mirrors the Rust SDK's `resolved_org_id`.
|
|
427
|
-
*/
|
|
428
|
-
resolvedOrgId;
|
|
429
368
|
/** Mutable CSRF token store — populated by the request/response interceptors (D-05). */
|
|
430
369
|
csrfToken;
|
|
431
370
|
/** Set true once a successful login/verifyMfa has completed. */
|
|
@@ -445,55 +384,8 @@ var SharedSession = class {
|
|
|
445
384
|
this.axios = axiosInstance;
|
|
446
385
|
this.baseUrl = options.baseUrl;
|
|
447
386
|
this.tenantHeaderValue = tenantHeaderValue;
|
|
448
|
-
this.tenantId = options.tenantId;
|
|
449
|
-
this.tenantSlug = options.tenantSlug;
|
|
450
|
-
this.orgId = options.orgId;
|
|
451
|
-
this.orgSlug = options.orgSlug;
|
|
452
|
-
this.resolvedTenantId = options.tenantId;
|
|
453
|
-
this.resolvedOrgId = options.orgId;
|
|
454
387
|
this.refreshGuard = createRefreshGuard();
|
|
455
388
|
}
|
|
456
|
-
/**
|
|
457
|
-
* Build the `POST /api/v1/auth/refresh` request body (§1). The server's
|
|
458
|
-
* `RefreshRequest` requires both `tenant_id` and `org_id` as UUIDs, so this
|
|
459
|
-
* emits the resolved UUIDs — from the access-token claims after login, or
|
|
460
|
-
* from UUID-form construction options as a fallback. Fields that could not
|
|
461
|
-
* be resolved are omitted (the server then answers with a clear 400), rather
|
|
462
|
-
* than sending a slug where a UUID is required.
|
|
463
|
-
*/
|
|
464
|
-
buildRefreshBody() {
|
|
465
|
-
const body = {};
|
|
466
|
-
if (this.resolvedTenantId) {
|
|
467
|
-
body.tenant_id = this.resolvedTenantId;
|
|
468
|
-
}
|
|
469
|
-
if (this.resolvedOrgId) {
|
|
470
|
-
body.org_id = this.resolvedOrgId;
|
|
471
|
-
}
|
|
472
|
-
return body;
|
|
473
|
-
}
|
|
474
|
-
/**
|
|
475
|
-
* Build the `POST /api/v1/auth/login` request body (§1/§5). Carries the
|
|
476
|
-
* configured tenant and organization identifiers (UUID or slug form) in
|
|
477
|
-
* addition to the credentials — the server resolves the workspace from the
|
|
478
|
-
* body, not the `X-Tenant-ID` header, and rejects a login that omits org
|
|
479
|
-
* context. Undefined identifiers are omitted.
|
|
480
|
-
*/
|
|
481
|
-
buildLoginBody(email, password) {
|
|
482
|
-
const body = { username_or_email: email, password };
|
|
483
|
-
if (this.tenantId) {
|
|
484
|
-
body.tenant_id = this.tenantId;
|
|
485
|
-
}
|
|
486
|
-
if (this.tenantSlug) {
|
|
487
|
-
body.tenant_slug = this.tenantSlug;
|
|
488
|
-
}
|
|
489
|
-
if (this.orgId) {
|
|
490
|
-
body.org_id = this.orgId;
|
|
491
|
-
}
|
|
492
|
-
if (this.orgSlug) {
|
|
493
|
-
body.org_slug = this.orgSlug;
|
|
494
|
-
}
|
|
495
|
-
return body;
|
|
496
|
-
}
|
|
497
389
|
/**
|
|
498
390
|
* Host-isolation guard (3A, defense in depth): returns `true` when `url`
|
|
499
391
|
* targets a host other than this session's base origin — an absolute
|
|
@@ -527,12 +419,11 @@ function resolveTenantHeaderValue(options) {
|
|
|
527
419
|
"AxiamClient construction requires a tenant: provide either tenantSlug or tenantId (CONTRACT.md \xA75)."
|
|
528
420
|
);
|
|
529
421
|
}
|
|
530
|
-
function maybeBuildHttpsAgent(customCa
|
|
422
|
+
function maybeBuildHttpsAgent(customCa) {
|
|
531
423
|
if (!customCa) {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
} else if (!customCa.includes(PEM_MARKER)) {
|
|
424
|
+
return void 0;
|
|
425
|
+
}
|
|
426
|
+
if (!customCa.includes(PEM_MARKER)) {
|
|
536
427
|
throw new Error(
|
|
537
428
|
'customCa must be a PEM-encoded certificate (expected to contain "-----BEGIN CERTIFICATE-----") (CONTRACT.md \xA76).'
|
|
538
429
|
);
|
|
@@ -541,11 +432,7 @@ function maybeBuildHttpsAgent(customCa, identity) {
|
|
|
541
432
|
return void 0;
|
|
542
433
|
}
|
|
543
434
|
const https = __require("https");
|
|
544
|
-
return new https.Agent({
|
|
545
|
-
...customCa ? { ca: customCa } : {},
|
|
546
|
-
// rejectUnauthorized is intentionally left at its secure default (true).
|
|
547
|
-
...identity ? { cert: identity.cert, key: identity.key.expose() } : {}
|
|
548
|
-
});
|
|
435
|
+
return new https.Agent({ ca: customCa });
|
|
549
436
|
}
|
|
550
437
|
function createSession(options) {
|
|
551
438
|
const tenantHeaderValue = resolveTenantHeaderValue(options);
|
|
@@ -554,8 +441,7 @@ function createSession(options) {
|
|
|
554
441
|
'customCa must be a PEM-encoded certificate (expected to contain "-----BEGIN CERTIFICATE-----") (CONTRACT.md \xA76).'
|
|
555
442
|
);
|
|
556
443
|
}
|
|
557
|
-
const
|
|
558
|
-
const httpsAgent = maybeBuildHttpsAgent(options.customCa, clientIdentity);
|
|
444
|
+
const httpsAgent = maybeBuildHttpsAgent(options.customCa);
|
|
559
445
|
const axiosInstance = axios__default.default.create({
|
|
560
446
|
baseURL: options.baseUrl,
|
|
561
447
|
withCredentials: true,
|
|
@@ -606,7 +492,7 @@ function installRefreshInterceptor(axiosInstance, session) {
|
|
|
606
492
|
originalRequest._retry = true;
|
|
607
493
|
try {
|
|
608
494
|
await session.refreshGuard(async () => {
|
|
609
|
-
await session.axios.post("/api/v1/auth/refresh",
|
|
495
|
+
await session.axios.post("/api/v1/auth/refresh", {});
|
|
610
496
|
});
|
|
611
497
|
return axiosInstance(originalRequest);
|
|
612
498
|
} catch (refreshError) {
|
|
@@ -658,7 +544,7 @@ function extractErrorMessage(err) {
|
|
|
658
544
|
return "request failed";
|
|
659
545
|
}
|
|
660
546
|
async function login(client, email, password) {
|
|
661
|
-
const body =
|
|
547
|
+
const body = { username_or_email: email, password };
|
|
662
548
|
try {
|
|
663
549
|
const response = await client.session.axios.post(
|
|
664
550
|
LOGIN_PATH,
|
|
@@ -699,7 +585,7 @@ async function verifyMfa(client, mfaToken, code) {
|
|
|
699
585
|
}
|
|
700
586
|
async function refresh(client) {
|
|
701
587
|
try {
|
|
702
|
-
await client.session.axios.post(REFRESH_PATH,
|
|
588
|
+
await client.session.axios.post(REFRESH_PATH, {});
|
|
703
589
|
} catch (err) {
|
|
704
590
|
const status = extractAxiosStatus(err);
|
|
705
591
|
if (status !== void 0) {
|
|
@@ -917,46 +803,11 @@ var TokenManager = class {
|
|
|
917
803
|
setTenantId(tenantId) {
|
|
918
804
|
this.#tenantId = tenantId;
|
|
919
805
|
}
|
|
920
|
-
/**
|
|
921
|
-
* Best-effort decode of the `tenant_id`/`org_id` claims out of the cached
|
|
922
|
-
* access token, WITHOUT signature verification. Used only to populate the
|
|
923
|
-
* `refresh` request body (`RefreshRequest` requires both UUIDs) — never as a
|
|
924
|
-
* trust decision: the actual credential is the httpOnly `axiam_access` cookie
|
|
925
|
-
* the server verifies, and the server re-derives the authoritative `org_id`
|
|
926
|
-
* from the tenant on refresh (see crates/axiam-api-rest handlers/auth.rs),
|
|
927
|
-
* so echoing these values back carries no security weight. A malformed or
|
|
928
|
-
* absent token yields an empty result (the caller then keeps whatever UUIDs
|
|
929
|
-
* were resolved from construction options).
|
|
930
|
-
*/
|
|
931
|
-
claimsFromCachedToken() {
|
|
932
|
-
const token = this.#cachedAccess?.expose();
|
|
933
|
-
if (!token) {
|
|
934
|
-
return {};
|
|
935
|
-
}
|
|
936
|
-
const claims = decodeJwtPayload(token);
|
|
937
|
-
return {
|
|
938
|
-
tenantId: typeof claims.tenant_id === "string" ? claims.tenant_id : void 0,
|
|
939
|
-
orgId: typeof claims.org_id === "string" ? claims.org_id : void 0
|
|
940
|
-
};
|
|
941
|
-
}
|
|
942
806
|
/** Clear all cached token state (used by logout()). */
|
|
943
807
|
clear() {
|
|
944
808
|
this.#cachedAccess = null;
|
|
945
809
|
}
|
|
946
810
|
};
|
|
947
|
-
function decodeJwtPayload(token) {
|
|
948
|
-
try {
|
|
949
|
-
const segments = token.split(".");
|
|
950
|
-
if (segments.length !== 3) {
|
|
951
|
-
return {};
|
|
952
|
-
}
|
|
953
|
-
const json = Buffer.from(segments[1], "base64url").toString("utf8");
|
|
954
|
-
const parsed = JSON.parse(json);
|
|
955
|
-
return typeof parsed === "object" && parsed !== null ? parsed : {};
|
|
956
|
-
} catch {
|
|
957
|
-
return {};
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
811
|
|
|
961
812
|
// src/node/jwks.ts
|
|
962
813
|
var JWKS_PATH = "/oauth2/jwks";
|
|
@@ -1008,9 +859,8 @@ var NodeSession = class extends SharedSession {
|
|
|
1008
859
|
* remaining fully independent from any other session's guard.
|
|
1009
860
|
*/
|
|
1010
861
|
doRefresh = async () => {
|
|
1011
|
-
await this.axios.post("/api/v1/auth/refresh",
|
|
862
|
+
await this.axios.post("/api/v1/auth/refresh", {});
|
|
1012
863
|
await this.tokenManager.syncFromJar();
|
|
1013
|
-
this.#resolveIdentifiersFromToken();
|
|
1014
864
|
await this.#syncCsrfFromJar();
|
|
1015
865
|
};
|
|
1016
866
|
/**
|
|
@@ -1022,25 +872,8 @@ var NodeSession = class extends SharedSession {
|
|
|
1022
872
|
*/
|
|
1023
873
|
onAuthenticated = async () => {
|
|
1024
874
|
await this.tokenManager.syncFromJar();
|
|
1025
|
-
this.#resolveIdentifiersFromToken();
|
|
1026
875
|
await this.#syncCsrfFromJar();
|
|
1027
876
|
};
|
|
1028
|
-
/**
|
|
1029
|
-
* Populate `resolvedTenantId`/`resolvedOrgId` from the cached access token's
|
|
1030
|
-
* claims when present, leaving any UUID resolved from construction options in
|
|
1031
|
-
* place otherwise. Best-effort and unverified (see
|
|
1032
|
-
* TokenManager.claimsFromCachedToken) — used purely to build the refresh body.
|
|
1033
|
-
*/
|
|
1034
|
-
#resolveIdentifiersFromToken() {
|
|
1035
|
-
const { tenantId, orgId } = this.tokenManager.claimsFromCachedToken();
|
|
1036
|
-
if (tenantId) {
|
|
1037
|
-
this.resolvedTenantId = tenantId;
|
|
1038
|
-
this.tokenManager.setTenantId(tenantId);
|
|
1039
|
-
}
|
|
1040
|
-
if (orgId) {
|
|
1041
|
-
this.resolvedOrgId = orgId;
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
877
|
async #syncCsrfFromJar() {
|
|
1045
878
|
this.csrfToken = await extractCookieValue(this.#jar, this.baseUrl, CSRF_COOKIE);
|
|
1046
879
|
}
|