smartling-api-sdk-nodejs 2.27.0 → 2.28.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 (42) hide show
  1. package/.scannerwork/report-task.txt +2 -2
  2. package/api/base/base-api.ts +205 -0
  3. package/api/base/base-file-api.ts +23 -0
  4. package/api/base/index.ts +2 -205
  5. package/api/file-translations/index.ts +5 -24
  6. package/api/files/index.ts +20 -2
  7. package/api/files/params/download-file-with-metadata-parameters.ts +12 -0
  8. package/api/files/params/filename-mode.ts +4 -0
  9. package/built/api/base/base-api.d.ts +26 -0
  10. package/built/api/base/base-api.js +163 -0
  11. package/built/api/base/base-api.js.map +1 -0
  12. package/built/api/base/base-file-api.d.ts +5 -0
  13. package/built/api/base/base-file-api.js +36 -0
  14. package/built/api/base/base-file-api.js.map +1 -0
  15. package/built/api/base/index.d.ts +2 -26
  16. package/built/api/base/index.js +5 -160
  17. package/built/api/base/index.js.map +1 -1
  18. package/built/api/dto/translated-file-dto.js.map +1 -0
  19. package/built/api/file-translations/index.d.ts +3 -4
  20. package/built/api/file-translations/index.js +3 -22
  21. package/built/api/file-translations/index.js.map +1 -1
  22. package/built/api/files/index.d.ts +5 -2
  23. package/built/api/files/index.js +7 -2
  24. package/built/api/files/index.js.map +1 -1
  25. package/built/api/files/params/download-file-with-metadata-parameters.d.ts +5 -0
  26. package/built/api/files/params/download-file-with-metadata-parameters.js +15 -0
  27. package/built/api/files/params/download-file-with-metadata-parameters.js.map +1 -0
  28. package/built/api/files/params/filename-mode.d.ts +4 -0
  29. package/built/api/files/params/filename-mode.js +9 -0
  30. package/built/api/files/params/filename-mode.js.map +1 -0
  31. package/built/index.d.ts +4 -1
  32. package/built/index.js +4 -1
  33. package/built/index.js.map +1 -1
  34. package/built/package.json +1 -1
  35. package/index.ts +4 -1
  36. package/package.json +1 -1
  37. package/test/base-file.spec.ts +57 -0
  38. package/test/files.spec.ts +272 -0
  39. package/built/api/file-translations/dto/translated-file-dto.js.map +0 -1
  40. /package/api/{file-translations/dto → dto}/translated-file-dto.ts +0 -0
  41. /package/built/api/{file-translations/dto → dto}/translated-file-dto.d.ts +0 -0
  42. /package/built/api/{file-translations/dto → dto}/translated-file-dto.js +0 -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=AZnkDu2E5pumWNxcJ_G-
6
- ceTaskUrl=https://sonar-next.connectors.stg.smartling.net/api/ce/task?id=AZnkDu2E5pumWNxcJ_G-
5
+ ceTaskId=AZnyEx5RJWZPnO2QZLpi
6
+ ceTaskUrl=https://sonar-next.connectors.stg.smartling.net/api/ce/task?id=AZnyEx5RJWZPnO2QZLpi
@@ -0,0 +1,205 @@
1
+ import merge from "merge-deep";
2
+ import ua from "default-user-agent";
3
+ import FormData from "form-data";
4
+ import fetch from "cross-fetch";
5
+ import { ParsedUrlQueryInput, stringify } from "querystring";
6
+ import { Logger } from "../logger";
7
+ import { SmartlingException } from "../exception/index";
8
+ import { AccessTokenProvider } from "../auth/access-token-provider";
9
+ import { ResponseBodyType } from "./enum/response-body-type";
10
+
11
+ /* eslint-disable-next-line @typescript-eslint/no-var-requires */
12
+ const packageJson = require("../../package.json");
13
+
14
+ export class SmartlingBaseApi {
15
+ protected authApi: AccessTokenProvider = undefined;
16
+ protected entrypoint: string;
17
+ protected defaultClientLibId: string;
18
+ protected defaultClientVersion: string;
19
+ protected clientLibId: string;
20
+ protected clientLibVersion: string;
21
+ protected logger: Logger;
22
+ protected options: Record<string, unknown>;
23
+
24
+ constructor(logger: Logger) {
25
+ this.defaultClientLibId = packageJson.name;
26
+ this.defaultClientVersion = packageJson.version;
27
+ this.clientLibId = this.defaultClientLibId;
28
+ this.clientLibVersion = this.defaultClientVersion;
29
+ this.logger = logger;
30
+ this.options = {};
31
+ }
32
+
33
+ setOptions(options: Record<string, unknown>): void {
34
+ this.options = options;
35
+ }
36
+
37
+ public getClientLibId(): string {
38
+ return this.clientLibId;
39
+ }
40
+
41
+ public setClientLibId(clientLibId: string): void {
42
+ this.clientLibId = clientLibId;
43
+ }
44
+
45
+ public getClientLibVersion(): string {
46
+ return this.clientLibVersion;
47
+ }
48
+
49
+ public setClientLibVersion(clientLibVersion: string): void {
50
+ this.clientLibVersion = clientLibVersion;
51
+ }
52
+
53
+ /* eslint-disable-next-line class-methods-use-this */
54
+ async fetch(uri: string, options: Record<string, unknown>): Promise<Response> {
55
+ return await fetch(uri, options);
56
+ }
57
+
58
+ /* eslint-disable-next-line class-methods-use-this */
59
+ ua(clientId: string, clientVersion: string): string {
60
+ return ua(clientId, clientVersion);
61
+ }
62
+
63
+ /* eslint-disable-next-line class-methods-use-this */
64
+ alterRequestData(uri: string, opts: Record<string, unknown>): Record<string, unknown> {
65
+ return opts;
66
+ }
67
+
68
+ async getDefaultHeaders(
69
+ headers: Record<string, unknown> = {}
70
+ ): Promise<Record<string, unknown>> {
71
+ let defaultHeaders = {};
72
+
73
+ /* eslint-disable-next-line no-prototype-builtins */
74
+ if (this.hasOwnProperty("authApi") && undefined !== this.authApi) {
75
+ const accessToken = await this.authApi.getAccessToken();
76
+ const tokenType = await this.authApi.getTokenType();
77
+
78
+ defaultHeaders = {
79
+ Authorization: `${tokenType} ${accessToken}`
80
+ };
81
+ }
82
+
83
+ defaultHeaders["Content-Type"] = "application/json";
84
+ defaultHeaders["User-Agent"] = this.ua(this.clientLibId, this.clientLibVersion);
85
+
86
+ return merge(defaultHeaders, headers);
87
+ }
88
+
89
+ async makeRequest(
90
+ verb: string,
91
+ uri: string,
92
+ payload: Record<string, unknown> | string | FormData = null,
93
+ returnRawResponseBody: ResponseBodyType | boolean = false,
94
+ headers: Record<string, unknown> = {}
95
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
96
+ ): Promise<any> {
97
+ const opts = merge({
98
+ method: verb,
99
+ headers: await this.getDefaultHeaders(headers)
100
+ }, this.options);
101
+
102
+ if (verb.toLowerCase() !== "get" && payload) {
103
+ opts.body = payload;
104
+ } else if (payload) {
105
+ // Package node-fetch doesn't support query parameters.
106
+ // Let's add them manually.
107
+ uri = `${uri}?${stringify(payload as unknown as ParsedUrlQueryInput)}`;
108
+ }
109
+
110
+ let response = await this.fetch(uri, this.alterRequestData(uri, opts));
111
+
112
+ if (response.status === 401) {
113
+ this.logger.warn("Got unexpected 401 response code, trying to re-auth carefully...");
114
+
115
+ /* eslint-disable-next-line no-prototype-builtins */
116
+ if (this.hasOwnProperty("authApi") && this.authApi !== undefined) {
117
+ this.authApi.resetToken();
118
+ }
119
+
120
+ // Do not override http client headers set by SmartlingBaseApi.setOptions().
121
+ const defaultHeaders = await this.getDefaultHeaders(headers);
122
+ opts.headers.Authorization = defaultHeaders.Authorization;
123
+
124
+ response = await this.fetch(uri, this.alterRequestData(uri, opts));
125
+ }
126
+
127
+ if (response.status >= 400) {
128
+ const responseText = await response.text();
129
+
130
+ throw new SmartlingException(`Request for ${uri} failed`, {
131
+ statusCode: response.status,
132
+ errorResponse: responseText,
133
+ requestId: response.headers.get("x-sl-requestid")
134
+ });
135
+ }
136
+
137
+ // Special case for file download - return raw response text.
138
+ if (returnRawResponseBody === true || returnRawResponseBody === ResponseBodyType.TEXT) {
139
+ return response.text();
140
+ }
141
+
142
+ // Special case for zip file download - return raw response array buffer.
143
+ if (returnRawResponseBody === ResponseBodyType.ARRAY_BUFFER) {
144
+ return response.arrayBuffer();
145
+ }
146
+
147
+ // Special case for download file with metadata - return raw response.
148
+ if (returnRawResponseBody === ResponseBodyType.RAW_RESPONSE) {
149
+ return response;
150
+ }
151
+
152
+ let textResponse: string;
153
+ try {
154
+ textResponse = await response.text();
155
+ const jsonResponse = JSON.parse(textResponse, (key, value) => {
156
+ const dateProperties = [
157
+ "created",
158
+ "modified",
159
+ "updated",
160
+ "createdDate",
161
+ "modifiedDate",
162
+ "updatedDate",
163
+ "dueDate",
164
+ "actionTime",
165
+ "publishDate",
166
+ "lastModified",
167
+ "attemptDate"
168
+ ];
169
+
170
+ if (dateProperties.includes(key) && value) {
171
+ return new Date(value);
172
+ }
173
+
174
+ return value;
175
+ });
176
+
177
+ this.logger.debug(`Received code ${response.status}; content: ${JSON.stringify(jsonResponse, SmartlingBaseApi.sensitiveReplacer)}`);
178
+
179
+ return jsonResponse?.response?.data ? jsonResponse?.response?.data : true;
180
+ } catch (e) {
181
+ this.logger.error(`Couldn't parse response json: ${e.toString()}`);
182
+
183
+ throw new SmartlingException("Couldn't parse response json", {
184
+ statusCode: response.status,
185
+ errorResponse: textResponse,
186
+ requestId: response.headers.get("x-sl-requestid")
187
+ });
188
+ }
189
+ }
190
+
191
+ public static sensitiveReplacer(key: string, value: any): any {
192
+ const sensitiveProperties = [
193
+ "userIdentifier",
194
+ "userSecret",
195
+ "accessToken",
196
+ "refreshToken"
197
+ ];
198
+
199
+ if (sensitiveProperties.includes(key) && value && typeof value === "string") {
200
+ return `${value.substring(0, 10)}xxxxx`;
201
+ }
202
+
203
+ return value;
204
+ }
205
+ }
@@ -0,0 +1,23 @@
1
+ import { SmartlingBaseApi } from "./base-api";
2
+ import { TranslatedFileDto } from "../dto/translated-file-dto";
3
+
4
+ export class SmartlingBaseFileApi extends SmartlingBaseApi {
5
+ static async downloadResponseToTranslatedFileDto(
6
+ response: Response
7
+ ): Promise<TranslatedFileDto> {
8
+ const contentType = response.headers.get("content-type") ?? undefined;
9
+ const contentDisposition = response.headers.get("content-disposition");
10
+ let fileName;
11
+ if (contentDisposition) {
12
+ const fileNameMatch = contentDisposition.match(/filename="((?:[^"\\]|\\.)*)"/);
13
+ if (fileNameMatch) {
14
+ fileName = fileNameMatch[1].replace(/\\"/g, "\"");
15
+ }
16
+ }
17
+ return {
18
+ fileContent: await response.arrayBuffer(),
19
+ fileName,
20
+ contentType
21
+ };
22
+ }
23
+ }
package/api/base/index.ts CHANGED
@@ -1,205 +1,2 @@
1
- import merge from "merge-deep";
2
- import ua from "default-user-agent";
3
- import FormData from "form-data";
4
- import fetch from "cross-fetch";
5
- import { ParsedUrlQueryInput, stringify } from "querystring";
6
- import { Logger } from "../logger";
7
- import { SmartlingException } from "../exception/index";
8
- import { AccessTokenProvider } from "../auth/access-token-provider";
9
- import { ResponseBodyType } from "./enum/response-body-type";
10
-
11
- /* eslint-disable-next-line @typescript-eslint/no-var-requires */
12
- const packageJson = require("../../package.json");
13
-
14
- export class SmartlingBaseApi {
15
- protected authApi: AccessTokenProvider = undefined;
16
- protected entrypoint: string;
17
- protected defaultClientLibId: string;
18
- protected defaultClientVersion: string;
19
- protected clientLibId: string;
20
- protected clientLibVersion: string;
21
- protected logger: Logger;
22
- protected options: Record<string, unknown>;
23
-
24
- constructor(logger: Logger) {
25
- this.defaultClientLibId = packageJson.name;
26
- this.defaultClientVersion = packageJson.version;
27
- this.clientLibId = this.defaultClientLibId;
28
- this.clientLibVersion = this.defaultClientVersion;
29
- this.logger = logger;
30
- this.options = {};
31
- }
32
-
33
- setOptions(options: Record<string, unknown>): void {
34
- this.options = options;
35
- }
36
-
37
- public getClientLibId(): string {
38
- return this.clientLibId;
39
- }
40
-
41
- public setClientLibId(clientLibId: string): void {
42
- this.clientLibId = clientLibId;
43
- }
44
-
45
- public getClientLibVersion(): string {
46
- return this.clientLibVersion;
47
- }
48
-
49
- public setClientLibVersion(clientLibVersion: string): void {
50
- this.clientLibVersion = clientLibVersion;
51
- }
52
-
53
- /* eslint-disable-next-line class-methods-use-this */
54
- async fetch(uri: string, options: Record<string, unknown>): Promise<Response> {
55
- return await fetch(uri, options);
56
- }
57
-
58
- /* eslint-disable-next-line class-methods-use-this */
59
- ua(clientId: string, clientVersion: string): string {
60
- return ua(clientId, clientVersion);
61
- }
62
-
63
- /* eslint-disable-next-line class-methods-use-this */
64
- alterRequestData(uri: string, opts: Record<string, unknown>): Record<string, unknown> {
65
- return opts;
66
- }
67
-
68
- async getDefaultHeaders(
69
- headers: Record<string, unknown> = {}
70
- ): Promise<Record<string, unknown>> {
71
- let defaultHeaders = {};
72
-
73
- /* eslint-disable-next-line no-prototype-builtins */
74
- if (this.hasOwnProperty("authApi") && undefined !== this.authApi) {
75
- const accessToken = await this.authApi.getAccessToken();
76
- const tokenType = await this.authApi.getTokenType();
77
-
78
- defaultHeaders = {
79
- Authorization: `${tokenType} ${accessToken}`
80
- };
81
- }
82
-
83
- defaultHeaders["Content-Type"] = "application/json";
84
- defaultHeaders["User-Agent"] = this.ua(this.clientLibId, this.clientLibVersion);
85
-
86
- return merge(defaultHeaders, headers);
87
- }
88
-
89
- async makeRequest(
90
- verb: string,
91
- uri: string,
92
- payload: Record<string, unknown> | string | FormData = null,
93
- returnRawResponseBody: ResponseBodyType | boolean = false,
94
- headers: Record<string, unknown> = {}
95
- /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
96
- ): Promise<any> {
97
- const opts = merge({
98
- method: verb,
99
- headers: await this.getDefaultHeaders(headers)
100
- }, this.options);
101
-
102
- if (verb.toLowerCase() !== "get" && payload) {
103
- opts.body = payload;
104
- } else if (payload) {
105
- // Package node-fetch doesn't support query parameters.
106
- // Let's add them manually.
107
- uri = `${uri}?${stringify(payload as unknown as ParsedUrlQueryInput)}`;
108
- }
109
-
110
- let response = await this.fetch(uri, this.alterRequestData(uri, opts));
111
-
112
- if (response.status === 401) {
113
- this.logger.warn("Got unexpected 401 response code, trying to re-auth carefully...");
114
-
115
- /* eslint-disable-next-line no-prototype-builtins */
116
- if (this.hasOwnProperty("authApi") && this.authApi !== undefined) {
117
- this.authApi.resetToken();
118
- }
119
-
120
- // Do not override http client headers set by SmartlingBaseApi.setOptions().
121
- const defaultHeaders = await this.getDefaultHeaders(headers);
122
- opts.headers.Authorization = defaultHeaders.Authorization;
123
-
124
- response = await this.fetch(uri, this.alterRequestData(uri, opts));
125
- }
126
-
127
- if (response.status >= 400) {
128
- const responseText = await response.text();
129
-
130
- throw new SmartlingException(`Request for ${uri} failed`, {
131
- statusCode: response.status,
132
- errorResponse: responseText,
133
- requestId: response.headers.get("x-sl-requestid")
134
- });
135
- }
136
-
137
- // Special case for file download - return raw response text.
138
- if (returnRawResponseBody === true || returnRawResponseBody === ResponseBodyType.TEXT) {
139
- return response.text();
140
- }
141
-
142
- // Special case for zip file download - return raw response array buffer.
143
- if (returnRawResponseBody === ResponseBodyType.ARRAY_BUFFER) {
144
- return response.arrayBuffer();
145
- }
146
-
147
- // Special case for download file with metadata - return raw response.
148
- if (returnRawResponseBody === ResponseBodyType.RAW_RESPONSE) {
149
- return response;
150
- }
151
-
152
- let textResponse: string;
153
- try {
154
- textResponse = await response.text();
155
- const jsonResponse = JSON.parse(textResponse, (key, value) => {
156
- const dateProperties = [
157
- "created",
158
- "modified",
159
- "updated",
160
- "createdDate",
161
- "modifiedDate",
162
- "updatedDate",
163
- "dueDate",
164
- "actionTime",
165
- "publishDate",
166
- "lastModified",
167
- "attemptDate"
168
- ];
169
-
170
- if (dateProperties.includes(key) && value) {
171
- return new Date(value);
172
- }
173
-
174
- return value;
175
- });
176
-
177
- this.logger.debug(`Received code ${response.status}; content: ${JSON.stringify(jsonResponse, SmartlingBaseApi.sensitiveReplacer)}`);
178
-
179
- return jsonResponse?.response?.data ? jsonResponse?.response?.data : true;
180
- } catch (e) {
181
- this.logger.error(`Couldn't parse response json: ${e.toString()}`);
182
-
183
- throw new SmartlingException("Couldn't parse response json", {
184
- statusCode: response.status,
185
- errorResponse: textResponse,
186
- requestId: response.headers.get("x-sl-requestid")
187
- });
188
- }
189
- }
190
-
191
- public static sensitiveReplacer(key: string, value: any): any {
192
- const sensitiveProperties = [
193
- "userIdentifier",
194
- "userSecret",
195
- "accessToken",
196
- "refreshToken"
197
- ];
198
-
199
- if (sensitiveProperties.includes(key) && value && typeof value === "string") {
200
- return `${value.substring(0, 10)}xxxxx`;
201
- }
202
-
203
- return value;
204
- }
205
- }
1
+ export { SmartlingBaseApi } from "./base-api";
2
+ export { SmartlingBaseFileApi } from "./base-file-api";
@@ -1,5 +1,5 @@
1
1
  import FormData from "form-data";
2
- import { SmartlingBaseApi } from "../base";
2
+ import { SmartlingBaseFileApi } from "../base";
3
3
  import { AccessTokenProvider } from "../auth/access-token-provider";
4
4
  import { Logger } from "../logger";
5
5
  import { FtsUploadedFileDto } from "./dto/fts-uploaded-file-dto";
@@ -9,11 +9,11 @@ import { TranslateFileParameters } from "./params/translate-file-parameters";
9
9
  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
- import { TranslatedFileDto } from "./dto/translated-file-dto";
12
+ import { TranslatedFileDto } from "../dto/translated-file-dto";
13
13
  import { ResponseBodyType } from "../base/enum/response-body-type";
14
14
  import { LanguageDetectionParameters } from "./params/language-detection-parameters";
15
15
 
16
- export class SmartlingFileTranslationsApi extends SmartlingBaseApi {
16
+ export class SmartlingFileTranslationsApi extends SmartlingBaseFileApi {
17
17
  constructor(smartlingApiBaseUrl: string, authApi: AccessTokenProvider, logger: Logger) {
18
18
  super(logger);
19
19
  this.authApi = authApi;
@@ -81,7 +81,7 @@ export class SmartlingFileTranslationsApi extends SmartlingBaseApi {
81
81
  async downloadTranslatedFileWithMetadata(
82
82
  accountUid: string, fileUid: string, mtUid: string, localeId: string
83
83
  ): Promise<TranslatedFileDto> {
84
- return await SmartlingFileTranslationsApi.downloadResponseToTranslatedFileDto(
84
+ return await SmartlingBaseFileApi.downloadResponseToTranslatedFileDto(
85
85
  await this.makeRequest(
86
86
  "get",
87
87
  `${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/locales/${localeId}/file`,
@@ -105,7 +105,7 @@ export class SmartlingFileTranslationsApi extends SmartlingBaseApi {
105
105
  async downloadTranslatedFilesWithMetadata(
106
106
  accountUid: string, fileUid: string, mtUid: string
107
107
  ): Promise<TranslatedFileDto> {
108
- return await SmartlingFileTranslationsApi.downloadResponseToTranslatedFileDto(
108
+ return await SmartlingBaseFileApi.downloadResponseToTranslatedFileDto(
109
109
  await this.makeRequest(
110
110
  "get",
111
111
  `${this.entrypoint}/${accountUid}/files/${fileUid}/mt/${mtUid}/locales/all/file/zip`,
@@ -151,23 +151,4 @@ export class SmartlingFileTranslationsApi extends SmartlingBaseApi {
151
151
  delete headers["content-type"];
152
152
  return headers;
153
153
  }
154
-
155
- private static async downloadResponseToTranslatedFileDto(
156
- response: Response
157
- ): Promise<TranslatedFileDto> {
158
- const contentType = response.headers.get("content-type") ?? undefined;
159
- const contentDisposition = response.headers.get("content-disposition");
160
- let fileName;
161
- if (contentDisposition) {
162
- const fileNameMatch = contentDisposition.match(/filename="((?:[^"\\]|\\.)*)"/);
163
- if (fileNameMatch) {
164
- fileName = fileNameMatch[1].replace(/\\"/g, "\"");
165
- }
166
- }
167
- return {
168
- fileContent: await response.arrayBuffer(),
169
- fileName,
170
- contentType
171
- };
172
- }
173
154
  }
@@ -1,8 +1,9 @@
1
1
  import FormData from "form-data";
2
- import { SmartlingBaseApi } from "../base/index";
2
+ import { SmartlingBaseFileApi } from "../base";
3
3
  import { AccessTokenProvider } from "../auth/access-token-provider";
4
4
  import { Logger } from "../logger";
5
5
  import { DownloadFileParameters } from "./params/download-file-parameters";
6
+ import { DownloadFileWithMetadataParameters } from "./params/download-file-with-metadata-parameters";
6
7
  import { UploadFileParameters } from "./params/upload-file-parameters";
7
8
  import { FileStatusForAllLocalesDto } from "./dto/file-status-for-all-locales-dto";
8
9
  import { SmartlingListResponse } from "../http/smartling-list-response";
@@ -12,8 +13,9 @@ import { FileStatusForProjectDto } from "./dto/file-status-for-project-dto";
12
13
  import { DownloadFileAllTranslationsParameters } from "./params/download-file-all-translations-parameters";
13
14
  import { RecentlyUploadedFilesParameters } from "./params/recently-uploaded-files";
14
15
  import { ResponseBodyType } from "../base/enum/response-body-type";
16
+ import { TranslatedFileDto } from "../dto/translated-file-dto";
15
17
 
16
- export class SmartlingFilesApi extends SmartlingBaseApi {
18
+ export class SmartlingFilesApi extends SmartlingBaseFileApi {
17
19
  constructor(smartlingApiBaseUrl: string, authApi: AccessTokenProvider, logger: Logger) {
18
20
  super(logger);
19
21
  this.authApi = authApi;
@@ -55,6 +57,22 @@ export class SmartlingFilesApi extends SmartlingBaseApi {
55
57
  );
56
58
  }
57
59
 
60
+ async downloadFileWithMetadata(
61
+ projectId: string,
62
+ fileUri: string,
63
+ locale: string,
64
+ params: DownloadFileWithMetadataParameters
65
+ ): Promise<TranslatedFileDto> {
66
+ return await SmartlingBaseFileApi.downloadResponseToTranslatedFileDto(
67
+ await this.makeRequest(
68
+ "get",
69
+ `${this.entrypoint}/${projectId}/locales/${locale}/file`,
70
+ Object.assign(params.export(), { fileUri }),
71
+ ResponseBodyType.RAW_RESPONSE
72
+ )
73
+ );
74
+ }
75
+
58
76
  async downloadFileAllTranslations(
59
77
  projectId: string,
60
78
  fileUri: string,
@@ -0,0 +1,12 @@
1
+ import { DownloadFileParameters } from "./download-file-parameters";
2
+ import { FileNameMode } from "./filename-mode";
3
+
4
+ export class DownloadFileWithMetadataParameters extends DownloadFileParameters {
5
+ setFileNameMode(fileNameMode: FileNameMode): DownloadFileParameters {
6
+ if (fileNameMode === FileNameMode.TRANSFORMED) {
7
+ this.set("changeFileName", true);
8
+ }
9
+
10
+ return this;
11
+ }
12
+ }
@@ -0,0 +1,4 @@
1
+ export enum FileNameMode {
2
+ ORIGINAL = "original",
3
+ TRANSFORMED = "transformed"
4
+ }
@@ -0,0 +1,26 @@
1
+ import FormData from "form-data";
2
+ import { Logger } from "../logger";
3
+ import { AccessTokenProvider } from "../auth/access-token-provider";
4
+ import { ResponseBodyType } from "./enum/response-body-type";
5
+ export declare class SmartlingBaseApi {
6
+ protected authApi: AccessTokenProvider;
7
+ protected entrypoint: string;
8
+ protected defaultClientLibId: string;
9
+ protected defaultClientVersion: string;
10
+ protected clientLibId: string;
11
+ protected clientLibVersion: string;
12
+ protected logger: Logger;
13
+ protected options: Record<string, unknown>;
14
+ constructor(logger: Logger);
15
+ setOptions(options: Record<string, unknown>): void;
16
+ getClientLibId(): string;
17
+ setClientLibId(clientLibId: string): void;
18
+ getClientLibVersion(): string;
19
+ setClientLibVersion(clientLibVersion: string): void;
20
+ fetch(uri: string, options: Record<string, unknown>): Promise<Response>;
21
+ ua(clientId: string, clientVersion: string): string;
22
+ alterRequestData(uri: string, opts: Record<string, unknown>): Record<string, unknown>;
23
+ getDefaultHeaders(headers?: Record<string, unknown>): Promise<Record<string, unknown>>;
24
+ makeRequest(verb: string, uri: string, payload?: Record<string, unknown> | string | FormData, returnRawResponseBody?: ResponseBodyType | boolean, headers?: Record<string, unknown>): Promise<any>;
25
+ static sensitiveReplacer(key: string, value: any): any;
26
+ }