@geekmidas/events 10.0.0-alpha.155 → 10.0.0-alpha.156
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 +19 -0
- package/dist/sns/index.cjs +15 -191
- package/dist/sns/index.cjs.map +1 -1
- package/dist/sns/index.d.cts +5 -115
- package/dist/sns/index.d.cts.map +1 -1
- package/dist/sns/index.d.mts +5 -115
- package/dist/sns/index.d.mts.map +1 -1
- package/dist/sns/index.mjs +1 -177
- package/dist/sns/index.mjs.map +1 -1
- package/dist/sns/message.cjs +194 -0
- package/dist/sns/message.cjs.map +1 -0
- package/dist/sns/message.d.cts +127 -0
- package/dist/sns/message.d.cts.map +1 -0
- package/dist/sns/message.d.mts +127 -0
- package/dist/sns/message.d.mts.map +1 -0
- package/dist/sns/message.mjs +182 -0
- package/dist/sns/message.mjs.map +1 -0
- package/package.json +13 -3
package/README.md
CHANGED
|
@@ -513,6 +513,25 @@ type PublishableMessage<TType extends string, TPayload> = {
|
|
|
513
513
|
6. **Cleanup**: Always call `stop()` on subscribers when shutting down
|
|
514
514
|
7. **Message Versioning**: Include version in message type for breaking changes (e.g., `user.created.v2`)
|
|
515
515
|
|
|
516
|
+
## Optional peers
|
|
517
|
+
|
|
518
|
+
<!-- optional-peers:start -->
|
|
519
|
+
|
|
520
|
+
<!-- Generated by `node scripts/check-optional-peers.mjs --write-docs`; CI fails when it drifts. -->
|
|
521
|
+
|
|
522
|
+
Each of these entries imports an optional peer when it loads, so using it means installing that peer:
|
|
523
|
+
|
|
524
|
+
| Entry | Install |
|
|
525
|
+
| --- | --- |
|
|
526
|
+
| `@geekmidas/events/pgboss` | `pg-boss` |
|
|
527
|
+
| `@geekmidas/events/rabbitmq` | `amqplib` |
|
|
528
|
+
| `@geekmidas/events/sns` | `@aws-sdk/client-sns`, `@aws-sdk/client-sqs` |
|
|
529
|
+
| `@geekmidas/events/sqs` | `@aws-sdk/client-sqs` |
|
|
530
|
+
|
|
531
|
+
No other entry imports an optional peer when it loads. `@geekmidas/schema` is loaded only when a feature that uses it runs (an `import()` inside a `try`, whose error names the package to install), or named only in types.
|
|
532
|
+
|
|
533
|
+
<!-- optional-peers:end -->
|
|
534
|
+
|
|
516
535
|
## License
|
|
517
536
|
|
|
518
537
|
MIT
|
package/dist/sns/index.cjs
CHANGED
|
@@ -3,9 +3,9 @@ const require_rolldown_runtime = require("../rolldown-runtime-C0BPl7ul.cjs");
|
|
|
3
3
|
const require_telemetry = require("../telemetry-DG3l807O.cjs");
|
|
4
4
|
const require_SQSSubscriber = require("../SQSSubscriber-COTqWvOk.cjs");
|
|
5
5
|
const require_sns_snsUrl = require("./snsUrl.cjs");
|
|
6
|
+
const require_sns_message = require("./message.cjs");
|
|
6
7
|
let _aws_sdk_client_sqs = require("@aws-sdk/client-sqs");
|
|
7
8
|
let _aws_sdk_client_sns = require("@aws-sdk/client-sns");
|
|
8
|
-
let node_crypto = require("node:crypto");
|
|
9
9
|
//#region src/sns/SNSConnection.ts
|
|
10
10
|
var SNSConnection_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ SNSConnection: () => SNSConnection });
|
|
11
11
|
var SNSConnection = class SNSConnection {
|
|
@@ -274,96 +274,6 @@ const snsEventsDriver = {
|
|
|
274
274
|
};
|
|
275
275
|
//#endregion
|
|
276
276
|
//#region src/sns/push.ts
|
|
277
|
-
/** The fields signed, in the order SNS signs them, per message type. */
|
|
278
|
-
const SIGNED_FIELDS = {
|
|
279
|
-
Notification: [
|
|
280
|
-
"Message",
|
|
281
|
-
"MessageId",
|
|
282
|
-
"Subject",
|
|
283
|
-
"Timestamp",
|
|
284
|
-
"TopicArn",
|
|
285
|
-
"Type"
|
|
286
|
-
],
|
|
287
|
-
SubscriptionConfirmation: [
|
|
288
|
-
"Message",
|
|
289
|
-
"MessageId",
|
|
290
|
-
"SubscribeURL",
|
|
291
|
-
"Timestamp",
|
|
292
|
-
"Token",
|
|
293
|
-
"TopicArn",
|
|
294
|
-
"Type"
|
|
295
|
-
],
|
|
296
|
-
UnsubscribeConfirmation: [
|
|
297
|
-
"Message",
|
|
298
|
-
"MessageId",
|
|
299
|
-
"SubscribeURL",
|
|
300
|
-
"Timestamp",
|
|
301
|
-
"Token",
|
|
302
|
-
"TopicArn",
|
|
303
|
-
"Type"
|
|
304
|
-
]
|
|
305
|
-
};
|
|
306
|
-
/**
|
|
307
|
-
* Where SNS serves its signing certificates. Anywhere else is a certificate
|
|
308
|
-
* the sender chose, which would let the sender sign its own forgeries.
|
|
309
|
-
*/
|
|
310
|
-
const SNS_CERTIFICATE_HOST = /^sns\.[a-z0-9-]+\.amazonaws\.com(\.cn)?$/;
|
|
311
|
-
const certificates = /* @__PURE__ */ new Map();
|
|
312
|
-
async function defaultFetchCertificate(url) {
|
|
313
|
-
const response = await fetch(url);
|
|
314
|
-
if (!response.ok) throw new SnsCertificateUnavailable(url, response.status);
|
|
315
|
-
return response.text();
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* A URL, or undefined for a value that is not one at all — what an emulator
|
|
319
|
-
* sends — so it is untrusted rather than a crash. (`URL.parse` is Node 22.1+.)
|
|
320
|
-
*/
|
|
321
|
-
function parseUrl(value) {
|
|
322
|
-
try {
|
|
323
|
-
return new URL(String(value));
|
|
324
|
-
} catch {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
/** The string SNS signed for this message. */
|
|
329
|
-
function snsStringToSign(message) {
|
|
330
|
-
const fields = SIGNED_FIELDS[message.Type];
|
|
331
|
-
if (!fields) throw new SnsMessageTypeUnknown(String(message.Type));
|
|
332
|
-
return fields.filter((field) => message[field] !== void 0).map((field) => `${field}\n${message[field]}\n`).join("");
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Check that SNS sent this message: the certificate is SNS's own, and the
|
|
336
|
-
* signature over the message's signed fields verifies against it.
|
|
337
|
-
*
|
|
338
|
-
* Throws rather than returning false, so a caller cannot forget to look.
|
|
339
|
-
*/
|
|
340
|
-
async function verifySnsMessage(message, options = {}) {
|
|
341
|
-
const url = parseUrl(message.SigningCertURL);
|
|
342
|
-
if (url?.protocol !== "https:" || !SNS_CERTIFICATE_HOST.test(url.hostname)) throw new SnsCertificateUntrusted(message.SigningCertURL);
|
|
343
|
-
const algorithm = message.SignatureVersion === "1" ? "RSA-SHA1" : message.SignatureVersion === "2" ? "RSA-SHA256" : void 0;
|
|
344
|
-
if (!algorithm) throw new SnsSignatureVersionUnknown(message.SignatureVersion);
|
|
345
|
-
const fetchCertificate = options.fetchCertificate ?? defaultFetchCertificate;
|
|
346
|
-
let certificate = certificates.get(message.SigningCertURL);
|
|
347
|
-
if (!certificate || options.fetchCertificate) {
|
|
348
|
-
certificate = fetchCertificate(message.SigningCertURL);
|
|
349
|
-
if (!options.fetchCertificate) {
|
|
350
|
-
certificates.set(message.SigningCertURL, certificate);
|
|
351
|
-
certificate.catch(() => certificates.delete(message.SigningCertURL));
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
const verifier = (0, node_crypto.createVerify)(algorithm);
|
|
355
|
-
verifier.update(snsStringToSign(message), "utf8");
|
|
356
|
-
if (!verifier.verify(await certificate, message.Signature, "base64")) throw new SnsSignatureInvalid(message.MessageId, message.TopicArn);
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Confirm a subscription by visiting the URL SNS sent. Until this happens SNS
|
|
360
|
-
* delivers nothing to the endpoint.
|
|
361
|
-
*/
|
|
362
|
-
async function confirmSnsSubscription(message, request = fetch) {
|
|
363
|
-
if (message.Type !== "SubscriptionConfirmation" || !message.SubscribeURL) throw new SnsNotAConfirmation(message.Type);
|
|
364
|
-
const response = await request(message.SubscribeURL);
|
|
365
|
-
if (!response.ok) throw new SnsConfirmationFailed(message.TopicArn, response.status);
|
|
366
|
-
}
|
|
367
277
|
/** The subscription attributes a filter asks for, as SNS spells them. */
|
|
368
278
|
function subscriptionAttributes(filter) {
|
|
369
279
|
const attributes = filter.filterPolicy ? {
|
|
@@ -378,7 +288,7 @@ function subscriptionAttributes(filter) {
|
|
|
378
288
|
}
|
|
379
289
|
/** The protocol SNS delivers to an endpoint with, from its URL. */
|
|
380
290
|
function protocolOf(endpoint) {
|
|
381
|
-
const protocol = parseUrl(endpoint)?.protocol.replace(":", "");
|
|
291
|
+
const protocol = require_sns_message.parseUrl(endpoint)?.protocol.replace(":", "");
|
|
382
292
|
if (protocol !== "http" && protocol !== "https") throw new SnsEndpointNotHttp(endpoint);
|
|
383
293
|
return protocol;
|
|
384
294
|
}
|
|
@@ -489,7 +399,7 @@ async function reconcileHttpSubscriptions(connection, options) {
|
|
|
489
399
|
const wanted = new Set(options.endpoints.map((spec) => spec.endpoint));
|
|
490
400
|
for (const { arn, endpoint } of listed) {
|
|
491
401
|
if (!arn || wanted.has(endpoint)) continue;
|
|
492
|
-
if (parseUrl(endpoint)?.host !== options.ownedHost) continue;
|
|
402
|
+
if (require_sns_message.parseUrl(endpoint)?.host !== options.ownedHost) continue;
|
|
493
403
|
await client.send(new _aws_sdk_client_sns.UnsubscribeCommand({ SubscriptionArn: arn }));
|
|
494
404
|
result.removed.push(arn);
|
|
495
405
|
}
|
|
@@ -507,7 +417,7 @@ async function reconcileHttpSubscriptions(connection, options) {
|
|
|
507
417
|
* `sns:ConfirmSubscription` on this one topic.
|
|
508
418
|
*/
|
|
509
419
|
async function confirmSubscription(connection, message) {
|
|
510
|
-
if (message.Type !== "SubscriptionConfirmation" || !message.Token) throw new SnsNotAConfirmation(message.Type);
|
|
420
|
+
if (message.Type !== "SubscriptionConfirmation" || !message.Token) throw new require_sns_message.SnsNotAConfirmation(message.Type);
|
|
511
421
|
const { SubscriptionArn } = await connection.snsClient.send(new _aws_sdk_client_sns.ConfirmSubscriptionCommand({
|
|
512
422
|
TopicArn: message.TopicArn,
|
|
513
423
|
Token: message.Token,
|
|
@@ -539,92 +449,6 @@ async function topicSubscriptions(connection) {
|
|
|
539
449
|
} while (NextToken);
|
|
540
450
|
return found;
|
|
541
451
|
}
|
|
542
|
-
/**
|
|
543
|
-
* A pushed notification as the Lambda event SNS would have invoked a function
|
|
544
|
-
* with, so it can be handed to the same adaptor.
|
|
545
|
-
*/
|
|
546
|
-
function toSnsEvent(message, subscriptionArn = "") {
|
|
547
|
-
return { Records: [{
|
|
548
|
-
EventSource: "aws:sns",
|
|
549
|
-
EventVersion: "1.0",
|
|
550
|
-
EventSubscriptionArn: subscriptionArn,
|
|
551
|
-
Sns: {
|
|
552
|
-
Type: message.Type,
|
|
553
|
-
MessageId: message.MessageId,
|
|
554
|
-
TopicArn: message.TopicArn,
|
|
555
|
-
Subject: message.Subject ?? null,
|
|
556
|
-
Message: message.Message,
|
|
557
|
-
Timestamp: message.Timestamp,
|
|
558
|
-
SignatureVersion: message.SignatureVersion,
|
|
559
|
-
Signature: message.Signature,
|
|
560
|
-
SigningCertUrl: message.SigningCertURL,
|
|
561
|
-
UnsubscribeUrl: message.UnsubscribeURL ?? "",
|
|
562
|
-
MessageAttributes: message.MessageAttributes ?? {}
|
|
563
|
-
}
|
|
564
|
-
}] };
|
|
565
|
-
}
|
|
566
|
-
var SnsCertificateUntrusted = class extends Error {
|
|
567
|
-
url;
|
|
568
|
-
constructor(url) {
|
|
569
|
-
super(`The SNS message names a signing certificate at '${url}', which is not an https URL on sns.<region>.amazonaws.com. Only SNS can send to this endpoint; reject the request.`);
|
|
570
|
-
this.url = url;
|
|
571
|
-
this.name = "SnsCertificateUntrusted";
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
var SnsCertificateUnavailable = class extends Error {
|
|
575
|
-
url;
|
|
576
|
-
status;
|
|
577
|
-
constructor(url, status) {
|
|
578
|
-
super(`Fetching the SNS signing certificate at '${url}' answered ${status}. The message cannot be verified, so it is not handled; SNS will retry.`);
|
|
579
|
-
this.url = url;
|
|
580
|
-
this.status = status;
|
|
581
|
-
this.name = "SnsCertificateUnavailable";
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
var SnsSignatureVersionUnknown = class extends Error {
|
|
585
|
-
version;
|
|
586
|
-
constructor(version) {
|
|
587
|
-
super(`SNS signature version '${version}' is not one this endpoint verifies (it knows '1' and '2'). Reject the request.`);
|
|
588
|
-
this.version = version;
|
|
589
|
-
this.name = "SnsSignatureVersionUnknown";
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
var SnsSignatureInvalid = class extends Error {
|
|
593
|
-
messageId;
|
|
594
|
-
topicArn;
|
|
595
|
-
constructor(messageId, topicArn) {
|
|
596
|
-
super(`SNS message '${messageId}' from '${topicArn}' does not verify against its signing certificate. It was not sent by SNS, or was altered on the way; reject it.`);
|
|
597
|
-
this.messageId = messageId;
|
|
598
|
-
this.topicArn = topicArn;
|
|
599
|
-
this.name = "SnsSignatureInvalid";
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
var SnsMessageTypeUnknown = class extends Error {
|
|
603
|
-
type;
|
|
604
|
-
constructor(type) {
|
|
605
|
-
super(`'${type}' is not an SNS message type (Notification, SubscriptionConfirmation, UnsubscribeConfirmation). Reject it.`);
|
|
606
|
-
this.type = type;
|
|
607
|
-
this.name = "SnsMessageTypeUnknown";
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
var SnsNotAConfirmation = class extends Error {
|
|
611
|
-
type;
|
|
612
|
-
constructor(type) {
|
|
613
|
-
super(`Only a SubscriptionConfirmation carries a URL to confirm; this is a '${type}'.`);
|
|
614
|
-
this.type = type;
|
|
615
|
-
this.name = "SnsNotAConfirmation";
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
var SnsConfirmationFailed = class extends Error {
|
|
619
|
-
topicArn;
|
|
620
|
-
status;
|
|
621
|
-
constructor(topicArn, status) {
|
|
622
|
-
super(`Confirming the subscription to '${topicArn}' answered ${status}. SNS will deliver nothing until it is confirmed; it resends the confirmation, or subscribe the endpoint again.`);
|
|
623
|
-
this.topicArn = topicArn;
|
|
624
|
-
this.status = status;
|
|
625
|
-
this.name = "SnsConfirmationFailed";
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
452
|
var SnsEndpointNotHttp = class extends Error {
|
|
629
453
|
endpoint;
|
|
630
454
|
constructor(endpoint) {
|
|
@@ -647,21 +471,21 @@ var SnsSubscriptionArnMissing = class extends Error {
|
|
|
647
471
|
exports.SNSConnection = SNSConnection;
|
|
648
472
|
exports.SNSPublisher = SNSPublisher;
|
|
649
473
|
exports.SNSSubscriber = SNSSubscriber;
|
|
650
|
-
exports.SnsCertificateUnavailable = SnsCertificateUnavailable;
|
|
651
|
-
exports.SnsCertificateUntrusted = SnsCertificateUntrusted;
|
|
652
|
-
exports.SnsConfirmationFailed = SnsConfirmationFailed;
|
|
474
|
+
exports.SnsCertificateUnavailable = require_sns_message.SnsCertificateUnavailable;
|
|
475
|
+
exports.SnsCertificateUntrusted = require_sns_message.SnsCertificateUntrusted;
|
|
476
|
+
exports.SnsConfirmationFailed = require_sns_message.SnsConfirmationFailed;
|
|
653
477
|
exports.SnsEndpointNotHttp = SnsEndpointNotHttp;
|
|
654
|
-
exports.SnsMessageTypeUnknown = SnsMessageTypeUnknown;
|
|
655
|
-
exports.SnsNotAConfirmation = SnsNotAConfirmation;
|
|
478
|
+
exports.SnsMessageTypeUnknown = require_sns_message.SnsMessageTypeUnknown;
|
|
479
|
+
exports.SnsNotAConfirmation = require_sns_message.SnsNotAConfirmation;
|
|
656
480
|
exports.SnsQueueMissing = SnsQueueMissing;
|
|
657
|
-
exports.SnsSignatureInvalid = SnsSignatureInvalid;
|
|
658
|
-
exports.SnsSignatureVersionUnknown = SnsSignatureVersionUnknown;
|
|
481
|
+
exports.SnsSignatureInvalid = require_sns_message.SnsSignatureInvalid;
|
|
482
|
+
exports.SnsSignatureVersionUnknown = require_sns_message.SnsSignatureVersionUnknown;
|
|
659
483
|
exports.SnsSubscriptionArnMissing = SnsSubscriptionArnMissing;
|
|
660
|
-
exports.confirmSnsSubscription = confirmSnsSubscription;
|
|
484
|
+
exports.confirmSnsSubscription = require_sns_message.confirmSnsSubscription;
|
|
661
485
|
exports.confirmSubscription = confirmSubscription;
|
|
662
486
|
exports.reconcileHttpSubscriptions = reconcileHttpSubscriptions;
|
|
663
487
|
exports.snsEventsDriver = snsEventsDriver;
|
|
664
|
-
exports.snsStringToSign = snsStringToSign;
|
|
488
|
+
exports.snsStringToSign = require_sns_message.snsStringToSign;
|
|
665
489
|
Object.defineProperty(exports, "snsUrl", {
|
|
666
490
|
enumerable: true,
|
|
667
491
|
get: function() {
|
|
@@ -669,7 +493,7 @@ Object.defineProperty(exports, "snsUrl", {
|
|
|
669
493
|
}
|
|
670
494
|
});
|
|
671
495
|
exports.subscribeHttpEndpoint = subscribeHttpEndpoint;
|
|
672
|
-
exports.toSnsEvent = toSnsEvent;
|
|
673
|
-
exports.verifySnsMessage = verifySnsMessage;
|
|
496
|
+
exports.toSnsEvent = require_sns_message.toSnsEvent;
|
|
497
|
+
exports.verifySnsMessage = require_sns_message.verifySnsMessage;
|
|
674
498
|
|
|
675
499
|
//# sourceMappingURL=index.cjs.map
|
package/dist/sns/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["SNSClient","publishTraced","PublishCommand","carrierAsAttributes","SQSClient","SQSConnection","SQSSubscriber","UnsubscribeCommand","DeleteQueueCommand","CreateQueueCommand","GetQueueAttributesCommand","SetQueueAttributesCommand","SubscribeCommand","createVerify","SetSubscriptionAttributesCommand","GetSubscriptionAttributesCommand","UnsubscribeCommand","SubscribeCommand","ConfirmSubscriptionCommand","ListSubscriptionsByTopicCommand"],"sources":["../../src/sns/SNSConnection.ts","../../src/sns/SNSPublisher.ts","../../src/sns/SNSSubscriber.ts","../../src/sns/driver.ts","../../src/sns/push.ts"],"sourcesContent":["import { SNSClient, type SNSClientConfig } from '@aws-sdk/client-sns';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\nimport * as snsUrl from './snsUrl';\n\nexport interface SNSConnectionConfig {\n\ttopicArn: string;\n\tregion?: string;\n\tendpoint?: string; // Custom endpoint (e.g., for LocalStack)\n\t/**\n\t * Static keys, or a provider the SDK resolves them through — a deploy's\n\t * profile or chain, where nothing pins a key pair.\n\t */\n\tcredentials?: SNSClientConfig['credentials'];\n}\n\nexport class SNSConnection implements EventConnection {\n\treadonly type = EventPublisherType.SNS;\n\tprivate client: SNSClient;\n\tprivate connected = false;\n\tprivate config: SNSConnectionConfig;\n\n\tconstructor(config: SNSConnectionConfig) {\n\t\tthis.config = config;\n\n\t\tconst clientConfig: SNSClientConfig = {\n\t\t\tregion: config.region,\n\t\t\tendpoint: config.endpoint,\n\t\t\tcredentials: config.credentials,\n\t\t};\n\n\t\tthis.client = new SNSClient(clientConfig);\n\t}\n\n\t/**\n\t * Create an SNSConnection from a connection string\n\t * Format: sns://?topicArn=arn:aws:sns:region:account:topic®ion=us-east-1&endpoint=http://localhost:4566\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<SNSConnection> {\n\t\t// Through the codec, not a second hand-rolled parse: the deploy target\n\t\t// composes these with `snsUrl.build`, and a string it cannot read back is\n\t\t// exactly the drift one shared module rules out.\n\t\tconst { topicArn, region, endpoint } = snsUrl.parse(connectionString);\n\t\tconst params = new URL(connectionString).searchParams;\n\n\t\tconst config: SNSConnectionConfig = {\n\t\t\ttopicArn,\n\t\t\tregion,\n\t\t\tendpoint,\n\t\t};\n\n\t\t// Credentials are not part of the address — see `snsUrl` — but a caller\n\t\t// may still pin them here, so they are read beside it rather than in it.\n\t\tconst accessKeyId = params.get('accessKeyId');\n\t\tconst secretAccessKey = params.get('secretAccessKey');\n\t\tif (accessKeyId && secretAccessKey) {\n\t\t\tconfig.credentials = {\n\t\t\t\taccessKeyId,\n\t\t\t\tsecretAccessKey,\n\t\t\t\tsessionToken: params.get('sessionToken') || undefined,\n\t\t\t};\n\t\t}\n\n\t\tconst connection = new SNSConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\t// SNS doesn't have a traditional connection, but we mark as connected\n\t\tthis.connected = true;\n\t}\n\n\tasync close(): Promise<void> {\n\t\tthis.client.destroy();\n\t\tthis.connected = false;\n\t}\n\n\tisConnected(): boolean {\n\t\treturn this.connected;\n\t}\n\n\t/**\n\t * Get the underlying SNS client\n\t */\n\tget snsClient(): SNSClient {\n\t\treturn this.client;\n\t}\n\n\t/**\n\t * Get the topic ARN for this connection\n\t */\n\tget topicArn(): string {\n\t\treturn this.config.topicArn;\n\t}\n}\n","import { PublishCommand } from '@aws-sdk/client-sns';\nimport { carrierAsAttributes, publishTraced } from '../telemetry';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport type { SNSConnection } from './SNSConnection';\n\nexport type SNSPublisherOptions = {};\n\nexport class SNSPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: SNSConnection,\n\t\t_options: SNSPublisherOptions = {},\n\t) {}\n\n\t/**\n\t * Create an SNSPublisher from a connection string\n\t * Format: sns://?topicArn=arn:aws:sns:region:account:topic®ion=us-east-1&endpoint=http://localhost:4566\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<SNSPublisher<TMessage>> {\n\t\tconst { SNSConnection } = await import('./SNSConnection');\n\t\tconst connection =\n\t\t\tawait SNSConnection.fromConnectionString(connectionString);\n\n\t\treturn new SNSPublisher<TMessage>(connection);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (messages.length === 0) return;\n\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst topicArn = this.connection.topicArn;\n\t\tconst destination = topicArn.split(':').pop() ?? topicArn;\n\t\tawait publishTraced(\n\t\t\tmessages,\n\t\t\t(message) => ({ system: 'aws_sns', destination, type: message.type }),\n\t\t\t(carriers) =>\n\t\t\t\tPromise.all(\n\t\t\t\t\tmessages.map((message, i) =>\n\t\t\t\t\t\tthis.publishMessage(message, carriers[i]),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t);\n\t}\n\n\tprivate async publishMessage(\n\t\tmessage: TMessage,\n\t\tcarrier: Record<string, string> | undefined,\n\t): Promise<void> {\n\t\tconst command = new PublishCommand({\n\t\t\tTopicArn: this.connection.topicArn,\n\t\t\tMessage: JSON.stringify({\n\t\t\t\ttype: message.type,\n\t\t\t\tpayload: message.payload,\n\t\t\t}),\n\t\t\tMessageAttributes: {\n\t\t\t\ttype: {\n\t\t\t\t\tDataType: 'String',\n\t\t\t\t\tStringValue: message.type,\n\t\t\t\t},\n\t\t\t\t// The trace context as message attributes: SNS hands them on to\n\t\t\t\t// an SQS subscription's envelope, an HTTP push and a Lambda record.\n\t\t\t\t...carrierAsAttributes(carrier),\n\t\t\t},\n\t\t});\n\n\t\tawait this.connection.snsClient.send(command);\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t\t// Connection should be closed by whoever created it\n\t}\n}\n","import { SubscribeCommand, UnsubscribeCommand } from '@aws-sdk/client-sns';\nimport {\n\tCreateQueueCommand,\n\tDeleteQueueCommand,\n\tGetQueueAttributesCommand,\n\tSetQueueAttributesCommand,\n\tSQSClient,\n} from '@aws-sdk/client-sqs';\nimport { SQSConnection } from '../sqs/SQSConnection';\nimport { SQSSubscriber } from '../sqs/SQSSubscriber';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport type { SNSConnection } from './SNSConnection';\n\nexport interface SNSSubscriberOptions {\n\tqueueName?: string; // Optional queue name (defaults to auto-generated)\n\tcreateQueue?: boolean; // Auto-create SQS queue (default: true)\n\tdeleteQueueOnClose?: boolean; // Delete queue when subscriber closes (default: false for named queues, true for auto-generated)\n\twaitTimeSeconds?: number; // SQS long polling (default: 20)\n\tmaxMessages?: number; // Max messages per poll (default: 10)\n}\n\n/**\n * SNS Subscriber - receives push-based messages from SNS via SQS queue\n *\n * Architecture:\n * SNS Topic → (push) → SQS Queue → Subscriber\n *\n * This subscriber automatically:\n * 1. Creates an SQS queue (or uses existing one)\n * 2. Subscribes the queue to the SNS topic\n * 3. Receives messages pushed from SNS to the queue\n * 4. Filters messages by topic ARN and message type\n * 5. Processes and acknowledges messages\n *\n * Note: While SQS long-polling is used internally to receive messages,\n * this is an implementation detail of the SNS push delivery mechanism.\n * Messages are pushed from SNS to SQS, and we receive those pushed messages.\n */\nexport class SNSSubscriber<TMessage extends PublishableMessage<string, any>>\n\timplements EventSubscriber<TMessage>\n{\n\tprivate sqsClient: SQSClient;\n\tprivate queueUrl?: string;\n\tprivate queueArn?: string;\n\tprivate subscriptionArn?: string;\n\tprivate sqsSubscriber?: SQSSubscriber<TMessage>;\n\tprivate options: Required<SNSSubscriberOptions>;\n\n\tconstructor(\n\t\tprivate connection: SNSConnection,\n\t\toptions: SNSSubscriberOptions = {},\n\t) {\n\t\tthis.options = {\n\t\t\tqueueName:\n\t\t\t\toptions.queueName ||\n\t\t\t\t`sns-sub-${Date.now()}-${Math.random().toString(36).substring(7)}`,\n\t\t\tcreateQueue: options.createQueue ?? true,\n\t\t\tdeleteQueueOnClose: options.deleteQueueOnClose ?? !options.queueName, // Delete auto-generated queues\n\t\t\twaitTimeSeconds: options.waitTimeSeconds ?? 20,\n\t\t\tmaxMessages: options.maxMessages ?? 10,\n\t\t};\n\n\t\t// Create SQS client with same config as SNS\n\t\tthis.sqsClient = new SQSClient({\n\t\t\tregion: (this.connection as any).config.region,\n\t\t\tendpoint: (this.connection as any).config.endpoint,\n\t\t\tcredentials: (this.connection as any).config.credentials,\n\t\t});\n\t}\n\n\t/**\n\t * Create an SNSSubscriber from a connection string\n\t * Format: sns://?topicArn=...&queueName=myqueue®ion=us-east-1\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<SNSSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { SNSConnection } = await import('./SNSConnection');\n\t\tconst connection =\n\t\t\tawait SNSConnection.fromConnectionString(connectionString);\n\n\t\tconst options: SNSSubscriberOptions = {\n\t\t\tqueueName: params.get('queueName') || undefined,\n\t\t\tcreateQueue: params.get('createQueue') !== 'false',\n\t\t\tdeleteQueueOnClose: params.get('deleteQueueOnClose') === 'true',\n\t\t\twaitTimeSeconds: params.get('waitTimeSeconds')\n\t\t\t\t? Number.parseInt(params.get('waitTimeSeconds')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new SNSSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\t// Setup SQS queue and SNS subscription\n\t\tawait this.setupQueue();\n\t\tawait this.subscribeToTopic();\n\n\t\t// Create SQS connection for the subscriber\n\t\tconst sqsConnection = new SQSConnection({\n\t\t\tqueueUrl: this.queueUrl!,\n\t\t\tregion: (this.connection as any).config.region,\n\t\t\tendpoint: (this.connection as any).config.endpoint,\n\t\t\tcredentials: (this.connection as any).config.credentials,\n\t\t});\n\t\tawait sqsConnection.connect();\n\n\t\t// Use SQSSubscriber to receive messages, with topic filtering\n\t\tthis.sqsSubscriber = new SQSSubscriber<TMessage>(sqsConnection, {\n\t\t\twaitTimeSeconds: this.options.waitTimeSeconds,\n\t\t\tmaxMessages: this.options.maxMessages,\n\t\t\texpectedTopicArn: this.connection.topicArn,\n\t\t});\n\n\t\tawait this.sqsSubscriber.subscribe(messages, listener);\n\t}\n\n\t/**\n\t * Stop receiving messages and clean up resources\n\t */\n\tasync stop(): Promise<void> {\n\t\t// Stop SQS subscriber\n\t\tif (this.sqsSubscriber) {\n\t\t\tthis.sqsSubscriber.stop();\n\t\t}\n\n\t\t// Unsubscribe from topic\n\t\tif (this.subscriptionArn) {\n\t\t\ttry {\n\t\t\t\tconst command = new UnsubscribeCommand({\n\t\t\t\t\tSubscriptionArn: this.subscriptionArn,\n\t\t\t\t});\n\t\t\t\tawait this.connection.snsClient.send(command);\n\t\t\t} catch (_error) {}\n\t\t}\n\n\t\t// Delete queue if configured\n\t\tif (this.queueUrl && this.options.deleteQueueOnClose) {\n\t\t\ttry {\n\t\t\t\tconst command = new DeleteQueueCommand({\n\t\t\t\t\tQueueUrl: this.queueUrl,\n\t\t\t\t});\n\t\t\t\tawait this.sqsClient.send(command);\n\t\t\t} catch (_error) {}\n\t\t}\n\n\t\tthis.sqsClient.destroy();\n\t}\n\n\tprivate async setupQueue(): Promise<void> {\n\t\tif (this.options.createQueue) {\n\t\t\t// Create queue\n\t\t\tconst createCommand = new CreateQueueCommand({\n\t\t\t\tQueueName: this.options.queueName,\n\t\t\t});\n\t\t\tconst response = await this.sqsClient.send(createCommand);\n\t\t\tthis.queueUrl = response.QueueUrl!;\n\t\t} else {\n\t\t\tthrow new SnsQueueMissing(this.options.queueName);\n\t\t}\n\n\t\t// Get queue ARN\n\t\tconst attrsCommand = new GetQueueAttributesCommand({\n\t\t\tQueueUrl: this.queueUrl,\n\t\t\tAttributeNames: ['QueueArn'],\n\t\t});\n\t\tconst attrsResponse = await this.sqsClient.send(attrsCommand);\n\t\tthis.queueArn = attrsResponse.Attributes?.QueueArn!;\n\n\t\t// Set queue policy to allow SNS\n\t\tawait this.setQueuePolicy();\n\t}\n\n\tprivate async setQueuePolicy(): Promise<void> {\n\t\tconst policy = {\n\t\t\tVersion: '2012-10-17',\n\t\t\tStatement: [\n\t\t\t\t{\n\t\t\t\t\tEffect: 'Allow',\n\t\t\t\t\tPrincipal: '*',\n\t\t\t\t\tAction: 'SQS:SendMessage',\n\t\t\t\t\tResource: this.queueArn,\n\t\t\t\t\tCondition: {\n\t\t\t\t\t\tArnEquals: {\n\t\t\t\t\t\t\t'aws:SourceArn': this.connection.topicArn,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\n\t\tconst command = new SetQueueAttributesCommand({\n\t\t\tQueueUrl: this.queueUrl,\n\t\t\tAttributes: {\n\t\t\t\tPolicy: JSON.stringify(policy),\n\t\t\t},\n\t\t});\n\n\t\tawait this.sqsClient.send(command);\n\t}\n\n\tprivate async subscribeToTopic(): Promise<void> {\n\t\tconst command = new SubscribeCommand({\n\t\t\tTopicArn: this.connection.topicArn,\n\t\t\tProtocol: 'sqs',\n\t\t\tEndpoint: this.queueArn,\n\t\t});\n\n\t\tconst response = await this.connection.snsClient.send(command);\n\t\tthis.subscriptionArn = response.SubscriptionArn!;\n\t}\n}\n\n/**\n * A subscriber asked to use a queue it may not create. The SQS queue behind an\n * SNS subscription has to exist first, or `createQueue` has to allow it.\n */\nexport class SnsQueueMissing extends Error {\n\tconstructor(readonly queueName: string | undefined) {\n\t\tsuper(\n\t\t\t`The SNS subscriber's queue${queueName ? ` \"${queueName}\"` : ''} is not created here: pass createQueue: true, or create the queue first.`,\n\t\t);\n\t\tthis.name = 'SnsQueueMissing';\n\t}\n}\n","import type { EventsDriver } from '../registry';\nimport { EventPublisherType } from '../types';\nimport { SNSConnection } from './SNSConnection';\nimport { SNSPublisher } from './SNSPublisher';\nimport { SNSSubscriber } from './SNSSubscriber';\n\n/**\n * `sns://` — an SNS topic, consumed through an SQS queue subscribed to it.\n * Register it with `registerEventsDriver(snsEventsDriver)`; an AWS entry\n * registers `sqsEventsDriver` beside it.\n */\nexport const snsEventsDriver: EventsDriver = {\n\tscheme: EventPublisherType.SNS,\n\tconnect: (url) => SNSConnection.fromConnectionString(url),\n\tpublisher: (url) => SNSPublisher.fromConnectionString(url),\n\tpublisherFor: (connection) => new SNSPublisher(connection as SNSConnection),\n\tsubscriber: (url) => SNSSubscriber.fromConnectionString(url),\n\tsubscriberFor: (connection) => new SNSSubscriber(connection as SNSConnection),\n};\n","import { createVerify } from 'node:crypto';\nimport {\n\tConfirmSubscriptionCommand,\n\tGetSubscriptionAttributesCommand,\n\tListSubscriptionsByTopicCommand,\n\tSetSubscriptionAttributesCommand,\n\tSubscribeCommand,\n\ttype SubscribeCommandInput,\n\tUnsubscribeCommand,\n} from '@aws-sdk/client-sns';\nimport type { SNSConnection } from './SNSConnection';\n\n/**\n * SNS delivering to an HTTP(S) endpoint, rather than to a queue that is polled.\n *\n * SNS POSTs each message to the subscribed URL as JSON. That is the whole\n * transport: no queue in between, no poller, and the endpoint is handed the\n * same envelope a Lambda subscription receives inside `Records[].Sns` — so the\n * handler that runs deployed can be the one that runs here.\n *\n * The endpoint is public, so a message is trusted only once its signature\n * checks out against a certificate SNS itself serves. Anything else that POSTs\n * there is somebody's guess at the shape.\n */\n\n/** A message SNS POSTs to a subscribed HTTP endpoint. */\nexport interface SnsHttpMessage {\n\tType: 'Notification' | 'SubscriptionConfirmation' | 'UnsubscribeConfirmation';\n\tMessageId: string;\n\tTopicArn: string;\n\tMessage: string;\n\tTimestamp: string;\n\tSignatureVersion: string;\n\tSignature: string;\n\tSigningCertURL: string;\n\tSubject?: string;\n\t/** Confirmation messages only. */\n\tToken?: string;\n\t/** Confirmation messages only: GET it to confirm. */\n\tSubscribeURL?: string;\n\t/** Notifications only. */\n\tUnsubscribeURL?: string;\n\tMessageAttributes?: Record<string, { Type: string; Value: string }>;\n}\n\n/** The fields signed, in the order SNS signs them, per message type. */\nconst SIGNED_FIELDS: Record<SnsHttpMessage['Type'], (keyof SnsHttpMessage)[]> =\n\t{\n\t\tNotification: [\n\t\t\t'Message',\n\t\t\t'MessageId',\n\t\t\t'Subject',\n\t\t\t'Timestamp',\n\t\t\t'TopicArn',\n\t\t\t'Type',\n\t\t],\n\t\tSubscriptionConfirmation: [\n\t\t\t'Message',\n\t\t\t'MessageId',\n\t\t\t'SubscribeURL',\n\t\t\t'Timestamp',\n\t\t\t'Token',\n\t\t\t'TopicArn',\n\t\t\t'Type',\n\t\t],\n\t\tUnsubscribeConfirmation: [\n\t\t\t'Message',\n\t\t\t'MessageId',\n\t\t\t'SubscribeURL',\n\t\t\t'Timestamp',\n\t\t\t'Token',\n\t\t\t'TopicArn',\n\t\t\t'Type',\n\t\t],\n\t};\n\n/**\n * Where SNS serves its signing certificates. Anywhere else is a certificate\n * the sender chose, which would let the sender sign its own forgeries.\n */\nconst SNS_CERTIFICATE_HOST = /^sns\\.[a-z0-9-]+\\.amazonaws\\.com(\\.cn)?$/;\n\nexport interface VerifySnsMessageOptions {\n\t/**\n\t * Fetch the PEM at a certificate URL. `fetch` by default; replaceable so a\n\t * test signs with its own key instead of SNS's.\n\t */\n\tfetchCertificate?: (url: string) => Promise<string>;\n}\n\nconst certificates = new Map<string, Promise<string>>();\n\nasync function defaultFetchCertificate(url: string): Promise<string> {\n\tconst response = await fetch(url);\n\tif (!response.ok) throw new SnsCertificateUnavailable(url, response.status);\n\treturn response.text();\n}\n\n/**\n * A URL, or undefined for a value that is not one at all — what an emulator\n * sends — so it is untrusted rather than a crash. (`URL.parse` is Node 22.1+.)\n */\nfunction parseUrl(value: unknown): URL | undefined {\n\ttry {\n\t\treturn new URL(String(value));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** The string SNS signed for this message. */\nexport function snsStringToSign(message: SnsHttpMessage): string {\n\tconst fields = SIGNED_FIELDS[message.Type];\n\tif (!fields) throw new SnsMessageTypeUnknown(String(message.Type));\n\n\treturn fields\n\t\t.filter((field) => message[field] !== undefined)\n\t\t.map((field) => `${field}\\n${message[field]}\\n`)\n\t\t.join('');\n}\n\n/**\n * Check that SNS sent this message: the certificate is SNS's own, and the\n * signature over the message's signed fields verifies against it.\n *\n * Throws rather than returning false, so a caller cannot forget to look.\n */\nexport async function verifySnsMessage(\n\tmessage: SnsHttpMessage,\n\toptions: VerifySnsMessageOptions = {},\n): Promise<void> {\n\tconst url = parseUrl(message.SigningCertURL);\n\tif (url?.protocol !== 'https:' || !SNS_CERTIFICATE_HOST.test(url.hostname)) {\n\t\tthrow new SnsCertificateUntrusted(message.SigningCertURL);\n\t}\n\n\tconst algorithm =\n\t\tmessage.SignatureVersion === '1'\n\t\t\t? 'RSA-SHA1'\n\t\t\t: message.SignatureVersion === '2'\n\t\t\t\t? 'RSA-SHA256'\n\t\t\t\t: undefined;\n\tif (!algorithm) {\n\t\tthrow new SnsSignatureVersionUnknown(message.SignatureVersion);\n\t}\n\n\tconst fetchCertificate = options.fetchCertificate ?? defaultFetchCertificate;\n\tlet certificate = certificates.get(message.SigningCertURL);\n\tif (!certificate || options.fetchCertificate) {\n\t\tcertificate = fetchCertificate(message.SigningCertURL);\n\t\t// Only SNS's real fetch is cached: a test's key belongs to that test.\n\t\tif (!options.fetchCertificate) {\n\t\t\tcertificates.set(message.SigningCertURL, certificate);\n\t\t\tcertificate.catch(() => certificates.delete(message.SigningCertURL));\n\t\t}\n\t}\n\n\tconst verifier = createVerify(algorithm);\n\tverifier.update(snsStringToSign(message), 'utf8');\n\tif (!verifier.verify(await certificate, message.Signature, 'base64')) {\n\t\tthrow new SnsSignatureInvalid(message.MessageId, message.TopicArn);\n\t}\n}\n\n/**\n * Confirm a subscription by visiting the URL SNS sent. Until this happens SNS\n * delivers nothing to the endpoint.\n */\nexport async function confirmSnsSubscription(\n\tmessage: SnsHttpMessage,\n\trequest: (url: string) => Promise<{ ok: boolean; status: number }> = fetch,\n): Promise<void> {\n\tif (message.Type !== 'SubscriptionConfirmation' || !message.SubscribeURL) {\n\t\tthrow new SnsNotAConfirmation(message.Type);\n\t}\n\n\tconst response = await request(message.SubscribeURL);\n\tif (!response.ok) {\n\t\tthrow new SnsConfirmationFailed(message.TopicArn, response.status);\n\t}\n}\n\n/** Where a subscription's filter policy is matched. */\nexport type SnsFilterPolicyScope = 'MessageAttributes' | 'MessageBody';\n\n/** What an HTTP subscription is created or brought up to date with. */\nexport interface HttpSubscriptionFilter {\n\t/**\n\t * The event types this endpoint takes. Becomes the subscription's filter\n\t * policy on the `type` attribute `SNSPublisher` sets, so SNS sends nothing\n\t * else — fan-out to every subscriber, each seeing only what it named.\n\t *\n\t * Absent, with no {@link filterPolicy} either, for a topic whose\n\t * publisher sets no `type` — a bucket's — whose subscriber filters what it\n\t * is sent.\n\t *\n\t * Ignored when {@link filterPolicy} is given.\n\t */\n\tevents?: readonly string[];\n\t/**\n\t * A filter policy of the caller's own, for messages SNS did not receive\n\t * from `SNSPublisher` — a bucket's notifications carry no `type` attribute,\n\t * so they are matched on their body instead.\n\t */\n\tfilterPolicy?: Record<string, unknown>;\n\t/** Where {@link filterPolicy} is matched. `MessageAttributes` by default. */\n\tfilterPolicyScope?: SnsFilterPolicyScope;\n\t/**\n\t * An SQS queue's ARN for what SNS gives up delivering. SNS retries an HTTP\n\t * endpoint for a limited time and then drops the message, so without one an\n\t * outage longer than that loses events.\n\t */\n\tdeadLetterQueueArn?: string;\n}\n\nexport interface SubscribeHttpEndpointOptions extends HttpSubscriptionFilter {\n\t/** The URL SNS POSTs to — `http:` or `https:`, which picks the protocol. */\n\tendpoint: string;\n}\n\n/** The subscription attributes a filter asks for, as SNS spells them. */\nfunction subscriptionAttributes(\n\tfilter: HttpSubscriptionFilter,\n): Record<string, string> {\n\tconst attributes: Record<string, string> = filter.filterPolicy\n\t\t? {\n\t\t\t\tFilterPolicyScope: filter.filterPolicyScope ?? 'MessageAttributes',\n\t\t\t\tFilterPolicy: JSON.stringify(filter.filterPolicy),\n\t\t\t}\n\t\t: filter.events\n\t\t\t? {\n\t\t\t\t\tFilterPolicyScope: 'MessageAttributes',\n\t\t\t\t\tFilterPolicy: JSON.stringify({ type: [...filter.events] }),\n\t\t\t\t}\n\t\t\t: {};\n\tif (filter.deadLetterQueueArn) {\n\t\tattributes.RedrivePolicy = JSON.stringify({\n\t\t\tdeadLetterTargetArn: filter.deadLetterQueueArn,\n\t\t});\n\t}\n\treturn attributes;\n}\n\n/** The protocol SNS delivers to an endpoint with, from its URL. */\nfunction protocolOf(endpoint: string): 'http' | 'https' {\n\tconst protocol = parseUrl(endpoint)?.protocol.replace(':', '');\n\tif (protocol !== 'http' && protocol !== 'https') {\n\t\tthrow new SnsEndpointNotHttp(endpoint);\n\t}\n\treturn protocol;\n}\n\n/** Bring an existing subscription's attributes up to what is asked for. */\nasync function updateAttributes(\n\tconnection: SNSConnection,\n\tsubscriptionArn: string,\n\tcurrent: Record<string, string>,\n\twanted: Record<string, string>,\n): Promise<void> {\n\tfor (const [name, value] of Object.entries(wanted)) {\n\t\tif (current[name] === value) continue;\n\t\tawait connection.snsClient.send(\n\t\t\tnew SetSubscriptionAttributesCommand({\n\t\t\t\tSubscriptionArn: subscriptionArn,\n\t\t\t\tAttributeName: name,\n\t\t\t\tAttributeValue: value,\n\t\t\t}),\n\t\t);\n\t}\n}\n\n/**\n * Subscribe an HTTP endpoint to the connection's topic, converging on one\n * confirmed subscription with the filter asked for — so it is safe on every\n * start. What a server does against an emulator, where nothing deploys it;\n * against SNS itself the deploy owns the subscription\n * ({@link reconcileHttpSubscriptions}).\n *\n * - **none yet** — subscribed; SNS sends a confirmation to the endpoint.\n * - **confirmed** — its filter and dead-letter queue are brought up to date.\n * Subscribing again with different attributes is an error on SNS, and the\n * events a subscriber names change.\n * - **stuck pending** — a confirmation that never landed (the endpoint was\n * down, or answered wrong). Subscribing the same endpoint again is a no-op\n * on an emulator, so it is dropped and subscribed afresh, which sends a new\n * confirmation.\n */\nexport async function subscribeHttpEndpoint(\n\tconnection: SNSConnection,\n\toptions: SubscribeHttpEndpointOptions,\n): Promise<string | undefined> {\n\tconst protocol = protocolOf(options.endpoint);\n\tconst attributes = subscriptionAttributes(options);\n\n\tconst client = connection.snsClient;\n\tconst existing = (await topicSubscriptions(connection)).find(\n\t\t(s) => s.endpoint === options.endpoint,\n\t)?.arn;\n\tif (existing) {\n\t\tconst { Attributes = {} } = await client.send(\n\t\t\tnew GetSubscriptionAttributesCommand({ SubscriptionArn: existing }),\n\t\t);\n\t\tif (Attributes.PendingConfirmation === 'true') {\n\t\t\tawait client.send(new UnsubscribeCommand({ SubscriptionArn: existing }));\n\t\t} else {\n\t\t\tawait updateAttributes(connection, existing, Attributes, attributes);\n\t\t\treturn existing;\n\t\t}\n\t}\n\n\tconst { SubscriptionArn } = await client.send(\n\t\tnew SubscribeCommand({\n\t\t\tTopicArn: connection.topicArn,\n\t\t\tProtocol: protocol,\n\t\t\tEndpoint: options.endpoint,\n\t\t\tAttributes: attributes as SubscribeCommandInput['Attributes'],\n\t\t\tReturnSubscriptionArn: true,\n\t\t}),\n\t);\n\treturn SubscriptionArn;\n}\n\n/** One endpoint the deploy wants subscribed, under the name it is recorded by. */\nexport interface HttpSubscriptionSpec extends HttpSubscriptionFilter {\n\t/** What the ARN is recorded under — the subscriber's export. */\n\tname: string;\n\t/** The URL SNS POSTs to. */\n\tendpoint: string;\n}\n\nexport interface ReconcileHttpSubscriptionsOptions {\n\t/** Every endpoint that should be subscribed to the topic. */\n\tendpoints: readonly HttpSubscriptionSpec[];\n\t/**\n\t * The host these endpoints answer on. A subscription to an endpoint on it\n\t * that is not in {@link endpoints} — a subscriber renamed or removed — is\n\t * unsubscribed; anything subscribed on another host is somebody else's and\n\t * left alone.\n\t */\n\townedHost: string;\n}\n\nexport interface ReconciledHttpSubscriptions {\n\t/** Each endpoint's subscription ARN, by its name — stable across runs. */\n\tsubscriptions: Record<string, string>;\n\t/** The names whose subscription SNS still waits to have confirmed. */\n\tpending: string[];\n\t/** The ARNs of what was unsubscribed as no longer wanted. */\n\tremoved: string[];\n}\n\n/**\n * Converge a topic's HTTP subscriptions on the endpoints a deploy wants, and\n * answer each one's ARN for the deploy to record and hand to the server.\n *\n * The deploy's half of push delivery against SNS itself: the server never\n * subscribes, so its credentials need no `sns:Subscribe` — and the only\n * subscriptions to the topic are ones the deploy made.\n *\n * Run it twice: once before the server starts, for the ARNs it is configured\n * with — SNS answers one even while the subscription waits to be confirmed —\n * and once the server is up, which subscribes each still-pending endpoint\n * again so SNS resends its confirmation to a server now there to answer it.\n * The ARN does not change between the two.\n *\n * - **absent** — subscribed with its filter.\n * - **present** — its filter and dead-letter queue are brought up to date;\n * pending, it is subscribed again to resend the confirmation.\n * - **stale** — on {@link ReconcileHttpSubscriptionsOptions.ownedHost} and no\n * longer wanted: unsubscribed. (A stale one SNS still lists as pending has\n * no ARN to act on; SNS drops it unconfirmed after three days.)\n */\nexport async function reconcileHttpSubscriptions(\n\tconnection: SNSConnection,\n\toptions: ReconcileHttpSubscriptionsOptions,\n): Promise<ReconciledHttpSubscriptions> {\n\tconst client = connection.snsClient;\n\tconst listed = await topicSubscriptions(connection);\n\tconst result: ReconciledHttpSubscriptions = {\n\t\tsubscriptions: {},\n\t\tpending: [],\n\t\tremoved: [],\n\t};\n\n\tfor (const spec of options.endpoints) {\n\t\tconst protocol = protocolOf(spec.endpoint);\n\t\tconst attributes = subscriptionAttributes(spec);\n\t\tconst subscribe = async () =>\n\t\t\t(\n\t\t\t\tawait client.send(\n\t\t\t\t\tnew SubscribeCommand({\n\t\t\t\t\t\tTopicArn: connection.topicArn,\n\t\t\t\t\t\tProtocol: protocol,\n\t\t\t\t\t\tEndpoint: spec.endpoint,\n\t\t\t\t\t\tAttributes: attributes as SubscribeCommandInput['Attributes'],\n\t\t\t\t\t\tReturnSubscriptionArn: true,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t).SubscriptionArn;\n\n\t\tconst existing = listed.find((s) => s.endpoint === spec.endpoint)?.arn;\n\t\tlet arn: string | undefined;\n\t\tlet pending: boolean;\n\t\tif (existing) {\n\t\t\tconst { Attributes = {} } = await client.send(\n\t\t\t\tnew GetSubscriptionAttributesCommand({ SubscriptionArn: existing }),\n\t\t\t);\n\t\t\tawait updateAttributes(connection, existing, Attributes, attributes);\n\t\t\tpending = Attributes.PendingConfirmation === 'true';\n\t\t\t// Subscribing a pending endpoint again resends its confirmation,\n\t\t\t// under the same ARN.\n\t\t\tarn = pending ? ((await subscribe()) ?? existing) : existing;\n\t\t} else {\n\t\t\t// Absent — or pending on SNS itself, which lists it with no ARN:\n\t\t\t// subscribing answers the one it has, and resends the confirmation.\n\t\t\tarn = await subscribe();\n\t\t\tpending = true;\n\t\t}\n\t\tif (!arn) {\n\t\t\tthrow new SnsSubscriptionArnMissing(connection.topicArn, spec.endpoint);\n\t\t}\n\n\t\tresult.subscriptions[spec.name] = arn;\n\t\tif (pending) result.pending.push(spec.name);\n\t}\n\n\tconst wanted = new Set(options.endpoints.map((spec) => spec.endpoint));\n\tfor (const { arn, endpoint } of listed) {\n\t\tif (!arn || wanted.has(endpoint)) continue;\n\t\tif (parseUrl(endpoint)?.host !== options.ownedHost) continue;\n\t\tawait client.send(new UnsubscribeCommand({ SubscriptionArn: arn }));\n\t\tresult.removed.push(arn);\n\t}\n\n\treturn result;\n}\n\n/**\n * Confirm a subscription through the API, as its topic's owner, rather than by\n * visiting the URL SNS sent.\n *\n * `AuthenticateOnUnsubscribe` is the point of it. A subscription confirmed by\n * visiting `SubscribeURL` can be removed by anyone holding the\n * `UnsubscribeURL` every notification carries — one unauthenticated GET, and\n * the endpoint is silently cut off. Confirmed this way, only the topic's owner\n * can unsubscribe it. All it takes of the caller's credentials is\n * `sns:ConfirmSubscription` on this one topic.\n */\nexport async function confirmSubscription(\n\tconnection: SNSConnection,\n\tmessage: SnsHttpMessage,\n): Promise<string | undefined> {\n\tif (message.Type !== 'SubscriptionConfirmation' || !message.Token) {\n\t\tthrow new SnsNotAConfirmation(message.Type);\n\t}\n\n\tconst { SubscriptionArn } = await connection.snsClient.send(\n\t\tnew ConfirmSubscriptionCommand({\n\t\t\tTopicArn: message.TopicArn,\n\t\t\tToken: message.Token,\n\t\t\tAuthenticateOnUnsubscribe: 'true',\n\t\t}),\n\t);\n\treturn SubscriptionArn;\n}\n\n/**\n * Every subscription on the connection's topic, with the ARN SNS names for it\n * — none for one real SNS lists as `PendingConfirmation`, which there is no\n * ARN to act on (and which a new Subscribe resends the confirmation of anyway).\n */\nasync function topicSubscriptions(\n\tconnection: SNSConnection,\n): Promise<{ arn?: string; endpoint: string }[]> {\n\tconst found: { arn?: string; endpoint: string }[] = [];\n\tlet NextToken: string | undefined;\n\tdo {\n\t\tconst page = await connection.snsClient.send(\n\t\t\tnew ListSubscriptionsByTopicCommand({\n\t\t\t\tTopicArn: connection.topicArn,\n\t\t\t\tNextToken,\n\t\t\t}),\n\t\t);\n\t\tfor (const s of page.Subscriptions ?? []) {\n\t\t\tif (!s.Endpoint) continue;\n\t\t\tfound.push({\n\t\t\t\tendpoint: s.Endpoint,\n\t\t\t\t...(s.SubscriptionArn?.startsWith('arn:')\n\t\t\t\t\t? { arn: s.SubscriptionArn }\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\t}\n\t\tNextToken = page.NextToken;\n\t} while (NextToken);\n\treturn found;\n}\n\n/**\n * A pushed notification as the Lambda event SNS would have invoked a function\n * with, so it can be handed to the same adaptor.\n */\nexport function toSnsEvent(message: SnsHttpMessage, subscriptionArn = '') {\n\treturn {\n\t\tRecords: [\n\t\t\t{\n\t\t\t\tEventSource: 'aws:sns',\n\t\t\t\tEventVersion: '1.0',\n\t\t\t\tEventSubscriptionArn: subscriptionArn,\n\t\t\t\tSns: {\n\t\t\t\t\tType: message.Type,\n\t\t\t\t\tMessageId: message.MessageId,\n\t\t\t\t\tTopicArn: message.TopicArn,\n\t\t\t\t\tSubject: message.Subject ?? null,\n\t\t\t\t\tMessage: message.Message,\n\t\t\t\t\tTimestamp: message.Timestamp,\n\t\t\t\t\tSignatureVersion: message.SignatureVersion,\n\t\t\t\t\tSignature: message.Signature,\n\t\t\t\t\t// Lambda spells these two differently from the HTTP envelope.\n\t\t\t\t\tSigningCertUrl: message.SigningCertURL,\n\t\t\t\t\tUnsubscribeUrl: message.UnsubscribeURL ?? '',\n\t\t\t\t\tMessageAttributes: message.MessageAttributes ?? {},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t};\n}\n\nexport class SnsCertificateUntrusted extends Error {\n\tconstructor(readonly url: string) {\n\t\tsuper(\n\t\t\t`The SNS message names a signing certificate at '${url}', which is not ` +\n\t\t\t\t'an https URL on sns.<region>.amazonaws.com. Only SNS can send to ' +\n\t\t\t\t'this endpoint; reject the request.',\n\t\t);\n\t\tthis.name = 'SnsCertificateUntrusted';\n\t}\n}\n\nexport class SnsCertificateUnavailable extends Error {\n\tconstructor(\n\t\treadonly url: string,\n\t\treadonly status: number,\n\t) {\n\t\tsuper(\n\t\t\t`Fetching the SNS signing certificate at '${url}' answered ${status}. ` +\n\t\t\t\t'The message cannot be verified, so it is not handled; SNS will retry.',\n\t\t);\n\t\tthis.name = 'SnsCertificateUnavailable';\n\t}\n}\n\nexport class SnsSignatureVersionUnknown extends Error {\n\tconstructor(readonly version: string) {\n\t\tsuper(\n\t\t\t`SNS signature version '${version}' is not one this endpoint verifies ` +\n\t\t\t\t\"(it knows '1' and '2'). Reject the request.\",\n\t\t);\n\t\tthis.name = 'SnsSignatureVersionUnknown';\n\t}\n}\n\nexport class SnsSignatureInvalid extends Error {\n\tconstructor(\n\t\treadonly messageId: string,\n\t\treadonly topicArn: string,\n\t) {\n\t\tsuper(\n\t\t\t`SNS message '${messageId}' from '${topicArn}' does not verify against ` +\n\t\t\t\t'its signing certificate. It was not sent by SNS, or was altered ' +\n\t\t\t\t'on the way; reject it.',\n\t\t);\n\t\tthis.name = 'SnsSignatureInvalid';\n\t}\n}\n\nexport class SnsMessageTypeUnknown extends Error {\n\tconstructor(readonly type: string) {\n\t\tsuper(\n\t\t\t`'${type}' is not an SNS message type (Notification, ` +\n\t\t\t\t'SubscriptionConfirmation, UnsubscribeConfirmation). Reject it.',\n\t\t);\n\t\tthis.name = 'SnsMessageTypeUnknown';\n\t}\n}\n\nexport class SnsNotAConfirmation extends Error {\n\tconstructor(readonly type: string) {\n\t\tsuper(\n\t\t\t`Only a SubscriptionConfirmation carries a URL to confirm; this is a ` +\n\t\t\t\t`'${type}'.`,\n\t\t);\n\t\tthis.name = 'SnsNotAConfirmation';\n\t}\n}\n\nexport class SnsConfirmationFailed extends Error {\n\tconstructor(\n\t\treadonly topicArn: string,\n\t\treadonly status: number,\n\t) {\n\t\tsuper(\n\t\t\t`Confirming the subscription to '${topicArn}' answered ${status}. ` +\n\t\t\t\t'SNS will deliver nothing until it is confirmed; it resends the ' +\n\t\t\t\t'confirmation, or subscribe the endpoint again.',\n\t\t);\n\t\tthis.name = 'SnsConfirmationFailed';\n\t}\n}\n\nexport class SnsEndpointNotHttp extends Error {\n\tconstructor(readonly endpoint: string) {\n\t\tsuper(\n\t\t\t`'${endpoint}' is not an http(s) URL. SNS pushes to an HTTP endpoint; ` +\n\t\t\t\t'subscribe a queue for anything else.',\n\t\t);\n\t\tthis.name = 'SnsEndpointNotHttp';\n\t}\n}\n\nexport class SnsSubscriptionArnMissing extends Error {\n\tconstructor(\n\t\treadonly topicArn: string,\n\t\treadonly endpoint: string,\n\t) {\n\t\tsuper(\n\t\t\t`Subscribing '${endpoint}' to '${topicArn}' answered no subscription ` +\n\t\t\t\t'ARN, so there is nothing to record for the server to accept. ' +\n\t\t\t\t'Check the topic exists and the deploy may subscribe to it.',\n\t\t);\n\t\tthis.name = 'SnsSubscriptionArnMissing';\n\t}\n}\n"],"mappings":";;;;;;;;;;AAgBA,IAAa,gBAAb,MAAa,cAAyC;CACrD,OAAS;CACT;CACA,YAAoB;CACpB;CAEA,YAAY,QAA6B;EACxC,KAAK,SAAS;EAEd,MAAM,eAAgC;GACrC,QAAQ,OAAO;GACf,UAAU,OAAO;GACjB,aAAa,OAAO;EACrB;EAEA,KAAK,SAAS,IAAIA,oBAAAA,UAAU,YAAY;CACzC;;;;;CAMA,aAAa,qBACZ,kBACyB;EAIzB,MAAM,EAAE,UAAU,QAAQ,aAAA,mBAAA,MAA0B,gBAAgB;EACpE,MAAM,SAAS,IAAI,IAAI,gBAAgB,CAAC,CAAC;EAEzC,MAAM,SAA8B;GACnC;GACA;GACA;EACD;EAIA,MAAM,cAAc,OAAO,IAAI,aAAa;EAC5C,MAAM,kBAAkB,OAAO,IAAI,iBAAiB;EACpD,IAAI,eAAe,iBAClB,OAAO,cAAc;GACpB;GACA;GACA,cAAc,OAAO,IAAI,cAAc,KAAK,KAAA;EAC7C;EAGD,MAAM,aAAa,IAAI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0BAA0B,QAAQ,gFAEnC;EAJoB,KAAA,UAAA;EAKpB,KAAK,OAAO;CACb;AACD;AAEA,IAAa,sBAAb,cAAyC,MAAM;CAEpC;CACA;CAFV,YACC,WACA,UACC;EACD,MACC,gBAAgB,UAAU,UAAU,SAAS,iHAG9C;EAPS,KAAA,YAAA;EACA,KAAA,WAAA;EAOT,KAAK,OAAO;CACb;AACD;AAEA,IAAa,wBAAb,cAA2C,MAAM;CAC3B;CAArB,YAAY,MAAuB;EAClC,MACC,IAAI,KAAK,2GAEV;EAJoB,KAAA,OAAA;EAKpB,KAAK,OAAO;CACb;AACD;AAEA,IAAa,sBAAb,cAAyC,MAAM;CACzB;CAArB,YAAY,MAAuB;EAClC,MACC,wEACK,KAAK,GACX;EAJoB,KAAA,OAAA;EAKpB,KAAK,OAAO;CACb;AACD;AAEA,IAAa,wBAAb,cAA2C,MAAM;CAEtC;CACA;CAFV,YACC,UACA,QACC;EACD,MACC,mCAAmC,SAAS,aAAa,OAAO,gHAGjE;EAPS,KAAA,WAAA;EACA,KAAA,SAAA;EAOT,KAAK,OAAO;CACb;AACD;AAEA,IAAa,qBAAb,cAAwC,MAAM;CACxB;CAArB,YAAY,UAA2B;EACtC,MACC,IAAI,SAAS,8FAEd;EAJoB,KAAA,WAAA;EAKpB,KAAK,OAAO;CACb;AACD;AAEA,IAAa,4BAAb,cAA+C,MAAM;CAE1C;CACA;CAFV,YACC,UACA,UACC;EACD,MACC,gBAAgB,SAAS,QAAQ,SAAS,mJAG3C;EAPS,KAAA,WAAA;EACA,KAAA,WAAA;EAOT,KAAK,OAAO;CACb;AACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["SNSClient","publishTraced","PublishCommand","carrierAsAttributes","SQSClient","SQSConnection","SQSSubscriber","UnsubscribeCommand","DeleteQueueCommand","CreateQueueCommand","GetQueueAttributesCommand","SetQueueAttributesCommand","SubscribeCommand","parseUrl","SetSubscriptionAttributesCommand","GetSubscriptionAttributesCommand","UnsubscribeCommand","SubscribeCommand","SnsNotAConfirmation","ConfirmSubscriptionCommand","ListSubscriptionsByTopicCommand"],"sources":["../../src/sns/SNSConnection.ts","../../src/sns/SNSPublisher.ts","../../src/sns/SNSSubscriber.ts","../../src/sns/driver.ts","../../src/sns/push.ts"],"sourcesContent":["import { SNSClient, type SNSClientConfig } from '@aws-sdk/client-sns';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\nimport * as snsUrl from './snsUrl';\n\nexport interface SNSConnectionConfig {\n\ttopicArn: string;\n\tregion?: string;\n\tendpoint?: string; // Custom endpoint (e.g., for LocalStack)\n\t/**\n\t * Static keys, or a provider the SDK resolves them through — a deploy's\n\t * profile or chain, where nothing pins a key pair.\n\t */\n\tcredentials?: SNSClientConfig['credentials'];\n}\n\nexport class SNSConnection implements EventConnection {\n\treadonly type = EventPublisherType.SNS;\n\tprivate client: SNSClient;\n\tprivate connected = false;\n\tprivate config: SNSConnectionConfig;\n\n\tconstructor(config: SNSConnectionConfig) {\n\t\tthis.config = config;\n\n\t\tconst clientConfig: SNSClientConfig = {\n\t\t\tregion: config.region,\n\t\t\tendpoint: config.endpoint,\n\t\t\tcredentials: config.credentials,\n\t\t};\n\n\t\tthis.client = new SNSClient(clientConfig);\n\t}\n\n\t/**\n\t * Create an SNSConnection from a connection string\n\t * Format: sns://?topicArn=arn:aws:sns:region:account:topic®ion=us-east-1&endpoint=http://localhost:4566\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<SNSConnection> {\n\t\t// Through the codec, not a second hand-rolled parse: the deploy target\n\t\t// composes these with `snsUrl.build`, and a string it cannot read back is\n\t\t// exactly the drift one shared module rules out.\n\t\tconst { topicArn, region, endpoint } = snsUrl.parse(connectionString);\n\t\tconst params = new URL(connectionString).searchParams;\n\n\t\tconst config: SNSConnectionConfig = {\n\t\t\ttopicArn,\n\t\t\tregion,\n\t\t\tendpoint,\n\t\t};\n\n\t\t// Credentials are not part of the address — see `snsUrl` — but a caller\n\t\t// may still pin them here, so they are read beside it rather than in it.\n\t\tconst accessKeyId = params.get('accessKeyId');\n\t\tconst secretAccessKey = params.get('secretAccessKey');\n\t\tif (accessKeyId && secretAccessKey) {\n\t\t\tconfig.credentials = {\n\t\t\t\taccessKeyId,\n\t\t\t\tsecretAccessKey,\n\t\t\t\tsessionToken: params.get('sessionToken') || undefined,\n\t\t\t};\n\t\t}\n\n\t\tconst connection = new SNSConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\t// SNS doesn't have a traditional connection, but we mark as connected\n\t\tthis.connected = true;\n\t}\n\n\tasync close(): Promise<void> {\n\t\tthis.client.destroy();\n\t\tthis.connected = false;\n\t}\n\n\tisConnected(): boolean {\n\t\treturn this.connected;\n\t}\n\n\t/**\n\t * Get the underlying SNS client\n\t */\n\tget snsClient(): SNSClient {\n\t\treturn this.client;\n\t}\n\n\t/**\n\t * Get the topic ARN for this connection\n\t */\n\tget topicArn(): string {\n\t\treturn this.config.topicArn;\n\t}\n}\n","import { PublishCommand } from '@aws-sdk/client-sns';\nimport { carrierAsAttributes, publishTraced } from '../telemetry';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport type { SNSConnection } from './SNSConnection';\n\nexport type SNSPublisherOptions = {};\n\nexport class SNSPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: SNSConnection,\n\t\t_options: SNSPublisherOptions = {},\n\t) {}\n\n\t/**\n\t * Create an SNSPublisher from a connection string\n\t * Format: sns://?topicArn=arn:aws:sns:region:account:topic®ion=us-east-1&endpoint=http://localhost:4566\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<SNSPublisher<TMessage>> {\n\t\tconst { SNSConnection } = await import('./SNSConnection');\n\t\tconst connection =\n\t\t\tawait SNSConnection.fromConnectionString(connectionString);\n\n\t\treturn new SNSPublisher<TMessage>(connection);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (messages.length === 0) return;\n\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst topicArn = this.connection.topicArn;\n\t\tconst destination = topicArn.split(':').pop() ?? topicArn;\n\t\tawait publishTraced(\n\t\t\tmessages,\n\t\t\t(message) => ({ system: 'aws_sns', destination, type: message.type }),\n\t\t\t(carriers) =>\n\t\t\t\tPromise.all(\n\t\t\t\t\tmessages.map((message, i) =>\n\t\t\t\t\t\tthis.publishMessage(message, carriers[i]),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t);\n\t}\n\n\tprivate async publishMessage(\n\t\tmessage: TMessage,\n\t\tcarrier: Record<string, string> | undefined,\n\t): Promise<void> {\n\t\tconst command = new PublishCommand({\n\t\t\tTopicArn: this.connection.topicArn,\n\t\t\tMessage: JSON.stringify({\n\t\t\t\ttype: message.type,\n\t\t\t\tpayload: message.payload,\n\t\t\t}),\n\t\t\tMessageAttributes: {\n\t\t\t\ttype: {\n\t\t\t\t\tDataType: 'String',\n\t\t\t\t\tStringValue: message.type,\n\t\t\t\t},\n\t\t\t\t// The trace context as message attributes: SNS hands them on to\n\t\t\t\t// an SQS subscription's envelope, an HTTP push and a Lambda record.\n\t\t\t\t...carrierAsAttributes(carrier),\n\t\t\t},\n\t\t});\n\n\t\tawait this.connection.snsClient.send(command);\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t\t// Connection should be closed by whoever created it\n\t}\n}\n","import { SubscribeCommand, UnsubscribeCommand } from '@aws-sdk/client-sns';\nimport {\n\tCreateQueueCommand,\n\tDeleteQueueCommand,\n\tGetQueueAttributesCommand,\n\tSetQueueAttributesCommand,\n\tSQSClient,\n} from '@aws-sdk/client-sqs';\nimport { SQSConnection } from '../sqs/SQSConnection';\nimport { SQSSubscriber } from '../sqs/SQSSubscriber';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport type { SNSConnection } from './SNSConnection';\n\nexport interface SNSSubscriberOptions {\n\tqueueName?: string; // Optional queue name (defaults to auto-generated)\n\tcreateQueue?: boolean; // Auto-create SQS queue (default: true)\n\tdeleteQueueOnClose?: boolean; // Delete queue when subscriber closes (default: false for named queues, true for auto-generated)\n\twaitTimeSeconds?: number; // SQS long polling (default: 20)\n\tmaxMessages?: number; // Max messages per poll (default: 10)\n}\n\n/**\n * SNS Subscriber - receives push-based messages from SNS via SQS queue\n *\n * Architecture:\n * SNS Topic → (push) → SQS Queue → Subscriber\n *\n * This subscriber automatically:\n * 1. Creates an SQS queue (or uses existing one)\n * 2. Subscribes the queue to the SNS topic\n * 3. Receives messages pushed from SNS to the queue\n * 4. Filters messages by topic ARN and message type\n * 5. Processes and acknowledges messages\n *\n * Note: While SQS long-polling is used internally to receive messages,\n * this is an implementation detail of the SNS push delivery mechanism.\n * Messages are pushed from SNS to SQS, and we receive those pushed messages.\n */\nexport class SNSSubscriber<TMessage extends PublishableMessage<string, any>>\n\timplements EventSubscriber<TMessage>\n{\n\tprivate sqsClient: SQSClient;\n\tprivate queueUrl?: string;\n\tprivate queueArn?: string;\n\tprivate subscriptionArn?: string;\n\tprivate sqsSubscriber?: SQSSubscriber<TMessage>;\n\tprivate options: Required<SNSSubscriberOptions>;\n\n\tconstructor(\n\t\tprivate connection: SNSConnection,\n\t\toptions: SNSSubscriberOptions = {},\n\t) {\n\t\tthis.options = {\n\t\t\tqueueName:\n\t\t\t\toptions.queueName ||\n\t\t\t\t`sns-sub-${Date.now()}-${Math.random().toString(36).substring(7)}`,\n\t\t\tcreateQueue: options.createQueue ?? true,\n\t\t\tdeleteQueueOnClose: options.deleteQueueOnClose ?? !options.queueName, // Delete auto-generated queues\n\t\t\twaitTimeSeconds: options.waitTimeSeconds ?? 20,\n\t\t\tmaxMessages: options.maxMessages ?? 10,\n\t\t};\n\n\t\t// Create SQS client with same config as SNS\n\t\tthis.sqsClient = new SQSClient({\n\t\t\tregion: (this.connection as any).config.region,\n\t\t\tendpoint: (this.connection as any).config.endpoint,\n\t\t\tcredentials: (this.connection as any).config.credentials,\n\t\t});\n\t}\n\n\t/**\n\t * Create an SNSSubscriber from a connection string\n\t * Format: sns://?topicArn=...&queueName=myqueue®ion=us-east-1\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<SNSSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { SNSConnection } = await import('./SNSConnection');\n\t\tconst connection =\n\t\t\tawait SNSConnection.fromConnectionString(connectionString);\n\n\t\tconst options: SNSSubscriberOptions = {\n\t\t\tqueueName: params.get('queueName') || undefined,\n\t\t\tcreateQueue: params.get('createQueue') !== 'false',\n\t\t\tdeleteQueueOnClose: params.get('deleteQueueOnClose') === 'true',\n\t\t\twaitTimeSeconds: params.get('waitTimeSeconds')\n\t\t\t\t? Number.parseInt(params.get('waitTimeSeconds')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new SNSSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\t// Setup SQS queue and SNS subscription\n\t\tawait this.setupQueue();\n\t\tawait this.subscribeToTopic();\n\n\t\t// Create SQS connection for the subscriber\n\t\tconst sqsConnection = new SQSConnection({\n\t\t\tqueueUrl: this.queueUrl!,\n\t\t\tregion: (this.connection as any).config.region,\n\t\t\tendpoint: (this.connection as any).config.endpoint,\n\t\t\tcredentials: (this.connection as any).config.credentials,\n\t\t});\n\t\tawait sqsConnection.connect();\n\n\t\t// Use SQSSubscriber to receive messages, with topic filtering\n\t\tthis.sqsSubscriber = new SQSSubscriber<TMessage>(sqsConnection, {\n\t\t\twaitTimeSeconds: this.options.waitTimeSeconds,\n\t\t\tmaxMessages: this.options.maxMessages,\n\t\t\texpectedTopicArn: this.connection.topicArn,\n\t\t});\n\n\t\tawait this.sqsSubscriber.subscribe(messages, listener);\n\t}\n\n\t/**\n\t * Stop receiving messages and clean up resources\n\t */\n\tasync stop(): Promise<void> {\n\t\t// Stop SQS subscriber\n\t\tif (this.sqsSubscriber) {\n\t\t\tthis.sqsSubscriber.stop();\n\t\t}\n\n\t\t// Unsubscribe from topic\n\t\tif (this.subscriptionArn) {\n\t\t\ttry {\n\t\t\t\tconst command = new UnsubscribeCommand({\n\t\t\t\t\tSubscriptionArn: this.subscriptionArn,\n\t\t\t\t});\n\t\t\t\tawait this.connection.snsClient.send(command);\n\t\t\t} catch (_error) {}\n\t\t}\n\n\t\t// Delete queue if configured\n\t\tif (this.queueUrl && this.options.deleteQueueOnClose) {\n\t\t\ttry {\n\t\t\t\tconst command = new DeleteQueueCommand({\n\t\t\t\t\tQueueUrl: this.queueUrl,\n\t\t\t\t});\n\t\t\t\tawait this.sqsClient.send(command);\n\t\t\t} catch (_error) {}\n\t\t}\n\n\t\tthis.sqsClient.destroy();\n\t}\n\n\tprivate async setupQueue(): Promise<void> {\n\t\tif (this.options.createQueue) {\n\t\t\t// Create queue\n\t\t\tconst createCommand = new CreateQueueCommand({\n\t\t\t\tQueueName: this.options.queueName,\n\t\t\t});\n\t\t\tconst response = await this.sqsClient.send(createCommand);\n\t\t\tthis.queueUrl = response.QueueUrl!;\n\t\t} else {\n\t\t\tthrow new SnsQueueMissing(this.options.queueName);\n\t\t}\n\n\t\t// Get queue ARN\n\t\tconst attrsCommand = new GetQueueAttributesCommand({\n\t\t\tQueueUrl: this.queueUrl,\n\t\t\tAttributeNames: ['QueueArn'],\n\t\t});\n\t\tconst attrsResponse = await this.sqsClient.send(attrsCommand);\n\t\tthis.queueArn = attrsResponse.Attributes?.QueueArn!;\n\n\t\t// Set queue policy to allow SNS\n\t\tawait this.setQueuePolicy();\n\t}\n\n\tprivate async setQueuePolicy(): Promise<void> {\n\t\tconst policy = {\n\t\t\tVersion: '2012-10-17',\n\t\t\tStatement: [\n\t\t\t\t{\n\t\t\t\t\tEffect: 'Allow',\n\t\t\t\t\tPrincipal: '*',\n\t\t\t\t\tAction: 'SQS:SendMessage',\n\t\t\t\t\tResource: this.queueArn,\n\t\t\t\t\tCondition: {\n\t\t\t\t\t\tArnEquals: {\n\t\t\t\t\t\t\t'aws:SourceArn': this.connection.topicArn,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\n\t\tconst command = new SetQueueAttributesCommand({\n\t\t\tQueueUrl: this.queueUrl,\n\t\t\tAttributes: {\n\t\t\t\tPolicy: JSON.stringify(policy),\n\t\t\t},\n\t\t});\n\n\t\tawait this.sqsClient.send(command);\n\t}\n\n\tprivate async subscribeToTopic(): Promise<void> {\n\t\tconst command = new SubscribeCommand({\n\t\t\tTopicArn: this.connection.topicArn,\n\t\t\tProtocol: 'sqs',\n\t\t\tEndpoint: this.queueArn,\n\t\t});\n\n\t\tconst response = await this.connection.snsClient.send(command);\n\t\tthis.subscriptionArn = response.SubscriptionArn!;\n\t}\n}\n\n/**\n * A subscriber asked to use a queue it may not create. The SQS queue behind an\n * SNS subscription has to exist first, or `createQueue` has to allow it.\n */\nexport class SnsQueueMissing extends Error {\n\tconstructor(readonly queueName: string | undefined) {\n\t\tsuper(\n\t\t\t`The SNS subscriber's queue${queueName ? ` \"${queueName}\"` : ''} is not created here: pass createQueue: true, or create the queue first.`,\n\t\t);\n\t\tthis.name = 'SnsQueueMissing';\n\t}\n}\n","import type { EventsDriver } from '../registry';\nimport { EventPublisherType } from '../types';\nimport { SNSConnection } from './SNSConnection';\nimport { SNSPublisher } from './SNSPublisher';\nimport { SNSSubscriber } from './SNSSubscriber';\n\n/**\n * `sns://` — an SNS topic, consumed through an SQS queue subscribed to it.\n * Register it with `registerEventsDriver(snsEventsDriver)`; an AWS entry\n * registers `sqsEventsDriver` beside it.\n */\nexport const snsEventsDriver: EventsDriver = {\n\tscheme: EventPublisherType.SNS,\n\tconnect: (url) => SNSConnection.fromConnectionString(url),\n\tpublisher: (url) => SNSPublisher.fromConnectionString(url),\n\tpublisherFor: (connection) => new SNSPublisher(connection as SNSConnection),\n\tsubscriber: (url) => SNSSubscriber.fromConnectionString(url),\n\tsubscriberFor: (connection) => new SNSSubscriber(connection as SNSConnection),\n};\n","import {\n\tConfirmSubscriptionCommand,\n\tGetSubscriptionAttributesCommand,\n\tListSubscriptionsByTopicCommand,\n\tSetSubscriptionAttributesCommand,\n\tSubscribeCommand,\n\ttype SubscribeCommandInput,\n\tUnsubscribeCommand,\n} from '@aws-sdk/client-sns';\nimport { parseUrl, type SnsHttpMessage, SnsNotAConfirmation } from './message';\nimport type { SNSConnection } from './SNSConnection';\n\n/**\n * Subscribing an HTTP(S) endpoint to a topic, which takes the SNS API and so\n * the AWS SDK. Receiving what SNS then pushes takes neither: that is\n * `./message`, the `@geekmidas/events/sns/message` entry.\n */\n\n/** Where a subscription's filter policy is matched. */\nexport type SnsFilterPolicyScope = 'MessageAttributes' | 'MessageBody';\n\n/** What an HTTP subscription is created or brought up to date with. */\nexport interface HttpSubscriptionFilter {\n\t/**\n\t * The event types this endpoint takes. Becomes the subscription's filter\n\t * policy on the `type` attribute `SNSPublisher` sets, so SNS sends nothing\n\t * else — fan-out to every subscriber, each seeing only what it named.\n\t *\n\t * Absent, with no {@link filterPolicy} either, for a topic whose\n\t * publisher sets no `type` — a bucket's — whose subscriber filters what it\n\t * is sent.\n\t *\n\t * Ignored when {@link filterPolicy} is given.\n\t */\n\tevents?: readonly string[];\n\t/**\n\t * A filter policy of the caller's own, for messages SNS did not receive\n\t * from `SNSPublisher` — a bucket's notifications carry no `type` attribute,\n\t * so they are matched on their body instead.\n\t */\n\tfilterPolicy?: Record<string, unknown>;\n\t/** Where {@link filterPolicy} is matched. `MessageAttributes` by default. */\n\tfilterPolicyScope?: SnsFilterPolicyScope;\n\t/**\n\t * An SQS queue's ARN for what SNS gives up delivering. SNS retries an HTTP\n\t * endpoint for a limited time and then drops the message, so without one an\n\t * outage longer than that loses events.\n\t */\n\tdeadLetterQueueArn?: string;\n}\n\nexport interface SubscribeHttpEndpointOptions extends HttpSubscriptionFilter {\n\t/** The URL SNS POSTs to — `http:` or `https:`, which picks the protocol. */\n\tendpoint: string;\n}\n\n/** The subscription attributes a filter asks for, as SNS spells them. */\nfunction subscriptionAttributes(\n\tfilter: HttpSubscriptionFilter,\n): Record<string, string> {\n\tconst attributes: Record<string, string> = filter.filterPolicy\n\t\t? {\n\t\t\t\tFilterPolicyScope: filter.filterPolicyScope ?? 'MessageAttributes',\n\t\t\t\tFilterPolicy: JSON.stringify(filter.filterPolicy),\n\t\t\t}\n\t\t: filter.events\n\t\t\t? {\n\t\t\t\t\tFilterPolicyScope: 'MessageAttributes',\n\t\t\t\t\tFilterPolicy: JSON.stringify({ type: [...filter.events] }),\n\t\t\t\t}\n\t\t\t: {};\n\tif (filter.deadLetterQueueArn) {\n\t\tattributes.RedrivePolicy = JSON.stringify({\n\t\t\tdeadLetterTargetArn: filter.deadLetterQueueArn,\n\t\t});\n\t}\n\treturn attributes;\n}\n\n/** The protocol SNS delivers to an endpoint with, from its URL. */\nfunction protocolOf(endpoint: string): 'http' | 'https' {\n\tconst protocol = parseUrl(endpoint)?.protocol.replace(':', '');\n\tif (protocol !== 'http' && protocol !== 'https') {\n\t\tthrow new SnsEndpointNotHttp(endpoint);\n\t}\n\treturn protocol;\n}\n\n/** Bring an existing subscription's attributes up to what is asked for. */\nasync function updateAttributes(\n\tconnection: SNSConnection,\n\tsubscriptionArn: string,\n\tcurrent: Record<string, string>,\n\twanted: Record<string, string>,\n): Promise<void> {\n\tfor (const [name, value] of Object.entries(wanted)) {\n\t\tif (current[name] === value) continue;\n\t\tawait connection.snsClient.send(\n\t\t\tnew SetSubscriptionAttributesCommand({\n\t\t\t\tSubscriptionArn: subscriptionArn,\n\t\t\t\tAttributeName: name,\n\t\t\t\tAttributeValue: value,\n\t\t\t}),\n\t\t);\n\t}\n}\n\n/**\n * Subscribe an HTTP endpoint to the connection's topic, converging on one\n * confirmed subscription with the filter asked for — so it is safe on every\n * start. What a server does against an emulator, where nothing deploys it;\n * against SNS itself the deploy owns the subscription\n * ({@link reconcileHttpSubscriptions}).\n *\n * - **none yet** — subscribed; SNS sends a confirmation to the endpoint.\n * - **confirmed** — its filter and dead-letter queue are brought up to date.\n * Subscribing again with different attributes is an error on SNS, and the\n * events a subscriber names change.\n * - **stuck pending** — a confirmation that never landed (the endpoint was\n * down, or answered wrong). Subscribing the same endpoint again is a no-op\n * on an emulator, so it is dropped and subscribed afresh, which sends a new\n * confirmation.\n */\nexport async function subscribeHttpEndpoint(\n\tconnection: SNSConnection,\n\toptions: SubscribeHttpEndpointOptions,\n): Promise<string | undefined> {\n\tconst protocol = protocolOf(options.endpoint);\n\tconst attributes = subscriptionAttributes(options);\n\n\tconst client = connection.snsClient;\n\tconst existing = (await topicSubscriptions(connection)).find(\n\t\t(s) => s.endpoint === options.endpoint,\n\t)?.arn;\n\tif (existing) {\n\t\tconst { Attributes = {} } = await client.send(\n\t\t\tnew GetSubscriptionAttributesCommand({ SubscriptionArn: existing }),\n\t\t);\n\t\tif (Attributes.PendingConfirmation === 'true') {\n\t\t\tawait client.send(new UnsubscribeCommand({ SubscriptionArn: existing }));\n\t\t} else {\n\t\t\tawait updateAttributes(connection, existing, Attributes, attributes);\n\t\t\treturn existing;\n\t\t}\n\t}\n\n\tconst { SubscriptionArn } = await client.send(\n\t\tnew SubscribeCommand({\n\t\t\tTopicArn: connection.topicArn,\n\t\t\tProtocol: protocol,\n\t\t\tEndpoint: options.endpoint,\n\t\t\tAttributes: attributes as SubscribeCommandInput['Attributes'],\n\t\t\tReturnSubscriptionArn: true,\n\t\t}),\n\t);\n\treturn SubscriptionArn;\n}\n\n/** One endpoint the deploy wants subscribed, under the name it is recorded by. */\nexport interface HttpSubscriptionSpec extends HttpSubscriptionFilter {\n\t/** What the ARN is recorded under — the subscriber's export. */\n\tname: string;\n\t/** The URL SNS POSTs to. */\n\tendpoint: string;\n}\n\nexport interface ReconcileHttpSubscriptionsOptions {\n\t/** Every endpoint that should be subscribed to the topic. */\n\tendpoints: readonly HttpSubscriptionSpec[];\n\t/**\n\t * The host these endpoints answer on. A subscription to an endpoint on it\n\t * that is not in {@link endpoints} — a subscriber renamed or removed — is\n\t * unsubscribed; anything subscribed on another host is somebody else's and\n\t * left alone.\n\t */\n\townedHost: string;\n}\n\nexport interface ReconciledHttpSubscriptions {\n\t/** Each endpoint's subscription ARN, by its name — stable across runs. */\n\tsubscriptions: Record<string, string>;\n\t/** The names whose subscription SNS still waits to have confirmed. */\n\tpending: string[];\n\t/** The ARNs of what was unsubscribed as no longer wanted. */\n\tremoved: string[];\n}\n\n/**\n * Converge a topic's HTTP subscriptions on the endpoints a deploy wants, and\n * answer each one's ARN for the deploy to record and hand to the server.\n *\n * The deploy's half of push delivery against SNS itself: the server never\n * subscribes, so its credentials need no `sns:Subscribe` — and the only\n * subscriptions to the topic are ones the deploy made.\n *\n * Run it twice: once before the server starts, for the ARNs it is configured\n * with — SNS answers one even while the subscription waits to be confirmed —\n * and once the server is up, which subscribes each still-pending endpoint\n * again so SNS resends its confirmation to a server now there to answer it.\n * The ARN does not change between the two.\n *\n * - **absent** — subscribed with its filter.\n * - **present** — its filter and dead-letter queue are brought up to date;\n * pending, it is subscribed again to resend the confirmation.\n * - **stale** — on {@link ReconcileHttpSubscriptionsOptions.ownedHost} and no\n * longer wanted: unsubscribed. (A stale one SNS still lists as pending has\n * no ARN to act on; SNS drops it unconfirmed after three days.)\n */\nexport async function reconcileHttpSubscriptions(\n\tconnection: SNSConnection,\n\toptions: ReconcileHttpSubscriptionsOptions,\n): Promise<ReconciledHttpSubscriptions> {\n\tconst client = connection.snsClient;\n\tconst listed = await topicSubscriptions(connection);\n\tconst result: ReconciledHttpSubscriptions = {\n\t\tsubscriptions: {},\n\t\tpending: [],\n\t\tremoved: [],\n\t};\n\n\tfor (const spec of options.endpoints) {\n\t\tconst protocol = protocolOf(spec.endpoint);\n\t\tconst attributes = subscriptionAttributes(spec);\n\t\tconst subscribe = async () =>\n\t\t\t(\n\t\t\t\tawait client.send(\n\t\t\t\t\tnew SubscribeCommand({\n\t\t\t\t\t\tTopicArn: connection.topicArn,\n\t\t\t\t\t\tProtocol: protocol,\n\t\t\t\t\t\tEndpoint: spec.endpoint,\n\t\t\t\t\t\tAttributes: attributes as SubscribeCommandInput['Attributes'],\n\t\t\t\t\t\tReturnSubscriptionArn: true,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t).SubscriptionArn;\n\n\t\tconst existing = listed.find((s) => s.endpoint === spec.endpoint)?.arn;\n\t\tlet arn: string | undefined;\n\t\tlet pending: boolean;\n\t\tif (existing) {\n\t\t\tconst { Attributes = {} } = await client.send(\n\t\t\t\tnew GetSubscriptionAttributesCommand({ SubscriptionArn: existing }),\n\t\t\t);\n\t\t\tawait updateAttributes(connection, existing, Attributes, attributes);\n\t\t\tpending = Attributes.PendingConfirmation === 'true';\n\t\t\t// Subscribing a pending endpoint again resends its confirmation,\n\t\t\t// under the same ARN.\n\t\t\tarn = pending ? ((await subscribe()) ?? existing) : existing;\n\t\t} else {\n\t\t\t// Absent — or pending on SNS itself, which lists it with no ARN:\n\t\t\t// subscribing answers the one it has, and resends the confirmation.\n\t\t\tarn = await subscribe();\n\t\t\tpending = true;\n\t\t}\n\t\tif (!arn) {\n\t\t\tthrow new SnsSubscriptionArnMissing(connection.topicArn, spec.endpoint);\n\t\t}\n\n\t\tresult.subscriptions[spec.name] = arn;\n\t\tif (pending) result.pending.push(spec.name);\n\t}\n\n\tconst wanted = new Set(options.endpoints.map((spec) => spec.endpoint));\n\tfor (const { arn, endpoint } of listed) {\n\t\tif (!arn || wanted.has(endpoint)) continue;\n\t\tif (parseUrl(endpoint)?.host !== options.ownedHost) continue;\n\t\tawait client.send(new UnsubscribeCommand({ SubscriptionArn: arn }));\n\t\tresult.removed.push(arn);\n\t}\n\n\treturn result;\n}\n\n/**\n * Confirm a subscription through the API, as its topic's owner, rather than by\n * visiting the URL SNS sent.\n *\n * `AuthenticateOnUnsubscribe` is the point of it. A subscription confirmed by\n * visiting `SubscribeURL` can be removed by anyone holding the\n * `UnsubscribeURL` every notification carries — one unauthenticated GET, and\n * the endpoint is silently cut off. Confirmed this way, only the topic's owner\n * can unsubscribe it. All it takes of the caller's credentials is\n * `sns:ConfirmSubscription` on this one topic.\n */\nexport async function confirmSubscription(\n\tconnection: SNSConnection,\n\tmessage: SnsHttpMessage,\n): Promise<string | undefined> {\n\tif (message.Type !== 'SubscriptionConfirmation' || !message.Token) {\n\t\tthrow new SnsNotAConfirmation(message.Type);\n\t}\n\n\tconst { SubscriptionArn } = await connection.snsClient.send(\n\t\tnew ConfirmSubscriptionCommand({\n\t\t\tTopicArn: message.TopicArn,\n\t\t\tToken: message.Token,\n\t\t\tAuthenticateOnUnsubscribe: 'true',\n\t\t}),\n\t);\n\treturn SubscriptionArn;\n}\n\n/**\n * Every subscription on the connection's topic, with the ARN SNS names for it\n * — none for one real SNS lists as `PendingConfirmation`, which there is no\n * ARN to act on (and which a new Subscribe resends the confirmation of anyway).\n */\nasync function topicSubscriptions(\n\tconnection: SNSConnection,\n): Promise<{ arn?: string; endpoint: string }[]> {\n\tconst found: { arn?: string; endpoint: string }[] = [];\n\tlet NextToken: string | undefined;\n\tdo {\n\t\tconst page = await connection.snsClient.send(\n\t\t\tnew ListSubscriptionsByTopicCommand({\n\t\t\t\tTopicArn: connection.topicArn,\n\t\t\t\tNextToken,\n\t\t\t}),\n\t\t);\n\t\tfor (const s of page.Subscriptions ?? []) {\n\t\t\tif (!s.Endpoint) continue;\n\t\t\tfound.push({\n\t\t\t\tendpoint: s.Endpoint,\n\t\t\t\t...(s.SubscriptionArn?.startsWith('arn:')\n\t\t\t\t\t? { arn: s.SubscriptionArn }\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\t}\n\t\tNextToken = page.NextToken;\n\t} while (NextToken);\n\treturn found;\n}\n\nexport class SnsEndpointNotHttp extends Error {\n\tconstructor(readonly endpoint: string) {\n\t\tsuper(\n\t\t\t`'${endpoint}' is not an http(s) URL. SNS pushes to an HTTP endpoint; ` +\n\t\t\t\t'subscribe a queue for anything else.',\n\t\t);\n\t\tthis.name = 'SnsEndpointNotHttp';\n\t}\n}\n\nexport class SnsSubscriptionArnMissing extends Error {\n\tconstructor(\n\t\treadonly topicArn: string,\n\t\treadonly endpoint: string,\n\t) {\n\t\tsuper(\n\t\t\t`Subscribing '${endpoint}' to '${topicArn}' answered no subscription ` +\n\t\t\t\t'ARN, so there is nothing to record for the server to accept. ' +\n\t\t\t\t'Check the topic exists and the deploy may subscribe to it.',\n\t\t);\n\t\tthis.name = 'SnsSubscriptionArnMissing';\n\t}\n}\n"],"mappings":";;;;;;;;;;AAgBA,IAAa,gBAAb,MAAa,cAAyC;CACrD,OAAS;CACT;CACA,YAAoB;CACpB;CAEA,YAAY,QAA6B;EACxC,KAAK,SAAS;EAEd,MAAM,eAAgC;GACrC,QAAQ,OAAO;GACf,UAAU,OAAO;GACjB,aAAa,OAAO;EACrB;EAEA,KAAK,SAAS,IAAIA,oBAAAA,UAAU,YAAY;CACzC;;;;;CAMA,aAAa,qBACZ,kBACyB;EAIzB,MAAM,EAAE,UAAU,QAAQ,aAAA,mBAAA,MAA0B,gBAAgB;EACpE,MAAM,SAAS,IAAI,IAAI,gBAAgB,CAAC,CAAC;EAEzC,MAAM,SAA8B;GACnC;GACA;GACA;EACD;EAIA,MAAM,cAAc,OAAO,IAAI,aAAa;EAC5C,MAAM,kBAAkB,OAAO,IAAI,iBAAiB;EACpD,IAAI,eAAe,iBAClB,OAAO,cAAc;GACpB;GACA;GACA,cAAc,OAAO,IAAI,cAAc,KAAK,KAAA;EAC7C;EAGD,MAAM,aAAa,IAAI,cAAc,MAAM;EAC3C,MAAM,WAAW,QAAQ;EACzB,OAAO;CACR;CAEA,MAAM,UAAyB;EAE9B,KAAK,YAAY;CAClB;CAEA,MAAM,QAAuB;EAC5B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AACD"}
|
package/dist/sns/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { d as EventPublisher, f as EventPublisherType, g as PublishableMessage, p as EventSubscriber, t as EventsDriver, u as EventConnection } from "../registry-DIx25Q5s.cjs";
|
|
2
|
+
import { SnsCertificateUnavailable, SnsCertificateUntrusted, SnsConfirmationFailed, SnsHttpMessage, SnsMessageTypeUnknown, SnsNotAConfirmation, SnsSignatureInvalid, SnsSignatureVersionUnknown, VerifySnsMessageOptions, confirmSnsSubscription, snsStringToSign, toSnsEvent, verifySnsMessage } from "./message.cjs";
|
|
2
3
|
import { SnsAddress, t as snsUrl_d_exports } from "./snsUrl.cjs";
|
|
3
4
|
import { SNSClient, SNSClientConfig } from "@aws-sdk/client-sns";
|
|
4
5
|
//#region src/sns/driver.d.ts
|
|
@@ -46,63 +47,10 @@ export declare class SNSConnection implements EventConnection {
|
|
|
46
47
|
//#endregion
|
|
47
48
|
//#region src/sns/push.d.ts
|
|
48
49
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* transport: no queue in between, no poller, and the endpoint is handed the
|
|
53
|
-
* same envelope a Lambda subscription receives inside `Records[].Sns` — so the
|
|
54
|
-
* handler that runs deployed can be the one that runs here.
|
|
55
|
-
*
|
|
56
|
-
* The endpoint is public, so a message is trusted only once its signature
|
|
57
|
-
* checks out against a certificate SNS itself serves. Anything else that POSTs
|
|
58
|
-
* there is somebody's guess at the shape.
|
|
59
|
-
*/
|
|
60
|
-
/** A message SNS POSTs to a subscribed HTTP endpoint. */
|
|
61
|
-
interface SnsHttpMessage {
|
|
62
|
-
Type: 'Notification' | 'SubscriptionConfirmation' | 'UnsubscribeConfirmation';
|
|
63
|
-
MessageId: string;
|
|
64
|
-
TopicArn: string;
|
|
65
|
-
Message: string;
|
|
66
|
-
Timestamp: string;
|
|
67
|
-
SignatureVersion: string;
|
|
68
|
-
Signature: string;
|
|
69
|
-
SigningCertURL: string;
|
|
70
|
-
Subject?: string;
|
|
71
|
-
/** Confirmation messages only. */
|
|
72
|
-
Token?: string;
|
|
73
|
-
/** Confirmation messages only: GET it to confirm. */
|
|
74
|
-
SubscribeURL?: string;
|
|
75
|
-
/** Notifications only. */
|
|
76
|
-
UnsubscribeURL?: string;
|
|
77
|
-
MessageAttributes?: Record<string, {
|
|
78
|
-
Type: string;
|
|
79
|
-
Value: string;
|
|
80
|
-
}>;
|
|
81
|
-
}
|
|
82
|
-
interface VerifySnsMessageOptions {
|
|
83
|
-
/**
|
|
84
|
-
* Fetch the PEM at a certificate URL. `fetch` by default; replaceable so a
|
|
85
|
-
* test signs with its own key instead of SNS's.
|
|
86
|
-
*/
|
|
87
|
-
fetchCertificate?: (url: string) => Promise<string>;
|
|
88
|
-
}
|
|
89
|
-
/** The string SNS signed for this message. */
|
|
90
|
-
export declare function snsStringToSign(message: SnsHttpMessage): string;
|
|
91
|
-
/**
|
|
92
|
-
* Check that SNS sent this message: the certificate is SNS's own, and the
|
|
93
|
-
* signature over the message's signed fields verifies against it.
|
|
94
|
-
*
|
|
95
|
-
* Throws rather than returning false, so a caller cannot forget to look.
|
|
96
|
-
*/
|
|
97
|
-
export declare function verifySnsMessage(message: SnsHttpMessage, options?: VerifySnsMessageOptions): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Confirm a subscription by visiting the URL SNS sent. Until this happens SNS
|
|
100
|
-
* delivers nothing to the endpoint.
|
|
50
|
+
* Subscribing an HTTP(S) endpoint to a topic, which takes the SNS API and so
|
|
51
|
+
* the AWS SDK. Receiving what SNS then pushes takes neither: that is
|
|
52
|
+
* `./message`, the `@geekmidas/events/sns/message` entry.
|
|
101
53
|
*/
|
|
102
|
-
export declare function confirmSnsSubscription(message: SnsHttpMessage, request?: (url: string) => Promise<{
|
|
103
|
-
ok: boolean;
|
|
104
|
-
status: number;
|
|
105
|
-
}>): Promise<void>;
|
|
106
54
|
/** Where a subscription's filter policy is matched. */
|
|
107
55
|
type SnsFilterPolicyScope = 'MessageAttributes' | 'MessageBody';
|
|
108
56
|
/** What an HTTP subscription is created or brought up to date with. */
|
|
@@ -215,64 +163,6 @@ export declare function reconcileHttpSubscriptions(connection: SNSConnection, op
|
|
|
215
163
|
* `sns:ConfirmSubscription` on this one topic.
|
|
216
164
|
*/
|
|
217
165
|
export declare function confirmSubscription(connection: SNSConnection, message: SnsHttpMessage): Promise<string | undefined>;
|
|
218
|
-
/**
|
|
219
|
-
* A pushed notification as the Lambda event SNS would have invoked a function
|
|
220
|
-
* with, so it can be handed to the same adaptor.
|
|
221
|
-
*/
|
|
222
|
-
export declare function toSnsEvent(message: SnsHttpMessage, subscriptionArn?: string): {
|
|
223
|
-
Records: {
|
|
224
|
-
EventSource: string;
|
|
225
|
-
EventVersion: string;
|
|
226
|
-
EventSubscriptionArn: string;
|
|
227
|
-
Sns: {
|
|
228
|
-
Type: "Notification" | "SubscriptionConfirmation" | "UnsubscribeConfirmation";
|
|
229
|
-
MessageId: string;
|
|
230
|
-
TopicArn: string;
|
|
231
|
-
Subject: string | null;
|
|
232
|
-
Message: string;
|
|
233
|
-
Timestamp: string;
|
|
234
|
-
SignatureVersion: string;
|
|
235
|
-
Signature: string;
|
|
236
|
-
SigningCertUrl: string;
|
|
237
|
-
UnsubscribeUrl: string;
|
|
238
|
-
MessageAttributes: Record<string, {
|
|
239
|
-
Type: string;
|
|
240
|
-
Value: string;
|
|
241
|
-
}>;
|
|
242
|
-
};
|
|
243
|
-
}[];
|
|
244
|
-
};
|
|
245
|
-
export declare class SnsCertificateUntrusted extends Error {
|
|
246
|
-
readonly url: string;
|
|
247
|
-
constructor(url: string);
|
|
248
|
-
}
|
|
249
|
-
export declare class SnsCertificateUnavailable extends Error {
|
|
250
|
-
readonly url: string;
|
|
251
|
-
readonly status: number;
|
|
252
|
-
constructor(url: string, status: number);
|
|
253
|
-
}
|
|
254
|
-
export declare class SnsSignatureVersionUnknown extends Error {
|
|
255
|
-
readonly version: string;
|
|
256
|
-
constructor(version: string);
|
|
257
|
-
}
|
|
258
|
-
export declare class SnsSignatureInvalid extends Error {
|
|
259
|
-
readonly messageId: string;
|
|
260
|
-
readonly topicArn: string;
|
|
261
|
-
constructor(messageId: string, topicArn: string);
|
|
262
|
-
}
|
|
263
|
-
export declare class SnsMessageTypeUnknown extends Error {
|
|
264
|
-
readonly type: string;
|
|
265
|
-
constructor(type: string);
|
|
266
|
-
}
|
|
267
|
-
export declare class SnsNotAConfirmation extends Error {
|
|
268
|
-
readonly type: string;
|
|
269
|
-
constructor(type: string);
|
|
270
|
-
}
|
|
271
|
-
export declare class SnsConfirmationFailed extends Error {
|
|
272
|
-
readonly topicArn: string;
|
|
273
|
-
readonly status: number;
|
|
274
|
-
constructor(topicArn: string, status: number);
|
|
275
|
-
}
|
|
276
166
|
export declare class SnsEndpointNotHttp extends Error {
|
|
277
167
|
readonly endpoint: string;
|
|
278
168
|
constructor(endpoint: string);
|
|
@@ -355,5 +245,5 @@ export declare class SnsQueueMissing extends Error {
|
|
|
355
245
|
constructor(queueName: string | undefined);
|
|
356
246
|
}
|
|
357
247
|
//#endregion
|
|
358
|
-
export { type HttpSubscriptionFilter, type HttpSubscriptionSpec, type ReconcileHttpSubscriptionsOptions, type ReconciledHttpSubscriptions, type SNSConnectionConfig, type SNSPublisherOptions, type SNSSubscriberOptions, type SnsAddress, type SnsFilterPolicyScope, type SnsHttpMessage, type SubscribeHttpEndpointOptions, type VerifySnsMessageOptions, snsUrl_d_exports as snsUrl };
|
|
248
|
+
export { type HttpSubscriptionFilter, type HttpSubscriptionSpec, type ReconcileHttpSubscriptionsOptions, type ReconciledHttpSubscriptions, type SNSConnectionConfig, type SNSPublisherOptions, type SNSSubscriberOptions, type SnsAddress, SnsCertificateUnavailable, SnsCertificateUntrusted, SnsConfirmationFailed, type SnsFilterPolicyScope, type SnsHttpMessage, SnsMessageTypeUnknown, SnsNotAConfirmation, SnsSignatureInvalid, SnsSignatureVersionUnknown, type SubscribeHttpEndpointOptions, type VerifySnsMessageOptions, confirmSnsSubscription, snsStringToSign, snsUrl_d_exports as snsUrl, toSnsEvent, verifySnsMessage };
|
|
359
249
|
//# sourceMappingURL=index.d.cts.map
|