@workos-inc/widgets 1.1.4 → 1.2.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.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/lib/organization-switcher.d.ts +10 -1
  3. package/dist/cjs/lib/organization-switcher.d.ts.map +1 -1
  4. package/dist/cjs/lib/organization-switcher.js +31 -3
  5. package/dist/cjs/lib/organization-switcher.js.map +1 -1
  6. package/dist/cjs/workos-widgets.client.d.ts +6 -0
  7. package/dist/cjs/workos-widgets.client.d.ts.map +1 -1
  8. package/dist/cjs/workos-widgets.client.js +23 -3
  9. package/dist/cjs/workos-widgets.client.js.map +1 -1
  10. package/dist/esm/lib/organization-switcher.d.ts +10 -1
  11. package/dist/esm/lib/organization-switcher.d.ts.map +1 -1
  12. package/dist/esm/lib/organization-switcher.js +31 -3
  13. package/dist/esm/lib/organization-switcher.js.map +1 -1
  14. package/dist/esm/workos-widgets.client.d.ts +6 -0
  15. package/dist/esm/workos-widgets.client.d.ts.map +1 -1
  16. package/dist/esm/workos-widgets.client.js +25 -5
  17. package/dist/esm/workos-widgets.client.js.map +1 -1
  18. package/package.json +40 -47
  19. package/src/api/api-provider.tsx +0 -158
  20. package/src/api/constants.ts +0 -1
  21. package/src/api/endpoint.ts +0 -3097
  22. package/src/api/errors.ts +0 -48
  23. package/src/api/index.ts +0 -2
  24. package/src/api/utils.ts +0 -42
  25. package/src/api/widgets-api-client.ts +0 -87
  26. package/src/card-list.tsx +0 -26
  27. package/src/index.ts +0 -9
  28. package/src/lib/add-mfa-dialog.tsx +0 -379
  29. package/src/lib/api/config.ts +0 -9
  30. package/src/lib/api/user.ts +0 -98
  31. package/src/lib/change-password-dialog.tsx +0 -290
  32. package/src/lib/constants.ts +0 -3
  33. package/src/lib/copy-button.tsx +0 -53
  34. package/src/lib/delete-user-dialog.tsx +0 -110
  35. package/src/lib/edit-user-profile-dialog.tsx +0 -181
  36. package/src/lib/edit-user-role-dialog.tsx +0 -178
  37. package/src/lib/elements.tsx +0 -428
  38. package/src/lib/elevated-access.tsx +0 -261
  39. package/src/lib/error-boundary.tsx +0 -166
  40. package/src/lib/errors.ts +0 -49
  41. package/src/lib/generic-error.tsx +0 -70
  42. package/src/lib/icon-panel.tsx +0 -26
  43. package/src/lib/icons.tsx +0 -21
  44. package/src/lib/invite-user-dialog.tsx +0 -327
  45. package/src/lib/logout-all-sessions-dialog.tsx +0 -82
  46. package/src/lib/logout-dialog.tsx +0 -85
  47. package/src/lib/marker.tsx +0 -39
  48. package/src/lib/oauth-icons.tsx +0 -138
  49. package/src/lib/organization-switcher.tsx +0 -156
  50. package/src/lib/otp-input.tsx +0 -276
  51. package/src/lib/resend-invite-dialog.tsx +0 -145
  52. package/src/lib/reset-mfa-dialog.tsx +0 -104
  53. package/src/lib/revoke-invite-dialog.tsx +0 -111
  54. package/src/lib/save-button.tsx +0 -113
  55. package/src/lib/search-provider.tsx +0 -51
  56. package/src/lib/set-password-dialog.tsx +0 -204
  57. package/src/lib/use-dialog-close.tsx +0 -19
  58. package/src/lib/use-is-hydrated.ts +0 -13
  59. package/src/lib/use-layout-effect.ts +0 -6
  60. package/src/lib/use-security-settings.tsx +0 -49
  61. package/src/lib/user-actions-dropdown.tsx +0 -157
  62. package/src/lib/user-profile.tsx +0 -227
  63. package/src/lib/user-security.tsx +0 -187
  64. package/src/lib/user-sessions.tsx +0 -204
  65. package/src/lib/users-filter.tsx +0 -62
  66. package/src/lib/users-management-context.tsx +0 -74
  67. package/src/lib/users-management-state.ts +0 -165
  68. package/src/lib/users-management.tsx +0 -594
  69. package/src/lib/users-search.tsx +0 -73
  70. package/src/lib/utils.ts +0 -131
  71. package/src/lib/widgets-context.ts +0 -29
  72. package/src/organization-switcher.client.tsx +0 -81
  73. package/src/user-profile.client.tsx +0 -55
  74. package/src/user-security.client.tsx +0 -55
  75. package/src/user-sessions.client.tsx +0 -100
  76. package/src/users-management.client.tsx +0 -73
  77. package/src/workos-widgets.client.tsx +0 -75
  78. /package/{src → dist/css}/base.css +0 -0
  79. /package/{src → dist/css}/lib/card-list.css +0 -0
  80. /package/{src → dist/css}/lib/marker.css +0 -0
  81. /package/{src → dist/css}/lib/save-button.css +0 -0
  82. /package/{src → dist/css}/styles.css +0 -0
  83. /package/{src → dist/css}/users-management.css +0 -0
@@ -1,158 +0,0 @@
1
- import * as React from "react";
2
-
3
- export type WidgetType =
4
- | "user-management"
5
- | "organization-switcher"
6
- | "user-sessions"
7
- | "user-security"
8
- | "user-profile";
9
-
10
- export type AuthToken = string | (() => Promise<string>);
11
-
12
- interface ElevatedAccess {
13
- token: string;
14
- expiresAt: string;
15
- }
16
-
17
- interface ApiConfig {
18
- authToken: Promise<string> | string;
19
- authTokenQueryKey: string;
20
- baseUrl: string;
21
- widgetType: WidgetType;
22
- elevatedAccess?: ElevatedAccess;
23
- setElevatedAccess: (elevatedAccess?: ElevatedAccess) => void;
24
- }
25
-
26
- const ApiContext = React.createContext<ApiConfig | undefined>(undefined);
27
-
28
- interface ApiProviderProps {
29
- authToken: AuthToken;
30
- baseUrl: string;
31
- children: React.ReactNode;
32
- widgetType: WidgetType;
33
- }
34
-
35
- export const ApiProvider = ({
36
- authToken,
37
- baseUrl,
38
- children,
39
- widgetType,
40
- }: ApiProviderProps) => {
41
- const authTokenPromiseOrString =
42
- typeof authToken === "string" ? authToken : authToken();
43
- const [elevatedAccess, setElevatedAccess] = React.useState<ElevatedAccess>();
44
- const elevatedAccessTimeout = React.useRef<NodeJS.Timeout>();
45
-
46
- // This effect manages the expiration of elevated access tokens
47
- // When an elevated access token is present, it checks every 30 seconds if the token has expired
48
- // If the token has expired (current time > expiration time), it clears the elevated access
49
- React.useEffect(() => {
50
- if (elevatedAccessTimeout.current) {
51
- clearInterval(elevatedAccessTimeout.current);
52
- }
53
-
54
- if (elevatedAccess) {
55
- elevatedAccessTimeout.current = setInterval(() => {
56
- const now = new Date();
57
- const expiresAtDate = new Date(elevatedAccess.expiresAt);
58
-
59
- // Reset the elevated access if it has expired
60
- if (now > expiresAtDate) {
61
- setElevatedAccess(undefined);
62
- }
63
- }, 30_000); // every 30 seconds
64
- }
65
-
66
- return () => {
67
- if (elevatedAccessTimeout.current) {
68
- clearInterval(elevatedAccessTimeout.current);
69
- }
70
- };
71
- }, [elevatedAccess]);
72
-
73
- const value = React.useMemo(
74
- () => ({
75
- authToken: authTokenPromiseOrString,
76
- authTokenQueryKey: getAuthTokenQueryKey(authTokenPromiseOrString),
77
- baseUrl,
78
- elevatedAccess,
79
- setElevatedAccess,
80
- widgetType,
81
- }),
82
- [
83
- authTokenPromiseOrString,
84
- baseUrl,
85
- elevatedAccess,
86
- setElevatedAccess,
87
- widgetType,
88
- ],
89
- );
90
-
91
- return <ApiContext.Provider value={value}>{children}</ApiContext.Provider>;
92
- };
93
-
94
- export const useApi = () => {
95
- const context = React.useContext(ApiContext);
96
-
97
- if (context === undefined) {
98
- throw new Error("useApi must be used within an ApiProvider");
99
- }
100
-
101
- return context;
102
- };
103
-
104
- export const useElevatedAccessToken = () => {
105
- const { elevatedAccess, setElevatedAccess } = useApi();
106
-
107
- return { elevatedAccess, setElevatedAccess };
108
- };
109
-
110
- // Map promises to a UUID that they can be identified by
111
- const PromiseKey = new WeakMap<Promise<string>, string>();
112
- /*
113
- *
114
- * @param getAccessToken - Async function that returns a promise that resolves to a string
115
- * @returns a resolved string or null from the access token promise
116
- */
117
- function getAuthTokenQueryKey(
118
- authTokenPromiseOrString: Promise<string> | string,
119
- ): string {
120
- // Need to go by equality of the promise to avoid scenarios where
121
- // 1. The promise is the same, but the function changes
122
- // 2. The function is the same, but the promise is different ⚠️
123
- //
124
- // This does have the unfortunate side effect where if the function result
125
- // isn't memoized somehow, then it will invalidate the query on every render.
126
- // This doesn't occur with the current use case of getAccessToken from
127
- // useAuth, but could in a custom implementation.
128
- //
129
- // Other things I explored:
130
- // 1. Removing promise api, and force user to resolve the promise
131
- // themselves. The user can already do this with the string API, so
132
- // it's not necessary, and they could run into issues 1, or 2 if
133
- // implemented wrong.
134
- // 2. Memoizing the function - this results in issue 2, where the function
135
- // is static, but the promise changes. I believe this actually is the
136
- // case with useAuth since it only sets the client once on initialization,
137
- // and binds the function to the client after that promise resolves.
138
-
139
- if (typeof authTokenPromiseOrString === "string") {
140
- return authTokenPromiseOrString;
141
- }
142
-
143
- const authTokenPromise = authTokenPromiseOrString;
144
-
145
- // Cannot memoize on the function because it could remain the same while
146
- // returning a different promise (and useAuth behaves this way).
147
-
148
- const promiseKey = PromiseKey.get(authTokenPromise);
149
-
150
- // Side effect, but we we're using a weak map, so it should be pretty safe
151
- if (!promiseKey) {
152
- const newPromiseKey = `${Math.random()}`;
153
- PromiseKey.set(authTokenPromise, newPromiseKey);
154
- return newPromiseKey;
155
- } else {
156
- return promiseKey;
157
- }
158
- }
@@ -1 +0,0 @@
1
- export const WIDGETS_API_VERSION = "1";