sst-http 2.0.0-beta.4 → 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 -63
- package/dist/infra.d.cts +4 -22
- package/dist/infra.d.ts +4 -22
- package/dist/infra.js +20 -62
- 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
|
-
getBus,
|
|
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 = getBus();
|
|
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,10 +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
|
-
getBus: () => getBus,
|
|
24
23
|
httpApiAdapter: () => httpApiAdapter,
|
|
25
24
|
loadRoutesManifest: () => loadRoutesManifest,
|
|
26
25
|
restApiAdapter: () => restApiAdapter,
|
|
26
|
+
setHandlerBus: () => setHandlerBus,
|
|
27
27
|
wireApiFromManifest: () => wireApiFromManifest
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(infra_exports);
|
|
@@ -41,13 +41,6 @@ function getFunction(value, key) {
|
|
|
41
41
|
const candidate = value[key];
|
|
42
42
|
return typeof candidate === "function" ? candidate : void 0;
|
|
43
43
|
}
|
|
44
|
-
function getStringProp(value, key) {
|
|
45
|
-
if (!isRecord(value)) {
|
|
46
|
-
return void 0;
|
|
47
|
-
}
|
|
48
|
-
const candidate = value[key];
|
|
49
|
-
return typeof candidate === "string" && candidate.length > 0 ? candidate : void 0;
|
|
50
|
-
}
|
|
51
44
|
function ensureRecord(value, message) {
|
|
52
45
|
if (!isRecord(value)) {
|
|
53
46
|
throw new Error(message);
|
|
@@ -84,16 +77,11 @@ function resolveHandlerInput(handler) {
|
|
|
84
77
|
|
|
85
78
|
// src/bus/infra.ts
|
|
86
79
|
var MAX_SUBSCRIBER_NAME_LENGTH = 60;
|
|
87
|
-
function getBus() {
|
|
88
|
-
const aws = ensureSstAws();
|
|
89
|
-
return aws.Bus.get("default", "default");
|
|
90
|
-
}
|
|
91
80
|
function wireEventsFromManifest(events, opts) {
|
|
92
81
|
if (!events || events.length === 0) {
|
|
93
82
|
return;
|
|
94
83
|
}
|
|
95
84
|
const aws = ensureSstAws(opts.source);
|
|
96
|
-
const busMap = normalizeBusInput(opts.buses);
|
|
97
85
|
const subscriber = resolveHandlerInput(opts.handler);
|
|
98
86
|
const seen = /* @__PURE__ */ new Set();
|
|
99
87
|
for (const event of events) {
|
|
@@ -102,57 +90,11 @@ function wireEventsFromManifest(events, opts) {
|
|
|
102
90
|
continue;
|
|
103
91
|
}
|
|
104
92
|
seen.add(key);
|
|
105
|
-
const bus =
|
|
93
|
+
const bus = aws.Bus.get("default", "default");
|
|
106
94
|
const subscriberName = buildSubscriberName(event.event);
|
|
107
95
|
subscribeToBus(bus, subscriberName, subscriber, event.event);
|
|
108
96
|
}
|
|
109
97
|
}
|
|
110
|
-
function normalizeBusInput(input) {
|
|
111
|
-
if (!input) {
|
|
112
|
-
return void 0;
|
|
113
|
-
}
|
|
114
|
-
const map = /* @__PURE__ */ new Map();
|
|
115
|
-
if (Array.isArray(input)) {
|
|
116
|
-
for (const bus of input) {
|
|
117
|
-
const key2 = getBusKey(bus);
|
|
118
|
-
if (key2) {
|
|
119
|
-
map.set(key2, bus);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (map.size === 1 && !map.has("default")) {
|
|
123
|
-
const [bus] = map.values();
|
|
124
|
-
map.set("default", bus);
|
|
125
|
-
}
|
|
126
|
-
return map;
|
|
127
|
-
}
|
|
128
|
-
if (isBusRecord(input)) {
|
|
129
|
-
for (const [key2, bus] of Object.entries(input)) {
|
|
130
|
-
map.set(key2, bus);
|
|
131
|
-
}
|
|
132
|
-
return map;
|
|
133
|
-
}
|
|
134
|
-
const key = getBusKey(input) ?? "default";
|
|
135
|
-
map.set(key, input);
|
|
136
|
-
return map;
|
|
137
|
-
}
|
|
138
|
-
function isBusRecord(input) {
|
|
139
|
-
return !Array.isArray(input) && isRecord(input) && !("subscribe" in input);
|
|
140
|
-
}
|
|
141
|
-
function getBusKey(bus) {
|
|
142
|
-
return getStringProp(bus, "name") ?? getStringProp(bus, "constructorName");
|
|
143
|
-
}
|
|
144
|
-
function resolveBusForEvent(busMap, aws) {
|
|
145
|
-
if (busMap && busMap.size > 0) {
|
|
146
|
-
const direct = busMap.get("default");
|
|
147
|
-
if (direct) {
|
|
148
|
-
return direct;
|
|
149
|
-
}
|
|
150
|
-
if (busMap.size === 1) {
|
|
151
|
-
return busMap.values().next().value;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return aws.Bus.get("default", "default");
|
|
155
|
-
}
|
|
156
98
|
function subscribeToBus(bus, subscriberName, subscriber, eventName) {
|
|
157
99
|
if (typeof bus.subscribe !== "function") {
|
|
158
100
|
throw new Error("Bus instance does not support subscribe().");
|
|
@@ -367,6 +309,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
367
309
|
if (!manifest || !Array.isArray(manifest.routes)) {
|
|
368
310
|
throw new Error("Invalid routes manifest");
|
|
369
311
|
}
|
|
312
|
+
setHandlerBus(opts.handler);
|
|
370
313
|
wireRoutesFromManifest(manifest, {
|
|
371
314
|
handler: opts.handler,
|
|
372
315
|
firebaseProjectId: opts.firebaseProjectId,
|
|
@@ -374,8 +317,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
374
317
|
ensureJwtAuthorizer: opts.ensureJwtAuthorizer
|
|
375
318
|
});
|
|
376
319
|
wireEventsFromManifest(manifest.events, {
|
|
377
|
-
handler: opts.handler
|
|
378
|
-
buses: opts.buses
|
|
320
|
+
handler: opts.handler
|
|
379
321
|
});
|
|
380
322
|
}
|
|
381
323
|
function loadRoutesManifest(filePath) {
|
|
@@ -387,11 +329,27 @@ function loadRoutesManifest(filePath) {
|
|
|
387
329
|
}
|
|
388
330
|
return manifest;
|
|
389
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
|
+
}
|
|
390
348
|
// Annotate the CommonJS export names for ESM import in node:
|
|
391
349
|
0 && (module.exports = {
|
|
392
|
-
getBus,
|
|
393
350
|
httpApiAdapter,
|
|
394
351
|
loadRoutesManifest,
|
|
395
352
|
restApiAdapter,
|
|
353
|
+
setHandlerBus,
|
|
396
354
|
wireApiFromManifest
|
|
397
355
|
});
|
package/dist/infra.d.cts
CHANGED
|
@@ -1,31 +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 getBus(): BusLike;
|
|
23
|
-
declare function wireEventsFromManifest(events: RoutesManifestEvent[] | undefined, opts: {
|
|
24
|
-
handler: unknown;
|
|
25
|
-
buses?: BusInput;
|
|
26
|
-
source?: AwsSource;
|
|
27
|
-
}): void;
|
|
28
|
-
|
|
29
11
|
type RegisterRouteConfig = {
|
|
30
12
|
handler: unknown;
|
|
31
13
|
protected: boolean;
|
|
@@ -62,8 +44,8 @@ declare function wireApiFromManifest(manifest: RoutesManifest, opts: {
|
|
|
62
44
|
firebaseProjectId: string;
|
|
63
45
|
registerRoute: RegisterRoute;
|
|
64
46
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
65
|
-
buses?: Parameters<typeof wireEventsFromManifest>[1]["buses"];
|
|
66
47
|
}): void;
|
|
67
48
|
declare function loadRoutesManifest(filePath: string): RoutesManifest;
|
|
49
|
+
declare function setHandlerBus(handler: unknown): void;
|
|
68
50
|
|
|
69
|
-
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,31 +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 getBus(): BusLike;
|
|
23
|
-
declare function wireEventsFromManifest(events: RoutesManifestEvent[] | undefined, opts: {
|
|
24
|
-
handler: unknown;
|
|
25
|
-
buses?: BusInput;
|
|
26
|
-
source?: AwsSource;
|
|
27
|
-
}): void;
|
|
28
|
-
|
|
29
11
|
type RegisterRouteConfig = {
|
|
30
12
|
handler: unknown;
|
|
31
13
|
protected: boolean;
|
|
@@ -62,8 +44,8 @@ declare function wireApiFromManifest(manifest: RoutesManifest, opts: {
|
|
|
62
44
|
firebaseProjectId: string;
|
|
63
45
|
registerRoute: RegisterRoute;
|
|
64
46
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
65
|
-
buses?: Parameters<typeof wireEventsFromManifest>[1]["buses"];
|
|
66
47
|
}): void;
|
|
67
48
|
declare function loadRoutesManifest(filePath: string): RoutesManifest;
|
|
49
|
+
declare function setHandlerBus(handler: unknown): void;
|
|
68
50
|
|
|
69
|
-
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,16 +53,11 @@ function resolveHandlerInput(handler) {
|
|
|
60
53
|
|
|
61
54
|
// src/bus/infra.ts
|
|
62
55
|
var MAX_SUBSCRIBER_NAME_LENGTH = 60;
|
|
63
|
-
function getBus() {
|
|
64
|
-
const aws = ensureSstAws();
|
|
65
|
-
return aws.Bus.get("default", "default");
|
|
66
|
-
}
|
|
67
56
|
function wireEventsFromManifest(events, opts) {
|
|
68
57
|
if (!events || events.length === 0) {
|
|
69
58
|
return;
|
|
70
59
|
}
|
|
71
60
|
const aws = ensureSstAws(opts.source);
|
|
72
|
-
const busMap = normalizeBusInput(opts.buses);
|
|
73
61
|
const subscriber = resolveHandlerInput(opts.handler);
|
|
74
62
|
const seen = /* @__PURE__ */ new Set();
|
|
75
63
|
for (const event of events) {
|
|
@@ -78,57 +66,11 @@ function wireEventsFromManifest(events, opts) {
|
|
|
78
66
|
continue;
|
|
79
67
|
}
|
|
80
68
|
seen.add(key);
|
|
81
|
-
const bus =
|
|
69
|
+
const bus = aws.Bus.get("default", "default");
|
|
82
70
|
const subscriberName = buildSubscriberName(event.event);
|
|
83
71
|
subscribeToBus(bus, subscriberName, subscriber, event.event);
|
|
84
72
|
}
|
|
85
73
|
}
|
|
86
|
-
function normalizeBusInput(input) {
|
|
87
|
-
if (!input) {
|
|
88
|
-
return void 0;
|
|
89
|
-
}
|
|
90
|
-
const map = /* @__PURE__ */ new Map();
|
|
91
|
-
if (Array.isArray(input)) {
|
|
92
|
-
for (const bus of input) {
|
|
93
|
-
const key2 = getBusKey(bus);
|
|
94
|
-
if (key2) {
|
|
95
|
-
map.set(key2, bus);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (map.size === 1 && !map.has("default")) {
|
|
99
|
-
const [bus] = map.values();
|
|
100
|
-
map.set("default", bus);
|
|
101
|
-
}
|
|
102
|
-
return map;
|
|
103
|
-
}
|
|
104
|
-
if (isBusRecord(input)) {
|
|
105
|
-
for (const [key2, bus] of Object.entries(input)) {
|
|
106
|
-
map.set(key2, bus);
|
|
107
|
-
}
|
|
108
|
-
return map;
|
|
109
|
-
}
|
|
110
|
-
const key = getBusKey(input) ?? "default";
|
|
111
|
-
map.set(key, input);
|
|
112
|
-
return map;
|
|
113
|
-
}
|
|
114
|
-
function isBusRecord(input) {
|
|
115
|
-
return !Array.isArray(input) && isRecord(input) && !("subscribe" in input);
|
|
116
|
-
}
|
|
117
|
-
function getBusKey(bus) {
|
|
118
|
-
return getStringProp(bus, "name") ?? getStringProp(bus, "constructorName");
|
|
119
|
-
}
|
|
120
|
-
function resolveBusForEvent(busMap, aws) {
|
|
121
|
-
if (busMap && busMap.size > 0) {
|
|
122
|
-
const direct = busMap.get("default");
|
|
123
|
-
if (direct) {
|
|
124
|
-
return direct;
|
|
125
|
-
}
|
|
126
|
-
if (busMap.size === 1) {
|
|
127
|
-
return busMap.values().next().value;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return aws.Bus.get("default", "default");
|
|
131
|
-
}
|
|
132
74
|
function subscribeToBus(bus, subscriberName, subscriber, eventName) {
|
|
133
75
|
if (typeof bus.subscribe !== "function") {
|
|
134
76
|
throw new Error("Bus instance does not support subscribe().");
|
|
@@ -337,6 +279,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
337
279
|
if (!manifest || !Array.isArray(manifest.routes)) {
|
|
338
280
|
throw new Error("Invalid routes manifest");
|
|
339
281
|
}
|
|
282
|
+
setHandlerBus(opts.handler);
|
|
340
283
|
wireRoutesFromManifest(manifest, {
|
|
341
284
|
handler: opts.handler,
|
|
342
285
|
firebaseProjectId: opts.firebaseProjectId,
|
|
@@ -344,8 +287,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
344
287
|
ensureJwtAuthorizer: opts.ensureJwtAuthorizer
|
|
345
288
|
});
|
|
346
289
|
wireEventsFromManifest(manifest.events, {
|
|
347
|
-
handler: opts.handler
|
|
348
|
-
buses: opts.buses
|
|
290
|
+
handler: opts.handler
|
|
349
291
|
});
|
|
350
292
|
}
|
|
351
293
|
function loadRoutesManifest(filePath) {
|
|
@@ -357,10 +299,26 @@ function loadRoutesManifest(filePath) {
|
|
|
357
299
|
}
|
|
358
300
|
return manifest;
|
|
359
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
|
+
}
|
|
360
318
|
export {
|
|
361
|
-
getBus,
|
|
362
319
|
httpApiAdapter,
|
|
363
320
|
loadRoutesManifest,
|
|
364
321
|
restApiAdapter,
|
|
322
|
+
setHandlerBus,
|
|
365
323
|
wireApiFromManifest
|
|
366
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 };
|