@prismatic-io/spectral 10.11.4 → 10.12.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.
|
@@ -1,4 +1,27 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,12 +31,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
32
|
});
|
|
10
33
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
35
|
exports.fetchComponentDataForManifest = void 0;
|
|
16
|
-
const axios_1 =
|
|
36
|
+
const axios_1 = __importStar(require("axios"));
|
|
17
37
|
const prism_1 = require("../utils/prism");
|
|
18
38
|
// Helper to transform input nodes from GraphQL response to the expected format
|
|
19
39
|
function transformInputNodes(inputs) {
|
|
@@ -22,7 +42,7 @@ function transformInputNodes(inputs) {
|
|
|
22
42
|
// This function does not return a complete Component as described in ServerTypes;
|
|
23
43
|
// it instead selectively returns only what's needed to generate a manifest.
|
|
24
44
|
const fetchComponentDataForManifest = (_a) => __awaiter(void 0, [_a], void 0, function* ({ componentKey, isPrivate, }) {
|
|
25
|
-
var _b;
|
|
45
|
+
var _b, _c, _d;
|
|
26
46
|
const accessToken = yield (0, prism_1.getPrismAccessToken)();
|
|
27
47
|
const prismaticUrl = (_b = process.env.PRISMATIC_URL) !== null && _b !== void 0 ? _b : "https://app.prismatic.io";
|
|
28
48
|
const query = `
|
|
@@ -138,67 +158,78 @@ const fetchComponentDataForManifest = (_a) => __awaiter(void 0, [_a], void 0, fu
|
|
|
138
158
|
};
|
|
139
159
|
}
|
|
140
160
|
catch (error) {
|
|
141
|
-
|
|
161
|
+
if (error instanceof axios_1.AxiosError && ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.errors)) {
|
|
162
|
+
throw new Error(JSON.stringify(error.response.data.errors, null, 2));
|
|
163
|
+
}
|
|
164
|
+
throw error;
|
|
142
165
|
}
|
|
143
166
|
});
|
|
144
167
|
exports.fetchComponentDataForManifest = fetchComponentDataForManifest;
|
|
145
168
|
function getComponentActions(componentId, prismaticUrl, accessToken) {
|
|
146
169
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
var _a, _b;
|
|
170
|
+
var _a, _b, _c, _d;
|
|
148
171
|
let hasNextPage = true;
|
|
149
172
|
let cursor = null;
|
|
150
173
|
let actions = [];
|
|
151
174
|
while (hasNextPage) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
175
|
+
try {
|
|
176
|
+
const query = `
|
|
177
|
+
query componentActionQuery($component: ID!, $after: String) {
|
|
178
|
+
actions(component: $component, after: $after) {
|
|
179
|
+
nodes {
|
|
180
|
+
isDataSource
|
|
181
|
+
isDetailDataSource
|
|
182
|
+
dataSourceType
|
|
183
|
+
isTrigger
|
|
184
|
+
isCommonTrigger
|
|
185
|
+
key
|
|
186
|
+
label
|
|
187
|
+
description
|
|
188
|
+
inputs {
|
|
189
|
+
nodes {
|
|
190
|
+
key
|
|
191
|
+
label
|
|
192
|
+
type
|
|
193
|
+
required
|
|
194
|
+
default
|
|
195
|
+
collection
|
|
196
|
+
shown
|
|
197
|
+
onPremiseControlled
|
|
198
|
+
}
|
|
174
199
|
}
|
|
200
|
+
examplePayload
|
|
201
|
+
}
|
|
202
|
+
pageInfo {
|
|
203
|
+
hasNextPage
|
|
204
|
+
endCursor
|
|
175
205
|
}
|
|
176
|
-
examplePayload
|
|
177
|
-
}
|
|
178
|
-
pageInfo {
|
|
179
|
-
hasNextPage
|
|
180
|
-
endCursor
|
|
181
206
|
}
|
|
182
207
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
208
|
+
`;
|
|
209
|
+
const response = yield axios_1.default.post(`${prismaticUrl}/api`, {
|
|
210
|
+
query: query,
|
|
211
|
+
variables: {
|
|
212
|
+
component: componentId,
|
|
213
|
+
after: cursor,
|
|
214
|
+
},
|
|
215
|
+
}, {
|
|
216
|
+
headers: {
|
|
217
|
+
Authorization: `Bearer ${accessToken}`,
|
|
218
|
+
"Content-Type": "application/json",
|
|
219
|
+
"Prismatic-Client": "spectral",
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
const responseActions = response.data.data.actions.nodes;
|
|
223
|
+
actions = actions.concat(responseActions);
|
|
224
|
+
hasNextPage = (_a = response.data.data.actions.pageInfo) === null || _a === void 0 ? void 0 : _a.hasNextPage;
|
|
225
|
+
cursor = (_b = response.data.data.actions.pageInfo) === null || _b === void 0 ? void 0 : _b.endCursor;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
if (error instanceof axios_1.AxiosError && ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.errors)) {
|
|
229
|
+
throw new Error(JSON.stringify(error.response.data.errors, null, 2));
|
|
230
|
+
}
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
202
233
|
}
|
|
203
234
|
return actions.sort((a, b) => a.key.localeCompare(b.key));
|
|
204
235
|
});
|
|
@@ -504,6 +504,15 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
|
|
|
504
504
|
if ((0, types_1.isJsonFormConfigVar)(configVar) || (0, types_1.isJsonFormDataSourceConfigVar)(configVar)) {
|
|
505
505
|
result.meta = Object.assign(Object.assign({}, result.meta), { validationMode: (_c = configVar === null || configVar === void 0 ? void 0 : configVar.validationMode) !== null && _c !== void 0 ? _c : "ValidateAndShow" });
|
|
506
506
|
}
|
|
507
|
+
if ((0, types_1.isJsonFormDataSourceConfigVar)(configVar) && configVar.dataSourceReset) {
|
|
508
|
+
result.meta = Object.assign(Object.assign({}, result.meta), { dataSourceReset: configVar.dataSourceReset.mode });
|
|
509
|
+
// Create placeholder inputs for each config variable dependency, so that
|
|
510
|
+
// the config wizard can detect if any changed and reset the data source.
|
|
511
|
+
result.inputs = (configVar.dataSourceReset.dependencies || []).reduce((acc, dep, idx) => (Object.assign(Object.assign({}, acc), { [`input${idx}`]: {
|
|
512
|
+
type: "configVar",
|
|
513
|
+
value: dep,
|
|
514
|
+
} })), {});
|
|
515
|
+
}
|
|
507
516
|
if ((0, types_1.isDataSourceDefinitionConfigVar)(configVar)) {
|
|
508
517
|
result.dataType = configVar.dataSourceType;
|
|
509
518
|
result.dataSource = {
|
|
@@ -520,6 +529,9 @@ const convertConfigVar = (key, configVar, referenceKey, componentRegistry) => {
|
|
|
520
529
|
if (configVar.validationMode) {
|
|
521
530
|
result.meta = Object.assign(Object.assign({}, result.meta), { validationMode: configVar.validationMode });
|
|
522
531
|
}
|
|
532
|
+
if (configVar.dataSourceReset) {
|
|
533
|
+
result.meta = Object.assign(Object.assign({}, result.meta), { dataSourceReset: configVar.dataSourceReset.mode });
|
|
534
|
+
}
|
|
523
535
|
}
|
|
524
536
|
return result;
|
|
525
537
|
};
|
|
@@ -688,7 +700,16 @@ const codeNativeIntegrationComponent = ({ name, iconPath, description, flows = [
|
|
|
688
700
|
return Object.assign(Object.assign({}, result), { [camelKey]: Object.assign(Object.assign({}, dataSource), { key: camelKey, display: {
|
|
689
701
|
label: key,
|
|
690
702
|
description: key,
|
|
691
|
-
}, inputs:
|
|
703
|
+
}, inputs:
|
|
704
|
+
// Create placeholder inputs for each config variable dependency,so that
|
|
705
|
+
// the config wizard can detect if any changed and reset the data source.
|
|
706
|
+
(0, types_1.isJsonFormDataSourceConfigVar)(configVar) && configVar.dataSourceReset
|
|
707
|
+
? (configVar.dataSourceReset.dependencies || []).map((dep, idx) => ({
|
|
708
|
+
key: `input${idx}`,
|
|
709
|
+
label: dep,
|
|
710
|
+
type: "string",
|
|
711
|
+
}))
|
|
712
|
+
: [] }) });
|
|
692
713
|
}, {});
|
|
693
714
|
const convertedConnections = Object.entries(configVars).reduce((result, [key, configVar]) => {
|
|
694
715
|
var _a;
|
|
@@ -126,11 +126,18 @@ type ScheduleConfigVar = CreateStandardConfigVar<"schedule"> & {
|
|
|
126
126
|
};
|
|
127
127
|
type ObjectSelectionConfigVar = CreateStandardConfigVar<"objectSelection">;
|
|
128
128
|
type ObjectFieldMapConfigVar = CreateStandardConfigVar<"objectFieldMap">;
|
|
129
|
+
type DataSourceReset = {
|
|
130
|
+
/** Either always prompt a user to reset the data source when a dependent config variable changes, or always reset the data source */
|
|
131
|
+
mode: "prompt" | "always";
|
|
132
|
+
/** List of config variable names that, if changed, should trigger a reset of the JSON Form */
|
|
133
|
+
dependencies?: string[];
|
|
134
|
+
};
|
|
129
135
|
type JsonFormConfigVar = CreateStandardConfigVar<"jsonForm"> & {
|
|
130
136
|
validationMode?: ValidationMode;
|
|
131
137
|
};
|
|
132
138
|
type JsonFormDataSourceDefinitionConfigVar = DataSourceDefinitionConfigVar & {
|
|
133
139
|
validationMode?: ValidationMode;
|
|
140
|
+
dataSourceReset?: DataSourceReset;
|
|
134
141
|
};
|
|
135
142
|
type HtmlElementConfigVar = CreateStandardConfigVar<"htmlElement">;
|
|
136
143
|
export type StandardConfigVar = StringConfigVar | DateConfigVar | TimestampConfigVar | PicklistConfigVar | CodeConfigVar | BooleanConfigVar | NumberConfigVar | ScheduleConfigVar | ObjectSelectionConfigVar | ObjectFieldMapConfigVar | JsonFormConfigVar | HtmlElementConfigVar;
|
|
@@ -155,6 +162,7 @@ type DataSourceDefinitionConfigVar = DataSourceType extends infer TDataSourceTyp
|
|
|
155
162
|
type DataSourceReferenceConfigVar = ComponentRegistryDataSource extends infer TDataSourceReference extends ComponentRegistryDataSource ? Omit<BaseDataSourceConfigVar<TDataSourceReference["dataSourceType"]>, "dataSourceType"> & {
|
|
156
163
|
dataSource: TDataSourceReference["reference"];
|
|
157
164
|
validationMode?: ValidationMode;
|
|
165
|
+
dataSourceReset?: Omit<DataSourceReset, "dependencies">;
|
|
158
166
|
} : never;
|
|
159
167
|
/** Defines attributes of a data source config variable. */
|
|
160
168
|
export type DataSourceConfigVar = DataSourceDefinitionConfigVar | DataSourceReferenceConfigVar;
|
package/package.json
CHANGED