@knocklabs/cli 0.1.22 → 0.2.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.
- package/README.md +191 -106
- package/bin/dev.js +4 -4
- package/dist/commands/commit/list.js +21 -1
- package/dist/commands/guide/activate.js +121 -0
- package/dist/commands/guide/generate-types.js +148 -0
- package/dist/commands/guide/get.js +139 -0
- package/dist/commands/guide/list.js +112 -0
- package/dist/commands/guide/pull.js +209 -0
- package/dist/commands/guide/push.js +171 -0
- package/dist/commands/guide/validate.js +148 -0
- package/dist/commands/knock.js +3 -0
- package/dist/commands/login.js +50 -0
- package/dist/commands/logout.js +48 -0
- package/dist/commands/whoami.js +6 -2
- package/dist/commands/workflow/generate-types.js +6 -5
- package/dist/lib/api-v1.js +74 -4
- package/dist/lib/auth.js +256 -0
- package/dist/lib/base-command.js +85 -12
- package/dist/lib/helpers/browser.js +25 -0
- package/dist/lib/helpers/const.js +4 -4
- package/dist/lib/helpers/date.js +3 -3
- package/dist/lib/helpers/error.js +8 -8
- package/dist/lib/helpers/flag.js +7 -7
- package/dist/lib/helpers/json.js +5 -5
- package/dist/lib/helpers/object.isomorphic.js +8 -8
- package/dist/lib/helpers/page.js +9 -9
- package/dist/lib/helpers/request.js +4 -4
- package/dist/lib/helpers/string.js +3 -3
- package/dist/lib/helpers/typegen.js +59 -0
- package/dist/lib/helpers/ux.js +3 -3
- package/dist/lib/marshal/email-layout/helpers.js +5 -5
- package/dist/lib/marshal/email-layout/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/email-layout/reader.js +5 -5
- package/dist/lib/marshal/email-layout/writer.js +4 -4
- package/dist/lib/marshal/guide/helpers.js +283 -0
- package/dist/lib/marshal/guide/index.js +3 -0
- package/dist/lib/marshal/guide/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/guide/reader.js +193 -0
- package/dist/lib/marshal/guide/writer.js +175 -0
- package/dist/lib/marshal/index.isomorphic.js +7 -7
- package/dist/lib/marshal/message-type/helpers.js +5 -5
- package/dist/lib/marshal/message-type/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/message-type/reader.js +5 -5
- package/dist/lib/marshal/message-type/writer.js +4 -4
- package/dist/lib/marshal/partial/helpers.js +5 -5
- package/dist/lib/marshal/partial/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/partial/reader.js +5 -5
- package/dist/lib/marshal/partial/writer.js +4 -4
- package/dist/lib/marshal/shared/const.isomorphic.js +3 -3
- package/dist/lib/marshal/shared/helpers.isomorphic.js +9 -2
- package/dist/lib/marshal/shared/helpers.js +4 -4
- package/dist/lib/marshal/translation/helpers.js +10 -10
- package/dist/lib/marshal/translation/processor.isomorphic.js +6 -6
- package/dist/lib/marshal/translation/writer.js +3 -3
- package/dist/lib/marshal/workflow/generator.js +4 -4
- package/dist/lib/marshal/workflow/helpers.js +53 -10
- package/dist/lib/marshal/workflow/processor.isomorphic.js +5 -5
- package/dist/lib/marshal/workflow/reader.js +5 -5
- package/dist/lib/marshal/workflow/writer.js +5 -5
- package/dist/lib/resources.js +3 -3
- package/dist/lib/types.js +4 -0
- package/dist/lib/urls.js +32 -0
- package/dist/lib/user-config.js +69 -31
- package/oclif.manifest.json +749 -114
- package/package.json +12 -11
- package/dist/lib/type-generator.js +0 -100
package/bin/dev.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node_modules/.bin/ts-node
|
|
2
2
|
// eslint-disable-next-line node/shebang, unicorn/prefer-top-level-await
|
|
3
|
-
|
|
4
|
-
const oclif = await import(
|
|
5
|
-
await oclif.execute({development: true, dir: __dirname})
|
|
6
|
-
})()
|
|
3
|
+
(async () => {
|
|
4
|
+
const oclif = await import("@oclif/core");
|
|
5
|
+
await oclif.execute({ development: true, dir: __dirname });
|
|
6
|
+
})();
|
|
@@ -35,8 +35,14 @@ function _interop_require_default(obj) {
|
|
|
35
35
|
}
|
|
36
36
|
class CommitList extends _basecommand.default {
|
|
37
37
|
async run() {
|
|
38
|
-
|
|
38
|
+
// Validate that resource-type and resource-id are used together
|
|
39
39
|
const { flags } = this.props;
|
|
40
|
+
const hasResourceType = Boolean(flags["resource-type"]);
|
|
41
|
+
const hasResourceId = Boolean(flags["resource-id"]);
|
|
42
|
+
if (hasResourceType !== hasResourceId) {
|
|
43
|
+
this.error("The --resource-type and --resource-id flags must be used together. " + "You cannot use one without the other.");
|
|
44
|
+
}
|
|
45
|
+
const resp = await this.request();
|
|
40
46
|
if (flags.json) return resp.data;
|
|
41
47
|
this.render(resp.data);
|
|
42
48
|
}
|
|
@@ -109,6 +115,20 @@ _define_property(CommitList, "flags", {
|
|
|
109
115
|
summary: "Show only promoted or unpromoted changes between the given environment and the subsequent environment.",
|
|
110
116
|
allowNo: true
|
|
111
117
|
}),
|
|
118
|
+
"resource-type": _core.Flags.string({
|
|
119
|
+
summary: "Filter commits by resource type. Must be used together with resource-id.",
|
|
120
|
+
options: [
|
|
121
|
+
"email_layout",
|
|
122
|
+
"guide",
|
|
123
|
+
"message_type",
|
|
124
|
+
"partial",
|
|
125
|
+
"translation",
|
|
126
|
+
"workflow"
|
|
127
|
+
]
|
|
128
|
+
}),
|
|
129
|
+
"resource-id": _core.Flags.string({
|
|
130
|
+
summary: "Filter commits by resource identifier. Must be used together with resource-type. For most resources, this will be the resource key. In the case of translations, this will be the locale code and namespace, separated by a /. For example, en/courses or en."
|
|
131
|
+
}),
|
|
112
132
|
..._page.pageFlags
|
|
113
133
|
});
|
|
114
134
|
_define_property(CommitList, "enableJsonFlag", true);
|
|
@@ -0,0 +1,121 @@
|
|
|
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 GuideActivate;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@oclif/core");
|
|
12
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
13
|
+
const _flag = require("../../lib/helpers/flag");
|
|
14
|
+
const _request = require("../../lib/helpers/request");
|
|
15
|
+
const _ux = require("../../lib/helpers/ux");
|
|
16
|
+
function _define_property(obj, key, value) {
|
|
17
|
+
if (key in obj) {
|
|
18
|
+
Object.defineProperty(obj, key, {
|
|
19
|
+
value: value,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
obj[key] = value;
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
function _interop_require_default(obj) {
|
|
30
|
+
return obj && obj.__esModule ? obj : {
|
|
31
|
+
default: obj
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
class GuideActivate extends _basecommand.default {
|
|
35
|
+
async run() {
|
|
36
|
+
const { args, flags } = this.props;
|
|
37
|
+
// Validate that either status OR from/until is provided
|
|
38
|
+
const hasStatus = flags.status !== undefined;
|
|
39
|
+
const hasFrom = Boolean(flags.from);
|
|
40
|
+
const hasUntil = Boolean(flags.until);
|
|
41
|
+
if (!hasStatus && !hasFrom && !hasUntil) {
|
|
42
|
+
this.error("Either --status or --from/--until must be provided");
|
|
43
|
+
}
|
|
44
|
+
let action;
|
|
45
|
+
if (hasStatus) {
|
|
46
|
+
action = flags.status ? "Activate" : "Deactivate";
|
|
47
|
+
} else if (hasFrom && hasUntil) {
|
|
48
|
+
action = `Schedule activation from ${flags.from} until ${flags.until}`;
|
|
49
|
+
} else if (hasFrom) {
|
|
50
|
+
action = `Activate from ${flags.from}`;
|
|
51
|
+
} else {
|
|
52
|
+
action = `Deactivate at ${flags.until}`;
|
|
53
|
+
}
|
|
54
|
+
// 1. Confirm before activating or deactivating the guide, unless forced.
|
|
55
|
+
const prompt = `${action} \`${args.guideKey}\` guide in \`${flags.environment}\` environment?`;
|
|
56
|
+
const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
|
|
57
|
+
if (!input) return;
|
|
58
|
+
// 2. Proceed to make a request to set the guide status.
|
|
59
|
+
let actioning;
|
|
60
|
+
if (hasStatus) {
|
|
61
|
+
actioning = flags.status ? "Activating" : "Deactivating";
|
|
62
|
+
} else {
|
|
63
|
+
actioning = "Scheduling activation";
|
|
64
|
+
}
|
|
65
|
+
await (0, _request.withSpinner)(()=>{
|
|
66
|
+
return this.apiV1.activateGuide(this.props);
|
|
67
|
+
}, {
|
|
68
|
+
action: `‣ ${actioning}`
|
|
69
|
+
});
|
|
70
|
+
let actioned;
|
|
71
|
+
if (hasStatus) {
|
|
72
|
+
actioned = flags.status ? "activated" : "deactivated";
|
|
73
|
+
} else {
|
|
74
|
+
actioned = "scheduled";
|
|
75
|
+
}
|
|
76
|
+
this.log(`‣ Successfully ${actioned} \`${args.guideKey}\` guide in \`${flags.environment}\` environment`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
_define_property(GuideActivate, "summary", "Activate or deactivate a guide in a given environment.");
|
|
80
|
+
_define_property(GuideActivate, "description", `
|
|
81
|
+
This enables or disables a guide in a given environment without
|
|
82
|
+
needing to go through environment promotion.
|
|
83
|
+
|
|
84
|
+
You can activate or deactivate a guide immediately or schedule it to be activated
|
|
85
|
+
or deactivated at a later time using the --from and --until flags.
|
|
86
|
+
`.trim());
|
|
87
|
+
_define_property(GuideActivate, "flags", {
|
|
88
|
+
// Do not default to any env for this command, since this action runs
|
|
89
|
+
// directly in each environment outside the commit and promote flow.
|
|
90
|
+
environment: _core.Flags.string({
|
|
91
|
+
required: true,
|
|
92
|
+
summary: "The environment to use."
|
|
93
|
+
}),
|
|
94
|
+
status: (0, _flag.booleanStr)({
|
|
95
|
+
summary: "The guide active status to set. Cannot be used with --from/--until.",
|
|
96
|
+
exclusive: [
|
|
97
|
+
"from",
|
|
98
|
+
"until"
|
|
99
|
+
]
|
|
100
|
+
}),
|
|
101
|
+
from: _core.Flags.string({
|
|
102
|
+
summary: "Activate the guide from this ISO8601 UTC datetime (e.g., '2024-01-15T10:30:00Z').",
|
|
103
|
+
exclusive: [
|
|
104
|
+
"status"
|
|
105
|
+
]
|
|
106
|
+
}),
|
|
107
|
+
until: _core.Flags.string({
|
|
108
|
+
summary: "Deactivate the guide at this ISO8601 UTC datetime (e.g., '2024-01-15T18:30:00Z').",
|
|
109
|
+
exclusive: [
|
|
110
|
+
"status"
|
|
111
|
+
]
|
|
112
|
+
}),
|
|
113
|
+
force: _core.Flags.boolean({
|
|
114
|
+
summary: "Remove the confirmation prompt."
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
_define_property(GuideActivate, "args", {
|
|
118
|
+
guideKey: _core.Args.string({
|
|
119
|
+
required: true
|
|
120
|
+
})
|
|
121
|
+
});
|
|
@@ -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 GuideGenerateTypes;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
12
|
+
const _core = require("@oclif/core");
|
|
13
|
+
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
14
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
15
|
+
const _const = require("../../lib/helpers/const");
|
|
16
|
+
const _error = require("../../lib/helpers/error");
|
|
17
|
+
const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
|
|
18
|
+
const _objectisomorphic = require("../../lib/helpers/object.isomorphic");
|
|
19
|
+
const _page = require("../../lib/helpers/page");
|
|
20
|
+
const _request = require("../../lib/helpers/request");
|
|
21
|
+
const _typegen = require("../../lib/helpers/typegen");
|
|
22
|
+
const _ux = require("../../lib/helpers/ux");
|
|
23
|
+
const _guide = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/guide"));
|
|
24
|
+
function _define_property(obj, key, value) {
|
|
25
|
+
if (key in obj) {
|
|
26
|
+
Object.defineProperty(obj, key, {
|
|
27
|
+
value: value,
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
obj[key] = value;
|
|
34
|
+
}
|
|
35
|
+
return obj;
|
|
36
|
+
}
|
|
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 supportedExts = _typegen.supportedExtensions.join(", ");
|
|
84
|
+
class GuideGenerateTypes extends _basecommand.default {
|
|
85
|
+
async run() {
|
|
86
|
+
const { flags } = this.props;
|
|
87
|
+
const outputFilePath = flags["output-file"].abspath;
|
|
88
|
+
const extension = _nodepath.default.extname(outputFilePath);
|
|
89
|
+
const targetLang = (0, _typegen.getLanguageFromExtension)(extension);
|
|
90
|
+
if (!targetLang) {
|
|
91
|
+
this.error(new _error.ApiError(`Unsupported file extension: ${extension}. We currently support ${supportedExts} files only.`));
|
|
92
|
+
}
|
|
93
|
+
_ux.spinner.start(`‣ Loading guides`);
|
|
94
|
+
// 1. List all guides in the target environment.
|
|
95
|
+
const guides = await this.listAllGuides();
|
|
96
|
+
_ux.spinner.stop();
|
|
97
|
+
// 2. Generate types for all guides and its step contents.
|
|
98
|
+
_ux.spinner.start(`‣ Generating types`);
|
|
99
|
+
const { result, count, mapping } = await _guide.generateTypes(guides, targetLang);
|
|
100
|
+
_ux.spinner.stop();
|
|
101
|
+
if (!result) {
|
|
102
|
+
this.log(`‣ No guides with content JSON schema found, skipping type generation`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// 3. Write the generated types to the output file.
|
|
106
|
+
await _fsextra.outputFile(outputFilePath, result.lines.join("\n"));
|
|
107
|
+
// 4. If for typescript, render and append the types index at the end.
|
|
108
|
+
if (targetLang === "typescript") {
|
|
109
|
+
const lines = _guide.generateIndexTypeTS(mapping);
|
|
110
|
+
await _fsextra.appendFile(outputFilePath, lines.join("\n"));
|
|
111
|
+
}
|
|
112
|
+
this.log(`‣ Successfully generated types for ${count} message type(s) and wrote them to ${outputFilePath}`);
|
|
113
|
+
}
|
|
114
|
+
async listAllGuides(pageParams = {}, guidesFetchedSoFar = []) {
|
|
115
|
+
const props = (0, _objectisomorphic.merge)(this.props, {
|
|
116
|
+
flags: {
|
|
117
|
+
...pageParams,
|
|
118
|
+
limit: _page.MAX_PAGINATION_LIMIT,
|
|
119
|
+
// Generate json schemas for guide contents so we can generate types.
|
|
120
|
+
"include-json-schema": true
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const resp = await this.apiV1.listGuides(props);
|
|
124
|
+
if (!(0, _request.isSuccessResp)(resp)) {
|
|
125
|
+
const message = (0, _request.formatErrorRespMessage)(resp);
|
|
126
|
+
this.error(new _error.ApiError(message));
|
|
127
|
+
}
|
|
128
|
+
const { entries, page_info: pageInfo } = resp.data;
|
|
129
|
+
const guides = [
|
|
130
|
+
...guidesFetchedSoFar,
|
|
131
|
+
...entries
|
|
132
|
+
];
|
|
133
|
+
return pageInfo.after ? this.listAllGuides({
|
|
134
|
+
after: pageInfo.after
|
|
135
|
+
}, guides) : guides;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
_define_property(GuideGenerateTypes, "description", "Generate types for all guides in an environment and write them to a file.");
|
|
139
|
+
_define_property(GuideGenerateTypes, "flags", {
|
|
140
|
+
environment: _core.Flags.string({
|
|
141
|
+
summary: "Select the environment to generate types for.",
|
|
142
|
+
default: _const.KnockEnv.Development
|
|
143
|
+
}),
|
|
144
|
+
"output-file": _flag.filePath({
|
|
145
|
+
summary: `The output file to write the generated types to. We currently support ${supportedExts} files only. Your file extension will determine the target language for the generated types.`,
|
|
146
|
+
required: true
|
|
147
|
+
})
|
|
148
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
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 GuideGet;
|
|
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
|
+
const _conditions = require("../../lib/marshal/conditions");
|
|
18
|
+
const _helpers = require("../../lib/marshal/guide/helpers");
|
|
19
|
+
function _define_property(obj, key, value) {
|
|
20
|
+
if (key in obj) {
|
|
21
|
+
Object.defineProperty(obj, key, {
|
|
22
|
+
value: value,
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
obj[key] = value;
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
function _interop_require_default(obj) {
|
|
33
|
+
return obj && obj.__esModule ? obj : {
|
|
34
|
+
default: obj
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
class GuideGet extends _basecommand.default {
|
|
38
|
+
async run() {
|
|
39
|
+
_ux.spinner.start("‣ Loading");
|
|
40
|
+
const { guide } = await this.loadGuide();
|
|
41
|
+
_ux.spinner.stop();
|
|
42
|
+
const { flags } = this.props;
|
|
43
|
+
if (flags.json) return guide;
|
|
44
|
+
this.render(guide);
|
|
45
|
+
}
|
|
46
|
+
async loadGuide() {
|
|
47
|
+
const guideResp = await this.apiV1.getGuide(this.props);
|
|
48
|
+
if (!(0, _request.isSuccessResp)(guideResp)) {
|
|
49
|
+
const message = (0, _request.formatErrorRespMessage)(guideResp);
|
|
50
|
+
_core.ux.error(new _error.ApiError(message));
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
guide: guideResp.data
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
render(guide) {
|
|
57
|
+
const { guideKey } = this.props.args;
|
|
58
|
+
const { environment: env, "hide-uncommitted-changes": committedOnly } = this.props.flags;
|
|
59
|
+
const qualifier = env === "development" && !committedOnly ? "(including uncommitted)" : "";
|
|
60
|
+
this.log(`‣ Showing guide \`${guideKey}\` in \`${env}\` environment ${qualifier}\n`);
|
|
61
|
+
/*
|
|
62
|
+
* Guide table
|
|
63
|
+
*/ const rows = [
|
|
64
|
+
{
|
|
65
|
+
key: "Name",
|
|
66
|
+
value: guide.name
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
key: "Key",
|
|
70
|
+
value: guide.key
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: "Type",
|
|
74
|
+
value: guide.type || "-"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "Status",
|
|
78
|
+
value: (0, _helpers.formatStatusWithSchedule)(guide)
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
key: "Description",
|
|
82
|
+
value: guide.description || "-"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
key: "Content",
|
|
86
|
+
value: guide.steps.length > 0 ? (0, _helpers.formatStep)(guide.steps[0]) : "-"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
key: "Targeting audience",
|
|
90
|
+
value: guide.target_audience_key || "(All users)"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: "Targeting conditions",
|
|
94
|
+
value: guide.target_property_conditions ? (0, _conditions.formatConditions)(guide.target_property_conditions) : "-"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
key: "Activation",
|
|
98
|
+
value: (0, _helpers.formatActivationRules)(guide.activation_location_rules)
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
key: "Created at",
|
|
102
|
+
value: (0, _date.formatDateTime)(guide.created_at)
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
key: "Updated at",
|
|
106
|
+
value: (0, _date.formatDateTime)(guide.updated_at)
|
|
107
|
+
}
|
|
108
|
+
];
|
|
109
|
+
_core.ux.table(rows, {
|
|
110
|
+
key: {
|
|
111
|
+
header: "Guide",
|
|
112
|
+
minWidth: 24
|
|
113
|
+
},
|
|
114
|
+
value: {
|
|
115
|
+
header: "",
|
|
116
|
+
minWidth: 24
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
this.log("");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
_define_property(GuideGet, "summary", "Display a single guide from an environment.");
|
|
123
|
+
// Hide until guides are released in GA.
|
|
124
|
+
_define_property(GuideGet, "hidden", true);
|
|
125
|
+
_define_property(GuideGet, "flags", {
|
|
126
|
+
environment: _core.Flags.string({
|
|
127
|
+
default: "development",
|
|
128
|
+
summary: "The environment to use."
|
|
129
|
+
}),
|
|
130
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
131
|
+
summary: "Hide any uncommitted changes."
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
_define_property(GuideGet, "args", {
|
|
135
|
+
guideKey: _core.Args.string({
|
|
136
|
+
required: true
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
_define_property(GuideGet, "enableJsonFlag", true);
|
|
@@ -0,0 +1,112 @@
|
|
|
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 GuideList;
|
|
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 _objectisomorphic = require("../../lib/helpers/object.isomorphic");
|
|
15
|
+
const _page = require("../../lib/helpers/page");
|
|
16
|
+
const _request = require("../../lib/helpers/request");
|
|
17
|
+
const _helpers = require("../../lib/marshal/guide/helpers");
|
|
18
|
+
function _define_property(obj, key, value) {
|
|
19
|
+
if (key in obj) {
|
|
20
|
+
Object.defineProperty(obj, key, {
|
|
21
|
+
value: value,
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
obj[key] = value;
|
|
28
|
+
}
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
function _interop_require_default(obj) {
|
|
32
|
+
return obj && obj.__esModule ? obj : {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
class GuideList extends _basecommand.default {
|
|
37
|
+
async run() {
|
|
38
|
+
const resp = await this.request();
|
|
39
|
+
const { flags } = this.props;
|
|
40
|
+
if (flags.json) return resp.data;
|
|
41
|
+
this.render(resp.data);
|
|
42
|
+
}
|
|
43
|
+
async request(pageParams = {}) {
|
|
44
|
+
const props = (0, _objectisomorphic.merge)(this.props, {
|
|
45
|
+
flags: {
|
|
46
|
+
...pageParams
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return (0, _request.withSpinner)(()=>this.apiV1.listGuides(props));
|
|
50
|
+
}
|
|
51
|
+
async render(data) {
|
|
52
|
+
const { entries } = data;
|
|
53
|
+
const { environment: env, "hide-uncommitted-changes": committedOnly } = this.props.flags;
|
|
54
|
+
const qualifier = env === "development" && !committedOnly ? "(including uncommitted)" : "";
|
|
55
|
+
this.log(`‣ Showing ${entries.length} guides in \`${env}\` environment ${qualifier}\n`);
|
|
56
|
+
/*
|
|
57
|
+
* Guides list table
|
|
58
|
+
*/ _core.ux.table(entries, {
|
|
59
|
+
key: {
|
|
60
|
+
header: "Key"
|
|
61
|
+
},
|
|
62
|
+
name: {
|
|
63
|
+
header: "Name"
|
|
64
|
+
},
|
|
65
|
+
type: {
|
|
66
|
+
header: "Type",
|
|
67
|
+
get: (entry)=>entry.type || "-"
|
|
68
|
+
},
|
|
69
|
+
channel: {
|
|
70
|
+
header: "Channel",
|
|
71
|
+
get: (entry)=>entry.channel_key || "-"
|
|
72
|
+
},
|
|
73
|
+
status: {
|
|
74
|
+
header: "Status",
|
|
75
|
+
get: (entry)=>(0, _helpers.formatStatusWithSchedule)(entry)
|
|
76
|
+
},
|
|
77
|
+
description: {
|
|
78
|
+
header: "Description",
|
|
79
|
+
get: (entry)=>entry.description || "-"
|
|
80
|
+
},
|
|
81
|
+
updated_at: {
|
|
82
|
+
header: "Updated at",
|
|
83
|
+
get: (entry)=>(0, _date.formatDate)(entry.updated_at)
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return this.prompt(data);
|
|
87
|
+
}
|
|
88
|
+
async prompt(data) {
|
|
89
|
+
const { page_info } = data;
|
|
90
|
+
const pageAction = await (0, _page.maybePromptPageAction)(page_info);
|
|
91
|
+
const pageParams = pageAction && (0, _page.paramsForPageAction)(pageAction, page_info);
|
|
92
|
+
if (pageParams) {
|
|
93
|
+
this.log("\n");
|
|
94
|
+
const resp = await this.request(pageParams);
|
|
95
|
+
return this.render(resp.data);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
_define_property(GuideList, "summary", "Display all guides for an environment.");
|
|
100
|
+
// Hide until guides are released in GA.
|
|
101
|
+
_define_property(GuideList, "hidden", true);
|
|
102
|
+
_define_property(GuideList, "flags", {
|
|
103
|
+
environment: _core.Flags.string({
|
|
104
|
+
default: "development",
|
|
105
|
+
summary: "The environment to use."
|
|
106
|
+
}),
|
|
107
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
108
|
+
summary: "Hide any uncommitted changes."
|
|
109
|
+
}),
|
|
110
|
+
..._page.pageFlags
|
|
111
|
+
});
|
|
112
|
+
_define_property(GuideList, "enableJsonFlag", true);
|