import { z } from "zod"; import { createAuthEndpoint } from "better-auth/api"; import { GenericEndpointContext, InferOptionSchema } from "better-auth"; import * as better_call0 from "better-call"; import { StandardSchemaV1 } from "better-call"; //#region src/utils/transform.d.ts type CapitalizeFirst = S extends `${infer First}${infer Rest}` ? `${Uppercase}${Rest}` : S; type TransformPath = S extends `${infer Head}/${infer Tail}` ? TransformPath<`${Head}${CapitalizeFirst}`> : S extends `${infer Head}-${infer Tail}` ? TransformPath<`${Head}${CapitalizeFirst}`> : CapitalizeFirst; type KebabStart = S extends `-${infer R}` ? KebabStart : S extends `/${infer R}` ? KebabStart : S extends `${infer F}${infer R}` ? F extends Lowercase ? `${F}${KebabCont}` : `${Lowercase}${KebabCont}` : S; type KebabCont = S extends `${infer F}${infer R}` ? F extends "-" | "/" ? `-${KebabStart}` : F extends Lowercase ? `${F}${KebabCont}` : `-${Lowercase}${KebabCont}` : S; type TransformClientPath = KebabStart; //#endregion //#region src/internal-types.d.ts type Permission = { statement: string; permissions: string[]; }; type AllOptional = { [K in keyof T$1]-?: {} extends Pick ? true : false }[keyof T$1] extends true ? true : false; type MakeOptionalIfAllOptional = AllOptional extends true ? T$1 | undefined : T$1; type InferPreferenceInput = MakeOptionalIfAllOptional<(OmitValue extends true ? {} : { value: StandardSchemaV1.InferInput; }) & (S["requireScopeId"] extends true ? { scopeId: string; } : { scopeId?: string; })>; type InferPreferenceOutput = StandardSchemaV1.InferOutput | S["defaultValues"] extends { [key in Preference]: infer V } ? V extends (() => infer R) ? Awaited : V extends undefined ? null : V : null; type EndpointPair = { set: ReturnType}/${TransformClientPath}/set`, { method: "POST"; metadata: { $Infer: { body: InferPreferenceInput; }; }; }, void>>; get: ReturnType}/${TransformClientPath}/get`, { method: "GET"; metadata: { $Infer: { query: InferPreferenceInput; }; }; }, InferPreferenceOutput>>; }; type FilteredGroupPreferences>> = { [K in keyof T$1 as T$1[K] extends false ? never : K]: T$1[K] }; type InferGroupInput, OmitValue extends boolean = false> = MakeOptionalIfAllOptional<(OmitValue extends true ? {} : { values: { [K in keyof FilteredGroupPreferences]: StandardSchemaV1.InferInput }; }) & { scopeId?: string; }>; type InferGroupOutput> = { [K in keyof FilteredGroupPreferences]: StandardSchemaV1.InferOutput | null }; type GroupEndpointPair> = { set: G["operations"] extends undefined | "write" | ["write", "read"] | ["read", "write"] ? ReturnType}/$${TransformClientPath}/set`, { method: "POST"; metadata: { $Infer: { body: InferGroupInput; }; }; }, void>> : never; get: G["operations"] extends undefined | "read" | ["write", "read"] | ["read", "write"] ? ReturnType}/$${TransformClientPath}/get`, { method: "GET"; metadata: { $Infer: { query: InferGroupInput; }; }; }, InferGroupOutput>> : never; }; type AffixedGroupEndpoints> = { [K in keyof GroupEndpointPair as `${Extract}${TransformPath}${TransformPath}Preferences`]: GroupEndpointPair[K] }; type AffixedEndpoints = { [K in keyof EndpointPair as `${Extract}${TransformPath}${TransformPath}Preference`]: EndpointPair[K] }; type PreferenceScopesToEndpoints> = { [K in keyof S & string]: { [T in keyof S[K]["preferences"] & string]: AffixedEndpoints }[keyof S[K]["preferences"] & string] & (S[K]["groups"] extends infer V ? V extends Record ? { [T in keyof V & string]: AffixedGroupEndpoints }[keyof V & string] : {} : {}) }[keyof S & string]; //#endregion //#region src/schema.d.ts declare const schema: { preference: { fields: { userId: { type: "string"; required: false; references: { model: string; field: string; }; }; scopeId: { type: "string"; required: false; }; scope: { type: "string"; }; key: { type: "string"; }; value: { type: "string"; sortable: true; }; updatedAt: { type: "date"; required: true; input: false; defaultValue: () => Date; onUpdate: () => Date; }; }; }; }; //#endregion //#region src/types.d.ts type PreferenceSchemaAttribute = { type: StandardSchemaV1; sensitive?: boolean; secret?: string; }; type PreferenceScopeGroupAttributes = Record> = { preferences: Partial>; operations?: "read" | "write" | ["read", "write"] | ["write", "read"]; }; type PreferenceScopeAttributes = Record, G extends Record> = Record>> = { preferences: S; groups?: G; defaultValues?: Partial<{ [K in keyof S]: StandardSchemaV1.InferInput | (() => Promise> | StandardSchemaV1.InferInput) }>; canRead?: ((data: { key: string[]; scope: string; scopeId?: string; }, ctx: GenericEndpointContext) => Promise | boolean | Promise | Permission) | boolean | Permission; canWrite?: ((data: { key: string[]; scope: string; scopeId?: string; values: Record; }, ctx: GenericEndpointContext) => Promise | boolean | Promise | Permission) | boolean | Permission; requireScopeId?: boolean; disableUserBinding?: boolean; mergeStrategy?: "deep" | "replace"; sensitive?: boolean; secret?: string; }; type PreferencesOptions = Record> = { scopes: Scopes; schema?: InferOptionSchema; }; type JSONType = z.infer>; //#endregion //#region src/index.d.ts declare const preferences: { , O extends PreferencesOptions>(options: O & { scopes: S; }): { id: "preferences"; endpoints: { getPreference: { (inputCtx_0: { body?: undefined; } & { method?: "GET" | undefined; } & { query: { scope: string; key: string; scopeId?: string | undefined; }; } & { params?: Record; } & { request?: Request; } & { headers?: HeadersInit; } & { asResponse?: boolean; returnHeaders?: boolean; use?: better_call0.Middleware[]; path?: string; } & { asResponse?: AsResponse | undefined; returnHeaders?: ReturnHeaders | undefined; }): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? { headers: Headers; response: any; } : any>; options: { method: "GET"; query: z.ZodObject<{ scope: z.ZodString; scopeId: z.ZodOptional; key: z.ZodString; }, z.core.$strip>; } & { use: any[]; }; path: "/preferences/get-preference"; }; setPreference: { (inputCtx_0: { body: { scope: string; key: string; value: z.core.util.JSONType; scopeId?: string | undefined; }; } & { method?: "POST" | undefined; } & { query?: Record | undefined; } & { params?: Record; } & { request?: Request; } & { headers?: HeadersInit; } & { asResponse?: boolean; returnHeaders?: boolean; use?: better_call0.Middleware[]; path?: string; } & { asResponse?: AsResponse | undefined; returnHeaders?: ReturnHeaders | undefined; }): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? { headers: Headers; response: void; } : void>; options: { method: "POST"; body: z.ZodObject<{ scope: z.ZodString; scopeId: z.ZodOptional; key: z.ZodString; value: z.ZodJSONSchema; }, z.core.$strip>; use: ((inputContext: better_call0.MiddlewareInputContext) => Promise<{ session: { session: Record & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; } | null; }>)[]; } & { use: any[]; }; path: "/preferences/set-preference"; }; } & PreferenceScopesToEndpoints; options: O & { scopes: S; }; schema: { preference: { fields: { userId: { type: "string"; required: false; references: { model: string; field: string; }; }; scopeId: { type: "string"; required: false; }; scope: { type: "string"; }; key: { type: "string"; }; value: { type: "string"; sortable: true; }; updatedAt: { type: "date"; required: true; input: false; defaultValue: () => Date; onUpdate: () => Date; }; }; }; }; $ERROR_CODES: { readonly PREFERENCE_SCOPE_NOT_FOUND: "Scope not found"; readonly PREFERENCE_SCOPE_PREFERENCE_NOT_FOUND: "Scope preference not found"; readonly PREFERENCE_SCOPE_ID_IS_REQUIRED: "Scope id is required"; readonly PREFERENCE_MISSING_PERMISSION: "Missing permission"; readonly PREFERENCES_ADMIN_PLUGIN_NOT_SETUP: "Admin plugin is not set up"; }; $Infer: { PreferenceScopes: Extract; "~PreferenceScopesDef": S; }; }; createScope: , G extends Record>, D extends PreferenceScopeAttributes>(data: D & { preferences: S; groups?: G; }) => D & { preferences: S; groups?: G; }; }; declare const createPreferenceScope: , G extends Record>, D extends PreferenceScopeAttributes>(data: D & { preferences: S; groups?: G; }) => D & { preferences: S; groups?: G; }; //#endregion //#region src/client.d.ts declare const preferencesClient: ; }; }>() => { id: "preferences"; $InferServerPlugin: ReturnType>>; getActions: () => { $Infer: { PreferenceScopes: Extract; }; }; }; //#endregion export { PreferenceSchemaAttribute as a, PreferencesOptions as c, JSONType as i, createPreferenceScope as n, PreferenceScopeAttributes as o, preferences as r, PreferenceScopeGroupAttributes as s, preferencesClient as t };