@proxy-checkout/cli 0.1.0-prx-128.104.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/LICENSE +21 -0
- package/README.md +128 -0
- package/dist/cjs/auth.d.cts +38 -0
- package/dist/cjs/auth.d.ts +38 -0
- package/dist/cjs/auth.js +258 -0
- package/dist/cjs/bin.d.cts +2 -0
- package/dist/cjs/bin.d.ts +2 -0
- package/dist/cjs/bin.js +10 -0
- package/dist/cjs/cli.d.cts +10 -0
- package/dist/cjs/cli.d.ts +10 -0
- package/dist/cjs/cli.js +469 -0
- package/dist/cjs/command-schema.d.cts +23 -0
- package/dist/cjs/command-schema.d.ts +23 -0
- package/dist/cjs/command-schema.js +238 -0
- package/dist/cjs/config.d.cts +55 -0
- package/dist/cjs/config.d.ts +55 -0
- package/dist/cjs/config.js +339 -0
- package/dist/cjs/errors.d.cts +20 -0
- package/dist/cjs/errors.d.ts +20 -0
- package/dist/cjs/errors.js +52 -0
- package/dist/cjs/http-client.d.cts +25 -0
- package/dist/cjs/http-client.d.ts +25 -0
- package/dist/cjs/http-client.js +102 -0
- package/dist/cjs/index.d.cts +5 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +17 -0
- package/dist/cjs/output.d.cts +19 -0
- package/dist/cjs/output.d.ts +19 -0
- package/dist/cjs/output.js +76 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/webhooks.d.cts +81 -0
- package/dist/cjs/webhooks.d.ts +81 -0
- package/dist/cjs/webhooks.js +343 -0
- package/dist/esm/auth.d.ts +38 -0
- package/dist/esm/auth.js +253 -0
- package/dist/esm/bin.d.ts +2 -0
- package/dist/esm/bin.js +8 -0
- package/dist/esm/cli.d.ts +10 -0
- package/dist/esm/cli.js +465 -0
- package/dist/esm/command-schema.d.ts +23 -0
- package/dist/esm/command-schema.js +232 -0
- package/dist/esm/config.d.ts +55 -0
- package/dist/esm/config.js +333 -0
- package/dist/esm/errors.d.ts +20 -0
- package/dist/esm/errors.js +46 -0
- package/dist/esm/http-client.d.ts +25 -0
- package/dist/esm/http-client.js +98 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/output.d.ts +19 -0
- package/dist/esm/output.js +71 -0
- package/dist/esm/webhooks.d.ts +81 -0
- package/dist/esm/webhooks.js +337 -0
- package/package.json +68 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const cliExitCodes: {
|
|
2
|
+
readonly authentication: 3;
|
|
3
|
+
readonly conflict: 6;
|
|
4
|
+
readonly dependency: 7;
|
|
5
|
+
readonly internal: 10;
|
|
6
|
+
readonly interrupted: 8;
|
|
7
|
+
readonly network: 4;
|
|
8
|
+
readonly permission: 5;
|
|
9
|
+
readonly success: 0;
|
|
10
|
+
readonly usage: 2;
|
|
11
|
+
};
|
|
12
|
+
export type CliExitCode = (typeof cliExitCodes)[keyof typeof cliExitCodes];
|
|
13
|
+
export declare class CliError extends Error {
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly exitCode: CliExitCode;
|
|
16
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
17
|
+
constructor(message: string, code: string, exitCode: CliExitCode, details?: Record<string, unknown> | undefined);
|
|
18
|
+
}
|
|
19
|
+
export declare function usageError(message: string, details?: Record<string, unknown>): CliError;
|
|
20
|
+
export declare function asCliError(error: unknown): CliError;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const cliExitCodes: {
|
|
2
|
+
readonly authentication: 3;
|
|
3
|
+
readonly conflict: 6;
|
|
4
|
+
readonly dependency: 7;
|
|
5
|
+
readonly internal: 10;
|
|
6
|
+
readonly interrupted: 8;
|
|
7
|
+
readonly network: 4;
|
|
8
|
+
readonly permission: 5;
|
|
9
|
+
readonly success: 0;
|
|
10
|
+
readonly usage: 2;
|
|
11
|
+
};
|
|
12
|
+
export type CliExitCode = (typeof cliExitCodes)[keyof typeof cliExitCodes];
|
|
13
|
+
export declare class CliError extends Error {
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly exitCode: CliExitCode;
|
|
16
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
17
|
+
constructor(message: string, code: string, exitCode: CliExitCode, details?: Record<string, unknown> | undefined);
|
|
18
|
+
}
|
|
19
|
+
export declare function usageError(message: string, details?: Record<string, unknown>): CliError;
|
|
20
|
+
export declare function asCliError(error: unknown): CliError;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CliError = exports.cliExitCodes = void 0;
|
|
4
|
+
exports.usageError = usageError;
|
|
5
|
+
exports.asCliError = asCliError;
|
|
6
|
+
exports.cliExitCodes = {
|
|
7
|
+
authentication: 3,
|
|
8
|
+
conflict: 6,
|
|
9
|
+
dependency: 7,
|
|
10
|
+
internal: 10,
|
|
11
|
+
interrupted: 8,
|
|
12
|
+
network: 4,
|
|
13
|
+
permission: 5,
|
|
14
|
+
success: 0,
|
|
15
|
+
usage: 2,
|
|
16
|
+
};
|
|
17
|
+
class CliError extends Error {
|
|
18
|
+
code;
|
|
19
|
+
exitCode;
|
|
20
|
+
details;
|
|
21
|
+
constructor(message, code, exitCode, details) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.code = code;
|
|
24
|
+
this.exitCode = exitCode;
|
|
25
|
+
this.details = details;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.CliError = CliError;
|
|
29
|
+
function usageError(message, details) {
|
|
30
|
+
return new CliError(message, "usage_error", exports.cliExitCodes.usage, details);
|
|
31
|
+
}
|
|
32
|
+
function asCliError(error) {
|
|
33
|
+
if (error instanceof CliError) {
|
|
34
|
+
return error;
|
|
35
|
+
}
|
|
36
|
+
if (isStructurallyValidCliError(error)) {
|
|
37
|
+
return new CliError(error.message, error.code, error.exitCode, error.details);
|
|
38
|
+
}
|
|
39
|
+
return new CliError("Unexpected CLI error", "internal_error", exports.cliExitCodes.internal, {
|
|
40
|
+
error_class: error instanceof Error ? error.name : typeof error,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function isStructurallyValidCliError(error) {
|
|
44
|
+
return (error instanceof Error &&
|
|
45
|
+
typeof error.code === "string" &&
|
|
46
|
+
error.code?.length !== 0 &&
|
|
47
|
+
Object.values(exports.cliExitCodes).includes(error.exitCode) &&
|
|
48
|
+
(error.details === undefined ||
|
|
49
|
+
(typeof error.details === "object" &&
|
|
50
|
+
error.details !== null &&
|
|
51
|
+
!Array.isArray(error.details))));
|
|
52
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface ProxyApiErrorBody {
|
|
2
|
+
error?: {
|
|
3
|
+
code?: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
request_id?: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare class ProxyApiClient {
|
|
9
|
+
readonly baseUrl: string;
|
|
10
|
+
private readonly token?;
|
|
11
|
+
private readonly fetchImpl;
|
|
12
|
+
constructor(baseUrl: string, token?: string | undefined, fetchImpl?: typeof fetch);
|
|
13
|
+
request<T>(path: string, options?: {
|
|
14
|
+
body?: unknown;
|
|
15
|
+
method?: "DELETE" | "GET" | "PATCH" | "POST";
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}): Promise<T>;
|
|
18
|
+
oauthRequest<T>(path: string, body: unknown, options?: {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
body: T | Record<string, unknown>;
|
|
22
|
+
ok: boolean;
|
|
23
|
+
status: number;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface ProxyApiErrorBody {
|
|
2
|
+
error?: {
|
|
3
|
+
code?: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
request_id?: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare class ProxyApiClient {
|
|
9
|
+
readonly baseUrl: string;
|
|
10
|
+
private readonly token?;
|
|
11
|
+
private readonly fetchImpl;
|
|
12
|
+
constructor(baseUrl: string, token?: string | undefined, fetchImpl?: typeof fetch);
|
|
13
|
+
request<T>(path: string, options?: {
|
|
14
|
+
body?: unknown;
|
|
15
|
+
method?: "DELETE" | "GET" | "PATCH" | "POST";
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}): Promise<T>;
|
|
18
|
+
oauthRequest<T>(path: string, body: unknown, options?: {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
body: T | Record<string, unknown>;
|
|
22
|
+
ok: boolean;
|
|
23
|
+
status: number;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProxyApiClient = void 0;
|
|
4
|
+
const errors_js_1 = require("./errors.js");
|
|
5
|
+
const requestTimeoutMs = 30_000;
|
|
6
|
+
class ProxyApiClient {
|
|
7
|
+
baseUrl;
|
|
8
|
+
token;
|
|
9
|
+
fetchImpl;
|
|
10
|
+
constructor(baseUrl, token, fetchImpl = fetch) {
|
|
11
|
+
this.baseUrl = baseUrl;
|
|
12
|
+
this.token = token;
|
|
13
|
+
this.fetchImpl = fetchImpl;
|
|
14
|
+
}
|
|
15
|
+
async request(path, options = {}) {
|
|
16
|
+
let response;
|
|
17
|
+
try {
|
|
18
|
+
response = await this.fetchImpl(new URL(path, `${this.baseUrl}/`), {
|
|
19
|
+
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
|
20
|
+
method: options.method ?? "GET",
|
|
21
|
+
redirect: "manual",
|
|
22
|
+
signal: requestSignal(options.signal),
|
|
23
|
+
headers: {
|
|
24
|
+
accept: "application/json",
|
|
25
|
+
...(options.body === undefined ? {} : { "content-type": "application/json" }),
|
|
26
|
+
...(this.token ? { authorization: `Bearer ${this.token}` } : {}),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (options.signal?.aborted)
|
|
32
|
+
throw commandInterrupted();
|
|
33
|
+
throw new errors_js_1.CliError("Could not reach the Proxy API", "cli_network_error", errors_js_1.cliExitCodes.network, { error_class: error instanceof Error ? error.name : typeof error });
|
|
34
|
+
}
|
|
35
|
+
const body = await readJson(response);
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const errorBody = isRecord(body) ? body : {};
|
|
38
|
+
const code = errorBody.error?.code ?? `http_${response.status}`;
|
|
39
|
+
const message = errorBody.error?.message ?? `Proxy API request failed with HTTP ${response.status}`;
|
|
40
|
+
throw new errors_js_1.CliError(message, code, exitCodeForStatus(response.status), {
|
|
41
|
+
request_id: errorBody.error?.request_id,
|
|
42
|
+
status: response.status,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return body;
|
|
46
|
+
}
|
|
47
|
+
async oauthRequest(path, body, options = {}) {
|
|
48
|
+
let response;
|
|
49
|
+
try {
|
|
50
|
+
response = await this.fetchImpl(new URL(path, `${this.baseUrl}/`), {
|
|
51
|
+
body: JSON.stringify(body),
|
|
52
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
53
|
+
method: "POST",
|
|
54
|
+
redirect: "manual",
|
|
55
|
+
signal: requestSignal(options.signal),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (options.signal?.aborted)
|
|
60
|
+
throw commandInterrupted();
|
|
61
|
+
throw new errors_js_1.CliError("Could not reach the Proxy authentication service", "cli_network_error", errors_js_1.cliExitCodes.network, { error_class: error instanceof Error ? error.name : typeof error });
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
body: (await readJson(response)),
|
|
65
|
+
ok: response.ok,
|
|
66
|
+
status: response.status,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ProxyApiClient = ProxyApiClient;
|
|
71
|
+
function requestSignal(signal) {
|
|
72
|
+
const timeout = AbortSignal.timeout(requestTimeoutMs);
|
|
73
|
+
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
74
|
+
}
|
|
75
|
+
function commandInterrupted() {
|
|
76
|
+
return new errors_js_1.CliError("CLI command interrupted", "cli_command_interrupted", errors_js_1.cliExitCodes.interrupted);
|
|
77
|
+
}
|
|
78
|
+
function exitCodeForStatus(status) {
|
|
79
|
+
if (status === 401)
|
|
80
|
+
return errors_js_1.cliExitCodes.authentication;
|
|
81
|
+
if (status === 403)
|
|
82
|
+
return errors_js_1.cliExitCodes.permission;
|
|
83
|
+
if (status === 409)
|
|
84
|
+
return errors_js_1.cliExitCodes.conflict;
|
|
85
|
+
if (status >= 500 || status === 429)
|
|
86
|
+
return errors_js_1.cliExitCodes.network;
|
|
87
|
+
return errors_js_1.cliExitCodes.usage;
|
|
88
|
+
}
|
|
89
|
+
async function readJson(response) {
|
|
90
|
+
const text = await response.text();
|
|
91
|
+
if (!text)
|
|
92
|
+
return {};
|
|
93
|
+
try {
|
|
94
|
+
return JSON.parse(text);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
throw new errors_js_1.CliError("Proxy API returned an invalid response", "cli_invalid_api_response", errors_js_1.cliExitCodes.network, { status: response.status });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function isRecord(value) {
|
|
101
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
102
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { cliVersion, type RunCliOptions, runCli } from "./cli.js";
|
|
2
|
+
export { type CommandOptionSchema, type CommandSchema, commandSchemaDocument, commandSchemas, findCommandSchema, llmsFullDocument, } from "./command-schema.js";
|
|
3
|
+
export { CliConfigStore, type CliProfile, type ResolvedCredential } from "./config.js";
|
|
4
|
+
export { CliError, type CliExitCode, cliExitCodes } from "./errors.js";
|
|
5
|
+
export declare const packageName = "@proxy-checkout/cli";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { cliVersion, type RunCliOptions, runCli } from "./cli.js";
|
|
2
|
+
export { type CommandOptionSchema, type CommandSchema, commandSchemaDocument, commandSchemas, findCommandSchema, llmsFullDocument, } from "./command-schema.js";
|
|
3
|
+
export { CliConfigStore, type CliProfile, type ResolvedCredential } from "./config.js";
|
|
4
|
+
export { CliError, type CliExitCode, cliExitCodes } from "./errors.js";
|
|
5
|
+
export declare const packageName = "@proxy-checkout/cli";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.packageName = exports.cliExitCodes = exports.CliError = exports.CliConfigStore = exports.llmsFullDocument = exports.findCommandSchema = exports.commandSchemas = exports.commandSchemaDocument = exports.runCli = exports.cliVersion = void 0;
|
|
4
|
+
var cli_js_1 = require("./cli.js");
|
|
5
|
+
Object.defineProperty(exports, "cliVersion", { enumerable: true, get: function () { return cli_js_1.cliVersion; } });
|
|
6
|
+
Object.defineProperty(exports, "runCli", { enumerable: true, get: function () { return cli_js_1.runCli; } });
|
|
7
|
+
var command_schema_js_1 = require("./command-schema.js");
|
|
8
|
+
Object.defineProperty(exports, "commandSchemaDocument", { enumerable: true, get: function () { return command_schema_js_1.commandSchemaDocument; } });
|
|
9
|
+
Object.defineProperty(exports, "commandSchemas", { enumerable: true, get: function () { return command_schema_js_1.commandSchemas; } });
|
|
10
|
+
Object.defineProperty(exports, "findCommandSchema", { enumerable: true, get: function () { return command_schema_js_1.findCommandSchema; } });
|
|
11
|
+
Object.defineProperty(exports, "llmsFullDocument", { enumerable: true, get: function () { return command_schema_js_1.llmsFullDocument; } });
|
|
12
|
+
var config_js_1 = require("./config.js");
|
|
13
|
+
Object.defineProperty(exports, "CliConfigStore", { enumerable: true, get: function () { return config_js_1.CliConfigStore; } });
|
|
14
|
+
var errors_js_1 = require("./errors.js");
|
|
15
|
+
Object.defineProperty(exports, "CliError", { enumerable: true, get: function () { return errors_js_1.CliError; } });
|
|
16
|
+
Object.defineProperty(exports, "cliExitCodes", { enumerable: true, get: function () { return errors_js_1.cliExitCodes; } });
|
|
17
|
+
exports.packageName = "@proxy-checkout/cli";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Readable, Writable } from "node:stream";
|
|
2
|
+
import type { CliError } from "./errors.js";
|
|
3
|
+
export type OutputFormat = "human" | "json" | "jsonl";
|
|
4
|
+
export interface CliIo {
|
|
5
|
+
isTTY: boolean;
|
|
6
|
+
stderr: Pick<Writable, "write">;
|
|
7
|
+
stdin: Readable;
|
|
8
|
+
stdout: Pick<Writable, "write">;
|
|
9
|
+
}
|
|
10
|
+
export declare class CliOutput {
|
|
11
|
+
readonly format: OutputFormat;
|
|
12
|
+
private readonly io;
|
|
13
|
+
constructor(format: OutputFormat, io: CliIo);
|
|
14
|
+
result(value: unknown, human: string): void;
|
|
15
|
+
event(type: string, value: Record<string, unknown>, human: string): void;
|
|
16
|
+
notice(message: string): void;
|
|
17
|
+
error(error: CliError): void;
|
|
18
|
+
}
|
|
19
|
+
export declare function redactText(value: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Readable, Writable } from "node:stream";
|
|
2
|
+
import type { CliError } from "./errors.js";
|
|
3
|
+
export type OutputFormat = "human" | "json" | "jsonl";
|
|
4
|
+
export interface CliIo {
|
|
5
|
+
isTTY: boolean;
|
|
6
|
+
stderr: Pick<Writable, "write">;
|
|
7
|
+
stdin: Readable;
|
|
8
|
+
stdout: Pick<Writable, "write">;
|
|
9
|
+
}
|
|
10
|
+
export declare class CliOutput {
|
|
11
|
+
readonly format: OutputFormat;
|
|
12
|
+
private readonly io;
|
|
13
|
+
constructor(format: OutputFormat, io: CliIo);
|
|
14
|
+
result(value: unknown, human: string): void;
|
|
15
|
+
event(type: string, value: Record<string, unknown>, human: string): void;
|
|
16
|
+
notice(message: string): void;
|
|
17
|
+
error(error: CliError): void;
|
|
18
|
+
}
|
|
19
|
+
export declare function redactText(value: string): string;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CliOutput = void 0;
|
|
4
|
+
exports.redactText = redactText;
|
|
5
|
+
class CliOutput {
|
|
6
|
+
format;
|
|
7
|
+
io;
|
|
8
|
+
constructor(format, io) {
|
|
9
|
+
this.format = format;
|
|
10
|
+
this.io = io;
|
|
11
|
+
}
|
|
12
|
+
result(value, human) {
|
|
13
|
+
this.io.stdout.write(this.format === "human" ? `${human}\n` : `${safeJson(value)}\n`);
|
|
14
|
+
}
|
|
15
|
+
event(type, value, human) {
|
|
16
|
+
this.io.stdout.write(this.format === "human" ? `${human}\n` : `${safeJson({ type, ...redactObject(value) })}\n`);
|
|
17
|
+
}
|
|
18
|
+
notice(message) {
|
|
19
|
+
if (this.format === "human") {
|
|
20
|
+
this.io.stderr.write(`${redactText(message)}\n`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
error(error) {
|
|
24
|
+
if (this.format === "human") {
|
|
25
|
+
this.io.stderr.write(`Error: ${redactText(error.message)} (${error.code})\n`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.io.stderr.write(`${safeJson({
|
|
29
|
+
error: {
|
|
30
|
+
code: error.code,
|
|
31
|
+
details: redactObject(error.details ?? {}),
|
|
32
|
+
message: redactText(error.message),
|
|
33
|
+
},
|
|
34
|
+
})}\n`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.CliOutput = CliOutput;
|
|
38
|
+
function redactText(value) {
|
|
39
|
+
return value
|
|
40
|
+
.replace(/\b(?:pcli|sk|rk)_(?:test|live)_[A-Za-z0-9_-]+\b/g, "[REDACTED_PROXY_CREDENTIAL]")
|
|
41
|
+
.replace(/\bwhsec_[A-Za-z0-9_-]+\b/g, "[REDACTED_WEBHOOK_SECRET]")
|
|
42
|
+
.replace(/\bBearer\s+[A-Za-z0-9._~-]+\b/gi, "Bearer [REDACTED]");
|
|
43
|
+
}
|
|
44
|
+
function safeJson(value) {
|
|
45
|
+
return JSON.stringify(redactUnknown(value));
|
|
46
|
+
}
|
|
47
|
+
function redactUnknown(value) {
|
|
48
|
+
if (typeof value === "string") {
|
|
49
|
+
return redactText(value);
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
return value.map(redactUnknown);
|
|
53
|
+
}
|
|
54
|
+
if (value && typeof value === "object") {
|
|
55
|
+
return redactObject(value);
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
function redactObject(value) {
|
|
60
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
61
|
+
key,
|
|
62
|
+
isSensitiveKey(key) ? "[REDACTED]" : redactUnknown(item),
|
|
63
|
+
]));
|
|
64
|
+
}
|
|
65
|
+
function isSensitiveKey(key) {
|
|
66
|
+
const normalized = key.toLowerCase();
|
|
67
|
+
return (normalized === "authorization" ||
|
|
68
|
+
normalized === "credential" ||
|
|
69
|
+
normalized === "secret" ||
|
|
70
|
+
normalized === "token" ||
|
|
71
|
+
normalized.endsWith("_credential") ||
|
|
72
|
+
normalized.endsWith("_secret") ||
|
|
73
|
+
normalized.endsWith("_signature") ||
|
|
74
|
+
normalized.endsWith("_token") ||
|
|
75
|
+
normalized.endsWith("-signature"));
|
|
76
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { CliOutput } from "./output.js";
|
|
2
|
+
export interface WebhookEndpointRecord {
|
|
3
|
+
event_schema_version: string;
|
|
4
|
+
event_types: string[] | null;
|
|
5
|
+
id: string;
|
|
6
|
+
url: string;
|
|
7
|
+
}
|
|
8
|
+
export interface WebhookListenerRecord {
|
|
9
|
+
created_at: string;
|
|
10
|
+
event_schema_version: string;
|
|
11
|
+
event_types: string[] | null;
|
|
12
|
+
heartbeat_interval_seconds: number;
|
|
13
|
+
id: string;
|
|
14
|
+
last_heartbeat_at: string;
|
|
15
|
+
lease_expires_at: string;
|
|
16
|
+
source_webhook_endpoint_id: string;
|
|
17
|
+
status: "active" | "archived";
|
|
18
|
+
}
|
|
19
|
+
interface DeliveryClaim {
|
|
20
|
+
attempt_id: string;
|
|
21
|
+
attempt_number: number;
|
|
22
|
+
body: string;
|
|
23
|
+
headers: Record<string, string>;
|
|
24
|
+
kind: "delivery" | "replay";
|
|
25
|
+
replay_outbox_event_id: string | null;
|
|
26
|
+
webhook_delivery_id: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class ProxyWebhooksClient {
|
|
29
|
+
private readonly api;
|
|
30
|
+
constructor(apiBaseUrl: string, token: string, fetchImpl?: typeof fetch);
|
|
31
|
+
listEndpoints(): Promise<WebhookEndpointRecord[]>;
|
|
32
|
+
createListener(sourceEndpointId: string): Promise<WebhookListenerRecord>;
|
|
33
|
+
getListener(listenerId: string): Promise<WebhookListenerRecord>;
|
|
34
|
+
heartbeat(listenerId: string): Promise<WebhookListenerRecord>;
|
|
35
|
+
close(listenerId: string): Promise<WebhookListenerRecord>;
|
|
36
|
+
listDeliveries(listenerId: string, limit?: number): Promise<unknown[]>;
|
|
37
|
+
replay(listenerId: string, deliveryId: string, reason: string): Promise<unknown>;
|
|
38
|
+
claim(listenerId: string, selection?: {
|
|
39
|
+
deliveryId?: string;
|
|
40
|
+
replayOutboxEventId?: string;
|
|
41
|
+
}): Promise<DeliveryClaim | null>;
|
|
42
|
+
complete(attemptId: string, input: {
|
|
43
|
+
durationMs: number;
|
|
44
|
+
errorClass: "network_error" | "timeout" | null;
|
|
45
|
+
responseStatusCode: number | null;
|
|
46
|
+
}): Promise<unknown>;
|
|
47
|
+
createStripeIngress(listenerId: string, webhookSecret: string, pspConfigId?: string): Promise<{
|
|
48
|
+
expires_at: string;
|
|
49
|
+
id: string;
|
|
50
|
+
inbound_url: string;
|
|
51
|
+
merchant_psp_config_id: string;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
54
|
+
export declare function runListener(input: {
|
|
55
|
+
client: ProxyWebhooksClient;
|
|
56
|
+
forwardTo: string;
|
|
57
|
+
maxEvents: number;
|
|
58
|
+
output: CliOutput;
|
|
59
|
+
pspConfigId?: string;
|
|
60
|
+
signal: AbortSignal;
|
|
61
|
+
sourceEndpointId: string;
|
|
62
|
+
stripe: boolean;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
forwarded: number;
|
|
65
|
+
listener: WebhookListenerRecord;
|
|
66
|
+
}>;
|
|
67
|
+
export declare function forwardSelectedDelivery(input: {
|
|
68
|
+
client: ProxyWebhooksClient;
|
|
69
|
+
deliveryId?: string;
|
|
70
|
+
forwardTo: string;
|
|
71
|
+
listenerId: string;
|
|
72
|
+
replayOutboxEventId?: string;
|
|
73
|
+
signal?: AbortSignal;
|
|
74
|
+
}): Promise<{
|
|
75
|
+
attempt_id: string;
|
|
76
|
+
attempt_number: number;
|
|
77
|
+
completion: unknown;
|
|
78
|
+
kind: DeliveryClaim["kind"];
|
|
79
|
+
webhook_delivery_id: string;
|
|
80
|
+
}>;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { CliOutput } from "./output.js";
|
|
2
|
+
export interface WebhookEndpointRecord {
|
|
3
|
+
event_schema_version: string;
|
|
4
|
+
event_types: string[] | null;
|
|
5
|
+
id: string;
|
|
6
|
+
url: string;
|
|
7
|
+
}
|
|
8
|
+
export interface WebhookListenerRecord {
|
|
9
|
+
created_at: string;
|
|
10
|
+
event_schema_version: string;
|
|
11
|
+
event_types: string[] | null;
|
|
12
|
+
heartbeat_interval_seconds: number;
|
|
13
|
+
id: string;
|
|
14
|
+
last_heartbeat_at: string;
|
|
15
|
+
lease_expires_at: string;
|
|
16
|
+
source_webhook_endpoint_id: string;
|
|
17
|
+
status: "active" | "archived";
|
|
18
|
+
}
|
|
19
|
+
interface DeliveryClaim {
|
|
20
|
+
attempt_id: string;
|
|
21
|
+
attempt_number: number;
|
|
22
|
+
body: string;
|
|
23
|
+
headers: Record<string, string>;
|
|
24
|
+
kind: "delivery" | "replay";
|
|
25
|
+
replay_outbox_event_id: string | null;
|
|
26
|
+
webhook_delivery_id: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class ProxyWebhooksClient {
|
|
29
|
+
private readonly api;
|
|
30
|
+
constructor(apiBaseUrl: string, token: string, fetchImpl?: typeof fetch);
|
|
31
|
+
listEndpoints(): Promise<WebhookEndpointRecord[]>;
|
|
32
|
+
createListener(sourceEndpointId: string): Promise<WebhookListenerRecord>;
|
|
33
|
+
getListener(listenerId: string): Promise<WebhookListenerRecord>;
|
|
34
|
+
heartbeat(listenerId: string): Promise<WebhookListenerRecord>;
|
|
35
|
+
close(listenerId: string): Promise<WebhookListenerRecord>;
|
|
36
|
+
listDeliveries(listenerId: string, limit?: number): Promise<unknown[]>;
|
|
37
|
+
replay(listenerId: string, deliveryId: string, reason: string): Promise<unknown>;
|
|
38
|
+
claim(listenerId: string, selection?: {
|
|
39
|
+
deliveryId?: string;
|
|
40
|
+
replayOutboxEventId?: string;
|
|
41
|
+
}): Promise<DeliveryClaim | null>;
|
|
42
|
+
complete(attemptId: string, input: {
|
|
43
|
+
durationMs: number;
|
|
44
|
+
errorClass: "network_error" | "timeout" | null;
|
|
45
|
+
responseStatusCode: number | null;
|
|
46
|
+
}): Promise<unknown>;
|
|
47
|
+
createStripeIngress(listenerId: string, webhookSecret: string, pspConfigId?: string): Promise<{
|
|
48
|
+
expires_at: string;
|
|
49
|
+
id: string;
|
|
50
|
+
inbound_url: string;
|
|
51
|
+
merchant_psp_config_id: string;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
54
|
+
export declare function runListener(input: {
|
|
55
|
+
client: ProxyWebhooksClient;
|
|
56
|
+
forwardTo: string;
|
|
57
|
+
maxEvents: number;
|
|
58
|
+
output: CliOutput;
|
|
59
|
+
pspConfigId?: string;
|
|
60
|
+
signal: AbortSignal;
|
|
61
|
+
sourceEndpointId: string;
|
|
62
|
+
stripe: boolean;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
forwarded: number;
|
|
65
|
+
listener: WebhookListenerRecord;
|
|
66
|
+
}>;
|
|
67
|
+
export declare function forwardSelectedDelivery(input: {
|
|
68
|
+
client: ProxyWebhooksClient;
|
|
69
|
+
deliveryId?: string;
|
|
70
|
+
forwardTo: string;
|
|
71
|
+
listenerId: string;
|
|
72
|
+
replayOutboxEventId?: string;
|
|
73
|
+
signal?: AbortSignal;
|
|
74
|
+
}): Promise<{
|
|
75
|
+
attempt_id: string;
|
|
76
|
+
attempt_number: number;
|
|
77
|
+
completion: unknown;
|
|
78
|
+
kind: DeliveryClaim["kind"];
|
|
79
|
+
webhook_delivery_id: string;
|
|
80
|
+
}>;
|
|
81
|
+
export {};
|