import {z} from 'zod' export type GetApiV1ConfigArchivingOptions = {baseUrl?: string | undefined, PipelineServiceKey?: string | undefined, fetch?: typeof fetch | undefined}; export const integration = z.string(); export const bucket = z.string(); export const endpoint = z.string(); export const apikey = z.string(); export const resourceinstanceid = z.string(); export const accountname = z.string(); export const accountkey = z.string(); export const projectid = z.string(); export const space = z.string(); export const accesskey = z.string(); export const secretkey = z.string(); export const authurl = z.string(); export const expires = z.string(); export const username = z.string(); export const password = z.string(); export const tenantname = z.string(); export const archivingConfigRequest = z.object({integration: integration.optional(), bucket: bucket.optional(), endpoint: endpoint.optional(), apikey: apikey.optional(), resourceinstanceid: resourceinstanceid.optional(), accountname: accountname.optional(), accountkey: accountkey.optional(), projectid: projectid.optional(), space: space.optional(), accesskey: accesskey.optional(), secretkey: secretkey.optional(), authurl: authurl.optional(), expires: expires.optional(), username: username.optional(), password: password.optional(), tenantname: tenantname.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 }; /** * Get Archive Configuration * * GET /v1/config/archiving */ export const getApiV1ConfigArchiving = async (options?: GetApiV1ConfigArchivingOptions) => { const {baseUrl = "https://api.mezmo.com/v3", fetch: fetchFn = fetch, PipelineServiceKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (PipelineServiceKey !== undefined) headers.set("Authorization", PipelineServiceKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/config/archiving${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(archivingConfigRequest, await res.json()) };