@crvouga/mockingbird-service-fcm 1.1.0 → 1.2.0

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/dist/admin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  fcmCredential
3
- } from "./chunk-5ZBL7JON.js";
3
+ } from "./chunk-TX5DICAS.js";
4
4
 
5
5
  // src/admin.ts
6
6
  import { Agent, createServer } from "node:https";
@@ -3,7 +3,7 @@ import {
3
3
  createRuntime,
4
4
  parseDuration,
5
5
  resolveAdminPrefix
6
- } from "./chunk-5ZBL7JON.js";
6
+ } from "./chunk-TX5DICAS.js";
7
7
 
8
8
  // ../../adapters/node/dist/cli.js
9
9
  import { readFile as readFile2 } from "node:fs/promises";
@@ -831,4 +831,4 @@ export {
831
831
  createServer2 as createServer,
832
832
  serveTarget
833
833
  };
834
- //# sourceMappingURL=chunk-EE7F2ZC6.js.map
834
+ //# sourceMappingURL=chunk-BBU3KFCD.js.map
@@ -1018,7 +1018,40 @@ var decodeBody = (contentType, bytes) => {
1018
1018
  return { kind: "bytes", value: bytes };
1019
1019
  };
1020
1020
  var readBody = async (message) => {
1021
- const bytes = new Uint8Array(await message.arrayBuffer());
1021
+ if (!(message instanceof Request) || !message.body) {
1022
+ if (message instanceof Request)
1023
+ message.signal.throwIfAborted();
1024
+ return decodeBody(message.headers.get("content-type"), new Uint8Array(await message.arrayBuffer()));
1025
+ }
1026
+ message.signal.throwIfAborted();
1027
+ const reader = message.body.getReader();
1028
+ const cancel = () => {
1029
+ void reader.cancel(message.signal.reason).catch(() => {
1030
+ });
1031
+ };
1032
+ message.signal.addEventListener("abort", cancel, { once: true });
1033
+ const chunks = [];
1034
+ let size = 0;
1035
+ try {
1036
+ for (; ; ) {
1037
+ message.signal.throwIfAborted();
1038
+ const { done, value } = await reader.read();
1039
+ message.signal.throwIfAborted();
1040
+ if (done)
1041
+ break;
1042
+ chunks.push(value);
1043
+ size += value.byteLength;
1044
+ }
1045
+ } finally {
1046
+ message.signal.removeEventListener("abort", cancel);
1047
+ reader.releaseLock();
1048
+ }
1049
+ const bytes = new Uint8Array(size);
1050
+ let offset = 0;
1051
+ for (const chunk of chunks) {
1052
+ bytes.set(chunk, offset);
1053
+ offset += chunk.byteLength;
1054
+ }
1022
1055
  return decodeBody(message.headers.get("content-type"), bytes);
1023
1056
  };
1024
1057
 
@@ -1734,7 +1767,42 @@ var verifyOperations = (document2, handlers) => {
1734
1767
  }
1735
1768
  return problems;
1736
1769
  };
1737
- var honoPath = (template) => template.replace(/\{([^}]+)\}/g, ":$1");
1770
+ var escapePattern = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1771
+ var serviceRoute = (template) => {
1772
+ const names = [];
1773
+ let pattern = "", end = 0;
1774
+ for (const match of template.matchAll(/\{([^}]+)\}/g)) {
1775
+ pattern += `${escapePattern(template.slice(end, match.index))}([^/]+?)`;
1776
+ const name = match[1];
1777
+ if (!name)
1778
+ throw new Error(`Invalid OpenAPI route template: ${template}`);
1779
+ names.push(name);
1780
+ end = match.index + match[0].length;
1781
+ }
1782
+ pattern += escapePattern(template.slice(end));
1783
+ const matcher = new RegExp(`^${pattern}$`);
1784
+ const path = template.split("/").map((segment, index) => {
1785
+ if (!segment.includes("{"))
1786
+ return segment;
1787
+ const literal = /^\{([^}]+)\}$/.exec(segment);
1788
+ if (literal)
1789
+ return `:${literal[1]}`;
1790
+ let expression = "", offset = 0;
1791
+ for (const match of segment.matchAll(/\{[^}]+\}/g)) {
1792
+ expression += `${escapePattern(segment.slice(offset, match.index))}[^/]+?`;
1793
+ offset = match.index + match[0].length;
1794
+ }
1795
+ expression += escapePattern(segment.slice(offset));
1796
+ return `:mockingbirdSegment${index}{${expression}}`;
1797
+ }).join("/");
1798
+ return {
1799
+ path,
1800
+ params: (pathname) => {
1801
+ const values = matcher.exec(pathname);
1802
+ return Object.fromEntries(names.map((name, index) => [name, decodeURIComponent(values?.[index + 1] ?? "")]));
1803
+ }
1804
+ };
1805
+ };
1738
1806
  var routeOrder = (a, b) => {
1739
1807
  const sa = a.path.split("/");
1740
1808
  const sb = b.path.split("/");
@@ -1769,6 +1837,7 @@ var createService = (options) => {
1769
1837
  for (const operation of operations) {
1770
1838
  const metadata = operationMetadata(operation.operation);
1771
1839
  const handler = options.handlers[operation.operationId];
1840
+ const registeredRoute = serviceRoute(operation.path);
1772
1841
  const route = async (c) => {
1773
1842
  const request = c.req.raw;
1774
1843
  if (!metadata.supported || !handler) {
@@ -1778,7 +1847,7 @@ var createService = (options) => {
1778
1847
  const context = {
1779
1848
  request,
1780
1849
  url,
1781
- params: c.req.param(),
1850
+ params: registeredRoute.params(url.pathname),
1782
1851
  query: queryOf(url),
1783
1852
  body: await readBody(request),
1784
1853
  sqlite: options.sqlite,
@@ -1790,7 +1859,7 @@ var createService = (options) => {
1790
1859
  const short = await options.before?.(context);
1791
1860
  return withIssues(request, short ?? await handler(context));
1792
1861
  };
1793
- app.on(operation.method.toUpperCase(), honoPath(operation.path), route);
1862
+ app.on(operation.method.toUpperCase(), registeredRoute.path, route);
1794
1863
  }
1795
1864
  return {
1796
1865
  app,
@@ -2259,7 +2328,7 @@ var stateAdminRoutes = (routes) => {
2259
2328
  };
2260
2329
 
2261
2330
  // ../core/dist/version.js
2262
- var PACKAGE_VERSION = true ? "1.1.0" : UNRELEASED_VERSION;
2331
+ var PACKAGE_VERSION = true ? "1.2.0" : UNRELEASED_VERSION;
2263
2332
 
2264
2333
  // ../core/dist/webhooks.js
2265
2334
  var json4 = (status, body) => new Response(JSON.stringify(body), {
@@ -3915,4 +3984,4 @@ export {
3915
3984
  fcmCredential,
3916
3985
  FcmAPI
3917
3986
  };
3918
- //# sourceMappingURL=chunk-5ZBL7JON.js.map
3987
+ //# sourceMappingURL=chunk-TX5DICAS.js.map