export type Channel = string; export type SellerId = string; export type TicketId = string; export type TicketFrom = {role: 'BUYER' | 'SELLER' | 'CHANNEL', name?: string | undefined}; export type TicketAttachment = {filename: string, contentType: string}; export type SellerTicketReply = {channel: Channel, sellerId: SellerId, ticketId: TicketId, replyRequested?: boolean | undefined, createdAt: string, from: TicketFrom, message: string, attachment?: Array | undefined}; export type CreateApiV1SellerTicketArgs = {body: SellerTicketReply}; export type CreateApiV1SellerTicketOptions = {baseUrl?: string | undefined, SellerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Reply to Ticket * * POST /v1/seller/ticket */ export const createApiV1SellerTicket = async (args: CreateApiV1SellerTicketArgs, options?: CreateApiV1SellerTicketOptions) => { const {baseUrl = "https://scx-sbx.api.jtl-software.com", fetch: fetchFn = fetch, SellerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (SellerAuth !== undefined) headers.set('authorization', `Bearer ${SellerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/seller/ticket${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 undefined };