@geekmidas/events 10.0.0-alpha.17 → 10.0.0-alpha.170
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
package/dist/sns/index.d.cts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
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
|
+
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
|
-
import { SNSClient } from "@aws-sdk/client-sns";
|
|
4
|
+
import { SNSClient, SNSClientConfig } from "@aws-sdk/client-sns";
|
|
5
|
+
//#region src/sns/driver.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* `sns://` — an SNS topic, consumed through an SQS queue subscribed to it.
|
|
8
|
+
* Register it with `registerEventsDriver(snsEventsDriver)`; an AWS entry
|
|
9
|
+
* registers `sqsEventsDriver` beside it.
|
|
10
|
+
*/
|
|
11
|
+
export declare const snsEventsDriver: EventsDriver;
|
|
12
|
+
//#endregion
|
|
4
13
|
//#region src/sns/SNSConnection.d.ts
|
|
5
14
|
interface SNSConnectionConfig {
|
|
6
15
|
topicArn: string;
|
|
7
16
|
region?: string;
|
|
8
17
|
endpoint?: string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Static keys, or a provider the SDK resolves them through — a deploy's
|
|
20
|
+
* profile or chain, where nothing pins a key pair.
|
|
21
|
+
*/
|
|
22
|
+
credentials?: SNSClientConfig['credentials'];
|
|
14
23
|
}
|
|
15
24
|
export declare class SNSConnection implements EventConnection {
|
|
16
25
|
readonly type = EventPublisherType.SNS;
|
|
@@ -36,6 +45,134 @@ export declare class SNSConnection implements EventConnection {
|
|
|
36
45
|
get topicArn(): string;
|
|
37
46
|
}
|
|
38
47
|
//#endregion
|
|
48
|
+
//#region src/sns/push.d.ts
|
|
49
|
+
/**
|
|
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.
|
|
53
|
+
*/
|
|
54
|
+
/** Where a subscription's filter policy is matched. */
|
|
55
|
+
type SnsFilterPolicyScope = 'MessageAttributes' | 'MessageBody';
|
|
56
|
+
/** What an HTTP subscription is created or brought up to date with. */
|
|
57
|
+
interface HttpSubscriptionFilter {
|
|
58
|
+
/**
|
|
59
|
+
* The event types this endpoint takes. Becomes the subscription's filter
|
|
60
|
+
* policy on the `type` attribute `SNSPublisher` sets, so SNS sends nothing
|
|
61
|
+
* else — fan-out to every subscriber, each seeing only what it named.
|
|
62
|
+
*
|
|
63
|
+
* Absent, with no {@link filterPolicy} either, for a topic whose
|
|
64
|
+
* publisher sets no `type` — a bucket's — whose subscriber filters what it
|
|
65
|
+
* is sent.
|
|
66
|
+
*
|
|
67
|
+
* Ignored when {@link filterPolicy} is given.
|
|
68
|
+
*/
|
|
69
|
+
events?: readonly string[];
|
|
70
|
+
/**
|
|
71
|
+
* A filter policy of the caller's own, for messages SNS did not receive
|
|
72
|
+
* from `SNSPublisher` — a bucket's notifications carry no `type` attribute,
|
|
73
|
+
* so they are matched on their body instead.
|
|
74
|
+
*/
|
|
75
|
+
filterPolicy?: Record<string, unknown>;
|
|
76
|
+
/** Where {@link filterPolicy} is matched. `MessageAttributes` by default. */
|
|
77
|
+
filterPolicyScope?: SnsFilterPolicyScope;
|
|
78
|
+
/**
|
|
79
|
+
* An SQS queue's ARN for what SNS gives up delivering. SNS retries an HTTP
|
|
80
|
+
* endpoint for a limited time and then drops the message, so without one an
|
|
81
|
+
* outage longer than that loses events.
|
|
82
|
+
*/
|
|
83
|
+
deadLetterQueueArn?: string;
|
|
84
|
+
}
|
|
85
|
+
interface SubscribeHttpEndpointOptions extends HttpSubscriptionFilter {
|
|
86
|
+
/** The URL SNS POSTs to — `http:` or `https:`, which picks the protocol. */
|
|
87
|
+
endpoint: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Subscribe an HTTP endpoint to the connection's topic, converging on one
|
|
91
|
+
* confirmed subscription with the filter asked for — so it is safe on every
|
|
92
|
+
* start. What a server does against an emulator, where nothing deploys it;
|
|
93
|
+
* against SNS itself the deploy owns the subscription
|
|
94
|
+
* ({@link reconcileHttpSubscriptions}).
|
|
95
|
+
*
|
|
96
|
+
* - **none yet** — subscribed; SNS sends a confirmation to the endpoint.
|
|
97
|
+
* - **confirmed** — its filter and dead-letter queue are brought up to date.
|
|
98
|
+
* Subscribing again with different attributes is an error on SNS, and the
|
|
99
|
+
* events a subscriber names change.
|
|
100
|
+
* - **stuck pending** — a confirmation that never landed (the endpoint was
|
|
101
|
+
* down, or answered wrong). Subscribing the same endpoint again is a no-op
|
|
102
|
+
* on an emulator, so it is dropped and subscribed afresh, which sends a new
|
|
103
|
+
* confirmation.
|
|
104
|
+
*/
|
|
105
|
+
export declare function subscribeHttpEndpoint(connection: SNSConnection, options: SubscribeHttpEndpointOptions): Promise<string | undefined>;
|
|
106
|
+
/** One endpoint the deploy wants subscribed, under the name it is recorded by. */
|
|
107
|
+
interface HttpSubscriptionSpec extends HttpSubscriptionFilter {
|
|
108
|
+
/** What the ARN is recorded under — the subscriber's export. */
|
|
109
|
+
name: string;
|
|
110
|
+
/** The URL SNS POSTs to. */
|
|
111
|
+
endpoint: string;
|
|
112
|
+
}
|
|
113
|
+
interface ReconcileHttpSubscriptionsOptions {
|
|
114
|
+
/** Every endpoint that should be subscribed to the topic. */
|
|
115
|
+
endpoints: readonly HttpSubscriptionSpec[];
|
|
116
|
+
/**
|
|
117
|
+
* The host these endpoints answer on. A subscription to an endpoint on it
|
|
118
|
+
* that is not in {@link endpoints} — a subscriber renamed or removed — is
|
|
119
|
+
* unsubscribed; anything subscribed on another host is somebody else's and
|
|
120
|
+
* left alone.
|
|
121
|
+
*/
|
|
122
|
+
ownedHost: string;
|
|
123
|
+
}
|
|
124
|
+
interface ReconciledHttpSubscriptions {
|
|
125
|
+
/** Each endpoint's subscription ARN, by its name — stable across runs. */
|
|
126
|
+
subscriptions: Record<string, string>;
|
|
127
|
+
/** The names whose subscription SNS still waits to have confirmed. */
|
|
128
|
+
pending: string[];
|
|
129
|
+
/** The ARNs of what was unsubscribed as no longer wanted. */
|
|
130
|
+
removed: string[];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Converge a topic's HTTP subscriptions on the endpoints a deploy wants, and
|
|
134
|
+
* answer each one's ARN for the deploy to record and hand to the server.
|
|
135
|
+
*
|
|
136
|
+
* The deploy's half of push delivery against SNS itself: the server never
|
|
137
|
+
* subscribes, so its credentials need no `sns:Subscribe` — and the only
|
|
138
|
+
* subscriptions to the topic are ones the deploy made.
|
|
139
|
+
*
|
|
140
|
+
* Run it twice: once before the server starts, for the ARNs it is configured
|
|
141
|
+
* with — SNS answers one even while the subscription waits to be confirmed —
|
|
142
|
+
* and once the server is up, which subscribes each still-pending endpoint
|
|
143
|
+
* again so SNS resends its confirmation to a server now there to answer it.
|
|
144
|
+
* The ARN does not change between the two.
|
|
145
|
+
*
|
|
146
|
+
* - **absent** — subscribed with its filter.
|
|
147
|
+
* - **present** — its filter and dead-letter queue are brought up to date;
|
|
148
|
+
* pending, it is subscribed again to resend the confirmation.
|
|
149
|
+
* - **stale** — on {@link ReconcileHttpSubscriptionsOptions.ownedHost} and no
|
|
150
|
+
* longer wanted: unsubscribed. (A stale one SNS still lists as pending has
|
|
151
|
+
* no ARN to act on; SNS drops it unconfirmed after three days.)
|
|
152
|
+
*/
|
|
153
|
+
export declare function reconcileHttpSubscriptions(connection: SNSConnection, options: ReconcileHttpSubscriptionsOptions): Promise<ReconciledHttpSubscriptions>;
|
|
154
|
+
/**
|
|
155
|
+
* Confirm a subscription through the API, as its topic's owner, rather than by
|
|
156
|
+
* visiting the URL SNS sent.
|
|
157
|
+
*
|
|
158
|
+
* `AuthenticateOnUnsubscribe` is the point of it. A subscription confirmed by
|
|
159
|
+
* visiting `SubscribeURL` can be removed by anyone holding the
|
|
160
|
+
* `UnsubscribeURL` every notification carries — one unauthenticated GET, and
|
|
161
|
+
* the endpoint is silently cut off. Confirmed this way, only the topic's owner
|
|
162
|
+
* can unsubscribe it. All it takes of the caller's credentials is
|
|
163
|
+
* `sns:ConfirmSubscription` on this one topic.
|
|
164
|
+
*/
|
|
165
|
+
export declare function confirmSubscription(connection: SNSConnection, message: SnsHttpMessage): Promise<string | undefined>;
|
|
166
|
+
export declare class SnsEndpointNotHttp extends Error {
|
|
167
|
+
readonly endpoint: string;
|
|
168
|
+
constructor(endpoint: string);
|
|
169
|
+
}
|
|
170
|
+
export declare class SnsSubscriptionArnMissing extends Error {
|
|
171
|
+
readonly topicArn: string;
|
|
172
|
+
readonly endpoint: string;
|
|
173
|
+
constructor(topicArn: string, endpoint: string);
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
39
176
|
//#region src/sns/SNSPublisher.d.ts
|
|
40
177
|
type SNSPublisherOptions = {};
|
|
41
178
|
export declare class SNSPublisher<TMessage extends PublishableMessage<string, any>> implements EventPublisher<TMessage> {
|
|
@@ -108,5 +245,5 @@ export declare class SnsQueueMissing extends Error {
|
|
|
108
245
|
constructor(queueName: string | undefined);
|
|
109
246
|
}
|
|
110
247
|
//#endregion
|
|
111
|
-
export { type SNSConnectionConfig, type SNSPublisherOptions, type SNSSubscriberOptions, type SnsAddress, 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 };
|
|
112
249
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/sns/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/sns/SNSConnection.ts","../../src/sns/SNSPublisher.ts","../../src/sns/SNSSubscriber.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/sns/driver.ts","../../src/sns/SNSConnection.ts","../../src/sns/push.ts","../../src/sns/SNSPublisher.ts","../../src/sns/SNSSubscriber.ts"],"mappings":";;;;;;;;;;qBAWa,iBAAiB;;;UCNb;EAChB;EACA;EACA;;;;;EAKA,cAAc;;qBAGF,yBAAyB;WAC5B,OAAI,mBAAA;UACL;UACA;UACA;EAER,YAAY,QAAQ;;;;;SAgBP,qBACZ,2BACE,QAAQ;EA8BL,WAAW;EAKX,SAAS;EAKf;;;;MAOI,aAAa;;;;MAOb;;;;;;;;;;KC3EO;;UAGK;;;;;;;;;;;;EAYhB;;;;;;EAMA,eAAe;;EAEf,oBAAoB;;;;;;EAMpB;;UAGgB,qCAAqC;;EAErD;;;;;;;;;;;;;;;;;;wBAsEqB,sBACrB,YAAY,eACZ,SAAS,+BACP;;UAiCc,6BAA6B;;EAE7C;;EAEA;;UAGgB;;EAEhB,oBAAoB;;;;;;;EAOpB;;UAGgB;;EAEhB,eAAe;;EAEf;;EAEA;;;;;;;;;;;;;;;;;;;;;;;wBAwBqB,2BACrB,YAAY,eACZ,SAAS,oCACP,QAAQ;;;;;;;;;;;;wBAyEW,oBACrB,YAAY,eACZ,SAAS,iBACP;qBA8CU,2BAA2B;WAClB;EAArB,YAAqB;;qBAST,kCAAkC;WAEpC;WACA;EAFV,YACU,kBACA;;;;KCrVC;qBAEC,aAAa,iBAAiB,4CAC/B,eAAe;UAGjB;EADT,YACS,YAAY,eACpB,WAAU;;;;;SAOE,qBACZ,iBAAiB,iCAChB,2BAA2B,QAAQ,aAAa;EAQ5C,QAAQ,UAAU,aAAa;UAqBvB;EAwBR,SAAS;;;;UC7DC;EAChB;EACA;EACA;EACA;EACA;;;;;;;;;;;;;;;;;;;qBAoBY,cAAc,iBAAiB,4CAChC,gBAAgB;UAUlB;UARD;UACA;UACA;UACA;UACA;UACA;EAER,YACS,YAAY,eACpB,UAAS;;;;;SAwBG,qBACZ,iBAAiB,iCAChB,2BAA2B,QAAQ,cAAc;EAoB7C,UACL,UAAU,oBACV,WAAW,SAAS,aAAa,gBAC/B;;;;EA2BG,QAAQ;UA6BA;UAwBA;UA4BA;;;;;;qBAgBF,wBAAwB;WACf;EAArB,YAAqB"}
|
package/dist/sns/index.d.mts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
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
|
+
import { SnsCertificateUnavailable, SnsCertificateUntrusted, SnsConfirmationFailed, SnsHttpMessage, SnsMessageTypeUnknown, SnsNotAConfirmation, SnsSignatureInvalid, SnsSignatureVersionUnknown, VerifySnsMessageOptions, confirmSnsSubscription, snsStringToSign, toSnsEvent, verifySnsMessage } from "./message.mjs";
|
|
2
3
|
import { SnsAddress, t as snsUrl_d_exports } from "./snsUrl.mjs";
|
|
3
|
-
import { SNSClient } from "@aws-sdk/client-sns";
|
|
4
|
+
import { SNSClient, SNSClientConfig } from "@aws-sdk/client-sns";
|
|
5
|
+
//#region src/sns/driver.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* `sns://` — an SNS topic, consumed through an SQS queue subscribed to it.
|
|
8
|
+
* Register it with `registerEventsDriver(snsEventsDriver)`; an AWS entry
|
|
9
|
+
* registers `sqsEventsDriver` beside it.
|
|
10
|
+
*/
|
|
11
|
+
export declare const snsEventsDriver: EventsDriver;
|
|
12
|
+
//#endregion
|
|
4
13
|
//#region src/sns/SNSConnection.d.ts
|
|
5
14
|
interface SNSConnectionConfig {
|
|
6
15
|
topicArn: string;
|
|
7
16
|
region?: string;
|
|
8
17
|
endpoint?: string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Static keys, or a provider the SDK resolves them through — a deploy's
|
|
20
|
+
* profile or chain, where nothing pins a key pair.
|
|
21
|
+
*/
|
|
22
|
+
credentials?: SNSClientConfig['credentials'];
|
|
14
23
|
}
|
|
15
24
|
export declare class SNSConnection implements EventConnection {
|
|
16
25
|
readonly type = EventPublisherType.SNS;
|
|
@@ -36,6 +45,134 @@ export declare class SNSConnection implements EventConnection {
|
|
|
36
45
|
get topicArn(): string;
|
|
37
46
|
}
|
|
38
47
|
//#endregion
|
|
48
|
+
//#region src/sns/push.d.ts
|
|
49
|
+
/**
|
|
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.
|
|
53
|
+
*/
|
|
54
|
+
/** Where a subscription's filter policy is matched. */
|
|
55
|
+
type SnsFilterPolicyScope = 'MessageAttributes' | 'MessageBody';
|
|
56
|
+
/** What an HTTP subscription is created or brought up to date with. */
|
|
57
|
+
interface HttpSubscriptionFilter {
|
|
58
|
+
/**
|
|
59
|
+
* The event types this endpoint takes. Becomes the subscription's filter
|
|
60
|
+
* policy on the `type` attribute `SNSPublisher` sets, so SNS sends nothing
|
|
61
|
+
* else — fan-out to every subscriber, each seeing only what it named.
|
|
62
|
+
*
|
|
63
|
+
* Absent, with no {@link filterPolicy} either, for a topic whose
|
|
64
|
+
* publisher sets no `type` — a bucket's — whose subscriber filters what it
|
|
65
|
+
* is sent.
|
|
66
|
+
*
|
|
67
|
+
* Ignored when {@link filterPolicy} is given.
|
|
68
|
+
*/
|
|
69
|
+
events?: readonly string[];
|
|
70
|
+
/**
|
|
71
|
+
* A filter policy of the caller's own, for messages SNS did not receive
|
|
72
|
+
* from `SNSPublisher` — a bucket's notifications carry no `type` attribute,
|
|
73
|
+
* so they are matched on their body instead.
|
|
74
|
+
*/
|
|
75
|
+
filterPolicy?: Record<string, unknown>;
|
|
76
|
+
/** Where {@link filterPolicy} is matched. `MessageAttributes` by default. */
|
|
77
|
+
filterPolicyScope?: SnsFilterPolicyScope;
|
|
78
|
+
/**
|
|
79
|
+
* An SQS queue's ARN for what SNS gives up delivering. SNS retries an HTTP
|
|
80
|
+
* endpoint for a limited time and then drops the message, so without one an
|
|
81
|
+
* outage longer than that loses events.
|
|
82
|
+
*/
|
|
83
|
+
deadLetterQueueArn?: string;
|
|
84
|
+
}
|
|
85
|
+
interface SubscribeHttpEndpointOptions extends HttpSubscriptionFilter {
|
|
86
|
+
/** The URL SNS POSTs to — `http:` or `https:`, which picks the protocol. */
|
|
87
|
+
endpoint: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Subscribe an HTTP endpoint to the connection's topic, converging on one
|
|
91
|
+
* confirmed subscription with the filter asked for — so it is safe on every
|
|
92
|
+
* start. What a server does against an emulator, where nothing deploys it;
|
|
93
|
+
* against SNS itself the deploy owns the subscription
|
|
94
|
+
* ({@link reconcileHttpSubscriptions}).
|
|
95
|
+
*
|
|
96
|
+
* - **none yet** — subscribed; SNS sends a confirmation to the endpoint.
|
|
97
|
+
* - **confirmed** — its filter and dead-letter queue are brought up to date.
|
|
98
|
+
* Subscribing again with different attributes is an error on SNS, and the
|
|
99
|
+
* events a subscriber names change.
|
|
100
|
+
* - **stuck pending** — a confirmation that never landed (the endpoint was
|
|
101
|
+
* down, or answered wrong). Subscribing the same endpoint again is a no-op
|
|
102
|
+
* on an emulator, so it is dropped and subscribed afresh, which sends a new
|
|
103
|
+
* confirmation.
|
|
104
|
+
*/
|
|
105
|
+
export declare function subscribeHttpEndpoint(connection: SNSConnection, options: SubscribeHttpEndpointOptions): Promise<string | undefined>;
|
|
106
|
+
/** One endpoint the deploy wants subscribed, under the name it is recorded by. */
|
|
107
|
+
interface HttpSubscriptionSpec extends HttpSubscriptionFilter {
|
|
108
|
+
/** What the ARN is recorded under — the subscriber's export. */
|
|
109
|
+
name: string;
|
|
110
|
+
/** The URL SNS POSTs to. */
|
|
111
|
+
endpoint: string;
|
|
112
|
+
}
|
|
113
|
+
interface ReconcileHttpSubscriptionsOptions {
|
|
114
|
+
/** Every endpoint that should be subscribed to the topic. */
|
|
115
|
+
endpoints: readonly HttpSubscriptionSpec[];
|
|
116
|
+
/**
|
|
117
|
+
* The host these endpoints answer on. A subscription to an endpoint on it
|
|
118
|
+
* that is not in {@link endpoints} — a subscriber renamed or removed — is
|
|
119
|
+
* unsubscribed; anything subscribed on another host is somebody else's and
|
|
120
|
+
* left alone.
|
|
121
|
+
*/
|
|
122
|
+
ownedHost: string;
|
|
123
|
+
}
|
|
124
|
+
interface ReconciledHttpSubscriptions {
|
|
125
|
+
/** Each endpoint's subscription ARN, by its name — stable across runs. */
|
|
126
|
+
subscriptions: Record<string, string>;
|
|
127
|
+
/** The names whose subscription SNS still waits to have confirmed. */
|
|
128
|
+
pending: string[];
|
|
129
|
+
/** The ARNs of what was unsubscribed as no longer wanted. */
|
|
130
|
+
removed: string[];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Converge a topic's HTTP subscriptions on the endpoints a deploy wants, and
|
|
134
|
+
* answer each one's ARN for the deploy to record and hand to the server.
|
|
135
|
+
*
|
|
136
|
+
* The deploy's half of push delivery against SNS itself: the server never
|
|
137
|
+
* subscribes, so its credentials need no `sns:Subscribe` — and the only
|
|
138
|
+
* subscriptions to the topic are ones the deploy made.
|
|
139
|
+
*
|
|
140
|
+
* Run it twice: once before the server starts, for the ARNs it is configured
|
|
141
|
+
* with — SNS answers one even while the subscription waits to be confirmed —
|
|
142
|
+
* and once the server is up, which subscribes each still-pending endpoint
|
|
143
|
+
* again so SNS resends its confirmation to a server now there to answer it.
|
|
144
|
+
* The ARN does not change between the two.
|
|
145
|
+
*
|
|
146
|
+
* - **absent** — subscribed with its filter.
|
|
147
|
+
* - **present** — its filter and dead-letter queue are brought up to date;
|
|
148
|
+
* pending, it is subscribed again to resend the confirmation.
|
|
149
|
+
* - **stale** — on {@link ReconcileHttpSubscriptionsOptions.ownedHost} and no
|
|
150
|
+
* longer wanted: unsubscribed. (A stale one SNS still lists as pending has
|
|
151
|
+
* no ARN to act on; SNS drops it unconfirmed after three days.)
|
|
152
|
+
*/
|
|
153
|
+
export declare function reconcileHttpSubscriptions(connection: SNSConnection, options: ReconcileHttpSubscriptionsOptions): Promise<ReconciledHttpSubscriptions>;
|
|
154
|
+
/**
|
|
155
|
+
* Confirm a subscription through the API, as its topic's owner, rather than by
|
|
156
|
+
* visiting the URL SNS sent.
|
|
157
|
+
*
|
|
158
|
+
* `AuthenticateOnUnsubscribe` is the point of it. A subscription confirmed by
|
|
159
|
+
* visiting `SubscribeURL` can be removed by anyone holding the
|
|
160
|
+
* `UnsubscribeURL` every notification carries — one unauthenticated GET, and
|
|
161
|
+
* the endpoint is silently cut off. Confirmed this way, only the topic's owner
|
|
162
|
+
* can unsubscribe it. All it takes of the caller's credentials is
|
|
163
|
+
* `sns:ConfirmSubscription` on this one topic.
|
|
164
|
+
*/
|
|
165
|
+
export declare function confirmSubscription(connection: SNSConnection, message: SnsHttpMessage): Promise<string | undefined>;
|
|
166
|
+
export declare class SnsEndpointNotHttp extends Error {
|
|
167
|
+
readonly endpoint: string;
|
|
168
|
+
constructor(endpoint: string);
|
|
169
|
+
}
|
|
170
|
+
export declare class SnsSubscriptionArnMissing extends Error {
|
|
171
|
+
readonly topicArn: string;
|
|
172
|
+
readonly endpoint: string;
|
|
173
|
+
constructor(topicArn: string, endpoint: string);
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
39
176
|
//#region src/sns/SNSPublisher.d.ts
|
|
40
177
|
type SNSPublisherOptions = {};
|
|
41
178
|
export declare class SNSPublisher<TMessage extends PublishableMessage<string, any>> implements EventPublisher<TMessage> {
|
|
@@ -108,5 +245,5 @@ export declare class SnsQueueMissing extends Error {
|
|
|
108
245
|
constructor(queueName: string | undefined);
|
|
109
246
|
}
|
|
110
247
|
//#endregion
|
|
111
|
-
export { type SNSConnectionConfig, type SNSPublisherOptions, type SNSSubscriberOptions, type SnsAddress, 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 };
|
|
112
249
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/sns/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/sns/SNSConnection.ts","../../src/sns/SNSPublisher.ts","../../src/sns/SNSSubscriber.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/sns/driver.ts","../../src/sns/SNSConnection.ts","../../src/sns/push.ts","../../src/sns/SNSPublisher.ts","../../src/sns/SNSSubscriber.ts"],"mappings":";;;;;;;;;;qBAWa,iBAAiB;;;UCNb;EAChB;EACA;EACA;;;;;EAKA,cAAc;;qBAGF,yBAAyB;WAC5B,OAAI,mBAAA;UACL;UACA;UACA;EAER,YAAY,QAAQ;;;;;SAgBP,qBACZ,2BACE,QAAQ;EA8BL,WAAW;EAKX,SAAS;EAKf;;;;MAOI,aAAa;;;;MAOb;;;;;;;;;;KC3EO;;UAGK;;;;;;;;;;;;EAYhB;;;;;;EAMA,eAAe;;EAEf,oBAAoB;;;;;;EAMpB;;UAGgB,qCAAqC;;EAErD;;;;;;;;;;;;;;;;;;wBAsEqB,sBACrB,YAAY,eACZ,SAAS,+BACP;;UAiCc,6BAA6B;;EAE7C;;EAEA;;UAGgB;;EAEhB,oBAAoB;;;;;;;EAOpB;;UAGgB;;EAEhB,eAAe;;EAEf;;EAEA;;;;;;;;;;;;;;;;;;;;;;;wBAwBqB,2BACrB,YAAY,eACZ,SAAS,oCACP,QAAQ;;;;;;;;;;;;wBAyEW,oBACrB,YAAY,eACZ,SAAS,iBACP;qBA8CU,2BAA2B;WAClB;EAArB,YAAqB;;qBAST,kCAAkC;WAEpC;WACA;EAFV,YACU,kBACA;;;;KCrVC;qBAEC,aAAa,iBAAiB,4CAC/B,eAAe;UAGjB;EADT,YACS,YAAY,eACpB,WAAU;;;;;SAOE,qBACZ,iBAAiB,iCAChB,2BAA2B,QAAQ,aAAa;EAQ5C,QAAQ,UAAU,aAAa;UAqBvB;EAwBR,SAAS;;;;UC7DC;EAChB;EACA;EACA;EACA;EACA;;;;;;;;;;;;;;;;;;;qBAoBY,cAAc,iBAAiB,4CAChC,gBAAgB;UAUlB;UARD;UACA;UACA;UACA;UACA;UACA;EAER,YACS,YAAY,eACpB,UAAS;;;;;SAwBG,qBACZ,iBAAiB,iCAChB,2BAA2B,QAAQ,cAAc;EAoB7C,UACL,UAAU,oBACV,WAAW,SAAS,aAAa,gBAC/B;;;;EA2BG,QAAQ;UA6BA;UAwBA;UA4BA;;;;;;qBAgBF,wBAAwB;WACf;EAArB,YAAqB"}
|
package/dist/sns/index.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import { n as
|
|
1
|
+
import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { n as carrierAsAttributes, s as publishTraced } from "../telemetry-DjjgJMul.mjs";
|
|
3
|
+
import { i as SQSConnection, t as SQSSubscriber } from "../SQSSubscriber-BEJBfNTe.mjs";
|
|
3
4
|
import { parse, t as snsUrl_exports } from "./snsUrl.mjs";
|
|
5
|
+
import { SnsCertificateUnavailable, SnsCertificateUntrusted, SnsConfirmationFailed, SnsMessageTypeUnknown, SnsNotAConfirmation, SnsSignatureInvalid, SnsSignatureVersionUnknown, confirmSnsSubscription, parseUrl, snsStringToSign, toSnsEvent, verifySnsMessage } from "./message.mjs";
|
|
4
6
|
import { CreateQueueCommand, DeleteQueueCommand, GetQueueAttributesCommand, SQSClient, SetQueueAttributesCommand } from "@aws-sdk/client-sqs";
|
|
5
|
-
import { PublishCommand, SNSClient, SubscribeCommand, UnsubscribeCommand } from "@aws-sdk/client-sns";
|
|
7
|
+
import { ConfirmSubscriptionCommand, GetSubscriptionAttributesCommand, ListSubscriptionsByTopicCommand, PublishCommand, SNSClient, SetSubscriptionAttributesCommand, SubscribeCommand, UnsubscribeCommand } from "@aws-sdk/client-sns";
|
|
6
8
|
//#region src/sns/SNSConnection.ts
|
|
9
|
+
var SNSConnection_exports = /* @__PURE__ */ __exportAll({ SNSConnection: () => SNSConnection });
|
|
7
10
|
var SNSConnection = class SNSConnection {
|
|
8
11
|
type = "sns";
|
|
9
12
|
client;
|
|
@@ -76,26 +79,35 @@ var SNSPublisher = class SNSPublisher {
|
|
|
76
79
|
* Format: sns://?topicArn=arn:aws:sns:region:account:topic®ion=us-east-1&endpoint=http://localhost:4566
|
|
77
80
|
*/
|
|
78
81
|
static async fromConnectionString(connectionString) {
|
|
79
|
-
const { SNSConnection } = await
|
|
82
|
+
const { SNSConnection } = await Promise.resolve().then(() => SNSConnection_exports);
|
|
80
83
|
const connection = await SNSConnection.fromConnectionString(connectionString);
|
|
81
84
|
return new SNSPublisher(connection);
|
|
82
85
|
}
|
|
83
86
|
async publish(messages) {
|
|
84
87
|
if (messages.length === 0) return;
|
|
85
88
|
if (!this.connection.isConnected()) await this.connection.connect();
|
|
86
|
-
|
|
89
|
+
const topicArn = this.connection.topicArn;
|
|
90
|
+
const destination = topicArn.split(":").pop() ?? topicArn;
|
|
91
|
+
await publishTraced(messages, (message) => ({
|
|
92
|
+
system: "aws_sns",
|
|
93
|
+
destination,
|
|
94
|
+
type: message.type
|
|
95
|
+
}), (carriers) => Promise.all(messages.map((message, i) => this.publishMessage(message, carriers[i]))));
|
|
87
96
|
}
|
|
88
|
-
async publishMessage(message) {
|
|
97
|
+
async publishMessage(message, carrier) {
|
|
89
98
|
const command = new PublishCommand({
|
|
90
99
|
TopicArn: this.connection.topicArn,
|
|
91
100
|
Message: JSON.stringify({
|
|
92
101
|
type: message.type,
|
|
93
102
|
payload: message.payload
|
|
94
103
|
}),
|
|
95
|
-
MessageAttributes: {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
MessageAttributes: {
|
|
105
|
+
type: {
|
|
106
|
+
DataType: "String",
|
|
107
|
+
StringValue: message.type
|
|
108
|
+
},
|
|
109
|
+
...carrierAsAttributes(carrier)
|
|
110
|
+
}
|
|
99
111
|
});
|
|
100
112
|
await this.connection.snsClient.send(command);
|
|
101
113
|
}
|
|
@@ -149,7 +161,7 @@ var SNSSubscriber = class SNSSubscriber {
|
|
|
149
161
|
*/
|
|
150
162
|
static async fromConnectionString(connectionString) {
|
|
151
163
|
const params = new URL(connectionString).searchParams;
|
|
152
|
-
const { SNSConnection } = await
|
|
164
|
+
const { SNSConnection } = await Promise.resolve().then(() => SNSConnection_exports);
|
|
153
165
|
const connection = await SNSConnection.fromConnectionString(connectionString);
|
|
154
166
|
const options = {
|
|
155
167
|
queueName: params.get("queueName") || void 0,
|
|
@@ -245,6 +257,216 @@ var SnsQueueMissing = class extends Error {
|
|
|
245
257
|
}
|
|
246
258
|
};
|
|
247
259
|
//#endregion
|
|
248
|
-
|
|
260
|
+
//#region src/sns/driver.ts
|
|
261
|
+
/**
|
|
262
|
+
* `sns://` — an SNS topic, consumed through an SQS queue subscribed to it.
|
|
263
|
+
* Register it with `registerEventsDriver(snsEventsDriver)`; an AWS entry
|
|
264
|
+
* registers `sqsEventsDriver` beside it.
|
|
265
|
+
*/
|
|
266
|
+
const snsEventsDriver = {
|
|
267
|
+
scheme: "sns",
|
|
268
|
+
connect: (url) => SNSConnection.fromConnectionString(url),
|
|
269
|
+
publisher: (url) => SNSPublisher.fromConnectionString(url),
|
|
270
|
+
publisherFor: (connection) => new SNSPublisher(connection),
|
|
271
|
+
subscriber: (url) => SNSSubscriber.fromConnectionString(url),
|
|
272
|
+
subscriberFor: (connection) => new SNSSubscriber(connection)
|
|
273
|
+
};
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/sns/push.ts
|
|
276
|
+
/** The subscription attributes a filter asks for, as SNS spells them. */
|
|
277
|
+
function subscriptionAttributes(filter) {
|
|
278
|
+
const attributes = filter.filterPolicy ? {
|
|
279
|
+
FilterPolicyScope: filter.filterPolicyScope ?? "MessageAttributes",
|
|
280
|
+
FilterPolicy: JSON.stringify(filter.filterPolicy)
|
|
281
|
+
} : filter.events ? {
|
|
282
|
+
FilterPolicyScope: "MessageAttributes",
|
|
283
|
+
FilterPolicy: JSON.stringify({ type: [...filter.events] })
|
|
284
|
+
} : {};
|
|
285
|
+
if (filter.deadLetterQueueArn) attributes.RedrivePolicy = JSON.stringify({ deadLetterTargetArn: filter.deadLetterQueueArn });
|
|
286
|
+
return attributes;
|
|
287
|
+
}
|
|
288
|
+
/** The protocol SNS delivers to an endpoint with, from its URL. */
|
|
289
|
+
function protocolOf(endpoint) {
|
|
290
|
+
const protocol = parseUrl(endpoint)?.protocol.replace(":", "");
|
|
291
|
+
if (protocol !== "http" && protocol !== "https") throw new SnsEndpointNotHttp(endpoint);
|
|
292
|
+
return protocol;
|
|
293
|
+
}
|
|
294
|
+
/** Bring an existing subscription's attributes up to what is asked for. */
|
|
295
|
+
async function updateAttributes(connection, subscriptionArn, current, wanted) {
|
|
296
|
+
for (const [name, value] of Object.entries(wanted)) {
|
|
297
|
+
if (current[name] === value) continue;
|
|
298
|
+
await connection.snsClient.send(new SetSubscriptionAttributesCommand({
|
|
299
|
+
SubscriptionArn: subscriptionArn,
|
|
300
|
+
AttributeName: name,
|
|
301
|
+
AttributeValue: value
|
|
302
|
+
}));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Subscribe an HTTP endpoint to the connection's topic, converging on one
|
|
307
|
+
* confirmed subscription with the filter asked for — so it is safe on every
|
|
308
|
+
* start. What a server does against an emulator, where nothing deploys it;
|
|
309
|
+
* against SNS itself the deploy owns the subscription
|
|
310
|
+
* ({@link reconcileHttpSubscriptions}).
|
|
311
|
+
*
|
|
312
|
+
* - **none yet** — subscribed; SNS sends a confirmation to the endpoint.
|
|
313
|
+
* - **confirmed** — its filter and dead-letter queue are brought up to date.
|
|
314
|
+
* Subscribing again with different attributes is an error on SNS, and the
|
|
315
|
+
* events a subscriber names change.
|
|
316
|
+
* - **stuck pending** — a confirmation that never landed (the endpoint was
|
|
317
|
+
* down, or answered wrong). Subscribing the same endpoint again is a no-op
|
|
318
|
+
* on an emulator, so it is dropped and subscribed afresh, which sends a new
|
|
319
|
+
* confirmation.
|
|
320
|
+
*/
|
|
321
|
+
async function subscribeHttpEndpoint(connection, options) {
|
|
322
|
+
const protocol = protocolOf(options.endpoint);
|
|
323
|
+
const attributes = subscriptionAttributes(options);
|
|
324
|
+
const client = connection.snsClient;
|
|
325
|
+
const existing = (await topicSubscriptions(connection)).find((s) => s.endpoint === options.endpoint)?.arn;
|
|
326
|
+
if (existing) {
|
|
327
|
+
const { Attributes = {} } = await client.send(new GetSubscriptionAttributesCommand({ SubscriptionArn: existing }));
|
|
328
|
+
if (Attributes.PendingConfirmation === "true") await client.send(new UnsubscribeCommand({ SubscriptionArn: existing }));
|
|
329
|
+
else {
|
|
330
|
+
await updateAttributes(connection, existing, Attributes, attributes);
|
|
331
|
+
return existing;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const { SubscriptionArn } = await client.send(new SubscribeCommand({
|
|
335
|
+
TopicArn: connection.topicArn,
|
|
336
|
+
Protocol: protocol,
|
|
337
|
+
Endpoint: options.endpoint,
|
|
338
|
+
Attributes: attributes,
|
|
339
|
+
ReturnSubscriptionArn: true
|
|
340
|
+
}));
|
|
341
|
+
return SubscriptionArn;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Converge a topic's HTTP subscriptions on the endpoints a deploy wants, and
|
|
345
|
+
* answer each one's ARN for the deploy to record and hand to the server.
|
|
346
|
+
*
|
|
347
|
+
* The deploy's half of push delivery against SNS itself: the server never
|
|
348
|
+
* subscribes, so its credentials need no `sns:Subscribe` — and the only
|
|
349
|
+
* subscriptions to the topic are ones the deploy made.
|
|
350
|
+
*
|
|
351
|
+
* Run it twice: once before the server starts, for the ARNs it is configured
|
|
352
|
+
* with — SNS answers one even while the subscription waits to be confirmed —
|
|
353
|
+
* and once the server is up, which subscribes each still-pending endpoint
|
|
354
|
+
* again so SNS resends its confirmation to a server now there to answer it.
|
|
355
|
+
* The ARN does not change between the two.
|
|
356
|
+
*
|
|
357
|
+
* - **absent** — subscribed with its filter.
|
|
358
|
+
* - **present** — its filter and dead-letter queue are brought up to date;
|
|
359
|
+
* pending, it is subscribed again to resend the confirmation.
|
|
360
|
+
* - **stale** — on {@link ReconcileHttpSubscriptionsOptions.ownedHost} and no
|
|
361
|
+
* longer wanted: unsubscribed. (A stale one SNS still lists as pending has
|
|
362
|
+
* no ARN to act on; SNS drops it unconfirmed after three days.)
|
|
363
|
+
*/
|
|
364
|
+
async function reconcileHttpSubscriptions(connection, options) {
|
|
365
|
+
const client = connection.snsClient;
|
|
366
|
+
const listed = await topicSubscriptions(connection);
|
|
367
|
+
const result = {
|
|
368
|
+
subscriptions: {},
|
|
369
|
+
pending: [],
|
|
370
|
+
removed: []
|
|
371
|
+
};
|
|
372
|
+
for (const spec of options.endpoints) {
|
|
373
|
+
const protocol = protocolOf(spec.endpoint);
|
|
374
|
+
const attributes = subscriptionAttributes(spec);
|
|
375
|
+
const subscribe = async () => (await client.send(new SubscribeCommand({
|
|
376
|
+
TopicArn: connection.topicArn,
|
|
377
|
+
Protocol: protocol,
|
|
378
|
+
Endpoint: spec.endpoint,
|
|
379
|
+
Attributes: attributes,
|
|
380
|
+
ReturnSubscriptionArn: true
|
|
381
|
+
}))).SubscriptionArn;
|
|
382
|
+
const existing = listed.find((s) => s.endpoint === spec.endpoint)?.arn;
|
|
383
|
+
let arn;
|
|
384
|
+
let pending;
|
|
385
|
+
if (existing) {
|
|
386
|
+
const { Attributes = {} } = await client.send(new GetSubscriptionAttributesCommand({ SubscriptionArn: existing }));
|
|
387
|
+
await updateAttributes(connection, existing, Attributes, attributes);
|
|
388
|
+
pending = Attributes.PendingConfirmation === "true";
|
|
389
|
+
arn = pending ? await subscribe() ?? existing : existing;
|
|
390
|
+
} else {
|
|
391
|
+
arn = await subscribe();
|
|
392
|
+
pending = true;
|
|
393
|
+
}
|
|
394
|
+
if (!arn) throw new SnsSubscriptionArnMissing(connection.topicArn, spec.endpoint);
|
|
395
|
+
result.subscriptions[spec.name] = arn;
|
|
396
|
+
if (pending) result.pending.push(spec.name);
|
|
397
|
+
}
|
|
398
|
+
const wanted = new Set(options.endpoints.map((spec) => spec.endpoint));
|
|
399
|
+
for (const { arn, endpoint } of listed) {
|
|
400
|
+
if (!arn || wanted.has(endpoint)) continue;
|
|
401
|
+
if (parseUrl(endpoint)?.host !== options.ownedHost) continue;
|
|
402
|
+
await client.send(new UnsubscribeCommand({ SubscriptionArn: arn }));
|
|
403
|
+
result.removed.push(arn);
|
|
404
|
+
}
|
|
405
|
+
return result;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Confirm a subscription through the API, as its topic's owner, rather than by
|
|
409
|
+
* visiting the URL SNS sent.
|
|
410
|
+
*
|
|
411
|
+
* `AuthenticateOnUnsubscribe` is the point of it. A subscription confirmed by
|
|
412
|
+
* visiting `SubscribeURL` can be removed by anyone holding the
|
|
413
|
+
* `UnsubscribeURL` every notification carries — one unauthenticated GET, and
|
|
414
|
+
* the endpoint is silently cut off. Confirmed this way, only the topic's owner
|
|
415
|
+
* can unsubscribe it. All it takes of the caller's credentials is
|
|
416
|
+
* `sns:ConfirmSubscription` on this one topic.
|
|
417
|
+
*/
|
|
418
|
+
async function confirmSubscription(connection, message) {
|
|
419
|
+
if (message.Type !== "SubscriptionConfirmation" || !message.Token) throw new SnsNotAConfirmation(message.Type);
|
|
420
|
+
const { SubscriptionArn } = await connection.snsClient.send(new ConfirmSubscriptionCommand({
|
|
421
|
+
TopicArn: message.TopicArn,
|
|
422
|
+
Token: message.Token,
|
|
423
|
+
AuthenticateOnUnsubscribe: "true"
|
|
424
|
+
}));
|
|
425
|
+
return SubscriptionArn;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Every subscription on the connection's topic, with the ARN SNS names for it
|
|
429
|
+
* — none for one real SNS lists as `PendingConfirmation`, which there is no
|
|
430
|
+
* ARN to act on (and which a new Subscribe resends the confirmation of anyway).
|
|
431
|
+
*/
|
|
432
|
+
async function topicSubscriptions(connection) {
|
|
433
|
+
const found = [];
|
|
434
|
+
let NextToken;
|
|
435
|
+
do {
|
|
436
|
+
const page = await connection.snsClient.send(new ListSubscriptionsByTopicCommand({
|
|
437
|
+
TopicArn: connection.topicArn,
|
|
438
|
+
NextToken
|
|
439
|
+
}));
|
|
440
|
+
for (const s of page.Subscriptions ?? []) {
|
|
441
|
+
if (!s.Endpoint) continue;
|
|
442
|
+
found.push({
|
|
443
|
+
endpoint: s.Endpoint,
|
|
444
|
+
...s.SubscriptionArn?.startsWith("arn:") ? { arn: s.SubscriptionArn } : {}
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
NextToken = page.NextToken;
|
|
448
|
+
} while (NextToken);
|
|
449
|
+
return found;
|
|
450
|
+
}
|
|
451
|
+
var SnsEndpointNotHttp = class extends Error {
|
|
452
|
+
endpoint;
|
|
453
|
+
constructor(endpoint) {
|
|
454
|
+
super(`'${endpoint}' is not an http(s) URL. SNS pushes to an HTTP endpoint; subscribe a queue for anything else.`);
|
|
455
|
+
this.endpoint = endpoint;
|
|
456
|
+
this.name = "SnsEndpointNotHttp";
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
var SnsSubscriptionArnMissing = class extends Error {
|
|
460
|
+
topicArn;
|
|
461
|
+
endpoint;
|
|
462
|
+
constructor(topicArn, endpoint) {
|
|
463
|
+
super(`Subscribing '${endpoint}' to '${topicArn}' answered no subscription ARN, so there is nothing to record for the server to accept. Check the topic exists and the deploy may subscribe to it.`);
|
|
464
|
+
this.topicArn = topicArn;
|
|
465
|
+
this.endpoint = endpoint;
|
|
466
|
+
this.name = "SnsSubscriptionArnMissing";
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
//#endregion
|
|
470
|
+
export { SNSConnection, SNSPublisher, SNSSubscriber, SnsCertificateUnavailable, SnsCertificateUntrusted, SnsConfirmationFailed, SnsEndpointNotHttp, SnsMessageTypeUnknown, SnsNotAConfirmation, SnsQueueMissing, SnsSignatureInvalid, SnsSignatureVersionUnknown, SnsSubscriptionArnMissing, confirmSnsSubscription, confirmSubscription, reconcileHttpSubscriptions, snsEventsDriver, snsStringToSign, snsUrl_exports as snsUrl, subscribeHttpEndpoint, toSnsEvent, verifySnsMessage };
|
|
249
471
|
|
|
250
472
|
//# sourceMappingURL=index.mjs.map
|