@dev-fastn-ai/react-core 1.0.4 → 1.0.5
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/index.cjs.js +428 -470
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +428 -470
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -16848,11 +16848,11 @@ function v4(options, buf, offset) {
|
|
|
16848
16848
|
return unsafeStringify(rnds);
|
|
16849
16849
|
}
|
|
16850
16850
|
|
|
16851
|
-
const customFetch =
|
|
16851
|
+
const customFetch = async (url, options, retryCount = 0) => {
|
|
16852
16852
|
const config = getConfig();
|
|
16853
16853
|
if (!config.authToken) {
|
|
16854
16854
|
if (retryCount < 3) {
|
|
16855
|
-
|
|
16855
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
16856
16856
|
return customFetch(url, options, retryCount + 1);
|
|
16857
16857
|
}
|
|
16858
16858
|
else {
|
|
@@ -16864,12 +16864,12 @@ const customFetch = (url_1, options_1, ...args_1) => __awaiter(void 0, [url_1, o
|
|
|
16864
16864
|
}
|
|
16865
16865
|
const headers = Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.headers), { authorization: `Bearer ${config.authToken}` });
|
|
16866
16866
|
addCustomAuthContextHeader(headers, getCustomAuthContext(options));
|
|
16867
|
-
const response =
|
|
16867
|
+
const response = await fetch(config.baseUrl + "/graphql", Object.assign(Object.assign({}, options), { headers }));
|
|
16868
16868
|
if (response.status === 401) {
|
|
16869
16869
|
throw new Error("Authentication token is invalid or expired");
|
|
16870
16870
|
}
|
|
16871
16871
|
return response;
|
|
16872
|
-
}
|
|
16872
|
+
};
|
|
16873
16873
|
let apolloClient = null;
|
|
16874
16874
|
function makeApolloClient() {
|
|
16875
16875
|
const config = getConfig();
|
|
@@ -17194,103 +17194,81 @@ const GENERATE_ACCESS_TOKEN = gql `
|
|
|
17194
17194
|
connectorConnection(input: $input)
|
|
17195
17195
|
}
|
|
17196
17196
|
`;
|
|
17197
|
-
function getConnectors$1(variables) {
|
|
17198
|
-
|
|
17199
|
-
|
|
17200
|
-
|
|
17201
|
-
|
|
17202
|
-
variables,
|
|
17203
|
-
});
|
|
17197
|
+
async function getConnectors$1(variables) {
|
|
17198
|
+
const apolloClient = getApolloClient();
|
|
17199
|
+
return apolloClient.query({
|
|
17200
|
+
query: GET_WIDGET_CONNECTORS,
|
|
17201
|
+
variables,
|
|
17204
17202
|
});
|
|
17205
17203
|
}
|
|
17206
|
-
function saveActivateConnectorStatus(variables) {
|
|
17207
|
-
|
|
17208
|
-
|
|
17209
|
-
|
|
17210
|
-
|
|
17211
|
-
variables,
|
|
17212
|
-
});
|
|
17204
|
+
async function saveActivateConnectorStatus(variables) {
|
|
17205
|
+
const apolloClient = getApolloClient();
|
|
17206
|
+
return apolloClient.mutate({
|
|
17207
|
+
mutation: SAVE_ACTIVATE_CONNECTOR_STATUS,
|
|
17208
|
+
variables,
|
|
17213
17209
|
});
|
|
17214
17210
|
}
|
|
17215
|
-
function deactivateConnector$1(variables) {
|
|
17216
|
-
|
|
17217
|
-
|
|
17218
|
-
|
|
17219
|
-
|
|
17220
|
-
variables,
|
|
17221
|
-
});
|
|
17211
|
+
async function deactivateConnector$1(variables) {
|
|
17212
|
+
const apolloClient = getApolloClient();
|
|
17213
|
+
return apolloClient.mutate({
|
|
17214
|
+
mutation: DEACTIVATE_CONNECTOR,
|
|
17215
|
+
variables,
|
|
17222
17216
|
});
|
|
17223
17217
|
}
|
|
17224
|
-
function deleteTenantConfiguration(variables) {
|
|
17225
|
-
|
|
17226
|
-
|
|
17227
|
-
|
|
17228
|
-
|
|
17229
|
-
variables,
|
|
17230
|
-
});
|
|
17218
|
+
async function deleteTenantConfiguration(variables) {
|
|
17219
|
+
const apolloClient = getApolloClient();
|
|
17220
|
+
return apolloClient.mutate({
|
|
17221
|
+
mutation: DELETE_TENANT_CONFIGURATION,
|
|
17222
|
+
variables,
|
|
17231
17223
|
});
|
|
17232
17224
|
}
|
|
17233
|
-
function getFieldData(variables) {
|
|
17234
|
-
|
|
17235
|
-
|
|
17236
|
-
|
|
17237
|
-
|
|
17238
|
-
variables,
|
|
17239
|
-
});
|
|
17225
|
+
async function getFieldData(variables) {
|
|
17226
|
+
const apolloClient = getApolloClient();
|
|
17227
|
+
return apolloClient.query({
|
|
17228
|
+
query: GET_FIELD_DATA_QUERY,
|
|
17229
|
+
variables,
|
|
17240
17230
|
});
|
|
17241
17231
|
}
|
|
17242
|
-
function getConfigurationSubscriptions(variables) {
|
|
17243
|
-
|
|
17244
|
-
|
|
17245
|
-
|
|
17246
|
-
|
|
17247
|
-
variables,
|
|
17248
|
-
});
|
|
17232
|
+
async function getConfigurationSubscriptions(variables) {
|
|
17233
|
+
const apolloClient = getApolloClient();
|
|
17234
|
+
return apolloClient.query({
|
|
17235
|
+
query: GET_TENANT_CONFIGURATIONS,
|
|
17236
|
+
variables,
|
|
17249
17237
|
});
|
|
17250
17238
|
}
|
|
17251
|
-
function getConfigurationSubscriptionById(variables) {
|
|
17252
|
-
|
|
17253
|
-
|
|
17254
|
-
|
|
17255
|
-
|
|
17256
|
-
variables,
|
|
17257
|
-
});
|
|
17239
|
+
async function getConfigurationSubscriptionById(variables) {
|
|
17240
|
+
const apolloClient = getApolloClient();
|
|
17241
|
+
return apolloClient.query({
|
|
17242
|
+
query: GET_TENANT_CONFIGURATIONS_BY_ID,
|
|
17243
|
+
variables,
|
|
17258
17244
|
});
|
|
17259
17245
|
}
|
|
17260
|
-
function createTenantConfiguration(variables) {
|
|
17261
|
-
|
|
17262
|
-
|
|
17263
|
-
|
|
17264
|
-
|
|
17265
|
-
variables,
|
|
17266
|
-
});
|
|
17246
|
+
async function createTenantConfiguration(variables) {
|
|
17247
|
+
const apolloClient = getApolloClient();
|
|
17248
|
+
return apolloClient.mutate({
|
|
17249
|
+
mutation: CREATE_TENANT_CONFIGURATION,
|
|
17250
|
+
variables,
|
|
17267
17251
|
});
|
|
17268
17252
|
}
|
|
17269
|
-
function updateTenantConfiguration(variables) {
|
|
17270
|
-
|
|
17271
|
-
|
|
17272
|
-
|
|
17273
|
-
|
|
17274
|
-
variables,
|
|
17275
|
-
});
|
|
17253
|
+
async function updateTenantConfiguration(variables) {
|
|
17254
|
+
const apolloClient = getApolloClient();
|
|
17255
|
+
return apolloClient.mutate({
|
|
17256
|
+
mutation: UPDATE_TENANT_CONFIGURATION,
|
|
17257
|
+
variables,
|
|
17276
17258
|
});
|
|
17277
17259
|
}
|
|
17278
|
-
function disableTenantConfig(variables) {
|
|
17279
|
-
|
|
17280
|
-
|
|
17281
|
-
|
|
17282
|
-
|
|
17283
|
-
variables,
|
|
17284
|
-
});
|
|
17260
|
+
async function disableTenantConfig(variables) {
|
|
17261
|
+
const apolloClient = getApolloClient();
|
|
17262
|
+
return apolloClient.mutate({
|
|
17263
|
+
mutation: DISABLE_TENANT_CONFIG,
|
|
17264
|
+
variables,
|
|
17285
17265
|
});
|
|
17286
17266
|
}
|
|
17287
|
-
function generateAccessToken(variables) {
|
|
17288
|
-
|
|
17289
|
-
|
|
17290
|
-
|
|
17291
|
-
|
|
17292
|
-
variables,
|
|
17293
|
-
});
|
|
17267
|
+
async function generateAccessToken(variables) {
|
|
17268
|
+
const apolloClient = getApolloClient();
|
|
17269
|
+
return apolloClient.query({
|
|
17270
|
+
query: GENERATE_ACCESS_TOKEN,
|
|
17271
|
+
variables,
|
|
17294
17272
|
});
|
|
17295
17273
|
}
|
|
17296
17274
|
|
|
@@ -17306,11 +17284,11 @@ const getBackendUrl = () => {
|
|
|
17306
17284
|
* Executes a backend flow with the given path, input, and headers.
|
|
17307
17285
|
* @returns {Promise<any>} The response data from the backend.
|
|
17308
17286
|
*/
|
|
17309
|
-
const executeFLow =
|
|
17287
|
+
const executeFLow = async ({ path, input = {}, headers = {} }) => {
|
|
17310
17288
|
try {
|
|
17311
17289
|
const config = getConfig();
|
|
17312
17290
|
const backendUrl = getBackendUrl();
|
|
17313
|
-
const response =
|
|
17291
|
+
const response = await fetch(`${backendUrl}/${path}`, {
|
|
17314
17292
|
method: "POST",
|
|
17315
17293
|
headers: Object.assign({ "Content-Type": "application/json", [PROJECT_ID_HEADER_KEY]: config.spaceId, [TENANT_ID_HEADER_KEY]: config.tenantId, authorization: `${config.authToken}`, stage: config.environment }, headers),
|
|
17316
17294
|
body: JSON.stringify({
|
|
@@ -17320,14 +17298,14 @@ const executeFLow = (_a) => __awaiter(void 0, [_a], void 0, function* ({ path, i
|
|
|
17320
17298
|
if (!response.ok) {
|
|
17321
17299
|
throw new Error(`Failed to execute flow: ${response.statusText}`);
|
|
17322
17300
|
}
|
|
17323
|
-
const data =
|
|
17301
|
+
const data = await response.json();
|
|
17324
17302
|
return data;
|
|
17325
17303
|
}
|
|
17326
17304
|
catch (error) {
|
|
17327
17305
|
console.error("Error in executeFLow:", error);
|
|
17328
17306
|
throw error;
|
|
17329
17307
|
}
|
|
17330
|
-
}
|
|
17308
|
+
};
|
|
17331
17309
|
|
|
17332
17310
|
/**
|
|
17333
17311
|
* Builds the request input for connector activation.
|
|
@@ -17357,10 +17335,10 @@ const buildRequestInput = (dependencyConnector, authMethod, formData) => {
|
|
|
17357
17335
|
/**
|
|
17358
17336
|
* Calls the backend to activate a connector.
|
|
17359
17337
|
*/
|
|
17360
|
-
const callActivateConnector = (input, headers) =>
|
|
17338
|
+
const callActivateConnector = async (input, headers) => {
|
|
17361
17339
|
const config = getConfig();
|
|
17362
17340
|
const url = config.baseUrl + ACTIVATE_CONNECTOR_URL;
|
|
17363
|
-
const response =
|
|
17341
|
+
const response = await fetch(url, {
|
|
17364
17342
|
method: "POST",
|
|
17365
17343
|
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 }),
|
|
17366
17344
|
body: JSON.stringify({
|
|
@@ -17370,20 +17348,20 @@ const callActivateConnector = (input, headers) => __awaiter(void 0, void 0, void
|
|
|
17370
17348
|
if (!response.ok) {
|
|
17371
17349
|
throw new Error(`Failed to activate connector: ${response.statusText}`);
|
|
17372
17350
|
}
|
|
17373
|
-
const responseData =
|
|
17351
|
+
const responseData = await response.json();
|
|
17374
17352
|
return responseData.data;
|
|
17375
|
-
}
|
|
17353
|
+
};
|
|
17376
17354
|
/**
|
|
17377
17355
|
* Handles the OAuth flow for connector activation.
|
|
17378
17356
|
*/
|
|
17379
|
-
const handleOauthFlow = (authMethod, formData, input) =>
|
|
17357
|
+
const handleOauthFlow = async (authMethod, formData, input) => {
|
|
17380
17358
|
const config = getConfig();
|
|
17381
17359
|
const authUrl = generateAuthUrl({ oauthDetails: authMethod.details, formData });
|
|
17382
17360
|
const { width, height, top, left } = getOauthPopUpDimensions();
|
|
17383
17361
|
const oAuthPopUpWindow = window.open(authUrl, "OAuthPopup", `width=${width},height=${height},top=${top},left=${left}`);
|
|
17384
17362
|
return new Promise((resolve, reject) => {
|
|
17385
17363
|
let params = null;
|
|
17386
|
-
const messageListener = (event) =>
|
|
17364
|
+
const messageListener = async (event) => {
|
|
17387
17365
|
var _a;
|
|
17388
17366
|
if (event.origin === PROD_OAUTH_REDIRECT_URL && ((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === "oauth_complete" && !params) {
|
|
17389
17367
|
params = getParams(event.data.params);
|
|
@@ -17391,7 +17369,7 @@ const handleOauthFlow = (authMethod, formData, input) => __awaiter(void 0, void
|
|
|
17391
17369
|
clearInterval(closePopupInterval);
|
|
17392
17370
|
try {
|
|
17393
17371
|
input.oauth.response = params;
|
|
17394
|
-
const data =
|
|
17372
|
+
const data = await callActivateConnector(input, {
|
|
17395
17373
|
[TENANT_ID_HEADER_KEY]: config === null || config === void 0 ? void 0 : config.tenantId,
|
|
17396
17374
|
[CUSTOM_AUTH_HEADER_KEY]: String(config === null || config === void 0 ? void 0 : config.customAuth),
|
|
17397
17375
|
authorization: config === null || config === void 0 ? void 0 : config.authToken
|
|
@@ -17405,7 +17383,7 @@ const handleOauthFlow = (authMethod, formData, input) => __awaiter(void 0, void
|
|
|
17405
17383
|
finally {
|
|
17406
17384
|
}
|
|
17407
17385
|
}
|
|
17408
|
-
}
|
|
17386
|
+
};
|
|
17409
17387
|
const closePopupInterval = setInterval(() => {
|
|
17410
17388
|
if (oAuthPopUpWindow.closed) {
|
|
17411
17389
|
clearInterval(closePopupInterval);
|
|
@@ -17420,17 +17398,17 @@ const handleOauthFlow = (authMethod, formData, input) => __awaiter(void 0, void
|
|
|
17420
17398
|
}, 1000);
|
|
17421
17399
|
window.addEventListener("message", messageListener);
|
|
17422
17400
|
});
|
|
17423
|
-
}
|
|
17401
|
+
};
|
|
17424
17402
|
/**
|
|
17425
17403
|
* Framework-agnostic activateConnector utility.
|
|
17426
17404
|
* @param args - Activation arguments (connectorId, action, dependencyConnector, authMethod, input, saveStatusFn, executeActionHandlerFn, config)
|
|
17427
17405
|
* @returns {Promise<{ status: string; data: any }>}
|
|
17428
17406
|
*/
|
|
17429
|
-
const activateConnector =
|
|
17407
|
+
const activateConnector = async ({ connectorId, action, dependencyConnector, authMethod, input = {}, }) => {
|
|
17430
17408
|
try {
|
|
17431
17409
|
const config = getConfig();
|
|
17432
17410
|
// Activate the connector
|
|
17433
|
-
let response =
|
|
17411
|
+
let response = await activateConnectorCore({
|
|
17434
17412
|
dependencyConnector,
|
|
17435
17413
|
authMethod,
|
|
17436
17414
|
formData: input,
|
|
@@ -17439,9 +17417,9 @@ const activateConnector = (_a) => __awaiter(void 0, [_a], void 0, function* ({ c
|
|
|
17439
17417
|
return response;
|
|
17440
17418
|
}
|
|
17441
17419
|
// Execute the action handler
|
|
17442
|
-
response =
|
|
17420
|
+
response = await executeActionHandler(action === null || action === void 0 ? void 0 : action.handler, addCustomAuthContextHeader({}, { resourceId: connectorId, action: ResourceAction.ACTIVATION }));
|
|
17443
17421
|
// Save connector status
|
|
17444
|
-
|
|
17422
|
+
await saveActivateConnectorStatus({
|
|
17445
17423
|
input: {
|
|
17446
17424
|
projectId: config.spaceId,
|
|
17447
17425
|
tenantId: config.tenantId,
|
|
@@ -17458,20 +17436,20 @@ const activateConnector = (_a) => __awaiter(void 0, [_a], void 0, function* ({ c
|
|
|
17458
17436
|
console.error("Error in activateConnector:", error);
|
|
17459
17437
|
throw error;
|
|
17460
17438
|
}
|
|
17461
|
-
}
|
|
17439
|
+
};
|
|
17462
17440
|
/**
|
|
17463
17441
|
* Framework-agnostic deactivateConnector utility.
|
|
17464
17442
|
* @param args - Deactivation arguments (connectorId, action, deactivateConnectorFn, executeActionHandlerFn, config)
|
|
17465
17443
|
* @returns {Promise<{ status: string; data: any }>}
|
|
17466
17444
|
*/
|
|
17467
|
-
const deactivateConnector =
|
|
17445
|
+
const deactivateConnector = async ({ connectorId, action, }) => {
|
|
17468
17446
|
try {
|
|
17469
17447
|
const config = getConfig();
|
|
17470
17448
|
// Execute the action handler
|
|
17471
17449
|
let response = {};
|
|
17472
|
-
response =
|
|
17450
|
+
response = await executeActionHandler(action === null || action === void 0 ? void 0 : action.handler, addCustomAuthContextHeader({}, { resourceId: connectorId, action: ResourceAction.ACTIVATION }));
|
|
17473
17451
|
// Deactivate the connector
|
|
17474
|
-
|
|
17452
|
+
await deactivateConnector$1({
|
|
17475
17453
|
input: {
|
|
17476
17454
|
projectId: config.spaceId,
|
|
17477
17455
|
tenantId: config.tenantId,
|
|
@@ -17487,14 +17465,14 @@ const deactivateConnector = (_a) => __awaiter(void 0, [_a], void 0, function* ({
|
|
|
17487
17465
|
console.error("Error in deactivateConnector:", error);
|
|
17488
17466
|
throw error;
|
|
17489
17467
|
}
|
|
17490
|
-
}
|
|
17468
|
+
};
|
|
17491
17469
|
/**
|
|
17492
17470
|
* Framework-agnostic executeActionHandler utility.
|
|
17493
17471
|
* @param handler - The handler path or function
|
|
17494
17472
|
* @param headers - Optional headers
|
|
17495
17473
|
* @returns {Promise<any>}
|
|
17496
17474
|
*/
|
|
17497
|
-
const executeActionHandler =
|
|
17475
|
+
const executeActionHandler = async (handler, headers = {}) => {
|
|
17498
17476
|
try {
|
|
17499
17477
|
if (!handler) {
|
|
17500
17478
|
return {
|
|
@@ -17502,24 +17480,24 @@ const executeActionHandler = (handler_1, ...args_1) => __awaiter(void 0, [handle
|
|
|
17502
17480
|
data: {},
|
|
17503
17481
|
};
|
|
17504
17482
|
}
|
|
17505
|
-
const response =
|
|
17483
|
+
const response = await executeFLow({ path: handler, headers });
|
|
17506
17484
|
return response;
|
|
17507
17485
|
}
|
|
17508
17486
|
catch (error) {
|
|
17509
17487
|
console.warn("Error executing action handler:", error);
|
|
17510
17488
|
throw error;
|
|
17511
17489
|
}
|
|
17512
|
-
}
|
|
17490
|
+
};
|
|
17513
17491
|
// Core activation logic for internal use
|
|
17514
|
-
const activateConnectorCore =
|
|
17492
|
+
const activateConnectorCore = async ({ dependencyConnector, authMethod, formData }) => {
|
|
17515
17493
|
try {
|
|
17516
17494
|
const input = buildRequestInput(dependencyConnector, authMethod, formData);
|
|
17517
17495
|
const isOauth = (authMethod === null || authMethod === void 0 ? void 0 : authMethod.type) === "OAUTH";
|
|
17518
17496
|
if (isOauth) {
|
|
17519
|
-
return
|
|
17497
|
+
return await handleOauthFlow(authMethod, formData, input);
|
|
17520
17498
|
}
|
|
17521
17499
|
const config = getConfig();
|
|
17522
|
-
const data =
|
|
17500
|
+
const data = await callActivateConnector(input, {
|
|
17523
17501
|
[TENANT_ID_HEADER_KEY]: config === null || config === void 0 ? void 0 : config.tenantId,
|
|
17524
17502
|
[CUSTOM_AUTH_HEADER_KEY]: String(config === null || config === void 0 ? void 0 : config.customAuth),
|
|
17525
17503
|
authorization: config === null || config === void 0 ? void 0 : config.authToken
|
|
@@ -17530,7 +17508,7 @@ const activateConnectorCore = (_a) => __awaiter(void 0, [_a], void 0, function*
|
|
|
17530
17508
|
console.error("Error in activateConnectorCore", error);
|
|
17531
17509
|
throw error;
|
|
17532
17510
|
}
|
|
17533
|
-
}
|
|
17511
|
+
};
|
|
17534
17512
|
|
|
17535
17513
|
const refetchFunctions = {};
|
|
17536
17514
|
const registerRefetchFunction = (input) => {
|
|
@@ -17545,111 +17523,109 @@ const REFETCH_KEY$2 = "connectors";
|
|
|
17545
17523
|
* Updates the global state store.
|
|
17546
17524
|
* @returns {Promise<Connector[]>}
|
|
17547
17525
|
*/
|
|
17548
|
-
function getConnectors() {
|
|
17549
|
-
|
|
17550
|
-
|
|
17551
|
-
|
|
17552
|
-
|
|
17553
|
-
|
|
17554
|
-
|
|
17555
|
-
|
|
17556
|
-
|
|
17557
|
-
|
|
17558
|
-
|
|
17559
|
-
|
|
17560
|
-
|
|
17561
|
-
const
|
|
17562
|
-
|
|
17563
|
-
|
|
17564
|
-
|
|
17565
|
-
if (action.actionType !== "ACTIVATION" && action.actionType !== "DEACTIVATION" && action.actionType !== "NONE") {
|
|
17566
|
-
return false;
|
|
17567
|
-
}
|
|
17568
|
-
if (!action.shows || action.shows === "ALWAYS") {
|
|
17569
|
-
return true;
|
|
17570
|
-
}
|
|
17571
|
-
if (action.shows === "WHEN_ACTIVE" && connector.status === "ACTIVE") {
|
|
17572
|
-
return true;
|
|
17573
|
-
}
|
|
17574
|
-
if (action.shows === "WHEN_INACTIVE" && connector.status === "INACTIVE") {
|
|
17575
|
-
return true;
|
|
17576
|
-
}
|
|
17526
|
+
async function getConnectors({ disabled = false, status = "ALL", refetch } = {}) {
|
|
17527
|
+
try {
|
|
17528
|
+
const config = getConfig();
|
|
17529
|
+
const { data } = await getConnectors$1({
|
|
17530
|
+
input: {
|
|
17531
|
+
projectId: config.spaceId,
|
|
17532
|
+
tenantId: config.tenantId,
|
|
17533
|
+
onlyActive: !disabled,
|
|
17534
|
+
environment: config.environment,
|
|
17535
|
+
},
|
|
17536
|
+
});
|
|
17537
|
+
const connectors = data === null || data === void 0 ? void 0 : data.connectors;
|
|
17538
|
+
const mappedConnectors = connectors.map((connector) => {
|
|
17539
|
+
const actions = (connector.actions || [])
|
|
17540
|
+
.filter((action) => {
|
|
17541
|
+
// Only allow ACTIVATION, DEACTIVATION, or NONE
|
|
17542
|
+
if (action.actionType !== "ACTIVATION" && action.actionType !== "DEACTIVATION" && action.actionType !== "NONE") {
|
|
17577
17543
|
return false;
|
|
17578
|
-
}
|
|
17579
|
-
|
|
17580
|
-
var _a, _b, _c, _d;
|
|
17581
|
-
const handler = (...args_1) => __awaiter(this, [...args_1], void 0, function* (formData = {}) {
|
|
17582
|
-
var _a, _b, _c, _d, _e;
|
|
17583
|
-
try {
|
|
17584
|
-
let response = null;
|
|
17585
|
-
if ((action === null || action === void 0 ? void 0 : action.actionType) === "ACTIVATION") {
|
|
17586
|
-
response = yield activateConnector({
|
|
17587
|
-
connectorId: connector.id,
|
|
17588
|
-
action,
|
|
17589
|
-
dependencyConnector: (_a = connector === null || connector === void 0 ? void 0 : connector.connectedConnectors) === null || _a === void 0 ? void 0 : _a[0],
|
|
17590
|
-
authMethod: (_d = (_c = (_b = connector === null || connector === void 0 ? void 0 : connector.connectedConnectors) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.authMethods) === null || _d === void 0 ? void 0 : _d[0],
|
|
17591
|
-
input: formData,
|
|
17592
|
-
});
|
|
17593
|
-
}
|
|
17594
|
-
else if ((action === null || action === void 0 ? void 0 : action.actionType) === "DEACTIVATION") {
|
|
17595
|
-
response = yield deactivateConnector({
|
|
17596
|
-
connectorId: connector.id,
|
|
17597
|
-
action,
|
|
17598
|
-
});
|
|
17599
|
-
yield (refetch === null || refetch === void 0 ? void 0 : refetch());
|
|
17600
|
-
}
|
|
17601
|
-
else {
|
|
17602
|
-
response = yield executeActionHandler(action === null || action === void 0 ? void 0 : action.handler);
|
|
17603
|
-
}
|
|
17604
|
-
yield ((_e = refetchFunctions[REFETCH_KEY$2]) === null || _e === void 0 ? void 0 : _e.call(refetchFunctions));
|
|
17605
|
-
return response;
|
|
17606
|
-
}
|
|
17607
|
-
catch (e) {
|
|
17608
|
-
return {
|
|
17609
|
-
data: {
|
|
17610
|
-
error: e instanceof Error ? e.message : "Unknown error",
|
|
17611
|
-
},
|
|
17612
|
-
status: "ERROR",
|
|
17613
|
-
};
|
|
17614
|
-
}
|
|
17615
|
-
});
|
|
17616
|
-
const form = inputContractToFormData((_d = (_c = (_b = (_a = connector === null || connector === void 0 ? void 0 : connector.connectedConnectors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.authMethods) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.inputContract);
|
|
17617
|
-
// Construct the action object with all properties at creation
|
|
17618
|
-
return Object.assign({ name: action.name, actionType: action.actionType, form }, (form
|
|
17619
|
-
? { onSubmit: (formData) => __awaiter(this, void 0, void 0, function* () { return yield handler(formData); }) }
|
|
17620
|
-
: { onClick: () => __awaiter(this, void 0, void 0, function* () { return yield handler(); }) }));
|
|
17621
|
-
});
|
|
17622
|
-
return {
|
|
17623
|
-
id: connector.id,
|
|
17624
|
-
name: connector.name,
|
|
17625
|
-
description: connector.description,
|
|
17626
|
-
imageUri: connector === null || connector === void 0 ? void 0 : connector.imageUri,
|
|
17627
|
-
status: connector.status,
|
|
17628
|
-
actions,
|
|
17629
|
-
};
|
|
17630
|
-
}).filter((connector) => {
|
|
17631
|
-
if (status === "ALL")
|
|
17544
|
+
}
|
|
17545
|
+
if (!action.shows || action.shows === "ALWAYS") {
|
|
17632
17546
|
return true;
|
|
17633
|
-
|
|
17547
|
+
}
|
|
17548
|
+
if (action.shows === "WHEN_ACTIVE" && connector.status === "ACTIVE") {
|
|
17634
17549
|
return true;
|
|
17635
|
-
|
|
17550
|
+
}
|
|
17551
|
+
if (action.shows === "WHEN_INACTIVE" && connector.status === "INACTIVE") {
|
|
17636
17552
|
return true;
|
|
17553
|
+
}
|
|
17637
17554
|
return false;
|
|
17555
|
+
})
|
|
17556
|
+
.map((action) => {
|
|
17557
|
+
var _a, _b, _c, _d;
|
|
17558
|
+
const handler = async (formData = {}) => {
|
|
17559
|
+
var _a, _b, _c, _d, _e;
|
|
17560
|
+
try {
|
|
17561
|
+
let response = null;
|
|
17562
|
+
if ((action === null || action === void 0 ? void 0 : action.actionType) === "ACTIVATION") {
|
|
17563
|
+
response = await activateConnector({
|
|
17564
|
+
connectorId: connector.id,
|
|
17565
|
+
action,
|
|
17566
|
+
dependencyConnector: (_a = connector === null || connector === void 0 ? void 0 : connector.connectedConnectors) === null || _a === void 0 ? void 0 : _a[0],
|
|
17567
|
+
authMethod: (_d = (_c = (_b = connector === null || connector === void 0 ? void 0 : connector.connectedConnectors) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.authMethods) === null || _d === void 0 ? void 0 : _d[0],
|
|
17568
|
+
input: formData,
|
|
17569
|
+
});
|
|
17570
|
+
}
|
|
17571
|
+
else if ((action === null || action === void 0 ? void 0 : action.actionType) === "DEACTIVATION") {
|
|
17572
|
+
response = await deactivateConnector({
|
|
17573
|
+
connectorId: connector.id,
|
|
17574
|
+
action,
|
|
17575
|
+
});
|
|
17576
|
+
await (refetch === null || refetch === void 0 ? void 0 : refetch());
|
|
17577
|
+
}
|
|
17578
|
+
else {
|
|
17579
|
+
response = await executeActionHandler(action === null || action === void 0 ? void 0 : action.handler);
|
|
17580
|
+
}
|
|
17581
|
+
await ((_e = refetchFunctions[REFETCH_KEY$2]) === null || _e === void 0 ? void 0 : _e.call(refetchFunctions));
|
|
17582
|
+
return response;
|
|
17583
|
+
}
|
|
17584
|
+
catch (e) {
|
|
17585
|
+
return {
|
|
17586
|
+
data: {
|
|
17587
|
+
error: e instanceof Error ? e.message : "Unknown error",
|
|
17588
|
+
},
|
|
17589
|
+
status: "ERROR",
|
|
17590
|
+
};
|
|
17591
|
+
}
|
|
17592
|
+
};
|
|
17593
|
+
const form = inputContractToFormData((_d = (_c = (_b = (_a = connector === null || connector === void 0 ? void 0 : connector.connectedConnectors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.authMethods) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.inputContract);
|
|
17594
|
+
// Construct the action object with all properties at creation
|
|
17595
|
+
return Object.assign({ name: action.name, actionType: action.actionType, form }, (form
|
|
17596
|
+
? { onSubmit: async (formData) => await handler(formData) }
|
|
17597
|
+
: { onClick: async () => await handler() }));
|
|
17638
17598
|
});
|
|
17639
|
-
return
|
|
17640
|
-
|
|
17641
|
-
|
|
17642
|
-
|
|
17643
|
-
|
|
17644
|
-
|
|
17599
|
+
return {
|
|
17600
|
+
id: connector.id,
|
|
17601
|
+
name: connector.name,
|
|
17602
|
+
description: connector.description,
|
|
17603
|
+
imageUri: connector === null || connector === void 0 ? void 0 : connector.imageUri,
|
|
17604
|
+
status: connector.status,
|
|
17605
|
+
actions,
|
|
17606
|
+
};
|
|
17607
|
+
}).filter((connector) => {
|
|
17608
|
+
if (status === "ALL")
|
|
17609
|
+
return true;
|
|
17610
|
+
if (status === "ACTIVE" && connector.status === "ACTIVE")
|
|
17611
|
+
return true;
|
|
17612
|
+
if (status === "INACTIVE" && connector.status === "INACTIVE")
|
|
17613
|
+
return true;
|
|
17614
|
+
return false;
|
|
17615
|
+
});
|
|
17616
|
+
return mappedConnectors;
|
|
17617
|
+
}
|
|
17618
|
+
catch (error) {
|
|
17619
|
+
throw new Error(formatApolloErrors(error));
|
|
17620
|
+
}
|
|
17645
17621
|
}
|
|
17646
17622
|
|
|
17647
17623
|
const REFETCH_KEY$1 = "configurations";
|
|
17648
|
-
const handleDisableConfiguration =
|
|
17649
|
-
var
|
|
17624
|
+
const handleDisableConfiguration = async ({ id, connectorId, }) => {
|
|
17625
|
+
var _a;
|
|
17650
17626
|
try {
|
|
17651
17627
|
const config = getConfig();
|
|
17652
|
-
|
|
17628
|
+
await disableTenantConfig({
|
|
17653
17629
|
input: {
|
|
17654
17630
|
clientId: config.spaceId,
|
|
17655
17631
|
tenantId: config.tenantId,
|
|
@@ -17658,17 +17634,17 @@ const handleDisableConfiguration = (_a) => __awaiter(void 0, [_a], void 0, funct
|
|
|
17658
17634
|
widgetConnectorId: connectorId,
|
|
17659
17635
|
},
|
|
17660
17636
|
});
|
|
17661
|
-
|
|
17637
|
+
await ((_a = refetchFunctions[REFETCH_KEY$1]) === null || _a === void 0 ? void 0 : _a.call(refetchFunctions));
|
|
17662
17638
|
}
|
|
17663
17639
|
catch (error) {
|
|
17664
17640
|
throw new Error(formatApolloErrors(error));
|
|
17665
17641
|
}
|
|
17666
|
-
}
|
|
17667
|
-
const handleDeleteConfiguration =
|
|
17668
|
-
var
|
|
17642
|
+
};
|
|
17643
|
+
const handleDeleteConfiguration = async ({ id, connectorId, }) => {
|
|
17644
|
+
var _a;
|
|
17669
17645
|
try {
|
|
17670
17646
|
const config = getConfig();
|
|
17671
|
-
|
|
17647
|
+
await deleteTenantConfiguration({
|
|
17672
17648
|
variables: {
|
|
17673
17649
|
input: {
|
|
17674
17650
|
clientId: config.spaceId,
|
|
@@ -17679,93 +17655,91 @@ const handleDeleteConfiguration = (_a) => __awaiter(void 0, [_a], void 0, functi
|
|
|
17679
17655
|
},
|
|
17680
17656
|
},
|
|
17681
17657
|
});
|
|
17682
|
-
|
|
17658
|
+
await ((_a = refetchFunctions[REFETCH_KEY$1]) === null || _a === void 0 ? void 0 : _a.call(refetchFunctions));
|
|
17683
17659
|
}
|
|
17684
17660
|
catch (error) {
|
|
17685
17661
|
throw new Error(formatApolloErrors(error));
|
|
17686
17662
|
}
|
|
17687
|
-
}
|
|
17688
|
-
function getConfigurations(
|
|
17689
|
-
|
|
17690
|
-
|
|
17691
|
-
|
|
17692
|
-
|
|
17693
|
-
|
|
17694
|
-
|
|
17695
|
-
|
|
17696
|
-
|
|
17697
|
-
|
|
17698
|
-
|
|
17699
|
-
|
|
17700
|
-
|
|
17701
|
-
|
|
17702
|
-
|
|
17703
|
-
|
|
17704
|
-
|
|
17705
|
-
|
|
17706
|
-
|
|
17707
|
-
|
|
17708
|
-
|
|
17709
|
-
|
|
17710
|
-
|
|
17711
|
-
|
|
17712
|
-
|
|
17713
|
-
|
|
17714
|
-
|
|
17715
|
-
|
|
17716
|
-
|
|
17717
|
-
|
|
17718
|
-
|
|
17719
|
-
|
|
17720
|
-
|
|
17721
|
-
|
|
17722
|
-
|
|
17723
|
-
|
|
17724
|
-
|
|
17725
|
-
|
|
17726
|
-
|
|
17727
|
-
|
|
17728
|
-
|
|
17729
|
-
|
|
17730
|
-
|
|
17731
|
-
|
|
17732
|
-
|
|
17733
|
-
|
|
17734
|
-
|
|
17735
|
-
|
|
17736
|
-
|
|
17737
|
-
|
|
17738
|
-
input: formData,
|
|
17739
|
-
});
|
|
17740
|
-
});
|
|
17741
|
-
actions.push({
|
|
17742
|
-
name: "Enable",
|
|
17743
|
-
actionType: ConnectorActionType.ENABLE,
|
|
17744
|
-
form,
|
|
17745
|
-
onClick: handler,
|
|
17746
|
-
onSubmit: handler,
|
|
17663
|
+
};
|
|
17664
|
+
async function getConfigurations({ configurationId, status = "ALL", }) {
|
|
17665
|
+
try {
|
|
17666
|
+
const config = getConfig();
|
|
17667
|
+
const { data } = await getConfigurationSubscriptions({
|
|
17668
|
+
input: {
|
|
17669
|
+
clientId: config.spaceId,
|
|
17670
|
+
tenantId: config.tenantId,
|
|
17671
|
+
id: configurationId,
|
|
17672
|
+
status,
|
|
17673
|
+
}
|
|
17674
|
+
});
|
|
17675
|
+
const configurations = (data.getConfigurationSubscription || [])
|
|
17676
|
+
.map((configSubscription) => {
|
|
17677
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
17678
|
+
const configureAction = (_b = (_a = configSubscription === null || configSubscription === void 0 ? void 0 : configSubscription.connector) === null || _a === void 0 ? void 0 : _a.actions) === null || _b === void 0 ? void 0 : _b.find((action) => action.actionType === "CONFIGURATION");
|
|
17679
|
+
if (!configureAction || ((_c = configSubscription === null || configSubscription === void 0 ? void 0 : configSubscription.connector) === null || _c === void 0 ? void 0 : _c.active) === false)
|
|
17680
|
+
return null;
|
|
17681
|
+
const actions = [];
|
|
17682
|
+
if ((configSubscription === null || configSubscription === void 0 ? void 0 : configSubscription.status) === "ENABLED") {
|
|
17683
|
+
actions.push({
|
|
17684
|
+
name: "Disable",
|
|
17685
|
+
actionType: ConnectorActionType.DISABLE,
|
|
17686
|
+
onClick: async () => {
|
|
17687
|
+
var _a;
|
|
17688
|
+
await handleDisableConfiguration({ connectorId: configSubscription.connector.id, id: configurationId });
|
|
17689
|
+
await ((_a = refetchFunctions[REFETCH_KEY$1]) === null || _a === void 0 ? void 0 : _a.call(refetchFunctions));
|
|
17690
|
+
},
|
|
17691
|
+
});
|
|
17692
|
+
actions.push({
|
|
17693
|
+
name: "Delete",
|
|
17694
|
+
actionType: ConnectorActionType.DELETE,
|
|
17695
|
+
onClick: async () => {
|
|
17696
|
+
var _a;
|
|
17697
|
+
await handleDeleteConfiguration({ connectorId: configSubscription.connector.id, id: configurationId });
|
|
17698
|
+
await ((_a = refetchFunctions[REFETCH_KEY$1]) === null || _a === void 0 ? void 0 : _a.call(refetchFunctions));
|
|
17699
|
+
},
|
|
17700
|
+
});
|
|
17701
|
+
}
|
|
17702
|
+
else {
|
|
17703
|
+
const form = inputContractToFormData((_h = (_g = (_f = (_e = (_d = configSubscription === null || configSubscription === void 0 ? void 0 : configSubscription.connector) === null || _d === void 0 ? void 0 : _d.connectedConnectors) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.authMethods) === null || _g === void 0 ? void 0 : _g.find((authMethod) => authMethod.isDefault)) === null || _h === void 0 ? void 0 : _h.inputContract);
|
|
17704
|
+
const handler = async (formData = {}) => {
|
|
17705
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
17706
|
+
if (((_a = configSubscription === null || configSubscription === void 0 ? void 0 : configSubscription.connector) === null || _a === void 0 ? void 0 : _a.status) === "ACTIVE")
|
|
17707
|
+
return;
|
|
17708
|
+
await activateConnector({
|
|
17709
|
+
connectorId: configSubscription.connector.id,
|
|
17710
|
+
action: (_c = (_b = configSubscription === null || configSubscription === void 0 ? void 0 : configSubscription.connector) === null || _b === void 0 ? void 0 : _b.actions) === null || _c === void 0 ? void 0 : _c.find((action) => action.actionType === ResourceAction.ACTIVATION),
|
|
17711
|
+
dependencyConnector: (_e = (_d = configSubscription === null || configSubscription === void 0 ? void 0 : configSubscription.connector) === null || _d === void 0 ? void 0 : _d.connectedConnectors) === null || _e === void 0 ? void 0 : _e[0],
|
|
17712
|
+
authMethod: (_h = (_g = (_f = configSubscription === null || configSubscription === void 0 ? void 0 : configSubscription.connector) === null || _f === void 0 ? void 0 : _f.connectedConnectors) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.authMethods[0],
|
|
17713
|
+
input: formData,
|
|
17747
17714
|
});
|
|
17748
|
-
}
|
|
17749
|
-
return {
|
|
17750
|
-
id: configSubscription.connector.id,
|
|
17751
|
-
connectorId: (_j = configSubscription === null || configSubscription === void 0 ? void 0 : configSubscription.connector) === null || _j === void 0 ? void 0 : _j.id,
|
|
17752
|
-
configurationId,
|
|
17753
|
-
name: configSubscription.connector.name,
|
|
17754
|
-
flowId: configureAction.handler,
|
|
17755
|
-
description: configSubscription.connector.description,
|
|
17756
|
-
imageUri: configSubscription.connector.imageUri,
|
|
17757
|
-
status: configSubscription.status,
|
|
17758
|
-
actions,
|
|
17759
|
-
metadata: configSubscription.metaData,
|
|
17760
17715
|
};
|
|
17761
|
-
|
|
17762
|
-
|
|
17763
|
-
|
|
17764
|
-
|
|
17765
|
-
|
|
17766
|
-
|
|
17767
|
-
|
|
17768
|
-
|
|
17716
|
+
actions.push({
|
|
17717
|
+
name: "Enable",
|
|
17718
|
+
actionType: ConnectorActionType.ENABLE,
|
|
17719
|
+
form,
|
|
17720
|
+
onClick: handler,
|
|
17721
|
+
onSubmit: handler,
|
|
17722
|
+
});
|
|
17723
|
+
}
|
|
17724
|
+
return {
|
|
17725
|
+
id: configSubscription.connector.id,
|
|
17726
|
+
connectorId: (_j = configSubscription === null || configSubscription === void 0 ? void 0 : configSubscription.connector) === null || _j === void 0 ? void 0 : _j.id,
|
|
17727
|
+
configurationId,
|
|
17728
|
+
name: configSubscription.connector.name,
|
|
17729
|
+
flowId: configureAction.handler,
|
|
17730
|
+
description: configSubscription.connector.description,
|
|
17731
|
+
imageUri: configSubscription.connector.imageUri,
|
|
17732
|
+
status: configSubscription.status,
|
|
17733
|
+
actions,
|
|
17734
|
+
metadata: configSubscription.metaData,
|
|
17735
|
+
};
|
|
17736
|
+
})
|
|
17737
|
+
.filter(Boolean);
|
|
17738
|
+
return configurations;
|
|
17739
|
+
}
|
|
17740
|
+
catch (err) {
|
|
17741
|
+
throw new Error(formatApolloErrors(err));
|
|
17742
|
+
}
|
|
17769
17743
|
}
|
|
17770
17744
|
|
|
17771
17745
|
function loadGapiClient() {
|
|
@@ -17777,73 +17751,69 @@ function loadGapiClient() {
|
|
|
17777
17751
|
document.body.appendChild(script);
|
|
17778
17752
|
});
|
|
17779
17753
|
}
|
|
17780
|
-
function initializeGooglePicker() {
|
|
17781
|
-
|
|
17782
|
-
|
|
17783
|
-
|
|
17784
|
-
|
|
17785
|
-
|
|
17786
|
-
|
|
17787
|
-
resolve();
|
|
17788
|
-
});
|
|
17754
|
+
async function initializeGooglePicker() {
|
|
17755
|
+
await loadGapiClient();
|
|
17756
|
+
return new Promise((resolve) => {
|
|
17757
|
+
// @ts-ignore
|
|
17758
|
+
gapi.load('picker', () => {
|
|
17759
|
+
console.log('gapi loaded');
|
|
17760
|
+
resolve();
|
|
17789
17761
|
});
|
|
17790
17762
|
});
|
|
17791
17763
|
}
|
|
17792
|
-
function createGooglePicker(developerKey, accessToken) {
|
|
17793
|
-
|
|
17794
|
-
|
|
17795
|
-
|
|
17796
|
-
|
|
17797
|
-
|
|
17798
|
-
|
|
17799
|
-
|
|
17800
|
-
|
|
17801
|
-
|
|
17802
|
-
|
|
17803
|
-
|
|
17804
|
-
|
|
17805
|
-
|
|
17806
|
-
|
|
17807
|
-
|
|
17808
|
-
|
|
17809
|
-
|
|
17810
|
-
|
|
17811
|
-
|
|
17812
|
-
resolve(data === null || data === void 0 ? void 0 : data.docs);
|
|
17813
|
-
}
|
|
17814
|
-
})
|
|
17815
|
-
.build();
|
|
17816
|
-
picker.setVisible(true);
|
|
17817
|
-
const iframe = document.querySelector("iframe.picker-dialog-frame");
|
|
17818
|
-
const pickerDialogBg = document.querySelector(".picker-dialog-bg");
|
|
17819
|
-
if (iframe) {
|
|
17820
|
-
iframe.style.pointerEvents = "auto";
|
|
17821
|
-
pickerDialogBg.style.pointerEvents = "auto";
|
|
17822
|
-
// Step 3: Allow only iframe to be clickable
|
|
17823
|
-
iframe.addEventListener("click", (event) => {
|
|
17824
|
-
event.preventDefault();
|
|
17825
|
-
event.stopPropagation();
|
|
17826
|
-
});
|
|
17827
|
-
pickerDialogBg.addEventListener("click", (event) => {
|
|
17828
|
-
event.preventDefault();
|
|
17829
|
-
event.stopPropagation();
|
|
17830
|
-
});
|
|
17764
|
+
async function createGooglePicker(developerKey, accessToken) {
|
|
17765
|
+
// Ensure Google Picker API is initialized
|
|
17766
|
+
await initializeGooglePicker();
|
|
17767
|
+
return new Promise((resolve, reject) => {
|
|
17768
|
+
try {
|
|
17769
|
+
// @ts-ignore: `google.picker` is loaded via Google APIs script
|
|
17770
|
+
const picker = new google.picker.PickerBuilder()
|
|
17771
|
+
// @ts-ignore
|
|
17772
|
+
.addView(google.picker.ViewId.DOCS)
|
|
17773
|
+
// @ts-ignore
|
|
17774
|
+
.addView(new google.picker.DocsView(google.picker.ViewId.FOLDERS)
|
|
17775
|
+
.setIncludeFolders(true)
|
|
17776
|
+
.setSelectFolderEnabled(true))
|
|
17777
|
+
// @ts-ignore
|
|
17778
|
+
.enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
|
|
17779
|
+
.setOAuthToken(accessToken)
|
|
17780
|
+
.setDeveloperKey(developerKey || GOOGLE_FILES_PICKER_API_KEY)
|
|
17781
|
+
.setCallback((data) => {
|
|
17782
|
+
if ((data === null || data === void 0 ? void 0 : data.action) === "picked") {
|
|
17783
|
+
resolve(data === null || data === void 0 ? void 0 : data.docs);
|
|
17831
17784
|
}
|
|
17785
|
+
})
|
|
17786
|
+
.build();
|
|
17787
|
+
picker.setVisible(true);
|
|
17788
|
+
const iframe = document.querySelector("iframe.picker-dialog-frame");
|
|
17789
|
+
const pickerDialogBg = document.querySelector(".picker-dialog-bg");
|
|
17790
|
+
if (iframe) {
|
|
17791
|
+
iframe.style.pointerEvents = "auto";
|
|
17792
|
+
pickerDialogBg.style.pointerEvents = "auto";
|
|
17793
|
+
// Step 3: Allow only iframe to be clickable
|
|
17794
|
+
iframe.addEventListener("click", (event) => {
|
|
17795
|
+
event.preventDefault();
|
|
17796
|
+
event.stopPropagation();
|
|
17797
|
+
});
|
|
17798
|
+
pickerDialogBg.addEventListener("click", (event) => {
|
|
17799
|
+
event.preventDefault();
|
|
17800
|
+
event.stopPropagation();
|
|
17801
|
+
});
|
|
17832
17802
|
}
|
|
17833
|
-
|
|
17834
|
-
|
|
17835
|
-
|
|
17836
|
-
}
|
|
17803
|
+
}
|
|
17804
|
+
catch (error) {
|
|
17805
|
+
reject(new Error('Failed to create Google Picker'));
|
|
17806
|
+
}
|
|
17837
17807
|
});
|
|
17838
17808
|
}
|
|
17839
17809
|
|
|
17840
17810
|
const REFETCH_KEY = "configuration-form";
|
|
17841
17811
|
function openGoogleFilesPicker(parentArgs) {
|
|
17842
|
-
return (args) =>
|
|
17812
|
+
return async (args) => {
|
|
17843
17813
|
var _a, _b, _c;
|
|
17844
17814
|
try {
|
|
17845
17815
|
const config = getConfig();
|
|
17846
|
-
const { data } =
|
|
17816
|
+
const { data } = await generateAccessToken({
|
|
17847
17817
|
input: {
|
|
17848
17818
|
orgId: config.spaceId,
|
|
17849
17819
|
tenantId: config.tenantId,
|
|
@@ -17854,31 +17824,31 @@ function openGoogleFilesPicker(parentArgs) {
|
|
|
17854
17824
|
const accessToken = (_a = data === null || data === void 0 ? void 0 : data.connectorConnection) === null || _a === void 0 ? void 0 : _a.access_token;
|
|
17855
17825
|
if (!accessToken)
|
|
17856
17826
|
throw new Error("Missing access token from connector");
|
|
17857
|
-
const docs =
|
|
17827
|
+
const docs = await createGooglePicker(args.apiKey || ((_c = (_b = data === null || data === void 0 ? void 0 : data.connectorConnection) === null || _b === void 0 ? void 0 : _b.metadata) === null || _c === void 0 ? void 0 : _c.google_picker_api_key), accessToken);
|
|
17858
17828
|
const files = (docs || []).map((doc) => ({
|
|
17859
17829
|
label: doc === null || doc === void 0 ? void 0 : doc.name,
|
|
17860
17830
|
value: doc === null || doc === void 0 ? void 0 : doc.id,
|
|
17861
17831
|
}));
|
|
17862
|
-
|
|
17832
|
+
await args.onComplete(files);
|
|
17863
17833
|
}
|
|
17864
17834
|
catch (err) {
|
|
17865
17835
|
const error = err instanceof Error ? err : new Error("Unknown error");
|
|
17866
|
-
|
|
17836
|
+
await args.onError(error);
|
|
17867
17837
|
}
|
|
17868
|
-
}
|
|
17838
|
+
};
|
|
17869
17839
|
}
|
|
17870
17840
|
/**
|
|
17871
17841
|
* Returns a submit handler for a configuration form.
|
|
17872
17842
|
* Handles both creation and update flows.
|
|
17873
17843
|
*/
|
|
17874
17844
|
function getSubmitHandler({ configuration, configurationId, connectorId, }) {
|
|
17875
|
-
return
|
|
17876
|
-
var
|
|
17845
|
+
return async ({ formData }) => {
|
|
17846
|
+
var _a, _b;
|
|
17877
17847
|
const config = getConfig();
|
|
17878
17848
|
const uiCode = populateFormDataInUiCode(configuration.uiCode, formData);
|
|
17879
17849
|
try {
|
|
17880
17850
|
if (configuration.status === "ENABLED") {
|
|
17881
|
-
|
|
17851
|
+
await updateTenantConfiguration({
|
|
17882
17852
|
input: stripTypename({
|
|
17883
17853
|
clientId: config.spaceId,
|
|
17884
17854
|
tenantId: config.tenantId,
|
|
@@ -17890,10 +17860,10 @@ function getSubmitHandler({ configuration, configurationId, connectorId, }) {
|
|
|
17890
17860
|
configurations: formData,
|
|
17891
17861
|
}),
|
|
17892
17862
|
});
|
|
17893
|
-
|
|
17863
|
+
await ((_a = refetchFunctions[REFETCH_KEY]) === null || _a === void 0 ? void 0 : _a.call(refetchFunctions));
|
|
17894
17864
|
}
|
|
17895
17865
|
else {
|
|
17896
|
-
|
|
17866
|
+
await createTenantConfiguration({
|
|
17897
17867
|
input: stripTypename({
|
|
17898
17868
|
clientId: config.spaceId,
|
|
17899
17869
|
tenantId: config.tenantId,
|
|
@@ -17905,96 +17875,86 @@ function getSubmitHandler({ configuration, configurationId, connectorId, }) {
|
|
|
17905
17875
|
configurations: formData,
|
|
17906
17876
|
}),
|
|
17907
17877
|
});
|
|
17908
|
-
|
|
17878
|
+
await ((_b = refetchFunctions[REFETCH_KEY]) === null || _b === void 0 ? void 0 : _b.call(refetchFunctions));
|
|
17909
17879
|
}
|
|
17910
17880
|
}
|
|
17911
17881
|
catch (error) {
|
|
17912
17882
|
throw new Error(formatApolloErrors(error));
|
|
17913
17883
|
}
|
|
17914
|
-
}
|
|
17884
|
+
};
|
|
17915
17885
|
}
|
|
17916
17886
|
/**
|
|
17917
17887
|
* Fetches options for select fields, supporting pagination and search.
|
|
17918
17888
|
* Extensible for custom loaders.
|
|
17919
17889
|
*/
|
|
17920
|
-
function fetchOptions(
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
|
|
17924
|
-
|
|
17925
|
-
|
|
17890
|
+
async function fetchOptions(context, pagination, resetCursor = false, query) {
|
|
17891
|
+
var _a, _b;
|
|
17892
|
+
const config = getConfig();
|
|
17893
|
+
try {
|
|
17894
|
+
const { data } = await getFieldData({
|
|
17895
|
+
input: {
|
|
17896
|
+
id: pagination.sourceId,
|
|
17897
|
+
clientId: config.spaceId,
|
|
17898
|
+
// sameProjectFlow: pagination.sourceProject === "self",
|
|
17926
17899
|
input: {
|
|
17927
|
-
|
|
17928
|
-
|
|
17929
|
-
|
|
17930
|
-
|
|
17931
|
-
|
|
17932
|
-
|
|
17933
|
-
|
|
17934
|
-
|
|
17935
|
-
cursor: resetCursor ? null : pagination.cursor,
|
|
17936
|
-
curser: resetCursor ? null : pagination.cursor,
|
|
17937
|
-
offset: resetCursor ? 0 : pagination.offset,
|
|
17938
|
-
query,
|
|
17939
|
-
},
|
|
17940
|
-
headers: { [TENANT_ID_HEADER_KEY]: config.tenantId },
|
|
17900
|
+
data: {
|
|
17901
|
+
input: {
|
|
17902
|
+
data: context,
|
|
17903
|
+
limit: pagination.limit || 10,
|
|
17904
|
+
cursor: resetCursor ? null : pagination.cursor,
|
|
17905
|
+
curser: resetCursor ? null : pagination.cursor,
|
|
17906
|
+
offset: resetCursor ? 0 : pagination.offset,
|
|
17907
|
+
query,
|
|
17941
17908
|
},
|
|
17909
|
+
headers: { [TENANT_ID_HEADER_KEY]: config.tenantId },
|
|
17942
17910
|
},
|
|
17943
17911
|
},
|
|
17944
|
-
}
|
|
17945
|
-
|
|
17946
|
-
|
|
17947
|
-
|
|
17948
|
-
|
|
17949
|
-
|
|
17950
|
-
|
|
17951
|
-
|
|
17952
|
-
|
|
17953
|
-
|
|
17954
|
-
|
|
17955
|
-
|
|
17956
|
-
|
|
17957
|
-
|
|
17958
|
-
|
|
17959
|
-
|
|
17960
|
-
|
|
17961
|
-
}
|
|
17962
|
-
|
|
17963
|
-
|
|
17964
|
-
|
|
17965
|
-
}
|
|
17912
|
+
},
|
|
17913
|
+
});
|
|
17914
|
+
const response = ((_a = data === null || data === void 0 ? void 0 : data.executeGetFieldDataFlow) === null || _a === void 0 ? void 0 : _a.data) || {};
|
|
17915
|
+
const newOptions = response.options || [];
|
|
17916
|
+
const limit = pagination.limit || 0;
|
|
17917
|
+
const offset = resetCursor ? 0 : pagination.offset || 0;
|
|
17918
|
+
const newOffset = newOptions.length > 0 ? offset + limit : offset;
|
|
17919
|
+
const total = (_b = response.total) !== null && _b !== void 0 ? _b : pagination.total;
|
|
17920
|
+
const cursor = response.cursor || response.curser;
|
|
17921
|
+
const hasNextPage = Boolean(cursor || response.hasNextPage) ||
|
|
17922
|
+
(typeof total === 'number'
|
|
17923
|
+
? total > newOffset
|
|
17924
|
+
: newOptions.length === limit && !pagination.cursor);
|
|
17925
|
+
return {
|
|
17926
|
+
options: newOptions,
|
|
17927
|
+
pagination: Object.assign(Object.assign({}, pagination), { cursor, offset: newOffset, total,
|
|
17928
|
+
hasNextPage, loaded: newOptions.length }),
|
|
17929
|
+
};
|
|
17930
|
+
}
|
|
17931
|
+
catch (error) {
|
|
17932
|
+
throw new Error(formatApolloErrors(error));
|
|
17933
|
+
}
|
|
17966
17934
|
}
|
|
17967
17935
|
/**
|
|
17968
17936
|
* Loads more options for a select field.
|
|
17969
17937
|
*/
|
|
17970
|
-
function loadMoreOptions(pagination, context) {
|
|
17971
|
-
return
|
|
17972
|
-
return fetchOptions(context || {}, pagination, false);
|
|
17973
|
-
});
|
|
17938
|
+
async function loadMoreOptions(pagination, context) {
|
|
17939
|
+
return fetchOptions(context || {}, pagination, false);
|
|
17974
17940
|
}
|
|
17975
17941
|
/**
|
|
17976
17942
|
* Refreshes options for a select field.
|
|
17977
17943
|
*/
|
|
17978
|
-
function refreshOptions(pagination, context) {
|
|
17979
|
-
return
|
|
17980
|
-
return fetchOptions(context || {}, pagination, true);
|
|
17981
|
-
});
|
|
17944
|
+
async function refreshOptions(pagination, context) {
|
|
17945
|
+
return fetchOptions(context || {}, pagination, true);
|
|
17982
17946
|
}
|
|
17983
17947
|
/**
|
|
17984
17948
|
* Gets options for a select field.
|
|
17985
17949
|
*/
|
|
17986
|
-
function getOptions(pagination, context) {
|
|
17987
|
-
return
|
|
17988
|
-
return fetchOptions(context || {}, pagination, false);
|
|
17989
|
-
});
|
|
17950
|
+
async function getOptions(pagination, context) {
|
|
17951
|
+
return fetchOptions(context || {}, pagination, false);
|
|
17990
17952
|
}
|
|
17991
17953
|
/**
|
|
17992
17954
|
* Searches options for a select field.
|
|
17993
17955
|
*/
|
|
17994
|
-
function searchOptions(query, pagination, context) {
|
|
17995
|
-
return
|
|
17996
|
-
return fetchOptions(context || {}, pagination, false, query);
|
|
17997
|
-
});
|
|
17956
|
+
async function searchOptions(query, pagination, context) {
|
|
17957
|
+
return fetchOptions(context || {}, pagination, false, query);
|
|
17998
17958
|
}
|
|
17999
17959
|
/**
|
|
18000
17960
|
* Fetches and builds a configuration form for a connector.
|
|
@@ -18002,46 +17962,44 @@ function searchOptions(query, pagination, context) {
|
|
|
18002
17962
|
* @param input - ConfigurationFormInput
|
|
18003
17963
|
* @returns Promise<ConfigurationForm>
|
|
18004
17964
|
*/
|
|
18005
|
-
function getConfigurationForm(input) {
|
|
18006
|
-
|
|
18007
|
-
|
|
18008
|
-
|
|
18009
|
-
|
|
18010
|
-
|
|
18011
|
-
|
|
18012
|
-
|
|
18013
|
-
|
|
18014
|
-
|
|
18015
|
-
|
|
18016
|
-
|
|
18017
|
-
|
|
18018
|
-
|
|
18019
|
-
|
|
18020
|
-
|
|
18021
|
-
|
|
18022
|
-
|
|
18023
|
-
|
|
18024
|
-
|
|
18025
|
-
|
|
18026
|
-
|
|
18027
|
-
|
|
18028
|
-
|
|
18029
|
-
|
|
18030
|
-
|
|
18031
|
-
|
|
18032
|
-
|
|
18033
|
-
|
|
18034
|
-
|
|
18035
|
-
|
|
18036
|
-
|
|
18037
|
-
|
|
18038
|
-
|
|
18039
|
-
|
|
18040
|
-
|
|
18041
|
-
|
|
18042
|
-
|
|
18043
|
-
}
|
|
18044
|
-
});
|
|
17965
|
+
async function getConfigurationForm(input) {
|
|
17966
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
17967
|
+
try {
|
|
17968
|
+
const config = getConfig();
|
|
17969
|
+
const { data: configurationFormData } = await getConfigurationSubscriptionById({
|
|
17970
|
+
input: {
|
|
17971
|
+
clientId: config.spaceId,
|
|
17972
|
+
tenantId: config.tenantId,
|
|
17973
|
+
id: input.configurationId,
|
|
17974
|
+
connectorId: input.connectorId,
|
|
17975
|
+
widgetConnectorId: input.connectorId,
|
|
17976
|
+
flowId: (_a = input === null || input === void 0 ? void 0 : input.configuration) === null || _a === void 0 ? void 0 : _a.flowId,
|
|
17977
|
+
},
|
|
17978
|
+
});
|
|
17979
|
+
const uiCodeString = (_b = configurationFormData === null || configurationFormData === void 0 ? void 0 : configurationFormData.tenantConfigurationsById) === null || _b === void 0 ? void 0 : _b.uiCode;
|
|
17980
|
+
const uiCode = safeParse(uiCodeString || "") || {};
|
|
17981
|
+
const fields = uiCodeToFormFields(Object.assign(Object.assign({}, uiCode), { target: Object.assign(Object.assign({}, uiCode === null || uiCode === void 0 ? void 0 : uiCode.target), { connectorId: Object.assign(Object.assign({}, (_c = uiCode === null || uiCode === void 0 ? void 0 : uiCode.target) === null || _c === void 0 ? void 0 : _c.connectorId), { target: ((_e = (_d = uiCode === null || uiCode === void 0 ? void 0 : uiCode.target) === null || _d === void 0 ? void 0 : _d.connectorId) === null || _e === void 0 ? void 0 : _e.target) || (input === null || input === void 0 ? void 0 : input.connectorId), hideOption: Object.assign(Object.assign({}, (_g = (_f = uiCode === null || uiCode === void 0 ? void 0 : uiCode.target) === null || _f === void 0 ? void 0 : _f.connectorId) === null || _g === void 0 ? void 0 : _g.hideOption), { enable: true }) }), id: Object.assign(Object.assign({}, (_h = uiCode === null || uiCode === void 0 ? void 0 : uiCode.target) === null || _h === void 0 ? void 0 : _h.id), { target: ((_k = (_j = uiCode === null || uiCode === void 0 ? void 0 : uiCode.target) === null || _j === void 0 ? void 0 : _j.id) === null || _k === void 0 ? void 0 : _k.target) || (input === null || input === void 0 ? void 0 : input.configurationId), hideOption: Object.assign(Object.assign({}, (_m = (_l = uiCode === null || uiCode === void 0 ? void 0 : uiCode.target) === null || _l === void 0 ? void 0 : _l.id) === null || _m === void 0 ? void 0 : _m.hideOption), { enable: true }) }) }) }), {
|
|
17982
|
+
getOptions,
|
|
17983
|
+
loadMore: loadMoreOptions,
|
|
17984
|
+
refresh: refreshOptions,
|
|
17985
|
+
searchOptions,
|
|
17986
|
+
openGoogleFilesPicker: openGoogleFilesPicker({ connectorId: input.connectorId }),
|
|
17987
|
+
});
|
|
17988
|
+
return {
|
|
17989
|
+
name: ((_o = input === null || input === void 0 ? void 0 : input.configuration) === null || _o === void 0 ? void 0 : _o.name) || "",
|
|
17990
|
+
description: ((_p = input === null || input === void 0 ? void 0 : input.configuration) === null || _p === void 0 ? void 0 : _p.description) || "",
|
|
17991
|
+
imageUri: ((_q = input === null || input === void 0 ? void 0 : input.configuration) === null || _q === void 0 ? void 0 : _q.imageUri) || "",
|
|
17992
|
+
fields: fields,
|
|
17993
|
+
submitHandler: getSubmitHandler({
|
|
17994
|
+
configuration: configurationFormData === null || configurationFormData === void 0 ? void 0 : configurationFormData.tenantConfigurationsById,
|
|
17995
|
+
configurationId: input === null || input === void 0 ? void 0 : input.configurationId,
|
|
17996
|
+
connectorId: input === null || input === void 0 ? void 0 : input.connectorId,
|
|
17997
|
+
}),
|
|
17998
|
+
};
|
|
17999
|
+
}
|
|
18000
|
+
catch (error) {
|
|
18001
|
+
throw new Error(formatApolloErrors(error));
|
|
18002
|
+
}
|
|
18045
18003
|
}
|
|
18046
18004
|
|
|
18047
18005
|
class Fastn {
|
|
@@ -18143,7 +18101,7 @@ function useFieldOptions(field) {
|
|
|
18143
18101
|
// Initial fetch query for static options or first page
|
|
18144
18102
|
const initialQuery = reactQuery.useQuery({
|
|
18145
18103
|
queryKey: [...queryKey, "initial"],
|
|
18146
|
-
queryFn: () =>
|
|
18104
|
+
queryFn: async () => {
|
|
18147
18105
|
var _a, _b;
|
|
18148
18106
|
if (!((_a = field.optionsSource) === null || _a === void 0 ? void 0 : _a.getOptions))
|
|
18149
18107
|
return null;
|
|
@@ -18156,8 +18114,8 @@ function useFieldOptions(field) {
|
|
|
18156
18114
|
type: "OFFSET",
|
|
18157
18115
|
hasNextPage: false,
|
|
18158
18116
|
};
|
|
18159
|
-
return
|
|
18160
|
-
}
|
|
18117
|
+
return await field.optionsSource.getOptions(pagination, {});
|
|
18118
|
+
},
|
|
18161
18119
|
enabled: !!((_a = field.optionsSource) === null || _a === void 0 ? void 0 : _a.getOptions),
|
|
18162
18120
|
staleTime: 1000 * 60 * 5, // 5 minutes
|
|
18163
18121
|
gcTime: 1000 * 60 * 10, // 10 minutes (formerly cacheTime)
|
|
@@ -18165,13 +18123,13 @@ function useFieldOptions(field) {
|
|
|
18165
18123
|
// Infinite query for pagination
|
|
18166
18124
|
const infiniteQuery = reactQuery.useInfiniteQuery({
|
|
18167
18125
|
queryKey: [...queryKey, "infinite"],
|
|
18168
|
-
queryFn:
|
|
18169
|
-
var
|
|
18170
|
-
if (!((
|
|
18126
|
+
queryFn: async ({ pageParam, }) => {
|
|
18127
|
+
var _a;
|
|
18128
|
+
if (!((_a = field.optionsSource) === null || _a === void 0 ? void 0 : _a.loadMore)) {
|
|
18171
18129
|
throw new Error("loadMore function not available");
|
|
18172
18130
|
}
|
|
18173
|
-
return
|
|
18174
|
-
}
|
|
18131
|
+
return await field.optionsSource.loadMore(pageParam, {});
|
|
18132
|
+
},
|
|
18175
18133
|
initialPageParam: ((_c = (_b = field.optionsSource) === null || _b === void 0 ? void 0 : _b.pagination) !== null && _c !== void 0 ? _c : {
|
|
18176
18134
|
sourceId: "",
|
|
18177
18135
|
sourceProject: "",
|
|
@@ -18217,32 +18175,32 @@ function useFieldOptions(field) {
|
|
|
18217
18175
|
setSearchQuery(query);
|
|
18218
18176
|
}, []);
|
|
18219
18177
|
// Load more handler
|
|
18220
|
-
const loadMore = react.useCallback(() =>
|
|
18178
|
+
const loadMore = react.useCallback(async () => {
|
|
18221
18179
|
if (infiniteQuery.hasNextPage && !infiniteQuery.isFetchingNextPage) {
|
|
18222
|
-
|
|
18180
|
+
await infiniteQuery.fetchNextPage();
|
|
18223
18181
|
}
|
|
18224
|
-
}
|
|
18182
|
+
}, [infiniteQuery]);
|
|
18225
18183
|
// Refresh handler - resets to initial state and invalidates cache
|
|
18226
|
-
const refresh = react.useCallback(() =>
|
|
18184
|
+
const refresh = react.useCallback(async () => {
|
|
18227
18185
|
var _a, _b;
|
|
18228
18186
|
try {
|
|
18229
18187
|
// Reset search query
|
|
18230
18188
|
setSearchQuery("");
|
|
18231
18189
|
// Invalidate and refetch initial query
|
|
18232
18190
|
if ((_a = field.optionsSource) === null || _a === void 0 ? void 0 : _a.getOptions) {
|
|
18233
|
-
|
|
18234
|
-
|
|
18191
|
+
await queryClient.invalidateQueries({ queryKey: [...queryKey, "initial"] });
|
|
18192
|
+
await initialQuery.refetch();
|
|
18235
18193
|
}
|
|
18236
18194
|
// Invalidate and refetch infinite query
|
|
18237
18195
|
if ((_b = field.optionsSource) === null || _b === void 0 ? void 0 : _b.loadMore) {
|
|
18238
|
-
|
|
18239
|
-
|
|
18196
|
+
await queryClient.invalidateQueries({ queryKey: [...queryKey, "infinite"] });
|
|
18197
|
+
await infiniteQuery.refetch();
|
|
18240
18198
|
}
|
|
18241
18199
|
}
|
|
18242
18200
|
catch (error) {
|
|
18243
18201
|
console.error("Error in refresh:", error);
|
|
18244
18202
|
}
|
|
18245
|
-
}
|
|
18203
|
+
}, [queryClient, queryKey, initialQuery, infiniteQuery, field.optionsSource, field]);
|
|
18246
18204
|
return {
|
|
18247
18205
|
options: filteredOptions,
|
|
18248
18206
|
loading: initialQuery.isLoading || infiniteQuery.isLoading,
|