@prismatic-io/spectral 10.16.4 → 10.17.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/dist/generators/cniComponentManifest/cli.js +5 -0
- package/dist/generators/cniComponentManifest/index.d.ts +4 -0
- package/dist/generators/cniComponentManifest/index.js +38 -1
- package/dist/generators/componentManifest/createConnections.d.ts +2 -1
- package/dist/generators/componentManifest/createConnections.js +7 -2
- package/dist/generators/componentManifest/templates/connections/index.ts.ejs +12 -1
- package/dist/types/FlowAttributes.d.ts +2 -0
- package/package.json +1 -1
|
@@ -81,6 +81,10 @@ const runMain = (process) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
81
81
|
componentKey,
|
|
82
82
|
isPrivate: flags.isPrivate.value || false,
|
|
83
83
|
});
|
|
84
|
+
const reusableConnectionStableKeys = yield (0, _1.fetchConnectionStableKeys)({
|
|
85
|
+
componentKey: component.key,
|
|
86
|
+
isPrivate: flags.isPrivate.value || false,
|
|
87
|
+
});
|
|
84
88
|
// Generate the manifest
|
|
85
89
|
const destinationDir = node_path_1.default.join(process.cwd(), "src", "manifests", component.key);
|
|
86
90
|
const templatesDir = node_path_1.default.join(__dirname, "..", "componentManifest", "templates");
|
|
@@ -122,6 +126,7 @@ const runMain = (process) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
122
126
|
verbose,
|
|
123
127
|
sourceDir: templatesDir,
|
|
124
128
|
destinationDir,
|
|
129
|
+
reusableConnectionStableKeys,
|
|
125
130
|
});
|
|
126
131
|
yield (0, createDataSources_1.createDataSources)({
|
|
127
132
|
component,
|
|
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.fetchComponentDataForManifest = void 0;
|
|
35
|
+
exports.fetchConnectionStableKeys = exports.fetchComponentDataForManifest = void 0;
|
|
36
36
|
const axios_1 = __importStar(require("axios"));
|
|
37
37
|
const prism_1 = require("../utils/prism");
|
|
38
38
|
// Helper to transform input nodes from GraphQL response to the expected format
|
|
@@ -165,6 +165,43 @@ const fetchComponentDataForManifest = (_a) => __awaiter(void 0, [_a], void 0, fu
|
|
|
165
165
|
}
|
|
166
166
|
});
|
|
167
167
|
exports.fetchComponentDataForManifest = fetchComponentDataForManifest;
|
|
168
|
+
const fetchConnectionStableKeys = (_a) => __awaiter(void 0, [_a], void 0, function* ({ componentKey, isPrivate, }) {
|
|
169
|
+
var _b, _c, _d, _e, _f, _g, _h;
|
|
170
|
+
const accessToken = yield (0, prism_1.getPrismAccessToken)();
|
|
171
|
+
const prismaticUrl = (_b = process.env.PRISMATIC_URL) !== null && _b !== void 0 ? _b : "https://app.prismatic.io";
|
|
172
|
+
const query = `
|
|
173
|
+
query connectionStableKeysQuery($componentSelector: [ComponentSelector]!) {
|
|
174
|
+
scopedConfigVariables(connection_Component_In: $componentSelector) {
|
|
175
|
+
nodes {
|
|
176
|
+
stableKey
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
`;
|
|
181
|
+
try {
|
|
182
|
+
const response = yield axios_1.default.post(new URL("/api", prismaticUrl).toString(), {
|
|
183
|
+
query,
|
|
184
|
+
variables: {
|
|
185
|
+
componentSelector: [{ key: componentKey, isPublic: !isPrivate }],
|
|
186
|
+
},
|
|
187
|
+
}, {
|
|
188
|
+
headers: {
|
|
189
|
+
Authorization: `Bearer ${accessToken}`,
|
|
190
|
+
"Content-Type": "application/json",
|
|
191
|
+
"Prismatic-Client": "spectral",
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
const nodes = (_f = (_e = (_d = (_c = response.data) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.scopedConfigVariables) === null || _e === void 0 ? void 0 : _e.nodes) !== null && _f !== void 0 ? _f : [];
|
|
195
|
+
return nodes.map((node) => node.stableKey);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
if (error instanceof axios_1.AxiosError && ((_h = (_g = error.response) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.errors)) {
|
|
199
|
+
throw new Error(JSON.stringify(error.response.data.errors, null, 2));
|
|
200
|
+
}
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
exports.fetchConnectionStableKeys = fetchConnectionStableKeys;
|
|
168
205
|
function getComponentActions(componentId, prismaticUrl, accessToken) {
|
|
169
206
|
return __awaiter(this, void 0, void 0, function* () {
|
|
170
207
|
var _a, _b, _c, _d;
|
|
@@ -6,8 +6,9 @@ interface CreateConnectionsProps<TInputs extends Inputs, TActionInputs extends I
|
|
|
6
6
|
verbose: boolean;
|
|
7
7
|
sourceDir: string;
|
|
8
8
|
destinationDir: string;
|
|
9
|
+
reusableConnectionStableKeys?: string[];
|
|
9
10
|
}
|
|
10
|
-
export declare const createConnections: <TInputs extends Inputs, TActionInputs extends Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>>({ component, dryRun, verbose, sourceDir, destinationDir, }: CreateConnectionsProps<TInputs, TActionInputs, TConfigVars, TPayload, TAllowsBranching, TResult>) => Promise<{
|
|
11
|
+
export declare const createConnections: <TInputs extends Inputs, TActionInputs extends Inputs, TConfigVars extends ConfigVarResultCollection = ConfigVarResultCollection, TPayload extends TriggerPayload = TriggerPayload, TAllowsBranching extends boolean = boolean, TResult extends TriggerResult<TAllowsBranching, TPayload> = TriggerResult<TAllowsBranching, TPayload>>({ component, dryRun, verbose, sourceDir, destinationDir, reusableConnectionStableKeys, }: CreateConnectionsProps<TInputs, TActionInputs, TConfigVars, TPayload, TAllowsBranching, TResult>) => Promise<{
|
|
11
12
|
connectionIndex: string | void;
|
|
12
13
|
connections: (string | void)[];
|
|
13
14
|
}>;
|
|
@@ -20,7 +20,7 @@ const helpers_1 = require("./helpers");
|
|
|
20
20
|
const createTemplate_1 = require("../utils/createTemplate");
|
|
21
21
|
const createTypeInterface_1 = require("../utils/createTypeInterface");
|
|
22
22
|
const createImport_1 = require("../utils/createImport");
|
|
23
|
-
const createConnections = (_a) => __awaiter(void 0, [_a], void 0, function* ({ component, dryRun, verbose, sourceDir, destinationDir, }) {
|
|
23
|
+
const createConnections = (_a) => __awaiter(void 0, [_a], void 0, function* ({ component, dryRun, verbose, sourceDir, destinationDir, reusableConnectionStableKeys = [], }) {
|
|
24
24
|
var _b, _c;
|
|
25
25
|
if (verbose) {
|
|
26
26
|
console.info("Creating connections...");
|
|
@@ -35,6 +35,8 @@ const createConnections = (_a) => __awaiter(void 0, [_a], void 0, function* ({ c
|
|
|
35
35
|
verbose,
|
|
36
36
|
sourceDir,
|
|
37
37
|
destinationDir,
|
|
38
|
+
reusableConnectionStableKeys,
|
|
39
|
+
componentKey: component.key,
|
|
38
40
|
});
|
|
39
41
|
const connections = yield Promise.all(((_c = component.connections) !== null && _c !== void 0 ? _c : []).map((connection) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
42
|
const inputs = (0, getInputs_1.getInputs)({
|
|
@@ -75,12 +77,15 @@ const createConnections = (_a) => __awaiter(void 0, [_a], void 0, function* ({ c
|
|
|
75
77
|
});
|
|
76
78
|
});
|
|
77
79
|
exports.createConnections = createConnections;
|
|
78
|
-
const renderConnectionsIndex = (_a) => __awaiter(void 0, [_a], void 0, function* ({ imports, dryRun, verbose, sourceDir, destinationDir, }) {
|
|
80
|
+
const renderConnectionsIndex = (_a) => __awaiter(void 0, [_a], void 0, function* ({ imports, dryRun, verbose, sourceDir, destinationDir, reusableConnectionStableKeys = [], componentKey, }) {
|
|
79
81
|
return yield (0, createTemplate_1.createTemplate)({
|
|
80
82
|
source: path_1.default.join(sourceDir, "connections", "index.ts.ejs"),
|
|
81
83
|
destination: path_1.default.join(destinationDir, "connections", "index.ts"),
|
|
82
84
|
data: {
|
|
83
85
|
imports,
|
|
86
|
+
reusableConnectionStableKeys,
|
|
87
|
+
componentKey,
|
|
88
|
+
helpers: helpers_1.helpers,
|
|
84
89
|
},
|
|
85
90
|
dryRun,
|
|
86
91
|
verbose,
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
<%- include('../partials/generatedHeader.ejs') -%>
|
|
2
|
-
|
|
2
|
+
<% if (reusableConnectionStableKeys.length > 0) { -%>
|
|
3
|
+
import type { CustomerActivatedConnectionConfigVar, OrganizationActivatedConnectionConfigVar } from "@prismatic-io/spectral";
|
|
4
|
+
<% } -%>
|
|
5
|
+
<%- include('../partials/importBarrel.ejs', { imports }) -%>
|
|
6
|
+
<% if (reusableConnectionStableKeys.length > 0) { %>
|
|
7
|
+
export const <%- helpers.camelCase(componentKey) %>ReusableConnection = (
|
|
8
|
+
stableKey: <%- reusableConnectionStableKeys.map(k => JSON.stringify(k)).join(" | ") %> | (string & {}),
|
|
9
|
+
): OrganizationActivatedConnectionConfigVar | CustomerActivatedConnectionConfigVar => ({
|
|
10
|
+
stableKey,
|
|
11
|
+
dataType: "connection",
|
|
12
|
+
});
|
|
13
|
+
<% } -%>
|
package/package.json
CHANGED