smartling-api-sdk-nodejs 2.15.1 → 2.16.1
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/index.ts +10 -2
- package/api/file-translations/params/fts-upload-file-parameters.ts +15 -0
- package/api/files/index.ts +6 -2
- package/built/api/file-translations/index.d.ts +1 -1
- package/built/api/file-translations/index.js +8 -1
- package/built/api/file-translations/index.js.map +1 -1
- package/built/api/file-translations/params/fts-upload-file-parameters.d.ts +5 -0
- package/built/api/file-translations/params/fts-upload-file-parameters.js +12 -0
- package/built/api/file-translations/params/fts-upload-file-parameters.js.map +1 -1
- package/built/api/files/index.d.ts +2 -1
- package/built/api/files/index.js +2 -2
- package/built/api/files/index.js.map +1 -1
- package/built/package.json +1 -1
- package/package.json +1 -1
- package/test/file-translations.spec.ts +152 -0
- package/test/files.spec.ts +26 -5
|
@@ -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=AZT0dv92Gh-y-CGibre5
|
|
6
|
+
ceTaskUrl=https://sonar-next.connectors.stg.smartling.net/api/ce/task?id=AZT0dv92Gh-y-CGibre5
|
|
@@ -24,7 +24,15 @@ export class SmartlingFileTranslationsApi extends SmartlingBaseApi {
|
|
|
24
24
|
const formData = new FormData();
|
|
25
25
|
const exported = parameters.export();
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const fileOptions: Record<string, unknown> = {};
|
|
28
|
+
if (exported.fileName) {
|
|
29
|
+
fileOptions.filename = exported.fileName;
|
|
30
|
+
}
|
|
31
|
+
if (exported.contentType) {
|
|
32
|
+
fileOptions.contentType = exported.contentType;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
formData.append("file", exported.file, fileOptions);
|
|
28
36
|
formData.append("request", JSON.stringify(exported.request), {
|
|
29
37
|
contentType: "application/json"
|
|
30
38
|
});
|
|
@@ -70,7 +78,7 @@ export class SmartlingFileTranslationsApi extends SmartlingBaseApi {
|
|
|
70
78
|
|
|
71
79
|
async downloadTranslatedFiles(
|
|
72
80
|
accountUid: string, fileUid: string, mtUid: string
|
|
73
|
-
): Promise<
|
|
81
|
+
): Promise<ArrayBuffer> {
|
|
74
82
|
return await this.makeRequest(
|
|
75
83
|
"get",
|
|
76
84
|
`${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/locales/all/file/zip`,
|
|
@@ -22,6 +22,21 @@ export class FtsUploadFileParameters extends BaseParameters {
|
|
|
22
22
|
return this;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
setFileContentFromBuffer(fileContent: Buffer): FtsUploadFileParameters {
|
|
26
|
+
this.set("file", fileContent);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
setFileName(fileName: string): FtsUploadFileParameters {
|
|
31
|
+
this.set("fileName", fileName);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
setFileContentType(contentType: string): FtsUploadFileParameters {
|
|
36
|
+
this.set("contentType", contentType);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
25
40
|
setFileType(fileType: FileType): FtsUploadFileParameters {
|
|
26
41
|
this.parameters.request.fileType = fileType.toUpperCase();
|
|
27
42
|
return this;
|
package/api/files/index.ts
CHANGED
|
@@ -41,13 +41,17 @@ export class SmartlingFilesApi extends SmartlingBaseApi {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
async downloadFile(
|
|
44
|
-
projectId: string,
|
|
44
|
+
projectId: string,
|
|
45
|
+
fileUri: string,
|
|
46
|
+
locale: string,
|
|
47
|
+
params: DownloadFileParameters,
|
|
48
|
+
responseType: ResponseBodyType = ResponseBodyType.TEXT
|
|
45
49
|
): Promise<string> {
|
|
46
50
|
return await this.makeRequest(
|
|
47
51
|
"get",
|
|
48
52
|
`${this.entrypoint}/${projectId}/locales/${locale}/file`,
|
|
49
53
|
Object.assign(params.export(), { fileUri }),
|
|
50
|
-
|
|
54
|
+
responseType
|
|
51
55
|
);
|
|
52
56
|
}
|
|
53
57
|
|
|
@@ -15,7 +15,7 @@ export declare class SmartlingFileTranslationsApi extends SmartlingBaseApi {
|
|
|
15
15
|
translateFile(accountUid: string, fileUid: string, params: TranslateFileParameters): Promise<TranslationDto>;
|
|
16
16
|
getTranslationProgress(accountUid: string, fileUid: string, mtUid: string): Promise<TranslationStatusDto>;
|
|
17
17
|
downloadTranslatedFile(accountUid: string, fileUid: string, mtUid: string, localeId: string): Promise<string>;
|
|
18
|
-
downloadTranslatedFiles(accountUid: string, fileUid: string, mtUid: string): Promise<
|
|
18
|
+
downloadTranslatedFiles(accountUid: string, fileUid: string, mtUid: string): Promise<ArrayBuffer>;
|
|
19
19
|
cancelFileTranslation(accountUid: string, fileUid: string, mtUid: string): Promise<void>;
|
|
20
20
|
detectFileLanguage(accountUid: string, fileUid: string): Promise<LanguageDetectionDto>;
|
|
21
21
|
getLanguageDetectionProgress(accountUid: string, fileUid: string, languageDetectionUid: string): Promise<LanguageDetectionStatusDto>;
|
|
@@ -26,7 +26,14 @@ class SmartlingFileTranslationsApi extends base_1.SmartlingBaseApi {
|
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
const formData = new form_data_1.default();
|
|
28
28
|
const exported = parameters.export();
|
|
29
|
-
|
|
29
|
+
const fileOptions = {};
|
|
30
|
+
if (exported.fileName) {
|
|
31
|
+
fileOptions.filename = exported.fileName;
|
|
32
|
+
}
|
|
33
|
+
if (exported.contentType) {
|
|
34
|
+
fileOptions.contentType = exported.contentType;
|
|
35
|
+
}
|
|
36
|
+
formData.append("file", exported.file, fileOptions);
|
|
30
37
|
formData.append("request", JSON.stringify(exported.request), {
|
|
31
38
|
contentType: "application/json"
|
|
32
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/file-translations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAAiC;AACjC,kCAA2C;AAU3C,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,CAAC;IAEK,UAAU,CACZ,UAAkB,EAAE,UAAmC;;YAEvD,MAAM,QAAQ,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAChC,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;YAErC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/file-translations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAAiC;AACjC,kCAA2C;AAU3C,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,CAAC;IAEK,UAAU,CACZ,UAAkB,EAAE,UAAmC;;YAEvD,MAAM,QAAQ,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAChC,MAAM,QAAQ,GAA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CACJ;AA7GD,oEA6GC"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
1
3
|
import { BaseParameters } from "../../parameters";
|
|
2
4
|
import { FileType } from "../../files/params/file-type";
|
|
3
5
|
export declare class FtsUploadFileParameters extends BaseParameters {
|
|
4
6
|
constructor(parameters?: Record<string, unknown>);
|
|
5
7
|
setFileFromLocalFilePath(filePath: string): FtsUploadFileParameters;
|
|
6
8
|
setFileContent(fileContent: string): FtsUploadFileParameters;
|
|
9
|
+
setFileContentFromBuffer(fileContent: Buffer): FtsUploadFileParameters;
|
|
10
|
+
setFileName(fileName: string): FtsUploadFileParameters;
|
|
11
|
+
setFileContentType(contentType: string): FtsUploadFileParameters;
|
|
7
12
|
setFileType(fileType: FileType): FtsUploadFileParameters;
|
|
8
13
|
}
|
|
@@ -43,6 +43,18 @@ class FtsUploadFileParameters extends parameters_1.BaseParameters {
|
|
|
43
43
|
this.set("file", (0, string_to_file_stream_1.default)(fileContent));
|
|
44
44
|
return this;
|
|
45
45
|
}
|
|
46
|
+
setFileContentFromBuffer(fileContent) {
|
|
47
|
+
this.set("file", fileContent);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
setFileName(fileName) {
|
|
51
|
+
this.set("fileName", fileName);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
setFileContentType(contentType) {
|
|
55
|
+
this.set("contentType", contentType);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
46
58
|
setFileType(fileType) {
|
|
47
59
|
this.parameters.request.fileType = fileType.toUpperCase();
|
|
48
60
|
return this;
|
|
@@ -1 +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;
|
|
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,wBAAwB,CAAC,WAAmB;QACxC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,WAAW,CAAC,QAAgB;QACxB,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,kBAAkB,CAAC,WAAmB;QAClC,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;QACrC,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;AAtCD,0DAsCC"}
|
|
@@ -11,11 +11,12 @@ import { UploadedFileDto } from "./dto/uploaded-file-dto";
|
|
|
11
11
|
import { FileStatusForProjectDto } from "./dto/file-status-for-project-dto";
|
|
12
12
|
import { DownloadFileAllTranslationsParameters } from "./params/download-file-all-translations-parameters";
|
|
13
13
|
import { RecentlyUploadedFilesParameters } from "./params/recently-uploaded-files";
|
|
14
|
+
import { ResponseBodyType } from "../base/enum/response-body-type";
|
|
14
15
|
export declare class SmartlingFilesApi extends SmartlingBaseApi {
|
|
15
16
|
constructor(smartlingApiBaseUrl: string, authApi: SmartlingAuthApi, logger: Logger);
|
|
16
17
|
getStatusForAllLocales(projectId: string, fileUri: string): Promise<FileStatusForAllLocalesDto>;
|
|
17
18
|
getLastModified(projectId: string, fileUri: string): Promise<SmartlingListResponse<LastModifiedForLocale>>;
|
|
18
|
-
downloadFile(projectId: string, fileUri: string, locale: string, params: DownloadFileParameters): Promise<string>;
|
|
19
|
+
downloadFile(projectId: string, fileUri: string, locale: string, params: DownloadFileParameters, responseType?: ResponseBodyType): Promise<string>;
|
|
19
20
|
downloadFileAllTranslations(projectId: string, fileUri: string, params: DownloadFileAllTranslationsParameters): Promise<string>;
|
|
20
21
|
deleteFile(projectId: string, fileUri: string): Promise<boolean>;
|
|
21
22
|
uploadFile(projectId: string, parameters: UploadFileParameters): Promise<UploadedFileDto>;
|
package/built/api/files/index.js
CHANGED
|
@@ -32,9 +32,9 @@ class SmartlingFilesApi extends index_1.SmartlingBaseApi {
|
|
|
32
32
|
return yield this.makeRequest("get", `${this.entrypoint}/${projectId}/file/last-modified`, { fileUri });
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
downloadFile(projectId, fileUri, locale, params) {
|
|
35
|
+
downloadFile(projectId, fileUri, locale, params, responseType = response_body_type_1.ResponseBodyType.TEXT) {
|
|
36
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
return yield this.makeRequest("get", `${this.entrypoint}/${projectId}/locales/${locale}/file`, Object.assign(params.export(), { fileUri }),
|
|
37
|
+
return yield this.makeRequest("get", `${this.entrypoint}/${projectId}/locales/${locale}/file`, Object.assign(params.export(), { fileUri }), responseType);
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
downloadFileAllTranslations(projectId, fileUri, params) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/files/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAAiC;AACjC,yCAAiD;AAYjD,wEAAmE;AAEnE,MAAa,iBAAkB,SAAQ,wBAAgB;IACnD,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,wBAAwB,CAAC;IACrE,CAAC;IAEK,sBAAsB,CAC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AC,WAAW,CACzB,MAAM,EACN,GAAG,IAAI,CAAC,UAAU,IAAI,SAAS,OAAO,EACtC,QAAQ,EACR,KAAK,EACL,iBAAiB,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CACvD,CAAC;QACN,CAAC;KAAA;IAEK,wBAAwB,CAC1B,SAAiB,EACjB,MAAuC;;YAEvC,OAAO,MAAM,IAAI,CAAC,WAAW,CACzB,KAAK,EACL,GAAG,IAAI,CAAC,UAAU,IAAI,SAAS,aAAa,EAC5C,MAAM,CAAC,MAAM,EAAE,CAClB,CAAC;QACN,CAAC;KAAA;IAED,MAAM,CAAC,wBAAwB,CAAC,IAAc;QAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAElC,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;QAElD,OAAO,OAAO,CAAC,cAAc,CAAC,CAAC;QAC/B,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AA1GD,8CA0GC"}
|
package/built/package.json
CHANGED
package/package.json
CHANGED
|
@@ -144,6 +144,158 @@ describe("SmartlingFileTranslationsApi class tests.", () => {
|
|
|
144
144
|
assert.equal(fileTranslationsApiFetchCall.args[1].body._streams[4], "{\"fileType\":\"XML\"}");
|
|
145
145
|
});
|
|
146
146
|
|
|
147
|
+
it("Upload file: as binary buffer", async () => {
|
|
148
|
+
const params = new FtsUploadFileParameters();
|
|
149
|
+
|
|
150
|
+
const testFileContent = fs.readFileSync(
|
|
151
|
+
fs.realpathSync("./test/data/file.xml")
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
params
|
|
155
|
+
.setFileType(FileType.XML)
|
|
156
|
+
.setFileContentFromBuffer(testFileContent);
|
|
157
|
+
|
|
158
|
+
await fileTranslationsApi.uploadFile(accountUid, params);
|
|
159
|
+
|
|
160
|
+
sinon.assert.calledOnce(fileTranslationsApiFetchStub);
|
|
161
|
+
|
|
162
|
+
const fileTranslationsApiFetchCall = fileTranslationsApiFetchStub.getCall(0);
|
|
163
|
+
|
|
164
|
+
assert.equal(
|
|
165
|
+
fileTranslationsApiFetchCall.args[0],
|
|
166
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files`
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
assert.equal(
|
|
170
|
+
fileTranslationsApiFetchCall.args[1].method,
|
|
171
|
+
"post"
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
assert.equal(
|
|
175
|
+
fileTranslationsApiFetchCall.args[1].headers.Authorization,
|
|
176
|
+
"test_token_type test_access_token"
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const formData = fileTranslationsApiFetchCall.args[1].body as FormData;
|
|
180
|
+
const boundary = formData.getBoundary();
|
|
181
|
+
|
|
182
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].headers["User-Agent"], userAgent);
|
|
183
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].headers["Content-Type"], `multipart/form-data; boundary=${boundary}`);
|
|
184
|
+
|
|
185
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
186
|
+
const content = fileTranslationsApiFetchCall.args[1].body._streams[1].toString("utf-8");
|
|
187
|
+
assert.equal(content, testFileContent);
|
|
188
|
+
|
|
189
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
190
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].body._streams[4], "{\"fileType\":\"XML\"}");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("Upload file: with file name", async () => {
|
|
194
|
+
const params = new FtsUploadFileParameters();
|
|
195
|
+
|
|
196
|
+
const testFileContent = fs.readFileSync(
|
|
197
|
+
fs.realpathSync("./test/data/file.xml")
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
params
|
|
201
|
+
.setFileType(FileType.XML)
|
|
202
|
+
.setFileContentFromBuffer(testFileContent)
|
|
203
|
+
.setFileName("my-file");
|
|
204
|
+
|
|
205
|
+
await fileTranslationsApi.uploadFile(accountUid, params);
|
|
206
|
+
|
|
207
|
+
sinon.assert.calledOnce(fileTranslationsApiFetchStub);
|
|
208
|
+
|
|
209
|
+
const fileTranslationsApiFetchCall = fileTranslationsApiFetchStub.getCall(0);
|
|
210
|
+
|
|
211
|
+
assert.equal(
|
|
212
|
+
fileTranslationsApiFetchCall.args[0],
|
|
213
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files`
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
assert.equal(
|
|
217
|
+
fileTranslationsApiFetchCall.args[1].method,
|
|
218
|
+
"post"
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
assert.equal(
|
|
222
|
+
fileTranslationsApiFetchCall.args[1].headers.Authorization,
|
|
223
|
+
"test_token_type test_access_token"
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const formData = fileTranslationsApiFetchCall.args[1].body as FormData;
|
|
227
|
+
const boundary = formData.getBoundary();
|
|
228
|
+
|
|
229
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].headers["User-Agent"], userAgent);
|
|
230
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].headers["Content-Type"], `multipart/form-data; boundary=${boundary}`);
|
|
231
|
+
|
|
232
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
233
|
+
const content = fileTranslationsApiFetchCall.args[1].body._streams[1].toString("utf-8");
|
|
234
|
+
assert.equal(content, testFileContent);
|
|
235
|
+
|
|
236
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
237
|
+
const contentDisposition = fileTranslationsApiFetchCall.args[1].body._streams[0].toString("utf-8");
|
|
238
|
+
|
|
239
|
+
assert.ok(contentDisposition.includes("filename=\"my-file\""));
|
|
240
|
+
assert.ok(contentDisposition.includes("Content-Type: application/octet-stream"));
|
|
241
|
+
|
|
242
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
243
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].body._streams[4], "{\"fileType\":\"XML\"}");
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("Upload file: with file content type", async () => {
|
|
247
|
+
const params = new FtsUploadFileParameters();
|
|
248
|
+
|
|
249
|
+
const testFileContent = fs.readFileSync(
|
|
250
|
+
fs.realpathSync("./test/data/file.xml")
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
params
|
|
254
|
+
.setFileType(FileType.XML)
|
|
255
|
+
.setFileContentFromBuffer(testFileContent)
|
|
256
|
+
.setFileContentType("application/xml");
|
|
257
|
+
|
|
258
|
+
await fileTranslationsApi.uploadFile(accountUid, params);
|
|
259
|
+
|
|
260
|
+
sinon.assert.calledOnce(fileTranslationsApiFetchStub);
|
|
261
|
+
|
|
262
|
+
const fileTranslationsApiFetchCall = fileTranslationsApiFetchStub.getCall(0);
|
|
263
|
+
|
|
264
|
+
assert.equal(
|
|
265
|
+
fileTranslationsApiFetchCall.args[0],
|
|
266
|
+
`https://test.com/file-translations-api/v2/accounts/${accountUid}/files`
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
assert.equal(
|
|
270
|
+
fileTranslationsApiFetchCall.args[1].method,
|
|
271
|
+
"post"
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
assert.equal(
|
|
275
|
+
fileTranslationsApiFetchCall.args[1].headers.Authorization,
|
|
276
|
+
"test_token_type test_access_token"
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const formData = fileTranslationsApiFetchCall.args[1].body as FormData;
|
|
280
|
+
const boundary = formData.getBoundary();
|
|
281
|
+
|
|
282
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].headers["User-Agent"], userAgent);
|
|
283
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].headers["Content-Type"], `multipart/form-data; boundary=${boundary}`);
|
|
284
|
+
|
|
285
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
286
|
+
const content = fileTranslationsApiFetchCall.args[1].body._streams[1].toString("utf-8");
|
|
287
|
+
assert.equal(content, testFileContent);
|
|
288
|
+
|
|
289
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
290
|
+
const contentDisposition = fileTranslationsApiFetchCall.args[1].body._streams[0].toString("utf-8");
|
|
291
|
+
|
|
292
|
+
assert.ok(!contentDisposition.includes("filename="));
|
|
293
|
+
assert.ok(contentDisposition.includes("Content-Type: application/xml"));
|
|
294
|
+
|
|
295
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
296
|
+
assert.equal(fileTranslationsApiFetchCall.args[1].body._streams[4], "{\"fileType\":\"XML\"}");
|
|
297
|
+
});
|
|
298
|
+
|
|
147
299
|
it("Translate file", async () => {
|
|
148
300
|
const params = new TranslateFileParameters();
|
|
149
301
|
|
package/test/files.spec.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as fs from "fs";
|
|
|
2
2
|
import sinon from "sinon";
|
|
3
3
|
import assert from "assert";
|
|
4
4
|
import { SmartlingFilesApi } from "../api/files/index";
|
|
5
|
-
import {
|
|
5
|
+
import { authMock, loggerMock, responseMock } from "./mock";
|
|
6
6
|
import { RetrievalType } from "../api/files/params/retrieval-type";
|
|
7
7
|
import { DownloadFileParameters } from "../api/files/params/download-file-parameters";
|
|
8
8
|
import { UploadFileParameters } from "../api/files/params/upload-file-parameters";
|
|
@@ -11,6 +11,7 @@ import { FileType } from "../api/files/params/file-type";
|
|
|
11
11
|
import { streamToString } from "./stream-to-string";
|
|
12
12
|
import { DownloadFileAllTranslationsParameters } from "../api/files/params/download-file-all-translations-parameters";
|
|
13
13
|
import { RecentlyUploadedFilesParameters } from "../api/files/params/recently-uploaded-files";
|
|
14
|
+
import { ResponseBodyType } from "../api/base/enum/response-body-type";
|
|
14
15
|
|
|
15
16
|
describe("SmartlingFilesApi class tests.", () => {
|
|
16
17
|
const projectId = "testProjectId";
|
|
@@ -112,7 +113,12 @@ describe("SmartlingFilesApi class tests.", () => {
|
|
|
112
113
|
.setRetrievalType(RetrievalType.PUBLISHED)
|
|
113
114
|
.enableDebugMode();
|
|
114
115
|
|
|
115
|
-
await filesApi.downloadFile(
|
|
116
|
+
await filesApi.downloadFile(
|
|
117
|
+
projectId,
|
|
118
|
+
fileUri,
|
|
119
|
+
localeId,
|
|
120
|
+
params
|
|
121
|
+
);
|
|
116
122
|
|
|
117
123
|
sinon.assert.calledOnce(filesApiFetchStub);
|
|
118
124
|
sinon.assert.calledWithExactly(
|
|
@@ -132,7 +138,12 @@ describe("SmartlingFilesApi class tests.", () => {
|
|
|
132
138
|
it("Download file with debugMode disabled and retrievalType published", async () => {
|
|
133
139
|
params.setRetrievalType(RetrievalType.PUBLISHED);
|
|
134
140
|
|
|
135
|
-
await filesApi.downloadFile(
|
|
141
|
+
await filesApi.downloadFile(
|
|
142
|
+
projectId,
|
|
143
|
+
fileUri,
|
|
144
|
+
localeId,
|
|
145
|
+
params
|
|
146
|
+
);
|
|
136
147
|
|
|
137
148
|
sinon.assert.calledOnce(filesApiFetchStub);
|
|
138
149
|
sinon.assert.calledWithExactly(
|
|
@@ -152,7 +163,12 @@ describe("SmartlingFilesApi class tests.", () => {
|
|
|
152
163
|
it("Download file with includeOriginalStrings enabled", async() => {
|
|
153
164
|
params.setRetrievalType(RetrievalType.PUBLISHED).includeOriginalStrings();
|
|
154
165
|
|
|
155
|
-
await filesApi.downloadFile(
|
|
166
|
+
await filesApi.downloadFile(
|
|
167
|
+
projectId,
|
|
168
|
+
fileUri,
|
|
169
|
+
localeId,
|
|
170
|
+
params
|
|
171
|
+
);
|
|
156
172
|
|
|
157
173
|
sinon.assert.calledOnce(filesApiFetchStub);
|
|
158
174
|
sinon.assert.calledWithExactly(
|
|
@@ -172,7 +188,12 @@ describe("SmartlingFilesApi class tests.", () => {
|
|
|
172
188
|
it("Download file with includeOriginalStrings disabled", async() => {
|
|
173
189
|
params.setRetrievalType(RetrievalType.PUBLISHED).excludeOriginalStrings();
|
|
174
190
|
|
|
175
|
-
await filesApi.downloadFile(
|
|
191
|
+
await filesApi.downloadFile(
|
|
192
|
+
projectId,
|
|
193
|
+
fileUri,
|
|
194
|
+
localeId,
|
|
195
|
+
params
|
|
196
|
+
);
|
|
176
197
|
|
|
177
198
|
sinon.assert.calledOnce(filesApiFetchStub);
|
|
178
199
|
sinon.assert.calledWithExactly(
|