arcway 0.2.0 → 0.3.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.
@@ -46,8 +46,7 @@ function prefixRoutePattern(pattern, prefix) {
46
46
  if (pattern === '/') return normalized;
47
47
  return normalized + pattern;
48
48
  }
49
- async function discoverRoutes(apiDir, { prefix = '', plugin } = {}) {
50
- const entries = await discoverModules(apiDir, { recursive: true, label: 'route file' });
49
+ function buildRoutesFromModules(entries, { prefix = '', plugin } = {}) {
51
50
  const routes = [];
52
51
  for (const { filePath, relativePath, module } of entries) {
53
52
  const urlPattern = prefixRoutePattern(filePathToPattern(relativePath), prefix);
@@ -84,6 +83,11 @@ async function discoverRoutes(apiDir, { prefix = '', plugin } = {}) {
84
83
  sortBySpecificity(routes);
85
84
  return routes;
86
85
  }
86
+
87
+ async function discoverRoutes(apiDir, { prefix = '', plugin } = {}) {
88
+ const entries = await discoverModules(apiDir, { recursive: true, label: 'route file' });
89
+ return buildRoutesFromModules(entries, { prefix, plugin });
90
+ }
87
91
  function matchRoute(routes, method, pathname) {
88
92
  const upperMethod = method.toUpperCase();
89
93
  const methodRoutes = routes.filter((r) => r.method === upperMethod);
@@ -106,6 +110,7 @@ function matchRoutesByPath(routes, pathname) {
106
110
  }
107
111
  export {
108
112
  compilePattern,
113
+ buildRoutesFromModules,
109
114
  discoverRoutes,
110
115
  filePathToPattern,
111
116
  matchPattern,
@@ -1,5 +1,12 @@
1
+ import { cleanupCallbacksJob } from '../callbacks/cleanup-job.js';
2
+
1
3
  const SYSTEM_JOB_DOMAIN = '__system';
2
4
  const systemJobRegistry = [
5
+ {
6
+ definition: cleanupCallbacksJob,
7
+ shouldRegister: (config) => Boolean(config.vault?.values?.callback && config.database),
8
+ description: 'Delete expired callback registrations',
9
+ },
3
10
  // Future system jobs are added here. Examples:
4
11
  //
5
12
  // {
@@ -5,9 +5,11 @@ const SYSTEM_PREFIX = '/_system/api';
5
5
  class SystemRouter {
6
6
  routes = [];
7
7
  _healthDeps = null;
8
+ _callbackDispatcher = null;
8
9
 
9
- constructor({ healthDeps } = {}) {
10
+ constructor({ healthDeps, callbackDispatcher } = {}) {
10
11
  this._healthDeps = healthDeps ?? null;
12
+ this._callbackDispatcher = callbackDispatcher ?? null;
11
13
  }
12
14
 
13
15
  register(route) {
@@ -23,6 +25,18 @@ class SystemRouter {
23
25
  return this._handleHealth(res);
24
26
  }
25
27
 
28
+ const pathname = url.split('?')[0];
29
+ if (
30
+ this._callbackDispatcher &&
31
+ (pathname === '/_system/callback' || pathname.startsWith('/_system/callback/'))
32
+ ) {
33
+ const fullPath = pathname;
34
+ const path = fullPath.slice('/_system/callback'.length) || '/';
35
+ const query = new URL(url, 'http://localhost').searchParams;
36
+ await this._callbackDispatcher.handle(req, res, { path, query, method });
37
+ return true;
38
+ }
39
+
26
40
  if (!url.startsWith(SYSTEM_PREFIX)) return false;
27
41
  const fullPath = url.split('?')[0];
28
42
  const routePath = fullPath.slice(SYSTEM_PREFIX.length) || '/';