@gravito/echo 3.1.0 → 3.1.2

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 (245) hide show
  1. package/README.md +24 -9
  2. package/dist/OrbitEcho.d.ts +76 -60
  3. package/dist/index.d.ts +31 -16
  4. package/dist/index.js +1 -1596
  5. package/dist/index.js.map +3 -28
  6. package/dist/{echo/src/middleware → middleware}/RequestBufferMiddleware.d.ts +3 -3
  7. package/dist/providers/GenericProvider.d.ts +37 -19
  8. package/dist/providers/GitHubProvider.d.ts +21 -13
  9. package/dist/providers/StripeProvider.d.ts +20 -13
  10. package/dist/providers/index.d.ts +14 -4
  11. package/dist/receive/SignatureValidator.d.ts +33 -1
  12. package/dist/receive/WebhookReceiver.d.ts +139 -22
  13. package/dist/receive/index.d.ts +0 -1
  14. package/dist/send/WebhookDispatcher.d.ts +159 -16
  15. package/dist/send/index.d.ts +0 -1
  16. package/dist/types.d.ts +669 -57
  17. package/package.json +5 -2
  18. package/dist/OrbitEcho.d.ts.map +0 -1
  19. package/dist/atlas/src/DB.d.ts +0 -301
  20. package/dist/atlas/src/OrbitAtlas.d.ts +0 -9
  21. package/dist/atlas/src/config/defineConfig.d.ts +0 -14
  22. package/dist/atlas/src/config/index.d.ts +0 -7
  23. package/dist/atlas/src/config/loadConfig.d.ts +0 -48
  24. package/dist/atlas/src/connection/Connection.d.ts +0 -108
  25. package/dist/atlas/src/connection/ConnectionManager.d.ts +0 -111
  26. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +0 -32
  27. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +0 -118
  28. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +0 -36
  29. package/dist/atlas/src/drivers/MySQLDriver.d.ts +0 -66
  30. package/dist/atlas/src/drivers/PostgresDriver.d.ts +0 -83
  31. package/dist/atlas/src/drivers/RedisDriver.d.ts +0 -43
  32. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +0 -45
  33. package/dist/atlas/src/drivers/types.d.ts +0 -260
  34. package/dist/atlas/src/errors/index.d.ts +0 -45
  35. package/dist/atlas/src/grammar/Grammar.d.ts +0 -342
  36. package/dist/atlas/src/grammar/MongoGrammar.d.ts +0 -47
  37. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +0 -54
  38. package/dist/atlas/src/grammar/NullGrammar.d.ts +0 -35
  39. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +0 -62
  40. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +0 -32
  41. package/dist/atlas/src/index.d.ts +0 -67
  42. package/dist/atlas/src/migration/Migration.d.ts +0 -64
  43. package/dist/atlas/src/migration/MigrationRepository.d.ts +0 -65
  44. package/dist/atlas/src/migration/Migrator.d.ts +0 -110
  45. package/dist/atlas/src/migration/index.d.ts +0 -6
  46. package/dist/atlas/src/observability/AtlasMetrics.d.ts +0 -11
  47. package/dist/atlas/src/observability/AtlasObservability.d.ts +0 -15
  48. package/dist/atlas/src/observability/AtlasTracer.d.ts +0 -12
  49. package/dist/atlas/src/observability/index.d.ts +0 -9
  50. package/dist/atlas/src/orm/index.d.ts +0 -5
  51. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +0 -121
  52. package/dist/atlas/src/orm/model/Model.d.ts +0 -449
  53. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +0 -20
  54. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +0 -136
  55. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +0 -36
  56. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +0 -87
  57. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +0 -117
  58. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +0 -64
  59. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +0 -15
  60. package/dist/atlas/src/orm/model/concerns/index.d.ts +0 -12
  61. package/dist/atlas/src/orm/model/decorators.d.ts +0 -109
  62. package/dist/atlas/src/orm/model/errors.d.ts +0 -52
  63. package/dist/atlas/src/orm/model/index.d.ts +0 -10
  64. package/dist/atlas/src/orm/model/relationships.d.ts +0 -207
  65. package/dist/atlas/src/orm/model/types.d.ts +0 -12
  66. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +0 -123
  67. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +0 -54
  68. package/dist/atlas/src/orm/schema/index.d.ts +0 -6
  69. package/dist/atlas/src/orm/schema/types.d.ts +0 -85
  70. package/dist/atlas/src/query/Expression.d.ts +0 -60
  71. package/dist/atlas/src/query/NPlusOneDetector.d.ts +0 -10
  72. package/dist/atlas/src/query/QueryBuilder.d.ts +0 -573
  73. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +0 -51
  74. package/dist/atlas/src/query/clauses/HavingClause.d.ts +0 -70
  75. package/dist/atlas/src/query/clauses/JoinClause.d.ts +0 -87
  76. package/dist/atlas/src/query/clauses/LimitClause.d.ts +0 -82
  77. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +0 -69
  78. package/dist/atlas/src/query/clauses/SelectClause.d.ts +0 -71
  79. package/dist/atlas/src/query/clauses/WhereClause.d.ts +0 -167
  80. package/dist/atlas/src/query/clauses/index.d.ts +0 -11
  81. package/dist/atlas/src/schema/Blueprint.d.ts +0 -276
  82. package/dist/atlas/src/schema/ColumnDefinition.d.ts +0 -154
  83. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +0 -37
  84. package/dist/atlas/src/schema/Schema.d.ts +0 -131
  85. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +0 -23
  86. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +0 -26
  87. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +0 -28
  88. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +0 -97
  89. package/dist/atlas/src/schema/grammars/index.d.ts +0 -7
  90. package/dist/atlas/src/schema/index.d.ts +0 -8
  91. package/dist/atlas/src/seed/Factory.d.ts +0 -90
  92. package/dist/atlas/src/seed/Seeder.d.ts +0 -28
  93. package/dist/atlas/src/seed/SeederRunner.d.ts +0 -74
  94. package/dist/atlas/src/seed/index.d.ts +0 -6
  95. package/dist/atlas/src/types/index.d.ts +0 -1100
  96. package/dist/atlas/src/utils/levenshtein.d.ts +0 -9
  97. package/dist/core/src/Application.d.ts +0 -215
  98. package/dist/core/src/CommandKernel.d.ts +0 -33
  99. package/dist/core/src/ConfigManager.d.ts +0 -26
  100. package/dist/core/src/Container.d.ts +0 -108
  101. package/dist/core/src/ErrorHandler.d.ts +0 -63
  102. package/dist/core/src/Event.d.ts +0 -5
  103. package/dist/core/src/EventManager.d.ts +0 -123
  104. package/dist/core/src/GlobalErrorHandlers.d.ts +0 -47
  105. package/dist/core/src/GravitoServer.d.ts +0 -28
  106. package/dist/core/src/HookManager.d.ts +0 -496
  107. package/dist/core/src/Listener.d.ts +0 -4
  108. package/dist/core/src/Logger.d.ts +0 -20
  109. package/dist/core/src/PlanetCore.d.ts +0 -289
  110. package/dist/core/src/Route.d.ts +0 -36
  111. package/dist/core/src/Router.d.ts +0 -284
  112. package/dist/core/src/ServiceProvider.d.ts +0 -156
  113. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +0 -27
  114. package/dist/core/src/adapters/PhotonAdapter.d.ts +0 -171
  115. package/dist/core/src/adapters/bun/BunContext.d.ts +0 -45
  116. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +0 -31
  117. package/dist/core/src/adapters/bun/BunRequest.d.ts +0 -31
  118. package/dist/core/src/adapters/bun/RadixNode.d.ts +0 -19
  119. package/dist/core/src/adapters/bun/RadixRouter.d.ts +0 -31
  120. package/dist/core/src/adapters/bun/types.d.ts +0 -20
  121. package/dist/core/src/adapters/photon-types.d.ts +0 -73
  122. package/dist/core/src/adapters/types.d.ts +0 -235
  123. package/dist/core/src/engine/AOTRouter.d.ts +0 -124
  124. package/dist/core/src/engine/FastContext.d.ts +0 -100
  125. package/dist/core/src/engine/Gravito.d.ts +0 -137
  126. package/dist/core/src/engine/MinimalContext.d.ts +0 -79
  127. package/dist/core/src/engine/analyzer.d.ts +0 -27
  128. package/dist/core/src/engine/constants.d.ts +0 -23
  129. package/dist/core/src/engine/index.d.ts +0 -26
  130. package/dist/core/src/engine/path.d.ts +0 -26
  131. package/dist/core/src/engine/pool.d.ts +0 -83
  132. package/dist/core/src/engine/types.d.ts +0 -143
  133. package/dist/core/src/events/CircuitBreaker.d.ts +0 -229
  134. package/dist/core/src/events/DeadLetterQueue.d.ts +0 -145
  135. package/dist/core/src/events/EventBackend.d.ts +0 -11
  136. package/dist/core/src/events/EventOptions.d.ts +0 -109
  137. package/dist/core/src/events/EventPriorityQueue.d.ts +0 -202
  138. package/dist/core/src/events/IdempotencyCache.d.ts +0 -60
  139. package/dist/core/src/events/index.d.ts +0 -14
  140. package/dist/core/src/events/observability/EventMetrics.d.ts +0 -132
  141. package/dist/core/src/events/observability/EventTracer.d.ts +0 -68
  142. package/dist/core/src/events/observability/EventTracing.d.ts +0 -161
  143. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +0 -240
  144. package/dist/core/src/events/observability/ObservableHookManager.d.ts +0 -108
  145. package/dist/core/src/events/observability/index.d.ts +0 -20
  146. package/dist/core/src/events/observability/metrics-types.d.ts +0 -16
  147. package/dist/core/src/events/types.d.ts +0 -75
  148. package/dist/core/src/exceptions/AuthenticationException.d.ts +0 -8
  149. package/dist/core/src/exceptions/AuthorizationException.d.ts +0 -8
  150. package/dist/core/src/exceptions/CircularDependencyException.d.ts +0 -9
  151. package/dist/core/src/exceptions/GravitoException.d.ts +0 -23
  152. package/dist/core/src/exceptions/HttpException.d.ts +0 -9
  153. package/dist/core/src/exceptions/ModelNotFoundException.d.ts +0 -10
  154. package/dist/core/src/exceptions/ValidationException.d.ts +0 -22
  155. package/dist/core/src/exceptions/index.d.ts +0 -7
  156. package/dist/core/src/helpers/Arr.d.ts +0 -19
  157. package/dist/core/src/helpers/Str.d.ts +0 -23
  158. package/dist/core/src/helpers/data.d.ts +0 -25
  159. package/dist/core/src/helpers/errors.d.ts +0 -34
  160. package/dist/core/src/helpers/response.d.ts +0 -41
  161. package/dist/core/src/helpers.d.ts +0 -338
  162. package/dist/core/src/http/CookieJar.d.ts +0 -51
  163. package/dist/core/src/http/cookie.d.ts +0 -29
  164. package/dist/core/src/http/middleware/BodySizeLimit.d.ts +0 -16
  165. package/dist/core/src/http/middleware/Cors.d.ts +0 -24
  166. package/dist/core/src/http/middleware/Csrf.d.ts +0 -23
  167. package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +0 -28
  168. package/dist/core/src/http/middleware/SecurityHeaders.d.ts +0 -29
  169. package/dist/core/src/http/middleware/ThrottleRequests.d.ts +0 -18
  170. package/dist/core/src/http/types.d.ts +0 -355
  171. package/dist/core/src/index.d.ts +0 -76
  172. package/dist/core/src/instrumentation/index.d.ts +0 -35
  173. package/dist/core/src/instrumentation/opentelemetry.d.ts +0 -178
  174. package/dist/core/src/instrumentation/types.d.ts +0 -182
  175. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +0 -316
  176. package/dist/core/src/reliability/RetryPolicy.d.ts +0 -217
  177. package/dist/core/src/reliability/index.d.ts +0 -6
  178. package/dist/core/src/router/ControllerDispatcher.d.ts +0 -12
  179. package/dist/core/src/router/RequestValidator.d.ts +0 -20
  180. package/dist/core/src/runtime.d.ts +0 -119
  181. package/dist/core/src/security/Encrypter.d.ts +0 -33
  182. package/dist/core/src/security/Hasher.d.ts +0 -29
  183. package/dist/core/src/testing/HttpTester.d.ts +0 -39
  184. package/dist/core/src/testing/TestResponse.d.ts +0 -78
  185. package/dist/core/src/testing/index.d.ts +0 -2
  186. package/dist/core/src/types/events.d.ts +0 -94
  187. package/dist/echo/src/OrbitEcho.d.ts +0 -115
  188. package/dist/echo/src/index.d.ts +0 -64
  189. package/dist/echo/src/providers/GenericProvider.d.ts +0 -53
  190. package/dist/echo/src/providers/GitHubProvider.d.ts +0 -35
  191. package/dist/echo/src/providers/StripeProvider.d.ts +0 -38
  192. package/dist/echo/src/providers/index.d.ts +0 -14
  193. package/dist/echo/src/receive/SignatureValidator.d.ts +0 -67
  194. package/dist/echo/src/receive/WebhookReceiver.d.ts +0 -185
  195. package/dist/echo/src/receive/index.d.ts +0 -2
  196. package/dist/echo/src/send/WebhookDispatcher.d.ts +0 -198
  197. package/dist/echo/src/send/index.d.ts +0 -1
  198. package/dist/echo/src/types.d.ts +0 -756
  199. package/dist/index.d.ts.map +0 -1
  200. package/dist/photon/src/index.d.ts +0 -84
  201. package/dist/photon/src/middleware/binary.d.ts +0 -31
  202. package/dist/photon/src/middleware/htmx.d.ts +0 -39
  203. package/dist/photon/src/middleware/ratelimit.d.ts +0 -157
  204. package/dist/photon/src/openapi.d.ts +0 -19
  205. package/dist/providers/GenericProvider.d.ts.map +0 -1
  206. package/dist/providers/GitHubProvider.d.ts.map +0 -1
  207. package/dist/providers/StripeProvider.d.ts.map +0 -1
  208. package/dist/providers/index.d.ts.map +0 -1
  209. package/dist/receive/SignatureValidator.d.ts.map +0 -1
  210. package/dist/receive/WebhookReceiver.d.ts.map +0 -1
  211. package/dist/receive/index.d.ts.map +0 -1
  212. package/dist/send/WebhookDispatcher.d.ts.map +0 -1
  213. package/dist/send/index.d.ts.map +0 -1
  214. package/dist/types.d.ts.map +0 -1
  215. /package/dist/{echo/src/dlq → dlq}/DeadLetterQueue.d.ts +0 -0
  216. /package/dist/{echo/src/dlq → dlq}/MemoryDeadLetterQueue.d.ts +0 -0
  217. /package/dist/{echo/src/dlq → dlq}/index.d.ts +0 -0
  218. /package/dist/{echo/src/middleware → middleware}/index.d.ts +0 -0
  219. /package/dist/{echo/src/observability → observability}/index.d.ts +0 -0
  220. /package/dist/{echo/src/observability → observability}/logging/ConsoleEchoLogger.d.ts +0 -0
  221. /package/dist/{echo/src/observability → observability}/logging/EchoLogger.d.ts +0 -0
  222. /package/dist/{echo/src/observability → observability}/logging/index.d.ts +0 -0
  223. /package/dist/{echo/src/observability → observability}/metrics/MetricsProvider.d.ts +0 -0
  224. /package/dist/{echo/src/observability → observability}/metrics/NoopMetricsProvider.d.ts +0 -0
  225. /package/dist/{echo/src/observability → observability}/metrics/PrometheusMetricsProvider.d.ts +0 -0
  226. /package/dist/{echo/src/observability → observability}/metrics/index.d.ts +0 -0
  227. /package/dist/{echo/src/observability → observability}/tracing/NoopTracer.d.ts +0 -0
  228. /package/dist/{echo/src/observability → observability}/tracing/Tracer.d.ts +0 -0
  229. /package/dist/{echo/src/observability → observability}/tracing/index.d.ts +0 -0
  230. /package/dist/{echo/src/providers → providers}/LinearProvider.d.ts +0 -0
  231. /package/dist/{echo/src/providers → providers}/PaddleProvider.d.ts +0 -0
  232. /package/dist/{echo/src/providers → providers}/ShopifyProvider.d.ts +0 -0
  233. /package/dist/{echo/src/providers → providers}/SlackProvider.d.ts +0 -0
  234. /package/dist/{echo/src/providers → providers}/TwilioProvider.d.ts +0 -0
  235. /package/dist/{echo/src/providers → providers}/base/BaseProvider.d.ts +0 -0
  236. /package/dist/{echo/src/providers → providers}/base/HeaderUtils.d.ts +0 -0
  237. /package/dist/{echo/src/replay → replay}/WebhookReplayService.d.ts +0 -0
  238. /package/dist/{echo/src/replay → replay}/index.d.ts +0 -0
  239. /package/dist/{echo/src/resilience → resilience}/CircuitBreaker.d.ts +0 -0
  240. /package/dist/{echo/src/resilience → resilience}/index.d.ts +0 -0
  241. /package/dist/{echo/src/rotation → rotation}/KeyRotationManager.d.ts +0 -0
  242. /package/dist/{echo/src/rotation → rotation}/index.d.ts +0 -0
  243. /package/dist/{echo/src/storage → storage}/MemoryWebhookStore.d.ts +0 -0
  244. /package/dist/{echo/src/storage → storage}/WebhookStore.d.ts +0 -0
  245. /package/dist/{echo/src/storage → storage}/index.d.ts +0 -0
package/README.md CHANGED
@@ -2,15 +2,30 @@
2
2
 
3
3
  > 📡 Enterprise-grade webhook handling for Gravito. Secure receiving and reliable sending.
4
4
 
5
- ## Features
6
-
7
- - **Secure Receiving** - HMAC signature verification, timestamp validation
8
- - **Built-in Providers** - Stripe, GitHub, and generic provider support
9
- - **Reliable Sending** - Exponential backoff retry with configurable strategy
10
- - **Gravito Integration** - First-class OrbitEcho module for PlanetCore
11
- - **Request Buffering (v1.1)** - Prevents signature verification failures from framework auto-parsing
12
- - **Circuit Breaker (v1.1)** - Protects downstream services with automatic failure detection
13
- - **Key Rotation (v1.2)** - Zero-downtime key updates with multi-version support
5
+ ## Features
6
+
7
+ - 🪐 **Galaxy-Ready Gateway**: The primary entry/exit point for external asynchronous communication.
8
+ - 🛡️ **Secure Receiving**: HMAC signature verification, timestamp validation, and multi-key support.
9
+ - 🔄 **Boundary Reliability**: Built-in **Circuit Breaker**, **Retry Scheduler**, and **DLQ** for outgoing hooks.
10
+ - 📦 **Built-in Providers**: Native support for Stripe, GitHub, Shopify, Slack, and more.
11
+ - **Request Buffering**: Prevents signature failures by handling raw bodies before framework parsing.
12
+ - 🔐 **Key Rotation**: Seamless, zero-downtime secret rotation for enterprise security.
13
+
14
+ ## 🌌 Role in Galaxy Architecture
15
+
16
+ In the **Gravito Galaxy Architecture**, Echo acts as the **Deep Space Radar Layer (Boundary Communication)**.
17
+
18
+ - **External Stimuli**: Converts external world signals (Webhooks from Stripe, etc.) into internal `Signal` events that Satellites can react to.
19
+ - **Outbound Pulse**: Provides a reliable way for internal Galaxy state changes to be broadcasted to the outside world (e.g., notifying a 3rd party logistics provider).
20
+ - **Isolation Barrier**: Protects the core Galaxy from external failure ripples by utilizing circuit breakers on outgoing requests.
21
+
22
+ ```mermaid
23
+ graph LR
24
+ World([External Service]) -- Webhook --> Echo{Echo Orbit}
25
+ Echo -->|Verified Signal| Sat[Satellite: Payment]
26
+ Sat -->|Internal Event| Stream[Stream Orbit]
27
+ Echo -.->|Circuit Breaker| World
28
+ ```
14
29
 
15
30
  ## Installation
16
31
 
@@ -1,99 +1,115 @@
1
- /**
2
- * @fileoverview OrbitEcho Module
3
- *
4
- * Gravito integration for webhook handling.
5
- *
6
- * @module @gravito/echo
7
- */
1
+ import type { GravitoOrbit, PlanetCore } from '@gravito/core';
8
2
  import { WebhookReceiver } from './receive/WebhookReceiver';
3
+ import { KeyRotationManager } from './rotation/KeyRotationManager';
9
4
  import { WebhookDispatcher } from './send/WebhookDispatcher';
10
- import type { EchoConfig } from './types';
5
+ import type { EchoConfig, ProviderKeyEntry } from './types';
11
6
  /**
12
- * Simple module interface for PlanetCore integration
13
- */
14
- interface ModuleConfig {
15
- singleton?: boolean;
16
- }
17
- /**
18
- * Minimal PlanetCore interface
19
- */
20
- interface PlanetCore {
21
- container: {
22
- instance<T>(key: string, value: T): void;
23
- };
24
- hooks: {
25
- addAction(hook: string, callback: () => void | Promise<void>): void;
26
- };
27
- adapter: {
28
- use(middleware: unknown): void;
29
- };
30
- router: {
31
- post(path: string, handler: unknown): void;
32
- };
33
- }
34
- /**
35
- * OrbitEcho - Gravito Webhook Module
7
+ * OrbitEcho is the official webhook orchestration module for the Gravito ecosystem.
36
8
  *
37
- * Provides secure webhook receiving and reliable webhook sending.
9
+ * It serves as a comprehensive hub for managing the entire webhook lifecycle,
10
+ * including secure reception, signature verification across multiple providers,
11
+ * persistent storage for auditing, and reliable outgoing dispatch with
12
+ * exponential backoff and circuit breaking.
38
13
  *
39
- * @example
14
+ * @example Basic integration with PlanetCore
40
15
  * ```typescript
41
- * const core = new PlanetCore()
16
+ * import { PlanetCore } from '@gravito/core';
17
+ * import { OrbitEcho } from '@gravito/echo';
42
18
  *
43
- * core.install(new OrbitEcho({
19
+ * const core = new PlanetCore();
20
+ * const echo = new OrbitEcho({
44
21
  * providers: {
45
- * stripe: { name: 'stripe', secret: process.env.STRIPE_WEBHOOK_SECRET! },
46
- * github: { name: 'github', secret: process.env.GITHUB_WEBHOOK_SECRET! }
22
+ * stripe: { name: 'stripe', secret: process.env.STRIPE_SECRET }
47
23
  * },
48
24
  * dispatcher: {
49
- * secret: process.env.OUTGOING_WEBHOOK_SECRET!
25
+ * secret: process.env.APP_WEBHOOK_SECRET
50
26
  * }
51
- * }))
27
+ * });
52
28
  *
53
- * // Get receiver to add handlers
54
- * const receiver = core.container.make<WebhookReceiver>('echo.receiver')
55
- * receiver.on('stripe', 'payment_intent.succeeded', async (event) => {
56
- * console.log('Payment received:', event.payload)
57
- * })
29
+ * core.install(echo);
58
30
  * ```
31
+ *
32
+ * @public
59
33
  */
60
- export declare class OrbitEcho {
61
- static config: ModuleConfig;
34
+ export declare class OrbitEcho implements GravitoOrbit {
62
35
  private receiver;
63
36
  private dispatcher?;
64
37
  private echoConfig;
38
+ private keyRotationManager?;
65
39
  /**
66
- * Create a new OrbitEcho instance.
40
+ * Constructs a new OrbitEcho instance with the specified configuration.
67
41
  *
68
- * @param config - The configuration object for providers and dispatcher.
42
+ * This constructor initializes the core receiver component, sets up key rotation
43
+ * orchestration if enabled, registers defined providers, and connects the
44
+ * observability stack (metrics, tracing, logging).
45
+ *
46
+ * @param config - The global configuration defining providers, dispatchers, and infrastructure.
69
47
  */
70
48
  constructor(config?: EchoConfig);
71
49
  /**
72
- * Install into PlanetCore
50
+ * Integrates the Echo module into the Gravito application lifecycle.
73
51
  *
74
- * Registers the OrbitEcho instance and its components into the service container.
52
+ * This method performs the following setup tasks:
53
+ * 1. Installs request buffering middleware (if enabled) to preserve raw bodies.
54
+ * 2. Binds Echo components to the service container (`echo`, `echo.receiver`).
55
+ * 3. Injects the Echo instance into the request context for easy access in handlers.
75
56
  *
76
- * @param core - The PlanetCore instance.
57
+ * @param core - The PlanetCore instance managing the application.
58
+ * @throws {Error} If the core adapter is missing or improperly configured.
77
59
  */
78
60
  install(core: PlanetCore): void;
79
61
  /**
80
- * Get webhook receiver
62
+ * Retrieves the underlying receiver instance for manual webhook processing.
63
+ *
64
+ * Use this when you need fine-grained control over how incoming webhooks
65
+ * are routed or verified outside of the standard middleware flow.
81
66
  *
82
- * @returns The WebhookReceiver instance.
67
+ * @returns The active WebhookReceiver instance.
83
68
  */
84
69
  getReceiver(): WebhookReceiver;
85
70
  /**
86
- * Get webhook dispatcher
71
+ * Retrieves the dispatcher instance for sending outgoing webhooks.
87
72
  *
88
- * @returns The WebhookDispatcher instance, or undefined if not configured.
73
+ * @returns The configured WebhookDispatcher, or undefined if dispatch is disabled.
89
74
  */
90
75
  getDispatcher(): WebhookDispatcher | undefined;
91
76
  /**
92
- * Get configuration
77
+ * Accesses the active configuration used by this OrbitEcho instance.
93
78
  *
94
- * @returns The EchoConfig object.
79
+ * @returns The immutable EchoConfig object.
95
80
  */
96
81
  getConfig(): EchoConfig;
82
+ /**
83
+ * Retrieves the key rotation manager responsible for secret lifecycle.
84
+ *
85
+ * @returns The manager instance, or undefined if key rotation is disabled.
86
+ */
87
+ getKeyRotationManager(): KeyRotationManager | undefined;
88
+ /**
89
+ * Initiates a zero-downtime primary key rotation for a specific provider.
90
+ *
91
+ * This method promotes a new key to primary status while maintaining valid old keys
92
+ * for a grace period, ensuring that webhooks signed with either key are accepted
93
+ * during the transition.
94
+ *
95
+ * @param providerName - The identifier of the provider to update.
96
+ * @param newKey - Metadata and value for the replacement key.
97
+ * @throws {Error} If key rotation is not enabled in the global configuration.
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * await echo.rotateProviderKey('stripe', {
102
+ * key: 'whsec_new_secret',
103
+ * version: 'v2',
104
+ * activeFrom: new Date()
105
+ * });
106
+ * ```
107
+ */
108
+ rotateProviderKey(providerName: string, newKey: Omit<ProviderKeyEntry, 'isPrimary'>): Promise<void>;
109
+ }
110
+ declare module '@gravito/core' {
111
+ interface GravitoVariables {
112
+ /** Webhook receiver and dispatcher */
113
+ echo?: OrbitEcho;
114
+ }
97
115
  }
98
- export {};
99
- //# sourceMappingURL=OrbitEcho.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,49 +1,64 @@
1
1
  /**
2
- * @fileoverview @gravito/echo - Enterprise Webhook Module
2
+ * @fileoverview \@gravito/echo - Enterprise Webhook Orchestration
3
3
  *
4
- * Secure webhook receiving and reliable webhook sending for Gravito.
4
+ * Echo provides a secure, reliable, and observable layer for handling webhooks
5
+ * in Gravito applications. It standardizes incoming webhook reception with
6
+ * signature verification and dynamic key rotation, while ensuring reliable
7
+ * outgoing delivery via exponential backoff and circuit breaking.
5
8
  *
6
- * @example Receiving webhooks
9
+ * @example Receiving webhooks from Stripe
7
10
  * ```typescript
8
11
  * import { OrbitEcho, WebhookReceiver } from '@gravito/echo'
9
12
  *
10
13
  * const core = new PlanetCore()
11
- *
12
14
  * core.install(new OrbitEcho({
13
15
  * providers: {
14
- * stripe: { name: 'stripe', secret: process.env.STRIPE_WEBHOOK_SECRET! }
16
+ * stripe: { name: 'stripe', secret: process.env.STRIPE_SECRET! }
15
17
  * }
16
18
  * }))
17
19
  *
18
20
  * const receiver = core.container.make<WebhookReceiver>('echo.receiver')
19
21
  * receiver.on('stripe', 'payment_intent.succeeded', async (event) => {
20
- * console.log('Payment:', event.payload)
22
+ * // Securely process validated payment
21
23
  * })
22
24
  * ```
23
25
  *
24
- * @example Sending webhooks
26
+ * @example Dispatching reliable outgoing webhooks
25
27
  * ```typescript
26
28
  * import { WebhookDispatcher } from '@gravito/echo'
27
29
  *
28
- * const dispatcher = new WebhookDispatcher({
29
- * secret: 'my-secret'
30
- * })
31
- *
30
+ * const dispatcher = new WebhookDispatcher({ secret: 'app-secret' })
32
31
  * await dispatcher.dispatch({
33
- * url: 'https://example.com/webhook',
32
+ * url: 'https://consumer.com/hook',
34
33
  * event: 'order.created',
35
- * data: { orderId: 123 }
34
+ * data: { id: 123 }
36
35
  * })
37
36
  * ```
38
37
  *
39
38
  * @module @gravito/echo
40
39
  */
40
+ export type { DeadLetterEvent, DeadLetterQueue } from './dlq/DeadLetterQueue';
41
+ export { MemoryDeadLetterQueue } from './dlq/MemoryDeadLetterQueue';
42
+ export { createRequestBufferMiddleware, RequestBufferMiddleware } from './middleware';
41
43
  export { OrbitEcho } from './OrbitEcho';
44
+ export type { EchoLogEvent, EchoLogger } from './observability/logging';
45
+ export { ConsoleEchoLogger } from './observability/logging';
46
+ export type { MetricsProvider, WebhookMetricLabels } from './observability/metrics';
47
+ export { EchoMetrics, NoopMetricsProvider, PrometheusMetricsProvider, } from './observability/metrics';
48
+ export type { Span, SpanOptions, Tracer } from './observability/tracing';
49
+ export { NoopSpan, NoopTracer, SpanStatusCode } from './observability/tracing';
50
+ export { BaseProvider, type ProviderOptions } from './providers/base/BaseProvider';
42
51
  export { GenericProvider } from './providers/GenericProvider';
43
52
  export { GitHubProvider } from './providers/GitHubProvider';
53
+ export { LinearProvider } from './providers/LinearProvider';
54
+ export { PaddleProvider } from './providers/PaddleProvider';
55
+ export { ShopifyProvider } from './providers/ShopifyProvider';
56
+ export { SlackProvider } from './providers/SlackProvider';
44
57
  export { StripeProvider } from './providers/StripeProvider';
58
+ export { TwilioProvider } from './providers/TwilioProvider';
45
59
  export { computeHmacSha1, computeHmacSha256, parseStripeSignature, timingSafeEqual, validateTimestamp, } from './receive/SignatureValidator';
46
60
  export { WebhookReceiver } from './receive/WebhookReceiver';
47
- export { WebhookDispatcher } from './send/WebhookDispatcher';
48
- export type { EchoConfig, RetryConfig, WebhookDeliveryResult, WebhookDispatcherConfig, WebhookEvent, WebhookHandler, WebhookPayload, WebhookProvider, WebhookProviderConfig, WebhookVerificationResult, } from './types';
49
- //# sourceMappingURL=index.d.ts.map
61
+ export { WebhookReplayService } from './replay/WebhookReplayService';
62
+ export { CircuitBreaker } from './resilience';
63
+ export { KeyRotationManager } from './rotation';
64
+ export type { BufferedRequest, CircuitBreakerConfig, CircuitBreakerMetrics, CircuitBreakerState, EchoConfig, EchoObservabilityConfig, KeyRotationConfig, ProviderKeyEntry, ReplayOptions, ReplayResult, RequestBufferConfig, RetryConfig, WebhookDeliveryResult, WebhookDispatcherConfig, WebhookEvent, WebhookHandler, WebhookPayload, WebhookProvider, WebhookProviderConfig, WebhookProviderConfigWithRotation, WebhookVerificationResult, } from './types';