@proxy-checkout/server-js 0.0.4-pr-76.31.1 → 0.0.4-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.
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Server SDK webhook delivery handler.
3
+ *
4
+ * `handle` turns a verified Proxy webhook into a current-state lifecycle
5
+ * decision and runs the merchant's entitlement callback, with optional
6
+ * idempotency via a pluggable {@link ProxyWebhookStore}. It owns signature
7
+ * verification, duplicate/in-flight handling, retryable responses, and
8
+ * current-state retrieval so customer webhook routes stay tiny.
9
+ */
10
+ import type { ProxyEventsResource, ResolvedProxyEvent, ResolvedProxyEventKind } from "./events.js";
11
+ import { type ProxyWebhookEvent } from "./webhooks.js";
12
+ /** Seconds advertised in `Retry-After` when an event is already in flight. */
13
+ export declare const PROXY_WEBHOOK_RETRY_AFTER_SECONDS = 30;
14
+ export type ProxyWebhookClaimResult = "claimed" | "duplicate" | "processing";
15
+ export type ProxyWebhookOutcome = "duplicate" | "ignored" | "processed" | "processing";
16
+ /** Compact, lifecycle-free audit record handed to a {@link ProxyWebhookStore}. */
17
+ export interface ProxyWebhookProcessRecord {
18
+ readonly kind: ResolvedProxyEventKind;
19
+ readonly paymentAttemptId?: string | null;
20
+ readonly sessionId: string | null;
21
+ readonly subscriptionId: string | null;
22
+ }
23
+ /**
24
+ * Optional merchant-owned idempotency/audit store. The handler treats already
25
+ * processed events as success and concurrently in-flight events as retryable;
26
+ * it never classifies lifecycle itself.
27
+ */
28
+ export interface ProxyWebhookStore {
29
+ /** Atomically claim an event id. Return "duplicate" if already processed, "processing" if in flight. */
30
+ claim(event: ProxyWebhookEvent): Promise<ProxyWebhookClaimResult> | ProxyWebhookClaimResult;
31
+ /** Mark a claimed event failed so it can be retried/reclaimed. */
32
+ markFailed(eventId: string, error: unknown): Promise<void> | void;
33
+ /** Mark a claimed event processed (idempotency commit). */
34
+ markProcessed(eventId: string, record: ProxyWebhookProcessRecord): Promise<void> | void;
35
+ }
36
+ export interface ProxyWebhookPayloadInput {
37
+ readonly body: Buffer | string;
38
+ readonly signature?: string | null;
39
+ }
40
+ /**
41
+ * A web `Request` (Next.js route handlers, Hono on Node) or an explicit
42
+ * body/signature pair (Express/Node). Signature verification uses `node:crypto`,
43
+ * so this targets Node-compatible runtimes — not Cloudflare Workers.
44
+ */
45
+ export type ProxyWebhookRequestInput = ProxyWebhookPayloadInput | Request;
46
+ export interface ProxyWebhookHandlerOptions {
47
+ /** Merchant entitlement callback, invoked once per claimed event after current-state resolution. */
48
+ readonly onResolved: (resolved: ResolvedProxyEvent) => Promise<void> | void;
49
+ /** Optional request id forwarded to the current-state retrieval calls. */
50
+ readonly requestId?: string;
51
+ /** Endpoint signing secret. */
52
+ readonly secret: string;
53
+ /** Optional idempotency/audit store. Omit for at-least-once delivery with idempotent fulfillment. */
54
+ readonly store?: ProxyWebhookStore;
55
+ /** Signature timestamp tolerance in seconds (default 300). */
56
+ readonly toleranceSeconds?: number;
57
+ }
58
+ export interface ProxyWebhookProcessResult {
59
+ readonly event: ProxyWebhookEvent;
60
+ readonly outcome: ProxyWebhookOutcome;
61
+ readonly resolved: ResolvedProxyEvent | null;
62
+ readonly retryable: boolean;
63
+ readonly statusCode: number;
64
+ }
65
+ export declare class ProxyWebhooksResource {
66
+ private readonly events;
67
+ constructor(events: ProxyEventsResource);
68
+ /** Low-level: verify + construct the event without resolving lifecycle. */
69
+ constructEvent(input: {
70
+ body: Buffer | string;
71
+ header: string | null | undefined;
72
+ secret: string;
73
+ toleranceSeconds?: number;
74
+ }): ProxyWebhookEvent;
75
+ /**
76
+ * Framework-agnostic processing. Verifies the signature, applies the store,
77
+ * resolves current state, runs `onResolved`, and returns response metadata.
78
+ * Throws {@link ProxyWebhookSignatureVerificationError} on a bad signature so
79
+ * non-Response frameworks (Express) can map it to 400.
80
+ */
81
+ process(input: ProxyWebhookRequestInput, options: ProxyWebhookHandlerOptions): Promise<ProxyWebhookProcessResult>;
82
+ /**
83
+ * Turnkey handler for web `Request` frameworks. Returns a `Response` with the
84
+ * right status (200 success/duplicate, 409 + `Retry-After` in flight, 400 on
85
+ * bad signature). Re-throws merchant `onResolved` errors so the platform can
86
+ * surface a 500 and Proxy retries.
87
+ */
88
+ handle(input: ProxyWebhookRequestInput, options: ProxyWebhookHandlerOptions): Promise<Response>;
89
+ }
@@ -0,0 +1,84 @@
1
+ import type { ProxyCheckoutHttpClient } from "./http-client.js";
2
+ import type { JsonObject, ProxyCheckoutServerRequestOptions } from "./types.js";
3
+ export interface WebhookEndpoint {
4
+ readonly createdAt: string;
5
+ readonly eventSchemaVersion: string;
6
+ readonly eventTypes: string[] | null;
7
+ readonly id: string;
8
+ readonly previousSigningSecretExpiresAt: string | null;
9
+ readonly status: string;
10
+ readonly updatedAt: string;
11
+ readonly url: string;
12
+ }
13
+ export interface CreateWebhookEndpointInput extends ProxyCheckoutServerRequestOptions {
14
+ readonly eventTypes?: string[];
15
+ readonly url: string;
16
+ }
17
+ export interface UpdateWebhookEndpointInput extends ProxyCheckoutServerRequestOptions {
18
+ readonly eventTypes?: string[];
19
+ readonly status?: "active" | "inactive";
20
+ readonly url?: string;
21
+ }
22
+ export interface RotateWebhookEndpointSecretInput extends ProxyCheckoutServerRequestOptions {
23
+ readonly previousSigningSecretExpiresAt: Date | string;
24
+ }
25
+ export interface WebhookEndpointSecretResult {
26
+ readonly signingSecret: string;
27
+ readonly webhookEndpoint: WebhookEndpoint;
28
+ }
29
+ export interface VerifyProxyWebhookSignatureInput {
30
+ readonly body: Buffer | string;
31
+ readonly header: string | null | undefined;
32
+ readonly secret: string;
33
+ readonly toleranceSeconds?: number;
34
+ }
35
+ export interface ConstructProxyWebhookEventInput extends VerifyProxyWebhookSignatureInput {
36
+ }
37
+ export interface ProxyWebhookEvent {
38
+ readonly data: JsonObject;
39
+ readonly id: string;
40
+ readonly schemaVersion: string;
41
+ readonly type: string;
42
+ }
43
+ export declare const PROXY_SIGNATURE_HEADER = "proxy-signature";
44
+ /** Raised when a webhook payload fails signature verification. */
45
+ export declare class ProxyWebhookSignatureVerificationError extends Error {
46
+ readonly name = "ProxyWebhookSignatureVerificationError";
47
+ }
48
+ export declare const proxyCheckoutWebhookEndpointEndpoints: readonly [{
49
+ readonly method: "GET";
50
+ readonly operation: "webhookEndpoints.list";
51
+ readonly path: "/webhook_endpoints";
52
+ }, {
53
+ readonly method: "POST";
54
+ readonly operation: "webhookEndpoints.create";
55
+ readonly path: "/webhook_endpoints";
56
+ }, {
57
+ readonly method: "GET";
58
+ readonly operation: "webhookEndpoints.get";
59
+ readonly path: "/webhook_endpoints/:id";
60
+ }, {
61
+ readonly method: "PATCH";
62
+ readonly operation: "webhookEndpoints.update";
63
+ readonly path: "/webhook_endpoints/:id";
64
+ }, {
65
+ readonly method: "POST";
66
+ readonly operation: "webhookEndpoints.archive";
67
+ readonly path: "/webhook_endpoints/:id/archive";
68
+ }, {
69
+ readonly method: "POST";
70
+ readonly operation: "webhookEndpoints.rotateSecret";
71
+ readonly path: "/webhook_endpoints/:id/rotate_secret";
72
+ }];
73
+ export declare class ProxyWebhookEndpointsResource {
74
+ private readonly httpClient;
75
+ constructor(httpClient: ProxyCheckoutHttpClient);
76
+ list(options?: ProxyCheckoutServerRequestOptions): Promise<WebhookEndpoint[]>;
77
+ create(input: CreateWebhookEndpointInput): Promise<WebhookEndpointSecretResult>;
78
+ get(webhookEndpointId: string, options?: ProxyCheckoutServerRequestOptions): Promise<WebhookEndpoint>;
79
+ update(webhookEndpointId: string, input: UpdateWebhookEndpointInput): Promise<WebhookEndpoint>;
80
+ archive(webhookEndpointId: string, options?: ProxyCheckoutServerRequestOptions): Promise<WebhookEndpoint>;
81
+ rotateSecret(webhookEndpointId: string, input: RotateWebhookEndpointSecretInput): Promise<WebhookEndpointSecretResult>;
82
+ }
83
+ export declare function verifyProxyWebhookSignature(input: VerifyProxyWebhookSignatureInput): boolean;
84
+ export declare function constructProxyWebhookEvent(input: ConstructProxyWebhookEventInput): ProxyWebhookEvent;
@@ -0,0 +1,84 @@
1
+ import type { ProxyCheckoutHttpClient } from "./http-client.js";
2
+ import type { JsonObject, ProxyCheckoutServerRequestOptions } from "./types.js";
3
+ export interface WebhookEndpoint {
4
+ readonly createdAt: string;
5
+ readonly eventSchemaVersion: string;
6
+ readonly eventTypes: string[] | null;
7
+ readonly id: string;
8
+ readonly previousSigningSecretExpiresAt: string | null;
9
+ readonly status: string;
10
+ readonly updatedAt: string;
11
+ readonly url: string;
12
+ }
13
+ export interface CreateWebhookEndpointInput extends ProxyCheckoutServerRequestOptions {
14
+ readonly eventTypes?: string[];
15
+ readonly url: string;
16
+ }
17
+ export interface UpdateWebhookEndpointInput extends ProxyCheckoutServerRequestOptions {
18
+ readonly eventTypes?: string[];
19
+ readonly status?: "active" | "inactive";
20
+ readonly url?: string;
21
+ }
22
+ export interface RotateWebhookEndpointSecretInput extends ProxyCheckoutServerRequestOptions {
23
+ readonly previousSigningSecretExpiresAt: Date | string;
24
+ }
25
+ export interface WebhookEndpointSecretResult {
26
+ readonly signingSecret: string;
27
+ readonly webhookEndpoint: WebhookEndpoint;
28
+ }
29
+ export interface VerifyProxyWebhookSignatureInput {
30
+ readonly body: Buffer | string;
31
+ readonly header: string | null | undefined;
32
+ readonly secret: string;
33
+ readonly toleranceSeconds?: number;
34
+ }
35
+ export interface ConstructProxyWebhookEventInput extends VerifyProxyWebhookSignatureInput {
36
+ }
37
+ export interface ProxyWebhookEvent {
38
+ readonly data: JsonObject;
39
+ readonly id: string;
40
+ readonly schemaVersion: string;
41
+ readonly type: string;
42
+ }
43
+ export declare const PROXY_SIGNATURE_HEADER = "proxy-signature";
44
+ /** Raised when a webhook payload fails signature verification. */
45
+ export declare class ProxyWebhookSignatureVerificationError extends Error {
46
+ readonly name = "ProxyWebhookSignatureVerificationError";
47
+ }
48
+ export declare const proxyCheckoutWebhookEndpointEndpoints: readonly [{
49
+ readonly method: "GET";
50
+ readonly operation: "webhookEndpoints.list";
51
+ readonly path: "/webhook_endpoints";
52
+ }, {
53
+ readonly method: "POST";
54
+ readonly operation: "webhookEndpoints.create";
55
+ readonly path: "/webhook_endpoints";
56
+ }, {
57
+ readonly method: "GET";
58
+ readonly operation: "webhookEndpoints.get";
59
+ readonly path: "/webhook_endpoints/:id";
60
+ }, {
61
+ readonly method: "PATCH";
62
+ readonly operation: "webhookEndpoints.update";
63
+ readonly path: "/webhook_endpoints/:id";
64
+ }, {
65
+ readonly method: "POST";
66
+ readonly operation: "webhookEndpoints.archive";
67
+ readonly path: "/webhook_endpoints/:id/archive";
68
+ }, {
69
+ readonly method: "POST";
70
+ readonly operation: "webhookEndpoints.rotateSecret";
71
+ readonly path: "/webhook_endpoints/:id/rotate_secret";
72
+ }];
73
+ export declare class ProxyWebhookEndpointsResource {
74
+ private readonly httpClient;
75
+ constructor(httpClient: ProxyCheckoutHttpClient);
76
+ list(options?: ProxyCheckoutServerRequestOptions): Promise<WebhookEndpoint[]>;
77
+ create(input: CreateWebhookEndpointInput): Promise<WebhookEndpointSecretResult>;
78
+ get(webhookEndpointId: string, options?: ProxyCheckoutServerRequestOptions): Promise<WebhookEndpoint>;
79
+ update(webhookEndpointId: string, input: UpdateWebhookEndpointInput): Promise<WebhookEndpoint>;
80
+ archive(webhookEndpointId: string, options?: ProxyCheckoutServerRequestOptions): Promise<WebhookEndpoint>;
81
+ rotateSecret(webhookEndpointId: string, input: RotateWebhookEndpointSecretInput): Promise<WebhookEndpointSecretResult>;
82
+ }
83
+ export declare function verifyProxyWebhookSignature(input: VerifyProxyWebhookSignatureInput): boolean;
84
+ export declare function constructProxyWebhookEvent(input: ConstructProxyWebhookEventInput): ProxyWebhookEvent;
@@ -1,3 +1,3 @@
1
1
  export declare const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
2
- export declare const proxyCheckoutServerSdkVersion = "0.0.4-pr-76.31.1";
3
- export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.4-pr-76.31.1";
2
+ export declare const proxyCheckoutServerSdkVersion = "0.0.4-pr-76.32.1";
3
+ export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.4-pr-76.32.1";
@@ -1,3 +1,3 @@
1
1
  export const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
2
- export const proxyCheckoutServerSdkVersion = "0.0.4-pr-76.31.1";
2
+ export const proxyCheckoutServerSdkVersion = "0.0.4-pr-76.32.1";
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.4-pr-76.31.1",
10
+ "version": "0.0.4-pr-76.32.1",
11
11
  "devDependencies": {
12
12
  "@types/node": "^24.12.4",
13
13
  "@vitest/coverage-v8": "4.1.7",
@@ -16,9 +16,14 @@
16
16
  },
17
17
  "exports": {
18
18
  ".": {
19
- "import": "./dist/esm/index.js",
20
- "require": "./dist/cjs/index.js",
21
- "types": "./dist/esm/index.d.ts"
19
+ "import": {
20
+ "default": "./dist/esm/index.js",
21
+ "types": "./dist/esm/index.d.ts"
22
+ },
23
+ "require": {
24
+ "default": "./dist/cjs/index.js",
25
+ "types": "./dist/cjs/index.d.cts"
26
+ }
22
27
  }
23
28
  },
24
29
  "files": [