import {z} from 'zod' export type Region = 'JP' | 'NA' | 'CN' | 'KR' | 'TW'; export type Language = 'jp' | 'en'; export type GetApiBasicRegionEventEventIdArgs = {region: Region, event_id: number, lang?: (Language | null) | undefined}; export type GetApiBasicRegionEventEventIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const niceEventType = z.enum(["none", "raidBoss", "pvp", "point", "loginBonus", "combineCampaign", "shop", "questCampaign", "bank", "serialCampaign", "loginCampaign", "loginCampaignRepeat", "eventQuest", "svtequipCombineCampaign", "terminalBanner", "boxGacha", "boxGachaPoint", "loginCampaignStrict", "totalLogin", "comebackCampaign", "locationCampaign", "warBoard", "combineCosutumeItem", "myroomMultipleViewCampaign", "interludeCampaign", "myroomPhotoCampaign", "fortuneCampaign", "genderSelection"]); export const basicEvent = z.object({id: z.number().int(), type: niceEventType, name: z.string(), noticeAt: z.number().int(), startedAt: z.number().int(), endedAt: z.number().int(), finishedAt: z.number().int(), materialOpenedAt: z.number().int(), warIds: z.array(z.number().int())}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Event data * * GET /basic/{region}/event/{event_id} */ export const getApiBasicRegionEventEventId = async (args: GetApiBasicRegionEventEventIdArgs, options?: GetApiBasicRegionEventEventIdOptions) => { const {baseUrl = "https://api.atlasacademy.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.lang != null) query.append("lang", String(args.lang)) const url = `${baseUrl.replace(/\/+$/, '')}/basic/${encodeURIComponent(String(args.region))}/event/${encodeURIComponent(String(args.event_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(basicEvent, await res.json()) };