gdc-common-utils-ts 1.24.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/constants/profile-runtime.d.ts +33 -0
- package/dist/constants/profile-runtime.js +30 -0
- package/dist/examples/frontend-session.js +2 -1
- package/dist/examples/ica-activation-proof.d.ts +11 -4
- package/dist/examples/ica-activation-proof.js +11 -4
- package/dist/examples/index.d.ts +1 -0
- package/dist/examples/index.js +1 -0
- package/dist/examples/lifecycle.js +5 -5
- package/dist/examples/organization-controller.d.ts +0 -1
- package/dist/examples/organization-controller.js +0 -1
- package/dist/examples/profile-runtime.d.ts +16 -0
- package/dist/examples/profile-runtime.js +18 -0
- package/dist/examples/shared.d.ts +9 -0
- package/dist/examples/shared.js +9 -0
- package/dist/interfaces/Cryptography.types.d.ts +15 -0
- package/dist/models/identity-bootstrap.d.ts +9 -0
- package/dist/utils/activation-policy.d.ts +45 -1
- package/dist/utils/activation-policy.js +65 -7
- package/dist/utils/activation-request.d.ts +63 -2
- package/dist/utils/activation-request.js +82 -0
- package/dist/utils/communication-participant-search-test-data.d.ts +17 -0
- package/dist/utils/communication-participant-search-test-data.js +39 -0
- package/dist/utils/communication-participant-search.d.ts +108 -0
- package/dist/utils/communication-participant-search.js +425 -0
- package/dist/utils/communication-retention-policy.d.ts +32 -0
- package/dist/utils/communication-retention-policy.js +41 -0
- package/dist/utils/communication-search-editor.d.ts +54 -0
- package/dist/utils/communication-search-editor.js +156 -0
- package/dist/utils/fhir-search.d.ts +32 -0
- package/dist/utils/fhir-search.js +45 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/individual-organization-lifecycle.d.ts +15 -5
- package/dist/utils/individual-organization-lifecycle.js +53 -6
- package/dist/utils/interoperable-resource-operation.d.ts +4 -4
- package/dist/utils/interoperable-resource-operation.js +22 -22
- package/dist/utils/jwk-thumbprint.d.ts +40 -0
- package/dist/utils/jwk-thumbprint.js +57 -0
- package/dist/utils/legal-organization-onboarding.d.ts +97 -0
- package/dist/utils/legal-organization-onboarding.js +128 -0
- package/dist/utils/license-commercial-search.d.ts +6 -6
- package/dist/utils/license-commercial-search.js +2 -2
- package/dist/utils/license-list-search.d.ts +7 -7
- package/dist/utils/license-list-search.js +23 -23
- package/dist/utils/license-offer-order.d.ts +19 -19
- package/dist/utils/license-offer-order.js +68 -68
- package/dist/utils/organization-lifecycle.d.ts +59 -0
- package/dist/utils/organization-lifecycle.js +155 -0
- package/dist/utils/same-as.d.ts +41 -0
- package/dist/utils/same-as.js +83 -0
- package/package.json +2 -2
|
@@ -42,11 +42,11 @@ function cloneOrder(order) {
|
|
|
42
42
|
seats: normalizeNumber(order?.seats),
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function patchState(state, patch) {
|
|
46
46
|
return {
|
|
47
|
-
offer: patch.offer ? cloneOffer({ ...
|
|
48
|
-
order: patch.order ? cloneOrder({ ...
|
|
49
|
-
baseClaims: patch.baseClaims ? cloneClaims(patch.baseClaims) : cloneClaims(
|
|
47
|
+
offer: patch.offer ? cloneOffer({ ...state.offer, ...patch.offer }) : state.offer,
|
|
48
|
+
order: patch.order ? cloneOrder({ ...state.order, ...patch.order }) : state.order,
|
|
49
|
+
baseClaims: patch.baseClaims ? cloneClaims(patch.baseClaims) : cloneClaims(state.baseClaims),
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
@@ -102,80 +102,80 @@ export function readLicenseOrderSummaryFromResponseBody(body) {
|
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
function createEditorFromFacade(facade, initial) {
|
|
105
|
-
let
|
|
105
|
+
let state = facade.createState(initial);
|
|
106
106
|
const editor = {
|
|
107
107
|
setOfferId(value) {
|
|
108
|
-
|
|
108
|
+
state = facade.setOfferId(state, value);
|
|
109
109
|
return editor;
|
|
110
110
|
},
|
|
111
111
|
setAmount(value) {
|
|
112
|
-
|
|
112
|
+
state = facade.setAmount(state, value);
|
|
113
113
|
return editor;
|
|
114
114
|
},
|
|
115
115
|
setCurrency(value) {
|
|
116
|
-
|
|
116
|
+
state = facade.setCurrency(state, value);
|
|
117
117
|
return editor;
|
|
118
118
|
},
|
|
119
119
|
setSeats(value) {
|
|
120
|
-
|
|
120
|
+
state = facade.setSeats(state, value);
|
|
121
121
|
return editor;
|
|
122
122
|
},
|
|
123
123
|
setPlanName(value) {
|
|
124
|
-
|
|
124
|
+
state = facade.setPlanName(state, value);
|
|
125
125
|
return editor;
|
|
126
126
|
},
|
|
127
127
|
setSku(value) {
|
|
128
|
-
|
|
128
|
+
state = facade.setSku(state, value);
|
|
129
129
|
return editor;
|
|
130
130
|
},
|
|
131
131
|
setPaymentMethod(value) {
|
|
132
|
-
|
|
132
|
+
state = facade.setPaymentMethod(state, value);
|
|
133
133
|
return editor;
|
|
134
134
|
},
|
|
135
135
|
setCheckoutUrl(value) {
|
|
136
|
-
|
|
136
|
+
state = facade.setCheckoutUrl(state, value);
|
|
137
137
|
return editor;
|
|
138
138
|
},
|
|
139
139
|
setAcceptedOfferId(value) {
|
|
140
|
-
|
|
140
|
+
state = facade.setAcceptedOfferId(state, value);
|
|
141
141
|
return editor;
|
|
142
142
|
},
|
|
143
143
|
setPaymentUrl(value) {
|
|
144
|
-
|
|
144
|
+
state = facade.setPaymentUrl(state, value);
|
|
145
145
|
return editor;
|
|
146
146
|
},
|
|
147
147
|
setInvoiceId(value) {
|
|
148
|
-
|
|
148
|
+
state = facade.setInvoiceId(state, value);
|
|
149
149
|
return editor;
|
|
150
150
|
},
|
|
151
151
|
setActivationCode(value) {
|
|
152
|
-
|
|
152
|
+
state = facade.setActivationCode(state, value);
|
|
153
153
|
return editor;
|
|
154
154
|
},
|
|
155
155
|
setBaseClaims(claims) {
|
|
156
|
-
|
|
156
|
+
state = facade.setBaseClaims(state, claims);
|
|
157
157
|
return editor;
|
|
158
158
|
},
|
|
159
159
|
getOfferPreview() {
|
|
160
|
-
return cloneOffer(
|
|
160
|
+
return cloneOffer(state.offer);
|
|
161
161
|
},
|
|
162
162
|
getOrderSummary() {
|
|
163
|
-
return cloneOrder(
|
|
163
|
+
return cloneOrder(state.order);
|
|
164
164
|
},
|
|
165
165
|
buildOfferClaims() {
|
|
166
|
-
return facade.buildOfferClaims(
|
|
166
|
+
return facade.buildOfferClaims(state);
|
|
167
167
|
},
|
|
168
168
|
buildOrderClaims() {
|
|
169
|
-
return facade.buildOrderClaims(
|
|
169
|
+
return facade.buildOrderClaims(state);
|
|
170
170
|
},
|
|
171
171
|
readOfferPreviewFromResponseBody(body) {
|
|
172
172
|
const preview = facade.readOfferPreviewFromResponseBody(body);
|
|
173
|
-
|
|
173
|
+
state = patchState(state, { offer: preview });
|
|
174
174
|
return preview;
|
|
175
175
|
},
|
|
176
176
|
readOrderSummaryFromResponseBody(body) {
|
|
177
177
|
const summary = facade.readOrderSummaryFromResponseBody(body);
|
|
178
|
-
|
|
178
|
+
state = patchState(state, { order: summary });
|
|
179
179
|
return summary;
|
|
180
180
|
},
|
|
181
181
|
};
|
|
@@ -187,61 +187,61 @@ function createEditorFromFacade(facade, initial) {
|
|
|
187
187
|
*/
|
|
188
188
|
export function createLicenseOfferOrderFacade() {
|
|
189
189
|
const facade = {
|
|
190
|
-
|
|
190
|
+
createState(initial = {}) {
|
|
191
191
|
return {
|
|
192
192
|
offer: cloneOffer(initial.offer),
|
|
193
193
|
order: cloneOrder(initial.order),
|
|
194
194
|
baseClaims: cloneClaims(initial.baseClaims),
|
|
195
195
|
};
|
|
196
196
|
},
|
|
197
|
-
setOfferId(
|
|
198
|
-
setAmount(
|
|
199
|
-
setCurrency(
|
|
200
|
-
setSeats(
|
|
201
|
-
setPlanName(
|
|
202
|
-
setSku(
|
|
203
|
-
setPaymentMethod(
|
|
204
|
-
setCheckoutUrl(
|
|
205
|
-
setAcceptedOfferId(
|
|
206
|
-
setPaymentUrl(
|
|
207
|
-
setInvoiceId(
|
|
208
|
-
setActivationCode(
|
|
209
|
-
setBaseClaims(
|
|
210
|
-
buildOfferClaims(
|
|
197
|
+
setOfferId(state, value) { return patchState(state, { offer: { offerId: value } }); },
|
|
198
|
+
setAmount(state, value) { return patchState(state, { offer: { amount: value }, order: { amount: value } }); },
|
|
199
|
+
setCurrency(state, value) { return patchState(state, { offer: { currency: value }, order: { currency: value } }); },
|
|
200
|
+
setSeats(state, value) { return patchState(state, { offer: { seats: value }, order: { seats: value } }); },
|
|
201
|
+
setPlanName(state, value) { return patchState(state, { offer: { planName: value } }); },
|
|
202
|
+
setSku(state, value) { return patchState(state, { offer: { sku: value } }); },
|
|
203
|
+
setPaymentMethod(state, value) { return patchState(state, { offer: { paymentMethod: value }, order: { paymentMethod: value } }); },
|
|
204
|
+
setCheckoutUrl(state, value) { return patchState(state, { offer: { checkoutUrl: value } }); },
|
|
205
|
+
setAcceptedOfferId(state, value) { return patchState(state, { order: { acceptedOfferId: value } }); },
|
|
206
|
+
setPaymentUrl(state, value) { return patchState(state, { order: { paymentUrl: value } }); },
|
|
207
|
+
setInvoiceId(state, value) { return patchState(state, { order: { invoiceId: value } }); },
|
|
208
|
+
setActivationCode(state, value) { return patchState(state, { order: { activationCode: value } }); },
|
|
209
|
+
setBaseClaims(state, claims) { return patchState(state, { baseClaims: claims }); },
|
|
210
|
+
buildOfferClaims(state) {
|
|
211
211
|
const claims = {
|
|
212
212
|
'@context': LicenseClaimContext.SchemaOrg,
|
|
213
|
-
...cloneClaims(
|
|
213
|
+
...cloneClaims(state.baseClaims),
|
|
214
214
|
};
|
|
215
|
-
if (
|
|
216
|
-
claims[ClaimsOfferSchemaorg.identifier] =
|
|
217
|
-
if (
|
|
218
|
-
claims[ClaimsOfferSchemaorg.price] =
|
|
219
|
-
if (
|
|
220
|
-
claims[ClaimsOfferSchemaorg.priceCurrency] =
|
|
221
|
-
if (typeof
|
|
222
|
-
claims[ClaimsOfferSchemaorg.eligibleQuantityValue] =
|
|
223
|
-
if (
|
|
224
|
-
claims[ClaimsOfferSchemaorg.itemOfferedName] =
|
|
225
|
-
if (
|
|
226
|
-
claims[ClaimsOfferSchemaorg.itemOfferedSku] =
|
|
227
|
-
if (
|
|
228
|
-
claims[ClaimsOfferSchemaorg.acceptedPaymentMethod] =
|
|
229
|
-
if (
|
|
230
|
-
claims[ClaimsOfferSchemaorg.checkoutPageURLTemplate] =
|
|
215
|
+
if (state.offer.offerId)
|
|
216
|
+
claims[ClaimsOfferSchemaorg.identifier] = state.offer.offerId;
|
|
217
|
+
if (state.offer.amount)
|
|
218
|
+
claims[ClaimsOfferSchemaorg.price] = state.offer.amount;
|
|
219
|
+
if (state.offer.currency)
|
|
220
|
+
claims[ClaimsOfferSchemaorg.priceCurrency] = state.offer.currency;
|
|
221
|
+
if (typeof state.offer.seats === 'number')
|
|
222
|
+
claims[ClaimsOfferSchemaorg.eligibleQuantityValue] = state.offer.seats;
|
|
223
|
+
if (state.offer.planName)
|
|
224
|
+
claims[ClaimsOfferSchemaorg.itemOfferedName] = state.offer.planName;
|
|
225
|
+
if (state.offer.sku)
|
|
226
|
+
claims[ClaimsOfferSchemaorg.itemOfferedSku] = state.offer.sku;
|
|
227
|
+
if (state.offer.paymentMethod)
|
|
228
|
+
claims[ClaimsOfferSchemaorg.acceptedPaymentMethod] = state.offer.paymentMethod;
|
|
229
|
+
if (state.offer.checkoutUrl)
|
|
230
|
+
claims[ClaimsOfferSchemaorg.checkoutPageURLTemplate] = state.offer.checkoutUrl;
|
|
231
231
|
return claims;
|
|
232
232
|
},
|
|
233
|
-
buildOrderClaims(
|
|
234
|
-
const claims = facade.buildOfferClaims(
|
|
235
|
-
if (
|
|
236
|
-
claims[ClaimsOrderSchemaorg.acceptedOfferIdentifier] =
|
|
237
|
-
if (
|
|
238
|
-
claims[ClaimsOrderSchemaorg.paymentUrl] =
|
|
239
|
-
if (
|
|
240
|
-
claims[ClaimsOrderSchemaorg.partOfInvoice] =
|
|
241
|
-
if (
|
|
242
|
-
claims[ClaimsOrderSchemaorg.paymentMethod] =
|
|
243
|
-
if (
|
|
244
|
-
claims[ClaimsIndividualProductSchemaorg.serialNumber] =
|
|
233
|
+
buildOrderClaims(state) {
|
|
234
|
+
const claims = facade.buildOfferClaims(state);
|
|
235
|
+
if (state.order.acceptedOfferId)
|
|
236
|
+
claims[ClaimsOrderSchemaorg.acceptedOfferIdentifier] = state.order.acceptedOfferId;
|
|
237
|
+
if (state.order.paymentUrl)
|
|
238
|
+
claims[ClaimsOrderSchemaorg.paymentUrl] = state.order.paymentUrl;
|
|
239
|
+
if (state.order.invoiceId)
|
|
240
|
+
claims[ClaimsOrderSchemaorg.partOfInvoice] = state.order.invoiceId;
|
|
241
|
+
if (state.order.paymentMethod)
|
|
242
|
+
claims[ClaimsOrderSchemaorg.paymentMethod] = state.order.paymentMethod;
|
|
243
|
+
if (state.order.activationCode)
|
|
244
|
+
claims[ClaimsIndividualProductSchemaorg.serialNumber] = state.order.activationCode;
|
|
245
245
|
return claims;
|
|
246
246
|
},
|
|
247
247
|
readOfferPreviewFromResponseBody(body) { return readLicenseOfferPreviewFromResponseBody(body); },
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare const OrganizationLifecycleOperations: Readonly<{
|
|
2
|
+
readonly Enable: "enable";
|
|
3
|
+
readonly Disable: "disable";
|
|
4
|
+
readonly Purge: "purge";
|
|
5
|
+
}>;
|
|
6
|
+
export type OrganizationLifecycleOperation = typeof OrganizationLifecycleOperations[keyof typeof OrganizationLifecycleOperations];
|
|
7
|
+
export type OrganizationLifecycleClaims = Record<string, unknown>;
|
|
8
|
+
export type OrganizationLifecycleEditorState = Readonly<{
|
|
9
|
+
operation: OrganizationLifecycleOperation;
|
|
10
|
+
claims: OrganizationLifecycleClaims;
|
|
11
|
+
requestType?: string;
|
|
12
|
+
thid?: string;
|
|
13
|
+
}>;
|
|
14
|
+
export type OrganizationLifecycleDataEntry = Readonly<{
|
|
15
|
+
type: string;
|
|
16
|
+
request: {
|
|
17
|
+
method: 'POST';
|
|
18
|
+
};
|
|
19
|
+
meta: {
|
|
20
|
+
claims: OrganizationLifecycleClaims;
|
|
21
|
+
};
|
|
22
|
+
resource: {
|
|
23
|
+
resourceType: 'Organization';
|
|
24
|
+
meta: {
|
|
25
|
+
claims: OrganizationLifecycleClaims;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}>;
|
|
29
|
+
export type OrganizationLifecyclePayload = Readonly<{
|
|
30
|
+
thid: string;
|
|
31
|
+
body: {
|
|
32
|
+
data: OrganizationLifecycleDataEntry[];
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
35
|
+
export declare class OrganizationLifecycleEditor {
|
|
36
|
+
private draft;
|
|
37
|
+
constructor(initial?: Partial<OrganizationLifecycleEditorState>);
|
|
38
|
+
mergeClaims(claims: OrganizationLifecycleClaims): this;
|
|
39
|
+
setClaims(claims: OrganizationLifecycleClaims): this;
|
|
40
|
+
setContext(context: string): this;
|
|
41
|
+
setIdentifier(identifier: string): this;
|
|
42
|
+
setIdentifierValue(identifierValue: string): this;
|
|
43
|
+
setTaxId(taxId: string): this;
|
|
44
|
+
setOperation(operation: OrganizationLifecycleOperation): this;
|
|
45
|
+
setRequestType(requestType: string): this;
|
|
46
|
+
setThreadId(thid: string): this;
|
|
47
|
+
getContext(): string | undefined;
|
|
48
|
+
getIdentifier(): string | undefined;
|
|
49
|
+
getIdentifierValue(): string | undefined;
|
|
50
|
+
getTaxId(): string | undefined;
|
|
51
|
+
getOperation(): OrganizationLifecycleOperation;
|
|
52
|
+
getRequestType(): string | undefined;
|
|
53
|
+
getThreadId(): string | undefined;
|
|
54
|
+
getClaims(): OrganizationLifecycleClaims;
|
|
55
|
+
getState(): OrganizationLifecycleEditorState;
|
|
56
|
+
getEditorState(): OrganizationLifecycleEditorState;
|
|
57
|
+
buildCurrentGwDataEntry(): OrganizationLifecycleDataEntry;
|
|
58
|
+
buildCurrentGwPayload(): OrganizationLifecyclePayload;
|
|
59
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Copyright 2026 Antifraud Services Inc. under the Apache License, Version 2.0.
|
|
2
|
+
import { ClaimsOrganizationSchemaorg } from '../constants/schemaorg.js';
|
|
3
|
+
export const OrganizationLifecycleOperations = Object.freeze({
|
|
4
|
+
Enable: 'enable',
|
|
5
|
+
Disable: 'disable',
|
|
6
|
+
Purge: 'purge',
|
|
7
|
+
});
|
|
8
|
+
function cloneClaims(claims) {
|
|
9
|
+
return { ...(claims || {}) };
|
|
10
|
+
}
|
|
11
|
+
function normalizeText(value) {
|
|
12
|
+
const normalized = String(value ?? '').trim();
|
|
13
|
+
return normalized || undefined;
|
|
14
|
+
}
|
|
15
|
+
function normalizeDraft(draft) {
|
|
16
|
+
return {
|
|
17
|
+
operation: draft?.operation || OrganizationLifecycleOperations.Disable,
|
|
18
|
+
claims: {
|
|
19
|
+
'@context': 'org.schema',
|
|
20
|
+
...cloneClaims(draft?.claims),
|
|
21
|
+
},
|
|
22
|
+
requestType: normalizeText(draft?.requestType),
|
|
23
|
+
thid: normalizeText(draft?.thid),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function patchDraft(draft, patch) {
|
|
27
|
+
return normalizeDraft({
|
|
28
|
+
...draft,
|
|
29
|
+
...patch,
|
|
30
|
+
claims: patch.claims ? cloneClaims(patch.claims) : cloneClaims(draft.claims),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function createLifecycleThreadId(operation) {
|
|
34
|
+
return `organization-${operation}-example-001`;
|
|
35
|
+
}
|
|
36
|
+
export class OrganizationLifecycleEditor {
|
|
37
|
+
draft;
|
|
38
|
+
constructor(initial) {
|
|
39
|
+
this.draft = normalizeDraft(initial);
|
|
40
|
+
}
|
|
41
|
+
mergeClaims(claims) {
|
|
42
|
+
this.draft = patchDraft(this.draft, { claims: { ...this.draft.claims, ...cloneClaims(claims) } });
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
setClaims(claims) {
|
|
46
|
+
this.draft = patchDraft(this.draft, { claims });
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
setContext(context) {
|
|
50
|
+
this.draft = patchDraft(this.draft, {
|
|
51
|
+
claims: {
|
|
52
|
+
...this.draft.claims,
|
|
53
|
+
'@context': String(context).trim(),
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
setIdentifier(identifier) {
|
|
59
|
+
this.draft = patchDraft(this.draft, {
|
|
60
|
+
claims: {
|
|
61
|
+
...this.draft.claims,
|
|
62
|
+
[ClaimsOrganizationSchemaorg.identifier]: String(identifier).trim(),
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
setIdentifierValue(identifierValue) {
|
|
68
|
+
this.draft = patchDraft(this.draft, {
|
|
69
|
+
claims: {
|
|
70
|
+
...this.draft.claims,
|
|
71
|
+
[ClaimsOrganizationSchemaorg.identifierValue]: String(identifierValue).trim(),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
setTaxId(taxId) {
|
|
77
|
+
this.draft = patchDraft(this.draft, {
|
|
78
|
+
claims: {
|
|
79
|
+
...this.draft.claims,
|
|
80
|
+
[ClaimsOrganizationSchemaorg.taxId]: String(taxId).trim(),
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
setOperation(operation) {
|
|
86
|
+
this.draft = patchDraft(this.draft, { operation });
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
setRequestType(requestType) {
|
|
90
|
+
this.draft = patchDraft(this.draft, { requestType });
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
setThreadId(thid) {
|
|
94
|
+
this.draft = patchDraft(this.draft, { thid });
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
getContext() {
|
|
98
|
+
return normalizeText(this.draft.claims['@context']) || undefined;
|
|
99
|
+
}
|
|
100
|
+
getIdentifier() {
|
|
101
|
+
return normalizeText(this.draft.claims[ClaimsOrganizationSchemaorg.identifier]) || undefined;
|
|
102
|
+
}
|
|
103
|
+
getIdentifierValue() {
|
|
104
|
+
return normalizeText(this.draft.claims[ClaimsOrganizationSchemaorg.identifierValue]) || undefined;
|
|
105
|
+
}
|
|
106
|
+
getTaxId() {
|
|
107
|
+
return normalizeText(this.draft.claims[ClaimsOrganizationSchemaorg.taxId]) || undefined;
|
|
108
|
+
}
|
|
109
|
+
getOperation() {
|
|
110
|
+
return this.draft.operation;
|
|
111
|
+
}
|
|
112
|
+
getRequestType() {
|
|
113
|
+
return normalizeText(this.draft.requestType) || undefined;
|
|
114
|
+
}
|
|
115
|
+
getThreadId() {
|
|
116
|
+
return normalizeText(this.draft.thid) || undefined;
|
|
117
|
+
}
|
|
118
|
+
getClaims() {
|
|
119
|
+
return cloneClaims(this.draft.claims);
|
|
120
|
+
}
|
|
121
|
+
getState() {
|
|
122
|
+
return normalizeDraft(this.draft);
|
|
123
|
+
}
|
|
124
|
+
getEditorState() {
|
|
125
|
+
return this.getState();
|
|
126
|
+
}
|
|
127
|
+
buildCurrentGwDataEntry() {
|
|
128
|
+
const requestType = normalizeText(this.draft.requestType);
|
|
129
|
+
if (!requestType) {
|
|
130
|
+
throw new Error('OrganizationLifecycleEditor.buildCurrentGwDataEntry requires requestType.');
|
|
131
|
+
}
|
|
132
|
+
const claims = this.getClaims();
|
|
133
|
+
return {
|
|
134
|
+
type: requestType,
|
|
135
|
+
request: { method: 'POST' },
|
|
136
|
+
meta: { claims },
|
|
137
|
+
resource: {
|
|
138
|
+
resourceType: 'Organization',
|
|
139
|
+
meta: { claims },
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
buildCurrentGwPayload() {
|
|
144
|
+
const requestType = normalizeText(this.draft.requestType);
|
|
145
|
+
if (!requestType) {
|
|
146
|
+
throw new Error('OrganizationLifecycleEditor.buildCurrentGwPayload requires requestType.');
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
thid: this.draft.thid || createLifecycleThreadId(this.draft.operation),
|
|
150
|
+
body: {
|
|
151
|
+
data: [this.buildCurrentGwDataEntry()],
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the ICA-compatible multibase58(multihash(sha3-256)) payload for a
|
|
3
|
+
* public controller alias.
|
|
4
|
+
*
|
|
5
|
+
* Synchronization note:
|
|
6
|
+
* - this helper is intentionally copied from the current ICA-side algorithm in
|
|
7
|
+
* `dataspace-ica-ts/src/api/tools/multihash.ts`
|
|
8
|
+
* - do not change this hashing/normalization contract here without updating
|
|
9
|
+
* the ICA implementation in lockstep
|
|
10
|
+
*
|
|
11
|
+
* @param value Raw canonical string to hash.
|
|
12
|
+
*/
|
|
13
|
+
export declare function multibase58MultihashSha3_256(value: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Normalizes a public controller alias into the same representation used by
|
|
16
|
+
* ICA for `credentialSubject.sameAs` and `controller.sameAs`.
|
|
17
|
+
*
|
|
18
|
+
* Synchronization note:
|
|
19
|
+
* - this helper is a copied shared version of the current ICA algorithm from
|
|
20
|
+
* `dataspace-ica-ts/src/api/tools/multihash.ts`
|
|
21
|
+
* - it exists in `gdc-common-utils-ts` so BFF/backend callers can compute the
|
|
22
|
+
* exact same value before calling GW/ICA
|
|
23
|
+
* - do not let the two implementations drift
|
|
24
|
+
*
|
|
25
|
+
* Current rules:
|
|
26
|
+
* - `urn:multibase:z...` stays unchanged
|
|
27
|
+
* - bare `z...` becomes `urn:multibase:z...`
|
|
28
|
+
* - plain email becomes hashed `urn:multibase:z...`
|
|
29
|
+
* - any other identifier (for example `tel:+...`, `did:web:...`, custom URN)
|
|
30
|
+
* stays unchanged
|
|
31
|
+
*
|
|
32
|
+
* @param value Email, phone, DID, URN, or any other public alias string.
|
|
33
|
+
*/
|
|
34
|
+
export declare function normalizeSameAsHash(value: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Compares two public controller aliases after ICA-compatible normalization.
|
|
37
|
+
*
|
|
38
|
+
* @param left First alias.
|
|
39
|
+
* @param right Second alias.
|
|
40
|
+
*/
|
|
41
|
+
export declare function sameAsValuesEqual(left: string, right: string): boolean;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { encodeMultibase58btc } from './multibase58.js';
|
|
3
|
+
/**
|
|
4
|
+
* Builds the ICA-compatible multibase58(multihash(sha3-256)) payload for a
|
|
5
|
+
* public controller alias.
|
|
6
|
+
*
|
|
7
|
+
* Synchronization note:
|
|
8
|
+
* - this helper is intentionally copied from the current ICA-side algorithm in
|
|
9
|
+
* `dataspace-ica-ts/src/api/tools/multihash.ts`
|
|
10
|
+
* - do not change this hashing/normalization contract here without updating
|
|
11
|
+
* the ICA implementation in lockstep
|
|
12
|
+
*
|
|
13
|
+
* @param value Raw canonical string to hash.
|
|
14
|
+
*/
|
|
15
|
+
export function multibase58MultihashSha3_256(value) {
|
|
16
|
+
const normalized = value.trim();
|
|
17
|
+
if (!normalized) {
|
|
18
|
+
throw new Error('Cannot create multihash from empty value.');
|
|
19
|
+
}
|
|
20
|
+
const digest = createHash('sha3-256').update(normalized, 'utf8').digest();
|
|
21
|
+
const multihash = Buffer.concat([Buffer.from([0x16, 0x20]), digest]);
|
|
22
|
+
return encodeMultibase58btc(multihash);
|
|
23
|
+
}
|
|
24
|
+
function looksLikeBase58Multibase(value) {
|
|
25
|
+
return /^z\S+$/.test(value.trim());
|
|
26
|
+
}
|
|
27
|
+
function looksLikeEmail(value) {
|
|
28
|
+
const trimmed = value.trim();
|
|
29
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmed);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Normalizes a public controller alias into the same representation used by
|
|
33
|
+
* ICA for `credentialSubject.sameAs` and `controller.sameAs`.
|
|
34
|
+
*
|
|
35
|
+
* Synchronization note:
|
|
36
|
+
* - this helper is a copied shared version of the current ICA algorithm from
|
|
37
|
+
* `dataspace-ica-ts/src/api/tools/multihash.ts`
|
|
38
|
+
* - it exists in `gdc-common-utils-ts` so BFF/backend callers can compute the
|
|
39
|
+
* exact same value before calling GW/ICA
|
|
40
|
+
* - do not let the two implementations drift
|
|
41
|
+
*
|
|
42
|
+
* Current rules:
|
|
43
|
+
* - `urn:multibase:z...` stays unchanged
|
|
44
|
+
* - bare `z...` becomes `urn:multibase:z...`
|
|
45
|
+
* - plain email becomes hashed `urn:multibase:z...`
|
|
46
|
+
* - any other identifier (for example `tel:+...`, `did:web:...`, custom URN)
|
|
47
|
+
* stays unchanged
|
|
48
|
+
*
|
|
49
|
+
* @param value Email, phone, DID, URN, or any other public alias string.
|
|
50
|
+
*/
|
|
51
|
+
export function normalizeSameAsHash(value) {
|
|
52
|
+
const trimmed = value.trim();
|
|
53
|
+
if (!trimmed)
|
|
54
|
+
return '';
|
|
55
|
+
if (trimmed.toLowerCase().startsWith('urn:multibase:')) {
|
|
56
|
+
const suffix = trimmed.slice('urn:multibase:'.length).trim();
|
|
57
|
+
return looksLikeBase58Multibase(suffix) ? `urn:multibase:${suffix}` : trimmed;
|
|
58
|
+
}
|
|
59
|
+
if (looksLikeBase58Multibase(trimmed)) {
|
|
60
|
+
return `urn:multibase:${trimmed}`;
|
|
61
|
+
}
|
|
62
|
+
if (looksLikeEmail(trimmed)) {
|
|
63
|
+
return `urn:multibase:${multibase58MultihashSha3_256(trimmed.toLowerCase())}`;
|
|
64
|
+
}
|
|
65
|
+
return trimmed;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Compares two public controller aliases after ICA-compatible normalization.
|
|
69
|
+
*
|
|
70
|
+
* @param left First alias.
|
|
71
|
+
* @param right Second alias.
|
|
72
|
+
*/
|
|
73
|
+
export function sameAsValuesEqual(left, right) {
|
|
74
|
+
const normalizeComparable = (value) => {
|
|
75
|
+
const normalized = normalizeSameAsHash(value);
|
|
76
|
+
return normalized.toLowerCase().startsWith('urn:multibase:')
|
|
77
|
+
? normalized.slice('urn:multibase:'.length)
|
|
78
|
+
: normalized;
|
|
79
|
+
};
|
|
80
|
+
const normalizedLeft = normalizeComparable(left);
|
|
81
|
+
const normalizedRight = normalizeComparable(right);
|
|
82
|
+
return !!normalizedLeft && normalizedLeft === normalizedRight;
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdc-common-utils-ts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@stablelib/base64": "^1.0.1",
|
|
11
11
|
"@stablelib/utf8": "^1.0.2",
|
|
12
12
|
"base-x": "^4.0.0",
|
|
13
|
-
"gdc-common-utils-ts": "^
|
|
13
|
+
"gdc-common-utils-ts": "^2.0.1",
|
|
14
14
|
"pako": "^2.1.0"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|