@carrierllc/mcp 0.13.51 → 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/index.js CHANGED
@@ -82,7 +82,7 @@ import {
82
82
  verifyStorefront,
83
83
  withOcsListSummary,
84
84
  withTemplateResellerId
85
- } from "./chunk-NPAD6AA7.js";
85
+ } from "./chunk-DLEHOLDG.js";
86
86
  import "./chunk-SHKKVIIA.js";
87
87
 
88
88
  // src/index.ts
@@ -104,22 +104,40 @@ async function issueInventory(ctx, args, extra) {
104
104
  ...Object.fromEntries(["startDate", "endDate", "validityPeriod"].filter((k) => args[k] !== void 0).map((k) => [k, args[k]])),
105
105
  ...args.business_reference !== void 0 ? { businessReference: args.business_reference } : {}
106
106
  };
107
+ const unknown = "Issuance outcome is unknown. Preserve this request_key for reconciliation; do not issue with a new key.";
108
+ let response;
107
109
  try {
108
- const response = await fetch(`${ctx.env.CARRIER_API_BASE_URL ?? "https://api.carrier.llc"}/v1/subscribers/issue-from-inventory`, {
110
+ response = await fetch(`${ctx.env.CARRIER_API_BASE_URL ?? "https://api.carrier.llc"}/v1/subscribers/issue-from-inventory`, {
109
111
  method: "POST",
110
112
  redirect: "error",
111
113
  headers: { "Authorization": `Bearer ${token2}`, "Content-Type": "application/json", "X-Idempotency-Key": String(key) },
112
114
  body: JSON.stringify(body2)
113
115
  });
114
- const payload = await response.json();
115
- if (!payload || typeof payload !== "object" || Array.isArray(payload) || response.ok && !payload.data) throw new Error("Malformed API response");
116
- if (response.status >= 500 && payload.code !== "OUTCOME_UNKNOWN" && payload.upstream_dispatched !== false) {
117
- return error("OUTCOME_UNKNOWN", "Issuance outcome is unknown. Preserve this request_key for reconciliation; do not issue with a new key.", { api_error: payload });
118
- }
119
- return { ...!response.ok ? { isError: true } : {}, content: [{ type: "text", text: JSON.stringify({ ...payload, request_key: key }) }] };
116
+ } catch (err9) {
117
+ return error("OUTCOME_UNKNOWN", unknown, { transport_error: err9 instanceof Error ? err9.message : String(err9) });
118
+ }
119
+ let text;
120
+ try {
121
+ text = await response.text();
122
+ } catch (err9) {
123
+ return error("OUTCOME_UNKNOWN", unknown, { http_status: response.status, transport_error: err9 instanceof Error ? err9.message : String(err9) });
124
+ }
125
+ let parsed;
126
+ try {
127
+ parsed = JSON.parse(text);
120
128
  } catch {
121
- return error("OUTCOME_UNKNOWN", "Issuance outcome is unknown. Preserve this request_key for reconciliation; do not issue with a new key.");
129
+ parsed = void 0;
130
+ }
131
+ const payload = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : void 0;
132
+ const http = { http_status: response.status };
133
+ if (!payload) {
134
+ return error("OUTCOME_UNKNOWN", unknown, { ...http, body_excerpt: text.slice(0, 200) });
135
+ }
136
+ if (response.ok && !payload.data) return error("OUTCOME_UNKNOWN", unknown, { ...http, api_response: payload });
137
+ if (response.status >= 500 && payload.code !== "OUTCOME_UNKNOWN" && payload.upstream_dispatched !== false && payload.outcome !== "rejected") {
138
+ return error("OUTCOME_UNKNOWN", unknown, { ...http, api_error: payload });
122
139
  }
140
+ return { ...!response.ok ? { isError: true } : {}, content: [{ type: "text", text: JSON.stringify({ ...payload, request_key: key }) }] };
123
141
  }
124
142
 
125
143
  // src/tools.ts