smartling-api-sdk-nodejs 2.4.0 → 2.6.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/.scannerwork/report-task.txt +2 -2
- package/api/file-translations/dto/error.ts +7 -0
- package/api/file-translations/dto/fts-uploaded-file-dto.ts +5 -0
- package/api/file-translations/dto/language-detection-dto.ts +5 -0
- package/api/file-translations/dto/language-detection-state.ts +5 -0
- package/api/file-translations/dto/language-detection-status-dto.ts +11 -0
- package/api/file-translations/dto/language-dto.ts +6 -0
- package/api/file-translations/dto/mt-state.ts +7 -0
- package/api/file-translations/dto/translation-dto.ts +5 -0
- package/api/file-translations/dto/translation-locale-status-dto.ts +11 -0
- package/api/file-translations/dto/translation-status-dto.ts +12 -0
- package/api/file-translations/index.ts +114 -0
- package/api/file-translations/params/fts-upload-file-parameters.ts +29 -0
- package/api/file-translations/params/translate-file-parameters.ts +13 -0
- package/built/api/file-translations/dto/error.d.ts +6 -0
- package/built/api/file-translations/dto/error.js +3 -0
- package/built/api/file-translations/dto/error.js.map +1 -0
- package/built/api/file-translations/dto/fts-uploaded-file-dto.d.ts +4 -0
- package/built/api/file-translations/dto/fts-uploaded-file-dto.js +3 -0
- package/built/api/file-translations/dto/fts-uploaded-file-dto.js.map +1 -0
- package/built/api/file-translations/dto/language-detection-dto.d.ts +4 -0
- package/built/api/file-translations/dto/language-detection-dto.js +3 -0
- package/built/api/file-translations/dto/language-detection-dto.js.map +1 -0
- package/built/api/file-translations/dto/language-detection-state.d.ts +5 -0
- package/built/api/file-translations/dto/language-detection-state.js +10 -0
- package/built/api/file-translations/dto/language-detection-state.js.map +1 -0
- package/built/api/file-translations/dto/language-detection-status-dto.d.ts +9 -0
- package/built/api/file-translations/dto/language-detection-status-dto.js +3 -0
- package/built/api/file-translations/dto/language-detection-status-dto.js.map +1 -0
- package/built/api/file-translations/dto/language-dto.d.ts +5 -0
- package/built/api/file-translations/dto/language-dto.js +3 -0
- package/built/api/file-translations/dto/language-dto.js.map +1 -0
- package/built/api/file-translations/dto/mt-state.d.ts +7 -0
- package/built/api/file-translations/dto/mt-state.js +12 -0
- package/built/api/file-translations/dto/mt-state.js.map +1 -0
- package/built/api/file-translations/dto/translation-dto.d.ts +4 -0
- package/built/api/file-translations/dto/translation-dto.js +3 -0
- package/built/api/file-translations/dto/translation-dto.js.map +1 -0
- package/built/api/file-translations/dto/translation-locale-status-dto.d.ts +9 -0
- package/built/api/file-translations/dto/translation-locale-status-dto.js +3 -0
- package/built/api/file-translations/dto/translation-locale-status-dto.js.map +1 -0
- package/built/api/file-translations/dto/translation-status-dto.d.ts +10 -0
- package/built/api/file-translations/dto/translation-status-dto.js +3 -0
- package/built/api/file-translations/dto/translation-status-dto.js.map +1 -0
- package/built/api/file-translations/index.d.ts +23 -0
- package/built/api/file-translations/index.js +78 -0
- package/built/api/file-translations/index.js.map +1 -0
- package/built/api/file-translations/params/fts-upload-file-parameters.d.ts +8 -0
- package/built/api/file-translations/params/fts-upload-file-parameters.js +52 -0
- package/built/api/file-translations/params/fts-upload-file-parameters.js.map +1 -0
- package/built/api/file-translations/params/translate-file-parameters.d.ts +5 -0
- package/built/api/file-translations/params/translate-file-parameters.js +16 -0
- package/built/api/file-translations/params/translate-file-parameters.js.map +1 -0
- package/built/index.d.ts +13 -0
- package/built/index.js +13 -0
- package/built/index.js.map +1 -1
- package/built/package.json +1 -1
- package/index.ts +13 -0
- package/package.json +1 -1
- package/test/builder.spec.ts +8 -0
- package/test/file-translations.spec.ts +282 -0
|
@@ -2,5 +2,5 @@ projectKey=smartling-api-sdk-nodejs
|
|
|
2
2
|
serverUrl=https://sonar-next.connectors.stg.smartling.net
|
|
3
3
|
serverVersion=8.6.1.40680
|
|
4
4
|
dashboardUrl=https://sonar-next.connectors.stg.smartling.net/dashboard?id=smartling-api-sdk-nodejs
|
|
5
|
-
ceTaskId=
|
|
6
|
-
ceTaskUrl=https://sonar-next.connectors.stg.smartling.net/api/ce/task?id=
|
|
5
|
+
ceTaskId=AYyITSNeRe7rJHsZ61oT
|
|
6
|
+
ceTaskUrl=https://sonar-next.connectors.stg.smartling.net/api/ce/task?id=AYyITSNeRe7rJHsZ61oT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Error } from "./error";
|
|
2
|
+
import { LanguageDetectionState } from "./language-detection-state";
|
|
3
|
+
import { LanguageDto } from "./language-dto";
|
|
4
|
+
|
|
5
|
+
interface LanguageDetectionStatusDto {
|
|
6
|
+
state: LanguageDetectionState,
|
|
7
|
+
error?: Error,
|
|
8
|
+
detectedSourceLanguages: LanguageDto[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { LanguageDetectionStatusDto };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MTState } from "./mt-state";
|
|
2
|
+
import { Error } from "./error";
|
|
3
|
+
import { TranslationLocaleStatusDto } from "./translation-locale-status-dto";
|
|
4
|
+
|
|
5
|
+
interface TranslationStatusDto {
|
|
6
|
+
state: MTState,
|
|
7
|
+
requestedStringCount: number,
|
|
8
|
+
error?: Error,
|
|
9
|
+
localeProcessStatuses: TranslationLocaleStatusDto[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { TranslationStatusDto };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import FormData from "form-data";
|
|
2
|
+
import { SmartlingBaseApi } from "../base";
|
|
3
|
+
import { SmartlingAuthApi } from "../auth";
|
|
4
|
+
import { Logger } from "../logger";
|
|
5
|
+
import { FtsUploadedFileDto } from "./dto/fts-uploaded-file-dto";
|
|
6
|
+
import { FtsUploadFileParameters } from "./params/fts-upload-file-parameters";
|
|
7
|
+
import { TranslationDto } from "./dto/translation-dto";
|
|
8
|
+
import { TranslateFileParameters } from "./params/translate-file-parameters";
|
|
9
|
+
import { TranslationStatusDto } from "./dto/translation-status-dto";
|
|
10
|
+
import { LanguageDetectionDto } from "./dto/language-detection-dto";
|
|
11
|
+
import { LanguageDetectionStatusDto } from "./dto/language-detection-status-dto";
|
|
12
|
+
|
|
13
|
+
export class SmartlingFileTranslationsApi extends SmartlingBaseApi {
|
|
14
|
+
constructor(smartlingApiBaseUrl: string, authApi: SmartlingAuthApi, logger: Logger) {
|
|
15
|
+
super(logger);
|
|
16
|
+
this.authApi = authApi;
|
|
17
|
+
this.entrypoint = `${smartlingApiBaseUrl}/file-translations-api/v2/accounts`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async uploadFile(
|
|
21
|
+
accountUid: string, parameters: FtsUploadFileParameters
|
|
22
|
+
): Promise<FtsUploadedFileDto> {
|
|
23
|
+
const formData = new FormData();
|
|
24
|
+
const exported = parameters.export();
|
|
25
|
+
|
|
26
|
+
formData.append("file", exported.file);
|
|
27
|
+
formData.append("request", JSON.stringify(exported.request), {
|
|
28
|
+
contentType: "application/json"
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return await this.makeRequest(
|
|
32
|
+
"post",
|
|
33
|
+
`${this.entrypoint}/${accountUid}/files`,
|
|
34
|
+
formData,
|
|
35
|
+
false,
|
|
36
|
+
SmartlingFileTranslationsApi.fixContentTypeHeaderCase(formData)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async translateFile(
|
|
41
|
+
accountUid: string, fileUid: string, params: TranslateFileParameters
|
|
42
|
+
): Promise<TranslationDto> {
|
|
43
|
+
return await this.makeRequest(
|
|
44
|
+
"post",
|
|
45
|
+
`${this.entrypoint}/${accountUid}/files/${fileUid}/mt`,
|
|
46
|
+
JSON.stringify(params.export())
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async getTranslationProgress(
|
|
51
|
+
accountUid: string, fileUid: string, mtUid: string
|
|
52
|
+
): Promise<TranslationStatusDto> {
|
|
53
|
+
return await this.makeRequest(
|
|
54
|
+
"get",
|
|
55
|
+
`${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/status`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async downloadTranslatedFile(
|
|
60
|
+
accountUid: string, fileUid: string, mtUid: string, localeId: string
|
|
61
|
+
): Promise<string> {
|
|
62
|
+
return await this.makeRequest(
|
|
63
|
+
"get",
|
|
64
|
+
`${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/locales/${localeId}/file`,
|
|
65
|
+
null,
|
|
66
|
+
true
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async downloadTranslatedFiles(
|
|
71
|
+
accountUid: string, fileUid: string, mtUid: string
|
|
72
|
+
): Promise<string> {
|
|
73
|
+
return await this.makeRequest(
|
|
74
|
+
"get",
|
|
75
|
+
`${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/locales/all/file/zip`,
|
|
76
|
+
null,
|
|
77
|
+
true
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async cancelFileTranslation(
|
|
82
|
+
accountUid: string, fileUid: string, mtUid: string
|
|
83
|
+
): Promise<void> {
|
|
84
|
+
await this.makeRequest(
|
|
85
|
+
"post",
|
|
86
|
+
`${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/cancel`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async detectFileLanguage(accountUid: string, fileUid: string): Promise<LanguageDetectionDto> {
|
|
91
|
+
return await this.makeRequest(
|
|
92
|
+
"post",
|
|
93
|
+
`${this.entrypoint}/${accountUid}/files/${fileUid}/language-detection`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async getLanguageDetectionProgress(
|
|
98
|
+
accountUid: string, fileUid: string, languageDetectionUid: string
|
|
99
|
+
): Promise<LanguageDetectionStatusDto> {
|
|
100
|
+
return await this.makeRequest(
|
|
101
|
+
"get",
|
|
102
|
+
`${this.entrypoint}/${accountUid}/files/${fileUid}/language-detection/${languageDetectionUid}/status`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static fixContentTypeHeaderCase(form: FormData): Record<string, unknown> {
|
|
107
|
+
const headers = form.getHeaders();
|
|
108
|
+
|
|
109
|
+
headers["Content-Type"] = headers["content-type"];
|
|
110
|
+
// eslint-disable-next-line fp/no-delete
|
|
111
|
+
delete headers["content-type"];
|
|
112
|
+
return headers;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import string2fileStream from "string-to-file-stream";
|
|
3
|
+
import { BaseParameters } from "../../parameters";
|
|
4
|
+
import { FileType } from "../../files/params/file-type";
|
|
5
|
+
|
|
6
|
+
export class FtsUploadFileParameters extends BaseParameters {
|
|
7
|
+
constructor(parameters: Record<string, unknown> = {}) {
|
|
8
|
+
super(parameters);
|
|
9
|
+
|
|
10
|
+
this.set("request", {});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setFileFromLocalFilePath(filePath: string): FtsUploadFileParameters {
|
|
14
|
+
this.set("file", fs.createReadStream(
|
|
15
|
+
fs.realpathSync(filePath)
|
|
16
|
+
));
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
setFileContent(fileContent: string): FtsUploadFileParameters {
|
|
21
|
+
this.set("file", string2fileStream(fileContent));
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setFileType(fileType: FileType): FtsUploadFileParameters {
|
|
26
|
+
this.parameters.request.fileType = fileType.toUpperCase();
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseParameters } from "../../parameters";
|
|
2
|
+
|
|
3
|
+
export class TranslateFileParameters extends BaseParameters {
|
|
4
|
+
setSourceLocaleId(sourceLocaleId: string): TranslateFileParameters {
|
|
5
|
+
this.set("sourceLocaleId", sourceLocaleId);
|
|
6
|
+
return this;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
setTargetLocaleIds(targetLocaleIds: string[]): TranslateFileParameters {
|
|
10
|
+
this.set("targetLocaleIds", targetLocaleIds);
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/error.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fts-uploaded-file-dto.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/fts-uploaded-file-dto.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-detection-dto.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/language-detection-dto.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LanguageDetectionState = void 0;
|
|
4
|
+
var LanguageDetectionState;
|
|
5
|
+
(function (LanguageDetectionState) {
|
|
6
|
+
LanguageDetectionState["QUEUED"] = "QUEUED";
|
|
7
|
+
LanguageDetectionState["FAILED"] = "FAILED";
|
|
8
|
+
LanguageDetectionState["COMPLETED"] = "COMPLETED";
|
|
9
|
+
})(LanguageDetectionState = exports.LanguageDetectionState || (exports.LanguageDetectionState = {}));
|
|
10
|
+
//# sourceMappingURL=language-detection-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-detection-state.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/language-detection-state.ts"],"names":[],"mappings":";;;AAAA,IAAY,sBAIX;AAJD,WAAY,sBAAsB;IAC9B,2CAAiB,CAAA;IACjB,2CAAiB,CAAA;IACjB,iDAAuB,CAAA;AAC3B,CAAC,EAJW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAIjC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Error } from "./error";
|
|
2
|
+
import { LanguageDetectionState } from "./language-detection-state";
|
|
3
|
+
import { LanguageDto } from "./language-dto";
|
|
4
|
+
interface LanguageDetectionStatusDto {
|
|
5
|
+
state: LanguageDetectionState;
|
|
6
|
+
error?: Error;
|
|
7
|
+
detectedSourceLanguages: LanguageDto[];
|
|
8
|
+
}
|
|
9
|
+
export { LanguageDetectionStatusDto };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-detection-status-dto.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/language-detection-status-dto.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-dto.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/language-dto.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MTState = void 0;
|
|
4
|
+
var MTState;
|
|
5
|
+
(function (MTState) {
|
|
6
|
+
MTState["QUEUED"] = "QUEUED";
|
|
7
|
+
MTState["PROCESSING"] = "PROCESSING";
|
|
8
|
+
MTState["FAILED"] = "FAILED";
|
|
9
|
+
MTState["CANCELED"] = "CANCELED";
|
|
10
|
+
MTState["COMPLETED"] = "COMPLETED";
|
|
11
|
+
})(MTState = exports.MTState || (exports.MTState = {}));
|
|
12
|
+
//# sourceMappingURL=mt-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mt-state.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/mt-state.ts"],"names":[],"mappings":";;;AAAA,IAAY,OAMX;AAND,WAAY,OAAO;IACf,4BAAiB,CAAA;IACjB,oCAAyB,CAAA;IACzB,4BAAiB,CAAA;IACjB,gCAAqB,CAAA;IACrB,kCAAuB,CAAA;AAC3B,CAAC,EANW,OAAO,GAAP,eAAO,KAAP,eAAO,QAMlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation-dto.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/translation-dto.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation-locale-status-dto.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/translation-locale-status-dto.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MTState } from "./mt-state";
|
|
2
|
+
import { Error } from "./error";
|
|
3
|
+
import { TranslationLocaleStatusDto } from "./translation-locale-status-dto";
|
|
4
|
+
interface TranslationStatusDto {
|
|
5
|
+
state: MTState;
|
|
6
|
+
requestedStringCount: number;
|
|
7
|
+
error?: Error;
|
|
8
|
+
localeProcessStatuses: TranslationLocaleStatusDto[];
|
|
9
|
+
}
|
|
10
|
+
export { TranslationStatusDto };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation-status-dto.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/translation-status-dto.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import FormData from "form-data";
|
|
2
|
+
import { SmartlingBaseApi } from "../base";
|
|
3
|
+
import { SmartlingAuthApi } from "../auth";
|
|
4
|
+
import { Logger } from "../logger";
|
|
5
|
+
import { FtsUploadedFileDto } from "./dto/fts-uploaded-file-dto";
|
|
6
|
+
import { FtsUploadFileParameters } from "./params/fts-upload-file-parameters";
|
|
7
|
+
import { TranslationDto } from "./dto/translation-dto";
|
|
8
|
+
import { TranslateFileParameters } from "./params/translate-file-parameters";
|
|
9
|
+
import { TranslationStatusDto } from "./dto/translation-status-dto";
|
|
10
|
+
import { LanguageDetectionDto } from "./dto/language-detection-dto";
|
|
11
|
+
import { LanguageDetectionStatusDto } from "./dto/language-detection-status-dto";
|
|
12
|
+
export declare class SmartlingFileTranslationsApi extends SmartlingBaseApi {
|
|
13
|
+
constructor(smartlingApiBaseUrl: string, authApi: SmartlingAuthApi, logger: Logger);
|
|
14
|
+
uploadFile(accountUid: string, parameters: FtsUploadFileParameters): Promise<FtsUploadedFileDto>;
|
|
15
|
+
translateFile(accountUid: string, fileUid: string, params: TranslateFileParameters): Promise<TranslationDto>;
|
|
16
|
+
getTranslationProgress(accountUid: string, fileUid: string, mtUid: string): Promise<TranslationStatusDto>;
|
|
17
|
+
downloadTranslatedFile(accountUid: string, fileUid: string, mtUid: string, localeId: string): Promise<string>;
|
|
18
|
+
downloadTranslatedFiles(accountUid: string, fileUid: string, mtUid: string): Promise<string>;
|
|
19
|
+
cancelFileTranslation(accountUid: string, fileUid: string, mtUid: string): Promise<void>;
|
|
20
|
+
detectFileLanguage(accountUid: string, fileUid: string): Promise<LanguageDetectionDto>;
|
|
21
|
+
getLanguageDetectionProgress(accountUid: string, fileUid: string, languageDetectionUid: string): Promise<LanguageDetectionStatusDto>;
|
|
22
|
+
static fixContentTypeHeaderCase(form: FormData): Record<string, unknown>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SmartlingFileTranslationsApi = void 0;
|
|
16
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
17
|
+
const base_1 = require("../base");
|
|
18
|
+
class SmartlingFileTranslationsApi extends base_1.SmartlingBaseApi {
|
|
19
|
+
constructor(smartlingApiBaseUrl, authApi, logger) {
|
|
20
|
+
super(logger);
|
|
21
|
+
this.authApi = authApi;
|
|
22
|
+
this.entrypoint = `${smartlingApiBaseUrl}/file-translations-api/v2/accounts`;
|
|
23
|
+
}
|
|
24
|
+
uploadFile(accountUid, parameters) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const formData = new form_data_1.default();
|
|
27
|
+
const exported = parameters.export();
|
|
28
|
+
formData.append("file", exported.file);
|
|
29
|
+
formData.append("request", JSON.stringify(exported.request), {
|
|
30
|
+
contentType: "application/json"
|
|
31
|
+
});
|
|
32
|
+
return yield this.makeRequest("post", `${this.entrypoint}/${accountUid}/files`, formData, false, SmartlingFileTranslationsApi.fixContentTypeHeaderCase(formData));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
translateFile(accountUid, fileUid, params) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
return yield this.makeRequest("post", `${this.entrypoint}/${accountUid}/files/${fileUid}/mt`, JSON.stringify(params.export()));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
getTranslationProgress(accountUid, fileUid, mtUid) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
return yield this.makeRequest("get", `${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/status`);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
downloadTranslatedFile(accountUid, fileUid, mtUid, localeId) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
return yield this.makeRequest("get", `${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/locales/${localeId}/file`, null, true);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
downloadTranslatedFiles(accountUid, fileUid, mtUid) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
return yield this.makeRequest("get", `${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/locales/all/file/zip`, null, true);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
cancelFileTranslation(accountUid, fileUid, mtUid) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
yield this.makeRequest("post", `${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/cancel`);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
detectFileLanguage(accountUid, fileUid) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
return yield this.makeRequest("post", `${this.entrypoint}/${accountUid}/files/${fileUid}/language-detection`);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
getLanguageDetectionProgress(accountUid, fileUid, languageDetectionUid) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
return yield this.makeRequest("get", `${this.entrypoint}/${accountUid}/files/${fileUid}/language-detection/${languageDetectionUid}/status`);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
static fixContentTypeHeaderCase(form) {
|
|
71
|
+
const headers = form.getHeaders();
|
|
72
|
+
headers["Content-Type"] = headers["content-type"];
|
|
73
|
+
delete headers["content-type"];
|
|
74
|
+
return headers;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.SmartlingFileTranslationsApi = SmartlingFileTranslationsApi;
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/file-translations/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseParameters } from "../../parameters";
|
|
2
|
+
import { FileType } from "../../files/params/file-type";
|
|
3
|
+
export declare class FtsUploadFileParameters extends BaseParameters {
|
|
4
|
+
constructor(parameters?: Record<string, unknown>);
|
|
5
|
+
setFileFromLocalFilePath(filePath: string): FtsUploadFileParameters;
|
|
6
|
+
setFileContent(fileContent: string): FtsUploadFileParameters;
|
|
7
|
+
setFileType(fileType: FileType): FtsUploadFileParameters;
|
|
8
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.FtsUploadFileParameters = void 0;
|
|
30
|
+
const fs = __importStar(require("fs"));
|
|
31
|
+
const string_to_file_stream_1 = __importDefault(require("string-to-file-stream"));
|
|
32
|
+
const parameters_1 = require("../../parameters");
|
|
33
|
+
class FtsUploadFileParameters extends parameters_1.BaseParameters {
|
|
34
|
+
constructor(parameters = {}) {
|
|
35
|
+
super(parameters);
|
|
36
|
+
this.set("request", {});
|
|
37
|
+
}
|
|
38
|
+
setFileFromLocalFilePath(filePath) {
|
|
39
|
+
this.set("file", fs.createReadStream(fs.realpathSync(filePath)));
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
setFileContent(fileContent) {
|
|
43
|
+
this.set("file", (0, string_to_file_stream_1.default)(fileContent));
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
setFileType(fileType) {
|
|
47
|
+
this.parameters.request.fileType = fileType.toUpperCase();
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.FtsUploadFileParameters = FtsUploadFileParameters;
|
|
52
|
+
//# sourceMappingURL=fts-upload-file-parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fts-upload-file-parameters.js","sourceRoot":"","sources":["../../../../api/file-translations/params/fts-upload-file-parameters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,kFAAsD;AACtD,iDAAkD;AAGlD,MAAa,uBAAwB,SAAQ,2BAAc;IACvD,YAAY,aAAsC,EAAE;QAChD,KAAK,CAAC,UAAU,CAAC,CAAC;QAElB,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED,wBAAwB,CAAC,QAAgB;QACrC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,gBAAgB,CAChC,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAC5B,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,cAAc,CAAC,WAAmB;QAC9B,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAA,+BAAiB,EAAC,WAAW,CAAC,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,WAAW,CAAC,QAAkB;QAC1B,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC1D,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAvBD,0DAuBC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TranslateFileParameters = void 0;
|
|
4
|
+
const parameters_1 = require("../../parameters");
|
|
5
|
+
class TranslateFileParameters extends parameters_1.BaseParameters {
|
|
6
|
+
setSourceLocaleId(sourceLocaleId) {
|
|
7
|
+
this.set("sourceLocaleId", sourceLocaleId);
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
setTargetLocaleIds(targetLocaleIds) {
|
|
11
|
+
this.set("targetLocaleIds", targetLocaleIds);
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.TranslateFileParameters = TranslateFileParameters;
|
|
16
|
+
//# sourceMappingURL=translate-file-parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translate-file-parameters.js","sourceRoot":"","sources":["../../../../api/file-translations/params/translate-file-parameters.ts"],"names":[],"mappings":";;;AAAA,iDAAkD;AAElD,MAAa,uBAAwB,SAAQ,2BAAc;IACvD,iBAAiB,CAAC,cAAsB;QACpC,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,kBAAkB,CAAC,eAAyB;QACxC,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,eAAe,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAVD,0DAUC"}
|
package/built/index.d.ts
CHANGED
|
@@ -15,6 +15,19 @@ export * from "./api/context/params/create-bindings-parameters";
|
|
|
15
15
|
export * from "./api/context/params/list-parameters";
|
|
16
16
|
export * from "./api/context/context-http-response";
|
|
17
17
|
export * from "./api/exception/index";
|
|
18
|
+
export * from "./api/file-translations/index";
|
|
19
|
+
export * from "./api/file-translations/params/fts-upload-file-parameters";
|
|
20
|
+
export * from "./api/file-translations/params/translate-file-parameters";
|
|
21
|
+
export * from "./api/file-translations/dto/error";
|
|
22
|
+
export * from "./api/file-translations/dto/fts-uploaded-file-dto";
|
|
23
|
+
export * from "./api/file-translations/dto/language-detection-dto";
|
|
24
|
+
export * from "./api/file-translations/dto/language-detection-state";
|
|
25
|
+
export * from "./api/file-translations/dto/language-detection-status-dto";
|
|
26
|
+
export * from "./api/file-translations/dto/language-dto";
|
|
27
|
+
export * from "./api/file-translations/dto/mt-state";
|
|
28
|
+
export * from "./api/file-translations/dto/translation-dto";
|
|
29
|
+
export * from "./api/file-translations/dto/translation-locale-status-dto";
|
|
30
|
+
export * from "./api/file-translations/dto/translation-status-dto";
|
|
18
31
|
export * from "./api/files/index";
|
|
19
32
|
export * from "./api/files/params/download-file-parameters";
|
|
20
33
|
export * from "./api/files/params/retrieval-type";
|
package/built/index.js
CHANGED
|
@@ -31,6 +31,19 @@ __exportStar(require("./api/context/params/create-bindings-parameters"), exports
|
|
|
31
31
|
__exportStar(require("./api/context/params/list-parameters"), exports);
|
|
32
32
|
__exportStar(require("./api/context/context-http-response"), exports);
|
|
33
33
|
__exportStar(require("./api/exception/index"), exports);
|
|
34
|
+
__exportStar(require("./api/file-translations/index"), exports);
|
|
35
|
+
__exportStar(require("./api/file-translations/params/fts-upload-file-parameters"), exports);
|
|
36
|
+
__exportStar(require("./api/file-translations/params/translate-file-parameters"), exports);
|
|
37
|
+
__exportStar(require("./api/file-translations/dto/error"), exports);
|
|
38
|
+
__exportStar(require("./api/file-translations/dto/fts-uploaded-file-dto"), exports);
|
|
39
|
+
__exportStar(require("./api/file-translations/dto/language-detection-dto"), exports);
|
|
40
|
+
__exportStar(require("./api/file-translations/dto/language-detection-state"), exports);
|
|
41
|
+
__exportStar(require("./api/file-translations/dto/language-detection-status-dto"), exports);
|
|
42
|
+
__exportStar(require("./api/file-translations/dto/language-dto"), exports);
|
|
43
|
+
__exportStar(require("./api/file-translations/dto/mt-state"), exports);
|
|
44
|
+
__exportStar(require("./api/file-translations/dto/translation-dto"), exports);
|
|
45
|
+
__exportStar(require("./api/file-translations/dto/translation-locale-status-dto"), exports);
|
|
46
|
+
__exportStar(require("./api/file-translations/dto/translation-status-dto"), exports);
|
|
34
47
|
__exportStar(require("./api/files/index"), exports);
|
|
35
48
|
__exportStar(require("./api/files/params/download-file-parameters"), exports);
|
|
36
49
|
__exportStar(require("./api/files/params/retrieval-type"), exports);
|
package/built/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,kEAAgD;AAChD,mDAAiC;AACjC,sDAAoC;AACpC,sDAAoC;AACpC,wEAAsD;AACtD,6EAA2D;AAC3D,gEAA8C;AAC9C,4EAA0D;AAC1D,uEAAqD;AACrD,0FAAwE;AACxE,oEAAkD;AAClD,iFAA+D;AAC/D,kFAAgE;AAChE,uEAAqD;AACrD,sEAAoD;AACpD,wDAAsC;AACtC,oDAAkC;AAClC,8EAA4D;AAC5D,oEAAkD;AAClD,+DAA6C;AAC7C,4EAA0D;AAC1D,kFAAgE;AAChE,kFAAgE;AAChE,+EAA6D;AAC7D,oEAAkD;AAClD,qEAAmD;AACnD,0DAAwC;AACxC,kEAAgD;AAChD,uEAAqD;AACrD,yEAAuD;AACvD,yEAAuD;AACvD,4EAA0D;AAC1D,mFAAiE;AACjE,wFAAsE;AACtE,2FAAyE;AACzE,wFAAsE;AACtE,0FAAwE;AACxE,wEAAsD;AACtD,wEAAsD;AACtD,mFAAiE;AACjE,6EAA2D;AAC3D,mDAAiC;AACjC,8DAA4C;AAC5C,kFAAgE;AAChE,kEAAgD;AAChD,mEAAiD;AACjD,sEAAoD;AACpD,iEAA+C;AAC/C,yDAAuC;AACvC,iEAA+C;AAC/C,mFAAiE;AACjE,uFAAqE;AACrE,kEAAgD;AAChD,mEAAiD;AACjD,yEAAuD;AACvD,kEAAgD;AAChD,0EAAwD;AACxD,6EAA2D;AAC3D,4EAA0D;AAC1D,+DAA6C;AAC7C,8EAA4D;AAC5D,yEAAuD;AACvD,2EAAyD;AACzD,0EAAwD;AACxD,yEAAuD;AACvD,2EAAyD;AACzD,yDAAuC;AACvC,yDAAuC;AACvC,uDAAqC;AACrC,iEAA+C;AAC/C,gEAA8C;AAC9C,sDAAoC;AACpC,sEAAoD;AACpD,0EAAwD;AACxD,uFAAqE;AACrE,+CAA6B;AAC7B,wEAAsD;AACtD,+FAA6E;AAC7E,6EAA2D"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,kEAAgD;AAChD,mDAAiC;AACjC,sDAAoC;AACpC,sDAAoC;AACpC,wEAAsD;AACtD,6EAA2D;AAC3D,gEAA8C;AAC9C,4EAA0D;AAC1D,uEAAqD;AACrD,0FAAwE;AACxE,oEAAkD;AAClD,iFAA+D;AAC/D,kFAAgE;AAChE,uEAAqD;AACrD,sEAAoD;AACpD,wDAAsC;AACtC,gEAA8C;AAC9C,4FAA0E;AAC1E,2FAAyE;AACzE,oEAAkD;AAClD,oFAAkE;AAClE,qFAAmE;AACnE,uFAAqE;AACrE,4FAA0E;AAC1E,2EAAyD;AACzD,uEAAqD;AACrD,8EAA4D;AAC5D,4FAA0E;AAC1E,qFAAmE;AACnE,oDAAkC;AAClC,8EAA4D;AAC5D,oEAAkD;AAClD,+DAA6C;AAC7C,4EAA0D;AAC1D,kFAAgE;AAChE,kFAAgE;AAChE,+EAA6D;AAC7D,oEAAkD;AAClD,qEAAmD;AACnD,0DAAwC;AACxC,kEAAgD;AAChD,uEAAqD;AACrD,yEAAuD;AACvD,yEAAuD;AACvD,4EAA0D;AAC1D,mFAAiE;AACjE,wFAAsE;AACtE,2FAAyE;AACzE,wFAAsE;AACtE,0FAAwE;AACxE,wEAAsD;AACtD,wEAAsD;AACtD,mFAAiE;AACjE,6EAA2D;AAC3D,mDAAiC;AACjC,8DAA4C;AAC5C,kFAAgE;AAChE,kEAAgD;AAChD,mEAAiD;AACjD,sEAAoD;AACpD,iEAA+C;AAC/C,yDAAuC;AACvC,iEAA+C;AAC/C,mFAAiE;AACjE,uFAAqE;AACrE,kEAAgD;AAChD,mEAAiD;AACjD,yEAAuD;AACvD,kEAAgD;AAChD,0EAAwD;AACxD,6EAA2D;AAC3D,4EAA0D;AAC1D,+DAA6C;AAC7C,8EAA4D;AAC5D,yEAAuD;AACvD,2EAAyD;AACzD,0EAAwD;AACxD,yEAAuD;AACvD,2EAAyD;AACzD,yDAAuC;AACvC,yDAAuC;AACvC,uDAAqC;AACrC,iEAA+C;AAC/C,gEAA8C;AAC9C,sDAAoC;AACpC,sEAAoD;AACpD,0EAAwD;AACxD,uFAAqE;AACrE,+CAA6B;AAC7B,wEAAsD;AACtD,+FAA6E;AAC7E,6EAA2D"}
|
package/built/package.json
CHANGED
package/index.ts
CHANGED
|
@@ -15,6 +15,19 @@ export * from "./api/context/params/create-bindings-parameters";
|
|
|
15
15
|
export * from "./api/context/params/list-parameters";
|
|
16
16
|
export * from "./api/context/context-http-response";
|
|
17
17
|
export * from "./api/exception/index";
|
|
18
|
+
export * from "./api/file-translations/index";
|
|
19
|
+
export * from "./api/file-translations/params/fts-upload-file-parameters";
|
|
20
|
+
export * from "./api/file-translations/params/translate-file-parameters";
|
|
21
|
+
export * from "./api/file-translations/dto/error";
|
|
22
|
+
export * from "./api/file-translations/dto/fts-uploaded-file-dto";
|
|
23
|
+
export * from "./api/file-translations/dto/language-detection-dto";
|
|
24
|
+
export * from "./api/file-translations/dto/language-detection-state";
|
|
25
|
+
export * from "./api/file-translations/dto/language-detection-status-dto";
|
|
26
|
+
export * from "./api/file-translations/dto/language-dto";
|
|
27
|
+
export * from "./api/file-translations/dto/mt-state";
|
|
28
|
+
export * from "./api/file-translations/dto/translation-dto";
|
|
29
|
+
export * from "./api/file-translations/dto/translation-locale-status-dto";
|
|
30
|
+
export * from "./api/file-translations/dto/translation-status-dto";
|
|
18
31
|
export * from "./api/files/index";
|
|
19
32
|
export * from "./api/files/params/download-file-parameters";
|
|
20
33
|
export * from "./api/files/params/retrieval-type";
|
package/package.json
CHANGED
package/test/builder.spec.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import assert from "assert";
|
|
9
9
|
import { SmartlingApiClientBuilder } from "../api/builder/index";
|
|
10
|
+
import { SmartlingFileTranslationsApi } from "../api/file-translations/index";
|
|
10
11
|
import { SmartlingFilesApi } from "../api/files/index";
|
|
11
12
|
import { SmartlingJobsApi } from "../api/jobs/index";
|
|
12
13
|
import { SmartlingJobBatchesApi } from "../api/job-batches/index";
|
|
@@ -240,6 +241,13 @@ describe("SmartlingApiClientBuilder class tests.", () => {
|
|
|
240
241
|
assert.equal(apiClient["options"], httpClientOptions);
|
|
241
242
|
});
|
|
242
243
|
|
|
244
|
+
it("Instantiates file translations api client", () => {
|
|
245
|
+
assertApiClient(
|
|
246
|
+
SmartlingFileTranslationsApi,
|
|
247
|
+
apiClientsBuilder.build(SmartlingFileTranslationsApi)
|
|
248
|
+
);
|
|
249
|
+
});
|
|
250
|
+
|
|
243
251
|
it("Instantiates files api client", () => {
|
|
244
252
|
assertApiClient(
|
|
245
253
|
SmartlingFilesApi,
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import FormData from "form-data";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import sinon from "sinon";
|
|
5
|
+
import { loggerMock, authMock, responseMock } from "./mock";
|
|
6
|
+
import { SmartlingFileTranslationsApi } from "../api/file-translations";
|
|
7
|
+
import { SmartlingAuthApi } from "../api/auth";
|
|
8
|
+
import { FtsUploadFileParameters } from "../api/file-translations/params/fts-upload-file-parameters";
|
|
9
|
+
import { FileType } from "../api/files/params/file-type";
|
|
10
|
+
import { streamToString } from "./stream-to-string";
|
|
11
|
+
import { TranslateFileParameters } from "../api/file-translations/params/translate-file-parameters";
|
|
12
|
+
|
|
13
|
+
describe("SmartlingFileTranslationsApi class tests.", () => {
|
|
14
|
+
const userAgent = "test_user_agent";
|
|
15
|
+
const accountUid = "testAccountUid";
|
|
16
|
+
const fileUid = "testFileUid";
|
|
17
|
+
const mtUid = "testMtUid";
|
|
18
|
+
const languageDetectionUid = "testLanguageDetectionUid";
|
|
19
|
+
|
|
20
|
+
let fileTranslationsApi: SmartlingFileTranslationsApi;
|
|
21
|
+
let fileTranslationsApiFetchStub;
|
|
22
|
+
let fileTranslationsApiUaStub;
|
|
23
|
+
let responseMockJsonStub;
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
fileTranslationsApi = new SmartlingFileTranslationsApi(
|
|
27
|
+
"https://test.com",
|
|
28
|
+
authMock as unknown as SmartlingAuthApi,
|
|
29
|
+
loggerMock
|
|
30
|
+
);
|
|
31
|
+
fileTranslationsApiFetchStub = sinon.stub(fileTranslationsApi, "fetch");
|
|
32
|
+
fileTranslationsApiUaStub = sinon.stub(fileTranslationsApi, "ua");
|
|
33
|
+
responseMockJsonStub = sinon.stub(responseMock, "json");
|
|
34
|
+
|
|
35
|
+
fileTranslationsApiFetchStub.returns(responseMock);
|
|
36
|
+
fileTranslationsApiUaStub.returns(userAgent);
|
|
37
|
+
responseMockJsonStub.returns({
|
|
38
|
+
response: {}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
fileTranslationsApiFetchStub.restore();
|
|
44
|
+
fileTranslationsApiUaStub.restore();
|
|
45
|
+
responseMockJsonStub.restore();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("Methods", () => {
|
|
49
|
+
it("Upload file: from disk", async () => {
|
|
50
|
+
const params = new FtsUploadFileParameters();
|
|
51
|
+
|
|
52
|
+
params
|
|
53
|
+
.setFileType(FileType.XML)
|
|
54
|
+
.setFileFromLocalFilePath("./test/data/file.xml");
|
|
55
|
+
|
|
56
|
+
await fileTranslationsApi.uploadFile(accountUid, params);
|
|
57
|
+
|
|
58
|
+
sinon.assert.calledOnce(fileTranslationsApiFetchStub);
|
|
59
|
+
|
|
60
|
+
const fileTranslationsApiFetchCall = fileTranslationsApiFetchStub.getCall(0);
|
|
61
|
+
|
|
62
|
+
assert.equal(
|
|
63
|
+
fileTranslationsApiFetchCall.args[0],
|
|
64
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files`
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
assert.equal(
|
|
68
|
+
fileTranslationsApiFetchCall.args[1].method,
|
|
69
|
+
"post"
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
assert.equal(
|
|
73
|
+
fileTranslationsApiFetchCall.args[1].headers.Authorization,
|
|
74
|
+
"test_token_type test_access_token"
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const testFileContent = fs.readFileSync(
|
|
78
|
+
fs.realpathSync("./test/data/file.xml"),
|
|
79
|
+
"utf8"
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const formData = fileTranslationsApiFetchCall.args[1].body as FormData;
|
|
83
|
+
const boundary = formData.getBoundary();
|
|
84
|
+
|
|
85
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].headers["User-Agent"], userAgent);
|
|
86
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].headers["Content-Type"], `multipart/form-data; boundary=${boundary}`);
|
|
87
|
+
|
|
88
|
+
const content = await streamToString(
|
|
89
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
90
|
+
fileTranslationsApiFetchCall.args[1].body._streams[1]
|
|
91
|
+
);
|
|
92
|
+
assert.equal(content, testFileContent);
|
|
93
|
+
|
|
94
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
95
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].body._streams[4], "{\"fileType\":\"XML\"}");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("Upload file: as string", async () => {
|
|
99
|
+
const params = new FtsUploadFileParameters();
|
|
100
|
+
|
|
101
|
+
const testFileContent = fs.readFileSync(
|
|
102
|
+
fs.realpathSync("./test/data/file.xml"),
|
|
103
|
+
"utf8"
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
params
|
|
107
|
+
.setFileType(FileType.XML)
|
|
108
|
+
.setFileContent(testFileContent);
|
|
109
|
+
|
|
110
|
+
await fileTranslationsApi.uploadFile(accountUid, params);
|
|
111
|
+
|
|
112
|
+
sinon.assert.calledOnce(fileTranslationsApiFetchStub);
|
|
113
|
+
|
|
114
|
+
const fileTranslationsApiFetchCall = fileTranslationsApiFetchStub.getCall(0);
|
|
115
|
+
|
|
116
|
+
assert.equal(
|
|
117
|
+
fileTranslationsApiFetchCall.args[0],
|
|
118
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files`
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
assert.equal(
|
|
122
|
+
fileTranslationsApiFetchCall.args[1].method,
|
|
123
|
+
"post"
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
assert.equal(
|
|
127
|
+
fileTranslationsApiFetchCall.args[1].headers.Authorization,
|
|
128
|
+
"test_token_type test_access_token"
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const formData = fileTranslationsApiFetchCall.args[1].body as FormData;
|
|
132
|
+
const boundary = formData.getBoundary();
|
|
133
|
+
|
|
134
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].headers["User-Agent"], userAgent);
|
|
135
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].headers["Content-Type"], `multipart/form-data; boundary=${boundary}`);
|
|
136
|
+
|
|
137
|
+
const content = await streamToString(
|
|
138
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
139
|
+
fileTranslationsApiFetchCall.args[1].body._streams[1]
|
|
140
|
+
);
|
|
141
|
+
assert.equal(content, testFileContent);
|
|
142
|
+
|
|
143
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
144
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].body._streams[4], "{\"fileType\":\"XML\"}");
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("Translate file", async () => {
|
|
148
|
+
const params = new TranslateFileParameters();
|
|
149
|
+
|
|
150
|
+
params
|
|
151
|
+
.setSourceLocaleId("en-US")
|
|
152
|
+
.setTargetLocaleIds(["de-DE", "fr-FR"]);
|
|
153
|
+
|
|
154
|
+
await fileTranslationsApi.translateFile(accountUid, fileUid, params);
|
|
155
|
+
|
|
156
|
+
sinon.assert.calledOnceWithExactly(
|
|
157
|
+
fileTranslationsApiFetchStub,
|
|
158
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/mt`,
|
|
159
|
+
{
|
|
160
|
+
method: "post",
|
|
161
|
+
headers: {
|
|
162
|
+
Authorization: "test_token_type test_access_token",
|
|
163
|
+
"Content-Type": "application/json",
|
|
164
|
+
"User-Agent": userAgent
|
|
165
|
+
},
|
|
166
|
+
body: JSON.stringify({
|
|
167
|
+
sourceLocaleId: "en-US",
|
|
168
|
+
targetLocaleIds: ["de-DE", "fr-FR"]
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("Get translation progress", async () => {
|
|
175
|
+
await fileTranslationsApi.getTranslationProgress(accountUid, fileUid, mtUid);
|
|
176
|
+
|
|
177
|
+
sinon.assert.calledOnceWithExactly(
|
|
178
|
+
fileTranslationsApiFetchStub,
|
|
179
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/mt/${mtUid}/status`,
|
|
180
|
+
{
|
|
181
|
+
method: "get",
|
|
182
|
+
headers: {
|
|
183
|
+
Authorization: "test_token_type test_access_token",
|
|
184
|
+
"Content-Type": "application/json",
|
|
185
|
+
"User-Agent": userAgent
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("Download translated file", async () => {
|
|
192
|
+
const localeId = "de-DE";
|
|
193
|
+
|
|
194
|
+
await fileTranslationsApi.downloadTranslatedFile(accountUid, fileUid, mtUid, localeId);
|
|
195
|
+
|
|
196
|
+
sinon.assert.calledOnceWithExactly(
|
|
197
|
+
fileTranslationsApiFetchStub,
|
|
198
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/mt/${mtUid}/locales/${localeId}/file`,
|
|
199
|
+
{
|
|
200
|
+
method: "get",
|
|
201
|
+
headers: {
|
|
202
|
+
Authorization: "test_token_type test_access_token",
|
|
203
|
+
"Content-Type": "application/json",
|
|
204
|
+
"User-Agent": userAgent
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("Download translated files", async () => {
|
|
211
|
+
await fileTranslationsApi.downloadTranslatedFiles(accountUid, fileUid, mtUid);
|
|
212
|
+
|
|
213
|
+
sinon.assert.calledOnceWithExactly(
|
|
214
|
+
fileTranslationsApiFetchStub,
|
|
215
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/mt/${mtUid}/locales/all/file/zip`,
|
|
216
|
+
{
|
|
217
|
+
method: "get",
|
|
218
|
+
headers: {
|
|
219
|
+
Authorization: "test_token_type test_access_token",
|
|
220
|
+
"Content-Type": "application/json",
|
|
221
|
+
"User-Agent": userAgent
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("Cancel file translation", async () => {
|
|
228
|
+
await fileTranslationsApi.cancelFileTranslation(accountUid, fileUid, mtUid);
|
|
229
|
+
|
|
230
|
+
sinon.assert.calledOnceWithExactly(
|
|
231
|
+
fileTranslationsApiFetchStub,
|
|
232
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/mt/${mtUid}/cancel`,
|
|
233
|
+
{
|
|
234
|
+
method: "post",
|
|
235
|
+
headers: {
|
|
236
|
+
Authorization: "test_token_type test_access_token",
|
|
237
|
+
"Content-Type": "application/json",
|
|
238
|
+
"User-Agent": userAgent
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("Detect file language", async () => {
|
|
245
|
+
await fileTranslationsApi.detectFileLanguage(accountUid, fileUid);
|
|
246
|
+
|
|
247
|
+
sinon.assert.calledOnceWithExactly(
|
|
248
|
+
fileTranslationsApiFetchStub,
|
|
249
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/language-detection`,
|
|
250
|
+
{
|
|
251
|
+
method: "post",
|
|
252
|
+
headers: {
|
|
253
|
+
Authorization: "test_token_type test_access_token",
|
|
254
|
+
"Content-Type": "application/json",
|
|
255
|
+
"User-Agent": userAgent
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("Get language detection progress", async () => {
|
|
262
|
+
await fileTranslationsApi.getLanguageDetectionProgress(
|
|
263
|
+
accountUid,
|
|
264
|
+
fileUid,
|
|
265
|
+
languageDetectionUid
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
sinon.assert.calledOnceWithExactly(
|
|
269
|
+
fileTranslationsApiFetchStub,
|
|
270
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/language-detection/${languageDetectionUid}/status`,
|
|
271
|
+
{
|
|
272
|
+
method: "get",
|
|
273
|
+
headers: {
|
|
274
|
+
Authorization: "test_token_type test_access_token",
|
|
275
|
+
"Content-Type": "application/json",
|
|
276
|
+
"User-Agent": userAgent
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
});
|