smartling-api-sdk-nodejs 2.6.0 → 2.7.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.
@@ -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=AYyITSNeRe7rJHsZ61oT
6
- ceTaskUrl=https://sonar-next.connectors.stg.smartling.net/api/ce/task?id=AYyITSNeRe7rJHsZ61oT
5
+ ceTaskId=AYzU_wxtRe7rJHsZ61o0
6
+ ceTaskUrl=https://sonar-next.connectors.stg.smartling.net/api/ce/task?id=AYzU_wxtRe7rJHsZ61o0
@@ -0,0 +1,7 @@
1
+ interface PublishedFileDto {
2
+ fileUri: string;
3
+ localeId: string;
4
+ publishDate: Date;
5
+ }
6
+
7
+ export { PublishedFileDto };
@@ -0,0 +1,25 @@
1
+ import { SmartlingBaseApi } from "../base/index";
2
+ import { SmartlingAuthApi } from "../auth/index";
3
+ import { Logger } from "../logger";
4
+ import { RecentlyPublishedFilesParameters } from "./params/recently-published-files-parameters";
5
+ import { PublishedFileDto } from "./dto/published-file-dto";
6
+ import { SmartlingListResponse } from "../http/smartling-list-response";
7
+
8
+ export class SmartlingPublishedFilesApi extends SmartlingBaseApi {
9
+ constructor(smartlingApiBaseUrl: string, authApi: SmartlingAuthApi, logger: Logger) {
10
+ super(logger);
11
+
12
+ this.authApi = authApi;
13
+ this.entrypoint = `${smartlingApiBaseUrl}/published-files-api/v2`;
14
+ }
15
+
16
+ public async getRecentlyPublishedFiles(
17
+ projectUid: string, params: RecentlyPublishedFilesParameters
18
+ ): Promise<SmartlingListResponse<PublishedFileDto>> {
19
+ return await this.makeRequest(
20
+ "get",
21
+ `${this.entrypoint}/projects/${projectUid}/files/list/recently-published`,
22
+ params.export()
23
+ );
24
+ }
25
+ }
@@ -0,0 +1,42 @@
1
+ import { BaseParameters } from "../../parameters";
2
+ import { SmartlingException } from "../../exception";
3
+
4
+ export class RecentlyPublishedFilesParameters extends BaseParameters {
5
+ public setPublishedAfterDate(publishedAfterDate: Date): RecentlyPublishedFilesParameters {
6
+ this.set("publishedAfter", `${publishedAfterDate.toISOString().split(".")[0]}Z`);
7
+
8
+ return this;
9
+ }
10
+
11
+ setLimit(limit: number): RecentlyPublishedFilesParameters {
12
+ if (limit > 0) {
13
+ this.set("limit", limit);
14
+
15
+ return this;
16
+ }
17
+
18
+ throw new SmartlingException("Limit must be > 0");
19
+ }
20
+
21
+ setOffset(offset: number): RecentlyPublishedFilesParameters {
22
+ if (offset >= 0) {
23
+ this.set("offset", offset);
24
+
25
+ return this;
26
+ }
27
+
28
+ throw new SmartlingException("Offset must be >= 0");
29
+ }
30
+
31
+ setFileUris(fileUris: Array<string>): RecentlyPublishedFilesParameters {
32
+ this.set("fileUris[]", fileUris);
33
+
34
+ return this;
35
+ }
36
+
37
+ setLocaleIds(localeIds: Array<string>): RecentlyPublishedFilesParameters {
38
+ this.set("localeIds[]", localeIds);
39
+
40
+ return this;
41
+ }
42
+ }
@@ -0,0 +1,6 @@
1
+ interface PublishedFileDto {
2
+ fileUri: string;
3
+ localeId: string;
4
+ publishDate: Date;
5
+ }
6
+ export { PublishedFileDto };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=published-file-dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"published-file-dto.js","sourceRoot":"","sources":["../../../../api/published-files/dto/published-file-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 { RecentlyPublishedFilesParameters } from "./params/recently-published-files-parameters";
5
+ import { PublishedFileDto } from "./dto/published-file-dto";
6
+ import { SmartlingListResponse } from "../http/smartling-list-response";
7
+ export declare class SmartlingPublishedFilesApi extends SmartlingBaseApi {
8
+ constructor(smartlingApiBaseUrl: string, authApi: SmartlingAuthApi, logger: Logger);
9
+ getRecentlyPublishedFiles(projectUid: string, params: RecentlyPublishedFilesParameters): Promise<SmartlingListResponse<PublishedFileDto>>;
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.SmartlingPublishedFilesApi = void 0;
13
+ const index_1 = require("../base/index");
14
+ class SmartlingPublishedFilesApi extends index_1.SmartlingBaseApi {
15
+ constructor(smartlingApiBaseUrl, authApi, logger) {
16
+ super(logger);
17
+ this.authApi = authApi;
18
+ this.entrypoint = `${smartlingApiBaseUrl}/published-files-api/v2`;
19
+ }
20
+ getRecentlyPublishedFiles(projectUid, params) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return yield this.makeRequest("get", `${this.entrypoint}/projects/${projectUid}/files/list/recently-published`, params.export());
23
+ });
24
+ }
25
+ }
26
+ exports.SmartlingPublishedFilesApi = SmartlingPublishedFilesApi;
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/published-files/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAiD;AAOjD,MAAa,0BAA2B,SAAQ,wBAAgB;IAC5D,YAAY,mBAA2B,EAAE,OAAyB,EAAE,MAAc;QAC9E,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,GAAG,mBAAmB,yBAAyB,CAAC;IACtE,CAAC;IAEY,yBAAyB,CAClC,UAAkB,EAAE,MAAwC;;YAE5D,OAAO,MAAM,IAAI,CAAC,WAAW,CACzB,KAAK,EACL,GAAG,IAAI,CAAC,UAAU,aAAa,UAAU,gCAAgC,EACzE,MAAM,CAAC,MAAM,EAAE,CAClB,CAAC;QACN,CAAC;KAAA;CACJ;AAjBD,gEAiBC"}
@@ -0,0 +1,8 @@
1
+ import { BaseParameters } from "../../parameters";
2
+ export declare class RecentlyPublishedFilesParameters extends BaseParameters {
3
+ setPublishedAfterDate(publishedAfterDate: Date): RecentlyPublishedFilesParameters;
4
+ setLimit(limit: number): RecentlyPublishedFilesParameters;
5
+ setOffset(offset: number): RecentlyPublishedFilesParameters;
6
+ setFileUris(fileUris: Array<string>): RecentlyPublishedFilesParameters;
7
+ setLocaleIds(localeIds: Array<string>): RecentlyPublishedFilesParameters;
8
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecentlyPublishedFilesParameters = void 0;
4
+ const parameters_1 = require("../../parameters");
5
+ const exception_1 = require("../../exception");
6
+ class RecentlyPublishedFilesParameters extends parameters_1.BaseParameters {
7
+ setPublishedAfterDate(publishedAfterDate) {
8
+ this.set("publishedAfter", `${publishedAfterDate.toISOString().split(".")[0]}Z`);
9
+ return this;
10
+ }
11
+ setLimit(limit) {
12
+ if (limit > 0) {
13
+ this.set("limit", limit);
14
+ return this;
15
+ }
16
+ throw new exception_1.SmartlingException("Limit must be > 0");
17
+ }
18
+ setOffset(offset) {
19
+ if (offset >= 0) {
20
+ this.set("offset", offset);
21
+ return this;
22
+ }
23
+ throw new exception_1.SmartlingException("Offset must be >= 0");
24
+ }
25
+ setFileUris(fileUris) {
26
+ this.set("fileUris[]", fileUris);
27
+ return this;
28
+ }
29
+ setLocaleIds(localeIds) {
30
+ this.set("localeIds[]", localeIds);
31
+ return this;
32
+ }
33
+ }
34
+ exports.RecentlyPublishedFilesParameters = RecentlyPublishedFilesParameters;
35
+ //# sourceMappingURL=recently-published-files-parameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recently-published-files-parameters.js","sourceRoot":"","sources":["../../../../api/published-files/params/recently-published-files-parameters.ts"],"names":[],"mappings":";;;AAAA,iDAAkD;AAClD,+CAAqD;AAErD,MAAa,gCAAiC,SAAQ,2BAAc;IACzD,qBAAqB,CAAC,kBAAwB;QACjD,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAEjF,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,QAAQ,CAAC,KAAa;QAClB,IAAI,KAAK,GAAG,CAAC,EAAE;YACX,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAEzB,OAAO,IAAI,CAAC;SACf;QAED,MAAM,IAAI,8BAAkB,CAAC,mBAAmB,CAAC,CAAC;IACtD,CAAC;IAED,SAAS,CAAC,MAAc;QACpB,IAAI,MAAM,IAAI,CAAC,EAAE;YACb,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAE3B,OAAO,IAAI,CAAC;SACf;QAED,MAAM,IAAI,8BAAkB,CAAC,qBAAqB,CAAC,CAAC;IACxD,CAAC;IAED,WAAW,CAAC,QAAuB;QAC/B,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAEjC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,YAAY,CAAC,SAAwB;QACjC,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;QAEnC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAtCD,4EAsCC"}
package/built/index.d.ts CHANGED
@@ -83,6 +83,9 @@ export * from "./api/parameters/order";
83
83
  export * from "./api/projects/index";
84
84
  export * from "./api/projects/dto/project-dto";
85
85
  export * from "./api/projects/dto/locale-dto";
86
+ export * from "./api/published-files/index";
87
+ export * from "./api/published-files/dto/published-file-dto";
88
+ export * from "./api/published-files/params/recently-published-files-parameters";
86
89
  export * from "./api/strings/index";
87
90
  export * from "./api/strings/dto/source-string-dto";
88
91
  export * from "./api/strings/dto/source-string-key-dto";
package/built/index.js CHANGED
@@ -99,6 +99,9 @@ __exportStar(require("./api/parameters/order"), exports);
99
99
  __exportStar(require("./api/projects/index"), exports);
100
100
  __exportStar(require("./api/projects/dto/project-dto"), exports);
101
101
  __exportStar(require("./api/projects/dto/locale-dto"), exports);
102
+ __exportStar(require("./api/published-files/index"), exports);
103
+ __exportStar(require("./api/published-files/dto/published-file-dto"), exports);
104
+ __exportStar(require("./api/published-files/params/recently-published-files-parameters"), exports);
102
105
  __exportStar(require("./api/strings/index"), exports);
103
106
  __exportStar(require("./api/strings/dto/source-string-dto"), exports);
104
107
  __exportStar(require("./api/strings/dto/source-string-key-dto"), exports);
@@ -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,oEAAkD;AAClD,+DAA6C;AAC7C,4EAA0D;AAC1D,kFAAgE;AAChE,kFAAgE;AAChE,+EAA6D;AAC7D,oEAAkD;AAClD,qEAAmD;AACnD,0DAAwC;AACxC,kEAAgD;AAChD,uEAAqD;AACrD,yEAAuD;AACvD,yEAAuD;AACvD,4EAA0D;AAC1D,mFAAiE;AACjE,wFAAsE;AACtE,2FAAyE;AACzE,wFAAsE;AACtE,0FAAwE;AACxE,wEAAsD;AACtD,wEAAsD;AACtD,mFAAiE;AACjE,6EAA2D;AAC3D,mDAAiC;AACjC,8DAA4C;AAC5C,kFAAgE;AAChE,kEAAgD;AAChD,mEAAiD;AACjD,sEAAoD;AACpD,iEAA+C;AAC/C,yDAAuC;AACvC,iEAA+C;AAC/C,mFAAiE;AACjE,uFAAqE;AACrE,kEAAgD;AAChD,mEAAiD;AACjD,yEAAuD;AACvD,kEAAgD;AAChD,0EAAwD;AACxD,6EAA2D;AAC3D,4EAA0D;AAC1D,+DAA6C;AAC7C,8EAA4D;AAC5D,yEAAuD;AACvD,2EAAyD;AACzD,0EAAwD;AACxD,yEAAuD;AACvD,2EAAyD;AACzD,yDAAuC;AACvC,yDAAuC;AACvC,uDAAqC;AACrC,iEAA+C;AAC/C,gEAA8C;AAC9C,sDAAoC;AACpC,sEAAoD;AACpD,0EAAwD;AACxD,uFAAqE;AACrE,+CAA6B;AAC7B,wEAAsD;AACtD,+FAA6E;AAC7E,6EAA2D"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,kEAAgD;AAChD,mDAAiC;AACjC,sDAAoC;AACpC,sDAAoC;AACpC,wEAAsD;AACtD,6EAA2D;AAC3D,gEAA8C;AAC9C,4EA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AACrE,+CAA6B;AAC7B,wEAAsD;AACtD,+FAA6E;AAC7E,6EAA2D"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smartling-api-sdk-nodejs",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Package for Smartling API",
5
5
  "main": "built/index.js",
6
6
  "engines": {
package/index.ts CHANGED
@@ -83,6 +83,9 @@ export * from "./api/parameters/order";
83
83
  export * from "./api/projects/index";
84
84
  export * from "./api/projects/dto/project-dto";
85
85
  export * from "./api/projects/dto/locale-dto";
86
+ export * from "./api/published-files/index";
87
+ export * from "./api/published-files/dto/published-file-dto";
88
+ export * from "./api/published-files/params/recently-published-files-parameters";
86
89
  export * from "./api/strings/index";
87
90
  export * from "./api/strings/dto/source-string-dto";
88
91
  export * from "./api/strings/dto/source-string-key-dto";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smartling-api-sdk-nodejs",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Package for Smartling API",
5
5
  "main": "built/index.js",
6
6
  "engines": {
@@ -0,0 +1,74 @@
1
+ import sinon from "sinon";
2
+ import assert from "assert";
3
+ import { SmartlingPublishedFilesApi } from "../api/published-files";
4
+ import { RecentlyPublishedFilesParameters } from "../api/published-files/params/recently-published-files-parameters";
5
+ import { SmartlingAuthApi } from "../api/auth/index";
6
+ import { loggerMock, authMock, responseMock } from "./mock";
7
+
8
+ describe("SmartlingPublishedFilesApi class tests.", () => {
9
+ let publishedFilesApi;
10
+ let publishedFilesApiFetchStub;
11
+ let publishedFilesApiUaStub;
12
+ let responseMockTextStub;
13
+
14
+ beforeEach(() => {
15
+ publishedFilesApi = new SmartlingPublishedFilesApi("https://test.com", authMock as unknown as SmartlingAuthApi, loggerMock);
16
+
17
+ publishedFilesApiFetchStub = sinon.stub(publishedFilesApi, "fetch");
18
+ publishedFilesApiUaStub = sinon.stub(publishedFilesApi, "ua");
19
+ responseMockTextStub = sinon.stub(responseMock, "text");
20
+
21
+ publishedFilesApiUaStub.returns("test_user_agent");
22
+ publishedFilesApiFetchStub.returns(responseMock);
23
+ responseMockTextStub.returns("{\"response\": {}}");
24
+ });
25
+
26
+ afterEach(() => {
27
+ publishedFilesApiFetchStub.restore();
28
+ responseMockTextStub.restore();
29
+ publishedFilesApiUaStub.restore();
30
+ });
31
+
32
+ it("Get recently published files", async () => {
33
+ const params: RecentlyPublishedFilesParameters = new RecentlyPublishedFilesParameters();
34
+
35
+ params.setPublishedAfterDate(new Date("2020-09-24T00:00:00Z"));
36
+ params.setFileUris(["test:_1.xml", "test/file&_2.xml"]);
37
+ params.setLocaleIds(["fr", "de"]);
38
+ params.setOffset(0);
39
+ params.setLimit(100);
40
+
41
+ await publishedFilesApi.getRecentlyPublishedFiles("test_project", params);
42
+
43
+ sinon.assert.calledOnce(publishedFilesApiFetchStub);
44
+ sinon.assert.calledWithExactly(
45
+ publishedFilesApiFetchStub,
46
+ "https://test.com/published-files-api/v2/projects/test_project/files/list/recently-published?publishedAfter=2020-09-24T00%3A00%3A00Z&fileUris%5B%5D=test%3A_1.xml&fileUris%5B%5D=test%2Ffile%26_2.xml&localeIds%5B%5D=fr&localeIds%5B%5D=de&offset=0&limit=100", {
47
+ headers: {
48
+ Authorization: "test_token_type test_access_token",
49
+ "Content-Type": "application/json",
50
+ "User-Agent": "test_user_agent"
51
+ },
52
+ method: "get"
53
+ }
54
+ );
55
+ });
56
+
57
+ it("Invalid offset", async () => {
58
+ try {
59
+ new RecentlyPublishedFilesParameters().setOffset(-1);
60
+ } catch (e) {
61
+ assert.equal(e.constructor.name, "SmartlingException");
62
+ assert.equal(e.message, "Offset must be >= 0");
63
+ }
64
+ });
65
+
66
+ it("Invalid limit", async () => {
67
+ try {
68
+ new RecentlyPublishedFilesParameters().setLimit(0);
69
+ } catch (e) {
70
+ assert.equal(e.constructor.name, "SmartlingException");
71
+ assert.equal(e.message, "Limit must be > 0");
72
+ }
73
+ });
74
+ });