UNPKG

@translated/lara

Version:

Official Lara SDK for JavaScript and Node.js

130 lines (129 loc) • 5.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Glossaries = void 0; const errors_1 = require("./errors"); class Glossaries { constructor(client) { this.client = client; this.pollingInterval = 2000; } /** @deprecated Use listPaginated() instead. */ async list() { return await this.client.get("/v2/glossaries"); } /** * List resources with optional name filtering and pagination. * Without options, returns the complete list of resources without pagination. * Providing search, page, or size enables pagination; omitted page and size default to 1 and 20. */ async listPaginated(options) { return await this.client.getCollection("/v2/glossaries", options); } async create(name) { return await this.client.post("/v2/glossaries", { name }); } async get(id) { try { return await this.client.get(`/v2/glossaries/${id}`); } catch (e) { if (e instanceof errors_1.LaraApiError && e.statusCode === 404) { return null; } throw e; } } async delete(id) { return await this.client.delete(`/v2/glossaries/${id}`); } async update(id, name) { return await this.client.put(`/v2/glossaries/${id}`, { name }); } async getShares(id) { return await this.client.get(`/v2/glossaries/${id}/shares`); } async addAccountShare(id, name) { return await this.client.post(`/v2/glossaries/${id}/shares`, { name }); } async revokeAccountShare(id) { return await this.client.delete(`/v2/glossaries/${id}/shares`); } async renameAccountShare(id, name) { return await this.client.put(`/v2/glossaries/${id}/shares`, { name }); } async addGroupShare(id, groupId, name) { return await this.client.post(`/v2/glossaries/${id}/shares/groups/${groupId}`, { name }); } async revokeGroupShare(id, groupId) { return await this.client.delete(`/v2/glossaries/${id}/shares/groups/${groupId}`); } async renameGroupShare(id, groupId, name) { return await this.client.put(`/v2/glossaries/${id}/shares/groups/${groupId}`, { name }); } async importFile(id, file, options = {}) { const { contentType = "csv/table-uni", gzip = false, callbackUrl } = options; return await this.client.post(`/v2/glossaries/${id}/import`, { compression: gzip ? "gzip" : undefined, content_type: contentType, callback_url: callbackUrl }, { csv: file }); } async importCsv(id, csv, gzipOrContentType, maybeGzipOrCallbackUrl, maybeCallbackUrl) { if (typeof gzipOrContentType === "string") { if (gzipOrContentType !== "csv/table-uni" && gzipOrContentType !== "csv/table-multi") { throw new TypeError("importCsv only supports CSV formats; use importFile for TBX files."); } const gzip = typeof maybeGzipOrCallbackUrl === "boolean" ? maybeGzipOrCallbackUrl : undefined; return await this.importFile(id, csv, { contentType: gzipOrContentType, gzip, callbackUrl: maybeCallbackUrl }); } const callbackUrl = typeof maybeGzipOrCallbackUrl === "string" ? maybeGzipOrCallbackUrl : undefined; return await this.importFile(id, csv, { gzip: gzipOrContentType, callbackUrl }); } async getImportStatus(id) { return await this.client.get(`/v2/glossaries/imports/${id}`); } async waitForImport(gImport, updateCallback, maxWaitTime) { const start = Date.now(); while (gImport.progress < 1.0) { if (maxWaitTime && Date.now() - start > maxWaitTime) throw new errors_1.TimeoutError(); await new Promise((resolve) => setTimeout(resolve, this.pollingInterval)); gImport = await this.getImportStatus(gImport.id); if (updateCallback) updateCallback(gImport); } return gImport; } async counts(id) { return await this.client.get(`/v2/glossaries/${id}/counts`); } async export(id, contentType, source) { return await this.client.get(`/v2/glossaries/${id}/export`, { content_type: contentType, source }); } async exportAsync(id, callbackUrl, contentType, source) { return await this.client.get(`/v2/glossaries/${id}/export/async`, { callback_url: callbackUrl, content_type: contentType, source }); } async addOrReplaceEntry(id, terms, guid) { return await this.client.put(`/v2/glossaries/${id}/content`, { terms, guid }); } async deleteEntry(id, term, guid) { return await this.client.delete(`/v2/glossaries/${id}/content`, undefined, { term, guid }); } } exports.Glossaries = Glossaries;