@xemahq/authorization-nest 0.5.0 → 0.6.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.
@@ -0,0 +1,6 @@
1
+ export declare enum DurableDelegationDecisionCode {
2
+ AuthorityUnavailable = "DURABLE_DELEGATION_AUTHORITY_UNAVAILABLE",
3
+ Ended = "DURABLE_DELEGATION_ENDED"
4
+ }
5
+ export declare function isDurableDelegationDecisionCode(reason: string | undefined): reason is DurableDelegationDecisionCode;
6
+ //# sourceMappingURL=decision-codes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decision-codes.d.ts","sourceRoot":"","sources":["../../src/durable-delegation/decision-codes.ts"],"names":[],"mappings":"AAgBA,oBAAY,6BAA6B;IACvC,oBAAoB,6CAA6C;IACjE,KAAK,6BAA6B;CACnC;AAGD,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,MAAM,IAAI,6BAA6B,CAKzC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DurableDelegationDecisionCode = void 0;
4
+ exports.isDurableDelegationDecisionCode = isDurableDelegationDecisionCode;
5
+ var DurableDelegationDecisionCode;
6
+ (function (DurableDelegationDecisionCode) {
7
+ DurableDelegationDecisionCode["AuthorityUnavailable"] = "DURABLE_DELEGATION_AUTHORITY_UNAVAILABLE";
8
+ DurableDelegationDecisionCode["Ended"] = "DURABLE_DELEGATION_ENDED";
9
+ })(DurableDelegationDecisionCode || (exports.DurableDelegationDecisionCode = DurableDelegationDecisionCode = {}));
10
+ function isDurableDelegationDecisionCode(reason) {
11
+ return (reason === DurableDelegationDecisionCode.AuthorityUnavailable ||
12
+ reason === DurableDelegationDecisionCode.Ended);
13
+ }
14
+ //# sourceMappingURL=decision-codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decision-codes.js","sourceRoot":"","sources":["../../src/durable-delegation/decision-codes.ts"],"names":[],"mappings":";;;AAsBA,0EAOC;AAbD,IAAY,6BAGX;AAHD,WAAY,6BAA6B;IACvC,kGAAiE,CAAA;IACjE,mEAAkC,CAAA;AACpC,CAAC,EAHW,6BAA6B,6CAA7B,6BAA6B,QAGxC;AAGD,SAAgB,+BAA+B,CAC7C,MAA0B;IAE1B,OAAO,CACL,MAAM,KAAK,6BAA6B,CAAC,oBAAoB;QAC7D,MAAM,KAAK,6BAA6B,CAAC,KAAK,CAC/C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,65 @@
1
+ import { type ServiceRegistry } from '@xemahq/contracts/service-registry';
2
+ import { IdentityBootstrapService } from '@xemahq/identity-client';
3
+ import { type ForwardedCallerContext } from '@xemahq/platform-common';
4
+ export declare enum DurableDelegationOwnerKind {
5
+ User = "USER",
6
+ Team = "TEAM",
7
+ Org = "ORG"
8
+ }
9
+ export declare enum DurableDelegationRecordState {
10
+ Provisioning = "PROVISIONING",
11
+ Active = "ACTIVE",
12
+ Revoked = "REVOKED",
13
+ Expired = "EXPIRED"
14
+ }
15
+ export interface DurableDelegationCreate {
16
+ readonly owner: {
17
+ readonly kind: DurableDelegationOwnerKind;
18
+ readonly id: string;
19
+ };
20
+ readonly scope: readonly string[];
21
+ readonly capabilities: readonly string[];
22
+ readonly integrationId: string;
23
+ readonly environmentId: string;
24
+ readonly requestKey: string;
25
+ readonly holderMember?: string;
26
+ readonly expiresAt?: Date;
27
+ }
28
+ export interface DurableDelegationView {
29
+ readonly id: string;
30
+ readonly state: DurableDelegationRecordState;
31
+ readonly endReason?: string;
32
+ readonly owner: {
33
+ readonly kind: DurableDelegationOwnerKind;
34
+ readonly id: string;
35
+ };
36
+ readonly scope: readonly string[];
37
+ readonly capabilities: readonly string[];
38
+ readonly integrationId: string;
39
+ readonly environmentId: string;
40
+ readonly holderWorkload: string;
41
+ readonly carrierId?: string;
42
+ readonly expiresAt?: string;
43
+ readonly lastDenial?: {
44
+ readonly at: string;
45
+ readonly check: string;
46
+ readonly right: string;
47
+ readonly scope: string;
48
+ };
49
+ }
50
+ export declare class DurableDelegationRequestError extends Error {
51
+ readonly status: number;
52
+ readonly code: string | undefined;
53
+ constructor(message: string, status: number, code: string | undefined);
54
+ }
55
+ export declare class DurableDelegationHolderClient {
56
+ private readonly registry;
57
+ private readonly identity;
58
+ constructor(registry: ServiceRegistry, identity: IdentityBootstrapService);
59
+ create(author: ForwardedCallerContext, request: DurableDelegationCreate): Promise<DurableDelegationView>;
60
+ read(orgId: string, delegationId: string): Promise<DurableDelegationView>;
61
+ revoke(orgId: string, delegationId: string): Promise<DurableDelegationView>;
62
+ mintContext(carrierId: string): Promise<string>;
63
+ private send;
64
+ }
65
+ //# sourceMappingURL=holder-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holder-client.d.ts","sourceRoot":"","sources":["../../src/durable-delegation/holder-client.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC;AAOjC,oBAAY,0BAA0B;IACpC,IAAI,SAAS;IACb,IAAI,SAAS;IACb,GAAG,QAAQ;CACZ;AAGD,oBAAY,4BAA4B;IACtC,YAAY,iBAAiB;IAC7B,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAGD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,0BAA0B,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACnF,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAE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GAAG,SAAS;CAK3C;AAmBD,qBACa,6BAA6B;IAEN,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADwB,QAAQ,EAAE,eAAe,EACzD,QAAQ,EAAE,wBAAwB;IAGxC,MAAM,CACjB,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;IAepB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IASzE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAc3E,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAQ9C,IAAI;CA8BnB"}
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DurableDelegationHolderClient = exports.DurableDelegationRequestError = exports.DurableDelegationRecordState = exports.DurableDelegationOwnerKind = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const service_registry_1 = require("@xemahq/contracts/service-registry");
18
+ const identity_client_1 = require("@xemahq/identity-client");
19
+ const platform_common_1 = require("@xemahq/platform-common");
20
+ const service_registry_nest_1 = require("@xemahq/service-registry-nest");
21
+ var DurableDelegationOwnerKind;
22
+ (function (DurableDelegationOwnerKind) {
23
+ DurableDelegationOwnerKind["User"] = "USER";
24
+ DurableDelegationOwnerKind["Team"] = "TEAM";
25
+ DurableDelegationOwnerKind["Org"] = "ORG";
26
+ })(DurableDelegationOwnerKind || (exports.DurableDelegationOwnerKind = DurableDelegationOwnerKind = {}));
27
+ var DurableDelegationRecordState;
28
+ (function (DurableDelegationRecordState) {
29
+ DurableDelegationRecordState["Provisioning"] = "PROVISIONING";
30
+ DurableDelegationRecordState["Active"] = "ACTIVE";
31
+ DurableDelegationRecordState["Revoked"] = "REVOKED";
32
+ DurableDelegationRecordState["Expired"] = "EXPIRED";
33
+ })(DurableDelegationRecordState || (exports.DurableDelegationRecordState = DurableDelegationRecordState = {}));
34
+ class DurableDelegationRequestError extends Error {
35
+ status;
36
+ code;
37
+ constructor(message, status, code) {
38
+ super(message);
39
+ this.status = status;
40
+ this.code = code;
41
+ this.name = 'DurableDelegationRequestError';
42
+ }
43
+ }
44
+ exports.DurableDelegationRequestError = DurableDelegationRequestError;
45
+ const DELEGATED_CONTEXT_AUDIENCE = service_registry_1.ServiceName.XEMA_CAPABILITY_ROUTER;
46
+ let DurableDelegationHolderClient = class DurableDelegationHolderClient {
47
+ registry;
48
+ identity;
49
+ constructor(registry, identity) {
50
+ this.registry = registry;
51
+ this.identity = identity;
52
+ }
53
+ async create(author, request) {
54
+ return this.send('POST', '/durable-delegations', author.orgId, {
55
+ ...(await (0, platform_common_1.forwardedCallerHeaders)(author, this.identity)),
56
+ }, {
57
+ owner: request.owner,
58
+ scope: [...request.scope],
59
+ capabilities: [...request.capabilities],
60
+ integrationId: request.integrationId,
61
+ environmentId: request.environmentId,
62
+ requestKey: request.requestKey,
63
+ ...(request.holderMember === undefined ? {} : { holderMember: request.holderMember }),
64
+ ...(request.expiresAt === undefined ? {} : { expiresAt: request.expiresAt.toISOString() }),
65
+ });
66
+ }
67
+ async read(orgId, delegationId) {
68
+ return this.send('GET', `/internal/durable-delegations/${encodeURIComponent(delegationId)}`, orgId, { Authorization: `Bearer ${await this.identity.getAccessToken()}` });
69
+ }
70
+ async revoke(orgId, delegationId) {
71
+ return this.send('POST', `/internal/durable-delegations/${encodeURIComponent(delegationId)}/revoke`, orgId, { Authorization: `Bearer ${await this.identity.getAccessToken()}` });
72
+ }
73
+ async mintContext(carrierId) {
74
+ const minted = await this.identity.mintDelegatedContext({
75
+ delegationId: carrierId,
76
+ audience: DELEGATED_CONTEXT_AUDIENCE,
77
+ });
78
+ return minted.accessToken;
79
+ }
80
+ async send(method, path, orgId, headers, body) {
81
+ const baseUrl = await (0, service_registry_nest_1.resolveHttpUrl)(this.registry, service_registry_1.ServiceName.AUTHORIZATION_API);
82
+ const response = await fetch(`${baseUrl.replace(/\/+$/, '')}${path}`, {
83
+ method,
84
+ headers: {
85
+ ...headers,
86
+ 'X-Xema-Org-Id': orgId,
87
+ ...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
88
+ },
89
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
90
+ });
91
+ if (!response.ok) {
92
+ const text = await response.text();
93
+ throw new DurableDelegationRequestError(`authorization-api ${method} ${path} failed with HTTP ${response.status}: ${text.slice(0, 2000)}`, response.status, codeOf(text));
94
+ }
95
+ return (0, platform_common_1.unwrapPlatformResponseEnvelope)(await response.json(), `authorization-api ${method} ${path}`);
96
+ }
97
+ };
98
+ exports.DurableDelegationHolderClient = DurableDelegationHolderClient;
99
+ exports.DurableDelegationHolderClient = DurableDelegationHolderClient = __decorate([
100
+ (0, common_1.Injectable)(),
101
+ __param(0, (0, common_1.Inject)(service_registry_nest_1.SERVICE_REGISTRY_TOKEN)),
102
+ __metadata("design:paramtypes", [Object, identity_client_1.IdentityBootstrapService])
103
+ ], DurableDelegationHolderClient);
104
+ function codeOf(text) {
105
+ try {
106
+ const parsed = JSON.parse(text);
107
+ return typeof parsed.code === 'string' ? parsed.code : undefined;
108
+ }
109
+ catch {
110
+ return undefined;
111
+ }
112
+ }
113
+ //# sourceMappingURL=holder-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holder-client.js","sourceRoot":"","sources":["../../src/durable-delegation/holder-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,yEAG4C;AAC5C,6DAAmE;AACnE,6DAIiC;AACjC,yEAGuC;AAGvC,IAAY,0BAIX;AAJD,WAAY,0BAA0B;IACpC,2CAAa,CAAA;IACb,2CAAa,CAAA;IACb,yCAAW,CAAA;AACb,CAAC,EAJW,0BAA0B,0CAA1B,0BAA0B,QAIrC;AAGD,IAAY,4BAKX;AALD,WAAY,4BAA4B;IACtC,6DAA6B,CAAA;IAC7B,iDAAiB,CAAA;IACjB,mDAAmB,CAAA;IACnB,mDAAmB,CAAA;AACrB,CAAC,EALW,4BAA4B,4CAA5B,4BAA4B,QAKvC;AAuCD,MAAa,6BAA8B,SAAQ,KAAK;IAGpC;IACA;IAHlB,YACE,OAAe,EACC,MAAc,EACd,IAAwB;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAoB;QAGxC,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;IAC9C,CAAC;CACF;AATD,sEASC;AAGD,MAAM,0BAA0B,GAAG,8BAAW,CAAC,sBAAsB,CAAC;AAiB/D,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IAEW;IAChC;IAFnB,YACmD,QAAyB,EACzD,QAAkC;QADF,aAAQ,GAAR,QAAQ,CAAiB;QACzD,aAAQ,GAAR,QAAQ,CAA0B;IAClD,CAAC;IAEG,KAAK,CAAC,MAAM,CACjB,MAA8B,EAC9B,OAAgC;QAEhC,OAAO,IAA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I,CAAC,CACb,CAAC;QACJ,CAAC;QACD,OAAO,IAAA,gDAA8B,EACnC,MAAM,QAAQ,CAAC,IAAI,EAAE,EACrB,qBAAqB,MAAM,IAAI,IAAI,EAAE,CACtC,CAAC;IACJ,CAAC;CACF,CAAA;AArFY,sEAA6B;wCAA7B,6BAA6B;IADzC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,8CAAsB,CAAC,CAAA;6CACJ,0CAAwB;GAH1C,6BAA6B,CAqFzC;AAED,SAAS,MAAM,CAAC,IAAY;IAC1B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAuB,CAAC;QACtD,OAAO,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ export declare enum DelegationRequiredReason {
2
+ NeverAuthorised = "never-authorised",
3
+ Unprovisioned = "unprovisioned",
4
+ Ended = "ended",
5
+ Stale = "stale"
6
+ }
7
+ export declare class DelegationRequiredError extends Error {
8
+ readonly reason: DelegationRequiredReason;
9
+ readonly subject: string;
10
+ constructor(reason: DelegationRequiredReason, subject: string);
11
+ }
12
+ export declare class DelegationUseDeniedError extends Error {
13
+ readonly delegationId: string;
14
+ readonly detail: string;
15
+ constructor(delegationId: string, detail: string);
16
+ }
17
+ export declare class DelegationEndedError extends Error {
18
+ readonly delegationId: string;
19
+ readonly endReason: string | undefined;
20
+ constructor(delegationId: string, endReason: string | undefined);
21
+ }
22
+ //# sourceMappingURL=holder-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holder-errors.d.ts","sourceRoot":"","sources":["../../src/durable-delegation/holder-errors.ts"],"names":[],"mappings":"AAkBA,oBAAY,wBAAwB;IAElC,eAAe,qBAAqB;IAEpC,aAAa,kBAAkB;IAE/B,KAAK,UAAU;IAEf,KAAK,UAAU;CAChB;AAED,qBAAa,uBAAwB,SAAQ,KAAK;aAE9B,MAAM,EAAE,wBAAwB;aAChC,OAAO,EAAE,MAAM;gBADf,MAAM,EAAE,wBAAwB,EAChC,OAAO,EAAE,MAAM;CAKlC;AAED,qBAAa,wBAAyB,SAAQ,KAAK;aAE/B,YAAY,EAAE,MAAM;aACpB,MAAM,EAAE,MAAM;gBADd,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM;CAKjC;AAED,qBAAa,oBAAqB,SAAQ,KAAK;aAE3B,YAAY,EAAE,MAAM;aACpB,SAAS,EAAE,MAAM,GAAG,SAAS;gBAD7B,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GAAG,SAAS;CAKhD"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DelegationEndedError = exports.DelegationUseDeniedError = exports.DelegationRequiredError = exports.DelegationRequiredReason = void 0;
4
+ var DelegationRequiredReason;
5
+ (function (DelegationRequiredReason) {
6
+ DelegationRequiredReason["NeverAuthorised"] = "never-authorised";
7
+ DelegationRequiredReason["Unprovisioned"] = "unprovisioned";
8
+ DelegationRequiredReason["Ended"] = "ended";
9
+ DelegationRequiredReason["Stale"] = "stale";
10
+ })(DelegationRequiredReason || (exports.DelegationRequiredReason = DelegationRequiredReason = {}));
11
+ class DelegationRequiredError extends Error {
12
+ reason;
13
+ subject;
14
+ constructor(reason, subject) {
15
+ super(`${subject} needs a person to authorise its durable work (${reason}).`);
16
+ this.reason = reason;
17
+ this.subject = subject;
18
+ this.name = 'DelegationRequiredError';
19
+ }
20
+ }
21
+ exports.DelegationRequiredError = DelegationRequiredError;
22
+ class DelegationUseDeniedError extends Error {
23
+ delegationId;
24
+ detail;
25
+ constructor(delegationId, detail) {
26
+ super(`authority currently unavailable for durable delegation ${delegationId}: ${detail}`);
27
+ this.delegationId = delegationId;
28
+ this.detail = detail;
29
+ this.name = 'DelegationUseDeniedError';
30
+ }
31
+ }
32
+ exports.DelegationUseDeniedError = DelegationUseDeniedError;
33
+ class DelegationEndedError extends Error {
34
+ delegationId;
35
+ endReason;
36
+ constructor(delegationId, endReason) {
37
+ super(`durable delegation ${delegationId} has ended${endReason === undefined ? '' : ` (${endReason})`}.`);
38
+ this.delegationId = delegationId;
39
+ this.endReason = endReason;
40
+ this.name = 'DelegationEndedError';
41
+ }
42
+ }
43
+ exports.DelegationEndedError = DelegationEndedError;
44
+ //# sourceMappingURL=holder-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holder-errors.js","sourceRoot":"","sources":["../../src/durable-delegation/holder-errors.ts"],"names":[],"mappings":";;;AAkBA,IAAY,wBASX;AATD,WAAY,wBAAwB;IAElC,gEAAoC,CAAA;IAEpC,2DAA+B,CAAA;IAE/B,2CAAe,CAAA;IAEf,2CAAe,CAAA;AACjB,CAAC,EATW,wBAAwB,wCAAxB,wBAAwB,QASnC;AAED,MAAa,uBAAwB,SAAQ,KAAK;IAE9B;IACA;IAFlB,YACkB,MAAgC,EAChC,OAAe;QAE/B,KAAK,CAAC,GAAG,OAAO,kDAAkD,MAAM,IAAI,CAAC,CAAC;QAH9D,WAAM,GAAN,MAAM,CAA0B;QAChC,YAAO,GAAP,OAAO,CAAQ;QAG/B,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AARD,0DAQC;AAED,MAAa,wBAAyB,SAAQ,KAAK;IAE/B;IACA;IAFlB,YACkB,YAAoB,EACpB,MAAc;QAE9B,KAAK,CAAC,0DAA0D,YAAY,KAAK,MAAM,EAAE,CAAC,CAAC;QAH3E,iBAAY,GAAZ,YAAY,CAAQ;QACpB,WAAM,GAAN,MAAM,CAAQ;QAG9B,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AARD,4DAQC;AAED,MAAa,oBAAqB,SAAQ,KAAK;IAE3B;IACA;IAFlB,YACkB,YAAoB,EACpB,SAA6B;QAE7C,KAAK,CAAC,sBAAsB,YAAY,aAAa,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,GAAG,GAAG,CAAC,CAAC;QAH1F,iBAAY,GAAZ,YAAY,CAAQ;QACpB,cAAS,GAAT,SAAS,CAAoB;QAG7C,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AARD,oDAQC"}
@@ -0,0 +1,43 @@
1
+ import { type DurableDelegationCreate, DurableDelegationHolderClient, type DurableDelegationView } from './holder-client';
2
+ import { DelegationEndedError, DelegationUseDeniedError } from './holder-errors';
3
+ import type { ForwardedCallerContext } from '@xemahq/platform-common';
4
+ export declare enum HolderDelegationState {
5
+ NotRequired = "not_required",
6
+ Required = "required",
7
+ Unprovisioned = "unprovisioned",
8
+ Held = "held",
9
+ Ended = "ended"
10
+ }
11
+ export interface HolderDelegationRow {
12
+ readonly state: HolderDelegationState;
13
+ readonly delegationId: string | null;
14
+ readonly carrierId: string | null;
15
+ readonly capabilities: readonly string[];
16
+ }
17
+ export interface HolderDelegationStore {
18
+ read(): Promise<HolderDelegationRow | null>;
19
+ writeIf(expected: Pick<HolderDelegationRow, 'state' | 'delegationId'>, next: HolderDelegationRow): Promise<boolean>;
20
+ }
21
+ export interface HolderDelegationNeed {
22
+ readonly capabilities: readonly string[];
23
+ }
24
+ export interface HeldAuthority {
25
+ readonly delegationId: string;
26
+ readonly orgId: string;
27
+ readonly authorization: string;
28
+ }
29
+ export declare class DurableDelegationHolder {
30
+ private readonly client;
31
+ private readonly logger;
32
+ constructor(client: DurableDelegationHolderClient);
33
+ reconcileNeed(store: HolderDelegationStore, orgId: string, need: HolderDelegationNeed | null): Promise<HolderDelegationRow>;
34
+ authorize(store: HolderDelegationStore, author: ForwardedCallerContext, request: DurableDelegationCreate): Promise<HolderDelegationRow>;
35
+ authority(row: HolderDelegationRow, orgId: string, subject: string): Promise<HeldAuthority>;
36
+ onDenied(store: HolderDelegationStore, row: HolderDelegationRow, reason: string | undefined, detail: string): Promise<DelegationUseDeniedError | DelegationEndedError | undefined>;
37
+ refresh(store: HolderDelegationStore, orgId: string): Promise<HolderDelegationRow | null>;
38
+ endFor(row: HolderDelegationRow, orgId: string): Promise<void>;
39
+ private revokeQuietly;
40
+ }
41
+ export declare function rowOf(view: DurableDelegationView): HolderDelegationRow;
42
+ export declare function needTransition(row: HolderDelegationRow, need: HolderDelegationNeed | null): HolderDelegationRow | null;
43
+ //# sourceMappingURL=holder-lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holder-lifecycle.d.ts","sourceRoot":"","sources":["../../src/durable-delegation/holder-lifecycle.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,uBAAuB,EAC5B,6BAA6B,EAE7B,KAAK,qBAAqB,EAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,oBAAoB,EAGpB,wBAAwB,EACzB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAWtE,oBAAY,qBAAqB;IAE/B,WAAW,iBAAiB;IAE5B,QAAQ,aAAa;IAErB,aAAa,kBAAkB;IAE/B,IAAI,SAAS;IAEb,KAAK,UAAU;CAChB;AAGD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAElC,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AAQD,MAAM,WAAW,qBAAqB;IACpC,IAAI,IAAI,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;IAC5C,OAAO,CACL,QAAQ,EAAE,IAAI,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AE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAM7D,aAAa;CAc5B;AAGD,wBAAgB,KAAK,CAAC,IAAI,EAAE,qBAAqB,GAAG,mBAAmB,CAetE;AAGD,wBAAgB,cAAc,CAC5B,GAAG,EAAE,mBAAmB,EACxB,IAAI,EAAE,oBAAoB,GAAG,IAAI,GAChC,mBAAmB,GAAG,IAAI,CAgB5B"}
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var DurableDelegationHolder_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.DurableDelegationHolder = exports.HolderDelegationState = void 0;
14
+ exports.rowOf = rowOf;
15
+ exports.needTransition = needTransition;
16
+ const common_1 = require("@nestjs/common");
17
+ const decision_codes_1 = require("./decision-codes");
18
+ const holder_client_1 = require("./holder-client");
19
+ const holder_errors_1 = require("./holder-errors");
20
+ var HolderDelegationState;
21
+ (function (HolderDelegationState) {
22
+ HolderDelegationState["NotRequired"] = "not_required";
23
+ HolderDelegationState["Required"] = "required";
24
+ HolderDelegationState["Unprovisioned"] = "unprovisioned";
25
+ HolderDelegationState["Held"] = "held";
26
+ HolderDelegationState["Ended"] = "ended";
27
+ })(HolderDelegationState || (exports.HolderDelegationState = HolderDelegationState = {}));
28
+ const MAX_CAS_ATTEMPTS = 3;
29
+ let DurableDelegationHolder = DurableDelegationHolder_1 = class DurableDelegationHolder {
30
+ client;
31
+ logger = new common_1.Logger(DurableDelegationHolder_1.name);
32
+ constructor(client) {
33
+ this.client = client;
34
+ }
35
+ async reconcileNeed(store, orgId, need) {
36
+ for (let attempt = 0; attempt < MAX_CAS_ATTEMPTS; attempt += 1) {
37
+ const row = await store.read();
38
+ if (row === null) {
39
+ throw new common_1.ConflictException('The holder row disappeared while its need was being stated.');
40
+ }
41
+ const next = needTransition(row, need);
42
+ if (next === null) {
43
+ return row;
44
+ }
45
+ if (await store.writeIf(row, next)) {
46
+ if (row.delegationId !== null && next.delegationId === null) {
47
+ await this.revokeQuietly(orgId, row.delegationId);
48
+ }
49
+ return next;
50
+ }
51
+ }
52
+ throw new common_1.ConflictException('The holder row kept changing while its need was being stated.');
53
+ }
54
+ async authorize(store, author, request) {
55
+ const view = await this.client.create(author, request);
56
+ const next = rowOf(view);
57
+ for (let attempt = 0; attempt < MAX_CAS_ATTEMPTS; attempt += 1) {
58
+ const row = await store.read();
59
+ if (row === null) {
60
+ await this.revokeQuietly(author.orgId, view.id);
61
+ throw new common_1.ConflictException('The holder row disappeared while it was being authorised.');
62
+ }
63
+ if (row.delegationId === view.id) {
64
+ return row;
65
+ }
66
+ if (await store.writeIf(row, next)) {
67
+ if (row.delegationId !== null) {
68
+ await this.revokeQuietly(author.orgId, row.delegationId);
69
+ }
70
+ return next;
71
+ }
72
+ }
73
+ throw new common_1.ConflictException('The holder row kept changing while it was being authorised.');
74
+ }
75
+ async authority(row, orgId, subject) {
76
+ switch (row.state) {
77
+ case HolderDelegationState.Held:
78
+ break;
79
+ case HolderDelegationState.NotRequired:
80
+ case HolderDelegationState.Required:
81
+ throw new holder_errors_1.DelegationRequiredError(holder_errors_1.DelegationRequiredReason.NeverAuthorised, subject);
82
+ case HolderDelegationState.Unprovisioned:
83
+ throw new holder_errors_1.DelegationRequiredError(holder_errors_1.DelegationRequiredReason.Unprovisioned, subject);
84
+ case HolderDelegationState.Ended:
85
+ throw new holder_errors_1.DelegationRequiredError(holder_errors_1.DelegationRequiredReason.Ended, subject);
86
+ }
87
+ if (row.delegationId === null || row.carrierId === null) {
88
+ throw new holder_errors_1.DelegationRequiredError(holder_errors_1.DelegationRequiredReason.Unprovisioned, subject);
89
+ }
90
+ return {
91
+ delegationId: row.delegationId,
92
+ orgId,
93
+ authorization: `Bearer ${await this.client.mintContext(row.carrierId)}`,
94
+ };
95
+ }
96
+ async onDenied(store, row, reason, detail) {
97
+ if (!(0, decision_codes_1.isDurableDelegationDecisionCode)(reason) || row.delegationId === null) {
98
+ return undefined;
99
+ }
100
+ if (reason === decision_codes_1.DurableDelegationDecisionCode.AuthorityUnavailable) {
101
+ return new holder_errors_1.DelegationUseDeniedError(row.delegationId, detail);
102
+ }
103
+ await store.writeIf(row, { ...row, state: HolderDelegationState.Ended, carrierId: null });
104
+ return new holder_errors_1.DelegationEndedError(row.delegationId, undefined);
105
+ }
106
+ async refresh(store, orgId) {
107
+ const row = await store.read();
108
+ if (row === null || row.delegationId === null) {
109
+ return row;
110
+ }
111
+ const view = await this.client.read(orgId, row.delegationId);
112
+ const next = rowOf(view);
113
+ if (next.state === row.state && next.carrierId === row.carrierId) {
114
+ return row;
115
+ }
116
+ return (await store.writeIf(row, next)) ? next : store.read();
117
+ }
118
+ async endFor(row, orgId) {
119
+ if (row.delegationId !== null) {
120
+ await this.client.revoke(orgId, row.delegationId);
121
+ }
122
+ }
123
+ async revokeQuietly(orgId, delegationId) {
124
+ try {
125
+ await this.client.revoke(orgId, delegationId);
126
+ }
127
+ catch (error) {
128
+ this.logger.warn({
129
+ message: 'durable-delegation-superseded-revoke-failed',
130
+ delegationId,
131
+ error: error instanceof Error ? error.message : String(error),
132
+ });
133
+ }
134
+ }
135
+ };
136
+ exports.DurableDelegationHolder = DurableDelegationHolder;
137
+ exports.DurableDelegationHolder = DurableDelegationHolder = DurableDelegationHolder_1 = __decorate([
138
+ (0, common_1.Injectable)(),
139
+ __metadata("design:paramtypes", [holder_client_1.DurableDelegationHolderClient])
140
+ ], DurableDelegationHolder);
141
+ function rowOf(view) {
142
+ switch (view.state) {
143
+ case holder_client_1.DurableDelegationRecordState.Active:
144
+ return {
145
+ state: view.carrierId === undefined ? HolderDelegationState.Unprovisioned : HolderDelegationState.Held,
146
+ delegationId: view.id,
147
+ carrierId: view.carrierId ?? null,
148
+ capabilities: [...view.capabilities],
149
+ };
150
+ case holder_client_1.DurableDelegationRecordState.Provisioning:
151
+ return { state: HolderDelegationState.Unprovisioned, delegationId: view.id, carrierId: null, capabilities: [...view.capabilities] };
152
+ case holder_client_1.DurableDelegationRecordState.Revoked:
153
+ case holder_client_1.DurableDelegationRecordState.Expired:
154
+ return { state: HolderDelegationState.Ended, delegationId: view.id, carrierId: null, capabilities: [...view.capabilities] };
155
+ }
156
+ }
157
+ function needTransition(row, need) {
158
+ if (need === null) {
159
+ return row.state === HolderDelegationState.NotRequired && row.delegationId === null
160
+ ? null
161
+ : { state: HolderDelegationState.NotRequired, delegationId: null, carrierId: null, capabilities: [] };
162
+ }
163
+ const lendsExactly = row.capabilities.length === need.capabilities.length &&
164
+ need.capabilities.every((c) => row.capabilities.includes(c));
165
+ if (row.delegationId !== null && lendsExactly) {
166
+ return null;
167
+ }
168
+ if (row.state === HolderDelegationState.Required && row.delegationId === null) {
169
+ return null;
170
+ }
171
+ return { state: HolderDelegationState.Required, delegationId: null, carrierId: null, capabilities: [] };
172
+ }
173
+ //# sourceMappingURL=holder-lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holder-lifecycle.js","sourceRoot":"","sources":["../../src/durable-delegation/holder-lifecycle.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAkPA,sBAeC;AAGD,wCAmBC;AAvRD,2CAAuE;AAGvE,qDAG0B;AAC1B,mDAKyB;AACzB,mDAKyB;AAazB,IAAY,qBAWX;AAXD,WAAY,qBAAqB;IAE/B,qDAA4B,CAAA;IAE5B,8CAAqB,CAAA;IA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AK,qBAAqB,CAAC,WAAW,IAAI,GAAG,CAAC,YAAY,KAAK,IAAI;YACjF,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,EAAE,KAAK,EAAE,qBAAqB,CAAC,WAAW,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IAC1G,CAAC;IACD,MAAM,YAAY,GAChB,GAAG,CAAC,YAAY,CAAC,MAAM,KAAK,IAAI,CAAC,YAAY,CAAC,MAAM;QACpD,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,IAAI,GAAG,CAAC,YAAY,KAAK,IAAI,IAAI,YAAY,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,GAAG,CAAC,KAAK,KAAK,qBAAqB,CAAC,QAAQ,IAAI,GAAG,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;QAC9E,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,qBAAqB,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;AAC1G,CAAC"}
package/dist/index.d.ts CHANGED
@@ -11,4 +11,8 @@ export * from './route-action-evaluator';
11
11
  export * from './internal-caller-or-member-context.guard';
12
12
  export * from './organization-delegation-admission';
13
13
  export * from './relayable-caller';
14
+ export * from './durable-delegation/decision-codes';
15
+ export * from './durable-delegation/holder-client';
16
+ export * from './durable-delegation/holder-errors';
17
+ export * from './durable-delegation/holder-lifecycle';
14
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2CAA2C,CAAC;AAC1D,cAAc,qCAAqC,CAAC;AACpD,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2CAA2C,CAAC;AAC1D,cAAc,qCAAqC,CAAC;AACpD,cAAc,oBAAoB,CAAC;AACnC,cAAc,qCAAqC,CAAC;AACpD,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,uCAAuC,CAAC"}
package/dist/index.js CHANGED
@@ -27,4 +27,8 @@ __exportStar(require("./route-action-evaluator"), exports);
27
27
  __exportStar(require("./internal-caller-or-member-context.guard"), exports);
28
28
  __exportStar(require("./organization-delegation-admission"), exports);
29
29
  __exportStar(require("./relayable-caller"), exports);
30
+ __exportStar(require("./durable-delegation/decision-codes"), exports);
31
+ __exportStar(require("./durable-delegation/holder-client"), exports);
32
+ __exportStar(require("./durable-delegation/holder-errors"), exports);
33
+ __exportStar(require("./durable-delegation/holder-lifecycle"), exports);
30
34
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,yDAAuC;AACvC,0DAAwC;AACxC,wDAAsC;AACtC,sDAAoC;AACpC,yDAAuC;AACvC,uDAAqC;AACrC,qDAAmC;AACnC,yDAAuC;AACvC,2DAAyC;AACzC,4EAA0D;AAC1D,sEAAoD;AACpD,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,yDAAuC;AACvC,0DAAwC;AACxC,wDAAsC;AACtC,sDAAoC;AACpC,yDAAuC;AACvC,uDAAqC;AACrC,qDAAmC;AACnC,yDAAuC;AACvC,2DAAyC;AACzC,4EAA0D;AAC1D,sEAAoD;AACpD,qDAAmC;AACnC,sEAAoD;AACpD,qEAAmD;AACnD,qEAAmD;AACnD,wEAAsD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xemahq/authorization-nest",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "AuthZEN 1.0 PEP for Xema services: one Nest module, an AuthZEN client against authorization-api, and the @Authorize route guard.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -24,11 +24,11 @@
24
24
  "@nestjs/common": "11.1.18",
25
25
  "@nestjs/core": "11.1.18",
26
26
  "@nestjs/testing": "11.1.18",
27
- "@xemahq/contracts": ">=0.50.0",
28
- "@xemahq/eslint-config": "^0.5.0",
27
+ "@xemahq/contracts": ">=0.59.0",
28
+ "@xemahq/eslint-config": "^0.12.0",
29
29
  "@xemahq/identity-client": "^0.16.0",
30
- "@xemahq/platform-common": "^0.60.0",
31
- "@xemahq/service-registry-nest": "^0.19.0",
30
+ "@xemahq/platform-common": "^0.64.0",
31
+ "@xemahq/service-registry-nest": "^0.20.0",
32
32
  "@types/jest": "^30.0.0",
33
33
  "@types/node": "25.2.3",
34
34
  "eslint": "^9.39.4",