跳转到内容

SDK

StudioCMS SDK 是一个强大的工具,允许您以编程方式与 StudioCMS 交互。它提供了一套函数和实用工具,使您能够使用 Astro DB 管理和提供内容。它同时也是 StudioCMS 仪表板的核心基础。

StudioCMS SDK 在您的 Astro 项目中作为虚拟模块提供。您可以使用以下语法导入它:

import
module "studiocms:sdk"
SDK
from 'studiocms:sdk';
// 或者
import
import SDKCached
SDKCached
from 'studiocms:sdk/cache';
Error ts(2307) ― Cannot find module 'studiocms:sdk/cache' or its corresponding type declarations.

studioCMSSDK 对象提供了一套允许您与 StudioCMS 交互的函数和实用工具。您可以使用这些函数在 Astro 项目中创建、读取、更新和删除内容。

studioCMSSDKCached 对象提供了一套函数和实用工具,允许您在 StudioCMS SDK 之上使用缓存层进行交互。您可以使用这些函数在 Astro 项目中缓存内容。

SDK.AUTH 对象提供了一套管理 Astro 项目身份验证的函数和实用工具。您可以使用这些函数来验证用户、管理会话等。

import
module "studiocms:sdk"
SDK
from 'studiocms:sdk';
const {
const oAuth: any
oAuth
,
const permission: any
permission
,
const session: any
session
,
const user: any
user
,
} =
module "studiocms:sdk"
SDK
.AUTH;
Error ts(2339) ― Property 'AUTH' does not exist on type 'typeof import("studiocms:sdk")'.

SDK.INIT 对象提供了一套用于在 Astro 项目中初始化 StudioCMS SDK 的函数和实用工具。您可以使用这些函数设置 SDK、进行配置等。

import
module "studiocms:sdk"
SDK
from 'studiocms:sdk';
const {
const siteConfig: any
siteConfig
,
const ghostUser: any
ghostUser
,
} =
module "studiocms:sdk"
SDK
.INIT;
Error ts(2339) ― Property 'INIT' does not exist on type 'typeof import("studiocms:sdk")'.

SDK.GET 对象提供了一套从 Astro DB 检索内容的函数和实用工具。您可以使用这些函数按 ID 获取内容、按类型获取内容等。

import
module "studiocms:sdk"
SDK
from 'studiocms:sdk';
const {
const database: any
database
,
const databaseEntry: any
databaseEntry
,
const databaseTable: any
databaseTable
,
const permissionsLists: any
permissionsLists
,
const packagePages: any
packagePages
,
} =
module "studiocms:sdk"
SDK
.GET;
Error ts(2339) ― Property 'GET' does not exist on type 'typeof import("studiocms:sdk")'.

SDK.POST 对象提供了一套在 Astro DB 中创建内容的函数和实用工具。您可以使用这些函数按类型创建内容、按 ID 创建内容等。

import
module "studiocms:sdk"
SDK
from 'studiocms:sdk';
const {
const databaseEntry: any
databaseEntry
,
const databaseEntries: any
databaseEntries
,
} =
module "studiocms:sdk"
SDK
.POST;
Error ts(2339) ― Property 'POST' does not exist on type 'typeof import("studiocms:sdk")'.

SDK.UPDATE 对象提供了一套更新 Astro DB 中内容的函数和实用工具。您可以使用这些函数按 ID 更新内容、按类型更新内容等。

import
module "studiocms:sdk"
SDK
from 'studiocms:sdk';
const {
const page: any
page
,
const pageContent: any
pageContent
,
const tags: any
tags
,
const categories: any
categories
,
const permissions: any
permissions
,
const siteConfig: any
siteConfig
,
const folder: any
folder
,
} =
module "studiocms:sdk"
SDK
.UPDATE;
Error ts(2339) ― Property 'UPDATE' does not exist on type 'typeof import("studiocms:sdk")'.

SDK.DELETE 对象提供了一套从 Astro DB 中删除内容的函数和实用工具。您可以使用这些函数按 ID 删除内容、按类型删除内容等。

import
module "studiocms:sdk"
SDK
from 'studiocms:sdk';
const {
const page: any
page
,
const pageContent: any
pageContent
,
const pageContentLang: any
pageContentLang
,
const tags: any
tags
,
const categories: any
categories
,
const permissions: any
permissions
,
const diffTracking: any
diffTracking
,
const folder: any
folder
,
const user: any
user
,
} =
module "studiocms:sdk"
SDK
.DELETE;
Error ts(2339) ― Property 'DELETE' does not exist on type 'typeof import("studiocms:sdk")'.

SDK.db 对象提供了一套直接与 Astro DB 交互的函数和实用工具。您可以使用这些函数查询数据库、运行自定义查询等。

import
module "studiocms:sdk"
SDK
from 'studiocms:sdk';
const { db } =
module "studiocms:sdk"
SDK
;
Error ts(2339) ― Property 'db' does not exist on type 'typeof import("studiocms:sdk")'.
有关如何使用 db 的更多信息,请查看 Astro DB 指南^

SDK.REST_API 对象提供了一套 REST API 用来与 StudioCMS 和 Astro DB 交互的函数和实用工具。

import
module "studiocms:sdk"
SDK
from 'studiocms:sdk';
const {
any
tokens
: {
any
get
:
const getToken: any
getToken
,
any
new
:
const newToken: any
newToken
,
any
delete
:
const deleteToken: any
deleteToken
,
any
verify
:
const verifyToken: any
verifyToken
,
},
} =
module "studiocms:sdk"
SDK
.REST_API;
Error ts(2339) ― Property 'REST_API' does not exist on type 'typeof import("studiocms:sdk")'.

SDK.diffTracking 对象提供了一套跟踪 Astro DB 中变更的函数和实用工具。您可以使用这些函数跟踪内容变更、用户变更等。

import
module "studiocms:sdk"
SDK
from 'studiocms:sdk';
const {
const insert: any
insert
,
const clear: any
clear
,
const get: any
get
,
const revertToDiff: any
revertToDiff
} =
module "studiocms:sdk"
SDK
.diffTracking;
Error ts(2339) ― Property 'diffTracking' does not exist on type 'typeof import("studiocms:sdk")'.

StudioCMS SDK 还提供了一套可与 SDK 交互的实用工具函数。这些函数包括:

import
module "studiocms:sdk"
SDK
from 'studiocms:sdk';
const {
addPageToFolderTree,
Error ts(2339) ― Property 'addPageToFolderTree' does not exist on type 'typeof import("studiocms:sdk")'.
findNodeById,
Error ts(2339) ― Property 'findNodeById' does not exist on type 'typeof import("studiocms:sdk")'.
findNodeByPath,
Error ts(2339) ― Property 'findNodeByPath' does not exist on type 'typeof import("studiocms:sdk")'.
findNodesAlongPath,
Error ts(2339) ― Property 'findNodesAlongPath' does not exist on type 'typeof import("studiocms:sdk")'.
getFullPath,
Error ts(2339) ― Property 'getFullPath' does not exist on type 'typeof import("studiocms:sdk")'.
parseIdNumberArray,
Error ts(2339) ― Property 'parseIdNumberArray' does not exist on type 'typeof import("studiocms:sdk")'.
parseIdStringArray,
Error ts(2339) ― Property 'parseIdStringArray' does not exist on type 'typeof import("studiocms:sdk")'.
generateRandomIDNumber,
Error ts(2339) ― Property 'generateRandomIDNumber' does not exist on type 'typeof import("studiocms:sdk")'.
generateToken,
Error ts(2339) ― Property 'generateToken' does not exist on type 'typeof import("studiocms:sdk")'.
testToken,
Error ts(2339) ― Property 'testToken' does not exist on type 'typeof import("studiocms:sdk")'.
combineRanks,
Error ts(2339) ― Property 'combineRanks' does not exist on type 'typeof import("studiocms:sdk")'.
verifyRank,
Error ts(2339) ― Property 'verifyRank' does not exist on type 'typeof import("studiocms:sdk")'.
buildFolderTree,
Error ts(2339) ― Property 'buildFolderTree' does not exist on type 'typeof import("studiocms:sdk")'.
getAvailableFolders,
Error ts(2339) ― Property 'getAvailableFolders' does not exist on type 'typeof import("studiocms:sdk")'.
clearUserReferences,
Error ts(2339) ― Property 'clearUserReferences' does not exist on type 'typeof import("studiocms:sdk")'.
collectCategories,
Error ts(2339) ― Property 'collectCategories' does not exist on type 'typeof import("studiocms:sdk")'.
collectTags,
Error ts(2339) ― Property 'collectTags' does not exist on type 'typeof import("studiocms:sdk")'.
collectPageData,
Error ts(2339) ― Property 'collectPageData' does not exist on type 'typeof import("studiocms:sdk")'.
collectUserData,
Error ts(2339) ― Property 'collectUserData' does not exist on type 'typeof import("studiocms:sdk")'.
generateRandomPassword,
Error ts(2339) ― Property 'generateRandomPassword' does not exist on type 'typeof import("studiocms:sdk")'.
} =
module "studiocms:sdk"
SDK
;

StudioCMS SDK 还提供了一个具有部分标准 SDK 功能并在其基础上增加缓存层的缓存版本。您可以使用以下语法导入缓存版 SDK:

import
import SDKCached
SDKCached
from 'studiocms:sdk/cache';
Error ts(2307) ― Cannot find module 'studiocms:sdk/cache' or its corresponding type declarations.

SDKCached.GET 对象提供了一套带缓存的从 Astro DB 检索内容的函数和实用工具。您可以使用这些函数按 ID 获取内容、按类型获取内容等。

import
import SDKCached
SDKCached
from 'studiocms:sdk/cache';
Error ts(2307) ― Cannot find module 'studiocms:sdk/cache' or its corresponding type declarations.
const {
const page: any
page
,
const pages: any
pages
,
const siteConfig: any
siteConfig
,
const latestVersion: any
latestVersion
,
const folderTree: any
folderTree
,
const pageFolderTree: any
pageFolderTree
,
const folderList: any
folderList
,
const folder: any
folder
,
} =
import SDKCached
SDKCached
.
any
GET
;

SDKCached.CLEAR 对象提供了一套用于清除缓存版 SDK 中缓存的函数和实用工具。您可以使用这些函数清除特定内容类型的缓存、清除特定内容 ID 的缓存等。

import
import SDKCached
SDKCached
from 'studiocms:sdk/cache';
Error ts(2307) ― Cannot find module 'studiocms:sdk/cache' or its corresponding type declarations.
const {
const page: any
page
,
const pages: any
pages
,
const latestVersion: any
latestVersion
,
const folderTree: any
folderTree
,
const folderList: any
folderList
,
} =
import SDKCached
SDKCached
.
any
CLEAR
;

SDKCached.UPDATE 对象提供了一套带缓存的更新 Astro DB 中内容的函数和实用工具。您可以使用这些函数按 ID 更新内容、按类型更新内容等。

import
import SDKCached
SDKCached
from 'studiocms:sdk/cache';
Error ts(2307) ― Cannot find module 'studiocms:sdk/cache' or its corresponding type declarations.
const {
const page: any
page
,
const siteConfig: any
siteConfig
,
const latestVersion: any
latestVersion
,
const folderTree: any
folderTree
,
const folderList: any
folderList
,
const folder: any
folder
,
} =
import SDKCached
SDKCached
.
any
UPDATE
;

这是指向标准 SDK db 对象的直接通路。

更多信息请参见 SDK.db