sst-http 2.0.0-beta.1 → 2.0.0-beta.6
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 +3 -7
- package/dist/http/index.d.cts +2 -2
- package/dist/http/index.d.ts +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/infra.cjs +21 -69
- package/dist/infra.d.cts +4 -23
- package/dist/infra.d.ts +4 -23
- package/dist/infra.js +20 -67
- package/dist/{types-w1A7o_rd.d.cts → types-o33yWNSY.d.cts} +1 -1
- package/dist/{types-w1A7o_rd.d.ts → types-o33yWNSY.d.ts} +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -113,7 +113,7 @@ Helpers such as `json()`, `text()`, and `noContent()` are available for concise
|
|
|
113
113
|
|
|
114
114
|
## Event bus
|
|
115
115
|
|
|
116
|
-
Use `@On()` to register EventBridge handlers and `publish()` to emit events.
|
|
116
|
+
Use `@On()` to register EventBridge handlers and `publish()` to emit events. Handlers decorated with `@On()` are automatically subscribed to the default EventBridge bus when you call `wireApiFromManifest()` with a manifest that includes events.
|
|
117
117
|
|
|
118
118
|
```ts
|
|
119
119
|
// src/events/user-events.ts
|
|
@@ -158,7 +158,7 @@ Optional roles and optional-auth flags flow into the adapter so you can fine-tun
|
|
|
158
158
|
|
|
159
159
|
## Wire API Gateway + EventBridge
|
|
160
160
|
|
|
161
|
-
`sst-http/infra` ships with a manifest-driven wiring utility plus adapters for HTTP API (ApiGatewayV2) and REST API (ApiGateway). The example below wires all routes to a single Lambda function inside `sst.config.ts` and connects event subscriptions from the same manifest.
|
|
161
|
+
`sst-http/infra` ships with a manifest-driven wiring utility plus adapters for HTTP API (ApiGatewayV2) and REST API (ApiGateway). The example below wires all routes to a single Lambda function inside `sst.config.ts` and automatically connects event subscriptions from the same manifest.
|
|
162
162
|
|
|
163
163
|
```ts
|
|
164
164
|
// sst.config.ts
|
|
@@ -171,7 +171,6 @@ export default $config({
|
|
|
171
171
|
loadRoutesManifest,
|
|
172
172
|
wireApiFromManifest,
|
|
173
173
|
httpApiAdapter,
|
|
174
|
-
createBus,
|
|
175
174
|
} = await import("sst-http/infra");
|
|
176
175
|
|
|
177
176
|
const manifest = loadRoutesManifest("routes.manifest.json");
|
|
@@ -184,14 +183,11 @@ export default $config({
|
|
|
184
183
|
memory: "512 MB",
|
|
185
184
|
});
|
|
186
185
|
|
|
187
|
-
const bus = createBus();
|
|
188
|
-
|
|
189
186
|
wireApiFromManifest(manifest, {
|
|
190
187
|
handler,
|
|
191
188
|
firebaseProjectId: process.env.FIREBASE_PROJECT_ID!,
|
|
192
189
|
registerRoute,
|
|
193
190
|
ensureJwtAuthorizer,
|
|
194
|
-
buses: [bus],
|
|
195
191
|
});
|
|
196
192
|
|
|
197
193
|
return { ApiUrl: api.url };
|
|
@@ -199,7 +195,7 @@ export default $config({
|
|
|
199
195
|
});
|
|
200
196
|
```
|
|
201
197
|
|
|
202
|
-
Swap in `restApiAdapter` if you prefer API Gateway REST APIs—the wiring contract is identical.
|
|
198
|
+
When the manifest contains events (from `@On()` decorators), handlers are automatically subscribed to the default EventBridge bus. Swap in `restApiAdapter` if you prefer API Gateway REST APIs—the wiring contract is identical.
|
|
203
199
|
|
|
204
200
|
## Publishing
|
|
205
201
|
|
package/dist/http/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyResultV2 } from 'aws-lambda';
|
|
2
|
-
import { R as ResponseLike, F as FirebaseAuthOptions, e as RouteOptions } from '../types-
|
|
3
|
-
export { c as FirebaseAuthMetadata, d as FirebaseClaims, H as Handler, a as HandlerContext, b as HttpMethod } from '../types-
|
|
2
|
+
import { R as ResponseLike, F as FirebaseAuthOptions, e as RouteOptions } from '../types-o33yWNSY.cjs';
|
|
3
|
+
export { c as FirebaseAuthMetadata, d as FirebaseClaims, H as Handler, a as HandlerContext, b as HttpMethod } from '../types-o33yWNSY.cjs';
|
|
4
4
|
import { ZodTypeAny } from 'zod/v4';
|
|
5
5
|
import { L as LegacyDecorator, a as LegacyParameterDecorator } from '../handler-DaM4Racx.cjs';
|
|
6
6
|
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyResultV2 } from 'aws-lambda';
|
|
2
|
-
import { R as ResponseLike, F as FirebaseAuthOptions, e as RouteOptions } from '../types-
|
|
3
|
-
export { c as FirebaseAuthMetadata, d as FirebaseClaims, H as Handler, a as HandlerContext, b as HttpMethod } from '../types-
|
|
2
|
+
import { R as ResponseLike, F as FirebaseAuthOptions, e as RouteOptions } from '../types-o33yWNSY.js';
|
|
3
|
+
export { c as FirebaseAuthMetadata, d as FirebaseClaims, H as Handler, a as HandlerContext, b as HttpMethod } from '../types-o33yWNSY.js';
|
|
4
4
|
import { ZodTypeAny } from 'zod/v4';
|
|
5
5
|
import { L as LegacyDecorator, a as LegacyParameterDecorator } from '../handler-DaM4Racx.js';
|
|
6
6
|
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Auth, Body, Delete, FirebaseAuth, Get, Head, Header, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, configureRoutes, createHandler, handleError, json, noContent, text } from './http/index.cjs';
|
|
2
|
-
export { c as FirebaseAuthMetadata, F as FirebaseAuthOptions, d as FirebaseClaims, H as Handler, a as HandlerContext, b as HttpMethod, R as ResponseLike, e as RouteOptions } from './types-
|
|
2
|
+
export { c as FirebaseAuthMetadata, F as FirebaseAuthOptions, d as FirebaseClaims, H as Handler, a as HandlerContext, b as HttpMethod, R as ResponseLike, e as RouteOptions } from './types-o33yWNSY.cjs';
|
|
3
3
|
export { On, publish } from './bus/index.cjs';
|
|
4
4
|
import 'aws-lambda';
|
|
5
5
|
import 'zod/v4';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Auth, Body, Delete, FirebaseAuth, Get, Head, Header, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, configureRoutes, createHandler, handleError, json, noContent, text } from './http/index.js';
|
|
2
|
-
export { c as FirebaseAuthMetadata, F as FirebaseAuthOptions, d as FirebaseClaims, H as Handler, a as HandlerContext, b as HttpMethod, R as ResponseLike, e as RouteOptions } from './types-
|
|
2
|
+
export { c as FirebaseAuthMetadata, F as FirebaseAuthOptions, d as FirebaseClaims, H as Handler, a as HandlerContext, b as HttpMethod, R as ResponseLike, e as RouteOptions } from './types-o33yWNSY.js';
|
|
3
3
|
export { On, publish } from './bus/index.js';
|
|
4
4
|
import 'aws-lambda';
|
|
5
5
|
import 'zod/v4';
|
package/dist/infra.cjs
CHANGED
|
@@ -20,11 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/infra.ts
|
|
21
21
|
var infra_exports = {};
|
|
22
22
|
__export(infra_exports, {
|
|
23
|
-
createBus: () => createBus,
|
|
24
|
-
getBus: () => getBus,
|
|
25
23
|
httpApiAdapter: () => httpApiAdapter,
|
|
26
24
|
loadRoutesManifest: () => loadRoutesManifest,
|
|
27
25
|
restApiAdapter: () => restApiAdapter,
|
|
26
|
+
setHandlerBus: () => setHandlerBus,
|
|
28
27
|
wireApiFromManifest: () => wireApiFromManifest
|
|
29
28
|
});
|
|
30
29
|
module.exports = __toCommonJS(infra_exports);
|
|
@@ -42,13 +41,6 @@ function getFunction(value, key) {
|
|
|
42
41
|
const candidate = value[key];
|
|
43
42
|
return typeof candidate === "function" ? candidate : void 0;
|
|
44
43
|
}
|
|
45
|
-
function getStringProp(value, key) {
|
|
46
|
-
if (!isRecord(value)) {
|
|
47
|
-
return void 0;
|
|
48
|
-
}
|
|
49
|
-
const candidate = value[key];
|
|
50
|
-
return typeof candidate === "string" && candidate.length > 0 ? candidate : void 0;
|
|
51
|
-
}
|
|
52
44
|
function ensureRecord(value, message) {
|
|
53
45
|
if (!isRecord(value)) {
|
|
54
46
|
throw new Error(message);
|
|
@@ -85,20 +77,11 @@ function resolveHandlerInput(handler) {
|
|
|
85
77
|
|
|
86
78
|
// src/bus/infra.ts
|
|
87
79
|
var MAX_SUBSCRIBER_NAME_LENGTH = 60;
|
|
88
|
-
function createBus() {
|
|
89
|
-
const aws = ensureSstAws();
|
|
90
|
-
return new aws.Bus("default");
|
|
91
|
-
}
|
|
92
|
-
function getBus() {
|
|
93
|
-
const aws = ensureSstAws();
|
|
94
|
-
return aws.Bus.get("default", "default");
|
|
95
|
-
}
|
|
96
80
|
function wireEventsFromManifest(events, opts) {
|
|
97
81
|
if (!events || events.length === 0) {
|
|
98
82
|
return;
|
|
99
83
|
}
|
|
100
84
|
const aws = ensureSstAws(opts.source);
|
|
101
|
-
const busMap = normalizeBusInput(opts.buses);
|
|
102
85
|
const subscriber = resolveHandlerInput(opts.handler);
|
|
103
86
|
const seen = /* @__PURE__ */ new Set();
|
|
104
87
|
for (const event of events) {
|
|
@@ -107,57 +90,11 @@ function wireEventsFromManifest(events, opts) {
|
|
|
107
90
|
continue;
|
|
108
91
|
}
|
|
109
92
|
seen.add(key);
|
|
110
|
-
const bus =
|
|
93
|
+
const bus = aws.Bus.get("default", "default");
|
|
111
94
|
const subscriberName = buildSubscriberName(event.event);
|
|
112
95
|
subscribeToBus(bus, subscriberName, subscriber, event.event);
|
|
113
96
|
}
|
|
114
97
|
}
|
|
115
|
-
function normalizeBusInput(input) {
|
|
116
|
-
if (!input) {
|
|
117
|
-
return void 0;
|
|
118
|
-
}
|
|
119
|
-
const map = /* @__PURE__ */ new Map();
|
|
120
|
-
if (Array.isArray(input)) {
|
|
121
|
-
for (const bus of input) {
|
|
122
|
-
const key2 = getBusKey(bus);
|
|
123
|
-
if (key2) {
|
|
124
|
-
map.set(key2, bus);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (map.size === 1 && !map.has("default")) {
|
|
128
|
-
const [bus] = map.values();
|
|
129
|
-
map.set("default", bus);
|
|
130
|
-
}
|
|
131
|
-
return map;
|
|
132
|
-
}
|
|
133
|
-
if (isBusRecord(input)) {
|
|
134
|
-
for (const [key2, bus] of Object.entries(input)) {
|
|
135
|
-
map.set(key2, bus);
|
|
136
|
-
}
|
|
137
|
-
return map;
|
|
138
|
-
}
|
|
139
|
-
const key = getBusKey(input) ?? "default";
|
|
140
|
-
map.set(key, input);
|
|
141
|
-
return map;
|
|
142
|
-
}
|
|
143
|
-
function isBusRecord(input) {
|
|
144
|
-
return !Array.isArray(input) && isRecord(input) && !("subscribe" in input);
|
|
145
|
-
}
|
|
146
|
-
function getBusKey(bus) {
|
|
147
|
-
return getStringProp(bus, "name") ?? getStringProp(bus, "constructorName");
|
|
148
|
-
}
|
|
149
|
-
function resolveBusForEvent(busMap, aws) {
|
|
150
|
-
if (busMap && busMap.size > 0) {
|
|
151
|
-
const direct = busMap.get("default");
|
|
152
|
-
if (direct) {
|
|
153
|
-
return direct;
|
|
154
|
-
}
|
|
155
|
-
if (busMap.size === 1) {
|
|
156
|
-
return busMap.values().next().value;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return aws.Bus.get("default", "default");
|
|
160
|
-
}
|
|
161
98
|
function subscribeToBus(bus, subscriberName, subscriber, eventName) {
|
|
162
99
|
if (typeof bus.subscribe !== "function") {
|
|
163
100
|
throw new Error("Bus instance does not support subscribe().");
|
|
@@ -372,6 +309,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
372
309
|
if (!manifest || !Array.isArray(manifest.routes)) {
|
|
373
310
|
throw new Error("Invalid routes manifest");
|
|
374
311
|
}
|
|
312
|
+
setHandlerBus(opts.handler);
|
|
375
313
|
wireRoutesFromManifest(manifest, {
|
|
376
314
|
handler: opts.handler,
|
|
377
315
|
firebaseProjectId: opts.firebaseProjectId,
|
|
@@ -379,8 +317,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
379
317
|
ensureJwtAuthorizer: opts.ensureJwtAuthorizer
|
|
380
318
|
});
|
|
381
319
|
wireEventsFromManifest(manifest.events, {
|
|
382
|
-
handler: opts.handler
|
|
383
|
-
buses: opts.buses
|
|
320
|
+
handler: opts.handler
|
|
384
321
|
});
|
|
385
322
|
}
|
|
386
323
|
function loadRoutesManifest(filePath) {
|
|
@@ -392,12 +329,27 @@ function loadRoutesManifest(filePath) {
|
|
|
392
329
|
}
|
|
393
330
|
return manifest;
|
|
394
331
|
}
|
|
332
|
+
function setHandlerBus(handler) {
|
|
333
|
+
const aws = ensureSstAws();
|
|
334
|
+
new aws.iam.RolePolicy("PublisherHandlerPolicy", {
|
|
335
|
+
role: handler.nodes.role.name,
|
|
336
|
+
policy: {
|
|
337
|
+
Version: "2012-10-17",
|
|
338
|
+
Statement: [
|
|
339
|
+
{
|
|
340
|
+
Action: ["events:PutEvents"],
|
|
341
|
+
Resource: ["*"],
|
|
342
|
+
Effect: "Allow"
|
|
343
|
+
}
|
|
344
|
+
]
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}
|
|
395
348
|
// Annotate the CommonJS export names for ESM import in node:
|
|
396
349
|
0 && (module.exports = {
|
|
397
|
-
createBus,
|
|
398
|
-
getBus,
|
|
399
350
|
httpApiAdapter,
|
|
400
351
|
loadRoutesManifest,
|
|
401
352
|
restApiAdapter,
|
|
353
|
+
setHandlerBus,
|
|
402
354
|
wireApiFromManifest
|
|
403
355
|
});
|
package/dist/infra.d.cts
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { b as HttpMethod, f as RoutesManifest } from './types-o33yWNSY.cjs';
|
|
2
|
+
export { h as RoutesManifestAuth, i as RoutesManifestEvent, g as RoutesManifestRoute } from './types-o33yWNSY.cjs';
|
|
3
3
|
import 'aws-lambda';
|
|
4
4
|
|
|
5
|
-
type BusSubscriberArgs = {
|
|
6
|
-
pattern?: {
|
|
7
|
-
detailType?: string[];
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
type BusLike = {
|
|
11
|
-
name?: unknown;
|
|
12
|
-
arn?: unknown;
|
|
13
|
-
subscribe: (name: string, subscriber: unknown, args?: BusSubscriberArgs) => unknown;
|
|
14
|
-
};
|
|
15
5
|
type AwsSource = {
|
|
16
6
|
sst?: {
|
|
17
7
|
aws?: unknown;
|
|
18
8
|
};
|
|
19
9
|
};
|
|
20
10
|
|
|
21
|
-
type BusInput = BusLike | BusLike[] | Record<string, BusLike>;
|
|
22
|
-
declare function createBus(): BusLike;
|
|
23
|
-
declare function getBus(): BusLike;
|
|
24
|
-
declare function wireEventsFromManifest(events: RoutesManifestEvent[] | undefined, opts: {
|
|
25
|
-
handler: unknown;
|
|
26
|
-
buses?: BusInput;
|
|
27
|
-
source?: AwsSource;
|
|
28
|
-
}): void;
|
|
29
|
-
|
|
30
11
|
type RegisterRouteConfig = {
|
|
31
12
|
handler: unknown;
|
|
32
13
|
protected: boolean;
|
|
@@ -63,8 +44,8 @@ declare function wireApiFromManifest(manifest: RoutesManifest, opts: {
|
|
|
63
44
|
firebaseProjectId: string;
|
|
64
45
|
registerRoute: RegisterRoute;
|
|
65
46
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
66
|
-
buses?: Parameters<typeof wireEventsFromManifest>[1]["buses"];
|
|
67
47
|
}): void;
|
|
68
48
|
declare function loadRoutesManifest(filePath: string): RoutesManifest;
|
|
49
|
+
declare function setHandlerBus(handler: unknown): void;
|
|
69
50
|
|
|
70
|
-
export { type EnsureJwtAuthorizer, type RegisterRoute, type RegisterRouteConfig, RoutesManifest,
|
|
51
|
+
export { type EnsureJwtAuthorizer, type RegisterRoute, type RegisterRouteConfig, RoutesManifest, httpApiAdapter, loadRoutesManifest, restApiAdapter, setHandlerBus, wireApiFromManifest };
|
package/dist/infra.d.ts
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { b as HttpMethod, f as RoutesManifest } from './types-o33yWNSY.js';
|
|
2
|
+
export { h as RoutesManifestAuth, i as RoutesManifestEvent, g as RoutesManifestRoute } from './types-o33yWNSY.js';
|
|
3
3
|
import 'aws-lambda';
|
|
4
4
|
|
|
5
|
-
type BusSubscriberArgs = {
|
|
6
|
-
pattern?: {
|
|
7
|
-
detailType?: string[];
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
type BusLike = {
|
|
11
|
-
name?: unknown;
|
|
12
|
-
arn?: unknown;
|
|
13
|
-
subscribe: (name: string, subscriber: unknown, args?: BusSubscriberArgs) => unknown;
|
|
14
|
-
};
|
|
15
5
|
type AwsSource = {
|
|
16
6
|
sst?: {
|
|
17
7
|
aws?: unknown;
|
|
18
8
|
};
|
|
19
9
|
};
|
|
20
10
|
|
|
21
|
-
type BusInput = BusLike | BusLike[] | Record<string, BusLike>;
|
|
22
|
-
declare function createBus(): BusLike;
|
|
23
|
-
declare function getBus(): BusLike;
|
|
24
|
-
declare function wireEventsFromManifest(events: RoutesManifestEvent[] | undefined, opts: {
|
|
25
|
-
handler: unknown;
|
|
26
|
-
buses?: BusInput;
|
|
27
|
-
source?: AwsSource;
|
|
28
|
-
}): void;
|
|
29
|
-
|
|
30
11
|
type RegisterRouteConfig = {
|
|
31
12
|
handler: unknown;
|
|
32
13
|
protected: boolean;
|
|
@@ -63,8 +44,8 @@ declare function wireApiFromManifest(manifest: RoutesManifest, opts: {
|
|
|
63
44
|
firebaseProjectId: string;
|
|
64
45
|
registerRoute: RegisterRoute;
|
|
65
46
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
66
|
-
buses?: Parameters<typeof wireEventsFromManifest>[1]["buses"];
|
|
67
47
|
}): void;
|
|
68
48
|
declare function loadRoutesManifest(filePath: string): RoutesManifest;
|
|
49
|
+
declare function setHandlerBus(handler: unknown): void;
|
|
69
50
|
|
|
70
|
-
export { type EnsureJwtAuthorizer, type RegisterRoute, type RegisterRouteConfig, RoutesManifest,
|
|
51
|
+
export { type EnsureJwtAuthorizer, type RegisterRoute, type RegisterRouteConfig, RoutesManifest, httpApiAdapter, loadRoutesManifest, restApiAdapter, setHandlerBus, wireApiFromManifest };
|
package/dist/infra.js
CHANGED
|
@@ -17,13 +17,6 @@ function getFunction(value, key) {
|
|
|
17
17
|
const candidate = value[key];
|
|
18
18
|
return typeof candidate === "function" ? candidate : void 0;
|
|
19
19
|
}
|
|
20
|
-
function getStringProp(value, key) {
|
|
21
|
-
if (!isRecord(value)) {
|
|
22
|
-
return void 0;
|
|
23
|
-
}
|
|
24
|
-
const candidate = value[key];
|
|
25
|
-
return typeof candidate === "string" && candidate.length > 0 ? candidate : void 0;
|
|
26
|
-
}
|
|
27
20
|
function ensureRecord(value, message) {
|
|
28
21
|
if (!isRecord(value)) {
|
|
29
22
|
throw new Error(message);
|
|
@@ -60,20 +53,11 @@ function resolveHandlerInput(handler) {
|
|
|
60
53
|
|
|
61
54
|
// src/bus/infra.ts
|
|
62
55
|
var MAX_SUBSCRIBER_NAME_LENGTH = 60;
|
|
63
|
-
function createBus() {
|
|
64
|
-
const aws = ensureSstAws();
|
|
65
|
-
return new aws.Bus("default");
|
|
66
|
-
}
|
|
67
|
-
function getBus() {
|
|
68
|
-
const aws = ensureSstAws();
|
|
69
|
-
return aws.Bus.get("default", "default");
|
|
70
|
-
}
|
|
71
56
|
function wireEventsFromManifest(events, opts) {
|
|
72
57
|
if (!events || events.length === 0) {
|
|
73
58
|
return;
|
|
74
59
|
}
|
|
75
60
|
const aws = ensureSstAws(opts.source);
|
|
76
|
-
const busMap = normalizeBusInput(opts.buses);
|
|
77
61
|
const subscriber = resolveHandlerInput(opts.handler);
|
|
78
62
|
const seen = /* @__PURE__ */ new Set();
|
|
79
63
|
for (const event of events) {
|
|
@@ -82,57 +66,11 @@ function wireEventsFromManifest(events, opts) {
|
|
|
82
66
|
continue;
|
|
83
67
|
}
|
|
84
68
|
seen.add(key);
|
|
85
|
-
const bus =
|
|
69
|
+
const bus = aws.Bus.get("default", "default");
|
|
86
70
|
const subscriberName = buildSubscriberName(event.event);
|
|
87
71
|
subscribeToBus(bus, subscriberName, subscriber, event.event);
|
|
88
72
|
}
|
|
89
73
|
}
|
|
90
|
-
function normalizeBusInput(input) {
|
|
91
|
-
if (!input) {
|
|
92
|
-
return void 0;
|
|
93
|
-
}
|
|
94
|
-
const map = /* @__PURE__ */ new Map();
|
|
95
|
-
if (Array.isArray(input)) {
|
|
96
|
-
for (const bus of input) {
|
|
97
|
-
const key2 = getBusKey(bus);
|
|
98
|
-
if (key2) {
|
|
99
|
-
map.set(key2, bus);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (map.size === 1 && !map.has("default")) {
|
|
103
|
-
const [bus] = map.values();
|
|
104
|
-
map.set("default", bus);
|
|
105
|
-
}
|
|
106
|
-
return map;
|
|
107
|
-
}
|
|
108
|
-
if (isBusRecord(input)) {
|
|
109
|
-
for (const [key2, bus] of Object.entries(input)) {
|
|
110
|
-
map.set(key2, bus);
|
|
111
|
-
}
|
|
112
|
-
return map;
|
|
113
|
-
}
|
|
114
|
-
const key = getBusKey(input) ?? "default";
|
|
115
|
-
map.set(key, input);
|
|
116
|
-
return map;
|
|
117
|
-
}
|
|
118
|
-
function isBusRecord(input) {
|
|
119
|
-
return !Array.isArray(input) && isRecord(input) && !("subscribe" in input);
|
|
120
|
-
}
|
|
121
|
-
function getBusKey(bus) {
|
|
122
|
-
return getStringProp(bus, "name") ?? getStringProp(bus, "constructorName");
|
|
123
|
-
}
|
|
124
|
-
function resolveBusForEvent(busMap, aws) {
|
|
125
|
-
if (busMap && busMap.size > 0) {
|
|
126
|
-
const direct = busMap.get("default");
|
|
127
|
-
if (direct) {
|
|
128
|
-
return direct;
|
|
129
|
-
}
|
|
130
|
-
if (busMap.size === 1) {
|
|
131
|
-
return busMap.values().next().value;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return aws.Bus.get("default", "default");
|
|
135
|
-
}
|
|
136
74
|
function subscribeToBus(bus, subscriberName, subscriber, eventName) {
|
|
137
75
|
if (typeof bus.subscribe !== "function") {
|
|
138
76
|
throw new Error("Bus instance does not support subscribe().");
|
|
@@ -341,6 +279,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
341
279
|
if (!manifest || !Array.isArray(manifest.routes)) {
|
|
342
280
|
throw new Error("Invalid routes manifest");
|
|
343
281
|
}
|
|
282
|
+
setHandlerBus(opts.handler);
|
|
344
283
|
wireRoutesFromManifest(manifest, {
|
|
345
284
|
handler: opts.handler,
|
|
346
285
|
firebaseProjectId: opts.firebaseProjectId,
|
|
@@ -348,8 +287,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
348
287
|
ensureJwtAuthorizer: opts.ensureJwtAuthorizer
|
|
349
288
|
});
|
|
350
289
|
wireEventsFromManifest(manifest.events, {
|
|
351
|
-
handler: opts.handler
|
|
352
|
-
buses: opts.buses
|
|
290
|
+
handler: opts.handler
|
|
353
291
|
});
|
|
354
292
|
}
|
|
355
293
|
function loadRoutesManifest(filePath) {
|
|
@@ -361,11 +299,26 @@ function loadRoutesManifest(filePath) {
|
|
|
361
299
|
}
|
|
362
300
|
return manifest;
|
|
363
301
|
}
|
|
302
|
+
function setHandlerBus(handler) {
|
|
303
|
+
const aws = ensureSstAws();
|
|
304
|
+
new aws.iam.RolePolicy("PublisherHandlerPolicy", {
|
|
305
|
+
role: handler.nodes.role.name,
|
|
306
|
+
policy: {
|
|
307
|
+
Version: "2012-10-17",
|
|
308
|
+
Statement: [
|
|
309
|
+
{
|
|
310
|
+
Action: ["events:PutEvents"],
|
|
311
|
+
Resource: ["*"],
|
|
312
|
+
Effect: "Allow"
|
|
313
|
+
}
|
|
314
|
+
]
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
364
318
|
export {
|
|
365
|
-
createBus,
|
|
366
|
-
getBus,
|
|
367
319
|
httpApiAdapter,
|
|
368
320
|
loadRoutesManifest,
|
|
369
321
|
restApiAdapter,
|
|
322
|
+
setHandlerBus,
|
|
370
323
|
wireApiFromManifest
|
|
371
324
|
};
|
|
@@ -55,4 +55,4 @@ type RoutesManifest = {
|
|
|
55
55
|
events?: RoutesManifestEvent[];
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
export type { FirebaseAuthOptions as F, Handler as H, ResponseLike as R, HandlerContext as a, HttpMethod as b, FirebaseAuthMetadata as c, FirebaseClaims as d, RouteOptions as e,
|
|
58
|
+
export type { FirebaseAuthOptions as F, Handler as H, ResponseLike as R, HandlerContext as a, HttpMethod as b, FirebaseAuthMetadata as c, FirebaseClaims as d, RouteOptions as e, RoutesManifest as f, RoutesManifestRoute as g, RoutesManifestAuth as h, RoutesManifestEvent as i };
|
|
@@ -55,4 +55,4 @@ type RoutesManifest = {
|
|
|
55
55
|
events?: RoutesManifestEvent[];
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
export type { FirebaseAuthOptions as F, Handler as H, ResponseLike as R, HandlerContext as a, HttpMethod as b, FirebaseAuthMetadata as c, FirebaseClaims as d, RouteOptions as e,
|
|
58
|
+
export type { FirebaseAuthOptions as F, Handler as H, ResponseLike as R, HandlerContext as a, HttpMethod as b, FirebaseAuthMetadata as c, FirebaseClaims as d, RouteOptions as e, RoutesManifest as f, RoutesManifestRoute as g, RoutesManifestAuth as h, RoutesManifestEvent as i };
|