axiam-sdk 1.0.0-beta16 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +546 -27
- package/dist/amqp/index.d.cts +1 -1
- package/dist/amqp/index.d.ts +1 -1
- package/dist/amqp/index.js +6 -1
- package/dist/amqp/index.js.map +1 -1
- package/dist/amqp/index.mjs +6 -1
- package/dist/amqp/index.mjs.map +1 -1
- package/dist/{authzCore-DJmDAAtw.d.cts → authzCore-BQfX9qxN.d.cts} +33 -6
- package/dist/{authzCore-0fObXIqB.d.ts → authzCore-BlSHwGnW.d.ts} +33 -6
- package/dist/browser/index.d.cts +3 -3
- package/dist/browser/index.d.ts +3 -3
- package/dist/{client-BstRBtp8.d.ts → client-0WJkblDE.d.ts} +2536 -182
- package/dist/{client-Dd_XaOtg.d.cts → client-yD0eMwHQ.d.cts} +2536 -182
- package/dist/{cookieJar-Dvb1Gnwm.d.cts → cookieJar-CTD5jOmd.d.cts} +3 -3
- package/dist/{cookieJar-D0FxzBQG.d.ts → cookieJar-hWRmZkhe.d.ts} +3 -3
- package/dist/errors-CmBvsxV0.d.ts +79 -0
- package/dist/errors-DMIlw2lN.d.cts +101 -0
- package/dist/errors-DMIlw2lN.d.ts +101 -0
- package/dist/errors-m0Tue_pE.d.cts +79 -0
- package/dist/grpc/index.d.cts +219 -12
- package/dist/grpc/index.d.ts +219 -12
- package/dist/grpc/index.js +4178 -1965
- package/dist/grpc/index.js.map +1 -1
- package/dist/grpc/index.mjs +4177 -1966
- package/dist/grpc/index.mjs.map +1 -1
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +4097 -1940
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4059 -1941
- package/dist/index.mjs.map +1 -1
- package/dist/{jwks-CSXHo3DS.d.cts → jwks-BR55d7-Z.d.cts} +36 -13
- package/dist/{jwks-CSXHo3DS.d.ts → jwks-BR55d7-Z.d.ts} +36 -13
- package/dist/middleware/index.d.cts +50 -9
- package/dist/middleware/index.d.ts +50 -9
- package/dist/middleware/index.js +623 -31
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs +621 -33
- 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 +6 -1
- package/dist/nestjs/index.js.map +1 -1
- package/dist/nestjs/index.mjs +6 -1
- package/dist/nestjs/index.mjs.map +1 -1
- package/dist/node/index.d.cts +307 -7
- package/dist/node/index.d.ts +307 -7
- package/dist/node/index.js +4681 -1644
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +4668 -1646
- package/dist/node/index.mjs.map +1 -1
- package/dist/{oidcState-CffZ6PkC.d.ts → oidcState-DOSCgnMG.d.ts} +382 -9
- package/dist/{oidcState-CSi4DY8h.d.cts → oidcState-mQLVn3-A.d.cts} +382 -9
- package/dist/rest/index.d.cts +80 -11
- package/dist/rest/index.d.ts +80 -11
- package/dist/rest/index.js +4097 -1940
- package/dist/rest/index.js.map +1 -1
- package/dist/rest/index.mjs +4059 -1941
- package/dist/rest/index.mjs.map +1 -1
- package/dist/{session-oiuBA1ZA.d.cts → session-BmjEMowX.d.cts} +216 -2
- package/dist/{session-ymrHvMuJ.d.ts → session-CeG6P9GO.d.ts} +216 -2
- package/dist/{telemetry-DrGqL4kb.d.cts → telemetry--0DwnNjV.d.cts} +24 -2
- package/dist/{telemetry-DrGqL4kb.d.ts → telemetry--0DwnNjV.d.ts} +24 -2
- package/package.json +6 -3
- package/dist/errors-CxqAZsex.d.cts +0 -168
- package/dist/errors-CxqAZsex.d.ts +0 -168
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { S as Sensitive } from './sensitive-BC_s7Rrd.cjs';
|
|
3
|
+
import { T as TelemetryHook, a as TelemetryDispatcher, O as Outcome } from './telemetry--0DwnNjV.cjs';
|
|
4
|
+
import { a as AccessDecision } from './types-zXSpiQM-.cjs';
|
|
3
5
|
|
|
4
6
|
/** A session-scoped single-flight guard closure, as returned by `createRefreshGuard()`. */
|
|
5
7
|
type RefreshGuard = (doRefresh: () => Promise<void>) => Promise<void>;
|
|
@@ -123,6 +125,139 @@ interface AxiamClientOptions {
|
|
|
123
125
|
connectTimeoutMs?: number;
|
|
124
126
|
/** Request timeout in milliseconds. Defaults to DEFAULT_REQUEST_TIMEOUT_MS. */
|
|
125
127
|
requestTimeoutMs?: number;
|
|
128
|
+
/**
|
|
129
|
+
* Act on another tenant of the caller's organization from construction —
|
|
130
|
+
* CONTRACT.md §5.2 rule 1 (contract 1.51). Every `/api/v1` REST request
|
|
131
|
+
* then also carries `X-Axiam-Tenant: <this value>`, distinct from the
|
|
132
|
+
* `X-Tenant-ID` header {@link tenantSlug}/{@link tenantId} controls, which
|
|
133
|
+
* is unaffected.
|
|
134
|
+
*
|
|
135
|
+
* Meaningful only for an **organization-level** principal; the server
|
|
136
|
+
* answers `403` for an ordinary tenant principal. Construction cannot gate
|
|
137
|
+
* on that — it precedes the login that would reveal it — so only the UUID
|
|
138
|
+
* shape is checked here, client-side, with no wire call; a client already
|
|
139
|
+
* holding a login result should prefer the on-client {@link
|
|
140
|
+
* AxiamClient.actingTenant}, which also gates on `organizationLevel` and
|
|
141
|
+
* `reachableTenantIds`. REST-only: the gRPC interceptor sends no
|
|
142
|
+
* acting-tenant metadata.
|
|
143
|
+
*/
|
|
144
|
+
actingTenantId?: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The §17.1 rule 2 ceiling. A configured TTL above this is clamped, not
|
|
149
|
+
* rejected: a caller who asked for 60 s wants caching, and silently giving them
|
|
150
|
+
* the maximum safe value beats failing construction.
|
|
151
|
+
*/
|
|
152
|
+
declare const MAX_TTL_MS = 5000;
|
|
153
|
+
/**
|
|
154
|
+
* The §17.1 rule 3 key: all four components, with absent distinguished from
|
|
155
|
+
* present.
|
|
156
|
+
*
|
|
157
|
+
* `\u001f` (unit separator) joins the parts because it cannot appear in an
|
|
158
|
+
* action, a UUID or a scope, so no combination of values can forge a
|
|
159
|
+
* collision. `\u0000` marks an *absent* optional, which is why an absent scope
|
|
160
|
+
* can never collide with a present one — a memo that let them collide would
|
|
161
|
+
* answer a narrower question with a broader answer.
|
|
162
|
+
*
|
|
163
|
+
* `actingTenantId` (contract 1.51, CONTRACT.md §5.2 rule 1's C-12 note) joins
|
|
164
|
+
* the key too, for the same reason: since 1.51 one session can ask the same
|
|
165
|
+
* question of two tenants, and the server can answer differently for each.
|
|
166
|
+
* Without it, a memoized answer for tenant A would be returned for tenant B
|
|
167
|
+
* within the TTL — the memo caching an answer to a question it was never
|
|
168
|
+
* asked. Two absent values (a client that never called `actingTenant()`) are
|
|
169
|
+
* still the same key as before 1.51, so nothing already using this memo sees
|
|
170
|
+
* a behaviour change.
|
|
171
|
+
*/
|
|
172
|
+
declare function memoKey(check: {
|
|
173
|
+
action: string;
|
|
174
|
+
resourceId: string;
|
|
175
|
+
scope?: string;
|
|
176
|
+
subjectId?: string;
|
|
177
|
+
}, actingTenantId?: string): string;
|
|
178
|
+
/**
|
|
179
|
+
* A bounded, TTL-clamped decision memo.
|
|
180
|
+
*
|
|
181
|
+
* `ttlMs === 0` means **disabled** — not "cache for zero milliseconds". That is
|
|
182
|
+
* the default, and both `get` and `set` become no-ops.
|
|
183
|
+
*/
|
|
184
|
+
declare class DecisionMemo {
|
|
185
|
+
/** Injected so the TTL can be tested without waiting. */
|
|
186
|
+
private readonly now;
|
|
187
|
+
private readonly ttlMs;
|
|
188
|
+
private readonly entries;
|
|
189
|
+
/**
|
|
190
|
+
* @param ttlMs requested TTL in milliseconds; `0` disables the memo and any
|
|
191
|
+
* value above {@link MAX_TTL_MS} is clamped to it.
|
|
192
|
+
* @param now injected clock, so the TTL can be tested without waiting.
|
|
193
|
+
*/
|
|
194
|
+
constructor(ttlMs?: number,
|
|
195
|
+
/** Injected so the TTL can be tested without waiting. */
|
|
196
|
+
now?: () => number);
|
|
197
|
+
/** Whether this memo does anything. `false` for the default configuration. */
|
|
198
|
+
get enabled(): boolean;
|
|
199
|
+
/** The effective TTL after clamping. */
|
|
200
|
+
get effectiveTtlMs(): number;
|
|
201
|
+
/** A live decision for `key`, if one is memoized and unexpired. */
|
|
202
|
+
get(key: string): AccessDecision | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Memoize a decision the server actually returned.
|
|
205
|
+
*
|
|
206
|
+
* Callers must only reach here on success. §17.1 rule 7 forbids
|
|
207
|
+
* negative-caching a failure: memoizing a transport error as a deny would
|
|
208
|
+
* turn a blip into a TTL-long outage, and memoizing it as an allow is
|
|
209
|
+
* unthinkable.
|
|
210
|
+
*/
|
|
211
|
+
set(key: string, decision: AccessDecision): void;
|
|
212
|
+
/**
|
|
213
|
+
* Drop every entry (§17.1 rule 9).
|
|
214
|
+
*
|
|
215
|
+
* Called on login, verifyMfa, refresh and logout. Entries are keyed by
|
|
216
|
+
* subject, not by session, so a re-authentication as a *different* principal
|
|
217
|
+
* would otherwise read the previous principal's decisions.
|
|
218
|
+
*/
|
|
219
|
+
clear(): void;
|
|
220
|
+
/**
|
|
221
|
+
* Emit a {@link ConfigClampedEvent} if the requested TTL was clamped (§19.2
|
|
222
|
+
* rule 6).
|
|
223
|
+
*
|
|
224
|
+
* This is the clamp that matters most to get right: an operator who set a
|
|
225
|
+
* 60-second TTL believes their staleness bound is 60 seconds. It is five, and
|
|
226
|
+
* without this event nothing anywhere says so.
|
|
227
|
+
*
|
|
228
|
+
* Nothing is emitted when the requested value was already inside the limit,
|
|
229
|
+
* or when the memo is disabled — an event that fires when nothing happened
|
|
230
|
+
* trains its reader to ignore it.
|
|
231
|
+
*/
|
|
232
|
+
reportClamp(requestedMs: number, telemetry: TelemetryDispatcher): void;
|
|
233
|
+
/** Entry count, for tests. */
|
|
234
|
+
get size(): number;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Closes a §19 request pair. Call exactly once, on every exit path. */
|
|
238
|
+
type FinishRequest = (status: number | undefined, outcome: Outcome) => void;
|
|
239
|
+
/**
|
|
240
|
+
* Emits the §19 `requestStart`/`requestEnd` pair around one **attempt**.
|
|
241
|
+
*
|
|
242
|
+
* Per attempt, not per logical call: §19.2 rule 5 requires a caller to be able
|
|
243
|
+
* to count real wire calls from the events, which one pair per operation would
|
|
244
|
+
* hide — a retried call would look like a single slow one.
|
|
245
|
+
*/
|
|
246
|
+
declare class TelemetryReporter {
|
|
247
|
+
/** The underlying §19 dispatcher. */
|
|
248
|
+
readonly dispatcher: TelemetryDispatcher;
|
|
249
|
+
/** @param dispatcher the sink these events are emitted to. */
|
|
250
|
+
constructor(
|
|
251
|
+
/** The underlying §19 dispatcher. */
|
|
252
|
+
dispatcher: TelemetryDispatcher);
|
|
253
|
+
/**
|
|
254
|
+
* Emit `requestStart` and return the function that emits its `requestEnd`.
|
|
255
|
+
*
|
|
256
|
+
* `pathTemplate` must be the route constant — `/api/v1/authz/check`, never a
|
|
257
|
+
* path with ids substituted in. A metric label carrying a UUID is a
|
|
258
|
+
* cardinality bomb.
|
|
259
|
+
*/
|
|
260
|
+
startRequest(operation: string, method: string, pathTemplate: string, attempt?: number): FinishRequest;
|
|
126
261
|
}
|
|
127
262
|
|
|
128
263
|
/**
|
|
@@ -189,6 +324,85 @@ declare class SharedSession {
|
|
|
189
324
|
csrfToken: string | undefined;
|
|
190
325
|
/** Set true once a successful login/verifyMfa has completed. */
|
|
191
326
|
authenticated: boolean;
|
|
327
|
+
/**
|
|
328
|
+
* §17 decision memo (contract 1.51: moved here from `AxiamClient` so every
|
|
329
|
+
* handle sharing this session — the base client and any
|
|
330
|
+
* `actingTenant(id)`/`clearActingTenant()` clone of it — shares one memo
|
|
331
|
+
* rather than each getting an empty one of its own). Disabled unless
|
|
332
|
+
* `decisionMemoTtlMs` was configured.
|
|
333
|
+
*/
|
|
334
|
+
readonly decisionMemo: DecisionMemo;
|
|
335
|
+
/**
|
|
336
|
+
* §19 telemetry dispatcher (moved here alongside `decisionMemo`, same
|
|
337
|
+
* reason). Empty unless a hook was installed.
|
|
338
|
+
*/
|
|
339
|
+
readonly telemetry: TelemetryReporter;
|
|
340
|
+
/** §16.1 disable switch (moved here alongside `decisionMemo`). Defaults to enabled. */
|
|
341
|
+
readonly retryEnabled: boolean;
|
|
342
|
+
/**
|
|
343
|
+
* §18 shutdown flag (moved here from `AxiamClient`, contract 1.51): a
|
|
344
|
+
* handle and every clone of it sharing this session close together, exactly
|
|
345
|
+
* as the Rust reference's `Arc<AxiamClientInner>` closes every handle over
|
|
346
|
+
* it. Set once by `AxiamClient.close()`; read by `ensureOpen()`.
|
|
347
|
+
*/
|
|
348
|
+
closed: boolean;
|
|
349
|
+
/**
|
|
350
|
+
* Whether {@link installInterceptors} has already run for this session's
|
|
351
|
+
* axios instance (contract 1.51). Guards `AxiamClient.actingTenant()` /
|
|
352
|
+
* `.clearActingTenant()`, which construct a second `AxiamClient` handle
|
|
353
|
+
* over this same session: without this flag that second construction would
|
|
354
|
+
* install the CSRF/refresh interceptors a second time, double-running them
|
|
355
|
+
* on every request. Checked and set only by `rest/client.ts`.
|
|
356
|
+
*
|
|
357
|
+
* @internal
|
|
358
|
+
*/
|
|
359
|
+
interceptorsInstalled: boolean;
|
|
360
|
+
/**
|
|
361
|
+
* CONTRACT.md §5.2 / §5.2.3 (contract 1.51) — what the last completed login
|
|
362
|
+
* reported about the principal's reach, when it reported anything at all.
|
|
363
|
+
*
|
|
364
|
+
* `undefined` until a session-establishing response has carried a user
|
|
365
|
+
* object, and reset to `undefined` by `logout()` and by
|
|
366
|
+
* `authenticateDevice()` (§6.1: a device token is a service-account
|
|
367
|
+
* credential with no `LoginUserInfo` behind it). It is `undefined` on
|
|
368
|
+
* purpose rather than a defaulted `false` — "the server did not say"
|
|
369
|
+
* must not gate `AxiamClient.actingTenant()` as though the server had
|
|
370
|
+
* said "not organization-level" (§5.2 rule 1: a client holding no login
|
|
371
|
+
* result has nothing to gate on, so it sends the header and lets the
|
|
372
|
+
* server's `403` decide).
|
|
373
|
+
*
|
|
374
|
+
* Shared across every handle over this session, not per-handle — the
|
|
375
|
+
* principal did not change because a caller asked for a different acting
|
|
376
|
+
* tenant.
|
|
377
|
+
*/
|
|
378
|
+
principalScope: {
|
|
379
|
+
/** What the login response's `organizationLevel` reported. */
|
|
380
|
+
organizationLevel: boolean;
|
|
381
|
+
/** What the login response's `reachableTenantIds` reported, if present. `undefined` means unrestricted. */
|
|
382
|
+
reachableTenantIds?: string[];
|
|
383
|
+
} | undefined;
|
|
384
|
+
/**
|
|
385
|
+
* CONTRACT.md §6.1 rules 6–10 (contract 1.51) — the access token
|
|
386
|
+
* `authenticateDevice()` adopted, when this session's credential is a
|
|
387
|
+
* device/mTLS one rather than a cookie session.
|
|
388
|
+
*
|
|
389
|
+
* `undefined` is the state every session starts in and the only one
|
|
390
|
+
* before contract 1.51: nothing about REST authentication changes for a
|
|
391
|
+
* client that never calls `authenticateDevice()`. Once set, the request
|
|
392
|
+
* interceptor installed in `createSession` sends it as
|
|
393
|
+
* `Authorization: Bearer <token>` and switches this request to the
|
|
394
|
+
* jar-free agent pair `noCredentialsConfig()` builds — the server reads
|
|
395
|
+
* the `axiam_access` cookie **before** the `Authorization` header (rule 3
|
|
396
|
+
* of the "what the plan did not anticipate" note), so a cookie left over
|
|
397
|
+
* from an earlier session would otherwise silently outrank this token and
|
|
398
|
+
* the request would run as that earlier session's principal. There is no
|
|
399
|
+
* refresh token behind a device token (rule 6), so `installRefreshInterceptor`
|
|
400
|
+
* checks this field too and never attempts one.
|
|
401
|
+
*
|
|
402
|
+
* Cleared by `logout()`, and by a subsequent `login()`/`verifyMfa()` that
|
|
403
|
+
* establishes an ordinary cookie session on the same client.
|
|
404
|
+
*/
|
|
405
|
+
deviceAccessToken: Sensitive<string> | undefined;
|
|
192
406
|
/**
|
|
193
407
|
* Per-instance single-flight refresh guard (CR-02, D-13). Shared across
|
|
194
408
|
* this session's REST and gRPC transports (rest/interceptors.ts,
|
|
@@ -264,4 +478,4 @@ interface NodeTlsOptions {
|
|
|
264
478
|
key?: string;
|
|
265
479
|
}
|
|
266
480
|
|
|
267
|
-
export { type AxiamClientOptions as A, type NodeTlsOptions as N, SharedSession as S };
|
|
481
|
+
export { type AxiamClientOptions as A, DecisionMemo as D, type FinishRequest as F, MAX_TTL_MS as M, type NodeTlsOptions as N, SharedSession as S, TelemetryReporter as T, memoKey as m };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { S as Sensitive } from './sensitive-BC_s7Rrd.js';
|
|
3
|
+
import { T as TelemetryHook, a as TelemetryDispatcher, O as Outcome } from './telemetry--0DwnNjV.js';
|
|
4
|
+
import { a as AccessDecision } from './types-BOX-6Srv.js';
|
|
3
5
|
|
|
4
6
|
/** A session-scoped single-flight guard closure, as returned by `createRefreshGuard()`. */
|
|
5
7
|
type RefreshGuard = (doRefresh: () => Promise<void>) => Promise<void>;
|
|
@@ -123,6 +125,139 @@ interface AxiamClientOptions {
|
|
|
123
125
|
connectTimeoutMs?: number;
|
|
124
126
|
/** Request timeout in milliseconds. Defaults to DEFAULT_REQUEST_TIMEOUT_MS. */
|
|
125
127
|
requestTimeoutMs?: number;
|
|
128
|
+
/**
|
|
129
|
+
* Act on another tenant of the caller's organization from construction —
|
|
130
|
+
* CONTRACT.md §5.2 rule 1 (contract 1.51). Every `/api/v1` REST request
|
|
131
|
+
* then also carries `X-Axiam-Tenant: <this value>`, distinct from the
|
|
132
|
+
* `X-Tenant-ID` header {@link tenantSlug}/{@link tenantId} controls, which
|
|
133
|
+
* is unaffected.
|
|
134
|
+
*
|
|
135
|
+
* Meaningful only for an **organization-level** principal; the server
|
|
136
|
+
* answers `403` for an ordinary tenant principal. Construction cannot gate
|
|
137
|
+
* on that — it precedes the login that would reveal it — so only the UUID
|
|
138
|
+
* shape is checked here, client-side, with no wire call; a client already
|
|
139
|
+
* holding a login result should prefer the on-client {@link
|
|
140
|
+
* AxiamClient.actingTenant}, which also gates on `organizationLevel` and
|
|
141
|
+
* `reachableTenantIds`. REST-only: the gRPC interceptor sends no
|
|
142
|
+
* acting-tenant metadata.
|
|
143
|
+
*/
|
|
144
|
+
actingTenantId?: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The §17.1 rule 2 ceiling. A configured TTL above this is clamped, not
|
|
149
|
+
* rejected: a caller who asked for 60 s wants caching, and silently giving them
|
|
150
|
+
* the maximum safe value beats failing construction.
|
|
151
|
+
*/
|
|
152
|
+
declare const MAX_TTL_MS = 5000;
|
|
153
|
+
/**
|
|
154
|
+
* The §17.1 rule 3 key: all four components, with absent distinguished from
|
|
155
|
+
* present.
|
|
156
|
+
*
|
|
157
|
+
* `\u001f` (unit separator) joins the parts because it cannot appear in an
|
|
158
|
+
* action, a UUID or a scope, so no combination of values can forge a
|
|
159
|
+
* collision. `\u0000` marks an *absent* optional, which is why an absent scope
|
|
160
|
+
* can never collide with a present one — a memo that let them collide would
|
|
161
|
+
* answer a narrower question with a broader answer.
|
|
162
|
+
*
|
|
163
|
+
* `actingTenantId` (contract 1.51, CONTRACT.md §5.2 rule 1's C-12 note) joins
|
|
164
|
+
* the key too, for the same reason: since 1.51 one session can ask the same
|
|
165
|
+
* question of two tenants, and the server can answer differently for each.
|
|
166
|
+
* Without it, a memoized answer for tenant A would be returned for tenant B
|
|
167
|
+
* within the TTL — the memo caching an answer to a question it was never
|
|
168
|
+
* asked. Two absent values (a client that never called `actingTenant()`) are
|
|
169
|
+
* still the same key as before 1.51, so nothing already using this memo sees
|
|
170
|
+
* a behaviour change.
|
|
171
|
+
*/
|
|
172
|
+
declare function memoKey(check: {
|
|
173
|
+
action: string;
|
|
174
|
+
resourceId: string;
|
|
175
|
+
scope?: string;
|
|
176
|
+
subjectId?: string;
|
|
177
|
+
}, actingTenantId?: string): string;
|
|
178
|
+
/**
|
|
179
|
+
* A bounded, TTL-clamped decision memo.
|
|
180
|
+
*
|
|
181
|
+
* `ttlMs === 0` means **disabled** — not "cache for zero milliseconds". That is
|
|
182
|
+
* the default, and both `get` and `set` become no-ops.
|
|
183
|
+
*/
|
|
184
|
+
declare class DecisionMemo {
|
|
185
|
+
/** Injected so the TTL can be tested without waiting. */
|
|
186
|
+
private readonly now;
|
|
187
|
+
private readonly ttlMs;
|
|
188
|
+
private readonly entries;
|
|
189
|
+
/**
|
|
190
|
+
* @param ttlMs requested TTL in milliseconds; `0` disables the memo and any
|
|
191
|
+
* value above {@link MAX_TTL_MS} is clamped to it.
|
|
192
|
+
* @param now injected clock, so the TTL can be tested without waiting.
|
|
193
|
+
*/
|
|
194
|
+
constructor(ttlMs?: number,
|
|
195
|
+
/** Injected so the TTL can be tested without waiting. */
|
|
196
|
+
now?: () => number);
|
|
197
|
+
/** Whether this memo does anything. `false` for the default configuration. */
|
|
198
|
+
get enabled(): boolean;
|
|
199
|
+
/** The effective TTL after clamping. */
|
|
200
|
+
get effectiveTtlMs(): number;
|
|
201
|
+
/** A live decision for `key`, if one is memoized and unexpired. */
|
|
202
|
+
get(key: string): AccessDecision | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Memoize a decision the server actually returned.
|
|
205
|
+
*
|
|
206
|
+
* Callers must only reach here on success. §17.1 rule 7 forbids
|
|
207
|
+
* negative-caching a failure: memoizing a transport error as a deny would
|
|
208
|
+
* turn a blip into a TTL-long outage, and memoizing it as an allow is
|
|
209
|
+
* unthinkable.
|
|
210
|
+
*/
|
|
211
|
+
set(key: string, decision: AccessDecision): void;
|
|
212
|
+
/**
|
|
213
|
+
* Drop every entry (§17.1 rule 9).
|
|
214
|
+
*
|
|
215
|
+
* Called on login, verifyMfa, refresh and logout. Entries are keyed by
|
|
216
|
+
* subject, not by session, so a re-authentication as a *different* principal
|
|
217
|
+
* would otherwise read the previous principal's decisions.
|
|
218
|
+
*/
|
|
219
|
+
clear(): void;
|
|
220
|
+
/**
|
|
221
|
+
* Emit a {@link ConfigClampedEvent} if the requested TTL was clamped (§19.2
|
|
222
|
+
* rule 6).
|
|
223
|
+
*
|
|
224
|
+
* This is the clamp that matters most to get right: an operator who set a
|
|
225
|
+
* 60-second TTL believes their staleness bound is 60 seconds. It is five, and
|
|
226
|
+
* without this event nothing anywhere says so.
|
|
227
|
+
*
|
|
228
|
+
* Nothing is emitted when the requested value was already inside the limit,
|
|
229
|
+
* or when the memo is disabled — an event that fires when nothing happened
|
|
230
|
+
* trains its reader to ignore it.
|
|
231
|
+
*/
|
|
232
|
+
reportClamp(requestedMs: number, telemetry: TelemetryDispatcher): void;
|
|
233
|
+
/** Entry count, for tests. */
|
|
234
|
+
get size(): number;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Closes a §19 request pair. Call exactly once, on every exit path. */
|
|
238
|
+
type FinishRequest = (status: number | undefined, outcome: Outcome) => void;
|
|
239
|
+
/**
|
|
240
|
+
* Emits the §19 `requestStart`/`requestEnd` pair around one **attempt**.
|
|
241
|
+
*
|
|
242
|
+
* Per attempt, not per logical call: §19.2 rule 5 requires a caller to be able
|
|
243
|
+
* to count real wire calls from the events, which one pair per operation would
|
|
244
|
+
* hide — a retried call would look like a single slow one.
|
|
245
|
+
*/
|
|
246
|
+
declare class TelemetryReporter {
|
|
247
|
+
/** The underlying §19 dispatcher. */
|
|
248
|
+
readonly dispatcher: TelemetryDispatcher;
|
|
249
|
+
/** @param dispatcher the sink these events are emitted to. */
|
|
250
|
+
constructor(
|
|
251
|
+
/** The underlying §19 dispatcher. */
|
|
252
|
+
dispatcher: TelemetryDispatcher);
|
|
253
|
+
/**
|
|
254
|
+
* Emit `requestStart` and return the function that emits its `requestEnd`.
|
|
255
|
+
*
|
|
256
|
+
* `pathTemplate` must be the route constant — `/api/v1/authz/check`, never a
|
|
257
|
+
* path with ids substituted in. A metric label carrying a UUID is a
|
|
258
|
+
* cardinality bomb.
|
|
259
|
+
*/
|
|
260
|
+
startRequest(operation: string, method: string, pathTemplate: string, attempt?: number): FinishRequest;
|
|
126
261
|
}
|
|
127
262
|
|
|
128
263
|
/**
|
|
@@ -189,6 +324,85 @@ declare class SharedSession {
|
|
|
189
324
|
csrfToken: string | undefined;
|
|
190
325
|
/** Set true once a successful login/verifyMfa has completed. */
|
|
191
326
|
authenticated: boolean;
|
|
327
|
+
/**
|
|
328
|
+
* §17 decision memo (contract 1.51: moved here from `AxiamClient` so every
|
|
329
|
+
* handle sharing this session — the base client and any
|
|
330
|
+
* `actingTenant(id)`/`clearActingTenant()` clone of it — shares one memo
|
|
331
|
+
* rather than each getting an empty one of its own). Disabled unless
|
|
332
|
+
* `decisionMemoTtlMs` was configured.
|
|
333
|
+
*/
|
|
334
|
+
readonly decisionMemo: DecisionMemo;
|
|
335
|
+
/**
|
|
336
|
+
* §19 telemetry dispatcher (moved here alongside `decisionMemo`, same
|
|
337
|
+
* reason). Empty unless a hook was installed.
|
|
338
|
+
*/
|
|
339
|
+
readonly telemetry: TelemetryReporter;
|
|
340
|
+
/** §16.1 disable switch (moved here alongside `decisionMemo`). Defaults to enabled. */
|
|
341
|
+
readonly retryEnabled: boolean;
|
|
342
|
+
/**
|
|
343
|
+
* §18 shutdown flag (moved here from `AxiamClient`, contract 1.51): a
|
|
344
|
+
* handle and every clone of it sharing this session close together, exactly
|
|
345
|
+
* as the Rust reference's `Arc<AxiamClientInner>` closes every handle over
|
|
346
|
+
* it. Set once by `AxiamClient.close()`; read by `ensureOpen()`.
|
|
347
|
+
*/
|
|
348
|
+
closed: boolean;
|
|
349
|
+
/**
|
|
350
|
+
* Whether {@link installInterceptors} has already run for this session's
|
|
351
|
+
* axios instance (contract 1.51). Guards `AxiamClient.actingTenant()` /
|
|
352
|
+
* `.clearActingTenant()`, which construct a second `AxiamClient` handle
|
|
353
|
+
* over this same session: without this flag that second construction would
|
|
354
|
+
* install the CSRF/refresh interceptors a second time, double-running them
|
|
355
|
+
* on every request. Checked and set only by `rest/client.ts`.
|
|
356
|
+
*
|
|
357
|
+
* @internal
|
|
358
|
+
*/
|
|
359
|
+
interceptorsInstalled: boolean;
|
|
360
|
+
/**
|
|
361
|
+
* CONTRACT.md §5.2 / §5.2.3 (contract 1.51) — what the last completed login
|
|
362
|
+
* reported about the principal's reach, when it reported anything at all.
|
|
363
|
+
*
|
|
364
|
+
* `undefined` until a session-establishing response has carried a user
|
|
365
|
+
* object, and reset to `undefined` by `logout()` and by
|
|
366
|
+
* `authenticateDevice()` (§6.1: a device token is a service-account
|
|
367
|
+
* credential with no `LoginUserInfo` behind it). It is `undefined` on
|
|
368
|
+
* purpose rather than a defaulted `false` — "the server did not say"
|
|
369
|
+
* must not gate `AxiamClient.actingTenant()` as though the server had
|
|
370
|
+
* said "not organization-level" (§5.2 rule 1: a client holding no login
|
|
371
|
+
* result has nothing to gate on, so it sends the header and lets the
|
|
372
|
+
* server's `403` decide).
|
|
373
|
+
*
|
|
374
|
+
* Shared across every handle over this session, not per-handle — the
|
|
375
|
+
* principal did not change because a caller asked for a different acting
|
|
376
|
+
* tenant.
|
|
377
|
+
*/
|
|
378
|
+
principalScope: {
|
|
379
|
+
/** What the login response's `organizationLevel` reported. */
|
|
380
|
+
organizationLevel: boolean;
|
|
381
|
+
/** What the login response's `reachableTenantIds` reported, if present. `undefined` means unrestricted. */
|
|
382
|
+
reachableTenantIds?: string[];
|
|
383
|
+
} | undefined;
|
|
384
|
+
/**
|
|
385
|
+
* CONTRACT.md §6.1 rules 6–10 (contract 1.51) — the access token
|
|
386
|
+
* `authenticateDevice()` adopted, when this session's credential is a
|
|
387
|
+
* device/mTLS one rather than a cookie session.
|
|
388
|
+
*
|
|
389
|
+
* `undefined` is the state every session starts in and the only one
|
|
390
|
+
* before contract 1.51: nothing about REST authentication changes for a
|
|
391
|
+
* client that never calls `authenticateDevice()`. Once set, the request
|
|
392
|
+
* interceptor installed in `createSession` sends it as
|
|
393
|
+
* `Authorization: Bearer <token>` and switches this request to the
|
|
394
|
+
* jar-free agent pair `noCredentialsConfig()` builds — the server reads
|
|
395
|
+
* the `axiam_access` cookie **before** the `Authorization` header (rule 3
|
|
396
|
+
* of the "what the plan did not anticipate" note), so a cookie left over
|
|
397
|
+
* from an earlier session would otherwise silently outrank this token and
|
|
398
|
+
* the request would run as that earlier session's principal. There is no
|
|
399
|
+
* refresh token behind a device token (rule 6), so `installRefreshInterceptor`
|
|
400
|
+
* checks this field too and never attempts one.
|
|
401
|
+
*
|
|
402
|
+
* Cleared by `logout()`, and by a subsequent `login()`/`verifyMfa()` that
|
|
403
|
+
* establishes an ordinary cookie session on the same client.
|
|
404
|
+
*/
|
|
405
|
+
deviceAccessToken: Sensitive<string> | undefined;
|
|
192
406
|
/**
|
|
193
407
|
* Per-instance single-flight refresh guard (CR-02, D-13). Shared across
|
|
194
408
|
* this session's REST and gRPC transports (rest/interceptors.ts,
|
|
@@ -264,4 +478,4 @@ interface NodeTlsOptions {
|
|
|
264
478
|
key?: string;
|
|
265
479
|
}
|
|
266
480
|
|
|
267
|
-
export { type AxiamClientOptions as A, type NodeTlsOptions as N, SharedSession as S };
|
|
481
|
+
export { type AxiamClientOptions as A, DecisionMemo as D, type FinishRequest as F, MAX_TTL_MS as M, type NodeTlsOptions as N, SharedSession as S, TelemetryReporter as T, memoKey as m };
|
|
@@ -94,8 +94,30 @@ interface ConfigClampedEvent {
|
|
|
94
94
|
/** The §-reference for the limit, e.g. `§17.1 rule 2`. */
|
|
95
95
|
contractReference: string;
|
|
96
96
|
}
|
|
97
|
+
/** Why an SSF poll left SETs unjudged: the JWKS (or discovery) fetch, or the replay store. */
|
|
98
|
+
type SsfUnjudgedCategory = 'key_fetch' | 'replay_store';
|
|
99
|
+
/**
|
|
100
|
+
* Emitted when `SsfReceiver.poll` returns normally leaving at least one SET
|
|
101
|
+
* unjudged (contract 1.60, §19.1's SHOULD; §34.2 P1) — one event per failure
|
|
102
|
+
* category present in the batch.
|
|
103
|
+
*
|
|
104
|
+
* A poll that accepted some SETs cannot raise without losing them, so it
|
|
105
|
+
* returns and lists the rest in `unjudged`; this event is what makes that
|
|
106
|
+
* outage visible to an operator who never inspects the list. It carries a
|
|
107
|
+
* count, never a `jti` or a SET.
|
|
108
|
+
*/
|
|
109
|
+
interface SsfUnjudgedEvent {
|
|
110
|
+
/** Discriminant. */
|
|
111
|
+
type: 'ssfUnjudged';
|
|
112
|
+
/** Canonical operation name: `ssf.poll`. */
|
|
113
|
+
operation: string;
|
|
114
|
+
/** How many SETs of the batch this category left unjudged. */
|
|
115
|
+
count: number;
|
|
116
|
+
/** The failure that left them unjudged. */
|
|
117
|
+
category: SsfUnjudgedCategory;
|
|
118
|
+
}
|
|
97
119
|
/** A §19 telemetry event. Closed union — see the file header for why. */
|
|
98
|
-
type TelemetryEvent = RequestStartEvent | RequestEndEvent | RetryEvent | RefreshEvent | ConfigClampedEvent;
|
|
120
|
+
type TelemetryEvent = RequestStartEvent | RequestEndEvent | RetryEvent | RefreshEvent | ConfigClampedEvent | SsfUnjudgedEvent;
|
|
99
121
|
/**
|
|
100
122
|
* A caller-supplied telemetry sink (§19).
|
|
101
123
|
*
|
|
@@ -121,4 +143,4 @@ declare class TelemetryDispatcher {
|
|
|
121
143
|
get installed(): boolean;
|
|
122
144
|
}
|
|
123
145
|
|
|
124
|
-
export { type ConfigClampedEvent as C, type Outcome as O, type RefreshEvent as R, type TelemetryHook as T, TelemetryDispatcher as a, type RefreshRole as b, type RequestEndEvent as c, type RequestStartEvent as d, type RetryEvent as e, type
|
|
146
|
+
export { type ConfigClampedEvent as C, type Outcome as O, type RefreshEvent as R, type SsfUnjudgedCategory as S, type TelemetryHook as T, TelemetryDispatcher as a, type RefreshRole as b, type RequestEndEvent as c, type RequestStartEvent as d, type RetryEvent as e, type SsfUnjudgedEvent as f, type TelemetryEvent as g };
|
|
@@ -94,8 +94,30 @@ interface ConfigClampedEvent {
|
|
|
94
94
|
/** The §-reference for the limit, e.g. `§17.1 rule 2`. */
|
|
95
95
|
contractReference: string;
|
|
96
96
|
}
|
|
97
|
+
/** Why an SSF poll left SETs unjudged: the JWKS (or discovery) fetch, or the replay store. */
|
|
98
|
+
type SsfUnjudgedCategory = 'key_fetch' | 'replay_store';
|
|
99
|
+
/**
|
|
100
|
+
* Emitted when `SsfReceiver.poll` returns normally leaving at least one SET
|
|
101
|
+
* unjudged (contract 1.60, §19.1's SHOULD; §34.2 P1) — one event per failure
|
|
102
|
+
* category present in the batch.
|
|
103
|
+
*
|
|
104
|
+
* A poll that accepted some SETs cannot raise without losing them, so it
|
|
105
|
+
* returns and lists the rest in `unjudged`; this event is what makes that
|
|
106
|
+
* outage visible to an operator who never inspects the list. It carries a
|
|
107
|
+
* count, never a `jti` or a SET.
|
|
108
|
+
*/
|
|
109
|
+
interface SsfUnjudgedEvent {
|
|
110
|
+
/** Discriminant. */
|
|
111
|
+
type: 'ssfUnjudged';
|
|
112
|
+
/** Canonical operation name: `ssf.poll`. */
|
|
113
|
+
operation: string;
|
|
114
|
+
/** How many SETs of the batch this category left unjudged. */
|
|
115
|
+
count: number;
|
|
116
|
+
/** The failure that left them unjudged. */
|
|
117
|
+
category: SsfUnjudgedCategory;
|
|
118
|
+
}
|
|
97
119
|
/** A §19 telemetry event. Closed union — see the file header for why. */
|
|
98
|
-
type TelemetryEvent = RequestStartEvent | RequestEndEvent | RetryEvent | RefreshEvent | ConfigClampedEvent;
|
|
120
|
+
type TelemetryEvent = RequestStartEvent | RequestEndEvent | RetryEvent | RefreshEvent | ConfigClampedEvent | SsfUnjudgedEvent;
|
|
99
121
|
/**
|
|
100
122
|
* A caller-supplied telemetry sink (§19).
|
|
101
123
|
*
|
|
@@ -121,4 +143,4 @@ declare class TelemetryDispatcher {
|
|
|
121
143
|
get installed(): boolean;
|
|
122
144
|
}
|
|
123
145
|
|
|
124
|
-
export { type ConfigClampedEvent as C, type Outcome as O, type RefreshEvent as R, type TelemetryHook as T, TelemetryDispatcher as a, type RefreshRole as b, type RequestEndEvent as c, type RequestStartEvent as d, type RetryEvent as e, type
|
|
146
|
+
export { type ConfigClampedEvent as C, type Outcome as O, type RefreshEvent as R, type SsfUnjudgedCategory as S, type TelemetryHook as T, TelemetryDispatcher as a, type RefreshRole as b, type RequestEndEvent as c, type RequestStartEvent as d, type RetryEvent as e, type SsfUnjudgedEvent as f, type TelemetryEvent as g };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axiam-sdk",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Official TypeScript/JavaScript client SDK for AXIAM IAM",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -160,7 +160,10 @@
|
|
|
160
160
|
}
|
|
161
161
|
},
|
|
162
162
|
"overrides": {
|
|
163
|
-
"esbuild": "^0.28.1"
|
|
163
|
+
"esbuild": "^0.28.1",
|
|
164
|
+
"@vitest/mocker": {
|
|
165
|
+
"msw": "$msw"
|
|
166
|
+
}
|
|
164
167
|
},
|
|
165
168
|
"devDependencies": {
|
|
166
169
|
"@nestjs/common": "^12.0.1",
|
|
@@ -173,7 +176,7 @@
|
|
|
173
176
|
"express": "^5.2.1",
|
|
174
177
|
"fastify": "^5.10.0",
|
|
175
178
|
"jsdom": "^30.0.0",
|
|
176
|
-
"msw": "^
|
|
179
|
+
"msw": "^3.0.2",
|
|
177
180
|
"reflect-metadata": "^0.2.2",
|
|
178
181
|
"rxjs": "^7.8.2",
|
|
179
182
|
"ts-proto": "^2.12.0",
|