studiocms
Version:
Astro Native CMS for AstroDB. Built from the ground up by the Astro community.
85 lines (84 loc) • 4.09 kB
TypeScript
import { Effect } from '../../../effect.js';
import { AstroDB, SDKCore_Generators } from '../effect/index.js';
declare const SDKCore_REST_API_base: Effect.Service.Class<SDKCore_REST_API, "studiocms/sdk/SDKCore/modules/rest_api", {
readonly dependencies: readonly [import("effect/Layer").Layer<AstroDB, never, never>, import("effect/Layer").Layer<SDKCore_Generators, never, never>];
readonly effect: Effect.Effect<{
tokens: {
/**
* Retrieves all API tokens for a specific user.
* @param userId - The ID of the user whose tokens are to be retrieved.
* @returns An Effect that resolves to an array of API keys for the user.
* @throws {LibSQLDatabaseError} If a database error occurs during the operation.
*/
get: (input: string) => Effect.Effect<{
key: string;
description: string | null;
id: string;
userId: string;
creationDate: Date;
}[], import("../errors.js").SDKCoreError, never>;
/**
* Creates a new API token for a user with the specified description.
* @param userId - The ID of the user for whom to create the token.
* @param description - A description for the API key.
* @returns An Effect that resolves to the created API key record.
* @throws {LibSQLDatabaseError} If a database error occurs during the operation.
*/
new: (userId: string, description: string) => Effect.Effect<{
key: string;
description: string | null;
id: string;
userId: string;
creationDate: Date;
}, import("../errors.js").SDKCoreError, never>;
/**
* Deletes an API token for a user by its ID.
* @param userId - The ID of the user whose token is to be deleted.
* @param tokenId - The ID of the API token to delete.
* @returns An Effect that resolves when the token is successfully deleted.
* @throws {LibSQLDatabaseError} If a database error occurs during the operation.
*/
delete: (userId: string, tokenId: string) => Effect.Effect<import("@libsql/client").ResultSet, import("../errors.js").SDKCoreError, never>;
/**
* Verifies an API key and retrieves the associated user ID and rank.
* @param key - The API key to verify.
* @returns An Effect that resolves to an object containing userId, key, and rank if valid, or false if invalid.
* @throws {LibSQLDatabaseError} If a database error occurs during the verification.
*/
verify: (key: string) => Effect.Effect<false | {
userId: string;
key: string;
rank: "unknown" | "owner" | "admin" | "editor" | "visitor";
}, import("../errors.js").SDKCoreError, never>;
};
}, never, AstroDB | SDKCore_Generators>;
}>;
/**
* Provides REST API token management functionality for the StudioCMS SDK.
*
* This service exposes methods for creating, retrieving, deleting, and verifying API tokens
* associated with users. It integrates with the database and token generator services.
*
* @remarks
* - Handles database errors gracefully using custom error handlers.
* - Uses Drizzle ORM for database operations.
* - Token verification also retrieves user rank from permissions table.
*
* @example
* ```typescript
* const api = yield* Effect.service(SDKCore_REST_API);
* const tokens = yield* api.tokens.get(userId);
* ```
*
* @dependencies
* - AstroDB.Default: Database service for executing queries.
* - SDKCore_Generators.Default: Token generation utilities.
*
* @effect
* - All methods return Effect-wrapped results for composability and error handling.
*
* @module studiocms/sdk/SDKCore/modules/rest_api
*/
export declare class SDKCore_REST_API extends SDKCore_REST_API_base {
}
export {};