UNPKG

@maximai/maxim-js

Version:

Maxim AI JS SDK. Visit https://getmaxim.ai for more info.

42 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MaximAttachmentAPI = void 0; const maxim_1 = require("./maxim"); class MaximAttachmentAPI extends maxim_1.MaximAPI { constructor(baseUrl, apiKey, isDebug) { super(baseUrl, apiKey, isDebug); } async getUploadUrl(key, mimeType, size) { const response = await this.fetch(`/api/sdk/v1/log-repositories/attachments/upload-url?key=${key}&mimeType=${mimeType}&size=${size}`); if ("error" in response) { throw response.error; } return response.data; } async uploadToSignedUrl(url, data, mimeType) { const response = await this.axiosInstance.put(url, data, { headers: { "Content-Type": mimeType, "Content-Length": data.length.toString(), }, responseType: "text", timeout: 120000, // 2 minute timeout for large file uploads // Don't transform the request/response to preserve binary data transformRequest: [(data) => data], transformResponse: [(data) => data], // Override base URL since this is a direct call to signed URL baseURL: "", }); // Success - axios retry already handled any retryable errors if (response.status >= 200 && response.status < 300) { return; } // This shouldn't happen due to axios retry, but just in case if (response.data && typeof response.data === "object" && "error" in response.data) { throw response.data.error; } throw response.data; } } exports.MaximAttachmentAPI = MaximAttachmentAPI; //# sourceMappingURL=attachment.js.map