smartling-api-sdk-nodejs 2.4.0 → 2.5.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.
Files changed (57) hide show
  1. package/.scannerwork/report-task.txt +2 -2
  2. package/api/file-translations/dto/error.ts +7 -0
  3. package/api/file-translations/dto/language-detection-dto.ts +5 -0
  4. package/api/file-translations/dto/language-detection-state.ts +5 -0
  5. package/api/file-translations/dto/language-detection-status-dto.ts +11 -0
  6. package/api/file-translations/dto/language-dto.ts +6 -0
  7. package/api/file-translations/dto/mt-state.ts +7 -0
  8. package/api/file-translations/dto/translation-dto.ts +5 -0
  9. package/api/file-translations/dto/translation-locale-status-dto.ts +11 -0
  10. package/api/file-translations/dto/translation-status-dto.ts +12 -0
  11. package/api/file-translations/dto/uploaded-file-dto.ts +5 -0
  12. package/api/file-translations/index.ts +114 -0
  13. package/api/file-translations/params/translate-file-parameters.ts +13 -0
  14. package/api/file-translations/params/upload-file-parameters.ts +29 -0
  15. package/built/api/file-translations/dto/error.d.ts +6 -0
  16. package/built/api/file-translations/dto/error.js +3 -0
  17. package/built/api/file-translations/dto/error.js.map +1 -0
  18. package/built/api/file-translations/dto/language-detection-dto.d.ts +4 -0
  19. package/built/api/file-translations/dto/language-detection-dto.js +3 -0
  20. package/built/api/file-translations/dto/language-detection-dto.js.map +1 -0
  21. package/built/api/file-translations/dto/language-detection-state.d.ts +5 -0
  22. package/built/api/file-translations/dto/language-detection-state.js +10 -0
  23. package/built/api/file-translations/dto/language-detection-state.js.map +1 -0
  24. package/built/api/file-translations/dto/language-detection-status-dto.d.ts +9 -0
  25. package/built/api/file-translations/dto/language-detection-status-dto.js +3 -0
  26. package/built/api/file-translations/dto/language-detection-status-dto.js.map +1 -0
  27. package/built/api/file-translations/dto/language-dto.d.ts +5 -0
  28. package/built/api/file-translations/dto/language-dto.js +3 -0
  29. package/built/api/file-translations/dto/language-dto.js.map +1 -0
  30. package/built/api/file-translations/dto/mt-state.d.ts +7 -0
  31. package/built/api/file-translations/dto/mt-state.js +12 -0
  32. package/built/api/file-translations/dto/mt-state.js.map +1 -0
  33. package/built/api/file-translations/dto/translation-dto.d.ts +4 -0
  34. package/built/api/file-translations/dto/translation-dto.js +3 -0
  35. package/built/api/file-translations/dto/translation-dto.js.map +1 -0
  36. package/built/api/file-translations/dto/translation-locale-status-dto.d.ts +9 -0
  37. package/built/api/file-translations/dto/translation-locale-status-dto.js +3 -0
  38. package/built/api/file-translations/dto/translation-locale-status-dto.js.map +1 -0
  39. package/built/api/file-translations/dto/translation-status-dto.d.ts +10 -0
  40. package/built/api/file-translations/dto/translation-status-dto.js +3 -0
  41. package/built/api/file-translations/dto/translation-status-dto.js.map +1 -0
  42. package/built/api/file-translations/dto/uploaded-file-dto.d.ts +4 -0
  43. package/built/api/file-translations/dto/uploaded-file-dto.js +3 -0
  44. package/built/api/file-translations/dto/uploaded-file-dto.js.map +1 -0
  45. package/built/api/file-translations/index.d.ts +23 -0
  46. package/built/api/file-translations/index.js +78 -0
  47. package/built/api/file-translations/index.js.map +1 -0
  48. package/built/api/file-translations/params/translate-file-parameters.d.ts +5 -0
  49. package/built/api/file-translations/params/translate-file-parameters.js +16 -0
  50. package/built/api/file-translations/params/translate-file-parameters.js.map +1 -0
  51. package/built/api/file-translations/params/upload-file-parameters.d.ts +8 -0
  52. package/built/api/file-translations/params/upload-file-parameters.js +52 -0
  53. package/built/api/file-translations/params/upload-file-parameters.js.map +1 -0
  54. package/built/package.json +1 -1
  55. package/package.json +1 -1
  56. package/test/builder.spec.ts +8 -0
  57. 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=AYwW7p9HRe7rJHsZ61nW
6
- ceTaskUrl=https://sonar-next.connectors.stg.smartling.net/api/ce/task?id=AYwW7p9HRe7rJHsZ61nW
5
+ ceTaskId=AYyGVn8fRe7rJHsZ61oS
6
+ ceTaskUrl=https://sonar-next.connectors.stg.smartling.net/api/ce/task?id=AYyGVn8fRe7rJHsZ61oS
@@ -0,0 +1,7 @@
1
+ interface Error {
2
+ key: string,
3
+ message: string,
4
+ details: unknown
5
+ }
6
+
7
+ export { Error };
@@ -0,0 +1,5 @@
1
+ interface LanguageDetectionDto {
2
+ languageDetectionUid: string,
3
+ }
4
+
5
+ export { LanguageDetectionDto };
@@ -0,0 +1,5 @@
1
+ export enum LanguageDetectionState {
2
+ QUEUED = "QUEUED",
3
+ FAILED = "FAILED",
4
+ COMPLETED = "COMPLETED"
5
+ }
@@ -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,6 @@
1
+ interface LanguageDto {
2
+ languageId: string,
3
+ defaultLocaleId: string
4
+ }
5
+
6
+ export { LanguageDto };
@@ -0,0 +1,7 @@
1
+ export enum MTState {
2
+ QUEUED = "QUEUED",
3
+ PROCESSING = "PROCESSING",
4
+ FAILED = "FAILED",
5
+ CANCELED = "CANCELED",
6
+ COMPLETED = "COMPLETED"
7
+ }
@@ -0,0 +1,5 @@
1
+ interface TranslationDto {
2
+ mtUid: string
3
+ }
4
+
5
+ export { TranslationDto };
@@ -0,0 +1,11 @@
1
+ import { MTState } from "./mt-state";
2
+ import { Error } from "./error";
3
+
4
+ interface TranslationLocaleStatusDto {
5
+ localeId: string,
6
+ state: MTState,
7
+ processedStringCount: number,
8
+ error?: Error,
9
+ }
10
+
11
+ export { TranslationLocaleStatusDto };
@@ -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,5 @@
1
+ interface UploadedFileDto {
2
+ fileUid: string
3
+ }
4
+
5
+ export { UploadedFileDto };
@@ -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 { UploadedFileDto } from "./dto/uploaded-file-dto";
6
+ import { UploadFileParameters } from "./params/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: UploadFileParameters
22
+ ): Promise<UploadedFileDto> {
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,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,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 UploadFileParameters extends BaseParameters {
7
+ constructor(parameters: Record<string, unknown> = {}) {
8
+ super(parameters);
9
+
10
+ this.set("request", {});
11
+ }
12
+
13
+ setFileFromLocalFilePath(filePath: string): UploadFileParameters {
14
+ this.set("file", fs.createReadStream(
15
+ fs.realpathSync(filePath)
16
+ ));
17
+ return this;
18
+ }
19
+
20
+ setFileContent(fileContent: string): UploadFileParameters {
21
+ this.set("file", string2fileStream(fileContent));
22
+ return this;
23
+ }
24
+
25
+ setFileType(fileType: FileType): UploadFileParameters {
26
+ this.parameters.request.fileType = fileType.toUpperCase();
27
+ return this;
28
+ }
29
+ }
@@ -0,0 +1,6 @@
1
+ interface Error {
2
+ key: string;
3
+ message: string;
4
+ details: unknown;
5
+ }
6
+ export { Error };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/error.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ interface LanguageDetectionDto {
2
+ languageDetectionUid: string;
3
+ }
4
+ export { LanguageDetectionDto };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=language-detection-dto.js.map
@@ -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,5 @@
1
+ export declare enum LanguageDetectionState {
2
+ QUEUED = "QUEUED",
3
+ FAILED = "FAILED",
4
+ COMPLETED = "COMPLETED"
5
+ }
@@ -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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=language-detection-status-dto.js.map
@@ -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,5 @@
1
+ interface LanguageDto {
2
+ languageId: string;
3
+ defaultLocaleId: string;
4
+ }
5
+ export { LanguageDto };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=language-dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language-dto.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/language-dto.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export declare enum MTState {
2
+ QUEUED = "QUEUED",
3
+ PROCESSING = "PROCESSING",
4
+ FAILED = "FAILED",
5
+ CANCELED = "CANCELED",
6
+ COMPLETED = "COMPLETED"
7
+ }
@@ -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,4 @@
1
+ interface TranslationDto {
2
+ mtUid: string;
3
+ }
4
+ export { TranslationDto };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=translation-dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translation-dto.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/translation-dto.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import { MTState } from "./mt-state";
2
+ import { Error } from "./error";
3
+ interface TranslationLocaleStatusDto {
4
+ localeId: string;
5
+ state: MTState;
6
+ processedStringCount: number;
7
+ error?: Error;
8
+ }
9
+ export { TranslationLocaleStatusDto };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=translation-locale-status-dto.js.map
@@ -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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=translation-status-dto.js.map
@@ -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,4 @@
1
+ interface UploadedFileDto {
2
+ fileUid: string;
3
+ }
4
+ export { UploadedFileDto };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=uploaded-file-dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploaded-file-dto.js","sourceRoot":"","sources":["../../../../api/file-translations/dto/uploaded-file-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 { UploadedFileDto } from "./dto/uploaded-file-dto";
6
+ import { UploadFileParameters } from "./params/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: UploadFileParameters): Promise<UploadedFileDto>;
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,5 @@
1
+ import { BaseParameters } from "../../parameters";
2
+ export declare class TranslateFileParameters extends BaseParameters {
3
+ setSourceLocaleId(sourceLocaleId: string): TranslateFileParameters;
4
+ setTargetLocaleIds(targetLocaleIds: string[]): TranslateFileParameters;
5
+ }
@@ -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"}
@@ -0,0 +1,8 @@
1
+ import { BaseParameters } from "../../parameters";
2
+ import { FileType } from "../../files/params/file-type";
3
+ export declare class UploadFileParameters extends BaseParameters {
4
+ constructor(parameters?: Record<string, unknown>);
5
+ setFileFromLocalFilePath(filePath: string): UploadFileParameters;
6
+ setFileContent(fileContent: string): UploadFileParameters;
7
+ setFileType(fileType: FileType): UploadFileParameters;
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.UploadFileParameters = 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 UploadFileParameters 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.UploadFileParameters = UploadFileParameters;
52
+ //# sourceMappingURL=upload-file-parameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-file-parameters.js","sourceRoot":"","sources":["../../../../api/file-translations/params/upload-file-parameters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,kFAAsD;AACtD,iDAAkD;AAGlD,MAAa,oBAAqB,SAAQ,2BAAc;IACpD,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,oDAuBC"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smartling-api-sdk-nodejs",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Package for Smartling API",
5
5
  "main": "built/index.js",
6
6
  "engines": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smartling-api-sdk-nodejs",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Package for Smartling API",
5
5
  "main": "built/index.js",
6
6
  "engines": {
@@ -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 { UploadFileParameters } from "../api/file-translations/params/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 UploadFileParameters();
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 UploadFileParameters();
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
+ });