import {z} from 'zod' export type Integration = string; export type Bucket = string; export type Endpoint = string; export type Apikey = string; export type Resourceinstanceid = string; export type Accountname = string; export type Accountkey = string; export type Projectid = string; export type Space = string; export type Accesskey = string; export type Secretkey = string; export type Authurl = string; export type Expires = string; export type Username = string; export type Password = string; export type Tenantname = string; export type ArchivingConfigRequest = {integration?: Integration | undefined, bucket?: Bucket | undefined, endpoint?: Endpoint | undefined, apikey?: Apikey | undefined, resourceinstanceid?: Resourceinstanceid | undefined, accountname?: Accountname | undefined, accountkey?: Accountkey | undefined, projectid?: Projectid | undefined, space?: Space | undefined, accesskey?: Accesskey | undefined, secretkey?: Secretkey | undefined, authurl?: Authurl | undefined, expires?: Expires | undefined, username?: Username | undefined, password?: Password | undefined, tenantname?: Tenantname | undefined}; export type UpdateApiV1ConfigArchivingArgs = {body: ArchivingConfigRequest}; export type UpdateApiV1ConfigArchivingOptions = {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 }; /** * Update Archive Configuration * * PUT /v1/config/archiving */ export const updateApiV1ConfigArchiving = async (args: UpdateApiV1ConfigArchivingArgs, options?: UpdateApiV1ConfigArchivingOptions) => { const {baseUrl = "https://api.mezmo.com/v3", fetch: fetchFn = fetch, PipelineServiceKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "PUT", headers, body: JSON.stringify(args.body)}) 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()) };