@dev-fastn-ai/react-core 1.0.18 → 1.0.20
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/README.md +1 -1
- package/dist/core/src/utils/misc.d.ts +2 -1
- package/dist/index.cjs.js +416 -351
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +416 -351
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -92,278 +92,6 @@ function v4(options, buf, offset) {
|
|
|
92
92
|
return unsafeStringify(rnds);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
// GraphQL endpoint (customize as needed)
|
|
96
|
-
const GRAPHQL_ENDPOINT = "/graphql";
|
|
97
|
-
// Utility to perform GraphQL queries/mutations using fetch
|
|
98
|
-
async function fetchGraphQL({ query, variables }) {
|
|
99
|
-
const config = getConfig();
|
|
100
|
-
const response = await fetch(config.baseUrl + GRAPHQL_ENDPOINT, {
|
|
101
|
-
method: "POST",
|
|
102
|
-
headers: {
|
|
103
|
-
"Content-Type": "application/json",
|
|
104
|
-
authorization: `Bearer ${config.authToken}`,
|
|
105
|
-
realm: REALM,
|
|
106
|
-
[CUSTOM_AUTH_HEADER_KEY]: String(config.customAuth),
|
|
107
|
-
[PROJECT_ID_HEADER_KEY]: config.spaceId,
|
|
108
|
-
[TENANT_ID_HEADER_KEY]: config.tenantId,
|
|
109
|
-
[REQUEST_TRACE_ID_HEADER_KEY]: `fastn-ai-ts-${v4()}`,
|
|
110
|
-
},
|
|
111
|
-
body: JSON.stringify({ query, variables }),
|
|
112
|
-
});
|
|
113
|
-
if (!response.ok) {
|
|
114
|
-
switch (response.status) {
|
|
115
|
-
case 401:
|
|
116
|
-
throw new Error("Unauthorized: Please check your auth token");
|
|
117
|
-
case 403:
|
|
118
|
-
throw new Error("Forbidden: Please check your access");
|
|
119
|
-
case 404:
|
|
120
|
-
throw new Error("Not Found: Please check your request");
|
|
121
|
-
default:
|
|
122
|
-
throw new Error("Failed to fetch: Please check your request");
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const result = await response.json();
|
|
126
|
-
if (result.errors) {
|
|
127
|
-
throw new Error(result.errors.map((e) => e.message).join("; "));
|
|
128
|
-
}
|
|
129
|
-
return {
|
|
130
|
-
data: result.data,
|
|
131
|
-
errors: result.errors
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
// GraphQL Queries & Mutations (as plain strings)
|
|
135
|
-
const GET_WIDGET_CONNECTORS = `
|
|
136
|
-
query Connectors($input: GetConnectorsListInput!) {
|
|
137
|
-
connectors(input: $input) {
|
|
138
|
-
name
|
|
139
|
-
id
|
|
140
|
-
imageUri
|
|
141
|
-
description
|
|
142
|
-
content
|
|
143
|
-
actions {
|
|
144
|
-
name
|
|
145
|
-
handler
|
|
146
|
-
actionType
|
|
147
|
-
activatedStateLabel
|
|
148
|
-
content
|
|
149
|
-
shows
|
|
150
|
-
handlerPayload
|
|
151
|
-
multiConnectorWidgetConnectors {
|
|
152
|
-
name
|
|
153
|
-
id
|
|
154
|
-
imageUri
|
|
155
|
-
description
|
|
156
|
-
content
|
|
157
|
-
connectionId
|
|
158
|
-
actions {
|
|
159
|
-
name
|
|
160
|
-
handler
|
|
161
|
-
actionType
|
|
162
|
-
activatedStateLabel
|
|
163
|
-
content
|
|
164
|
-
shows
|
|
165
|
-
handlerPayload
|
|
166
|
-
}
|
|
167
|
-
events {
|
|
168
|
-
name
|
|
169
|
-
eventId
|
|
170
|
-
content
|
|
171
|
-
payload
|
|
172
|
-
}
|
|
173
|
-
connectedConnectors {
|
|
174
|
-
id
|
|
175
|
-
imageUrl
|
|
176
|
-
clientId
|
|
177
|
-
name
|
|
178
|
-
enableActivate
|
|
179
|
-
activateStatus
|
|
180
|
-
authMethods {
|
|
181
|
-
title
|
|
182
|
-
inputContract
|
|
183
|
-
type
|
|
184
|
-
details
|
|
185
|
-
isDefault
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
status
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
events {
|
|
192
|
-
name
|
|
193
|
-
eventId
|
|
194
|
-
content
|
|
195
|
-
payload
|
|
196
|
-
}
|
|
197
|
-
connectedConnectors {
|
|
198
|
-
id
|
|
199
|
-
imageUrl
|
|
200
|
-
clientId
|
|
201
|
-
name
|
|
202
|
-
enableActivate
|
|
203
|
-
activateStatus
|
|
204
|
-
authMethods {
|
|
205
|
-
title
|
|
206
|
-
inputContract
|
|
207
|
-
type
|
|
208
|
-
details
|
|
209
|
-
isDefault
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
status
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
`;
|
|
216
|
-
const SAVE_ACTIVATE_CONNECTOR_STATUS = `
|
|
217
|
-
mutation SaveActivateConnectorStatus(
|
|
218
|
-
$input: SaveWidgetConnectorStatusInput!
|
|
219
|
-
) {
|
|
220
|
-
saveWidgetConnectorStatus(input: $input)
|
|
221
|
-
}
|
|
222
|
-
`;
|
|
223
|
-
const DEACTIVATE_CONNECTOR = `
|
|
224
|
-
mutation DeactivateConnector($input: DeactivateConnectorInput!) {
|
|
225
|
-
deactivateConnector(input: $input)
|
|
226
|
-
}
|
|
227
|
-
`;
|
|
228
|
-
const GET_FIELD_DATA_QUERY = `
|
|
229
|
-
query executeGetFieldDataFlow($input: ApiPrimaryResolverInvocationInput!) {
|
|
230
|
-
executeGetFieldDataFlow(input: $input) {
|
|
231
|
-
data
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
`;
|
|
235
|
-
const GET_TENANT_CONFIGURATIONS = `
|
|
236
|
-
query GetConfigurationSubscription($input: ConfigurationSubscriptionInput!) {
|
|
237
|
-
getConfigurationSubscription(input: $input) {
|
|
238
|
-
connector {
|
|
239
|
-
id
|
|
240
|
-
name
|
|
241
|
-
description
|
|
242
|
-
imageUri
|
|
243
|
-
status
|
|
244
|
-
active
|
|
245
|
-
actions {
|
|
246
|
-
name
|
|
247
|
-
handler
|
|
248
|
-
actionType
|
|
249
|
-
}
|
|
250
|
-
connectedConnectors {
|
|
251
|
-
id
|
|
252
|
-
name
|
|
253
|
-
clientId
|
|
254
|
-
imageUrl
|
|
255
|
-
enableActivate
|
|
256
|
-
activateStatus
|
|
257
|
-
authMethods {
|
|
258
|
-
title
|
|
259
|
-
inputContract
|
|
260
|
-
type
|
|
261
|
-
details
|
|
262
|
-
isDefault
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
status
|
|
267
|
-
metaData
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
`;
|
|
271
|
-
const GET_TENANT_CONFIGURATIONS_BY_ID = `
|
|
272
|
-
query GetConfigurationSubscription($input: GetTenantConfigurationsInput) {
|
|
273
|
-
tenantConfigurationsById(input: $input) {
|
|
274
|
-
uiCode
|
|
275
|
-
flowId
|
|
276
|
-
stepId
|
|
277
|
-
status
|
|
278
|
-
configurations
|
|
279
|
-
configuredStepSetting {
|
|
280
|
-
keyIsEditable
|
|
281
|
-
addButton {
|
|
282
|
-
label
|
|
283
|
-
isDisabled
|
|
284
|
-
fieldsLimit
|
|
285
|
-
}
|
|
286
|
-
description
|
|
287
|
-
label
|
|
288
|
-
validation {
|
|
289
|
-
fieldValidation
|
|
290
|
-
submitValidation
|
|
291
|
-
modelId
|
|
292
|
-
jsonSchema
|
|
293
|
-
submitValidationFunction
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
`;
|
|
299
|
-
const CREATE_TENANT_CONFIGURATION = `
|
|
300
|
-
mutation CreateTenantConfiguration($input: TenantConfigurationsInput!) {
|
|
301
|
-
createTenantConfiguration(input: $input) {
|
|
302
|
-
id
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
`;
|
|
306
|
-
const UPDATE_TENANT_CONFIGURATION = `
|
|
307
|
-
mutation UpdateTenantConfiguration($input: TenantConfigurationsInput!) {
|
|
308
|
-
updateTenantConfiguration(input: $input) {
|
|
309
|
-
id
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
`;
|
|
313
|
-
const DELETE_TENANT_CONFIG = `
|
|
314
|
-
mutation DeleteTenantConfig($input: GetTenantConfigurationsInput!) {
|
|
315
|
-
deleteTenantConfig(input: $input) {
|
|
316
|
-
id
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
`;
|
|
320
|
-
const DISABLE_TENANT_CONFIG = `
|
|
321
|
-
mutation DisableTenantConfig($input: GetTenantConfigurationsInput!) {
|
|
322
|
-
disableTenantConfig(input: $input) {
|
|
323
|
-
id
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
`;
|
|
327
|
-
const GENERATE_ACCESS_TOKEN = `
|
|
328
|
-
query GenerateAccessToken($input: ConnectorConnectionInput!) {
|
|
329
|
-
connectorConnection(input: $input)
|
|
330
|
-
}
|
|
331
|
-
`;
|
|
332
|
-
// Refactored functions using fetchGraphQL
|
|
333
|
-
async function getConnectors$1(variables) {
|
|
334
|
-
return fetchGraphQL({ query: GET_WIDGET_CONNECTORS, variables });
|
|
335
|
-
}
|
|
336
|
-
async function saveActivateConnectorStatus(variables) {
|
|
337
|
-
return fetchGraphQL({ query: SAVE_ACTIVATE_CONNECTOR_STATUS, variables });
|
|
338
|
-
}
|
|
339
|
-
async function deactivateConnector$1(variables) {
|
|
340
|
-
return fetchGraphQL({ query: DEACTIVATE_CONNECTOR, variables });
|
|
341
|
-
}
|
|
342
|
-
async function getFieldData(variables) {
|
|
343
|
-
return fetchGraphQL({ query: GET_FIELD_DATA_QUERY, variables });
|
|
344
|
-
}
|
|
345
|
-
async function getConfigurationSubscriptions(variables) {
|
|
346
|
-
return fetchGraphQL({ query: GET_TENANT_CONFIGURATIONS, variables });
|
|
347
|
-
}
|
|
348
|
-
async function getConfigurationSubscriptionById(variables) {
|
|
349
|
-
return fetchGraphQL({ query: GET_TENANT_CONFIGURATIONS_BY_ID, variables });
|
|
350
|
-
}
|
|
351
|
-
async function createTenantConfiguration(variables) {
|
|
352
|
-
return fetchGraphQL({ query: CREATE_TENANT_CONFIGURATION, variables });
|
|
353
|
-
}
|
|
354
|
-
async function updateTenantConfiguration(variables) {
|
|
355
|
-
return fetchGraphQL({ query: UPDATE_TENANT_CONFIGURATION, variables });
|
|
356
|
-
}
|
|
357
|
-
async function deleteTenantConfig(variables) {
|
|
358
|
-
return fetchGraphQL({ query: DELETE_TENANT_CONFIG, variables });
|
|
359
|
-
}
|
|
360
|
-
async function disableTenantConfig(variables) {
|
|
361
|
-
return fetchGraphQL({ query: DISABLE_TENANT_CONFIG, variables });
|
|
362
|
-
}
|
|
363
|
-
async function generateAccessToken(variables) {
|
|
364
|
-
return fetchGraphQL({ query: GENERATE_ACCESS_TOKEN, variables });
|
|
365
|
-
}
|
|
366
|
-
|
|
367
95
|
/**
|
|
368
96
|
* Supported field types for connector forms.
|
|
369
97
|
*/
|
|
@@ -419,6 +147,70 @@ var ResourceAction;
|
|
|
419
147
|
ResourceAction["DELETE_CONFIGURATION"] = "DELETE_CONFIGURATION";
|
|
420
148
|
})(ResourceAction || (ResourceAction = {}));
|
|
421
149
|
|
|
150
|
+
const getCustomAuthContextValue = (operationName, variables) => {
|
|
151
|
+
var _a;
|
|
152
|
+
try {
|
|
153
|
+
if (!operationName)
|
|
154
|
+
return "";
|
|
155
|
+
return btoa(JSON.stringify(getCustomAuthContext(operationName, (_a = variables === null || variables === void 0 ? void 0 : variables.input) !== null && _a !== void 0 ? _a : {})));
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
console.error("Error getting custom auth context value:", error);
|
|
159
|
+
return "";
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const getCustomAuthContext = (operationName, input) => {
|
|
163
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
164
|
+
if (!operationName)
|
|
165
|
+
return {};
|
|
166
|
+
try {
|
|
167
|
+
let action = ResourceAction.QUERY;
|
|
168
|
+
let resourceId = "";
|
|
169
|
+
switch (operationName) {
|
|
170
|
+
case "metadata":
|
|
171
|
+
case "connectors":
|
|
172
|
+
case "api":
|
|
173
|
+
case "tenantflow":
|
|
174
|
+
case "generateaccesstoken":
|
|
175
|
+
break;
|
|
176
|
+
case "deactivateconnector":
|
|
177
|
+
action = ResourceAction.DEACTIVATION;
|
|
178
|
+
resourceId = (_a = input.connectorId) !== null && _a !== void 0 ? _a : "";
|
|
179
|
+
break;
|
|
180
|
+
case "configuretenantflow":
|
|
181
|
+
action = ResourceAction.CONFIGURE;
|
|
182
|
+
resourceId = (_b = input.connectorId) !== null && _b !== void 0 ? _b : "";
|
|
183
|
+
break;
|
|
184
|
+
case "deletetenantconfiguration":
|
|
185
|
+
action = ResourceAction.UNCONFIGURE;
|
|
186
|
+
resourceId = (_c = input.connectorId) !== null && _c !== void 0 ? _c : "";
|
|
187
|
+
break;
|
|
188
|
+
case "createtenantconfiguration":
|
|
189
|
+
action = ResourceAction.ENABLE_CONFIGURATION;
|
|
190
|
+
resourceId = (_d = input.connectorId) !== null && _d !== void 0 ? _d : "";
|
|
191
|
+
break;
|
|
192
|
+
case "updatetenantconfiguration":
|
|
193
|
+
action = ResourceAction.UPDATE_CONFIGURATION;
|
|
194
|
+
resourceId = (_e = input.connectorId) !== null && _e !== void 0 ? _e : "";
|
|
195
|
+
break;
|
|
196
|
+
case "disabletenantconfig":
|
|
197
|
+
action = ResourceAction.DISABLE_CONFIGURATION;
|
|
198
|
+
resourceId = (_f = input.connectorId) !== null && _f !== void 0 ? _f : "";
|
|
199
|
+
break;
|
|
200
|
+
case "deletetenantconfig":
|
|
201
|
+
action = ResourceAction.DELETE_CONFIGURATION;
|
|
202
|
+
resourceId = (_g = input.connectorId) !== null && _g !== void 0 ? _g : "";
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
resourceId = (_j = (_h = input.clientId) !== null && _h !== void 0 ? _h : input.projectId) !== null && _j !== void 0 ? _j : "";
|
|
206
|
+
}
|
|
207
|
+
return { action, resourceId };
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
console.error("Error parsing custom auth context:", error);
|
|
211
|
+
return {};
|
|
212
|
+
}
|
|
213
|
+
};
|
|
422
214
|
const addCustomAuthContextHeader = (headers, context) => {
|
|
423
215
|
try {
|
|
424
216
|
const contextString = JSON.stringify(context);
|
|
@@ -691,92 +483,365 @@ function populateFormDataInUiCode(uiCodeString, formData) {
|
|
|
691
483
|
else {
|
|
692
484
|
acc[key] = target[key];
|
|
693
485
|
}
|
|
694
|
-
return acc;
|
|
695
|
-
}, {});
|
|
696
|
-
return Object.assign(Object.assign({}, uiCode), { target: updatedTarget });
|
|
697
|
-
}
|
|
698
|
-
else if (targetType === "array" && Array.isArray(target)) {
|
|
699
|
-
const updatedTarget = target.map((item, index) => {
|
|
700
|
-
const updatedItem = Object.assign({}, item);
|
|
701
|
-
// Assuming item has a unique key (e.g., id or name) to match formData fields
|
|
702
|
-
Object.keys(item).forEach((key) => {
|
|
703
|
-
var _a, _b;
|
|
704
|
-
const formValue = (_a = formData[`${index}.${key}`]) !== null && _a !== void 0 ? _a : formData[key];
|
|
705
|
-
if (formValue !== undefined) {
|
|
706
|
-
updatedItem[key] = Object.assign(Object.assign({}, item[key]), { target: (_b = convertFormDataToUiCodeFormData(formValue)) === null || _b === void 0 ? void 0 : _b.target });
|
|
707
|
-
}
|
|
708
|
-
});
|
|
709
|
-
return updatedItem;
|
|
710
|
-
});
|
|
711
|
-
return Object.assign(Object.assign({}, uiCode), { target: updatedTarget });
|
|
486
|
+
return acc;
|
|
487
|
+
}, {});
|
|
488
|
+
return Object.assign(Object.assign({}, uiCode), { target: updatedTarget });
|
|
489
|
+
}
|
|
490
|
+
else if (targetType === "array" && Array.isArray(target)) {
|
|
491
|
+
const updatedTarget = target.map((item, index) => {
|
|
492
|
+
const updatedItem = Object.assign({}, item);
|
|
493
|
+
// Assuming item has a unique key (e.g., id or name) to match formData fields
|
|
494
|
+
Object.keys(item).forEach((key) => {
|
|
495
|
+
var _a, _b;
|
|
496
|
+
const formValue = (_a = formData[`${index}.${key}`]) !== null && _a !== void 0 ? _a : formData[key];
|
|
497
|
+
if (formValue !== undefined) {
|
|
498
|
+
updatedItem[key] = Object.assign(Object.assign({}, item[key]), { target: (_b = convertFormDataToUiCodeFormData(formValue)) === null || _b === void 0 ? void 0 : _b.target });
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
return updatedItem;
|
|
502
|
+
});
|
|
503
|
+
return Object.assign(Object.assign({}, uiCode), { target: updatedTarget });
|
|
504
|
+
}
|
|
505
|
+
return uiCode;
|
|
506
|
+
}
|
|
507
|
+
const convertFormDataToUiCodeFormData = (formData) => {
|
|
508
|
+
if (Array.isArray(formData)) {
|
|
509
|
+
return {
|
|
510
|
+
actionType: "map",
|
|
511
|
+
targetType: "array",
|
|
512
|
+
target: formData.map((item) => convertFormDataToUiCodeFormData(item)),
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
else if (formData !== null && typeof formData === "object") {
|
|
516
|
+
const target = {};
|
|
517
|
+
for (const key in formData) {
|
|
518
|
+
target[key] = convertFormDataToUiCodeFormData(formData[key]);
|
|
519
|
+
}
|
|
520
|
+
return {
|
|
521
|
+
actionType: "map",
|
|
522
|
+
targetType: "object",
|
|
523
|
+
target,
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
else if (typeof formData === "string") {
|
|
527
|
+
return {
|
|
528
|
+
actionType: "map",
|
|
529
|
+
targetType: "string",
|
|
530
|
+
target: formData,
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
else if (typeof formData === "number") {
|
|
534
|
+
return {
|
|
535
|
+
actionType: "map",
|
|
536
|
+
targetType: "number",
|
|
537
|
+
target: formData,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
else if (typeof formData === "boolean") {
|
|
541
|
+
return {
|
|
542
|
+
actionType: "map",
|
|
543
|
+
targetType: "boolean",
|
|
544
|
+
target: formData,
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
return {
|
|
549
|
+
actionType: "map",
|
|
550
|
+
targetType: "string",
|
|
551
|
+
target: formData,
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
/**
|
|
556
|
+
* Recursively removes __typename fields from an object or array.
|
|
557
|
+
*/
|
|
558
|
+
function stripTypename(obj) {
|
|
559
|
+
if (Array.isArray(obj)) {
|
|
560
|
+
return obj.map(stripTypename);
|
|
561
|
+
}
|
|
562
|
+
else if (obj && typeof obj === 'object') {
|
|
563
|
+
const newObj = {};
|
|
564
|
+
for (const key in obj) {
|
|
565
|
+
if (key === '__typename')
|
|
566
|
+
continue;
|
|
567
|
+
newObj[key] = stripTypename(obj[key]);
|
|
568
|
+
}
|
|
569
|
+
return newObj;
|
|
570
|
+
}
|
|
571
|
+
return obj;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// GraphQL endpoint (customize as needed)
|
|
575
|
+
const GRAPHQL_ENDPOINT = "/graphql";
|
|
576
|
+
// Utility to perform GraphQL queries/mutations using fetch
|
|
577
|
+
async function fetchGraphQL({ query, variables, operationName }) {
|
|
578
|
+
const config = getConfig();
|
|
579
|
+
const response = await fetch(config.baseUrl + GRAPHQL_ENDPOINT, {
|
|
580
|
+
method: "POST",
|
|
581
|
+
headers: {
|
|
582
|
+
"Content-Type": "application/json",
|
|
583
|
+
authorization: `Bearer ${config.authToken}`,
|
|
584
|
+
realm: REALM,
|
|
585
|
+
[CUSTOM_AUTH_HEADER_KEY]: String(config.customAuth),
|
|
586
|
+
[PROJECT_ID_HEADER_KEY]: config.spaceId,
|
|
587
|
+
[TENANT_ID_HEADER_KEY]: config.tenantId,
|
|
588
|
+
[REQUEST_TRACE_ID_HEADER_KEY]: `react-ai-core-${v4()}`,
|
|
589
|
+
[CUSTOM_AUTH_CONTEXT_HEADER_KEY]: getCustomAuthContextValue(operationName, variables),
|
|
590
|
+
},
|
|
591
|
+
body: JSON.stringify({ query, variables }),
|
|
592
|
+
});
|
|
593
|
+
if (!response.ok) {
|
|
594
|
+
switch (response.status) {
|
|
595
|
+
case 401:
|
|
596
|
+
throw new Error("Unauthorized: Please check your auth token");
|
|
597
|
+
case 403:
|
|
598
|
+
throw new Error("Forbidden: Please check your access");
|
|
599
|
+
case 404:
|
|
600
|
+
throw new Error("Not Found: Please check your request");
|
|
601
|
+
default:
|
|
602
|
+
throw new Error("Failed to fetch: Please check your request");
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
const result = await response.json();
|
|
606
|
+
if (result.errors) {
|
|
607
|
+
throw new Error(result.errors.map((e) => e.message).join("; "));
|
|
608
|
+
}
|
|
609
|
+
return {
|
|
610
|
+
data: result.data,
|
|
611
|
+
errors: result.errors
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
// GraphQL Queries & Mutations (as plain strings)
|
|
615
|
+
const GET_WIDGET_CONNECTORS = `
|
|
616
|
+
query Connectors($input: GetConnectorsListInput!) {
|
|
617
|
+
connectors(input: $input) {
|
|
618
|
+
name
|
|
619
|
+
id
|
|
620
|
+
imageUri
|
|
621
|
+
description
|
|
622
|
+
content
|
|
623
|
+
actions {
|
|
624
|
+
name
|
|
625
|
+
handler
|
|
626
|
+
actionType
|
|
627
|
+
activatedStateLabel
|
|
628
|
+
content
|
|
629
|
+
shows
|
|
630
|
+
handlerPayload
|
|
631
|
+
multiConnectorWidgetConnectors {
|
|
632
|
+
name
|
|
633
|
+
id
|
|
634
|
+
imageUri
|
|
635
|
+
description
|
|
636
|
+
content
|
|
637
|
+
connectionId
|
|
638
|
+
actions {
|
|
639
|
+
name
|
|
640
|
+
handler
|
|
641
|
+
actionType
|
|
642
|
+
activatedStateLabel
|
|
643
|
+
content
|
|
644
|
+
shows
|
|
645
|
+
handlerPayload
|
|
646
|
+
}
|
|
647
|
+
events {
|
|
648
|
+
name
|
|
649
|
+
eventId
|
|
650
|
+
content
|
|
651
|
+
payload
|
|
652
|
+
}
|
|
653
|
+
connectedConnectors {
|
|
654
|
+
id
|
|
655
|
+
imageUrl
|
|
656
|
+
clientId
|
|
657
|
+
name
|
|
658
|
+
enableActivate
|
|
659
|
+
activateStatus
|
|
660
|
+
authMethods {
|
|
661
|
+
title
|
|
662
|
+
inputContract
|
|
663
|
+
type
|
|
664
|
+
details
|
|
665
|
+
isDefault
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
status
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
events {
|
|
672
|
+
name
|
|
673
|
+
eventId
|
|
674
|
+
content
|
|
675
|
+
payload
|
|
676
|
+
}
|
|
677
|
+
connectedConnectors {
|
|
678
|
+
id
|
|
679
|
+
imageUrl
|
|
680
|
+
clientId
|
|
681
|
+
name
|
|
682
|
+
enableActivate
|
|
683
|
+
activateStatus
|
|
684
|
+
authMethods {
|
|
685
|
+
title
|
|
686
|
+
inputContract
|
|
687
|
+
type
|
|
688
|
+
details
|
|
689
|
+
isDefault
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
status
|
|
712
693
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
const
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
694
|
+
}
|
|
695
|
+
`;
|
|
696
|
+
const SAVE_ACTIVATE_CONNECTOR_STATUS = `
|
|
697
|
+
mutation SaveActivateConnectorStatus(
|
|
698
|
+
$input: SaveWidgetConnectorStatusInput!
|
|
699
|
+
) {
|
|
700
|
+
saveWidgetConnectorStatus(input: $input)
|
|
701
|
+
}
|
|
702
|
+
`;
|
|
703
|
+
const DEACTIVATE_CONNECTOR = `
|
|
704
|
+
mutation DeactivateConnector($input: DeactivateConnectorInput!) {
|
|
705
|
+
deactivateConnector(input: $input)
|
|
706
|
+
}
|
|
707
|
+
`;
|
|
708
|
+
const GET_FIELD_DATA_QUERY = `
|
|
709
|
+
query executeGetFieldDataFlow($input: ApiPrimaryResolverInvocationInput!) {
|
|
710
|
+
executeGetFieldDataFlow(input: $input) {
|
|
711
|
+
data
|
|
722
712
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
713
|
+
}
|
|
714
|
+
`;
|
|
715
|
+
const GET_TENANT_CONFIGURATIONS = `
|
|
716
|
+
query GetConfigurationSubscription($input: ConfigurationSubscriptionInput!) {
|
|
717
|
+
getConfigurationSubscription(input: $input) {
|
|
718
|
+
connector {
|
|
719
|
+
id
|
|
720
|
+
name
|
|
721
|
+
description
|
|
722
|
+
imageUri
|
|
723
|
+
status
|
|
724
|
+
active
|
|
725
|
+
actions {
|
|
726
|
+
name
|
|
727
|
+
handler
|
|
728
|
+
actionType
|
|
727
729
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
730
|
+
connectedConnectors {
|
|
731
|
+
id
|
|
732
|
+
name
|
|
733
|
+
clientId
|
|
734
|
+
imageUrl
|
|
735
|
+
enableActivate
|
|
736
|
+
activateStatus
|
|
737
|
+
authMethods {
|
|
738
|
+
title
|
|
739
|
+
inputContract
|
|
740
|
+
type
|
|
741
|
+
details
|
|
742
|
+
isDefault
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
status
|
|
747
|
+
metaData
|
|
740
748
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
749
|
+
}
|
|
750
|
+
`;
|
|
751
|
+
const GET_TENANT_CONFIGURATIONS_BY_ID = `
|
|
752
|
+
query GetConfigurationSubscription($input: GetTenantConfigurationsInput) {
|
|
753
|
+
tenantConfigurationsById(input: $input) {
|
|
754
|
+
uiCode
|
|
755
|
+
flowId
|
|
756
|
+
stepId
|
|
757
|
+
status
|
|
758
|
+
configurations
|
|
759
|
+
configuredStepSetting {
|
|
760
|
+
keyIsEditable
|
|
761
|
+
addButton {
|
|
762
|
+
label
|
|
763
|
+
isDisabled
|
|
764
|
+
fieldsLimit
|
|
765
|
+
}
|
|
766
|
+
description
|
|
767
|
+
label
|
|
768
|
+
validation {
|
|
769
|
+
fieldValidation
|
|
770
|
+
submitValidation
|
|
771
|
+
modelId
|
|
772
|
+
jsonSchema
|
|
773
|
+
submitValidationFunction
|
|
774
|
+
}
|
|
775
|
+
}
|
|
747
776
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
777
|
+
}
|
|
778
|
+
`;
|
|
779
|
+
const CREATE_TENANT_CONFIGURATION = `
|
|
780
|
+
mutation CreateTenantConfiguration($input: TenantConfigurationsInput!) {
|
|
781
|
+
createTenantConfiguration(input: $input) {
|
|
782
|
+
id
|
|
754
783
|
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
784
|
+
}
|
|
785
|
+
`;
|
|
786
|
+
const UPDATE_TENANT_CONFIGURATION = `
|
|
787
|
+
mutation UpdateTenantConfiguration($input: TenantConfigurationsInput!) {
|
|
788
|
+
updateTenantConfiguration(input: $input) {
|
|
789
|
+
id
|
|
761
790
|
}
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
return obj.map(stripTypename);
|
|
791
|
+
}
|
|
792
|
+
`;
|
|
793
|
+
const DELETE_TENANT_CONFIG = `
|
|
794
|
+
mutation DeleteTenantConfig($input: GetTenantConfigurationsInput!) {
|
|
795
|
+
deleteTenantConfig(input: $input) {
|
|
796
|
+
id
|
|
769
797
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
}
|
|
777
|
-
return newObj;
|
|
798
|
+
}
|
|
799
|
+
`;
|
|
800
|
+
const DISABLE_TENANT_CONFIG = `
|
|
801
|
+
mutation DisableTenantConfig($input: GetTenantConfigurationsInput!) {
|
|
802
|
+
disableTenantConfig(input: $input) {
|
|
803
|
+
id
|
|
778
804
|
}
|
|
779
|
-
|
|
805
|
+
}
|
|
806
|
+
`;
|
|
807
|
+
const GENERATE_ACCESS_TOKEN = `
|
|
808
|
+
query GenerateAccessToken($input: ConnectorConnectionInput!) {
|
|
809
|
+
connectorConnection(input: $input)
|
|
810
|
+
}
|
|
811
|
+
`;
|
|
812
|
+
// Refactored functions using fetchGraphQL
|
|
813
|
+
async function getConnectors$1(variables) {
|
|
814
|
+
return fetchGraphQL({ query: GET_WIDGET_CONNECTORS, variables, operationName: "connectors" });
|
|
815
|
+
}
|
|
816
|
+
async function saveActivateConnectorStatus(variables) {
|
|
817
|
+
return fetchGraphQL({ query: SAVE_ACTIVATE_CONNECTOR_STATUS, variables, operationName: "saveactivatconnectorstatus" });
|
|
818
|
+
}
|
|
819
|
+
async function deactivateConnector$1(variables) {
|
|
820
|
+
return fetchGraphQL({ query: DEACTIVATE_CONNECTOR, variables, operationName: "deactivateConnector" });
|
|
821
|
+
}
|
|
822
|
+
async function getFieldData(variables) {
|
|
823
|
+
return fetchGraphQL({ query: GET_FIELD_DATA_QUERY, variables, operationName: "executeGetFieldDataFlow" });
|
|
824
|
+
}
|
|
825
|
+
async function getConfigurationSubscriptions(variables) {
|
|
826
|
+
return fetchGraphQL({ query: GET_TENANT_CONFIGURATIONS, variables, operationName: "getconfigurationsubscription" });
|
|
827
|
+
}
|
|
828
|
+
async function getConfigurationSubscriptionById(variables) {
|
|
829
|
+
return fetchGraphQL({ query: GET_TENANT_CONFIGURATIONS_BY_ID, variables, operationName: "getconfigurationsubscriptionbyid" });
|
|
830
|
+
}
|
|
831
|
+
async function createTenantConfiguration(variables) {
|
|
832
|
+
return fetchGraphQL({ query: CREATE_TENANT_CONFIGURATION, variables, operationName: "createtenantconfiguration" });
|
|
833
|
+
}
|
|
834
|
+
async function updateTenantConfiguration(variables) {
|
|
835
|
+
return fetchGraphQL({ query: UPDATE_TENANT_CONFIGURATION, variables, operationName: "updatetenantconfiguration" });
|
|
836
|
+
}
|
|
837
|
+
async function deleteTenantConfig(variables) {
|
|
838
|
+
return fetchGraphQL({ query: DELETE_TENANT_CONFIG, variables, operationName: "deletetenantconfig" });
|
|
839
|
+
}
|
|
840
|
+
async function disableTenantConfig(variables) {
|
|
841
|
+
return fetchGraphQL({ query: DISABLE_TENANT_CONFIG, variables, operationName: "disabletenantconfig" });
|
|
842
|
+
}
|
|
843
|
+
async function generateAccessToken(variables) {
|
|
844
|
+
return fetchGraphQL({ query: GENERATE_ACCESS_TOKEN, variables, operationName: "generateaccesstoken" });
|
|
780
845
|
}
|
|
781
846
|
|
|
782
847
|
/**
|
|
@@ -847,7 +912,7 @@ const callActivateConnector = async (input, headers) => {
|
|
|
847
912
|
const url = config.baseUrl + ACTIVATE_CONNECTOR_URL;
|
|
848
913
|
const response = await fetch(url, {
|
|
849
914
|
method: "POST",
|
|
850
|
-
headers: Object.assign(Object.assign({ "Content-Type": "application/json" }, headers), { "x-fastn-api-key": ACTIVATE_CONNECTOR_ACCESS_KEY, "x-fastn-space-id": ACTIVATE_CONNECTOR_PROJECT_ID, "x-fastn-space-client-id": config.spaceId }),
|
|
915
|
+
headers: Object.assign(Object.assign({ "Content-Type": "application/json" }, headers), { "x-fastn-api-key": ACTIVATE_CONNECTOR_ACCESS_KEY, "x-fastn-space-id": ACTIVATE_CONNECTOR_PROJECT_ID, "x-fastn-space-client-id": config.spaceId, 'stage': "LIVE" }),
|
|
851
916
|
body: JSON.stringify({
|
|
852
917
|
input
|
|
853
918
|
})
|
|
@@ -954,7 +1019,7 @@ const deactivateConnector = async ({ connectorId, action, }) => {
|
|
|
954
1019
|
const config = getConfig();
|
|
955
1020
|
// Execute the action handler
|
|
956
1021
|
let response = {};
|
|
957
|
-
response = await executeActionHandler(action === null || action === void 0 ? void 0 : action.handler, addCustomAuthContextHeader({}, { resourceId: connectorId, action: ResourceAction.
|
|
1022
|
+
response = await executeActionHandler(action === null || action === void 0 ? void 0 : action.handler, addCustomAuthContextHeader({}, { resourceId: connectorId, action: ResourceAction.DEACTIVATION }));
|
|
958
1023
|
// Deactivate the connector
|
|
959
1024
|
await deactivateConnector$1({
|
|
960
1025
|
input: {
|