@proxy-checkout/server-js 0.0.6 → 0.0.7

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/README.md CHANGED
@@ -12,8 +12,8 @@ This package should expose the merchant-authenticated backend routes that exist
12
12
  | `proxy.sessions.createHandoff` | `POST /proxy_sessions/handoff` | Create a Proxy session and atomically mark it ready for hosted payer handoff. |
13
13
  | `proxy.sessions.retrieve` | `GET /proxy_sessions/:id/merchant` | Retrieve current merchant-owned session state after a webhook or before creating PSP objects. |
14
14
  | `proxy.sessions.cart.set` | `PUT /proxy_sessions/:id/cart` | Replace the current cart snapshot before payment orchestration. |
15
- | `proxy.sessions.payerHandoff` | `POST /proxy_sessions/:id/payer_handoff` | Record merchant handoff issuance before the payer loads checkout. |
16
- | `proxy.sessions.payerOpened` | `POST /proxy_sessions/:id/payer_opened` | Record checkout open and read the current merchant session/cart state. |
15
+ | `proxy.sessions.payerHandoff` | `POST /proxy_sessions/:id/payer_handoff` | Low-level escape hatch. Most delegated checkout integrations should use `createHandoff`. |
16
+ | `proxy.sessions.payerOpened` | `POST /proxy_sessions/:id/payer_opened` | Low-level escape hatch. Stripe integrations should usually let `@proxy-checkout/stripe-server-js` call this through `openCheckout`. |
17
17
  | `proxy.subscriptions.retrieve` | `GET /subscriptions/:id` | Retrieve current Proxy-linked subscription lifecycle state. |
18
18
  | `proxy.webhookEndpoints.list` | `GET /webhook_endpoints` | List outbound merchant webhook endpoints. |
19
19
  | `proxy.webhookEndpoints.create` | `POST /webhook_endpoints` | Create an outbound endpoint and receive its one-time signing secret. |
@@ -62,6 +62,14 @@ const endpoint = await proxy.webhookEndpoints.create({
62
62
  console.log(endpoint.signingSecret);
63
63
  ```
64
64
 
65
+ For delegated checkout, prefer the high-level flow:
66
+
67
+ 1. Create buyer handoffs with `proxy.sessions.createHandoff(...)`.
68
+ 2. Let `@proxy-checkout/stripe-server-js` `openCheckout(...)` record payer-opened, create the merchant-owned Stripe object, inject required metadata, and record provider binding.
69
+ 3. Let `proxy.webhooks.handle(...)` verify signed Proxy webhooks, resolve current state, and acknowledge initial provisioning.
70
+
71
+ Use `payerHandoff`, `payerOpened`, raw event construction, or manual provisioning acknowledgements only for custom integrations that cannot use the default helpers.
72
+
65
73
  Verify and parse outbound webhooks with the exact raw request body:
66
74
 
67
75
  ```ts
@@ -29,4 +29,6 @@ export declare class ProxyCheckoutApiError extends Error {
29
29
  readonly statusCode: number;
30
30
  constructor(message: string, details: ProxyCheckoutApiErrorDetails);
31
31
  }
32
+ export declare const PROXY_SESSION_NOT_FOUND_ERROR_CODE = "proxy_session_not_found";
33
+ export declare function isProxySessionNotFoundError(error: unknown): error is ProxyCheckoutApiError;
32
34
  export declare function toApiError(statusCode: number, responseBody: unknown, headerRequestId?: string): ProxyCheckoutApiError;
@@ -29,4 +29,6 @@ export declare class ProxyCheckoutApiError extends Error {
29
29
  readonly statusCode: number;
30
30
  constructor(message: string, details: ProxyCheckoutApiErrorDetails);
31
31
  }
32
+ export declare const PROXY_SESSION_NOT_FOUND_ERROR_CODE = "proxy_session_not_found";
33
+ export declare function isProxySessionNotFoundError(error: unknown): error is ProxyCheckoutApiError;
32
34
  export declare function toApiError(statusCode: number, responseBody: unknown, headerRequestId?: string): ProxyCheckoutApiError;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProxyCheckoutApiError = exports.ProxyCheckoutValidationError = void 0;
3
+ exports.PROXY_SESSION_NOT_FOUND_ERROR_CODE = exports.ProxyCheckoutApiError = exports.ProxyCheckoutValidationError = void 0;
4
+ exports.isProxySessionNotFoundError = isProxySessionNotFoundError;
4
5
  exports.toApiError = toApiError;
5
6
  /**
6
7
  * Raised when the SDK receives Proxy data it cannot safely normalize, for
@@ -35,6 +36,22 @@ class ProxyCheckoutApiError extends Error {
35
36
  }
36
37
  }
37
38
  exports.ProxyCheckoutApiError = ProxyCheckoutApiError;
39
+ exports.PROXY_SESSION_NOT_FOUND_ERROR_CODE = "proxy_session_not_found";
40
+ function isProxySessionNotFoundError(error) {
41
+ if (error instanceof ProxyCheckoutApiError) {
42
+ return error.statusCode === 404 && error.code === exports.PROXY_SESSION_NOT_FOUND_ERROR_CODE;
43
+ }
44
+ // Preserve classification across ESM/CJS or bundled SDK boundaries where
45
+ // instanceof can fail even though the error still came from Proxy.
46
+ return (typeof error === "object" &&
47
+ error !== null &&
48
+ "name" in error &&
49
+ error.name === "ProxyCheckoutApiError" &&
50
+ "statusCode" in error &&
51
+ error.statusCode === 404 &&
52
+ "code" in error &&
53
+ error.code === exports.PROXY_SESSION_NOT_FOUND_ERROR_CODE);
54
+ }
38
55
  function toApiError(statusCode, responseBody, headerRequestId) {
39
56
  const error = readApiError(responseBody);
40
57
  const message = error.message ?? `Proxy API request failed with status ${statusCode}.`;
@@ -1,7 +1,7 @@
1
1
  export { type ProxyCartParseOptions, type ProxyCartValidator, parseProxyCart, } from "./cart.js";
2
2
  export { createProxyCheckoutServerClient, ProxyCheckoutServerClient, } from "./client.js";
3
3
  export { assertCartBuyerReference, assertSubscriptionMatchesSession, } from "./consistency.js";
4
- export { ProxyCheckoutApiError, type ProxyCheckoutApiErrorDetails, type ProxyCheckoutValidationCode, ProxyCheckoutValidationError, } from "./errors.js";
4
+ export { isProxySessionNotFoundError, PROXY_SESSION_NOT_FOUND_ERROR_CODE, 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
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";
@@ -1,7 +1,7 @@
1
1
  export { type ProxyCartParseOptions, type ProxyCartValidator, parseProxyCart, } from "./cart.js";
2
2
  export { createProxyCheckoutServerClient, ProxyCheckoutServerClient, } from "./client.js";
3
3
  export { assertCartBuyerReference, assertSubscriptionMatchesSession, } from "./consistency.js";
4
- export { ProxyCheckoutApiError, type ProxyCheckoutApiErrorDetails, type ProxyCheckoutValidationCode, ProxyCheckoutValidationError, } from "./errors.js";
4
+ export { isProxySessionNotFoundError, PROXY_SESSION_NOT_FOUND_ERROR_CODE, 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
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";
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyProxyWebhookSignature = exports.proxyCheckoutWebhookEndpointEndpoints = exports.ProxyWebhookSignatureVerificationError = exports.ProxyWebhookEndpointsResource = exports.PROXY_SIGNATURE_HEADER = exports.constructProxyWebhookEvent = exports.ProxyWebhooksResource = exports.PROXY_WEBHOOK_RETRY_AFTER_SECONDS = exports.PROXY_WEBHOOK_EVENT_TYPES = exports.isProxySubscriptionEvent = exports.isProxySessionEvent = exports.isProxyPaymentAttemptEvent = exports.proxyCheckoutServerSdkVersion = exports.proxyCheckoutServerSdkUserAgent = exports.proxyCheckoutServerSdkName = exports.proxyCheckoutSubscriptionEndpoints = exports.ProxySubscriptionsResource = exports.proxyCheckoutServerEndpoints = exports.ProxySessionsResource = exports.ProxySessionCartResource = exports.TERMINAL_SESSION_STATUSES = exports.subscriptionWillRenew = exports.subscriptionAccessEndsAt = exports.requireProxyDate = exports.parseOptionalProxyDate = exports.PROVISIONABLE_SESSION_STATUSES = exports.isSubscriptionPaymentAtRisk = exports.isSubscriptionEnded = exports.isSessionTerminal = exports.isSessionProvisionable = exports.ENDED_SUBSCRIPTION_STATUSES = exports.AT_RISK_SUBSCRIPTION_STATUSES = exports.ProxyEventsResource = exports.ProxyCheckoutValidationError = exports.ProxyCheckoutApiError = exports.assertSubscriptionMatchesSession = exports.assertCartBuyerReference = exports.ProxyCheckoutServerClient = exports.createProxyCheckoutServerClient = exports.parseProxyCart = void 0;
3
+ exports.verifyProxyWebhookSignature = exports.proxyCheckoutWebhookEndpointEndpoints = exports.ProxyWebhookSignatureVerificationError = exports.ProxyWebhookEndpointsResource = exports.PROXY_SIGNATURE_HEADER = exports.constructProxyWebhookEvent = exports.ProxyWebhooksResource = exports.PROXY_WEBHOOK_RETRY_AFTER_SECONDS = exports.PROXY_WEBHOOK_EVENT_TYPES = exports.isProxySubscriptionEvent = exports.isProxySessionEvent = exports.isProxyPaymentAttemptEvent = exports.proxyCheckoutServerSdkVersion = exports.proxyCheckoutServerSdkUserAgent = exports.proxyCheckoutServerSdkName = exports.proxyCheckoutSubscriptionEndpoints = exports.ProxySubscriptionsResource = exports.proxyCheckoutServerEndpoints = exports.ProxySessionsResource = exports.ProxySessionCartResource = exports.TERMINAL_SESSION_STATUSES = exports.subscriptionWillRenew = exports.subscriptionAccessEndsAt = exports.requireProxyDate = exports.parseOptionalProxyDate = exports.PROVISIONABLE_SESSION_STATUSES = exports.isSubscriptionPaymentAtRisk = exports.isSubscriptionEnded = exports.isSessionTerminal = exports.isSessionProvisionable = exports.ENDED_SUBSCRIPTION_STATUSES = exports.AT_RISK_SUBSCRIPTION_STATUSES = exports.ProxyEventsResource = exports.ProxyCheckoutValidationError = exports.ProxyCheckoutApiError = exports.PROXY_SESSION_NOT_FOUND_ERROR_CODE = exports.isProxySessionNotFoundError = exports.assertSubscriptionMatchesSession = exports.assertCartBuyerReference = exports.ProxyCheckoutServerClient = exports.createProxyCheckoutServerClient = exports.parseProxyCart = void 0;
4
4
  var cart_js_1 = require("./cart.js");
5
5
  Object.defineProperty(exports, "parseProxyCart", { enumerable: true, get: function () { return cart_js_1.parseProxyCart; } });
6
6
  var client_js_1 = require("./client.js");
@@ -10,6 +10,8 @@ var consistency_js_1 = require("./consistency.js");
10
10
  Object.defineProperty(exports, "assertCartBuyerReference", { enumerable: true, get: function () { return consistency_js_1.assertCartBuyerReference; } });
11
11
  Object.defineProperty(exports, "assertSubscriptionMatchesSession", { enumerable: true, get: function () { return consistency_js_1.assertSubscriptionMatchesSession; } });
12
12
  var errors_js_1 = require("./errors.js");
13
+ Object.defineProperty(exports, "isProxySessionNotFoundError", { enumerable: true, get: function () { return errors_js_1.isProxySessionNotFoundError; } });
14
+ Object.defineProperty(exports, "PROXY_SESSION_NOT_FOUND_ERROR_CODE", { enumerable: true, get: function () { return errors_js_1.PROXY_SESSION_NOT_FOUND_ERROR_CODE; } });
13
15
  Object.defineProperty(exports, "ProxyCheckoutApiError", { enumerable: true, get: function () { return errors_js_1.ProxyCheckoutApiError; } });
14
16
  Object.defineProperty(exports, "ProxyCheckoutValidationError", { enumerable: true, get: function () { return errors_js_1.ProxyCheckoutValidationError; } });
15
17
  var events_js_1 = require("./events.js");
@@ -73,9 +73,6 @@ class ProxySessionsResource {
73
73
  throw new Error("Proxy Checkout sessions.createHandoff requires a publishableKey option or input field.");
74
74
  }
75
75
  const payHost = input.payHost ?? this.options.payHost;
76
- if (!payHost && this.httpClient.apiHost !== "https://api.proxycheckout.com") {
77
- throw new Error("Proxy Checkout sessions.createHandoff requires a payHost option or input field when apiHost is overridden.");
78
- }
79
76
  const response = await this.httpClient.request("POST", "/proxy_sessions/handoff", {
80
77
  ...toCreateProxySessionBody(input),
81
78
  ...(input.payerDestinationUrl !== undefined
@@ -87,13 +84,19 @@ class ProxySessionsResource {
87
84
  requestId: input.requestId,
88
85
  });
89
86
  const session = toProxySessionHandoff(response);
87
+ if (!session.handoffUrl &&
88
+ !payHost &&
89
+ this.httpClient.apiHost !== "https://api.proxycheckout.com") {
90
+ throw new Error("Proxy Checkout sessions.createHandoff requires a payHost option or input field when apiHost is overridden and the API response does not include handoff_url.");
91
+ }
90
92
  return {
91
93
  ...session,
92
- handoffUrl: buildHandoffUrl({
93
- payHost,
94
- proxySessionId: session.id,
95
- publishableKey,
96
- }),
94
+ handoffUrl: session.handoffUrl ||
95
+ buildHandoffUrl({
96
+ payHost,
97
+ proxySessionId: session.id,
98
+ publishableKey,
99
+ }),
97
100
  };
98
101
  }
99
102
  async retrieve(proxySessionId, options = {}) {
@@ -239,7 +242,11 @@ function toProxySessionHandoff(response) {
239
242
  const integrationMode = (0, response_validators_js_1.requireString)(body.integration_mode, "sessions.createHandoff.integrationMode");
240
243
  return {
241
244
  expiresAt: (0, response_validators_js_1.requireString)(body.expires_at, "sessions.createHandoff.expiresAt"),
242
- handoffUrl: "",
245
+ handoffUrl: typeof body.handoff_url === "string"
246
+ ? body.handoff_url
247
+ : typeof body.handoffUrl === "string"
248
+ ? body.handoffUrl
249
+ : "",
243
250
  id: (0, response_validators_js_1.requireString)(body.id, "sessions.createHandoff.id"),
244
251
  integrationMode,
245
252
  status,
@@ -1,3 +1,3 @@
1
1
  export declare const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
2
- export declare const proxyCheckoutServerSdkVersion = "0.0.6";
3
- export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.6";
2
+ export declare const proxyCheckoutServerSdkVersion = "0.0.7";
3
+ export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.7";
@@ -1,3 +1,3 @@
1
1
  export declare const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
2
- export declare const proxyCheckoutServerSdkVersion = "0.0.6";
3
- export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.6";
2
+ export declare const proxyCheckoutServerSdkVersion = "0.0.7";
3
+ export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.7";
@@ -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.6";
5
+ exports.proxyCheckoutServerSdkVersion = "0.0.7";
6
6
  exports.proxyCheckoutServerSdkUserAgent = `${exports.proxyCheckoutServerSdkName}/${exports.proxyCheckoutServerSdkVersion}`;
@@ -29,4 +29,6 @@ export declare class ProxyCheckoutApiError extends Error {
29
29
  readonly statusCode: number;
30
30
  constructor(message: string, details: ProxyCheckoutApiErrorDetails);
31
31
  }
32
+ export declare const PROXY_SESSION_NOT_FOUND_ERROR_CODE = "proxy_session_not_found";
33
+ export declare function isProxySessionNotFoundError(error: unknown): error is ProxyCheckoutApiError;
32
34
  export declare function toApiError(statusCode: number, responseBody: unknown, headerRequestId?: string): ProxyCheckoutApiError;
@@ -29,6 +29,22 @@ export class ProxyCheckoutApiError extends Error {
29
29
  this.statusCode = details.statusCode;
30
30
  }
31
31
  }
32
+ export const PROXY_SESSION_NOT_FOUND_ERROR_CODE = "proxy_session_not_found";
33
+ export function isProxySessionNotFoundError(error) {
34
+ if (error instanceof ProxyCheckoutApiError) {
35
+ return error.statusCode === 404 && error.code === PROXY_SESSION_NOT_FOUND_ERROR_CODE;
36
+ }
37
+ // Preserve classification across ESM/CJS or bundled SDK boundaries where
38
+ // instanceof can fail even though the error still came from Proxy.
39
+ return (typeof error === "object" &&
40
+ error !== null &&
41
+ "name" in error &&
42
+ error.name === "ProxyCheckoutApiError" &&
43
+ "statusCode" in error &&
44
+ error.statusCode === 404 &&
45
+ "code" in error &&
46
+ error.code === PROXY_SESSION_NOT_FOUND_ERROR_CODE);
47
+ }
32
48
  export function toApiError(statusCode, responseBody, headerRequestId) {
33
49
  const error = readApiError(responseBody);
34
50
  const message = error.message ?? `Proxy API request failed with status ${statusCode}.`;
@@ -1,7 +1,7 @@
1
1
  export { type ProxyCartParseOptions, type ProxyCartValidator, parseProxyCart, } from "./cart.js";
2
2
  export { createProxyCheckoutServerClient, ProxyCheckoutServerClient, } from "./client.js";
3
3
  export { assertCartBuyerReference, assertSubscriptionMatchesSession, } from "./consistency.js";
4
- export { ProxyCheckoutApiError, type ProxyCheckoutApiErrorDetails, type ProxyCheckoutValidationCode, ProxyCheckoutValidationError, } from "./errors.js";
4
+ export { isProxySessionNotFoundError, PROXY_SESSION_NOT_FOUND_ERROR_CODE, 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
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";
package/dist/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { parseProxyCart, } from "./cart.js";
2
2
  export { createProxyCheckoutServerClient, ProxyCheckoutServerClient, } from "./client.js";
3
3
  export { assertCartBuyerReference, assertSubscriptionMatchesSession, } from "./consistency.js";
4
- export { ProxyCheckoutApiError, ProxyCheckoutValidationError, } from "./errors.js";
4
+ export { isProxySessionNotFoundError, PROXY_SESSION_NOT_FOUND_ERROR_CODE, ProxyCheckoutApiError, ProxyCheckoutValidationError, } from "./errors.js";
5
5
  export { ProxyEventsResource, } 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
7
  export { ProxySessionCartResource, ProxySessionsResource, proxyCheckoutServerEndpoints, } from "./sessions.js";
@@ -70,9 +70,6 @@ export class ProxySessionsResource {
70
70
  throw new Error("Proxy Checkout sessions.createHandoff requires a publishableKey option or input field.");
71
71
  }
72
72
  const payHost = input.payHost ?? this.options.payHost;
73
- if (!payHost && this.httpClient.apiHost !== "https://api.proxycheckout.com") {
74
- throw new Error("Proxy Checkout sessions.createHandoff requires a payHost option or input field when apiHost is overridden.");
75
- }
76
73
  const response = await this.httpClient.request("POST", "/proxy_sessions/handoff", {
77
74
  ...toCreateProxySessionBody(input),
78
75
  ...(input.payerDestinationUrl !== undefined
@@ -84,13 +81,19 @@ export class ProxySessionsResource {
84
81
  requestId: input.requestId,
85
82
  });
86
83
  const session = toProxySessionHandoff(response);
84
+ if (!session.handoffUrl &&
85
+ !payHost &&
86
+ this.httpClient.apiHost !== "https://api.proxycheckout.com") {
87
+ throw new Error("Proxy Checkout sessions.createHandoff requires a payHost option or input field when apiHost is overridden and the API response does not include handoff_url.");
88
+ }
87
89
  return {
88
90
  ...session,
89
- handoffUrl: buildHandoffUrl({
90
- payHost,
91
- proxySessionId: session.id,
92
- publishableKey,
93
- }),
91
+ handoffUrl: session.handoffUrl ||
92
+ buildHandoffUrl({
93
+ payHost,
94
+ proxySessionId: session.id,
95
+ publishableKey,
96
+ }),
94
97
  };
95
98
  }
96
99
  async retrieve(proxySessionId, options = {}) {
@@ -234,7 +237,11 @@ function toProxySessionHandoff(response) {
234
237
  const integrationMode = requireString(body.integration_mode, "sessions.createHandoff.integrationMode");
235
238
  return {
236
239
  expiresAt: requireString(body.expires_at, "sessions.createHandoff.expiresAt"),
237
- handoffUrl: "",
240
+ handoffUrl: typeof body.handoff_url === "string"
241
+ ? body.handoff_url
242
+ : typeof body.handoffUrl === "string"
243
+ ? body.handoffUrl
244
+ : "",
238
245
  id: requireString(body.id, "sessions.createHandoff.id"),
239
246
  integrationMode,
240
247
  status,
@@ -1,3 +1,3 @@
1
1
  export declare const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
2
- export declare const proxyCheckoutServerSdkVersion = "0.0.6";
3
- export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.6";
2
+ export declare const proxyCheckoutServerSdkVersion = "0.0.7";
3
+ export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.7";
@@ -1,3 +1,3 @@
1
1
  export const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
2
- export const proxyCheckoutServerSdkVersion = "0.0.6";
2
+ export const proxyCheckoutServerSdkVersion = "0.0.7";
3
3
  export const proxyCheckoutServerSdkUserAgent = `${proxyCheckoutServerSdkName}/${proxyCheckoutServerSdkVersion}`;
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "sideEffects": false,
8
8
  "type": "module",
9
9
  "types": "./dist/esm/index.d.ts",
10
- "version": "0.0.6",
10
+ "version": "0.0.7",
11
11
  "devDependencies": {
12
12
  "@types/node": "^24.12.4",
13
13
  "@vitest/coverage-v8": "4.1.7",
@@ -48,6 +48,7 @@
48
48
  "scripts": {
49
49
  "build": "node ../../scripts/sdk/build-dual-package.mjs",
50
50
  "test:all": "vitest run",
51
+ "test:ci": "pnpm run test:coverage",
51
52
  "test:coverage": "vitest run --coverage.enabled --coverage.reportsDirectory=coverage/all",
52
53
  "test:coverage:changed": "vitest run --coverage.enabled --coverage.reportsDirectory=coverage/changed",
53
54
  "test:coverage:integration": "vitest run --project integration --coverage.enabled --coverage.reportsDirectory=coverage/integration",