@peable.to/shared-types 0.10.0 → 0.11.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/dist/cjs/charge.js +2 -0
- package/dist/cjs/customer.js +2 -0
- package/dist/cjs/event.js +7 -0
- package/dist/cjs/index.js +19 -8
- package/dist/cjs/paymentIntent.js +90 -188
- package/dist/cjs/paymentMethod.js +2 -0
- package/dist/cjs/setupIntent.js +11 -0
- package/dist/cjs/webhookEndpoint.js +20 -0
- package/dist/cjs/webhookSigner.js +35 -12
- package/dist/esm/charge.js +1 -0
- package/dist/esm/customer.js +1 -0
- package/dist/esm/event.js +6 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/paymentIntent.js +89 -186
- package/dist/esm/paymentMethod.js +1 -0
- package/dist/esm/setupIntent.js +8 -0
- package/dist/esm/webhookEndpoint.js +17 -0
- package/dist/esm/webhookSigner.js +35 -12
- package/dist/types/charge.d.ts +56 -0
- package/dist/types/customer.d.ts +39 -0
- package/dist/types/dispute.d.ts +2 -2
- package/dist/types/event.d.ts +99 -89
- package/dist/types/index.d.ts +7 -2
- package/dist/types/merchant.d.ts +0 -1
- package/dist/types/paymentIntent.d.ts +215 -84
- package/dist/types/paymentMethod.d.ts +33 -0
- package/dist/types/settlement.d.ts +0 -9
- package/dist/types/setupIntent.d.ts +39 -0
- package/dist/types/webhookDelivery.d.ts +15 -32
- package/dist/types/webhookEndpoint.d.ts +81 -0
- package/dist/types/webhookSigner.d.ts +13 -5
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CardDetails } from './charge';
|
|
2
|
+
import type { Customer } from './customer';
|
|
3
|
+
import type { Address, AddressParams } from './paymentIntent';
|
|
4
|
+
export interface BillingDetails {
|
|
5
|
+
address: Address | null;
|
|
6
|
+
email: string | null;
|
|
7
|
+
name: string | null;
|
|
8
|
+
phone: string | null;
|
|
9
|
+
}
|
|
10
|
+
export interface PaymentMethod {
|
|
11
|
+
id: string;
|
|
12
|
+
object: 'payment_method';
|
|
13
|
+
livemode: boolean;
|
|
14
|
+
type: 'card';
|
|
15
|
+
card: CardDetails;
|
|
16
|
+
billing_details: BillingDetails;
|
|
17
|
+
/** `cus_…`, or the {@link Customer} with `expand[]=customer`; `null` once detached. */
|
|
18
|
+
customer: string | Customer | null;
|
|
19
|
+
metadata: Record<string, string>;
|
|
20
|
+
created: number;
|
|
21
|
+
}
|
|
22
|
+
export interface UpdatePaymentMethodParams {
|
|
23
|
+
billing_details?: {
|
|
24
|
+
address?: AddressParams;
|
|
25
|
+
email?: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
phone?: string;
|
|
28
|
+
};
|
|
29
|
+
metadata?: Record<string, string>;
|
|
30
|
+
}
|
|
31
|
+
export interface AttachPaymentMethodParams {
|
|
32
|
+
customer: string;
|
|
33
|
+
}
|
|
@@ -229,15 +229,6 @@ export interface Refund {
|
|
|
229
229
|
amount: string;
|
|
230
230
|
currency: CurrencyCode | string;
|
|
231
231
|
status: RefundStatus;
|
|
232
|
-
/**
|
|
233
|
-
* Where the PAYMENT stands after this refund.
|
|
234
|
-
*
|
|
235
|
-
* On the refund deliberately: a caller that has just refunded needs to know
|
|
236
|
-
* whether the payment is now `partially_refunded` or `refunded`, and making
|
|
237
|
-
* them re-read the intent is a round trip whose answer can move on before it
|
|
238
|
-
* arrives.
|
|
239
|
-
*/
|
|
240
|
-
payment_status: string;
|
|
241
232
|
failure_code: string | null;
|
|
242
233
|
created: number;
|
|
243
234
|
updated_at: number;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Customer } from './customer';
|
|
2
|
+
import type { PaymentIntentLastPaymentError } from './paymentIntent';
|
|
3
|
+
import type { PaymentMethod } from './paymentMethod';
|
|
4
|
+
export type SetupIntentStatus = 'requires_payment_method' | 'requires_confirmation' | 'requires_action' | 'processing' | 'canceled' | 'succeeded';
|
|
5
|
+
export declare const SETUP_INTENT_STATUSES: readonly SetupIntentStatus[];
|
|
6
|
+
export type SetupIntentUsage = 'on_session' | 'off_session';
|
|
7
|
+
export type SetupIntentCancellationReason = 'abandoned' | 'duplicate' | 'requested_by_customer';
|
|
8
|
+
export interface SetupIntent {
|
|
9
|
+
id: string;
|
|
10
|
+
object: 'setup_intent';
|
|
11
|
+
livemode: boolean;
|
|
12
|
+
status: SetupIntentStatus;
|
|
13
|
+
usage: SetupIntentUsage;
|
|
14
|
+
payment_method_types: ['card'];
|
|
15
|
+
/** `cus_…`, or the {@link Customer} with `expand[]=customer`. */
|
|
16
|
+
customer: string | Customer | null;
|
|
17
|
+
/** The `pm_…` it saved, once `succeeded`. */
|
|
18
|
+
payment_method: string | PaymentMethod | null;
|
|
19
|
+
/** Possession of it lets the payer's browser confirm this SetupIntent. */
|
|
20
|
+
client_secret: string;
|
|
21
|
+
next_action: {
|
|
22
|
+
type: 'use_peable_sdk';
|
|
23
|
+
} | null;
|
|
24
|
+
last_setup_error: PaymentIntentLastPaymentError | null;
|
|
25
|
+
cancellation_reason: SetupIntentCancellationReason | null;
|
|
26
|
+
description: string | null;
|
|
27
|
+
metadata: Record<string, string>;
|
|
28
|
+
created: number;
|
|
29
|
+
}
|
|
30
|
+
export interface CreateSetupIntentParams {
|
|
31
|
+
customer?: string;
|
|
32
|
+
usage?: SetupIntentUsage;
|
|
33
|
+
payment_method_types?: ['card'];
|
|
34
|
+
description?: string;
|
|
35
|
+
metadata?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
export interface CancelSetupIntentParams {
|
|
38
|
+
cancellation_reason?: SetupIntentCancellationReason;
|
|
39
|
+
}
|
|
@@ -2,52 +2,35 @@ import type { WebhookEventType } from './event';
|
|
|
2
2
|
/**
|
|
3
3
|
* Where one webhook delivery stands (ADR 0001 D7).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* delivery could report once it had already given up. Delivery is now a durable
|
|
7
|
-
* outbox, so a delivery exists BEFORE any attempt and this set has to say so.
|
|
8
|
-
*
|
|
9
|
-
* - `pending` — enqueued and will be attempted. `nextAttemptAt` says when.
|
|
5
|
+
* - `pending` — will be attempted. `next_attempt_at` says when.
|
|
10
6
|
* - `delivered` — terminal success.
|
|
11
|
-
* - `failed` — the endpoint REFUSED it (a 4xx, a blocked address)
|
|
7
|
+
* - `failed` — the endpoint REFUSED it (a 4xx, a blocked address), or the
|
|
8
|
+
* endpoint was disabled before it could be attempted. No retry
|
|
12
9
|
* can fix that, so none is made.
|
|
13
|
-
* - `dead` — every attempt failed transiently
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* ⚠️ Widening a published union is a breaking change for a consumer that
|
|
17
|
-
* switches exhaustively on it. It is the honest shape: the previous one could
|
|
18
|
-
* not describe a delivery that had not been attempted yet, which is now the
|
|
19
|
-
* state every delivery starts in.
|
|
10
|
+
* - `dead` — every attempt failed transiently over three days and the
|
|
11
|
+
* budget ran out. It can be redelivered by hand.
|
|
20
12
|
*/
|
|
21
13
|
export type WebhookDeliveryStatus = 'pending' | 'delivered' | 'failed' | 'dead';
|
|
14
|
+
/**
|
|
15
|
+
* One event sent to one webhook endpoint (ADR 0014 D4). An event that matches
|
|
16
|
+
* three endpoints is three deliveries, each with its own attempts.
|
|
17
|
+
*/
|
|
22
18
|
export interface WebhookDelivery {
|
|
23
19
|
id: string;
|
|
24
20
|
object: 'webhook_delivery';
|
|
25
|
-
/**
|
|
26
|
-
* Which of the provider's two worlds this object belongs to (ADR 0017):
|
|
27
|
-
* `true` for a `production` merchant, `false` for every other environment.
|
|
28
|
-
*/
|
|
21
|
+
/** The mode of the merchant it was sent for (ADR 0017). */
|
|
29
22
|
livemode: boolean;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The `pi_…` this delivery is about — `null` when the event is not about a
|
|
33
|
-
* payment.
|
|
34
|
-
*
|
|
35
|
-
* Nullable since `connected_account.updated`, which is about a SELLER. The
|
|
36
|
-
* alternative was to name an unrelated payment to keep the field a string,
|
|
37
|
-
* which is worse than a null: a consumer correlating on it would attach a
|
|
38
|
-
* seller's readiness change to a payment that has nothing to do with it.
|
|
39
|
-
*/
|
|
40
|
-
intent_id: string | null;
|
|
23
|
+
/** The `evt_…` delivered — `GET /v1/events/:id` returns it. */
|
|
41
24
|
event_id: string;
|
|
42
25
|
event_type: WebhookEventType;
|
|
26
|
+
/** The `we_…` it was sent to. */
|
|
27
|
+
webhook_endpoint_id: string;
|
|
28
|
+
/** The URL actually POSTed to, as of the latest attempt. */
|
|
43
29
|
url: string;
|
|
44
30
|
attempts: number;
|
|
45
31
|
delivered: boolean;
|
|
46
32
|
last_status: WebhookDeliveryStatus;
|
|
47
|
-
/**
|
|
48
|
-
* Why the last attempt did not succeed — operator-facing, never a secret.
|
|
49
|
-
* Absent while pending with no attempts, and after a success.
|
|
50
|
-
*/
|
|
33
|
+
/** Why the last attempt did not succeed — operator-facing, never a secret. */
|
|
51
34
|
last_error?: string;
|
|
52
35
|
/** When the next attempt is due, Unix seconds. Absent once the delivery is terminal. */
|
|
53
36
|
next_attempt_at?: number;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { WebhookEventType } from './event';
|
|
2
|
+
/**
|
|
3
|
+
* A webhook endpoint (`we_…`) — one URL a merchant receives events at, with
|
|
4
|
+
* the event types it wants and the secret deliveries to it are signed with
|
|
5
|
+
* (ADR 0014 D4).
|
|
6
|
+
*
|
|
7
|
+
* A merchant may hold several; every event fans out to each ENABLED endpoint
|
|
8
|
+
* whose `enabled_events` matches it, as one delivery per endpoint.
|
|
9
|
+
*/
|
|
10
|
+
/** `'*'` subscribes to every event type, including ones added later. */
|
|
11
|
+
export type WebhookEnabledEvent = WebhookEventType | '*';
|
|
12
|
+
export declare const WEBHOOK_ENDPOINT_STATUSES: readonly ["enabled", "disabled"];
|
|
13
|
+
export type WebhookEndpointStatus = (typeof WEBHOOK_ENDPOINT_STATUSES)[number];
|
|
14
|
+
/**
|
|
15
|
+
* Why an endpoint is `disabled`.
|
|
16
|
+
*
|
|
17
|
+
* - `disabled_by_merchant` — its owner set `disabled: true`.
|
|
18
|
+
* - `delivery_failures` — every delivery to it failed for three days
|
|
19
|
+
* straight, so Peable stopped sending. Re-enabling it (`disabled: false`)
|
|
20
|
+
* starts the clock again.
|
|
21
|
+
*/
|
|
22
|
+
export declare const WEBHOOK_ENDPOINT_DISABLED_REASONS: readonly ["disabled_by_merchant", "delivery_failures"];
|
|
23
|
+
export type WebhookEndpointDisabledReason = (typeof WEBHOOK_ENDPOINT_DISABLED_REASONS)[number];
|
|
24
|
+
/** At most this many endpoints per merchant (per mode). */
|
|
25
|
+
export declare const WEBHOOK_ENDPOINTS_MAX_PER_MERCHANT = 16;
|
|
26
|
+
/** The longest a rolled secret may keep signing beside its replacement. */
|
|
27
|
+
export declare const WEBHOOK_SECRET_ROLL_MAX_EXPIRES_IN_SECONDS: number;
|
|
28
|
+
export interface WebhookEndpoint {
|
|
29
|
+
id: string;
|
|
30
|
+
object: 'webhook_endpoint';
|
|
31
|
+
/** The mode of the merchant that owns it (ADR 0017). */
|
|
32
|
+
livemode: boolean;
|
|
33
|
+
url: string;
|
|
34
|
+
description: string | null;
|
|
35
|
+
enabled_events: WebhookEnabledEvent[];
|
|
36
|
+
status: WebhookEndpointStatus;
|
|
37
|
+
/** `null` exactly when `status` is `enabled`. */
|
|
38
|
+
disabled_reason: WebhookEndpointDisabledReason | null;
|
|
39
|
+
/** The wire version events are rendered with for this endpoint. */
|
|
40
|
+
api_version: string;
|
|
41
|
+
metadata: Record<string, string>;
|
|
42
|
+
/**
|
|
43
|
+
* The signing secret (`whsec_…`). Present ONLY on the response that
|
|
44
|
+
* created it — the create, and a `roll_secret`. Peable never shows it again;
|
|
45
|
+
* a lost secret is rolled, not retrieved.
|
|
46
|
+
*/
|
|
47
|
+
secret?: string;
|
|
48
|
+
created: number;
|
|
49
|
+
updated_at: number;
|
|
50
|
+
}
|
|
51
|
+
/** What `DELETE /v1/webhook_endpoints/:id` answers. */
|
|
52
|
+
export interface DeletedWebhookEndpoint {
|
|
53
|
+
id: string;
|
|
54
|
+
object: 'webhook_endpoint';
|
|
55
|
+
deleted: true;
|
|
56
|
+
}
|
|
57
|
+
export interface CreateWebhookEndpointParams {
|
|
58
|
+
/** An `https` URL (a test-mode endpoint may also use `http`), ports 80/443 only. */
|
|
59
|
+
url: string;
|
|
60
|
+
enabled_events: WebhookEnabledEvent[];
|
|
61
|
+
description?: string;
|
|
62
|
+
metadata?: Record<string, string>;
|
|
63
|
+
}
|
|
64
|
+
export interface UpdateWebhookEndpointParams {
|
|
65
|
+
url?: string;
|
|
66
|
+
enabled_events?: WebhookEnabledEvent[];
|
|
67
|
+
/** `true` stops deliveries; `false` re-enables an endpoint, whatever disabled it. */
|
|
68
|
+
disabled?: boolean;
|
|
69
|
+
/** `''` clears it. */
|
|
70
|
+
description?: string;
|
|
71
|
+
/** Merged: named keys are set, a key sent as `''` is removed. */
|
|
72
|
+
metadata?: Record<string, string>;
|
|
73
|
+
}
|
|
74
|
+
export interface RollWebhookEndpointSecretParams {
|
|
75
|
+
/**
|
|
76
|
+
* How long the PREVIOUS secret keeps signing beside the new one, in seconds
|
|
77
|
+
* (0–86400, default 0). While both are live every delivery carries two
|
|
78
|
+
* `v1=` signatures, so a receiver can switch secrets without a gap.
|
|
79
|
+
*/
|
|
80
|
+
expires_in_seconds?: number;
|
|
81
|
+
}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Produce a Stripe-style signature header for an outbound webhook:
|
|
3
|
-
* `t=${timestamp},v1=${
|
|
3
|
+
* `t=${timestamp},v1=${hex}` — with one `v1=` per secret.
|
|
4
|
+
*
|
|
5
|
+
* Several secrets are what make a rotation gapless: while an endpoint's rolled
|
|
6
|
+
* secret is still inside its overlap window, every delivery is signed with
|
|
7
|
+
* BOTH, so a receiver verifying with either one accepts it.
|
|
4
8
|
*/
|
|
5
|
-
export declare function signWebhook(secret: string, rawBody: string, timestamp: number): string;
|
|
9
|
+
export declare function signWebhook(secret: string | readonly string[], rawBody: string, timestamp: number): string;
|
|
6
10
|
/**
|
|
7
11
|
* Verify a webhook signature header against the raw body.
|
|
8
|
-
*
|
|
12
|
+
*
|
|
13
|
+
* - Parses `t` and EVERY `v1` from the header.
|
|
9
14
|
* - Rejects if the timestamp drifts more than `toleranceSec` from `nowSec`.
|
|
10
|
-
* -
|
|
15
|
+
* - Accepts when any `v1` matches the signature computed with any of
|
|
16
|
+
* `secret` — so a receiver mid-rotation can pass both of its secrets, and a
|
|
17
|
+
* delivery signed during the sender's overlap window verifies against
|
|
18
|
+
* either.
|
|
11
19
|
*/
|
|
12
|
-
export declare function verifyWebhook(secret: string, rawBody: string, header: string, toleranceSec: number, nowSec: number): boolean;
|
|
20
|
+
export declare function verifyWebhook(secret: string | readonly string[], rawBody: string, header: string, toleranceSec: number, nowSec: number): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peable.to/shared-types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Shared TypeScript types for the Peable Gateway — the wire contract shared by the backend, SDK, and frontend.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|