@prismatic-io/prism 3.3.0 → 4.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/bin/run +9 -8
- package/lib/auth.js +183 -201
- package/lib/commands/alerts/events/list.js +27 -57
- package/lib/commands/alerts/groups/create.js +18 -49
- package/lib/commands/alerts/groups/delete.js +10 -41
- package/lib/commands/alerts/groups/list.js +15 -47
- package/lib/commands/alerts/monitors/clear.js +10 -41
- package/lib/commands/alerts/monitors/create.js +27 -58
- package/lib/commands/alerts/monitors/delete.js +10 -41
- package/lib/commands/alerts/monitors/list.js +16 -48
- package/lib/commands/alerts/triggers/list.js +15 -47
- package/lib/commands/alerts/webhooks/create.js +18 -49
- package/lib/commands/alerts/webhooks/delete.js +10 -41
- package/lib/commands/alerts/webhooks/list.js +25 -57
- package/lib/commands/authorization-methods/list.js +20 -51
- package/lib/commands/components/actions/list.js +29 -61
- package/lib/commands/components/delete.js +10 -41
- package/lib/commands/components/dev/run.js +89 -0
- package/lib/commands/components/dev/test.js +218 -0
- package/lib/commands/components/init/action.js +12 -0
- package/lib/commands/components/init/component.js +12 -0
- package/lib/commands/components/init/connection.js +12 -0
- package/lib/commands/components/init/index.js +142 -0
- package/lib/commands/components/init/trigger.js +12 -0
- package/lib/commands/components/list.js +31 -60
- package/lib/commands/components/publish.js +29 -279
- package/lib/commands/components/triggers/list.js +29 -61
- package/lib/commands/customers/create.js +14 -45
- package/lib/commands/customers/credentials/create.js +19 -50
- package/lib/commands/customers/credentials/delete.js +10 -41
- package/lib/commands/customers/credentials/list.js +30 -59
- package/lib/commands/customers/credentials/update.js +16 -47
- package/lib/commands/customers/delete.js +10 -41
- package/lib/commands/customers/list.js +16 -48
- package/lib/commands/customers/update.js +15 -46
- package/lib/commands/customers/users/create.js +18 -49
- package/lib/commands/customers/users/delete.js +10 -41
- package/lib/commands/customers/users/list.js +21 -51
- package/lib/commands/customers/users/roles.js +18 -48
- package/lib/commands/customers/users/update.js +19 -50
- package/lib/commands/executions/step-result/get.js +36 -66
- package/lib/commands/instances/config-vars/list.js +32 -62
- package/lib/commands/instances/create.js +20 -51
- package/lib/commands/instances/delete.js +10 -41
- package/lib/commands/instances/deploy.js +20 -44
- package/lib/commands/instances/disable.js +11 -42
- package/lib/commands/instances/enable.js +11 -42
- package/lib/commands/instances/flow-configs/list.js +25 -55
- package/lib/commands/instances/flow-configs/test.js +62 -97
- package/lib/commands/instances/list.js +31 -59
- package/lib/commands/instances/update.js +15 -46
- package/lib/commands/integrations/available.js +13 -44
- package/lib/commands/integrations/create.js +14 -45
- package/lib/commands/integrations/delete.js +10 -41
- package/lib/commands/integrations/export.js +11 -68
- package/lib/commands/integrations/flows/list.js +22 -52
- package/lib/commands/integrations/flows/test.js +62 -96
- package/lib/commands/integrations/fork.js +15 -46
- package/lib/commands/integrations/import.js +12 -63
- package/lib/commands/integrations/list.js +25 -54
- package/lib/commands/integrations/publish.js +13 -44
- package/lib/commands/integrations/update.js +18 -49
- package/lib/commands/integrations/versions/index.js +26 -58
- package/lib/commands/login.js +16 -32
- package/lib/commands/logout.js +10 -22
- package/lib/commands/logs/severities/list.js +15 -47
- package/lib/commands/me/index.js +15 -60
- package/lib/commands/me/token/revoke.js +12 -0
- package/lib/commands/me/token.js +10 -22
- package/lib/commands/organization/credentials/create.js +17 -48
- package/lib/commands/organization/credentials/delete.js +10 -41
- package/lib/commands/organization/credentials/list.js +22 -54
- package/lib/commands/organization/credentials/update.js +16 -47
- package/lib/commands/organization/update.js +12 -43
- package/lib/commands/organization/updateAvatarUrl.js +14 -45
- package/lib/commands/organization/users/create.js +16 -47
- package/lib/commands/organization/users/delete.js +10 -41
- package/lib/commands/organization/users/list.js +16 -48
- package/lib/commands/organization/users/roles.js +18 -48
- package/lib/commands/organization/users/update.js +19 -50
- package/lib/config.js +24 -30
- package/lib/errors.js +48 -27
- package/lib/fields.js +6 -4
- package/lib/fs.js +6 -14
- package/lib/generate/action.js +43 -100
- package/lib/generate/index.js +27 -23
- package/lib/generate/input.js +28 -43
- package/lib/generate/parse.js +18 -76
- package/lib/generate/sourceFile.js +15 -44
- package/lib/generate/util.js +4 -106
- package/lib/graphql.js +37 -65
- package/lib/index.js +3 -3
- package/lib/utils/component/publish.js +219 -0
- package/lib/utils/component/query.js +23 -0
- package/lib/utils/date.js +14 -0
- package/lib/utils/execution/logs.js +86 -0
- package/lib/utils/integration/definition.js +101 -0
- package/lib/utils/integration/export.js +36 -0
- package/lib/utils/integration/import.js +46 -0
- package/lib/utils/integration/invoke.js +64 -0
- package/lib/utils/integration/query.js +59 -0
- package/lib/utils/serialize.js +8 -0
- package/lib/utils/user/query.js +24 -0
- package/lib/yeoman.js +24 -0
- package/oclif.manifest.json +1 -1
- package/package.json +50 -58
- package/lib/auth.js.map +0 -1
- package/lib/commands/alerts/events/list.js.map +0 -1
- package/lib/commands/alerts/groups/create.js.map +0 -1
- package/lib/commands/alerts/groups/delete.js.map +0 -1
- package/lib/commands/alerts/groups/list.js.map +0 -1
- package/lib/commands/alerts/monitors/clear.js.map +0 -1
- package/lib/commands/alerts/monitors/create.js.map +0 -1
- package/lib/commands/alerts/monitors/delete.js.map +0 -1
- package/lib/commands/alerts/monitors/list.js.map +0 -1
- package/lib/commands/alerts/triggers/list.js.map +0 -1
- package/lib/commands/alerts/webhooks/create.js.map +0 -1
- package/lib/commands/alerts/webhooks/delete.js.map +0 -1
- package/lib/commands/alerts/webhooks/list.js.map +0 -1
- package/lib/commands/authorization-methods/list.js.map +0 -1
- package/lib/commands/components/actions/list.js.map +0 -1
- package/lib/commands/components/delete.js.map +0 -1
- package/lib/commands/components/init.js +0 -224
- package/lib/commands/components/init.js.map +0 -1
- package/lib/commands/components/list.js.map +0 -1
- package/lib/commands/components/publish.js.map +0 -1
- package/lib/commands/components/triggers/list.js.map +0 -1
- package/lib/commands/customers/create.js.map +0 -1
- package/lib/commands/customers/credentials/create.js.map +0 -1
- package/lib/commands/customers/credentials/delete.js.map +0 -1
- package/lib/commands/customers/credentials/list.js.map +0 -1
- package/lib/commands/customers/credentials/update.js.map +0 -1
- package/lib/commands/customers/delete.js.map +0 -1
- package/lib/commands/customers/list.js.map +0 -1
- package/lib/commands/customers/update.js.map +0 -1
- package/lib/commands/customers/users/create.js.map +0 -1
- package/lib/commands/customers/users/delete.js.map +0 -1
- package/lib/commands/customers/users/list.js.map +0 -1
- package/lib/commands/customers/users/roles.js.map +0 -1
- package/lib/commands/customers/users/update.js.map +0 -1
- package/lib/commands/executions/step-result/get.js.map +0 -1
- package/lib/commands/instances/config-vars/list.js.map +0 -1
- package/lib/commands/instances/create.js.map +0 -1
- package/lib/commands/instances/delete.js.map +0 -1
- package/lib/commands/instances/deploy.js.map +0 -1
- package/lib/commands/instances/disable.js.map +0 -1
- package/lib/commands/instances/enable.js.map +0 -1
- package/lib/commands/instances/flow-configs/list.js.map +0 -1
- package/lib/commands/instances/flow-configs/test.js.map +0 -1
- package/lib/commands/instances/list.js.map +0 -1
- package/lib/commands/instances/update.js.map +0 -1
- package/lib/commands/integrations/available.js.map +0 -1
- package/lib/commands/integrations/create.js.map +0 -1
- package/lib/commands/integrations/delete.js.map +0 -1
- package/lib/commands/integrations/export.js.map +0 -1
- package/lib/commands/integrations/flows/list.js.map +0 -1
- package/lib/commands/integrations/flows/test.js.map +0 -1
- package/lib/commands/integrations/fork.js.map +0 -1
- package/lib/commands/integrations/import.js.map +0 -1
- package/lib/commands/integrations/list.js.map +0 -1
- package/lib/commands/integrations/publish.js.map +0 -1
- package/lib/commands/integrations/update.js.map +0 -1
- package/lib/commands/integrations/versions/index.js.map +0 -1
- package/lib/commands/login.js.map +0 -1
- package/lib/commands/logout.js.map +0 -1
- package/lib/commands/logs/severities/list.js.map +0 -1
- package/lib/commands/me/index.js.map +0 -1
- package/lib/commands/me/token.js.map +0 -1
- package/lib/commands/organization/credentials/create.js.map +0 -1
- package/lib/commands/organization/credentials/delete.js.map +0 -1
- package/lib/commands/organization/credentials/list.js.map +0 -1
- package/lib/commands/organization/credentials/update.js.map +0 -1
- package/lib/commands/organization/update.js.map +0 -1
- package/lib/commands/organization/updateAvatarUrl.js.map +0 -1
- package/lib/commands/organization/users/create.js.map +0 -1
- package/lib/commands/organization/users/delete.js.map +0 -1
- package/lib/commands/organization/users/list.js.map +0 -1
- package/lib/commands/organization/users/roles.js.map +0 -1
- package/lib/commands/organization/users/update.js.map +0 -1
- package/lib/config.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/fields.js.map +0 -1
- package/lib/fs.js.map +0 -1
- package/lib/generate/action.js.map +0 -1
- package/lib/generate/client.js +0 -98
- package/lib/generate/client.js.map +0 -1
- package/lib/generate/connection.js +0 -86
- package/lib/generate/connection.js.map +0 -1
- package/lib/generate/index.js.map +0 -1
- package/lib/generate/input.js.map +0 -1
- package/lib/generate/parse.js.map +0 -1
- package/lib/generate/sourceFile.js.map +0 -1
- package/lib/generate/util.js.map +0 -1
- package/lib/graphql.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/templates/component/assets/icon.png +0 -0
- package/templates/component/jest.config.js +0 -4
- package/templates/component/openapi/client.ts +0 -73
- package/templates/component/openapi/request.ts +0 -161
- package/templates/component/package.json +0 -24
- package/templates/component/src/actions.ts +0 -33
- package/templates/component/src/client.ts +0 -7
- package/templates/component/src/connections.ts +0 -25
- package/templates/component/src/index.test.ts +0 -32
- package/templates/component/src/index.ts +0 -17
- package/templates/component/src/triggers.ts +0 -18
- package/templates/component/tsconfig.json +0 -19
- package/templates/component/webpack.config.js +0 -44
package/lib/generate/util.js
CHANGED
|
@@ -3,117 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.createDescription = void 0;
|
|
7
7
|
const striptags_1 = __importDefault(require("striptags"));
|
|
8
|
-
const
|
|
9
|
-
exports.createDescription = (text) => {
|
|
8
|
+
const createDescription = (text) => {
|
|
10
9
|
if (!text) {
|
|
11
10
|
return "";
|
|
12
11
|
}
|
|
13
|
-
const strippedText = striptags_1.default(text);
|
|
12
|
+
const strippedText = (0, striptags_1.default)(text);
|
|
14
13
|
const [nonEmptyLine] = strippedText.split("\n").filter((t) => t.trim() != "");
|
|
15
14
|
const [fragment] = nonEmptyLine.split(/[.!?]/g);
|
|
16
15
|
return fragment.replace(/`/g, "'");
|
|
17
16
|
};
|
|
18
|
-
|
|
19
|
-
const placeholder = inputsFile.addVariableStatement({
|
|
20
|
-
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
21
|
-
declarations: [
|
|
22
|
-
{ name: "genericActionInput", initializer: ts_morph_1.Writers.object({}) },
|
|
23
|
-
],
|
|
24
|
-
});
|
|
25
|
-
const object = placeholder.getDeclarations()[0].getInitializer();
|
|
26
|
-
object.addPropertyAssignments(propertyList);
|
|
27
|
-
inputsFile.addVariableStatement({
|
|
28
|
-
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
29
|
-
isExported: true,
|
|
30
|
-
declarations: [
|
|
31
|
-
{ name: inputName, initializer: `input(${object.print()})` },
|
|
32
|
-
],
|
|
33
|
-
});
|
|
34
|
-
placeholder.remove();
|
|
35
|
-
};
|
|
36
|
-
exports.addRequiredInputs = (projectType, inputsFile, addRetry) => {
|
|
37
|
-
addProperty(inputsFile, "apiBaseUrl", [
|
|
38
|
-
{ name: `"label"`, initializer: `"API Base URL"` },
|
|
39
|
-
{ name: `"type"`, initializer: `"string"` },
|
|
40
|
-
{ name: `"required"`, initializer: `false` },
|
|
41
|
-
{
|
|
42
|
-
name: `"comments"`,
|
|
43
|
-
initializer: `"An optional url you can specify to overide the default provided by the OpenAPI spec."`,
|
|
44
|
-
},
|
|
45
|
-
]);
|
|
46
|
-
addProperty(inputsFile, "debugRequest", [
|
|
47
|
-
{ name: `"label"`, initializer: `"Debug Request"` },
|
|
48
|
-
{ name: `"type"`, initializer: `"boolean"` },
|
|
49
|
-
{ name: `"required"`, initializer: `false` },
|
|
50
|
-
{
|
|
51
|
-
name: `"comments"`,
|
|
52
|
-
initializer: `"An optional boolean you can toggle to log the contents of the HTTP request for each action."`,
|
|
53
|
-
},
|
|
54
|
-
]);
|
|
55
|
-
addProperty(inputsFile, "timeout", [
|
|
56
|
-
{ name: `"label"`, initializer: `"Timeout"` },
|
|
57
|
-
{ name: `"type"`, initializer: `"string"` },
|
|
58
|
-
{ name: `"required"`, initializer: `false` },
|
|
59
|
-
{
|
|
60
|
-
name: `"comments"`,
|
|
61
|
-
initializer: `"An optional input that indicates how long the client will await a response."`,
|
|
62
|
-
},
|
|
63
|
-
]);
|
|
64
|
-
if (addRetry) {
|
|
65
|
-
addProperty(inputsFile, "maxRetries", [
|
|
66
|
-
{ name: `"label"`, initializer: `"Max Retries"` },
|
|
67
|
-
{ name: `"type"`, initializer: `"string"` },
|
|
68
|
-
{ name: `"required"`, initializer: `false` },
|
|
69
|
-
{
|
|
70
|
-
name: `"comments"`,
|
|
71
|
-
initializer: `"An optional input that indicates how many times this client will retry the request."`,
|
|
72
|
-
},
|
|
73
|
-
]);
|
|
74
|
-
addProperty(inputsFile, "retryDelayMS", [
|
|
75
|
-
{ name: `"label"`, initializer: `"Retry Delay (MS)"` },
|
|
76
|
-
{ name: `"type"`, initializer: `"string"` },
|
|
77
|
-
{ name: `"required"`, initializer: `false` },
|
|
78
|
-
{
|
|
79
|
-
name: `"comments"`,
|
|
80
|
-
initializer: `"An optional input that indicates a delay between retries."`,
|
|
81
|
-
},
|
|
82
|
-
]);
|
|
83
|
-
addProperty(inputsFile, "retryOnAllErrors", [
|
|
84
|
-
{ name: `"label"`, initializer: `"Retry On All Errors"` },
|
|
85
|
-
{ name: `"type"`, initializer: `"boolean"` },
|
|
86
|
-
{ name: `"required"`, initializer: `false` },
|
|
87
|
-
{
|
|
88
|
-
name: `"comments"`,
|
|
89
|
-
initializer: `"An optional boolean that will have the client retry the request, reguardless of what type of error is thrown."`,
|
|
90
|
-
},
|
|
91
|
-
]);
|
|
92
|
-
addProperty(inputsFile, "useExponentialBackoff", [
|
|
93
|
-
{ name: `"label"`, initializer: `"Use Exponential Backoff"` },
|
|
94
|
-
{ name: `"type"`, initializer: `"boolean"` },
|
|
95
|
-
{ name: `"required"`, initializer: `false` },
|
|
96
|
-
{
|
|
97
|
-
name: `"comments"`,
|
|
98
|
-
initializer: `"An optional boolean that will enable exponential backoff on retry."`,
|
|
99
|
-
},
|
|
100
|
-
]);
|
|
101
|
-
}
|
|
102
|
-
return inputsFile;
|
|
103
|
-
};
|
|
104
|
-
exports.appendRequiredFields = ({ inputFields, addRetry, includeClient, }) => {
|
|
105
|
-
if (!includeClient) {
|
|
106
|
-
return inputFields;
|
|
107
|
-
}
|
|
108
|
-
const base = [...inputFields, "apiBaseUrl", "debugRequest", "timeout"];
|
|
109
|
-
return addRetry
|
|
110
|
-
? [
|
|
111
|
-
...base,
|
|
112
|
-
"maxRetries",
|
|
113
|
-
"retryDelayMS",
|
|
114
|
-
"retryOnAllErrors",
|
|
115
|
-
"useExponentialBackoff",
|
|
116
|
-
]
|
|
117
|
-
: base;
|
|
118
|
-
};
|
|
119
|
-
//# sourceMappingURL=util.js.map
|
|
17
|
+
exports.createDescription = createDescription;
|
package/lib/graphql.js
CHANGED
|
@@ -1,70 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
var _a;
|
|
15
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.gql = exports.
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const apollo_link_1 = require("apollo-link");
|
|
20
|
-
const apollo_link_context_1 = require("apollo-link-context");
|
|
21
|
-
const apollo_link_http_1 = require("apollo-link-http");
|
|
22
|
-
const apollo_cache_inmemory_1 = require("apollo-cache-inmemory");
|
|
23
|
-
const graphql_utils_1 = require("@prismatic-io/graphql-utils");
|
|
3
|
+
exports.gql = exports.gqlRequest = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
5
|
+
const graphql_request_1 = require("graphql-request");
|
|
24
6
|
const auth_1 = require("./auth");
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
7
|
+
const isErrored = (result) => {
|
|
8
|
+
if (!(Boolean(result) &&
|
|
9
|
+
typeof result === "object" &&
|
|
10
|
+
result !== null &&
|
|
11
|
+
"errors" in result)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const assumed = result;
|
|
15
|
+
return Boolean(assumed.errors) && assumed.errors.length > 0;
|
|
16
|
+
};
|
|
17
|
+
const formatError = (field, messages) => {
|
|
18
|
+
const message = messages.join("\n");
|
|
19
|
+
if (field === "__all__") {
|
|
20
|
+
return message;
|
|
21
|
+
}
|
|
22
|
+
return `${field}: ${message}`;
|
|
23
|
+
};
|
|
24
|
+
const gqlRequest = async ({ document, variables, }) => {
|
|
25
|
+
const accessToken = await (0, auth_1.getAccessToken)();
|
|
26
|
+
const url = new url_1.URL("/api", auth_1.prismaticUrl).toString();
|
|
27
|
+
const result = await (0, graphql_request_1.request)(url, document, variables, {
|
|
28
|
+
Authorization: `Bearer ${accessToken}`,
|
|
29
|
+
"Prismatic-Client": "prism",
|
|
30
|
+
});
|
|
31
|
+
const errors = Object.values(result)
|
|
32
|
+
.filter(isErrored)
|
|
33
|
+
.flatMap(({ errors }) => errors)
|
|
34
|
+
.map(({ field, messages }) => formatError(field, messages));
|
|
44
35
|
if (errors.length > 0) {
|
|
45
|
-
errors.
|
|
46
|
-
const label = !field || field === "__all__" ? "Error" : field;
|
|
47
|
-
console.error(`${label}: ${message}`);
|
|
48
|
-
});
|
|
49
|
-
process.exit(1);
|
|
36
|
+
throw new Error(errors.join("\n"));
|
|
50
37
|
}
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// FIXME: What should this actually be...? ALB requires it for HTTPS calls.
|
|
57
|
-
Referer: prismaticUri,
|
|
58
|
-
},
|
|
59
|
-
fetch: node_fetch_1.default,
|
|
60
|
-
});
|
|
61
|
-
exports.unauthedClient = new apollo_client_1.ApolloClient({
|
|
62
|
-
link: grapheneErrorLink.concat(httpLink),
|
|
63
|
-
cache: new apollo_cache_inmemory_1.InMemoryCache(),
|
|
64
|
-
});
|
|
65
|
-
exports.client = new apollo_client_1.ApolloClient({
|
|
66
|
-
link: authContext.concat(grapheneErrorLink).concat(httpLink),
|
|
67
|
-
cache: new apollo_cache_inmemory_1.InMemoryCache(),
|
|
68
|
-
});
|
|
69
|
-
exports.default = exports.client;
|
|
70
|
-
//# sourceMappingURL=graphql.js.map
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
exports.gqlRequest = gqlRequest;
|
|
41
|
+
var graphql_request_2 = require("graphql-request");
|
|
42
|
+
Object.defineProperty(exports, "gql", { enumerable: true, get: function () { return graphql_request_2.gql; } });
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.run = void 0;
|
|
4
|
+
var core_1 = require("@oclif/core");
|
|
5
|
+
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.uploadConnectionIcons = exports.uploadFile = exports.publishDefinition = exports.confirmPublish = exports.checkSignature = exports.createComponentPackage = exports.validateDefinition = exports.loadEntrypoint = exports.seekComponentPackageDistDirectory = void 0;
|
|
7
|
+
const core_1 = require("@oclif/core");
|
|
8
|
+
const fs_1 = require("../../fs");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const tempy_1 = __importDefault(require("tempy"));
|
|
11
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
12
|
+
const archiver_1 = __importDefault(require("archiver"));
|
|
13
|
+
const graphql_1 = require("../../graphql");
|
|
14
|
+
const axios_1 = __importDefault(require("axios"));
|
|
15
|
+
const mime_types_1 = __importDefault(require("mime-types"));
|
|
16
|
+
const path_2 = require("path");
|
|
17
|
+
const seekComponentPackageDistDirectory = async () => {
|
|
18
|
+
while (!(await (0, fs_1.exists)("package.json"))) {
|
|
19
|
+
const tempDir = process.cwd();
|
|
20
|
+
process.chdir("../");
|
|
21
|
+
if (process.cwd() == tempDir) {
|
|
22
|
+
core_1.CliUx.ux.error("Failed to find 'package.json' file. Is the current path a component?", { exit: 1 });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!(await (0, fs_1.exists)("./dist"))) {
|
|
26
|
+
core_1.CliUx.ux.error("Failed to find 'dist' folder. Is the current path a component?", {
|
|
27
|
+
exit: 1,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
process.chdir("./dist");
|
|
31
|
+
};
|
|
32
|
+
exports.seekComponentPackageDistDirectory = seekComponentPackageDistDirectory;
|
|
33
|
+
const loadEntrypoint = async () => {
|
|
34
|
+
// If we don't have an index.js in cwd seek directories to find package.json of component
|
|
35
|
+
if (!(await (0, fs_1.exists)("index.js"))) {
|
|
36
|
+
await (0, exports.seekComponentPackageDistDirectory)();
|
|
37
|
+
}
|
|
38
|
+
// If we still didn't find index.js error out
|
|
39
|
+
if (!(await (0, fs_1.exists)("index.js"))) {
|
|
40
|
+
core_1.CliUx.ux.error("Failed to find 'index.js' entrypoint file. Is the current path a component?", { exit: 1 });
|
|
41
|
+
}
|
|
42
|
+
// Require index.js and access its root-most default export which should be the Component config
|
|
43
|
+
const cwd = process.cwd();
|
|
44
|
+
const entrypointPath = (0, path_1.resolve)(cwd, "./index.js");
|
|
45
|
+
const { default: definition } = require(entrypointPath); // eslint-disable-line @typescript-eslint/no-var-requires
|
|
46
|
+
return definition;
|
|
47
|
+
};
|
|
48
|
+
exports.loadEntrypoint = loadEntrypoint;
|
|
49
|
+
const validateDefinition = async (definition) => {
|
|
50
|
+
// Output basic information to the user to confirm that this component is what they want to publish
|
|
51
|
+
const { display: { label, description, iconPath },
|
|
52
|
+
// connections,
|
|
53
|
+
} = definition;
|
|
54
|
+
if (!label || !description) {
|
|
55
|
+
core_1.CliUx.ux.error("Missing required values `label` or `description`. Exiting.", { exit: 1 });
|
|
56
|
+
}
|
|
57
|
+
if (iconPath && !(await (0, fs_1.exists)(iconPath))) {
|
|
58
|
+
core_1.CliUx.ux.error("Icon was specified (iconPath) but a file was not found at specified path. Exiting.", { exit: 1 });
|
|
59
|
+
}
|
|
60
|
+
// TODO: Check if all Connection icons exist.
|
|
61
|
+
};
|
|
62
|
+
exports.validateDefinition = validateDefinition;
|
|
63
|
+
const createComponentPackage = async () => {
|
|
64
|
+
const zip = (0, archiver_1.default)("zip", { zlib: { level: 9 } });
|
|
65
|
+
const pathPromise = tempy_1.default.write(zip, { extension: "zip" });
|
|
66
|
+
// Zip all files in the current directory (since we found the index.js entrypoint)
|
|
67
|
+
zip.directory(process.cwd(), false);
|
|
68
|
+
await zip.finalize();
|
|
69
|
+
return pathPromise;
|
|
70
|
+
};
|
|
71
|
+
exports.createComponentPackage = createComponentPackage;
|
|
72
|
+
const checkSignature = async ({ key }, packagePath) => {
|
|
73
|
+
// Retrieve the existing signature of the component if it exists.
|
|
74
|
+
const result = await (0, graphql_1.gqlRequest)({
|
|
75
|
+
document: (0, graphql_1.gql) `
|
|
76
|
+
query component($key: String!) {
|
|
77
|
+
components(key: $key) {
|
|
78
|
+
nodes {
|
|
79
|
+
signature
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
`,
|
|
84
|
+
variables: {
|
|
85
|
+
key,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
const { components: { nodes: [{ signature: existingSignature } = { signature: null }], }, } = result;
|
|
89
|
+
// Generate the signature of the package so we may compare it against the existing one.
|
|
90
|
+
const packageSignature = crypto_1.default
|
|
91
|
+
.createHash("sha1")
|
|
92
|
+
.update(await fs_1.fs.readFile(packagePath))
|
|
93
|
+
.digest("hex");
|
|
94
|
+
return existingSignature === packageSignature;
|
|
95
|
+
};
|
|
96
|
+
exports.checkSignature = checkSignature;
|
|
97
|
+
const confirmPublish = async ({ display: { label, description } }, confirm = true) => {
|
|
98
|
+
if (!confirm)
|
|
99
|
+
return;
|
|
100
|
+
core_1.CliUx.ux.log(label, "-", description);
|
|
101
|
+
const continuePublish = await core_1.CliUx.ux.confirm(`Would you like to publish ${label}? (y/N)`);
|
|
102
|
+
if (!continuePublish)
|
|
103
|
+
core_1.CliUx.ux.exit(0);
|
|
104
|
+
};
|
|
105
|
+
exports.confirmPublish = confirmPublish;
|
|
106
|
+
const publishDefinition = async ({ actions, triggers, connections, ...rest }, comment) => {
|
|
107
|
+
// FIXME: Ideally we should just pass the entire configuration blob but Graphene can't represent
|
|
108
|
+
// a dictionary having arbitrary keys. For now, split actions and triggers out.
|
|
109
|
+
const actionDefinitions = Object.values(actions || {}).map((action) => {
|
|
110
|
+
return {
|
|
111
|
+
...action,
|
|
112
|
+
examplePayload: (action === null || action === void 0 ? void 0 : action.examplePayload)
|
|
113
|
+
? JSON.stringify(action === null || action === void 0 ? void 0 : action.examplePayload)
|
|
114
|
+
: JSON.stringify({}),
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
const triggerDefinitions = Object.values(triggers || {}).map((trigger) => {
|
|
118
|
+
return {
|
|
119
|
+
...trigger,
|
|
120
|
+
examplePayload: (trigger === null || trigger === void 0 ? void 0 : trigger.examplePayload)
|
|
121
|
+
? JSON.stringify(trigger === null || trigger === void 0 ? void 0 : trigger.examplePayload)
|
|
122
|
+
: JSON.stringify({}),
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
const connectionDefinitions = connections || [];
|
|
126
|
+
// Initiate start of the publish procedure by sending config data and receive back presigned s3 URL
|
|
127
|
+
const result = await (0, graphql_1.gqlRequest)({
|
|
128
|
+
document: (0, graphql_1.gql) `
|
|
129
|
+
mutation publishComponent(
|
|
130
|
+
$definition: ComponentDefinitionInput!
|
|
131
|
+
$actions: [ActionDefinitionInput]!
|
|
132
|
+
$triggers: [TriggerDefinitionInput]
|
|
133
|
+
$connections: [ConnectionDefinitionInput]
|
|
134
|
+
$comment: String
|
|
135
|
+
) {
|
|
136
|
+
publishComponent(
|
|
137
|
+
input: {
|
|
138
|
+
definition: $definition
|
|
139
|
+
actions: $actions
|
|
140
|
+
triggers: $triggers
|
|
141
|
+
connections: $connections
|
|
142
|
+
comment: $comment
|
|
143
|
+
}
|
|
144
|
+
) {
|
|
145
|
+
publishResult {
|
|
146
|
+
component {
|
|
147
|
+
id
|
|
148
|
+
versionNumber
|
|
149
|
+
}
|
|
150
|
+
iconUploadUrl
|
|
151
|
+
packageUploadUrl
|
|
152
|
+
connectionIconUploadUrls {
|
|
153
|
+
connectionKey
|
|
154
|
+
iconUploadUrl
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
errors {
|
|
158
|
+
field
|
|
159
|
+
messages
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
`,
|
|
164
|
+
variables: {
|
|
165
|
+
definition: rest,
|
|
166
|
+
actions: actionDefinitions,
|
|
167
|
+
triggers: triggerDefinitions,
|
|
168
|
+
connections: connectionDefinitions,
|
|
169
|
+
comment,
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
const { iconUploadUrl, packageUploadUrl, connectionIconUploadUrls, component: { versionNumber }, } = result.publishComponent.publishResult;
|
|
173
|
+
const uploadUrls = connectionIconUploadUrls.reduce((result, { connectionKey, iconUploadUrl }) => ({
|
|
174
|
+
...result,
|
|
175
|
+
[connectionKey]: iconUploadUrl,
|
|
176
|
+
}), {});
|
|
177
|
+
return {
|
|
178
|
+
iconUploadUrl,
|
|
179
|
+
packageUploadUrl,
|
|
180
|
+
connectionIconUploadUrls: uploadUrls,
|
|
181
|
+
versionNumber,
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
exports.publishDefinition = publishDefinition;
|
|
185
|
+
const uploadFile = async (filePath, destinationUrl) => {
|
|
186
|
+
try {
|
|
187
|
+
// TODO: Stream instead of Buffer.
|
|
188
|
+
const response = await axios_1.default.put(destinationUrl, await fs_1.fs.readFile(filePath), { headers: { "Content-Type": mime_types_1.default.contentType((0, path_2.extname)(filePath)) } });
|
|
189
|
+
return response;
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
193
|
+
const { message } = error;
|
|
194
|
+
throw new Error(message);
|
|
195
|
+
}
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
exports.uploadFile = uploadFile;
|
|
200
|
+
const uploadConnectionIcons = async ({ connections }, connectionIconUploadUrls) => {
|
|
201
|
+
if (!connections ||
|
|
202
|
+
!connections.length ||
|
|
203
|
+
!connectionIconUploadUrls ||
|
|
204
|
+
!Object.keys(connectionIconUploadUrls).length) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const iconPaths = connections.reduce((result, { key, iconPath }) => {
|
|
208
|
+
if (!iconPath) {
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
...result,
|
|
213
|
+
[key]: iconPath,
|
|
214
|
+
};
|
|
215
|
+
}, {});
|
|
216
|
+
const promises = Object.entries(connectionIconUploadUrls).map(async ([connectionKey, uploadUrl]) => (0, exports.uploadFile)(iconPaths[connectionKey], uploadUrl));
|
|
217
|
+
await Promise.all(promises);
|
|
218
|
+
};
|
|
219
|
+
exports.uploadConnectionIcons = uploadConnectionIcons;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queryComponentKeys = void 0;
|
|
4
|
+
const graphql_1 = require("../../graphql");
|
|
5
|
+
const queryComponentKeys = async (keys) => {
|
|
6
|
+
const result = await (0, graphql_1.gqlRequest)({
|
|
7
|
+
document: (0, graphql_1.gql) `
|
|
8
|
+
query components($keys: [String]!) {
|
|
9
|
+
components(key_In: $keys) {
|
|
10
|
+
nodes {
|
|
11
|
+
id
|
|
12
|
+
key
|
|
13
|
+
versionNumber
|
|
14
|
+
public
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`,
|
|
19
|
+
variables: { keys },
|
|
20
|
+
});
|
|
21
|
+
return result.components.nodes;
|
|
22
|
+
};
|
|
23
|
+
exports.queryComponentKeys = queryComponentKeys;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatTimestamp = void 0;
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
9
|
+
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
|
|
10
|
+
dayjs_1.default.extend(utc_1.default);
|
|
11
|
+
dayjs_1.default.extend(timezone_1.default);
|
|
12
|
+
const formatTimestamp = (timestamp) => (0, dayjs_1.default)(timestamp, "YYYY-MM-DDTHH:mm:ss.SSS000+Z", true).format("HH:mm:ss.SSS");
|
|
13
|
+
exports.formatTimestamp = formatTimestamp;
|
|
14
|
+
exports.default = dayjs_1.default;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.displayLogs = exports.waitForExecutionCompletion = void 0;
|
|
7
|
+
const core_1 = require("@oclif/core");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const date_1 = require("../date");
|
|
10
|
+
const graphql_1 = require("../../graphql");
|
|
11
|
+
const util_1 = require("util");
|
|
12
|
+
const setTimeoutPromise = (0, util_1.promisify)(setTimeout);
|
|
13
|
+
const waitForExecutionCompletion = (executionId) => {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const interval = setInterval(async () => {
|
|
16
|
+
try {
|
|
17
|
+
const result = await (0, graphql_1.gqlRequest)({
|
|
18
|
+
document: (0, graphql_1.gql) `
|
|
19
|
+
query pollExecution($executionId: ID!) {
|
|
20
|
+
executionResult(id: $executionId) {
|
|
21
|
+
endedAt
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`,
|
|
25
|
+
variables: { executionId },
|
|
26
|
+
});
|
|
27
|
+
const { endedAt } = result.executionResult;
|
|
28
|
+
if (endedAt) {
|
|
29
|
+
clearInterval(interval);
|
|
30
|
+
// Grace period to let logs finish flowing; logs are fully async and are
|
|
31
|
+
// not guaranteed to be added in chronological order.
|
|
32
|
+
await setTimeoutPromise(1000);
|
|
33
|
+
resolve();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
clearInterval(interval);
|
|
38
|
+
reject(error);
|
|
39
|
+
}
|
|
40
|
+
}, 1000);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
exports.waitForExecutionCompletion = waitForExecutionCompletion;
|
|
44
|
+
const displayLogs = async (executionId) => {
|
|
45
|
+
await (0, exports.waitForExecutionCompletion)(executionId);
|
|
46
|
+
// TODO: Add paging
|
|
47
|
+
const result = await (0, graphql_1.gqlRequest)({
|
|
48
|
+
document: (0, graphql_1.gql) `
|
|
49
|
+
query logs($executionId: ID!) {
|
|
50
|
+
executionResult(id: $executionId) {
|
|
51
|
+
logs(orderBy: { field: TIMESTAMP, direction: ASC }) {
|
|
52
|
+
nodes {
|
|
53
|
+
timestamp
|
|
54
|
+
severity
|
|
55
|
+
message
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`,
|
|
61
|
+
variables: { executionId },
|
|
62
|
+
});
|
|
63
|
+
const logs = result.executionResult.logs.nodes;
|
|
64
|
+
core_1.CliUx.ux.table(logs, {
|
|
65
|
+
timestamp: {
|
|
66
|
+
get: ({ timestamp }) => (0, date_1.formatTimestamp)(timestamp),
|
|
67
|
+
},
|
|
68
|
+
severity: {
|
|
69
|
+
minWidth: 12,
|
|
70
|
+
get: ({ severity }) => {
|
|
71
|
+
if (severity == "INFO") {
|
|
72
|
+
return chalk_1.default.blue("info");
|
|
73
|
+
}
|
|
74
|
+
if (severity == "WARN") {
|
|
75
|
+
return chalk_1.default.yellow("warn");
|
|
76
|
+
}
|
|
77
|
+
if (severity == "ERROR") {
|
|
78
|
+
return chalk_1.default.red("error");
|
|
79
|
+
}
|
|
80
|
+
return severity.toLowerCase();
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
message: {},
|
|
84
|
+
}, { "no-header": true });
|
|
85
|
+
};
|
|
86
|
+
exports.displayLogs = displayLogs;
|