@proxy-checkout/stripe-server-js 0.0.0 → 0.0.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.
Files changed (49) hide show
  1. package/README.md +8 -9
  2. package/dist/cjs/errors.d.cts +38 -0
  3. package/dist/cjs/errors.d.ts +38 -0
  4. package/dist/cjs/errors.js +38 -0
  5. package/dist/cjs/index.d.cts +7 -0
  6. package/dist/cjs/index.d.ts +7 -0
  7. package/dist/cjs/index.js +22 -0
  8. package/dist/cjs/metadata.d.cts +46 -0
  9. package/dist/{metadata.d.ts → cjs/metadata.d.ts} +7 -1
  10. package/dist/cjs/metadata.js +92 -0
  11. package/dist/cjs/open-checkout.d.cts +60 -0
  12. package/dist/cjs/open-checkout.d.ts +60 -0
  13. package/dist/cjs/open-checkout.js +210 -0
  14. package/dist/cjs/package.json +3 -0
  15. package/dist/cjs/psp.d.cts +12 -0
  16. package/dist/cjs/psp.d.ts +12 -0
  17. package/dist/cjs/psp.js +25 -0
  18. package/dist/cjs/sync-checkout-cart.d.cts +47 -0
  19. package/dist/{sync-checkout-cart.d.ts → cjs/sync-checkout-cart.d.ts} +3 -1
  20. package/dist/cjs/sync-checkout-cart.js +97 -0
  21. package/dist/cjs/types.d.cts +52 -0
  22. package/dist/{types.d.ts → cjs/types.d.ts} +20 -3
  23. package/dist/cjs/types.js +10 -0
  24. package/dist/cjs/version.d.cts +2 -0
  25. package/dist/{version.d.ts → cjs/version.d.ts} +1 -1
  26. package/dist/cjs/version.js +5 -0
  27. package/dist/esm/errors.d.ts +38 -0
  28. package/dist/esm/errors.js +33 -0
  29. package/dist/esm/index.d.ts +7 -0
  30. package/dist/esm/index.js +6 -0
  31. package/dist/esm/metadata.d.ts +46 -0
  32. package/dist/{metadata.js → esm/metadata.js} +44 -0
  33. package/dist/esm/open-checkout.d.ts +60 -0
  34. package/dist/esm/open-checkout.js +207 -0
  35. package/dist/esm/psp.d.ts +12 -0
  36. package/dist/esm/psp.js +22 -0
  37. package/dist/esm/sync-checkout-cart.d.ts +47 -0
  38. package/dist/{sync-checkout-cart.js → esm/sync-checkout-cart.js} +37 -17
  39. package/dist/esm/types.d.ts +52 -0
  40. package/dist/esm/version.d.ts +2 -0
  41. package/dist/{version.js → esm/version.js} +1 -1
  42. package/package.json +16 -8
  43. package/dist/errors.d.ts +0 -20
  44. package/dist/errors.js +0 -15
  45. package/dist/index.d.ts +0 -6
  46. package/dist/index.js +0 -5
  47. package/dist/open-checkout.d.ts +0 -48
  48. package/dist/open-checkout.js +0 -48
  49. /package/dist/{types.js → esm/types.js} +0 -0
package/package.json CHANGED
@@ -1,24 +1,31 @@
1
1
  {
2
2
  "description": "Server-side Stripe adapter for Proxy Checkout: required metadata, provider binding, openCheckout, and cart sync.",
3
3
  "license": "MIT",
4
- "module": "./dist/index.js",
4
+ "module": "./dist/esm/index.js",
5
5
  "name": "@proxy-checkout/stripe-server-js",
6
6
  "private": false,
7
7
  "sideEffects": false,
8
8
  "type": "module",
9
- "types": "./dist/index.d.ts",
10
- "version": "0.0.0",
9
+ "types": "./dist/esm/index.d.ts",
10
+ "version": "0.0.1",
11
11
  "devDependencies": {
12
12
  "@types/node": "^24.12.4",
13
13
  "@vitest/coverage-v8": "4.1.7",
14
+ "stripe": "^21.0.1",
14
15
  "typescript": "^6.0.3",
15
16
  "vitest": "4.1.7",
16
17
  "@proxy-checkout/server-js": "0.0.4"
17
18
  },
18
19
  "exports": {
19
20
  ".": {
20
- "import": "./dist/index.js",
21
- "types": "./dist/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
+ }
22
29
  }
23
30
  },
24
31
  "files": [
@@ -34,7 +41,7 @@
34
41
  "sdk"
35
42
  ],
36
43
  "peerDependencies": {
37
- "@proxy-checkout/server-js": "0.0.4"
44
+ "@proxy-checkout/server-js": ">=0.0.4-0 <0.1.0"
38
45
  },
39
46
  "publishConfig": {
40
47
  "access": "public"
@@ -45,7 +52,7 @@
45
52
  "url": "git+https://github.com/linuslabs/proxy.git"
46
53
  },
47
54
  "scripts": {
48
- "build": "tsc -p tsconfig.build.json",
55
+ "build": "node ../../scripts/sdk/build-dual-package.mjs",
49
56
  "test:all": "vitest run",
50
57
  "test:coverage": "vitest run --coverage.enabled --coverage.reportsDirectory=coverage/all",
51
58
  "test:coverage:changed": "vitest run --coverage.enabled --coverage.reportsDirectory=coverage/changed",
@@ -54,5 +61,6 @@
54
61
  "test:integration": "vitest run --project integration",
55
62
  "test:unit": "vitest run --project unit",
56
63
  "typecheck": "tsc --noEmit -p tsconfig.json"
57
- }
64
+ },
65
+ "main": "./dist/cjs/index.js"
58
66
  }
package/dist/errors.d.ts DELETED
@@ -1,20 +0,0 @@
1
- /**
2
- * Adapter-specific error raised when a Stripe/Proxy cart synchronization cannot
3
- * complete cleanly. The `reconciled` flag states whether the Proxy cart was
4
- * restored to its prior state, so callers can react deterministically.
5
- */
6
- export type ProxyStripeCartSyncCode = "reconciliation_failed" | "stripe_update_failed";
7
- export declare class ProxyStripeCartSyncError extends Error {
8
- readonly name = "ProxyStripeCartSyncError";
9
- readonly code: ProxyStripeCartSyncCode;
10
- /** True when the Proxy cart was rolled back to its prior state after the failure. */
11
- readonly reconciled: boolean;
12
- readonly cause: unknown;
13
- readonly rollbackCause: unknown;
14
- constructor(message: string, details: {
15
- code: ProxyStripeCartSyncCode;
16
- reconciled: boolean;
17
- cause: unknown;
18
- rollbackCause?: unknown;
19
- });
20
- }
package/dist/errors.js DELETED
@@ -1,15 +0,0 @@
1
- export class ProxyStripeCartSyncError extends Error {
2
- name = "ProxyStripeCartSyncError";
3
- code;
4
- /** True when the Proxy cart was rolled back to its prior state after the failure. */
5
- reconciled;
6
- cause;
7
- rollbackCause;
8
- constructor(message, details) {
9
- super(message);
10
- this.code = details.code;
11
- this.reconciled = details.reconciled;
12
- this.cause = details.cause;
13
- this.rollbackCause = details.rollbackCause;
14
- }
15
- }
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export { type ProxyStripeCartSyncCode, ProxyStripeCartSyncError, } from "./errors.js";
2
- export { assertCheckoutSessionBelongsToProxy, assertPaymentIntentBelongsToProxy, assertSubscriptionBelongsToProxy, PROXY_SESSION_METADATA_KEY, type ProxySessionMetadata, type ProxyStripeRequiredMetadata, requiredMetadata, } from "./metadata.js";
3
- export { type OpenCheckoutOptions, type OpenCheckoutResult, openCheckout, } from "./open-checkout.js";
4
- export { type SyncCheckoutCartOptions, type SyncCheckoutCartResult, type SyncedCart, syncCheckoutCart, } from "./sync-checkout-cart.js";
5
- export type { StripeCheckoutSessionLike, StripeCheckoutSessionsApiLike, StripeCheckoutSessionUpdateParams, StripeClientLike, StripeMetadata, StripePaymentIntentLike, StripeSubscriptionLike, } from "./types.js";
6
- export { proxyCheckoutStripeServerSdkName, proxyCheckoutStripeServerSdkVersion, } from "./version.js";
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- export { ProxyStripeCartSyncError, } from "./errors.js";
2
- export { assertCheckoutSessionBelongsToProxy, assertPaymentIntentBelongsToProxy, assertSubscriptionBelongsToProxy, PROXY_SESSION_METADATA_KEY, requiredMetadata, } from "./metadata.js";
3
- export { openCheckout, } from "./open-checkout.js";
4
- export { syncCheckoutCart, } from "./sync-checkout-cart.js";
5
- export { proxyCheckoutStripeServerSdkName, proxyCheckoutStripeServerSdkVersion, } from "./version.js";
@@ -1,48 +0,0 @@
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
- * supply required metadata, record the provider binding) and delegates only the
6
- * app-specific Stripe object creation to the merchant callback. This makes it
7
- * hard to create a Stripe checkout that is not correctly linked to a session.
8
- */
9
- import type { PayerOpenedResult, ProxyCartValidator, ProxyCheckoutServerClient } from "@proxy-checkout/server-js";
10
- import type { ProxyStripeRequiredMetadata } from "./metadata.js";
11
- import type { StripeCheckoutSessionLike } from "./types.js";
12
- export interface OpenCheckoutOptions<TStripe, TCart, TOffer, TSession> {
13
- /** Optional schema validating the session cart snapshot into a typed cart. */
14
- readonly cartSchema?: ProxyCartValidator<TCart>;
15
- /** Builds the Stripe checkout object. Must place `metadata.checkoutSession` (and subscription/payment-intent metadata) on the created object. */
16
- readonly createCheckoutSession: (input: {
17
- cart: TCart;
18
- metadata: ProxyStripeRequiredMetadata;
19
- offer: TOffer;
20
- proxySession: PayerOpenedResult;
21
- stripe: TStripe;
22
- }) => Promise<TSession> | TSession;
23
- /** Optional extractor used to assert the cart buyer reference matches the session. */
24
- readonly getCartBuyerReference?: (cart: TCart) => string | null | undefined;
25
- /** A Proxy server SDK client. */
26
- readonly proxy: ProxyCheckoutServerClient;
27
- readonly proxySessionId: string;
28
- /** Provider identifier recorded with the binding. Defaults to "stripe". */
29
- readonly psp?: string;
30
- readonly requestId?: string;
31
- /** The merchant's Stripe instance, forwarded to `createCheckoutSession`. */
32
- readonly stripe: TStripe;
33
- /** Optional merchant cart validation that derives an app-specific offer. */
34
- readonly validateCart?: (input: {
35
- cart: TCart;
36
- session: PayerOpenedResult;
37
- }) => Promise<TOffer> | TOffer;
38
- }
39
- export interface OpenCheckoutResult<TCart, TOffer, TSession> {
40
- readonly binding: Awaited<ReturnType<ProxyCheckoutServerClient["sessions"]["recordProviderBinding"]>>;
41
- readonly cart: TCart;
42
- readonly checkoutSession: TSession;
43
- readonly clientSecret: string | null;
44
- readonly offer: TOffer;
45
- readonly proxySession: PayerOpenedResult;
46
- readonly proxySessionId: string;
47
- }
48
- export declare function openCheckout<TStripe, TCart = unknown, TOffer = undefined, TSession extends StripeCheckoutSessionLike = StripeCheckoutSessionLike>(options: OpenCheckoutOptions<TStripe, TCart, TOffer, TSession>): Promise<OpenCheckoutResult<TCart, TOffer, TSession>>;
@@ -1,48 +0,0 @@
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
- * supply required metadata, record the provider binding) and delegates only the
6
- * app-specific Stripe object creation to the merchant callback. This makes it
7
- * hard to create a Stripe checkout that is not correctly linked to a session.
8
- */
9
- import { assertCheckoutSessionBelongsToProxy, requiredMetadata } from "./metadata.js";
10
- export async function openCheckout(options) {
11
- const psp = options.psp ?? "stripe";
12
- const proxySession = await options.proxy.sessions.payerOpened(options.proxySessionId, {
13
- requestId: options.requestId,
14
- });
15
- // Parse the cart (and run the buyer-reference check) whenever a schema OR a
16
- // buyer-reference extractor is provided, so the consistency check is never
17
- // silently skipped just because no custom schema was passed.
18
- const cart = options.cartSchema || options.getCartBuyerReference
19
- ? options.proxy.sessions.parseCart(proxySession, options.cartSchema ?? ((value) => value), { getBuyerReference: options.getCartBuyerReference })
20
- : proxySession.cartSnapshot;
21
- const offer = options.validateCart
22
- ? await options.validateCart({ cart, session: proxySession })
23
- : undefined;
24
- const metadata = requiredMetadata(proxySession);
25
- const checkoutSession = await options.createCheckoutSession({
26
- cart,
27
- metadata,
28
- offer,
29
- proxySession,
30
- stripe: options.stripe,
31
- });
32
- // Fail closed if the merchant forgot to place proxy_session_id metadata.
33
- assertCheckoutSessionBelongsToProxy(checkoutSession, proxySession.id);
34
- const binding = await options.proxy.sessions.recordProviderBinding(proxySession.id, {
35
- providerCheckoutSessionId: checkoutSession.id,
36
- psp,
37
- requestId: options.requestId,
38
- });
39
- return {
40
- binding,
41
- cart,
42
- checkoutSession,
43
- clientSecret: checkoutSession.client_secret ?? null,
44
- offer,
45
- proxySession,
46
- proxySessionId: proxySession.id,
47
- };
48
- }
File without changes