@camstack/sdk 1.2.131 → 1.2.133
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.
- package/dist/index.cjs +11 -1
- package/dist/index.js +11 -1
- package/dist/system.d.ts +9 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -684,6 +684,7 @@ var System = class {
|
|
|
684
684
|
maxRetryMs;
|
|
685
685
|
onConnectionChange;
|
|
686
686
|
token;
|
|
687
|
+
getLanguage;
|
|
687
688
|
_trpcClient;
|
|
688
689
|
_wsClient = null;
|
|
689
690
|
/**
|
|
@@ -714,6 +715,7 @@ var System = class {
|
|
|
714
715
|
constructor(config) {
|
|
715
716
|
this._serverUrl = config.serverUrl.replace(/\/+$/, "");
|
|
716
717
|
this.token = config.token;
|
|
718
|
+
this.getLanguage = config.getLanguage ?? (() => void 0);
|
|
717
719
|
const isBrowser = typeof window !== "undefined";
|
|
718
720
|
this.useWs = config.useWebSocket ?? isBrowser;
|
|
719
721
|
this.onConnectionChange = config.onConnectionChange;
|
|
@@ -1354,6 +1356,8 @@ var System = class {
|
|
|
1354
1356
|
const headers = () => {
|
|
1355
1357
|
const h = {};
|
|
1356
1358
|
if (this.token) h["Authorization"] = `Bearer ${this.token}`;
|
|
1359
|
+
const lang = this.getLanguage();
|
|
1360
|
+
if (lang) h["x-camstack-lang"] = lang;
|
|
1357
1361
|
return h;
|
|
1358
1362
|
};
|
|
1359
1363
|
if (this.useWs) {
|
|
@@ -1363,7 +1367,13 @@ var System = class {
|
|
|
1363
1367
|
const epoch = this._wsEpoch;
|
|
1364
1368
|
this._wsClient = (0, _trpc_client.createWSClient)({
|
|
1365
1369
|
url: wsUrl,
|
|
1366
|
-
connectionParams: () =>
|
|
1370
|
+
connectionParams: () => {
|
|
1371
|
+
const lang = this.getLanguage();
|
|
1372
|
+
return {
|
|
1373
|
+
...this.token !== void 0 ? { token: this.token } : {},
|
|
1374
|
+
...lang ? { lang } : {}
|
|
1375
|
+
};
|
|
1376
|
+
},
|
|
1367
1377
|
retryDelayMs: (attemptIndex) => Math.min(baseRetryMs * Math.pow(2, attemptIndex), maxRetryMs),
|
|
1368
1378
|
keepAlive: {
|
|
1369
1379
|
enabled: true,
|
package/dist/index.js
CHANGED
|
@@ -683,6 +683,7 @@ var System = class {
|
|
|
683
683
|
maxRetryMs;
|
|
684
684
|
onConnectionChange;
|
|
685
685
|
token;
|
|
686
|
+
getLanguage;
|
|
686
687
|
_trpcClient;
|
|
687
688
|
_wsClient = null;
|
|
688
689
|
/**
|
|
@@ -713,6 +714,7 @@ var System = class {
|
|
|
713
714
|
constructor(config) {
|
|
714
715
|
this._serverUrl = config.serverUrl.replace(/\/+$/, "");
|
|
715
716
|
this.token = config.token;
|
|
717
|
+
this.getLanguage = config.getLanguage ?? (() => void 0);
|
|
716
718
|
const isBrowser = typeof window !== "undefined";
|
|
717
719
|
this.useWs = config.useWebSocket ?? isBrowser;
|
|
718
720
|
this.onConnectionChange = config.onConnectionChange;
|
|
@@ -1353,6 +1355,8 @@ var System = class {
|
|
|
1353
1355
|
const headers = () => {
|
|
1354
1356
|
const h = {};
|
|
1355
1357
|
if (this.token) h["Authorization"] = `Bearer ${this.token}`;
|
|
1358
|
+
const lang = this.getLanguage();
|
|
1359
|
+
if (lang) h["x-camstack-lang"] = lang;
|
|
1356
1360
|
return h;
|
|
1357
1361
|
};
|
|
1358
1362
|
if (this.useWs) {
|
|
@@ -1362,7 +1366,13 @@ var System = class {
|
|
|
1362
1366
|
const epoch = this._wsEpoch;
|
|
1363
1367
|
this._wsClient = createWSClient({
|
|
1364
1368
|
url: wsUrl,
|
|
1365
|
-
connectionParams: () =>
|
|
1369
|
+
connectionParams: () => {
|
|
1370
|
+
const lang = this.getLanguage();
|
|
1371
|
+
return {
|
|
1372
|
+
...this.token !== void 0 ? { token: this.token } : {},
|
|
1373
|
+
...lang ? { lang } : {}
|
|
1374
|
+
};
|
|
1375
|
+
},
|
|
1366
1376
|
retryDelayMs: (attemptIndex) => Math.min(baseRetryMs * Math.pow(2, attemptIndex), maxRetryMs),
|
|
1367
1377
|
keepAlive: {
|
|
1368
1378
|
enabled: true,
|
package/dist/system.d.ts
CHANGED
|
@@ -48,6 +48,14 @@ export interface SystemConfig {
|
|
|
48
48
|
readonly retryDelayMs?: number;
|
|
49
49
|
/** Max WS reconnect delay in ms (default 30_000). */
|
|
50
50
|
readonly maxRetryDelayMs?: number;
|
|
51
|
+
/**
|
|
52
|
+
* The client's current UI language (e.g. `'it'`), read on EVERY request so a
|
|
53
|
+
* language switch applies without a reconnect. Sent as the `x-camstack-lang`
|
|
54
|
+
* header (HTTP) and the `lang` connection param (WS); the hub answers settings
|
|
55
|
+
* labels and error messages in it (D863). Absent / `undefined` = the hub decides
|
|
56
|
+
* from `Accept-Language`.
|
|
57
|
+
*/
|
|
58
|
+
readonly getLanguage?: () => string | undefined;
|
|
51
59
|
}
|
|
52
60
|
type ConnectionListener = (state: BackendConnectionState, version: number) => void;
|
|
53
61
|
/** Options of every login leg. */
|
|
@@ -105,6 +113,7 @@ export declare class System {
|
|
|
105
113
|
private readonly maxRetryMs;
|
|
106
114
|
private readonly onConnectionChange;
|
|
107
115
|
private token;
|
|
116
|
+
private readonly getLanguage;
|
|
108
117
|
private _trpcClient;
|
|
109
118
|
private _wsClient;
|
|
110
119
|
/**
|