sst-http 1.3.0 → 1.3.3-beta.2
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 +87 -28
- package/dist/bus/index.cjs +185 -0
- package/dist/bus/index.d.cts +7 -0
- package/dist/bus/index.d.ts +7 -0
- package/dist/bus/index.js +9 -0
- package/dist/{chunk-5MOJ3SW6.js → chunk-5OUNKYO5.js} +1 -1
- package/dist/chunk-LLR3DQ65.js +140 -0
- package/dist/chunk-SENBWWVV.js +499 -0
- package/dist/chunk-YMGEGOSD.js +117 -0
- package/dist/cli.cjs +49 -13
- package/dist/cli.js +49 -13
- package/dist/handler-DaM4Racx.d.cts +4 -0
- package/dist/handler-DaM4Racx.d.ts +4 -0
- package/dist/http/index.cjs +644 -0
- package/dist/http/index.d.cts +51 -0
- package/dist/http/index.d.ts +51 -0
- package/dist/http/index.js +53 -0
- package/dist/index.cjs +205 -14
- package/dist/index.d.cts +6 -45
- package/dist/index.d.ts +6 -45
- package/dist/index.js +33 -516
- package/dist/infra.cjs +273 -126
- package/dist/infra.d.cts +35 -18
- package/dist/infra.d.ts +35 -18
- package/dist/infra.js +268 -121
- package/dist/{types-BF3w-wTx.d.cts → types-w1A7o_rd.d.cts} +5 -1
- package/dist/{types-BF3w-wTx.d.ts → types-w1A7o_rd.d.ts} +5 -1
- package/package.json +16 -5
package/dist/infra.cjs
CHANGED
|
@@ -20,6 +20,8 @@ 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,
|
|
23
25
|
httpApiAdapter: () => httpApiAdapter,
|
|
24
26
|
loadRoutesManifest: () => loadRoutesManifest,
|
|
25
27
|
restApiAdapter: () => restApiAdapter,
|
|
@@ -29,18 +31,32 @@ module.exports = __toCommonJS(infra_exports);
|
|
|
29
31
|
var import_node_fs = require("fs");
|
|
30
32
|
var import_node_path = require("path");
|
|
31
33
|
|
|
32
|
-
// src/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return path.replace(API_GATEWAY_PARAM_RE, (_match, prefix, name) => `${prefix}{${name}}`);
|
|
34
|
+
// src/core/infra.ts
|
|
35
|
+
function isRecord(value) {
|
|
36
|
+
return typeof value === "object" && value !== null;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
function getFunction(value, key) {
|
|
39
|
+
if (!isRecord(value)) {
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
const candidate = value[key];
|
|
43
|
+
return typeof candidate === "function" ? candidate : void 0;
|
|
44
|
+
}
|
|
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
|
+
function ensureRecord(value, message) {
|
|
53
|
+
if (!isRecord(value)) {
|
|
54
|
+
throw new Error(message);
|
|
42
55
|
}
|
|
43
|
-
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
function ensureSstAws(source) {
|
|
59
|
+
const aws = typeof sst !== "undefined" ? sst.aws : source?.sst?.aws ?? globalThis.sst?.aws;
|
|
44
60
|
if (!aws) {
|
|
45
61
|
throw new Error(
|
|
46
62
|
"SST aws namespace is not available. Ensure this code runs within an SST config."
|
|
@@ -48,32 +64,133 @@ function ensureSstAws(source) {
|
|
|
48
64
|
}
|
|
49
65
|
return aws;
|
|
50
66
|
}
|
|
51
|
-
function
|
|
52
|
-
if (
|
|
53
|
-
|
|
67
|
+
function resolveHandlerInput(handler) {
|
|
68
|
+
if (handler === void 0) {
|
|
69
|
+
return void 0;
|
|
54
70
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
if (typeof handler === "string") {
|
|
72
|
+
return handler;
|
|
73
|
+
}
|
|
74
|
+
if (!isRecord(handler)) {
|
|
75
|
+
throw new Error("Unsupported handler type: provide a handler string, FunctionArgs, or a Function ARN/output");
|
|
76
|
+
}
|
|
77
|
+
if ("arn" in handler) {
|
|
78
|
+
return handler.arn;
|
|
79
|
+
}
|
|
80
|
+
if (typeof handler.handler === "string") {
|
|
81
|
+
return handler;
|
|
82
|
+
}
|
|
83
|
+
throw new Error("Unsupported handler type: provide a handler string, FunctionArgs, or a Function ARN/output");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/bus/infra.ts
|
|
87
|
+
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
|
+
function wireEventsFromManifest(events, opts) {
|
|
97
|
+
if (!events || events.length === 0) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const aws = ensureSstAws(opts.source);
|
|
101
|
+
const busMap = normalizeBusInput(opts.buses);
|
|
102
|
+
const subscriber = resolveHandlerInput(opts.handler);
|
|
103
|
+
const seen = /* @__PURE__ */ new Set();
|
|
104
|
+
for (const event of events) {
|
|
105
|
+
const key = `default:${event.event}`;
|
|
106
|
+
if (seen.has(key)) {
|
|
107
|
+
continue;
|
|
60
108
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
109
|
+
seen.add(key);
|
|
110
|
+
const bus = resolveBusForEvent(busMap, aws);
|
|
111
|
+
const subscriberName = buildSubscriberName(event.event);
|
|
112
|
+
subscribeToBus(bus, subscriberName, subscriber, event.event);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
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;
|
|
66
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
|
+
function subscribeToBus(bus, subscriberName, subscriber, eventName) {
|
|
162
|
+
if (typeof bus.subscribe !== "function") {
|
|
163
|
+
throw new Error("Bus instance does not support subscribe().");
|
|
164
|
+
}
|
|
165
|
+
bus.subscribe(subscriberName, subscriber, {
|
|
166
|
+
pattern: {
|
|
167
|
+
detailType: [eventName]
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function buildSubscriberName(eventName) {
|
|
172
|
+
const base = `default-${eventName}`.replace(/[^a-zA-Z0-9]/g, "");
|
|
173
|
+
if (base.length === 0) {
|
|
174
|
+
return "Event";
|
|
175
|
+
}
|
|
176
|
+
return base.length > MAX_SUBSCRIBER_NAME_LENGTH ? base.slice(0, MAX_SUBSCRIBER_NAME_LENGTH) : base;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/http/paths.ts
|
|
180
|
+
var API_GATEWAY_PARAM_RE = /(^|\/):([A-Za-z0-9_]+(?:[+*])?)(?=\/|$)/g;
|
|
181
|
+
function normalizeApiGatewayPath(path) {
|
|
182
|
+
return path.replace(API_GATEWAY_PARAM_RE, (_match, prefix, name) => `${prefix}{${name}}`);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/http/infra.ts
|
|
186
|
+
function wireRoutesFromManifest(manifest, opts) {
|
|
187
|
+
const firebaseRoutes = manifest.routes.filter((route) => route.auth.type === "firebase");
|
|
188
|
+
const firebaseAuthorizerRef = ensureFirebaseAuthorizer(firebaseRoutes.length, opts);
|
|
67
189
|
for (const route of manifest.routes) {
|
|
68
190
|
const isProtected = route.auth.type === "firebase";
|
|
69
191
|
const rawPath = route.path.startsWith("/") ? route.path : `/${route.path}`;
|
|
70
192
|
const path = normalizeApiGatewayPath(rawPath);
|
|
71
|
-
const authConfig =
|
|
72
|
-
name: "firebase",
|
|
73
|
-
optional: route.auth.optional,
|
|
74
|
-
roles: route.auth.roles,
|
|
75
|
-
ref: firebaseAuthorizerRef
|
|
76
|
-
} : void 0;
|
|
193
|
+
const authConfig = buildAuthorizerConfig(route, firebaseAuthorizerRef);
|
|
77
194
|
opts.registerRoute(route.method, path, {
|
|
78
195
|
handler: opts.handler,
|
|
79
196
|
protected: isProtected,
|
|
@@ -81,33 +198,74 @@ function wireApiFromManifest(manifest, opts) {
|
|
|
81
198
|
});
|
|
82
199
|
}
|
|
83
200
|
}
|
|
84
|
-
function loadRoutesManifest(filePath) {
|
|
85
|
-
const resolved = (0, import_node_path.resolve)(filePath);
|
|
86
|
-
const contents = (0, import_node_fs.readFileSync)(resolved, "utf8");
|
|
87
|
-
const manifest = JSON.parse(contents);
|
|
88
|
-
if (!manifest || !Array.isArray(manifest.routes)) {
|
|
89
|
-
throw new Error(`Invalid routes manifest at ${resolved}`);
|
|
90
|
-
}
|
|
91
|
-
return manifest;
|
|
92
|
-
}
|
|
93
201
|
function httpApiAdapter(args) {
|
|
94
202
|
const aws = args?.api ? void 0 : ensureSstAws(args);
|
|
95
203
|
const api = args?.api ?? new aws.ApiGatewayV2(args?.apiName ?? "HttpApi", args?.apiArgs);
|
|
204
|
+
const ensureJwtAuthorizer = createHttpAuthorizerManager(api);
|
|
205
|
+
const registerRoute = createRouteRegistrar(api, "ApiGatewayV2");
|
|
206
|
+
return {
|
|
207
|
+
api,
|
|
208
|
+
registerRoute,
|
|
209
|
+
ensureJwtAuthorizer
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function restApiAdapter(args) {
|
|
213
|
+
const aws = args?.api ? void 0 : ensureSstAws(args);
|
|
214
|
+
const api = args?.api ?? new aws.ApiGateway(args?.apiName ?? "RestApi", args?.apiArgs);
|
|
215
|
+
const ensureJwtAuthorizer = createRestAuthorizerManager(api);
|
|
216
|
+
const registerRoute = createRouteRegistrar(api, "ApiGateway");
|
|
217
|
+
return {
|
|
218
|
+
api,
|
|
219
|
+
registerRoute,
|
|
220
|
+
ensureJwtAuthorizer
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function ensureFirebaseAuthorizer(firebaseRouteCount, opts) {
|
|
224
|
+
if (firebaseRouteCount === 0) {
|
|
225
|
+
return void 0;
|
|
226
|
+
}
|
|
227
|
+
if (!opts.firebaseProjectId) {
|
|
228
|
+
throw new Error("firebaseProjectId is required when using @FirebaseAuth()");
|
|
229
|
+
}
|
|
230
|
+
const issuer = `https://securetoken.google.com/${opts.firebaseProjectId}`;
|
|
231
|
+
return opts.ensureJwtAuthorizer("firebase", {
|
|
232
|
+
issuer,
|
|
233
|
+
audiences: [opts.firebaseProjectId]
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
function buildAuthorizerConfig(route, firebaseAuthorizerRef) {
|
|
237
|
+
if (route.auth.type !== "firebase") {
|
|
238
|
+
return void 0;
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
name: "firebase",
|
|
242
|
+
optional: route.auth.optional,
|
|
243
|
+
roles: route.auth.roles,
|
|
244
|
+
ref: firebaseAuthorizerRef
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function createHttpAuthorizerManager(api) {
|
|
96
248
|
const authorizers = /* @__PURE__ */ new Map();
|
|
97
|
-
|
|
249
|
+
return (name, cfg) => {
|
|
98
250
|
if (authorizers.has(name)) {
|
|
99
251
|
return authorizers.get(name);
|
|
100
252
|
}
|
|
101
|
-
const
|
|
253
|
+
const addAuthorizer = getFunction(api, "addAuthorizer");
|
|
254
|
+
const addAuthorizers = getFunction(api, "addAuthorizers");
|
|
255
|
+
const authorizer = getFunction(api, "authorizer");
|
|
102
256
|
let ref = void 0;
|
|
103
|
-
if (
|
|
104
|
-
const created =
|
|
257
|
+
if (addAuthorizer) {
|
|
258
|
+
const created = addAuthorizer.call(api, {
|
|
105
259
|
name,
|
|
106
260
|
jwt: { issuer: cfg.issuer, audiences: cfg.audiences }
|
|
107
261
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
262
|
+
if (isRecord(created) && "id" in created) {
|
|
263
|
+
ref = created.id ?? created;
|
|
264
|
+
} else {
|
|
265
|
+
ref = created;
|
|
266
|
+
}
|
|
267
|
+
} else if (addAuthorizers) {
|
|
268
|
+
addAuthorizers.call(api, {
|
|
111
269
|
[name]: {
|
|
112
270
|
type: "jwt",
|
|
113
271
|
jwt: {
|
|
@@ -117,8 +275,8 @@ function httpApiAdapter(args) {
|
|
|
117
275
|
}
|
|
118
276
|
});
|
|
119
277
|
ref = name;
|
|
120
|
-
} else if (
|
|
121
|
-
ref =
|
|
278
|
+
} else if (authorizer) {
|
|
279
|
+
ref = authorizer.call(api, name, {
|
|
122
280
|
type: "jwt",
|
|
123
281
|
jwt: {
|
|
124
282
|
issuer: cfg.issuer,
|
|
@@ -131,58 +289,13 @@ function httpApiAdapter(args) {
|
|
|
131
289
|
authorizers.set(name, ref);
|
|
132
290
|
return ref;
|
|
133
291
|
};
|
|
134
|
-
const registerRoute = (method, path, config) => {
|
|
135
|
-
const apiAny = api;
|
|
136
|
-
const normalizedPath = normalizeApiGatewayPath(path);
|
|
137
|
-
const routeKey = `${method} ${normalizedPath}`;
|
|
138
|
-
const asAny = config.handler;
|
|
139
|
-
const handlerInput = typeof asAny === "string" ? asAny : asAny && typeof asAny.arn !== "undefined" ? asAny.arn : asAny && typeof asAny.handler === "string" ? asAny.handler : asAny === void 0 ? void 0 : (() => {
|
|
140
|
-
throw new Error("Unsupported handler type: provide a handler string, FunctionArgs, or a Function ARN/output");
|
|
141
|
-
})();
|
|
142
|
-
const args2 = {};
|
|
143
|
-
if (config.protected && config.authorizer) {
|
|
144
|
-
args2.auth = {
|
|
145
|
-
jwt: {
|
|
146
|
-
authorizer: config.authorizer.ref ?? config.authorizer.name,
|
|
147
|
-
scopes: config.authorizer.roles
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
if (typeof apiAny.route === "function") {
|
|
152
|
-
apiAny.route(routeKey, handlerInput, args2);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (typeof apiAny.addRoutes === "function") {
|
|
156
|
-
apiAny.addRoutes({
|
|
157
|
-
[routeKey]: {
|
|
158
|
-
handler: handlerInput,
|
|
159
|
-
...args2
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
if (typeof apiAny.addRoute === "function") {
|
|
165
|
-
apiAny.addRoute(routeKey, { handler: handlerInput, ...args2 });
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
throw new Error("Unsupported ApiGatewayV2 instance: expected route() or addRoutes() method.");
|
|
169
|
-
};
|
|
170
|
-
return {
|
|
171
|
-
api,
|
|
172
|
-
registerRoute,
|
|
173
|
-
ensureJwtAuthorizer
|
|
174
|
-
};
|
|
175
292
|
}
|
|
176
|
-
function
|
|
177
|
-
const aws = args?.api ? void 0 : ensureSstAws(args);
|
|
178
|
-
const api = args?.api ?? new aws.ApiGateway(args?.apiName ?? "RestApi", args?.apiArgs);
|
|
293
|
+
function createRestAuthorizerManager(api) {
|
|
179
294
|
const authorizers = /* @__PURE__ */ new Map();
|
|
180
|
-
|
|
295
|
+
return (name, cfg) => {
|
|
181
296
|
if (authorizers.has(name)) {
|
|
182
297
|
return authorizers.get(name);
|
|
183
298
|
}
|
|
184
|
-
const apiAny = api;
|
|
185
|
-
let ref = name;
|
|
186
299
|
const payload = {
|
|
187
300
|
type: "jwt",
|
|
188
301
|
jwt: {
|
|
@@ -190,65 +303,99 @@ function restApiAdapter(args) {
|
|
|
190
303
|
audience: cfg.audiences
|
|
191
304
|
}
|
|
192
305
|
};
|
|
193
|
-
|
|
194
|
-
|
|
306
|
+
const addAuthorizers = getFunction(api, "addAuthorizers");
|
|
307
|
+
const authorizer = getFunction(api, "authorizer");
|
|
308
|
+
let ref = name;
|
|
309
|
+
if (addAuthorizers) {
|
|
310
|
+
addAuthorizers.call(api, {
|
|
195
311
|
[name]: payload
|
|
196
312
|
});
|
|
197
|
-
} else if (
|
|
198
|
-
ref =
|
|
313
|
+
} else if (authorizer) {
|
|
314
|
+
ref = authorizer.call(api, name, payload);
|
|
199
315
|
} else {
|
|
200
|
-
|
|
201
|
-
|
|
316
|
+
const apiRecord = ensureRecord(api, "ApiGateway instance does not support authorizers.");
|
|
317
|
+
const current = isRecord(apiRecord.authorizers) ? apiRecord.authorizers : {};
|
|
318
|
+
apiRecord.authorizers = {
|
|
319
|
+
...current,
|
|
202
320
|
[name]: payload
|
|
203
321
|
};
|
|
204
322
|
}
|
|
205
323
|
authorizers.set(name, ref);
|
|
206
324
|
return ref;
|
|
207
325
|
};
|
|
208
|
-
|
|
209
|
-
|
|
326
|
+
}
|
|
327
|
+
function createRouteRegistrar(api, apiLabel) {
|
|
328
|
+
return (method, path, config) => {
|
|
210
329
|
const normalizedPath = normalizeApiGatewayPath(path);
|
|
211
330
|
const routeKey = `${method} ${normalizedPath}`;
|
|
212
|
-
const
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (config.protected && config.authorizer) {
|
|
218
|
-
args2.auth = {
|
|
219
|
-
jwt: {
|
|
220
|
-
authorizer: config.authorizer.ref ?? config.authorizer.name,
|
|
221
|
-
scopes: config.authorizer.roles
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
if (typeof apiAny.route === "function") {
|
|
226
|
-
apiAny.route(routeKey, handlerInput, args2);
|
|
331
|
+
const handlerInput = resolveHandlerInput(config.handler);
|
|
332
|
+
const args = buildRouteArgs(config);
|
|
333
|
+
const route = getFunction(api, "route");
|
|
334
|
+
if (route) {
|
|
335
|
+
route.call(api, routeKey, handlerInput, args);
|
|
227
336
|
return;
|
|
228
337
|
}
|
|
229
|
-
|
|
230
|
-
|
|
338
|
+
const addRoutes = getFunction(api, "addRoutes");
|
|
339
|
+
if (addRoutes) {
|
|
340
|
+
addRoutes.call(api, {
|
|
231
341
|
[routeKey]: {
|
|
232
342
|
handler: handlerInput,
|
|
233
|
-
...
|
|
343
|
+
...args
|
|
234
344
|
}
|
|
235
345
|
});
|
|
236
346
|
return;
|
|
237
347
|
}
|
|
238
|
-
|
|
239
|
-
|
|
348
|
+
const addRoute = getFunction(api, "addRoute");
|
|
349
|
+
if (addRoute) {
|
|
350
|
+
addRoute.call(api, routeKey, { handler: handlerInput, ...args });
|
|
240
351
|
return;
|
|
241
352
|
}
|
|
242
|
-
throw new Error(
|
|
353
|
+
throw new Error(`Unsupported ${apiLabel} instance: expected route() or addRoutes() method.`);
|
|
243
354
|
};
|
|
355
|
+
}
|
|
356
|
+
function buildRouteArgs(config) {
|
|
357
|
+
if (!config.protected || !config.authorizer) {
|
|
358
|
+
return {};
|
|
359
|
+
}
|
|
244
360
|
return {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
361
|
+
auth: {
|
|
362
|
+
jwt: {
|
|
363
|
+
authorizer: config.authorizer.ref ?? config.authorizer.name,
|
|
364
|
+
scopes: config.authorizer.roles
|
|
365
|
+
}
|
|
366
|
+
}
|
|
248
367
|
};
|
|
249
368
|
}
|
|
369
|
+
|
|
370
|
+
// src/infra.ts
|
|
371
|
+
function wireApiFromManifest(manifest, opts) {
|
|
372
|
+
if (!manifest || !Array.isArray(manifest.routes)) {
|
|
373
|
+
throw new Error("Invalid routes manifest");
|
|
374
|
+
}
|
|
375
|
+
wireRoutesFromManifest(manifest, {
|
|
376
|
+
handler: opts.handler,
|
|
377
|
+
firebaseProjectId: opts.firebaseProjectId,
|
|
378
|
+
registerRoute: opts.registerRoute,
|
|
379
|
+
ensureJwtAuthorizer: opts.ensureJwtAuthorizer
|
|
380
|
+
});
|
|
381
|
+
wireEventsFromManifest(manifest.events, {
|
|
382
|
+
handler: opts.handler,
|
|
383
|
+
buses: opts.buses
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
function loadRoutesManifest(filePath) {
|
|
387
|
+
const resolved = (0, import_node_path.resolve)(filePath);
|
|
388
|
+
const contents = (0, import_node_fs.readFileSync)(resolved, "utf8");
|
|
389
|
+
const manifest = JSON.parse(contents);
|
|
390
|
+
if (!manifest || !Array.isArray(manifest.routes)) {
|
|
391
|
+
throw new Error(`Invalid routes manifest at ${resolved}`);
|
|
392
|
+
}
|
|
393
|
+
return manifest;
|
|
394
|
+
}
|
|
250
395
|
// Annotate the CommonJS export names for ESM import in node:
|
|
251
396
|
0 && (module.exports = {
|
|
397
|
+
createBus,
|
|
398
|
+
getBus,
|
|
252
399
|
httpApiAdapter,
|
|
253
400
|
loadRoutesManifest,
|
|
254
401
|
restApiAdapter,
|
package/dist/infra.d.cts
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { f as RoutesManifestEvent, b as HttpMethod, g as RoutesManifest } from './types-w1A7o_rd.cjs';
|
|
2
|
+
export { i as RoutesManifestAuth, h as RoutesManifestRoute } from './types-w1A7o_rd.cjs';
|
|
3
3
|
import 'aws-lambda';
|
|
4
4
|
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
9
14
|
};
|
|
10
15
|
type AwsSource = {
|
|
11
16
|
sst?: {
|
|
12
|
-
aws?:
|
|
17
|
+
aws?: unknown;
|
|
13
18
|
};
|
|
14
19
|
};
|
|
20
|
+
|
|
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
|
+
|
|
15
30
|
type RegisterRouteConfig = {
|
|
16
31
|
handler: unknown;
|
|
17
32
|
protected: boolean;
|
|
@@ -27,27 +42,29 @@ type EnsureJwtAuthorizer = (name: string, cfg: {
|
|
|
27
42
|
issuer: string;
|
|
28
43
|
audiences: string[];
|
|
29
44
|
}) => unknown;
|
|
30
|
-
declare function wireApiFromManifest(manifest: RoutesManifest, opts: {
|
|
31
|
-
handler: unknown;
|
|
32
|
-
firebaseProjectId: string;
|
|
33
|
-
registerRoute: RegisterRoute;
|
|
34
|
-
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
35
|
-
}): void;
|
|
36
|
-
declare function loadRoutesManifest(filePath: string): RoutesManifest;
|
|
37
45
|
type AdapterArgs = AwsSource & {
|
|
38
|
-
api?:
|
|
46
|
+
api?: unknown;
|
|
39
47
|
apiName?: string;
|
|
40
48
|
apiArgs?: unknown;
|
|
41
49
|
};
|
|
42
50
|
declare function httpApiAdapter(args?: AdapterArgs): {
|
|
43
|
-
api:
|
|
51
|
+
api: unknown;
|
|
44
52
|
registerRoute: RegisterRoute;
|
|
45
53
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
46
54
|
};
|
|
47
55
|
declare function restApiAdapter(args?: AdapterArgs): {
|
|
48
|
-
api:
|
|
56
|
+
api: unknown;
|
|
49
57
|
registerRoute: RegisterRoute;
|
|
50
58
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
51
59
|
};
|
|
52
60
|
|
|
53
|
-
|
|
61
|
+
declare function wireApiFromManifest(manifest: RoutesManifest, opts: {
|
|
62
|
+
handler: unknown;
|
|
63
|
+
firebaseProjectId: string;
|
|
64
|
+
registerRoute: RegisterRoute;
|
|
65
|
+
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
66
|
+
buses?: Parameters<typeof wireEventsFromManifest>[1]["buses"];
|
|
67
|
+
}): void;
|
|
68
|
+
declare function loadRoutesManifest(filePath: string): RoutesManifest;
|
|
69
|
+
|
|
70
|
+
export { type EnsureJwtAuthorizer, type RegisterRoute, type RegisterRouteConfig, RoutesManifest, RoutesManifestEvent, createBus, getBus, httpApiAdapter, loadRoutesManifest, restApiAdapter, wireApiFromManifest };
|
package/dist/infra.d.ts
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { f as RoutesManifestEvent, b as HttpMethod, g as RoutesManifest } from './types-w1A7o_rd.js';
|
|
2
|
+
export { i as RoutesManifestAuth, h as RoutesManifestRoute } from './types-w1A7o_rd.js';
|
|
3
3
|
import 'aws-lambda';
|
|
4
4
|
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
9
14
|
};
|
|
10
15
|
type AwsSource = {
|
|
11
16
|
sst?: {
|
|
12
|
-
aws?:
|
|
17
|
+
aws?: unknown;
|
|
13
18
|
};
|
|
14
19
|
};
|
|
20
|
+
|
|
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
|
+
|
|
15
30
|
type RegisterRouteConfig = {
|
|
16
31
|
handler: unknown;
|
|
17
32
|
protected: boolean;
|
|
@@ -27,27 +42,29 @@ type EnsureJwtAuthorizer = (name: string, cfg: {
|
|
|
27
42
|
issuer: string;
|
|
28
43
|
audiences: string[];
|
|
29
44
|
}) => unknown;
|
|
30
|
-
declare function wireApiFromManifest(manifest: RoutesManifest, opts: {
|
|
31
|
-
handler: unknown;
|
|
32
|
-
firebaseProjectId: string;
|
|
33
|
-
registerRoute: RegisterRoute;
|
|
34
|
-
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
35
|
-
}): void;
|
|
36
|
-
declare function loadRoutesManifest(filePath: string): RoutesManifest;
|
|
37
45
|
type AdapterArgs = AwsSource & {
|
|
38
|
-
api?:
|
|
46
|
+
api?: unknown;
|
|
39
47
|
apiName?: string;
|
|
40
48
|
apiArgs?: unknown;
|
|
41
49
|
};
|
|
42
50
|
declare function httpApiAdapter(args?: AdapterArgs): {
|
|
43
|
-
api:
|
|
51
|
+
api: unknown;
|
|
44
52
|
registerRoute: RegisterRoute;
|
|
45
53
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
46
54
|
};
|
|
47
55
|
declare function restApiAdapter(args?: AdapterArgs): {
|
|
48
|
-
api:
|
|
56
|
+
api: unknown;
|
|
49
57
|
registerRoute: RegisterRoute;
|
|
50
58
|
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
51
59
|
};
|
|
52
60
|
|
|
53
|
-
|
|
61
|
+
declare function wireApiFromManifest(manifest: RoutesManifest, opts: {
|
|
62
|
+
handler: unknown;
|
|
63
|
+
firebaseProjectId: string;
|
|
64
|
+
registerRoute: RegisterRoute;
|
|
65
|
+
ensureJwtAuthorizer: EnsureJwtAuthorizer;
|
|
66
|
+
buses?: Parameters<typeof wireEventsFromManifest>[1]["buses"];
|
|
67
|
+
}): void;
|
|
68
|
+
declare function loadRoutesManifest(filePath: string): RoutesManifest;
|
|
69
|
+
|
|
70
|
+
export { type EnsureJwtAuthorizer, type RegisterRoute, type RegisterRouteConfig, RoutesManifest, RoutesManifestEvent, createBus, getBus, httpApiAdapter, loadRoutesManifest, restApiAdapter, wireApiFromManifest };
|