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