sst-http 1.0.0 → 1.3.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.
@@ -0,0 +1,13 @@
1
+ // src/paths.ts
2
+ var API_GATEWAY_PARAM_RE = /(^|\/):([A-Za-z0-9_]+(?:[+*])?)(?=\/|$)/g;
3
+ function normalizeRouterPath(path) {
4
+ return path.replace(/\{([^/{}]+)\}/g, ":$1");
5
+ }
6
+ function normalizeApiGatewayPath(path) {
7
+ return path.replace(API_GATEWAY_PARAM_RE, (_match, prefix, name) => `${prefix}{${name}}`);
8
+ }
9
+
10
+ export {
11
+ normalizeRouterPath,
12
+ normalizeApiGatewayPath
13
+ };
package/dist/cli.cjs CHANGED
@@ -6,6 +6,14 @@ var import_node_fs = require("fs");
6
6
  var import_node_path = require("path");
7
7
  var import_node_process = require("process");
8
8
  var import_ts_morph = require("ts-morph");
9
+
10
+ // src/paths.ts
11
+ var API_GATEWAY_PARAM_RE = /(^|\/):([A-Za-z0-9_]+(?:[+*])?)(?=\/|$)/g;
12
+ function normalizeApiGatewayPath(path) {
13
+ return path.replace(API_GATEWAY_PARAM_RE, (_match, prefix, name) => `${prefix}{${name}}`);
14
+ }
15
+
16
+ // src/cli.ts
9
17
  var METHOD_DECORATORS = {
10
18
  Get: "GET",
11
19
  Post: "POST",
@@ -150,7 +158,7 @@ function extractRoute(fn, inferName) {
150
158
  const auth = firebaseDecorator ? readFirebaseAuth(firebaseDecorator) : { type: "none" };
151
159
  return {
152
160
  method,
153
- path,
161
+ path: normalizeApiGatewayPath(path),
154
162
  auth
155
163
  };
156
164
  }
package/dist/cli.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ normalizeApiGatewayPath
4
+ } from "./chunk-5MOJ3SW6.js";
2
5
 
3
6
  // src/cli.ts
4
7
  import { writeFileSync } from "fs";
@@ -153,7 +156,7 @@ function extractRoute(fn, inferName) {
153
156
  const auth = firebaseDecorator ? readFirebaseAuth(firebaseDecorator) : { type: "none" };
154
157
  return {
155
158
  method,
156
- path,
159
+ path: normalizeApiGatewayPath(path),
157
160
  auth
158
161
  };
159
162
  }
package/dist/index.cjs CHANGED
@@ -122,12 +122,19 @@ function inferPath(handler) {
122
122
 
123
123
  // src/router.ts
124
124
  var import_path_to_regexp = require("path-to-regexp");
125
+
126
+ // src/paths.ts
127
+ function normalizeRouterPath(path) {
128
+ return path.replace(/\{([^/{}]+)\}/g, ":$1");
129
+ }
130
+
131
+ // src/router.ts
125
132
  var Router = class {
126
133
  routes;
127
134
  constructor(entries) {
128
135
  this.routes = entries.map((entry) => ({
129
136
  entry,
130
- matcher: (0, import_path_to_regexp.match)(normalizeRoutePath(entry.path), { decode: decodeURIComponent })
137
+ matcher: (0, import_path_to_regexp.match)(normalizeRouterPath(entry.path), { decode: decodeURIComponent })
131
138
  }));
132
139
  }
133
140
  find(method, pathname) {
@@ -162,9 +169,6 @@ function normalizeParams(params) {
162
169
  }
163
170
  return normalized;
164
171
  }
165
- function normalizeRoutePath(path) {
166
- return path.replace(/\{([^/{}]+)\}/g, ":$1");
167
- }
168
172
 
169
173
  // src/runtime.ts
170
174
  var HTTP_ERROR_MARKER = Symbol.for("sst-http.HttpError");
@@ -272,6 +276,7 @@ function createHandler() {
272
276
  try {
273
277
  bodyValue = schema.parse(current);
274
278
  } catch (error) {
279
+ console.error("[ERROR] Body validation failed", error);
275
280
  throw new HttpError(400, "Body validation failed", { cause: error });
276
281
  }
277
282
  }
package/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ import {
2
+ normalizeRouterPath
3
+ } from "./chunk-5MOJ3SW6.js";
4
+
1
5
  // src/registry.ts
2
6
  var routeMeta = /* @__PURE__ */ new Map();
3
7
  var parameterMeta = /* @__PURE__ */ new Map();
@@ -79,7 +83,7 @@ var Router = class {
79
83
  constructor(entries) {
80
84
  this.routes = entries.map((entry) => ({
81
85
  entry,
82
- matcher: match(normalizeRoutePath(entry.path), { decode: decodeURIComponent })
86
+ matcher: match(normalizeRouterPath(entry.path), { decode: decodeURIComponent })
83
87
  }));
84
88
  }
85
89
  find(method, pathname) {
@@ -114,9 +118,6 @@ function normalizeParams(params) {
114
118
  }
115
119
  return normalized;
116
120
  }
117
- function normalizeRoutePath(path) {
118
- return path.replace(/\{([^/{}]+)\}/g, ":$1");
119
- }
120
121
 
121
122
  // src/runtime.ts
122
123
  var HTTP_ERROR_MARKER = Symbol.for("sst-http.HttpError");
@@ -224,6 +225,7 @@ function createHandler() {
224
225
  try {
225
226
  bodyValue = schema.parse(current);
226
227
  } catch (error) {
228
+ console.error("[ERROR] Body validation failed", error);
227
229
  throw new HttpError(400, "Body validation failed", { cause: error });
228
230
  }
229
231
  }
package/dist/infra.cjs CHANGED
@@ -28,6 +28,14 @@ __export(infra_exports, {
28
28
  module.exports = __toCommonJS(infra_exports);
29
29
  var import_node_fs = require("fs");
30
30
  var import_node_path = require("path");
31
+
32
+ // src/paths.ts
33
+ var API_GATEWAY_PARAM_RE = /(^|\/):([A-Za-z0-9_]+(?:[+*])?)(?=\/|$)/g;
34
+ function normalizeApiGatewayPath(path) {
35
+ return path.replace(API_GATEWAY_PARAM_RE, (_match, prefix, name) => `${prefix}{${name}}`);
36
+ }
37
+
38
+ // src/infra.ts
31
39
  function ensureSstAws(source) {
32
40
  if (source?.sst?.aws) {
33
41
  return source.sst.aws;
@@ -58,7 +66,8 @@ function wireApiFromManifest(manifest, opts) {
58
66
  }
59
67
  for (const route of manifest.routes) {
60
68
  const isProtected = route.auth.type === "firebase";
61
- const path = route.path.startsWith("/") ? route.path : `/${route.path}`;
69
+ const rawPath = route.path.startsWith("/") ? route.path : `/${route.path}`;
70
+ const path = normalizeApiGatewayPath(rawPath);
62
71
  const authConfig = isProtected && route.auth.type === "firebase" ? {
63
72
  name: "firebase",
64
73
  optional: route.auth.optional,
@@ -124,7 +133,8 @@ function httpApiAdapter(args) {
124
133
  };
125
134
  const registerRoute = (method, path, config) => {
126
135
  const apiAny = api;
127
- const routeKey = `${method} ${path}`;
136
+ const normalizedPath = normalizeApiGatewayPath(path);
137
+ const routeKey = `${method} ${normalizedPath}`;
128
138
  const asAny = config.handler;
129
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 : (() => {
130
140
  throw new Error("Unsupported handler type: provide a handler string, FunctionArgs, or a Function ARN/output");
@@ -197,7 +207,8 @@ function restApiAdapter(args) {
197
207
  };
198
208
  const registerRoute = (method, path, config) => {
199
209
  const apiAny = api;
200
- const routeKey = `${method} ${path}`;
210
+ const normalizedPath = normalizeApiGatewayPath(path);
211
+ const routeKey = `${method} ${normalizedPath}`;
201
212
  const asAny = config.handler;
202
213
  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 : (() => {
203
214
  throw new Error("Unsupported handler type: provide a handler string, FunctionArgs, or a Function ARN/output");
package/dist/infra.js CHANGED
@@ -1,3 +1,7 @@
1
+ import {
2
+ normalizeApiGatewayPath
3
+ } from "./chunk-5MOJ3SW6.js";
4
+
1
5
  // src/infra.ts
2
6
  import { readFileSync } from "fs";
3
7
  import { resolve } from "path";
@@ -31,7 +35,8 @@ function wireApiFromManifest(manifest, opts) {
31
35
  }
32
36
  for (const route of manifest.routes) {
33
37
  const isProtected = route.auth.type === "firebase";
34
- const path = route.path.startsWith("/") ? route.path : `/${route.path}`;
38
+ const rawPath = route.path.startsWith("/") ? route.path : `/${route.path}`;
39
+ const path = normalizeApiGatewayPath(rawPath);
35
40
  const authConfig = isProtected && route.auth.type === "firebase" ? {
36
41
  name: "firebase",
37
42
  optional: route.auth.optional,
@@ -97,7 +102,8 @@ function httpApiAdapter(args) {
97
102
  };
98
103
  const registerRoute = (method, path, config) => {
99
104
  const apiAny = api;
100
- const routeKey = `${method} ${path}`;
105
+ const normalizedPath = normalizeApiGatewayPath(path);
106
+ const routeKey = `${method} ${normalizedPath}`;
101
107
  const asAny = config.handler;
102
108
  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 : (() => {
103
109
  throw new Error("Unsupported handler type: provide a handler string, FunctionArgs, or a Function ARN/output");
@@ -170,7 +176,8 @@ function restApiAdapter(args) {
170
176
  };
171
177
  const registerRoute = (method, path, config) => {
172
178
  const apiAny = api;
173
- const routeKey = `${method} ${path}`;
179
+ const normalizedPath = normalizeApiGatewayPath(path);
180
+ const routeKey = `${method} ${normalizedPath}`;
174
181
  const asAny = config.handler;
175
182
  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 : (() => {
176
183
  throw new Error("Unsupported handler type: provide a handler string, FunctionArgs, or a Function ARN/output");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst-http",
3
- "version": "1.0.0",
3
+ "version": "1.3.2",
4
4
  "description": "Decorator-based routing for SST v3 with a single Lambda and Firebase JWT authorizer.",
5
5
  "license": "MIT",
6
6
  "author": "",