@gravito/echo 3.0.1 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +211 -0
- package/dist/atlas/src/DB.d.ts +348 -0
- package/dist/atlas/src/OrbitAtlas.d.ts +9 -0
- package/dist/atlas/src/config/defineConfig.d.ts +14 -0
- package/dist/atlas/src/config/index.d.ts +7 -0
- package/dist/atlas/src/config/loadConfig.d.ts +41 -0
- package/dist/atlas/src/connection/Connection.d.ts +112 -0
- package/dist/atlas/src/connection/ConnectionManager.d.ts +180 -0
- package/dist/atlas/src/connection/ReplicaConnectionPool.d.ts +54 -0
- package/dist/atlas/src/drivers/BunSQLDriver.d.ts +32 -0
- package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +118 -0
- package/dist/atlas/src/drivers/MongoDBDriver.d.ts +36 -0
- package/dist/atlas/src/drivers/MySQLDriver.d.ts +79 -0
- package/dist/atlas/src/drivers/PostgresDriver.d.ts +96 -0
- package/dist/atlas/src/drivers/RedisDriver.d.ts +43 -0
- package/dist/atlas/src/drivers/SQLiteDriver.d.ts +45 -0
- package/dist/atlas/src/drivers/types.d.ts +260 -0
- package/dist/atlas/src/errors/index.d.ts +45 -0
- package/dist/atlas/src/grammar/Grammar.d.ts +342 -0
- package/dist/atlas/src/grammar/MongoGrammar.d.ts +47 -0
- package/dist/atlas/src/grammar/MySQLGrammar.d.ts +54 -0
- package/dist/atlas/src/grammar/NullGrammar.d.ts +35 -0
- package/dist/atlas/src/grammar/PostgresGrammar.d.ts +62 -0
- package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +32 -0
- package/dist/atlas/src/index.d.ts +79 -0
- package/dist/atlas/src/migration/Migration.d.ts +64 -0
- package/dist/atlas/src/migration/MigrationRepository.d.ts +65 -0
- package/dist/atlas/src/migration/Migrator.d.ts +110 -0
- package/dist/atlas/src/migration/index.d.ts +6 -0
- package/dist/atlas/src/observability/AtlasMetrics.d.ts +33 -0
- package/dist/atlas/src/observability/AtlasObservability.d.ts +15 -0
- package/dist/atlas/src/observability/AtlasTracer.d.ts +12 -0
- package/dist/atlas/src/observability/index.d.ts +9 -0
- package/dist/atlas/src/orm/Repository.d.ts +247 -0
- package/dist/atlas/src/orm/index.d.ts +6 -0
- package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
- package/dist/atlas/src/orm/model/Model.d.ts +458 -0
- package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
- package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +150 -0
- package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
- package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +92 -0
- package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +117 -0
- package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +64 -0
- package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +15 -0
- package/dist/atlas/src/orm/model/concerns/index.d.ts +12 -0
- package/dist/atlas/src/orm/model/decorators.d.ts +138 -0
- package/dist/atlas/src/orm/model/errors.d.ts +52 -0
- package/dist/atlas/src/orm/model/index.d.ts +10 -0
- package/dist/atlas/src/orm/model/relationships.d.ts +207 -0
- package/dist/atlas/src/orm/model/types.d.ts +12 -0
- package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +124 -0
- package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +54 -0
- package/dist/atlas/src/orm/schema/index.d.ts +6 -0
- package/dist/atlas/src/orm/schema/types.d.ts +85 -0
- package/dist/atlas/src/pool/AdaptivePoolManager.d.ts +98 -0
- package/dist/atlas/src/pool/PoolHealthChecker.d.ts +91 -0
- package/dist/atlas/src/pool/PoolStrategy.d.ts +129 -0
- package/dist/atlas/src/pool/PoolWarmer.d.ts +92 -0
- package/dist/atlas/src/query/Expression.d.ts +60 -0
- package/dist/atlas/src/query/NPlusOneDetector.d.ts +10 -0
- package/dist/atlas/src/query/QueryBuilder.d.ts +643 -0
- package/dist/atlas/src/query/RelationshipResolver.d.ts +23 -0
- package/dist/atlas/src/query/clauses/GroupByClause.d.ts +51 -0
- package/dist/atlas/src/query/clauses/HavingClause.d.ts +70 -0
- package/dist/atlas/src/query/clauses/JoinClause.d.ts +87 -0
- package/dist/atlas/src/query/clauses/LimitClause.d.ts +82 -0
- package/dist/atlas/src/query/clauses/OrderByClause.d.ts +69 -0
- package/dist/atlas/src/query/clauses/SelectClause.d.ts +71 -0
- package/dist/atlas/src/query/clauses/WhereClause.d.ts +167 -0
- package/dist/atlas/src/query/clauses/index.d.ts +11 -0
- package/dist/atlas/src/schema/Blueprint.d.ts +276 -0
- package/dist/atlas/src/schema/ColumnDefinition.d.ts +154 -0
- package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +37 -0
- package/dist/atlas/src/schema/MigrationGenerator.d.ts +45 -0
- package/dist/atlas/src/schema/Schema.d.ts +131 -0
- package/dist/atlas/src/schema/SchemaDiff.d.ts +73 -0
- package/dist/atlas/src/schema/TypeGenerator.d.ts +57 -0
- package/dist/atlas/src/schema/TypeWriter.d.ts +42 -0
- package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +23 -0
- package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +26 -0
- package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +28 -0
- package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +97 -0
- package/dist/atlas/src/schema/grammars/index.d.ts +7 -0
- package/dist/atlas/src/schema/index.d.ts +8 -0
- package/dist/atlas/src/seed/Factory.d.ts +90 -0
- package/dist/atlas/src/seed/Seeder.d.ts +28 -0
- package/dist/atlas/src/seed/SeederRunner.d.ts +74 -0
- package/dist/atlas/src/seed/index.d.ts +6 -0
- package/dist/atlas/src/sharding/ShardingManager.d.ts +59 -0
- package/dist/atlas/src/types/index.d.ts +1182 -0
- package/dist/atlas/src/utils/CursorEncoding.d.ts +63 -0
- package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
- package/dist/core/src/Application.d.ts +43 -17
- package/dist/core/src/CommandKernel.d.ts +33 -0
- package/dist/core/src/ConfigManager.d.ts +39 -0
- package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
- package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
- package/dist/core/src/Container.d.ts +123 -14
- package/dist/core/src/ErrorHandler.d.ts +3 -0
- package/dist/core/src/HookManager.d.ts +517 -8
- package/dist/core/src/PlanetCore.d.ts +141 -7
- package/dist/core/src/RequestContext.d.ts +97 -0
- package/dist/core/src/Router.d.ts +41 -7
- package/dist/core/src/ServiceProvider.d.ts +36 -8
- package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +1 -0
- package/dist/core/src/adapters/PhotonAdapter.d.ts +5 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +4 -0
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +1 -0
- package/dist/core/src/adapters/types.d.ts +39 -0
- package/dist/core/src/cli/queue-commands.d.ts +6 -0
- package/dist/core/src/engine/AOTRouter.d.ts +7 -12
- package/dist/core/src/engine/FastContext.d.ts +27 -2
- package/dist/core/src/engine/Gravito.d.ts +1 -2
- package/dist/core/src/engine/MinimalContext.d.ts +25 -2
- package/dist/core/src/engine/types.d.ts +9 -1
- package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
- package/dist/core/src/events/BackpressureManager.d.ts +215 -0
- package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
- package/dist/core/src/events/DeadLetterQueue.d.ts +219 -0
- package/dist/core/src/events/EventBackend.d.ts +12 -0
- package/dist/core/src/events/EventOptions.d.ts +204 -0
- package/dist/core/src/events/EventPriorityQueue.d.ts +301 -0
- package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
- package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
- package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
- package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
- package/dist/core/src/events/RetryScheduler.d.ts +104 -0
- package/dist/core/src/events/WorkerPool.d.ts +98 -0
- package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
- package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
- package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
- package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
- package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
- package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
- package/dist/core/src/events/aggregation/types.d.ts +117 -0
- package/dist/core/src/events/index.d.ts +25 -0
- package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
- package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
- package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
- package/dist/core/src/events/observability/OTelEventMetrics.d.ts +332 -0
- package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
- package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
- package/dist/core/src/events/observability/index.d.ts +24 -0
- package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
- package/dist/core/src/events/types.d.ts +134 -0
- package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
- package/dist/core/src/exceptions/index.d.ts +1 -0
- package/dist/core/src/health/HealthProvider.d.ts +67 -0
- package/dist/core/src/http/cookie.d.ts +29 -0
- package/dist/core/src/http/types.d.ts +40 -0
- package/dist/core/src/index.d.ts +26 -4
- package/dist/core/src/instrumentation/index.d.ts +35 -0
- package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
- package/dist/core/src/instrumentation/types.d.ts +182 -0
- package/dist/core/src/observability/Metrics.d.ts +244 -0
- package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +350 -0
- package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
- package/dist/core/src/reliability/index.d.ts +6 -0
- package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
- package/dist/core/src/router/RequestValidator.d.ts +20 -0
- package/dist/echo/src/OrbitEcho.d.ts +71 -16
- package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
- package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
- package/dist/echo/src/dlq/index.d.ts +2 -0
- package/dist/echo/src/index.d.ts +31 -15
- package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
- package/dist/echo/src/middleware/index.d.ts +8 -0
- package/dist/echo/src/observability/index.d.ts +3 -0
- package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
- package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
- package/dist/echo/src/observability/logging/index.d.ts +2 -0
- package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
- package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
- package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
- package/dist/echo/src/observability/metrics/index.d.ts +3 -0
- package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
- package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
- package/dist/echo/src/observability/tracing/index.d.ts +2 -0
- package/dist/echo/src/providers/GenericProvider.d.ts +37 -18
- package/dist/echo/src/providers/GitHubProvider.d.ts +21 -12
- package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
- package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
- package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
- package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
- package/dist/echo/src/providers/StripeProvider.d.ts +20 -12
- package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
- package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
- package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
- package/dist/echo/src/providers/index.d.ts +14 -3
- package/dist/echo/src/receive/SignatureValidator.d.ts +33 -0
- package/dist/echo/src/receive/WebhookReceiver.d.ts +139 -21
- package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
- package/dist/echo/src/replay/index.d.ts +1 -0
- package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
- package/dist/echo/src/resilience/index.d.ts +10 -0
- package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
- package/dist/echo/src/rotation/index.d.ts +10 -0
- package/dist/echo/src/send/WebhookDispatcher.d.ts +159 -15
- package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
- package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
- package/dist/echo/src/storage/index.d.ts +2 -0
- package/dist/echo/src/types.d.ts +656 -64
- package/dist/index.js +1327 -189
- package/dist/index.js.map +28 -10
- package/dist/monitor/src/MonitorOrbit.d.ts +43 -0
- package/dist/monitor/src/config.d.ts +106 -0
- package/dist/monitor/src/health/HealthController.d.ts +28 -0
- package/dist/monitor/src/health/HealthRegistry.d.ts +80 -0
- package/dist/monitor/src/health/index.d.ts +36 -0
- package/dist/monitor/src/index.d.ts +13 -0
- package/dist/monitor/src/metrics/MetricsController.d.ts +22 -0
- package/dist/monitor/src/metrics/MetricsRegistry.d.ts +136 -0
- package/dist/monitor/src/metrics/index.d.ts +11 -0
- package/dist/monitor/src/tracing/TracingManager.d.ts +97 -0
- package/dist/monitor/src/tracing/index.d.ts +10 -0
- package/dist/photon/src/index.d.ts +74 -5
- package/dist/photon/src/middleware/binary.d.ts +12 -15
- package/dist/photon/src/middleware/htmx.d.ts +39 -0
- package/dist/photon/src/middleware/ratelimit-redis.d.ts +50 -0
- package/dist/photon/src/middleware/ratelimit.d.ts +161 -0
- package/dist/photon/src/openapi.d.ts +19 -0
- package/package.json +8 -6
|
@@ -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
|
+
}
|
|
@@ -1,34 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Simple HMAC-SHA256 signature verification.
|
|
5
|
-
*
|
|
2
|
+
* Generic webhook provider.
|
|
6
3
|
* @module @gravito/echo/providers
|
|
7
4
|
*/
|
|
8
|
-
import type {
|
|
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
|
-
*
|
|
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
|
|
38
|
+
export declare class GenericProvider extends BaseProvider {
|
|
23
39
|
readonly name = "generic";
|
|
24
40
|
private signatureHeader;
|
|
25
41
|
private timestampHeader;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
*
|
|
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 {
|
|
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
|
|
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
|
-
*
|
|
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 {
|
|
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
|
|
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
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for webhook providers.
|
|
3
|
+
* @module @gravito/echo/providers/base
|
|
4
|
+
*/
|
|
5
|
+
import type { WebhookProvider, WebhookVerificationResult } from '../../types';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for webhook providers.
|
|
8
|
+
*/
|
|
9
|
+
export interface ProviderOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Maximum allowed age of the webhook request in seconds to prevent replay attacks.
|
|
12
|
+
* @defaultValue 300
|
|
13
|
+
*/
|
|
14
|
+
tolerance?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Base implementation for all webhook providers.
|
|
18
|
+
* Handles common header extraction, payload conversion, and result formatting.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* class MyProvider extends BaseProvider {
|
|
23
|
+
* readonly name = 'my-provider';
|
|
24
|
+
* async verify(payload, headers, secret) {
|
|
25
|
+
* // Implementation logic
|
|
26
|
+
* return this.createSuccess(JSON.parse(payload));
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare abstract class BaseProvider implements WebhookProvider {
|
|
32
|
+
/** Unique identifier for the provider. */
|
|
33
|
+
abstract readonly name: string;
|
|
34
|
+
/** Time tolerance for timestamp validation. */
|
|
35
|
+
protected tolerance: number;
|
|
36
|
+
constructor(options?: ProviderOptions);
|
|
37
|
+
/**
|
|
38
|
+
* Verifies the authenticity of a webhook request.
|
|
39
|
+
*
|
|
40
|
+
* @param payload - Raw request body.
|
|
41
|
+
* @param headers - Request headers.
|
|
42
|
+
* @param secret - Provider-specific secret key.
|
|
43
|
+
* @returns Verification result containing the parsed payload or error message.
|
|
44
|
+
* @throws Error if verification logic encounters an unrecoverable failure.
|
|
45
|
+
*/
|
|
46
|
+
abstract verify(payload: string | Buffer, headers: Record<string, string | string[] | undefined>, secret: string): Promise<WebhookVerificationResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Extracts the event type from the verified payload.
|
|
49
|
+
*
|
|
50
|
+
* @param payload - The parsed webhook payload.
|
|
51
|
+
* @returns The event type string if found.
|
|
52
|
+
*/
|
|
53
|
+
parseEventType?(payload: unknown): string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves a header value in a case-insensitive manner.
|
|
56
|
+
*/
|
|
57
|
+
protected getHeader(headers: Record<string, string | string[] | undefined>, name: string): string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Checks if a specific header exists.
|
|
60
|
+
*/
|
|
61
|
+
protected hasHeader(headers: Record<string, string | string[] | undefined>, name: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a failed verification result.
|
|
64
|
+
*/
|
|
65
|
+
protected createFailure(error: string): WebhookVerificationResult;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a successful verification result.
|
|
68
|
+
*/
|
|
69
|
+
protected createSuccess(payload: unknown, options?: {
|
|
70
|
+
eventType?: string;
|
|
71
|
+
webhookId?: string;
|
|
72
|
+
}): WebhookVerificationResult;
|
|
73
|
+
/**
|
|
74
|
+
* Ensures the payload is a string.
|
|
75
|
+
*/
|
|
76
|
+
protected payloadToString(payload: string | Buffer): string;
|
|
77
|
+
/**
|
|
78
|
+
* Safely parses a JSON string without throwing.
|
|
79
|
+
*/
|
|
80
|
+
protected safeParseJson(str: string): {
|
|
81
|
+
success: true;
|
|
82
|
+
data: unknown;
|
|
83
|
+
} | {
|
|
84
|
+
success: false;
|
|
85
|
+
error: string;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for handling webhook headers.
|
|
3
|
+
* @module @gravito/echo/providers/base
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves a header value from a headers object.
|
|
7
|
+
* Supports case-insensitive lookup by checking the original name and its lowercase version.
|
|
8
|
+
*
|
|
9
|
+
* @param headers - The headers object from the request.
|
|
10
|
+
* @param name - The name of the header to retrieve.
|
|
11
|
+
* @returns The first value of the header if found, otherwise undefined.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const sig = getHeader(headers, 'X-Webhook-Signature');
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function getHeader(headers: Record<string, string | string[] | undefined>, name: string): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves multiple header values at once.
|
|
21
|
+
*
|
|
22
|
+
* @param headers - The headers object from the request.
|
|
23
|
+
* @param names - An array of header names to retrieve.
|
|
24
|
+
* @returns A record mapping each requested name to its value or undefined.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getHeaders(headers: Record<string, string | string[] | undefined>, names: string[]): Record<string, string | undefined>;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a specific header exists in the headers object.
|
|
29
|
+
*
|
|
30
|
+
* @param headers - The headers object from the request.
|
|
31
|
+
* @param name - The name of the header to check.
|
|
32
|
+
* @returns True if the header exists and is not undefined.
|
|
33
|
+
*/
|
|
34
|
+
export declare function hasHeader(headers: Record<string, string | string[] | undefined>, name: string): boolean;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Webhook providers for various services.
|
|
3
|
+
* @module @gravito/echo/providers
|
|
4
|
+
*/
|
|
5
|
+
export { BaseProvider, type ProviderOptions } from './base/BaseProvider';
|
|
6
|
+
export { getHeader, getHeaders, hasHeader } from './base/HeaderUtils';
|
|
7
|
+
export { GenericProvider } from './GenericProvider';
|
|
8
|
+
export { GitHubProvider } from './GitHubProvider';
|
|
9
|
+
export { LinearProvider } from './LinearProvider';
|
|
10
|
+
export { PaddleProvider } from './PaddleProvider';
|
|
11
|
+
export { ShopifyProvider } from './ShopifyProvider';
|
|
12
|
+
export { SlackProvider } from './SlackProvider';
|
|
13
|
+
export { StripeProvider } from './StripeProvider';
|
|
14
|
+
export { TwilioProvider } from './TwilioProvider';
|
|
@@ -9,10 +9,43 @@
|
|
|
9
9
|
* Compute HMAC-SHA256 signature
|
|
10
10
|
*/
|
|
11
11
|
export declare function computeHmacSha256(payload: string | Buffer, secret: string): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Computes an HMAC-SHA256 signature and returns it as a base64 encoded string.
|
|
14
|
+
*
|
|
15
|
+
* Used by providers that require base64 encoding for their signatures (e.g., Shopify).
|
|
16
|
+
*
|
|
17
|
+
* @param payload - The raw data to sign.
|
|
18
|
+
* @param secret - The shared secret key.
|
|
19
|
+
* @returns The base64 encoded HMAC-SHA256 signature.
|
|
20
|
+
* @throws Error if the crypto operations fail.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const sig = await computeHmacSha256Base64('data', 'secret');
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function computeHmacSha256Base64(payload: string | Buffer, secret: string): Promise<string>;
|
|
12
28
|
/**
|
|
13
29
|
* Compute HMAC-SHA1 signature (for legacy providers)
|
|
14
30
|
*/
|
|
15
31
|
export declare function computeHmacSha1(payload: string | Buffer, secret: string): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Computes an HMAC-SHA1 signature and returns it as a base64 encoded string.
|
|
34
|
+
*
|
|
35
|
+
* Primarily used for legacy services or specific providers like Twilio that
|
|
36
|
+
* still rely on SHA1-based HMAC for their webhook verification.
|
|
37
|
+
*
|
|
38
|
+
* @param payload - The raw data to sign.
|
|
39
|
+
* @param secret - The shared secret key.
|
|
40
|
+
* @returns The base64 encoded HMAC-SHA1 signature.
|
|
41
|
+
* @throws Error if the crypto operations fail.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const sig = await computeHmacSha1Base64('data', 'secret');
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function computeHmacSha1Base64(payload: string | Buffer, secret: string): Promise<string>;
|
|
16
49
|
/**
|
|
17
50
|
* Timing-safe string comparison to prevent timing attacks
|
|
18
51
|
*/
|