@peable.to/sdk 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +14 -0
  2. package/dist/cjs/browser/mount.js +55 -8
  3. package/dist/cjs/browser/payerClient.js +58 -8
  4. package/dist/cjs/checkout.js +9 -1
  5. package/dist/cjs/core/client.js +25 -1
  6. package/dist/cjs/core/config.js +11 -0
  7. package/dist/cjs/core/errors.js +1 -1
  8. package/dist/cjs/core/serviceToken.js +11 -2
  9. package/dist/cjs/index.js +28 -1
  10. package/dist/cjs/resources/billing.js +25 -0
  11. package/dist/cjs/resources/checkoutSessions.js +2 -1
  12. package/dist/cjs/resources/connectedAccounts.js +63 -0
  13. package/dist/cjs/resources/merchants.js +51 -0
  14. package/dist/cjs/resources/paymentIntents.js +30 -2
  15. package/dist/cjs/resources/refunds.js +54 -0
  16. package/dist/cjs/resources/transfers.js +49 -0
  17. package/dist/esm/browser/mount.js +52 -7
  18. package/dist/esm/browser/payerClient.js +58 -8
  19. package/dist/esm/checkout.js +5 -0
  20. package/dist/esm/core/client.js +25 -1
  21. package/dist/esm/core/config.js +10 -0
  22. package/dist/esm/core/errors.js +1 -1
  23. package/dist/esm/core/serviceToken.js +11 -2
  24. package/dist/esm/index.js +28 -1
  25. package/dist/esm/resources/billing.js +21 -0
  26. package/dist/esm/resources/checkoutSessions.js +2 -1
  27. package/dist/esm/resources/connectedAccounts.js +59 -0
  28. package/dist/esm/resources/merchants.js +46 -0
  29. package/dist/esm/resources/paymentIntents.js +30 -2
  30. package/dist/esm/resources/refunds.js +50 -0
  31. package/dist/esm/resources/transfers.js +45 -0
  32. package/dist/types/browser/mount.d.ts +23 -1
  33. package/dist/types/browser/payerClient.d.ts +56 -2
  34. package/dist/types/checkout.d.ts +2 -1
  35. package/dist/types/core/client.d.ts +1 -0
  36. package/dist/types/core/config.d.ts +4 -0
  37. package/dist/types/core/errors.d.ts +2 -2
  38. package/dist/types/index.d.ts +40 -1
  39. package/dist/types/resources/billing.d.ts +15 -0
  40. package/dist/types/resources/checkoutSessions.d.ts +15 -1
  41. package/dist/types/resources/connectedAccounts.d.ts +84 -0
  42. package/dist/types/resources/merchants.d.ts +113 -0
  43. package/dist/types/resources/paymentIntents.d.ts +47 -1
  44. package/dist/types/resources/refunds.d.ts +77 -0
  45. package/dist/types/resources/transfers.d.ts +75 -0
  46. package/package.json +2 -2
@@ -0,0 +1,77 @@
1
+ import type { Refund, Settlement } from '@peable.to/shared-types';
2
+ import type { RestClient } from '../core/client';
3
+ /**
4
+ * Sending money back to a payer.
5
+ *
6
+ * The one operation on this API whose duplicate is unrecoverable: a payer sent
7
+ * their money twice has no reason to report it, and nothing reverses the second
8
+ * automatically. `externalRef` — your own refund id — is what every path here
9
+ * converges on, and unlike a header key you cannot lose it.
10
+ */
11
+ export interface CreateRefundParams {
12
+ /** The `pi_…` being refunded. */
13
+ paymentIntentId: string;
14
+ /** YOUR id for this refund. The idempotency. */
15
+ externalRef: string;
16
+ /** Minor units, as a canonical integer string. Zero is refused. */
17
+ amount: string;
18
+ }
19
+ export interface RefundList {
20
+ object: 'list';
21
+ data: Refund[];
22
+ /**
23
+ * What can still go back, in minor units.
24
+ *
25
+ * Offered because otherwise every integrator computes it by summing the list
26
+ * — and the ones who forget that a `pending` or `failed` refund moved no
27
+ * money compute it wrong, in the direction that refuses a legitimate refund.
28
+ * It reserves PENDING refunds, which is what stops two concurrent ones
29
+ * between them exceeding the payment.
30
+ */
31
+ remainingRefundable: string;
32
+ }
33
+ export declare class RefundsResource {
34
+ private readonly client;
35
+ constructor(client: RestClient);
36
+ /**
37
+ * Refund part or all of a payment.
38
+ *
39
+ * **`status` is the refund's own lifecycle and it is not always
40
+ * `succeeded`.** A provider can report a refund `pending` — and a bank can
41
+ * reject one days later, which arrives as an event and moves the row to
42
+ * `failed`. Treating the creation as completion is how a merchant's books
43
+ * come to say money went back that is still with them.
44
+ *
45
+ * `paymentStatus` on the response is where the PAYMENT stands after it, so a
46
+ * caller does not need a second read whose answer can move on before it
47
+ * arrives.
48
+ */
49
+ create(params: CreateRefundParams, options?: {
50
+ idempotencyKey?: string;
51
+ }): Promise<Refund>;
52
+ /**
53
+ * What this payment actually came to — gross, fee, net.
54
+ *
55
+ * On this resource because it is the same question you ask in the same
56
+ * breath: how much of this money is really mine.
57
+ *
58
+ * **A missing figure is `null` with a `status`, never `0`.** `unknown` means
59
+ * there is nothing to read — an uncaptured payment, a FairCoin one, a
60
+ * provider that could not be reached — and treating it as zero is how a
61
+ * reconciliation silently gains money that was never there.
62
+ *
63
+ * It reports what the provider took. It does NOT say which entity bears that
64
+ * cost: a fee paid by the operator of a Peable deployment is not
65
+ * automatically your expense, and that is a commercial question this API does
66
+ * not answer.
67
+ */
68
+ settlement(paymentIntentId: string): Promise<Settlement>;
69
+ /**
70
+ * Every refund against one payment, including ones made OUTSIDE Peable.
71
+ *
72
+ * A refund issued from the acquirer's dashboard, or created by the network
73
+ * resolving a dispute, is imported with `origin: 'provider'` and no
74
+ * `externalRef` — the merchant did not make it and has no id for it.
75
+ */
76
+ listForPaymentIntent(paymentIntentId: string): Promise<RefundList>;
77
+ }
@@ -0,0 +1,75 @@
1
+ import type { Transfer, TransferWithReversal } from '@peable.to/shared-types';
2
+ import type { RestClient } from '../core/client';
3
+ /**
4
+ * Settling a seller out of a funded payment, and taking it back.
5
+ *
6
+ * Two rules govern this whole surface and neither is negotiable:
7
+ *
8
+ * 1. **The amount comes from you.** Peable does not compute a marketplace's
9
+ * split and must never learn its fee schedule; it records that a stated
10
+ * amount was moved. A gateway that computed the split would be a second
11
+ * definition of it.
12
+ * 2. **Your own id is the idempotency.** `externalRef` is your order id, and
13
+ * unlike a header key you cannot lose it — a retried settlement converges on
14
+ * it rather than paying a seller twice.
15
+ */
16
+ export interface CreateTransferParams {
17
+ /** The `pi_…` this settles out of. Must be a SETTLED payment. */
18
+ paymentIntentId: string;
19
+ /** Name the seller by exactly one of these. */
20
+ connectedAccountId?: string;
21
+ connectedAccountRef?: string;
22
+ /** YOUR id for what this settles. The idempotency, and it is durable. */
23
+ externalRef: string;
24
+ /** Minor units, as a canonical integer string. In the payment's currency. */
25
+ amount: string;
26
+ }
27
+ export interface ReverseTransferParams {
28
+ amount: string;
29
+ /**
30
+ * YOUR id for THIS reversal — required, one way or the other.
31
+ *
32
+ * Supply it here, or as `options.idempotencyKey`, which the gateway accepts
33
+ * as the same identity. It cannot be omitted, and an AMOUNT IS NOT AN
34
+ * IDENTITY: two reversals of one settlement for the same amount are two
35
+ * distinct operations, and a gateway that keyed them by amount would answer
36
+ * the first one to the second request — leaving a seller holding money that
37
+ * had been taken back, with nothing recording that it was asked for.
38
+ */
39
+ externalRef?: string;
40
+ }
41
+ export interface TransferList {
42
+ object: 'list';
43
+ data: Transfer[];
44
+ }
45
+ export declare class TransfersResource {
46
+ private readonly client;
47
+ constructor(client: RestClient);
48
+ /**
49
+ * Settle one seller.
50
+ *
51
+ * Answers 201 for a new settlement and 200 for an order already settled,
52
+ * which is the distinction to act on after a timeout: "did I just pay this
53
+ * seller a second time" is a question with a real answer.
54
+ *
55
+ * Refused when the payment cannot fund it — the total settled out of one
56
+ * payment may not exceed what that payment brought in, because the overflow
57
+ * would come from the platform's general balance, which is other merchants'
58
+ * money in flight.
59
+ */
60
+ create(params: CreateTransferParams, options?: {
61
+ idempotencyKey?: string;
62
+ }): Promise<Transfer>;
63
+ /**
64
+ * Take some or all of a settlement back.
65
+ *
66
+ * The response carries the transfer AND the reversal leg, so a caller can
67
+ * tell which operation it is reading: `amountReversed` on the transfer is the
68
+ * provider's CUMULATIVE figure, while `reversal` is this one.
69
+ */
70
+ reverse(transferId: string, params: ReverseTransferParams, options?: {
71
+ idempotencyKey?: string;
72
+ }): Promise<TransferWithReversal>;
73
+ /** What one payment settled — the reconciliation read. */
74
+ listForPaymentIntent(paymentIntentId: string): Promise<TransferList>;
75
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peable.to/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "Peable SDK — a Stripe-ergonomics TypeScript client over the Peable Gateway REST + realtime contract. Server entry (`@peable.to/sdk`) mints Oxy service tokens from an ApplicationCredential and exposes paymentIntents/paymentLinks/checkout.sessions/webhooks; browser entry (`@peable.to/sdk/checkout`) is the anonymous payer-side client core.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -71,7 +71,7 @@
71
71
  "prepublishOnly": "bun run clean && bun run build"
72
72
  },
73
73
  "dependencies": {
74
- "@peable.to/shared-types": "workspace:^",
74
+ "@peable.to/shared-types": "^0.3.0",
75
75
  "qrcode-generator": "^2.0.4",
76
76
  "socket.io-client": "^4.8.3"
77
77
  },