@cosmosapp/pay_sdk 1.2.0 → 2.0.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 +18 -0
- package/LICENSE +0 -75
- package/NOTICE +8 -0
- package/README.md +15 -18
- package/dist/chunk-AYVWYEOK.js +62 -0
- package/dist/chunk-AYVWYEOK.js.map +1 -0
- package/dist/{chunk-TZDZBVFS.js → chunk-TM4HAKWE.js} +5 -3
- package/dist/chunk-TM4HAKWE.js.map +1 -0
- package/dist/cosmosProvider-CFASjnd5.d.cts +100 -0
- package/dist/cosmosProvider-CFASjnd5.d.ts +100 -0
- package/dist/index.cjs +739 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +618 -6
- package/dist/index.d.ts +618 -6
- package/dist/index.js +731 -5
- package/dist/index.js.map +1 -1
- package/dist/intent-input-BtUp3tFN.d.cts +1697 -0
- package/dist/intent-input-BtUp3tFN.d.ts +1697 -0
- package/dist/swk/index.cjs +170 -0
- package/dist/swk/index.cjs.map +1 -0
- package/dist/swk/index.d.cts +207 -0
- package/dist/swk/index.d.ts +207 -0
- package/dist/swk/index.js +106 -0
- package/dist/swk/index.js.map +1 -0
- package/dist/web/index.cjs +129 -2
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts +49 -4
- package/dist/web/index.d.ts +49 -4
- package/dist/web/index.js +67 -4
- package/dist/web/index.js.map +1 -1
- package/llms/03-quickstart.md +4 -4
- package/llms/05-payment-intents.md +6 -2
- package/llms/08-products-customers.md +1 -1
- package/llms/13-types-reference.md +1 -1
- package/llms/14-recipes.md +14 -8
- package/llms/llms-full.txt +26 -16
- package/package.json +17 -6
- package/dist/chunk-TZDZBVFS.js.map +0 -1
- package/dist/intent-input-Ch8ogEg-.d.cts +0 -750
- package/dist/intent-input-Ch8ogEg-.d.ts +0 -750
package/dist/index.cjs
CHANGED
|
@@ -61,7 +61,6 @@ var Customer = class extends Base {
|
|
|
61
61
|
}
|
|
62
62
|
_patch(data) {
|
|
63
63
|
super._patch(data);
|
|
64
|
-
this.consumerId = data.consumerId;
|
|
65
64
|
this.name = data.name;
|
|
66
65
|
this.alias = data.alias;
|
|
67
66
|
this.note = data.note;
|
|
@@ -91,7 +90,6 @@ var Customer = class extends Base {
|
|
|
91
90
|
toJSON() {
|
|
92
91
|
return {
|
|
93
92
|
id: this.id,
|
|
94
|
-
consumerId: this.consumerId,
|
|
95
93
|
name: this.name,
|
|
96
94
|
alias: this.alias,
|
|
97
95
|
note: this.note,
|
|
@@ -225,6 +223,728 @@ var SwapStatus = {
|
|
|
225
223
|
Failed: "FAILED",
|
|
226
224
|
Expired: "EXPIRED"
|
|
227
225
|
};
|
|
226
|
+
var LiquidityOperationKind = {
|
|
227
|
+
Deposit: "DEPOSIT"};
|
|
228
|
+
var LiquidityOperationStatus = {
|
|
229
|
+
Pending: "PENDING",
|
|
230
|
+
Succeeded: "SUCCEEDED"};
|
|
231
|
+
|
|
232
|
+
// src/structures/LiquidityOperation.ts
|
|
233
|
+
var LiquidityOperation = class extends Base {
|
|
234
|
+
constructor(client, data) {
|
|
235
|
+
super(client, data);
|
|
236
|
+
}
|
|
237
|
+
_patch(data) {
|
|
238
|
+
super._patch(data);
|
|
239
|
+
this.kind = data.kind;
|
|
240
|
+
this.status = data.status;
|
|
241
|
+
this.network = data.network;
|
|
242
|
+
this.source = data.source;
|
|
243
|
+
this.poolId = data.poolId;
|
|
244
|
+
this.assetA = data.assetA;
|
|
245
|
+
this.assetAIssuer = data.assetAIssuer ?? null;
|
|
246
|
+
this.assetB = data.assetB;
|
|
247
|
+
this.assetBIssuer = data.assetBIssuer ?? null;
|
|
248
|
+
this.amountA = data.amountA;
|
|
249
|
+
this.amountB = data.amountB;
|
|
250
|
+
this.shares = data.shares ?? null;
|
|
251
|
+
this.minPrice = data.minPrice ?? null;
|
|
252
|
+
this.maxPrice = data.maxPrice ?? null;
|
|
253
|
+
this.slippageBps = data.slippageBps;
|
|
254
|
+
this.idempotencyKey = data.idempotencyKey ?? null;
|
|
255
|
+
this.feeBps = data.feeBps;
|
|
256
|
+
this.feeAmountA = data.feeAmountA;
|
|
257
|
+
this.feeAmountB = data.feeAmountB;
|
|
258
|
+
this.feeWallet = data.feeWallet ?? null;
|
|
259
|
+
this.commissionMemo = data.commissionMemo ?? null;
|
|
260
|
+
this.xdr = data.xdr;
|
|
261
|
+
this.uri = data.uri;
|
|
262
|
+
this.txHash = data.txHash;
|
|
263
|
+
this.qr = data.qr;
|
|
264
|
+
this.expiresAt = data.expiresAt ? new Date(data.expiresAt) : null;
|
|
265
|
+
this.createdAt = new Date(data.createdAt);
|
|
266
|
+
this.updatedAt = new Date(data.updatedAt);
|
|
267
|
+
return this;
|
|
268
|
+
}
|
|
269
|
+
/** True while the envelope still needs a signature. */
|
|
270
|
+
get isPending() {
|
|
271
|
+
return this.status === LiquidityOperationStatus.Pending;
|
|
272
|
+
}
|
|
273
|
+
/** True once the network accepted it. */
|
|
274
|
+
get isSucceeded() {
|
|
275
|
+
return this.status === LiquidityOperationStatus.Succeeded;
|
|
276
|
+
}
|
|
277
|
+
/** True for a deposit, false for a withdrawal. */
|
|
278
|
+
get isDeposit() {
|
|
279
|
+
return this.kind === LiquidityOperationKind.Deposit;
|
|
280
|
+
}
|
|
281
|
+
/** Re-fetch this operation and patch it in place. */
|
|
282
|
+
async fetch() {
|
|
283
|
+
const data = await this.client.liquidity.fetchRaw(this.id);
|
|
284
|
+
return this._patch(data);
|
|
285
|
+
}
|
|
286
|
+
/** Relay the signed envelope to the network and patch this instance with the result. */
|
|
287
|
+
async submit(options) {
|
|
288
|
+
const outcome = await this.client.liquidity.submit(this.id, options);
|
|
289
|
+
this._patch(outcome.operation.toJSON());
|
|
290
|
+
return outcome;
|
|
291
|
+
}
|
|
292
|
+
toJSON() {
|
|
293
|
+
return {
|
|
294
|
+
id: this.id,
|
|
295
|
+
kind: this.kind,
|
|
296
|
+
status: this.status,
|
|
297
|
+
network: this.network,
|
|
298
|
+
source: this.source,
|
|
299
|
+
poolId: this.poolId,
|
|
300
|
+
assetA: this.assetA,
|
|
301
|
+
assetAIssuer: this.assetAIssuer,
|
|
302
|
+
assetB: this.assetB,
|
|
303
|
+
assetBIssuer: this.assetBIssuer,
|
|
304
|
+
amountA: this.amountA,
|
|
305
|
+
amountB: this.amountB,
|
|
306
|
+
shares: this.shares,
|
|
307
|
+
minPrice: this.minPrice,
|
|
308
|
+
maxPrice: this.maxPrice,
|
|
309
|
+
slippageBps: this.slippageBps,
|
|
310
|
+
idempotencyKey: this.idempotencyKey,
|
|
311
|
+
feeBps: this.feeBps,
|
|
312
|
+
feeAmountA: this.feeAmountA,
|
|
313
|
+
feeAmountB: this.feeAmountB,
|
|
314
|
+
feeWallet: this.feeWallet,
|
|
315
|
+
commissionMemo: this.commissionMemo,
|
|
316
|
+
xdr: this.xdr,
|
|
317
|
+
uri: this.uri,
|
|
318
|
+
txHash: this.txHash,
|
|
319
|
+
qr: this.qr,
|
|
320
|
+
expiresAt: this.expiresAt ? this.expiresAt.toISOString() : null,
|
|
321
|
+
createdAt: this.createdAt.toISOString(),
|
|
322
|
+
updatedAt: this.updatedAt.toISOString()
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// src/managers/LiquidityManager.ts
|
|
328
|
+
var LiquidityManager = class extends BaseManager {
|
|
329
|
+
constructor() {
|
|
330
|
+
super(...arguments);
|
|
331
|
+
this.route = "/liquidity-pools";
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Build a deposit into the pool formed by the two assets → unsigned XDR, SEP-7
|
|
335
|
+
* URI and QR.
|
|
336
|
+
*
|
|
337
|
+
* The pool is DERIVED from the two assets rather than named: a constant-product
|
|
338
|
+
* pool id is a hash of its (assetA, assetB, fee) in CAP-38 order, so there is
|
|
339
|
+
* exactly one pool the pair can form and no id for a caller to get wrong.
|
|
340
|
+
*/
|
|
341
|
+
async deposit(options) {
|
|
342
|
+
const { idempotencyKey, ...body } = options;
|
|
343
|
+
const data = await this.rest.post(`${this.route}/deposit`, {
|
|
344
|
+
body: { ...body, ...idempotencyKey ? { idempotencyKey } : {} },
|
|
345
|
+
// Sent as a header too: the service accepts either, and the header is what
|
|
346
|
+
// makes a retried POST safe when the body was already consumed upstream.
|
|
347
|
+
...idempotencyKey ? { headers: { "Idempotency-Key": idempotencyKey } } : {}
|
|
348
|
+
});
|
|
349
|
+
return this._add(new LiquidityOperation(this.client, data));
|
|
350
|
+
}
|
|
351
|
+
/** Build a withdrawal (burn shares) from a pool → unsigned XDR, SEP-7 URI and QR. */
|
|
352
|
+
async withdraw(options) {
|
|
353
|
+
const { idempotencyKey, ...body } = options;
|
|
354
|
+
const data = await this.rest.post(`${this.route}/withdraw`, {
|
|
355
|
+
body: { ...body, ...idempotencyKey ? { idempotencyKey } : {} },
|
|
356
|
+
...idempotencyKey ? { headers: { "Idempotency-Key": idempotencyKey } } : {}
|
|
357
|
+
});
|
|
358
|
+
return this._add(new LiquidityOperation(this.client, data));
|
|
359
|
+
}
|
|
360
|
+
/** An account's pool share positions, with what each is redeemable for right now. */
|
|
361
|
+
positions(account) {
|
|
362
|
+
return this.rest.get(`${this.route}/positions`, {
|
|
363
|
+
query: { account }
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/** Browse on-chain pools (Horizon proxy). Filter by asset pair or by holder. */
|
|
367
|
+
async browse(options = {}) {
|
|
368
|
+
const data = await this.rest.get(this.route, {
|
|
369
|
+
query: {
|
|
370
|
+
assetACode: options.assetACode,
|
|
371
|
+
assetAIssuer: options.assetAIssuer,
|
|
372
|
+
assetBCode: options.assetBCode,
|
|
373
|
+
assetBIssuer: options.assetBIssuer,
|
|
374
|
+
account: options.account,
|
|
375
|
+
cursor: options.cursor,
|
|
376
|
+
limit: options.limit
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
return { items: data.data, cursor: data.cursor ?? null };
|
|
380
|
+
}
|
|
381
|
+
/** One on-chain pool by its hex id (Horizon proxy). */
|
|
382
|
+
pool(poolId) {
|
|
383
|
+
return this.rest.get(`${this.route}/${poolId}`);
|
|
384
|
+
}
|
|
385
|
+
/** List this consumer's pool operations (paginated). */
|
|
386
|
+
async operations(options = {}) {
|
|
387
|
+
const data = await this.rest.get(`${this.route}/operations`, {
|
|
388
|
+
query: {
|
|
389
|
+
kind: options.kind,
|
|
390
|
+
status: options.status,
|
|
391
|
+
take: options.take,
|
|
392
|
+
skip: options.skip
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
return {
|
|
396
|
+
items: data.data.map((d) => this._add(new LiquidityOperation(this.client, d))),
|
|
397
|
+
total: data.total,
|
|
398
|
+
take: data.take,
|
|
399
|
+
skip: data.skip
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
/** Get one operation by id, materialized. */
|
|
403
|
+
async fetch(id) {
|
|
404
|
+
return this._add(new LiquidityOperation(this.client, await this.fetchRaw(id)));
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* The raw payload for one operation. Exists so {@link LiquidityOperation.fetch}
|
|
408
|
+
* can patch itself in place instead of materializing a second instance of the
|
|
409
|
+
* thing the caller is already holding.
|
|
410
|
+
*/
|
|
411
|
+
fetchRaw(id) {
|
|
412
|
+
return this.rest.get(`${this.route}/operations/${id}`);
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Relay a signed operation to the network. The service checks the envelope's
|
|
416
|
+
* hash against the one it built, so a signed envelope that is not the one this
|
|
417
|
+
* operation describes is refused rather than broadcast.
|
|
418
|
+
*/
|
|
419
|
+
async submit(id, options) {
|
|
420
|
+
const data = await this.rest.post(
|
|
421
|
+
`${this.route}/operations/${id}/submit`,
|
|
422
|
+
{ body: options }
|
|
423
|
+
);
|
|
424
|
+
return {
|
|
425
|
+
submitted: data.submitted,
|
|
426
|
+
status: data.status,
|
|
427
|
+
txHash: data.txHash ?? null,
|
|
428
|
+
reason: data.reason ?? null,
|
|
429
|
+
resultCodes: data.resultCodes ?? null,
|
|
430
|
+
operation: this._add(new LiquidityOperation(this.client, data.operation))
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
// src/managers/OnrampManager.ts
|
|
436
|
+
var OnrampManager = class {
|
|
437
|
+
constructor(client) {
|
|
438
|
+
this.route = "/onramp";
|
|
439
|
+
this.client = client;
|
|
440
|
+
}
|
|
441
|
+
get rest() {
|
|
442
|
+
return this.client.rest;
|
|
443
|
+
}
|
|
444
|
+
/** Price a payin. The quote expires — check `expires_at` before using it. */
|
|
445
|
+
quote(options) {
|
|
446
|
+
return this.rest.post(`${this.route}/quotes`, { body: options });
|
|
447
|
+
}
|
|
448
|
+
/** Create a payin from a quote. The response carries the funding instructions. */
|
|
449
|
+
createPayin(options) {
|
|
450
|
+
return this.rest.post(`${this.route}/payins`, { body: options });
|
|
451
|
+
}
|
|
452
|
+
/** List this consumer's payins (paginated). */
|
|
453
|
+
async payins(options = {}) {
|
|
454
|
+
const data = await this.rest.get(`${this.route}/payins`, {
|
|
455
|
+
query: { take: options.take, skip: options.skip }
|
|
456
|
+
});
|
|
457
|
+
return { items: data.data, total: data.total, take: data.take, skip: data.skip };
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* One payin. Served from the local mirror, refreshed from the provider when it
|
|
461
|
+
* is stale — so this is the right call to poll, not the provider's own API.
|
|
462
|
+
*/
|
|
463
|
+
payin(id) {
|
|
464
|
+
return this.rest.get(`${this.route}/payins/${id}`);
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Build the unsigned trustline transaction an address needs before it can hold
|
|
468
|
+
* the stablecoin the ramp pays out in.
|
|
469
|
+
*
|
|
470
|
+
* The envelope comes from the gateway, so a wallet signing it must decode and
|
|
471
|
+
* bound it first — the issuer it names is the one the payout will use, and it is
|
|
472
|
+
* not known to the caller in advance.
|
|
473
|
+
*/
|
|
474
|
+
createTrustline(options) {
|
|
475
|
+
return this.rest.post(`${this.route}/trustline`, { body: options });
|
|
476
|
+
}
|
|
477
|
+
/** Open a virtual account (a permanent bank reference) for a verified receiver. */
|
|
478
|
+
createVirtualAccount(receiverId, options) {
|
|
479
|
+
return this.rest.post(
|
|
480
|
+
`${this.route}/receivers/${receiverId}/virtual-accounts`,
|
|
481
|
+
{ body: options }
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
/** A receiver's virtual accounts. */
|
|
485
|
+
virtualAccounts(receiverId, options = {}) {
|
|
486
|
+
return this.rest.get(
|
|
487
|
+
`${this.route}/receivers/${receiverId}/virtual-accounts`,
|
|
488
|
+
{ query: { take: options.take, skip: options.skip } }
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
// src/managers/OfframpManager.ts
|
|
494
|
+
var OfframpManager = class {
|
|
495
|
+
constructor(client) {
|
|
496
|
+
this.route = "/offramp";
|
|
497
|
+
this.client = client;
|
|
498
|
+
}
|
|
499
|
+
get rest() {
|
|
500
|
+
return this.client.rest;
|
|
501
|
+
}
|
|
502
|
+
/** Price a payout. Expires in about five minutes. */
|
|
503
|
+
quote(options) {
|
|
504
|
+
return this.rest.post(`${this.route}/quotes`, { body: options });
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Build the unsigned transfer for a Stellar or Solana payout.
|
|
508
|
+
*
|
|
509
|
+
* What comes back is built by the gateway, not by the caller: bound it against
|
|
510
|
+
* the quote the user confirmed before signing, or the amount that leaves is
|
|
511
|
+
* whatever the response says it is.
|
|
512
|
+
*/
|
|
513
|
+
authorize(options) {
|
|
514
|
+
return this.rest.post(`${this.route}/payouts/authorize`, {
|
|
515
|
+
body: options
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
/** Create the payout from a quote, with the signed transfer attached. */
|
|
519
|
+
createPayout(options) {
|
|
520
|
+
return this.rest.post(`${this.route}/payouts`, { body: options });
|
|
521
|
+
}
|
|
522
|
+
/** List this consumer's payouts (paginated). */
|
|
523
|
+
async payouts(options = {}) {
|
|
524
|
+
const data = await this.rest.get(`${this.route}/payouts`, {
|
|
525
|
+
query: { take: options.take, skip: options.skip }
|
|
526
|
+
});
|
|
527
|
+
return { items: data.data, total: data.total, take: data.take, skip: data.skip };
|
|
528
|
+
}
|
|
529
|
+
/** One payout. Served from the local mirror, refreshed when stale. */
|
|
530
|
+
payout(id) {
|
|
531
|
+
return this.rest.get(`${this.route}/payouts/${id}`);
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Attach a compliance document to a payout — an invoice or proof of funds the
|
|
535
|
+
* rail asks for before it will settle.
|
|
536
|
+
*/
|
|
537
|
+
attachDocument(id, options) {
|
|
538
|
+
return this.rest.post(`${this.route}/payouts/${id}/documents`, {
|
|
539
|
+
body: options
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
// src/managers/ActivityManager.ts
|
|
545
|
+
var ActivityManager = class {
|
|
546
|
+
constructor(client) {
|
|
547
|
+
this.route = "/activity";
|
|
548
|
+
this.client = client;
|
|
549
|
+
}
|
|
550
|
+
get rest() {
|
|
551
|
+
return this.client.rest;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Report a batch of events.
|
|
555
|
+
*
|
|
556
|
+
* Accepts the array directly or the full body. Give each event an `eventId`: the
|
|
557
|
+
* service de-duplicates on it, which is the difference between a retried batch
|
|
558
|
+
* and a double-counted one.
|
|
559
|
+
*/
|
|
560
|
+
report(events) {
|
|
561
|
+
const body = Array.isArray(events) ? { events } : events;
|
|
562
|
+
return this.rest.post(`${this.route}/events`, { body });
|
|
563
|
+
}
|
|
564
|
+
/** Recent events for this consumer, newest first. */
|
|
565
|
+
async events(options = {}) {
|
|
566
|
+
const data = await this.rest.get(`${this.route}/events`, {
|
|
567
|
+
query: {
|
|
568
|
+
take: options.take,
|
|
569
|
+
skip: options.skip,
|
|
570
|
+
source: options.source,
|
|
571
|
+
level: options.level,
|
|
572
|
+
category: options.category,
|
|
573
|
+
type: options.type,
|
|
574
|
+
network: options.network,
|
|
575
|
+
since: options.since,
|
|
576
|
+
until: options.until
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
return { items: data.data, total: data.total, take: data.take, skip: data.skip };
|
|
580
|
+
}
|
|
581
|
+
/** Counts, top event types, top errors and a daily series. */
|
|
582
|
+
summary(options = {}) {
|
|
583
|
+
return this.rest.get(`${this.route}/summary`, {
|
|
584
|
+
query: { days: options.days, source: options.source }
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
// src/structures/Receiver.ts
|
|
590
|
+
var Receiver = class extends Base {
|
|
591
|
+
constructor(client, data) {
|
|
592
|
+
super(client, data);
|
|
593
|
+
}
|
|
594
|
+
_patch(data) {
|
|
595
|
+
super._patch(data);
|
|
596
|
+
this.blindpayId = data.blindpayId;
|
|
597
|
+
this.type = data.type;
|
|
598
|
+
this.kycType = data.kycType ?? null;
|
|
599
|
+
this.kycStatus = data.kycStatus ?? null;
|
|
600
|
+
this.email = data.email ?? null;
|
|
601
|
+
this.name = data.name ?? null;
|
|
602
|
+
this.country = data.country ?? null;
|
|
603
|
+
this.externalId = data.externalId ?? null;
|
|
604
|
+
this.disabled = data.disabled;
|
|
605
|
+
this.dossierVersion = data.dossierVersion;
|
|
606
|
+
this.reviewedVersion = data.reviewedVersion ?? null;
|
|
607
|
+
this.createdAt = new Date(data.createdAt);
|
|
608
|
+
this.updatedAt = new Date(data.updatedAt);
|
|
609
|
+
return this;
|
|
610
|
+
}
|
|
611
|
+
/** True once verification has passed and the ramps will act on this receiver. */
|
|
612
|
+
get isApproved() {
|
|
613
|
+
return this.kycStatus === "approved";
|
|
614
|
+
}
|
|
615
|
+
/** Re-read this receiver, refreshing `kycStatus`, and patch it in place. */
|
|
616
|
+
async fetch() {
|
|
617
|
+
return this._patch(await this.client.kyc.fetchReceiverRaw(this.id));
|
|
618
|
+
}
|
|
619
|
+
/** Update and patch in place. */
|
|
620
|
+
async update(options) {
|
|
621
|
+
const updated = await this.client.kyc.updateReceiver(this.id, options);
|
|
622
|
+
return this._patch(updated.toJSON());
|
|
623
|
+
}
|
|
624
|
+
/** Delete this receiver. */
|
|
625
|
+
delete() {
|
|
626
|
+
return this.client.kyc.deleteReceiver(this.id);
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Approve it out of review (admin-only).
|
|
630
|
+
*
|
|
631
|
+
* Pinned to the dossier THIS instance holds: `expected_version` defaults to
|
|
632
|
+
* {@link Receiver.dossierVersion}, so approving a receiver that was edited since
|
|
633
|
+
* you read it is a `409 kyc_state_invalid` rather than a silent approval of data
|
|
634
|
+
* you never saw. Call {@link Receiver.fetch} and review again, or pass
|
|
635
|
+
* `expected_version` yourself — including `undefined`, which approves whatever
|
|
636
|
+
* is stored now.
|
|
637
|
+
*/
|
|
638
|
+
approve(options = {}) {
|
|
639
|
+
const pinned = "expected_version" in options ? options : { ...options, expected_version: this.dossierVersion };
|
|
640
|
+
return this.client.kyc.approveReceiver(this.id, pinned);
|
|
641
|
+
}
|
|
642
|
+
/** Ask for a terms-of-service link for this receiver. */
|
|
643
|
+
requestTos(options) {
|
|
644
|
+
return this.client.kyc.requestTos(this.id, options);
|
|
645
|
+
}
|
|
646
|
+
/** Enable it with an accepted terms-of-service id, and patch in place. */
|
|
647
|
+
async enable(options) {
|
|
648
|
+
const enabled = await this.client.kyc.enableReceiver(this.id, options);
|
|
649
|
+
return this._patch(enabled.toJSON());
|
|
650
|
+
}
|
|
651
|
+
/** Cut this receiver off from both ramps, or let it back in. */
|
|
652
|
+
async setAccess(disabled) {
|
|
653
|
+
const updated = await this.client.kyc.setReceiverAccess(this.id, { disabled });
|
|
654
|
+
return this._patch(updated.toJSON());
|
|
655
|
+
}
|
|
656
|
+
/** Register a blockchain wallet for this receiver. */
|
|
657
|
+
addWallet(options) {
|
|
658
|
+
return this.client.kyc.addWallet(this.id, options);
|
|
659
|
+
}
|
|
660
|
+
/** This receiver's wallets. */
|
|
661
|
+
wallets(options = {}) {
|
|
662
|
+
return this.client.kyc.wallets(this.id, options);
|
|
663
|
+
}
|
|
664
|
+
/** Add a fiat bank account — where an off-ramp pays out. */
|
|
665
|
+
addBankAccount(options) {
|
|
666
|
+
return this.client.kyc.addBankAccount(this.id, options);
|
|
667
|
+
}
|
|
668
|
+
/** This receiver's bank accounts. */
|
|
669
|
+
bankAccounts(options = {}) {
|
|
670
|
+
return this.client.kyc.bankAccounts(this.id, options);
|
|
671
|
+
}
|
|
672
|
+
toJSON() {
|
|
673
|
+
return {
|
|
674
|
+
id: this.id,
|
|
675
|
+
blindpayId: this.blindpayId,
|
|
676
|
+
type: this.type,
|
|
677
|
+
kycType: this.kycType,
|
|
678
|
+
kycStatus: this.kycStatus,
|
|
679
|
+
email: this.email,
|
|
680
|
+
name: this.name,
|
|
681
|
+
country: this.country,
|
|
682
|
+
externalId: this.externalId,
|
|
683
|
+
disabled: this.disabled,
|
|
684
|
+
dossierVersion: this.dossierVersion,
|
|
685
|
+
reviewedVersion: this.reviewedVersion,
|
|
686
|
+
createdAt: this.createdAt.toISOString(),
|
|
687
|
+
updatedAt: this.updatedAt.toISOString()
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
// src/managers/KycManager.ts
|
|
693
|
+
var KycManager = class extends BaseManager {
|
|
694
|
+
constructor() {
|
|
695
|
+
super(...arguments);
|
|
696
|
+
this.route = "/kyc";
|
|
697
|
+
}
|
|
698
|
+
/* ----------------------------- receivers ------------------------------- */
|
|
699
|
+
/** Create a receiver and start verification. */
|
|
700
|
+
async createReceiver(options) {
|
|
701
|
+
const data = await this.rest.post(`${this.route}/receivers`, { body: options });
|
|
702
|
+
return this._add(new Receiver(this.client, data));
|
|
703
|
+
}
|
|
704
|
+
/** List this consumer's receivers (paginated). */
|
|
705
|
+
async receivers(options = {}) {
|
|
706
|
+
const data = await this.rest.get(`${this.route}/receivers`, {
|
|
707
|
+
query: { take: options.take, skip: options.skip }
|
|
708
|
+
});
|
|
709
|
+
return {
|
|
710
|
+
items: data.data.map((d) => this._add(new Receiver(this.client, d))),
|
|
711
|
+
total: data.total,
|
|
712
|
+
take: data.take,
|
|
713
|
+
skip: data.skip
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
/** One receiver, materialized. Reading it refreshes `kycStatus` upstream. */
|
|
717
|
+
async fetchReceiver(id) {
|
|
718
|
+
return this._add(new Receiver(this.client, await this.fetchReceiverRaw(id)));
|
|
719
|
+
}
|
|
720
|
+
/** The raw payload, so a {@link Receiver} can patch itself in place. */
|
|
721
|
+
fetchReceiverRaw(id) {
|
|
722
|
+
return this.rest.get(`${this.route}/receivers/${id}`);
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Update a receiver — the same fields as creation, all optional. Once the receiver
|
|
726
|
+
* exists at the provider, identity fields need an elevated key; see
|
|
727
|
+
* {@link UpdateReceiverOptions}.
|
|
728
|
+
*/
|
|
729
|
+
async updateReceiver(id, options) {
|
|
730
|
+
const data = await this.rest.patch(`${this.route}/receivers/${id}`, {
|
|
731
|
+
body: options
|
|
732
|
+
});
|
|
733
|
+
return this._add(new Receiver(this.client, data));
|
|
734
|
+
}
|
|
735
|
+
/** Delete a receiver. */
|
|
736
|
+
async deleteReceiver(id) {
|
|
737
|
+
await this.rest.delete(`${this.route}/receivers/${id}`);
|
|
738
|
+
this.cache.delete(id);
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Approve a receiver sitting in review. Admin-only: it is the human gate on a
|
|
742
|
+
* verification the provider could not decide by itself.
|
|
743
|
+
*/
|
|
744
|
+
approveReceiver(id, options = {}) {
|
|
745
|
+
return this.rest.post(`${this.route}/receivers/${id}/approve`, { body: options });
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Ask for a terms-of-service link for an existing receiver. `channel: 'code'`
|
|
749
|
+
* returns the URL to render; `'email'` sends it to the receiver instead.
|
|
750
|
+
*/
|
|
751
|
+
requestTos(id, options) {
|
|
752
|
+
return this.rest.post(`${this.route}/receivers/${id}/tos`, {
|
|
753
|
+
body: options
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
/** Enable an inactive receiver with an accepted terms-of-service id. */
|
|
757
|
+
async enableReceiver(id, options) {
|
|
758
|
+
const data = await this.rest.post(`${this.route}/receivers/${id}/enable`, {
|
|
759
|
+
body: options
|
|
760
|
+
});
|
|
761
|
+
return this._add(new Receiver(this.client, data));
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Cut a receiver off from both ramps, or let it back in. Admin-only, and the
|
|
765
|
+
* fastest lever there is when something is wrong with an account.
|
|
766
|
+
*/
|
|
767
|
+
async setReceiverAccess(id, options) {
|
|
768
|
+
const data = await this.rest.patch(`${this.route}/receivers/${id}/access`, {
|
|
769
|
+
body: options
|
|
770
|
+
});
|
|
771
|
+
return this._add(new Receiver(this.client, data));
|
|
772
|
+
}
|
|
773
|
+
/* ------------------------------ wallets -------------------------------- */
|
|
774
|
+
/**
|
|
775
|
+
* The message a receiver must sign to prove it controls an address. Sign it,
|
|
776
|
+
* then pass the resulting transaction hash as `signature_tx_hash` to
|
|
777
|
+
* {@link addWallet}.
|
|
778
|
+
*/
|
|
779
|
+
walletSignMessage(receiverId) {
|
|
780
|
+
return this.rest.get(
|
|
781
|
+
`${this.route}/receivers/${receiverId}/wallets/sign-message`
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
/** Register a blockchain wallet for a receiver. */
|
|
785
|
+
addWallet(receiverId, options) {
|
|
786
|
+
return this.rest.post(`${this.route}/receivers/${receiverId}/wallets`, {
|
|
787
|
+
body: options
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
/** A receiver's wallets (paginated). */
|
|
791
|
+
async wallets(receiverId, options = {}) {
|
|
792
|
+
const data = await this.rest.get(
|
|
793
|
+
`${this.route}/receivers/${receiverId}/wallets`,
|
|
794
|
+
{ query: { take: options.take, skip: options.skip } }
|
|
795
|
+
);
|
|
796
|
+
return { items: data.data, total: data.total, take: data.take, skip: data.skip };
|
|
797
|
+
}
|
|
798
|
+
/** Delete one of a receiver's wallets. */
|
|
799
|
+
async deleteWallet(receiverId, id) {
|
|
800
|
+
await this.rest.delete(`${this.route}/receivers/${receiverId}/wallets/${id}`);
|
|
801
|
+
}
|
|
802
|
+
/* ---------------------------- bank accounts ---------------------------- */
|
|
803
|
+
/** Add a fiat bank account for a receiver — where an off-ramp pays out. */
|
|
804
|
+
addBankAccount(receiverId, options) {
|
|
805
|
+
return this.rest.post(
|
|
806
|
+
`${this.route}/receivers/${receiverId}/bank-accounts`,
|
|
807
|
+
{ body: options }
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
/** A receiver's bank accounts (paginated). */
|
|
811
|
+
async bankAccounts(receiverId, options = {}) {
|
|
812
|
+
const data = await this.rest.get(
|
|
813
|
+
`${this.route}/receivers/${receiverId}/bank-accounts`,
|
|
814
|
+
{ query: { take: options.take, skip: options.skip } }
|
|
815
|
+
);
|
|
816
|
+
return { items: data.data, total: data.total, take: data.take, skip: data.skip };
|
|
817
|
+
}
|
|
818
|
+
/** Delete one of a receiver's bank accounts. */
|
|
819
|
+
async deleteBankAccount(receiverId, id) {
|
|
820
|
+
await this.rest.delete(`${this.route}/receivers/${receiverId}/bank-accounts/${id}`);
|
|
821
|
+
}
|
|
822
|
+
/* ------------------------------ the rest ------------------------------- */
|
|
823
|
+
/**
|
|
824
|
+
* Upload a KYC document and get back the `file_url` every `*_file` field
|
|
825
|
+
* expects. Documents are uploaded first and referenced by URL — the receiver
|
|
826
|
+
* payload never carries bytes.
|
|
827
|
+
*/
|
|
828
|
+
upload(file) {
|
|
829
|
+
return this.rest.post(`${this.route}/upload`, { body: file });
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Start terms-of-service acceptance and get the hosted URL. This is the FIRST
|
|
833
|
+
* step of the flow: the provider will not create a receiver without the `tos_id`
|
|
834
|
+
* it produces.
|
|
835
|
+
*/
|
|
836
|
+
termsOfService(options = {}) {
|
|
837
|
+
return this.rest.post(`${this.route}/terms-of-service`, { body: options });
|
|
838
|
+
}
|
|
839
|
+
/** The bank rails available to this consumer. */
|
|
840
|
+
rails() {
|
|
841
|
+
return this.rest.get(`${this.route}/rails`);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* The field schema a given rail requires. The authority on which of the ~70
|
|
845
|
+
* rail-specific bank-account fields to send — read it at runtime rather than
|
|
846
|
+
* hard-coding a rail's shape.
|
|
847
|
+
*/
|
|
848
|
+
bankDetails(rail) {
|
|
849
|
+
return this.rest.get(`${this.route}/bank-details`, { query: { rail } });
|
|
850
|
+
}
|
|
851
|
+
get rest() {
|
|
852
|
+
return this.client.rest;
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
// src/managers/PollarManager.ts
|
|
857
|
+
var PollarManager = class {
|
|
858
|
+
constructor(client) {
|
|
859
|
+
this.route = "/pollar";
|
|
860
|
+
this.client = client;
|
|
861
|
+
}
|
|
862
|
+
get rest() {
|
|
863
|
+
return this.client.rest;
|
|
864
|
+
}
|
|
865
|
+
/* -------------------------------- login -------------------------------- */
|
|
866
|
+
/** Start a login and get the URL to send the user to. */
|
|
867
|
+
authorize(options) {
|
|
868
|
+
return this.rest.post(`${this.route}/oauth/authorize`, { body: options });
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Poll a login. `status: 'authorized'` carries the bridge `code` to redeem;
|
|
872
|
+
* `pending` means keep waiting; anything else is over.
|
|
873
|
+
*/
|
|
874
|
+
session(state) {
|
|
875
|
+
return this.rest.get(`${this.route}/oauth/sessions/${state}`);
|
|
876
|
+
}
|
|
877
|
+
/** Redeem the bridge code for a session. Single use — a consumed code is dead. */
|
|
878
|
+
token(options) {
|
|
879
|
+
return this.rest.post(`${this.route}/oauth/token`, { body: options });
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Rotate the token pair. The old refresh token stops working, so store what
|
|
883
|
+
* comes back before using it — a rotation you lose is a session you lose.
|
|
884
|
+
*/
|
|
885
|
+
refresh(options) {
|
|
886
|
+
return this.rest.post(`${this.route}/oauth/refresh`, { body: options });
|
|
887
|
+
}
|
|
888
|
+
/** Revoke a session — this device, or every one of them. */
|
|
889
|
+
logout(options) {
|
|
890
|
+
return this.rest.post(`${this.route}/oauth/logout`, { body: options });
|
|
891
|
+
}
|
|
892
|
+
/** Validate an end-user access token and learn whose it is. */
|
|
893
|
+
verifyToken(options) {
|
|
894
|
+
return this.rest.post(`${this.route}/tokens/verify`, {
|
|
895
|
+
body: options
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
/* ------------------------------- wallets ------------------------------- */
|
|
899
|
+
/**
|
|
900
|
+
* Fund a wallet's XLM base reserve. A Stellar account does not exist until
|
|
901
|
+
* something pays for it, which is why a fresh Pollar wallet can have an address
|
|
902
|
+
* and still not be on the network.
|
|
903
|
+
*/
|
|
904
|
+
activateWallet(options) {
|
|
905
|
+
return this.rest.post(`${this.route}/wallets/activate`, {
|
|
906
|
+
body: options
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
/** Enable the application's configured assets on a wallet. */
|
|
910
|
+
addDefaultTrustlines(address) {
|
|
911
|
+
return this.rest.post(
|
|
912
|
+
`${this.route}/wallets/${address}/trustlines/default`
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
/** Enable specific assets on a wallet. */
|
|
916
|
+
addTrustlines(address, options) {
|
|
917
|
+
return this.rest.post(`${this.route}/wallets/${address}/trustlines`, {
|
|
918
|
+
body: options
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Remove a trustline. An asset is `(code, issuer)`, and both are in the path for
|
|
923
|
+
* that reason: a bare code names no asset.
|
|
924
|
+
*/
|
|
925
|
+
removeTrustline(address, code, issuer) {
|
|
926
|
+
return this.rest.delete(
|
|
927
|
+
`${this.route}/wallets/${address}/trustlines/${code}/${issuer}`
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
/* -------------------------------- users -------------------------------- */
|
|
931
|
+
/**
|
|
932
|
+
* Register a user with Pollar ahead of their first login. Needs an elevated
|
|
933
|
+
* (admin) key: the Pollar user directory is shared by every tenant, so a tenant
|
|
934
|
+
* key gets `403 elevated_key_required`.
|
|
935
|
+
*/
|
|
936
|
+
registerUser(options) {
|
|
937
|
+
return this.rest.post(`${this.route}/users`, { body: options });
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Register a user AND provision their Stellar wallet in one call — the variant
|
|
941
|
+
* to use when the user should be able to receive before they ever log in. Needs
|
|
942
|
+
* an elevated (admin) key, like {@link registerUser}.
|
|
943
|
+
*/
|
|
944
|
+
registerUserWithWallet(options) {
|
|
945
|
+
return this.rest.post(`${this.route}/users/with-wallet`, { body: options });
|
|
946
|
+
}
|
|
947
|
+
};
|
|
228
948
|
|
|
229
949
|
// src/structures/PaymentIntent.ts
|
|
230
950
|
var PaymentIntent = class extends Base {
|
|
@@ -899,7 +1619,7 @@ var WebhookEndpoint = class extends Base {
|
|
|
899
1619
|
};
|
|
900
1620
|
|
|
901
1621
|
// src/util/Constants.ts
|
|
902
|
-
var version = "
|
|
1622
|
+
var version = "2.0.0";
|
|
903
1623
|
var DEFAULT_BASE_URL = "https://api.cosmospay.lat/cosmos-api";
|
|
904
1624
|
var DEFAULT_VERSION = "v1";
|
|
905
1625
|
var DEFAULT_TIMEOUT = 3e4;
|
|
@@ -1450,6 +2170,12 @@ var Client = class extends events.EventEmitter {
|
|
|
1450
2170
|
this.webhooks = new WebhookManager(this);
|
|
1451
2171
|
this.products = new ProductManager(this);
|
|
1452
2172
|
this.swaps = new SwapManager(this);
|
|
2173
|
+
this.liquidity = new LiquidityManager(this);
|
|
2174
|
+
this.onramp = new OnrampManager(this);
|
|
2175
|
+
this.offramp = new OfframpManager(this);
|
|
2176
|
+
this.activity = new ActivityManager(this);
|
|
2177
|
+
this.kyc = new KycManager(this);
|
|
2178
|
+
this.pollar = new PollarManager(this);
|
|
1453
2179
|
this.customers = new CustomerManager(this);
|
|
1454
2180
|
this.analytics = new AnalyticsManager(this);
|
|
1455
2181
|
this.health = new HealthManager(this);
|
|
@@ -1473,6 +2199,8 @@ var Client = class extends events.EventEmitter {
|
|
|
1473
2199
|
|
|
1474
2200
|
// src/common/wallets.ts
|
|
1475
2201
|
var Wallets = {
|
|
2202
|
+
/** Cosmos Pay's own wallet — extension, or the hosted build (see CosmosWalletAdapter). */
|
|
2203
|
+
COSMOS: "cosmos",
|
|
1476
2204
|
FREIGHTER: "freighter",
|
|
1477
2205
|
XBULL: "xbull",
|
|
1478
2206
|
RABET: "rabet",
|
|
@@ -1480,6 +2208,7 @@ var Wallets = {
|
|
|
1480
2208
|
ALBEDO: "albedo"
|
|
1481
2209
|
};
|
|
1482
2210
|
|
|
2211
|
+
exports.ActivityManager = ActivityManager;
|
|
1483
2212
|
exports.AddressBook = AddressBook;
|
|
1484
2213
|
exports.AnalyticsManager = AnalyticsManager;
|
|
1485
2214
|
exports.Assets = Assets;
|
|
@@ -1496,14 +2225,21 @@ exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
|
|
|
1496
2225
|
exports.DEFAULT_VERSION = DEFAULT_VERSION;
|
|
1497
2226
|
exports.Events = Events;
|
|
1498
2227
|
exports.HealthManager = HealthManager;
|
|
2228
|
+
exports.KycManager = KycManager;
|
|
2229
|
+
exports.LiquidityManager = LiquidityManager;
|
|
2230
|
+
exports.LiquidityOperation = LiquidityOperation;
|
|
2231
|
+
exports.OfframpManager = OfframpManager;
|
|
2232
|
+
exports.OnrampManager = OnrampManager;
|
|
1499
2233
|
exports.PaymentIntent = PaymentIntent;
|
|
1500
2234
|
exports.PaymentIntentKind = PaymentIntentKind;
|
|
1501
2235
|
exports.PaymentIntentManager = PaymentIntentManager;
|
|
1502
2236
|
exports.PaymentIntentStatus = PaymentIntentStatus;
|
|
2237
|
+
exports.PollarManager = PollarManager;
|
|
1503
2238
|
exports.Product = Product;
|
|
1504
2239
|
exports.ProductKind = ProductKind;
|
|
1505
2240
|
exports.ProductManager = ProductManager;
|
|
1506
2241
|
exports.REST = REST;
|
|
2242
|
+
exports.Receiver = Receiver;
|
|
1507
2243
|
exports.SIGNATURE_HEADER = SIGNATURE_HEADER;
|
|
1508
2244
|
exports.Swap = Swap;
|
|
1509
2245
|
exports.SwapManager = SwapManager;
|