@geekmidas/events 10.0.0-alpha.16 → 10.0.0-alpha.161
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 +65 -1
- package/dist/{SQSSubscriber-BXLE_1L3.mjs → SQSSubscriber-BEJBfNTe.mjs} +94 -10
- package/dist/SQSSubscriber-BEJBfNTe.mjs.map +1 -0
- package/dist/{SQSSubscriber-DtRUaZB3.cjs → SQSSubscriber-COTqWvOk.cjs} +101 -10
- package/dist/SQSSubscriber-COTqWvOk.cjs.map +1 -0
- package/dist/basic/index.cjs +35 -4
- package/dist/basic/index.cjs.map +1 -1
- package/dist/basic/index.d.cts +8 -1
- package/dist/basic/index.d.cts.map +1 -1
- package/dist/basic/index.d.mts +8 -1
- package/dist/basic/index.d.mts.map +1 -1
- package/dist/basic/index.mjs +35 -5
- package/dist/basic/index.mjs.map +1 -1
- package/dist/index.cjs +45 -142
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -20
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +80 -20
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +33 -141
- package/dist/index.mjs.map +1 -1
- package/dist/pgboss/index.cjs +121 -34
- package/dist/pgboss/index.cjs.map +1 -1
- package/dist/pgboss/index.d.cts +45 -4
- package/dist/pgboss/index.d.cts.map +1 -1
- package/dist/pgboss/index.d.mts +45 -4
- package/dist/pgboss/index.d.mts.map +1 -1
- package/dist/pgboss/index.mjs +119 -34
- package/dist/pgboss/index.mjs.map +1 -1
- package/dist/rabbitmq/index.cjs +60 -27
- package/dist/rabbitmq/index.cjs.map +1 -1
- package/dist/rabbitmq/index.d.cts +9 -1
- package/dist/rabbitmq/index.d.cts.map +1 -1
- package/dist/rabbitmq/index.d.mts +9 -1
- package/dist/rabbitmq/index.d.mts.map +1 -1
- package/dist/rabbitmq/index.mjs +61 -27
- package/dist/rabbitmq/index.mjs.map +1 -1
- package/dist/{types-gGaoT8qc.d.cts → registry-DIx25Q5s.d.cts} +108 -2
- package/dist/registry-DIx25Q5s.d.cts.map +1 -0
- package/dist/{types-gGaoT8qc.d.mts → registry-DIx25Q5s.d.mts} +108 -2
- package/dist/registry-DIx25Q5s.d.mts.map +1 -0
- package/dist/registry-DXLY1Xf6.mjs +99 -0
- package/dist/registry-DXLY1Xf6.mjs.map +1 -0
- package/dist/registry-DlT36229.cjs +122 -0
- package/dist/registry-DlT36229.cjs.map +1 -0
- package/dist/sns/index.cjs +249 -11
- package/dist/sns/index.cjs.map +1 -1
- package/dist/sns/index.d.cts +145 -8
- package/dist/sns/index.d.cts.map +1 -1
- package/dist/sns/index.d.mts +145 -8
- package/dist/sns/index.d.mts.map +1 -1
- package/dist/sns/index.mjs +234 -12
- 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/dist/sqs/index.cjs +22 -66
- package/dist/sqs/index.cjs.map +1 -1
- package/dist/sqs/index.d.cts +10 -1
- package/dist/sqs/index.d.cts.map +1 -1
- package/dist/sqs/index.d.mts +10 -1
- package/dist/sqs/index.d.mts.map +1 -1
- package/dist/sqs/index.mjs +20 -63
- package/dist/sqs/index.mjs.map +1 -1
- package/dist/telemetry-DG3l807O.cjs +309 -0
- package/dist/telemetry-DG3l807O.cjs.map +1 -0
- package/dist/telemetry-DjjgJMul.mjs +244 -0
- package/dist/telemetry-DjjgJMul.mjs.map +1 -0
- package/package.json +18 -3
- package/dist/PgBossConnection-CywKoAZU.cjs +0 -2
- package/dist/PgBossConnection-DjoqT84r.mjs +0 -2
- package/dist/RabbitMQConnection-C9eccBL8.cjs +0 -2
- package/dist/RabbitMQConnection-CAp7VqyT.mjs +0 -2
- package/dist/SNSConnection-BWDC1wAF.cjs +0 -2
- package/dist/SNSConnection-ezQvVrDv.mjs +0 -2
- package/dist/SQSSubscriber-BXLE_1L3.mjs.map +0 -1
- package/dist/SQSSubscriber-DtRUaZB3.cjs.map +0 -1
- package/dist/types-BcZjLxVV.cjs +0 -51
- package/dist/types-BcZjLxVV.cjs.map +0 -1
- package/dist/types-Bk5JM6MP.mjs +0 -40
- package/dist/types-Bk5JM6MP.mjs.map +0 -1
- package/dist/types-gGaoT8qc.d.cts.map +0 -1
- package/dist/types-gGaoT8qc.d.mts.map +0 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { createVerify } from "node:crypto";
|
|
2
|
+
//#region src/sns/message.ts
|
|
3
|
+
/** The fields signed, in the order SNS signs them, per message type. */
|
|
4
|
+
const SIGNED_FIELDS = {
|
|
5
|
+
Notification: [
|
|
6
|
+
"Message",
|
|
7
|
+
"MessageId",
|
|
8
|
+
"Subject",
|
|
9
|
+
"Timestamp",
|
|
10
|
+
"TopicArn",
|
|
11
|
+
"Type"
|
|
12
|
+
],
|
|
13
|
+
SubscriptionConfirmation: [
|
|
14
|
+
"Message",
|
|
15
|
+
"MessageId",
|
|
16
|
+
"SubscribeURL",
|
|
17
|
+
"Timestamp",
|
|
18
|
+
"Token",
|
|
19
|
+
"TopicArn",
|
|
20
|
+
"Type"
|
|
21
|
+
],
|
|
22
|
+
UnsubscribeConfirmation: [
|
|
23
|
+
"Message",
|
|
24
|
+
"MessageId",
|
|
25
|
+
"SubscribeURL",
|
|
26
|
+
"Timestamp",
|
|
27
|
+
"Token",
|
|
28
|
+
"TopicArn",
|
|
29
|
+
"Type"
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Where SNS serves its signing certificates. Anywhere else is a certificate
|
|
34
|
+
* the sender chose, which would let the sender sign its own forgeries.
|
|
35
|
+
*/
|
|
36
|
+
const SNS_CERTIFICATE_HOST = /^sns\.[a-z0-9-]+\.amazonaws\.com(\.cn)?$/;
|
|
37
|
+
const certificates = /* @__PURE__ */ new Map();
|
|
38
|
+
async function defaultFetchCertificate(url) {
|
|
39
|
+
const response = await fetch(url);
|
|
40
|
+
if (!response.ok) throw new SnsCertificateUnavailable(url, response.status);
|
|
41
|
+
return response.text();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A URL, or undefined for a value that is not one at all — what an emulator
|
|
45
|
+
* sends — so it is untrusted rather than a crash. (`URL.parse` is Node 22.1+.)
|
|
46
|
+
*/
|
|
47
|
+
function parseUrl(value) {
|
|
48
|
+
try {
|
|
49
|
+
return new URL(String(value));
|
|
50
|
+
} catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** The string SNS signed for this message. */
|
|
55
|
+
function snsStringToSign(message) {
|
|
56
|
+
const fields = SIGNED_FIELDS[message.Type];
|
|
57
|
+
if (!fields) throw new SnsMessageTypeUnknown(String(message.Type));
|
|
58
|
+
return fields.filter((field) => message[field] !== void 0).map((field) => `${field}\n${message[field]}\n`).join("");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check that SNS sent this message: the certificate is SNS's own, and the
|
|
62
|
+
* signature over the message's signed fields verifies against it.
|
|
63
|
+
*
|
|
64
|
+
* Throws rather than returning false, so a caller cannot forget to look.
|
|
65
|
+
*/
|
|
66
|
+
async function verifySnsMessage(message, options = {}) {
|
|
67
|
+
const url = parseUrl(message.SigningCertURL);
|
|
68
|
+
if (url?.protocol !== "https:" || !SNS_CERTIFICATE_HOST.test(url.hostname)) throw new SnsCertificateUntrusted(message.SigningCertURL);
|
|
69
|
+
const algorithm = message.SignatureVersion === "1" ? "RSA-SHA1" : message.SignatureVersion === "2" ? "RSA-SHA256" : void 0;
|
|
70
|
+
if (!algorithm) throw new SnsSignatureVersionUnknown(message.SignatureVersion);
|
|
71
|
+
const fetchCertificate = options.fetchCertificate ?? defaultFetchCertificate;
|
|
72
|
+
let certificate = certificates.get(message.SigningCertURL);
|
|
73
|
+
if (!certificate || options.fetchCertificate) {
|
|
74
|
+
certificate = fetchCertificate(message.SigningCertURL);
|
|
75
|
+
if (!options.fetchCertificate) {
|
|
76
|
+
certificates.set(message.SigningCertURL, certificate);
|
|
77
|
+
certificate.catch(() => certificates.delete(message.SigningCertURL));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const verifier = createVerify(algorithm);
|
|
81
|
+
verifier.update(snsStringToSign(message), "utf8");
|
|
82
|
+
if (!verifier.verify(await certificate, message.Signature, "base64")) throw new SnsSignatureInvalid(message.MessageId, message.TopicArn);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Confirm a subscription by visiting the URL SNS sent. Until this happens SNS
|
|
86
|
+
* delivers nothing to the endpoint.
|
|
87
|
+
*/
|
|
88
|
+
async function confirmSnsSubscription(message, request = fetch) {
|
|
89
|
+
if (message.Type !== "SubscriptionConfirmation" || !message.SubscribeURL) throw new SnsNotAConfirmation(message.Type);
|
|
90
|
+
const response = await request(message.SubscribeURL);
|
|
91
|
+
if (!response.ok) throw new SnsConfirmationFailed(message.TopicArn, response.status);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A pushed notification as the Lambda event SNS would have invoked a function
|
|
95
|
+
* with, so it can be handed to the same adaptor.
|
|
96
|
+
*/
|
|
97
|
+
function toSnsEvent(message, subscriptionArn = "") {
|
|
98
|
+
return { Records: [{
|
|
99
|
+
EventSource: "aws:sns",
|
|
100
|
+
EventVersion: "1.0",
|
|
101
|
+
EventSubscriptionArn: subscriptionArn,
|
|
102
|
+
Sns: {
|
|
103
|
+
Type: message.Type,
|
|
104
|
+
MessageId: message.MessageId,
|
|
105
|
+
TopicArn: message.TopicArn,
|
|
106
|
+
Subject: message.Subject ?? null,
|
|
107
|
+
Message: message.Message,
|
|
108
|
+
Timestamp: message.Timestamp,
|
|
109
|
+
SignatureVersion: message.SignatureVersion,
|
|
110
|
+
Signature: message.Signature,
|
|
111
|
+
SigningCertUrl: message.SigningCertURL,
|
|
112
|
+
UnsubscribeUrl: message.UnsubscribeURL ?? "",
|
|
113
|
+
MessageAttributes: message.MessageAttributes ?? {}
|
|
114
|
+
}
|
|
115
|
+
}] };
|
|
116
|
+
}
|
|
117
|
+
var SnsCertificateUntrusted = class extends Error {
|
|
118
|
+
url;
|
|
119
|
+
constructor(url) {
|
|
120
|
+
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.`);
|
|
121
|
+
this.url = url;
|
|
122
|
+
this.name = "SnsCertificateUntrusted";
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var SnsCertificateUnavailable = class extends Error {
|
|
126
|
+
url;
|
|
127
|
+
status;
|
|
128
|
+
constructor(url, status) {
|
|
129
|
+
super(`Fetching the SNS signing certificate at '${url}' answered ${status}. The message cannot be verified, so it is not handled; SNS will retry.`);
|
|
130
|
+
this.url = url;
|
|
131
|
+
this.status = status;
|
|
132
|
+
this.name = "SnsCertificateUnavailable";
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var SnsSignatureVersionUnknown = class extends Error {
|
|
136
|
+
version;
|
|
137
|
+
constructor(version) {
|
|
138
|
+
super(`SNS signature version '${version}' is not one this endpoint verifies (it knows '1' and '2'). Reject the request.`);
|
|
139
|
+
this.version = version;
|
|
140
|
+
this.name = "SnsSignatureVersionUnknown";
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
var SnsSignatureInvalid = class extends Error {
|
|
144
|
+
messageId;
|
|
145
|
+
topicArn;
|
|
146
|
+
constructor(messageId, topicArn) {
|
|
147
|
+
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.`);
|
|
148
|
+
this.messageId = messageId;
|
|
149
|
+
this.topicArn = topicArn;
|
|
150
|
+
this.name = "SnsSignatureInvalid";
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var SnsMessageTypeUnknown = class extends Error {
|
|
154
|
+
type;
|
|
155
|
+
constructor(type) {
|
|
156
|
+
super(`'${type}' is not an SNS message type (Notification, SubscriptionConfirmation, UnsubscribeConfirmation). Reject it.`);
|
|
157
|
+
this.type = type;
|
|
158
|
+
this.name = "SnsMessageTypeUnknown";
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
var SnsNotAConfirmation = class extends Error {
|
|
162
|
+
type;
|
|
163
|
+
constructor(type) {
|
|
164
|
+
super(`Only a SubscriptionConfirmation carries a URL to confirm; this is a '${type}'.`);
|
|
165
|
+
this.type = type;
|
|
166
|
+
this.name = "SnsNotAConfirmation";
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var SnsConfirmationFailed = class extends Error {
|
|
170
|
+
topicArn;
|
|
171
|
+
status;
|
|
172
|
+
constructor(topicArn, status) {
|
|
173
|
+
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.`);
|
|
174
|
+
this.topicArn = topicArn;
|
|
175
|
+
this.status = status;
|
|
176
|
+
this.name = "SnsConfirmationFailed";
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
//#endregion
|
|
180
|
+
export { SnsCertificateUnavailable, SnsCertificateUntrusted, SnsConfirmationFailed, SnsMessageTypeUnknown, SnsNotAConfirmation, SnsSignatureInvalid, SnsSignatureVersionUnknown, confirmSnsSubscription, parseUrl, snsStringToSign, toSnsEvent, verifySnsMessage };
|
|
181
|
+
|
|
182
|
+
//# sourceMappingURL=message.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.mjs","names":[],"sources":["../../src/sns/message.ts"],"sourcesContent":["import { createVerify } from 'node:crypto';\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 * Nothing here calls the SNS API, so nothing here needs the AWS SDK: a server\n * that only receives pushes loads this as `@geekmidas/events/sns/message`.\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 */\nexport function 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/**\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"],"mappings":"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"}
|
package/dist/sqs/index.cjs
CHANGED
|
@@ -1,75 +1,31 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
require("../telemetry-DG3l807O.cjs");
|
|
3
|
+
const require_registry = require("../registry-DlT36229.cjs");
|
|
3
4
|
const require_sqs_sqsUrl = require("./sqsUrl.cjs");
|
|
4
|
-
const require_SQSSubscriber = require("../SQSSubscriber-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const params = new URL(connectionString).searchParams;
|
|
22
|
-
const { SQSConnection } = await Promise.resolve().then(() => require("../SQSSubscriber-DtRUaZB3.cjs")).then((n) => n.SQSConnection_exports);
|
|
23
|
-
const connection = await SQSConnection.fromConnectionString(connectionString);
|
|
24
|
-
const options = { maxBatchSize: params.get("maxBatchSize") ? Number.parseInt(params.get("maxBatchSize"), 10) : void 0 };
|
|
25
|
-
return new SQSPublisher(connection, options);
|
|
26
|
-
}
|
|
27
|
-
async publish(messages) {
|
|
28
|
-
if (messages.length === 0) return;
|
|
29
|
-
if (!this.connection.isConnected()) await this.connection.connect();
|
|
30
|
-
const batches = (0, lodash_chunk.default)(messages, this.options.maxBatchSize);
|
|
31
|
-
await Promise.all(batches.map((batch) => this.sendBatch(batch)));
|
|
32
|
-
}
|
|
33
|
-
async sendBatch(messages) {
|
|
34
|
-
const entries = messages.map((message, index) => ({
|
|
35
|
-
Id: `${index}`,
|
|
36
|
-
MessageBody: JSON.stringify({
|
|
37
|
-
type: message.type,
|
|
38
|
-
payload: message.payload
|
|
39
|
-
}),
|
|
40
|
-
MessageAttributes: { type: {
|
|
41
|
-
DataType: "String",
|
|
42
|
-
StringValue: message.type
|
|
43
|
-
} }
|
|
44
|
-
}));
|
|
45
|
-
const input = {
|
|
46
|
-
QueueUrl: this.connection.queueUrl,
|
|
47
|
-
Entries: entries
|
|
48
|
-
};
|
|
49
|
-
const command = new _aws_sdk_client_sqs.SendMessageBatchCommand(input);
|
|
50
|
-
const response = await this.connection.sqsClient.send(command);
|
|
51
|
-
if (response.Failed && response.Failed.length > 0) throw new SqsBatchPartlyFailed(response.Failed.map((f) => ({
|
|
52
|
-
id: f.Id,
|
|
53
|
-
code: f.Code,
|
|
54
|
-
message: f.Message
|
|
55
|
-
})));
|
|
56
|
-
}
|
|
57
|
-
async close() {}
|
|
58
|
-
};
|
|
59
|
-
/** SQS accepted the batch but refused some of its messages; the rest were sent. */
|
|
60
|
-
var SqsBatchPartlyFailed = class extends Error {
|
|
61
|
-
failed;
|
|
62
|
-
constructor(failed) {
|
|
63
|
-
super(`Failed to send ${failed.length} messages: ${failed.map((f) => `${f.id}: ${f.code} - ${f.message}`).join(", ")}. The others in the batch were sent; retry only these.`);
|
|
64
|
-
this.failed = failed;
|
|
65
|
-
this.name = "SqsBatchPartlyFailed";
|
|
66
|
-
}
|
|
5
|
+
const require_SQSSubscriber = require("../SQSSubscriber-COTqWvOk.cjs");
|
|
6
|
+
//#region src/sqs/driver.ts
|
|
7
|
+
/**
|
|
8
|
+
* `sqs://` — an SQS queue. Register it with
|
|
9
|
+
* `registerEventsDriver(sqsEventsDriver)`; this subpath is the only one that
|
|
10
|
+
* imports `@aws-sdk/client-sqs` on its own.
|
|
11
|
+
*/
|
|
12
|
+
const sqsEventsDriver = {
|
|
13
|
+
scheme: "sqs",
|
|
14
|
+
connect: (url) => require_SQSSubscriber.SQSConnection.fromConnectionString(url),
|
|
15
|
+
publisher: (url) => require_SQSSubscriber.SQSPublisher.fromConnectionString(url),
|
|
16
|
+
publisherFor: (connection) => new require_SQSSubscriber.SQSPublisher(connection),
|
|
17
|
+
async subscriber(url) {
|
|
18
|
+
if (new URL(url).searchParams.get("topicArn")) return require_registry.eventsDriverFor("sns", "subscriber").subscriber(url.replace(/^sqs:/, "sns:"));
|
|
19
|
+
return new require_SQSSubscriber.SQSSubscriber(await require_SQSSubscriber.SQSConnection.fromConnectionString(url));
|
|
20
|
+
},
|
|
21
|
+
subscriberFor: (connection) => new require_SQSSubscriber.SQSSubscriber(connection)
|
|
67
22
|
};
|
|
68
23
|
//#endregion
|
|
69
24
|
exports.SQSConnection = require_SQSSubscriber.SQSConnection;
|
|
70
|
-
exports.SQSPublisher = SQSPublisher;
|
|
25
|
+
exports.SQSPublisher = require_SQSSubscriber.SQSPublisher;
|
|
71
26
|
exports.SQSSubscriber = require_SQSSubscriber.SQSSubscriber;
|
|
72
|
-
exports.SqsBatchPartlyFailed = SqsBatchPartlyFailed;
|
|
27
|
+
exports.SqsBatchPartlyFailed = require_SQSSubscriber.SqsBatchPartlyFailed;
|
|
28
|
+
exports.sqsEventsDriver = sqsEventsDriver;
|
|
73
29
|
Object.defineProperty(exports, "sqsUrl", {
|
|
74
30
|
enumerable: true,
|
|
75
31
|
get: function() {
|
package/dist/sqs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["SQSConnection","SQSPublisher","eventsDriverFor","SQSSubscriber"],"sources":["../../src/sqs/driver.ts"],"sourcesContent":["import { type EventsDriver, eventsDriverFor } from '../registry';\nimport { EventPublisherType } from '../types';\nimport { SQSConnection } from './SQSConnection';\nimport { SQSPublisher } from './SQSPublisher';\nimport { SQSSubscriber } from './SQSSubscriber';\n\n/**\n * `sqs://` — an SQS queue. Register it with\n * `registerEventsDriver(sqsEventsDriver)`; this subpath is the only one that\n * imports `@aws-sdk/client-sqs` on its own.\n */\nexport const sqsEventsDriver: EventsDriver = {\n\tscheme: EventPublisherType.SQS,\n\tconnect: (url) => SQSConnection.fromConnectionString(url),\n\tpublisher: (url) => SQSPublisher.fromConnectionString(url),\n\tpublisherFor: (connection) => new SQSPublisher(connection as SQSConnection),\n\tasync subscriber(url) {\n\t\t// A queue named with the topic it is subscribed to is a managed SNS→SQS\n\t\t// subscription, which is the SNS driver's to build — reached through the\n\t\t// registry, so this subpath never imports the SNS client.\n\t\tif (new URL(url).searchParams.get('topicArn')) {\n\t\t\treturn eventsDriverFor(EventPublisherType.SNS, 'subscriber').subscriber(\n\t\t\t\turl.replace(/^sqs:/, 'sns:'),\n\t\t\t);\n\t\t}\n\t\treturn new SQSSubscriber(await SQSConnection.fromConnectionString(url));\n\t},\n\tsubscriberFor: (connection) => new SQSSubscriber(connection as SQSConnection),\n};\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,kBAAgC;CAC5C,QAAA;CACA,UAAU,QAAQA,sBAAAA,cAAc,qBAAqB,GAAG;CACxD,YAAY,QAAQC,sBAAAA,aAAa,qBAAqB,GAAG;CACzD,eAAe,eAAe,IAAIA,sBAAAA,aAAa,UAA2B;CAC1E,MAAM,WAAW,KAAK;EAIrB,IAAI,IAAI,IAAI,GAAG,CAAC,CAAC,aAAa,IAAI,UAAU,GAC3C,OAAOC,iBAAAA,gBAAAA,OAAwC,YAAY,CAAC,CAAC,WAC5D,IAAI,QAAQ,SAAS,MAAM,CAC5B;EAED,OAAO,IAAIC,sBAAAA,cAAc,MAAMH,sBAAAA,cAAc,qBAAqB,GAAG,CAAC;CACvE;CACA,gBAAgB,eAAe,IAAIG,sBAAAA,cAAc,UAA2B;AAC7E"}
|
package/dist/sqs/index.d.cts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
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
2
|
import { SqsAddress, t as sqsUrl_d_exports } from "./sqsUrl.cjs";
|
|
3
3
|
import { SQSClient } from "@aws-sdk/client-sqs";
|
|
4
|
+
//#region src/sqs/driver.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* `sqs://` — an SQS queue. Register it with
|
|
7
|
+
* `registerEventsDriver(sqsEventsDriver)`; this subpath is the only one that
|
|
8
|
+
* imports `@aws-sdk/client-sqs` on its own.
|
|
9
|
+
*/
|
|
10
|
+
export declare const sqsEventsDriver: EventsDriver;
|
|
11
|
+
//#endregion
|
|
4
12
|
//#region src/sqs/SQSConnection.d.ts
|
|
5
13
|
interface SQSConnectionConfig {
|
|
6
14
|
queueUrl: string;
|
|
@@ -51,6 +59,7 @@ export declare class SQSPublisher<TMessage extends PublishableMessage<string, an
|
|
|
51
59
|
static fromConnectionString<TMessage extends PublishableMessage<string, any>>(connectionString: string): Promise<SQSPublisher<TMessage>>;
|
|
52
60
|
publish(messages: TMessage[]): Promise<void>;
|
|
53
61
|
private sendBatch;
|
|
62
|
+
private send;
|
|
54
63
|
close(): Promise<void>;
|
|
55
64
|
}
|
|
56
65
|
/** SQS accepted the batch but refused some of its messages; the rest were sent. */
|
package/dist/sqs/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/sqs/SQSConnection.ts","../../src/sqs/SQSPublisher.ts","../../src/sqs/SQSSubscriber.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/sqs/driver.ts","../../src/sqs/SQSConnection.ts","../../src/sqs/SQSPublisher.ts","../../src/sqs/SQSSubscriber.ts"],"mappings":";;;;;;;;;qBAWa,iBAAiB;;;UCNb;EAChB;EACA;EACA;EACA;IACC;IACA;IACA;;;qBAIW,yBAAyB;WAKhB,QAAQ;WAJpB,OAAI,mBAAA;UACL;UACA;EAER,YAAqB,QAAQ;;;;;SAgBhB,qBACZ,2BACE,QAAQ;EA8BL,WAAW;EAKX,SAAS;EAKf;;;;MAOI,aAAa;;;;MAOb;;;;UCnFY;EAChB;;qBAGY,aAAa,iBAAiB,4CAC/B,eAAe;WAKhB,YAAY;WAHb,SAAS,SAAS;EAE3B,YACU,YAAY,eACrB,UAAS;;;;;SAWG,qBACZ,iBAAiB,iCAChB,2BAA2B,QAAQ,aAAa;EAiB5C,QAAQ,UAAU,aAAa;UAcvB;UA2BA;EAqBR,SAAS;;;qBAOH,6BAA6B;WAE/B;IACR;IACA;IACA;;EAJF,YACU;IACR;IACA;IACA;;;;;UC/Gc;EAChB;EACA;EACA;;;;;;;;;;;;;;;qBAgBY,cAAc,iBAAiB,4CAChC,gBAAgB;UAQlB;UAND;UACA;UACA;UACA;EAER,YACS,YAAY,eACpB,UAAS;EASJ,UACL,UAAU,oBACV,WAAW,SAAS,aAAa,gBAC/B;EAYH;UAIc;UAqBA;;;;UA8DN;UAuCM;UAUN"}
|
package/dist/sqs/index.d.mts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as EventPublisher, f as EventPublisherType, g as PublishableMessage, p as EventSubscriber, t as EventsDriver, u as EventConnection } from "../registry-DIx25Q5s.mjs";
|
|
2
2
|
import { SqsAddress, t as sqsUrl_d_exports } from "./sqsUrl.mjs";
|
|
3
3
|
import { SQSClient } from "@aws-sdk/client-sqs";
|
|
4
|
+
//#region src/sqs/driver.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* `sqs://` — an SQS queue. Register it with
|
|
7
|
+
* `registerEventsDriver(sqsEventsDriver)`; this subpath is the only one that
|
|
8
|
+
* imports `@aws-sdk/client-sqs` on its own.
|
|
9
|
+
*/
|
|
10
|
+
export declare const sqsEventsDriver: EventsDriver;
|
|
11
|
+
//#endregion
|
|
4
12
|
//#region src/sqs/SQSConnection.d.ts
|
|
5
13
|
interface SQSConnectionConfig {
|
|
6
14
|
queueUrl: string;
|
|
@@ -51,6 +59,7 @@ export declare class SQSPublisher<TMessage extends PublishableMessage<string, an
|
|
|
51
59
|
static fromConnectionString<TMessage extends PublishableMessage<string, any>>(connectionString: string): Promise<SQSPublisher<TMessage>>;
|
|
52
60
|
publish(messages: TMessage[]): Promise<void>;
|
|
53
61
|
private sendBatch;
|
|
62
|
+
private send;
|
|
54
63
|
close(): Promise<void>;
|
|
55
64
|
}
|
|
56
65
|
/** SQS accepted the batch but refused some of its messages; the rest were sent. */
|
package/dist/sqs/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/sqs/SQSConnection.ts","../../src/sqs/SQSPublisher.ts","../../src/sqs/SQSSubscriber.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/sqs/driver.ts","../../src/sqs/SQSConnection.ts","../../src/sqs/SQSPublisher.ts","../../src/sqs/SQSSubscriber.ts"],"mappings":";;;;;;;;;qBAWa,iBAAiB;;;UCNb;EAChB;EACA;EACA;EACA;IACC;IACA;IACA;;;qBAIW,yBAAyB;WAKhB,QAAQ;WAJpB,OAAI,mBAAA;UACL;UACA;EAER,YAAqB,QAAQ;;;;;SAgBhB,qBACZ,2BACE,QAAQ;EA8BL,WAAW;EAKX,SAAS;EAKf;;;;MAOI,aAAa;;;;MAOb;;;;UCnFY;EAChB;;qBAGY,aAAa,iBAAiB,4CAC/B,eAAe;WAKhB,YAAY;WAHb,SAAS,SAAS;EAE3B,YACU,YAAY,eACrB,UAAS;;;;;SAWG,qBACZ,iBAAiB,iCAChB,2BAA2B,QAAQ,aAAa;EAiB5C,QAAQ,UAAU,aAAa;UAcvB;UA2BA;EAqBR,SAAS;;;qBAOH,6BAA6B;WAE/B;IACR;IACA;IACA;;EAJF,YACU;IACR;IACA;IACA;;;;;UC/Gc;EAChB;EACA;EACA;;;;;;;;;;;;;;;qBAgBY,cAAc,iBAAiB,4CAChC,gBAAgB;UAQlB;UAND;UACA;UACA;UACA;EAER,YACS,YAAY,eACpB,UAAS;EASJ,UACL,UAAU,oBACV,WAAW,SAAS,aAAa,gBAC/B;EAYH;UAIc;UAqBA;;;;UA8DN;UAuCM;UAUN"}
|
package/dist/sqs/index.mjs
CHANGED
|
@@ -1,68 +1,25 @@
|
|
|
1
|
+
import "../telemetry-DjjgJMul.mjs";
|
|
2
|
+
import { n as eventsDriverFor } from "../registry-DXLY1Xf6.mjs";
|
|
1
3
|
import { t as sqsUrl_exports } from "./sqsUrl.mjs";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const { SQSConnection } = await import("../SQSSubscriber-BXLE_1L3.mjs").then((n) => n.r);
|
|
20
|
-
const connection = await SQSConnection.fromConnectionString(connectionString);
|
|
21
|
-
const options = { maxBatchSize: params.get("maxBatchSize") ? Number.parseInt(params.get("maxBatchSize"), 10) : void 0 };
|
|
22
|
-
return new SQSPublisher(connection, options);
|
|
23
|
-
}
|
|
24
|
-
async publish(messages) {
|
|
25
|
-
if (messages.length === 0) return;
|
|
26
|
-
if (!this.connection.isConnected()) await this.connection.connect();
|
|
27
|
-
const batches = chunk(messages, this.options.maxBatchSize);
|
|
28
|
-
await Promise.all(batches.map((batch) => this.sendBatch(batch)));
|
|
29
|
-
}
|
|
30
|
-
async sendBatch(messages) {
|
|
31
|
-
const entries = messages.map((message, index) => ({
|
|
32
|
-
Id: `${index}`,
|
|
33
|
-
MessageBody: JSON.stringify({
|
|
34
|
-
type: message.type,
|
|
35
|
-
payload: message.payload
|
|
36
|
-
}),
|
|
37
|
-
MessageAttributes: { type: {
|
|
38
|
-
DataType: "String",
|
|
39
|
-
StringValue: message.type
|
|
40
|
-
} }
|
|
41
|
-
}));
|
|
42
|
-
const input = {
|
|
43
|
-
QueueUrl: this.connection.queueUrl,
|
|
44
|
-
Entries: entries
|
|
45
|
-
};
|
|
46
|
-
const command = new SendMessageBatchCommand(input);
|
|
47
|
-
const response = await this.connection.sqsClient.send(command);
|
|
48
|
-
if (response.Failed && response.Failed.length > 0) throw new SqsBatchPartlyFailed(response.Failed.map((f) => ({
|
|
49
|
-
id: f.Id,
|
|
50
|
-
code: f.Code,
|
|
51
|
-
message: f.Message
|
|
52
|
-
})));
|
|
53
|
-
}
|
|
54
|
-
async close() {}
|
|
55
|
-
};
|
|
56
|
-
/** SQS accepted the batch but refused some of its messages; the rest were sent. */
|
|
57
|
-
var SqsBatchPartlyFailed = class extends Error {
|
|
58
|
-
failed;
|
|
59
|
-
constructor(failed) {
|
|
60
|
-
super(`Failed to send ${failed.length} messages: ${failed.map((f) => `${f.id}: ${f.code} - ${f.message}`).join(", ")}. The others in the batch were sent; retry only these.`);
|
|
61
|
-
this.failed = failed;
|
|
62
|
-
this.name = "SqsBatchPartlyFailed";
|
|
63
|
-
}
|
|
4
|
+
import { i as SQSConnection, n as SQSPublisher, r as SqsBatchPartlyFailed, t as SQSSubscriber } from "../SQSSubscriber-BEJBfNTe.mjs";
|
|
5
|
+
//#region src/sqs/driver.ts
|
|
6
|
+
/**
|
|
7
|
+
* `sqs://` — an SQS queue. Register it with
|
|
8
|
+
* `registerEventsDriver(sqsEventsDriver)`; this subpath is the only one that
|
|
9
|
+
* imports `@aws-sdk/client-sqs` on its own.
|
|
10
|
+
*/
|
|
11
|
+
const sqsEventsDriver = {
|
|
12
|
+
scheme: "sqs",
|
|
13
|
+
connect: (url) => SQSConnection.fromConnectionString(url),
|
|
14
|
+
publisher: (url) => SQSPublisher.fromConnectionString(url),
|
|
15
|
+
publisherFor: (connection) => new SQSPublisher(connection),
|
|
16
|
+
async subscriber(url) {
|
|
17
|
+
if (new URL(url).searchParams.get("topicArn")) return eventsDriverFor("sns", "subscriber").subscriber(url.replace(/^sqs:/, "sns:"));
|
|
18
|
+
return new SQSSubscriber(await SQSConnection.fromConnectionString(url));
|
|
19
|
+
},
|
|
20
|
+
subscriberFor: (connection) => new SQSSubscriber(connection)
|
|
64
21
|
};
|
|
65
22
|
//#endregion
|
|
66
|
-
export { SQSConnection, SQSPublisher, SQSSubscriber, SqsBatchPartlyFailed, sqsUrl_exports as sqsUrl };
|
|
23
|
+
export { SQSConnection, SQSPublisher, SQSSubscriber, SqsBatchPartlyFailed, sqsEventsDriver, sqsUrl_exports as sqsUrl };
|
|
67
24
|
|
|
68
25
|
//# sourceMappingURL=index.mjs.map
|
package/dist/sqs/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/sqs/
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/sqs/driver.ts"],"sourcesContent":["import { type EventsDriver, eventsDriverFor } from '../registry';\nimport { EventPublisherType } from '../types';\nimport { SQSConnection } from './SQSConnection';\nimport { SQSPublisher } from './SQSPublisher';\nimport { SQSSubscriber } from './SQSSubscriber';\n\n/**\n * `sqs://` — an SQS queue. Register it with\n * `registerEventsDriver(sqsEventsDriver)`; this subpath is the only one that\n * imports `@aws-sdk/client-sqs` on its own.\n */\nexport const sqsEventsDriver: EventsDriver = {\n\tscheme: EventPublisherType.SQS,\n\tconnect: (url) => SQSConnection.fromConnectionString(url),\n\tpublisher: (url) => SQSPublisher.fromConnectionString(url),\n\tpublisherFor: (connection) => new SQSPublisher(connection as SQSConnection),\n\tasync subscriber(url) {\n\t\t// A queue named with the topic it is subscribed to is a managed SNS→SQS\n\t\t// subscription, which is the SNS driver's to build — reached through the\n\t\t// registry, so this subpath never imports the SNS client.\n\t\tif (new URL(url).searchParams.get('topicArn')) {\n\t\t\treturn eventsDriverFor(EventPublisherType.SNS, 'subscriber').subscriber(\n\t\t\t\turl.replace(/^sqs:/, 'sns:'),\n\t\t\t);\n\t\t}\n\t\treturn new SQSSubscriber(await SQSConnection.fromConnectionString(url));\n\t},\n\tsubscriberFor: (connection) => new SQSSubscriber(connection as SQSConnection),\n};\n"],"mappings":";;;;;;;;;;AAWA,MAAa,kBAAgC;CAC5C,QAAA;CACA,UAAU,QAAQ,cAAc,qBAAqB,GAAG;CACxD,YAAY,QAAQ,aAAa,qBAAqB,GAAG;CACzD,eAAe,eAAe,IAAI,aAAa,UAA2B;CAC1E,MAAM,WAAW,KAAK;EAIrB,IAAI,IAAI,IAAI,GAAG,CAAC,CAAC,aAAa,IAAI,UAAU,GAC3C,OAAO,gBAAA,OAAwC,YAAY,CAAC,CAAC,WAC5D,IAAI,QAAQ,SAAS,MAAM,CAC5B;EAED,OAAO,IAAI,cAAc,MAAM,cAAc,qBAAqB,GAAG,CAAC;CACvE;CACA,gBAAgB,eAAe,IAAI,cAAc,UAA2B;AAC7E"}
|