@meshtrade/api-web 1.30.2 → 1.31.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.
Files changed (43) hide show
  1. package/dist/meshtrade/compliance/client/v1/client_pb.d.ts +17 -9
  2. package/dist/meshtrade/compliance/client/v1/client_pb.js +1 -1
  3. package/dist/meshtrade/compliance/client/v1/service_web_meshts.d.ts +62 -7
  4. package/dist/meshtrade/compliance/client/v1/service_web_meshts.js +118 -28
  5. package/dist/meshtrade/config/index.d.ts +160 -0
  6. package/dist/meshtrade/config/index.js +210 -0
  7. package/dist/meshtrade/iam/api_user/v1/api_user_pb.d.ts +12 -4
  8. package/dist/meshtrade/iam/api_user/v1/api_user_pb.js +1 -1
  9. package/dist/meshtrade/iam/api_user/v1/service_web_meshts.d.ts +62 -7
  10. package/dist/meshtrade/iam/api_user/v1/service_web_meshts.js +167 -35
  11. package/dist/meshtrade/iam/group/v1/group_pb.d.ts +8 -0
  12. package/dist/meshtrade/iam/group/v1/group_pb.js +1 -1
  13. package/dist/meshtrade/iam/group/v1/service_web_meshts.d.ts +62 -7
  14. package/dist/meshtrade/iam/group/v1/service_web_meshts.js +134 -30
  15. package/dist/meshtrade/iam/user/v1/service_web_meshts.d.ts +62 -7
  16. package/dist/meshtrade/iam/user/v1/service_web_meshts.js +159 -34
  17. package/dist/meshtrade/iam/user/v1/user_pb.d.ts +10 -2
  18. package/dist/meshtrade/iam/user/v1/user_pb.js +1 -1
  19. package/dist/meshtrade/{common/connectInterceptors.d.ts → interceptors/index.d.ts} +23 -17
  20. package/dist/meshtrade/{common/connectInterceptors.js → interceptors/index.js} +61 -24
  21. package/dist/meshtrade/ledger/transaction/v1/service_web_meshts.d.ts +62 -7
  22. package/dist/meshtrade/ledger/transaction/v1/service_web_meshts.js +110 -27
  23. package/dist/meshtrade/market_data/price/v1/service_web_meshts.d.ts +62 -7
  24. package/dist/meshtrade/market_data/price/v1/service_web_meshts.js +102 -26
  25. package/dist/meshtrade/reporting/account_report/v1/service_web_meshts.d.ts +62 -7
  26. package/dist/meshtrade/reporting/account_report/v1/service_web_meshts.js +110 -27
  27. package/dist/meshtrade/studio/instrument/v1/instrument_pb.d.ts +8 -0
  28. package/dist/meshtrade/studio/instrument/v1/instrument_pb.js +1 -1
  29. package/dist/meshtrade/trading/limit_order/v1/limit_order_pb.d.ts +16 -8
  30. package/dist/meshtrade/trading/limit_order/v1/limit_order_pb.js +1 -1
  31. package/dist/meshtrade/trading/limit_order/v1/service_web_meshts.d.ts +62 -7
  32. package/dist/meshtrade/trading/limit_order/v1/service_web_meshts.js +151 -33
  33. package/dist/meshtrade/trading/market_order/v1/service_web_meshts.d.ts +62 -7
  34. package/dist/meshtrade/trading/market_order/v1/service_web_meshts.js +102 -26
  35. package/dist/meshtrade/wallet/account/v1/account_pb.d.ts +8 -0
  36. package/dist/meshtrade/wallet/account/v1/account_pb.js +1 -1
  37. package/dist/meshtrade/wallet/account/v1/service_web_meshts.d.ts +62 -7
  38. package/dist/meshtrade/wallet/account/v1/service_web_meshts.js +167 -35
  39. package/package.json +19 -2
  40. package/dist/meshtrade/common/config.d.ts +0 -7
  41. package/dist/meshtrade/common/config.js +0 -9
  42. package/dist/meshtrade/common/validation.d.ts +0 -62
  43. package/dist/meshtrade/common/validation.js +0 -77
@@ -7,28 +7,87 @@ exports.LimitOrderServiceWeb = void 0;
7
7
  const connect_1 = require("@connectrpc/connect");
8
8
  const connect_web_1 = require("@connectrpc/connect-web");
9
9
  const service_pb_1 = require("./service_pb");
10
- const config_1 = require("../../../common/config");
11
- const validation_1 = require("../../../common/validation");
12
- const connectInterceptors_1 = require("../../../common/connectInterceptors");
10
+ const service_pb_2 = require("./service_pb");
11
+ const config_1 = require("../../../config");
12
+ const protovalidate_1 = require("@bufbuild/protovalidate");
13
+ const interceptors_1 = require("../../../interceptors");
13
14
  /**
14
15
  * Web client for interacting with the meshtrade.trading.limit_order.v1 limit order v1 API resource service.
15
- * Uses Connect-ES with gRPC-Web transport for browser-compatible gRPC communication.
16
+ * Uses Connect-ES with gRPC-Web transport for browser-based communication.
17
+ *
18
+ * Supports flexible authentication modes using functional options pattern:
19
+ *
20
+ * 1. **No Authentication** (public APIs):
21
+ * ```typescript
22
+ * const client = new LimitOrderServiceWeb(
23
+ * WithServerUrl("http://localhost:10000")
24
+ * );
25
+ * ```
26
+ *
27
+ * 2. **API Key Authentication** (backend services):
28
+ * ```typescript
29
+ * const client = new LimitOrderServiceWeb(
30
+ * WithAPIKey("your-api-key"),
31
+ * WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
32
+ * WithServerUrl("https://api.example.com")
33
+ * );
34
+ * ```
35
+ *
36
+ * 3. **JWT Token Authentication** (Next.js frontend with user session):
37
+ * ```typescript
38
+ * const client = new LimitOrderServiceWeb(
39
+ * WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
40
+ * WithServerUrl("https://api.example.com")
41
+ * );
42
+ * ```
43
+ *
44
+ * 4. **JWT with Group Context** (user session with specific group):
45
+ * ```typescript
46
+ * const client = new LimitOrderServiceWeb(
47
+ * WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
48
+ * WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
49
+ * WithServerUrl("https://api.example.com")
50
+ * );
51
+ * ```
52
+ *
53
+ * Available options:
54
+ * - `WithAPIKey(key)` - API key authentication (mutually exclusive with JWT)
55
+ * - `WithJWTAccessToken(token)` - JWT authentication (mutually exclusive with API key)
56
+ * - `WithGroup(group)` - Group context (optional, works with both auth modes)
57
+ * - `WithServerUrl(url)` - Custom server URL (optional, defaults to production)
16
58
  */
17
59
  class LimitOrderServiceWeb {
18
60
  /**
19
61
  * Constructs an instance of LimitOrderServiceWeb.
20
- * @param {ConfigOpts} [config] - Optional configuration for the client.
21
- * @param {Interceptor[]} [interceptors] - For internal use by `withGroup`.
62
+ *
63
+ * Uses functional options pattern for flexible configuration:
64
+ * - `WithAPIKey(key)` - API key authentication
65
+ * - `WithJWTAccessToken(token)` - JWT authentication
66
+ * - `WithGroup(group)` - Group context (optional)
67
+ * - `WithServerUrl(url)` - Custom server URL (optional)
68
+ *
69
+ * @param {...ClientOption} opts - Variable number of configuration options
22
70
  */
23
- constructor(config, interceptors) {
24
- this._config = (0, config_1.getConfigFromOpts)(config);
25
- this._interceptors = interceptors || [];
26
- // Create the gRPC-Web transport with interceptors
71
+ constructor(...opts) {
72
+ // Build configuration from options
73
+ this._config = (0, config_1.buildConfigFromOptions)(...opts);
74
+ // Initialize validator for request validation
75
+ this._validator = (0, protovalidate_1.createValidator)();
76
+ this._interceptors = [];
77
+ this._interceptors.push((0, interceptors_1.createLoggingInterceptor)());
78
+ if (this._config.apiKey) {
79
+ this._interceptors.push((0, interceptors_1.createApiKeyInterceptor)(this._config.apiKey));
80
+ }
81
+ if (this._config.jwtToken) {
82
+ this._interceptors.push((0, interceptors_1.createJwtInterceptor)(this._config.jwtToken));
83
+ }
84
+ if (this._config.group) {
85
+ this._interceptors.push((0, interceptors_1.createGroupInterceptor)(this._config.group));
86
+ }
87
+ // Create the gRPC-Web transport for browser with interceptors
27
88
  const transport = (0, connect_web_1.createGrpcWebTransport)({
28
89
  baseUrl: this._config.apiServerURL,
29
90
  interceptors: this._interceptors,
30
- // Enable credentials (cookies) for cross-origin requests
31
- fetch: (input, init) => globalThis.fetch(input, { ...init, credentials: 'include' }),
32
91
  });
33
92
  // Construct the Connect-ES client
34
93
  this._client = (0, connect_1.createClient)(service_pb_1.LimitOrderService, transport);
@@ -37,26 +96,36 @@ class LimitOrderServiceWeb {
37
96
  * Returns a new client instance configured to send the specified group
38
97
  * resource name in the request headers for subsequent API calls.
39
98
  *
99
+ * This method creates a new client with the same authentication configuration
100
+ * but with the group context updated to the specified value.
101
+ *
102
+ * **Compatibility**: Works with all authentication modes:
103
+ * - **API key auth**: Creates new client with API key + new group
104
+ * - **JWT auth**: Creates new client with JWT + new group
105
+ * - **No auth**: Creates new client with standalone group interceptor
106
+ *
40
107
  * @param {string} group - The operating group context to inject into the request
41
108
  * in the format `groups/{ulid}` where {ulid} is a 26-character ULID.
42
109
  * Example: 'groups/01ARZ3NDEKTSV4YWVF8F5BH32'
43
110
  * @returns {LimitOrderServiceWeb} A new, configured instance of the client.
44
- * @throws {Error} If the group format is invalid (validation occurs in createGroupInterceptor)
111
+ * @throws {Error} If the group format is invalid
45
112
  */
46
113
  withGroup(group) {
47
- // Check if a group interceptor already exists.
48
- // Group interceptors are identified by having a 'groupContext' property
49
- const hasGroupInterceptor = this._interceptors.some((interceptor) => interceptor.groupContext !== undefined);
50
- if (hasGroupInterceptor) {
51
- throw new Error("Attempted to set group context twice. A group has already been set for this client instance.");
52
- }
53
- // Create a new interceptor for the group context
54
- const groupInterceptor = (0, connectInterceptors_1.createGroupInterceptor)(group);
55
- // Return a new client instance with the existing interceptors plus the new one
56
- return new LimitOrderServiceWeb(this._config, [
57
- ...this._interceptors,
58
- groupInterceptor,
59
- ]);
114
+ // Build new options array with existing auth and updated group
115
+ const newOpts = [];
116
+ // Add server URL
117
+ newOpts.push((0, config_1.WithServerUrl)(this._config.apiServerURL));
118
+ // Add authentication (preserve existing mode)
119
+ if (this._config.apiKey) {
120
+ newOpts.push((0, config_1.WithAPIKey)(this._config.apiKey));
121
+ }
122
+ else if (this._config.jwtToken) {
123
+ newOpts.push((0, config_1.WithJWTAccessToken)(this._config.jwtToken));
124
+ }
125
+ // Add the new group
126
+ newOpts.push((0, config_1.WithGroup)(group));
127
+ // Return a new client instance with updated configuration
128
+ return new LimitOrderServiceWeb(...newOpts);
60
129
  }
61
130
  /**
62
131
  * Creates a new limit order.
@@ -65,7 +134,14 @@ class LimitOrderServiceWeb {
65
134
  */
66
135
  createLimitOrder(request) {
67
136
  // Validate request
68
- (0, validation_1.validateRequest)(request);
137
+ const result = this._validator.validate(service_pb_2.CreateLimitOrderRequestSchema, request);
138
+ if (result.kind === "invalid") {
139
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
140
+ throw new Error(`Validation failed: ${violations}`);
141
+ }
142
+ else if (result.kind === "error") {
143
+ throw result.error;
144
+ }
69
145
  return this._client.createLimitOrder(request);
70
146
  }
71
147
  /**
@@ -75,7 +151,14 @@ class LimitOrderServiceWeb {
75
151
  */
76
152
  cancelLimitOrder(request) {
77
153
  // Validate request
78
- (0, validation_1.validateRequest)(request);
154
+ const result = this._validator.validate(service_pb_2.CancelLimitOrderRequestSchema, request);
155
+ if (result.kind === "invalid") {
156
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
157
+ throw new Error(`Validation failed: ${violations}`);
158
+ }
159
+ else if (result.kind === "error") {
160
+ throw result.error;
161
+ }
79
162
  return this._client.cancelLimitOrder(request);
80
163
  }
81
164
  /**
@@ -85,7 +168,14 @@ class LimitOrderServiceWeb {
85
168
  */
86
169
  getLimitOrder(request) {
87
170
  // Validate request
88
- (0, validation_1.validateRequest)(request);
171
+ const result = this._validator.validate(service_pb_2.GetLimitOrderRequestSchema, request);
172
+ if (result.kind === "invalid") {
173
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
174
+ throw new Error(`Validation failed: ${violations}`);
175
+ }
176
+ else if (result.kind === "error") {
177
+ throw result.error;
178
+ }
89
179
  return this._client.getLimitOrder(request);
90
180
  }
91
181
  /**
@@ -95,7 +185,14 @@ class LimitOrderServiceWeb {
95
185
  */
96
186
  getLimitOrderByExternalReference(request) {
97
187
  // Validate request
98
- (0, validation_1.validateRequest)(request);
188
+ const result = this._validator.validate(service_pb_2.GetLimitOrderByExternalReferenceRequestSchema, request);
189
+ if (result.kind === "invalid") {
190
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
191
+ throw new Error(`Validation failed: ${violations}`);
192
+ }
193
+ else if (result.kind === "error") {
194
+ throw result.error;
195
+ }
99
196
  return this._client.getLimitOrderByExternalReference(request);
100
197
  }
101
198
  /**
@@ -105,7 +202,14 @@ class LimitOrderServiceWeb {
105
202
  */
106
203
  listLimitOrders(request) {
107
204
  // Validate request
108
- (0, validation_1.validateRequest)(request);
205
+ const result = this._validator.validate(service_pb_2.ListLimitOrdersRequestSchema, request);
206
+ if (result.kind === "invalid") {
207
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
208
+ throw new Error(`Validation failed: ${violations}`);
209
+ }
210
+ else if (result.kind === "error") {
211
+ throw result.error;
212
+ }
109
213
  return this._client.listLimitOrders(request);
110
214
  }
111
215
  /**
@@ -115,7 +219,14 @@ class LimitOrderServiceWeb {
115
219
  */
116
220
  searchLimitOrders(request) {
117
221
  // Validate request
118
- (0, validation_1.validateRequest)(request);
222
+ const result = this._validator.validate(service_pb_2.SearchLimitOrdersRequestSchema, request);
223
+ if (result.kind === "invalid") {
224
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
225
+ throw new Error(`Validation failed: ${violations}`);
226
+ }
227
+ else if (result.kind === "error") {
228
+ throw result.error;
229
+ }
119
230
  return this._client.searchLimitOrders(request);
120
231
  }
121
232
  /**
@@ -134,7 +245,14 @@ class LimitOrderServiceWeb {
134
245
  */
135
246
  monitorLimitOrder(request) {
136
247
  // Validate request before initiating stream
137
- (0, validation_1.validateRequest)(request);
248
+ const result = this._validator.validate(service_pb_2.MonitorLimitOrderRequestSchema, request);
249
+ if (result.kind === "invalid") {
250
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
251
+ throw new Error(`Validation failed: ${violations}`);
252
+ }
253
+ else if (result.kind === "error") {
254
+ throw result.error;
255
+ }
138
256
  return this._client.monitorLimitOrder(request);
139
257
  }
140
258
  }
@@ -1,30 +1,85 @@
1
- import { Interceptor } from "@connectrpc/connect";
2
1
  import { GetMarketOrderRequest } from "./service_pb";
3
2
  import { MarketOrder } from "./market_order_pb";
4
- import { ConfigOpts } from "../../../common/config";
3
+ import { ClientOption } from "../../../config";
5
4
  /**
6
5
  * Web client for interacting with the meshtrade.trading.market_order.v1 market order v1 API resource service.
7
- * Uses Connect-ES with gRPC-Web transport for browser-compatible gRPC communication.
6
+ * Uses Connect-ES with gRPC-Web transport for browser-based communication.
7
+ *
8
+ * Supports flexible authentication modes using functional options pattern:
9
+ *
10
+ * 1. **No Authentication** (public APIs):
11
+ * ```typescript
12
+ * const client = new MarketOrderServiceWeb(
13
+ * WithServerUrl("http://localhost:10000")
14
+ * );
15
+ * ```
16
+ *
17
+ * 2. **API Key Authentication** (backend services):
18
+ * ```typescript
19
+ * const client = new MarketOrderServiceWeb(
20
+ * WithAPIKey("your-api-key"),
21
+ * WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
22
+ * WithServerUrl("https://api.example.com")
23
+ * );
24
+ * ```
25
+ *
26
+ * 3. **JWT Token Authentication** (Next.js frontend with user session):
27
+ * ```typescript
28
+ * const client = new MarketOrderServiceWeb(
29
+ * WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
30
+ * WithServerUrl("https://api.example.com")
31
+ * );
32
+ * ```
33
+ *
34
+ * 4. **JWT with Group Context** (user session with specific group):
35
+ * ```typescript
36
+ * const client = new MarketOrderServiceWeb(
37
+ * WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
38
+ * WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
39
+ * WithServerUrl("https://api.example.com")
40
+ * );
41
+ * ```
42
+ *
43
+ * Available options:
44
+ * - `WithAPIKey(key)` - API key authentication (mutually exclusive with JWT)
45
+ * - `WithJWTAccessToken(token)` - JWT authentication (mutually exclusive with API key)
46
+ * - `WithGroup(group)` - Group context (optional, works with both auth modes)
47
+ * - `WithServerUrl(url)` - Custom server URL (optional, defaults to production)
8
48
  */
9
49
  export declare class MarketOrderServiceWeb {
10
50
  private _client;
11
51
  private readonly _config;
12
52
  private readonly _interceptors;
53
+ private readonly _validator;
13
54
  /**
14
55
  * Constructs an instance of MarketOrderServiceWeb.
15
- * @param {ConfigOpts} [config] - Optional configuration for the client.
16
- * @param {Interceptor[]} [interceptors] - For internal use by `withGroup`.
56
+ *
57
+ * Uses functional options pattern for flexible configuration:
58
+ * - `WithAPIKey(key)` - API key authentication
59
+ * - `WithJWTAccessToken(token)` - JWT authentication
60
+ * - `WithGroup(group)` - Group context (optional)
61
+ * - `WithServerUrl(url)` - Custom server URL (optional)
62
+ *
63
+ * @param {...ClientOption} opts - Variable number of configuration options
17
64
  */
18
- constructor(config?: ConfigOpts, interceptors?: Interceptor[]);
65
+ constructor(...opts: ClientOption[]);
19
66
  /**
20
67
  * Returns a new client instance configured to send the specified group
21
68
  * resource name in the request headers for subsequent API calls.
22
69
  *
70
+ * This method creates a new client with the same authentication configuration
71
+ * but with the group context updated to the specified value.
72
+ *
73
+ * **Compatibility**: Works with all authentication modes:
74
+ * - **API key auth**: Creates new client with API key + new group
75
+ * - **JWT auth**: Creates new client with JWT + new group
76
+ * - **No auth**: Creates new client with standalone group interceptor
77
+ *
23
78
  * @param {string} group - The operating group context to inject into the request
24
79
  * in the format `groups/{ulid}` where {ulid} is a 26-character ULID.
25
80
  * Example: 'groups/01ARZ3NDEKTSV4YWVF8F5BH32'
26
81
  * @returns {MarketOrderServiceWeb} A new, configured instance of the client.
27
- * @throws {Error} If the group format is invalid (validation occurs in createGroupInterceptor)
82
+ * @throws {Error} If the group format is invalid
28
83
  */
29
84
  withGroup(group: string): MarketOrderServiceWeb;
30
85
  /**
@@ -7,28 +7,87 @@ exports.MarketOrderServiceWeb = void 0;
7
7
  const connect_1 = require("@connectrpc/connect");
8
8
  const connect_web_1 = require("@connectrpc/connect-web");
9
9
  const service_pb_1 = require("./service_pb");
10
- const config_1 = require("../../../common/config");
11
- const validation_1 = require("../../../common/validation");
12
- const connectInterceptors_1 = require("../../../common/connectInterceptors");
10
+ const service_pb_2 = require("./service_pb");
11
+ const config_1 = require("../../../config");
12
+ const protovalidate_1 = require("@bufbuild/protovalidate");
13
+ const interceptors_1 = require("../../../interceptors");
13
14
  /**
14
15
  * Web client for interacting with the meshtrade.trading.market_order.v1 market order v1 API resource service.
15
- * Uses Connect-ES with gRPC-Web transport for browser-compatible gRPC communication.
16
+ * Uses Connect-ES with gRPC-Web transport for browser-based communication.
17
+ *
18
+ * Supports flexible authentication modes using functional options pattern:
19
+ *
20
+ * 1. **No Authentication** (public APIs):
21
+ * ```typescript
22
+ * const client = new MarketOrderServiceWeb(
23
+ * WithServerUrl("http://localhost:10000")
24
+ * );
25
+ * ```
26
+ *
27
+ * 2. **API Key Authentication** (backend services):
28
+ * ```typescript
29
+ * const client = new MarketOrderServiceWeb(
30
+ * WithAPIKey("your-api-key"),
31
+ * WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
32
+ * WithServerUrl("https://api.example.com")
33
+ * );
34
+ * ```
35
+ *
36
+ * 3. **JWT Token Authentication** (Next.js frontend with user session):
37
+ * ```typescript
38
+ * const client = new MarketOrderServiceWeb(
39
+ * WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
40
+ * WithServerUrl("https://api.example.com")
41
+ * );
42
+ * ```
43
+ *
44
+ * 4. **JWT with Group Context** (user session with specific group):
45
+ * ```typescript
46
+ * const client = new MarketOrderServiceWeb(
47
+ * WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
48
+ * WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
49
+ * WithServerUrl("https://api.example.com")
50
+ * );
51
+ * ```
52
+ *
53
+ * Available options:
54
+ * - `WithAPIKey(key)` - API key authentication (mutually exclusive with JWT)
55
+ * - `WithJWTAccessToken(token)` - JWT authentication (mutually exclusive with API key)
56
+ * - `WithGroup(group)` - Group context (optional, works with both auth modes)
57
+ * - `WithServerUrl(url)` - Custom server URL (optional, defaults to production)
16
58
  */
17
59
  class MarketOrderServiceWeb {
18
60
  /**
19
61
  * Constructs an instance of MarketOrderServiceWeb.
20
- * @param {ConfigOpts} [config] - Optional configuration for the client.
21
- * @param {Interceptor[]} [interceptors] - For internal use by `withGroup`.
62
+ *
63
+ * Uses functional options pattern for flexible configuration:
64
+ * - `WithAPIKey(key)` - API key authentication
65
+ * - `WithJWTAccessToken(token)` - JWT authentication
66
+ * - `WithGroup(group)` - Group context (optional)
67
+ * - `WithServerUrl(url)` - Custom server URL (optional)
68
+ *
69
+ * @param {...ClientOption} opts - Variable number of configuration options
22
70
  */
23
- constructor(config, interceptors) {
24
- this._config = (0, config_1.getConfigFromOpts)(config);
25
- this._interceptors = interceptors || [];
26
- // Create the gRPC-Web transport with interceptors
71
+ constructor(...opts) {
72
+ // Build configuration from options
73
+ this._config = (0, config_1.buildConfigFromOptions)(...opts);
74
+ // Initialize validator for request validation
75
+ this._validator = (0, protovalidate_1.createValidator)();
76
+ this._interceptors = [];
77
+ this._interceptors.push((0, interceptors_1.createLoggingInterceptor)());
78
+ if (this._config.apiKey) {
79
+ this._interceptors.push((0, interceptors_1.createApiKeyInterceptor)(this._config.apiKey));
80
+ }
81
+ if (this._config.jwtToken) {
82
+ this._interceptors.push((0, interceptors_1.createJwtInterceptor)(this._config.jwtToken));
83
+ }
84
+ if (this._config.group) {
85
+ this._interceptors.push((0, interceptors_1.createGroupInterceptor)(this._config.group));
86
+ }
87
+ // Create the gRPC-Web transport for browser with interceptors
27
88
  const transport = (0, connect_web_1.createGrpcWebTransport)({
28
89
  baseUrl: this._config.apiServerURL,
29
90
  interceptors: this._interceptors,
30
- // Enable credentials (cookies) for cross-origin requests
31
- fetch: (input, init) => globalThis.fetch(input, { ...init, credentials: 'include' }),
32
91
  });
33
92
  // Construct the Connect-ES client
34
93
  this._client = (0, connect_1.createClient)(service_pb_1.MarketOrderService, transport);
@@ -37,26 +96,36 @@ class MarketOrderServiceWeb {
37
96
  * Returns a new client instance configured to send the specified group
38
97
  * resource name in the request headers for subsequent API calls.
39
98
  *
99
+ * This method creates a new client with the same authentication configuration
100
+ * but with the group context updated to the specified value.
101
+ *
102
+ * **Compatibility**: Works with all authentication modes:
103
+ * - **API key auth**: Creates new client with API key + new group
104
+ * - **JWT auth**: Creates new client with JWT + new group
105
+ * - **No auth**: Creates new client with standalone group interceptor
106
+ *
40
107
  * @param {string} group - The operating group context to inject into the request
41
108
  * in the format `groups/{ulid}` where {ulid} is a 26-character ULID.
42
109
  * Example: 'groups/01ARZ3NDEKTSV4YWVF8F5BH32'
43
110
  * @returns {MarketOrderServiceWeb} A new, configured instance of the client.
44
- * @throws {Error} If the group format is invalid (validation occurs in createGroupInterceptor)
111
+ * @throws {Error} If the group format is invalid
45
112
  */
46
113
  withGroup(group) {
47
- // Check if a group interceptor already exists.
48
- // Group interceptors are identified by having a 'groupContext' property
49
- const hasGroupInterceptor = this._interceptors.some((interceptor) => interceptor.groupContext !== undefined);
50
- if (hasGroupInterceptor) {
51
- throw new Error("Attempted to set group context twice. A group has already been set for this client instance.");
114
+ // Build new options array with existing auth and updated group
115
+ const newOpts = [];
116
+ // Add server URL
117
+ newOpts.push((0, config_1.WithServerUrl)(this._config.apiServerURL));
118
+ // Add authentication (preserve existing mode)
119
+ if (this._config.apiKey) {
120
+ newOpts.push((0, config_1.WithAPIKey)(this._config.apiKey));
121
+ }
122
+ else if (this._config.jwtToken) {
123
+ newOpts.push((0, config_1.WithJWTAccessToken)(this._config.jwtToken));
52
124
  }
53
- // Create a new interceptor for the group context
54
- const groupInterceptor = (0, connectInterceptors_1.createGroupInterceptor)(group);
55
- // Return a new client instance with the existing interceptors plus the new one
56
- return new MarketOrderServiceWeb(this._config, [
57
- ...this._interceptors,
58
- groupInterceptor,
59
- ]);
125
+ // Add the new group
126
+ newOpts.push((0, config_1.WithGroup)(group));
127
+ // Return a new client instance with updated configuration
128
+ return new MarketOrderServiceWeb(...newOpts);
60
129
  }
61
130
  /**
62
131
  * Retrieves a market order.
@@ -65,7 +134,14 @@ class MarketOrderServiceWeb {
65
134
  */
66
135
  getMarketOrder(request) {
67
136
  // Validate request
68
- (0, validation_1.validateRequest)(request);
137
+ const result = this._validator.validate(service_pb_2.GetMarketOrderRequestSchema, request);
138
+ if (result.kind === "invalid") {
139
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
140
+ throw new Error(`Validation failed: ${violations}`);
141
+ }
142
+ else if (result.kind === "error") {
143
+ throw result.error;
144
+ }
69
145
  return this._client.getMarketOrder(request);
70
146
  }
71
147
  }
@@ -40,6 +40,14 @@ export type Account = Message<"meshtrade.wallet.account.v1.Account"> & {
40
40
  * @generated from field: string owner = 2;
41
41
  */
42
42
  owner: string;
43
+ /**
44
+ *
45
+ * Ownership hiearchy of groups that have access to this resource in the format groups/{group_id}.
46
+ * System set on creation.
47
+ *
48
+ * @generated from field: repeated string owners = 3;
49
+ */
50
+ owners: string[];
43
51
  /**
44
52
  *
45
53
  * The Unique Mesh Account Number for simplified account identification.
@@ -14,7 +14,7 @@ const ledger_pb_1 = require("../../../type/v1/ledger_pb");
14
14
  /**
15
15
  * Describes the file meshtrade/wallet/account/v1/account.proto.
16
16
  */
17
- exports.file_meshtrade_wallet_account_v1_account = (0, codegenv2_1.fileDesc)("CiltZXNodHJhZGUvd2FsbGV0L2FjY291bnQvdjEvYWNjb3VudC5wcm90bxIbbWVzaHRyYWRlLndhbGxldC5hY2NvdW50LnYxIqAGCgdBY2NvdW50EroBCgRuYW1lGAEgASgJQqsBukinAboBowEKFG5hbWUuZm9ybWF0Lm9wdGlvbmFsEjVuYW1lIG11c3QgYmUgZW1wdHkgb3IgaW4gdGhlIGZvcm1hdCBhY2NvdW50cy97VUxJRHYyfRpUc2l6ZSh0aGlzKSA9PSAwIHx8IHRoaXMubWF0Y2hlcygnXmFjY291bnRzL1swMTIzNDU2Nzg5QUJDREVGR0hKS01OUFFSU1RWV1hZWl17MjZ9JCcpEksKBW93bmVyGAIgASgJQjy6SDnIAQFyNDIvXmdyb3Vwcy9bMDEyMzQ1Njc4OUFCQ0RFRkdISktN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bnRNZXRhRGF0YSI+CglTaWduYXRvcnkSFAoMZGlzcGxheV9uYW1lGAEgASgJEhsKCWxlZGdlcl9pZBgCIAEoCUIIukgFcgMY/wEqXwoMQWNjb3VudFN0YXRlEh0KGUFDQ09VTlRfU1RBVEVfVU5TUEVDSUZJRUQQABIYChRBQ0NPVU5UX1NUQVRFX0NMT1NFRBABEhYKEkFDQ09VTlRfU1RBVEVfT1BFThACQl4KImNvLm1lc2h0cmFkZS5hcGkud2FsbGV0LmFjY291bnQudjFaOGdpdGh1Yi5jb20vbWVzaHRyYWRlL2FwaS9nby93YWxsZXQvYWNjb3VudC92MTthY2NvdW50X3YxYgZwcm90bzM", [validate_pb_1.file_buf_validate_validate, wkt_1.file_google_protobuf_timestamp, instrument_type_pb_1.file_meshtrade_studio_instrument_v1_instrument_type, unit_pb_1.file_meshtrade_studio_instrument_v1_unit, amount_pb_1.file_meshtrade_type_v1_amount, ledger_pb_1.file_meshtrade_type_v1_ledger]);
17
+ exports.file_meshtrade_wallet_account_v1_account = (0, codegenv2_1.fileDesc)("CiltZXNodHJhZGUvd2FsbGV0L2FjY291bnQvdjEvYWNjb3VudC5wcm90bxIbbWVzaHRyYWRlLndhbGxldC5hY2NvdW50LnYxIvAGCgdBY2NvdW50EroBCgRuYW1lGAEgASgJQqsBukinAboBowEKFG5hbWUuZm9ybWF0Lm9wdGlvbmFsEjVuYW1lIG11c3QgYmUgZW1wdHkgb3IgaW4gdGhlIGZvcm1hdCBhY2NvdW50cy97VUxJRHYyfRpUc2l6ZSh0aGlzKSA9PSAwIHx8IHRoaXMubWF0Y2hlcygnXmFjY291bnRzL1swMTIzNDU2Nzg5QUJDREVGR0hKS01OUFFSU1RWV1hZWl17MjZ9JCcpEksKBW93bmVyGAIgASgJQjy6SDnIAQFyNDIvXmdyb3Vwcy9bMDEyMzQ1Njc4OUFCQ0RFRkdISktNTlBRUlNUVldYWVpdezI2fSSYASESTgoGb3duZXJzGAMgAygJQj66SDuSATgiNnI0Mi9eZ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bGV0LmFjY291bnQudjEuSW5zdHJ1bWVudE1ldGFEYXRhIj4KCVNpZ25hdG9yeRIUCgxkaXNwbGF5X25hbWUYASABKAkSGwoJbGVkZ2VyX2lkGAIgASgJQgi6SAVyAxj/ASpfCgxBY2NvdW50U3RhdGUSHQoZQUNDT1VOVF9TVEFURV9VTlNQRUNJRklFRBAAEhgKFEFDQ09VTlRfU1RBVEVfQ0xPU0VEEAESFgoSQUNDT1VOVF9TVEFURV9PUEVOEAJCXgoiY28ubWVzaHRyYWRlLmFwaS53YWxsZXQuYWNjb3VudC52MVo4Z2l0aHViLmNvbS9tZXNodHJhZGUvYXBpL2dvL3dhbGxldC9hY2NvdW50L3YxO2FjY291bnRfdjFiBnByb3RvMw", [validate_pb_1.file_buf_validate_validate, wkt_1.file_google_protobuf_timestamp, instrument_type_pb_1.file_meshtrade_studio_instrument_v1_instrument_type, unit_pb_1.file_meshtrade_studio_instrument_v1_unit, amount_pb_1.file_meshtrade_type_v1_amount, ledger_pb_1.file_meshtrade_type_v1_ledger]);
18
18
  /**
19
19
  * Describes the message meshtrade.wallet.account.v1.Account.
20
20
  * Use `create(AccountSchema)` to create a new message.
@@ -1,30 +1,85 @@
1
- import { Interceptor } from "@connectrpc/connect";
2
1
  import { AddSignatoriesToAccountRequest, AddSignatoriesToAccountResponse, CreateAccountRequest, GetAccountByNumberRequest, GetAccountRequest, ListAccountsRequest, ListAccountsResponse, OpenAccountRequest, OpenAccountResponse, RemoveSignatoriesFromAccountRequest, RemoveSignatoriesFromAccountResponse, SearchAccountsRequest, SearchAccountsResponse, UpdateAccountRequest } from "./service_pb";
3
2
  import { Account } from "./account_pb";
4
- import { ConfigOpts } from "../../../common/config";
3
+ import { ClientOption } from "../../../config";
5
4
  /**
6
5
  * Web client for interacting with the meshtrade.wallet.account.v1 account v1 API resource service.
7
- * Uses Connect-ES with gRPC-Web transport for browser-compatible gRPC communication.
6
+ * Uses Connect-ES with gRPC-Web transport for browser-based communication.
7
+ *
8
+ * Supports flexible authentication modes using functional options pattern:
9
+ *
10
+ * 1. **No Authentication** (public APIs):
11
+ * ```typescript
12
+ * const client = new AccountServiceWeb(
13
+ * WithServerUrl("http://localhost:10000")
14
+ * );
15
+ * ```
16
+ *
17
+ * 2. **API Key Authentication** (backend services):
18
+ * ```typescript
19
+ * const client = new AccountServiceWeb(
20
+ * WithAPIKey("your-api-key"),
21
+ * WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
22
+ * WithServerUrl("https://api.example.com")
23
+ * );
24
+ * ```
25
+ *
26
+ * 3. **JWT Token Authentication** (Next.js frontend with user session):
27
+ * ```typescript
28
+ * const client = new AccountServiceWeb(
29
+ * WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
30
+ * WithServerUrl("https://api.example.com")
31
+ * );
32
+ * ```
33
+ *
34
+ * 4. **JWT with Group Context** (user session with specific group):
35
+ * ```typescript
36
+ * const client = new AccountServiceWeb(
37
+ * WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
38
+ * WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
39
+ * WithServerUrl("https://api.example.com")
40
+ * );
41
+ * ```
42
+ *
43
+ * Available options:
44
+ * - `WithAPIKey(key)` - API key authentication (mutually exclusive with JWT)
45
+ * - `WithJWTAccessToken(token)` - JWT authentication (mutually exclusive with API key)
46
+ * - `WithGroup(group)` - Group context (optional, works with both auth modes)
47
+ * - `WithServerUrl(url)` - Custom server URL (optional, defaults to production)
8
48
  */
9
49
  export declare class AccountServiceWeb {
10
50
  private _client;
11
51
  private readonly _config;
12
52
  private readonly _interceptors;
53
+ private readonly _validator;
13
54
  /**
14
55
  * Constructs an instance of AccountServiceWeb.
15
- * @param {ConfigOpts} [config] - Optional configuration for the client.
16
- * @param {Interceptor[]} [interceptors] - For internal use by `withGroup`.
56
+ *
57
+ * Uses functional options pattern for flexible configuration:
58
+ * - `WithAPIKey(key)` - API key authentication
59
+ * - `WithJWTAccessToken(token)` - JWT authentication
60
+ * - `WithGroup(group)` - Group context (optional)
61
+ * - `WithServerUrl(url)` - Custom server URL (optional)
62
+ *
63
+ * @param {...ClientOption} opts - Variable number of configuration options
17
64
  */
18
- constructor(config?: ConfigOpts, interceptors?: Interceptor[]);
65
+ constructor(...opts: ClientOption[]);
19
66
  /**
20
67
  * Returns a new client instance configured to send the specified group
21
68
  * resource name in the request headers for subsequent API calls.
22
69
  *
70
+ * This method creates a new client with the same authentication configuration
71
+ * but with the group context updated to the specified value.
72
+ *
73
+ * **Compatibility**: Works with all authentication modes:
74
+ * - **API key auth**: Creates new client with API key + new group
75
+ * - **JWT auth**: Creates new client with JWT + new group
76
+ * - **No auth**: Creates new client with standalone group interceptor
77
+ *
23
78
  * @param {string} group - The operating group context to inject into the request
24
79
  * in the format `groups/{ulid}` where {ulid} is a 26-character ULID.
25
80
  * Example: 'groups/01ARZ3NDEKTSV4YWVF8F5BH32'
26
81
  * @returns {AccountServiceWeb} A new, configured instance of the client.
27
- * @throws {Error} If the group format is invalid (validation occurs in createGroupInterceptor)
82
+ * @throws {Error} If the group format is invalid
28
83
  */
29
84
  withGroup(group: string): AccountServiceWeb;
30
85
  /**