sst-http 2.0.0-beta.4 → 2.0.0-beta.7
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 +30 -71
- package/dist/infra.d.cts +4 -22
- package/dist/infra.d.ts +4 -22
- package/dist/infra.js +29 -70
- 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);
|
|
@@ -55,13 +48,14 @@ function ensureRecord(value, message) {
|
|
|
55
48
|
return value;
|
|
56
49
|
}
|
|
57
50
|
function ensureSstAws(source) {
|
|
58
|
-
const
|
|
59
|
-
if (!
|
|
51
|
+
const awsData = typeof sst !== "undefined" ? sst.aws : source?.sst?.aws ?? globalThis.sst?.aws;
|
|
52
|
+
if (!awsData) {
|
|
60
53
|
throw new Error(
|
|
61
54
|
"SST aws namespace is not available. Ensure this code runs within an SST config."
|
|
62
55
|
);
|
|
63
56
|
}
|
|
64
|
-
|
|
57
|
+
awsData.iam = aws.iam;
|
|
58
|
+
return awsData;
|
|
65
59
|
}
|
|
66
60
|
function resolveHandlerInput(handler) {
|
|
67
61
|
if (handler === void 0) {
|
|
@@ -84,16 +78,11 @@ function resolveHandlerInput(handler) {
|
|
|
84
78
|
|
|
85
79
|
// src/bus/infra.ts
|
|
86
80
|
var MAX_SUBSCRIBER_NAME_LENGTH = 60;
|
|
87
|
-
function getBus() {
|
|
88
|
-
const aws = ensureSstAws();
|
|
89
|
-
return aws.Bus.get("default", "default");
|
|
90
|
-
}
|
|
91
81
|
function wireEventsFromManifest(events, opts) {
|
|
92
82
|
if (!events || events.length === 0) {
|
|
93
83
|
return;
|
|
94
84
|
}
|
|
95
|
-
const
|
|
96
|
-
const busMap = normalizeBusInput(opts.buses);
|
|
85
|
+
const aws2 = ensureSstAws(opts.source);
|
|
97
86
|
const subscriber = resolveHandlerInput(opts.handler);
|
|
98
87
|
const seen = /* @__PURE__ */ new Set();
|
|
99
88
|
for (const event of events) {
|
|
@@ -102,57 +91,11 @@ function wireEventsFromManifest(events, opts) {
|
|
|
102
91
|
continue;
|
|
103
92
|
}
|
|
104
93
|
seen.add(key);
|
|
105
|
-
const bus =
|
|
94
|
+
const bus = aws2.Bus.get("default", "default");
|
|
106
95
|
const subscriberName = buildSubscriberName(event.event);
|
|
107
96
|
subscribeToBus(bus, subscriberName, subscriber, event.event);
|
|
108
97
|
}
|
|
109
98
|
}
|
|
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
99
|
function subscribeToBus(bus, subscriberName, subscriber, eventName) {
|
|
157
100
|
if (typeof bus.subscribe !== "function") {
|
|
158
101
|
throw new Error("Bus instance does not support subscribe().");
|
|
@@ -194,8 +137,8 @@ function wireRoutesFromManifest(manifest, opts) {
|
|
|
194
137
|
}
|
|
195
138
|
}
|
|
196
139
|
function httpApiAdapter(args) {
|
|
197
|
-
const
|
|
198
|
-
const api = args?.api ?? new
|
|
140
|
+
const aws2 = args?.api ? void 0 : ensureSstAws(args);
|
|
141
|
+
const api = args?.api ?? new aws2.ApiGatewayV2(args?.apiName ?? "HttpApi", args?.apiArgs);
|
|
199
142
|
const ensureJwtAuthorizer = createHttpAuthorizerManager(api);
|
|
200
143
|
const registerRoute = createRouteRegistrar(api, "ApiGatewayV2");
|
|
201
144
|
return {
|
|
@@ -205,8 +148,8 @@ function httpApiAdapter(args) {
|
|
|
205
148
|
};
|
|
206
149
|
}
|
|
207
150
|
function restApiAdapter(args) {
|
|
208
|
-
const
|
|
209
|
-
const api = args?.api ?? new
|
|
151
|
+
const aws2 = args?.api ? void 0 : ensureSstAws(args);
|
|
152
|
+
const api = args?.api ?? new aws2.ApiGateway(args?.apiName ?? "RestApi", args?.apiArgs);
|
|
210
153
|
const ensureJwtAuthorizer = createRestAuthorizerManager(api);
|
|
211
154
|
const registerRoute = createRouteRegistrar(api, "ApiGateway");
|
|
212
155
|
return {
|
|
@@ -367,6 +310,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
367
310
|
if (!manifest || !Array.isArray(manifest.routes)) {
|
|
368
311
|
throw new Error("Invalid routes manifest");
|
|
369
312
|
}
|
|
313
|
+
setHandlerBus(opts.handler);
|
|
370
314
|
wireRoutesFromManifest(manifest, {
|
|
371
315
|
handler: opts.handler,
|
|
372
316
|
firebaseProjectId: opts.firebaseProjectId,
|
|
@@ -374,8 +318,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
374
318
|
ensureJwtAuthorizer: opts.ensureJwtAuthorizer
|
|
375
319
|
});
|
|
376
320
|
wireEventsFromManifest(manifest.events, {
|
|
377
|
-
handler: opts.handler
|
|
378
|
-
buses: opts.buses
|
|
321
|
+
handler: opts.handler
|
|
379
322
|
});
|
|
380
323
|
}
|
|
381
324
|
function loadRoutesManifest(filePath) {
|
|
@@ -387,11 +330,27 @@ function loadRoutesManifest(filePath) {
|
|
|
387
330
|
}
|
|
388
331
|
return manifest;
|
|
389
332
|
}
|
|
333
|
+
function setHandlerBus(handler) {
|
|
334
|
+
const aws2 = ensureSstAws();
|
|
335
|
+
new aws2.iam.RolePolicy("PublisherHandlerPolicy", {
|
|
336
|
+
role: handler.nodes.role.name,
|
|
337
|
+
policy: {
|
|
338
|
+
Version: "2012-10-17",
|
|
339
|
+
Statement: [
|
|
340
|
+
{
|
|
341
|
+
Action: ["events:PutEvents"],
|
|
342
|
+
Resource: ["*"],
|
|
343
|
+
Effect: "Allow"
|
|
344
|
+
}
|
|
345
|
+
]
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}
|
|
390
349
|
// Annotate the CommonJS export names for ESM import in node:
|
|
391
350
|
0 && (module.exports = {
|
|
392
|
-
getBus,
|
|
393
351
|
httpApiAdapter,
|
|
394
352
|
loadRoutesManifest,
|
|
395
353
|
restApiAdapter,
|
|
354
|
+
setHandlerBus,
|
|
396
355
|
wireApiFromManifest
|
|
397
356
|
});
|
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);
|
|
@@ -31,13 +24,14 @@ function ensureRecord(value, message) {
|
|
|
31
24
|
return value;
|
|
32
25
|
}
|
|
33
26
|
function ensureSstAws(source) {
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
27
|
+
const awsData = typeof sst !== "undefined" ? sst.aws : source?.sst?.aws ?? globalThis.sst?.aws;
|
|
28
|
+
if (!awsData) {
|
|
36
29
|
throw new Error(
|
|
37
30
|
"SST aws namespace is not available. Ensure this code runs within an SST config."
|
|
38
31
|
);
|
|
39
32
|
}
|
|
40
|
-
|
|
33
|
+
awsData.iam = aws.iam;
|
|
34
|
+
return awsData;
|
|
41
35
|
}
|
|
42
36
|
function resolveHandlerInput(handler) {
|
|
43
37
|
if (handler === void 0) {
|
|
@@ -60,16 +54,11 @@ function resolveHandlerInput(handler) {
|
|
|
60
54
|
|
|
61
55
|
// src/bus/infra.ts
|
|
62
56
|
var MAX_SUBSCRIBER_NAME_LENGTH = 60;
|
|
63
|
-
function getBus() {
|
|
64
|
-
const aws = ensureSstAws();
|
|
65
|
-
return aws.Bus.get("default", "default");
|
|
66
|
-
}
|
|
67
57
|
function wireEventsFromManifest(events, opts) {
|
|
68
58
|
if (!events || events.length === 0) {
|
|
69
59
|
return;
|
|
70
60
|
}
|
|
71
|
-
const
|
|
72
|
-
const busMap = normalizeBusInput(opts.buses);
|
|
61
|
+
const aws2 = ensureSstAws(opts.source);
|
|
73
62
|
const subscriber = resolveHandlerInput(opts.handler);
|
|
74
63
|
const seen = /* @__PURE__ */ new Set();
|
|
75
64
|
for (const event of events) {
|
|
@@ -78,57 +67,11 @@ function wireEventsFromManifest(events, opts) {
|
|
|
78
67
|
continue;
|
|
79
68
|
}
|
|
80
69
|
seen.add(key);
|
|
81
|
-
const bus =
|
|
70
|
+
const bus = aws2.Bus.get("default", "default");
|
|
82
71
|
const subscriberName = buildSubscriberName(event.event);
|
|
83
72
|
subscribeToBus(bus, subscriberName, subscriber, event.event);
|
|
84
73
|
}
|
|
85
74
|
}
|
|
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
75
|
function subscribeToBus(bus, subscriberName, subscriber, eventName) {
|
|
133
76
|
if (typeof bus.subscribe !== "function") {
|
|
134
77
|
throw new Error("Bus instance does not support subscribe().");
|
|
@@ -164,8 +107,8 @@ function wireRoutesFromManifest(manifest, opts) {
|
|
|
164
107
|
}
|
|
165
108
|
}
|
|
166
109
|
function httpApiAdapter(args) {
|
|
167
|
-
const
|
|
168
|
-
const api = args?.api ?? new
|
|
110
|
+
const aws2 = args?.api ? void 0 : ensureSstAws(args);
|
|
111
|
+
const api = args?.api ?? new aws2.ApiGatewayV2(args?.apiName ?? "HttpApi", args?.apiArgs);
|
|
169
112
|
const ensureJwtAuthorizer = createHttpAuthorizerManager(api);
|
|
170
113
|
const registerRoute = createRouteRegistrar(api, "ApiGatewayV2");
|
|
171
114
|
return {
|
|
@@ -175,8 +118,8 @@ function httpApiAdapter(args) {
|
|
|
175
118
|
};
|
|
176
119
|
}
|
|
177
120
|
function restApiAdapter(args) {
|
|
178
|
-
const
|
|
179
|
-
const api = args?.api ?? new
|
|
121
|
+
const aws2 = args?.api ? void 0 : ensureSstAws(args);
|
|
122
|
+
const api = args?.api ?? new aws2.ApiGateway(args?.apiName ?? "RestApi", args?.apiArgs);
|
|
180
123
|
const ensureJwtAuthorizer = createRestAuthorizerManager(api);
|
|
181
124
|
const registerRoute = createRouteRegistrar(api, "ApiGateway");
|
|
182
125
|
return {
|
|
@@ -337,6 +280,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
337
280
|
if (!manifest || !Array.isArray(manifest.routes)) {
|
|
338
281
|
throw new Error("Invalid routes manifest");
|
|
339
282
|
}
|
|
283
|
+
setHandlerBus(opts.handler);
|
|
340
284
|
wireRoutesFromManifest(manifest, {
|
|
341
285
|
handler: opts.handler,
|
|
342
286
|
firebaseProjectId: opts.firebaseProjectId,
|
|
@@ -344,8 +288,7 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
344
288
|
ensureJwtAuthorizer: opts.ensureJwtAuthorizer
|
|
345
289
|
});
|
|
346
290
|
wireEventsFromManifest(manifest.events, {
|
|
347
|
-
handler: opts.handler
|
|
348
|
-
buses: opts.buses
|
|
291
|
+
handler: opts.handler
|
|
349
292
|
});
|
|
350
293
|
}
|
|
351
294
|
function loadRoutesManifest(filePath) {
|
|
@@ -357,10 +300,26 @@ function loadRoutesManifest(filePath) {
|
|
|
357
300
|
}
|
|
358
301
|
return manifest;
|
|
359
302
|
}
|
|
303
|
+
function setHandlerBus(handler) {
|
|
304
|
+
const aws2 = ensureSstAws();
|
|
305
|
+
new aws2.iam.RolePolicy("PublisherHandlerPolicy", {
|
|
306
|
+
role: handler.nodes.role.name,
|
|
307
|
+
policy: {
|
|
308
|
+
Version: "2012-10-17",
|
|
309
|
+
Statement: [
|
|
310
|
+
{
|
|
311
|
+
Action: ["events:PutEvents"],
|
|
312
|
+
Resource: ["*"],
|
|
313
|
+
Effect: "Allow"
|
|
314
|
+
}
|
|
315
|
+
]
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
360
319
|
export {
|
|
361
|
-
getBus,
|
|
362
320
|
httpApiAdapter,
|
|
363
321
|
loadRoutesManifest,
|
|
364
322
|
restApiAdapter,
|
|
323
|
+
setHandlerBus,
|
|
365
324
|
wireApiFromManifest
|
|
366
325
|
};
|
|
@@ -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 };
|