@ampless/backend 0.2.0-alpha.12 → 0.2.0-alpha.13

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.
@@ -627,17 +627,26 @@ async function validateBearer(plaintext) {
627
627
  );
628
628
  const row = res.Item;
629
629
  if (!row?.value) return null;
630
- let meta;
631
- try {
632
- meta = JSON.parse(row.value);
633
- } catch {
634
- console.error("[mcp-handler] could not parse token row", { hash });
630
+ const meta = decodeTokenMeta(row.value);
631
+ if (!meta) {
632
+ console.error("[mcp-handler] could not decode token row", { hash, valueType: typeof row.value });
635
633
  return null;
636
634
  }
637
635
  if (meta.revokedAt) return null;
638
636
  if (meta.expiresAt && new Date(meta.expiresAt).getTime() <= Date.now()) return null;
639
637
  return meta;
640
638
  }
639
+ function decodeTokenMeta(value) {
640
+ if (typeof value === "object") return value;
641
+ if (typeof value === "string") {
642
+ try {
643
+ return JSON.parse(value);
644
+ } catch {
645
+ return null;
646
+ }
647
+ }
648
+ return null;
649
+ }
641
650
  var cachedCtx = null;
642
651
  function makeContext(meta) {
643
652
  if (cachedCtx && cachedCtx.defaultSiteId === (meta.scope.siteId ?? "default")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampless/backend",
3
- "version": "0.2.0-alpha.12",
3
+ "version": "0.2.0-alpha.13",
4
4
  "description": "Amplify Gen 2 backend factories for ampless: auth, data, storage, event processors, API key renewer",
5
5
  "license": "MIT",
6
6
  "type": "module",