@translated/lara 2.0.0-beta.1 → 2.0.0-beta.3

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.
@@ -1,12 +1,12 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { Document, DocumentDownloadOptions, DocumentTranslateOptions, DocumentUploadOptions, UploadableFile } from './models';
2
+ import { Document, DocumentDownloadOptions, DocumentTranslateOptions, DocumentUploadOptions, DownloadResult, UploadableFile } from './models';
3
3
  export default class Documents {
4
4
  private readonly client;
5
5
  private readonly pollingInterval;
6
6
  private readonly maxWaitTime;
7
7
  constructor(client: AxiosInstance);
8
- upload(file: UploadableFile, filenane: string, source: string | null, target: string, options?: DocumentUploadOptions): Promise<Document>;
8
+ upload(file: UploadableFile, filenane: string, source: string | undefined, target: string, options?: DocumentUploadOptions): Promise<Document>;
9
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>;
10
+ download(id: string, options?: DocumentDownloadOptions): Promise<DownloadResult>;
11
+ translate(file: UploadableFile, filenane: string, source: string | undefined, target: string, options?: DocumentTranslateOptions): Promise<DownloadResult>;
12
12
  }
package/lib/Documents.js CHANGED
@@ -4,6 +4,8 @@ import toFormData from './utils/formdata';
4
4
  import toSnakeCase from './utils/toSnakeCase';
5
5
  import sleep from './utils/sleep';
6
6
  import { LaraApiError, TimeoutError } from './utils/errors';
7
+ import toQueryString from './utils/toQueryString';
8
+ import isNode from './utils/isNode';
7
9
  export default class Documents {
8
10
  constructor(client) {
9
11
  this.pollingInterval = 2000;
@@ -14,8 +16,8 @@ export default class Documents {
14
16
  const { data: s3UploadUrlData } = await this.client.get(`/v2/documents/upload-url?filename=${encodeURIComponent(filenane)}`);
15
17
  const { url, fields } = s3UploadUrlData;
16
18
  const [formData, headers] = toFormData({
17
- file,
18
19
  ...fields,
20
+ file,
19
21
  });
20
22
  await axios.post(url, formData, { headers });
21
23
  const noTraceHeader = (options === null || options === void 0 ? void 0 : options.noTrace) ? { 'X-Lara-No-Trace': 'true' } : undefined;
@@ -36,13 +38,22 @@ export default class Documents {
36
38
  return data;
37
39
  }
38
40
  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
- },
41
+ const queryString = toQueryString({
42
+ output_format: options === null || options === void 0 ? void 0 : options.outputFormat,
43
43
  });
44
- const { data: downloadedData } = await axios.get(data.url);
45
- return downloadedData;
44
+ const { data } = await this.client.get(`/v2/documents/${id}/download-url?${queryString}`);
45
+ if (isNode) {
46
+ const { data: downloadedData } = await axios.get(data.url, {
47
+ responseType: 'stream',
48
+ });
49
+ return downloadedData;
50
+ }
51
+ else {
52
+ const { data: downloadedData } = await axios.get(data.url, {
53
+ responseType: 'blob',
54
+ });
55
+ return downloadedData.stream();
56
+ }
46
57
  }
47
58
  async translate(file, filenane, source, target, options) {
48
59
  const uploadOptions = {
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { Glossary, GlossaryCounts, GlossaryImport, UploadableFile } from './models';
2
+ import { DownloadResult, Glossary, GlossaryCounts, GlossaryImport, UploadableFile } from './models';
3
3
  export default class Glossaries {
4
4
  private readonly client;
5
5
  private readonly pollingInterval;
@@ -13,5 +13,5 @@ export default class Glossaries {
13
13
  getImportStatus(id: string): Promise<GlossaryImport>;
14
14
  waitForImport(gImport: GlossaryImport, updateCallback?: (mImport: GlossaryImport) => void, maxWaitTime?: number): Promise<GlossaryImport>;
15
15
  counts(id: string): Promise<GlossaryCounts>;
16
- export(id: string, contentType: 'csv/table-uni', source?: string): Promise<string>;
16
+ export(id: string, contentType: 'csv/table-uni', source?: string): Promise<DownloadResult>;
17
17
  }
package/lib/Glossaries.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { TimeoutError } from './utils/errors';
2
2
  import toFormData from './utils/formdata';
3
3
  import sleep from './utils/sleep';
4
+ import toQueryString from './utils/toQueryString';
5
+ import isNode from './utils/isNode';
4
6
  export default class Glossaries {
5
7
  constructor(client) {
6
8
  this.pollingInterval = 2000;
@@ -52,17 +54,25 @@ export default class Glossaries {
52
54
  return gImport;
53
55
  }
54
56
  async counts(id) {
55
- const { data } = await this.client.get(`/v2/glossaries/${id}/countes`);
57
+ const { data } = await this.client.get(`/v2/glossaries/${id}/counts`);
56
58
  return data;
57
59
  }
58
- // FIXME: this method should return a Blob or Buffer
59
60
  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
- },
61
+ const queryString = toQueryString({
62
+ content_type: contentType,
63
+ source,
65
64
  });
66
- return data;
65
+ if (isNode) {
66
+ const { data } = await this.client.get(`/v2/glossaries/${id}/export?${queryString}`, {
67
+ responseType: 'stream',
68
+ });
69
+ return data;
70
+ }
71
+ else {
72
+ const { data } = await this.client.get(`/v2/glossaries/${id}/export?${queryString}`, {
73
+ responseType: 'blob',
74
+ });
75
+ return data.stream();
76
+ }
67
77
  }
68
78
  }
package/lib/Translator.js CHANGED
@@ -30,7 +30,7 @@ export class Translator {
30
30
  // Intercepts errors to handle authentication errors
31
31
  this.client.interceptors.response.use((response) => {
32
32
  // Convert payload in camel case if needed
33
- if (response.data && typeof response.data === 'object') {
33
+ if (response.config.responseType !== 'stream' && response.data && typeof response.data === 'object') {
34
34
  response.data = toCamelCase(response.data);
35
35
  }
36
36
  return response;
@@ -1 +1,2 @@
1
1
  export type UploadableFile = File | import('stream').Readable;
2
+ export type DownloadResult = ReadableStream<Uint8Array> | import('stream').Readable;
@@ -1 +1 @@
1
- export declare const version = "1.6.6";
1
+ export declare const version = "2.0.0-beta.1";
@@ -1 +1 @@
1
- export const version = "1.6.6";
1
+ export const version = '2.0.0-beta.1';
@@ -0,0 +1,2 @@
1
+ declare const _default: boolean;
2
+ export default _default;
@@ -0,0 +1 @@
1
+ export default typeof window === 'undefined';
@@ -0,0 +1,2 @@
1
+ declare const _default: (params: Record<string, any>) => string;
2
+ export default _default;
@@ -0,0 +1,8 @@
1
+ export default (params) => Object.entries(params)
2
+ .reduce((acc, [key, value]) => {
3
+ if (value !== undefined && value !== null) {
4
+ acc.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
5
+ }
6
+ return acc;
7
+ }, [])
8
+ .join('&');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@translated/lara",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.3",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "engines": {