@brokerize/client 1.8.0 → 1.9.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/README.md CHANGED
@@ -20,6 +20,9 @@ async function someBrokerizeActions() {
20
20
  createWebSocket: (url, protocol) => new WebSocket(url, protocol),
21
21
  // basePath: 'https://api-preview.brokerize.com', // this is the default value
22
22
  // basePathCryptoService: 'https://crypto-service-api.com' // the optional external crypto service
23
+ // acceptLanguage: 'de', // optional `Accept-Language` header for localized responses (e.g. legal terms).
24
+ // // may also be a function `() => 'de'` that is evaluated on every request,
25
+ // // so runtime language changes are picked up without recreating the client.
23
26
  })
24
27
 
25
28
  /* create a guest user. the result contains the user's tokens and be stored, e.g. in a cookie or session storage */
package/dist/apiCtx.d.ts CHANGED
@@ -19,7 +19,29 @@ export interface BrokerizeConfig {
19
19
  * The AWS cognito configuration, if the application is supposed to be used with brokerize accounts.
20
20
  */
21
21
  cognito?: CognitoConfig;
22
+ /**
23
+ * Optional value for the `Accept-Language` header sent with API requests. Use this to request
24
+ * localized backend responses (e.g. legal terms) in the language selected in your application,
25
+ * overriding the language the browser would send by default.
26
+ *
27
+ * Accepts a static value (e.g. `"de"`, `"en"`, `"de-DE"`) or a function that returns the current
28
+ * language. The function is evaluated on every request, so runtime language changes are picked up
29
+ * without recreating the client. Return `undefined`/`null` (or provide no value) to omit the
30
+ * header and let the runtime/browser default apply.
31
+ */
32
+ acceptLanguage?: string | (() => string | null | undefined | Promise<string | null | undefined>);
22
33
  }
34
+ /**
35
+ * Resolves the configured `Accept-Language` value (static or via a getter function) to a string,
36
+ * or `undefined` if none is configured / the getter yields an empty value.
37
+ */
38
+ export declare function resolveAcceptLanguage(cfg: BrokerizeConfig): Promise<string | undefined>;
39
+ /**
40
+ * Adds the configured `Accept-Language` header to the given headers object (mutating and returning
41
+ * it) if a language is configured. No-op otherwise. Used to apply the configured language uniformly
42
+ * to authorized and unauthenticated requests.
43
+ */
44
+ export declare function withAcceptLanguage(cfg: BrokerizeConfig, headers: Record<string, string>): Promise<Record<string, string>>;
23
45
  export type AuthContextConfiguration = GuestAuthContextConfiguration | RegisteredUserAuthContextConfiguration;
24
46
  export type RegisteredUserAuthContextConfiguration = {
25
47
  type: "registered";
package/dist/apiCtx.js CHANGED
@@ -2,6 +2,29 @@
2
2
  but reduced to the parts actually used by bg-trading. */
3
3
  import { BrokerizeError } from "./index.js";
4
4
  import { Configuration } from "./swagger/index.js";
5
+ /**
6
+ * Resolves the configured `Accept-Language` value (static or via a getter function) to a string,
7
+ * or `undefined` if none is configured / the getter yields an empty value.
8
+ */
9
+ export async function resolveAcceptLanguage(cfg) {
10
+ const { acceptLanguage } = cfg;
11
+ const value = typeof acceptLanguage === "function"
12
+ ? await acceptLanguage()
13
+ : acceptLanguage;
14
+ return value || undefined;
15
+ }
16
+ /**
17
+ * Adds the configured `Accept-Language` header to the given headers object (mutating and returning
18
+ * it) if a language is configured. No-op otherwise. Used to apply the configured language uniformly
19
+ * to authorized and unauthenticated requests.
20
+ */
21
+ export async function withAcceptLanguage(cfg, headers) {
22
+ const acceptLanguage = await resolveAcceptLanguage(cfg);
23
+ if (acceptLanguage) {
24
+ headers["Accept-Language"] = acceptLanguage;
25
+ }
26
+ return headers;
27
+ }
5
28
  export function createConfiguration(cfg) {
6
29
  if (!cfg.clientId) {
7
30
  throw new Error("You must configure a clientId to use the brokerize API.");
@@ -33,10 +56,10 @@ export function createAuth({ authCfg, cfg, options, tokenRefreshCallback, }) {
33
56
  }
34
57
  const response = await fetch(cfg.basePath + "/user/token", {
35
58
  method: "POST",
36
- headers: {
59
+ headers: await withAcceptLanguage(cfg, {
37
60
  "x-brkrz-client-id": cfg.clientId,
38
61
  "Content-Type": "application/x-www-form-urlencoded",
39
- },
62
+ }),
40
63
  // XXX some runtimes do not have URLSearchParams, so just produce the body in the old-fashioned way
41
64
  body: `grant_type=refresh_token&refresh_token=${encodeURIComponent(guestAuthCfg.tokens.response.refreshToken)}`,
42
65
  });
@@ -1,5 +1,5 @@
1
1
  import { Subject } from "rxjs";
2
- import { createConfiguration } from "./apiCtx.js";
2
+ import { createConfiguration, withAcceptLanguage, } from "./apiCtx.js";
3
3
  import { BrokerizeError } from "./errors.js";
4
4
  import { createPollingSubscription } from "./pollingSubscription.js";
5
5
  import * as openApiClient from "./swagger/index.js";
@@ -74,13 +74,14 @@ export class AuthorizedApiContext {
74
74
  throw new Error("AuthorizedApiContext is destroyed");
75
75
  }
76
76
  const tok = await this._auth.getToken();
77
+ const headers = await withAcceptLanguage(this._cfg, {
78
+ "x-brkrz-client-id": this._cfg.clientId,
79
+ Authorization: "Bearer " + tok.idToken,
80
+ "Content-Type": "application/json",
81
+ });
77
82
  return {
78
83
  signal: this._abortController.signal,
79
- headers: {
80
- "x-brkrz-client-id": this._cfg.clientId,
81
- Authorization: "Bearer " + tok.idToken,
82
- "Content-Type": "application/json",
83
- },
84
+ headers,
84
85
  };
85
86
  }
86
87
  async getBrokers() {
@@ -19,7 +19,29 @@ export interface BrokerizeConfig {
19
19
  * The AWS cognito configuration, if the application is supposed to be used with brokerize accounts.
20
20
  */
21
21
  cognito?: CognitoConfig;
22
+ /**
23
+ * Optional value for the `Accept-Language` header sent with API requests. Use this to request
24
+ * localized backend responses (e.g. legal terms) in the language selected in your application,
25
+ * overriding the language the browser would send by default.
26
+ *
27
+ * Accepts a static value (e.g. `"de"`, `"en"`, `"de-DE"`) or a function that returns the current
28
+ * language. The function is evaluated on every request, so runtime language changes are picked up
29
+ * without recreating the client. Return `undefined`/`null` (or provide no value) to omit the
30
+ * header and let the runtime/browser default apply.
31
+ */
32
+ acceptLanguage?: string | (() => string | null | undefined | Promise<string | null | undefined>);
22
33
  }
34
+ /**
35
+ * Resolves the configured `Accept-Language` value (static or via a getter function) to a string,
36
+ * or `undefined` if none is configured / the getter yields an empty value.
37
+ */
38
+ export declare function resolveAcceptLanguage(cfg: BrokerizeConfig): Promise<string | undefined>;
39
+ /**
40
+ * Adds the configured `Accept-Language` header to the given headers object (mutating and returning
41
+ * it) if a language is configured. No-op otherwise. Used to apply the configured language uniformly
42
+ * to authorized and unauthenticated requests.
43
+ */
44
+ export declare function withAcceptLanguage(cfg: BrokerizeConfig, headers: Record<string, string>): Promise<Record<string, string>>;
23
45
  export type AuthContextConfiguration = GuestAuthContextConfiguration | RegisteredUserAuthContextConfiguration;
24
46
  export type RegisteredUserAuthContextConfiguration = {
25
47
  type: "registered";
@@ -1,11 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveAcceptLanguage = resolveAcceptLanguage;
4
+ exports.withAcceptLanguage = withAcceptLanguage;
3
5
  exports.createConfiguration = createConfiguration;
4
6
  exports.createAuth = createAuth;
5
7
  /* Import/Export the DOM parts we rely on. Those are partial copies from the official TypeScript DOM library definitions (https://github.com/microsoft/TypeScript/blob/master/lib/lib.dom.d.ts),
6
8
  but reduced to the parts actually used by bg-trading. */
7
9
  const _1 = require(".");
8
10
  const swagger_1 = require("./swagger");
11
+ /**
12
+ * Resolves the configured `Accept-Language` value (static or via a getter function) to a string,
13
+ * or `undefined` if none is configured / the getter yields an empty value.
14
+ */
15
+ async function resolveAcceptLanguage(cfg) {
16
+ const { acceptLanguage } = cfg;
17
+ const value = typeof acceptLanguage === "function"
18
+ ? await acceptLanguage()
19
+ : acceptLanguage;
20
+ return value || undefined;
21
+ }
22
+ /**
23
+ * Adds the configured `Accept-Language` header to the given headers object (mutating and returning
24
+ * it) if a language is configured. No-op otherwise. Used to apply the configured language uniformly
25
+ * to authorized and unauthenticated requests.
26
+ */
27
+ async function withAcceptLanguage(cfg, headers) {
28
+ const acceptLanguage = await resolveAcceptLanguage(cfg);
29
+ if (acceptLanguage) {
30
+ headers["Accept-Language"] = acceptLanguage;
31
+ }
32
+ return headers;
33
+ }
9
34
  function createConfiguration(cfg) {
10
35
  if (!cfg.clientId) {
11
36
  throw new Error("You must configure a clientId to use the brokerize API.");
@@ -37,10 +62,10 @@ function createAuth({ authCfg, cfg, options, tokenRefreshCallback, }) {
37
62
  }
38
63
  const response = await fetch(cfg.basePath + "/user/token", {
39
64
  method: "POST",
40
- headers: {
65
+ headers: await withAcceptLanguage(cfg, {
41
66
  "x-brkrz-client-id": cfg.clientId,
42
67
  "Content-Type": "application/x-www-form-urlencoded",
43
- },
68
+ }),
44
69
  // XXX some runtimes do not have URLSearchParams, so just produce the body in the old-fashioned way
45
70
  body: `grant_type=refresh_token&refresh_token=${encodeURIComponent(guestAuthCfg.tokens.response.refreshToken)}`,
46
71
  });
@@ -111,13 +111,14 @@ class AuthorizedApiContext {
111
111
  throw new Error("AuthorizedApiContext is destroyed");
112
112
  }
113
113
  const tok = await this._auth.getToken();
114
+ const headers = await (0, apiCtx_1.withAcceptLanguage)(this._cfg, {
115
+ "x-brkrz-client-id": this._cfg.clientId,
116
+ Authorization: "Bearer " + tok.idToken,
117
+ "Content-Type": "application/json",
118
+ });
114
119
  return {
115
120
  signal: this._abortController.signal,
116
- headers: {
117
- "x-brkrz-client-id": this._cfg.clientId,
118
- Authorization: "Bearer " + tok.idToken,
119
- "Content-Type": "application/json",
120
- },
121
+ headers,
121
122
  };
122
123
  }
123
124
  async getBrokers() {
package/dist/cjs/index.js CHANGED
@@ -88,10 +88,10 @@ class Brokerize {
88
88
  async refreshGuestUser(refreshToken) {
89
89
  const response = await fetch(this._cfg.basePath + "/user/token", {
90
90
  method: "POST",
91
- headers: {
91
+ headers: await (0, apiCtx_1.withAcceptLanguage)(this._cfg, {
92
92
  "x-brkrz-client-id": this._cfg.clientId,
93
93
  "Content-Type": "application/x-www-form-urlencoded",
94
- },
94
+ }),
95
95
  // XXX some runtimes do not have URLSearchParams, so just produce the body in the old-fashioned way
96
96
  body: `grant_type=refresh_token&refresh_token=${encodeURIComponent(refreshToken)}`,
97
97
  });
@@ -123,10 +123,10 @@ class Brokerize {
123
123
  async createGuestUser() {
124
124
  const updatedAt = Date.now();
125
125
  const user = await this._userApi.createGuestUser({
126
- headers: {
126
+ headers: await (0, apiCtx_1.withAcceptLanguage)(this._cfg, {
127
127
  "x-brkrz-client-id": this._cfg.clientId,
128
128
  "Content-Type": "application/json",
129
- },
129
+ }),
130
130
  });
131
131
  return {
132
132
  type: "guest",
@@ -173,24 +173,24 @@ class Brokerize {
173
173
  },
174
174
  });
175
175
  }
176
- checkRecoveryPhrase(recoveryPhrase) {
176
+ async checkRecoveryPhrase(recoveryPhrase) {
177
177
  return this._userApi.checkRecoveryPhrase({
178
178
  obtainTokenByRecoveryPhraseParams: { recoveryPhrase },
179
179
  }, {
180
- headers: {
180
+ headers: await (0, apiCtx_1.withAcceptLanguage)(this._cfg, {
181
181
  "x-brkrz-client-id": this._cfg.clientId,
182
182
  "Content-Type": "application/json",
183
- },
183
+ }),
184
184
  });
185
185
  }
186
186
  async obtainTokenByRecoveryPhrase(recoveryPhrase) {
187
187
  const tokResult = await this._userApi.obtainTokenByRecoveryPhrase({
188
188
  obtainTokenByRecoveryPhraseParams: { recoveryPhrase },
189
189
  }, {
190
- headers: {
190
+ headers: await (0, apiCtx_1.withAcceptLanguage)(this._cfg, {
191
191
  "x-brkrz-client-id": this._cfg.clientId,
192
192
  "Content-Type": "application/json",
193
- },
193
+ }),
194
194
  });
195
195
  const updatedAt = Date.now();
196
196
  return {
package/dist/client.d.ts CHANGED
@@ -1508,6 +1508,17 @@ export declare interface BrokerizeConfig {
1508
1508
  * The AWS cognito configuration, if the application is supposed to be used with brokerize accounts.
1509
1509
  */
1510
1510
  cognito?: CognitoConfig;
1511
+ /**
1512
+ * Optional value for the `Accept-Language` header sent with API requests. Use this to request
1513
+ * localized backend responses (e.g. legal terms) in the language selected in your application,
1514
+ * overriding the language the browser would send by default.
1515
+ *
1516
+ * Accepts a static value (e.g. `"de"`, `"en"`, `"de-DE"`) or a function that returns the current
1517
+ * language. The function is evaluated on every request, so runtime language changes are picked up
1518
+ * without recreating the client. Return `undefined`/`null` (or provide no value) to omit the
1519
+ * header and let the runtime/browser default apply.
1520
+ */
1521
+ acceptLanguage?: string | (() => string | null | undefined | Promise<string | null | undefined>);
1511
1522
  }
1512
1523
 
1513
1524
  export declare class BrokerizeError extends Error {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /* Import/Export the DOM parts we rely on. Those are partial copies from the official TypeScript DOM library definitions (https://github.com/microsoft/TypeScript/blob/master/lib/lib.dom.d.ts),
2
2
  but reduced to the parts actually used by bg-trading. */
3
- import { createAuth, createConfiguration, } from "./apiCtx.js";
3
+ import { createAuth, createConfiguration, withAcceptLanguage, } from "./apiCtx.js";
4
4
  import { AuthorizedApiContext, getWebSocketURLByBasePath, } from "./authorizedApiContext.js";
5
5
  import { BrokerizeError } from "./errors.js";
6
6
  import * as openApiClient from "./swagger/index.js";
@@ -48,10 +48,10 @@ export class Brokerize {
48
48
  async refreshGuestUser(refreshToken) {
49
49
  const response = await fetch(this._cfg.basePath + "/user/token", {
50
50
  method: "POST",
51
- headers: {
51
+ headers: await withAcceptLanguage(this._cfg, {
52
52
  "x-brkrz-client-id": this._cfg.clientId,
53
53
  "Content-Type": "application/x-www-form-urlencoded",
54
- },
54
+ }),
55
55
  // XXX some runtimes do not have URLSearchParams, so just produce the body in the old-fashioned way
56
56
  body: `grant_type=refresh_token&refresh_token=${encodeURIComponent(refreshToken)}`,
57
57
  });
@@ -83,10 +83,10 @@ export class Brokerize {
83
83
  async createGuestUser() {
84
84
  const updatedAt = Date.now();
85
85
  const user = await this._userApi.createGuestUser({
86
- headers: {
86
+ headers: await withAcceptLanguage(this._cfg, {
87
87
  "x-brkrz-client-id": this._cfg.clientId,
88
88
  "Content-Type": "application/json",
89
- },
89
+ }),
90
90
  });
91
91
  return {
92
92
  type: "guest",
@@ -133,24 +133,24 @@ export class Brokerize {
133
133
  },
134
134
  });
135
135
  }
136
- checkRecoveryPhrase(recoveryPhrase) {
136
+ async checkRecoveryPhrase(recoveryPhrase) {
137
137
  return this._userApi.checkRecoveryPhrase({
138
138
  obtainTokenByRecoveryPhraseParams: { recoveryPhrase },
139
139
  }, {
140
- headers: {
140
+ headers: await withAcceptLanguage(this._cfg, {
141
141
  "x-brkrz-client-id": this._cfg.clientId,
142
142
  "Content-Type": "application/json",
143
- },
143
+ }),
144
144
  });
145
145
  }
146
146
  async obtainTokenByRecoveryPhrase(recoveryPhrase) {
147
147
  const tokResult = await this._userApi.obtainTokenByRecoveryPhrase({
148
148
  obtainTokenByRecoveryPhraseParams: { recoveryPhrase },
149
149
  }, {
150
- headers: {
150
+ headers: await withAcceptLanguage(this._cfg, {
151
151
  "x-brkrz-client-id": this._cfg.clientId,
152
152
  "Content-Type": "application/json",
153
- },
153
+ }),
154
154
  });
155
155
  const updatedAt = Date.now();
156
156
  return {
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.58.8"
8
+ "packageVersion": "7.58.11"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brokerize/client",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Client for the brokerize.com API",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/brokerize/client-js#readme",
@@ -61,15 +61,15 @@
61
61
  "package.json": "sort-package-json"
62
62
  },
63
63
  "devDependencies": {
64
- "@microsoft/api-extractor": "7.58.8",
65
- "@openapitools/openapi-generator-cli": "2.38.0",
66
- "@types/node": "24.12.3",
67
- "@typescript-eslint/eslint-plugin": "8.61.0",
68
- "eslint": "10.4.1",
64
+ "@microsoft/api-extractor": "7.58.11",
65
+ "@openapitools/openapi-generator-cli": "2.39.1",
66
+ "@types/node": "24.13.3",
67
+ "@typescript-eslint/eslint-plugin": "8.64.0",
68
+ "eslint": "10.7.0",
69
69
  "eslint-config-prettier": "10.1.8",
70
70
  "husky": "9.1.7",
71
- "lint-staged": "17.0.7",
72
- "prettier": "3.8.4",
71
+ "lint-staged": "17.0.8",
72
+ "prettier": "3.9.5",
73
73
  "sort-package-json": "4.0.0",
74
74
  "typescript": "6.0.3"
75
75
  },