checkly 5.3.1 → 5.4.0-prerelease-6249ef2

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 (443) hide show
  1. package/dist/auth/index.js +125 -132
  2. package/dist/auth/index.js.map +1 -1
  3. package/dist/commands/authCommand.js +1 -1
  4. package/dist/commands/authCommand.js.map +1 -1
  5. package/dist/commands/baseCommand.d.ts +2 -0
  6. package/dist/commands/baseCommand.js +7 -9
  7. package/dist/commands/baseCommand.js.map +1 -1
  8. package/dist/commands/deploy.js +55 -57
  9. package/dist/commands/deploy.js.map +1 -1
  10. package/dist/commands/destroy.js +15 -16
  11. package/dist/commands/destroy.js.map +1 -1
  12. package/dist/commands/env/add.js +28 -29
  13. package/dist/commands/env/add.js.map +1 -1
  14. package/dist/commands/env/ls.js +2 -2
  15. package/dist/commands/env/ls.js.map +1 -1
  16. package/dist/commands/env/pull.js +17 -17
  17. package/dist/commands/env/pull.js.map +1 -1
  18. package/dist/commands/env/rm.js +17 -18
  19. package/dist/commands/env/rm.js.map +1 -1
  20. package/dist/commands/env/update.js +29 -30
  21. package/dist/commands/env/update.js.map +1 -1
  22. package/dist/commands/help.js +2 -2
  23. package/dist/commands/help.js.map +1 -1
  24. package/dist/commands/import/apply.d.ts +14 -0
  25. package/dist/commands/import/apply.js +157 -0
  26. package/dist/commands/import/apply.js.map +1 -0
  27. package/dist/commands/import/cancel.d.ts +11 -0
  28. package/dist/commands/import/cancel.js +119 -0
  29. package/dist/commands/import/cancel.js.map +1 -0
  30. package/dist/commands/import/commit.d.ts +14 -0
  31. package/dist/commands/import/commit.js +141 -0
  32. package/dist/commands/import/commit.js.map +1 -0
  33. package/dist/commands/import/plan.d.ts +20 -0
  34. package/dist/commands/import/plan.js +1237 -0
  35. package/dist/commands/import/plan.js.map +1 -0
  36. package/dist/commands/login.js +38 -48
  37. package/dist/commands/login.js.map +1 -1
  38. package/dist/commands/logout.js +9 -9
  39. package/dist/commands/logout.js.map +1 -1
  40. package/dist/commands/runtimes.js +2 -2
  41. package/dist/commands/runtimes.js.map +1 -1
  42. package/dist/commands/switch.js +9 -9
  43. package/dist/commands/switch.js.map +1 -1
  44. package/dist/commands/sync-playwright.js +7 -7
  45. package/dist/commands/sync-playwright.js.map +1 -1
  46. package/dist/commands/test.js +107 -111
  47. package/dist/commands/test.js.map +1 -1
  48. package/dist/commands/trigger.js +74 -78
  49. package/dist/commands/trigger.js.map +1 -1
  50. package/dist/commands/whoami.js +2 -2
  51. package/dist/commands/whoami.js.map +1 -1
  52. package/dist/constructs/alert-channel-codegen.d.ts +35 -0
  53. package/dist/constructs/alert-channel-codegen.js +98 -0
  54. package/dist/constructs/alert-channel-codegen.js.map +1 -0
  55. package/dist/constructs/alert-channel-subscription-codegen.d.ts +11 -0
  56. package/dist/constructs/alert-channel-subscription-codegen.js +23 -0
  57. package/dist/constructs/alert-channel-subscription-codegen.js.map +1 -0
  58. package/dist/constructs/alert-channel-subscription.js +5 -1
  59. package/dist/constructs/alert-channel-subscription.js.map +1 -1
  60. package/dist/constructs/alert-channel.d.ts +17 -3
  61. package/dist/constructs/alert-channel.js +15 -4
  62. package/dist/constructs/alert-channel.js.map +1 -1
  63. package/dist/constructs/alert-escalation-policy-codegen.d.ts +4 -0
  64. package/dist/constructs/alert-escalation-policy-codegen.js +59 -0
  65. package/dist/constructs/alert-escalation-policy-codegen.js.map +1 -0
  66. package/dist/constructs/alert-escalation-policy.js +8 -9
  67. package/dist/constructs/alert-escalation-policy.js.map +1 -1
  68. package/dist/constructs/api-check-codegen.d.ts +21 -0
  69. package/dist/constructs/api-check-codegen.js +163 -0
  70. package/dist/constructs/api-check-codegen.js.map +1 -0
  71. package/dist/constructs/api-check.js +9 -0
  72. package/dist/constructs/api-check.js.map +1 -1
  73. package/dist/constructs/browser-check-codegen.d.ts +14 -0
  74. package/dist/constructs/browser-check-codegen.js +48 -0
  75. package/dist/constructs/browser-check-codegen.js.map +1 -0
  76. package/dist/constructs/browser-check.js +12 -6
  77. package/dist/constructs/browser-check.js.map +1 -1
  78. package/dist/constructs/check-codegen.d.ts +42 -0
  79. package/dist/constructs/check-codegen.js +208 -0
  80. package/dist/constructs/check-codegen.js.map +1 -0
  81. package/dist/constructs/check-group-codegen.d.ts +45 -0
  82. package/dist/constructs/check-group-codegen.js +266 -0
  83. package/dist/constructs/check-group-codegen.js.map +1 -0
  84. package/dist/constructs/check-group.d.ts +21 -8
  85. package/dist/constructs/check-group.js +65 -15
  86. package/dist/constructs/check-group.js.map +1 -1
  87. package/dist/constructs/check.d.ts +8 -8
  88. package/dist/constructs/check.js +31 -14
  89. package/dist/constructs/check.js.map +1 -1
  90. package/dist/constructs/construct-codegen.d.ts +39 -0
  91. package/dist/constructs/construct-codegen.js +100 -0
  92. package/dist/constructs/construct-codegen.js.map +1 -0
  93. package/dist/constructs/construct.js +5 -1
  94. package/dist/constructs/construct.js.map +1 -1
  95. package/dist/constructs/dashboard-codegen.d.ts +29 -0
  96. package/dist/constructs/dashboard-codegen.js +108 -0
  97. package/dist/constructs/dashboard-codegen.js.map +1 -0
  98. package/dist/constructs/dashboard.js +23 -1
  99. package/dist/constructs/dashboard.js.map +1 -1
  100. package/dist/constructs/email-alert-channel-codegen.d.ts +13 -0
  101. package/dist/constructs/email-alert-channel-codegen.js +38 -0
  102. package/dist/constructs/email-alert-channel-codegen.js.map +1 -0
  103. package/dist/constructs/email-alert-channel.js +1 -0
  104. package/dist/constructs/email-alert-channel.js.map +1 -1
  105. package/dist/constructs/frequency-codegen.d.ts +4 -0
  106. package/dist/constructs/frequency-codegen.js +49 -0
  107. package/dist/constructs/frequency-codegen.js.map +1 -0
  108. package/dist/constructs/frequency.js +17 -15
  109. package/dist/constructs/frequency.js.map +1 -1
  110. package/dist/constructs/heartbeat-check-codegen.d.ts +11 -0
  111. package/dist/constructs/heartbeat-check-codegen.js +33 -0
  112. package/dist/constructs/heartbeat-check-codegen.js.map +1 -0
  113. package/dist/constructs/heartbeat-check.js +1 -0
  114. package/dist/constructs/heartbeat-check.js.map +1 -1
  115. package/dist/constructs/incidentio-alert-channel-codegen.d.ts +13 -0
  116. package/dist/constructs/incidentio-alert-channel-codegen.js +89 -0
  117. package/dist/constructs/incidentio-alert-channel-codegen.js.map +1 -0
  118. package/dist/constructs/incidentio-alert-channel.d.ts +6 -0
  119. package/dist/constructs/incidentio-alert-channel.js +17 -16
  120. package/dist/constructs/incidentio-alert-channel.js.map +1 -1
  121. package/dist/constructs/internal/assertion-codegen.d.ts +4 -0
  122. package/dist/constructs/internal/assertion-codegen.js +141 -0
  123. package/dist/constructs/internal/assertion-codegen.js.map +1 -0
  124. package/dist/constructs/internal/assertion.js +7 -4
  125. package/dist/constructs/internal/assertion.js.map +1 -1
  126. package/dist/constructs/internal/codegen/codegen.d.ts +9 -0
  127. package/dist/constructs/internal/codegen/codegen.js +14 -0
  128. package/dist/constructs/internal/codegen/codegen.js.map +1 -0
  129. package/dist/constructs/internal/codegen/context.d.ts +62 -0
  130. package/dist/constructs/internal/codegen/context.js +445 -0
  131. package/dist/constructs/internal/codegen/context.js.map +1 -0
  132. package/dist/constructs/internal/codegen/index.d.ts +4 -0
  133. package/dist/constructs/internal/codegen/index.js +13 -0
  134. package/dist/constructs/internal/codegen/index.js.map +1 -0
  135. package/dist/constructs/internal/codegen/safety.d.ts +2 -0
  136. package/dist/constructs/internal/codegen/safety.js +7 -0
  137. package/dist/constructs/internal/codegen/safety.js.map +1 -0
  138. package/dist/constructs/internal/codegen/snippet.d.ts +12 -0
  139. package/dist/constructs/internal/codegen/snippet.js +48 -0
  140. package/dist/constructs/internal/codegen/snippet.js.map +1 -0
  141. package/dist/constructs/key-value-pair-codegen.d.ts +4 -0
  142. package/dist/constructs/key-value-pair-codegen.js +39 -0
  143. package/dist/constructs/key-value-pair-codegen.js.map +1 -0
  144. package/dist/constructs/maintenance-window-codegen.d.ts +14 -0
  145. package/dist/constructs/maintenance-window-codegen.js +57 -0
  146. package/dist/constructs/maintenance-window-codegen.js.map +1 -0
  147. package/dist/constructs/maintenance-window.js +8 -1
  148. package/dist/constructs/maintenance-window.js.map +1 -1
  149. package/dist/constructs/msteams-alert-channel-codegen.d.ts +13 -0
  150. package/dist/constructs/msteams-alert-channel-codegen.js +75 -0
  151. package/dist/constructs/msteams-alert-channel-codegen.js.map +1 -0
  152. package/dist/constructs/msteams-alert-channel.d.ts +6 -0
  153. package/dist/constructs/msteams-alert-channel.js +14 -13
  154. package/dist/constructs/msteams-alert-channel.js.map +1 -1
  155. package/dist/constructs/multi-step-check-codegen.d.ts +13 -0
  156. package/dist/constructs/multi-step-check-codegen.js +39 -0
  157. package/dist/constructs/multi-step-check-codegen.js.map +1 -0
  158. package/dist/constructs/multi-step-check.js +8 -8
  159. package/dist/constructs/multi-step-check.js.map +1 -1
  160. package/dist/constructs/opsgenie-alert-channel-codegen.d.ts +16 -0
  161. package/dist/constructs/opsgenie-alert-channel-codegen.js +41 -0
  162. package/dist/constructs/opsgenie-alert-channel-codegen.js.map +1 -0
  163. package/dist/constructs/opsgenie-alert-channel.js +4 -0
  164. package/dist/constructs/opsgenie-alert-channel.js.map +1 -1
  165. package/dist/constructs/pagerduty-alert-channel-codegen.d.ts +15 -0
  166. package/dist/constructs/pagerduty-alert-channel-codegen.js +53 -0
  167. package/dist/constructs/pagerduty-alert-channel-codegen.js.map +1 -0
  168. package/dist/constructs/pagerduty-alert-channel.js +3 -0
  169. package/dist/constructs/pagerduty-alert-channel.js.map +1 -1
  170. package/dist/constructs/phone-call-alert-channel-codegen.d.ts +14 -0
  171. package/dist/constructs/phone-call-alert-channel-codegen.js +46 -0
  172. package/dist/constructs/phone-call-alert-channel-codegen.js.map +1 -0
  173. package/dist/constructs/phone-call-alert-channel.js +2 -0
  174. package/dist/constructs/phone-call-alert-channel.js.map +1 -1
  175. package/dist/constructs/playwright-config-codegen.d.ts +4 -0
  176. package/dist/constructs/playwright-config-codegen.js +9 -0
  177. package/dist/constructs/playwright-config-codegen.js.map +1 -0
  178. package/dist/constructs/private-location-check-assignment-codegen.d.ts +10 -0
  179. package/dist/constructs/private-location-check-assignment-codegen.js +18 -0
  180. package/dist/constructs/private-location-check-assignment-codegen.js.map +1 -0
  181. package/dist/constructs/private-location-check-assignment.js +3 -1
  182. package/dist/constructs/private-location-check-assignment.js.map +1 -1
  183. package/dist/constructs/private-location-codegen.d.ts +15 -0
  184. package/dist/constructs/private-location-codegen.js +51 -0
  185. package/dist/constructs/private-location-codegen.js.map +1 -0
  186. package/dist/constructs/private-location-group-assignment-codegen.d.ts +10 -0
  187. package/dist/constructs/private-location-group-assignment-codegen.js +18 -0
  188. package/dist/constructs/private-location-group-assignment-codegen.js.map +1 -0
  189. package/dist/constructs/private-location-group-assignment.js +3 -1
  190. package/dist/constructs/private-location-group-assignment.js.map +1 -1
  191. package/dist/constructs/private-location.d.ts +8 -4
  192. package/dist/constructs/private-location.js +14 -4
  193. package/dist/constructs/private-location.js.map +1 -1
  194. package/dist/constructs/project.d.ts +10 -0
  195. package/dist/constructs/project.js +74 -18
  196. package/dist/constructs/project.js.map +1 -1
  197. package/dist/constructs/ref-codegen.d.ts +3 -0
  198. package/dist/constructs/ref-codegen.js +15 -0
  199. package/dist/constructs/ref-codegen.js.map +1 -0
  200. package/dist/constructs/ref.js +1 -0
  201. package/dist/constructs/ref.js.map +1 -1
  202. package/dist/constructs/retry-strategy-codegen.d.ts +4 -0
  203. package/dist/constructs/retry-strategy-codegen.js +69 -0
  204. package/dist/constructs/retry-strategy-codegen.js.map +1 -0
  205. package/dist/constructs/retry-strategy.js +8 -9
  206. package/dist/constructs/retry-strategy.js.map +1 -1
  207. package/dist/constructs/slack-alert-channel-codegen.d.ts +14 -0
  208. package/dist/constructs/slack-alert-channel-codegen.js +46 -0
  209. package/dist/constructs/slack-alert-channel-codegen.js.map +1 -0
  210. package/dist/constructs/slack-alert-channel.js +2 -0
  211. package/dist/constructs/slack-alert-channel.js.map +1 -1
  212. package/dist/constructs/sms-alert-channel-codegen.d.ts +14 -0
  213. package/dist/constructs/sms-alert-channel-codegen.js +46 -0
  214. package/dist/constructs/sms-alert-channel-codegen.js.map +1 -0
  215. package/dist/constructs/sms-alert-channel.js +2 -0
  216. package/dist/constructs/sms-alert-channel.js.map +1 -1
  217. package/dist/constructs/status-page-codegen.d.ts +23 -0
  218. package/dist/constructs/status-page-codegen.js +71 -0
  219. package/dist/constructs/status-page-codegen.js.map +1 -0
  220. package/dist/constructs/status-page-service-codegen.d.ts +12 -0
  221. package/dist/constructs/status-page-service-codegen.js +44 -0
  222. package/dist/constructs/status-page-service-codegen.js.map +1 -0
  223. package/dist/constructs/status-page-service.d.ts +10 -0
  224. package/dist/constructs/status-page-service.js +21 -2
  225. package/dist/constructs/status-page-service.js.map +1 -1
  226. package/dist/constructs/status-page.js +15 -9
  227. package/dist/constructs/status-page.js.map +1 -1
  228. package/dist/constructs/tcp-check-codegen.d.ts +15 -0
  229. package/dist/constructs/tcp-check-codegen.js +69 -0
  230. package/dist/constructs/tcp-check-codegen.js.map +1 -0
  231. package/dist/constructs/tcp-check.js +3 -0
  232. package/dist/constructs/tcp-check.js.map +1 -1
  233. package/dist/constructs/telegram-alert-channel-codegen.d.ts +13 -0
  234. package/dist/constructs/telegram-alert-channel-codegen.js +105 -0
  235. package/dist/constructs/telegram-alert-channel-codegen.js.map +1 -0
  236. package/dist/constructs/telegram-alert-channel.d.ts +6 -0
  237. package/dist/constructs/telegram-alert-channel.js +8 -4
  238. package/dist/constructs/telegram-alert-channel.js.map +1 -1
  239. package/dist/constructs/webhook-alert-channel-codegen.d.ts +34 -0
  240. package/dist/constructs/webhook-alert-channel-codegen.js +152 -0
  241. package/dist/constructs/webhook-alert-channel-codegen.js.map +1 -0
  242. package/dist/constructs/webhook-alert-channel.js +8 -0
  243. package/dist/constructs/webhook-alert-channel.js.map +1 -1
  244. package/dist/help/help-extension.js +1 -2
  245. package/dist/help/help-extension.js.map +1 -1
  246. package/dist/helpers/command-style.d.ts +18 -0
  247. package/dist/helpers/command-style.js +87 -0
  248. package/dist/helpers/command-style.js.map +1 -0
  249. package/dist/helpers/wrap.d.ts +6 -0
  250. package/dist/helpers/wrap.js +53 -0
  251. package/dist/helpers/wrap.js.map +1 -0
  252. package/dist/loader/index.d.ts +6 -0
  253. package/dist/loader/index.js +21 -0
  254. package/dist/loader/index.js.map +1 -0
  255. package/dist/loader/jiti.d.ts +27 -0
  256. package/dist/loader/jiti.js +63 -0
  257. package/dist/loader/jiti.js.map +1 -0
  258. package/dist/loader/loader.d.ts +29 -0
  259. package/dist/loader/loader.js +32 -0
  260. package/dist/loader/loader.js.map +1 -0
  261. package/dist/loader/match.d.ts +15 -0
  262. package/dist/loader/match.js +47 -0
  263. package/dist/loader/match.js.map +1 -0
  264. package/dist/loader/mixed.d.ts +7 -0
  265. package/dist/loader/mixed.js +39 -0
  266. package/dist/loader/mixed.js.map +1 -0
  267. package/dist/loader/native.d.ts +10 -0
  268. package/dist/loader/native.js +36 -0
  269. package/dist/loader/native.js.map +1 -0
  270. package/dist/loader/ts-node.d.ts +25 -0
  271. package/dist/loader/ts-node.js +85 -0
  272. package/dist/loader/ts-node.js.map +1 -0
  273. package/dist/playwright/playwright-config-loader.d.ts +1 -1
  274. package/dist/playwright/playwright-config-loader.js +7 -4
  275. package/dist/playwright/playwright-config-loader.js.map +1 -1
  276. package/dist/playwright/playwright-config-template.js +1 -0
  277. package/dist/playwright/playwright-config-template.js.map +1 -1
  278. package/dist/reporters/abstract-list.js +10 -6
  279. package/dist/reporters/abstract-list.js.map +1 -1
  280. package/dist/reporters/github.js +13 -6
  281. package/dist/reporters/github.js.map +1 -1
  282. package/dist/reporters/json.js +7 -4
  283. package/dist/reporters/json.js.map +1 -1
  284. package/dist/reporters/list.js +4 -6
  285. package/dist/reporters/list.js.map +1 -1
  286. package/dist/reporters/util.js +15 -20
  287. package/dist/reporters/util.js.map +1 -1
  288. package/dist/rest/accounts.js +1 -0
  289. package/dist/rest/accounts.js.map +1 -1
  290. package/dist/rest/api.js +3 -5
  291. package/dist/rest/api.js.map +1 -1
  292. package/dist/rest/assets.js +1 -0
  293. package/dist/rest/assets.js.map +1 -1
  294. package/dist/rest/checkly-storage.js +1 -0
  295. package/dist/rest/checkly-storage.js.map +1 -1
  296. package/dist/rest/environment-variables.js +1 -0
  297. package/dist/rest/environment-variables.js.map +1 -1
  298. package/dist/rest/heartbeat-checks.js +1 -0
  299. package/dist/rest/heartbeat-checks.js.map +1 -1
  300. package/dist/rest/locations.js +1 -0
  301. package/dist/rest/locations.js.map +1 -1
  302. package/dist/rest/private-locations.js +1 -0
  303. package/dist/rest/private-locations.js.map +1 -1
  304. package/dist/rest/projects.d.ts +69 -1
  305. package/dist/rest/projects.js +76 -4
  306. package/dist/rest/projects.js.map +1 -1
  307. package/dist/rest/runtimes.js +1 -0
  308. package/dist/rest/runtimes.js.map +1 -1
  309. package/dist/rest/test-sessions.js +1 -0
  310. package/dist/rest/test-sessions.js.map +1 -1
  311. package/dist/rest/users.js +1 -0
  312. package/dist/rest/users.js.map +1 -1
  313. package/dist/services/abstract-check-runner.js +10 -0
  314. package/dist/services/abstract-check-runner.js.map +1 -1
  315. package/dist/services/check-parser/collector.js +6 -4
  316. package/dist/services/check-parser/collector.js.map +1 -1
  317. package/dist/services/check-parser/errors.js +4 -0
  318. package/dist/services/check-parser/errors.js.map +1 -1
  319. package/dist/services/check-parser/package-files/extension.js +2 -0
  320. package/dist/services/check-parser/package-files/extension.js.map +1 -1
  321. package/dist/services/check-parser/package-files/jsconfig-json-file.js +5 -22
  322. package/dist/services/check-parser/package-files/jsconfig-json-file.js.map +1 -1
  323. package/dist/services/check-parser/package-files/json-source-file.d.ts +1 -1
  324. package/dist/services/check-parser/package-files/json-source-file.js +5 -17
  325. package/dist/services/check-parser/package-files/json-source-file.js.map +1 -1
  326. package/dist/services/check-parser/package-files/loader.js +2 -1
  327. package/dist/services/check-parser/package-files/loader.js.map +1 -1
  328. package/dist/services/check-parser/package-files/lookup.js +3 -17
  329. package/dist/services/check-parser/package-files/lookup.js.map +1 -1
  330. package/dist/services/check-parser/package-files/package-json-file.d.ts +14 -1
  331. package/dist/services/check-parser/package-files/package-json-file.js +87 -19
  332. package/dist/services/check-parser/package-files/package-json-file.js.map +1 -1
  333. package/dist/services/check-parser/package-files/package-manager.d.ts +91 -0
  334. package/dist/services/check-parser/package-files/package-manager.js +321 -0
  335. package/dist/services/check-parser/package-files/package-manager.js.map +1 -0
  336. package/dist/services/check-parser/package-files/paths.js +39 -0
  337. package/dist/services/check-parser/package-files/paths.js.map +1 -1
  338. package/dist/services/check-parser/package-files/resolver.d.ts +6 -3
  339. package/dist/services/check-parser/package-files/resolver.js +58 -50
  340. package/dist/services/check-parser/package-files/resolver.js.map +1 -1
  341. package/dist/services/check-parser/package-files/source-file.d.ts +1 -1
  342. package/dist/services/check-parser/package-files/source-file.js +8 -17
  343. package/dist/services/check-parser/package-files/source-file.js.map +1 -1
  344. package/dist/services/check-parser/package-files/tsconfig-json-file.js +16 -27
  345. package/dist/services/check-parser/package-files/tsconfig-json-file.js.map +1 -1
  346. package/dist/services/check-parser/parser.js +18 -11
  347. package/dist/services/check-parser/parser.js.map +1 -1
  348. package/dist/services/checkly-config-codegen.d.ts +4 -0
  349. package/dist/services/checkly-config-codegen.js +196 -0
  350. package/dist/services/checkly-config-codegen.js.map +1 -0
  351. package/dist/services/checkly-config-loader.d.ts +6 -2
  352. package/dist/services/checkly-config-loader.js +27 -12
  353. package/dist/services/checkly-config-loader.js.map +1 -1
  354. package/dist/services/config.js +5 -6
  355. package/dist/services/config.js.map +1 -1
  356. package/dist/services/project-parser.js +5 -12
  357. package/dist/services/project-parser.js.map +1 -1
  358. package/dist/services/snapshot-service.js +2 -2
  359. package/dist/services/snapshot-service.js.map +1 -1
  360. package/dist/services/test-filters.js +1 -1
  361. package/dist/services/test-filters.js.map +1 -1
  362. package/dist/services/test-runner.js +12 -5
  363. package/dist/services/test-runner.js.map +1 -1
  364. package/dist/services/trigger-runner.js +12 -5
  365. package/dist/services/trigger-runner.js.map +1 -1
  366. package/dist/services/util.d.ts +0 -1
  367. package/dist/services/util.js +12 -107
  368. package/dist/services/util.js.map +1 -1
  369. package/dist/sourcegen/args.d.ts +7 -0
  370. package/dist/sourcegen/args.js +26 -0
  371. package/dist/sourcegen/args.js.map +1 -0
  372. package/dist/sourcegen/argsbuilder.d.ts +22 -0
  373. package/dist/sourcegen/argsbuilder.js +111 -0
  374. package/dist/sourcegen/argsbuilder.js.map +1 -0
  375. package/dist/sourcegen/array.d.ts +8 -0
  376. package/dist/sourcegen/array.js +32 -0
  377. package/dist/sourcegen/array.js.map +1 -0
  378. package/dist/sourcegen/arraybuilder.d.ts +21 -0
  379. package/dist/sourcegen/arraybuilder.js +109 -0
  380. package/dist/sourcegen/arraybuilder.js.map +1 -0
  381. package/dist/sourcegen/boolean.d.ts +7 -0
  382. package/dist/sourcegen/boolean.js +22 -0
  383. package/dist/sourcegen/boolean.js.map +1 -0
  384. package/dist/sourcegen/case.d.ts +9 -0
  385. package/dist/sourcegen/case.js +107 -0
  386. package/dist/sourcegen/case.js.map +1 -0
  387. package/dist/sourcegen/comment.d.ts +32 -0
  388. package/dist/sourcegen/comment.js +124 -0
  389. package/dist/sourcegen/comment.js.map +1 -0
  390. package/dist/sourcegen/decl.d.ts +43 -0
  391. package/dist/sourcegen/decl.js +95 -0
  392. package/dist/sourcegen/decl.js.map +1 -0
  393. package/dist/sourcegen/declbuilder.d.ts +14 -0
  394. package/dist/sourcegen/declbuilder.js +39 -0
  395. package/dist/sourcegen/declbuilder.js.map +1 -0
  396. package/dist/sourcegen/expr.d.ts +39 -0
  397. package/dist/sourcegen/expr.js +86 -0
  398. package/dist/sourcegen/expr.js.map +1 -0
  399. package/dist/sourcegen/exprbuilder.d.ts +13 -0
  400. package/dist/sourcegen/exprbuilder.js +54 -0
  401. package/dist/sourcegen/exprbuilder.js.map +1 -0
  402. package/dist/sourcegen/identifier.d.ts +12 -0
  403. package/dist/sourcegen/identifier.js +27 -0
  404. package/dist/sourcegen/identifier.js.map +1 -0
  405. package/dist/sourcegen/index.d.ts +22 -0
  406. package/dist/sourcegen/index.js +76 -0
  407. package/dist/sourcegen/index.js.map +1 -0
  408. package/dist/sourcegen/null.d.ts +5 -0
  409. package/dist/sourcegen/null.js +11 -0
  410. package/dist/sourcegen/null.js.map +1 -0
  411. package/dist/sourcegen/number.d.ts +7 -0
  412. package/dist/sourcegen/number.js +22 -0
  413. package/dist/sourcegen/number.js.map +1 -0
  414. package/dist/sourcegen/object.d.ts +28 -0
  415. package/dist/sourcegen/object.js +88 -0
  416. package/dist/sourcegen/object.js.map +1 -0
  417. package/dist/sourcegen/objectbuilder.d.ts +25 -0
  418. package/dist/sourcegen/objectbuilder.js +127 -0
  419. package/dist/sourcegen/objectbuilder.js.map +1 -0
  420. package/dist/sourcegen/output.d.ts +14 -0
  421. package/dist/sourcegen/output.js +85 -0
  422. package/dist/sourcegen/output.js.map +1 -0
  423. package/dist/sourcegen/program.d.ts +55 -0
  424. package/dist/sourcegen/program.js +284 -0
  425. package/dist/sourcegen/program.js.map +1 -0
  426. package/dist/sourcegen/string.d.ts +8 -0
  427. package/dist/sourcegen/string.js +28 -0
  428. package/dist/sourcegen/string.js.map +1 -0
  429. package/dist/sourcegen/undefined.d.ts +5 -0
  430. package/dist/sourcegen/undefined.js +11 -0
  431. package/dist/sourcegen/undefined.js.map +1 -0
  432. package/dist/sourcegen/unknown.d.ts +2 -0
  433. package/dist/sourcegen/unknown.js +40 -0
  434. package/dist/sourcegen/unknown.js.map +1 -0
  435. package/dist/sourcegen/value.d.ts +4 -0
  436. package/dist/sourcegen/value.js +7 -0
  437. package/dist/sourcegen/value.js.map +1 -0
  438. package/dist/tsconfig.tsbuildinfo +1 -1
  439. package/dist/util/index.d.ts +9 -0
  440. package/dist/util/index.js +27 -0
  441. package/dist/util/index.js.map +1 -0
  442. package/oclif.manifest.json +173 -1
  443. package/package.json +14 -37
@@ -0,0 +1,1237 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const promises_1 = __importDefault(require("node:fs/promises"));
30
+ const node_path_1 = __importDefault(require("node:path"));
31
+ const promises_2 = require("node:timers/promises");
32
+ const core_1 = require("@oclif/core");
33
+ const prompts_1 = __importDefault(require("prompts"));
34
+ const chalk_1 = __importDefault(require("chalk"));
35
+ const axios_1 = require("axios");
36
+ const log_symbols_1 = __importDefault(require("log-symbols"));
37
+ const uuid_1 = require("uuid");
38
+ const api = __importStar(require("../../rest/api"));
39
+ const authCommand_1 = require("../authCommand");
40
+ const common_messages_1 = __importDefault(require("../../messages/common-messages"));
41
+ const util_1 = require("../../services/util");
42
+ const checkly_config_loader_1 = require("../../services/checkly-config-loader");
43
+ const projects_1 = require("../../rest/projects");
44
+ const sourcegen_1 = require("../../sourcegen");
45
+ const construct_codegen_1 = require("../../constructs/construct-codegen");
46
+ const codegen_1 = require("../../constructs/internal/codegen");
47
+ const snippet_1 = require("../../constructs/internal/codegen/snippet");
48
+ const errors_1 = require("@oclif/core/errors");
49
+ const commit_1 = require("./commit");
50
+ const apply_1 = require("./apply");
51
+ const checkly_config_codegen_1 = require("../../services/checkly-config-codegen");
52
+ const resolver_1 = require("../../services/check-parser/package-files/resolver");
53
+ const package_json_file_1 = require("../../services/check-parser/package-files/package-json-file");
54
+ const package_manager_1 = require("../../services/check-parser/package-files/package-manager");
55
+ const project_parser_1 = require("../../services/project-parser");
56
+ const config_1 = __importDefault(require("../../services/config"));
57
+ const project_1 = require("../../constructs/project");
58
+ class ImportPlanCommand extends authCommand_1.AuthCommand {
59
+ static hidden = false;
60
+ static description = `\
61
+ Import existing resources from your Checkly account to your project.
62
+
63
+ By default, all resources that can be imported will be imported. However, you
64
+ may fine-tune the process by including or excluding any combination of
65
+ resources.
66
+
67
+ The import process consists of three steps:
68
+
69
+ 1. Creating a plan, which generates the appropriate code for your resources
70
+ 2. Applying the plan, which links your resources to the generated code
71
+ 3. Committing the plan, which finalizes the import session
72
+
73
+ CREATING A PLAN
74
+
75
+ Creating a plan carries no risk as no concrete links to your Checkly resources
76
+ are made at this point. However, if you accidentally deploy the generated code
77
+ before applying the plan, you will end up with duplicate resources and will
78
+ not be able to complete the import session without first deleting the
79
+ duplicates.
80
+
81
+ For the curious, you may also preview the generated code with the '--preview'
82
+ option. No plan will be created, allowing you to leisurely inspect the
83
+ generated code. However keep in mind that you will need to create a plan to
84
+ actually import any resources, at which point the code will be generated
85
+ again.
86
+
87
+ You may cancel any plan you've created without affecting any of the
88
+ underlying resources.
89
+
90
+ APPLYING A PLAN
91
+
92
+ Applying a plan links your existing resources to the generated code. You
93
+ should carefully review the generated code to make sure that it contains the
94
+ resources you expect before applying a plan. After a plan has been applied,
95
+ any deployments of those resources will irreversibly modify the underlying
96
+ Checkly resources. However, as a fail safe against concurrent use, any
97
+ deployments not including the imported resources will not delete the
98
+ underlying resources (or the links to the resources). This means that there
99
+ is no need to block deployments while working on an import session.
100
+
101
+ Even after you've applied a plan, you may still cancel it, which will unlink
102
+ the underlying resources from your project once more. However, keep in mind
103
+ that any changes to the resources that you've already deployed cannot be
104
+ undone.
105
+
106
+ COMMITTING A PLAN
107
+
108
+ Finally, committing a plan removes all fail safes and permanently links the
109
+ imported resources to your project. Any resources you remove from your code
110
+ will result in the underlying resources also getting irrevocably deleted on
111
+ the next deploy. You should only commit your plan once you are sure that all
112
+ future deployments include the imported resources.`;
113
+ static flags = {
114
+ config: core_1.Flags.string({
115
+ char: 'c',
116
+ description: common_messages_1.default.configFile,
117
+ }),
118
+ root: core_1.Flags.string({
119
+ description: 'The root folder in which to write generated code files.',
120
+ default: '__checks__',
121
+ }),
122
+ preview: core_1.Flags.boolean({
123
+ description: 'Preview generated code without creating an actual import plan.',
124
+ default: false,
125
+ }),
126
+ 'debug-import-plan': core_1.Flags.boolean({
127
+ description: 'Output the import plan to a file.',
128
+ default: false,
129
+ hidden: true,
130
+ }),
131
+ 'debug-import-plan-output-file': core_1.Flags.string({
132
+ description: 'The file to output the import plan to.',
133
+ default: './debug-import-plan.json',
134
+ hidden: true,
135
+ }),
136
+ };
137
+ static args = {
138
+ resource: core_1.Args.string({
139
+ name: 'resource',
140
+ required: false,
141
+ description: 'A specific resource to import.',
142
+ }),
143
+ };
144
+ static strict = false;
145
+ static hiddenAliases = [
146
+ 'import',
147
+ ];
148
+ async run() {
149
+ const { flags, argv } = await this.parse(ImportPlanCommand);
150
+ const { config: configFilename, root: rootDirectory, 'debug-import-plan': debugImportPlan, 'debug-import-plan-output-file': debugImportPlanOutputFile, preview, } = flags;
151
+ const filters = argv.map(value => {
152
+ return parseFilter(value);
153
+ });
154
+ this.style.shortInfo(`You are about to import resources from your Checkly account.`);
155
+ this.style.comment(`Please make sure to commit any unsaved changes to avoid having any ` +
156
+ `local changes get overwritten by generated code.`);
157
+ const { configDirectory, configFilenames } = (0, util_1.splitConfigFilePath)(configFilename);
158
+ const checklyConfig = await this.#loadConfig(configDirectory, configFilenames)
159
+ ?? await this.#interactiveCreateConfig(configDirectory);
160
+ await this.#initializeProject(checklyConfig);
161
+ const constructExports = await this.#findExportedResources(configDirectory, checklyConfig, rootDirectory);
162
+ const friendExports = {
163
+ 'alert-channel': new Map(),
164
+ 'check-group': new Map(),
165
+ 'private-location': new Map(),
166
+ 'status-page-service': new Map(),
167
+ };
168
+ const friends = [];
169
+ for (const constructExport of constructExports) {
170
+ const { type, logicalId } = constructExport;
171
+ const friendExport = friendExports[type];
172
+ if (friendExport === undefined) {
173
+ continue;
174
+ }
175
+ friendExport.set(logicalId, constructExport);
176
+ friends.push({
177
+ type,
178
+ logicalId,
179
+ });
180
+ }
181
+ const { logicalId, } = checklyConfig;
182
+ if (!preview) {
183
+ const { data: existingPlans } = await api.projects.findImportPlans(logicalId, {
184
+ onlyUncommitted: true,
185
+ });
186
+ if (existingPlans.length !== 0) {
187
+ await this.#handleExistingPlans(existingPlans);
188
+ }
189
+ }
190
+ const createProgram = () => {
191
+ return new sourcegen_1.Program({
192
+ rootDirectory,
193
+ constructFileSuffix: '.check',
194
+ constructHeaders: preview ? [previewComment()] : undefined,
195
+ specFileSuffix: '.spec',
196
+ language: 'typescript',
197
+ });
198
+ };
199
+ // These are needed for the interactive filter creation for now. Ideally
200
+ // we'd remove these.
201
+ const program = createProgram();
202
+ const codegen = new construct_codegen_1.ConstructCodegen(program);
203
+ // If the user provided no filter, ask interactively.
204
+ if (filters.length === 0) {
205
+ filters.push(...await this.#interactiveFilter(logicalId, codegen));
206
+ }
207
+ // Inject the default filter.
208
+ //
209
+ // By default all resource will be included, unless the user has specified
210
+ // an inclusive filter by themselves, in which case the default filter
211
+ // excludes all resources.
212
+ filters.unshift({
213
+ type: filters.some(({ type }) => type === 'include') ? 'exclude' : 'include',
214
+ });
215
+ while (true) {
216
+ // Recreate program on every attempt as otherwise resources from earlier
217
+ // runs will persist.
218
+ const program = createProgram();
219
+ const codegen = new construct_codegen_1.ConstructCodegen(program);
220
+ const plan = await this.#createImportPlan(logicalId, {
221
+ preview,
222
+ filters,
223
+ friends,
224
+ });
225
+ if (!plan) {
226
+ return;
227
+ }
228
+ if (debugImportPlan) {
229
+ const output = JSON.stringify(plan, null, 2);
230
+ await promises_1.default.writeFile(debugImportPlanOutputFile, output, 'utf8');
231
+ this.style.shortSuccess(`Successfully wrote debug import plan to "${debugImportPlanOutputFile}".`);
232
+ return;
233
+ }
234
+ try {
235
+ const { failures } = this.#generateCode(plan, program, codegen, friendExports);
236
+ if (failures.length) {
237
+ this.log(`${log_symbols_1.default.error} ${chalk_1.default.red('The following resources could not be imported:')}`);
238
+ this.log();
239
+ for (const { resource, cause } of failures) {
240
+ const spec = `${resource.type}:${resource.physicalId}`;
241
+ const desc = (() => {
242
+ try {
243
+ return codegen.describe(resource);
244
+ }
245
+ catch {
246
+ return resource.type;
247
+ }
248
+ })();
249
+ this.log(` ${desc} (${chalk_1.default.gray(spec)})`);
250
+ this.log();
251
+ this.log(` ${chalk_1.default.red(cause.toString())}`);
252
+ this.log();
253
+ // Proactively exclude the failed resource. If the user wants to
254
+ // retry it'll already be in the filter list, and otherwise it will
255
+ // simply not get used.
256
+ filters.push({
257
+ type: 'exclude',
258
+ resource: {
259
+ type: resource.type,
260
+ physicalId: resource.physicalId,
261
+ },
262
+ });
263
+ }
264
+ const retry = await this.#confirmRetryWithoutFailed();
265
+ if (!retry) {
266
+ this.cancelAndExit();
267
+ }
268
+ // When previewing, there is no plan to cancel.
269
+ if (preview) {
270
+ continue;
271
+ }
272
+ this.style.comment(`The current plan will be cancelled so that a new plan can be created.`);
273
+ this.style.actionStart('Cancelling current plan');
274
+ try {
275
+ await api.projects.cancelImportPlan(plan.id);
276
+ this.style.actionSuccess();
277
+ }
278
+ catch (err) {
279
+ this.style.actionFailure();
280
+ throw err;
281
+ }
282
+ this.style.comment(`A new plan will be created without the failed resources.`);
283
+ continue;
284
+ }
285
+ this.style.actionStart('Writing files');
286
+ try {
287
+ await program.realize();
288
+ this.style.actionSuccess();
289
+ }
290
+ catch (err) {
291
+ this.style.actionFailure();
292
+ throw err;
293
+ }
294
+ this.log(`${log_symbols_1.default.success} ${chalk_1.default.bold('Your import plan has been created!')}`);
295
+ this.log();
296
+ this.log(` You can find the generated code under the following directory:`);
297
+ this.log();
298
+ this.log(` ${chalk_1.default.green(rootDirectory)}`);
299
+ this.log();
300
+ this.log(`\
301
+ The imported resources have not been linked to your project yet. Please
302
+ make sure to inspect the generated code. Should you find anything you do
303
+ not like, you can cancel the import plan and no harm will be done.
304
+
305
+ ${log_symbols_1.default.warning} \
306
+ ${chalk_1.default.yellow('If you deploy now, you will end up with duplicate resources!')}
307
+
308
+ Once you have inspected the code, the next step will be to apply the plan,
309
+ which links the generated code to the underlying resources, making them
310
+ modifiable. At this point you may still cancel the plan, though any changes
311
+ you've already deployed cannot be undone.
312
+
313
+ ${log_symbols_1.default.info} \
314
+ ${chalk_1.default.cyan('For safety, resources are not deletable until the plan has been committed.')}
315
+
316
+ The final step will be to commit your plan, at which point the underlying
317
+ resources will be fully managed by the Checkly CLI in the exact same
318
+ manner as any other CLI-native resource.
319
+ `);
320
+ const apply = await apply_1.confirmApply.call(this);
321
+ if (!apply) {
322
+ return;
323
+ }
324
+ await apply_1.performApplyAction.call(this, plan);
325
+ const commit = await commit_1.confirmCommit.call(this);
326
+ if (!commit) {
327
+ return;
328
+ }
329
+ await commit_1.performCommitAction.call(this, plan);
330
+ return;
331
+ }
332
+ catch (err) {
333
+ if (err instanceof errors_1.ExitError) {
334
+ throw err;
335
+ }
336
+ try {
337
+ const output = JSON.stringify(plan, null, 2);
338
+ await promises_1.default.writeFile(debugImportPlanOutputFile, output, 'utf8');
339
+ this.log(`${log_symbols_1.default.warning} Please contact Checkly support at support@checklyhq.com and attach the newly created "${debugImportPlanOutputFile}" file.`);
340
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
341
+ }
342
+ catch (err) {
343
+ this.log(`${log_symbols_1.default.warning} Please contact Checkly support at support@checklyhq.com.`);
344
+ }
345
+ throw err;
346
+ }
347
+ }
348
+ }
349
+ #outputConfigSection(options) {
350
+ const { title, step: [step, totalSteps], description } = options;
351
+ this.log(` ${title} ${chalk_1.default.grey(`(step ${step}/${totalSteps})`)}`);
352
+ this.log();
353
+ this.style.comment(description);
354
+ }
355
+ async #askProjectName(step) {
356
+ this.#outputConfigSection({
357
+ title: `Let's give your project a name`,
358
+ description: `You'll be able to change the name later if you like.`,
359
+ step,
360
+ });
361
+ while (true) {
362
+ const { projectName } = await (0, prompts_1.default)({
363
+ name: 'projectName',
364
+ type: 'text',
365
+ message: 'What should we call your project?',
366
+ });
367
+ this.log();
368
+ if (projectName === undefined) {
369
+ this.cancelAndExit();
370
+ }
371
+ if (projectName.trim() !== '') {
372
+ return projectName;
373
+ }
374
+ this.style.comment(`Sorry, but a project name is absolutely required. ` +
375
+ `You can also press ESC to cancel and exit.`);
376
+ }
377
+ }
378
+ async #askLogicalId(suggested, step) {
379
+ this.#outputConfigSection({
380
+ title: `Set up a unique project identifier`,
381
+ description: `The identifier given here uniquely identifies your ` +
382
+ `project among any other Checkly projects you may have. You will ` +
383
+ `not be able to change the identifier later without recreating the ` +
384
+ `project. Please choose a value you'll be comfortable with ` +
385
+ `long term.`,
386
+ step,
387
+ });
388
+ while (true) {
389
+ const { logicalId } = await (0, prompts_1.default)({
390
+ name: 'logicalId',
391
+ type: 'text',
392
+ message: 'How would you like your project to be identified?',
393
+ initial: suggested,
394
+ validate: (input) => {
395
+ if (!/^[A-Za-z0-9_\-/#.]+$/.test(input)) {
396
+ return `Please only use ASCII letters, numbers, and the ` +
397
+ `symbols _, -, /, #, and .`;
398
+ }
399
+ return true;
400
+ },
401
+ });
402
+ this.log();
403
+ if (logicalId === undefined) {
404
+ this.cancelAndExit();
405
+ }
406
+ if (logicalId.trim() !== '') {
407
+ return logicalId;
408
+ }
409
+ this.style.comment(`Sorry, but a project identifier is absolutely required. ` +
410
+ `You can also press ESC to cancel and exit.`);
411
+ }
412
+ }
413
+ async #interactiveCreateConfig(configDirectory) {
414
+ this.style.shortWarning(`Unable to find an existing Checkly configuration file.`);
415
+ this.style.comment(`Setting up Checkly for the first time? No worries, we'll walk you ` +
416
+ `through the process.`);
417
+ const choices = [{
418
+ title: `Yes, I want to start a new project for the imported resources`,
419
+ value: 'init',
420
+ description: `We'll walk you through a minimal setup`,
421
+ }, {
422
+ title: `No, I intended to import resources into an existing project`,
423
+ value: 'mistake',
424
+ description: 'Exit and verify your configuration.',
425
+ }, {
426
+ title: 'No, I want to cancel and exit',
427
+ value: 'exit',
428
+ description: 'No changes will be made.',
429
+ }];
430
+ const { action } = await (0, prompts_1.default)({
431
+ name: 'action',
432
+ type: 'select',
433
+ message: 'Set up a new Checkly project?',
434
+ choices,
435
+ });
436
+ this.log();
437
+ switch (action) {
438
+ case 'init': {
439
+ const projectName = await this.#askProjectName([1, 2]);
440
+ const suggestedLogicalId = (0, sourcegen_1.cased)(projectName, 'kebab-case');
441
+ const logicalId = await this.#askLogicalId(suggestedLogicalId, [2, 2]);
442
+ try {
443
+ this.style.actionStart('Creating project');
444
+ try {
445
+ await api.projects.create({
446
+ name: projectName,
447
+ logicalId,
448
+ });
449
+ }
450
+ catch (err) {
451
+ if ((0, axios_1.isAxiosError)(err)) {
452
+ if (err.response?.status === 409) {
453
+ throw new Error(`You are already using the same identifier for a different project.`);
454
+ }
455
+ }
456
+ throw err;
457
+ }
458
+ this.style.actionSuccess();
459
+ }
460
+ catch (err) {
461
+ this.style.actionFailure();
462
+ throw err;
463
+ }
464
+ const program = new sourcegen_1.Program({
465
+ rootDirectory: configDirectory,
466
+ constructFileSuffix: '.check',
467
+ specFileSuffix: '.spec',
468
+ language: 'typescript',
469
+ });
470
+ const context = new codegen_1.Context();
471
+ const config = {
472
+ projectName,
473
+ logicalId,
474
+ checks: {
475
+ tags: ['mac'],
476
+ checkMatch: '**/__checks__/**/*.check.ts',
477
+ },
478
+ };
479
+ try {
480
+ this.style.actionStart('Creating Checkly configuration');
481
+ // TODO: Make this less ugly.
482
+ (0, checkly_config_codegen_1.generateChecklyConfig)(program, context, config, 'checkly.config.ts');
483
+ this.style.actionSuccess();
484
+ }
485
+ catch (err) {
486
+ this.style.actionFailure();
487
+ throw err;
488
+ }
489
+ let askInstall = false;
490
+ let packageJson;
491
+ try {
492
+ this.style.actionStart('Configuring package.json for Checkly');
493
+ // TODO: Make this less ugly.
494
+ packageJson = (() => {
495
+ const file = this.#loadPackageJson();
496
+ if (file !== undefined) {
497
+ this.style.shortSuccess(`Found existing package.json`);
498
+ return file;
499
+ }
500
+ else {
501
+ this.style.shortSuccess(`Creating a new minimal package.json`);
502
+ return this.#createPackageJson(logicalId);
503
+ }
504
+ })();
505
+ const updated = packageJson.upsertDevDependencies({
506
+ checkly: `^5`,
507
+ jiti: '^2',
508
+ });
509
+ if (updated) {
510
+ this.style.shortSuccess(`Successfully added Checkly devDependencies`);
511
+ program.staticSupportFile(packageJson.meta.filePath, packageJson.toJSON());
512
+ askInstall = true;
513
+ }
514
+ else {
515
+ this.style.shortSuccess(`Checkly devDependencies are already up to date`);
516
+ }
517
+ this.style.actionSuccess();
518
+ }
519
+ catch (err) {
520
+ this.style.actionFailure();
521
+ throw err;
522
+ }
523
+ try {
524
+ this.style.actionStart('Writing project files');
525
+ await program.realize();
526
+ this.style.actionSuccess();
527
+ }
528
+ catch (err) {
529
+ this.style.actionFailure();
530
+ throw err;
531
+ }
532
+ if (askInstall && packageJson !== undefined) {
533
+ await this.#interactiveNpmInstall(packageJson.meta.dirname);
534
+ }
535
+ return config;
536
+ }
537
+ case 'mistake':
538
+ this.style.fatal(`Please verify your configuration and try again.`);
539
+ this.cancelAndExit();
540
+ break;
541
+ case 'exit':
542
+ // falls through
543
+ default: {
544
+ this.cancelAndExit();
545
+ }
546
+ }
547
+ }
548
+ #loadPackageJson() {
549
+ const resolver = new resolver_1.PackageFilesResolver();
550
+ return resolver.loadPackageJsonFile(process.cwd(), {
551
+ isDir: true,
552
+ });
553
+ }
554
+ #createPackageJson(logicalId) {
555
+ return package_json_file_1.PackageJsonFile.make(package_json_file_1.PackageJsonFile.FILENAME, {
556
+ name: logicalId,
557
+ version: '1.0.0',
558
+ private: true,
559
+ });
560
+ }
561
+ async #interactiveNpmInstall(dirPath, forcePackageManager) {
562
+ const { execa } = await import('execa');
563
+ const packageManager = forcePackageManager ?? await (async () => {
564
+ try {
565
+ this.style.actionStart(`Detecting package manager`);
566
+ const packageManager = await (0, package_manager_1.detectPackageManager)(dirPath);
567
+ this.style.actionSuccess();
568
+ this.style.comment(`It looks like your package manager is ${packageManager.name}.`);
569
+ return packageManager;
570
+ }
571
+ catch (err) {
572
+ this.style.actionFailure();
573
+ throw err;
574
+ }
575
+ })();
576
+ const { unsafeDisplayCommand, executable, args } = packageManager.installCommand();
577
+ const choices = [{
578
+ title: `Yes, please run \`${unsafeDisplayCommand}\` for me`,
579
+ value: 'install',
580
+ }, {
581
+ title: `I want to use a different package manager`,
582
+ value: 'other-manager',
583
+ }, {
584
+ title: 'I will do it later myself',
585
+ value: 'later',
586
+ }];
587
+ const { action } = await (0, prompts_1.default)({
588
+ type: 'select',
589
+ name: 'action',
590
+ message: 'Would you like to install dependencies now? (recommended)',
591
+ choices,
592
+ });
593
+ this.log();
594
+ switch (action) {
595
+ case 'install': {
596
+ this.style.comment(`Ok, now running \`${unsafeDisplayCommand}\`.`);
597
+ try {
598
+ await execa(executable, args, {
599
+ cwd: dirPath,
600
+ stdout: ['inherit'],
601
+ stderr: ['inherit'],
602
+ stdin: ['inherit'],
603
+ });
604
+ this.log();
605
+ this.style.comment(`Successfully installed dependencies.`);
606
+ }
607
+ catch (err) {
608
+ if (err instanceof Error) {
609
+ this.style.longError(`Failed to install dependencies`, err.message); // TODO :
610
+ }
611
+ this.style.comment(`Uh oh. Looks like that didn't quite work as expected.` +
612
+ `\n\n` +
613
+ `You can still continue the import process and install ` +
614
+ `dependencies later by yourself.`);
615
+ const { action } = await (0, prompts_1.default)({
616
+ type: 'confirm',
617
+ name: 'action',
618
+ message: 'Continue the import process?',
619
+ });
620
+ this.log();
621
+ if (action) {
622
+ this.style.comment(`Great, let's proceed to the next step.`);
623
+ await (0, promises_2.setTimeout)(200);
624
+ }
625
+ else {
626
+ this.cancelAndExit();
627
+ }
628
+ }
629
+ break;
630
+ }
631
+ case 'other-manager': {
632
+ const packageManagersByName = Object.fromEntries(package_manager_1.knownPackageManagers.map(packageManager => {
633
+ return [packageManager.name, packageManager];
634
+ }));
635
+ const choices = package_manager_1.knownPackageManagers.map(packageManager => ({
636
+ title: packageManager.name,
637
+ value: packageManager.name,
638
+ }));
639
+ choices.push({
640
+ title: 'None of the above',
641
+ value: 'other',
642
+ });
643
+ const { action } = await (0, prompts_1.default)({
644
+ type: 'select',
645
+ name: 'action',
646
+ message: 'Which package manager would you like to use?',
647
+ choices,
648
+ });
649
+ this.log();
650
+ if (action === undefined) {
651
+ this.cancelAndExit();
652
+ }
653
+ if (action === 'other') {
654
+ this.style.comment(`Alright. If possible, let us know which package manager you ` +
655
+ `use and we may be able to support it in the future.` +
656
+ `\n\n` +
657
+ `You can still continue the import process and install ` +
658
+ `dependencies later by yourself.`);
659
+ const { action } = await (0, prompts_1.default)({
660
+ type: 'confirm',
661
+ name: 'action',
662
+ message: 'Continue the import process?',
663
+ });
664
+ this.log();
665
+ if (action) {
666
+ this.style.comment(`Great, let's proceed to the next step.`);
667
+ await (0, promises_2.setTimeout)(200);
668
+ break;
669
+ }
670
+ else {
671
+ this.cancelAndExit();
672
+ }
673
+ }
674
+ const packageManager = packageManagersByName[action];
675
+ if (packageManager === undefined) {
676
+ throw new Error(`Somehow, you selected an option that does not exist.`);
677
+ }
678
+ return this.#interactiveNpmInstall(dirPath, packageManager);
679
+ }
680
+ case 'later': {
681
+ this.style.comment(`Ok, but make sure to perform the appropriate actions to install ` +
682
+ `dependencies once you've completed the setup.` +
683
+ `\n\n` +
684
+ `If you do not, the Checkly CLI will not function as intended.`);
685
+ await (0, promises_2.setTimeout)(200);
686
+ break;
687
+ }
688
+ default: {
689
+ this.cancelAndExit();
690
+ }
691
+ }
692
+ }
693
+ async #loadConfig(configDirectory, configFilenames) {
694
+ try {
695
+ const { config: checklyConfig, } = await (0, checkly_config_loader_1.loadChecklyConfig)(configDirectory, configFilenames);
696
+ return checklyConfig;
697
+ }
698
+ catch (err) {
699
+ if (err instanceof checkly_config_loader_1.ConfigNotFoundError) {
700
+ return;
701
+ }
702
+ throw err;
703
+ }
704
+ }
705
+ async #findExportedResources(configDirectory, checklyConfig, rootDirectory) {
706
+ this.style.actionStart('Parsing your project for exported resources');
707
+ try {
708
+ const { data: account } = await api.accounts.get(config_1.default.getAccountId());
709
+ const { data: availableRuntimes } = await api.runtimes.getAll();
710
+ await (0, project_parser_1.parseProject)({
711
+ directory: configDirectory,
712
+ projectLogicalId: checklyConfig.logicalId,
713
+ projectName: checklyConfig.projectName,
714
+ repoUrl: checklyConfig.repoUrl,
715
+ checkMatch: checklyConfig.checks?.checkMatch,
716
+ browserCheckMatch: checklyConfig.checks?.browserChecks?.testMatch,
717
+ multiStepCheckMatch: checklyConfig.checks?.multiStepChecks?.testMatch,
718
+ ignoreDirectoriesMatch: checklyConfig.checks?.ignoreDirectoriesMatch,
719
+ checkDefaults: checklyConfig.checks,
720
+ browserCheckDefaults: checklyConfig.checks?.browserChecks,
721
+ availableRuntimes: availableRuntimes.reduce((acc, runtime) => {
722
+ acc[runtime.name] = runtime;
723
+ return acc;
724
+ }, {}),
725
+ defaultRuntimeId: account.runtimeId,
726
+ verifyRuntimeDependencies: false,
727
+ });
728
+ this.style.actionSuccess();
729
+ const constructExports = project_1.Session.constructExports;
730
+ switch (constructExports.length) {
731
+ case 0: {
732
+ this.style.comment(`Did not find any exported resources.`);
733
+ break;
734
+ }
735
+ case 1: {
736
+ this.style.comment(`Found 1 exported resource.`);
737
+ break;
738
+ }
739
+ default: {
740
+ this.style.comment(`Found ${constructExports.length} exported resources.`);
741
+ break;
742
+ }
743
+ }
744
+ // Paths need to be relative to the root directory or our generated
745
+ // imports won't work correctly.
746
+ for (const constructExport of constructExports) {
747
+ constructExport.filePath = node_path_1.default.relative(rootDirectory, constructExport.filePath);
748
+ }
749
+ return constructExports;
750
+ }
751
+ catch (err) {
752
+ this.style.actionFailure();
753
+ throw err;
754
+ }
755
+ }
756
+ async #confirmRetryWithoutFailed() {
757
+ const { action } = await (0, prompts_1.default)({
758
+ name: 'action',
759
+ type: 'confirm',
760
+ message: 'Would you like to try again without the failed resources?',
761
+ });
762
+ this.log();
763
+ return action ?? false;
764
+ }
765
+ async #createImportPlan(logicalId, options) {
766
+ this.style.actionStart('Creating a new plan');
767
+ try {
768
+ const { data } = await api.projects.createImportPlan(logicalId, options);
769
+ this.style.actionSuccess();
770
+ return data;
771
+ }
772
+ catch (err) {
773
+ this.style.actionFailure();
774
+ if ((0, axios_1.isAxiosError)(err)) {
775
+ if (err.response?.status === 404) {
776
+ const message = err.response?.data.message;
777
+ if (message) {
778
+ this.style.fatal(message);
779
+ return;
780
+ }
781
+ }
782
+ }
783
+ throw err;
784
+ }
785
+ }
786
+ async #interactiveFilter(logicalId, codegen) {
787
+ const choices = [{
788
+ title: `I want to import everything in one go`,
789
+ value: 'all',
790
+ }, {
791
+ title: `Let me choose resources manually`,
792
+ value: 'choose',
793
+ description: 'You will be presented with options.'
794
+ }, {
795
+ title: 'Cancel and exit',
796
+ value: 'exit',
797
+ description: 'No changes will be made.',
798
+ }];
799
+ const { action } = await (0, prompts_1.default)({
800
+ name: 'action',
801
+ type: 'select',
802
+ message: 'Which resources would you like to import?',
803
+ choices,
804
+ });
805
+ this.log();
806
+ switch (action) {
807
+ case 'all':
808
+ return [];
809
+ case 'choose': {
810
+ const choices = await (async () => {
811
+ this.style.actionStart('Fetching available resources');
812
+ try {
813
+ const { data } = await api.projects.createImportPlan(logicalId, {
814
+ preview: true,
815
+ filters: [{
816
+ type: 'include',
817
+ }],
818
+ });
819
+ this.style.actionSuccess();
820
+ return (data.changes?.resources ?? []).flatMap(resource => {
821
+ if (!isFilterable(resource.type)) {
822
+ return [];
823
+ }
824
+ try {
825
+ return [{
826
+ title: codegen.describe(resource),
827
+ value: `${resource.type}:${resource.physicalId}`,
828
+ description: `${resource.type}:${resource.physicalId}`,
829
+ }];
830
+ }
831
+ catch {
832
+ return [];
833
+ }
834
+ });
835
+ }
836
+ catch (err) {
837
+ this.style.actionFailure();
838
+ if ((0, axios_1.isAxiosError)(err)) {
839
+ if (err.response?.status === 404) {
840
+ return [];
841
+ }
842
+ }
843
+ throw err;
844
+ }
845
+ })();
846
+ choices.sort((a, b) => {
847
+ return a.title.localeCompare(b.title);
848
+ });
849
+ const { resources } = await (0, prompts_1.default)({
850
+ name: 'resources',
851
+ type: 'autocompleteMultiselect',
852
+ message: 'Please select the resources you would like to import',
853
+ choices,
854
+ hint: ' - Space to select. Return to submit.',
855
+ instructions: false,
856
+ });
857
+ this.log();
858
+ if (resources === undefined) {
859
+ this.cancelAndExit();
860
+ }
861
+ if (resources.length === 0) {
862
+ this.style.fatal(`You did not choose any resources.`);
863
+ this.cancelAndExit();
864
+ }
865
+ return resources.map(parseFilter);
866
+ }
867
+ case 'exit':
868
+ // falls through
869
+ default: {
870
+ this.cancelAndExit();
871
+ }
872
+ }
873
+ }
874
+ #generateCode(plan, program, codegen, friendExports) {
875
+ this.style.actionStart('Generating Checkly constructs for imported resources');
876
+ try {
877
+ const context = new codegen_1.Context();
878
+ const failures = new Map();
879
+ if (plan.changes) {
880
+ const { resources, friends, auxiliary } = plan.changes;
881
+ if (friends) {
882
+ for (const resource of friends) {
883
+ try {
884
+ if (friendExports[resource.type] === undefined) {
885
+ throw new Error(`Unable to process unsupported friend resource type '${resource.type}'.`);
886
+ }
887
+ const friendExport = friendExports[resource.type].get(resource.logicalId);
888
+ if (friendExport === undefined) {
889
+ throw new Error(`Received friend resource '${resource.logicalId}' that was not requested for.`);
890
+ }
891
+ switch (resource.type) {
892
+ case 'alert-channel':
893
+ context.registerFriendAlertChannel(resource.physicalId, friendExport);
894
+ break;
895
+ case 'check-group':
896
+ context.registerFriendCheckGroup(resource.physicalId, friendExport);
897
+ break;
898
+ case 'private-location':
899
+ context.registerFriendPrivateLocation(resource.physicalId, friendExport);
900
+ break;
901
+ case 'status-page-service':
902
+ context.registerFriendStatusPageService(resource.physicalId, friendExport);
903
+ break;
904
+ }
905
+ }
906
+ catch (cause) {
907
+ throw new Error(`Failed to process friend resource '${resource.type}:${resource.physicalId}' (${resource.logicalId}): ${cause}`, { cause });
908
+ }
909
+ }
910
+ }
911
+ if (auxiliary) {
912
+ const globalSnippetFiles = new Set();
913
+ for (const resource of auxiliary) {
914
+ try {
915
+ switch (resource.type) {
916
+ case 'snippet': {
917
+ const snippet = resource.payload;
918
+ if (!(0, snippet_1.isSnippet)(snippet)) {
919
+ throw new Error(`Invalid auxiliary snippet`);
920
+ }
921
+ const snippetFilePath = context.filePath('snippets', snippet.name, {
922
+ unique: false,
923
+ contentKey: `snippet::${snippet.id}`,
924
+ case: (0, snippet_1.isSafeSnippetFilename)(snippet.name) ? 'identity' : 'kebab-case',
925
+ });
926
+ const snippetFile = program.staticSupportFile(snippetFilePath.fullPath, snippet.script);
927
+ globalSnippetFiles.add(snippetFile);
928
+ context.registerAuxiliarySnippetFile(snippet.id, snippetFile);
929
+ break;
930
+ }
931
+ default:
932
+ throw new Error(`Unable to process unsupported auxiliary resource type '${resource.type}'.`);
933
+ }
934
+ }
935
+ catch (cause) {
936
+ throw new Error(`Failed to process auxiliary resource '${resource.type}:${resource.physicalId}': ${cause}`, { cause });
937
+ }
938
+ }
939
+ // Due to questionable historical design choices, snippets may
940
+ // reference other snippets in two ways:
941
+ //
942
+ // 1. From the same folder (i.e. `require('./other-snippet')`) if
943
+ // the requiring snippet is NOT the main entrypoint, but has
944
+ // itself been required by another snippet or script.
945
+ // 2. From the magic './snippets' folder using
946
+ // `require('./snippets/other-snippet')` irrespective of whether
947
+ // the requiring snippet is the main entrypoint or not (works in
948
+ // either case).
949
+ //
950
+ // To emulate this functionality with a proper file structure, we
951
+ // need to check if any global snippets are using the second method,
952
+ // and create appropriate aliases in the beatifully named
953
+ // './snippets/snippets/' folder so that the paths can resolve
954
+ // without modification.
955
+ for (const globalSnippetFile of globalSnippetFiles) {
956
+ const content = globalSnippetFile.content.toString();
957
+ const snippetFiles = context.findScriptSnippetFiles(content);
958
+ for (const snippetFile of snippetFiles) {
959
+ const localSnippetFile = program.generatedSupportFile(`snippets/snippets/${snippetFile.basename}`);
960
+ localSnippetFile.header((0, sourcegen_1.docComment)(`This file has been generated to help resolve cross-snippet imports.\n` +
961
+ `\n` +
962
+ `We recommend rewriting your imports to not reference this file, after which\n` +
963
+ `you may remove it.`));
964
+ localSnippetFile.plainImport(localSnippetFile.relativePath(snippetFile));
965
+ }
966
+ }
967
+ }
968
+ (0, construct_codegen_1.sortResources)(resources);
969
+ for (const resource of resources) {
970
+ try {
971
+ codegen.prepare(resource.logicalId, resource, context);
972
+ }
973
+ catch (cause) {
974
+ if (!(cause instanceof Error)) {
975
+ throw cause;
976
+ }
977
+ failures.set(resource.logicalId, {
978
+ resource,
979
+ cause,
980
+ });
981
+ }
982
+ }
983
+ for (const resource of resources) {
984
+ if (failures.has(resource.logicalId)) {
985
+ continue;
986
+ }
987
+ try {
988
+ codegen.gencode(resource.logicalId, resource, context);
989
+ }
990
+ catch (cause) {
991
+ if (!(cause instanceof Error)) {
992
+ throw cause;
993
+ }
994
+ failures.set(resource.logicalId, {
995
+ resource,
996
+ cause,
997
+ });
998
+ }
999
+ }
1000
+ }
1001
+ if (failures.size === 0) {
1002
+ this.style.actionSuccess();
1003
+ }
1004
+ else {
1005
+ this.style.actionFailure();
1006
+ }
1007
+ return {
1008
+ failures: [...failures.values()],
1009
+ };
1010
+ }
1011
+ catch (err) {
1012
+ this.style.actionFailure();
1013
+ throw err;
1014
+ }
1015
+ }
1016
+ async #initializeProject(config) {
1017
+ const { logicalId, projectName, repoUrl, } = config;
1018
+ this.style.actionStart('Checking project status');
1019
+ try {
1020
+ await api.projects.get(logicalId);
1021
+ this.style.actionSuccess();
1022
+ // The project has already been initialized, not need to do anything.
1023
+ return;
1024
+ }
1025
+ catch (err) {
1026
+ this.style.actionFailure();
1027
+ if (!(err instanceof projects_1.ProjectNotFoundError)) {
1028
+ throw err;
1029
+ }
1030
+ // The project does not exist yet and we must create (initialize) it.
1031
+ }
1032
+ const choices = [{
1033
+ title: `Yes, I want to start a new project with the imported resources`,
1034
+ value: 'init',
1035
+ }, {
1036
+ title: `No, I intended to import resources into an existing project`,
1037
+ value: 'mistake',
1038
+ description: 'Exit and verify your configuration.',
1039
+ }, {
1040
+ title: 'No, I want to cancel and exit',
1041
+ value: 'exit',
1042
+ description: 'No changes will be made.',
1043
+ }];
1044
+ const { action } = await (0, prompts_1.default)({
1045
+ name: 'action',
1046
+ type: 'select',
1047
+ message: 'Your project has not been initialized yet. Initialize now?',
1048
+ choices,
1049
+ });
1050
+ this.log();
1051
+ switch (action) {
1052
+ case 'init': {
1053
+ try {
1054
+ this.style.actionStart('Initializing project');
1055
+ await api.projects.create({
1056
+ name: projectName,
1057
+ logicalId,
1058
+ repoUrl,
1059
+ });
1060
+ this.style.actionSuccess();
1061
+ }
1062
+ catch (err) {
1063
+ this.style.actionFailure();
1064
+ throw err;
1065
+ }
1066
+ break;
1067
+ }
1068
+ case 'mistake':
1069
+ this.style.fatal(`Please verify your configuration and try again.`);
1070
+ this.cancelAndExit();
1071
+ break;
1072
+ case 'exit':
1073
+ // falls through
1074
+ default: {
1075
+ this.cancelAndExit();
1076
+ }
1077
+ }
1078
+ }
1079
+ async #handleExistingPlans(plans) {
1080
+ const choices = [{
1081
+ title: 'I want to exit and rethink',
1082
+ value: 'exit',
1083
+ description: 'No changes will be made.',
1084
+ }, {
1085
+ title: 'I want to see some basic details about the existing plans first',
1086
+ value: 'show',
1087
+ }, {
1088
+ title: 'I want to cancel all existing plans and create a new plan',
1089
+ value: 'cancel-proceed',
1090
+ }, {
1091
+ title: 'I want to create a new plan regardless',
1092
+ value: 'new',
1093
+ }];
1094
+ while (true) {
1095
+ const { action } = await (0, prompts_1.default)({
1096
+ name: 'action',
1097
+ type: 'select',
1098
+ message: `Found ${plans.length} existing uncommitted plan(s). How do you want to proceed?`,
1099
+ choices,
1100
+ });
1101
+ this.log();
1102
+ switch (action) {
1103
+ case 'show': {
1104
+ this.log();
1105
+ for (const plan of plans) {
1106
+ this.log(`Plan ${plan.id}:`);
1107
+ this.log(` Created at: ${new Date(plan.createdAt)}`);
1108
+ this.log(` Applied?: ${plan.appliedAt ? 'yes' : 'no'}`);
1109
+ if (plan.appliedAt) {
1110
+ this.log(` Applied at: ${new Date(plan.appliedAt)}`);
1111
+ }
1112
+ this.log();
1113
+ }
1114
+ const { action } = await (0, prompts_1.default)({
1115
+ name: 'action',
1116
+ type: 'select',
1117
+ message: 'Do you want to exit or retry?',
1118
+ choices: [{
1119
+ title: 'Exit',
1120
+ value: 'exit',
1121
+ description: 'No changes will be made.',
1122
+ }, {
1123
+ title: 'Return to previous options',
1124
+ value: 'return',
1125
+ }],
1126
+ });
1127
+ this.log();
1128
+ if (action === 'exit') {
1129
+ this.cancelAndExit();
1130
+ }
1131
+ continue;
1132
+ }
1133
+ case 'cancel-proceed': {
1134
+ this.style.actionStart('Cancelling existing plans');
1135
+ try {
1136
+ for (const plan of plans) {
1137
+ await api.projects.cancelImportPlan(plan.id);
1138
+ this.style.shortSuccess(`Cancelled plan ${plan.id}`);
1139
+ }
1140
+ this.style.actionSuccess();
1141
+ }
1142
+ catch (err) {
1143
+ this.style.actionFailure();
1144
+ throw err;
1145
+ }
1146
+ return;
1147
+ }
1148
+ case 'new': {
1149
+ return;
1150
+ }
1151
+ case 'exit':
1152
+ // falls through
1153
+ default: {
1154
+ this.cancelAndExit();
1155
+ }
1156
+ }
1157
+ }
1158
+ }
1159
+ cancelAndExit() {
1160
+ this.log('Exiting without making any changes.');
1161
+ this.exit(0);
1162
+ }
1163
+ }
1164
+ exports.default = ImportPlanCommand;
1165
+ function previewComment() {
1166
+ return (0, sourcegen_1.docComment)('This Checkly construct file has been generated for preview purposes only.' +
1167
+ '\n\n' +
1168
+ 'Deploying this file will create duplicate resources.');
1169
+ }
1170
+ class InvalidResourceIdentifierError extends Error {
1171
+ }
1172
+ function parseFilter(spec) {
1173
+ const filter = {
1174
+ type: 'include'
1175
+ };
1176
+ if (spec.startsWith('!')) {
1177
+ filter.type = 'exclude';
1178
+ spec = spec.slice(1);
1179
+ }
1180
+ const [type, physicalId] = spec.split(':', 2);
1181
+ const parseId = importables[type];
1182
+ if (parseId === undefined) {
1183
+ throw new Error(`Invalid resource specifier '${spec}': Unsupported resource type '${type}'`);
1184
+ }
1185
+ try {
1186
+ filter.resource = {
1187
+ type,
1188
+ physicalId: parseId(physicalId),
1189
+ };
1190
+ }
1191
+ catch (err) {
1192
+ if (err instanceof InvalidResourceIdentifierError) {
1193
+ throw new Error(`Invalid resource specifier '${spec}': ${err.message}`);
1194
+ }
1195
+ throw err;
1196
+ }
1197
+ return filter;
1198
+ }
1199
+ function integerPhysicalId(value) {
1200
+ if (value === undefined) {
1201
+ return;
1202
+ }
1203
+ if (value === '' || value === '*') {
1204
+ return;
1205
+ }
1206
+ const numberValue = parseInt(value, 10);
1207
+ if (Number.isNaN(numberValue)) {
1208
+ throw new InvalidResourceIdentifierError(`Resource identifier '${value}' must be a valid integer`);
1209
+ }
1210
+ return numberValue;
1211
+ }
1212
+ function uuidPhysicalId(value) {
1213
+ if (value === undefined) {
1214
+ return;
1215
+ }
1216
+ if (value === '' || value === '*') {
1217
+ return;
1218
+ }
1219
+ if (!(0, uuid_1.validate)(value)) {
1220
+ throw new InvalidResourceIdentifierError(`Resource identifier '${value}' must be a valid UUID`);
1221
+ }
1222
+ return value;
1223
+ }
1224
+ const importables = {
1225
+ 'alert-channel': integerPhysicalId,
1226
+ 'check-group': integerPhysicalId,
1227
+ 'check': uuidPhysicalId,
1228
+ 'dashboard': integerPhysicalId,
1229
+ 'maintenance-window': integerPhysicalId,
1230
+ 'private-location': uuidPhysicalId,
1231
+ 'status-page-service': uuidPhysicalId,
1232
+ 'status-page': uuidPhysicalId,
1233
+ };
1234
+ function isFilterable(type) {
1235
+ return importables[type] !== undefined;
1236
+ }
1237
+ //# sourceMappingURL=plan.js.map