El SDK
El SDK de StudioCMS es una herramienta poderosa que te permite interactuar con StudioCMS de forma programática. Proporciona un conjunto de funciones y utilidades que te permiten gestionar y servir tu contenido usando Astro DB. También proporciona la base para el Panel de Control de StudioCMS.
El SDK de StudioCMS está disponible como un módulo virtual en tu proyecto Astro. Puedes importarlo usando la siguiente sintaxis:
import const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK from 'studiocms:sdk';// Oimport const SDKCached: { GET: { page: { byId: (id: string) => Promise<PageDataCacheObject>; bySlug: (slug: string) => Promise<PageDataCacheObject>; }; pages: (includeDrafts?: boolean) => Promise<PageDataCacheObject[]>; siteConfig: () => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; pageFolderTree: (includeDrafts?: boolean) => Promise<FolderTreeCacheObject>; folderList: () => Promise<FolderListCacheObject>; folder: (id: string) => Promise<{ name: string; id: string; parent: string | null; } | undefined>; }; CLEAR: { page: { byId: (id: string) => void; bySlug: (slug: string) => void; }; pages: () => void; latestVersion: () => void; folderTree: () => void; folderList: () => void; }; UPDATE: { page: { byId: (id: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; bySlug: (slug: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; }; siteConfig: (data: SiteConfig) => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; folderList: () => ...
SDKCached from 'studiocms:sdk/cache';
El objeto studioCMSSDK
proporciona un conjunto de funciones y utilidades que te permiten interactuar con StudioCMS. Puedes usar estas funciones para crear, leer, actualizar y eliminar contenido en tu proyecto Astro.
El objeto studioCMSSDKCached
proporciona un conjunto de funciones y utilidades que te permiten interactuar con el SDK de StudioCMS con una capa de caché encima. Puedes usar estas funciones para almacenar en caché contenido en tu proyecto Astro.
SDK de StudioCMS (estándar)
'Read the “', SDK de StudioCMS (estándar), '” section'El objeto SDK.AUTH
proporciona un conjunto de funciones y utilidades que te permiten gestionar la autenticación en tu proyecto Astro. Puedes usar estas funciones para autenticar usuarios, gestionar sesiones y más.
import const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK from 'studiocms:sdk';
const { const oAuth: { create: (data: { provider: string; providerUserId: string; userId: string; }) => Promise<{ provider: string; providerUserId: string; userId: string; }>; delete: (userId: string, provider: string) => Promise<DeletionResponse>; searchProvidersForId: (providerId: string, userId: string) => Promise<{ ...; } | undefined>;}
oAuth, const permission: { currentStatus: (userId: string) => Promise<{ user: string; rank: string; } | undefined>;}
permission, const session: { create: (data: { userId: string; expiresAt: Date; id?: string; }) => Promise<{ userId: string; id: string; expiresAt: Date; }>; sessionWithUser: (sessionId: string) => Promise<{ user: { ...; }; session: { ...; }; }[]>; delete: (sessionId: string) => Promise<DeletionResponse>; update: (sessionId: string, newDate: Date) => Promise<{ ...; }[]>;}
session, const user: { create: (newUserData: { name: string; username: string; id?: string; url?: string | null; email?: string | null; avatar?: string | null; password?: string | null; updatedAt?: Date | null; createdAt?: Date | null; }, rank?: "visitor" | "editor" | "admin" | "owner") => Promise<{ ...; }>; update: (userId: string, userData: Partial<...>) => Promise<{ ...; }>; searchUsersForUsernameOrEmail: (username: string, email: string) => Promise<{ usernameSearch: { ...; }[]; emailSearch: { ...; }[]; }>; ghost: { verifyExists: () => Promise<boolean>; create: () => Promise<{ name: string; username: string; email: string | null; id: string; url: string | null; avatar: string | null; password: string | null; updatedAt: Date | null; createdAt: Date | null; }>; get: () => Promise<{ name: string; username: string; email: string | null; id: string; url: string | null; avatar: string | null; password: string | null; updatedAt: Date | null; createdAt: Date | null; } | undefined>; };}
user,} = const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK.type AUTH: { oAuth: { create: (data: { provider: string; providerUserId: string; userId: string; }) => Promise<{ provider: string; providerUserId: string; userId: string; }>; delete: (userId: string, provider: string) => Promise<DeletionResponse>; searchProvidersForId: (providerId: string, userId: string) => Promise<{ provider: string; providerUserId: string; userId: string; } | undefined>; }; permission: { currentStatus: (userId: string) => Promise<{ ...; } | undefined>; }; session: { create: (data: { ...; }) => Promise<{ ...; }>; sessionWithUser: (sessionId: string) => Promise<{ user: { ...; }; session: { ...; }; }[]>; delete: (sessionId: string) => Promise<DeletionResponse>; update: (sessionId: string, newDate: Date) => Promise<{ ...; }[]>; }; user: { create: (newUserData: { ...; }, rank?: "visitor" | "editor" | "admin" | "owner") => Promise<{ ...; }>; update: (userId: string, userData: Partial<...>) => Promise<{ ...; }>; searchUsersForUsernameOrEmail: (username: string, email: string) => Promise<{ usernameSearch: { ...; }[]; emailSearch: { ...; } ...
AUTH;
El objeto SDK.INIT
proporciona un conjunto de funciones y utilidades que te permiten inicializar el SDK de StudioCMS en tu proyecto Astro. Puedes usar estas funciones para configurar el SDK, configurarlo y más.
import const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK from 'studiocms:sdk';
const { const siteConfig: (config: { title: string; description: string; id?: number; defaultOgImage?: string | null; siteIcon?: string | null; loginPageBackground?: string; loginPageCustomImage?: string | null; enableDiffs?: boolean; diffPerPage?: number; gridItems?: unknown;}) => Promise<{ ...;}>
siteConfig, const ghostUser: () => Promise<{ id: string; name: string; url: string | null; email: string | null; avatar: string | null; username: string; password: string | null; updatedAt: Date | null; createdAt: Date | null;}>
ghostUser,} = const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK.type INIT: { siteConfig: (config: { title: string; description: string; id?: number; defaultOgImage?: string | null; siteIcon?: string | null; loginPageBackground?: string; loginPageCustomImage?: string | null; enableDiffs?: boolean; diffPerPage?: number; gridItems?: unknown; }) => Promise<{ ...; }>; ghostUser: () => Promise<{ ...; }>;}
INIT;
El objeto SDK.GET
proporciona un conjunto de funciones y utilidades que te permiten recuperar contenido de Astro DB. Puedes usar estas funciones para obtener contenido por ID, obtener contenido por tipo y más.
import const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK from 'studiocms:sdk';
const { const database: { users: () => Promise<CombinedUserData[]>; pages: (includeDrafts?: boolean, tree?: FolderNode[]) => Promise<CombinedPageData[]>; config: () => Promise<{ ...; } | undefined>; folders: () => Promise<{ ...; }[]>;}
database, const databaseEntry: { users: { byId: (id: string) => Promise<CombinedUserData | undefined>; byUsername: (username: string) => Promise<CombinedUserData | undefined>; byEmail: (email: string) => Promise<CombinedUserData | undefined>; }; pages: { byId: (id: string, tree?: FolderNode[]) => Promise<CombinedPageData | undefined>; bySlug: (slug: string, tree?: FolderNode[]) => Promise<CombinedPageData | undefined>; }; folder: (id: string) => Promise<{ ...; } | undefined>;}
databaseEntry, const databaseTable: { users: () => Promise<{ name: string; username: string; email: string | null; id: string; url: string | null; avatar: string | null; password: string | null; updatedAt: Date | null; createdAt: Date | null; }[]>; ... 9 more ...; pageFolderStructure: () => Promise<{ name: string; id: string; parent: string | null; }[]>;}
databaseTable, const permissionsLists: { all: () => Promise<CombinedRank[]>; owners: () => Promise<SingleRank[]>; admins: () => Promise<SingleRank[]>; editors: () => Promise<SingleRank[]>; visitors: () => Promise<SingleRank[]>;}
permissionsLists, const packagePages: (packageName: string, tree?: FolderNode[]) => Promise<CombinedPageData[]>
packagePages,} = const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK.type GET: { database: { users: () => Promise<CombinedUserData[]>; pages: (includeDrafts?: boolean, tree?: FolderNode[]) => Promise<CombinedPageData[]>; config: () => Promise<{ id: number; title: string; description: string; defaultOgImage: string | null; ... 5 more ...; gridItems: unknown; } | undefined>; folders: () => Promise<{ ...; }[]>; }; databaseEntry: { users: { byId: (id: string) => Promise<CombinedUserData | undefined>; byUsername: (username: string) => Promise<CombinedUserData | undefined>; byEmail: (email: string) => Promise<CombinedUserData | undefined>; }; pages: { byId: (id: string, tree?: FolderNode[]) => Promise<CombinedPageData | undefined>; bySlug: (slug: string, tree?: FolderNode[]) => Promise<CombinedPageData | undefined>; }; folder: (id: string) => Promise<{ ...; } | undefined>; }; databaseTable: { users: () => Promise<{ name: string; username: string; email: string | null; id: string; url: string | null; avatar: string | null; password: string | null; updatedAt: Date | null; createdAt: Date | null; }[]>; oAuthAccounts: () => Promise<{ provider: string; providerUserId: string; userId: string; }[]>; sessionTable: () => ...
GET;
El objeto SDK.POST
proporciona un conjunto de funciones y utilidades que te permiten crear contenido en Astro DB. Puedes usar estas funciones para crear contenido por tipo, crear contenido por ID y más.
import const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK from 'studiocms:sdk';
const { const databaseEntry: { pages: (pageData: { title: string; description: string; slug: string; id?: string; package?: string; showOnNav?: boolean; publishedAt?: Date; updatedAt?: Date | null; contentLang?: string; heroImage?: string; ... 7 more ...; draft?: boolean | null; }, pageContent: CombinedInsertContent) => Promise<addDatabaseEntryInsertPage>; ... 5 more ...; folder: (folder: { ...; }) => Promise<{ ...; }[]>;}
databaseEntry, const databaseEntries: { tags: (data: { description: string; slug: string; name: string; id?: number; meta?: unknown; }[]) => Promise<PageDataTagsInsertResponse[]>; categories: (data: { ...; }[]) => Promise<PageDataCategoriesInsertResponse[]>; permissions: (data: { ...; }[]) => Promise<{ ...; }[]>; pages: (pages: MultiPageInsert) => Promise<void>;}
databaseEntries,} = const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK.type POST: { databaseEntry: { pages: (pageData: { title: string; description: string; slug: string; id?: string; package?: string; showOnNav?: boolean; publishedAt?: Date; updatedAt?: Date | null; contentLang?: string; ... 8 more ...; draft?: boolean | null; }, pageContent: CombinedInsertContent) => Promise<addDatabaseEntryInsertPage>; pageContent: (pageContent: { ...; }) => Promise<PageContentReturnId[]>; tags: (tag: { ...; }) => Promise<PageDataTagsInsertResponse[]>; categories: (category: { ...; }) => Promise<{ id: number; }[]>; permissions: (userId: string, rank: string) => Promise<{ ...; }[]>; diffTracking: (diff: { ...; }) => Promise<{ ...; }[]>; folder: (folder: { ...; }) => Promise<{ ...; }[]>; }; databaseEntries: { tags: (data: { ...; }[]) => Promise<PageDataTagsInsertResponse[]>; categories: (data: { ...; }[]) => Promise<PageDataCategoriesInsertResponse[]>; permissions: (data: { ...; }[]) => Promise<{ ...; }[]>; pages: (pages: MultiPageInsert) => Promise<void>; };}
POST;
SDK.UPDATE
'Read the “', SDK.UPDATE, '” section'El objeto SDK.UPDATE
proporciona un conjunto de funciones y utilidades que te permiten actualizar contenido en Astro DB. Puedes usar estas funciones para actualizar contenido por ID, actualizar contenido por tipo y más.
import const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK from 'studiocms:sdk';
const { const page: (data: { id: string; package: string; title: string; description: string; showOnNav: boolean; publishedAt: Date; updatedAt: Date | null; slug: string; contentLang: string; heroImage: string; ... 7 more ...; draft: boolean | null;}) => Promise<{ ...;}>
page, const pageContent: (data: { id: string; contentLang: string; contentId: string; content: string | null;}) => Promise<{ id: string; contentLang: string; contentId: string; content: string | null;}>
pageContent, const tags: (data: { id: number; description: string; slug: string; name: string; meta: unknown;}) => Promise<{ id: number; description: string; slug: string; name: string; meta: unknown;}>
tags, const categories: (data: { id: number; description: string; slug: string; name: string; meta: unknown; parent: number | null;}) => Promise<{ id: number; description: string; slug: string; name: string; meta: unknown; parent: number | null;}>
categories, const permissions: (data: { user: string; rank: string;}) => Promise<{ user: string; rank: string;}>
permissions, const siteConfig: (data: { id: number; title: string; description: string; defaultOgImage: string | null; siteIcon: string | null; loginPageBackground: string; loginPageCustomImage: string | null; enableDiffs: boolean; diffPerPage: number; gridItems: unknown;}) => Promise<{ ...;}>
siteConfig, const folder: (data: { id: string; name: string; parent: string | null;}) => Promise<{ id: string; name: string; parent: string | null;}>
folder,} = const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK.type UPDATE: { page: (data: { id: string; package: string; title: string; description: string; showOnNav: boolean; publishedAt: Date; updatedAt: Date | null; slug: string; contentLang: string; heroImage: string; ... 7 more ...; draft: boolean | null; }) => Promise<{ ...; }>; ... 5 more ...; folder: (data: { ...; }) => Promise<{ ...; }>;}
UPDATE;
SDK.DELETE
'Read the “', SDK.DELETE, '” section'El objeto SDK.DELETE
proporciona un conjunto de funciones y utilidades que te permiten eliminar contenido de Astro DB. Puedes usar estas funciones para eliminar contenido por ID, eliminar contenido por tipo y más.
import const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK from 'studiocms:sdk';
const { const page: (id: string) => Promise<DeletionResponse>
page, const pageContent: (id: string) => Promise<DeletionResponse>
pageContent, const pageContentLang: (id: string, lang: string) => Promise<DeletionResponse>
pageContentLang, const tags: (id: number) => Promise<DeletionResponse>
tags, const categories: (id: number) => Promise<DeletionResponse>
categories, const permissions: (userId: string) => Promise<DeletionResponse>
permissions, const diffTracking: (id: string) => Promise<DeletionResponse>
diffTracking, const folder: (id: string) => Promise<DeletionResponse>
folder, const user: (id: string) => Promise<DeletionResponse>
user,} = const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK.type DELETE: { page: (id: string) => Promise<DeletionResponse>; pageContent: (id: string) => Promise<DeletionResponse>; ... 6 more ...; user: (id: string) => Promise<DeletionResponse>;}
DELETE;
El objeto SDK.db
proporciona un conjunto de funciones y utilidades que te permiten interactuar con Astro DB directamente. Puedes usar estas funciones para consultar la base de datos, ejecutar consultas personalizadas y más.
import const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK from 'studiocms:sdk';
const { const db: LibSQLDatabase<typeof import("/app/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected][email protected]__@astrojs+markdo_f7bx6jlnw364fw6qo65korgk3a/node_modules/studiocms/dist/sdk/tables")>
db } = const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK;
db
consulta la Guía de Astro DB^ SDK.REST_API
'Read the “', SDK.REST_API, '” section'El objeto SDK.REST_API
proporciona un conjunto de funciones y utilidades que la API REST utiliza para interactuar con StudioCMS y Astro DB.
import const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK from 'studiocms:sdk';
const { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>;}
tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date;}[]>
get: const getToken: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date;}[]>
getToken, new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date;}>
new: const newToken: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date;}>
newToken, delete: (userId: string, tokenId: string) => Promise<void>
delete: const deleteToken: (userId: string, tokenId: string) => Promise<void>
deleteToken, verify: (key: string) => Promise<false | { userId: string; key: string; rank: string;}>
verify: const verifyToken: (key: string) => Promise<false | { userId: string; key: string; rank: string;}>
verifyToken, },} = const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK.type REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; };}
REST_API;
SDK.diffTracking
'Read the “', SDK.diffTracking, '” section'El objeto SDK.diffTracking
proporciona un conjunto de funciones y utilidades que te permiten rastrear cambios en Astro DB. Puedes usar estas funciones para rastrear cambios en contenido, rastrear cambios en usuarios y más.
import const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK from 'studiocms:sdk';
const { const insert: (userId: string, pageId: string, data: { content: { start: string; end: string; }; metaData: { start: Partial<{ id: string; package: string; title: string; description: string; showOnNav: boolean; publishedAt: Date; updatedAt: Date | null; slug: string; ... 9 more ...; draft: boolean | null; }>; end: Partial<{ ...; }>; };}, diffLength: number) => Promise<{ userId: string; id: string; pageId: string; timestamp: Date | null; pageMetaData: unknown; pageContentStart: string; diff: string | null;}>
insert, const clear: (pageId: string) => Promise<void>
clear, const get: { byPageId: { all: (pageId: string) => Promise<{ userId: string; id: string; pageId: string; timestamp: Date | null; pageMetaData: unknown; pageContentStart: string; diff: string | null; }[]>; latest: (pageId: string, count: number) => Promise<{ userId: string; id: string; pageId: string; timestamp: Date | null; pageMetaData: unknown; pageContentStart: string; diff: string | null; }[]>; }; byUserId: { all: (userId: string) => Promise<{ userId: string; id: string; pageId: string; timestamp: Date | null; pageMetaData: unknown; pageContentStart: string; diff: string | null; }[]>; latest: (userId: string, count: number) => Promise<{ userId: string; id: string; pageId: string; timestamp: Date | null; pageMetaData: unknown; pageContentStart: string; diff: string | null; }[]>; }; single: (id: string) => Promise<{ userId: string; id: string; pageId: string; timestamp: Date | null; pageMetaData: unknown; pageContentStart: string; diff: string | null; } | undefined>; withHtml: (id: string, options?: Diff2HtmlConfig) => Promise<{ metadataDiffHtml: string; contentDiffHtml: string; userId: ...
get, const revertToDiff: (id: string, type: "content" | "data" | "both") => Promise<{ userId: string; id: string; pageId: string; timestamp: Date | null; pageMetaData: unknown; pageContentStart: string; diff: string | null;}>
revertToDiff} = const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK.diffTracking: { insert: (userId: string, pageId: string, data: { content: { start: string; end: string; }; metaData: { start: Partial<{ id: string; package: string; title: string; description: string; showOnNav: boolean; publishedAt: Date; updatedAt: Date | null; slug: string; contentLang: string; heroImage: string; ... 7 more ...; draft: boolean | null; }>; end: Partial<{ ...; }>; }; }, diffLength: number) => Promise<{ userId: string; id: string; pageId: string; timestamp: Date | null; pageMetaData: unknown; pageContentStart: string; diff: string | null; }>; clear: (pageId: string) => Promise<void>; get: { byPageId: { all: (pageId: string) => Promise<{ userId: string; id: string; pageId: string; timestamp: Date | null; pageMetaData: unknown; pageContentStart: string; diff: string | null; }[]>; latest: (pageId: string, count: number) => Promise<{ userId: string; id: string; pageId: string; timestamp: Date | null; pageMetaData: unknown; pageContentStart: string; ...
diffTracking;
Funciones Utilitarias
'Read the “', Funciones Utilitarias, '” section'El SDK de StudioCMS también proporciona un conjunto de funciones utilitarias que puedes usar para interactuar con el SDK. Estas funciones incluyen:
import const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK from 'studiocms:sdk';
const { const addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]
addPageToFolderTree, const findNodeById: (tree: FolderNode[], id: string) => FolderNode | null
findNodeById, const findNodeByPath: (tree: FolderNode[], path: string[]) => FolderNode | null
findNodeByPath, const findNodesAlongPath: (tree: FolderNode[], path: string[]) => FolderNode[]
findNodesAlongPath, const getFullPath: (tree: FolderNode[], path: string[]) => string[]
getFullPath, const parseIdNumberArray: (ids: unknown) => number[]
parseIdNumberArray, const parseIdStringArray: (ids: unknown) => string[]
parseIdStringArray, const generateRandomIDNumber: (length: number) => number
generateRandomIDNumber, const generateToken: (userId: string) => string
generateToken, const testToken: (token: string) => string | jwt.JwtPayload
testToken, const combineRanks: (rank: string, users: SingleRank[]) => CombinedRank[]
combineRanks, const verifyRank: (users: tsUsersSelect[], permissions: tsPermissionsSelect[], rank: string) => SingleRank[]
verifyRank, const buildFolderTree: () => Promise<FolderNode[]>
buildFolderTree, const getAvailableFolders: () => Promise<FolderListItem[]>
getAvailableFolders, const clearUserReferences: (userId: string) => Promise<boolean>
clearUserReferences, const collectCategories: (categoryIds: number[]) => Promise<CombinedPageData["categories"]>
collectCategories, const collectTags: (tagIds: number[]) => Promise<CombinedPageData["tags"]>
collectTags, const collectPageData: (page: { id: string; updatedAt: Date | null; categories: unknown; package: string; title: string; description: string; showOnNav: boolean; publishedAt: Date; slug: string; contentLang: string; ... 7 more ...; draft: boolean | null;}, tree: FolderNode[]) => Promise<CombinedPageData>
collectPageData, const collectUserData: (user: { id: string; url: string | null; name: string; email: string | null; avatar: string | null; username: string; password: string | null; updatedAt: Date | null; createdAt: Date | null;}) => Promise<CombinedUserData>
collectUserData, const generateRandomPassword: (length: number) => string
generateRandomPassword,} = const SDK: { addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[]; ... 28 more ...; REST_API: { tokens: { get: (userId: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }[]>; new: (userId: string, description: string) => Promise<{ description: string | null; userId: string; id: string; key: string; creationDate: Date; }>; delete: (userId: string, tokenId: string) => Promise<void>; verify: (key: string) => Promise<false | { userId: string; key: string; rank: string; }>; }; };}
SDK;
SDK de StudioCMS (Caché)
'Read the “', SDK de StudioCMS (Caché), '” section'El SDK de StudioCMS también proporciona una versión en caché del SDK con un subconjunto limitado de las características del SDK que incluye una capa de caché sobre el SDK estándar. Puedes importar el SDK en caché usando la siguiente sintaxis:
import const SDKCached: { GET: { page: { byId: (id: string) => Promise<PageDataCacheObject>; bySlug: (slug: string) => Promise<PageDataCacheObject>; }; pages: (includeDrafts?: boolean) => Promise<PageDataCacheObject[]>; siteConfig: () => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; pageFolderTree: (includeDrafts?: boolean) => Promise<FolderTreeCacheObject>; folderList: () => Promise<FolderListCacheObject>; folder: (id: string) => Promise<{ name: string; id: string; parent: string | null; } | undefined>; }; CLEAR: { page: { byId: (id: string) => void; bySlug: (slug: string) => void; }; pages: () => void; latestVersion: () => void; folderTree: () => void; folderList: () => void; }; UPDATE: { page: { byId: (id: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; bySlug: (slug: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; }; siteConfig: (data: SiteConfig) => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; folderList: () => ...
SDKCached from 'studiocms:sdk/cache';
SDKCached.GET
'Read the “', SDKCached.GET, '” section'El objeto SDKCached.GET
proporciona un conjunto de funciones y utilidades que te permiten recuperar contenido de Astro DB con una capa de caché encima. Puedes usar estas funciones para obtener contenido por ID, obtener contenido por tipo y más.
import const SDKCached: { GET: { page: { byId: (id: string) => Promise<PageDataCacheObject>; bySlug: (slug: string) => Promise<PageDataCacheObject>; }; pages: (includeDrafts?: boolean) => Promise<PageDataCacheObject[]>; siteConfig: () => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; pageFolderTree: (includeDrafts?: boolean) => Promise<FolderTreeCacheObject>; folderList: () => Promise<FolderListCacheObject>; folder: (id: string) => Promise<{ name: string; id: string; parent: string | null; } | undefined>; }; CLEAR: { page: { byId: (id: string) => void; bySlug: (slug: string) => void; }; pages: () => void; latestVersion: () => void; folderTree: () => void; folderList: () => void; }; UPDATE: { page: { byId: (id: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; bySlug: (slug: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; }; siteConfig: (data: SiteConfig) => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; folderList: () => ...
SDKCached from 'studiocms:sdk/cache';
const { const page: { byId: (id: string) => Promise<PageDataCacheObject>; bySlug: (slug: string) => Promise<PageDataCacheObject>;}
page, const pages: (includeDrafts?: boolean) => Promise<PageDataCacheObject[]>
pages, const siteConfig: () => Promise<SiteConfigCacheObject>
siteConfig, const latestVersion: () => Promise<VersionCacheObject>
latestVersion, const folderTree: () => Promise<FolderTreeCacheObject>
folderTree, const pageFolderTree: (includeDrafts?: boolean) => Promise<FolderTreeCacheObject>
pageFolderTree, const folderList: () => Promise<FolderListCacheObject>
folderList, const folder: (id: string) => Promise<{ name: string; id: string; parent: string | null;} | undefined>
folder,} = const SDKCached: { GET: { page: { byId: (id: string) => Promise<PageDataCacheObject>; bySlug: (slug: string) => Promise<PageDataCacheObject>; }; pages: (includeDrafts?: boolean) => Promise<PageDataCacheObject[]>; siteConfig: () => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; pageFolderTree: (includeDrafts?: boolean) => Promise<FolderTreeCacheObject>; folderList: () => Promise<FolderListCacheObject>; folder: (id: string) => Promise<{ name: string; id: string; parent: string | null; } | undefined>; }; CLEAR: { page: { byId: (id: string) => void; bySlug: (slug: string) => void; }; pages: () => void; latestVersion: () => void; folderTree: () => void; folderList: () => void; }; UPDATE: { page: { byId: (id: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; bySlug: (slug: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; }; siteConfig: (data: SiteConfig) => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; folderList: () => ...
SDKCached.type GET: { page: { byId: (id: string) => Promise<PageDataCacheObject>; bySlug: (slug: string) => Promise<PageDataCacheObject>; }; ... 6 more ...; folder: (id: string) => Promise<{ name: string; id: string; parent: string | null; } | undefined>;}
GET;
SDKCached.CLEAR
'Read the “', SDKCached.CLEAR, '” section'El objeto SDKCached.CLEAR
proporciona un conjunto de funciones y utilidades que te permiten limpiar la caché en el SDK en caché. Puedes usar estas funciones para limpiar la caché de un tipo de contenido específico, limpiar la caché de un ID de contenido específico y más.
import const SDKCached: { GET: { page: { byId: (id: string) => Promise<PageDataCacheObject>; bySlug: (slug: string) => Promise<PageDataCacheObject>; }; pages: (includeDrafts?: boolean) => Promise<PageDataCacheObject[]>; siteConfig: () => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; pageFolderTree: (includeDrafts?: boolean) => Promise<FolderTreeCacheObject>; folderList: () => Promise<FolderListCacheObject>; folder: (id: string) => Promise<{ name: string; id: string; parent: string | null; } | undefined>; }; CLEAR: { page: { byId: (id: string) => void; bySlug: (slug: string) => void; }; pages: () => void; latestVersion: () => void; folderTree: () => void; folderList: () => void; }; UPDATE: { page: { byId: (id: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; bySlug: (slug: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; }; siteConfig: (data: SiteConfig) => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; folderList: () => ...
SDKCached from 'studiocms:sdk/cache';
const { const page: { byId: (id: string) => void; bySlug: (slug: string) => void;}
page, const pages: () => void
pages, const latestVersion: () => void
latestVersion, const folderTree: () => void
folderTree, const folderList: () => void
folderList,} = const SDKCached: { GET: { page: { byId: (id: string) => Promise<PageDataCacheObject>; bySlug: (slug: string) => Promise<PageDataCacheObject>; }; pages: (includeDrafts?: boolean) => Promise<PageDataCacheObject[]>; siteConfig: () => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; pageFolderTree: (includeDrafts?: boolean) => Promise<FolderTreeCacheObject>; folderList: () => Promise<FolderListCacheObject>; folder: (id: string) => Promise<{ name: string; id: string; parent: string | null; } | undefined>; }; CLEAR: { page: { byId: (id: string) => void; bySlug: (slug: string) => void; }; pages: () => void; latestVersion: () => void; folderTree: () => void; folderList: () => void; }; UPDATE: { page: { byId: (id: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; bySlug: (slug: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; }; siteConfig: (data: SiteConfig) => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; folderList: () => ...
SDKCached.type CLEAR: { page: { byId: (id: string) => void; bySlug: (slug: string) => void; }; pages: () => void; latestVersion: () => void; folderTree: () => void; folderList: () => void;}
CLEAR;
SDKCached.UPDATE
'Read the “', SDKCached.UPDATE, '” section'El objeto SDKCached.UPDATE
proporciona un conjunto de funciones y utilidades que te permiten actualizar contenido en Astro DB con una capa de caché encima. Puedes usar estas funciones para actualizar contenido por ID, actualizar contenido por tipo y más.
import const SDKCached: { GET: { page: { byId: (id: string) => Promise<PageDataCacheObject>; bySlug: (slug: string) => Promise<PageDataCacheObject>; }; pages: (includeDrafts?: boolean) => Promise<PageDataCacheObject[]>; siteConfig: () => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; pageFolderTree: (includeDrafts?: boolean) => Promise<FolderTreeCacheObject>; folderList: () => Promise<FolderListCacheObject>; folder: (id: string) => Promise<{ name: string; id: string; parent: string | null; } | undefined>; }; CLEAR: { page: { byId: (id: string) => void; bySlug: (slug: string) => void; }; pages: () => void; latestVersion: () => void; folderTree: () => void; folderList: () => void; }; UPDATE: { page: { byId: (id: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; bySlug: (slug: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; }; siteConfig: (data: SiteConfig) => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; folderList: () => ...
SDKCached from 'studiocms:sdk/cache';
const { const page: { byId: (id: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; bySlug: (slug: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>;}
page, const siteConfig: (data: SiteConfig) => Promise<SiteConfigCacheObject>
siteConfig, const latestVersion: () => Promise<VersionCacheObject>
latestVersion, const folderTree: () => Promise<FolderTreeCacheObject>
folderTree, const folderList: () => Promise<FolderListCacheObject>
folderList, const folder: (data: tsPageFolderSelect) => Promise<{ name: string; id: string; parent: string | null;}>
folder,} = const SDKCached: { GET: { page: { byId: (id: string) => Promise<PageDataCacheObject>; bySlug: (slug: string) => Promise<PageDataCacheObject>; }; pages: (includeDrafts?: boolean) => Promise<PageDataCacheObject[]>; siteConfig: () => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; pageFolderTree: (includeDrafts?: boolean) => Promise<FolderTreeCacheObject>; folderList: () => Promise<FolderListCacheObject>; folder: (id: string) => Promise<{ name: string; id: string; parent: string | null; } | undefined>; }; CLEAR: { page: { byId: (id: string) => void; bySlug: (slug: string) => void; }; pages: () => void; latestVersion: () => void; folderTree: () => void; folderList: () => void; }; UPDATE: { page: { byId: (id: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; bySlug: (slug: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; }; siteConfig: (data: SiteConfig) => Promise<SiteConfigCacheObject>; latestVersion: () => Promise<VersionCacheObject>; folderTree: () => Promise<FolderTreeCacheObject>; folderList: () => ...
SDKCached.type UPDATE: { page: { byId: (id: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; bySlug: (slug: string, data: { pageData: tsPageDataSelect; pageContent: tsPageContentSelect; }) => Promise<PageDataCacheObject>; }; ... 4 more ...; folder: (data: tsPageFolderSelect) => Promise<{ name: string; id: string; parent: string | null; }>;}
UPDATE;
SDKCached.db
'Read the “', SDKCached.db, '” section'Este es un paso directo al objeto db
del SDK estándar.
SDK.db
para más información