@meshtrade/api-node 1.30.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 (186) hide show
  1. package/README.md +93 -0
  2. package/dist/buf/validate/validate_pb.d.ts +4597 -0
  3. package/dist/buf/validate/validate_pb.js +354 -0
  4. package/dist/google/type/date_pb.d.ts +52 -0
  5. package/dist/google/type/date_pb.js +26 -0
  6. package/dist/meshtrade/common/config.d.ts +50 -0
  7. package/dist/meshtrade/common/config.js +34 -0
  8. package/dist/meshtrade/common/connectInterceptors.d.ts +137 -0
  9. package/dist/meshtrade/common/connectInterceptors.js +233 -0
  10. package/dist/meshtrade/common/validation.d.ts +62 -0
  11. package/dist/meshtrade/common/validation.js +77 -0
  12. package/dist/meshtrade/compliance/client/v1/client_pb.d.ts +138 -0
  13. package/dist/meshtrade/compliance/client/v1/client_pb.js +23 -0
  14. package/dist/meshtrade/compliance/client/v1/company_pb.d.ts +313 -0
  15. package/dist/meshtrade/compliance/client/v1/company_pb.js +100 -0
  16. package/dist/meshtrade/compliance/client/v1/company_representative_pb.d.ts +81 -0
  17. package/dist/meshtrade/compliance/client/v1/company_representative_pb.js +22 -0
  18. package/dist/meshtrade/compliance/client/v1/company_representative_role_pb.d.ts +88 -0
  19. package/dist/meshtrade/compliance/client/v1/company_representative_role_pb.js +95 -0
  20. package/dist/meshtrade/compliance/client/v1/fund_pb.d.ts +65 -0
  21. package/dist/meshtrade/compliance/client/v1/fund_pb.js +18 -0
  22. package/dist/meshtrade/compliance/client/v1/identification_document_type_pb.d.ts +55 -0
  23. package/dist/meshtrade/compliance/client/v1/identification_document_type_pb.js +62 -0
  24. package/dist/meshtrade/compliance/client/v1/index.d.ts +16 -0
  25. package/dist/meshtrade/compliance/client/v1/index.js +59 -0
  26. package/dist/meshtrade/compliance/client/v1/industry_classification_pb.d.ts +86 -0
  27. package/dist/meshtrade/compliance/client/v1/industry_classification_pb.js +16 -0
  28. package/dist/meshtrade/compliance/client/v1/natural_person_connection_type_pb.d.ts +133 -0
  29. package/dist/meshtrade/compliance/client/v1/natural_person_connection_type_pb.js +140 -0
  30. package/dist/meshtrade/compliance/client/v1/natural_person_pb.d.ts +143 -0
  31. package/dist/meshtrade/compliance/client/v1/natural_person_pb.js +24 -0
  32. package/dist/meshtrade/compliance/client/v1/pep_status_pb.d.ts +46 -0
  33. package/dist/meshtrade/compliance/client/v1/pep_status_pb.js +53 -0
  34. package/dist/meshtrade/compliance/client/v1/service_node_meshts.d.ts +78 -0
  35. package/dist/meshtrade/compliance/client/v1/service_node_meshts.js +141 -0
  36. package/dist/meshtrade/compliance/client/v1/service_pb.d.ts +123 -0
  37. package/dist/meshtrade/compliance/client/v1/service_pb.js +45 -0
  38. package/dist/meshtrade/compliance/client/v1/source_of_income_and_wealth_pb.d.ts +180 -0
  39. package/dist/meshtrade/compliance/client/v1/source_of_income_and_wealth_pb.js +187 -0
  40. package/dist/meshtrade/compliance/client/v1/tax_residency_pb.d.ts +40 -0
  41. package/dist/meshtrade/compliance/client/v1/tax_residency_pb.js +17 -0
  42. package/dist/meshtrade/compliance/client/v1/trust_pb.d.ts +65 -0
  43. package/dist/meshtrade/compliance/client/v1/trust_pb.js +18 -0
  44. package/dist/meshtrade/compliance/client/v1/verification_status_pb.d.ts +57 -0
  45. package/dist/meshtrade/compliance/client/v1/verification_status_pb.js +64 -0
  46. package/dist/meshtrade/iam/api_user/v1/api_credentials_pb.d.ts +43 -0
  47. package/dist/meshtrade/iam/api_user/v1/api_credentials_pb.js +17 -0
  48. package/dist/meshtrade/iam/api_user/v1/api_user_pb.d.ts +152 -0
  49. package/dist/meshtrade/iam/api_user/v1/api_user_pb.js +95 -0
  50. package/dist/meshtrade/iam/api_user/v1/index.d.ts +4 -0
  51. package/dist/meshtrade/iam/api_user/v1/index.js +45 -0
  52. package/dist/meshtrade/iam/api_user/v1/service_node_meshts.d.ts +114 -0
  53. package/dist/meshtrade/iam/api_user/v1/service_node_meshts.js +201 -0
  54. package/dist/meshtrade/iam/api_user/v1/service_pb.d.ts +343 -0
  55. package/dist/meshtrade/iam/api_user/v1/service_pb.js +86 -0
  56. package/dist/meshtrade/iam/group/v1/group_pb.d.ts +58 -0
  57. package/dist/meshtrade/iam/group/v1/group_pb.js +17 -0
  58. package/dist/meshtrade/iam/group/v1/index.d.ts +3 -0
  59. package/dist/meshtrade/iam/group/v1/index.js +44 -0
  60. package/dist/meshtrade/iam/group/v1/service_node_meshts.d.ts +90 -0
  61. package/dist/meshtrade/iam/group/v1/service_node_meshts.js +161 -0
  62. package/dist/meshtrade/iam/group/v1/service_pb.d.ts +306 -0
  63. package/dist/meshtrade/iam/group/v1/service_pb.js +75 -0
  64. package/dist/meshtrade/iam/role/v1/index.d.ts +2 -0
  65. package/dist/meshtrade/iam/role/v1/index.js +43 -0
  66. package/dist/meshtrade/iam/role/v1/role.d.ts +71 -0
  67. package/dist/meshtrade/iam/role/v1/role.js +192 -0
  68. package/dist/meshtrade/iam/role/v1/role_pb.d.ts +164 -0
  69. package/dist/meshtrade/iam/role/v1/role_pb.js +171 -0
  70. package/dist/meshtrade/iam/user/v1/index.d.ts +3 -0
  71. package/dist/meshtrade/iam/user/v1/index.js +44 -0
  72. package/dist/meshtrade/iam/user/v1/service_node_meshts.d.ts +108 -0
  73. package/dist/meshtrade/iam/user/v1/service_node_meshts.js +191 -0
  74. package/dist/meshtrade/iam/user/v1/service_pb.d.ts +379 -0
  75. package/dist/meshtrade/iam/user/v1/service_pb.js +90 -0
  76. package/dist/meshtrade/iam/user/v1/user_pb.d.ts +58 -0
  77. package/dist/meshtrade/iam/user/v1/user_pb.js +17 -0
  78. package/dist/meshtrade/ledger/transaction/v1/index.d.ts +5 -0
  79. package/dist/meshtrade/ledger/transaction/v1/index.js +46 -0
  80. package/dist/meshtrade/ledger/transaction/v1/service_node_meshts.d.ts +80 -0
  81. package/dist/meshtrade/ledger/transaction/v1/service_node_meshts.js +140 -0
  82. package/dist/meshtrade/ledger/transaction/v1/service_pb.d.ts +102 -0
  83. package/dist/meshtrade/ledger/transaction/v1/service_pb.js +41 -0
  84. package/dist/meshtrade/ledger/transaction/v1/transaction_action_pb.d.ts +46 -0
  85. package/dist/meshtrade/ledger/transaction/v1/transaction_action_pb.js +53 -0
  86. package/dist/meshtrade/ledger/transaction/v1/transaction_state.d.ts +14 -0
  87. package/dist/meshtrade/ledger/transaction/v1/transaction_state.js +64 -0
  88. package/dist/meshtrade/ledger/transaction/v1/transaction_state_pb.d.ts +50 -0
  89. package/dist/meshtrade/ledger/transaction/v1/transaction_state_pb.js +57 -0
  90. package/dist/meshtrade/market_data/price/v1/index.d.ts +3 -0
  91. package/dist/meshtrade/market_data/price/v1/index.js +44 -0
  92. package/dist/meshtrade/market_data/price/v1/price_pb.d.ts +50 -0
  93. package/dist/meshtrade/market_data/price/v1/price_pb.js +19 -0
  94. package/dist/meshtrade/market_data/price/v1/service_node_meshts.d.ts +66 -0
  95. package/dist/meshtrade/market_data/price/v1/service_node_meshts.js +121 -0
  96. package/dist/meshtrade/market_data/price/v1/service_pb.d.ts +48 -0
  97. package/dist/meshtrade/market_data/price/v1/service_pb.js +27 -0
  98. package/dist/meshtrade/option/method_options/v1/index.d.ts +1 -0
  99. package/dist/meshtrade/option/method_options/v1/index.js +42 -0
  100. package/dist/meshtrade/option/method_options/v1/method_options_pb.d.ts +132 -0
  101. package/dist/meshtrade/option/method_options/v1/method_options_pb.js +108 -0
  102. package/dist/meshtrade/reporting/account_report/v1/account_report_pb.d.ts +136 -0
  103. package/dist/meshtrade/reporting/account_report/v1/account_report_pb.js +28 -0
  104. package/dist/meshtrade/reporting/account_report/v1/disclaimer_pb.d.ts +39 -0
  105. package/dist/meshtrade/reporting/account_report/v1/disclaimer_pb.js +16 -0
  106. package/dist/meshtrade/reporting/account_report/v1/fee_entry_pb.d.ts +66 -0
  107. package/dist/meshtrade/reporting/account_report/v1/fee_entry_pb.js +18 -0
  108. package/dist/meshtrade/reporting/account_report/v1/income_entry_pb.d.ts +139 -0
  109. package/dist/meshtrade/reporting/account_report/v1/income_entry_pb.js +80 -0
  110. package/dist/meshtrade/reporting/account_report/v1/index.d.ts +7 -0
  111. package/dist/meshtrade/reporting/account_report/v1/index.js +48 -0
  112. package/dist/meshtrade/reporting/account_report/v1/service_node_meshts.d.ts +72 -0
  113. package/dist/meshtrade/reporting/account_report/v1/service_node_meshts.js +131 -0
  114. package/dist/meshtrade/reporting/account_report/v1/service_pb.d.ts +162 -0
  115. package/dist/meshtrade/reporting/account_report/v1/service_pb.js +46 -0
  116. package/dist/meshtrade/reporting/account_report/v1/trading_statement_entry_pb.d.ts +80 -0
  117. package/dist/meshtrade/reporting/account_report/v1/trading_statement_entry_pb.js +18 -0
  118. package/dist/meshtrade/studio/instrument/v1/index.d.ts +3 -0
  119. package/dist/meshtrade/studio/instrument/v1/index.js +44 -0
  120. package/dist/meshtrade/studio/instrument/v1/instrument_pb.d.ts +53 -0
  121. package/dist/meshtrade/studio/instrument/v1/instrument_pb.js +18 -0
  122. package/dist/meshtrade/studio/instrument/v1/instrument_type_pb.d.ts +214 -0
  123. package/dist/meshtrade/studio/instrument/v1/instrument_type_pb.js +221 -0
  124. package/dist/meshtrade/studio/instrument/v1/unit_pb.d.ts +148 -0
  125. package/dist/meshtrade/studio/instrument/v1/unit_pb.js +155 -0
  126. package/dist/meshtrade/trading/limit_order/v1/index.d.ts +3 -0
  127. package/dist/meshtrade/trading/limit_order/v1/index.js +44 -0
  128. package/dist/meshtrade/trading/limit_order/v1/limit_order_pb.d.ts +211 -0
  129. package/dist/meshtrade/trading/limit_order/v1/limit_order_pb.js +111 -0
  130. package/dist/meshtrade/trading/limit_order/v1/service_node_meshts.d.ts +111 -0
  131. package/dist/meshtrade/trading/limit_order/v1/service_node_meshts.js +190 -0
  132. package/dist/meshtrade/trading/limit_order/v1/service_pb.d.ts +357 -0
  133. package/dist/meshtrade/trading/limit_order/v1/service_pb.js +73 -0
  134. package/dist/meshtrade/trading/market_order/v1/index.d.ts +3 -0
  135. package/dist/meshtrade/trading/market_order/v1/index.js +44 -0
  136. package/dist/meshtrade/trading/market_order/v1/market_order_pb.d.ts +20 -0
  137. package/dist/meshtrade/trading/market_order/v1/market_order_pb.js +16 -0
  138. package/dist/meshtrade/trading/market_order/v1/service_node_meshts.d.ts +66 -0
  139. package/dist/meshtrade/trading/market_order/v1/service_node_meshts.js +121 -0
  140. package/dist/meshtrade/trading/market_order/v1/service_pb.d.ts +34 -0
  141. package/dist/meshtrade/trading/market_order/v1/service_pb.js +22 -0
  142. package/dist/meshtrade/type/v1/address_pb.d.ts +82 -0
  143. package/dist/meshtrade/type/v1/address_pb.js +16 -0
  144. package/dist/meshtrade/type/v1/amount.d.ts +13 -0
  145. package/dist/meshtrade/type/v1/amount.js +68 -0
  146. package/dist/meshtrade/type/v1/amountWrapper.d.ts +74 -0
  147. package/dist/meshtrade/type/v1/amountWrapper.js +98 -0
  148. package/dist/meshtrade/type/v1/amount_pb.d.ts +44 -0
  149. package/dist/meshtrade/type/v1/amount_pb.js +18 -0
  150. package/dist/meshtrade/type/v1/contact_details_pb.d.ts +98 -0
  151. package/dist/meshtrade/type/v1/contact_details_pb.js +16 -0
  152. package/dist/meshtrade/type/v1/date.d.ts +49 -0
  153. package/dist/meshtrade/type/v1/date.js +136 -0
  154. package/dist/meshtrade/type/v1/date_pb.d.ts +50 -0
  155. package/dist/meshtrade/type/v1/date_pb.js +16 -0
  156. package/dist/meshtrade/type/v1/decimalConversions.d.ts +24 -0
  157. package/dist/meshtrade/type/v1/decimalConversions.js +39 -0
  158. package/dist/meshtrade/type/v1/decimal_pb.d.ts +24 -0
  159. package/dist/meshtrade/type/v1/decimal_pb.js +16 -0
  160. package/dist/meshtrade/type/v1/index.d.ts +15 -0
  161. package/dist/meshtrade/type/v1/index.js +56 -0
  162. package/dist/meshtrade/type/v1/ledger.d.ts +27 -0
  163. package/dist/meshtrade/type/v1/ledger.js +115 -0
  164. package/dist/meshtrade/type/v1/ledger_pb.d.ts +83 -0
  165. package/dist/meshtrade/type/v1/ledger_pb.js +90 -0
  166. package/dist/meshtrade/type/v1/sorting_pb.d.ts +35 -0
  167. package/dist/meshtrade/type/v1/sorting_pb.js +42 -0
  168. package/dist/meshtrade/type/v1/time_of_day.d.ts +74 -0
  169. package/dist/meshtrade/type/v1/time_of_day.js +199 -0
  170. package/dist/meshtrade/type/v1/time_of_day_pb.d.ts +67 -0
  171. package/dist/meshtrade/type/v1/time_of_day_pb.js +16 -0
  172. package/dist/meshtrade/type/v1/token.d.ts +4 -0
  173. package/dist/meshtrade/type/v1/token.js +23 -0
  174. package/dist/meshtrade/type/v1/tokenWrapper.d.ts +49 -0
  175. package/dist/meshtrade/type/v1/tokenWrapper.js +92 -0
  176. package/dist/meshtrade/type/v1/token_pb.d.ts +56 -0
  177. package/dist/meshtrade/type/v1/token_pb.js +17 -0
  178. package/dist/meshtrade/wallet/account/v1/account_pb.d.ts +264 -0
  179. package/dist/meshtrade/wallet/account/v1/account_pb.js +74 -0
  180. package/dist/meshtrade/wallet/account/v1/index.d.ts +3 -0
  181. package/dist/meshtrade/wallet/account/v1/index.js +44 -0
  182. package/dist/meshtrade/wallet/account/v1/service_node_meshts.d.ts +114 -0
  183. package/dist/meshtrade/wallet/account/v1/service_node_meshts.js +201 -0
  184. package/dist/meshtrade/wallet/account/v1/service_pb.d.ts +559 -0
  185. package/dist/meshtrade/wallet/account/v1/service_pb.js +112 -0
  186. package/package.json +171 -0
@@ -0,0 +1,34 @@
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
+ }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Connect-ES interceptors for the Meshtrade API client.
3
+ *
4
+ * Provides interceptor utilities for use with @connectrpc/connect clients,
5
+ * including authentication (API key, JWT) and group context injection for
6
+ * multi-tenant operations.
7
+ */
8
+ import { Interceptor } from "@connectrpc/connect";
9
+ /**
10
+ * Creates a Connect-ES interceptor that injects operating group context
11
+ * into API requests by adding an `x-group` header.
12
+ *
13
+ * The group context determines the scope of operations and resource access
14
+ * within the Meshtrade platform's hierarchical group ownership model.
15
+ *
16
+ * This interceptor validates that the provided group follows the correct
17
+ * resource name format: `groups/{ulid}` where {ulid} is a 26-character
18
+ * ULID (Universally Unique Lexicographically Sortable Identifier).
19
+ *
20
+ * @param group - The group resource name in the format `groups/{ulid}` where
21
+ * {ulid} is a 26-character ULID identifier. This determines
22
+ * the operating group context for all API requests.
23
+ * @returns An interceptor function that adds the group header to all requests
24
+ * @throws {Error} If the group format is invalid
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // Create an interceptor with a valid group resource name
29
+ * const groupInterceptor = createGroupInterceptor('groups/01ARZ3NDEKTSV4YWVF8F5BH32');
30
+ *
31
+ * // Use with a Connect-ES client
32
+ * const transport = createGrpcWebTransport({
33
+ * baseUrl: 'https://api.example.com',
34
+ * interceptors: [groupInterceptor]
35
+ * });
36
+ *
37
+ * const client = createPromiseClient(MyService, transport);
38
+ * ```
39
+ */
40
+ export declare function createGroupInterceptor(group: string): Interceptor & {
41
+ groupContext: string;
42
+ };
43
+ /**
44
+ * Creates a Connect-ES interceptor that injects API key authentication
45
+ * into API requests by adding `x-api-key` and `x-group` headers.
46
+ *
47
+ * This authentication mode is used for service-to-service communication
48
+ * where a backend service authenticates using an API key and operates
49
+ * within a specific group context.
50
+ *
51
+ * Both the API key and group are required and validated. The group must
52
+ * follow the resource name format: `groups/{ulid}` where {ulid} is a
53
+ * 26-character ULID.
54
+ *
55
+ * @param apiKey - The API key for authentication
56
+ * @param group - The group resource name in format `groups/{ulid}`
57
+ * @returns An interceptor function that adds authentication headers to all requests
58
+ * @throws {Error} If apiKey is empty or group format is invalid
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const authInterceptor = createApiKeyInterceptor(
63
+ * 'your-api-key',
64
+ * 'groups/01ARZ3NDEKTSV4YWVF8F5BH32'
65
+ * );
66
+ *
67
+ * const transport = createGrpcTransport({
68
+ * baseUrl: 'https://api.example.com',
69
+ * interceptors: [authInterceptor]
70
+ * });
71
+ * ```
72
+ */
73
+ export declare function createApiKeyInterceptor(apiKey: string, group: string): Interceptor & {
74
+ apiKeyAuth: true;
75
+ groupContext: string;
76
+ };
77
+ /**
78
+ * Creates a Connect-ES interceptor that injects JWT token authentication
79
+ * into API requests by adding a `Cookie` header with the AccessToken.
80
+ *
81
+ * This authentication mode is used in Next.js backends where the server
82
+ * has access to the user's JWT token from their browser session. The JWT
83
+ * is injected as a cookie so the server can extract it in the same way
84
+ * it would from a browser request.
85
+ *
86
+ * The JWT token is added as: `Cookie: AccessToken=<jwt>`
87
+ *
88
+ * This allows the server-side authentication middleware to extract it as:
89
+ * ```go
90
+ * if cookieHeader := request.Attributes.Request.Http.Headers["cookie"]; cookieHeader != "" {
91
+ * cookies := parseHTTPCookies(cookieHeader)
92
+ * for _, cookie := range cookies {
93
+ * if cookie.Name == "AccessToken" && cookie.Value != "" {
94
+ * authContext.AccessToken = cookie.Value
95
+ * break
96
+ * }
97
+ * }
98
+ * }
99
+ * ```
100
+ *
101
+ * @param jwtToken - The JWT token from the user's session
102
+ * @returns An interceptor function that adds the JWT as a cookie header
103
+ * @throws {Error} If jwtToken is empty
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * // In a Next.js API route
108
+ * const authInterceptor = createJwtInterceptor(
109
+ * 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
110
+ * );
111
+ *
112
+ * const transport = createGrpcTransport({
113
+ * baseUrl: 'https://api.example.com',
114
+ * interceptors: [authInterceptor]
115
+ * });
116
+ * ```
117
+ */
118
+ export declare function createJwtInterceptor(jwtToken: string): Interceptor & {
119
+ jwtAuth: true;
120
+ };
121
+ /**
122
+ * Creates a logging interceptor that logs all requests and responses.
123
+ * Useful for debugging and development.
124
+ *
125
+ * @returns An interceptor function that logs request/response details
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const loggingInterceptor = createLoggingInterceptor();
130
+ *
131
+ * const transport = createGrpcWebTransport({
132
+ * baseUrl: 'https://api.example.com',
133
+ * interceptors: [loggingInterceptor]
134
+ * });
135
+ * ```
136
+ */
137
+ export declare function createLoggingInterceptor(): Interceptor;
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ /**
3
+ * Connect-ES interceptors for the Meshtrade API client.
4
+ *
5
+ * Provides interceptor utilities for use with @connectrpc/connect clients,
6
+ * including authentication (API key, JWT) and group context injection for
7
+ * multi-tenant operations.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.createGroupInterceptor = createGroupInterceptor;
11
+ exports.createApiKeyInterceptor = createApiKeyInterceptor;
12
+ exports.createJwtInterceptor = createJwtInterceptor;
13
+ exports.createLoggingInterceptor = createLoggingInterceptor;
14
+ const validation_1 = require("./validation");
15
+ /**
16
+ * HTTP header names for authentication.
17
+ * Must match the server-side header constants.
18
+ */
19
+ const API_KEY_HEADER = "x-api-key";
20
+ const GROUP_HEADER = "x-group";
21
+ const COOKIE_HEADER = "cookie";
22
+ const ACCESS_TOKEN_COOKIE_NAME = "AccessToken";
23
+ /**
24
+ * Creates a Connect-ES interceptor that injects operating group context
25
+ * into API requests by adding an `x-group` header.
26
+ *
27
+ * The group context determines the scope of operations and resource access
28
+ * within the Meshtrade platform's hierarchical group ownership model.
29
+ *
30
+ * This interceptor validates that the provided group follows the correct
31
+ * resource name format: `groups/{ulid}` where {ulid} is a 26-character
32
+ * ULID (Universally Unique Lexicographically Sortable Identifier).
33
+ *
34
+ * @param group - The group resource name in the format `groups/{ulid}` where
35
+ * {ulid} is a 26-character ULID identifier. This determines
36
+ * the operating group context for all API requests.
37
+ * @returns An interceptor function that adds the group header to all requests
38
+ * @throws {Error} If the group format is invalid
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * // Create an interceptor with a valid group resource name
43
+ * const groupInterceptor = createGroupInterceptor('groups/01ARZ3NDEKTSV4YWVF8F5BH32');
44
+ *
45
+ * // Use with a Connect-ES client
46
+ * const transport = createGrpcWebTransport({
47
+ * baseUrl: 'https://api.example.com',
48
+ * interceptors: [groupInterceptor]
49
+ * });
50
+ *
51
+ * const client = createPromiseClient(MyService, transport);
52
+ * ```
53
+ */
54
+ function createGroupInterceptor(group) {
55
+ // Validate the group resource name format
56
+ if (!(0, validation_1.isValidGroupResourceName)(group)) {
57
+ throw new Error(`Invalid group format: "${group}". Group must be in the format "groups/{ulid}" ` +
58
+ `where {ulid} is a 26-character ULID (e.g., "groups/01ARZ3NDEKTSV4YWVF8F5BH32").`);
59
+ }
60
+ // Create the interceptor function
61
+ const interceptor = (next) => async (req) => {
62
+ // Add the x-group header to the request
63
+ req.header.set("x-group", group);
64
+ // Call the next interceptor in the chain
65
+ return await next(req);
66
+ };
67
+ // Add a marker property so we can identify group interceptors
68
+ // This is used in the withGroup method to prevent double-setting
69
+ return Object.assign(interceptor, { groupContext: group });
70
+ }
71
+ /**
72
+ * Creates a Connect-ES interceptor that injects API key authentication
73
+ * into API requests by adding `x-api-key` and `x-group` headers.
74
+ *
75
+ * This authentication mode is used for service-to-service communication
76
+ * where a backend service authenticates using an API key and operates
77
+ * within a specific group context.
78
+ *
79
+ * Both the API key and group are required and validated. The group must
80
+ * follow the resource name format: `groups/{ulid}` where {ulid} is a
81
+ * 26-character ULID.
82
+ *
83
+ * @param apiKey - The API key for authentication
84
+ * @param group - The group resource name in format `groups/{ulid}`
85
+ * @returns An interceptor function that adds authentication headers to all requests
86
+ * @throws {Error} If apiKey is empty or group format is invalid
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const authInterceptor = createApiKeyInterceptor(
91
+ * 'your-api-key',
92
+ * 'groups/01ARZ3NDEKTSV4YWVF8F5BH32'
93
+ * );
94
+ *
95
+ * const transport = createGrpcTransport({
96
+ * baseUrl: 'https://api.example.com',
97
+ * interceptors: [authInterceptor]
98
+ * });
99
+ * ```
100
+ */
101
+ function createApiKeyInterceptor(apiKey, group) {
102
+ // Validate inputs
103
+ if (!apiKey || apiKey.trim() === "") {
104
+ throw new Error("API key cannot be empty");
105
+ }
106
+ if (!(0, validation_1.isValidGroupResourceName)(group)) {
107
+ throw new Error(`Invalid group format: "${group}". Group must be in the format "groups/{ulid}" ` +
108
+ `where {ulid} is a 26-character ULID (e.g., "groups/01ARZ3NDEKTSV4YWVF8F5BH32").`);
109
+ }
110
+ // Create the interceptor function
111
+ const interceptor = (next) => async (req) => {
112
+ // Add authentication headers to the request
113
+ req.header.set(API_KEY_HEADER, apiKey);
114
+ req.header.set(GROUP_HEADER, group);
115
+ // Call the next interceptor in the chain
116
+ return await next(req);
117
+ };
118
+ // Add marker properties for identification
119
+ return Object.assign(interceptor, {
120
+ apiKeyAuth: true,
121
+ groupContext: group,
122
+ });
123
+ }
124
+ /**
125
+ * Creates a Connect-ES interceptor that injects JWT token authentication
126
+ * into API requests by adding a `Cookie` header with the AccessToken.
127
+ *
128
+ * This authentication mode is used in Next.js backends where the server
129
+ * has access to the user's JWT token from their browser session. The JWT
130
+ * is injected as a cookie so the server can extract it in the same way
131
+ * it would from a browser request.
132
+ *
133
+ * The JWT token is added as: `Cookie: AccessToken=<jwt>`
134
+ *
135
+ * This allows the server-side authentication middleware to extract it as:
136
+ * ```go
137
+ * if cookieHeader := request.Attributes.Request.Http.Headers["cookie"]; cookieHeader != "" {
138
+ * cookies := parseHTTPCookies(cookieHeader)
139
+ * for _, cookie := range cookies {
140
+ * if cookie.Name == "AccessToken" && cookie.Value != "" {
141
+ * authContext.AccessToken = cookie.Value
142
+ * break
143
+ * }
144
+ * }
145
+ * }
146
+ * ```
147
+ *
148
+ * @param jwtToken - The JWT token from the user's session
149
+ * @returns An interceptor function that adds the JWT as a cookie header
150
+ * @throws {Error} If jwtToken is empty
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // In a Next.js API route
155
+ * const authInterceptor = createJwtInterceptor(
156
+ * 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
157
+ * );
158
+ *
159
+ * const transport = createGrpcTransport({
160
+ * baseUrl: 'https://api.example.com',
161
+ * interceptors: [authInterceptor]
162
+ * });
163
+ * ```
164
+ */
165
+ function createJwtInterceptor(jwtToken) {
166
+ // Validate input
167
+ if (!jwtToken || jwtToken.trim() === "") {
168
+ throw new Error("JWT token cannot be empty");
169
+ }
170
+ // Create the interceptor function
171
+ const interceptor = (next) => async (req) => {
172
+ // Add JWT as a cookie header
173
+ // Format: "Cookie: AccessToken=<jwt>"
174
+ const cookieValue = `${ACCESS_TOKEN_COOKIE_NAME}=${jwtToken}`;
175
+ req.header.set(COOKIE_HEADER, cookieValue);
176
+ // Call the next interceptor in the chain
177
+ return await next(req);
178
+ };
179
+ // Add marker property for identification
180
+ return Object.assign(interceptor, { jwtAuth: true });
181
+ }
182
+ /**
183
+ * Creates a logging interceptor that logs all requests and responses.
184
+ * Useful for debugging and development.
185
+ *
186
+ * @returns An interceptor function that logs request/response details
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const loggingInterceptor = createLoggingInterceptor();
191
+ *
192
+ * const transport = createGrpcWebTransport({
193
+ * baseUrl: 'https://api.example.com',
194
+ * interceptors: [loggingInterceptor]
195
+ * });
196
+ * ```
197
+ */
198
+ function createLoggingInterceptor() {
199
+ return (next) => async (req) => {
200
+ // Convert headers to plain object for logging
201
+ const headers = {};
202
+ req.header.forEach((value, key) => {
203
+ headers[key] = value;
204
+ });
205
+ // Log the request
206
+ console.log(`[Connect] ${req.method.name} request:`, {
207
+ service: req.service.typeName,
208
+ method: req.method.name,
209
+ headers,
210
+ });
211
+ try {
212
+ // Call the next interceptor and get the response
213
+ const response = await next(req);
214
+ // Log successful response
215
+ console.log(`[Connect] ${req.method.name} response:`, {
216
+ service: req.service.typeName,
217
+ method: req.method.name,
218
+ status: "success",
219
+ });
220
+ return response;
221
+ }
222
+ catch (error) {
223
+ // Log error
224
+ console.error(`[Connect] ${req.method.name} error:`, {
225
+ service: req.service.typeName,
226
+ method: req.method.name,
227
+ error: error,
228
+ });
229
+ // Re-throw the error
230
+ throw error;
231
+ }
232
+ };
233
+ }
@@ -0,0 +1,62 @@
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;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /**
3
+ * Generic validation utilities for Meshtrade API resource names and identifiers.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isValidULID = isValidULID;
7
+ exports.isValidGroupResourceName = isValidGroupResourceName;
8
+ exports.validateRequest = validateRequest;
9
+ /**
10
+ * Validates if a string is a valid ULID (Universally Unique Lexicographically Sortable Identifier).
11
+ *
12
+ * Note: This implementation uses a simplified character set for ULIDs that includes
13
+ * all uppercase letters A-Z and digits 0-9, unlike the standard ULID specification
14
+ * which excludes certain ambiguous characters (I, L, O, U).
15
+ *
16
+ * ULIDs in this system are 26-character identifiers that are:
17
+ * - Lexicographically sortable
18
+ * - Uppercase alphanumeric only
19
+ * - Contain timestamp information for natural ordering
20
+ *
21
+ * @param ulid - The string to validate as a ULID
22
+ * @returns true if the string is a valid ULID format, false otherwise
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * isValidULID('01ARZ3NDEKTSV4YWVF8F5BH32'); // true
27
+ * isValidULID('invalid'); // false
28
+ * isValidULID('01arz3ndektsv4ywvf8f5bh32'); // false (lowercase)
29
+ * ```
30
+ */
31
+ function isValidULID(ulid) {
32
+ return /^[0-9A-Z]{26}$/.test(ulid);
33
+ }
34
+ /**
35
+ * Validates if a resource name follows the groups/{ulid} format.
36
+ *
37
+ * Group resource names in the Meshtrade API follow the pattern "groups/{ulid}"
38
+ * where {ulid} is a 26-character ULID identifier.
39
+ *
40
+ * @param resourceName - The resource name string to validate
41
+ * @returns true if the resource name is a valid group resource name, false otherwise
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * isValidGroupResourceName('groups/01ARZ3NDEKTSV4YWVF8F5BH32'); // true
46
+ * isValidGroupResourceName('groups/invalid'); // false
47
+ * isValidGroupResourceName('users/01ARZ3NDEKTSV4YWVF8F5BH32'); // false
48
+ * isValidGroupResourceName('01ARZ3NDEKTSV4YWVF8F5BH32'); // false
49
+ * ```
50
+ */
51
+ function isValidGroupResourceName(resourceName) {
52
+ return /^groups\/[0-9A-Z]{26}$/.test(resourceName);
53
+ }
54
+ /**
55
+ * Validates a protobuf request message before sending to the server.
56
+ *
57
+ * This function serves as a client-side validation hook that can be extended
58
+ * to include protovalidate integration or other validation logic.
59
+ *
60
+ * Currently performs basic null/undefined checks. Future enhancements may include
61
+ * protovalidate integration for comprehensive message validation.
62
+ *
63
+ * @param request - The protobuf request message to validate
64
+ * @throws {Error} If the request is null or undefined
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * validateRequest(myRequest); // Throws if request is invalid
69
+ * ```
70
+ */
71
+ function validateRequest(request) {
72
+ if (request === null || request === undefined) {
73
+ throw new Error("Request cannot be null or undefined");
74
+ }
75
+ // Future: Integrate protovalidate for comprehensive message validation
76
+ // For now, basic validation is sufficient as the server also validates
77
+ }
@@ -0,0 +1,138 @@
1
+ import type { GenFile, GenMessage } from "@bufbuild/protobuf/codegenv2";
2
+ import type { Timestamp } from "@bufbuild/protobuf/wkt";
3
+ import type { Company } from "./company_pb";
4
+ import type { Fund } from "./fund_pb";
5
+ import type { NaturalPerson } from "./natural_person_pb";
6
+ import type { Trust } from "./trust_pb";
7
+ import type { VerificationStatus } from "./verification_status_pb";
8
+ import type { Message } from "@bufbuild/protobuf";
9
+ /**
10
+ * Describes the file meshtrade/compliance/client/v1/client.proto.
11
+ */
12
+ export declare const file_meshtrade_compliance_client_v1_client: GenFile;
13
+ /**
14
+ *
15
+ * Client represents an authorized legal entity, which can be either an individual (KYC)
16
+ * or a business (KYB). It serves as the central resource for all compliance information
17
+ * and verification status related to a single party.
18
+ *
19
+ * @generated from message meshtrade.compliance.client.v1.Client
20
+ */
21
+ export type Client = Message<"meshtrade.compliance.client.v1.Client"> & {
22
+ /**
23
+ *
24
+ * The unique, immutable, and canonical name of the client resource in the format clients/{client_id}.
25
+ * The {client_id} is a system-generated unique identifier (e.g., UUID) that will never change. This name field will never change and should be used as the permanent primary key for this resource in all systems.
26
+ * System set on creation.
27
+ *
28
+ * @generated from field: string name = 1;
29
+ */
30
+ name: string;
31
+ /**
32
+ *
33
+ * The resource name of the group that owns this client in the format groups/{group_id}.
34
+ * This field establishes the ownership link and can be updated if the client's ownership changes,
35
+ * without affecting the client's stable `name`.
36
+ * The executing user needs to have permission to perform client.Create in this group.
37
+ * Required on creation.
38
+ *
39
+ * @generated from field: string owner = 2;
40
+ */
41
+ owner: string;
42
+ /**
43
+ *
44
+ * A non-unique, user-provided name for the client, used for display purposes
45
+ * in user interfaces and reports.
46
+ * Required on creation.
47
+ *
48
+ * @generated from field: string display_name = 3;
49
+ */
50
+ displayName: string;
51
+ /**
52
+ *
53
+ * Contains the specific data for the legal entity type.
54
+ * Only one of these may be set at a time.
55
+ *
56
+ * @generated from oneof meshtrade.compliance.client.v1.Client.legal_person
57
+ */
58
+ legalPerson: {
59
+ /**
60
+ *
61
+ * Set when the legal entity is an individual human being.
62
+ *
63
+ * @generated from field: meshtrade.compliance.client.v1.NaturalPerson natural_person = 4;
64
+ */
65
+ value: NaturalPerson;
66
+ case: "naturalPerson";
67
+ } | {
68
+ /**
69
+ *
70
+ * Set when the legal entity is a company or corporation.
71
+ *
72
+ * @generated from field: meshtrade.compliance.client.v1.Company company = 5;
73
+ */
74
+ value: Company;
75
+ case: "company";
76
+ } | {
77
+ /**
78
+ *
79
+ * Set when the legal entity is an investment fund.
80
+ *
81
+ * @generated from field: meshtrade.compliance.client.v1.Fund fund = 6;
82
+ */
83
+ value: Fund;
84
+ case: "fund";
85
+ } | {
86
+ /**
87
+ *
88
+ * Set when the legal entity is a trust.
89
+ *
90
+ * @generated from field: meshtrade.compliance.client.v1.Trust trust = 7;
91
+ */
92
+ value: Trust;
93
+ case: "trust";
94
+ } | {
95
+ case: undefined;
96
+ value?: undefined;
97
+ };
98
+ /**
99
+ *
100
+ * The definitive, most recent compliance status of the client (e.g., VERIFICATION_STATUS_VERIFIED, VERIFICATION_STATUS_FAILED).
101
+ * Must always be a valid field
102
+ *
103
+ * @generated from field: meshtrade.compliance.client.v1.VerificationStatus verification_status = 8;
104
+ */
105
+ verificationStatus: VerificationStatus;
106
+ /**
107
+ *
108
+ * The resource name of the client (acting as a verifier) that last set the
109
+ * `verification_status`. This provides an audit trail for status changes.
110
+ * System set when verification_status changes.
111
+ *
112
+ * @generated from field: string verification_authority = 9;
113
+ */
114
+ verificationAuthority: string;
115
+ /**
116
+ *
117
+ * The timestamp when the `verification_status` was last set to a conclusive
118
+ * state, specifically `VERIFICATION_STATUS_VERIFIED`.
119
+ * System set when verification_status changes to VERIFICATION_STATUS_VERIFIED.
120
+ *
121
+ * @generated from field: google.protobuf.Timestamp verification_date = 10;
122
+ */
123
+ verificationDate?: Timestamp;
124
+ /**
125
+ *
126
+ * The timestamp indicating when the client's next periodic compliance review
127
+ * is due. This field drives re-verification workflows.
128
+ * Optional for Verification.
129
+ *
130
+ * @generated from field: google.protobuf.Timestamp next_verification_date = 11;
131
+ */
132
+ nextVerificationDate?: Timestamp;
133
+ };
134
+ /**
135
+ * Describes the message meshtrade.compliance.client.v1.Client.
136
+ * Use `create(ClientSchema)` to create a new message.
137
+ */
138
+ export declare const ClientSchema: GenMessage<Client>;