@proxy-checkout/server-js 0.0.5 → 0.0.6
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/client.js +1 -1
- package/dist/cjs/errors.d.cts +1 -1
- package/dist/cjs/errors.d.ts +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/sessions.d.cts +24 -0
- package/dist/cjs/sessions.d.ts +24 -0
- package/dist/cjs/sessions.js +37 -0
- package/dist/cjs/version.d.cts +2 -2
- package/dist/cjs/version.d.ts +2 -2
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/webhook-handler.d.cts +16 -1
- package/dist/cjs/webhook-handler.d.ts +16 -1
- package/dist/cjs/webhook-handler.js +40 -2
- package/dist/esm/client.js +1 -1
- package/dist/esm/errors.d.ts +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/sessions.d.ts +24 -0
- package/dist/esm/sessions.js +37 -0
- package/dist/esm/version.d.ts +2 -2
- package/dist/esm/version.js +1 -1
- package/dist/esm/webhook-handler.d.ts +16 -1
- package/dist/esm/webhook-handler.js +40 -2
- package/package.json +1 -1
package/dist/cjs/client.js
CHANGED
|
@@ -31,7 +31,7 @@ class ProxyCheckoutServerClient {
|
|
|
31
31
|
});
|
|
32
32
|
this.subscriptions = new subscriptions_js_1.ProxySubscriptionsResource(httpClient, this.sessions);
|
|
33
33
|
this.events = new events_js_1.ProxyEventsResource(this.sessions, this.subscriptions);
|
|
34
|
-
this.webhooks = new webhook_handler_js_1.ProxyWebhooksResource(this.events);
|
|
34
|
+
this.webhooks = new webhook_handler_js_1.ProxyWebhooksResource(this.events, this.sessions);
|
|
35
35
|
this.webhookEndpoints = new webhooks_js_1.ProxyWebhookEndpointsResource(httpClient);
|
|
36
36
|
}
|
|
37
37
|
}
|
package/dist/cjs/errors.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ export interface ProxyCheckoutApiErrorDetails {
|
|
|
4
4
|
readonly responseBody: unknown;
|
|
5
5
|
readonly statusCode: number;
|
|
6
6
|
}
|
|
7
|
-
export type ProxyCheckoutValidationCode = "buyer_reference_mismatch" | "cart_invalid" | "invalid_date" | "provider_binding_mismatch" | "subscription_session_mismatch";
|
|
7
|
+
export type ProxyCheckoutValidationCode = "buyer_reference_mismatch" | "cart_invalid" | "invalid_date" | "provider_binding_mismatch" | "subscription_session_mismatch" | "webhook_sessions_resource_missing";
|
|
8
8
|
/**
|
|
9
9
|
* Raised when the SDK receives Proxy data it cannot safely normalize, for
|
|
10
10
|
* example an invalid date string, a cart snapshot that fails the merchant
|
package/dist/cjs/errors.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface ProxyCheckoutApiErrorDetails {
|
|
|
4
4
|
readonly responseBody: unknown;
|
|
5
5
|
readonly statusCode: number;
|
|
6
6
|
}
|
|
7
|
-
export type ProxyCheckoutValidationCode = "buyer_reference_mismatch" | "cart_invalid" | "invalid_date" | "provider_binding_mismatch" | "subscription_session_mismatch";
|
|
7
|
+
export type ProxyCheckoutValidationCode = "buyer_reference_mismatch" | "cart_invalid" | "invalid_date" | "provider_binding_mismatch" | "subscription_session_mismatch" | "webhook_sessions_resource_missing";
|
|
8
8
|
/**
|
|
9
9
|
* Raised when the SDK receives Proxy data it cannot safely normalize, for
|
|
10
10
|
* example an invalid date string, a cart snapshot that fails the merchant
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -4,10 +4,10 @@ export { assertCartBuyerReference, assertSubscriptionMatchesSession, } from "./c
|
|
|
4
4
|
export { ProxyCheckoutApiError, type ProxyCheckoutApiErrorDetails, type ProxyCheckoutValidationCode, ProxyCheckoutValidationError, } from "./errors.js";
|
|
5
5
|
export { ProxyEventsResource, type ResolvedIgnored, type ResolvedInitialProvision, type ResolvedPaymentAttempt, type ResolvedPaymentRisk, type ResolvedProxyEvent, type ResolvedProxyEventKind, type ResolvedSubscriptionCancelled, type ResolvedSubscriptionCancelScheduled, type ResolvedSubscriptionRenewed, type ResolvedTerminalSession, type ResolveProxyEventOptions, } from "./events.js";
|
|
6
6
|
export { AT_RISK_SUBSCRIPTION_STATUSES, ENDED_SUBSCRIPTION_STATUSES, isSessionProvisionable, isSessionTerminal, isSubscriptionEnded, isSubscriptionPaymentAtRisk, PROVISIONABLE_SESSION_STATUSES, parseOptionalProxyDate, requireProxyDate, subscriptionAccessEndsAt, subscriptionWillRenew, TERMINAL_SESSION_STATUSES, } from "./lifecycle.js";
|
|
7
|
-
export { type CreateProxySessionHandoffInput, type CreateProxySessionInput, type CreateProxySessionOptions, type MerchantProxySession, type PayerHandoffResult, type PayerOpenedResult, type ProxySession, ProxySessionCartResource, type ProxySessionCartResult, type ProxySessionHandoff, type ProxySessionProviderBinding, ProxySessionsResource, proxyCheckoutServerEndpoints, type RecordProviderBindingInput, type SetProxySessionCartInput, type TypedMerchantProxySession, } from "./sessions.js";
|
|
7
|
+
export { type CreateProxySessionHandoffInput, type CreateProxySessionInput, type CreateProxySessionOptions, type MarkProxySessionProvisionedInput, type MarkProxySessionProvisioningFailedInput, type MerchantProxySession, type PayerHandoffResult, type PayerOpenedResult, type ProxySession, ProxySessionCartResource, type ProxySessionCartResult, type ProxySessionHandoff, type ProxySessionProviderBinding, type ProxySessionProvisioningAcknowledgement, ProxySessionsResource, proxyCheckoutServerEndpoints, type RecordProviderBindingInput, type SetProxySessionCartInput, type TypedMerchantProxySession, } from "./sessions.js";
|
|
8
8
|
export { type MerchantProxySubscription, ProxySubscriptionsResource, type ProxySubscriptionWithSession, type ProxySubscriptionWithUntypedSession, proxyCheckoutSubscriptionEndpoints, } from "./subscriptions.js";
|
|
9
9
|
export type { JsonObject, JsonPrimitive, JsonValue, ProxyCheckoutFetch, ProxyCheckoutServerClientOptions, ProxyCheckoutServerRequestOptions, } from "./types.js";
|
|
10
10
|
export { proxyCheckoutServerSdkName, proxyCheckoutServerSdkUserAgent, proxyCheckoutServerSdkVersion, } from "./version.js";
|
|
11
11
|
export { isProxyPaymentAttemptEvent, isProxySessionEvent, isProxySubscriptionEvent, PROXY_WEBHOOK_EVENT_TYPES, type ProxyWebhookEventType, } from "./webhook-events.js";
|
|
12
|
-
export { PROXY_WEBHOOK_RETRY_AFTER_SECONDS, type ProxyWebhookClaimResult, type ProxyWebhookHandlerOptions, type ProxyWebhookOutcome, type ProxyWebhookPayloadInput, type ProxyWebhookProcessRecord, type ProxyWebhookProcessResult, type ProxyWebhookRequestInput, type ProxyWebhookStore, ProxyWebhooksResource, } from "./webhook-handler.js";
|
|
12
|
+
export { PROXY_WEBHOOK_RETRY_AFTER_SECONDS, type ProxyWebhookClaimResult, type ProxyWebhookHandlerOptions, type ProxyWebhookOutcome, type ProxyWebhookPayloadInput, type ProxyWebhookProcessRecord, type ProxyWebhookProcessResult, type ProxyWebhookProvisioningFailure, type ProxyWebhookRequestInput, type ProxyWebhookStore, ProxyWebhooksResource, } from "./webhook-handler.js";
|
|
13
13
|
export { type ConstructProxyWebhookEventInput, type CreateWebhookEndpointInput, constructProxyWebhookEvent, PROXY_SIGNATURE_HEADER, ProxyWebhookEndpointsResource, type ProxyWebhookEvent, ProxyWebhookSignatureVerificationError, proxyCheckoutWebhookEndpointEndpoints, type RotateWebhookEndpointSecretInput, type UpdateWebhookEndpointInput, type VerifyProxyWebhookSignatureInput, verifyProxyWebhookSignature, type WebhookEndpoint, type WebhookEndpointSecretResult, } from "./webhooks.js";
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ export { assertCartBuyerReference, assertSubscriptionMatchesSession, } from "./c
|
|
|
4
4
|
export { ProxyCheckoutApiError, type ProxyCheckoutApiErrorDetails, type ProxyCheckoutValidationCode, ProxyCheckoutValidationError, } from "./errors.js";
|
|
5
5
|
export { ProxyEventsResource, type ResolvedIgnored, type ResolvedInitialProvision, type ResolvedPaymentAttempt, type ResolvedPaymentRisk, type ResolvedProxyEvent, type ResolvedProxyEventKind, type ResolvedSubscriptionCancelled, type ResolvedSubscriptionCancelScheduled, type ResolvedSubscriptionRenewed, type ResolvedTerminalSession, type ResolveProxyEventOptions, } from "./events.js";
|
|
6
6
|
export { AT_RISK_SUBSCRIPTION_STATUSES, ENDED_SUBSCRIPTION_STATUSES, isSessionProvisionable, isSessionTerminal, isSubscriptionEnded, isSubscriptionPaymentAtRisk, PROVISIONABLE_SESSION_STATUSES, parseOptionalProxyDate, requireProxyDate, subscriptionAccessEndsAt, subscriptionWillRenew, TERMINAL_SESSION_STATUSES, } from "./lifecycle.js";
|
|
7
|
-
export { type CreateProxySessionHandoffInput, type CreateProxySessionInput, type CreateProxySessionOptions, type MerchantProxySession, type PayerHandoffResult, type PayerOpenedResult, type ProxySession, ProxySessionCartResource, type ProxySessionCartResult, type ProxySessionHandoff, type ProxySessionProviderBinding, ProxySessionsResource, proxyCheckoutServerEndpoints, type RecordProviderBindingInput, type SetProxySessionCartInput, type TypedMerchantProxySession, } from "./sessions.js";
|
|
7
|
+
export { type CreateProxySessionHandoffInput, type CreateProxySessionInput, type CreateProxySessionOptions, type MarkProxySessionProvisionedInput, type MarkProxySessionProvisioningFailedInput, type MerchantProxySession, type PayerHandoffResult, type PayerOpenedResult, type ProxySession, ProxySessionCartResource, type ProxySessionCartResult, type ProxySessionHandoff, type ProxySessionProviderBinding, type ProxySessionProvisioningAcknowledgement, ProxySessionsResource, proxyCheckoutServerEndpoints, type RecordProviderBindingInput, type SetProxySessionCartInput, type TypedMerchantProxySession, } from "./sessions.js";
|
|
8
8
|
export { type MerchantProxySubscription, ProxySubscriptionsResource, type ProxySubscriptionWithSession, type ProxySubscriptionWithUntypedSession, proxyCheckoutSubscriptionEndpoints, } from "./subscriptions.js";
|
|
9
9
|
export type { JsonObject, JsonPrimitive, JsonValue, ProxyCheckoutFetch, ProxyCheckoutServerClientOptions, ProxyCheckoutServerRequestOptions, } from "./types.js";
|
|
10
10
|
export { proxyCheckoutServerSdkName, proxyCheckoutServerSdkUserAgent, proxyCheckoutServerSdkVersion, } from "./version.js";
|
|
11
11
|
export { isProxyPaymentAttemptEvent, isProxySessionEvent, isProxySubscriptionEvent, PROXY_WEBHOOK_EVENT_TYPES, type ProxyWebhookEventType, } from "./webhook-events.js";
|
|
12
|
-
export { PROXY_WEBHOOK_RETRY_AFTER_SECONDS, type ProxyWebhookClaimResult, type ProxyWebhookHandlerOptions, type ProxyWebhookOutcome, type ProxyWebhookPayloadInput, type ProxyWebhookProcessRecord, type ProxyWebhookProcessResult, type ProxyWebhookRequestInput, type ProxyWebhookStore, ProxyWebhooksResource, } from "./webhook-handler.js";
|
|
12
|
+
export { PROXY_WEBHOOK_RETRY_AFTER_SECONDS, type ProxyWebhookClaimResult, type ProxyWebhookHandlerOptions, type ProxyWebhookOutcome, type ProxyWebhookPayloadInput, type ProxyWebhookProcessRecord, type ProxyWebhookProcessResult, type ProxyWebhookProvisioningFailure, type ProxyWebhookRequestInput, type ProxyWebhookStore, ProxyWebhooksResource, } from "./webhook-handler.js";
|
|
13
13
|
export { type ConstructProxyWebhookEventInput, type CreateWebhookEndpointInput, constructProxyWebhookEvent, PROXY_SIGNATURE_HEADER, ProxyWebhookEndpointsResource, type ProxyWebhookEvent, ProxyWebhookSignatureVerificationError, proxyCheckoutWebhookEndpointEndpoints, type RotateWebhookEndpointSecretInput, type UpdateWebhookEndpointInput, type VerifyProxyWebhookSignatureInput, verifyProxyWebhookSignature, type WebhookEndpoint, type WebhookEndpointSecretResult, } from "./webhooks.js";
|
package/dist/cjs/sessions.d.cts
CHANGED
|
@@ -86,6 +86,20 @@ export interface ProxySessionProviderBinding {
|
|
|
86
86
|
readonly psp: string;
|
|
87
87
|
readonly updatedAt: string;
|
|
88
88
|
}
|
|
89
|
+
export interface MarkProxySessionProvisionedInput extends ProxyCheckoutServerRequestOptions {
|
|
90
|
+
readonly fulfillmentReference?: string;
|
|
91
|
+
readonly metadata?: JsonObject;
|
|
92
|
+
}
|
|
93
|
+
export interface MarkProxySessionProvisioningFailedInput extends ProxyCheckoutServerRequestOptions {
|
|
94
|
+
readonly errorCode?: string;
|
|
95
|
+
readonly errorMessage: string;
|
|
96
|
+
readonly metadata?: JsonObject;
|
|
97
|
+
}
|
|
98
|
+
export interface ProxySessionProvisioningAcknowledgement {
|
|
99
|
+
readonly proxySessionId: string;
|
|
100
|
+
readonly status: "provisioned" | "provisioning_failed";
|
|
101
|
+
readonly updatedAt: string;
|
|
102
|
+
}
|
|
89
103
|
export declare const proxyCheckoutServerEndpoints: readonly [{
|
|
90
104
|
readonly method: "POST";
|
|
91
105
|
readonly operation: "sessions.create";
|
|
@@ -114,6 +128,14 @@ export declare const proxyCheckoutServerEndpoints: readonly [{
|
|
|
114
128
|
readonly method: "POST";
|
|
115
129
|
readonly operation: "sessions.providerBindings.create";
|
|
116
130
|
readonly path: "/proxy_sessions/:id/provider_bindings";
|
|
131
|
+
}, {
|
|
132
|
+
readonly method: "POST";
|
|
133
|
+
readonly operation: "sessions.markProvisioned";
|
|
134
|
+
readonly path: "/proxy_sessions/:id/provisioned";
|
|
135
|
+
}, {
|
|
136
|
+
readonly method: "POST";
|
|
137
|
+
readonly operation: "sessions.markProvisioningFailed";
|
|
138
|
+
readonly path: "/proxy_sessions/:id/provisioning_failed";
|
|
117
139
|
}];
|
|
118
140
|
export declare class ProxySessionsResource {
|
|
119
141
|
private readonly httpClient;
|
|
@@ -146,6 +168,8 @@ export declare class ProxySessionsResource {
|
|
|
146
168
|
* the session is already bound to a different one.
|
|
147
169
|
*/
|
|
148
170
|
recordProviderBinding(proxySessionId: string, input: RecordProviderBindingInput): Promise<ProxySessionProviderBinding>;
|
|
171
|
+
markProvisioned(proxySessionId: string, input?: MarkProxySessionProvisionedInput): Promise<ProxySessionProvisioningAcknowledgement>;
|
|
172
|
+
markProvisioningFailed(proxySessionId: string, input: MarkProxySessionProvisioningFailedInput): Promise<ProxySessionProvisioningAcknowledgement>;
|
|
149
173
|
}
|
|
150
174
|
export declare class ProxySessionCartResource {
|
|
151
175
|
private readonly httpClient;
|
package/dist/cjs/sessions.d.ts
CHANGED
|
@@ -86,6 +86,20 @@ export interface ProxySessionProviderBinding {
|
|
|
86
86
|
readonly psp: string;
|
|
87
87
|
readonly updatedAt: string;
|
|
88
88
|
}
|
|
89
|
+
export interface MarkProxySessionProvisionedInput extends ProxyCheckoutServerRequestOptions {
|
|
90
|
+
readonly fulfillmentReference?: string;
|
|
91
|
+
readonly metadata?: JsonObject;
|
|
92
|
+
}
|
|
93
|
+
export interface MarkProxySessionProvisioningFailedInput extends ProxyCheckoutServerRequestOptions {
|
|
94
|
+
readonly errorCode?: string;
|
|
95
|
+
readonly errorMessage: string;
|
|
96
|
+
readonly metadata?: JsonObject;
|
|
97
|
+
}
|
|
98
|
+
export interface ProxySessionProvisioningAcknowledgement {
|
|
99
|
+
readonly proxySessionId: string;
|
|
100
|
+
readonly status: "provisioned" | "provisioning_failed";
|
|
101
|
+
readonly updatedAt: string;
|
|
102
|
+
}
|
|
89
103
|
export declare const proxyCheckoutServerEndpoints: readonly [{
|
|
90
104
|
readonly method: "POST";
|
|
91
105
|
readonly operation: "sessions.create";
|
|
@@ -114,6 +128,14 @@ export declare const proxyCheckoutServerEndpoints: readonly [{
|
|
|
114
128
|
readonly method: "POST";
|
|
115
129
|
readonly operation: "sessions.providerBindings.create";
|
|
116
130
|
readonly path: "/proxy_sessions/:id/provider_bindings";
|
|
131
|
+
}, {
|
|
132
|
+
readonly method: "POST";
|
|
133
|
+
readonly operation: "sessions.markProvisioned";
|
|
134
|
+
readonly path: "/proxy_sessions/:id/provisioned";
|
|
135
|
+
}, {
|
|
136
|
+
readonly method: "POST";
|
|
137
|
+
readonly operation: "sessions.markProvisioningFailed";
|
|
138
|
+
readonly path: "/proxy_sessions/:id/provisioning_failed";
|
|
117
139
|
}];
|
|
118
140
|
export declare class ProxySessionsResource {
|
|
119
141
|
private readonly httpClient;
|
|
@@ -146,6 +168,8 @@ export declare class ProxySessionsResource {
|
|
|
146
168
|
* the session is already bound to a different one.
|
|
147
169
|
*/
|
|
148
170
|
recordProviderBinding(proxySessionId: string, input: RecordProviderBindingInput): Promise<ProxySessionProviderBinding>;
|
|
171
|
+
markProvisioned(proxySessionId: string, input?: MarkProxySessionProvisionedInput): Promise<ProxySessionProvisioningAcknowledgement>;
|
|
172
|
+
markProvisioningFailed(proxySessionId: string, input: MarkProxySessionProvisioningFailedInput): Promise<ProxySessionProvisioningAcknowledgement>;
|
|
149
173
|
}
|
|
150
174
|
export declare class ProxySessionCartResource {
|
|
151
175
|
private readonly httpClient;
|
package/dist/cjs/sessions.js
CHANGED
|
@@ -40,6 +40,16 @@ exports.proxyCheckoutServerEndpoints = [
|
|
|
40
40
|
operation: "sessions.providerBindings.create",
|
|
41
41
|
path: "/proxy_sessions/:id/provider_bindings",
|
|
42
42
|
},
|
|
43
|
+
{
|
|
44
|
+
method: "POST",
|
|
45
|
+
operation: "sessions.markProvisioned",
|
|
46
|
+
path: "/proxy_sessions/:id/provisioned",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
method: "POST",
|
|
50
|
+
operation: "sessions.markProvisioningFailed",
|
|
51
|
+
path: "/proxy_sessions/:id/provisioning_failed",
|
|
52
|
+
},
|
|
43
53
|
];
|
|
44
54
|
class ProxySessionsResource {
|
|
45
55
|
httpClient;
|
|
@@ -140,6 +150,21 @@ class ProxySessionsResource {
|
|
|
140
150
|
updatedAt: (0, response_validators_js_1.requireString)(body.updated_at, "sessions.providerBindings.create.updatedAt"),
|
|
141
151
|
};
|
|
142
152
|
}
|
|
153
|
+
async markProvisioned(proxySessionId, input = {}) {
|
|
154
|
+
const response = await this.httpClient.request("POST", `/proxy_sessions/${encodeURIComponent(proxySessionId)}/provisioned`, removeUndefinedValues({
|
|
155
|
+
fulfillment_reference: input.fulfillmentReference,
|
|
156
|
+
metadata: input.metadata,
|
|
157
|
+
}), { requestId: input.requestId });
|
|
158
|
+
return toProvisioningAcknowledgement(response, "sessions.markProvisioned");
|
|
159
|
+
}
|
|
160
|
+
async markProvisioningFailed(proxySessionId, input) {
|
|
161
|
+
const response = await this.httpClient.request("POST", `/proxy_sessions/${encodeURIComponent(proxySessionId)}/provisioning_failed`, removeUndefinedValues({
|
|
162
|
+
error_code: input.errorCode,
|
|
163
|
+
error_message: input.errorMessage,
|
|
164
|
+
metadata: input.metadata,
|
|
165
|
+
}), { requestId: input.requestId });
|
|
166
|
+
return toProvisioningAcknowledgement(response, "sessions.markProvisioningFailed");
|
|
167
|
+
}
|
|
143
168
|
}
|
|
144
169
|
exports.ProxySessionsResource = ProxySessionsResource;
|
|
145
170
|
class ProxySessionCartResource {
|
|
@@ -285,6 +310,18 @@ function requirePayerHandoffStatus(value) {
|
|
|
285
310
|
}
|
|
286
311
|
throw new Error("Proxy API response field sessions.payerHandoff.status is unsupported.");
|
|
287
312
|
}
|
|
313
|
+
function toProvisioningAcknowledgement(response, operation) {
|
|
314
|
+
const body = (0, response_validators_js_1.requireJsonObject)(response, operation);
|
|
315
|
+
const status = (0, response_validators_js_1.requireString)(body.status, `${operation}.status`);
|
|
316
|
+
if (status !== "provisioned" && status !== "provisioning_failed") {
|
|
317
|
+
throw new Error(`Proxy API response field ${operation}.status is unsupported.`);
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
proxySessionId: (0, response_validators_js_1.requireString)(body.proxy_session_id, `${operation}.proxySessionId`),
|
|
321
|
+
status,
|
|
322
|
+
updatedAt: (0, response_validators_js_1.requireString)(body.updated_at, `${operation}.updatedAt`),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
288
325
|
function buildHandoffUrl({ payHost, proxySessionId, publishableKey, }) {
|
|
289
326
|
const url = new URL(`${normalizePayHost(payHost)}/s/${encodeURIComponent(proxySessionId)}`);
|
|
290
327
|
url.searchParams.set("pk", publishableKey);
|
package/dist/cjs/version.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
|
|
2
|
-
export declare const proxyCheckoutServerSdkVersion = "0.0.
|
|
3
|
-
export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.
|
|
2
|
+
export declare const proxyCheckoutServerSdkVersion = "0.0.6";
|
|
3
|
+
export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.6";
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
|
|
2
|
-
export declare const proxyCheckoutServerSdkVersion = "0.0.
|
|
3
|
-
export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.
|
|
2
|
+
export declare const proxyCheckoutServerSdkVersion = "0.0.6";
|
|
3
|
+
export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.6";
|
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.
|
|
5
|
+
exports.proxyCheckoutServerSdkVersion = "0.0.6";
|
|
6
6
|
exports.proxyCheckoutServerSdkUserAgent = `${exports.proxyCheckoutServerSdkName}/${exports.proxyCheckoutServerSdkVersion}`;
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* current-state retrieval so customer webhook routes stay tiny.
|
|
9
9
|
*/
|
|
10
10
|
import type { ProxyEventsResource, ResolvedProxyEvent, ResolvedProxyEventKind } from "./events.js";
|
|
11
|
+
import type { ProxySessionsResource } from "./sessions.js";
|
|
12
|
+
import type { JsonObject } from "./types.js";
|
|
11
13
|
import { type ProxyWebhookEvent } from "./webhooks.js";
|
|
12
14
|
/** Seconds advertised in `Retry-After` when an event is already in flight. */
|
|
13
15
|
export declare const PROXY_WEBHOOK_RETRY_AFTER_SECONDS = 30;
|
|
@@ -33,6 +35,11 @@ export interface ProxyWebhookStore {
|
|
|
33
35
|
/** Mark a claimed event processed (idempotency commit). */
|
|
34
36
|
markProcessed(eventId: string, record: ProxyWebhookProcessRecord): Promise<void> | void;
|
|
35
37
|
}
|
|
38
|
+
export interface ProxyWebhookProvisioningFailure {
|
|
39
|
+
readonly errorCode?: string;
|
|
40
|
+
readonly errorMessage: string;
|
|
41
|
+
readonly metadata?: JsonObject;
|
|
42
|
+
}
|
|
36
43
|
export interface ProxyWebhookPayloadInput {
|
|
37
44
|
readonly body: Buffer | string;
|
|
38
45
|
readonly signature?: string | null;
|
|
@@ -44,6 +51,11 @@ export interface ProxyWebhookPayloadInput {
|
|
|
44
51
|
*/
|
|
45
52
|
export type ProxyWebhookRequestInput = ProxyWebhookPayloadInput | Request;
|
|
46
53
|
export interface ProxyWebhookHandlerOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Optional classifier for non-retryable initial-provision failures. Return a
|
|
56
|
+
* failure payload only after the merchant knows retrying cannot grant access.
|
|
57
|
+
*/
|
|
58
|
+
readonly classifyProvisioningFailure?: (error: unknown, resolved: ResolvedProxyEvent) => Promise<ProxyWebhookProvisioningFailure | null | undefined> | ProxyWebhookProvisioningFailure | null | undefined;
|
|
47
59
|
/** Merchant entitlement callback, invoked once per claimed event after current-state resolution. */
|
|
48
60
|
readonly onResolved: (resolved: ResolvedProxyEvent) => Promise<void> | void;
|
|
49
61
|
/** Optional request id forwarded to the current-state retrieval calls. */
|
|
@@ -64,7 +76,8 @@ export interface ProxyWebhookProcessResult {
|
|
|
64
76
|
}
|
|
65
77
|
export declare class ProxyWebhooksResource {
|
|
66
78
|
private readonly events;
|
|
67
|
-
|
|
79
|
+
private readonly sessions?;
|
|
80
|
+
constructor(events: ProxyEventsResource, sessions?: Pick<ProxySessionsResource, "markProvisioned" | "markProvisioningFailed"> | undefined);
|
|
68
81
|
/** Low-level: verify + construct the event without resolving lifecycle. */
|
|
69
82
|
constructEvent(input: {
|
|
70
83
|
body: Buffer | string;
|
|
@@ -86,4 +99,6 @@ export declare class ProxyWebhooksResource {
|
|
|
86
99
|
* surface a 500 and Proxy retries.
|
|
87
100
|
*/
|
|
88
101
|
handle(input: ProxyWebhookRequestInput, options: ProxyWebhookHandlerOptions): Promise<Response>;
|
|
102
|
+
private runResolvedHandler;
|
|
103
|
+
private requireSessionsResource;
|
|
89
104
|
}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* current-state retrieval so customer webhook routes stay tiny.
|
|
9
9
|
*/
|
|
10
10
|
import type { ProxyEventsResource, ResolvedProxyEvent, ResolvedProxyEventKind } from "./events.js";
|
|
11
|
+
import type { ProxySessionsResource } from "./sessions.js";
|
|
12
|
+
import type { JsonObject } from "./types.js";
|
|
11
13
|
import { type ProxyWebhookEvent } from "./webhooks.js";
|
|
12
14
|
/** Seconds advertised in `Retry-After` when an event is already in flight. */
|
|
13
15
|
export declare const PROXY_WEBHOOK_RETRY_AFTER_SECONDS = 30;
|
|
@@ -33,6 +35,11 @@ export interface ProxyWebhookStore {
|
|
|
33
35
|
/** Mark a claimed event processed (idempotency commit). */
|
|
34
36
|
markProcessed(eventId: string, record: ProxyWebhookProcessRecord): Promise<void> | void;
|
|
35
37
|
}
|
|
38
|
+
export interface ProxyWebhookProvisioningFailure {
|
|
39
|
+
readonly errorCode?: string;
|
|
40
|
+
readonly errorMessage: string;
|
|
41
|
+
readonly metadata?: JsonObject;
|
|
42
|
+
}
|
|
36
43
|
export interface ProxyWebhookPayloadInput {
|
|
37
44
|
readonly body: Buffer | string;
|
|
38
45
|
readonly signature?: string | null;
|
|
@@ -44,6 +51,11 @@ export interface ProxyWebhookPayloadInput {
|
|
|
44
51
|
*/
|
|
45
52
|
export type ProxyWebhookRequestInput = ProxyWebhookPayloadInput | Request;
|
|
46
53
|
export interface ProxyWebhookHandlerOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Optional classifier for non-retryable initial-provision failures. Return a
|
|
56
|
+
* failure payload only after the merchant knows retrying cannot grant access.
|
|
57
|
+
*/
|
|
58
|
+
readonly classifyProvisioningFailure?: (error: unknown, resolved: ResolvedProxyEvent) => Promise<ProxyWebhookProvisioningFailure | null | undefined> | ProxyWebhookProvisioningFailure | null | undefined;
|
|
47
59
|
/** Merchant entitlement callback, invoked once per claimed event after current-state resolution. */
|
|
48
60
|
readonly onResolved: (resolved: ResolvedProxyEvent) => Promise<void> | void;
|
|
49
61
|
/** Optional request id forwarded to the current-state retrieval calls. */
|
|
@@ -64,7 +76,8 @@ export interface ProxyWebhookProcessResult {
|
|
|
64
76
|
}
|
|
65
77
|
export declare class ProxyWebhooksResource {
|
|
66
78
|
private readonly events;
|
|
67
|
-
|
|
79
|
+
private readonly sessions?;
|
|
80
|
+
constructor(events: ProxyEventsResource, sessions?: Pick<ProxySessionsResource, "markProvisioned" | "markProvisioningFailed"> | undefined);
|
|
68
81
|
/** Low-level: verify + construct the event without resolving lifecycle. */
|
|
69
82
|
constructEvent(input: {
|
|
70
83
|
body: Buffer | string;
|
|
@@ -86,4 +99,6 @@ export declare class ProxyWebhooksResource {
|
|
|
86
99
|
* surface a 500 and Proxy retries.
|
|
87
100
|
*/
|
|
88
101
|
handle(input: ProxyWebhookRequestInput, options: ProxyWebhookHandlerOptions): Promise<Response>;
|
|
102
|
+
private runResolvedHandler;
|
|
103
|
+
private requireSessionsResource;
|
|
89
104
|
}
|
|
@@ -10,13 +10,16 @@
|
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ProxyWebhooksResource = exports.PROXY_WEBHOOK_RETRY_AFTER_SECONDS = void 0;
|
|
13
|
+
const errors_js_1 = require("./errors.js");
|
|
13
14
|
const webhooks_js_1 = require("./webhooks.js");
|
|
14
15
|
/** Seconds advertised in `Retry-After` when an event is already in flight. */
|
|
15
16
|
exports.PROXY_WEBHOOK_RETRY_AFTER_SECONDS = 30;
|
|
16
17
|
class ProxyWebhooksResource {
|
|
17
18
|
events;
|
|
18
|
-
|
|
19
|
+
sessions;
|
|
20
|
+
constructor(events, sessions) {
|
|
19
21
|
this.events = events;
|
|
22
|
+
this.sessions = sessions;
|
|
20
23
|
}
|
|
21
24
|
/** Low-level: verify + construct the event without resolving lifecycle. */
|
|
22
25
|
constructEvent(input) {
|
|
@@ -61,7 +64,12 @@ class ProxyWebhooksResource {
|
|
|
61
64
|
let resolved;
|
|
62
65
|
try {
|
|
63
66
|
resolved = await this.events.resolveCurrentState(event, { requestId: options.requestId });
|
|
64
|
-
await
|
|
67
|
+
const provisioningFailed = await this.runResolvedHandler(resolved, options);
|
|
68
|
+
if (!provisioningFailed && resolved.kind === "initial_provision") {
|
|
69
|
+
await this.requireSessionsResource("mark provisioned").markProvisioned(resolved.session.id, {
|
|
70
|
+
requestId: options.requestId,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
65
73
|
}
|
|
66
74
|
catch (error) {
|
|
67
75
|
if (store !== undefined) {
|
|
@@ -120,6 +128,36 @@ class ProxyWebhooksResource {
|
|
|
120
128
|
}
|
|
121
129
|
return toWebhookResponse(result);
|
|
122
130
|
}
|
|
131
|
+
async runResolvedHandler(resolved, options) {
|
|
132
|
+
try {
|
|
133
|
+
await options.onResolved(resolved);
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (resolved.kind !== "initial_provision" || !options.classifyProvisioningFailure) {
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
const failure = await options.classifyProvisioningFailure(error, resolved);
|
|
141
|
+
if (!failure) {
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
await this.requireSessionsResource("mark provisioning failed").markProvisioningFailed(resolved.session.id, {
|
|
145
|
+
errorCode: failure.errorCode,
|
|
146
|
+
errorMessage: failure.errorMessage,
|
|
147
|
+
metadata: failure.metadata,
|
|
148
|
+
requestId: options.requestId,
|
|
149
|
+
});
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
requireSessionsResource(operation) {
|
|
154
|
+
if (this.sessions) {
|
|
155
|
+
return this.sessions;
|
|
156
|
+
}
|
|
157
|
+
throw new errors_js_1.ProxyCheckoutValidationError(`ProxyWebhooksResource cannot ${operation} without a ProxySessionsResource. Construct webhooks via createProxyCheckoutServerClient or pass the sessions resource to new ProxyWebhooksResource(events, sessions).`, {
|
|
158
|
+
code: "webhook_sessions_resource_missing",
|
|
159
|
+
});
|
|
160
|
+
}
|
|
123
161
|
}
|
|
124
162
|
exports.ProxyWebhooksResource = ProxyWebhooksResource;
|
|
125
163
|
function toWebhookResponse(result) {
|
package/dist/esm/client.js
CHANGED
|
@@ -27,7 +27,7 @@ export class ProxyCheckoutServerClient {
|
|
|
27
27
|
});
|
|
28
28
|
this.subscriptions = new ProxySubscriptionsResource(httpClient, this.sessions);
|
|
29
29
|
this.events = new ProxyEventsResource(this.sessions, this.subscriptions);
|
|
30
|
-
this.webhooks = new ProxyWebhooksResource(this.events);
|
|
30
|
+
this.webhooks = new ProxyWebhooksResource(this.events, this.sessions);
|
|
31
31
|
this.webhookEndpoints = new ProxyWebhookEndpointsResource(httpClient);
|
|
32
32
|
}
|
|
33
33
|
}
|
package/dist/esm/errors.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface ProxyCheckoutApiErrorDetails {
|
|
|
4
4
|
readonly responseBody: unknown;
|
|
5
5
|
readonly statusCode: number;
|
|
6
6
|
}
|
|
7
|
-
export type ProxyCheckoutValidationCode = "buyer_reference_mismatch" | "cart_invalid" | "invalid_date" | "provider_binding_mismatch" | "subscription_session_mismatch";
|
|
7
|
+
export type ProxyCheckoutValidationCode = "buyer_reference_mismatch" | "cart_invalid" | "invalid_date" | "provider_binding_mismatch" | "subscription_session_mismatch" | "webhook_sessions_resource_missing";
|
|
8
8
|
/**
|
|
9
9
|
* Raised when the SDK receives Proxy data it cannot safely normalize, for
|
|
10
10
|
* example an invalid date string, a cart snapshot that fails the merchant
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ export { assertCartBuyerReference, assertSubscriptionMatchesSession, } from "./c
|
|
|
4
4
|
export { ProxyCheckoutApiError, type ProxyCheckoutApiErrorDetails, type ProxyCheckoutValidationCode, ProxyCheckoutValidationError, } from "./errors.js";
|
|
5
5
|
export { ProxyEventsResource, type ResolvedIgnored, type ResolvedInitialProvision, type ResolvedPaymentAttempt, type ResolvedPaymentRisk, type ResolvedProxyEvent, type ResolvedProxyEventKind, type ResolvedSubscriptionCancelled, type ResolvedSubscriptionCancelScheduled, type ResolvedSubscriptionRenewed, type ResolvedTerminalSession, type ResolveProxyEventOptions, } from "./events.js";
|
|
6
6
|
export { AT_RISK_SUBSCRIPTION_STATUSES, ENDED_SUBSCRIPTION_STATUSES, isSessionProvisionable, isSessionTerminal, isSubscriptionEnded, isSubscriptionPaymentAtRisk, PROVISIONABLE_SESSION_STATUSES, parseOptionalProxyDate, requireProxyDate, subscriptionAccessEndsAt, subscriptionWillRenew, TERMINAL_SESSION_STATUSES, } from "./lifecycle.js";
|
|
7
|
-
export { type CreateProxySessionHandoffInput, type CreateProxySessionInput, type CreateProxySessionOptions, type MerchantProxySession, type PayerHandoffResult, type PayerOpenedResult, type ProxySession, ProxySessionCartResource, type ProxySessionCartResult, type ProxySessionHandoff, type ProxySessionProviderBinding, ProxySessionsResource, proxyCheckoutServerEndpoints, type RecordProviderBindingInput, type SetProxySessionCartInput, type TypedMerchantProxySession, } from "./sessions.js";
|
|
7
|
+
export { type CreateProxySessionHandoffInput, type CreateProxySessionInput, type CreateProxySessionOptions, type MarkProxySessionProvisionedInput, type MarkProxySessionProvisioningFailedInput, type MerchantProxySession, type PayerHandoffResult, type PayerOpenedResult, type ProxySession, ProxySessionCartResource, type ProxySessionCartResult, type ProxySessionHandoff, type ProxySessionProviderBinding, type ProxySessionProvisioningAcknowledgement, ProxySessionsResource, proxyCheckoutServerEndpoints, type RecordProviderBindingInput, type SetProxySessionCartInput, type TypedMerchantProxySession, } from "./sessions.js";
|
|
8
8
|
export { type MerchantProxySubscription, ProxySubscriptionsResource, type ProxySubscriptionWithSession, type ProxySubscriptionWithUntypedSession, proxyCheckoutSubscriptionEndpoints, } from "./subscriptions.js";
|
|
9
9
|
export type { JsonObject, JsonPrimitive, JsonValue, ProxyCheckoutFetch, ProxyCheckoutServerClientOptions, ProxyCheckoutServerRequestOptions, } from "./types.js";
|
|
10
10
|
export { proxyCheckoutServerSdkName, proxyCheckoutServerSdkUserAgent, proxyCheckoutServerSdkVersion, } from "./version.js";
|
|
11
11
|
export { isProxyPaymentAttemptEvent, isProxySessionEvent, isProxySubscriptionEvent, PROXY_WEBHOOK_EVENT_TYPES, type ProxyWebhookEventType, } from "./webhook-events.js";
|
|
12
|
-
export { PROXY_WEBHOOK_RETRY_AFTER_SECONDS, type ProxyWebhookClaimResult, type ProxyWebhookHandlerOptions, type ProxyWebhookOutcome, type ProxyWebhookPayloadInput, type ProxyWebhookProcessRecord, type ProxyWebhookProcessResult, type ProxyWebhookRequestInput, type ProxyWebhookStore, ProxyWebhooksResource, } from "./webhook-handler.js";
|
|
12
|
+
export { PROXY_WEBHOOK_RETRY_AFTER_SECONDS, type ProxyWebhookClaimResult, type ProxyWebhookHandlerOptions, type ProxyWebhookOutcome, type ProxyWebhookPayloadInput, type ProxyWebhookProcessRecord, type ProxyWebhookProcessResult, type ProxyWebhookProvisioningFailure, type ProxyWebhookRequestInput, type ProxyWebhookStore, ProxyWebhooksResource, } from "./webhook-handler.js";
|
|
13
13
|
export { type ConstructProxyWebhookEventInput, type CreateWebhookEndpointInput, constructProxyWebhookEvent, PROXY_SIGNATURE_HEADER, ProxyWebhookEndpointsResource, type ProxyWebhookEvent, ProxyWebhookSignatureVerificationError, proxyCheckoutWebhookEndpointEndpoints, type RotateWebhookEndpointSecretInput, type UpdateWebhookEndpointInput, type VerifyProxyWebhookSignatureInput, verifyProxyWebhookSignature, type WebhookEndpoint, type WebhookEndpointSecretResult, } from "./webhooks.js";
|
package/dist/esm/sessions.d.ts
CHANGED
|
@@ -86,6 +86,20 @@ export interface ProxySessionProviderBinding {
|
|
|
86
86
|
readonly psp: string;
|
|
87
87
|
readonly updatedAt: string;
|
|
88
88
|
}
|
|
89
|
+
export interface MarkProxySessionProvisionedInput extends ProxyCheckoutServerRequestOptions {
|
|
90
|
+
readonly fulfillmentReference?: string;
|
|
91
|
+
readonly metadata?: JsonObject;
|
|
92
|
+
}
|
|
93
|
+
export interface MarkProxySessionProvisioningFailedInput extends ProxyCheckoutServerRequestOptions {
|
|
94
|
+
readonly errorCode?: string;
|
|
95
|
+
readonly errorMessage: string;
|
|
96
|
+
readonly metadata?: JsonObject;
|
|
97
|
+
}
|
|
98
|
+
export interface ProxySessionProvisioningAcknowledgement {
|
|
99
|
+
readonly proxySessionId: string;
|
|
100
|
+
readonly status: "provisioned" | "provisioning_failed";
|
|
101
|
+
readonly updatedAt: string;
|
|
102
|
+
}
|
|
89
103
|
export declare const proxyCheckoutServerEndpoints: readonly [{
|
|
90
104
|
readonly method: "POST";
|
|
91
105
|
readonly operation: "sessions.create";
|
|
@@ -114,6 +128,14 @@ export declare const proxyCheckoutServerEndpoints: readonly [{
|
|
|
114
128
|
readonly method: "POST";
|
|
115
129
|
readonly operation: "sessions.providerBindings.create";
|
|
116
130
|
readonly path: "/proxy_sessions/:id/provider_bindings";
|
|
131
|
+
}, {
|
|
132
|
+
readonly method: "POST";
|
|
133
|
+
readonly operation: "sessions.markProvisioned";
|
|
134
|
+
readonly path: "/proxy_sessions/:id/provisioned";
|
|
135
|
+
}, {
|
|
136
|
+
readonly method: "POST";
|
|
137
|
+
readonly operation: "sessions.markProvisioningFailed";
|
|
138
|
+
readonly path: "/proxy_sessions/:id/provisioning_failed";
|
|
117
139
|
}];
|
|
118
140
|
export declare class ProxySessionsResource {
|
|
119
141
|
private readonly httpClient;
|
|
@@ -146,6 +168,8 @@ export declare class ProxySessionsResource {
|
|
|
146
168
|
* the session is already bound to a different one.
|
|
147
169
|
*/
|
|
148
170
|
recordProviderBinding(proxySessionId: string, input: RecordProviderBindingInput): Promise<ProxySessionProviderBinding>;
|
|
171
|
+
markProvisioned(proxySessionId: string, input?: MarkProxySessionProvisionedInput): Promise<ProxySessionProvisioningAcknowledgement>;
|
|
172
|
+
markProvisioningFailed(proxySessionId: string, input: MarkProxySessionProvisioningFailedInput): Promise<ProxySessionProvisioningAcknowledgement>;
|
|
149
173
|
}
|
|
150
174
|
export declare class ProxySessionCartResource {
|
|
151
175
|
private readonly httpClient;
|
package/dist/esm/sessions.js
CHANGED
|
@@ -37,6 +37,16 @@ export const proxyCheckoutServerEndpoints = [
|
|
|
37
37
|
operation: "sessions.providerBindings.create",
|
|
38
38
|
path: "/proxy_sessions/:id/provider_bindings",
|
|
39
39
|
},
|
|
40
|
+
{
|
|
41
|
+
method: "POST",
|
|
42
|
+
operation: "sessions.markProvisioned",
|
|
43
|
+
path: "/proxy_sessions/:id/provisioned",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
method: "POST",
|
|
47
|
+
operation: "sessions.markProvisioningFailed",
|
|
48
|
+
path: "/proxy_sessions/:id/provisioning_failed",
|
|
49
|
+
},
|
|
40
50
|
];
|
|
41
51
|
export class ProxySessionsResource {
|
|
42
52
|
httpClient;
|
|
@@ -137,6 +147,21 @@ export class ProxySessionsResource {
|
|
|
137
147
|
updatedAt: requireString(body.updated_at, "sessions.providerBindings.create.updatedAt"),
|
|
138
148
|
};
|
|
139
149
|
}
|
|
150
|
+
async markProvisioned(proxySessionId, input = {}) {
|
|
151
|
+
const response = await this.httpClient.request("POST", `/proxy_sessions/${encodeURIComponent(proxySessionId)}/provisioned`, removeUndefinedValues({
|
|
152
|
+
fulfillment_reference: input.fulfillmentReference,
|
|
153
|
+
metadata: input.metadata,
|
|
154
|
+
}), { requestId: input.requestId });
|
|
155
|
+
return toProvisioningAcknowledgement(response, "sessions.markProvisioned");
|
|
156
|
+
}
|
|
157
|
+
async markProvisioningFailed(proxySessionId, input) {
|
|
158
|
+
const response = await this.httpClient.request("POST", `/proxy_sessions/${encodeURIComponent(proxySessionId)}/provisioning_failed`, removeUndefinedValues({
|
|
159
|
+
error_code: input.errorCode,
|
|
160
|
+
error_message: input.errorMessage,
|
|
161
|
+
metadata: input.metadata,
|
|
162
|
+
}), { requestId: input.requestId });
|
|
163
|
+
return toProvisioningAcknowledgement(response, "sessions.markProvisioningFailed");
|
|
164
|
+
}
|
|
140
165
|
}
|
|
141
166
|
export class ProxySessionCartResource {
|
|
142
167
|
httpClient;
|
|
@@ -280,6 +305,18 @@ function requirePayerHandoffStatus(value) {
|
|
|
280
305
|
}
|
|
281
306
|
throw new Error("Proxy API response field sessions.payerHandoff.status is unsupported.");
|
|
282
307
|
}
|
|
308
|
+
function toProvisioningAcknowledgement(response, operation) {
|
|
309
|
+
const body = requireJsonObject(response, operation);
|
|
310
|
+
const status = requireString(body.status, `${operation}.status`);
|
|
311
|
+
if (status !== "provisioned" && status !== "provisioning_failed") {
|
|
312
|
+
throw new Error(`Proxy API response field ${operation}.status is unsupported.`);
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
proxySessionId: requireString(body.proxy_session_id, `${operation}.proxySessionId`),
|
|
316
|
+
status,
|
|
317
|
+
updatedAt: requireString(body.updated_at, `${operation}.updatedAt`),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
283
320
|
function buildHandoffUrl({ payHost, proxySessionId, publishableKey, }) {
|
|
284
321
|
const url = new URL(`${normalizePayHost(payHost)}/s/${encodeURIComponent(proxySessionId)}`);
|
|
285
322
|
url.searchParams.set("pk", publishableKey);
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
|
|
2
|
-
export declare const proxyCheckoutServerSdkVersion = "0.0.
|
|
3
|
-
export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.
|
|
2
|
+
export declare const proxyCheckoutServerSdkVersion = "0.0.6";
|
|
3
|
+
export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.6";
|
package/dist/esm/version.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
|
|
2
|
-
export const proxyCheckoutServerSdkVersion = "0.0.
|
|
2
|
+
export const proxyCheckoutServerSdkVersion = "0.0.6";
|
|
3
3
|
export const proxyCheckoutServerSdkUserAgent = `${proxyCheckoutServerSdkName}/${proxyCheckoutServerSdkVersion}`;
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* current-state retrieval so customer webhook routes stay tiny.
|
|
9
9
|
*/
|
|
10
10
|
import type { ProxyEventsResource, ResolvedProxyEvent, ResolvedProxyEventKind } from "./events.js";
|
|
11
|
+
import type { ProxySessionsResource } from "./sessions.js";
|
|
12
|
+
import type { JsonObject } from "./types.js";
|
|
11
13
|
import { type ProxyWebhookEvent } from "./webhooks.js";
|
|
12
14
|
/** Seconds advertised in `Retry-After` when an event is already in flight. */
|
|
13
15
|
export declare const PROXY_WEBHOOK_RETRY_AFTER_SECONDS = 30;
|
|
@@ -33,6 +35,11 @@ export interface ProxyWebhookStore {
|
|
|
33
35
|
/** Mark a claimed event processed (idempotency commit). */
|
|
34
36
|
markProcessed(eventId: string, record: ProxyWebhookProcessRecord): Promise<void> | void;
|
|
35
37
|
}
|
|
38
|
+
export interface ProxyWebhookProvisioningFailure {
|
|
39
|
+
readonly errorCode?: string;
|
|
40
|
+
readonly errorMessage: string;
|
|
41
|
+
readonly metadata?: JsonObject;
|
|
42
|
+
}
|
|
36
43
|
export interface ProxyWebhookPayloadInput {
|
|
37
44
|
readonly body: Buffer | string;
|
|
38
45
|
readonly signature?: string | null;
|
|
@@ -44,6 +51,11 @@ export interface ProxyWebhookPayloadInput {
|
|
|
44
51
|
*/
|
|
45
52
|
export type ProxyWebhookRequestInput = ProxyWebhookPayloadInput | Request;
|
|
46
53
|
export interface ProxyWebhookHandlerOptions {
|
|
54
|
+
/**
|
|
55
|
+
* Optional classifier for non-retryable initial-provision failures. Return a
|
|
56
|
+
* failure payload only after the merchant knows retrying cannot grant access.
|
|
57
|
+
*/
|
|
58
|
+
readonly classifyProvisioningFailure?: (error: unknown, resolved: ResolvedProxyEvent) => Promise<ProxyWebhookProvisioningFailure | null | undefined> | ProxyWebhookProvisioningFailure | null | undefined;
|
|
47
59
|
/** Merchant entitlement callback, invoked once per claimed event after current-state resolution. */
|
|
48
60
|
readonly onResolved: (resolved: ResolvedProxyEvent) => Promise<void> | void;
|
|
49
61
|
/** Optional request id forwarded to the current-state retrieval calls. */
|
|
@@ -64,7 +76,8 @@ export interface ProxyWebhookProcessResult {
|
|
|
64
76
|
}
|
|
65
77
|
export declare class ProxyWebhooksResource {
|
|
66
78
|
private readonly events;
|
|
67
|
-
|
|
79
|
+
private readonly sessions?;
|
|
80
|
+
constructor(events: ProxyEventsResource, sessions?: Pick<ProxySessionsResource, "markProvisioned" | "markProvisioningFailed"> | undefined);
|
|
68
81
|
/** Low-level: verify + construct the event without resolving lifecycle. */
|
|
69
82
|
constructEvent(input: {
|
|
70
83
|
body: Buffer | string;
|
|
@@ -86,4 +99,6 @@ export declare class ProxyWebhooksResource {
|
|
|
86
99
|
* surface a 500 and Proxy retries.
|
|
87
100
|
*/
|
|
88
101
|
handle(input: ProxyWebhookRequestInput, options: ProxyWebhookHandlerOptions): Promise<Response>;
|
|
102
|
+
private runResolvedHandler;
|
|
103
|
+
private requireSessionsResource;
|
|
89
104
|
}
|
|
@@ -7,13 +7,16 @@
|
|
|
7
7
|
* verification, duplicate/in-flight handling, retryable responses, and
|
|
8
8
|
* current-state retrieval so customer webhook routes stay tiny.
|
|
9
9
|
*/
|
|
10
|
+
import { ProxyCheckoutValidationError } from "./errors.js";
|
|
10
11
|
import { constructProxyWebhookEvent, PROXY_SIGNATURE_HEADER, ProxyWebhookSignatureVerificationError, } from "./webhooks.js";
|
|
11
12
|
/** Seconds advertised in `Retry-After` when an event is already in flight. */
|
|
12
13
|
export const PROXY_WEBHOOK_RETRY_AFTER_SECONDS = 30;
|
|
13
14
|
export class ProxyWebhooksResource {
|
|
14
15
|
events;
|
|
15
|
-
|
|
16
|
+
sessions;
|
|
17
|
+
constructor(events, sessions) {
|
|
16
18
|
this.events = events;
|
|
19
|
+
this.sessions = sessions;
|
|
17
20
|
}
|
|
18
21
|
/** Low-level: verify + construct the event without resolving lifecycle. */
|
|
19
22
|
constructEvent(input) {
|
|
@@ -58,7 +61,12 @@ export class ProxyWebhooksResource {
|
|
|
58
61
|
let resolved;
|
|
59
62
|
try {
|
|
60
63
|
resolved = await this.events.resolveCurrentState(event, { requestId: options.requestId });
|
|
61
|
-
await
|
|
64
|
+
const provisioningFailed = await this.runResolvedHandler(resolved, options);
|
|
65
|
+
if (!provisioningFailed && resolved.kind === "initial_provision") {
|
|
66
|
+
await this.requireSessionsResource("mark provisioned").markProvisioned(resolved.session.id, {
|
|
67
|
+
requestId: options.requestId,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
62
70
|
}
|
|
63
71
|
catch (error) {
|
|
64
72
|
if (store !== undefined) {
|
|
@@ -117,6 +125,36 @@ export class ProxyWebhooksResource {
|
|
|
117
125
|
}
|
|
118
126
|
return toWebhookResponse(result);
|
|
119
127
|
}
|
|
128
|
+
async runResolvedHandler(resolved, options) {
|
|
129
|
+
try {
|
|
130
|
+
await options.onResolved(resolved);
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (resolved.kind !== "initial_provision" || !options.classifyProvisioningFailure) {
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
const failure = await options.classifyProvisioningFailure(error, resolved);
|
|
138
|
+
if (!failure) {
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
await this.requireSessionsResource("mark provisioning failed").markProvisioningFailed(resolved.session.id, {
|
|
142
|
+
errorCode: failure.errorCode,
|
|
143
|
+
errorMessage: failure.errorMessage,
|
|
144
|
+
metadata: failure.metadata,
|
|
145
|
+
requestId: options.requestId,
|
|
146
|
+
});
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
requireSessionsResource(operation) {
|
|
151
|
+
if (this.sessions) {
|
|
152
|
+
return this.sessions;
|
|
153
|
+
}
|
|
154
|
+
throw new ProxyCheckoutValidationError(`ProxyWebhooksResource cannot ${operation} without a ProxySessionsResource. Construct webhooks via createProxyCheckoutServerClient or pass the sessions resource to new ProxyWebhooksResource(events, sessions).`, {
|
|
155
|
+
code: "webhook_sessions_resource_missing",
|
|
156
|
+
});
|
|
157
|
+
}
|
|
120
158
|
}
|
|
121
159
|
function toWebhookResponse(result) {
|
|
122
160
|
const headers = { "content-type": "application/json" };
|