@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
|
@@ -0,0 +1,209 @@
|
|
|
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 GuidePull;
|
|
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 _guide = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/guide"));
|
|
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 GuidePull extends _basecommand.default {
|
|
82
|
+
async run() {
|
|
83
|
+
const { args, flags } = this.props;
|
|
84
|
+
if (flags.all && args.guideKey) {
|
|
85
|
+
return this.error(`guideKey arg \`${args.guideKey}\` cannot also be provided when using --all`);
|
|
86
|
+
}
|
|
87
|
+
return flags.all ? this.pullAllGuides() : this.pullOneGuide();
|
|
88
|
+
}
|
|
89
|
+
async pullOneGuide() {
|
|
90
|
+
const { flags } = this.props;
|
|
91
|
+
const dirContext = await this.getGuideDirContext();
|
|
92
|
+
if (dirContext.exists) {
|
|
93
|
+
this.log(`‣ Found \`${dirContext.key}\` at ${dirContext.abspath}`);
|
|
94
|
+
} else {
|
|
95
|
+
const prompt = `Create a new guide directory \`${dirContext.key}\` at ${dirContext.abspath}?`;
|
|
96
|
+
const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
|
|
97
|
+
if (!input) return;
|
|
98
|
+
}
|
|
99
|
+
const resp = await (0, _request.withSpinner)(()=>{
|
|
100
|
+
const props = (0, _objectisomorphic.merge)(this.props, {
|
|
101
|
+
args: {
|
|
102
|
+
guideKey: dirContext.key
|
|
103
|
+
},
|
|
104
|
+
flags: {
|
|
105
|
+
annotate: true
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return this.apiV1.getGuide(props);
|
|
109
|
+
});
|
|
110
|
+
await _guide.writeGuideDirFromData(dirContext, resp.data);
|
|
111
|
+
const action = dirContext.exists ? "updated" : "created";
|
|
112
|
+
this.log(`‣ Successfully ${action} \`${dirContext.key}\` at ${dirContext.abspath}`);
|
|
113
|
+
}
|
|
114
|
+
async pullAllGuides() {
|
|
115
|
+
const { flags } = this.props;
|
|
116
|
+
const defaultToCwd = {
|
|
117
|
+
abspath: this.runContext.cwd,
|
|
118
|
+
exists: true
|
|
119
|
+
};
|
|
120
|
+
const targetDirCtx = flags["guides-dir"] || defaultToCwd;
|
|
121
|
+
const prompt = targetDirCtx.exists ? `Pull latest guides into ${targetDirCtx.abspath}?\n This will overwrite the contents of this directory.` : `Create a new guides directory at ${targetDirCtx.abspath}?`;
|
|
122
|
+
const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
|
|
123
|
+
if (!input) return;
|
|
124
|
+
_ux.spinner.start(`‣ Loading`);
|
|
125
|
+
const guides = await this.listAllGuides();
|
|
126
|
+
await _guide.writeGuidesIndexDir(targetDirCtx, guides);
|
|
127
|
+
_ux.spinner.stop();
|
|
128
|
+
const action = targetDirCtx.exists ? "updated" : "created";
|
|
129
|
+
this.log(`‣ Successfully ${action} the guides directory at ${targetDirCtx.abspath}`);
|
|
130
|
+
}
|
|
131
|
+
async listAllGuides(pageParams = {}, guidesFetchedSoFar = []) {
|
|
132
|
+
const props = (0, _objectisomorphic.merge)(this.props, {
|
|
133
|
+
flags: {
|
|
134
|
+
...pageParams,
|
|
135
|
+
annotate: true,
|
|
136
|
+
limit: _page.MAX_PAGINATION_LIMIT
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
const resp = await this.apiV1.listGuides(props);
|
|
140
|
+
if (!(0, _request.isSuccessResp)(resp)) {
|
|
141
|
+
const message = (0, _request.formatErrorRespMessage)(resp);
|
|
142
|
+
this.error(new _error.ApiError(message));
|
|
143
|
+
}
|
|
144
|
+
const { entries, page_info: pageInfo } = resp.data;
|
|
145
|
+
const guides = [
|
|
146
|
+
...guidesFetchedSoFar,
|
|
147
|
+
...entries
|
|
148
|
+
];
|
|
149
|
+
return pageInfo.after ? this.listAllGuides({
|
|
150
|
+
after: pageInfo.after
|
|
151
|
+
}, guides) : guides;
|
|
152
|
+
}
|
|
153
|
+
async getGuideDirContext() {
|
|
154
|
+
const { guideKey } = this.props.args;
|
|
155
|
+
const { resourceDir, cwd: runCwd } = this.runContext;
|
|
156
|
+
// Inside an existing resource dir, use it if valid for the target guide.
|
|
157
|
+
if (resourceDir) {
|
|
158
|
+
const target = {
|
|
159
|
+
commandId: _basecommand.default.id,
|
|
160
|
+
type: "guide",
|
|
161
|
+
key: guideKey
|
|
162
|
+
};
|
|
163
|
+
return (0, _runcontext.ensureResourceDirForTarget)(resourceDir, target);
|
|
164
|
+
}
|
|
165
|
+
// Not inside any existing guide directory, which means either create a
|
|
166
|
+
// new guide directory in the cwd, or update it if there is one already.
|
|
167
|
+
if (guideKey) {
|
|
168
|
+
const dirPath = _nodepath.resolve(runCwd, guideKey);
|
|
169
|
+
const exists = await _guide.isGuideDir(dirPath);
|
|
170
|
+
return {
|
|
171
|
+
type: "guide",
|
|
172
|
+
key: guideKey,
|
|
173
|
+
abspath: dirPath,
|
|
174
|
+
exists
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// Not in any guide directory, nor a guide key arg was given so error.
|
|
178
|
+
return this.error("Missing 1 required arg:\nguideKey");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Hide until guides are released in GA.
|
|
182
|
+
_define_property(GuidePull, "hidden", true);
|
|
183
|
+
_define_property(GuidePull, "summary", "Pull one or more guides from an environment into a local file system.");
|
|
184
|
+
_define_property(GuidePull, "flags", {
|
|
185
|
+
environment: _core.Flags.string({
|
|
186
|
+
default: "development",
|
|
187
|
+
summary: "The environment to use."
|
|
188
|
+
}),
|
|
189
|
+
all: _core.Flags.boolean({
|
|
190
|
+
summary: "Whether to pull all guides from the specified environment."
|
|
191
|
+
}),
|
|
192
|
+
"guides-dir": _flag.dirPath({
|
|
193
|
+
summary: "The target directory path to pull all guides into.",
|
|
194
|
+
dependsOn: [
|
|
195
|
+
"all"
|
|
196
|
+
]
|
|
197
|
+
}),
|
|
198
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
199
|
+
summary: "Hide any uncommitted changes."
|
|
200
|
+
}),
|
|
201
|
+
force: _core.Flags.boolean({
|
|
202
|
+
summary: "Remove the confirmation prompt."
|
|
203
|
+
})
|
|
204
|
+
});
|
|
205
|
+
_define_property(GuidePull, "args", {
|
|
206
|
+
guideKey: _core.Args.string({
|
|
207
|
+
required: false
|
|
208
|
+
})
|
|
209
|
+
});
|
|
@@ -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 GuidePush;
|
|
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 _guide = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/guide"));
|
|
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 GuidePush extends _basecommand.default {
|
|
82
|
+
async run() {
|
|
83
|
+
const { flags } = this.props;
|
|
84
|
+
// 1. First read all guide directories found for the given command.
|
|
85
|
+
const target = await _guide.ensureValidCommandTarget(this.props, this.runContext);
|
|
86
|
+
const [guides, readErrors] = await _guide.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 (guides.length === 0) {
|
|
95
|
+
this.error(`No guide 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, guides);
|
|
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 guide, abort on the first error.
|
|
107
|
+
_ux.spinner.start(`‣ Pushing`);
|
|
108
|
+
for (const guide of guides){
|
|
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.upsertGuide(props, {
|
|
116
|
+
...guide.content,
|
|
117
|
+
key: guide.key
|
|
118
|
+
});
|
|
119
|
+
if ((0, _request.isSuccessResp)(resp)) {
|
|
120
|
+
// Update the guide directory with the successfully pushed guide
|
|
121
|
+
// payload from the server.
|
|
122
|
+
// eslint-disable-next-line no-await-in-loop
|
|
123
|
+
await _guide.writeGuideDirFromData(guide, resp.data.guide);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const error = new _error.SourceError((0, _request.formatErrorRespMessage)(resp), _guide.guideJsonPath(guide), "ApiError");
|
|
127
|
+
this.error((0, _error.formatError)(error));
|
|
128
|
+
}
|
|
129
|
+
_ux.spinner.stop();
|
|
130
|
+
// 4. Display a success message.
|
|
131
|
+
const guideKeys = guides.map((g)=>g.key);
|
|
132
|
+
const actioned = flags.commit ? "pushed and committed" : "pushed";
|
|
133
|
+
this.log(`‣ Successfully ${actioned} ${guides.length} guide(s):\n` + (0, _string.indentString)(guideKeys.join("\n"), 4));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Hide until guides are released in GA.
|
|
137
|
+
_define_property(GuidePush, "hidden", true);
|
|
138
|
+
_define_property(GuidePush, "summary", "Push one or more guides from a local file system to Knock.");
|
|
139
|
+
_define_property(GuidePush, "flags", {
|
|
140
|
+
environment: _core.Flags.string({
|
|
141
|
+
summary: "Pushing a guide 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 guides from the target directory."
|
|
149
|
+
}),
|
|
150
|
+
"guides-dir": _flag.dirPath({
|
|
151
|
+
summary: "The target directory path to find all guides to push.",
|
|
152
|
+
dependsOn: [
|
|
153
|
+
"all"
|
|
154
|
+
]
|
|
155
|
+
}),
|
|
156
|
+
commit: _core.Flags.boolean({
|
|
157
|
+
summary: "Push and commit the guide(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(GuidePush, "args", {
|
|
168
|
+
guideKey: _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 GuideValidate;
|
|
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 _guide = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/guide"));
|
|
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 GuideValidate extends _basecommand.default {
|
|
80
|
+
async run() {
|
|
81
|
+
// 1. Read all guide directories found for the given command.
|
|
82
|
+
const target = await _guide.ensureValidCommandTarget(this.props, this.runContext);
|
|
83
|
+
const [guides, readErrors] = await _guide.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 (guides.length === 0) {
|
|
92
|
+
this.error(`No guide directories found in ${target.context.abspath}`);
|
|
93
|
+
}
|
|
94
|
+
// 2. Validate each guide data.
|
|
95
|
+
_ux.spinner.start(`‣ Validating`);
|
|
96
|
+
const apiErrors = await GuideValidate.validateAll(this.apiV1, this.props, guides);
|
|
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 guideKeys = guides.map((g)=>g.key);
|
|
105
|
+
this.log(`‣ Successfully validated ${guides.length} guide(s):\n` + (0, _string.indentString)(guideKeys.join("\n"), 4));
|
|
106
|
+
}
|
|
107
|
+
static async validateAll(api, props, guides) {
|
|
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 = guides.map(async (guide)=>{
|
|
111
|
+
const resp = await api.validateGuide(props, {
|
|
112
|
+
...guide.content,
|
|
113
|
+
key: guide.key
|
|
114
|
+
});
|
|
115
|
+
if ((0, _request.isSuccessResp)(resp)) return;
|
|
116
|
+
const error = new _error.SourceError((0, _request.formatErrorRespMessage)(resp), _guide.guideJsonPath(guide), "ApiError");
|
|
117
|
+
return error;
|
|
118
|
+
});
|
|
119
|
+
const errors = (await Promise.all(errorPromises)).filter((e)=>Boolean(e));
|
|
120
|
+
return errors;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
_define_property(GuideValidate, "summary", "Validate one or more guides from a local file system.");
|
|
124
|
+
// Hide until guides are released in GA.
|
|
125
|
+
_define_property(GuideValidate, "hidden", true);
|
|
126
|
+
_define_property(GuideValidate, "flags", {
|
|
127
|
+
environment: _core.Flags.string({
|
|
128
|
+
summary: "Validating a guide 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 guides from the target directory."
|
|
136
|
+
}),
|
|
137
|
+
"guides-dir": _flag.dirPath({
|
|
138
|
+
summary: "The target directory path to find all guides to validate.",
|
|
139
|
+
dependsOn: [
|
|
140
|
+
"all"
|
|
141
|
+
]
|
|
142
|
+
})
|
|
143
|
+
});
|
|
144
|
+
_define_property(GuideValidate, "args", {
|
|
145
|
+
guideKey: _core.Args.string({
|
|
146
|
+
required: false
|
|
147
|
+
})
|
|
148
|
+
});
|
package/dist/commands/knock.js
CHANGED
|
@@ -112,6 +112,9 @@ class Knock extends _basecommand.default {
|
|
|
112
112
|
this.log("");
|
|
113
113
|
this.log("Thank you for using Knock, and have a nice day! 🙂");
|
|
114
114
|
}
|
|
115
|
+
constructor(...args){
|
|
116
|
+
super(...args), _define_property(this, "requiresAuth", false);
|
|
117
|
+
}
|
|
115
118
|
}
|
|
116
119
|
// Because, it's a secret :)
|
|
117
120
|
_define_property(Knock, "hidden", true);
|
|
@@ -0,0 +1,50 @@
|
|
|
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 Login;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _auth = /*#__PURE__*/ _interop_require_default(require("../lib/auth"));
|
|
12
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../lib/base-command"));
|
|
13
|
+
const _ux = require("../lib/helpers/ux");
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _interop_require_default(obj) {
|
|
28
|
+
return obj && obj.__esModule ? obj : {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
class Login extends _basecommand.default {
|
|
33
|
+
async run() {
|
|
34
|
+
const { flags } = this.props;
|
|
35
|
+
if (flags["service-token"]) {
|
|
36
|
+
this.log("Service token provided, skipping login.");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
_ux.spinner.start("‣ Authenticating with Knock...");
|
|
40
|
+
const resp = await _auth.default.waitForAccessToken(this.sessionContext.dashboardOrigin, this.sessionContext.authOrigin);
|
|
41
|
+
_ux.spinner.stop();
|
|
42
|
+
await this.configStore.set({
|
|
43
|
+
userSession: resp
|
|
44
|
+
});
|
|
45
|
+
this.log("‣ Successfully authenticated with Knock.");
|
|
46
|
+
}
|
|
47
|
+
constructor(...args){
|
|
48
|
+
super(...args), _define_property(this, "requiresAuth", false);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 Logout;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../lib/base-command"));
|
|
12
|
+
const _ux = require("../lib/helpers/ux");
|
|
13
|
+
function _define_property(obj, key, value) {
|
|
14
|
+
if (key in obj) {
|
|
15
|
+
Object.defineProperty(obj, key, {
|
|
16
|
+
value: value,
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
obj[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
26
|
+
function _interop_require_default(obj) {
|
|
27
|
+
return obj && obj.__esModule ? obj : {
|
|
28
|
+
default: obj
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
class Logout extends _basecommand.default {
|
|
32
|
+
async run() {
|
|
33
|
+
const { flags } = this.props;
|
|
34
|
+
if (flags["service-token"]) {
|
|
35
|
+
this.log("Service token provided, skipping logout.");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
_ux.spinner.start("‣ Logging out of Knock...");
|
|
39
|
+
await this.configStore.set({
|
|
40
|
+
userSession: undefined
|
|
41
|
+
});
|
|
42
|
+
_ux.spinner.stop();
|
|
43
|
+
this.log("‣ Successfully logged out of Knock. See you around.");
|
|
44
|
+
}
|
|
45
|
+
constructor(...args){
|
|
46
|
+
super(...args), _define_property(this, "requiresAuth", false);
|
|
47
|
+
}
|
|
48
|
+
}
|
package/dist/commands/whoami.js
CHANGED
|
@@ -34,10 +34,14 @@ class Whoami extends _basecommand.default {
|
|
|
34
34
|
const resp = await (0, _request.withSpinner)(()=>this.apiV1.whoami());
|
|
35
35
|
const { flags } = this.props;
|
|
36
36
|
if (flags.json) return resp.data;
|
|
37
|
-
this.log(`‣ Successfully
|
|
38
|
-
|
|
37
|
+
this.log(`‣ Successfully authenticated:`);
|
|
38
|
+
let info = [];
|
|
39
|
+
info = resp.data.service_token_name ? [
|
|
39
40
|
`Account name: ${resp.data.account_name}`,
|
|
40
41
|
`Service token name: ${resp.data.service_token_name}`
|
|
42
|
+
] : [
|
|
43
|
+
`Account name: ${resp.data.account_name}`,
|
|
44
|
+
`User ID: ${resp.data.user_id}`
|
|
41
45
|
];
|
|
42
46
|
this.log((0, _string.indentString)(info.join("\n"), 4));
|
|
43
47
|
}
|