gdc-common-utils-ts 2.5.20 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/http.d.ts +2 -0
- package/dist/constants/http.js +2 -0
- package/dist/models/bundle-editor-types.d.ts +3 -0
- package/dist/models/bundle.d.ts +3 -1
- package/dist/utils/bundle-editor-core.js +13 -7
- package/dist/utils/bundle-editor-helpers.d.ts +12 -0
- package/dist/utils/bundle-editor-helpers.js +29 -0
- package/dist/utils/bundle-entry-editor.d.ts +18 -0
- package/dist/utils/bundle-entry-editor.js +71 -1
- package/dist/utils/organization-test-network-credential.d.ts +2 -1
- package/dist/utils/organization-test-network-credential.js +2 -1
- package/dist/utils/test-network-organization-credentials.d.ts +4 -1
- package/dist/utils/test-network-organization-credentials.js +6 -7
- package/package.json +1 -1
package/dist/constants/http.d.ts
CHANGED
|
@@ -15,7 +15,9 @@ export declare const HttpStatusCodes: Readonly<{
|
|
|
15
15
|
export declare const HttpRequestMethods: Readonly<{
|
|
16
16
|
readonly Get: "GET";
|
|
17
17
|
readonly Post: "POST";
|
|
18
|
+
readonly Put: "PUT";
|
|
18
19
|
readonly Patch: "PATCH";
|
|
20
|
+
readonly Delete: "DELETE";
|
|
19
21
|
}>;
|
|
20
22
|
/** Canonical HTTP header names. */
|
|
21
23
|
export declare const HttpHeaderNames: Readonly<{
|
package/dist/constants/http.js
CHANGED
|
@@ -15,7 +15,9 @@ export const HttpStatusCodes = Object.freeze({
|
|
|
15
15
|
export const HttpRequestMethods = Object.freeze({
|
|
16
16
|
Get: 'GET',
|
|
17
17
|
Post: 'POST',
|
|
18
|
+
Put: 'PUT',
|
|
18
19
|
Patch: 'PATCH',
|
|
20
|
+
Delete: 'DELETE',
|
|
19
21
|
});
|
|
20
22
|
/** Canonical HTTP header names. */
|
|
21
23
|
export const HttpHeaderNames = Object.freeze({
|
|
@@ -57,6 +57,7 @@ export type BuiltBundleEntry = {
|
|
|
57
57
|
request: {
|
|
58
58
|
method: BundleRequest['method'];
|
|
59
59
|
url?: string;
|
|
60
|
+
ifMatch?: string;
|
|
60
61
|
};
|
|
61
62
|
resource: {
|
|
62
63
|
resourceType: string;
|
|
@@ -67,6 +68,8 @@ export type BuiltBundleEntry = {
|
|
|
67
68
|
[key: string]: unknown;
|
|
68
69
|
};
|
|
69
70
|
fullUrl?: string;
|
|
71
|
+
/** @internal Materialization hint for request-only FHIR operations. */
|
|
72
|
+
omitResource?: boolean;
|
|
70
73
|
};
|
|
71
74
|
export declare const BundleTypes: Readonly<{
|
|
72
75
|
readonly batch: "batch";
|
package/dist/models/bundle.d.ts
CHANGED
|
@@ -40,8 +40,10 @@ import { OperationOutcome } from "./operation-outcome";
|
|
|
40
40
|
* - `BundleEntry.type` remains a separate internal business/message label
|
|
41
41
|
*/
|
|
42
42
|
export interface BundleRequest {
|
|
43
|
-
method: 'POST' | 'PUT' | 'DELETE' | 'GET';
|
|
43
|
+
method: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'GET';
|
|
44
44
|
url: string;
|
|
45
|
+
/** Weak or strong ETag used for optimistic update/delete contention. */
|
|
46
|
+
ifMatch?: string;
|
|
45
47
|
}
|
|
46
48
|
/**
|
|
47
49
|
* Defines the `response` property for an entry in a response Bundle.
|
|
@@ -14,7 +14,7 @@ import { getClaimValues, setClaimValues } from '../claims/claim-list-helpers.js'
|
|
|
14
14
|
import { buildBundleDocumentFromClaims } from './bundle-document-builder.js';
|
|
15
15
|
import { buildEmployeeBatchEntry, buildEmployeePurgeBundle, buildEmployeeSearchBundle, EmployeeBundleOperations, EmployeeResourceTypes, } from './employee.js';
|
|
16
16
|
import { BundleEntryEditor } from './bundle-entry-editor.js';
|
|
17
|
-
import { cloneEntry, createCanonicalIdentifierUrn, inferGenericEntryType, normalizeOptionalIdentifier, resolveEntryTypeForOperation, resolveRequestMethodForOperation, } from './bundle-editor-helpers.js';
|
|
17
|
+
import { cloneEntry, createCanonicalIdentifierUrn, inferGenericEntryType, normalizeOptionalIdentifier, materializeBundleEntry, resolveEntryTypeForOperation, resolveRequestMethodForOperation, } from './bundle-editor-helpers.js';
|
|
18
18
|
export class BundleEditor {
|
|
19
19
|
bundleOperation = null;
|
|
20
20
|
allowedResourceType = null;
|
|
@@ -92,7 +92,7 @@ export class BundleEditor {
|
|
|
92
92
|
if (!Object.values(BundleTypes).includes(bundle.type)) {
|
|
93
93
|
throw new TypeError(`BundleEditor.setBundle does not support Bundle.type: ${String(bundle.type || '')}`);
|
|
94
94
|
}
|
|
95
|
-
const operation = this.
|
|
95
|
+
const operation = this.bundleOperation || EmployeeBundleOperations.create;
|
|
96
96
|
const nextEntries = bundle.data.map((source, index) => {
|
|
97
97
|
const resource = source?.resource;
|
|
98
98
|
const resourceType = normalizeOptionalIdentifier(resource?.resourceType);
|
|
@@ -180,7 +180,11 @@ export class BundleEditor {
|
|
|
180
180
|
}
|
|
181
181
|
/** Opens one new entry with an explicit resource type, mainly for document bundles. */
|
|
182
182
|
newEntryAs(resourceType, resourceId) {
|
|
183
|
-
|
|
183
|
+
const operation = this.bundleOperation || EmployeeBundleOperations.create;
|
|
184
|
+
const resolvedResourceType = this.resolveEntryResourceType(resourceType);
|
|
185
|
+
const entry = this.createEntryDraft(operation, resolvedResourceType, resourceId);
|
|
186
|
+
this.entries.push(entry);
|
|
187
|
+
return new BundleEntryEditor(this, this.entries.length - 1).asResourceType(resourceType);
|
|
184
188
|
}
|
|
185
189
|
/** Reopens one existing entry by `resource.id` or `fullUrl`. */
|
|
186
190
|
openEntry(resourceIdOrFullUrl) {
|
|
@@ -260,9 +264,9 @@ export class BundleEditor {
|
|
|
260
264
|
if (this.bundleType === BundleTypes.document) {
|
|
261
265
|
return this.buildDocument();
|
|
262
266
|
}
|
|
263
|
-
const operation = this.
|
|
264
|
-
const resourceType = this.requireAllowedResourceType();
|
|
267
|
+
const operation = this.bundleOperation;
|
|
265
268
|
if (operation === EmployeeBundleOperations.search) {
|
|
269
|
+
const resourceType = this.requireAllowedResourceType();
|
|
266
270
|
if (resourceType !== EmployeeResourceTypes.employee) {
|
|
267
271
|
throw new Error(`BundleEditor search currently supports only resource type: ${EmployeeResourceTypes.employee}`);
|
|
268
272
|
}
|
|
@@ -272,6 +276,7 @@ export class BundleEditor {
|
|
|
272
276
|
});
|
|
273
277
|
}
|
|
274
278
|
if (operation === EmployeeBundleOperations.purge) {
|
|
279
|
+
const resourceType = this.requireAllowedResourceType();
|
|
275
280
|
if (resourceType !== EmployeeResourceTypes.employee) {
|
|
276
281
|
throw new Error(`BundleEditor purge currently supports only resource type: ${EmployeeResourceTypes.employee}`);
|
|
277
282
|
}
|
|
@@ -295,7 +300,7 @@ export class BundleEditor {
|
|
|
295
300
|
return {
|
|
296
301
|
resourceType: ResourceTypesFhirR4.Bundle,
|
|
297
302
|
type: this.bundleType,
|
|
298
|
-
entry: this.entries.map((entry) =>
|
|
303
|
+
entry: this.entries.map((entry) => materializeBundleEntry(entry)),
|
|
299
304
|
};
|
|
300
305
|
}
|
|
301
306
|
/**
|
|
@@ -310,12 +315,13 @@ export class BundleEditor {
|
|
|
310
315
|
resourceType: ResourceTypesFhirR4.Bundle,
|
|
311
316
|
type: this.bundleType,
|
|
312
317
|
data: this.entries.map((entry) => {
|
|
313
|
-
const clonedEntry =
|
|
318
|
+
const clonedEntry = materializeBundleEntry(entry);
|
|
314
319
|
const { request: _requestIgnored, ...clonedEntryWithoutRequest } = clonedEntry;
|
|
315
320
|
const normalizedRequest = clonedEntry.request
|
|
316
321
|
? {
|
|
317
322
|
method: clonedEntry.request.method,
|
|
318
323
|
url: clonedEntry.request.url || '',
|
|
324
|
+
...(clonedEntry.request.ifMatch ? { ifMatch: clonedEntry.request.ifMatch } : {}),
|
|
319
325
|
}
|
|
320
326
|
: undefined;
|
|
321
327
|
return normalizedRequest
|
|
@@ -11,6 +11,18 @@ export declare function cloneClaimValue<T>(value: T): T;
|
|
|
11
11
|
* every editor follows the same blank-value rule.
|
|
12
12
|
*/
|
|
13
13
|
export declare function normalizeOptionalIdentifier(value: unknown): string | undefined;
|
|
14
|
+
/** Builds the canonical relative FHIR request URL for one technical resource id. */
|
|
15
|
+
export declare function buildFhirResourceRequestUrl(resourceType: string, resourceId: string): string;
|
|
16
|
+
/** Converts one content version id into the weak ETag shape used by FHIR ifMatch. */
|
|
17
|
+
export declare function buildFhirIfMatch(versionId: string): string;
|
|
18
|
+
/** Clones a staged entry and removes the resource body required to be absent for DELETE. */
|
|
19
|
+
export declare function materializeBundleEntry<T extends {
|
|
20
|
+
request?: {
|
|
21
|
+
method: BundleRequest['method'];
|
|
22
|
+
};
|
|
23
|
+
resource?: unknown;
|
|
24
|
+
omitResource?: boolean;
|
|
25
|
+
}>(entry: T): T;
|
|
14
26
|
/** Returns one canonical `urn:uuid:*` identifier for new entry/resource drafts. */
|
|
15
27
|
export declare function createCanonicalIdentifierUrn(): string;
|
|
16
28
|
/**
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* in the editor classes.
|
|
7
7
|
*/
|
|
8
8
|
import { ResourceTypesFhirR4 } from '../constants/fhir-resource-types.js';
|
|
9
|
+
import { HttpRequestMethods } from '../constants/http.js';
|
|
9
10
|
import { AllergyIntoleranceClaim, } from '../models/interoperable-claims/allergy-intolerance-claims.js';
|
|
10
11
|
import { ConditionClaim } from '../models/interoperable-claims/condition-claims.js';
|
|
11
12
|
import { DiagnosticReportClaim } from '../models/interoperable-claims/diagnostic-report-claims.js';
|
|
@@ -37,6 +38,34 @@ export function normalizeOptionalIdentifier(value) {
|
|
|
37
38
|
const normalized = String(value).trim();
|
|
38
39
|
return normalized ? normalized : undefined;
|
|
39
40
|
}
|
|
41
|
+
/** Builds the canonical relative FHIR request URL for one technical resource id. */
|
|
42
|
+
export function buildFhirResourceRequestUrl(resourceType, resourceId) {
|
|
43
|
+
const normalizedType = normalizeOptionalIdentifier(resourceType);
|
|
44
|
+
const normalizedId = normalizeOptionalIdentifier(resourceId);
|
|
45
|
+
if (!normalizedType || !normalizedId) {
|
|
46
|
+
throw new Error('FHIR resource request URL requires resource type and technical resource id.');
|
|
47
|
+
}
|
|
48
|
+
const prefix = `${normalizedType}/`;
|
|
49
|
+
return normalizedId.startsWith(prefix) ? normalizedId : `${prefix}${normalizedId}`;
|
|
50
|
+
}
|
|
51
|
+
/** Converts one content version id into the weak ETag shape used by FHIR ifMatch. */
|
|
52
|
+
export function buildFhirIfMatch(versionId) {
|
|
53
|
+
const normalized = normalizeOptionalIdentifier(versionId);
|
|
54
|
+
if (!normalized)
|
|
55
|
+
throw new Error('ifMatch requires a non-empty version id.');
|
|
56
|
+
if (/^(W\/)?"[^"]+"$/.test(normalized))
|
|
57
|
+
return normalized;
|
|
58
|
+
return `W/"${normalized}"`;
|
|
59
|
+
}
|
|
60
|
+
/** Clones a staged entry and removes the resource body required to be absent for DELETE. */
|
|
61
|
+
export function materializeBundleEntry(entry) {
|
|
62
|
+
const materialized = cloneEntry(entry);
|
|
63
|
+
if (materialized.request?.method === HttpRequestMethods.Delete && materialized.omitResource) {
|
|
64
|
+
delete materialized.resource;
|
|
65
|
+
}
|
|
66
|
+
delete materialized.omitResource;
|
|
67
|
+
return materialized;
|
|
68
|
+
}
|
|
40
69
|
/** Returns one canonical `urn:uuid:*` identifier for new entry/resource drafts. */
|
|
41
70
|
export function createCanonicalIdentifierUrn() {
|
|
42
71
|
const cryptoLike = globalThis;
|
|
@@ -24,6 +24,22 @@ export declare class BundleEntryEditor {
|
|
|
24
24
|
protected readonly bundleEditor: BundleEditor;
|
|
25
25
|
protected readonly entryIndex: number;
|
|
26
26
|
constructor(bundleEditor: BundleEditor, entryIndex: number);
|
|
27
|
+
/** Stages a FHIR create request for only this batch entry. */
|
|
28
|
+
create(): this;
|
|
29
|
+
/** Stages a FHIR update request for only this batch entry. */
|
|
30
|
+
update(): this;
|
|
31
|
+
/**
|
|
32
|
+
* Stages a FHIR delete request for only this batch entry.
|
|
33
|
+
*
|
|
34
|
+
* The mutable editor keeps the resource shell so typed methods can still
|
|
35
|
+
* inspect identity. Materialization removes that shell because DELETE has no
|
|
36
|
+
* request body.
|
|
37
|
+
*/
|
|
38
|
+
delete(): this;
|
|
39
|
+
/** Adds optimistic version matching to this update or delete entry. */
|
|
40
|
+
ifMatch(versionId: string): this;
|
|
41
|
+
/** Reads the staged optimistic version ETag. */
|
|
42
|
+
getIfMatch(): string | undefined;
|
|
27
43
|
/**
|
|
28
44
|
* Reopens the current slot as one typed resource editor.
|
|
29
45
|
*
|
|
@@ -102,6 +118,8 @@ export declare class BundleEntryEditor {
|
|
|
102
118
|
getFullUrl(): string | undefined;
|
|
103
119
|
/** Returns control to the parent bundle editor. */
|
|
104
120
|
doneEntry(): BundleEditor;
|
|
121
|
+
private requireResourceType;
|
|
122
|
+
private requireTechnicalResourceId;
|
|
105
123
|
/** Returns the mutable staged entry owned by this editor wrapper. */
|
|
106
124
|
protected getMutableEntry(): BuiltBundleEntry;
|
|
107
125
|
/** Returns a cloned claims view for safe read-modify-write helper code. */
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* - Resource-specific semantics must live in the dedicated typed entry editors.
|
|
6
6
|
*/
|
|
7
7
|
import { ResourceTypesFhirR4 } from '../constants/fhir-resource-types.js';
|
|
8
|
+
import { HttpRequestMethods } from '../constants/http.js';
|
|
8
9
|
import { BundleEditableResourceTypes, } from '../models/bundle-editor-types.js';
|
|
9
10
|
import { normalizeFhirApiClaimKey } from './fhir-api-claim-helpers.js';
|
|
10
11
|
import { EmployeeResourceTypes, } from './employee.js';
|
|
11
|
-
import { cloneClaimValue, normalizeOptionalIdentifier } from './bundle-editor-helpers.js';
|
|
12
|
+
import { buildFhirIfMatch, buildFhirResourceRequestUrl, cloneClaimValue, normalizeOptionalIdentifier, } from './bundle-editor-helpers.js';
|
|
12
13
|
import { createRegisteredBundleEntryEditor } from './bundle-editor-registry.js';
|
|
13
14
|
export class BundleEntryEditor {
|
|
14
15
|
bundleEditor;
|
|
@@ -17,6 +18,61 @@ export class BundleEntryEditor {
|
|
|
17
18
|
this.bundleEditor = bundleEditor;
|
|
18
19
|
this.entryIndex = entryIndex;
|
|
19
20
|
}
|
|
21
|
+
/** Stages a FHIR create request for only this batch entry. */
|
|
22
|
+
create() {
|
|
23
|
+
const entry = this.getMutableEntry();
|
|
24
|
+
const resourceType = this.requireResourceType('create');
|
|
25
|
+
entry.request = { method: HttpRequestMethods.Post, url: resourceType };
|
|
26
|
+
entry.omitResource = false;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
/** Stages a FHIR update request for only this batch entry. */
|
|
30
|
+
update() {
|
|
31
|
+
const entry = this.getMutableEntry();
|
|
32
|
+
const resourceType = this.requireResourceType('update');
|
|
33
|
+
const resourceId = this.requireTechnicalResourceId('update');
|
|
34
|
+
entry.request = {
|
|
35
|
+
method: HttpRequestMethods.Put,
|
|
36
|
+
url: buildFhirResourceRequestUrl(resourceType, resourceId),
|
|
37
|
+
};
|
|
38
|
+
entry.omitResource = false;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Stages a FHIR delete request for only this batch entry.
|
|
43
|
+
*
|
|
44
|
+
* The mutable editor keeps the resource shell so typed methods can still
|
|
45
|
+
* inspect identity. Materialization removes that shell because DELETE has no
|
|
46
|
+
* request body.
|
|
47
|
+
*/
|
|
48
|
+
delete() {
|
|
49
|
+
const entry = this.getMutableEntry();
|
|
50
|
+
const resourceType = this.requireResourceType('delete');
|
|
51
|
+
const resourceId = this.requireTechnicalResourceId('delete');
|
|
52
|
+
entry.request = {
|
|
53
|
+
method: HttpRequestMethods.Delete,
|
|
54
|
+
url: buildFhirResourceRequestUrl(resourceType, resourceId),
|
|
55
|
+
};
|
|
56
|
+
entry.omitResource = true;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
/** Adds optimistic version matching to this update or delete entry. */
|
|
60
|
+
ifMatch(versionId) {
|
|
61
|
+
const entry = this.getMutableEntry();
|
|
62
|
+
if (entry.request?.method !== HttpRequestMethods.Put
|
|
63
|
+
&& entry.request?.method !== HttpRequestMethods.Delete) {
|
|
64
|
+
throw new Error('ifMatch is supported only for update or delete entries.');
|
|
65
|
+
}
|
|
66
|
+
entry.request = {
|
|
67
|
+
...entry.request,
|
|
68
|
+
ifMatch: buildFhirIfMatch(versionId),
|
|
69
|
+
};
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
/** Reads the staged optimistic version ETag. */
|
|
73
|
+
getIfMatch() {
|
|
74
|
+
return normalizeOptionalIdentifier(this.getMutableEntry().request?.ifMatch);
|
|
75
|
+
}
|
|
20
76
|
/**
|
|
21
77
|
* Reopens the current slot as one typed resource editor.
|
|
22
78
|
*
|
|
@@ -324,6 +380,20 @@ export class BundleEntryEditor {
|
|
|
324
380
|
doneEntry() {
|
|
325
381
|
return this.bundleEditor;
|
|
326
382
|
}
|
|
383
|
+
requireResourceType(operation) {
|
|
384
|
+
const resourceType = normalizeOptionalIdentifier(this.getMutableEntry().resource?.resourceType);
|
|
385
|
+
if (!resourceType)
|
|
386
|
+
throw new Error(`${operation} requires a resource type.`);
|
|
387
|
+
return resourceType;
|
|
388
|
+
}
|
|
389
|
+
requireTechnicalResourceId(operation) {
|
|
390
|
+
const entry = this.getMutableEntry();
|
|
391
|
+
const resourceId = normalizeOptionalIdentifier(entry.resource?.id)
|
|
392
|
+
|| normalizeOptionalIdentifier(entry.fullUrl);
|
|
393
|
+
if (!resourceId)
|
|
394
|
+
throw new Error(`${operation} requires a technical resource id.`);
|
|
395
|
+
return resourceId;
|
|
396
|
+
}
|
|
327
397
|
/** Returns the mutable staged entry owned by this editor wrapper. */
|
|
328
398
|
getMutableEntry() {
|
|
329
399
|
return this.bundleEditor.getMutableEntry(this.entryIndex);
|
|
@@ -51,7 +51,6 @@ export type OrganizationTestNetworkCredentialInput = Readonly<{
|
|
|
51
51
|
controllerKeyMaterial: string;
|
|
52
52
|
applicationId: string;
|
|
53
53
|
accessPath: 'partner' | 'test-network';
|
|
54
|
-
targetNetwork: 'test-network' | 'network';
|
|
55
54
|
/**
|
|
56
55
|
* @deprecated Postal-address verification is a separate production-readiness
|
|
57
56
|
* flow. This compatibility input is ignored and is never embedded in a Test
|
|
@@ -64,6 +63,8 @@ export type OrganizationTestNetworkCredentialInput = Readonly<{
|
|
|
64
63
|
* Builds the immutable VC that a controller receives out-of-band and attaches
|
|
65
64
|
* to `Organization/_transaction`. Postal-address verification is deliberately
|
|
66
65
|
* outside this credential and may be completed independently before production.
|
|
66
|
+
* Test Network scope is expressed by `OrganizationTestNetworkCredential` in
|
|
67
|
+
* the signed `type[]`, not by a non-schema.org credential-subject property.
|
|
67
68
|
*/
|
|
68
69
|
export declare function buildOrganizationTestNetworkCredential(input: OrganizationTestNetworkCredentialInput): VerifiableCredentialV2;
|
|
69
70
|
/**
|
|
@@ -19,6 +19,8 @@ function required(value, name) {
|
|
|
19
19
|
* Builds the immutable VC that a controller receives out-of-band and attaches
|
|
20
20
|
* to `Organization/_transaction`. Postal-address verification is deliberately
|
|
21
21
|
* outside this credential and may be completed independently before production.
|
|
22
|
+
* Test Network scope is expressed by `OrganizationTestNetworkCredential` in
|
|
23
|
+
* the signed `type[]`, not by a non-schema.org credential-subject property.
|
|
22
24
|
*/
|
|
23
25
|
export function buildOrganizationTestNetworkCredential(input) {
|
|
24
26
|
const applicationId = required(input.applicationId, 'applicationId');
|
|
@@ -36,7 +38,6 @@ export function buildOrganizationTestNetworkCredential(input) {
|
|
|
36
38
|
id: required(input.subjectDid, 'subjectDid'),
|
|
37
39
|
applicationId,
|
|
38
40
|
accessPath: input.accessPath,
|
|
39
|
-
targetNetwork: input.targetNetwork,
|
|
40
41
|
organization: {
|
|
41
42
|
legalName: required(input.legalName, 'legalName'),
|
|
42
43
|
identifier: organizationIdentifier,
|
|
@@ -31,5 +31,8 @@ export type BuildTestNetworkOrganizationCredentialSetInput = Readonly<{
|
|
|
31
31
|
* must still be added to every returned credential.
|
|
32
32
|
*/
|
|
33
33
|
export declare function buildTestNetworkOrganizationCredentialSet(input: BuildTestNetworkOrganizationCredentialSetInput): TestNetworkOrganizationCredentialSet;
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Deterministic detached-proof payload for one of the three Test Network VCs.
|
|
36
|
+
* The signed `TestNetworkCredential` type is the sole environment marker.
|
|
37
|
+
*/
|
|
35
38
|
export declare function canonicalizeTestNetworkOrganizationCredential(credential: VerifiableCredentialV2): string;
|
|
@@ -37,7 +37,6 @@ export function buildTestNetworkOrganizationCredentialSet(input) {
|
|
|
37
37
|
id: `urn:sha256:${required(input.pdfSha256, 'pdfSha256')}`,
|
|
38
38
|
documentVersion: required(input.documentVersion, 'documentVersion'),
|
|
39
39
|
applicationId,
|
|
40
|
-
targetNetwork: 'test-network',
|
|
41
40
|
}];
|
|
42
41
|
const base = {
|
|
43
42
|
'@context': [W3cCredentialContexts.V2, 'https://schema.org'],
|
|
@@ -62,7 +61,6 @@ export function buildTestNetworkOrganizationCredentialSet(input) {
|
|
|
62
61
|
...(identifierType === 'taxID' ? { taxID: organizationIdentifier } : {}),
|
|
63
62
|
address: { '@type': 'PostalAddress', addressCountry },
|
|
64
63
|
makesOffer: { '@type': 'Offer', category: serviceCategory },
|
|
65
|
-
targetNetwork: 'test-network',
|
|
66
64
|
},
|
|
67
65
|
};
|
|
68
66
|
const representative = {
|
|
@@ -87,7 +85,6 @@ export function buildTestNetworkOrganizationCredentialSet(input) {
|
|
|
87
85
|
? { taxID: organizationIdentifier }
|
|
88
86
|
: { identifier: { additionalType: identifierType, value: organizationIdentifier } }),
|
|
89
87
|
},
|
|
90
|
-
targetNetwork: 'test-network',
|
|
91
88
|
},
|
|
92
89
|
};
|
|
93
90
|
const controller = {
|
|
@@ -117,7 +114,6 @@ export function buildTestNetworkOrganizationCredentialSet(input) {
|
|
|
117
114
|
hasOccupation: { '@type': 'Occupation', occupationalCategory: 'ISCO-08|1330' },
|
|
118
115
|
hasCredential: { material: required(input.controllerKeyMaterial, 'controllerKeyMaterial') },
|
|
119
116
|
},
|
|
120
|
-
targetNetwork: 'test-network',
|
|
121
117
|
},
|
|
122
118
|
};
|
|
123
119
|
return [organization, representative, controller];
|
|
@@ -132,13 +128,16 @@ function canonicalizeValue(value) {
|
|
|
132
128
|
.sort(([left], [right]) => left.localeCompare(right))
|
|
133
129
|
.map(([key, nested]) => [key, canonicalizeValue(nested)]));
|
|
134
130
|
}
|
|
135
|
-
/**
|
|
131
|
+
/**
|
|
132
|
+
* Deterministic detached-proof payload for one of the three Test Network VCs.
|
|
133
|
+
* The signed `TestNetworkCredential` type is the sole environment marker.
|
|
134
|
+
*/
|
|
136
135
|
export function canonicalizeTestNetworkOrganizationCredential(credential) {
|
|
137
136
|
if (!TestNetworkOrganizationCredentialTypes.some(type => credential.type.includes(type))) {
|
|
138
137
|
throw new Error('Credential is not a Test Network organization credential.');
|
|
139
138
|
}
|
|
140
|
-
if (credential.
|
|
141
|
-
throw new Error('Test Network organization credential requires
|
|
139
|
+
if (!credential.type.includes(EnvironmentCredentialTypes.TestNetworkCredential)) {
|
|
140
|
+
throw new Error('Test Network organization credential requires TestNetworkCredential in type[].');
|
|
142
141
|
}
|
|
143
142
|
return JSON.stringify(canonicalizeValue(credential));
|
|
144
143
|
}
|