import {z} from 'zod' export type UserSecurityToken = {id?: number | undefined, token?: string | undefined, isAdmin?: boolean | undefined, user?: (User | null) | undefined}; export type Supplier = {alias?: (string | null) | undefined, name?: (string | null) | undefined, id?: number | undefined}; export type MartSupplier = {mart?: (Mart | null) | undefined, supplier?: (Supplier | null) | undefined, tableName?: (string | null) | undefined, id?: number | undefined}; export type Mart = {alias?: (string | null) | undefined, server?: (string | null) | undefined, database?: (string | null) | undefined, username?: (string | null) | undefined, password?: (string | null) | undefined, searchTypeId?: number | undefined, audit?: boolean | undefined, martAttributes?: (Array | null) | undefined, martSuppliers?: (Array | null) | undefined, attributes?: (Array | null) | undefined, suppliers?: (Array | null) | undefined, id?: number | undefined}; export type AttributeType = 1; export type Attribute = {alias?: (string | null) | undefined, type?: AttributeType | undefined, id?: number | undefined}; export type MartAttribute = {mart?: (Mart | null) | undefined, attribute?: (Attribute | null) | undefined, columnName?: (string | null) | undefined, dataDictionaryItemId?: number | undefined, id?: number | undefined}; export type UserMartAttribute = {user?: (User | null) | undefined, martAttribute?: (MartAttribute | null) | undefined, id?: number | undefined}; export type UserMartSupplier = {user?: (User | null) | undefined, martSupplier?: (MartSupplier | null) | undefined, id?: number | undefined}; export type User = {externalId?: (string | null) | undefined, tokens?: (Array | null) | undefined, userMartAttributes?: (Array | null) | undefined, userMartSuppliers?: (Array | null) | undefined, availableMarts?: (Array | null) | undefined, id?: number | undefined}; export type CreateApiApiUsersArgs = {body: User}; export type CreateApiApiUsersOptions = {baseUrl: string, token?: string | undefined, fetch?: typeof fetch | undefined}; export const userSecurityToken = z.object({id: z.number().int().optional(), token: z.string().optional(), isAdmin: z.boolean().optional(), user: z.lazy(() => user.nullable().optional())}); export const supplier = z.object({alias: z.string().nullable().optional(), name: z.string().nullable().optional(), id: z.number().int().optional()}); export const martSupplier = z.object({mart: z.lazy(() => mart.nullable().optional()), supplier: supplier.nullable().optional(), tableName: z.string().nullable().optional(), id: z.number().int().optional()}); export const mart: z.ZodType = z.object({alias: z.string().nullable().optional(), server: z.string().nullable().optional(), database: z.string().nullable().optional(), username: z.string().nullable().optional(), password: z.string().nullable().optional(), searchTypeId: z.number().int().optional(), audit: z.boolean().optional(), martAttributes: z.array(z.lazy(() => martAttribute)).nullable().optional(), martSuppliers: z.array(martSupplier).nullable().optional(), attributes: z.array(z.string()).nullable().optional(), suppliers: z.array(z.string()).nullable().optional(), id: z.number().int().optional()}); export const attributeType = z.literal(1); export const attribute = z.object({alias: z.string().nullable().optional(), type: attributeType.optional(), id: z.number().int().optional()}); export const martAttribute: z.ZodType = z.object({mart: mart.nullable().optional(), attribute: attribute.nullable().optional(), columnName: z.string().nullable().optional(), dataDictionaryItemId: z.number().int().optional(), id: z.number().int().optional()}); export const userMartAttribute = z.object({user: z.lazy(() => user.nullable().optional()), martAttribute: martAttribute.nullable().optional(), id: z.number().int().optional()}); export const userMartSupplier = z.object({user: z.lazy(() => user.nullable().optional()), martSupplier: martSupplier.nullable().optional(), id: z.number().int().optional()}); export const user: z.ZodType = z.object({externalId: z.string().nullable().optional(), tokens: z.array(userSecurityToken).nullable().optional(), userMartAttributes: z.array(userMartAttribute).nullable().optional(), userMartSuppliers: z.array(userMartSupplier).nullable().optional(), availableMarts: z.array(mart).nullable().optional(), id: z.number().int().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 }; /** * POST /api/users */ export const createApiApiUsers = async (args: CreateApiApiUsersArgs, options: CreateApiApiUsersOptions) => { const {baseUrl, fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (token !== undefined) headers.set("X-Deluxe-Auth", token) const url = `${baseUrl.replace(/\/+$/, '')}/api/users${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(user, await res.json()) };