import {z} from 'zod' export type GetApiV1SubjectRightsRequestTypesArgs = {country?: string | undefined, privacyLawName?: string | undefined, requestType?: string | undefined, category?: string | undefined}; export type GetApiV1SubjectRightsRequestTypesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const jurisdiction = z.object({country: z.string(), territory: z.string().optional()}); export const applicableLaw = z.object({name: z.string(), abbreviation: z.string().nullable(), effectiveDate: z.string(), jurisdictions: z.array(jurisdiction)}); export const requestType = z.object({requestType: z.string(), requestTypeCategory: z.string(), applicableLaws: z.array(applicableLaw)}); export const requestTypeList = z.object({items: z.array(requestType)}); 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 Subject Rights Request Types * * GET /v1/subject-rights/request-types */ export const getApiV1SubjectRightsRequestTypes = async (args: GetApiV1SubjectRightsRequestTypesArgs, options?: GetApiV1SubjectRightsRequestTypesOptions) => { 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.country != null) query.append("country", String(args.country)) if (args.privacyLawName != null) query.append("privacyLawName", String(args.privacyLawName)) if (args.requestType != null) query.append("requestType", String(args.requestType)) if (args.category != null) query.append("category", String(args.category)) if (ApiKeyAuth !== undefined) headers.set("x-osano-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/subject-rights/request-types${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(requestTypeList, await res.json()) };