@meshtrade/api-node 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_node_meshts.d.ts +46 -21
  4. package/dist/meshtrade/compliance/client/v1/service_node_meshts.js +98 -56
  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_node_meshts.d.ts +46 -21
  10. package/dist/meshtrade/iam/api_user/v1/service_node_meshts.js +149 -65
  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_node_meshts.d.ts +46 -21
  14. package/dist/meshtrade/iam/group/v1/service_node_meshts.js +114 -58
  15. package/dist/meshtrade/iam/user/v1/service_node_meshts.d.ts +46 -21
  16. package/dist/meshtrade/iam/user/v1/service_node_meshts.js +141 -64
  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} +6 -64
  20. package/dist/meshtrade/{common/connectInterceptors.js → interceptors/index.js} +20 -90
  21. package/dist/meshtrade/ledger/transaction/v1/service_node_meshts.d.ts +46 -21
  22. package/dist/meshtrade/ledger/transaction/v1/service_node_meshts.js +90 -55
  23. package/dist/meshtrade/market_data/price/v1/service_node_meshts.d.ts +46 -21
  24. package/dist/meshtrade/market_data/price/v1/service_node_meshts.js +82 -54
  25. package/dist/meshtrade/reporting/account_report/v1/service_node_meshts.d.ts +46 -21
  26. package/dist/meshtrade/reporting/account_report/v1/service_node_meshts.js +90 -55
  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_node_meshts.d.ts +46 -21
  32. package/dist/meshtrade/trading/limit_order/v1/service_node_meshts.js +133 -63
  33. package/dist/meshtrade/trading/market_order/v1/service_node_meshts.d.ts +46 -21
  34. package/dist/meshtrade/trading/market_order/v1/service_node_meshts.js +82 -54
  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_node_meshts.d.ts +46 -21
  38. package/dist/meshtrade/wallet/account/v1/service_node_meshts.js +149 -65
  39. package/package.json +19 -2
  40. package/dist/meshtrade/common/config.d.ts +0 -50
  41. package/dist/meshtrade/common/config.js +0 -34
  42. package/dist/meshtrade/common/validation.d.ts +0 -62
  43. package/dist/meshtrade/common/validation.js +0 -77
@@ -7,62 +7,82 @@ exports.LimitOrderServiceNode = void 0;
7
7
  const connect_1 = require("@connectrpc/connect");
8
8
  const connect_node_1 = require("@connectrpc/connect-node");
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
  * Node.js client for interacting with the meshtrade.trading.limit_order.v1 limit order v1 API resource service.
15
16
  * Uses Connect-ES with gRPC transport for Node.js gRPC communication.
16
17
  *
17
- * Supports three authentication modes:
18
+ * Supports flexible authentication modes using functional options pattern:
18
19
  *
19
20
  * 1. **No Authentication** (public APIs):
20
21
  * ```typescript
21
- * const client = new LimitOrderServiceNode({ apiServerURL: "http://localhost:10000" });
22
+ * const client = new LimitOrderServiceNode(
23
+ * WithServerUrl("http://localhost:10000")
24
+ * );
22
25
  * ```
23
26
  *
24
27
  * 2. **API Key Authentication** (backend services):
25
28
  * ```typescript
26
- * const client = new LimitOrderServiceNode({
27
- * apiServerURL: "https://api.example.com",
28
- * apiKey: "your-api-key",
29
- * group: "groups/01ARZ3NDEKTSV4YWVF8F5BH32"
30
- * });
29
+ * const client = new LimitOrderServiceNode(
30
+ * WithAPIKey("your-api-key"),
31
+ * WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
32
+ * WithServerUrl("https://api.example.com")
33
+ * );
31
34
  * ```
32
35
  *
33
36
  * 3. **JWT Token Authentication** (Next.js backend with user session):
34
37
  * ```typescript
35
- * const client = new LimitOrderServiceNode({
36
- * apiServerURL: "https://api.example.com",
37
- * jwtToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
38
- * });
38
+ * const client = new LimitOrderServiceNode(
39
+ * WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
40
+ * WithServerUrl("https://api.example.com")
41
+ * );
39
42
  * ```
43
+ *
44
+ * 4. **JWT with Group Context** (user session with specific group):
45
+ * ```typescript
46
+ * const client = new LimitOrderServiceNode(
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)
40
58
  */
41
59
  class LimitOrderServiceNode {
42
60
  /**
43
61
  * Constructs an instance of LimitOrderServiceNode.
44
- * @param {ConfigOpts} [config] - Optional configuration for the client.
45
- * @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
46
70
  */
47
- constructor(config, interceptors) {
48
- this._config = (0, config_1.getConfigFromOpts)(config);
49
- // If interceptors are provided (from withGroup), use them
50
- // Otherwise, create auth interceptors based on config
51
- if (interceptors) {
52
- this._interceptors = interceptors;
53
- }
54
- else {
55
- this._interceptors = [];
56
- // Add authentication interceptor based on configuration
57
- if (this._config.apiKey && this._config.group) {
58
- // API Key authentication mode
59
- this._interceptors.push((0, connectInterceptors_1.createApiKeyInterceptor)(this._config.apiKey, this._config.group));
60
- }
61
- else if (this._config.jwtToken) {
62
- // JWT authentication mode
63
- this._interceptors.push((0, connectInterceptors_1.createJwtInterceptor)(this._config.jwtToken));
64
- }
65
- // If neither is configured, no authentication (public API mode)
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));
66
86
  }
67
87
  // Create the gRPC transport for Node.js with interceptors
68
88
  // Note: gRPC transport uses HTTP/2 by default
@@ -77,35 +97,36 @@ class LimitOrderServiceNode {
77
97
  * Returns a new client instance configured to send the specified group
78
98
  * resource name in the request headers for subsequent API calls.
79
99
  *
80
- * **Important**: This method only works with API key authentication.
81
- * - For **API key auth**: Creates a new client with updated group context
82
- * - For **JWT auth**: Throws error (group comes from JWT token claims)
83
- * - For **no auth**: Throws error (group requires authentication)
100
+ * This method creates a new client with the same authentication configuration
101
+ * but with the group context updated to the specified value.
102
+ *
103
+ * **Compatibility**: Works with all authentication modes:
104
+ * - **API key auth**: Creates new client with API key + new group
105
+ * - **JWT auth**: Creates new client with JWT + new group
106
+ * - **No auth**: Creates new client with standalone group interceptor
84
107
  *
85
108
  * @param {string} group - The operating group context to inject into the request
86
109
  * in the format `groups/{ulid}` where {ulid} is a 26-character ULID.
87
110
  * Example: 'groups/01ARZ3NDEKTSV4YWVF8F5BH32'
88
111
  * @returns {LimitOrderServiceNode} A new, configured instance of the client.
89
- * @throws {Error} If used with JWT authentication or no authentication
90
112
  * @throws {Error} If the group format is invalid
91
113
  */
92
114
  withGroup(group) {
93
- // Check authentication mode
94
- if (this._config.jwtToken) {
95
- throw new Error("Cannot use withGroup() with JWT authentication. " +
96
- "The group context is determined by the JWT token claims.");
97
- }
98
- if (!this._config.apiKey) {
99
- throw new Error("Cannot use withGroup() without authentication. " +
100
- "Please configure API key authentication to use group context.");
101
- }
102
- // For API key authentication, create new client with updated group
103
- // Replace the existing API key interceptor with one that has the new group
104
- const newInterceptors = [
105
- (0, connectInterceptors_1.createApiKeyInterceptor)(this._config.apiKey, group)
106
- ];
107
- // Return a new client instance with updated group context
108
- return new LimitOrderServiceNode(this._config, newInterceptors);
115
+ // Build new options array with existing auth and updated group
116
+ const newOpts = [];
117
+ // Add server URL
118
+ newOpts.push((0, config_1.WithServerUrl)(this._config.apiServerURL));
119
+ // Add authentication (preserve existing mode)
120
+ if (this._config.apiKey) {
121
+ newOpts.push((0, config_1.WithAPIKey)(this._config.apiKey));
122
+ }
123
+ else if (this._config.jwtToken) {
124
+ newOpts.push((0, config_1.WithJWTAccessToken)(this._config.jwtToken));
125
+ }
126
+ // Add the new group
127
+ newOpts.push((0, config_1.WithGroup)(group));
128
+ // Return a new client instance with updated configuration
129
+ return new LimitOrderServiceNode(...newOpts);
109
130
  }
110
131
  /**
111
132
  * Creates a new limit order.
@@ -114,7 +135,14 @@ class LimitOrderServiceNode {
114
135
  */
115
136
  createLimitOrder(request) {
116
137
  // Validate request
117
- (0, validation_1.validateRequest)(request);
138
+ const result = this._validator.validate(service_pb_2.CreateLimitOrderRequestSchema, request);
139
+ if (result.kind === "invalid") {
140
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
141
+ throw new Error(`Validation failed: ${violations}`);
142
+ }
143
+ else if (result.kind === "error") {
144
+ throw result.error;
145
+ }
118
146
  return this._client.createLimitOrder(request);
119
147
  }
120
148
  /**
@@ -124,7 +152,14 @@ class LimitOrderServiceNode {
124
152
  */
125
153
  cancelLimitOrder(request) {
126
154
  // Validate request
127
- (0, validation_1.validateRequest)(request);
155
+ const result = this._validator.validate(service_pb_2.CancelLimitOrderRequestSchema, request);
156
+ if (result.kind === "invalid") {
157
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
158
+ throw new Error(`Validation failed: ${violations}`);
159
+ }
160
+ else if (result.kind === "error") {
161
+ throw result.error;
162
+ }
128
163
  return this._client.cancelLimitOrder(request);
129
164
  }
130
165
  /**
@@ -134,7 +169,14 @@ class LimitOrderServiceNode {
134
169
  */
135
170
  getLimitOrder(request) {
136
171
  // Validate request
137
- (0, validation_1.validateRequest)(request);
172
+ const result = this._validator.validate(service_pb_2.GetLimitOrderRequestSchema, request);
173
+ if (result.kind === "invalid") {
174
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
175
+ throw new Error(`Validation failed: ${violations}`);
176
+ }
177
+ else if (result.kind === "error") {
178
+ throw result.error;
179
+ }
138
180
  return this._client.getLimitOrder(request);
139
181
  }
140
182
  /**
@@ -144,7 +186,14 @@ class LimitOrderServiceNode {
144
186
  */
145
187
  getLimitOrderByExternalReference(request) {
146
188
  // Validate request
147
- (0, validation_1.validateRequest)(request);
189
+ const result = this._validator.validate(service_pb_2.GetLimitOrderByExternalReferenceRequestSchema, request);
190
+ if (result.kind === "invalid") {
191
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
192
+ throw new Error(`Validation failed: ${violations}`);
193
+ }
194
+ else if (result.kind === "error") {
195
+ throw result.error;
196
+ }
148
197
  return this._client.getLimitOrderByExternalReference(request);
149
198
  }
150
199
  /**
@@ -154,7 +203,14 @@ class LimitOrderServiceNode {
154
203
  */
155
204
  listLimitOrders(request) {
156
205
  // Validate request
157
- (0, validation_1.validateRequest)(request);
206
+ const result = this._validator.validate(service_pb_2.ListLimitOrdersRequestSchema, request);
207
+ if (result.kind === "invalid") {
208
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
209
+ throw new Error(`Validation failed: ${violations}`);
210
+ }
211
+ else if (result.kind === "error") {
212
+ throw result.error;
213
+ }
158
214
  return this._client.listLimitOrders(request);
159
215
  }
160
216
  /**
@@ -164,7 +220,14 @@ class LimitOrderServiceNode {
164
220
  */
165
221
  searchLimitOrders(request) {
166
222
  // Validate request
167
- (0, validation_1.validateRequest)(request);
223
+ const result = this._validator.validate(service_pb_2.SearchLimitOrdersRequestSchema, request);
224
+ if (result.kind === "invalid") {
225
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
226
+ throw new Error(`Validation failed: ${violations}`);
227
+ }
228
+ else if (result.kind === "error") {
229
+ throw result.error;
230
+ }
168
231
  return this._client.searchLimitOrders(request);
169
232
  }
170
233
  /**
@@ -183,7 +246,14 @@ class LimitOrderServiceNode {
183
246
  */
184
247
  monitorLimitOrder(request) {
185
248
  // Validate request before initiating stream
186
- (0, validation_1.validateRequest)(request);
249
+ const result = this._validator.validate(service_pb_2.MonitorLimitOrderRequestSchema, request);
250
+ if (result.kind === "invalid") {
251
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
252
+ throw new Error(`Validation failed: ${violations}`);
253
+ }
254
+ else if (result.kind === "error") {
255
+ throw result.error;
256
+ }
187
257
  return this._client.monitorLimitOrder(request);
188
258
  }
189
259
  }
@@ -1,59 +1,84 @@
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
  * Node.js client for interacting with the meshtrade.trading.market_order.v1 market order v1 API resource service.
7
6
  * Uses Connect-ES with gRPC transport for Node.js gRPC communication.
8
7
  *
9
- * Supports three authentication modes:
8
+ * Supports flexible authentication modes using functional options pattern:
10
9
  *
11
10
  * 1. **No Authentication** (public APIs):
12
11
  * ```typescript
13
- * const client = new MarketOrderServiceNode({ apiServerURL: "http://localhost:10000" });
12
+ * const client = new MarketOrderServiceNode(
13
+ * WithServerUrl("http://localhost:10000")
14
+ * );
14
15
  * ```
15
16
  *
16
17
  * 2. **API Key Authentication** (backend services):
17
18
  * ```typescript
18
- * const client = new MarketOrderServiceNode({
19
- * apiServerURL: "https://api.example.com",
20
- * apiKey: "your-api-key",
21
- * group: "groups/01ARZ3NDEKTSV4YWVF8F5BH32"
22
- * });
19
+ * const client = new MarketOrderServiceNode(
20
+ * WithAPIKey("your-api-key"),
21
+ * WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
22
+ * WithServerUrl("https://api.example.com")
23
+ * );
23
24
  * ```
24
25
  *
25
26
  * 3. **JWT Token Authentication** (Next.js backend with user session):
26
27
  * ```typescript
27
- * const client = new MarketOrderServiceNode({
28
- * apiServerURL: "https://api.example.com",
29
- * jwtToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
30
- * });
28
+ * const client = new MarketOrderServiceNode(
29
+ * WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
30
+ * WithServerUrl("https://api.example.com")
31
+ * );
31
32
  * ```
33
+ *
34
+ * 4. **JWT with Group Context** (user session with specific group):
35
+ * ```typescript
36
+ * const client = new MarketOrderServiceNode(
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)
32
48
  */
33
49
  export declare class MarketOrderServiceNode {
34
50
  private _client;
35
51
  private readonly _config;
36
52
  private readonly _interceptors;
53
+ private readonly _validator;
37
54
  /**
38
55
  * Constructs an instance of MarketOrderServiceNode.
39
- * @param {ConfigOpts} [config] - Optional configuration for the client.
40
- * @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
41
64
  */
42
- constructor(config?: ConfigOpts, interceptors?: Interceptor[]);
65
+ constructor(...opts: ClientOption[]);
43
66
  /**
44
67
  * Returns a new client instance configured to send the specified group
45
68
  * resource name in the request headers for subsequent API calls.
46
69
  *
47
- * **Important**: This method only works with API key authentication.
48
- * - For **API key auth**: Creates a new client with updated group context
49
- * - For **JWT auth**: Throws error (group comes from JWT token claims)
50
- * - For **no auth**: Throws error (group requires authentication)
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
51
77
  *
52
78
  * @param {string} group - The operating group context to inject into the request
53
79
  * in the format `groups/{ulid}` where {ulid} is a 26-character ULID.
54
80
  * Example: 'groups/01ARZ3NDEKTSV4YWVF8F5BH32'
55
81
  * @returns {MarketOrderServiceNode} A new, configured instance of the client.
56
- * @throws {Error} If used with JWT authentication or no authentication
57
82
  * @throws {Error} If the group format is invalid
58
83
  */
59
84
  withGroup(group: string): MarketOrderServiceNode;
@@ -7,62 +7,82 @@ exports.MarketOrderServiceNode = void 0;
7
7
  const connect_1 = require("@connectrpc/connect");
8
8
  const connect_node_1 = require("@connectrpc/connect-node");
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
  * Node.js client for interacting with the meshtrade.trading.market_order.v1 market order v1 API resource service.
15
16
  * Uses Connect-ES with gRPC transport for Node.js gRPC communication.
16
17
  *
17
- * Supports three authentication modes:
18
+ * Supports flexible authentication modes using functional options pattern:
18
19
  *
19
20
  * 1. **No Authentication** (public APIs):
20
21
  * ```typescript
21
- * const client = new MarketOrderServiceNode({ apiServerURL: "http://localhost:10000" });
22
+ * const client = new MarketOrderServiceNode(
23
+ * WithServerUrl("http://localhost:10000")
24
+ * );
22
25
  * ```
23
26
  *
24
27
  * 2. **API Key Authentication** (backend services):
25
28
  * ```typescript
26
- * const client = new MarketOrderServiceNode({
27
- * apiServerURL: "https://api.example.com",
28
- * apiKey: "your-api-key",
29
- * group: "groups/01ARZ3NDEKTSV4YWVF8F5BH32"
30
- * });
29
+ * const client = new MarketOrderServiceNode(
30
+ * WithAPIKey("your-api-key"),
31
+ * WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
32
+ * WithServerUrl("https://api.example.com")
33
+ * );
31
34
  * ```
32
35
  *
33
36
  * 3. **JWT Token Authentication** (Next.js backend with user session):
34
37
  * ```typescript
35
- * const client = new MarketOrderServiceNode({
36
- * apiServerURL: "https://api.example.com",
37
- * jwtToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
38
- * });
38
+ * const client = new MarketOrderServiceNode(
39
+ * WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
40
+ * WithServerUrl("https://api.example.com")
41
+ * );
39
42
  * ```
43
+ *
44
+ * 4. **JWT with Group Context** (user session with specific group):
45
+ * ```typescript
46
+ * const client = new MarketOrderServiceNode(
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)
40
58
  */
41
59
  class MarketOrderServiceNode {
42
60
  /**
43
61
  * Constructs an instance of MarketOrderServiceNode.
44
- * @param {ConfigOpts} [config] - Optional configuration for the client.
45
- * @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
46
70
  */
47
- constructor(config, interceptors) {
48
- this._config = (0, config_1.getConfigFromOpts)(config);
49
- // If interceptors are provided (from withGroup), use them
50
- // Otherwise, create auth interceptors based on config
51
- if (interceptors) {
52
- this._interceptors = 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));
53
80
  }
54
- else {
55
- this._interceptors = [];
56
- // Add authentication interceptor based on configuration
57
- if (this._config.apiKey && this._config.group) {
58
- // API Key authentication mode
59
- this._interceptors.push((0, connectInterceptors_1.createApiKeyInterceptor)(this._config.apiKey, this._config.group));
60
- }
61
- else if (this._config.jwtToken) {
62
- // JWT authentication mode
63
- this._interceptors.push((0, connectInterceptors_1.createJwtInterceptor)(this._config.jwtToken));
64
- }
65
- // If neither is configured, no authentication (public API mode)
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));
66
86
  }
67
87
  // Create the gRPC transport for Node.js with interceptors
68
88
  // Note: gRPC transport uses HTTP/2 by default
@@ -77,35 +97,36 @@ class MarketOrderServiceNode {
77
97
  * Returns a new client instance configured to send the specified group
78
98
  * resource name in the request headers for subsequent API calls.
79
99
  *
80
- * **Important**: This method only works with API key authentication.
81
- * - For **API key auth**: Creates a new client with updated group context
82
- * - For **JWT auth**: Throws error (group comes from JWT token claims)
83
- * - For **no auth**: Throws error (group requires authentication)
100
+ * This method creates a new client with the same authentication configuration
101
+ * but with the group context updated to the specified value.
102
+ *
103
+ * **Compatibility**: Works with all authentication modes:
104
+ * - **API key auth**: Creates new client with API key + new group
105
+ * - **JWT auth**: Creates new client with JWT + new group
106
+ * - **No auth**: Creates new client with standalone group interceptor
84
107
  *
85
108
  * @param {string} group - The operating group context to inject into the request
86
109
  * in the format `groups/{ulid}` where {ulid} is a 26-character ULID.
87
110
  * Example: 'groups/01ARZ3NDEKTSV4YWVF8F5BH32'
88
111
  * @returns {MarketOrderServiceNode} A new, configured instance of the client.
89
- * @throws {Error} If used with JWT authentication or no authentication
90
112
  * @throws {Error} If the group format is invalid
91
113
  */
92
114
  withGroup(group) {
93
- // Check authentication mode
94
- if (this._config.jwtToken) {
95
- throw new Error("Cannot use withGroup() with JWT authentication. " +
96
- "The group context is determined by the JWT token claims.");
115
+ // Build new options array with existing auth and updated group
116
+ const newOpts = [];
117
+ // Add server URL
118
+ newOpts.push((0, config_1.WithServerUrl)(this._config.apiServerURL));
119
+ // Add authentication (preserve existing mode)
120
+ if (this._config.apiKey) {
121
+ newOpts.push((0, config_1.WithAPIKey)(this._config.apiKey));
97
122
  }
98
- if (!this._config.apiKey) {
99
- throw new Error("Cannot use withGroup() without authentication. " +
100
- "Please configure API key authentication to use group context.");
123
+ else if (this._config.jwtToken) {
124
+ newOpts.push((0, config_1.WithJWTAccessToken)(this._config.jwtToken));
101
125
  }
102
- // For API key authentication, create new client with updated group
103
- // Replace the existing API key interceptor with one that has the new group
104
- const newInterceptors = [
105
- (0, connectInterceptors_1.createApiKeyInterceptor)(this._config.apiKey, group)
106
- ];
107
- // Return a new client instance with updated group context
108
- return new MarketOrderServiceNode(this._config, newInterceptors);
126
+ // Add the new group
127
+ newOpts.push((0, config_1.WithGroup)(group));
128
+ // Return a new client instance with updated configuration
129
+ return new MarketOrderServiceNode(...newOpts);
109
130
  }
110
131
  /**
111
132
  * Retrieves a market order.
@@ -114,7 +135,14 @@ class MarketOrderServiceNode {
114
135
  */
115
136
  getMarketOrder(request) {
116
137
  // Validate request
117
- (0, validation_1.validateRequest)(request);
138
+ const result = this._validator.validate(service_pb_2.GetMarketOrderRequestSchema, request);
139
+ if (result.kind === "invalid") {
140
+ const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
141
+ throw new Error(`Validation failed: ${violations}`);
142
+ }
143
+ else if (result.kind === "error") {
144
+ throw result.error;
145
+ }
118
146
  return this._client.getMarketOrder(request);
119
147
  }
120
148
  }
@@ -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)("CiltZXNodHJhZGUvd2FsbGV0L2FjY291bnQvdjEvYWNjb3VudC5wcm90bxIbbWVzaHRyYWRlLndhbGxldC5hY2NvdW50LnYxIqAGCgdBY2NvdW50EroBCgRuYW1lGAEgASgJQqsBukinAboBowEKFG5hbWUuZm9ybWF0Lm9wdGlvbmFsEjVuYW1lIG11c3QgYmUgZW1wdHkgb3IgaW4gdGhlIGZvcm1hdCBhY2NvdW50cy97VUxJRHYyfRpUc2l6ZSh0aGlzKSA9PSAwIHx8IHRoaXMubWF0Y2hlcygnXmFjY291bnRz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b3VudBgBIAEoCzIZLm1lc2h0cmFkZS50eXBlLnYxLkFtb3VudBJMChNpbnN0cnVtZW50X21ldGFkYXRhGAIgASgLMi8ubWVzaHRyYWRlLndhbGxldC5hY2NvdW50LnYxLkluc3RydW1lbnRNZXRhRGF0YSI+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)("CiltZXNodHJhZGUvd2FsbGV0L2FjY291bnQvdjEvYWNjb3VudC5wcm90bxIbbWVzaHRyYWRlLndhbGxldC5hY2NvdW50LnYxIvAGCgdBY2NvdW50EroBCgRuYW1lGAEgASgJQqsBukinAboBowEKFG5hbWUuZm9ybWF0Lm9wdGlvbmFsEjVuYW1lIG11c3QgYmUgZW1wdHkgb3IgaW4gdGhlIGZvcm1hdCBhY2NvdW50cy97VUxJRHYyfRpUc2l6ZSh0aGlzKSA9PSAwIHx8IHRoaXMubWF0Y2hlcygnXmFjY291bnRzL1swMTIzNDU2Nzg5QUJDREVGR0hKS01OUFFSU1RWV1hZWl17MjZ9JCcpEksKBW93bm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LlVuaXQiggEKB0JhbGFuY2USKQoGYW1vdW50GAEgASgLMhkubWVzaHRyYWRlLnR5cGUudjEuQW1vdW50EkwKE2luc3RydW1lbnRfbWV0YWRhdGEYAiABKAsyLy5tZXNodHJhZGUud2FsbGV0LmFjY291bnQudjEuSW5zdHJ1bWVudE1ldGFEYXRhIj4KCVNpZ25hdG9yeRIUCgxkaXNwbGF5X25hbWUYASABKAkSGwoJbGVkZ2VyX2lkGAIgASgJQgi6SAVyAxj/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.