import {z} from 'zod' export type GetApiApiCdpSettingsV1AppAppIdActivationArgs = {audience_id?: string | undefined}; export type GetApiApiCdpSettingsV1AppAppIdActivationOptions = {baseUrl?: string | undefined, JWTAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiCdpSettingsV1AppAppIdActivationResponse = z.array(z.object({id: z.string(), name: z.string(), status: z.enum(["active", "inactive"]), required_consents: z.array(z.enum(["analytics", "ab_testing_and_personalization", "conversion_tracking", "marketing_automation", "remarketing", "user_feedback", "custom_consent"])), created_at: z.string(), updated_at: z.string(), author: z.object({email: z.string()}), is_author: z.boolean(), type: z.enum(["webhook", "gads_customer_match"])})); 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 activations * * GET /api/cdp/settings/v1/app/{app_id}/activation */ export const getApiApiCdpSettingsV1AppAppIdActivation = async (args: GetApiApiCdpSettingsV1AppAppIdActivationArgs, options?: GetApiApiCdpSettingsV1AppAppIdActivationOptions) => { const {baseUrl = "https://example.piwik.pro", fetch: fetchFn = fetch, JWTAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.audience_id != null) query.append("audience_id", String(args.audience_id)) if (JWTAuth !== undefined) headers.set('authorization', `Bearer ${JWTAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/cdp/settings/v1/app/${encodeURIComponent(String(args.app_id))}/activation${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(getApiApiCdpSettingsV1AppAppIdActivationResponse, await res.json()) };