@translated/lara 1.6.6 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/lib/Documents.d.ts +12 -0
  2. package/lib/Documents.js +71 -0
  3. package/lib/Glossaries.d.ts +17 -0
  4. package/lib/Glossaries.js +68 -0
  5. package/lib/Memories.d.ts +18 -0
  6. package/lib/Memories.js +95 -0
  7. package/lib/Translator.d.ts +24 -0
  8. package/lib/Translator.js +152 -0
  9. package/lib/index.d.ts +2 -6
  10. package/lib/index.js +2 -17
  11. package/lib/models/Authentication.d.ts +12 -0
  12. package/lib/models/Authentication.js +1 -0
  13. package/lib/models/UploadableFile.d.ts +1 -0
  14. package/lib/models/UploadableFile.js +1 -0
  15. package/lib/models/documents.d.ts +51 -0
  16. package/lib/{translator/models.js → models/documents.js} +2 -6
  17. package/lib/models/glossaries.d.ts +19 -0
  18. package/lib/models/glossaries.js +1 -0
  19. package/lib/models/index.d.ts +6 -0
  20. package/lib/models/index.js +6 -0
  21. package/lib/models/memories.d.ts +19 -0
  22. package/lib/models/memories.js +1 -0
  23. package/lib/models/translator.d.ts +48 -0
  24. package/lib/models/translator.js +1 -0
  25. package/lib/sdk-version.js +1 -4
  26. package/lib/utils/errors.js +12 -0
  27. package/lib/utils/formdata/browser.d.ts +2 -0
  28. package/lib/utils/formdata/browser.js +15 -0
  29. package/lib/utils/formdata/index.d.ts +4 -0
  30. package/lib/utils/formdata/index.js +10 -0
  31. package/lib/utils/formdata/node.d.ts +5 -0
  32. package/lib/utils/formdata/node.js +16 -0
  33. package/lib/utils/sleep.d.ts +2 -0
  34. package/lib/utils/sleep.js +1 -0
  35. package/lib/utils/toCamelCase.d.ts +2 -0
  36. package/lib/utils/toCamelCase.js +16 -0
  37. package/lib/utils/toSnakeCase.js +1 -3
  38. package/package.json +23 -13
  39. package/lib/credentials.d.ts +0 -5
  40. package/lib/credentials.js +0 -10
  41. package/lib/crypto/browser-crypto.d.ts +0 -11
  42. package/lib/crypto/browser-crypto.js +0 -28
  43. package/lib/crypto/index.d.ts +0 -3
  44. package/lib/crypto/index.js +0 -15
  45. package/lib/crypto/node-crypto.d.ts +0 -6
  46. package/lib/crypto/node-crypto.js +0 -55
  47. package/lib/crypto/portable-crypto.d.ts +0 -5
  48. package/lib/crypto/portable-crypto.js +0 -2
  49. package/lib/errors.js +0 -18
  50. package/lib/net/browser-client.d.ts +0 -8
  51. package/lib/net/browser-client.js +0 -62
  52. package/lib/net/client.d.ts +0 -34
  53. package/lib/net/client.js +0 -108
  54. package/lib/net/index.d.ts +0 -3
  55. package/lib/net/index.js +0 -23
  56. package/lib/net/node-client.d.ts +0 -10
  57. package/lib/net/node-client.js +0 -103
  58. package/lib/net/s3/browser-client.d.ts +0 -9
  59. package/lib/net/s3/browser-client.js +0 -28
  60. package/lib/net/s3/client.d.ts +0 -9
  61. package/lib/net/s3/client.js +0 -10
  62. package/lib/net/s3/index.d.ts +0 -3
  63. package/lib/net/s3/index.js +0 -13
  64. package/lib/net/s3/node-client.d.ts +0 -10
  65. package/lib/net/s3/node-client.js +0 -47
  66. package/lib/translator/models.d.ts +0 -105
  67. package/lib/translator/translator.d.ts +0 -80
  68. package/lib/translator/translator.js +0 -265
  69. /package/lib/{errors.d.ts → utils/errors.d.ts} +0 -0
@@ -0,0 +1,12 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { Document, DocumentDownloadOptions, DocumentTranslateOptions, DocumentUploadOptions, UploadableFile } from './models';
3
+ export default class Documents {
4
+ private readonly client;
5
+ private readonly pollingInterval;
6
+ private readonly maxWaitTime;
7
+ constructor(client: AxiosInstance);
8
+ upload(file: UploadableFile, filenane: string, source: string | null, target: string, options?: DocumentUploadOptions): Promise<Document>;
9
+ status(id: string): Promise<Document>;
10
+ download(id: string, options?: DocumentDownloadOptions): Promise<Blob | Buffer>;
11
+ translate(file: UploadableFile, filenane: string, source: string | null, target: string, options?: DocumentTranslateOptions): Promise<Blob | Buffer>;
12
+ }
@@ -0,0 +1,71 @@
1
+ import axios from 'axios';
2
+ import { DocumentStatus, } from './models';
3
+ import toFormData from './utils/formdata';
4
+ import toSnakeCase from './utils/toSnakeCase';
5
+ import sleep from './utils/sleep';
6
+ import { LaraApiError, TimeoutError } from './utils/errors';
7
+ export default class Documents {
8
+ constructor(client) {
9
+ this.pollingInterval = 2000;
10
+ this.maxWaitTime = 1000 * 60 * 15; // 15 minutes
11
+ this.client = client;
12
+ }
13
+ async upload(file, filenane, source, target, options) {
14
+ const { data: s3UploadUrlData } = await this.client.get(`/v2/documents/upload-url?filename=${encodeURIComponent(filenane)}`);
15
+ const { url, fields } = s3UploadUrlData;
16
+ const [formData, headers] = toFormData({
17
+ file,
18
+ ...fields,
19
+ });
20
+ await axios.post(url, formData, { headers });
21
+ const noTraceHeader = (options === null || options === void 0 ? void 0 : options.noTrace) ? { 'X-Lara-No-Trace': 'true' } : undefined;
22
+ const { data } = await this.client.post(`/v2/documents`, {
23
+ source,
24
+ target,
25
+ s3key: fields.key,
26
+ adapt_to: options === null || options === void 0 ? void 0 : options.adaptTo,
27
+ glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
28
+ style: options === null || options === void 0 ? void 0 : options.style,
29
+ password: options === null || options === void 0 ? void 0 : options.password,
30
+ extraction_params: (options === null || options === void 0 ? void 0 : options.extractionParams) ? toSnakeCase(options.extractionParams) : undefined,
31
+ }, noTraceHeader ? { headers: noTraceHeader } : undefined);
32
+ return data;
33
+ }
34
+ async status(id) {
35
+ const { data } = await this.client.get(`/v2/documents/${id}`);
36
+ return data;
37
+ }
38
+ async download(id, options) {
39
+ const { data } = await this.client.get(`/v2/documents/${id}/download-url`, {
40
+ data: {
41
+ output_format: options === null || options === void 0 ? void 0 : options.outputFormat,
42
+ },
43
+ });
44
+ const { data: downloadedData } = await axios.get(data.url);
45
+ return downloadedData;
46
+ }
47
+ async translate(file, filenane, source, target, options) {
48
+ const uploadOptions = {
49
+ adaptTo: options === null || options === void 0 ? void 0 : options.adaptTo,
50
+ glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
51
+ noTrace: options === null || options === void 0 ? void 0 : options.noTrace,
52
+ style: options === null || options === void 0 ? void 0 : options.style,
53
+ password: options === null || options === void 0 ? void 0 : options.password,
54
+ extractionParams: options === null || options === void 0 ? void 0 : options.extractionParams,
55
+ };
56
+ const { id } = await this.upload(file, filenane, source, target, uploadOptions);
57
+ const downloadOptions = {
58
+ outputFormat: options === null || options === void 0 ? void 0 : options.outputFormat,
59
+ };
60
+ const start = Date.now();
61
+ while (Date.now() - start < this.maxWaitTime) {
62
+ await sleep(this.pollingInterval);
63
+ const { status, errorReason } = await this.status(id);
64
+ if (status === DocumentStatus.TRANSLATED)
65
+ return await this.download(id, downloadOptions);
66
+ if (status === DocumentStatus.ERROR)
67
+ throw new LaraApiError(500, 'DocumentError', errorReason);
68
+ }
69
+ throw new TimeoutError();
70
+ }
71
+ }
@@ -0,0 +1,17 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { Glossary, GlossaryCounts, GlossaryImport, UploadableFile } from './models';
3
+ export default class Glossaries {
4
+ private readonly client;
5
+ private readonly pollingInterval;
6
+ constructor(client: AxiosInstance);
7
+ list(): Promise<Glossary[]>;
8
+ create(name: string): Promise<Glossary>;
9
+ get(id: string): Promise<Glossary>;
10
+ delete(id: string): Promise<Glossary>;
11
+ update(id: string, name: string): Promise<Glossary>;
12
+ importCsv(id: string, csv: UploadableFile, gzip?: boolean): Promise<GlossaryImport>;
13
+ getImportStatus(id: string): Promise<GlossaryImport>;
14
+ waitForImport(gImport: GlossaryImport, updateCallback?: (mImport: GlossaryImport) => void, maxWaitTime?: number): Promise<GlossaryImport>;
15
+ counts(id: string): Promise<GlossaryCounts>;
16
+ export(id: string, contentType: 'csv/table-uni', source?: string): Promise<string>;
17
+ }
@@ -0,0 +1,68 @@
1
+ import { TimeoutError } from './utils/errors';
2
+ import toFormData from './utils/formdata';
3
+ import sleep from './utils/sleep';
4
+ export default class Glossaries {
5
+ constructor(client) {
6
+ this.pollingInterval = 2000;
7
+ this.client = client;
8
+ }
9
+ async list() {
10
+ const { data } = await this.client.get('/v2/glossaries');
11
+ return data;
12
+ }
13
+ async create(name) {
14
+ const { data } = await this.client.post('/v2/glossaries', {
15
+ name,
16
+ });
17
+ return data;
18
+ }
19
+ async get(id) {
20
+ const { data } = await this.client.get(`/v2/glossaries/${id}`);
21
+ return data;
22
+ }
23
+ async delete(id) {
24
+ const { data } = await this.client.delete(`/v2/glossaries/${id}`);
25
+ return data;
26
+ }
27
+ async update(id, name) {
28
+ const { data } = await this.client.put(`/v2/glossaries/${id}`, { name });
29
+ return data;
30
+ }
31
+ async importCsv(id, csv, gzip = false) {
32
+ const [formData, headers] = toFormData({
33
+ csv,
34
+ compression: gzip ? 'gzip' : undefined,
35
+ });
36
+ const { data } = await this.client.post(`/v2/glossaries/${id}/import`, formData, { headers });
37
+ return data;
38
+ }
39
+ async getImportStatus(id) {
40
+ const { data } = await this.client.get(`/v2/glossaries/imports/${id}`);
41
+ return data;
42
+ }
43
+ async waitForImport(gImport, updateCallback, maxWaitTime) {
44
+ const start = Date.now();
45
+ while (gImport.progress < 1.0) {
46
+ if (maxWaitTime && Date.now() - start > maxWaitTime)
47
+ throw new TimeoutError();
48
+ await sleep(this.pollingInterval);
49
+ gImport = await this.getImportStatus(gImport.id);
50
+ updateCallback && updateCallback(gImport);
51
+ }
52
+ return gImport;
53
+ }
54
+ async counts(id) {
55
+ const { data } = await this.client.get(`/v2/glossaries/${id}/countes`);
56
+ return data;
57
+ }
58
+ // FIXME: this method should return a Blob or Buffer
59
+ async export(id, contentType, source) {
60
+ const { data } = await this.client.get(`/v2/glossaries/${id}/export`, {
61
+ data: {
62
+ content_type: contentType,
63
+ source: !!source ? source : undefined,
64
+ },
65
+ });
66
+ return data;
67
+ }
68
+ }
@@ -0,0 +1,18 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { Memory, MemoryImport, UploadableFile } from './models';
3
+ export default class Memories {
4
+ private readonly client;
5
+ private readonly pollingInterval;
6
+ constructor(client: AxiosInstance);
7
+ list(): Promise<Memory[]>;
8
+ create(name: string, externalId?: string): Promise<Memory>;
9
+ get(id: string): Promise<Memory>;
10
+ delete(id: string): Promise<Memory>;
11
+ update(id: string, name: string): Promise<Memory>;
12
+ addTranslation(id: string | string[], source: string, target: string, sentence: string, translation: string, tuid?: string, sentenceBefore?: string, sentenceAfter?: string, headers?: Record<string, any>): Promise<MemoryImport>;
13
+ deleteTranslation(id: string | string[], source: string, target: string, sentence?: string, translation?: string, tuid?: string, sentenceBefore?: string, sentenceAfter?: string): Promise<MemoryImport>;
14
+ importTmx(id: string, tmx: UploadableFile, gzip?: boolean): Promise<MemoryImport>;
15
+ getImportStatus(id: string): Promise<MemoryImport>;
16
+ waitForImport(mImport: MemoryImport, updateCallback?: (mImport: MemoryImport) => void, maxWaitTime?: number): Promise<MemoryImport>;
17
+ connect<T extends string | string[]>(ids: T): Promise<T extends string ? Memory : Memory[]>;
18
+ }
@@ -0,0 +1,95 @@
1
+ import { TimeoutError } from './utils/errors';
2
+ import toFormData from './utils/formdata';
3
+ import sleep from './utils/sleep';
4
+ export default class Memories {
5
+ constructor(client) {
6
+ this.pollingInterval = 2000;
7
+ this.client = client;
8
+ }
9
+ async list() {
10
+ const { data } = await this.client.get('/v2/memories');
11
+ return data;
12
+ }
13
+ async create(name, externalId) {
14
+ const { data } = await this.client.post('/v2/memories', {
15
+ name,
16
+ external_id: externalId,
17
+ });
18
+ return data;
19
+ }
20
+ async get(id) {
21
+ const { data } = await this.client.get(`/v2/memories/${id}`);
22
+ return data;
23
+ }
24
+ async delete(id) {
25
+ const { data } = await this.client.delete(`/v2/memories/${id}`);
26
+ return data;
27
+ }
28
+ async update(id, name) {
29
+ const { data } = await this.client.put(`/v2/memories/${id}`, { name });
30
+ return data;
31
+ }
32
+ async addTranslation(id, source, target, sentence, translation, tuid, sentenceBefore, sentenceAfter, headers) {
33
+ const url = Array.isArray(id) ? '/v2/memories/content' : `/v2/memories/${id}/content`;
34
+ const { data } = await this.client.put(url, {
35
+ ids: Array.isArray(id) ? id : undefined,
36
+ source,
37
+ target,
38
+ sentence,
39
+ translation,
40
+ tuid,
41
+ sentence_before: sentenceBefore,
42
+ sentence_after: sentenceAfter,
43
+ }, {
44
+ headers,
45
+ });
46
+ return data;
47
+ }
48
+ async deleteTranslation(id, source, target, sentence, translation, tuid, sentenceBefore, sentenceAfter) {
49
+ const url = Array.isArray(id) ? '/v2/memories/content' : `/v2/memories/${id}/content`;
50
+ const { data } = await this.client.delete(url, {
51
+ data: {
52
+ ids: Array.isArray(id) ? id : undefined,
53
+ source,
54
+ target,
55
+ sentence,
56
+ translation,
57
+ tuid,
58
+ sentence_before: sentenceBefore,
59
+ sentence_after: sentenceAfter,
60
+ },
61
+ });
62
+ return data;
63
+ }
64
+ async importTmx(id, tmx, gzip = false) {
65
+ const [formData, headers] = toFormData({
66
+ tmx,
67
+ compression: gzip ? 'gzip' : undefined,
68
+ });
69
+ const { data } = await this.client.post(`/v2/memories/${id}/import`, formData, {
70
+ headers,
71
+ });
72
+ return data;
73
+ }
74
+ async getImportStatus(id) {
75
+ const { data } = await this.client.get(`/v2/memories/imports/${id}`);
76
+ return data;
77
+ }
78
+ async waitForImport(mImport, updateCallback, maxWaitTime) {
79
+ const start = Date.now();
80
+ while (mImport.progress < 1.0) {
81
+ if (maxWaitTime && Date.now() - start > maxWaitTime)
82
+ throw new TimeoutError();
83
+ await sleep(this.pollingInterval);
84
+ mImport = await this.getImportStatus(mImport.id);
85
+ updateCallback && updateCallback(mImport);
86
+ }
87
+ return mImport;
88
+ }
89
+ async connect(ids) {
90
+ const { data } = await this.client.post('/v2/memories/connect', {
91
+ ids: Array.isArray(ids) ? ids : [ids],
92
+ });
93
+ return (Array.isArray(ids) ? data : data[0]);
94
+ }
95
+ }
@@ -0,0 +1,24 @@
1
+ import { AccessKey, Credentials, AuthToken, TranslatorOptions, TextBlock, TranslateOptions, TextResult } from './models';
2
+ import Memories from './Memories';
3
+ import Glossaries from './Glossaries';
4
+ import Documents from './Documents';
5
+ export declare class Translator {
6
+ private readonly accessKey?;
7
+ private readonly credentials?;
8
+ private authToken?;
9
+ readonly memories: Memories;
10
+ readonly glossaries: Glossaries;
11
+ readonly documents: Documents;
12
+ private token?;
13
+ private refreshToken?;
14
+ private readonly options?;
15
+ private readonly client;
16
+ constructor(accessKey?: AccessKey, credentials?: Credentials, authToken?: AuthToken, options?: TranslatorOptions);
17
+ private authenticate;
18
+ translate<T extends string | string[] | TextBlock[]>(text: T, source: string | null, target: string, options?: TranslateOptions): Promise<TextResult<T>>;
19
+ getLanguages(): Promise<string[]>;
20
+ static getLoginUrl(serverUrl?: string): Promise<string>;
21
+ static byAccessKey(id: string, secret: string, options?: TranslatorOptions): Translator;
22
+ static byCredentials(email: string, password: string, options?: TranslatorOptions): Translator;
23
+ static byAuthToken(token: string, refresh_token: string, options?: TranslatorOptions): Translator;
24
+ }
@@ -0,0 +1,152 @@
1
+ import axios from 'axios';
2
+ import Memories from './Memories';
3
+ import { version } from './sdk-version';
4
+ import Glossaries from './Glossaries';
5
+ import Documents from './Documents';
6
+ import toCamelCase from './utils/toCamelCase';
7
+ const DEFAULT_BASE_URL = 'https://api.laratranslate.com';
8
+ export class Translator {
9
+ constructor(accessKey, credentials, authToken, options) {
10
+ var _a;
11
+ this.accessKey = accessKey;
12
+ this.credentials = credentials;
13
+ this.authToken = authToken;
14
+ this.options = options || {};
15
+ this.client = axios.create({
16
+ baseURL: (_a = options === null || options === void 0 ? void 0 : options.serverUrl) !== null && _a !== void 0 ? _a : DEFAULT_BASE_URL,
17
+ headers: {
18
+ 'X-Lara-SDK-Name': 'lara-node',
19
+ 'X-Lara-SDK-Version': version,
20
+ 'X-Lara-Date': new Date().toUTCString(),
21
+ ...((options === null || options === void 0 ? void 0 : options.extraHeaders) || {}),
22
+ },
23
+ });
24
+ // Intercept request to add authentication header
25
+ this.client.interceptors.request.use(async (request) => {
26
+ const token = await this.authenticate();
27
+ request.headers.Authorization = `Bearer ${token}`;
28
+ return request;
29
+ }, Promise.reject);
30
+ // Intercepts errors to handle authentication errors
31
+ this.client.interceptors.response.use((response) => {
32
+ response.data && console.log(response.data);
33
+ // Convert payload in camel case if needed
34
+ if (response.data && typeof response.data === 'object') {
35
+ response.data = toCamelCase(response.data);
36
+ }
37
+ return response;
38
+ }, async (error) => {
39
+ const originalRequest = error.config;
40
+ if (originalRequest.isRetry)
41
+ return Promise.reject(error);
42
+ if (error.response && error.response.status === 401 && error.response.message === 'jwt expired') {
43
+ this.token = undefined;
44
+ const token = await this.authenticate();
45
+ originalRequest.isRetry = true;
46
+ originalRequest.headers.Authorization = `Bearer ${token}`;
47
+ return this.client(originalRequest);
48
+ }
49
+ return Promise.reject(error);
50
+ });
51
+ this.memories = new Memories(this.client);
52
+ this.glossaries = new Glossaries(this.client);
53
+ this.documents = new Documents(this.client);
54
+ }
55
+ async authenticate() {
56
+ var _a, _b, _c, _d, _e, _f;
57
+ // If the token is set, return it
58
+ if (this.token)
59
+ return this.token;
60
+ // If we have a refresh token, use it to get a new token
61
+ if (this.refreshToken) {
62
+ const { data } = await axios.post(`${(_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.serverUrl) !== null && _b !== void 0 ? _b : DEFAULT_BASE_URL}/v2/auth/refresh`, null, {
63
+ headers: {
64
+ authorization: `Bearer ${this.refreshToken}`,
65
+ 'X-Lara-Date': new Date().toUTCString(),
66
+ },
67
+ });
68
+ this.token = data.token;
69
+ this.refreshToken = data.refresh_token;
70
+ return this.token;
71
+ }
72
+ else if (this.accessKey) {
73
+ // Use access key to get a new token
74
+ const { data } = await axios.post(`${(_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.serverUrl) !== null && _d !== void 0 ? _d : DEFAULT_BASE_URL}/v2/auth`, this.accessKey, {
75
+ headers: {
76
+ 'X-Lara-Date': new Date().toUTCString(),
77
+ },
78
+ });
79
+ this.token = data.token;
80
+ this.refreshToken = data.refresh_token;
81
+ return this.token;
82
+ }
83
+ else if (this.credentials) {
84
+ // Use credentials to get a new token
85
+ const { data } = await axios.post(
86
+ //FIXME: client id should be set
87
+ `${(_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.serverUrl) !== null && _f !== void 0 ? _f : DEFAULT_BASE_URL}/v2/auth/Unknown/login`, this.credentials, {
88
+ headers: {
89
+ 'X-Lara-Date': new Date().toUTCString(),
90
+ },
91
+ });
92
+ this.token = data.token;
93
+ this.refreshToken = data.refresh_token;
94
+ return this.token;
95
+ }
96
+ else if (this.authToken) {
97
+ // Use the provided auth token
98
+ this.token = this.authToken.token;
99
+ this.refreshToken = this.authToken.refresh_token;
100
+ this.authToken = undefined;
101
+ return this.token;
102
+ }
103
+ else {
104
+ throw new Error('No authentication method provided');
105
+ }
106
+ }
107
+ async translate(text, source, target, options) {
108
+ const headers = {};
109
+ if (options === null || options === void 0 ? void 0 : options.headers) {
110
+ for (const [name, value] of Object.entries(options.headers)) {
111
+ headers[name] = value;
112
+ }
113
+ }
114
+ if (options === null || options === void 0 ? void 0 : options.noTrace)
115
+ headers['X-No-Trace'] = 'true';
116
+ const { data } = await this.client.post(`/v2/translate`, {
117
+ q: text,
118
+ source: !!source ? source : undefined,
119
+ target,
120
+ source_hint: options === null || options === void 0 ? void 0 : options.sourceHint,
121
+ content_type: options === null || options === void 0 ? void 0 : options.contentType,
122
+ multiline: (options === null || options === void 0 ? void 0 : options.multiline) !== false,
123
+ adapt_to: options === null || options === void 0 ? void 0 : options.adaptTo,
124
+ glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
125
+ instructions: options === null || options === void 0 ? void 0 : options.instructions,
126
+ timeout: options === null || options === void 0 ? void 0 : options.timeoutInMillis,
127
+ priority: options === null || options === void 0 ? void 0 : options.priority,
128
+ use_cache: options === null || options === void 0 ? void 0 : options.useCache,
129
+ cache_ttl: options === null || options === void 0 ? void 0 : options.cacheTTLSeconds,
130
+ verbose: options === null || options === void 0 ? void 0 : options.verbose,
131
+ style: options === null || options === void 0 ? void 0 : options.style,
132
+ }, headers);
133
+ return data;
134
+ }
135
+ async getLanguages() {
136
+ const { data } = await this.client.get(`/v2/languages`);
137
+ return data;
138
+ }
139
+ static async getLoginUrl(serverUrl) {
140
+ const { data } = await axios.get(`${serverUrl !== null && serverUrl !== void 0 ? serverUrl : DEFAULT_BASE_URL}/v2/auth/login-page`);
141
+ return data;
142
+ }
143
+ static byAccessKey(id, secret, options) {
144
+ return new Translator({ id, secret }, undefined, undefined, options);
145
+ }
146
+ static byCredentials(email, password, options) {
147
+ return new Translator(undefined, { email, password }, undefined, options);
148
+ }
149
+ static byAuthToken(token, refresh_token, options) {
150
+ return new Translator(undefined, undefined, { token, refresh_token }, options);
151
+ }
152
+ }
package/lib/index.d.ts CHANGED
@@ -1,6 +1,2 @@
1
- export { Credentials } from "./credentials";
2
- export { LaraApiError, LaraError, TimeoutError } from "./errors";
3
- export { MultiPartFile } from "./net/client";
4
- export { version } from "./sdk-version";
5
- export { Document, DocumentDownloadOptions, DocumentStatus, DocumentUploadOptions, Memory, MemoryImport, NGGlossaryMatch, NGMemoryMatch, TextBlock, TextResult } from "./translator/models";
6
- export { Documents, DocumentTranslateOptions, Memories, MemoryImportCallback, TranslateOptions, Translator, TranslatorOptions } from "./translator/translator";
1
+ export * from './Translator';
2
+ export * from './models';
package/lib/index.js CHANGED
@@ -1,17 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Translator = exports.Memories = exports.Documents = exports.DocumentStatus = exports.version = exports.TimeoutError = exports.LaraError = exports.LaraApiError = exports.Credentials = void 0;
4
- var credentials_1 = require("./credentials");
5
- Object.defineProperty(exports, "Credentials", { enumerable: true, get: function () { return credentials_1.Credentials; } });
6
- var errors_1 = require("./errors");
7
- Object.defineProperty(exports, "LaraApiError", { enumerable: true, get: function () { return errors_1.LaraApiError; } });
8
- Object.defineProperty(exports, "LaraError", { enumerable: true, get: function () { return errors_1.LaraError; } });
9
- Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
10
- var sdk_version_1 = require("./sdk-version");
11
- Object.defineProperty(exports, "version", { enumerable: true, get: function () { return sdk_version_1.version; } });
12
- var models_1 = require("./translator/models");
13
- Object.defineProperty(exports, "DocumentStatus", { enumerable: true, get: function () { return models_1.DocumentStatus; } });
14
- var translator_1 = require("./translator/translator");
15
- Object.defineProperty(exports, "Documents", { enumerable: true, get: function () { return translator_1.Documents; } });
16
- Object.defineProperty(exports, "Memories", { enumerable: true, get: function () { return translator_1.Memories; } });
17
- Object.defineProperty(exports, "Translator", { enumerable: true, get: function () { return translator_1.Translator; } });
1
+ export * from './Translator';
2
+ export * from './models';
@@ -0,0 +1,12 @@
1
+ export type AccessKey = {
2
+ id: string;
3
+ secret: string;
4
+ };
5
+ export type AuthToken = {
6
+ token: string;
7
+ refresh_token: string;
8
+ };
9
+ export type Credentials = {
10
+ email: string;
11
+ password: string;
12
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type UploadableFile = File | import('stream').Readable;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import { TranslationStyle } from './translator';
2
+ export interface Document {
3
+ readonly id: string;
4
+ readonly status: DocumentStatus;
5
+ readonly source?: string;
6
+ readonly target: string;
7
+ readonly filename: string;
8
+ readonly createdAt: Date;
9
+ readonly updatedAt: Date;
10
+ readonly options?: DocumentOptions;
11
+ readonly translatedChars?: number;
12
+ readonly totalChars?: number;
13
+ readonly errorReason?: string;
14
+ }
15
+ export declare enum DocumentStatus {
16
+ INITIALIZED = "initialized",// just been created
17
+ ANALYZING = "analyzing",// being analyzed for language detection and chars count
18
+ PAUSED = "paused",// paused after analysis, needs user confirm
19
+ READY = "ready",// ready to be translated
20
+ TRANSLATING = "translating",
21
+ TRANSLATED = "translated",
22
+ ERROR = "error"
23
+ }
24
+ export type DocumentOptions = {
25
+ adaptTo?: string[];
26
+ glossaries?: string[];
27
+ noTrace?: boolean;
28
+ style?: TranslationStyle;
29
+ };
30
+ export type DocumentUploadOptions = DocumentOptions & {
31
+ password?: string;
32
+ extractionParams?: DocxExtractionParams;
33
+ };
34
+ export type DocumentDownloadOptions = {
35
+ outputFormat?: string;
36
+ };
37
+ export type DocumentTranslateOptions = DocumentUploadOptions & DocumentDownloadOptions;
38
+ export interface DocxExtractionParams {
39
+ extractComments?: boolean;
40
+ accepsRevisions?: boolean;
41
+ }
42
+ interface S3UploadFields {
43
+ acl: string;
44
+ bucket: string;
45
+ key: string;
46
+ }
47
+ export interface UploadUrlData {
48
+ url: string;
49
+ fields: S3UploadFields;
50
+ }
51
+ export {};
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentStatus = void 0;
4
- // biome-ignore format: keep comments aligned
5
- var DocumentStatus;
1
+ export var DocumentStatus;
6
2
  (function (DocumentStatus) {
7
3
  DocumentStatus["INITIALIZED"] = "initialized";
8
4
  DocumentStatus["ANALYZING"] = "analyzing";
@@ -11,4 +7,4 @@ var DocumentStatus;
11
7
  DocumentStatus["TRANSLATING"] = "translating";
12
8
  DocumentStatus["TRANSLATED"] = "translated";
13
9
  DocumentStatus["ERROR"] = "error";
14
- })(DocumentStatus || (exports.DocumentStatus = DocumentStatus = {}));
10
+ })(DocumentStatus || (DocumentStatus = {}));
@@ -0,0 +1,19 @@
1
+ export interface Glossary {
2
+ readonly id: string;
3
+ readonly name: string;
4
+ readonly ownerId: string;
5
+ readonly createdAt: Date;
6
+ readonly updatedAt: Date;
7
+ }
8
+ export interface GlossaryImport {
9
+ readonly id: string;
10
+ readonly begin: number;
11
+ readonly end: number;
12
+ readonly channel: number;
13
+ readonly size: number;
14
+ readonly progress: number;
15
+ }
16
+ export interface GlossaryCounts {
17
+ unidirectional?: Record<string, number>;
18
+ multidirectional?: number;
19
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export * from './Authentication';
2
+ export * from './documents';
3
+ export * from './glossaries';
4
+ export * from './memories';
5
+ export * from './translator';
6
+ export * from './UploadableFile';
@@ -0,0 +1,6 @@
1
+ export * from './Authentication';
2
+ export * from './documents';
3
+ export * from './glossaries';
4
+ export * from './memories';
5
+ export * from './translator';
6
+ export * from './UploadableFile';
@@ -0,0 +1,19 @@
1
+ export interface Memory {
2
+ readonly id: string;
3
+ readonly createdAt: Date;
4
+ readonly updatedAt: Date;
5
+ readonly sharedAt: Date;
6
+ readonly name: string;
7
+ readonly externalId?: string;
8
+ readonly secret?: string;
9
+ readonly ownerId: string;
10
+ readonly collaboratorsCount: number;
11
+ }
12
+ export interface MemoryImport {
13
+ readonly id: string;
14
+ readonly begin: number;
15
+ readonly end: number;
16
+ readonly channel: number;
17
+ readonly size: number;
18
+ readonly progress: number;
19
+ }
@@ -0,0 +1 @@
1
+ export {};