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.
- package/package.json +1 -1
- package/server/boot/index.js +28 -2
- package/server/build.js +0 -1
- package/server/callbacks/cleanup-job.js +12 -0
- package/server/callbacks/discovery.js +33 -0
- package/server/callbacks/index.js +173 -0
- package/server/callbacks/rate-limit.js +32 -0
- package/server/callbacks/store.js +121 -0
- package/server/callbacks/tokens.js +44 -0
- package/server/context.js +4 -0
- package/server/jobs/runner.js +54 -10
- package/server/jobs/worker-entry.js +9 -1
- package/server/lib/vault/jwt.js +34 -21
- package/server/lib/vault/secrets.js +3 -1
- package/server/plugins/bundle.js +122 -0
- package/server/plugins/discovery.js +29 -12
- package/server/plugins/graph.js +22 -8
- package/server/plugins/manager.js +158 -22
- package/server/router/api-router.js +5 -7
- package/server/router/routes.js +7 -2
- package/server/system-jobs/index.js +7 -0
- package/server/system-routes/index.js +15 -1
package/server/router/routes.js
CHANGED
|
@@ -46,8 +46,7 @@ function prefixRoutePattern(pattern, prefix) {
|
|
|
46
46
|
if (pattern === '/') return normalized;
|
|
47
47
|
return normalized + pattern;
|
|
48
48
|
}
|
|
49
|
-
|
|
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) || '/';
|