appwrite-cli 22.2.2 → 22.3.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
@@ -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.3.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);
@@ -103717,6 +103720,7 @@ var siteRequiresBuildCommand = (site) => {
103717
103720
  };
103718
103721
  var WINDOWS_EXECUTABLE_NAME = `${EXECUTABLE_NAME.toLowerCase()}.exe`;
103719
103722
  var CLOUD_REGION_CODES = /* @__PURE__ */ new Set(["fra", "nyc", "syd", "sfo", "sgp", "tor"]);
103723
+ var CLOUD_LOGIN_ENVIRONMENTS = /* @__PURE__ */ new Set(["stage"]);
103720
103724
  var isCloudHostname = (hostname3) => {
103721
103725
  if (hostname3 === "cloud.appwrite.io") {
103722
103726
  return true;
@@ -103726,11 +103730,44 @@ var isCloudHostname = (hostname3) => {
103726
103730
  }
103727
103731
  return CLOUD_REGION_CODES.has(hostname3.split(".")[0]);
103728
103732
  };
103733
+ var getCloudEndpointRegion = (endpoint) => {
103734
+ try {
103735
+ const hostname3 = new URL(endpoint).hostname;
103736
+ if (!isCloudHostname(hostname3) || hostname3 === "cloud.appwrite.io") {
103737
+ return null;
103738
+ }
103739
+ const region = hostname3.split(".")[0];
103740
+ return CLOUD_REGION_CODES.has(region) ? region : null;
103741
+ } catch (_error) {
103742
+ return null;
103743
+ }
103744
+ };
103745
+ var getCloudConsoleHostname = (hostname3) => {
103746
+ if (hostname3 === "cloud.appwrite.io") {
103747
+ return hostname3;
103748
+ }
103749
+ const labels = hostname3.split(".");
103750
+ if (labels.length < 4 || labels.slice(-3).join(".") !== "cloud.appwrite.io") {
103751
+ return null;
103752
+ }
103753
+ if (CLOUD_REGION_CODES.has(labels[0])) {
103754
+ const environment = labels[1];
103755
+ if (environment && CLOUD_LOGIN_ENVIRONMENTS.has(environment)) {
103756
+ return `${environment}.cloud.appwrite.io`;
103757
+ }
103758
+ return "cloud.appwrite.io";
103759
+ }
103760
+ if (CLOUD_LOGIN_ENVIRONMENTS.has(labels[0])) {
103761
+ return hostname3;
103762
+ }
103763
+ return null;
103764
+ };
103729
103765
  var getConsoleBaseUrl = (endpoint) => {
103730
103766
  try {
103731
103767
  const url2 = new URL(endpoint);
103732
- if (isCloudHostname(url2.hostname)) {
103733
- url2.hostname = "cloud.appwrite.io";
103768
+ const consoleHostname = getCloudConsoleHostname(url2.hostname);
103769
+ if (consoleHostname) {
103770
+ url2.hostname = consoleHostname;
103734
103771
  }
103735
103772
  url2.pathname = url2.pathname.replace(/\/v1\/?$/, "");
103736
103773
  url2.search = "";
@@ -104216,10 +104253,7 @@ var Config = class {
104216
104253
  }
104217
104254
  _addDBEntity(entityType, props, keysSet, nestedKeys = {}) {
104218
104255
  props = whitelistKeys(props, keysSet, nestedKeys);
104219
- if (!this.has(entityType)) {
104220
- this.set(entityType, []);
104221
- }
104222
- const entities = this.get(entityType);
104256
+ const entities = this.has(entityType) ? [...this.get(entityType) ?? []] : [];
104223
104257
  for (let i = 0; i < entities.length; i++) {
104224
104258
  if (entities[i]["$id"] == props["$id"]) {
104225
104259
  entities[i] = props;
@@ -104911,7 +104945,7 @@ var package_default = {
104911
104945
  type: "module",
104912
104946
  homepage: "https://appwrite.io/support",
104913
104947
  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",
104948
+ version: "22.3.0",
104915
104949
  license: "BSD-3-Clause",
104916
104950
  main: "dist/index.cjs",
104917
104951
  module: "dist/index.js",
@@ -105910,6 +105944,28 @@ var printQueryErrorHint = (err) => {
105910
105944
  `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
105945
  );
105912
105946
  };
105947
+ var ERROR_DETAIL_KEYS = ["code", "type", "response"];
105948
+ var formatErrorForLog = (err) => {
105949
+ const stack = err.stack || `${err.name}: ${err.message}`;
105950
+ const detailLines = ERROR_DETAIL_KEYS.flatMap((key) => {
105951
+ if (!Object.prototype.hasOwnProperty.call(err, key)) {
105952
+ return [];
105953
+ }
105954
+ const value = err[key];
105955
+ let detail = "undefined";
105956
+ try {
105957
+ detail = typeof value === "string" ? JSON.stringify(value) : JSON.stringify(value) ?? String(value);
105958
+ } catch {
105959
+ detail = String(value);
105960
+ }
105961
+ return [`${key}: ${detail}`];
105962
+ });
105963
+ if (detailLines.length === 0) {
105964
+ return stack;
105965
+ }
105966
+ const [summary, ...frames] = stack.split("\n");
105967
+ return [summary, ...detailLines, ...frames].join("\n");
105968
+ };
105913
105969
  var parseError = (err) => {
105914
105970
  if (cliConfig.report) {
105915
105971
  void (async () => {
@@ -105960,12 +106016,12 @@ ${stack}`
105960
106016
  );
105961
106017
  printQueryErrorHint(err);
105962
106018
  error51("\n Stack Trace: \n");
105963
- console.error(err);
106019
+ console.error(formatErrorForLog(err));
105964
106020
  process.exit(1);
105965
106021
  })();
105966
106022
  } else {
105967
106023
  if (cliConfig.verbose) {
105968
- console.error(err);
106024
+ console.error(formatErrorForLog(err));
105969
106025
  printQueryErrorHint(err);
105970
106026
  } else {
105971
106027
  log("For detailed error pass the --verbose or --report flag");
@@ -109601,12 +109657,12 @@ var deleteStoredRefreshToken = (sessionId) => {
109601
109657
  };
109602
109658
 
109603
109659
  // lib/sdks.ts
109604
- var getValidAccessToken = async (endpoint) => {
109660
+ var getValidAccessToken = async (endpoint, options = {}) => {
109605
109661
  const accessToken = globalConfig2.getAccessToken();
109606
109662
  const tokenExpiry = globalConfig2.getTokenExpiry();
109607
109663
  const clientId = globalConfig2.getClientId() || OAUTH2_CLIENT_ID;
109608
109664
  const currentSession = globalConfig2.getCurrentSession();
109609
- if (accessToken && tokenExpiry > Date.now() + 6e4) {
109665
+ if (!options.forceRefresh && accessToken && tokenExpiry > Date.now() + 6e4) {
109610
109666
  return accessToken;
109611
109667
  }
109612
109668
  const refreshToken = currentSession ? getStoredRefreshToken(currentSession) : "";
@@ -112286,6 +112342,44 @@ function createDeploymentLogsController(enabled) {
112286
112342
  close: cleanup
112287
112343
  };
112288
112344
  }
112345
+ var getPushErrorMessage = (error52) => {
112346
+ if (error52 instanceof Error) {
112347
+ return error52.message;
112348
+ }
112349
+ if (typeof error52 === "object" && error52 !== null && "message" in error52 && typeof error52.message === "string") {
112350
+ return error52.message;
112351
+ }
112352
+ return String(error52);
112353
+ };
112354
+ var getPushResultErrors = (result) => {
112355
+ if (typeof result !== "object" || result === null) {
112356
+ return [];
112357
+ }
112358
+ if ("errors" in result && Array.isArray(result.errors) && result.errors.length > 0) {
112359
+ return result.errors.map(getPushErrorMessage).filter((message) => message.trim() !== "");
112360
+ }
112361
+ if ("error" in result && typeof result.error === "string" && result.error.trim() !== "") {
112362
+ return [result.error];
112363
+ }
112364
+ return [];
112365
+ };
112366
+ var formatPushResourceErrors = (results) => {
112367
+ const failed = Object.entries(results).map(([resourceGroup, result]) => ({
112368
+ resourceGroup,
112369
+ messages: getPushResultErrors(result)
112370
+ })).filter(({ messages }) => messages.length > 0);
112371
+ if (failed.length === 0) {
112372
+ return "Failed to push resource groups.";
112373
+ }
112374
+ return [
112375
+ `Failed to push ${failed.length} resource group${failed.length === 1 ? "" : "s"}:`,
112376
+ ...failed.flatMap(({ resourceGroup, messages }) => [
112377
+ `- ${resourceGroup}:`,
112378
+ ...messages.map((message) => ` - ${message}`)
112379
+ ])
112380
+ ].join("\n");
112381
+ };
112382
+ var nullablePolicyTotal = (value) => value === null || Number(value) === 0 ? null : Number(value);
112289
112383
  var normalizeIgnoreRules = (value) => {
112290
112384
  if (Array.isArray(value)) {
112291
112385
  return value.filter(
@@ -112331,6 +112425,53 @@ var Push = class {
112331
112425
  warn(message);
112332
112426
  }
112333
112427
  }
112428
+ getFunctionRuleDomain(domain2) {
112429
+ const region = getCloudEndpointRegion(this.projectClient.config.endpoint);
112430
+ if (!region) {
112431
+ return domain2;
112432
+ }
112433
+ const parts = domain2.split(".");
112434
+ if (parts.length < 3) {
112435
+ return domain2;
112436
+ }
112437
+ parts[0] = region;
112438
+ return parts.join(".");
112439
+ }
112440
+ async createDefaultFunctionRule(functionId) {
112441
+ let domain2 = "";
112442
+ try {
112443
+ const consoleService = await getConsoleService(this.consoleClient);
112444
+ const variables = await consoleService.variables();
112445
+ const domains = variables["_APP_DOMAIN_FUNCTIONS"].split(",").map((value) => value.trim()).filter((value) => value.length > 0);
112446
+ if (domains.length === 0) {
112447
+ throw new Error("_APP_DOMAIN_FUNCTIONS is not configured.");
112448
+ }
112449
+ domain2 = id_default.unique() + "." + this.getFunctionRuleDomain(domains[0]);
112450
+ } catch (err) {
112451
+ this.error("Error fetching console variables.");
112452
+ throw err;
112453
+ }
112454
+ try {
112455
+ const proxyService = await getProxyService(this.projectClient);
112456
+ this.log(`Creating function proxy rule for ${domain2} ...`);
112457
+ await proxyService.createFunctionRule(domain2, functionId);
112458
+ } catch (err) {
112459
+ this.error("Error creating function rule.");
112460
+ throw err;
112461
+ }
112462
+ }
112463
+ async hasDefaultFunctionRule(functionId) {
112464
+ const proxyService = await getProxyService(this.projectClient);
112465
+ const { rules } = await proxyService.listRules({
112466
+ queries: [
112467
+ Query.limit(1),
112468
+ Query.equal("deploymentResourceType", "function"),
112469
+ Query.equal("deploymentResourceId", functionId),
112470
+ Query.equal("trigger", "manual")
112471
+ ]
112472
+ });
112473
+ return rules.length > 0;
112474
+ }
112334
112475
  /**
112335
112476
  * Log an error message (respects silent mode)
112336
112477
  */
@@ -112394,7 +112535,11 @@ var Push = class {
112394
112535
  results.settings = { success: true };
112395
112536
  } catch (e) {
112396
112537
  allErrors.push(e);
112397
- results.settings = { success: false, error: e.message };
112538
+ results.settings = {
112539
+ success: false,
112540
+ error: getPushErrorMessage(e),
112541
+ errors: [e]
112542
+ };
112398
112543
  }
112399
112544
  }
112400
112545
  if ((shouldPushAll || options.buckets) && config2.buckets && config2.buckets.length > 0) {
@@ -112477,10 +112622,28 @@ var Push = class {
112477
112622
  }
112478
112623
  if ((shouldPushAll || options.sites) && config2.sites && config2.sites.length > 0) {
112479
112624
  try {
112625
+ let siteOptions = options.siteOptions;
112626
+ if (siteOptions?.code === void 0) {
112627
+ let allowSitesCodePush = cliConfig.force === true ? true : null;
112628
+ if (allowSitesCodePush === null) {
112629
+ const codeAnswer = await import_inquirer3.default.prompt(questionsPushSitesCode);
112630
+ allowSitesCodePush = codeAnswer.override;
112631
+ }
112632
+ siteOptions = {
112633
+ ...siteOptions,
112634
+ code: allowSitesCodePush === true
112635
+ };
112636
+ }
112637
+ if (siteOptions.code === true && siteOptions.activate === void 0) {
112638
+ siteOptions = {
112639
+ ...siteOptions,
112640
+ activate: cliConfig.force === true ? true : (await import_inquirer3.default.prompt(questionsPushSitesActivate)).activate
112641
+ };
112642
+ }
112480
112643
  this.log("Pushing sites ...");
112481
112644
  const result = await this.pushSites(
112482
112645
  config2.sites,
112483
- options.siteOptions
112646
+ siteOptions
112484
112647
  );
112485
112648
  this.success(
112486
112649
  `Successfully pushed ${import_chalk9.default.bold(result.successfullyPushed)} sites.`
@@ -112499,6 +112662,12 @@ var Push = class {
112499
112662
  }
112500
112663
  if ((shouldPushAll || options.tables) && config2.tables && config2.tables.length > 0) {
112501
112664
  try {
112665
+ const { resyncNeeded } = await checkAndApplyTablesDBChanges();
112666
+ if (resyncNeeded) {
112667
+ throw new Error(
112668
+ "Configuration changed after applying tablesDB deletions. Re-run the push command to continue."
112669
+ );
112670
+ }
112502
112671
  this.log("Pushing tables ...");
112503
112672
  const result = await this.pushTables(config2.tables, {
112504
112673
  attempts: options.tableOptions?.attempts,
@@ -112570,46 +112739,80 @@ var Push = class {
112570
112739
  }
112571
112740
  if (settings.services) {
112572
112741
  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
- }
112742
+ await Promise.all(
112743
+ Object.entries(settings.services).map(
112744
+ ([service, status]) => projectService.updateService({
112745
+ serviceId: service,
112746
+ enabled: status
112747
+ })
112748
+ )
112749
+ );
112579
112750
  }
112580
112751
  if (settings.protocols) {
112581
112752
  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
- }
112753
+ await Promise.all(
112754
+ Object.entries(settings.protocols).map(
112755
+ ([protocol, status]) => projectService.updateProtocol({
112756
+ protocolId: protocol,
112757
+ enabled: status
112758
+ })
112759
+ )
112760
+ );
112588
112761
  }
112589
112762
  if (settings.auth) {
112590
112763
  if (settings.auth.security) {
112591
112764
  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
- });
112765
+ const securityUpdates = [];
112766
+ if (settings.auth.security.duration !== void 0) {
112767
+ securityUpdates.push(
112768
+ projectService.updateSessionDurationPolicy({
112769
+ duration: Number(settings.auth.security.duration)
112770
+ })
112771
+ );
112772
+ }
112773
+ if (settings.auth.security.limit !== void 0) {
112774
+ securityUpdates.push(
112775
+ projectService.updateUserLimitPolicy({
112776
+ total: nullablePolicyTotal(settings.auth.security.limit)
112777
+ })
112778
+ );
112779
+ }
112780
+ if (settings.auth.security.sessionsLimit !== void 0) {
112781
+ securityUpdates.push(
112782
+ projectService.updateSessionLimitPolicy({
112783
+ total: nullablePolicyTotal(settings.auth.security.sessionsLimit)
112784
+ })
112785
+ );
112786
+ }
112787
+ if (settings.auth.security.passwordDictionary !== void 0) {
112788
+ securityUpdates.push(
112789
+ projectService.updatePasswordDictionaryPolicy({
112790
+ enabled: settings.auth.security.passwordDictionary
112791
+ })
112792
+ );
112793
+ }
112794
+ if (settings.auth.security.passwordHistory !== void 0) {
112795
+ securityUpdates.push(
112796
+ projectService.updatePasswordHistoryPolicy({
112797
+ total: nullablePolicyTotal(settings.auth.security.passwordHistory)
112798
+ })
112799
+ );
112800
+ }
112801
+ if (settings.auth.security.personalDataCheck !== void 0) {
112802
+ securityUpdates.push(
112803
+ projectService.updatePasswordPersonalDataPolicy({
112804
+ enabled: settings.auth.security.personalDataCheck
112805
+ })
112806
+ );
112807
+ }
112808
+ if (settings.auth.security.sessionAlerts !== void 0) {
112809
+ securityUpdates.push(
112810
+ projectService.updateSessionAlertPolicy({
112811
+ enabled: settings.auth.security.sessionAlerts
112812
+ })
112813
+ );
112814
+ }
112815
+ await Promise.all(securityUpdates);
112613
112816
  if (settings.auth.security.mockNumbers !== void 0) {
112614
112817
  const remoteMockNumbers = [];
112615
112818
  const limit = 100;
@@ -112632,40 +112835,50 @@ var Push = class {
112632
112835
  mockNumber.otp
112633
112836
  ])
112634
112837
  );
112838
+ const mockNumberUpdates = [];
112635
112839
  for (const remoteMockNumber of remoteMockNumbers) {
112636
112840
  const desiredOtp = desiredMockNumbersByPhone.get(
112637
112841
  remoteMockNumber.number
112638
112842
  );
112639
112843
  if (desiredOtp === void 0) {
112640
- await projectService.deleteMockPhone({
112641
- number: remoteMockNumber.number
112642
- });
112844
+ mockNumberUpdates.push(
112845
+ projectService.deleteMockPhone({
112846
+ number: remoteMockNumber.number
112847
+ })
112848
+ );
112643
112849
  continue;
112644
112850
  }
112645
112851
  if (remoteMockNumber.otp !== desiredOtp) {
112646
- await projectService.updateMockPhone({
112647
- number: remoteMockNumber.number,
112648
- otp: desiredOtp
112649
- });
112852
+ mockNumberUpdates.push(
112853
+ projectService.updateMockPhone({
112854
+ number: remoteMockNumber.number,
112855
+ otp: desiredOtp
112856
+ })
112857
+ );
112650
112858
  }
112651
112859
  desiredMockNumbersByPhone.delete(remoteMockNumber.number);
112652
112860
  }
112653
112861
  for (const [phone, otp] of desiredMockNumbersByPhone) {
112654
- await projectService.createMockPhone({
112655
- number: phone,
112656
- otp
112657
- });
112862
+ mockNumberUpdates.push(
112863
+ projectService.createMockPhone({
112864
+ number: phone,
112865
+ otp
112866
+ })
112867
+ );
112658
112868
  }
112869
+ await Promise.all(mockNumberUpdates);
112659
112870
  }
112660
112871
  }
112661
112872
  if (settings.auth.methods) {
112662
112873
  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
- }
112874
+ await Promise.all(
112875
+ Object.entries(settings.auth.methods).map(
112876
+ ([method, status]) => projectService.updateAuthMethod({
112877
+ methodId: method,
112878
+ enabled: status
112879
+ })
112880
+ )
112881
+ );
112669
112882
  }
112670
112883
  }
112671
112884
  }
@@ -112956,24 +113169,7 @@ var Push = class {
112956
113169
  runtimeSpecification: func.runtimeSpecification,
112957
113170
  deploymentRetention: func.deploymentRetention
112958
113171
  });
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
- }
113172
+ await this.createDefaultFunctionRule(func.$id);
112977
113173
  updaterRow.update({ status: "Created" });
112978
113174
  } catch (e) {
112979
113175
  errors.push(e);
@@ -112982,6 +113178,18 @@ var Push = class {
112982
113178
  });
112983
113179
  return;
112984
113180
  }
113181
+ } else {
113182
+ try {
113183
+ if (!await this.hasDefaultFunctionRule(func.$id)) {
113184
+ await this.createDefaultFunctionRule(func.$id);
113185
+ }
113186
+ } catch (e) {
113187
+ errors.push(e);
113188
+ updaterRow.fail({
113189
+ errorMessage: e.message ?? "General error occurs please try again"
113190
+ });
113191
+ return;
113192
+ }
112985
113193
  }
112986
113194
  if (withVariables) {
112987
113195
  updaterRow.update({ status: "Updating variables" }).replaceSpinner(SPINNER_DOTS);
@@ -114083,10 +114291,11 @@ async function createPushInstance(options = {
114083
114291
  silent: false,
114084
114292
  requiresConsoleAuth: false
114085
114293
  }) {
114086
- const { silent, requiresConsoleAuth } = options;
114294
+ const { silent, requiresConsoleAuth, organizationId } = options;
114087
114295
  const projectClient = await sdkForProject();
114088
114296
  const consoleClient = await sdkForConsole({
114089
- requiresAuth: requiresConsoleAuth
114297
+ requiresAuth: requiresConsoleAuth,
114298
+ organizationId
114090
114299
  });
114091
114300
  return new Push(projectClient, consoleClient, silent);
114092
114301
  }
@@ -114117,20 +114326,11 @@ var pushResources = async ({
114117
114326
  activateFunctionsDeployment = activateAnswer.activate;
114118
114327
  }
114119
114328
  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
- }
114329
+ const project = localConfig.getProject();
114130
114330
  const pushInstance = await createPushInstance({
114131
- requiresConsoleAuth: true
114331
+ requiresConsoleAuth: true,
114332
+ organizationId: project.organizationId
114132
114333
  });
114133
- const project = localConfig.getProject();
114134
114334
  const config2 = {
114135
114335
  organizationId: project.organizationId,
114136
114336
  projectId: project.projectId ?? "",
@@ -114153,7 +114353,7 @@ var pushResources = async ({
114153
114353
  "Configuration validation failed",
114154
114354
  config2
114155
114355
  );
114156
- await pushInstance.pushResources(config2, {
114356
+ const result = await pushInstance.pushResources(config2, {
114157
114357
  all: cliConfig.all,
114158
114358
  skipDeprecated,
114159
114359
  functionOptions: {
@@ -114163,12 +114363,13 @@ var pushResources = async ({
114163
114363
  logs: functionOptions?.logs
114164
114364
  },
114165
114365
  siteOptions: {
114166
- code: allowSitesCodePush === true,
114167
- activate: activateSitesDeployment ?? true,
114168
114366
  withVariables: false,
114169
114367
  logs: siteOptions?.logs
114170
114368
  }
114171
114369
  });
114370
+ if (result.errors.length > 0) {
114371
+ throw new Error(formatPushResourceErrors(result.results));
114372
+ }
114172
114373
  } else {
114173
114374
  const actions = {
114174
114375
  settings: pushSettings,
@@ -114247,10 +114448,11 @@ var pushSettings = async () => {
114247
114448
  }
114248
114449
  try {
114249
114450
  log("Pushing project settings ...");
114451
+ const config2 = localConfig.getProject();
114250
114452
  const pushInstance = await createPushInstance({
114251
- requiresConsoleAuth: true
114453
+ requiresConsoleAuth: true,
114454
+ organizationId: config2.organizationId ?? resolvedOrganizationId
114252
114455
  });
114253
- const config2 = localConfig.getProject();
114254
114456
  await pushInstance.pushSettings({
114255
114457
  projectId: config2.projectId,
114256
114458
  organizationId: config2.organizationId ?? resolvedOrganizationId,
@@ -114339,7 +114541,10 @@ var pushSite = async ({
114339
114541
  }
114340
114542
  log("Pushing sites ...");
114341
114543
  const pushStartTime = Date.now();
114342
- const pushInstance = await createPushInstance();
114544
+ const pushInstance = await createPushInstance({
114545
+ requiresConsoleAuth: true,
114546
+ organizationId: localConfig.getProject().organizationId
114547
+ });
114343
114548
  const result = await pushInstance.pushSites(
114344
114549
  withResolvedResourcePaths("sites", sites),
114345
114550
  {
@@ -114394,7 +114599,7 @@ var pushSite = async ({
114394
114599
  }
114395
114600
  if (cliConfig.verbose) {
114396
114601
  errors.forEach((e) => {
114397
- console.error(e);
114602
+ console.error(formatErrorForLog(e));
114398
114603
  });
114399
114604
  }
114400
114605
  };
@@ -114477,7 +114682,10 @@ var pushFunction = async ({
114477
114682
  }
114478
114683
  log("Pushing functions ...");
114479
114684
  const pushStartTime = Date.now();
114480
- const pushInstance = await createPushInstance();
114685
+ const pushInstance = await createPushInstance({
114686
+ requiresConsoleAuth: true,
114687
+ organizationId: localConfig.getProject().organizationId
114688
+ });
114481
114689
  const result = await pushInstance.pushFunctions(
114482
114690
  withResolvedResourcePaths("functions", functions),
114483
114691
  {
@@ -114532,7 +114740,7 @@ var pushFunction = async ({
114532
114740
  }
114533
114741
  if (cliConfig.verbose) {
114534
114742
  errors.forEach((e) => {
114535
- console.error(e);
114743
+ console.error(formatErrorForLog(e));
114536
114744
  });
114537
114745
  }
114538
114746
  };
@@ -114677,7 +114885,7 @@ var pushTable = async ({
114677
114885
  success2(`Successfully pushed ${successfullyPushed} tables.`);
114678
114886
  }
114679
114887
  if (cliConfig.verbose) {
114680
- errors.forEach((e) => console.error(e));
114888
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114681
114889
  }
114682
114890
  };
114683
114891
  var pushCollection = async () => {
@@ -114741,7 +114949,7 @@ var pushCollection = async () => {
114741
114949
  success2(`Successfully pushed ${successfullyPushed} collections.`);
114742
114950
  }
114743
114951
  if (cliConfig.verbose) {
114744
- errors.forEach((e) => console.error(e));
114952
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114745
114953
  }
114746
114954
  };
114747
114955
  var pushBucket = async () => {
@@ -114791,7 +114999,7 @@ var pushBucket = async () => {
114791
114999
  success2(`Successfully pushed ${successfullyPushed} buckets.`);
114792
115000
  }
114793
115001
  if (cliConfig.verbose) {
114794
- errors.forEach((e) => console.error(e));
115002
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114795
115003
  }
114796
115004
  };
114797
115005
  var pushTeam = async () => {
@@ -114841,7 +115049,7 @@ var pushTeam = async () => {
114841
115049
  success2(`Successfully pushed ${successfullyPushed} teams.`);
114842
115050
  }
114843
115051
  if (cliConfig.verbose) {
114844
- errors.forEach((e) => console.error(e));
115052
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114845
115053
  }
114846
115054
  };
114847
115055
  var pushWebhook = async () => {
@@ -114891,7 +115099,7 @@ var pushWebhook = async () => {
114891
115099
  success2(`Successfully pushed ${successfullyPushed} webhooks.`);
114892
115100
  }
114893
115101
  if (cliConfig.verbose) {
114894
- errors.forEach((e) => console.error(e));
115102
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114895
115103
  }
114896
115104
  };
114897
115105
  var pushMessagingTopic = async () => {
@@ -114941,7 +115149,7 @@ var pushMessagingTopic = async () => {
114941
115149
  success2(`Successfully pushed ${successfullyPushed} topics.`);
114942
115150
  }
114943
115151
  if (cliConfig.verbose) {
114944
- errors.forEach((e) => console.error(e));
115152
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114945
115153
  }
114946
115154
  };
114947
115155
  var push = new Command("push").description(commandDescriptions["push"]).action(actionRunner(() => pushResources({ skipDeprecated: true })));