@sakeetech/viva-payments-core 0.2.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 (203) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +413 -0
  3. package/dist/auth/http.d.ts +44 -0
  4. package/dist/auth/http.d.ts.map +1 -0
  5. package/dist/auth/http.js +80 -0
  6. package/dist/auth/http.js.map +1 -0
  7. package/dist/auth/index.d.ts +19 -0
  8. package/dist/auth/index.d.ts.map +1 -0
  9. package/dist/auth/index.js +18 -0
  10. package/dist/auth/index.js.map +1 -0
  11. package/dist/auth/oauth2-strategy.d.ts +117 -0
  12. package/dist/auth/oauth2-strategy.d.ts.map +1 -0
  13. package/dist/auth/oauth2-strategy.js +217 -0
  14. package/dist/auth/oauth2-strategy.js.map +1 -0
  15. package/dist/auth/reseller-strategy.d.ts +65 -0
  16. package/dist/auth/reseller-strategy.d.ts.map +1 -0
  17. package/dist/auth/reseller-strategy.js +68 -0
  18. package/dist/auth/reseller-strategy.js.map +1 -0
  19. package/dist/auth/single-flight.d.ts +81 -0
  20. package/dist/auth/single-flight.d.ts.map +1 -0
  21. package/dist/auth/single-flight.js +160 -0
  22. package/dist/auth/single-flight.js.map +1 -0
  23. package/dist/auth/token-cache.d.ts +50 -0
  24. package/dist/auth/token-cache.d.ts.map +1 -0
  25. package/dist/auth/token-cache.js +59 -0
  26. package/dist/auth/token-cache.js.map +1 -0
  27. package/dist/errors/api-error.d.ts +15 -0
  28. package/dist/errors/api-error.d.ts.map +1 -0
  29. package/dist/errors/api-error.js +18 -0
  30. package/dist/errors/api-error.js.map +1 -0
  31. package/dist/errors/auth-error.d.ts +14 -0
  32. package/dist/errors/auth-error.d.ts.map +1 -0
  33. package/dist/errors/auth-error.js +17 -0
  34. package/dist/errors/auth-error.js.map +1 -0
  35. package/dist/errors/base.d.ts +59 -0
  36. package/dist/errors/base.d.ts.map +1 -0
  37. package/dist/errors/base.js +51 -0
  38. package/dist/errors/base.js.map +1 -0
  39. package/dist/errors/index.d.ts +18 -0
  40. package/dist/errors/index.d.ts.map +1 -0
  41. package/dist/errors/index.js +16 -0
  42. package/dist/errors/index.js.map +1 -0
  43. package/dist/errors/mode-mismatch-error.d.ts +19 -0
  44. package/dist/errors/mode-mismatch-error.d.ts.map +1 -0
  45. package/dist/errors/mode-mismatch-error.js +22 -0
  46. package/dist/errors/mode-mismatch-error.js.map +1 -0
  47. package/dist/errors/rate-limit-error.d.ts +20 -0
  48. package/dist/errors/rate-limit-error.d.ts.map +1 -0
  49. package/dist/errors/rate-limit-error.js +20 -0
  50. package/dist/errors/rate-limit-error.js.map +1 -0
  51. package/dist/errors/validation-error.d.ts +14 -0
  52. package/dist/errors/validation-error.d.ts.map +1 -0
  53. package/dist/errors/validation-error.js +17 -0
  54. package/dist/errors/validation-error.js.map +1 -0
  55. package/dist/errors/webhook-error.d.ts +14 -0
  56. package/dist/errors/webhook-error.d.ts.map +1 -0
  57. package/dist/errors/webhook-error.js +17 -0
  58. package/dist/errors/webhook-error.js.map +1 -0
  59. package/dist/index.d.ts +15 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +15 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/isv/accounts.d.ts +38 -0
  64. package/dist/isv/accounts.d.ts.map +1 -0
  65. package/dist/isv/accounts.js +60 -0
  66. package/dist/isv/accounts.js.map +1 -0
  67. package/dist/isv/client.d.ts +187 -0
  68. package/dist/isv/client.d.ts.map +1 -0
  69. package/dist/isv/client.js +465 -0
  70. package/dist/isv/client.js.map +1 -0
  71. package/dist/isv/index.d.ts +52 -0
  72. package/dist/isv/index.d.ts.map +1 -0
  73. package/dist/isv/index.js +53 -0
  74. package/dist/isv/index.js.map +1 -0
  75. package/dist/isv/legacy-basic-client.d.ts +122 -0
  76. package/dist/isv/legacy-basic-client.d.ts.map +1 -0
  77. package/dist/isv/legacy-basic-client.js +281 -0
  78. package/dist/isv/legacy-basic-client.js.map +1 -0
  79. package/dist/isv/payments.d.ts +199 -0
  80. package/dist/isv/payments.d.ts.map +1 -0
  81. package/dist/isv/payments.js +385 -0
  82. package/dist/isv/payments.js.map +1 -0
  83. package/dist/isv/sources.d.ts +80 -0
  84. package/dist/isv/sources.d.ts.map +1 -0
  85. package/dist/isv/sources.js +112 -0
  86. package/dist/isv/sources.js.map +1 -0
  87. package/dist/isv/webhooks-api.d.ts +48 -0
  88. package/dist/isv/webhooks-api.d.ts.map +1 -0
  89. package/dist/isv/webhooks-api.js +66 -0
  90. package/dist/isv/webhooks-api.js.map +1 -0
  91. package/dist/legacy/client.d.ts +199 -0
  92. package/dist/legacy/client.d.ts.map +1 -0
  93. package/dist/legacy/client.js +351 -0
  94. package/dist/legacy/client.js.map +1 -0
  95. package/dist/legacy/index.d.ts +15 -0
  96. package/dist/legacy/index.d.ts.map +1 -0
  97. package/dist/legacy/index.js +14 -0
  98. package/dist/legacy/index.js.map +1 -0
  99. package/dist/observability/context.d.ts +30 -0
  100. package/dist/observability/context.d.ts.map +1 -0
  101. package/dist/observability/context.js +40 -0
  102. package/dist/observability/context.js.map +1 -0
  103. package/dist/observability/index.d.ts +15 -0
  104. package/dist/observability/index.d.ts.map +1 -0
  105. package/dist/observability/index.js +11 -0
  106. package/dist/observability/index.js.map +1 -0
  107. package/dist/observability/logger.d.ts +81 -0
  108. package/dist/observability/logger.d.ts.map +1 -0
  109. package/dist/observability/logger.js +127 -0
  110. package/dist/observability/logger.js.map +1 -0
  111. package/dist/observability/metrics.d.ts +37 -0
  112. package/dist/observability/metrics.d.ts.map +1 -0
  113. package/dist/observability/metrics.js +40 -0
  114. package/dist/observability/metrics.js.map +1 -0
  115. package/dist/observability/redact.d.ts +21 -0
  116. package/dist/observability/redact.d.ts.map +1 -0
  117. package/dist/observability/redact.js +72 -0
  118. package/dist/observability/redact.js.map +1 -0
  119. package/dist/observability/tracer.d.ts +25 -0
  120. package/dist/observability/tracer.d.ts.map +1 -0
  121. package/dist/observability/tracer.js +18 -0
  122. package/dist/observability/tracer.js.map +1 -0
  123. package/dist/payments/client.d.ts +247 -0
  124. package/dist/payments/client.d.ts.map +1 -0
  125. package/dist/payments/client.js +488 -0
  126. package/dist/payments/client.js.map +1 -0
  127. package/dist/payments/index.d.ts +14 -0
  128. package/dist/payments/index.d.ts.map +1 -0
  129. package/dist/payments/index.js +13 -0
  130. package/dist/payments/index.js.map +1 -0
  131. package/dist/refunds/fast-refund-client.d.ts +128 -0
  132. package/dist/refunds/fast-refund-client.d.ts.map +1 -0
  133. package/dist/refunds/fast-refund-client.js +138 -0
  134. package/dist/refunds/fast-refund-client.js.map +1 -0
  135. package/dist/refunds/index.d.ts +19 -0
  136. package/dist/refunds/index.d.ts.map +1 -0
  137. package/dist/refunds/index.js +17 -0
  138. package/dist/refunds/index.js.map +1 -0
  139. package/dist/refunds/strategy.d.ts +78 -0
  140. package/dist/refunds/strategy.d.ts.map +1 -0
  141. package/dist/refunds/strategy.js +75 -0
  142. package/dist/refunds/strategy.js.map +1 -0
  143. package/dist/types/auth.d.ts +80 -0
  144. package/dist/types/auth.d.ts.map +1 -0
  145. package/dist/types/auth.js +12 -0
  146. package/dist/types/auth.js.map +1 -0
  147. package/dist/types/card-types.d.ts +48 -0
  148. package/dist/types/card-types.d.ts.map +1 -0
  149. package/dist/types/card-types.js +62 -0
  150. package/dist/types/card-types.js.map +1 -0
  151. package/dist/types/common.d.ts +160 -0
  152. package/dist/types/common.d.ts.map +1 -0
  153. package/dist/types/common.js +70 -0
  154. package/dist/types/common.js.map +1 -0
  155. package/dist/types/index.d.ts +21 -0
  156. package/dist/types/index.d.ts.map +1 -0
  157. package/dist/types/index.js +21 -0
  158. package/dist/types/index.js.map +1 -0
  159. package/dist/types/isv-accounts.d.ts +109 -0
  160. package/dist/types/isv-accounts.d.ts.map +1 -0
  161. package/dist/types/isv-accounts.js +22 -0
  162. package/dist/types/isv-accounts.js.map +1 -0
  163. package/dist/types/isv-payments.d.ts +262 -0
  164. package/dist/types/isv-payments.d.ts.map +1 -0
  165. package/dist/types/isv-payments.js +19 -0
  166. package/dist/types/isv-payments.js.map +1 -0
  167. package/dist/types/status.d.ts +125 -0
  168. package/dist/types/status.d.ts.map +1 -0
  169. package/dist/types/status.js +19 -0
  170. package/dist/types/status.js.map +1 -0
  171. package/dist/types/webhook-events.d.ts +447 -0
  172. package/dist/types/webhook-events.d.ts.map +1 -0
  173. package/dist/types/webhook-events.js +76 -0
  174. package/dist/types/webhook-events.js.map +1 -0
  175. package/dist/webhooks/challenge-response.d.ts +28 -0
  176. package/dist/webhooks/challenge-response.d.ts.map +1 -0
  177. package/dist/webhooks/challenge-response.js +35 -0
  178. package/dist/webhooks/challenge-response.js.map +1 -0
  179. package/dist/webhooks/event-types.d.ts +44 -0
  180. package/dist/webhooks/event-types.d.ts.map +1 -0
  181. package/dist/webhooks/event-types.js +50 -0
  182. package/dist/webhooks/event-types.js.map +1 -0
  183. package/dist/webhooks/extract-client-ip.d.ts +40 -0
  184. package/dist/webhooks/extract-client-ip.d.ts.map +1 -0
  185. package/dist/webhooks/extract-client-ip.js +72 -0
  186. package/dist/webhooks/extract-client-ip.js.map +1 -0
  187. package/dist/webhooks/hmac-verify.d.ts +38 -0
  188. package/dist/webhooks/hmac-verify.d.ts.map +1 -0
  189. package/dist/webhooks/hmac-verify.js +92 -0
  190. package/dist/webhooks/hmac-verify.js.map +1 -0
  191. package/dist/webhooks/index.d.ts +19 -0
  192. package/dist/webhooks/index.d.ts.map +1 -0
  193. package/dist/webhooks/index.js +19 -0
  194. package/dist/webhooks/index.js.map +1 -0
  195. package/dist/webhooks/ip-allowlist.d.ts +59 -0
  196. package/dist/webhooks/ip-allowlist.d.ts.map +1 -0
  197. package/dist/webhooks/ip-allowlist.js +147 -0
  198. package/dist/webhooks/ip-allowlist.js.map +1 -0
  199. package/dist/webhooks/status-lattice.d.ts +72 -0
  200. package/dist/webhooks/status-lattice.d.ts.map +1 -0
  201. package/dist/webhooks/status-lattice.js +208 -0
  202. package/dist/webhooks/status-lattice.js.map +1 -0
  203. package/package.json +85 -0
@@ -0,0 +1,447 @@
1
+ /**
2
+ * Webhook event types and payloads for the Viva Wallet ISV integration.
3
+ *
4
+ * Covers: WebhookEnvelope<T> generic, EVENT_TYPES const object, and typed
5
+ * EventData payloads for v1-scope event types:
6
+ * 1796 — Transaction Payment Created
7
+ * 1797 — Transaction Reversal Created
8
+ * 1798 — Transaction Failed
9
+ * 4865 — Order Updated (cancellation)
10
+ * 8193 — Account Connected
11
+ * 8194 — Account Verification Status Changed
12
+ *
13
+ * Event 7936 (Sale Transactions) is NOT in v1 scope per plan A8.
14
+ * HMAC verification only applies to 7936; not implemented in v1.
15
+ *
16
+ * @see references/viva-docs/md/webhooks-for-payments.txt:141
17
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:158
18
+ * @see references/viva-docs/md/wh-transaction-failed.txt:162
19
+ * @see references/viva-docs/md/wh-account-connected.txt:150
20
+ * @see references/viva-docs/md/wh-account-verif-status-changed.txt:152
21
+ */
22
+ import type { CurrencyCode, TransactionId, OrderCode } from './common.js';
23
+ /**
24
+ * v1-scope Viva Webhook event type identifiers.
25
+ *
26
+ * Defined as `as const` object per requirement 4 — NOT a TypeScript enum.
27
+ * This avoids TypeScript enum pitfalls (numeric reverse-mapping, etc.).
28
+ *
29
+ * @see references/viva-docs/md/webhooks-for-payments.txt:141
30
+ */
31
+ export declare const EVENT_TYPES: {
32
+ /** A customer payment has been successful. */
33
+ readonly TRANSACTION_PAYMENT_CREATED: 1796;
34
+ /** A customer refund has been successfully actioned. */
35
+ readonly TRANSACTION_REVERSAL_CREATED: 1797;
36
+ /** A customer payment failed. */
37
+ readonly TRANSACTION_FAILED: 1798;
38
+ /** An order was cancelled (API or Smart Checkout back button). */
39
+ readonly ORDER_UPDATED: 4865;
40
+ /** An account is successfully connected to the ISV account. */
41
+ readonly ACCOUNT_CONNECTED: 8193;
42
+ /** Verification status of a connected account changed. */
43
+ readonly ACCOUNT_VERIFICATION_STATUS_CHANGED: 8194;
44
+ };
45
+ /**
46
+ * Union type of all v1-scope EventTypeId numeric values.
47
+ */
48
+ export type VivaEventTypeId = (typeof EVENT_TYPES)[keyof typeof EVENT_TYPES];
49
+ /**
50
+ * Deferred event type IDs — documented for future implementation.
51
+ * NOT in v1 scope per plan A8 and the narrowed event-type set.
52
+ *
53
+ * @see references/viva-docs/md/webhooks-for-payments.txt:141
54
+ */
55
+ export declare const DEFERRED_EVENT_TYPES: {
56
+ /** Commission payment withdrawn by Viva. Post-v1. */
57
+ readonly TRANSACTION_PRICE_CALCULATED: 1799;
58
+ /** ECR integration only. Post-v1. */
59
+ readonly TRANSACTION_POS_ECR_SESSION_CREATED: 1802;
60
+ /** ECR integration only. Post-v1. */
61
+ readonly TRANSACTION_POS_ECR_SESSION_FAILED: 1803;
62
+ /** Wallet account balance change. Post-v1. */
63
+ readonly ACCOUNT_TRANSACTION_CREATED: 2054;
64
+ /** Bank transfer created. Post-v1. */
65
+ readonly COMMAND_BANK_TRANSFER_CREATED: 768;
66
+ /** Bank transfer executed. Post-v1. */
67
+ readonly COMMAND_BANK_TRANSFER_EXECUTED: 769;
68
+ /**
69
+ * Sale transactions report file available. NOT in v1 — HMAC-signed webhook
70
+ * distinct from transaction events. Re-add in v1.1 if needed.
71
+ *
72
+ * @see references/viva-docs/md/wh-sale-transactions.txt:118
73
+ */
74
+ readonly SALE_TRANSACTIONS: 7936;
75
+ /** Marketplace-only: a transfer has been made. Post-v1. */
76
+ readonly TRANSFER_CREATED: 8448;
77
+ };
78
+ /**
79
+ * Generic webhook envelope shape.
80
+ *
81
+ * All Viva webhook POSTs share the same outer envelope; only `EventData`
82
+ * varies by event type.
83
+ *
84
+ * Observed in two different docs:
85
+ * - wh-transaction-payment-created.txt line 158: has `RetryCount` and
86
+ * `RetryDelayInSeconds` at the top level (inside EventData AND envelope).
87
+ * - wh-account-connected.txt line 150: does NOT show RetryCount at top level,
88
+ * only inside EventData.
89
+ *
90
+ * TODO(impl): verify whether RetryCount/RetryDelayInSeconds are envelope-level
91
+ * fields on all event types or only on transaction events. Cross-check against
92
+ * live demo payload.
93
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:252
94
+ * @see references/viva-docs/md/wh-account-connected.txt:159
95
+ *
96
+ * The `Delay` field is documented as `string` in wh-account-connected.txt:231
97
+ * but shown as `null` in the example. Typed as `string | null`.
98
+ */
99
+ export interface WebhookEnvelope<T> {
100
+ /** The webhook URL that received this notification. */
101
+ readonly Url: string;
102
+ /**
103
+ * The event-specific payload. Type varies by EventTypeId.
104
+ *
105
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:158
106
+ */
107
+ readonly EventData: T;
108
+ /**
109
+ * ISO 8601 UTC timestamp when the notification was initially created.
110
+ * Used for the 25-hour freshness check (plan A12).
111
+ *
112
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:252
113
+ */
114
+ readonly Created: string;
115
+ /**
116
+ * Viva internal tracking ID for cross-system log correlation.
117
+ * Store as `correlation_id` on structured log lines (plan A13).
118
+ *
119
+ * @see references/viva-docs/md/wh-account-connected.txt:159
120
+ */
121
+ readonly CorrelationId: string;
122
+ /**
123
+ * The type of event that triggered this notification.
124
+ *
125
+ * @see references/viva-docs/md/webhooks-for-payments.txt:141
126
+ */
127
+ readonly EventTypeId: number;
128
+ /**
129
+ * Delay timespan for messages sent at a future date (null for immediate).
130
+ *
131
+ * @see references/viva-docs/md/wh-account-connected.txt:161
132
+ */
133
+ readonly Delay: string | null;
134
+ /**
135
+ * Unique identifier of this message delivery.
136
+ * Used for deduplication at the DB layer (UNIQUE constraint on message_id).
137
+ *
138
+ * @see references/viva-docs/md/wh-account-connected.txt:164
139
+ */
140
+ readonly MessageId: string;
141
+ /**
142
+ * The recipient of the webhook (typically the ISV account Merchant ID).
143
+ *
144
+ * @see references/viva-docs/md/wh-account-connected.txt:165
145
+ */
146
+ readonly RecipientId: string;
147
+ /**
148
+ * Message type: always 512 (0x200) for merchant webhooks.
149
+ *
150
+ * @see references/viva-docs/md/wh-account-connected.txt:166
151
+ */
152
+ readonly MessageTypeId: number;
153
+ /**
154
+ * Number of retry attempts so far (0 on first delivery).
155
+ *
156
+ * TODO(impl): verify RetryCount is present on ALL event type envelopes,
157
+ * not just transaction events. wh-account-connected.txt does not show it
158
+ * in the response example but wh-transaction-payment-created.txt does.
159
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:255
160
+ */
161
+ readonly RetryCount?: number;
162
+ /**
163
+ * Delay in seconds between retries. Null on first delivery.
164
+ *
165
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:257
166
+ */
167
+ readonly RetryDelayInSeconds?: number | null;
168
+ }
169
+ /**
170
+ * Base shape for transaction event data (EventTypeId 1796, 1797, 1798).
171
+ *
172
+ * All three share the same flat structure. Differences:
173
+ * - 1796: StatusId is typically 'F' (Finished/captured)
174
+ * - 1797: StatusId is typically 'R' (Refunded); ParentId links to original
175
+ * - 1798: StatusId is typically 'E' (Error)
176
+ *
177
+ * Amount ambiguity: the docs show `Amount: decimal` in the description text
178
+ * (webhooks-for-payments.txt:483) but the createOrder request uses integer
179
+ * minor units. The sample payloads show integer values (Amount: 10, 1000).
180
+ *
181
+ * TODO(impl): verify Amount unit (minor int vs major decimal) against first
182
+ * real demo payment. Treat as minor units until confirmed otherwise.
183
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:344
184
+ *
185
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:158
186
+ */
187
+ export interface TransactionEventData {
188
+ /** The TransactionId of the transaction. */
189
+ readonly TransactionId: TransactionId;
190
+ /** The OrderCode of the transaction. */
191
+ readonly OrderCode: OrderCode;
192
+ /**
193
+ * Status letter. See VivaStatusLetter in status.ts.
194
+ *
195
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:398
196
+ */
197
+ readonly StatusId: string;
198
+ /**
199
+ * Signed amount of the transaction. Represents total funds paid by the
200
+ * customer (includes TotalFee).
201
+ *
202
+ * TODO(impl): verify unit — docs say decimal, sample shows integer.
203
+ * Assuming minor units. Treat as number on wire, convert to bigint on ingest.
204
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:344
205
+ */
206
+ readonly Amount: number;
207
+ /**
208
+ * ISO 4217 numeric currency code string.
209
+ *
210
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:487
211
+ */
212
+ readonly CurrencyCode: CurrencyCode;
213
+ /** MerchantId of the merchant. Used for tenant routing. */
214
+ readonly MerchantId: string;
215
+ /**
216
+ * ConnectedAccountId (ISV schema). May be null if not ISV-scoped.
217
+ * Used for onboarding event tenant routing.
218
+ *
219
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:224
220
+ */
221
+ readonly ConnectedAccountId: string | null;
222
+ /** Parent TransactionId (if this is a reversal/refund). */
223
+ readonly ParentId: TransactionId | null;
224
+ /** ISO 8601 timestamp when the transaction occurred. */
225
+ readonly InsDate: string;
226
+ /** Transaction type numeric identifier (5 = CardCharge, 4 = Refund, etc.). */
227
+ readonly TransactionTypeId: number;
228
+ /** Customer email. May be masked. */
229
+ readonly Email: string | null;
230
+ /** Customer full name. */
231
+ readonly FullName: string | null;
232
+ /** Masked card number (e.g. "414746XXXXXX0133"). */
233
+ readonly CardNumber: string | null;
234
+ /**
235
+ * Card type: 0=Visa, 1=Mastercard, 2=Diners, 3=Amex, 4=Invalid,
236
+ * 5=Unknown, 6=Maestro, 7=Discover, 8=JCB.
237
+ *
238
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:770
239
+ */
240
+ readonly CardTypeId: number;
241
+ /** Merchant transaction reference. */
242
+ readonly MerchantTrns: string | null;
243
+ /** Customer transaction reference. */
244
+ readonly CustomerTrns: string | null;
245
+ /** Source code of the Merchant's payment source. */
246
+ readonly SourceCode: string;
247
+ /** Total fees (signed). */
248
+ readonly TotalFee: number;
249
+ /** Card expiration date in ISO 8601 format. */
250
+ readonly CardExpirationDate: string | null;
251
+ /** Two-letter ISO country code of the card-issuing country. */
252
+ readonly CardCountryCode: string | null;
253
+ /** Name of the card-issuing bank. */
254
+ readonly CardIssuingBank: string | null;
255
+ /**
256
+ * Internal event ID used for failure classification on 1798.
257
+ * The ResponseEventId indicates why a payment failed.
258
+ *
259
+ * @see references/viva-docs/md/wh-transaction-failed.txt:243
260
+ */
261
+ readonly ResponseEventId: number | null;
262
+ /** Order tags. */
263
+ readonly Tags: readonly string[];
264
+ /** Reseller ID if applicable. */
265
+ readonly ResellerId: string | null;
266
+ readonly ResellerCompanyName: string | null;
267
+ readonly ResellerSourceCode: string | null;
268
+ readonly ResellerSourceAddress: string | null;
269
+ readonly CompanyName: string;
270
+ readonly CompanyTitle: string;
271
+ readonly AuthorizationId: string;
272
+ readonly ReferenceNumber: number;
273
+ readonly ResponseCode: string | null;
274
+ /** Whether this is a Mail Order / Telephone Order transaction. */
275
+ readonly Moto: boolean;
276
+ readonly DualMessage: boolean;
277
+ readonly TipAmount: number;
278
+ readonly TotalInstallments: number;
279
+ readonly CurrentInstallment: number;
280
+ readonly ElectronicCommerceIndicator: string | null;
281
+ /** Digital wallet type ID (2=Apple Pay, 3=Google Pay, 4=Samsung Pay). */
282
+ readonly DigitalWalletId: number | null;
283
+ readonly BinId: number;
284
+ readonly IsDcc: boolean;
285
+ /** DCC conversion rate. */
286
+ readonly ConversionRate: number;
287
+ readonly OriginalAmount: number;
288
+ readonly OriginalCurrencyCode: CurrencyCode | null;
289
+ readonly OrderCulture: string;
290
+ readonly CardToken: string | null;
291
+ readonly CardUniqueReference: string | null;
292
+ readonly TargetPersonId: string | null;
293
+ readonly TargetWalletId: string | null;
294
+ readonly SourceName: string;
295
+ readonly Latitude: number | null;
296
+ readonly Longitude: number | null;
297
+ readonly BatchId: string | null;
298
+ readonly PanEntryMode: string;
299
+ readonly BankId: string;
300
+ readonly ChannelId: string;
301
+ readonly TerminalId: number;
302
+ readonly ProductId: string | null;
303
+ readonly Descriptor: string | null;
304
+ readonly Switching: boolean;
305
+ readonly Systemic: boolean;
306
+ readonly AcquirerApproved: boolean;
307
+ readonly LoyaltyTriggered: boolean;
308
+ readonly RedeemedAmount: number;
309
+ readonly SurchargeAmount: number | null;
310
+ readonly ClearanceDate: string | null;
311
+ readonly Ucaf: string | null;
312
+ readonly IsManualRefund: boolean;
313
+ readonly BillId: string | null;
314
+ readonly MerchantCategoryCode: number | null;
315
+ readonly ExternalTransactionId: string | null;
316
+ readonly RetrievalReferenceNumber: string | null;
317
+ readonly AssignedMerchantUsers: readonly string[];
318
+ readonly AssignedResellerUsers: readonly string[];
319
+ readonly CardProductCategoryId: number | null;
320
+ readonly CardProductAccountTypeId: number | null;
321
+ readonly OrderServiceId: number;
322
+ readonly ApplicationIdentifierTerminal: string | null;
323
+ readonly IntegrationId: number | null;
324
+ readonly PrimaryAccountNumberLast4Digits: string | null;
325
+ readonly ServiceId: number | null;
326
+ readonly ResellerSourceName: string | null;
327
+ readonly DccSessionId: string | null;
328
+ readonly DccMarkup: number | null;
329
+ readonly DccDifferenceOverEcb: number | null;
330
+ }
331
+ /**
332
+ * EventData for Transaction Payment Created (EventTypeId 1796).
333
+ * StatusId is typically 'F' (Finished/captured).
334
+ *
335
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:158
336
+ */
337
+ export type TransactionPaymentCreatedEventData = TransactionEventData;
338
+ /**
339
+ * EventData for Transaction Reversal Created (EventTypeId 1797).
340
+ * StatusId is typically 'R' (Refunded).
341
+ * ParentId references the original transaction.
342
+ *
343
+ * @see references/viva-docs/md/webhooks-for-payments.txt:167
344
+ */
345
+ export type TransactionReversalCreatedEventData = TransactionEventData;
346
+ /**
347
+ * EventData for Transaction Failed (EventTypeId 1798).
348
+ * StatusId is typically 'E' (Error).
349
+ * ResponseEventId indicates the failure reason.
350
+ *
351
+ * @see references/viva-docs/md/wh-transaction-failed.txt:162
352
+ */
353
+ export type TransactionFailedEventData = TransactionEventData;
354
+ /**
355
+ * EventData for Order Updated (EventTypeId 4865).
356
+ *
357
+ * Sent when an order is cancelled via Smart Checkout's back button or the
358
+ * cancel-order API. The EventData shape may differ from transaction events.
359
+ *
360
+ * TODO(impl): verify exact EventData fields for 4865 Order Updated.
361
+ * The webhooks-for-payments.txt doc lists it but does not show a sample.
362
+ * wh-transaction-payment-created.txt and wh-transaction-failed.txt cover
363
+ * 1796/1798; no dedicated 4865 doc exists in the local mirror.
364
+ * @see references/viva-docs/md/webhooks-for-payments.txt:207
365
+ */
366
+ export interface OrderUpdatedEventData {
367
+ /** The order code of the updated/cancelled order. */
368
+ readonly OrderCode: OrderCode;
369
+ /**
370
+ * The merchant ID for tenant routing.
371
+ * TODO(impl): confirm MerchantId is present on 4865 payload.
372
+ * @see references/viva-docs/md/webhooks-for-payments.txt:207
373
+ */
374
+ readonly MerchantId?: string;
375
+ /**
376
+ * Raw event data — preserved as unknown for forensics until shape confirmed.
377
+ * TODO(impl): replace with fully typed fields once 4865 sample payload obtained.
378
+ */
379
+ readonly raw?: unknown;
380
+ }
381
+ /**
382
+ * EventData for Account Connected (EventTypeId 8193).
383
+ *
384
+ * @see references/viva-docs/md/wh-account-connected.txt:150
385
+ */
386
+ export interface AccountConnectedEventData {
387
+ /** ID of the created person/merchant. */
388
+ readonly PersonId: string;
389
+ /**
390
+ * The ID of the primary wallet created for the merchant.
391
+ * Stored as number (int64 on the wire); use BigInt if precision matters.
392
+ *
393
+ * @see references/viva-docs/md/wh-account-connected.txt:154
394
+ */
395
+ readonly WalletId: number;
396
+ /** ID of the ISV platform account. */
397
+ readonly PlatformPersonId: string;
398
+ /**
399
+ * Connected account ID (UUID). Use for tenant routing on onboarding events.
400
+ *
401
+ * @see references/viva-docs/md/wh-account-connected.txt:155
402
+ */
403
+ readonly ConnectedAccountId: string;
404
+ }
405
+ /**
406
+ * EventData for Account Verification Status Changed (EventTypeId 8194).
407
+ *
408
+ * @see references/viva-docs/md/wh-account-verif-status-changed.txt:152
409
+ */
410
+ export interface AccountVerificationStatusChangedEventData {
411
+ /**
412
+ * True if the account is now verified.
413
+ *
414
+ * @see references/viva-docs/md/wh-account-verif-status-changed.txt:155
415
+ */
416
+ readonly Verified: boolean;
417
+ /** ID of the created person/merchant. */
418
+ readonly PersonId: string;
419
+ /** ID of the ISV platform account. */
420
+ readonly PlatformPersonId: string;
421
+ /**
422
+ * Connected account ID (UUID). Use for tenant routing on onboarding events.
423
+ *
424
+ * @see references/viva-docs/md/wh-account-verif-status-changed.txt:158
425
+ */
426
+ readonly ConnectedAccountId: string;
427
+ }
428
+ /**
429
+ * Discriminated union of all typed webhook envelopes for v1-scope event types.
430
+ * Switch on `EventTypeId` to narrow to the specific EventData type.
431
+ *
432
+ * @see references/viva-docs/md/webhooks-for-payments.txt:141
433
+ */
434
+ export type VivaWebhookEnvelope = WebhookEnvelope<TransactionPaymentCreatedEventData> & {
435
+ readonly EventTypeId: 1796;
436
+ } | WebhookEnvelope<TransactionReversalCreatedEventData> & {
437
+ readonly EventTypeId: 1797;
438
+ } | WebhookEnvelope<TransactionFailedEventData> & {
439
+ readonly EventTypeId: 1798;
440
+ } | WebhookEnvelope<OrderUpdatedEventData> & {
441
+ readonly EventTypeId: 4865;
442
+ } | WebhookEnvelope<AccountConnectedEventData> & {
443
+ readonly EventTypeId: 8193;
444
+ } | WebhookEnvelope<AccountVerificationStatusChangedEventData> & {
445
+ readonly EventTypeId: 8194;
446
+ };
447
+ //# sourceMappingURL=webhook-events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-events.d.ts","sourceRoot":"","sources":["../../src/types/webhook-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM1E;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW;IACtB,8CAA8C;;IAE9C,wDAAwD;;IAExD,iCAAiC;;IAEjC,kEAAkE;;IAElE,+DAA+D;;IAE/D,0DAA0D;;CAElD,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,WAAW,CAA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IAAI,CAAA;CAAE,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Webhook event types and payloads for the Viva Wallet ISV integration.
3
+ *
4
+ * Covers: WebhookEnvelope<T> generic, EVENT_TYPES const object, and typed
5
+ * EventData payloads for v1-scope event types:
6
+ * 1796 — Transaction Payment Created
7
+ * 1797 — Transaction Reversal Created
8
+ * 1798 — Transaction Failed
9
+ * 4865 — Order Updated (cancellation)
10
+ * 8193 — Account Connected
11
+ * 8194 — Account Verification Status Changed
12
+ *
13
+ * Event 7936 (Sale Transactions) is NOT in v1 scope per plan A8.
14
+ * HMAC verification only applies to 7936; not implemented in v1.
15
+ *
16
+ * @see references/viva-docs/md/webhooks-for-payments.txt:141
17
+ * @see references/viva-docs/md/wh-transaction-payment-created.txt:158
18
+ * @see references/viva-docs/md/wh-transaction-failed.txt:162
19
+ * @see references/viva-docs/md/wh-account-connected.txt:150
20
+ * @see references/viva-docs/md/wh-account-verif-status-changed.txt:152
21
+ */
22
+ // ---------------------------------------------------------------------------
23
+ // EventTypeId const object (not a TypeScript enum)
24
+ // ---------------------------------------------------------------------------
25
+ /**
26
+ * v1-scope Viva Webhook event type identifiers.
27
+ *
28
+ * Defined as `as const` object per requirement 4 — NOT a TypeScript enum.
29
+ * This avoids TypeScript enum pitfalls (numeric reverse-mapping, etc.).
30
+ *
31
+ * @see references/viva-docs/md/webhooks-for-payments.txt:141
32
+ */
33
+ export const EVENT_TYPES = {
34
+ /** A customer payment has been successful. */
35
+ TRANSACTION_PAYMENT_CREATED: 1796,
36
+ /** A customer refund has been successfully actioned. */
37
+ TRANSACTION_REVERSAL_CREATED: 1797,
38
+ /** A customer payment failed. */
39
+ TRANSACTION_FAILED: 1798,
40
+ /** An order was cancelled (API or Smart Checkout back button). */
41
+ ORDER_UPDATED: 4865,
42
+ /** An account is successfully connected to the ISV account. */
43
+ ACCOUNT_CONNECTED: 8193,
44
+ /** Verification status of a connected account changed. */
45
+ ACCOUNT_VERIFICATION_STATUS_CHANGED: 8194,
46
+ };
47
+ /**
48
+ * Deferred event type IDs — documented for future implementation.
49
+ * NOT in v1 scope per plan A8 and the narrowed event-type set.
50
+ *
51
+ * @see references/viva-docs/md/webhooks-for-payments.txt:141
52
+ */
53
+ export const DEFERRED_EVENT_TYPES = {
54
+ /** Commission payment withdrawn by Viva. Post-v1. */
55
+ TRANSACTION_PRICE_CALCULATED: 1799,
56
+ /** ECR integration only. Post-v1. */
57
+ TRANSACTION_POS_ECR_SESSION_CREATED: 1802,
58
+ /** ECR integration only. Post-v1. */
59
+ TRANSACTION_POS_ECR_SESSION_FAILED: 1803,
60
+ /** Wallet account balance change. Post-v1. */
61
+ ACCOUNT_TRANSACTION_CREATED: 2054,
62
+ /** Bank transfer created. Post-v1. */
63
+ COMMAND_BANK_TRANSFER_CREATED: 768,
64
+ /** Bank transfer executed. Post-v1. */
65
+ COMMAND_BANK_TRANSFER_EXECUTED: 769,
66
+ /**
67
+ * Sale transactions report file available. NOT in v1 — HMAC-signed webhook
68
+ * distinct from transaction events. Re-add in v1.1 if needed.
69
+ *
70
+ * @see references/viva-docs/md/wh-sale-transactions.txt:118
71
+ */
72
+ SALE_TRANSACTIONS: 7936,
73
+ /** Marketplace-only: a transfer has been made. Post-v1. */
74
+ TRANSFER_CREATED: 8448,
75
+ };
76
+ //# sourceMappingURL=webhook-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-events.js","sourceRoot":"","sources":["../../src/types/webhook-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,8EAA8E;AAC9E,mDAAmD;AACnD,8EAA8E;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,8CAA8C;IAC9C,2BAA2B,EAAE,IAAI;IACjC,wDAAwD;IACxD,4BAA4B,EAAE,IAAI;IAClC,iCAAiC;IACjC,kBAAkB,EAAE,IAAI;IACxB,kEAAkE;IAClE,aAAa,EAAE,IAAI;IACnB,+DAA+D;IAC/D,iBAAiB,EAAE,IAAI;IACvB,0DAA0D;IAC1D,mCAAmC,EAAE,IAAI;CACjC,CAAC;AAOX;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,qDAAqD;IACrD,4BAA4B,EAAE,IAAI;IAClC,qCAAqC;IACrC,mCAAmC,EAAE,IAAI;IACzC,qCAAqC;IACrC,kCAAkC,EAAE,IAAI;IACxC,8CAA8C;IAC9C,2BAA2B,EAAE,IAAI;IACjC,sCAAsC;IACtC,6BAA6B,EAAE,GAAG;IAClC,uCAAuC;IACvC,8BAA8B,EAAE,GAAG;IACnC;;;;;OAKG;IACH,iBAAiB,EAAE,IAAI;IACvB,2DAA2D;IAC3D,gBAAgB,EAAE,IAAI;CACd,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Viva Wallet webhook challenge-response handler.
3
+ *
4
+ * When Viva verifies a webhook URL at registration time it sends a GET request.
5
+ * The endpoint must respond with `{"Key": "<webhook_verification_key>"}`.
6
+ *
7
+ * @see references/viva-docs/md/webhooks-for-payments.txt:311
8
+ */
9
+ /**
10
+ * Returns the GET-request response body for Viva's URL verification challenge.
11
+ *
12
+ * @param webhookVerificationKey The webhook verification key obtained from
13
+ * Viva's `GET /api/messages/config/token` endpoint. Must be non-empty.
14
+ *
15
+ * @throws VivaWebhookError when the key is empty or whitespace-only.
16
+ *
17
+ * @see references/viva-docs/md/webhooks-for-payments.txt:362
18
+ *
19
+ * @example
20
+ * // Route handler (framework-agnostic pseudocode):
21
+ * if (req.method === 'GET') {
22
+ * return res.json(buildChallengeResponse(env.VIVA_WEBHOOK_KEY));
23
+ * }
24
+ */
25
+ export declare function buildChallengeResponse(webhookVerificationKey: string): {
26
+ Key: string;
27
+ };
28
+ //# sourceMappingURL=challenge-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"challenge-response.d.ts","sourceRoot":"","sources":["../../src/webhooks/challenge-response.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,sBAAsB,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAUtF"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Viva Wallet webhook challenge-response handler.
3
+ *
4
+ * When Viva verifies a webhook URL at registration time it sends a GET request.
5
+ * The endpoint must respond with `{"Key": "<webhook_verification_key>"}`.
6
+ *
7
+ * @see references/viva-docs/md/webhooks-for-payments.txt:311
8
+ */
9
+ import { VivaWebhookError } from '../errors/index.js';
10
+ /**
11
+ * Returns the GET-request response body for Viva's URL verification challenge.
12
+ *
13
+ * @param webhookVerificationKey The webhook verification key obtained from
14
+ * Viva's `GET /api/messages/config/token` endpoint. Must be non-empty.
15
+ *
16
+ * @throws VivaWebhookError when the key is empty or whitespace-only.
17
+ *
18
+ * @see references/viva-docs/md/webhooks-for-payments.txt:362
19
+ *
20
+ * @example
21
+ * // Route handler (framework-agnostic pseudocode):
22
+ * if (req.method === 'GET') {
23
+ * return res.json(buildChallengeResponse(env.VIVA_WEBHOOK_KEY));
24
+ * }
25
+ */
26
+ export function buildChallengeResponse(webhookVerificationKey) {
27
+ if (!webhookVerificationKey || webhookVerificationKey.trim().length === 0) {
28
+ throw new VivaWebhookError({
29
+ message: 'webhookVerificationKey must be a non-empty string. ' +
30
+ 'Obtain it from GET /api/messages/config/token and set VIVA_WEBHOOK_KEY.',
31
+ });
32
+ }
33
+ return { Key: webhookVerificationKey };
34
+ }
35
+ //# sourceMappingURL=challenge-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"challenge-response.js","sourceRoot":"","sources":["../../src/webhooks/challenge-response.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CAAC,sBAA8B;IACnE,IAAI,CAAC,sBAAsB,IAAI,sBAAsB,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1E,MAAM,IAAI,gBAAgB,CAAC;YACzB,OAAO,EACL,qDAAqD;gBACrD,yEAAyE;SAC5E,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,sBAAsB,EAAE,CAAC;AACzC,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Runtime helpers for Viva webhook event type IDs.
3
+ *
4
+ * Re-exports EVENT_TYPES and VivaEventTypeId from the types package, and
5
+ * provides runtime type-guard helpers for routing webhook payloads.
6
+ *
7
+ * @see references/viva-docs/md/webhooks-for-payments.txt:141
8
+ */
9
+ export { EVENT_TYPES, type VivaEventTypeId } from '../types/webhook-events.js';
10
+ /**
11
+ * Returns `true` for event types that carry a transaction payload and require
12
+ * MerchantId-based tenant resolution.
13
+ *
14
+ * v1-scope transaction events:
15
+ * 1796 — Transaction Payment Created
16
+ * 1797 — Transaction Reversal Created
17
+ * 1798 — Transaction Failed
18
+ * 4865 — Order Updated (cancellation)
19
+ * 7936 — Sale Transactions (HMAC-signed, deferred from v1 core but type-guard kept)
20
+ *
21
+ * @see references/viva-docs/md/webhooks-for-payments.txt:141
22
+ */
23
+ export declare function isTransactionEvent(id: number): id is 1796 | 1797 | 1798 | 4865 | 7936;
24
+ /**
25
+ * Returns `true` for event types that carry an onboarding payload and require
26
+ * ConnectedAccountId-based tenant resolution.
27
+ *
28
+ * v1-scope onboarding events:
29
+ * 8193 — Account Connected
30
+ * 8194 — Account Verification Status Changed
31
+ *
32
+ * @see references/viva-docs/md/webhooks-for-payments.txt:224
33
+ */
34
+ export declare function isOnboardingEvent(id: number): id is 8193 | 8194;
35
+ /**
36
+ * All v1-scope event IDs as a frozen array.
37
+ *
38
+ * Used by `viva:register-webhooks` CLI to enumerate the required registrations
39
+ * and by the route handler to reject unknown event types.
40
+ *
41
+ * @see references/viva-docs/md/webhooks-for-payments.txt:141
42
+ */
43
+ export declare const V1_EVENT_TYPE_IDS: readonly (1796 | 1797 | 1798 | 4865 | 8193 | 8194)[];
44
+ //# sourceMappingURL=event-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-types.d.ts","sourceRoot":"","sources":["../../src/webhooks/event-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE/E;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAErF;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,IAAI,GAAG,IAAI,CAE/D;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAAS,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,EAEvE,CAAC"}