@strapi/cloud-cli 0.0.0-next.d7fa025a4eacdc27490fb1629b0efb93e3cb58b9 → 0.0.0-next.ee56af7ae29770097422de95c0d5500908dce15c

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
@@ -43,6 +43,7 @@ const cliProgress = require("cli-progress");
43
43
  const pkgUp = require("pkg-up");
44
44
  const yup = require("yup");
45
45
  const EventSource = require("eventsource");
46
+ const commander = require("commander");
46
47
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
47
48
  function _interopNamespace(e) {
48
49
  if (e && e.__esModule)
@@ -192,7 +193,7 @@ async function saveLocalConfig(data) {
192
193
  await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
193
194
  }
194
195
  const name = "@strapi/cloud-cli";
195
- const version = "4.25.7";
196
+ const version = "5.0.6";
196
197
  const description = "Commands to interact with the Strapi Cloud";
197
198
  const keywords = [
198
199
  "strapi",
@@ -237,14 +238,14 @@ const scripts = {
237
238
  watch: "pack-up watch"
238
239
  };
239
240
  const dependencies = {
240
- "@strapi/utils": "4.25.7",
241
- axios: "1.6.0",
241
+ "@strapi/utils": "workspace:*",
242
+ axios: "1.7.4",
242
243
  chalk: "4.1.2",
243
244
  "cli-progress": "3.12.0",
244
245
  commander: "8.3.0",
245
246
  eventsource: "2.0.2",
246
247
  "fast-safe-stringify": "2.1.1",
247
- "fs-extra": "10.0.0",
248
+ "fs-extra": "11.2.0",
248
249
  inquirer: "8.2.5",
249
250
  jsonwebtoken: "9.0.0",
250
251
  "jwks-rsa": "3.1.0",
@@ -253,7 +254,7 @@ const dependencies = {
253
254
  open: "8.4.0",
254
255
  ora: "5.4.1",
255
256
  "pkg-up": "3.1.0",
256
- tar: "6.1.13",
257
+ tar: "6.2.1",
257
258
  "xdg-app-paths": "8.3.0",
258
259
  yup: "0.32.9"
259
260
  };
@@ -262,11 +263,11 @@ const devDependencies = {
262
263
  "@types/cli-progress": "3.11.5",
263
264
  "@types/eventsource": "1.1.15",
264
265
  "@types/lodash": "^4.14.191",
265
- "eslint-config-custom": "4.25.7",
266
- tsconfig: "4.25.7"
266
+ "eslint-config-custom": "workspace:*",
267
+ tsconfig: "workspace:*"
267
268
  };
268
269
  const engines = {
269
- node: ">=18.0.0 <=20.x.x",
270
+ node: ">=18.0.0 <=22.x.x",
270
271
  npm: ">=6.0.0"
271
272
  };
272
273
  const packageJson = {
@@ -375,7 +376,7 @@ async function cloudApiFactory({ logger }, token) {
375
376
  },
376
377
  async listLinkProjects() {
377
378
  try {
378
- const response = await axiosCloudAPI.get("/projects/linkable");
379
+ const response = await axiosCloudAPI.get("/projects-linkable");
379
380
  if (response.status !== 200) {
380
381
  throw new Error("Error fetching cloud projects from the server.");
381
382
  }
@@ -387,6 +388,34 @@ async function cloudApiFactory({ logger }, token) {
387
388
  throw error;
388
389
  }
389
390
  },
391
+ async listEnvironments({ name: name2 }) {
392
+ try {
393
+ const response = await axiosCloudAPI.get(`/projects/${name2}/environments`);
394
+ if (response.status !== 200) {
395
+ throw new Error("Error fetching cloud environments from the server.");
396
+ }
397
+ return response;
398
+ } catch (error) {
399
+ logger.debug(
400
+ "🥲 Oops! Couldn't retrieve your project's environments from the server. Please try again."
401
+ );
402
+ throw error;
403
+ }
404
+ },
405
+ async getProject({ name: name2 }) {
406
+ try {
407
+ const response = await axiosCloudAPI.get(`/projects/${name2}`);
408
+ if (response.status !== 200) {
409
+ throw new Error("Error fetching project's details.");
410
+ }
411
+ return response;
412
+ } catch (error) {
413
+ logger.debug(
414
+ "🥲 Oops! There was a problem retrieving your project's details. Please try again."
415
+ );
416
+ throw error;
417
+ }
418
+ },
390
419
  track(event, payload = {}) {
391
420
  return axiosCloudAPI.post("/track", {
392
421
  event,
@@ -660,21 +689,24 @@ yup__namespace.object({
660
689
  name: yup__namespace.string().required(),
661
690
  exports: yup__namespace.lazy(
662
691
  (value) => yup__namespace.object(
663
- typeof value === "object" ? Object.entries(value).reduce((acc, [key, value2]) => {
664
- if (typeof value2 === "object") {
665
- acc[key] = yup__namespace.object({
666
- types: yup__namespace.string().optional(),
667
- source: yup__namespace.string().required(),
668
- module: yup__namespace.string().optional(),
669
- import: yup__namespace.string().required(),
670
- require: yup__namespace.string().required(),
671
- default: yup__namespace.string().required()
672
- }).noUnknown(true);
673
- } else {
674
- acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
675
- }
676
- return acc;
677
- }, {}) : void 0
692
+ typeof value === "object" ? Object.entries(value).reduce(
693
+ (acc, [key, value2]) => {
694
+ if (typeof value2 === "object") {
695
+ acc[key] = yup__namespace.object({
696
+ types: yup__namespace.string().optional(),
697
+ source: yup__namespace.string().required(),
698
+ module: yup__namespace.string().optional(),
699
+ import: yup__namespace.string().required(),
700
+ require: yup__namespace.string().required(),
701
+ default: yup__namespace.string().required()
702
+ }).noUnknown(true);
703
+ } else {
704
+ acc[key] = yup__namespace.string().matches(/^\.\/.*\.json$/).required();
705
+ }
706
+ return acc;
707
+ },
708
+ {}
709
+ ) : void 0
678
710
  ).optional()
679
711
  )
680
712
  });
@@ -942,7 +974,7 @@ async function createProject$1(ctx, cloudApi, projectInput) {
942
974
  throw e;
943
975
  }
944
976
  }
945
- const action$4 = async (ctx) => {
977
+ const action$5 = async (ctx) => {
946
978
  const { logger } = ctx;
947
979
  const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
948
980
  const token = await getValidToken(ctx, promptLogin);
@@ -1137,17 +1169,7 @@ async function upload(ctx, project, token, maxProjectFileSize) {
1137
1169
  return data.build_id;
1138
1170
  } catch (e) {
1139
1171
  progressBar.stop();
1140
- if (e instanceof axios.AxiosError && e.response?.data) {
1141
- if (e.response.status === 404) {
1142
- ctx.logger.warn(
1143
- `The project does not exist. Please link your local project to a Strapi Cloud project using the link command.`
1144
- );
1145
- } else {
1146
- ctx.logger.error(e.response.data);
1147
- }
1148
- } else {
1149
- ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1150
- }
1172
+ ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1151
1173
  ctx.logger.debug(e);
1152
1174
  } finally {
1153
1175
  await fse__namespace.default.remove(tarFilePath);
@@ -1159,11 +1181,11 @@ async function upload(ctx, project, token, maxProjectFileSize) {
1159
1181
  process.exit(1);
1160
1182
  }
1161
1183
  }
1162
- async function getProject(ctx) {
1184
+ async function getProject$1(ctx) {
1163
1185
  const { project } = await retrieve();
1164
1186
  if (!project) {
1165
1187
  try {
1166
- return await action$4(ctx);
1188
+ return await action$5(ctx);
1167
1189
  } catch (e) {
1168
1190
  ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1169
1191
  ctx.logger.debug(e);
@@ -1184,17 +1206,49 @@ async function getConfig({
1184
1206
  return null;
1185
1207
  }
1186
1208
  }
1187
- const action$3 = async (ctx) => {
1209
+ const action$4 = async (ctx) => {
1188
1210
  const { getValidToken } = await tokenServiceFactory(ctx);
1189
1211
  const token = await getValidToken(ctx, promptLogin);
1190
1212
  if (!token) {
1191
1213
  return;
1192
1214
  }
1193
- const project = await getProject(ctx);
1215
+ const project = await getProject$1(ctx);
1194
1216
  if (!project) {
1195
1217
  return;
1196
1218
  }
1197
- const cloudApiService = await cloudApiFactory(ctx);
1219
+ const cloudApiService = await cloudApiFactory(ctx, token);
1220
+ try {
1221
+ const {
1222
+ data: { data: projectData, metadata }
1223
+ } = await cloudApiService.getProject({ name: project.name });
1224
+ const isProjectSuspended = projectData.suspendedAt;
1225
+ if (isProjectSuspended) {
1226
+ ctx.logger.log(
1227
+ "\n Oops! This project has been suspended. \n\n Please reactivate it from the dashboard to continue deploying: "
1228
+ );
1229
+ ctx.logger.log(chalk__default.default.underline(`${metadata.dashboardUrls.project}`));
1230
+ return;
1231
+ }
1232
+ } catch (e) {
1233
+ if (e instanceof axios.AxiosError && e.response?.data) {
1234
+ if (e.response.status === 404) {
1235
+ ctx.logger.warn(
1236
+ `The project associated with this folder does not exist in Strapi Cloud.
1237
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1238
+ "link"
1239
+ )} command before deploying.`
1240
+ );
1241
+ } else {
1242
+ ctx.logger.error(e.response.data);
1243
+ }
1244
+ } else {
1245
+ ctx.logger.error(
1246
+ "An error occurred while retrieving the project's information. Please try again later."
1247
+ );
1248
+ }
1249
+ ctx.logger.debug(e);
1250
+ return;
1251
+ }
1198
1252
  await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
1199
1253
  projectInternalName: project.name
1200
1254
  });
@@ -1203,7 +1257,7 @@ const action$3 = async (ctx) => {
1203
1257
  const cliConfig2 = await getConfig({ ctx, cloudApiService });
1204
1258
  if (!cliConfig2) {
1205
1259
  ctx.logger.error(
1206
- "An error occurred while retrieving data from Strapi Cloud. Please try check your network or again later."
1260
+ "An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
1207
1261
  );
1208
1262
  return;
1209
1263
  }
@@ -1263,14 +1317,14 @@ const runAction = (name2, action2) => (...args) => {
1263
1317
  process.exit(1);
1264
1318
  });
1265
1319
  };
1266
- const command$5 = ({ command: command2, ctx }) => {
1267
- command2.command("cloud:deploy").alias("deploy").description("Deploy a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("deploy", action$3)(ctx));
1320
+ const command$6 = ({ ctx }) => {
1321
+ return commander.createCommand("cloud:deploy").alias("deploy").description("Deploy a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("deploy", action$4)(ctx));
1268
1322
  };
1269
1323
  const deployProject = {
1270
1324
  name: "deploy-project",
1271
1325
  description: "Deploy a Strapi Cloud project",
1272
- action: action$3,
1273
- command: command$5
1326
+ action: action$4,
1327
+ command: command$6
1274
1328
  };
1275
1329
  const QUIT_OPTION = "Quit";
1276
1330
  async function getExistingConfig(ctx) {
@@ -1354,7 +1408,7 @@ async function getUserSelection(ctx, projects) {
1354
1408
  return null;
1355
1409
  }
1356
1410
  }
1357
- const action$2 = async (ctx) => {
1411
+ const action$3 = async (ctx) => {
1358
1412
  const { getValidToken } = await tokenServiceFactory(ctx);
1359
1413
  const token = await getValidToken(ctx, promptLogin);
1360
1414
  const { logger } = ctx;
@@ -1409,17 +1463,17 @@ const action$2 = async (ctx) => {
1409
1463
  });
1410
1464
  }
1411
1465
  };
1412
- const command$4 = ({ command: command2, ctx }) => {
1413
- command2.command("cloud:link").alias("link").description("Link a local directory to a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("link", action$2)(ctx));
1466
+ const command$5 = ({ command: command2, ctx }) => {
1467
+ command2.command("cloud:link").alias("link").description("Link a local directory to a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("link", action$3)(ctx));
1414
1468
  };
1415
1469
  const link = {
1416
1470
  name: "link-project",
1417
1471
  description: "Link a local directory to a Strapi Cloud project",
1418
- action: action$2,
1419
- command: command$4
1472
+ action: action$3,
1473
+ command: command$5
1420
1474
  };
1421
- const command$3 = ({ command: command2, ctx }) => {
1422
- command2.command("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1475
+ const command$4 = ({ ctx }) => {
1476
+ return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1423
1477
  "after",
1424
1478
  "\nAfter running this command, you will be prompted to enter your authentication information."
1425
1479
  ).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
@@ -1428,10 +1482,10 @@ const login = {
1428
1482
  name: "login",
1429
1483
  description: "Strapi Cloud Login",
1430
1484
  action: loginAction,
1431
- command: command$3
1485
+ command: command$4
1432
1486
  };
1433
1487
  const openModule = import("open");
1434
- const action$1 = async (ctx) => {
1488
+ const action$2 = async (ctx) => {
1435
1489
  const { logger } = ctx;
1436
1490
  const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
1437
1491
  const token = await retrieveToken();
@@ -1463,25 +1517,25 @@ const action$1 = async (ctx) => {
1463
1517
  }
1464
1518
  await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
1465
1519
  };
1466
- const command$2 = ({ command: command2, ctx }) => {
1467
- command2.command("cloud:logout").alias("logout").description("Strapi Cloud Logout").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("logout", action$1)(ctx));
1520
+ const command$3 = ({ ctx }) => {
1521
+ return commander.createCommand("cloud:logout").alias("logout").description("Strapi Cloud Logout").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("logout", action$2)(ctx));
1468
1522
  };
1469
1523
  const logout = {
1470
1524
  name: "logout",
1471
1525
  description: "Strapi Cloud Logout",
1472
- action: action$1,
1473
- command: command$2
1526
+ action: action$2,
1527
+ command: command$3
1474
1528
  };
1475
- const command$1 = ({ command: command2, ctx }) => {
1476
- command2.command("cloud:create-project").description("Create a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("cloud:create-project", action$4)(ctx));
1529
+ const command$2 = ({ ctx }) => {
1530
+ return commander.createCommand("cloud:create-project").description("Create a Strapi Cloud project").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("cloud:create-project", action$5)(ctx));
1477
1531
  };
1478
1532
  const createProject = {
1479
1533
  name: "create-project",
1480
1534
  description: "Create a new project",
1481
- action: action$4,
1482
- command: command$1
1535
+ action: action$5,
1536
+ command: command$2
1483
1537
  };
1484
- const action = async (ctx) => {
1538
+ const action$1 = async (ctx) => {
1485
1539
  const { getValidToken } = await tokenServiceFactory(ctx);
1486
1540
  const token = await getValidToken(ctx, promptLogin);
1487
1541
  const { logger } = ctx;
@@ -1501,12 +1555,86 @@ const action = async (ctx) => {
1501
1555
  spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
1502
1556
  }
1503
1557
  };
1504
- const command = ({ command: command2, ctx }) => {
1505
- command2.command("cloud:projects").alias("projects").description("List Strapi Cloud projects").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("projects", action)(ctx));
1558
+ const command$1 = ({ command: command2, ctx }) => {
1559
+ command2.command("cloud:projects").alias("projects").description("List Strapi Cloud projects").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("projects", action$1)(ctx));
1506
1560
  };
1507
1561
  const listProjects = {
1508
1562
  name: "list-projects",
1509
1563
  description: "List Strapi Cloud projects",
1564
+ action: action$1,
1565
+ command: command$1
1566
+ };
1567
+ async function getProject(ctx) {
1568
+ const { project } = await retrieve();
1569
+ if (!project) {
1570
+ ctx.logger.warn(
1571
+ `
1572
+ We couldn't find a valid local project config.
1573
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1574
+ "link"
1575
+ )} command`
1576
+ );
1577
+ process.exit(1);
1578
+ }
1579
+ return project;
1580
+ }
1581
+ const action = async (ctx) => {
1582
+ const { getValidToken } = await tokenServiceFactory(ctx);
1583
+ const token = await getValidToken(ctx, promptLogin);
1584
+ const { logger } = ctx;
1585
+ if (!token) {
1586
+ return;
1587
+ }
1588
+ const project = await getProject(ctx);
1589
+ if (!project) {
1590
+ ctx.logger.debug(`No valid local project configuration was found.`);
1591
+ return;
1592
+ }
1593
+ const cloudApiService = await cloudApiFactory(ctx, token);
1594
+ const spinner = logger.spinner("Fetching environments...").start();
1595
+ await trackEvent(ctx, cloudApiService, "willListEnvironment", {
1596
+ projectInternalName: project.name
1597
+ });
1598
+ try {
1599
+ const {
1600
+ data: { data: environmentsList }
1601
+ } = await cloudApiService.listEnvironments({ name: project.name });
1602
+ spinner.succeed();
1603
+ logger.log(environmentsList);
1604
+ await trackEvent(ctx, cloudApiService, "didListEnvironment", {
1605
+ projectInternalName: project.name
1606
+ });
1607
+ } catch (e) {
1608
+ if (e.response && e.response.status === 404) {
1609
+ spinner.succeed();
1610
+ logger.warn(
1611
+ `
1612
+ The project associated with this folder does not exist in Strapi Cloud.
1613
+ Please link your local project to an existing Strapi Cloud project using the ${chalk__default.default.cyan(
1614
+ "link"
1615
+ )} command`
1616
+ );
1617
+ } else {
1618
+ spinner.fail("An error occurred while fetching environments data from Strapi Cloud.");
1619
+ logger.debug("Failed to list environments", e);
1620
+ }
1621
+ await trackEvent(ctx, cloudApiService, "didNotListEnvironment", {
1622
+ projectInternalName: project.name
1623
+ });
1624
+ }
1625
+ };
1626
+ function defineCloudNamespace(command2) {
1627
+ return command2.command("cloud").description("Manage Strapi Cloud projects");
1628
+ }
1629
+ const command = ({ command: command2, ctx }) => {
1630
+ const cloud = defineCloudNamespace(command2);
1631
+ cloud.command("environments").description("Alias for cloud environment list").action(() => runAction("list", action)(ctx));
1632
+ const environment = cloud.command("environment").description("Manage environments for a Strapi Cloud project");
1633
+ environment.command("list").description("List Strapi Cloud project environments").option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("list", action)(ctx));
1634
+ };
1635
+ const listEnvironments = {
1636
+ name: "list-environments",
1637
+ description: "List Strapi Cloud environments",
1510
1638
  action,
1511
1639
  command
1512
1640
  };
@@ -1516,9 +1644,10 @@ const cli = {
1516
1644
  login,
1517
1645
  logout,
1518
1646
  createProject,
1519
- listProjects
1647
+ listProjects,
1648
+ listEnvironments
1520
1649
  };
1521
- const cloudCommands = [deployProject, link, login, logout, listProjects];
1650
+ const cloudCommands = [deployProject, link, login, logout, listProjects, listEnvironments];
1522
1651
  async function initCloudCLIConfig() {
1523
1652
  const localConfig = await getLocalConfig();
1524
1653
  if (!localConfig.deviceId) {
@@ -1534,7 +1663,10 @@ async function buildStrapiCloudCommands({
1534
1663
  await initCloudCLIConfig();
1535
1664
  for (const cloudCommand of cloudCommands) {
1536
1665
  try {
1537
- await cloudCommand.command({ command: command2, ctx, argv });
1666
+ const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
1667
+ if (subCommand) {
1668
+ command2.addCommand(subCommand);
1669
+ }
1538
1670
  } catch (e) {
1539
1671
  console.error(`Failed to load command ${cloudCommand.name}`, e);
1540
1672
  }