@carrierllc/mcp 0.13.48 → 0.13.56
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/dist/{chunk-H77A3SME.js → chunk-DLEHOLDG.js} +239 -43
- package/dist/chunk-DLEHOLDG.js.map +1 -0
- package/dist/cli.js +26 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.js +95 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/plugin/carrier/skills/storefront/SKILL.md +2 -2
- package/templates/storefront/CLERK.md +2 -0
- package/templates/storefront/package-lock.json +41 -41
- package/templates/storefront/package.json +1 -1
- package/templates/storefront/pnpm-lock.yaml +87 -64
- package/dist/chunk-H77A3SME.js.map +0 -1
|
@@ -957,15 +957,6 @@ async function provisionClerk(opts) {
|
|
|
957
957
|
"CLERK_PLATFORM_TOKEN"
|
|
958
958
|
]);
|
|
959
959
|
const notes = [];
|
|
960
|
-
if (platformToken && !opts.noCreate) {
|
|
961
|
-
const created = await createClerkApplication(platformToken, {
|
|
962
|
-
name: opts.name,
|
|
963
|
-
domain: opts.domain,
|
|
964
|
-
production: opts.production
|
|
965
|
-
});
|
|
966
|
-
if (created.ok) return created;
|
|
967
|
-
notes.push(created.reason ?? "Clerk Platform API call failed.");
|
|
968
|
-
}
|
|
969
960
|
const discovered = discoverClerkCredentials(opts.env);
|
|
970
961
|
if (discovered) {
|
|
971
962
|
return {
|
|
@@ -975,12 +966,27 @@ async function provisionClerk(opts) {
|
|
|
975
966
|
reason: notes.length ? notes.join(" ") : void 0
|
|
976
967
|
};
|
|
977
968
|
}
|
|
969
|
+
if (platformToken && !opts.noCreate) {
|
|
970
|
+
const created = await createClerkApplication(platformToken, {
|
|
971
|
+
name: opts.name,
|
|
972
|
+
domain: opts.domain,
|
|
973
|
+
production: opts.production
|
|
974
|
+
});
|
|
975
|
+
if (created.ok) return created;
|
|
976
|
+
notes.push(created.reason ?? "Clerk Platform API call failed.");
|
|
977
|
+
}
|
|
978
978
|
if (opts.cli && opts.storefront && !opts.noCreate) {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
979
|
+
if (opts.production) {
|
|
980
|
+
notes.push(
|
|
981
|
+
"Keyless Clerk minting is skipped for production deploys: a keyless app is a development instance. Set CLERK_PLATFORM_API_KEY or provide existing keys."
|
|
982
|
+
);
|
|
983
|
+
} else {
|
|
984
|
+
const minted = await mintKeylessClerkApp(opts.storefront, opts.cli);
|
|
985
|
+
if (minted.ok) {
|
|
986
|
+
return { ...minted, reason: notes.length ? notes.join(" ") : void 0 };
|
|
987
|
+
}
|
|
988
|
+
notes.push(minted.reason ?? "Clerk CLI keyless provisioning failed.");
|
|
982
989
|
}
|
|
983
|
-
notes.push(minted.reason ?? "Clerk CLI keyless provisioning failed.");
|
|
984
990
|
}
|
|
985
991
|
if (!platformToken) {
|
|
986
992
|
notes.push(
|
|
@@ -1077,17 +1083,22 @@ var PROBES = [
|
|
|
1077
1083
|
{ path: "/" },
|
|
1078
1084
|
{ path: "/shop", expectBody: /·/ },
|
|
1079
1085
|
// plan names render as "Visit · Calm"
|
|
1080
|
-
{ path: "/help" }
|
|
1086
|
+
{ path: "/help" },
|
|
1087
|
+
// apps/storefront/src/app/dashboard/AccountSession.tsx renders this when
|
|
1088
|
+
// NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY or CLERK_SECRET_KEY is missing — the
|
|
1089
|
+
// build shipped without Clerk inlined, so sign-in can never reach the user.
|
|
1090
|
+
{ path: "/dashboard", rejectBody: /Your install code is on the link from checkout/ }
|
|
1081
1091
|
];
|
|
1082
|
-
async function probe(base, path, expectBody) {
|
|
1092
|
+
async function probe(base, path, expectBody, rejectBody) {
|
|
1083
1093
|
const url = `${base.replace(/\/$/, "")}${path}${path.includes("?") ? "&" : "?"}_v=${Date.now()}`;
|
|
1084
1094
|
try {
|
|
1085
1095
|
const res = await fetch(url, { redirect: "manual" });
|
|
1086
1096
|
const status = res.status;
|
|
1087
1097
|
const ok = status < 400;
|
|
1088
|
-
if (!expectBody || !ok) return { path, status, ok };
|
|
1098
|
+
if (!expectBody && !rejectBody || !ok) return { path, status, ok };
|
|
1089
1099
|
const body = await res.text();
|
|
1090
|
-
return { path, status, ok, bodyOk: expectBody.test(body) };
|
|
1100
|
+
if (expectBody) return { path, status, ok, bodyOk: expectBody.test(body) };
|
|
1101
|
+
return { path, status, ok, bodyOk: !rejectBody.test(body) };
|
|
1091
1102
|
} catch (e) {
|
|
1092
1103
|
return { path, status: 0, ok: false, error: e instanceof Error ? e.message : String(e) };
|
|
1093
1104
|
}
|
|
@@ -1097,6 +1108,7 @@ function diagnose(probes, secrets) {
|
|
|
1097
1108
|
const root = by("/");
|
|
1098
1109
|
const shop = by("/shop");
|
|
1099
1110
|
const help = by("/help");
|
|
1111
|
+
const dashboard = by("/dashboard");
|
|
1100
1112
|
if (probes.every((p) => p.ok && p.bodyOk !== false)) return "healthy";
|
|
1101
1113
|
if (probes.every((p) => p.status === 0)) return "not-deployed";
|
|
1102
1114
|
const catalogDown = root?.status === 500 && shop?.status === 500;
|
|
@@ -1104,6 +1116,9 @@ function diagnose(probes, secrets) {
|
|
|
1104
1116
|
return needsCarrierKey(secrets) ? "carrier-key-missing" : "unclassified";
|
|
1105
1117
|
}
|
|
1106
1118
|
if (shop?.ok && shop.bodyOk === false) return "empty-catalog";
|
|
1119
|
+
if (root?.ok && shop?.ok && help?.ok && dashboard?.bodyOk === false) {
|
|
1120
|
+
return "clerk-not-configured";
|
|
1121
|
+
}
|
|
1107
1122
|
if (root?.ok && shop?.ok && probes.some((p) => p.status >= 500)) return "clerk-keys-missing";
|
|
1108
1123
|
if (probes.every((p) => p.status === 404)) return "not-deployed";
|
|
1109
1124
|
return "unclassified";
|
|
@@ -1112,13 +1127,15 @@ var SUMMARIES = {
|
|
|
1112
1127
|
healthy: "All probes returned a working page.",
|
|
1113
1128
|
"carrier-key-missing": "Catalog pages return 500 while non-catalog pages work \u2014 CARRIER_API_KEY is missing or invalid on the host.",
|
|
1114
1129
|
"clerk-keys-missing": "Public pages work but auth routes error \u2014 Clerk keys are missing on the host.",
|
|
1130
|
+
"clerk-not-configured": "/dashboard serves its no-Clerk fallback while public pages work \u2014 Clerk keys are missing on the storefront. Provision Clerk, rebuild so the publishable key is inlined, and redeploy.",
|
|
1115
1131
|
"empty-catalog": "/shop renders but no plans are in it \u2014 the Carrier catalog returned nothing sellable. Not a deploy problem.",
|
|
1116
1132
|
"not-deployed": "Nothing served at the deployed URL \u2014 the deploy did not land, or the URL is wrong.",
|
|
1117
1133
|
unclassified: "The storefront is not serving correctly and the symptom matches no known cause."
|
|
1118
1134
|
};
|
|
1119
1135
|
var REPAIRABLE = /* @__PURE__ */ new Set([
|
|
1120
1136
|
"carrier-key-missing",
|
|
1121
|
-
"clerk-keys-missing"
|
|
1137
|
+
"clerk-keys-missing",
|
|
1138
|
+
"clerk-not-configured"
|
|
1122
1139
|
]);
|
|
1123
1140
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1124
1141
|
async function verifyStorefront(url, storefront, env = process.env, opts = {}) {
|
|
@@ -1129,8 +1146,8 @@ async function verifyStorefront(url, storefront, env = process.env, opts = {}) {
|
|
|
1129
1146
|
let diagnosis = "unclassified";
|
|
1130
1147
|
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
1131
1148
|
probes = [];
|
|
1132
|
-
for (const { path, expectBody } of PROBES) {
|
|
1133
|
-
probes.push(await probe(url, path, expectBody));
|
|
1149
|
+
for (const { path, expectBody, rejectBody } of PROBES) {
|
|
1150
|
+
probes.push(await probe(url, path, expectBody, rejectBody));
|
|
1134
1151
|
}
|
|
1135
1152
|
diagnosis = diagnose(probes, secrets);
|
|
1136
1153
|
if (diagnosis !== "not-deployed" || attempt === attempts) break;
|
|
@@ -1149,7 +1166,7 @@ async function verifyStorefront(url, storefront, env = process.env, opts = {}) {
|
|
|
1149
1166
|
function formatProbes(probes) {
|
|
1150
1167
|
return probes.map((p) => {
|
|
1151
1168
|
const status = p.status === 0 ? "unreachable" : String(p.status);
|
|
1152
|
-
const body = p.bodyOk === false ? "
|
|
1169
|
+
const body = p.bodyOk === false ? ` (${p.path === "/dashboard" ? "clerk fallback" : "no plans"})` : "";
|
|
1153
1170
|
return `${p.path} ${status}${body}`;
|
|
1154
1171
|
}).join(" ");
|
|
1155
1172
|
}
|
|
@@ -1173,6 +1190,14 @@ function repairPlanFor(diagnosis) {
|
|
|
1173
1190
|
note: "Provision Clerk, rebuild so the publishable key is inlined, and redeploy."
|
|
1174
1191
|
};
|
|
1175
1192
|
}
|
|
1193
|
+
if (diagnosis === "clerk-not-configured") {
|
|
1194
|
+
return {
|
|
1195
|
+
diagnosis,
|
|
1196
|
+
runClerk: true,
|
|
1197
|
+
rebuild: true,
|
|
1198
|
+
note: "Clerk keys are missing on the storefront; provision Clerk, rebuild so the publishable key is inlined, and redeploy."
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1176
1201
|
return void 0;
|
|
1177
1202
|
}
|
|
1178
1203
|
|
|
@@ -1888,7 +1913,7 @@ function storefrontScreen(input) {
|
|
|
1888
1913
|
// package.json
|
|
1889
1914
|
var package_default = {
|
|
1890
1915
|
name: "@carrierllc/mcp",
|
|
1891
|
-
version: "0.13.
|
|
1916
|
+
version: "0.13.56",
|
|
1892
1917
|
description: "Carrier MCP \u2014 natural-language control of MVNO/eSIM fleets via eSIMVault OCS. Stdio mode for direct integration with Claude Desktop, Cursor, Windsurf, and MCP-compatible clients. Ships the `carrier` CLI (plugin install + white-label eSIM storefront scaffold).",
|
|
1893
1918
|
license: "MIT",
|
|
1894
1919
|
author: "Carrier (Lifecycle Innovations Limited)",
|
|
@@ -1934,7 +1959,7 @@ var package_default = {
|
|
|
1934
1959
|
"@clack/prompts": "^0.7.0",
|
|
1935
1960
|
"@clerk/backend": "^3.18.1",
|
|
1936
1961
|
"@modelcontextprotocol/ext-apps": "^1.7.5",
|
|
1937
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
1962
|
+
"@modelcontextprotocol/sdk": "^1.32.0",
|
|
1938
1963
|
"@noble/hashes": "^2.3.0",
|
|
1939
1964
|
"@sentry/cloudflare": "^10.65.0",
|
|
1940
1965
|
aws4fetch: "^1.0.20",
|
|
@@ -3159,7 +3184,7 @@ async function runWithBudget(method, attempt, budget = ocsBudgetFor(method)) {
|
|
|
3159
3184
|
throw lastTimeout ?? new OcsTimeoutError(method, budget.attemptMs, budget.totalMs, Math.max(attempts, 1));
|
|
3160
3185
|
}
|
|
3161
3186
|
|
|
3162
|
-
// ../../packages/ocs-client/dist/chunk-
|
|
3187
|
+
// ../../packages/ocs-client/dist/chunk-ABY2BUXP.js
|
|
3163
3188
|
var RATE_LIMIT = 10;
|
|
3164
3189
|
var WINDOW_MS = 1e3;
|
|
3165
3190
|
var windows = /* @__PURE__ */ new Map();
|
|
@@ -3426,6 +3451,16 @@ function assertBareIntParam(method, params) {
|
|
|
3426
3451
|
);
|
|
3427
3452
|
}
|
|
3428
3453
|
var SINGLE_ATTEMPT_METHODS = /* @__PURE__ */ new Set(["affectPackageToSubscriber", "addSubscriberPackage", "deleteSubscriberPackage"]);
|
|
3454
|
+
var OcsHttpError = class extends Error {
|
|
3455
|
+
constructor(status, method) {
|
|
3456
|
+
super("[" + method + "] HTTP " + status);
|
|
3457
|
+
this.status = status;
|
|
3458
|
+
this.method = method;
|
|
3459
|
+
this.name = "OcsHttpError";
|
|
3460
|
+
}
|
|
3461
|
+
status;
|
|
3462
|
+
method;
|
|
3463
|
+
};
|
|
3429
3464
|
var OcsApiError = class extends Error {
|
|
3430
3465
|
constructor(code, message, method, details = {}) {
|
|
3431
3466
|
super(`[${method}] OCS error ${code}: ${message}`);
|
|
@@ -3471,6 +3506,11 @@ var OcsContractError = class _OcsContractError extends Error {
|
|
|
3471
3506
|
};
|
|
3472
3507
|
function ocsErrorMessage(code, rawMsg, rawBody) {
|
|
3473
3508
|
switch (code) {
|
|
3509
|
+
case 9:
|
|
3510
|
+
return {
|
|
3511
|
+
message: "OCS source IP not authorised (code 9 SRC_IP_NOT_AUTHORISED). This reseller token has an IP allowlist configured on eSIMVault. Route traffic through the fixed-egress proxy (CARRIER_OCS_PROXY_URL / fixedEgress) and ensure its static IP is whitelisted.",
|
|
3512
|
+
details: {}
|
|
3513
|
+
};
|
|
3474
3514
|
case 12:
|
|
3475
3515
|
return {
|
|
3476
3516
|
message: "OCS resource is read-only (code 12). The package/subscriber/account state does not allow this mutation. Often returned for end-of-life subscribers or finalized invoices.",
|
|
@@ -3518,12 +3558,16 @@ async function retryWithBackoff(fn) {
|
|
|
3518
3558
|
return await fn();
|
|
3519
3559
|
} catch (err) {
|
|
3520
3560
|
lastError = err;
|
|
3561
|
+
if (err instanceof OcsHttpError) throw err;
|
|
3521
3562
|
if (err instanceof OcsApiError) {
|
|
3522
3563
|
if (err.code !== 100) throw err;
|
|
3523
3564
|
maxRetries = TRAFFIC_CONTROL_MAX_RETRIES;
|
|
3524
3565
|
backoffBaseMs = TRAFFIC_CONTROL_BACKOFF_BASE_MS;
|
|
3525
3566
|
backoffMaxMs = TRAFFIC_CONTROL_BACKOFF_MAX_MS;
|
|
3526
3567
|
}
|
|
3568
|
+
if (err instanceof OcsProxyError) {
|
|
3569
|
+
if (err.status === 401 || err.status === 403) throw err;
|
|
3570
|
+
}
|
|
3527
3571
|
if (err instanceof OcsContractError) {
|
|
3528
3572
|
throw err;
|
|
3529
3573
|
}
|
|
@@ -3537,13 +3581,44 @@ async function retryWithBackoff(fn) {
|
|
|
3537
3581
|
function isAbortError(err) {
|
|
3538
3582
|
return err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError" || /aborted|timed? ?out/i.test(err.message));
|
|
3539
3583
|
}
|
|
3584
|
+
var OcsProxyError = class extends Error {
|
|
3585
|
+
constructor(message, status, cause) {
|
|
3586
|
+
super(`[ocs-client] Fixed egress proxy error: ${message}`);
|
|
3587
|
+
this.status = status;
|
|
3588
|
+
this.cause = cause;
|
|
3589
|
+
this.name = "OcsProxyError";
|
|
3590
|
+
}
|
|
3591
|
+
status;
|
|
3592
|
+
cause;
|
|
3593
|
+
};
|
|
3594
|
+
var configuredFixedEgress;
|
|
3595
|
+
function fixedEgressFromEnv(env) {
|
|
3596
|
+
if (!env) return void 0;
|
|
3597
|
+
const proxyUrl = (env["CARRIER_OCS_PROXY_URL"] ?? env["OCS_FIXED_EGRESS_PROXY_URL"] ?? env["OCS_PROXY_URL"])?.trim();
|
|
3598
|
+
const required = env["CARRIER_OCS_REQUIRE_FIXED_EGRESS"] === "true" || env["CARRIER_OCS_REQUIRE_FIXED_EGRESS"] === true;
|
|
3599
|
+
if (!proxyUrl && !required) return void 0;
|
|
3600
|
+
const proxySecret = env["CARRIER_OCS_PROXY_SECRET"] ?? env["OCS_FIXED_EGRESS_PROXY_SECRET"] ?? env["OCS_PROXY_SECRET"];
|
|
3601
|
+
const targetHost = env["CARRIER_OCS_PROXY_TARGET_HOST"] ?? env["OCS_FIXED_EGRESS_TARGET_HOST"];
|
|
3602
|
+
const fallbackMode = env["CARRIER_OCS_PROXY_FALLBACK"] ?? env["OCS_PROXY_FALLBACK"];
|
|
3603
|
+
const requireFixedEgress = env["CARRIER_OCS_REQUIRE_FIXED_EGRESS"] === "true" || env["CARRIER_OCS_REQUIRE_FIXED_EGRESS"] === true;
|
|
3604
|
+
const enabledRaw = env["CARRIER_OCS_PROXY_ENABLED"];
|
|
3605
|
+
const enabled = enabledRaw !== void 0 ? enabledRaw === "true" || enabledRaw === true || enabledRaw === "1" : true;
|
|
3606
|
+
return {
|
|
3607
|
+
proxyUrl,
|
|
3608
|
+
proxySecret,
|
|
3609
|
+
targetHost,
|
|
3610
|
+
fallbackMode: fallbackMode ?? "strict",
|
|
3611
|
+
requireFixedEgress,
|
|
3612
|
+
enabled
|
|
3613
|
+
};
|
|
3614
|
+
}
|
|
3540
3615
|
var OcsClient = class {
|
|
3541
3616
|
/**
|
|
3542
3617
|
* @param baseUrl OCS base URL without trailing slash (e.g. https://ocs.esimvault.cloud).
|
|
3543
3618
|
* @param _defaultToken Default API token; identifies the reseller for rate-floor keying.
|
|
3544
3619
|
* @param _priority Call priority: "interactive" (MCP tool calls, 80% capacity) or
|
|
3545
3620
|
* "batch" (cron/poll callers, 20% capacity). Default: "interactive".
|
|
3546
|
-
* @param options Contract-enforcement opt-outs (see `OcsClientOptions`).
|
|
3621
|
+
* @param options Contract-enforcement opt-outs and proxy routing (see `OcsClientOptions`).
|
|
3547
3622
|
*/
|
|
3548
3623
|
constructor(baseUrl, _defaultToken, _priority = "interactive", options = {}) {
|
|
3549
3624
|
this._defaultToken = _defaultToken;
|
|
@@ -3554,6 +3629,46 @@ var OcsClient = class {
|
|
|
3554
3629
|
this._strictMethods = options.strictMethods ?? false;
|
|
3555
3630
|
this._validateResponses = options.validateResponses ?? true;
|
|
3556
3631
|
this._strictValidation = options.strictValidation ?? false;
|
|
3632
|
+
const envConfig = options.env ? fixedEgressFromEnv(options.env) : configuredFixedEgress ?? (typeof process !== "undefined" && process?.env ? fixedEgressFromEnv(process.env) : void 0);
|
|
3633
|
+
const optConfig = options.fixedEgress ?? {
|
|
3634
|
+
proxyUrl: options.fixedEgressProxyUrl,
|
|
3635
|
+
proxySecret: options.fixedEgressProxySecret,
|
|
3636
|
+
targetHost: options.fixedEgressTargetHost,
|
|
3637
|
+
requireFixedEgress: options.requireFixedEgress,
|
|
3638
|
+
fallbackMode: options.fallbackMode
|
|
3639
|
+
};
|
|
3640
|
+
const resolvedProxyUrl = optConfig.proxyUrl?.trim() || envConfig?.proxyUrl;
|
|
3641
|
+
const resolvedProxySecret = optConfig.proxySecret ?? envConfig?.proxySecret;
|
|
3642
|
+
const resolvedTargetHost = optConfig.targetHost ?? envConfig?.targetHost ?? (this.baseUrl ? new URL(this.baseUrl).hostname : "ocs.esimvault.cloud");
|
|
3643
|
+
const resolvedRequire = Boolean(optConfig.requireFixedEgress || envConfig?.requireFixedEgress);
|
|
3644
|
+
const resolvedFallback = optConfig.fallbackMode ?? envConfig?.fallbackMode ?? "strict";
|
|
3645
|
+
const resolvedEnabled = optConfig.enabled ?? envConfig?.enabled ?? Boolean(resolvedProxyUrl);
|
|
3646
|
+
if (resolvedProxyUrl && resolvedEnabled) {
|
|
3647
|
+
if (!resolvedProxySecret?.trim()) {
|
|
3648
|
+
throw new OcsProxyError("Fixed OCS egress proxy is configured but proxySecret is missing");
|
|
3649
|
+
}
|
|
3650
|
+
let proxyUrl;
|
|
3651
|
+
try {
|
|
3652
|
+
proxyUrl = new URL(resolvedProxyUrl);
|
|
3653
|
+
} catch {
|
|
3654
|
+
throw new OcsProxyError("Proxy URL must be a valid HTTPS URL");
|
|
3655
|
+
}
|
|
3656
|
+
if (proxyUrl.protocol !== "https:" || proxyUrl.username || proxyUrl.password || proxyUrl.search || proxyUrl.hash) {
|
|
3657
|
+
throw new OcsProxyError("Proxy URL must use HTTPS without credentials, query or fragment");
|
|
3658
|
+
}
|
|
3659
|
+
this._fixedEgress = {
|
|
3660
|
+
proxyUrl: resolvedProxyUrl,
|
|
3661
|
+
proxySecret: resolvedProxySecret,
|
|
3662
|
+
targetHost: resolvedTargetHost,
|
|
3663
|
+
requireFixedEgress: resolvedRequire,
|
|
3664
|
+
fallbackMode: resolvedFallback,
|
|
3665
|
+
enabled: true
|
|
3666
|
+
};
|
|
3667
|
+
} else if (resolvedRequire) {
|
|
3668
|
+
throw new OcsProxyError("Fixed OCS egress is required but no authenticated proxy is configured");
|
|
3669
|
+
} else {
|
|
3670
|
+
this._fixedEgress = void 0;
|
|
3671
|
+
}
|
|
3557
3672
|
}
|
|
3558
3673
|
_defaultToken;
|
|
3559
3674
|
_priority;
|
|
@@ -3561,10 +3676,14 @@ var OcsClient = class {
|
|
|
3561
3676
|
_strictMethods;
|
|
3562
3677
|
_validateResponses;
|
|
3563
3678
|
_strictValidation;
|
|
3679
|
+
_fixedEgress;
|
|
3564
3680
|
// Per-instance (NOT static): a static set would dedup across requests in a
|
|
3565
3681
|
// reused Worker isolate and silently swallow recurring contract-drift warnings.
|
|
3566
3682
|
_warnedMethods = /* @__PURE__ */ new Set();
|
|
3567
3683
|
_warnedValidation = /* @__PURE__ */ new Set();
|
|
3684
|
+
get fixedEgress() {
|
|
3685
|
+
return this._fixedEgress;
|
|
3686
|
+
}
|
|
3568
3687
|
async call(method, params = {}, token) {
|
|
3569
3688
|
if (OCS_FORBIDDEN_METHODS.has(method)) {
|
|
3570
3689
|
throw new OcsUnknownMethodError(method);
|
|
@@ -3582,39 +3701,115 @@ var OcsClient = class {
|
|
|
3582
3701
|
if (!tok) {
|
|
3583
3702
|
throw new OcsApiError(-1, "No OCS API token provided", method);
|
|
3584
3703
|
}
|
|
3585
|
-
const
|
|
3704
|
+
const directUrl = `${this.baseUrl}/v1?token=${encodeURIComponent(tok)}`;
|
|
3705
|
+
const useProxy = Boolean(this._fixedEgress?.enabled && this._fixedEgress?.proxyUrl);
|
|
3706
|
+
if (this._fixedEgress?.requireFixedEgress && !useProxy) {
|
|
3707
|
+
throw new OcsProxyError("Fixed OCS egress is required but no authenticated proxy is configured");
|
|
3708
|
+
}
|
|
3709
|
+
let proxyEndpoint = this._fixedEgress?.proxyUrl ?? "";
|
|
3710
|
+
if (useProxy && !proxyEndpoint.includes("/v1")) {
|
|
3711
|
+
proxyEndpoint = `${proxyEndpoint}/v1`;
|
|
3712
|
+
}
|
|
3713
|
+
const url = useProxy ? proxyEndpoint : directUrl;
|
|
3586
3714
|
assertBareIntParam(method, params);
|
|
3587
3715
|
const wireParams = applyParamRenames(method, params);
|
|
3588
3716
|
const shapedParams = nestsSubscriberId(method) ? nestSubscriberIdParam(wireParams) : wireParams;
|
|
3589
3717
|
const body = JSON.stringify({ [method]: shapedParams });
|
|
3590
3718
|
const singleAttempt = SINGLE_ATTEMPT_METHODS.has(method);
|
|
3719
|
+
const directFallback = !this._fixedEgress?.requireFixedEgress && this._fixedEgress?.fallbackMode === "fallback" && !singleAttempt;
|
|
3591
3720
|
const send = async () => {
|
|
3592
3721
|
await acquireToken(tok);
|
|
3593
3722
|
await acquireEndpointSlot(tok, method, this._priority);
|
|
3594
3723
|
return runWithBudget(method, async (signal, attemptMs) => {
|
|
3595
3724
|
let res;
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
}
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3725
|
+
if (useProxy) {
|
|
3726
|
+
const proxyHeaders = {
|
|
3727
|
+
"Content-Type": "application/json",
|
|
3728
|
+
"X-OCS-Target-Host": this._fixedEgress.targetHost ?? new URL(this.baseUrl).hostname,
|
|
3729
|
+
"X-OCS-Target-Path": `/v1?token=${encodeURIComponent(tok)}`,
|
|
3730
|
+
"X-Carrier-Target-Base-Url": this.baseUrl
|
|
3731
|
+
};
|
|
3732
|
+
if (this._fixedEgress.proxySecret) {
|
|
3733
|
+
proxyHeaders["Authorization"] = `Bearer ${this._fixedEgress.proxySecret}`;
|
|
3734
|
+
proxyHeaders["X-Carrier-Proxy-Secret"] = this._fixedEgress.proxySecret;
|
|
3735
|
+
}
|
|
3736
|
+
try {
|
|
3737
|
+
res = await fetch(url, {
|
|
3738
|
+
method: "POST",
|
|
3739
|
+
headers: proxyHeaders,
|
|
3740
|
+
body,
|
|
3741
|
+
signal
|
|
3742
|
+
});
|
|
3743
|
+
} catch (err) {
|
|
3744
|
+
if (isAbortError(err)) {
|
|
3745
|
+
throw new OcsTimeoutError(method, attemptMs);
|
|
3746
|
+
}
|
|
3747
|
+
if (directFallback) {
|
|
3748
|
+
console.warn(
|
|
3749
|
+
`[ocs-client] fixed-egress proxy network failure (${err instanceof Error ? err.message : String(err)}), falling back to direct OCS call`
|
|
3750
|
+
);
|
|
3751
|
+
try {
|
|
3752
|
+
res = await fetch(directUrl, {
|
|
3753
|
+
method: "POST",
|
|
3754
|
+
headers: { "Content-Type": "application/json" },
|
|
3755
|
+
body,
|
|
3756
|
+
signal
|
|
3757
|
+
});
|
|
3758
|
+
} catch (fallbackErr) {
|
|
3759
|
+
if (isAbortError(fallbackErr)) {
|
|
3760
|
+
throw new OcsTimeoutError(method, attemptMs);
|
|
3761
|
+
}
|
|
3762
|
+
throw fallbackErr;
|
|
3763
|
+
}
|
|
3764
|
+
} else {
|
|
3765
|
+
throw new OcsProxyError(`Proxy connection failure: ${err instanceof Error ? err.message : String(err)}`, void 0, err);
|
|
3766
|
+
}
|
|
3767
|
+
}
|
|
3768
|
+
if (res.status === 401 || res.status === 403) {
|
|
3769
|
+
throw new OcsProxyError(`Proxy authentication rejected (HTTP ${res.status} ${res.statusText})`, res.status);
|
|
3770
|
+
}
|
|
3771
|
+
if (res.status >= 502 && res.status <= 504) {
|
|
3772
|
+
if (directFallback) {
|
|
3773
|
+
console.warn(
|
|
3774
|
+
`[ocs-client] fixed-egress proxy returned HTTP ${res.status}, falling back to direct OCS call`
|
|
3775
|
+
);
|
|
3776
|
+
try {
|
|
3777
|
+
res = await fetch(directUrl, {
|
|
3778
|
+
method: "POST",
|
|
3779
|
+
headers: { "Content-Type": "application/json" },
|
|
3780
|
+
body,
|
|
3781
|
+
signal
|
|
3782
|
+
});
|
|
3783
|
+
} catch (fallbackErr) {
|
|
3784
|
+
if (isAbortError(fallbackErr)) {
|
|
3785
|
+
throw new OcsTimeoutError(method, attemptMs);
|
|
3786
|
+
}
|
|
3787
|
+
throw fallbackErr;
|
|
3788
|
+
}
|
|
3789
|
+
} else {
|
|
3790
|
+
throw new OcsProxyError(`Proxy upstream gateway failure: HTTP ${res.status} ${res.statusText}`, res.status);
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
3793
|
+
} else {
|
|
3794
|
+
try {
|
|
3795
|
+
res = await fetch(directUrl, {
|
|
3796
|
+
method: "POST",
|
|
3797
|
+
headers: { "Content-Type": "application/json" },
|
|
3798
|
+
body,
|
|
3799
|
+
signal
|
|
3800
|
+
});
|
|
3801
|
+
} catch (err) {
|
|
3802
|
+
if (isAbortError(err)) {
|
|
3803
|
+
throw new OcsTimeoutError(method, attemptMs);
|
|
3804
|
+
}
|
|
3805
|
+
throw err;
|
|
3606
3806
|
}
|
|
3607
|
-
throw err;
|
|
3608
3807
|
}
|
|
3609
3808
|
if (res.status >= 500) {
|
|
3610
3809
|
throw new Error(`HTTP ${res.status} ${res.statusText}`);
|
|
3611
3810
|
}
|
|
3612
3811
|
if (!res.ok) {
|
|
3613
|
-
throw new
|
|
3614
|
-
res.status,
|
|
3615
|
-
`HTTP ${res.status} ${res.statusText}`,
|
|
3616
|
-
method
|
|
3617
|
-
);
|
|
3812
|
+
throw new OcsHttpError(res.status, method);
|
|
3618
3813
|
}
|
|
3619
3814
|
let json;
|
|
3620
3815
|
try {
|
|
@@ -5578,6 +5773,7 @@ export {
|
|
|
5578
5773
|
deriveAccentLight,
|
|
5579
5774
|
deriveAccentPaletteSubs,
|
|
5580
5775
|
renderEnv,
|
|
5776
|
+
discoverSecrets,
|
|
5581
5777
|
mergeEnvLocal,
|
|
5582
5778
|
slug,
|
|
5583
5779
|
installDeps,
|
|
@@ -5604,4 +5800,4 @@ export {
|
|
|
5604
5800
|
package_default,
|
|
5605
5801
|
CARRIER_VERSION
|
|
5606
5802
|
};
|
|
5607
|
-
//# sourceMappingURL=chunk-
|
|
5803
|
+
//# sourceMappingURL=chunk-DLEHOLDG.js.map
|