gdc-common-utils-ts 2.5.2 → 2.5.4
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 +3 -2
- package/dist/constants/device.d.ts +6 -0
- package/dist/constants/device.js +5 -0
- package/dist/constants/employee-lifecycle.d.ts +52 -0
- package/dist/constants/employee-lifecycle.js +48 -0
- package/dist/constants/http.d.ts +28 -0
- package/dist/constants/http.js +28 -0
- package/dist/constants/identity-auth.d.ts +57 -0
- package/dist/constants/identity-auth.js +57 -0
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/index.js +4 -0
- package/dist/constants/organization-application.d.ts +27 -0
- package/dist/constants/organization-application.js +29 -0
- package/dist/constants/schemaorg.d.ts +4 -0
- package/dist/constants/schemaorg.js +4 -0
- package/dist/constants/verifiable-credentials.d.ts +5 -1
- package/dist/constants/verifiable-credentials.js +6 -1
- package/dist/examples/ica-activation-proof.d.ts +31 -7
- package/dist/examples/ica-activation-proof.js +31 -7
- package/dist/examples/ica-verify-response.d.ts +57 -8
- package/dist/examples/ica-verify-response.js +82 -4
- package/dist/examples/inter-tenant-access-contract.d.ts +2 -0
- package/dist/examples/inter-tenant-access-contract.js +2 -0
- package/dist/examples/license.d.ts +111 -0
- package/dist/examples/license.js +85 -2
- package/dist/examples/shared.d.ts +33 -0
- package/dist/examples/shared.js +32 -0
- package/dist/models/device-license.d.ts +2 -2
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +1 -0
- package/dist/models/inter-tenant-access-contract.d.ts +6 -0
- package/dist/models/inter-tenant-access-contract.js +6 -0
- package/dist/models/organization-employee-lifecycle.d.ts +45 -0
- package/dist/models/organization-employee-lifecycle.js +1 -0
- package/dist/models/urlPath.d.ts +1 -0
- package/dist/models/urlPath.js +1 -0
- package/dist/utils/activation-policy.d.ts +32 -10
- package/dist/utils/activation-policy.js +134 -17
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/inter-tenant-access-contract.js +16 -0
- package/dist/utils/jwk-thumbprint.d.ts +2 -0
- package/dist/utils/jwk-thumbprint.js +8 -0
- package/dist/utils/legal-organization-verification-result.d.ts +8 -0
- package/dist/utils/legal-organization-verification-result.js +10 -1
- package/dist/utils/legal-organization-verification-transaction.d.ts +6 -1
- package/dist/utils/legal-organization-verification-transaction.js +4 -4
- package/dist/utils/license.js +3 -3
- package/dist/utils/organization-employee-lifecycle.d.ts +12 -0
- package/dist/utils/organization-employee-lifecycle.js +125 -0
- package/dist/utils/vp-token.d.ts +5 -1
- package/dist/utils/vp-token.js +6 -2
- package/package.json +1 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { ClaimsIndividualProductSchemaorg, ClaimsPersonSchemaorg } from '../constants/schemaorg.js';
|
|
2
|
+
import { DeviceBindingStatuses } from '../constants/device.js';
|
|
3
|
+
import { EmployeeDirectoryStatuses } from '../constants/employee-lifecycle.js';
|
|
4
|
+
import { IdentityAuthRequestFields, IdentityAuthResponseEntryTypes, } from '../constants/identity-auth.js';
|
|
5
|
+
import { DEFAULT_LICENSE_DEVICE_ALLOWANCE } from './license.js';
|
|
6
|
+
/** Builds the exact identity/auth revoke request body from a typed target. */
|
|
7
|
+
export function buildEmployeeDeviceRevocationBody(target) {
|
|
8
|
+
return Object.freeze({
|
|
9
|
+
[IdentityAuthRequestFields.LicenseId]: target.licenseId,
|
|
10
|
+
[IdentityAuthRequestFields.ClientId]: target.clientId,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/** Reads an employee activation credential from canonical and legacy GW envelopes. */
|
|
14
|
+
export function readEmployeeActivationCode(value) {
|
|
15
|
+
for (const candidate of listNestedRecords(value)) {
|
|
16
|
+
if (candidate.type === IdentityAuthResponseEntryTypes.LicenseIssued) {
|
|
17
|
+
const issuedId = text(candidate.id);
|
|
18
|
+
if (issuedId)
|
|
19
|
+
return issuedId;
|
|
20
|
+
}
|
|
21
|
+
const claims = record(candidate.claims) || record(record(candidate.meta)?.claims);
|
|
22
|
+
const serial = text(claims?.[ClaimsIndividualProductSchemaorg.serialNumber]);
|
|
23
|
+
if (serial)
|
|
24
|
+
return serial;
|
|
25
|
+
}
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
/** Extracts GW search rows regardless of async job envelope depth. */
|
|
29
|
+
export function extractGwSearchResources(value) {
|
|
30
|
+
for (const candidate of listNestedRecords(value)) {
|
|
31
|
+
const data = record(candidate.resource)?.data || candidate.data;
|
|
32
|
+
if (Array.isArray(data))
|
|
33
|
+
return data.map(record).filter(isRecord);
|
|
34
|
+
}
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
/** Combines employee directory and license search results into one typed view. */
|
|
38
|
+
export function projectOrganizationEmployeeLifecycle(input) {
|
|
39
|
+
const licenses = extractGwSearchResources(input.licenseResponse);
|
|
40
|
+
return extractGwSearchResources(input.employeeResponse).map((employee) => {
|
|
41
|
+
const claims = record(employee.claims) || record(record(employee.meta)?.claims) || {};
|
|
42
|
+
const resourceId = text(employee.id);
|
|
43
|
+
const employeeDid = text(claims[ClaimsPersonSchemaorg.identifier]);
|
|
44
|
+
const license = licenses.find((candidate) => {
|
|
45
|
+
const meta = record(candidate.meta) || {};
|
|
46
|
+
const subjectId = text(meta.subjectId);
|
|
47
|
+
return subjectId === resourceId || subjectId === employeeDid;
|
|
48
|
+
});
|
|
49
|
+
const status = normalizeEmployeeDirectoryStatus(text(employee.status) || text(record(employee.meta)?.status));
|
|
50
|
+
if (!license)
|
|
51
|
+
return {
|
|
52
|
+
resourceId,
|
|
53
|
+
email: text(claims[ClaimsPersonSchemaorg.email]),
|
|
54
|
+
roleCode: text(claims[ClaimsPersonSchemaorg.hasOccupationalRoleValue]),
|
|
55
|
+
employeeDid,
|
|
56
|
+
status,
|
|
57
|
+
};
|
|
58
|
+
const meta = record(license.meta) || {};
|
|
59
|
+
const bindings = Array.isArray(meta.deviceBindings) ? meta.deviceBindings.map(record).filter(isRecord) : [];
|
|
60
|
+
const devices = bindings.map((binding) => {
|
|
61
|
+
const info = record(binding.deviceInfo) || {};
|
|
62
|
+
const clientId = text(binding.clientId);
|
|
63
|
+
return {
|
|
64
|
+
clientId,
|
|
65
|
+
name: text(info.model) || text(info.clientInstanceId) || clientId,
|
|
66
|
+
status: binding.status === DeviceBindingStatuses.Revoked
|
|
67
|
+
? DeviceBindingStatuses.Revoked
|
|
68
|
+
: DeviceBindingStatuses.Active,
|
|
69
|
+
};
|
|
70
|
+
}).filter((device) => Boolean(device.clientId));
|
|
71
|
+
return {
|
|
72
|
+
resourceId,
|
|
73
|
+
email: text(claims[ClaimsPersonSchemaorg.email]),
|
|
74
|
+
roleCode: text(claims[ClaimsPersonSchemaorg.hasOccupationalRoleValue]),
|
|
75
|
+
employeeDid,
|
|
76
|
+
status,
|
|
77
|
+
license: {
|
|
78
|
+
id: text(license.id),
|
|
79
|
+
status: text(meta.status),
|
|
80
|
+
maxDevices: positiveInteger(meta.maxDevices) || DEFAULT_LICENSE_DEVICE_ALLOWANCE,
|
|
81
|
+
activeDevices: devices.filter((device) => device.status === DeviceBindingStatuses.Active).length,
|
|
82
|
+
devices,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}).filter((employee) => Boolean(employee.resourceId));
|
|
86
|
+
}
|
|
87
|
+
function normalizeEmployeeDirectoryStatus(value) {
|
|
88
|
+
return Object.values(EmployeeDirectoryStatuses).includes(value)
|
|
89
|
+
? value
|
|
90
|
+
: EmployeeDirectoryStatuses.Unknown;
|
|
91
|
+
}
|
|
92
|
+
function listNestedRecords(root) {
|
|
93
|
+
const result = [];
|
|
94
|
+
const pending = [root];
|
|
95
|
+
const visited = new Set();
|
|
96
|
+
while (pending.length > 0) {
|
|
97
|
+
const value = pending.shift();
|
|
98
|
+
if (!value || typeof value !== 'object' || visited.has(value))
|
|
99
|
+
continue;
|
|
100
|
+
visited.add(value);
|
|
101
|
+
if (Array.isArray(value)) {
|
|
102
|
+
pending.push(...value);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const item = value;
|
|
106
|
+
result.push(item);
|
|
107
|
+
pending.push(...Object.values(item));
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
function record(value) {
|
|
112
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
113
|
+
? value
|
|
114
|
+
: undefined;
|
|
115
|
+
}
|
|
116
|
+
function isRecord(value) {
|
|
117
|
+
return Boolean(value);
|
|
118
|
+
}
|
|
119
|
+
function text(value) {
|
|
120
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
121
|
+
}
|
|
122
|
+
function positiveInteger(value) {
|
|
123
|
+
const parsed = Number(value);
|
|
124
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : undefined;
|
|
125
|
+
}
|
package/dist/utils/vp-token.d.ts
CHANGED
|
@@ -103,12 +103,14 @@ export declare function getOrganizationCredentialFromVpToken(vpToken: string): V
|
|
|
103
103
|
*/
|
|
104
104
|
export declare function getLegalRepresentativeCredentialFromVpToken(vpToken: string): VpCredential | undefined;
|
|
105
105
|
/**
|
|
106
|
-
* Extracts the
|
|
106
|
+
* Extracts the service-controller credential from a VP token
|
|
107
107
|
* when present. It never substitutes a legal-representative credential.
|
|
108
108
|
*
|
|
109
109
|
* @param vpToken Compact VP token or raw JSON string.
|
|
110
110
|
*/
|
|
111
111
|
export declare function getOrganizationControllerCredentialFromVpToken(vpToken: string): VpCredential | undefined;
|
|
112
|
+
/** Canonical name for `getOrganizationControllerCredentialFromVpToken`. */
|
|
113
|
+
export declare const getServiceControllerCredentialFromVpToken: typeof getOrganizationControllerCredentialFromVpToken;
|
|
112
114
|
/**
|
|
113
115
|
* Appends an organization activation credential after validating its VC type.
|
|
114
116
|
*
|
|
@@ -129,6 +131,8 @@ export declare function addLegalRepresentativeCredential(vpPayload: VpTokenPaylo
|
|
|
129
131
|
* Accepts compact VC strings, raw JSON VC strings, or VC JSON objects.
|
|
130
132
|
*/
|
|
131
133
|
export declare function addOrganizationControllerCredential(vpPayload: VpTokenPayload, vc: VpCredentialInput): VpTokenPayload;
|
|
134
|
+
/** Canonical name for `addOrganizationControllerCredential`. */
|
|
135
|
+
export declare const addServiceControllerCredential: typeof addOrganizationControllerCredential;
|
|
132
136
|
export declare function prepareForSignature(header: VpTokenHeader, payload: VpTokenPayload): {
|
|
133
137
|
encodedHeader: string;
|
|
134
138
|
encodedPayload: string;
|
package/dist/utils/vp-token.js
CHANGED
|
@@ -190,7 +190,7 @@ export function getLegalRepresentativeCredentialFromVpToken(vpToken) {
|
|
|
190
190
|
return getVpCredentialByAnyType(vpToken, [...REPRESENTATIVE_ACTIVATION_VC_TYPES]);
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
|
-
* Extracts the
|
|
193
|
+
* Extracts the service-controller credential from a VP token
|
|
194
194
|
* when present. It never substitutes a legal-representative credential.
|
|
195
195
|
*
|
|
196
196
|
* @param vpToken Compact VP token or raw JSON string.
|
|
@@ -198,6 +198,8 @@ export function getLegalRepresentativeCredentialFromVpToken(vpToken) {
|
|
|
198
198
|
export function getOrganizationControllerCredentialFromVpToken(vpToken) {
|
|
199
199
|
return getVpCredentialByAnyType(vpToken, [...ORGANIZATION_CONTROLLER_ACTIVATION_VC_TYPES]);
|
|
200
200
|
}
|
|
201
|
+
/** Canonical name for `getOrganizationControllerCredentialFromVpToken`. */
|
|
202
|
+
export const getServiceControllerCredentialFromVpToken = getOrganizationControllerCredentialFromVpToken;
|
|
201
203
|
function vcHasAnyType(vcPayload, acceptedTypes) {
|
|
202
204
|
if (!vcPayload)
|
|
203
205
|
return false;
|
|
@@ -238,8 +240,10 @@ export function addLegalRepresentativeCredential(vpPayload, vc) {
|
|
|
238
240
|
* Accepts compact VC strings, raw JSON VC strings, or VC JSON objects.
|
|
239
241
|
*/
|
|
240
242
|
export function addOrganizationControllerCredential(vpPayload, vc) {
|
|
241
|
-
return addTypedVC(vpPayload, vc, [...ORGANIZATION_CONTROLLER_ACTIVATION_VC_TYPES], '
|
|
243
|
+
return addTypedVC(vpPayload, vc, [...ORGANIZATION_CONTROLLER_ACTIVATION_VC_TYPES], 'ServiceController');
|
|
242
244
|
}
|
|
245
|
+
/** Canonical name for `addOrganizationControllerCredential`. */
|
|
246
|
+
export const addServiceControllerCredential = addOrganizationControllerCredential;
|
|
243
247
|
export function prepareForSignature(header, payload) {
|
|
244
248
|
return prepareJwtForSignature(header, payload);
|
|
245
249
|
}
|