@woodger/t-invest-node-sdk 0.5.2 → 0.5.4

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 (229) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/{THIRD_PARTY_NOTICES.md → LICENSE-APACHE-2.0} +1 -106
  3. package/NOTICE +98 -0
  4. package/dist/application/services/unary-limiter.d.ts +10 -1
  5. package/dist/application/services/unary-limiter.js +35 -11
  6. package/dist/bootstrap/args/sdk-options.d.ts +1 -2
  7. package/dist/bootstrap/cli/help-catalog.d.ts +733 -0
  8. package/dist/bootstrap/cli/help-catalog.js +1649 -0
  9. package/dist/bootstrap/cli/help.d.ts +2 -730
  10. package/dist/bootstrap/cli/help.js +5 -1647
  11. package/dist/bootstrap/cli/registry.d.ts +6 -6
  12. package/dist/bootstrap/commands/accounts/cli.d.ts +2 -3
  13. package/dist/bootstrap/commands/accounts/cli.js +5 -10
  14. package/dist/bootstrap/commands/accrued-interests/cli.d.ts +2 -3
  15. package/dist/bootstrap/commands/accrued-interests/cli.js +5 -10
  16. package/dist/bootstrap/commands/asset/cli.d.ts +2 -3
  17. package/dist/bootstrap/commands/asset/cli.js +5 -10
  18. package/dist/bootstrap/commands/assets/cli.d.ts +2 -3
  19. package/dist/bootstrap/commands/assets/cli.js +5 -10
  20. package/dist/bootstrap/commands/bond/cli.d.ts +2 -3
  21. package/dist/bootstrap/commands/bond/cli.js +5 -10
  22. package/dist/bootstrap/commands/bond-coupons/cli.d.ts +2 -3
  23. package/dist/bootstrap/commands/bond-coupons/cli.js +5 -10
  24. package/dist/bootstrap/commands/bonds/cli.d.ts +2 -3
  25. package/dist/bootstrap/commands/bonds/cli.js +5 -10
  26. package/dist/bootstrap/commands/brand/cli.d.ts +2 -3
  27. package/dist/bootstrap/commands/brand/cli.js +5 -10
  28. package/dist/bootstrap/commands/brands/cli.d.ts +2 -3
  29. package/dist/bootstrap/commands/brands/cli.js +5 -10
  30. package/dist/bootstrap/commands/broker-report/cli.d.ts +2 -3
  31. package/dist/bootstrap/commands/broker-report/cli.js +5 -10
  32. package/dist/bootstrap/commands/cancel-order/cli.d.ts +3 -39
  33. package/dist/bootstrap/commands/cancel-order/cli.js +8 -19
  34. package/dist/bootstrap/commands/cancel-order/request.mapper.d.ts +7 -0
  35. package/dist/bootstrap/commands/cancel-order/request.mapper.js +9 -0
  36. package/dist/bootstrap/commands/cancel-stop-order/cli.d.ts +3 -4
  37. package/dist/bootstrap/commands/cancel-stop-order/cli.js +6 -11
  38. package/dist/bootstrap/commands/candles/cli.d.ts +3 -4
  39. package/dist/bootstrap/commands/candles/cli.js +6 -11
  40. package/dist/bootstrap/commands/close-prices/cli.d.ts +3 -4
  41. package/dist/bootstrap/commands/close-prices/cli.js +6 -11
  42. package/dist/bootstrap/commands/countries/cli.d.ts +2 -3
  43. package/dist/bootstrap/commands/countries/cli.js +5 -10
  44. package/dist/bootstrap/commands/currencies/cli.d.ts +2 -3
  45. package/dist/bootstrap/commands/currencies/cli.js +5 -10
  46. package/dist/bootstrap/commands/currency/cli.d.ts +2 -3
  47. package/dist/bootstrap/commands/currency/cli.js +5 -10
  48. package/dist/bootstrap/commands/dividends/cli.d.ts +2 -3
  49. package/dist/bootstrap/commands/dividends/cli.js +5 -10
  50. package/dist/bootstrap/commands/dividends-foreign-issuer/cli.d.ts +2 -3
  51. package/dist/bootstrap/commands/dividends-foreign-issuer/cli.js +5 -10
  52. package/dist/bootstrap/commands/edit-favorites/cli.d.ts +2 -3
  53. package/dist/bootstrap/commands/edit-favorites/cli.js +5 -10
  54. package/dist/bootstrap/commands/etf/cli.d.ts +2 -3
  55. package/dist/bootstrap/commands/etf/cli.js +5 -10
  56. package/dist/bootstrap/commands/etfs/cli.d.ts +2 -3
  57. package/dist/bootstrap/commands/etfs/cli.js +5 -10
  58. package/dist/bootstrap/commands/favorites/cli.d.ts +2 -3
  59. package/dist/bootstrap/commands/favorites/cli.js +5 -10
  60. package/dist/bootstrap/commands/find-instrument/cli.d.ts +2 -3
  61. package/dist/bootstrap/commands/find-instrument/cli.js +5 -10
  62. package/dist/bootstrap/commands/future/cli.d.ts +2 -3
  63. package/dist/bootstrap/commands/future/cli.js +5 -10
  64. package/dist/bootstrap/commands/futures/cli.d.ts +2 -3
  65. package/dist/bootstrap/commands/futures/cli.js +5 -10
  66. package/dist/bootstrap/commands/futures-margin/cli.d.ts +2 -3
  67. package/dist/bootstrap/commands/futures-margin/cli.js +5 -10
  68. package/dist/bootstrap/commands/instrument/cli.d.ts +2 -3
  69. package/dist/bootstrap/commands/instrument/cli.js +5 -10
  70. package/dist/bootstrap/commands/last-prices/cli.d.ts +3 -4
  71. package/dist/bootstrap/commands/last-prices/cli.js +6 -11
  72. package/dist/bootstrap/commands/last-trades/cli.d.ts +3 -4
  73. package/dist/bootstrap/commands/last-trades/cli.js +6 -11
  74. package/dist/bootstrap/commands/margin-attributes/cli.d.ts +2 -3
  75. package/dist/bootstrap/commands/margin-attributes/cli.js +5 -10
  76. package/dist/bootstrap/commands/operations/cli.d.ts +5 -53
  77. package/dist/bootstrap/commands/operations/cli.js +9 -36
  78. package/dist/bootstrap/commands/operations/request.mapper.d.ts +23 -0
  79. package/dist/bootstrap/commands/operations/request.mapper.js +33 -0
  80. package/dist/bootstrap/commands/operations-by-cursor/cli.d.ts +5 -69
  81. package/dist/bootstrap/commands/operations-by-cursor/cli.js +9 -74
  82. package/dist/bootstrap/commands/operations-by-cursor/request.mapper.d.ts +28 -0
  83. package/dist/bootstrap/commands/operations-by-cursor/request.mapper.js +70 -0
  84. package/dist/bootstrap/commands/option/cli.d.ts +2 -3
  85. package/dist/bootstrap/commands/option/cli.js +5 -10
  86. package/dist/bootstrap/commands/options-by/cli.d.ts +2 -3
  87. package/dist/bootstrap/commands/options-by/cli.js +5 -10
  88. package/dist/bootstrap/commands/order-book/cli.d.ts +3 -4
  89. package/dist/bootstrap/commands/order-book/cli.js +6 -11
  90. package/dist/bootstrap/commands/order-state/cli.d.ts +3 -36
  91. package/dist/bootstrap/commands/order-state/cli.js +8 -21
  92. package/dist/bootstrap/commands/order-state/request.mapper.d.ts +13 -0
  93. package/dist/bootstrap/commands/order-state/request.mapper.js +17 -0
  94. package/dist/bootstrap/commands/orders/cli.d.ts +3 -32
  95. package/dist/bootstrap/commands/orders/cli.js +8 -18
  96. package/dist/bootstrap/commands/orders/request.mapper.d.ts +6 -0
  97. package/dist/bootstrap/commands/orders/request.mapper.js +8 -0
  98. package/dist/bootstrap/commands/portfolio/cli.d.ts +6 -40
  99. package/dist/bootstrap/commands/portfolio/cli.js +9 -26
  100. package/dist/bootstrap/commands/portfolio/request.mapper.d.ts +18 -0
  101. package/dist/bootstrap/commands/portfolio/request.mapper.js +21 -0
  102. package/dist/bootstrap/commands/positions/cli.d.ts +3 -32
  103. package/dist/bootstrap/commands/positions/cli.js +8 -18
  104. package/dist/bootstrap/commands/positions/request.mapper.d.ts +6 -0
  105. package/dist/bootstrap/commands/positions/request.mapper.js +8 -0
  106. package/dist/bootstrap/commands/post-order/cli.d.ts +8 -68
  107. package/dist/bootstrap/commands/post-order/cli.js +9 -39
  108. package/dist/bootstrap/commands/post-order/request.mapper.d.ts +27 -0
  109. package/dist/bootstrap/commands/post-order/request.mapper.js +35 -0
  110. package/dist/bootstrap/commands/post-stop-order/cli.d.ts +3 -4
  111. package/dist/bootstrap/commands/post-stop-order/cli.js +6 -11
  112. package/dist/bootstrap/commands/replace-order/cli.d.ts +5 -61
  113. package/dist/bootstrap/commands/replace-order/cli.js +9 -30
  114. package/dist/bootstrap/commands/replace-order/request.mapper.d.ts +22 -0
  115. package/dist/bootstrap/commands/replace-order/request.mapper.js +26 -0
  116. package/dist/bootstrap/commands/sandbox-accounts/cli.d.ts +2 -3
  117. package/dist/bootstrap/commands/sandbox-accounts/cli.js +5 -10
  118. package/dist/bootstrap/commands/sandbox-cancel-order/cli.d.ts +3 -4
  119. package/dist/bootstrap/commands/sandbox-cancel-order/cli.js +8 -13
  120. package/dist/bootstrap/commands/sandbox-close-account/cli.d.ts +2 -3
  121. package/dist/bootstrap/commands/sandbox-close-account/cli.js +5 -10
  122. package/dist/bootstrap/commands/sandbox-open-account/cli.d.ts +2 -3
  123. package/dist/bootstrap/commands/sandbox-open-account/cli.js +5 -10
  124. package/dist/bootstrap/commands/sandbox-operations/cli.d.ts +3 -4
  125. package/dist/bootstrap/commands/sandbox-operations/cli.js +8 -13
  126. package/dist/bootstrap/commands/sandbox-operations-by-cursor/cli.d.ts +3 -4
  127. package/dist/bootstrap/commands/sandbox-operations-by-cursor/cli.js +8 -13
  128. package/dist/bootstrap/commands/sandbox-order-state/cli.d.ts +3 -4
  129. package/dist/bootstrap/commands/sandbox-order-state/cli.js +8 -13
  130. package/dist/bootstrap/commands/sandbox-orders/cli.d.ts +3 -4
  131. package/dist/bootstrap/commands/sandbox-orders/cli.js +8 -13
  132. package/dist/bootstrap/commands/sandbox-pay-in/cli.d.ts +2 -3
  133. package/dist/bootstrap/commands/sandbox-pay-in/cli.js +5 -10
  134. package/dist/bootstrap/commands/sandbox-portfolio/cli.d.ts +3 -4
  135. package/dist/bootstrap/commands/sandbox-portfolio/cli.js +8 -13
  136. package/dist/bootstrap/commands/sandbox-positions/cli.d.ts +3 -4
  137. package/dist/bootstrap/commands/sandbox-positions/cli.js +8 -13
  138. package/dist/bootstrap/commands/sandbox-post-order/cli.d.ts +3 -4
  139. package/dist/bootstrap/commands/sandbox-post-order/cli.js +8 -13
  140. package/dist/bootstrap/commands/sandbox-replace-order/cli.d.ts +3 -4
  141. package/dist/bootstrap/commands/sandbox-replace-order/cli.js +8 -13
  142. package/dist/bootstrap/commands/sandbox-withdraw-limits/cli.d.ts +3 -4
  143. package/dist/bootstrap/commands/sandbox-withdraw-limits/cli.js +8 -13
  144. package/dist/bootstrap/commands/sdk-command-lifecycle.d.ts +15 -0
  145. package/dist/bootstrap/commands/sdk-command-lifecycle.js +21 -0
  146. package/dist/bootstrap/commands/share/cli.d.ts +2 -3
  147. package/dist/bootstrap/commands/share/cli.js +5 -10
  148. package/dist/bootstrap/commands/shares/cli.d.ts +2 -3
  149. package/dist/bootstrap/commands/shares/cli.js +5 -10
  150. package/dist/bootstrap/commands/stop-orders/cli.d.ts +3 -4
  151. package/dist/bootstrap/commands/stop-orders/cli.js +6 -11
  152. package/dist/bootstrap/commands/stream-run/cli.d.ts +2 -24
  153. package/dist/bootstrap/commands/stream-run/cli.js +7 -142
  154. package/dist/bootstrap/commands/stream-run/config.d.ts +7 -15
  155. package/dist/bootstrap/commands/stream-run/config.js +1 -101
  156. package/dist/bootstrap/commands/stream-run/request.mapper.d.ts +14 -0
  157. package/dist/bootstrap/commands/stream-run/request.mapper.js +111 -0
  158. package/dist/bootstrap/commands/stream-run/stream-session.d.ts +37 -0
  159. package/dist/bootstrap/commands/stream-run/stream-session.js +152 -0
  160. package/dist/bootstrap/commands/trading-schedules/cli.d.ts +2 -3
  161. package/dist/bootstrap/commands/trading-schedules/cli.js +5 -10
  162. package/dist/bootstrap/commands/trading-status/cli.d.ts +3 -4
  163. package/dist/bootstrap/commands/trading-status/cli.js +6 -11
  164. package/dist/bootstrap/commands/trading-statuses/cli.d.ts +3 -4
  165. package/dist/bootstrap/commands/trading-statuses/cli.js +6 -11
  166. package/dist/bootstrap/commands/user-info/cli.d.ts +2 -3
  167. package/dist/bootstrap/commands/user-info/cli.js +5 -10
  168. package/dist/bootstrap/commands/user-tariff/cli.d.ts +2 -3
  169. package/dist/bootstrap/commands/user-tariff/cli.js +5 -10
  170. package/dist/bootstrap/commands/withdraw-limits/cli.d.ts +3 -32
  171. package/dist/bootstrap/commands/withdraw-limits/cli.js +8 -18
  172. package/dist/bootstrap/commands/withdraw-limits/request.mapper.d.ts +6 -0
  173. package/dist/bootstrap/commands/withdraw-limits/request.mapper.js +8 -0
  174. package/dist/bootstrap/index.js +2 -2
  175. package/dist/bootstrap/proto/compile-proto.d.ts +1 -1
  176. package/dist/bootstrap/proto/compile-proto.js +28 -35
  177. package/dist/bootstrap/t-invest-node-sdk.d.ts +9 -9
  178. package/dist/bootstrap/t-invest-node-sdk.js +33 -18
  179. package/dist/bootstrap/unary-limit-config.js +4 -4
  180. package/dist/generated/common.js +2 -2
  181. package/dist/generated/google/api/field_behavior.js +2 -2
  182. package/dist/generated/google/protobuf/descriptor.js +2 -2
  183. package/dist/generated/google/protobuf/timestamp.js +2 -2
  184. package/dist/generated/instruments.js +2 -2
  185. package/dist/generated/marketdata.js +2 -2
  186. package/dist/generated/operations.js +2 -2
  187. package/dist/generated/orders.js +2 -2
  188. package/dist/generated/sandbox.js +2 -2
  189. package/dist/generated/signals.js +2 -2
  190. package/dist/generated/stoporders.js +2 -2
  191. package/dist/generated/users.js +2 -2
  192. package/dist/index.d.ts +1 -1
  193. package/dist/infrastructure/interceptor/warning-interceptor.d.ts +1 -1
  194. package/dist/infrastructure/interceptor/warning-interceptor.js +2 -2
  195. package/dist/infrastructure/transport/grpc/sdk-call-error.d.ts +12 -0
  196. package/dist/infrastructure/transport/grpc/sdk-call-error.js +180 -0
  197. package/dist/infrastructure/transport/grpc/sdk-client.d.ts +1 -1
  198. package/dist/infrastructure/transport/grpc/sdk-client.js +2 -2
  199. package/dist/infrastructure/transport/grpc/sdk-middleware.d.ts +1 -1
  200. package/dist/infrastructure/transport/grpc/sdk-middleware.js +8 -174
  201. package/dist/infrastructure/transport/grpc/unary-limit-resolver.d.ts +3 -1
  202. package/dist/infrastructure/transport/grpc/unary-limit-resolver.js +19 -18
  203. package/docs/architecture.md +45 -42
  204. package/docs/bundled-ca.md +12 -12
  205. package/docs/clean-architecture/adapters.md +15 -15
  206. package/docs/clean-architecture/api-commands.md +63 -52
  207. package/docs/clean-architecture/application.md +13 -13
  208. package/docs/clean-architecture/cli-output-boundaries.md +23 -23
  209. package/docs/clean-architecture/dto.md +9 -9
  210. package/docs/clean-architecture/index.md +13 -12
  211. package/docs/cli-stream-configuration.md +9 -9
  212. package/docs/cli-stream-reference.md +11 -11
  213. package/docs/guides/custom-unary-limiter.md +44 -30
  214. package/docs/guides/errors-and-lifecycle.md +10 -10
  215. package/docs/guides/getting-started.md +9 -9
  216. package/docs/guides/index.md +3 -3
  217. package/docs/guides/streams-and-cancellation.md +6 -6
  218. package/docs/guides/testing-with-service-definitions.md +4 -4
  219. package/docs/guides/unary-calls.md +8 -8
  220. package/docs/index.md +14 -10
  221. package/docs/limits-policy.md +10 -10
  222. package/docs/roadmap.md +14 -14
  223. package/docs/tls-policy.md +7 -7
  224. package/package.json +6 -5
  225. package/readme.md +37 -85
  226. package/dist/infrastructure/interceptor/index.d.ts +0 -1
  227. package/dist/infrastructure/interceptor/index.js +0 -17
  228. /package/dist/infrastructure/transport/grpc/{unary-limits.d.ts → unary-method-path.d.ts} +0 -0
  229. /package/dist/infrastructure/transport/grpc/{unary-limits.js → unary-method-path.js} +0 -0
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.12.2
5
- // protoc v3.19.6
4
+ // protoc-gen-ts_proto v2.12.3
5
+ // protoc v7.36.0
6
6
  // source: sandbox.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.SandboxServiceDefinition = exports.SandboxPayInResponse = exports.SandboxPayInRequest = exports.CloseSandboxAccountResponse = exports.CloseSandboxAccountRequest = exports.OpenSandboxAccountResponse = exports.OpenSandboxAccountRequest = exports.protobufPackage = void 0;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.12.2
5
- // protoc v3.19.6
4
+ // protoc-gen-ts_proto v2.12.3
5
+ // protoc v7.36.0
6
6
  // source: signals.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.SignalServiceDefinition = exports.Signal = exports.GetSignalsResponse = exports.GetSignalsRequest = exports.Strategy = exports.GetStrategiesResponse = exports.GetStrategiesRequest = exports.SignalState = exports.SignalDirection = exports.StrategyType = exports.protobufPackage = void 0;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.12.2
5
- // protoc v3.19.6
4
+ // protoc-gen-ts_proto v2.12.3
5
+ // protoc v7.36.0
6
6
  // source: stoporders.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.StopOrdersServiceDefinition = exports.StopOrder_TrailingData = exports.StopOrder = exports.CancelStopOrderResponse = exports.CancelStopOrderRequest = exports.GetStopOrdersResponse = exports.GetStopOrdersRequest = exports.PostStopOrderResponse = exports.PostStopOrderRequest_TrailingData = exports.PostStopOrderRequest = exports.TrailingStopStatus = exports.TrailingValueType = exports.TakeProfitType = exports.ExchangeOrderType = exports.StopOrderStatusOption = exports.StopOrderType = exports.StopOrderExpirationType = exports.StopOrderDirection = exports.protobufPackage = void 0;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
3
3
  // versions:
4
- // protoc-gen-ts_proto v2.12.2
5
- // protoc v3.19.6
4
+ // protoc-gen-ts_proto v2.12.3
5
+ // protoc v7.36.0
6
6
  // source: users.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.UsersServiceDefinition = exports.InstrumentParameter = exports.AccountValuesWithParameters = exports.GetAccountValuesResponse = exports.GetAccountValuesRequest = exports.PayInResponse = exports.PayInRequest = exports.CurrencyTransferResponse = exports.CurrencyTransferRequest = exports.BankAccount = exports.GetBankAccountsResponse = exports.GetBankAccountsRequest = exports.GetInfoResponse = exports.GetInfoRequest = exports.StreamLimit = exports.UnaryLimit = exports.GetUserTariffResponse = exports.GetUserTariffRequest = exports.GetMarginAttributesResponse = exports.GetMarginAttributesRequest = exports.Account = exports.GetAccountsResponse = exports.GetAccountsRequest = exports.AccountValue = exports.AccessLevel = exports.AccountStatus = exports.AccountType = exports.protobufPackage = void 0;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { TInvestNodeSDK } from './bootstrap/t-invest-node-sdk';
2
2
  export type { TInvestOptions, TInvestTlsOptions } from './application/dto/t-invest-options';
3
3
  export { createInMemoryUnaryLimiter } from './application/services/unary-limiter';
4
- export type { TInvestUnaryLimit, TInvestUnaryLimitContext, TInvestUnaryLimiter, TInvestUnaryLimits, TInvestUnaryQuota } from './application/services/unary-limiter';
4
+ export type { TInvestInMemoryUnaryLimiterOptions, TInvestUnaryLimit, TInvestUnaryLimitContext, TInvestUnaryLimiter, TInvestUnaryLimits, TInvestUnaryQuota } from './application/services/unary-limiter';
5
5
  export { isSdkError, SdkError, SdkErrorCode } from './application/errors/sdk-error';
6
6
  export type { SdkErrorOptions, SdkErrorSource } from './application/errors/sdk-error';
7
7
  export type { InstrumentsService, MarketDataService, MarketDataStreamService, OperationsService, OperationsStreamService, OrdersService, OrdersStreamService, SandboxService, SignalService, StopOrdersService, TInvestCallOptions, TInvestMetadata, TInvestMetadataValue, UsersService } from './application/dto/t-invest-services';
@@ -19,5 +19,5 @@ type InstallOptions = {
19
19
  /**
20
20
  * Устанавливает временный `process.emitWarning` hook и возвращает restore-функцию.
21
21
  */
22
- export declare function warningInterceptor(options: InstallOptions): () => void;
22
+ export declare function installWarningInterceptor(options: InstallOptions): () => void;
23
23
  export {};
@@ -11,11 +11,11 @@
11
11
  * или application use-case-ами.
12
12
  */
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.warningInterceptor = warningInterceptor;
14
+ exports.installWarningInterceptor = installWarningInterceptor;
15
15
  /**
16
16
  * Устанавливает временный `process.emitWarning` hook и возвращает restore-функцию.
17
17
  */
18
- function warningInterceptor(options) {
18
+ function installWarningInterceptor(options) {
19
19
  const { rules, enabled = process.env['NODE_ENV'] !== 'production' } = options;
20
20
  if (!enabled) {
21
21
  // Отключённый interceptor не устанавливает process hook.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Модуль классифицирует ошибки transport call в публичный контракт `SdkError`.
3
+ *
4
+ * Здесь допустимы распознавание gRPC status, локальных codec/receive failures,
5
+ * TLS verification failures и отмены конкретного вызова.
6
+ *
7
+ * Здесь не должно быть retry policy, выполнения middleware или lifecycle SDK.
8
+ */
9
+ export declare function mapSdkCallError(error: unknown, path: string, signal: AbortSignal | undefined, useSsl: boolean, maxReceiveMessageLength: number | undefined): unknown;
10
+ export declare function isCallCancellation(error: unknown, signal: AbortSignal | undefined): boolean;
11
+ export declare function errorMessage(error: unknown, fallback: string): string;
12
+ export declare function createAbortError(): Error;
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ /**
3
+ * Модуль классифицирует ошибки transport call в публичный контракт `SdkError`.
4
+ *
5
+ * Здесь допустимы распознавание gRPC status, локальных codec/receive failures,
6
+ * TLS verification failures и отмены конкретного вызова.
7
+ *
8
+ * Здесь не должно быть retry policy, выполнения middleware или lifecycle SDK.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.mapSdkCallError = mapSdkCallError;
12
+ exports.isCallCancellation = isCallCancellation;
13
+ exports.errorMessage = errorMessage;
14
+ exports.createAbortError = createAbortError;
15
+ const nice_grpc_1 = require("nice-grpc");
16
+ const sdk_error_1 = require("../../../application/errors/sdk-error");
17
+ const grpcErrorCodes = {
18
+ [nice_grpc_1.Status.CANCELLED]: sdk_error_1.SdkErrorCode.Cancelled,
19
+ [nice_grpc_1.Status.UNKNOWN]: sdk_error_1.SdkErrorCode.Unknown,
20
+ [nice_grpc_1.Status.INVALID_ARGUMENT]: sdk_error_1.SdkErrorCode.InvalidArgument,
21
+ [nice_grpc_1.Status.DEADLINE_EXCEEDED]: sdk_error_1.SdkErrorCode.DeadlineExceeded,
22
+ [nice_grpc_1.Status.NOT_FOUND]: sdk_error_1.SdkErrorCode.NotFound,
23
+ [nice_grpc_1.Status.ALREADY_EXISTS]: sdk_error_1.SdkErrorCode.AlreadyExists,
24
+ [nice_grpc_1.Status.PERMISSION_DENIED]: sdk_error_1.SdkErrorCode.PermissionDenied,
25
+ [nice_grpc_1.Status.RESOURCE_EXHAUSTED]: sdk_error_1.SdkErrorCode.ResourceExhausted,
26
+ [nice_grpc_1.Status.FAILED_PRECONDITION]: sdk_error_1.SdkErrorCode.FailedPrecondition,
27
+ [nice_grpc_1.Status.ABORTED]: sdk_error_1.SdkErrorCode.Aborted,
28
+ [nice_grpc_1.Status.OUT_OF_RANGE]: sdk_error_1.SdkErrorCode.OutOfRange,
29
+ [nice_grpc_1.Status.UNIMPLEMENTED]: sdk_error_1.SdkErrorCode.Unimplemented,
30
+ [nice_grpc_1.Status.INTERNAL]: sdk_error_1.SdkErrorCode.Internal,
31
+ [nice_grpc_1.Status.UNAVAILABLE]: sdk_error_1.SdkErrorCode.Unavailable,
32
+ [nice_grpc_1.Status.DATA_LOSS]: sdk_error_1.SdkErrorCode.DataLoss,
33
+ [nice_grpc_1.Status.UNAUTHENTICATED]: sdk_error_1.SdkErrorCode.Unauthenticated
34
+ };
35
+ const tlsCertificateErrorCodes = [
36
+ 'CERT_CHAIN_TOO_LONG',
37
+ 'CERT_HAS_EXPIRED',
38
+ 'CERT_NOT_YET_VALID',
39
+ 'CERT_REJECTED',
40
+ 'CERT_REVOKED',
41
+ 'CERT_SIGNATURE_FAILURE',
42
+ 'CERT_UNTRUSTED',
43
+ 'CRL_HAS_EXPIRED',
44
+ 'CRL_NOT_YET_VALID',
45
+ 'CRL_SIGNATURE_FAILURE',
46
+ 'DEPTH_ZERO_SELF_SIGNED_CERT',
47
+ 'ERR_TLS_CERT_ALTNAME_FORMAT',
48
+ 'ERR_TLS_CERT_ALTNAME_INVALID',
49
+ 'HOSTNAME_MISMATCH',
50
+ 'INVALID_CA',
51
+ 'INVALID_PURPOSE',
52
+ 'PATH_LENGTH_EXCEEDED',
53
+ 'SELF_SIGNED_CERT_IN_CHAIN',
54
+ 'UNABLE_TO_GET_CRL',
55
+ 'UNABLE_TO_GET_ISSUER_CERT',
56
+ 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY',
57
+ 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
58
+ ];
59
+ const tlsCertificateErrorMessages = [
60
+ 'certificate has expired',
61
+ 'certificate is not yet valid',
62
+ 'certificate is not trusted',
63
+ 'certificate rejected',
64
+ 'certificate revoked',
65
+ 'certificate verification failed',
66
+ 'certificate verify failed',
67
+ 'hostname does not match certificate',
68
+ 'hostname/ip does not match certificate',
69
+ 'self signed certificate',
70
+ 'self-signed certificate',
71
+ 'unable to get issuer certificate',
72
+ 'unable to get local issuer certificate',
73
+ 'unable to verify the first certificate',
74
+ 'unable to verify leaf signature'
75
+ ];
76
+ const standaloneTlsCertificateErrorMessages = new Set([
77
+ ...tlsCertificateErrorMessages,
78
+ 'self signed certificate in certificate chain',
79
+ 'self-signed certificate in certificate chain'
80
+ ]);
81
+ const grpcConnectionErrorMarker = 'no connection established. last error:';
82
+ const requestSerializationFailurePrefix = 'Request message serialization failure:';
83
+ const responseParsingFailurePrefix = 'Response message parsing error:';
84
+ const receivedMessageLargerThanMaxPattern = /^Received message larger than max \((\d+) vs (\d+)\)$/;
85
+ function mapSdkCallError(error, path, signal, useSsl, maxReceiveMessageLength) {
86
+ if (isCallCancellation(error, signal)) {
87
+ return new sdk_error_1.SdkError(sdk_error_1.SdkErrorCode.Cancelled, errorMessage(error, `SDK call ${path} was cancelled`), {
88
+ source: 'abort',
89
+ path,
90
+ cause: error
91
+ });
92
+ }
93
+ if ((0, sdk_error_1.isSdkError)(error)) {
94
+ return error;
95
+ }
96
+ if (error instanceof nice_grpc_1.ClientError) {
97
+ return new sdk_error_1.SdkError(grpcErrorCodes[error.code] ?? sdk_error_1.SdkErrorCode.Unknown, error.message, {
98
+ source: resolveClientErrorSource(error, useSsl, maxReceiveMessageLength),
99
+ path: error.path,
100
+ details: error.details,
101
+ cause: error
102
+ });
103
+ }
104
+ return error;
105
+ }
106
+ function isCallCancellation(error, signal) {
107
+ return signal?.aborted === true
108
+ && (error === signal.reason || errorName(error) === 'AbortError');
109
+ }
110
+ function errorMessage(error, fallback) {
111
+ if (typeof error !== 'object' || error === null) {
112
+ return fallback;
113
+ }
114
+ const message = error['message'];
115
+ return typeof message === 'string' ? message : fallback;
116
+ }
117
+ function createAbortError() {
118
+ const error = new Error('The operation was aborted');
119
+ error.name = 'AbortError';
120
+ return error;
121
+ }
122
+ function resolveClientErrorSource(error, useSsl, maxReceiveMessageLength) {
123
+ if (isTlsCertificateError(error, useSsl)) {
124
+ return 'tls';
125
+ }
126
+ if (isLocalReceiveMessageLimitError(error, maxReceiveMessageLength)) {
127
+ return 'sdk';
128
+ }
129
+ if (isLocalRequestSerializationError(error)) {
130
+ return 'sdk';
131
+ }
132
+ if (isLocalResponseParsingError(error)) {
133
+ return 'sdk';
134
+ }
135
+ return 'grpc';
136
+ }
137
+ function isLocalRequestSerializationError(error) {
138
+ return error.code === nice_grpc_1.Status.INTERNAL
139
+ && error.details.startsWith(requestSerializationFailurePrefix);
140
+ }
141
+ function isLocalResponseParsingError(error) {
142
+ return error.code === nice_grpc_1.Status.INTERNAL
143
+ && error.details.startsWith(responseParsingFailurePrefix);
144
+ }
145
+ function isLocalReceiveMessageLimitError(error, maxReceiveMessageLength) {
146
+ if (maxReceiveMessageLength === undefined
147
+ || error.code !== nice_grpc_1.Status.RESOURCE_EXHAUSTED) {
148
+ return false;
149
+ }
150
+ const rawMessageMatch = receivedMessageLargerThanMaxPattern.exec(error.details);
151
+ if (rawMessageMatch !== null) {
152
+ const receivedMessageLength = rawMessageMatch[1];
153
+ const configuredMessageLength = rawMessageMatch[2];
154
+ return receivedMessageLength !== undefined
155
+ && configuredMessageLength === String(maxReceiveMessageLength)
156
+ && Number(receivedMessageLength) > maxReceiveMessageLength;
157
+ }
158
+ return error.details ===
159
+ `Received message that decompresses to a size larger than ${maxReceiveMessageLength}`;
160
+ }
161
+ function isTlsCertificateError(error, useSsl) {
162
+ if (!useSsl || error.code !== nice_grpc_1.Status.UNAVAILABLE) {
163
+ return false;
164
+ }
165
+ const normalizedDetails = error.details.toLowerCase();
166
+ if (tlsCertificateErrorCodes.some((code) => error.details.includes(code))) {
167
+ return true;
168
+ }
169
+ const hasCertificateErrorMessage = tlsCertificateErrorMessages.some((message) => normalizedDetails.includes(message));
170
+ return hasCertificateErrorMessage
171
+ && (normalizedDetails.includes(grpcConnectionErrorMarker)
172
+ || standaloneTlsCertificateErrorMessages.has(normalizedDetails.trim()));
173
+ }
174
+ function errorName(error) {
175
+ if (typeof error !== 'object' || error === null) {
176
+ return undefined;
177
+ }
178
+ const name = error['name'];
179
+ return typeof name === 'string' ? name : undefined;
180
+ }
@@ -13,4 +13,4 @@ import type { TInvestUnaryLimiter } from '../../../application/services/unary-li
13
13
  import { Metadata } from 'nice-grpc';
14
14
  import type { SdkCallRuntime } from './sdk-middleware';
15
15
  import type { UnaryLimitResolver } from './unary-limit-resolver';
16
- export declare function createSdkClient<T>(service: unknown, channel: Channel, metadata: Metadata, unaryLimiter: TInvestUnaryLimiter | undefined, unaryLimitResolver: UnaryLimitResolver, runtime: SdkCallRuntime): T;
16
+ export declare function createSdkClient<T>(serviceDefinition: unknown, channel: Channel, metadata: Metadata, unaryLimiter: TInvestUnaryLimiter | undefined, unaryLimitResolver: UnaryLimitResolver, runtime: SdkCallRuntime): T;
@@ -13,11 +13,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.createSdkClient = createSdkClient;
14
14
  const nice_grpc_1 = require("nice-grpc");
15
15
  const sdk_middleware_1 = require("./sdk-middleware");
16
- function createSdkClient(service, channel, metadata, unaryLimiter, unaryLimitResolver, runtime) {
16
+ function createSdkClient(serviceDefinition, channel, metadata, unaryLimiter, unaryLimitResolver, runtime) {
17
17
  return (0, nice_grpc_1.createClientFactory)()
18
18
  .use((0, sdk_middleware_1.createSdkMiddleware)(unaryLimiter, unaryLimitResolver, runtime))
19
19
  .use(createSdkMetadataMiddleware(metadata))
20
- .create(service, channel);
20
+ .create(serviceDefinition, channel);
21
21
  }
22
22
  function createSdkMetadataMiddleware(metadata) {
23
23
  return async function* (call, options) {
@@ -5,7 +5,7 @@
5
5
  * - разрешение gRPC path в transport-neutral quota;
6
6
  * - вызов Consumer-owned limiter-а перед unary transport call;
7
7
  * - пропуск response stream calls без limiter-а;
8
- * - проверка SDK lifecycle и mapping известных call failures в `SdkError`;
8
+ * - проверка SDK lifecycle и делегирование классификации call failures;
9
9
  * - делегирование actual call execution в nice-grpc middleware chain;
10
10
  *
11
11
  * Здесь не должно быть retry policy или stream lifecycle management.
@@ -6,15 +6,15 @@
6
6
  * - разрешение gRPC path в transport-neutral quota;
7
7
  * - вызов Consumer-owned limiter-а перед unary transport call;
8
8
  * - пропуск response stream calls без limiter-а;
9
- * - проверка SDK lifecycle и mapping известных call failures в `SdkError`;
9
+ * - проверка SDK lifecycle и делегирование классификации call failures;
10
10
  * - делегирование actual call execution в nice-grpc middleware chain;
11
11
  *
12
12
  * Здесь не должно быть retry policy или stream lifecycle management.
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.createSdkMiddleware = createSdkMiddleware;
16
- const nice_grpc_1 = require("nice-grpc");
17
16
  const sdk_error_1 = require("../../../application/errors/sdk-error");
17
+ const sdk_call_error_1 = require("./sdk-call-error");
18
18
  function createSdkMiddleware(unaryLimiter, unaryLimitResolver, runtime) {
19
19
  return async function* (call, options) {
20
20
  runtime?.assertOpen();
@@ -42,78 +42,13 @@ function createSdkMiddleware(unaryLimiter, unaryLimitResolver, runtime) {
42
42
  if (callbackBoundary?.failure !== undefined) {
43
43
  throw callbackBoundary.failure.reason;
44
44
  }
45
- throw mapSdkCallError(error, call.method.path, options.signal, runtime?.useSsl === true, runtime?.maxReceiveMessageLength);
45
+ throw (0, sdk_call_error_1.mapSdkCallError)(error, call.method.path, options.signal, runtime?.useSsl === true, runtime?.maxReceiveMessageLength);
46
46
  }
47
47
  finally {
48
48
  throwCallCallbackFailure(callbackBoundary);
49
49
  }
50
50
  };
51
51
  }
52
- const grpcErrorCodes = {
53
- [nice_grpc_1.Status.CANCELLED]: sdk_error_1.SdkErrorCode.Cancelled,
54
- [nice_grpc_1.Status.UNKNOWN]: sdk_error_1.SdkErrorCode.Unknown,
55
- [nice_grpc_1.Status.INVALID_ARGUMENT]: sdk_error_1.SdkErrorCode.InvalidArgument,
56
- [nice_grpc_1.Status.DEADLINE_EXCEEDED]: sdk_error_1.SdkErrorCode.DeadlineExceeded,
57
- [nice_grpc_1.Status.NOT_FOUND]: sdk_error_1.SdkErrorCode.NotFound,
58
- [nice_grpc_1.Status.ALREADY_EXISTS]: sdk_error_1.SdkErrorCode.AlreadyExists,
59
- [nice_grpc_1.Status.PERMISSION_DENIED]: sdk_error_1.SdkErrorCode.PermissionDenied,
60
- [nice_grpc_1.Status.RESOURCE_EXHAUSTED]: sdk_error_1.SdkErrorCode.ResourceExhausted,
61
- [nice_grpc_1.Status.FAILED_PRECONDITION]: sdk_error_1.SdkErrorCode.FailedPrecondition,
62
- [nice_grpc_1.Status.ABORTED]: sdk_error_1.SdkErrorCode.Aborted,
63
- [nice_grpc_1.Status.OUT_OF_RANGE]: sdk_error_1.SdkErrorCode.OutOfRange,
64
- [nice_grpc_1.Status.UNIMPLEMENTED]: sdk_error_1.SdkErrorCode.Unimplemented,
65
- [nice_grpc_1.Status.INTERNAL]: sdk_error_1.SdkErrorCode.Internal,
66
- [nice_grpc_1.Status.UNAVAILABLE]: sdk_error_1.SdkErrorCode.Unavailable,
67
- [nice_grpc_1.Status.DATA_LOSS]: sdk_error_1.SdkErrorCode.DataLoss,
68
- [nice_grpc_1.Status.UNAUTHENTICATED]: sdk_error_1.SdkErrorCode.Unauthenticated
69
- };
70
- const tlsCertificateErrorCodes = [
71
- 'CERT_CHAIN_TOO_LONG',
72
- 'CERT_HAS_EXPIRED',
73
- 'CERT_NOT_YET_VALID',
74
- 'CERT_REJECTED',
75
- 'CERT_REVOKED',
76
- 'CERT_SIGNATURE_FAILURE',
77
- 'CERT_UNTRUSTED',
78
- 'CRL_HAS_EXPIRED',
79
- 'CRL_NOT_YET_VALID',
80
- 'CRL_SIGNATURE_FAILURE',
81
- 'DEPTH_ZERO_SELF_SIGNED_CERT',
82
- 'ERR_TLS_CERT_ALTNAME_FORMAT',
83
- 'ERR_TLS_CERT_ALTNAME_INVALID',
84
- 'HOSTNAME_MISMATCH',
85
- 'INVALID_CA',
86
- 'INVALID_PURPOSE',
87
- 'PATH_LENGTH_EXCEEDED',
88
- 'SELF_SIGNED_CERT_IN_CHAIN',
89
- 'UNABLE_TO_GET_CRL',
90
- 'UNABLE_TO_GET_ISSUER_CERT',
91
- 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY',
92
- 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
93
- ];
94
- const tlsCertificateErrorMessages = [
95
- 'certificate has expired',
96
- 'certificate is not yet valid',
97
- 'certificate is not trusted',
98
- 'certificate rejected',
99
- 'certificate revoked',
100
- 'certificate verification failed',
101
- 'certificate verify failed',
102
- 'hostname does not match certificate',
103
- 'hostname/ip does not match certificate',
104
- 'self signed certificate',
105
- 'self-signed certificate',
106
- 'unable to get issuer certificate',
107
- 'unable to get local issuer certificate',
108
- 'unable to verify the first certificate',
109
- 'unable to verify leaf signature'
110
- ];
111
- const standaloneTlsCertificateErrorMessages = new Set([
112
- ...tlsCertificateErrorMessages,
113
- 'self signed certificate in certificate chain',
114
- 'self-signed certificate in certificate chain'
115
- ]);
116
- const grpcConnectionErrorMarker = 'no connection established. last error:';
117
52
  const passiveUnaryLimitSignal = new AbortController().signal;
118
53
  async function acquireUnaryPermit(limiter, resolver, path, callSignal, lifecycleSignal) {
119
54
  const quota = resolver.resolve(path);
@@ -134,17 +69,15 @@ async function acquireUnaryPermit(limiter, resolver, path, callSignal, lifecycle
134
69
  throwIfAborted(signal);
135
70
  }
136
71
  catch (error) {
137
- if (isCallCancellation(error, callSignal)) {
138
- throw new sdk_error_1.SdkError(sdk_error_1.SdkErrorCode.Cancelled, errorMessage(error, `SDK call ${path} was cancelled`), {
72
+ if ((0, sdk_call_error_1.isCallCancellation)(error, callSignal)) {
73
+ throw new sdk_error_1.SdkError(sdk_error_1.SdkErrorCode.Cancelled, (0, sdk_call_error_1.errorMessage)(error, `SDK call ${path} was cancelled`), {
139
74
  source: 'abort',
140
75
  path,
141
76
  cause: error
142
77
  });
143
78
  }
144
- if (lifecycleSignal?.aborted === true
145
- && (error === lifecycleSignal.reason
146
- || errorName(error) === 'AbortError')) {
147
- throw lifecycleSignal.reason ?? error;
79
+ if ((0, sdk_call_error_1.isCallCancellation)(error, lifecycleSignal)) {
80
+ throw lifecycleSignal?.reason ?? error;
148
81
  }
149
82
  if ((0, sdk_error_1.isSdkError)(error)) {
150
83
  throw error;
@@ -160,89 +93,9 @@ function resolveUnaryLimitSignal(callSignal, lifecycleSignal) {
160
93
  }
161
94
  function throwIfAborted(signal) {
162
95
  if (signal?.aborted) {
163
- throw signal.reason ?? createAbortError();
96
+ throw signal.reason ?? (0, sdk_call_error_1.createAbortError)();
164
97
  }
165
98
  }
166
- function mapSdkCallError(error, path, signal, useSsl, maxReceiveMessageLength) {
167
- if (isCallCancellation(error, signal)) {
168
- return new sdk_error_1.SdkError(sdk_error_1.SdkErrorCode.Cancelled, errorMessage(error, `SDK call ${path} was cancelled`), {
169
- source: 'abort',
170
- path,
171
- cause: error
172
- });
173
- }
174
- if ((0, sdk_error_1.isSdkError)(error)) {
175
- return error;
176
- }
177
- if (error instanceof nice_grpc_1.ClientError) {
178
- return new sdk_error_1.SdkError(grpcErrorCodes[error.code] ?? sdk_error_1.SdkErrorCode.Unknown, error.message, {
179
- source: resolveClientErrorSource(error, useSsl, maxReceiveMessageLength),
180
- path: error.path,
181
- details: error.details,
182
- cause: error
183
- });
184
- }
185
- return error;
186
- }
187
- function resolveClientErrorSource(error, useSsl, maxReceiveMessageLength) {
188
- if (isTlsCertificateError(error, useSsl)) {
189
- return 'tls';
190
- }
191
- if (isLocalReceiveMessageLimitError(error, maxReceiveMessageLength)) {
192
- return 'sdk';
193
- }
194
- if (isLocalRequestSerializationError(error)) {
195
- return 'sdk';
196
- }
197
- if (isLocalResponseParsingError(error)) {
198
- return 'sdk';
199
- }
200
- return 'grpc';
201
- }
202
- const requestSerializationFailurePrefix = 'Request message serialization failure:';
203
- function isLocalRequestSerializationError(error) {
204
- return error.code === nice_grpc_1.Status.INTERNAL
205
- && error.details.startsWith(requestSerializationFailurePrefix);
206
- }
207
- const responseParsingFailurePrefix = 'Response message parsing error:';
208
- function isLocalResponseParsingError(error) {
209
- return error.code === nice_grpc_1.Status.INTERNAL
210
- && error.details.startsWith(responseParsingFailurePrefix);
211
- }
212
- const receivedMessageLargerThanMaxPattern = /^Received message larger than max \((\d+) vs (\d+)\)$/;
213
- function isLocalReceiveMessageLimitError(error, maxReceiveMessageLength) {
214
- if (maxReceiveMessageLength === undefined
215
- || error.code !== nice_grpc_1.Status.RESOURCE_EXHAUSTED) {
216
- return false;
217
- }
218
- const rawMessageMatch = receivedMessageLargerThanMaxPattern.exec(error.details);
219
- if (rawMessageMatch !== null) {
220
- const receivedMessageLength = rawMessageMatch[1];
221
- const configuredMessageLength = rawMessageMatch[2];
222
- return receivedMessageLength !== undefined
223
- && configuredMessageLength === String(maxReceiveMessageLength)
224
- && Number(receivedMessageLength) > maxReceiveMessageLength;
225
- }
226
- return error.details ===
227
- `Received message that decompresses to a size larger than ${maxReceiveMessageLength}`;
228
- }
229
- function isTlsCertificateError(error, useSsl) {
230
- if (!useSsl || error.code !== nice_grpc_1.Status.UNAVAILABLE) {
231
- return false;
232
- }
233
- const normalizedDetails = error.details.toLowerCase();
234
- if (tlsCertificateErrorCodes.some((code) => error.details.includes(code))) {
235
- return true;
236
- }
237
- const hasCertificateErrorMessage = tlsCertificateErrorMessages.some((message) => normalizedDetails.includes(message));
238
- return hasCertificateErrorMessage
239
- && (normalizedDetails.includes(grpcConnectionErrorMarker)
240
- || standaloneTlsCertificateErrorMessages.has(normalizedDetails.trim()));
241
- }
242
- function isCallCancellation(error, signal) {
243
- return signal?.aborted === true
244
- && (error === signal.reason || errorName(error) === 'AbortError');
245
- }
246
99
  function createCallCallbackBoundary(options) {
247
100
  if (options.onHeader === undefined && options.onTrailer === undefined) {
248
101
  return undefined;
@@ -291,22 +144,3 @@ function throwCallCallbackFailure(boundary) {
291
144
  throw boundary.failure.reason;
292
145
  }
293
146
  }
294
- function errorName(error) {
295
- if (typeof error !== 'object' || error === null) {
296
- return undefined;
297
- }
298
- const name = error['name'];
299
- return typeof name === 'string' ? name : undefined;
300
- }
301
- function errorMessage(error, fallback) {
302
- if (typeof error !== 'object' || error === null) {
303
- return fallback;
304
- }
305
- const message = error['message'];
306
- return typeof message === 'string' ? message : fallback;
307
- }
308
- function createAbortError() {
309
- const error = new Error('The operation was aborted');
310
- error.name = 'AbortError';
311
- return error;
312
- }
@@ -17,6 +17,8 @@ export declare class UnaryLimitResolver {
17
17
  private readonly buckets;
18
18
  constructor(limits: UnaryLimitRules, buckets?: UnaryLimitBuckets);
19
19
  resolve(path: string): TInvestUnaryQuota | undefined;
20
- private matchesRule;
20
+ private getOwnLimit;
21
+ private createQuota;
22
+ private resolveServiceName;
21
23
  }
22
24
  export {};
@@ -20,18 +20,25 @@ class UnaryLimitResolver {
20
20
  this.buckets = buckets;
21
21
  }
22
22
  resolve(path) {
23
- let matchedKey;
24
- let matchedLimit;
25
- for (const [key, limit] of Object.entries(this.limits)) {
26
- if (this.matchesRule(path, key)
27
- && (matchedKey === undefined || key.length > matchedKey.length)) {
28
- matchedKey = key;
29
- matchedLimit = limit;
30
- }
23
+ const exactLimit = this.getOwnLimit(path);
24
+ if (exactLimit !== undefined) {
25
+ return this.createQuota(path, exactLimit);
31
26
  }
32
- if (matchedKey === undefined || matchedLimit === undefined) {
27
+ const serviceName = this.resolveServiceName(path);
28
+ if (serviceName === undefined) {
33
29
  return undefined;
34
30
  }
31
+ const serviceLimit = this.getOwnLimit(serviceName);
32
+ return serviceLimit === undefined
33
+ ? undefined
34
+ : this.createQuota(serviceName, serviceLimit);
35
+ }
36
+ getOwnLimit(key) {
37
+ return Object.hasOwn(this.limits, key)
38
+ ? this.limits[key]
39
+ : undefined;
40
+ }
41
+ createQuota(matchedKey, matchedLimit) {
35
42
  const quotaBucket = this.buckets[matchedKey];
36
43
  return {
37
44
  bucket: quotaBucket === undefined
@@ -41,20 +48,14 @@ class UnaryLimitResolver {
41
48
  windowMs: matchedLimit.windowMs
42
49
  };
43
50
  }
44
- matchesRule(path, key) {
45
- if (path === key) {
46
- return true;
47
- }
48
- if (key.indexOf('/') > -1) {
49
- return false;
50
- }
51
+ resolveServiceName(path) {
51
52
  const methodSeparator = path.lastIndexOf('/');
52
53
  if (methodSeparator < 1) {
53
- return false;
54
+ return undefined;
54
55
  }
55
56
  const qualifiedService = path.slice(0, methodSeparator);
56
57
  const serviceSeparator = Math.max(qualifiedService.lastIndexOf('.'), qualifiedService.lastIndexOf('/'));
57
- return qualifiedService.slice(serviceSeparator + 1) === key;
58
+ return qualifiedService.slice(serviceSeparator + 1);
58
59
  }
59
60
  }
60
61
  exports.UnaryLimitResolver = UnaryLimitResolver;