diff --git a/payload/endpoint-types.ts b/payload/endpoint-types.ts index ac53643..db90f7e 100644 --- a/payload/endpoint-types.ts +++ b/payload/endpoint-types.ts @@ -542,19 +542,3 @@ 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[] }; -}; diff --git a/payload/sdk.ts b/payload/sdk.ts index b154366..609da02 100644 --- a/payload/sdk.ts +++ b/payload/sdk.ts @@ -17,36 +17,56 @@ import type { EndpointVideo, EndpointFile, EndpointRecorder, - EndpointAllSDKUrls, - EndpointAllIds, } from "./endpoint-types"; +import type { EndpointChange } from "./webhooks"; + +export enum SDKEndpointNames { + getWebsiteConfig = "getWebsiteConfig", + getFolder = "getFolder", + getLanguages = "getLanguages", + getCurrencies = "getCurrencies", + getWordings = "getWordings", + getPage = "getPage", + getCollectible = "getCollectible", + getCollectibleScans = "getCollectibleScans", + getCollectibleScanPage = "getCollectibleScanPage", + getCollectibleGallery = "getCollectibleGallery", + getCollectibleGalleryImage = "getCollectibleGalleryImage", + getChronologyEvents = "getChronologyEvents", + getChronologyEventByID = "getChronologyEventByID", + getImageByID = "getImageByID", + getAudioByID = "getAudioByID", + getVideoByID = "getVideoByID", + getFileByID = "getFileByID", + getRecorderByID = "getRecorderByID", + getLogin = "getLogin", + getAll = "getAll", +} 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) => + getWebsiteConfig: () => `/globals/${Collections.WebsiteConfig}/config`, + getFolder: (slug: string) => `/${Collections.Folders}/slug/${slug}`, + getLanguages: () => `/${Collections.Languages}/all`, + getCurrencies: () => `/${Collections.Currencies}/all`, + getWordings: () => `/${Collections.Wordings}/all`, + getPage: (slug: string) => `/${Collections.Pages}/slug/${slug}`, + getCollectible: (slug: string) => `/${Collections.Collectibles}/slug/${slug}`, + getCollectibleScans: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/scans`, + getCollectibleScanPage: (slug: string, index: string) => `/${Collections.Collectibles}/slug/${slug}/scans/${index}`, - getCollectibleGalleryEndpoint: (slug: string) => - `/${Collections.Collectibles}/slug/${slug}/gallery`, - getCollectibleGalleryImageEndpoint: (slug: string, index: string) => + getCollectibleGallery: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/gallery`, + getCollectibleGalleryImage: (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`, -}; + getChronologyEvents: () => `/${Collections.ChronologyEvents}/all`, + getChronologyEventByID: (id: string) => `/${Collections.ChronologyEvents}/id/${id}`, + getImageByID: (id: string) => `/${Collections.Images}/id/${id}`, + getAudioByID: (id: string) => `/${Collections.Audios}/id/${id}`, + getVideoByID: (id: string) => `/${Collections.Videos}/id/${id}`, + getFileByID: (id: string) => `/${Collections.Files}/id/${id}`, + getRecorderByID: (id: string) => `/${Collections.Recorders}/id/${id}`, + getLogin: () => `/${Collections.Recorders}/login`, + getAll: () => `/all`, +} satisfies Record string>; export type PayloadSDKResponse = { data: T; @@ -86,7 +106,7 @@ export class PayloadSDK { } private async refreshToken() { - const loginUrl = `${this.apiURL}${getSDKEndpoint.getLoginEndpoint()}`; + const loginUrl = `${this.apiURL}${getSDKEndpoint.getLogin()}`; const loginResult = await fetch(loginUrl, { method: "POST", headers: { "Content-Type": "application/json" }, @@ -128,72 +148,69 @@ export class PayloadSDK { return response; } - async getConfig(): Promise> { - return await this.request(getSDKEndpoint.getConfigEndpoint()); + async getWebsiteConfig(): Promise> { + return await this.request(getSDKEndpoint.getWebsiteConfig()); } async getFolder(slug: string): Promise> { - return await this.request(getSDKEndpoint.getFolderEndpoint(slug)); + return await this.request(getSDKEndpoint.getFolder(slug)); } async getLanguages(): Promise> { - return await this.request(getSDKEndpoint.getLanguagesEndpoint()); + return await this.request(getSDKEndpoint.getLanguages()); } async getCurrencies(): Promise> { - return await this.request(getSDKEndpoint.getCurrenciesEndpoint()); + return await this.request(getSDKEndpoint.getCurrencies()); } async getWordings(): Promise> { - return await this.request(getSDKEndpoint.getWordingsEndpoint()); + return await this.request(getSDKEndpoint.getWordings()); } async getPage(slug: string): Promise> { - return await this.request(getSDKEndpoint.getPageEndpoint(slug)); + return await this.request(getSDKEndpoint.getPage(slug)); } async getCollectible(slug: string): Promise> { - return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug)); + return await this.request(getSDKEndpoint.getCollectible(slug)); } async getCollectibleScans(slug: string): Promise> { - return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug)); + return await this.request(getSDKEndpoint.getCollectibleScans(slug)); } async getCollectibleScanPage( slug: string, index: string ): Promise> { - return await this.request(getSDKEndpoint.getCollectibleScanPageEndpoint(slug, index)); + return await this.request(getSDKEndpoint.getCollectibleScanPage(slug, index)); } async getCollectibleGallery( slug: string ): Promise> { - return await this.request(getSDKEndpoint.getCollectibleGalleryEndpoint(slug)); + return await this.request(getSDKEndpoint.getCollectibleGallery(slug)); } async getCollectibleGalleryImage( slug: string, index: string ): Promise> { - return await this.request(getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index)); + return await this.request(getSDKEndpoint.getCollectibleGalleryImage(slug, index)); } async getChronologyEvents(): Promise> { - return await this.request(getSDKEndpoint.getChronologyEventsEndpoint()); + return await this.request(getSDKEndpoint.getChronologyEvents()); } async getChronologyEventByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getChronologyEventByIDEndpoint(id)); + return await this.request(getSDKEndpoint.getChronologyEventByID(id)); } async getImageByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getImageByIDEndpoint(id)); + return await this.request(getSDKEndpoint.getImageByID(id)); } async getAudioByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getAudioByIDEndpoint(id)); + return await this.request(getSDKEndpoint.getAudioByID(id)); } async getVideoByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getVideoByIDEndpoint(id)); + return await this.request(getSDKEndpoint.getVideoByID(id)); } async getFileByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getFileByIDEndpoint(id)); + return await this.request(getSDKEndpoint.getFileByID(id)); } async getRecorderByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getRecorderByIDEndpoint(id)); + return await this.request(getSDKEndpoint.getRecorderByID(id)); } - async getAllSdkUrls(): Promise> { - return await this.request(getSDKEndpoint.getAllSDKUrlsEndpoint()); - } - async getAllIds(): Promise> { - return await this.request(getSDKEndpoint.getAllIds()); + async getAll(): Promise> { + return await this.request(getSDKEndpoint.getAll()); } } diff --git a/payload/webhooks.ts b/payload/webhooks.ts index a4779a8..5117d7d 100644 --- a/payload/webhooks.ts +++ b/payload/webhooks.ts @@ -1,24 +1,25 @@ +import type { SDKEndpointNames } from "./sdk"; + export type EndpointChange = { url: string; } & ( - | { type: "getConfig" } - | { type: "getFolder"; slug: string } - | { type: "getLanguages" } - | { type: "getCurrencies" } - | { type: "getWordings" } - | { type: "getPage"; slug: string } - | { type: "getCollectible"; slug: string } - | { type: "getCollectibleScans"; slug: string } - | { type: "getCollectibleScanPage"; slug: string; index: string } - | { type: "getCollectibleGallery"; slug: string } - | { type: "getCollectibleGalleryImage"; slug: string; index: string } - | { type: "getChronologyEvents" } - | { type: "getChronologyEventByID"; id: string } - | { type: "getImageByID"; id: string } - | { type: "getAudioByID"; id: string } - | { type: "getVideoByID"; id: string } - | { type: "getFileByID"; id: string } - | { type: "getRecorderByID"; id: string } - | { type: "getAllSdkUrls" } - | { type: "getAllIds" } -); \ No newline at end of file + | { type: SDKEndpointNames.getWebsiteConfig } + | { type: SDKEndpointNames.getFolder; slug: string } + | { type: SDKEndpointNames.getLanguages } + | { type: SDKEndpointNames.getCurrencies } + | { type: SDKEndpointNames.getWordings } + | { type: SDKEndpointNames.getPage; slug: string } + | { type: SDKEndpointNames.getCollectible; slug: string } + | { type: SDKEndpointNames.getCollectibleScans; slug: string } + | { type: SDKEndpointNames.getCollectibleScanPage; slug: string; index: string } + | { type: SDKEndpointNames.getCollectibleGallery; slug: string } + | { type: SDKEndpointNames.getCollectibleGalleryImage; slug: string; index: string } + | { type: SDKEndpointNames.getChronologyEvents } + | { type: SDKEndpointNames.getChronologyEventByID; id: string } + | { type: SDKEndpointNames.getImageByID; id: string } + | { type: SDKEndpointNames.getAudioByID; id: string } + | { type: SDKEndpointNames.getVideoByID; id: string } + | { type: SDKEndpointNames.getFileByID; id: string } + | { type: SDKEndpointNames.getRecorderByID; id: string } +); +