@strapi/cloud-cli 0.0.0-next.f6dca5adf05ef6bed9605a1535999ab0bbbf063e → 0.0.0-next.fb92031f3d90f3d2a2d191ba65725b6c8e329a5d

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.
Files changed (319) hide show
  1. package/dist/bin.d.ts.map +1 -0
  2. package/dist/bin.js +40 -171
  3. package/dist/bin.js.map +1 -1
  4. package/dist/bin.mjs +44 -0
  5. package/dist/bin.mjs.map +1 -0
  6. package/dist/cloud/command.d.ts +3 -0
  7. package/dist/cloud/command.d.ts.map +1 -0
  8. package/dist/cloud/command.js +14 -0
  9. package/dist/cloud/command.js.map +1 -0
  10. package/dist/cloud/command.mjs +12 -0
  11. package/dist/cloud/command.mjs.map +1 -0
  12. package/dist/config/api.d.ts.map +1 -0
  13. package/dist/config/api.js +11 -0
  14. package/dist/config/api.js.map +1 -0
  15. package/dist/config/api.mjs +9 -0
  16. package/dist/config/api.mjs.map +1 -0
  17. package/dist/{src/config → config}/local.d.ts +1 -1
  18. package/dist/config/local.d.ts.map +1 -0
  19. package/dist/config/local.js +60 -0
  20. package/dist/config/local.js.map +1 -0
  21. package/dist/config/local.mjs +55 -0
  22. package/dist/config/local.mjs.map +1 -0
  23. package/dist/create-project/action.d.ts.map +1 -0
  24. package/dist/create-project/action.js +95 -0
  25. package/dist/create-project/action.js.map +1 -0
  26. package/dist/create-project/action.mjs +93 -0
  27. package/dist/create-project/action.mjs.map +1 -0
  28. package/dist/create-project/command.d.ts.map +1 -0
  29. package/dist/create-project/command.js +14 -0
  30. package/dist/create-project/command.js.map +1 -0
  31. package/dist/create-project/command.mjs +12 -0
  32. package/dist/create-project/command.mjs.map +1 -0
  33. package/dist/create-project/index.d.ts.map +1 -0
  34. package/dist/create-project/index.js +18 -0
  35. package/dist/create-project/index.js.map +1 -0
  36. package/dist/create-project/index.mjs +12 -0
  37. package/dist/create-project/index.mjs.map +1 -0
  38. package/dist/create-project/utils/get-project-name-from-pkg.d.ts.map +1 -0
  39. package/dist/create-project/utils/get-project-name-from-pkg.js +15 -0
  40. package/dist/create-project/utils/get-project-name-from-pkg.js.map +1 -0
  41. package/dist/create-project/utils/get-project-name-from-pkg.mjs +13 -0
  42. package/dist/create-project/utils/get-project-name-from-pkg.mjs.map +1 -0
  43. package/dist/create-project/utils/project-questions.utils.d.ts.map +1 -0
  44. package/dist/create-project/utils/project-questions.utils.js +63 -0
  45. package/dist/create-project/utils/project-questions.utils.js.map +1 -0
  46. package/dist/create-project/utils/project-questions.utils.mjs +59 -0
  47. package/dist/create-project/utils/project-questions.utils.mjs.map +1 -0
  48. package/dist/deploy-project/action.d.ts +8 -0
  49. package/dist/deploy-project/action.d.ts.map +1 -0
  50. package/dist/deploy-project/action.js +287 -0
  51. package/dist/deploy-project/action.js.map +1 -0
  52. package/dist/deploy-project/action.mjs +266 -0
  53. package/dist/deploy-project/action.mjs.map +1 -0
  54. package/dist/deploy-project/command.d.ts.map +1 -0
  55. package/dist/deploy-project/command.js +14 -0
  56. package/dist/deploy-project/command.js.map +1 -0
  57. package/dist/deploy-project/command.mjs +12 -0
  58. package/dist/deploy-project/command.mjs.map +1 -0
  59. package/dist/deploy-project/index.d.ts.map +1 -0
  60. package/dist/deploy-project/index.js +18 -0
  61. package/dist/deploy-project/index.js.map +1 -0
  62. package/dist/deploy-project/index.mjs +12 -0
  63. package/dist/deploy-project/index.mjs.map +1 -0
  64. package/dist/environment/command.d.ts +3 -0
  65. package/dist/environment/command.d.ts.map +1 -0
  66. package/dist/environment/command.js +15 -0
  67. package/dist/environment/command.js.map +1 -0
  68. package/dist/environment/command.mjs +13 -0
  69. package/dist/environment/command.mjs.map +1 -0
  70. package/dist/environment/link/action.d.ts.map +1 -0
  71. package/dist/environment/link/action.js +117 -0
  72. package/dist/environment/link/action.js.map +1 -0
  73. package/dist/environment/link/action.mjs +115 -0
  74. package/dist/environment/link/action.mjs.map +1 -0
  75. package/dist/environment/link/command.d.ts.map +1 -0
  76. package/dist/environment/link/command.js +13 -0
  77. package/dist/environment/link/command.js.map +1 -0
  78. package/dist/environment/link/command.mjs +11 -0
  79. package/dist/environment/link/command.mjs.map +1 -0
  80. package/dist/environment/link/index.d.ts.map +1 -0
  81. package/dist/environment/link/index.js +18 -0
  82. package/dist/environment/link/index.js.map +1 -0
  83. package/dist/environment/link/index.mjs +12 -0
  84. package/dist/environment/link/index.mjs.map +1 -0
  85. package/dist/environment/list/action.d.ts +4 -0
  86. package/dist/environment/list/action.d.ts.map +1 -0
  87. package/dist/environment/list/action.js +57 -0
  88. package/dist/environment/list/action.js.map +1 -0
  89. package/dist/environment/list/action.mjs +55 -0
  90. package/dist/environment/list/action.mjs.map +1 -0
  91. package/dist/environment/list/command.d.ts +4 -0
  92. package/dist/environment/list/command.d.ts.map +1 -0
  93. package/dist/environment/list/command.js +13 -0
  94. package/dist/environment/list/command.js.map +1 -0
  95. package/dist/environment/list/command.mjs +11 -0
  96. package/dist/environment/list/command.mjs.map +1 -0
  97. package/dist/environment/list/index.d.ts +7 -0
  98. package/dist/environment/list/index.d.ts.map +1 -0
  99. package/dist/environment/list/index.js +18 -0
  100. package/dist/environment/list/index.js.map +1 -0
  101. package/dist/environment/list/index.mjs +12 -0
  102. package/dist/environment/list/index.mjs.map +1 -0
  103. package/dist/{src/index.d.ts → index.d.ts} +1 -0
  104. package/dist/index.d.ts.map +1 -0
  105. package/dist/index.js +56 -1670
  106. package/dist/index.js.map +1 -1
  107. package/dist/index.mjs +55 -1615
  108. package/dist/index.mjs.map +1 -1
  109. package/dist/link/action.d.ts.map +1 -0
  110. package/dist/link/action.js +146 -0
  111. package/dist/link/action.js.map +1 -0
  112. package/dist/link/action.mjs +144 -0
  113. package/dist/link/action.mjs.map +1 -0
  114. package/dist/link/command.d.ts.map +1 -0
  115. package/dist/link/command.js +13 -0
  116. package/dist/link/command.js.map +1 -0
  117. package/dist/link/command.mjs +11 -0
  118. package/dist/link/command.mjs.map +1 -0
  119. package/dist/link/index.d.ts.map +1 -0
  120. package/dist/link/index.js +18 -0
  121. package/dist/link/index.js.map +1 -0
  122. package/dist/link/index.mjs +12 -0
  123. package/dist/link/index.mjs.map +1 -0
  124. package/dist/list-projects/action.d.ts.map +1 -0
  125. package/dist/list-projects/action.js +34 -0
  126. package/dist/list-projects/action.js.map +1 -0
  127. package/dist/list-projects/action.mjs +32 -0
  128. package/dist/list-projects/action.mjs.map +1 -0
  129. package/dist/list-projects/command.d.ts.map +1 -0
  130. package/dist/list-projects/command.js +13 -0
  131. package/dist/list-projects/command.js.map +1 -0
  132. package/dist/list-projects/command.mjs +11 -0
  133. package/dist/list-projects/command.mjs.map +1 -0
  134. package/dist/list-projects/index.d.ts.map +1 -0
  135. package/dist/list-projects/index.js +18 -0
  136. package/dist/list-projects/index.js.map +1 -0
  137. package/dist/list-projects/index.mjs +12 -0
  138. package/dist/list-projects/index.mjs.map +1 -0
  139. package/dist/login/action.d.ts.map +1 -0
  140. package/dist/login/action.js +177 -0
  141. package/dist/login/action.js.map +1 -0
  142. package/dist/login/action.mjs +172 -0
  143. package/dist/login/action.mjs.map +1 -0
  144. package/dist/login/command.d.ts.map +1 -0
  145. package/dist/login/command.js +14 -0
  146. package/dist/login/command.js.map +1 -0
  147. package/dist/login/command.mjs +12 -0
  148. package/dist/login/command.mjs.map +1 -0
  149. package/dist/login/index.d.ts.map +1 -0
  150. package/dist/login/index.js +18 -0
  151. package/dist/login/index.js.map +1 -0
  152. package/dist/login/index.mjs +12 -0
  153. package/dist/login/index.mjs.map +1 -0
  154. package/dist/logout/action.d.ts.map +1 -0
  155. package/dist/logout/action.js +46 -0
  156. package/dist/logout/action.js.map +1 -0
  157. package/dist/logout/action.mjs +44 -0
  158. package/dist/logout/action.mjs.map +1 -0
  159. package/dist/logout/command.d.ts.map +1 -0
  160. package/dist/logout/command.js +14 -0
  161. package/dist/logout/command.js.map +1 -0
  162. package/dist/logout/command.mjs +12 -0
  163. package/dist/logout/command.mjs.map +1 -0
  164. package/dist/logout/index.d.ts.map +1 -0
  165. package/dist/logout/index.js +18 -0
  166. package/dist/logout/index.js.map +1 -0
  167. package/dist/logout/index.mjs +12 -0
  168. package/dist/logout/index.mjs.map +1 -0
  169. package/dist/package.json.js +129 -0
  170. package/dist/package.json.js.map +1 -0
  171. package/dist/package.json.mjs +105 -0
  172. package/dist/package.json.mjs.map +1 -0
  173. package/dist/services/build-logs.d.ts.map +1 -0
  174. package/dist/services/build-logs.js +67 -0
  175. package/dist/services/build-logs.js.map +1 -0
  176. package/dist/services/build-logs.mjs +65 -0
  177. package/dist/services/build-logs.mjs.map +1 -0
  178. package/dist/{src/services → services}/cli-api.d.ts +21 -3
  179. package/dist/services/cli-api.d.ts.map +1 -0
  180. package/dist/services/cli-api.js +146 -0
  181. package/dist/services/cli-api.js.map +1 -0
  182. package/dist/services/cli-api.mjs +143 -0
  183. package/dist/services/cli-api.mjs.map +1 -0
  184. package/dist/services/index.d.ts.map +1 -0
  185. package/dist/services/index.js +14 -0
  186. package/dist/services/index.js.map +1 -0
  187. package/dist/services/index.mjs +6 -0
  188. package/dist/services/index.mjs.map +1 -0
  189. package/dist/services/logger.d.ts.map +1 -0
  190. package/dist/services/logger.js +128 -0
  191. package/dist/services/logger.js.map +1 -0
  192. package/dist/services/logger.mjs +107 -0
  193. package/dist/services/logger.mjs.map +1 -0
  194. package/dist/services/notification.d.ts.map +1 -0
  195. package/dist/services/notification.js +37 -0
  196. package/dist/services/notification.js.map +1 -0
  197. package/dist/services/notification.mjs +35 -0
  198. package/dist/services/notification.mjs.map +1 -0
  199. package/dist/services/strapi-info-save.d.ts +25 -0
  200. package/dist/services/strapi-info-save.d.ts.map +1 -0
  201. package/dist/services/strapi-info-save.js +53 -0
  202. package/dist/services/strapi-info-save.js.map +1 -0
  203. package/dist/services/strapi-info-save.mjs +47 -0
  204. package/dist/services/strapi-info-save.mjs.map +1 -0
  205. package/dist/services/token.d.ts.map +1 -0
  206. package/dist/services/token.js +126 -0
  207. package/dist/services/token.js.map +1 -0
  208. package/dist/services/token.mjs +124 -0
  209. package/dist/services/token.mjs.map +1 -0
  210. package/dist/{src/types.d.ts → types.d.ts} +3 -0
  211. package/dist/types.d.ts.map +1 -0
  212. package/dist/utils/analytics.d.ts.map +1 -0
  213. package/dist/utils/analytics.js +12 -0
  214. package/dist/utils/analytics.js.map +1 -0
  215. package/dist/utils/analytics.mjs +10 -0
  216. package/dist/utils/analytics.mjs.map +1 -0
  217. package/dist/utils/compress-files.d.ts.map +1 -0
  218. package/dist/utils/compress-files.js +102 -0
  219. package/dist/utils/compress-files.js.map +1 -0
  220. package/dist/utils/compress-files.mjs +78 -0
  221. package/dist/utils/compress-files.mjs.map +1 -0
  222. package/dist/utils/get-local-config.d.ts +6 -0
  223. package/dist/utils/get-local-config.d.ts.map +1 -0
  224. package/dist/utils/get-local-config.js +37 -0
  225. package/dist/utils/get-local-config.js.map +1 -0
  226. package/dist/utils/get-local-config.mjs +34 -0
  227. package/dist/utils/get-local-config.mjs.map +1 -0
  228. package/dist/utils/helpers.d.ts.map +1 -0
  229. package/dist/utils/helpers.js +33 -0
  230. package/dist/utils/helpers.js.map +1 -0
  231. package/dist/utils/helpers.mjs +31 -0
  232. package/dist/utils/helpers.mjs.map +1 -0
  233. package/dist/utils/pkg.d.ts.map +1 -0
  234. package/dist/utils/pkg.js +65 -0
  235. package/dist/utils/pkg.js.map +1 -0
  236. package/dist/utils/pkg.mjs +43 -0
  237. package/dist/utils/pkg.mjs.map +1 -0
  238. package/dist/utils/tests/compress-files.test.d.ts.map +1 -0
  239. package/package.json +12 -11
  240. package/dist/src/bin.d.ts.map +0 -1
  241. package/dist/src/cloud/command.d.ts +0 -3
  242. package/dist/src/cloud/command.d.ts.map +0 -1
  243. package/dist/src/config/api.d.ts.map +0 -1
  244. package/dist/src/config/local.d.ts.map +0 -1
  245. package/dist/src/create-project/action.d.ts.map +0 -1
  246. package/dist/src/create-project/command.d.ts.map +0 -1
  247. package/dist/src/create-project/index.d.ts.map +0 -1
  248. package/dist/src/create-project/utils/get-project-name-from-pkg.d.ts.map +0 -1
  249. package/dist/src/create-project/utils/project-questions.utils.d.ts.map +0 -1
  250. package/dist/src/deploy-project/action.d.ts.map +0 -1
  251. package/dist/src/deploy-project/command.d.ts.map +0 -1
  252. package/dist/src/deploy-project/index.d.ts.map +0 -1
  253. package/dist/src/environment/command.d.ts +0 -3
  254. package/dist/src/environment/command.d.ts.map +0 -1
  255. package/dist/src/environment/list/action.d.ts.map +0 -1
  256. package/dist/src/environment/list/command.d.ts.map +0 -1
  257. package/dist/src/environment/list/index.d.ts.map +0 -1
  258. package/dist/src/index.d.ts.map +0 -1
  259. package/dist/src/link/action.d.ts.map +0 -1
  260. package/dist/src/link/command.d.ts.map +0 -1
  261. package/dist/src/link/index.d.ts.map +0 -1
  262. package/dist/src/list-projects/action.d.ts.map +0 -1
  263. package/dist/src/list-projects/command.d.ts.map +0 -1
  264. package/dist/src/list-projects/index.d.ts.map +0 -1
  265. package/dist/src/login/action.d.ts.map +0 -1
  266. package/dist/src/login/command.d.ts.map +0 -1
  267. package/dist/src/login/index.d.ts.map +0 -1
  268. package/dist/src/logout/action.d.ts +0 -4
  269. package/dist/src/logout/action.d.ts.map +0 -1
  270. package/dist/src/logout/command.d.ts.map +0 -1
  271. package/dist/src/logout/index.d.ts.map +0 -1
  272. package/dist/src/services/build-logs.d.ts.map +0 -1
  273. package/dist/src/services/cli-api.d.ts.map +0 -1
  274. package/dist/src/services/index.d.ts.map +0 -1
  275. package/dist/src/services/logger.d.ts.map +0 -1
  276. package/dist/src/services/notification.d.ts.map +0 -1
  277. package/dist/src/services/strapi-info-save.d.ts +0 -12
  278. package/dist/src/services/strapi-info-save.d.ts.map +0 -1
  279. package/dist/src/services/token.d.ts.map +0 -1
  280. package/dist/src/types.d.ts.map +0 -1
  281. package/dist/src/utils/analytics.d.ts.map +0 -1
  282. package/dist/src/utils/compress-files.d.ts.map +0 -1
  283. package/dist/src/utils/helpers.d.ts.map +0 -1
  284. package/dist/src/utils/pkg.d.ts.map +0 -1
  285. package/dist/src/utils/tests/compress-files.test.d.ts.map +0 -1
  286. /package/dist/{src/bin.d.ts → bin.d.ts} +0 -0
  287. /package/dist/{src/config → config}/api.d.ts +0 -0
  288. /package/dist/{src/create-project → create-project}/action.d.ts +0 -0
  289. /package/dist/{src/create-project → create-project}/command.d.ts +0 -0
  290. /package/dist/{src/create-project → create-project}/index.d.ts +0 -0
  291. /package/dist/{src/create-project → create-project}/utils/get-project-name-from-pkg.d.ts +0 -0
  292. /package/dist/{src/create-project → create-project}/utils/project-questions.utils.d.ts +0 -0
  293. /package/dist/{src/deploy-project → deploy-project}/command.d.ts +0 -0
  294. /package/dist/{src/deploy-project → deploy-project}/index.d.ts +0 -0
  295. /package/dist/{src/environment/list → environment/link}/action.d.ts +0 -0
  296. /package/dist/{src/environment/list → environment/link}/command.d.ts +0 -0
  297. /package/dist/{src/environment/list → environment/link}/index.d.ts +0 -0
  298. /package/dist/{src/deploy-project → link}/action.d.ts +0 -0
  299. /package/dist/{src/link → link}/command.d.ts +0 -0
  300. /package/dist/{src/link → link}/index.d.ts +0 -0
  301. /package/dist/{src/link → list-projects}/action.d.ts +0 -0
  302. /package/dist/{src/list-projects → list-projects}/command.d.ts +0 -0
  303. /package/dist/{src/list-projects → list-projects}/index.d.ts +0 -0
  304. /package/dist/{src/login → login}/action.d.ts +0 -0
  305. /package/dist/{src/login → login}/command.d.ts +0 -0
  306. /package/dist/{src/login → login}/index.d.ts +0 -0
  307. /package/dist/{src/list-projects → logout}/action.d.ts +0 -0
  308. /package/dist/{src/logout → logout}/command.d.ts +0 -0
  309. /package/dist/{src/logout → logout}/index.d.ts +0 -0
  310. /package/dist/{src/services → services}/build-logs.d.ts +0 -0
  311. /package/dist/{src/services → services}/index.d.ts +0 -0
  312. /package/dist/{src/services → services}/logger.d.ts +0 -0
  313. /package/dist/{src/services → services}/notification.d.ts +0 -0
  314. /package/dist/{src/services → services}/token.d.ts +0 -0
  315. /package/dist/{src/utils → utils}/analytics.d.ts +0 -0
  316. /package/dist/{src/utils → utils}/compress-files.d.ts +0 -0
  317. /package/dist/{src/utils → utils}/helpers.d.ts +0 -0
  318. /package/dist/{src/utils → utils}/pkg.d.ts +0 -0
  319. /package/dist/{src/utils → utils}/tests/compress-files.test.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1,1678 +1,64 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
- const crypto$1 = require("crypto");
26
- const fse = require("fs-extra");
27
- const path = require("path");
28
- const chalk = require("chalk");
29
- const axios = require("axios");
30
- const crypto = require("node:crypto");
31
- const utils = require("@strapi/utils");
32
- const tar = require("tar");
33
- const minimatch = require("minimatch");
34
- const inquirer = require("inquirer");
35
- const fp = require("lodash/fp");
36
- const os = require("os");
37
- const XDGAppPaths = require("xdg-app-paths");
38
- const jwksClient = require("jwks-rsa");
39
- const jwt = require("jsonwebtoken");
40
- const stringify = require("fast-safe-stringify");
41
- const ora = require("ora");
42
- const cliProgress = require("cli-progress");
43
- const pkgUp = require("pkg-up");
44
- const yup = require("yup");
45
- const EventSource = require("eventsource");
46
- const commander = require("commander");
47
- const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
48
- function _interopNamespace(e) {
49
- if (e && e.__esModule)
50
- return e;
51
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
52
- if (e) {
53
- for (const k in e) {
54
- if (k !== "default") {
55
- const d = Object.getOwnPropertyDescriptor(e, k);
56
- Object.defineProperty(n, k, d.get ? d : {
57
- enumerable: true,
58
- get: () => e[k]
59
- });
60
- }
61
- }
62
- }
63
- n.default = e;
64
- return Object.freeze(n);
65
- }
66
- const crypto__default = /* @__PURE__ */ _interopDefault(crypto$1);
67
- const fse__namespace = /* @__PURE__ */ _interopNamespace(fse);
68
- const path__namespace = /* @__PURE__ */ _interopNamespace(path);
69
- const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
70
- const axios__default = /* @__PURE__ */ _interopDefault(axios);
71
- const crypto__namespace = /* @__PURE__ */ _interopNamespace(crypto);
72
- const tar__namespace = /* @__PURE__ */ _interopNamespace(tar);
73
- const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer);
74
- const os__default = /* @__PURE__ */ _interopDefault(os);
75
- const XDGAppPaths__default = /* @__PURE__ */ _interopDefault(XDGAppPaths);
76
- const jwksClient__default = /* @__PURE__ */ _interopDefault(jwksClient);
77
- const jwt__default = /* @__PURE__ */ _interopDefault(jwt);
78
- const stringify__default = /* @__PURE__ */ _interopDefault(stringify);
79
- const ora__default = /* @__PURE__ */ _interopDefault(ora);
80
- const cliProgress__namespace = /* @__PURE__ */ _interopNamespace(cliProgress);
81
- const pkgUp__default = /* @__PURE__ */ _interopDefault(pkgUp);
82
- const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
83
- const EventSource__default = /* @__PURE__ */ _interopDefault(EventSource);
84
- const apiConfig = {
85
- apiBaseUrl: utils.env("STRAPI_CLI_CLOUD_API", "https://cloud-cli-api.strapi.io"),
86
- dashboardBaseUrl: utils.env("STRAPI_CLI_CLOUD_DASHBOARD", "https://cloud.strapi.io")
87
- };
88
- const IGNORED_PATTERNS = [
89
- "**/.git/**",
90
- "**/node_modules/**",
91
- "**/build/**",
92
- "**/dist/**",
93
- "**/.cache/**",
94
- "**/.circleci/**",
95
- "**/.github/**",
96
- "**/.gitignore",
97
- "**/.gitkeep",
98
- "**/.gitlab-ci.yml",
99
- "**/.idea/**",
100
- "**/.vscode/**"
101
- ];
102
- const isIgnoredFile = (folderPath, file, ignorePatterns) => {
103
- ignorePatterns.push(...IGNORED_PATTERNS);
104
- const relativeFilePath = path__namespace.join(folderPath, file);
105
- let isIgnored = false;
106
- for (const pattern of ignorePatterns) {
107
- if (pattern.startsWith("!")) {
108
- if (minimatch.minimatch(relativeFilePath, pattern.slice(1), { matchBase: true, dot: true })) {
109
- return false;
110
- }
111
- } else if (minimatch.minimatch(relativeFilePath, pattern, { matchBase: true, dot: true })) {
112
- if (path__namespace.basename(file) !== ".gitkeep") {
113
- isIgnored = true;
114
- }
115
- }
116
- }
117
- return isIgnored;
118
- };
119
- const getFiles = async (dirPath, ignorePatterns = [], subfolder = "") => {
120
- const arrayOfFiles = [];
121
- const entries = await fse__namespace.readdir(path__namespace.join(dirPath, subfolder));
122
- for (const entry of entries) {
123
- const entryPathFromRoot = path__namespace.join(subfolder, entry);
124
- const entryPath = path__namespace.relative(dirPath, entryPathFromRoot);
125
- const isIgnored = isIgnoredFile(dirPath, entryPathFromRoot, ignorePatterns);
126
- if (!isIgnored) {
127
- if (fse__namespace.statSync(entryPath).isDirectory()) {
128
- const subFiles = await getFiles(dirPath, ignorePatterns, entryPathFromRoot);
129
- arrayOfFiles.push(...subFiles);
130
- } else {
131
- arrayOfFiles.push(entryPath);
132
- }
133
- }
134
- }
135
- return arrayOfFiles;
136
- };
137
- const readGitignore = async (folderPath) => {
138
- const gitignorePath = path__namespace.resolve(folderPath, ".gitignore");
139
- const pathExist = await fse__namespace.pathExists(gitignorePath);
140
- if (!pathExist)
141
- return [];
142
- const gitignoreContent = await fse__namespace.readFile(gitignorePath, "utf8");
143
- return gitignoreContent.split(/\r?\n/).filter((line) => Boolean(line.trim()) && !line.startsWith("#"));
144
- };
145
- const compressFilesToTar = async (storagePath, folderToCompress, filename) => {
146
- const ignorePatterns = await readGitignore(folderToCompress);
147
- const filesToCompress = await getFiles(folderToCompress, ignorePatterns);
148
- return tar__namespace.c(
149
- {
150
- gzip: true,
151
- file: path__namespace.resolve(storagePath, filename)
152
- },
153
- filesToCompress
154
- );
155
- };
156
- const APP_FOLDER_NAME = "com.strapi.cli";
157
- const CONFIG_FILENAME = "config.json";
158
- async function checkDirectoryExists(directoryPath) {
159
- try {
160
- const fsStat = await fse__namespace.default.lstat(directoryPath);
161
- return fsStat.isDirectory();
162
- } catch (e) {
163
- return false;
164
- }
165
- }
166
- async function getTmpStoragePath() {
167
- const storagePath = path__namespace.default.join(os__default.default.tmpdir(), APP_FOLDER_NAME);
168
- await fse__namespace.default.ensureDir(storagePath);
169
- return storagePath;
170
- }
171
- async function getConfigPath() {
172
- const configDirs = XDGAppPaths__default.default(APP_FOLDER_NAME).configDirs();
173
- const configPath = configDirs.find(checkDirectoryExists);
174
- if (!configPath) {
175
- await fse__namespace.default.ensureDir(configDirs[0]);
176
- return configDirs[0];
177
- }
178
- return configPath;
179
- }
180
- async function getLocalConfig() {
181
- const configPath = await getConfigPath();
182
- const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
183
- await fse__namespace.default.ensureFile(configFilePath);
184
- try {
185
- return await fse__namespace.default.readJSON(configFilePath, { encoding: "utf8", throws: true });
186
- } catch (e) {
187
- return {};
188
- }
189
- }
190
- async function saveLocalConfig(data) {
191
- const configPath = await getConfigPath();
192
- const configFilePath = path__namespace.default.join(configPath, CONFIG_FILENAME);
193
- await fse__namespace.default.writeJson(configFilePath, data, { encoding: "utf8", spaces: 2, mode: 384 });
194
- }
195
- const name = "@strapi/cloud-cli";
196
- const version = "5.1.1";
197
- const description = "Commands to interact with the Strapi Cloud";
198
- const keywords = [
199
- "strapi",
200
- "cloud",
201
- "cli"
202
- ];
203
- const homepage = "https://strapi.io";
204
- const bugs = {
205
- url: "https://github.com/strapi/strapi/issues"
206
- };
207
- const repository = {
208
- type: "git",
209
- url: "git://github.com/strapi/strapi.git"
210
- };
211
- const license = "SEE LICENSE IN LICENSE";
212
- const author = {
213
- name: "Strapi Solutions SAS",
214
- email: "hi@strapi.io",
215
- url: "https://strapi.io"
216
- };
217
- const maintainers = [
218
- {
219
- name: "Strapi Solutions SAS",
220
- email: "hi@strapi.io",
221
- url: "https://strapi.io"
222
- }
223
- ];
224
- const main = "./dist/index.js";
225
- const module$1 = "./dist/index.mjs";
226
- const source = "./src/index.ts";
227
- const types = "./dist/src/index.d.ts";
228
- const bin = "./bin/index.js";
229
- const files = [
230
- "./dist",
231
- "./bin"
1
+ 'use strict';
2
+
3
+ var crypto = require('crypto');
4
+ var index$1 = require('./deploy-project/index.js');
5
+ var index$2 = require('./link/index.js');
6
+ var index$3 = require('./login/index.js');
7
+ var index$4 = require('./logout/index.js');
8
+ var index$5 = require('./create-project/index.js');
9
+ var index$7 = require('./list-projects/index.js');
10
+ var index$8 = require('./environment/list/index.js');
11
+ var index$6 = require('./environment/link/index.js');
12
+ var local = require('./config/local.js');
13
+ var index = require('./services/index.js');
14
+
15
+ const cli = {
16
+ deployProject: index$1.default,
17
+ link: index$2.default,
18
+ login: index$3.default,
19
+ logout: index$4.default,
20
+ createProject: index$5.default,
21
+ linkEnvironment: index$6.default,
22
+ listProjects: index$7.default,
23
+ listEnvironments: index$8.default
24
+ };
25
+ const cloudCommands = [
26
+ index$1.default,
27
+ index$2.default,
28
+ index$3.default,
29
+ index$4.default,
30
+ index$6.default,
31
+ index$7.default,
32
+ index$8.default
232
33
  ];
233
- const scripts = {
234
- build: "pack-up build",
235
- clean: "run -T rimraf ./dist",
236
- lint: "run -T eslint .",
237
- "test:unit": "run -T jest",
238
- watch: "pack-up watch"
239
- };
240
- const dependencies = {
241
- "@strapi/utils": "workspace:*",
242
- axios: "1.7.4",
243
- chalk: "4.1.2",
244
- "cli-progress": "3.12.0",
245
- commander: "8.3.0",
246
- eventsource: "2.0.2",
247
- "fast-safe-stringify": "2.1.1",
248
- "fs-extra": "11.2.0",
249
- inquirer: "8.2.5",
250
- jsonwebtoken: "9.0.0",
251
- "jwks-rsa": "3.1.0",
252
- lodash: "4.17.21",
253
- minimatch: "9.0.3",
254
- open: "8.4.0",
255
- ora: "5.4.1",
256
- "pkg-up": "3.1.0",
257
- tar: "6.2.1",
258
- "xdg-app-paths": "8.3.0",
259
- yup: "0.32.9"
260
- };
261
- const devDependencies = {
262
- "@strapi/pack-up": "4.23.0",
263
- "@types/cli-progress": "3.11.5",
264
- "@types/eventsource": "1.1.15",
265
- "@types/lodash": "^4.14.191",
266
- "eslint-config-custom": "workspace:*",
267
- tsconfig: "workspace:*"
268
- };
269
- const engines = {
270
- node: ">=18.0.0 <=22.x.x",
271
- npm: ">=6.0.0"
272
- };
273
- const packageJson = {
274
- name,
275
- version,
276
- description,
277
- keywords,
278
- homepage,
279
- bugs,
280
- repository,
281
- license,
282
- author,
283
- maintainers,
284
- main,
285
- module: module$1,
286
- source,
287
- types,
288
- bin,
289
- files,
290
- scripts,
291
- dependencies,
292
- devDependencies,
293
- engines
294
- };
295
- const VERSION = "v1";
296
- async function cloudApiFactory({ logger }, token) {
297
- const localConfig = await getLocalConfig();
298
- const customHeaders = {
299
- "x-device-id": localConfig.deviceId,
300
- "x-app-version": packageJson.version,
301
- "x-os-name": os__default.default.type(),
302
- "x-os-version": os__default.default.version(),
303
- "x-language": Intl.DateTimeFormat().resolvedOptions().locale,
304
- "x-node-version": process.versions.node
305
- };
306
- const axiosCloudAPI = axios__default.default.create({
307
- baseURL: `${apiConfig.apiBaseUrl}/${VERSION}`,
308
- headers: {
309
- "Content-Type": "application/json",
310
- ...customHeaders
311
- }
312
- });
313
- if (token) {
314
- axiosCloudAPI.defaults.headers.Authorization = `Bearer ${token}`;
315
- }
316
- return {
317
- deploy({ filePath, project }, { onUploadProgress }) {
318
- return axiosCloudAPI.post(
319
- `/deploy/${project.name}`,
320
- { file: fse__namespace.default.createReadStream(filePath) },
321
- {
322
- headers: {
323
- "Content-Type": "multipart/form-data"
324
- },
325
- onUploadProgress
326
- }
327
- );
328
- },
329
- async createProject({ name: name2, nodeVersion, region, plan }) {
330
- const response = await axiosCloudAPI.post("/project", {
331
- projectName: name2,
332
- region,
333
- nodeVersion,
334
- plan
335
- });
336
- return {
337
- data: {
338
- id: response.data.id,
339
- name: response.data.name,
340
- nodeVersion: response.data.nodeVersion,
341
- region: response.data.region
342
- },
343
- status: response.status
344
- };
345
- },
346
- getUserInfo() {
347
- return axiosCloudAPI.get("/user");
348
- },
349
- async config() {
350
- try {
351
- const response = await axiosCloudAPI.get("/config");
352
- if (response.status !== 200) {
353
- throw new Error("Error fetching cloud CLI config from the server.");
354
- }
355
- return response;
356
- } catch (error) {
357
- logger.debug(
358
- "🥲 Oops! Couldn't retrieve the cloud CLI config from the server. Please try again."
359
- );
360
- throw error;
361
- }
362
- },
363
- async listProjects() {
364
- try {
365
- const response = await axiosCloudAPI.get("/projects");
366
- if (response.status !== 200) {
367
- throw new Error("Error fetching cloud projects from the server.");
368
- }
369
- return response;
370
- } catch (error) {
371
- logger.debug(
372
- "🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
373
- );
374
- throw error;
375
- }
376
- },
377
- async listLinkProjects() {
378
- try {
379
- const response = await axiosCloudAPI.get("/projects-linkable");
380
- if (response.status !== 200) {
381
- throw new Error("Error fetching cloud projects from the server.");
382
- }
383
- return response;
384
- } catch (error) {
385
- logger.debug(
386
- "🥲 Oops! Couldn't retrieve your project's list from the server. Please try again."
387
- );
388
- throw error;
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
- },
419
- track(event, payload = {}) {
420
- return axiosCloudAPI.post("/track", {
421
- event,
422
- payload
423
- });
424
- }
425
- };
426
- }
427
- const LOCAL_SAVE_FILENAME = ".strapi-cloud.json";
428
- async function save(data, { directoryPath } = {}) {
429
- const alreadyInFileData = await retrieve({ directoryPath });
430
- const storedData = { ...alreadyInFileData, ...data };
431
- const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
432
- await fse__namespace.default.ensureDir(path__namespace.default.dirname(pathToFile));
433
- await fse__namespace.default.writeJson(pathToFile, storedData, { encoding: "utf8" });
434
- }
435
- async function retrieve({
436
- directoryPath
437
- } = {}) {
438
- const pathToFile = path__namespace.default.join(directoryPath || process.cwd(), LOCAL_SAVE_FILENAME);
439
- const pathExists = await fse__namespace.default.pathExists(pathToFile);
440
- if (!pathExists) {
441
- return {};
442
- }
443
- return fse__namespace.default.readJSON(pathToFile, { encoding: "utf8" });
444
- }
445
- const strapiInfoSave = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
446
- __proto__: null,
447
- LOCAL_SAVE_FILENAME,
448
- retrieve,
449
- save
450
- }, Symbol.toStringTag, { value: "Module" }));
451
- let cliConfig;
452
- async function tokenServiceFactory({ logger }) {
453
- const cloudApiService = await cloudApiFactory({ logger });
454
- async function saveToken(str) {
455
- const appConfig = await getLocalConfig();
456
- if (!appConfig) {
457
- logger.error("There was a problem saving your token. Please try again.");
458
- return;
459
- }
460
- appConfig.token = str;
461
- try {
462
- await saveLocalConfig(appConfig);
463
- } catch (e) {
464
- logger.debug(e);
465
- logger.error("There was a problem saving your token. Please try again.");
466
- }
467
- }
468
- async function retrieveToken() {
469
- const appConfig = await getLocalConfig();
470
- if (appConfig.token) {
471
- if (await isTokenValid(appConfig.token)) {
472
- return appConfig.token;
473
- }
474
- }
475
- return void 0;
476
- }
477
- async function validateToken(idToken, jwksUrl) {
478
- const client = jwksClient__default.default({
479
- jwksUri: jwksUrl
480
- });
481
- const getKey = (header, callback) => {
482
- client.getSigningKey(header.kid, (e, key) => {
483
- if (e) {
484
- callback(e);
485
- } else if (key) {
486
- const publicKey = "publicKey" in key ? key.publicKey : key.rsaPublicKey;
487
- callback(null, publicKey);
488
- } else {
489
- callback(new Error("Key not found"));
490
- }
491
- });
492
- };
493
- const decodedToken = jwt__default.default.decode(idToken, { complete: true });
494
- if (!decodedToken) {
495
- if (typeof idToken === "undefined" || idToken === "") {
496
- logger.warn("You need to be logged in to use this feature. Please log in and try again.");
497
- } else {
498
- logger.error(
499
- "There seems to be a problem with your login information. Please try logging in again."
500
- );
501
- }
502
- return Promise.reject(new Error("Invalid token"));
503
- }
504
- return new Promise((resolve, reject) => {
505
- jwt__default.default.verify(idToken, getKey, (err) => {
506
- if (err) {
507
- reject(err);
508
- }
509
- if (decodedToken.payload.exp < Math.floor(Date.now() / 1e3)) {
510
- reject(new Error("Token is expired"));
511
- }
512
- resolve();
513
- });
514
- });
515
- }
516
- async function isTokenValid(token) {
517
- try {
518
- const config = await cloudApiService.config();
519
- cliConfig = config.data;
520
- if (token) {
521
- await validateToken(token, cliConfig.jwksUrl);
522
- return true;
523
- }
524
- return false;
525
- } catch (e) {
526
- logger.debug(e);
527
- return false;
528
- }
529
- }
530
- async function eraseToken() {
531
- const appConfig = await getLocalConfig();
532
- if (!appConfig) {
533
- return;
534
- }
535
- delete appConfig.token;
536
- try {
537
- await saveLocalConfig(appConfig);
538
- } catch (e) {
539
- logger.debug(e);
540
- logger.error(
541
- "There was an issue removing your login information. Please try logging out again."
542
- );
543
- throw e;
544
- }
545
- }
546
- async function getValidToken(ctx, loginAction2) {
547
- let token = await retrieveToken();
548
- while (!token || !await isTokenValid(token)) {
549
- logger.log(
550
- token ? "Oops! Your token seems expired or invalid. Please login again." : "We couldn't find a valid token. You need to be logged in to use this feature."
551
- );
552
- if (!await loginAction2(ctx))
553
- return null;
554
- token = await retrieveToken();
555
- }
556
- return token;
557
- }
558
- return {
559
- saveToken,
560
- retrieveToken,
561
- validateToken,
562
- isTokenValid,
563
- eraseToken,
564
- getValidToken
565
- };
566
- }
567
- const stringifyArg = (arg) => {
568
- return typeof arg === "object" ? stringify__default.default(arg) : arg;
569
- };
570
- const createLogger = (options = {}) => {
571
- const { silent = false, debug = false, timestamp = true } = options;
572
- const state = { errors: 0, warning: 0 };
573
- return {
574
- get warnings() {
575
- return state.warning;
576
- },
577
- get errors() {
578
- return state.errors;
579
- },
580
- async debug(...args) {
581
- if (silent || !debug) {
582
- return;
583
- }
584
- console.log(
585
- chalk__default.default.cyan(`[DEBUG]${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`),
586
- ...args.map(stringifyArg)
587
- );
588
- },
589
- info(...args) {
590
- if (silent) {
591
- return;
592
- }
593
- console.info(
594
- chalk__default.default.blue(`[INFO]${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`),
595
- ...args.map(stringifyArg)
596
- );
597
- },
598
- log(...args) {
599
- if (silent) {
600
- return;
601
- }
602
- console.info(
603
- chalk__default.default.blue(`${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`),
604
- ...args.map(stringifyArg)
605
- );
606
- },
607
- success(...args) {
608
- if (silent) {
609
- return;
610
- }
611
- console.info(
612
- chalk__default.default.green(`[SUCCESS]${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`),
613
- ...args.map(stringifyArg)
614
- );
615
- },
616
- warn(...args) {
617
- state.warning += 1;
618
- if (silent) {
619
- return;
620
- }
621
- console.warn(
622
- chalk__default.default.yellow(`[WARN]${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`),
623
- ...args.map(stringifyArg)
624
- );
625
- },
626
- error(...args) {
627
- state.errors += 1;
628
- if (silent) {
629
- return;
630
- }
631
- console.error(
632
- chalk__default.default.red(`[ERROR]${timestamp ? ` [${(/* @__PURE__ */ new Date()).toISOString()}]` : ""}`),
633
- ...args.map(stringifyArg)
634
- );
635
- },
636
- // @ts-expect-error – returning a subpart of ora is fine because the types tell us what is what.
637
- spinner(text) {
638
- if (silent) {
639
- return {
640
- succeed() {
641
- return this;
642
- },
643
- fail() {
644
- return this;
645
- },
646
- start() {
647
- return this;
648
- },
649
- text: "",
650
- isSpinning: false
651
- };
652
- }
653
- return ora__default.default(text);
654
- },
655
- progressBar(totalSize, text) {
656
- if (silent) {
657
- return {
658
- start() {
659
- return this;
660
- },
661
- stop() {
662
- return this;
663
- },
664
- update() {
665
- return this;
666
- }
667
- };
668
- }
669
- const progressBar = new cliProgress__namespace.SingleBar({
670
- format: `${text ? `${text} |` : ""}${chalk__default.default.green("{bar}")}| {percentage}%`,
671
- barCompleteChar: "█",
672
- barIncompleteChar: "░",
673
- hideCursor: true,
674
- forceRedraw: true
675
- });
676
- progressBar.start(totalSize, 0);
677
- return progressBar;
678
- }
679
- };
680
- };
681
- const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
682
- __proto__: null,
683
- cloudApiFactory,
684
- createLogger,
685
- local: strapiInfoSave,
686
- tokenServiceFactory
687
- }, Symbol.toStringTag, { value: "Module" }));
688
- yup__namespace.object({
689
- name: yup__namespace.string().required(),
690
- exports: yup__namespace.lazy(
691
- (value) => yup__namespace.object(
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
710
- ).optional()
711
- )
712
- });
713
- const loadPkg = async ({ cwd, logger }) => {
714
- const pkgPath = await pkgUp__default.default({ cwd });
715
- if (!pkgPath) {
716
- throw new Error("Could not find a package.json in the current directory");
717
- }
718
- const buffer = await fse__namespace.readFile(pkgPath);
719
- const pkg = JSON.parse(buffer.toString());
720
- logger.debug("Loaded package.json:", os__default.default.EOL, pkg);
721
- return pkg;
722
- };
723
- async function getProjectNameFromPackageJson(ctx) {
724
- try {
725
- const packageJson2 = await loadPkg(ctx);
726
- return packageJson2.name || "my-strapi-project";
727
- } catch (e) {
728
- return "my-strapi-project";
729
- }
730
- }
731
- const trackEvent = async (ctx, cloudApiService, eventName, eventData) => {
732
- try {
733
- await cloudApiService.track(eventName, eventData);
734
- } catch (e) {
735
- ctx.logger.debug(`Failed to track ${eventName}`, e);
736
- }
737
- };
738
- const openModule$1 = import("open");
739
- async function promptLogin(ctx) {
740
- const response = await inquirer__default.default.prompt([
741
- {
742
- type: "confirm",
743
- name: "login",
744
- message: "Would you like to login?"
745
- }
746
- ]);
747
- if (response.login) {
748
- const loginSuccessful = await loginAction(ctx);
749
- return loginSuccessful;
750
- }
751
- return false;
752
- }
753
- async function loginAction(ctx) {
754
- const { logger } = ctx;
755
- const tokenService = await tokenServiceFactory(ctx);
756
- const existingToken = await tokenService.retrieveToken();
757
- const cloudApiService = await cloudApiFactory(ctx, existingToken || void 0);
758
- if (existingToken) {
759
- const isTokenValid = await tokenService.isTokenValid(existingToken);
760
- if (isTokenValid) {
761
- try {
762
- const userInfo = await cloudApiService.getUserInfo();
763
- const { email } = userInfo.data.data;
764
- if (email) {
765
- logger.log(`You are already logged into your account (${email}).`);
766
- } else {
767
- logger.log("You are already logged in.");
768
- }
769
- logger.log(
770
- "To access your dashboard, please copy and paste the following URL into your web browser:"
771
- );
772
- logger.log(chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects`));
773
- return true;
774
- } catch (e) {
775
- logger.debug("Failed to fetch user info", e);
776
- }
777
- }
778
- }
779
- let cliConfig2;
780
- try {
781
- logger.info("🔌 Connecting to the Strapi Cloud API...");
782
- const config = await cloudApiService.config();
783
- cliConfig2 = config.data;
784
- } catch (e) {
785
- logger.error("🥲 Oops! Something went wrong while logging you in. Please try again.");
786
- logger.debug(e);
787
- return false;
788
- }
789
- await trackEvent(ctx, cloudApiService, "willLoginAttempt", {});
790
- logger.debug("🔐 Creating device authentication request...", {
791
- client_id: cliConfig2.clientId,
792
- scope: cliConfig2.scope,
793
- audience: cliConfig2.audience
794
- });
795
- const deviceAuthResponse = await axios__default.default.post(cliConfig2.deviceCodeAuthUrl, {
796
- client_id: cliConfig2.clientId,
797
- scope: cliConfig2.scope,
798
- audience: cliConfig2.audience
799
- }).catch((e) => {
800
- logger.error("There was an issue with the authentication process. Please try again.");
801
- if (e.message) {
802
- logger.debug(e.message, e);
803
- } else {
804
- logger.debug(e);
805
- }
806
- });
807
- openModule$1.then((open) => {
808
- open.default(deviceAuthResponse.data.verification_uri_complete).catch((e) => {
809
- logger.error("We encountered an issue opening the browser. Please try again later.");
810
- logger.debug(e.message, e);
811
- });
812
- });
813
- logger.log("If a browser tab does not open automatically, please follow the next steps:");
814
- logger.log(
815
- `1. Open this url in your device: ${deviceAuthResponse.data.verification_uri_complete}`
816
- );
817
- logger.log(
818
- `2. Enter the following code: ${deviceAuthResponse.data.user_code} and confirm to login.
819
- `
820
- );
821
- const tokenPayload = {
822
- grant_type: "urn:ietf:params:oauth:grant-type:device_code",
823
- device_code: deviceAuthResponse.data.device_code,
824
- client_id: cliConfig2.clientId
825
- };
826
- let isAuthenticated = false;
827
- const authenticate = async () => {
828
- const spinner = logger.spinner("Waiting for authentication");
829
- spinner.start();
830
- const spinnerFail = () => spinner.fail("Authentication failed!");
831
- while (!isAuthenticated) {
832
- try {
833
- const tokenResponse = await axios__default.default.post(cliConfig2.tokenUrl, tokenPayload);
834
- const authTokenData = tokenResponse.data;
835
- if (tokenResponse.status === 200) {
836
- try {
837
- logger.debug("🔐 Validating token...");
838
- await tokenService.validateToken(authTokenData.id_token, cliConfig2.jwksUrl);
839
- logger.debug("🔐 Token validation successful!");
840
- } catch (e) {
841
- logger.debug(e);
842
- spinnerFail();
843
- throw new Error("Unable to proceed: Token validation failed");
844
- }
845
- logger.debug("🔍 Fetching user information...");
846
- const cloudApiServiceWithToken = await cloudApiFactory(ctx, authTokenData.access_token);
847
- await cloudApiServiceWithToken.getUserInfo();
848
- logger.debug("🔍 User information fetched successfully!");
849
- try {
850
- logger.debug("📝 Saving login information...");
851
- await tokenService.saveToken(authTokenData.access_token);
852
- logger.debug("📝 Login information saved successfully!");
853
- isAuthenticated = true;
854
- } catch (e) {
855
- logger.error(
856
- "There was a problem saving your login information. Please try logging in again."
857
- );
858
- logger.debug(e);
859
- spinnerFail();
860
- return false;
861
- }
862
- }
863
- } catch (e) {
864
- if (e.message === "Unable to proceed: Token validation failed") {
865
- logger.error(
866
- "There seems to be a problem with your login information. Please try logging in again."
867
- );
868
- spinnerFail();
869
- await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
870
- return false;
871
- }
872
- if (e.response?.data.error && !["authorization_pending", "slow_down"].includes(e.response.data.error)) {
873
- logger.debug(e);
874
- spinnerFail();
875
- await trackEvent(ctx, cloudApiService, "didNotLogin", { loginMethod: "cli" });
876
- return false;
877
- }
878
- await new Promise((resolve) => {
879
- setTimeout(resolve, deviceAuthResponse.data.interval * 1e3);
880
- });
881
- }
882
- }
883
- spinner.succeed("Authentication successful!");
884
- logger.log("You are now logged into Strapi Cloud.");
885
- logger.log(
886
- "To access your dashboard, please copy and paste the following URL into your web browser:"
887
- );
888
- logger.log(chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects`));
889
- await trackEvent(ctx, cloudApiService, "didLogin", { loginMethod: "cli" });
890
- };
891
- await authenticate();
892
- return isAuthenticated;
893
- }
894
- function questionDefaultValuesMapper(questionsMap) {
895
- return (questions) => {
896
- return questions.map((question) => {
897
- const questionName = question.name;
898
- if (questionName in questionsMap) {
899
- const questionDefault = questionsMap[questionName];
900
- if (typeof questionDefault === "function") {
901
- return {
902
- ...question,
903
- default: questionDefault(question)
904
- };
905
- }
906
- return {
907
- ...question,
908
- default: questionDefault
909
- };
910
- }
911
- return question;
912
- });
913
- };
914
- }
915
- function getDefaultsFromQuestions(questions) {
916
- return questions.reduce((acc, question) => {
917
- if (question.default && question.name) {
918
- return { ...acc, [question.name]: question.default };
919
- }
920
- return acc;
921
- }, {});
922
- }
923
- function getProjectNodeVersionDefault(question) {
924
- const currentNodeVersion = process.versions.node.split(".")[0];
925
- if (question.type === "list" && Array.isArray(question.choices)) {
926
- const choice = question.choices.find((choice2) => choice2.value === currentNodeVersion);
927
- if (choice) {
928
- return choice.value;
929
- }
930
- }
931
- return question.default;
932
- }
933
- async function handleError(ctx, error) {
934
- const { logger } = ctx;
935
- logger.debug(error);
936
- if (error instanceof axios.AxiosError) {
937
- const errorMessage = typeof error.response?.data === "string" ? error.response.data : null;
938
- switch (error.response?.status) {
939
- case 403:
940
- logger.error(
941
- errorMessage || "You do not have permission to create a project. Please contact support for assistance."
942
- );
943
- return;
944
- case 400:
945
- logger.error(errorMessage || "Invalid input. Please check your inputs and try again.");
946
- return;
947
- case 503:
948
- logger.error(
949
- "Strapi Cloud project creation is currently unavailable. Please try again later."
950
- );
951
- return;
952
- default:
953
- if (errorMessage) {
954
- logger.error(errorMessage);
955
- return;
956
- }
957
- break;
958
- }
959
- }
960
- logger.error(
961
- "We encountered an issue while creating your project. Please try again in a moment. If the problem persists, contact support for assistance."
962
- );
963
- }
964
- async function createProject$1(ctx, cloudApi, projectInput) {
965
- const { logger } = ctx;
966
- const spinner = logger.spinner("Setting up your project...").start();
967
- try {
968
- const { data } = await cloudApi.createProject(projectInput);
969
- await save({ project: data });
970
- spinner.succeed("Project created successfully!");
971
- return data;
972
- } catch (e) {
973
- spinner.fail("An error occurred while creating the project on Strapi Cloud.");
974
- throw e;
975
- }
976
- }
977
- const action$5 = async (ctx) => {
978
- const { logger } = ctx;
979
- const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
980
- const token = await getValidToken(ctx, promptLogin);
981
- if (!token) {
982
- return;
983
- }
984
- const cloudApi = await cloudApiFactory(ctx, token);
985
- const { data: config } = await cloudApi.config();
986
- const projectName = await getProjectNameFromPackageJson(ctx);
987
- const defaultAnswersMapper = questionDefaultValuesMapper({
988
- name: projectName,
989
- nodeVersion: getProjectNodeVersionDefault
990
- });
991
- const questions = defaultAnswersMapper(config.projectCreation.questions);
992
- const defaultValues = {
993
- ...config.projectCreation.defaults,
994
- ...getDefaultsFromQuestions(questions)
995
- };
996
- const projectAnswersDefaulted = fp.defaults(defaultValues);
997
- const projectAnswers = await inquirer__default.default.prompt(questions);
998
- const projectInput = projectAnswersDefaulted(projectAnswers);
999
- try {
1000
- return await createProject$1(ctx, cloudApi, projectInput);
1001
- } catch (e) {
1002
- if (e instanceof axios.AxiosError && e.response?.status === 401) {
1003
- logger.warn("Oops! Your session has expired. Please log in again to retry.");
1004
- await eraseToken();
1005
- if (await promptLogin(ctx)) {
1006
- return await createProject$1(ctx, cloudApi, projectInput);
1007
- }
1008
- } else {
1009
- await handleError(ctx, e);
1010
- }
1011
- }
1012
- };
1013
- function notificationServiceFactory({ logger }) {
1014
- return (url, token, cliConfig2) => {
1015
- const CONN_TIMEOUT = Number(cliConfig2.notificationsConnectionTimeout);
1016
- const es = new EventSource__default.default(url, {
1017
- headers: {
1018
- Authorization: `Bearer ${token}`
1019
- }
1020
- });
1021
- let timeoutId;
1022
- const resetTimeout = () => {
1023
- clearTimeout(timeoutId);
1024
- timeoutId = setTimeout(() => {
1025
- logger.log(
1026
- "We were unable to connect to the server at this time. This could be due to a temporary issue. Please try again in a moment."
1027
- );
1028
- es.close();
1029
- }, CONN_TIMEOUT);
1030
- };
1031
- es.onopen = resetTimeout;
1032
- es.onmessage = (event) => {
1033
- resetTimeout();
1034
- const data = JSON.parse(event.data);
1035
- if (data.message) {
1036
- logger.log(data.message);
1037
- }
1038
- if (data.event === "deploymentFinished" || data.event === "deploymentFailed") {
1039
- es.close();
1040
- }
1041
- };
1042
- };
1043
- }
1044
- const buildLogsServiceFactory = ({ logger }) => {
1045
- return async (url, token, cliConfig2) => {
1046
- const CONN_TIMEOUT = Number(cliConfig2.buildLogsConnectionTimeout);
1047
- const MAX_RETRIES = Number(cliConfig2.buildLogsMaxRetries);
1048
- return new Promise((resolve, reject) => {
1049
- let timeoutId = null;
1050
- let retries = 0;
1051
- const connect = (url2) => {
1052
- const spinner = logger.spinner("Connecting to server to get build logs");
1053
- spinner.start();
1054
- const es = new EventSource__default.default(`${url2}`, {
1055
- headers: {
1056
- Authorization: `Bearer ${token}`
1057
- }
1058
- });
1059
- const clearExistingTimeout = () => {
1060
- if (timeoutId) {
1061
- clearTimeout(timeoutId);
1062
- }
1063
- };
1064
- const resetTimeout = () => {
1065
- clearExistingTimeout();
1066
- timeoutId = setTimeout(() => {
1067
- if (spinner.isSpinning) {
1068
- spinner.fail(
1069
- "We were unable to connect to the server to get build logs at this time. This could be due to a temporary issue."
1070
- );
34
+ async function initCloudCLIConfig() {
35
+ const localConfig = await local.getLocalConfig();
36
+ if (!localConfig.installId) {
37
+ localConfig.installId = crypto.randomUUID();
38
+ }
39
+ await local.saveLocalConfig(localConfig);
40
+ }
41
+ async function buildStrapiCloudCommands({ command, ctx, argv }) {
42
+ await initCloudCLIConfig();
43
+ // Load all commands
44
+ for (const cloudCommand of cloudCommands){
45
+ try {
46
+ // Add this command to the Commander command object
47
+ const subCommand = await cloudCommand.command({
48
+ command,
49
+ ctx,
50
+ argv
51
+ });
52
+ if (subCommand) {
53
+ command.addCommand(subCommand);
1071
54
  }
1072
- es.close();
1073
- reject(new Error("Connection timed out"));
1074
- }, CONN_TIMEOUT);
1075
- };
1076
- es.onopen = resetTimeout;
1077
- es.addEventListener("finished", (event) => {
1078
- const data = JSON.parse(event.data);
1079
- logger.log(data.msg);
1080
- es.close();
1081
- clearExistingTimeout();
1082
- resolve(null);
1083
- });
1084
- es.addEventListener("log", (event) => {
1085
- if (spinner.isSpinning) {
1086
- spinner.succeed();
1087
- }
1088
- resetTimeout();
1089
- const data = JSON.parse(event.data);
1090
- logger.log(data.msg);
1091
- });
1092
- es.onerror = async () => {
1093
- retries += 1;
1094
- if (retries > MAX_RETRIES) {
1095
- spinner.fail("We were unable to connect to the server to get build logs at this time.");
1096
- es.close();
1097
- clearExistingTimeout();
1098
- reject(new Error("Max retries reached"));
1099
- }
1100
- };
1101
- };
1102
- connect(url);
1103
- });
1104
- };
1105
- };
1106
- async function upload(ctx, project, token, maxProjectFileSize) {
1107
- const cloudApi = await cloudApiFactory(ctx, token);
1108
- try {
1109
- const storagePath = await getTmpStoragePath();
1110
- const projectFolder = path__namespace.default.resolve(process.cwd());
1111
- const packageJson2 = await loadPkg(ctx);
1112
- if (!packageJson2) {
1113
- ctx.logger.error(
1114
- "Unable to deploy the project. Please make sure the package.json file is correctly formatted."
1115
- );
1116
- return;
1117
- }
1118
- ctx.logger.log("📦 Compressing project...");
1119
- const hashname = crypto__namespace.createHash("sha512").update(packageJson2.name).digest("hex");
1120
- const compressedFilename = `${hashname}.tar.gz`;
1121
- try {
1122
- ctx.logger.debug(
1123
- "Compression parameters\n",
1124
- `Storage path: ${storagePath}
1125
- `,
1126
- `Project folder: ${projectFolder}
1127
- `,
1128
- `Compressed filename: ${compressedFilename}`
1129
- );
1130
- await compressFilesToTar(storagePath, projectFolder, compressedFilename);
1131
- ctx.logger.log("📦 Project compressed successfully!");
1132
- } catch (e) {
1133
- ctx.logger.error(
1134
- "⚠️ Project compression failed. Try again later or check for large/incompatible files."
1135
- );
1136
- ctx.logger.debug(e);
1137
- process.exit(1);
1138
- }
1139
- const tarFilePath = path__namespace.default.resolve(storagePath, compressedFilename);
1140
- const fileStats = await fse__namespace.default.stat(tarFilePath);
1141
- if (fileStats.size > maxProjectFileSize) {
1142
- ctx.logger.log(
1143
- "Unable to proceed: Your project is too big to be transferred, please use a git repo instead."
1144
- );
1145
- try {
1146
- await fse__namespace.default.remove(tarFilePath);
1147
- } catch (e) {
1148
- ctx.logger.log("Unable to remove file: ", tarFilePath);
1149
- ctx.logger.debug(e);
1150
- }
1151
- return;
1152
- }
1153
- ctx.logger.info("🚀 Uploading project...");
1154
- const progressBar = ctx.logger.progressBar(100, "Upload Progress");
1155
- try {
1156
- const { data } = await cloudApi.deploy(
1157
- { filePath: tarFilePath, project },
1158
- {
1159
- onUploadProgress(progressEvent) {
1160
- const total = progressEvent.total || fileStats.size;
1161
- const percentage = Math.round(progressEvent.loaded * 100 / total);
1162
- progressBar.update(percentage);
1163
- }
55
+ } catch (e) {
56
+ console.error(`Failed to load command ${cloudCommand.name}`, e);
1164
57
  }
1165
- );
1166
- progressBar.update(100);
1167
- progressBar.stop();
1168
- ctx.logger.success("✨ Upload finished!");
1169
- return data.build_id;
1170
- } catch (e) {
1171
- progressBar.stop();
1172
- ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1173
- ctx.logger.debug(e);
1174
- } finally {
1175
- await fse__namespace.default.remove(tarFilePath);
1176
- }
1177
- process.exit(0);
1178
- } catch (e) {
1179
- ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1180
- ctx.logger.debug(e);
1181
- process.exit(1);
1182
- }
1183
- }
1184
- async function getProject$1(ctx) {
1185
- const { project } = await retrieve();
1186
- if (!project) {
1187
- try {
1188
- return await action$5(ctx);
1189
- } catch (e) {
1190
- ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1191
- ctx.logger.debug(e);
1192
- process.exit(1);
1193
- }
1194
- }
1195
- return project;
1196
- }
1197
- async function getConfig({
1198
- ctx,
1199
- cloudApiService
1200
- }) {
1201
- try {
1202
- const { data: cliConfig2 } = await cloudApiService.config();
1203
- return cliConfig2;
1204
- } catch (e) {
1205
- ctx.logger.debug("Failed to get cli config", e);
1206
- return null;
1207
- }
1208
- }
1209
- const action$4 = async (ctx) => {
1210
- const { getValidToken } = await tokenServiceFactory(ctx);
1211
- const token = await getValidToken(ctx, promptLogin);
1212
- if (!token) {
1213
- return;
1214
- }
1215
- const project = await getProject$1(ctx);
1216
- if (!project) {
1217
- return;
1218
- }
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
- }
1252
- await trackEvent(ctx, cloudApiService, "willDeployWithCLI", {
1253
- projectInternalName: project.name
1254
- });
1255
- const notificationService = notificationServiceFactory(ctx);
1256
- const buildLogsService = buildLogsServiceFactory(ctx);
1257
- const cliConfig2 = await getConfig({ ctx, cloudApiService });
1258
- if (!cliConfig2) {
1259
- ctx.logger.error(
1260
- "An error occurred while retrieving data from Strapi Cloud. Please check your network or try again later."
1261
- );
1262
- return;
1263
- }
1264
- let maxSize = parseInt(cliConfig2.maxProjectFileSize, 10);
1265
- if (Number.isNaN(maxSize)) {
1266
- ctx.logger.debug(
1267
- "An error occurred while parsing the maxProjectFileSize. Using default value."
1268
- );
1269
- maxSize = 1e8;
1270
- }
1271
- const buildId = await upload(ctx, project, token, maxSize);
1272
- if (!buildId) {
1273
- return;
1274
- }
1275
- try {
1276
- notificationService(`${apiConfig.apiBaseUrl}/notifications`, token, cliConfig2);
1277
- await buildLogsService(`${apiConfig.apiBaseUrl}/v1/logs/${buildId}`, token, cliConfig2);
1278
- ctx.logger.log(
1279
- "Visit the following URL for deployment logs. Your deployment will be available here shortly."
1280
- );
1281
- ctx.logger.log(
1282
- chalk__default.default.underline(`${apiConfig.dashboardBaseUrl}/projects/${project.name}/deployments`)
1283
- );
1284
- } catch (e) {
1285
- ctx.logger.debug(e);
1286
- if (e instanceof Error) {
1287
- ctx.logger.error(e.message);
1288
- } else {
1289
- ctx.logger.error("An error occurred while deploying the project. Please try again later.");
1290
- }
1291
- }
1292
- };
1293
- const assertCwdContainsStrapiProject = (name2) => {
1294
- const logErrorAndExit = () => {
1295
- console.log(
1296
- `You need to run ${chalk__default.default.yellow(
1297
- `strapi ${name2}`
1298
- )} in a Strapi project. Make sure you are in the right directory.`
1299
- );
1300
- process.exit(1);
1301
- };
1302
- try {
1303
- const pkgJSON = require(`${process.cwd()}/package.json`);
1304
- if (!fp.has("dependencies.@strapi/strapi", pkgJSON) && !fp.has("devDependencies.@strapi/strapi", pkgJSON)) {
1305
- logErrorAndExit();
1306
- }
1307
- } catch (err) {
1308
- logErrorAndExit();
1309
- }
1310
- };
1311
- const runAction = (name2, action2) => (...args) => {
1312
- assertCwdContainsStrapiProject(name2);
1313
- Promise.resolve().then(() => {
1314
- return action2(...args);
1315
- }).catch((error) => {
1316
- console.error(error);
1317
- process.exit(1);
1318
- });
1319
- };
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));
1322
- };
1323
- const deployProject = {
1324
- name: "deploy-project",
1325
- description: "Deploy a Strapi Cloud project",
1326
- action: action$4,
1327
- command: command$6
1328
- };
1329
- const QUIT_OPTION = "Quit";
1330
- async function getExistingConfig(ctx) {
1331
- try {
1332
- return await retrieve();
1333
- } catch (e) {
1334
- ctx.logger.debug("Failed to get project config", e);
1335
- ctx.logger.error("An error occurred while retrieving config data from your local project.");
1336
- return null;
1337
- }
1338
- }
1339
- async function promptForRelink(ctx, cloudApiService, existingConfig) {
1340
- if (existingConfig && existingConfig.project) {
1341
- const { shouldRelink } = await inquirer__default.default.prompt([
1342
- {
1343
- type: "confirm",
1344
- name: "shouldRelink",
1345
- message: `A project named ${chalk__default.default.cyan(
1346
- existingConfig.project.displayName ? existingConfig.project.displayName : existingConfig.project.name
1347
- )} is already linked to this local folder. Do you want to update the link?`,
1348
- default: false
1349
- }
1350
- ]);
1351
- if (!shouldRelink) {
1352
- await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
1353
- currentProjectName: existingConfig.project?.name
1354
- });
1355
- return false;
1356
58
  }
1357
- }
1358
- return true;
1359
- }
1360
- async function getProjectsList(ctx, cloudApiService, existingConfig) {
1361
- const spinner = ctx.logger.spinner("Fetching your projects...\n").start();
1362
- try {
1363
- const {
1364
- data: { data: projectList }
1365
- } = await cloudApiService.listLinkProjects();
1366
- spinner.succeed();
1367
- if (!Array.isArray(projectList)) {
1368
- ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
1369
- return null;
1370
- }
1371
- const projects = projectList.filter(
1372
- (project) => !(project.isMaintainer || project.name === existingConfig?.project?.name)
1373
- ).map((project) => {
1374
- return {
1375
- name: project.displayName,
1376
- value: { name: project.name, displayName: project.displayName }
1377
- };
1378
- });
1379
- if (projects.length === 0) {
1380
- ctx.logger.log("We couldn't find any projects available for linking in Strapi Cloud");
1381
- return null;
1382
- }
1383
- return projects;
1384
- } catch (e) {
1385
- spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
1386
- ctx.logger.debug("Failed to list projects", e);
1387
- return null;
1388
- }
1389
- }
1390
- async function getUserSelection(ctx, projects) {
1391
- const { logger } = ctx;
1392
- try {
1393
- const answer = await inquirer__default.default.prompt([
1394
- {
1395
- type: "list",
1396
- name: "linkProject",
1397
- message: "Which project do you want to link?",
1398
- choices: [...projects, { name: chalk__default.default.grey(`(${QUIT_OPTION})`), value: null }]
1399
- }
1400
- ]);
1401
- if (!answer.linkProject) {
1402
- return null;
1403
- }
1404
- return answer;
1405
- } catch (e) {
1406
- logger.debug("Failed to get user input", e);
1407
- logger.error("An error occurred while trying to get your input.");
1408
- return null;
1409
- }
1410
- }
1411
- const action$3 = async (ctx) => {
1412
- const { getValidToken } = await tokenServiceFactory(ctx);
1413
- const token = await getValidToken(ctx, promptLogin);
1414
- const { logger } = ctx;
1415
- if (!token) {
1416
- return;
1417
- }
1418
- const cloudApiService = await cloudApiFactory(ctx, token);
1419
- const existingConfig = await getExistingConfig(ctx);
1420
- const shouldRelink = await promptForRelink(ctx, cloudApiService, existingConfig);
1421
- if (!shouldRelink) {
1422
- return;
1423
- }
1424
- await trackEvent(ctx, cloudApiService, "willLinkProject", {});
1425
- const projects = await getProjectsList(
1426
- ctx,
1427
- cloudApiService,
1428
- existingConfig
1429
- );
1430
- if (!projects) {
1431
- return;
1432
- }
1433
- const answer = await getUserSelection(ctx, projects);
1434
- if (!answer) {
1435
- return;
1436
- }
1437
- try {
1438
- const { confirmAction } = await inquirer__default.default.prompt([
1439
- {
1440
- type: "confirm",
1441
- name: "confirmAction",
1442
- message: "Warning: Once linked, deploying from CLI will replace the existing project and its data. Confirm to proceed:",
1443
- default: false
1444
- }
1445
- ]);
1446
- if (!confirmAction) {
1447
- await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
1448
- cancelledProjectName: answer.linkProject.name,
1449
- currentProjectName: existingConfig ? existingConfig.project?.name : null
1450
- });
1451
- return;
1452
- }
1453
- await save({ project: answer.linkProject });
1454
- logger.log(`Project ${chalk__default.default.cyan(answer.linkProject.displayName)} linked successfully.`);
1455
- await trackEvent(ctx, cloudApiService, "didLinkProject", {
1456
- projectInternalName: answer.linkProject
1457
- });
1458
- } catch (e) {
1459
- logger.debug("Failed to link project", e);
1460
- logger.error("An error occurred while linking the project.");
1461
- await trackEvent(ctx, cloudApiService, "didNotLinkProject", {
1462
- projectInternalName: answer.linkProject
1463
- });
1464
- }
1465
- };
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));
1468
- };
1469
- const link = {
1470
- name: "link-project",
1471
- description: "Link a local directory to a Strapi Cloud project",
1472
- action: action$3,
1473
- command: command$5
1474
- };
1475
- const command$4 = ({ ctx }) => {
1476
- return commander.createCommand("cloud:login").alias("login").description("Strapi Cloud Login").addHelpText(
1477
- "after",
1478
- "\nAfter running this command, you will be prompted to enter your authentication information."
1479
- ).option("-d, --debug", "Enable debugging mode with verbose logs").option("-s, --silent", "Don't log anything").action(() => runAction("login", loginAction)(ctx));
1480
- };
1481
- const login = {
1482
- name: "login",
1483
- description: "Strapi Cloud Login",
1484
- action: loginAction,
1485
- command: command$4
1486
- };
1487
- const openModule = import("open");
1488
- const action$2 = async (ctx) => {
1489
- const { logger } = ctx;
1490
- const { retrieveToken, eraseToken } = await tokenServiceFactory(ctx);
1491
- const token = await retrieveToken();
1492
- if (!token) {
1493
- logger.log("You're already logged out.");
1494
- return;
1495
- }
1496
- const cloudApiService = await cloudApiFactory(ctx, token);
1497
- const config = await cloudApiService.config();
1498
- const cliConfig2 = config.data;
1499
- try {
1500
- await eraseToken();
1501
- openModule.then((open) => {
1502
- open.default(
1503
- `${cliConfig2.baseUrl}/oidc/logout?client_id=${encodeURIComponent(
1504
- cliConfig2.clientId
1505
- )}&logout_hint=${encodeURIComponent(token)}
1506
- `
1507
- ).catch((e) => {
1508
- logger.debug(e.message, e);
1509
- });
1510
- });
1511
- logger.log(
1512
- "🔌 You have been logged out from the CLI. If you are on a shared computer, please make sure to log out from the Strapi Cloud Dashboard as well."
1513
- );
1514
- } catch (e) {
1515
- logger.error("🥲 Oops! Something went wrong while logging you out. Please try again.");
1516
- logger.debug(e);
1517
- }
1518
- await trackEvent(ctx, cloudApiService, "didLogout", { loginMethod: "cli" });
1519
- };
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));
1522
- };
1523
- const logout = {
1524
- name: "logout",
1525
- description: "Strapi Cloud Logout",
1526
- action: action$2,
1527
- command: command$3
1528
- };
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));
1531
- };
1532
- const createProject = {
1533
- name: "create-project",
1534
- description: "Create a new project",
1535
- action: action$5,
1536
- command: command$2
1537
- };
1538
- const action$1 = async (ctx) => {
1539
- const { getValidToken } = await tokenServiceFactory(ctx);
1540
- const token = await getValidToken(ctx, promptLogin);
1541
- const { logger } = ctx;
1542
- if (!token) {
1543
- return;
1544
- }
1545
- const cloudApiService = await cloudApiFactory(ctx, token);
1546
- const spinner = logger.spinner("Fetching your projects...").start();
1547
- try {
1548
- const {
1549
- data: { data: projectList }
1550
- } = await cloudApiService.listProjects();
1551
- spinner.succeed();
1552
- logger.log(projectList);
1553
- } catch (e) {
1554
- ctx.logger.debug("Failed to list projects", e);
1555
- spinner.fail("An error occurred while fetching your projects from Strapi Cloud.");
1556
- }
1557
- };
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));
1560
- };
1561
- const listProjects = {
1562
- name: "list-projects",
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",
1638
- action,
1639
- command
1640
- };
1641
- const cli = {
1642
- deployProject,
1643
- link,
1644
- login,
1645
- logout,
1646
- createProject,
1647
- listProjects,
1648
- listEnvironments
1649
- };
1650
- const cloudCommands = [deployProject, link, login, logout, listProjects, listEnvironments];
1651
- async function initCloudCLIConfig() {
1652
- const localConfig = await getLocalConfig();
1653
- if (!localConfig.deviceId) {
1654
- localConfig.deviceId = crypto__default.default.randomUUID();
1655
- }
1656
- await saveLocalConfig(localConfig);
1657
- }
1658
- async function buildStrapiCloudCommands({
1659
- command: command2,
1660
- ctx,
1661
- argv
1662
- }) {
1663
- await initCloudCLIConfig();
1664
- for (const cloudCommand of cloudCommands) {
1665
- try {
1666
- const subCommand = await cloudCommand.command({ command: command2, ctx, argv });
1667
- if (subCommand) {
1668
- command2.addCommand(subCommand);
1669
- }
1670
- } catch (e) {
1671
- console.error(`Failed to load command ${cloudCommand.name}`, e);
1672
- }
1673
- }
1674
59
  }
60
+
61
+ exports.services = index;
1675
62
  exports.buildStrapiCloudCommands = buildStrapiCloudCommands;
1676
63
  exports.cli = cli;
1677
- exports.services = index;
1678
64
  //# sourceMappingURL=index.js.map