@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.
- 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_web_meshts.d.ts +62 -7
- package/dist/meshtrade/compliance/client/v1/service_web_meshts.js +118 -28
- 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_web_meshts.d.ts +62 -7
- package/dist/meshtrade/iam/api_user/v1/service_web_meshts.js +167 -35
- 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_web_meshts.d.ts +62 -7
- package/dist/meshtrade/iam/group/v1/service_web_meshts.js +134 -30
- package/dist/meshtrade/iam/user/v1/service_web_meshts.d.ts +62 -7
- package/dist/meshtrade/iam/user/v1/service_web_meshts.js +159 -34
- 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} +23 -17
- package/dist/meshtrade/{common/connectInterceptors.js → interceptors/index.js} +61 -24
- package/dist/meshtrade/ledger/transaction/v1/service_web_meshts.d.ts +62 -7
- package/dist/meshtrade/ledger/transaction/v1/service_web_meshts.js +110 -27
- package/dist/meshtrade/market_data/price/v1/service_web_meshts.d.ts +62 -7
- package/dist/meshtrade/market_data/price/v1/service_web_meshts.js +102 -26
- package/dist/meshtrade/reporting/account_report/v1/service_web_meshts.d.ts +62 -7
- package/dist/meshtrade/reporting/account_report/v1/service_web_meshts.js +110 -27
- 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_web_meshts.d.ts +62 -7
- package/dist/meshtrade/trading/limit_order/v1/service_web_meshts.js +151 -33
- package/dist/meshtrade/trading/market_order/v1/service_web_meshts.d.ts +62 -7
- package/dist/meshtrade/trading/market_order/v1/service_web_meshts.js +102 -26
- 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_web_meshts.d.ts +62 -7
- package/dist/meshtrade/wallet/account/v1/service_web_meshts.js +167 -35
- package/package.json +19 -2
- package/dist/meshtrade/common/config.d.ts +0 -7
- package/dist/meshtrade/common/config.js +0 -9
- package/dist/meshtrade/common/validation.d.ts +0 -62
- package/dist/meshtrade/common/validation.js +0 -77
|
@@ -39,13 +39,21 @@ export type Client = Message<"meshtrade.compliance.client.v1.Client"> & {
|
|
|
39
39
|
* @generated from field: string owner = 2;
|
|
40
40
|
*/
|
|
41
41
|
owner: string;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* Ownership hiearchy of groups that have access to this resource in the format groups/{group_id}.
|
|
45
|
+
* System set on creation.
|
|
46
|
+
*
|
|
47
|
+
* @generated from field: repeated string owners = 3;
|
|
48
|
+
*/
|
|
49
|
+
owners: string[];
|
|
42
50
|
/**
|
|
43
51
|
*
|
|
44
52
|
* A non-unique, user-provided name for the client, used for display purposes
|
|
45
53
|
* in user interfaces and reports.
|
|
46
54
|
* Required on creation.
|
|
47
55
|
*
|
|
48
|
-
* @generated from field: string display_name =
|
|
56
|
+
* @generated from field: string display_name = 4;
|
|
49
57
|
*/
|
|
50
58
|
displayName: string;
|
|
51
59
|
/**
|
|
@@ -60,7 +68,7 @@ export type Client = Message<"meshtrade.compliance.client.v1.Client"> & {
|
|
|
60
68
|
*
|
|
61
69
|
* Set when the legal entity is an individual human being.
|
|
62
70
|
*
|
|
63
|
-
* @generated from field: meshtrade.compliance.client.v1.NaturalPerson natural_person =
|
|
71
|
+
* @generated from field: meshtrade.compliance.client.v1.NaturalPerson natural_person = 5;
|
|
64
72
|
*/
|
|
65
73
|
value: NaturalPerson;
|
|
66
74
|
case: "naturalPerson";
|
|
@@ -69,7 +77,7 @@ export type Client = Message<"meshtrade.compliance.client.v1.Client"> & {
|
|
|
69
77
|
*
|
|
70
78
|
* Set when the legal entity is a company or corporation.
|
|
71
79
|
*
|
|
72
|
-
* @generated from field: meshtrade.compliance.client.v1.Company company =
|
|
80
|
+
* @generated from field: meshtrade.compliance.client.v1.Company company = 6;
|
|
73
81
|
*/
|
|
74
82
|
value: Company;
|
|
75
83
|
case: "company";
|
|
@@ -78,7 +86,7 @@ export type Client = Message<"meshtrade.compliance.client.v1.Client"> & {
|
|
|
78
86
|
*
|
|
79
87
|
* Set when the legal entity is an investment fund.
|
|
80
88
|
*
|
|
81
|
-
* @generated from field: meshtrade.compliance.client.v1.Fund fund =
|
|
89
|
+
* @generated from field: meshtrade.compliance.client.v1.Fund fund = 7;
|
|
82
90
|
*/
|
|
83
91
|
value: Fund;
|
|
84
92
|
case: "fund";
|
|
@@ -87,7 +95,7 @@ export type Client = Message<"meshtrade.compliance.client.v1.Client"> & {
|
|
|
87
95
|
*
|
|
88
96
|
* Set when the legal entity is a trust.
|
|
89
97
|
*
|
|
90
|
-
* @generated from field: meshtrade.compliance.client.v1.Trust trust =
|
|
98
|
+
* @generated from field: meshtrade.compliance.client.v1.Trust trust = 8;
|
|
91
99
|
*/
|
|
92
100
|
value: Trust;
|
|
93
101
|
case: "trust";
|
|
@@ -100,7 +108,7 @@ export type Client = Message<"meshtrade.compliance.client.v1.Client"> & {
|
|
|
100
108
|
* The definitive, most recent compliance status of the client (e.g., VERIFICATION_STATUS_VERIFIED, VERIFICATION_STATUS_FAILED).
|
|
101
109
|
* Must always be a valid field
|
|
102
110
|
*
|
|
103
|
-
* @generated from field: meshtrade.compliance.client.v1.VerificationStatus verification_status =
|
|
111
|
+
* @generated from field: meshtrade.compliance.client.v1.VerificationStatus verification_status = 9;
|
|
104
112
|
*/
|
|
105
113
|
verificationStatus: VerificationStatus;
|
|
106
114
|
/**
|
|
@@ -109,7 +117,7 @@ export type Client = Message<"meshtrade.compliance.client.v1.Client"> & {
|
|
|
109
117
|
* `verification_status`. This provides an audit trail for status changes.
|
|
110
118
|
* System set when verification_status changes.
|
|
111
119
|
*
|
|
112
|
-
* @generated from field: string verification_authority =
|
|
120
|
+
* @generated from field: string verification_authority = 10;
|
|
113
121
|
*/
|
|
114
122
|
verificationAuthority: string;
|
|
115
123
|
/**
|
|
@@ -118,7 +126,7 @@ export type Client = Message<"meshtrade.compliance.client.v1.Client"> & {
|
|
|
118
126
|
* state, specifically `VERIFICATION_STATUS_VERIFIED`.
|
|
119
127
|
* System set when verification_status changes to VERIFICATION_STATUS_VERIFIED.
|
|
120
128
|
*
|
|
121
|
-
* @generated from field: google.protobuf.Timestamp verification_date =
|
|
129
|
+
* @generated from field: google.protobuf.Timestamp verification_date = 11;
|
|
122
130
|
*/
|
|
123
131
|
verificationDate?: Timestamp;
|
|
124
132
|
/**
|
|
@@ -127,7 +135,7 @@ export type Client = Message<"meshtrade.compliance.client.v1.Client"> & {
|
|
|
127
135
|
* is due. This field drives re-verification workflows.
|
|
128
136
|
* Optional for Verification.
|
|
129
137
|
*
|
|
130
|
-
* @generated from field: google.protobuf.Timestamp next_verification_date =
|
|
138
|
+
* @generated from field: google.protobuf.Timestamp next_verification_date = 12;
|
|
131
139
|
*/
|
|
132
140
|
nextVerificationDate?: Timestamp;
|
|
133
141
|
};
|
|
@@ -15,7 +15,7 @@ const verification_status_pb_1 = require("./verification_status_pb");
|
|
|
15
15
|
/**
|
|
16
16
|
* Describes the file meshtrade/compliance/client/v1/client.proto.
|
|
17
17
|
*/
|
|
18
|
-
exports.file_meshtrade_compliance_client_v1_client = (0, codegenv2_1.fileDesc)("
|
|
18
|
+
exports.file_meshtrade_compliance_client_v1_client = (0, codegenv2_1.fileDesc)("CittZXNodHJhZGUvY29tcGxpYW5jZS9jbGllbnQvdjEvY2xpZW50LnByb3RvEh5tZXNodHJhZGUuY29tcGxpYW5jZS5jbGllbnQudjEiyggKBkNsaWVudBK4AQoEbmFtZRgBIAEoCUKpAbpIpQG6AaEBChRuYW1lLmZvcm1hdC5vcHRpb25hbBI0bmFtZSBtdXN0IGJlIGVtcHR5IG9yIGluIHRoZSBmb3JtYXQgY2xpZW50cy97VUxJRHYyfRpTc2l6ZSh0aGlzKSA9PSAwIHx8IHRoaXMubWF0Y2hlcygnXmNsaWVudHMvWzAxMjM0NTY3ODlBQkNERUZHSEpLTU5QUVJTVFZXWFlaXXsyNn0kJykSSwoFb3duZXIYAiABKAlCPLpIOcgBAXI0Mi9eZ3JvdXBzL1swMTIzNDU2Nzg5QUJDREVGR0hKS01OUFFSU1RWV1hZWl17MjZ9JJgBIRJOCgZvd25lcnMYAyADKAlCPrpIO5IBOCI2cjQyL15ncm91cHMvWzAxMjM0NTY3ODlBQkNERUZHSEpLTU5QUVJTVFZXWFlaXXsyNn0kmAEhEiMKDGRpc3BsYXlfbmFtZRgEIAEoCUINukgKyAEBcgUQARj/ARJHCg5uYXR1cmFsX3BlcnNvbhgFIAEoCzItLm1lc2h0cmFkZS5jb21wbGlhbmNlLmNsaWVudC52MS5OYXR1cmFsUGVyc29uSAASOgoHY29tcGFueRgGIAEoCzInLm1lc2h0cmFkZS5jb21wbGlhbmNlLmNsaWVudC52MS5Db21wYW55SAASNAoEZnVuZBgHIAEoCzIkLm1lc2h0cmFkZS5jb21wbGlhbmNlLmNsaWVudC52MS5GdW5kSAASNgoFdHJ1c3QYCCABKAsyJS5tZXNodHJhZGUuY29tcGxpYW5jZS5jbGllbnQudjEuVHJ1c3RIABJcChN2ZXJpZmljYXRpb25fc3RhdHVzGAkgASgOMjIubWVzaHRyYWRlLmNvbXBsaWFuY2UuY2xpZW50LnYxLlZlcmlmaWNhdGlvblN0YXR1c0ILukgIyAEBggECEAES7gEKFnZlcmlmaWNhdGlvbl9hdXRob3JpdHkYCiABKAlCzQG6SMkBugHFAQomdmVyaWZpY2F0aW9uX2F1dGhvcml0eS5mb3JtYXQub3B0aW9uYWwSRnZlcmlmaWNhdGlvbl9hdXRob3JpdHkgbXVzdCBiZSBlbXB0eSBvciBpbiB0aGUgZm9ybWF0IGNsaWVudHMve1VMSUR2Mn0aU3NpemUodGhpcykgPT0gMCB8fCB0aGlzLm1hdGNoZXMoJ15jbGllbnRzL1swMTIzNDU2Nzg5QUJDREVGR0hKS01OUFFSU1RWV1hZWl17MjZ9JCcpEjUKEXZlcmlmaWNhdGlvbl9kYXRlGAsgASgLMhouZ29vZ2xlLnByb3RvYnVmLlRpbWVzdGFtcBI6ChZuZXh0X3ZlcmlmaWNhdGlvbl9kYXRlGAwgASgLMhouZ29vZ2xlLnByb3RvYnVmLlRpbWVzdGFtcEIOCgxsZWdhbF9wZXJzb25CYwolY28ubWVzaHRyYWRlLmFwaS5jb21wbGlhbmNlLmNsaWVudC52MVo6Z2l0aHViLmNvbS9tZXNodHJhZGUvYXBpL2dvL2NvbXBsaWFuY2UvY2xpZW50L3YxO2NsaWVudF92MWIGcHJvdG8z", [validate_pb_1.file_buf_validate_validate, wkt_1.file_google_protobuf_timestamp, company_pb_1.file_meshtrade_compliance_client_v1_company, fund_pb_1.file_meshtrade_compliance_client_v1_fund, natural_person_pb_1.file_meshtrade_compliance_client_v1_natural_person, trust_pb_1.file_meshtrade_compliance_client_v1_trust, verification_status_pb_1.file_meshtrade_compliance_client_v1_verification_status]);
|
|
19
19
|
/**
|
|
20
20
|
* Describes the message meshtrade.compliance.client.v1.Client.
|
|
21
21
|
* Use `create(ClientSchema)` to create a new message.
|
|
@@ -1,30 +1,85 @@
|
|
|
1
|
-
import { Interceptor } from "@connectrpc/connect";
|
|
2
1
|
import { CreateClientRequest, GetClientRequest, ListClientsRequest, ListClientsResponse } from "./service_pb";
|
|
3
2
|
import { Client } from "./client_pb";
|
|
4
|
-
import {
|
|
3
|
+
import { ClientOption } from "../../../config";
|
|
5
4
|
/**
|
|
6
5
|
* Web client for interacting with the meshtrade.compliance.client.v1 client v1 API resource service.
|
|
7
|
-
* Uses Connect-ES with gRPC-Web transport for browser-
|
|
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 ClientServiceWeb(
|
|
13
|
+
* WithServerUrl("http://localhost:10000")
|
|
14
|
+
* );
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* 2. **API Key Authentication** (backend services):
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const client = new ClientServiceWeb(
|
|
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 ClientServiceWeb(
|
|
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 ClientServiceWeb(
|
|
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 ClientServiceWeb {
|
|
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 ClientServiceWeb.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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(
|
|
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 {ClientServiceWeb} A new, configured instance of the client.
|
|
27
|
-
* @throws {Error} If the group format is invalid
|
|
82
|
+
* @throws {Error} If the group format is invalid
|
|
28
83
|
*/
|
|
29
84
|
withGroup(group: string): ClientServiceWeb;
|
|
30
85
|
/**
|
|
@@ -7,28 +7,87 @@ exports.ClientServiceWeb = 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
|
|
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
|
* Web client for interacting with the meshtrade.compliance.client.v1 client v1 API resource service.
|
|
15
|
-
* Uses Connect-ES with gRPC-Web transport for browser-
|
|
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 ClientServiceWeb(
|
|
23
|
+
* WithServerUrl("http://localhost:10000")
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* 2. **API Key Authentication** (backend services):
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const client = new ClientServiceWeb(
|
|
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 ClientServiceWeb(
|
|
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 ClientServiceWeb(
|
|
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 ClientServiceWeb {
|
|
18
60
|
/**
|
|
19
61
|
* Constructs an instance of ClientServiceWeb.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
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(
|
|
24
|
-
|
|
25
|
-
this.
|
|
26
|
-
//
|
|
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.ClientService, transport);
|
|
@@ -37,26 +96,36 @@ class ClientServiceWeb {
|
|
|
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 {ClientServiceWeb} A new, configured instance of the client.
|
|
44
|
-
* @throws {Error} If the group format is invalid
|
|
111
|
+
* @throws {Error} If the group format is invalid
|
|
45
112
|
*/
|
|
46
113
|
withGroup(group) {
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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));
|
|
52
121
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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 ClientServiceWeb(...newOpts);
|
|
60
129
|
}
|
|
61
130
|
/**
|
|
62
131
|
* Creates a new client.
|
|
@@ -65,7 +134,14 @@ class ClientServiceWeb {
|
|
|
65
134
|
*/
|
|
66
135
|
createClient(request) {
|
|
67
136
|
// Validate request
|
|
68
|
-
(
|
|
137
|
+
const result = this._validator.validate(service_pb_2.CreateClientRequestSchema, 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.createClient(request);
|
|
70
146
|
}
|
|
71
147
|
/**
|
|
@@ -75,7 +151,14 @@ class ClientServiceWeb {
|
|
|
75
151
|
*/
|
|
76
152
|
getClient(request) {
|
|
77
153
|
// Validate request
|
|
78
|
-
(
|
|
154
|
+
const result = this._validator.validate(service_pb_2.GetClientRequestSchema, 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.getClient(request);
|
|
80
163
|
}
|
|
81
164
|
/**
|
|
@@ -85,7 +168,14 @@ class ClientServiceWeb {
|
|
|
85
168
|
*/
|
|
86
169
|
listClients(request) {
|
|
87
170
|
// Validate request
|
|
88
|
-
(
|
|
171
|
+
const result = this._validator.validate(service_pb_2.ListClientsRequestSchema, 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.listClients(request);
|
|
90
180
|
}
|
|
91
181
|
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for Meshtrade API clients using functional options pattern.
|
|
3
|
+
*
|
|
4
|
+
* Supports flexible authentication modes with optional group context:
|
|
5
|
+
*
|
|
6
|
+
* 1. **No Authentication** (public APIs):
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const client = new ServiceNode(
|
|
9
|
+
* WithServerUrl("http://localhost:10000")
|
|
10
|
+
* );
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* 2. **API Key Authentication** (backend services):
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const client = new ServiceNode(
|
|
16
|
+
* WithAPIKey("your-api-key"),
|
|
17
|
+
* WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
|
|
18
|
+
* WithServerUrl("https://api.example.com")
|
|
19
|
+
* );
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* 3. **JWT Token Authentication** (Next.js backend with user session):
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const client = new ServiceNode(
|
|
25
|
+
* WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
|
|
26
|
+
* WithServerUrl("https://api.example.com")
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* 4. **JWT with Group Context** (user session with specific group):
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const client = new ServiceNode(
|
|
33
|
+
* WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
|
|
34
|
+
* WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
|
|
35
|
+
* WithServerUrl("https://api.example.com")
|
|
36
|
+
* );
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Internal configuration class used to build client configuration.
|
|
41
|
+
*/
|
|
42
|
+
export declare class ClientConfig {
|
|
43
|
+
/** API server URL (default: production) */
|
|
44
|
+
apiServerURL: string;
|
|
45
|
+
/** API key for service-to-service authentication */
|
|
46
|
+
apiKey?: string;
|
|
47
|
+
/** JWT token for user session authentication */
|
|
48
|
+
jwtToken?: string;
|
|
49
|
+
/** Group context in format "groups/{ulid}" */
|
|
50
|
+
group?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Validates the configuration.
|
|
53
|
+
* @throws {Error} If both API key and JWT token are provided (mutually exclusive)
|
|
54
|
+
*/
|
|
55
|
+
validate(): void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Client option function type for functional options pattern.
|
|
59
|
+
* Each option function modifies the ClientConfig.
|
|
60
|
+
*/
|
|
61
|
+
export type ClientOption = (config: ClientConfig) => void;
|
|
62
|
+
/**
|
|
63
|
+
* Configures the client with an API key for service-to-service authentication.
|
|
64
|
+
*
|
|
65
|
+
* **Mutually Exclusive**: Cannot be used with WithJWTAccessToken().
|
|
66
|
+
* **Optional**: Can be combined with WithGroup() for group-specific operations.
|
|
67
|
+
*
|
|
68
|
+
* @param apiKey - The API key for authentication
|
|
69
|
+
* @returns A client option function
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const client = new ServiceNode(
|
|
74
|
+
* WithAPIKey("your-api-key"),
|
|
75
|
+
* WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32")
|
|
76
|
+
* );
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function WithAPIKey(apiKey: string): ClientOption;
|
|
80
|
+
/**
|
|
81
|
+
* Configures the client with a JWT access token for user session authentication.
|
|
82
|
+
*
|
|
83
|
+
* **Mutually Exclusive**: Cannot be used with WithAPIKey().
|
|
84
|
+
* **Optional**: Can be combined with WithGroup() for group-specific operations.
|
|
85
|
+
*
|
|
86
|
+
* The JWT is injected as a cookie header (Cookie: AccessToken=<jwt>)
|
|
87
|
+
* so the server can extract it from the request.
|
|
88
|
+
*
|
|
89
|
+
* @param token - The JWT access token from the user's session
|
|
90
|
+
* @returns A client option function
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const client = new ServiceNode(
|
|
95
|
+
* WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
|
|
96
|
+
* WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32")
|
|
97
|
+
* );
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function WithJWTAccessToken(token: string): ClientOption;
|
|
101
|
+
/**
|
|
102
|
+
* Configures the client with a group context for operations.
|
|
103
|
+
*
|
|
104
|
+
* **Optional**: Can be used with WithAPIKey() or WithJWTAccessToken().
|
|
105
|
+
* When used alone without authentication, adds group header to requests.
|
|
106
|
+
*
|
|
107
|
+
* @param group - The group resource name in format "groups/{ulid}"
|
|
108
|
+
* @returns A client option function
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* // With API Key
|
|
113
|
+
* const client = new ServiceNode(
|
|
114
|
+
* WithAPIKey("your-api-key"),
|
|
115
|
+
* WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32")
|
|
116
|
+
* );
|
|
117
|
+
*
|
|
118
|
+
* // With JWT
|
|
119
|
+
* const client = new ServiceNode(
|
|
120
|
+
* WithJWTAccessToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."),
|
|
121
|
+
* WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32")
|
|
122
|
+
* );
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function WithGroup(group: string): ClientOption;
|
|
126
|
+
/**
|
|
127
|
+
* Configures the client with a custom server URL.
|
|
128
|
+
*
|
|
129
|
+
* **Optional**: If not provided, defaults to localhost:10000.
|
|
130
|
+
*
|
|
131
|
+
* @param url - The API server URL
|
|
132
|
+
* @returns A client option function
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const client = new ServiceNode(
|
|
137
|
+
* WithServerUrl("http://localhost:10000"),
|
|
138
|
+
* WithAPIKey("your-api-key"),
|
|
139
|
+
* WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32")
|
|
140
|
+
* );
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare function WithServerUrl(url: string): ClientOption;
|
|
144
|
+
/**
|
|
145
|
+
* Builds client configuration from an array of option functions.
|
|
146
|
+
*
|
|
147
|
+
* @param opts - Variable number of option functions
|
|
148
|
+
* @returns A validated ClientConfig instance
|
|
149
|
+
* @throws {Error} If configuration is invalid (e.g., both API key and JWT provided)
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const config = buildConfigFromOptions(
|
|
154
|
+
* WithAPIKey("your-api-key"),
|
|
155
|
+
* WithGroup("groups/01ARZ3NDEKTSV4YWVF8F5BH32"),
|
|
156
|
+
* WithServerUrl("https://api.example.com")
|
|
157
|
+
* );
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function buildConfigFromOptions(...opts: ClientOption[]): ClientConfig;
|