@base44-preview/cli 0.2.7-pr.687.f53a85d → 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");
@@ -238253,19 +238253,21 @@ async function pullAllConnectors() {
238253
238253
  return connectors;
238254
238254
  }
238255
238255
  // src/core/resources/connector/push.ts
238256
- async function pushConnectors(connectors, { prune = true } = {}) {
238256
+ async function pushConnectors(connectors) {
238257
238257
  const stripeConnector = connectors.find((c) => c.type === STRIPE_CONNECTOR_TYPE);
238258
238258
  const oauthConnectors = connectors.filter((c) => c.type !== STRIPE_CONNECTOR_TYPE);
238259
- const oauthResults = await syncOAuthConnectors(oauthConnectors, prune);
238260
- const stripeResult = stripeConnector || prune ? await syncStripeConnector(stripeConnector) : null;
238259
+ const oauthResults = await syncOAuthConnectors(oauthConnectors);
238260
+ const stripeResult = await syncStripeConnector(stripeConnector);
238261
238261
  const results = [...oauthResults];
238262
238262
  if (stripeResult) {
238263
238263
  results.push(stripeResult);
238264
238264
  }
238265
238265
  return { results };
238266
238266
  }
238267
- async function syncOAuthConnectors(connectors, prune) {
238267
+ async function syncOAuthConnectors(connectors) {
238268
238268
  const results = [];
238269
+ const upstream = await listConnectors();
238270
+ const localTypes = new Set(connectors.map((c) => c.type));
238269
238271
  for (const connector of connectors) {
238270
238272
  try {
238271
238273
  const response = await setConnector(connector.type, connector.scopes ?? []);
@@ -238278,11 +238280,6 @@ async function syncOAuthConnectors(connectors, prune) {
238278
238280
  });
238279
238281
  }
238280
238282
  }
238281
- if (!prune) {
238282
- return results;
238283
- }
238284
- const upstream = await listConnectors();
238285
- const localTypes = new Set(connectors.map((c) => c.type));
238286
238283
  for (const upstreamConnector of upstream.integrations) {
238287
238284
  if (!localTypes.has(upstreamConnector.integrationType)) {
238288
238285
  try {
@@ -246982,9 +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, {
246986
- prune: false
246987
- });
246982
+ const skipConnectorSync = connectors.length === 0 && hasWorkspaceApiKeyAuth();
246983
+ const connectorResults = skipConnectorSync ? [] : (await pushConnectors(connectors)).results;
246988
246984
  const appUrl = await deployProjectSite(project, options);
246989
246985
  return appUrl ? { appUrl, connectorResults } : { connectorResults };
246990
246986
  }
@@ -247124,6 +247120,23 @@ var base44Client = distribution_default.create({
247124
247120
  afterResponse: [handleUnauthorized]
247125
247121
  }
247126
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
+ }
247127
247140
  function getAppClient() {
247128
247141
  const { id } = getAppContext();
247129
247142
  return base44Client.extend({
@@ -249357,10 +249370,15 @@ function cleanText(text) {
249357
249370
  // src/core/api-spec/operations.ts
249358
249371
  var PERSONAL_ACCESS_TOKEN_SCHEME = "PersonalAccessTokenAuth";
249359
249372
  var READ_ONLY_SCOPE = "read_only";
249373
+ var APP_USER_TOKEN_SCHEME = "AppUserTokenAuth";
249360
249374
  function isReadOnly(operation, spec) {
249361
249375
  const security = operation.security ?? spec.security ?? [];
249362
249376
  return security.some((requirement) => requirement[PERSONAL_ACCESS_TOKEN_SCHEME]?.includes(READ_ONLY_SCOPE));
249363
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
+ }
249364
249382
  function parameterText(operation) {
249365
249383
  return (operation.parameters ?? []).flatMap((parameter) => {
249366
249384
  const parsed = ParameterSchema.safeParse(parameter);
@@ -249412,6 +249430,7 @@ function listOperations(spec) {
249412
249430
  description: cleanText(operation.description ?? ""),
249413
249431
  parameterText: parameterText(operation),
249414
249432
  readOnly: isReadOnly(operation, spec),
249433
+ appUserToken: takesAppUserToken(operation, spec),
249415
249434
  operation
249416
249435
  }
249417
249436
  ];
@@ -249440,6 +249459,10 @@ function matchOperation(operations, method, concretePath) {
249440
249459
  });
249441
249460
  return candidates.sort((a, b) => literalSegments(b.path).localeCompare(literalSegments(a.path)))[0];
249442
249461
  }
249462
+ function pathParameter(op, concretePath, name) {
249463
+ const index = pathSegments(op.path).indexOf(`{${name}}`);
249464
+ return index < 0 ? undefined : pathSegments(concretePath)[index];
249465
+ }
249443
249466
 
249444
249467
  // src/core/api-spec/contract.ts
249445
249468
  var SCHEMA_REF_PREFIX = "#/components/schemas/";
@@ -249580,59 +249603,6 @@ function grepOperations(spec, operations, pattern, options = {}) {
249580
249603
  const regex = new RegExp(pattern, options.ignoreCase ? "i" : "");
249581
249604
  return operations.filter((op) => regex.test(JSON.stringify(getOperationContract(spec, op)))).slice(0, options.limit ?? 20).map(toOperationSummary);
249582
249605
  }
249583
- // src/core/api-spec/request.ts
249584
- var MAX_ERROR_BODY_CHARS = 4000;
249585
- var QUERY_STRING = /\?\S*/g;
249586
- async function readBody(response) {
249587
- try {
249588
- const text = (await response.clone().text()).trim();
249589
- return text.length > MAX_ERROR_BODY_CHARS ? `${text.slice(0, MAX_ERROR_BODY_CHARS)}…` : text || undefined;
249590
- } catch {
249591
- return;
249592
- }
249593
- }
249594
- function normalizePath(path) {
249595
- const url = new URL(path.replace(/^\/*/, "/"), "http://placeholder");
249596
- return `${url.pathname}${url.search}`;
249597
- }
249598
- async function sendApiRequest(method, path, body) {
249599
- try {
249600
- const response = await base44Client(path.replace(/^\/+/, ""), {
249601
- method,
249602
- body,
249603
- headers: typeof body === "string" ? { "Content-Type": "application/json" } : {},
249604
- timeout: false,
249605
- retry: { methods: ["get", "head"] }
249606
- });
249607
- return {
249608
- status: response.status,
249609
- contentType: response.headers.get("content-type") ?? "",
249610
- body: new Uint8Array(await response.arrayBuffer())
249611
- };
249612
- } catch (error) {
249613
- const apiError = await ApiError.fromHttpError(error, `calling ${method} ${path}`);
249614
- const response = error instanceof HTTPError ? error.response : undefined;
249615
- const raw = response ? await readBody(response) : undefined;
249616
- const retryAfter = response?.headers.get("retry-after") ?? undefined;
249617
- throw redactedApiError(apiError, raw, method, path, retryAfter);
249618
- }
249619
- }
249620
- function redactedApiError(apiError, raw, method, path, retryAfter) {
249621
- const wait = retryAfter ? ` (retry after ${/^\d+$/.test(retryAfter) ? `${retryAfter} s` : retryAfter})` : "";
249622
- const reason = apiError.statusCode !== undefined ? `HTTP ${apiError.statusCode}${wait}` : (apiError.cause?.message ?? "request failed").replace(QUERY_STRING, "");
249623
- const message = `Error calling ${method} ${path.split("?", 1)[0]}: ${reason}`;
249624
- return new ApiError(message, {
249625
- statusCode: apiError.statusCode,
249626
- requestUrl: apiError.requestUrl?.split("?", 1)[0],
249627
- requestMethod: apiError.requestMethod,
249628
- requestId: apiError.requestId,
249629
- hints: apiError.hints,
249630
- details: [
249631
- ...raw ? [`Response body: ${raw}`] : apiError.details ?? [],
249632
- ...apiError.requestId ? [`Request ID: ${apiError.requestId}`] : []
249633
- ]
249634
- });
249635
- }
249636
249606
  // src/core/api-spec/spec.ts
249637
249607
  import { rename, rm, stat as stat3 } from "node:fs/promises";
249638
249608
  import { join as join22 } from "node:path";
@@ -249699,6 +249669,71 @@ async function loadSpec(options = {}) {
249699
249669
  }
249700
249670
  return { text, spec };
249701
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
+ }
249702
249737
  // src/cli/commands/api/shared.ts
249703
249738
  import { basename as basename6 } from "node:path";
249704
249739
  function formatJson(value) {
@@ -249918,7 +249953,12 @@ ${CONTRACT_HELP}
249918
249953
  }
249919
249954
  await ensureAuth(ctx);
249920
249955
  const body = options.form.length > 0 ? await readFormBody(options.form) : await readRequestBody(options.body);
249921
- 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
+ }, {
249922
249962
  successMessage: `Called ${method} ${target}`,
249923
249963
  errorMessage: "Request failed"
249924
249964
  });
@@ -252118,10 +252158,6 @@ ${summaryLines.join(`
252118
252158
  if (stripeResult?.action === "provisioned") {
252119
252159
  printStripeResult(stripeResult, log);
252120
252160
  }
252121
- for (const r of connectorResults) {
252122
- if (r.action === "error")
252123
- log.error(`Failed: ${r.type} - ${r.error}`);
252124
- }
252125
252161
  log.message(`${theme.styles.header("Dashboard")}: ${theme.colors.links(getDashboardUrl())}`);
252126
252162
  if (result.appUrl) {
252127
252163
  log.message(`${theme.styles.header("App URL")}: ${theme.colors.links(result.appUrl)}`);
@@ -274989,4 +275025,4 @@ export {
274989
275025
  runCLI
274990
275026
  };
274991
275027
 
274992
- //# debugId=4C75853E117A86FD64756E2164756E21
275028
+ //# debugId=337CE6C02AFECBB564756E2164756E21