@authowl/react 0.23.0 → 0.24.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.
- package/README.md +11 -2
- package/dist/OrganizationListContent-BSGDHYAC.js +185 -0
- package/dist/OrganizationProfileContent-HJT33DMJ.js +451 -0
- package/dist/OrganizationSwitcherContent-2TJ76HZM.js +176 -0
- package/dist/PrivacyCenterContent-EQEXXSLA.js +204 -0
- package/dist/{TeamsSection-NV64O5I4.js → TeamsSection-VJTKS4KP.js} +8 -4
- package/dist/chunk-2HNQYORD.js +139 -0
- package/dist/chunk-7WIBXVGK.js +19 -0
- package/dist/chunk-IDMSHQ6V.js +106 -0
- package/dist/chunk-SAVEQ6RC.js +83 -0
- package/dist/{chunk-E5ZOQHXY.js → chunk-TOVDZ2ZE.js} +6 -119
- package/dist/chunk-ZYCPC5DH.js +46 -0
- package/dist/index.cjs +5213 -4748
- package/dist/index.d.cts +26 -5
- package/dist/index.d.ts +26 -5
- package/dist/index.js +489 -1305
- package/dist/styles.css +58 -0
- package/package.json +2 -2
|
@@ -115,7 +115,7 @@ function readableAccent(brandHex, surfaceHex, dir) {
|
|
|
115
115
|
}
|
|
116
116
|
return dir === 1 ? WHITE : NEAR_BLACK;
|
|
117
117
|
}
|
|
118
|
-
var LIGHT_SURFACE = "#
|
|
118
|
+
var LIGHT_SURFACE = "#f4f4f5";
|
|
119
119
|
var DARK_SURFACE = "#18181b";
|
|
120
120
|
function deriveBrandRamp(primaryHex) {
|
|
121
121
|
const solid = normalizeHex(primaryHex) ?? DEFAULT_BRAND_COLOR.toLowerCase();
|
|
@@ -534,6 +534,9 @@ function useAuthClient() {
|
|
|
534
534
|
function useAccount() {
|
|
535
535
|
return useAuthClient().account;
|
|
536
536
|
}
|
|
537
|
+
function usePrivacy() {
|
|
538
|
+
return useAuthClient().privacy;
|
|
539
|
+
}
|
|
537
540
|
function usePublicConfig() {
|
|
538
541
|
const { config, configState, retryPublicConfig } = useAuthOwlContext();
|
|
539
542
|
return {
|
|
@@ -826,35 +829,6 @@ function useSignOut() {
|
|
|
826
829
|
return { signOut: client.signOut };
|
|
827
830
|
}
|
|
828
831
|
|
|
829
|
-
// src/components/use-submit-action.ts
|
|
830
|
-
import * as React7 from "react";
|
|
831
|
-
function useSubmitAction() {
|
|
832
|
-
const [pending, setPending] = React7.useState(false);
|
|
833
|
-
const [error, setError] = React7.useState(null);
|
|
834
|
-
const toMessage = useServerError();
|
|
835
|
-
const run = React7.useCallback(
|
|
836
|
-
async (action, { failure, onSuccess, mapError, keepPendingOnSuccess }) => {
|
|
837
|
-
setError(null);
|
|
838
|
-
setPending(true);
|
|
839
|
-
try {
|
|
840
|
-
const res = await action();
|
|
841
|
-
if (res?.error) {
|
|
842
|
-
setError(mapError?.(res.error) ?? toMessage(res.error, failure));
|
|
843
|
-
setPending(false);
|
|
844
|
-
return;
|
|
845
|
-
}
|
|
846
|
-
await onSuccess?.(res ?? { data: null, error: null });
|
|
847
|
-
if (!keepPendingOnSuccess) setPending(false);
|
|
848
|
-
} catch {
|
|
849
|
-
setError(failure);
|
|
850
|
-
setPending(false);
|
|
851
|
-
}
|
|
852
|
-
},
|
|
853
|
-
[toMessage]
|
|
854
|
-
);
|
|
855
|
-
return { pending, error, setError, run };
|
|
856
|
-
}
|
|
857
|
-
|
|
858
832
|
// src/components/Spinner.tsx
|
|
859
833
|
import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
860
834
|
function Spinner() {
|
|
@@ -883,91 +857,11 @@ function FormError({ children, className, "data-testid": testId }) {
|
|
|
883
857
|
);
|
|
884
858
|
}
|
|
885
859
|
|
|
886
|
-
// src/components/organization/model.ts
|
|
887
|
-
function organizationSlugFromName(name) {
|
|
888
|
-
return name.normalize("NFKD").toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 63);
|
|
889
|
-
}
|
|
890
|
-
function organizationRoles(role) {
|
|
891
|
-
return role.split(",").map((value) => value.trim()).filter(Boolean);
|
|
892
|
-
}
|
|
893
|
-
function hasOrganizationRole(member, role) {
|
|
894
|
-
return member ? organizationRoles(member.role).includes(role) : false;
|
|
895
|
-
}
|
|
896
|
-
function canManageOrganization(member) {
|
|
897
|
-
return hasOrganizationRole(member, "owner") || hasOrganizationRole(member, "admin");
|
|
898
|
-
}
|
|
899
|
-
function roleHasStatement(roles, heldRoles, resource, action) {
|
|
900
|
-
return roles.some((role) => {
|
|
901
|
-
if (!heldRoles.has(role.role) || typeof role.permission !== "object" || role.permission === null) {
|
|
902
|
-
return false;
|
|
903
|
-
}
|
|
904
|
-
const actions = role.permission[resource];
|
|
905
|
-
return Array.isArray(actions) && actions.includes(action);
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
function teamManagementCapabilities(member, dynamicRoles) {
|
|
909
|
-
const heldRoles = new Set(organizationRoles(member.role));
|
|
910
|
-
if (heldRoles.has("owner") || heldRoles.has("admin")) {
|
|
911
|
-
return {
|
|
912
|
-
createTeam: true,
|
|
913
|
-
updateTeam: true,
|
|
914
|
-
deleteTeam: true,
|
|
915
|
-
addTeamMember: true,
|
|
916
|
-
removeTeamMember: true
|
|
917
|
-
};
|
|
918
|
-
}
|
|
919
|
-
return {
|
|
920
|
-
createTeam: roleHasStatement(dynamicRoles, heldRoles, "team", "create"),
|
|
921
|
-
updateTeam: roleHasStatement(dynamicRoles, heldRoles, "team", "update"),
|
|
922
|
-
deleteTeam: roleHasStatement(dynamicRoles, heldRoles, "team", "delete"),
|
|
923
|
-
addTeamMember: roleHasStatement(dynamicRoles, heldRoles, "member", "update"),
|
|
924
|
-
removeTeamMember: roleHasStatement(dynamicRoles, heldRoles, "member", "delete")
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
// src/components/organization/use-organization-roles.ts
|
|
929
|
-
import * as React8 from "react";
|
|
930
|
-
var BUILTIN_ROLES = ["owner", "admin", "member"];
|
|
931
|
-
function useOrganizationRoles(organizationId) {
|
|
932
|
-
const api = useAuthClient().organization;
|
|
933
|
-
const apiRef = React8.useRef(api);
|
|
934
|
-
apiRef.current = api;
|
|
935
|
-
const [dynamicRoles, setDynamicRoles] = React8.useState([]);
|
|
936
|
-
const requestRef = React8.useRef(0);
|
|
937
|
-
React8.useEffect(() => {
|
|
938
|
-
const token = ++requestRef.current;
|
|
939
|
-
setDynamicRoles([]);
|
|
940
|
-
if (!organizationId) return;
|
|
941
|
-
void (async () => {
|
|
942
|
-
try {
|
|
943
|
-
const result = await apiRef.current.listRoles({ organizationId });
|
|
944
|
-
if (token !== requestRef.current) return;
|
|
945
|
-
setDynamicRoles((result.data ?? []).filter((entry) => entry.role.trim().length > 0));
|
|
946
|
-
} catch {
|
|
947
|
-
}
|
|
948
|
-
})();
|
|
949
|
-
return () => {
|
|
950
|
-
requestRef.current += 1;
|
|
951
|
-
};
|
|
952
|
-
}, [organizationId]);
|
|
953
|
-
const roles = React8.useMemo(() => {
|
|
954
|
-
const seen = /* @__PURE__ */ new Set();
|
|
955
|
-
const out = [];
|
|
956
|
-
for (const candidate of [...BUILTIN_ROLES, ...dynamicRoles.map((entry) => entry.role)]) {
|
|
957
|
-
const key = candidate.trim();
|
|
958
|
-
if (!key || seen.has(key)) continue;
|
|
959
|
-
seen.add(key);
|
|
960
|
-
out.push(key);
|
|
961
|
-
}
|
|
962
|
-
return out;
|
|
963
|
-
}, [dynamicRoles]);
|
|
964
|
-
return { roles, dynamicRoles };
|
|
965
|
-
}
|
|
966
|
-
|
|
967
860
|
export {
|
|
968
861
|
DEFAULT_BRAND_COLOR,
|
|
969
862
|
useAuthClient,
|
|
970
863
|
useAccount,
|
|
864
|
+
usePrivacy,
|
|
971
865
|
usePublicConfig,
|
|
972
866
|
useSession,
|
|
973
867
|
useUser,
|
|
@@ -995,14 +889,7 @@ export {
|
|
|
995
889
|
useSignInMethodRecorder,
|
|
996
890
|
AuthOwlProvider,
|
|
997
891
|
useAuthOwlContext,
|
|
998
|
-
useSubmitAction,
|
|
999
892
|
Spinner,
|
|
1000
893
|
Busy,
|
|
1001
|
-
FormError
|
|
1002
|
-
organizationSlugFromName,
|
|
1003
|
-
organizationRoles,
|
|
1004
|
-
hasOrganizationRole,
|
|
1005
|
-
canManageOrganization,
|
|
1006
|
-
teamManagementCapabilities,
|
|
1007
|
-
useOrganizationRoles
|
|
894
|
+
FormError
|
|
1008
895
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useAuthClient
|
|
3
|
+
} from "./chunk-TOVDZ2ZE.js";
|
|
4
|
+
|
|
5
|
+
// src/components/organization/use-organization-roles.ts
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
var BUILTIN_ROLES = ["owner", "admin", "member"];
|
|
8
|
+
function useOrganizationRoles(organizationId) {
|
|
9
|
+
const api = useAuthClient().organization;
|
|
10
|
+
const apiRef = React.useRef(api);
|
|
11
|
+
apiRef.current = api;
|
|
12
|
+
const [dynamicRoles, setDynamicRoles] = React.useState([]);
|
|
13
|
+
const requestRef = React.useRef(0);
|
|
14
|
+
React.useEffect(() => {
|
|
15
|
+
const token = ++requestRef.current;
|
|
16
|
+
setDynamicRoles([]);
|
|
17
|
+
if (!organizationId) return;
|
|
18
|
+
void (async () => {
|
|
19
|
+
try {
|
|
20
|
+
const result = await apiRef.current.listRoles({ organizationId });
|
|
21
|
+
if (token !== requestRef.current) return;
|
|
22
|
+
setDynamicRoles((result.data ?? []).filter((entry) => entry.role.trim().length > 0));
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
})();
|
|
26
|
+
return () => {
|
|
27
|
+
requestRef.current += 1;
|
|
28
|
+
};
|
|
29
|
+
}, [organizationId]);
|
|
30
|
+
const roles = React.useMemo(() => {
|
|
31
|
+
const seen = /* @__PURE__ */ new Set();
|
|
32
|
+
const out = [];
|
|
33
|
+
for (const candidate of [...BUILTIN_ROLES, ...dynamicRoles.map((entry) => entry.role)]) {
|
|
34
|
+
const key = candidate.trim();
|
|
35
|
+
if (!key || seen.has(key)) continue;
|
|
36
|
+
seen.add(key);
|
|
37
|
+
out.push(key);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}, [dynamicRoles]);
|
|
41
|
+
return { roles, dynamicRoles };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
useOrganizationRoles
|
|
46
|
+
};
|