@xemahq/authorization-nest 0.5.0 → 0.7.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/dist/authzen.transport.d.ts +11 -8
- package/dist/authzen.transport.d.ts.map +1 -1
- package/dist/authzen.transport.js +20 -12
- package/dist/authzen.transport.js.map +1 -1
- package/dist/durable-delegation/carrier-mint.d.ts +20 -0
- package/dist/durable-delegation/carrier-mint.d.ts.map +1 -0
- package/dist/durable-delegation/carrier-mint.js +19 -0
- package/dist/durable-delegation/carrier-mint.js.map +1 -0
- package/dist/durable-delegation/carrier-shape.d.ts +8 -0
- package/dist/durable-delegation/carrier-shape.d.ts.map +1 -0
- package/dist/durable-delegation/carrier-shape.js +32 -0
- package/dist/durable-delegation/carrier-shape.js.map +1 -0
- package/dist/durable-delegation/carrier-window.d.ts +21 -0
- package/dist/durable-delegation/carrier-window.d.ts.map +1 -0
- package/dist/durable-delegation/carrier-window.js +28 -0
- package/dist/durable-delegation/carrier-window.js.map +1 -0
- package/dist/durable-delegation/decision-codes.d.ts +6 -0
- package/dist/durable-delegation/decision-codes.d.ts.map +1 -0
- package/dist/durable-delegation/decision-codes.js +14 -0
- package/dist/durable-delegation/decision-codes.js.map +1 -0
- package/dist/durable-delegation/holder-client.d.ts +121 -0
- package/dist/durable-delegation/holder-client.d.ts.map +1 -0
- package/dist/durable-delegation/holder-client.js +274 -0
- package/dist/durable-delegation/holder-client.js.map +1 -0
- package/dist/durable-delegation/holder-errors.d.ts +28 -0
- package/dist/durable-delegation/holder-errors.d.ts.map +1 -0
- package/dist/durable-delegation/holder-errors.js +57 -0
- package/dist/durable-delegation/holder-errors.js.map +1 -0
- package/dist/durable-delegation/holder-lifecycle.d.ts +50 -0
- package/dist/durable-delegation/holder-lifecycle.d.ts.map +1 -0
- package/dist/durable-delegation/holder-lifecycle.js +187 -0
- package/dist/durable-delegation/holder-lifecycle.js.map +1 -0
- package/dist/ephemeral-delegation/ephemeral-delegation.d.ts +71 -0
- package/dist/ephemeral-delegation/ephemeral-delegation.d.ts.map +1 -0
- package/dist/ephemeral-delegation/ephemeral-delegation.js +147 -0
- package/dist/ephemeral-delegation/ephemeral-delegation.js.map +1 -0
- package/dist/grant-version.reader.d.ts +3 -2
- package/dist/grant-version.reader.d.ts.map +1 -1
- package/dist/grant-version.reader.js +6 -3
- package/dist/grant-version.reader.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/route-action-evaluator.js +3 -3
- package/dist/route-action-evaluator.js.map +1 -1
- package/dist/subject-from-context.d.ts.map +1 -1
- package/dist/subject-from-context.js.map +1 -1
- package/dist/xema-authz.service.d.ts.map +1 -1
- package/dist/xema-authz.service.js +14 -6
- package/dist/xema-authz.service.js.map +1 -1
- package/package.json +19 -14
|
@@ -0,0 +1,274 @@
|
|
|
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
|
+
var DurableDelegationHolderClient_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.DurableDelegationHolderClient = exports.DurableDelegationRequestError = exports.DurableDelegationErrorCode = exports.DurableDelegationEndReason = exports.DurableDelegationRecordState = exports.DurableDelegationOwnerKind = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const service_registry_1 = require("@xemahq/contracts/service-registry");
|
|
19
|
+
const identity_client_1 = require("@xemahq/identity-client");
|
|
20
|
+
const platform_common_1 = require("@xemahq/platform-common");
|
|
21
|
+
const service_registry_nest_1 = require("@xemahq/service-registry-nest");
|
|
22
|
+
const carrier_shape_1 = require("./carrier-shape");
|
|
23
|
+
const carrier_window_1 = require("./carrier-window");
|
|
24
|
+
const holder_errors_1 = require("./holder-errors");
|
|
25
|
+
var DurableDelegationOwnerKind;
|
|
26
|
+
(function (DurableDelegationOwnerKind) {
|
|
27
|
+
DurableDelegationOwnerKind["User"] = "USER";
|
|
28
|
+
DurableDelegationOwnerKind["Org"] = "ORG";
|
|
29
|
+
})(DurableDelegationOwnerKind || (exports.DurableDelegationOwnerKind = DurableDelegationOwnerKind = {}));
|
|
30
|
+
var DurableDelegationRecordState;
|
|
31
|
+
(function (DurableDelegationRecordState) {
|
|
32
|
+
DurableDelegationRecordState["Provisioning"] = "PROVISIONING";
|
|
33
|
+
DurableDelegationRecordState["Active"] = "ACTIVE";
|
|
34
|
+
DurableDelegationRecordState["Revoked"] = "REVOKED";
|
|
35
|
+
DurableDelegationRecordState["Expired"] = "EXPIRED";
|
|
36
|
+
})(DurableDelegationRecordState || (exports.DurableDelegationRecordState = DurableDelegationRecordState = {}));
|
|
37
|
+
var DurableDelegationEndReason;
|
|
38
|
+
(function (DurableDelegationEndReason) {
|
|
39
|
+
DurableDelegationEndReason["Explicit"] = "EXPLICIT";
|
|
40
|
+
DurableDelegationEndReason["AnchorInactive"] = "ANCHOR_INACTIVE";
|
|
41
|
+
DurableDelegationEndReason["AnchorDeleted"] = "ANCHOR_DELETED";
|
|
42
|
+
DurableDelegationEndReason["OwnerDeleted"] = "OWNER_DELETED";
|
|
43
|
+
DurableDelegationEndReason["Expired"] = "EXPIRED";
|
|
44
|
+
DurableDelegationEndReason["ParentEnded"] = "PARENT_ENDED";
|
|
45
|
+
})(DurableDelegationEndReason || (exports.DurableDelegationEndReason = DurableDelegationEndReason = {}));
|
|
46
|
+
var DurableDelegationErrorCode;
|
|
47
|
+
(function (DurableDelegationErrorCode) {
|
|
48
|
+
DurableDelegationErrorCode["CreationRefused"] = "DURABLE_DELEGATION_CREATION_REFUSED";
|
|
49
|
+
DurableDelegationErrorCode["NotFound"] = "DURABLE_DELEGATION_NOT_FOUND";
|
|
50
|
+
DurableDelegationErrorCode["NotActive"] = "DURABLE_DELEGATION_NOT_ACTIVE";
|
|
51
|
+
DurableDelegationErrorCode["CarrierUnavailable"] = "DURABLE_DELEGATION_CARRIER_UNAVAILABLE";
|
|
52
|
+
DurableDelegationErrorCode["RevocationNotPermitted"] = "DURABLE_DELEGATION_REVOCATION_NOT_PERMITTED";
|
|
53
|
+
DurableDelegationErrorCode["HolderMismatch"] = "DURABLE_DELEGATION_HOLDER_IS_NOT_PRESENTER";
|
|
54
|
+
DurableDelegationErrorCode["RequestKeyConflict"] = "DURABLE_DELEGATION_REQUEST_KEY_CONFLICT";
|
|
55
|
+
DurableDelegationErrorCode["CarrierAlreadyBound"] = "DURABLE_DELEGATION_CARRIER_ALREADY_BOUND";
|
|
56
|
+
DurableDelegationErrorCode["AnchorTypeNotDeclared"] = "DELEGATION_ANCHOR_TYPE_NOT_DECLARED";
|
|
57
|
+
DurableDelegationErrorCode["AnchorOriginationNotDeclared"] = "DELEGATION_ANCHOR_ORIGINATION_NOT_DECLARED";
|
|
58
|
+
DurableDelegationErrorCode["ChainTooDeep"] = "DELEGATION_CHAIN_TOO_DEEP";
|
|
59
|
+
DurableDelegationErrorCode["Ended"] = "DURABLE_DELEGATION_ENDED";
|
|
60
|
+
DurableDelegationErrorCode["MemberBoundParent"] = "DURABLE_DELEGATION_MEMBER_BOUND_PARENT";
|
|
61
|
+
DurableDelegationErrorCode["RootCarrierNotPresenterRenewed"] = "DURABLE_DELEGATION_ROOT_CARRIER_NOT_PRESENTER_RENEWED";
|
|
62
|
+
DurableDelegationErrorCode["BeyondHolderDeclarations"] = "DELEGATION_BEYOND_HOLDER_DECLARATIONS";
|
|
63
|
+
DurableDelegationErrorCode["HolderDeclarationsUnstamped"] = "DELEGATION_HOLDER_DECLARATIONS_UNSTAMPED";
|
|
64
|
+
})(DurableDelegationErrorCode || (exports.DurableDelegationErrorCode = DurableDelegationErrorCode = {}));
|
|
65
|
+
class DurableDelegationRequestError extends Error {
|
|
66
|
+
status;
|
|
67
|
+
code;
|
|
68
|
+
constructor(message, status, code) {
|
|
69
|
+
super(message);
|
|
70
|
+
this.status = status;
|
|
71
|
+
this.code = code;
|
|
72
|
+
this.name = 'DurableDelegationRequestError';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.DurableDelegationRequestError = DurableDelegationRequestError;
|
|
76
|
+
const DELEGATED_CONTEXT_AUDIENCE = service_registry_1.ServiceName.XEMA_CAPABILITY_ROUTER;
|
|
77
|
+
let DurableDelegationHolderClient = DurableDelegationHolderClient_1 = class DurableDelegationHolderClient {
|
|
78
|
+
registry;
|
|
79
|
+
identity;
|
|
80
|
+
logger = new common_1.Logger(DurableDelegationHolderClient_1.name);
|
|
81
|
+
constructor(registry, identity) {
|
|
82
|
+
this.registry = registry;
|
|
83
|
+
this.identity = identity;
|
|
84
|
+
}
|
|
85
|
+
async originate(author, input) {
|
|
86
|
+
return this.send('POST', '/durable-delegations/originate', author.orgId, {
|
|
87
|
+
...(await (0, platform_common_1.forwardedCallerHeaders)(author, this.identity)),
|
|
88
|
+
}, {
|
|
89
|
+
anchorType: input.anchorType,
|
|
90
|
+
anchorId: input.anchorId,
|
|
91
|
+
requestKey: input.requestKey,
|
|
92
|
+
environmentId: input.environmentId,
|
|
93
|
+
...(input.capabilities === undefined ? {} : { capabilities: [...input.capabilities] }),
|
|
94
|
+
...(input.redelegable === undefined ? {} : { redelegable: [...input.redelegable] }),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async createChild(orgId, parentId, request) {
|
|
98
|
+
const child = await this.postChild(orgId, parentId, request);
|
|
99
|
+
if (child.carrierId !== undefined) {
|
|
100
|
+
return child;
|
|
101
|
+
}
|
|
102
|
+
const parent = await this.read(orgId, parentId);
|
|
103
|
+
if (parent.state !== DurableDelegationRecordState.Active) {
|
|
104
|
+
throw new holder_errors_1.DelegationEndedError(parent.id, parent.endReason);
|
|
105
|
+
}
|
|
106
|
+
if (parent.carrierId === undefined) {
|
|
107
|
+
throw new holder_errors_1.DelegationRequiredError(holder_errors_1.DelegationRequiredReason.Unprovisioned, `durable delegation ${parent.id}`);
|
|
108
|
+
}
|
|
109
|
+
const carrier = await this.identity.createDelegation({
|
|
110
|
+
parentId: parent.carrierId,
|
|
111
|
+
organizationId: orgId,
|
|
112
|
+
delegateWorkload: child.holderWorkload,
|
|
113
|
+
...(request.holderMember === undefined ? {} : { delegateMember: request.holderMember }),
|
|
114
|
+
capabilities: [...child.capabilities],
|
|
115
|
+
redelegableCapabilities: [...child.redelegable],
|
|
116
|
+
resourceScope: [...child.scope, (0, carrier_shape_1.durableDelegationRootMarker)(child.rootId)],
|
|
117
|
+
basis: (0, carrier_shape_1.durableDelegationBasis)(child.id),
|
|
118
|
+
authorizingAction: carrier_shape_1.DURABLE_DELEGATION_CARRY_ACTION,
|
|
119
|
+
renewable: true,
|
|
120
|
+
...(child.expiresAt === undefined ? {} : { expiresAt: child.expiresAt }),
|
|
121
|
+
});
|
|
122
|
+
return this.bindOrResume(orgId, parentId, request, child.id, carrier.id);
|
|
123
|
+
}
|
|
124
|
+
async read(orgId, delegationId) {
|
|
125
|
+
return this.send('GET', `/internal/durable-delegations/${encodeURIComponent(delegationId)}`, orgId, await this.serviceHeaders());
|
|
126
|
+
}
|
|
127
|
+
async revoke(orgId, delegationId) {
|
|
128
|
+
return this.send('POST', `/internal/durable-delegations/${encodeURIComponent(delegationId)}/revoke`, orgId, await this.serviceHeaders());
|
|
129
|
+
}
|
|
130
|
+
async supersede(orgId, delegationId, original) {
|
|
131
|
+
try {
|
|
132
|
+
return await this.send('POST', `/internal/durable-delegations/${encodeURIComponent(delegationId)}/supersede`, orgId, await this.serviceHeaders());
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
throw new holder_errors_1.DelegationSupersedeFailedError(delegationId, original, error);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async renewCarrier(orgId, delegationId) {
|
|
139
|
+
const view = await this.read(orgId, delegationId);
|
|
140
|
+
if (view.state === DurableDelegationRecordState.Revoked || view.state === DurableDelegationRecordState.Expired) {
|
|
141
|
+
throw new holder_errors_1.DelegationEndedError(view.id, view.endReason);
|
|
142
|
+
}
|
|
143
|
+
if (view.state !== DurableDelegationRecordState.Active || view.carrierId === undefined) {
|
|
144
|
+
throw new holder_errors_1.DelegationRequiredError(holder_errors_1.DelegationRequiredReason.Unprovisioned, `durable delegation ${view.id}`);
|
|
145
|
+
}
|
|
146
|
+
if (view.parentId === undefined) {
|
|
147
|
+
return carrier_window_1.CarrierRenewalOutcome.RenewedByAuthorizationApi;
|
|
148
|
+
}
|
|
149
|
+
const carrierId = view.carrierId;
|
|
150
|
+
const carrier = await this.identity.getDelegation(carrierId);
|
|
151
|
+
if (carrier.status !== identity_client_1.DelegationStatus.Active) {
|
|
152
|
+
throw new holder_errors_1.DelegationUseDeniedError(view.id, `its carrier ${carrierId} is ${carrier.status}`);
|
|
153
|
+
}
|
|
154
|
+
if (carrier.expiresAt === null) {
|
|
155
|
+
return carrier_window_1.CarrierRenewalOutcome.NotDue;
|
|
156
|
+
}
|
|
157
|
+
const window = await this.reportCarrierWindow(orgId, view.id, carrierId, carrier.expiresAt);
|
|
158
|
+
const plan = (0, carrier_window_1.planChildCarrierRenewal)(new Date(), new Date(carrier.expiresAt), window.renewalCeiling === undefined ? undefined : new Date(window.renewalCeiling));
|
|
159
|
+
if (plan.outcome !== carrier_window_1.CarrierRenewalOutcome.Renewed) {
|
|
160
|
+
return plan.outcome;
|
|
161
|
+
}
|
|
162
|
+
const renewed = await this.identity.renewDelegation(carrierId, plan.expiresAt.toISOString());
|
|
163
|
+
await this.reportCarrierWindow(orgId, view.id, carrierId, renewed.expiresAt ?? plan.expiresAt.toISOString());
|
|
164
|
+
return carrier_window_1.CarrierRenewalOutcome.Renewed;
|
|
165
|
+
}
|
|
166
|
+
async mintContext(carrierId) {
|
|
167
|
+
const minted = await this.mintDelegatedContext({
|
|
168
|
+
delegationId: carrierId,
|
|
169
|
+
audience: DELEGATED_CONTEXT_AUDIENCE,
|
|
170
|
+
});
|
|
171
|
+
return minted.accessToken;
|
|
172
|
+
}
|
|
173
|
+
mintDelegatedContext(params) {
|
|
174
|
+
return this.identity.mintDelegatedContext(params);
|
|
175
|
+
}
|
|
176
|
+
async bindOrResume(orgId, parentId, request, childId, carrierId) {
|
|
177
|
+
try {
|
|
178
|
+
return await this.send('POST', `/internal/durable-delegations/${encodeURIComponent(childId)}/carrier`, orgId, await this.serviceHeaders(), { carrierId });
|
|
179
|
+
}
|
|
180
|
+
catch (bindError) {
|
|
181
|
+
if (bindError instanceof DurableDelegationRequestError && bindError.code === DurableDelegationErrorCode.CarrierAlreadyBound) {
|
|
182
|
+
throw bindError;
|
|
183
|
+
}
|
|
184
|
+
let current;
|
|
185
|
+
try {
|
|
186
|
+
current = await this.postChild(orgId, parentId, request);
|
|
187
|
+
}
|
|
188
|
+
catch (rereadError) {
|
|
189
|
+
if (rereadError instanceof DurableDelegationRequestError && rereadError.code === DurableDelegationErrorCode.Ended) {
|
|
190
|
+
await this.revokeUnboundCarrier(childId, carrierId);
|
|
191
|
+
throw rereadError;
|
|
192
|
+
}
|
|
193
|
+
this.logger.error({
|
|
194
|
+
message: 'durable-delegation-child-carrier-unconfirmed',
|
|
195
|
+
childId,
|
|
196
|
+
carrierId,
|
|
197
|
+
error: bindError instanceof Error ? bindError.message : String(bindError),
|
|
198
|
+
});
|
|
199
|
+
throw bindError;
|
|
200
|
+
}
|
|
201
|
+
if (current.carrierId === carrierId) {
|
|
202
|
+
return current;
|
|
203
|
+
}
|
|
204
|
+
await this.revokeUnboundCarrier(childId, carrierId);
|
|
205
|
+
if (current.carrierId !== undefined) {
|
|
206
|
+
return current;
|
|
207
|
+
}
|
|
208
|
+
throw bindError;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async revokeUnboundCarrier(childId, carrierId) {
|
|
212
|
+
try {
|
|
213
|
+
await this.identity.revokeDelegation(carrierId);
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
this.logger.error({
|
|
217
|
+
message: 'durable-delegation-child-carrier-revoke-failed',
|
|
218
|
+
childId,
|
|
219
|
+
carrierId,
|
|
220
|
+
error: error instanceof Error ? error.message : String(error),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async postChild(orgId, parentId, request) {
|
|
225
|
+
return this.send('POST', `/internal/durable-delegations/${encodeURIComponent(parentId)}/children`, orgId, await this.serviceHeaders(), {
|
|
226
|
+
scope: [...request.scope],
|
|
227
|
+
capabilities: [...request.capabilities],
|
|
228
|
+
...(request.redelegable === undefined ? {} : { redelegable: [...request.redelegable] }),
|
|
229
|
+
holderWorkload: request.holderWorkload,
|
|
230
|
+
...(request.holderMember === undefined ? {} : { holderMember: request.holderMember }),
|
|
231
|
+
requestKey: request.requestKey,
|
|
232
|
+
...(request.expiresAt === undefined ? {} : { expiresAt: request.expiresAt.toISOString() }),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
async reportCarrierWindow(orgId, delegationId, carrierId, expiresAt) {
|
|
236
|
+
return this.send('POST', `/internal/durable-delegations/${encodeURIComponent(delegationId)}/carrier/window`, orgId, await this.serviceHeaders(), { carrierId, expiresAt });
|
|
237
|
+
}
|
|
238
|
+
async serviceHeaders() {
|
|
239
|
+
return { Authorization: `Bearer ${await this.identity.getAccessToken()}` };
|
|
240
|
+
}
|
|
241
|
+
async send(method, path, orgId, headers, body) {
|
|
242
|
+
const baseUrl = await (0, service_registry_nest_1.resolveHttpUrl)(this.registry, service_registry_1.ServiceName.AUTHORIZATION_API);
|
|
243
|
+
const response = await fetch(`${baseUrl.replace(/\/+$/, '')}${path}`, {
|
|
244
|
+
method,
|
|
245
|
+
headers: {
|
|
246
|
+
...headers,
|
|
247
|
+
'X-Xema-Org-Id': orgId,
|
|
248
|
+
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
|
|
249
|
+
},
|
|
250
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
251
|
+
});
|
|
252
|
+
if (!response.ok) {
|
|
253
|
+
const text = await response.text();
|
|
254
|
+
throw new DurableDelegationRequestError(`authorization-api ${method} ${path} failed with HTTP ${response.status}: ${text.slice(0, 2000)}`, response.status, codeOf(text));
|
|
255
|
+
}
|
|
256
|
+
return (0, platform_common_1.unwrapPlatformResponseEnvelope)(await response.json(), `authorization-api ${method} ${path}`);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
exports.DurableDelegationHolderClient = DurableDelegationHolderClient;
|
|
260
|
+
exports.DurableDelegationHolderClient = DurableDelegationHolderClient = DurableDelegationHolderClient_1 = __decorate([
|
|
261
|
+
(0, common_1.Injectable)(),
|
|
262
|
+
__param(0, (0, common_1.Inject)(service_registry_nest_1.SERVICE_REGISTRY_TOKEN)),
|
|
263
|
+
__metadata("design:paramtypes", [Object, identity_client_1.IdentityBootstrapService])
|
|
264
|
+
], DurableDelegationHolderClient);
|
|
265
|
+
function codeOf(text) {
|
|
266
|
+
try {
|
|
267
|
+
const parsed = JSON.parse(text);
|
|
268
|
+
return typeof parsed.code === 'string' ? parsed.code : undefined;
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
//# 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,2CAA4D;AAC5D,yEAG4C;AAC5C,6DAA6G;AAC7G,6DAIiC;AACjC,yEAGuC;AAEvC,mDAIyB;AACzB,qDAAkF;AAClF,mDAMyB;AAOzB,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,2CAAa,CAAA;IACb,yCAAW,CAAA;AACb,CAAC,EAHW,0BAA0B,0CAA1B,0BAA0B,QAGrC;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;AAGD,IAAY,0BAQX;AARD,WAAY,0BAA0B;IACpC,mDAAqB,CAAA;IACrB,gEAAkC,CAAA;IAClC,8DAAgC,CAAA;IAChC,4DAA8B,CAAA;IAC9B,iDAAmB,CAAA;IAEnB,0DAA4B,CAAA;AAC9B,CAAC,EARW,0BAA0B,0CAA1B,0BAA0B,QAQrC;AAGD,IAAY,0BAwBX;AAxBD,WAAY,0BAA0B;IACpC,qFAAuD,CAAA;IACvD,uEAAyC,CAAA;IACzC,yEAA2C,CAAA;IAC3C,2FAA6D,CAAA;IAC7D,oGAAsE,CAAA;IACtE,2FAA6D,CAAA;IAC7D,4FAA8D,CAAA;IAE9D,8FAAgE,CAAA;IAChE,2FAA6D,CAAA;IAE7D,yGAA2E,CAAA;IAC3E,wEAA0C,CAAA;IAE1C,gEAAkC,CAAA;IAElC,0FAA4D,CAAA;IAE5D,sHAAwF,CAAA;IAExF,gGAAkE,CAAA;IAElE,sGAAwE,CAAA;AAC1E,CAAC,EAxBW,0BAA0B,0CAA1B,0BAA0B,QAwBrC;AAkGD,MAAa,6BAA8B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,qBAAqB,MAAM,IAAI,IAAI,qBAAqB,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EACjG,QAAQ,CAAC,MAAM,EACf,MAAM,CAAC,IAAI,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;AAjWY,sEAA6B;wCAA7B,6BAA6B;IADzC,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,8CAAsB,CAAC,CAAA;6CACJ,0CAAwB;GAL1C,6BAA6B,CAiWzC;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,28 @@
|
|
|
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
|
+
export declare class DelegationSupersedeFailedError extends Error {
|
|
23
|
+
readonly delegationId: string;
|
|
24
|
+
readonly original: unknown;
|
|
25
|
+
readonly cause: unknown;
|
|
26
|
+
constructor(delegationId: string, original: unknown, cause: unknown);
|
|
27
|
+
}
|
|
28
|
+
//# 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;AAUD,qBAAa,8BAA+B,SAAQ,KAAK;aAErC,YAAY,EAAE,MAAM;aACpB,QAAQ,EAAE,OAAO;aACR,KAAK,EAAE,OAAO;gBAFvB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,OAAO,EACR,KAAK,EAAE,OAAO;CAO1C"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DelegationSupersedeFailedError = 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
|
+
class DelegationSupersedeFailedError extends Error {
|
|
45
|
+
delegationId;
|
|
46
|
+
original;
|
|
47
|
+
cause;
|
|
48
|
+
constructor(delegationId, original, cause) {
|
|
49
|
+
super(`durable delegation ${delegationId} could not be superseded: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
50
|
+
this.delegationId = delegationId;
|
|
51
|
+
this.original = original;
|
|
52
|
+
this.cause = cause;
|
|
53
|
+
this.name = 'DelegationSupersedeFailedError';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.DelegationSupersedeFailedError = DelegationSupersedeFailedError;
|
|
57
|
+
//# 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;AAUD,MAAa,8BAA+B,SAAQ,KAAK;IAErC;IACA;IACS;IAH3B,YACkB,YAAoB,EACpB,QAAiB,EACR,KAAc;QAEvC,KAAK,CACH,sBAAsB,YAAY,6BAA6B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACxH,CAAC;QANc,iBAAY,GAAZ,YAAY,CAAQ;QACpB,aAAQ,GAAR,QAAQ,CAAS;QACR,UAAK,GAAL,KAAK,CAAS;QAKvC,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC/C,CAAC;CACF;AAXD,wEAWC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type DurableDelegationCarrierRef } from './carrier-mint';
|
|
2
|
+
import { CarrierRenewalOutcome } from './carrier-window';
|
|
3
|
+
import { type OriginateDurableDelegationInput, DurableDelegationHolderClient, type DurableDelegationView } from './holder-client';
|
|
4
|
+
import { DelegationEndedError, DelegationUseDeniedError } from './holder-errors';
|
|
5
|
+
import type { ForwardedCallerContext } from '@xemahq/platform-common';
|
|
6
|
+
import type { HeldDurableDelegation } from '@xemahq/xema-service-nest';
|
|
7
|
+
export declare enum HolderDelegationState {
|
|
8
|
+
NotRequired = "not_required",
|
|
9
|
+
Required = "required",
|
|
10
|
+
Unprovisioned = "unprovisioned",
|
|
11
|
+
Held = "held",
|
|
12
|
+
Ended = "ended"
|
|
13
|
+
}
|
|
14
|
+
export declare enum HolderRenewal {
|
|
15
|
+
NotHeld = "not-held"
|
|
16
|
+
}
|
|
17
|
+
export interface HolderDelegationRow {
|
|
18
|
+
readonly state: HolderDelegationState;
|
|
19
|
+
readonly delegationId: string | null;
|
|
20
|
+
readonly carrierId: string | null;
|
|
21
|
+
readonly capabilities: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
export interface HolderDelegationStore {
|
|
24
|
+
read(): Promise<HolderDelegationRow | null>;
|
|
25
|
+
writeIf(expected: Pick<HolderDelegationRow, 'state' | 'delegationId'>, next: HolderDelegationRow): Promise<boolean>;
|
|
26
|
+
}
|
|
27
|
+
export interface HolderDelegationNeed {
|
|
28
|
+
readonly capabilities: readonly string[];
|
|
29
|
+
}
|
|
30
|
+
export interface HeldAuthority {
|
|
31
|
+
readonly delegationId: string;
|
|
32
|
+
readonly orgId: string;
|
|
33
|
+
readonly authorization: string;
|
|
34
|
+
}
|
|
35
|
+
export declare class DurableDelegationHolder {
|
|
36
|
+
private readonly client;
|
|
37
|
+
constructor(client: DurableDelegationHolderClient);
|
|
38
|
+
reconcileNeed(store: HolderDelegationStore, orgId: string, need: HolderDelegationNeed | null): Promise<HolderDelegationRow>;
|
|
39
|
+
authorize(store: HolderDelegationStore, author: ForwardedCallerContext, input: OriginateDurableDelegationInput): Promise<HolderDelegationRow>;
|
|
40
|
+
authority(row: HolderDelegationRow, orgId: string, subject: string): Promise<HeldAuthority>;
|
|
41
|
+
carrierRef(row: HolderDelegationRow, orgId: string, subject: string): DurableDelegationCarrierRef;
|
|
42
|
+
held(row: HolderDelegationRow, orgId: string, subject: string): HeldDurableDelegation;
|
|
43
|
+
onDenied(store: HolderDelegationStore, row: HolderDelegationRow, reason: string | undefined, detail: string): Promise<DelegationUseDeniedError | DelegationEndedError | undefined>;
|
|
44
|
+
refresh(store: HolderDelegationStore, orgId: string): Promise<HolderDelegationRow | null>;
|
|
45
|
+
renewCarrier(store: HolderDelegationStore, orgId: string): Promise<CarrierRenewalOutcome | HolderRenewal>;
|
|
46
|
+
endFor(row: HolderDelegationRow, orgId: string): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export declare function rowOf(view: DurableDelegationView): HolderDelegationRow;
|
|
49
|
+
export declare function needTransition(row: HolderDelegationRow, need: HolderDelegationNeed | null): HolderDelegationRow | null;
|
|
50
|
+
//# 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":"AAEA,OAAO,EAAE,KAAK,2BAA2B,EAAyB,MAAM,gBAAgB,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAKzD,OAAO,EACL,KAAK,+BAA+B,EACpC,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;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAWvE,oBAAY,qBAAqB;IAE/B,WAAW,iBAAiB;IAE5B,QAAQ,aAAa;IAErB,aAAa,kBAAkB;IAE/B,IAAI,SAAS;IAEb,KAAK,UAAU;CAChB;AAGD,oBAAY,aAAa;IAEvB,OAAO,aAAa;CACrB;AAGD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,qBAAqB,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BAA2B;IAuBjG,IAAI,CAAC,GAAG,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,qBAAqB;IAS/E,QAAQ,CACnB,KAAK,EAAE,qBAAqB,EAC5B,GAAG,EAAE,mBAAmB,EACxB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,wBAAwB,GAAG,oBAAoB,GAAG,SAAS,CAAC;IAW1D,OAAO,CAAC,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAqBzF,YAAY,CAAC,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,aAAa,CAAC;IAezG,MAAM,CAAC,GAAG,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAK5E;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,187 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DurableDelegationHolder = exports.HolderRenewal = exports.HolderDelegationState = void 0;
|
|
13
|
+
exports.rowOf = rowOf;
|
|
14
|
+
exports.needTransition = needTransition;
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
const carrier_mint_1 = require("./carrier-mint");
|
|
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
|
+
var HolderRenewal;
|
|
29
|
+
(function (HolderRenewal) {
|
|
30
|
+
HolderRenewal["NotHeld"] = "not-held";
|
|
31
|
+
})(HolderRenewal || (exports.HolderRenewal = HolderRenewal = {}));
|
|
32
|
+
const MAX_CAS_ATTEMPTS = 3;
|
|
33
|
+
let DurableDelegationHolder = class DurableDelegationHolder {
|
|
34
|
+
client;
|
|
35
|
+
constructor(client) {
|
|
36
|
+
this.client = client;
|
|
37
|
+
}
|
|
38
|
+
async reconcileNeed(store, orgId, need) {
|
|
39
|
+
for (let attempt = 0; attempt < MAX_CAS_ATTEMPTS; attempt += 1) {
|
|
40
|
+
const row = await store.read();
|
|
41
|
+
if (row === null) {
|
|
42
|
+
throw new common_1.ConflictException('The holder row disappeared while its need was being stated.');
|
|
43
|
+
}
|
|
44
|
+
const next = needTransition(row, need);
|
|
45
|
+
if (next === null) {
|
|
46
|
+
return row;
|
|
47
|
+
}
|
|
48
|
+
if (await store.writeIf(row, next)) {
|
|
49
|
+
if (row.delegationId !== null && next.delegationId === null) {
|
|
50
|
+
await this.client.supersede(orgId, row.delegationId);
|
|
51
|
+
}
|
|
52
|
+
return next;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
throw new common_1.ConflictException('The holder row kept changing while its need was being stated.');
|
|
56
|
+
}
|
|
57
|
+
async authorize(store, author, input) {
|
|
58
|
+
const view = await this.client.originate(author, input);
|
|
59
|
+
const next = rowOf(view);
|
|
60
|
+
for (let attempt = 0; attempt < MAX_CAS_ATTEMPTS; attempt += 1) {
|
|
61
|
+
const row = await store.read();
|
|
62
|
+
if (row === null) {
|
|
63
|
+
const conflict = new common_1.ConflictException('The holder row disappeared while it was being authorised.');
|
|
64
|
+
await this.client.supersede(author.orgId, view.id, conflict);
|
|
65
|
+
throw conflict;
|
|
66
|
+
}
|
|
67
|
+
if (row.delegationId === view.id) {
|
|
68
|
+
return row;
|
|
69
|
+
}
|
|
70
|
+
if (await store.writeIf(row, next)) {
|
|
71
|
+
if (row.delegationId !== null) {
|
|
72
|
+
await this.client.supersede(author.orgId, row.delegationId);
|
|
73
|
+
}
|
|
74
|
+
return next;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
throw new common_1.ConflictException('The holder row kept changing while it was being authorised.');
|
|
78
|
+
}
|
|
79
|
+
async authority(row, orgId, subject) {
|
|
80
|
+
const ref = this.carrierRef(row, orgId, subject);
|
|
81
|
+
return {
|
|
82
|
+
delegationId: ref.delegationId,
|
|
83
|
+
orgId,
|
|
84
|
+
authorization: `Bearer ${await this.client.mintContext(ref.carrierId)}`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
carrierRef(row, orgId, subject) {
|
|
88
|
+
switch (row.state) {
|
|
89
|
+
case HolderDelegationState.Held:
|
|
90
|
+
break;
|
|
91
|
+
case HolderDelegationState.NotRequired:
|
|
92
|
+
case HolderDelegationState.Required:
|
|
93
|
+
throw new holder_errors_1.DelegationRequiredError(holder_errors_1.DelegationRequiredReason.NeverAuthorised, subject);
|
|
94
|
+
case HolderDelegationState.Unprovisioned:
|
|
95
|
+
throw new holder_errors_1.DelegationRequiredError(holder_errors_1.DelegationRequiredReason.Unprovisioned, subject);
|
|
96
|
+
case HolderDelegationState.Ended:
|
|
97
|
+
throw new holder_errors_1.DelegationRequiredError(holder_errors_1.DelegationRequiredReason.Ended, subject);
|
|
98
|
+
}
|
|
99
|
+
if (row.delegationId === null || row.carrierId === null) {
|
|
100
|
+
throw new holder_errors_1.DelegationRequiredError(holder_errors_1.DelegationRequiredReason.Unprovisioned, subject);
|
|
101
|
+
}
|
|
102
|
+
return { delegationId: row.delegationId, organizationId: orgId, carrierId: row.carrierId };
|
|
103
|
+
}
|
|
104
|
+
held(row, orgId, subject) {
|
|
105
|
+
return (0, carrier_mint_1.heldDurableDelegation)(this.client, this.carrierRef(row, orgId, subject));
|
|
106
|
+
}
|
|
107
|
+
async onDenied(store, row, reason, detail) {
|
|
108
|
+
if (!(0, decision_codes_1.isDurableDelegationDecisionCode)(reason) || row.delegationId === null) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
if (reason === decision_codes_1.DurableDelegationDecisionCode.AuthorityUnavailable) {
|
|
112
|
+
return new holder_errors_1.DelegationUseDeniedError(row.delegationId, detail);
|
|
113
|
+
}
|
|
114
|
+
await store.writeIf(row, { ...row, state: HolderDelegationState.Ended, carrierId: null });
|
|
115
|
+
return new holder_errors_1.DelegationEndedError(row.delegationId, undefined);
|
|
116
|
+
}
|
|
117
|
+
async refresh(store, orgId) {
|
|
118
|
+
const row = await store.read();
|
|
119
|
+
if (row === null || row.delegationId === null) {
|
|
120
|
+
return row;
|
|
121
|
+
}
|
|
122
|
+
const view = await this.client.read(orgId, row.delegationId);
|
|
123
|
+
const next = rowOf(view);
|
|
124
|
+
if (next.state === row.state && next.carrierId === row.carrierId) {
|
|
125
|
+
return row;
|
|
126
|
+
}
|
|
127
|
+
return (await store.writeIf(row, next)) ? next : store.read();
|
|
128
|
+
}
|
|
129
|
+
async renewCarrier(store, orgId) {
|
|
130
|
+
const row = await store.read();
|
|
131
|
+
if (row === null || row.state !== HolderDelegationState.Held || row.delegationId === null) {
|
|
132
|
+
return HolderRenewal.NotHeld;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return await this.client.renewCarrier(orgId, row.delegationId);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
if (error instanceof holder_errors_1.DelegationEndedError) {
|
|
139
|
+
await store.writeIf(row, { ...row, state: HolderDelegationState.Ended, carrierId: null });
|
|
140
|
+
}
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async endFor(row, orgId) {
|
|
145
|
+
if (row.delegationId !== null) {
|
|
146
|
+
await this.client.revoke(orgId, row.delegationId);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
exports.DurableDelegationHolder = DurableDelegationHolder;
|
|
151
|
+
exports.DurableDelegationHolder = DurableDelegationHolder = __decorate([
|
|
152
|
+
(0, common_1.Injectable)(),
|
|
153
|
+
__metadata("design:paramtypes", [holder_client_1.DurableDelegationHolderClient])
|
|
154
|
+
], DurableDelegationHolder);
|
|
155
|
+
function rowOf(view) {
|
|
156
|
+
switch (view.state) {
|
|
157
|
+
case holder_client_1.DurableDelegationRecordState.Active:
|
|
158
|
+
return {
|
|
159
|
+
state: view.carrierId === undefined ? HolderDelegationState.Unprovisioned : HolderDelegationState.Held,
|
|
160
|
+
delegationId: view.id,
|
|
161
|
+
carrierId: view.carrierId ?? null,
|
|
162
|
+
capabilities: [...view.capabilities],
|
|
163
|
+
};
|
|
164
|
+
case holder_client_1.DurableDelegationRecordState.Provisioning:
|
|
165
|
+
return { state: HolderDelegationState.Unprovisioned, delegationId: view.id, carrierId: null, capabilities: [...view.capabilities] };
|
|
166
|
+
case holder_client_1.DurableDelegationRecordState.Revoked:
|
|
167
|
+
case holder_client_1.DurableDelegationRecordState.Expired:
|
|
168
|
+
return { state: HolderDelegationState.Ended, delegationId: view.id, carrierId: null, capabilities: [...view.capabilities] };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function needTransition(row, need) {
|
|
172
|
+
if (need === null) {
|
|
173
|
+
return row.state === HolderDelegationState.NotRequired && row.delegationId === null
|
|
174
|
+
? null
|
|
175
|
+
: { state: HolderDelegationState.NotRequired, delegationId: null, carrierId: null, capabilities: [] };
|
|
176
|
+
}
|
|
177
|
+
const lendsExactly = row.capabilities.length === need.capabilities.length &&
|
|
178
|
+
need.capabilities.every((c) => row.capabilities.includes(c));
|
|
179
|
+
if (row.delegationId !== null && lendsExactly) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
if (row.state === HolderDelegationState.Required && row.delegationId === null) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
return { state: HolderDelegationState.Required, delegationId: null, carrierId: null, capabilities: [] };
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=holder-lifecycle.js.map
|