import {z} from 'zod' export type Item = {id?: string | undefined, group_id?: string | undefined}; export type Limitation = {dynamic_purchase_to_days?: number | undefined, discount_activation?: Array<{type: 'deactivate_if_discount_active', value: string}> | undefined, discount_hours?: ({timezone?: string | undefined, hours: Array<{day: 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun', start: string, end: string}>}) | undefined, discount_reward_usage?: number | undefined, discount_combination?: (-1 | 0) | undefined, discount_eligible?: ('item_eligible_for_discount' | 'item_eligible_for_discount_no_discount' | 'receipt_no_discount') | undefined, discount_repeat_usage?: number | undefined, stamp_expire_days?: number | undefined, blacklist?: Array | undefined}; export type CustomerRequirement = {addresses?: (Array<{country?: Array | undefined, postal_code?: Array | undefined, postal_place?: Array | undefined, custom_type?: Array | undefined, type?: Array | undefined}>) | undefined, company?: ({bussiness_name?: Array | undefined, department?: Array | undefined, industry?: Array | undefined, number_of_employees?: Array | undefined, organization_number?: Array | undefined, website?: Array | undefined}) | undefined, date_of_birth?: Array | undefined, enrolled_by?: ({type?: Array | undefined, value?: Array | undefined}) | undefined, favorite_store?: Array | undefined, first_name?: Array | undefined, gender?: Array | undefined, last_name?: Array | undefined, marketing_consent?: ({email?: ({consent?: Array | undefined}) | undefined, sms?: ({consent?: Array | undefined}) | undefined}) | undefined, status?: Array | undefined, term?: ({id?: Array | undefined}) | undefined, type?: Array | undefined, attributes?: {[key: string]: Array} | undefined}; export type ItemMixProperty = {items?: (Array<{id?: string | undefined, group_id?: string | undefined}>) | undefined, quantity: number, reward_eligible: boolean}; export type StoreRequirement = {id?: Array | undefined, name?: Array | undefined, business_name?: Array | undefined, address?: ({country?: Array | undefined, postal_code?: Array | undefined, postal_place?: Array | undefined}) | undefined, chain?: Array | undefined, email?: Array | undefined, gln?: Array | undefined, organization_number?: Array | undefined, phone_number?: Array | undefined, mcc?: Array | undefined, mcc_ranges?: Array<{start: unknown, end: unknown}> | undefined, bax?: Array | undefined, terminal_id?: Array | undefined}; export type Requirement = {customer?: CustomerRequirement | undefined, item?: ({quantity?: number | undefined, mixes?: Array | undefined, items?: Array | undefined}) | undefined, store_ids?: Array | undefined, gross_amount?: number | undefined, net_amount?: number | undefined, currencies?: (Array<{'anything-but'?: Array | undefined} | string>) | undefined, stamp?: number | undefined, discount_code?: string | undefined, store?: StoreRequirement | undefined, purchase_from: string, purchase_to: string}; export type RewardBase = 'net' | 'gross'; export type Reward = {type: 'discount_amount' | 'discount_percent' | 'discount_item_new_price' | 'discount_item_quantity' | 'discount_item_percent' | 'discount_mix_new_price' | 'discount_debit', value: number | number, values?: (Array<{items: Array<{id?: string | undefined, group_id?: string | undefined}>, value: number}>) | undefined, base?: RewardBase | undefined, effect?: ('discount' | 'bonus') | undefined}; export type Links = Array<{href: string, rel?: string | undefined, type?: string | undefined}>; export type DiscountRefs = {id?: string | undefined, created_at?: string | undefined, created_by?: string | undefined, updated_at?: string | undefined, deleted_by?: string | undefined, deleted_at?: string | undefined, campaign_id?: string | undefined, active?: boolean | undefined, private?: boolean | undefined, updated_by?: string | undefined, type?: ('item' | 'receipt') | undefined, name?: string | undefined, receipt_text?: string | undefined, visible_from?: string | undefined, description?: string | undefined, limitation?: Limitation | undefined, requirement: Requirement, reward: Reward, metadata?: Record | undefined, links?: Links | undefined, refs?: (Array<{id?: string | undefined, stamp?: number | undefined, amount?: number | undefined, bonus?: number | undefined, statistics?: ({amount?: number | undefined, bonus?: number | undefined, debit_balance?: number | undefined, stamp?: number | undefined, usage?: number | undefined}) | undefined, items?: (Array<{line_id?: number | undefined, bonus?: number | undefined, amount?: number | undefined}>) | undefined, usage?: number | undefined}>) | undefined}; export type Address = {address_line: string, address_line_2?: string | undefined, postal_code?: string | undefined, postal_place: string, country: unknown}; export type Store = {id: string, name?: string | undefined, business_name?: string | undefined, address?: Address | undefined, chain?: string | undefined, email?: string | undefined, gln?: string | undefined, organization_number?: string | undefined, phone_number?: string | undefined, mcc?: unknown | undefined, bax?: string | undefined, terminal_id?: string | undefined, payout_destination_id?: string | undefined}; export type InfoCodeItem = {line_id?: number | undefined, amount?: number | undefined, amount_dwh?: string | undefined, infocode_id?: string | undefined, sub_infocode_id?: string | undefined, information?: string | undefined, input_type?: number | undefined, withdrawal_from_stock?: boolean | undefined}; export type TaxItem = {amount?: number | undefined, amount_dwh?: string | undefined, exempt?: boolean | undefined, included_in_price?: boolean | undefined, percentage?: number | undefined, tax_basis?: number | undefined, tax_basis_dwh?: string | undefined, tax_code?: string | undefined, tax_group?: string | undefined}; export type Dimension = {color?: string | undefined, size?: string | undefined, style?: string | undefined, config?: string | undefined, variant?: string | undefined}; export type DiscountType = 'customer' | 'periodic' | 'manual' | 'loyalty' | 'total' | 'employee' | 'external'; export type DiscountItem = {amount?: number | undefined, percentage?: number | undefined, discount_type?: DiscountType | undefined, discount_id?: string | undefined, description?: string | undefined, line_id?: number | undefined}; export type BonusItem = {bonus?: number | undefined, percentage?: number | undefined, discount_type?: DiscountType | undefined, discount_id?: string | undefined, description?: string | undefined, line_id?: number | undefined}; export type ExtraInfo = {key?: string | undefined, value?: string | undefined, value_type?: ('string' | 'integer' | 'number' | 'boolean' | 'datetime') | undefined}; export type ReceiptItem = {id?: string | undefined, groups?: (Array<{id: string, name?: string | undefined}>) | undefined, quantity?: number | undefined, unit?: string | undefined, description?: string | undefined, description_alias?: string | undefined, net_amount?: number | undefined, net_amount_dwh?: string | undefined, gross_amount?: number | undefined, gross_amount_dwh?: string | undefined, unit_gross_price?: number | undefined, tax_percent?: number | undefined, line_id?: number | undefined, barcode?: string | undefined, cost_price?: number | undefined, voided?: boolean | undefined, scale_item?: boolean | undefined, eligible_for_discount?: boolean | undefined, included_in_total_discount?: boolean | undefined, price_has_been_keyedIn?: boolean | undefined, discount_has_been_keyedIn?: boolean | undefined, is_return_item?: boolean | undefined, is_linked_item?: boolean | undefined, is_virtual_product?: boolean | undefined, is_changed?: boolean | undefined, salesperson_id?: string | undefined, salesperson_name?: string | undefined, serial_id?: string | undefined, comment?: string | undefined, infocode_lines?: Array | undefined, tax_lines?: Array | undefined, dimension?: Dimension | undefined, discount_lines?: Array | undefined, bonus_lines?: Array | undefined, extra_info?: Array | undefined}; export type CardInfo = {balance_amount?: number | undefined, card_amount?: number | undefined, issuer_id?: number | undefined, issuer_name?: string | undefined, session_id?: string | undefined, terminal_id?: string | undefined, card_number?: string | undefined, card_type?: string | undefined, receipt?: string | undefined}; export type PaymentItem = {line_id?: number | undefined, amount?: number | undefined, type_id?: string | undefined, token_id?: string | undefined, token_type?: string | undefined, description?: string | undefined, voided?: boolean | undefined, card_info?: CardInfo | undefined, reference_id?: string | undefined, infocode_lines?: Array | undefined}; export type CreateApiAccountsAidReceiptsArgs = {aid: unknown, token_expire_days?: number | undefined, body: Array<{id?: string | undefined, created_at?: string | undefined, created_by?: string | undefined, updated_at?: string | undefined, deleted_by?: string | undefined, deleted_at?: string | undefined, discounts?: Array | undefined, store: Store, items?: Array | undefined, receipt_id: string, delivery?: ({first_name?: string | undefined, last_name?: string | undefined, email?: string | undefined, phone_number?: unknown | undefined, address?: Address | undefined}) | undefined, customer_id?: string | undefined, customer?: ({gender?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, email?: string | undefined, metadata?: Record | undefined, phone_number?: unknown | undefined, addresses?: (Array<{address_line: string, address_line_2?: string | undefined, postal_code?: string | undefined, postal_place: string, country: unknown, type?: string | undefined, custom_type?: string | undefined}>) | undefined, pays_tax?: boolean | undefined, date_of_birth?: (string | null) | undefined, enrolled_by?: ({type?: string | undefined, value: string | null}) | undefined, favorite_store?: (string | null) | undefined, company?: ({organization_number?: string | undefined, bussiness_name: string, department?: string | undefined, industry?: string | undefined, website?: string | undefined, number_of_employees?: string | undefined}) | undefined, marketing_consent?: ({sms?: ({consent?: boolean | undefined, updated_at?: string | undefined}) | undefined, email?: ({consent?: boolean | undefined, updated_at?: string | undefined}) | undefined}) | undefined, status?: string | undefined, term?: ({id?: string | undefined}) | undefined, type?: ('customer' | 'company' | 'contact' | 'employee' | 'other') | undefined, token?: ({token_id?: string | undefined, value?: string | undefined, type?: string | undefined}) | undefined}) | undefined, gross_amount?: number | undefined, gross_amount_dwh?: string | undefined, net_amount?: number | undefined, net_amount_dwh?: string | undefined, round_off_to_coin?: number | undefined, currency?: string | undefined, purchase_at: string, order_number?: string | undefined, transaction_date?: string | undefined, amount_due?: number | undefined, amount_due_dwh?: string | undefined, no_of_items?: number | undefined, is_changed?: boolean | undefined, transaction_id?: string | undefined, total_discount?: number | undefined, total_manual_discount_amount?: number | undefined, total_manual_percentage_discount?: number | undefined, operator_id?: string | undefined, operator_name?: string | undefined, salesperson_id?: string | undefined, salesperson_name?: string | undefined, entry_status?: ('None' | 'Voided' | 'Posted' | 'Concluded' | 'Cancelled' | 'OnHold' | 'Training' | 'Reprinted') | undefined, comment?: string | undefined, tax_lines?: Array | undefined, payments?: Array | undefined, infocode_items?: Array | undefined, receipt_text?: string | undefined, discount_code?: Array | undefined, extra_info?: Array | undefined}>}; export type CreateApiAccountsAidReceiptsOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const entity = z.object({id: z.string().optional(), created_at: z.string().optional(), created_by: z.string().optional(), updated_at: z.string().optional(), deleted_by: z.string().optional(), deleted_at: z.string().optional()}); export const createApiAccountsAidReceiptsResponse = z.object({receipts: z.array(entity).optional(), duplicates: 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 }; /** * aid_receipts_post * * POST /accounts/{aid}/receipts */ export const createApiAccountsAidReceipts = async (args: CreateApiAccountsAidReceiptsArgs, options?: CreateApiAccountsAidReceiptsOptions) => { const {baseUrl = "https://api.dintero.com/v1", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.token_expire_days != null) query.append("token_expire_days", String(args.token_expire_days)) if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.aid))}/receipts${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(createApiAccountsAidReceiptsResponse, await res.json()) };