@base44-preview/cli 0.1.32-pr.663.16bdb8e → 0.1.32-pr.663.43d14f8

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/cli/index.js CHANGED
@@ -39570,9 +39570,9 @@ function tm(e, t, r) {
39570
39570
  return l(["<", r("name"), r("typeArguments"), " ", ...e.map(r, "attributes"), n.selfClosing ? " />" : ">"]);
39571
39571
  let i = n.attributes?.some((u) => V3(u.value) && u.value.value.includes(`
39572
39572
  `)), o = t.singleAttributePerLine && n.attributes.length > 1 ? E : A;
39573
- return l(["<", r("name"), r("typeArguments"), m(e.map(() => [o, r()], "attributes")), ...rm2(n, t, s)], { shouldBreak: i });
39573
+ return l(["<", r("name"), r("typeArguments"), m(e.map(() => [o, r()], "attributes")), ...rm3(n, t, s)], { shouldBreak: i });
39574
39574
  }
39575
- function rm2(e, t, r) {
39575
+ function rm3(e, t, r) {
39576
39576
  return e.selfClosing ? [A, "/>"] : nm(e, t, r) ? [">"] : [f, ">"];
39577
39577
  }
39578
39578
  function nm(e, t, r) {
@@ -111521,7 +111521,7 @@ function N62(e) {
111521
111521
  function nm2(e, t, a) {
111522
111522
  return ie10(t, a, e.typeParameters) || ie10(t, a, e.parameters) || S7(t, e.type);
111523
111523
  }
111524
- function rm3(e, t, a) {
111524
+ function rm4(e, t, a) {
111525
111525
  return ie10(t, a, e.types);
111526
111526
  }
111527
111527
  function im2(e, t, a) {
@@ -114489,7 +114489,7 @@ ${Me.join(`
114489
114489
  return S7(a, t.elementType);
114490
114490
  }, 190: function(t, a, _) {
114491
114491
  return ie10(a, _, t.elements);
114492
- }, 193: rm3, 194: rm3, 195: function(t, a, _) {
114492
+ }, 193: rm4, 194: rm4, 195: function(t, a, _) {
114493
114493
  return S7(a, t.checkType) || S7(a, t.extendsType) || S7(a, t.trueType) || S7(a, t.falseType);
114494
114494
  }, 196: function(t, a, _) {
114495
114495
  return S7(a, t.typeParameter);
@@ -239451,7 +239451,7 @@ var package_default = {
239451
239451
  jsonwebtoken: "^9.0.3",
239452
239452
  ky: "^1.14.2",
239453
239453
  lodash: "^4.17.23",
239454
- minisearch: "7.1.2",
239454
+ minisearch: "^7.1.2",
239455
239455
  ms: "^2.1.3",
239456
239456
  multer: "^2.0.0",
239457
239457
  nanoid: "^5.1.6",
@@ -249234,7 +249234,7 @@ var ParameterSchema = looseObject({
249234
249234
  example: unknown().optional()
249235
249235
  });
249236
249236
  var MediaTypesSchema = record(string2(), looseObject({ schema: unknown().optional() }));
249237
- var RequestBodySchema = looseObject({
249237
+ var MediaContentSchema = looseObject({
249238
249238
  content: MediaTypesSchema.optional()
249239
249239
  });
249240
249240
  var ResponseObjectSchema = looseObject({
@@ -249251,18 +249251,22 @@ var OperationSchema = looseObject({
249251
249251
  responses: record(string2(), unknown()).optional(),
249252
249252
  security: array(SecurityRequirementSchema).optional()
249253
249253
  });
249254
- var PathItemSchema = looseObject({
249255
- ...Object.fromEntries(HTTP_METHODS.map((method) => [method, OperationSchema.optional()])),
249256
- parameters: array(unknown()).optional()
249257
- });
249258
249254
  var OpenApiSpecSchema = looseObject({
249259
249255
  openapi: string2(),
249260
- paths: record(string2(), PathItemSchema),
249256
+ paths: record(string2(), record(string2(), unknown())),
249261
249257
  components: looseObject({
249262
249258
  schemas: record(string2(), unknown()).optional()
249263
249259
  }).optional(),
249264
- security: array(SecurityRequirementSchema).optional()
249260
+ security: array(SecurityRequirementSchema).optional().catch(undefined)
249265
249261
  });
249262
+ var ParameterListSchema = array(unknown());
249263
+
249264
+ // src/core/api-spec/text.ts
249265
+ var DOCS_CALLOUT = /<(Info|Note|Tip|Check|Warning)>([\s\S]*?)<\/\1>/g;
249266
+ var RELATIVE_LINK = /\[([^\]]+)\]\(\/[^)]*\)/g;
249267
+ function cleanText(text) {
249268
+ return text.replace(DOCS_CALLOUT, (_, kind, body) => kind === "Warning" ? `Warning: ${body}` : body).replace(RELATIVE_LINK, "$1");
249269
+ }
249266
249270
 
249267
249271
  // src/core/api-spec/operations.ts
249268
249272
  var PERSONAL_ACCESS_TOKEN_SCHEME = "PersonalAccessTokenAuth";
@@ -249274,9 +249278,19 @@ function isReadOnly(operation, spec) {
249274
249278
  function parameterText(operation) {
249275
249279
  return (operation.parameters ?? []).flatMap((parameter) => {
249276
249280
  const parsed = ParameterSchema.safeParse(parameter);
249277
- return parsed.success ? [parsed.data.name, parsed.data.description ?? ""] : [];
249281
+ return parsed.success ? [parsed.data.name, cleanText(parsed.data.description ?? "")] : [];
249278
249282
  }).join(" ");
249279
249283
  }
249284
+ var COMPONENT_REF = /^#\/components\/([^/]+)\/([^/]+)$/;
249285
+ function resolveComponentRef(spec, value) {
249286
+ const ref = value !== null && typeof value === "object" ? value.$ref : undefined;
249287
+ const match = typeof ref === "string" ? COMPONENT_REF.exec(ref) : null;
249288
+ if (!match?.[1] || !match[2]) {
249289
+ return value;
249290
+ }
249291
+ const components = spec.components;
249292
+ return components?.[match[1]]?.[match[2]] ?? value;
249293
+ }
249280
249294
  function mergeParameters(shared, own) {
249281
249295
  if (!shared?.length) {
249282
249296
  return own;
@@ -249293,13 +249307,15 @@ function mergeParameters(shared, own) {
249293
249307
  }
249294
249308
  function listOperations(spec) {
249295
249309
  return Object.entries(spec.paths).flatMap(([path, item]) => HTTP_METHODS.flatMap((method) => {
249296
- const declared = item[method];
249297
- if (!declared) {
249310
+ const parsed = OperationSchema.safeParse(item[method]);
249311
+ if (!parsed.success) {
249298
249312
  return [];
249299
249313
  }
249314
+ const shared = ParameterListSchema.safeParse(item.parameters);
249315
+ const resolve = (list) => list?.map((parameter) => resolveComponentRef(spec, parameter));
249300
249316
  const operation = {
249301
- ...declared,
249302
- parameters: mergeParameters(item.parameters, declared.parameters)
249317
+ ...parsed.data,
249318
+ parameters: mergeParameters(resolve(shared.success ? shared.data : undefined), resolve(parsed.data.parameters))
249303
249319
  };
249304
249320
  return [
249305
249321
  {
@@ -249307,7 +249323,7 @@ function listOperations(spec) {
249307
249323
  method: method.toUpperCase(),
249308
249324
  path,
249309
249325
  summary: operation.summary ?? "",
249310
- description: operation.description ?? "",
249326
+ description: cleanText(operation.description ?? ""),
249311
249327
  parameterText: parameterText(operation),
249312
249328
  readOnly: isReadOnly(operation, spec),
249313
249329
  operation
@@ -249317,22 +249333,14 @@ function listOperations(spec) {
249317
249333
  }
249318
249334
  function pathSegments(path) {
249319
249335
  const pathname = path.split(/[?#]/, 1)[0] ?? "";
249320
- return pathname.split("/").filter(Boolean);
249336
+ return pathname.replace(/^\/+|\/+$/g, "").split("/");
249321
249337
  }
249322
249338
  function segmentPattern(segment) {
249323
249339
  const source = segment.split(/(\{[^}]+\})/).map((part) => part.startsWith("{") ? "[^/]+" : part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("");
249324
249340
  return new RegExp(`^${source}$`);
249325
249341
  }
249326
- function specificity(templateSegments) {
249327
- return templateSegments.map((segment) => segment.includes("{") ? 0 : 1);
249328
- }
249329
- function compareSpecificity(a, b) {
249330
- for (let i = 0;i < a.length; i++) {
249331
- if (a[i] !== b[i]) {
249332
- return (b[i] ?? 0) - (a[i] ?? 0);
249333
- }
249334
- }
249335
- return 0;
249342
+ function literalSegments(path) {
249343
+ return pathSegments(path).map((segment) => segment.includes("{") ? "0" : "1").join("");
249336
249344
  }
249337
249345
  function matchOperation(operations, method, concretePath) {
249338
249346
  const upperMethod = method.toUpperCase();
@@ -249344,11 +249352,12 @@ function matchOperation(operations, method, concretePath) {
249344
249352
  const template = pathSegments(op.path);
249345
249353
  return template.length === segments.length && template.every((part, i) => segmentPattern(part).test(segments[i] ?? ""));
249346
249354
  });
249347
- return candidates.sort((a, b) => compareSpecificity(specificity(pathSegments(a.path)), specificity(pathSegments(b.path))))[0];
249355
+ return candidates.sort((a, b) => literalSegments(b.path).localeCompare(literalSegments(a.path)))[0];
249348
249356
  }
249357
+
249358
+ // src/core/api-spec/contract.ts
249349
249359
  var SCHEMA_REF_PREFIX = "#/components/schemas/";
249350
249360
  var MAX_REF_DEPTH = 4;
249351
- var FRAMEWORK_VALIDATION_ERROR = "Validation Error";
249352
249361
  function inlineRefs(node, schemas, seen = new Set, depth = 0) {
249353
249362
  if (depth > MAX_REF_DEPTH) {
249354
249363
  return node;
@@ -249373,12 +249382,8 @@ function inlineRefs(node, schemas, seen = new Set, depth = 0) {
249373
249382
  inlineRefs(value, schemas, seen, depth)
249374
249383
  ]));
249375
249384
  }
249376
- function jsonSchemaOf(value) {
249377
- const parsed = RequestBodySchema.safeParse(value);
249378
- return parsed.success ? parsed.data.content?.["application/json"]?.schema : undefined;
249379
- }
249380
- function requestBodyOf(value) {
249381
- const parsed = RequestBodySchema.safeParse(value);
249385
+ function bodyOf(value) {
249386
+ const parsed = MediaContentSchema.safeParse(value);
249382
249387
  const content = parsed.success ? parsed.data.content ?? {} : {};
249383
249388
  const contentType = "application/json" in content ? "application/json" : Object.keys(content)[0];
249384
249389
  return contentType ? { contentType, schema: content[contentType]?.schema } : {};
@@ -249392,8 +249397,10 @@ function leftoverRefs(node, schemas, found = new Map) {
249392
249397
  for (const [key, value] of Object.entries(node)) {
249393
249398
  if (key === "$ref" && typeof value === "string" && value.startsWith(SCHEMA_REF_PREFIX) && !found.has(value)) {
249394
249399
  const schema = schemas[value.slice(SCHEMA_REF_PREFIX.length)];
249395
- found.set(value, schema);
249396
- leftoverRefs(schema, schemas, found);
249400
+ if (schema !== undefined) {
249401
+ found.set(value, schema);
249402
+ leftoverRefs(schema, schemas, found);
249403
+ }
249397
249404
  } else {
249398
249405
  leftoverRefs(value, schemas, found);
249399
249406
  }
@@ -249401,16 +249408,51 @@ function leftoverRefs(node, schemas, found = new Map) {
249401
249408
  }
249402
249409
  return found;
249403
249410
  }
249411
+ var SCHEMA_DATA_KEYS = new Set([
249412
+ "example",
249413
+ "examples",
249414
+ "default",
249415
+ "enum",
249416
+ "const"
249417
+ ]);
249418
+ function slimSchema(node, isPropertyMap = false) {
249419
+ if (Array.isArray(node)) {
249420
+ return node.map((item) => slimSchema(item));
249421
+ }
249422
+ if (node === null || typeof node !== "object") {
249423
+ return node;
249424
+ }
249425
+ const entries = Object.entries(node);
249426
+ if (isPropertyMap) {
249427
+ return Object.fromEntries(entries.map(([name, value]) => [name, slimSchema(value)]));
249428
+ }
249429
+ const slim = {};
249430
+ for (const [key, value] of entries) {
249431
+ if (key === "title" && typeof value === "string") {
249432
+ continue;
249433
+ }
249434
+ slim[key] = SCHEMA_DATA_KEYS.has(key) ? value : key === "properties" ? slimSchema(value, true) : key === "description" && typeof value === "string" ? cleanText(value) : slimSchema(value);
249435
+ }
249436
+ const { anyOf, ...rest } = slim;
249437
+ const nullable = Array.isArray(anyOf) && anyOf.length === 2 ? nullableType(anyOf) : undefined;
249438
+ return nullable ? { type: [nullable, "null"], ...rest } : slim;
249439
+ }
249440
+ function nullableType(variants) {
249441
+ const types = variants.map((variant) => variant !== null && typeof variant === "object" && Object.keys(variant).length === 1 && typeof variant.type === "string" ? variant.type : undefined);
249442
+ if (types.includes(undefined) || !types.includes("null")) {
249443
+ return;
249444
+ }
249445
+ return types.find((type) => type !== "null");
249446
+ }
249404
249447
  function getOperationContract(spec, op) {
249405
249448
  const schemas = spec.components?.schemas ?? {};
249406
- const inline = (node) => node === undefined ? null : inlineRefs(node, schemas);
249449
+ const inline = (node) => node === undefined ? null : slimSchema(inlineRefs(node, schemas));
249407
249450
  const responses = Object.entries(op.operation.responses ?? {}).flatMap(([status, response]) => {
249408
- const parsed = ResponseObjectSchema.safeParse(response);
249451
+ const parsed = ResponseObjectSchema.safeParse(resolveComponentRef(spec, response));
249409
249452
  return parsed.success ? [[status, parsed.data]] : [];
249410
249453
  });
249411
- const success = responses.filter(([status]) => status.startsWith("2")).sort(([a], [b]) => a.localeCompare(b)).map(([, response]) => jsonSchemaOf(response)).find(Boolean);
249412
- const errors = responses.filter(([status, response]) => !status.startsWith("2") && response.description !== FRAMEWORK_VALIDATION_ERROR);
249413
- const requestBody = requestBodyOf(op.operation.requestBody);
249454
+ const success = responses.filter(([status]) => status.startsWith("2")).sort(([a], [b]) => a.localeCompare(b)).map(([, response]) => bodyOf(response).schema).find(Boolean);
249455
+ const requestBody = bodyOf(resolveComponentRef(spec, op.operation.requestBody));
249414
249456
  const contract = {
249415
249457
  endpoint: op.endpoint,
249416
249458
  method: op.method,
@@ -249420,7 +249462,7 @@ function getOperationContract(spec, op) {
249420
249462
  parameters: (op.operation.parameters ?? []).flatMap((parameter) => {
249421
249463
  const parsed = ParameterSchema.safeParse(parameter);
249422
249464
  if (!parsed.success) {
249423
- return [];
249465
+ return [parameter];
249424
249466
  }
249425
249467
  const { name, in: location2, required, schema, description } = parsed.data;
249426
249468
  const inSchema = schema !== null && typeof schema === "object" && "description" in schema;
@@ -249430,23 +249472,23 @@ function getOperationContract(spec, op) {
249430
249472
  in: location2,
249431
249473
  required: required ?? false,
249432
249474
  schema: inline(schema ?? {}),
249433
- ...description && !inSchema ? { description } : {},
249475
+ ...description && !inSchema ? { description: cleanText(description) } : {},
249434
249476
  ..."example" in parsed.data ? { example: parsed.data.example } : {}
249435
249477
  }
249436
249478
  ];
249437
249479
  }),
249438
249480
  ...requestBody.contentType && requestBody.contentType !== "application/json" ? { requestBodyContentType: requestBody.contentType } : {},
249439
249481
  requestBodySchema: inline(requestBody.schema),
249440
- responseSchema: inline(success),
249441
- errors: Object.fromEntries(errors.map(([status, response]) => [status, response.description ?? ""]))
249482
+ responseSchema: inline(success)
249442
249483
  };
249443
249484
  const refs = leftoverRefs(contract, schemas);
249444
249485
  return {
249445
249486
  ...contract,
249446
- ...refs.size > 0 ? { refs: Object.fromEntries(refs) } : {}
249487
+ ...refs.size > 0 ? {
249488
+ refs: Object.fromEntries([...refs].map(([ref, schema]) => [ref, slimSchema(schema)]))
249489
+ } : {}
249447
249490
  };
249448
249491
  }
249449
-
249450
249492
  // src/core/api-spec/grep.ts
249451
249493
  function grepOperations(spec, operations, pattern, options = {}) {
249452
249494
  const regex = new RegExp(pattern, options.ignoreCase ? "i" : "");
@@ -249454,6 +249496,7 @@ function grepOperations(spec, operations, pattern, options = {}) {
249454
249496
  }
249455
249497
  // src/core/api-spec/request.ts
249456
249498
  var MAX_ERROR_BODY_CHARS = 4000;
249499
+ var QUERY_STRING = /\?\S*/g;
249457
249500
  async function readBody(response) {
249458
249501
  try {
249459
249502
  const text = (await response.clone().text()).trim();
@@ -249462,13 +249505,18 @@ async function readBody(response) {
249462
249505
  return;
249463
249506
  }
249464
249507
  }
249508
+ function normalizePath(path) {
249509
+ const url = new URL(path.replace(/^\/*/, "/"), "http://placeholder");
249510
+ return `${url.pathname}${url.search}`;
249511
+ }
249465
249512
  async function sendApiRequest(method, path, body) {
249466
249513
  try {
249467
249514
  const response = await base44Client(path.replace(/^\/+/, ""), {
249468
249515
  method,
249469
249516
  body,
249470
- headers: body === undefined ? {} : { "Content-Type": "application/json" },
249471
- timeout: false
249517
+ headers: typeof body === "string" ? { "Content-Type": "application/json" } : {},
249518
+ timeout: false,
249519
+ retry: { methods: ["get", "head"] }
249472
249520
  });
249473
249521
  return {
249474
249522
  status: response.status,
@@ -249477,19 +249525,27 @@ async function sendApiRequest(method, path, body) {
249477
249525
  };
249478
249526
  } catch (error) {
249479
249527
  const apiError = await ApiError.fromHttpError(error, `calling ${method} ${path}`);
249480
- const raw = error instanceof HTTPError ? await readBody(error.response) : undefined;
249481
- throw new ApiError(apiError.message, {
249482
- statusCode: apiError.statusCode,
249483
- requestUrl: apiError.requestUrl,
249484
- requestMethod: apiError.requestMethod,
249485
- requestId: apiError.requestId,
249486
- hints: apiError.hints,
249487
- details: raw ? [`Response body: ${raw}`] : apiError.details
249488
- });
249528
+ const response = error instanceof HTTPError ? error.response : undefined;
249529
+ const raw = response ? await readBody(response) : undefined;
249530
+ const retryAfter = response?.headers.get("retry-after") ?? undefined;
249531
+ throw redactedApiError(apiError, raw, method, path, retryAfter);
249489
249532
  }
249490
249533
  }
249534
+ function redactedApiError(apiError, raw, method, path, retryAfter) {
249535
+ const wait = retryAfter ? ` (retry after ${/^\d+$/.test(retryAfter) ? `${retryAfter} s` : retryAfter})` : "";
249536
+ const reason = apiError.statusCode !== undefined ? `HTTP ${apiError.statusCode}${wait}` : (apiError.cause?.message ?? "request failed").replace(QUERY_STRING, "");
249537
+ const message = `Error calling ${method} ${path.split("?", 1)[0]}: ${reason}`;
249538
+ return new ApiError(message, {
249539
+ statusCode: apiError.statusCode,
249540
+ requestUrl: apiError.requestUrl?.split("?", 1)[0],
249541
+ requestMethod: apiError.requestMethod,
249542
+ requestId: apiError.requestId,
249543
+ hints: apiError.hints,
249544
+ details: raw ? [`Response body: ${raw}`] : apiError.details
249545
+ });
249546
+ }
249491
249547
  // src/core/api-spec/spec.ts
249492
- import { rename, stat as stat3 } from "node:fs/promises";
249548
+ import { rename, rm, stat as stat3 } from "node:fs/promises";
249493
249549
  import { join as join22 } from "node:path";
249494
249550
  var SPEC_CACHE_TTL_MS = 60 * 60 * 1000;
249495
249551
  function getSpecCachePath(apiUrl = getBase44ApiUrl()) {
@@ -249544,12 +249600,19 @@ async function loadSpec(options = {}) {
249544
249600
  const text = await downloadSpec();
249545
249601
  const spec = parseSpec(text);
249546
249602
  const partial = `${path}.${process.pid}.tmp`;
249547
- await writeFile(partial, text);
249548
- await rename(partial, path);
249603
+ try {
249604
+ await writeFile(partial, text);
249605
+ await rename(partial, path);
249606
+ } catch {
249607
+ await rm(partial, { force: true }).catch(() => {
249608
+ return;
249609
+ });
249610
+ }
249549
249611
  return { text, spec };
249550
249612
  }
249551
249613
  // src/cli/commands/api/shared.ts
249552
249614
  import { fstatSync } from "node:fs";
249615
+ import { basename as basename6 } from "node:path";
249553
249616
  function formatJson(value) {
249554
249617
  return toJsonStdout(value, { compact: !process.stdout.isTTY });
249555
249618
  }
@@ -249601,6 +249664,41 @@ async function readRequestBody(flag, log) {
249601
249664
  }
249602
249665
  return flag;
249603
249666
  }
249667
+ var FORM_FILE = /^@(.+?)(?:;type=([^;]+))?$/;
249668
+ async function readFormBody(fields) {
249669
+ const form = new FormData;
249670
+ for (const field of fields) {
249671
+ const separator = field.indexOf("=");
249672
+ if (separator < 1) {
249673
+ throw new InvalidInputError(`--form takes name=value or name=@file, got "${field}".`);
249674
+ }
249675
+ const name = field.slice(0, separator);
249676
+ const value = field.slice(separator + 1);
249677
+ const file = FORM_FILE.exec(value);
249678
+ if (file?.[1]) {
249679
+ const type = file[2] ?? "application/octet-stream";
249680
+ const blob = new Blob([await readFile(file[1])], { type });
249681
+ form.append(name, blob, basename6(file[1]));
249682
+ } else {
249683
+ form.append(name, value);
249684
+ }
249685
+ }
249686
+ return form;
249687
+ }
249688
+ function withoutQuery(path) {
249689
+ return path.split("?", 1)[0] ?? "";
249690
+ }
249691
+ function reportedFetchCommand(method, path, options) {
249692
+ return {
249693
+ name: "api fetch",
249694
+ args: [method, withoutQuery(path)],
249695
+ options: {
249696
+ ...options,
249697
+ ...options.body === undefined ? {} : { body: "[not reported]" },
249698
+ ...Array.isArray(options.form) && options.form.length > 0 ? { form: "[not reported]" } : {}
249699
+ }
249700
+ };
249701
+ }
249604
249702
 
249605
249703
  // src/cli/commands/api/catalog.ts
249606
249704
  async function catalogAction(ctx, area, options) {
@@ -249625,7 +249723,7 @@ async function findOperation(ctx, method, path, { refresh, flag }) {
249625
249723
  const { spec } = await loadSpecTask(ctx, refresh);
249626
249724
  const op = matchOperation(listOperations(spec), method, path);
249627
249725
  if (!op) {
249628
- throw new InvalidInputError(`No operation in the API spec matches ${method} ${path}.`, {
249726
+ throw new InvalidInputError(`No operation in the API spec matches ${method} ${withoutQuery(path)}.`, {
249629
249727
  hints: [
249630
249728
  {
249631
249729
  message: "The cached spec may predate this route; fetch it again",
@@ -249640,6 +249738,9 @@ async function findOperation(ctx, method, path, { refresh, flag }) {
249640
249738
  }
249641
249739
  return { spec, op };
249642
249740
  }
249741
+ var MULTIPART_HINT = "Send this body with --form name=value, and --form name=@path for files.";
249742
+ var CONTRACT_HELP = `
249743
+ The contract is JSON; cut it down with e.g. | jq '.parameters, .requestBodySchema'`;
249643
249744
  var TEXT_CONTENT_TYPES = [
249644
249745
  "json",
249645
249746
  "text/",
@@ -249647,8 +249748,16 @@ var TEXT_CONTENT_TYPES = [
249647
249748
  "javascript",
249648
249749
  "x-www-form-urlencoded"
249649
249750
  ];
249650
- function isText(contentType) {
249651
- return !contentType || TEXT_CONTENT_TYPES.some((hint) => contentType.toLowerCase().includes(hint));
249751
+ function decodeText(body, contentType) {
249752
+ const type = contentType.toLowerCase();
249753
+ if (type && !TEXT_CONTENT_TYPES.some((hint) => type.includes(hint))) {
249754
+ return;
249755
+ }
249756
+ try {
249757
+ return new TextDecoder("utf-8", { fatal: true }).decode(body);
249758
+ } catch {
249759
+ return;
249760
+ }
249652
249761
  }
249653
249762
  async function formatResponse({ status, contentType, body }, output, jsonMode) {
249654
249763
  if (output !== undefined) {
@@ -249658,7 +249767,8 @@ async function formatResponse({ status, contentType, body }, output, jsonMode) {
249658
249767
  if (body.length === 0) {
249659
249768
  return formatJson({ status });
249660
249769
  }
249661
- if (!isText(contentType)) {
249770
+ const text = decodeText(body, contentType);
249771
+ if (text === undefined) {
249662
249772
  return formatJson({
249663
249773
  status,
249664
249774
  contentType,
@@ -249666,36 +249776,42 @@ async function formatResponse({ status, contentType, body }, output, jsonMode) {
249666
249776
  note: "Binary body not printed; add --output <file> to save it."
249667
249777
  });
249668
249778
  }
249669
- const text = new TextDecoder().decode(body);
249670
- try {
249671
- return formatJson(JSON.parse(text));
249672
- } catch {
249673
- if (jsonMode) {
249674
- return formatJson({ status, contentType, body: text });
249675
- }
249676
- return text.endsWith(`
249779
+ const asIs = text.endsWith(`
249677
249780
  `) ? text : `${text}
249678
249781
  `;
249782
+ try {
249783
+ const parsed = JSON.parse(text);
249784
+ return process.stdout.isTTY ? formatJson(parsed) : asIs;
249785
+ } catch {
249786
+ return jsonMode ? formatJson({ status, contentType, body: text }) : asIs;
249679
249787
  }
249680
249788
  }
249681
249789
  async function fetchAction(ctx, methodArg, path, options, command) {
249790
+ ctx.errorReporter.setContext({
249791
+ command: reportedFetchCommand(methodArg ?? "", path ?? "", { ...options })
249792
+ });
249682
249793
  if (!methodArg || !path) {
249683
249794
  if (options.help) {
249684
- const usage = command.helpInformation();
249795
+ const usage = `${command.helpInformation()}${CONTRACT_HELP}
249796
+ `;
249685
249797
  return { stdout: ctx.jsonMode ? formatJson({ usage }) : usage };
249686
249798
  }
249687
249799
  throw new InvalidInputError("Provide a method and a path, e.g. GET /api/apps.");
249688
249800
  }
249689
249801
  const method = methodArg.toUpperCase();
249802
+ const target = normalizePath(path);
249690
249803
  if (options.help) {
249691
- const { spec, op } = await findOperation(ctx, method, path, {
249804
+ const { spec, op } = await findOperation(ctx, method, target, {
249692
249805
  refresh: options.refresh,
249693
249806
  flag: "--help"
249694
249807
  });
249695
- return { stdout: formatJson(getOperationContract(spec, op)) };
249808
+ const contract = getOperationContract(spec, op);
249809
+ return {
249810
+ stdout: formatJson(contract.requestBodyContentType === "multipart/form-data" ? { ...contract, hint: MULTIPART_HINT } : contract)
249811
+ };
249696
249812
  }
249697
249813
  if (options.readOnly) {
249698
- const { op } = await findOperation(ctx, method, path, {
249814
+ const { op } = await findOperation(ctx, method, target, {
249699
249815
  refresh: options.refresh,
249700
249816
  flag: "--read-only"
249701
249817
  });
@@ -249703,17 +249819,13 @@ async function fetchAction(ctx, methodArg, path, options, command) {
249703
249819
  throw new InvalidInputError(`Refused under --read-only: ${op.method} ${op.path} is not a read-only operation. Nothing was sent.`);
249704
249820
  }
249705
249821
  }
249706
- ctx.errorReporter.setContext({
249707
- command: {
249708
- name: "api fetch",
249709
- args: [method, path.split("?", 1)[0] ?? ""],
249710
- options: { ...options, body: options.body && "[not reported]" }
249711
- }
249712
- });
249822
+ if (options.body !== undefined && options.form.length > 0) {
249823
+ throw new InvalidInputError("Use --body or --form, not both.");
249824
+ }
249713
249825
  await ensureAuth(ctx);
249714
- const body = await readRequestBody(options.body, ctx.log);
249715
- const response = await ctx.runTask(`Calling ${method} ${path}`, () => sendApiRequest(method, path, body), {
249716
- successMessage: `Called ${method} ${path}`,
249826
+ const body = options.form.length > 0 ? await readFormBody(options.form) : await readRequestBody(options.body, ctx.log);
249827
+ const response = await ctx.runTask(`Calling ${method} ${target}`, () => sendApiRequest(method, target, body), {
249828
+ successMessage: `Called ${method} ${target}`,
249717
249829
  errorMessage: "Request failed"
249718
249830
  });
249719
249831
  return {
@@ -249724,7 +249836,7 @@ function getApiFetchCommand() {
249724
249836
  return new Base44Command("fetch", {
249725
249837
  requireAuth: false,
249726
249838
  requireAppContext: false
249727
- }).description("Call a Base44 API operation; add --help after a path for its contract").helpOption(false).argument("[method]", "HTTP method, e.g. GET or POST").argument("[path]", 'Concrete path with any query string, e.g. "/api/apps/<app-id>/workflows/runs?status=failed"').option("--body <json>", "Request body: JSON, @file.json, or @- to read it from stdin").option("--output <file>", "Save the response body to a file").option("--read-only", "Refuse, before sending, any operation the spec does not mark read-only").option("--refresh", REFRESH_OPTION_HELP).option("-h, --help", "With a method and path, print that operation's contract; otherwise this help").action(fetchAction);
249839
+ }).description("Call a Base44 API operation; add --help after a path for its contract").helpOption(false).argument("[method]", "HTTP method, e.g. GET or POST").argument("[path]", 'Concrete path with any query string, e.g. "/api/apps/<app-id>/workflows/runs?status=failed"').option("--body <json>", "Request body: JSON, @file.json, or @- to read it from stdin").option("--form <field>", "Multipart field: name=value, or name=@file to attach a file (repeatable)", (field, fields) => [...fields, field], []).option("--output <file>", "Save the response body to a file").option("--read-only", "Refuse, before sending, any operation the spec does not mark read-only").option("--refresh", REFRESH_OPTION_HELP).option("-h, --help", "With a method and path, print that operation's contract; otherwise this help").addHelpText("after", CONTRACT_HELP).action(fetchAction);
249728
249840
  }
249729
249841
 
249730
249842
  // src/cli/commands/api/grep.ts
@@ -249756,7 +249868,7 @@ function getApiGrepCommand() {
249756
249868
  return new Base44Command("grep", {
249757
249869
  requireAuth: false,
249758
249870
  requireAppContext: false
249759
- }).description("Search the API spec with a regular expression, for when search misses").argument("<pattern>", 'Regular expression, e.g. "runs.*status"').option("--area <area>", "Search only one area's operations (see base44 api catalog)").option("-i, --ignore-case", "Case-insensitive match").option("--limit <n>", "Most operations to return (default 20)").option("--read-only", READ_ONLY_FILTER_HELP).option("--refresh", REFRESH_OPTION_HELP).action(grepAction);
249871
+ }).description("Search the API spec with a regular expression, for when search misses").argument("<pattern>", `Regular expression over each operation's contract as JSON text (quotes and newlines appear escaped), e.g. "runs.*status"`).option("--area <area>", "Search only one area's operations (see base44 api catalog)").option("-i, --ignore-case", "Case-insensitive match").option("--limit <n>", "Most operations to return (default 20)").option("--read-only", READ_ONLY_FILTER_HELP).option("--refresh", REFRESH_OPTION_HELP).action(grepAction);
249760
249872
  }
249761
249873
 
249762
249874
  // src/cli/commands/api/search.ts
@@ -251543,7 +251655,7 @@ function getBuildCommand() {
251543
251655
  }
251544
251656
 
251545
251657
  // src/cli/commands/project/create.ts
251546
- import { basename as basename6, resolve as resolve11 } from "node:path";
251658
+ import { basename as basename7, resolve as resolve11 } from "node:path";
251547
251659
  var import_kebabCase = __toESM(require_kebabCase(), 1);
251548
251660
 
251549
251661
  // src/cli/commands/project/scaffold-shared.ts
@@ -251708,8 +251820,8 @@ async function createInteractive(options, ctx) {
251708
251820
  name: () => {
251709
251821
  return options.name ? Promise.resolve(options.name) : Ze({
251710
251822
  message: "What is the name of your project?",
251711
- placeholder: basename6(process.cwd()),
251712
- initialValue: basename6(process.cwd()),
251823
+ placeholder: basename7(process.cwd()),
251824
+ initialValue: basename7(process.cwd()),
251713
251825
  validate: (value) => {
251714
251826
  if (!value || value.trim().length === 0) {
251715
251827
  return "Every project deserves a name";
@@ -252404,7 +252516,7 @@ function getLogsCommand() {
252404
252516
  }
252405
252517
 
252406
252518
  // src/cli/commands/project/scaffold.ts
252407
- import { basename as basename7, resolve as resolve12 } from "node:path";
252519
+ import { basename as basename8, resolve as resolve12 } from "node:path";
252408
252520
  function resolveAppId(options) {
252409
252521
  const appId = options.appId;
252410
252522
  if (!appId) {
@@ -252421,7 +252533,7 @@ async function scaffoldAction(ctx, name, options, command) {
252421
252533
  const { log, runTask } = ctx;
252422
252534
  const appId = resolveAppId(command.optsWithGlobals());
252423
252535
  const resolvedPath = resolve12("./");
252424
- const projectName = (name ?? basename7(resolvedPath)).trim();
252536
+ const projectName = (name ?? basename8(resolvedPath)).trim();
252425
252537
  const template = await getTemplateById("backend-only");
252426
252538
  log.info(`Scaffolding project at ${resolvedPath}`);
252427
252539
  const { projectId } = await runTask("Setting up your project...", async () => {
@@ -262316,7 +262428,7 @@ var nativeEnumType = ZodNativeEnum.create;
262316
262428
  var promiseType = ZodPromise.create;
262317
262429
  var effectsType = ZodEffects.create;
262318
262430
  var optionalType = ZodOptional2.create;
262319
- var nullableType = ZodNullable2.create;
262431
+ var nullableType2 = ZodNullable2.create;
262320
262432
  var preprocessType = ZodEffects.createWithPreprocess;
262321
262433
  var pipelineType = ZodPipeline.create;
262322
262434
  // ../functions-compiler/src/contracts.ts
@@ -262346,7 +262458,7 @@ var bundleAppRequestSchema = objectType({
262346
262458
  var ACTIVATION_MODE = "pull";
262347
262459
 
262348
262460
  // ../functions-compiler/src/deno-bundle.ts
262349
- import { mkdtemp, rm, writeFile as writeFile2 } from "node:fs/promises";
262461
+ import { mkdtemp, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
262350
262462
  import { tmpdir as tmpdir2 } from "node:os";
262351
262463
  import path21 from "node:path";
262352
262464
 
@@ -262953,7 +263065,7 @@ async function bundleToModule(prepared, nodeModulesDir = "none") {
262953
263065
  warnings: result.warnings.map((w) => w.text)
262954
263066
  };
262955
263067
  } finally {
262956
- await rm(dir, { recursive: true, force: true });
263068
+ await rm2(dir, { recursive: true, force: true });
262957
263069
  }
262958
263070
  }
262959
263071
  function buildFailureErrors(e, dir) {
@@ -267944,7 +268056,7 @@ function createPattern(matcher) {
267944
268056
  }
267945
268057
  return () => false;
267946
268058
  }
267947
- function normalizePath(path) {
268059
+ function normalizePath2(path) {
267948
268060
  if (typeof path !== "string")
267949
268061
  throw new Error("string expected");
267950
268062
  path = sp3.normalize(path);
@@ -267958,7 +268070,7 @@ function normalizePath(path) {
267958
268070
  return path;
267959
268071
  }
267960
268072
  function matchPatterns(patterns, testString, stats) {
267961
- const path = normalizePath(testString);
268073
+ const path = normalizePath2(testString);
267962
268074
  for (let index = 0;index < patterns.length; index++) {
267963
268075
  const pattern = patterns[index];
267964
268076
  if (pattern(path, stats)) {
@@ -273318,4 +273430,4 @@ export {
273318
273430
  runCLI
273319
273431
  };
273320
273432
 
273321
- //# debugId=719BE22CF0CDD92864756E2164756E21
273433
+ //# debugId=67402E43327C710664756E2164756E21