@translated/lara 1.6.5 → 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.
- package/README.md +360 -2
- package/lib/Documents.d.ts +12 -0
- package/lib/Documents.js +71 -0
- package/lib/Glossaries.d.ts +17 -0
- package/lib/Glossaries.js +68 -0
- package/lib/Memories.d.ts +18 -0
- package/lib/Memories.js +95 -0
- package/lib/Translator.d.ts +24 -0
- package/lib/Translator.js +152 -0
- package/lib/index.d.ts +2 -6
- package/lib/index.js +2 -17
- package/lib/models/Authentication.d.ts +12 -0
- package/lib/models/Authentication.js +1 -0
- package/lib/models/UploadableFile.d.ts +1 -0
- package/lib/models/UploadableFile.js +1 -0
- package/lib/models/documents.d.ts +51 -0
- package/lib/{translator/models.js → models/documents.js} +2 -6
- package/lib/models/glossaries.d.ts +19 -0
- package/lib/models/glossaries.js +1 -0
- package/lib/models/index.d.ts +6 -0
- package/lib/models/index.js +6 -0
- package/lib/models/memories.d.ts +19 -0
- package/lib/models/memories.js +1 -0
- package/lib/models/translator.d.ts +48 -0
- package/lib/models/translator.js +1 -0
- package/lib/sdk-version.d.ts +1 -1
- package/lib/sdk-version.js +1 -4
- package/lib/utils/errors.js +12 -0
- package/lib/utils/formdata/browser.d.ts +2 -0
- package/lib/utils/formdata/browser.js +15 -0
- package/lib/utils/formdata/index.d.ts +4 -0
- package/lib/utils/formdata/index.js +10 -0
- package/lib/utils/formdata/node.d.ts +5 -0
- package/lib/utils/formdata/node.js +16 -0
- package/lib/utils/sleep.d.ts +2 -0
- package/lib/utils/sleep.js +1 -0
- package/lib/utils/toCamelCase.d.ts +2 -0
- package/lib/utils/toCamelCase.js +16 -0
- package/lib/utils/toSnakeCase.d.ts +2 -0
- package/lib/utils/toSnakeCase.js +16 -0
- package/package.json +23 -13
- package/lib/credentials.d.ts +0 -5
- package/lib/credentials.js +0 -10
- package/lib/crypto/browser-crypto.d.ts +0 -11
- package/lib/crypto/browser-crypto.js +0 -28
- package/lib/crypto/index.d.ts +0 -3
- package/lib/crypto/index.js +0 -15
- package/lib/crypto/node-crypto.d.ts +0 -6
- package/lib/crypto/node-crypto.js +0 -55
- package/lib/crypto/portable-crypto.d.ts +0 -5
- package/lib/crypto/portable-crypto.js +0 -2
- package/lib/errors.js +0 -18
- package/lib/net/browser-client.d.ts +0 -8
- package/lib/net/browser-client.js +0 -59
- package/lib/net/client.d.ts +0 -34
- package/lib/net/client.js +0 -108
- package/lib/net/index.d.ts +0 -3
- package/lib/net/index.js +0 -23
- package/lib/net/node-client.d.ts +0 -10
- package/lib/net/node-client.js +0 -100
- package/lib/net/s3/browser-client.d.ts +0 -9
- package/lib/net/s3/browser-client.js +0 -28
- package/lib/net/s3/client.d.ts +0 -9
- package/lib/net/s3/client.js +0 -10
- package/lib/net/s3/index.d.ts +0 -3
- package/lib/net/s3/index.js +0 -13
- package/lib/net/s3/node-client.d.ts +0 -10
- package/lib/net/s3/node-client.js +0 -47
- package/lib/translator/models.d.ts +0 -99
- package/lib/translator/translator.d.ts +0 -80
- package/lib/translator/translator.js +0 -260
- /package/lib/{errors.d.ts → utils/errors.d.ts} +0 -0
|
@@ -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
|
|
2
|
-
export
|
|
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
|
-
|
|
2
|
-
|
|
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 @@
|
|
|
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
|
-
|
|
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 || (
|
|
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,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 {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface TranslatorOptions {
|
|
2
|
+
serverUrl?: string;
|
|
3
|
+
extraHeaders?: Record<string, any>;
|
|
4
|
+
}
|
|
5
|
+
export interface TextBlock {
|
|
6
|
+
readonly text: string;
|
|
7
|
+
readonly translatable?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type TranslationStyle = 'faithful' | 'fluid' | 'creative';
|
|
10
|
+
export type TranslateOptions = {
|
|
11
|
+
sourceHint?: string;
|
|
12
|
+
adaptTo?: string[];
|
|
13
|
+
instructions?: string[];
|
|
14
|
+
glossaries?: string[];
|
|
15
|
+
contentType?: string;
|
|
16
|
+
multiline?: boolean;
|
|
17
|
+
timeoutInMillis?: number;
|
|
18
|
+
priority?: 'normal' | 'background';
|
|
19
|
+
useCache?: boolean | 'overwrite';
|
|
20
|
+
cacheTTLSeconds?: number;
|
|
21
|
+
noTrace?: boolean;
|
|
22
|
+
verbose?: boolean;
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
style?: TranslationStyle;
|
|
25
|
+
};
|
|
26
|
+
export interface NGMemoryMatch {
|
|
27
|
+
memory: string;
|
|
28
|
+
tuid?: string;
|
|
29
|
+
language: [string, string];
|
|
30
|
+
sentence: string;
|
|
31
|
+
translation: string;
|
|
32
|
+
score: number;
|
|
33
|
+
}
|
|
34
|
+
export interface NGGlossaryMatch {
|
|
35
|
+
glossary: string;
|
|
36
|
+
language: [string, string];
|
|
37
|
+
term: string;
|
|
38
|
+
translation: string;
|
|
39
|
+
}
|
|
40
|
+
export interface TextResult<T extends string | string[] | TextBlock[]> {
|
|
41
|
+
readonly contentType: string;
|
|
42
|
+
readonly sourceLanguage: string;
|
|
43
|
+
readonly translation: T;
|
|
44
|
+
readonly adaptedTo?: string[];
|
|
45
|
+
readonly glossaries?: string[];
|
|
46
|
+
readonly adaptedToMatches?: NGMemoryMatch[] | NGMemoryMatch[][];
|
|
47
|
+
readonly glossariesMatches?: NGGlossaryMatch[] | NGGlossaryMatch[][];
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/sdk-version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.6.
|
|
1
|
+
export declare const version = "1.6.6";
|
package/lib/sdk-version.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class LaraError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export class TimeoutError extends LaraError {
|
|
4
|
+
}
|
|
5
|
+
export class LaraApiError extends LaraError {
|
|
6
|
+
constructor(statusCode, type, message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.type = type;
|
|
10
|
+
this.message = message;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default (data) => {
|
|
2
|
+
const formData = new FormData();
|
|
3
|
+
for (const [key, value] of Object.entries(data)) {
|
|
4
|
+
if (!value)
|
|
5
|
+
continue;
|
|
6
|
+
if (Array.isArray(value)) {
|
|
7
|
+
for (const v of value)
|
|
8
|
+
formData.append(key, v);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
formData.append(key, value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return [formData, {}];
|
|
15
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import FormData from 'form-data';
|
|
2
|
+
export default (data) => {
|
|
3
|
+
const formData = new FormData();
|
|
4
|
+
for (const [key, value] of Object.entries(data)) {
|
|
5
|
+
if (!value)
|
|
6
|
+
continue;
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
for (const v of value)
|
|
9
|
+
formData.append(key, v);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
formData.append(key, value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return [formData, { ...formData.getHeaders() }];
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default (millis) => new Promise((resolve) => setTimeout(resolve, millis));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const toCamelCase = (content) => {
|
|
2
|
+
if (typeof content === 'string')
|
|
3
|
+
return content;
|
|
4
|
+
if (Array.isArray(content))
|
|
5
|
+
return content.map(toCamelCase);
|
|
6
|
+
if (typeof content === 'object' && content !== null) {
|
|
7
|
+
const result = {};
|
|
8
|
+
for (const [key, value] of Object.entries(content)) {
|
|
9
|
+
const camelKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
10
|
+
result[camelKey] = toCamelCase(value);
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
return content;
|
|
15
|
+
};
|
|
16
|
+
export default toCamelCase;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const toSnakeCase = (content) => {
|
|
2
|
+
if (typeof content === 'string')
|
|
3
|
+
return content;
|
|
4
|
+
if (Array.isArray(content))
|
|
5
|
+
return content.map(toSnakeCase);
|
|
6
|
+
if (typeof content === 'object' && content !== null) {
|
|
7
|
+
const result = {};
|
|
8
|
+
for (const [key, value] of Object.entries(content)) {
|
|
9
|
+
const snakeKey = key.replace(/([A-Z])/g, '_$1').toLowerCase();
|
|
10
|
+
result[snakeKey] = toSnakeCase(value);
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
return content;
|
|
15
|
+
};
|
|
16
|
+
export default toSnakeCase;
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@translated/lara",
|
|
3
|
-
"version": "
|
|
4
|
-
"main": "lib/index.js",
|
|
5
|
-
"types": "lib/index.d.ts",
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"main": "./lib/index.js",
|
|
5
|
+
"types": "./lib/index.d.ts",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=12.*"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "rm -rf lib/* lib-browser/* && node scripts/generate-sdk-version.js && tsc && webpack",
|
|
11
|
+
"_build": "rm -rf lib/* && tsc",
|
|
11
12
|
"version": "node scripts/generate-sdk-version.js && git add src/sdk-version.ts",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
13
|
+
"lint:fix": "eslint --fix .",
|
|
14
|
+
"lint:check": "eslint ."
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"lib",
|
|
@@ -34,14 +35,23 @@
|
|
|
34
35
|
"url": "git+ssh://git@github.com/translated/lara-node.git"
|
|
35
36
|
},
|
|
36
37
|
"description": "Official Lara SDK for JavaScript and Node.js",
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"form-data": "^4.0.2"
|
|
39
|
-
},
|
|
40
38
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"typescript": "^
|
|
44
|
-
"
|
|
45
|
-
"
|
|
39
|
+
"@types/node": "^24.9.1",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^8.46.0",
|
|
41
|
+
"@typescript-eslint/parser": "^8.46.0",
|
|
42
|
+
"eslint": "^9.37.0",
|
|
43
|
+
"eslint-config-prettier": "^10.1.8",
|
|
44
|
+
"eslint-plugin-import": "^2.32.0",
|
|
45
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
46
|
+
"husky": "^9.1.7",
|
|
47
|
+
"prettier": "^3.6.2",
|
|
48
|
+
"tsup": "^8.5.0",
|
|
49
|
+
"typescript": "^5.9.3",
|
|
50
|
+
"webpack": "^5.102.1",
|
|
51
|
+
"webpack-cli": "^6.0.1"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"axios": "^1.12.2",
|
|
55
|
+
"form-data": "^4.0.4"
|
|
46
56
|
}
|
|
47
57
|
}
|
package/lib/credentials.d.ts
DELETED
package/lib/credentials.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Credentials = void 0;
|
|
4
|
-
class Credentials {
|
|
5
|
-
constructor(accessKeyId, accessKeySecret) {
|
|
6
|
-
this.accessKeyId = accessKeyId;
|
|
7
|
-
this.accessKeySecret = accessKeySecret;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.Credentials = Credentials;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { PortableCrypto } from "./portable-crypto";
|
|
2
|
-
/** @internal */
|
|
3
|
-
export declare class BrowserCrypto implements PortableCrypto {
|
|
4
|
-
private readonly subtle;
|
|
5
|
-
constructor();
|
|
6
|
-
/**
|
|
7
|
-
* MD5 in browser is not supported, so we use SHA-256 instead and return the first 16 bytes
|
|
8
|
-
*/
|
|
9
|
-
digest(data: string): Promise<string>;
|
|
10
|
-
hmac(key: string, data: string): Promise<string>;
|
|
11
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BrowserCrypto = void 0;
|
|
4
|
-
/** @internal */
|
|
5
|
-
class BrowserCrypto {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.subtle = window.crypto.subtle;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* MD5 in browser is not supported, so we use SHA-256 instead and return the first 16 bytes
|
|
11
|
-
*/
|
|
12
|
-
async digest(data) {
|
|
13
|
-
const encoder = new TextEncoder();
|
|
14
|
-
const buffer = (await this.subtle.digest("sha-256", encoder.encode(data))).slice(0, 16);
|
|
15
|
-
return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
16
|
-
}
|
|
17
|
-
async hmac(key, data) {
|
|
18
|
-
const encoder = new TextEncoder();
|
|
19
|
-
encoder.encode(data);
|
|
20
|
-
const cKey = await this.subtle.importKey("raw", encoder.encode(key), {
|
|
21
|
-
name: "hmac",
|
|
22
|
-
hash: { name: "sha-256" }
|
|
23
|
-
}, false, ["sign"]);
|
|
24
|
-
const buffer = await this.subtle.sign("hmac", cKey, encoder.encode(data));
|
|
25
|
-
return btoa(String.fromCharCode(...new Uint8Array(buffer)));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.BrowserCrypto = BrowserCrypto;
|
package/lib/crypto/index.d.ts
DELETED