@knocklabs/cli 0.1.19 → 0.1.20

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.
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return MessageTypePull;
9
+ }
10
+ });
11
+ const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require("node:path"));
12
+ const _core = require("@oclif/core");
13
+ const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
14
+ const _error = require("../../lib/helpers/error");
15
+ const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
16
+ const _objectisomorphic = require("../../lib/helpers/object.isomorphic");
17
+ const _page = require("../../lib/helpers/page");
18
+ const _request = require("../../lib/helpers/request");
19
+ const _ux = require("../../lib/helpers/ux");
20
+ const _messagetype = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/message-type"));
21
+ const _runcontext = require("../../lib/run-context");
22
+ function _define_property(obj, key, value) {
23
+ if (key in obj) {
24
+ Object.defineProperty(obj, key, {
25
+ value: value,
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true
29
+ });
30
+ } else {
31
+ obj[key] = value;
32
+ }
33
+ return obj;
34
+ }
35
+ function _interop_require_default(obj) {
36
+ return obj && obj.__esModule ? obj : {
37
+ default: obj
38
+ };
39
+ }
40
+ function _getRequireWildcardCache(nodeInterop) {
41
+ if (typeof WeakMap !== "function") return null;
42
+ var cacheBabelInterop = new WeakMap();
43
+ var cacheNodeInterop = new WeakMap();
44
+ return (_getRequireWildcardCache = function(nodeInterop) {
45
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
46
+ })(nodeInterop);
47
+ }
48
+ function _interop_require_wildcard(obj, nodeInterop) {
49
+ if (!nodeInterop && obj && obj.__esModule) {
50
+ return obj;
51
+ }
52
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
53
+ return {
54
+ default: obj
55
+ };
56
+ }
57
+ var cache = _getRequireWildcardCache(nodeInterop);
58
+ if (cache && cache.has(obj)) {
59
+ return cache.get(obj);
60
+ }
61
+ var newObj = {
62
+ __proto__: null
63
+ };
64
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
65
+ for(var key in obj){
66
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
67
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
68
+ if (desc && (desc.get || desc.set)) {
69
+ Object.defineProperty(newObj, key, desc);
70
+ } else {
71
+ newObj[key] = obj[key];
72
+ }
73
+ }
74
+ }
75
+ newObj.default = obj;
76
+ if (cache) {
77
+ cache.set(obj, newObj);
78
+ }
79
+ return newObj;
80
+ }
81
+ class MessageTypePull extends _basecommand.default {
82
+ async run() {
83
+ const { args, flags } = this.props;
84
+ if (flags.all && args.messageTypeKey) {
85
+ return this.error(`messageTypeKey arg \`${args.messageTypeKey}\` cannot also be provided when using --all`);
86
+ }
87
+ return flags.all ? this.pullAllMessageTypes() : this.pullOneMessageType();
88
+ }
89
+ /*
90
+ * Pull one message type
91
+ */ async pullOneMessageType() {
92
+ const { flags } = this.props;
93
+ // 1. Retrieve or build a new message type directory context.
94
+ const dirContext = await this.getMessageTypeDirContext();
95
+ if (dirContext.exists) {
96
+ this.log(`‣ Found \`${dirContext.key}\` at ${dirContext.abspath}`);
97
+ } else {
98
+ const prompt = `Create a new message type directory \`${dirContext.key}\` at ${dirContext.abspath}?`;
99
+ const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
100
+ if (!input) return;
101
+ }
102
+ // 2. Fetch the message type with annotations.
103
+ const resp = await (0, _request.withSpinner)(()=>{
104
+ const props = (0, _objectisomorphic.merge)(this.props, {
105
+ args: {
106
+ messageTypeKey: dirContext.key
107
+ },
108
+ flags: {
109
+ annotate: true
110
+ }
111
+ });
112
+ return this.apiV1.getMessageType(props);
113
+ });
114
+ await _messagetype.writeMessageTypeDirFromData(dirContext, resp.data);
115
+ const action = dirContext.exists ? "updated" : "created";
116
+ this.log(`‣ Successfully ${action} \`${dirContext.key}\` at ${dirContext.abspath}`);
117
+ }
118
+ async getMessageTypeDirContext() {
119
+ const { messageTypeKey } = this.props.args;
120
+ const { resourceDir, cwd: runCwd } = this.runContext;
121
+ // Inside an existing resource dir, use it if valid for the target message
122
+ // type.
123
+ if (resourceDir) {
124
+ const target = {
125
+ commandId: _basecommand.default.id,
126
+ type: "message_type",
127
+ key: messageTypeKey
128
+ };
129
+ return (0, _runcontext.ensureResourceDirForTarget)(resourceDir, target);
130
+ }
131
+ // Not inside any existing message type directory, which means either create
132
+ // a new message type directory in the cwd, or update it if there is one
133
+ // already.
134
+ if (messageTypeKey) {
135
+ const dirPath = _nodepath.resolve(runCwd, messageTypeKey);
136
+ const exists = await _messagetype.isMessageTypeDir(dirPath);
137
+ return {
138
+ type: "message_type",
139
+ key: messageTypeKey,
140
+ abspath: dirPath,
141
+ exists
142
+ };
143
+ }
144
+ // Not in any message type directory, nor a message type key arg was given
145
+ // so error.
146
+ return this.error("Missing 1 required arg:\nmessageTypeKey");
147
+ }
148
+ /*
149
+ * Pull all message types
150
+ */ async pullAllMessageTypes() {
151
+ const { flags } = this.props;
152
+ const defaultToCwd = {
153
+ abspath: this.runContext.cwd,
154
+ exists: true
155
+ };
156
+ const targetDirCtx = flags["message-types-dir"] || defaultToCwd;
157
+ const prompt = targetDirCtx.exists ? `Pull latest message types into ${targetDirCtx.abspath}?\n This will overwrite the contents of this directory.` : `Create a new message types directory at ${targetDirCtx.abspath}?`;
158
+ const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
159
+ if (!input) return;
160
+ _ux.spinner.start(`‣ Loading`);
161
+ const messageTypes = await this.listAllMessageTypes();
162
+ await _messagetype.writeMessageTypesIndexDir(targetDirCtx, messageTypes);
163
+ _ux.spinner.stop();
164
+ const action = targetDirCtx.exists ? "updated" : "created";
165
+ this.log(`‣ Successfully ${action} the message types directory at ${targetDirCtx.abspath}`);
166
+ }
167
+ async listAllMessageTypes(pageParams = {}, messageTypesFetchedSoFar = []) {
168
+ const props = (0, _objectisomorphic.merge)(this.props, {
169
+ flags: {
170
+ ...pageParams,
171
+ annotate: true,
172
+ limit: _page.MAX_PAGINATION_LIMIT
173
+ }
174
+ });
175
+ const resp = await this.apiV1.listMessageTypes(props);
176
+ if (!(0, _request.isSuccessResp)(resp)) {
177
+ const message = (0, _request.formatErrorRespMessage)(resp);
178
+ this.error(new _error.ApiError(message));
179
+ }
180
+ const { entries, page_info: pageInfo } = resp.data;
181
+ const messageTypes = [
182
+ ...messageTypesFetchedSoFar,
183
+ ...entries
184
+ ];
185
+ return pageInfo.after ? this.listAllMessageTypes({
186
+ after: pageInfo.after
187
+ }, messageTypes) : messageTypes;
188
+ }
189
+ }
190
+ // Hide until guides are released in GA.
191
+ _define_property(MessageTypePull, "hidden", true);
192
+ _define_property(MessageTypePull, "summary", "Pull one or more in-app message types from an environment into a local file system.");
193
+ _define_property(MessageTypePull, "flags", {
194
+ environment: _core.Flags.string({
195
+ default: "development",
196
+ summary: "The environment to use."
197
+ }),
198
+ all: _core.Flags.boolean({
199
+ summary: "Whether to pull all in-app message types from the specified environment."
200
+ }),
201
+ "message-types-dir": _flag.dirPath({
202
+ summary: "The target directory path to pull all in-app message types into.",
203
+ dependsOn: [
204
+ "all"
205
+ ]
206
+ }),
207
+ "hide-uncommitted-changes": _core.Flags.boolean({
208
+ summary: "Hide any uncommitted changes."
209
+ }),
210
+ force: _core.Flags.boolean({
211
+ summary: "Remove the confirmation prompt."
212
+ })
213
+ });
214
+ _define_property(MessageTypePull, "args", {
215
+ messageTypeKey: _core.Args.string({
216
+ required: false
217
+ })
218
+ });
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return MessageTypePush;
9
+ }
10
+ });
11
+ const _core = require("@oclif/core");
12
+ const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
13
+ const _const = require("../../lib/helpers/const");
14
+ const _error = require("../../lib/helpers/error");
15
+ const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
16
+ const _objectisomorphic = require("../../lib/helpers/object.isomorphic");
17
+ const _request = require("../../lib/helpers/request");
18
+ const _string = require("../../lib/helpers/string");
19
+ const _ux = require("../../lib/helpers/ux");
20
+ const _messagetype = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/message-type"));
21
+ const _validate = /*#__PURE__*/ _interop_require_default(require("./validate"));
22
+ function _define_property(obj, key, value) {
23
+ if (key in obj) {
24
+ Object.defineProperty(obj, key, {
25
+ value: value,
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true
29
+ });
30
+ } else {
31
+ obj[key] = value;
32
+ }
33
+ return obj;
34
+ }
35
+ function _interop_require_default(obj) {
36
+ return obj && obj.__esModule ? obj : {
37
+ default: obj
38
+ };
39
+ }
40
+ function _getRequireWildcardCache(nodeInterop) {
41
+ if (typeof WeakMap !== "function") return null;
42
+ var cacheBabelInterop = new WeakMap();
43
+ var cacheNodeInterop = new WeakMap();
44
+ return (_getRequireWildcardCache = function(nodeInterop) {
45
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
46
+ })(nodeInterop);
47
+ }
48
+ function _interop_require_wildcard(obj, nodeInterop) {
49
+ if (!nodeInterop && obj && obj.__esModule) {
50
+ return obj;
51
+ }
52
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
53
+ return {
54
+ default: obj
55
+ };
56
+ }
57
+ var cache = _getRequireWildcardCache(nodeInterop);
58
+ if (cache && cache.has(obj)) {
59
+ return cache.get(obj);
60
+ }
61
+ var newObj = {
62
+ __proto__: null
63
+ };
64
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
65
+ for(var key in obj){
66
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
67
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
68
+ if (desc && (desc.get || desc.set)) {
69
+ Object.defineProperty(newObj, key, desc);
70
+ } else {
71
+ newObj[key] = obj[key];
72
+ }
73
+ }
74
+ }
75
+ newObj.default = obj;
76
+ if (cache) {
77
+ cache.set(obj, newObj);
78
+ }
79
+ return newObj;
80
+ }
81
+ class MessageTypePush extends _basecommand.default {
82
+ async run() {
83
+ const { flags } = this.props;
84
+ // 1. First read all message type directories found for the given command.
85
+ const target = await _messagetype.ensureValidCommandTarget(this.props, this.runContext);
86
+ const [messageTypes, readErrors] = await _messagetype.readAllForCommandTarget(target, {
87
+ withExtractedFiles: true
88
+ });
89
+ if (readErrors.length > 0) {
90
+ this.error((0, _error.formatErrors)(readErrors, {
91
+ prependBy: "\n\n"
92
+ }));
93
+ }
94
+ if (messageTypes.length === 0) {
95
+ this.error(`No message type directories found in ${target.context.abspath}`);
96
+ }
97
+ // 2. Then validate them all ahead of pushing them.
98
+ _ux.spinner.start(`‣ Validating`);
99
+ const apiErrors = await _validate.default.validateAll(this.apiV1, this.props, messageTypes);
100
+ if (apiErrors.length > 0) {
101
+ this.error((0, _error.formatErrors)(apiErrors, {
102
+ prependBy: "\n\n"
103
+ }));
104
+ }
105
+ _ux.spinner.stop();
106
+ // 3. Finally push up each message type, abort on the first error.
107
+ _ux.spinner.start(`‣ Pushing`);
108
+ for (const messageType of messageTypes){
109
+ const props = (0, _objectisomorphic.merge)(this.props, {
110
+ flags: {
111
+ annotate: true
112
+ }
113
+ });
114
+ // eslint-disable-next-line no-await-in-loop
115
+ const resp = await this.apiV1.upsertMessageType(props, {
116
+ ...messageType.content,
117
+ key: messageType.key
118
+ });
119
+ if ((0, _request.isSuccessResp)(resp)) {
120
+ // Update the message type directory with the successfully pushed message
121
+ // type payload from the server.
122
+ // eslint-disable-next-line no-await-in-loop
123
+ await _messagetype.writeMessageTypeDirFromData(messageType, resp.data.message_type);
124
+ continue;
125
+ }
126
+ const error = new _error.SourceError((0, _request.formatErrorRespMessage)(resp), _messagetype.messageTypeJsonPath(messageType), "ApiError");
127
+ this.error((0, _error.formatError)(error));
128
+ }
129
+ _ux.spinner.stop();
130
+ // 4. Display a success message.
131
+ const messageTypeKeys = messageTypes.map((w)=>w.key);
132
+ const actioned = flags.commit ? "pushed and committed" : "pushed";
133
+ this.log(`‣ Successfully ${actioned} ${messageTypes.length} message type(s):\n` + (0, _string.indentString)(messageTypeKeys.join("\n"), 4));
134
+ }
135
+ }
136
+ // Hide until guides are released in GA.
137
+ _define_property(MessageTypePush, "hidden", true);
138
+ _define_property(MessageTypePush, "summary", "Push one or more message types from a local file system to Knock.");
139
+ _define_property(MessageTypePush, "flags", {
140
+ environment: _core.Flags.string({
141
+ summary: "Pushing a message type is only allowed in the development environment",
142
+ default: _const.KnockEnv.Development,
143
+ options: [
144
+ _const.KnockEnv.Development
145
+ ]
146
+ }),
147
+ all: _core.Flags.boolean({
148
+ summary: "Whether to push all message types from the target directory."
149
+ }),
150
+ "message-types-dir": _flag.dirPath({
151
+ summary: "The target directory path to find all message types to push.",
152
+ dependsOn: [
153
+ "all"
154
+ ]
155
+ }),
156
+ commit: _core.Flags.boolean({
157
+ summary: "Push and commit the message type(s) at the same time"
158
+ }),
159
+ "commit-message": _core.Flags.string({
160
+ summary: "Use the given value as the commit message",
161
+ char: "m",
162
+ dependsOn: [
163
+ "commit"
164
+ ]
165
+ })
166
+ });
167
+ _define_property(MessageTypePush, "args", {
168
+ messageTypeKey: _core.Args.string({
169
+ required: false
170
+ })
171
+ });
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return MessageTypeValidate;
9
+ }
10
+ });
11
+ const _core = require("@oclif/core");
12
+ const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
13
+ const _const = require("../../lib/helpers/const");
14
+ const _error = require("../../lib/helpers/error");
15
+ const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
16
+ const _request = require("../../lib/helpers/request");
17
+ const _string = require("../../lib/helpers/string");
18
+ const _ux = require("../../lib/helpers/ux");
19
+ const _messagetype = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/message-type"));
20
+ function _define_property(obj, key, value) {
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
30
+ }
31
+ return obj;
32
+ }
33
+ function _interop_require_default(obj) {
34
+ return obj && obj.__esModule ? obj : {
35
+ default: obj
36
+ };
37
+ }
38
+ function _getRequireWildcardCache(nodeInterop) {
39
+ if (typeof WeakMap !== "function") return null;
40
+ var cacheBabelInterop = new WeakMap();
41
+ var cacheNodeInterop = new WeakMap();
42
+ return (_getRequireWildcardCache = function(nodeInterop) {
43
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
44
+ })(nodeInterop);
45
+ }
46
+ function _interop_require_wildcard(obj, nodeInterop) {
47
+ if (!nodeInterop && obj && obj.__esModule) {
48
+ return obj;
49
+ }
50
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
51
+ return {
52
+ default: obj
53
+ };
54
+ }
55
+ var cache = _getRequireWildcardCache(nodeInterop);
56
+ if (cache && cache.has(obj)) {
57
+ return cache.get(obj);
58
+ }
59
+ var newObj = {
60
+ __proto__: null
61
+ };
62
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
63
+ for(var key in obj){
64
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
65
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
66
+ if (desc && (desc.get || desc.set)) {
67
+ Object.defineProperty(newObj, key, desc);
68
+ } else {
69
+ newObj[key] = obj[key];
70
+ }
71
+ }
72
+ }
73
+ newObj.default = obj;
74
+ if (cache) {
75
+ cache.set(obj, newObj);
76
+ }
77
+ return newObj;
78
+ }
79
+ class MessageTypeValidate extends _basecommand.default {
80
+ async run() {
81
+ // 1. Read all message type directories found for the given command.
82
+ const target = await _messagetype.ensureValidCommandTarget(this.props, this.runContext);
83
+ const [messageTypes, readErrors] = await _messagetype.readAllForCommandTarget(target, {
84
+ withExtractedFiles: true
85
+ });
86
+ if (readErrors.length > 0) {
87
+ this.error((0, _error.formatErrors)(readErrors, {
88
+ prependBy: "\n\n"
89
+ }));
90
+ }
91
+ if (messageTypes.length === 0) {
92
+ this.error(`No message type directories found in ${target.context.abspath}`);
93
+ }
94
+ // 2. Validate each message type data.
95
+ _ux.spinner.start(`‣ Validating`);
96
+ const apiErrors = await MessageTypeValidate.validateAll(this.apiV1, this.props, messageTypes);
97
+ if (apiErrors.length > 0) {
98
+ this.error((0, _error.formatErrors)(apiErrors, {
99
+ prependBy: "\n\n"
100
+ }));
101
+ }
102
+ _ux.spinner.stop();
103
+ // 3. Display a success message.
104
+ const messageTypeKeys = messageTypes.map((w)=>w.key);
105
+ this.log(`‣ Successfully validated ${messageTypes.length} message type(s):\n` + (0, _string.indentString)(messageTypeKeys.join("\n"), 4));
106
+ }
107
+ static async validateAll(api, props, messageTypes) {
108
+ // TODO: Throw an error if a non validation error (e.g. authentication error)
109
+ // instead of printing out same error messages repeatedly.
110
+ const errorPromises = messageTypes.map(async (messageType)=>{
111
+ const resp = await api.validateMessageType(props, {
112
+ ...messageType.content,
113
+ key: messageType.key
114
+ });
115
+ if ((0, _request.isSuccessResp)(resp)) return;
116
+ const error = new _error.SourceError((0, _request.formatErrorRespMessage)(resp), _messagetype.messageTypeJsonPath(messageType), "ApiError");
117
+ return error;
118
+ });
119
+ const errors = (await Promise.all(errorPromises)).filter((e)=>Boolean(e));
120
+ return errors;
121
+ }
122
+ }
123
+ // Hide until guides are released in GA.
124
+ _define_property(MessageTypeValidate, "hidden", true);
125
+ _define_property(MessageTypeValidate, "summary", "Validate one or more message types from a local file system.");
126
+ _define_property(MessageTypeValidate, "flags", {
127
+ environment: _core.Flags.string({
128
+ summary: "Validating a message type is only done in the development environment",
129
+ default: _const.KnockEnv.Development,
130
+ options: [
131
+ _const.KnockEnv.Development
132
+ ]
133
+ }),
134
+ all: _core.Flags.boolean({
135
+ summary: "Whether to validate all message types from the target directory."
136
+ }),
137
+ "message-types-dir": _flag.dirPath({
138
+ summary: "The target directory path to find all message types to validate.",
139
+ dependsOn: [
140
+ "all"
141
+ ]
142
+ })
143
+ });
144
+ _define_property(MessageTypeValidate, "args", {
145
+ messageTypeKey: _core.Args.string({
146
+ required: false
147
+ })
148
+ });
@@ -89,7 +89,7 @@ class PartialPull extends _basecommand.default {
89
89
  // Pull one partial
90
90
  async pullOnePartial() {
91
91
  const { flags } = this.props;
92
- const dirContext = await this.getPartialsDirContext();
92
+ const dirContext = await this.getPartialDirContext();
93
93
  if (dirContext.exists) {
94
94
  this.log(`‣ Found \`${dirContext.key}\` at ${dirContext.abspath}`);
95
95
  } else {
@@ -152,7 +152,7 @@ class PartialPull extends _basecommand.default {
152
152
  after: pageInfo.after
153
153
  }, partials) : partials;
154
154
  }
155
- async getPartialsDirContext() {
155
+ async getPartialDirContext() {
156
156
  const { partialKey } = this.props.args;
157
157
  const { resourceDir, cwd: runCwd } = this.runContext;
158
158
  // Inside an existing resource dir, use it if valid for the target partial.
@@ -286,6 +286,53 @@ class ApiV1 {
286
286
  params
287
287
  });
288
288
  }
289
+ // By resources: Message types
290
+ async listMessageTypes({ flags }) {
291
+ const params = (0, _objectisomorphic.prune)({
292
+ environment: flags.environment,
293
+ hide_uncommitted_changes: flags["hide-uncommitted-changes"],
294
+ annotate: flags.annotate,
295
+ ...(0, _page.toPageParams)(flags)
296
+ });
297
+ return this.get("/message_types", {
298
+ params
299
+ });
300
+ }
301
+ async getMessageType({ args, flags }) {
302
+ const params = (0, _objectisomorphic.prune)({
303
+ environment: flags.environment,
304
+ annotate: flags.annotate,
305
+ hide_uncommitted_changes: flags["hide-uncommitted-changes"]
306
+ });
307
+ return this.get(`/message_types/${args.messageTypeKey}`, {
308
+ params
309
+ });
310
+ }
311
+ async upsertMessageType({ flags }, messageType) {
312
+ const params = (0, _objectisomorphic.prune)({
313
+ environment: flags.environment,
314
+ annotate: flags.annotate,
315
+ commit: flags.commit,
316
+ commit_message: flags["commit-message"]
317
+ });
318
+ const data = {
319
+ message_type: messageType
320
+ };
321
+ return this.put(`/message_types/${messageType.key}`, data, {
322
+ params
323
+ });
324
+ }
325
+ async validateMessageType({ flags }, messageType) {
326
+ const params = (0, _objectisomorphic.prune)({
327
+ environment: flags.environment
328
+ });
329
+ const data = {
330
+ message_type: messageType
331
+ };
332
+ return this.put(`/message_types/${messageType.key}/validate`, data, {
333
+ params
334
+ });
335
+ }
289
336
  // By methods:
290
337
  async get(subpath, config) {
291
338
  return this.client.get(`/${API_VERSION}` + subpath, config);
@@ -88,10 +88,7 @@ class BaseCommand extends _core.Command {
88
88
  this.runContext = await _runcontext.load(this.id);
89
89
  }
90
90
  constructor(...args){
91
- super(...args);
92
- _define_property(this, "props", void 0);
93
- _define_property(this, "apiV1", void 0);
94
- _define_property(this, "runContext", void 0);
91
+ super(...args), _define_property(this, "props", void 0), _define_property(this, "apiV1", void 0), _define_property(this, "runContext", void 0);
95
92
  }
96
93
  }
97
94
  // Base flags are inherited by any command that extends BaseCommand.
@@ -68,10 +68,10 @@ function _interop_require_wildcard(obj, nodeInterop) {
68
68
  }
69
69
  return newObj;
70
70
  }
71
- var KnockEnv;
72
- (function(KnockEnv) {
71
+ var KnockEnv = /*#__PURE__*/ function(KnockEnv) {
73
72
  KnockEnv["Development"] = "development";
74
73
  KnockEnv["Production"] = "production";
75
- })(KnockEnv || (KnockEnv = {}));
74
+ return KnockEnv;
75
+ }({});
76
76
  const isTestEnv = process.env.NODE_ENV === "test";
77
77
  const sandboxDir = _nodepath.resolve(_fsextra.realpathSync(_nodeos.default.tmpdir()), ".knock");
@@ -63,16 +63,14 @@ class JsonSyntaxError extends CustomError {
63
63
  }
64
64
  class JsonDataError extends CustomError {
65
65
  constructor(message, objPath){
66
- super(message);
67
- // For example: `foo.bar[2].baz`
66
+ super(message), // For example: `foo.bar[2].baz`
68
67
  _define_property(this, "objPath", void 0);
69
68
  this.objPath = objPath;
70
69
  }
71
70
  }
72
71
  class LiquidParseError extends CustomError {
73
72
  constructor(message, context){
74
- super(message);
75
- // Shows the erroneous liquid content with line numbers, should be taken
73
+ super(message), // Shows the erroneous liquid content with line numbers, should be taken
76
74
  // directly from a LiquidError.
77
75
  _define_property(this, "context", void 0);
78
76
  this.context = context;
@@ -80,8 +78,7 @@ class LiquidParseError extends CustomError {
80
78
  }
81
79
  class SourceError extends CustomError {
82
80
  constructor(message, source, tag){
83
- super(tag ? `${tag}: ${message}` : message);
84
- // Arbitrary string to describe the identifying source of the error message.
81
+ super(tag ? `${tag}: ${message}` : message), // Arbitrary string to describe the identifying source of the error message.
85
82
  _define_property(this, "source", void 0);
86
83
  this.source = source;
87
84
  }
@@ -58,11 +58,11 @@ const pageFlags = {
58
58
  const toPageParams = (flags)=>{
59
59
  return (0, _lodash.pick)(flags, Object.keys(pageFlags));
60
60
  };
61
- var PageAction;
62
- (function(PageAction) {
61
+ var PageAction = /*#__PURE__*/ function(PageAction) {
63
62
  PageAction["Previous"] = "p";
64
63
  PageAction["Next"] = "n";
65
- })(PageAction || (PageAction = {}));
64
+ return PageAction;
65
+ }({});
66
66
  /*
67
67
  * Format a prompt text to show available page actions.
68
68
  * e.g. [p: preview, n: next]