import {z} from 'zod' export type RobloxAdConfigurationApiModelsGetEligibleCampaignTargetsRequest = {campaignTargetTypes?: (Array<0 | 1 | 2 | 3>) | undefined, groupId?: number | undefined}; export type CreateApiV2SponsoredCampaignsEligibleCampaignTargetsArgs = {body: RobloxAdConfigurationApiModelsGetEligibleCampaignTargetsRequest}; export type CreateApiV2SponsoredCampaignsEligibleCampaignTargetsOptions = {baseUrl?: string | undefined, robloxLegacyCookie?: string | undefined, fetch?: typeof fetch | undefined}; export const robloxAdConfigurationApiModelsCampaignTargetModel = z.object({campaignTargetType: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]).optional(), campaignTargetId: z.number().int().optional(), name: z.string().optional()}); export const robloxAdConfigurationApiModelsGetCampaignTargetsResponse = z.object({campaignTargetModels: z.array(robloxAdConfigurationApiModelsCampaignTargetModel).optional()}); 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 }; /** * Returns a collection of Roblox.AdConfiguration.Api.Models.CampaignTargetModel that the user is authorized to sponsor, ordered by most recently advertised * * POST /v2/sponsored-campaigns/eligible-campaign-targets */ export const createApiV2SponsoredCampaignsEligibleCampaignTargets = async (args: CreateApiV2SponsoredCampaignsEligibleCampaignTargetsArgs, options?: CreateApiV2SponsoredCampaignsEligibleCampaignTargetsOptions) => { const {baseUrl = "https://adconfiguration.roblox.com", fetch: fetchFn = fetch, robloxLegacyCookie} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (robloxLegacyCookie !== undefined) cookies.push(".ROBLOSECURITY=" + encodeURIComponent(robloxLegacyCookie)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/sponsored-campaigns/eligible-campaign-targets${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(robloxAdConfigurationApiModelsGetCampaignTargetsResponse, await res.json()) };