The SDK
The StudioCMS SDK is a powerful tool that allows you to interact with StudioCMS programmatically. It provides a set of functions and utilities that allow you to manage and serve your content using Astro DB. It also provides the backbone for the StudioCMS Dashboard.
The StudioCMS SDK is available as a virtual module in your Astro project. You can import it using the following syntax:
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';// Orimport 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';
The studioCMSSDK
object provides a set of functions and utilities that allow you to interact with StudioCMS. You can use these functions to create, read, update, and delete content in your Astro project.
The studioCMSSDKCached
object provides a set of functions and utilities that allow you to interact with the StudioCMS SDK with a caching layer on top. You can use these functions to cache content in your Astro project.
StudioCMS SDK (Standard)
'Read the “', StudioCMS SDK (Standard), '” section'The SDK.AUTH
object provides a set of functions and utilities that allow you to manage authentication in your Astro project. You can use these functions to authenticate users, manage sessions, and more.
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;
The SDK.INIT
object provides a set of functions and utilities that allow you to initialize the StudioCMS SDK in your Astro project. You can use these functions to set up the SDK, configure it, and more.
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;
The SDK.GET
object provides a set of functions and utilities that allow you to retrieve content from Astro DB. You can use these functions to get content by ID, get content by type, and more.
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;
The SDK.POST
object provides a set of functions and utilities that allow you to create content in Astro DB. You can use these functions to create content by type, create content by ID, and more.
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'The SDK.UPDATE
object provides a set of functions and utilities that allow you to update content in Astro DB. You can use these functions to update content by ID, update content by type, and more.
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'The SDK.DELETE
object provides a set of functions and utilities that allow you to delete content from Astro DB. You can use these functions to delete content by ID, delete content by type, and more.
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;
The SDK.db
object provides a set of functions and utilities that allow you to interact with the Astro DB directly. You can use these functions to query the database, run custom queries, and more.
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
check out the Astro DB Guide^ SDK.REST_API
'Read the “', SDK.REST_API, '” section'The SDK.REST_API
object provides a set of functions and utilities that the REST API uses to interact with the StudioCMS and 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'The SDK.diffTracking
object provides a set of functions and utilities that allow you to track changes in Astro DB. You can use these functions to track changes in content, track changes in users, and more.
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;
Utility Functions
'Read the “', Utility Functions, '” section'The StudioCMS SDK also provides a set of utility functions that you can use to interact with the SDK. These functions include:
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;
StudioCMS SDK (Cached)
'Read the “', StudioCMS SDK (Cached), '” section'The StudioCMS SDK also provides a cached version of the SDK with a limited subset of the SDKs features that includes a caching layer on top of the standard SDK. You can import the cached SDK using the following syntax:
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'The SDKCached.GET
object provides a set of functions and utilities that allow you to retrieve content from Astro DB with a caching layer on top. You can use these functions to get content by ID, get content by type, and more.
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'The SDKCached.CLEAR
object provides a set of functions and utilities that allow you to clear the cache in the cached SDK. You can use these functions to clear the cache for a specific content type, clear the cache for a specific content ID, and more.
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'The SDKCached.UPDATE
object provides a set of functions and utilities that allow you to update content in Astro DB with a caching layer on top. You can use these functions to update content by ID, update content by type, and more.
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'This is a passthrough to the standard SDK db
object.
SDK.db
for more information