@brightchain/brightchain-api-lib 0.25.0 → 0.27.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.
- package/package.json +4 -3
- package/src/lib/appConstants.d.ts +1 -1
- package/src/lib/appConstants.js +1 -1
- package/src/lib/application.d.ts +3 -14
- package/src/lib/application.d.ts.map +1 -1
- package/src/lib/application.js +91 -34
- package/src/lib/application.js.map +1 -1
- package/src/lib/constants.d.ts.map +1 -1
- package/src/lib/constants.js +1 -1
- package/src/lib/constants.js.map +1 -1
- package/src/lib/databaseInit.d.ts +7 -11
- package/src/lib/databaseInit.d.ts.map +1 -1
- package/src/lib/databaseInit.js +41 -107
- package/src/lib/databaseInit.js.map +1 -1
- package/src/lib/datastore/block-document-store-factory.d.ts +3 -0
- package/src/lib/datastore/block-document-store-factory.d.ts.map +1 -1
- package/src/lib/datastore/block-document-store-factory.js +15 -18
- package/src/lib/datastore/block-document-store-factory.js.map +1 -1
- package/src/lib/datastore/block-document-store.d.ts +2 -191
- package/src/lib/datastore/block-document-store.d.ts.map +1 -1
- package/src/lib/datastore/block-document-store.js +4 -628
- package/src/lib/datastore/block-document-store.js.map +1 -1
- package/src/lib/datastore/document-store.d.ts +1 -62
- package/src/lib/datastore/document-store.d.ts.map +1 -1
- package/src/lib/datastore/memory-document-store.d.ts +1 -8
- package/src/lib/datastore/memory-document-store.d.ts.map +1 -1
- package/src/lib/datastore/memory-document-store.js +3 -214
- package/src/lib/datastore/memory-document-store.js.map +1 -1
- package/src/lib/environment.d.ts +4 -47
- package/src/lib/environment.d.ts.map +1 -1
- package/src/lib/environment.js +2 -136
- package/src/lib/environment.js.map +1 -1
- package/src/lib/interfaces/environment.d.ts +3 -25
- package/src/lib/interfaces/environment.d.ts.map +1 -1
- package/src/lib/interfaces/responses/emailGatewayResponses.d.ts +30 -0
- package/src/lib/interfaces/responses/emailGatewayResponses.d.ts.map +1 -0
- package/src/lib/interfaces/responses/emailGatewayResponses.js +3 -0
- package/src/lib/interfaces/responses/emailGatewayResponses.js.map +1 -0
- package/src/lib/interfaces/responses/index.d.ts +1 -0
- package/src/lib/interfaces/responses/index.d.ts.map +1 -1
- package/src/lib/middleware/index.d.ts +1 -1
- package/src/lib/middleware/index.d.ts.map +1 -1
- package/src/lib/middleware/index.js +3 -2
- package/src/lib/middleware/index.js.map +1 -1
- package/src/lib/middleware/validateBody.d.ts +1 -12
- package/src/lib/middleware/validateBody.d.ts.map +1 -1
- package/src/lib/middleware/validateBody.js +4 -32
- package/src/lib/middleware/validateBody.js.map +1 -1
- package/src/lib/middlewares.d.ts.map +1 -1
- package/src/lib/middlewares.js +7 -1
- package/src/lib/middlewares.js.map +1 -1
- package/src/lib/plugins/brightchain-database-plugin.d.ts +27 -79
- package/src/lib/plugins/brightchain-database-plugin.d.ts.map +1 -1
- package/src/lib/plugins/brightchain-database-plugin.js +32 -103
- package/src/lib/plugins/brightchain-database-plugin.js.map +1 -1
- package/src/lib/routers/app.d.ts.map +1 -1
- package/src/lib/routers/app.js +1 -0
- package/src/lib/routers/app.js.map +1 -1
- package/src/lib/services/emailGateway/antiSpamFilter.d.ts +229 -0
- package/src/lib/services/emailGateway/antiSpamFilter.d.ts.map +1 -0
- package/src/lib/services/emailGateway/antiSpamFilter.js +325 -0
- package/src/lib/services/emailGateway/antiSpamFilter.js.map +1 -0
- package/src/lib/services/emailGateway/bounceProcessor.d.ts +182 -0
- package/src/lib/services/emailGateway/bounceProcessor.d.ts.map +1 -0
- package/src/lib/services/emailGateway/bounceProcessor.js +391 -0
- package/src/lib/services/emailGateway/bounceProcessor.js.map +1 -0
- package/src/lib/services/emailGateway/emailAuthVerifier.d.ts +99 -0
- package/src/lib/services/emailGateway/emailAuthVerifier.d.ts.map +1 -0
- package/src/lib/services/emailGateway/emailAuthVerifier.js +202 -0
- package/src/lib/services/emailGateway/emailAuthVerifier.js.map +1 -0
- package/src/lib/services/emailGateway/emailGatewayConfig.d.ts +74 -0
- package/src/lib/services/emailGateway/emailGatewayConfig.d.ts.map +1 -0
- package/src/lib/services/emailGateway/emailGatewayConfig.js +107 -0
- package/src/lib/services/emailGateway/emailGatewayConfig.js.map +1 -0
- package/src/lib/services/emailGateway/emailGatewayService.d.ts +209 -0
- package/src/lib/services/emailGateway/emailGatewayService.d.ts.map +1 -0
- package/src/lib/services/emailGateway/emailGatewayService.js +254 -0
- package/src/lib/services/emailGateway/emailGatewayService.js.map +1 -0
- package/src/lib/services/emailGateway/gatewayObservability.d.ts +123 -0
- package/src/lib/services/emailGateway/gatewayObservability.d.ts.map +1 -0
- package/src/lib/services/emailGateway/gatewayObservability.js +186 -0
- package/src/lib/services/emailGateway/gatewayObservability.js.map +1 -0
- package/src/lib/services/emailGateway/inboundProcessor.d.ts +113 -0
- package/src/lib/services/emailGateway/inboundProcessor.d.ts.map +1 -0
- package/src/lib/services/emailGateway/inboundProcessor.js +298 -0
- package/src/lib/services/emailGateway/inboundProcessor.js.map +1 -0
- package/src/lib/services/emailGateway/index.d.ts +23 -0
- package/src/lib/services/emailGateway/index.d.ts.map +1 -0
- package/src/lib/services/emailGateway/index.js +26 -0
- package/src/lib/services/emailGateway/index.js.map +1 -0
- package/src/lib/services/emailGateway/outboundDeliveryWorker.d.ts +122 -0
- package/src/lib/services/emailGateway/outboundDeliveryWorker.d.ts.map +1 -0
- package/src/lib/services/emailGateway/outboundDeliveryWorker.js +110 -0
- package/src/lib/services/emailGateway/outboundDeliveryWorker.js.map +1 -0
- package/src/lib/services/emailGateway/outboundQueue.d.ts +135 -0
- package/src/lib/services/emailGateway/outboundQueue.d.ts.map +1 -0
- package/src/lib/services/emailGateway/outboundQueue.js +227 -0
- package/src/lib/services/emailGateway/outboundQueue.js.map +1 -0
- package/src/lib/services/emailGateway/outboundQueueStore.d.ts +110 -0
- package/src/lib/services/emailGateway/outboundQueueStore.d.ts.map +1 -0
- package/src/lib/services/emailGateway/outboundQueueStore.js +131 -0
- package/src/lib/services/emailGateway/outboundQueueStore.js.map +1 -0
- package/src/lib/services/emailGateway/recipientLookupService.d.ts +146 -0
- package/src/lib/services/emailGateway/recipientLookupService.d.ts.map +1 -0
- package/src/lib/services/emailGateway/recipientLookupService.js +307 -0
- package/src/lib/services/emailGateway/recipientLookupService.js.map +1 -0
- package/src/lib/services/emailGateway/retryBackoff.d.ts +79 -0
- package/src/lib/services/emailGateway/retryBackoff.d.ts.map +1 -0
- package/src/lib/services/emailGateway/retryBackoff.js +77 -0
- package/src/lib/services/emailGateway/retryBackoff.js.map +1 -0
- package/src/lib/services/index.d.ts +1 -0
- package/src/lib/services/index.d.ts.map +1 -1
- package/src/lib/services/index.js +1 -0
- package/src/lib/services/index.js.map +1 -1
- package/src/lib/services/quorumDatabaseAdapter.d.ts +7 -1
- package/src/lib/services/quorumDatabaseAdapter.d.ts.map +1 -1
- package/src/lib/services/quorumDatabaseAdapter.js +83 -0
- package/src/lib/services/quorumDatabaseAdapter.js.map +1 -1
- package/src/lib/services/sessionAdapter.d.ts +2 -61
- package/src/lib/services/sessionAdapter.d.ts.map +1 -1
- package/src/lib/services/sessionAdapter.js +2 -102
- package/src/lib/services/sessionAdapter.js.map +1 -1
- package/src/lib/shared-types.d.ts +7 -15
- package/src/lib/shared-types.d.ts.map +1 -1
- package/src/lib/types/backend-id.d.ts +1 -2
- package/src/lib/types/backend-id.d.ts.map +1 -1
- package/src/lib/validation/userValidation.d.ts +2 -43
- package/src/lib/validation/userValidation.d.ts.map +1 -1
- package/src/lib/validation/userValidation.js +6 -144
- package/src/lib/validation/userValidation.js.map +1 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Gateway Observability
|
|
4
|
+
*
|
|
5
|
+
* Provides unified logging, metrics collection, and alerting for all
|
|
6
|
+
* Email Gateway components. Wraps the existing `IMessageLogger`,
|
|
7
|
+
* `IMessageMetricsCollector`, and `AlertMonitor` services to add
|
|
8
|
+
* gateway-specific observability.
|
|
9
|
+
*
|
|
10
|
+
* @see Requirements 10.1, 10.2, 10.3, 10.4, 10.5
|
|
11
|
+
* @module gatewayObservability
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.GatewayObservability = void 0;
|
|
15
|
+
/**
|
|
16
|
+
* Centralised observability for the Email Gateway.
|
|
17
|
+
*
|
|
18
|
+
* Integrates with the existing `IMessageLogger`, `IMessageMetricsCollector`,
|
|
19
|
+
* and `AlertMonitor` services so that all gateway events flow through the
|
|
20
|
+
* same infrastructure used by the rest of BrightChain.
|
|
21
|
+
*
|
|
22
|
+
* @see Requirements 10.1, 10.2, 10.3, 10.4, 10.5
|
|
23
|
+
*/
|
|
24
|
+
class GatewayObservability {
|
|
25
|
+
logger;
|
|
26
|
+
metrics;
|
|
27
|
+
alertMonitor;
|
|
28
|
+
// Gateway-specific counters (Req 10.3)
|
|
29
|
+
_outboundQueueDepth = 0;
|
|
30
|
+
_deliverySuccessCount = 0;
|
|
31
|
+
_deliveryFailureCount = 0;
|
|
32
|
+
_totalDeliveryLatencyMs = 0;
|
|
33
|
+
_spamRejectionCount = 0;
|
|
34
|
+
_totalInboundProcessed = 0;
|
|
35
|
+
constructor(logger, metrics, alertMonitor) {
|
|
36
|
+
this.logger = logger;
|
|
37
|
+
this.metrics = metrics;
|
|
38
|
+
this.alertMonitor = alertMonitor;
|
|
39
|
+
}
|
|
40
|
+
// ── Outbound delivery logging (Req 10.1) ──────────────────────────
|
|
41
|
+
/**
|
|
42
|
+
* Log an outbound delivery attempt.
|
|
43
|
+
*
|
|
44
|
+
* Delegates to `IMessageLogger.logMessageCreated` for consistent logging
|
|
45
|
+
* and records the attempt in the metrics collector.
|
|
46
|
+
*
|
|
47
|
+
* @see Requirement 10.1
|
|
48
|
+
*/
|
|
49
|
+
logOutboundAttempt(recipient, statusCode, retryCount, timestamp) {
|
|
50
|
+
// Use the existing logger infrastructure (Req 10.4)
|
|
51
|
+
this.logger.logMessageCreated(`outbound:${recipient}:${timestamp.toISOString()}`, 'gateway-outbound', 1);
|
|
52
|
+
this.logger.logRoutingDecision(`outbound:${recipient}`, `smtp-status:${statusCode}:retry:${retryCount}`, 1);
|
|
53
|
+
// Track success/failure in metrics (Req 10.3)
|
|
54
|
+
if (statusCode >= 200 && statusCode < 300) {
|
|
55
|
+
this._deliverySuccessCount++;
|
|
56
|
+
this.metrics.recordMessageDelivered(0);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this._deliveryFailureCount++;
|
|
60
|
+
this.metrics.recordMessageFailed();
|
|
61
|
+
}
|
|
62
|
+
this.metrics.recordMessageSent();
|
|
63
|
+
}
|
|
64
|
+
// ── Inbound processing logging (Req 10.2) ─────────────────────────
|
|
65
|
+
/**
|
|
66
|
+
* Log an inbound email processing event.
|
|
67
|
+
*
|
|
68
|
+
* @see Requirement 10.2
|
|
69
|
+
*/
|
|
70
|
+
logInboundProcessing(sender, recipient, spamScore, authResults, accepted) {
|
|
71
|
+
this._totalInboundProcessed++;
|
|
72
|
+
const messageId = `inbound:${sender}->${recipient}:${Date.now()}`;
|
|
73
|
+
// Log via existing logger (Req 10.4)
|
|
74
|
+
this.logger.logMessageCreated(messageId, sender, 1);
|
|
75
|
+
this.logger.logRoutingDecision(messageId, `spam:${spamScore}|spf:${authResults.spf.status}|dkim:${authResults.dkim.status}|dmarc:${authResults.dmarc.status}|${accepted ? 'accepted' : 'rejected'}`, 1);
|
|
76
|
+
if (!accepted) {
|
|
77
|
+
this.logger.logDeliveryFailure(messageId, recipient, 'rejected');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// ── Metrics recording (Req 10.3) ──────────────────────────────────
|
|
81
|
+
/**
|
|
82
|
+
* Record the current outbound queue depth.
|
|
83
|
+
*
|
|
84
|
+
* @see Requirement 10.3
|
|
85
|
+
*/
|
|
86
|
+
recordQueueDepth(depth) {
|
|
87
|
+
this._outboundQueueDepth = depth;
|
|
88
|
+
this.metrics.recordStorageUtilization(depth);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Record a successful delivery and its latency.
|
|
92
|
+
*
|
|
93
|
+
* @see Requirement 10.3
|
|
94
|
+
*/
|
|
95
|
+
recordDeliverySuccess(latencyMs) {
|
|
96
|
+
this._deliverySuccessCount++;
|
|
97
|
+
if (latencyMs !== undefined) {
|
|
98
|
+
this._totalDeliveryLatencyMs += latencyMs;
|
|
99
|
+
this.metrics.recordMessageDelivered(latencyMs);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.metrics.recordMessageDelivered(0);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Record a delivery failure.
|
|
107
|
+
*
|
|
108
|
+
* @see Requirement 10.3
|
|
109
|
+
*/
|
|
110
|
+
recordDeliveryFailure() {
|
|
111
|
+
this._deliveryFailureCount++;
|
|
112
|
+
this.metrics.recordMessageFailed();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Record delivery latency in milliseconds.
|
|
116
|
+
*
|
|
117
|
+
* @see Requirement 10.3
|
|
118
|
+
*/
|
|
119
|
+
recordDeliveryLatency(ms) {
|
|
120
|
+
this._totalDeliveryLatencyMs += ms;
|
|
121
|
+
this.metrics.recordMessageDelivered(ms);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Record a spam rejection.
|
|
125
|
+
*
|
|
126
|
+
* @see Requirement 10.3
|
|
127
|
+
*/
|
|
128
|
+
recordSpamRejection() {
|
|
129
|
+
this._spamRejectionCount++;
|
|
130
|
+
this._totalInboundProcessed++;
|
|
131
|
+
this.metrics.recordMessageFailed();
|
|
132
|
+
}
|
|
133
|
+
// ── Alert emission (Req 10.5) ─────────────────────────────────────
|
|
134
|
+
/**
|
|
135
|
+
* Emit an alert when delivery fails after all retries are exhausted.
|
|
136
|
+
*
|
|
137
|
+
* Delegates to the existing `AlertMonitor` for consistent alerting.
|
|
138
|
+
*
|
|
139
|
+
* @see Requirement 10.5
|
|
140
|
+
*/
|
|
141
|
+
alertDeliveryExhausted(messageId, recipient, retryCount) {
|
|
142
|
+
// Use AlertMonitor's failure rate check to trigger handler (Req 10.5)
|
|
143
|
+
this.alertMonitor.checkFailureRate(this._deliverySuccessCount, this._deliveryFailureCount);
|
|
144
|
+
// Also emit a specific event-emission alert with context
|
|
145
|
+
this.alertMonitor.checkEventEmission(`Delivery exhausted: messageId=${messageId}, recipient=${recipient}, retries=${retryCount}`);
|
|
146
|
+
// Log via existing logger
|
|
147
|
+
this.logger.logDeliveryFailure(messageId, recipient, `retries exhausted after ${retryCount} attempts`);
|
|
148
|
+
}
|
|
149
|
+
// ── Metrics snapshot (Req 10.3) ───────────────────────────────────
|
|
150
|
+
/**
|
|
151
|
+
* Return a point-in-time snapshot of all gateway-specific metrics.
|
|
152
|
+
*
|
|
153
|
+
* @see Requirement 10.3
|
|
154
|
+
*/
|
|
155
|
+
getMetricsSnapshot() {
|
|
156
|
+
const totalDeliveries = this._deliverySuccessCount + this._deliveryFailureCount;
|
|
157
|
+
const deliveredCount = this._deliverySuccessCount;
|
|
158
|
+
return {
|
|
159
|
+
outboundQueueDepth: this._outboundQueueDepth,
|
|
160
|
+
deliverySuccessCount: this._deliverySuccessCount,
|
|
161
|
+
deliveryFailureCount: this._deliveryFailureCount,
|
|
162
|
+
deliverySuccessRate: totalDeliveries > 0 ? deliveredCount / totalDeliveries : 0,
|
|
163
|
+
deliveryFailureRate: totalDeliveries > 0 ? this._deliveryFailureCount / totalDeliveries : 0,
|
|
164
|
+
averageDeliveryLatencyMs: deliveredCount > 0 ? this._totalDeliveryLatencyMs / deliveredCount : 0,
|
|
165
|
+
spamRejectionCount: this._spamRejectionCount,
|
|
166
|
+
spamRejectionRate: this._totalInboundProcessed > 0
|
|
167
|
+
? this._spamRejectionCount / this._totalInboundProcessed
|
|
168
|
+
: 0,
|
|
169
|
+
totalInboundProcessed: this._totalInboundProcessed,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Reset all gateway-specific counters.
|
|
174
|
+
*/
|
|
175
|
+
reset() {
|
|
176
|
+
this._outboundQueueDepth = 0;
|
|
177
|
+
this._deliverySuccessCount = 0;
|
|
178
|
+
this._deliveryFailureCount = 0;
|
|
179
|
+
this._totalDeliveryLatencyMs = 0;
|
|
180
|
+
this._spamRejectionCount = 0;
|
|
181
|
+
this._totalInboundProcessed = 0;
|
|
182
|
+
this.metrics.reset();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.GatewayObservability = GatewayObservability;
|
|
186
|
+
//# sourceMappingURL=gatewayObservability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gatewayObservability.js","sourceRoot":"","sources":["../../../../../../brightchain-api-lib/src/lib/services/emailGateway/gatewayObservability.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAmCH;;;;;;;;GAQG;AACH,MAAa,oBAAoB;IAUZ;IACA;IACA;IAXnB,uCAAuC;IAC/B,mBAAmB,GAAG,CAAC,CAAC;IACxB,qBAAqB,GAAG,CAAC,CAAC;IAC1B,qBAAqB,GAAG,CAAC,CAAC;IAC1B,uBAAuB,GAAG,CAAC,CAAC;IAC5B,mBAAmB,GAAG,CAAC,CAAC;IACxB,sBAAsB,GAAG,CAAC,CAAC;IAEnC,YACmB,MAAsB,EACtB,OAAiC,EACjC,YAA0B;QAF1B,WAAM,GAAN,MAAM,CAAgB;QACtB,YAAO,GAAP,OAAO,CAA0B;QACjC,iBAAY,GAAZ,YAAY,CAAc;IAC1C,CAAC;IAEJ,qEAAqE;IAErE;;;;;;;OAOG;IACH,kBAAkB,CAChB,SAAiB,EACjB,UAAkB,EAClB,UAAkB,EAClB,SAAe;QAEf,oDAAoD;QACpD,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAC3B,YAAY,SAAS,IAAI,SAAS,CAAC,WAAW,EAAE,EAAE,EAClD,kBAAkB,EAClB,CAAC,CACF,CAAC;QACF,IAAI,CAAC,MA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C/B,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,mBAAmB,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,sBAAsB,GAAG,CAAC,CAAC;QAChC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;CACF;AA3ND,oDA2NC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InboundProcessor — watches the Mail Drop Directory for new Maildir-format
|
|
3
|
+
* files deposited by Postfix, parses each message via EmailParser, stores
|
|
4
|
+
* content in the Block Store, creates metadata via EmailMessageService, and
|
|
5
|
+
* announces delivery to the recipient via the Gossip Protocol.
|
|
6
|
+
*
|
|
7
|
+
* On success the processed file is deleted from the Mail Drop Directory.
|
|
8
|
+
* On failure the file is moved to a configurable error directory and the
|
|
9
|
+
* failure reason is logged.
|
|
10
|
+
*
|
|
11
|
+
* A Set of processed filenames provides idempotency — the same file will
|
|
12
|
+
* not be processed twice even if the watcher fires duplicate events.
|
|
13
|
+
*
|
|
14
|
+
* @see Requirements 4.4, 4.5, 4.6, 4.7, 4.8, 4.9
|
|
15
|
+
* @module inboundProcessor
|
|
16
|
+
*/
|
|
17
|
+
import type { IBlockStore, IGossipService } from '@brightchain/brightchain-lib';
|
|
18
|
+
import { EmailMessageService, EmailParser } from '@brightchain/brightchain-lib';
|
|
19
|
+
import type { IEmailAuthVerifier } from './emailAuthVerifier';
|
|
20
|
+
import type { IEmailGatewayConfig } from './emailGatewayConfig';
|
|
21
|
+
/**
|
|
22
|
+
* Watches the Mail Drop Directory for new inbound email files and processes
|
|
23
|
+
* them into the BrightChain internal messaging system.
|
|
24
|
+
*
|
|
25
|
+
* Processing pipeline per file:
|
|
26
|
+
* 1. Read raw file content
|
|
27
|
+
* 2. Parse RFC 5322 message via EmailParser
|
|
28
|
+
* 3. Store content in Block Store
|
|
29
|
+
* 4. Create metadata via EmailMessageService
|
|
30
|
+
* 5. Announce to recipient via Gossip Protocol
|
|
31
|
+
* 6. Delete file on success / move to error directory on failure
|
|
32
|
+
*
|
|
33
|
+
* @see Requirements 4.4, 4.5, 4.6, 4.7, 4.8, 4.9
|
|
34
|
+
*/
|
|
35
|
+
export declare class InboundProcessor {
|
|
36
|
+
private readonly config;
|
|
37
|
+
private readonly emailMessageService;
|
|
38
|
+
private readonly blockStore;
|
|
39
|
+
private readonly gossipService;
|
|
40
|
+
private readonly parser;
|
|
41
|
+
/** Authentication verifier for SPF/DKIM/DMARC. Req 6.4, 6.5 */
|
|
42
|
+
private readonly authVerifier;
|
|
43
|
+
/** fs.watch handle — `null` when stopped. */
|
|
44
|
+
private watcher;
|
|
45
|
+
/** Whether the processor is currently running. */
|
|
46
|
+
private running;
|
|
47
|
+
/** Filenames that have already been processed (idempotency guard). Req 4.7 */
|
|
48
|
+
private readonly processedFiles;
|
|
49
|
+
constructor(config: IEmailGatewayConfig, emailParser: EmailParser | null, emailMessageService: EmailMessageService, blockStore: IBlockStore, gossipService: IGossipService, authVerifier?: IEmailAuthVerifier);
|
|
50
|
+
/**
|
|
51
|
+
* Start watching the Mail Drop Directory for new files.
|
|
52
|
+
*
|
|
53
|
+
* Creates the mail drop and error directories if they do not exist,
|
|
54
|
+
* then sets up an `fs.watch` listener that triggers processing for
|
|
55
|
+
* every new or renamed file.
|
|
56
|
+
*
|
|
57
|
+
* @see Requirement 4.5 — watch via inotify / fs.watch
|
|
58
|
+
*/
|
|
59
|
+
start(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Stop watching the Mail Drop Directory.
|
|
62
|
+
*/
|
|
63
|
+
stop(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Whether the processor is currently running.
|
|
66
|
+
*/
|
|
67
|
+
isRunning(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Process all files already present in the Mail Drop Directory.
|
|
70
|
+
* Called once on startup to handle files deposited while the processor
|
|
71
|
+
* was not running.
|
|
72
|
+
*/
|
|
73
|
+
private processExistingFiles;
|
|
74
|
+
/**
|
|
75
|
+
* Process a single inbound email file.
|
|
76
|
+
*
|
|
77
|
+
* Idempotency: if the file has already been processed (tracked in
|
|
78
|
+
* `processedFiles`) the call is a no-op. Req 4.7
|
|
79
|
+
*
|
|
80
|
+
* @param filename - The filename (not full path) within the Mail Drop Directory
|
|
81
|
+
*
|
|
82
|
+
* @see Requirement 4.6 — parse, store, create metadata
|
|
83
|
+
* @see Requirement 4.7 — delete on success
|
|
84
|
+
* @see Requirement 4.8 — move to error directory on failure
|
|
85
|
+
* @see Requirement 4.9 — announce via gossip
|
|
86
|
+
*/
|
|
87
|
+
processFile(filename: string): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Merge authentication results into custom headers as a serialized
|
|
90
|
+
* `X-BrightChain-Auth-Results` header so the auth metadata is
|
|
91
|
+
* preserved alongside the message.
|
|
92
|
+
*
|
|
93
|
+
* @see Requirement 6.4
|
|
94
|
+
*/
|
|
95
|
+
private mergeAuthHeaders;
|
|
96
|
+
/**
|
|
97
|
+
* Extract plain-text body from parsed email metadata.
|
|
98
|
+
*/
|
|
99
|
+
private extractTextBody;
|
|
100
|
+
/**
|
|
101
|
+
* Extract HTML body from parsed email metadata.
|
|
102
|
+
*/
|
|
103
|
+
private extractHtmlBody;
|
|
104
|
+
/**
|
|
105
|
+
* Get the set of processed filenames (for testing / inspection).
|
|
106
|
+
*/
|
|
107
|
+
getProcessedFiles(): ReadonlySet<string>;
|
|
108
|
+
/**
|
|
109
|
+
* Clear the processed files set (for testing).
|
|
110
|
+
*/
|
|
111
|
+
clearProcessedFiles(): void;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=inboundProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inboundProcessor.d.ts","sourceRoot":"","sources":["../../../../../../brightchain-api-lib/src/lib/services/emailGateway/inboundProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,KAAK,EAEV,WA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AAC,eAAe;IAiBvB;;OAEG;IACH,iBAAiB,IAAI,WAAW,CAAC,MAAM,CAAC;IAIxC;;OAEG;IACH,mBAAmB,IAAI,IAAI;CAG5B"}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* InboundProcessor — watches the Mail Drop Directory for new Maildir-format
|
|
4
|
+
* files deposited by Postfix, parses each message via EmailParser, stores
|
|
5
|
+
* content in the Block Store, creates metadata via EmailMessageService, and
|
|
6
|
+
* announces delivery to the recipient via the Gossip Protocol.
|
|
7
|
+
*
|
|
8
|
+
* On success the processed file is deleted from the Mail Drop Directory.
|
|
9
|
+
* On failure the file is moved to a configurable error directory and the
|
|
10
|
+
* failure reason is logged.
|
|
11
|
+
*
|
|
12
|
+
* A Set of processed filenames provides idempotency — the same file will
|
|
13
|
+
* not be processed twice even if the watcher fires duplicate events.
|
|
14
|
+
*
|
|
15
|
+
* @see Requirements 4.4, 4.5, 4.6, 4.7, 4.8, 4.9
|
|
16
|
+
* @module inboundProcessor
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.InboundProcessor = void 0;
|
|
20
|
+
const tslib_1 = require("tslib");
|
|
21
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
22
|
+
const path = tslib_1.__importStar(require("path"));
|
|
23
|
+
const brightchain_lib_1 = require("@brightchain/brightchain-lib");
|
|
24
|
+
const emailAuthVerifier_1 = require("./emailAuthVerifier");
|
|
25
|
+
// ─── InboundProcessor ───────────────────────────────────────────────────────
|
|
26
|
+
/**
|
|
27
|
+
* Watches the Mail Drop Directory for new inbound email files and processes
|
|
28
|
+
* them into the BrightChain internal messaging system.
|
|
29
|
+
*
|
|
30
|
+
* Processing pipeline per file:
|
|
31
|
+
* 1. Read raw file content
|
|
32
|
+
* 2. Parse RFC 5322 message via EmailParser
|
|
33
|
+
* 3. Store content in Block Store
|
|
34
|
+
* 4. Create metadata via EmailMessageService
|
|
35
|
+
* 5. Announce to recipient via Gossip Protocol
|
|
36
|
+
* 6. Delete file on success / move to error directory on failure
|
|
37
|
+
*
|
|
38
|
+
* @see Requirements 4.4, 4.5, 4.6, 4.7, 4.8, 4.9
|
|
39
|
+
*/
|
|
40
|
+
class InboundProcessor {
|
|
41
|
+
config;
|
|
42
|
+
emailMessageService;
|
|
43
|
+
blockStore;
|
|
44
|
+
gossipService;
|
|
45
|
+
parser;
|
|
46
|
+
/** Authentication verifier for SPF/DKIM/DMARC. Req 6.4, 6.5 */
|
|
47
|
+
authVerifier;
|
|
48
|
+
/** fs.watch handle — `null` when stopped. */
|
|
49
|
+
watcher = null;
|
|
50
|
+
/** Whether the processor is currently running. */
|
|
51
|
+
running = false;
|
|
52
|
+
/** Filenames that have already been processed (idempotency guard). Req 4.7 */
|
|
53
|
+
processedFiles = new Set();
|
|
54
|
+
constructor(config, emailParser, emailMessageService, blockStore, gossipService, authVerifier) {
|
|
55
|
+
this.config = config;
|
|
56
|
+
this.emailMessageService = emailMessageService;
|
|
57
|
+
this.blockStore = blockStore;
|
|
58
|
+
this.gossipService = gossipService;
|
|
59
|
+
this.parser = emailParser ?? new brightchain_lib_1.EmailParser();
|
|
60
|
+
this.authVerifier = authVerifier ?? new emailAuthVerifier_1.EmailAuthVerifier();
|
|
61
|
+
}
|
|
62
|
+
// ─── Lifecycle ──────────────────────────────────────────────────────
|
|
63
|
+
/**
|
|
64
|
+
* Start watching the Mail Drop Directory for new files.
|
|
65
|
+
*
|
|
66
|
+
* Creates the mail drop and error directories if they do not exist,
|
|
67
|
+
* then sets up an `fs.watch` listener that triggers processing for
|
|
68
|
+
* every new or renamed file.
|
|
69
|
+
*
|
|
70
|
+
* @see Requirement 4.5 — watch via inotify / fs.watch
|
|
71
|
+
*/
|
|
72
|
+
start() {
|
|
73
|
+
if (this.running) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// Ensure directories exist.
|
|
77
|
+
fs.mkdirSync(this.config.mailDropDirectory, { recursive: true });
|
|
78
|
+
fs.mkdirSync(this.config.errorDirectory, { recursive: true });
|
|
79
|
+
// Process any files already present in the directory.
|
|
80
|
+
this.processExistingFiles();
|
|
81
|
+
// Watch for new files.
|
|
82
|
+
this.watcher = fs.watch(this.config.mailDropDirectory, (eventType, filename) => {
|
|
83
|
+
if (filename && (eventType === 'rename' || eventType === 'change')) {
|
|
84
|
+
// Small delay to allow the file to be fully written.
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
void this.processFile(filename);
|
|
87
|
+
}, 100);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
this.running = true;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Stop watching the Mail Drop Directory.
|
|
94
|
+
*/
|
|
95
|
+
stop() {
|
|
96
|
+
if (!this.running) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (this.watcher) {
|
|
100
|
+
this.watcher.close();
|
|
101
|
+
this.watcher = null;
|
|
102
|
+
}
|
|
103
|
+
this.running = false;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Whether the processor is currently running.
|
|
107
|
+
*/
|
|
108
|
+
isRunning() {
|
|
109
|
+
return this.running;
|
|
110
|
+
}
|
|
111
|
+
// ─── File Processing ────────────────────────────────────────────────
|
|
112
|
+
/**
|
|
113
|
+
* Process all files already present in the Mail Drop Directory.
|
|
114
|
+
* Called once on startup to handle files deposited while the processor
|
|
115
|
+
* was not running.
|
|
116
|
+
*/
|
|
117
|
+
processExistingFiles() {
|
|
118
|
+
let entries;
|
|
119
|
+
try {
|
|
120
|
+
entries = fs.readdirSync(this.config.mailDropDirectory);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
for (const filename of entries) {
|
|
126
|
+
const fullPath = path.join(this.config.mailDropDirectory, filename);
|
|
127
|
+
try {
|
|
128
|
+
const stat = fs.statSync(fullPath);
|
|
129
|
+
if (stat.isFile()) {
|
|
130
|
+
void this.processFile(filename);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// Skip entries we cannot stat.
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Process a single inbound email file.
|
|
140
|
+
*
|
|
141
|
+
* Idempotency: if the file has already been processed (tracked in
|
|
142
|
+
* `processedFiles`) the call is a no-op. Req 4.7
|
|
143
|
+
*
|
|
144
|
+
* @param filename - The filename (not full path) within the Mail Drop Directory
|
|
145
|
+
*
|
|
146
|
+
* @see Requirement 4.6 — parse, store, create metadata
|
|
147
|
+
* @see Requirement 4.7 — delete on success
|
|
148
|
+
* @see Requirement 4.8 — move to error directory on failure
|
|
149
|
+
* @see Requirement 4.9 — announce via gossip
|
|
150
|
+
*/
|
|
151
|
+
async processFile(filename) {
|
|
152
|
+
// Idempotency guard (Req 4.7).
|
|
153
|
+
if (this.processedFiles.has(filename)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const filePath = path.join(this.config.mailDropDirectory, filename);
|
|
157
|
+
// Verify the file still exists (it may have been removed between
|
|
158
|
+
// the watcher event and this handler running).
|
|
159
|
+
if (!fs.existsSync(filePath)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
// Mark as in-progress immediately to prevent duplicate processing
|
|
163
|
+
// from concurrent watcher events.
|
|
164
|
+
this.processedFiles.add(filename);
|
|
165
|
+
try {
|
|
166
|
+
// 1. Read raw file content.
|
|
167
|
+
const rawContent = fs.readFileSync(filePath);
|
|
168
|
+
// 2. Parse RFC 5322 message via EmailParser (Req 4.6).
|
|
169
|
+
const metadata = await this.parser.parse(rawContent);
|
|
170
|
+
// 2b. Verify SPF/DKIM/DMARC authentication results (Req 6.4).
|
|
171
|
+
const authResult = this.authVerifier.verify(rawContent);
|
|
172
|
+
// 2c. Reject messages failing DMARC with reject policy (Req 6.5).
|
|
173
|
+
if (emailAuthVerifier_1.EmailAuthVerifier.shouldRejectDmarc(authResult)) {
|
|
174
|
+
throw new Error(`DMARC verification failed (550 reject): ${authResult.dmarc.details ?? 'policy=reject'}`);
|
|
175
|
+
}
|
|
176
|
+
// 3. Store content in Block Store.
|
|
177
|
+
const blockId = metadata.messageId;
|
|
178
|
+
await this.blockStore.put(blockId, rawContent);
|
|
179
|
+
// 4. Create metadata via EmailMessageService (Req 4.6).
|
|
180
|
+
// We use sendEmail with the parsed metadata to go through the
|
|
181
|
+
// standard storage and delivery pipeline.
|
|
182
|
+
const recipientAddresses = [
|
|
183
|
+
...metadata.to.map((m) => m.address),
|
|
184
|
+
...(metadata.cc ?? []).map((m) => m.address),
|
|
185
|
+
];
|
|
186
|
+
await this.emailMessageService.sendEmail({
|
|
187
|
+
from: metadata.from,
|
|
188
|
+
to: metadata.to,
|
|
189
|
+
cc: metadata.cc,
|
|
190
|
+
bcc: metadata.bcc,
|
|
191
|
+
subject: metadata.subject,
|
|
192
|
+
messageId: metadata.messageId,
|
|
193
|
+
date: metadata.date,
|
|
194
|
+
inReplyTo: metadata.inReplyTo,
|
|
195
|
+
references: metadata.references,
|
|
196
|
+
contentType: metadata.contentType,
|
|
197
|
+
parts: metadata.parts,
|
|
198
|
+
textBody: this.extractTextBody(metadata),
|
|
199
|
+
htmlBody: this.extractHtmlBody(metadata),
|
|
200
|
+
customHeaders: this.mergeAuthHeaders(metadata.customHeaders, authResult),
|
|
201
|
+
});
|
|
202
|
+
// 5. Announce to recipients via Gossip Protocol (Req 4.9).
|
|
203
|
+
await this.gossipService.announceMessage(metadata.cblBlockIds ?? [blockId], {
|
|
204
|
+
messageId: metadata.messageId,
|
|
205
|
+
recipientIds: recipientAddresses,
|
|
206
|
+
priority: 'normal',
|
|
207
|
+
blockIds: metadata.cblBlockIds ?? [blockId],
|
|
208
|
+
cblBlockId: metadata.blockId ?? blockId,
|
|
209
|
+
ackRequired: true,
|
|
210
|
+
});
|
|
211
|
+
// 6. Delete processed file on success (Req 4.7).
|
|
212
|
+
fs.unlinkSync(filePath);
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
// On failure: move to error directory and log reason (Req 4.8).
|
|
216
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
217
|
+
try {
|
|
218
|
+
const errorPath = path.join(this.config.errorDirectory, filename);
|
|
219
|
+
fs.renameSync(filePath, errorPath);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
// If we can't move the file, leave it in place — it won't be
|
|
223
|
+
// reprocessed because it's already in processedFiles.
|
|
224
|
+
}
|
|
225
|
+
// Log the failure reason.
|
|
226
|
+
console.error(`[InboundProcessor] Failed to process ${filename}: ${reason}`);
|
|
227
|
+
// Remove from processedFiles so a retry can be attempted if the
|
|
228
|
+
// file is re-deposited.
|
|
229
|
+
this.processedFiles.delete(filename);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// ─── Helpers ────────────────────────────────────────────────────────
|
|
233
|
+
/**
|
|
234
|
+
* Merge authentication results into custom headers as a serialized
|
|
235
|
+
* `X-BrightChain-Auth-Results` header so the auth metadata is
|
|
236
|
+
* preserved alongside the message.
|
|
237
|
+
*
|
|
238
|
+
* @see Requirement 6.4
|
|
239
|
+
*/
|
|
240
|
+
mergeAuthHeaders(existing, authResult) {
|
|
241
|
+
const merged = new Map(existing);
|
|
242
|
+
const summary = [
|
|
243
|
+
`spf=${authResult.spf.status}`,
|
|
244
|
+
`dkim=${authResult.dkim.status}`,
|
|
245
|
+
`dmarc=${authResult.dmarc.status}`,
|
|
246
|
+
].join('; ');
|
|
247
|
+
merged.set('X-BrightChain-Auth-Results', [summary]);
|
|
248
|
+
return merged;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Extract plain-text body from parsed email metadata.
|
|
252
|
+
*/
|
|
253
|
+
extractTextBody(metadata) {
|
|
254
|
+
if (metadata.parts && metadata.parts.length > 0) {
|
|
255
|
+
for (const part of metadata.parts) {
|
|
256
|
+
if (part.contentType?.type === 'text' &&
|
|
257
|
+
part.contentType?.subtype === 'plain' &&
|
|
258
|
+
part.body) {
|
|
259
|
+
return typeof part.body === 'string'
|
|
260
|
+
? part.body
|
|
261
|
+
: new TextDecoder().decode(part.body);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Extract HTML body from parsed email metadata.
|
|
269
|
+
*/
|
|
270
|
+
extractHtmlBody(metadata) {
|
|
271
|
+
if (metadata.parts && metadata.parts.length > 0) {
|
|
272
|
+
for (const part of metadata.parts) {
|
|
273
|
+
if (part.contentType?.type === 'text' &&
|
|
274
|
+
part.contentType?.subtype === 'html' &&
|
|
275
|
+
part.body) {
|
|
276
|
+
return typeof part.body === 'string'
|
|
277
|
+
? part.body
|
|
278
|
+
: new TextDecoder().decode(part.body);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Get the set of processed filenames (for testing / inspection).
|
|
286
|
+
*/
|
|
287
|
+
getProcessedFiles() {
|
|
288
|
+
return this.processedFiles;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Clear the processed files set (for testing).
|
|
292
|
+
*/
|
|
293
|
+
clearProcessedFiles() {
|
|
294
|
+
this.processedFiles.clear();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
exports.InboundProcessor = InboundProcessor;
|
|
298
|
+
//# sourceMappingURL=inboundProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inboundProcessor.js","sourceRoot":"","sources":["../../../../../../brightchain-api-lib/src/lib/services/emailGateway/inboundProcessor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;AAEH,+CAAyB;AACzB,mDAA6B;AAS7B,kEAAgF;AAGhF,2DAAwD;AAGxD,+EAA+E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,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;CACF;AArTD,4CAqTC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email Gateway module barrel export.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all public gateway components so consumers can import from
|
|
5
|
+
* `@brightchain/brightchain-api-lib` (via the services barrel) with a
|
|
6
|
+
* single import path.
|
|
7
|
+
*
|
|
8
|
+
* @see Requirements 11.2, 11.3
|
|
9
|
+
* @module emailGateway
|
|
10
|
+
*/
|
|
11
|
+
export * from './antiSpamFilter';
|
|
12
|
+
export * from './bounceProcessor';
|
|
13
|
+
export * from './emailAuthVerifier';
|
|
14
|
+
export * from './emailGatewayConfig';
|
|
15
|
+
export * from './emailGatewayService';
|
|
16
|
+
export * from './gatewayObservability';
|
|
17
|
+
export * from './inboundProcessor';
|
|
18
|
+
export * from './outboundDeliveryWorker';
|
|
19
|
+
export * from './outboundQueue';
|
|
20
|
+
export * from './outboundQueueStore';
|
|
21
|
+
export * from './recipientLookupService';
|
|
22
|
+
export * from './retryBackoff';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../brightchain-api-lib/src/lib/services/emailGateway/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gBAAgB,CAAC"}
|