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 (schema: SCHEMAS|string) => ( await client.contents.getContents(schema, { }) ) as ContentsDto; export const getContentsByIds = async (schema: SCHEMAS|string, ids: string) => ( await client.contents.getContents(schema, { ids }) ) as ContentsDto; export const getContentsUsingJsonQuery = async (schema: SCHEMAS|string, jsonQuery: string|undefined = undefined) => ( await client.contents.getContents(schema, { q: jsonQuery }) ) as ContentsDto; export const getContentsByLangSlug = async (schema: SCHEMAS|string, forLang: SupportedLocales|string, slug: string) => ( await getContentsUsingJsonQuery(schema, JSON.stringify({ filter: { path: `data.slug.${forLang}`, op: 'eq', value: slug }})) );