Skip to content

Commit 63e7e83

Browse files
committed
v14.7.0
1 parent 65b8307 commit 63e7e83

File tree

14 files changed

+119
-23
lines changed

14 files changed

+119
-23
lines changed

dist/main.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ interface ClientData {
7575
tokenType: string;
7676
authHeader: string;
7777
enableCompression: boolean;
78+
silent: boolean;
7879
host?: string;
7980
version?: string;
8081
requestTimeout?: number;
@@ -1333,6 +1334,10 @@ type ClientParams = {
13331334
* Request timeout in milliseconds. If not provided, requests have no explicit timeout.
13341335
*/
13351336
requestTimeout?: number;
1337+
/**
1338+
* Silent mode (supress all warning/error messages). Defaults to false.
1339+
*/
1340+
silent?: boolean;
13361341
};
13371342

13381343
interface ProjectSettings {
@@ -3081,7 +3086,7 @@ declare class BaseClient {
30813086
* @param params - Configuration parameters including API key and optional features.
30823087
* @throws Error if the API key is not provided or is empty.
30833088
*/
3084-
constructor(params: ClientParams);
3089+
constructor({ apiKey, enableCompression, silent, tokenType, host, requestTimeout, }: ClientParams);
30853090
}
30863091

30873092
/**

dist/main.js

Lines changed: 23 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/additional_info/changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 14.7.0 (09-May-2025)
4+
5+
* Added `silent` option for `LokaliseApi` to supress warning messages (default is `false`):
6+
7+
```js
8+
const client = new LokaliseApi({
9+
// other config ...
10+
silent: true,
11+
});
12+
```
13+
314
## 14.6.0 (08-May-2025)
415

516
* Added support for [Get team details](https://developers.lokalise.com/reference/get-team-details) endpoint

docs/additional_info/customizing_client.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ const client = new LokaliseApi({
3030

3131
Then use your `client` as usual.
3232

33+
## Silent mode
34+
35+
To supress all warning messages, set the `silent` option to `true` (`false` by default):
36+
37+
```js
38+
const client = new LokaliseApi({
39+
// other config ...
40+
silent: true,
41+
});
42+
```
43+
3344
## Proxy support
3445

3546
If you are behind a firewall and have to use proxy in order to communicate with Lokalise API, that's not a problem! You can take advantage of the [global-agent](https://github.com/gajus/global-agent) package which allows to enable proxy globally without the need to do any changes to your API-related script.

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lokalise/node-api",
3-
"version": "14.6.0",
3+
"version": "14.7.0",
44
"description": "Official Lokalise API 2.0 Node.js client",
55
"license": "BSD-3-Clause",
66
"repository": {

src/collections/files.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
ListFileParams,
1010
UploadFileParams,
1111
} from "../types/files.js";
12+
import { warn } from "../utils/logger.js";
1213
import { BaseCollection } from "./base_collection.js";
1314

1415
export class Files extends BaseCollection<File, QueuedProcess> {
@@ -39,7 +40,8 @@ export class Files extends BaseCollection<File, QueuedProcess> {
3940
headers: Headers,
4041
): T {
4142
if (this.isResponseTooBig(headers)) {
42-
console.warn(
43+
warn(
44+
this.clientData.silent,
4345
"\x1b[33m\x1b[1mWarning:\x1b[0m Project too big for sync export. Please use our async export lokaliseApi.files().async_download() method.",
4446
);
4547
}

src/interfaces/client_data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface ClientData {
33
tokenType: string;
44
authHeader: string;
55
enableCompression: boolean;
6+
silent: boolean;
67
host?: string;
78
version?: string;
89
requestTimeout?: number;

src/interfaces/client_params.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ export type ClientParams = {
3838
* Request timeout in milliseconds. If not provided, requests have no explicit timeout.
3939
*/
4040
requestTimeout?: number;
41+
42+
/**
43+
* Silent mode (supress all warning/error messages). Defaults to false.
44+
*/
45+
silent?: boolean;
4146
};

src/lokalise/base_client.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,33 @@ export class BaseClient {
1515
authHeader: "x-api-token",
1616
enableCompression: false,
1717
requestTimeout: undefined,
18+
silent: false,
1819
};
1920

2021
/**
2122
* Constructs a new BaseClient instance.
2223
* @param params - Configuration parameters including API key and optional features.
2324
* @throws Error if the API key is not provided or is empty.
2425
*/
25-
constructor(params: ClientParams) {
26-
const { apiKey } = params;
26+
constructor({
27+
apiKey,
28+
enableCompression = false,
29+
silent = false,
30+
tokenType = "",
31+
host,
32+
requestTimeout,
33+
}: ClientParams) {
2734
if (typeof apiKey !== "string" || apiKey.trim().length === 0) {
2835
throw new Error(
2936
"Instantiation failed: A non-empty API key or JWT must be provided.",
3037
);
3138
}
3239

3340
this.clientData.token = apiKey;
34-
this.clientData.enableCompression = params.enableCompression ?? false;
35-
this.clientData.tokenType = params.tokenType ?? "";
36-
this.clientData.host = params.host;
37-
this.clientData.requestTimeout = params.requestTimeout;
41+
this.clientData.enableCompression = enableCompression;
42+
this.clientData.silent = silent;
43+
this.clientData.tokenType = tokenType;
44+
this.clientData.host = host;
45+
this.clientData.requestTimeout = requestTimeout;
3846
}
3947
}

src/utils/logger.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Emits a warning to the console unless `silent` is true.
3+
*
4+
* @param silent - If true, suppresses the log output.
5+
* @param args - The items to log, passed to `console.warn`.
6+
*/
7+
export function warn(silent: boolean, ...args: unknown[]): void {
8+
if (silent) return;
9+
10+
console.warn(...args);
11+
}

test/lokalise/lokalise_api.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe("LokaliseApi", () => {
1515
expect(client.clientData.token).to.eq(process.env.API_KEY);
1616
expect(client.clientData.authHeader).to.eq("x-api-token");
1717
expect(client.clientData.enableCompression).to.be.false;
18+
expect(client.clientData.silent).to.be.false;
1819
expect(client.clientData.version).to.eq("api2");
1920
});
2021

test/utils/logger.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { warn } from "../../src/utils/logger.js";
2+
import { describe, expect, it, vi } from "../setup.js";
3+
4+
describe("logger", () => {
5+
it("warns when silent is disabled", async () => {
6+
const message = "sample message";
7+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
8+
9+
warn(false, message);
10+
11+
expect(warnSpy).toHaveBeenCalledWith(message);
12+
13+
warnSpy.mockRestore();
14+
});
15+
16+
it("does not warn when silent is enabled", async () => {
17+
const message = "sample message";
18+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
19+
20+
warn(true, message);
21+
22+
expect(warnSpy).not.toHaveBeenCalledWith(message);
23+
24+
warnSpy.mockRestore();
25+
});
26+
});

0 commit comments

Comments
 (0)