@crvouga/mockingbird-service-easypost 2.1.0 → 2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog — @crvouga/mockingbird-service-easypost
2
2
 
3
+ ## 2.2.0 (2026-10-05)
4
+
5
+ ### Features
6
+
7
+ - add scripted local API mock ([4a76a11](https://github.com/crvouga/mockingbird/commit/4a76a114e2efad45934e0a93cf29576fd418e15c))
8
+
9
+ ### Fixes and improvements
10
+
11
+ - support embedded route parameters ([127cad9](https://github.com/crvouga/mockingbird/commit/127cad997ef106950c1b866070eea191ba54403f))
12
+
3
13
  ## 2.1.0 (2026-10-04)
4
14
 
5
15
  ### Features
@@ -12,10 +22,6 @@
12
22
  - fill the embedded viewport ([c1a35a4](https://github.com/crvouga/mockingbird/commit/c1a35a4789389ee9cd06c286d09bd47c4d06c71e))
13
23
  - make dialog cleanup immediate ([0c1a3c5](https://github.com/crvouga/mockingbird/commit/0c1a3c5b12584d50c19dcae595b951b8e5417b9c))
14
24
 
15
- ### Dependencies
16
-
17
- - `@crvouga/mockingbird-service-sqlite`
18
-
19
25
  ## 2.0.0 (2026-10-04)
20
26
 
21
27
  ### ⚠️ Breaking changes
@@ -1029,7 +1029,40 @@ var decodeBody = (contentType, bytes) => {
1029
1029
  return { kind: "bytes", value: bytes };
1030
1030
  };
1031
1031
  var readBody = async (message) => {
1032
- const bytes = new Uint8Array(await message.arrayBuffer());
1032
+ if (!(message instanceof Request) || !message.body) {
1033
+ if (message instanceof Request)
1034
+ message.signal.throwIfAborted();
1035
+ return decodeBody(message.headers.get("content-type"), new Uint8Array(await message.arrayBuffer()));
1036
+ }
1037
+ message.signal.throwIfAborted();
1038
+ const reader = message.body.getReader();
1039
+ const cancel = () => {
1040
+ void reader.cancel(message.signal.reason).catch(() => {
1041
+ });
1042
+ };
1043
+ message.signal.addEventListener("abort", cancel, { once: true });
1044
+ const chunks = [];
1045
+ let size = 0;
1046
+ try {
1047
+ for (; ; ) {
1048
+ message.signal.throwIfAborted();
1049
+ const { done, value } = await reader.read();
1050
+ message.signal.throwIfAborted();
1051
+ if (done)
1052
+ break;
1053
+ chunks.push(value);
1054
+ size += value.byteLength;
1055
+ }
1056
+ } finally {
1057
+ message.signal.removeEventListener("abort", cancel);
1058
+ reader.releaseLock();
1059
+ }
1060
+ const bytes = new Uint8Array(size);
1061
+ let offset = 0;
1062
+ for (const chunk of chunks) {
1063
+ bytes.set(chunk, offset);
1064
+ offset += chunk.byteLength;
1065
+ }
1033
1066
  return decodeBody(message.headers.get("content-type"), bytes);
1034
1067
  };
1035
1068
 
@@ -1808,7 +1841,42 @@ var verifyOperations = (document2, handlers) => {
1808
1841
  }
1809
1842
  return problems;
1810
1843
  };
1811
- var honoPath = (template) => template.replace(/\{([^}]+)\}/g, ":$1");
1844
+ var escapePattern = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1845
+ var serviceRoute = (template) => {
1846
+ const names = [];
1847
+ let pattern = "", end = 0;
1848
+ for (const match of template.matchAll(/\{([^}]+)\}/g)) {
1849
+ pattern += `${escapePattern(template.slice(end, match.index))}([^/]+?)`;
1850
+ const name = match[1];
1851
+ if (!name)
1852
+ throw new Error(`Invalid OpenAPI route template: ${template}`);
1853
+ names.push(name);
1854
+ end = match.index + match[0].length;
1855
+ }
1856
+ pattern += escapePattern(template.slice(end));
1857
+ const matcher = new RegExp(`^${pattern}$`);
1858
+ const path = template.split("/").map((segment, index) => {
1859
+ if (!segment.includes("{"))
1860
+ return segment;
1861
+ const literal = /^\{([^}]+)\}$/.exec(segment);
1862
+ if (literal)
1863
+ return `:${literal[1]}`;
1864
+ let expression = "", offset = 0;
1865
+ for (const match of segment.matchAll(/\{[^}]+\}/g)) {
1866
+ expression += `${escapePattern(segment.slice(offset, match.index))}[^/]+?`;
1867
+ offset = match.index + match[0].length;
1868
+ }
1869
+ expression += escapePattern(segment.slice(offset));
1870
+ return `:mockingbirdSegment${index}{${expression}}`;
1871
+ }).join("/");
1872
+ return {
1873
+ path,
1874
+ params: (pathname) => {
1875
+ const values = matcher.exec(pathname);
1876
+ return Object.fromEntries(names.map((name, index) => [name, decodeURIComponent(values?.[index + 1] ?? "")]));
1877
+ }
1878
+ };
1879
+ };
1812
1880
  var routeOrder = (a, b) => {
1813
1881
  const sa = a.path.split("/");
1814
1882
  const sb = b.path.split("/");
@@ -1843,6 +1911,7 @@ var createService = (options) => {
1843
1911
  for (const operation of operations) {
1844
1912
  const metadata = operationMetadata(operation.operation);
1845
1913
  const handler = options.handlers[operation.operationId];
1914
+ const registeredRoute = serviceRoute(operation.path);
1846
1915
  const route = async (c) => {
1847
1916
  const request = c.req.raw;
1848
1917
  if (!metadata.supported || !handler) {
@@ -1852,7 +1921,7 @@ var createService = (options) => {
1852
1921
  const context = {
1853
1922
  request,
1854
1923
  url,
1855
- params: c.req.param(),
1924
+ params: registeredRoute.params(url.pathname),
1856
1925
  query: queryOf(url),
1857
1926
  body: await readBody(request),
1858
1927
  sqlite: options.sqlite,
@@ -1864,7 +1933,7 @@ var createService = (options) => {
1864
1933
  const short = await options.before?.(context);
1865
1934
  return withIssues(request, short ?? await handler(context));
1866
1935
  };
1867
- app.on(operation.method.toUpperCase(), honoPath(operation.path), route);
1936
+ app.on(operation.method.toUpperCase(), registeredRoute.path, route);
1868
1937
  }
1869
1938
  return {
1870
1939
  app,
@@ -2333,7 +2402,7 @@ var stateAdminRoutes = (routes) => {
2333
2402
  };
2334
2403
 
2335
2404
  // ../core/dist/version.js
2336
- var PACKAGE_VERSION = true ? "2.1.0" : UNRELEASED_VERSION;
2405
+ var PACKAGE_VERSION = true ? "2.2.0" : UNRELEASED_VERSION;
2337
2406
 
2338
2407
  // ../core/dist/webhooks.js
2339
2408
  var json4 = (status, body) => new Response(JSON.stringify(body), {
@@ -3561,4 +3630,4 @@ export {
3561
3630
  isTrackerStatus,
3562
3631
  EasyPostAPI
3563
3632
  };
3564
- //# sourceMappingURL=chunk-ZHRTG7AA.js.map
3633
+ //# sourceMappingURL=chunk-4N6YKCAI.js.map