@better-auth-ui/core
Version:
Authentication components and data utilities for [Better Auth](https://better-auth.com), available for React and Solid.
188 lines (187 loc) • 7.49 kB
JavaScript
import { t as e } from "../../auth-query-keys-B_bcsA3s.js";
import { t } from "../../create-auth-plugin-BXWyolC8.js";
import { skipToken as n } from "@tanstack/query-core";
//#region src/plugins/dash/dash-audit-log.ts
var r = (e, t) => {
let n = e[t];
return typeof n == "string" && n && n !== "unknown" ? n : void 0;
}, i = (e) => {
if (e) return e.replaceAll("_", " ").replaceAll("-", " ").replace(/\b\w/g, (e) => e.toUpperCase());
}, a = (e) => {
let { eventData: t } = e, n = r(t, "memberName") ?? r(t, "memberEmail"), a = r(t, "inviteeEmail"), o = r(t, "teamName"), s = r(t, "organizationName");
switch (e.eventType) {
case "account_linked":
case "account_unlinked": return i(r(t, "providerId"));
case "user_signed_in":
case "user_signed_out":
case "user_sign_in_failed":
case "session_created":
case "session_revoked": return i(r(t, "loginMethod"));
case "organization_member_added":
case "organization_member_removed": return n;
case "organization_member_role_updated": {
let e = i(r(t, "oldRole")), a = i(r(t, "newRole"));
return [n, e && a ? `${e} → ${a}` : a ?? e].filter(Boolean).join(" · ") || void 0;
}
case "organization_member_invited":
case "organization_member_invite_accepted":
case "organization_member_invite_canceled":
case "organization_member_invite_rejected": return a;
case "organization_team_created":
case "organization_team_updated":
case "organization_team_deleted":
case "organization_team_member_added":
case "organization_team_member_removed": return o;
case "organization_created":
case "organization_updated": return s;
case "user_banned":
case "user_unbanned":
case "user_deleted":
case "user_impersonated":
case "user_impersonated_stopped": return r(t, "userName") ?? r(t, "userEmail");
default: return;
}
}, o = (e, t = !1) => {
let n = [e.location?.city, e.location?.country].filter(Boolean).filter((e, t, n) => n.indexOf(e) === t).join(", "), r = t ? e.location?.ipAddress : void 0;
return [n || void 0, r].filter(Boolean).join(" · ");
}, s = (e) => [
e.projectId,
e.eventKey,
e.eventType,
e.createdAt,
e.updatedAt
].join(":"), c = {
all: (t) => [...e.user(t), "dash"],
auditLogs: (e, t) => [
...c.all(e),
"audit-logs",
t
],
allAuditLogs: (e, t) => [
...c.all(e),
"all-audit-logs",
t
],
userAuditLogs: (e, t, n) => [
...c.all(e),
"user-audit-logs",
t,
n
]
}, l = class extends Error {
status;
statusText;
constructor(e) {
super(e.message || e.statusText || "Dash request failed"), this.name = "DashClientError", this.status = e.status, this.statusText = e.statusText;
}
}, u = (e) => {
if (e.error) throw new l(e.error);
return e.data;
};
function d(e, t, r = {}) {
return {
queryKey: c.auditLogs(t, r),
queryFn: t ? async () => u(await e.dash.getAuditLogs({
...r,
userId: t
})) : n
};
}
function f(e, t, r = {}) {
return {
queryKey: c.allAuditLogs(t, r),
queryFn: t ? async () => u(await e.dash.getAllAuditLogs(r)) : n
};
}
function p(e, t, r, i = {}) {
return {
queryKey: c.userAuditLogs(t, r, i),
queryFn: t && r ? async () => u(await e.dash.getAllAuditLogs({
...i,
userId: r
})) : n
};
}
var m = (e, t, n, r) => e.ensureQueryData(d(t, n, r)), h = (e, t, n, r) => e.prefetchQuery(d(t, n, r)), g = (e, t, n, r) => e.fetchQuery(d(t, n, r)), _ = (e, t, n, r) => e.ensureQueryData(f(t, n, r)), v = (e, t, n, r) => e.prefetchQuery(f(t, n, r)), y = (e, t, n, r) => e.fetchQuery(f(t, n, r)), b = (e, t, n, r, i) => e.ensureQueryData(p(t, n, r, i)), x = (e, t, n, r, i) => e.prefetchQuery(p(t, n, r, i)), S = (e, t, n, r, i) => e.fetchQuery(p(t, n, r, i)), C = {
account_linked: "Account linked",
account_unlinked: "Account unlinked",
all_sessions_revoked: "All sessions revoked",
email_changed: "Email changed",
email_verification_sent: "Verification email sent",
email_verified: "Email verified",
organization_created: "Organization created",
organization_member_added: "Member added",
organization_member_invite_accepted: "Invitation accepted",
organization_member_invite_canceled: "Invitation canceled",
organization_member_invite_rejected: "Invitation rejected",
organization_member_invited: "Member invited",
organization_member_removed: "Member removed",
organization_member_role_updated: "Member role updated",
organization_team_created: "Team created",
organization_team_deleted: "Team deleted",
organization_team_member_added: "Team member added",
organization_team_member_removed: "Team member removed",
organization_team_updated: "Team updated",
organization_updated: "Organization updated",
password_changed: "Password changed",
password_reset_completed: "Password reset completed",
password_reset_requested: "Password reset requested",
profile_image_updated: "Profile image updated",
profile_updated: "Profile updated",
session_created: "Session created",
session_revoked: "Session revoked",
two_factor_disabled: "Two-factor authentication disabled",
two_factor_enabled: "Two-factor authentication enabled",
two_factor_verified: "Two-factor authentication verified",
user_banned: "User banned",
user_created: "Account created",
user_deleted: "User deleted",
user_impersonated: "User impersonated",
user_impersonated_stopped: "User impersonation stopped",
user_sign_in_failed: "Sign-in failed",
user_signed_in: "Signed in",
user_signed_out: "Signed out",
user_unbanned: "User unbanned"
}, w = {
activity: "Activity",
activityDescription: "Review recent authentication and account activity.",
adminUserActivityDescription: "Review recent authentication and account activity for this user.",
adminActivityDescription: "Review activity across the organizations you manage.",
organizationActivityDescription: "Review activity you can access for this organization.",
organizationWide: "Organization-wide",
personalOnly: "Your activity",
noActivity: "No retained activity",
noActivityDescription: "No retained activity matches this view.",
activityLoadError: "Activity could not be loaded",
activityLoadErrorDescription: "Check the Dash client configuration, then try again.",
retry: "Try again",
paginationRange: "{{from}}–{{to}} of {{total}}",
previousPage: "Previous page",
nextPage: "Next page",
allEvents: "All events",
eventType: "Event type",
identifier: "Identifier",
identifierPlaceholder: "Filter by email, user ID, or provider",
unknownEvent: "Activity event",
eventLabels: C
}, T = (e) => {
let t = e ?? 20;
return Number.isFinite(t) ? Math.min(100, Math.max(1, Math.floor(t))) : 20;
}, E = t("dash", (e = {}) => ({
admin: e.admin ?? !0,
user: e.user ?? !0,
organization: e.organization ?? !0,
pageSize: T(e.pageSize),
showIpAddress: e.showIpAddress ?? !1,
localization: {
...w,
...e.localization,
eventLabels: {
...w.eventLabels,
...e.localization?.eventLabels
}
},
viewPaths: { settings: { activity: e.path ?? "activity" } }
}));
//#endregion
export { l as DashClientError, f as dashAllAuditLogsOptions, d as dashAuditLogsOptions, C as dashEventLabels, w as dashLocalization, E as dashPlugin, c as dashQueryKeys, p as dashUserAuditLogsOptions, _ as ensureDashAllAuditLogs, m as ensureDashAuditLogs, b as ensureDashUserAuditLogs, y as fetchDashAllAuditLogs, g as fetchDashAuditLogs, S as fetchDashUserAuditLogs, i as formatDashEventName, a as getDashEventDetail, s as getDashEventKey, o as getDashEventLocation, v as prefetchDashAllAuditLogs, h as prefetchDashAuditLogs, x as prefetchDashUserAuditLogs };