{"version":3,"sources":["../src/UberDirectDaaS.ts"],"sourcesContent":["import { UberDirectAuth } from './UberDirectAuth'\nimport {\n    DeliveryData,\n    DeliveryListResponse,\n    deliveryListResponseSchema,\n    DeliveryResponse,\n    deliveryResponseSchema,\n    PODRequest,\n    PODResponse,\n    pODResponseSchema,\n    QuoteRequest,\n    QuoteResponse,\n    QuoteResponseSchema,\n} from './types/DaasTypes'\nimport { ZodError } from 'zod'\nimport { UberDirectTypeProtectErrorHandling } from './UberDirectTypeProtect'\nimport { UberDirectLogger } from './UberDirectLogger'\n\n/**\n * UberDirect Direct DaaS API Client\n * Delivery as a Service (DaaS) is a service that allows you to create deliveries between two addresses.\n */\nexport class UberDirectDaaS extends UberDirectTypeProtectErrorHandling {\n    constructor(private readonly auth: UberDirectAuth, private readonly logger = new UberDirectLogger(), private readonly testMode = false) {\n        super()\n    }\n\n    /**\n     * Create a quote to check deliverability, validity and cost for delivery between two addresses.\n     * @param requestBody\n     * @param customerId\n     */\n    async quote(requestBody: QuoteRequest, customerId: undefined | string = undefined): Promise<QuoteResponse> {\n        const url = `customers/${ customerId || this.auth.getCustomerId() }/delivery_quotes`\n\n        const response = await this.auth.makeApiRequest<QuoteResponse>('post', url, requestBody, this.logger)\n        try {\n            QuoteResponseSchema.parse(response)\n        } catch (e) {\n            this.throw(e as ZodError)\n        }\n        return response\n    }\n\n    /**\n     * Create a delivery between two addresses.\n     * @param requestBody\n     * @param customerId\n     */\n    async createDelivery(requestBody: DeliveryData, customerId: undefined | string = undefined): Promise<DeliveryResponse> {\n        const url = `customers/${ customerId || this.auth.getCustomerId() }/deliveries`\n        if (this.testMode) {\n            requestBody.test_specifications = {\n                robo_courier_specification: {\n                    mode: 'auto',\n                },\n            }\n        }\n\n        const response = await this.auth.makeApiRequest<DeliveryResponse>('post', url, requestBody, this.logger)\n        try {\n            deliveryResponseSchema.parse(response)\n        } catch (e) {\n            this.throw(e as ZodError)\n        }\n\n        return response\n    }\n\n    /**\n     * Retrieve the current status of an existing delivery\n     * @param deliveryId\n     * @param customerId\n     */\n    async getDelivery(deliveryId: string, customerId: undefined | string = undefined): Promise<DeliveryResponse> {\n        const url = `customers/${ customerId || this.auth.getCustomerId() }/deliveries/${ deliveryId }`\n\n        const response = await this.auth.makeApiRequest<DeliveryResponse>('get', url, undefined, this.logger)\n        try {\n            deliveryResponseSchema.parse(response)\n        } catch (e) {\n            this.throw(e as ZodError)\n        }\n        return response\n    }\n\n    /**\n     * Modify an ongoing delivery.\n     * @param deliveryId\n     * @param requestBody\n     * @param customerId\n     */\n    async updateDelivery(deliveryId: string, requestBody: DeliveryData, customerId: undefined | string = undefined): Promise<DeliveryResponse> {\n        const url = `customers/${ customerId || this.auth.getCustomerId() }/deliveries/${ deliveryId }`\n        if (this.testMode) {\n            requestBody.test_specifications = {\n                robo_courier_specification: {\n                    mode: 'auto',\n                },\n            }\n        }\n\n        const response = await this.auth.makeApiRequest<DeliveryResponse>('post', url, requestBody, this.logger)\n        try {\n            deliveryResponseSchema.parse(response)\n        } catch (e) {\n            this.throw(e as ZodError)\n        }\n        return response\n    }\n\n    /**\n     * Cancel an ongoing or previously scheduled delivery.\n     * @param deliveryId\n     * @param customerId\n     */\n    async cancelDelivery(deliveryId: string, customerId: undefined | string = undefined): Promise<boolean> {\n        const url = `customers/${ customerId || this.auth.getCustomerId() }/deliveries/${ deliveryId }/cancel`\n\n        const response = await this.auth.makeApiRequest<DeliveryResponse>('post', url, undefined, this.logger)\n        try {\n            deliveryResponseSchema.parse(response)\n        } catch (e) {\n            this.throw(e as ZodError)\n        }\n        return response.status === 'canceled'\n    }\n\n    /**\n     * List all deliveries for a customer.\n     * @param customerId\n     */\n    async listDeliveries(customerId: undefined | string = undefined): Promise<DeliveryListResponse> {\n        const url = `customers/${ customerId || this.auth.getCustomerId() }/deliveries`\n\n        const response = await this.auth.makeApiRequest<DeliveryListResponse>('get', url, undefined, this.logger)\n        try {\n            deliveryListResponseSchema.parse(response)\n        } catch (e) {\n            this.throw(e as ZodError)\n        }\n        return response\n    }\n\n    /**\n     * If you require verification for a delivery, you can retrieve a proof-of-delivery image file through our API.\n     * This file contains information such as the delivery status, timestamp, Uber Order ID, External Order ID,\n     * and the type of proof collected (signature, picture, or pincode).\n     * If signer name or relationship is enabled, it will also be included in the file.\n     * You can use the delivery token, delivery uuid, or UUID from the CreateDelivery response to identify the order when making the API call.\n     * @param deliveryId\n     * @param requestBody\n     * @param customerId\n     */\n    async getPOD(deliveryId: string, requestBody: PODRequest, customerId: undefined | string = undefined): Promise<PODResponse> {\n        const url = `customers/${ customerId || this.auth.getCustomerId() }/deliveries/${ deliveryId }/proof-of-delivery`\n\n        const response = await this.auth.makeApiRequest<PODResponse>('post', url, requestBody, this.logger)\n        try {\n            pODResponseSchema.parse(response)\n        } catch (e) {\n            this.throw(e as ZodError)\n        }\n        return response\n    }\n}\n"],"mappings":";;;AACA;AAAA,EAGI;AAAA,EAEA;AAAA,EAGA;AAAA,EAGA;AAAA,OACG;AAEP,SAAS,0CAA0C;AACnD,SAAS,wBAAwB;AAM1B,MAAM,uBAAuB,mCAAmC;AAAA,EACnE,YAA6B,MAAuC,SAAS,IAAI,iBAAiB,GAAoB,WAAW,OAAO;AACpI,UAAM;AADmB;AAAuC;AAAkD;AAAA,EAEtH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOM,MAAM,aAA2B,aAAiC,QAAmC;AAAA;AACvG,YAAM,MAAM,aAAc,cAAc,KAAK,KAAK,cAAc,CAAE;AAElE,YAAM,WAAW,MAAM,KAAK,KAAK,eAA8B,QAAQ,KAAK,aAAa,KAAK,MAAM;AACpG,UAAI;AACA,4BAAoB,MAAM,QAAQ;AAAA,MACtC,SAAS,GAAG;AACR,aAAK,MAAM,CAAa;AAAA,MAC5B;AACA,aAAO;AAAA,IACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOM,eAAe,aAA2B,aAAiC,QAAsC;AAAA;AACnH,YAAM,MAAM,aAAc,cAAc,KAAK,KAAK,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