import {z} from 'zod' export type DeleteApiApiPoolRulesPoolRuleIdArgs = {poolRuleId: number}; export type DeleteApiApiPoolRulesPoolRuleIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const restPoolRuleCondition = z.discriminatedUnion("type", [z.object({type: z.enum(["invocation_type", "project_name", "workflow_name", "workflow_type"]), values: z.array(z.enum(["on_demand", "scheduled"]))}), z.object({operator: z.literal("starts_with"), type: z.enum(["invocation_type", "project_name", "workflow_name", "workflow_type"]), values: z.array(z.string())}), z.object({operator: z.literal("starts_with"), type: z.enum(["invocation_type", "project_name", "workflow_name", "workflow_type"]), values: z.array(z.string())}), z.object({type: z.enum(["invocation_type", "project_name", "workflow_name", "workflow_type"]), values: z.array(z.enum(["ab_test", "audience", "customer_journey", "engage", "predictive_scoring", "realtime", "segment_insights", "syndication"]))})]); export const restPoolRule = z.object({conditions: z.array(restPoolRuleCondition), id: z.string(), poolId: z.string(), priority: z.number().int().gte(1).lte(10000)}); 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 }; /** * Delete a pool rule * * DELETE /api/pool_rules/{poolRuleId} */ export const deleteApiApiPoolRulesPoolRuleId = async (args: DeleteApiApiPoolRulesPoolRuleIdArgs, options?: DeleteApiApiPoolRulesPoolRuleIdOptions) => { const {baseUrl = "https://api-workflow.treasuredata.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set('authorization', `TD1 ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/pool_rules/${encodeURIComponent(String(args.poolRuleId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(restPoolRule, await res.json()) };