gdc-common-utils-ts 2.5.9 → 2.5.10
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/utils/did.d.ts +4 -1
- package/dist/utils/did.js +28 -11
- package/dist/utils/license-list-search.js +33 -4
- package/package.json +1 -1
package/dist/utils/did.d.ts
CHANGED
|
@@ -36,7 +36,10 @@ export declare function generateServiceId(selector: ServiceEndpointSelector): st
|
|
|
36
36
|
* due to case sensitivity in the path component of the underlying URL.
|
|
37
37
|
*
|
|
38
38
|
* The rule is:
|
|
39
|
-
* -
|
|
39
|
+
* - The DNS authority and ordinary non-final path segments are lowercased.
|
|
40
|
+
* - A hosted VAT tenant segment is uppercased (`vates-b...` -> `VATES-B...`).
|
|
41
|
+
* - A `cds-<jurisdiction>` segment uses an uppercase ISO jurisdiction.
|
|
42
|
+
* - The final segment is preserved.
|
|
40
43
|
* - If the final segment represents a `system|code` pair (e.g., for a role),
|
|
41
44
|
* the `system` part is lowercased, but the `code` is preserved as-is.
|
|
42
45
|
* - If the final segment is a unique identifier (like a Tax ID), it is preserved as-is.
|
package/dist/utils/did.js
CHANGED
|
@@ -56,7 +56,10 @@ export function generateServiceId(selector) {
|
|
|
56
56
|
* due to case sensitivity in the path component of the underlying URL.
|
|
57
57
|
*
|
|
58
58
|
* The rule is:
|
|
59
|
-
* -
|
|
59
|
+
* - The DNS authority and ordinary non-final path segments are lowercased.
|
|
60
|
+
* - A hosted VAT tenant segment is uppercased (`vates-b...` -> `VATES-B...`).
|
|
61
|
+
* - A `cds-<jurisdiction>` segment uses an uppercase ISO jurisdiction.
|
|
62
|
+
* - The final segment is preserved.
|
|
60
63
|
* - If the final segment represents a `system|code` pair (e.g., for a role),
|
|
61
64
|
* the `system` part is lowercased, but the `code` is preserved as-is.
|
|
62
65
|
* - If the final segment is a unique identifier (like a Tax ID), it is preserved as-is.
|
|
@@ -70,16 +73,30 @@ export function normalizeDidWeb(did) {
|
|
|
70
73
|
// Not a valid did:web, return as is.
|
|
71
74
|
return did;
|
|
72
75
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
const lastIndex = parts.length - 1;
|
|
77
|
+
return parts.map((part, index) => {
|
|
78
|
+
if (index < 2)
|
|
79
|
+
return part.toLowerCase();
|
|
80
|
+
if (index === 2)
|
|
81
|
+
return part.toLowerCase().replace(/%3a/gi, '%3A');
|
|
82
|
+
// Hosted tenant identifiers use the canonical VAT + ISO country prefix.
|
|
83
|
+
// Keep this deliberately narrow so unrelated opaque DID path identifiers
|
|
84
|
+
// are not modified merely because they contain the letters "vat".
|
|
85
|
+
if (/^vat[a-z]{2}[-a-z0-9._]+$/i.test(part)) {
|
|
86
|
+
return part.toUpperCase();
|
|
87
|
+
}
|
|
88
|
+
const jurisdictionMatch = /^cds-([a-z]{2})$/i.exec(part);
|
|
89
|
+
if (jurisdictionMatch) {
|
|
90
|
+
return `cds-${jurisdictionMatch[1].toUpperCase()}`;
|
|
91
|
+
}
|
|
92
|
+
if (index === lastIndex) {
|
|
93
|
+
if (!part.includes('|'))
|
|
94
|
+
return part;
|
|
95
|
+
const [system, ...codeParts] = part.split('|');
|
|
96
|
+
return `${system.toLowerCase()}|${codeParts.join('|')}`;
|
|
97
|
+
}
|
|
98
|
+
return part.toLowerCase();
|
|
99
|
+
}).join(':');
|
|
83
100
|
}
|
|
84
101
|
/**
|
|
85
102
|
* Encodes a hostname according to did:web spec (percent-encodes port colons).
|
|
@@ -139,6 +139,35 @@ function extractClaims(entry) {
|
|
|
139
139
|
const resourceClaims = resourceMeta.claims && typeof resourceMeta.claims === 'object' ? resourceMeta.claims : undefined;
|
|
140
140
|
return { ...(resourceClaims || {}), ...(metaClaims || {}) };
|
|
141
141
|
}
|
|
142
|
+
function isLicenseListEntry(entry) {
|
|
143
|
+
const meta = entry.meta && typeof entry.meta === 'object'
|
|
144
|
+
? entry.meta
|
|
145
|
+
: {};
|
|
146
|
+
const claims = extractClaims(entry);
|
|
147
|
+
return !!(normalizeText(meta.status)
|
|
148
|
+
|| normalizeText(entry.status)
|
|
149
|
+
|| normalizeText(entry.id)
|
|
150
|
+
|| normalizeText(claims[ClaimsIndividualProductSchemaorg.serialNumber])
|
|
151
|
+
|| normalizeText(claims[ClaimsOfferSchemaorg.serialNumber]));
|
|
152
|
+
}
|
|
153
|
+
function extractLicenseListEntries(node) {
|
|
154
|
+
if (!node || typeof node !== 'object')
|
|
155
|
+
return [];
|
|
156
|
+
if (Array.isArray(node)) {
|
|
157
|
+
return node.flatMap((entry) => extractLicenseListEntries(entry));
|
|
158
|
+
}
|
|
159
|
+
const entry = node;
|
|
160
|
+
const resource = entry.resource && typeof entry.resource === 'object'
|
|
161
|
+
? entry.resource
|
|
162
|
+
: undefined;
|
|
163
|
+
if (resource && Array.isArray(resource.data)) {
|
|
164
|
+
return extractLicenseListEntries(resource.data);
|
|
165
|
+
}
|
|
166
|
+
if (Array.isArray(entry.data)) {
|
|
167
|
+
return extractLicenseListEntries(entry.data);
|
|
168
|
+
}
|
|
169
|
+
return isLicenseListEntry(entry) ? [entry] : [];
|
|
170
|
+
}
|
|
142
171
|
/**
|
|
143
172
|
* Reads license-like search/list records from one current GW-style response
|
|
144
173
|
* body without exposing raw claim access to frontend code.
|
|
@@ -146,7 +175,7 @@ function extractClaims(entry) {
|
|
|
146
175
|
export function readLicenseListRecords(body) {
|
|
147
176
|
const root = body && typeof body === 'object' ? body : {};
|
|
148
177
|
const bodyNode = root.body && typeof root.body === 'object' ? root.body : root;
|
|
149
|
-
const data =
|
|
178
|
+
const data = extractLicenseListEntries(bodyNode);
|
|
150
179
|
return data
|
|
151
180
|
.filter((entry) => !!entry && typeof entry === 'object')
|
|
152
181
|
.map((entry) => {
|
|
@@ -156,9 +185,9 @@ export function readLicenseListRecords(body) {
|
|
|
156
185
|
id: normalizeText(claims[ClaimsIndividualProductSchemaorg.serialNumber]
|
|
157
186
|
|| claims[ClaimsOfferSchemaorg.serialNumber]
|
|
158
187
|
|| entry.id),
|
|
159
|
-
status: normalizeText(meta.status),
|
|
160
|
-
subjectId: normalizeText(meta.subjectId),
|
|
161
|
-
ownerOrganizationId: normalizeText(meta.ownerOrganizationId || claims['License.ownerOrganizationId']),
|
|
188
|
+
status: normalizeText(meta.status || entry.status),
|
|
189
|
+
subjectId: normalizeText(meta.subjectId || entry.subjectId),
|
|
190
|
+
ownerOrganizationId: normalizeText(meta.ownerOrganizationId || entry.ownerOrganizationId || claims['License.ownerOrganizationId']),
|
|
162
191
|
email: normalizeText(claims[ClaimsPersonSchemaorg.email]),
|
|
163
192
|
telephone: normalizeText(claims[ClaimsPersonSchemaorg.telephone]),
|
|
164
193
|
role: normalizeText(claims[ClaimsPersonSchemaorg.hasOccupationalRoleValue]),
|