@translated/lara 1.5.1 → 1.5.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.
@@ -15,6 +15,7 @@ class BrowserLaraClient extends client_1.LaraClient {
15
15
  this.baseUrl = url;
16
16
  }
17
17
  async send(path, headers, body) {
18
+ var _a;
18
19
  let requestBody = undefined;
19
20
  if (body) {
20
21
  if (headers["Content-Type"] === "multipart/form-data") {
@@ -39,6 +40,14 @@ class BrowserLaraClient extends client_1.LaraClient {
39
40
  method: "POST",
40
41
  body: requestBody
41
42
  });
43
+ if ((_a = response.headers.get("Content-Type")) === null || _a === void 0 ? void 0 : _a.includes("text/csv")) {
44
+ return {
45
+ statusCode: response.status,
46
+ body: {
47
+ content: await response.text()
48
+ }
49
+ };
50
+ }
42
51
  return { statusCode: response.status, body: await response.json() };
43
52
  }
44
53
  wrapMultiPartFile(file) {
@@ -22,11 +22,11 @@ export declare abstract class LaraClient {
22
22
  private readonly extraHeaders;
23
23
  protected constructor(accessKeyId: string, accessKeySecret: string);
24
24
  setExtraHeader(name: string, value: string): void;
25
- get<T>(path: string, params?: Record<string, any>): Promise<T>;
26
- delete<T>(path: string, params?: Record<string, any>): Promise<T>;
27
- post<T>(path: string, body?: Record<string, any>, files?: Record<string, MultiPartFile>): Promise<T>;
28
- put<T>(path: string, body?: Record<string, any>, files?: Record<string, MultiPartFile>): Promise<T>;
29
- protected request<T>(method: HttpMethod, path: string, body?: Record<string, any>, files?: Record<string, MultiPartFile>): Promise<T>;
25
+ get<T>(path: string, params?: Record<string, any>, headers?: Record<string, string>): Promise<T>;
26
+ delete<T>(path: string, params?: Record<string, any>, headers?: Record<string, string>): Promise<T>;
27
+ post<T>(path: string, body?: Record<string, any>, files?: Record<string, MultiPartFile>, headers?: Record<string, string>): Promise<T>;
28
+ put<T>(path: string, body?: Record<string, any>, files?: Record<string, MultiPartFile>, headers?: Record<string, string>): Promise<T>;
29
+ protected request<T>(method: HttpMethod, path: string, body?: Record<string, any>, files?: Record<string, MultiPartFile>, headers?: Record<string, string>): Promise<T>;
30
30
  private sign;
31
31
  protected abstract send(path: string, headers: Record<string, string>, body?: Record<string, any>): Promise<ClientResponse>;
32
32
  protected abstract wrapMultiPartFile(file: MultiPartFile): any;
package/lib/net/client.js CHANGED
@@ -40,27 +40,28 @@ class LaraClient {
40
40
  setExtraHeader(name, value) {
41
41
  this.extraHeaders[name] = value;
42
42
  }
43
- get(path, params) {
44
- return this.request("GET", path, params);
43
+ get(path, params, headers) {
44
+ return this.request("GET", path, params, undefined, headers);
45
45
  }
46
- delete(path, params) {
47
- return this.request("DELETE", path, params);
46
+ delete(path, params, headers) {
47
+ return this.request("DELETE", path, params, undefined, headers);
48
48
  }
49
- post(path, body, files) {
50
- return this.request("POST", path, body, files);
49
+ post(path, body, files, headers) {
50
+ return this.request("POST", path, body, files, headers);
51
51
  }
52
- put(path, body, files) {
53
- return this.request("PUT", path, body, files);
52
+ put(path, body, files, headers) {
53
+ return this.request("PUT", path, body, files, headers);
54
54
  }
55
- async request(method, path, body, files) {
55
+ async request(method, path, body, files, headers) {
56
56
  if (!path.startsWith("/"))
57
57
  path = "/" + path;
58
- const headers = {
58
+ const _headers = {
59
59
  "X-HTTP-Method-Override": method,
60
60
  "X-Lara-Date": new Date().toUTCString(),
61
61
  "X-Lara-SDK-Name": "lara-node",
62
62
  'X-Lara-SDK-Version': sdk_version_1.version,
63
- ...this.extraHeaders
63
+ ...this.extraHeaders,
64
+ ...headers
64
65
  };
65
66
  if (body) {
66
67
  body = Object.fromEntries(Object.entries(body).filter(([_, v]) => v !== undefined && v !== null));
@@ -68,7 +69,7 @@ class LaraClient {
68
69
  body = undefined;
69
70
  if (body) {
70
71
  const jsonBody = JSON.stringify(body, undefined, 0);
71
- headers["Content-MD5"] = await this.crypto.digest(jsonBody);
72
+ _headers["Content-MD5"] = await this.crypto.digest(jsonBody);
72
73
  }
73
74
  }
74
75
  let requestBody = undefined;
@@ -76,17 +77,17 @@ class LaraClient {
76
77
  // validate files
77
78
  for (const [key, file] of Object.entries(files))
78
79
  files[key] = this.wrapMultiPartFile(file);
79
- headers["Content-Type"] = "multipart/form-data";
80
+ _headers["Content-Type"] = "multipart/form-data";
80
81
  requestBody = Object.assign({}, files, body);
81
82
  }
82
83
  else {
83
- headers["Content-Type"] = "application/json";
84
+ _headers["Content-Type"] = "application/json";
84
85
  if (body)
85
86
  requestBody = body;
86
87
  }
87
- const signature = await this.sign(method, path, headers);
88
- headers["Authorization"] = `Lara ${this.accessKeyId}:${signature}`;
89
- const response = await this.send(path, headers, requestBody);
88
+ const signature = await this.sign(method, path, _headers);
89
+ _headers["Authorization"] = `Lara ${this.accessKeyId}:${signature}`;
90
+ const response = await this.send(path, _headers, requestBody);
90
91
  if (200 <= response.statusCode && response.statusCode < 300) {
91
92
  return parseContent(response.body.content);
92
93
  }
@@ -1,5 +1,5 @@
1
- import { BaseURL, ClientResponse, LaraClient, MultiPartFile } from "./client";
2
1
  import { Readable } from "stream";
2
+ import { BaseURL, ClientResponse, LaraClient, MultiPartFile } from "./client";
3
3
  /** @internal */
4
4
  export declare class NodeLaraClient extends LaraClient {
5
5
  private readonly baseUrl;
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.NodeLaraClient = void 0;
7
+ const form_data_1 = __importDefault(require("form-data"));
8
+ const fs_1 = __importDefault(require("fs"));
7
9
  const http_1 = __importDefault(require("http"));
8
10
  const https_1 = __importDefault(require("https"));
9
- const form_data_1 = __importDefault(require("form-data"));
10
- const client_1 = require("./client");
11
11
  const stream_1 = require("stream");
12
- const fs_1 = __importDefault(require("fs"));
12
+ const client_1 = require("./client");
13
13
  /** @internal */
14
14
  class NodeLaraClient extends client_1.LaraClient {
15
15
  constructor(baseUrl, accessKeyId, accessKeySecret) {
@@ -53,7 +53,16 @@ class NodeLaraClient extends client_1.LaraClient {
53
53
  let data = "";
54
54
  res.on("data", (chunk) => data += chunk);
55
55
  res.on("end", () => {
56
+ var _a;
56
57
  let json;
58
+ if ((_a = res.headers['content-type']) === null || _a === void 0 ? void 0 : _a.includes('text/csv')) {
59
+ return resolve({
60
+ statusCode: res.statusCode,
61
+ body: {
62
+ content: data
63
+ }
64
+ });
65
+ }
57
66
  try {
58
67
  json = JSON.parse(data);
59
68
  }
@@ -1 +1 @@
1
- export declare const version = "1.5.1";
1
+ export declare const version = "1.5.3";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- exports.version = "1.5.1";
4
+ exports.version = "1.5.3";
@@ -45,8 +45,8 @@ export declare class Documents {
45
45
  constructor(client: LaraClient);
46
46
  upload(file: MultiPartFile, filename: string, source: string | null, target: string, options?: DocumentUploadOptions): Promise<Document>;
47
47
  status(id: string): Promise<Document>;
48
- download(id: string, options?: DocumentDownloadOptions): Promise<Blob | Buffer<ArrayBufferLike>>;
49
- translate(file: MultiPartFile, filename: string, source: string | null, target: string, options?: DocumentTranslateOptions): Promise<Blob | Buffer<ArrayBufferLike>>;
48
+ download(id: string, options?: DocumentDownloadOptions): Promise<Blob | Buffer>;
49
+ translate(file: MultiPartFile, filename: string, source: string | null, target: string, options?: DocumentTranslateOptions): Promise<Blob | Buffer>;
50
50
  }
51
51
  export declare class Translator {
52
52
  protected readonly client: LaraClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@translated/lara",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "engines": {