import {z} from 'zod' export type GetApiV1CookieConsentRulesArgs = {configId?: string | undefined, rule?: string | undefined, type?: ('cookie' | 'script' | 'iframe' | 'localStorage') | undefined, ruleType?: ('FILENAME' | 'DOMAIN' | 'PATH' | 'REGEXP' | 'STARTS_WITH' | 'ENDS_WITH' | 'CONTAINS' | 'EXACT_MATCH') | undefined, classification?: ('ESSENTIAL' | 'ANALYTICS' | 'MARKETING' | 'PERSONALIZATION' | 'HIDDEN' | 'BLACKLISTED') | undefined, limit?: number | undefined, next?: string | undefined}; export type GetApiV1CookieConsentRulesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const cmpCustomerRule = z.object({ruleId: z.number().int().optional(), configId: z.string().optional(), type: z.enum(["cookie", "script", "iframe", "localStorage"]).optional(), classification: z.enum(["ANALYTICS", "BLACKLISTED", "ESSENTIAL", "HIDDEN", "MARKETING", "PERSONALIZATION"]).optional(), rule: z.string().optional(), ruleType: z.enum(["FILENAME", "DOMAIN", "PATH", "REGEXP", "STARTS_WITH", "ENDS_WITH", "CONTAINS", "EXACT_MATCH"]).nullable().optional(), title: z.string().nullable().optional(), vendorId: z.string().nullable().optional(), vendorName: z.string().nullable().optional(), disclosure: z.boolean().optional(), expiry: z.string().nullable().optional(), description: z.string().nullable().optional(), created: z.string().optional(), updated: z.string().optional()}); export const cmpCustomerRulesResponseList = z.object({items: z.array(cmpCustomerRule), next: z.string().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 }; /** * List Rules Across All Configurations * * GET /v1/cookie-consent/rules */ export const getApiV1CookieConsentRules = async (args: GetApiV1CookieConsentRulesArgs, options?: GetApiV1CookieConsentRulesOptions) => { const {baseUrl = "https://api.osano.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.configId != null) query.append("configId", String(args.configId)) if (args.rule != null) query.append("rule", String(args.rule)) if (args.type != null) query.append("type", String(args.type)) if (args.ruleType != null) query.append("ruleType", String(args.ruleType)) if (args.classification != null) query.append("classification", String(args.classification)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.next != null) query.append("next", String(args.next)) if (ApiKeyAuth !== undefined) headers.set("x-osano-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/cookie-consent/rules${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(cmpCustomerRulesResponseList, await res.json()) };