@knocklabs/cli 0.2.1 → 0.2.3

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 (64) hide show
  1. package/README.md +258 -36
  2. package/dist/commands/branch/create.js +1 -1
  3. package/dist/commands/branch/delete.js +1 -1
  4. package/dist/commands/branch/exit.js +44 -0
  5. package/dist/commands/branch/switch.js +161 -0
  6. package/dist/commands/commit/get.js +4 -4
  7. package/dist/commands/commit/index.js +47 -2
  8. package/dist/commands/commit/list.js +61 -13
  9. package/dist/commands/guide/activate.js +48 -4
  10. package/dist/commands/guide/generate-types.js +4 -1
  11. package/dist/commands/guide/get.js +46 -3
  12. package/dist/commands/guide/list.js +46 -3
  13. package/dist/commands/guide/pull.js +6 -4
  14. package/dist/commands/guide/push.js +4 -3
  15. package/dist/commands/guide/validate.js +4 -3
  16. package/dist/commands/layout/get.js +46 -1
  17. package/dist/commands/layout/list.js +46 -1
  18. package/dist/commands/layout/pull.js +6 -2
  19. package/dist/commands/layout/push.js +4 -1
  20. package/dist/commands/layout/validate.js +4 -1
  21. package/dist/commands/login.js +1 -0
  22. package/dist/commands/logout.js +1 -0
  23. package/dist/commands/message-type/get.js +46 -3
  24. package/dist/commands/message-type/list.js +46 -3
  25. package/dist/commands/message-type/pull.js +6 -4
  26. package/dist/commands/message-type/push.js +4 -3
  27. package/dist/commands/message-type/validate.js +4 -3
  28. package/dist/commands/partial/get.js +46 -1
  29. package/dist/commands/partial/list.js +46 -1
  30. package/dist/commands/partial/pull.js +6 -2
  31. package/dist/commands/partial/push.js +4 -1
  32. package/dist/commands/partial/validate.js +6 -1
  33. package/dist/commands/pull.js +28 -8
  34. package/dist/commands/push.js +27 -8
  35. package/dist/commands/translation/get.js +5 -1
  36. package/dist/commands/translation/list.js +5 -1
  37. package/dist/commands/translation/pull.js +8 -3
  38. package/dist/commands/translation/push.js +4 -1
  39. package/dist/commands/translation/validate.js +4 -1
  40. package/dist/commands/workflow/activate.js +47 -3
  41. package/dist/commands/workflow/generate-types.js +4 -1
  42. package/dist/commands/workflow/get.js +9 -4
  43. package/dist/commands/workflow/list.js +5 -1
  44. package/dist/commands/workflow/pull.js +6 -2
  45. package/dist/commands/workflow/push.js +4 -1
  46. package/dist/commands/workflow/run.js +46 -2
  47. package/dist/commands/workflow/validate.js +4 -1
  48. package/dist/lib/api-v1.js +35 -12
  49. package/dist/lib/helpers/arg.js +6 -5
  50. package/dist/lib/helpers/branch.js +124 -0
  51. package/dist/lib/helpers/command.js +14 -0
  52. package/dist/lib/helpers/error.js +5 -0
  53. package/dist/lib/helpers/flag.js +23 -0
  54. package/dist/lib/helpers/git.js +25 -0
  55. package/dist/lib/helpers/request.js +1 -1
  56. package/dist/lib/helpers/string.js +4 -0
  57. package/dist/lib/marshal/commit/index.js +0 -1
  58. package/dist/lib/marshal/translation/helpers.js +1 -1
  59. package/dist/lib/resources.js +6 -1
  60. package/dist/lib/urls.js +4 -0
  61. package/oclif.manifest.json +414 -50
  62. package/package.json +15 -5
  63. package/dist/commands/ping.js +0 -37
  64. package/dist/lib/marshal/commit/types.js +0 -5
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "default", {
11
11
  const _core = require("@oclif/core");
12
12
  const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
13
13
  const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
14
+ const _command = require("../../lib/helpers/command");
14
15
  const _const = require("../../lib/helpers/const");
15
16
  const _error = require("../../lib/helpers/error");
16
17
  const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
@@ -101,7 +102,8 @@ class WorkflowGenerateTypes extends _basecommand.default {
101
102
  }
102
103
  // 3. Write the generated types to the output file.
103
104
  await _fsextra.writeFile(flags["output-file"].abspath, result.lines.join("\n"));
104
- this.log(`‣ Successfully generated types for ${workflowsWithValidTypes.length} workflow(s) and wrote them to ${flags["output-file"].abspath}`);
105
+ const scope = (0, _command.formatCommandScope)(flags);
106
+ this.log(`‣ Successfully generated types for ${workflowsWithValidTypes.length} workflow(s) using ${scope} and wrote them to ${flags["output-file"].abspath}`);
105
107
  }
106
108
  async listAllWorkflows(pageParams = {}, workflowsFetchedSoFar = []) {
107
109
  const props = (0, _objectisomorphic.merge)(this.props, {
@@ -132,6 +134,7 @@ _define_property(WorkflowGenerateTypes, "flags", {
132
134
  summary: "Select the environment to generate types for.",
133
135
  default: _const.KnockEnv.Development
134
136
  }),
137
+ branch: _flag.branch,
135
138
  "output-file": _flag.filePath({
136
139
  summary: "The output file to write the generated types to. We currently support .ts, .rb, .go, .py files only. Your file extension will determine the target language for the generated types.",
137
140
  required: true
@@ -10,13 +10,16 @@ Object.defineProperty(exports, "default", {
10
10
  });
11
11
  const _core = require("@oclif/core");
12
12
  const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
13
+ const _command = require("../../lib/helpers/command");
13
14
  const _date = require("../../lib/helpers/date");
14
15
  const _error = require("../../lib/helpers/error");
16
+ const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
15
17
  const _request = require("../../lib/helpers/request");
16
18
  const _string = require("../../lib/helpers/string");
17
19
  const _ux = require("../../lib/helpers/ux");
18
20
  const _conditions = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/conditions"));
19
21
  const _workflow = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/workflow"));
22
+ const _urls = require("../../lib/urls");
20
23
  function _define_property(obj, key, value) {
21
24
  if (key in obj) {
22
25
  Object.defineProperty(obj, key, {
@@ -103,9 +106,10 @@ class WorkflowGet extends _basecommand.default {
103
106
  }
104
107
  render(workflow, whoami) {
105
108
  const { workflowKey } = this.props.args;
106
- const { environment: env, "hide-uncommitted-changes": commitedOnly } = this.props.flags;
109
+ const { environment: env, branch, "hide-uncommitted-changes": commitedOnly } = this.props.flags;
107
110
  const qualifier = env === "development" && !commitedOnly ? "(including uncommitted)" : "";
108
- this.log(`‣ Showing workflow \`${workflowKey}\` in \`${env}\` environment ${qualifier}\n`);
111
+ const scope = (0, _command.formatCommandScope)(this.props.flags);
112
+ this.log(`‣ Showing workflow \`${workflowKey}\` in ${scope} ${qualifier}\n`);
109
113
  /*
110
114
  * Workflow table
111
115
  */ const rows = [
@@ -191,9 +195,9 @@ class WorkflowGet extends _basecommand.default {
191
195
  });
192
196
  const hasTopLevelBranchStep = workflow.steps.some((step)=>step.type === _workflow.StepType.Branch);
193
197
  const dashboardLinkMessage = hasTopLevelBranchStep ? `\n‣ This workflow has branches with nested steps, view the full workflow tree in the Knock Dashboard:` : `\n‣ View the full workflow in the Knock Dashboard:`;
194
- const viewWorkflowUrl = `https://dashboard.knock.app/${whoami.account_slug}/${env.toLowerCase()}/workflows/${workflow.key}`;
198
+ const url = (0, _urls.viewWorkflowUrl)(this.sessionContext.dashboardOrigin, whoami.account_slug, branch !== null && branch !== void 0 ? branch : env, workflow.key);
195
199
  this.log(dashboardLinkMessage);
196
- this.log((0, _string.indentString)(viewWorkflowUrl, 2));
200
+ this.log((0, _string.indentString)(url, 2));
197
201
  }
198
202
  }
199
203
  _define_property(WorkflowGet, "summary", "Display a single workflow from an environment.");
@@ -202,6 +206,7 @@ _define_property(WorkflowGet, "flags", {
202
206
  default: "development",
203
207
  summary: "The environment to use."
204
208
  }),
209
+ branch: _flag.branch,
205
210
  "hide-uncommitted-changes": _core.Flags.boolean({
206
211
  summary: "Hide any uncommitted changes."
207
212
  })
@@ -10,7 +10,9 @@ Object.defineProperty(exports, "default", {
10
10
  });
11
11
  const _core = require("@oclif/core");
12
12
  const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
13
+ const _command = require("../../lib/helpers/command");
13
14
  const _date = require("../../lib/helpers/date");
15
+ const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
14
16
  const _objectisomorphic = require("../../lib/helpers/object.isomorphic");
15
17
  const _page = require("../../lib/helpers/page");
16
18
  const _request = require("../../lib/helpers/request");
@@ -93,7 +95,8 @@ class WorkflowList extends _basecommand.default {
93
95
  const { entries } = data;
94
96
  const { environment: env, "hide-uncommitted-changes": commitedOnly } = this.props.flags;
95
97
  const qualifier = env === "development" && !commitedOnly ? "(including uncommitted)" : "";
96
- this.log(`‣ Showing ${entries.length} workflows in \`${env}\` environment ${qualifier}\n`);
98
+ const scope = (0, _command.formatCommandScope)(this.props.flags);
99
+ this.log(`‣ Showing ${entries.length} workflows in ${scope} ${qualifier}\n`);
97
100
  /*
98
101
  * Workflows list table
99
102
  */ _core.ux.table(entries, {
@@ -144,6 +147,7 @@ _define_property(WorkflowList, "flags", {
144
147
  default: "development",
145
148
  summary: "The environment to use."
146
149
  }),
150
+ branch: _flag.branch,
147
151
  "hide-uncommitted-changes": _core.Flags.boolean({
148
152
  summary: "Hide any uncommitted changes."
149
153
  }),
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "default", {
11
11
  const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require("node:path"));
12
12
  const _core = require("@oclif/core");
13
13
  const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
14
+ const _command = require("../../lib/helpers/command");
14
15
  const _error = require("../../lib/helpers/error");
15
16
  const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
16
17
  const _objectisomorphic = require("../../lib/helpers/object.isomorphic");
@@ -114,7 +115,8 @@ class WorkflowPull extends _basecommand.default {
114
115
  // 3. Write the fetched workflow to create or update the workflow directory.
115
116
  await _workflow.writeWorkflowDirFromData(dirContext, resp.data);
116
117
  const action = dirContext.exists ? "updated" : "created";
117
- this.log(`‣ Successfully ${action} \`${dirContext.key}\` at ${dirContext.abspath}`);
118
+ const scope = (0, _command.formatCommandScope)(flags);
119
+ this.log(`‣ Successfully ${action} \`${dirContext.key}\` at ${dirContext.abspath} using ${scope}`);
118
120
  }
119
121
  async getWorkflowDirContext() {
120
122
  const { workflowKey } = this.props.args;
@@ -163,7 +165,8 @@ class WorkflowPull extends _basecommand.default {
163
165
  await _workflow.writeWorkflowsIndexDir(targetDirCtx, workflows);
164
166
  _ux.spinner.stop();
165
167
  const action = targetDirCtx.exists ? "updated" : "created";
166
- this.log(`‣ Successfully ${action} the workflows directory at ${targetDirCtx.abspath}`);
168
+ const scope = (0, _command.formatCommandScope)(flags);
169
+ this.log(`‣ Successfully ${action} the workflows directory at ${targetDirCtx.abspath} using ${scope}`);
167
170
  }
168
171
  async listAllWorkflows(pageParams = {}, workflowsFetchedSoFar = []) {
169
172
  const props = (0, _objectisomorphic.merge)(this.props, {
@@ -194,6 +197,7 @@ _define_property(WorkflowPull, "flags", {
194
197
  default: "development",
195
198
  summary: "The environment to use."
196
199
  }),
200
+ branch: _flag.branch,
197
201
  all: _core.Flags.boolean({
198
202
  summary: "Whether to pull all workflows from the specified environment."
199
203
  }),
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "default", {
10
10
  });
11
11
  const _core = require("@oclif/core");
12
12
  const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
13
+ const _command = require("../../lib/helpers/command");
13
14
  const _const = require("../../lib/helpers/const");
14
15
  const _error = require("../../lib/helpers/error");
15
16
  const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
@@ -130,7 +131,8 @@ class WorkflowPush extends _basecommand.default {
130
131
  // 4. Display a success message.
131
132
  const workflowKeys = workflows.map((w)=>w.key);
132
133
  const actioned = flags.commit ? "pushed and committed" : "pushed";
133
- this.log(`‣ Successfully ${actioned} ${workflows.length} workflow(s):\n` + (0, _string.indentString)(workflowKeys.join("\n"), 4));
134
+ const scope = (0, _command.formatCommandScope)(flags);
135
+ this.log(`‣ Successfully ${actioned} ${workflows.length} workflow(s) to ${scope}:\n` + (0, _string.indentString)(workflowKeys.join("\n"), 4));
134
136
  }
135
137
  }
136
138
  _define_property(WorkflowPush, "summary", "Push one or more workflows from a local file system to Knock.");
@@ -142,6 +144,7 @@ _define_property(WorkflowPush, "flags", {
142
144
  _const.KnockEnv.Development
143
145
  ]
144
146
  }),
147
+ branch: _flag.branch,
145
148
  all: _core.Flags.boolean({
146
149
  summary: "Whether to push all workflows from the target directory."
147
150
  }),
@@ -10,7 +10,8 @@ Object.defineProperty(exports, "default", {
10
10
  });
11
11
  const _core = require("@oclif/core");
12
12
  const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
13
- const _flag = require("../../lib/helpers/flag");
13
+ const _command = require("../../lib/helpers/command");
14
+ const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
14
15
  const _request = require("../../lib/helpers/request");
15
16
  const _string = require("../../lib/helpers/string");
16
17
  function _define_property(obj, key, value) {
@@ -31,13 +32,55 @@ function _interop_require_default(obj) {
31
32
  default: obj
32
33
  };
33
34
  }
35
+ function _getRequireWildcardCache(nodeInterop) {
36
+ if (typeof WeakMap !== "function") return null;
37
+ var cacheBabelInterop = new WeakMap();
38
+ var cacheNodeInterop = new WeakMap();
39
+ return (_getRequireWildcardCache = function(nodeInterop) {
40
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
41
+ })(nodeInterop);
42
+ }
43
+ function _interop_require_wildcard(obj, nodeInterop) {
44
+ if (!nodeInterop && obj && obj.__esModule) {
45
+ return obj;
46
+ }
47
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
48
+ return {
49
+ default: obj
50
+ };
51
+ }
52
+ var cache = _getRequireWildcardCache(nodeInterop);
53
+ if (cache && cache.has(obj)) {
54
+ return cache.get(obj);
55
+ }
56
+ var newObj = {
57
+ __proto__: null
58
+ };
59
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
60
+ for(var key in obj){
61
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
62
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
63
+ if (desc && (desc.get || desc.set)) {
64
+ Object.defineProperty(newObj, key, desc);
65
+ } else {
66
+ newObj[key] = obj[key];
67
+ }
68
+ }
69
+ }
70
+ newObj.default = obj;
71
+ if (cache) {
72
+ cache.set(obj, newObj);
73
+ }
74
+ return newObj;
75
+ }
34
76
  class WorkflowRun extends _basecommand.default {
35
77
  async run() {
36
78
  const { args, flags } = this.props;
37
79
  const resp = await (0, _request.withSpinner)(()=>this.apiV1.runWorkflow(this.props), {
38
80
  action: "‣ Running"
39
81
  });
40
- this.log(`‣ Successfully ran \`${args.workflowKey}\` workflow in \`${flags.environment}\` environment`);
82
+ const scope = (0, _command.formatCommandScope)(flags);
83
+ this.log(`‣ Successfully ran \`${args.workflowKey}\` workflow in ${scope}`);
41
84
  this.log((0, _string.indentString)(`Workflow run id: ${resp.data.workflow_run_id}`, 4));
42
85
  }
43
86
  }
@@ -47,6 +90,7 @@ _define_property(WorkflowRun, "flags", {
47
90
  default: "development",
48
91
  summary: "The environment in which to run the workflow"
49
92
  }),
93
+ branch: _flag.branch,
50
94
  recipients: (0, _flag.maybeJsonStrAsList)({
51
95
  required: true,
52
96
  aliases: [
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "default", {
10
10
  });
11
11
  const _core = require("@oclif/core");
12
12
  const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
13
+ const _command = require("../../lib/helpers/command");
13
14
  const _const = require("../../lib/helpers/const");
14
15
  const _error = require("../../lib/helpers/error");
15
16
  const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
@@ -102,7 +103,8 @@ class WorkflowValidate extends _basecommand.default {
102
103
  _ux.spinner.stop();
103
104
  // 3. Display a success message.
104
105
  const workflowKeys = workflows.map((w)=>w.key);
105
- this.log(`‣ Successfully validated ${workflows.length} workflow(s):\n` + (0, _string.indentString)(workflowKeys.join("\n"), 4));
106
+ const scope = (0, _command.formatCommandScope)(this.props.flags);
107
+ this.log(`‣ Successfully validated ${workflows.length} workflow(s) using ${scope}:\n` + (0, _string.indentString)(workflowKeys.join("\n"), 4));
106
108
  }
107
109
  static async validateAll(api, props, workflows) {
108
110
  // TODO: Throw an error if a non validation error (e.g. authentication error)
@@ -129,6 +131,7 @@ _define_property(WorkflowValidate, "flags", {
129
131
  _const.KnockEnv.Development
130
132
  ]
131
133
  }),
134
+ branch: _flag.branch,
132
135
  all: _core.Flags.boolean({
133
136
  summary: "Whether to validate all workflows from the target directory."
134
137
  }),
@@ -40,9 +40,6 @@ class ApiV1 {
40
40
  getToken(sessionContext) {
41
41
  return sessionContext.session ? sessionContext.session.accessToken : sessionContext.token;
42
42
  }
43
- async ping() {
44
- return this.get("/ping");
45
- }
46
43
  async whoami() {
47
44
  return this.get("/whoami");
48
45
  }
@@ -50,6 +47,7 @@ class ApiV1 {
50
47
  async listWorkflows({ flags }) {
51
48
  const params = (0, _objectisomorphic.prune)({
52
49
  environment: flags.environment,
50
+ branch: flags.branch,
53
51
  annotate: flags.annotate,
54
52
  hide_uncommitted_changes: flags["hide-uncommitted-changes"],
55
53
  ...(0, _page.toPageParams)(flags)
@@ -61,6 +59,7 @@ class ApiV1 {
61
59
  async getWorkflow({ args, flags }) {
62
60
  const params = (0, _objectisomorphic.prune)({
63
61
  environment: flags.environment,
62
+ branch: flags.branch,
64
63
  annotate: flags.annotate,
65
64
  hide_uncommitted_changes: flags["hide-uncommitted-changes"]
66
65
  });
@@ -71,6 +70,7 @@ class ApiV1 {
71
70
  async upsertWorkflow({ flags }, workflow) {
72
71
  const params = (0, _objectisomorphic.prune)({
73
72
  environment: flags.environment,
73
+ branch: flags.branch,
74
74
  annotate: flags.annotate,
75
75
  commit: flags.commit,
76
76
  commit_message: flags["commit-message"]
@@ -84,7 +84,8 @@ class ApiV1 {
84
84
  }
85
85
  async validateWorkflow({ flags }, workflow) {
86
86
  const params = (0, _objectisomorphic.prune)({
87
- environment: flags.environment
87
+ environment: flags.environment,
88
+ branch: flags.branch
88
89
  });
89
90
  const data = {
90
91
  workflow
@@ -96,6 +97,7 @@ class ApiV1 {
96
97
  async activateWorkflow({ args, flags }) {
97
98
  const params = (0, _objectisomorphic.prune)({
98
99
  environment: flags.environment,
100
+ branch: flags.branch,
99
101
  status: flags.status
100
102
  });
101
103
  return this.put(`/workflows/${args.workflowKey}/activate`, {}, {
@@ -104,7 +106,8 @@ class ApiV1 {
104
106
  }
105
107
  async runWorkflow({ args, flags }) {
106
108
  const params = (0, _objectisomorphic.prune)({
107
- environment: flags.environment
109
+ environment: flags.environment,
110
+ branch: flags.branch
108
111
  });
109
112
  const data = (0, _objectisomorphic.prune)({
110
113
  recipients: flags.recipients,
@@ -120,6 +123,7 @@ class ApiV1 {
120
123
  async listCommits({ flags }) {
121
124
  const params = (0, _objectisomorphic.prune)({
122
125
  environment: flags.environment,
126
+ branch: flags.branch,
123
127
  promoted: flags.promoted,
124
128
  resource_type: flags["resource-type"],
125
129
  resource_id: flags["resource-id"],
@@ -129,12 +133,10 @@ class ApiV1 {
129
133
  params
130
134
  });
131
135
  }
132
- async getCommit({ args }) {
133
- return this.get(`/commits/${args.id}`);
134
- }
135
136
  async commitAllChanges({ flags }) {
136
137
  const params = (0, _objectisomorphic.prune)({
137
138
  environment: flags.environment,
139
+ branch: flags.branch,
138
140
  commit_message: flags["commit-message"]
139
141
  });
140
142
  return this.put(`/commits`, {}, {
@@ -156,6 +158,7 @@ class ApiV1 {
156
158
  async listTranslations({ flags }, filters = {}) {
157
159
  const params = (0, _objectisomorphic.prune)({
158
160
  environment: flags.environment,
161
+ branch: flags.branch,
159
162
  hide_uncommitted_changes: flags["hide-uncommitted-changes"],
160
163
  locale_code: filters.localeCode,
161
164
  namespace: filters.namespace,
@@ -169,6 +172,7 @@ class ApiV1 {
169
172
  async getTranslation({ flags }, translation) {
170
173
  const params = (0, _objectisomorphic.prune)({
171
174
  environment: flags.environment,
175
+ branch: flags.branch,
172
176
  hide_uncommitted_changes: flags["hide-uncommitted-changes"],
173
177
  namespace: translation.namespace,
174
178
  format: flags.format
@@ -180,6 +184,7 @@ class ApiV1 {
180
184
  async upsertTranslation({ flags }, translation) {
181
185
  const params = (0, _objectisomorphic.prune)({
182
186
  environment: flags.environment,
187
+ branch: flags.branch,
183
188
  commit: flags.commit,
184
189
  commit_message: flags["commit-message"],
185
190
  namespace: translation.namespace
@@ -193,6 +198,7 @@ class ApiV1 {
193
198
  async validateTranslation({ flags }, translation) {
194
199
  const params = (0, _objectisomorphic.prune)({
195
200
  environment: flags.environment,
201
+ branch: flags.branch,
196
202
  namespace: translation.namespace
197
203
  });
198
204
  const data = {
@@ -206,6 +212,7 @@ class ApiV1 {
206
212
  async listEmailLayouts({ flags }) {
207
213
  const params = (0, _objectisomorphic.prune)({
208
214
  environment: flags.environment,
215
+ branch: flags.branch,
209
216
  annotate: flags.annotate,
210
217
  hide_uncommitted_changes: flags["hide-uncommitted-changes"],
211
218
  ...(0, _page.toPageParams)(flags)
@@ -217,6 +224,7 @@ class ApiV1 {
217
224
  async getEmailLayout({ args, flags }) {
218
225
  const params = (0, _objectisomorphic.prune)({
219
226
  environment: flags.environment,
227
+ branch: flags.branch,
220
228
  annotate: flags.annotate,
221
229
  hide_uncommitted_changes: flags["hide-uncommitted-changes"]
222
230
  });
@@ -227,6 +235,7 @@ class ApiV1 {
227
235
  async upsertEmailLayout({ flags }, layout) {
228
236
  const params = (0, _objectisomorphic.prune)({
229
237
  environment: flags.environment,
238
+ branch: flags.branch,
230
239
  annotate: flags.annotate,
231
240
  commit: flags.commit,
232
241
  commit_message: flags["commit-message"]
@@ -240,7 +249,8 @@ class ApiV1 {
240
249
  }
241
250
  async validateEmailLayout({ flags }, layout) {
242
251
  const params = (0, _objectisomorphic.prune)({
243
- environment: flags.environment
252
+ environment: flags.environment,
253
+ branch: flags.branch
244
254
  });
245
255
  const data = {
246
256
  email_layout: layout
@@ -253,6 +263,7 @@ class ApiV1 {
253
263
  async listPartials({ flags }) {
254
264
  const params = (0, _objectisomorphic.prune)({
255
265
  environment: flags.environment,
266
+ branch: flags.branch,
256
267
  hide_uncommitted_changes: flags["hide-uncommitted-changes"],
257
268
  annotate: flags.annotate,
258
269
  ...(0, _page.toPageParams)(flags)
@@ -264,6 +275,7 @@ class ApiV1 {
264
275
  async getPartial({ args, flags }) {
265
276
  const params = (0, _objectisomorphic.prune)({
266
277
  environment: flags.environment,
278
+ branch: flags.branch,
267
279
  annotate: flags.annotate,
268
280
  hide_uncommitted_changes: flags["hide-uncommitted-changes"]
269
281
  });
@@ -274,6 +286,7 @@ class ApiV1 {
274
286
  async upsertPartial({ flags }, partial) {
275
287
  const params = (0, _objectisomorphic.prune)({
276
288
  environment: flags.environment,
289
+ branch: flags.branch,
277
290
  annotate: flags.annotate,
278
291
  commit: flags.commit,
279
292
  commit_message: flags["commit-message"]
@@ -287,7 +300,8 @@ class ApiV1 {
287
300
  }
288
301
  async validatePartial({ flags }, partial) {
289
302
  const params = (0, _objectisomorphic.prune)({
290
- environment: flags.environment
303
+ environment: flags.environment,
304
+ branch: flags.branch
291
305
  });
292
306
  const data = {
293
307
  partial
@@ -300,6 +314,7 @@ class ApiV1 {
300
314
  async listMessageTypes({ flags }) {
301
315
  const params = (0, _objectisomorphic.prune)({
302
316
  environment: flags.environment,
317
+ branch: flags.branch,
303
318
  hide_uncommitted_changes: flags["hide-uncommitted-changes"],
304
319
  annotate: flags.annotate,
305
320
  ...(0, _page.toPageParams)(flags)
@@ -311,6 +326,7 @@ class ApiV1 {
311
326
  async getMessageType({ args, flags }) {
312
327
  const params = (0, _objectisomorphic.prune)({
313
328
  environment: flags.environment,
329
+ branch: flags.branch,
314
330
  annotate: flags.annotate,
315
331
  hide_uncommitted_changes: flags["hide-uncommitted-changes"]
316
332
  });
@@ -321,6 +337,7 @@ class ApiV1 {
321
337
  async upsertMessageType({ flags }, messageType) {
322
338
  const params = (0, _objectisomorphic.prune)({
323
339
  environment: flags.environment,
340
+ branch: flags.branch,
324
341
  annotate: flags.annotate,
325
342
  commit: flags.commit,
326
343
  commit_message: flags["commit-message"]
@@ -334,7 +351,8 @@ class ApiV1 {
334
351
  }
335
352
  async validateMessageType({ flags }, messageType) {
336
353
  const params = (0, _objectisomorphic.prune)({
337
- environment: flags.environment
354
+ environment: flags.environment,
355
+ branch: flags.branch
338
356
  });
339
357
  const data = {
340
358
  message_type: messageType
@@ -347,6 +365,7 @@ class ApiV1 {
347
365
  async listGuides({ flags }) {
348
366
  const params = (0, _objectisomorphic.prune)({
349
367
  environment: flags.environment,
368
+ branch: flags.branch,
350
369
  annotate: flags.annotate,
351
370
  hide_uncommitted_changes: flags["hide-uncommitted-changes"],
352
371
  include_json_schema: flags["include-json-schema"],
@@ -359,6 +378,7 @@ class ApiV1 {
359
378
  async getGuide({ args, flags }) {
360
379
  const params = (0, _objectisomorphic.prune)({
361
380
  environment: flags.environment,
381
+ branch: flags.branch,
362
382
  annotate: flags.annotate,
363
383
  hide_uncommitted_changes: flags["hide-uncommitted-changes"]
364
384
  });
@@ -368,7 +388,8 @@ class ApiV1 {
368
388
  }
369
389
  async validateGuide({ flags }, guide) {
370
390
  const params = (0, _objectisomorphic.prune)({
371
- environment: flags.environment
391
+ environment: flags.environment,
392
+ branch: flags.branch
372
393
  });
373
394
  const data = {
374
395
  guide
@@ -380,6 +401,7 @@ class ApiV1 {
380
401
  async upsertGuide({ flags }, guide) {
381
402
  const params = (0, _objectisomorphic.prune)({
382
403
  environment: flags.environment,
404
+ branch: flags.branch,
383
405
  annotate: flags.annotate,
384
406
  commit: flags.commit,
385
407
  commit_message: flags["commit-message"]
@@ -394,6 +416,7 @@ class ApiV1 {
394
416
  async activateGuide({ args, flags }) {
395
417
  const params = (0, _objectisomorphic.prune)({
396
418
  environment: flags.environment,
419
+ branch: flags.branch,
397
420
  status: flags.status,
398
421
  from: flags.from,
399
422
  until: flags.until
@@ -9,15 +9,16 @@ Object.defineProperty(exports, "CustomArgs", {
9
9
  }
10
10
  });
11
11
  const _core = require("@oclif/core");
12
- const slugArg = _core.Args.custom({
12
+ const _string = require("./string");
13
+ const slug = _core.Args.custom({
13
14
  parse: async (str)=>{
14
- const slug = str.toLowerCase().trim().replace(/\s+/g, "-");
15
- if (!slug) {
15
+ const slugifiedInput = (0, _string.slugify)(str);
16
+ if (!slugifiedInput) {
16
17
  throw new Error("Invalid slug provided");
17
18
  }
18
- return slug;
19
+ return slugifiedInput;
19
20
  }
20
21
  });
21
22
  const CustomArgs = {
22
- slugArg
23
+ slug
23
24
  };
@@ -0,0 +1,124 @@
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 BRANCH_FILE_NAME () {
13
+ return BRANCH_FILE_NAME;
14
+ },
15
+ get appendBranchFileToGitIgnore () {
16
+ return appendBranchFileToGitIgnore;
17
+ },
18
+ get clearBranchFile () {
19
+ return clearBranchFile;
20
+ },
21
+ get findProjectRoot () {
22
+ return findProjectRoot;
23
+ },
24
+ get parseSlugFromBranchFile () {
25
+ return parseSlugFromBranchFile;
26
+ },
27
+ get readSlugFromBranchFile () {
28
+ return readSlugFromBranchFile;
29
+ },
30
+ get writeSlugToBranchFile () {
31
+ return writeSlugToBranchFile;
32
+ }
33
+ });
34
+ const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
35
+ const _findup = /*#__PURE__*/ _interop_require_default(require("find-up"));
36
+ const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
37
+ function _interop_require_default(obj) {
38
+ return obj && obj.__esModule ? obj : {
39
+ default: obj
40
+ };
41
+ }
42
+ function _getRequireWildcardCache(nodeInterop) {
43
+ if (typeof WeakMap !== "function") return null;
44
+ var cacheBabelInterop = new WeakMap();
45
+ var cacheNodeInterop = new WeakMap();
46
+ return (_getRequireWildcardCache = function(nodeInterop) {
47
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
48
+ })(nodeInterop);
49
+ }
50
+ function _interop_require_wildcard(obj, nodeInterop) {
51
+ if (!nodeInterop && obj && obj.__esModule) {
52
+ return obj;
53
+ }
54
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
55
+ return {
56
+ default: obj
57
+ };
58
+ }
59
+ var cache = _getRequireWildcardCache(nodeInterop);
60
+ if (cache && cache.has(obj)) {
61
+ return cache.get(obj);
62
+ }
63
+ var newObj = {
64
+ __proto__: null
65
+ };
66
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
67
+ for(var key in obj){
68
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
69
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
70
+ if (desc && (desc.get || desc.set)) {
71
+ Object.defineProperty(newObj, key, desc);
72
+ } else {
73
+ newObj[key] = obj[key];
74
+ }
75
+ }
76
+ }
77
+ newObj.default = obj;
78
+ if (cache) {
79
+ cache.set(obj, newObj);
80
+ }
81
+ return newObj;
82
+ }
83
+ const BRANCH_FILE_NAME = ".knockbranch";
84
+ /**
85
+ * A comment written to the `.gitignore` file when it's updated.
86
+ */ const GITIGNORE_COMMENT = "# Knock CLI config files\n";
87
+ const readSlugFromBranchFile = async ()=>{
88
+ const branchFilePath = await (0, _findup.default)(BRANCH_FILE_NAME);
89
+ const slug = branchFilePath ? await parseSlugFromBranchFile(branchFilePath) : undefined;
90
+ return slug;
91
+ };
92
+ const parseSlugFromBranchFile = async (branchFilePath)=>{
93
+ const input = (await _fsextra.readFile(branchFilePath, "utf-8")).trim();
94
+ return /^[\w-]+$/.test(input) ? input : undefined;
95
+ };
96
+ const clearBranchFile = async (branchFilePath)=>{
97
+ // The empty string indicates that no branch is currently active
98
+ await _fsextra.writeFile(branchFilePath, "");
99
+ };
100
+ const writeSlugToBranchFile = async (branchFilePath, branchSlug)=>{
101
+ await _fsextra.writeFile(branchFilePath, `${branchSlug}\n`);
102
+ };
103
+ const findProjectRoot = async ()=>{
104
+ const currDir = process.cwd();
105
+ const gitIgnoreFilePath = await (0, _findup.default)(async (directory)=>{
106
+ const filePath = _nodepath.default.join(directory, ".gitignore");
107
+ const gitIgnoreFileExists = await _fsextra.exists(filePath);
108
+ if (gitIgnoreFileExists) {
109
+ return filePath;
110
+ }
111
+ // Stop search when we find a .git directory
112
+ const gitDirExists = await _fsextra.exists(_nodepath.default.join(directory, ".git"));
113
+ if (gitDirExists) {
114
+ return _findup.default.stop;
115
+ }
116
+ }, {
117
+ cwd: currDir
118
+ });
119
+ return gitIgnoreFilePath ? _nodepath.default.dirname(gitIgnoreFilePath) : currDir;
120
+ };
121
+ const appendBranchFileToGitIgnore = async (gitIgnoreFilePath, addLeadingNewline = true)=>{
122
+ const appendedContent = (addLeadingNewline ? "\n" : "") + GITIGNORE_COMMENT + BRANCH_FILE_NAME + "\n";
123
+ await _fsextra.appendFile(gitIgnoreFilePath, appendedContent);
124
+ };