@objectstack/client 7.2.1 → 7.4.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.
package/dist/index.d.mts CHANGED
@@ -271,6 +271,17 @@ interface ClientConfig {
271
271
  * @see docs/adr/0002-project-database-isolation.md
272
272
  */
273
273
  environmentId?: string;
274
+ /**
275
+ * Active UI locale (BCP-47, e.g. `'zh-CN'`). When set, the client sends
276
+ * it as an `Accept-Language` header on every request so the server
277
+ * resolves metadata translations (object/field labels, view headers,
278
+ * action text) for the *in-app* language rather than the browser default.
279
+ *
280
+ * Apps should keep this in sync with their language switcher via
281
+ * {@link ObjectStackClient.setLocale} so switching language re-fetches
282
+ * localized metadata without a page refresh (issue #1319).
283
+ */
284
+ locale?: string;
274
285
  }
275
286
  /**
276
287
  * Discovery Result
@@ -375,6 +386,7 @@ declare class ObjectStackClient {
375
386
  private baseUrl;
376
387
  private token?;
377
388
  private environmentId?;
389
+ private locale?;
378
390
  private fetchImpl;
379
391
  private discoveryInfo?;
380
392
  private logger;
@@ -1246,6 +1258,18 @@ declare class ObjectStackClient {
1246
1258
  * Current active project id (if set).
1247
1259
  */
1248
1260
  getProjectId(): string | undefined;
1261
+ /**
1262
+ * Update the active UI locale used for subsequent requests. Apps should
1263
+ * call this from their language switcher so server-translated metadata
1264
+ * (object/field labels, view headers, action text) follows the in-app
1265
+ * language without a page refresh. Pass `undefined` to clear and fall
1266
+ * back to the browser's `Accept-Language` (issue #1319).
1267
+ */
1268
+ setLocale(locale: string | undefined): void;
1269
+ /**
1270
+ * Current active UI locale (if set).
1271
+ */
1272
+ getLocale(): string | undefined;
1249
1273
  /**
1250
1274
  * Authentication Services
1251
1275
  */
package/dist/index.d.ts CHANGED
@@ -271,6 +271,17 @@ interface ClientConfig {
271
271
  * @see docs/adr/0002-project-database-isolation.md
272
272
  */
273
273
  environmentId?: string;
274
+ /**
275
+ * Active UI locale (BCP-47, e.g. `'zh-CN'`). When set, the client sends
276
+ * it as an `Accept-Language` header on every request so the server
277
+ * resolves metadata translations (object/field labels, view headers,
278
+ * action text) for the *in-app* language rather than the browser default.
279
+ *
280
+ * Apps should keep this in sync with their language switcher via
281
+ * {@link ObjectStackClient.setLocale} so switching language re-fetches
282
+ * localized metadata without a page refresh (issue #1319).
283
+ */
284
+ locale?: string;
274
285
  }
275
286
  /**
276
287
  * Discovery Result
@@ -375,6 +386,7 @@ declare class ObjectStackClient {
375
386
  private baseUrl;
376
387
  private token?;
377
388
  private environmentId?;
389
+ private locale?;
378
390
  private fetchImpl;
379
391
  private discoveryInfo?;
380
392
  private logger;
@@ -1246,6 +1258,18 @@ declare class ObjectStackClient {
1246
1258
  * Current active project id (if set).
1247
1259
  */
1248
1260
  getProjectId(): string | undefined;
1261
+ /**
1262
+ * Update the active UI locale used for subsequent requests. Apps should
1263
+ * call this from their language switcher so server-translated metadata
1264
+ * (object/field labels, view headers, action text) follows the in-app
1265
+ * language without a page refresh. Pass `undefined` to clear and fall
1266
+ * back to the browser's `Accept-Language` (issue #1319).
1267
+ */
1268
+ setLocale(locale: string | undefined): void;
1269
+ /**
1270
+ * Current active UI locale (if set).
1271
+ */
1272
+ getLocale(): string | undefined;
1249
1273
  /**
1250
1274
  * Authentication Services
1251
1275
  */
package/dist/index.js CHANGED
@@ -2744,6 +2744,7 @@ var ObjectStackClient = class {
2744
2744
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
2745
2745
  this.token = config.token;
2746
2746
  this.environmentId = config.environmentId;
2747
+ this.locale = config.locale;
2747
2748
  this.fetchImpl = config.fetch || globalThis.fetch.bind(globalThis);
2748
2749
  this.logger = config.logger || (0, import_logger.createLogger)({
2749
2750
  level: config.debug ? "debug" : "info",
@@ -2878,6 +2879,23 @@ var ObjectStackClient = class {
2878
2879
  getProjectId() {
2879
2880
  return this.environmentId;
2880
2881
  }
2882
+ /**
2883
+ * Update the active UI locale used for subsequent requests. Apps should
2884
+ * call this from their language switcher so server-translated metadata
2885
+ * (object/field labels, view headers, action text) follows the in-app
2886
+ * language without a page refresh. Pass `undefined` to clear and fall
2887
+ * back to the browser's `Accept-Language` (issue #1319).
2888
+ */
2889
+ setLocale(locale) {
2890
+ this.locale = locale;
2891
+ this.logger.debug("Active locale changed", { locale });
2892
+ }
2893
+ /**
2894
+ * Current active UI locale (if set).
2895
+ */
2896
+ getLocale() {
2897
+ return this.locale;
2898
+ }
2881
2899
  /**
2882
2900
  * Event Subscription API
2883
2901
  * Provides real-time event subscriptions for metadata and data changes
@@ -2921,6 +2939,9 @@ var ObjectStackClient = class {
2921
2939
  if (this.environmentId) {
2922
2940
  headers["X-Environment-Id"] = this.environmentId;
2923
2941
  }
2942
+ if (this.locale && !Object.keys(headers).some((h) => h.toLowerCase() === "accept-language")) {
2943
+ headers["Accept-Language"] = this.locale;
2944
+ }
2924
2945
  const res = await this.fetchImpl(url, { ...options, headers });
2925
2946
  this.logger.debug("HTTP response", {
2926
2947
  method: options.method || "GET",