UNPKG

studiocms

Version:

Astro Native CMS for AstroDB. Built from the ground up by the Astro community.

326 lines (325 loc) 14.1 kB
import type { AvailablePermissionRanks } from '@withstudiocms/auth-kit/types'; import { Effect } from '../../../effect.js'; import { AstroDB, SDKCore_Generators } from '../effect/index.js'; import { SDKCoreError } from '../errors.js'; import type { tsUsersInsert, tsUsersUpdate } from '../types/index.js'; declare const SDKCore_AUTH_base: Effect.Service.Class<SDKCore_AUTH, "studiocms/sdk/SDKCore/modules/auth", { readonly dependencies: readonly [import("effect/Layer").Layer<AstroDB, never, never>, import("effect/Layer").Layer<SDKCore_Generators, never, never>]; readonly effect: Effect.Effect<{ verifyEmail: { /** * Retrieves an email verification token by its ID. * * @param id - The ID of the email verification token to retrieve. * @returns A promise that resolves to the email verification token if found, otherwise undefined. * @throws {StudioCMS_SDK_Error} If an error occurs while retrieving the token. */ get: (input: string) => Effect.Effect<{ id: string; userId: string; token: string; expiresAt: Date; } | undefined, SDKCoreError, never>; /** * Creates a new email verification token in the database. * * @param userId - The ID of the user to create the token for. * @returns A promise that resolves to the created email verification token. * @throws {StudioCMS_SDK_Error} If an error occurs while creating the token. */ create: (userId: string) => Effect.Effect<{ id: string; userId: string; token: string; expiresAt: Date; }, SDKCoreError, never>; /** * Deletes an email verification token from the database. * * @param userId - The ID of the user associated with the token. * @returns A promise that resolves to the deletion response. * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the token. */ delete: (input: string) => Effect.Effect<import("@libsql/client").ResultSet, SDKCoreError, never>; }; oAuth: { /** * Creates a new OAuth account in the database. * * @param data - The data to insert into the OAuth account table. * @returns A promise that resolves to the inserted OAuth account. * @throws {StudioCMS_SDK_Error} If an error occurs while creating the OAuth account. */ create: (input: { provider: string; userId: string; providerUserId?: string | undefined; }) => Effect.Effect<{ provider: string; userId: string; providerUserId: string; }, SDKCoreError, never>; /** * Deletes an OAuth account from the database. * * @param userId - The ID of the user associated with the OAuth account. * @param provider - The provider of the OAuth account. * @returns A promise that resolves to a deletion response. * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the OAuth account. */ delete: (userId: string, provider: string) => Effect.Effect<{ status: string; message: string; }, SDKCoreError, never>; /** * Searches for OAuth accounts based on the provider ID and user ID. * * @param providerId - The provider ID to search for. * @param userId - The user ID to search for. * @returns A promise that resolves to the OAuth account data if found, otherwise undefined. * @throws {StudioCMS_SDK_Error} If an error occurs while searching for the OAuth account. */ searchProvidersForId: (providerId: string, userId: string) => Effect.Effect<{ provider: string; userId: string; providerUserId: string; } | undefined, SDKCoreError, never>; }; permission: { /** * Checks the current status of a user's permissions. */ currentStatus: (input: string) => Effect.Effect<{ user: string; rank: "unknown" | "owner" | "admin" | "editor" | "visitor"; } | undefined, SDKCoreError, never>; }; session: { /** * Creates a new session in the database. * * @param data - The data to insert into the session table. * @returns A promise that resolves to the inserted session. * @throws {StudioCMS_SDK_Error} If an error occurs while creating the session. */ create: (input: { userId: string; expiresAt: Date; id?: string | undefined; }) => Effect.Effect<{ id: string; userId: string; expiresAt: Date; }, SDKCoreError, never>; /** * Gets a session with the associated user. * * @param sessionId - The ID of the session to search for. * @returns A promise that resolves to the session with the associated user. * @throws {StudioCMS_SDK_Error} If an error occurs while getting the session with the user. */ sessionWithUser: (input: string) => Effect.Effect<{ user: { name: string; password: string | null; email: string | null; url: string | null; id: string; username: string; avatar: string | null; updatedAt: Date | null; createdAt: Date | null; emailVerified: boolean; notifications: string | null; }; session: { id: string; userId: string; expiresAt: Date; }; }[], SDKCoreError, never>; /** * Deletes a session from the database. * * @param sessionId - The ID of the session to delete. * @returns A promise that resolves to a deletion response. * @throws {StudioCMS_SDK_Error} If an error occurs while deleting the session. */ delete: (input: string) => Effect.Effect<{ status: string; message: string; }, SDKCoreError, never>; /** * Updates the expiration date of a session. * * @param sessionId - The ID of the session to update. * @param newDate - The new expiration date for the session. * @returns A promise that resolves to the updated session. * @throws {StudioCMS_SDK_Error} If an error occurs while updating the session. */ update: (sessionId: string, newDate: Date) => Effect.Effect<{ id: string; userId: string; expiresAt: Date; }[], SDKCoreError, never>; }; user: { /** * Creates a new user in the database. * * @param newUserData - The data to insert into the users table. * @returns A promise that resolves to the inserted user. * @throws {StudioCMS_SDK_Error} If an error occurs while creating the user. */ create: (newUserData: tsUsersInsert, rank?: AvailablePermissionRanks) => Effect.Effect<{ name: string; password: string | null; email: string | null; url: string | null; id: string; username: string; avatar: string | null; updatedAt: Date | null; createdAt: Date | null; emailVerified: boolean; notifications: string | null; }, SDKCoreError, never>; /** * Updates a user in the database. * * @param userId - The ID of the user to update. * @param userData - The data to update the user with. * @returns A promise that resolves to the updated user. * @throws {StudioCMS_SDK_Error} If an error occurs while updating the user. */ update: (userId: string, userData: tsUsersUpdate) => Effect.Effect<{ name: string; password: string | null; email: string | null; url: string | null; id: string; username: string; avatar: string | null; updatedAt: Date | null; createdAt: Date | null; emailVerified: boolean; notifications: string | null; }, SDKCoreError, never>; /** * Searches for users based on the provided username or email. * * @param username - The username to search for. * @param email - The email to search for. * @returns A promise that resolves to an object containing the search results for the username and email. * @throws {StudioCMS_SDK_Error} If an error occurs while searching for the username or email. */ searchUsersForUsernameOrEmail: (username?: string, email?: string) => Effect.Effect<{ usernameSearch: { name: string; password: string | null; email: string | null; url: string | null; id: string; username: string; avatar: string | null; updatedAt: Date | null; createdAt: Date | null; emailVerified: boolean; notifications: string | null; }[]; emailSearch: { name: string; password: string | null; email: string | null; url: string | null; id: string; username: string; avatar: string | null; updatedAt: Date | null; createdAt: Date | null; emailVerified: boolean; notifications: string | null; }[]; }, SDKCoreError, never>; ghost: { /** * Verifies if the ghost user exists in the database. * * @returns A promise that resolves to a boolean indicating if the ghost user exists. * @throws {StudioCMS_SDK_Error} If an error occurs while verifying the ghost user. */ verifyExists: () => Effect.Effect<boolean, SDKCoreError, never>; /** * Creates the ghost user in the database. * * @returns A promise that resolves to the inserted ghost user. * @throws {StudioCMS_SDK_Error} If an error occurs while creating the ghost user. */ create: () => Effect.Effect<{ name: string; password: string | null; email: string | null; url: string | null; id: string; username: string; avatar: string | null; updatedAt: Date | null; createdAt: Date | null; emailVerified: boolean; notifications: string | null; }, SDKCoreError, never>; /** * Gets the ghost user from the database. * * @returns A promise that resolves to the ghost user. * @throws {StudioCMS_SDK_Error} If an error occurs while getting the ghost user. */ get: () => Effect.Effect<{ name: string; password: string | null; email: string | null; url: string | null; id: string; username: string; avatar: string | null; updatedAt: Date | null; createdAt: Date | null; emailVerified: boolean; notifications: string | null; } | undefined, SDKCoreError, never>; }; }; }, never, AstroDB | SDKCore_Generators>; }>; /** * Provides authentication-related operations for the StudioCMS SDK. * * This service includes methods for managing email verification tokens, OAuth accounts, * user permissions, sessions, and users (including ghost users). * * @remarks * All database operations are wrapped with error handling for `LibSQLDatabaseError`, * returning a custom `SDKCoreError` with contextual information. * * @example * ```typescript * const auth = Effect.runPromise(SDKCore_AUTH.effect); * const user = await auth.user.create({ username: 'adam', email: 'adam@example.com' }); * ``` * * @service * @module studiocms/sdk/SDKCore/modules/auth * * @dependencies * - AstroDB.Default * - SDKCore_Generators.Default * * @effect * - genLogger('studiocms/sdk/SDKCore/modules/auth/effect') * * @see SDKCoreError * @see StudioCMS_SDK_Error */ export declare class SDKCore_AUTH extends SDKCore_AUTH_base { } export {};