import {z} from 'zod' export type GetApiV1SubjectRightsRequestsArgs = {limit?: number | undefined, next?: string | undefined, after?: string | undefined, source?: ('ADMIN' | 'AGENT_WEB' | 'API' | 'CMP' | 'CSV' | 'EMAIL_INTAKE' | 'WEB') | undefined, status?: ('PENDING_EMAIL_VERIFICATION' | 'PENDING_IDENTITY_VERIFICATION' | 'IN_PROGRESS' | 'IN_REVIEW' | 'PENDING_APPEAL' | 'COMPLETED' | 'REJECTED' | 'REJECTED_AUTO') | undefined, requestType?: ('CORRECT' | 'CUSTOM_1' | 'CUSTOM_2' | 'CUSTOM_3' | 'CUSTOM_4' | 'CUSTOM_5' | 'CUSTOM_6' | 'DELETE' | 'DO_NOT_SELL' | 'LIMIT_USE' | 'LIST_OR_CATEGORIES_OF_THIRD_PARTIES' | 'OPT_OUT' | 'OPT_OUT_OF_PROFILING' | 'OPT_OUT_OF_USING_SENSITIVE_DATA' | 'OTHER' | 'PORTABILITY' | 'RESTRICT_PROCESSING' | 'SUMMARIZE') | undefined, formId?: number | undefined, testRequests?: ('exclude' | 'include' | 'only') | undefined}; export type GetApiV1SubjectRightsRequestsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const dsarResponse = z.object({dsarId: z.string(), status: z.string(), requestType: z.string(), requestSource: z.string(), notes: z.string().max(3000).optional(), dsarDetails: z.object({}).optional(), due: z.string(), created: z.string(), form: z.object({formId: z.number().int().optional(), formName: z.string().optional()}).optional(), isTest: z.boolean()}); export const dsarResponseList = z.object({items: z.array(dsarResponse), 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 Subject Rights Requests * * GET /v1/subject-rights/requests */ export const getApiV1SubjectRightsRequests = async (args: GetApiV1SubjectRightsRequestsArgs, options?: GetApiV1SubjectRightsRequestsOptions) => { 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.limit != null) query.append("limit", String(args.limit)) if (args.next != null) query.append("next", String(args.next)) if (args.after != null) query.append("after", String(args.after)) if (args.source != null) query.append("source", String(args.source)) if (args.status != null) query.append("status", String(args.status)) if (args.requestType != null) query.append("requestType", String(args.requestType)) if (args.formId != null) query.append("formId", String(args.formId)) if (args.testRequests != null) query.append("testRequests", String(args.testRequests)) if (ApiKeyAuth !== undefined) headers.set("x-osano-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/subject-rights/requests${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(dsarResponseList, await res.json()) };