@knocklabs/cli 0.3.1 → 1.0.0

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 (69) hide show
  1. package/README.md +343 -55
  2. package/dist/commands/branch/delete.js +4 -1
  3. package/dist/commands/branch/merge.js +82 -0
  4. package/dist/commands/channel/list.js +73 -0
  5. package/dist/commands/environment/list.js +73 -0
  6. package/dist/commands/guide/new.js +276 -0
  7. package/dist/commands/guide/open.js +106 -0
  8. package/dist/commands/guide/pull.js +5 -6
  9. package/dist/commands/guide/push.js +1 -1
  10. package/dist/commands/guide/validate.js +1 -1
  11. package/dist/commands/init.js +108 -0
  12. package/dist/commands/layout/new.js +228 -0
  13. package/dist/commands/layout/open.js +106 -0
  14. package/dist/commands/layout/pull.js +5 -6
  15. package/dist/commands/layout/push.js +1 -1
  16. package/dist/commands/layout/validate.js +1 -1
  17. package/dist/commands/message-type/new.js +228 -0
  18. package/dist/commands/message-type/open.js +106 -0
  19. package/dist/commands/message-type/pull.js +5 -6
  20. package/dist/commands/message-type/push.js +1 -1
  21. package/dist/commands/message-type/validate.js +1 -1
  22. package/dist/commands/partial/new.js +274 -0
  23. package/dist/commands/partial/open.js +106 -0
  24. package/dist/commands/partial/pull.js +5 -6
  25. package/dist/commands/partial/push.js +1 -1
  26. package/dist/commands/partial/validate.js +1 -1
  27. package/dist/commands/pull.js +7 -2
  28. package/dist/commands/push.js +6 -4
  29. package/dist/commands/translation/pull.js +1 -1
  30. package/dist/commands/translation/push.js +1 -1
  31. package/dist/commands/translation/validate.js +1 -1
  32. package/dist/commands/workflow/new.js +179 -54
  33. package/dist/commands/workflow/open.js +106 -0
  34. package/dist/commands/workflow/pull.js +6 -8
  35. package/dist/commands/workflow/push.js +1 -1
  36. package/dist/commands/workflow/validate.js +1 -1
  37. package/dist/lib/api-v1.js +23 -2
  38. package/dist/lib/auth.js +1 -1
  39. package/dist/lib/base-command.js +18 -15
  40. package/dist/lib/helpers/project-config.js +158 -0
  41. package/dist/lib/helpers/request.js +1 -2
  42. package/dist/lib/helpers/string.js +4 -4
  43. package/dist/lib/helpers/typegen.js +1 -1
  44. package/dist/lib/marshal/email-layout/generator.js +152 -0
  45. package/dist/lib/marshal/email-layout/helpers.js +6 -9
  46. package/dist/lib/marshal/email-layout/index.js +1 -0
  47. package/dist/lib/marshal/email-layout/writer.js +15 -3
  48. package/dist/lib/marshal/guide/generator.js +163 -0
  49. package/dist/lib/marshal/guide/helpers.js +6 -10
  50. package/dist/lib/marshal/guide/index.js +1 -0
  51. package/dist/lib/marshal/guide/writer.js +5 -9
  52. package/dist/lib/marshal/message-type/generator.js +139 -0
  53. package/dist/lib/marshal/message-type/helpers.js +6 -10
  54. package/dist/lib/marshal/message-type/index.js +1 -0
  55. package/dist/lib/marshal/message-type/writer.js +5 -1
  56. package/dist/lib/marshal/partial/generator.js +159 -0
  57. package/dist/lib/marshal/partial/helpers.js +6 -10
  58. package/dist/lib/marshal/partial/index.js +1 -0
  59. package/dist/lib/marshal/partial/writer.js +3 -0
  60. package/dist/lib/marshal/translation/helpers.js +6 -10
  61. package/dist/lib/marshal/translation/processor.isomorphic.js +4 -4
  62. package/dist/lib/marshal/translation/writer.js +2 -2
  63. package/dist/lib/marshal/workflow/generator.js +175 -19
  64. package/dist/lib/marshal/workflow/helpers.js +7 -10
  65. package/dist/lib/run-context/loader.js +5 -0
  66. package/dist/lib/templates.js +131 -0
  67. package/dist/lib/urls.js +16 -0
  68. package/oclif.manifest.json +1446 -547
  69. package/package.json +11 -9
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get cleanupTempDir () {
13
+ return cleanupTempDir;
14
+ },
15
+ get downloadTemplate () {
16
+ return downloadTemplate;
17
+ },
18
+ get resolveTemplate () {
19
+ return resolveTemplate;
20
+ }
21
+ });
22
+ const _nodeos = /*#__PURE__*/ _interop_require_wildcard(require("node:os"));
23
+ const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
24
+ const _degit = /*#__PURE__*/ _interop_require_default(require("degit"));
25
+ const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
26
+ function _interop_require_default(obj) {
27
+ return obj && obj.__esModule ? obj : {
28
+ default: obj
29
+ };
30
+ }
31
+ function _getRequireWildcardCache(nodeInterop) {
32
+ if (typeof WeakMap !== "function") return null;
33
+ var cacheBabelInterop = new WeakMap();
34
+ var cacheNodeInterop = new WeakMap();
35
+ return (_getRequireWildcardCache = function(nodeInterop) {
36
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
37
+ })(nodeInterop);
38
+ }
39
+ function _interop_require_wildcard(obj, nodeInterop) {
40
+ if (!nodeInterop && obj && obj.__esModule) {
41
+ return obj;
42
+ }
43
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
44
+ return {
45
+ default: obj
46
+ };
47
+ }
48
+ var cache = _getRequireWildcardCache(nodeInterop);
49
+ if (cache && cache.has(obj)) {
50
+ return cache.get(obj);
51
+ }
52
+ var newObj = {
53
+ __proto__: null
54
+ };
55
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
56
+ for(var key in obj){
57
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
58
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
59
+ if (desc && (desc.get || desc.set)) {
60
+ Object.defineProperty(newObj, key, desc);
61
+ } else {
62
+ newObj[key] = obj[key];
63
+ }
64
+ }
65
+ }
66
+ newObj.default = obj;
67
+ if (cache) {
68
+ cache.set(obj, newObj);
69
+ }
70
+ return newObj;
71
+ }
72
+ const DEFAULT_ORG = "knocklabs";
73
+ const DEFAULT_REPO = "templates";
74
+ const TEMP_DIR_PREFIX = "knock-cli-templates";
75
+ function resolveTemplate(templateString) {
76
+ const parts = templateString.split("/");
77
+ let org;
78
+ let repo;
79
+ let subdir;
80
+ if (parts.length === 2) {
81
+ // workflows/some-workflow
82
+ org = DEFAULT_ORG;
83
+ repo = DEFAULT_REPO;
84
+ subdir = parts.join("/");
85
+ }
86
+ if (parts.length === 4) {
87
+ // knocklabs/templates/workflows/some-workflow
88
+ org = parts[0];
89
+ repo = parts[1];
90
+ subdir = parts.slice(2).join("/");
91
+ }
92
+ if (!org || !repo || !subdir) {
93
+ throw new Error(`Invalid template string: ${templateString}. Expected format: org/repo/subdir`);
94
+ }
95
+ return {
96
+ org,
97
+ repo,
98
+ subdir
99
+ };
100
+ }
101
+ function buildSource(org, repo, subdir, branch = "main") {
102
+ const base = `${org}/${repo}`;
103
+ if (subdir) {
104
+ return `${base}/${subdir}#${branch}`;
105
+ }
106
+ return `${base}#${branch}`;
107
+ }
108
+ async function downloadTemplate(templateString) {
109
+ const { org, repo, subdir } = resolveTemplate(templateString);
110
+ const source = buildSource(org, repo, subdir);
111
+ // Create temp directory for template
112
+ const tempDir = _nodepath.default.join(_nodeos.tmpdir(), TEMP_DIR_PREFIX, `${org}-${repo}-${subdir.replace(/\//g, "-")}-${Date.now()}`);
113
+ await _fsextra.ensureDir(tempDir);
114
+ try {
115
+ const emitter = (0, _degit.default)(source, {
116
+ cache: false,
117
+ force: true,
118
+ verbose: false
119
+ });
120
+ await emitter.clone(tempDir);
121
+ return tempDir;
122
+ } catch (error) {
123
+ await _fsextra.remove(tempDir);
124
+ throw new Error(`Failed to download template: ${error instanceof Error ? error.message : "Unknown error"}\n\nSource: ${source}`);
125
+ }
126
+ }
127
+ async function cleanupTempDir(tempDir) {
128
+ if (tempDir && tempDir.includes(TEMP_DIR_PREFIX)) {
129
+ await _fsextra.remove(tempDir);
130
+ }
131
+ }
package/dist/lib/urls.js CHANGED
@@ -24,6 +24,18 @@ _export(exports, {
24
24
  get authSuccessUrl () {
25
25
  return authSuccessUrl;
26
26
  },
27
+ get viewGuideUrl () {
28
+ return viewGuideUrl;
29
+ },
30
+ get viewLayoutUrl () {
31
+ return viewLayoutUrl;
32
+ },
33
+ get viewMessageTypeUrl () {
34
+ return viewMessageTypeUrl;
35
+ },
36
+ get viewPartialUrl () {
37
+ return viewPartialUrl;
38
+ },
27
39
  get viewWorkflowUrl () {
28
40
  return viewWorkflowUrl;
29
41
  }
@@ -34,3 +46,7 @@ const DEFAULT_API_URL = "https://control.knock.app";
34
46
  const authSuccessUrl = (dashboardUrl)=>`${dashboardUrl}/auth/oauth/cli`;
35
47
  const authErrorUrl = (dashboardUrl, error)=>`${dashboardUrl}/auth/oauth/cli?error=${error}`;
36
48
  const viewWorkflowUrl = (dashboardUrl, accountSlug, envOrBranchSlug, workflowKey)=>`${dashboardUrl}/${accountSlug}/${envOrBranchSlug.toLowerCase()}/workflows/${workflowKey}`;
49
+ const viewGuideUrl = (dashboardUrl, accountSlug, envOrBranchSlug, guideKey)=>`${dashboardUrl}/${accountSlug}/${envOrBranchSlug.toLowerCase()}/guides/${guideKey}`;
50
+ const viewLayoutUrl = (dashboardUrl, accountSlug, envOrBranchSlug, layoutKey)=>`${dashboardUrl}/${accountSlug}/${envOrBranchSlug.toLowerCase()}/layouts/${layoutKey}`;
51
+ const viewMessageTypeUrl = (dashboardUrl, accountSlug, envOrBranchSlug, messageTypeKey)=>`${dashboardUrl}/${accountSlug}/${envOrBranchSlug.toLowerCase()}/message-types/${messageTypeKey}`;
52
+ const viewPartialUrl = (dashboardUrl, accountSlug, envOrBranchSlug, partialKey)=>`${dashboardUrl}/${accountSlug}/${envOrBranchSlug.toLowerCase()}/partials/${partialKey}`;