smartling-api-sdk-nodejs 2.17.0 → 2.19.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 (49) hide show
  1. package/.scannerwork/report-task.txt +2 -2
  2. package/api/file-translations/index.ts +6 -2
  3. package/api/file-translations/params/base-parameters-with-callback.ts +9 -0
  4. package/api/file-translations/params/fts-callback-method.ts +6 -0
  5. package/api/file-translations/params/fts-callback-parameter.ts +9 -0
  6. package/api/file-translations/params/language-detection-parameters.ts +4 -0
  7. package/api/file-translations/params/translate-file-parameters.ts +2 -2
  8. package/api/mt/dto/translation-text-item-dto.ts +6 -0
  9. package/api/mt/index.ts +25 -0
  10. package/api/mt/params/smartling-mt-parameters.ts +40 -0
  11. package/api/mt/params/source-text-item.ts +6 -0
  12. package/built/api/file-translations/index.d.ts +2 -1
  13. package/built/api/file-translations/index.js +2 -2
  14. package/built/api/file-translations/index.js.map +1 -1
  15. package/built/api/file-translations/params/base-parameters-with-callback.d.ts +5 -0
  16. package/built/api/file-translations/params/base-parameters-with-callback.js +12 -0
  17. package/built/api/file-translations/params/base-parameters-with-callback.js.map +1 -0
  18. package/built/api/file-translations/params/fts-callback-method.d.ts +4 -0
  19. package/built/api/file-translations/params/fts-callback-method.js +9 -0
  20. package/built/api/file-translations/params/fts-callback-method.js.map +1 -0
  21. package/built/api/file-translations/params/fts-callback-parameter.d.ts +7 -0
  22. package/built/api/file-translations/params/fts-callback-parameter.js +3 -0
  23. package/built/api/file-translations/params/fts-callback-parameter.js.map +1 -0
  24. package/built/api/file-translations/params/language-detection-parameters.d.ts +3 -0
  25. package/built/api/file-translations/params/language-detection-parameters.js +8 -0
  26. package/built/api/file-translations/params/language-detection-parameters.js.map +1 -0
  27. package/built/api/file-translations/params/translate-file-parameters.d.ts +2 -2
  28. package/built/api/file-translations/params/translate-file-parameters.js +2 -2
  29. package/built/api/file-translations/params/translate-file-parameters.js.map +1 -1
  30. package/built/api/mt/dto/translation-text-item-dto.d.ts +5 -0
  31. package/built/api/mt/dto/translation-text-item-dto.js +3 -0
  32. package/built/api/mt/dto/translation-text-item-dto.js.map +1 -0
  33. package/built/api/mt/index.d.ts +10 -0
  34. package/built/api/mt/index.js +27 -0
  35. package/built/api/mt/index.js.map +1 -0
  36. package/built/api/mt/params/smartling-mt-parameters.d.ts +5 -0
  37. package/built/api/mt/params/smartling-mt-parameters.js +38 -0
  38. package/built/api/mt/params/smartling-mt-parameters.js.map +1 -0
  39. package/built/api/mt/params/source-text-item.d.ts +5 -0
  40. package/built/api/mt/params/source-text-item.js +3 -0
  41. package/built/api/mt/params/source-text-item.js.map +1 -0
  42. package/built/index.d.ts +7 -0
  43. package/built/index.js +7 -0
  44. package/built/index.js.map +1 -1
  45. package/built/package.json +1 -1
  46. package/index.ts +7 -0
  47. package/package.json +1 -1
  48. package/test/file-translations.spec.ts +154 -0
  49. package/test/mt.spec.ts +165 -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=AZT-MpEN_0lymG1kFSkV
6
- ceTaskUrl=https://sonar-next.connectors.stg.smartling.net/api/ce/task?id=AZT-MpEN_0lymG1kFSkV
5
+ ceTaskId=AZVHo229fYfLTOL0FF0f
6
+ ceTaskUrl=https://sonar-next.connectors.stg.smartling.net/api/ce/task?id=AZVHo229fYfLTOL0FF0f
@@ -11,6 +11,7 @@ import { LanguageDetectionDto } from "./dto/language-detection-dto";
11
11
  import { LanguageDetectionStatusDto } from "./dto/language-detection-status-dto";
12
12
  import { TranslatedFileDto } from "./dto/translated-file-dto";
13
13
  import { ResponseBodyType } from "../base/enum/response-body-type";
14
+ import { LanguageDetectionParameters } from "./params/language-detection-parameters";
14
15
 
15
16
  export class SmartlingFileTranslationsApi extends SmartlingBaseApi {
16
17
  constructor(smartlingApiBaseUrl: string, authApi: SmartlingAuthApi, logger: Logger) {
@@ -123,10 +124,13 @@ export class SmartlingFileTranslationsApi extends SmartlingBaseApi {
123
124
  );
124
125
  }
125
126
 
126
- async detectFileLanguage(accountUid: string, fileUid: string): Promise<LanguageDetectionDto> {
127
+ async detectFileLanguage(
128
+ accountUid: string, fileUid: string, params?: LanguageDetectionParameters
129
+ ): Promise<LanguageDetectionDto> {
127
130
  return await this.makeRequest(
128
131
  "post",
129
- `${this.entrypoint}/${accountUid}/files/${fileUid}/language-detection`
132
+ `${this.entrypoint}/${accountUid}/files/${fileUid}/language-detection`,
133
+ JSON.stringify(params?.export())
130
134
  );
131
135
  }
132
136
 
@@ -0,0 +1,9 @@
1
+ import { BaseParameters } from "../../parameters";
2
+ import { FtsCallback } from "./fts-callback-parameter";
3
+
4
+ export class BaseParametersWithCallback extends BaseParameters {
5
+ setCallback(callback: FtsCallback): this {
6
+ this.parameters.callback = callback;
7
+ return this;
8
+ }
9
+ }
@@ -0,0 +1,6 @@
1
+ enum FtsCallbackMethod {
2
+ // Other HTTP methods are not supported by API for now
3
+ POST = "POST"
4
+ }
5
+
6
+ export { FtsCallbackMethod };
@@ -0,0 +1,9 @@
1
+ import { FtsCallbackMethod } from "./fts-callback-method";
2
+
3
+ interface FtsCallback {
4
+ url: string;
5
+ httpMethod: FtsCallbackMethod;
6
+ userData?: string
7
+ }
8
+
9
+ export { FtsCallback };
@@ -0,0 +1,4 @@
1
+ import { BaseParametersWithCallback } from "./base-parameters-with-callback";
2
+
3
+ export class LanguageDetectionParameters extends BaseParametersWithCallback {
4
+ }
@@ -1,6 +1,6 @@
1
- import { BaseParameters } from "../../parameters";
1
+ import { BaseParametersWithCallback } from "./base-parameters-with-callback";
2
2
 
3
- export class TranslateFileParameters extends BaseParameters {
3
+ export class TranslateFileParameters extends BaseParametersWithCallback {
4
4
  setSourceLocaleId(sourceLocaleId: string): TranslateFileParameters {
5
5
  this.set("sourceLocaleId", sourceLocaleId);
6
6
  return this;
@@ -0,0 +1,6 @@
1
+ interface TranslationTextItemDto {
2
+ key: string;
3
+ translationText: string;
4
+ }
5
+
6
+ export { TranslationTextItemDto };
@@ -0,0 +1,25 @@
1
+ import { SmartlingBaseApi } from "../base/index";
2
+ import { SmartlingAuthApi } from "../auth/index";
3
+ import { Logger } from "../logger";
4
+ import { SmartlingMTParameters } from "./params/smartling-mt-parameters";
5
+ import { SmartlingListResponse } from "../http/smartling-list-response";
6
+ import { TranslationTextItemDto } from "./dto/translation-text-item-dto";
7
+
8
+ export class SmartlingMachineTranslationsApi extends SmartlingBaseApi {
9
+ constructor(smartlingApiBaseUrl: string, authApi: SmartlingAuthApi, logger: Logger) {
10
+ super(logger);
11
+ this.authApi = authApi;
12
+ this.entrypoint = `${smartlingApiBaseUrl}/mt-router-api/v2/accounts`;
13
+ }
14
+
15
+ async translate(
16
+ accountUid: string,
17
+ params: SmartlingMTParameters
18
+ ): Promise<SmartlingListResponse<TranslationTextItemDto>> {
19
+ return await this.makeRequest(
20
+ "post",
21
+ `${this.entrypoint}/${accountUid}/smartling-mt`,
22
+ JSON.stringify(params.export())
23
+ );
24
+ }
25
+ }
@@ -0,0 +1,40 @@
1
+ import { SmartlingException } from "../../exception";
2
+ import { BaseParameters } from "../../parameters";
3
+ import { SourceTextItem } from "./source-text-item";
4
+
5
+ const MAX_ALLOWED_SOURCE_ITEMS = 1000;
6
+ const MAX_ALLOWED_KEY_LENGTH = 255;
7
+ const MAX_ALLOWED_SOURCE_TEXT_LENGTH = 64 * 1024;
8
+
9
+ export class SmartlingMTParameters extends BaseParameters {
10
+ constructor(sourceLocaleId: string, targetLocaleId: string, items: SourceTextItem[]) {
11
+ super();
12
+
13
+ if (!items.length) {
14
+ throw new SmartlingException("At least one source text item is required.");
15
+ }
16
+
17
+ if (items.length > MAX_ALLOWED_SOURCE_ITEMS) {
18
+ throw new SmartlingException(`The request contains too many source text items: ${items.length}. Maximum allowed items number is ${MAX_ALLOWED_SOURCE_ITEMS}.`);
19
+ }
20
+
21
+ items.forEach((sourceTextItem, index) => {
22
+ if (!sourceTextItem.key.length) {
23
+ throw new SmartlingException(`The key is requred for items[${index}].`);
24
+ }
25
+ if (sourceTextItem.key.length > MAX_ALLOWED_KEY_LENGTH) {
26
+ throw new SmartlingException(`The key is too long for items[${index}]: ${sourceTextItem.key.length}. Maximum allowed key length is ${MAX_ALLOWED_KEY_LENGTH}.`);
27
+ }
28
+ if (!sourceTextItem.sourceText.length) {
29
+ throw new SmartlingException(`The source text is requred for items[${index}].`);
30
+ }
31
+ if (sourceTextItem.sourceText.length > MAX_ALLOWED_SOURCE_TEXT_LENGTH) {
32
+ throw new SmartlingException(`The source text is too long for items[${index}]: ${sourceTextItem.sourceText.length}. Maximum allowed source text length is ${MAX_ALLOWED_SOURCE_TEXT_LENGTH}.`);
33
+ }
34
+ });
35
+
36
+ this.set("sourceLocaleId", sourceLocaleId);
37
+ this.set("targetLocaleId", targetLocaleId);
38
+ this.set("items", items);
39
+ }
40
+ }
@@ -0,0 +1,6 @@
1
+ interface SourceTextItem {
2
+ key: string;
3
+ sourceText: string;
4
+ }
5
+
6
+ export { SourceTextItem };
@@ -10,6 +10,7 @@ import { TranslationStatusDto } from "./dto/translation-status-dto";
10
10
  import { LanguageDetectionDto } from "./dto/language-detection-dto";
11
11
  import { LanguageDetectionStatusDto } from "./dto/language-detection-status-dto";
12
12
  import { TranslatedFileDto } from "./dto/translated-file-dto";
13
+ import { LanguageDetectionParameters } from "./params/language-detection-parameters";
13
14
  export declare class SmartlingFileTranslationsApi extends SmartlingBaseApi {
14
15
  constructor(smartlingApiBaseUrl: string, authApi: SmartlingAuthApi, logger: Logger);
15
16
  uploadFile(accountUid: string, parameters: FtsUploadFileParameters): Promise<FtsUploadedFileDto>;
@@ -20,7 +21,7 @@ export declare class SmartlingFileTranslationsApi extends SmartlingBaseApi {
20
21
  downloadTranslatedFiles(accountUid: string, fileUid: string, mtUid: string): Promise<ArrayBuffer>;
21
22
  downloadTranslatedFilesWithMetadata(accountUid: string, fileUid: string, mtUid: string): Promise<TranslatedFileDto>;
22
23
  cancelFileTranslation(accountUid: string, fileUid: string, mtUid: string): Promise<void>;
23
- detectFileLanguage(accountUid: string, fileUid: string): Promise<LanguageDetectionDto>;
24
+ detectFileLanguage(accountUid: string, fileUid: string, params?: LanguageDetectionParameters): Promise<LanguageDetectionDto>;
24
25
  getLanguageDetectionProgress(accountUid: string, fileUid: string, languageDetectionUid: string): Promise<LanguageDetectionStatusDto>;
25
26
  static fixContentTypeHeaderCase(form: FormData): Record<string, unknown>;
26
27
  private static downloadResponseToTranslatedFileDto;
@@ -75,9 +75,9 @@ class SmartlingFileTranslationsApi extends base_1.SmartlingBaseApi {
75
75
  yield this.makeRequest("post", `${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/cancel`);
76
76
  });
77
77
  }
78
- detectFileLanguage(accountUid, fileUid) {
78
+ detectFileLanguage(accountUid, fileUid, params) {
79
79
  return __awaiter(this, void 0, void 0, function* () {
80
- return yield this.makeRequest("post", `${this.entrypoint}/${accountUid}/files/${fileUid}/language-detection`);
80
+ return yield this.makeRequest("post", `${this.entrypoint}/${accountUid}/files/${fileUid}/language-detection`, JSON.stringify(params === null || params === void 0 ? void 0 : params.export()));
81
81
  });
82
82
  }
83
83
  getLanguageDetectionProgress(accountUid, fileUid, languageDetectionUid) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/file-translations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAAiC;AACjC,kCAA2C;AAW3C,wEAAmE;AAEnE,MAAa,4BAA6B,SAAQ,uBAAgB;IAC9D,YAAY,mBAA2B,EAAE,OAAyB,EAAE,MAAc;QAC9E,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,GAAG,mBAAmB,oCAAoC,CAAC;IACjF,CA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AAO,CAAC;IACnB,CAAC;IAEO,MAAM,CAAO,mCAAmC,CACpD,QAAkB;;;YAElB,MAAM,WAAW,GAAG,MAAA,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,mCAAI,SAAS,CAAC;YACtE,MAAM,kBAAkB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;YACvE,IAAI,QAAQ,CAAC;YACb,IAAI,kBAAkB,EAAE;gBACpB,MAAM,aAAa,GAAG,kBAAkB,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;gBAC/E,IAAI,aAAa,EAAE;oBACf,QAAQ,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;iBACrD;aACJ;YACD,OAAO;gBACH,WAAW,EAAE,MAAM,QAAQ,CAAC,WAAW,EAAE;gBACzC,QAAQ;gBACR,WAAW;aACd,CAAC;;KACL;CACJ;AA7JD,oEA6JC"}
@@ -0,0 +1,5 @@
1
+ import { BaseParameters } from "../../parameters";
2
+ import { FtsCallback } from "./fts-callback-parameter";
3
+ export declare class BaseParametersWithCallback extends BaseParameters {
4
+ setCallback(callback: FtsCallback): this;
5
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseParametersWithCallback = void 0;
4
+ const parameters_1 = require("../../parameters");
5
+ class BaseParametersWithCallback extends parameters_1.BaseParameters {
6
+ setCallback(callback) {
7
+ this.parameters.callback = callback;
8
+ return this;
9
+ }
10
+ }
11
+ exports.BaseParametersWithCallback = BaseParametersWithCallback;
12
+ //# sourceMappingURL=base-parameters-with-callback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-parameters-with-callback.js","sourceRoot":"","sources":["../../../../api/file-translations/params/base-parameters-with-callback.ts"],"names":[],"mappings":";;;AAAA,iDAAkD;AAGlD,MAAa,0BAA2B,SAAQ,2BAAc;IAC1D,WAAW,CAAC,QAAqB;QAC7B,IAAI,CAAC,UAAU,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACpC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AALD,gEAKC"}
@@ -0,0 +1,4 @@
1
+ declare enum FtsCallbackMethod {
2
+ POST = "POST"
3
+ }
4
+ export { FtsCallbackMethod };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FtsCallbackMethod = void 0;
4
+ var FtsCallbackMethod;
5
+ (function (FtsCallbackMethod) {
6
+ FtsCallbackMethod["POST"] = "POST";
7
+ })(FtsCallbackMethod || (FtsCallbackMethod = {}));
8
+ exports.FtsCallbackMethod = FtsCallbackMethod;
9
+ //# sourceMappingURL=fts-callback-method.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fts-callback-method.js","sourceRoot":"","sources":["../../../../api/file-translations/params/fts-callback-method.ts"],"names":[],"mappings":";;;AAAA,IAAK,iBAGJ;AAHD,WAAK,iBAAiB;IAElB,kCAAa,CAAA;AACjB,CAAC,EAHI,iBAAiB,KAAjB,iBAAiB,QAGrB;AAEQ,8CAAiB"}
@@ -0,0 +1,7 @@
1
+ import { FtsCallbackMethod } from "./fts-callback-method";
2
+ interface FtsCallback {
3
+ url: string;
4
+ httpMethod: FtsCallbackMethod;
5
+ userData?: string;
6
+ }
7
+ export { FtsCallback };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=fts-callback-parameter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fts-callback-parameter.js","sourceRoot":"","sources":["../../../../api/file-translations/params/fts-callback-parameter.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import { BaseParametersWithCallback } from "./base-parameters-with-callback";
2
+ export declare class LanguageDetectionParameters extends BaseParametersWithCallback {
3
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LanguageDetectionParameters = void 0;
4
+ const base_parameters_with_callback_1 = require("./base-parameters-with-callback");
5
+ class LanguageDetectionParameters extends base_parameters_with_callback_1.BaseParametersWithCallback {
6
+ }
7
+ exports.LanguageDetectionParameters = LanguageDetectionParameters;
8
+ //# sourceMappingURL=language-detection-parameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"language-detection-parameters.js","sourceRoot":"","sources":["../../../../api/file-translations/params/language-detection-parameters.ts"],"names":[],"mappings":";;;AAAA,mFAA6E;AAE7E,MAAa,2BAA4B,SAAQ,0DAA0B;CAC1E;AADD,kEACC"}
@@ -1,5 +1,5 @@
1
- import { BaseParameters } from "../../parameters";
2
- export declare class TranslateFileParameters extends BaseParameters {
1
+ import { BaseParametersWithCallback } from "./base-parameters-with-callback";
2
+ export declare class TranslateFileParameters extends BaseParametersWithCallback {
3
3
  setSourceLocaleId(sourceLocaleId: string): TranslateFileParameters;
4
4
  setTargetLocaleIds(targetLocaleIds: string[]): TranslateFileParameters;
5
5
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TranslateFileParameters = void 0;
4
- const parameters_1 = require("../../parameters");
5
- class TranslateFileParameters extends parameters_1.BaseParameters {
4
+ const base_parameters_with_callback_1 = require("./base-parameters-with-callback");
5
+ class TranslateFileParameters extends base_parameters_with_callback_1.BaseParametersWithCallback {
6
6
  setSourceLocaleId(sourceLocaleId) {
7
7
  this.set("sourceLocaleId", sourceLocaleId);
8
8
  return this;
@@ -1 +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"}
1
+ {"version":3,"file":"translate-file-parameters.js","sourceRoot":"","sources":["../../../../api/file-translations/params/translate-file-parameters.ts"],"names":[],"mappings":";;;AAAA,mFAA6E;AAE7E,MAAa,uBAAwB,SAAQ,0DAA0B;IACnE,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,5 @@
1
+ interface TranslationTextItemDto {
2
+ key: string;
3
+ translationText: string;
4
+ }
5
+ export { TranslationTextItemDto };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=translation-text-item-dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translation-text-item-dto.js","sourceRoot":"","sources":["../../../../api/mt/dto/translation-text-item-dto.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { SmartlingBaseApi } from "../base/index";
2
+ import { SmartlingAuthApi } from "../auth/index";
3
+ import { Logger } from "../logger";
4
+ import { SmartlingMTParameters } from "./params/smartling-mt-parameters";
5
+ import { SmartlingListResponse } from "../http/smartling-list-response";
6
+ import { TranslationTextItemDto } from "./dto/translation-text-item-dto";
7
+ export declare class SmartlingMachineTranslationsApi extends SmartlingBaseApi {
8
+ constructor(smartlingApiBaseUrl: string, authApi: SmartlingAuthApi, logger: Logger);
9
+ translate(accountUid: string, params: SmartlingMTParameters): Promise<SmartlingListResponse<TranslationTextItemDto>>;
10
+ }
@@ -0,0 +1,27 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SmartlingMachineTranslationsApi = void 0;
13
+ const index_1 = require("../base/index");
14
+ class SmartlingMachineTranslationsApi extends index_1.SmartlingBaseApi {
15
+ constructor(smartlingApiBaseUrl, authApi, logger) {
16
+ super(logger);
17
+ this.authApi = authApi;
18
+ this.entrypoint = `${smartlingApiBaseUrl}/mt-router-api/v2/accounts`;
19
+ }
20
+ translate(accountUid, params) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return yield this.makeRequest("post", `${this.entrypoint}/${accountUid}/smartling-mt`, JSON.stringify(params.export()));
23
+ });
24
+ }
25
+ }
26
+ exports.SmartlingMachineTranslationsApi = SmartlingMachineTranslationsApi;
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/mt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAiD;AAOjD,MAAa,+BAAgC,SAAQ,wBAAgB;IACjE,YAAY,mBAA2B,EAAE,OAAyB,EAAE,MAAc;QAC9E,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,GAAG,mBAAmB,4BAA4B,CAAC;IACzE,CAAC;IAEK,SAAS,CACX,UAAkB,EAClB,MAA6B;;YAE7B,OAAO,MAAM,IAAI,CAAC,WAAW,CACzB,MAAM,EACN,GAAG,IAAI,CAAC,UAAU,IAAI,UAAU,eAAe,EAC/C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAClC,CAAC;QACN,CAAC;KAAA;CACJ;AAjBD,0EAiBC"}
@@ -0,0 +1,5 @@
1
+ import { BaseParameters } from "../../parameters";
2
+ import { SourceTextItem } from "./source-text-item";
3
+ export declare class SmartlingMTParameters extends BaseParameters {
4
+ constructor(sourceLocaleId: string, targetLocaleId: string, items: SourceTextItem[]);
5
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SmartlingMTParameters = void 0;
4
+ const exception_1 = require("../../exception");
5
+ const parameters_1 = require("../../parameters");
6
+ const MAX_ALLOWED_SOURCE_ITEMS = 1000;
7
+ const MAX_ALLOWED_KEY_LENGTH = 255;
8
+ const MAX_ALLOWED_SOURCE_TEXT_LENGTH = 64 * 1024;
9
+ class SmartlingMTParameters extends parameters_1.BaseParameters {
10
+ constructor(sourceLocaleId, targetLocaleId, items) {
11
+ super();
12
+ if (!items.length) {
13
+ throw new exception_1.SmartlingException("At least one source text item is required.");
14
+ }
15
+ if (items.length > MAX_ALLOWED_SOURCE_ITEMS) {
16
+ throw new exception_1.SmartlingException(`The request contains too many source text items: ${items.length}. Maximum allowed items number is ${MAX_ALLOWED_SOURCE_ITEMS}.`);
17
+ }
18
+ items.forEach((sourceTextItem, index) => {
19
+ if (!sourceTextItem.key.length) {
20
+ throw new exception_1.SmartlingException(`The key is requred for items[${index}].`);
21
+ }
22
+ if (sourceTextItem.key.length > MAX_ALLOWED_KEY_LENGTH) {
23
+ throw new exception_1.SmartlingException(`The key is too long for items[${index}]: ${sourceTextItem.key.length}. Maximum allowed key length is ${MAX_ALLOWED_KEY_LENGTH}.`);
24
+ }
25
+ if (!sourceTextItem.sourceText.length) {
26
+ throw new exception_1.SmartlingException(`The source text is requred for items[${index}].`);
27
+ }
28
+ if (sourceTextItem.sourceText.length > MAX_ALLOWED_SOURCE_TEXT_LENGTH) {
29
+ throw new exception_1.SmartlingException(`The source text is too long for items[${index}]: ${sourceTextItem.sourceText.length}. Maximum allowed source text length is ${MAX_ALLOWED_SOURCE_TEXT_LENGTH}.`);
30
+ }
31
+ });
32
+ this.set("sourceLocaleId", sourceLocaleId);
33
+ this.set("targetLocaleId", targetLocaleId);
34
+ this.set("items", items);
35
+ }
36
+ }
37
+ exports.SmartlingMTParameters = SmartlingMTParameters;
38
+ //# sourceMappingURL=smartling-mt-parameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smartling-mt-parameters.js","sourceRoot":"","sources":["../../../../api/mt/params/smartling-mt-parameters.ts"],"names":[],"mappings":";;;AAAA,+CAAqD;AACrD,iDAAkD;AAGlD,MAAM,wBAAwB,GAAG,IAAI,CAAC;AACtC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,8BAA8B,GAAG,EAAE,GAAG,IAAI,CAAC;AAEjD,MAAa,qBAAsB,SAAQ,2BAAc;IACrD,YAAY,cAAsB,EAAE,cAAsB,EAAE,KAAuB;QAC/E,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACf,MAAM,IAAI,8BAAkB,CAAC,4CAA4C,CAAC,CAAC;SAC9E;QAED,IAAI,KAAK,CAAC,MAAM,GAAG,wBAAwB,EAAE;YACzC,MAAM,IAAI,8BAAkB,CAAC,oDAAoD,KAAK,CAAC,MAAM,qCAAqC,wBAAwB,GAAG,CAAC,CAAC;SAClK;QAED,KAAK,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,KAAK,EAAE,EAAE;YACpC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE;gBAC5B,MAAM,IAAI,8BAAkB,CAAC,gCAAgC,KAAK,IAAI,CAAC,CAAC;aAC3E;YACD,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,GAAG,sBAAsB,EAAE;gBACpD,MAAM,IAAI,8BAAkB,CAAC,iCAAiC,KAAK,MAAM,cAAc,CAAC,GAAG,CAAC,MAAM,mCAAmC,sBAAsB,GAAG,CAAC,CAAC;aACnK;YACD,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,EAAE;gBACnC,MAAM,IAAI,8BAAkB,CAAC,wCAAwC,KAAK,IAAI,CAAC,CAAC;aACnF;YACD,IAAI,cAAc,CAAC,UAAU,CAAC,MAAM,GAAG,8BAA8B,EAAE;gBACnE,MAAM,IAAI,8BAAkB,CAAC,yCAAyC,KAAK,MAAM,cAAc,CAAC,UAAU,CAAC,MAAM,2CAA2C,8BAA8B,GAAG,CAAC,CAAC;aAClM;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QAC3C,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QAC3C,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;CACJ;AA/BD,sDA+BC"}
@@ -0,0 +1,5 @@
1
+ interface SourceTextItem {
2
+ key: string;
3
+ sourceText: string;
4
+ }
5
+ export { SourceTextItem };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=source-text-item.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-text-item.js","sourceRoot":"","sources":["../../../../api/mt/params/source-text-item.ts"],"names":[],"mappings":""}
package/built/index.d.ts CHANGED
@@ -16,7 +16,10 @@ export * from "./api/context/params/list-parameters";
16
16
  export * from "./api/context/context-http-response";
17
17
  export * from "./api/exception/index";
18
18
  export * from "./api/file-translations/index";
19
+ export * from "./api/file-translations/params/fts-callback-parameter";
20
+ export * from "./api/file-translations/params/fts-callback-method";
19
21
  export * from "./api/file-translations/params/fts-upload-file-parameters";
22
+ export * from "./api/file-translations/params/language-detection-parameters";
20
23
  export * from "./api/file-translations/params/translate-file-parameters";
21
24
  export * from "./api/file-translations/dto/error";
22
25
  export * from "./api/file-translations/dto/fts-uploaded-file-dto";
@@ -107,3 +110,7 @@ export * from "./api/locales/dto/direction";
107
110
  export * from "./api/locales/dto/word-delimeter";
108
111
  export * from "./api/locales/params/get-locales-parameters";
109
112
  export * from "./api/locales/index";
113
+ export * from "./api/mt/index";
114
+ export * from "./api/mt/params/smartling-mt-parameters";
115
+ export * from "./api/mt/params/source-text-item";
116
+ export * from "./api/mt/dto/translation-text-item-dto";
package/built/index.js CHANGED
@@ -32,7 +32,10 @@ __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
34
  __exportStar(require("./api/file-translations/index"), exports);
35
+ __exportStar(require("./api/file-translations/params/fts-callback-parameter"), exports);
36
+ __exportStar(require("./api/file-translations/params/fts-callback-method"), exports);
35
37
  __exportStar(require("./api/file-translations/params/fts-upload-file-parameters"), exports);
38
+ __exportStar(require("./api/file-translations/params/language-detection-parameters"), exports);
36
39
  __exportStar(require("./api/file-translations/params/translate-file-parameters"), exports);
37
40
  __exportStar(require("./api/file-translations/dto/error"), exports);
38
41
  __exportStar(require("./api/file-translations/dto/fts-uploaded-file-dto"), exports);
@@ -123,4 +126,8 @@ __exportStar(require("./api/locales/dto/direction"), exports);
123
126
  __exportStar(require("./api/locales/dto/word-delimeter"), exports);
124
127
  __exportStar(require("./api/locales/params/get-locales-parameters"), exports);
125
128
  __exportStar(require("./api/locales/index"), exports);
129
+ __exportStar(require("./api/mt/index"), exports);
130
+ __exportStar(require("./api/mt/params/smartling-mt-parameters"), exports);
131
+ __exportStar(require("./api/mt/params/source-text-item"), exports);
132
+ __exportStar(require("./api/mt/dto/translation-text-item-dto"), exports);
126
133
  //# sourceMappingURL=index.js.map
@@ -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,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,6EAA2D;AAC3D,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,oFAAkE;AAClE,oFAAkE;AAClE,mFAAiE;AACjE,kFAAgE;AAChE,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,kE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AC7D,oEAAkD;AAClD,qEAAmD;AACnD,0DAAwC;AACxC,kEAAgD;AAChD,uEAAqD;AACrD,yEAAuD;AACvD,yEAAuD;AACvD,4EAA0D;AAC1D,oFAAkE;AAClE,oFAAkE;AAClE,mFAAiE;AACjE,kFAAgE;AAChE,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,oEAAkD;AAClD,0EAAwD;AACxD,6EAA2D;AAC3D,4EAA0D;AAC1D,+DAA6C;AAC7C,8EAA4D;AAC5D,yEAAuD;AACvD,2EAAyD;AACzD,0EAAwD;AACxD,yEAAuD;AACvD,2EAAyD;AACzD,0EAAwD;AACxD,yDAAuC;AACvC,yDAAuC;AACvC,uDAAqC;AACrC,iEAA+C;AAC/C,gEAA8C;AAC9C,8DAA4C;AAC5C,+EAA6D;AAC7D,mGAAiF;AACjF,sDAAoC;AACpC,sEAAoD;AACpD,0EAAwD;AACxD,uFAAqE;AACrE,+CAA6B;AAC7B,wEAAsD;AACtD,+FAA6E;AAC7E,6EAA2D;AAC3D,gEAA8C;AAC9C,2EAAyD;AACzD,yEAAuD;AACvD,8DAA4C;AAC5C,mEAAiD;AACjD,8EAA4D;AAC5D,sDAAoC;AACpC,iDAA+B;AAC/B,0EAAwD;AACxD,mEAAiD;AACjD,yEAAuD"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smartling-api-sdk-nodejs",
3
- "version": "2.17.0",
3
+ "version": "2.19.0",
4
4
  "description": "Package for Smartling API",
5
5
  "main": "built/index.js",
6
6
  "engines": {
package/index.ts CHANGED
@@ -16,7 +16,10 @@ export * from "./api/context/params/list-parameters";
16
16
  export * from "./api/context/context-http-response";
17
17
  export * from "./api/exception/index";
18
18
  export * from "./api/file-translations/index";
19
+ export * from "./api/file-translations/params/fts-callback-parameter";
20
+ export * from "./api/file-translations/params/fts-callback-method";
19
21
  export * from "./api/file-translations/params/fts-upload-file-parameters";
22
+ export * from "./api/file-translations/params/language-detection-parameters";
20
23
  export * from "./api/file-translations/params/translate-file-parameters";
21
24
  export * from "./api/file-translations/dto/error";
22
25
  export * from "./api/file-translations/dto/fts-uploaded-file-dto";
@@ -107,3 +110,7 @@ export * from "./api/locales/dto/direction";
107
110
  export * from "./api/locales/dto/word-delimeter";
108
111
  export * from "./api/locales/params/get-locales-parameters";
109
112
  export * from "./api/locales/index";
113
+ export * from "./api/mt/index";
114
+ export * from "./api/mt/params/smartling-mt-parameters";
115
+ export * from "./api/mt/params/source-text-item";
116
+ export * from "./api/mt/dto/translation-text-item-dto";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smartling-api-sdk-nodejs",
3
- "version": "2.17.0",
3
+ "version": "2.19.0",
4
4
  "description": "Package for Smartling API",
5
5
  "main": "built/index.js",
6
6
  "engines": {
@@ -9,6 +9,8 @@ import { FtsUploadFileParameters } from "../api/file-translations/params/fts-upl
9
9
  import { FileType } from "../api/files/params/file-type";
10
10
  import { streamToString } from "./stream-to-string";
11
11
  import { TranslateFileParameters } from "../api/file-translations/params/translate-file-parameters";
12
+ import { FtsCallbackMethod } from "../api/file-translations/params/fts-callback-method";
13
+ import { LanguageDetectionParameters } from "../api/file-translations/params/language-detection-parameters";
12
14
 
13
15
  describe("SmartlingFileTranslationsApi class tests.", () => {
14
16
  const userAgent = "test_user_agent";
@@ -327,6 +329,78 @@ describe("SmartlingFileTranslationsApi class tests.", () => {
327
329
  );
328
330
  });
329
331
 
332
+ it("Translate file with callback and without user data", async () => {
333
+ const params = new TranslateFileParameters();
334
+
335
+ params
336
+ .setSourceLocaleId("en-US")
337
+ .setTargetLocaleIds(["de-DE", "fr-FR"])
338
+ .setCallback({
339
+ url: "https://myhost.com",
340
+ httpMethod: FtsCallbackMethod.POST
341
+ });
342
+
343
+ await fileTranslationsApi.translateFile(accountUid, fileUid, params);
344
+
345
+ sinon.assert.calledOnceWithExactly(
346
+ fileTranslationsApiFetchStub,
347
+ `https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/mt`,
348
+ {
349
+ method: "post",
350
+ headers: {
351
+ Authorization: "test_token_type test_access_token",
352
+ "Content-Type": "application/json",
353
+ "User-Agent": userAgent
354
+ },
355
+ body: JSON.stringify({
356
+ sourceLocaleId: "en-US",
357
+ targetLocaleIds: ["de-DE", "fr-FR"],
358
+ callback: {
359
+ url: "https://myhost.com",
360
+ httpMethod: "POST"
361
+ }
362
+ })
363
+ }
364
+ );
365
+ });
366
+
367
+ it("Translate file with callback and user data", async () => {
368
+ const params = new TranslateFileParameters();
369
+
370
+ params
371
+ .setSourceLocaleId("en-US")
372
+ .setTargetLocaleIds(["de-DE", "fr-FR"])
373
+ .setCallback({
374
+ url: "https://myhost.com",
375
+ httpMethod: FtsCallbackMethod.POST,
376
+ userData: "test user data"
377
+ });
378
+
379
+ await fileTranslationsApi.translateFile(accountUid, fileUid, params);
380
+
381
+ sinon.assert.calledOnceWithExactly(
382
+ fileTranslationsApiFetchStub,
383
+ `https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/mt`,
384
+ {
385
+ method: "post",
386
+ headers: {
387
+ Authorization: "test_token_type test_access_token",
388
+ "Content-Type": "application/json",
389
+ "User-Agent": userAgent
390
+ },
391
+ body: JSON.stringify({
392
+ sourceLocaleId: "en-US",
393
+ targetLocaleIds: ["de-DE", "fr-FR"],
394
+ callback: {
395
+ url: "https://myhost.com",
396
+ httpMethod: "POST",
397
+ userData: "test user data"
398
+ }
399
+ })
400
+ }
401
+ );
402
+ });
403
+
330
404
  it("Get translation progress", async () => {
331
405
  await fileTranslationsApi.getTranslationProgress(accountUid, fileUid, mtUid);
332
406
 
@@ -547,6 +621,86 @@ describe("SmartlingFileTranslationsApi class tests.", () => {
547
621
  );
548
622
  });
549
623
 
624
+ it("Detect file language with empty parameters", async () => {
625
+ await fileTranslationsApi.detectFileLanguage(
626
+ accountUid, fileUid, new LanguageDetectionParameters()
627
+ );
628
+
629
+ sinon.assert.calledOnceWithExactly(
630
+ fileTranslationsApiFetchStub,
631
+ `https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/language-detection`,
632
+ {
633
+ method: "post",
634
+ headers: {
635
+ Authorization: "test_token_type test_access_token",
636
+ "Content-Type": "application/json",
637
+ "User-Agent": userAgent
638
+ },
639
+ body: JSON.stringify({})
640
+ }
641
+ );
642
+ });
643
+
644
+ it("Detect file language with callback and without user data", async () => {
645
+ const params = new LanguageDetectionParameters()
646
+ .setCallback({
647
+ url: "https://myhost.com",
648
+ httpMethod: FtsCallbackMethod.POST
649
+ });
650
+
651
+ await fileTranslationsApi.detectFileLanguage(accountUid, fileUid, params);
652
+
653
+ sinon.assert.calledOnceWithExactly(
654
+ fileTranslationsApiFetchStub,
655
+ `https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/language-detection`,
656
+ {
657
+ method: "post",
658
+ headers: {
659
+ Authorization: "test_token_type test_access_token",
660
+ "Content-Type": "application/json",
661
+ "User-Agent": userAgent
662
+ },
663
+ body: JSON.stringify({
664
+ callback: {
665
+ url: "https://myhost.com",
666
+ httpMethod: "POST"
667
+ }
668
+ })
669
+ }
670
+ );
671
+ });
672
+
673
+ it("Detect file language with callback and with user data", async () => {
674
+ const params = new LanguageDetectionParameters()
675
+ .setCallback({
676
+ url: "https://myhost.com",
677
+ httpMethod: FtsCallbackMethod.POST,
678
+ userData: "test user data"
679
+ });
680
+
681
+ await fileTranslationsApi.detectFileLanguage(accountUid, fileUid, params);
682
+
683
+ sinon.assert.calledOnceWithExactly(
684
+ fileTranslationsApiFetchStub,
685
+ `https://test.com/file-translations-api/v2/accounts/${accountUid}/files/${fileUid}/language-detection`,
686
+ {
687
+ method: "post",
688
+ headers: {
689
+ Authorization: "test_token_type test_access_token",
690
+ "Content-Type": "application/json",
691
+ "User-Agent": userAgent
692
+ },
693
+ body: JSON.stringify({
694
+ callback: {
695
+ url: "https://myhost.com",
696
+ httpMethod: "POST",
697
+ userData: "test user data"
698
+ }
699
+ })
700
+ }
701
+ );
702
+ });
703
+
550
704
  it("Get language detection progress", async () => {
551
705
  await fileTranslationsApi.getLanguageDetectionProgress(
552
706
  accountUid,
@@ -0,0 +1,165 @@
1
+ import sinon from "sinon";
2
+ import assert from "assert";
3
+ import { SmartlingMachineTranslationsApi } from "../api/mt";
4
+ import { SmartlingMTParameters } from "../api/mt/params/smartling-mt-parameters";
5
+ import { SmartlingAuthApi } from "../api/auth/index";
6
+ import { SmartlingException } from "../api/exception/index";
7
+ import { loggerMock, authMock, responseMock } from "./mock";
8
+
9
+ describe("SmartlinMachineTranslationsApi class tests.", () => {
10
+ const accountUid = "testAccountUid";
11
+ let mtApi;
12
+ let mtApiFetchStub;
13
+ let mtApiUaStub;
14
+ let responseMockTextStub;
15
+
16
+ beforeEach(() => {
17
+ mtApi = new SmartlingMachineTranslationsApi("https://test.com", authMock as unknown as SmartlingAuthApi, loggerMock);
18
+
19
+ mtApiFetchStub = sinon.stub(mtApi, "fetch");
20
+ mtApiUaStub = sinon.stub(mtApi, "ua");
21
+ responseMockTextStub = sinon.stub(responseMock, "text");
22
+
23
+ mtApiUaStub.returns("test_user_agent");
24
+ mtApiFetchStub.returns(responseMock);
25
+ responseMockTextStub.returns("{\"response\": {}}");
26
+ });
27
+
28
+ afterEach(() => {
29
+ mtApiFetchStub.restore();
30
+ responseMockTextStub.restore();
31
+ mtApiUaStub.restore();
32
+ });
33
+
34
+ it("Translate using Smartling MT", async () => {
35
+ const params = new SmartlingMTParameters(
36
+ "en-US",
37
+ "es-ES",
38
+ [{
39
+ key: "text.key",
40
+ sourceText: "This is text for translation"
41
+ }]
42
+ );
43
+ await mtApi.translate(accountUid, params);
44
+
45
+ sinon.assert.calledOnce(mtApiFetchStub);
46
+ sinon.assert.calledWithExactly(
47
+ mtApiFetchStub,
48
+ `https://test.com/mt-router-api/v2/accounts/${accountUid}/smartling-mt`, {
49
+ headers: {
50
+ Authorization: "test_token_type test_access_token",
51
+ "Content-Type": "application/json",
52
+ "User-Agent": "test_user_agent"
53
+ },
54
+ method: "post",
55
+ body: JSON.stringify({
56
+ sourceLocaleId: "en-US",
57
+ targetLocaleId: "es-ES",
58
+ items: [{
59
+ key: "text.key",
60
+ sourceText: "This is text for translation"
61
+ }]
62
+ })
63
+ }
64
+ );
65
+ });
66
+
67
+ it("Validation of MT parameters throws error when no source items specified", async () => {
68
+ try {
69
+ // eslint-disable-next-line no-new
70
+ new SmartlingMTParameters(
71
+ "en-US",
72
+ "es-ES",
73
+ []
74
+ );
75
+ assert.fail("must throw SmartlingException");
76
+ } catch (e) {
77
+ assert.ok(e instanceof SmartlingException);
78
+ }
79
+ });
80
+
81
+ it("Validation of MT parameters throws error when number of source items exceeds limit", async () => {
82
+ try {
83
+ // eslint-disable-next-line no-new
84
+ new SmartlingMTParameters(
85
+ "en-US",
86
+ "es-ES",
87
+ Array(1001).fill({
88
+ key: "key",
89
+ sourceText: "string for translation"
90
+ })
91
+ );
92
+ assert.fail("must throw SmartlingException");
93
+ } catch (e) {
94
+ assert.ok(e instanceof SmartlingException);
95
+ }
96
+ });
97
+
98
+ it("Validation of MT parameters throws error when source item has empty key", async () => {
99
+ try {
100
+ // eslint-disable-next-line no-new
101
+ new SmartlingMTParameters(
102
+ "en-US",
103
+ "es-ES",
104
+ [{
105
+ key: "",
106
+ sourceText: "text"
107
+ }]
108
+ );
109
+ assert.fail("must throw SmartlingException");
110
+ } catch (e) {
111
+ assert.ok(e instanceof SmartlingException);
112
+ }
113
+ });
114
+
115
+ it("Validation of MT parameters throws error when source item has long key", async () => {
116
+ try {
117
+ // eslint-disable-next-line no-new
118
+ new SmartlingMTParameters(
119
+ "en-US",
120
+ "es-ES",
121
+ [{
122
+ key: "A".repeat(256),
123
+ sourceText: "text"
124
+ }]
125
+ );
126
+ assert.fail("must throw SmartlingException");
127
+ } catch (e) {
128
+ assert.ok(e instanceof SmartlingException);
129
+ }
130
+ });
131
+
132
+ it("Validation of MT parameters throws error when source item has empty text", async () => {
133
+ try {
134
+ // eslint-disable-next-line no-new
135
+ new SmartlingMTParameters(
136
+ "en-US",
137
+ "es-ES",
138
+ [{
139
+ key: "key",
140
+ sourceText: ""
141
+ }]
142
+ );
143
+ assert.fail("must throw SmartlingException");
144
+ } catch (e) {
145
+ assert.ok(e instanceof SmartlingException);
146
+ }
147
+ });
148
+
149
+ it("Validation of MT parameters throws error when source item has long text", async () => {
150
+ try {
151
+ // eslint-disable-next-line no-new
152
+ new SmartlingMTParameters(
153
+ "en-US",
154
+ "es-ES",
155
+ [{
156
+ key: "key",
157
+ sourceText: "A".repeat((64 * 1024) + 1)
158
+ }]
159
+ );
160
+ assert.fail("must throw SmartlingException");
161
+ } catch (e) {
162
+ assert.ok(e instanceof SmartlingException);
163
+ }
164
+ });
165
+ });