From 433c0df76858c044b4b359c9252b4401a68cdc66 Mon Sep 17 00:00:00 2001 From: Eirini Date: Tue, 23 Sep 2025 08:23:49 +0000 Subject: [PATCH 1/5] fix: removed GET with body from result() call and replaced with POST to prepare for deprecation of GET with body from API. --- CHANGES.md | 4 +++- package.json | 4 ++-- src/tinify/Source.ts | 6 +++++- test/tinify-source-test.js | 18 +++++++++--------- test/tinify-test.js | 6 +++--- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 26b2854..0e6c38c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,7 @@ -## 1.8.1 +## 1.8.2 +* Removed the `GET` with body HTTP call that was being made when obtaining the results of a compression and transforming at the same time. Replaced with `POST` in order to prepare for deprecation of `GET` with body interface from API. +## 1.8.1 * Set minimum node engine to v14 in package.json * Update examples in README * Test the code on node 24 diff --git a/package.json b/package.json index b6f8443..ef5c207 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tinify", - "version": "1.8.1", + "version": "1.8.2", "description": "Node.js client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.", "keywords": [ "tinify", @@ -54,4 +54,4 @@ "tslint": "^5.10.0", "typescript": "^5.7.3" } -} +} \ No newline at end of file diff --git a/src/tinify/Source.ts b/src/tinify/Source.ts index 7140cc3..93546b9 100644 --- a/src/tinify/Source.ts +++ b/src/tinify/Source.ts @@ -77,7 +77,11 @@ export default class Source { result(): Result { const commands = this._commands const response = this._url.then(url => { - return tinify.client.request("get", url, commands) + if(Object.keys(commands).length === 0){ + return tinify.client.request("get", url) + } else { + return tinify.client.request("post", url, commands) + } }) return new tinify.Result( diff --git a/test/tinify-source-test.js b/test/tinify-source-test.js index dfdce7f..ba2ec71 100644 --- a/test/tinify-source-test.js +++ b/test/tinify-source-test.js @@ -62,7 +62,7 @@ describe("Source", function() { it("should return source with data", function() { nock("https://api.tinify.com") - .get("/some/location") + .post("/some/location") .reply(200, "compressed file") const data = tinify.Source.fromFile(dummyFile).toBuffer() @@ -86,7 +86,7 @@ describe("Source", function() { it("should return source with data", function() { nock("https://api.tinify.com") - .get("/some/location") + .post("/some/location") .reply(200, "compressed file") const data = tinify.Source.fromBuffer("png file").toBuffer() @@ -112,7 +112,7 @@ describe("Source", function() { .reply(201, {}, {location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .get("/some/location") + .post("/some/location") .reply(200, "compressed file") const data = tinify.Source.fromUrl("http://example.com/test.jpg").toBuffer() @@ -139,7 +139,7 @@ describe("Source", function() { .reply(201, {}, {location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .get("/some/location") + .post("/some/location") .reply(200, "compressed file") }) @@ -156,7 +156,7 @@ describe("Source", function() { .reply(201, {}, {location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .get("/some/location", '{"preserve":["copyright","location"]}') + .post("/some/location", '{"preserve":["copyright","location"]}') .reply(200, "copyrighted file") }) @@ -181,7 +181,7 @@ describe("Source", function() { it("should include other options if set", function() { nock("https://api.tinify.com") - .get("/some/location", '{"preserve":["copyright","location"],"resize":{"width":400}}') + .post("/some/location", '{"preserve":["copyright","location"],"resize":{"width":400}}') .reply(200, "copyrighted resized file") const data = tinify.Source.fromBuffer("png file").resize({width: 400}).preserve("copyright", "location").toBuffer() @@ -198,7 +198,7 @@ describe("Source", function() { .reply(201, {}, {location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .get("/some/location", '{"resize":{"width":400}}') + .post("/some/location", '{"resize":{"width":400}}') .reply(200, "small file") }) @@ -257,7 +257,7 @@ describe("Source", function() { .reply(201, {}, {location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .get("/some/location") + .post("/some/location") .reply(200, "compressed file") }) @@ -276,7 +276,7 @@ describe("Source", function() { .reply(201, {}, {location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .get("/some/location") + .post("/some/location") .reply(200, "compressed file") }) diff --git a/test/tinify-test.js b/test/tinify-test.js index 702036e..870ab66 100644 --- a/test/tinify-test.js +++ b/test/tinify-test.js @@ -192,7 +192,7 @@ describe("tinify", function() { .reply(201, {}, {Location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .get("/some/location") + .post("/some/location") .reply(200, "compressed file") }) @@ -215,7 +215,7 @@ describe("tinify", function() { .reply(201, {}, {Location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .get("/some/location") + .post("/some/location") .reply(200, "compressed file") }) @@ -238,7 +238,7 @@ describe("tinify", function() { .reply(201, {}, {Location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .get("/some/location") + .post("/some/location") .reply(200, "compressed file") }) From 34a7c102613db21ab3a38532b7603d2426d710a6 Mon Sep 17 00:00:00 2001 From: Eirini Date: Tue, 23 Sep 2025 10:44:16 +0200 Subject: [PATCH 2/5] fix: fixed unit tests --- test/tinify-source-test.js | 12 ++++++------ test/tinify-test.js | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/tinify-source-test.js b/test/tinify-source-test.js index ba2ec71..e99e200 100644 --- a/test/tinify-source-test.js +++ b/test/tinify-source-test.js @@ -62,7 +62,7 @@ describe("Source", function() { it("should return source with data", function() { nock("https://api.tinify.com") - .post("/some/location") + .get("/some/location") .reply(200, "compressed file") const data = tinify.Source.fromFile(dummyFile).toBuffer() @@ -86,7 +86,7 @@ describe("Source", function() { it("should return source with data", function() { nock("https://api.tinify.com") - .post("/some/location") + .get("/some/location") .reply(200, "compressed file") const data = tinify.Source.fromBuffer("png file").toBuffer() @@ -112,7 +112,7 @@ describe("Source", function() { .reply(201, {}, {location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .post("/some/location") + .get("/some/location") .reply(200, "compressed file") const data = tinify.Source.fromUrl("http://example.com/test.jpg").toBuffer() @@ -139,7 +139,7 @@ describe("Source", function() { .reply(201, {}, {location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .post("/some/location") + .get("/some/location") .reply(200, "compressed file") }) @@ -257,7 +257,7 @@ describe("Source", function() { .reply(201, {}, {location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .post("/some/location") + .get("/some/location") .reply(200, "compressed file") }) @@ -276,7 +276,7 @@ describe("Source", function() { .reply(201, {}, {location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .post("/some/location") + .get("/some/location") .reply(200, "compressed file") }) diff --git a/test/tinify-test.js b/test/tinify-test.js index 870ab66..702036e 100644 --- a/test/tinify-test.js +++ b/test/tinify-test.js @@ -192,7 +192,7 @@ describe("tinify", function() { .reply(201, {}, {Location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .post("/some/location") + .get("/some/location") .reply(200, "compressed file") }) @@ -215,7 +215,7 @@ describe("tinify", function() { .reply(201, {}, {Location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .post("/some/location") + .get("/some/location") .reply(200, "compressed file") }) @@ -238,7 +238,7 @@ describe("tinify", function() { .reply(201, {}, {Location: "https://api.tinify.com/some/location"}) nock("https://api.tinify.com") - .post("/some/location") + .get("/some/location") .reply(200, "compressed file") }) From 25e4813cf7fcbde5fab018aaf02b173d328f64fb Mon Sep 17 00:00:00 2001 From: Eirini Date: Tue, 23 Sep 2025 10:48:11 +0200 Subject: [PATCH 3/5] fix:updated package version of tmp --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ef5c207..9c376c7 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "mocha": "^2.2.5", "nock": "^13.2.9", "semver": "*", - "tmp": "^0.0.26", + "tmp": "^0.2.4", "tslint": "^5.10.0", "typescript": "^5.7.3" } From 268034dd0646626f8bc85da712257428f8bb3839 Mon Sep 17 00:00:00 2001 From: Eirini Date: Tue, 23 Sep 2025 10:53:16 +0200 Subject: [PATCH 4/5] chore: cleaned up code --- src/tinify/Source.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/tinify/Source.ts b/src/tinify/Source.ts index 93546b9..df6ba63 100644 --- a/src/tinify/Source.ts +++ b/src/tinify/Source.ts @@ -77,11 +77,10 @@ export default class Source { result(): Result { const commands = this._commands const response = this._url.then(url => { - if(Object.keys(commands).length === 0){ - return tinify.client.request("get", url) - } else { + if (Object.keys(commands).length > 0) { return tinify.client.request("post", url, commands) } + return tinify.client.request("get", url) }) return new tinify.Result( From fad324b18f17e48d8c4f2a4115734ebad63fd083 Mon Sep 17 00:00:00 2001 From: Eirini Date: Tue, 23 Sep 2025 10:54:56 +0200 Subject: [PATCH 5/5] chore: updated changes --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 0e6c38c..2e03d03 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ## 1.8.2 * Removed the `GET` with body HTTP call that was being made when obtaining the results of a compression and transforming at the same time. Replaced with `POST` in order to prepare for deprecation of `GET` with body interface from API. +* Updated dependencies. ## 1.8.1 * Set minimum node engine to v14 in package.json