import {z} from 'zod' export type Region = 'JP' | 'NA' | 'CN' | 'KR' | 'TW'; export type NiceEventType = '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 type NiceCombineAdjustTarget = 'combineQp' | 'combineExp' | 'activeSkill' | 'largeSuccess' | 'superSuccess' | 'limitQp' | 'limitItem' | 'skillQp' | 'skillItem' | 'treasureDeviceQp' | 'treasureDeviceItem' | 'questAp' | 'questExp' | 'questQp' | 'questDrop' | 'svtequipCombineQp' | 'svtequipCombineExp' | 'svtequipLargeSuccess' | 'svtequipSuperSuccess' | 'questEventPoint' | 'enemySvtClassPickUp' | 'eventEachDropNum' | 'eventEachDropRate' | 'questFp' | 'questApFirstTime' | 'dailyDropUp' | 'exchangeSvtCombineExp' | 'questUseContinueItem' | 'friendPointGachaFreeDrawNum' | 'questUseFriendshipUpItem' | 'questFriendship' | 'largeSuccessByClass' | 'superSuccessByClass' | 'exchangeSvt' | 'questItemFirstTime' | 'questUseRewardAddItem' | 'questEquipExp' | 'questPassiveSkill'; export type Language = 'jp' | 'en'; export type GetApiBasicRegionEventSearchArgs = {region: Region, name?: (string | null) | undefined, ongoing?: (boolean | null) | undefined, eventType?: (NiceEventType | null) | undefined, campaignTarget?: (NiceCombineAdjustTarget | null) | undefined, lang?: (Language | null) | undefined}; export type GetApiBasicRegionEventSearchOptions = {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 getApiBasicRegionEventSearchResponse = z.array(basicEvent); 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 }; /** * Find and get event data * * GET /basic/{region}/event/search */ export const getApiBasicRegionEventSearch = async (args: GetApiBasicRegionEventSearchArgs, options?: GetApiBasicRegionEventSearchOptions) => { 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.name != null) query.append("name", String(args.name)) if (args.ongoing != null) query.append("ongoing", String(args.ongoing)) if (args.eventType != null) query.append("eventType", String(args.eventType)) if (args.campaignTarget != null) query.append("campaignTarget", String(args.campaignTarget)) if (args.lang != null) query.append("lang", String(args.lang)) const url = `${baseUrl.replace(/\/+$/, '')}/basic/${encodeURIComponent(String(args.region))}/event/search${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(getApiBasicRegionEventSearchResponse, await res.json()) };