diff --git a/src/shared/analytics/analytics.ts b/src/shared/analytics/analytics.ts deleted file mode 100644 index c0d216d..0000000 --- a/src/shared/analytics/analytics.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { contextCache } from "src/utils/payload"; - -const getUnlocalizedPathname = (pathname: string): string => { - for (const locale of contextCache.locales) { - if (pathname.startsWith(`/${locale}`)) { - return pathname.substring(`/${locale}`.length) || "/"; - } - } - return pathname; -}; - -type TrackRequestParams = { - params: Record; - locals: App.Locals; - clientAddress: string; -}; - -export const trackRequest = (request: Request, { clientAddress, locals }: TrackRequestParams) => { - const userAgent = request.headers.get("User-Agent"); - const acceptLanguage = request.headers.get("Accept-Language"); - const { method, url: stringUrl, referrer } = request; - const url = new URL(stringUrl); - - const body: AnalyticsBody = { - type: "request", - timestamp: Date.now(), - payload: { - user: { - address: clientAddress, - attributes: { - locale: locals.currentLocale, - }, - }, - request: { - method, - pathname: getUnlocalizedPathname(url.pathname), - referrer, - ...(acceptLanguage ? { acceptLanguage } : {}), - ...(userAgent ? { userAgent } : {}), - }, - response: { - status: locals.notFound ? 404 : 200, - }, - }, - }; - track(body); -}; - -export const trackEvent = (eventName: string) => { - const body: AnalyticsBody = { type: "event", timestamp: Date.now(), eventName }; - track(body); -}; - -type AnalyticsBody = Record & { - type: "event" | "request"; - timestamp: number; -}; - -const track = async (body: AnalyticsBody) => { - if (!import.meta.env.ANALYTICS_URL) return; - try { - await fetch(import.meta.env.ANALYTICS_URL, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(body), - }); - } catch (e) { - console.warn("Couldn't send analytics", e); - } -}; diff --git a/src/shared/meilisearch/meilisearch-sdk.ts b/src/shared/meilisearch/meilisearch-sdk.ts deleted file mode 100644 index 336ef7a..0000000 --- a/src/shared/meilisearch/meilisearch-sdk.ts +++ /dev/null @@ -1,118 +0,0 @@ -import { - Collections, - type EndpointAudio, - type EndpointChronologyEvent, - type EndpointCollectible, - type EndpointFile, - type EndpointFolder, - type EndpointImage, - type EndpointPage, - type EndpointRecorder, - type EndpointVideo, -} from "src/shared/payload/payload-sdk"; - -export enum Indexes { - DOCUMENT = "DOCUMENT", -} - -export type MeiliDocument = { - meilid: string; - id: string; - languages: string[]; - title?: string; - content?: string; -} & ( - | { - type: Collections.Collectibles; - data: EndpointCollectible; - } - | { - type: Collections.Pages; - data: EndpointPage; - } - | { - type: Collections.Folders; - data: EndpointFolder; - } - | { - type: Collections.Videos; - data: EndpointVideo; - } - | { - type: Collections.Audios; - data: EndpointAudio; - } - | { - type: Collections.Images; - data: EndpointImage; - } - | { - type: Collections.Files; - data: EndpointFile; - } - | { - type: Collections.Recorders; - data: EndpointRecorder; - } - | { - type: Collections.ChronologyEvents; - data: { - date: EndpointChronologyEvent["date"]; - event: EndpointChronologyEvent["events"][number]; - }; - } -); - -export type SearchResponse = { - hits: T[]; - query: string; - processingTimeMs: number; - hitsPerPage: number; - page: number; - totalPages: number; - totalHits: number; - facetDistribution: Record<"type" | "languages", Record>; -}; - -export type SearchRequest = { - q: string; - page: number; - types?: string[] | string | undefined; -}; - -export class Meilisearch { - constructor( - private readonly apiURL: string, - private readonly bearer: string - ) {} - - async search({ q, page, types }: SearchRequest): Promise> { - const filter: string[] = []; - - if (types) { - if (typeof types === "string") { - filter.push(`type = ${types}`); - } else { - filter.push(`type IN [${types.join(", ")}]`); - } - } - - const body = { - q, - page, - hitsPerPage: 25, - filter, - sort: ["updatedAt:desc"] - }; - - const result = await fetch(`${this.apiURL}/indexes/DOCUMENT/search`, { - method: "POST", - body: JSON.stringify(body), - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${this.bearer}`, - }, - }); - return await result.json(); - } -} diff --git a/src/shared/payload/payload-sdk.ts b/src/shared/payload/payload-sdk.ts deleted file mode 100644 index 7b99365..0000000 --- a/src/shared/payload/payload-sdk.ts +++ /dev/null @@ -1,2273 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * This file was automatically generated by Payload. - * DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config, - * and re-run `payload generate:types` to regenerate this file. - */ - -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "Credits". - */ -export type Credits = - | { - role: string | CreditsRole; - recorders: (string | Recorder)[]; - id?: string | null; - }[] - | null; - -export interface Config { - collections: { - pages: Page; - collectibles: Collectible; - folders: Folder; - "chronology-events": ChronologyEvent; - images: Image; - audios: Audio; - "media-thumbnails": MediaThumbnail; - videos: Video; - "videos-subtitles": VideoSubtitle; - "videos-channels": VideosChannel; - files: File; - scans: Scan; - tags: Tag; - attributes: Attribute; - "credits-roles": CreditsRole; - recorders: Recorder; - languages: Language; - currencies: Currency; - wordings: Wording; - "generic-contents": GenericContent; - "payload-preferences": PayloadPreference; - "payload-migrations": PayloadMigration; - }; - globals: { - "website-config": WebsiteConfig; - }; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "pages". - */ -export interface Page { - id: string; - slug: string; - thumbnail?: string | Image | null; - backgroundImage?: string | Image | null; - attributes?: (TagsBlock | NumberBlock | TextBlock)[] | null; - translations: { - language: string | Language; - sourceLanguage: string | Language; - pretitle?: string | null; - title: string; - subtitle?: string | null; - summary?: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - } | null; - content: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - }; - credits?: Credits; - id?: string | null; - }[]; - folders?: (string | Folder)[] | null; - collectibles?: (string | Collectible)[] | null; - updatedBy: string | Recorder; - updatedAt: string; - createdAt: string; - _status?: ("draft" | "published") | null; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "images". - */ -export interface Image { - id: string; - translations?: - | { - language: string | Language; - pretitle?: string | null; - title: string; - subtitle?: string | null; - description?: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - } | null; - id?: string | null; - }[] - | null; - attributes?: (TagsBlock | NumberBlock | TextBlock)[] | null; - credits?: Credits; - updatedAt: string; - createdAt: string; - url?: string | null; - filename?: string | null; - mimeType?: string | null; - filesize?: number | null; - width?: number | null; - height?: number | null; - focalX?: number | null; - focalY?: number | null; - sizes?: { - thumb?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - og?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "200w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "320w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "480w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "800w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "1280w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "1920w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "2560w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - }; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "languages". - */ -export interface Language { - id: string; - name: string; - selectable: boolean; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "TagsBlock". - */ -export interface TagsBlock { - name: string | Attribute; - tags: (string | Tag)[]; - id?: string | null; - blockName?: string | null; - blockType: "tagsBlock"; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "attributes". - */ -export interface Attribute { - id: string; - slug: string; - icon?: string | null; - type: "Number" | "Text" | "Tags"; - translations: { - language: string | Language; - name: string; - id?: string | null; - }[]; - updatedAt: string; - createdAt: string; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "tags". - */ -export interface Tag { - id: string; - slug: string; - page?: (string | null) | Page; - translations: { - language: string | Language; - name: string; - id?: string | null; - }[]; - updatedAt: string; - createdAt: string; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "NumberBlock". - */ -export interface NumberBlock { - name: string | Attribute; - number: number; - id?: string | null; - blockName?: string | null; - blockType: "numberBlock"; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "TextBlock". - */ -export interface TextBlock { - name: string | Attribute; - text: string; - id?: string | null; - blockName?: string | null; - blockType: "textBlock"; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "credits-roles". - */ -export interface CreditsRole { - id: string; - slug: string; - icon?: string | null; - translations: { - language: string | Language; - name: string; - id?: string | null; - }[]; - updatedAt: string; - createdAt: string; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "recorders". - */ -export interface Recorder { - id: string; - username: string; - avatar?: string | Image | null; - languages?: (string | Language)[] | null; - translations?: - | { - language: string | Language; - biography: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - }; - id?: string | null; - }[] - | null; - role?: ("Admin" | "Recorder" | "Api")[] | null; - anonymize: boolean; - email: string; - resetPasswordToken?: string | null; - resetPasswordExpiration?: string | null; - salt?: string | null; - hash?: string | null; - loginAttempts?: number | null; - lockUntil?: string | null; - password?: string | null; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "folders". - */ -export interface Folder { - id: string; - slug: string; - icon?: string | null; - parentFolders?: (string | Folder)[] | null; - translations: { - language: string | Language; - name: string; - description?: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - } | null; - id?: string | null; - }[]; - sections?: - | { - translations?: - | { - language: string | Language; - name: string; - id?: string | null; - }[] - | null; - subfolders?: (string | Folder)[] | null; - id?: string | null; - }[] - | null; - files?: - | ( - | { - relationTo: "collectibles"; - value: string | Collectible; - } - | { - relationTo: "pages"; - value: string | Page; - } - | { - relationTo: "videos"; - value: string | Video; - } - | { - relationTo: "images"; - value: string | Image; - } - | { - relationTo: "audios"; - value: string | Audio; - } - | { - relationTo: "files"; - value: string | File; - } - )[] - | null; - updatedAt: string; - createdAt: string; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "collectibles". - */ -export interface Collectible { - id: string; - slug: string; - thumbnail?: string | Image | null; - nature: "Physical" | "Digital"; - languages?: (string | Language)[] | null; - attributes?: (TagsBlock | NumberBlock | TextBlock)[] | null; - translations: { - language: string | Language; - pretitle?: string | null; - title: string; - subtitle?: string | null; - description?: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - } | null; - id?: string | null; - }[]; - backgroundImage?: string | Image | null; - gallery?: - | { - image: string | Image; - id?: string | null; - }[] - | null; - scansEnabled?: boolean | null; - scans?: { - credits?: Credits; - coverEnabled?: boolean | null; - cover?: { - front?: string | Scan | null; - spine?: string | Scan | null; - back?: string | Scan | null; - insideFront?: string | Scan | null; - insideBack?: string | Scan | null; - flapFront?: string | Scan | null; - flapBack?: string | Scan | null; - insideFlapFront?: string | Scan | null; - insideFlapBack?: string | Scan | null; - }; - dustjacketEnabled?: boolean | null; - dustjacket?: { - front?: string | Scan | null; - spine?: string | Scan | null; - back?: string | Scan | null; - insideFront?: string | Scan | null; - insideSpine?: string | Scan | null; - insideBack?: string | Scan | null; - flapFront?: string | Scan | null; - flapBack?: string | Scan | null; - insideFlapFront?: string | Scan | null; - insideFlapBack?: string | Scan | null; - }; - obiEnabled?: boolean | null; - obi?: { - front?: string | Scan | null; - spine?: string | Scan | null; - back?: string | Scan | null; - insideFront?: string | Scan | null; - insideSpine?: string | Scan | null; - insideBack?: string | Scan | null; - flapFront?: string | Scan | null; - flapBack?: string | Scan | null; - insideFlapFront?: string | Scan | null; - insideFlapBack?: string | Scan | null; - }; - pages?: - | { - page: number; - image: string | Scan; - id?: string | null; - }[] - | null; - }; - urls?: - | { - url: string; - id?: string | null; - }[] - | null; - releaseDate?: string | null; - priceEnabled?: boolean | null; - price?: { - amount: number; - currency: string | Currency; - }; - sizeEnabled?: boolean | null; - size?: { - width: number; - height: number; - thickness?: number | null; - }; - weightEnabled?: boolean | null; - weight?: { - amount: number; - }; - pageInfoEnabled?: boolean | null; - pageInfo?: { - pageCount: number; - bindingType?: ("Paperback" | "Hardcover") | null; - pageOrder?: ("Left to right" | "Right to left") | null; - }; - subitems?: (string | Collectible)[] | null; - files?: (string | File)[] | null; - contents?: - | { - content: - | { - relationTo: "pages"; - value: string | Page; - } - | { - relationTo: "generic-contents"; - value: string | GenericContent; - } - | { - relationTo: "audios"; - value: string | Audio; - } - | { - relationTo: "videos"; - value: string | Video; - }; - range?: - | ( - | { - start: number; - end: number; - id?: string | null; - blockName?: string | null; - blockType: "pageRange"; - } - | { - start: string; - end: string; - id?: string | null; - blockName?: string | null; - blockType: "timeRange"; - } - | { - translations: { - language: string | Language; - note: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - }; - id?: string | null; - }[]; - id?: string | null; - blockName?: string | null; - blockType: "other"; - } - )[] - | null; - id?: string | null; - }[] - | null; - folders?: (string | Folder)[] | null; - parentItems?: (string | Collectible)[] | null; - updatedBy: string | Recorder; - updatedAt: string; - createdAt: string; - _status?: ("draft" | "published") | null; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "scans". - */ -export interface Scan { - id: string; - updatedAt: string; - createdAt: string; - url?: string | null; - filename?: string | null; - mimeType?: string | null; - filesize?: number | null; - width?: number | null; - height?: number | null; - focalX?: number | null; - focalY?: number | null; - sizes?: { - thumb?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "200w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "320w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "480w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "800w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - }; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "currencies". - */ -export interface Currency { - id: string; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "files". - */ -export interface File { - id: string; - thumbnail?: string | MediaThumbnail | null; - translations?: - | { - language: string | Language; - pretitle?: string | null; - title: string; - subtitle?: string | null; - description?: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - } | null; - id?: string | null; - }[] - | null; - attributes?: (TagsBlock | NumberBlock | TextBlock)[] | null; - credits?: Credits; - updatedAt: string; - createdAt: string; - url?: string | null; - filename?: string | null; - mimeType?: string | null; - filesize?: number | null; - width?: number | null; - height?: number | null; - focalX?: number | null; - focalY?: number | null; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "media-thumbnails". - */ -export interface MediaThumbnail { - id: string; - updatedAt: string; - createdAt: string; - url?: string | null; - filename?: string | null; - mimeType?: string | null; - filesize?: number | null; - width?: number | null; - height?: number | null; - focalX?: number | null; - focalY?: number | null; - sizes?: { - thumb?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - og?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "200w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "320w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "480w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "800w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "1280w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "1920w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - "2560w"?: { - url?: string | null; - width?: number | null; - height?: number | null; - mimeType?: string | null; - filesize?: number | null; - filename?: string | null; - }; - }; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "generic-contents". - */ -export interface GenericContent { - id: string; - name: string; - translations: { - language: string | Language; - name: string; - id?: string | null; - }[]; - updatedAt: string; - createdAt: string; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "audios". - */ -export interface Audio { - id: string; - duration: number; - thumbnail?: string | MediaThumbnail | null; - translations: { - language: string | Language; - pretitle?: string | null; - title: string; - subtitle?: string | null; - description?: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - } | null; - id?: string | null; - }[]; - attributes?: (TagsBlock | NumberBlock | TextBlock)[] | null; - credits?: Credits; - updatedAt: string; - createdAt: string; - url?: string | null; - filename?: string | null; - mimeType?: string | null; - filesize?: number | null; - width?: number | null; - height?: number | null; - focalX?: number | null; - focalY?: number | null; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "videos". - */ -export interface Video { - id: string; - duration: number; - thumbnail?: string | MediaThumbnail | null; - translations: { - language: string | Language; - pretitle?: string | null; - title: string; - subtitle?: string | null; - description?: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - } | null; - subfile?: string | VideoSubtitle | null; - id?: string | null; - }[]; - attributes?: (TagsBlock | NumberBlock | TextBlock)[] | null; - credits?: Credits; - platformEnabled?: boolean | null; - platform?: { - channel: string | VideosChannel; - views?: number | null; - likes?: number | null; - dislikes?: number | null; - url: string; - publishedDate: string; - }; - updatedAt: string; - createdAt: string; - url?: string | null; - filename?: string | null; - mimeType?: string | null; - filesize?: number | null; - width?: number | null; - height?: number | null; - focalX?: number | null; - focalY?: number | null; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "videos-subtitles". - */ -export interface VideoSubtitle { - id: string; - url?: string | null; - filename?: string | null; - mimeType?: string | null; - filesize?: number | null; - width?: number | null; - height?: number | null; - focalX?: number | null; - focalY?: number | null; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "videos-channels". - */ -export interface VideosChannel { - id: string; - url: string; - title: string; - subscribers: number; - videos?: (string | Video)[] | null; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "chronology-events". - */ -export interface ChronologyEvent { - id: string; - name?: string | null; - date: { - year: number; - month?: number | null; - day?: number | null; - }; - events: { - sources?: (UrlBlock | CollectibleBlock | PageBlock)[] | null; - translations: { - language: string | Language; - sourceLanguage: string | Language; - title?: string | null; - description?: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - } | null; - notes?: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - } | null; - credits?: Credits; - id?: string | null; - }[]; - id?: string | null; - }[]; - updatedBy: string | Recorder; - updatedAt: string; - createdAt: string; - _status?: ("draft" | "published") | null; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "UrlBlock". - */ -export interface UrlBlock { - url: string; - id?: string | null; - blockName?: string | null; - blockType: "urlBlock"; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "CollectibleBlock". - */ -export interface CollectibleBlock { - collectible: string | Collectible; - range?: - | ( - | { - page: number; - id?: string | null; - blockName?: string | null; - blockType: "page"; - } - | { - timestamp: string; - id?: string | null; - blockName?: string | null; - blockType: "timestamp"; - } - | { - translations: { - language: string | Language; - note: string; - id?: string | null; - }[]; - id?: string | null; - blockName?: string | null; - blockType: "other"; - } - )[] - | null; - id?: string | null; - blockName?: string | null; - blockType: "collectibleBlock"; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "PageBlock". - */ -export interface PageBlock { - page: string | Page; - id?: string | null; - blockName?: string | null; - blockType: "pageBlock"; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "wordings". - */ -export interface Wording { - id: string; - name: string; - translations: { - language: string | Language; - name: string; - id?: string | null; - }[]; - updatedAt: string; - createdAt: string; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "payload-preferences". - */ -export interface PayloadPreference { - id: string; - user: { - relationTo: "recorders"; - value: string | Recorder; - }; - key?: string | null; - value?: - | { - [k: string]: unknown; - } - | unknown[] - | string - | number - | boolean - | null; - updatedAt: string; - createdAt: string; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "payload-migrations". - */ -export interface PayloadMigration { - id: string; - name?: string | null; - batch?: number | null; - updatedAt: string; - createdAt: string; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "website-config". - */ -export interface WebsiteConfig { - id: string; - homeBackgroundImage: string | Image; - timelineBackgroundImage: string | Image; - defaultOpenGraphImage: string | Image; - homeFolders?: - | { - lightThumbnail?: string | Image | null; - darkThumbnail?: string | Image | null; - folder: string | Folder; - id?: string | null; - }[] - | null; - timeline?: { - breaks?: number[] | null; - eras?: - | { - name: string | Wording; - startingYear: number; - endingYear: number; - id?: string | null; - }[] - | null; - }; - updatedAt?: string | null; - createdAt?: string | null; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "LineBlock". - */ -export interface LineBlock { - content: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - }; - id?: string | null; - blockName?: string | null; - blockType: "lineBlock"; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "CueBlock". - */ -export interface CueBlock { - content: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - }; - id?: string | null; - blockName?: string | null; - blockType: "cueBlock"; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "TranscriptBlock". - */ -export interface TranscriptBlock { - lines: (LineBlock | CueBlock)[]; - id?: string | null; - blockName?: string | null; - blockType: "transcriptBlock"; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "BreakBlock". - */ -export interface BreakBlock { - type: "Scene break" | "Empty space" | "Solid line" | "Dotted line"; - id?: string | null; - blockName?: string | null; - blockType: "breakBlock"; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "SectionBlock". - */ -export interface SectionBlock { - content: { - root: { - type: string; - children: { - type: string; - version: number; - [k: string]: unknown; - }[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - version: number; - }; - [k: string]: unknown; - }; - id?: string | null; - blockName?: string | null; - blockType: "sectionBlock"; -} - - -/////////////// CONSTANTS /////////////// - - -export enum Collections { - Attributes = "attributes", - Audios = "audios", - ChronologyEvents = "chronology-events", - Collectibles = "collectibles", - CreditsRole = "credits-roles", - Currencies = "currencies", - Files = "files", - Folders = "folders", - GenericContents = "generic-contents", - Images = "images", - Languages = "languages", - MediaThumbnails = "media-thumbnails", - Pages = "pages", - Recorders = "recorders", - Scans = "scans", - Tags = "tags", - Videos = "videos", - VideosChannels = "videos-channels", - VideosSubtitles = "videos-subtitles", - Wordings = "wordings", - WebsiteConfig = "website-config", -} - -export enum CollectionGroups { - Collections = "Collections", - Media = "Media", - Meta = "Meta", -} - -export enum LanguageCodes { - en = "English", - fr = "French", - ja = "Japan", - es = "Spanish", - "pt-br" = "Portuguese", - "zh" = "Chinese", -} - -export enum BreakBlockType { - sceneBreak = "Scene break", - space = "Empty space", - solidLine = "Solid line", - dottedLine = "Dotted line", -} - -export enum CollectibleBindingTypes { - Paperback = "Paperback", - Hardcover = "Hardcover", -} - -export enum CollectiblePageOrders { - LeftToRight = "Left to right", - RightToLeft = "Right to left", -} - -export enum CollectibleNature { - Physical = "Physical", - Digital = "Digital", -} - -export enum CollectibleContentType { - None = "None", - Indexes = "Index-based", - Pages = "Page-based", -} - -export enum RecordersRoles { - Admin = "Admin", - Recorder = "Recorder", - Api = "Api", -} - -export enum CollectionStatus { - Draft = "draft", - Published = "published", -} - -export enum AttributeTypes { - Number = "Number", - Text = "Text", - Tags = "Tags", -} - -/* WEB HOOKS */ - -export type AfterOperationWebHookMessage = { - collection: Collections; - id?: string; - addedDependantIds: string[]; - urls: string[]; -}; -/* RICH TEXT */ - -export type RichTextContent = { - root: { - children: RichTextNode[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - type: string; - version: number; - }; - [k: string]: unknown; -}; - -export type RichTextNode = { - type: string; - version: number; - [k: string]: unknown; -}; - -export interface RichTextNodeWithChildren extends RichTextNode { - children: RichTextNode[]; -} - -export interface RichTextParagraphNode extends RichTextNodeWithChildren { - type: "paragraph"; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; -} - -export interface RichTextListNode extends RichTextNode { - type: "list"; - children: RichTextNodeWithChildren[]; - listType: string; -} - -export interface RichTextListNumberNode extends RichTextListNode { - listType: "number"; -} - -export interface RichTextListBulletNode extends RichTextListNode { - listType: "bullet"; -} - -export interface RichTextListCheckNode extends RichTextListNode { - listType: "check"; -} - -export interface RichTextLinebreakNode extends RichTextNode { - type: "linebreak"; -} - -export interface RichTextUploadNode extends RichTextNode { - type: "upload"; - relationTo: string; -} - -export interface RichTextUploadImageNode extends RichTextUploadNode { - relationTo: Collections.Images; - value: EndpointImagePreview; -} - -export interface RichTextUploadVideoNode extends RichTextUploadNode { - relationTo: Collections.Videos; - value: EndpointVideoPreview; -} - -export interface RichTextUploadAudioNode extends RichTextUploadNode { - relationTo: Collections.Audios; - value: EndpointAudioPreview; -} - -export interface RichTextTextNode extends RichTextNode { - type: "text"; - format: number; - text: string; -} - -export interface RichTextTabNode extends RichTextNode { - type: "tab"; - format: number; -} - -export interface RichTextLinkNode extends RichTextNodeWithChildren { - type: "link"; - fields: { - linkType: "internal" | "custom"; - }; -} - -export interface RichTextLinkInternalNode extends RichTextLinkNode { - fields: { - linkType: "internal"; - newTab: boolean; - doc: { - relationTo: string; - value: any; - }; - }; -} - -export interface RichTextLinkCustomNode extends RichTextLinkNode { - fields: { - linkType: "custom"; - newTab: boolean; - url: string; - }; -} - -export interface RichTextBlockNode extends RichTextNode { - type: "block"; - fields: { - blockType: string; - }; -} - -export interface RichTextSectionBlock extends RichTextBlockNode { - fields: SectionBlock; - anchorHash: string; -} - -export interface RichTextTranscriptBlock extends RichTextBlockNode { - fields: TranscriptBlock; -} - -export interface RichTextBreakBlock extends RichTextBlockNode { - fields: BreakBlock; - anchorHash: string; -} - -export const isNodeParagraphNode = (node: RichTextNode): node is RichTextParagraphNode => - node.type === "paragraph"; - -export const isNodeUploadNode = (node: RichTextNode): node is RichTextUploadNode => - node.type === "upload"; - -export const isUploadNodeImageNode = (node: RichTextUploadNode): node is RichTextUploadImageNode => - node.relationTo === Collections.Images; - -export const isUploadNodeVideoNode = (node: RichTextUploadNode): node is RichTextUploadVideoNode => - node.relationTo === Collections.Videos; - -export const isUploadNodeAudioNode = (node: RichTextUploadNode): node is RichTextUploadAudioNode => - node.relationTo === Collections.Audios; - -export const isNodeListNode = (node: RichTextNode): node is RichTextListNode => - node.type === "list"; - -export const isListNodeNumberListNode = (node: RichTextListNode): node is RichTextListNumberNode => - node.listType === "number"; - -export const isListNodeBulletListNode = (node: RichTextListNode): node is RichTextListBulletNode => - node.listType === "bullet"; - -export const isListNodeCheckListNode = (node: RichTextListNode): node is RichTextListCheckNode => - node.listType === "check"; - -export const isNodeLinebreakNode = (node: RichTextNode): node is RichTextLinebreakNode => - node.type === "linebreak"; - -export const isNodeTextNode = (node: RichTextNode): node is RichTextTextNode => - node.type === "text"; - -export const isNodeTabNode = (node: RichTextNode): node is RichTextTabNode => node.type === "tab"; - -export const isNodeLinkNode = (node: RichTextNode): node is RichTextLinkNode => - node.type === "link"; - -export const isLinkNodeInternalLinkNode = ( - node: RichTextLinkNode -): node is RichTextLinkInternalNode => node.fields.linkType === "internal"; - -export const isLinkNodeCustomLinkNode = (node: RichTextLinkNode): node is RichTextLinkCustomNode => - node.fields.linkType === "custom"; - -export const isNodeBlockNode = (node: RichTextNode): node is RichTextBlockNode => - node.type === "block"; - -export const isBlockNodeSectionBlock = (node: RichTextBlockNode): node is RichTextSectionBlock => - node.fields.blockType === "sectionBlock"; - -export const isBlockNodeTranscriptBlock = ( - node: RichTextBlockNode -): node is RichTextTranscriptBlock => node.fields.blockType === "transcriptBlock"; - -export const isBlockNodeBreakBlock = (node: RichTextBlockNode): node is RichTextBreakBlock => - node.fields.blockType === "breakBlock"; - -/* BLOCKS */ - -/* TODO: TO BE REMOVED WHEN https://github.com/payloadcms/payload/issues/5216 is closed */ -export interface CueBlock { - content: RichTextContent; - blockType: "cueBlock"; - id?: string | null; - blockName?: string | null; -} - -export interface LineBlock { - content: RichTextContent; - blockType: "lineBlock"; - id?: string | null; - blockName?: string | null; -} - -export interface GenericBlock { - id?: string | null; - blockName?: string | null; - blockType: string; -} - -export const isBlockCueBlock = (block: GenericBlock): block is CueBlock => - block.blockType === "cueBlock"; - -export const isBlockLineBlock = (block: GenericBlock): block is LineBlock => - block.blockType === "lineBlock"; - - -////////////////// SDK ////////////////// - - -export type EndpointFolderPreview = { - id: string; - slug: string; - icon?: string; - translations: { - language: string; - title: string; - }[]; -}; - -export type EndpointFolder = Omit & { - translations: (EndpointFolderPreview["translations"][number] & { - description?: RichTextContent; - })[]; - sections: - | { type: "single"; subfolders: EndpointFolderPreview[] } - | { - type: "multiple"; - sections: { - translations: { language: string; name: string }[]; - subfolders: EndpointFolderPreview[]; - }[]; - }; - files: ( - | { - relationTo: Collections.Collectibles; - value: EndpointCollectiblePreview; - } - | { - relationTo: Collections.Pages; - value: EndpointPagePreview; - } - | { - relationTo: Collections.Images; - value: EndpointImagePreview; - } - | { - relationTo: Collections.Audios; - value: EndpointAudioPreview; - } - | { - relationTo: Collections.Videos; - value: EndpointVideoPreview; - } - | { - relationTo: Collections.Files; - value: EndpointFilePreview; - } - )[]; - parentPages: EndpointSource[]; -}; - -export type EndpointWebsiteConfig = { - home: { - backgroundImage?: EndpointPayloadImage; - folders: (EndpointFolderPreview & { - lightThumbnail?: EndpointPayloadImage; - darkThumbnail?: EndpointPayloadImage; - })[]; - }; - timeline: { - backgroundImage?: EndpointPayloadImage; - breaks: number[]; - eventCount: number; - eras: { - startingYear: number; - endingYear: number; - name: string; - }[]; - }; - defaultOpenGraphImage?: EndpointPayloadImage; -}; - -export type EndpointRecorderPreview = { - id: string; - username: string; -}; - -export type EndpointRecorder = EndpointRecorderPreview & { - avatar?: EndpointPayloadImage; - translations: { - language: string; - biography: RichTextContent; - }[]; - languages: string[]; -}; - -export type EndpointWording = { - name: string; - translations: { - language: string; - name: string; - }[]; -}; - -export type EndpointTag = { - id: string; - slug: string; - page?: { slug: string }; - translations: { - language: string; - name: string; - }[]; -}; - -export type EndpointGenericAttribute = { - id: string; - slug: string; - icon: string; - translations: { - language: string; - name: string; - }[]; -}; - -export type EndpointNumberAttribute = EndpointGenericAttribute & { - type: AttributeTypes.Number; - value: number; -}; - -export type EndpointTextAttribute = EndpointGenericAttribute & { - type: AttributeTypes.Text; - value: string; -}; - -export type EndpointTagsAttribute = EndpointGenericAttribute & { - type: AttributeTypes.Tags; - value: EndpointTag[]; -}; - -export type EndpointAttribute = - | EndpointNumberAttribute - | EndpointTextAttribute - | EndpointTagsAttribute; - -export type EndpointRole = { - id: string; - icon: string; - translations: { - language: string; - name: string; - }[]; -}; - -export type EndpointCredit = { - role: EndpointRole; - recorders: EndpointRecorderPreview[]; -}; - -export type EndpointPagePreview = { - id: string; - slug: string; - thumbnail?: EndpointPayloadImage; - attributes: EndpointAttribute[]; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - }[]; - updatedAt: string; -}; - -export type EndpointPage = Omit & { - backgroundImage?: EndpointPayloadImage; - translations: (EndpointPagePreview["translations"][number] & { - sourceLanguage: string; - summary?: RichTextContent; - content: RichTextContent; - credits: EndpointCredit[]; - toc: TableOfContentEntry[]; - })[]; - createdAt: string; - updatedBy?: EndpointRecorderPreview; - parentPages: EndpointSource[]; -}; - -export type EndpointCollectiblePreview = { - id: string; - slug: string; - thumbnail?: EndpointPayloadImage; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - }[]; - attributes: EndpointAttribute[]; - releaseDate?: string; - languages: string[]; - price?: { - amount: number; - currency: string; - }; -}; - -export type EndpointCollectible = Omit & { - translations: (EndpointCollectiblePreview["translations"][number] & { - description?: RichTextContent; - })[]; - backgroundImage?: EndpointPayloadImage; - nature: CollectibleNature; - gallery?: { count: number; thumbnail: EndpointPayloadImage }; - scans?: { count: number; thumbnail: EndpointPayloadImage }; - urls: { url: string; label: string }[]; - size?: { - width: number; - height: number; - thickness?: number; - }; - weight?: number; - pageInfo?: { - pageCount: number; - bindingType?: CollectibleBindingTypes; - pageOrder?: CollectiblePageOrders; - }; - subitems: EndpointCollectiblePreview[]; - files: EndpointFilePreview[]; - contents: { - content: - | { - relationTo: Collections.Pages; - value: EndpointPagePreview; - } - | { - relationTo: Collections.Audios; - value: EndpointAudioPreview; - } - | { - relationTo: Collections.Videos; - value: EndpointVideoPreview; - } - | { - relationTo: Collections.GenericContents; - value: { - translations: { - language: string; - name: string; - }[]; - }; - }; - - range?: - | { - type: "pageRange"; - start: number; - end: number; - } - | { - type: "timeRange"; - start: string; - end: string; - } - | { - type: "other"; - translations: { - language: string; - note: RichTextContent; - }[]; - }; - }[]; - createdAt: string; - updatedAt: string; - updatedBy?: EndpointRecorderPreview; - parentPages: EndpointSource[]; -}; - -export type EndpointCollectibleScans = { - slug: string; - thumbnail?: EndpointPayloadImage; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - description?: RichTextContent; - }[]; - credits: EndpointCredit[]; - cover?: { - front?: EndpointScanImage; - spine?: EndpointScanImage; - back?: EndpointScanImage; - insideFront?: EndpointScanImage; - insideBack?: EndpointScanImage; - flapFront?: EndpointScanImage; - flapBack?: EndpointScanImage; - insideFlapFront?: EndpointScanImage; - insideFlapBack?: EndpointScanImage; - }; - dustjacket?: { - front?: EndpointScanImage; - spine?: EndpointScanImage; - back?: EndpointScanImage; - insideFront?: EndpointScanImage; - insideSpine?: EndpointScanImage; - insideBack?: EndpointScanImage; - flapFront?: EndpointScanImage; - flapBack?: EndpointScanImage; - insideFlapFront?: EndpointScanImage; - insideFlapBack?: EndpointScanImage; - }; - obi?: { - front?: EndpointScanImage; - spine?: EndpointScanImage; - back?: EndpointScanImage; - insideFront?: EndpointScanImage; - insideSpine?: EndpointScanImage; - insideBack?: EndpointScanImage; - flapFront?: EndpointScanImage; - flapBack?: EndpointScanImage; - insideFlapFront?: EndpointScanImage; - insideFlapBack?: EndpointScanImage; - }; - pages: EndpointScanImage[]; - parentPages: EndpointSource[]; -}; - -export type EndpointCollectibleGallery = { - slug: string; - thumbnail?: EndpointPayloadImage; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - description?: RichTextContent; - }[]; - images: EndpointPayloadImage[]; - parentPages: EndpointSource[]; -}; - -export type EndpointCollectibleGalleryImage = { - slug: string; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - description?: RichTextContent; - }[]; - image: EndpointImage; - previousIndex?: string; - nextIndex?: string; - parentPages: EndpointSource[]; -}; - -export type EndpointCollectibleScanPage = { - slug: string; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - description?: RichTextContent; - }[]; - image: EndpointScanImage; - previousIndex?: string; - nextIndex?: string; - parentPages: EndpointSource[]; -}; - -export type EndpointScanImage = PayloadImage & { - index: string; - sizes: PayloadImage[]; -}; - -export type TableOfContentEntry = { - prefix: string; - title: string; - type: "sceneBreak" | "break" | "section"; - index: number; - children: TableOfContentEntry[]; -}; - -export type EndpointChronologyEvent = { - id: string; - date: { - year: number; - month?: number; - day?: number; - }; - events: { - sources: EndpointSource[]; - translations: { - language: string; - sourceLanguage: string; - title?: string; - description?: RichTextContent; - notes?: RichTextContent; - credits: EndpointCredit[]; - }[]; - }[]; -}; - -export type EndpointSourcePreview = { - id: string; - slug: string; - translations: { language: string; pretitle?: string; title: string; subtitle?: string }[]; -}; - -export type EndpointSource = - | { type: "url"; url: string; label: string } - | { - type: "collectible"; - collectible: EndpointSourcePreview; - range?: - | { type: "page"; page: number } - | { type: "timestamp"; timestamp: string } - | { type: "custom"; translations: { language: string; note: string }[] }; - } - | { type: "page"; page: EndpointSourcePreview } - | { type: "folder"; folder: EndpointSourcePreview } - | { type: "scans"; collectible: EndpointSourcePreview } - | { type: "gallery"; collectible: EndpointSourcePreview }; - -export type EndpointMediaPreview = { - id: string; - url: string; - filename: string; - mimeType: string; - attributes: EndpointAttribute[]; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - }[]; -}; - -export type EndpointMedia = Omit & { - filesize: number; - updatedAt: string; - createdAt: string; - translations: (EndpointMediaPreview["translations"][number] & { - description?: RichTextContent; - })[]; - credits: EndpointCredit[]; -}; - -export type EndpointImagePreview = EndpointMediaPreview & { - width: number; - height: number; - sizes: PayloadImage[]; - openGraph?: PayloadImage; -}; - -export type EndpointImage = EndpointMedia & { - width: number; - height: number; - sizes: PayloadImage[]; - openGraph?: PayloadImage; -}; - -export type EndpointAudioPreview = EndpointMediaPreview & { - thumbnail?: EndpointPayloadImage; - duration: number; -}; - -export type EndpointAudio = EndpointMedia & { - thumbnail?: EndpointPayloadImage; - duration: number; -}; - -export type EndpointVideoPreview = EndpointMediaPreview & { - thumbnail?: EndpointPayloadImage; - subtitles: { - language: string; - url: string; - }[]; - duration: number; -}; - -export type EndpointVideo = EndpointMedia & { - thumbnail?: EndpointPayloadImage; - subtitles: { - language: string; - url: string; - }[]; - platform?: { - channel: { - url: string; - title: string; - subscribers: number; - }; - views?: number; - likes?: number; - dislikes?: number; - url: string; - publishedDate: string; - }; - duration: number; -}; - -export type EndpointFilePreview = EndpointMediaPreview & { - filesize: number; - thumbnail?: EndpointPayloadImage; -}; - -export type EndpointFile = EndpointMedia & { - filesize: number; - thumbnail?: EndpointPayloadImage; -}; - -export type EndpointPayloadImage = PayloadImage & { - sizes: PayloadImage[]; - openGraph?: PayloadImage; -}; - -export type PayloadMedia = { - id: string; - url: string; - mimeType: string; - filename: string; - filesize: number; -}; - -export type PayloadImage = PayloadMedia & { - width: number; - height: number; -}; - -export type EndpointAllSDKUrls = { - urls: string[]; -}; - -export type EndpointAllIds = { - collectibles: { slugs: string[] }; - pages: { slugs: string[] }; - folders: { slugs: string[] }; - videos: { ids: string[] }; - audios: { ids: string[] }; - images: { ids: string[] }; - files: { ids: string[] }; - recorders: { ids: string[] }; - chronologyEvents: { ids: string[] }; -}; - -// SDK - -export const getSDKEndpoint = { - getConfigEndpoint: () => `/globals/${Collections.WebsiteConfig}/config`, - getFolderEndpoint: (slug: string) => `/${Collections.Folders}/slug/${slug}`, - getLanguagesEndpoint: () => `/${Collections.Languages}/all`, - getCurrenciesEndpoint: () => `/${Collections.Currencies}/all`, - getWordingsEndpoint: () => `/${Collections.Wordings}/all`, - getPageEndpoint: (slug: string) => `/${Collections.Pages}/slug/${slug}`, - getCollectibleEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}`, - getCollectibleScansEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/scans`, - getCollectibleScanPageEndpoint: (slug: string, index: string) => - `/${Collections.Collectibles}/slug/${slug}/scans/${index}`, - getCollectibleGalleryEndpoint: (slug: string) => - `/${Collections.Collectibles}/slug/${slug}/gallery`, - getCollectibleGalleryImageEndpoint: (slug: string, index: string) => - `/${Collections.Collectibles}/slug/${slug}/gallery/${index}`, - getChronologyEventsEndpoint: () => `/${Collections.ChronologyEvents}/all`, - getChronologyEventByIDEndpoint: (id: string) => `/${Collections.ChronologyEvents}/id/${id}`, - getImageByIDEndpoint: (id: string) => `/${Collections.Images}/id/${id}`, - getAudioByIDEndpoint: (id: string) => `/${Collections.Audios}/id/${id}`, - getVideoByIDEndpoint: (id: string) => `/${Collections.Videos}/id/${id}`, - getFileByIDEndpoint: (id: string) => `/${Collections.Files}/id/${id}`, - getRecorderByIDEndpoint: (id: string) => `/${Collections.Recorders}/id/${id}`, - getAllSDKUrlsEndpoint: () => `/all-sdk-urls`, - getAllIds: () => `/all-ids`, - getLoginEndpoint: () => `/${Collections.Recorders}/login`, -}; - -type PayloadSDKResponse = { - data: T; - endpointCalled: string; -}; - -type PayloadTokenCache = { - set: (token: string, expirationTimestamp: number) => void; - get: () => string | undefined; -}; - -type PayloadDataCache = { - set: (url: string, response: any) => void; - get: (url: string) => any | undefined; -}; - -export class PayloadSDK { - private tokenCache: PayloadTokenCache | undefined; - private dataCache: PayloadDataCache | undefined; - - constructor( - private readonly apiURL: string, - private readonly email: string, - private readonly password: string - ) {} - - addTokenCache(tokenCache: PayloadTokenCache) { - this.tokenCache = tokenCache; - } - - addDataCache(dataCache: PayloadDataCache) { - this.dataCache = dataCache; - } - - private logResponse(res: Response) { - console.log(res.status, res.statusText, res.url); - } - - private async refreshToken() { - const loginUrl = `${this.apiURL}${getSDKEndpoint.getLoginEndpoint()}`; - const loginResult = await fetch(loginUrl, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ email: this.email, password: this.password }), - }); - this.logResponse(loginResult); - - if (loginResult.status !== 200) { - throw new Error("Unable to login"); - } - - const { token, exp } = (await loginResult.json()) as { - token: string; - exp: number; - }; - this.tokenCache?.set(token, exp); - return token; - } - - async request(endpoint: string): Promise> { - const cachedResponse = this.dataCache?.get(endpoint); - if (cachedResponse) { - return cachedResponse; - } - - const result = await fetch(`${this.apiURL}${endpoint}`, { - headers: { - Authorization: `JWT ${this.tokenCache?.get() ?? (await this.refreshToken())}`, - }, - }); - this.logResponse(result); - - if (!result.ok) { - throw new Error("Unhandled fetch error"); - } - - const response = { data: await result.json(), endpointCalled: endpoint }; - this.dataCache?.set(endpoint, response); - return response; - } - - async getConfig(): Promise> { - return await this.request(getSDKEndpoint.getConfigEndpoint()); - } - async getFolder(slug: string): Promise> { - return await this.request(getSDKEndpoint.getFolderEndpoint(slug)); - } - async getLanguages(): Promise> { - return await this.request(getSDKEndpoint.getLanguagesEndpoint()); - } - async getCurrencies(): Promise> { - return await this.request(getSDKEndpoint.getCurrenciesEndpoint()); - } - async getWordings(): Promise> { - return await this.request(getSDKEndpoint.getWordingsEndpoint()); - } - async getPage(slug: string): Promise> { - return await this.request(getSDKEndpoint.getPageEndpoint(slug)); - } - async getCollectible(slug: string): Promise> { - return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug)); - } - async getCollectibleScans(slug: string): Promise> { - return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug)); - } - async getCollectibleScanPage( - slug: string, - index: string - ): Promise> { - return await this.request(getSDKEndpoint.getCollectibleScanPageEndpoint(slug, index)); - } - async getCollectibleGallery( - slug: string - ): Promise> { - return await this.request(getSDKEndpoint.getCollectibleGalleryEndpoint(slug)); - } - async getCollectibleGalleryImage( - slug: string, - index: string - ): Promise> { - return await this.request(getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index)); - } - async getChronologyEvents(): Promise> { - return await this.request(getSDKEndpoint.getChronologyEventsEndpoint()); - } - async getChronologyEventByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getChronologyEventByIDEndpoint(id)); - } - async getImageByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getImageByIDEndpoint(id)); - } - async getAudioByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getAudioByIDEndpoint(id)); - } - async getVideoByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getVideoByIDEndpoint(id)); - } - async getFileByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getFileByIDEndpoint(id)); - } - async getRecorderByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getRecorderByIDEndpoint(id)); - } - async getAllSdkUrls(): Promise> { - return await this.request(getSDKEndpoint.getAllSDKUrlsEndpoint()); - } - async getAllIds(): Promise> { - return await this.request(getSDKEndpoint.getAllIds()); - } -} diff --git a/src/utils/currencies.ts b/src/utils/currencies.ts index bccf589..da90bc2 100644 --- a/src/utils/currencies.ts +++ b/src/utils/currencies.ts @@ -1,5 +1,5 @@ -import currencies from "src/shared/openExchange/currencies.json"; -import { rates } from "src/shared/openExchange/rates.json"; +import currencies from "src/dist/openExchange/currencies.json"; +import { rates } from "src/dist/openExchange/rates.json"; type CurrencyCode = keyof typeof rates;