@xemahq/authorization-internal-api-client 0.3.10 → 0.4.3

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.
@@ -47,6 +47,28 @@ export interface ClientConfig {
47
47
  getAuthToken?: () => Promise<string>;
48
48
  /** Optional callback returning headers to inject on every request. Per-call headers take precedence. */
49
49
  getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
50
+ /**
51
+ * Optional resolver for the CORRELATION ID of the request being made — the
52
+ * handle that ties one causal chain together across every service hop.
53
+ *
54
+ * WHY IT IS A CALLBACK AND NOT A VALUE. `ClientConfig` is process-global
55
+ * (`configureClient` is called once at wiring time), and a correlation id is
56
+ * per-request. This is invoked INSIDE the request, so a server can point it
57
+ * at whatever carries its ambient request context and get the CURRENT id
58
+ * rather than the one that happened to be live at boot.
59
+ *
60
+ * WHY THE TRANSPORT DOES NOT MINT ONE. Returning `undefined` sends no header,
61
+ * and the receiving service's `RequestContextMiddleware` mints its own — a
62
+ * new trace, which is honest. A transport that minted per call would produce
63
+ * a FRESH id on every hop while looking like propagation, which is strictly
64
+ * worse than none: every row would carry a correlation id and no two rows
65
+ * that belong together would share one. That is the exact defect this exists
66
+ * to fix, so the transport must not reproduce it one layer down.
67
+ *
68
+ * A caller-supplied `X-Correlation-Id` header always wins, and so does one
69
+ * from `getHeaders`.
70
+ */
71
+ getCorrelationId?: () => string | undefined | Promise<string | undefined>;
50
72
  /**
51
73
  * Optional callback invoked on a 401 before ONE re-attempt. Supplying it is
52
74
  * what opts this client into that re-attempt; without it a 401 comes back to
@@ -89,6 +89,16 @@ function getClientConfig() {
89
89
  */
90
90
  /** The only statuses that state the request was NOT processed. See above. */
91
91
  const RETRYABLE_STATUSES = [429, 503];
92
+ /**
93
+ * The platform's correlation header, spelled once.
94
+ *
95
+ * Value-identical to what `RequestContextMiddleware` reads in
96
+ * `@xemahq/platform-common`. It is a literal here rather than an import
97
+ * because this file has ZERO imports on purpose: it ships byte-identical into
98
+ * browser-target clients as well as server-target ones, and a dependency on a
99
+ * NestJS-peer package would follow it into every one of them.
100
+ */
101
+ const CORRELATION_ID_HEADER = 'X-Correlation-Id';
92
102
  /** Backoff floor, doubling per attempt up to {@link MAX_BACKOFF_MS}. */
93
103
  const BASE_BACKOFF_MS = 1000;
94
104
  /** Ceiling on a single backoff, however many attempts have elapsed. */
@@ -104,6 +114,23 @@ async function buildHeaders(config, callerHeaders) {
104
114
  }
105
115
  }
106
116
  }
117
+ // Correlation id (caller and global headers still take precedence).
118
+ //
119
+ // Without this, every server-to-server hop through a generated client started
120
+ // a NEW trace: the id is read-or-minted per hop by the receiving service's
121
+ // RequestContextMiddleware, and nothing carried it outbound — so an audit
122
+ // journal could record a whole causal chain and offer no way to join it back
123
+ // together.
124
+ //
125
+ // Absent resolver, or a resolver that answers `undefined`: NO header. The
126
+ // receiver mints and a new trace begins, which is the truthful outcome when
127
+ // there is nothing to continue.
128
+ if (config.getCorrelationId && !headers.has(CORRELATION_ID_HEADER)) {
129
+ const correlationId = await Promise.resolve(config.getCorrelationId());
130
+ if (correlationId) {
131
+ headers.set(CORRELATION_ID_HEADER, correlationId);
132
+ }
133
+ }
107
134
  // Auth token (caller or global headers take precedence)
108
135
  if (config.getAuthToken && !headers.has('Authorization')) {
109
136
  const token = await config.getAuthToken();
@@ -3,7 +3,10 @@
3
3
  * Authorization API
4
4
  * OpenAPI spec version: 0.1.1
5
5
  */
6
+ import type { ResourceShareRefDto } from './resourceShareRefDto.js';
6
7
  import type { ResourceSubjectRefDto } from './resourceSubjectRefDto.js';
7
8
  export interface AddResourceShareDto {
8
- share: ResourceSubjectRefDto;
9
+ share: ResourceShareRefDto;
10
+ /** The subject GRANTING this share, when it is not the instance owner. Used to apply the two delegation rules: a grantor may never confer more than they hold, and re-sharing is itself a level. Omitted means the caller asserts owner authority, which this service verifies against the tuple store — it is never taken on the caller's word. */
11
+ grantor?: ResourceSubjectRefDto;
9
12
  }
@@ -7,7 +7,6 @@ import type { GrantConstraintsDto } from './grantConstraintsDto.js';
7
7
  export interface AddRoleGrantDto {
8
8
  /** Canonical CapabilityRef from `@xemahq/kernel-contracts/capability`. */
9
9
  capability: string;
10
- resourceGlob?: string;
11
10
  /** Built-in environment slug. */
12
11
  environment: string;
13
12
  constraints?: GrantConstraintsDto;
@@ -13,7 +13,6 @@ export interface CapabilityGrantDto {
13
13
  subjectKind: SubjectKind;
14
14
  subjectRef: string;
15
15
  capability: string;
16
- resourceGlob: string;
17
16
  environment: string;
18
17
  constraints?: GrantConstraintsDto | null;
19
18
  requiresApproval: boolean;
@@ -13,8 +13,6 @@ export interface CreateGrantDto {
13
13
  subjectRef: string;
14
14
  /** Canonical CapabilityRef from `@xemahq/kernel-contracts/capability`. */
15
15
  capability: string;
16
- /** Resource-scope glob for this grant. STORED ONLY — it is part of the grant uniqueness key and nothing in the decision path reads it, so a value narrower than `**` grants exactly what `**` grants today and must not be relied on to restrict anything. The vocabulary it will be matched against is deliberately NOT specified: instance refs are the canonical `resource:<type>:<id>` (see `PolicyResourceDto.ref`), and whether this glob matches those or a different addressing scheme is the decision of the phase that makes it enforceable. It previously advertised `xema://orgs/acme/projects/support/kb/**` — an XVFS path form the platform rejects wherever it IS parsed, and that stale vocabulary is what led five producers to send refs the PDP refuses. */
17
- resourceGlob?: string;
18
16
  /** Built-in environment slug. Phase 3 stores but does not enforce. */
19
17
  environment: string;
20
18
  constraints?: GrantConstraintsDto;
@@ -12,6 +12,8 @@ export interface CredentialDefaultDto {
12
12
  * @nullable
13
13
  */
14
14
  projectId?: string | null;
15
+ /** The external provider this default is for. */
16
+ provider: string;
15
17
  /** Opaque credential-binding pointer. Not a secret. */
16
18
  credentialBindingId: string;
17
19
  createdAt: string;
@@ -12,4 +12,8 @@ export type CredentialDefaultsControllerDeleteParams = {
12
12
  * Project identifier. Omit for the ORG-wide default; set for a per-project default.
13
13
  */
14
14
  projectId?: string;
15
+ /**
16
+ * The external provider whose default is being addressed. Required: a default is per (scope, provider), so a scope alone does not name one.
17
+ */
18
+ provider: string;
15
19
  };
@@ -12,4 +12,8 @@ export type CredentialDefaultsControllerGetParams = {
12
12
  * Project identifier. Omit for the ORG-wide default; set for a per-project default.
13
13
  */
14
14
  projectId?: string;
15
+ /**
16
+ * The external provider whose default is being addressed. Required: a default is per (scope, provider), so a scope alone does not name one.
17
+ */
18
+ provider: string;
15
19
  };
@@ -5,7 +5,5 @@
5
5
  */
6
6
  export type DataResidency = typeof DataResidency[keyof typeof DataResidency];
7
7
  export declare const DataResidency: {
8
- readonly eu: "eu";
9
- readonly us: "us";
10
8
  readonly 'customer-private': "customer-private";
11
9
  };
@@ -7,7 +7,5 @@
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.DataResidency = void 0;
9
9
  exports.DataResidency = {
10
- eu: 'eu',
11
- us: 'us',
12
10
  'customer-private': 'customer-private',
13
11
  };
@@ -106,6 +106,7 @@ export * from './resourceOwnershipDtoDataEnvelope';
106
106
  export * from './resourceOwnershipEntryDto';
107
107
  export * from './resourceOwnershipReadDto';
108
108
  export * from './resourceOwnershipReadDtoDataEnvelope';
109
+ export * from './resourceShareRefDto';
109
110
  export * from './resourceSubjectRefDto';
110
111
  export * from './resourceVisibilityPattern';
111
112
  export * from './roleAssignmentDto';
@@ -123,6 +123,7 @@ __exportStar(require("./resourceOwnershipDtoDataEnvelope"), exports);
123
123
  __exportStar(require("./resourceOwnershipEntryDto"), exports);
124
124
  __exportStar(require("./resourceOwnershipReadDto"), exports);
125
125
  __exportStar(require("./resourceOwnershipReadDtoDataEnvelope"), exports);
126
+ __exportStar(require("./resourceShareRefDto"), exports);
126
127
  __exportStar(require("./resourceSubjectRefDto"), exports);
127
128
  __exportStar(require("./resourceVisibilityPattern"), exports);
128
129
  __exportStar(require("./roleAssignmentDto"), exports);
@@ -3,6 +3,7 @@
3
3
  * Authorization API
4
4
  * OpenAPI spec version: 0.1.1
5
5
  */
6
+ import type { ResourceShareRefDto } from './resourceShareRefDto.js';
6
7
  import type { ResourceSubjectRefDto } from './resourceSubjectRefDto.js';
7
8
  import type { ResourceVisibilityPattern } from './resourceVisibilityPattern.js';
8
9
  export interface RegisterResourceOwnershipDto {
@@ -14,6 +15,6 @@ export interface RegisterResourceOwnershipDto {
14
15
  visibility: ResourceVisibilityPattern;
15
16
  /** Subjects that OWN the instance (full visibility). */
16
17
  owners: ResourceSubjectRefDto[];
17
- /** Subjects explicitly granted visibility (shared-with). */
18
- explicitShares?: ResourceSubjectRefDto[];
18
+ /** Subjects explicitly granted visibility, each at a LEVEL and with an optional expiry. */
19
+ explicitShares?: ResourceShareRefDto[];
19
20
  }
@@ -3,6 +3,7 @@
3
3
  * Authorization API
4
4
  * OpenAPI spec version: 0.1.1
5
5
  */
6
+ import type { ResourceShareRefDto } from './resourceShareRefDto.js';
6
7
  import type { ResourceSubjectRefDto } from './resourceSubjectRefDto.js';
7
8
  import type { ResourceVisibilityPattern } from './resourceVisibilityPattern.js';
8
9
  export interface ReplaceResourceOwnershipDto {
@@ -10,6 +11,6 @@ export interface ReplaceResourceOwnershipDto {
10
11
  visibility: ResourceVisibilityPattern;
11
12
  /** Subjects that OWN the instance (full visibility). */
12
13
  owners: ResourceSubjectRefDto[];
13
- /** Subjects explicitly granted visibility (shared-with). */
14
- explicitShares?: ResourceSubjectRefDto[];
14
+ /** Subjects explicitly granted visibility, each at a LEVEL and with an optional expiry. */
15
+ explicitShares?: ResourceShareRefDto[];
15
16
  }
@@ -8,4 +8,10 @@ export interface ResourceOwnershipEntryDto {
8
8
  id: string;
9
9
  ownerKind: SubjectKind;
10
10
  ownerRef: string;
11
+ /** The level this share confers, in the resource kind's vocabulary. ABSENT on an owner row — ownership is not a rung. */
12
+ level?: string;
13
+ /** When the share stops granting. Absent = never. */
14
+ expiresAt?: string;
15
+ /** `<subjectKind>:<subjectRef>` of whoever granted this share. Absent on an owner row. */
16
+ grantedBy?: string;
11
17
  }
@@ -3,12 +3,14 @@
3
3
  * Authorization API
4
4
  * OpenAPI spec version: 0.1.1
5
5
  */
6
- import type { ResourceSubjectRefDto } from './resourceSubjectRefDto.js';
6
+ import type { ResourceOwnershipEntryDto } from './resourceOwnershipEntryDto.js';
7
7
  import type { ResourceVisibilityPattern } from './resourceVisibilityPattern.js';
8
8
  export interface ResourceOwnershipReadDto {
9
9
  resourceType: string;
10
10
  resourceId: string;
11
11
  visibility: ResourceVisibilityPattern;
12
- /** All registered subjects (owners + shares combined; the SQL authority does not split the two). */
13
- subjects: ResourceSubjectRefDto[];
12
+ /** Subjects that OWN the instance. */
13
+ owners: ResourceOwnershipEntryDto[];
14
+ /** Subjects the instance is SHARED with, each with its level, expiry and grantor. */
15
+ shares: ResourceOwnershipEntryDto[];
14
16
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Generated by @xemahq/api-client-generator — do not edit manually.
3
+ * Authorization API
4
+ * OpenAPI spec version: 0.1.1
5
+ */
6
+ import type { SubjectKind } from './subjectKind.js';
7
+ export interface ResourceShareRefDto {
8
+ kind: SubjectKind;
9
+ /** Subject id (the `<id>` in `<kind>:<id>`). */
10
+ ref: string;
11
+ /** The resource kind's own name for the level this share confers. Levels are declared per kind (a document has `viewer < editor < manager`; a mailbox's `editor` is not a meaningful authority) and are totally ordered with monotone verb expansion. OMITTED means the LOWEST level the kind declares — never the highest. */
12
+ level?: string;
13
+ /** ISO-8601 instant after which the share stops granting. Enforced by an OpenFGA condition evaluated at DECISION time, not by a sweeper — a sweeper leaves a window in which a lapsed share still passes. Omitted means the share does not expire. An instant in the past is a 400. */
14
+ expiresAt?: string;
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -8,7 +8,6 @@ export interface RoleGrantDto {
8
8
  id: string;
9
9
  roleId: string;
10
10
  capability: string;
11
- resourceGlob: string;
12
11
  environment: string;
13
12
  constraints?: GrantConstraintsDto | null;
14
13
  requiresApproval: boolean;
@@ -6,7 +6,6 @@
6
6
  import type { BiomePermissionProfile } from './biomePermissionProfile.js';
7
7
  import type { GrantConstraintsDto } from './grantConstraintsDto.js';
8
8
  export interface UpdateGrantDto {
9
- resourceGlob?: string;
10
9
  environment?: string;
11
10
  constraints?: GrantConstraintsDto;
12
11
  requiresApproval?: boolean;
@@ -8,6 +8,8 @@ export interface UpsertCredentialDefaultDto {
8
8
  orgId: string;
9
9
  /** Project identifier. Omit (or null) for the ORG-wide default; set for a per-project default. */
10
10
  projectId?: string;
11
+ /** The EXTERNAL PROVIDER this default is for — `github`, `slack`, an MCP server's provider slug. A default is per (scope, provider): without it an organisation would have one default binding for every provider at once. Must be a value a capability ref can derive (lowercase kebab), because the ladder looks it up by exactly that derivation. */
12
+ provider: string;
11
13
  /** Opaque credential-binding pointer the gateway resolves the external credential from. Not a secret. */
12
14
  credentialBindingId: string;
13
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xemahq/authorization-internal-api-client",
3
- "version": "0.3.10",
3
+ "version": "0.4.3",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -19,7 +19,7 @@
19
19
  "service": "authorization-api",
20
20
  "biome": "authorization",
21
21
  "target": "server",
22
- "generator": "@xemahq/api-client-generator@0.13.0",
22
+ "generator": "@xemahq/api-client-generator@0.14.1",
23
23
  "source": "openapi.internal.json"
24
24
  },
25
25
  "license": "LicenseRef-Xema-BSL-1.1",