Aller au contenu

Le SDK

Le SDK de StudioCMS est un outil puissant qui vous permet d’interagir avec StudioCMS par programmation. Il fournit un ensemble de fonctions et d’utilitaires pour gérer et diffuser votre contenu via Astro DB. Il constitue également la base du tableau de bord de StudioCMS.

Le SDK de StudioCMS est disponible sous forme de module virtuel dans votre projet Astro. Vous pouvez l’importer avec la syntaxe suivante :

import
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
SDK
from 'studiocms:sdk';
// Ou
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>;
databaseTable: {
...;
};
};
... 5 more ...;
diffTracking: {
...;
};
}
SDKCached
from 'studiocms:sdk/cache';

L’objet studioCMSSDK fournit un ensemble de fonctions et d’utilitaires qui vous permettent d’interagir avec StudioCMS. Vous pouvez utiliser ces fonctions pour créer, lire, mettre à jour et supprimer du contenu dans votre projet Astro.

L’objet studioCMSSDKCached fournit un ensemble de fonctions et d’utilitaires qui vous permettent d’interagir avec le SDK de StudioCMS avec une couche de mise en cache par-dessus. Vous pouvez utiliser ces fonctions pour mettre en cache le contenu de votre projet Astro.

L’objet SDK.AUTH fournit un ensemble de fonctions et d’utilitaires qui vous permettent de gérer l’authentification dans votre projet Astro. Vous pouvez utiliser ces fonctions pour authentifier les utilisateurs, gérer les sessions, etc.

import
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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<{
id: string;
userId: 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;
emailVerified?: boolean;
notifications?: string | 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;
password: string | null;
email: string | null;
url: string | null;
username: string;
id: string;
avatar: string | null;
updatedAt: Date | null;
createdAt: Date | null;
emailVerified: boolean;
notifications: string | null;
}>;
get: () => Promise<{
name: string;
password: string | null;
email: string | null;
url: string | null;
username: string;
id: string;
avatar: string | null;
updatedAt: Date | null;
createdAt: Date | null;
emailVerified: boolean;
notifications: string | ...
user
,
} =
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
SDK
.
type AUTH: {
verifyEmail: {
get: (id: string) => Promise<{
id: string;
userId: string;
token: string;
expiresAt: Date;
} | null>;
create: (userId: string) => Promise<{
id: string;
userId: string;
token: string;
expiresAt: Date;
}>;
delete: (userId: string) => Promise<void>;
};
oAuth: {
create: (data: {
...;
}) => Promise<{
...;
}>;
delete: (userId: string, provider: string) => Promise<DeletionResponse>;
searchProvidersForId: (providerId: string, userId: string) => Promise<{
...;
} | 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 ...
AUTH
;

L’objet SDK.INIT fournit un ensemble de fonctions et d’utilitaires qui vous permettent d’initialiser le SDK de StudioCMS dans votre projet Astro. Vous pouvez utiliser ces fonctions pour installer et configurer le SDK, et bien plus encore.

import
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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;
enableMailer?: boolean;
}) => 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;
emailVerified: boolean;
notifications: string | null;
}>
ghostUser
,
} =
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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;
enableMailer?: boolean;
}) => Promise<{
...;
}>;
ghostUser: () => Promise<{
...;
}>;
}
INIT
;

L’objet SDK.GET fournit un ensemble de fonctions et d’utilitaires qui vous permettent de récupérer du contenu depuis Astro DB. Vous pouvez utiliser ces fonctions pour obtenir du contenu par identifiant, par type, etc.

import
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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;
password: string | null;
email: string | null;
url: string | null;
username: string;
id: string;
avatar: string | null;
updatedAt: Date | null;
createdAt: Date | null;
emailVerified: boolean;
notifications: string | null;
}[]>;
... 11 more ...;
emailVerificationTokens: () => Promise<{
id: string;
userId: string;
token: string;
expiresAt: Date;
}[]>;
}
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[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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;
... 6 more ...;
enableMailer: boolean;
} | 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;
password: string | null;
email: string | null;
url: string | null;
username: string;
id: string;
avatar: string | null;
updatedAt: Date | null;
createdAt: Date | null;
emailVerified: boolean;
notifications: string | null;
}[]>;
oAuthAccounts: () => Promise<{
userId: string;
provider: string ...
GET
;

L’objet SDK.POST fournit un ensemble de fonctions et d’utilitaires qui vous permettent de créer du contenu dans Astro DB. Vous pouvez utiliser ces fonctions pour créer du contenu par type, par ID, etc.

import
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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: {
name: string;
description: string;
slug: string;
meta: unknown;
id?: number;
}[]) => 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[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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
;

L’objet SDK.UPDATE fournit un ensemble de fonctions et d’utilitaires qui vous permettent de mettre à jour le contenu dans Astro DB. Vous pouvez utiliser ces fonctions pour mettre à jour le contenu par ID, par type, etc.

import
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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;
name: string;
description: string;
slug: string;
meta: unknown;
}) => Promise<{
id: number;
name: string;
description: string;
slug: string;
meta: unknown;
}>
tags
,
const categories: (data: {
id: number;
name: string;
description: string;
slug: string;
meta: unknown;
parent: number | null;
}) => Promise<{
id: number;
name: string;
description: string;
slug: 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;
enableMailer: boolean;
}) => 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[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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
;

L’objet SDK.DELETE fournit un ensemble de fonctions et d’utilitaires qui vous permettent de supprimer du contenu d’Astro DB. Vous pouvez utiliser ces fonctions pour supprimer du contenu par identifiant, par type, etc.

import
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
SDK
.
type DELETE: {
page: (id: string) => Promise<DeletionResponse>;
pageContent: (id: string) => Promise<DeletionResponse>;
... 6 more ...;
user: (id: string) => Promise<DeletionResponse>;
}
DELETE
;

L’objet SDK.db fournit un ensemble de fonctions et d’utilitaires qui vous permettent d’interagir directement avec Astro DB. Vous pouvez utiliser ces fonctions pour interroger la base de données, exécuter des requêtes personnalisées, etc.

import
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
SDK
from 'studiocms:sdk';
const {
const db: Database
db
} =
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
SDK
;
Pour plus d’informations sur l’utilisation de db, consultez le guide Astro DB^

L’objet SDK.REST_API fournit un ensemble de fonctions et d’utilitaires que l’API REST utilise pour interagir avec StudioCMS et Astro DB.

import
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
SDK
from 'studiocms:sdk';
const {
tokens: {
get: (userId: string) => Promise<{
key: string;
description: string | null;
id: string;
userId: string;
creationDate: Date;
}[]>;
new: (userId: string, description: string) => Promise<{
key: string;
description: string | null;
id: string;
userId: 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<{
key: string;
description: string | null;
id: string;
userId: string;
creationDate: Date;
}[]>
get
:
const getToken: (userId: string) => Promise<{
key: string;
description: string | null;
id: string;
userId: string;
creationDate: Date;
}[]>
getToken
,
new: (userId: string, description: string) => Promise<{
key: string;
description: string | null;
id: string;
userId: string;
creationDate: Date;
}>
new
:
const newToken: (userId: string, description: string) => Promise<{
key: string;
description: string | null;
id: string;
userId: 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[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
SDK
.
type REST_API: {
tokens: {
get: (userId: string) => Promise<{
key: string;
description: string | null;
id: string;
userId: string;
creationDate: Date;
}[]>;
new: (userId: string, description: string) => Promise<{
key: string;
description: string | null;
id: string;
userId: string;
creationDate: Date;
}>;
delete: (userId: string, tokenId: string) => Promise<void>;
verify: (key: string) => Promise<false | {
userId: string;
key: string;
rank: string;
}>;
};
}
REST_API
;

L’objet SDK.diffTracking fournit un ensemble de fonctions et d’utilitaires qui vous permettent de suivre les modifications dans Astro DB. Vous pouvez utiliser ces fonctions pour suivre les modifications de contenu, les modifications d’utilisateurs, etc.

import
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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<diffReturn>
insert
,
const clear: (pageId: string) => Promise<void>
clear
,
const get: {
byPageId: {
all: (pageId: string) => Promise<diffReturn[]>;
latest: (pageId: string, count: number) => Promise<diffReturn[]>;
};
byUserId: {
all: (userId: string) => Promise<diffReturn[]>;
latest: (userId: string, count: number) => Promise<diffReturn[]>;
};
single: (id: string) => Promise<diffReturn | undefined>;
}
get
,
const revertToDiff: (id: string, type: "content" | "data" | "both") => Promise<diffReturn>
revertToDiff
} =
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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<diffReturn>;
clear: (pageId: string) => Promise<void>;
get: {
byPageId: {
all: (pageId: string) => Promise<diffReturn[]>;
latest: (pageId: string, count: number) => Promise<diffReturn[]>;
};
byUserId: {
all: (userId: string) => Promise<diffReturn[]>;
latest: (userId: string, count: number) => Promise<diffReturn[]>;
};
single: (id: string) => Promise<diffReturn | undefined>;
};
revertToDiff: (id: string, type: "content" | "data" | "both") => Promise<diffReturn>;
utils: {
getMetaDataDifferences<T extends Record<string, any>>(obj1: T, obj2: T): {
label: string;
previous: any;
current: any;
}[];
getDiffHTML(diff: string | null, options?: Diff2HtmlConfig): string;
};
}
diffTracking
;

Le SDK de StudioCMS propose également un ensemble de fonctions utilitaires permettant d’interagir avec le SDK. Ces fonctions comprennent :

import
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
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;
name: string;
url: string | null;
email: string | null;
avatar: string | null;
username: string;
password: string | null;
updatedAt: Date | null;
createdAt: Date | null;
emailVerified: boolean;
notifications: string | null;
}) => Promise<CombinedUserData>
collectUserData
,
const generateRandomPassword: (length: number) => string
generateRandomPassword
,
} =
const SDK: {
addPageToFolderTree: (tree: FolderNode[], folderId: string, newPage: FolderNode) => FolderNode[];
... 29 more ...;
notificationSettings: {
site: {
get: () => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
update: (settings: {
...;
}) => Promise<{
id: string;
emailVerification: boolean;
requireAdminVerification: boolean;
requireEditorVerification: boolean;
oAuthBypassVerification: boolean;
}>;
};
};
}
SDK
;

Le SDK de StudioCMS fournit également une version mise en cache du SDK avec un sous-ensemble limité de fonctionnalités du SDK qui comprend une couche de mise en cache par-dessus le SDK standard. Vous pouvez importer le SDK en cache avec la syntaxe suivante :

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>;
databaseTable: {
...;
};
};
... 5 more ...;
diffTracking: {
...;
};
}
SDKCached
from 'studiocms:sdk/cache';

L’objet SDKCached.GET fournit un ensemble de fonctions et d’utilitaires qui vous permettent de récupérer le contenu d’Astro DB avec une couche de mise en cache par-dessus. Vous pouvez utiliser ces fonctions pour obtenir du contenu par identifiant, par type, etc.

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>;
databaseTable: {
...;
};
};
... 5 more ...;
diffTracking: {
...;
};
}
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>;
databaseTable: {
...;
};
};
... 5 more ...;
diffTracking: {
...;
};
}
SDKCached
.
type GET: {
page: {
byId: (id: string) => Promise<PageDataCacheObject>;
bySlug: (slug: string) => Promise<PageDataCacheObject>;
};
... 7 more ...;
databaseTable: {
...;
};
}
GET
;

L’objet SDKCached.CLEAR fournit un ensemble de fonctions et d’utilitaires qui vous permettent de vider le cache du SDK mis en cache. Vous pouvez utiliser ces fonctions pour vider le cache d’un type de contenu spécifique, d’un identifiant de contenu spécifique, etc.

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>;
databaseTable: {
...;
};
};
... 5 more ...;
diffTracking: {
...;
};
}
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>;
databaseTable: {
...;
};
};
... 5 more ...;
diffTracking: {
...;
};
}
SDKCached
.
type CLEAR: {
page: {
byId: (id: string) => void;
bySlug: (slug: string) => void;
};
pages: () => void;
latestVersion: () => void;
folderTree: () => void;
folderList: () => void;
}
CLEAR
;

L’objet SDKCached.UPDATE fournit un ensemble de fonctions et d’utilitaires qui vous permettent de mettre à jour le contenu dans Astro DB avec une couche de mise en cache par-dessus. Vous pouvez utiliser ces fonctions pour mettre à jour le contenu par ID, par type, etc.

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>;
databaseTable: {
...;
};
};
... 5 more ...;
diffTracking: {
...;
};
}
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>;
databaseTable: {
...;
};
};
... 5 more ...;
diffTracking: {
...;
};
}
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
;

Il s’agit d’un relais vers l’objet db du SDK standard.

Consultez SDK.db pour plus d’informations