@tagadapay/node-sdk 0.1.0

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 (198) hide show
  1. package/README.md +92 -0
  2. package/dist/HttpClient.d.ts +31 -0
  3. package/dist/HttpClient.d.ts.map +1 -0
  4. package/dist/HttpClient.js +258 -0
  5. package/dist/HttpClient.js.map +1 -0
  6. package/dist/Tagada.d.ts +93 -0
  7. package/dist/Tagada.d.ts.map +1 -0
  8. package/dist/Tagada.js +98 -0
  9. package/dist/Tagada.js.map +1 -0
  10. package/dist/errors/TagadaError.d.ts +71 -0
  11. package/dist/errors/TagadaError.d.ts.map +1 -0
  12. package/dist/errors/TagadaError.js +94 -0
  13. package/dist/errors/TagadaError.js.map +1 -0
  14. package/dist/errors/index.d.ts +2 -0
  15. package/dist/errors/index.d.ts.map +1 -0
  16. package/dist/errors/index.js +2 -0
  17. package/dist/errors/index.js.map +1 -0
  18. package/dist/index.d.ts +6 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +5 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/resources/BaseResource.d.ts +21 -0
  23. package/dist/resources/BaseResource.d.ts.map +1 -0
  24. package/dist/resources/BaseResource.js +41 -0
  25. package/dist/resources/BaseResource.js.map +1 -0
  26. package/dist/resources/BlockRules.d.ts +11 -0
  27. package/dist/resources/BlockRules.d.ts.map +1 -0
  28. package/dist/resources/BlockRules.js +19 -0
  29. package/dist/resources/BlockRules.js.map +1 -0
  30. package/dist/resources/Checkout.d.ts +32 -0
  31. package/dist/resources/Checkout.d.ts.map +1 -0
  32. package/dist/resources/Checkout.js +54 -0
  33. package/dist/resources/Checkout.js.map +1 -0
  34. package/dist/resources/CheckoutOffers.d.ts +27 -0
  35. package/dist/resources/CheckoutOffers.d.ts.map +1 -0
  36. package/dist/resources/CheckoutOffers.js +29 -0
  37. package/dist/resources/CheckoutOffers.js.map +1 -0
  38. package/dist/resources/Customers.d.ts +18 -0
  39. package/dist/resources/Customers.d.ts.map +1 -0
  40. package/dist/resources/Customers.js +23 -0
  41. package/dist/resources/Customers.js.map +1 -0
  42. package/dist/resources/Domains.d.ts +29 -0
  43. package/dist/resources/Domains.d.ts.map +1 -0
  44. package/dist/resources/Domains.js +28 -0
  45. package/dist/resources/Domains.js.map +1 -0
  46. package/dist/resources/Events.d.ts +22 -0
  47. package/dist/resources/Events.d.ts.map +1 -0
  48. package/dist/resources/Events.js +29 -0
  49. package/dist/resources/Events.js.map +1 -0
  50. package/dist/resources/Funnels.d.ts +39 -0
  51. package/dist/resources/Funnels.d.ts.map +1 -0
  52. package/dist/resources/Funnels.js +46 -0
  53. package/dist/resources/Funnels.js.map +1 -0
  54. package/dist/resources/Offers.d.ts +31 -0
  55. package/dist/resources/Offers.d.ts.map +1 -0
  56. package/dist/resources/Offers.js +35 -0
  57. package/dist/resources/Offers.js.map +1 -0
  58. package/dist/resources/Orders.d.ts +16 -0
  59. package/dist/resources/Orders.d.ts.map +1 -0
  60. package/dist/resources/Orders.js +17 -0
  61. package/dist/resources/Orders.js.map +1 -0
  62. package/dist/resources/PaymentFlows.d.ts +62 -0
  63. package/dist/resources/PaymentFlows.d.ts.map +1 -0
  64. package/dist/resources/PaymentFlows.js +71 -0
  65. package/dist/resources/PaymentFlows.js.map +1 -0
  66. package/dist/resources/PaymentInstruments.d.ts +28 -0
  67. package/dist/resources/PaymentInstruments.d.ts.map +1 -0
  68. package/dist/resources/PaymentInstruments.js +30 -0
  69. package/dist/resources/PaymentInstruments.js.map +1 -0
  70. package/dist/resources/Payments.d.ts +54 -0
  71. package/dist/resources/Payments.d.ts.map +1 -0
  72. package/dist/resources/Payments.js +61 -0
  73. package/dist/resources/Payments.js.map +1 -0
  74. package/dist/resources/Plugins.d.ts +60 -0
  75. package/dist/resources/Plugins.d.ts.map +1 -0
  76. package/dist/resources/Plugins.js +80 -0
  77. package/dist/resources/Plugins.js.map +1 -0
  78. package/dist/resources/Processors.d.ts +54 -0
  79. package/dist/resources/Processors.d.ts.map +1 -0
  80. package/dist/resources/Processors.js +54 -0
  81. package/dist/resources/Processors.js.map +1 -0
  82. package/dist/resources/Products.d.ts +28 -0
  83. package/dist/resources/Products.d.ts.map +1 -0
  84. package/dist/resources/Products.js +24 -0
  85. package/dist/resources/Products.js.map +1 -0
  86. package/dist/resources/Promotions.d.ts +19 -0
  87. package/dist/resources/Promotions.d.ts.map +1 -0
  88. package/dist/resources/Promotions.js +33 -0
  89. package/dist/resources/Promotions.js.map +1 -0
  90. package/dist/resources/Stores.d.ts +18 -0
  91. package/dist/resources/Stores.d.ts.map +1 -0
  92. package/dist/resources/Stores.js +23 -0
  93. package/dist/resources/Stores.js.map +1 -0
  94. package/dist/resources/Subscriptions.d.ts +45 -0
  95. package/dist/resources/Subscriptions.d.ts.map +1 -0
  96. package/dist/resources/Subscriptions.js +49 -0
  97. package/dist/resources/Subscriptions.js.map +1 -0
  98. package/dist/resources/Webhooks.d.ts +29 -0
  99. package/dist/resources/Webhooks.d.ts.map +1 -0
  100. package/dist/resources/Webhooks.js +30 -0
  101. package/dist/resources/Webhooks.js.map +1 -0
  102. package/dist/resources/index.d.ts +21 -0
  103. package/dist/resources/index.d.ts.map +1 -0
  104. package/dist/resources/index.js +21 -0
  105. package/dist/resources/index.js.map +1 -0
  106. package/dist/types/blockRules.d.ts +18 -0
  107. package/dist/types/blockRules.d.ts.map +1 -0
  108. package/dist/types/blockRules.js +5 -0
  109. package/dist/types/blockRules.js.map +1 -0
  110. package/dist/types/checkout-offers.d.ts +62 -0
  111. package/dist/types/checkout-offers.d.ts.map +1 -0
  112. package/dist/types/checkout-offers.js +5 -0
  113. package/dist/types/checkout-offers.js.map +1 -0
  114. package/dist/types/checkout.d.ts +55 -0
  115. package/dist/types/checkout.d.ts.map +1 -0
  116. package/dist/types/checkout.js +5 -0
  117. package/dist/types/checkout.js.map +1 -0
  118. package/dist/types/common.d.ts +42 -0
  119. package/dist/types/common.d.ts.map +1 -0
  120. package/dist/types/common.js +5 -0
  121. package/dist/types/common.js.map +1 -0
  122. package/dist/types/customers.d.ts +41 -0
  123. package/dist/types/customers.d.ts.map +1 -0
  124. package/dist/types/customers.js +2 -0
  125. package/dist/types/customers.js.map +1 -0
  126. package/dist/types/domains.d.ts +18 -0
  127. package/dist/types/domains.d.ts.map +1 -0
  128. package/dist/types/domains.js +5 -0
  129. package/dist/types/domains.js.map +1 -0
  130. package/dist/types/events.d.ts +47 -0
  131. package/dist/types/events.d.ts.map +1 -0
  132. package/dist/types/events.js +2 -0
  133. package/dist/types/events.js.map +1 -0
  134. package/dist/types/funnels.d.ts +160 -0
  135. package/dist/types/funnels.d.ts.map +1 -0
  136. package/dist/types/funnels.js +5 -0
  137. package/dist/types/funnels.js.map +1 -0
  138. package/dist/types/index.d.ts +20 -0
  139. package/dist/types/index.d.ts.map +1 -0
  140. package/dist/types/index.js +20 -0
  141. package/dist/types/index.js.map +1 -0
  142. package/dist/types/offers.d.ts +76 -0
  143. package/dist/types/offers.d.ts.map +1 -0
  144. package/dist/types/offers.js +5 -0
  145. package/dist/types/offers.js.map +1 -0
  146. package/dist/types/orders.d.ts +50 -0
  147. package/dist/types/orders.d.ts.map +1 -0
  148. package/dist/types/orders.js +2 -0
  149. package/dist/types/orders.js.map +1 -0
  150. package/dist/types/paymentFlows.d.ts +55 -0
  151. package/dist/types/paymentFlows.d.ts.map +1 -0
  152. package/dist/types/paymentFlows.js +5 -0
  153. package/dist/types/paymentFlows.js.map +1 -0
  154. package/dist/types/paymentInstruments.d.ts +49 -0
  155. package/dist/types/paymentInstruments.d.ts.map +1 -0
  156. package/dist/types/paymentInstruments.js +2 -0
  157. package/dist/types/paymentInstruments.js.map +1 -0
  158. package/dist/types/payments.d.ts +139 -0
  159. package/dist/types/payments.d.ts.map +1 -0
  160. package/dist/types/payments.js +2 -0
  161. package/dist/types/payments.js.map +1 -0
  162. package/dist/types/plugins.d.ts +116 -0
  163. package/dist/types/plugins.d.ts.map +1 -0
  164. package/dist/types/plugins.js +5 -0
  165. package/dist/types/plugins.js.map +1 -0
  166. package/dist/types/processors.d.ts +34 -0
  167. package/dist/types/processors.d.ts.map +1 -0
  168. package/dist/types/processors.js +5 -0
  169. package/dist/types/processors.js.map +1 -0
  170. package/dist/types/products.d.ts +68 -0
  171. package/dist/types/products.d.ts.map +1 -0
  172. package/dist/types/products.js +5 -0
  173. package/dist/types/products.js.map +1 -0
  174. package/dist/types/promotions.d.ts +36 -0
  175. package/dist/types/promotions.d.ts.map +1 -0
  176. package/dist/types/promotions.js +5 -0
  177. package/dist/types/promotions.js.map +1 -0
  178. package/dist/types/stores.d.ts +26 -0
  179. package/dist/types/stores.d.ts.map +1 -0
  180. package/dist/types/stores.js +2 -0
  181. package/dist/types/stores.js.map +1 -0
  182. package/dist/types/subscriptions.d.ts +74 -0
  183. package/dist/types/subscriptions.d.ts.map +1 -0
  184. package/dist/types/subscriptions.js +5 -0
  185. package/dist/types/subscriptions.js.map +1 -0
  186. package/dist/types/webhooks.d.ts +18 -0
  187. package/dist/types/webhooks.d.ts.map +1 -0
  188. package/dist/types/webhooks.js +5 -0
  189. package/dist/types/webhooks.js.map +1 -0
  190. package/dist/utils/index.d.ts +2 -0
  191. package/dist/utils/index.d.ts.map +1 -0
  192. package/dist/utils/index.js +2 -0
  193. package/dist/utils/index.js.map +1 -0
  194. package/dist/utils/sleep.d.ts +2 -0
  195. package/dist/utils/sleep.d.ts.map +1 -0
  196. package/dist/utils/sleep.js +4 -0
  197. package/dist/utils/sleep.js.map +1 -0
  198. package/package.json +74 -0
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # @tagadapay/node-sdk
2
+
3
+ Server-side Node.js SDK for [TagadaPay](https://tagadapay.com) — the PSP-agnostic payment orchestration platform.
4
+
5
+ Use this SDK to programmatically create stores, deploy checkout pages, set up funnels, process payments, and manage your entire checkout infrastructure from code.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @tagadapay/node-sdk
11
+ ```
12
+
13
+ Requires Node.js 18+.
14
+
15
+ ## Quick Start
16
+
17
+ ```ts
18
+ import Tagada from '@tagadapay/node-sdk';
19
+
20
+ const tagada = new Tagada('tgd_live_...');
21
+
22
+ // List stores
23
+ const stores = await tagada.stores.list();
24
+
25
+ // Process a payment
26
+ const { payment } = await tagada.payments.process({
27
+ amount: 4999,
28
+ currency: 'USD',
29
+ storeId: 'store_xxx',
30
+ paymentInstrumentId: 'pi_xxx',
31
+ });
32
+ ```
33
+
34
+ ## What Can You Do With It?
35
+
36
+ | Resource | What it does |
37
+ | --- | --- |
38
+ | `tagada.stores` | Create and manage stores |
39
+ | `tagada.products` | Create products with variants and pricing |
40
+ | `tagada.payments` | Process, refund, and void payments |
41
+ | `tagada.paymentFlows` | Configure PSP routing (cascade, weighted, failover) |
42
+ | `tagada.funnels` | Create multi-step funnels (checkout → upsell → thank you) |
43
+ | `tagada.plugins` | Deploy pages, instantiate, mount to domains |
44
+ | `tagada.subscriptions` | Create and manage recurring billing |
45
+ | `tagada.customers` | Look up and manage customers |
46
+ | `tagada.orders` | Query orders |
47
+ | `tagada.webhooks` | Register webhook endpoints |
48
+ | `tagada.domains` | Add custom domains |
49
+ | `tagada.checkout` | Server-side checkout operations |
50
+ | `tagada.processors` | List connected payment processors |
51
+
52
+ ## Configuration
53
+
54
+ ```ts
55
+ const tagada = new Tagada({
56
+ apiKey: 'tgd_live_...',
57
+ baseUrl: 'https://app.tagadapay.com/api/public/v1',
58
+ timeout: 30_000,
59
+ maxRetries: 2,
60
+ });
61
+ ```
62
+
63
+ ## Error Handling
64
+
65
+ ```ts
66
+ import Tagada, {
67
+ TagadaNotFoundError,
68
+ TagadaValidationError,
69
+ TagadaAuthenticationError,
70
+ TagadaRateLimitError,
71
+ } from '@tagadapay/node-sdk';
72
+
73
+ try {
74
+ await tagada.payments.retrieve('pay_nonexistent');
75
+ } catch (err) {
76
+ if (err instanceof TagadaNotFoundError) {
77
+ // 404
78
+ } else if (err instanceof TagadaValidationError) {
79
+ console.log(err.errors); // field-level errors
80
+ } else if (err instanceof TagadaRateLimitError) {
81
+ console.log(`Retry after ${err.retryAfter}s`);
82
+ }
83
+ }
84
+ ```
85
+
86
+ ## Full Guide
87
+
88
+ See the [Node SDK guide](https://docs.tagadapay.com/developer-tools/node-sdk/quick-start) for a complete walkthrough with examples.
89
+
90
+ ## License
91
+
92
+ MIT
@@ -0,0 +1,31 @@
1
+ import type { RequestOptions, TagadaClientOptions } from './types/common.js';
2
+ export declare class HttpClient {
3
+ private readonly apiKey;
4
+ private readonly baseUrl;
5
+ private readonly timeout;
6
+ private readonly maxRetries;
7
+ private readonly apiVersion;
8
+ constructor(opts: TagadaClientOptions);
9
+ get<T>(path: string, query?: Record<string, unknown>, opts?: RequestOptions): Promise<T>;
10
+ post<T>(path: string, body?: unknown, opts?: RequestOptions): Promise<T>;
11
+ put<T>(path: string, body?: unknown, opts?: RequestOptions): Promise<T>;
12
+ del<T>(path: string, body?: unknown, opts?: RequestOptions): Promise<T>;
13
+ getRedirectUrl(path: string, query?: Record<string, unknown>, opts?: RequestOptions): Promise<string>;
14
+ private request;
15
+ private executeRequest;
16
+ private handleErrorResponse;
17
+ /**
18
+ * Extract a human-readable message from the API response. Handles ZSA error
19
+ * shapes where message can be a JSON string of Zod issues.
20
+ */
21
+ private extractMessage;
22
+ /**
23
+ * Extract structured validation errors from ZSA/Zod error responses.
24
+ */
25
+ private extractValidationErrors;
26
+ private buildUrl;
27
+ private buildHeaders;
28
+ private shouldRetry;
29
+ private retryDelay;
30
+ }
31
+ //# sourceMappingURL=HttpClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../src/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AA0B7E,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAA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LimitError, TagadaValidationError, TagadaConnectionError, TagadaTimeoutError, } from './errors/index.js';
2
+ import { sleep } from './utils/sleep.js';
3
+ const SDK_VERSION = '0.1.0';
4
+ const DEFAULT_BASE_URL = 'https://app.tagadapay.com/api/public/v1';
5
+ const DEFAULT_TIMEOUT = 30000;
6
+ const DEFAULT_MAX_RETRIES = 2;
7
+ const RETRYABLE_STATUS_CODES = new Set([408, 429, 500, 502, 503, 504]);
8
+ export class HttpClient {
9
+ constructor(opts) {
10
+ if (!opts.apiKey) {
11
+ throw new TagadaAuthenticationError({
12
+ message: 'No API key provided. Set it when initializing Tagada: new Tagada("tgd_live_...")',
13
+ });
14
+ }
15
+ this.apiKey = opts.apiKey;
16
+ this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
17
+ this.timeout = opts.timeout ?? DEFAULT_TIMEOUT;
18
+ this.maxRetries = opts.maxRetries ?? DEFAULT_MAX_RETRIES;
19
+ this.apiVersion = opts.apiVersion ?? '2025-01-01';
20
+ }
21
+ async get(path, query, opts) {
22
+ return this.request('GET', path, undefined, query, opts);
23
+ }
24
+ async post(path, body, opts) {
25
+ return this.request('POST', path, body, undefined, opts);
26
+ }
27
+ async put(path, body, opts) {
28
+ return this.request('PUT', path, body, undefined, opts);
29
+ }
30
+ async del(path, body, opts) {
31
+ return this.request('DELETE', path, body, undefined, opts);
32
+ }
33
+ async getRedirectUrl(path, query, opts) {
34
+ const url = this.buildUrl(path, query);
35
+ const headers = this.buildHeaders(opts);
36
+ const timeout = opts?.timeout ?? this.timeout;
37
+ const controller = new AbortController();
38
+ const timer = setTimeout(() => controller.abort(), timeout);
39
+ try {
40
+ const res = await fetch(url, {
41
+ method: 'GET',
42
+ headers,
43
+ signal: controller.signal,
44
+ redirect: 'manual',
45
+ });
46
+ const location = res.headers.get('location');
47
+ if (location)
48
+ return location;
49
+ if (!res.ok) {
50
+ const requestId = res.headers.get('x-request-id') ?? null;
51
+ await this.handleErrorResponse(res, requestId);
52
+ }
53
+ throw new TagadaAPIError({
54
+ message: 'Expected redirect response but got ' + res.status,
55
+ statusCode: res.status,
56
+ requestId: null,
57
+ code: null,
58
+ raw: null,
59
+ });
60
+ }
61
+ finally {
62
+ clearTimeout(timer);
63
+ }
64
+ }
65
+ async request(method, path, body, query, opts) {
66
+ const url = this.buildUrl(path, query);
67
+ const headers = this.buildHeaders(opts);
68
+ const timeout = opts?.timeout ?? this.timeout;
69
+ let lastError;
70
+ for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
71
+ try {
72
+ const response = await this.executeRequest(method, url, headers, body, timeout);
73
+ return response.data;
74
+ }
75
+ catch (err) {
76
+ lastError = err;
77
+ if (!this.shouldRetry(err, attempt)) {
78
+ throw err;
79
+ }
80
+ const delay = this.retryDelay(attempt, err);
81
+ await sleep(delay);
82
+ }
83
+ }
84
+ throw lastError;
85
+ }
86
+ async executeRequest(method, url, headers, body, timeout) {
87
+ const controller = new AbortController();
88
+ const timer = setTimeout(() => controller.abort(), timeout);
89
+ try {
90
+ const fetchOpts = {
91
+ method,
92
+ headers,
93
+ signal: controller.signal,
94
+ };
95
+ if (body !== undefined && method !== 'GET') {
96
+ fetchOpts.body = JSON.stringify(body);
97
+ }
98
+ const res = await fetch(url, fetchOpts);
99
+ const responseHeaders = {};
100
+ res.headers.forEach((value, key) => {
101
+ responseHeaders[key.toLowerCase()] = value;
102
+ });
103
+ const requestId = responseHeaders['x-request-id'] ?? null;
104
+ if (!res.ok) {
105
+ await this.handleErrorResponse(res, requestId);
106
+ }
107
+ const data = (await res.json());
108
+ return { data, status: res.status, headers: responseHeaders, requestId };
109
+ }
110
+ catch (err) {
111
+ if (err instanceof TagadaAPIError)
112
+ throw err;
113
+ if (err.name === 'AbortError') {
114
+ throw new TagadaTimeoutError(`Request timed out after ${timeout}ms`);
115
+ }
116
+ throw new TagadaConnectionError(`Failed to connect to ${url}: ${err.message}`);
117
+ }
118
+ finally {
119
+ clearTimeout(timer);
120
+ }
121
+ }
122
+ async handleErrorResponse(res, requestId) {
123
+ let raw;
124
+ try {
125
+ raw = await res.json();
126
+ }
127
+ catch {
128
+ raw = await res.text().catch(() => null);
129
+ }
130
+ const body = raw && typeof raw === 'object' ? raw : {};
131
+ const message = this.extractMessage(body, res.status);
132
+ const code = body.code ?? null;
133
+ switch (res.status) {
134
+ case 401:
135
+ throw new TagadaAuthenticationError({ message, requestId, raw });
136
+ case 403:
137
+ throw new TagadaPermissionError({ message, requestId, raw });
138
+ case 404:
139
+ throw new TagadaNotFoundError({ message, requestId, raw });
140
+ case 429: {
141
+ const retryAfter = res.headers.get('retry-after');
142
+ throw new TagadaRateLimitError({
143
+ message,
144
+ requestId,
145
+ retryAfter: retryAfter ? parseInt(retryAfter, 10) : null,
146
+ raw,
147
+ });
148
+ }
149
+ case 400:
150
+ case 422: {
151
+ const errors = this.extractValidationErrors(body);
152
+ throw new TagadaValidationError({ message, requestId, errors, raw });
153
+ }
154
+ default:
155
+ throw new TagadaAPIError({ message, statusCode: res.status, requestId, code, raw });
156
+ }
157
+ }
158
+ /**
159
+ * Extract a human-readable message from the API response. Handles ZSA error
160
+ * shapes where message can be a JSON string of Zod issues.
161
+ */
162
+ extractMessage(body, status) {
163
+ if (typeof body.message === 'string') {
164
+ return body.message;
165
+ }
166
+ if (typeof body.error === 'string') {
167
+ return body.error;
168
+ }
169
+ if (body.name === 'ZodError' && typeof body.data === 'string') {
170
+ try {
171
+ const issues = JSON.parse(body.data)?.issues;
172
+ if (Array.isArray(issues)) {
173
+ return issues.map((i) => `${i.path?.join('.')}: ${i.message}`).join('; ');
174
+ }
175
+ }
176
+ catch { /* ignore */ }
177
+ }
178
+ return `Request failed with status ${status}`;
179
+ }
180
+ /**
181
+ * Extract structured validation errors from ZSA/Zod error responses.
182
+ */
183
+ extractValidationErrors(body) {
184
+ if (Array.isArray(body.errors)) {
185
+ return body.errors;
186
+ }
187
+ if (body.fieldErrors && typeof body.fieldErrors === 'object') {
188
+ const errors = [];
189
+ for (const [field, msgs] of Object.entries(body.fieldErrors)) {
190
+ for (const msg of msgs) {
191
+ errors.push({ field, message: msg });
192
+ }
193
+ }
194
+ return errors;
195
+ }
196
+ if (typeof body.data === 'string') {
197
+ try {
198
+ const parsed = JSON.parse(body.data);
199
+ if (parsed.issues && Array.isArray(parsed.issues)) {
200
+ return parsed.issues.map((i) => ({
201
+ field: i.path?.join('.'),
202
+ message: i.message,
203
+ }));
204
+ }
205
+ }
206
+ catch { /* ignore */ }
207
+ }
208
+ return [];
209
+ }
210
+ buildUrl(path, query) {
211
+ const cleanPath = path.startsWith('/') ? path : `/${path}`;
212
+ const url = new URL(`${this.baseUrl}${cleanPath}`);
213
+ if (query) {
214
+ for (const [key, value] of Object.entries(query)) {
215
+ if (value !== undefined && value !== null) {
216
+ url.searchParams.set(key, String(value));
217
+ }
218
+ }
219
+ }
220
+ return url.toString();
221
+ }
222
+ buildHeaders(opts) {
223
+ const headers = {
224
+ Authorization: `Bearer ${this.apiKey}`,
225
+ 'Content-Type': 'application/json',
226
+ Accept: 'application/json',
227
+ 'User-Agent': `tagada-node/${SDK_VERSION}`,
228
+ 'X-Tagada-Api-Version': this.apiVersion,
229
+ };
230
+ if (opts?.idempotencyKey) {
231
+ headers['Idempotency-Key'] = opts.idempotencyKey;
232
+ }
233
+ if (opts?.headers) {
234
+ Object.assign(headers, opts.headers);
235
+ }
236
+ return headers;
237
+ }
238
+ shouldRetry(err, attempt) {
239
+ if (attempt >= this.maxRetries)
240
+ return false;
241
+ if (err instanceof TagadaRateLimitError)
242
+ return true;
243
+ if (err instanceof TagadaConnectionError)
244
+ return true;
245
+ if (err instanceof TagadaTimeoutError)
246
+ return true;
247
+ if (err instanceof TagadaAPIError && RETRYABLE_STATUS_CODES.has(err.statusCode))
248
+ return true;
249
+ return false;
250
+ }
251
+ retryDelay(attempt, err) {
252
+ if (err instanceof TagadaRateLimitError && err.retryAfter) {
253
+ return err.retryAfter * 1000;
254
+ }
255
+ return Math.min(500 * 2 ** attempt + Math.random() * 200, 10000);
256
+ }
257
+ }
258
+ //# sourceMappingURL=HttpClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpClient.js","sourceRoot":"","sources":["../src/HttpClient.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,MAAM,WAAW,GAAG,OAAO,CAAC;AAC5B,MAAM,gBAAgB,GAAG,yCAAyC,CAAC;AACnE,MAAM,eAAe,GAAG,KAAM,CAAC;AAC/B,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AASvE,MAAM,OAAO,UAAU;IAOrB,YAAY,IAAyB;QACnC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,yBAAyB,CAAC;gBAClC,OAAO,EACL,kFAAkF;aACrF,CAAC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,eAAe,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,mBAAmB,CAAC;QACzD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,YAAY,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,GAAG,CAAI,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AE,CAAC;YAC1D,OAAO,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,IAAI,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,EAAE,KAAM,CAAC,CAAC;IACpE,CAAC;CACF"}
@@ -0,0 +1,93 @@
1
+ import type { TagadaClientOptions } from './types/common.js';
2
+ import { Payments } from './resources/Payments.js';
3
+ import { Customers } from './resources/Customers.js';
4
+ import { Orders } from './resources/Orders.js';
5
+ import { Stores } from './resources/Stores.js';
6
+ import { Subscriptions } from './resources/Subscriptions.js';
7
+ import { Products } from './resources/Products.js';
8
+ import { Checkout } from './resources/Checkout.js';
9
+ import { PaymentFlows } from './resources/PaymentFlows.js';
10
+ import { PaymentInstruments } from './resources/PaymentInstruments.js';
11
+ import { Webhooks } from './resources/Webhooks.js';
12
+ import { Funnels } from './resources/Funnels.js';
13
+ import { Events } from './resources/Events.js';
14
+ import { Processors } from './resources/Processors.js';
15
+ import { Domains } from './resources/Domains.js';
16
+ import { Promotions, PromotionCodes } from './resources/Promotions.js';
17
+ import { BlockRules } from './resources/BlockRules.js';
18
+ import { Plugins } from './resources/Plugins.js';
19
+ import { Offers } from './resources/Offers.js';
20
+ import { CheckoutOffers } from './resources/CheckoutOffers.js';
21
+ /**
22
+ * The Tagada Node.js SDK client.
23
+ *
24
+ * Tagada is a **PSP/gateway-agnostic** payment orchestration platform.
25
+ * Connect any combination of payment processors (Stripe, Adyen, NMI,
26
+ * Checkout.com, etc.) and let Tagada handle intelligent routing, cascading
27
+ * fallbacks, 3DS, and recurring billing across all of them.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import Tagada from '@tagadapay/node-sdk';
32
+ *
33
+ * const tagada = new Tagada('tgd_live_...');
34
+ *
35
+ * // List payments
36
+ * const payments = await tagada.payments.list({
37
+ * filters: { status: ['captured'] },
38
+ * pagination: { page: 1, pageSize: 25 },
39
+ * });
40
+ *
41
+ * // Process a payment — Tagada routes it across your processors
42
+ * const { payment } = await tagada.payments.process({
43
+ * amount: 4999,
44
+ * currency: 'USD',
45
+ * storeId: 'store_xxx',
46
+ * paymentInstrumentId: 'pi_xxx',
47
+ * });
48
+ *
49
+ * // Create a cascading payment flow
50
+ * const flow = await tagada.paymentFlows.create({
51
+ * data: {
52
+ * name: 'US Flow',
53
+ * strategy: 'cascade',
54
+ * fallbackMode: 'sequential',
55
+ * maxFallbackRetries: 3,
56
+ * threeDsEnabled: true,
57
+ * stickyProcessorEnabled: false,
58
+ * pickProcessorStrategy: 'weighted',
59
+ * processorConfigs: [
60
+ * { processorId: 'proc_stripe', weight: 60 },
61
+ * { processorId: 'proc_adyen', weight: 40 },
62
+ * ],
63
+ * fallbackProcessorConfigs: [
64
+ * { processorId: 'proc_nmi', orderIndex: 0 },
65
+ * ],
66
+ * },
67
+ * });
68
+ * ```
69
+ */
70
+ export declare class Tagada {
71
+ readonly payments: Payments;
72
+ readonly customers: Customers;
73
+ readonly orders: Orders;
74
+ readonly stores: Stores;
75
+ readonly subscriptions: Subscriptions;
76
+ readonly products: Products;
77
+ readonly checkout: Checkout;
78
+ readonly paymentFlows: PaymentFlows;
79
+ readonly paymentInstruments: PaymentInstruments;
80
+ readonly webhooks: Webhooks;
81
+ readonly funnels: Funnels;
82
+ readonly events: Events;
83
+ readonly processors: Processors;
84
+ readonly domains: Domains;
85
+ readonly promotions: Promotions;
86
+ readonly promotionCodes: PromotionCodes;
87
+ readonly blockRules: BlockRules;
88
+ readonly plugins: Plugins;
89
+ readonly offers: Offers;
90
+ readonly checkoutOffers: CheckoutOffers;
91
+ constructor(apiKeyOrOptions: string | TagadaClientOptions);
92
+ }
93
+ //# sourceMappingURL=Tagada.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tagada.d.ts","sourceRoot":"","sources":["../src/Tagada.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM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,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAChD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;gBAE5B,eAAe,EAAE,MAAM,GAAG,mBAAmB;CA6B1D"}
package/dist/Tagada.js ADDED
@@ -0,0 +1,98 @@
1
+ import { HttpClient } from './HttpClient.js';
2
+ import { Payments } from './resources/Payments.js';
3
+ import { Customers } from './resources/Customers.js';
4
+ import { Orders } from './resources/Orders.js';
5
+ import { Stores } from './resources/Stores.js';
6
+ import { Subscriptions } from './resources/Subscriptions.js';
7
+ import { Products } from './resources/Products.js';
8
+ import { Checkout } from './resources/Checkout.js';
9
+ import { PaymentFlows } from './resources/PaymentFlows.js';
10
+ import { PaymentInstruments } from './resources/PaymentInstruments.js';
11
+ import { Webhooks } from './resources/Webhooks.js';
12
+ import { Funnels } from './resources/Funnels.js';
13
+ import { Events } from './resources/Events.js';
14
+ import { Processors } from './resources/Processors.js';
15
+ import { Domains } from './resources/Domains.js';
16
+ import { Promotions, PromotionCodes } from './resources/Promotions.js';
17
+ import { BlockRules } from './resources/BlockRules.js';
18
+ import { Plugins } from './resources/Plugins.js';
19
+ import { Offers } from './resources/Offers.js';
20
+ import { CheckoutOffers } from './resources/CheckoutOffers.js';
21
+ /**
22
+ * The Tagada Node.js SDK client.
23
+ *
24
+ * Tagada is a **PSP/gateway-agnostic** payment orchestration platform.
25
+ * Connect any combination of payment processors (Stripe, Adyen, NMI,
26
+ * Checkout.com, etc.) and let Tagada handle intelligent routing, cascading
27
+ * fallbacks, 3DS, and recurring billing across all of them.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import Tagada from '@tagadapay/node-sdk';
32
+ *
33
+ * const tagada = new Tagada('tgd_live_...');
34
+ *
35
+ * // List payments
36
+ * const payments = await tagada.payments.list({
37
+ * filters: { status: ['captured'] },
38
+ * pagination: { page: 1, pageSize: 25 },
39
+ * });
40
+ *
41
+ * // Process a payment — Tagada routes it across your processors
42
+ * const { payment } = await tagada.payments.process({
43
+ * amount: 4999,
44
+ * currency: 'USD',
45
+ * storeId: 'store_xxx',
46
+ * paymentInstrumentId: 'pi_xxx',
47
+ * });
48
+ *
49
+ * // Create a cascading payment flow
50
+ * const flow = await tagada.paymentFlows.create({
51
+ * data: {
52
+ * name: 'US Flow',
53
+ * strategy: 'cascade',
54
+ * fallbackMode: 'sequential',
55
+ * maxFallbackRetries: 3,
56
+ * threeDsEnabled: true,
57
+ * stickyProcessorEnabled: false,
58
+ * pickProcessorStrategy: 'weighted',
59
+ * processorConfigs: [
60
+ * { processorId: 'proc_stripe', weight: 60 },
61
+ * { processorId: 'proc_adyen', weight: 40 },
62
+ * ],
63
+ * fallbackProcessorConfigs: [
64
+ * { processorId: 'proc_nmi', orderIndex: 0 },
65
+ * ],
66
+ * },
67
+ * });
68
+ * ```
69
+ */
70
+ export class Tagada {
71
+ constructor(apiKeyOrOptions) {
72
+ const opts = typeof apiKeyOrOptions === 'string'
73
+ ? { apiKey: apiKeyOrOptions }
74
+ : apiKeyOrOptions;
75
+ const client = new HttpClient(opts);
76
+ this.payments = new Payments(client);
77
+ this.customers = new Customers(client);
78
+ this.orders = new Orders(client);
79
+ this.stores = new Stores(client);
80
+ this.subscriptions = new Subscriptions(client);
81
+ this.products = new Products(client);
82
+ this.checkout = new Checkout(client);
83
+ this.paymentFlows = new PaymentFlows(client);
84
+ this.paymentInstruments = new PaymentInstruments(client);
85
+ this.webhooks = new Webhooks(client);
86
+ this.funnels = new Funnels(client);
87
+ this.events = new Events(client);
88
+ this.processors = new Processors(client);
89
+ this.domains = new Domains(client);
90
+ this.promotions = new Promotions(client);
91
+ this.promotionCodes = new PromotionCodes(client);
92
+ this.blockRules = new BlockRules(client);
93
+ this.plugins = new Plugins(client);
94
+ this.offers = new Offers(client);
95
+ this.checkoutOffers = new CheckoutOffers(client);
96
+ }
97
+ }
98
+ //# sourceMappingURL=Tagada.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tagada.js","sourceRoot":"","sources":["../src/Tagada.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,QAAQ,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