@proxy-checkout/cli 0.1.0-prx-128.115.1 → 0.1.0-prx-124.118.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 +3 -1
- package/dist/cjs/cli.d.cts +1 -1
- package/dist/cjs/cli.d.ts +1 -1
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/generated/stripe-integration-capabilities-version.d.cts +1 -0
- package/dist/cjs/generated/stripe-integration-capabilities-version.d.ts +1 -0
- package/dist/cjs/generated/stripe-integration-capabilities-version.js +5 -0
- package/dist/cjs/stripe-profile.d.cts +13 -0
- package/dist/cjs/stripe-profile.d.ts +13 -0
- package/dist/cjs/stripe-profile.js +42 -0
- package/dist/cjs/webhooks.d.cts +6 -1
- package/dist/cjs/webhooks.d.ts +6 -1
- package/dist/cjs/webhooks.js +20 -18
- package/dist/esm/cli.d.ts +1 -1
- package/dist/esm/cli.js +1 -1
- package/dist/esm/generated/stripe-integration-capabilities-version.d.ts +1 -0
- package/dist/esm/generated/stripe-integration-capabilities-version.js +2 -0
- package/dist/esm/stripe-profile.d.ts +13 -0
- package/dist/esm/stripe-profile.js +38 -0
- package/dist/esm/webhooks.d.ts +6 -1
- package/dist/esm/webhooks.js +20 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,7 +64,9 @@ proxy listen \
|
|
|
64
64
|
--forward-to http://127.0.0.1:3000/webhooks
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
Before capturing a signing secret, the CLI asks the authenticated Proxy API for the exact sorted Stripe event union implied by Proxy's existing legacy lifecycle bridge plus the selected configuration's enabled capabilities. Both Stripe CLI processes use that union. Temporary-ingress creation includes a non-secret profile hash that Proxy recomputes under the configuration lock; stale or unsupported profiles fail before secret persistence. No separate local event list or new dashboard configuration is required.
|
|
68
|
+
|
|
69
|
+
Structured `stripe.started` output includes the selected configuration, effective capability IDs, exact events, manifest version, non-secret profile hash, ingress ID, and expiry for agent/CI evidence. The Stripe signing secret is captured only in child-process memory, never echoed or placed in argv, and stored only inside Proxy's existing encrypted temporary PSP ingress boundary. The CLI never receives the merchant's Stripe API credential. Both the Stripe ingress and local listener close on exit or expire server-side after a crash.
|
|
68
70
|
|
|
69
71
|
## Advanced delivery controls
|
|
70
72
|
|
package/dist/cjs/cli.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliConfigStore } from "./config.js";
|
|
2
2
|
import { type CliIo } from "./output.js";
|
|
3
|
-
export declare const cliVersion = "0.1.0-prx-
|
|
3
|
+
export declare const cliVersion = "0.1.0-prx-124.118.1";
|
|
4
4
|
export interface RunCliOptions {
|
|
5
5
|
configStore?: CliConfigStore;
|
|
6
6
|
environment?: NodeJS.ProcessEnv;
|
package/dist/cjs/cli.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliConfigStore } from "./config.js";
|
|
2
2
|
import { type CliIo } from "./output.js";
|
|
3
|
-
export declare const cliVersion = "0.1.0-prx-
|
|
3
|
+
export declare const cliVersion = "0.1.0-prx-124.118.1";
|
|
4
4
|
export interface RunCliOptions {
|
|
5
5
|
configStore?: CliConfigStore;
|
|
6
6
|
environment?: NodeJS.ProcessEnv;
|
package/dist/cjs/cli.js
CHANGED
|
@@ -9,7 +9,7 @@ const config_js_1 = require("./config.js");
|
|
|
9
9
|
const errors_js_1 = require("./errors.js");
|
|
10
10
|
const output_js_1 = require("./output.js");
|
|
11
11
|
const webhooks_js_1 = require("./webhooks.js");
|
|
12
|
-
exports.cliVersion = "0.1.0-prx-
|
|
12
|
+
exports.cliVersion = "0.1.0-prx-124.118.1";
|
|
13
13
|
async function runCli(argv, options = {}) {
|
|
14
14
|
const io = options.io ?? {
|
|
15
15
|
isTTY: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stripeIntegrationCapabilitiesManifestVersion: 2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stripeIntegrationCapabilitiesManifestVersion: 2;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripeIntegrationCapabilitiesManifestVersion = void 0;
|
|
4
|
+
// Generated by tools/compliance/sync-stripe-integration-capabilities.mjs.
|
|
5
|
+
exports.stripeIntegrationCapabilitiesManifestVersion = 2;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface StripeIngressProfileRecord {
|
|
2
|
+
effective_capability_ids: string[];
|
|
3
|
+
event_types: string[];
|
|
4
|
+
manifest_version: number;
|
|
5
|
+
merchant_psp_config_id: string;
|
|
6
|
+
profile_hash: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function validateStripeIngressProfile(profile: StripeIngressProfileRecord): StripeIngressProfileRecord;
|
|
9
|
+
export declare function assertCreatedStripeIngressProfile(expected: StripeIngressProfileRecord, actual: {
|
|
10
|
+
event_types: string[];
|
|
11
|
+
manifest_version: number;
|
|
12
|
+
profile_hash: string;
|
|
13
|
+
}): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface StripeIngressProfileRecord {
|
|
2
|
+
effective_capability_ids: string[];
|
|
3
|
+
event_types: string[];
|
|
4
|
+
manifest_version: number;
|
|
5
|
+
merchant_psp_config_id: string;
|
|
6
|
+
profile_hash: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function validateStripeIngressProfile(profile: StripeIngressProfileRecord): StripeIngressProfileRecord;
|
|
9
|
+
export declare function assertCreatedStripeIngressProfile(expected: StripeIngressProfileRecord, actual: {
|
|
10
|
+
event_types: string[];
|
|
11
|
+
manifest_version: number;
|
|
12
|
+
profile_hash: string;
|
|
13
|
+
}): void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateStripeIngressProfile = validateStripeIngressProfile;
|
|
4
|
+
exports.assertCreatedStripeIngressProfile = assertCreatedStripeIngressProfile;
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
const stripe_integration_capabilities_version_js_1 = require("./generated/stripe-integration-capabilities-version.js");
|
|
7
|
+
const stripeEventPattern = /^[a-z0-9_]+(?:\.[a-z0-9_]+)+$/;
|
|
8
|
+
const capabilityPattern = /^[a-z0-9_]+(?:\.[a-z0-9_]+)+$/;
|
|
9
|
+
const sha256Pattern = /^[0-9a-f]{64}$/;
|
|
10
|
+
const maximumEntries = 100;
|
|
11
|
+
function validateStripeIngressProfile(profile) {
|
|
12
|
+
if (profile.manifest_version !== stripe_integration_capabilities_version_js_1.stripeIntegrationCapabilitiesManifestVersion) {
|
|
13
|
+
throw profileError("Stripe ingress profile uses an incompatible manifest version");
|
|
14
|
+
}
|
|
15
|
+
if (!profile.merchant_psp_config_id.startsWith("pspcfg_") ||
|
|
16
|
+
!sha256Pattern.test(profile.profile_hash)) {
|
|
17
|
+
throw profileError("Stripe ingress profile identity is invalid");
|
|
18
|
+
}
|
|
19
|
+
assertSortedUnique(profile.event_types, stripeEventPattern, false, "event types");
|
|
20
|
+
assertSortedUnique(profile.effective_capability_ids, capabilityPattern, true, "capability ids");
|
|
21
|
+
return profile;
|
|
22
|
+
}
|
|
23
|
+
function assertCreatedStripeIngressProfile(expected, actual) {
|
|
24
|
+
assertSortedUnique(actual.event_types, stripeEventPattern, false, "event types");
|
|
25
|
+
if (actual.manifest_version !== expected.manifest_version ||
|
|
26
|
+
actual.profile_hash !== expected.profile_hash ||
|
|
27
|
+
JSON.stringify(actual.event_types) !== JSON.stringify(expected.event_types)) {
|
|
28
|
+
throw profileError("Stripe ingress profile changed while the listener was starting");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function assertSortedUnique(values, pattern, allowEmpty, label) {
|
|
32
|
+
if (!Array.isArray(values) ||
|
|
33
|
+
(!allowEmpty && values.length === 0) ||
|
|
34
|
+
values.length > maximumEntries ||
|
|
35
|
+
values.some((value) => !pattern.test(value)) ||
|
|
36
|
+
values.some((value, index) => index > 0 && values[index - 1] >= value)) {
|
|
37
|
+
throw profileError(`Stripe ingress profile ${label} are invalid`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function profileError(message) {
|
|
41
|
+
return new errors_js_1.CliError(message, "stripe_ingress_profile_unsupported", errors_js_1.cliExitCodes.dependency);
|
|
42
|
+
}
|
package/dist/cjs/webhooks.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CliOutput } from "./output.js";
|
|
2
|
+
import { type StripeIngressProfileRecord } from "./stripe-profile.js";
|
|
2
3
|
export interface WebhookEndpointRecord {
|
|
3
4
|
event_schema_version: string;
|
|
4
5
|
event_types: string[] | null;
|
|
@@ -44,12 +45,16 @@ export declare class ProxyWebhooksClient {
|
|
|
44
45
|
errorClass: "network_error" | "timeout" | null;
|
|
45
46
|
responseStatusCode: number | null;
|
|
46
47
|
}): Promise<unknown>;
|
|
47
|
-
createStripeIngress(listenerId: string, webhookSecret: string, pspConfigId?: string, signal?: AbortSignal): Promise<{
|
|
48
|
+
createStripeIngress(listenerId: string, webhookSecret: string, profileHash: string, pspConfigId?: string, signal?: AbortSignal): Promise<{
|
|
49
|
+
event_types: string[];
|
|
48
50
|
expires_at: string;
|
|
49
51
|
id: string;
|
|
50
52
|
inbound_url: string;
|
|
53
|
+
manifest_version: number;
|
|
51
54
|
merchant_psp_config_id: string;
|
|
55
|
+
profile_hash: string;
|
|
52
56
|
}>;
|
|
57
|
+
getStripeIngressProfile(listenerId: string, pspConfigId?: string, signal?: AbortSignal): Promise<StripeIngressProfileRecord>;
|
|
53
58
|
}
|
|
54
59
|
export declare function runListener(input: {
|
|
55
60
|
client: ProxyWebhooksClient;
|
package/dist/cjs/webhooks.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CliOutput } from "./output.js";
|
|
2
|
+
import { type StripeIngressProfileRecord } from "./stripe-profile.js";
|
|
2
3
|
export interface WebhookEndpointRecord {
|
|
3
4
|
event_schema_version: string;
|
|
4
5
|
event_types: string[] | null;
|
|
@@ -44,12 +45,16 @@ export declare class ProxyWebhooksClient {
|
|
|
44
45
|
errorClass: "network_error" | "timeout" | null;
|
|
45
46
|
responseStatusCode: number | null;
|
|
46
47
|
}): Promise<unknown>;
|
|
47
|
-
createStripeIngress(listenerId: string, webhookSecret: string, pspConfigId?: string, signal?: AbortSignal): Promise<{
|
|
48
|
+
createStripeIngress(listenerId: string, webhookSecret: string, profileHash: string, pspConfigId?: string, signal?: AbortSignal): Promise<{
|
|
49
|
+
event_types: string[];
|
|
48
50
|
expires_at: string;
|
|
49
51
|
id: string;
|
|
50
52
|
inbound_url: string;
|
|
53
|
+
manifest_version: number;
|
|
51
54
|
merchant_psp_config_id: string;
|
|
55
|
+
profile_hash: string;
|
|
52
56
|
}>;
|
|
57
|
+
getStripeIngressProfile(listenerId: string, pspConfigId?: string, signal?: AbortSignal): Promise<StripeIngressProfileRecord>;
|
|
53
58
|
}
|
|
54
59
|
export declare function runListener(input: {
|
|
55
60
|
client: ProxyWebhooksClient;
|
package/dist/cjs/webhooks.js
CHANGED
|
@@ -7,19 +7,10 @@ const node_child_process_1 = require("node:child_process");
|
|
|
7
7
|
const errors_js_1 = require("./errors.js");
|
|
8
8
|
const http_client_js_1 = require("./http-client.js");
|
|
9
9
|
const output_js_1 = require("./output.js");
|
|
10
|
+
const stripe_profile_js_1 = require("./stripe-profile.js");
|
|
10
11
|
const claimPollIntervalMs = 1_000;
|
|
11
12
|
const heartbeatIntervalMs = 30_000;
|
|
12
13
|
const localForwardTimeoutMs = 30_000;
|
|
13
|
-
const stripeEvents = [
|
|
14
|
-
"checkout.session.completed",
|
|
15
|
-
"customer.subscription.deleted",
|
|
16
|
-
"customer.subscription.updated",
|
|
17
|
-
"invoice.paid",
|
|
18
|
-
"invoice.payment_failed",
|
|
19
|
-
"payment_intent.canceled",
|
|
20
|
-
"payment_intent.payment_failed",
|
|
21
|
-
"payment_intent.succeeded",
|
|
22
|
-
].join(",");
|
|
23
14
|
class ProxyWebhooksClient {
|
|
24
15
|
api;
|
|
25
16
|
constructor(apiBaseUrl, token, fetchImpl) {
|
|
@@ -73,16 +64,21 @@ class ProxyWebhooksClient {
|
|
|
73
64
|
},
|
|
74
65
|
});
|
|
75
66
|
}
|
|
76
|
-
async createStripeIngress(listenerId, webhookSecret, pspConfigId, signal) {
|
|
67
|
+
async createStripeIngress(listenerId, webhookSecret, profileHash, pspConfigId, signal) {
|
|
77
68
|
return (await this.api.request(`/cli/webhook-listeners/${encodeURIComponent(listenerId)}/stripe-ingress`, {
|
|
78
69
|
method: "POST",
|
|
79
70
|
body: {
|
|
80
71
|
...(pspConfigId ? { psp_config_id: pspConfigId } : {}),
|
|
72
|
+
profile_hash: profileHash,
|
|
81
73
|
webhook_secret: webhookSecret,
|
|
82
74
|
},
|
|
83
75
|
signal,
|
|
84
76
|
})).stripe_ingress;
|
|
85
77
|
}
|
|
78
|
+
async getStripeIngressProfile(listenerId, pspConfigId, signal) {
|
|
79
|
+
const query = pspConfigId ? `?${new URLSearchParams({ psp_config_id: pspConfigId })}` : "";
|
|
80
|
+
return (await this.api.request(`/cli/webhook-listeners/${encodeURIComponent(listenerId)}/stripe-ingress-profile${query}`, { signal })).stripe_ingress_profile;
|
|
81
|
+
}
|
|
86
82
|
}
|
|
87
83
|
exports.ProxyWebhooksClient = ProxyWebhooksClient;
|
|
88
84
|
async function runListener(input) {
|
|
@@ -103,15 +99,21 @@ async function runListener(input) {
|
|
|
103
99
|
if (input.signal.aborted)
|
|
104
100
|
throw listenerInterrupted();
|
|
105
101
|
if (input.stripe) {
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
102
|
+
const stripeProfile = (0, stripe_profile_js_1.validateStripeIngressProfile)(await input.client.getStripeIngressProfile(listener.id, input.pspConfigId, input.signal));
|
|
103
|
+
const webhookSecret = await captureStripeWebhookSecret(stripeProfile.event_types, input.signal);
|
|
104
|
+
const ingress = await input.client.createStripeIngress(listener.id, webhookSecret, stripeProfile.profile_hash, input.pspConfigId, input.signal);
|
|
105
|
+
(0, stripe_profile_js_1.assertCreatedStripeIngressProfile)(stripeProfile, ingress);
|
|
106
|
+
stripeProcess = await startStripeListener(ingress.inbound_url, ingress.event_types, input.output, (error) => {
|
|
109
107
|
stripeProcessFailure = stripeListenerStartError(error);
|
|
110
108
|
});
|
|
111
109
|
input.output.event("stripe.started", {
|
|
110
|
+
effective_capability_ids: stripeProfile.effective_capability_ids,
|
|
111
|
+
event_types: ingress.event_types,
|
|
112
112
|
expires_at: ingress.expires_at,
|
|
113
113
|
ingress_id: ingress.id,
|
|
114
|
+
manifest_version: ingress.manifest_version,
|
|
114
115
|
merchant_psp_config_id: ingress.merchant_psp_config_id,
|
|
116
|
+
profile_hash: ingress.profile_hash,
|
|
115
117
|
}, "Stripe CLI test webhook orchestration is active.");
|
|
116
118
|
}
|
|
117
119
|
if (input.signal.aborted)
|
|
@@ -216,8 +218,8 @@ async function forwardClaim(client, claim, destination, signal) {
|
|
|
216
218
|
responseStatusCode,
|
|
217
219
|
});
|
|
218
220
|
}
|
|
219
|
-
async function captureStripeWebhookSecret(signal) {
|
|
220
|
-
const result = await captureProcess("stripe", ["listen", "--events",
|
|
221
|
+
async function captureStripeWebhookSecret(eventTypes, signal) {
|
|
222
|
+
const result = await captureProcess("stripe", ["listen", "--events", eventTypes.join(","), "--print-secret"], signal, 30_000);
|
|
221
223
|
if (signal.aborted)
|
|
222
224
|
throw listenerInterrupted();
|
|
223
225
|
const match = `${result.stdout}\n${result.stderr}`.match(/\bwhsec_[A-Za-z0-9_-]{8,512}\b/);
|
|
@@ -229,8 +231,8 @@ async function captureStripeWebhookSecret(signal) {
|
|
|
229
231
|
function listenerInterrupted() {
|
|
230
232
|
return new errors_js_1.CliError("Local webhook listener interrupted", "cli_listener_interrupted", errors_js_1.cliExitCodes.interrupted);
|
|
231
233
|
}
|
|
232
|
-
function startStripeListener(inboundUrl, output, onError) {
|
|
233
|
-
const child = (0, node_child_process_1.spawn)("stripe", ["listen", "--events",
|
|
234
|
+
function startStripeListener(inboundUrl, eventTypes, output, onError) {
|
|
235
|
+
const child = (0, node_child_process_1.spawn)("stripe", ["listen", "--events", eventTypes.join(","), "--forward-to", inboundUrl], {
|
|
234
236
|
shell: false,
|
|
235
237
|
stdio: ["pipe", "pipe", "pipe"],
|
|
236
238
|
});
|
package/dist/esm/cli.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliConfigStore } from "./config.js";
|
|
2
2
|
import { type CliIo } from "./output.js";
|
|
3
|
-
export declare const cliVersion = "0.1.0-prx-
|
|
3
|
+
export declare const cliVersion = "0.1.0-prx-124.118.1";
|
|
4
4
|
export interface RunCliOptions {
|
|
5
5
|
configStore?: CliConfigStore;
|
|
6
6
|
environment?: NodeJS.ProcessEnv;
|
package/dist/esm/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import { CliConfigStore } from "./config.js";
|
|
|
5
5
|
import { asCliError, CliError, cliExitCodes, usageError } from "./errors.js";
|
|
6
6
|
import { CliOutput } from "./output.js";
|
|
7
7
|
import { forwardSelectedDelivery, ProxyWebhooksClient, runListener, } from "./webhooks.js";
|
|
8
|
-
export const cliVersion = "0.1.0-prx-
|
|
8
|
+
export const cliVersion = "0.1.0-prx-124.118.1";
|
|
9
9
|
export async function runCli(argv, options = {}) {
|
|
10
10
|
const io = options.io ?? {
|
|
11
11
|
isTTY: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stripeIntegrationCapabilitiesManifestVersion: 2;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface StripeIngressProfileRecord {
|
|
2
|
+
effective_capability_ids: string[];
|
|
3
|
+
event_types: string[];
|
|
4
|
+
manifest_version: number;
|
|
5
|
+
merchant_psp_config_id: string;
|
|
6
|
+
profile_hash: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function validateStripeIngressProfile(profile: StripeIngressProfileRecord): StripeIngressProfileRecord;
|
|
9
|
+
export declare function assertCreatedStripeIngressProfile(expected: StripeIngressProfileRecord, actual: {
|
|
10
|
+
event_types: string[];
|
|
11
|
+
manifest_version: number;
|
|
12
|
+
profile_hash: string;
|
|
13
|
+
}): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CliError, cliExitCodes } from "./errors.js";
|
|
2
|
+
import { stripeIntegrationCapabilitiesManifestVersion } from "./generated/stripe-integration-capabilities-version.js";
|
|
3
|
+
const stripeEventPattern = /^[a-z0-9_]+(?:\.[a-z0-9_]+)+$/;
|
|
4
|
+
const capabilityPattern = /^[a-z0-9_]+(?:\.[a-z0-9_]+)+$/;
|
|
5
|
+
const sha256Pattern = /^[0-9a-f]{64}$/;
|
|
6
|
+
const maximumEntries = 100;
|
|
7
|
+
export function validateStripeIngressProfile(profile) {
|
|
8
|
+
if (profile.manifest_version !== stripeIntegrationCapabilitiesManifestVersion) {
|
|
9
|
+
throw profileError("Stripe ingress profile uses an incompatible manifest version");
|
|
10
|
+
}
|
|
11
|
+
if (!profile.merchant_psp_config_id.startsWith("pspcfg_") ||
|
|
12
|
+
!sha256Pattern.test(profile.profile_hash)) {
|
|
13
|
+
throw profileError("Stripe ingress profile identity is invalid");
|
|
14
|
+
}
|
|
15
|
+
assertSortedUnique(profile.event_types, stripeEventPattern, false, "event types");
|
|
16
|
+
assertSortedUnique(profile.effective_capability_ids, capabilityPattern, true, "capability ids");
|
|
17
|
+
return profile;
|
|
18
|
+
}
|
|
19
|
+
export function assertCreatedStripeIngressProfile(expected, actual) {
|
|
20
|
+
assertSortedUnique(actual.event_types, stripeEventPattern, false, "event types");
|
|
21
|
+
if (actual.manifest_version !== expected.manifest_version ||
|
|
22
|
+
actual.profile_hash !== expected.profile_hash ||
|
|
23
|
+
JSON.stringify(actual.event_types) !== JSON.stringify(expected.event_types)) {
|
|
24
|
+
throw profileError("Stripe ingress profile changed while the listener was starting");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function assertSortedUnique(values, pattern, allowEmpty, label) {
|
|
28
|
+
if (!Array.isArray(values) ||
|
|
29
|
+
(!allowEmpty && values.length === 0) ||
|
|
30
|
+
values.length > maximumEntries ||
|
|
31
|
+
values.some((value) => !pattern.test(value)) ||
|
|
32
|
+
values.some((value, index) => index > 0 && values[index - 1] >= value)) {
|
|
33
|
+
throw profileError(`Stripe ingress profile ${label} are invalid`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function profileError(message) {
|
|
37
|
+
return new CliError(message, "stripe_ingress_profile_unsupported", cliExitCodes.dependency);
|
|
38
|
+
}
|
package/dist/esm/webhooks.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CliOutput } from "./output.js";
|
|
2
|
+
import { type StripeIngressProfileRecord } from "./stripe-profile.js";
|
|
2
3
|
export interface WebhookEndpointRecord {
|
|
3
4
|
event_schema_version: string;
|
|
4
5
|
event_types: string[] | null;
|
|
@@ -44,12 +45,16 @@ export declare class ProxyWebhooksClient {
|
|
|
44
45
|
errorClass: "network_error" | "timeout" | null;
|
|
45
46
|
responseStatusCode: number | null;
|
|
46
47
|
}): Promise<unknown>;
|
|
47
|
-
createStripeIngress(listenerId: string, webhookSecret: string, pspConfigId?: string, signal?: AbortSignal): Promise<{
|
|
48
|
+
createStripeIngress(listenerId: string, webhookSecret: string, profileHash: string, pspConfigId?: string, signal?: AbortSignal): Promise<{
|
|
49
|
+
event_types: string[];
|
|
48
50
|
expires_at: string;
|
|
49
51
|
id: string;
|
|
50
52
|
inbound_url: string;
|
|
53
|
+
manifest_version: number;
|
|
51
54
|
merchant_psp_config_id: string;
|
|
55
|
+
profile_hash: string;
|
|
52
56
|
}>;
|
|
57
|
+
getStripeIngressProfile(listenerId: string, pspConfigId?: string, signal?: AbortSignal): Promise<StripeIngressProfileRecord>;
|
|
53
58
|
}
|
|
54
59
|
export declare function runListener(input: {
|
|
55
60
|
client: ProxyWebhooksClient;
|
package/dist/esm/webhooks.js
CHANGED
|
@@ -2,19 +2,10 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { CliError, cliExitCodes } from "./errors.js";
|
|
3
3
|
import { ProxyApiClient } from "./http-client.js";
|
|
4
4
|
import { redactText } from "./output.js";
|
|
5
|
+
import { assertCreatedStripeIngressProfile, validateStripeIngressProfile, } from "./stripe-profile.js";
|
|
5
6
|
const claimPollIntervalMs = 1_000;
|
|
6
7
|
const heartbeatIntervalMs = 30_000;
|
|
7
8
|
const localForwardTimeoutMs = 30_000;
|
|
8
|
-
const stripeEvents = [
|
|
9
|
-
"checkout.session.completed",
|
|
10
|
-
"customer.subscription.deleted",
|
|
11
|
-
"customer.subscription.updated",
|
|
12
|
-
"invoice.paid",
|
|
13
|
-
"invoice.payment_failed",
|
|
14
|
-
"payment_intent.canceled",
|
|
15
|
-
"payment_intent.payment_failed",
|
|
16
|
-
"payment_intent.succeeded",
|
|
17
|
-
].join(",");
|
|
18
9
|
export class ProxyWebhooksClient {
|
|
19
10
|
api;
|
|
20
11
|
constructor(apiBaseUrl, token, fetchImpl) {
|
|
@@ -68,16 +59,21 @@ export class ProxyWebhooksClient {
|
|
|
68
59
|
},
|
|
69
60
|
});
|
|
70
61
|
}
|
|
71
|
-
async createStripeIngress(listenerId, webhookSecret, pspConfigId, signal) {
|
|
62
|
+
async createStripeIngress(listenerId, webhookSecret, profileHash, pspConfigId, signal) {
|
|
72
63
|
return (await this.api.request(`/cli/webhook-listeners/${encodeURIComponent(listenerId)}/stripe-ingress`, {
|
|
73
64
|
method: "POST",
|
|
74
65
|
body: {
|
|
75
66
|
...(pspConfigId ? { psp_config_id: pspConfigId } : {}),
|
|
67
|
+
profile_hash: profileHash,
|
|
76
68
|
webhook_secret: webhookSecret,
|
|
77
69
|
},
|
|
78
70
|
signal,
|
|
79
71
|
})).stripe_ingress;
|
|
80
72
|
}
|
|
73
|
+
async getStripeIngressProfile(listenerId, pspConfigId, signal) {
|
|
74
|
+
const query = pspConfigId ? `?${new URLSearchParams({ psp_config_id: pspConfigId })}` : "";
|
|
75
|
+
return (await this.api.request(`/cli/webhook-listeners/${encodeURIComponent(listenerId)}/stripe-ingress-profile${query}`, { signal })).stripe_ingress_profile;
|
|
76
|
+
}
|
|
81
77
|
}
|
|
82
78
|
export async function runListener(input) {
|
|
83
79
|
const destination = validateLoopbackDestination(input.forwardTo);
|
|
@@ -97,15 +93,21 @@ export async function runListener(input) {
|
|
|
97
93
|
if (input.signal.aborted)
|
|
98
94
|
throw listenerInterrupted();
|
|
99
95
|
if (input.stripe) {
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
|
|
96
|
+
const stripeProfile = validateStripeIngressProfile(await input.client.getStripeIngressProfile(listener.id, input.pspConfigId, input.signal));
|
|
97
|
+
const webhookSecret = await captureStripeWebhookSecret(stripeProfile.event_types, input.signal);
|
|
98
|
+
const ingress = await input.client.createStripeIngress(listener.id, webhookSecret, stripeProfile.profile_hash, input.pspConfigId, input.signal);
|
|
99
|
+
assertCreatedStripeIngressProfile(stripeProfile, ingress);
|
|
100
|
+
stripeProcess = await startStripeListener(ingress.inbound_url, ingress.event_types, input.output, (error) => {
|
|
103
101
|
stripeProcessFailure = stripeListenerStartError(error);
|
|
104
102
|
});
|
|
105
103
|
input.output.event("stripe.started", {
|
|
104
|
+
effective_capability_ids: stripeProfile.effective_capability_ids,
|
|
105
|
+
event_types: ingress.event_types,
|
|
106
106
|
expires_at: ingress.expires_at,
|
|
107
107
|
ingress_id: ingress.id,
|
|
108
|
+
manifest_version: ingress.manifest_version,
|
|
108
109
|
merchant_psp_config_id: ingress.merchant_psp_config_id,
|
|
110
|
+
profile_hash: ingress.profile_hash,
|
|
109
111
|
}, "Stripe CLI test webhook orchestration is active.");
|
|
110
112
|
}
|
|
111
113
|
if (input.signal.aborted)
|
|
@@ -210,8 +212,8 @@ async function forwardClaim(client, claim, destination, signal) {
|
|
|
210
212
|
responseStatusCode,
|
|
211
213
|
});
|
|
212
214
|
}
|
|
213
|
-
async function captureStripeWebhookSecret(signal) {
|
|
214
|
-
const result = await captureProcess("stripe", ["listen", "--events",
|
|
215
|
+
async function captureStripeWebhookSecret(eventTypes, signal) {
|
|
216
|
+
const result = await captureProcess("stripe", ["listen", "--events", eventTypes.join(","), "--print-secret"], signal, 30_000);
|
|
215
217
|
if (signal.aborted)
|
|
216
218
|
throw listenerInterrupted();
|
|
217
219
|
const match = `${result.stdout}\n${result.stderr}`.match(/\bwhsec_[A-Za-z0-9_-]{8,512}\b/);
|
|
@@ -223,8 +225,8 @@ async function captureStripeWebhookSecret(signal) {
|
|
|
223
225
|
function listenerInterrupted() {
|
|
224
226
|
return new CliError("Local webhook listener interrupted", "cli_listener_interrupted", cliExitCodes.interrupted);
|
|
225
227
|
}
|
|
226
|
-
function startStripeListener(inboundUrl, output, onError) {
|
|
227
|
-
const child = spawn("stripe", ["listen", "--events",
|
|
228
|
+
function startStripeListener(inboundUrl, eventTypes, output, onError) {
|
|
229
|
+
const child = spawn("stripe", ["listen", "--events", eventTypes.join(","), "--forward-to", inboundUrl], {
|
|
228
230
|
shell: false,
|
|
229
231
|
stdio: ["pipe", "pipe", "pipe"],
|
|
230
232
|
});
|