@proxy-checkout/server-js 0.0.4-pr-76.30.1 → 0.0.4-pr-76.32.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.
- package/dist/cjs/cart.d.cts +17 -0
- package/dist/cjs/cart.d.ts +17 -0
- package/dist/cjs/client.d.cts +19 -0
- package/dist/cjs/client.d.ts +19 -0
- package/dist/cjs/consistency.d.cts +20 -0
- package/dist/cjs/consistency.d.ts +20 -0
- package/dist/cjs/errors.d.cts +32 -0
- package/dist/cjs/errors.d.ts +32 -0
- package/dist/cjs/events.d.cts +89 -0
- package/dist/cjs/events.d.ts +89 -0
- package/dist/cjs/http-client.d.cts +16 -0
- package/dist/cjs/http-client.d.ts +16 -0
- package/dist/cjs/index.d.cts +13 -0
- package/dist/cjs/index.d.ts +13 -0
- package/dist/cjs/lifecycle.d.cts +47 -0
- package/dist/cjs/lifecycle.d.ts +47 -0
- package/dist/cjs/response-validators.d.cts +8 -0
- package/dist/cjs/response-validators.d.ts +8 -0
- package/dist/cjs/sessions.d.cts +152 -0
- package/dist/cjs/sessions.d.ts +152 -0
- package/dist/cjs/subscriptions.d.cts +54 -0
- package/dist/cjs/subscriptions.d.ts +54 -0
- package/dist/cjs/types.d.cts +16 -0
- package/dist/cjs/types.d.ts +16 -0
- package/dist/cjs/version.d.cts +3 -0
- package/dist/cjs/version.d.ts +3 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/webhook-events.d.cts +34 -0
- package/dist/cjs/webhook-events.d.ts +34 -0
- package/dist/cjs/webhook-handler.d.cts +89 -0
- package/dist/cjs/webhook-handler.d.ts +89 -0
- package/dist/cjs/webhooks.d.cts +84 -0
- package/dist/cjs/webhooks.d.ts +84 -0
- package/dist/esm/version.d.ts +2 -2
- package/dist/esm/version.js +1 -1
- package/package.json +9 -4
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { type ProxyCartParseOptions, type ProxyCartValidator } from "./cart.js";
|
|
2
|
+
import type { ProxyCheckoutHttpClient } from "./http-client.js";
|
|
3
|
+
import type { JsonObject, ProxyCheckoutServerRequestOptions } from "./types.js";
|
|
4
|
+
export interface CreateProxySessionOptions extends ProxyCheckoutServerRequestOptions {
|
|
5
|
+
readonly idempotencyKey?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CreateProxySessionInput extends CreateProxySessionOptions {
|
|
8
|
+
readonly amountMinor: number;
|
|
9
|
+
readonly buyerReference: string;
|
|
10
|
+
readonly cartSnapshot: JsonObject;
|
|
11
|
+
readonly currency: string;
|
|
12
|
+
readonly expiresAt?: Date | string;
|
|
13
|
+
readonly integrationMode?: "elements";
|
|
14
|
+
readonly metadata?: JsonObject;
|
|
15
|
+
readonly payerContact?: {
|
|
16
|
+
readonly email?: string;
|
|
17
|
+
readonly phone?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface CreateProxySessionHandoffInput extends CreateProxySessionInput {
|
|
21
|
+
readonly payHost?: string;
|
|
22
|
+
readonly publishableKey?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ProxySession {
|
|
25
|
+
readonly expiresAt: string;
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly integrationMode: string;
|
|
28
|
+
readonly status: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ProxySessionHandoff extends ProxySession {
|
|
31
|
+
readonly handoffUrl: string;
|
|
32
|
+
readonly status: "payer_handoff_pending" | "payer_opened";
|
|
33
|
+
}
|
|
34
|
+
export interface MerchantProxySession {
|
|
35
|
+
readonly amountMinor: number;
|
|
36
|
+
readonly buyerReference: string;
|
|
37
|
+
readonly cartSnapshot: JsonObject;
|
|
38
|
+
readonly cartVersion: number;
|
|
39
|
+
readonly createdAt: string;
|
|
40
|
+
readonly currency: string;
|
|
41
|
+
readonly expiresAt: string;
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly idempotencyKey: string | null;
|
|
44
|
+
readonly integrationMode: string;
|
|
45
|
+
readonly metadata: JsonObject;
|
|
46
|
+
readonly payerContact: {
|
|
47
|
+
readonly email: string | null;
|
|
48
|
+
readonly phone: string | null;
|
|
49
|
+
} | null;
|
|
50
|
+
readonly providerCheckoutSessionId: string | null;
|
|
51
|
+
readonly providerCheckoutSessionPsp: string | null;
|
|
52
|
+
readonly status: string;
|
|
53
|
+
readonly updatedAt: string;
|
|
54
|
+
}
|
|
55
|
+
export interface PayerOpenedResult extends MerchantProxySession {
|
|
56
|
+
readonly status: "payer_opened";
|
|
57
|
+
}
|
|
58
|
+
/** A merchant session with its cart snapshot validated against a merchant schema. */
|
|
59
|
+
export interface TypedMerchantProxySession<TCart> extends MerchantProxySession {
|
|
60
|
+
readonly cart: TCart;
|
|
61
|
+
}
|
|
62
|
+
export interface PayerHandoffResult {
|
|
63
|
+
readonly status: "payer_handoff_pending" | "payer_opened";
|
|
64
|
+
}
|
|
65
|
+
export interface SetProxySessionCartInput extends ProxyCheckoutServerRequestOptions {
|
|
66
|
+
readonly amountMinor: number;
|
|
67
|
+
readonly cartSnapshot: JsonObject;
|
|
68
|
+
readonly currency: string;
|
|
69
|
+
readonly expectedCartVersion: number;
|
|
70
|
+
}
|
|
71
|
+
export interface ProxySessionCartResult {
|
|
72
|
+
readonly amountMinor: number;
|
|
73
|
+
readonly cartSnapshot: JsonObject;
|
|
74
|
+
readonly cartVersion: number;
|
|
75
|
+
readonly currency: string;
|
|
76
|
+
}
|
|
77
|
+
export interface RecordProviderBindingInput extends ProxyCheckoutServerRequestOptions {
|
|
78
|
+
readonly providerCheckoutSessionId: string;
|
|
79
|
+
readonly psp: string;
|
|
80
|
+
}
|
|
81
|
+
export interface ProxySessionProviderBinding {
|
|
82
|
+
readonly providerCheckoutSessionId: string;
|
|
83
|
+
readonly proxySessionId: string;
|
|
84
|
+
readonly psp: string;
|
|
85
|
+
readonly updatedAt: string;
|
|
86
|
+
}
|
|
87
|
+
export declare const proxyCheckoutServerEndpoints: readonly [{
|
|
88
|
+
readonly method: "POST";
|
|
89
|
+
readonly operation: "sessions.create";
|
|
90
|
+
readonly path: "/proxy_sessions";
|
|
91
|
+
}, {
|
|
92
|
+
readonly method: "POST";
|
|
93
|
+
readonly operation: "sessions.createHandoff";
|
|
94
|
+
readonly path: "/proxy_sessions/handoff";
|
|
95
|
+
}, {
|
|
96
|
+
readonly method: "GET";
|
|
97
|
+
readonly operation: "sessions.retrieve";
|
|
98
|
+
readonly path: "/proxy_sessions/:id/merchant";
|
|
99
|
+
}, {
|
|
100
|
+
readonly method: "PUT";
|
|
101
|
+
readonly operation: "sessions.cart.set";
|
|
102
|
+
readonly path: "/proxy_sessions/:id/cart";
|
|
103
|
+
}, {
|
|
104
|
+
readonly method: "POST";
|
|
105
|
+
readonly operation: "sessions.payerHandoff";
|
|
106
|
+
readonly path: "/proxy_sessions/:id/payer_handoff";
|
|
107
|
+
}, {
|
|
108
|
+
readonly method: "POST";
|
|
109
|
+
readonly operation: "sessions.payerOpened";
|
|
110
|
+
readonly path: "/proxy_sessions/:id/payer_opened";
|
|
111
|
+
}, {
|
|
112
|
+
readonly method: "POST";
|
|
113
|
+
readonly operation: "sessions.providerBindings.create";
|
|
114
|
+
readonly path: "/proxy_sessions/:id/provider_bindings";
|
|
115
|
+
}];
|
|
116
|
+
export declare class ProxySessionsResource {
|
|
117
|
+
private readonly httpClient;
|
|
118
|
+
private readonly options;
|
|
119
|
+
readonly cart: ProxySessionCartResource;
|
|
120
|
+
constructor(httpClient: ProxyCheckoutHttpClient, options?: {
|
|
121
|
+
payHost?: string;
|
|
122
|
+
publishableKey?: string;
|
|
123
|
+
});
|
|
124
|
+
create(input: CreateProxySessionInput): Promise<ProxySession>;
|
|
125
|
+
createHandoff(input: CreateProxySessionHandoffInput): Promise<ProxySessionHandoff>;
|
|
126
|
+
retrieve(proxySessionId: string, options?: ProxyCheckoutServerRequestOptions): Promise<MerchantProxySession>;
|
|
127
|
+
/**
|
|
128
|
+
* Retrieve a session and validate its cart snapshot against a merchant schema,
|
|
129
|
+
* returning the session with a typed `cart`. Throws a structured error if the
|
|
130
|
+
* cart fails validation or its buyer reference disagrees with the session.
|
|
131
|
+
*/
|
|
132
|
+
retrieveTyped<TCart>(proxySessionId: string, cartSchema: ProxyCartValidator<TCart>, options?: ProxyCheckoutServerRequestOptions & ProxyCartParseOptions<TCart>): Promise<TypedMerchantProxySession<TCart>>;
|
|
133
|
+
/**
|
|
134
|
+
* Validate the cart snapshot of an already-retrieved session against a merchant
|
|
135
|
+
* schema. When `getBuyerReference` is supplied, the cart buyer reference is
|
|
136
|
+
* asserted to match the session buyer reference.
|
|
137
|
+
*/
|
|
138
|
+
parseCart<TCart>(session: MerchantProxySession, cartSchema: ProxyCartValidator<TCart>, options?: ProxyCartParseOptions<TCart>): TCart;
|
|
139
|
+
payerHandoff(proxySessionId: string, options?: ProxyCheckoutServerRequestOptions): Promise<PayerHandoffResult>;
|
|
140
|
+
payerOpened(proxySessionId: string, options?: ProxyCheckoutServerRequestOptions): Promise<PayerOpenedResult>;
|
|
141
|
+
/**
|
|
142
|
+
* Bind a provider (PSP) checkout object to a Proxy session so later cart sync
|
|
143
|
+
* can verify ownership. Idempotent for the same provider object; conflicts when
|
|
144
|
+
* the session is already bound to a different one.
|
|
145
|
+
*/
|
|
146
|
+
recordProviderBinding(proxySessionId: string, input: RecordProviderBindingInput): Promise<ProxySessionProviderBinding>;
|
|
147
|
+
}
|
|
148
|
+
export declare class ProxySessionCartResource {
|
|
149
|
+
private readonly httpClient;
|
|
150
|
+
constructor(httpClient: ProxyCheckoutHttpClient);
|
|
151
|
+
set(proxySessionId: string, input: SetProxySessionCartInput): Promise<ProxySessionCartResult>;
|
|
152
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { type ProxyCartParseOptions, type ProxyCartValidator } from "./cart.js";
|
|
2
|
+
import type { ProxyCheckoutHttpClient } from "./http-client.js";
|
|
3
|
+
import type { JsonObject, ProxyCheckoutServerRequestOptions } from "./types.js";
|
|
4
|
+
export interface CreateProxySessionOptions extends ProxyCheckoutServerRequestOptions {
|
|
5
|
+
readonly idempotencyKey?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CreateProxySessionInput extends CreateProxySessionOptions {
|
|
8
|
+
readonly amountMinor: number;
|
|
9
|
+
readonly buyerReference: string;
|
|
10
|
+
readonly cartSnapshot: JsonObject;
|
|
11
|
+
readonly currency: string;
|
|
12
|
+
readonly expiresAt?: Date | string;
|
|
13
|
+
readonly integrationMode?: "elements";
|
|
14
|
+
readonly metadata?: JsonObject;
|
|
15
|
+
readonly payerContact?: {
|
|
16
|
+
readonly email?: string;
|
|
17
|
+
readonly phone?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface CreateProxySessionHandoffInput extends CreateProxySessionInput {
|
|
21
|
+
readonly payHost?: string;
|
|
22
|
+
readonly publishableKey?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ProxySession {
|
|
25
|
+
readonly expiresAt: string;
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly integrationMode: string;
|
|
28
|
+
readonly status: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ProxySessionHandoff extends ProxySession {
|
|
31
|
+
readonly handoffUrl: string;
|
|
32
|
+
readonly status: "payer_handoff_pending" | "payer_opened";
|
|
33
|
+
}
|
|
34
|
+
export interface MerchantProxySession {
|
|
35
|
+
readonly amountMinor: number;
|
|
36
|
+
readonly buyerReference: string;
|
|
37
|
+
readonly cartSnapshot: JsonObject;
|
|
38
|
+
readonly cartVersion: number;
|
|
39
|
+
readonly createdAt: string;
|
|
40
|
+
readonly currency: string;
|
|
41
|
+
readonly expiresAt: string;
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly idempotencyKey: string | null;
|
|
44
|
+
readonly integrationMode: string;
|
|
45
|
+
readonly metadata: JsonObject;
|
|
46
|
+
readonly payerContact: {
|
|
47
|
+
readonly email: string | null;
|
|
48
|
+
readonly phone: string | null;
|
|
49
|
+
} | null;
|
|
50
|
+
readonly providerCheckoutSessionId: string | null;
|
|
51
|
+
readonly providerCheckoutSessionPsp: string | null;
|
|
52
|
+
readonly status: string;
|
|
53
|
+
readonly updatedAt: string;
|
|
54
|
+
}
|
|
55
|
+
export interface PayerOpenedResult extends MerchantProxySession {
|
|
56
|
+
readonly status: "payer_opened";
|
|
57
|
+
}
|
|
58
|
+
/** A merchant session with its cart snapshot validated against a merchant schema. */
|
|
59
|
+
export interface TypedMerchantProxySession<TCart> extends MerchantProxySession {
|
|
60
|
+
readonly cart: TCart;
|
|
61
|
+
}
|
|
62
|
+
export interface PayerHandoffResult {
|
|
63
|
+
readonly status: "payer_handoff_pending" | "payer_opened";
|
|
64
|
+
}
|
|
65
|
+
export interface SetProxySessionCartInput extends ProxyCheckoutServerRequestOptions {
|
|
66
|
+
readonly amountMinor: number;
|
|
67
|
+
readonly cartSnapshot: JsonObject;
|
|
68
|
+
readonly currency: string;
|
|
69
|
+
readonly expectedCartVersion: number;
|
|
70
|
+
}
|
|
71
|
+
export interface ProxySessionCartResult {
|
|
72
|
+
readonly amountMinor: number;
|
|
73
|
+
readonly cartSnapshot: JsonObject;
|
|
74
|
+
readonly cartVersion: number;
|
|
75
|
+
readonly currency: string;
|
|
76
|
+
}
|
|
77
|
+
export interface RecordProviderBindingInput extends ProxyCheckoutServerRequestOptions {
|
|
78
|
+
readonly providerCheckoutSessionId: string;
|
|
79
|
+
readonly psp: string;
|
|
80
|
+
}
|
|
81
|
+
export interface ProxySessionProviderBinding {
|
|
82
|
+
readonly providerCheckoutSessionId: string;
|
|
83
|
+
readonly proxySessionId: string;
|
|
84
|
+
readonly psp: string;
|
|
85
|
+
readonly updatedAt: string;
|
|
86
|
+
}
|
|
87
|
+
export declare const proxyCheckoutServerEndpoints: readonly [{
|
|
88
|
+
readonly method: "POST";
|
|
89
|
+
readonly operation: "sessions.create";
|
|
90
|
+
readonly path: "/proxy_sessions";
|
|
91
|
+
}, {
|
|
92
|
+
readonly method: "POST";
|
|
93
|
+
readonly operation: "sessions.createHandoff";
|
|
94
|
+
readonly path: "/proxy_sessions/handoff";
|
|
95
|
+
}, {
|
|
96
|
+
readonly method: "GET";
|
|
97
|
+
readonly operation: "sessions.retrieve";
|
|
98
|
+
readonly path: "/proxy_sessions/:id/merchant";
|
|
99
|
+
}, {
|
|
100
|
+
readonly method: "PUT";
|
|
101
|
+
readonly operation: "sessions.cart.set";
|
|
102
|
+
readonly path: "/proxy_sessions/:id/cart";
|
|
103
|
+
}, {
|
|
104
|
+
readonly method: "POST";
|
|
105
|
+
readonly operation: "sessions.payerHandoff";
|
|
106
|
+
readonly path: "/proxy_sessions/:id/payer_handoff";
|
|
107
|
+
}, {
|
|
108
|
+
readonly method: "POST";
|
|
109
|
+
readonly operation: "sessions.payerOpened";
|
|
110
|
+
readonly path: "/proxy_sessions/:id/payer_opened";
|
|
111
|
+
}, {
|
|
112
|
+
readonly method: "POST";
|
|
113
|
+
readonly operation: "sessions.providerBindings.create";
|
|
114
|
+
readonly path: "/proxy_sessions/:id/provider_bindings";
|
|
115
|
+
}];
|
|
116
|
+
export declare class ProxySessionsResource {
|
|
117
|
+
private readonly httpClient;
|
|
118
|
+
private readonly options;
|
|
119
|
+
readonly cart: ProxySessionCartResource;
|
|
120
|
+
constructor(httpClient: ProxyCheckoutHttpClient, options?: {
|
|
121
|
+
payHost?: string;
|
|
122
|
+
publishableKey?: string;
|
|
123
|
+
});
|
|
124
|
+
create(input: CreateProxySessionInput): Promise<ProxySession>;
|
|
125
|
+
createHandoff(input: CreateProxySessionHandoffInput): Promise<ProxySessionHandoff>;
|
|
126
|
+
retrieve(proxySessionId: string, options?: ProxyCheckoutServerRequestOptions): Promise<MerchantProxySession>;
|
|
127
|
+
/**
|
|
128
|
+
* Retrieve a session and validate its cart snapshot against a merchant schema,
|
|
129
|
+
* returning the session with a typed `cart`. Throws a structured error if the
|
|
130
|
+
* cart fails validation or its buyer reference disagrees with the session.
|
|
131
|
+
*/
|
|
132
|
+
retrieveTyped<TCart>(proxySessionId: string, cartSchema: ProxyCartValidator<TCart>, options?: ProxyCheckoutServerRequestOptions & ProxyCartParseOptions<TCart>): Promise<TypedMerchantProxySession<TCart>>;
|
|
133
|
+
/**
|
|
134
|
+
* Validate the cart snapshot of an already-retrieved session against a merchant
|
|
135
|
+
* schema. When `getBuyerReference` is supplied, the cart buyer reference is
|
|
136
|
+
* asserted to match the session buyer reference.
|
|
137
|
+
*/
|
|
138
|
+
parseCart<TCart>(session: MerchantProxySession, cartSchema: ProxyCartValidator<TCart>, options?: ProxyCartParseOptions<TCart>): TCart;
|
|
139
|
+
payerHandoff(proxySessionId: string, options?: ProxyCheckoutServerRequestOptions): Promise<PayerHandoffResult>;
|
|
140
|
+
payerOpened(proxySessionId: string, options?: ProxyCheckoutServerRequestOptions): Promise<PayerOpenedResult>;
|
|
141
|
+
/**
|
|
142
|
+
* Bind a provider (PSP) checkout object to a Proxy session so later cart sync
|
|
143
|
+
* can verify ownership. Idempotent for the same provider object; conflicts when
|
|
144
|
+
* the session is already bound to a different one.
|
|
145
|
+
*/
|
|
146
|
+
recordProviderBinding(proxySessionId: string, input: RecordProviderBindingInput): Promise<ProxySessionProviderBinding>;
|
|
147
|
+
}
|
|
148
|
+
export declare class ProxySessionCartResource {
|
|
149
|
+
private readonly httpClient;
|
|
150
|
+
constructor(httpClient: ProxyCheckoutHttpClient);
|
|
151
|
+
set(proxySessionId: string, input: SetProxySessionCartInput): Promise<ProxySessionCartResult>;
|
|
152
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ProxyCartParseOptions, ProxyCartValidator } from "./cart.js";
|
|
2
|
+
import type { ProxyCheckoutHttpClient } from "./http-client.js";
|
|
3
|
+
import type { MerchantProxySession, ProxySessionsResource, TypedMerchantProxySession } from "./sessions.js";
|
|
4
|
+
import type { ProxyCheckoutServerRequestOptions } from "./types.js";
|
|
5
|
+
export interface MerchantProxySubscription {
|
|
6
|
+
readonly buyerReference: string;
|
|
7
|
+
readonly cancelAtPeriodEnd: boolean;
|
|
8
|
+
readonly createdAt: string;
|
|
9
|
+
readonly currentPeriodEnd: string | null;
|
|
10
|
+
readonly currentPeriodStart: string | null;
|
|
11
|
+
readonly endedAt: string | null;
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly latestInvoiceAmountMinor: number | null;
|
|
14
|
+
readonly latestInvoiceCurrency: string | null;
|
|
15
|
+
readonly latestInvoiceId: string | null;
|
|
16
|
+
readonly latestPaymentStatus: string | null;
|
|
17
|
+
readonly originalProxySessionId: string;
|
|
18
|
+
readonly providerCheckoutSessionId: string | null;
|
|
19
|
+
readonly providerSubscriptionId: string;
|
|
20
|
+
readonly psp: string;
|
|
21
|
+
readonly status: string;
|
|
22
|
+
readonly trialEnd: string | null;
|
|
23
|
+
readonly updatedAt: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const proxyCheckoutSubscriptionEndpoints: readonly [{
|
|
26
|
+
readonly method: "GET";
|
|
27
|
+
readonly operation: "subscriptions.retrieve";
|
|
28
|
+
readonly path: "/subscriptions/:id";
|
|
29
|
+
}];
|
|
30
|
+
/** A subscription paired with its verified original session (and optional typed cart). */
|
|
31
|
+
export interface ProxySubscriptionWithSession<TCart> {
|
|
32
|
+
readonly cart: TCart;
|
|
33
|
+
readonly session: TypedMerchantProxySession<TCart>;
|
|
34
|
+
readonly subscription: MerchantProxySubscription;
|
|
35
|
+
}
|
|
36
|
+
export interface ProxySubscriptionWithUntypedSession {
|
|
37
|
+
readonly session: MerchantProxySession;
|
|
38
|
+
readonly subscription: MerchantProxySubscription;
|
|
39
|
+
}
|
|
40
|
+
export declare class ProxySubscriptionsResource {
|
|
41
|
+
private readonly httpClient;
|
|
42
|
+
private readonly sessions;
|
|
43
|
+
constructor(httpClient: ProxyCheckoutHttpClient, sessions: ProxySessionsResource);
|
|
44
|
+
retrieve(subscriptionId: string, options?: ProxyCheckoutServerRequestOptions): Promise<MerchantProxySubscription>;
|
|
45
|
+
/**
|
|
46
|
+
* Retrieve a subscription together with the original Proxy session it was
|
|
47
|
+
* created from, asserting buyer/session linkage. When `cartSchema` is given the
|
|
48
|
+
* session cart is validated and returned typed.
|
|
49
|
+
*/
|
|
50
|
+
retrieveWithOriginalSession(subscriptionId: string, options?: ProxyCheckoutServerRequestOptions): Promise<ProxySubscriptionWithUntypedSession>;
|
|
51
|
+
retrieveWithOriginalSession<TCart>(subscriptionId: string, options: ProxyCheckoutServerRequestOptions & ProxyCartParseOptions<TCart> & {
|
|
52
|
+
cartSchema: ProxyCartValidator<TCart>;
|
|
53
|
+
}): Promise<ProxySubscriptionWithSession<TCart>>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ProxyCartParseOptions, ProxyCartValidator } from "./cart.js";
|
|
2
|
+
import type { ProxyCheckoutHttpClient } from "./http-client.js";
|
|
3
|
+
import type { MerchantProxySession, ProxySessionsResource, TypedMerchantProxySession } from "./sessions.js";
|
|
4
|
+
import type { ProxyCheckoutServerRequestOptions } from "./types.js";
|
|
5
|
+
export interface MerchantProxySubscription {
|
|
6
|
+
readonly buyerReference: string;
|
|
7
|
+
readonly cancelAtPeriodEnd: boolean;
|
|
8
|
+
readonly createdAt: string;
|
|
9
|
+
readonly currentPeriodEnd: string | null;
|
|
10
|
+
readonly currentPeriodStart: string | null;
|
|
11
|
+
readonly endedAt: string | null;
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly latestInvoiceAmountMinor: number | null;
|
|
14
|
+
readonly latestInvoiceCurrency: string | null;
|
|
15
|
+
readonly latestInvoiceId: string | null;
|
|
16
|
+
readonly latestPaymentStatus: string | null;
|
|
17
|
+
readonly originalProxySessionId: string;
|
|
18
|
+
readonly providerCheckoutSessionId: string | null;
|
|
19
|
+
readonly providerSubscriptionId: string;
|
|
20
|
+
readonly psp: string;
|
|
21
|
+
readonly status: string;
|
|
22
|
+
readonly trialEnd: string | null;
|
|
23
|
+
readonly updatedAt: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const proxyCheckoutSubscriptionEndpoints: readonly [{
|
|
26
|
+
readonly method: "GET";
|
|
27
|
+
readonly operation: "subscriptions.retrieve";
|
|
28
|
+
readonly path: "/subscriptions/:id";
|
|
29
|
+
}];
|
|
30
|
+
/** A subscription paired with its verified original session (and optional typed cart). */
|
|
31
|
+
export interface ProxySubscriptionWithSession<TCart> {
|
|
32
|
+
readonly cart: TCart;
|
|
33
|
+
readonly session: TypedMerchantProxySession<TCart>;
|
|
34
|
+
readonly subscription: MerchantProxySubscription;
|
|
35
|
+
}
|
|
36
|
+
export interface ProxySubscriptionWithUntypedSession {
|
|
37
|
+
readonly session: MerchantProxySession;
|
|
38
|
+
readonly subscription: MerchantProxySubscription;
|
|
39
|
+
}
|
|
40
|
+
export declare class ProxySubscriptionsResource {
|
|
41
|
+
private readonly httpClient;
|
|
42
|
+
private readonly sessions;
|
|
43
|
+
constructor(httpClient: ProxyCheckoutHttpClient, sessions: ProxySessionsResource);
|
|
44
|
+
retrieve(subscriptionId: string, options?: ProxyCheckoutServerRequestOptions): Promise<MerchantProxySubscription>;
|
|
45
|
+
/**
|
|
46
|
+
* Retrieve a subscription together with the original Proxy session it was
|
|
47
|
+
* created from, asserting buyer/session linkage. When `cartSchema` is given the
|
|
48
|
+
* session cart is validated and returned typed.
|
|
49
|
+
*/
|
|
50
|
+
retrieveWithOriginalSession(subscriptionId: string, options?: ProxyCheckoutServerRequestOptions): Promise<ProxySubscriptionWithUntypedSession>;
|
|
51
|
+
retrieveWithOriginalSession<TCart>(subscriptionId: string, options: ProxyCheckoutServerRequestOptions & ProxyCartParseOptions<TCart> & {
|
|
52
|
+
cartSchema: ProxyCartValidator<TCart>;
|
|
53
|
+
}): Promise<ProxySubscriptionWithSession<TCart>>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type JsonPrimitive = boolean | null | number | string;
|
|
2
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
3
|
+
export interface JsonObject {
|
|
4
|
+
readonly [key: string]: JsonValue;
|
|
5
|
+
}
|
|
6
|
+
export type ProxyCheckoutFetch = (input: Request | URL | string, init?: RequestInit) => Promise<Response>;
|
|
7
|
+
export interface ProxyCheckoutServerClientOptions {
|
|
8
|
+
readonly apiHost?: string;
|
|
9
|
+
readonly apiKey: string;
|
|
10
|
+
readonly fetch?: ProxyCheckoutFetch;
|
|
11
|
+
readonly payHost?: string;
|
|
12
|
+
readonly publishableKey?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ProxyCheckoutServerRequestOptions {
|
|
15
|
+
readonly requestId?: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type JsonPrimitive = boolean | null | number | string;
|
|
2
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
3
|
+
export interface JsonObject {
|
|
4
|
+
readonly [key: string]: JsonValue;
|
|
5
|
+
}
|
|
6
|
+
export type ProxyCheckoutFetch = (input: Request | URL | string, init?: RequestInit) => Promise<Response>;
|
|
7
|
+
export interface ProxyCheckoutServerClientOptions {
|
|
8
|
+
readonly apiHost?: string;
|
|
9
|
+
readonly apiKey: string;
|
|
10
|
+
readonly fetch?: ProxyCheckoutFetch;
|
|
11
|
+
readonly payHost?: string;
|
|
12
|
+
readonly publishableKey?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ProxyCheckoutServerRequestOptions {
|
|
15
|
+
readonly requestId?: string;
|
|
16
|
+
}
|
package/dist/cjs/version.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.proxyCheckoutServerSdkUserAgent = exports.proxyCheckoutServerSdkVersion = exports.proxyCheckoutServerSdkName = void 0;
|
|
4
4
|
exports.proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
|
|
5
|
-
exports.proxyCheckoutServerSdkVersion = "0.0.4-pr-76.
|
|
5
|
+
exports.proxyCheckoutServerSdkVersion = "0.0.4-pr-76.32.1";
|
|
6
6
|
exports.proxyCheckoutServerSdkUserAgent = `${exports.proxyCheckoutServerSdkName}/${exports.proxyCheckoutServerSdkVersion}`;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical outbound Proxy webhook event types and predicates.
|
|
3
|
+
*
|
|
4
|
+
* These mirror the event types the Proxy API can deliver to merchant webhook
|
|
5
|
+
* endpoints. Use the predicates instead of comparing raw strings so customer
|
|
6
|
+
* integration code does not encode the event taxonomy by hand.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PROXY_WEBHOOK_EVENT_TYPES: {
|
|
9
|
+
readonly paymentAttemptCancelled: "payment_attempt.cancelled";
|
|
10
|
+
readonly paymentAttemptDisputed: "payment_attempt.disputed";
|
|
11
|
+
readonly paymentAttemptDisputeLost: "payment_attempt.dispute_lost";
|
|
12
|
+
readonly paymentAttemptDisputeWon: "payment_attempt.dispute_won";
|
|
13
|
+
readonly paymentAttemptFailed: "payment_attempt.failed";
|
|
14
|
+
readonly paymentAttemptPartiallyRefunded: "payment_attempt.partially_refunded";
|
|
15
|
+
readonly paymentAttemptRefunded: "payment_attempt.refunded";
|
|
16
|
+
readonly paymentAttemptSucceeded: "payment_attempt.succeeded";
|
|
17
|
+
readonly sessionCancelled: "proxy_session.cancelled";
|
|
18
|
+
readonly sessionExpired: "proxy_session.expired";
|
|
19
|
+
readonly sessionFailed: "proxy_session.failed";
|
|
20
|
+
readonly sessionMerchantActionRequired: "proxy_session.merchant_action_required";
|
|
21
|
+
readonly sessionPaid: "proxy_session.paid";
|
|
22
|
+
readonly sessionProvisionable: "proxy_session.provisionable";
|
|
23
|
+
readonly subscriptionCancelled: "subscription.cancelled";
|
|
24
|
+
readonly subscriptionCancelScheduled: "subscription.cancel_scheduled";
|
|
25
|
+
readonly subscriptionPaymentFailed: "subscription.payment_failed";
|
|
26
|
+
readonly subscriptionRenewed: "subscription.renewed";
|
|
27
|
+
};
|
|
28
|
+
export type ProxyWebhookEventType = (typeof PROXY_WEBHOOK_EVENT_TYPES)[keyof typeof PROXY_WEBHOOK_EVENT_TYPES];
|
|
29
|
+
/** True for `proxy_session.*` events. */
|
|
30
|
+
export declare function isProxySessionEvent(eventType: string): boolean;
|
|
31
|
+
/** True for `subscription.*` events. */
|
|
32
|
+
export declare function isProxySubscriptionEvent(eventType: string): boolean;
|
|
33
|
+
/** True for `payment_attempt.*` events. */
|
|
34
|
+
export declare function isProxyPaymentAttemptEvent(eventType: string): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical outbound Proxy webhook event types and predicates.
|
|
3
|
+
*
|
|
4
|
+
* These mirror the event types the Proxy API can deliver to merchant webhook
|
|
5
|
+
* endpoints. Use the predicates instead of comparing raw strings so customer
|
|
6
|
+
* integration code does not encode the event taxonomy by hand.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PROXY_WEBHOOK_EVENT_TYPES: {
|
|
9
|
+
readonly paymentAttemptCancelled: "payment_attempt.cancelled";
|
|
10
|
+
readonly paymentAttemptDisputed: "payment_attempt.disputed";
|
|
11
|
+
readonly paymentAttemptDisputeLost: "payment_attempt.dispute_lost";
|
|
12
|
+
readonly paymentAttemptDisputeWon: "payment_attempt.dispute_won";
|
|
13
|
+
readonly paymentAttemptFailed: "payment_attempt.failed";
|
|
14
|
+
readonly paymentAttemptPartiallyRefunded: "payment_attempt.partially_refunded";
|
|
15
|
+
readonly paymentAttemptRefunded: "payment_attempt.refunded";
|
|
16
|
+
readonly paymentAttemptSucceeded: "payment_attempt.succeeded";
|
|
17
|
+
readonly sessionCancelled: "proxy_session.cancelled";
|
|
18
|
+
readonly sessionExpired: "proxy_session.expired";
|
|
19
|
+
readonly sessionFailed: "proxy_session.failed";
|
|
20
|
+
readonly sessionMerchantActionRequired: "proxy_session.merchant_action_required";
|
|
21
|
+
readonly sessionPaid: "proxy_session.paid";
|
|
22
|
+
readonly sessionProvisionable: "proxy_session.provisionable";
|
|
23
|
+
readonly subscriptionCancelled: "subscription.cancelled";
|
|
24
|
+
readonly subscriptionCancelScheduled: "subscription.cancel_scheduled";
|
|
25
|
+
readonly subscriptionPaymentFailed: "subscription.payment_failed";
|
|
26
|
+
readonly subscriptionRenewed: "subscription.renewed";
|
|
27
|
+
};
|
|
28
|
+
export type ProxyWebhookEventType = (typeof PROXY_WEBHOOK_EVENT_TYPES)[keyof typeof PROXY_WEBHOOK_EVENT_TYPES];
|
|
29
|
+
/** True for `proxy_session.*` events. */
|
|
30
|
+
export declare function isProxySessionEvent(eventType: string): boolean;
|
|
31
|
+
/** True for `subscription.*` events. */
|
|
32
|
+
export declare function isProxySubscriptionEvent(eventType: string): boolean;
|
|
33
|
+
/** True for `payment_attempt.*` events. */
|
|
34
|
+
export declare function isProxyPaymentAttemptEvent(eventType: string): boolean;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server SDK webhook delivery handler.
|
|
3
|
+
*
|
|
4
|
+
* `handle` turns a verified Proxy webhook into a current-state lifecycle
|
|
5
|
+
* decision and runs the merchant's entitlement callback, with optional
|
|
6
|
+
* idempotency via a pluggable {@link ProxyWebhookStore}. It owns signature
|
|
7
|
+
* verification, duplicate/in-flight handling, retryable responses, and
|
|
8
|
+
* current-state retrieval so customer webhook routes stay tiny.
|
|
9
|
+
*/
|
|
10
|
+
import type { ProxyEventsResource, ResolvedProxyEvent, ResolvedProxyEventKind } from "./events.js";
|
|
11
|
+
import { type ProxyWebhookEvent } from "./webhooks.js";
|
|
12
|
+
/** Seconds advertised in `Retry-After` when an event is already in flight. */
|
|
13
|
+
export declare const PROXY_WEBHOOK_RETRY_AFTER_SECONDS = 30;
|
|
14
|
+
export type ProxyWebhookClaimResult = "claimed" | "duplicate" | "processing";
|
|
15
|
+
export type ProxyWebhookOutcome = "duplicate" | "ignored" | "processed" | "processing";
|
|
16
|
+
/** Compact, lifecycle-free audit record handed to a {@link ProxyWebhookStore}. */
|
|
17
|
+
export interface ProxyWebhookProcessRecord {
|
|
18
|
+
readonly kind: ResolvedProxyEventKind;
|
|
19
|
+
readonly paymentAttemptId?: string | null;
|
|
20
|
+
readonly sessionId: string | null;
|
|
21
|
+
readonly subscriptionId: string | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Optional merchant-owned idempotency/audit store. The handler treats already
|
|
25
|
+
* processed events as success and concurrently in-flight events as retryable;
|
|
26
|
+
* it never classifies lifecycle itself.
|
|
27
|
+
*/
|
|
28
|
+
export interface ProxyWebhookStore {
|
|
29
|
+
/** Atomically claim an event id. Return "duplicate" if already processed, "processing" if in flight. */
|
|
30
|
+
claim(event: ProxyWebhookEvent): Promise<ProxyWebhookClaimResult> | ProxyWebhookClaimResult;
|
|
31
|
+
/** Mark a claimed event failed so it can be retried/reclaimed. */
|
|
32
|
+
markFailed(eventId: string, error: unknown): Promise<void> | void;
|
|
33
|
+
/** Mark a claimed event processed (idempotency commit). */
|
|
34
|
+
markProcessed(eventId: string, record: ProxyWebhookProcessRecord): Promise<void> | void;
|
|
35
|
+
}
|
|
36
|
+
export interface ProxyWebhookPayloadInput {
|
|
37
|
+
readonly body: Buffer | string;
|
|
38
|
+
readonly signature?: string | null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A web `Request` (Next.js route handlers, Hono on Node) or an explicit
|
|
42
|
+
* body/signature pair (Express/Node). Signature verification uses `node:crypto`,
|
|
43
|
+
* so this targets Node-compatible runtimes — not Cloudflare Workers.
|
|
44
|
+
*/
|
|
45
|
+
export type ProxyWebhookRequestInput = ProxyWebhookPayloadInput | Request;
|
|
46
|
+
export interface ProxyWebhookHandlerOptions {
|
|
47
|
+
/** Merchant entitlement callback, invoked once per claimed event after current-state resolution. */
|
|
48
|
+
readonly onResolved: (resolved: ResolvedProxyEvent) => Promise<void> | void;
|
|
49
|
+
/** Optional request id forwarded to the current-state retrieval calls. */
|
|
50
|
+
readonly requestId?: string;
|
|
51
|
+
/** Endpoint signing secret. */
|
|
52
|
+
readonly secret: string;
|
|
53
|
+
/** Optional idempotency/audit store. Omit for at-least-once delivery with idempotent fulfillment. */
|
|
54
|
+
readonly store?: ProxyWebhookStore;
|
|
55
|
+
/** Signature timestamp tolerance in seconds (default 300). */
|
|
56
|
+
readonly toleranceSeconds?: number;
|
|
57
|
+
}
|
|
58
|
+
export interface ProxyWebhookProcessResult {
|
|
59
|
+
readonly event: ProxyWebhookEvent;
|
|
60
|
+
readonly outcome: ProxyWebhookOutcome;
|
|
61
|
+
readonly resolved: ResolvedProxyEvent | null;
|
|
62
|
+
readonly retryable: boolean;
|
|
63
|
+
readonly statusCode: number;
|
|
64
|
+
}
|
|
65
|
+
export declare class ProxyWebhooksResource {
|
|
66
|
+
private readonly events;
|
|
67
|
+
constructor(events: ProxyEventsResource);
|
|
68
|
+
/** Low-level: verify + construct the event without resolving lifecycle. */
|
|
69
|
+
constructEvent(input: {
|
|
70
|
+
body: Buffer | string;
|
|
71
|
+
header: string | null | undefined;
|
|
72
|
+
secret: string;
|
|
73
|
+
toleranceSeconds?: number;
|
|
74
|
+
}): ProxyWebhookEvent;
|
|
75
|
+
/**
|
|
76
|
+
* Framework-agnostic processing. Verifies the signature, applies the store,
|
|
77
|
+
* resolves current state, runs `onResolved`, and returns response metadata.
|
|
78
|
+
* Throws {@link ProxyWebhookSignatureVerificationError} on a bad signature so
|
|
79
|
+
* non-Response frameworks (Express) can map it to 400.
|
|
80
|
+
*/
|
|
81
|
+
process(input: ProxyWebhookRequestInput, options: ProxyWebhookHandlerOptions): Promise<ProxyWebhookProcessResult>;
|
|
82
|
+
/**
|
|
83
|
+
* Turnkey handler for web `Request` frameworks. Returns a `Response` with the
|
|
84
|
+
* right status (200 success/duplicate, 409 + `Retry-After` in flight, 400 on
|
|
85
|
+
* bad signature). Re-throws merchant `onResolved` errors so the platform can
|
|
86
|
+
* surface a 500 and Proxy retries.
|
|
87
|
+
*/
|
|
88
|
+
handle(input: ProxyWebhookRequestInput, options: ProxyWebhookHandlerOptions): Promise<Response>;
|
|
89
|
+
}
|