@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sakee Technologies AB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,413 @@
1
+ # @sakeetech/viva-payments-core
2
+
3
+ Framework-agnostic Viva Wallet SDK. Used by
4
+ [`@sakeetech/medusa-payment-viva`](../medusa-payment-viva) and
5
+ [`@sakeetech/vendure-payment-viva`](../vendure-payment-viva). Zero Medusa
6
+ or Vendure imports — pure TypeScript on top of `undici`.
7
+
8
+ Covers the full Smart Checkout surface for both **merchant** and **ISV**
9
+ operational modes: OAuth2 client_credentials auth (with token cache +
10
+ single-flight refresh), the legacy Basic-auth host (used for refunds),
11
+ Fast Refund, webhook verification + state-machine lattice, and structured
12
+ error / observability hooks.
13
+
14
+ ---
15
+
16
+ > **v0.2.0 — alpha. Live demo verification pending.**
17
+ >
18
+ > Migrating from `0.1.x`? See [`docs/MIGRATION-0.1-to-0.2.md`](https://github.com/sakee-tech/vivawallet-npm-public/blob/main/docs/MIGRATION-0.1-to-0.2.md).
19
+ > All locked auth / endpoint / webhook / error / state-machine decisions
20
+ > live in [`docs/`](../../docs) — this README links into them rather than
21
+ > duplicating.
22
+
23
+ ---
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pnpm add @sakeetech/viva-payments-core
29
+ ```
30
+
31
+ Runtime dep: `undici ^7`. Node.js ≥ 20. ESM-only.
32
+
33
+ You typically do **not** install this directly — install the Medusa or
34
+ Vendure adapter, which depends on this package. Install directly only if
35
+ you're building a custom adapter or driving Viva from a non-storefront
36
+ context (CLI tool, scheduled job, etc.).
37
+
38
+ ---
39
+
40
+ ## Subpath exports
41
+
42
+ Every public symbol lives behind a subpath export. Import only what you
43
+ need.
44
+
45
+ | Subpath | Purpose |
46
+ |---|---|
47
+ | `@sakeetech/viva-payments-core/auth` | OAuth2 client_credentials strategy, Reseller Basic strategy, token cache (in-memory or Redis), single-flight refresh mutex, shared `undici` dispatchers. |
48
+ | `@sakeetech/viva-payments-core/payments` | [`Payments`](#payments) — mode-aware Smart Checkout client (`createOrder`, `retrieveTransaction`, `refundPayment`, `cancelOrder`). |
49
+ | `@sakeetech/viva-payments-core/isv` | ISV-only API clients: [`IsvAccounts`](#isvaccounts), [`IsvWebhooks`](#isvwebhooks), [`IsvSources`](#isvsources). Also the shared `IsvHttpClient` (OAuth2 HTTP wrapper). |
50
+ | `@sakeetech/viva-payments-core/legacy` | [`BasicAuthClient`](#basicauthclient) — wraps Viva's legacy host with Basic auth. Required for refunds; supports `authVariant: 'merchant' \| 'reseller'`. |
51
+ | `@sakeetech/viva-payments-core/refunds` | [`FastRefundClient`](#fastrefundclient) (acquiring-scope OAuth2) + [`resolveRefundStrategy`](#resolverefundstrategy) (pure decision function). |
52
+ | `@sakeetech/viva-payments-core/webhooks` | URL-verify handshake builder, IP allowlist, HMAC verifier (event 7936), event-type constants, monotonic status lattice, `extractClientIp` source-IP helper with `trustedProxyDepth` X-Forwarded-For walking. |
53
+ | `@sakeetech/viva-payments-core/types` | All TypeScript types for the Viva API surface — request / response shapes, card type helpers, status letters, ISV event payloads. |
54
+ | `@sakeetech/viva-payments-core/errors` | Error class hierarchy — `VivaError` + specialised subclasses. |
55
+ | `@sakeetech/viva-payments-core/observability` | Logger interfaces (`StructuredJsonLogger`, `RedactingLogger`), metrics hooks, tracer hooks, log redactor. |
56
+
57
+ > The root entry (`@sakeetech/viva-payments-core`) currently only exports
58
+ > `VERSION`. Always import from a subpath.
59
+
60
+ ---
61
+
62
+ ## Class reference
63
+
64
+ Short signatures only — link out for full docs.
65
+
66
+ ### `Payments`
67
+
68
+ Subpath: `@sakeetech/viva-payments-core/payments`.
69
+
70
+ ```ts
71
+ new Payments({
72
+ mode: 'merchant' | 'isv',
73
+ client: IsvHttpClient, // primary OAuth2 client
74
+ secondaryClient?: IsvHttpClient, // optional 401-fallback (defensive; D15)
75
+ legacyClient?: BasicAuthClient, // required for refundPayment()
76
+ });
77
+ ```
78
+
79
+ | Method | Description |
80
+ |---|---|
81
+ | `createOrder(req, opts?)` | `POST /checkout/v2/orders` (merchant) / `POST /checkout/v2/isv/orders?merchantId={uuid}` (ISV). Returns `{ orderCode, redirectUrl }`. |
82
+ | `retrieveTransaction(transactionId, opts?)` | `GET /checkout/v2/[isv/]transactions/{id}`. Idempotent. |
83
+ | `refundPayment(transactionId, opts)` | `POST /api/transactions/{id}` on the **legacy host** with Basic auth (probe F1 — v2/OAuth2 path returns 405). Requires `legacyClient`. |
84
+ | `cancelOrder(orderCode, opts?)` | `DELETE /checkout/v2/orders/{orderCode}[?merchantId=...]`. Idempotent. |
85
+
86
+ Mode behaviour: in merchant mode, `merchantId` (if passed) is silently
87
+ ignored; `isvAmount` is stripped from the wire body. In ISV mode,
88
+ `merchantId` is required and `VivaValidationError` is thrown if absent.
89
+
90
+ Deep dives: [`docs/ENDPOINTS.md`](https://github.com/sakee-tech/vivawallet-npm-public/blob/main/docs/ENDPOINTS.md) §2.
91
+
92
+ ### `BasicAuthClient`
93
+
94
+ Subpath: `@sakeetech/viva-payments-core/legacy`.
95
+
96
+ ```ts
97
+ // Merchant variant
98
+ new BasicAuthClient({
99
+ authVariant: 'merchant',
100
+ environment: 'demo' | 'production',
101
+ merchantId: string,
102
+ apiKey: string,
103
+ });
104
+
105
+ // Reseller variant — for POST /api/sources in ISV mode
106
+ new BasicAuthClient({
107
+ authVariant: 'reseller',
108
+ environment: 'demo' | 'production',
109
+ resellerId: string,
110
+ merchantId: string,
111
+ resellerApiKey: string,
112
+ });
113
+ ```
114
+
115
+ | Method | Description |
116
+ |---|---|
117
+ | `request<T>({ method, path, formBody?, jsonBody?, idempotent, ... })` | Generic legacy-API request. Retries on 429/5xx + connection errors per backoff schedule. Returns `LegacyApiResult<T>` with parsed body + Viva tracing headers. |
118
+ | `fetchWebhookVerificationKey()` | `GET /api/messages/config/token`. Used by the adapter CLI in merchant mode. |
119
+
120
+ Auth header format and the merchant/reseller distinction are documented in
121
+ [`docs/AUTH.md`](https://github.com/sakee-tech/vivawallet-npm-public/blob/main/docs/AUTH.md) §4.
122
+
123
+ ### `FastRefundClient`
124
+
125
+ Subpath: `@sakeetech/viva-payments-core/refunds`.
126
+
127
+ ```ts
128
+ new FastRefundClient({
129
+ client: IsvHttpClient, // OAuth2 with `acquiring` scope
130
+ environment: 'demo' | 'production',
131
+ });
132
+ ```
133
+
134
+ | Method | Description |
135
+ |---|---|
136
+ | `refund({ transactionId, amount, currencyCode, customerTrns? })` | `POST /acquiring/v1/transactions/{id}:fastrefund`. Returns the refund response or throws `VIVA_FAST_REFUND_INELIGIBLE` on 403. |
137
+
138
+ Eligibility (Visa / MC / Maestro, card-not-present, merchant approval) is
139
+ described in [`docs/ENDPOINTS.md`](https://github.com/sakee-tech/vivawallet-npm-public/blob/main/docs/ENDPOINTS.md) §4.
140
+
141
+ ### `resolveRefundStrategy`
142
+
143
+ Subpath: `@sakeetech/viva-payments-core/refunds`. Pure function — no I/O.
144
+
145
+ ```ts
146
+ function resolveRefundStrategy(
147
+ strategy: 'auto' | 'fast' | 'standard',
148
+ context: { cardType?: string; cardNotPresent: boolean; ... },
149
+ ): RefundDecision;
150
+ ```
151
+
152
+ Returns `{ path: 'fast' | 'standard', reason: string }`. Callers (Medusa
153
+ or Vendure adapters) execute the chosen path; on `auto` + 403 Fast Refund
154
+ ineligibility, the caller falls back to standard transparently.
155
+
156
+ Decision table in [`docs/ENDPOINTS.md`](https://github.com/sakee-tech/vivawallet-npm-public/blob/main/docs/ENDPOINTS.md) §4.
157
+
158
+ ### `IsvAccounts`
159
+
160
+ Subpath: `@sakeetech/viva-payments-core/isv`.
161
+
162
+ ```ts
163
+ new IsvAccounts(client: IsvHttpClient);
164
+ ```
165
+
166
+ | Method | Description |
167
+ |---|---|
168
+ | `createConnectedAccount({ email, returnUrl, branding? })` | `POST /isv/v1/accounts`. Returns `{ accountId, onboardingUrl }`. |
169
+ | `retrieveConnectedAccount(accountId)` | `GET /isv/v1/accounts/{id}`. Returns current verification + payouts state. |
170
+
171
+ Onboarding flow + 8194 verification webhook: [`docs/WEBHOOKS.md`](https://github.com/sakee-tech/vivawallet-npm-public/blob/main/docs/WEBHOOKS.md) §4.
172
+
173
+ ### `IsvWebhooks`
174
+
175
+ Subpath: `@sakeetech/viva-payments-core/isv`.
176
+
177
+ ```ts
178
+ new IsvWebhooks(client: IsvHttpClient);
179
+ ```
180
+
181
+ | Method | Description |
182
+ |---|---|
183
+ | `registerWebhook({ eventTypeId, webhookUrl })` | `POST /isv/v1/webhooks`. Idempotent — Viva returns the existing registration on duplicate. |
184
+ | `getVerificationKey()` | `GET /isv/v1/webhooks/token`. The CLI uses this to populate `VIVA_WEBHOOK_VERIFICATION_KEY` in ISV mode. |
185
+
186
+ ### `IsvSources`
187
+
188
+ Subpath: `@sakeetech/viva-payments-core/isv`.
189
+
190
+ ```ts
191
+ new IsvSources(basic: BasicAuthClient); // MUST be authVariant: 'reseller'
192
+ ```
193
+
194
+ | Method | Description |
195
+ |---|---|
196
+ | `createEcommerceSource(input)` | `POST /api/sources` (legacy host, Reseller Basic auth). Creates a Smart Checkout source for a connected merchant. |
197
+ | `createPhysicalSource(input)` | Same endpoint, for in-store / physical sources. |
198
+
199
+ ISV-only. The Medusa / Vendure admin route surfaces this as
200
+ `POST /viva/admin/connected-accounts/:id/sources`.
201
+
202
+ ### `validateStatusTransition` + `mapStatusLetter`
203
+
204
+ Subpath: `@sakeetech/viva-payments-core/webhooks`. Pure functions —
205
+ no I/O.
206
+
207
+ ```ts
208
+ mapStatusLetter(letter: 'F' | 'C' | 'A' | 'R' | 'E' | 'X' | 'M' | ...): {
209
+ plugin: 'pending' | 'authorized' | 'captured' | 'refunded' | 'failed' | 'cancelled' | 'disputed';
210
+ framework: 'authorized' | 'captured' | 'refunded' | 'error' | 'canceled' | 'requires_more';
211
+ };
212
+
213
+ validateStatusTransition(current, next): StatusTransitionResult;
214
+ ```
215
+
216
+ The lattice is monotonic forward — redelivered events on terminal states
217
+ are no-ops; backward transitions log WARN; illegal transitions log ERROR
218
+ and leave `processed_at NULL`. Full table:
219
+ [`docs/STATE-MACHINE.md`](https://github.com/sakee-tech/vivawallet-npm-public/blob/main/docs/STATE-MACHINE.md).
220
+
221
+ ---
222
+
223
+ ## Error classes
224
+
225
+ Subpath: `@sakeetech/viva-payments-core/errors`. Every public method
226
+ throws one of these.
227
+
228
+ | Class | Thrown when |
229
+ |---|---|
230
+ | `VivaError` | Abstract base. All others extend this. Carries `code: VivaErrorCode`, `message`, `retryable: boolean`, optional `vivaErrorCode` / `vivaErrorMessage` / `cause`. |
231
+ | `VivaAuthError` | OAuth2 token endpoint unavailable, 401 after force-refresh, or auth-layer misconfig. `retryable: true` for transient. |
232
+ | `VivaApiError` | Viva returned a 4xx/5xx that doesn't map to a more specific code. Carries the original HTTP status + Viva error code. |
233
+ | `VivaValidationError` | Local input validation failed (missing `merchantId` in ISV mode, invalid currency code, etc.). Never retryable. |
234
+ | `VivaWebhookError` | URL-verify mismatch, IP not allowlisted, HMAC verification failed. Never retryable. |
235
+ | `VivaRateLimitError` | Viva returned 429. Carries `retryAfterSeconds`. Retryable per backoff schedule. |
236
+ | `VivaModeMismatchError` | ISV-only API called when client was constructed with `mode: 'merchant'` (or vice versa). |
237
+
238
+ Full envelope shape, Viva→plugin code mapping, and per-code retryable
239
+ flag in [`docs/ERRORS.md`](https://github.com/sakee-tech/vivawallet-npm-public/blob/main/docs/ERRORS.md).
240
+
241
+ ---
242
+
243
+ ## Mode-aware behaviour
244
+
245
+ Two surfaces in this SDK switch behaviour by mode.
246
+
247
+ **`Payments`** is constructed with `mode: 'merchant' | 'isv'`. The URL
248
+ builder for `createOrder`, `retrieveTransaction`, and `cancelOrder`
249
+ toggles the `/isv` segment and the `?merchantId={uuid}` query param.
250
+ `refundPayment` is mode-agnostic — it always uses `legacyClient` against
251
+ the legacy host (probe F1 verified). In merchant mode, `merchantId` and
252
+ `isvAmount` are silently ignored; in ISV mode, `merchantId` is required.
253
+
254
+ **`BasicAuthClient`** takes `authVariant: 'merchant' | 'reseller'`. The
255
+ merchant variant authenticates with `merchantId + apiKey` (the standard
256
+ legacy Basic pair, used for refunds in both modes). The reseller variant
257
+ authenticates with `resellerId + merchantId + resellerApiKey` and is only
258
+ used for `POST /api/sources` in ISV mode. The two variants share the
259
+ same HTTP client; only the `Authorization` header differs.
260
+
261
+ Auth flow detail in [`docs/AUTH.md`](https://github.com/sakee-tech/vivawallet-npm-public/blob/main/docs/AUTH.md). Endpoint
262
+ matrices per mode in [`docs/ENDPOINTS.md`](https://github.com/sakee-tech/vivawallet-npm-public/blob/main/docs/ENDPOINTS.md) §2.
263
+
264
+ ---
265
+
266
+ ## Deprecated aliases (`0.2.x` only — removed in `0.3.0`)
267
+
268
+ The pre-multi-mode classes still ship as wrappers for one-minor
269
+ back-compat.
270
+
271
+ | Deprecated | Use instead |
272
+ |---|---|
273
+ | `IsvPayments` (from `/isv`) | `Payments` from `/payments` with `mode: 'isv'` explicitly set. |
274
+ | `LegacyBasicClient` (from `/isv`) | `BasicAuthClient` from `/legacy` with `authVariant: 'merchant'`. |
275
+ | `LegacyBasicClientConfig` | `BasicAuthClientConfig`. |
276
+
277
+ Both aliases preserve the pre-slice constructor signatures and pin the
278
+ correct mode / variant internally. They emit no warnings at runtime — the
279
+ deprecation marker is the JSDoc tag — but they will be **deleted** in
280
+ `0.3.0`. Migration steps:
281
+ [`docs/MIGRATION-0.1-to-0.2.md`](https://github.com/sakee-tech/vivawallet-npm-public/blob/main/docs/MIGRATION-0.1-to-0.2.md).
282
+
283
+ ---
284
+
285
+ ## Example — construct everything for ISV mode
286
+
287
+ The Medusa and Vendure adapters do this internally; you generally won't
288
+ call the SDK directly. Shown here as a reference for custom integrations.
289
+
290
+ ```ts
291
+ import {
292
+ OAuth2ClientCredentialsStrategy,
293
+ InMemoryTokenCache,
294
+ AsyncMutex,
295
+ getAuthDispatcher,
296
+ getApiDispatcher,
297
+ } from '@sakeetech/viva-payments-core/auth';
298
+ import { IsvHttpClient } from '@sakeetech/viva-payments-core/isv';
299
+ import { BasicAuthClient } from '@sakeetech/viva-payments-core/legacy';
300
+ import { Payments } from '@sakeetech/viva-payments-core/payments';
301
+ import { FastRefundClient } from '@sakeetech/viva-payments-core/refunds';
302
+ import { IsvAccounts, IsvWebhooks, IsvSources } from '@sakeetech/viva-payments-core/isv';
303
+ import { StructuredJsonLogger } from '@sakeetech/viva-payments-core/observability';
304
+
305
+ const env = 'demo' as const;
306
+ const logger = new StructuredJsonLogger();
307
+
308
+ // 1. OAuth2 strategy — token cache + single-flight refresh.
309
+ const oauth2 = new OAuth2ClientCredentialsStrategy({
310
+ environment: env,
311
+ clientId: process.env.VIVA_CLIENT_ID!,
312
+ clientSecret: process.env.VIVA_CLIENT_SECRET!,
313
+ scope: 'urn:viva:payments:core:api:isv urn:viva:payments:core:api:acquiring',
314
+ tokenCache: new InMemoryTokenCache(),
315
+ refreshMutex: new AsyncMutex(),
316
+ dispatcher: getAuthDispatcher(),
317
+ });
318
+
319
+ // 2. OAuth2 HTTP client — wraps undici fetch with the strategy.
320
+ const isvClient = new IsvHttpClient({
321
+ environment: env,
322
+ authStrategy: oauth2,
323
+ dispatcher: getApiDispatcher(),
324
+ logger,
325
+ });
326
+
327
+ // 3. Legacy Basic client — required for refundPayment().
328
+ const legacy = new BasicAuthClient({
329
+ authVariant: 'merchant',
330
+ environment: env,
331
+ merchantId: process.env.VIVA_MERCHANT_ID!,
332
+ apiKey: process.env.VIVA_API_KEY!,
333
+ });
334
+
335
+ // 4. Mode-aware Smart Checkout client.
336
+ const payments = new Payments({
337
+ mode: 'isv',
338
+ client: isvClient,
339
+ legacyClient: legacy,
340
+ });
341
+
342
+ // 5. Fast Refund (optional — `resolveRefundStrategy` decides whether to use it).
343
+ const fastRefund = new FastRefundClient({
344
+ client: isvClient,
345
+ environment: env,
346
+ });
347
+
348
+ // 6. ISV-only surfaces.
349
+ const accounts = new IsvAccounts(isvClient);
350
+ const webhooks = new IsvWebhooks(isvClient);
351
+
352
+ // Reseller Basic client + sources — only if VIVA_RESELLER_* are set.
353
+ const resellerBasic = new BasicAuthClient({
354
+ authVariant: 'reseller',
355
+ environment: env,
356
+ resellerId: process.env.VIVA_RESELLER_ID!,
357
+ merchantId: process.env.VIVA_RESELLER_MERCHANT_ID!,
358
+ resellerApiKey: process.env.VIVA_RESELLER_API_KEY!,
359
+ });
360
+ const sources = new IsvSources(resellerBasic);
361
+
362
+ // Now use:
363
+ const order = await payments.createOrder(
364
+ { amount: 9999n, currencyCode: '978', merchantId: 'uuid-of-connected-merchant', ... },
365
+ );
366
+ ```
367
+
368
+ For merchant mode, swap `mode: 'isv'` → `mode: 'merchant'`, change the
369
+ OAuth2 scope to `urn:viva:payments:core:api:redirectcheckout
370
+ urn:viva:payments:core:api:acquiring`, drop `IsvAccounts` / `IsvWebhooks`
371
+ / `IsvSources`, and stop passing `merchantId` to `createOrder`.
372
+
373
+ ---
374
+
375
+ ## Versioning
376
+
377
+ Semver. Breaking changes only on major bumps. `0.x` minors may introduce
378
+ new subpath exports and new method overloads, but won't break existing
379
+ public signatures. Deprecated aliases get **one** minor of back-compat
380
+ before deletion.
381
+
382
+ See [`CHANGELOG.md`](./CHANGELOG.md). The monorepo uses
383
+ [changesets](https://github.com/changesets/changesets) — all three
384
+ packages bump together.
385
+
386
+ ---
387
+
388
+ ## Tests + development
389
+
390
+ ```bash
391
+ pnpm test # vitest — 242 tests at the time of writing
392
+ pnpm typecheck # tsc --noEmit
393
+ pnpm build # tsc emit → dist/
394
+ ```
395
+
396
+ The test suite covers unit tests per module plus sandbox-shaped scenario
397
+ tests (duplicate webhook delivery, status lattice transitions, token
398
+ single-flight contention, etc.). All tests run hermetically — no network
399
+ calls. The live-sandbox probes live in `scripts/` at the repo root and are
400
+ run manually.
401
+
402
+ ---
403
+
404
+ ## License
405
+
406
+ MIT. See [`LICENSE`](./LICENSE).
407
+
408
+ ## Contributing
409
+
410
+ Internal SaaS use for now. Contributions welcome once `0.2.0` stabilises
411
+ after the first live demo. Any behaviour change should reference the
412
+ locked decision it touches (auth, endpoints, webhooks, errors, state
413
+ machine) in [`docs/`](../../docs).
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Shared undici Pool dispatchers for outbound Viva API calls.
3
+ *
4
+ * Two separate pools are maintained — one per host — because the auth
5
+ * endpoint (`/connect/token`) and the API endpoint live on different hosts.
6
+ * Mixing them in one pool would route all requests to a single origin.
7
+ *
8
+ * @see references/viva-docs/md/oauth2-authentication.txt:145 (environment URLs)
9
+ * @see references/viva-docs/md/oauth2-authentication.txt:145 (demo vs production hosts)
10
+ */
11
+ import { type Dispatcher } from 'undici';
12
+ import type { VivaEnvironment } from '../types/common.js';
13
+ export type { VivaEnvironment };
14
+ export interface VivaHttpConfig {
15
+ /** 'demo' | 'production' */
16
+ environment: VivaEnvironment;
17
+ /** Optional dispatcher override — use in unit tests with MockAgent. */
18
+ dispatcher?: Dispatcher;
19
+ }
20
+ /**
21
+ * Returns a memoized undici Pool for the auth host (`/connect/token`).
22
+ *
23
+ * @see references/viva-docs/md/oauth2-authentication.txt:145
24
+ * Demo: https://demo-accounts.vivapayments.com
25
+ * Production: https://accounts.vivapayments.com
26
+ */
27
+ export declare function getAuthDispatcher(env: VivaEnvironment): Dispatcher;
28
+ /**
29
+ * Returns a memoized undici Pool for the Viva API host.
30
+ *
31
+ * @see references/viva-docs/md/oauth2-authentication.txt:145
32
+ * Demo: https://demo-api.vivapayments.com
33
+ * Production: https://api.vivapayments.com
34
+ */
35
+ export declare function getApiDispatcher(env: VivaEnvironment): Dispatcher;
36
+ /**
37
+ * Closes all memoized pools. Call this in test `afterAll` hooks and during
38
+ * graceful process shutdown to avoid open-handle warnings.
39
+ *
40
+ * Note: dispatchers are process-shared; tests MUST call `closeAllDispatchers()`
41
+ * in `afterAll` when injecting a `MockAgent` to avoid cross-test leaks.
42
+ */
43
+ export declare function closeAllDispatchers(): Promise<void>;
44
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/auth/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,YAAY,EAAE,eAAe,EAAE,CAAC;AAEhC,MAAM,WAAW,cAAc;IAC7B,4BAA4B;IAC5B,WAAW,EAAE,eAAe,CAAC;IAC7B,uEAAuE;IACvE,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAoBD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,eAAe,GAAG,UAAU,CAQlE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,eAAe,GAAG,UAAU,CAQjE;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAWzD"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Shared undici Pool dispatchers for outbound Viva API calls.
3
+ *
4
+ * Two separate pools are maintained — one per host — because the auth
5
+ * endpoint (`/connect/token`) and the API endpoint live on different hosts.
6
+ * Mixing them in one pool would route all requests to a single origin.
7
+ *
8
+ * @see references/viva-docs/md/oauth2-authentication.txt:145 (environment URLs)
9
+ * @see references/viva-docs/md/oauth2-authentication.txt:145 (demo vs production hosts)
10
+ */
11
+ import { Pool } from 'undici';
12
+ import { ENVIRONMENT_URLS } from '../types/common.js';
13
+ /**
14
+ * Pool connection settings shared across auth and API dispatchers.
15
+ * Keep-alive is enabled with a 30 s idle timeout and a 10-minute max.
16
+ * Pipelining is deliberately set to 1 (safe default for HTTP/1.1 APIs).
17
+ */
18
+ const POOL_OPTIONS = {
19
+ connections: 8,
20
+ keepAliveTimeout: 30_000,
21
+ keepAliveMaxTimeout: 600_000,
22
+ pipelining: 1,
23
+ bodyTimeout: 30_000,
24
+ headersTimeout: 30_000,
25
+ };
26
+ /** Lazily created, memoized per-host pools. */
27
+ const authPools = new Map();
28
+ const apiPools = new Map();
29
+ /**
30
+ * Returns a memoized undici Pool for the auth host (`/connect/token`).
31
+ *
32
+ * @see references/viva-docs/md/oauth2-authentication.txt:145
33
+ * Demo: https://demo-accounts.vivapayments.com
34
+ * Production: https://accounts.vivapayments.com
35
+ */
36
+ export function getAuthDispatcher(env) {
37
+ let pool = authPools.get(env);
38
+ if (!pool) {
39
+ const { authBaseUrl } = ENVIRONMENT_URLS[env];
40
+ pool = new Pool(authBaseUrl, POOL_OPTIONS);
41
+ authPools.set(env, pool);
42
+ }
43
+ return pool;
44
+ }
45
+ /**
46
+ * Returns a memoized undici Pool for the Viva API host.
47
+ *
48
+ * @see references/viva-docs/md/oauth2-authentication.txt:145
49
+ * Demo: https://demo-api.vivapayments.com
50
+ * Production: https://api.vivapayments.com
51
+ */
52
+ export function getApiDispatcher(env) {
53
+ let pool = apiPools.get(env);
54
+ if (!pool) {
55
+ const { apiBaseUrl } = ENVIRONMENT_URLS[env];
56
+ pool = new Pool(apiBaseUrl, POOL_OPTIONS);
57
+ apiPools.set(env, pool);
58
+ }
59
+ return pool;
60
+ }
61
+ /**
62
+ * Closes all memoized pools. Call this in test `afterAll` hooks and during
63
+ * graceful process shutdown to avoid open-handle warnings.
64
+ *
65
+ * Note: dispatchers are process-shared; tests MUST call `closeAllDispatchers()`
66
+ * in `afterAll` when injecting a `MockAgent` to avoid cross-test leaks.
67
+ */
68
+ export async function closeAllDispatchers() {
69
+ const closers = [];
70
+ for (const pool of authPools.values()) {
71
+ closers.push(pool.close());
72
+ }
73
+ for (const pool of apiPools.values()) {
74
+ closers.push(pool.close());
75
+ }
76
+ authPools.clear();
77
+ apiPools.clear();
78
+ await Promise.all(closers);
79
+ }
80
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/auth/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAmB,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAatD;;;;GAIG;AACH,MAAM,YAAY,GAA0C;IAC1D,WAAW,EAAE,CAAC;IACd,gBAAgB,EAAE,MAAM;IACxB,mBAAmB,EAAE,OAAO;IAC5B,UAAU,EAAE,CAAC;IACb,WAAW,EAAE,MAAM;IACnB,cAAc,EAAE,MAAM;CACvB,CAAC;AAEF,+CAA+C;AAC/C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;AACnD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAoB;IACpD,IAAI,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,EAAE,WAAW,EAAE,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,GAAG,IAAI,IAAI,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QAC3C,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAoB;IACnD,IAAI,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,EAAE,UAAU,EAAE,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAC7C,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QAC1C,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,MAAM,OAAO,GAAoB,EAAE,CAAC;IACpC,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;QACtC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAC7B,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAC7B,CAAC;IACD,SAAS,CAAC,KAAK,EAAE,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * viva-payments-core/auth — barrel export.
3
+ *
4
+ * Subpath: `viva-payments-core/auth`
5
+ *
6
+ * Exports auth strategies, token cache types, single-flight primitives,
7
+ * and HTTP dispatcher helpers for re-use by S3 (ISV calls).
8
+ */
9
+ export { OAuth2ClientCredentialsStrategy } from './oauth2-strategy.js';
10
+ export type { OAuth2StrategyOptions } from './oauth2-strategy.js';
11
+ export { ResellerBasicAuthStrategy } from './reseller-strategy.js';
12
+ export type { ResellerStrategyOptions } from './reseller-strategy.js';
13
+ export { InMemoryTokenCache, RedisTokenCache } from './token-cache.js';
14
+ export type { TokenCache, RedisTokenCacheClient } from './token-cache.js';
15
+ export { AsyncMutex, singleFlight, noopRedisLock } from './single-flight.js';
16
+ export type { RedisLockClient } from './single-flight.js';
17
+ export { getAuthDispatcher, getApiDispatcher, closeAllDispatchers } from './http.js';
18
+ export type { VivaHttpConfig } from './http.js';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AACvE,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAGtE,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACvE,YAAY,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAG1E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC7E,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrF,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * viva-payments-core/auth — barrel export.
3
+ *
4
+ * Subpath: `viva-payments-core/auth`
5
+ *
6
+ * Exports auth strategies, token cache types, single-flight primitives,
7
+ * and HTTP dispatcher helpers for re-use by S3 (ISV calls).
8
+ */
9
+ // Strategies
10
+ export { OAuth2ClientCredentialsStrategy } from './oauth2-strategy.js';
11
+ export { ResellerBasicAuthStrategy } from './reseller-strategy.js';
12
+ // Token cache
13
+ export { InMemoryTokenCache, RedisTokenCache } from './token-cache.js';
14
+ // Single-flight primitives (exposed for SaaS to wire Redis)
15
+ export { AsyncMutex, singleFlight, noopRedisLock } from './single-flight.js';
16
+ // HTTP dispatcher (re-exported so S3 can share the same pools)
17
+ export { getAuthDispatcher, getApiDispatcher, closeAllDispatchers } from './http.js';
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,aAAa;AACb,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AAGvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAGnE,cAAc;AACd,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGvE,4DAA4D;AAC5D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAG7E,+DAA+D;AAC/D,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}