gdc-common-utils-ts 2.5.11 → 2.5.12

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.
@@ -9,6 +9,7 @@ export * from './individual-controller';
9
9
  export * from './professional';
10
10
  export * from './employee';
11
11
  export * from './license';
12
+ export * from './organization-role-license';
12
13
  export * from './invoice';
13
14
  export * from './inter-tenant-access-contract';
14
15
  export * from './subject-identity-binding';
@@ -9,6 +9,7 @@ export * from './individual-controller.js';
9
9
  export * from './professional.js';
10
10
  export * from './employee.js';
11
11
  export * from './license.js';
12
+ export * from './organization-role-license.js';
12
13
  export * from './invoice.js';
13
14
  export * from './inter-tenant-access-contract.js';
14
15
  export * from './subject-identity-binding.js';
@@ -0,0 +1,16 @@
1
+ import type { OrganizationRoleLicense } from '../models/organization-role-license';
2
+ import { type OrganizationRoleLicenseIdentity } from '../utils/organization-role-license';
3
+ /** Reusable synthetic identity for role-licence contract and consumer tests. */
4
+ export declare const EXAMPLE_ORGANIZATION_ROLE_LICENSE_IDENTITY: OrganizationRoleLicenseIdentity;
5
+ /** Reusable catch-all plus exact-override policy example. */
6
+ export declare const EXAMPLE_ORGANIZATION_ROLE_LICENSE_POLICIES: readonly (Readonly<{
7
+ sector: "";
8
+ active: true;
9
+ maxDevices: null;
10
+ }> | Readonly<{
11
+ sector: "animal-care";
12
+ active: false;
13
+ maxDevices: 2;
14
+ }>)[];
15
+ /** Public ledger fixture: no clear contact or tenant-local employee UUID. */
16
+ export declare const EXAMPLE_ORGANIZATION_ROLE_LICENSE: OrganizationRoleLicense;
@@ -0,0 +1,37 @@
1
+ // Copyright 2026 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ import { buildStableActorIdentifier } from '../utils/actor-identifier.js';
3
+ import { buildOrganizationRoleLicenseId, } from '../utils/organization-role-license.js';
4
+ /** Reusable synthetic identity for role-licence contract and consumer tests. */
5
+ export const EXAMPLE_ORGANIZATION_ROLE_LICENSE_IDENTITY = Object.freeze({
6
+ jurisdiction: 'es',
7
+ organizationId: 'urn:org:TAX:ES-B12345678',
8
+ stableContactIdentifier: buildStableActorIdentifier({
9
+ contactKind: 'email',
10
+ contact: 'professional@example.org',
11
+ }),
12
+ licensedRole: 'RESPRSN',
13
+ });
14
+ /** Reusable catch-all plus exact-override policy example. */
15
+ export const EXAMPLE_ORGANIZATION_ROLE_LICENSE_POLICIES = Object.freeze([
16
+ Object.freeze({ sector: '', active: true, maxDevices: null }),
17
+ Object.freeze({ sector: 'animal-care', active: false, maxDevices: 2 }),
18
+ ]);
19
+ /** Public ledger fixture: no clear contact or tenant-local employee UUID. */
20
+ export const EXAMPLE_ORGANIZATION_ROLE_LICENSE = Object.freeze({
21
+ id: buildOrganizationRoleLicenseId(EXAMPLE_ORGANIZATION_ROLE_LICENSE_IDENTITY),
22
+ ...EXAMPLE_ORGANIZATION_ROLE_LICENSE_IDENTITY,
23
+ status: 'active',
24
+ data: [...EXAMPLE_ORGANIZATION_ROLE_LICENSE_POLICIES],
25
+ devices: [
26
+ Object.freeze({
27
+ clientId: 'example-client-health-1',
28
+ clientInstanceId: 'example-installation-health-1',
29
+ sector: 'health-care',
30
+ host: 'https://gw.example.org',
31
+ status: 'active',
32
+ activatedAt: 1_700_000_000,
33
+ }),
34
+ ],
35
+ createdAt: 1_700_000_000,
36
+ updatedAt: 1_700_000_000,
37
+ });
@@ -19,6 +19,7 @@ export * from './dataspace-discovery';
19
19
  export * from './dataspace-discovery-defaults';
20
20
  export * from './dataspace-protocol';
21
21
  export * from './device-license';
22
+ export * from './organization-role-license';
22
23
  export * from './organization-employee-lifecycle';
23
24
  export * from './did';
24
25
  export * from './fhir-documents';
@@ -19,6 +19,7 @@ export * from './dataspace-discovery.js';
19
19
  export * from './dataspace-discovery-defaults.js';
20
20
  export * from './dataspace-protocol.js';
21
21
  export * from './device-license.js';
22
+ export * from './organization-role-license.js';
22
23
  export * from './organization-employee-lifecycle.js';
23
24
  export * from './did.js';
24
25
  export * from './fhir-documents.js';
@@ -0,0 +1,45 @@
1
+ import type { DeviceBindingStatus } from '../constants/device';
2
+ /** Lifecycle of one organization-owned, role-bearing licence assignment. */
3
+ export type OrganizationRoleLicenseStatus = 'active' | 'revoked';
4
+ /**
5
+ * Contractual policy for one sector.
6
+ *
7
+ * `sector: ""` is the catch-all policy. An exact sector entry overrides it.
8
+ * `maxDevices: null` delegates the numeric limit to the GW/portal policy; it
9
+ * does not mean an unlimited number of installations.
10
+ */
11
+ export interface OrganizationRoleLicenseSectorPolicy {
12
+ sector: string;
13
+ active: boolean;
14
+ maxDevices: number | null;
15
+ }
16
+ /** One concrete DCR installation registered against the licence. */
17
+ export interface OrganizationRoleLicenseDevice {
18
+ clientId: string;
19
+ clientInstanceId: string;
20
+ sector: string;
21
+ host: string;
22
+ status: DeviceBindingStatus;
23
+ activatedAt: number;
24
+ revokedAt?: number;
25
+ }
26
+ /**
27
+ * Public ledger projection of one licence assigned by an organization.
28
+ *
29
+ * The stable contact is a one-way `urn:multibase:` identifier. Clear email,
30
+ * telephone, tenant-local employee UUIDs, payment details and application
31
+ * permissions must never be written to this asset.
32
+ */
33
+ export interface OrganizationRoleLicense {
34
+ id: string;
35
+ organizationId: string;
36
+ jurisdiction: string;
37
+ stableContactIdentifier: string;
38
+ licensedRole: string;
39
+ status: OrganizationRoleLicenseStatus;
40
+ data: OrganizationRoleLicenseSectorPolicy[];
41
+ devices: OrganizationRoleLicenseDevice[];
42
+ createdAt: number;
43
+ updatedAt: number;
44
+ revokedAt?: number;
45
+ }
@@ -0,0 +1,2 @@
1
+ // Copyright 2026 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ export {};
@@ -88,6 +88,7 @@ export * from './organization-test-network-credential';
88
88
  export * from './test-network-organization-credentials';
89
89
  export * from './local-terminology-provider';
90
90
  export * from './license';
91
+ export * from './organization-role-license';
91
92
  export * from './license-commercial-search';
92
93
  export * from './license-list-search';
93
94
  export * from './license-offer-order';
@@ -88,6 +88,7 @@ export * from './organization-test-network-credential.js';
88
88
  export * from './test-network-organization-credentials.js';
89
89
  export * from './local-terminology-provider.js';
90
90
  export * from './license.js';
91
+ export * from './organization-role-license.js';
91
92
  export * from './license-commercial-search.js';
92
93
  export * from './license-list-search.js';
93
94
  export * from './license-offer-order.js';
@@ -0,0 +1,41 @@
1
+ import type { OrganizationRoleLicense, OrganizationRoleLicenseDevice, OrganizationRoleLicenseSectorPolicy } from '../models/organization-role-license';
2
+ export type OrganizationRoleLicenseIdentity = Readonly<{
3
+ jurisdiction: string;
4
+ organizationId: string;
5
+ stableContactIdentifier: string;
6
+ licensedRole: string;
7
+ }>;
8
+ /**
9
+ * Builds the exact, compact licence preimage agreed across portals and hosts.
10
+ * The preimage is hashed before persistence and is never itself a ledger key.
11
+ */
12
+ export declare function buildOrganizationRoleLicensePreimage(identity: OrganizationRoleLicenseIdentity): string;
13
+ /** SHA3-384 multihash identifier for organization + contact + licensed role. */
14
+ export declare function buildOrganizationRoleLicenseId(identity: OrganizationRoleLicenseIdentity): string;
15
+ /** Validates and de-duplicates sector policies while preserving input order. */
16
+ export declare function normalizeOrganizationRoleLicensePolicies(policies: readonly OrganizationRoleLicenseSectorPolicy[]): OrganizationRoleLicenseSectorPolicy[];
17
+ /** Exact sector policy wins; the empty-sector catch-all is only a fallback. */
18
+ export declare function resolveOrganizationRoleLicensePolicy(policies: readonly OrganizationRoleLicenseSectorPolicy[], sector: string): OrganizationRoleLicenseSectorPolicy | undefined;
19
+ /** Returns the contractual limit or the positive GW/portal default. */
20
+ export declare function resolveOrganizationRoleLicenseMaxDevices(policy: OrganizationRoleLicenseSectorPolicy, defaultMaxDevices: number): number;
21
+ /** Checks global status plus the resolved exact/catch-all sector policy. */
22
+ export declare function organizationRoleLicenseAllowsSector(license: Readonly<{
23
+ status: OrganizationRoleLicense['status'];
24
+ data: readonly OrganizationRoleLicenseSectorPolicy[];
25
+ }>, sector: string): boolean;
26
+ /** Active DCR installations are counted per concrete sector, across hosts/apps. */
27
+ export declare function countActiveOrganizationRoleLicenseDevices(devices: readonly OrganizationRoleLicenseDevice[], sector: string): number;
28
+ /**
29
+ * Deterministic DCR admission decision. Re-registering the same active client
30
+ * is idempotent and does not consume an additional device slot.
31
+ */
32
+ export declare function organizationRoleLicenseAllowsDevice(license: Readonly<{
33
+ status: OrganizationRoleLicense['status'];
34
+ data: readonly OrganizationRoleLicenseSectorPolicy[];
35
+ devices: readonly OrganizationRoleLicenseDevice[];
36
+ }>, input: Readonly<{
37
+ sector: string;
38
+ clientId: string;
39
+ clientInstanceId: string;
40
+ defaultMaxDevices: number;
41
+ }>): boolean;
@@ -0,0 +1,99 @@
1
+ // Copyright 2026 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ import { encodeMultibaseSha3 } from './multibasehash.js';
3
+ function required(value, label) {
4
+ const normalized = String(value || '').trim();
5
+ if (!normalized)
6
+ throw new TypeError(`${label} is required.`);
7
+ return normalized;
8
+ }
9
+ function normalizedSector(value) {
10
+ return String(value || '').trim().toLowerCase();
11
+ }
12
+ function validateStableContactIdentifier(value) {
13
+ const normalized = required(value, 'stableContactIdentifier');
14
+ if (!/^urn:multibase:z[1-9A-HJ-NP-Za-km-z]+$/.test(normalized)) {
15
+ throw new TypeError('stableContactIdentifier must be a canonical urn:multibase value.');
16
+ }
17
+ return normalized;
18
+ }
19
+ /**
20
+ * Builds the exact, compact licence preimage agreed across portals and hosts.
21
+ * The preimage is hashed before persistence and is never itself a ledger key.
22
+ */
23
+ export function buildOrganizationRoleLicensePreimage(identity) {
24
+ const jurisdiction = required(identity.jurisdiction, 'jurisdiction').toLowerCase();
25
+ const organizationId = required(identity.organizationId, 'organizationId');
26
+ const stableContactIdentifier = validateStableContactIdentifier(identity.stableContactIdentifier);
27
+ const licensedRole = required(identity.licensedRole, 'licensedRole');
28
+ return `urn:cds-${jurisdiction}:${organizationId}:${stableContactIdentifier}:${licensedRole}`;
29
+ }
30
+ /** SHA3-384 multihash identifier for organization + contact + licensed role. */
31
+ export function buildOrganizationRoleLicenseId(identity) {
32
+ return `urn:multibase:${encodeMultibaseSha3(buildOrganizationRoleLicensePreimage(identity), 384)}`;
33
+ }
34
+ /** Validates and de-duplicates sector policies while preserving input order. */
35
+ export function normalizeOrganizationRoleLicensePolicies(policies) {
36
+ if (!Array.isArray(policies) || policies.length === 0) {
37
+ throw new TypeError('At least one licence sector policy is required.');
38
+ }
39
+ const seen = new Set();
40
+ return policies.map((policy) => {
41
+ const sector = normalizedSector(policy.sector);
42
+ if (seen.has(sector))
43
+ throw new TypeError(`Duplicate licence sector policy: ${sector || '<all>'}.`);
44
+ seen.add(sector);
45
+ if (policy.maxDevices !== null
46
+ && (!Number.isInteger(policy.maxDevices) || policy.maxDevices < 1)) {
47
+ throw new TypeError('maxDevices must be null or a positive integer.');
48
+ }
49
+ return { sector, active: Boolean(policy.active), maxDevices: policy.maxDevices };
50
+ });
51
+ }
52
+ /** Exact sector policy wins; the empty-sector catch-all is only a fallback. */
53
+ export function resolveOrganizationRoleLicensePolicy(policies, sector) {
54
+ const requested = required(sector, 'sector').toLowerCase();
55
+ return policies.find((policy) => normalizedSector(policy.sector) === requested)
56
+ ?? policies.find((policy) => normalizedSector(policy.sector) === '');
57
+ }
58
+ /** Returns the contractual limit or the positive GW/portal default. */
59
+ export function resolveOrganizationRoleLicenseMaxDevices(policy, defaultMaxDevices) {
60
+ if (policy.maxDevices !== null)
61
+ return policy.maxDevices;
62
+ if (!Number.isInteger(defaultMaxDevices) || defaultMaxDevices < 1) {
63
+ throw new TypeError('defaultMaxDevices must be a positive integer.');
64
+ }
65
+ return defaultMaxDevices;
66
+ }
67
+ /** Checks global status plus the resolved exact/catch-all sector policy. */
68
+ export function organizationRoleLicenseAllowsSector(license, sector) {
69
+ if (license.status !== 'active')
70
+ return false;
71
+ return resolveOrganizationRoleLicensePolicy(license.data, sector)?.active === true;
72
+ }
73
+ /** Active DCR installations are counted per concrete sector, across hosts/apps. */
74
+ export function countActiveOrganizationRoleLicenseDevices(devices, sector) {
75
+ const requested = required(sector, 'sector').toLowerCase();
76
+ return devices.filter((device) => device.status === 'active'
77
+ && normalizedSector(device.sector) === requested).length;
78
+ }
79
+ /**
80
+ * Deterministic DCR admission decision. Re-registering the same active client
81
+ * is idempotent and does not consume an additional device slot.
82
+ */
83
+ export function organizationRoleLicenseAllowsDevice(license, input) {
84
+ const sector = required(input.sector, 'sector').toLowerCase();
85
+ const clientId = required(input.clientId, 'clientId');
86
+ const clientInstanceId = required(input.clientInstanceId, 'clientInstanceId');
87
+ if (!organizationRoleLicenseAllowsSector(license, sector))
88
+ return false;
89
+ if (license.devices.some((device) => device.status === 'active'
90
+ && device.clientId === clientId
91
+ && device.clientInstanceId === clientInstanceId
92
+ && normalizedSector(device.sector) === sector))
93
+ return true;
94
+ const policy = resolveOrganizationRoleLicensePolicy(license.data, sector);
95
+ if (!policy)
96
+ return false;
97
+ return countActiveOrganizationRoleLicenseDevices(license.devices, sector)
98
+ < resolveOrganizationRoleLicenseMaxDevices(policy, input.defaultMaxDevices);
99
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gdc-common-utils-ts",
3
- "version": "2.5.11",
3
+ "version": "2.5.12",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },