@propper-ai/cli 0.4.0 → 0.5.0

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.
@@ -97,33 +97,37 @@ async function parseErrorBody(res) {
97
97
  return { message: text.slice(0, 500), body: text };
98
98
  }
99
99
  }
100
- async function request(entry, req, ctx) {
100
+ function mergeHeaders(defaults, extra) {
101
+ const headers = { ...defaults };
102
+ for (const [key, value] of Object.entries(extra ?? {})) {
103
+ const lower = key.toLowerCase();
104
+ if (value === "") delete headers[lower];
105
+ else headers[lower] = value;
106
+ }
107
+ return headers;
108
+ }
109
+ async function rawRequest(method, url, opts, ctx, errorMeta = {}) {
101
110
  const fetchFn = ctx.fetchFn ?? fetch;
102
111
  const sleep = ctx.sleepFn ?? defaultSleep;
103
112
  const maxRetries = ctx.maxRetries ?? DEFAULT_MAX_RETRIES;
104
- const url = buildUrl(entry, req, ctx.apiBaseUrl);
105
- const headers = {
113
+ const defaults = {
106
114
  "user-agent": ctx.userAgent,
107
- accept: entry.produces === "binary" ? "*/*" : "application/json"
115
+ accept: opts.accept ?? "application/json"
108
116
  };
109
- if (ctx.token) headers.authorization = `Bearer ${ctx.token}`;
110
- let bodyInit;
111
- if (entry.consumes === "json" && req.body !== void 0) {
112
- headers["content-type"] = "application/json";
113
- bodyInit = JSON.stringify(req.body);
114
- }
117
+ if (ctx.token) defaults.authorization = `Bearer ${ctx.token}`;
118
+ const headers = mergeHeaders(defaults, opts.headers);
115
119
  let lastError;
116
120
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
117
121
  const controller = new AbortController();
118
122
  const timer = setTimeout(() => controller.abort(), ctx.timeoutMs ?? DEFAULT_TIMEOUT_MS);
119
123
  try {
120
124
  if (ctx.debug) {
121
- console.error(`\u2192 ${entry.method} ${url}${bodyInit ? ` body=${bodyInit}` : ""}`);
125
+ console.error(`\u2192 ${method} ${url}${opts.body ? ` body=${opts.body}` : ""}`);
122
126
  }
123
127
  const res = await fetchFn(url, {
124
- method: entry.method,
128
+ method,
125
129
  headers,
126
- body: bodyInit,
130
+ body: opts.body,
127
131
  signal: controller.signal
128
132
  });
129
133
  if (RETRYABLE_STATUS.has(res.status) && attempt < maxRetries) {
@@ -138,18 +142,16 @@ async function request(entry, req, ctx) {
138
142
  code,
139
143
  requestId: res.headers.get("x-request-id") ?? void 0,
140
144
  body,
141
- method: entry.method,
142
- path: entry.path,
143
- operation: operationLabel(entry)
145
+ method: errorMeta.method,
146
+ path: errorMeta.path,
147
+ operation: errorMeta.operation
144
148
  });
145
149
  }
146
- if (entry.produces === "binary") {
147
- const buf = Buffer.from(await res.arrayBuffer());
148
- return { status: res.status, headers: res.headers, bytes: buf };
149
- }
150
- const text = await res.text();
151
- const data = text ? JSON.parse(text) : void 0;
152
- return { status: res.status, headers: res.headers, data };
150
+ return {
151
+ status: res.status,
152
+ headers: res.headers,
153
+ bytes: Buffer.from(await res.arrayBuffer())
154
+ };
153
155
  } catch (err) {
154
156
  if (err instanceof ApiError) throw err;
155
157
  lastError = err;
@@ -163,11 +165,33 @@ async function request(entry, req, ctx) {
163
165
  throw new ApiError({
164
166
  status: 0,
165
167
  message: `Network error: ${lastError instanceof Error ? lastError.message : String(lastError)}`,
166
- method: entry.method,
167
- path: entry.path,
168
- operation: operationLabel(entry)
168
+ method: errorMeta.method,
169
+ path: errorMeta.path,
170
+ operation: errorMeta.operation
169
171
  });
170
172
  }
173
+ async function request(entry, req, ctx) {
174
+ const url = buildUrl(entry, req, ctx.apiBaseUrl);
175
+ const headers = {};
176
+ let body;
177
+ if (entry.consumes === "json" && req.body !== void 0) {
178
+ headers["content-type"] = "application/json";
179
+ body = JSON.stringify(req.body);
180
+ }
181
+ const raw = await rawRequest(
182
+ entry.method,
183
+ url,
184
+ { headers, body, accept: entry.produces === "binary" ? "*/*" : "application/json" },
185
+ ctx,
186
+ { method: entry.method, path: entry.path, operation: operationLabel(entry) }
187
+ );
188
+ if (entry.produces === "binary") {
189
+ return { status: raw.status, headers: raw.headers, bytes: raw.bytes };
190
+ }
191
+ const text = raw.bytes.toString("utf8");
192
+ const data = text ? JSON.parse(text) : void 0;
193
+ return { status: raw.status, headers: raw.headers, data };
194
+ }
171
195
 
172
196
  // src/generated/manifest.json
173
197
  var manifest_default = {
@@ -5160,8 +5184,9 @@ export {
5160
5184
  ApiError,
5161
5185
  UsageError,
5162
5186
  AuthError,
5187
+ rawRequest,
5163
5188
  manifest,
5164
5189
  callOperation,
5165
5190
  operations
5166
5191
  };
5167
- //# sourceMappingURL=chunk-XSRXBEWN.js.map
5192
+ //# sourceMappingURL=chunk-K664LS27.js.map