Created getAll endpoint

This commit is contained in:
DrMint 2024-07-26 07:40:33 +02:00
parent 3582a48bd1
commit caa79dee9e
3 changed files with 89 additions and 87 deletions

View File

@ -542,19 +542,3 @@ export type PayloadImage = PayloadMedia & {
width: number; width: number;
height: 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[] };
};

View File

@ -17,36 +17,56 @@ import type {
EndpointVideo, EndpointVideo,
EndpointFile, EndpointFile,
EndpointRecorder, EndpointRecorder,
EndpointAllSDKUrls,
EndpointAllIds,
} from "./endpoint-types"; } 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 = { export const getSDKEndpoint = {
getConfigEndpoint: () => `/globals/${Collections.WebsiteConfig}/config`, getWebsiteConfig: () => `/globals/${Collections.WebsiteConfig}/config`,
getFolderEndpoint: (slug: string) => `/${Collections.Folders}/slug/${slug}`, getFolder: (slug: string) => `/${Collections.Folders}/slug/${slug}`,
getLanguagesEndpoint: () => `/${Collections.Languages}/all`, getLanguages: () => `/${Collections.Languages}/all`,
getCurrenciesEndpoint: () => `/${Collections.Currencies}/all`, getCurrencies: () => `/${Collections.Currencies}/all`,
getWordingsEndpoint: () => `/${Collections.Wordings}/all`, getWordings: () => `/${Collections.Wordings}/all`,
getPageEndpoint: (slug: string) => `/${Collections.Pages}/slug/${slug}`, getPage: (slug: string) => `/${Collections.Pages}/slug/${slug}`,
getCollectibleEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}`, getCollectible: (slug: string) => `/${Collections.Collectibles}/slug/${slug}`,
getCollectibleScansEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/scans`, getCollectibleScans: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/scans`,
getCollectibleScanPageEndpoint: (slug: string, index: string) => getCollectibleScanPage: (slug: string, index: string) =>
`/${Collections.Collectibles}/slug/${slug}/scans/${index}`, `/${Collections.Collectibles}/slug/${slug}/scans/${index}`,
getCollectibleGalleryEndpoint: (slug: string) => getCollectibleGallery: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/gallery`,
`/${Collections.Collectibles}/slug/${slug}/gallery`, getCollectibleGalleryImage: (slug: string, index: string) =>
getCollectibleGalleryImageEndpoint: (slug: string, index: string) =>
`/${Collections.Collectibles}/slug/${slug}/gallery/${index}`, `/${Collections.Collectibles}/slug/${slug}/gallery/${index}`,
getChronologyEventsEndpoint: () => `/${Collections.ChronologyEvents}/all`, getChronologyEvents: () => `/${Collections.ChronologyEvents}/all`,
getChronologyEventByIDEndpoint: (id: string) => `/${Collections.ChronologyEvents}/id/${id}`, getChronologyEventByID: (id: string) => `/${Collections.ChronologyEvents}/id/${id}`,
getImageByIDEndpoint: (id: string) => `/${Collections.Images}/id/${id}`, getImageByID: (id: string) => `/${Collections.Images}/id/${id}`,
getAudioByIDEndpoint: (id: string) => `/${Collections.Audios}/id/${id}`, getAudioByID: (id: string) => `/${Collections.Audios}/id/${id}`,
getVideoByIDEndpoint: (id: string) => `/${Collections.Videos}/id/${id}`, getVideoByID: (id: string) => `/${Collections.Videos}/id/${id}`,
getFileByIDEndpoint: (id: string) => `/${Collections.Files}/id/${id}`, getFileByID: (id: string) => `/${Collections.Files}/id/${id}`,
getRecorderByIDEndpoint: (id: string) => `/${Collections.Recorders}/id/${id}`, getRecorderByID: (id: string) => `/${Collections.Recorders}/id/${id}`,
getAllSDKUrlsEndpoint: () => `/all-sdk-urls`, getLogin: () => `/${Collections.Recorders}/login`,
getAllIds: () => `/all-ids`, getAll: () => `/all`,
getLoginEndpoint: () => `/${Collections.Recorders}/login`, } satisfies Record<SDKEndpointNames, (...params: string[]) => string>;
};
export type PayloadSDKResponse<T> = { export type PayloadSDKResponse<T> = {
data: T; data: T;
@ -86,7 +106,7 @@ export class PayloadSDK {
} }
private async refreshToken() { private async refreshToken() {
const loginUrl = `${this.apiURL}${getSDKEndpoint.getLoginEndpoint()}`; const loginUrl = `${this.apiURL}${getSDKEndpoint.getLogin()}`;
const loginResult = await fetch(loginUrl, { const loginResult = await fetch(loginUrl, {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
@ -128,72 +148,69 @@ export class PayloadSDK {
return response; return response;
} }
async getConfig(): Promise<PayloadSDKResponse<EndpointWebsiteConfig>> { async getWebsiteConfig(): Promise<PayloadSDKResponse<EndpointWebsiteConfig>> {
return await this.request(getSDKEndpoint.getConfigEndpoint()); return await this.request(getSDKEndpoint.getWebsiteConfig());
} }
async getFolder(slug: string): Promise<PayloadSDKResponse<EndpointFolder>> { async getFolder(slug: string): Promise<PayloadSDKResponse<EndpointFolder>> {
return await this.request(getSDKEndpoint.getFolderEndpoint(slug)); return await this.request(getSDKEndpoint.getFolder(slug));
} }
async getLanguages(): Promise<PayloadSDKResponse<EndpointLanguage[]>> { async getLanguages(): Promise<PayloadSDKResponse<EndpointLanguage[]>> {
return await this.request(getSDKEndpoint.getLanguagesEndpoint()); return await this.request(getSDKEndpoint.getLanguages());
} }
async getCurrencies(): Promise<PayloadSDKResponse<EndpointCurrency[]>> { async getCurrencies(): Promise<PayloadSDKResponse<EndpointCurrency[]>> {
return await this.request(getSDKEndpoint.getCurrenciesEndpoint()); return await this.request(getSDKEndpoint.getCurrencies());
} }
async getWordings(): Promise<PayloadSDKResponse<EndpointWording[]>> { async getWordings(): Promise<PayloadSDKResponse<EndpointWording[]>> {
return await this.request(getSDKEndpoint.getWordingsEndpoint()); return await this.request(getSDKEndpoint.getWordings());
} }
async getPage(slug: string): Promise<PayloadSDKResponse<EndpointPage>> { async getPage(slug: string): Promise<PayloadSDKResponse<EndpointPage>> {
return await this.request(getSDKEndpoint.getPageEndpoint(slug)); return await this.request(getSDKEndpoint.getPage(slug));
} }
async getCollectible(slug: string): Promise<PayloadSDKResponse<EndpointCollectible>> { async getCollectible(slug: string): Promise<PayloadSDKResponse<EndpointCollectible>> {
return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug)); return await this.request(getSDKEndpoint.getCollectible(slug));
} }
async getCollectibleScans(slug: string): Promise<PayloadSDKResponse<EndpointCollectibleScans>> { async getCollectibleScans(slug: string): Promise<PayloadSDKResponse<EndpointCollectibleScans>> {
return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug)); return await this.request(getSDKEndpoint.getCollectibleScans(slug));
} }
async getCollectibleScanPage( async getCollectibleScanPage(
slug: string, slug: string,
index: string index: string
): Promise<PayloadSDKResponse<EndpointCollectibleScanPage>> { ): Promise<PayloadSDKResponse<EndpointCollectibleScanPage>> {
return await this.request(getSDKEndpoint.getCollectibleScanPageEndpoint(slug, index)); return await this.request(getSDKEndpoint.getCollectibleScanPage(slug, index));
} }
async getCollectibleGallery( async getCollectibleGallery(
slug: string slug: string
): Promise<PayloadSDKResponse<EndpointCollectibleGallery>> { ): Promise<PayloadSDKResponse<EndpointCollectibleGallery>> {
return await this.request(getSDKEndpoint.getCollectibleGalleryEndpoint(slug)); return await this.request(getSDKEndpoint.getCollectibleGallery(slug));
} }
async getCollectibleGalleryImage( async getCollectibleGalleryImage(
slug: string, slug: string,
index: string index: string
): Promise<PayloadSDKResponse<EndpointCollectibleGalleryImage>> { ): Promise<PayloadSDKResponse<EndpointCollectibleGalleryImage>> {
return await this.request(getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index)); return await this.request(getSDKEndpoint.getCollectibleGalleryImage(slug, index));
} }
async getChronologyEvents(): Promise<PayloadSDKResponse<EndpointChronologyEvent[]>> { async getChronologyEvents(): Promise<PayloadSDKResponse<EndpointChronologyEvent[]>> {
return await this.request(getSDKEndpoint.getChronologyEventsEndpoint()); return await this.request(getSDKEndpoint.getChronologyEvents());
} }
async getChronologyEventByID(id: string): Promise<PayloadSDKResponse<EndpointChronologyEvent>> { async getChronologyEventByID(id: string): Promise<PayloadSDKResponse<EndpointChronologyEvent>> {
return await this.request(getSDKEndpoint.getChronologyEventByIDEndpoint(id)); return await this.request(getSDKEndpoint.getChronologyEventByID(id));
} }
async getImageByID(id: string): Promise<PayloadSDKResponse<EndpointImage>> { async getImageByID(id: string): Promise<PayloadSDKResponse<EndpointImage>> {
return await this.request(getSDKEndpoint.getImageByIDEndpoint(id)); return await this.request(getSDKEndpoint.getImageByID(id));
} }
async getAudioByID(id: string): Promise<PayloadSDKResponse<EndpointAudio>> { async getAudioByID(id: string): Promise<PayloadSDKResponse<EndpointAudio>> {
return await this.request(getSDKEndpoint.getAudioByIDEndpoint(id)); return await this.request(getSDKEndpoint.getAudioByID(id));
} }
async getVideoByID(id: string): Promise<PayloadSDKResponse<EndpointVideo>> { async getVideoByID(id: string): Promise<PayloadSDKResponse<EndpointVideo>> {
return await this.request(getSDKEndpoint.getVideoByIDEndpoint(id)); return await this.request(getSDKEndpoint.getVideoByID(id));
} }
async getFileByID(id: string): Promise<PayloadSDKResponse<EndpointFile>> { async getFileByID(id: string): Promise<PayloadSDKResponse<EndpointFile>> {
return await this.request(getSDKEndpoint.getFileByIDEndpoint(id)); return await this.request(getSDKEndpoint.getFileByID(id));
} }
async getRecorderByID(id: string): Promise<PayloadSDKResponse<EndpointRecorder>> { async getRecorderByID(id: string): Promise<PayloadSDKResponse<EndpointRecorder>> {
return await this.request(getSDKEndpoint.getRecorderByIDEndpoint(id)); return await this.request(getSDKEndpoint.getRecorderByID(id));
} }
async getAllSdkUrls(): Promise<PayloadSDKResponse<EndpointAllSDKUrls>> { async getAll(): Promise<PayloadSDKResponse<EndpointChange[]>> {
return await this.request(getSDKEndpoint.getAllSDKUrlsEndpoint()); return await this.request(getSDKEndpoint.getAll());
}
async getAllIds(): Promise<PayloadSDKResponse<EndpointAllIds>> {
return await this.request(getSDKEndpoint.getAllIds());
} }
} }

View File

@ -1,24 +1,25 @@
import type { SDKEndpointNames } from "./sdk";
export type EndpointChange = { export type EndpointChange = {
url: string; url: string;
} & ( } & (
| { type: "getConfig" } | { type: SDKEndpointNames.getWebsiteConfig }
| { type: "getFolder"; slug: string } | { type: SDKEndpointNames.getFolder; slug: string }
| { type: "getLanguages" } | { type: SDKEndpointNames.getLanguages }
| { type: "getCurrencies" } | { type: SDKEndpointNames.getCurrencies }
| { type: "getWordings" } | { type: SDKEndpointNames.getWordings }
| { type: "getPage"; slug: string } | { type: SDKEndpointNames.getPage; slug: string }
| { type: "getCollectible"; slug: string } | { type: SDKEndpointNames.getCollectible; slug: string }
| { type: "getCollectibleScans"; slug: string } | { type: SDKEndpointNames.getCollectibleScans; slug: string }
| { type: "getCollectibleScanPage"; slug: string; index: string } | { type: SDKEndpointNames.getCollectibleScanPage; slug: string; index: string }
| { type: "getCollectibleGallery"; slug: string } | { type: SDKEndpointNames.getCollectibleGallery; slug: string }
| { type: "getCollectibleGalleryImage"; slug: string; index: string } | { type: SDKEndpointNames.getCollectibleGalleryImage; slug: string; index: string }
| { type: "getChronologyEvents" } | { type: SDKEndpointNames.getChronologyEvents }
| { type: "getChronologyEventByID"; id: string } | { type: SDKEndpointNames.getChronologyEventByID; id: string }
| { type: "getImageByID"; id: string } | { type: SDKEndpointNames.getImageByID; id: string }
| { type: "getAudioByID"; id: string } | { type: SDKEndpointNames.getAudioByID; id: string }
| { type: "getVideoByID"; id: string } | { type: SDKEndpointNames.getVideoByID; id: string }
| { type: "getFileByID"; id: string } | { type: SDKEndpointNames.getFileByID; id: string }
| { type: "getRecorderByID"; id: string } | { type: SDKEndpointNames.getRecorderByID; id: string }
| { type: "getAllSdkUrls" } );
| { type: "getAllIds" }
);