godprotocol 2.2.56 → 2.2.58
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
|
@@ -9,7 +9,7 @@ class DB {
|
|
|
9
9
|
db_url: config.db_url,
|
|
10
10
|
db_name: config.db_name || router?.gp?.platform_uri.replace(/\./g, "-"),
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
this.db = new Mongo(conf);
|
|
14
14
|
|
|
15
15
|
this.folders = {};
|
|
@@ -204,7 +204,7 @@ class Headers extends Services {
|
|
|
204
204
|
|
|
205
205
|
let checks = {
|
|
206
206
|
api_key: () => !!headers["x-api-key"],
|
|
207
|
-
|
|
207
|
+
auth_token: () => !!headers["authorization"],
|
|
208
208
|
xplatform: () => !!headers["x-platform"],
|
|
209
209
|
};
|
|
210
210
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Headers from "./Header.js";
|
|
2
2
|
|
|
3
3
|
let securities = {
|
|
4
|
-
both: ["api_key", "
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
all: ["api_key", "
|
|
4
|
+
both: ["api_key", "auth_token"],
|
|
5
|
+
api_key: ["api_key"],
|
|
6
|
+
auth_token: ["auth_token"],
|
|
7
|
+
all: ["api_key", "auth_token", "xplatform"],
|
|
8
8
|
none: [],
|
|
9
9
|
};
|
|
10
10
|
|
|
@@ -80,7 +80,11 @@ class Route_table extends Headers {
|
|
|
80
80
|
if (type) {
|
|
81
81
|
if (type.startsWith("/")) {
|
|
82
82
|
} else {
|
|
83
|
-
let type_of
|
|
83
|
+
let type_of;
|
|
84
|
+
if (type === "array") {
|
|
85
|
+
type_of = Array.isArray(data_value) ? "array" : typeof data_value;
|
|
86
|
+
} else type_of = typeof data_value;
|
|
87
|
+
|
|
84
88
|
if (type_of !== type)
|
|
85
89
|
return {
|
|
86
90
|
ok: false,
|
|
@@ -161,9 +165,9 @@ class Route_table extends Headers {
|
|
|
161
165
|
};
|
|
162
166
|
|
|
163
167
|
get_route_config = async (name) => {
|
|
164
|
-
let
|
|
168
|
+
let route = await this.get_route(name);
|
|
165
169
|
|
|
166
|
-
return
|
|
170
|
+
return route.config;
|
|
167
171
|
};
|
|
168
172
|
|
|
169
173
|
// =========================
|
|
@@ -189,17 +193,56 @@ class Route_table extends Headers {
|
|
|
189
193
|
|
|
190
194
|
// debug("Validation result for route", name, ":", resp);
|
|
191
195
|
|
|
192
|
-
if (!resp.ok)
|
|
196
|
+
if (!resp.ok) {
|
|
197
|
+
if (this.platform_agent) {
|
|
198
|
+
await this.call_agency({
|
|
199
|
+
endpoint: name,
|
|
200
|
+
args: payload.body,
|
|
201
|
+
response: resp,
|
|
202
|
+
conversation: payload.headers.meta.conversation_id,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return resp;
|
|
206
|
+
}
|
|
193
207
|
}
|
|
194
208
|
|
|
195
209
|
// ⚙️ middleware
|
|
196
210
|
for (let middleware of config.middlewares || []) {
|
|
197
211
|
let result = await middleware(payload);
|
|
198
|
-
if (!result?.ok)
|
|
212
|
+
if (!result?.ok) {
|
|
213
|
+
if (this.platform_agent) {
|
|
214
|
+
await this.call_agency({
|
|
215
|
+
endpoint: name,
|
|
216
|
+
args: payload.body,
|
|
217
|
+
response: resp,
|
|
218
|
+
conversation: payload.headers.meta.conversation_id,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
199
223
|
}
|
|
200
224
|
|
|
201
225
|
// 🎯 handler
|
|
202
|
-
|
|
226
|
+
let response = await handler(payload);
|
|
227
|
+
if (response.agent) {
|
|
228
|
+
await this.call_agency(
|
|
229
|
+
{
|
|
230
|
+
endpoint: name,
|
|
231
|
+
args: payload.body,
|
|
232
|
+
response,
|
|
233
|
+
conversation: payload.headers.meta.conversation_id,
|
|
234
|
+
},
|
|
235
|
+
response.agent,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return response;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
call_agency = async (payload, profile = this.platform_agent) => {
|
|
243
|
+
await (
|
|
244
|
+
await this.get_service("agency")
|
|
245
|
+
).call("response", payload, { profile });
|
|
203
246
|
};
|
|
204
247
|
}
|
|
205
248
|
|