@dcupl/cli 1.4.0-beta.1 → 1.4.0-beta.10

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 (266) hide show
  1. package/README.md +34 -0
  2. package/dist/cli.js +724 -168
  3. package/dist/cli.js.map +1 -1
  4. package/dist/functions/app/app-id.js +34 -2
  5. package/dist/functions/app/app-id.js.map +1 -1
  6. package/dist/functions/app/client/daemon-client.js.map +1 -1
  7. package/dist/functions/app/commands/cdn-host.d.ts +16 -0
  8. package/dist/functions/app/commands/cdn-host.js +47 -0
  9. package/dist/functions/app/commands/cdn-host.js.map +1 -0
  10. package/dist/functions/app/commands/create.js +50 -34
  11. package/dist/functions/app/commands/create.js.map +1 -1
  12. package/dist/functions/app/commands/destroy.js +10 -4
  13. package/dist/functions/app/commands/destroy.js.map +1 -1
  14. package/dist/functions/app/commands/detect-serve.js +17 -6
  15. package/dist/functions/app/commands/detect-serve.js.map +1 -1
  16. package/dist/functions/app/commands/fn/_fn-helpers.js +11 -3
  17. package/dist/functions/app/commands/fn/_fn-helpers.js.map +1 -1
  18. package/dist/functions/app/commands/fn/aggregate.js +4 -1
  19. package/dist/functions/app/commands/fn/aggregate.js.map +1 -1
  20. package/dist/functions/app/commands/fn/pivot.js.map +1 -1
  21. package/dist/functions/app/commands/list.js +6 -2
  22. package/dist/functions/app/commands/list.js.map +1 -1
  23. package/dist/functions/app/commands/loader-hash.js.map +1 -1
  24. package/dist/functions/app/commands/loaders/add.js +6 -0
  25. package/dist/functions/app/commands/loaders/add.js.map +1 -1
  26. package/dist/functions/app/commands/loaders/process-flags.js +4 -1
  27. package/dist/functions/app/commands/loaders/process-flags.js.map +1 -1
  28. package/dist/functions/app/commands/loaders/process.js +3 -1
  29. package/dist/functions/app/commands/loaders/process.js.map +1 -1
  30. package/dist/functions/app/commands/models/get.js.map +1 -1
  31. package/dist/functions/app/commands/models/keys.js.map +1 -1
  32. package/dist/functions/app/commands/models/remove.js.map +1 -1
  33. package/dist/functions/app/commands/models/set.js +3 -1
  34. package/dist/functions/app/commands/models/set.js.map +1 -1
  35. package/dist/functions/app/commands/query/execute.js +5 -2
  36. package/dist/functions/app/commands/query/execute.js.map +1 -1
  37. package/dist/functions/app/commands/query/one.js +3 -1
  38. package/dist/functions/app/commands/query/one.js.map +1 -1
  39. package/dist/functions/app/commands/render.js +10 -4
  40. package/dist/functions/app/commands/render.js.map +1 -1
  41. package/dist/functions/app/commands/resolve-app.js.map +1 -1
  42. package/dist/functions/app/commands/resolve-source.d.ts +1 -0
  43. package/dist/functions/app/commands/resolve-source.js +20 -5
  44. package/dist/functions/app/commands/resolve-source.js.map +1 -1
  45. package/dist/functions/app/commands/validate-report.d.ts +31 -0
  46. package/dist/functions/app/commands/validate-report.js +20 -1
  47. package/dist/functions/app/commands/validate-report.js.map +1 -1
  48. package/dist/functions/app/commands/validate.d.ts +1 -0
  49. package/dist/functions/app/commands/validate.js +31 -10
  50. package/dist/functions/app/commands/validate.js.map +1 -1
  51. package/dist/functions/app/daemon/app-server.module.js +6 -1
  52. package/dist/functions/app/daemon/app-server.module.js.map +1 -1
  53. package/dist/functions/app/daemon/controllers/data.controller.js +17 -6
  54. package/dist/functions/app/daemon/controllers/data.controller.js.map +1 -1
  55. package/dist/functions/app/daemon/controllers/lifecycle.controller.js.map +1 -1
  56. package/dist/functions/app/daemon/controllers/query.controller.js +4 -1
  57. package/dist/functions/app/daemon/controllers/query.controller.js.map +1 -1
  58. package/dist/functions/app/daemon/daemon-args.js +2 -2
  59. package/dist/functions/app/daemon/daemon-args.js.map +1 -1
  60. package/dist/functions/app/daemon/filters/envelope-exception.filter.js +6 -1
  61. package/dist/functions/app/daemon/filters/envelope-exception.filter.js.map +1 -1
  62. package/dist/functions/app/daemon/main.js +14 -7
  63. package/dist/functions/app/daemon/main.js.map +1 -1
  64. package/dist/functions/app/daemon/services/attribute-validation.d.ts +21 -0
  65. package/dist/functions/app/daemon/services/attribute-validation.js +164 -0
  66. package/dist/functions/app/daemon/services/attribute-validation.js.map +1 -0
  67. package/dist/functions/app/daemon/services/dcupl-host.service.d.ts +5 -0
  68. package/dist/functions/app/daemon/services/dcupl-host.service.js +83 -16
  69. package/dist/functions/app/daemon/services/dcupl-host.service.js.map +1 -1
  70. package/dist/functions/app/daemon/services/idle-watchdog.service.js.map +1 -1
  71. package/dist/functions/app/daemon/services/ingest.service.js +8 -4
  72. package/dist/functions/app/daemon/services/ingest.service.js.map +1 -1
  73. package/dist/functions/app/daemon/services/init-options.js.map +1 -1
  74. package/dist/functions/app/daemon/services/loaders.service.d.ts +3 -1
  75. package/dist/functions/app/daemon/services/loaders.service.js +22 -6
  76. package/dist/functions/app/daemon/services/loaders.service.js.map +1 -1
  77. package/dist/functions/app/e2e/port-lock.d.ts +8 -0
  78. package/dist/functions/app/e2e/port-lock.js +66 -2
  79. package/dist/functions/app/e2e/port-lock.js.map +1 -1
  80. package/dist/functions/app/registry/registry.js +11 -10
  81. package/dist/functions/app/registry/registry.js.map +1 -1
  82. package/dist/functions/app/registry/serve-registry.js +13 -9
  83. package/dist/functions/app/registry/serve-registry.js.map +1 -1
  84. package/dist/functions/app/types.d.ts +2 -0
  85. package/dist/functions/config/commands/set.js +2 -2
  86. package/dist/functions/config/commands/set.js.map +1 -1
  87. package/dist/functions/config/io.js +1 -3
  88. package/dist/functions/config/io.js.map +1 -1
  89. package/dist/functions/config/prompts.js +1 -3
  90. package/dist/functions/config/prompts.js.map +1 -1
  91. package/dist/functions/files/commands/copy.js +1 -1
  92. package/dist/functions/files/commands/copy.js.map +1 -1
  93. package/dist/functions/files/commands/delete.js +1 -1
  94. package/dist/functions/files/commands/delete.js.map +1 -1
  95. package/dist/functions/files/commands/list.js +6 -3
  96. package/dist/functions/files/commands/list.js.map +1 -1
  97. package/dist/functions/files/commands/move.js +1 -1
  98. package/dist/functions/files/commands/move.js.map +1 -1
  99. package/dist/functions/files/commands/pull.d.ts +16 -1
  100. package/dist/functions/files/commands/pull.js +135 -1
  101. package/dist/functions/files/commands/pull.js.map +1 -1
  102. package/dist/functions/files/commands/push.d.ts +1 -0
  103. package/dist/functions/files/commands/push.js +25 -3
  104. package/dist/functions/files/commands/push.js.map +1 -1
  105. package/dist/functions/files/commands/read.js +3 -2
  106. package/dist/functions/files/commands/read.js.map +1 -1
  107. package/dist/functions/files/commands/render.d.ts +29 -0
  108. package/dist/functions/files/commands/render.js +8 -4
  109. package/dist/functions/files/commands/render.js.map +1 -1
  110. package/dist/functions/files/commands/status.js +1 -0
  111. package/dist/functions/files/commands/status.js.map +1 -1
  112. package/dist/functions/files/commands/versions/copy.js +1 -1
  113. package/dist/functions/files/commands/versions/copy.js.map +1 -1
  114. package/dist/functions/files/commands/versions/delete.js +1 -1
  115. package/dist/functions/files/commands/versions/delete.js.map +1 -1
  116. package/dist/functions/files/commands/versions/list.js +4 -0
  117. package/dist/functions/files/commands/versions/list.js.map +1 -1
  118. package/dist/functions/files/commands/write.js +13 -3
  119. package/dist/functions/files/commands/write.js.map +1 -1
  120. package/dist/functions/files/files-push.js +1 -1
  121. package/dist/functions/files/files-push.js.map +1 -1
  122. package/dist/functions/files/helper/text-policy.d.ts +5 -0
  123. package/dist/functions/files/helper/text-policy.js +31 -0
  124. package/dist/functions/files/helper/text-policy.js.map +1 -0
  125. package/dist/functions/files/sync/large-upload.d.ts +20 -0
  126. package/dist/functions/files/sync/large-upload.js +140 -0
  127. package/dist/functions/files/sync/large-upload.js.map +1 -0
  128. package/dist/functions/files/sync/manifest.js +2 -1
  129. package/dist/functions/files/sync/manifest.js.map +1 -1
  130. package/dist/functions/files/sync/transfer.d.ts +5 -0
  131. package/dist/functions/files/sync/transfer.js +47 -10
  132. package/dist/functions/files/sync/transfer.js.map +1 -1
  133. package/dist/functions/files/test-helpers.d.ts +11 -0
  134. package/dist/functions/files/test-helpers.js +28 -0
  135. package/dist/functions/files/test-helpers.js.map +1 -1
  136. package/dist/functions/generate/files/generate-code.d.ts +1 -1
  137. package/dist/functions/generate/files/generate-files.d.ts +7 -1
  138. package/dist/functions/generate/files/generate-files.js +63 -15
  139. package/dist/functions/generate/files/generate-files.js.map +1 -1
  140. package/dist/functions/generate/files/workflow-presets.d.ts +6 -0
  141. package/dist/functions/generate/files/workflow-presets.js +158 -0
  142. package/dist/functions/generate/files/workflow-presets.js.map +1 -0
  143. package/dist/functions/generate/model-from-data/generate-model-from-data.js +8 -3
  144. package/dist/functions/generate/model-from-data/generate-model-from-data.js.map +1 -1
  145. package/dist/functions/generate/model-from-data/infer-key.js +1 -4
  146. package/dist/functions/generate/model-from-data/infer-key.js.map +1 -1
  147. package/dist/functions/generate/model-from-data/infer-to-model.js +1 -2
  148. package/dist/functions/generate/model-from-data/infer-to-model.js.map +1 -1
  149. package/dist/functions/generate/projects/generate-project.d.ts +5 -0
  150. package/dist/functions/generate/projects/generate-project.js +29 -8
  151. package/dist/functions/generate/projects/generate-project.js.map +1 -1
  152. package/dist/functions/helper/api-client.d.ts +3 -0
  153. package/dist/functions/helper/api-client.js +10 -3
  154. package/dist/functions/helper/api-client.js.map +1 -1
  155. package/dist/functions/helper/config.helper.d.ts +1 -0
  156. package/dist/functions/helper/config.helper.js.map +1 -1
  157. package/dist/functions/helper/output.d.ts +1 -1
  158. package/dist/functions/helper/output.js +10 -12
  159. package/dist/functions/helper/output.js.map +1 -1
  160. package/dist/functions/helper/parse-fail.js +4 -1
  161. package/dist/functions/helper/parse-fail.js.map +1 -1
  162. package/dist/functions/schemas/command.js.map +1 -1
  163. package/dist/functions/schemas/examples/AppLoaderConfiguration.example.json +1 -3
  164. package/dist/functions/schemas/examples/DataMapperStepConfig.example.json +6 -1
  165. package/dist/functions/schemas/examples/ModelDefinition.example.json +8 -1
  166. package/dist/functions/schemas/examples/ScriptStepConfig.example.json +3 -1
  167. package/dist/functions/schemas/examples/TemplateV3.example.json +5 -1
  168. package/dist/functions/schemas/extract.js +1 -1
  169. package/dist/functions/schemas/extract.js.map +1 -1
  170. package/dist/functions/schemas/format.js +4 -4
  171. package/dist/functions/schemas/format.js.map +1 -1
  172. package/dist/functions/schemas/registry.d.ts +14 -0
  173. package/dist/functions/schemas/registry.js +103 -30
  174. package/dist/functions/schemas/registry.js.map +1 -1
  175. package/dist/functions/schemas/resolve.js +1 -2
  176. package/dist/functions/schemas/resolve.js.map +1 -1
  177. package/dist/functions/schemas/validate.d.ts +22 -0
  178. package/dist/functions/schemas/validate.js +67 -0
  179. package/dist/functions/schemas/validate.js.map +1 -0
  180. package/dist/functions/serve/commands/list.js +2 -1
  181. package/dist/functions/serve/commands/list.js.map +1 -1
  182. package/dist/functions/serve/commands/stop.js +10 -5
  183. package/dist/functions/serve/commands/stop.js.map +1 -1
  184. package/dist/functions/serve/dev-server/dev-server-access.guard.d.ts +11 -0
  185. package/dist/functions/serve/dev-server/dev-server-access.guard.js +41 -0
  186. package/dist/functions/serve/dev-server/dev-server-access.guard.js.map +1 -0
  187. package/dist/functions/serve/dev-server/dev-server.controller.d.ts +3 -0
  188. package/dist/functions/serve/dev-server/dev-server.controller.js +20 -0
  189. package/dist/functions/serve/dev-server/dev-server.controller.js.map +1 -1
  190. package/dist/functions/serve/dev-server/dev-server.module.d.ts +3 -0
  191. package/dist/functions/serve/dev-server/dev-server.module.js +34 -23
  192. package/dist/functions/serve/dev-server/dev-server.module.js.map +1 -1
  193. package/dist/functions/serve/dev-server/dev-server.options.d.ts +8 -0
  194. package/dist/functions/serve/dev-server/dev-server.options.js +5 -0
  195. package/dist/functions/serve/dev-server/dev-server.options.js.map +1 -0
  196. package/dist/functions/serve/dev-server/dev-server.service.d.ts +11 -3
  197. package/dist/functions/serve/dev-server/dev-server.service.js +72 -65
  198. package/dist/functions/serve/dev-server/dev-server.service.js.map +1 -1
  199. package/dist/functions/serve/dev-server/path-scope.d.ts +5 -0
  200. package/dist/functions/serve/dev-server/path-scope.js +88 -0
  201. package/dist/functions/serve/dev-server/path-scope.js.map +1 -0
  202. package/dist/functions/serve/dev-server/request-security.d.ts +34 -0
  203. package/dist/functions/serve/dev-server/request-security.js +145 -0
  204. package/dist/functions/serve/dev-server/request-security.js.map +1 -0
  205. package/dist/functions/serve/main.d.ts +13 -0
  206. package/dist/functions/serve/main.js +85 -13
  207. package/dist/functions/serve/main.js.map +1 -1
  208. package/dist/functions/serve/serve-self-register.js +2 -1
  209. package/dist/functions/serve/serve-self-register.js.map +1 -1
  210. package/dist/functions/version/command.js +1 -6
  211. package/dist/functions/version/command.js.map +1 -1
  212. package/dist/functions/workflow/commands/deploy.d.ts +9 -1
  213. package/dist/functions/workflow/commands/deploy.js +39 -10
  214. package/dist/functions/workflow/commands/deploy.js.map +1 -1
  215. package/dist/functions/workflow/commands/get.js.map +1 -1
  216. package/dist/functions/workflow/commands/history.js.map +1 -1
  217. package/dist/functions/workflow/commands/run.d.ts +26 -0
  218. package/dist/functions/workflow/commands/run.js +101 -0
  219. package/dist/functions/workflow/commands/run.js.map +1 -0
  220. package/dist/functions/workflow/commands/runners-get.js.map +1 -1
  221. package/dist/functions/workflow/commands/runners.d.ts +2 -0
  222. package/dist/functions/workflow/commands/runners.js +10 -1
  223. package/dist/functions/workflow/commands/runners.js.map +1 -1
  224. package/dist/functions/workflow/commands/status.d.ts +1 -1
  225. package/dist/functions/workflow/commands/status.js +7 -1
  226. package/dist/functions/workflow/commands/status.js.map +1 -1
  227. package/dist/functions/workflow/commands/template.js.map +1 -1
  228. package/dist/functions/workflow/commands/test.d.ts +3 -0
  229. package/dist/functions/workflow/commands/test.js +22 -73
  230. package/dist/functions/workflow/commands/test.js.map +1 -1
  231. package/dist/functions/workflow/commands/trace.d.ts +4 -2
  232. package/dist/functions/workflow/commands/trace.js +22 -1
  233. package/dist/functions/workflow/commands/trace.js.map +1 -1
  234. package/dist/functions/workflow/commands/undeploy.js +3 -1
  235. package/dist/functions/workflow/commands/undeploy.js.map +1 -1
  236. package/dist/functions/workflow/commands/validate.d.ts +2 -0
  237. package/dist/functions/workflow/commands/validate.js +16 -2
  238. package/dist/functions/workflow/commands/validate.js.map +1 -1
  239. package/dist/functions/workflow/resolve-runner.d.ts +17 -0
  240. package/dist/functions/workflow/resolve-runner.js +41 -0
  241. package/dist/functions/workflow/resolve-runner.js.map +1 -0
  242. package/dist/functions/workflow/run-failure.d.ts +11 -0
  243. package/dist/functions/workflow/run-failure.js +74 -0
  244. package/dist/functions/workflow/run-failure.js.map +1 -0
  245. package/dist/functions/workflow/runner-health.d.ts +16 -0
  246. package/dist/functions/workflow/runner-health.js +36 -0
  247. package/dist/functions/workflow/runner-health.js.map +1 -0
  248. package/dist/functions/workflow/script-lint.d.ts +10 -0
  249. package/dist/functions/workflow/script-lint.js +513 -0
  250. package/dist/functions/workflow/script-lint.js.map +1 -0
  251. package/dist/functions/workflow/trace.js.map +1 -1
  252. package/dist/functions/workflow/types.d.ts +11 -2
  253. package/dist/functions/workflow/types.js +4 -0
  254. package/dist/functions/workflow/types.js.map +1 -1
  255. package/dist/functions/workflow/validate.js +4 -1
  256. package/dist/functions/workflow/validate.js.map +1 -1
  257. package/dist/functions/workflow/wait-for-swap.d.ts +24 -1
  258. package/dist/functions/workflow/wait-for-swap.js +58 -0
  259. package/dist/functions/workflow/wait-for-swap.js.map +1 -1
  260. package/dist/functions/workflow/workflow-api.js +3 -1
  261. package/dist/functions/workflow/workflow-api.js.map +1 -1
  262. package/files/dev-server/index.html +2 -1
  263. package/package.json +24 -18
  264. package/dist/functions/serve/guards/apiKey.guard.d.ts +0 -4
  265. package/dist/functions/serve/guards/apiKey.guard.js +0 -23
  266. package/dist/functions/serve/guards/apiKey.guard.js.map +0 -1
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorBody = errorBody;
4
+ exports.errorStatus = errorStatus;
5
+ exports.errorMessage = errorMessage;
6
+ exports.reportRunFailure = reportRunFailure;
7
+ const trace_js_1 = require("./trace.js");
8
+ function errorBody(err) {
9
+ const e = err;
10
+ return e.response?.data ?? e.responseData;
11
+ }
12
+ function errorStatus(err) {
13
+ const e = err;
14
+ return e.response?.status ?? e.statusCode;
15
+ }
16
+ function errorMessage(err) {
17
+ return err.message ?? String(err);
18
+ }
19
+ function nodeTypeById(template, nodeId) {
20
+ if (!template || !nodeId)
21
+ return undefined;
22
+ const nodes = (template.config?.nodes ?? []);
23
+ return nodes.find((n) => n.id === nodeId)?.type;
24
+ }
25
+ function hasFilesNode(template) {
26
+ const nodes = (template?.config?.nodes ?? []);
27
+ return nodes.some((n) => n.type === 'dcupl-files');
28
+ }
29
+ function looks403(status, runError) {
30
+ if (status === 403)
31
+ return true;
32
+ const hay = `${runError?.message ?? ''} ${runError?.errorType ?? ''} ${runError?.detail ?? ''}`.toLowerCase();
33
+ return /\b403\b|forbidden|unauthor/.test(hay);
34
+ }
35
+ const FILES_AUTH_HINT = 'dcupl-files auth failed (403) — check auth.apiKey: use {{variables.dcupl_api_key}} or the api-key id from the console, never the key value';
36
+ function filesAuthHint(template, status, runError, reachedRun) {
37
+ if (!looks403(status, runError))
38
+ return undefined;
39
+ if (nodeTypeById(template, runError?.nodeId) === 'dcupl-files')
40
+ return FILES_AUTH_HINT;
41
+ if (reachedRun && !runError?.nodeId && hasFilesNode(template))
42
+ return FILES_AUTH_HINT;
43
+ return undefined;
44
+ }
45
+ function reportRunFailure(output, err, ctx) {
46
+ const body = errorBody(err);
47
+ const status = errorStatus(err);
48
+ const trace = (0, trace_js_1.toTrace)(body);
49
+ if (Object.keys(trace.nodes ?? {}).length > 0 || trace.status === 'failed') {
50
+ output.success(trace, () => (0, trace_js_1.renderTrace)(trace));
51
+ output.error('Workflow run failed on the runner (see trace above).', 'WORKFLOW_RUN_ERROR');
52
+ return;
53
+ }
54
+ const runError = (0, trace_js_1.toRunError)(body);
55
+ if (runError) {
56
+ output.success(runError, () => (0, trace_js_1.renderRunError)(runError));
57
+ const hint = filesAuthHint(ctx.template, status, runError, ctx.reachedRun);
58
+ if (hint) {
59
+ output.error(hint, 'WORKFLOW_FILES_AUTH');
60
+ return;
61
+ }
62
+ const where = runError.nodeId ? ` @ nodeId: ${runError.nodeId}` : '';
63
+ output.error(`${runError.message}${where}`, 'WORKFLOW_RUN_ERROR');
64
+ return;
65
+ }
66
+ const hint = filesAuthHint(ctx.template, status, undefined, ctx.reachedRun);
67
+ if (hint) {
68
+ output.error(hint, 'WORKFLOW_FILES_AUTH');
69
+ return;
70
+ }
71
+ const suffix = status ? ` (HTTP ${status})` : '';
72
+ output.error(`${errorMessage(err)}${suffix}`, ctx.failedCode);
73
+ }
74
+ //# sourceMappingURL=run-failure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-failure.js","sourceRoot":"","sources":["../../../src/functions/workflow/run-failure.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,16 @@
1
+ export type RunnerHealth = {
2
+ status: 'ok';
3
+ httpStatus: number;
4
+ } | {
5
+ status: 'unknown';
6
+ httpStatus: number;
7
+ } | {
8
+ status: 'unreachable';
9
+ httpStatus?: number;
10
+ reason: string;
11
+ };
12
+ export declare const DEFAULT_HEALTH_TIMEOUT_MS = 5000;
13
+ export declare function probeRunnerHealth(runnerUrl: string, opts?: {
14
+ timeoutMs?: number;
15
+ }): Promise<RunnerHealth>;
16
+ export declare function renderHealth(health: RunnerHealth): string;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_HEALTH_TIMEOUT_MS = void 0;
4
+ exports.probeRunnerHealth = probeRunnerHealth;
5
+ exports.renderHealth = renderHealth;
6
+ const tslib_1 = require("tslib");
7
+ const axios_1 = tslib_1.__importDefault(require("axios"));
8
+ exports.DEFAULT_HEALTH_TIMEOUT_MS = 5000;
9
+ async function probeRunnerHealth(runnerUrl, opts = {}) {
10
+ const url = `${runnerUrl.replace(/\/$/, '')}/health`;
11
+ try {
12
+ const res = await axios_1.default.request({
13
+ method: 'GET',
14
+ url,
15
+ timeout: opts.timeoutMs ?? exports.DEFAULT_HEALTH_TIMEOUT_MS,
16
+ validateStatus: () => true,
17
+ });
18
+ if (res.status >= 200 && res.status < 300)
19
+ return { status: 'ok', httpStatus: res.status };
20
+ if (res.status >= 500)
21
+ return { status: 'unreachable', httpStatus: res.status, reason: `health endpoint returned HTTP ${res.status}` };
22
+ return { status: 'unknown', httpStatus: res.status };
23
+ }
24
+ catch (err) {
25
+ const e = err;
26
+ return { status: 'unreachable', reason: e.code ?? e.message ?? 'request failed' };
27
+ }
28
+ }
29
+ function renderHealth(health) {
30
+ if (health.status === 'ok')
31
+ return 'ok';
32
+ if (health.status === 'unknown')
33
+ return 'unknown';
34
+ return `unreachable (${health.reason})`;
35
+ }
36
+ //# sourceMappingURL=runner-health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner-health.js","sourceRoot":"","sources":["../../../src/functions/workflow/runner-health.ts"],"names":[],"mappings":";;;AAeA,8CAiBC;AAGD,oCAIC;;AAvCD,0DAA0B;AAOb,QAAA,yBAAyB,GAAG,IAAI,CAAC;AAQvC,KAAK,UAAU,iBAAiB,CAAC,SAAiB,EAAE,OAA+B,EAAE;IAC1F,MAAM,GAAG,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC;IACrD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,eAAK,CAAC,OAAO,CAAC;YAC9B,MAAM,EAAE,KAAK;YACb,GAAG;YACH,OAAO,EAAE,IAAI,CAAC,SAAS,IAAI,iCAAyB;YACpD,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;SAC3B,CAAC,CAAC;QACH,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG;YAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;QAC3F,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG;YACnB,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,iCAAiC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC;QAClH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;IACvD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,GAAG,GAAgC,CAAC;QAC3C,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,IAAI,gBAAgB,EAAE,CAAC;IACpF,CAAC;AACH,CAAC;AAGD,SAAgB,YAAY,CAAC,MAAoB;IAC/C,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACxC,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAClD,OAAO,gBAAgB,MAAM,CAAC,MAAM,GAAG,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ValidationError } from './types.js';
2
+ export declare const SANDBOX_DOLLAR_GLOBALS: readonly string[];
3
+ export declare const SANDBOX_UNDERSCORE_GLOBALS: readonly string[];
4
+ export interface LintableNode {
5
+ id: string;
6
+ type: string;
7
+ config?: unknown;
8
+ }
9
+ export declare function lintWorkflowScripts(nodes: ReadonlyArray<LintableNode>): ValidationError[];
10
+ export declare function lintScriptCode(nodeId: string, code: string): ValidationError[];
@@ -0,0 +1,513 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SANDBOX_UNDERSCORE_GLOBALS = exports.SANDBOX_DOLLAR_GLOBALS = void 0;
4
+ exports.lintWorkflowScripts = lintWorkflowScripts;
5
+ exports.lintScriptCode = lintScriptCode;
6
+ exports.SANDBOX_DOLLAR_GLOBALS = ['$items', '$json', '$input', '$context', '$state', '$ports'];
7
+ exports.SANDBOX_UNDERSCORE_GLOBALS = [
8
+ '_output',
9
+ '_csv',
10
+ '_json',
11
+ '_array',
12
+ '_string',
13
+ '_object',
14
+ '_datetime',
15
+ '_xml',
16
+ '_nodes',
17
+ ];
18
+ const BLOCKED_GLOBAL_HINTS = {
19
+ _http: 'blocked in the script sandbox — perform HTTP calls in a `request` step instead',
20
+ _crypto: 'blocked in the script sandbox — compute crypto values outside the workflow and pass them in via variables',
21
+ };
22
+ const RUNTIME_INTERNALS = [
23
+ '__items',
24
+ '__context',
25
+ '__inputPorts',
26
+ '__stateData',
27
+ '__consoleLogs',
28
+ '__ports__',
29
+ ];
30
+ const BARE_NAME_HINTS = {
31
+ csvToJson: {
32
+ hint: 'is not available in the script sandbox — use `_csv.toJSON(...)` instead',
33
+ suggestion: '_csv.toJSON(...)',
34
+ },
35
+ jsonToCsv: {
36
+ hint: 'is not available in the script sandbox — use `_csv.fromJSON(...)` instead',
37
+ suggestion: '_csv.fromJSON(...)',
38
+ },
39
+ items: {
40
+ hint: 'is not defined in the script sandbox — use `$items()` to access input items',
41
+ suggestion: '$items()',
42
+ },
43
+ input: {
44
+ hint: 'is not defined in the script sandbox — use `$json()` to access input JSON (or `$items()` for full items)',
45
+ suggestion: '$json()',
46
+ },
47
+ };
48
+ const FETCH_HINT = 'is not available in the script sandbox — perform HTTP calls in a `request` step instead';
49
+ const ALLOWED = new Set([...exports.SANDBOX_DOLLAR_GLOBALS, ...exports.SANDBOX_UNDERSCORE_GLOBALS, ...RUNTIME_INTERNALS]);
50
+ function lintWorkflowScripts(nodes) {
51
+ const warnings = [];
52
+ for (const node of nodes ?? []) {
53
+ if (node.type !== 'script' && node.type !== 'response-script')
54
+ continue;
55
+ const config = (node.config ?? {});
56
+ const code = typeof config.script === 'string' ? config.script : typeof config.code === 'string' ? config.code : undefined;
57
+ if (!code)
58
+ continue;
59
+ warnings.push(...lintScriptCode(node.id, code));
60
+ }
61
+ return warnings;
62
+ }
63
+ function lintScriptCode(nodeId, code) {
64
+ if (!code || !code.trim())
65
+ return [];
66
+ const masked = maskNonCode(code);
67
+ const declared = collectDeclaredNames(masked);
68
+ const warnings = [];
69
+ const reported = new Set();
70
+ const identRe = /[A-Za-z_$][A-Za-z0-9_$]*/g;
71
+ for (const match of masked.matchAll(identRe)) {
72
+ const name = match[0];
73
+ const start = match.index ?? 0;
74
+ const end = start + name.length;
75
+ if (reported.has(name) || declared.has(name))
76
+ continue;
77
+ if (prevNonWs(masked, start - 1) === '.')
78
+ continue;
79
+ const nextIdx = nextNonWsIdx(masked, end);
80
+ const nextCh = nextIdx === -1 ? '' : masked[nextIdx];
81
+ if (nextCh === ':')
82
+ continue;
83
+ let isCall = false;
84
+ if (nextCh === '(') {
85
+ isCall = true;
86
+ const close = matchParen(masked, nextIdx);
87
+ if (close !== -1 && masked[nextNonWsIdx(masked, close + 1)] === '{')
88
+ continue;
89
+ }
90
+ const warning = classify(name, isCall);
91
+ if (!warning)
92
+ continue;
93
+ reported.add(name);
94
+ const line = lineOf(masked, start);
95
+ warnings.push({
96
+ type: 'missing-reference',
97
+ message: `${warning.message} (line ${line})`,
98
+ node: nodeId,
99
+ context: { identifier: name, line, ...(warning.suggestion ? { suggestion: warning.suggestion } : {}) },
100
+ });
101
+ }
102
+ return warnings;
103
+ }
104
+ function classify(name, isCall) {
105
+ const bare = BARE_NAME_HINTS[name];
106
+ if (bare)
107
+ return { message: `\`${name}\` ${bare.hint}`, suggestion: bare.suggestion };
108
+ if (name === 'fetch' && isCall) {
109
+ return { message: `\`fetch\` ${FETCH_HINT}`, suggestion: 'request step' };
110
+ }
111
+ if (!name.startsWith('$') && !name.startsWith('_'))
112
+ return undefined;
113
+ if (ALLOWED.has(name))
114
+ return undefined;
115
+ const blocked = BLOCKED_GLOBAL_HINTS[name];
116
+ if (blocked) {
117
+ return {
118
+ message: `\`${name}\` is ${blocked}`,
119
+ suggestion: name === '_http' ? 'request step' : 'workflow variables',
120
+ };
121
+ }
122
+ const nearest = nearestGlobal(name);
123
+ if (nearest) {
124
+ const blockedNote = BLOCKED_GLOBAL_HINTS[nearest] ? ` (\`${nearest}\` is ${BLOCKED_GLOBAL_HINTS[nearest]})` : '';
125
+ return {
126
+ message: `\`${name}\` is not a sandbox global — did you mean \`${nearest}\`?${blockedNote}`,
127
+ suggestion: nearest,
128
+ };
129
+ }
130
+ const known = name.startsWith('$')
131
+ ? `known \`$\` globals: ${exports.SANDBOX_DOLLAR_GLOBALS.join(', ')}`
132
+ : `known \`_\` helpers: ${exports.SANDBOX_UNDERSCORE_GLOBALS.filter((g) => g !== '_nodes').join(', ')}`;
133
+ return { message: `\`${name}\` is not a sandbox global — ${known}` };
134
+ }
135
+ function nearestGlobal(name) {
136
+ const candidates = [...exports.SANDBOX_DOLLAR_GLOBALS, ...exports.SANDBOX_UNDERSCORE_GLOBALS, ...Object.keys(BLOCKED_GLOBAL_HINTS)];
137
+ let best;
138
+ let bestDistance = 3;
139
+ for (const candidate of candidates) {
140
+ const distance = editDistance(name, candidate);
141
+ if (distance < bestDistance) {
142
+ bestDistance = distance;
143
+ best = candidate;
144
+ }
145
+ }
146
+ return best;
147
+ }
148
+ function editDistance(a, b) {
149
+ const dp = Array.from({ length: b.length + 1 }, (_, j) => j);
150
+ for (let i = 1; i <= a.length; i++) {
151
+ let diagonal = dp[0];
152
+ dp[0] = i;
153
+ for (let j = 1; j <= b.length; j++) {
154
+ const previous = dp[j];
155
+ dp[j] = Math.min(dp[j] + 1, dp[j - 1] + 1, diagonal + (a[i - 1] === b[j - 1] ? 0 : 1));
156
+ diagonal = previous;
157
+ }
158
+ }
159
+ return dp[b.length];
160
+ }
161
+ function maskNonCode(src) {
162
+ const out = src.split('');
163
+ const n = src.length;
164
+ const blank = (idx) => {
165
+ if (out[idx] !== '\n')
166
+ out[idx] = ' ';
167
+ };
168
+ const stack = [{ kind: 'code', braceDepth: 0 }];
169
+ let i = 0;
170
+ while (i < n) {
171
+ const frame = stack[stack.length - 1];
172
+ const c = src[i];
173
+ const next = i + 1 < n ? src[i + 1] : '';
174
+ if (frame.kind === 'template') {
175
+ if (c === '\\') {
176
+ blank(i);
177
+ if (i + 1 < n)
178
+ blank(i + 1);
179
+ i += 2;
180
+ continue;
181
+ }
182
+ if (c === '`') {
183
+ blank(i);
184
+ i++;
185
+ stack.pop();
186
+ continue;
187
+ }
188
+ if (c === '$' && next === '{') {
189
+ blank(i);
190
+ blank(i + 1);
191
+ i += 2;
192
+ stack.push({ kind: 'code', braceDepth: 0 });
193
+ continue;
194
+ }
195
+ blank(i);
196
+ i++;
197
+ continue;
198
+ }
199
+ if (c === '/' && next === '/') {
200
+ while (i < n && src[i] !== '\n') {
201
+ blank(i);
202
+ i++;
203
+ }
204
+ continue;
205
+ }
206
+ if (c === '/' && next === '*') {
207
+ blank(i);
208
+ blank(i + 1);
209
+ i += 2;
210
+ while (i < n && !(src[i] === '*' && src[i + 1] === '/')) {
211
+ blank(i);
212
+ i++;
213
+ }
214
+ if (i < n) {
215
+ blank(i);
216
+ blank(i + 1);
217
+ i += 2;
218
+ }
219
+ continue;
220
+ }
221
+ if (c === "'" || c === '"') {
222
+ blank(i);
223
+ i++;
224
+ while (i < n && src[i] !== c && src[i] !== '\n') {
225
+ if (src[i] === '\\') {
226
+ blank(i);
227
+ i++;
228
+ if (i < n) {
229
+ blank(i);
230
+ i++;
231
+ }
232
+ continue;
233
+ }
234
+ blank(i);
235
+ i++;
236
+ }
237
+ if (i < n && src[i] === c) {
238
+ blank(i);
239
+ i++;
240
+ }
241
+ continue;
242
+ }
243
+ if (c === '`') {
244
+ blank(i);
245
+ i++;
246
+ stack.push({ kind: 'template' });
247
+ continue;
248
+ }
249
+ if (c === '{') {
250
+ frame.braceDepth++;
251
+ i++;
252
+ continue;
253
+ }
254
+ if (c === '}') {
255
+ if (frame.braceDepth === 0 && stack.length > 1) {
256
+ blank(i);
257
+ i++;
258
+ stack.pop();
259
+ continue;
260
+ }
261
+ if (frame.braceDepth > 0)
262
+ frame.braceDepth--;
263
+ i++;
264
+ continue;
265
+ }
266
+ if (c === '/' && isRegexPosition(out, i)) {
267
+ blank(i);
268
+ i++;
269
+ let inClass = false;
270
+ while (i < n && src[i] !== '\n') {
271
+ if (src[i] === '\\') {
272
+ blank(i);
273
+ i++;
274
+ if (i < n) {
275
+ blank(i);
276
+ i++;
277
+ }
278
+ continue;
279
+ }
280
+ if (src[i] === '[')
281
+ inClass = true;
282
+ else if (src[i] === ']')
283
+ inClass = false;
284
+ else if (src[i] === '/' && !inClass)
285
+ break;
286
+ blank(i);
287
+ i++;
288
+ }
289
+ if (i < n && src[i] === '/') {
290
+ blank(i);
291
+ i++;
292
+ }
293
+ while (i < n && /[a-z]/i.test(src[i])) {
294
+ blank(i);
295
+ i++;
296
+ }
297
+ continue;
298
+ }
299
+ i++;
300
+ }
301
+ return out.join('');
302
+ }
303
+ const REGEX_PRECEDING_KEYWORDS = new Set([
304
+ 'return',
305
+ 'typeof',
306
+ 'instanceof',
307
+ 'in',
308
+ 'of',
309
+ 'new',
310
+ 'delete',
311
+ 'void',
312
+ 'throw',
313
+ 'case',
314
+ 'do',
315
+ 'else',
316
+ 'yield',
317
+ 'await',
318
+ ]);
319
+ function isRegexPosition(maskedSoFar, slashIdx) {
320
+ let i = slashIdx - 1;
321
+ while (i >= 0 && /\s/.test(maskedSoFar[i]))
322
+ i--;
323
+ if (i < 0)
324
+ return true;
325
+ const ch = maskedSoFar[i];
326
+ if (/[A-Za-z0-9_$]/.test(ch)) {
327
+ let start = i;
328
+ while (start >= 0 && /[A-Za-z0-9_$]/.test(maskedSoFar[start]))
329
+ start--;
330
+ const word = maskedSoFar.slice(start + 1, i + 1).join('');
331
+ return REGEX_PRECEDING_KEYWORDS.has(word);
332
+ }
333
+ if (ch === ')' || ch === ']')
334
+ return false;
335
+ return true;
336
+ }
337
+ function collectDeclaredNames(masked) {
338
+ const declared = new Set();
339
+ const declRe = /\b(?:const|let|var)\b/g;
340
+ for (const match of masked.matchAll(declRe)) {
341
+ collectDeclarators(masked, (match.index ?? 0) + match[0].length, declared);
342
+ }
343
+ const fnRe = /\bfunction\b/g;
344
+ for (const match of masked.matchAll(fnRe)) {
345
+ let j = (match.index ?? 0) + match[0].length;
346
+ j = skipWs(masked, j);
347
+ if (masked[j] === '*')
348
+ j = skipWs(masked, j + 1);
349
+ const name = readIdentifier(masked, j);
350
+ if (name) {
351
+ declared.add(name);
352
+ j += name.length;
353
+ }
354
+ j = skipWs(masked, j);
355
+ if (masked[j] === '(')
356
+ addIdentifiersInSpan(masked, j, declared);
357
+ }
358
+ for (const match of masked.matchAll(/\bclass\s+([A-Za-z_$][A-Za-z0-9_$]*)/g))
359
+ declared.add(match[1]);
360
+ for (const match of masked.matchAll(/\bcatch\s*\(\s*([A-Za-z_$][A-Za-z0-9_$]*)/g))
361
+ declared.add(match[1]);
362
+ for (const match of masked.matchAll(/=>/g)) {
363
+ let j = (match.index ?? 0) - 1;
364
+ while (j >= 0 && /\s/.test(masked[j]))
365
+ j--;
366
+ if (j < 0)
367
+ continue;
368
+ if (masked[j] === ')') {
369
+ let depth = 1;
370
+ let k = j - 1;
371
+ while (k >= 0 && depth > 0) {
372
+ if (masked[k] === ')')
373
+ depth++;
374
+ else if (masked[k] === '(')
375
+ depth--;
376
+ k--;
377
+ }
378
+ if (depth === 0)
379
+ addIdentifiersIn(masked.slice(k + 2, j), declared);
380
+ }
381
+ else if (/[A-Za-z0-9_$]/.test(masked[j])) {
382
+ let k = j;
383
+ while (k >= 0 && /[A-Za-z0-9_$]/.test(masked[k]))
384
+ k--;
385
+ const name = masked.slice(k + 1, j + 1);
386
+ if (/^[A-Za-z_$]/.test(name))
387
+ declared.add(name);
388
+ }
389
+ }
390
+ const methodRe = /([A-Za-z_$][A-Za-z0-9_$]*)\s*\(/g;
391
+ const controlKeywords = new Set(['if', 'for', 'while', 'switch', 'catch', 'with', 'function']);
392
+ for (const match of masked.matchAll(methodRe)) {
393
+ const name = match[1];
394
+ if (controlKeywords.has(name))
395
+ continue;
396
+ const openIdx = (match.index ?? 0) + match[0].length - 1;
397
+ const close = matchParen(masked, openIdx);
398
+ if (close === -1)
399
+ continue;
400
+ if (masked[nextNonWsIdx(masked, close + 1)] === '{')
401
+ addIdentifiersInSpan(masked, openIdx, declared);
402
+ }
403
+ return declared;
404
+ }
405
+ function collectDeclarators(masked, from, declared) {
406
+ let j = skipWs(masked, from);
407
+ const readTarget = () => {
408
+ j = skipWs(masked, j);
409
+ if (masked[j] === '{' || masked[j] === '[') {
410
+ j = addIdentifiersInSpan(masked, j, declared);
411
+ return;
412
+ }
413
+ const name = readIdentifier(masked, j);
414
+ if (name) {
415
+ declared.add(name);
416
+ j += name.length;
417
+ }
418
+ };
419
+ readTarget();
420
+ let depth = 0;
421
+ let lastSignificant = '';
422
+ while (j < masked.length) {
423
+ const c = masked[j];
424
+ if (c === '(' || c === '[' || c === '{')
425
+ depth++;
426
+ else if (c === ')' || c === ']' || c === '}') {
427
+ depth--;
428
+ if (depth < 0)
429
+ return;
430
+ }
431
+ else if (depth === 0) {
432
+ if (c === ';')
433
+ return;
434
+ if (c === ',') {
435
+ j++;
436
+ readTarget();
437
+ lastSignificant = ',';
438
+ continue;
439
+ }
440
+ if (c === '\n') {
441
+ if (!/[,=([{+\-*/&|<>?:.]/.test(lastSignificant))
442
+ return;
443
+ }
444
+ }
445
+ if (!/\s/.test(c))
446
+ lastSignificant = c;
447
+ j++;
448
+ }
449
+ }
450
+ function addIdentifiersInSpan(masked, openIdx, declared) {
451
+ const open = masked[openIdx];
452
+ const close = open === '(' ? ')' : open === '[' ? ']' : '}';
453
+ let depth = 0;
454
+ for (let i = openIdx; i < masked.length; i++) {
455
+ if (masked[i] === open)
456
+ depth++;
457
+ else if (masked[i] === close) {
458
+ depth--;
459
+ if (depth === 0) {
460
+ addIdentifiersIn(masked.slice(openIdx + 1, i), declared);
461
+ return i + 1;
462
+ }
463
+ }
464
+ }
465
+ addIdentifiersIn(masked.slice(openIdx + 1), declared);
466
+ return masked.length;
467
+ }
468
+ function addIdentifiersIn(span, declared) {
469
+ for (const match of span.matchAll(/[A-Za-z_$][A-Za-z0-9_$]*/g))
470
+ declared.add(match[0]);
471
+ }
472
+ function skipWs(s, idx) {
473
+ let i = idx;
474
+ while (i < s.length && /\s/.test(s[i]))
475
+ i++;
476
+ return i;
477
+ }
478
+ function readIdentifier(s, idx) {
479
+ const match = /^[A-Za-z_$][A-Za-z0-9_$]*/.exec(s.slice(idx, idx + 128));
480
+ return match ? match[0] : undefined;
481
+ }
482
+ function prevNonWs(s, idx) {
483
+ let i = idx;
484
+ while (i >= 0 && /\s/.test(s[i]))
485
+ i--;
486
+ return i >= 0 ? s[i] : '';
487
+ }
488
+ function nextNonWsIdx(s, idx) {
489
+ let i = skipWs(s, idx);
490
+ return i < s.length ? i : -1;
491
+ }
492
+ function matchParen(s, openIdx) {
493
+ let depth = 0;
494
+ for (let i = openIdx; i < s.length; i++) {
495
+ if (s[i] === '(')
496
+ depth++;
497
+ else if (s[i] === ')') {
498
+ depth--;
499
+ if (depth === 0)
500
+ return i;
501
+ }
502
+ }
503
+ return -1;
504
+ }
505
+ function lineOf(s, idx) {
506
+ let line = 1;
507
+ for (let i = 0; i < idx; i++) {
508
+ if (s[i] === '\n')
509
+ line++;
510
+ }
511
+ return line;
512
+ }
513
+ //# sourceMappingURL=script-lint.js.map