vet-data-utils-ts 0.5.4 → 0.5.6

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.
@@ -13,6 +13,48 @@ export declare const VeterinaryFinancialResourceTypes: Readonly<{
13
13
  readonly PaymentReconciliation: "PaymentReconciliation";
14
14
  }>;
15
15
  export type VeterinaryFinancialResourceType = typeof VeterinaryFinancialResourceTypes[keyof typeof VeterinaryFinancialResourceTypes];
16
+ /** Governed FHIR R5 claim names used by payment reconciliation builders. */
17
+ export declare const VeterinaryPaymentClaimNames: Readonly<{
18
+ readonly Invoice: Readonly<{
19
+ Identifier: "Invoice.identifier";
20
+ Status: "Invoice.status";
21
+ Recipient: "Invoice.recipient";
22
+ Creation: "Invoice.creation";
23
+ TotalGross: "Invoice.total-gross";
24
+ }>;
25
+ readonly PaymentNotice: Readonly<{
26
+ Identifier: "PaymentNotice.identifier";
27
+ Status: "PaymentNotice.status";
28
+ Request: "PaymentNotice.request";
29
+ Created: "PaymentNotice.created";
30
+ Payment: "PaymentNotice.payment";
31
+ PaymentDate: "PaymentNotice.payment-date";
32
+ Recipient: "PaymentNotice.recipient";
33
+ Amount: "PaymentNotice.amount";
34
+ }>;
35
+ readonly PaymentReconciliation: Readonly<{
36
+ Identifier: "PaymentReconciliation.identifier";
37
+ Type: "PaymentReconciliation.type";
38
+ Status: "PaymentReconciliation.status";
39
+ Created: "PaymentReconciliation.created";
40
+ Outcome: "PaymentReconciliation.outcome";
41
+ Date: "PaymentReconciliation.date";
42
+ ReferenceNumber: "PaymentReconciliation.reference-number";
43
+ Amount: "PaymentReconciliation.amount";
44
+ PaymentIdentifier: "PaymentReconciliation.payment-identifier";
45
+ AllocationTarget: "PaymentReconciliation.allocation-target";
46
+ AllocationAmount: "PaymentReconciliation.allocation-amount";
47
+ }>;
48
+ }>;
49
+ export declare const FhirR5FinancialStatusCodes: Readonly<{
50
+ readonly Active: "active";
51
+ readonly InvoiceIssued: "issued";
52
+ readonly ReconciliationComplete: "complete";
53
+ }>;
54
+ export declare const FhirR5PaymentType: Readonly<{
55
+ readonly system: "http://terminology.hl7.org/CodeSystem/payment-type";
56
+ readonly code: "payment";
57
+ }>;
16
58
  /** Canonical claim allow-list used before a native FHIR resource is indexed. */
17
59
  export declare const VeterinaryFinancialClaimCatalog: Readonly<{
18
60
  Account: readonly ["Account.identifier", "Account.status", "Account.billing-status", "Account.type", "Account.name", "Account.subject", "Account.service-period", "Account.coverage-coverage", "Account.coverage-priority", "Account.owner", "Account.description", "Account.guarantor-party", "Account.guarantor-on-hold", "Account.guarantor-period", "Account.diagnosis-sequence", "Account.diagnosis-condition", "Account.diagnosis-date", "Account.diagnosis-type", "Account.diagnosis-on-admission", "Account.diagnosis-package-code", "Account.procedure-sequence", "Account.procedure-code", "Account.procedure-date-of-service", "Account.procedure-type", "Account.procedure-package-code", "Account.procedure-device", "Account.related-account-account", "Account.related-account-relationship", "Account.currency", "Account.balance-aggregate", "Account.balance-term", "Account.balance-estimate", "Account.balance-amount", "Account.calculated-at"];
@@ -24,3 +66,25 @@ export declare const VeterinaryFinancialClaimCatalog: Readonly<{
24
66
  export declare function getVeterinaryFinancialClaims(resourceType: unknown): readonly string[];
25
67
  /** Checks both the resource family and its claim prefix/allow-list. */
26
68
  export declare function isVeterinaryFinancialClaim(resourceType: unknown, claim: unknown): boolean;
69
+ export type ClaimsFirstFinancialResource<T extends VeterinaryFinancialResourceType> = Readonly<{
70
+ resourceType: T;
71
+ id: string;
72
+ meta: Readonly<{
73
+ claims: Readonly<Record<string, unknown>>;
74
+ }>;
75
+ }>;
76
+ /**
77
+ * Projects verified provider evidence into standard FHIR R5 financial claims.
78
+ * Provider references use existing FHIR elements and never extend the catalog.
79
+ */
80
+ export type EvmTransferFinancialReconciliation = Readonly<{
81
+ invoice: ClaimsFirstFinancialResource<'Invoice'>;
82
+ paymentNotice: ClaimsFirstFinancialResource<'PaymentNotice'>;
83
+ paymentReconciliation: ClaimsFirstFinancialResource<'PaymentReconciliation'>;
84
+ }>;
85
+ export declare function buildEvmTransferFinancialReconciliation(input: Readonly<{
86
+ quote: import('./payment.js').EvmTransferPaymentQuote;
87
+ transactionHash: `0x${string}`;
88
+ verifiedAt: string;
89
+ recipientReference: string;
90
+ }>): EvmTransferFinancialReconciliation;
package/dist/financial.js CHANGED
@@ -12,6 +12,33 @@ export const VeterinaryFinancialResourceTypes = Object.freeze({
12
12
  PaymentNotice: 'PaymentNotice',
13
13
  PaymentReconciliation: 'PaymentReconciliation',
14
14
  });
15
+ /** Governed FHIR R5 claim names used by payment reconciliation builders. */
16
+ export const VeterinaryPaymentClaimNames = Object.freeze({
17
+ Invoice: Object.freeze({
18
+ Identifier: 'Invoice.identifier', Status: 'Invoice.status', Recipient: 'Invoice.recipient',
19
+ Creation: 'Invoice.creation', TotalGross: 'Invoice.total-gross',
20
+ }),
21
+ PaymentNotice: Object.freeze({
22
+ Identifier: 'PaymentNotice.identifier', Status: 'PaymentNotice.status', Request: 'PaymentNotice.request',
23
+ Created: 'PaymentNotice.created', Payment: 'PaymentNotice.payment', PaymentDate: 'PaymentNotice.payment-date',
24
+ Recipient: 'PaymentNotice.recipient', Amount: 'PaymentNotice.amount',
25
+ }),
26
+ PaymentReconciliation: Object.freeze({
27
+ Identifier: 'PaymentReconciliation.identifier', Type: 'PaymentReconciliation.type',
28
+ Status: 'PaymentReconciliation.status', Created: 'PaymentReconciliation.created',
29
+ Outcome: 'PaymentReconciliation.outcome', Date: 'PaymentReconciliation.date',
30
+ ReferenceNumber: 'PaymentReconciliation.reference-number', Amount: 'PaymentReconciliation.amount',
31
+ PaymentIdentifier: 'PaymentReconciliation.payment-identifier',
32
+ AllocationTarget: 'PaymentReconciliation.allocation-target',
33
+ AllocationAmount: 'PaymentReconciliation.allocation-amount',
34
+ }),
35
+ });
36
+ export const FhirR5FinancialStatusCodes = Object.freeze({
37
+ Active: 'active', InvoiceIssued: 'issued', ReconciliationComplete: 'complete',
38
+ });
39
+ export const FhirR5PaymentType = Object.freeze({
40
+ system: 'http://terminology.hl7.org/CodeSystem/payment-type', code: 'payment',
41
+ });
15
42
  const accountClaims = Object.freeze([
16
43
  'Account.identifier',
17
44
  'Account.status',
@@ -160,3 +187,59 @@ export function isVeterinaryFinancialClaim(resourceType, claim) {
160
187
  function isVeterinaryFinancialResourceType(value) {
161
188
  return Object.values(VeterinaryFinancialResourceTypes).includes(value);
162
189
  }
190
+ function usdcMoney(amountMinor) {
191
+ const padded = amountMinor.padStart(7, '0');
192
+ const split = padded.length - 6;
193
+ return { value: `${padded.slice(0, split)}.${padded.slice(split)}`, currency: 'USD' };
194
+ }
195
+ export function buildEvmTransferFinancialReconciliation(input) {
196
+ const paymentNoticeId = input.quote.paymentReference;
197
+ const paymentReconciliationId = input.quote.paymentReference;
198
+ const invoiceReference = `Invoice/${input.quote.invoiceId}`;
199
+ const reconciliationReference = `PaymentReconciliation/${paymentReconciliationId}`;
200
+ const money = usdcMoney(input.quote.amountMinor);
201
+ return {
202
+ invoice: {
203
+ resourceType: VeterinaryFinancialResourceTypes.Invoice,
204
+ id: input.quote.invoiceId,
205
+ meta: { claims: {
206
+ [VeterinaryPaymentClaimNames.Invoice.Identifier]: input.quote.paymentReference,
207
+ [VeterinaryPaymentClaimNames.Invoice.Status]: FhirR5FinancialStatusCodes.InvoiceIssued,
208
+ [VeterinaryPaymentClaimNames.Invoice.Recipient]: input.recipientReference,
209
+ [VeterinaryPaymentClaimNames.Invoice.Creation]: input.quote.createdAt,
210
+ [VeterinaryPaymentClaimNames.Invoice.TotalGross]: money,
211
+ } },
212
+ },
213
+ paymentNotice: {
214
+ resourceType: VeterinaryFinancialResourceTypes.PaymentNotice,
215
+ id: paymentNoticeId,
216
+ meta: { claims: {
217
+ [VeterinaryPaymentClaimNames.PaymentNotice.Identifier]: input.quote.paymentReference,
218
+ [VeterinaryPaymentClaimNames.PaymentNotice.Status]: FhirR5FinancialStatusCodes.Active,
219
+ [VeterinaryPaymentClaimNames.PaymentNotice.Request]: invoiceReference,
220
+ [VeterinaryPaymentClaimNames.PaymentNotice.Created]: input.verifiedAt,
221
+ [VeterinaryPaymentClaimNames.PaymentNotice.Payment]: reconciliationReference,
222
+ [VeterinaryPaymentClaimNames.PaymentNotice.PaymentDate]: input.verifiedAt.slice(0, 10),
223
+ [VeterinaryPaymentClaimNames.PaymentNotice.Recipient]: input.recipientReference,
224
+ [VeterinaryPaymentClaimNames.PaymentNotice.Amount]: money,
225
+ } },
226
+ },
227
+ paymentReconciliation: {
228
+ resourceType: VeterinaryFinancialResourceTypes.PaymentReconciliation,
229
+ id: paymentReconciliationId,
230
+ meta: { claims: {
231
+ [VeterinaryPaymentClaimNames.PaymentReconciliation.Identifier]: input.quote.paymentReference,
232
+ [VeterinaryPaymentClaimNames.PaymentReconciliation.Type]: { coding: [FhirR5PaymentType] },
233
+ [VeterinaryPaymentClaimNames.PaymentReconciliation.Status]: FhirR5FinancialStatusCodes.Active,
234
+ [VeterinaryPaymentClaimNames.PaymentReconciliation.Created]: input.verifiedAt,
235
+ [VeterinaryPaymentClaimNames.PaymentReconciliation.Outcome]: FhirR5FinancialStatusCodes.ReconciliationComplete,
236
+ [VeterinaryPaymentClaimNames.PaymentReconciliation.Date]: input.verifiedAt.slice(0, 10),
237
+ [VeterinaryPaymentClaimNames.PaymentReconciliation.ReferenceNumber]: input.transactionHash,
238
+ [VeterinaryPaymentClaimNames.PaymentReconciliation.Amount]: money,
239
+ [VeterinaryPaymentClaimNames.PaymentReconciliation.PaymentIdentifier]: input.quote.paymentReference,
240
+ [VeterinaryPaymentClaimNames.PaymentReconciliation.AllocationTarget]: invoiceReference,
241
+ [VeterinaryPaymentClaimNames.PaymentReconciliation.AllocationAmount]: money,
242
+ } },
243
+ },
244
+ };
245
+ }
package/dist/payment.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /** Provider and asset identifiers for VetChain payment adapters. */
2
2
  export declare const PaymentProviderIds: Readonly<{
3
3
  readonly Stripe: "STRIPE";
4
- readonly UsdcEvm: "USDC_EVM";
4
+ readonly EvmTransfer: "EVM_TRANSFER";
5
5
  }>;
6
6
  export declare const PaymentAssetIds: Readonly<{
7
7
  readonly Usdc: "USDC";
@@ -15,7 +15,7 @@ export declare const PaymentFlowActions: Readonly<{
15
15
  readonly Confirm: "confirm";
16
16
  }>;
17
17
  export type PaymentFlowAction = typeof PaymentFlowActions[keyof typeof PaymentFlowActions];
18
- export type UsdcPaymentConfirmation = Readonly<{
18
+ export type EvmTransferPaymentConfirmation = Readonly<{
19
19
  offerId: string;
20
20
  transactionHash: `0x${string}`;
21
21
  }>;
@@ -26,10 +26,11 @@ export declare const EvmPaymentNetworkIds: Readonly<{
26
26
  }>;
27
27
  export type PaymentProviderId = typeof PaymentProviderIds[keyof typeof PaymentProviderIds];
28
28
  export type EvmPaymentNetworkId = typeof EvmPaymentNetworkIds[keyof typeof EvmPaymentNetworkIds];
29
- export type UsdcEvmNetwork = Readonly<{
29
+ export type EvmTransferNetwork = Readonly<{
30
30
  id: EvmPaymentNetworkId;
31
31
  chainId: number;
32
- usdcContract: `0x${string}`;
32
+ asset: typeof PaymentAssetIds.Usdc;
33
+ tokenContract: `0x${string}`;
33
34
  mainnet: boolean;
34
35
  }>;
35
36
  /** Circle-issued native USDC contracts for Base. */
@@ -37,28 +38,34 @@ export declare const USDC_BASE_NETWORKS: Readonly<{
37
38
  "base-sepolia": Readonly<{
38
39
  id: "base-sepolia";
39
40
  chainId: 84532;
40
- usdcContract: "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
41
+ asset: "USDC";
42
+ tokenContract: "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
41
43
  mainnet: false;
42
44
  }>;
43
45
  "base-mainnet": Readonly<{
44
46
  id: "base-mainnet";
45
47
  chainId: 8453;
46
- usdcContract: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
48
+ asset: "USDC";
49
+ tokenContract: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
47
50
  mainnet: true;
48
51
  }>;
49
52
  }>;
50
- export type UsdcPaymentQuote = Readonly<{
53
+ export type EvmTransferPaymentQuote = Readonly<{
51
54
  version: 1;
52
- provider: typeof PaymentProviderIds.UsdcEvm;
55
+ provider: typeof PaymentProviderIds.EvmTransfer;
56
+ asset: typeof PaymentAssetIds.Usdc;
53
57
  paymentReference: string;
54
58
  invoiceId: string;
59
+ offerId: string;
55
60
  network: EvmPaymentNetworkId;
56
61
  chainId: number;
57
62
  tokenContract: `0x${string}`;
58
63
  recipient: `0x${string}`;
59
64
  amountMinor: string;
60
65
  decimals: typeof USDC_DECIMALS;
66
+ createdAt: string;
61
67
  expiresAt: string;
68
+ expectedPayer?: `0x${string}`;
62
69
  }>;
63
70
  /** Reusable deterministic values for package, GW, BFF and browser tests. */
64
71
  export declare const VET_PAYMENT_TEST_DATA: Readonly<{
@@ -69,6 +76,7 @@ export declare const VET_PAYMENT_TEST_DATA: Readonly<{
69
76
  readonly localUsdcContract: "0x5FbDB2315678afecb367f032d93F642f64180aa3";
70
77
  readonly localRpcUrl: "http://127.0.0.1:3270";
71
78
  readonly transactionHash: `0x${string}`;
79
+ readonly otherTransactionHash: `0x${string}`;
72
80
  readonly amountMinor: 10000000n;
73
81
  readonly amountMinorText: "10000000";
74
82
  readonly zeroPriceText: "0";
@@ -85,9 +93,30 @@ export declare const VET_PAYMENT_TEST_DATA: Readonly<{
85
93
  readonly localPurchaseQuantity: 3;
86
94
  readonly paymentReference: "pay_test_01";
87
95
  readonly invoiceId: "invoice_test_01";
96
+ readonly offerId: "offer_test_01";
97
+ readonly ownerId: "payment_owner_test_01";
98
+ readonly profileId: "payment_profile_test_01";
99
+ readonly recipientOrganizationReference: "Organization/payment-recipient-test";
88
100
  readonly validAt: "2026-09-07T12:00:00.000Z";
89
101
  readonly expiresAt: "2026-09-07T12:10:00.000Z";
90
102
  readonly expiredAt: "2026-09-07T12:11:00.000Z";
103
+ readonly quote: Readonly<{
104
+ version: 1;
105
+ provider: "EVM_TRANSFER";
106
+ asset: "USDC";
107
+ paymentReference: string;
108
+ invoiceId: string;
109
+ offerId: string;
110
+ network: "local-anvil";
111
+ chainId: number;
112
+ tokenContract: "0x5FbDB2315678afecb367f032d93F642f64180aa3";
113
+ recipient: "0x1111111111111111111111111111111111111111";
114
+ amountMinor: string;
115
+ decimals: 6;
116
+ createdAt: string;
117
+ expiresAt: string;
118
+ expectedPayer: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
119
+ }>;
91
120
  }>;
92
121
  export declare function usdOfferToUsdcMinor(input: Readonly<{
93
122
  price: unknown;
package/dist/payment.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /** Provider and asset identifiers for VetChain payment adapters. */
2
2
  export const PaymentProviderIds = Object.freeze({
3
3
  Stripe: 'STRIPE',
4
- UsdcEvm: 'USDC_EVM',
4
+ EvmTransfer: 'EVM_TRANSFER',
5
5
  });
6
6
  export const PaymentAssetIds = Object.freeze({ Usdc: 'USDC' });
7
7
  export const PaymentCurrencyCodes = Object.freeze({ Usd: 'USD' });
@@ -20,13 +20,15 @@ export const USDC_BASE_NETWORKS = Object.freeze({
20
20
  [EvmPaymentNetworkIds.BaseSepolia]: Object.freeze({
21
21
  id: EvmPaymentNetworkIds.BaseSepolia,
22
22
  chainId: 84532,
23
- usdcContract: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
23
+ asset: PaymentAssetIds.Usdc,
24
+ tokenContract: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
24
25
  mainnet: false,
25
26
  }),
26
27
  [EvmPaymentNetworkIds.BaseMainnet]: Object.freeze({
27
28
  id: EvmPaymentNetworkIds.BaseMainnet,
28
29
  chainId: 8453,
29
- usdcContract: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
30
+ asset: PaymentAssetIds.Usdc,
31
+ tokenContract: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
30
32
  mainnet: true,
31
33
  }),
32
34
  });
@@ -39,6 +41,7 @@ export const VET_PAYMENT_TEST_DATA = Object.freeze({
39
41
  localUsdcContract: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
40
42
  localRpcUrl: 'http://127.0.0.1:3270',
41
43
  transactionHash: `0x${'a'.repeat(64)}`,
44
+ otherTransactionHash: `0x${'b'.repeat(64)}`,
42
45
  amountMinor: 10000000n,
43
46
  amountMinorText: '10000000',
44
47
  zeroPriceText: '0',
@@ -55,9 +58,30 @@ export const VET_PAYMENT_TEST_DATA = Object.freeze({
55
58
  localPurchaseQuantity: 3,
56
59
  paymentReference: 'pay_test_01',
57
60
  invoiceId: 'invoice_test_01',
61
+ offerId: 'offer_test_01',
62
+ ownerId: 'payment_owner_test_01',
63
+ profileId: 'payment_profile_test_01',
64
+ recipientOrganizationReference: 'Organization/payment-recipient-test',
58
65
  validAt: '2026-09-07T12:00:00.000Z',
59
66
  expiresAt: '2026-09-07T12:10:00.000Z',
60
67
  expiredAt: '2026-09-07T12:11:00.000Z',
68
+ quote: Object.freeze({
69
+ version: 1,
70
+ provider: PaymentProviderIds.EvmTransfer,
71
+ asset: PaymentAssetIds.Usdc,
72
+ paymentReference: 'pay_test_01',
73
+ invoiceId: 'invoice_test_01',
74
+ offerId: 'offer_test_01',
75
+ network: EvmPaymentNetworkIds.LocalAnvil,
76
+ chainId: 31337,
77
+ tokenContract: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
78
+ recipient: '0x1111111111111111111111111111111111111111',
79
+ amountMinor: '10000000',
80
+ decimals: USDC_DECIMALS,
81
+ createdAt: '2026-09-07T12:00:00.000Z',
82
+ expiresAt: '2026-09-07T12:10:00.000Z',
83
+ expectedPayer: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
84
+ }),
61
85
  });
62
86
  export function usdOfferToUsdcMinor(input) {
63
87
  if (String(input.priceCurrency || '').trim().toUpperCase() !== PaymentCurrencyCodes.Usd) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vet-data-utils-ts",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "description": "Browser-safe governed VetChain data contracts",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Connecting Solution & Applications Ltd",
@@ -88,7 +88,7 @@
88
88
  "typescript": "^5.5.4"
89
89
  },
90
90
  "dependencies": {
91
- "gdc-common-utils-ts": "2.9.4"
91
+ "gdc-common-utils-ts": "2.9.10"
92
92
  },
93
93
  "engines": {
94
94
  "node": ">=20"