import {z} from 'zod' export type File = {id: number, customer: number, created_at: string, created_by: number | null, created_by_name: string, created_by_email: string, last_modified_at: string, name: string, url: string, s3_content_type?: (string | null) | undefined, s3_content_length?: (number | null) | undefined, s3_path: string, object_id?: (number | null) | undefined, app: string, model: string, is_deleted: boolean, deleted_at: string | null}; export type FixedAssetDepreciation = {id?: number | undefined, fixed_asset?: number | undefined, journal_entry_order: string, depreciated_until?: (string | null) | undefined, posted?: boolean | undefined, post_date: string, amount?: number | undefined, created_at: string, last_modified_at: string, customer: number, journal_entry?: (number | null) | undefined}; export type FixedAssetDisposal = {id: number, journal_entry_order: string, transaction_id?: string | undefined, disposal_percentage: number, disposal_date: string, proceeds_amount?: number | undefined, created_at: string, last_modified_at: string, customer: number, fixed_asset: number, journal_entry?: (number | null) | undefined}; export type FixedAssetTransfer = {id: number, source_asset_class_name: string, new_asset_class_name: string, reclassification_journal_entry_order: string, catchup_depreciation_journal_entry_order: string, created_asset_name: string, effective_date: string, is_partial?: boolean | undefined, transfer_amount?: number | undefined, transfer_accumulated_depreciation?: number | undefined, transfer_percentage?: number | undefined, new_useful_life_months?: (number | null) | undefined, new_salvage_value?: number | undefined, new_depreciation_start_date?: (string | null) | undefined, new_depreciation_end_date?: (string | null) | undefined, memo?: (string | null) | undefined, created_at: string, last_modified_at: string, customer: number, fixed_asset: number, source_asset_class: number, new_asset_class: number, reclassification_journal_entry?: (number | null) | undefined, catchup_depreciation_journal_entry?: (number | null) | undefined, created_asset?: (number | null) | undefined}; export type FixedAssetStatusEnum = 'ACTIVE' | 'PAUSED' | 'DEPRECIATED' | 'DISPOSED'; export type FixedAsset = {id: number, entity_name: string, entity_currency: string, useful_life: string, asset_class_useful_life: number, asset_class_name: string, asset_account: string, asset_account_name: string, depreciation_expense_account: string, depreciation_expense_account_name: string, accumulated_depreciation_account: string, accumulated_depreciation_account_name: string, purchase_journal_entry_order: string, purchase_transaction_id: string, vendor_name: string, department_name: string, tags: Array<{[key: string]: unknown}>, attachments: Array, depreciations?: (Array | null) | undefined, depreciation_start_date?: (string | null) | undefined, depreciation_end_date?: (string | null) | undefined, disposals: Array | null, transfers: Array | null, net_book_value: string, depreciated_until?: (string | null) | undefined, last_modified_at: string, is_deleted: boolean, deleted_at: string | null, chat_uuid?: string | undefined, name: string, description?: (string | null) | undefined, currency?: string | undefined, initial_value?: number | undefined, salvage_value?: number | undefined, purchase_date: string, created_at: string, status?: FixedAssetStatusEnum | undefined, tag_ids?: Array | undefined, tag_group_ids?: Array | undefined, exchange_rate?: (number | null) | undefined, exchange_rate_book?: (number | null) | undefined, is_non_depreciable?: (boolean | null) | undefined, pause_date: string | null, pause_reason: string | null, last_resume_date: string | null, chat_id?: (number | null) | undefined, customer: number, entity?: (number | null) | undefined, asset_class?: (number | null) | undefined, purchase_journal_entry?: (number | null) | undefined, purchase_transaction?: (number | null) | undefined, vendor?: (number | null) | undefined, department?: (number | null) | undefined, purchase_transactions?: Array | undefined}; export type CreateApiCoaApiFixedAssetArgs = {body: FixedAsset}; export type CreateApiCoaApiFixedAssetOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const file = z.object({id: z.number().int(), customer: z.number().int(), created_at: z.string(), created_by: z.number().int().nullable(), created_by_name: z.string(), created_by_email: z.string(), last_modified_at: z.string(), name: z.string(), url: z.string(), s3_content_type: z.string().nullable().optional(), s3_content_length: z.number().int().gte(0).lte(2147483647).nullable().optional(), s3_path: z.string(), object_id: z.number().int().gte(0).lte(2147483647).nullable().optional(), app: z.string(), model: z.string(), is_deleted: z.boolean(), deleted_at: z.string().nullable()}); export const fixedAssetDepreciation = z.object({id: z.number().int().optional(), fixed_asset: z.number().int().optional(), journal_entry_order: z.string(), depreciated_until: z.string().nullable().optional(), posted: z.boolean().optional(), post_date: z.string(), amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), created_at: z.string(), last_modified_at: z.string(), customer: z.number().int(), journal_entry: z.number().int().nullable().optional()}); export const fixedAssetDisposal = z.object({id: z.number().int(), journal_entry_order: z.string(), transaction_id: z.string().optional(), disposal_percentage: z.number().gt(-1000000000000000000).lt(1000000000000000000), disposal_date: z.string(), proceeds_amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), created_at: z.string(), last_modified_at: z.string(), customer: z.number().int(), fixed_asset: z.number().int(), journal_entry: z.number().int().nullable().optional()}); export const fixedAssetTransfer = z.object({id: z.number().int(), source_asset_class_name: z.string(), new_asset_class_name: z.string(), reclassification_journal_entry_order: z.string(), catchup_depreciation_journal_entry_order: z.string(), created_asset_name: z.string(), effective_date: z.string(), is_partial: z.boolean().optional(), transfer_amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), transfer_accumulated_depreciation: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), transfer_percentage: z.number().gt(-1000).lt(1000).optional(), new_useful_life_months: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), new_salvage_value: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), new_depreciation_start_date: z.string().nullable().optional(), new_depreciation_end_date: z.string().nullable().optional(), memo: z.string().nullable().optional(), created_at: z.string(), last_modified_at: z.string(), customer: z.number().int(), fixed_asset: z.number().int(), source_asset_class: z.number().int(), new_asset_class: z.number().int(), reclassification_journal_entry: z.number().int().nullable().optional(), catchup_depreciation_journal_entry: z.number().int().nullable().optional(), created_asset: z.number().int().nullable().optional()}); export const fixedAssetStatusEnum = z.enum(["ACTIVE", "PAUSED", "DEPRECIATED", "DISPOSED"]); export const fixedAsset = z.object({id: z.number().int(), entity_name: z.string(), entity_currency: z.string(), useful_life: z.string(), asset_class_useful_life: z.number().int(), asset_class_name: z.string(), asset_account: z.string(), asset_account_name: z.string(), depreciation_expense_account: z.string(), depreciation_expense_account_name: z.string(), accumulated_depreciation_account: z.string(), accumulated_depreciation_account_name: z.string(), purchase_journal_entry_order: z.string(), purchase_transaction_id: z.string(), vendor_name: z.string(), department_name: z.string(), tags: z.array(z.record(z.string(), z.unknown())), attachments: z.array(file), depreciations: z.array(fixedAssetDepreciation).nullable().optional(), depreciation_start_date: z.string().nullable().optional(), depreciation_end_date: z.string().nullable().optional(), disposals: z.array(fixedAssetDisposal).nullable(), transfers: z.array(fixedAssetTransfer).nullable(), net_book_value: z.string(), depreciated_until: z.string().nullable().optional(), last_modified_at: z.string(), is_deleted: z.boolean(), deleted_at: z.string().nullable(), chat_uuid: z.string().optional(), name: z.string().max(250), description: z.string().nullable().optional(), currency: z.string().max(3).optional(), initial_value: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), salvage_value: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), purchase_date: z.string(), created_at: z.string(), status: fixedAssetStatusEnum.optional(), tag_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), tag_group_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), exchange_rate: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), exchange_rate_book: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), is_non_depreciable: z.boolean().nullable().optional(), pause_date: z.string().nullable(), pause_reason: z.string().nullable(), last_resume_date: z.string().nullable(), chat_id: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), customer: z.number().int(), entity: z.number().int().nullable().optional(), asset_class: z.number().int().nullable().optional(), purchase_journal_entry: z.number().int().nullable().optional(), purchase_transaction: z.number().int().nullable().optional(), vendor: z.number().int().nullable().optional(), department: z.number().int().nullable().optional(), purchase_transactions: z.array(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 }; /** * Create Fixed Asset * * POST /coa/api/fixed-asset */ export const createApiCoaApiFixedAsset = async (args: CreateApiCoaApiFixedAssetArgs, options?: CreateApiCoaApiFixedAssetOptions) => { const {baseUrl = "https://api.meetcampfire.com", fetch: fetchFn = fetch, knoxApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/coa/api/fixed-asset${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(fixedAsset, await res.json()) };