@proxy-checkout/server-js 0.0.4-pr-76.21.1 → 0.0.4-pr-76.22.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 (50) hide show
  1. package/dist/cjs/cart.js +26 -0
  2. package/dist/cjs/client.js +41 -0
  3. package/dist/cjs/consistency.js +36 -0
  4. package/dist/cjs/errors.js +59 -0
  5. package/dist/cjs/events.js +151 -0
  6. package/dist/cjs/http-client.js +84 -0
  7. package/dist/cjs/index.js +55 -0
  8. package/dist/cjs/lifecycle.js +109 -0
  9. package/dist/cjs/package.json +3 -0
  10. package/dist/cjs/response-validators.js +60 -0
  11. package/dist/cjs/sessions.js +303 -0
  12. package/dist/cjs/subscriptions.js +59 -0
  13. package/dist/cjs/types.js +2 -0
  14. package/dist/cjs/version.js +6 -0
  15. package/dist/cjs/webhook-events.js +69 -0
  16. package/dist/cjs/webhook-handler.js +177 -0
  17. package/dist/cjs/webhooks.js +182 -0
  18. package/dist/{version.d.ts → esm/version.d.ts} +2 -2
  19. package/dist/{version.js → esm/version.js} +1 -1
  20. package/package.json +8 -6
  21. /package/dist/{cart.d.ts → esm/cart.d.ts} +0 -0
  22. /package/dist/{cart.js → esm/cart.js} +0 -0
  23. /package/dist/{client.d.ts → esm/client.d.ts} +0 -0
  24. /package/dist/{client.js → esm/client.js} +0 -0
  25. /package/dist/{consistency.d.ts → esm/consistency.d.ts} +0 -0
  26. /package/dist/{consistency.js → esm/consistency.js} +0 -0
  27. /package/dist/{errors.d.ts → esm/errors.d.ts} +0 -0
  28. /package/dist/{errors.js → esm/errors.js} +0 -0
  29. /package/dist/{events.d.ts → esm/events.d.ts} +0 -0
  30. /package/dist/{events.js → esm/events.js} +0 -0
  31. /package/dist/{http-client.d.ts → esm/http-client.d.ts} +0 -0
  32. /package/dist/{http-client.js → esm/http-client.js} +0 -0
  33. /package/dist/{index.d.ts → esm/index.d.ts} +0 -0
  34. /package/dist/{index.js → esm/index.js} +0 -0
  35. /package/dist/{lifecycle.d.ts → esm/lifecycle.d.ts} +0 -0
  36. /package/dist/{lifecycle.js → esm/lifecycle.js} +0 -0
  37. /package/dist/{response-validators.d.ts → esm/response-validators.d.ts} +0 -0
  38. /package/dist/{response-validators.js → esm/response-validators.js} +0 -0
  39. /package/dist/{sessions.d.ts → esm/sessions.d.ts} +0 -0
  40. /package/dist/{sessions.js → esm/sessions.js} +0 -0
  41. /package/dist/{subscriptions.d.ts → esm/subscriptions.d.ts} +0 -0
  42. /package/dist/{subscriptions.js → esm/subscriptions.js} +0 -0
  43. /package/dist/{types.d.ts → esm/types.d.ts} +0 -0
  44. /package/dist/{types.js → esm/types.js} +0 -0
  45. /package/dist/{webhook-events.d.ts → esm/webhook-events.d.ts} +0 -0
  46. /package/dist/{webhook-events.js → esm/webhook-events.js} +0 -0
  47. /package/dist/{webhook-handler.d.ts → esm/webhook-handler.d.ts} +0 -0
  48. /package/dist/{webhook-handler.js → esm/webhook-handler.js} +0 -0
  49. /package/dist/{webhooks.d.ts → esm/webhooks.d.ts} +0 -0
  50. /package/dist/{webhooks.js → esm/webhooks.js} +0 -0
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProxyWebhookEndpointsResource = exports.proxyCheckoutWebhookEndpointEndpoints = exports.ProxyWebhookSignatureVerificationError = exports.PROXY_SIGNATURE_HEADER = void 0;
4
+ exports.verifyProxyWebhookSignature = verifyProxyWebhookSignature;
5
+ exports.constructProxyWebhookEvent = constructProxyWebhookEvent;
6
+ const node_crypto_1 = require("node:crypto");
7
+ const response_validators_js_1 = require("./response-validators.js");
8
+ exports.PROXY_SIGNATURE_HEADER = "proxy-signature";
9
+ /** Raised when a webhook payload fails signature verification. */
10
+ class ProxyWebhookSignatureVerificationError extends Error {
11
+ name = "ProxyWebhookSignatureVerificationError";
12
+ }
13
+ exports.ProxyWebhookSignatureVerificationError = ProxyWebhookSignatureVerificationError;
14
+ exports.proxyCheckoutWebhookEndpointEndpoints = [
15
+ {
16
+ method: "GET",
17
+ operation: "webhookEndpoints.list",
18
+ path: "/webhook_endpoints",
19
+ },
20
+ {
21
+ method: "POST",
22
+ operation: "webhookEndpoints.create",
23
+ path: "/webhook_endpoints",
24
+ },
25
+ {
26
+ method: "GET",
27
+ operation: "webhookEndpoints.get",
28
+ path: "/webhook_endpoints/:id",
29
+ },
30
+ {
31
+ method: "PATCH",
32
+ operation: "webhookEndpoints.update",
33
+ path: "/webhook_endpoints/:id",
34
+ },
35
+ {
36
+ method: "POST",
37
+ operation: "webhookEndpoints.archive",
38
+ path: "/webhook_endpoints/:id/archive",
39
+ },
40
+ {
41
+ method: "POST",
42
+ operation: "webhookEndpoints.rotateSecret",
43
+ path: "/webhook_endpoints/:id/rotate_secret",
44
+ },
45
+ ];
46
+ class ProxyWebhookEndpointsResource {
47
+ httpClient;
48
+ constructor(httpClient) {
49
+ this.httpClient = httpClient;
50
+ }
51
+ async list(options = {}) {
52
+ const response = await this.httpClient.request("GET", "/webhook_endpoints", undefined, options);
53
+ const body = (0, response_validators_js_1.requireJsonObject)(response, "webhookEndpoints.list");
54
+ const endpoints = body.webhook_endpoints;
55
+ if (!Array.isArray(endpoints)) {
56
+ throw new Error("Proxy API response field webhookEndpoints.list.webhookEndpoints must be an array.");
57
+ }
58
+ return endpoints.map(toWebhookEndpoint);
59
+ }
60
+ async create(input) {
61
+ const response = await this.httpClient.request("POST", "/webhook_endpoints", toWebhookEndpointBody(input), { requestId: input.requestId });
62
+ return toWebhookEndpointSecretResult(response, "webhookEndpoints.create");
63
+ }
64
+ async get(webhookEndpointId, options = {}) {
65
+ const response = await this.httpClient.request("GET", `/webhook_endpoints/${encodeURIComponent(webhookEndpointId)}`, undefined, options);
66
+ return toWebhookEndpointEnvelope(response, "webhookEndpoints.get");
67
+ }
68
+ async update(webhookEndpointId, input) {
69
+ const response = await this.httpClient.request("PATCH", `/webhook_endpoints/${encodeURIComponent(webhookEndpointId)}`, toWebhookEndpointBody(input), { requestId: input.requestId });
70
+ return toWebhookEndpointEnvelope(response, "webhookEndpoints.update");
71
+ }
72
+ async archive(webhookEndpointId, options = {}) {
73
+ const response = await this.httpClient.request("POST", `/webhook_endpoints/${encodeURIComponent(webhookEndpointId)}/archive`, undefined, options);
74
+ return toWebhookEndpointEnvelope(response, "webhookEndpoints.archive");
75
+ }
76
+ async rotateSecret(webhookEndpointId, input) {
77
+ const response = await this.httpClient.request("POST", `/webhook_endpoints/${encodeURIComponent(webhookEndpointId)}/rotate_secret`, {
78
+ previous_signing_secret_expires_at: input.previousSigningSecretExpiresAt instanceof Date
79
+ ? input.previousSigningSecretExpiresAt.toISOString()
80
+ : input.previousSigningSecretExpiresAt,
81
+ }, { requestId: input.requestId });
82
+ return toWebhookEndpointSecretResult(response, "webhookEndpoints.rotateSecret");
83
+ }
84
+ }
85
+ exports.ProxyWebhookEndpointsResource = ProxyWebhookEndpointsResource;
86
+ function verifyProxyWebhookSignature(input) {
87
+ const parsed = parseSignatureHeader(input.header);
88
+ if (!parsed) {
89
+ return false;
90
+ }
91
+ const toleranceSeconds = input.toleranceSeconds ?? 300;
92
+ const nowSeconds = Math.floor(Date.now() / 1000);
93
+ if (Math.abs(nowSeconds - parsed.timestamp) > toleranceSeconds) {
94
+ return false;
95
+ }
96
+ const body = typeof input.body === "string" ? input.body : input.body.toString("utf8");
97
+ const expected = (0, node_crypto_1.createHmac)("sha256", input.secret)
98
+ .update(`${parsed.timestamp}.${body}`)
99
+ .digest("hex");
100
+ return parsed.signatures.some((signature) => timingSafeEqualString(expected, signature));
101
+ }
102
+ function constructProxyWebhookEvent(input) {
103
+ if (!verifyProxyWebhookSignature(input)) {
104
+ throw new ProxyWebhookSignatureVerificationError("Proxy webhook signature verification failed.");
105
+ }
106
+ const body = typeof input.body === "string" ? input.body : input.body.toString("utf8");
107
+ let parsed;
108
+ try {
109
+ parsed = JSON.parse(body);
110
+ }
111
+ catch {
112
+ throw new Error("Proxy webhook body must be valid JSON.");
113
+ }
114
+ const event = (0, response_validators_js_1.requireJsonObject)(parsed, "webhookEvent");
115
+ return {
116
+ data: (0, response_validators_js_1.requireJsonObject)(event.data, "webhookEvent.data"),
117
+ id: (0, response_validators_js_1.requireString)(event.id, "webhookEvent.id"),
118
+ schemaVersion: (0, response_validators_js_1.requireString)(event.schema_version, "webhookEvent.schemaVersion"),
119
+ type: (0, response_validators_js_1.requireString)(event.type, "webhookEvent.type"),
120
+ };
121
+ }
122
+ function toWebhookEndpointBody(input) {
123
+ return {
124
+ ...(input.eventTypes === undefined ? {} : { event_types: input.eventTypes }),
125
+ ...(input.status === undefined ? {} : { status: input.status }),
126
+ ...(input.url === undefined ? {} : { url: input.url }),
127
+ };
128
+ }
129
+ function toWebhookEndpointSecretResult(response, operation) {
130
+ const body = (0, response_validators_js_1.requireJsonObject)(response, operation);
131
+ return {
132
+ signingSecret: (0, response_validators_js_1.requireString)(body.signing_secret, `${operation}.signingSecret`),
133
+ webhookEndpoint: toWebhookEndpoint(body.webhook_endpoint),
134
+ };
135
+ }
136
+ function toWebhookEndpointEnvelope(response, operation) {
137
+ const body = (0, response_validators_js_1.requireJsonObject)(response, operation);
138
+ return toWebhookEndpoint(body.webhook_endpoint);
139
+ }
140
+ function toWebhookEndpoint(value) {
141
+ const body = (0, response_validators_js_1.requireJsonObject)(value, "webhookEndpoint");
142
+ return {
143
+ createdAt: (0, response_validators_js_1.requireString)(body.created_at, "webhookEndpoint.createdAt"),
144
+ eventSchemaVersion: (0, response_validators_js_1.requireString)(body.event_schema_version, "webhookEndpoint.eventSchemaVersion"),
145
+ eventTypes: (0, response_validators_js_1.requireStringArrayOrNull)(body.event_types, "webhookEndpoint.eventTypes"),
146
+ id: (0, response_validators_js_1.requireString)(body.id, "webhookEndpoint.id"),
147
+ previousSigningSecretExpiresAt: (0, response_validators_js_1.requireNullableString)(body.previous_signing_secret_expires_at, "webhookEndpoint.previousSigningSecretExpiresAt"),
148
+ status: (0, response_validators_js_1.requireString)(body.status, "webhookEndpoint.status"),
149
+ updatedAt: (0, response_validators_js_1.requireString)(body.updated_at, "webhookEndpoint.updatedAt"),
150
+ url: (0, response_validators_js_1.requireString)(body.url, "webhookEndpoint.url"),
151
+ };
152
+ }
153
+ function parseSignatureHeader(header) {
154
+ if (!header) {
155
+ return undefined;
156
+ }
157
+ let timestamp;
158
+ const signatures = [];
159
+ for (const part of header.split(",")) {
160
+ const [rawKey, rawValue] = part.split("=", 2);
161
+ const key = rawKey?.trim();
162
+ const value = rawValue?.trim();
163
+ if (key === "t") {
164
+ timestamp = Number(value);
165
+ }
166
+ else if (key === "v1" && value) {
167
+ signatures.push(value);
168
+ }
169
+ }
170
+ if (timestamp === undefined || !Number.isSafeInteger(timestamp) || signatures.length === 0) {
171
+ return undefined;
172
+ }
173
+ return {
174
+ signatures,
175
+ timestamp,
176
+ };
177
+ }
178
+ function timingSafeEqualString(left, right) {
179
+ const leftBuffer = Buffer.from(left, "hex");
180
+ const rightBuffer = Buffer.from(right, "hex");
181
+ return leftBuffer.length === rightBuffer.length && (0, node_crypto_1.timingSafeEqual)(leftBuffer, rightBuffer);
182
+ }
@@ -1,3 +1,3 @@
1
1
  export declare const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
2
- export declare const proxyCheckoutServerSdkVersion = "0.0.4-pr-76.21.1";
3
- export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.4-pr-76.21.1";
2
+ export declare const proxyCheckoutServerSdkVersion = "0.0.4-pr-76.22.1";
3
+ export declare const proxyCheckoutServerSdkUserAgent = "@proxy-checkout/server-js/0.0.4-pr-76.22.1";
@@ -1,3 +1,3 @@
1
1
  export const proxyCheckoutServerSdkName = "@proxy-checkout/server-js";
2
- export const proxyCheckoutServerSdkVersion = "0.0.4-pr-76.21.1";
2
+ export const proxyCheckoutServerSdkVersion = "0.0.4-pr-76.22.1";
3
3
  export const proxyCheckoutServerSdkUserAgent = `${proxyCheckoutServerSdkName}/${proxyCheckoutServerSdkVersion}`;
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "description": "Server-side JavaScript SDK for Proxy merchant API calls.",
3
3
  "license": "MIT",
4
- "module": "./dist/index.js",
4
+ "main": "./dist/cjs/index.js",
5
+ "module": "./dist/esm/index.js",
5
6
  "name": "@proxy-checkout/server-js",
6
7
  "private": false,
7
8
  "sideEffects": false,
8
9
  "type": "module",
9
- "types": "./dist/index.d.ts",
10
- "version": "0.0.4-pr-76.21.1",
10
+ "types": "./dist/esm/index.d.ts",
11
+ "version": "0.0.4-pr-76.22.1",
11
12
  "devDependencies": {
12
13
  "@types/node": "^24.12.4",
13
14
  "@vitest/coverage-v8": "4.1.7",
@@ -16,8 +17,9 @@
16
17
  },
17
18
  "exports": {
18
19
  ".": {
19
- "import": "./dist/index.js",
20
- "types": "./dist/index.d.ts"
20
+ "import": "./dist/esm/index.js",
21
+ "require": "./dist/cjs/index.js",
22
+ "types": "./dist/esm/index.d.ts"
21
23
  }
22
24
  },
23
25
  "files": [
@@ -40,7 +42,7 @@
40
42
  "url": "git+https://github.com/linuslabs/proxy.git"
41
43
  },
42
44
  "scripts": {
43
- "build": "tsc -p tsconfig.build.json",
45
+ "build": "node ../../tools/sdk/build-dual-package.mjs",
44
46
  "test:all": "vitest run",
45
47
  "test:coverage": "vitest run --coverage.enabled --coverage.reportsDirectory=coverage/all",
46
48
  "test:coverage:changed": "vitest run --coverage.enabled --coverage.reportsDirectory=coverage/changed",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes