@translated/lara 1.5.1 → 1.5.2
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.
- package/lib/net/client.d.ts +5 -5
- package/lib/net/client.js +18 -17
- package/lib/sdk-version.d.ts +1 -1
- package/lib/sdk-version.js +1 -1
- package/package.json +1 -1
package/lib/net/client.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
80
|
+
_headers["Content-Type"] = "multipart/form-data";
|
|
80
81
|
requestBody = Object.assign({}, files, body);
|
|
81
82
|
}
|
|
82
83
|
else {
|
|
83
|
-
|
|
84
|
+
_headers["Content-Type"] = "application/json";
|
|
84
85
|
if (body)
|
|
85
86
|
requestBody = body;
|
|
86
87
|
}
|
|
87
|
-
const signature = await this.sign(method, path,
|
|
88
|
-
|
|
89
|
-
const response = await this.send(path,
|
|
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
|
}
|
package/lib/sdk-version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.5.
|
|
1
|
+
export declare const version = "1.5.2";
|
package/lib/sdk-version.js
CHANGED