gdc-common-utils-ts 2.5.12 → 2.5.15

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.
@@ -2,12 +2,8 @@ import type { OrganizationRoleLicense } from '../models/organization-role-licens
2
2
  import { type OrganizationRoleLicenseIdentity } from '../utils/organization-role-license';
3
3
  /** Reusable synthetic identity for role-licence contract and consumer tests. */
4
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<{
5
+ /** Reusable exact-sector policies; no empty-sector wildcard is authored. */
6
+ export declare const EXAMPLE_ORGANIZATION_ROLE_LICENSE_POLICIES: readonly (import("..").OrganizationRoleLicenseSectorPolicy | Readonly<{
11
7
  sector: "animal-care";
12
8
  active: false;
13
9
  maxDevices: 2;
@@ -1,20 +1,22 @@
1
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';
2
+ import { buildStableActorIdentifier, StableActorContactKinds } from '../utils/actor-identifier.js';
3
+ import { buildOrganizationRoleLicenseId, DEFAULT_ORGANIZATION_ROLE_LICENSE_POLICY, } from '../utils/organization-role-license.js';
4
+ import { EXAMPLE_EMAIL_PROFESSIONAL, EXAMPLE_JURISDICTION, EXAMPLE_LEGAL_ORGANIZATION_TAX_ID, EXAMPLE_ORGANIZATION_CONTROLLER_ROLE, } from './shared.js';
5
+ import { DataspaceSectors } from '../constants/sectors.js';
4
6
  /** Reusable synthetic identity for role-licence contract and consumer tests. */
5
7
  export const EXAMPLE_ORGANIZATION_ROLE_LICENSE_IDENTITY = Object.freeze({
6
- jurisdiction: 'es',
7
- organizationId: 'urn:org:TAX:ES-B12345678',
8
+ jurisdiction: EXAMPLE_JURISDICTION,
9
+ organizationOfficialId: EXAMPLE_LEGAL_ORGANIZATION_TAX_ID,
8
10
  stableContactIdentifier: buildStableActorIdentifier({
9
- contactKind: 'email',
10
- contact: 'professional@example.org',
11
+ contactKind: StableActorContactKinds.Email,
12
+ contact: EXAMPLE_EMAIL_PROFESSIONAL,
11
13
  }),
12
- licensedRole: 'RESPRSN',
14
+ licensedRole: EXAMPLE_ORGANIZATION_CONTROLLER_ROLE,
13
15
  });
14
- /** Reusable catch-all plus exact-override policy example. */
16
+ /** Reusable exact-sector policies; no empty-sector wildcard is authored. */
15
17
  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
+ DEFAULT_ORGANIZATION_ROLE_LICENSE_POLICY,
19
+ Object.freeze({ sector: DataspaceSectors.AnimalCare, active: false, maxDevices: 2 }),
18
20
  ]);
19
21
  /** Public ledger fixture: no clear contact or tenant-local employee UUID. */
20
22
  export const EXAMPLE_ORGANIZATION_ROLE_LICENSE = Object.freeze({
@@ -22,16 +24,6 @@ export const EXAMPLE_ORGANIZATION_ROLE_LICENSE = Object.freeze({
22
24
  ...EXAMPLE_ORGANIZATION_ROLE_LICENSE_IDENTITY,
23
25
  status: 'active',
24
26
  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
27
  createdAt: 1_700_000_000,
36
28
  updatedAt: 1_700_000_000,
37
29
  });
@@ -1,44 +1,33 @@
1
- import type { DeviceBindingStatus } from '../constants/device';
1
+ import type { DataspaceSector } from '../constants/sectors';
2
2
  /** Lifecycle of one organization-owned, role-bearing licence assignment. */
3
3
  export type OrganizationRoleLicenseStatus = 'active' | 'revoked';
4
4
  /**
5
5
  * Contractual policy for one sector.
6
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.
7
+ * Every entry targets one canonical dataspace sector. Omitting `maxDevices`
8
+ * delegates the numeric limit to the GW/portal policy.
10
9
  */
11
10
  export interface OrganizationRoleLicenseSectorPolicy {
12
- sector: string;
11
+ sector: DataspaceSector;
13
12
  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;
13
+ maxDevices?: number;
25
14
  }
26
15
  /**
27
16
  * Public ledger projection of one licence assigned by an organization.
28
17
  *
29
18
  * 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.
19
+ * telephone, tenant-local employee UUIDs, payment details, DCR registrations,
20
+ * hosts and application permissions must never be written to this asset.
32
21
  */
33
22
  export interface OrganizationRoleLicense {
34
23
  id: string;
35
- organizationId: string;
24
+ /** Official legal identifier value; never an embedded `urn:org:*` identifier. */
25
+ organizationOfficialId: string;
36
26
  jurisdiction: string;
37
27
  stableContactIdentifier: string;
38
28
  licensedRole: string;
39
29
  status: OrganizationRoleLicenseStatus;
40
30
  data: OrganizationRoleLicenseSectorPolicy[];
41
- devices: OrganizationRoleLicenseDevice[];
42
31
  createdAt: number;
43
32
  updatedAt: number;
44
33
  revokedAt?: number;
@@ -1,4 +1,8 @@
1
- export type StableActorContactKind = 'email' | 'phone';
1
+ export declare const StableActorContactKinds: Readonly<{
2
+ readonly Email: "email";
3
+ readonly Phone: "phone";
4
+ }>;
5
+ export type StableActorContactKind = typeof StableActorContactKinds[keyof typeof StableActorContactKinds];
2
6
  /**
3
7
  * Builds the private, stable actor identifier shared by independent portals.
4
8
  *
@@ -1,5 +1,9 @@
1
1
  import { normalizePhone } from './consent.js';
2
2
  import { normalizeSameAsHash, normalizeTelephoneHash } from './same-as.js';
3
+ export const StableActorContactKinds = Object.freeze({
4
+ Email: 'email',
5
+ Phone: 'phone',
6
+ });
3
7
  /**
4
8
  * Builds the private, stable actor identifier shared by independent portals.
5
9
  *
@@ -1,10 +1,12 @@
1
- import type { OrganizationRoleLicense, OrganizationRoleLicenseDevice, OrganizationRoleLicenseSectorPolicy } from '../models/organization-role-license';
1
+ import type { OrganizationRoleLicense, OrganizationRoleLicenseSectorPolicy } from '../models/organization-role-license';
2
2
  export type OrganizationRoleLicenseIdentity = Readonly<{
3
3
  jurisdiction: string;
4
- organizationId: string;
4
+ organizationOfficialId: string;
5
5
  stableContactIdentifier: string;
6
6
  licensedRole: string;
7
7
  }>;
8
+ export declare const DEFAULT_ORGANIZATION_ROLE_LICENSE_POLICY: OrganizationRoleLicenseSectorPolicy;
9
+ export declare function validateOrganizationOfficialId(value: string): string;
8
10
  /**
9
11
  * Builds the exact, compact licence preimage agreed across portals and hosts.
10
12
  * The preimage is hashed before persistence and is never itself a ledger key.
@@ -14,28 +16,12 @@ export declare function buildOrganizationRoleLicensePreimage(identity: Organizat
14
16
  export declare function buildOrganizationRoleLicenseId(identity: OrganizationRoleLicenseIdentity): string;
15
17
  /** Validates and de-duplicates sector policies while preserving input order. */
16
18
  export declare function normalizeOrganizationRoleLicensePolicies(policies: readonly OrganizationRoleLicenseSectorPolicy[]): OrganizationRoleLicenseSectorPolicy[];
17
- /** Exact sector policy wins; the empty-sector catch-all is only a fallback. */
19
+ /** Resolves the exact canonical sector policy. */
18
20
  export declare function resolveOrganizationRoleLicensePolicy(policies: readonly OrganizationRoleLicenseSectorPolicy[], sector: string): OrganizationRoleLicenseSectorPolicy | undefined;
19
21
  /** Returns the contractual limit or the positive GW/portal default. */
20
22
  export declare function resolveOrganizationRoleLicenseMaxDevices(policy: OrganizationRoleLicenseSectorPolicy, defaultMaxDevices: number): number;
21
- /** Checks global status plus the resolved exact/catch-all sector policy. */
23
+ /** Checks global status plus the resolved exact-sector policy. */
22
24
  export declare function organizationRoleLicenseAllowsSector(license: Readonly<{
23
25
  status: OrganizationRoleLicense['status'];
24
26
  data: readonly OrganizationRoleLicenseSectorPolicy[];
25
27
  }>, 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;
@@ -1,5 +1,6 @@
1
1
  // Copyright 2026 Antifraud Services Inc. under the Apache License, Version 2.0.
2
2
  import { encodeMultibaseSha3 } from './multibasehash.js';
3
+ import { DataspaceSectors } from '../constants/sectors.js';
3
4
  function required(value, label) {
4
5
  const normalized = String(value || '').trim();
5
6
  if (!normalized)
@@ -9,6 +10,10 @@ function required(value, label) {
9
10
  function normalizedSector(value) {
10
11
  return String(value || '').trim().toLowerCase();
11
12
  }
13
+ export const DEFAULT_ORGANIZATION_ROLE_LICENSE_POLICY = Object.freeze({
14
+ sector: DataspaceSectors.OneHealthResearch,
15
+ active: true,
16
+ });
12
17
  function validateStableContactIdentifier(value) {
13
18
  const normalized = required(value, 'stableContactIdentifier');
14
19
  if (!/^urn:multibase:z[1-9A-HJ-NP-Za-km-z]+$/.test(normalized)) {
@@ -16,16 +21,23 @@ function validateStableContactIdentifier(value) {
16
21
  }
17
22
  return normalized;
18
23
  }
24
+ export function validateOrganizationOfficialId(value) {
25
+ const normalized = required(value, 'organizationOfficialId');
26
+ if (normalized.includes(':') || /^urn:/i.test(normalized)) {
27
+ throw new TypeError('organizationOfficialId must be the official identifier value, not an organization URN.');
28
+ }
29
+ return normalized;
30
+ }
19
31
  /**
20
32
  * Builds the exact, compact licence preimage agreed across portals and hosts.
21
33
  * The preimage is hashed before persistence and is never itself a ledger key.
22
34
  */
23
35
  export function buildOrganizationRoleLicensePreimage(identity) {
24
36
  const jurisdiction = required(identity.jurisdiction, 'jurisdiction').toLowerCase();
25
- const organizationId = required(identity.organizationId, 'organizationId');
37
+ const organizationOfficialId = validateOrganizationOfficialId(identity.organizationOfficialId);
26
38
  const stableContactIdentifier = validateStableContactIdentifier(identity.stableContactIdentifier);
27
39
  const licensedRole = required(identity.licensedRole, 'licensedRole');
28
- return `urn:cds-${jurisdiction}:${organizationId}:${stableContactIdentifier}:${licensedRole}`;
40
+ return `urn:cds-${jurisdiction}:${organizationOfficialId}:${stableContactIdentifier}:${licensedRole}`;
29
41
  }
30
42
  /** SHA3-384 multihash identifier for organization + contact + licensed role. */
31
43
  export function buildOrganizationRoleLicenseId(identity) {
@@ -39,61 +51,42 @@ export function normalizeOrganizationRoleLicensePolicies(policies) {
39
51
  const seen = new Set();
40
52
  return policies.map((policy) => {
41
53
  const sector = normalizedSector(policy.sector);
54
+ if (!sector)
55
+ throw new TypeError('Licence sector policy requires a canonical sector.');
56
+ if (!Object.values(DataspaceSectors).includes(sector)) {
57
+ throw new TypeError(`Unsupported licence sector policy: ${sector}.`);
58
+ }
42
59
  if (seen.has(sector))
43
- throw new TypeError(`Duplicate licence sector policy: ${sector || '<all>'}.`);
60
+ throw new TypeError(`Duplicate licence sector policy: ${sector}.`);
44
61
  seen.add(sector);
45
- if (policy.maxDevices !== null
62
+ if (policy.maxDevices !== undefined
46
63
  && (!Number.isInteger(policy.maxDevices) || policy.maxDevices < 1)) {
47
- throw new TypeError('maxDevices must be null or a positive integer.');
64
+ throw new TypeError('maxDevices must be omitted or a positive integer.');
48
65
  }
49
- return { sector, active: Boolean(policy.active), maxDevices: policy.maxDevices };
66
+ return {
67
+ sector,
68
+ active: Boolean(policy.active),
69
+ ...(policy.maxDevices === undefined ? {} : { maxDevices: policy.maxDevices }),
70
+ };
50
71
  });
51
72
  }
52
- /** Exact sector policy wins; the empty-sector catch-all is only a fallback. */
73
+ /** Resolves the exact canonical sector policy. */
53
74
  export function resolveOrganizationRoleLicensePolicy(policies, sector) {
54
75
  const requested = required(sector, 'sector').toLowerCase();
55
- return policies.find((policy) => normalizedSector(policy.sector) === requested)
56
- ?? policies.find((policy) => normalizedSector(policy.sector) === '');
76
+ return policies.find((policy) => normalizedSector(policy.sector) === requested);
57
77
  }
58
78
  /** Returns the contractual limit or the positive GW/portal default. */
59
79
  export function resolveOrganizationRoleLicenseMaxDevices(policy, defaultMaxDevices) {
60
- if (policy.maxDevices !== null)
80
+ if (policy.maxDevices !== undefined)
61
81
  return policy.maxDevices;
62
82
  if (!Number.isInteger(defaultMaxDevices) || defaultMaxDevices < 1) {
63
83
  throw new TypeError('defaultMaxDevices must be a positive integer.');
64
84
  }
65
85
  return defaultMaxDevices;
66
86
  }
67
- /** Checks global status plus the resolved exact/catch-all sector policy. */
87
+ /** Checks global status plus the resolved exact-sector policy. */
68
88
  export function organizationRoleLicenseAllowsSector(license, sector) {
69
89
  if (license.status !== 'active')
70
90
  return false;
71
91
  return resolveOrganizationRoleLicensePolicy(license.data, sector)?.active === true;
72
92
  }
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.12",
3
+ "version": "2.5.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },