gdc-common-utils-ts 1.0.1

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.
Files changed (100) hide show
  1. package/PUBLISHING.md +33 -0
  2. package/__tests__/AesManager.test.ts +53 -0
  3. package/__tests__/CryptographyService.test.ts +194 -0
  4. package/__tests__/bundle.test.ts +29 -0
  5. package/__tests__/content.test.ts +72 -0
  6. package/__tests__/crypto-encode-decode.test.ts +52 -0
  7. package/__tests__/crypto-hmac.test.ts +21 -0
  8. package/__tests__/did-generateServiceId.errors.test.ts +8 -0
  9. package/__tests__/did-generateServiceId.test.ts +18 -0
  10. package/__tests__/models-clinical-sections.test.ts +32 -0
  11. package/__tests__/models-multibase58.test.ts +33 -0
  12. package/__tests__/multibase58.errors.test.ts +7 -0
  13. package/__tests__/multibase58.test.ts +28 -0
  14. package/__tests__/multibasehash.test.ts +25 -0
  15. package/__tests__/utils-actor.test.ts +22 -0
  16. package/__tests__/utils-base-convert.test.ts +57 -0
  17. package/__tests__/utils-baseN.test.ts +40 -0
  18. package/__tests__/utils-did-extra.test.ts +33 -0
  19. package/__tests__/utils-format-converter.test.ts +87 -0
  20. package/__tests__/utils-jwt.test.ts +57 -0
  21. package/__tests__/utils-manager-error.test.ts +11 -0
  22. package/__tests__/utils-normalize.test.ts +15 -0
  23. package/__tests__/utils-object-convert.test.ts +38 -0
  24. package/__tests__/utils-string-convert.test.ts +20 -0
  25. package/__tests__/utils-string-utils.test.ts +25 -0
  26. package/__tests__/utils-url.test.ts +21 -0
  27. package/babel.config.cjs +5 -0
  28. package/jest.config.ts +46 -0
  29. package/package.json +36 -0
  30. package/src/AesManager.ts +82 -0
  31. package/src/CryptographyService.ts +461 -0
  32. package/src/JweManager.ts.txt +365 -0
  33. package/src/KmsService.txt +493 -0
  34. package/src/constants/Schemas.ts +61 -0
  35. package/src/constants/index.ts +1 -0
  36. package/src/constants/schemaorg.ts +193 -0
  37. package/src/cryptoDecode.ts +104 -0
  38. package/src/cryptoEncode.ts +36 -0
  39. package/src/cryptography.abstract.ts +29 -0
  40. package/src/hmac.ts +15 -0
  41. package/src/index.ts +3 -0
  42. package/src/interfaces/Cryptography.types.ts +131 -0
  43. package/src/interfaces/ICryptoHelper.ts +33 -0
  44. package/src/interfaces/ICryptography.ts +177 -0
  45. package/src/interfaces/IWallet.ts +62 -0
  46. package/src/interfaces/MlDsa.ts +25 -0
  47. package/src/interfaces/MlKem.ts +18 -0
  48. package/src/models/aes.ts +93 -0
  49. package/src/models/auth.ts +38 -0
  50. package/src/models/bundle.ts +152 -0
  51. package/src/models/bundle.txt +93 -0
  52. package/src/models/clinical-sections.en.ts +82 -0
  53. package/src/models/clinical-sections.ts +64 -0
  54. package/src/models/comm.ts +63 -0
  55. package/src/models/confidential-job.ts +100 -0
  56. package/src/models/confidential-message.ts +137 -0
  57. package/src/models/confidential-storage.ts +170 -0
  58. package/src/models/consent-rule.ts +141 -0
  59. package/src/models/crypto.ts +43 -0
  60. package/src/models/device-license.ts +161 -0
  61. package/src/models/did.ts +81 -0
  62. package/src/models/index.ts +31 -0
  63. package/src/models/indexing.ts +20 -0
  64. package/src/models/issue.ts +85 -0
  65. package/src/models/jsonapi.ts +19 -0
  66. package/src/models/jwe.ts +132 -0
  67. package/src/models/jwk.ts +50 -0
  68. package/src/models/jws.ts +42 -0
  69. package/src/models/jwt.ts +15 -0
  70. package/src/models/multibase58.ts +46 -0
  71. package/src/models/oidc4ida.common.model.ts +39 -0
  72. package/src/models/oidc4ida.document.model.ts +61 -0
  73. package/src/models/oidc4ida.electronicRecord.model.ts +86 -0
  74. package/src/models/oidc4ida.evidence.model.ts +69 -0
  75. package/src/models/openid-device.ts +146 -0
  76. package/src/models/operation-outcome.ts +34 -0
  77. package/src/models/params.ts +142 -0
  78. package/src/models/resource-document.ts +21 -0
  79. package/src/models/response.ts +5 -0
  80. package/src/models/urlPath.ts +76 -0
  81. package/src/models/verifiable-credential.ts +52 -0
  82. package/src/types/noble-hashes.d.ts +4 -0
  83. package/src/utils/actor.ts +52 -0
  84. package/src/utils/base-convert.ts +77 -0
  85. package/src/utils/baseN.ts +203 -0
  86. package/src/utils/bundle.ts +30 -0
  87. package/src/utils/content.ts +66 -0
  88. package/src/utils/did.ts +155 -0
  89. package/src/utils/format-converter.ts +119 -0
  90. package/src/utils/index.ts +13 -0
  91. package/src/utils/jwt.ts +165 -0
  92. package/src/utils/manager-error.ts +27 -0
  93. package/src/utils/multibase58.ts +46 -0
  94. package/src/utils/multibasehash.ts +28 -0
  95. package/src/utils/normalize.ts +43 -0
  96. package/src/utils/object-convert.ts +57 -0
  97. package/src/utils/string-convert.ts +71 -0
  98. package/src/utils/string-utils.ts +70 -0
  99. package/src/utils/url.ts +46 -0
  100. package/tsconfig.json +13 -0
@@ -0,0 +1,141 @@
1
+ // src/models/consent-rule.ts
2
+
3
+ export enum ClaimConsent {
4
+ 'decision' = 'Consent.decision',
5
+ 'action' = 'Consent.action',
6
+ 'category' = 'Consent.category',
7
+ 'subject' = 'Consent.subject',
8
+ 'actorIdentifier' = 'Consent.actor-identifier',
9
+ 'actorRole' = 'Consent.actor-role',
10
+ 'date' = 'Consent.date',
11
+ 'periodStart' = 'Consent.period-start',
12
+ 'periodEnd' = 'Consent.period-end',
13
+ 'grantee' = 'Consent.grantee',
14
+ 'verifiedBy' = 'Consent.verified-by',
15
+ 'verifiedDate' = 'Consent.verified-date',
16
+ 'purpose' = 'Consent.purpose',
17
+ 'identifier' = 'Consent.identifier',
18
+ 'attachmentContentType' = 'Consent.attachment-contentType',
19
+ 'attachmentData' = 'Consent.attachment-data',
20
+ 'attachmentId' = 'Consent.attachment-id',
21
+ }
22
+
23
+ /**
24
+ * Defines the structured, query-optimized format for storing a single, atomic consent rule
25
+ * in the vault (e.g., Firestore, CouchDB).
26
+ *
27
+ * This object is the "Query" model in a CQRS (Command Query Responsibility Segregation) pattern.
28
+ * It is generated by the `ConsentManager` from the "Command" - a set of interoperable claims
29
+ * provided in the `meta.claims` block of an incoming FHIR Consent resource.
30
+ *
31
+ * The backend's authorization engine queries against collections of these objects for high-speed
32
+ * access decisions. The original FHIR Consent resource may be stored separately for auditing.
33
+ *
34
+ * All fields are derived from claims using the reverse-DNS format, e.g., the `decision` field
35
+ * is populated from the `org.hl7.fhir.api.Consent.decision` claim.
36
+ */
37
+ export interface ConsentRule {
38
+ /**
39
+ * JSON-LD context to define the vocabulary for the rule.
40
+ * Value MUST be "org.hl7.fhir.api".
41
+ */
42
+ '@context': 'org.hl7.fhir.api';
43
+
44
+ /**
45
+ * The decision of the rule: permit or deny.
46
+ * Derived from the `org.hl7.fhir.api.Consent.decision` claim.
47
+ */
48
+ 'Consent.decision': 'permit' | 'deny';
49
+
50
+ /**
51
+ * The data sections this rule applies to, as a comma-separated list of coded values.
52
+ * Derived from the `org.hl7.fhir.api.Consent.action` claim.
53
+ * Example claim: "LOINC|48765-2,SNOMED|12345"
54
+ */
55
+ 'Consent.action': string;
56
+
57
+ /**
58
+ * The type of consent document, as a comma-serpareted list of coded values.
59
+ * Used for classifying the consent itself (e.g., for release of information).
60
+ * Derived from the `org.hl7.fhir.api.Consent.category` claim.
61
+ * Example claim: "LOINC|59284-0,LOINC|57016-8"
62
+ */
63
+ 'Consent.category'?: string;
64
+
65
+ /**
66
+ * The subject of the consent.
67
+ * Derived from the `org.hl7.fhir.api.Consent.patient.identifier` claim.
68
+ */
69
+ 'Consent.subject': string;
70
+
71
+ /**
72
+ * The identifier of the actor (jurisdiction, organization, professional) this rule applies to.
73
+ * This is the party whose access is being controlled.
74
+ * Derived from a claim like `org.hl7.fhir.api.Consent.actor.reference.identifier`.
75
+ * e.g., "urn:iso:3166-2:ES-CT", "did:web:hospital.example.com", "urn:email:dr-smith@example.com"
76
+ */
77
+ 'Consent.actor-identifier': string;
78
+
79
+ /**
80
+ * The role of the actor this rule applies to.
81
+ * Derived from a claim like `org.hl7.fhir.api.Consent.actor.role`.
82
+ * e.g., "doctor", "nurse"
83
+ */
84
+ 'Consent.actor-role': string;
85
+
86
+ /**
87
+ * The date the consent was granted (ISO 8601 Date).
88
+ * Derived from the `org.hl7.fhir.api.Consent.date` claim.
89
+ */
90
+ 'Consent.date': string;
91
+
92
+ /**
93
+ * Start of the consent's validity period (ISO 8601 DateTime).
94
+ * Note: This is different from the date the consent was signed.
95
+ * Derived from the start of the `org.hl7.fhir.api.Consent.period` claim.
96
+ */
97
+ 'Consent.period-start'?: string;
98
+
99
+ /**
100
+ * End of the consent's validity period (ISO 8601 DateTime).
101
+ * Derived from the end of the `org.hl7.fhir.api.Consent.period` claim.
102
+ */
103
+ 'Consent.period-end'?: string;
104
+
105
+ /**
106
+ * The party to whom the consent is granted.
107
+ * Use both 'Consent.actor-identifier' and 'Consent.actor-role' instead.
108
+ * Derived from the `org.hl7.fhir.api.Consent.grantee` claim.
109
+ */
110
+ // 'Consent.grantee': string;
111
+
112
+ /**
113
+ * The DID of the entity (person or system) that verified the consent.
114
+ * Derived from the `org.hl7.fhir.api.Consent.verified-by` claim.
115
+ */
116
+ 'Consent.verified-by'?: string;
117
+
118
+ /**
119
+ * The date the consent was verified (ISO 8601 DateTime).
120
+ * Derived from the `org.hl7.fhir.api.Consent.verified-date` claim.
121
+ */
122
+ 'Consent.verified-date'?: string;
123
+
124
+
125
+ /**
126
+ * The purpose of use for this rule.
127
+ * Derived from the `org.hl7.fhir.api.Consent.purpose` claim.
128
+ * e.g., "ETREAT", "CAREMGT"
129
+ */
130
+ 'Consent.purpose': string;
131
+
132
+ /**
133
+ * The original Consent resource ID for auditing.
134
+ * Derived from the `org.hl7.fhir.api.Consent.identifier` claim.
135
+ */
136
+ 'Consent.identifier': string;
137
+
138
+ 'Consent.attachment-contentType'?: string
139
+ 'Consent.attachment-data'?: string
140
+ 'Consent.attachment-id'?: string
141
+ }
@@ -0,0 +1,43 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/models/crypto.ts
3
+
4
+ import { PublicJwk } from "../interfaces/Cryptography.types";
5
+
6
+ /**
7
+ * Describes a public key and its controller, for use in JWE recipients or DID documents.
8
+ * @see https://w3c-ccg.github.io/ld-cryptosuite-registry/
9
+ */
10
+ export interface RecipientPublicKey {
11
+ type: string; // "JsonWebKey2020";
12
+ controller?: string; // DID of the key controller
13
+ publicKeyJwk: PublicJwk;
14
+ nbf?: number; // Not Before timestamp
15
+ exp?: number; // Expiration timestamp
16
+ }
17
+
18
+ /**
19
+ * Represents a full cryptographic key pair, including the private key material.
20
+ * This format is for internal use by the KMS and should never be exposed.
21
+ */
22
+ export interface KeyPair extends RecipientPublicKey {
23
+ /** The raw private key bytes. This MUST be protected at rest (encrypted). */
24
+ privateKeyBytes: Uint8Array;
25
+ }
26
+
27
+ /**
28
+
29
+ * Contains all cryptographic material for a single tenant, managed by the Gateway Service.
30
+ * This object is what would be encrypted and stored in a tenant's vault.
31
+ */
32
+ export interface TenantCryptoData {
33
+ /** A cache of public keys of recipients this tenant frequently interacts with. */
34
+ recipients: RecipientPublicKey[];
35
+ /** A protected PIN/Password used to derive a key for local cryptographic operations. */
36
+ passKey: Uint8Array;
37
+ /** The history of encryption key pairs used by the tenant (for key rotation). The last one is the current key. */
38
+ keyAgreement: KeyPair[];
39
+ /** The history of signature key pairs used by the tenant (for key rotation). The last one is the current key. */
40
+ verificationMethod: KeyPair[];
41
+ }
42
+
43
+
@@ -0,0 +1,161 @@
1
+ // src/models/device-license.ts
2
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
3
+
4
+ /**
5
+ * A fingerprint of a specific device, used for binding a license to it.
6
+ */
7
+ export interface DeviceInfo {
8
+ /**
9
+ * A stable, unique identifier for the specific app installation, generated by the client.
10
+ * This is the primary key for device binding.
11
+ */
12
+ clientInstanceId: string;
13
+
14
+ /** The operating system of the device (e.g., "iOS", "Android", "Windows"). */
15
+ os?: string;
16
+
17
+ /** The specific OS version. */
18
+ osVersion?: string;
19
+
20
+ /** The manufacturer of the device (e.g., "Apple", "Samsung"). */
21
+ manufacturer?: string;
22
+
23
+ /** The model of the device (e.g., "iPhone14,6"). */
24
+ model?: string;
25
+ }
26
+
27
+ /**
28
+ * A set of rules that a device must match to be eligible to activate a license.
29
+ */
30
+ export interface DeviceRestrictions {
31
+ /** A regex pattern for the allowed manufacturer(s). */
32
+ manufacturer?: string;
33
+
34
+ /** A regex pattern for the allowed model(s). */
35
+ model?: string;
36
+ }
37
+
38
+ /**
39
+ * Represents a single device activation license, enabling a user to register a specific device
40
+ * for a tenant's service. It governs access based on user class, platform, and subscription terms.
41
+ * Timestamps are stored as Unix epoch seconds (numeric).
42
+ * All property names follow the camelCase convention.
43
+ */
44
+ export interface DeviceLicense {
45
+ /**
46
+ * The unique identifier for this license document in the vault.
47
+ */
48
+ id: string;
49
+
50
+ /**
51
+ * The logical identifier of the tenant organization that owns this license.
52
+ * @example "acme"
53
+ */
54
+ tenantId: string;
55
+
56
+ /**
57
+ * Identifier for the purchase order or invoice that generated this license.
58
+ * All licenses created from the same purchase will share the same orderId.
59
+ * @example "inv_12345"
60
+ */
61
+ orderId: string;
62
+
63
+ /**
64
+ * A secure, single-use code given to a user to activate a device.
65
+ * This is generated when the license status becomes 'issued'.
66
+ */
67
+ activationCode?: string;
68
+
69
+ /**
70
+ * **CRITICAL:** Defines the class of user this license is intended for.
71
+ * This allows for stratified licensing (e.g., selling "professional seats"
72
+ * separately from "individual access").
73
+ */
74
+ userClass: 'employee' | 'individual';
75
+
76
+ /**
77
+ * **Specifies the functional category for an 'employee' license.**
78
+ * This determines the set of roles the user is permitted to have.
79
+ * This field MUST be present if userClass is 'employee'.
80
+ * It is typically undefined for 'individual' licenses.
81
+ * @example "medicalStaff", "firstResponder", "admin"
82
+ */
83
+ userCategory?: string;
84
+
85
+
86
+ /**
87
+ * Defines the platform this license is for.
88
+ */
89
+ type: 'mobile' | 'web';
90
+
91
+ /**
92
+ * The current lifecycle status of the license.
93
+ * - 'available': Fresh license, ready to be assigned to a user.
94
+ * - 'issued': Assigned to a user and an activation code has been generated.
95
+ * - 'active': The user has successfully used the activation code to register a device.
96
+ * - 'inactive': Deactivated by an administrator or user, or has expired.
97
+ */
98
+ status: 'available' | 'issued' | 'active' | 'inactive';
99
+
100
+ /**
101
+ * The subscription or purchase plan associated with this license.
102
+ * @example "premium_annual" | "standard_monthly" | "trial"
103
+ */
104
+ plan: string;
105
+
106
+ /**
107
+ * Defines the renewal period for the license.
108
+ * '1m' for one month, '12m' for one year.
109
+ * A null value indicates the license does not auto-renew.
110
+ */
111
+ renewalCycle: '1m' | '12m' | null;
112
+
113
+ /**
114
+ * If true, the license can be reactivated after being made inactive
115
+ * (e.g., after a user clicks "Log out everywhere"). If false, an inactive
116
+ * license cannot be used again.
117
+ */
118
+ reactivationEnabled: boolean;
119
+
120
+ /**
121
+ * "Issued At" timestamp. The time the license was assigned to a user, as a Unix epoch in seconds.
122
+ * Set when status moves to 'issued'.
123
+ */
124
+ issuedAt?: number;
125
+
126
+ /**
127
+ * "Activation Time" timestamp. The time the license was successfully used to register a device,
128
+ * as a Unix epoch in seconds. Set when status moves to 'active'.
129
+ */
130
+ activatedAt?: number;
131
+
132
+ /**
133
+ * "Expiration Time" timestamp. The time at which the license and the device's authorization
134
+ * expire, as a Unix epoch in seconds.
135
+ */
136
+ exp: number;
137
+
138
+ /**
139
+ * The unique identifier of the user (e.g., employeeId or customerId) to whom the license is issued.
140
+ * Populated when the status becomes 'issued'.
141
+ */
142
+ subjectId?: string;
143
+
144
+ /**
145
+ * The unique identifier (`client_id`) of the device registered with this license.
146
+ * Populated when the status becomes 'active'.
147
+ */
148
+ deviceId?: string;
149
+
150
+ /**
151
+ * Optional, pre-defined restrictions on which devices are allowed to activate this license.
152
+ * Set at the time of license creation.
153
+ */
154
+ deviceRestrictions?: DeviceRestrictions;
155
+
156
+ /**
157
+ * A fingerprint of the device that successfully activated this license.
158
+ * This is captured upon activation and is used to lock the license to that specific device.
159
+ */
160
+ deviceInfo?: DeviceInfo;
161
+ }
@@ -0,0 +1,81 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/models/did.ts
3
+
4
+ import { PublicJwk } from "../interfaces/Cryptography.types";
5
+ import { RecipientPublicKey } from "./crypto";
6
+
7
+ /**
8
+ * The parameters required to construct a service endpoint selector.
9
+ * This is the contract for a specific API method to define its endpoint.
10
+ */
11
+ export interface ServiceEndpointSelector {
12
+ /** When the organization has its own domain for the connector the apiVersion and sector do not appear in the path */
13
+ apiVersion?: string;
14
+ sector?: string;
15
+ /** Corresponds to <sectionTypeOrCompartmentCodingSystem> */
16
+ section: string; // entity, individual, ...
17
+ /** Corresponds to <formatTypeOrCompartmentCodingValue> */
18
+ format: string;
19
+ resourceType: string;
20
+ action: string;
21
+ }
22
+
23
+ /**
24
+ * Extends the base selector with authorization information.
25
+ * This is used for endpoints that are not public and require a SMART token.
26
+ */
27
+ export interface SecureServiceEndpointSelector extends ServiceEndpointSelector {
28
+ requiredScope: string; // The OAuth/SMART scope needed to call this endpoint
29
+ }
30
+
31
+ /**
32
+ * Represents a service endpoint in a DID Document.
33
+ * @see https://www.w3.org/TR/did-core/#service-endpoints
34
+ */
35
+ export interface DidService {
36
+ id: string;
37
+ type: string;
38
+ serviceEndpoint: string;
39
+ [key: string]: any; // Allow for additional properties
40
+ }
41
+
42
+ /**
43
+ * Represents a DID Document, compliant with the W3C DID Core specification.
44
+ * It describes how to use a DID, including verification methods and service endpoints.
45
+ * @see https://www.w3.org/TR/did-core/
46
+ */
47
+ export interface DidDocument {
48
+ /** The DID context, typically "https://www.w3.org/ns/did/v1". */
49
+ '@context': string | string[];
50
+ /** The DID URI itself. */
51
+ id: string;
52
+ /** Public keys used for verifying digital signatures */
53
+ verificationMethod?: VerificationMethod[];
54
+ /**
55
+ * Specifies verification methods for making claims. Can be embedded or a string referencing a `verificationMethod`.
56
+ * @see https://www.w3.org/TR/did-core/#assertion
57
+ */
58
+ assertionMethod?: (string | VerificationMethod)[];
59
+ /**
60
+ * Specifies methods for authentication. Can be embedded or a string referencing a `verificationMethod`.
61
+ * @see https://www.w3.org/TR/did-core/#authentication
62
+ */
63
+ authentication?: (string | VerificationMethod)[];
64
+ /**
65
+ * Specifies methods for key agreement. Can be embedded or a string referencing a `verificationMethod`.
66
+ * @see https://www.w3.org/TR/did-core/#key-agreement
67
+ */
68
+ keyAgreement?: (string | VerificationMethod)[];
69
+ /** Service endpoints for interacting with the entity */
70
+ service?: DidService[];
71
+ /** Other properties are allowed. */
72
+ [key: string]: any;
73
+ }
74
+
75
+ // En src/models/did.ts (o donde esté RecipientPublicKey/VerificationMethod)
76
+ export interface VerificationMethod extends RecipientPublicKey {
77
+ id: string; // e.g., did:web:example.com#key-1
78
+ type: string; // e.g., JsonWebKey2020
79
+ controller: string; // e.g., did:web:example.com
80
+ publicKeyJwk: PublicJwk;
81
+ }
@@ -0,0 +1,31 @@
1
+ export * from './aes';
2
+ export * from './auth';
3
+ export * from './bundle';
4
+ export * from './comm';
5
+ export * from './clinical-sections';
6
+ export * from './clinical-sections.en';
7
+ export * from './confidential-job';
8
+ export * from './confidential-message';
9
+ export * from './confidential-storage';
10
+ export * from './consent-rule';
11
+ export * from './crypto';
12
+ export * from './device-license';
13
+ export * from './did';
14
+ export * from './indexing';
15
+ export * from './issue';
16
+ export * from './jsonapi';
17
+ export * from './jwe';
18
+ export * from './jwk';
19
+ export * from './jws';
20
+ export * from './jwt';
21
+ export * from './oidc4ida.common.model';
22
+ export * from './oidc4ida.document.model';
23
+ export * from './oidc4ida.electronicRecord.model';
24
+ export * from './oidc4ida.evidence.model';
25
+ export * from './openid-device';
26
+ export * from './operation-outcome';
27
+ export * from './params';
28
+ export * from './resource-document';
29
+ export * from './response';
30
+ export * from './urlPath';
31
+ export * from './verifiable-credential';
@@ -0,0 +1,20 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: src/models/indexing.ts
3
+
4
+ import { ClaimsOrganizationSchemaorg } from "../constants/schemaorg";
5
+
6
+ /**
7
+ * Defines which claims are allowed to be indexed for different resource types.
8
+ * This provides a single, strongly-typed source of truth for indexing strategies.
9
+ */
10
+ export const AllowedIndexableClaims = {
11
+ /**
12
+ * Defines the claims that can be indexed in the central tenant registry for an Organization.
13
+ */
14
+ organizationRegistry: [
15
+ ClaimsOrganizationSchemaorg.alternateName,
16
+ ClaimsOrganizationSchemaorg.identifierValue,
17
+ ClaimsOrganizationSchemaorg.identifierType,
18
+ ClaimsOrganizationSchemaorg.addressCountry,
19
+ ] as const, // Use 'as const' to provide strong typing for the array elements
20
+ };
@@ -0,0 +1,85 @@
1
+ // src/models/issue.ts
2
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
3
+ // Source: https://www.hl7.org/fhir/valueset-issue-severity.html
4
+
5
+ /**
6
+ * Defines the level of an issue.
7
+ */
8
+ export enum IssueLevel {
9
+ /** The issue is fatal and the system is in an unstable state. */
10
+ Fatal = 'fatal',
11
+ /** The issue is an error that prevents the action from completing. */
12
+ Error = 'error',
13
+ /** The issue is a warning that does not prevent the action from completing. */
14
+ Warning = 'warning',
15
+ /** The issue is informational and requires no action. */
16
+ Information = 'information',
17
+ }
18
+
19
+ // Source: https://www.hl7.org/fhir/valueset-issue-type.html
20
+ /**
21
+ * Defines the code for the type of issue.
22
+ * This is a subset of the full FHIR value set, focused on common API scenarios.
23
+ */
24
+ export const IssueType = {
25
+ // --- Category: Invalid Content ---
26
+ /** Content invalid against the specification. */
27
+ Invalid: 'invalid',
28
+ /** A required element is missing. */
29
+ Required: 'required',
30
+ /** An element value is invalid. */
31
+ Value: 'value',
32
+ /** A business rule has been violated. */
33
+ BusinessRule: 'business-rule',
34
+
35
+ // --- Category: Security ---
36
+ /** An authentication/authorization error has occurred. */
37
+ Login: 'login',
38
+ /** The user is not authorized for the requested action. */
39
+ Forbidden: 'forbidden',
40
+ /** A security-related issue has been detected. */
41
+ Security: 'security',
42
+
43
+ // --- Category: Processing ---
44
+ /** The resource was not found. */
45
+ NotFound: 'not-found',
46
+ /** The operation led to a conflict. */
47
+ Conflict: 'conflict',
48
+ /** A duplicate record was detected. */
49
+ Duplicate: 'duplicate',
50
+ /** The operation is not supported. */
51
+ NotSupported: 'not-supported',
52
+ /** An internal processing exception occurred. */
53
+ Exception: 'exception',
54
+ /** The operation has timed out. */
55
+ Timeout: 'timeout',
56
+ /** The operation was throttled. */
57
+ Throttled: 'throttled',
58
+ } as const;
59
+
60
+ /**
61
+ * A union type derived from the keys of the IssueType object.
62
+ * This ensures that only defined issue type codes can be used.
63
+ */
64
+ export type IssueTypeCode = typeof IssueType[keyof typeof IssueType];
65
+
66
+ /**
67
+ * Maps our internal IssueType codes to the appropriate HTTP status code strings.
68
+ * This provides a single source of truth for error responses.
69
+ */
70
+ export const IssueTypeToHttpStatus: Record<IssueTypeCode, string> = {
71
+ [IssueType.Invalid]: '400',
72
+ [IssueType.Required]: '400',
73
+ [IssueType.Value]: '400',
74
+ [IssueType.BusinessRule]: '400',
75
+ [IssueType.Login]: '401',
76
+ [IssueType.Forbidden]: '403',
77
+ [IssueType.Security]: '403',
78
+ [IssueType.NotFound]: '404',
79
+ [IssueType.Conflict]: '409',
80
+ [IssueType.Duplicate]: '409',
81
+ [IssueType.NotSupported]: '501',
82
+ [IssueType.Exception]: '500',
83
+ [IssueType.Timeout]: '503',
84
+ [IssueType.Throttled]: '429',
85
+ };
@@ -0,0 +1,19 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: src/models/jsonapi.ts
3
+
4
+ import { RecordBase } from "./resource-document";
5
+
6
+ /**
7
+ * Represents a resource object in a JSON:API 'included' array.
8
+ * The type is made "open" with an index signature to allow for additional properties.
9
+ */
10
+ export interface IncludedResource extends RecordBase {
11
+ // 'id' is inherited from RecordBase
12
+ type: string;
13
+ meta: {
14
+ claims: Record<string, any>; // The worker will create always claims (even if empty)
15
+ [key: string]: any; // Make meta open
16
+ };
17
+ [key: string]: any; // Make the top-level resource open
18
+ }
19
+