@strapi/cloud-cli 4.25.7 → 4.25.9

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
@@ -42,7 +42,6 @@ const ora = require("ora");
42
42
  const cliProgress = require("cli-progress");
43
43
  const pkgUp = require("pkg-up");
44
44
  const yup = require("yup");
45
- const _ = require("lodash");
46
45
  const EventSource = require("eventsource");
47
46
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
48
47
  function _interopNamespace(e) {
@@ -80,7 +79,6 @@ const ora__default = /* @__PURE__ */ _interopDefault(ora);
80
79
  const cliProgress__namespace = /* @__PURE__ */ _interopNamespace(cliProgress);
81
80
  const pkgUp__default = /* @__PURE__ */ _interopDefault(pkgUp);
82
81
  const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
83
- const ___default = /* @__PURE__ */ _interopDefault(_);
84
82
  const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
85
83
  const apiConfig = {
86
84
  apiBaseUrl: utils.env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
@@ -194,7 +192,7 @@ async function saveLocalConfig(data) {
194
192
  await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
195
193
  }
196
194
  const name = "@strapi/cloud-cli";
197
- const version = "4.25.6";
195
+ const version = "4.25.8";
198
196
  const description = "Commands to interact with the Strapi Cloud";
199
197
  const keywords = [
200
198
  "strapi",
@@ -239,8 +237,8 @@ const scripts = {
239
237
  watch: "pack-up watch"
240
238
  };
241
239
  const dependencies = {
242
- "@strapi/utils": "4.25.6",
243
- axios: "1.6.0",
240
+ "@strapi/utils": "4.25.8",
241
+ axios: "1.7.4",
244
242
  chalk: "4.1.2",
245
243
  "cli-progress": "3.12.0",
246
244
  commander: "8.3.0",
@@ -264,8 +262,8 @@ const devDependencies = {
264
262
  "@types/cli-progress": "3.11.5",
265
263
  "@types/eventsource": "1.1.15",
266
264
  "@types/lodash": "^4.14.191",
267
- "eslint-config-custom": "4.25.6",
268
- tsconfig: "4.25.6"
265
+ "eslint-config-custom": "4.25.8",
266
+ tsconfig: "4.25.8"
269
267
  };
270
268
  const engines = {
271
269
  node: ">=18.0.0 <=20.x.x",
@@ -377,7 +375,7 @@ async function cloudApiFactory({ logger }, token) {
377
375
  },
378
376
  async listLinkProjects() {
379
377
  try {
380
- const response = await axiosCloudAPI.get("/projects/linkable");
378
+ const response = await axiosCloudAPI.get("/projects-linkable");
381
379
  if (response.status !== 200) {
382
380
  throw new Error("Error fetching cloud projects from the server.");
383
381
  }
@@ -389,6 +387,20 @@ async function cloudApiFactory({ logger }, token) {
389
387
  throw error;
390
388
  }
391
389
  },
390
+ async getProject({ name: name2 }) {
391
+ try {
392
+ const response = await axiosCloudAPI.get(`/projects/${name2}`);
393
+ if (response.status !== 200) {
394
+ throw new Error("Error fetching project's details.");
395
+ }
396
+ return response;
397
+ } catch (error) {
398
+ logger.debug(
399
+ "🥲 Oops! There was a problem retrieving your project's details. Please try again."
400
+ );
401
+ throw error;
402
+ }
403
+ },
392
404
  track(event, payload = {}) {
393
405
  return axiosCloudAPI.post("/track", {
394
406
  event,
@@ -698,18 +710,6 @@ async function getProjectNameFromPackageJson(ctx) {
698
710
  return "my-strapi-project";
699
711
  }
700
712
  }
701
- function applyDefaultName(newDefaultName, questions, defaultValues) {
702
- const newDefaultValues = ___default.default.cloneDeep(defaultValues);
703
- newDefaultValues.name = newDefaultName;
704
- const newQuestions = questions.map((question) => {
705
- const questionCopy = ___default.default.cloneDeep(question);
706
- if (questionCopy.name === "name") {
707
- questionCopy.default = newDefaultName;
708
- }
709
- return questionCopy;
710
- });
711
- return { newQuestions, newDefaultValues };
712
- }
713
713
  const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
714
714
  try {
715
715
  await cloudApiService.track(eventName, eventData);
@@ -873,6 +873,45 @@ async function loginAction(ctx) {
873
873
  await authenticate();
874
874
  return isAuthenticated;
875
875
  }
876
+ function questionDefaultValuesMapper(questionsMap) {
877
+ return (questions) => {
878
+ return questions.map((question) => {
879
+ const questionName = question.name;
880
+ if (questionName in questionsMap) {
881
+ const questionDefault = questionsMap[questionName];
882
+ if (typeof questionDefault === "function") {
883
+ return {
884
+ ...question,
885
+ default: questionDefault(question)
886
+ };
887
+ }
888
+ return {
889
+ ...question,
890
+ default: questionDefault
891
+ };
892
+ }
893
+ return question;
894
+ });
895
+ };
896
+ }
897
+ function getDefaultsFromQuestions(questions) {
898
+ return questions.reduce((acc, question) => {
899
+ if (question.default && question.name) {
900
+ return { ...acc, [question.name]: question.default };
901
+ }
902
+ return acc;
903
+ }, {});
904
+ }
905
+ function getProjectNodeVersionDefault(question) {
906
+ const currentNodeVersion = process.versions.node.split(".")[0];
907
+ if (question.type === "list" && Array.isArray(question.choices)) {
908
+ const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
909
+ if (choice) {
910
+ return choice.value;
911
+ }
912
+ }
913
+ return question.default;
914
+ }
876
915
  async function handleError(ctx, error) {
877
916
  const { logger } = ctx;
878
917
  logger.debug(error);
@@ -926,11 +965,16 @@ const action$4 = async (ctx) => {
926
965
  }
927
966
  const cloudApi = await cloudApiFactory(ctx, token);
928
967
  const { data: config } = await cloudApi.config();
929
- const { newQuestions: questions, newDefaultValues: defaultValues } = applyDefaultName(
930
- await getProjectNameFromPackageJson(ctx),
931
- config.projectCreation.questions,
932
- config.projectCreation.defaults
933
- );
968
+ const projectName = await getProjectNameFromPackageJson(ctx);
969
+ const defaultAnswersMapper = questionDefaultValuesMapper({
970
+ name: projectName,
971
+ nodeVersion: getProjectNodeVersionDefault
972
+ });
973
+ const questions = defaultAnswersMapper(config.projectCreation.questions);
974
+ const defaultValues = {
975
+ ...config.projectCreation.defaults,
976
+ ...getDefaultsFromQuestions(questions)
977
+ };
934
978
  const projectAnswersDefaulted = fp.defaults(defaultValues);
935
979
  const projectAnswers = await inquirer__default.default.prompt(questions);
936
980
  const projectInput = projectAnswersDefaulted(projectAnswers);
@@ -1107,17 +1151,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
1107
1151
  return data.build_id;
1108
1152
  } catch (e) {
1109
1153
  progressBar.stop();
1110
- if (e instanceof axios.AxiosError && e.response?.data) {
1111
- if (e.response.status === 404) {
1112
- ctx.logger.warn(
1113
- `The project does not exist. Please link your local project to a Strapi Cloud project using the link command.`
1114
- );
1115
- } else {
1116
- ctx.logger.error(e.response.data);
1117
- }
1118
- } else {
1119
- ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1120
- }
1154
+ ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1121
1155
  ctx.logger.debug(e);
1122
1156
  } finally {
1123
1157
  await fse__namespace.default.remove(tarFilePath);
@@ -1164,7 +1198,39 @@ const action$3 = async (ctx) => {
1164
1198
  if (!project) {
1165
1199
  return;
1166
1200
  }
1167
- const cloudApiService = await cloudApiFactory(ctx);
1201
+ const cloudApiService = await cloudApiFactory(ctx, token);
1202
+ try {
1203
+ const {
1204
+ data: { data: projectData, metadata }
1205
+ } = await cloudApiService.getProject({ name: project.name });
1206
+ const isProjectSuspended = projectData.suspendedAt;
1207
+ if (isProjectSuspended) {
1208
+ ctx.logger.log(
1209
+ "\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
1210
+ );
1211
+ ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
1212
+ return;
1213
+ }
1214
+ } catch (e) {
1215
+ if (e instanceof axios.AxiosError && e.response?.data) {
1216
+ if (e.response.status === 404) {
1217
+ ctx.logger.warn(
1218
+ `The project associated with this folder does not exist in Strapi Cloud.
1219
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1220
+ "link"
1221
+ )} command before deploying.`
1222
+ );
1223
+ } else {
1224
+ ctx.logger.error(e.response.data);
1225
+ }
1226
+ } else {
1227
+ ctx.logger.error(
1228
+ "An error occurred while retrieving the project's information. Please try again later."
1229
+ );
1230
+ }
1231
+ ctx.logger.debug(e);
1232
+ return;
1233
+ }
1168
1234
  await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
1169
1235
  projectInternalName: project.name
1170
1236
  });
@@ -1173,7 +1239,7 @@ const action$3 = async (ctx) => {
1173
1239
  const cliConfig2 = await getConfig({ ctx, cloudApiService });
1174
1240
  if (!cliConfig2) {
1175
1241
  ctx.logger.error(
1176
- "An error occurred while retrieving data from Strapi Cloud. Please try check your network or again later."
1242
+ "An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
1177
1243
  );
1178
1244
  return;
1179
1245
  }