@prismatic-io/prism 3.2.3 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/bin/run +9 -8
  2. package/lib/auth.js +183 -201
  3. package/lib/commands/alerts/events/list.js +27 -57
  4. package/lib/commands/alerts/groups/create.js +18 -49
  5. package/lib/commands/alerts/groups/delete.js +10 -41
  6. package/lib/commands/alerts/groups/list.js +15 -47
  7. package/lib/commands/alerts/monitors/clear.js +10 -41
  8. package/lib/commands/alerts/monitors/create.js +27 -58
  9. package/lib/commands/alerts/monitors/delete.js +10 -41
  10. package/lib/commands/alerts/monitors/list.js +16 -48
  11. package/lib/commands/alerts/triggers/list.js +15 -47
  12. package/lib/commands/alerts/webhooks/create.js +18 -49
  13. package/lib/commands/alerts/webhooks/delete.js +10 -41
  14. package/lib/commands/alerts/webhooks/list.js +25 -57
  15. package/lib/commands/authorization-methods/list.js +20 -51
  16. package/lib/commands/components/actions/list.js +29 -61
  17. package/lib/commands/components/delete.js +10 -41
  18. package/lib/commands/components/dev/run.js +75 -0
  19. package/lib/commands/components/dev/test.js +218 -0
  20. package/lib/commands/components/init/action.js +12 -0
  21. package/lib/commands/components/init/component.js +12 -0
  22. package/lib/commands/components/init/connection.js +12 -0
  23. package/lib/commands/components/init/index.js +203 -0
  24. package/lib/commands/components/init/trigger.js +12 -0
  25. package/lib/commands/components/list.js +31 -60
  26. package/lib/commands/components/publish.js +29 -279
  27. package/lib/commands/components/triggers/list.js +29 -61
  28. package/lib/commands/customers/create.js +14 -45
  29. package/lib/commands/customers/credentials/create.js +19 -50
  30. package/lib/commands/customers/credentials/delete.js +10 -41
  31. package/lib/commands/customers/credentials/list.js +30 -59
  32. package/lib/commands/customers/credentials/update.js +16 -47
  33. package/lib/commands/customers/delete.js +10 -41
  34. package/lib/commands/customers/list.js +16 -48
  35. package/lib/commands/customers/update.js +15 -46
  36. package/lib/commands/customers/users/create.js +18 -49
  37. package/lib/commands/customers/users/delete.js +10 -41
  38. package/lib/commands/customers/users/list.js +21 -51
  39. package/lib/commands/customers/users/roles.js +18 -48
  40. package/lib/commands/customers/users/update.js +19 -50
  41. package/lib/commands/executions/step-result/get.js +36 -66
  42. package/lib/commands/instances/config-vars/list.js +32 -62
  43. package/lib/commands/instances/create.js +20 -51
  44. package/lib/commands/instances/delete.js +10 -41
  45. package/lib/commands/instances/deploy.js +20 -44
  46. package/lib/commands/instances/disable.js +11 -42
  47. package/lib/commands/instances/enable.js +11 -42
  48. package/lib/commands/instances/flow-configs/list.js +25 -55
  49. package/lib/commands/instances/flow-configs/test.js +62 -97
  50. package/lib/commands/instances/list.js +31 -59
  51. package/lib/commands/instances/update.js +15 -46
  52. package/lib/commands/integrations/available.js +13 -44
  53. package/lib/commands/integrations/create.js +14 -45
  54. package/lib/commands/integrations/delete.js +10 -41
  55. package/lib/commands/integrations/export.js +16 -59
  56. package/lib/commands/integrations/flows/list.js +22 -52
  57. package/lib/commands/integrations/flows/test.js +62 -96
  58. package/lib/commands/integrations/fork.js +15 -46
  59. package/lib/commands/integrations/import.js +12 -63
  60. package/lib/commands/integrations/list.js +25 -54
  61. package/lib/commands/integrations/publish.js +13 -44
  62. package/lib/commands/integrations/update.js +18 -49
  63. package/lib/commands/integrations/versions/index.js +26 -58
  64. package/lib/commands/login.js +16 -32
  65. package/lib/commands/logout.js +10 -22
  66. package/lib/commands/logs/severities/list.js +15 -47
  67. package/lib/commands/me/index.js +15 -60
  68. package/lib/commands/me/token/revoke.js +12 -0
  69. package/lib/commands/me/token.js +10 -22
  70. package/lib/commands/organization/credentials/create.js +17 -48
  71. package/lib/commands/organization/credentials/delete.js +10 -41
  72. package/lib/commands/organization/credentials/list.js +22 -54
  73. package/lib/commands/organization/credentials/update.js +16 -47
  74. package/lib/commands/organization/update.js +12 -43
  75. package/lib/commands/organization/updateAvatarUrl.js +14 -45
  76. package/lib/commands/organization/users/create.js +16 -47
  77. package/lib/commands/organization/users/delete.js +10 -41
  78. package/lib/commands/organization/users/list.js +16 -48
  79. package/lib/commands/organization/users/roles.js +18 -48
  80. package/lib/commands/organization/users/update.js +19 -50
  81. package/lib/config.js +24 -30
  82. package/lib/errors.js +48 -27
  83. package/lib/fields.js +6 -4
  84. package/lib/fs.js +6 -14
  85. package/lib/generate/action.js +36 -41
  86. package/lib/generate/client.js +11 -16
  87. package/lib/generate/connection.js +4 -13
  88. package/lib/generate/index.js +29 -19
  89. package/lib/generate/input.js +28 -43
  90. package/lib/generate/parse.js +38 -44
  91. package/lib/generate/sourceFile.js +11 -7
  92. package/lib/generate/util.js +9 -7
  93. package/lib/graphql.js +37 -65
  94. package/lib/index.js +3 -3
  95. package/lib/utils/component/publish.js +219 -0
  96. package/lib/utils/component/query.js +23 -0
  97. package/lib/utils/date.js +14 -0
  98. package/lib/utils/execution/logs.js +86 -0
  99. package/lib/utils/integration/definition.js +101 -0
  100. package/lib/utils/integration/export.js +36 -0
  101. package/lib/utils/integration/import.js +46 -0
  102. package/lib/utils/integration/invoke.js +64 -0
  103. package/lib/utils/integration/query.js +59 -0
  104. package/lib/utils/serialize.js +8 -0
  105. package/lib/utils/user/query.js +24 -0
  106. package/lib/yeoman.js +23 -0
  107. package/oclif.manifest.json +1 -1
  108. package/package.json +48 -54
  109. package/templates/component/openapi/client.ts +11 -9
  110. package/templates/component/openapi/request.ts +6 -4
  111. package/lib/auth.js.map +0 -1
  112. package/lib/commands/alerts/events/list.js.map +0 -1
  113. package/lib/commands/alerts/groups/create.js.map +0 -1
  114. package/lib/commands/alerts/groups/delete.js.map +0 -1
  115. package/lib/commands/alerts/groups/list.js.map +0 -1
  116. package/lib/commands/alerts/monitors/clear.js.map +0 -1
  117. package/lib/commands/alerts/monitors/create.js.map +0 -1
  118. package/lib/commands/alerts/monitors/delete.js.map +0 -1
  119. package/lib/commands/alerts/monitors/list.js.map +0 -1
  120. package/lib/commands/alerts/triggers/list.js.map +0 -1
  121. package/lib/commands/alerts/webhooks/create.js.map +0 -1
  122. package/lib/commands/alerts/webhooks/delete.js.map +0 -1
  123. package/lib/commands/alerts/webhooks/list.js.map +0 -1
  124. package/lib/commands/authorization-methods/list.js.map +0 -1
  125. package/lib/commands/components/actions/list.js.map +0 -1
  126. package/lib/commands/components/delete.js.map +0 -1
  127. package/lib/commands/components/init.js +0 -224
  128. package/lib/commands/components/init.js.map +0 -1
  129. package/lib/commands/components/list.js.map +0 -1
  130. package/lib/commands/components/publish.js.map +0 -1
  131. package/lib/commands/components/triggers/list.js.map +0 -1
  132. package/lib/commands/customers/create.js.map +0 -1
  133. package/lib/commands/customers/credentials/create.js.map +0 -1
  134. package/lib/commands/customers/credentials/delete.js.map +0 -1
  135. package/lib/commands/customers/credentials/list.js.map +0 -1
  136. package/lib/commands/customers/credentials/update.js.map +0 -1
  137. package/lib/commands/customers/delete.js.map +0 -1
  138. package/lib/commands/customers/list.js.map +0 -1
  139. package/lib/commands/customers/update.js.map +0 -1
  140. package/lib/commands/customers/users/create.js.map +0 -1
  141. package/lib/commands/customers/users/delete.js.map +0 -1
  142. package/lib/commands/customers/users/list.js.map +0 -1
  143. package/lib/commands/customers/users/roles.js.map +0 -1
  144. package/lib/commands/customers/users/update.js.map +0 -1
  145. package/lib/commands/executions/step-result/get.js.map +0 -1
  146. package/lib/commands/instances/config-vars/list.js.map +0 -1
  147. package/lib/commands/instances/create.js.map +0 -1
  148. package/lib/commands/instances/delete.js.map +0 -1
  149. package/lib/commands/instances/deploy.js.map +0 -1
  150. package/lib/commands/instances/disable.js.map +0 -1
  151. package/lib/commands/instances/enable.js.map +0 -1
  152. package/lib/commands/instances/flow-configs/list.js.map +0 -1
  153. package/lib/commands/instances/flow-configs/test.js.map +0 -1
  154. package/lib/commands/instances/list.js.map +0 -1
  155. package/lib/commands/instances/update.js.map +0 -1
  156. package/lib/commands/integrations/available.js.map +0 -1
  157. package/lib/commands/integrations/create.js.map +0 -1
  158. package/lib/commands/integrations/delete.js.map +0 -1
  159. package/lib/commands/integrations/export.js.map +0 -1
  160. package/lib/commands/integrations/flows/list.js.map +0 -1
  161. package/lib/commands/integrations/flows/test.js.map +0 -1
  162. package/lib/commands/integrations/fork.js.map +0 -1
  163. package/lib/commands/integrations/import.js.map +0 -1
  164. package/lib/commands/integrations/list.js.map +0 -1
  165. package/lib/commands/integrations/publish.js.map +0 -1
  166. package/lib/commands/integrations/update.js.map +0 -1
  167. package/lib/commands/integrations/versions/index.js.map +0 -1
  168. package/lib/commands/login.js.map +0 -1
  169. package/lib/commands/logout.js.map +0 -1
  170. package/lib/commands/logs/severities/list.js.map +0 -1
  171. package/lib/commands/me/index.js.map +0 -1
  172. package/lib/commands/me/token.js.map +0 -1
  173. package/lib/commands/organization/credentials/create.js.map +0 -1
  174. package/lib/commands/organization/credentials/delete.js.map +0 -1
  175. package/lib/commands/organization/credentials/list.js.map +0 -1
  176. package/lib/commands/organization/credentials/update.js.map +0 -1
  177. package/lib/commands/organization/update.js.map +0 -1
  178. package/lib/commands/organization/updateAvatarUrl.js.map +0 -1
  179. package/lib/commands/organization/users/create.js.map +0 -1
  180. package/lib/commands/organization/users/delete.js.map +0 -1
  181. package/lib/commands/organization/users/list.js.map +0 -1
  182. package/lib/commands/organization/users/roles.js.map +0 -1
  183. package/lib/commands/organization/users/update.js.map +0 -1
  184. package/lib/config.js.map +0 -1
  185. package/lib/errors.js.map +0 -1
  186. package/lib/fields.js.map +0 -1
  187. package/lib/fs.js.map +0 -1
  188. package/lib/generate/action.js.map +0 -1
  189. package/lib/generate/client.js.map +0 -1
  190. package/lib/generate/connection.js.map +0 -1
  191. package/lib/generate/index.js.map +0 -1
  192. package/lib/generate/input.js.map +0 -1
  193. package/lib/generate/parse.js.map +0 -1
  194. package/lib/generate/sourceFile.js.map +0 -1
  195. package/lib/generate/util.js.map +0 -1
  196. package/lib/graphql.js.map +0 -1
  197. package/lib/index.js.map +0 -1
  198. package/templates/component/jest.config.js +0 -4
  199. package/templates/component/package.json +0 -24
  200. package/templates/component/src/actions.ts +0 -33
  201. package/templates/component/src/client.ts +0 -7
  202. package/templates/component/src/connections.ts +0 -25
  203. package/templates/component/src/index.test.ts +0 -32
  204. package/templates/component/src/index.ts +0 -17
  205. package/templates/component/src/triggers.ts +0 -18
  206. package/templates/component/tsconfig.json +0 -19
  207. package/templates/component/webpack.config.js +0 -44
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const graphql_1 = require("../../../graphql");
5
+ const child_process_1 = require("child_process");
6
+ const spawnProcess = ([command, ...args], env) => {
7
+ return new Promise((resolve, reject) => {
8
+ const child = (0, child_process_1.spawn)(command, args, {
9
+ env: { ...process.env, ...env },
10
+ });
11
+ child.stdout.pipe(process.stdout);
12
+ child.stderr.pipe(process.stderr);
13
+ child.on("close", (code) => (code === 0 ? resolve() : reject()));
14
+ });
15
+ };
16
+ class RunCommand extends core_1.Command {
17
+ async run() {
18
+ const { argv, flags: { integrationId, configVarKey }, } = await this.parse(RunCommand);
19
+ const result = await (0, graphql_1.gqlRequest)({
20
+ document: (0, graphql_1.gql) `
21
+ query integration($id: ID!) {
22
+ integration(id: $id) {
23
+ testConfigVariables {
24
+ nodes {
25
+ requiredConfigVariable {
26
+ key
27
+ }
28
+ inputs {
29
+ nodes {
30
+ name
31
+ value
32
+ }
33
+ }
34
+ meta
35
+ }
36
+ }
37
+ }
38
+ }
39
+ `,
40
+ variables: {
41
+ id: integrationId,
42
+ },
43
+ });
44
+ const nodes = result.integration.testConfigVariables.nodes;
45
+ const [connection] = nodes.filter(({ requiredConfigVariable: { key } }) => key === configVarKey);
46
+ if (!connection) {
47
+ core_1.CliUx.ux.error("Failed to find active connection.", { exit: 1 });
48
+ }
49
+ const { meta, inputs } = connection;
50
+ const fields = inputs.nodes.reduce((result, { name, value }) => ({ ...result, [name]: value }), {});
51
+ const value = JSON.stringify({
52
+ ...JSON.parse(meta),
53
+ fields,
54
+ });
55
+ await spawnProcess(argv, { PRISMATIC_CONNECTION_VALUE: value });
56
+ }
57
+ }
58
+ exports.default = RunCommand;
59
+ RunCommand.description = "Run an arbitrary command within a Prismatic context";
60
+ // Allow us to manually capture argv so we can isolate the wrapped command.
61
+ RunCommand.strict = false;
62
+ // TODO: Make this derive from the component manifest using the same
63
+ // logic as the `test` command.
64
+ RunCommand.flags = {
65
+ integrationId: core_1.Flags.string({
66
+ required: true,
67
+ char: "i",
68
+ description: "Integration ID",
69
+ }),
70
+ configVarKey: core_1.Flags.string({
71
+ required: true,
72
+ char: "c",
73
+ description: "Key of the Connection Config Var to fetch meta/state for",
74
+ }),
75
+ };
@@ -0,0 +1,218 @@
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
+ const util_1 = require("util");
7
+ const dotenv_1 = __importDefault(require("dotenv"));
8
+ const core_1 = require("@oclif/core");
9
+ const inquirer_1 = __importDefault(require("inquirer"));
10
+ const lodash_1 = require("lodash");
11
+ const publish_1 = require("../../../utils/component/publish");
12
+ const logs_1 = require("../../../utils/execution/logs");
13
+ const definition_1 = require("../../../utils/integration/definition");
14
+ const import_1 = require("../../../utils/integration/import");
15
+ const invoke_1 = require("../../../utils/integration/invoke");
16
+ const query_1 = require("../../../utils/integration/query");
17
+ const fs_1 = require("../../../fs");
18
+ const query_2 = require("../../../utils/user/query");
19
+ const setTimeoutPromise = (0, util_1.promisify)(setTimeout);
20
+ const envVarCase = (name) => (0, lodash_1.upperCase)((0, lodash_1.snakeCase)(name)).replace(/\s+/g, "_");
21
+ const toInquirerInputType = (type, collection) => {
22
+ if (collection) {
23
+ // FIXME: Improve prompting instead of instantly bailing to editor.
24
+ return "editor";
25
+ }
26
+ switch (type) {
27
+ case "boolean":
28
+ return "checkbox";
29
+ case "password":
30
+ return "password";
31
+ case "code":
32
+ return "editor";
33
+ default:
34
+ return "input";
35
+ }
36
+ };
37
+ const getInputQuestion = ({ key, label, type, collection, default: defaultValue, }) => ({
38
+ type: toInquirerInputType(type, collection),
39
+ name: key,
40
+ message: `${label}:`,
41
+ when: (answers) => {
42
+ var _a;
43
+ const envVar = envVarCase(key);
44
+ const exists = envVar in process.env;
45
+ if (exists) {
46
+ const value = (_a = process.env[envVar]) !== null && _a !== void 0 ? _a : "";
47
+ answers[key] = collection
48
+ ? { type: "complex", value: JSON.parse(value) }
49
+ : { type: "value", value };
50
+ }
51
+ return !exists;
52
+ },
53
+ filter: (value) => {
54
+ if (type === "connection") {
55
+ return { type: "configVar", value };
56
+ }
57
+ if (collection) {
58
+ return {
59
+ type: "complex",
60
+ value: JSON.parse(value),
61
+ };
62
+ }
63
+ return {
64
+ type: "value",
65
+ value,
66
+ };
67
+ },
68
+ default: () => (type === "connection" ? "testConnection" : defaultValue),
69
+ });
70
+ const valuesFromAnswers = ({ action, actionInputs, connection, connectionInputs = {}, }) => {
71
+ const actionValues = Object.entries(actionInputs).reduce((result, [key, value]) => ({
72
+ ...result,
73
+ [key]: value,
74
+ }), {});
75
+ const connectionValues = Object.entries(connectionInputs).reduce((result, [key, value]) => ({
76
+ ...result,
77
+ [key]: value,
78
+ }), {});
79
+ const connectionInfo = connection
80
+ ? { key: connection.key, values: connectionValues }
81
+ : undefined;
82
+ return {
83
+ actionInfo: { key: action.key, values: actionValues },
84
+ connectionInfo,
85
+ };
86
+ };
87
+ class TestCommand extends core_1.Command {
88
+ async run() {
89
+ const { flags: { envPath }, } = await this.parse(TestCommand);
90
+ if (await (0, fs_1.exists)(envPath)) {
91
+ const { error } = dotenv_1.default.config({ path: envPath });
92
+ if (error) {
93
+ core_1.CliUx.ux.error(`Failed to load specified dotenv file: ${error}`, {
94
+ exit: 1,
95
+ });
96
+ }
97
+ }
98
+ core_1.CliUx.ux.action.start("Validating Component");
99
+ const { name } = await (0, query_2.whoAmI)();
100
+ if (!name) {
101
+ core_1.CliUx.ux.error("Failed to determine the name of the currently logged in user.", {
102
+ exit: 1,
103
+ });
104
+ }
105
+ const testingKey = (0, lodash_1.kebabCase)(name);
106
+ const definition = await (0, publish_1.loadEntrypoint)();
107
+ const { key: componentKey, public: isPublic } = definition;
108
+ definition.key = `${componentKey}-${testingKey}-testing`;
109
+ definition.display.label = `${definition.display.label} ${name} Testing`;
110
+ await (0, publish_1.validateDefinition)(definition);
111
+ const packagePath = await (0, publish_1.createComponentPackage)();
112
+ const signatureMatches = await (0, publish_1.checkSignature)(definition, packagePath);
113
+ core_1.CliUx.ux.action.stop();
114
+ if (!signatureMatches) {
115
+ core_1.CliUx.ux.action.start("Publishing Component");
116
+ const { iconUploadUrl, packageUploadUrl, connectionIconUploadUrls } = await (0, publish_1.publishDefinition)(definition);
117
+ const { display: { iconPath }, } = definition;
118
+ await (0, publish_1.uploadFile)(iconPath, iconUploadUrl);
119
+ await (0, publish_1.uploadConnectionIcons)(definition, connectionIconUploadUrls);
120
+ await (0, publish_1.uploadFile)(packagePath, packageUploadUrl);
121
+ core_1.CliUx.ux.action.stop();
122
+ }
123
+ const publishedTimestamp = Date.now();
124
+ const actions = definition.actions || {};
125
+ const { action } = await inquirer_1.default.prompt({
126
+ type: "list",
127
+ name: "action",
128
+ message: "Action:",
129
+ choices: Object.entries(actions).map(([key, { display: { label }, },]) => ({
130
+ name: label,
131
+ value: key,
132
+ short: key,
133
+ })),
134
+ default: Object.keys(actions)[0],
135
+ filter: (value) => actions[value],
136
+ });
137
+ const { inputs } = action;
138
+ // Ask for values of action's inputs
139
+ const actionInputs = await inquirer_1.default.prompt(inputs.map((i) => getInputQuestion(i)));
140
+ const answers = {
141
+ action,
142
+ actionInputs,
143
+ };
144
+ // Ask about Connection to test if there is a connection type input
145
+ const hasConnection = inputs.some(({ type }) => type === "connection");
146
+ if (hasConnection) {
147
+ const connections = definition.connections || [];
148
+ const { connection } = await inquirer_1.default.prompt({
149
+ type: "list",
150
+ name: "connection",
151
+ message: "Connection:",
152
+ choices: connections.map(({ key, label }) => ({
153
+ name: label,
154
+ value: key,
155
+ short: key,
156
+ })),
157
+ default: Object.keys(connections)[0],
158
+ filter: (value) => {
159
+ const [connection] = connections.filter(({ key }) => value === key);
160
+ return connection;
161
+ },
162
+ });
163
+ // Prompt for connection's inputs
164
+ const { inputs } = connection;
165
+ const connectionInputs = await inquirer_1.default.prompt(inputs
166
+ .filter(({ shown }) => shown === undefined || shown === true)
167
+ .map((i) => getInputQuestion(i)));
168
+ Object.assign(answers, { connection, connectionInputs });
169
+ }
170
+ const { actionInfo, connectionInfo } = valuesFromAnswers(answers);
171
+ core_1.CliUx.ux.action.start("Assembling test integration");
172
+ // FIXME: Wait for version to be available but due to issues we have to do a static wait.
173
+ const wait = 5000 - (Date.now() - publishedTimestamp);
174
+ if (wait > 0) {
175
+ await setTimeoutPromise(wait);
176
+ }
177
+ // Build up YAML
178
+ const harnessYaml = await (0, definition_1.buildComponentTestHarnessIntegration)({
179
+ integrationInfo: {
180
+ name: (0, definition_1.componentTestIntegrationName)(componentKey, name),
181
+ },
182
+ componentInfo: { key: componentKey, isPublic: isPublic !== null && isPublic !== void 0 ? isPublic : false },
183
+ actionInfo,
184
+ connectionInfo,
185
+ });
186
+ core_1.CliUx.ux.action.stop();
187
+ core_1.CliUx.ux.action.start("Updating test Integration");
188
+ const { integrationId, flows: [{ id: flowId }], pendingAuthorizations, } = await (0, import_1.importDefinition)(harnessYaml);
189
+ core_1.CliUx.ux.action.stop();
190
+ // Prompt for user authorization of pending connections
191
+ if (pendingAuthorizations.length > 0) {
192
+ const [{ id, url }] = pendingAuthorizations;
193
+ if (!url) {
194
+ throw new Error("Did not receive a valid URL for authorization. Verify your Connection inputs.");
195
+ }
196
+ core_1.CliUx.ux.url("Authorize URL", url);
197
+ await core_1.CliUx.ux.anykey("Press any key to open your browser and authorize the Connection");
198
+ await core_1.CliUx.ux.open(url);
199
+ core_1.CliUx.ux.action.start("Waiting for Connection authorization");
200
+ await (0, query_1.pollForActiveConfigVarState)(integrationId, id);
201
+ core_1.CliUx.ux.action.stop();
202
+ }
203
+ core_1.CliUx.ux.action.start("Running test Integration");
204
+ const { executionId } = await (0, invoke_1.runIntegrationFlow)({ integrationId, flowId });
205
+ await (0, logs_1.displayLogs)(executionId);
206
+ core_1.CliUx.ux.action.stop();
207
+ }
208
+ }
209
+ exports.default = TestCommand;
210
+ TestCommand.description = "Run a Component in Prismatic by publishing it into a test Integration";
211
+ TestCommand.flags = {
212
+ envPath: core_1.Flags.string({
213
+ required: false,
214
+ default: ".env",
215
+ char: "e",
216
+ description: "Path to dotenv file to load for supplying testing values",
217
+ }),
218
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const yeoman_1 = require("../../../yeoman");
5
+ class GenerateActionCommand extends core_1.Command {
6
+ async run() {
7
+ await this.parse(GenerateActionCommand);
8
+ await (0, yeoman_1.runGenerator)("action");
9
+ }
10
+ }
11
+ exports.default = GenerateActionCommand;
12
+ GenerateActionCommand.description = "Initialize a new Action file";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const yeoman_1 = require("../../../yeoman");
5
+ class GenerateComponentCommand extends core_1.Command {
6
+ async run() {
7
+ await this.parse(GenerateComponentCommand);
8
+ await (0, yeoman_1.runGenerator)("component");
9
+ }
10
+ }
11
+ exports.default = GenerateComponentCommand;
12
+ GenerateComponentCommand.description = "Initialize a new Component";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const yeoman_1 = require("../../../yeoman");
5
+ class GenerateConnectionCommand extends core_1.Command {
6
+ async run() {
7
+ await this.parse(GenerateConnectionCommand);
8
+ await (0, yeoman_1.runGenerator)("connection");
9
+ }
10
+ }
11
+ exports.default = GenerateConnectionCommand;
12
+ GenerateConnectionCommand.description = "Initialize a new Connection file";
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const core_1 = require("@oclif/core");
30
+ const fs_1 = require("fs");
31
+ const path = __importStar(require("path"));
32
+ const wsdl_tsclient_1 = require("wsdl-tsclient");
33
+ const logger_1 = require("wsdl-tsclient/dist/src/utils/logger");
34
+ const index_1 = require("../../../generate/index");
35
+ const openapi_typescript_codegen_1 = require("openapi-typescript-codegen");
36
+ const prettier_1 = __importDefault(require("prettier"));
37
+ const glob_promise_1 = __importDefault(require("glob-promise"));
38
+ const yeoman_1 = require("../../../yeoman");
39
+ const componentNameRegex = /^[a-zA-Z0-9][a-zA-Z0-9-_]*[a-zA-Z0-9]$/;
40
+ const insertText = /* javascript */ `
41
+ interface EnhancedConfig extends Config {
42
+ timeout?: number;
43
+ CLIENT?: AxiosInstance;
44
+ }
45
+ export const EnhancedOpenAPI: EnhancedConfig = OpenAPI;`;
46
+ const injectAxiosToOpenAPI = async (basePath) => {
47
+ const fileLocation = path.resolve(basePath, "core", "request.ts");
48
+ const replaceLocation = path.join(__dirname, "..", "..", "..", "..", "templates", "component", "openapi", "request.ts");
49
+ await fs_1.promises.copyFile(replaceLocation, fileLocation);
50
+ const file = path.resolve(basePath, "core", "OpenAPI.ts");
51
+ const contents = await fs_1.promises.readFile(file);
52
+ const parts = [contents, insertText].join("\n\n").split("\n");
53
+ const additions = [
54
+ ...parts.slice(0, 3),
55
+ /* javascript */ `import { AxiosInstance } from "axios";`,
56
+ ...parts.slice(3),
57
+ ].join("\n");
58
+ await fs_1.promises.writeFile(file, additions);
59
+ };
60
+ const getFilesToFormat = async (basename) => {
61
+ return await (0, glob_promise_1.default)("**/*.ts", {
62
+ ignore: ["**/node_modules/**"],
63
+ cwd: path.dirname(basename),
64
+ });
65
+ };
66
+ const formatSourceFiles = async (basePath, files) => {
67
+ //format the text of each file
68
+ await Promise.all(files.map(async (filePath) => {
69
+ const formattedFile = prettier_1.default.format(await fs_1.promises.readFile(path.resolve(path.dirname(basePath), filePath), "utf-8"), { parser: "typescript" });
70
+ //write the formatted text to the proper file location
71
+ await fs_1.promises.writeFile(path.resolve(path.dirname(basePath), filePath), formattedFile);
72
+ }));
73
+ };
74
+ class InitializeComponent extends core_1.Command {
75
+ async run() {
76
+ const { args: { name }, flags: { verbose, "wsdl-path": wsdlPath, "open-api-path": openApiPath, "skip-auth": skipAuth, "add-retry": addRetry, }, } = await this.parse(InitializeComponent);
77
+ if (!componentNameRegex.test(name)) {
78
+ this.error(`'${name}' contains invalid characters. Please select a component name that starts and ends with alphanumeric characters, and contains only alphanumeric characters, hyphens, and underscores. See https://regex101.com/?regex=${encodeURIComponent(componentNameRegex.source)}`, { exit: 1 });
79
+ }
80
+ if (wsdlPath && !(wsdlPath === null || wsdlPath === void 0 ? void 0 : wsdlPath.includes(".wsdl"))) {
81
+ this.error("If a WSDL is provided it must have an extension of '.wsdl'", {
82
+ exit: 1,
83
+ });
84
+ }
85
+ if (skipAuth && !openApiPath) {
86
+ this.error("Auth templating is only supported when generating components from Open API specifications", {
87
+ exit: 1,
88
+ });
89
+ }
90
+ if (addRetry && !openApiPath) {
91
+ this.error("HTTP retry logic is only supported when generating components from OpenAPI specifications", {
92
+ exit: 1,
93
+ });
94
+ }
95
+ this.log(`Creating component directory for "${name}"...`);
96
+ await fs_1.promises.mkdir(name);
97
+ const cwd = process.cwd();
98
+ process.chdir(name);
99
+ await (0, yeoman_1.runGenerator)("component", process.env.NODE_ENV === "test"
100
+ ? {
101
+ name,
102
+ description: "Prism-generated Component",
103
+ connectionType: "basic",
104
+ skipInstall: true,
105
+ }
106
+ : { name, skipInstall: Boolean(wsdlPath) || Boolean(openApiPath) });
107
+ process.chdir(cwd);
108
+ if (wsdlPath) {
109
+ if (!verbose) {
110
+ // wsdl-tsclient emits pretty noisy logs that aren't particularly useful
111
+ logger_1.Logger.disabled();
112
+ }
113
+ const wsdlName = path.basename(wsdlPath).split(".wsdl")[0];
114
+ await (0, wsdl_tsclient_1.parseAndGenerate)(wsdlPath, path.join(name), {
115
+ caseInsensitiveNames: true,
116
+ });
117
+ await (0, index_1.generate)({
118
+ projectRoot: name,
119
+ projectTemplateName: wsdlName,
120
+ projectTemplatePath: wsdlPath,
121
+ projectType: "wsdl",
122
+ includeClient: false,
123
+ addRetry: false,
124
+ });
125
+ await (0, index_1.updatePackageJson)({
126
+ path: path.resolve(name, "package.json"),
127
+ dependencies: { soap: "0.40.0" },
128
+ });
129
+ }
130
+ else if (openApiPath) {
131
+ const openApiName = path.basename(openApiPath).split(".")[0];
132
+ const basePath = path.resolve(name, openApiName);
133
+ await (0, openapi_typescript_codegen_1.generate)({
134
+ input: openApiPath,
135
+ output: path.join(name, openApiName),
136
+ httpClient: openapi_typescript_codegen_1.HttpClient.NODE,
137
+ useUnionTypes: true, // handles the case of enums using reserved keywords
138
+ });
139
+ await (0, index_1.generate)({
140
+ projectRoot: name,
141
+ projectTemplateName: openApiName,
142
+ projectTemplatePath: openApiPath,
143
+ projectType: "openApi",
144
+ includeClient: !skipAuth,
145
+ addRetry,
146
+ });
147
+ await (0, index_1.updatePackageJson)({
148
+ path: path.resolve(name, "package.json"),
149
+ dependencies: {
150
+ axios: "0.21.4",
151
+ "axios-retry": "3.1.9",
152
+ "form-data": "4.0.0",
153
+ },
154
+ });
155
+ await injectAxiosToOpenAPI(basePath);
156
+ const filesToFormat = await getFilesToFormat(basePath);
157
+ await formatSourceFiles(basePath, filesToFormat);
158
+ }
159
+ this.log(`
160
+ "${name}" is ready for development.
161
+ To install dependencies, run either "npm install" or "yarn install"
162
+ To test the component, run "npm run test" or "yarn test"
163
+ To build the component, run "npm run build" or "yarn build"
164
+ To publish the component, run "prism components:publish"
165
+
166
+ For documentation on writing custom components, visit https://prismatic.io/docs/custom-components/writing-custom-components/
167
+ `);
168
+ }
169
+ }
170
+ exports.default = InitializeComponent;
171
+ InitializeComponent.description = "Initialize a new Component";
172
+ InitializeComponent.flags = {
173
+ "wsdl-path": core_1.Flags.string({
174
+ required: false,
175
+ description: "Path to the WSDL definition file used to generate a Component",
176
+ }),
177
+ "open-api-path": core_1.Flags.string({
178
+ required: false,
179
+ description: "The path to an OpenAPI Specification file (JSON or YAML) used to generate a Component",
180
+ }),
181
+ "skip-auth": core_1.Flags.boolean({
182
+ required: false,
183
+ default: false,
184
+ description: "Skip templating authentication for an OpenAPI-based component. Use this option for OpenAPI specs that do not require authentication.",
185
+ }),
186
+ verbose: core_1.Flags.boolean({
187
+ required: false,
188
+ default: false,
189
+ description: "Output more verbose logging from Component generation",
190
+ }),
191
+ "add-retry": core_1.Flags.boolean({
192
+ required: false,
193
+ default: false,
194
+ description: "Add inputs to each action to utilize Axios retry logic",
195
+ }),
196
+ };
197
+ InitializeComponent.args = [
198
+ {
199
+ name: "name",
200
+ required: true,
201
+ description: "Name of the new component to create (alphanumeric characters, hyphens, and underscores)",
202
+ },
203
+ ];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const yeoman_1 = require("../../../yeoman");
5
+ class GenerateTriggerCommand extends core_1.Command {
6
+ async run() {
7
+ await this.parse(GenerateTriggerCommand);
8
+ await (0, yeoman_1.runGenerator)("trigger");
9
+ }
10
+ }
11
+ exports.default = GenerateTriggerCommand;
12
+ GenerateTriggerCommand.description = "Initialize a new Trigger file";
@@ -1,43 +1,13 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
2
  Object.defineProperty(exports, "__esModule", { value: true });
31
- const command_1 = __importStar(require("@oclif/command"));
32
- const graphql_1 = __importStar(require("../../graphql"));
33
- const cli_ux_1 = require("cli-ux");
34
- class ListCommand extends command_1.default {
35
- run() {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const { flags } = this.parse(ListCommand);
38
- const { showAllVersions } = flags;
39
- const result = yield graphql_1.default.query({
40
- query: graphql_1.gql `
3
+ const core_1 = require("@oclif/core");
4
+ const graphql_1 = require("../../graphql");
5
+ class ListCommand extends core_1.Command {
6
+ async run() {
7
+ const { flags } = await this.parse(ListCommand);
8
+ const { showAllVersions } = flags;
9
+ const result = await (0, graphql_1.gqlRequest)({
10
+ document: (0, graphql_1.gql) `
41
11
  query listComponents($showAllVersions: Boolean) {
42
12
  components(allVersions: $showAllVersions) {
43
13
  nodes {
@@ -52,33 +22,34 @@ class ListCommand extends command_1.default {
52
22
  }
53
23
  }
54
24
  `,
55
- variables: {
56
- showAllVersions,
57
- },
58
- });
59
- cli_ux_1.cli.table(result.data.components.nodes, {
60
- id: {
61
- minWidth: 8,
62
- extended: true,
63
- },
64
- key: {
65
- minWidth: 10,
66
- extended: true,
67
- },
68
- label: {},
69
- public: {},
70
- description: {},
71
- versionNumber: { header: "Version" },
72
- category: {},
73
- }, Object.assign({}, flags));
25
+ variables: {
26
+ showAllVersions,
27
+ },
74
28
  });
29
+ core_1.CliUx.ux.table(result.components.nodes, {
30
+ id: {
31
+ minWidth: 8,
32
+ extended: true,
33
+ },
34
+ key: {
35
+ minWidth: 10,
36
+ extended: true,
37
+ },
38
+ label: {},
39
+ public: {},
40
+ description: {},
41
+ versionNumber: { header: "Version" },
42
+ category: {},
43
+ }, { ...flags });
75
44
  }
76
45
  }
77
46
  exports.default = ListCommand;
78
47
  ListCommand.description = "List available Components";
79
- ListCommand.flags = Object.assign(Object.assign({}, cli_ux_1.cli.table.flags()), { showAllVersions: command_1.flags.boolean({
48
+ ListCommand.flags = {
49
+ ...core_1.CliUx.ux.table.flags(),
50
+ showAllVersions: core_1.Flags.boolean({
80
51
  char: "a",
81
52
  required: false,
82
53
  description: "If specified this command returns all versions of all components rather than only the latest version",
83
- }) });
84
- //# sourceMappingURL=list.js.map
54
+ }),
55
+ };