gdc-common-utils-ts 1.24.3 → 2.0.2
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-verify-response.d.ts +225 -0
- package/dist/examples/ica-verify-response.js +257 -0
- package/dist/examples/index.d.ts +2 -0
- package/dist/examples/index.js +2 -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/interfaces/Cryptography.types.d.ts +15 -0
- package/dist/models/identity-bootstrap.d.ts +9 -0
- package/dist/utils/activation-policy.d.ts +22 -3
- package/dist/utils/activation-policy.js +22 -3
- package/dist/utils/activation-request.d.ts +43 -1
- package/dist/utils/activation-request.js +74 -0
- package/dist/utils/communication-search-editor.d.ts +3 -3
- package/dist/utils/communication-search-editor.js +1 -1
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +3 -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/package.json +2 -2
|
@@ -19,7 +19,7 @@ export type LicenseOrderSummary = Readonly<{
|
|
|
19
19
|
currency?: string;
|
|
20
20
|
seats?: number;
|
|
21
21
|
}>;
|
|
22
|
-
export type
|
|
22
|
+
export type LicenseOfferOrderState = Readonly<{
|
|
23
23
|
offer: LicenseOfferPreview;
|
|
24
24
|
order: LicenseOrderSummary;
|
|
25
25
|
baseClaims: LicenseClaims;
|
|
@@ -32,25 +32,25 @@ export type LicenseOfferOrderDraft = Readonly<{
|
|
|
32
32
|
* serialization without keeping mutable editor state.
|
|
33
33
|
*/
|
|
34
34
|
export interface LicenseOfferOrderFacade {
|
|
35
|
-
|
|
36
|
-
setOfferId(
|
|
37
|
-
setAmount(
|
|
38
|
-
setCurrency(
|
|
39
|
-
setSeats(
|
|
40
|
-
setPlanName(
|
|
41
|
-
setSku(
|
|
42
|
-
setPaymentMethod(
|
|
43
|
-
setCheckoutUrl(
|
|
44
|
-
setAcceptedOfferId(
|
|
45
|
-
setPaymentUrl(
|
|
46
|
-
setInvoiceId(
|
|
47
|
-
setActivationCode(
|
|
48
|
-
setBaseClaims(
|
|
49
|
-
buildOfferClaims(
|
|
50
|
-
buildOrderClaims(
|
|
35
|
+
createState(initial?: Partial<LicenseOfferOrderState>): LicenseOfferOrderState;
|
|
36
|
+
setOfferId(state: LicenseOfferOrderState, value: string): LicenseOfferOrderState;
|
|
37
|
+
setAmount(state: LicenseOfferOrderState, value: string): LicenseOfferOrderState;
|
|
38
|
+
setCurrency(state: LicenseOfferOrderState, value: string): LicenseOfferOrderState;
|
|
39
|
+
setSeats(state: LicenseOfferOrderState, value: number): LicenseOfferOrderState;
|
|
40
|
+
setPlanName(state: LicenseOfferOrderState, value: string): LicenseOfferOrderState;
|
|
41
|
+
setSku(state: LicenseOfferOrderState, value: string): LicenseOfferOrderState;
|
|
42
|
+
setPaymentMethod(state: LicenseOfferOrderState, value: string): LicenseOfferOrderState;
|
|
43
|
+
setCheckoutUrl(state: LicenseOfferOrderState, value: string): LicenseOfferOrderState;
|
|
44
|
+
setAcceptedOfferId(state: LicenseOfferOrderState, value: string): LicenseOfferOrderState;
|
|
45
|
+
setPaymentUrl(state: LicenseOfferOrderState, value: string): LicenseOfferOrderState;
|
|
46
|
+
setInvoiceId(state: LicenseOfferOrderState, value: string): LicenseOfferOrderState;
|
|
47
|
+
setActivationCode(state: LicenseOfferOrderState, value: string): LicenseOfferOrderState;
|
|
48
|
+
setBaseClaims(state: LicenseOfferOrderState, claims: LicenseClaims): LicenseOfferOrderState;
|
|
49
|
+
buildOfferClaims(state: LicenseOfferOrderState): LicenseClaims;
|
|
50
|
+
buildOrderClaims(state: LicenseOfferOrderState): LicenseClaims;
|
|
51
51
|
readOfferPreviewFromResponseBody(body: unknown): LicenseOfferPreview;
|
|
52
52
|
readOrderSummaryFromResponseBody(body: unknown): LicenseOrderSummary;
|
|
53
|
-
createEditor(initial?: Partial<
|
|
53
|
+
createEditor(initial?: Partial<LicenseOfferOrderState>): LicenseOfferOrderEditor;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* Chainable editor mirroring the didactic `get/set/build/read` style used by
|
|
@@ -104,4 +104,4 @@ export declare function createLicenseOfferOrderFacade(): LicenseOfferOrderFacade
|
|
|
104
104
|
/**
|
|
105
105
|
* Creates the chainable editor shown in the 101 tests.
|
|
106
106
|
*/
|
|
107
|
-
export declare function createLicenseOfferOrderEditor(initial?: Partial<
|
|
107
|
+
export declare function createLicenseOfferOrderEditor(initial?: Partial<LicenseOfferOrderState>): LicenseOfferOrderEditor;
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdc-common-utils-ts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
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": {
|