sst-http 2.0.0-beta.10 → 2.0.0-beta.16
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 +12 -2
- package/dist/infra.cjs +10 -8
- package/dist/infra.d.cts +6 -14
- package/dist/infra.d.ts +6 -14
- package/dist/infra.js +10 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -174,7 +174,8 @@ export default $config({
|
|
|
174
174
|
} = await import("sst-http/infra");
|
|
175
175
|
|
|
176
176
|
const manifest = loadRoutesManifest("routes.manifest.json");
|
|
177
|
-
const
|
|
177
|
+
const api = new sst.aws.ApiGatewayV2("Api");
|
|
178
|
+
const { registerRoute, ensureJwtAuthorizer } = httpApiAdapter({ api });
|
|
178
179
|
|
|
179
180
|
const handler = new sst.aws.Function("Handler", {
|
|
180
181
|
handler: "src/server.handler",
|
|
@@ -185,7 +186,7 @@ export default $config({
|
|
|
185
186
|
|
|
186
187
|
wireApiFromManifest(manifest, {
|
|
187
188
|
handler,
|
|
188
|
-
firebaseProjectId: process.env.FIREBASE_PROJECT_ID
|
|
189
|
+
firebaseProjectId: process.env.FIREBASE_PROJECT_ID,
|
|
189
190
|
registerRoute,
|
|
190
191
|
ensureJwtAuthorizer,
|
|
191
192
|
});
|
|
@@ -195,6 +196,15 @@ export default $config({
|
|
|
195
196
|
});
|
|
196
197
|
```
|
|
197
198
|
|
|
199
|
+
**Note:** `firebaseProjectId` and `ensureJwtAuthorizer` are optional and only required when your manifest contains routes with `@FirebaseAuth()`. For event-only handlers (no HTTP routes), you can omit `registerRoute` and `ensureJwtAuthorizer`:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
wireApiFromManifest(manifest, {
|
|
203
|
+
handler,
|
|
204
|
+
registerRoute: (_method, _path, _config) => {},
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
198
208
|
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.
|
|
199
209
|
|
|
200
210
|
## Publishing
|
package/dist/infra.cjs
CHANGED
|
@@ -78,6 +78,7 @@ function resolveHandlerInput(handler) {
|
|
|
78
78
|
|
|
79
79
|
// src/bus/infra.ts
|
|
80
80
|
var MAX_SUBSCRIBER_NAME_LENGTH = 60;
|
|
81
|
+
var bus;
|
|
81
82
|
function wireEventsFromManifest(events, opts) {
|
|
82
83
|
if (!events || events.length === 0) {
|
|
83
84
|
return;
|
|
@@ -90,17 +91,17 @@ function wireEventsFromManifest(events, opts) {
|
|
|
90
91
|
if (seen.has(key)) {
|
|
91
92
|
continue;
|
|
92
93
|
}
|
|
94
|
+
if (!bus) bus = aws2.Bus.get("default", "default");
|
|
93
95
|
seen.add(key);
|
|
94
|
-
const bus = aws2.Bus.get("default", "default");
|
|
95
96
|
const subscriberName = buildSubscriberName(event.event);
|
|
96
97
|
subscribeToBus(bus, subscriberName, subscriber, event.event);
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
function subscribeToBus(
|
|
100
|
-
if (typeof
|
|
100
|
+
function subscribeToBus(bus2, subscriberName, subscriber, eventName) {
|
|
101
|
+
if (typeof bus2.subscribe !== "function") {
|
|
101
102
|
throw new Error("Bus instance does not support subscribe().");
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
+
bus2.subscribe(subscriberName, subscriber, {
|
|
104
105
|
pattern: {
|
|
105
106
|
detailType: [eventName]
|
|
106
107
|
}
|
|
@@ -137,8 +138,7 @@ function wireRoutesFromManifest(manifest, opts) {
|
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
function httpApiAdapter(args) {
|
|
140
|
-
const
|
|
141
|
-
const api = args?.api ?? new aws2.ApiGatewayV2(args?.apiName ?? "HttpApi", args?.apiArgs);
|
|
141
|
+
const api = args.api;
|
|
142
142
|
const ensureJwtAuthorizer = createHttpAuthorizerManager(api);
|
|
143
143
|
const registerRoute = createRouteRegistrar(api, "ApiGatewayV2");
|
|
144
144
|
return {
|
|
@@ -148,8 +148,7 @@ function httpApiAdapter(args) {
|
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
function restApiAdapter(args) {
|
|
151
|
-
const
|
|
152
|
-
const api = args?.api ?? new aws2.ApiGateway(args?.apiName ?? "RestApi", args?.apiArgs);
|
|
151
|
+
const api = args.api;
|
|
153
152
|
const ensureJwtAuthorizer = createRestAuthorizerManager(api);
|
|
154
153
|
const registerRoute = createRouteRegistrar(api, "ApiGateway");
|
|
155
154
|
return {
|
|
@@ -165,6 +164,9 @@ function ensureFirebaseAuthorizer(firebaseRouteCount, opts) {
|
|
|
165
164
|
if (!opts.firebaseProjectId) {
|
|
166
165
|
throw new Error("firebaseProjectId is required when using @FirebaseAuth()");
|
|
167
166
|
}
|
|
167
|
+
if (!opts.ensureJwtAuthorizer) {
|
|
168
|
+
throw new Error("ensureJwtAuthorizer is required when using @FirebaseAuth()");
|
|
169
|
+
}
|
|
168
170
|
const issuer = `https://securetoken.google.com/${opts.firebaseProjectId}`;
|
|
169
171
|
return opts.ensureJwtAuthorizer("firebase", {
|
|
170
172
|
issuer,
|
package/dist/infra.d.cts
CHANGED
|
@@ -2,12 +2,6 @@ import { b as HttpMethod, f as RoutesManifest } from './types-o33yWNSY.cjs';
|
|
|
2
2
|
export { h as RoutesManifestAuth, i as RoutesManifestEvent, g as RoutesManifestRoute } from './types-o33yWNSY.cjs';
|
|
3
3
|
import 'aws-lambda';
|
|
4
4
|
|
|
5
|
-
type AwsSource = {
|
|
6
|
-
sst?: {
|
|
7
|
-
aws?: unknown;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
|
|
11
5
|
type RegisterRouteConfig = {
|
|
12
6
|
handler: unknown;
|
|
13
7
|
protected: boolean;
|
|
@@ -23,17 +17,15 @@ type EnsureJwtAuthorizer = (name: string, cfg: {
|
|
|
23
17
|
issuer: string;
|
|
24
18
|
audiences: string[];
|
|
25
19
|
}) => unknown;
|
|
26
|
-
type AdapterArgs =
|
|
27
|
-
api
|
|
28
|
-
apiName?: string;
|
|
29
|
-
apiArgs?: unknown;
|
|
20
|
+
type AdapterArgs = {
|
|
21
|
+
api: unknown;
|
|
30
22
|
};
|
|
31
|
-
declare function httpApiAdapter(args
|
|
23
|
+
declare function httpApiAdapter(args: AdapterArgs): {
|
|
32
24
|
api: unknown;
|
|
33
25
|
registerRoute: RegisterRoute;
|
|
34
26
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
35
27
|
};
|
|
36
|
-
declare function restApiAdapter(args
|
|
28
|
+
declare function restApiAdapter(args: AdapterArgs): {
|
|
37
29
|
api: unknown;
|
|
38
30
|
registerRoute: RegisterRoute;
|
|
39
31
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
@@ -41,9 +33,9 @@ declare function restApiAdapter(args?: AdapterArgs): {
|
|
|
41
33
|
|
|
42
34
|
declare function wireApiFromManifest(manifest: RoutesManifest, opts: {
|
|
43
35
|
handler: unknown;
|
|
44
|
-
firebaseProjectId
|
|
36
|
+
firebaseProjectId?: string;
|
|
45
37
|
registerRoute: RegisterRoute;
|
|
46
|
-
ensureJwtAuthorizer
|
|
38
|
+
ensureJwtAuthorizer?: EnsureJwtAuthorizer;
|
|
47
39
|
}): void;
|
|
48
40
|
declare function loadRoutesManifest(filePath: string): RoutesManifest;
|
|
49
41
|
declare function setHandlerBus(handler: unknown): void;
|
package/dist/infra.d.ts
CHANGED
|
@@ -2,12 +2,6 @@ import { b as HttpMethod, f as RoutesManifest } from './types-o33yWNSY.js';
|
|
|
2
2
|
export { h as RoutesManifestAuth, i as RoutesManifestEvent, g as RoutesManifestRoute } from './types-o33yWNSY.js';
|
|
3
3
|
import 'aws-lambda';
|
|
4
4
|
|
|
5
|
-
type AwsSource = {
|
|
6
|
-
sst?: {
|
|
7
|
-
aws?: unknown;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
|
|
11
5
|
type RegisterRouteConfig = {
|
|
12
6
|
handler: unknown;
|
|
13
7
|
protected: boolean;
|
|
@@ -23,17 +17,15 @@ type EnsureJwtAuthorizer = (name: string, cfg: {
|
|
|
23
17
|
issuer: string;
|
|
24
18
|
audiences: string[];
|
|
25
19
|
}) => unknown;
|
|
26
|
-
type AdapterArgs =
|
|
27
|
-
api
|
|
28
|
-
apiName?: string;
|
|
29
|
-
apiArgs?: unknown;
|
|
20
|
+
type AdapterArgs = {
|
|
21
|
+
api: unknown;
|
|
30
22
|
};
|
|
31
|
-
declare function httpApiAdapter(args
|
|
23
|
+
declare function httpApiAdapter(args: AdapterArgs): {
|
|
32
24
|
api: unknown;
|
|
33
25
|
registerRoute: RegisterRoute;
|
|
34
26
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
35
27
|
};
|
|
36
|
-
declare function restApiAdapter(args
|
|
28
|
+
declare function restApiAdapter(args: AdapterArgs): {
|
|
37
29
|
api: unknown;
|
|
38
30
|
registerRoute: RegisterRoute;
|
|
39
31
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
@@ -41,9 +33,9 @@ declare function restApiAdapter(args?: AdapterArgs): {
|
|
|
41
33
|
|
|
42
34
|
declare function wireApiFromManifest(manifest: RoutesManifest, opts: {
|
|
43
35
|
handler: unknown;
|
|
44
|
-
firebaseProjectId
|
|
36
|
+
firebaseProjectId?: string;
|
|
45
37
|
registerRoute: RegisterRoute;
|
|
46
|
-
ensureJwtAuthorizer
|
|
38
|
+
ensureJwtAuthorizer?: EnsureJwtAuthorizer;
|
|
47
39
|
}): void;
|
|
48
40
|
declare function loadRoutesManifest(filePath: string): RoutesManifest;
|
|
49
41
|
declare function setHandlerBus(handler: unknown): void;
|
package/dist/infra.js
CHANGED
|
@@ -54,6 +54,7 @@ function resolveHandlerInput(handler) {
|
|
|
54
54
|
|
|
55
55
|
// src/bus/infra.ts
|
|
56
56
|
var MAX_SUBSCRIBER_NAME_LENGTH = 60;
|
|
57
|
+
var bus;
|
|
57
58
|
function wireEventsFromManifest(events, opts) {
|
|
58
59
|
if (!events || events.length === 0) {
|
|
59
60
|
return;
|
|
@@ -66,17 +67,17 @@ function wireEventsFromManifest(events, opts) {
|
|
|
66
67
|
if (seen.has(key)) {
|
|
67
68
|
continue;
|
|
68
69
|
}
|
|
70
|
+
if (!bus) bus = aws2.Bus.get("default", "default");
|
|
69
71
|
seen.add(key);
|
|
70
|
-
const bus = aws2.Bus.get("default", "default");
|
|
71
72
|
const subscriberName = buildSubscriberName(event.event);
|
|
72
73
|
subscribeToBus(bus, subscriberName, subscriber, event.event);
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
|
-
function subscribeToBus(
|
|
76
|
-
if (typeof
|
|
76
|
+
function subscribeToBus(bus2, subscriberName, subscriber, eventName) {
|
|
77
|
+
if (typeof bus2.subscribe !== "function") {
|
|
77
78
|
throw new Error("Bus instance does not support subscribe().");
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
+
bus2.subscribe(subscriberName, subscriber, {
|
|
80
81
|
pattern: {
|
|
81
82
|
detailType: [eventName]
|
|
82
83
|
}
|
|
@@ -107,8 +108,7 @@ function wireRoutesFromManifest(manifest, opts) {
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
function httpApiAdapter(args) {
|
|
110
|
-
const
|
|
111
|
-
const api = args?.api ?? new aws2.ApiGatewayV2(args?.apiName ?? "HttpApi", args?.apiArgs);
|
|
111
|
+
const api = args.api;
|
|
112
112
|
const ensureJwtAuthorizer = createHttpAuthorizerManager(api);
|
|
113
113
|
const registerRoute = createRouteRegistrar(api, "ApiGatewayV2");
|
|
114
114
|
return {
|
|
@@ -118,8 +118,7 @@ function httpApiAdapter(args) {
|
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
function restApiAdapter(args) {
|
|
121
|
-
const
|
|
122
|
-
const api = args?.api ?? new aws2.ApiGateway(args?.apiName ?? "RestApi", args?.apiArgs);
|
|
121
|
+
const api = args.api;
|
|
123
122
|
const ensureJwtAuthorizer = createRestAuthorizerManager(api);
|
|
124
123
|
const registerRoute = createRouteRegistrar(api, "ApiGateway");
|
|
125
124
|
return {
|
|
@@ -135,6 +134,9 @@ function ensureFirebaseAuthorizer(firebaseRouteCount, opts) {
|
|
|
135
134
|
if (!opts.firebaseProjectId) {
|
|
136
135
|
throw new Error("firebaseProjectId is required when using @FirebaseAuth()");
|
|
137
136
|
}
|
|
137
|
+
if (!opts.ensureJwtAuthorizer) {
|
|
138
|
+
throw new Error("ensureJwtAuthorizer is required when using @FirebaseAuth()");
|
|
139
|
+
}
|
|
138
140
|
const issuer = `https://securetoken.google.com/${opts.firebaseProjectId}`;
|
|
139
141
|
return opts.ensureJwtAuthorizer("firebase", {
|
|
140
142
|
issuer,
|