godprotocol 2.3.71 → 2.3.72

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "godprotocol",
3
- "version": "2.3.71",
3
+ "version": "2.3.72",
4
4
  "description": "A distributed computing environment for Web 4.0 — integrating AI, decentralisation, and virtual computation.",
5
5
  "main": "Index.js",
6
6
  "type": "module",
@@ -8,12 +8,22 @@ class Callbacks {
8
8
  this.on_service_callbacks = new Array();
9
9
  this.after_service_callbacks = new Array();
10
10
  this.service_error_callbacks = new Array();
11
+ this.headers_rejected_callbacks = new Array();
12
+ this.headers_resolved_callbacks = new Array();
11
13
  }
12
14
 
13
15
  before(fn) {
14
16
  this.before_callbacks.push(fn);
15
17
  }
16
18
 
19
+ headers_resolved(fn) {
20
+ this.headers_resolved_callbacks.push(fn);
21
+ }
22
+
23
+ headers_rejected(fn) {
24
+ this.headers_rejected_callbacks.push(fn);
25
+ }
26
+
17
27
  on_service(fn) {
18
28
  this.on_service_callbacks.push(fn);
19
29
  }
@@ -62,6 +72,22 @@ class Callbacks {
62
72
  return { ok: true };
63
73
  };
64
74
 
75
+ handle_headers_rejected_callback = async (payload) => {
76
+ for (const callback of this.headers_rejected_callbacks) {
77
+ await callback(payload, this.gp);
78
+ }
79
+
80
+ return { ok: true };
81
+ };
82
+
83
+ handler_headers_resolved_callback = async (payload) => {
84
+ for (const callback of this.headers_resolved_callbacks) {
85
+ await callback(payload, this.gp);
86
+ }
87
+
88
+ return { ok: true };
89
+ };
90
+
65
91
  handle_on_service_callback = async (payload) => {
66
92
  for (const callback of this.on_service_callbacks) {
67
93
  const result = await callback(payload, this.gp);
@@ -418,9 +418,29 @@ const version_middleware = async (req, res, routers) => {
418
418
  error_stage = "Header";
419
419
  securityResult = await router.handle_security(route, req, version); // was: name-based lookup inside handle_security
420
420
 
421
+ const headersCallbackPayload = {
422
+ headers: req.headers,
423
+ query,
424
+ route: name,
425
+ route_config: route,
426
+ version,
427
+ method: req.method,
428
+ };
429
+
421
430
  if (securityResult !== true) {
431
+ await route.handle_headers_rejected_callback({
432
+ ...headersCallbackPayload,
433
+ security: securityResult,
434
+ authorized: false,
435
+ });
436
+
422
437
  return respond(securityResult, res);
423
438
  }
439
+ await route.handle_headers_resolved_callback({
440
+ ...headersCallbackPayload,
441
+ security: securityResult,
442
+ authorized: true,
443
+ });
424
444
 
425
445
  // -----------------------------------------------------------------
426
446
  // BODY