@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.
- package/dist/meshtrade/compliance/client/v1/client_pb.d.ts +17 -9
- package/dist/meshtrade/compliance/client/v1/client_pb.js +1 -1
- package/dist/meshtrade/compliance/client/v1/service_node_meshts.d.ts +46 -21
- package/dist/meshtrade/compliance/client/v1/service_node_meshts.js +98 -56
- package/dist/meshtrade/config/index.d.ts +160 -0
- package/dist/meshtrade/config/index.js +210 -0
- package/dist/meshtrade/iam/api_user/v1/api_user_pb.d.ts +12 -4
- package/dist/meshtrade/iam/api_user/v1/api_user_pb.js +1 -1
- package/dist/meshtrade/iam/api_user/v1/service_node_meshts.d.ts +46 -21
- package/dist/meshtrade/iam/api_user/v1/service_node_meshts.js +149 -65
- package/dist/meshtrade/iam/group/v1/group_pb.d.ts +8 -0
- package/dist/meshtrade/iam/group/v1/group_pb.js +1 -1
- package/dist/meshtrade/iam/group/v1/service_node_meshts.d.ts +46 -21
- package/dist/meshtrade/iam/group/v1/service_node_meshts.js +114 -58
- package/dist/meshtrade/iam/user/v1/service_node_meshts.d.ts +46 -21
- package/dist/meshtrade/iam/user/v1/service_node_meshts.js +141 -64
- package/dist/meshtrade/iam/user/v1/user_pb.d.ts +10 -2
- package/dist/meshtrade/iam/user/v1/user_pb.js +1 -1
- package/dist/meshtrade/{common/connectInterceptors.d.ts → interceptors/index.d.ts} +6 -64
- package/dist/meshtrade/{common/connectInterceptors.js → interceptors/index.js} +20 -90
- package/dist/meshtrade/ledger/transaction/v1/service_node_meshts.d.ts +46 -21
- package/dist/meshtrade/ledger/transaction/v1/service_node_meshts.js +90 -55
- package/dist/meshtrade/market_data/price/v1/service_node_meshts.d.ts +46 -21
- package/dist/meshtrade/market_data/price/v1/service_node_meshts.js +82 -54
- package/dist/meshtrade/reporting/account_report/v1/service_node_meshts.d.ts +46 -21
- package/dist/meshtrade/reporting/account_report/v1/service_node_meshts.js +90 -55
- package/dist/meshtrade/studio/instrument/v1/instrument_pb.d.ts +8 -0
- package/dist/meshtrade/studio/instrument/v1/instrument_pb.js +1 -1
- package/dist/meshtrade/trading/limit_order/v1/limit_order_pb.d.ts +16 -8
- package/dist/meshtrade/trading/limit_order/v1/limit_order_pb.js +1 -1
- package/dist/meshtrade/trading/limit_order/v1/service_node_meshts.d.ts +46 -21
- package/dist/meshtrade/trading/limit_order/v1/service_node_meshts.js +133 -63
- package/dist/meshtrade/trading/market_order/v1/service_node_meshts.d.ts +46 -21
- package/dist/meshtrade/trading/market_order/v1/service_node_meshts.js +82 -54
- package/dist/meshtrade/wallet/account/v1/account_pb.d.ts +8 -0
- package/dist/meshtrade/wallet/account/v1/account_pb.js +1 -1
- package/dist/meshtrade/wallet/account/v1/service_node_meshts.d.ts +46 -21
- package/dist/meshtrade/wallet/account/v1/service_node_meshts.js +149 -65
- package/package.json +19 -2
- package/dist/meshtrade/common/config.d.ts +0 -50
- package/dist/meshtrade/common/config.js +0 -34
- package/dist/meshtrade/common/validation.d.ts +0 -62
- package/dist/meshtrade/common/validation.js +0 -77
|
@@ -1,59 +1,84 @@
|
|
|
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 {
|
|
3
|
+
import { ClientOption } from "../../../config";
|
|
5
4
|
/**
|
|
6
5
|
* Node.js client for interacting with the meshtrade.wallet.account.v1 account v1 API resource service.
|
|
7
6
|
* Uses Connect-ES with gRPC transport for Node.js gRPC communication.
|
|
8
7
|
*
|
|
9
|
-
* Supports
|
|
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 AccountServiceNode(
|
|
12
|
+
* const client = new AccountServiceNode(
|
|
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 AccountServiceNode(
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* const client = new AccountServiceNode(
|
|
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 AccountServiceNode(
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* const client = new AccountServiceNode(
|
|
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 AccountServiceNode(
|
|
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 AccountServiceNode {
|
|
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 AccountServiceNode.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
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(
|
|
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
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
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 {AccountServiceNode} 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): AccountServiceNode;
|
|
@@ -7,62 +7,82 @@ exports.AccountServiceNode = 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
|
|
11
|
-
const
|
|
12
|
-
const
|
|
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.wallet.account.v1 account v1 API resource service.
|
|
15
16
|
* Uses Connect-ES with gRPC transport for Node.js gRPC communication.
|
|
16
17
|
*
|
|
17
|
-
* Supports
|
|
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 AccountServiceNode(
|
|
22
|
+
* const client = new AccountServiceNode(
|
|
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 AccountServiceNode(
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* const client = new AccountServiceNode(
|
|
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 AccountServiceNode(
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
38
|
+
* const client = new AccountServiceNode(
|
|
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 AccountServiceNode(
|
|
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 AccountServiceNode {
|
|
42
60
|
/**
|
|
43
61
|
* Constructs an instance of AccountServiceNode.
|
|
44
|
-
*
|
|
45
|
-
*
|
|
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(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this._interceptors
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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 AccountServiceNode {
|
|
|
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
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
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 {AccountServiceNode} 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
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return new AccountServiceNode(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 AccountServiceNode(...newOpts);
|
|
109
130
|
}
|
|
110
131
|
/**
|
|
111
132
|
* Creates a new account.
|
|
@@ -114,7 +135,14 @@ class AccountServiceNode {
|
|
|
114
135
|
*/
|
|
115
136
|
createAccount(request) {
|
|
116
137
|
// Validate request
|
|
117
|
-
(
|
|
138
|
+
const result = this._validator.validate(service_pb_2.CreateAccountRequestSchema, 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.createAccount(request);
|
|
119
147
|
}
|
|
120
148
|
/**
|
|
@@ -124,7 +152,14 @@ class AccountServiceNode {
|
|
|
124
152
|
*/
|
|
125
153
|
updateAccount(request) {
|
|
126
154
|
// Validate request
|
|
127
|
-
(
|
|
155
|
+
const result = this._validator.validate(service_pb_2.UpdateAccountRequestSchema, 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.updateAccount(request);
|
|
129
164
|
}
|
|
130
165
|
/**
|
|
@@ -134,7 +169,14 @@ class AccountServiceNode {
|
|
|
134
169
|
*/
|
|
135
170
|
openAccount(request) {
|
|
136
171
|
// Validate request
|
|
137
|
-
(
|
|
172
|
+
const result = this._validator.validate(service_pb_2.OpenAccountRequestSchema, 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.openAccount(request);
|
|
139
181
|
}
|
|
140
182
|
/**
|
|
@@ -144,7 +186,14 @@ class AccountServiceNode {
|
|
|
144
186
|
*/
|
|
145
187
|
addSignatoriesToAccount(request) {
|
|
146
188
|
// Validate request
|
|
147
|
-
(
|
|
189
|
+
const result = this._validator.validate(service_pb_2.AddSignatoriesToAccountRequestSchema, 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.addSignatoriesToAccount(request);
|
|
149
198
|
}
|
|
150
199
|
/**
|
|
@@ -154,7 +203,14 @@ class AccountServiceNode {
|
|
|
154
203
|
*/
|
|
155
204
|
removeSignatoriesFromAccount(request) {
|
|
156
205
|
// Validate request
|
|
157
|
-
(
|
|
206
|
+
const result = this._validator.validate(service_pb_2.RemoveSignatoriesFromAccountRequestSchema, 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.removeSignatoriesFromAccount(request);
|
|
159
215
|
}
|
|
160
216
|
/**
|
|
@@ -164,7 +220,14 @@ class AccountServiceNode {
|
|
|
164
220
|
*/
|
|
165
221
|
getAccount(request) {
|
|
166
222
|
// Validate request
|
|
167
|
-
(
|
|
223
|
+
const result = this._validator.validate(service_pb_2.GetAccountRequestSchema, 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.getAccount(request);
|
|
169
232
|
}
|
|
170
233
|
/**
|
|
@@ -174,7 +237,14 @@ class AccountServiceNode {
|
|
|
174
237
|
*/
|
|
175
238
|
getAccountByNumber(request) {
|
|
176
239
|
// Validate request
|
|
177
|
-
(
|
|
240
|
+
const result = this._validator.validate(service_pb_2.GetAccountByNumberRequestSchema, request);
|
|
241
|
+
if (result.kind === "invalid") {
|
|
242
|
+
const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
|
|
243
|
+
throw new Error(`Validation failed: ${violations}`);
|
|
244
|
+
}
|
|
245
|
+
else if (result.kind === "error") {
|
|
246
|
+
throw result.error;
|
|
247
|
+
}
|
|
178
248
|
return this._client.getAccountByNumber(request);
|
|
179
249
|
}
|
|
180
250
|
/**
|
|
@@ -184,7 +254,14 @@ class AccountServiceNode {
|
|
|
184
254
|
*/
|
|
185
255
|
listAccounts(request) {
|
|
186
256
|
// Validate request
|
|
187
|
-
(
|
|
257
|
+
const result = this._validator.validate(service_pb_2.ListAccountsRequestSchema, request);
|
|
258
|
+
if (result.kind === "invalid") {
|
|
259
|
+
const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
|
|
260
|
+
throw new Error(`Validation failed: ${violations}`);
|
|
261
|
+
}
|
|
262
|
+
else if (result.kind === "error") {
|
|
263
|
+
throw result.error;
|
|
264
|
+
}
|
|
188
265
|
return this._client.listAccounts(request);
|
|
189
266
|
}
|
|
190
267
|
/**
|
|
@@ -194,7 +271,14 @@ class AccountServiceNode {
|
|
|
194
271
|
*/
|
|
195
272
|
searchAccounts(request) {
|
|
196
273
|
// Validate request
|
|
197
|
-
(
|
|
274
|
+
const result = this._validator.validate(service_pb_2.SearchAccountsRequestSchema, request);
|
|
275
|
+
if (result.kind === "invalid") {
|
|
276
|
+
const violations = result.violations.map(v => `${v.field.toString()}: ${v.message}`).join("; ");
|
|
277
|
+
throw new Error(`Validation failed: ${violations}`);
|
|
278
|
+
}
|
|
279
|
+
else if (result.kind === "error") {
|
|
280
|
+
throw result.error;
|
|
281
|
+
}
|
|
198
282
|
return this._client.searchAccounts(request);
|
|
199
283
|
}
|
|
200
284
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshtrade/api-node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.0",
|
|
4
4
|
"description": "Mesh Typescript Node SDK",
|
|
5
5
|
"author": "Bernard Bussy <bernard@meshtrade.co>",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -81,6 +81,16 @@
|
|
|
81
81
|
"require": "./dist/meshtrade/option/v1/index.js",
|
|
82
82
|
"import": "./dist/meshtrade/option/v1/index.js"
|
|
83
83
|
},
|
|
84
|
+
"./config": {
|
|
85
|
+
"types": "./dist/meshtrade/config/index.d.ts",
|
|
86
|
+
"require": "./dist/meshtrade/config/index.js",
|
|
87
|
+
"import": "./dist/meshtrade/config/index.js"
|
|
88
|
+
},
|
|
89
|
+
"./interceptors": {
|
|
90
|
+
"types": "./dist/meshtrade/interceptors/index.d.ts",
|
|
91
|
+
"require": "./dist/meshtrade/interceptors/index.js",
|
|
92
|
+
"import": "./dist/meshtrade/interceptors/index.js"
|
|
93
|
+
},
|
|
84
94
|
"./*": {
|
|
85
95
|
"types": "./dist/meshtrade/*",
|
|
86
96
|
"require": "./dist/meshtrade/*",
|
|
@@ -128,6 +138,12 @@
|
|
|
128
138
|
"option/v1": [
|
|
129
139
|
"dist/meshtrade/option/v1/index.d.ts"
|
|
130
140
|
],
|
|
141
|
+
"config": [
|
|
142
|
+
"dist/meshtrade/config/index.d.ts"
|
|
143
|
+
],
|
|
144
|
+
"interceptors": [
|
|
145
|
+
"dist/meshtrade/interceptors/index.d.ts"
|
|
146
|
+
],
|
|
131
147
|
"*": [
|
|
132
148
|
"dist/meshtrade/*"
|
|
133
149
|
]
|
|
@@ -138,6 +154,7 @@
|
|
|
138
154
|
],
|
|
139
155
|
"dependencies": {
|
|
140
156
|
"@bufbuild/protobuf": "^2.10.1",
|
|
157
|
+
"@bufbuild/protovalidate": "^1.0.0",
|
|
141
158
|
"@connectrpc/connect": "^2.1.0",
|
|
142
159
|
"@connectrpc/connect-node": "^2.1.0",
|
|
143
160
|
"bignumber.js": "^9.3.0"
|
|
@@ -159,7 +176,7 @@
|
|
|
159
176
|
},
|
|
160
177
|
"scripts": {
|
|
161
178
|
"clean": "rimraf ./dist",
|
|
162
|
-
"build:ts": "tsc",
|
|
179
|
+
"build:ts": "tsc --project tsconfig.build.json",
|
|
163
180
|
"build": "yarn run clean && yarn run build:ts",
|
|
164
181
|
"lint": "eslint . --ext .ts",
|
|
165
182
|
"test": "jest"
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration options for Meshtrade API clients.
|
|
3
|
-
*
|
|
4
|
-
* Supports three authentication modes:
|
|
5
|
-
*
|
|
6
|
-
* 1. **No Authentication** (public APIs):
|
|
7
|
-
* ```typescript
|
|
8
|
-
* const client = new ServiceNode({ apiServerURL: "http://localhost:10000" });
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* 2. **API Key Authentication** (backend services):
|
|
12
|
-
* ```typescript
|
|
13
|
-
* const client = new ServiceNode({
|
|
14
|
-
* apiServerURL: "https://api.example.com",
|
|
15
|
-
* apiKey: "your-api-key",
|
|
16
|
-
* group: "groups/01ARZ3NDEKTSV4YWVF8F5BH32"
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* 3. **JWT Token Authentication** (Next.js backend with user session):
|
|
21
|
-
* ```typescript
|
|
22
|
-
* const client = new ServiceNode({
|
|
23
|
-
* apiServerURL: "https://api.example.com",
|
|
24
|
-
* jwtToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
25
|
-
* });
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export type ConfigOpts = {
|
|
29
|
-
/** API server URL (default: "http://localhost:10000") */
|
|
30
|
-
apiServerURL?: string;
|
|
31
|
-
/** API key for service-to-service authentication (requires group) */
|
|
32
|
-
apiKey?: string;
|
|
33
|
-
/** Group context for API key authentication in format "groups/{ulid}" */
|
|
34
|
-
group?: string;
|
|
35
|
-
/** JWT token for user session authentication (injected as AccessToken cookie) */
|
|
36
|
-
jwtToken?: string;
|
|
37
|
-
};
|
|
38
|
-
export type Config = {
|
|
39
|
-
apiServerURL: string;
|
|
40
|
-
apiKey?: string;
|
|
41
|
-
group?: string;
|
|
42
|
-
jwtToken?: string;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Validates and creates configuration from options.
|
|
46
|
-
*
|
|
47
|
-
* @throws {Error} If API key is provided without group, or vice versa
|
|
48
|
-
* @throws {Error} If both API key and JWT token are provided (mutually exclusive)
|
|
49
|
-
*/
|
|
50
|
-
export declare function getConfigFromOpts(config?: ConfigOpts): Config;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConfigFromOpts = getConfigFromOpts;
|
|
4
|
-
/**
|
|
5
|
-
* Validates and creates configuration from options.
|
|
6
|
-
*
|
|
7
|
-
* @throws {Error} If API key is provided without group, or vice versa
|
|
8
|
-
* @throws {Error} If both API key and JWT token are provided (mutually exclusive)
|
|
9
|
-
*/
|
|
10
|
-
function getConfigFromOpts(config) {
|
|
11
|
-
const apiServerURL = config?.apiServerURL ?? "http://localhost:10000";
|
|
12
|
-
const apiKey = config?.apiKey;
|
|
13
|
-
const group = config?.group;
|
|
14
|
-
const jwtToken = config?.jwtToken;
|
|
15
|
-
// Validate authentication configuration
|
|
16
|
-
if (apiKey && jwtToken) {
|
|
17
|
-
throw new Error("API key and JWT token authentication are mutually exclusive. " +
|
|
18
|
-
"Please provide either apiKey+group OR jwtToken, not both.");
|
|
19
|
-
}
|
|
20
|
-
if (apiKey && !group) {
|
|
21
|
-
throw new Error("API key authentication requires a group. " +
|
|
22
|
-
"Please provide both 'apiKey' and 'group' options.");
|
|
23
|
-
}
|
|
24
|
-
if (group && !apiKey) {
|
|
25
|
-
throw new Error("Group context requires API key authentication. " +
|
|
26
|
-
"Please provide both 'apiKey' and 'group' options.");
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
apiServerURL,
|
|
30
|
-
apiKey,
|
|
31
|
-
group,
|
|
32
|
-
jwtToken,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic validation utilities for Meshtrade API resource names and identifiers.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Validates if a string is a valid ULID (Universally Unique Lexicographically Sortable Identifier).
|
|
6
|
-
*
|
|
7
|
-
* Note: This implementation uses a simplified character set for ULIDs that includes
|
|
8
|
-
* all uppercase letters A-Z and digits 0-9, unlike the standard ULID specification
|
|
9
|
-
* which excludes certain ambiguous characters (I, L, O, U).
|
|
10
|
-
*
|
|
11
|
-
* ULIDs in this system are 26-character identifiers that are:
|
|
12
|
-
* - Lexicographically sortable
|
|
13
|
-
* - Uppercase alphanumeric only
|
|
14
|
-
* - Contain timestamp information for natural ordering
|
|
15
|
-
*
|
|
16
|
-
* @param ulid - The string to validate as a ULID
|
|
17
|
-
* @returns true if the string is a valid ULID format, false otherwise
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* isValidULID('01ARZ3NDEKTSV4YWVF8F5BH32'); // true
|
|
22
|
-
* isValidULID('invalid'); // false
|
|
23
|
-
* isValidULID('01arz3ndektsv4ywvf8f5bh32'); // false (lowercase)
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare function isValidULID(ulid: string): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Validates if a resource name follows the groups/{ulid} format.
|
|
29
|
-
*
|
|
30
|
-
* Group resource names in the Meshtrade API follow the pattern "groups/{ulid}"
|
|
31
|
-
* where {ulid} is a 26-character ULID identifier.
|
|
32
|
-
*
|
|
33
|
-
* @param resourceName - The resource name string to validate
|
|
34
|
-
* @returns true if the resource name is a valid group resource name, false otherwise
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* isValidGroupResourceName('groups/01ARZ3NDEKTSV4YWVF8F5BH32'); // true
|
|
39
|
-
* isValidGroupResourceName('groups/invalid'); // false
|
|
40
|
-
* isValidGroupResourceName('users/01ARZ3NDEKTSV4YWVF8F5BH32'); // false
|
|
41
|
-
* isValidGroupResourceName('01ARZ3NDEKTSV4YWVF8F5BH32'); // false
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare function isValidGroupResourceName(resourceName: string): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Validates a protobuf request message before sending to the server.
|
|
47
|
-
*
|
|
48
|
-
* This function serves as a client-side validation hook that can be extended
|
|
49
|
-
* to include protovalidate integration or other validation logic.
|
|
50
|
-
*
|
|
51
|
-
* Currently performs basic null/undefined checks. Future enhancements may include
|
|
52
|
-
* protovalidate integration for comprehensive message validation.
|
|
53
|
-
*
|
|
54
|
-
* @param request - The protobuf request message to validate
|
|
55
|
-
* @throws {Error} If the request is null or undefined
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```typescript
|
|
59
|
-
* validateRequest(myRequest); // Throws if request is invalid
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export declare function validateRequest(request: unknown): void;
|