appwrite-cli 22.2.2 → 22.4.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.
package/dist/index.js CHANGED
@@ -35934,7 +35934,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
35934
35934
  }
35935
35935
  return positiveOption || option2;
35936
35936
  };
35937
- const getErrorMessage2 = (option2) => {
35937
+ const getErrorMessage3 = (option2) => {
35938
35938
  const bestOption = findBestOptionFromValue(option2);
35939
35939
  const optionKey = bestOption.attributeName();
35940
35940
  const source = this.getOptionValueSource(optionKey);
@@ -35943,7 +35943,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
35943
35943
  }
35944
35944
  return `option '${bestOption.flags}'`;
35945
35945
  };
35946
- const message = `error: ${getErrorMessage2(option)} cannot be used with ${getErrorMessage2(conflictingOption)}`;
35946
+ const message = `error: ${getErrorMessage3(option)} cannot be used with ${getErrorMessage3(conflictingOption)}`;
35947
35947
  this.error(message, { code: "commander.conflictingOption" });
35948
35948
  }
35949
35949
  /**
@@ -65545,7 +65545,7 @@ var id_default = ID;
65545
65545
  // lib/constants.ts
65546
65546
  var SDK_TITLE = "Appwrite";
65547
65547
  var SDK_TITLE_LOWER = "appwrite";
65548
- var SDK_VERSION = "22.2.2";
65548
+ var SDK_VERSION = "22.4.0";
65549
65549
  var SDK_LOGO = "\n _ _ _ ___ __ _____\n /_\\ _ __ _ ____ ___ __(_) |_ ___ / __\\ / / \\_ \\\n //_\\\\| '_ \\| '_ \\ \\ /\\ / / '__| | __/ _ \\ / / / / / /\\/\n / _ \\ |_) | |_) \\ V V /| | | | || __/ / /___/ /___/\\/ /_\n \\_/ \\_/ .__/| .__/ \\_/\\_/ |_| |_|\\__\\___| \\____/\\____/\\____/\n |_| |_|\n\n";
65550
65550
  var EXECUTABLE_NAME = "appwrite";
65551
65551
  var UPDATE_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
@@ -80284,9 +80284,9 @@ var SettingsSchema = external_exports.object({
80284
80284
  }).strict().optional(),
80285
80285
  security: external_exports.object({
80286
80286
  duration: external_exports.union([external_exports.number(), external_exports.bigint()]).optional(),
80287
- limit: external_exports.union([external_exports.number(), external_exports.bigint()]).optional(),
80288
- sessionsLimit: external_exports.union([external_exports.number(), external_exports.bigint()]).optional(),
80289
- passwordHistory: external_exports.union([external_exports.number(), external_exports.bigint()]).optional(),
80287
+ limit: external_exports.union([external_exports.number(), external_exports.bigint()]).nullable().optional(),
80288
+ sessionsLimit: external_exports.union([external_exports.number(), external_exports.bigint()]).nullable().optional(),
80289
+ passwordHistory: external_exports.union([external_exports.number(), external_exports.bigint()]).nullable().optional(),
80290
80290
  passwordDictionary: external_exports.boolean().optional(),
80291
80291
  personalDataCheck: external_exports.boolean().optional(),
80292
80292
  sessionAlerts: external_exports.boolean().optional(),
@@ -103629,7 +103629,10 @@ var createSettingsObject = (project, policies, mockNumbers) => {
103629
103629
  }
103630
103630
  const policyTotal = (id) => {
103631
103631
  const policy = policyById.get(id);
103632
- return policy && "total" in policy ? policy.total : void 0;
103632
+ if (!policy || !("total" in policy)) {
103633
+ return void 0;
103634
+ }
103635
+ return policy.total === 0 ? null : policy.total;
103633
103636
  };
103634
103637
  const policyEnabled = (id) => {
103635
103638
  const policy = policyById.get(id);
@@ -103695,8 +103698,23 @@ var getSafeDirectoryName = (value, fallback) => {
103695
103698
  var siteRequiresBuildCommand = (site) => {
103696
103699
  return !(site.framework === "other" && site.adapter === "static");
103697
103700
  };
103701
+ var getErrorMessage = (error52) => {
103702
+ if (error52 instanceof Error) {
103703
+ const message = typeof error52.message === "string" ? error52.message.trim() : "";
103704
+ if (message) {
103705
+ return message;
103706
+ }
103707
+ const response = error52.response;
103708
+ if (typeof response === "string" && response.trim() !== "") {
103709
+ return response.trim();
103710
+ }
103711
+ return "An unknown error occurred.";
103712
+ }
103713
+ return String(error52);
103714
+ };
103698
103715
  var WINDOWS_EXECUTABLE_NAME = `${EXECUTABLE_NAME.toLowerCase()}.exe`;
103699
103716
  var CLOUD_REGION_CODES = /* @__PURE__ */ new Set(["fra", "nyc", "syd", "sfo", "sgp", "tor"]);
103717
+ var CLOUD_LOGIN_ENVIRONMENTS = /* @__PURE__ */ new Set(["stage"]);
103700
103718
  var isCloudHostname = (hostname3) => {
103701
103719
  if (hostname3 === "cloud.appwrite.io") {
103702
103720
  return true;
@@ -103706,11 +103724,44 @@ var isCloudHostname = (hostname3) => {
103706
103724
  }
103707
103725
  return CLOUD_REGION_CODES.has(hostname3.split(".")[0]);
103708
103726
  };
103727
+ var getCloudEndpointRegion = (endpoint) => {
103728
+ try {
103729
+ const hostname3 = new URL(endpoint).hostname;
103730
+ if (!isCloudHostname(hostname3) || hostname3 === "cloud.appwrite.io") {
103731
+ return null;
103732
+ }
103733
+ const region = hostname3.split(".")[0];
103734
+ return CLOUD_REGION_CODES.has(region) ? region : null;
103735
+ } catch (_error) {
103736
+ return null;
103737
+ }
103738
+ };
103739
+ var getCloudConsoleHostname = (hostname3) => {
103740
+ if (hostname3 === "cloud.appwrite.io") {
103741
+ return hostname3;
103742
+ }
103743
+ const labels = hostname3.split(".");
103744
+ if (labels.length < 4 || labels.slice(-3).join(".") !== "cloud.appwrite.io") {
103745
+ return null;
103746
+ }
103747
+ if (CLOUD_REGION_CODES.has(labels[0])) {
103748
+ const environment = labels[1];
103749
+ if (environment && CLOUD_LOGIN_ENVIRONMENTS.has(environment)) {
103750
+ return `${environment}.cloud.appwrite.io`;
103751
+ }
103752
+ return "cloud.appwrite.io";
103753
+ }
103754
+ if (CLOUD_LOGIN_ENVIRONMENTS.has(labels[0])) {
103755
+ return hostname3;
103756
+ }
103757
+ return null;
103758
+ };
103709
103759
  var getConsoleBaseUrl = (endpoint) => {
103710
103760
  try {
103711
103761
  const url2 = new URL(endpoint);
103712
- if (isCloudHostname(url2.hostname)) {
103713
- url2.hostname = "cloud.appwrite.io";
103762
+ const consoleHostname = getCloudConsoleHostname(url2.hostname);
103763
+ if (consoleHostname) {
103764
+ url2.hostname = consoleHostname;
103714
103765
  }
103715
103766
  url2.pathname = url2.pathname.replace(/\/v1\/?$/, "");
103716
103767
  url2.search = "";
@@ -104196,10 +104247,7 @@ var Config = class {
104196
104247
  }
104197
104248
  _addDBEntity(entityType, props, keysSet, nestedKeys = {}) {
104198
104249
  props = whitelistKeys(props, keysSet, nestedKeys);
104199
- if (!this.has(entityType)) {
104200
- this.set(entityType, []);
104201
- }
104202
- const entities = this.get(entityType);
104250
+ const entities = this.has(entityType) ? [...this.get(entityType) ?? []] : [];
104203
104251
  for (let i = 0; i < entities.length; i++) {
104204
104252
  if (entities[i]["$id"] == props["$id"]) {
104205
104253
  entities[i] = props;
@@ -104891,7 +104939,7 @@ var package_default = {
104891
104939
  type: "module",
104892
104940
  homepage: "https://appwrite.io/support",
104893
104941
  description: "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API",
104894
- version: "22.2.2",
104942
+ version: "22.4.0",
104895
104943
  license: "BSD-3-Clause",
104896
104944
  main: "dist/index.cjs",
104897
104945
  module: "dist/index.js",
@@ -105890,6 +105938,53 @@ var printQueryErrorHint = (err) => {
105890
105938
  `For common list filters, use flags like --limit 25, --sort-desc '$createdAt', or --filter 'status=active'. Raw --queries values must be Appwrite JSON query strings, for example: ${EXECUTABLE_NAME} tables-db list-rows --queries '{"method":"limit","values":[25]}'`
105891
105939
  );
105892
105940
  };
105941
+ var ERROR_DETAIL_KEYS = ["code", "type", "response"];
105942
+ var ERROR_DETAIL_INDENT = " ";
105943
+ var ERROR_DETAIL_LABEL_WIDTH = Math.max(...ERROR_DETAIL_KEYS.map((key) => key.length)) + 2;
105944
+ var formatErrorDetail = (value) => {
105945
+ if (typeof value === "string") {
105946
+ const text = value;
105947
+ try {
105948
+ const parsed = JSON.parse(text);
105949
+ if (parsed && typeof parsed === "object") {
105950
+ value = parsed;
105951
+ }
105952
+ } catch {
105953
+ return text;
105954
+ }
105955
+ }
105956
+ try {
105957
+ const json2 = JSON.stringify(value, null, 2) ?? String(value);
105958
+ return json2.split("\n").map((line, index) => index === 0 ? line : ERROR_DETAIL_INDENT + line).join("\n");
105959
+ } catch {
105960
+ return String(value);
105961
+ }
105962
+ };
105963
+ var formatErrorForLog = (err) => {
105964
+ const lines = [
105965
+ `${import_chalk2.default.red.bold(err.name || "Error")}${import_chalk2.default.red(`: ${getErrorMessage(err)}`)}`
105966
+ ];
105967
+ for (const key of ERROR_DETAIL_KEYS) {
105968
+ if (!Object.prototype.hasOwnProperty.call(err, key)) {
105969
+ continue;
105970
+ }
105971
+ const value = err[key];
105972
+ lines.push(
105973
+ `${ERROR_DETAIL_INDENT}${import_chalk2.default.cyan(`${key}:`.padEnd(ERROR_DETAIL_LABEL_WIDTH))}${formatErrorDetail(value)}`
105974
+ );
105975
+ }
105976
+ const frames = (err.stack ?? "").split("\n").filter((line) => line.trim().startsWith("at "));
105977
+ if (frames.length > 0) {
105978
+ lines.push(
105979
+ "",
105980
+ import_chalk2.default.dim(`${ERROR_DETAIL_INDENT}Stack trace:`),
105981
+ ...frames.map(
105982
+ (frame) => import_chalk2.default.dim(`${ERROR_DETAIL_INDENT.repeat(2)}${frame.trim()}`)
105983
+ )
105984
+ );
105985
+ }
105986
+ return lines.join("\n");
105987
+ };
105893
105988
  var parseError = (err) => {
105894
105989
  if (cliConfig.report) {
105895
105990
  void (async () => {
@@ -105919,7 +106014,7 @@ Is Cloud: ${isCloud()}`;
105919
106014
  githubIssueUrl.searchParams.append("template", "bug.yaml");
105920
106015
  githubIssueUrl.searchParams.append(
105921
106016
  "title",
105922
- `\u{1F41B} Bug Report: ${err.message}`
106017
+ `\u{1F41B} Bug Report: ${getErrorMessage(err)}`
105923
106018
  );
105924
106019
  githubIssueUrl.searchParams.append(
105925
106020
  "actual-behavior",
@@ -105940,16 +106035,16 @@ ${stack}`
105940
106035
  );
105941
106036
  printQueryErrorHint(err);
105942
106037
  error51("\n Stack Trace: \n");
105943
- console.error(err);
106038
+ console.error(formatErrorForLog(err));
105944
106039
  process.exit(1);
105945
106040
  })();
105946
106041
  } else {
105947
106042
  if (cliConfig.verbose) {
105948
- console.error(err);
106043
+ console.error(formatErrorForLog(err));
105949
106044
  printQueryErrorHint(err);
105950
106045
  } else {
105951
106046
  log("For detailed error pass the --verbose or --report flag");
105952
- error51(err.message);
106047
+ error51(getErrorMessage(err));
105953
106048
  printQueryErrorHint(err);
105954
106049
  }
105955
106050
  process.exit(1);
@@ -105995,7 +106090,7 @@ var commandDescriptions = {
105995
106090
  avatars: `The avatars command aims to help you complete everyday tasks related to your app image, icons, and avatars.`,
105996
106091
  databases: `(Legacy) The databases command allows you to create structured collections of documents and query and filter lists of documents.`,
105997
106092
  "tables-db": `The tables-db command allows you to create structured tables of columns and query and filter lists of rows.`,
105998
- init: `The init command provides a convenient wrapper for creating and initializing projects, functions, collections, buckets, teams, messaging-topics, and agent skills in ${SDK_TITLE}.`,
106093
+ init: `The init command provides a convenient wrapper for creating and initializing projects, functions, collections, buckets, teams, messaging-topics, and skills in ${SDK_TITLE}.`,
105999
106094
  push: `The push command provides a convenient wrapper for pushing your functions, collections, buckets, teams, and messaging-topics.`,
106000
106095
  run: `The run command allows you to run the project locally to allow easy development and quick debugging.`,
106001
106096
  functions: `The functions command allows you to view, create, and manage your Cloud Functions.`,
@@ -109581,12 +109676,12 @@ var deleteStoredRefreshToken = (sessionId) => {
109581
109676
  };
109582
109677
 
109583
109678
  // lib/sdks.ts
109584
- var getValidAccessToken = async (endpoint) => {
109679
+ var getValidAccessToken = async (endpoint, options = {}) => {
109585
109680
  const accessToken = globalConfig2.getAccessToken();
109586
109681
  const tokenExpiry = globalConfig2.getTokenExpiry();
109587
109682
  const clientId = globalConfig2.getClientId() || OAUTH2_CLIENT_ID;
109588
109683
  const currentSession = globalConfig2.getCurrentSession();
109589
- if (accessToken && tokenExpiry > Date.now() + 6e4) {
109684
+ if (!options.forceRefresh && accessToken && tokenExpiry > Date.now() + 6e4) {
109590
109685
  return accessToken;
109591
109686
  }
109592
109687
  const refreshToken = currentSession ? getStoredRefreshToken(currentSession) : "";
@@ -110078,7 +110173,7 @@ async function downloadDeploymentCode(params) {
110078
110173
  }
110079
110174
  } catch (e) {
110080
110175
  if (e instanceof AppwriteException) {
110081
- error51(e.message);
110176
+ error51(getErrorMessage(e));
110082
110177
  return;
110083
110178
  } else {
110084
110179
  throw e;
@@ -112001,12 +112096,12 @@ async function getTerminalImage() {
112001
112096
  );
112002
112097
  return terminalImageModulePromise;
112003
112098
  }
112004
- function getErrorMessage(error52) {
112099
+ function getErrorMessage2(error52) {
112005
112100
  if (error52 instanceof Error && error52.message.trim().length > 0) {
112006
112101
  return error52.message.trim();
112007
112102
  }
112008
112103
  if (Array.isArray(error52)) {
112009
- const messages = error52.map((entry) => getErrorMessage(entry)).filter((entry) => entry !== "Unknown error");
112104
+ const messages = error52.map((entry) => getErrorMessage2(entry)).filter((entry) => entry !== "Unknown error");
112010
112105
  if (messages.length > 0) {
112011
112106
  return messages.join("; ");
112012
112107
  }
@@ -112164,7 +112259,7 @@ async function renderSiteTerminalPreview(params) {
112164
112259
  };
112165
112260
  } catch (previewError) {
112166
112261
  warnings.add(
112167
- `${label === "dark" ? "Dark mode" : "Light mode"} screenshot: ${getErrorMessage(previewError)}`
112262
+ `${label === "dark" ? "Dark mode" : "Light mode"} screenshot: ${getErrorMessage2(previewError)}`
112168
112263
  );
112169
112264
  }
112170
112265
  }
@@ -112266,6 +112361,44 @@ function createDeploymentLogsController(enabled) {
112266
112361
  close: cleanup
112267
112362
  };
112268
112363
  }
112364
+ var getPushErrorMessage = (error52) => {
112365
+ if (error52 instanceof Error) {
112366
+ return error52.message;
112367
+ }
112368
+ if (typeof error52 === "object" && error52 !== null && "message" in error52 && typeof error52.message === "string") {
112369
+ return error52.message;
112370
+ }
112371
+ return String(error52);
112372
+ };
112373
+ var getPushResultErrors = (result) => {
112374
+ if (typeof result !== "object" || result === null) {
112375
+ return [];
112376
+ }
112377
+ if ("errors" in result && Array.isArray(result.errors) && result.errors.length > 0) {
112378
+ return result.errors.map(getPushErrorMessage).filter((message) => message.trim() !== "");
112379
+ }
112380
+ if ("error" in result && typeof result.error === "string" && result.error.trim() !== "") {
112381
+ return [result.error];
112382
+ }
112383
+ return [];
112384
+ };
112385
+ var formatPushResourceErrors = (results) => {
112386
+ const failed = Object.entries(results).map(([resourceGroup, result]) => ({
112387
+ resourceGroup,
112388
+ messages: getPushResultErrors(result)
112389
+ })).filter(({ messages }) => messages.length > 0);
112390
+ if (failed.length === 0) {
112391
+ return "Failed to push resource groups.";
112392
+ }
112393
+ return [
112394
+ `Failed to push ${failed.length} resource group${failed.length === 1 ? "" : "s"}:`,
112395
+ ...failed.flatMap(({ resourceGroup, messages }) => [
112396
+ `- ${resourceGroup}:`,
112397
+ ...messages.map((message) => ` - ${message}`)
112398
+ ])
112399
+ ].join("\n");
112400
+ };
112401
+ var nullablePolicyTotal = (value) => value === null || Number(value) === 0 ? null : Number(value);
112269
112402
  var normalizeIgnoreRules = (value) => {
112270
112403
  if (Array.isArray(value)) {
112271
112404
  return value.filter(
@@ -112311,6 +112444,53 @@ var Push = class {
112311
112444
  warn(message);
112312
112445
  }
112313
112446
  }
112447
+ getFunctionRuleDomain(domain2) {
112448
+ const region = getCloudEndpointRegion(this.projectClient.config.endpoint);
112449
+ if (!region) {
112450
+ return domain2;
112451
+ }
112452
+ const parts = domain2.split(".");
112453
+ if (parts.length < 3) {
112454
+ return domain2;
112455
+ }
112456
+ parts[0] = region;
112457
+ return parts.join(".");
112458
+ }
112459
+ async createDefaultFunctionRule(functionId) {
112460
+ let domain2 = "";
112461
+ try {
112462
+ const consoleService = await getConsoleService(this.consoleClient);
112463
+ const variables = await consoleService.variables();
112464
+ const domains = variables["_APP_DOMAIN_FUNCTIONS"].split(",").map((value) => value.trim()).filter((value) => value.length > 0);
112465
+ if (domains.length === 0) {
112466
+ throw new Error("_APP_DOMAIN_FUNCTIONS is not configured.");
112467
+ }
112468
+ domain2 = id_default.unique() + "." + this.getFunctionRuleDomain(domains[0]);
112469
+ } catch (err) {
112470
+ this.error("Error fetching console variables.");
112471
+ throw err;
112472
+ }
112473
+ try {
112474
+ const proxyService = await getProxyService(this.projectClient);
112475
+ this.log(`Creating function proxy rule for ${domain2} ...`);
112476
+ await proxyService.createFunctionRule(domain2, functionId);
112477
+ } catch (err) {
112478
+ this.error("Error creating function rule.");
112479
+ throw err;
112480
+ }
112481
+ }
112482
+ async hasDefaultFunctionRule(functionId) {
112483
+ const proxyService = await getProxyService(this.projectClient);
112484
+ const { rules } = await proxyService.listRules({
112485
+ queries: [
112486
+ Query.limit(1),
112487
+ Query.equal("deploymentResourceType", "function"),
112488
+ Query.equal("deploymentResourceId", functionId),
112489
+ Query.equal("trigger", "manual")
112490
+ ]
112491
+ });
112492
+ return rules.length > 0;
112493
+ }
112314
112494
  /**
112315
112495
  * Log an error message (respects silent mode)
112316
112496
  */
@@ -112374,7 +112554,11 @@ var Push = class {
112374
112554
  results.settings = { success: true };
112375
112555
  } catch (e) {
112376
112556
  allErrors.push(e);
112377
- results.settings = { success: false, error: e.message };
112557
+ results.settings = {
112558
+ success: false,
112559
+ error: getPushErrorMessage(e),
112560
+ errors: [e]
112561
+ };
112378
112562
  }
112379
112563
  }
112380
112564
  if ((shouldPushAll || options.buckets) && config2.buckets && config2.buckets.length > 0) {
@@ -112457,10 +112641,28 @@ var Push = class {
112457
112641
  }
112458
112642
  if ((shouldPushAll || options.sites) && config2.sites && config2.sites.length > 0) {
112459
112643
  try {
112644
+ let siteOptions = options.siteOptions;
112645
+ if (siteOptions?.code === void 0) {
112646
+ let allowSitesCodePush = cliConfig.force === true ? true : null;
112647
+ if (allowSitesCodePush === null) {
112648
+ const codeAnswer = await import_inquirer3.default.prompt(questionsPushSitesCode);
112649
+ allowSitesCodePush = codeAnswer.override;
112650
+ }
112651
+ siteOptions = {
112652
+ ...siteOptions,
112653
+ code: allowSitesCodePush === true
112654
+ };
112655
+ }
112656
+ if (siteOptions.code === true && siteOptions.activate === void 0) {
112657
+ siteOptions = {
112658
+ ...siteOptions,
112659
+ activate: cliConfig.force === true ? true : (await import_inquirer3.default.prompt(questionsPushSitesActivate)).activate
112660
+ };
112661
+ }
112460
112662
  this.log("Pushing sites ...");
112461
112663
  const result = await this.pushSites(
112462
112664
  config2.sites,
112463
- options.siteOptions
112665
+ siteOptions
112464
112666
  );
112465
112667
  this.success(
112466
112668
  `Successfully pushed ${import_chalk9.default.bold(result.successfullyPushed)} sites.`
@@ -112479,6 +112681,12 @@ var Push = class {
112479
112681
  }
112480
112682
  if ((shouldPushAll || options.tables) && config2.tables && config2.tables.length > 0) {
112481
112683
  try {
112684
+ const { resyncNeeded } = await checkAndApplyTablesDBChanges();
112685
+ if (resyncNeeded) {
112686
+ throw new Error(
112687
+ "Configuration changed after applying tablesDB deletions. Re-run the push command to continue."
112688
+ );
112689
+ }
112482
112690
  this.log("Pushing tables ...");
112483
112691
  const result = await this.pushTables(config2.tables, {
112484
112692
  attempts: options.tableOptions?.attempts,
@@ -112550,46 +112758,80 @@ var Push = class {
112550
112758
  }
112551
112759
  if (settings.services) {
112552
112760
  this.log("Applying service statuses ...");
112553
- for (const [service, status] of Object.entries(settings.services)) {
112554
- await projectService.updateService({
112555
- serviceId: service,
112556
- enabled: status
112557
- });
112558
- }
112761
+ await Promise.all(
112762
+ Object.entries(settings.services).map(
112763
+ ([service, status]) => projectService.updateService({
112764
+ serviceId: service,
112765
+ enabled: status
112766
+ })
112767
+ )
112768
+ );
112559
112769
  }
112560
112770
  if (settings.protocols) {
112561
112771
  this.log("Applying protocol statuses ...");
112562
- for (const [protocol, status] of Object.entries(settings.protocols)) {
112563
- await projectService.updateProtocol({
112564
- protocolId: protocol,
112565
- enabled: status
112566
- });
112567
- }
112772
+ await Promise.all(
112773
+ Object.entries(settings.protocols).map(
112774
+ ([protocol, status]) => projectService.updateProtocol({
112775
+ protocolId: protocol,
112776
+ enabled: status
112777
+ })
112778
+ )
112779
+ );
112568
112780
  }
112569
112781
  if (settings.auth) {
112570
112782
  if (settings.auth.security) {
112571
112783
  this.log("Applying auth security settings ...");
112572
- await projectService.updateSessionDurationPolicy({
112573
- duration: Number(settings.auth.security.duration)
112574
- });
112575
- await projectService.updateUserLimitPolicy({
112576
- total: Number(settings.auth.security.limit)
112577
- });
112578
- await projectService.updateSessionLimitPolicy({
112579
- total: Number(settings.auth.security.sessionsLimit)
112580
- });
112581
- await projectService.updatePasswordDictionaryPolicy({
112582
- enabled: settings.auth.security.passwordDictionary
112583
- });
112584
- await projectService.updatePasswordHistoryPolicy({
112585
- total: Number(settings.auth.security.passwordHistory)
112586
- });
112587
- await projectService.updatePasswordPersonalDataPolicy({
112588
- enabled: settings.auth.security.personalDataCheck
112589
- });
112590
- await projectService.updateSessionAlertPolicy({
112591
- enabled: settings.auth.security.sessionAlerts
112592
- });
112784
+ const securityUpdates = [];
112785
+ if (settings.auth.security.duration !== void 0) {
112786
+ securityUpdates.push(
112787
+ projectService.updateSessionDurationPolicy({
112788
+ duration: Number(settings.auth.security.duration)
112789
+ })
112790
+ );
112791
+ }
112792
+ if (settings.auth.security.limit !== void 0) {
112793
+ securityUpdates.push(
112794
+ projectService.updateUserLimitPolicy({
112795
+ total: nullablePolicyTotal(settings.auth.security.limit)
112796
+ })
112797
+ );
112798
+ }
112799
+ if (settings.auth.security.sessionsLimit !== void 0) {
112800
+ securityUpdates.push(
112801
+ projectService.updateSessionLimitPolicy({
112802
+ total: nullablePolicyTotal(settings.auth.security.sessionsLimit)
112803
+ })
112804
+ );
112805
+ }
112806
+ if (settings.auth.security.passwordDictionary !== void 0) {
112807
+ securityUpdates.push(
112808
+ projectService.updatePasswordDictionaryPolicy({
112809
+ enabled: settings.auth.security.passwordDictionary
112810
+ })
112811
+ );
112812
+ }
112813
+ if (settings.auth.security.passwordHistory !== void 0) {
112814
+ securityUpdates.push(
112815
+ projectService.updatePasswordHistoryPolicy({
112816
+ total: nullablePolicyTotal(settings.auth.security.passwordHistory)
112817
+ })
112818
+ );
112819
+ }
112820
+ if (settings.auth.security.personalDataCheck !== void 0) {
112821
+ securityUpdates.push(
112822
+ projectService.updatePasswordPersonalDataPolicy({
112823
+ enabled: settings.auth.security.personalDataCheck
112824
+ })
112825
+ );
112826
+ }
112827
+ if (settings.auth.security.sessionAlerts !== void 0) {
112828
+ securityUpdates.push(
112829
+ projectService.updateSessionAlertPolicy({
112830
+ enabled: settings.auth.security.sessionAlerts
112831
+ })
112832
+ );
112833
+ }
112834
+ await Promise.all(securityUpdates);
112593
112835
  if (settings.auth.security.mockNumbers !== void 0) {
112594
112836
  const remoteMockNumbers = [];
112595
112837
  const limit = 100;
@@ -112612,40 +112854,50 @@ var Push = class {
112612
112854
  mockNumber.otp
112613
112855
  ])
112614
112856
  );
112857
+ const mockNumberUpdates = [];
112615
112858
  for (const remoteMockNumber of remoteMockNumbers) {
112616
112859
  const desiredOtp = desiredMockNumbersByPhone.get(
112617
112860
  remoteMockNumber.number
112618
112861
  );
112619
112862
  if (desiredOtp === void 0) {
112620
- await projectService.deleteMockPhone({
112621
- number: remoteMockNumber.number
112622
- });
112863
+ mockNumberUpdates.push(
112864
+ projectService.deleteMockPhone({
112865
+ number: remoteMockNumber.number
112866
+ })
112867
+ );
112623
112868
  continue;
112624
112869
  }
112625
112870
  if (remoteMockNumber.otp !== desiredOtp) {
112626
- await projectService.updateMockPhone({
112627
- number: remoteMockNumber.number,
112628
- otp: desiredOtp
112629
- });
112871
+ mockNumberUpdates.push(
112872
+ projectService.updateMockPhone({
112873
+ number: remoteMockNumber.number,
112874
+ otp: desiredOtp
112875
+ })
112876
+ );
112630
112877
  }
112631
112878
  desiredMockNumbersByPhone.delete(remoteMockNumber.number);
112632
112879
  }
112633
112880
  for (const [phone, otp] of desiredMockNumbersByPhone) {
112634
- await projectService.createMockPhone({
112635
- number: phone,
112636
- otp
112637
- });
112881
+ mockNumberUpdates.push(
112882
+ projectService.createMockPhone({
112883
+ number: phone,
112884
+ otp
112885
+ })
112886
+ );
112638
112887
  }
112888
+ await Promise.all(mockNumberUpdates);
112639
112889
  }
112640
112890
  }
112641
112891
  if (settings.auth.methods) {
112642
112892
  this.log("Applying auth methods statuses ...");
112643
- for (const [method, status] of Object.entries(settings.auth.methods)) {
112644
- await projectService.updateAuthMethod({
112645
- methodId: method,
112646
- enabled: status
112647
- });
112648
- }
112893
+ await Promise.all(
112894
+ Object.entries(settings.auth.methods).map(
112895
+ ([method, status]) => projectService.updateAuthMethod({
112896
+ methodId: method,
112897
+ enabled: status
112898
+ })
112899
+ )
112900
+ );
112649
112901
  }
112650
112902
  }
112651
112903
  }
@@ -112936,24 +113188,7 @@ var Push = class {
112936
113188
  runtimeSpecification: func.runtimeSpecification,
112937
113189
  deploymentRetention: func.deploymentRetention
112938
113190
  });
112939
- let domain2 = "";
112940
- try {
112941
- const consoleService = await getConsoleService(
112942
- this.consoleClient
112943
- );
112944
- const variables = await consoleService.variables();
112945
- domain2 = id_default.unique() + "." + variables["_APP_DOMAIN_FUNCTIONS"];
112946
- } catch (err) {
112947
- this.error("Error fetching console variables.");
112948
- throw err;
112949
- }
112950
- try {
112951
- const proxyService = await getProxyService(this.projectClient);
112952
- await proxyService.createFunctionRule(domain2, func.$id);
112953
- } catch (err) {
112954
- this.error("Error creating function rule.");
112955
- throw err;
112956
- }
113191
+ await this.createDefaultFunctionRule(func.$id);
112957
113192
  updaterRow.update({ status: "Created" });
112958
113193
  } catch (e) {
112959
113194
  errors.push(e);
@@ -112962,6 +113197,18 @@ var Push = class {
112962
113197
  });
112963
113198
  return;
112964
113199
  }
113200
+ } else {
113201
+ try {
113202
+ if (!await this.hasDefaultFunctionRule(func.$id)) {
113203
+ await this.createDefaultFunctionRule(func.$id);
113204
+ }
113205
+ } catch (e) {
113206
+ errors.push(e);
113207
+ updaterRow.fail({
113208
+ errorMessage: e.message ?? "General error occurs please try again"
113209
+ });
113210
+ return;
113211
+ }
112965
113212
  }
112966
113213
  if (withVariables) {
112967
113214
  updaterRow.update({ status: "Updating variables" }).replaceSpinner(SPINNER_DOTS);
@@ -113738,7 +113985,7 @@ var Push = class {
113738
113985
  storageService: await getStorageService(consoleClient)
113739
113986
  };
113740
113987
  } catch (previewSetupError) {
113741
- sitePreviewSetupWarning = getErrorMessage(previewSetupError);
113988
+ sitePreviewSetupWarning = getErrorMessage2(previewSetupError);
113742
113989
  }
113743
113990
  }
113744
113991
  process.stdout.write("\n");
@@ -114063,10 +114310,11 @@ async function createPushInstance(options = {
114063
114310
  silent: false,
114064
114311
  requiresConsoleAuth: false
114065
114312
  }) {
114066
- const { silent, requiresConsoleAuth } = options;
114313
+ const { silent, requiresConsoleAuth, organizationId } = options;
114067
114314
  const projectClient = await sdkForProject();
114068
114315
  const consoleClient = await sdkForConsole({
114069
- requiresAuth: requiresConsoleAuth
114316
+ requiresAuth: requiresConsoleAuth,
114317
+ organizationId
114070
114318
  });
114071
114319
  return new Push(projectClient, consoleClient, silent);
114072
114320
  }
@@ -114097,20 +114345,11 @@ var pushResources = async ({
114097
114345
  activateFunctionsDeployment = activateAnswer.activate;
114098
114346
  }
114099
114347
  const sites = localConfig.getSites();
114100
- let allowSitesCodePush = cliConfig.force === true ? true : null;
114101
- let activateSitesDeployment = cliConfig.force === true ? true : void 0;
114102
- if (sites.length > 0 && allowSitesCodePush === null) {
114103
- const codeAnswer = await import_inquirer3.default.prompt(questionsPushSitesCode);
114104
- allowSitesCodePush = codeAnswer.override;
114105
- }
114106
- if (sites.length > 0 && allowSitesCodePush === true && activateSitesDeployment === void 0) {
114107
- const activateAnswer = await import_inquirer3.default.prompt(questionsPushSitesActivate);
114108
- activateSitesDeployment = activateAnswer.activate;
114109
- }
114348
+ const project = localConfig.getProject();
114110
114349
  const pushInstance = await createPushInstance({
114111
- requiresConsoleAuth: true
114350
+ requiresConsoleAuth: true,
114351
+ organizationId: project.organizationId
114112
114352
  });
114113
- const project = localConfig.getProject();
114114
114353
  const config2 = {
114115
114354
  organizationId: project.organizationId,
114116
114355
  projectId: project.projectId ?? "",
@@ -114133,7 +114372,7 @@ var pushResources = async ({
114133
114372
  "Configuration validation failed",
114134
114373
  config2
114135
114374
  );
114136
- await pushInstance.pushResources(config2, {
114375
+ const result = await pushInstance.pushResources(config2, {
114137
114376
  all: cliConfig.all,
114138
114377
  skipDeprecated,
114139
114378
  functionOptions: {
@@ -114143,12 +114382,13 @@ var pushResources = async ({
114143
114382
  logs: functionOptions?.logs
114144
114383
  },
114145
114384
  siteOptions: {
114146
- code: allowSitesCodePush === true,
114147
- activate: activateSitesDeployment ?? true,
114148
114385
  withVariables: false,
114149
114386
  logs: siteOptions?.logs
114150
114387
  }
114151
114388
  });
114389
+ if (result.errors.length > 0) {
114390
+ throw new Error(formatPushResourceErrors(result.results));
114391
+ }
114152
114392
  } else {
114153
114393
  const actions = {
114154
114394
  settings: pushSettings,
@@ -114227,10 +114467,11 @@ var pushSettings = async () => {
114227
114467
  }
114228
114468
  try {
114229
114469
  log("Pushing project settings ...");
114470
+ const config2 = localConfig.getProject();
114230
114471
  const pushInstance = await createPushInstance({
114231
- requiresConsoleAuth: true
114472
+ requiresConsoleAuth: true,
114473
+ organizationId: config2.organizationId ?? resolvedOrganizationId
114232
114474
  });
114233
- const config2 = localConfig.getProject();
114234
114475
  await pushInstance.pushSettings({
114235
114476
  projectId: config2.projectId,
114236
114477
  organizationId: config2.organizationId ?? resolvedOrganizationId,
@@ -114319,7 +114560,10 @@ var pushSite = async ({
114319
114560
  }
114320
114561
  log("Pushing sites ...");
114321
114562
  const pushStartTime = Date.now();
114322
- const pushInstance = await createPushInstance();
114563
+ const pushInstance = await createPushInstance({
114564
+ requiresConsoleAuth: true,
114565
+ organizationId: localConfig.getProject().organizationId
114566
+ });
114323
114567
  const result = await pushInstance.pushSites(
114324
114568
  withResolvedResourcePaths("sites", sites),
114325
114569
  {
@@ -114374,7 +114618,7 @@ var pushSite = async ({
114374
114618
  }
114375
114619
  if (cliConfig.verbose) {
114376
114620
  errors.forEach((e) => {
114377
- console.error(e);
114621
+ console.error(formatErrorForLog(e));
114378
114622
  });
114379
114623
  }
114380
114624
  };
@@ -114457,7 +114701,10 @@ var pushFunction = async ({
114457
114701
  }
114458
114702
  log("Pushing functions ...");
114459
114703
  const pushStartTime = Date.now();
114460
- const pushInstance = await createPushInstance();
114704
+ const pushInstance = await createPushInstance({
114705
+ requiresConsoleAuth: true,
114706
+ organizationId: localConfig.getProject().organizationId
114707
+ });
114461
114708
  const result = await pushInstance.pushFunctions(
114462
114709
  withResolvedResourcePaths("functions", functions),
114463
114710
  {
@@ -114512,7 +114759,7 @@ var pushFunction = async ({
114512
114759
  }
114513
114760
  if (cliConfig.verbose) {
114514
114761
  errors.forEach((e) => {
114515
- console.error(e);
114762
+ console.error(formatErrorForLog(e));
114516
114763
  });
114517
114764
  }
114518
114765
  };
@@ -114657,7 +114904,7 @@ var pushTable = async ({
114657
114904
  success2(`Successfully pushed ${successfullyPushed} tables.`);
114658
114905
  }
114659
114906
  if (cliConfig.verbose) {
114660
- errors.forEach((e) => console.error(e));
114907
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114661
114908
  }
114662
114909
  };
114663
114910
  var pushCollection = async () => {
@@ -114721,7 +114968,7 @@ var pushCollection = async () => {
114721
114968
  success2(`Successfully pushed ${successfullyPushed} collections.`);
114722
114969
  }
114723
114970
  if (cliConfig.verbose) {
114724
- errors.forEach((e) => console.error(e));
114971
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114725
114972
  }
114726
114973
  };
114727
114974
  var pushBucket = async () => {
@@ -114771,7 +115018,7 @@ var pushBucket = async () => {
114771
115018
  success2(`Successfully pushed ${successfullyPushed} buckets.`);
114772
115019
  }
114773
115020
  if (cliConfig.verbose) {
114774
- errors.forEach((e) => console.error(e));
115021
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114775
115022
  }
114776
115023
  };
114777
115024
  var pushTeam = async () => {
@@ -114821,7 +115068,7 @@ var pushTeam = async () => {
114821
115068
  success2(`Successfully pushed ${successfullyPushed} teams.`);
114822
115069
  }
114823
115070
  if (cliConfig.verbose) {
114824
- errors.forEach((e) => console.error(e));
115071
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114825
115072
  }
114826
115073
  };
114827
115074
  var pushWebhook = async () => {
@@ -114871,7 +115118,7 @@ var pushWebhook = async () => {
114871
115118
  success2(`Successfully pushed ${successfullyPushed} webhooks.`);
114872
115119
  }
114873
115120
  if (cliConfig.verbose) {
114874
- errors.forEach((e) => console.error(e));
115121
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114875
115122
  }
114876
115123
  };
114877
115124
  var pushMessagingTopic = async () => {
@@ -114921,7 +115168,7 @@ var pushMessagingTopic = async () => {
114921
115168
  success2(`Successfully pushed ${successfullyPushed} topics.`);
114922
115169
  }
114923
115170
  if (cliConfig.verbose) {
114924
- errors.forEach((e) => console.error(e));
115171
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114925
115172
  }
114926
115173
  };
114927
115174
  var push = new Command("push").description(commandDescriptions["push"]).action(actionRunner(() => pushResources({ skipDeprecated: true })));