import {z} from 'zod' export type Region = 'JP' | 'NA' | 'CN' | 'KR' | 'TW'; export type Language = 'jp' | 'en'; export type NiceSvtType = 'normal' | 'heroine' | 'combineMaterial' | 'enemy' | 'enemyCollection' | 'servantEquip' | 'statusUp' | 'svtEquipMaterial' | 'enemyCollectionDetail' | 'all' | 'commandCode' | 'svtMaterialTd'; export type NiceSvtFlag = 'onlyUseForNpc' | 'svtEquipFriendShip' | 'ignoreCombineLimitSpecial' | 'svtEquipExp' | 'svtEquipChocolate' | 'svtEquipManaExchange' | 'svtEquipCampaign' | 'svtEquipEvent' | 'svtEquipEventReward' | 'svtEquipRarityLevelNumMission' | 'normal' | 'goetia' | 'matDropRateUpCe' | 'unknown'; export type GetApiBasicRegionEquipSearchArgs = {region: Region, lang?: (Language | null) | undefined, name?: (string | null) | undefined, illustrator?: (string | null) | undefined, excludeCollectionNo?: Array | undefined, type?: Array | undefined, flag?: Array | undefined, rarity?: Array | undefined}; export type GetApiBasicRegionEquipSearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const niceSvtType = z.enum(["normal", "heroine", "combineMaterial", "enemy", "enemyCollection", "servantEquip", "statusUp", "svtEquipMaterial", "enemyCollectionDetail", "all", "commandCode", "svtMaterialTd"]); export const niceSvtFlag = z.enum(["onlyUseForNpc", "svtEquipFriendShip", "ignoreCombineLimitSpecial", "svtEquipExp", "svtEquipChocolate", "svtEquipManaExchange", "svtEquipCampaign", "svtEquipEvent", "svtEquipEventReward", "svtEquipRarityLevelNumMission", "normal", "goetia", "matDropRateUpCe", "unknown"]); export const niceSvtFlagOriginal = z.enum(["onlyUseForNpc", "svtEquipFriendShip", "ignoreCombineLimitSpecial", "svtEquipExp", "svtEquipChocolate", "svtEquipManaExchange", "svtEquipCampaign", "svtEquipEvent", "svtEquipEventReward", "svtEquipRarityLevelNumMission"]); export const basicEquip = z.object({id: z.number().int(), collectionNo: z.number().int(), name: z.string(), originalName: z.string(), type: niceSvtType, flag: niceSvtFlag, flags: z.array(niceSvtFlagOriginal), rarity: z.number().int(), atkMax: z.number().int(), hpMax: z.number().int(), face: z.string().min(1).max(2083), bondEquipOwner: z.number().int().nullable().optional(), valentineEquipOwner: z.number().int().nullable().optional()}); export const getApiBasicRegionEquipSearchResponse = z.array(basicEquip); 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 CE data * * GET /basic/{region}/equip/search */ export const getApiBasicRegionEquipSearch = async (args: GetApiBasicRegionEquipSearchArgs, options?: GetApiBasicRegionEquipSearchOptions) => { 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)) if (args.name != null) query.append("name", String(args.name)) if (args.illustrator != null) query.append("illustrator", String(args.illustrator)) for (const item of args.excludeCollectionNo ?? []) query.append("excludeCollectionNo", String(item)) for (const item of args.type ?? []) query.append("type", String(item)) for (const item of args.flag ?? []) query.append("flag", String(item)) for (const item of args.rarity ?? []) query.append("rarity", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/basic/${encodeURIComponent(String(args.region))}/equip/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(getApiBasicRegionEquipSearchResponse, await res.json()) };