import {z} from 'zod' export type UserResourceRepresentationVersion3 = {userId?: (string | null) | undefined, email?: string | undefined, firstName: string, lastName: string, role: string, active?: boolean | undefined}; export type VerificationProcessStatusVersion3 = 'Unknown' | 'NotStarted' | 'InProgress' | 'Completed' | 'Failed'; export type OrganisationVerificationStatusOverviewResourceRepresentationVersion3 = {verified: boolean, verifiable: boolean, status: VerificationProcessStatusVersion3}; export type OrganisationPromotionResourceRepresentationVersion3 = {promotionId?: string | undefined, validFromUtc?: string | undefined, validToUtc?: string | undefined}; export type OrganisationResourceRepresentationVersion3 = {organisationId?: string | undefined, partnerClientId: string, companiesHouseNumber?: string | undefined, companyName?: string | undefined, users: Array, features?: Array | undefined, verification?: OrganisationVerificationStatusOverviewResourceRepresentationVersion3 | undefined, promotions?: Array | undefined}; export type UpdateApiOrganisationsOrganisationIdArgs = {organisationId: string, 'Crezco-Version'?: string | undefined, body: OrganisationResourceRepresentationVersion3}; export type UpdateApiOrganisationsOrganisationIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const userResourceRepresentationVersion3 = z.object({userId: z.string().nullable().optional(), email: z.string().optional(), firstName: z.string().min(1).max(50), lastName: z.string().min(1).max(50), role: z.string().min(1), active: z.boolean().optional()}); export const verificationProcessStatusVersion3 = z.enum(["Unknown", "NotStarted", "InProgress", "Completed", "Failed"]); export const organisationVerificationStatusOverviewResourceRepresentationVersion3 = z.object({verified: z.boolean(), verifiable: z.boolean(), status: verificationProcessStatusVersion3}); export const organisationPromotionResourceRepresentationVersion3 = z.object({promotionId: z.string().optional(), validFromUtc: z.string().optional(), validToUtc: z.string().optional()}); export const organisationResourceRepresentationVersion3 = z.object({organisationId: z.string().optional(), partnerClientId: z.string().min(1).max(50), companiesHouseNumber: z.string().max(8).optional(), companyName: z.string().max(200).optional(), users: z.array(userResourceRepresentationVersion3), features: z.array(z.string()).optional(), verification: organisationVerificationStatusOverviewResourceRepresentationVersion3.optional(), promotions: z.array(organisationPromotionResourceRepresentationVersion3).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 Organisation * * PUT /organisations/{organisationId} */ export const updateApiOrganisationsOrganisationId = async (args: UpdateApiOrganisationsOrganisationIdArgs, options?: UpdateApiOrganisationsOrganisationIdOptions) => { const {baseUrl = "https://api.partners.uat.crezco.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Crezco-Version'] != null) headers.set("Crezco-Version", String(args['Crezco-Version'])) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/organisations/${encodeURIComponent(String(args.organisationId))}${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(organisationResourceRepresentationVersion3, await res.json()) };