@knocklabs/cli 0.1.18 → 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.
Files changed (34) hide show
  1. package/README.md +132 -24
  2. package/dist/commands/message-type/get.js +124 -0
  3. package/dist/commands/message-type/list.js +101 -0
  4. package/dist/commands/message-type/pull.js +218 -0
  5. package/dist/commands/message-type/push.js +171 -0
  6. package/dist/commands/message-type/validate.js +148 -0
  7. package/dist/commands/partial/get.js +124 -0
  8. package/dist/commands/partial/list.js +103 -0
  9. package/dist/commands/partial/pull.js +209 -0
  10. package/dist/commands/partial/push.js +169 -0
  11. package/dist/commands/partial/validate.js +146 -0
  12. package/dist/lib/api-v1.js +94 -0
  13. package/dist/lib/base-command.js +1 -4
  14. package/dist/lib/helpers/const.js +3 -3
  15. package/dist/lib/helpers/error.js +3 -6
  16. package/dist/lib/helpers/liquid.js +0 -2
  17. package/dist/lib/helpers/page.js +3 -3
  18. package/dist/lib/marshal/guide/index.js +19 -0
  19. package/dist/lib/marshal/guide/processor.isomorphic.js +85 -0
  20. package/dist/lib/marshal/guide/types.js +4 -0
  21. package/dist/lib/marshal/index.isomorphic.js +12 -8
  22. package/dist/lib/marshal/message-type/helpers.js +135 -0
  23. package/dist/lib/marshal/message-type/index.js +3 -0
  24. package/dist/lib/marshal/message-type/reader.js +198 -0
  25. package/dist/lib/marshal/message-type/writer.js +175 -0
  26. package/dist/lib/marshal/partial/helpers.js +134 -0
  27. package/dist/lib/marshal/partial/index.js +3 -0
  28. package/dist/lib/marshal/partial/reader.js +198 -0
  29. package/dist/lib/marshal/partial/types.js +3 -3
  30. package/dist/lib/marshal/partial/writer.js +175 -0
  31. package/dist/lib/marshal/workflow/types.js +3 -3
  32. package/dist/lib/run-context/loader.js +35 -31
  33. package/oclif.manifest.json +776 -1
  34. package/package.json +13 -13
@@ -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
+ });
@@ -0,0 +1,124 @@
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 PartialGet;
9
+ }
10
+ });
11
+ const _core = require("@oclif/core");
12
+ const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
13
+ const _date = require("../../lib/helpers/date");
14
+ const _error = require("../../lib/helpers/error");
15
+ const _request = require("../../lib/helpers/request");
16
+ const _ux = require("../../lib/helpers/ux");
17
+ function _define_property(obj, key, value) {
18
+ if (key in obj) {
19
+ Object.defineProperty(obj, key, {
20
+ value: value,
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true
24
+ });
25
+ } else {
26
+ obj[key] = value;
27
+ }
28
+ return obj;
29
+ }
30
+ function _interop_require_default(obj) {
31
+ return obj && obj.__esModule ? obj : {
32
+ default: obj
33
+ };
34
+ }
35
+ class PartialGet extends _basecommand.default {
36
+ async run() {
37
+ _ux.spinner.start("‣ Loading");
38
+ const { partial } = await this.loadPartial();
39
+ _ux.spinner.stop();
40
+ const { flags } = this.props;
41
+ if (flags.json) return partial;
42
+ this.render(partial);
43
+ }
44
+ async loadPartial() {
45
+ const partialResp = await this.apiV1.getPartial(this.props);
46
+ if (!(0, _request.isSuccessResp)(partialResp)) {
47
+ const message = (0, _request.formatErrorRespMessage)(partialResp);
48
+ _core.ux.error(new _error.ApiError(message));
49
+ }
50
+ return {
51
+ partial: partialResp.data
52
+ };
53
+ }
54
+ render(partial) {
55
+ const { partialKey } = this.props.args;
56
+ const { environment: env, "hide-uncommitted-changes": commitedOnly } = this.props.flags;
57
+ const qualifier = env === "development" && !commitedOnly ? "(including uncommitted)" : "";
58
+ this.log(`‣ Showing partial \`${partialKey}\` in \`${env}\` environment ${qualifier}\n`);
59
+ /*
60
+ * Partial table
61
+ */ const rows = [
62
+ {
63
+ key: "Name",
64
+ value: partial.name
65
+ },
66
+ {
67
+ key: "Key",
68
+ value: partial.key
69
+ },
70
+ {
71
+ key: "Type",
72
+ value: partial.type
73
+ },
74
+ {
75
+ key: "Visual block",
76
+ value: partial.visual_block_enabled ? "Enabled" : "Disabled"
77
+ },
78
+ {
79
+ key: "Description",
80
+ value: partial.description || "-"
81
+ },
82
+ {
83
+ key: "Created at",
84
+ value: (0, _date.formatDateTime)(partial.created_at)
85
+ },
86
+ {
87
+ key: "Updated at",
88
+ value: (0, _date.formatDateTime)(partial.updated_at)
89
+ },
90
+ {
91
+ key: "Content",
92
+ value: ""
93
+ }
94
+ ];
95
+ _core.ux.table(rows, {
96
+ key: {
97
+ header: "Partial",
98
+ minWidth: 24
99
+ },
100
+ value: {
101
+ header: "",
102
+ minWidth: 24
103
+ }
104
+ });
105
+ this.log("");
106
+ _core.ux.log(partial.content);
107
+ }
108
+ }
109
+ _define_property(PartialGet, "summary", "Display a single partial from an environment.");
110
+ _define_property(PartialGet, "flags", {
111
+ environment: _core.Flags.string({
112
+ default: "development",
113
+ summary: "The environment to use."
114
+ }),
115
+ "hide-uncommitted-changes": _core.Flags.boolean({
116
+ summary: "Hide any uncommitted changes."
117
+ })
118
+ });
119
+ _define_property(PartialGet, "args", {
120
+ partialKey: _core.Args.string({
121
+ required: true
122
+ })
123
+ });
124
+ _define_property(PartialGet, "enableJsonFlag", true);