@lokalise/node-api
Advanced tools
Comparing version 6.2.2 to 6.3.0
@@ -27,2 +27,6 @@ "use strict"; | ||
}; | ||
if (lokalise_1.LokaliseApi.enableCompression && options["headers"]) { | ||
options["headers"]["Accept-Encoding"] = "gzip,deflate"; | ||
options["decompress"] = true; | ||
} | ||
const url = this.composeURI(uri); | ||
@@ -29,0 +33,0 @@ if (Object.keys(this.params).length > 0) { |
import { LocaliseApiMethods } from "./api_methods"; | ||
export declare class LokaliseApi extends LocaliseApiMethods { | ||
static apiKey: string | null; | ||
apiKey: string; | ||
static enableCompression: boolean; | ||
/** | ||
@@ -6,0 +6,0 @@ * Instantiate LokaliseApi to have access to methods |
@@ -17,2 +17,9 @@ "use strict"; | ||
} | ||
const compression = Object(params)["enableCompression"]; | ||
if (compression == null) { | ||
LokaliseApi.enableCompression = false; | ||
} | ||
else { | ||
LokaliseApi.enableCompression = compression; | ||
} | ||
return this; | ||
@@ -23,2 +30,3 @@ } | ||
LokaliseApi.apiKey = null; | ||
LokaliseApi.enableCompression = false; | ||
//# sourceMappingURL=lokalise.js.map |
# Changelog | ||
## 6.3.0 (15-Jul-21) | ||
* Added `enableCompression` option: `new LokaliseApi({ apiKey: "123abc", enableCompression: true })`. The default value for this option is `false`. When set to `true`, it will add an `Accept-Encoding=gzip,deflate` header to the request. It can be very useful when requesting a large amount of data. | ||
## 6.2.2 (13-Jul-21) | ||
@@ -4,0 +8,0 @@ |
@@ -86,1 +86,11 @@ # Getting Started | ||
``` | ||
## Compression | ||
Lokalise API supports gzip compression. By default it's turned off but you can enable it by setting the `enableCompression` option: | ||
```js | ||
new LokaliseApi({ apiKey: "123abc", enableCompression: true }) | ||
``` | ||
When this option is set to `true`, it will add an `Accept-Encoding=gzip,deflate` header to the request. It can be very useful when requesting a large amount of data. |
@@ -0,0 +0,0 @@ import { Options } from "got"; |
{ | ||
"name": "@lokalise/node-api", | ||
"version": "6.2.2", | ||
"version": "6.3.0", | ||
"description": "Official Lokalise API 2.0 Node.js client", | ||
@@ -26,3 +26,3 @@ "license": "BSD-3-Clause", | ||
"@types/mocha": "^8.2.0", | ||
"@types/node": "^16.0.0", | ||
"@types/node": "^16.3.2", | ||
"@typescript-eslint/eslint-plugin": "^4.24.0", | ||
@@ -29,0 +29,0 @@ "@typescript-eslint/parser": "^4.24.0", |
@@ -41,2 +41,7 @@ import { RequestError, Response, Options } from "got"; | ||
if (LokaliseApi.enableCompression && options["headers"]) { | ||
options["headers"]["Accept-Encoding"] = "gzip,deflate"; | ||
options["decompress"] = true; | ||
} | ||
const url: string = this.composeURI(uri); | ||
@@ -43,0 +48,0 @@ |
@@ -0,0 +0,0 @@ export interface UploadFileParams { |
import { LocaliseApiMethods } from "./api_methods"; | ||
export class LokaliseApi extends LocaliseApiMethods { | ||
public static apiKey: string | null = null; | ||
static apiKey: string | null = null; | ||
static enableCompression: boolean = false; | ||
public apiKey: string; | ||
/** | ||
@@ -19,4 +18,10 @@ * Instantiate LokaliseApi to have access to methods | ||
} | ||
const compression = Object(params)["enableCompression"]; | ||
if (compression == null) { | ||
LokaliseApi.enableCompression = false; | ||
} else { | ||
LokaliseApi.enableCompression = compression; | ||
} | ||
return this; | ||
} | ||
} |
@@ -0,0 +0,0 @@ import { BaseModel } from "./base_model"; |
@@ -0,0 +0,0 @@ import { BaseModel } from "./base_model"; |
@@ -0,4 +1,10 @@ | ||
require("../setup"); | ||
import { expect } from "chai"; | ||
import { Cassettes } from "mocha-cassettes"; | ||
import { LokaliseApi } from "../../src/lokalise/lokalise"; | ||
const cassette = new Cassettes("./test/cassettes"); | ||
const lokaliseApi = new LokaliseApi({ apiKey: process.env.API_KEY }); | ||
const project_id = "803826145ba90b42d5d860.46800099"; | ||
describe("LokaliseApi", function () { | ||
@@ -9,4 +15,47 @@ it("is expected to throw an error if the API key is not provided", function () { | ||
}).to.throw(Error); | ||
new LokaliseApi({ apiKey: process.env.API_KEY }); // weird issue when the token gets unloaded for all tests | ||
new LokaliseApi({ apiKey: process.env.API_KEY }); | ||
}); | ||
}); | ||
describe("LokaliseApi gzip", function () { | ||
cassette | ||
.createTest("list_with_gzip", async () => { | ||
new LokaliseApi({ apiKey: process.env.API_KEY, enableCompression: true }); | ||
const keys = await lokaliseApi.keys.list({ project_id: project_id }); | ||
expect(keys.items[0].key_id).to.eq(44596059); | ||
new LokaliseApi({ | ||
apiKey: process.env.API_KEY, | ||
enableCompression: false, | ||
}); | ||
}) | ||
.register(this); | ||
cassette | ||
.createTest("system_languages_no_gzip", async () => { | ||
new LokaliseApi({ | ||
apiKey: process.env.API_KEY, | ||
enableCompression: false, | ||
}); | ||
const languages = await lokaliseApi.languages.system_languages({ | ||
page: 3, | ||
limit: 1, | ||
}); | ||
expect(languages.items[0].lang_id).to.eq(790); | ||
}) | ||
.register(this); | ||
cassette | ||
.createTest("system_languages_default_gzip", async () => { | ||
new LokaliseApi({ apiKey: process.env.API_KEY }); | ||
const languages = await lokaliseApi.languages.system_languages({ | ||
page: 4, | ||
limit: 1, | ||
}); | ||
expect(languages.items[0].lang_id).to.eq(791); | ||
}) | ||
.register(this); | ||
}); |
@@ -22,5 +22,5 @@ require("../setup"); | ||
expect(teams.items[0].team_id).to.eq(176692); | ||
expect(teams.totalResults).to.eq(3); | ||
expect(teams.totalPages).to.eq(3); | ||
expect(teams.items[0].team_id).to.eq(186612); | ||
expect(teams.totalResults).to.eq(4); | ||
expect(teams.totalPages).to.eq(4); | ||
expect(teams.resultsPerPage).to.eq(1); | ||
@@ -30,2 +30,18 @@ expect(teams.currentPage).to.eq(2); | ||
.register(this); | ||
cassette | ||
.createTest("list_pagination_gzip", async () => { | ||
const anotherApi = new LokaliseApi({ | ||
apiKey: process.env.API_KEY, | ||
enableCompression: true, | ||
}); | ||
const teams = await anotherApi.teams.list({ page: 2, limit: 1 }); | ||
expect(teams.items[0].team_id).to.eq(186612); | ||
expect(teams.totalResults).to.eq(4); | ||
expect(teams.totalPages).to.eq(4); | ||
expect(teams.resultsPerPage).to.eq(1); | ||
expect(teams.currentPage).to.eq(2); | ||
}) | ||
.register(this); | ||
}); |
@@ -0,0 +0,0 @@ require("../setup"); |
@@ -0,0 +0,0 @@ require("../setup"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
977505
515
6484