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.cjs CHANGED
@@ -35929,7 +35929,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
35929
35929
  }
35930
35930
  return positiveOption || option2;
35931
35931
  };
35932
- const getErrorMessage2 = (option2) => {
35932
+ const getErrorMessage3 = (option2) => {
35933
35933
  const bestOption = findBestOptionFromValue(option2);
35934
35934
  const optionKey = bestOption.attributeName();
35935
35935
  const source = this.getOptionValueSource(optionKey);
@@ -35938,7 +35938,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
35938
35938
  }
35939
35939
  return `option '${bestOption.flags}'`;
35940
35940
  };
35941
- const message = `error: ${getErrorMessage2(option)} cannot be used with ${getErrorMessage2(conflictingOption)}`;
35941
+ const message = `error: ${getErrorMessage3(option)} cannot be used with ${getErrorMessage3(conflictingOption)}`;
35942
35942
  this.error(message, { code: "commander.conflictingOption" });
35943
35943
  }
35944
35944
  /**
@@ -65565,7 +65565,7 @@ var id_default = ID;
65565
65565
  // lib/constants.ts
65566
65566
  var SDK_TITLE = "Appwrite";
65567
65567
  var SDK_TITLE_LOWER = "appwrite";
65568
- var SDK_VERSION = "22.2.2";
65568
+ var SDK_VERSION = "22.4.0";
65569
65569
  var SDK_LOGO = "\n _ _ _ ___ __ _____\n /_\\ _ __ _ ____ ___ __(_) |_ ___ / __\\ / / \\_ \\\n //_\\\\| '_ \\| '_ \\ \\ /\\ / / '__| | __/ _ \\ / / / / / /\\/\n / _ \\ |_) | |_) \\ V V /| | | | || __/ / /___/ /___/\\/ /_\n \\_/ \\_/ .__/| .__/ \\_/\\_/ |_| |_|\\__\\___| \\____/\\____/\\____/\n |_| |_|\n\n";
65570
65570
  var EXECUTABLE_NAME = "appwrite";
65571
65571
  var UPDATE_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
@@ -80304,9 +80304,9 @@ var SettingsSchema = external_exports.object({
80304
80304
  }).strict().optional(),
80305
80305
  security: external_exports.object({
80306
80306
  duration: external_exports.union([external_exports.number(), external_exports.bigint()]).optional(),
80307
- limit: external_exports.union([external_exports.number(), external_exports.bigint()]).optional(),
80308
- sessionsLimit: external_exports.union([external_exports.number(), external_exports.bigint()]).optional(),
80309
- passwordHistory: external_exports.union([external_exports.number(), external_exports.bigint()]).optional(),
80307
+ limit: external_exports.union([external_exports.number(), external_exports.bigint()]).nullable().optional(),
80308
+ sessionsLimit: external_exports.union([external_exports.number(), external_exports.bigint()]).nullable().optional(),
80309
+ passwordHistory: external_exports.union([external_exports.number(), external_exports.bigint()]).nullable().optional(),
80310
80310
  passwordDictionary: external_exports.boolean().optional(),
80311
80311
  personalDataCheck: external_exports.boolean().optional(),
80312
80312
  sessionAlerts: external_exports.boolean().optional(),
@@ -103649,7 +103649,10 @@ var createSettingsObject = (project, policies, mockNumbers) => {
103649
103649
  }
103650
103650
  const policyTotal = (id) => {
103651
103651
  const policy = policyById.get(id);
103652
- return policy && "total" in policy ? policy.total : void 0;
103652
+ if (!policy || !("total" in policy)) {
103653
+ return void 0;
103654
+ }
103655
+ return policy.total === 0 ? null : policy.total;
103653
103656
  };
103654
103657
  const policyEnabled = (id) => {
103655
103658
  const policy = policyById.get(id);
@@ -103715,8 +103718,23 @@ var getSafeDirectoryName = (value, fallback) => {
103715
103718
  var siteRequiresBuildCommand = (site) => {
103716
103719
  return !(site.framework === "other" && site.adapter === "static");
103717
103720
  };
103721
+ var getErrorMessage = (error52) => {
103722
+ if (error52 instanceof Error) {
103723
+ const message = typeof error52.message === "string" ? error52.message.trim() : "";
103724
+ if (message) {
103725
+ return message;
103726
+ }
103727
+ const response = error52.response;
103728
+ if (typeof response === "string" && response.trim() !== "") {
103729
+ return response.trim();
103730
+ }
103731
+ return "An unknown error occurred.";
103732
+ }
103733
+ return String(error52);
103734
+ };
103718
103735
  var WINDOWS_EXECUTABLE_NAME = `${EXECUTABLE_NAME.toLowerCase()}.exe`;
103719
103736
  var CLOUD_REGION_CODES = /* @__PURE__ */ new Set(["fra", "nyc", "syd", "sfo", "sgp", "tor"]);
103737
+ var CLOUD_LOGIN_ENVIRONMENTS = /* @__PURE__ */ new Set(["stage"]);
103720
103738
  var isCloudHostname = (hostname3) => {
103721
103739
  if (hostname3 === "cloud.appwrite.io") {
103722
103740
  return true;
@@ -103726,11 +103744,44 @@ var isCloudHostname = (hostname3) => {
103726
103744
  }
103727
103745
  return CLOUD_REGION_CODES.has(hostname3.split(".")[0]);
103728
103746
  };
103747
+ var getCloudEndpointRegion = (endpoint) => {
103748
+ try {
103749
+ const hostname3 = new URL(endpoint).hostname;
103750
+ if (!isCloudHostname(hostname3) || hostname3 === "cloud.appwrite.io") {
103751
+ return null;
103752
+ }
103753
+ const region = hostname3.split(".")[0];
103754
+ return CLOUD_REGION_CODES.has(region) ? region : null;
103755
+ } catch (_error) {
103756
+ return null;
103757
+ }
103758
+ };
103759
+ var getCloudConsoleHostname = (hostname3) => {
103760
+ if (hostname3 === "cloud.appwrite.io") {
103761
+ return hostname3;
103762
+ }
103763
+ const labels = hostname3.split(".");
103764
+ if (labels.length < 4 || labels.slice(-3).join(".") !== "cloud.appwrite.io") {
103765
+ return null;
103766
+ }
103767
+ if (CLOUD_REGION_CODES.has(labels[0])) {
103768
+ const environment = labels[1];
103769
+ if (environment && CLOUD_LOGIN_ENVIRONMENTS.has(environment)) {
103770
+ return `${environment}.cloud.appwrite.io`;
103771
+ }
103772
+ return "cloud.appwrite.io";
103773
+ }
103774
+ if (CLOUD_LOGIN_ENVIRONMENTS.has(labels[0])) {
103775
+ return hostname3;
103776
+ }
103777
+ return null;
103778
+ };
103729
103779
  var getConsoleBaseUrl = (endpoint) => {
103730
103780
  try {
103731
103781
  const url2 = new URL(endpoint);
103732
- if (isCloudHostname(url2.hostname)) {
103733
- url2.hostname = "cloud.appwrite.io";
103782
+ const consoleHostname = getCloudConsoleHostname(url2.hostname);
103783
+ if (consoleHostname) {
103784
+ url2.hostname = consoleHostname;
103734
103785
  }
103735
103786
  url2.pathname = url2.pathname.replace(/\/v1\/?$/, "");
103736
103787
  url2.search = "";
@@ -104216,10 +104267,7 @@ var Config = class {
104216
104267
  }
104217
104268
  _addDBEntity(entityType, props, keysSet, nestedKeys = {}) {
104218
104269
  props = whitelistKeys(props, keysSet, nestedKeys);
104219
- if (!this.has(entityType)) {
104220
- this.set(entityType, []);
104221
- }
104222
- const entities = this.get(entityType);
104270
+ const entities = this.has(entityType) ? [...this.get(entityType) ?? []] : [];
104223
104271
  for (let i = 0; i < entities.length; i++) {
104224
104272
  if (entities[i]["$id"] == props["$id"]) {
104225
104273
  entities[i] = props;
@@ -104911,7 +104959,7 @@ var package_default = {
104911
104959
  type: "module",
104912
104960
  homepage: "https://appwrite.io/support",
104913
104961
  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",
104914
- version: "22.2.2",
104962
+ version: "22.4.0",
104915
104963
  license: "BSD-3-Clause",
104916
104964
  main: "dist/index.cjs",
104917
104965
  module: "dist/index.js",
@@ -105910,6 +105958,53 @@ var printQueryErrorHint = (err) => {
105910
105958
  `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]}'`
105911
105959
  );
105912
105960
  };
105961
+ var ERROR_DETAIL_KEYS = ["code", "type", "response"];
105962
+ var ERROR_DETAIL_INDENT = " ";
105963
+ var ERROR_DETAIL_LABEL_WIDTH = Math.max(...ERROR_DETAIL_KEYS.map((key) => key.length)) + 2;
105964
+ var formatErrorDetail = (value) => {
105965
+ if (typeof value === "string") {
105966
+ const text = value;
105967
+ try {
105968
+ const parsed = JSON.parse(text);
105969
+ if (parsed && typeof parsed === "object") {
105970
+ value = parsed;
105971
+ }
105972
+ } catch {
105973
+ return text;
105974
+ }
105975
+ }
105976
+ try {
105977
+ const json2 = JSON.stringify(value, null, 2) ?? String(value);
105978
+ return json2.split("\n").map((line, index) => index === 0 ? line : ERROR_DETAIL_INDENT + line).join("\n");
105979
+ } catch {
105980
+ return String(value);
105981
+ }
105982
+ };
105983
+ var formatErrorForLog = (err) => {
105984
+ const lines = [
105985
+ `${import_chalk2.default.red.bold(err.name || "Error")}${import_chalk2.default.red(`: ${getErrorMessage(err)}`)}`
105986
+ ];
105987
+ for (const key of ERROR_DETAIL_KEYS) {
105988
+ if (!Object.prototype.hasOwnProperty.call(err, key)) {
105989
+ continue;
105990
+ }
105991
+ const value = err[key];
105992
+ lines.push(
105993
+ `${ERROR_DETAIL_INDENT}${import_chalk2.default.cyan(`${key}:`.padEnd(ERROR_DETAIL_LABEL_WIDTH))}${formatErrorDetail(value)}`
105994
+ );
105995
+ }
105996
+ const frames = (err.stack ?? "").split("\n").filter((line) => line.trim().startsWith("at "));
105997
+ if (frames.length > 0) {
105998
+ lines.push(
105999
+ "",
106000
+ import_chalk2.default.dim(`${ERROR_DETAIL_INDENT}Stack trace:`),
106001
+ ...frames.map(
106002
+ (frame) => import_chalk2.default.dim(`${ERROR_DETAIL_INDENT.repeat(2)}${frame.trim()}`)
106003
+ )
106004
+ );
106005
+ }
106006
+ return lines.join("\n");
106007
+ };
105913
106008
  var parseError = (err) => {
105914
106009
  if (cliConfig.report) {
105915
106010
  void (async () => {
@@ -105939,7 +106034,7 @@ Is Cloud: ${isCloud()}`;
105939
106034
  githubIssueUrl.searchParams.append("template", "bug.yaml");
105940
106035
  githubIssueUrl.searchParams.append(
105941
106036
  "title",
105942
- `\u{1F41B} Bug Report: ${err.message}`
106037
+ `\u{1F41B} Bug Report: ${getErrorMessage(err)}`
105943
106038
  );
105944
106039
  githubIssueUrl.searchParams.append(
105945
106040
  "actual-behavior",
@@ -105960,16 +106055,16 @@ ${stack}`
105960
106055
  );
105961
106056
  printQueryErrorHint(err);
105962
106057
  error51("\n Stack Trace: \n");
105963
- console.error(err);
106058
+ console.error(formatErrorForLog(err));
105964
106059
  process.exit(1);
105965
106060
  })();
105966
106061
  } else {
105967
106062
  if (cliConfig.verbose) {
105968
- console.error(err);
106063
+ console.error(formatErrorForLog(err));
105969
106064
  printQueryErrorHint(err);
105970
106065
  } else {
105971
106066
  log("For detailed error pass the --verbose or --report flag");
105972
- error51(err.message);
106067
+ error51(getErrorMessage(err));
105973
106068
  printQueryErrorHint(err);
105974
106069
  }
105975
106070
  process.exit(1);
@@ -106015,7 +106110,7 @@ var commandDescriptions = {
106015
106110
  avatars: `The avatars command aims to help you complete everyday tasks related to your app image, icons, and avatars.`,
106016
106111
  databases: `(Legacy) The databases command allows you to create structured collections of documents and query and filter lists of documents.`,
106017
106112
  "tables-db": `The tables-db command allows you to create structured tables of columns and query and filter lists of rows.`,
106018
- 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}.`,
106113
+ init: `The init command provides a convenient wrapper for creating and initializing projects, functions, collections, buckets, teams, messaging-topics, and skills in ${SDK_TITLE}.`,
106019
106114
  push: `The push command provides a convenient wrapper for pushing your functions, collections, buckets, teams, and messaging-topics.`,
106020
106115
  run: `The run command allows you to run the project locally to allow easy development and quick debugging.`,
106021
106116
  functions: `The functions command allows you to view, create, and manage your Cloud Functions.`,
@@ -109601,12 +109696,12 @@ var deleteStoredRefreshToken = (sessionId) => {
109601
109696
  };
109602
109697
 
109603
109698
  // lib/sdks.ts
109604
- var getValidAccessToken = async (endpoint) => {
109699
+ var getValidAccessToken = async (endpoint, options = {}) => {
109605
109700
  const accessToken = globalConfig2.getAccessToken();
109606
109701
  const tokenExpiry = globalConfig2.getTokenExpiry();
109607
109702
  const clientId = globalConfig2.getClientId() || OAUTH2_CLIENT_ID;
109608
109703
  const currentSession = globalConfig2.getCurrentSession();
109609
- if (accessToken && tokenExpiry > Date.now() + 6e4) {
109704
+ if (!options.forceRefresh && accessToken && tokenExpiry > Date.now() + 6e4) {
109610
109705
  return accessToken;
109611
109706
  }
109612
109707
  const refreshToken = currentSession ? getStoredRefreshToken(currentSession) : "";
@@ -110098,7 +110193,7 @@ async function downloadDeploymentCode(params) {
110098
110193
  }
110099
110194
  } catch (e) {
110100
110195
  if (e instanceof AppwriteException) {
110101
- error51(e.message);
110196
+ error51(getErrorMessage(e));
110102
110197
  return;
110103
110198
  } else {
110104
110199
  throw e;
@@ -112021,12 +112116,12 @@ async function getTerminalImage() {
112021
112116
  );
112022
112117
  return terminalImageModulePromise;
112023
112118
  }
112024
- function getErrorMessage(error52) {
112119
+ function getErrorMessage2(error52) {
112025
112120
  if (error52 instanceof Error && error52.message.trim().length > 0) {
112026
112121
  return error52.message.trim();
112027
112122
  }
112028
112123
  if (Array.isArray(error52)) {
112029
- const messages = error52.map((entry) => getErrorMessage(entry)).filter((entry) => entry !== "Unknown error");
112124
+ const messages = error52.map((entry) => getErrorMessage2(entry)).filter((entry) => entry !== "Unknown error");
112030
112125
  if (messages.length > 0) {
112031
112126
  return messages.join("; ");
112032
112127
  }
@@ -112184,7 +112279,7 @@ async function renderSiteTerminalPreview(params) {
112184
112279
  };
112185
112280
  } catch (previewError) {
112186
112281
  warnings.add(
112187
- `${label === "dark" ? "Dark mode" : "Light mode"} screenshot: ${getErrorMessage(previewError)}`
112282
+ `${label === "dark" ? "Dark mode" : "Light mode"} screenshot: ${getErrorMessage2(previewError)}`
112188
112283
  );
112189
112284
  }
112190
112285
  }
@@ -112286,6 +112381,44 @@ function createDeploymentLogsController(enabled) {
112286
112381
  close: cleanup
112287
112382
  };
112288
112383
  }
112384
+ var getPushErrorMessage = (error52) => {
112385
+ if (error52 instanceof Error) {
112386
+ return error52.message;
112387
+ }
112388
+ if (typeof error52 === "object" && error52 !== null && "message" in error52 && typeof error52.message === "string") {
112389
+ return error52.message;
112390
+ }
112391
+ return String(error52);
112392
+ };
112393
+ var getPushResultErrors = (result) => {
112394
+ if (typeof result !== "object" || result === null) {
112395
+ return [];
112396
+ }
112397
+ if ("errors" in result && Array.isArray(result.errors) && result.errors.length > 0) {
112398
+ return result.errors.map(getPushErrorMessage).filter((message) => message.trim() !== "");
112399
+ }
112400
+ if ("error" in result && typeof result.error === "string" && result.error.trim() !== "") {
112401
+ return [result.error];
112402
+ }
112403
+ return [];
112404
+ };
112405
+ var formatPushResourceErrors = (results) => {
112406
+ const failed = Object.entries(results).map(([resourceGroup, result]) => ({
112407
+ resourceGroup,
112408
+ messages: getPushResultErrors(result)
112409
+ })).filter(({ messages }) => messages.length > 0);
112410
+ if (failed.length === 0) {
112411
+ return "Failed to push resource groups.";
112412
+ }
112413
+ return [
112414
+ `Failed to push ${failed.length} resource group${failed.length === 1 ? "" : "s"}:`,
112415
+ ...failed.flatMap(({ resourceGroup, messages }) => [
112416
+ `- ${resourceGroup}:`,
112417
+ ...messages.map((message) => ` - ${message}`)
112418
+ ])
112419
+ ].join("\n");
112420
+ };
112421
+ var nullablePolicyTotal = (value) => value === null || Number(value) === 0 ? null : Number(value);
112289
112422
  var normalizeIgnoreRules = (value) => {
112290
112423
  if (Array.isArray(value)) {
112291
112424
  return value.filter(
@@ -112331,6 +112464,53 @@ var Push = class {
112331
112464
  warn(message);
112332
112465
  }
112333
112466
  }
112467
+ getFunctionRuleDomain(domain2) {
112468
+ const region = getCloudEndpointRegion(this.projectClient.config.endpoint);
112469
+ if (!region) {
112470
+ return domain2;
112471
+ }
112472
+ const parts = domain2.split(".");
112473
+ if (parts.length < 3) {
112474
+ return domain2;
112475
+ }
112476
+ parts[0] = region;
112477
+ return parts.join(".");
112478
+ }
112479
+ async createDefaultFunctionRule(functionId) {
112480
+ let domain2 = "";
112481
+ try {
112482
+ const consoleService = await getConsoleService(this.consoleClient);
112483
+ const variables = await consoleService.variables();
112484
+ const domains = variables["_APP_DOMAIN_FUNCTIONS"].split(",").map((value) => value.trim()).filter((value) => value.length > 0);
112485
+ if (domains.length === 0) {
112486
+ throw new Error("_APP_DOMAIN_FUNCTIONS is not configured.");
112487
+ }
112488
+ domain2 = id_default.unique() + "." + this.getFunctionRuleDomain(domains[0]);
112489
+ } catch (err) {
112490
+ this.error("Error fetching console variables.");
112491
+ throw err;
112492
+ }
112493
+ try {
112494
+ const proxyService = await getProxyService(this.projectClient);
112495
+ this.log(`Creating function proxy rule for ${domain2} ...`);
112496
+ await proxyService.createFunctionRule(domain2, functionId);
112497
+ } catch (err) {
112498
+ this.error("Error creating function rule.");
112499
+ throw err;
112500
+ }
112501
+ }
112502
+ async hasDefaultFunctionRule(functionId) {
112503
+ const proxyService = await getProxyService(this.projectClient);
112504
+ const { rules } = await proxyService.listRules({
112505
+ queries: [
112506
+ Query.limit(1),
112507
+ Query.equal("deploymentResourceType", "function"),
112508
+ Query.equal("deploymentResourceId", functionId),
112509
+ Query.equal("trigger", "manual")
112510
+ ]
112511
+ });
112512
+ return rules.length > 0;
112513
+ }
112334
112514
  /**
112335
112515
  * Log an error message (respects silent mode)
112336
112516
  */
@@ -112394,7 +112574,11 @@ var Push = class {
112394
112574
  results.settings = { success: true };
112395
112575
  } catch (e) {
112396
112576
  allErrors.push(e);
112397
- results.settings = { success: false, error: e.message };
112577
+ results.settings = {
112578
+ success: false,
112579
+ error: getPushErrorMessage(e),
112580
+ errors: [e]
112581
+ };
112398
112582
  }
112399
112583
  }
112400
112584
  if ((shouldPushAll || options.buckets) && config2.buckets && config2.buckets.length > 0) {
@@ -112477,10 +112661,28 @@ var Push = class {
112477
112661
  }
112478
112662
  if ((shouldPushAll || options.sites) && config2.sites && config2.sites.length > 0) {
112479
112663
  try {
112664
+ let siteOptions = options.siteOptions;
112665
+ if (siteOptions?.code === void 0) {
112666
+ let allowSitesCodePush = cliConfig.force === true ? true : null;
112667
+ if (allowSitesCodePush === null) {
112668
+ const codeAnswer = await import_inquirer3.default.prompt(questionsPushSitesCode);
112669
+ allowSitesCodePush = codeAnswer.override;
112670
+ }
112671
+ siteOptions = {
112672
+ ...siteOptions,
112673
+ code: allowSitesCodePush === true
112674
+ };
112675
+ }
112676
+ if (siteOptions.code === true && siteOptions.activate === void 0) {
112677
+ siteOptions = {
112678
+ ...siteOptions,
112679
+ activate: cliConfig.force === true ? true : (await import_inquirer3.default.prompt(questionsPushSitesActivate)).activate
112680
+ };
112681
+ }
112480
112682
  this.log("Pushing sites ...");
112481
112683
  const result = await this.pushSites(
112482
112684
  config2.sites,
112483
- options.siteOptions
112685
+ siteOptions
112484
112686
  );
112485
112687
  this.success(
112486
112688
  `Successfully pushed ${import_chalk9.default.bold(result.successfullyPushed)} sites.`
@@ -112499,6 +112701,12 @@ var Push = class {
112499
112701
  }
112500
112702
  if ((shouldPushAll || options.tables) && config2.tables && config2.tables.length > 0) {
112501
112703
  try {
112704
+ const { resyncNeeded } = await checkAndApplyTablesDBChanges();
112705
+ if (resyncNeeded) {
112706
+ throw new Error(
112707
+ "Configuration changed after applying tablesDB deletions. Re-run the push command to continue."
112708
+ );
112709
+ }
112502
112710
  this.log("Pushing tables ...");
112503
112711
  const result = await this.pushTables(config2.tables, {
112504
112712
  attempts: options.tableOptions?.attempts,
@@ -112570,46 +112778,80 @@ var Push = class {
112570
112778
  }
112571
112779
  if (settings.services) {
112572
112780
  this.log("Applying service statuses ...");
112573
- for (const [service, status] of Object.entries(settings.services)) {
112574
- await projectService.updateService({
112575
- serviceId: service,
112576
- enabled: status
112577
- });
112578
- }
112781
+ await Promise.all(
112782
+ Object.entries(settings.services).map(
112783
+ ([service, status]) => projectService.updateService({
112784
+ serviceId: service,
112785
+ enabled: status
112786
+ })
112787
+ )
112788
+ );
112579
112789
  }
112580
112790
  if (settings.protocols) {
112581
112791
  this.log("Applying protocol statuses ...");
112582
- for (const [protocol, status] of Object.entries(settings.protocols)) {
112583
- await projectService.updateProtocol({
112584
- protocolId: protocol,
112585
- enabled: status
112586
- });
112587
- }
112792
+ await Promise.all(
112793
+ Object.entries(settings.protocols).map(
112794
+ ([protocol, status]) => projectService.updateProtocol({
112795
+ protocolId: protocol,
112796
+ enabled: status
112797
+ })
112798
+ )
112799
+ );
112588
112800
  }
112589
112801
  if (settings.auth) {
112590
112802
  if (settings.auth.security) {
112591
112803
  this.log("Applying auth security settings ...");
112592
- await projectService.updateSessionDurationPolicy({
112593
- duration: Number(settings.auth.security.duration)
112594
- });
112595
- await projectService.updateUserLimitPolicy({
112596
- total: Number(settings.auth.security.limit)
112597
- });
112598
- await projectService.updateSessionLimitPolicy({
112599
- total: Number(settings.auth.security.sessionsLimit)
112600
- });
112601
- await projectService.updatePasswordDictionaryPolicy({
112602
- enabled: settings.auth.security.passwordDictionary
112603
- });
112604
- await projectService.updatePasswordHistoryPolicy({
112605
- total: Number(settings.auth.security.passwordHistory)
112606
- });
112607
- await projectService.updatePasswordPersonalDataPolicy({
112608
- enabled: settings.auth.security.personalDataCheck
112609
- });
112610
- await projectService.updateSessionAlertPolicy({
112611
- enabled: settings.auth.security.sessionAlerts
112612
- });
112804
+ const securityUpdates = [];
112805
+ if (settings.auth.security.duration !== void 0) {
112806
+ securityUpdates.push(
112807
+ projectService.updateSessionDurationPolicy({
112808
+ duration: Number(settings.auth.security.duration)
112809
+ })
112810
+ );
112811
+ }
112812
+ if (settings.auth.security.limit !== void 0) {
112813
+ securityUpdates.push(
112814
+ projectService.updateUserLimitPolicy({
112815
+ total: nullablePolicyTotal(settings.auth.security.limit)
112816
+ })
112817
+ );
112818
+ }
112819
+ if (settings.auth.security.sessionsLimit !== void 0) {
112820
+ securityUpdates.push(
112821
+ projectService.updateSessionLimitPolicy({
112822
+ total: nullablePolicyTotal(settings.auth.security.sessionsLimit)
112823
+ })
112824
+ );
112825
+ }
112826
+ if (settings.auth.security.passwordDictionary !== void 0) {
112827
+ securityUpdates.push(
112828
+ projectService.updatePasswordDictionaryPolicy({
112829
+ enabled: settings.auth.security.passwordDictionary
112830
+ })
112831
+ );
112832
+ }
112833
+ if (settings.auth.security.passwordHistory !== void 0) {
112834
+ securityUpdates.push(
112835
+ projectService.updatePasswordHistoryPolicy({
112836
+ total: nullablePolicyTotal(settings.auth.security.passwordHistory)
112837
+ })
112838
+ );
112839
+ }
112840
+ if (settings.auth.security.personalDataCheck !== void 0) {
112841
+ securityUpdates.push(
112842
+ projectService.updatePasswordPersonalDataPolicy({
112843
+ enabled: settings.auth.security.personalDataCheck
112844
+ })
112845
+ );
112846
+ }
112847
+ if (settings.auth.security.sessionAlerts !== void 0) {
112848
+ securityUpdates.push(
112849
+ projectService.updateSessionAlertPolicy({
112850
+ enabled: settings.auth.security.sessionAlerts
112851
+ })
112852
+ );
112853
+ }
112854
+ await Promise.all(securityUpdates);
112613
112855
  if (settings.auth.security.mockNumbers !== void 0) {
112614
112856
  const remoteMockNumbers = [];
112615
112857
  const limit = 100;
@@ -112632,40 +112874,50 @@ var Push = class {
112632
112874
  mockNumber.otp
112633
112875
  ])
112634
112876
  );
112877
+ const mockNumberUpdates = [];
112635
112878
  for (const remoteMockNumber of remoteMockNumbers) {
112636
112879
  const desiredOtp = desiredMockNumbersByPhone.get(
112637
112880
  remoteMockNumber.number
112638
112881
  );
112639
112882
  if (desiredOtp === void 0) {
112640
- await projectService.deleteMockPhone({
112641
- number: remoteMockNumber.number
112642
- });
112883
+ mockNumberUpdates.push(
112884
+ projectService.deleteMockPhone({
112885
+ number: remoteMockNumber.number
112886
+ })
112887
+ );
112643
112888
  continue;
112644
112889
  }
112645
112890
  if (remoteMockNumber.otp !== desiredOtp) {
112646
- await projectService.updateMockPhone({
112647
- number: remoteMockNumber.number,
112648
- otp: desiredOtp
112649
- });
112891
+ mockNumberUpdates.push(
112892
+ projectService.updateMockPhone({
112893
+ number: remoteMockNumber.number,
112894
+ otp: desiredOtp
112895
+ })
112896
+ );
112650
112897
  }
112651
112898
  desiredMockNumbersByPhone.delete(remoteMockNumber.number);
112652
112899
  }
112653
112900
  for (const [phone, otp] of desiredMockNumbersByPhone) {
112654
- await projectService.createMockPhone({
112655
- number: phone,
112656
- otp
112657
- });
112901
+ mockNumberUpdates.push(
112902
+ projectService.createMockPhone({
112903
+ number: phone,
112904
+ otp
112905
+ })
112906
+ );
112658
112907
  }
112908
+ await Promise.all(mockNumberUpdates);
112659
112909
  }
112660
112910
  }
112661
112911
  if (settings.auth.methods) {
112662
112912
  this.log("Applying auth methods statuses ...");
112663
- for (const [method, status] of Object.entries(settings.auth.methods)) {
112664
- await projectService.updateAuthMethod({
112665
- methodId: method,
112666
- enabled: status
112667
- });
112668
- }
112913
+ await Promise.all(
112914
+ Object.entries(settings.auth.methods).map(
112915
+ ([method, status]) => projectService.updateAuthMethod({
112916
+ methodId: method,
112917
+ enabled: status
112918
+ })
112919
+ )
112920
+ );
112669
112921
  }
112670
112922
  }
112671
112923
  }
@@ -112956,24 +113208,7 @@ var Push = class {
112956
113208
  runtimeSpecification: func.runtimeSpecification,
112957
113209
  deploymentRetention: func.deploymentRetention
112958
113210
  });
112959
- let domain2 = "";
112960
- try {
112961
- const consoleService = await getConsoleService(
112962
- this.consoleClient
112963
- );
112964
- const variables = await consoleService.variables();
112965
- domain2 = id_default.unique() + "." + variables["_APP_DOMAIN_FUNCTIONS"];
112966
- } catch (err) {
112967
- this.error("Error fetching console variables.");
112968
- throw err;
112969
- }
112970
- try {
112971
- const proxyService = await getProxyService(this.projectClient);
112972
- await proxyService.createFunctionRule(domain2, func.$id);
112973
- } catch (err) {
112974
- this.error("Error creating function rule.");
112975
- throw err;
112976
- }
113211
+ await this.createDefaultFunctionRule(func.$id);
112977
113212
  updaterRow.update({ status: "Created" });
112978
113213
  } catch (e) {
112979
113214
  errors.push(e);
@@ -112982,6 +113217,18 @@ var Push = class {
112982
113217
  });
112983
113218
  return;
112984
113219
  }
113220
+ } else {
113221
+ try {
113222
+ if (!await this.hasDefaultFunctionRule(func.$id)) {
113223
+ await this.createDefaultFunctionRule(func.$id);
113224
+ }
113225
+ } catch (e) {
113226
+ errors.push(e);
113227
+ updaterRow.fail({
113228
+ errorMessage: e.message ?? "General error occurs please try again"
113229
+ });
113230
+ return;
113231
+ }
112985
113232
  }
112986
113233
  if (withVariables) {
112987
113234
  updaterRow.update({ status: "Updating variables" }).replaceSpinner(SPINNER_DOTS);
@@ -113758,7 +114005,7 @@ var Push = class {
113758
114005
  storageService: await getStorageService(consoleClient)
113759
114006
  };
113760
114007
  } catch (previewSetupError) {
113761
- sitePreviewSetupWarning = getErrorMessage(previewSetupError);
114008
+ sitePreviewSetupWarning = getErrorMessage2(previewSetupError);
113762
114009
  }
113763
114010
  }
113764
114011
  process.stdout.write("\n");
@@ -114083,10 +114330,11 @@ async function createPushInstance(options = {
114083
114330
  silent: false,
114084
114331
  requiresConsoleAuth: false
114085
114332
  }) {
114086
- const { silent, requiresConsoleAuth } = options;
114333
+ const { silent, requiresConsoleAuth, organizationId } = options;
114087
114334
  const projectClient = await sdkForProject();
114088
114335
  const consoleClient = await sdkForConsole({
114089
- requiresAuth: requiresConsoleAuth
114336
+ requiresAuth: requiresConsoleAuth,
114337
+ organizationId
114090
114338
  });
114091
114339
  return new Push(projectClient, consoleClient, silent);
114092
114340
  }
@@ -114117,20 +114365,11 @@ var pushResources = async ({
114117
114365
  activateFunctionsDeployment = activateAnswer.activate;
114118
114366
  }
114119
114367
  const sites = localConfig.getSites();
114120
- let allowSitesCodePush = cliConfig.force === true ? true : null;
114121
- let activateSitesDeployment = cliConfig.force === true ? true : void 0;
114122
- if (sites.length > 0 && allowSitesCodePush === null) {
114123
- const codeAnswer = await import_inquirer3.default.prompt(questionsPushSitesCode);
114124
- allowSitesCodePush = codeAnswer.override;
114125
- }
114126
- if (sites.length > 0 && allowSitesCodePush === true && activateSitesDeployment === void 0) {
114127
- const activateAnswer = await import_inquirer3.default.prompt(questionsPushSitesActivate);
114128
- activateSitesDeployment = activateAnswer.activate;
114129
- }
114368
+ const project = localConfig.getProject();
114130
114369
  const pushInstance = await createPushInstance({
114131
- requiresConsoleAuth: true
114370
+ requiresConsoleAuth: true,
114371
+ organizationId: project.organizationId
114132
114372
  });
114133
- const project = localConfig.getProject();
114134
114373
  const config2 = {
114135
114374
  organizationId: project.organizationId,
114136
114375
  projectId: project.projectId ?? "",
@@ -114153,7 +114392,7 @@ var pushResources = async ({
114153
114392
  "Configuration validation failed",
114154
114393
  config2
114155
114394
  );
114156
- await pushInstance.pushResources(config2, {
114395
+ const result = await pushInstance.pushResources(config2, {
114157
114396
  all: cliConfig.all,
114158
114397
  skipDeprecated,
114159
114398
  functionOptions: {
@@ -114163,12 +114402,13 @@ var pushResources = async ({
114163
114402
  logs: functionOptions?.logs
114164
114403
  },
114165
114404
  siteOptions: {
114166
- code: allowSitesCodePush === true,
114167
- activate: activateSitesDeployment ?? true,
114168
114405
  withVariables: false,
114169
114406
  logs: siteOptions?.logs
114170
114407
  }
114171
114408
  });
114409
+ if (result.errors.length > 0) {
114410
+ throw new Error(formatPushResourceErrors(result.results));
114411
+ }
114172
114412
  } else {
114173
114413
  const actions = {
114174
114414
  settings: pushSettings,
@@ -114247,10 +114487,11 @@ var pushSettings = async () => {
114247
114487
  }
114248
114488
  try {
114249
114489
  log("Pushing project settings ...");
114490
+ const config2 = localConfig.getProject();
114250
114491
  const pushInstance = await createPushInstance({
114251
- requiresConsoleAuth: true
114492
+ requiresConsoleAuth: true,
114493
+ organizationId: config2.organizationId ?? resolvedOrganizationId
114252
114494
  });
114253
- const config2 = localConfig.getProject();
114254
114495
  await pushInstance.pushSettings({
114255
114496
  projectId: config2.projectId,
114256
114497
  organizationId: config2.organizationId ?? resolvedOrganizationId,
@@ -114339,7 +114580,10 @@ var pushSite = async ({
114339
114580
  }
114340
114581
  log("Pushing sites ...");
114341
114582
  const pushStartTime = Date.now();
114342
- const pushInstance = await createPushInstance();
114583
+ const pushInstance = await createPushInstance({
114584
+ requiresConsoleAuth: true,
114585
+ organizationId: localConfig.getProject().organizationId
114586
+ });
114343
114587
  const result = await pushInstance.pushSites(
114344
114588
  withResolvedResourcePaths("sites", sites),
114345
114589
  {
@@ -114394,7 +114638,7 @@ var pushSite = async ({
114394
114638
  }
114395
114639
  if (cliConfig.verbose) {
114396
114640
  errors.forEach((e) => {
114397
- console.error(e);
114641
+ console.error(formatErrorForLog(e));
114398
114642
  });
114399
114643
  }
114400
114644
  };
@@ -114477,7 +114721,10 @@ var pushFunction = async ({
114477
114721
  }
114478
114722
  log("Pushing functions ...");
114479
114723
  const pushStartTime = Date.now();
114480
- const pushInstance = await createPushInstance();
114724
+ const pushInstance = await createPushInstance({
114725
+ requiresConsoleAuth: true,
114726
+ organizationId: localConfig.getProject().organizationId
114727
+ });
114481
114728
  const result = await pushInstance.pushFunctions(
114482
114729
  withResolvedResourcePaths("functions", functions),
114483
114730
  {
@@ -114532,7 +114779,7 @@ var pushFunction = async ({
114532
114779
  }
114533
114780
  if (cliConfig.verbose) {
114534
114781
  errors.forEach((e) => {
114535
- console.error(e);
114782
+ console.error(formatErrorForLog(e));
114536
114783
  });
114537
114784
  }
114538
114785
  };
@@ -114677,7 +114924,7 @@ var pushTable = async ({
114677
114924
  success2(`Successfully pushed ${successfullyPushed} tables.`);
114678
114925
  }
114679
114926
  if (cliConfig.verbose) {
114680
- errors.forEach((e) => console.error(e));
114927
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114681
114928
  }
114682
114929
  };
114683
114930
  var pushCollection = async () => {
@@ -114741,7 +114988,7 @@ var pushCollection = async () => {
114741
114988
  success2(`Successfully pushed ${successfullyPushed} collections.`);
114742
114989
  }
114743
114990
  if (cliConfig.verbose) {
114744
- errors.forEach((e) => console.error(e));
114991
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114745
114992
  }
114746
114993
  };
114747
114994
  var pushBucket = async () => {
@@ -114791,7 +115038,7 @@ var pushBucket = async () => {
114791
115038
  success2(`Successfully pushed ${successfullyPushed} buckets.`);
114792
115039
  }
114793
115040
  if (cliConfig.verbose) {
114794
- errors.forEach((e) => console.error(e));
115041
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114795
115042
  }
114796
115043
  };
114797
115044
  var pushTeam = async () => {
@@ -114841,7 +115088,7 @@ var pushTeam = async () => {
114841
115088
  success2(`Successfully pushed ${successfullyPushed} teams.`);
114842
115089
  }
114843
115090
  if (cliConfig.verbose) {
114844
- errors.forEach((e) => console.error(e));
115091
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114845
115092
  }
114846
115093
  };
114847
115094
  var pushWebhook = async () => {
@@ -114891,7 +115138,7 @@ var pushWebhook = async () => {
114891
115138
  success2(`Successfully pushed ${successfullyPushed} webhooks.`);
114892
115139
  }
114893
115140
  if (cliConfig.verbose) {
114894
- errors.forEach((e) => console.error(e));
115141
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114895
115142
  }
114896
115143
  };
114897
115144
  var pushMessagingTopic = async () => {
@@ -114941,7 +115188,7 @@ var pushMessagingTopic = async () => {
114941
115188
  success2(`Successfully pushed ${successfullyPushed} topics.`);
114942
115189
  }
114943
115190
  if (cliConfig.verbose) {
114944
- errors.forEach((e) => console.error(e));
115191
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114945
115192
  }
114946
115193
  };
114947
115194
  var push = new Command("push").description(commandDescriptions["push"]).action(actionRunner(() => pushResources({ skipDeprecated: true })));