@proxy-checkout/stripe-server-js 0.0.0-pr-76.31.1 → 0.0.0-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/README.md CHANGED
@@ -35,7 +35,7 @@ const checkout = await openCheckout({
35
35
  buildCheckoutSessionParams: ({ cart, offer }) => ({
36
36
  ...buildMerchantStripeParams(cart, offer),
37
37
  mode: "subscription",
38
- ui_mode: "embedded",
38
+ ui_mode: "custom",
39
39
  }),
40
40
  });
41
41
  // checkout.clientSecret -> render Stripe Elements
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Adapter-specific error raised when a Stripe/Proxy cart synchronization cannot
3
+ * complete cleanly. The `reconciled` flag is true only when the SDK verified the
4
+ * Proxy and Stripe carts are back in a consistent state.
5
+ */
6
+ export type ProxyStripeCartSyncCode = "reconciliation_failed" | "stripe_update_failed";
7
+ export type ProxyStripeOpenCheckoutCode = "provider_binding_failed";
8
+ /**
9
+ * Raised after Stripe Checkout creation succeeds but the Proxy binding cannot
10
+ * be recorded or reconciled. The provider id is exposed so operators can find
11
+ * and expire/refund the orphaned provider object deterministically.
12
+ */
13
+ export declare class ProxyStripeOpenCheckoutError extends Error {
14
+ readonly name = "ProxyStripeOpenCheckoutError";
15
+ readonly code: ProxyStripeOpenCheckoutCode;
16
+ readonly cause: unknown;
17
+ readonly providerCheckoutSessionId: string;
18
+ readonly reconciled = false;
19
+ constructor(message: string, details: {
20
+ cause: unknown;
21
+ code: ProxyStripeOpenCheckoutCode;
22
+ providerCheckoutSessionId: string;
23
+ });
24
+ }
25
+ export declare class ProxyStripeCartSyncError extends Error {
26
+ readonly name = "ProxyStripeCartSyncError";
27
+ readonly code: ProxyStripeCartSyncCode;
28
+ /** True only when the SDK verified Proxy and Stripe are in a consistent state. */
29
+ readonly reconciled: boolean;
30
+ readonly cause: unknown;
31
+ readonly rollbackCause: unknown;
32
+ constructor(message: string, details: {
33
+ code: ProxyStripeCartSyncCode;
34
+ reconciled: boolean;
35
+ cause: unknown;
36
+ rollbackCause?: unknown;
37
+ });
38
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Adapter-specific error raised when a Stripe/Proxy cart synchronization cannot
3
+ * complete cleanly. The `reconciled` flag is true only when the SDK verified the
4
+ * Proxy and Stripe carts are back in a consistent state.
5
+ */
6
+ export type ProxyStripeCartSyncCode = "reconciliation_failed" | "stripe_update_failed";
7
+ export type ProxyStripeOpenCheckoutCode = "provider_binding_failed";
8
+ /**
9
+ * Raised after Stripe Checkout creation succeeds but the Proxy binding cannot
10
+ * be recorded or reconciled. The provider id is exposed so operators can find
11
+ * and expire/refund the orphaned provider object deterministically.
12
+ */
13
+ export declare class ProxyStripeOpenCheckoutError extends Error {
14
+ readonly name = "ProxyStripeOpenCheckoutError";
15
+ readonly code: ProxyStripeOpenCheckoutCode;
16
+ readonly cause: unknown;
17
+ readonly providerCheckoutSessionId: string;
18
+ readonly reconciled = false;
19
+ constructor(message: string, details: {
20
+ cause: unknown;
21
+ code: ProxyStripeOpenCheckoutCode;
22
+ providerCheckoutSessionId: string;
23
+ });
24
+ }
25
+ export declare class ProxyStripeCartSyncError extends Error {
26
+ readonly name = "ProxyStripeCartSyncError";
27
+ readonly code: ProxyStripeCartSyncCode;
28
+ /** True only when the SDK verified Proxy and Stripe are in a consistent state. */
29
+ readonly reconciled: boolean;
30
+ readonly cause: unknown;
31
+ readonly rollbackCause: unknown;
32
+ constructor(message: string, details: {
33
+ code: ProxyStripeCartSyncCode;
34
+ reconciled: boolean;
35
+ cause: unknown;
36
+ rollbackCause?: unknown;
37
+ });
38
+ }
@@ -0,0 +1,7 @@
1
+ export { type ProxyStripeCartSyncCode, ProxyStripeCartSyncError, type ProxyStripeOpenCheckoutCode, ProxyStripeOpenCheckoutError, } from "./errors.js";
2
+ export { assertCheckoutSessionBelongsToProxy, assertPaymentIntentBelongsToProxy, assertSubscriptionBelongsToProxy, injectRequiredCheckoutSessionMetadata, PROXY_SESSION_METADATA_KEY, type ProxySessionMetadata, type ProxyStripeRequiredMetadata, requiredMetadata, } from "./metadata.js";
3
+ export { type OpenCheckoutOptions, type OpenCheckoutReconciledCart, type OpenCheckoutResult, openCheckout, } from "./open-checkout.js";
4
+ export { normalizePsp } from "./psp.js";
5
+ export { type SyncCheckoutCartOptions, type SyncCheckoutCartResult, type SyncedCart, syncCheckoutCart, } from "./sync-checkout-cart.js";
6
+ export type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripeCheckoutSessionsApiLike, StripeCheckoutSessionUpdateParams, StripeClientLike, StripeMetadata, StripePaymentIntentLike, StripeRequestOptionsLike, StripeSubscriptionLike, } from "./types.js";
7
+ export { proxyCheckoutStripeServerSdkName, proxyCheckoutStripeServerSdkVersion, } from "./version.js";
@@ -0,0 +1,7 @@
1
+ export { type ProxyStripeCartSyncCode, ProxyStripeCartSyncError, type ProxyStripeOpenCheckoutCode, ProxyStripeOpenCheckoutError, } from "./errors.js";
2
+ export { assertCheckoutSessionBelongsToProxy, assertPaymentIntentBelongsToProxy, assertSubscriptionBelongsToProxy, injectRequiredCheckoutSessionMetadata, PROXY_SESSION_METADATA_KEY, type ProxySessionMetadata, type ProxyStripeRequiredMetadata, requiredMetadata, } from "./metadata.js";
3
+ export { type OpenCheckoutOptions, type OpenCheckoutReconciledCart, type OpenCheckoutResult, openCheckout, } from "./open-checkout.js";
4
+ export { normalizePsp } from "./psp.js";
5
+ export { type SyncCheckoutCartOptions, type SyncCheckoutCartResult, type SyncedCart, syncCheckoutCart, } from "./sync-checkout-cart.js";
6
+ export type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripeCheckoutSessionsApiLike, StripeCheckoutSessionUpdateParams, StripeClientLike, StripeMetadata, StripePaymentIntentLike, StripeRequestOptionsLike, StripeSubscriptionLike, } from "./types.js";
7
+ export { proxyCheckoutStripeServerSdkName, proxyCheckoutStripeServerSdkVersion, } from "./version.js";
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Required Stripe metadata placement + provider-object ownership assertions.
3
+ *
4
+ * Proxy correlates Stripe objects to a session solely through
5
+ * `metadata.proxy_session_id`. This module centralizes that placement so
6
+ * customers never have to remember which Stripe objects need the key, and
7
+ * provides assertions that a Stripe object actually belongs to a Proxy session.
8
+ */
9
+ import type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripePaymentIntentLike, StripeSubscriptionLike } from "./types.js";
10
+ /** The single metadata key Proxy reads to correlate a Stripe object to a session. */
11
+ export declare const PROXY_SESSION_METADATA_KEY = "proxy_session_id";
12
+ export type ProxySessionMetadata = Readonly<Record<"proxy_session_id", string>>;
13
+ /**
14
+ * The metadata each Stripe object must carry, ready to spread into Stripe params.
15
+ *
16
+ * - `checkoutSession` → `metadata` on `checkout.sessions.create`
17
+ * - `subscriptionData` → `subscription_data` for subscription-mode Checkout
18
+ * - `paymentIntentData` → `payment_intent_data` for payment-mode Checkout / PaymentIntents
19
+ */
20
+ export interface ProxyStripeRequiredMetadata {
21
+ readonly checkoutSession: ProxySessionMetadata;
22
+ readonly paymentIntent: ProxySessionMetadata;
23
+ readonly paymentIntentData: {
24
+ readonly metadata: ProxySessionMetadata;
25
+ };
26
+ readonly subscription: ProxySessionMetadata;
27
+ readonly subscriptionData: {
28
+ readonly metadata: ProxySessionMetadata;
29
+ };
30
+ }
31
+ /** Build the required Stripe metadata placements for a Proxy session. */
32
+ export declare function requiredMetadata(proxySession: {
33
+ id: string;
34
+ }): ProxyStripeRequiredMetadata;
35
+ /**
36
+ * Return Stripe Checkout Session create params with required Proxy metadata in
37
+ * every object Proxy may later need to correlate. Conflicting merchant-provided
38
+ * proxy metadata fails before any Stripe side effect.
39
+ */
40
+ export declare function injectRequiredCheckoutSessionMetadata(params: StripeCheckoutSessionCreateParams, proxySessionId: string): StripeCheckoutSessionCreateParams;
41
+ /** Assert a Stripe Checkout Session carries the expected `proxy_session_id` metadata. */
42
+ export declare function assertCheckoutSessionBelongsToProxy(checkoutSession: Pick<StripeCheckoutSessionLike, "metadata">, proxySessionId: string): void;
43
+ /** Assert a Stripe Subscription carries the expected `proxy_session_id` metadata. */
44
+ export declare function assertSubscriptionBelongsToProxy(subscription: Pick<StripeSubscriptionLike, "metadata">, proxySessionId: string): void;
45
+ /** Assert a Stripe PaymentIntent carries the expected `proxy_session_id` metadata. */
46
+ export declare function assertPaymentIntentBelongsToProxy(paymentIntent: Pick<StripePaymentIntentLike, "metadata">, proxySessionId: string): void;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Required Stripe metadata placement + provider-object ownership assertions.
3
+ *
4
+ * Proxy correlates Stripe objects to a session solely through
5
+ * `metadata.proxy_session_id`. This module centralizes that placement so
6
+ * customers never have to remember which Stripe objects need the key, and
7
+ * provides assertions that a Stripe object actually belongs to a Proxy session.
8
+ */
9
+ import type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripePaymentIntentLike, StripeSubscriptionLike } from "./types.js";
10
+ /** The single metadata key Proxy reads to correlate a Stripe object to a session. */
11
+ export declare const PROXY_SESSION_METADATA_KEY = "proxy_session_id";
12
+ export type ProxySessionMetadata = Readonly<Record<"proxy_session_id", string>>;
13
+ /**
14
+ * The metadata each Stripe object must carry, ready to spread into Stripe params.
15
+ *
16
+ * - `checkoutSession` → `metadata` on `checkout.sessions.create`
17
+ * - `subscriptionData` → `subscription_data` for subscription-mode Checkout
18
+ * - `paymentIntentData` → `payment_intent_data` for payment-mode Checkout / PaymentIntents
19
+ */
20
+ export interface ProxyStripeRequiredMetadata {
21
+ readonly checkoutSession: ProxySessionMetadata;
22
+ readonly paymentIntent: ProxySessionMetadata;
23
+ readonly paymentIntentData: {
24
+ readonly metadata: ProxySessionMetadata;
25
+ };
26
+ readonly subscription: ProxySessionMetadata;
27
+ readonly subscriptionData: {
28
+ readonly metadata: ProxySessionMetadata;
29
+ };
30
+ }
31
+ /** Build the required Stripe metadata placements for a Proxy session. */
32
+ export declare function requiredMetadata(proxySession: {
33
+ id: string;
34
+ }): ProxyStripeRequiredMetadata;
35
+ /**
36
+ * Return Stripe Checkout Session create params with required Proxy metadata in
37
+ * every object Proxy may later need to correlate. Conflicting merchant-provided
38
+ * proxy metadata fails before any Stripe side effect.
39
+ */
40
+ export declare function injectRequiredCheckoutSessionMetadata(params: StripeCheckoutSessionCreateParams, proxySessionId: string): StripeCheckoutSessionCreateParams;
41
+ /** Assert a Stripe Checkout Session carries the expected `proxy_session_id` metadata. */
42
+ export declare function assertCheckoutSessionBelongsToProxy(checkoutSession: Pick<StripeCheckoutSessionLike, "metadata">, proxySessionId: string): void;
43
+ /** Assert a Stripe Subscription carries the expected `proxy_session_id` metadata. */
44
+ export declare function assertSubscriptionBelongsToProxy(subscription: Pick<StripeSubscriptionLike, "metadata">, proxySessionId: string): void;
45
+ /** Assert a Stripe PaymentIntent carries the expected `proxy_session_id` metadata. */
46
+ export declare function assertPaymentIntentBelongsToProxy(paymentIntent: Pick<StripePaymentIntentLike, "metadata">, proxySessionId: string): void;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * `openCheckout` — the payer-opened + provider-object creation workflow.
3
+ *
4
+ * It performs the Proxy protocol steps (record payer-opened, validate the cart,
5
+ * inject required metadata, create the Stripe Checkout Session, record the
6
+ * provider binding). Merchants provide only Stripe params, so the adapter owns
7
+ * metadata placement, idempotency, and binding reconciliation.
8
+ */
9
+ import type { JsonObject, PayerOpenedResult, ProxyCartValidator, ProxyCheckoutServerClient, ProxySessionProviderBinding } from "@proxy-checkout/server-js";
10
+ import type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripeClientLike, StripeRequestOptionsWithoutIdempotencyLike } from "./types.js";
11
+ export interface OpenCheckoutOptions<TStripe extends StripeClientLike, TCart, TOffer> {
12
+ /** Builds app-specific Stripe Checkout Session params. Proxy metadata is injected by the SDK. */
13
+ readonly buildCheckoutSessionParams: (input: {
14
+ cart: TCart;
15
+ offer: TOffer;
16
+ proxySession: PayerOpenedResult;
17
+ stripe: TStripe;
18
+ }) => Promise<StripeCheckoutSessionCreateParams> | StripeCheckoutSessionCreateParams;
19
+ /** Optional schema validating the session cart snapshot into a typed cart. */
20
+ readonly cartSchema?: ProxyCartValidator<TCart>;
21
+ /** Optional extractor used to assert the cart buyer reference matches the session. */
22
+ readonly getCartBuyerReference?: (cart: TCart) => string | null | undefined;
23
+ /** A Proxy server SDK client. */
24
+ readonly proxy: ProxyCheckoutServerClient;
25
+ readonly proxySessionId: string;
26
+ /** Provider identifier recorded with the binding. Defaults to "stripe". */
27
+ readonly psp?: string;
28
+ /** Optional cart reconciliation before Stripe creation. The SDK performs the versioned Proxy cart write. */
29
+ readonly reconcileCart?: (input: {
30
+ cart: TCart;
31
+ offer: TOffer;
32
+ session: PayerOpenedResult;
33
+ }) => OpenCheckoutReconciledCart<TCart> | Promise<OpenCheckoutReconciledCart<TCart>> | null | undefined;
34
+ readonly requestId?: string;
35
+ /** The merchant's Stripe instance. */
36
+ readonly stripe: TStripe;
37
+ /** Optional Stripe request options. The SDK owns the deterministic idempotency key. */
38
+ readonly stripeRequestOptions?: StripeRequestOptionsWithoutIdempotencyLike;
39
+ /** Optional merchant cart validation that derives an app-specific offer. */
40
+ readonly validateCart?: (input: {
41
+ cart: TCart;
42
+ session: PayerOpenedResult;
43
+ }) => Promise<TOffer> | TOffer;
44
+ }
45
+ export interface OpenCheckoutReconciledCart<TCart> {
46
+ readonly amountMinor: number;
47
+ readonly cart: TCart;
48
+ readonly cartSnapshot: JsonObject;
49
+ readonly currency: string;
50
+ }
51
+ export interface OpenCheckoutResult<TCart, TOffer, TSession> {
52
+ readonly binding: ProxySessionProviderBinding;
53
+ readonly cart: TCart;
54
+ readonly checkoutSession: TSession;
55
+ readonly clientSecret: string | null;
56
+ readonly offer: TOffer;
57
+ readonly proxySession: PayerOpenedResult;
58
+ readonly proxySessionId: string;
59
+ }
60
+ export declare function openCheckout<TStripe extends StripeClientLike, TCart = unknown, TOffer = undefined, TSession extends StripeCheckoutSessionLike = StripeCheckoutSessionLike>(options: OpenCheckoutOptions<TStripe, TCart, TOffer>): Promise<OpenCheckoutResult<TCart, TOffer, TSession>>;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * `openCheckout` — the payer-opened + provider-object creation workflow.
3
+ *
4
+ * It performs the Proxy protocol steps (record payer-opened, validate the cart,
5
+ * inject required metadata, create the Stripe Checkout Session, record the
6
+ * provider binding). Merchants provide only Stripe params, so the adapter owns
7
+ * metadata placement, idempotency, and binding reconciliation.
8
+ */
9
+ import type { JsonObject, PayerOpenedResult, ProxyCartValidator, ProxyCheckoutServerClient, ProxySessionProviderBinding } from "@proxy-checkout/server-js";
10
+ import type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripeClientLike, StripeRequestOptionsWithoutIdempotencyLike } from "./types.js";
11
+ export interface OpenCheckoutOptions<TStripe extends StripeClientLike, TCart, TOffer> {
12
+ /** Builds app-specific Stripe Checkout Session params. Proxy metadata is injected by the SDK. */
13
+ readonly buildCheckoutSessionParams: (input: {
14
+ cart: TCart;
15
+ offer: TOffer;
16
+ proxySession: PayerOpenedResult;
17
+ stripe: TStripe;
18
+ }) => Promise<StripeCheckoutSessionCreateParams> | StripeCheckoutSessionCreateParams;
19
+ /** Optional schema validating the session cart snapshot into a typed cart. */
20
+ readonly cartSchema?: ProxyCartValidator<TCart>;
21
+ /** Optional extractor used to assert the cart buyer reference matches the session. */
22
+ readonly getCartBuyerReference?: (cart: TCart) => string | null | undefined;
23
+ /** A Proxy server SDK client. */
24
+ readonly proxy: ProxyCheckoutServerClient;
25
+ readonly proxySessionId: string;
26
+ /** Provider identifier recorded with the binding. Defaults to "stripe". */
27
+ readonly psp?: string;
28
+ /** Optional cart reconciliation before Stripe creation. The SDK performs the versioned Proxy cart write. */
29
+ readonly reconcileCart?: (input: {
30
+ cart: TCart;
31
+ offer: TOffer;
32
+ session: PayerOpenedResult;
33
+ }) => OpenCheckoutReconciledCart<TCart> | Promise<OpenCheckoutReconciledCart<TCart>> | null | undefined;
34
+ readonly requestId?: string;
35
+ /** The merchant's Stripe instance. */
36
+ readonly stripe: TStripe;
37
+ /** Optional Stripe request options. The SDK owns the deterministic idempotency key. */
38
+ readonly stripeRequestOptions?: StripeRequestOptionsWithoutIdempotencyLike;
39
+ /** Optional merchant cart validation that derives an app-specific offer. */
40
+ readonly validateCart?: (input: {
41
+ cart: TCart;
42
+ session: PayerOpenedResult;
43
+ }) => Promise<TOffer> | TOffer;
44
+ }
45
+ export interface OpenCheckoutReconciledCart<TCart> {
46
+ readonly amountMinor: number;
47
+ readonly cart: TCart;
48
+ readonly cartSnapshot: JsonObject;
49
+ readonly currency: string;
50
+ }
51
+ export interface OpenCheckoutResult<TCart, TOffer, TSession> {
52
+ readonly binding: ProxySessionProviderBinding;
53
+ readonly cart: TCart;
54
+ readonly checkoutSession: TSession;
55
+ readonly clientSecret: string | null;
56
+ readonly offer: TOffer;
57
+ readonly proxySession: PayerOpenedResult;
58
+ readonly proxySessionId: string;
59
+ }
60
+ export declare function openCheckout<TStripe extends StripeClientLike, TCart = unknown, TOffer = undefined, TSession extends StripeCheckoutSessionLike = StripeCheckoutSessionLike>(options: OpenCheckoutOptions<TStripe, TCart, TOffer>): Promise<OpenCheckoutResult<TCart, TOffer, TSession>>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Provider (psp) identifier normalization, kept in lockstep with the Proxy API.
3
+ *
4
+ * The API normalizes the psp before persisting a provider binding
5
+ * (`psp.trim().toLowerCase()`), then compares stored bindings against that
6
+ * normalized value. The SDK must normalize identically before recording or
7
+ * validating a binding so a caller passing the same psp with different
8
+ * casing/whitespace for `openCheckout` vs `syncCheckoutCart` does not get a
9
+ * false `provider_binding_mismatch`.
10
+ */
11
+ /** Normalize and validate a psp identifier exactly as the Proxy API does before storing/comparing a binding. */
12
+ export declare function normalizePsp(psp: string): string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Provider (psp) identifier normalization, kept in lockstep with the Proxy API.
3
+ *
4
+ * The API normalizes the psp before persisting a provider binding
5
+ * (`psp.trim().toLowerCase()`), then compares stored bindings against that
6
+ * normalized value. The SDK must normalize identically before recording or
7
+ * validating a binding so a caller passing the same psp with different
8
+ * casing/whitespace for `openCheckout` vs `syncCheckoutCart` does not get a
9
+ * false `provider_binding_mismatch`.
10
+ */
11
+ /** Normalize and validate a psp identifier exactly as the Proxy API does before storing/comparing a binding. */
12
+ export declare function normalizePsp(psp: string): string;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * `syncCheckoutCart` — coordinated Proxy + Stripe cart update.
3
+ *
4
+ * Validates ownership against the first-class Proxy provider binding (not just
5
+ * Stripe metadata), then updates the Proxy cart and the Stripe checkout in the
6
+ * safest order with deterministic rollback/reconciliation on failure.
7
+ */
8
+ import { type JsonObject, type MerchantProxySession, type ProxyCartValidator, type ProxyCheckoutServerClient } from "@proxy-checkout/server-js";
9
+ import type { StripeCheckoutSessionLike, StripeClientLike, StripeRequestOptionsWithoutIdempotencyLike } from "./types.js";
10
+ /** The next cart, expressed both as Proxy state and the typed merchant cart. */
11
+ export interface SyncedCart<TCart> {
12
+ readonly amountMinor: number;
13
+ readonly cart: TCart;
14
+ readonly cartSnapshot: JsonObject;
15
+ readonly currency: string;
16
+ }
17
+ export interface SyncCheckoutCartOptions<TStripe extends StripeClientLike, TCart, TInput> {
18
+ /** Compute the next cart from current state and the merchant input. */
19
+ readonly buildNextCart: (input: {
20
+ currentCart: TCart;
21
+ currentSession: MerchantProxySession;
22
+ input: TInput;
23
+ }) => Promise<SyncedCart<TCart>> | SyncedCart<TCart>;
24
+ /** Derive the Stripe `line_items` update from the next typed cart. */
25
+ readonly buildStripeLineItems: (cart: TCart) => unknown;
26
+ /** Optional schema validating the current cart snapshot into a typed cart. */
27
+ readonly cartSchema?: ProxyCartValidator<TCart>;
28
+ readonly checkoutSessionId: string;
29
+ /** Merchant-supplied change request (e.g. new interval/quantity). */
30
+ readonly input: TInput;
31
+ readonly proxy: ProxyCheckoutServerClient;
32
+ readonly proxySessionId: string;
33
+ /** Provider identifier the session must be bound under. Defaults to "stripe". */
34
+ readonly psp?: string;
35
+ readonly requestId?: string;
36
+ readonly stripe: TStripe;
37
+ /** Optional Stripe request options, e.g. Stripe Connect account scoping. */
38
+ readonly stripeRequestOptions?: StripeRequestOptionsWithoutIdempotencyLike;
39
+ }
40
+ export interface SyncCheckoutCartResult<TCart> {
41
+ readonly amountMinor: number;
42
+ readonly cart: TCart;
43
+ readonly cartSnapshot: JsonObject;
44
+ readonly checkoutSession: StripeCheckoutSessionLike;
45
+ readonly currency: string;
46
+ }
47
+ export declare function syncCheckoutCart<TStripe extends StripeClientLike, TCart, TInput>(options: SyncCheckoutCartOptions<TStripe, TCart, TInput>): Promise<SyncCheckoutCartResult<TCart>>;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * `syncCheckoutCart` — coordinated Proxy + Stripe cart update.
3
+ *
4
+ * Validates ownership against the first-class Proxy provider binding (not just
5
+ * Stripe metadata), then updates the Proxy cart and the Stripe checkout in the
6
+ * safest order with deterministic rollback/reconciliation on failure.
7
+ */
8
+ import { type JsonObject, type MerchantProxySession, type ProxyCartValidator, type ProxyCheckoutServerClient } from "@proxy-checkout/server-js";
9
+ import type { StripeCheckoutSessionLike, StripeClientLike, StripeRequestOptionsWithoutIdempotencyLike } from "./types.js";
10
+ /** The next cart, expressed both as Proxy state and the typed merchant cart. */
11
+ export interface SyncedCart<TCart> {
12
+ readonly amountMinor: number;
13
+ readonly cart: TCart;
14
+ readonly cartSnapshot: JsonObject;
15
+ readonly currency: string;
16
+ }
17
+ export interface SyncCheckoutCartOptions<TStripe extends StripeClientLike, TCart, TInput> {
18
+ /** Compute the next cart from current state and the merchant input. */
19
+ readonly buildNextCart: (input: {
20
+ currentCart: TCart;
21
+ currentSession: MerchantProxySession;
22
+ input: TInput;
23
+ }) => Promise<SyncedCart<TCart>> | SyncedCart<TCart>;
24
+ /** Derive the Stripe `line_items` update from the next typed cart. */
25
+ readonly buildStripeLineItems: (cart: TCart) => unknown;
26
+ /** Optional schema validating the current cart snapshot into a typed cart. */
27
+ readonly cartSchema?: ProxyCartValidator<TCart>;
28
+ readonly checkoutSessionId: string;
29
+ /** Merchant-supplied change request (e.g. new interval/quantity). */
30
+ readonly input: TInput;
31
+ readonly proxy: ProxyCheckoutServerClient;
32
+ readonly proxySessionId: string;
33
+ /** Provider identifier the session must be bound under. Defaults to "stripe". */
34
+ readonly psp?: string;
35
+ readonly requestId?: string;
36
+ readonly stripe: TStripe;
37
+ /** Optional Stripe request options, e.g. Stripe Connect account scoping. */
38
+ readonly stripeRequestOptions?: StripeRequestOptionsWithoutIdempotencyLike;
39
+ }
40
+ export interface SyncCheckoutCartResult<TCart> {
41
+ readonly amountMinor: number;
42
+ readonly cart: TCart;
43
+ readonly cartSnapshot: JsonObject;
44
+ readonly checkoutSession: StripeCheckoutSessionLike;
45
+ readonly currency: string;
46
+ }
47
+ export declare function syncCheckoutCart<TStripe extends StripeClientLike, TCart, TInput>(options: SyncCheckoutCartOptions<TStripe, TCart, TInput>): Promise<SyncCheckoutCartResult<TCart>>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Minimal structural Stripe types.
3
+ *
4
+ * The adapter is dependency-free: merchants inject their own `Stripe` instance
5
+ * and objects, which are structurally compatible with these narrow interfaces.
6
+ * This avoids a runtime/build dependency on the `stripe` package while keeping
7
+ * the bits the adapter actually touches type-safe.
8
+ */
9
+ export type StripeMetadataValue = string | number | null;
10
+ export type StripeMetadata = Record<string, StripeMetadataValue> | null | undefined;
11
+ export type StripeMetadataParam = Record<string, StripeMetadataValue> | undefined;
12
+ export interface StripeCheckoutSessionLike {
13
+ readonly client_secret?: string | null;
14
+ readonly id: string;
15
+ readonly metadata?: StripeMetadata;
16
+ }
17
+ export interface StripeSubscriptionLike {
18
+ readonly id: string;
19
+ readonly metadata?: StripeMetadata;
20
+ }
21
+ export interface StripePaymentIntentLike {
22
+ readonly id: string;
23
+ readonly metadata?: StripeMetadata;
24
+ }
25
+ export interface StripeCheckoutSessionUpdateParams {
26
+ readonly line_items?: unknown;
27
+ readonly metadata?: StripeMetadataParam;
28
+ }
29
+ export type StripeCheckoutSessionCreateParams = object & {
30
+ readonly metadata?: StripeMetadataParam;
31
+ readonly mode?: "payment" | "setup" | "subscription";
32
+ readonly payment_intent_data?: unknown;
33
+ readonly subscription_data?: unknown;
34
+ };
35
+ export interface StripeRequestOptionsLike {
36
+ readonly idempotencyKey?: string;
37
+ readonly [key: string]: unknown;
38
+ }
39
+ export interface StripeRequestOptionsWithoutIdempotencyLike {
40
+ readonly idempotencyKey?: never;
41
+ readonly [key: string]: unknown;
42
+ }
43
+ export interface StripeCheckoutSessionsApiLike {
44
+ create(params: unknown, options?: unknown): Promise<StripeCheckoutSessionLike>;
45
+ retrieve(id: string, params?: unknown, options?: unknown): Promise<StripeCheckoutSessionLike>;
46
+ update(id: string, params: unknown, options?: unknown): Promise<StripeCheckoutSessionLike>;
47
+ }
48
+ export interface StripeClientLike {
49
+ readonly checkout: {
50
+ readonly sessions: StripeCheckoutSessionsApiLike;
51
+ };
52
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Minimal structural Stripe types.
3
+ *
4
+ * The adapter is dependency-free: merchants inject their own `Stripe` instance
5
+ * and objects, which are structurally compatible with these narrow interfaces.
6
+ * This avoids a runtime/build dependency on the `stripe` package while keeping
7
+ * the bits the adapter actually touches type-safe.
8
+ */
9
+ export type StripeMetadataValue = string | number | null;
10
+ export type StripeMetadata = Record<string, StripeMetadataValue> | null | undefined;
11
+ export type StripeMetadataParam = Record<string, StripeMetadataValue> | undefined;
12
+ export interface StripeCheckoutSessionLike {
13
+ readonly client_secret?: string | null;
14
+ readonly id: string;
15
+ readonly metadata?: StripeMetadata;
16
+ }
17
+ export interface StripeSubscriptionLike {
18
+ readonly id: string;
19
+ readonly metadata?: StripeMetadata;
20
+ }
21
+ export interface StripePaymentIntentLike {
22
+ readonly id: string;
23
+ readonly metadata?: StripeMetadata;
24
+ }
25
+ export interface StripeCheckoutSessionUpdateParams {
26
+ readonly line_items?: unknown;
27
+ readonly metadata?: StripeMetadataParam;
28
+ }
29
+ export type StripeCheckoutSessionCreateParams = object & {
30
+ readonly metadata?: StripeMetadataParam;
31
+ readonly mode?: "payment" | "setup" | "subscription";
32
+ readonly payment_intent_data?: unknown;
33
+ readonly subscription_data?: unknown;
34
+ };
35
+ export interface StripeRequestOptionsLike {
36
+ readonly idempotencyKey?: string;
37
+ readonly [key: string]: unknown;
38
+ }
39
+ export interface StripeRequestOptionsWithoutIdempotencyLike {
40
+ readonly idempotencyKey?: never;
41
+ readonly [key: string]: unknown;
42
+ }
43
+ export interface StripeCheckoutSessionsApiLike {
44
+ create(params: unknown, options?: unknown): Promise<StripeCheckoutSessionLike>;
45
+ retrieve(id: string, params?: unknown, options?: unknown): Promise<StripeCheckoutSessionLike>;
46
+ update(id: string, params: unknown, options?: unknown): Promise<StripeCheckoutSessionLike>;
47
+ }
48
+ export interface StripeClientLike {
49
+ readonly checkout: {
50
+ readonly sessions: StripeCheckoutSessionsApiLike;
51
+ };
52
+ }
@@ -0,0 +1,2 @@
1
+ export declare const proxyCheckoutStripeServerSdkName = "@proxy-checkout/stripe-server-js";
2
+ export declare const proxyCheckoutStripeServerSdkVersion = "0.0.0-pr-76.32.1";
@@ -0,0 +1,2 @@
1
+ export declare const proxyCheckoutStripeServerSdkName = "@proxy-checkout/stripe-server-js";
2
+ export declare const proxyCheckoutStripeServerSdkVersion = "0.0.0-pr-76.32.1";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.proxyCheckoutStripeServerSdkVersion = exports.proxyCheckoutStripeServerSdkName = void 0;
4
4
  exports.proxyCheckoutStripeServerSdkName = "@proxy-checkout/stripe-server-js";
5
- exports.proxyCheckoutStripeServerSdkVersion = "0.0.0-pr-76.31.1";
5
+ exports.proxyCheckoutStripeServerSdkVersion = "0.0.0-pr-76.32.1";
@@ -1,2 +1,2 @@
1
1
  export declare const proxyCheckoutStripeServerSdkName = "@proxy-checkout/stripe-server-js";
2
- export declare const proxyCheckoutStripeServerSdkVersion = "0.0.0-pr-76.31.1";
2
+ export declare const proxyCheckoutStripeServerSdkVersion = "0.0.0-pr-76.32.1";
@@ -1,2 +1,2 @@
1
1
  export const proxyCheckoutStripeServerSdkName = "@proxy-checkout/stripe-server-js";
2
- export const proxyCheckoutStripeServerSdkVersion = "0.0.0-pr-76.31.1";
2
+ export const proxyCheckoutStripeServerSdkVersion = "0.0.0-pr-76.32.1";
package/package.json CHANGED
@@ -7,20 +7,25 @@
7
7
  "sideEffects": false,
8
8
  "type": "module",
9
9
  "types": "./dist/esm/index.d.ts",
10
- "version": "0.0.0-pr-76.31.1",
10
+ "version": "0.0.0-pr-76.32.1",
11
11
  "devDependencies": {
12
12
  "@types/node": "^24.12.4",
13
13
  "@vitest/coverage-v8": "4.1.7",
14
14
  "stripe": "^21.0.1",
15
15
  "typescript": "^6.0.3",
16
16
  "vitest": "4.1.7",
17
- "@proxy-checkout/server-js": "0.0.4-pr-76.31.1"
17
+ "@proxy-checkout/server-js": "0.0.4-pr-76.32.1"
18
18
  },
19
19
  "exports": {
20
20
  ".": {
21
- "import": "./dist/esm/index.js",
22
- "require": "./dist/cjs/index.js",
23
- "types": "./dist/esm/index.d.ts"
21
+ "import": {
22
+ "default": "./dist/esm/index.js",
23
+ "types": "./dist/esm/index.d.ts"
24
+ },
25
+ "require": {
26
+ "default": "./dist/cjs/index.js",
27
+ "types": "./dist/cjs/index.d.cts"
28
+ }
24
29
  }
25
30
  },
26
31
  "files": [