@gravito/echo 3.0.1 → 3.1.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 (173) hide show
  1. package/README.md +211 -0
  2. package/dist/atlas/src/DB.d.ts +301 -0
  3. package/dist/atlas/src/OrbitAtlas.d.ts +9 -0
  4. package/dist/atlas/src/config/defineConfig.d.ts +14 -0
  5. package/dist/atlas/src/config/index.d.ts +7 -0
  6. package/dist/atlas/src/config/loadConfig.d.ts +48 -0
  7. package/dist/atlas/src/connection/Connection.d.ts +108 -0
  8. package/dist/atlas/src/connection/ConnectionManager.d.ts +111 -0
  9. package/dist/atlas/src/drivers/BunSQLDriver.d.ts +32 -0
  10. package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +118 -0
  11. package/dist/atlas/src/drivers/MongoDBDriver.d.ts +36 -0
  12. package/dist/atlas/src/drivers/MySQLDriver.d.ts +66 -0
  13. package/dist/atlas/src/drivers/PostgresDriver.d.ts +83 -0
  14. package/dist/atlas/src/drivers/RedisDriver.d.ts +43 -0
  15. package/dist/atlas/src/drivers/SQLiteDriver.d.ts +45 -0
  16. package/dist/atlas/src/drivers/types.d.ts +260 -0
  17. package/dist/atlas/src/errors/index.d.ts +45 -0
  18. package/dist/atlas/src/grammar/Grammar.d.ts +342 -0
  19. package/dist/atlas/src/grammar/MongoGrammar.d.ts +47 -0
  20. package/dist/atlas/src/grammar/MySQLGrammar.d.ts +54 -0
  21. package/dist/atlas/src/grammar/NullGrammar.d.ts +35 -0
  22. package/dist/atlas/src/grammar/PostgresGrammar.d.ts +62 -0
  23. package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +32 -0
  24. package/dist/atlas/src/index.d.ts +67 -0
  25. package/dist/atlas/src/migration/Migration.d.ts +64 -0
  26. package/dist/atlas/src/migration/MigrationRepository.d.ts +65 -0
  27. package/dist/atlas/src/migration/Migrator.d.ts +110 -0
  28. package/dist/atlas/src/migration/index.d.ts +6 -0
  29. package/dist/atlas/src/observability/AtlasMetrics.d.ts +11 -0
  30. package/dist/atlas/src/observability/AtlasObservability.d.ts +15 -0
  31. package/dist/atlas/src/observability/AtlasTracer.d.ts +12 -0
  32. package/dist/atlas/src/observability/index.d.ts +9 -0
  33. package/dist/atlas/src/orm/index.d.ts +5 -0
  34. package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
  35. package/dist/atlas/src/orm/model/Model.d.ts +449 -0
  36. package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
  37. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +136 -0
  38. package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
  39. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +87 -0
  40. package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +117 -0
  41. package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +64 -0
  42. package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +15 -0
  43. package/dist/atlas/src/orm/model/concerns/index.d.ts +12 -0
  44. package/dist/atlas/src/orm/model/decorators.d.ts +109 -0
  45. package/dist/atlas/src/orm/model/errors.d.ts +52 -0
  46. package/dist/atlas/src/orm/model/index.d.ts +10 -0
  47. package/dist/atlas/src/orm/model/relationships.d.ts +207 -0
  48. package/dist/atlas/src/orm/model/types.d.ts +12 -0
  49. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +123 -0
  50. package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +54 -0
  51. package/dist/atlas/src/orm/schema/index.d.ts +6 -0
  52. package/dist/atlas/src/orm/schema/types.d.ts +85 -0
  53. package/dist/atlas/src/query/Expression.d.ts +60 -0
  54. package/dist/atlas/src/query/NPlusOneDetector.d.ts +10 -0
  55. package/dist/atlas/src/query/QueryBuilder.d.ts +573 -0
  56. package/dist/atlas/src/query/clauses/GroupByClause.d.ts +51 -0
  57. package/dist/atlas/src/query/clauses/HavingClause.d.ts +70 -0
  58. package/dist/atlas/src/query/clauses/JoinClause.d.ts +87 -0
  59. package/dist/atlas/src/query/clauses/LimitClause.d.ts +82 -0
  60. package/dist/atlas/src/query/clauses/OrderByClause.d.ts +69 -0
  61. package/dist/atlas/src/query/clauses/SelectClause.d.ts +71 -0
  62. package/dist/atlas/src/query/clauses/WhereClause.d.ts +167 -0
  63. package/dist/atlas/src/query/clauses/index.d.ts +11 -0
  64. package/dist/atlas/src/schema/Blueprint.d.ts +276 -0
  65. package/dist/atlas/src/schema/ColumnDefinition.d.ts +154 -0
  66. package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +37 -0
  67. package/dist/atlas/src/schema/Schema.d.ts +131 -0
  68. package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +23 -0
  69. package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +26 -0
  70. package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +28 -0
  71. package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +97 -0
  72. package/dist/atlas/src/schema/grammars/index.d.ts +7 -0
  73. package/dist/atlas/src/schema/index.d.ts +8 -0
  74. package/dist/atlas/src/seed/Factory.d.ts +90 -0
  75. package/dist/atlas/src/seed/Seeder.d.ts +28 -0
  76. package/dist/atlas/src/seed/SeederRunner.d.ts +74 -0
  77. package/dist/atlas/src/seed/index.d.ts +6 -0
  78. package/dist/atlas/src/types/index.d.ts +1100 -0
  79. package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
  80. package/dist/core/src/Application.d.ts +43 -17
  81. package/dist/core/src/CommandKernel.d.ts +33 -0
  82. package/dist/core/src/Container.d.ts +78 -14
  83. package/dist/core/src/HookManager.d.ts +422 -8
  84. package/dist/core/src/PlanetCore.d.ts +52 -7
  85. package/dist/core/src/Router.d.ts +41 -7
  86. package/dist/core/src/ServiceProvider.d.ts +14 -8
  87. package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +1 -0
  88. package/dist/core/src/adapters/PhotonAdapter.d.ts +1 -0
  89. package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +1 -0
  90. package/dist/core/src/adapters/types.d.ts +39 -0
  91. package/dist/core/src/engine/AOTRouter.d.ts +1 -11
  92. package/dist/core/src/engine/FastContext.d.ts +4 -2
  93. package/dist/core/src/engine/Gravito.d.ts +1 -1
  94. package/dist/core/src/engine/MinimalContext.d.ts +4 -2
  95. package/dist/core/src/engine/types.d.ts +6 -1
  96. package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
  97. package/dist/core/src/events/DeadLetterQueue.d.ts +145 -0
  98. package/dist/core/src/events/EventBackend.d.ts +11 -0
  99. package/dist/core/src/events/EventOptions.d.ts +109 -0
  100. package/dist/core/src/events/EventPriorityQueue.d.ts +202 -0
  101. package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
  102. package/dist/core/src/events/index.d.ts +14 -0
  103. package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
  104. package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
  105. package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
  106. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +240 -0
  107. package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
  108. package/dist/core/src/events/observability/index.d.ts +20 -0
  109. package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
  110. package/dist/core/src/events/types.d.ts +75 -0
  111. package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
  112. package/dist/core/src/exceptions/index.d.ts +1 -0
  113. package/dist/core/src/http/cookie.d.ts +29 -0
  114. package/dist/core/src/http/types.d.ts +21 -0
  115. package/dist/core/src/index.d.ts +13 -3
  116. package/dist/core/src/instrumentation/index.d.ts +35 -0
  117. package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
  118. package/dist/core/src/instrumentation/types.d.ts +182 -0
  119. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +316 -0
  120. package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
  121. package/dist/core/src/reliability/index.d.ts +6 -0
  122. package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
  123. package/dist/core/src/router/RequestValidator.d.ts +20 -0
  124. package/dist/echo/src/OrbitEcho.d.ts +71 -16
  125. package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
  126. package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
  127. package/dist/echo/src/dlq/index.d.ts +2 -0
  128. package/dist/echo/src/index.d.ts +31 -15
  129. package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
  130. package/dist/echo/src/middleware/index.d.ts +8 -0
  131. package/dist/echo/src/observability/index.d.ts +3 -0
  132. package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
  133. package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
  134. package/dist/echo/src/observability/logging/index.d.ts +2 -0
  135. package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
  136. package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
  137. package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
  138. package/dist/echo/src/observability/metrics/index.d.ts +3 -0
  139. package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
  140. package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
  141. package/dist/echo/src/observability/tracing/index.d.ts +2 -0
  142. package/dist/echo/src/providers/GenericProvider.d.ts +37 -18
  143. package/dist/echo/src/providers/GitHubProvider.d.ts +21 -12
  144. package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
  145. package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
  146. package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
  147. package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
  148. package/dist/echo/src/providers/StripeProvider.d.ts +20 -12
  149. package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
  150. package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
  151. package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
  152. package/dist/echo/src/providers/index.d.ts +14 -3
  153. package/dist/echo/src/receive/SignatureValidator.d.ts +33 -0
  154. package/dist/echo/src/receive/WebhookReceiver.d.ts +139 -21
  155. package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
  156. package/dist/echo/src/replay/index.d.ts +1 -0
  157. package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
  158. package/dist/echo/src/resilience/index.d.ts +10 -0
  159. package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
  160. package/dist/echo/src/rotation/index.d.ts +10 -0
  161. package/dist/echo/src/send/WebhookDispatcher.d.ts +159 -15
  162. package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
  163. package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
  164. package/dist/echo/src/storage/index.d.ts +2 -0
  165. package/dist/echo/src/types.d.ts +656 -64
  166. package/dist/index.js +1327 -189
  167. package/dist/index.js.map +28 -10
  168. package/dist/photon/src/index.d.ts +69 -5
  169. package/dist/photon/src/middleware/binary.d.ts +12 -15
  170. package/dist/photon/src/middleware/htmx.d.ts +39 -0
  171. package/dist/photon/src/middleware/ratelimit.d.ts +157 -0
  172. package/dist/photon/src/openapi.d.ts +19 -0
  173. package/package.json +7 -5
@@ -0,0 +1,37 @@
1
+ import type { EchoLogger } from './EchoLogger';
2
+ /**
3
+ * A basic implementation of {@link EchoLogger} that outputs logs to the system console.
4
+ * Logs are formatted as JSON strings to facilitate integration with log aggregators.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const logger = new ConsoleEchoLogger();
9
+ * logger.info('Service started');
10
+ * ```
11
+ */
12
+ export declare class ConsoleEchoLogger implements EchoLogger {
13
+ /**
14
+ * Enriches the log context with default module information and timestamps.
15
+ *
16
+ * @param base - The base context object.
17
+ * @param extra - Additional metadata to include.
18
+ * @returns A merged context object.
19
+ */
20
+ private formatContext;
21
+ /**
22
+ * Outputs a debug-level log entry.
23
+ */
24
+ debug(message: string, context?: Record<string, unknown>): void;
25
+ /**
26
+ * Outputs an info-level log entry.
27
+ */
28
+ info(message: string, context?: Record<string, unknown>): void;
29
+ /**
30
+ * Outputs a warn-level log entry.
31
+ */
32
+ warn(message: string, context?: Record<string, unknown>): void;
33
+ /**
34
+ * Outputs an error-level log entry.
35
+ */
36
+ error(message: string, context?: Record<string, unknown>): void;
37
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Represents a structured log event within the Echo module.
3
+ * Used to ensure consistency across different logging implementations.
4
+ */
5
+ export interface EchoLogEvent {
6
+ /** Severity level of the log entry. */
7
+ level: 'debug' | 'info' | 'warn' | 'error';
8
+ /** Human-readable message describing the event. */
9
+ message: string;
10
+ /** Contextual metadata for better traceability. */
11
+ context: {
12
+ /** Always 'echo' to identify the source module. */
13
+ module: 'echo';
14
+ /** The specific sub-component triggering the log. */
15
+ component: 'receiver' | 'dispatcher' | 'dlq' | 'replay';
16
+ [key: string]: unknown;
17
+ };
18
+ }
19
+ /**
20
+ * Defines the standard logging interface for the Echo module.
21
+ * Implementations should handle structured data for observability.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const logger: EchoLogger = new ConsoleEchoLogger();
26
+ * logger.info('Webhook received', { provider: 'stripe' });
27
+ * ```
28
+ */
29
+ export interface EchoLogger {
30
+ /** Logs fine-grained informational events that are most useful to debug an application. */
31
+ debug(message: string, context?: Record<string, unknown>): void;
32
+ /** Logs informational messages that highlight the progress of the application at coarse-grained level. */
33
+ info(message: string, context?: Record<string, unknown>): void;
34
+ /** Logs potentially harmful situations. */
35
+ warn(message: string, context?: Record<string, unknown>): void;
36
+ /** Logs error events that might still allow the application to continue running. */
37
+ error(message: string, context?: Record<string, unknown>): void;
38
+ }
@@ -0,0 +1,2 @@
1
+ export * from './ConsoleEchoLogger';
2
+ export * from './EchoLogger';
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Defines the interface for collecting application metrics.
3
+ * Implementations can bridge to Prometheus, StatsD, or other monitoring systems.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * const metrics: MetricsProvider = getMetrics();
8
+ * metrics.increment(EchoMetrics.INCOMING_TOTAL, { provider: 'stripe' });
9
+ * ```
10
+ */
11
+ export interface MetricsProvider {
12
+ /**
13
+ * Increments a counter by 1.
14
+ * Counters are used for values that only increase (e.g., total requests).
15
+ */
16
+ increment(name: string, labels?: Record<string, string>): void;
17
+ /**
18
+ * Records a value in a histogram.
19
+ * Histograms are used to track the distribution of values (e.g., request latency).
20
+ */
21
+ histogram(name: string, value: number, labels?: Record<string, string>): void;
22
+ /**
23
+ * Sets a gauge to a specific value.
24
+ * Gauges are used for values that can go up and down (e.g., current queue size).
25
+ */
26
+ gauge(name: string, value: number, labels?: Record<string, string>): void;
27
+ }
28
+ /**
29
+ * Common labels used for webhook-related metrics.
30
+ */
31
+ export interface WebhookMetricLabels {
32
+ /** The webhook provider name (e.g., 'stripe', 'github'). */
33
+ provider?: string;
34
+ /** The type of event received or sent. */
35
+ event_type?: string;
36
+ /** The outcome of the operation. */
37
+ status?: 'success' | 'failure';
38
+ /** The HTTP status code returned by the remote server. */
39
+ status_code?: string;
40
+ /** A category for the error if the operation failed. */
41
+ error_type?: string;
42
+ [key: string]: string | undefined;
43
+ }
44
+ /**
45
+ * Standard metric names used across the Echo module.
46
+ * Use these constants to ensure consistency in dashboards and alerts.
47
+ */
48
+ export declare const EchoMetrics: {
49
+ /** Total number of incoming webhooks received. */
50
+ readonly INCOMING_TOTAL: "echo_incoming_webhooks_total";
51
+ /** Time taken to process an incoming webhook. */
52
+ readonly INCOMING_DURATION: "echo_incoming_duration_seconds";
53
+ /** Total number of incoming webhooks that failed signature verification. */
54
+ readonly INCOMING_VERIFICATION_FAILURES: "echo_incoming_verification_failures_total";
55
+ /** Total number of outgoing webhooks dispatched. */
56
+ readonly OUTGOING_TOTAL: "echo_outgoing_webhooks_total";
57
+ /** Time taken to deliver an outgoing webhook. */
58
+ readonly OUTGOING_DURATION: "echo_outgoing_duration_seconds";
59
+ /** Total number of retry attempts for outgoing webhooks. */
60
+ readonly OUTGOING_RETRIES: "echo_outgoing_retries_total";
61
+ /** Total number of outgoing webhooks that failed after all retries. */
62
+ readonly OUTGOING_FAILURES: "echo_outgoing_failures_total";
63
+ /** Current number of items in the Dead Letter Queue. */
64
+ readonly DLQ_SIZE: "echo_dlq_size";
65
+ /** Total number of items added to the DLQ. */
66
+ readonly DLQ_ENQUEUED: "echo_dlq_enqueued_total";
67
+ /** Total number of items successfully processed from the DLQ. */
68
+ readonly DLQ_PROCESSED: "echo_dlq_processed_total";
69
+ };
@@ -0,0 +1,17 @@
1
+ import type { MetricsProvider } from './MetricsProvider';
2
+ /**
3
+ * A non-operational implementation of {@link MetricsProvider}.
4
+ * Used as the default provider to ensure the application remains functional
5
+ * even if no monitoring system is configured.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const metrics = new NoopMetricsProvider();
10
+ * metrics.increment('any_metric'); // Does nothing
11
+ * ```
12
+ */
13
+ export declare class NoopMetricsProvider implements MetricsProvider {
14
+ increment(): void;
15
+ histogram(): void;
16
+ gauge(): void;
17
+ }
@@ -0,0 +1,39 @@
1
+ import type { MetricsProvider } from './MetricsProvider';
2
+ /**
3
+ * A Prometheus-compatible metrics provider.
4
+ * Collects and formats metrics in the Prometheus text-based format.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const provider = new PrometheusMetricsProvider();
9
+ * provider.increment('http_requests_total', { method: 'POST' });
10
+ * console.log(provider.export());
11
+ * ```
12
+ */
13
+ export declare class PrometheusMetricsProvider implements MetricsProvider {
14
+ private counters;
15
+ private histograms;
16
+ private gauges;
17
+ /**
18
+ * Increments a counter for the given name and labels.
19
+ */
20
+ increment(name: string, labels?: Record<string, string>): void;
21
+ /**
22
+ * Records a value in a histogram for the given name and labels.
23
+ */
24
+ histogram(name: string, value: number, labels?: Record<string, string>): void;
25
+ /**
26
+ * Sets a gauge to a specific value for the given name and labels.
27
+ */
28
+ gauge(name: string, value: number, labels?: Record<string, string>): void;
29
+ /**
30
+ * Exports all collected metrics in Prometheus text format.
31
+ *
32
+ * @returns A string containing the formatted metrics.
33
+ */
34
+ export(): string;
35
+ /**
36
+ * Builds a Prometheus-compatible metric key with labels.
37
+ */
38
+ private buildKey;
39
+ }
@@ -0,0 +1,3 @@
1
+ export * from './MetricsProvider';
2
+ export * from './NoopMetricsProvider';
3
+ export * from './PrometheusMetricsProvider';
@@ -0,0 +1,33 @@
1
+ import type { Span, Tracer } from './Tracer';
2
+ /**
3
+ * A non-operational implementation of {@link Span}.
4
+ * Used as a fallback when tracing is disabled to avoid null checks.
5
+ */
6
+ export declare class NoopSpan implements Span {
7
+ setAttribute(): this;
8
+ setAttributes(): this;
9
+ addEvent(): this;
10
+ setStatus(): this;
11
+ end(): void;
12
+ }
13
+ /**
14
+ * A non-operational implementation of {@link Tracer}.
15
+ * Ensures the application can run without a tracing backend.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const tracer = new NoopTracer();
20
+ * const span = tracer.startSpan('test');
21
+ * span.end();
22
+ * ```
23
+ */
24
+ export declare class NoopTracer implements Tracer {
25
+ /**
26
+ * Returns a {@link NoopSpan} that does nothing.
27
+ */
28
+ startSpan(): Span;
29
+ /**
30
+ * Executes the function with a {@link NoopSpan}.
31
+ */
32
+ withSpan<T>(_name: string, fn: (span: Span) => T | Promise<T>): Promise<T>;
33
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Represents a single unit of work in a trace.
3
+ * Compatible with OpenTelemetry Span interface to allow seamless integration.
4
+ */
5
+ export interface Span {
6
+ /**
7
+ * Sets a single attribute on the span.
8
+ * Attributes provide additional metadata for the operation.
9
+ */
10
+ setAttribute(key: string, value: string | number | boolean): this;
11
+ /**
12
+ * Sets multiple attributes on the span at once.
13
+ */
14
+ setAttributes(attributes: Record<string, string | number | boolean>): this;
15
+ /**
16
+ * Records a specific event that occurred during the span's lifetime.
17
+ */
18
+ addEvent(name: string, attributes?: Record<string, string | number>): this;
19
+ /**
20
+ * Sets the final status of the span.
21
+ */
22
+ setStatus(status: {
23
+ code: SpanStatusCode;
24
+ message?: string;
25
+ }): this;
26
+ /**
27
+ * Marks the end of the span, making it ready for export.
28
+ */
29
+ end(): void;
30
+ }
31
+ /**
32
+ * Standard status codes for a {@link Span}.
33
+ */
34
+ export declare enum SpanStatusCode {
35
+ /** Default status. */
36
+ UNSET = 0,
37
+ /** Operation completed successfully. */
38
+ OK = 1,
39
+ /** Operation failed. */
40
+ ERROR = 2
41
+ }
42
+ /**
43
+ * Defines the tracing interface for the Echo module.
44
+ * Used to track the lifecycle of webhook requests and deliveries.
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const tracer: Tracer = getTracer();
49
+ * await tracer.withSpan('process-webhook', async (span) => {
50
+ * span.setAttribute('provider', 'stripe');
51
+ * // ... logic
52
+ * });
53
+ * ```
54
+ */
55
+ export interface Tracer {
56
+ /**
57
+ * Starts a new span without making it active.
58
+ * The caller is responsible for ending the span.
59
+ */
60
+ startSpan(name: string, options?: SpanOptions): Span;
61
+ /**
62
+ * Executes a function within the context of a new span.
63
+ * Automatically ends the span when the function completes.
64
+ */
65
+ withSpan<T>(name: string, fn: (span: Span) => T | Promise<T>): Promise<T>;
66
+ }
67
+ /**
68
+ * Configuration options for starting a new {@link Span}.
69
+ */
70
+ export interface SpanOptions {
71
+ /** The relationship between the span and its neighbors. */
72
+ kind?: 'client' | 'server' | 'producer' | 'consumer' | 'internal';
73
+ /** Initial attributes to set on the span. */
74
+ attributes?: Record<string, string | number | boolean>;
75
+ }
@@ -0,0 +1,2 @@
1
+ export * from './NoopTracer';
2
+ export * from './Tracer';
@@ -1,34 +1,53 @@
1
1
  /**
2
- * @fileoverview Generic webhook provider
3
- *
4
- * Simple HMAC-SHA256 signature verification.
5
- *
2
+ * Generic webhook provider.
6
3
  * @module @gravito/echo/providers
7
4
  */
8
- import type { WebhookProvider, WebhookVerificationResult } from '../types';
5
+ import type { WebhookVerificationResult } from '../types';
6
+ import { BaseProvider, type ProviderOptions } from './base/BaseProvider';
7
+ /**
8
+ * Configuration options for the generic provider.
9
+ */
10
+ export interface GenericProviderOptions extends ProviderOptions {
11
+ /**
12
+ * Custom header name for the signature.
13
+ * @defaultValue 'x-webhook-signature'
14
+ */
15
+ signatureHeader?: string;
16
+ /**
17
+ * Custom header name for the timestamp.
18
+ * @defaultValue 'x-webhook-timestamp'
19
+ */
20
+ timestampHeader?: string;
21
+ }
9
22
  /**
10
- * Generic webhook provider using HMAC-SHA256
23
+ * Generic webhook provider using HMAC-SHA256 for signature verification.
11
24
  *
12
25
  * Expected headers:
13
- * - X-Webhook-Signature: HMAC-SHA256 hex signature
14
- * - X-Webhook-Timestamp: Unix timestamp (optional)
26
+ * - X-Webhook-Signature: HMAC-SHA256 hex signature.
27
+ * - X-Webhook-Timestamp: Unix timestamp (optional, used for replay protection).
15
28
  *
16
29
  * @example
17
30
  * ```typescript
18
- * const provider = new GenericProvider()
19
- * const result = await provider.verify(body, headers, secret)
31
+ * const provider = new GenericProvider({
32
+ * signatureHeader: 'X-Custom-Sig',
33
+ * tolerance: 600
34
+ * });
35
+ * const result = await provider.verify(body, headers, secret);
20
36
  * ```
21
37
  */
22
- export declare class GenericProvider implements WebhookProvider {
38
+ export declare class GenericProvider extends BaseProvider {
23
39
  readonly name = "generic";
24
40
  private signatureHeader;
25
41
  private timestampHeader;
26
- private tolerance;
27
- constructor(options?: {
28
- signatureHeader?: string;
29
- timestampHeader?: string;
30
- tolerance?: number;
31
- });
42
+ constructor(options?: GenericProviderOptions);
43
+ /**
44
+ * Verifies the webhook using HMAC-SHA256.
45
+ *
46
+ * @param payload - Raw request body.
47
+ * @param headers - Request headers.
48
+ * @param secret - Secret key for HMAC computation.
49
+ * @returns Verification result.
50
+ * @throws Error if signature computation fails.
51
+ */
32
52
  verify(payload: string | Buffer, headers: Record<string, string | string[] | undefined>, secret: string): Promise<WebhookVerificationResult>;
33
- private getHeader;
34
53
  }
@@ -1,26 +1,35 @@
1
1
  /**
2
- * @fileoverview GitHub webhook provider
3
- *
4
- * Implements GitHub's webhook signature verification.
5
- * @see https://docs.github.com/en/webhooks/using-webhooks/validating-webhook-deliveries
6
- *
2
+ * GitHub webhook provider.
7
3
  * @module @gravito/echo/providers
8
4
  */
9
- import type { WebhookProvider, WebhookVerificationResult } from '../types';
5
+ import type { WebhookVerificationResult } from '../types';
6
+ import { BaseProvider } from './base/BaseProvider';
10
7
  /**
11
- * GitHub webhook provider
8
+ * GitHub webhook provider.
12
9
  *
13
- * Verifies GitHub webhook signatures using the X-Hub-Signature-256 header.
10
+ * Verifies GitHub webhook signatures using the `X-Hub-Signature-256` header.
11
+ * @see {@link https://docs.github.com/en/webhooks/using-webhooks/validating-webhook-deliveries | GitHub Webhook Validation}
14
12
  *
15
13
  * @example
16
14
  * ```typescript
17
- * const provider = new GitHubProvider()
18
- * const result = await provider.verify(body, headers, process.env.GITHUB_WEBHOOK_SECRET)
15
+ * const provider = new GitHubProvider();
16
+ * const result = await provider.verify(body, headers, process.env.GITHUB_WEBHOOK_SECRET);
19
17
  * ```
20
18
  */
21
- export declare class GitHubProvider implements WebhookProvider {
19
+ export declare class GitHubProvider extends BaseProvider {
22
20
  readonly name = "github";
21
+ /**
22
+ * Verifies the GitHub webhook signature.
23
+ *
24
+ * @param payload - Raw request body.
25
+ * @param headers - Request headers.
26
+ * @param secret - GitHub webhook secret.
27
+ * @returns Verification result.
28
+ * @throws Error if signature computation fails.
29
+ */
23
30
  verify(payload: string | Buffer, headers: Record<string, string | string[] | undefined>, secret: string): Promise<WebhookVerificationResult>;
31
+ /**
32
+ * Extracts the action from the GitHub payload if available.
33
+ */
24
34
  parseEventType(payload: unknown): string | undefined;
25
- private getHeader;
26
35
  }
@@ -0,0 +1,27 @@
1
+ import type { WebhookVerificationResult } from '../types';
2
+ import { BaseProvider } from './base/BaseProvider';
3
+ /**
4
+ * Linear webhook provider.
5
+ *
6
+ * Verifies Linear webhook signatures using the `Linear-Signature` header.
7
+ * @see {@link https://developers.linear.app/docs/graphql/webhooks#signature-verification | Linear Webhook Verification}
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const provider = new LinearProvider();
12
+ * const result = await provider.verify(body, headers, process.env.LINEAR_WEBHOOK_SECRET);
13
+ * ```
14
+ */
15
+ export declare class LinearProvider extends BaseProvider {
16
+ readonly name = "linear";
17
+ /**
18
+ * Verifies the Linear webhook signature.
19
+ *
20
+ * @param payload - Raw request body.
21
+ * @param headers - Request headers.
22
+ * @param secret - Linear webhook secret.
23
+ * @returns Verification result.
24
+ * @throws Error if signature computation fails.
25
+ */
26
+ verify(payload: string | Buffer, headers: Record<string, string | string[] | undefined>, secret: string): Promise<WebhookVerificationResult>;
27
+ }
@@ -0,0 +1,31 @@
1
+ import type { WebhookVerificationResult } from '../types';
2
+ import { BaseProvider } from './base/BaseProvider';
3
+ /**
4
+ * Paddle webhook provider.
5
+ *
6
+ * Verifies Paddle webhook signatures using the `Paddle-Signature` header.
7
+ * @see {@link https://developer.paddle.com/webhooks/signature-verification | Paddle Signature Verification}
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const provider = new PaddleProvider();
12
+ * const result = await provider.verify(body, headers, process.env.PADDLE_WEBHOOK_SECRET);
13
+ * ```
14
+ */
15
+ export declare class PaddleProvider extends BaseProvider {
16
+ readonly name = "paddle";
17
+ /**
18
+ * Verifies the Paddle webhook signature.
19
+ *
20
+ * @param payload - Raw request body.
21
+ * @param headers - Request headers.
22
+ * @param secret - Paddle webhook secret.
23
+ * @returns Verification result.
24
+ * @throws Error if signature computation fails.
25
+ */
26
+ verify(payload: string | Buffer, headers: Record<string, string | string[] | undefined>, secret: string): Promise<WebhookVerificationResult>;
27
+ /**
28
+ * Parses the Paddle-Signature header into timestamp and signature components.
29
+ */
30
+ private parsePaddleSignature;
31
+ }
@@ -0,0 +1,27 @@
1
+ import type { WebhookVerificationResult } from '../types';
2
+ import { BaseProvider } from './base/BaseProvider';
3
+ /**
4
+ * Shopify webhook provider.
5
+ *
6
+ * Verifies Shopify webhook signatures using the `X-Shopify-Hmac-Sha256` header.
7
+ * @see {@link https://shopify.dev/docs/apps/webhooks/configuration/https#verify-webhook | Shopify Webhook Verification}
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const provider = new ShopifyProvider();
12
+ * const result = await provider.verify(body, headers, process.env.SHOPIFY_WEBHOOK_SECRET);
13
+ * ```
14
+ */
15
+ export declare class ShopifyProvider extends BaseProvider {
16
+ readonly name = "shopify";
17
+ /**
18
+ * Verifies the Shopify webhook signature.
19
+ *
20
+ * @param payload - Raw request body.
21
+ * @param headers - Request headers.
22
+ * @param secret - Shopify webhook secret.
23
+ * @returns Verification result.
24
+ * @throws Error if signature computation fails.
25
+ */
26
+ verify(payload: string | Buffer, headers: Record<string, string | string[] | undefined>, secret: string): Promise<WebhookVerificationResult>;
27
+ }
@@ -0,0 +1,27 @@
1
+ import type { WebhookVerificationResult } from '../types';
2
+ import { BaseProvider } from './base/BaseProvider';
3
+ /**
4
+ * Slack webhook provider.
5
+ *
6
+ * Verifies Slack webhook signatures using the `X-Slack-Signature` and `X-Slack-Request-Timestamp` headers.
7
+ * @see {@link https://api.slack.com/authentication/verifying-requests-from-slack | Slack Request Verification}
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const provider = new SlackProvider();
12
+ * const result = await provider.verify(body, headers, process.env.SLACK_SIGNING_SECRET);
13
+ * ```
14
+ */
15
+ export declare class SlackProvider extends BaseProvider {
16
+ readonly name = "slack";
17
+ /**
18
+ * Verifies the Slack webhook signature.
19
+ *
20
+ * @param payload - Raw request body.
21
+ * @param headers - Request headers.
22
+ * @param secret - Slack signing secret.
23
+ * @returns Verification result.
24
+ * @throws Error if signature computation fails.
25
+ */
26
+ verify(payload: string | Buffer, headers: Record<string, string | string[] | undefined>, secret: string): Promise<WebhookVerificationResult>;
27
+ }
@@ -1,30 +1,38 @@
1
1
  /**
2
- * @fileoverview Stripe webhook provider
3
- *
4
- * Implements Stripe's webhook signature verification.
5
- * @see https://stripe.com/docs/webhooks/signatures
6
- *
2
+ * Stripe webhook provider.
7
3
  * @module @gravito/echo/providers
8
4
  */
9
- import type { WebhookProvider, WebhookVerificationResult } from '../types';
5
+ import type { WebhookVerificationResult } from '../types';
6
+ import { BaseProvider } from './base/BaseProvider';
10
7
  /**
11
- * Stripe webhook provider
8
+ * Stripe webhook provider.
12
9
  *
13
10
  * Verifies Stripe webhook signatures using their standard format.
11
+ * @see {@link https://stripe.com/docs/webhooks/signatures | Stripe Webhook Signatures}
14
12
  *
15
13
  * @example
16
14
  * ```typescript
17
- * const provider = new StripeProvider()
18
- * const result = await provider.verify(body, headers, process.env.STRIPE_WEBHOOK_SECRET)
15
+ * const provider = new StripeProvider();
16
+ * const result = await provider.verify(body, headers, process.env.STRIPE_WEBHOOK_SECRET);
19
17
  * ```
20
18
  */
21
- export declare class StripeProvider implements WebhookProvider {
19
+ export declare class StripeProvider extends BaseProvider {
22
20
  readonly name = "stripe";
23
- private tolerance;
24
21
  constructor(options?: {
25
22
  tolerance?: number;
26
23
  });
24
+ /**
25
+ * Verifies the Stripe webhook signature.
26
+ *
27
+ * @param payload - Raw request body.
28
+ * @param headers - Request headers.
29
+ * @param secret - Stripe webhook secret (signing secret).
30
+ * @returns Verification result.
31
+ * @throws Error if signature computation fails.
32
+ */
27
33
  verify(payload: string | Buffer, headers: Record<string, string | string[] | undefined>, secret: string): Promise<WebhookVerificationResult>;
34
+ /**
35
+ * Extracts the event type from the Stripe payload.
36
+ */
28
37
  parseEventType(payload: unknown): string | undefined;
29
- private getHeader;
30
38
  }
@@ -0,0 +1,31 @@
1
+ import type { WebhookVerificationResult } from '../types';
2
+ import { BaseProvider, type ProviderOptions } from './base/BaseProvider';
3
+ /**
4
+ * Twilio webhook provider.
5
+ *
6
+ * Verifies Twilio webhook signatures using the `X-Twilio-Signature` header.
7
+ * @see {@link https://www.twilio.com/docs/usage/security#validating-requests | Twilio Request Validation}
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const provider = new TwilioProvider({ baseUrl: 'https://api.example.com/webhooks/twilio' });
12
+ * const result = await provider.verify(body, headers, process.env.TWILIO_AUTH_TOKEN);
13
+ * ```
14
+ */
15
+ export declare class TwilioProvider extends BaseProvider {
16
+ readonly name = "twilio";
17
+ private baseUrl?;
18
+ constructor(options?: ProviderOptions & {
19
+ baseUrl?: string;
20
+ });
21
+ /**
22
+ * Verifies the Twilio webhook signature.
23
+ *
24
+ * @param payload - Raw request body (URL-encoded).
25
+ * @param headers - Request headers.
26
+ * @param secret - Twilio Auth Token.
27
+ * @returns Verification result.
28
+ * @throws Error if signature computation fails.
29
+ */
30
+ verify(payload: string | Buffer, headers: Record<string, string | string[] | undefined>, secret: string): Promise<WebhookVerificationResult>;
31
+ }