sst-http 2.0.0-beta.10 → 2.0.0-beta.15
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/{chunk-SENBWWVV.js → chunk-P4HUTGVQ.js} +38 -0
- package/dist/http/index.cjs +39 -0
- package/dist/http/index.d.cts +2 -1
- package/dist/http/index.d.ts +2 -1
- package/dist/http/index.js +3 -1
- package/dist/index.cjs +39 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- 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
|
|
@@ -251,6 +251,14 @@ function buildHandlerArguments(entry, ctx, getBody) {
|
|
|
251
251
|
args[meta.index] = ctx.auth;
|
|
252
252
|
break;
|
|
253
253
|
}
|
|
254
|
+
case "userId": {
|
|
255
|
+
const userId = resolveUserIdFromClaims(ctx.auth);
|
|
256
|
+
if (!userId) {
|
|
257
|
+
throw new HttpError(401, "Invalid authentication");
|
|
258
|
+
}
|
|
259
|
+
args[meta.index] = userId;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
254
262
|
default: {
|
|
255
263
|
args[meta.index] = ctx;
|
|
256
264
|
}
|
|
@@ -337,6 +345,32 @@ function extractAuthClaims(event, entry) {
|
|
|
337
345
|
const claims = ctxV2?.authorizer?.jwt?.claims || ctxV1?.authorizer?.claims;
|
|
338
346
|
return claims ?? void 0;
|
|
339
347
|
}
|
|
348
|
+
function normalizeUserIdentifier(value) {
|
|
349
|
+
if (typeof value !== "string") {
|
|
350
|
+
return void 0;
|
|
351
|
+
}
|
|
352
|
+
const normalized = value.trim();
|
|
353
|
+
return normalized || void 0;
|
|
354
|
+
}
|
|
355
|
+
function resolveUserIdFromClaims(claims) {
|
|
356
|
+
const email = normalizeUserIdentifier(claims?.email);
|
|
357
|
+
if (email) {
|
|
358
|
+
return email.toLowerCase();
|
|
359
|
+
}
|
|
360
|
+
const userId = normalizeUserIdentifier(claims?.user_id);
|
|
361
|
+
if (userId) {
|
|
362
|
+
return userId;
|
|
363
|
+
}
|
|
364
|
+
const uid = normalizeUserIdentifier(claims?.uid);
|
|
365
|
+
if (uid) {
|
|
366
|
+
return uid;
|
|
367
|
+
}
|
|
368
|
+
const sub = normalizeUserIdentifier(claims?.sub);
|
|
369
|
+
if (sub) {
|
|
370
|
+
return sub;
|
|
371
|
+
}
|
|
372
|
+
return void 0;
|
|
373
|
+
}
|
|
340
374
|
function isHttpError(error) {
|
|
341
375
|
if (!error || typeof error !== "object") {
|
|
342
376
|
return false;
|
|
@@ -451,6 +485,9 @@ function FirebaseAuth(options) {
|
|
|
451
485
|
function Auth() {
|
|
452
486
|
return createParameterDecorator("auth");
|
|
453
487
|
}
|
|
488
|
+
function UserId() {
|
|
489
|
+
return createParameterDecorator("userId");
|
|
490
|
+
}
|
|
454
491
|
function Body(schema) {
|
|
455
492
|
return createParameterDecorator("body", { schema });
|
|
456
493
|
}
|
|
@@ -489,6 +526,7 @@ export {
|
|
|
489
526
|
Options,
|
|
490
527
|
FirebaseAuth,
|
|
491
528
|
Auth,
|
|
529
|
+
UserId,
|
|
492
530
|
Body,
|
|
493
531
|
Query,
|
|
494
532
|
Param,
|
package/dist/http/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ __export(http_exports, {
|
|
|
37
37
|
Query: () => Query,
|
|
38
38
|
Req: () => Req,
|
|
39
39
|
Res: () => Res,
|
|
40
|
+
UserId: () => UserId,
|
|
40
41
|
configureRoutes: () => configureRoutes,
|
|
41
42
|
createHandler: () => createHandler,
|
|
42
43
|
handleError: () => handleError,
|
|
@@ -381,6 +382,14 @@ function buildHandlerArguments(entry, ctx, getBody) {
|
|
|
381
382
|
args[meta.index] = ctx.auth;
|
|
382
383
|
break;
|
|
383
384
|
}
|
|
385
|
+
case "userId": {
|
|
386
|
+
const userId = resolveUserIdFromClaims(ctx.auth);
|
|
387
|
+
if (!userId) {
|
|
388
|
+
throw new HttpError(401, "Invalid authentication");
|
|
389
|
+
}
|
|
390
|
+
args[meta.index] = userId;
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
384
393
|
default: {
|
|
385
394
|
args[meta.index] = ctx;
|
|
386
395
|
}
|
|
@@ -467,6 +476,32 @@ function extractAuthClaims(event, entry) {
|
|
|
467
476
|
const claims = ctxV2?.authorizer?.jwt?.claims || ctxV1?.authorizer?.claims;
|
|
468
477
|
return claims ?? void 0;
|
|
469
478
|
}
|
|
479
|
+
function normalizeUserIdentifier(value) {
|
|
480
|
+
if (typeof value !== "string") {
|
|
481
|
+
return void 0;
|
|
482
|
+
}
|
|
483
|
+
const normalized = value.trim();
|
|
484
|
+
return normalized || void 0;
|
|
485
|
+
}
|
|
486
|
+
function resolveUserIdFromClaims(claims) {
|
|
487
|
+
const email = normalizeUserIdentifier(claims?.email);
|
|
488
|
+
if (email) {
|
|
489
|
+
return email.toLowerCase();
|
|
490
|
+
}
|
|
491
|
+
const userId = normalizeUserIdentifier(claims?.user_id);
|
|
492
|
+
if (userId) {
|
|
493
|
+
return userId;
|
|
494
|
+
}
|
|
495
|
+
const uid = normalizeUserIdentifier(claims?.uid);
|
|
496
|
+
if (uid) {
|
|
497
|
+
return uid;
|
|
498
|
+
}
|
|
499
|
+
const sub = normalizeUserIdentifier(claims?.sub);
|
|
500
|
+
if (sub) {
|
|
501
|
+
return sub;
|
|
502
|
+
}
|
|
503
|
+
return void 0;
|
|
504
|
+
}
|
|
470
505
|
function isHttpError(error) {
|
|
471
506
|
if (!error || typeof error !== "object") {
|
|
472
507
|
return false;
|
|
@@ -595,6 +630,9 @@ function FirebaseAuth(options2) {
|
|
|
595
630
|
function Auth() {
|
|
596
631
|
return createParameterDecorator("auth");
|
|
597
632
|
}
|
|
633
|
+
function UserId() {
|
|
634
|
+
return createParameterDecorator("userId");
|
|
635
|
+
}
|
|
598
636
|
function Body(schema) {
|
|
599
637
|
return createParameterDecorator("body", { schema });
|
|
600
638
|
}
|
|
@@ -635,6 +673,7 @@ function Res() {
|
|
|
635
673
|
Query,
|
|
636
674
|
Req,
|
|
637
675
|
Res,
|
|
676
|
+
UserId,
|
|
638
677
|
configureRoutes,
|
|
639
678
|
createHandler,
|
|
640
679
|
handleError,
|
package/dist/http/index.d.cts
CHANGED
|
@@ -38,6 +38,7 @@ declare const Head: (path?: string) => LegacyDecorator;
|
|
|
38
38
|
declare const Options: (path?: string) => LegacyDecorator;
|
|
39
39
|
declare function FirebaseAuth(options?: FirebaseAuthOptions): LegacyDecorator;
|
|
40
40
|
declare function Auth(): LegacyParameterDecorator;
|
|
41
|
+
declare function UserId(): LegacyParameterDecorator;
|
|
41
42
|
declare function Body(schema?: ZodTypeAny): LegacyParameterDecorator;
|
|
42
43
|
declare function Query(name?: string): LegacyParameterDecorator;
|
|
43
44
|
declare function Param(name?: string): LegacyParameterDecorator;
|
|
@@ -48,4 +49,4 @@ declare function Res(): LegacyParameterDecorator;
|
|
|
48
49
|
|
|
49
50
|
declare function configureRoutes(next?: RouteOptions): void;
|
|
50
51
|
|
|
51
|
-
export { Auth, Body, Delete, FirebaseAuth, FirebaseAuthOptions, Get, Head, Header, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, ResponseLike, RouteOptions, configureRoutes, createHandler, handleError, json, noContent, text };
|
|
52
|
+
export { Auth, Body, Delete, FirebaseAuth, FirebaseAuthOptions, Get, Head, Header, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, ResponseLike, RouteOptions, UserId, configureRoutes, createHandler, handleError, json, noContent, text };
|
package/dist/http/index.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ declare const Head: (path?: string) => LegacyDecorator;
|
|
|
38
38
|
declare const Options: (path?: string) => LegacyDecorator;
|
|
39
39
|
declare function FirebaseAuth(options?: FirebaseAuthOptions): LegacyDecorator;
|
|
40
40
|
declare function Auth(): LegacyParameterDecorator;
|
|
41
|
+
declare function UserId(): LegacyParameterDecorator;
|
|
41
42
|
declare function Body(schema?: ZodTypeAny): LegacyParameterDecorator;
|
|
42
43
|
declare function Query(name?: string): LegacyParameterDecorator;
|
|
43
44
|
declare function Param(name?: string): LegacyParameterDecorator;
|
|
@@ -48,4 +49,4 @@ declare function Res(): LegacyParameterDecorator;
|
|
|
48
49
|
|
|
49
50
|
declare function configureRoutes(next?: RouteOptions): void;
|
|
50
51
|
|
|
51
|
-
export { Auth, Body, Delete, FirebaseAuth, FirebaseAuthOptions, Get, Head, Header, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, ResponseLike, RouteOptions, configureRoutes, createHandler, handleError, json, noContent, text };
|
|
52
|
+
export { Auth, Body, Delete, FirebaseAuth, FirebaseAuthOptions, Get, Head, Header, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, ResponseLike, RouteOptions, UserId, configureRoutes, createHandler, handleError, json, noContent, text };
|
package/dist/http/index.js
CHANGED
|
@@ -16,12 +16,13 @@ import {
|
|
|
16
16
|
Query,
|
|
17
17
|
Req,
|
|
18
18
|
Res,
|
|
19
|
+
UserId,
|
|
19
20
|
createHandler,
|
|
20
21
|
handleError,
|
|
21
22
|
json,
|
|
22
23
|
noContent,
|
|
23
24
|
text
|
|
24
|
-
} from "../chunk-
|
|
25
|
+
} from "../chunk-P4HUTGVQ.js";
|
|
25
26
|
import "../chunk-5OUNKYO5.js";
|
|
26
27
|
import {
|
|
27
28
|
configureRoutes
|
|
@@ -44,6 +45,7 @@ export {
|
|
|
44
45
|
Query,
|
|
45
46
|
Req,
|
|
46
47
|
Res,
|
|
48
|
+
UserId,
|
|
47
49
|
configureRoutes,
|
|
48
50
|
createHandler,
|
|
49
51
|
handleError,
|
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
Query: () => Query,
|
|
39
39
|
Req: () => Req,
|
|
40
40
|
Res: () => Res,
|
|
41
|
+
UserId: () => UserId,
|
|
41
42
|
configureRoutes: () => configureRoutes,
|
|
42
43
|
createHandler: () => createHandler,
|
|
43
44
|
handleError: () => handleError,
|
|
@@ -389,6 +390,14 @@ function buildHandlerArguments(entry, ctx, getBody) {
|
|
|
389
390
|
args[meta.index] = ctx.auth;
|
|
390
391
|
break;
|
|
391
392
|
}
|
|
393
|
+
case "userId": {
|
|
394
|
+
const userId = resolveUserIdFromClaims(ctx.auth);
|
|
395
|
+
if (!userId) {
|
|
396
|
+
throw new HttpError(401, "Invalid authentication");
|
|
397
|
+
}
|
|
398
|
+
args[meta.index] = userId;
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
392
401
|
default: {
|
|
393
402
|
args[meta.index] = ctx;
|
|
394
403
|
}
|
|
@@ -475,6 +484,32 @@ function extractAuthClaims(event, entry) {
|
|
|
475
484
|
const claims = ctxV2?.authorizer?.jwt?.claims || ctxV1?.authorizer?.claims;
|
|
476
485
|
return claims ?? void 0;
|
|
477
486
|
}
|
|
487
|
+
function normalizeUserIdentifier(value) {
|
|
488
|
+
if (typeof value !== "string") {
|
|
489
|
+
return void 0;
|
|
490
|
+
}
|
|
491
|
+
const normalized = value.trim();
|
|
492
|
+
return normalized || void 0;
|
|
493
|
+
}
|
|
494
|
+
function resolveUserIdFromClaims(claims) {
|
|
495
|
+
const email = normalizeUserIdentifier(claims?.email);
|
|
496
|
+
if (email) {
|
|
497
|
+
return email.toLowerCase();
|
|
498
|
+
}
|
|
499
|
+
const userId = normalizeUserIdentifier(claims?.user_id);
|
|
500
|
+
if (userId) {
|
|
501
|
+
return userId;
|
|
502
|
+
}
|
|
503
|
+
const uid = normalizeUserIdentifier(claims?.uid);
|
|
504
|
+
if (uid) {
|
|
505
|
+
return uid;
|
|
506
|
+
}
|
|
507
|
+
const sub = normalizeUserIdentifier(claims?.sub);
|
|
508
|
+
if (sub) {
|
|
509
|
+
return sub;
|
|
510
|
+
}
|
|
511
|
+
return void 0;
|
|
512
|
+
}
|
|
478
513
|
function isHttpError(error) {
|
|
479
514
|
if (!error || typeof error !== "object") {
|
|
480
515
|
return false;
|
|
@@ -603,6 +638,9 @@ function FirebaseAuth(options2) {
|
|
|
603
638
|
function Auth() {
|
|
604
639
|
return createParameterDecorator("auth");
|
|
605
640
|
}
|
|
641
|
+
function UserId() {
|
|
642
|
+
return createParameterDecorator("userId");
|
|
643
|
+
}
|
|
606
644
|
function Body(schema) {
|
|
607
645
|
return createParameterDecorator("body", { schema });
|
|
608
646
|
}
|
|
@@ -775,6 +813,7 @@ function getSignedHeaders(headers) {
|
|
|
775
813
|
Query,
|
|
776
814
|
Req,
|
|
777
815
|
Res,
|
|
816
|
+
UserId,
|
|
778
817
|
configureRoutes,
|
|
779
818
|
createHandler,
|
|
780
819
|
handleError,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
1
|
+
export { Auth, Body, Delete, FirebaseAuth, Get, Head, Header, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, UserId, configureRoutes, createHandler, handleError, json, noContent, text } from './http/index.cjs';
|
|
2
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';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
1
|
+
export { Auth, Body, Delete, FirebaseAuth, Get, Head, Header, Headers, HttpError, Options, Param, Patch, Post, Put, Query, Req, Res, UserId, configureRoutes, createHandler, handleError, json, noContent, text } from './http/index.js';
|
|
2
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';
|
package/dist/index.js
CHANGED
|
@@ -20,12 +20,13 @@ import {
|
|
|
20
20
|
Query,
|
|
21
21
|
Req,
|
|
22
22
|
Res,
|
|
23
|
+
UserId,
|
|
23
24
|
createHandler,
|
|
24
25
|
handleError,
|
|
25
26
|
json,
|
|
26
27
|
noContent,
|
|
27
28
|
text
|
|
28
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-P4HUTGVQ.js";
|
|
29
30
|
import "./chunk-5OUNKYO5.js";
|
|
30
31
|
import {
|
|
31
32
|
configureRoutes
|
|
@@ -49,6 +50,7 @@ export {
|
|
|
49
50
|
Query,
|
|
50
51
|
Req,
|
|
51
52
|
Res,
|
|
53
|
+
UserId,
|
|
52
54
|
configureRoutes,
|
|
53
55
|
createHandler,
|
|
54
56
|
handleError,
|
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,
|