@base44-preview/cli 0.2.7-pr.687.d213a6e → 0.2.7-pr.689.072f10a

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
@@ -236688,9 +236688,9 @@ async function downloadProject(projectId, projectPath) {
236688
236688
  await makeDirectory(projectPath);
236689
236689
  await pipeline(nodeStream, extract({ cwd: projectPath }));
236690
236690
  }
236691
- async function getAppUserToken() {
236691
+ async function getAppUserToken(appId = getAppContext().id) {
236692
236692
  try {
236693
- const response = await getAppClient().get("auth/token").json();
236693
+ const response = await base44Client.get(`api/apps/${appId}/auth/token`).json();
236694
236694
  return response.token;
236695
236695
  } catch (error) {
236696
236696
  throw await ApiError.fromHttpError(error, "exchanging platform token for app user token");
@@ -238254,9 +238254,6 @@ async function pullAllConnectors() {
238254
238254
  }
238255
238255
  // src/core/resources/connector/push.ts
238256
238256
  async function pushConnectors(connectors) {
238257
- if (connectors.length === 0) {
238258
- return { results: [] };
238259
- }
238260
238257
  const stripeConnector = connectors.find((c) => c.type === STRIPE_CONNECTOR_TYPE);
238261
238258
  const oauthConnectors = connectors.filter((c) => c.type !== STRIPE_CONNECTOR_TYPE);
238262
238259
  const oauthResults = await syncOAuthConnectors(oauthConnectors);
@@ -246982,7 +246979,8 @@ async function deployAll(projectData, options) {
246982
246979
  await agentSkillResource.push(agentSkills);
246983
246980
  await agentResource.push(agents);
246984
246981
  await authConfigResource.push(authConfig);
246985
- const { results: connectorResults } = await pushConnectors(connectors);
246982
+ const skipConnectorSync = connectors.length === 0 && hasWorkspaceApiKeyAuth();
246983
+ const connectorResults = skipConnectorSync ? [] : (await pushConnectors(connectors)).results;
246986
246984
  const appUrl = await deployProjectSite(project, options);
246987
246985
  return appUrl ? { appUrl, connectorResults } : { connectorResults };
246988
246986
  }
@@ -247122,6 +247120,23 @@ var base44Client = distribution_default.create({
247122
247120
  afterResponse: [handleUnauthorized]
247123
247121
  }
247124
247122
  });
247123
+ function getAppUserClient(token) {
247124
+ return distribution_default.create({
247125
+ prefixUrl: getBase44ApiUrl(),
247126
+ headers: {
247127
+ "User-Agent": "Base44 CLI",
247128
+ Authorization: `Bearer ${token}`
247129
+ },
247130
+ hooks: {
247131
+ beforeRequest: [
247132
+ (request) => {
247133
+ request.headers.set("X-Request-ID", randomUUID2());
247134
+ },
247135
+ captureRequestBody
247136
+ ]
247137
+ }
247138
+ });
247139
+ }
247125
247140
  function getAppClient() {
247126
247141
  const { id } = getAppContext();
247127
247142
  return base44Client.extend({
@@ -249355,10 +249370,15 @@ function cleanText(text) {
249355
249370
  // src/core/api-spec/operations.ts
249356
249371
  var PERSONAL_ACCESS_TOKEN_SCHEME = "PersonalAccessTokenAuth";
249357
249372
  var READ_ONLY_SCOPE = "read_only";
249373
+ var APP_USER_TOKEN_SCHEME = "AppUserTokenAuth";
249358
249374
  function isReadOnly(operation, spec) {
249359
249375
  const security = operation.security ?? spec.security ?? [];
249360
249376
  return security.some((requirement) => requirement[PERSONAL_ACCESS_TOKEN_SCHEME]?.includes(READ_ONLY_SCOPE));
249361
249377
  }
249378
+ function takesAppUserToken(operation, spec) {
249379
+ const security = operation.security ?? spec.security ?? [];
249380
+ return security.some((requirement) => (APP_USER_TOKEN_SCHEME in requirement));
249381
+ }
249362
249382
  function parameterText(operation) {
249363
249383
  return (operation.parameters ?? []).flatMap((parameter) => {
249364
249384
  const parsed = ParameterSchema.safeParse(parameter);
@@ -249410,6 +249430,7 @@ function listOperations(spec) {
249410
249430
  description: cleanText(operation.description ?? ""),
249411
249431
  parameterText: parameterText(operation),
249412
249432
  readOnly: isReadOnly(operation, spec),
249433
+ appUserToken: takesAppUserToken(operation, spec),
249413
249434
  operation
249414
249435
  }
249415
249436
  ];
@@ -249438,6 +249459,10 @@ function matchOperation(operations, method, concretePath) {
249438
249459
  });
249439
249460
  return candidates.sort((a, b) => literalSegments(b.path).localeCompare(literalSegments(a.path)))[0];
249440
249461
  }
249462
+ function pathParameter(op, concretePath, name) {
249463
+ const index = pathSegments(op.path).indexOf(`{${name}}`);
249464
+ return index < 0 ? undefined : pathSegments(concretePath)[index];
249465
+ }
249441
249466
 
249442
249467
  // src/core/api-spec/contract.ts
249443
249468
  var SCHEMA_REF_PREFIX = "#/components/schemas/";
@@ -249578,59 +249603,6 @@ function grepOperations(spec, operations, pattern, options = {}) {
249578
249603
  const regex = new RegExp(pattern, options.ignoreCase ? "i" : "");
249579
249604
  return operations.filter((op) => regex.test(JSON.stringify(getOperationContract(spec, op)))).slice(0, options.limit ?? 20).map(toOperationSummary);
249580
249605
  }
249581
- // src/core/api-spec/request.ts
249582
- var MAX_ERROR_BODY_CHARS = 4000;
249583
- var QUERY_STRING = /\?\S*/g;
249584
- async function readBody(response) {
249585
- try {
249586
- const text = (await response.clone().text()).trim();
249587
- return text.length > MAX_ERROR_BODY_CHARS ? `${text.slice(0, MAX_ERROR_BODY_CHARS)}…` : text || undefined;
249588
- } catch {
249589
- return;
249590
- }
249591
- }
249592
- function normalizePath(path) {
249593
- const url = new URL(path.replace(/^\/*/, "/"), "http://placeholder");
249594
- return `${url.pathname}${url.search}`;
249595
- }
249596
- async function sendApiRequest(method, path, body) {
249597
- try {
249598
- const response = await base44Client(path.replace(/^\/+/, ""), {
249599
- method,
249600
- body,
249601
- headers: typeof body === "string" ? { "Content-Type": "application/json" } : {},
249602
- timeout: false,
249603
- retry: { methods: ["get", "head"] }
249604
- });
249605
- return {
249606
- status: response.status,
249607
- contentType: response.headers.get("content-type") ?? "",
249608
- body: new Uint8Array(await response.arrayBuffer())
249609
- };
249610
- } catch (error) {
249611
- const apiError = await ApiError.fromHttpError(error, `calling ${method} ${path}`);
249612
- const response = error instanceof HTTPError ? error.response : undefined;
249613
- const raw = response ? await readBody(response) : undefined;
249614
- const retryAfter = response?.headers.get("retry-after") ?? undefined;
249615
- throw redactedApiError(apiError, raw, method, path, retryAfter);
249616
- }
249617
- }
249618
- function redactedApiError(apiError, raw, method, path, retryAfter) {
249619
- const wait = retryAfter ? ` (retry after ${/^\d+$/.test(retryAfter) ? `${retryAfter} s` : retryAfter})` : "";
249620
- const reason = apiError.statusCode !== undefined ? `HTTP ${apiError.statusCode}${wait}` : (apiError.cause?.message ?? "request failed").replace(QUERY_STRING, "");
249621
- const message = `Error calling ${method} ${path.split("?", 1)[0]}: ${reason}`;
249622
- return new ApiError(message, {
249623
- statusCode: apiError.statusCode,
249624
- requestUrl: apiError.requestUrl?.split("?", 1)[0],
249625
- requestMethod: apiError.requestMethod,
249626
- requestId: apiError.requestId,
249627
- hints: apiError.hints,
249628
- details: [
249629
- ...raw ? [`Response body: ${raw}`] : apiError.details ?? [],
249630
- ...apiError.requestId ? [`Request ID: ${apiError.requestId}`] : []
249631
- ]
249632
- });
249633
- }
249634
249606
  // src/core/api-spec/spec.ts
249635
249607
  import { rename, rm, stat as stat3 } from "node:fs/promises";
249636
249608
  import { join as join22 } from "node:path";
@@ -249697,6 +249669,71 @@ async function loadSpec(options = {}) {
249697
249669
  }
249698
249670
  return { text, spec };
249699
249671
  }
249672
+
249673
+ // src/core/api-spec/request.ts
249674
+ var MAX_ERROR_BODY_CHARS = 4000;
249675
+ var QUERY_STRING = /\?\S*/g;
249676
+ async function readBody(response) {
249677
+ try {
249678
+ const text = (await response.clone().text()).trim();
249679
+ return text.length > MAX_ERROR_BODY_CHARS ? `${text.slice(0, MAX_ERROR_BODY_CHARS)}…` : text || undefined;
249680
+ } catch {
249681
+ return;
249682
+ }
249683
+ }
249684
+ function normalizePath(path) {
249685
+ const url = new URL(path.replace(/^\/*/, "/"), "http://placeholder");
249686
+ return `${url.pathname}${url.search}`;
249687
+ }
249688
+ var APP_PATH = /^\/api\/apps\/[^/?#]+\//;
249689
+ async function appUserTokenFor(method, path, options = {}) {
249690
+ if (hasWorkspaceApiKeyAuth() || !APP_PATH.test(path)) {
249691
+ return;
249692
+ }
249693
+ const loaded = await loadSpec(options).catch(() => null);
249694
+ const op = loaded ? matchOperation(listOperations(loaded.spec), method, path) : undefined;
249695
+ const appId = op?.appUserToken ? pathParameter(op, path, "app_id") : undefined;
249696
+ return appId ? getAppUserToken(appId) : undefined;
249697
+ }
249698
+ async function sendApiRequest(method, path, body, appUserToken) {
249699
+ const client = appUserToken ? getAppUserClient(appUserToken) : base44Client;
249700
+ try {
249701
+ const response = await client(path.replace(/^\/+/, ""), {
249702
+ method,
249703
+ body,
249704
+ headers: typeof body === "string" ? { "Content-Type": "application/json" } : {},
249705
+ timeout: false,
249706
+ retry: { methods: ["get", "head"] }
249707
+ });
249708
+ return {
249709
+ status: response.status,
249710
+ contentType: response.headers.get("content-type") ?? "",
249711
+ body: new Uint8Array(await response.arrayBuffer())
249712
+ };
249713
+ } catch (error) {
249714
+ const apiError = await ApiError.fromHttpError(error, `calling ${method} ${path}`);
249715
+ const response = error instanceof HTTPError ? error.response : undefined;
249716
+ const raw = response ? await readBody(response) : undefined;
249717
+ const retryAfter = response?.headers.get("retry-after") ?? undefined;
249718
+ throw redactedApiError(apiError, raw, method, path, retryAfter);
249719
+ }
249720
+ }
249721
+ function redactedApiError(apiError, raw, method, path, retryAfter) {
249722
+ const wait = retryAfter ? ` (retry after ${/^\d+$/.test(retryAfter) ? `${retryAfter} s` : retryAfter})` : "";
249723
+ const reason = apiError.statusCode !== undefined ? `HTTP ${apiError.statusCode}${wait}` : (apiError.cause?.message ?? "request failed").replace(QUERY_STRING, "");
249724
+ const message = `Error calling ${method} ${path.split("?", 1)[0]}: ${reason}`;
249725
+ return new ApiError(message, {
249726
+ statusCode: apiError.statusCode,
249727
+ requestUrl: apiError.requestUrl?.split("?", 1)[0],
249728
+ requestMethod: apiError.requestMethod,
249729
+ requestId: apiError.requestId,
249730
+ hints: apiError.hints,
249731
+ details: [
249732
+ ...raw ? [`Response body: ${raw}`] : apiError.details ?? [],
249733
+ ...apiError.requestId ? [`Request ID: ${apiError.requestId}`] : []
249734
+ ]
249735
+ });
249736
+ }
249700
249737
  // src/cli/commands/api/shared.ts
249701
249738
  import { basename as basename6 } from "node:path";
249702
249739
  function formatJson(value) {
@@ -249916,7 +249953,12 @@ ${CONTRACT_HELP}
249916
249953
  }
249917
249954
  await ensureAuth(ctx);
249918
249955
  const body = options.form.length > 0 ? await readFormBody(options.form) : await readRequestBody(options.body);
249919
- const response = await ctx.runTask(`Calling ${method} ${target}`, () => sendApiRequest(method, target, body), {
249956
+ const response = await ctx.runTask(`Calling ${method} ${target}`, async () => {
249957
+ const appUserToken = await appUserTokenFor(method, target, {
249958
+ refresh: options.refresh && !options.readOnly
249959
+ });
249960
+ return sendApiRequest(method, target, body, appUserToken);
249961
+ }, {
249920
249962
  successMessage: `Called ${method} ${target}`,
249921
249963
  errorMessage: "Request failed"
249922
249964
  });
@@ -251362,7 +251404,7 @@ async function pushConnectorsAction({ isNonInteractive, log, runTask, jsonMode }
251362
251404
  const connectors = await readConnectorsToPush(options);
251363
251405
  if (!jsonMode) {
251364
251406
  if (connectors.length === 0) {
251365
- log.info("No local connectors found - nothing to push");
251407
+ log.info("No local connectors found - checking for remote connectors to remove");
251366
251408
  } else {
251367
251409
  const connectorNames = connectors.map((c) => c.type).join(", ");
251368
251410
  log.info(`Found ${connectors.length} connectors to push: ${connectorNames}`);
@@ -274983,4 +275025,4 @@ export {
274983
275025
  runCLI
274984
275026
  };
274985
275027
 
274986
- //# debugId=286ECC3B93B7320F64756E2164756E21
275028
+ //# debugId=337CE6C02AFECBB564756E2164756E21