@workos-inc/widgets 1.18.0-next.1788904392369 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,11 +26,16 @@ import { IconPanel } from "./icon-panel.js";
26
26
  import { Status } from "./status.js";
27
27
  import {
28
28
  getMyDataIntegrationsQueryKey,
29
+ getOrganizationDataIntegrationsQueryKey,
30
+ getSharedDataConnectionsQueryKey,
29
31
  useAuthorizeDataIntegrationHook,
32
+ useAuthorizeOrganizationDataIntegrationHook,
30
33
  useDeleteDataInstallation,
31
34
  useSettings,
32
35
  useUpsertDataIntegrationApiKey,
33
- useUpsertDataIntegrationClientCredentials
36
+ useUpsertDataIntegrationClientCredentials,
37
+ useUpsertOrganizationDataIntegrationApiKey,
38
+ useUpsertOrganizationDataIntegrationClientCredentials
34
39
  } from "../api/endpoint.js";
35
40
  import { useQueryClient } from "@tanstack/react-query";
36
41
  import { GenericError } from "./generic-error.js";
@@ -46,8 +51,16 @@ const CONNECT_AUTH_METHODS = [
46
51
  "client_credentials",
47
52
  "api_key"
48
53
  ];
49
- const useOpenDataIntegrationAuthorizeUrl = (integration) => {
54
+ const useAuthorizeConnection = (owner) => {
50
55
  const authorizeDataIntegration = useAuthorizeDataIntegrationHook();
56
+ const authorizeOrganizationDataIntegration = useAuthorizeOrganizationDataIntegrationHook();
57
+ return useCallback(
58
+ (slug, config) => owner === "organization" ? authorizeOrganizationDataIntegration(slug, { config }) : authorizeDataIntegration(slug, { requireHandoff: true, config }),
59
+ [owner, authorizeDataIntegration, authorizeOrganizationDataIntegration]
60
+ );
61
+ };
62
+ const useOpenDataIntegrationAuthorizeUrl = (integration, owner = "user") => {
63
+ const authorizeDataIntegration = useAuthorizeConnection(owner);
51
64
  const settings = useSettings();
52
65
  const baseUrl = settings.data?.authkitOrigin ?? "";
53
66
  const intervalRef = useRef(
@@ -82,10 +95,10 @@ const useOpenDataIntegrationAuthorizeUrl = (integration) => {
82
95
  }
83
96
  let authorization;
84
97
  try {
85
- authorization = await authorizeDataIntegration(integration.slug, {
86
- requireHandoff: true,
98
+ authorization = await authorizeDataIntegration(
99
+ integration.slug,
87
100
  config
88
- });
101
+ );
89
102
  } catch (error) {
90
103
  win.close();
91
104
  throw error;
@@ -397,14 +410,15 @@ function ConnectDialog({
397
410
  integration,
398
411
  fields,
399
412
  open,
400
- onOpenChange
413
+ onOpenChange,
414
+ owner = "user"
401
415
  }) {
402
416
  const initialStep = fields.length > 0 ? "fields" : "review";
403
417
  const [step, setStep] = useState(initialStep);
404
418
  const [submitError, setSubmitError] = useState(null);
405
419
  const [isSubmitting, setIsSubmitting] = useState(false);
406
420
  const configForm = useConfigFieldsForm(fields);
407
- const eventHandler = useOpenDataIntegrationAuthorizeUrl(integration);
421
+ const eventHandler = useOpenDataIntegrationAuthorizeUrl(integration, owner);
408
422
  const translate = useTranslation();
409
423
  const genericConnectError = translate({
410
424
  defaultMessage: "We couldn't start the connection. Please try again.",
@@ -564,13 +578,31 @@ function ConnectIntegrationButton({
564
578
  ] });
565
579
  }
566
580
  const API_KEY_REDACTED_PREFIX = "\u2022\u2022\u2022\u2022";
581
+ function useInvalidateConnections(owner) {
582
+ const queryClient = useQueryClient();
583
+ return useCallback(() => {
584
+ if (owner === "organization") {
585
+ queryClient.invalidateQueries({
586
+ queryKey: getOrganizationDataIntegrationsQueryKey()
587
+ });
588
+ queryClient.invalidateQueries({
589
+ queryKey: getSharedDataConnectionsQueryKey()
590
+ });
591
+ } else {
592
+ queryClient.invalidateQueries({
593
+ queryKey: getMyDataIntegrationsQueryKey()
594
+ });
595
+ }
596
+ }, [owner, queryClient]);
597
+ }
567
598
  function ApiKeyDialog({
568
599
  integration,
600
+ installation = integration.installation,
601
+ owner = "user",
569
602
  open,
570
603
  onOpenChange
571
604
  }) {
572
- const queryClient = useQueryClient();
573
- const installation = integration.installation;
605
+ const invalidateConnections = useInvalidateConnections(owner);
574
606
  const isRotation = installation?.auth_method === "api_key" && installation.state === "connected";
575
607
  const last4 = installation?.api_key_last_4;
576
608
  const maskedKey = last4 ? `${API_KEY_REDACTED_PREFIX}${last4}` : "";
@@ -581,21 +613,22 @@ function ApiKeyDialog({
581
613
  id: "MzSxEF",
582
614
  description: "Placeholder for the API key input field"
583
615
  });
616
+ const onUpserted = () => {
617
+ onOpenChange(false);
618
+ invalidateConnections();
619
+ };
620
+ const userUpsert = useUpsertDataIntegrationApiKey({
621
+ mutation: { onSuccess: onUpserted }
622
+ });
623
+ const organizationUpsert = useUpsertOrganizationDataIntegrationApiKey({
624
+ mutation: { onSuccess: onUpserted }
625
+ });
584
626
  const {
585
627
  mutate: upsertApiKey,
586
628
  error,
587
629
  reset,
588
630
  isPending
589
- } = useUpsertDataIntegrationApiKey({
590
- mutation: {
591
- onSuccess: () => {
592
- onOpenChange(false);
593
- queryClient.invalidateQueries({
594
- queryKey: getMyDataIntegrationsQueryKey()
595
- });
596
- }
597
- }
598
- });
631
+ } = owner === "organization" ? organizationUpsert : userUpsert;
599
632
  useEffect(() => {
600
633
  reset();
601
634
  }, [reset]);
@@ -736,12 +769,13 @@ function ApiKeyConnectButton({
736
769
  }
737
770
  function ClientCredentialsDialog({
738
771
  integration,
772
+ installation = integration.installation,
773
+ owner = "user",
739
774
  fields,
740
775
  open,
741
776
  onOpenChange
742
777
  }) {
743
- const queryClient = useQueryClient();
744
- const installation = integration.installation;
778
+ const invalidateConnections = useInvalidateConnections(owner);
745
779
  const isUpdate = installation?.auth_method === "client_credentials";
746
780
  const storedConfig = useMemo(
747
781
  () => isUpdate ? installation?.config ?? {} : {},
@@ -771,20 +805,21 @@ function ClientCredentialsDialog({
771
805
  description: "Placeholder for the client credentials client secret input"
772
806
  });
773
807
  const secretMissing = !clientSecret.trim() || isRedactedSecret(clientSecret);
808
+ const onUpserted = () => {
809
+ onOpenChange(false);
810
+ invalidateConnections();
811
+ };
812
+ const userUpsert = useUpsertDataIntegrationClientCredentials({
813
+ mutation: { onSuccess: onUpserted }
814
+ });
815
+ const organizationUpsert = useUpsertOrganizationDataIntegrationClientCredentials({
816
+ mutation: { onSuccess: onUpserted }
817
+ });
774
818
  const {
775
819
  mutate: upsertClientCredentials,
776
820
  error,
777
821
  isPending
778
- } = useUpsertDataIntegrationClientCredentials({
779
- mutation: {
780
- onSuccess: () => {
781
- onOpenChange(false);
782
- queryClient.invalidateQueries({
783
- queryKey: getMyDataIntegrationsQueryKey()
784
- });
785
- }
786
- }
787
- });
822
+ } = owner === "organization" ? organizationUpsert : userUpsert;
788
823
  const errorMessage = error instanceof ApiError && error.message ? error.message : null;
789
824
  const handleSubmit = () => {
790
825
  if (!configForm.validate()) {
@@ -1795,9 +1830,16 @@ function getWidgetRootDomProps(state, domProps) {
1795
1830
  });
1796
1831
  }
1797
1832
  export {
1833
+ ApiKeyDialog,
1834
+ ClientCredentialsDialog,
1835
+ ConnectDialog,
1798
1836
  Pipes,
1837
+ PipesEmptyItem,
1799
1838
  PipesError,
1800
1839
  PipesLoading,
1801
- PipesSections
1840
+ PipesSection,
1841
+ PipesSections,
1842
+ getUnpinnedInstallationFields,
1843
+ useOpenDataIntegrationAuthorizeUrl
1802
1844
  };
1803
1845
  //# sourceMappingURL=pipes.js.map