godprotocol 2.2.59 → 2.2.60
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
|
@@ -98,11 +98,11 @@ class Headers extends Services {
|
|
|
98
98
|
// 🔹 1. Try cache
|
|
99
99
|
const cached = await db.read_cache(query, "auth");
|
|
100
100
|
|
|
101
|
-
if (cached
|
|
101
|
+
if (cached) {
|
|
102
102
|
try {
|
|
103
103
|
return {
|
|
104
104
|
ok: true,
|
|
105
|
-
data:
|
|
105
|
+
data: cached,
|
|
106
106
|
};
|
|
107
107
|
} catch {
|
|
108
108
|
// corrupted cache → ignore
|
|
@@ -111,7 +111,7 @@ class Headers extends Services {
|
|
|
111
111
|
|
|
112
112
|
// 🔹 2. Call remote
|
|
113
113
|
const headers = {
|
|
114
|
-
"x-api-version": "
|
|
114
|
+
"x-api-version": "v3",
|
|
115
115
|
"x-api-key": api_key,
|
|
116
116
|
};
|
|
117
117
|
|
|
@@ -124,7 +124,7 @@ class Headers extends Services {
|
|
|
124
124
|
headers: {
|
|
125
125
|
"Content-Type": "application/json",
|
|
126
126
|
Accept: "application/json",
|
|
127
|
-
"x-api-version": "
|
|
127
|
+
"x-api-version": "v3",
|
|
128
128
|
...headers,
|
|
129
129
|
},
|
|
130
130
|
body: JSON.stringify({}),
|
|
@@ -152,11 +152,11 @@ class Headers extends Services {
|
|
|
152
152
|
// 🔹 1. Try cache
|
|
153
153
|
const cached = await db.read_cache(query, "auth");
|
|
154
154
|
|
|
155
|
-
if (cached
|
|
155
|
+
if (cached) {
|
|
156
156
|
try {
|
|
157
157
|
return {
|
|
158
158
|
ok: true,
|
|
159
|
-
data:
|
|
159
|
+
data: cached,
|
|
160
160
|
};
|
|
161
161
|
} catch {
|
|
162
162
|
// corrupted cache → ignore
|
|
@@ -222,7 +222,9 @@ class Headers extends Services {
|
|
|
222
222
|
return {
|
|
223
223
|
ok: false,
|
|
224
224
|
status: 401,
|
|
225
|
-
message:
|
|
225
|
+
message:
|
|
226
|
+
"Unauthorized: Missing required authentication headers of type(s): " +
|
|
227
|
+
route.config.security.join(", "),
|
|
226
228
|
};
|
|
227
229
|
}
|
|
228
230
|
|
|
@@ -232,10 +234,13 @@ class Headers extends Services {
|
|
|
232
234
|
if (authorisation) authorisation = authorisation.replace("Bearer ", "");
|
|
233
235
|
|
|
234
236
|
let val;
|
|
235
|
-
if (
|
|
236
|
-
val = await this.validate_third_party(xplatform, authorisation);
|
|
237
|
-
} else {
|
|
237
|
+
if (api_key) {
|
|
238
238
|
val = await this.validate_api_key(api_key, authorisation);
|
|
239
|
+
} else if (authorisation) {
|
|
240
|
+
val = await this.validate_third_party(
|
|
241
|
+
xplatform || this.platform_uri,
|
|
242
|
+
authorisation,
|
|
243
|
+
);
|
|
239
244
|
}
|
|
240
245
|
|
|
241
246
|
// debug(val);
|
|
@@ -246,7 +251,8 @@ class Headers extends Services {
|
|
|
246
251
|
if (!val) {
|
|
247
252
|
return {
|
|
248
253
|
ok: false,
|
|
249
|
-
message:
|
|
254
|
+
message:
|
|
255
|
+
"Unauthorized: Invalid credentials provided in authentication headers",
|
|
250
256
|
status: 403,
|
|
251
257
|
};
|
|
252
258
|
}
|
|
@@ -63,18 +63,24 @@ class Route_table extends Headers {
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
check_validation = async (rule, data) => {
|
|
66
|
-
let { prop, type, required
|
|
66
|
+
let { prop, type, required } = rule;
|
|
67
67
|
|
|
68
68
|
let data_value = data[prop];
|
|
69
69
|
|
|
70
|
-
data_value
|
|
71
|
-
data_value
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return { ok: false, message: `Field '${prop}' is required` };
|
|
70
|
+
if (data_value === undefined && rule.hasOwnProperty("default_value")) {
|
|
71
|
+
data_value = rule.default_value;
|
|
72
|
+
data[prop] = data_value;
|
|
73
|
+
}
|
|
75
74
|
|
|
76
|
-
if (data_value
|
|
77
|
-
|
|
75
|
+
if (data_value === undefined || data_value === null) {
|
|
76
|
+
if (required) {
|
|
77
|
+
return {
|
|
78
|
+
ok: false,
|
|
79
|
+
message: `Field '${prop}' is required`,
|
|
80
|
+
};
|
|
81
|
+
} else {
|
|
82
|
+
return { ok: true };
|
|
83
|
+
}
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
if (type) {
|
|
@@ -41,7 +41,7 @@ class Services {
|
|
|
41
41
|
headers: {
|
|
42
42
|
"Content-Type": "application/json",
|
|
43
43
|
Accept: "application/json",
|
|
44
|
-
"x-api-version": "
|
|
44
|
+
"x-api-version": "v3",
|
|
45
45
|
"x-api-key": this.api_key,
|
|
46
46
|
},
|
|
47
47
|
body: JSON.stringify({ platform_uri: service.uri, ...id }),
|
|
@@ -63,7 +63,9 @@ class Services {
|
|
|
63
63
|
return {
|
|
64
64
|
ok: false,
|
|
65
65
|
status: 500,
|
|
66
|
-
message:
|
|
66
|
+
message:
|
|
67
|
+
e.message ||
|
|
68
|
+
`Error fetching ${service.uri} service token for profile`,
|
|
67
69
|
};
|
|
68
70
|
}
|
|
69
71
|
|
|
@@ -107,7 +109,8 @@ class Services {
|
|
|
107
109
|
} catch (e) {
|
|
108
110
|
return {
|
|
109
111
|
ok: false,
|
|
110
|
-
message:
|
|
112
|
+
message:
|
|
113
|
+
e.message || `Error calling ${service} service at path ${path}`,
|
|
111
114
|
status: 500,
|
|
112
115
|
};
|
|
113
116
|
}
|