@prismatic-io/prism 4.1.0 → 4.2.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.
@@ -30,7 +30,6 @@ exports.initializeProject = void 0;
30
30
  const camelcase_1 = __importDefault(require("camelcase"));
31
31
  const ts_morph_1 = require("ts-morph");
32
32
  const path = __importStar(require("path"));
33
- const util_1 = require("./util");
34
33
  const initializeActionFile = (componentProject, projectRoot) => {
35
34
  const actionFile = componentProject.createSourceFile(path.join(projectRoot, "src", "actions.ts"), undefined, { overwrite: true });
36
35
  actionFile.addImportDeclaration({
@@ -39,14 +38,6 @@ const initializeActionFile = (componentProject, projectRoot) => {
39
38
  });
40
39
  return actionFile;
41
40
  };
42
- const initializeClientFile = (componentProject, projectRoot) => {
43
- const clientFile = componentProject.createSourceFile(path.join(projectRoot, "src", "client.ts"), undefined, { overwrite: true });
44
- return clientFile;
45
- };
46
- const initializeConnectionsFile = (componentProject, projectRoot) => {
47
- const connectionsFile = componentProject.createSourceFile(path.join(projectRoot, "src", "connections.ts"), undefined, { overwrite: true });
48
- return connectionsFile;
49
- };
50
41
  const initializeInputsFile = (componentProject, projectRoot) => {
51
42
  const inputsFile = componentProject.createSourceFile(path.join(projectRoot, "src", "inputs.ts"), undefined, { overwrite: true });
52
43
  inputsFile.addImportDeclaration({
@@ -60,12 +51,6 @@ const copyTemplateFileToProject = (componentProject, projectRoot, projectTemplat
60
51
  const templateFile = componentProject.getSourceFileOrThrow(projectTemplatePath);
61
52
  templateFile.copy(path.join(process.cwd(), projectRoot, fileName));
62
53
  };
63
- const initializeOpenApi = ({ projectRoot, projectTemplatePath, componentProject, }) => {
64
- // Copy our template file into the component project
65
- copyTemplateFileToProject(componentProject, projectRoot, projectTemplatePath, path.basename(projectTemplatePath));
66
- // Return the relative path of the OpenAPI spec
67
- return path.relative(path.join(projectRoot, "src"), path.join(projectRoot, path.basename(projectTemplatePath)));
68
- };
69
54
  const initializeWSDL = ({ projectRoot, projectTemplateName, projectTemplatePath, componentProject, actionFile, }) => {
70
55
  const wsdlProjectLocation = path.join(projectRoot, `${projectTemplateName}.wsdl`);
71
56
  // Copy the wsdl used for generation to the project root
@@ -77,47 +62,29 @@ const initializeWSDL = ({ projectRoot, projectTemplateName, projectTemplatePath,
77
62
  // Return the relative path of the WSDL
78
63
  return path.relative(path.join(projectRoot, "src"), wsdlProjectLocation);
79
64
  };
80
- const projectTypeSetup = (project, projectType) => {
81
- if (projectType === "wsdl") {
82
- const wsdlPath = initializeWSDL(project);
83
- // Update the WSDL Path to be in our component project
84
- project.projectTemplatePath = wsdlPath;
85
- }
86
- else if (projectType === "openApi") {
87
- const openApiPath = initializeOpenApi(project);
88
- project.projectTemplatePath = openApiPath;
89
- }
65
+ const projectTypeSetup = (project) => {
66
+ const wsdlPath = initializeWSDL(project);
67
+ // Update the WSDL Path to be in our component project
68
+ project.projectTemplatePath = wsdlPath;
90
69
  };
91
- const initializeProject = (projectRoot, projectTemplateName, projectTemplatePath, projectType, includeClient, addRetry) => {
70
+ const initializeProject = (projectRoot, projectTemplateName, projectTemplatePath) => {
92
71
  const componentProject = new ts_morph_1.Project({
93
72
  tsConfigFilePath: path.join(projectRoot, "tsconfig.json"),
94
73
  });
95
74
  componentProject.addSourceFilesAtPaths(path.join(projectRoot, "**/*"));
96
75
  const actionFile = initializeActionFile(componentProject, projectRoot);
97
76
  const inputsFile = initializeInputsFile(componentProject, projectRoot);
98
- if (projectType === "openApi" && inputsFile) {
99
- (0, util_1.addRequiredInputs)(projectType, inputsFile, addRetry);
100
- }
101
77
  const project = {
102
78
  projectRoot,
103
79
  projectTemplateName: (0, camelcase_1.default)(projectTemplateName),
104
- definitionDirectory: projectType === "wsdl"
105
- ? (0, camelcase_1.default)(projectTemplateName).toLowerCase()
106
- : projectTemplateName,
80
+ definitionDirectory: (0, camelcase_1.default)(projectTemplateName).toLowerCase(),
107
81
  projectTemplatePath,
108
- projectType,
109
82
  componentProject,
110
83
  actionFile,
111
84
  inputsFile,
112
85
  };
113
- if (projectType === "openApi" && includeClient) {
114
- const clientFile = initializeClientFile(componentProject, projectRoot);
115
- project.clientFile = clientFile;
116
- const connectionsFile = initializeConnectionsFile(componentProject, projectRoot);
117
- project.connectionsFile = connectionsFile;
118
- }
119
86
  // Setup type specific project details
120
- projectTypeSetup(project, projectType);
87
+ projectTypeSetup(project);
121
88
  return project;
122
89
  };
123
90
  exports.initializeProject = initializeProject;
@@ -3,9 +3,8 @@ 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.appendRequiredFields = exports.addRequiredInputs = exports.createDescription = void 0;
6
+ exports.createDescription = void 0;
7
7
  const striptags_1 = __importDefault(require("striptags"));
8
- const ts_morph_1 = require("ts-morph");
9
8
  const createDescription = (text) => {
10
9
  if (!text) {
11
10
  return "";
@@ -16,106 +15,3 @@ const createDescription = (text) => {
16
15
  return fragment.replace(/`/g, "'");
17
16
  };
18
17
  exports.createDescription = createDescription;
19
- const addProperty = (inputsFile, inputName, propertyList) => {
20
- const placeholder = inputsFile.addVariableStatement({
21
- declarationKind: ts_morph_1.VariableDeclarationKind.Const,
22
- declarations: [
23
- { name: "genericActionInput", initializer: ts_morph_1.Writers.object({}) },
24
- ],
25
- });
26
- const object = placeholder.getDeclarations()[0].getInitializer();
27
- object.addPropertyAssignments(propertyList);
28
- inputsFile.addVariableStatement({
29
- declarationKind: ts_morph_1.VariableDeclarationKind.Const,
30
- isExported: true,
31
- declarations: [
32
- { name: inputName, initializer: `input(${object.print()})` },
33
- ],
34
- });
35
- placeholder.remove();
36
- };
37
- const addRequiredInputs = (projectType, inputsFile, addRetry) => {
38
- addProperty(inputsFile, "apiBaseUrl", [
39
- { name: `"label"`, initializer: `"API Base URL"` },
40
- { name: `"type"`, initializer: `"string"` },
41
- { name: `"required"`, initializer: `false` },
42
- {
43
- name: `"comments"`,
44
- initializer: `"An optional url you can specify to override the default provided by the OpenAPI spec."`,
45
- },
46
- ]);
47
- addProperty(inputsFile, "debugRequest", [
48
- { name: `"label"`, initializer: `"Debug Request"` },
49
- { name: `"type"`, initializer: `"boolean"` },
50
- { name: `"required"`, initializer: `false` },
51
- {
52
- name: `"comments"`,
53
- initializer: `"An optional boolean you can toggle to log the contents of the HTTP request for each action."`,
54
- },
55
- ]);
56
- addProperty(inputsFile, "timeout", [
57
- { name: `"label"`, initializer: `"Timeout"` },
58
- { name: `"type"`, initializer: `"string"` },
59
- { name: `"required"`, initializer: `false` },
60
- {
61
- name: `"comments"`,
62
- initializer: `"An optional input that indicates how long the client will await a response."`,
63
- },
64
- ]);
65
- if (addRetry) {
66
- addProperty(inputsFile, "maxRetries", [
67
- { name: `"label"`, initializer: `"Max Retries"` },
68
- { name: `"type"`, initializer: `"string"` },
69
- { name: `"required"`, initializer: `false` },
70
- {
71
- name: `"comments"`,
72
- initializer: `"An optional input that indicates how many times this client will retry the request."`,
73
- },
74
- ]);
75
- addProperty(inputsFile, "retryDelayMS", [
76
- { name: `"label"`, initializer: `"Retry Delay (MS)"` },
77
- { name: `"type"`, initializer: `"string"` },
78
- { name: `"required"`, initializer: `false` },
79
- {
80
- name: `"comments"`,
81
- initializer: `"An optional input that indicates a delay between retries."`,
82
- },
83
- ]);
84
- addProperty(inputsFile, "retryOnAllErrors", [
85
- { name: `"label"`, initializer: `"Retry On All Errors"` },
86
- { name: `"type"`, initializer: `"boolean"` },
87
- { name: `"required"`, initializer: `false` },
88
- {
89
- name: `"comments"`,
90
- initializer: `"An optional boolean that will have the client retry the request, regardless of what type of error is thrown."`,
91
- },
92
- ]);
93
- addProperty(inputsFile, "useExponentialBackoff", [
94
- { name: `"label"`, initializer: `"Use Exponential Backoff"` },
95
- { name: `"type"`, initializer: `"boolean"` },
96
- { name: `"required"`, initializer: `false` },
97
- {
98
- name: `"comments"`,
99
- initializer: `"An optional boolean that will enable exponential backoff on retry."`,
100
- },
101
- ]);
102
- }
103
- return inputsFile;
104
- };
105
- exports.addRequiredInputs = addRequiredInputs;
106
- const appendRequiredFields = ({ inputFields, addRetry, includeClient, }) => {
107
- if (!includeClient) {
108
- return inputFields;
109
- }
110
- const base = [...inputFields, "apiBaseUrl", "debugRequest", "timeout"];
111
- return addRetry
112
- ? [
113
- ...base,
114
- "maxRetries",
115
- "retryDelayMS",
116
- "retryOnAllErrors",
117
- "useExponentialBackoff",
118
- ]
119
- : base;
120
- };
121
- exports.appendRequiredFields = appendRequiredFields;
package/lib/graphql.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.gql = exports.gqlRequest = void 0;
4
+ const url_1 = require("url");
4
5
  const graphql_request_1 = require("graphql-request");
5
6
  const auth_1 = require("./auth");
6
7
  const isErrored = (result) => {
@@ -21,10 +22,9 @@ const formatError = (field, messages) => {
21
22
  return `${field}: ${message}`;
22
23
  };
23
24
  const gqlRequest = async ({ document, variables, }) => {
24
- var _a;
25
- const prismaticUri = (_a = process.env.PRISMATIC_URL) !== null && _a !== void 0 ? _a : "https://app.prismatic.io";
26
25
  const accessToken = await (0, auth_1.getAccessToken)();
27
- const result = await (0, graphql_request_1.request)(`${prismaticUri}/api`, document, variables, {
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
28
  Authorization: `Bearer ${accessToken}`,
29
29
  "Prismatic-Client": "prism",
30
30
  });
package/lib/yeoman.js CHANGED
@@ -11,6 +11,7 @@ const generatorTypes = [
11
11
  "action",
12
12
  "trigger",
13
13
  "connection",
14
+ "formats",
14
15
  ];
15
16
  const runGenerator = async (generatorName, options) => {
16
17
  if (!generatorTypes.includes(generatorName)) {