UNPKG

@better-auth-ui/core

Version:

Authentication components and data utilities for [Better Auth](https://better-auth.com), available for React and Solid.

230 lines (229 loc) 6.26 kB
import { t as e } from "../../auth-query-keys-B_bcsA3s.js"; import { r as t } from "../../auth-query-retry-Dyv0hsPy.js"; import { t as n } from "../../create-auth-plugin-BXWyolC8.js"; import { skipToken as r } from "@tanstack/query-core"; //#region src/plugins/api-key/api-key-expiration.ts var i = [30, 90], a = 86400, o = (e) => Number.isFinite(e) && e > 0; function s(e = {}) { let t = Array.from(new Set((e.intervals ?? i).filter(o))), n = e.allowNever ?? !0, r = e.defaultInterval === void 0 ? i[0] : e.defaultInterval; return t.length === 0 && !n ? !1 : { intervals: t, defaultInterval: r === null && n ? null : r !== null && t.includes(r) ? r : t[0] ?? null, allowNever: n }; } var c = (e) => e * a, l = { apiKey: "API key", apiKeys: "API keys", apiKeysDescription: "Create an API key for programmatic access to your account.", createApiKey: "Create API key", noApiKeys: "No API keys", name: "Name", expiration: "Expiration", day: "day", days: "days", never: "Never", created: "Created", expires: "Expires", neverExpires: "Never expires", newApiKey: "New API key", newApiKeyWarning: "This is the only time you'll see this API key. Copy and store it somewhere safe.", deleteApiKey: "Delete API key", deleteApiKeyWarning: "This action cannot be undone. Any service using this API key will stop working immediately.", dismissNewKey: "I've saved my key", editApiKey: "Edit API key", configuration: "Configuration", enabled: "Enabled", disabled: "Disabled", requests: "Requests", remaining: "Remaining", lastRequest: "Last request", neverRequested: "Never requested", sortBy: "Sort by", newest: "Newest", oldest: "Oldest", nameAscending: "Name A–Z", nameDescending: "Name Z–A", previousPage: "Previous page", nextPage: "Next page" }, u = { all: ["auth", "apiKey"], create: [ "auth", "apiKey", "create" ], delete: [ "auth", "apiKey", "delete" ], update: [ "auth", "apiKey", "update" ] }, d = (e) => e !== void 0 && Number.isFinite(e) ? Math.max(1, Math.floor(e)) : 10, f = n("apiKey", (e = {}) => { let t = e.keyExpiration !== !1 && s(e.keyExpiration); return { localization: { ...l, ...e.localization }, organization: e.organization ?? !1, keyExpiration: t, configurations: e.configurations ?? [], pageSize: d(e.pageSize) }; }), p = { all: (t) => [...e.user(t), "apiKey"], lists: (e) => [...p.all(e), "list"], list: (e, t) => [...p.lists(e), t ?? null], details: (e) => [...p.all(e), "detail"], detail: (e, t) => [...p.details(e), t ?? null] }; //#endregion //#region src/plugins/api-key/create-api-key-mutation.ts function m(e, t) { return { mutationKey: u.create, mutationFn: (t) => { let { configId: n, name: r, expiresIn: i, organizationId: a, prefix: o, metadata: s, fetchOptions: c } = t ?? {}; return e.apiKey.create({ ...n === void 0 ? {} : { configId: n }, ...r === void 0 ? {} : { name: r }, ...i === void 0 ? {} : { expiresIn: i }, ...a === void 0 ? {} : { organizationId: a }, ...o === void 0 ? {} : { prefix: o }, ...s === void 0 ? {} : { metadata: s }, fetchOptions: { ...c, throw: !0 } }); }, meta: { awaits: [p.lists(t)] } }; } //#endregion //#region src/plugins/api-key/delete-api-key-mutation.ts function h(e, t) { return { mutationKey: u.delete, mutationFn: (t) => e.apiKey.delete({ ...t, fetchOptions: { ...t?.fetchOptions, throw: !0 } }), meta: { awaits: [p.all(t)] } }; } //#endregion //#region src/plugins/api-key/get-api-key-query.ts function g(e, n, i) { return { queryKey: p.detail(n, i?.query), queryFn: n && i?.query?.id ? ({ signal: n }) => e.apiKey.get({ ...i, fetchOptions: t(i.fetchOptions, n) }) : r }; } var _ = (e, t, n, r) => { let { fetchOptions: i, query: a, ...o } = r; return e.ensureQueryData({ ...g(t, n, { query: a, fetchOptions: i }), ...o }); }, v = (e, t, n, r) => { let { fetchOptions: i, query: a, ...o } = r; return e.prefetchQuery({ ...g(t, n, { query: a, fetchOptions: i }), ...o }); }, y = (e, t, n, r) => { let { fetchOptions: i, query: a, ...o } = r; return e.fetchQuery({ ...g(t, n, { query: a, fetchOptions: i }), ...o }); }, b = (e, t, n, r) => e.getQueryData(p.detail(n, r?.query)); //#endregion //#region src/plugins/api-key/list-api-keys-query.ts function x(e, n, i) { let a = p.list(n, i?.query), o = i?.query, s = o?.configId !== "organization" || !!o.organizationId; return { queryKey: a, queryFn: n && s ? ({ signal: n }) => e.apiKey.list({ ...i, fetchOptions: t(i?.fetchOptions, n) }) : r }; } var S = (e, t, n, r) => { let { fetchOptions: i, query: a, ...o } = r ?? {}; return e.ensureQueryData({ ...x(t, n, { query: a, fetchOptions: i }), ...o }); }, C = (e, t, n, r) => { let { fetchOptions: i, query: a, ...o } = r ?? {}; return e.prefetchQuery({ ...x(t, n, { query: a, fetchOptions: i }), ...o }); }, w = (e, t, n, r) => { let { fetchOptions: i, query: a, ...o } = r ?? {}; return e.fetchQuery({ ...x(t, n, { query: a, fetchOptions: i }), ...o }); }, T = (e, t, n, r) => { let i = p.list(n, r?.query); return e.getQueryData(i); }; //#endregion //#region src/plugins/api-key/update-api-key-mutation.ts function E(e, t) { return { mutationKey: u.update, mutationFn: (t) => { let { configId: n, keyId: r, name: i, fetchOptions: a } = t; return e.apiKey.update({ keyId: r, ...n === void 0 ? {} : { configId: n }, ...i === void 0 ? {} : { name: i }, fetchOptions: { ...a, throw: !0 } }); }, meta: { awaits: [p.all(t)], errorPresentation: "inline" } }; } //#endregion export { a as API_KEY_EXPIRATION_SECONDS_PER_DAY, i as DEFAULT_API_KEY_EXPIRATION_INTERVALS, c as apiKeyExpirationDaysToSeconds, l as apiKeyLocalization, u as apiKeyMutationKeys, f as apiKeyPlugin, p as apiKeyQueryKeys, m as createApiKeyOptions, h as deleteApiKeyOptions, _ as ensureGetApiKey, S as ensureListApiKeys, y as fetchGetApiKey, w as fetchListApiKeys, b as getApiKey, g as getApiKeyOptions, T as getListApiKeys, x as listApiKeysOptions, v as prefetchGetApiKey, C as prefetchListApiKeys, s as resolveApiKeyExpirationOptions, E as updateApiKeyOptions };