@knocklabs/cli 0.1.0-rc.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/LICENSE +21 -0
- package/README.md +377 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/dist/commands/ping.js +24 -0
- package/dist/commands/workflow/get.js +161 -0
- package/dist/commands/workflow/list.js +128 -0
- package/dist/commands/workflow/pull.js +139 -0
- package/dist/commands/workflow/push.js +128 -0
- package/dist/index.js +9 -0
- package/dist/lib/api-v1.js +76 -0
- package/dist/lib/base-command.js +91 -0
- package/dist/lib/helpers/date.js +21 -0
- package/dist/lib/helpers/dir-context.js +33 -0
- package/dist/lib/helpers/env.js +63 -0
- package/dist/lib/helpers/error.js +60 -0
- package/dist/lib/helpers/json.js +72 -0
- package/dist/lib/helpers/object.js +111 -0
- package/dist/lib/helpers/page.js +92 -0
- package/dist/lib/helpers/request.js +38 -0
- package/dist/lib/helpers/string.js +34 -0
- package/dist/lib/marshal/conditions/helpers.js +26 -0
- package/dist/lib/marshal/conditions/index.js +17 -0
- package/dist/lib/marshal/conditions/types.js +4 -0
- package/dist/lib/marshal/shared/types.js +4 -0
- package/dist/lib/marshal/workflow/helpers.js +139 -0
- package/dist/lib/marshal/workflow/index.js +19 -0
- package/dist/lib/marshal/workflow/reader.js +233 -0
- package/dist/lib/marshal/workflow/types.js +15 -0
- package/dist/lib/marshal/workflow/writer.js +214 -0
- package/dist/lib/run-context.js +79 -0
- package/dist/lib/user-config.js +83 -0
- package/oclif.manifest.json +220 -0
- package/package.json +94 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>WorkflowList
|
|
8
|
+
});
|
|
9
|
+
const _core = require("@oclif/core");
|
|
10
|
+
const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
|
|
11
|
+
const _date = require("../../lib/helpers/date");
|
|
12
|
+
const _object = require("../../lib/helpers/object");
|
|
13
|
+
const _page = require("../../lib/helpers/page");
|
|
14
|
+
const _request = require("../../lib/helpers/request");
|
|
15
|
+
const _workflow = /*#__PURE__*/ _interopRequireWildcard(require("../../lib/marshal/workflow"));
|
|
16
|
+
function _interopRequireDefault(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : {
|
|
18
|
+
default: obj
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
22
|
+
if (typeof WeakMap !== "function") return null;
|
|
23
|
+
var cacheBabelInterop = new WeakMap();
|
|
24
|
+
var cacheNodeInterop = new WeakMap();
|
|
25
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
26
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
27
|
+
})(nodeInterop);
|
|
28
|
+
}
|
|
29
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
30
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
34
|
+
return {
|
|
35
|
+
default: obj
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
39
|
+
if (cache && cache.has(obj)) {
|
|
40
|
+
return cache.get(obj);
|
|
41
|
+
}
|
|
42
|
+
var newObj = {};
|
|
43
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
44
|
+
for(var key in obj){
|
|
45
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
46
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
47
|
+
if (desc && (desc.get || desc.set)) {
|
|
48
|
+
Object.defineProperty(newObj, key, desc);
|
|
49
|
+
} else {
|
|
50
|
+
newObj[key] = obj[key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
newObj.default = obj;
|
|
55
|
+
if (cache) {
|
|
56
|
+
cache.set(obj, newObj);
|
|
57
|
+
}
|
|
58
|
+
return newObj;
|
|
59
|
+
}
|
|
60
|
+
class WorkflowList extends _baseCommand.default {
|
|
61
|
+
async run() {
|
|
62
|
+
const resp = await this.request();
|
|
63
|
+
const { flags } = this.props;
|
|
64
|
+
if (flags.json) return resp.data;
|
|
65
|
+
this.render(resp.data);
|
|
66
|
+
}
|
|
67
|
+
async request(pageParams = {}) {
|
|
68
|
+
const props = (0, _object.merge)(this.props, {
|
|
69
|
+
flags: {
|
|
70
|
+
...pageParams
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return (0, _request.withSpinner)(()=>this.apiV1.listWorkflows(props));
|
|
74
|
+
}
|
|
75
|
+
async render(data) {
|
|
76
|
+
const { entries } = data;
|
|
77
|
+
const { environment: env , "hide-uncommitted-changes": commitedOnly } = this.props.flags;
|
|
78
|
+
const qualifier = env === "development" && !commitedOnly ? "(including uncommitted)" : "";
|
|
79
|
+
this.log(`‣ Showing ${entries.length} workflows in \`${env}\` environment ${qualifier}\n`);
|
|
80
|
+
/*
|
|
81
|
+
* Workflows list table
|
|
82
|
+
*/ _core.CliUx.ux.table(entries, {
|
|
83
|
+
key: {
|
|
84
|
+
header: "Key"
|
|
85
|
+
},
|
|
86
|
+
name: {
|
|
87
|
+
header: "Name"
|
|
88
|
+
},
|
|
89
|
+
status: {
|
|
90
|
+
header: "Status",
|
|
91
|
+
get: (entry)=>entry.active ? "active" : "inactive"
|
|
92
|
+
},
|
|
93
|
+
categories: {
|
|
94
|
+
header: "Categories",
|
|
95
|
+
get: (entry)=>_workflow.formatCategories(entry, {
|
|
96
|
+
truncateAfter: 3
|
|
97
|
+
})
|
|
98
|
+
},
|
|
99
|
+
steps: {
|
|
100
|
+
header: "Steps",
|
|
101
|
+
get: (entry)=>entry.steps.length > 0 ? entry.steps.length : "-"
|
|
102
|
+
},
|
|
103
|
+
updated_at: {
|
|
104
|
+
header: "Updated at",
|
|
105
|
+
get: (entry)=>(0, _date.formatDate)(entry.updated_at)
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return this.prompt(data);
|
|
109
|
+
}
|
|
110
|
+
async prompt(data) {
|
|
111
|
+
const { page_info } = data;
|
|
112
|
+
const pageAction = await (0, _page.maybePromptPageAction)(page_info);
|
|
113
|
+
const pageParams = pageAction && (0, _page.paramsForPageAction)(pageAction, page_info);
|
|
114
|
+
if (pageParams) {
|
|
115
|
+
this.log("\n");
|
|
116
|
+
const resp = await this.request(pageParams);
|
|
117
|
+
return this.render(resp.data);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
WorkflowList.flags = {
|
|
122
|
+
environment: _core.Flags.string({
|
|
123
|
+
default: "development"
|
|
124
|
+
}),
|
|
125
|
+
"hide-uncommitted-changes": _core.Flags.boolean(),
|
|
126
|
+
..._page.pageFlags
|
|
127
|
+
};
|
|
128
|
+
WorkflowList.enableJsonFlag = true;
|
|
@@ -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: ()=>WorkflowPull
|
|
8
|
+
});
|
|
9
|
+
const _nodePath = /*#__PURE__*/ _interopRequireWildcard(require("node:path"));
|
|
10
|
+
const _core = require("@oclif/core");
|
|
11
|
+
const _enquirer = /*#__PURE__*/ _interopRequireDefault(require("enquirer"));
|
|
12
|
+
const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
|
|
13
|
+
const _dirContext = require("../../lib/helpers/dir-context");
|
|
14
|
+
const _object = require("../../lib/helpers/object");
|
|
15
|
+
const _request = require("../../lib/helpers/request");
|
|
16
|
+
const _workflow = /*#__PURE__*/ _interopRequireWildcard(require("../../lib/marshal/workflow"));
|
|
17
|
+
function _interopRequireDefault(obj) {
|
|
18
|
+
return obj && obj.__esModule ? obj : {
|
|
19
|
+
default: obj
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
23
|
+
if (typeof WeakMap !== "function") return null;
|
|
24
|
+
var cacheBabelInterop = new WeakMap();
|
|
25
|
+
var cacheNodeInterop = new WeakMap();
|
|
26
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
27
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
28
|
+
})(nodeInterop);
|
|
29
|
+
}
|
|
30
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
31
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
35
|
+
return {
|
|
36
|
+
default: obj
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
40
|
+
if (cache && cache.has(obj)) {
|
|
41
|
+
return cache.get(obj);
|
|
42
|
+
}
|
|
43
|
+
var newObj = {};
|
|
44
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
45
|
+
for(var key in obj){
|
|
46
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
47
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
48
|
+
if (desc && (desc.get || desc.set)) {
|
|
49
|
+
Object.defineProperty(newObj, key, desc);
|
|
50
|
+
} else {
|
|
51
|
+
newObj[key] = obj[key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
newObj.default = obj;
|
|
56
|
+
if (cache) {
|
|
57
|
+
cache.set(obj, newObj);
|
|
58
|
+
}
|
|
59
|
+
return newObj;
|
|
60
|
+
}
|
|
61
|
+
const promptToConfirm = async ({ key })=>{
|
|
62
|
+
try {
|
|
63
|
+
const { input } = await _enquirer.default.prompt({
|
|
64
|
+
type: "confirm",
|
|
65
|
+
name: "input",
|
|
66
|
+
message: `Create a new workflow directory \`${_nodePath.join(key, "/")}\`?`
|
|
67
|
+
});
|
|
68
|
+
return input;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.log(error);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
class WorkflowPull extends _baseCommand.default {
|
|
74
|
+
async run() {
|
|
75
|
+
// 1. Retrieve or build a new workflow directory context.
|
|
76
|
+
const dirContext = await this.getWorkflowDirContext();
|
|
77
|
+
if (dirContext.exists) {
|
|
78
|
+
this.log(`‣ Found \`${dirContext.key}\` at ${dirContext.abspath}`);
|
|
79
|
+
} else {
|
|
80
|
+
const input = await promptToConfirm(dirContext);
|
|
81
|
+
if (!input) return;
|
|
82
|
+
}
|
|
83
|
+
// 2. Fetch the workflow with annotations.
|
|
84
|
+
const resp = await (0, _request.withSpinner)(()=>{
|
|
85
|
+
const props = (0, _object.merge)(this.props, {
|
|
86
|
+
args: {
|
|
87
|
+
workflowKey: dirContext.key
|
|
88
|
+
},
|
|
89
|
+
flags: {
|
|
90
|
+
annotate: true
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return this.apiV1.getWorkflow(props);
|
|
94
|
+
});
|
|
95
|
+
// 3. Write the workflow with the workflow directory context.
|
|
96
|
+
await _workflow.writeWorkflowDir(resp.data, dirContext);
|
|
97
|
+
const action = dirContext.exists ? "updated" : "created";
|
|
98
|
+
this.log(`‣ Successfully ${action} \`${dirContext.key}\` at ${dirContext.abspath}`);
|
|
99
|
+
}
|
|
100
|
+
async getWorkflowDirContext() {
|
|
101
|
+
const { workflowKey } = this.props.args;
|
|
102
|
+
const { resourceDir , cwd: runCwd } = this.runContext;
|
|
103
|
+
// Inside an existing resource dir, use it if valid for the target workflow.
|
|
104
|
+
if (resourceDir) {
|
|
105
|
+
const target = {
|
|
106
|
+
commandId: _baseCommand.default.id,
|
|
107
|
+
type: "workflow",
|
|
108
|
+
key: workflowKey
|
|
109
|
+
};
|
|
110
|
+
return (0, _dirContext.ensureResourceDirForTarget)(resourceDir, target);
|
|
111
|
+
}
|
|
112
|
+
// Not inside any existing workflow directory, which means either create a
|
|
113
|
+
// new worfklow directory in the cwd, or update it if there is one already.
|
|
114
|
+
if (workflowKey) {
|
|
115
|
+
const dirPath = _nodePath.resolve(runCwd, workflowKey);
|
|
116
|
+
const exists = await _workflow.isWorkflowDir(dirPath);
|
|
117
|
+
return {
|
|
118
|
+
type: "workflow",
|
|
119
|
+
key: workflowKey,
|
|
120
|
+
abspath: dirPath,
|
|
121
|
+
exists
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
// Not in any workflow directory, nor a workflow key arg was given so error.
|
|
125
|
+
return this.error("Missing 1 required arg:\nworkflowKey");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
WorkflowPull.flags = {
|
|
129
|
+
environment: _core.Flags.string({
|
|
130
|
+
default: "development"
|
|
131
|
+
}),
|
|
132
|
+
"hide-uncommitted-changes": _core.Flags.boolean()
|
|
133
|
+
};
|
|
134
|
+
WorkflowPull.args = [
|
|
135
|
+
{
|
|
136
|
+
name: "workflowKey",
|
|
137
|
+
required: false
|
|
138
|
+
}
|
|
139
|
+
];
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>WorkflowPush
|
|
8
|
+
});
|
|
9
|
+
const _nodePath = /*#__PURE__*/ _interopRequireWildcard(require("node:path"));
|
|
10
|
+
const _core = require("@oclif/core");
|
|
11
|
+
const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
|
|
12
|
+
const _dirContext = require("../../lib/helpers/dir-context");
|
|
13
|
+
const _error = require("../../lib/helpers/error");
|
|
14
|
+
const _object = require("../../lib/helpers/object");
|
|
15
|
+
const _request = require("../../lib/helpers/request");
|
|
16
|
+
const _workflow = /*#__PURE__*/ _interopRequireWildcard(require("../../lib/marshal/workflow"));
|
|
17
|
+
function _interopRequireDefault(obj) {
|
|
18
|
+
return obj && obj.__esModule ? obj : {
|
|
19
|
+
default: obj
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
23
|
+
if (typeof WeakMap !== "function") return null;
|
|
24
|
+
var cacheBabelInterop = new WeakMap();
|
|
25
|
+
var cacheNodeInterop = new WeakMap();
|
|
26
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
27
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
28
|
+
})(nodeInterop);
|
|
29
|
+
}
|
|
30
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
31
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
35
|
+
return {
|
|
36
|
+
default: obj
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
40
|
+
if (cache && cache.has(obj)) {
|
|
41
|
+
return cache.get(obj);
|
|
42
|
+
}
|
|
43
|
+
var newObj = {};
|
|
44
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
45
|
+
for(var key in obj){
|
|
46
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
47
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
48
|
+
if (desc && (desc.get || desc.set)) {
|
|
49
|
+
Object.defineProperty(newObj, key, desc);
|
|
50
|
+
} else {
|
|
51
|
+
newObj[key] = obj[key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
newObj.default = obj;
|
|
56
|
+
if (cache) {
|
|
57
|
+
cache.set(obj, newObj);
|
|
58
|
+
}
|
|
59
|
+
return newObj;
|
|
60
|
+
}
|
|
61
|
+
class WorkflowPush extends _baseCommand.default {
|
|
62
|
+
async run() {
|
|
63
|
+
// 1. Retrieve the target workflow directory context.
|
|
64
|
+
const dirContext = await this.getWorkflowDirContext();
|
|
65
|
+
this.log(`‣ Reading \`${dirContext.key}\` at ${dirContext.abspath}`);
|
|
66
|
+
// 2. Read the workflow.json with its template files.
|
|
67
|
+
const [workflow, errors] = await _workflow.readWorkflowDir(dirContext, {
|
|
68
|
+
withTemplateFiles: true
|
|
69
|
+
});
|
|
70
|
+
if (errors.length > 0) {
|
|
71
|
+
this.error(`Found the following errors in \`${dirContext.key}\` ${_workflow.WORKFLOW_JSON}\n\n` + (0, _error.formatErrors)(errors));
|
|
72
|
+
}
|
|
73
|
+
// 3. Push up the compiled workflow data.
|
|
74
|
+
const resp = await (0, _request.withSpinner)(()=>{
|
|
75
|
+
const props = (0, _object.merge)(this.props, {
|
|
76
|
+
args: {
|
|
77
|
+
workflowKey: dirContext.key
|
|
78
|
+
},
|
|
79
|
+
flags: {
|
|
80
|
+
annotate: true
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return this.apiV1.upsertWorkflow(props, workflow);
|
|
84
|
+
});
|
|
85
|
+
// 4. Update the workflow directory with the successfully pushed workflow
|
|
86
|
+
// payload from the server.
|
|
87
|
+
await _workflow.writeWorkflowDir(resp.data.workflow, dirContext);
|
|
88
|
+
this.log(`‣ Successfully pushed \`${dirContext.key}\`, and updated ${dirContext.abspath}`);
|
|
89
|
+
}
|
|
90
|
+
async getWorkflowDirContext() {
|
|
91
|
+
const { workflowKey } = this.props.args;
|
|
92
|
+
const { resourceDir , cwd: runCwd } = this.runContext;
|
|
93
|
+
if (resourceDir) {
|
|
94
|
+
const target = {
|
|
95
|
+
commandId: _baseCommand.default.id,
|
|
96
|
+
type: "workflow",
|
|
97
|
+
key: workflowKey
|
|
98
|
+
};
|
|
99
|
+
return (0, _dirContext.ensureResourceDirForTarget)(resourceDir, target);
|
|
100
|
+
}
|
|
101
|
+
if (workflowKey) {
|
|
102
|
+
const dirPath = _nodePath.resolve(runCwd, workflowKey);
|
|
103
|
+
const exists = await _workflow.isWorkflowDir(dirPath);
|
|
104
|
+
return exists ? {
|
|
105
|
+
type: "workflow",
|
|
106
|
+
key: workflowKey,
|
|
107
|
+
abspath: dirPath,
|
|
108
|
+
exists
|
|
109
|
+
} : this.error(`Cannot locate a workflow directory for \`${workflowKey}\``);
|
|
110
|
+
}
|
|
111
|
+
return this.error("Missing 1 required arg:\nworkflowKey");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
WorkflowPush.flags = {
|
|
115
|
+
// TODO: Maybe make environments into an enum.
|
|
116
|
+
environment: _core.Flags.string({
|
|
117
|
+
default: "development",
|
|
118
|
+
options: [
|
|
119
|
+
"development"
|
|
120
|
+
]
|
|
121
|
+
})
|
|
122
|
+
};
|
|
123
|
+
WorkflowPush.args = [
|
|
124
|
+
{
|
|
125
|
+
name: "workflowKey",
|
|
126
|
+
required: false
|
|
127
|
+
}
|
|
128
|
+
];
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>ApiV1
|
|
8
|
+
});
|
|
9
|
+
const _axios = /*#__PURE__*/ _interopRequireDefault(require("axios"));
|
|
10
|
+
const _object = require("./helpers/object");
|
|
11
|
+
const _page = require("./helpers/page");
|
|
12
|
+
function _interopRequireDefault(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const DEFAULT_ORIGIN = "https://control.knock.app";
|
|
18
|
+
const API_VERSION = "v1";
|
|
19
|
+
class ApiV1 {
|
|
20
|
+
// By resources:
|
|
21
|
+
async ping() {
|
|
22
|
+
return this.get("/ping");
|
|
23
|
+
}
|
|
24
|
+
async listWorkflows({ flags }) {
|
|
25
|
+
const params = (0, _object.prune)({
|
|
26
|
+
environment: flags.environment,
|
|
27
|
+
annotate: flags.annotate,
|
|
28
|
+
hide_uncommitted_changes: flags["hide-uncommitted-changes"],
|
|
29
|
+
...(0, _page.toPageParams)(flags)
|
|
30
|
+
});
|
|
31
|
+
return this.get("/workflows", {
|
|
32
|
+
params
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async getWorkflow({ args , flags }) {
|
|
36
|
+
const params = (0, _object.prune)({
|
|
37
|
+
environment: flags.environment,
|
|
38
|
+
annotate: flags.annotate,
|
|
39
|
+
hide_uncommitted_changes: flags["hide-uncommitted-changes"]
|
|
40
|
+
});
|
|
41
|
+
return this.get(`/workflows/${args.workflowKey}`, {
|
|
42
|
+
params
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async upsertWorkflow({ args , flags }, workflow) {
|
|
46
|
+
const params = (0, _object.prune)({
|
|
47
|
+
environment: flags.environment,
|
|
48
|
+
annotate: flags.annotate
|
|
49
|
+
});
|
|
50
|
+
const data = {
|
|
51
|
+
workflow
|
|
52
|
+
};
|
|
53
|
+
return this.put(`/workflows/${args.workflowKey}`, data, {
|
|
54
|
+
params
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// By methods:
|
|
58
|
+
async get(subpath, config) {
|
|
59
|
+
return this.client.get(`/${API_VERSION}` + subpath, config);
|
|
60
|
+
}
|
|
61
|
+
async put(subpath, data, config) {
|
|
62
|
+
return this.client.put(`/${API_VERSION}` + subpath, data, config);
|
|
63
|
+
}
|
|
64
|
+
constructor(flags, config){
|
|
65
|
+
const baseURL = flags["api-origin"] || DEFAULT_ORIGIN;
|
|
66
|
+
this.client = _axios.default.create({
|
|
67
|
+
baseURL,
|
|
68
|
+
headers: {
|
|
69
|
+
Authorization: `Bearer ${flags["service-token"]}`,
|
|
70
|
+
"User-Agent": `${config.userAgent}`
|
|
71
|
+
},
|
|
72
|
+
// Don't reject the promise based on a response status code.
|
|
73
|
+
validateStatus: null
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>_default
|
|
8
|
+
});
|
|
9
|
+
const _core = require("@oclif/core");
|
|
10
|
+
const _apiV1 = /*#__PURE__*/ _interopRequireDefault(require("./api-v1"));
|
|
11
|
+
const _runContext = /*#__PURE__*/ _interopRequireWildcard(require("./run-context"));
|
|
12
|
+
const _userConfig = /*#__PURE__*/ _interopRequireDefault(require("./user-config"));
|
|
13
|
+
function _interopRequireDefault(obj) {
|
|
14
|
+
return obj && obj.__esModule ? obj : {
|
|
15
|
+
default: obj
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
19
|
+
if (typeof WeakMap !== "function") return null;
|
|
20
|
+
var cacheBabelInterop = new WeakMap();
|
|
21
|
+
var cacheNodeInterop = new WeakMap();
|
|
22
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
23
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
24
|
+
})(nodeInterop);
|
|
25
|
+
}
|
|
26
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
27
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
31
|
+
return {
|
|
32
|
+
default: obj
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
36
|
+
if (cache && cache.has(obj)) {
|
|
37
|
+
return cache.get(obj);
|
|
38
|
+
}
|
|
39
|
+
var newObj = {};
|
|
40
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
41
|
+
for(var key in obj){
|
|
42
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
43
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
44
|
+
if (desc && (desc.get || desc.set)) {
|
|
45
|
+
Object.defineProperty(newObj, key, desc);
|
|
46
|
+
} else {
|
|
47
|
+
newObj[key] = obj[key];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
newObj.default = obj;
|
|
52
|
+
if (cache) {
|
|
53
|
+
cache.set(obj, newObj);
|
|
54
|
+
}
|
|
55
|
+
return newObj;
|
|
56
|
+
}
|
|
57
|
+
class BaseCommand extends _core.Command {
|
|
58
|
+
async init() {
|
|
59
|
+
await super.init();
|
|
60
|
+
// 1. Load user's config from the config dir, as available.
|
|
61
|
+
await _userConfig.default.load(this.config.configDir);
|
|
62
|
+
// 2. Parse flags and args, must come after the user config load.
|
|
63
|
+
this.props = await this.parse(this.constructor);
|
|
64
|
+
// 3. Instantiate a knock api client.
|
|
65
|
+
this.apiV1 = new _apiV1.default(this.props.flags, this.config);
|
|
66
|
+
// 4. Load the run context of the invoked command.
|
|
67
|
+
this.runContext = await _runContext.load();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Global flags are inherited by any command that extends BaseCommand.
|
|
71
|
+
BaseCommand.globalFlags = {
|
|
72
|
+
// Evaluated in the following precedence:
|
|
73
|
+
// - service token flag passed into the command
|
|
74
|
+
// - if not provided, fall back to env variable
|
|
75
|
+
// - if not available, fall back to user config
|
|
76
|
+
"service-token": _core.Flags.string({
|
|
77
|
+
summary: "service token to authenticate with",
|
|
78
|
+
required: true,
|
|
79
|
+
multiple: false,
|
|
80
|
+
env: "KNOCK_SERVICE_TOKEN",
|
|
81
|
+
default: async ()=>_userConfig.default.get().serviceToken
|
|
82
|
+
}),
|
|
83
|
+
// Hidden flag to use a different api base url for development purposes.
|
|
84
|
+
"api-origin": _core.Flags.string({
|
|
85
|
+
hidden: true,
|
|
86
|
+
required: false,
|
|
87
|
+
multiple: false,
|
|
88
|
+
default: async ()=>_userConfig.default.get().apiOrigin
|
|
89
|
+
})
|
|
90
|
+
};
|
|
91
|
+
const _default = BaseCommand;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
formatDate: ()=>formatDate,
|
|
13
|
+
formatDateTime: ()=>formatDateTime
|
|
14
|
+
});
|
|
15
|
+
const _dateFns = require("date-fns");
|
|
16
|
+
function formatDate(input) {
|
|
17
|
+
return (0, _dateFns.format)((0, _dateFns.parseISO)(input), "MMM d, yyyy");
|
|
18
|
+
}
|
|
19
|
+
function formatDateTime(input) {
|
|
20
|
+
return (0, _dateFns.format)((0, _dateFns.parseISO)(input), "MMM d, yyyy HH:mm:ss");
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ensureResourceDirForTarget", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>ensureResourceDirForTarget
|
|
8
|
+
});
|
|
9
|
+
const _core = require("@oclif/core");
|
|
10
|
+
const ensureResourceDirForTarget = (resourceDirCtx, target)=>{
|
|
11
|
+
switch(target.commandId){
|
|
12
|
+
case "workflow:pull":
|
|
13
|
+
break;
|
|
14
|
+
default:
|
|
15
|
+
throw new Error(`Unhandled commandId: ${target.commandId}`);
|
|
16
|
+
}
|
|
17
|
+
// If the target resource is a different type than the current resource dir
|
|
18
|
+
// type, error out.
|
|
19
|
+
if (resourceDirCtx.type !== target.type) {
|
|
20
|
+
return _core.CliUx.ux.error(`Cannot run ${target.commandId} inside a ${resourceDirCtx.type} directory`);
|
|
21
|
+
}
|
|
22
|
+
// If the resource key was not procided with the command, then infer from the
|
|
23
|
+
// current resource directory context.
|
|
24
|
+
if (!target.key) {
|
|
25
|
+
return resourceDirCtx;
|
|
26
|
+
}
|
|
27
|
+
// If the resource key was provided and matches the current workflow dir
|
|
28
|
+
// context, then use the current resource directory context; otherwise, error.
|
|
29
|
+
if (target.key === resourceDirCtx.key) {
|
|
30
|
+
return resourceDirCtx;
|
|
31
|
+
}
|
|
32
|
+
return _core.CliUx.ux.error(`Cannot run ${target.commandId} \`${target.key}\` inside another ${resourceDirCtx.type} directory:\n${resourceDirCtx.key}`);
|
|
33
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
isTestEnv: ()=>isTestEnv,
|
|
13
|
+
sandboxDir: ()=>sandboxDir
|
|
14
|
+
});
|
|
15
|
+
const _nodeOs = /*#__PURE__*/ _interopRequireDefault(require("node:os"));
|
|
16
|
+
const _nodePath = /*#__PURE__*/ _interopRequireWildcard(require("node:path"));
|
|
17
|
+
const _fsExtra = /*#__PURE__*/ _interopRequireWildcard(require("fs-extra"));
|
|
18
|
+
function _interopRequireDefault(obj) {
|
|
19
|
+
return obj && obj.__esModule ? obj : {
|
|
20
|
+
default: obj
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
24
|
+
if (typeof WeakMap !== "function") return null;
|
|
25
|
+
var cacheBabelInterop = new WeakMap();
|
|
26
|
+
var cacheNodeInterop = new WeakMap();
|
|
27
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
28
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
29
|
+
})(nodeInterop);
|
|
30
|
+
}
|
|
31
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
32
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
33
|
+
return obj;
|
|
34
|
+
}
|
|
35
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
36
|
+
return {
|
|
37
|
+
default: obj
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
41
|
+
if (cache && cache.has(obj)) {
|
|
42
|
+
return cache.get(obj);
|
|
43
|
+
}
|
|
44
|
+
var newObj = {};
|
|
45
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
46
|
+
for(var key in obj){
|
|
47
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
48
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
49
|
+
if (desc && (desc.get || desc.set)) {
|
|
50
|
+
Object.defineProperty(newObj, key, desc);
|
|
51
|
+
} else {
|
|
52
|
+
newObj[key] = obj[key];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
newObj.default = obj;
|
|
57
|
+
if (cache) {
|
|
58
|
+
cache.set(obj, newObj);
|
|
59
|
+
}
|
|
60
|
+
return newObj;
|
|
61
|
+
}
|
|
62
|
+
const isTestEnv = process.env.NODE_ENV === "test";
|
|
63
|
+
const sandboxDir = _nodePath.resolve(_fsExtra.realpathSync(_nodeOs.default.tmpdir()), ".knock");
|