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.js CHANGED
@@ -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.3.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);
@@ -103697,6 +103700,7 @@ var siteRequiresBuildCommand = (site) => {
103697
103700
  };
103698
103701
  var WINDOWS_EXECUTABLE_NAME = `${EXECUTABLE_NAME.toLowerCase()}.exe`;
103699
103702
  var CLOUD_REGION_CODES = /* @__PURE__ */ new Set(["fra", "nyc", "syd", "sfo", "sgp", "tor"]);
103703
+ var CLOUD_LOGIN_ENVIRONMENTS = /* @__PURE__ */ new Set(["stage"]);
103700
103704
  var isCloudHostname = (hostname3) => {
103701
103705
  if (hostname3 === "cloud.appwrite.io") {
103702
103706
  return true;
@@ -103706,11 +103710,44 @@ var isCloudHostname = (hostname3) => {
103706
103710
  }
103707
103711
  return CLOUD_REGION_CODES.has(hostname3.split(".")[0]);
103708
103712
  };
103713
+ var getCloudEndpointRegion = (endpoint) => {
103714
+ try {
103715
+ const hostname3 = new URL(endpoint).hostname;
103716
+ if (!isCloudHostname(hostname3) || hostname3 === "cloud.appwrite.io") {
103717
+ return null;
103718
+ }
103719
+ const region = hostname3.split(".")[0];
103720
+ return CLOUD_REGION_CODES.has(region) ? region : null;
103721
+ } catch (_error) {
103722
+ return null;
103723
+ }
103724
+ };
103725
+ var getCloudConsoleHostname = (hostname3) => {
103726
+ if (hostname3 === "cloud.appwrite.io") {
103727
+ return hostname3;
103728
+ }
103729
+ const labels = hostname3.split(".");
103730
+ if (labels.length < 4 || labels.slice(-3).join(".") !== "cloud.appwrite.io") {
103731
+ return null;
103732
+ }
103733
+ if (CLOUD_REGION_CODES.has(labels[0])) {
103734
+ const environment = labels[1];
103735
+ if (environment && CLOUD_LOGIN_ENVIRONMENTS.has(environment)) {
103736
+ return `${environment}.cloud.appwrite.io`;
103737
+ }
103738
+ return "cloud.appwrite.io";
103739
+ }
103740
+ if (CLOUD_LOGIN_ENVIRONMENTS.has(labels[0])) {
103741
+ return hostname3;
103742
+ }
103743
+ return null;
103744
+ };
103709
103745
  var getConsoleBaseUrl = (endpoint) => {
103710
103746
  try {
103711
103747
  const url2 = new URL(endpoint);
103712
- if (isCloudHostname(url2.hostname)) {
103713
- url2.hostname = "cloud.appwrite.io";
103748
+ const consoleHostname = getCloudConsoleHostname(url2.hostname);
103749
+ if (consoleHostname) {
103750
+ url2.hostname = consoleHostname;
103714
103751
  }
103715
103752
  url2.pathname = url2.pathname.replace(/\/v1\/?$/, "");
103716
103753
  url2.search = "";
@@ -104196,10 +104233,7 @@ var Config = class {
104196
104233
  }
104197
104234
  _addDBEntity(entityType, props, keysSet, nestedKeys = {}) {
104198
104235
  props = whitelistKeys(props, keysSet, nestedKeys);
104199
- if (!this.has(entityType)) {
104200
- this.set(entityType, []);
104201
- }
104202
- const entities = this.get(entityType);
104236
+ const entities = this.has(entityType) ? [...this.get(entityType) ?? []] : [];
104203
104237
  for (let i = 0; i < entities.length; i++) {
104204
104238
  if (entities[i]["$id"] == props["$id"]) {
104205
104239
  entities[i] = props;
@@ -104891,7 +104925,7 @@ var package_default = {
104891
104925
  type: "module",
104892
104926
  homepage: "https://appwrite.io/support",
104893
104927
  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",
104928
+ version: "22.3.0",
104895
104929
  license: "BSD-3-Clause",
104896
104930
  main: "dist/index.cjs",
104897
104931
  module: "dist/index.js",
@@ -105890,6 +105924,28 @@ var printQueryErrorHint = (err) => {
105890
105924
  `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
105925
  );
105892
105926
  };
105927
+ var ERROR_DETAIL_KEYS = ["code", "type", "response"];
105928
+ var formatErrorForLog = (err) => {
105929
+ const stack = err.stack || `${err.name}: ${err.message}`;
105930
+ const detailLines = ERROR_DETAIL_KEYS.flatMap((key) => {
105931
+ if (!Object.prototype.hasOwnProperty.call(err, key)) {
105932
+ return [];
105933
+ }
105934
+ const value = err[key];
105935
+ let detail = "undefined";
105936
+ try {
105937
+ detail = typeof value === "string" ? JSON.stringify(value) : JSON.stringify(value) ?? String(value);
105938
+ } catch {
105939
+ detail = String(value);
105940
+ }
105941
+ return [`${key}: ${detail}`];
105942
+ });
105943
+ if (detailLines.length === 0) {
105944
+ return stack;
105945
+ }
105946
+ const [summary, ...frames] = stack.split("\n");
105947
+ return [summary, ...detailLines, ...frames].join("\n");
105948
+ };
105893
105949
  var parseError = (err) => {
105894
105950
  if (cliConfig.report) {
105895
105951
  void (async () => {
@@ -105940,12 +105996,12 @@ ${stack}`
105940
105996
  );
105941
105997
  printQueryErrorHint(err);
105942
105998
  error51("\n Stack Trace: \n");
105943
- console.error(err);
105999
+ console.error(formatErrorForLog(err));
105944
106000
  process.exit(1);
105945
106001
  })();
105946
106002
  } else {
105947
106003
  if (cliConfig.verbose) {
105948
- console.error(err);
106004
+ console.error(formatErrorForLog(err));
105949
106005
  printQueryErrorHint(err);
105950
106006
  } else {
105951
106007
  log("For detailed error pass the --verbose or --report flag");
@@ -109581,12 +109637,12 @@ var deleteStoredRefreshToken = (sessionId) => {
109581
109637
  };
109582
109638
 
109583
109639
  // lib/sdks.ts
109584
- var getValidAccessToken = async (endpoint) => {
109640
+ var getValidAccessToken = async (endpoint, options = {}) => {
109585
109641
  const accessToken = globalConfig2.getAccessToken();
109586
109642
  const tokenExpiry = globalConfig2.getTokenExpiry();
109587
109643
  const clientId = globalConfig2.getClientId() || OAUTH2_CLIENT_ID;
109588
109644
  const currentSession = globalConfig2.getCurrentSession();
109589
- if (accessToken && tokenExpiry > Date.now() + 6e4) {
109645
+ if (!options.forceRefresh && accessToken && tokenExpiry > Date.now() + 6e4) {
109590
109646
  return accessToken;
109591
109647
  }
109592
109648
  const refreshToken = currentSession ? getStoredRefreshToken(currentSession) : "";
@@ -112266,6 +112322,44 @@ function createDeploymentLogsController(enabled) {
112266
112322
  close: cleanup
112267
112323
  };
112268
112324
  }
112325
+ var getPushErrorMessage = (error52) => {
112326
+ if (error52 instanceof Error) {
112327
+ return error52.message;
112328
+ }
112329
+ if (typeof error52 === "object" && error52 !== null && "message" in error52 && typeof error52.message === "string") {
112330
+ return error52.message;
112331
+ }
112332
+ return String(error52);
112333
+ };
112334
+ var getPushResultErrors = (result) => {
112335
+ if (typeof result !== "object" || result === null) {
112336
+ return [];
112337
+ }
112338
+ if ("errors" in result && Array.isArray(result.errors) && result.errors.length > 0) {
112339
+ return result.errors.map(getPushErrorMessage).filter((message) => message.trim() !== "");
112340
+ }
112341
+ if ("error" in result && typeof result.error === "string" && result.error.trim() !== "") {
112342
+ return [result.error];
112343
+ }
112344
+ return [];
112345
+ };
112346
+ var formatPushResourceErrors = (results) => {
112347
+ const failed = Object.entries(results).map(([resourceGroup, result]) => ({
112348
+ resourceGroup,
112349
+ messages: getPushResultErrors(result)
112350
+ })).filter(({ messages }) => messages.length > 0);
112351
+ if (failed.length === 0) {
112352
+ return "Failed to push resource groups.";
112353
+ }
112354
+ return [
112355
+ `Failed to push ${failed.length} resource group${failed.length === 1 ? "" : "s"}:`,
112356
+ ...failed.flatMap(({ resourceGroup, messages }) => [
112357
+ `- ${resourceGroup}:`,
112358
+ ...messages.map((message) => ` - ${message}`)
112359
+ ])
112360
+ ].join("\n");
112361
+ };
112362
+ var nullablePolicyTotal = (value) => value === null || Number(value) === 0 ? null : Number(value);
112269
112363
  var normalizeIgnoreRules = (value) => {
112270
112364
  if (Array.isArray(value)) {
112271
112365
  return value.filter(
@@ -112311,6 +112405,53 @@ var Push = class {
112311
112405
  warn(message);
112312
112406
  }
112313
112407
  }
112408
+ getFunctionRuleDomain(domain2) {
112409
+ const region = getCloudEndpointRegion(this.projectClient.config.endpoint);
112410
+ if (!region) {
112411
+ return domain2;
112412
+ }
112413
+ const parts = domain2.split(".");
112414
+ if (parts.length < 3) {
112415
+ return domain2;
112416
+ }
112417
+ parts[0] = region;
112418
+ return parts.join(".");
112419
+ }
112420
+ async createDefaultFunctionRule(functionId) {
112421
+ let domain2 = "";
112422
+ try {
112423
+ const consoleService = await getConsoleService(this.consoleClient);
112424
+ const variables = await consoleService.variables();
112425
+ const domains = variables["_APP_DOMAIN_FUNCTIONS"].split(",").map((value) => value.trim()).filter((value) => value.length > 0);
112426
+ if (domains.length === 0) {
112427
+ throw new Error("_APP_DOMAIN_FUNCTIONS is not configured.");
112428
+ }
112429
+ domain2 = id_default.unique() + "." + this.getFunctionRuleDomain(domains[0]);
112430
+ } catch (err) {
112431
+ this.error("Error fetching console variables.");
112432
+ throw err;
112433
+ }
112434
+ try {
112435
+ const proxyService = await getProxyService(this.projectClient);
112436
+ this.log(`Creating function proxy rule for ${domain2} ...`);
112437
+ await proxyService.createFunctionRule(domain2, functionId);
112438
+ } catch (err) {
112439
+ this.error("Error creating function rule.");
112440
+ throw err;
112441
+ }
112442
+ }
112443
+ async hasDefaultFunctionRule(functionId) {
112444
+ const proxyService = await getProxyService(this.projectClient);
112445
+ const { rules } = await proxyService.listRules({
112446
+ queries: [
112447
+ Query.limit(1),
112448
+ Query.equal("deploymentResourceType", "function"),
112449
+ Query.equal("deploymentResourceId", functionId),
112450
+ Query.equal("trigger", "manual")
112451
+ ]
112452
+ });
112453
+ return rules.length > 0;
112454
+ }
112314
112455
  /**
112315
112456
  * Log an error message (respects silent mode)
112316
112457
  */
@@ -112374,7 +112515,11 @@ var Push = class {
112374
112515
  results.settings = { success: true };
112375
112516
  } catch (e) {
112376
112517
  allErrors.push(e);
112377
- results.settings = { success: false, error: e.message };
112518
+ results.settings = {
112519
+ success: false,
112520
+ error: getPushErrorMessage(e),
112521
+ errors: [e]
112522
+ };
112378
112523
  }
112379
112524
  }
112380
112525
  if ((shouldPushAll || options.buckets) && config2.buckets && config2.buckets.length > 0) {
@@ -112457,10 +112602,28 @@ var Push = class {
112457
112602
  }
112458
112603
  if ((shouldPushAll || options.sites) && config2.sites && config2.sites.length > 0) {
112459
112604
  try {
112605
+ let siteOptions = options.siteOptions;
112606
+ if (siteOptions?.code === void 0) {
112607
+ let allowSitesCodePush = cliConfig.force === true ? true : null;
112608
+ if (allowSitesCodePush === null) {
112609
+ const codeAnswer = await import_inquirer3.default.prompt(questionsPushSitesCode);
112610
+ allowSitesCodePush = codeAnswer.override;
112611
+ }
112612
+ siteOptions = {
112613
+ ...siteOptions,
112614
+ code: allowSitesCodePush === true
112615
+ };
112616
+ }
112617
+ if (siteOptions.code === true && siteOptions.activate === void 0) {
112618
+ siteOptions = {
112619
+ ...siteOptions,
112620
+ activate: cliConfig.force === true ? true : (await import_inquirer3.default.prompt(questionsPushSitesActivate)).activate
112621
+ };
112622
+ }
112460
112623
  this.log("Pushing sites ...");
112461
112624
  const result = await this.pushSites(
112462
112625
  config2.sites,
112463
- options.siteOptions
112626
+ siteOptions
112464
112627
  );
112465
112628
  this.success(
112466
112629
  `Successfully pushed ${import_chalk9.default.bold(result.successfullyPushed)} sites.`
@@ -112479,6 +112642,12 @@ var Push = class {
112479
112642
  }
112480
112643
  if ((shouldPushAll || options.tables) && config2.tables && config2.tables.length > 0) {
112481
112644
  try {
112645
+ const { resyncNeeded } = await checkAndApplyTablesDBChanges();
112646
+ if (resyncNeeded) {
112647
+ throw new Error(
112648
+ "Configuration changed after applying tablesDB deletions. Re-run the push command to continue."
112649
+ );
112650
+ }
112482
112651
  this.log("Pushing tables ...");
112483
112652
  const result = await this.pushTables(config2.tables, {
112484
112653
  attempts: options.tableOptions?.attempts,
@@ -112550,46 +112719,80 @@ var Push = class {
112550
112719
  }
112551
112720
  if (settings.services) {
112552
112721
  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
- }
112722
+ await Promise.all(
112723
+ Object.entries(settings.services).map(
112724
+ ([service, status]) => projectService.updateService({
112725
+ serviceId: service,
112726
+ enabled: status
112727
+ })
112728
+ )
112729
+ );
112559
112730
  }
112560
112731
  if (settings.protocols) {
112561
112732
  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
- }
112733
+ await Promise.all(
112734
+ Object.entries(settings.protocols).map(
112735
+ ([protocol, status]) => projectService.updateProtocol({
112736
+ protocolId: protocol,
112737
+ enabled: status
112738
+ })
112739
+ )
112740
+ );
112568
112741
  }
112569
112742
  if (settings.auth) {
112570
112743
  if (settings.auth.security) {
112571
112744
  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
- });
112745
+ const securityUpdates = [];
112746
+ if (settings.auth.security.duration !== void 0) {
112747
+ securityUpdates.push(
112748
+ projectService.updateSessionDurationPolicy({
112749
+ duration: Number(settings.auth.security.duration)
112750
+ })
112751
+ );
112752
+ }
112753
+ if (settings.auth.security.limit !== void 0) {
112754
+ securityUpdates.push(
112755
+ projectService.updateUserLimitPolicy({
112756
+ total: nullablePolicyTotal(settings.auth.security.limit)
112757
+ })
112758
+ );
112759
+ }
112760
+ if (settings.auth.security.sessionsLimit !== void 0) {
112761
+ securityUpdates.push(
112762
+ projectService.updateSessionLimitPolicy({
112763
+ total: nullablePolicyTotal(settings.auth.security.sessionsLimit)
112764
+ })
112765
+ );
112766
+ }
112767
+ if (settings.auth.security.passwordDictionary !== void 0) {
112768
+ securityUpdates.push(
112769
+ projectService.updatePasswordDictionaryPolicy({
112770
+ enabled: settings.auth.security.passwordDictionary
112771
+ })
112772
+ );
112773
+ }
112774
+ if (settings.auth.security.passwordHistory !== void 0) {
112775
+ securityUpdates.push(
112776
+ projectService.updatePasswordHistoryPolicy({
112777
+ total: nullablePolicyTotal(settings.auth.security.passwordHistory)
112778
+ })
112779
+ );
112780
+ }
112781
+ if (settings.auth.security.personalDataCheck !== void 0) {
112782
+ securityUpdates.push(
112783
+ projectService.updatePasswordPersonalDataPolicy({
112784
+ enabled: settings.auth.security.personalDataCheck
112785
+ })
112786
+ );
112787
+ }
112788
+ if (settings.auth.security.sessionAlerts !== void 0) {
112789
+ securityUpdates.push(
112790
+ projectService.updateSessionAlertPolicy({
112791
+ enabled: settings.auth.security.sessionAlerts
112792
+ })
112793
+ );
112794
+ }
112795
+ await Promise.all(securityUpdates);
112593
112796
  if (settings.auth.security.mockNumbers !== void 0) {
112594
112797
  const remoteMockNumbers = [];
112595
112798
  const limit = 100;
@@ -112612,40 +112815,50 @@ var Push = class {
112612
112815
  mockNumber.otp
112613
112816
  ])
112614
112817
  );
112818
+ const mockNumberUpdates = [];
112615
112819
  for (const remoteMockNumber of remoteMockNumbers) {
112616
112820
  const desiredOtp = desiredMockNumbersByPhone.get(
112617
112821
  remoteMockNumber.number
112618
112822
  );
112619
112823
  if (desiredOtp === void 0) {
112620
- await projectService.deleteMockPhone({
112621
- number: remoteMockNumber.number
112622
- });
112824
+ mockNumberUpdates.push(
112825
+ projectService.deleteMockPhone({
112826
+ number: remoteMockNumber.number
112827
+ })
112828
+ );
112623
112829
  continue;
112624
112830
  }
112625
112831
  if (remoteMockNumber.otp !== desiredOtp) {
112626
- await projectService.updateMockPhone({
112627
- number: remoteMockNumber.number,
112628
- otp: desiredOtp
112629
- });
112832
+ mockNumberUpdates.push(
112833
+ projectService.updateMockPhone({
112834
+ number: remoteMockNumber.number,
112835
+ otp: desiredOtp
112836
+ })
112837
+ );
112630
112838
  }
112631
112839
  desiredMockNumbersByPhone.delete(remoteMockNumber.number);
112632
112840
  }
112633
112841
  for (const [phone, otp] of desiredMockNumbersByPhone) {
112634
- await projectService.createMockPhone({
112635
- number: phone,
112636
- otp
112637
- });
112842
+ mockNumberUpdates.push(
112843
+ projectService.createMockPhone({
112844
+ number: phone,
112845
+ otp
112846
+ })
112847
+ );
112638
112848
  }
112849
+ await Promise.all(mockNumberUpdates);
112639
112850
  }
112640
112851
  }
112641
112852
  if (settings.auth.methods) {
112642
112853
  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
- }
112854
+ await Promise.all(
112855
+ Object.entries(settings.auth.methods).map(
112856
+ ([method, status]) => projectService.updateAuthMethod({
112857
+ methodId: method,
112858
+ enabled: status
112859
+ })
112860
+ )
112861
+ );
112649
112862
  }
112650
112863
  }
112651
112864
  }
@@ -112936,24 +113149,7 @@ var Push = class {
112936
113149
  runtimeSpecification: func.runtimeSpecification,
112937
113150
  deploymentRetention: func.deploymentRetention
112938
113151
  });
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
- }
113152
+ await this.createDefaultFunctionRule(func.$id);
112957
113153
  updaterRow.update({ status: "Created" });
112958
113154
  } catch (e) {
112959
113155
  errors.push(e);
@@ -112962,6 +113158,18 @@ var Push = class {
112962
113158
  });
112963
113159
  return;
112964
113160
  }
113161
+ } else {
113162
+ try {
113163
+ if (!await this.hasDefaultFunctionRule(func.$id)) {
113164
+ await this.createDefaultFunctionRule(func.$id);
113165
+ }
113166
+ } catch (e) {
113167
+ errors.push(e);
113168
+ updaterRow.fail({
113169
+ errorMessage: e.message ?? "General error occurs please try again"
113170
+ });
113171
+ return;
113172
+ }
112965
113173
  }
112966
113174
  if (withVariables) {
112967
113175
  updaterRow.update({ status: "Updating variables" }).replaceSpinner(SPINNER_DOTS);
@@ -114063,10 +114271,11 @@ async function createPushInstance(options = {
114063
114271
  silent: false,
114064
114272
  requiresConsoleAuth: false
114065
114273
  }) {
114066
- const { silent, requiresConsoleAuth } = options;
114274
+ const { silent, requiresConsoleAuth, organizationId } = options;
114067
114275
  const projectClient = await sdkForProject();
114068
114276
  const consoleClient = await sdkForConsole({
114069
- requiresAuth: requiresConsoleAuth
114277
+ requiresAuth: requiresConsoleAuth,
114278
+ organizationId
114070
114279
  });
114071
114280
  return new Push(projectClient, consoleClient, silent);
114072
114281
  }
@@ -114097,20 +114306,11 @@ var pushResources = async ({
114097
114306
  activateFunctionsDeployment = activateAnswer.activate;
114098
114307
  }
114099
114308
  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
- }
114309
+ const project = localConfig.getProject();
114110
114310
  const pushInstance = await createPushInstance({
114111
- requiresConsoleAuth: true
114311
+ requiresConsoleAuth: true,
114312
+ organizationId: project.organizationId
114112
114313
  });
114113
- const project = localConfig.getProject();
114114
114314
  const config2 = {
114115
114315
  organizationId: project.organizationId,
114116
114316
  projectId: project.projectId ?? "",
@@ -114133,7 +114333,7 @@ var pushResources = async ({
114133
114333
  "Configuration validation failed",
114134
114334
  config2
114135
114335
  );
114136
- await pushInstance.pushResources(config2, {
114336
+ const result = await pushInstance.pushResources(config2, {
114137
114337
  all: cliConfig.all,
114138
114338
  skipDeprecated,
114139
114339
  functionOptions: {
@@ -114143,12 +114343,13 @@ var pushResources = async ({
114143
114343
  logs: functionOptions?.logs
114144
114344
  },
114145
114345
  siteOptions: {
114146
- code: allowSitesCodePush === true,
114147
- activate: activateSitesDeployment ?? true,
114148
114346
  withVariables: false,
114149
114347
  logs: siteOptions?.logs
114150
114348
  }
114151
114349
  });
114350
+ if (result.errors.length > 0) {
114351
+ throw new Error(formatPushResourceErrors(result.results));
114352
+ }
114152
114353
  } else {
114153
114354
  const actions = {
114154
114355
  settings: pushSettings,
@@ -114227,10 +114428,11 @@ var pushSettings = async () => {
114227
114428
  }
114228
114429
  try {
114229
114430
  log("Pushing project settings ...");
114431
+ const config2 = localConfig.getProject();
114230
114432
  const pushInstance = await createPushInstance({
114231
- requiresConsoleAuth: true
114433
+ requiresConsoleAuth: true,
114434
+ organizationId: config2.organizationId ?? resolvedOrganizationId
114232
114435
  });
114233
- const config2 = localConfig.getProject();
114234
114436
  await pushInstance.pushSettings({
114235
114437
  projectId: config2.projectId,
114236
114438
  organizationId: config2.organizationId ?? resolvedOrganizationId,
@@ -114319,7 +114521,10 @@ var pushSite = async ({
114319
114521
  }
114320
114522
  log("Pushing sites ...");
114321
114523
  const pushStartTime = Date.now();
114322
- const pushInstance = await createPushInstance();
114524
+ const pushInstance = await createPushInstance({
114525
+ requiresConsoleAuth: true,
114526
+ organizationId: localConfig.getProject().organizationId
114527
+ });
114323
114528
  const result = await pushInstance.pushSites(
114324
114529
  withResolvedResourcePaths("sites", sites),
114325
114530
  {
@@ -114374,7 +114579,7 @@ var pushSite = async ({
114374
114579
  }
114375
114580
  if (cliConfig.verbose) {
114376
114581
  errors.forEach((e) => {
114377
- console.error(e);
114582
+ console.error(formatErrorForLog(e));
114378
114583
  });
114379
114584
  }
114380
114585
  };
@@ -114457,7 +114662,10 @@ var pushFunction = async ({
114457
114662
  }
114458
114663
  log("Pushing functions ...");
114459
114664
  const pushStartTime = Date.now();
114460
- const pushInstance = await createPushInstance();
114665
+ const pushInstance = await createPushInstance({
114666
+ requiresConsoleAuth: true,
114667
+ organizationId: localConfig.getProject().organizationId
114668
+ });
114461
114669
  const result = await pushInstance.pushFunctions(
114462
114670
  withResolvedResourcePaths("functions", functions),
114463
114671
  {
@@ -114512,7 +114720,7 @@ var pushFunction = async ({
114512
114720
  }
114513
114721
  if (cliConfig.verbose) {
114514
114722
  errors.forEach((e) => {
114515
- console.error(e);
114723
+ console.error(formatErrorForLog(e));
114516
114724
  });
114517
114725
  }
114518
114726
  };
@@ -114657,7 +114865,7 @@ var pushTable = async ({
114657
114865
  success2(`Successfully pushed ${successfullyPushed} tables.`);
114658
114866
  }
114659
114867
  if (cliConfig.verbose) {
114660
- errors.forEach((e) => console.error(e));
114868
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114661
114869
  }
114662
114870
  };
114663
114871
  var pushCollection = async () => {
@@ -114721,7 +114929,7 @@ var pushCollection = async () => {
114721
114929
  success2(`Successfully pushed ${successfullyPushed} collections.`);
114722
114930
  }
114723
114931
  if (cliConfig.verbose) {
114724
- errors.forEach((e) => console.error(e));
114932
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114725
114933
  }
114726
114934
  };
114727
114935
  var pushBucket = async () => {
@@ -114771,7 +114979,7 @@ var pushBucket = async () => {
114771
114979
  success2(`Successfully pushed ${successfullyPushed} buckets.`);
114772
114980
  }
114773
114981
  if (cliConfig.verbose) {
114774
- errors.forEach((e) => console.error(e));
114982
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114775
114983
  }
114776
114984
  };
114777
114985
  var pushTeam = async () => {
@@ -114821,7 +115029,7 @@ var pushTeam = async () => {
114821
115029
  success2(`Successfully pushed ${successfullyPushed} teams.`);
114822
115030
  }
114823
115031
  if (cliConfig.verbose) {
114824
- errors.forEach((e) => console.error(e));
115032
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114825
115033
  }
114826
115034
  };
114827
115035
  var pushWebhook = async () => {
@@ -114871,7 +115079,7 @@ var pushWebhook = async () => {
114871
115079
  success2(`Successfully pushed ${successfullyPushed} webhooks.`);
114872
115080
  }
114873
115081
  if (cliConfig.verbose) {
114874
- errors.forEach((e) => console.error(e));
115082
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114875
115083
  }
114876
115084
  };
114877
115085
  var pushMessagingTopic = async () => {
@@ -114921,7 +115129,7 @@ var pushMessagingTopic = async () => {
114921
115129
  success2(`Successfully pushed ${successfullyPushed} topics.`);
114922
115130
  }
114923
115131
  if (cliConfig.verbose) {
114924
- errors.forEach((e) => console.error(e));
115132
+ errors.forEach((e) => console.error(formatErrorForLog(e)));
114925
115133
  }
114926
115134
  };
114927
115135
  var push = new Command("push").description(commandDescriptions["push"]).action(actionRunner(() => pushResources({ skipDeprecated: true })));