42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
import { config } from "../../config.js";
|
|
import { SquidexClient } from "@squidex/squidex";
|
|
import { InMemoryTokenStore } from "@squidex/squidex/dist/wrapper/SquidexClient.js";
|
|
import type { ContentsDto } from "../internals/ContentsDtoT.js";
|
|
import type { SupportedLocales } from "../internals/LocalizedT.js";
|
|
import type { SCHEMAS } from "../models/schemas.js";
|
|
|
|
export const client = new SquidexClient({
|
|
appName: config.squidexAppName!,
|
|
clientId: config.squidexClientId!,
|
|
clientSecret: config.squidexClientSecret!,
|
|
environment: config.squidexEnvironment!,
|
|
tokenStore: new InMemoryTokenStore(),
|
|
// tokenStore: new SquidexStorageTokenStore() // Keep the tokens in the local store.
|
|
// tokenStore: new SquidexStorageTokenStore(sessionStorage, "CustomKey")
|
|
});
|
|
|
|
export const TIMEOUT_IN_SECONDS = 10;
|
|
|
|
/** Asset Handling */
|
|
|
|
export const getAssetById = async (assetId: string) => (
|
|
await client.assets.getAsset(assetId)
|
|
);
|
|
|
|
/** Generic Content Handling */
|
|
|
|
export const getAllContents = async <T>(schema: SCHEMAS|string) => (
|
|
await client.contents.getContents(schema, { })
|
|
) as ContentsDto<T>;
|
|
|
|
export const getContentsByIds = async <T>(schema: SCHEMAS|string, ids: string) => (
|
|
await client.contents.getContents(schema, { ids })
|
|
) as ContentsDto<T>;
|
|
|
|
export const getContentsUsingJsonQuery = async <T>(schema: SCHEMAS|string, jsonQuery: string|undefined = undefined) => (
|
|
await client.contents.getContents(schema, { q: jsonQuery })
|
|
) as ContentsDto<T>;
|
|
|
|
export const getContentsByLangSlug = async <T>(schema: SCHEMAS|string, forLang: SupportedLocales|string, slug: string) => (
|
|
await getContentsUsingJsonQuery<T>(schema, JSON.stringify({ filter: { path: `data.slug.${forLang}`, op: 'eq', value: slug }}))
|
|
); |