@cosmosapp/pay_sdk 1.0.0 → 1.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.
- package/CHANGELOG.md +17 -0
- package/README.md +247 -8
- package/dist/chunk-RCLT7E4Y.js +216 -0
- package/dist/chunk-RCLT7E4Y.js.map +1 -0
- package/dist/index.cjs +176 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -431
- package/dist/index.d.ts +18 -431
- package/dist/index.js +7 -69
- package/dist/index.js.map +1 -1
- package/dist/intent-input-Caauq1Vl.d.cts +626 -0
- package/dist/intent-input-Caauq1Vl.d.ts +626 -0
- package/dist/web/index.cjs +1260 -0
- package/dist/web/index.cjs.map +1 -0
- package/dist/web/index.d.cts +758 -0
- package/dist/web/index.d.ts +758 -0
- package/dist/web/index.js +1015 -0
- package/dist/web/index.js.map +1 -0
- package/package.json +35 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,386 +1,8 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { A as AnalyticsSummaryData, a as AnalyticsBalancesData, b as ApiLogsData, W as WebhookLogsData, C as CustomerData, U as UpdateCustomerOptions, c as CreateCustomerOptions, H as HealthCheckData, P as PaymentIntentData, d as PaymentIntentKind, e as PaymentIntentStatus, f as UpdatePaymentIntentOptions, D as DeletedData, V as ValidationOutcomeData, g as CreateTxPaymentIntentOptions, h as CreatePayPaymentIntentOptions, L as ListPaymentIntentsOptions, i as ValidatePaymentIntentOptions, j as ProductData, k as ProductKind, l as UpdateProductOptions, m as CreateProductOptions, n as WebhookDeliveryData, o as WebhookEventType, p as WebhookDeliveryStatus, q as WebhookEndpointData, r as WebhookEndpointWithSecretData, s as UpdateWebhookEndpointOptions, t as WebhookPingData, u as ListWebhookDeliveriesOptions, v as WebhookEvent, w as CreateWebhookEndpointOptions } from './intent-input-Caauq1Vl.js';
|
|
3
|
+
export { x as AddressBook, y as AddressRef, z as AnalyticsBalanceEntry, B as AnalyticsRecentRow, E as AnalyticsSeriesPoint, F as AnalyticsVolumeEntry, G as ApiLogRow, I as AssetDefinition, J as AssetRef, K as Assets, M as CosmosPayAPIError, N as CosmosPayRequestError, O as CustomerListData, Q as PaymentIntentListData, R as ResolvableIntentInput, S as ResolvedAsset, T as TestnetAssets, X as WalletId, Y as Wallets, Z as WebhookDeliveryListData, _ as WebhookLogRow, $ as addresses, a0 as assertAddress, a1 as defineAsset, a2 as isAddress, a3 as isContractAddress, a4 as isMuxedAddress, a5 as isNativeAsset, a6 as isStellarAddress, a7 as resolveAddress, a8 as resolveAsset, a9 as resolveIntentBody } from './intent-input-Caauq1Vl.js';
|
|
2
4
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
5
|
|
|
4
|
-
/**
|
|
5
|
-
* Type definitions for the Cosmos Pay Payments API.
|
|
6
|
-
*
|
|
7
|
-
* These mirror the server's OpenAPI schema (Stellar SEP-7 payment intents,
|
|
8
|
-
* webhooks, products, customers and analytics). Every type is exported so
|
|
9
|
-
* TypeScript consumers get full intellisense; JavaScript consumers can ignore
|
|
10
|
-
* them entirely.
|
|
11
|
-
*/
|
|
12
|
-
/** Lifecycle state of a payment intent. */
|
|
13
|
-
declare const PaymentIntentStatus: {
|
|
14
|
-
readonly Pending: "PENDING";
|
|
15
|
-
readonly Submitted: "SUBMITTED";
|
|
16
|
-
readonly Succeeded: "SUCCEEDED";
|
|
17
|
-
readonly Failed: "FAILED";
|
|
18
|
-
readonly Cancelled: "CANCELLED";
|
|
19
|
-
readonly Expired: "EXPIRED";
|
|
20
|
-
};
|
|
21
|
-
type PaymentIntentStatus = (typeof PaymentIntentStatus)[keyof typeof PaymentIntentStatus];
|
|
22
|
-
/** SEP-7 operation a payment intent represents. */
|
|
23
|
-
declare const PaymentIntentKind: {
|
|
24
|
-
/** Source account is known → unsigned XDR + `web+stellar:tx` URI. */
|
|
25
|
-
readonly Tx: "TX";
|
|
26
|
-
/** No source → `web+stellar:pay` URI only (wallet picks the source). */
|
|
27
|
-
readonly Pay: "PAY";
|
|
28
|
-
};
|
|
29
|
-
type PaymentIntentKind = (typeof PaymentIntentKind)[keyof typeof PaymentIntentKind];
|
|
30
|
-
/** Domain events an integrator can subscribe a webhook to. */
|
|
31
|
-
declare const WebhookEventType: {
|
|
32
|
-
readonly PaymentIntentCreated: "PAYMENT_INTENT_CREATED";
|
|
33
|
-
readonly PaymentIntentUpdated: "PAYMENT_INTENT_UPDATED";
|
|
34
|
-
readonly PaymentIntentSucceeded: "PAYMENT_INTENT_SUCCEEDED";
|
|
35
|
-
readonly PaymentIntentFailed: "PAYMENT_INTENT_FAILED";
|
|
36
|
-
readonly PaymentIntentCancelled: "PAYMENT_INTENT_CANCELLED";
|
|
37
|
-
readonly PaymentIntentDeleted: "PAYMENT_INTENT_DELETED";
|
|
38
|
-
};
|
|
39
|
-
type WebhookEventType = (typeof WebhookEventType)[keyof typeof WebhookEventType];
|
|
40
|
-
/** Delivery state of a single webhook attempt. */
|
|
41
|
-
declare const WebhookDeliveryStatus: {
|
|
42
|
-
readonly Pending: "PENDING";
|
|
43
|
-
readonly Succeeded: "SUCCEEDED";
|
|
44
|
-
readonly Failed: "FAILED";
|
|
45
|
-
};
|
|
46
|
-
type WebhookDeliveryStatus = (typeof WebhookDeliveryStatus)[keyof typeof WebhookDeliveryStatus];
|
|
47
|
-
/** Product billing kind. */
|
|
48
|
-
declare const ProductKind: {
|
|
49
|
-
readonly Recurring: "recurring";
|
|
50
|
-
readonly OneTime: "one_time";
|
|
51
|
-
readonly Link: "link";
|
|
52
|
-
};
|
|
53
|
-
type ProductKind = (typeof ProductKind)[keyof typeof ProductKind];
|
|
54
|
-
/** Body for `POST /v1/payment-intents/tx`. */
|
|
55
|
-
interface CreateTxPaymentIntentOptions {
|
|
56
|
-
/** Payer's Stellar account — the transaction source. */
|
|
57
|
-
source: string;
|
|
58
|
-
/** Payee's Stellar account. */
|
|
59
|
-
destination: string;
|
|
60
|
-
/** Amount as a decimal string (max 7 decimals). */
|
|
61
|
-
amount: string;
|
|
62
|
-
/** Asset code. Omit (or `XLM`/`native`) for native lumens. */
|
|
63
|
-
assetCode?: string;
|
|
64
|
-
/** Issuer account for a non-native asset. */
|
|
65
|
-
assetIssuer?: string;
|
|
66
|
-
/** MEMO_ID (numeric uint64) for idempotency + on-chain identification. Auto-generated when omitted. */
|
|
67
|
-
memo?: string;
|
|
68
|
-
/** SEP-7 `msg`: shown to the user in their wallet (≤ 300 chars). */
|
|
69
|
-
msg?: string;
|
|
70
|
-
/** SEP-7 `callback` where the wallet POSTs the signed XDR, e.g. `url:https://...`. */
|
|
71
|
-
callback?: string;
|
|
72
|
-
}
|
|
73
|
-
/** Body for `POST /v1/payment-intents/pay`. */
|
|
74
|
-
interface CreatePayPaymentIntentOptions {
|
|
75
|
-
/** Payee's Stellar account. */
|
|
76
|
-
destination: string;
|
|
77
|
-
/** Amount the destination should receive. Omit to let the user enter it (e.g. donations). */
|
|
78
|
-
amount?: string;
|
|
79
|
-
/** Asset code the destination receives. Omit for native lumens (XLM). */
|
|
80
|
-
assetCode?: string;
|
|
81
|
-
/** Issuer account for a non-native asset. */
|
|
82
|
-
assetIssuer?: string;
|
|
83
|
-
/** MEMO_ID (numeric uint64) for idempotency + on-chain identification. Auto-generated when omitted. */
|
|
84
|
-
memo?: string;
|
|
85
|
-
/** SEP-7 `msg`: shown to the user in their wallet (≤ 300 chars). */
|
|
86
|
-
msg?: string;
|
|
87
|
-
/** SEP-7 `callback`, e.g. `url:https://...`. */
|
|
88
|
-
callback?: string;
|
|
89
|
-
}
|
|
90
|
-
/** Body for `PATCH /v1/payment-intents/:id`. */
|
|
91
|
-
interface UpdatePaymentIntentOptions {
|
|
92
|
-
status?: PaymentIntentStatus;
|
|
93
|
-
/** Stellar transaction hash once the signed tx is submitted. */
|
|
94
|
-
txHash?: string;
|
|
95
|
-
/** Merchant reference. */
|
|
96
|
-
reference?: string;
|
|
97
|
-
}
|
|
98
|
-
/** Query for `GET /v1/payment-intents`. */
|
|
99
|
-
interface ListPaymentIntentsOptions {
|
|
100
|
-
status?: PaymentIntentStatus;
|
|
101
|
-
/** Page size (max 100, default 20). */
|
|
102
|
-
take?: number;
|
|
103
|
-
/** Offset (default 0). */
|
|
104
|
-
skip?: number;
|
|
105
|
-
}
|
|
106
|
-
/** Raw payment intent payload returned by the API. */
|
|
107
|
-
interface PaymentIntentData {
|
|
108
|
-
id: string;
|
|
109
|
-
kind: PaymentIntentKind;
|
|
110
|
-
status: PaymentIntentStatus;
|
|
111
|
-
network: string;
|
|
112
|
-
source: string | null;
|
|
113
|
-
destination: string;
|
|
114
|
-
amount: string | null;
|
|
115
|
-
asset: string;
|
|
116
|
-
assetIssuer: string | null;
|
|
117
|
-
memo: string;
|
|
118
|
-
msg: string | null;
|
|
119
|
-
callback: string | null;
|
|
120
|
-
xdr: string | null;
|
|
121
|
-
uri: string;
|
|
122
|
-
qr: string;
|
|
123
|
-
txHash: string | null;
|
|
124
|
-
reference: string | null;
|
|
125
|
-
createdAt: string;
|
|
126
|
-
updatedAt: string;
|
|
127
|
-
}
|
|
128
|
-
/** Raw paginated list of payment intents. */
|
|
129
|
-
interface PaymentIntentListData {
|
|
130
|
-
data: PaymentIntentData[];
|
|
131
|
-
total: number;
|
|
132
|
-
take: number;
|
|
133
|
-
skip: number;
|
|
134
|
-
}
|
|
135
|
-
/** Body for `POST /v1/payment-intents/:id/validate`. */
|
|
136
|
-
interface ValidatePaymentIntentOptions {
|
|
137
|
-
/** Hash of the submitted Stellar transaction to validate against this intent. */
|
|
138
|
-
txHash: string;
|
|
139
|
-
}
|
|
140
|
-
/** Raw outcome of a validation attempt. */
|
|
141
|
-
interface ValidationOutcomeData {
|
|
142
|
-
valid: boolean;
|
|
143
|
-
status: PaymentIntentStatus;
|
|
144
|
-
reason?: string | null;
|
|
145
|
-
paymentIntent?: PaymentIntentData;
|
|
146
|
-
}
|
|
147
|
-
/** Raw `{ id, deleted }` response. */
|
|
148
|
-
interface DeletedData {
|
|
149
|
-
id: string;
|
|
150
|
-
deleted: boolean;
|
|
151
|
-
}
|
|
152
|
-
/** Body for `POST /v1/webhooks`. */
|
|
153
|
-
interface CreateWebhookEndpointOptions {
|
|
154
|
-
/** HTTPS URL that will receive POSTed event notifications. */
|
|
155
|
-
url: string;
|
|
156
|
-
description?: string;
|
|
157
|
-
/** Event types to subscribe to. Omit/empty to receive all events. */
|
|
158
|
-
eventTypes?: WebhookEventType[];
|
|
159
|
-
}
|
|
160
|
-
/** Body for `PATCH /v1/webhooks/:id`. */
|
|
161
|
-
interface UpdateWebhookEndpointOptions {
|
|
162
|
-
url?: string;
|
|
163
|
-
description?: string;
|
|
164
|
-
/** Pause/resume deliveries to this endpoint. */
|
|
165
|
-
enabled?: boolean;
|
|
166
|
-
eventTypes?: WebhookEventType[];
|
|
167
|
-
}
|
|
168
|
-
/** Raw webhook endpoint payload. */
|
|
169
|
-
interface WebhookEndpointData {
|
|
170
|
-
id: string;
|
|
171
|
-
url: string;
|
|
172
|
-
description: string | null;
|
|
173
|
-
enabled: boolean;
|
|
174
|
-
eventTypes: WebhookEventType[];
|
|
175
|
-
createdAt: string;
|
|
176
|
-
updatedAt: string;
|
|
177
|
-
}
|
|
178
|
-
/** Raw webhook endpoint payload including the one-time signing secret. */
|
|
179
|
-
interface WebhookEndpointWithSecretData extends WebhookEndpointData {
|
|
180
|
-
/** HMAC signing secret — shown once. Store it securely. */
|
|
181
|
-
secret: string;
|
|
182
|
-
}
|
|
183
|
-
/** Raw result of a webhook ping. */
|
|
184
|
-
interface WebhookPingData {
|
|
185
|
-
ok: boolean;
|
|
186
|
-
responseStatus: number | null;
|
|
187
|
-
error: string | null;
|
|
188
|
-
}
|
|
189
|
-
/** Raw webhook delivery (audit) record. */
|
|
190
|
-
interface WebhookDeliveryData {
|
|
191
|
-
id: string;
|
|
192
|
-
endpointId: string;
|
|
193
|
-
eventType: WebhookEventType;
|
|
194
|
-
eventId: string;
|
|
195
|
-
payload: Record<string, unknown>;
|
|
196
|
-
status: WebhookDeliveryStatus;
|
|
197
|
-
attempts: number;
|
|
198
|
-
responseStatus: number | null;
|
|
199
|
-
error: string | null;
|
|
200
|
-
lastAttemptAt: string | null;
|
|
201
|
-
createdAt: string;
|
|
202
|
-
updatedAt: string;
|
|
203
|
-
}
|
|
204
|
-
/** Raw paginated list of webhook deliveries. */
|
|
205
|
-
interface WebhookDeliveryListData {
|
|
206
|
-
data: WebhookDeliveryData[];
|
|
207
|
-
total: number;
|
|
208
|
-
take: number;
|
|
209
|
-
skip: number;
|
|
210
|
-
}
|
|
211
|
-
/** Query for `GET /v1/webhooks/:id/deliveries`. */
|
|
212
|
-
interface ListWebhookDeliveriesOptions {
|
|
213
|
-
status?: WebhookDeliveryStatus;
|
|
214
|
-
take?: number;
|
|
215
|
-
skip?: number;
|
|
216
|
-
}
|
|
217
|
-
/** Shape of the JSON body POSTed to an integrator's webhook URL. */
|
|
218
|
-
interface WebhookEvent<T = PaymentIntentData> {
|
|
219
|
-
/** Stable event id (use for idempotency). */
|
|
220
|
-
id: string;
|
|
221
|
-
type: WebhookEventType;
|
|
222
|
-
createdAt: string;
|
|
223
|
-
data: T;
|
|
224
|
-
}
|
|
225
|
-
/** Body for `POST /v1/products`. */
|
|
226
|
-
interface CreateProductOptions {
|
|
227
|
-
name: string;
|
|
228
|
-
description?: string;
|
|
229
|
-
/** Decimal price (≤ 7 decimals). Omit for a customer-set amount. */
|
|
230
|
-
amount?: string;
|
|
231
|
-
/** Asset code the price is in. Omit for native lumens (XLM). */
|
|
232
|
-
assetCode?: string;
|
|
233
|
-
kind?: ProductKind;
|
|
234
|
-
active?: boolean;
|
|
235
|
-
reference?: string;
|
|
236
|
-
}
|
|
237
|
-
/** Body for `PATCH /v1/products/:id`. */
|
|
238
|
-
type UpdateProductOptions = Partial<CreateProductOptions>;
|
|
239
|
-
/** Raw product payload. */
|
|
240
|
-
interface ProductData {
|
|
241
|
-
id: string;
|
|
242
|
-
name: string;
|
|
243
|
-
description: string | null;
|
|
244
|
-
amount: string | null;
|
|
245
|
-
asset: string;
|
|
246
|
-
kind: ProductKind;
|
|
247
|
-
active: boolean;
|
|
248
|
-
reference: string | null;
|
|
249
|
-
createdAt: string;
|
|
250
|
-
updatedAt: string;
|
|
251
|
-
}
|
|
252
|
-
/** Body for `POST /v1/customers`. */
|
|
253
|
-
interface CreateCustomerOptions {
|
|
254
|
-
name: string;
|
|
255
|
-
alias?: string;
|
|
256
|
-
note?: string;
|
|
257
|
-
email?: string;
|
|
258
|
-
/** Optional Stellar account to associate the customer with. */
|
|
259
|
-
account?: string;
|
|
260
|
-
reference?: string;
|
|
261
|
-
}
|
|
262
|
-
/** Body for `PATCH /v1/customers/:id`. */
|
|
263
|
-
type UpdateCustomerOptions = Partial<CreateCustomerOptions>;
|
|
264
|
-
/** Raw customer payload. */
|
|
265
|
-
interface CustomerData {
|
|
266
|
-
id: string;
|
|
267
|
-
consumerId: string;
|
|
268
|
-
name: string;
|
|
269
|
-
alias: string | null;
|
|
270
|
-
note: string | null;
|
|
271
|
-
email: string | null;
|
|
272
|
-
account: string | null;
|
|
273
|
-
reference: string | null;
|
|
274
|
-
createdAt: string;
|
|
275
|
-
updatedAt: string;
|
|
276
|
-
/** Derived on-chain stats (present in list responses). */
|
|
277
|
-
payments?: number;
|
|
278
|
-
succeeded?: number;
|
|
279
|
-
total?: string;
|
|
280
|
-
}
|
|
281
|
-
/** Raw `{ data, total }` list of customers. */
|
|
282
|
-
interface CustomerListData {
|
|
283
|
-
data: CustomerData[];
|
|
284
|
-
total: number;
|
|
285
|
-
}
|
|
286
|
-
interface AnalyticsVolumeEntry {
|
|
287
|
-
asset: string;
|
|
288
|
-
amount: string;
|
|
289
|
-
count: number;
|
|
290
|
-
}
|
|
291
|
-
interface AnalyticsSeriesPoint {
|
|
292
|
-
date: string;
|
|
293
|
-
count: number;
|
|
294
|
-
volume: string;
|
|
295
|
-
}
|
|
296
|
-
interface AnalyticsRecentRow {
|
|
297
|
-
id: string;
|
|
298
|
-
kind: string;
|
|
299
|
-
status: PaymentIntentStatus;
|
|
300
|
-
amount: string | null;
|
|
301
|
-
asset: string;
|
|
302
|
-
destination: string;
|
|
303
|
-
createdAt: string;
|
|
304
|
-
}
|
|
305
|
-
/** Raw overview metrics returned by `GET /v1/summary`. */
|
|
306
|
-
interface AnalyticsSummaryData {
|
|
307
|
-
totals: {
|
|
308
|
-
all: number;
|
|
309
|
-
succeeded: number;
|
|
310
|
-
pending: number;
|
|
311
|
-
submitted: number;
|
|
312
|
-
failed: number;
|
|
313
|
-
cancelled: number;
|
|
314
|
-
expired: number;
|
|
315
|
-
successRate: number;
|
|
316
|
-
};
|
|
317
|
-
volume: AnalyticsVolumeEntry[];
|
|
318
|
-
webhooks: {
|
|
319
|
-
endpoints: number;
|
|
320
|
-
deliveries: number;
|
|
321
|
-
failedDeliveries: number;
|
|
322
|
-
};
|
|
323
|
-
customers: number;
|
|
324
|
-
series: AnalyticsSeriesPoint[];
|
|
325
|
-
recent: AnalyticsRecentRow[];
|
|
326
|
-
}
|
|
327
|
-
interface AnalyticsBalanceEntry {
|
|
328
|
-
asset: string;
|
|
329
|
-
amount: string;
|
|
330
|
-
pending: string;
|
|
331
|
-
count: number;
|
|
332
|
-
}
|
|
333
|
-
/** Raw balances returned by `GET /v1/balances`. */
|
|
334
|
-
interface AnalyticsBalancesData {
|
|
335
|
-
data: AnalyticsBalanceEntry[];
|
|
336
|
-
total: number;
|
|
337
|
-
}
|
|
338
|
-
interface ApiLogRow {
|
|
339
|
-
id: string;
|
|
340
|
-
method: string;
|
|
341
|
-
path: string;
|
|
342
|
-
statusCode: number;
|
|
343
|
-
durationMs: number;
|
|
344
|
-
ip: string | null;
|
|
345
|
-
userAgent: string | null;
|
|
346
|
-
status: 'ok' | 'pending' | 'fail';
|
|
347
|
-
at: string;
|
|
348
|
-
}
|
|
349
|
-
/** Raw API request log returned by `GET /v1/logs`. */
|
|
350
|
-
interface ApiLogsData {
|
|
351
|
-
data: ApiLogRow[];
|
|
352
|
-
total: number;
|
|
353
|
-
}
|
|
354
|
-
interface WebhookLogRow {
|
|
355
|
-
id: string;
|
|
356
|
-
endpointId: string;
|
|
357
|
-
url: string | null;
|
|
358
|
-
eventType: WebhookEventType;
|
|
359
|
-
eventId: string;
|
|
360
|
-
attempts: number;
|
|
361
|
-
responseStatus: number | null;
|
|
362
|
-
error: string | null;
|
|
363
|
-
status: 'ok' | 'pending' | 'fail';
|
|
364
|
-
at: string;
|
|
365
|
-
}
|
|
366
|
-
/** Raw webhook delivery log returned by `GET /v1/logs/webhooks`. */
|
|
367
|
-
interface WebhookLogsData {
|
|
368
|
-
data: WebhookLogRow[];
|
|
369
|
-
total: number;
|
|
370
|
-
}
|
|
371
|
-
interface HealthCheckData {
|
|
372
|
-
status: string;
|
|
373
|
-
info?: Record<string, {
|
|
374
|
-
status: string;
|
|
375
|
-
} & Record<string, unknown>> | null;
|
|
376
|
-
error?: Record<string, {
|
|
377
|
-
status: string;
|
|
378
|
-
} & Record<string, unknown>> | null;
|
|
379
|
-
details?: Record<string, {
|
|
380
|
-
status: string;
|
|
381
|
-
} & Record<string, unknown>>;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
6
|
/**
|
|
385
7
|
* Read-only analytics derived from the consumer's intents and deliveries —
|
|
386
8
|
* `client.analytics`. Powers dashboard-style Overview / Balances / Logs views.
|
|
@@ -458,7 +80,8 @@ type FetchLike = typeof fetch;
|
|
|
458
80
|
interface RESTOptions {
|
|
459
81
|
/**
|
|
460
82
|
* Base URL of the Cosmos Pay gateway (no trailing slash), e.g.
|
|
461
|
-
* `https://
|
|
83
|
+
* `https://api.cosmospay.lat/cosmos-api`. The version segment is appended
|
|
84
|
+
* automatically.
|
|
462
85
|
*/
|
|
463
86
|
baseURL: string;
|
|
464
87
|
/**
|
|
@@ -536,7 +159,7 @@ declare class REST extends EventEmitter {
|
|
|
536
159
|
/**
|
|
537
160
|
* Base class for all resource managers. Each manager owns a slice of the API
|
|
538
161
|
* (payment intents, webhooks, ...) and a lightweight in-memory cache of the
|
|
539
|
-
* structures it has materialized —
|
|
162
|
+
* structures it has materialized — an atomic, per-resource manager pattern.
|
|
540
163
|
*
|
|
541
164
|
* Extends EventEmitter so managers that surface real-time events (e.g. the
|
|
542
165
|
* webhook listener) can `emit`/`on` without extra plumbing.
|
|
@@ -1071,7 +694,7 @@ interface Client {
|
|
|
1071
694
|
}
|
|
1072
695
|
/**
|
|
1073
696
|
* The main entry point of the SDK — a single, atomic client that exposes every
|
|
1074
|
-
* resource through its own manager
|
|
697
|
+
* resource through its own manager — an atomic, single-client design.
|
|
1075
698
|
*
|
|
1076
699
|
* @example
|
|
1077
700
|
* import { Client } from '@cosmosapp/pay_sdk';
|
|
@@ -1084,11 +707,11 @@ interface Client {
|
|
|
1084
707
|
*/
|
|
1085
708
|
declare class Client extends EventEmitter {
|
|
1086
709
|
/** Library version. */
|
|
1087
|
-
static readonly version = "1.
|
|
710
|
+
static readonly version = "1.1.0";
|
|
1088
711
|
/**
|
|
1089
712
|
* Process-wide shared defaults maintained by Cosmos Pay (gateway URL, version,
|
|
1090
|
-
* internal secrets). Mutate once at startup to change them for every client
|
|
1091
|
-
* `Client.shared.baseURL = 'https://
|
|
713
|
+
* internal secrets). Mutate once at startup to change them for every client
|
|
714
|
+
* (e.g. self-hosting): `Client.shared.baseURL = 'https://gateway.your-domain.com'`.
|
|
1092
715
|
*/
|
|
1093
716
|
static readonly shared: SharedConfig;
|
|
1094
717
|
/** Resolved shared configuration for this client instance. */
|
|
@@ -1118,47 +741,6 @@ declare class Client extends EventEmitter {
|
|
|
1118
741
|
setGatewayCredentials(secret: string, consumerUsername: string): this;
|
|
1119
742
|
}
|
|
1120
743
|
|
|
1121
|
-
/**
|
|
1122
|
-
* Error thrown when the Cosmos Pay API responds with a non-2xx status.
|
|
1123
|
-
*
|
|
1124
|
-
* Carries the HTTP status, the parsed response body and the request context so
|
|
1125
|
-
* callers can branch on `error.status` (e.g. 404 → not found, 403 → gateway).
|
|
1126
|
-
*/
|
|
1127
|
-
declare class CosmosPayAPIError extends Error {
|
|
1128
|
-
/** HTTP status code returned by the API. */
|
|
1129
|
-
readonly status: number;
|
|
1130
|
-
/** HTTP method of the failed request. */
|
|
1131
|
-
readonly method: string;
|
|
1132
|
-
/** Absolute URL of the failed request. */
|
|
1133
|
-
readonly url: string;
|
|
1134
|
-
/** Parsed response body (object when JSON, string otherwise, or null). */
|
|
1135
|
-
readonly body: unknown;
|
|
1136
|
-
/** Machine-readable error code extracted from the body when present. */
|
|
1137
|
-
readonly code: string | undefined;
|
|
1138
|
-
constructor(options: {
|
|
1139
|
-
status: number;
|
|
1140
|
-
method: string;
|
|
1141
|
-
url: string;
|
|
1142
|
-
body: unknown;
|
|
1143
|
-
});
|
|
1144
|
-
private static resolveMessage;
|
|
1145
|
-
private static resolveCode;
|
|
1146
|
-
}
|
|
1147
|
-
/**
|
|
1148
|
-
* Error thrown when a request never reaches the API: network failure, abort or
|
|
1149
|
-
* timeout. Distinct from {@link CosmosPayAPIError}, which always has a status.
|
|
1150
|
-
*/
|
|
1151
|
-
declare class CosmosPayRequestError extends Error {
|
|
1152
|
-
readonly method: string;
|
|
1153
|
-
readonly url: string;
|
|
1154
|
-
readonly cause: unknown;
|
|
1155
|
-
constructor(options: {
|
|
1156
|
-
method: string;
|
|
1157
|
-
url: string;
|
|
1158
|
-
cause: unknown;
|
|
1159
|
-
});
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
744
|
/** Options for {@link Webhooks.verify} / {@link Webhooks.constructEvent}. */
|
|
1163
745
|
interface VerifyWebhookOptions {
|
|
1164
746
|
/**
|
|
@@ -1214,13 +796,18 @@ declare const Webhooks: {
|
|
|
1214
796
|
};
|
|
1215
797
|
|
|
1216
798
|
/** Library version, kept in sync with package.json. */
|
|
1217
|
-
declare const version = "1.
|
|
799
|
+
declare const version = "1.1.0";
|
|
1218
800
|
/**
|
|
1219
801
|
* Default base URL of the Cosmos Pay gateway. Maintained by Cosmos Pay — users
|
|
1220
802
|
* never need to set this; it's part of the {@link shared} configuration. Override
|
|
1221
803
|
* only when self-hosting or pointing at a staging gateway.
|
|
804
|
+
*
|
|
805
|
+
* This is the public APISIX gateway: requests under `/cosmos-api/*` are
|
|
806
|
+
* authenticated (API key) and proxied to the Payments API. The version segment
|
|
807
|
+
* (`/v1`, see {@link DEFAULT_VERSION}) is appended by the REST layer, producing
|
|
808
|
+
* e.g. `https://api.cosmospay.lat/cosmos-api/v1/payment-intents/pay`.
|
|
1222
809
|
*/
|
|
1223
|
-
declare const DEFAULT_BASE_URL = "https://api.cosmospay.
|
|
810
|
+
declare const DEFAULT_BASE_URL = "https://api.cosmospay.lat/cosmos-api";
|
|
1224
811
|
/** Default API version segment prefixed to every route (`/v1/...`). */
|
|
1225
812
|
declare const DEFAULT_VERSION = "v1";
|
|
1226
813
|
/** Default request timeout in milliseconds. */
|
|
@@ -1231,7 +818,7 @@ declare const DEFAULT_RETRIES = 2;
|
|
|
1231
818
|
declare const SIGNATURE_HEADER = "x-cosmos-signature";
|
|
1232
819
|
/**
|
|
1233
820
|
* Client debug/telemetry events. The {@link Client} extends EventEmitter and
|
|
1234
|
-
* emits these for observability
|
|
821
|
+
* emits these for observability (`debug`/`rateLimit`-style events).
|
|
1235
822
|
*/
|
|
1236
823
|
declare const Events: {
|
|
1237
824
|
readonly Debug: "debug";
|
|
@@ -1241,4 +828,4 @@ declare const Events: {
|
|
|
1241
828
|
};
|
|
1242
829
|
type ClientEvent = (typeof Events)[keyof typeof Events];
|
|
1243
830
|
|
|
1244
|
-
export {
|
|
831
|
+
export { AnalyticsBalancesData, AnalyticsManager, AnalyticsSummaryData, ApiLogsData, Base, BaseManager, Client, type ClientEvent, type ClientEvents, type ClientOptions, CreateCustomerOptions, CreatePayPaymentIntentOptions, CreateProductOptions, CreateTxPaymentIntentOptions, CreateWebhookEndpointOptions, Customer, CustomerData, CustomerManager, DEFAULT_BASE_URL, DEFAULT_RETRIES, DEFAULT_TIMEOUT, DEFAULT_VERSION, DeletedData, Events, type FetchLike, HealthCheckData, HealthManager, ListPaymentIntentsOptions, ListWebhookDeliveriesOptions, PaymentIntent, PaymentIntentData, PaymentIntentKind, PaymentIntentManager, type PaymentIntentPage, PaymentIntentStatus, Product, ProductData, ProductKind, ProductManager, REST, type RESTOptions, type RequestOptions, SIGNATURE_HEADER, type SharedConfig, UpdateCustomerOptions, UpdatePaymentIntentOptions, UpdateProductOptions, UpdateWebhookEndpointOptions, ValidatePaymentIntentOptions, type ValidationOutcome, ValidationOutcomeData, type VerifyWebhookOptions, WebhookDelivery, WebhookDeliveryData, type WebhookDeliveryPage, WebhookDeliveryStatus, WebhookEndpoint, WebhookEndpointData, WebhookEndpointWithSecretData, WebhookEvent, WebhookEventType, type WebhookHandlerOptions, type WebhookListenerEvents, WebhookLogsData, WebhookManager, WebhookPingData, type WebhookProcessOptions, WebhookSignatureError, Webhooks, resolveShared, shared, version };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { version, DEFAULT_VERSION, DEFAULT_BASE_URL, DEFAULT_TIMEOUT, DEFAULT_RETRIES, Events, CosmosPayAPIError, CosmosPayRequestError, resolveIntentBody, SIGNATURE_HEADER } from './chunk-RCLT7E4Y.js';
|
|
2
|
+
export { AddressBook, Assets, CosmosPayAPIError, CosmosPayRequestError, DEFAULT_BASE_URL, DEFAULT_RETRIES, DEFAULT_TIMEOUT, DEFAULT_VERSION, Events, SIGNATURE_HEADER, TestnetAssets, Wallets, addresses, assertAddress, defineAsset, isAddress, isContractAddress, isMuxedAddress, isNativeAsset, isStellarAddress, resolveAddress, resolveAsset, resolveIntentBody, version } from './chunk-RCLT7E4Y.js';
|
|
1
3
|
import { EventEmitter } from 'events';
|
|
2
4
|
import { createHmac, timingSafeEqual } from 'crypto';
|
|
3
5
|
|
|
4
|
-
// src/client/Client.ts
|
|
5
|
-
|
|
6
6
|
// src/managers/AnalyticsManager.ts
|
|
7
7
|
var AnalyticsManager = class {
|
|
8
8
|
constructor(client) {
|
|
@@ -322,14 +322,14 @@ var PaymentIntentManager = class extends BaseManager {
|
|
|
322
322
|
/** Create a SEP-7 `tx` intent (source known → unsigned XDR + tx URI + QR). */
|
|
323
323
|
async createTx(options) {
|
|
324
324
|
const data = await this.rest.post(`${this.route}/tx`, {
|
|
325
|
-
body: options
|
|
325
|
+
body: resolveIntentBody(options)
|
|
326
326
|
});
|
|
327
327
|
return this._add(new PaymentIntent(this.client, data));
|
|
328
328
|
}
|
|
329
329
|
/** Create a SEP-7 `pay` intent (no source → pay URI + QR, no XDR). */
|
|
330
330
|
async createPay(options) {
|
|
331
331
|
const data = await this.rest.post(`${this.route}/pay`, {
|
|
332
|
-
body: options
|
|
332
|
+
body: resolveIntentBody(options)
|
|
333
333
|
});
|
|
334
334
|
return this._add(new PaymentIntent(this.client, data));
|
|
335
335
|
}
|
|
@@ -593,22 +593,6 @@ var WebhookEndpoint = class extends Base {
|
|
|
593
593
|
};
|
|
594
594
|
}
|
|
595
595
|
};
|
|
596
|
-
|
|
597
|
-
// src/util/Constants.ts
|
|
598
|
-
var version = "1.0.0";
|
|
599
|
-
var DEFAULT_BASE_URL = "https://api.cosmospay.io";
|
|
600
|
-
var DEFAULT_VERSION = "v1";
|
|
601
|
-
var DEFAULT_TIMEOUT = 3e4;
|
|
602
|
-
var DEFAULT_RETRIES = 2;
|
|
603
|
-
var SIGNATURE_HEADER = "x-cosmos-signature";
|
|
604
|
-
var Events = {
|
|
605
|
-
Debug: "debug",
|
|
606
|
-
Request: "request",
|
|
607
|
-
Response: "response",
|
|
608
|
-
RateLimited: "rateLimited"
|
|
609
|
-
};
|
|
610
|
-
|
|
611
|
-
// src/util/Webhooks.ts
|
|
612
596
|
var WebhookSignatureError = class extends Error {
|
|
613
597
|
constructor(message) {
|
|
614
598
|
super(message);
|
|
@@ -869,52 +853,6 @@ function extractRawBody(req) {
|
|
|
869
853
|
}
|
|
870
854
|
return "";
|
|
871
855
|
}
|
|
872
|
-
|
|
873
|
-
// src/errors/CosmosPayError.ts
|
|
874
|
-
var CosmosPayAPIError = class _CosmosPayAPIError extends Error {
|
|
875
|
-
constructor(options) {
|
|
876
|
-
const message = _CosmosPayAPIError.resolveMessage(options.status, options.body);
|
|
877
|
-
super(message);
|
|
878
|
-
this.name = "CosmosPayAPIError";
|
|
879
|
-
this.status = options.status;
|
|
880
|
-
this.method = options.method;
|
|
881
|
-
this.url = options.url;
|
|
882
|
-
this.body = options.body;
|
|
883
|
-
this.code = _CosmosPayAPIError.resolveCode(options.body);
|
|
884
|
-
Error.captureStackTrace?.(this, _CosmosPayAPIError);
|
|
885
|
-
}
|
|
886
|
-
static resolveMessage(status, body) {
|
|
887
|
-
if (body && typeof body === "object") {
|
|
888
|
-
const maybe = body;
|
|
889
|
-
const msg = maybe.message ?? maybe.error;
|
|
890
|
-
if (Array.isArray(msg)) return `[${status}] ${msg.join(", ")}`;
|
|
891
|
-
if (typeof msg === "string") return `[${status}] ${msg}`;
|
|
892
|
-
}
|
|
893
|
-
if (typeof body === "string" && body.length) return `[${status}] ${body}`;
|
|
894
|
-
return `[${status}] Request failed`;
|
|
895
|
-
}
|
|
896
|
-
static resolveCode(body) {
|
|
897
|
-
if (body && typeof body === "object") {
|
|
898
|
-
const maybe = body;
|
|
899
|
-
if (typeof maybe.code === "string") return maybe.code;
|
|
900
|
-
if (typeof maybe.error === "string") return maybe.error;
|
|
901
|
-
}
|
|
902
|
-
return void 0;
|
|
903
|
-
}
|
|
904
|
-
};
|
|
905
|
-
var CosmosPayRequestError = class _CosmosPayRequestError extends Error {
|
|
906
|
-
constructor(options) {
|
|
907
|
-
const reason = options.cause instanceof Error ? options.cause.message : String(options.cause);
|
|
908
|
-
super(`Request to ${options.method} ${options.url} failed: ${reason}`);
|
|
909
|
-
this.name = "CosmosPayRequestError";
|
|
910
|
-
this.method = options.method;
|
|
911
|
-
this.url = options.url;
|
|
912
|
-
this.cause = options.cause;
|
|
913
|
-
Error.captureStackTrace?.(this, _CosmosPayRequestError);
|
|
914
|
-
}
|
|
915
|
-
};
|
|
916
|
-
|
|
917
|
-
// src/rest/REST.ts
|
|
918
856
|
var RETRYABLE_STATUS = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
|
|
919
857
|
var REST = class extends EventEmitter {
|
|
920
858
|
constructor(options) {
|
|
@@ -1110,8 +1048,8 @@ var Client = class extends EventEmitter {
|
|
|
1110
1048
|
static {
|
|
1111
1049
|
/**
|
|
1112
1050
|
* Process-wide shared defaults maintained by Cosmos Pay (gateway URL, version,
|
|
1113
|
-
* internal secrets). Mutate once at startup to change them for every client
|
|
1114
|
-
* `Client.shared.baseURL = 'https://
|
|
1051
|
+
* internal secrets). Mutate once at startup to change them for every client
|
|
1052
|
+
* (e.g. self-hosting): `Client.shared.baseURL = 'https://gateway.your-domain.com'`.
|
|
1115
1053
|
*/
|
|
1116
1054
|
this.shared = shared;
|
|
1117
1055
|
}
|
|
@@ -1166,6 +1104,6 @@ var Client = class extends EventEmitter {
|
|
|
1166
1104
|
}
|
|
1167
1105
|
};
|
|
1168
1106
|
|
|
1169
|
-
export { AnalyticsManager, Base, BaseManager, Client,
|
|
1107
|
+
export { AnalyticsManager, Base, BaseManager, Client, Customer, CustomerManager, HealthManager, PaymentIntent, PaymentIntentKind, PaymentIntentManager, PaymentIntentStatus, Product, ProductKind, ProductManager, REST, WebhookDelivery, WebhookDeliveryStatus, WebhookEndpoint, WebhookEventType, WebhookManager, WebhookSignatureError, Webhooks, resolveShared, shared };
|
|
1170
1108
|
//# sourceMappingURL=index.js.map
|
|
1171
1109
|
//# sourceMappingURL=index.js.map
|