@proxy-checkout/stripe-server-js 0.1.0-prx-146.162.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -113
- package/dist/cjs/errors.d.cts +1 -68
- package/dist/cjs/errors.d.ts +1 -68
- package/dist/cjs/errors.js +1 -86
- package/dist/cjs/index.d.cts +4 -10
- package/dist/cjs/index.d.ts +4 -10
- package/dist/cjs/index.js +1 -24
- package/dist/cjs/metadata.d.cts +2 -26
- package/dist/cjs/metadata.d.ts +2 -26
- package/dist/cjs/metadata.js +3 -73
- package/dist/cjs/open-checkout.d.cts +0 -21
- package/dist/cjs/open-checkout.d.ts +0 -21
- package/dist/cjs/open-checkout.js +38 -310
- package/dist/cjs/sync-checkout-cart.d.cts +3 -3
- package/dist/cjs/sync-checkout-cart.d.ts +3 -3
- package/dist/cjs/sync-checkout-cart.js +22 -92
- package/dist/cjs/types.d.cts +0 -199
- package/dist/cjs/types.d.ts +0 -199
- package/dist/cjs/version.d.cts +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/errors.d.ts +1 -68
- package/dist/esm/errors.js +0 -80
- package/dist/esm/index.d.ts +4 -10
- package/dist/esm/index.js +2 -7
- package/dist/esm/metadata.d.ts +2 -26
- package/dist/esm/metadata.js +2 -69
- package/dist/esm/open-checkout.d.ts +0 -21
- package/dist/esm/open-checkout.js +40 -312
- package/dist/esm/sync-checkout-cart.d.ts +3 -3
- package/dist/esm/sync-checkout-cart.js +23 -93
- package/dist/esm/types.d.ts +0 -199
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +3 -3
- package/dist/cjs/acquisition.d.cts +0 -189
- package/dist/cjs/acquisition.d.ts +0 -189
- package/dist/cjs/acquisition.js +0 -789
- package/dist/cjs/compatibility.d.cts +0 -66
- package/dist/cjs/compatibility.d.ts +0 -66
- package/dist/cjs/compatibility.js +0 -174
- package/dist/cjs/open-payment-intent.d.cts +0 -35
- package/dist/cjs/open-payment-intent.d.ts +0 -35
- package/dist/cjs/open-payment-intent.js +0 -157
- package/dist/cjs/open-setup-intent.d.cts +0 -49
- package/dist/cjs/open-setup-intent.d.ts +0 -49
- package/dist/cjs/open-setup-intent.js +0 -157
- package/dist/cjs/open-subscription.d.cts +0 -75
- package/dist/cjs/open-subscription.d.ts +0 -75
- package/dist/cjs/open-subscription.js +0 -307
- package/dist/cjs/subscription-params.d.cts +0 -33
- package/dist/cjs/subscription-params.d.ts +0 -33
- package/dist/cjs/subscription-params.js +0 -237
- package/dist/esm/acquisition.d.ts +0 -189
- package/dist/esm/acquisition.js +0 -763
- package/dist/esm/compatibility.d.ts +0 -66
- package/dist/esm/compatibility.js +0 -168
- package/dist/esm/open-payment-intent.d.ts +0 -35
- package/dist/esm/open-payment-intent.js +0 -154
- package/dist/esm/open-setup-intent.d.ts +0 -49
- package/dist/esm/open-setup-intent.js +0 -153
- package/dist/esm/open-subscription.d.ts +0 -75
- package/dist/esm/open-subscription.js +0 -304
- package/dist/esm/subscription-params.d.ts +0 -33
- package/dist/esm/subscription-params.js +0 -232
package/dist/esm/errors.d.ts
CHANGED
|
@@ -3,75 +3,8 @@
|
|
|
3
3
|
* complete cleanly. The `reconciled` flag is true only when the SDK verified the
|
|
4
4
|
* Proxy and Stripe carts are back in a consistent state.
|
|
5
5
|
*/
|
|
6
|
-
export type ProxyStripeCartSyncCode = "
|
|
6
|
+
export type ProxyStripeCartSyncCode = "reconciliation_failed" | "stripe_update_failed";
|
|
7
7
|
export type ProxyStripeOpenCheckoutCode = "provider_binding_failed";
|
|
8
|
-
export type ProxyStripeAcquisitionCode = "acquisition_mismatch" | "customer_payment_method_mismatch" | "fixed_price_mismatch" | "provider_attachment_failed" | "provider_cart_confirmation_failed" | "provider_create_ambiguous" | "provider_response_invalid" | "provider_retrieve_failed" | "setup_intent_not_succeeded" | "unsupported_provider_option";
|
|
9
|
-
/**
|
|
10
|
-
* A provider root may already exist when this error is raised. The bounded
|
|
11
|
-
* identifiers are intentionally retained so a merchant can retrieve the same
|
|
12
|
-
* object or let Proxy's known-object recovery inspect it; no Stripe secret or
|
|
13
|
-
* response body is captured.
|
|
14
|
-
*/
|
|
15
|
-
export declare class ProxyStripeAcquisitionError extends Error {
|
|
16
|
-
readonly name: string;
|
|
17
|
-
readonly acquisitionAttemptId: string | null;
|
|
18
|
-
readonly code: ProxyStripeAcquisitionCode;
|
|
19
|
-
readonly cause: unknown;
|
|
20
|
-
readonly field: string | undefined;
|
|
21
|
-
readonly providerObjectId: string | null;
|
|
22
|
-
readonly reconciled = false;
|
|
23
|
-
constructor(message: string, details: {
|
|
24
|
-
acquisitionAttemptId?: string;
|
|
25
|
-
cause?: unknown;
|
|
26
|
-
code: ProxyStripeAcquisitionCode;
|
|
27
|
-
field?: string;
|
|
28
|
-
providerObjectId?: string | null;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
export declare class ProxyMetadataConflictError extends ProxyStripeAcquisitionError {
|
|
32
|
-
readonly name = "ProxyMetadataConflictError";
|
|
33
|
-
constructor(field: string);
|
|
34
|
-
}
|
|
35
|
-
export type StripeCompatibilityPath = "one_time.checkout.custom" | "one_time.checkout.embedded" | "one_time.checkout.hosted" | "one_time.direct_payment_intent" | "subscription.direct_saved_payment_method" | "subscription.direct_setup_intent";
|
|
36
|
-
export declare class StripeCompatibilityError extends Error {
|
|
37
|
-
readonly name = "StripeCompatibilityError";
|
|
38
|
-
readonly code = "stripe_version_not_supported";
|
|
39
|
-
readonly detectedApiVersion: string | null;
|
|
40
|
-
readonly detectedBrowserSdkVersion: string | null;
|
|
41
|
-
readonly detectedReactSdkVersion: string | null;
|
|
42
|
-
readonly detectedServerSdkVersion: string | null;
|
|
43
|
-
readonly docsUrl: string;
|
|
44
|
-
readonly minimumApiVersion: string;
|
|
45
|
-
readonly minimumBrowserSdkVersion: string | null;
|
|
46
|
-
readonly minimumReactSdkVersion: string | null;
|
|
47
|
-
readonly minimumServerSdkVersion: string;
|
|
48
|
-
readonly path: StripeCompatibilityPath;
|
|
49
|
-
constructor(input: {
|
|
50
|
-
detectedApiVersion?: string;
|
|
51
|
-
detectedBrowserSdkVersion?: string;
|
|
52
|
-
detectedReactSdkVersion?: string;
|
|
53
|
-
detectedServerSdkVersion?: string;
|
|
54
|
-
docsUrl: string;
|
|
55
|
-
message: string;
|
|
56
|
-
minimumApiVersion: string;
|
|
57
|
-
minimumBrowserSdkVersion?: string;
|
|
58
|
-
minimumReactSdkVersion?: string;
|
|
59
|
-
minimumServerSdkVersion: string;
|
|
60
|
-
path: StripeCompatibilityPath;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
export declare class StripeResponseShapeError extends Error {
|
|
64
|
-
readonly name = "StripeResponseShapeError";
|
|
65
|
-
readonly code = "stripe_response_shape_invalid";
|
|
66
|
-
readonly field: string;
|
|
67
|
-
constructor(message: string, field: string);
|
|
68
|
-
}
|
|
69
|
-
export declare class UnsupportedStripeOptionError extends Error {
|
|
70
|
-
readonly name = "UnsupportedStripeOptionError";
|
|
71
|
-
readonly code = "unsupported_stripe_option";
|
|
72
|
-
readonly field: string;
|
|
73
|
-
constructor(messageOrField: string, field?: string);
|
|
74
|
-
}
|
|
75
8
|
/**
|
|
76
9
|
* Raised after Stripe Checkout creation succeeds but the Proxy binding cannot
|
|
77
10
|
* be recorded or reconciled. The provider id is exposed so operators can find
|
package/dist/esm/errors.js
CHANGED
|
@@ -1,83 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A provider root may already exist when this error is raised. The bounded
|
|
3
|
-
* identifiers are intentionally retained so a merchant can retrieve the same
|
|
4
|
-
* object or let Proxy's known-object recovery inspect it; no Stripe secret or
|
|
5
|
-
* response body is captured.
|
|
6
|
-
*/
|
|
7
|
-
export class ProxyStripeAcquisitionError extends Error {
|
|
8
|
-
name = "ProxyStripeAcquisitionError";
|
|
9
|
-
acquisitionAttemptId;
|
|
10
|
-
code;
|
|
11
|
-
cause;
|
|
12
|
-
field;
|
|
13
|
-
providerObjectId;
|
|
14
|
-
reconciled = false;
|
|
15
|
-
constructor(message, details) {
|
|
16
|
-
super(message);
|
|
17
|
-
this.acquisitionAttemptId = details.acquisitionAttemptId ?? null;
|
|
18
|
-
this.cause = details.cause;
|
|
19
|
-
this.code = details.code;
|
|
20
|
-
this.field = details.field;
|
|
21
|
-
this.providerObjectId = details.providerObjectId ?? null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export class ProxyMetadataConflictError extends ProxyStripeAcquisitionError {
|
|
25
|
-
name = "ProxyMetadataConflictError";
|
|
26
|
-
constructor(field) {
|
|
27
|
-
super(`Stripe ${field} conflicts with Proxy-required acquisition metadata.`, {
|
|
28
|
-
code: "acquisition_mismatch",
|
|
29
|
-
field,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export class StripeCompatibilityError extends Error {
|
|
34
|
-
name = "StripeCompatibilityError";
|
|
35
|
-
code = "stripe_version_not_supported";
|
|
36
|
-
detectedApiVersion;
|
|
37
|
-
detectedBrowserSdkVersion;
|
|
38
|
-
detectedReactSdkVersion;
|
|
39
|
-
detectedServerSdkVersion;
|
|
40
|
-
docsUrl;
|
|
41
|
-
minimumApiVersion;
|
|
42
|
-
minimumBrowserSdkVersion;
|
|
43
|
-
minimumReactSdkVersion;
|
|
44
|
-
minimumServerSdkVersion;
|
|
45
|
-
path;
|
|
46
|
-
constructor(input) {
|
|
47
|
-
super(input.message);
|
|
48
|
-
this.detectedApiVersion = input.detectedApiVersion ?? null;
|
|
49
|
-
this.detectedBrowserSdkVersion = input.detectedBrowserSdkVersion ?? null;
|
|
50
|
-
this.detectedReactSdkVersion = input.detectedReactSdkVersion ?? null;
|
|
51
|
-
this.detectedServerSdkVersion = input.detectedServerSdkVersion ?? null;
|
|
52
|
-
this.docsUrl = input.docsUrl;
|
|
53
|
-
this.minimumApiVersion = input.minimumApiVersion;
|
|
54
|
-
this.minimumBrowserSdkVersion = input.minimumBrowserSdkVersion ?? null;
|
|
55
|
-
this.minimumReactSdkVersion = input.minimumReactSdkVersion ?? null;
|
|
56
|
-
this.minimumServerSdkVersion = input.minimumServerSdkVersion;
|
|
57
|
-
this.path = input.path;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export class StripeResponseShapeError extends Error {
|
|
61
|
-
name = "StripeResponseShapeError";
|
|
62
|
-
code = "stripe_response_shape_invalid";
|
|
63
|
-
field;
|
|
64
|
-
constructor(message, field) {
|
|
65
|
-
super(message);
|
|
66
|
-
this.field = field;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
export class UnsupportedStripeOptionError extends Error {
|
|
70
|
-
name = "UnsupportedStripeOptionError";
|
|
71
|
-
code = "unsupported_stripe_option";
|
|
72
|
-
field;
|
|
73
|
-
constructor(messageOrField, field) {
|
|
74
|
-
const resolvedField = field ?? messageOrField;
|
|
75
|
-
super(field === undefined
|
|
76
|
-
? `Stripe option ${resolvedField} is not supported for direct subscriptions.`
|
|
77
|
-
: messageOrField);
|
|
78
|
-
this.field = resolvedField;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
1
|
/**
|
|
82
2
|
* Raised after Stripe Checkout creation succeeds but the Proxy binding cannot
|
|
83
3
|
* be recorded or reconciled. The provider id is exposed so operators can find
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export { assertCheckoutSessionBelongsToProxy, assertCheckoutSessionMetadataPreflight, assertPaymentIntentBelongsToProxy, assertProviderObjectBelongsToAcquisition, assertSubscriptionBelongsToProxy, injectRequiredCheckoutSessionMetadata, injectRequiredPaymentIntentMetadata, PROXY_ACQUISITION_ATTEMPT_METADATA_KEY, PROXY_CONTRACT_VERSION_METADATA_KEY, PROXY_INTEGRATION_PATH_METADATA_KEY, PROXY_SESSION_METADATA_KEY, type ProxySessionMetadata, type ProxyStripeRequiredMetadata, requiredMetadata, } from "./metadata.js";
|
|
5
|
-
export { type OpenCheckoutOptions, type OpenCheckoutPresentation, type OpenCheckoutReconciledCart, type OpenCheckoutResponse, type OpenCheckoutResult, type OpenCheckoutTerminalResult, openCheckout, } from "./open-checkout.js";
|
|
6
|
-
export { type OpenPaymentIntentOptions, type OpenPaymentIntentResponse, openPaymentIntent, type ReadyPaymentIntentResult, type SafePaymentIntentStatus, } from "./open-payment-intent.js";
|
|
7
|
-
export { type OpenSetupIntentBuilderInput, type OpenSetupIntentOptions, type OpenSetupIntentReadyResult, type OpenSetupIntentResponse, openSetupIntent, } from "./open-setup-intent.js";
|
|
8
|
-
export { type InitialInvoiceAction, type LegacyInitialInvoiceLike, type OpenSubscriptionBuilderInput, type OpenSubscriptionOptions, type OpenSubscriptionReadyResult, type OpenSubscriptionResponse, openSubscription, } from "./open-subscription.js";
|
|
1
|
+
export { type ProxyStripeCartSyncCode, ProxyStripeCartSyncError, type ProxyStripeOpenCheckoutCode, ProxyStripeOpenCheckoutError, } from "./errors.js";
|
|
2
|
+
export { assertCheckoutSessionBelongsToProxy, assertPaymentIntentBelongsToProxy, assertSubscriptionBelongsToProxy, injectRequiredCheckoutSessionMetadata, PROXY_INTEGRATION_PATH_METADATA_KEY, PROXY_SESSION_METADATA_KEY, type ProxySessionMetadata, type ProxyStripeRequiredMetadata, requiredMetadata, } from "./metadata.js";
|
|
3
|
+
export { type OpenCheckoutOptions, type OpenCheckoutReconciledCart, type OpenCheckoutResponse, type OpenCheckoutResult, type OpenCheckoutTerminalResult, openCheckout, } from "./open-checkout.js";
|
|
9
4
|
export { normalizePsp } from "./psp.js";
|
|
10
|
-
export type { ValidatedSubscriptionItem, ValidateFixedSubscriptionPrice, ValidateFixedSubscriptionPriceInput, VerifiedSubscriptionPriceItem, } from "./subscription-params.js";
|
|
11
5
|
export { type SyncCheckoutCartOptions, type SyncCheckoutCartResult, type SyncedCart, syncCheckoutCart, } from "./sync-checkout-cart.js";
|
|
12
|
-
export type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripeCheckoutSessionsApiLike, StripeCheckoutSessionUpdateParams, StripeClientLike,
|
|
6
|
+
export type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripeCheckoutSessionsApiLike, StripeCheckoutSessionUpdateParams, StripeClientLike, StripeMetadata, StripePaymentIntentLike, StripeRequestOptionsLike, StripeSubscriptionLike, } from "./types.js";
|
|
13
7
|
export { proxyCheckoutStripeServerSdkName, proxyCheckoutStripeServerSdkVersion, } from "./version.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { ProxyMetadataConflictError, ProxyStripeAcquisitionError, ProxyStripeCartSyncError, ProxyStripeOpenCheckoutError, StripeCompatibilityError, StripeResponseShapeError, UnsupportedStripeOptionError, } from "./errors.js";
|
|
4
|
-
export { assertCheckoutSessionBelongsToProxy, assertCheckoutSessionMetadataPreflight, assertPaymentIntentBelongsToProxy, assertProviderObjectBelongsToAcquisition, assertSubscriptionBelongsToProxy, injectRequiredCheckoutSessionMetadata, injectRequiredPaymentIntentMetadata, PROXY_ACQUISITION_ATTEMPT_METADATA_KEY, PROXY_CONTRACT_VERSION_METADATA_KEY, PROXY_INTEGRATION_PATH_METADATA_KEY, PROXY_SESSION_METADATA_KEY, requiredMetadata, } from "./metadata.js";
|
|
1
|
+
export { ProxyStripeCartSyncError, ProxyStripeOpenCheckoutError, } from "./errors.js";
|
|
2
|
+
export { assertCheckoutSessionBelongsToProxy, assertPaymentIntentBelongsToProxy, assertSubscriptionBelongsToProxy, injectRequiredCheckoutSessionMetadata, PROXY_INTEGRATION_PATH_METADATA_KEY, PROXY_SESSION_METADATA_KEY, requiredMetadata, } from "./metadata.js";
|
|
5
3
|
export { openCheckout, } from "./open-checkout.js";
|
|
6
|
-
export { openPaymentIntent, } from "./open-payment-intent.js";
|
|
7
|
-
export { openSetupIntent, } from "./open-setup-intent.js";
|
|
8
|
-
export { openSubscription, } from "./open-subscription.js";
|
|
9
4
|
export { normalizePsp } from "./psp.js";
|
|
10
5
|
export { syncCheckoutCart, } from "./sync-checkout-cart.js";
|
|
11
6
|
export { proxyCheckoutStripeServerSdkName, proxyCheckoutStripeServerSdkVersion, } from "./version.js";
|
package/dist/esm/metadata.d.ts
CHANGED
|
@@ -6,13 +6,11 @@
|
|
|
6
6
|
* customers never have to remember which Stripe objects need the key, and
|
|
7
7
|
* provides assertions that a Stripe object actually belongs to a Proxy session.
|
|
8
8
|
*/
|
|
9
|
-
import type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike,
|
|
9
|
+
import type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripePaymentIntentLike, StripeSubscriptionLike } from "./types.js";
|
|
10
10
|
/** The single metadata key Proxy reads to correlate a Stripe object to a session. */
|
|
11
11
|
export declare const PROXY_SESSION_METADATA_KEY = "proxy_session_id";
|
|
12
12
|
/** Server-owned marker that distinguishes Checkout-created child objects from direct objects. */
|
|
13
13
|
export declare const PROXY_INTEGRATION_PATH_METADATA_KEY = "proxy_integration_path";
|
|
14
|
-
export declare const PROXY_ACQUISITION_ATTEMPT_METADATA_KEY = "proxy_acquisition_attempt_id";
|
|
15
|
-
export declare const PROXY_CONTRACT_VERSION_METADATA_KEY = "proxy_contract_version";
|
|
16
14
|
export type ProxySessionMetadata = Readonly<Record<"proxy_session_id", string>>;
|
|
17
15
|
/**
|
|
18
16
|
* The metadata each Stripe object must carry, ready to spread into Stripe params.
|
|
@@ -41,32 +39,10 @@ export declare function requiredMetadata(proxySession: {
|
|
|
41
39
|
* every object Proxy may later need to correlate. Conflicting merchant-provided
|
|
42
40
|
* proxy metadata fails before any Stripe side effect.
|
|
43
41
|
*/
|
|
44
|
-
export declare function injectRequiredCheckoutSessionMetadata(params: StripeCheckoutSessionCreateParams, proxySessionId: string
|
|
45
|
-
id: string;
|
|
46
|
-
contractVersion: "2";
|
|
47
|
-
}): StripeCheckoutSessionCreateParams;
|
|
48
|
-
/**
|
|
49
|
-
* Validate merchant-authored Checkout metadata before reserving an acquisition.
|
|
50
|
-
* The acquisition ID does not exist yet, so those reservation-owned keys must
|
|
51
|
-
* be absent until the shared create owner injects their exact values.
|
|
52
|
-
*/
|
|
53
|
-
export declare function assertCheckoutSessionMetadataPreflight(params: StripeCheckoutSessionCreateParams, proxySessionId: string): void;
|
|
54
|
-
/** Inject the server-owned acquisition identity into a direct PaymentIntent. */
|
|
55
|
-
export declare function injectRequiredPaymentIntentMetadata(params: StripePaymentIntentCreateParams, input: {
|
|
56
|
-
acquisitionAttemptId: string;
|
|
57
|
-
proxySessionId: string;
|
|
58
|
-
}): StripePaymentIntentCreateParams;
|
|
42
|
+
export declare function injectRequiredCheckoutSessionMetadata(params: StripeCheckoutSessionCreateParams, proxySessionId: string): StripeCheckoutSessionCreateParams;
|
|
59
43
|
/** Assert a Stripe Checkout Session carries the expected `proxy_session_id` metadata. */
|
|
60
44
|
export declare function assertCheckoutSessionBelongsToProxy(checkoutSession: Pick<StripeCheckoutSessionLike, "metadata">, proxySessionId: string): void;
|
|
61
45
|
/** Assert a Stripe Subscription carries the expected `proxy_session_id` metadata. */
|
|
62
46
|
export declare function assertSubscriptionBelongsToProxy(subscription: Pick<StripeSubscriptionLike, "metadata">, proxySessionId: string): void;
|
|
63
47
|
/** Assert a Stripe PaymentIntent carries the expected `proxy_session_id` metadata. */
|
|
64
48
|
export declare function assertPaymentIntentBelongsToProxy(paymentIntent: Pick<StripePaymentIntentLike, "metadata">, proxySessionId: string): void;
|
|
65
|
-
/** Assert the provider root carries the exact reserved acquisition identity. */
|
|
66
|
-
export declare function assertProviderObjectBelongsToAcquisition(object: {
|
|
67
|
-
readonly metadata?: StripeMetadata;
|
|
68
|
-
}, input: {
|
|
69
|
-
acquisitionAttemptId: string;
|
|
70
|
-
integrationPath: string;
|
|
71
|
-
proxySessionId: string;
|
|
72
|
-
}): void;
|
package/dist/esm/metadata.js
CHANGED
|
@@ -11,8 +11,6 @@ import { ProxyCheckoutValidationError } from "@proxy-checkout/server-js";
|
|
|
11
11
|
export const PROXY_SESSION_METADATA_KEY = "proxy_session_id";
|
|
12
12
|
/** Server-owned marker that distinguishes Checkout-created child objects from direct objects. */
|
|
13
13
|
export const PROXY_INTEGRATION_PATH_METADATA_KEY = "proxy_integration_path";
|
|
14
|
-
export const PROXY_ACQUISITION_ATTEMPT_METADATA_KEY = "proxy_acquisition_attempt_id";
|
|
15
|
-
export const PROXY_CONTRACT_VERSION_METADATA_KEY = "proxy_contract_version";
|
|
16
14
|
/** Build the required Stripe metadata placements for a Proxy session. */
|
|
17
15
|
export function requiredMetadata(proxySession) {
|
|
18
16
|
const metadata = { proxy_session_id: proxySession.id };
|
|
@@ -29,8 +27,8 @@ export function requiredMetadata(proxySession) {
|
|
|
29
27
|
* every object Proxy may later need to correlate. Conflicting merchant-provided
|
|
30
28
|
* proxy metadata fails before any Stripe side effect.
|
|
31
29
|
*/
|
|
32
|
-
export function injectRequiredCheckoutSessionMetadata(params, proxySessionId
|
|
33
|
-
const metadata =
|
|
30
|
+
export function injectRequiredCheckoutSessionMetadata(params, proxySessionId) {
|
|
31
|
+
const metadata = { proxy_session_id: proxySessionId };
|
|
34
32
|
const checkoutMetadata = {
|
|
35
33
|
...metadata,
|
|
36
34
|
[PROXY_INTEGRATION_PATH_METADATA_KEY]: "checkout_session",
|
|
@@ -56,44 +54,6 @@ export function injectRequiredCheckoutSessionMetadata(params, proxySessionId, ac
|
|
|
56
54
|
: {}),
|
|
57
55
|
};
|
|
58
56
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Validate merchant-authored Checkout metadata before reserving an acquisition.
|
|
61
|
-
* The acquisition ID does not exist yet, so those reservation-owned keys must
|
|
62
|
-
* be absent until the shared create owner injects their exact values.
|
|
63
|
-
*/
|
|
64
|
-
export function assertCheckoutSessionMetadataPreflight(params, proxySessionId) {
|
|
65
|
-
for (const [field, metadata] of [
|
|
66
|
-
["metadata", params.metadata],
|
|
67
|
-
["payment_intent_data.metadata", metadataFromNestedParams(params.payment_intent_data)],
|
|
68
|
-
["subscription_data.metadata", metadataFromNestedParams(params.subscription_data)],
|
|
69
|
-
]) {
|
|
70
|
-
for (const key of [
|
|
71
|
-
PROXY_ACQUISITION_ATTEMPT_METADATA_KEY,
|
|
72
|
-
PROXY_CONTRACT_VERSION_METADATA_KEY,
|
|
73
|
-
]) {
|
|
74
|
-
if (metadata?.[key] !== undefined) {
|
|
75
|
-
throw new ProxyCheckoutValidationError(`Stripe ${field}.${key} is owned by the Proxy acquisition reservation and must not be supplied by the merchant.`, { code: "provider_binding_mismatch", field: `${field}.${key}` });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Pure construction performs every session/path conflict check without
|
|
80
|
-
// contacting Proxy or Stripe. The returned params are intentionally ignored;
|
|
81
|
-
// the reservation-derived injection still happens exactly once in create.
|
|
82
|
-
injectRequiredCheckoutSessionMetadata(params, proxySessionId);
|
|
83
|
-
}
|
|
84
|
-
/** Inject the server-owned acquisition identity into a direct PaymentIntent. */
|
|
85
|
-
export function injectRequiredPaymentIntentMetadata(params, input) {
|
|
86
|
-
const required = {
|
|
87
|
-
[PROXY_ACQUISITION_ATTEMPT_METADATA_KEY]: input.acquisitionAttemptId,
|
|
88
|
-
[PROXY_CONTRACT_VERSION_METADATA_KEY]: "2",
|
|
89
|
-
[PROXY_INTEGRATION_PATH_METADATA_KEY]: "payment_intent",
|
|
90
|
-
[PROXY_SESSION_METADATA_KEY]: input.proxySessionId,
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
...params,
|
|
94
|
-
metadata: mergeProxyMetadata(params.metadata, required, "metadata"),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
57
|
/** Assert a Stripe Checkout Session carries the expected `proxy_session_id` metadata. */
|
|
98
58
|
export function assertCheckoutSessionBelongsToProxy(checkoutSession, proxySessionId) {
|
|
99
59
|
assertProxyMetadata(checkoutSession.metadata, proxySessionId, "Stripe checkout session");
|
|
@@ -106,39 +66,12 @@ export function assertSubscriptionBelongsToProxy(subscription, proxySessionId) {
|
|
|
106
66
|
export function assertPaymentIntentBelongsToProxy(paymentIntent, proxySessionId) {
|
|
107
67
|
assertProxyMetadata(paymentIntent.metadata, proxySessionId, "Stripe payment intent");
|
|
108
68
|
}
|
|
109
|
-
/** Assert the provider root carries the exact reserved acquisition identity. */
|
|
110
|
-
export function assertProviderObjectBelongsToAcquisition(object, input) {
|
|
111
|
-
assertProxyMetadata(object.metadata, input.proxySessionId, "Stripe provider object");
|
|
112
|
-
const acquisitionId = object.metadata?.[PROXY_ACQUISITION_ATTEMPT_METADATA_KEY];
|
|
113
|
-
const contractVersion = object.metadata?.[PROXY_CONTRACT_VERSION_METADATA_KEY];
|
|
114
|
-
const integrationPath = object.metadata?.[PROXY_INTEGRATION_PATH_METADATA_KEY];
|
|
115
|
-
if (acquisitionId !== input.acquisitionAttemptId) {
|
|
116
|
-
throw new ProxyCheckoutValidationError(`Stripe provider object metadata.${PROXY_ACQUISITION_ATTEMPT_METADATA_KEY} does not match the reserved Proxy acquisition.`, { code: "provider_binding_mismatch", field: PROXY_ACQUISITION_ATTEMPT_METADATA_KEY });
|
|
117
|
-
}
|
|
118
|
-
if (contractVersion !== "2") {
|
|
119
|
-
throw new ProxyCheckoutValidationError(`Stripe provider object metadata.${PROXY_CONTRACT_VERSION_METADATA_KEY} must be 2.`, { code: "provider_binding_mismatch", field: PROXY_CONTRACT_VERSION_METADATA_KEY });
|
|
120
|
-
}
|
|
121
|
-
if (integrationPath !== input.integrationPath) {
|
|
122
|
-
throw new ProxyCheckoutValidationError(`Stripe provider object metadata.${PROXY_INTEGRATION_PATH_METADATA_KEY} does not match ${input.integrationPath}.`, { code: "provider_binding_mismatch", field: PROXY_INTEGRATION_PATH_METADATA_KEY });
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
69
|
function assertProxyMetadata(metadata, proxySessionId, objectLabel) {
|
|
126
70
|
const value = metadata?.[PROXY_SESSION_METADATA_KEY];
|
|
127
71
|
if (value !== proxySessionId) {
|
|
128
72
|
throw new ProxyCheckoutValidationError(`${objectLabel} metadata.${PROXY_SESSION_METADATA_KEY} (${value ?? "missing"}) does not match Proxy session ${proxySessionId}.`, { code: "provider_binding_mismatch", field: `metadata.${PROXY_SESSION_METADATA_KEY}` });
|
|
129
73
|
}
|
|
130
74
|
}
|
|
131
|
-
function acquisitionMetadata(proxySessionId, acquisition) {
|
|
132
|
-
return {
|
|
133
|
-
...(acquisition
|
|
134
|
-
? {
|
|
135
|
-
[PROXY_ACQUISITION_ATTEMPT_METADATA_KEY]: acquisition.id,
|
|
136
|
-
[PROXY_CONTRACT_VERSION_METADATA_KEY]: acquisition.contractVersion,
|
|
137
|
-
}
|
|
138
|
-
: {}),
|
|
139
|
-
[PROXY_SESSION_METADATA_KEY]: proxySessionId,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
75
|
function mergeProxyMetadata(existing, required, field) {
|
|
143
76
|
for (const [key, requiredValue] of Object.entries(required)) {
|
|
144
77
|
const existingValue = existing?.[key];
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* metadata placement, idempotency, and binding reconciliation.
|
|
8
8
|
*/
|
|
9
9
|
import type { JsonObject, PayerOpenedResult, ProxyCartValidator, ProxyCheckoutServerClient, ProxySessionProviderBinding } from "@proxy-checkout/server-js";
|
|
10
|
-
import { type StripeCompatibilityDescriptor } from "./compatibility.js";
|
|
11
10
|
import type { StripeCheckoutSessionCreateParams, StripeCheckoutSessionLike, StripeClientLike, StripeRequestOptionsWithoutIdempotencyLike } from "./types.js";
|
|
12
11
|
export interface OpenCheckoutOptions<TStripe extends StripeClientLike, TCart, TOffer> {
|
|
13
12
|
/** Builds app-specific Stripe Checkout Session params. Proxy metadata is injected by the SDK. */
|
|
@@ -19,13 +18,8 @@ export interface OpenCheckoutOptions<TStripe extends StripeClientLike, TCart, TO
|
|
|
19
18
|
}) => Promise<StripeCheckoutSessionCreateParams> | StripeCheckoutSessionCreateParams;
|
|
20
19
|
/** Optional schema validating the session cart snapshot into a typed cart. */
|
|
21
20
|
readonly cartSchema?: ProxyCartValidator<TCart>;
|
|
22
|
-
/** New acquisition contract. Omit with the other acquisition fields only for 0.0.x compatibility. */
|
|
23
|
-
readonly commercialMode?: "one_time" | "subscription";
|
|
24
|
-
readonly compatibility?: StripeCompatibilityDescriptor;
|
|
25
21
|
/** Optional extractor used to assert the cart buyer reference matches the session. */
|
|
26
22
|
readonly getCartBuyerReference?: (cart: TCart) => string | null | undefined;
|
|
27
|
-
/** New acquisition contract. Defaults are intentionally not guessed for explicit callers. */
|
|
28
|
-
readonly pricingMode?: "fixed" | "provider_finalized";
|
|
29
23
|
/** A Proxy server SDK client. */
|
|
30
24
|
readonly proxy: ProxyCheckoutServerClient;
|
|
31
25
|
readonly proxySessionId: string;
|
|
@@ -40,12 +34,8 @@ export interface OpenCheckoutOptions<TStripe extends StripeClientLike, TCart, TO
|
|
|
40
34
|
readonly requestId?: string;
|
|
41
35
|
/** The merchant's Stripe instance. */
|
|
42
36
|
readonly stripe: TStripe;
|
|
43
|
-
/** Convenience alias for compatibility.apiVersion. */
|
|
44
|
-
readonly stripeApiVersion?: string;
|
|
45
37
|
/** Optional Stripe request options. The SDK owns the deterministic idempotency key. */
|
|
46
38
|
readonly stripeRequestOptions?: StripeRequestOptionsWithoutIdempotencyLike;
|
|
47
|
-
/** Semantic Checkout presentation. Provider aliases are normalized per Stripe generation. */
|
|
48
|
-
readonly uiMode?: "custom" | "embedded" | "hosted";
|
|
49
39
|
/** Optional merchant cart validation that derives an app-specific offer. */
|
|
50
40
|
readonly validateCart?: (input: {
|
|
51
41
|
cart: TCart;
|
|
@@ -59,26 +49,15 @@ export interface OpenCheckoutReconciledCart<TCart> {
|
|
|
59
49
|
readonly currency: string;
|
|
60
50
|
}
|
|
61
51
|
export interface OpenCheckoutResult<TCart, TOffer, TSession> {
|
|
62
|
-
readonly acquisitionAttemptId?: string;
|
|
63
52
|
readonly binding: ProxySessionProviderBinding;
|
|
64
53
|
readonly cart: TCart;
|
|
65
54
|
readonly checkoutSession: TSession;
|
|
66
|
-
readonly checkoutSessionId?: string;
|
|
67
55
|
readonly clientSecret: string | null;
|
|
68
56
|
readonly offer: TOffer;
|
|
69
57
|
readonly outcome: "ready";
|
|
70
|
-
readonly presentation?: {
|
|
71
|
-
readonly kind: "client_secret";
|
|
72
|
-
readonly clientSecret: string;
|
|
73
|
-
readonly uiMode: "custom" | "embedded";
|
|
74
|
-
} | {
|
|
75
|
-
readonly kind: "redirect";
|
|
76
|
-
readonly url: string;
|
|
77
|
-
};
|
|
78
58
|
readonly proxySession: PayerOpenedResult;
|
|
79
59
|
readonly proxySessionId: string;
|
|
80
60
|
}
|
|
81
|
-
export type OpenCheckoutPresentation = NonNullable<OpenCheckoutResult<unknown, unknown, unknown>["presentation"]>;
|
|
82
61
|
export type OpenCheckoutTerminalResult<TCart> = {
|
|
83
62
|
readonly cart: TCart;
|
|
84
63
|
readonly outcome: "already_paid";
|