@oondemand/oon-core-back 0.4.25 → 0.4.27
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
|
@@ -125,14 +125,50 @@ function translateProviderActivationError(error, fallback) {
|
|
|
125
125
|
|
|
126
126
|
const timedOut = error.code === "ECONNABORTED";
|
|
127
127
|
const statusCode = timedOut ? 504 : error.response?.status || 502;
|
|
128
|
+
const payload = error.response?.data;
|
|
129
|
+
const envelope = payload?.error && typeof payload.error === "object"
|
|
130
|
+
? payload.error
|
|
131
|
+
: payload;
|
|
132
|
+
const responseHeaders = error.response?.headers;
|
|
133
|
+
const headerRequestId = typeof responseHeaders?.get === "function"
|
|
134
|
+
? responseHeaders.get("x-request-id") || responseHeaders.get("x-correlation-id")
|
|
135
|
+
: responseHeaders?.["x-request-id"] || responseHeaders?.["x-correlation-id"];
|
|
136
|
+
const requestId = String(
|
|
137
|
+
envelope?.requestId
|
|
138
|
+
|| envelope?.details?.requestId
|
|
139
|
+
|| headerRequestId
|
|
140
|
+
|| "",
|
|
141
|
+
).trim();
|
|
142
|
+
const upstreamDetails = envelope?.details;
|
|
143
|
+
const details = upstreamDetails && typeof upstreamDetails === "object"
|
|
144
|
+
? { ...upstreamDetails, ...(requestId ? { requestId } : {}) }
|
|
145
|
+
: {
|
|
146
|
+
...(upstreamDetails !== undefined ? { upstream: upstreamDetails } : {}),
|
|
147
|
+
...(requestId ? { requestId } : {}),
|
|
148
|
+
};
|
|
128
149
|
const message =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
(timedOut
|
|
150
|
+
envelope?.message
|
|
151
|
+
|| payload?.message
|
|
152
|
+
|| (timedOut
|
|
132
153
|
? "A Central de Ativações não respondeu dentro do prazo."
|
|
133
154
|
: fallback);
|
|
134
155
|
|
|
135
|
-
return new GenericError(message, {
|
|
156
|
+
return new GenericError(message, {
|
|
157
|
+
statusCode,
|
|
158
|
+
code: envelope?.code || (timedOut ? "ACTIVATION_PROVIDER_TIMEOUT" : "ACTIVATION_PROVIDER_FAILED"),
|
|
159
|
+
details: Object.keys(details).length ? details : null,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function activationProviderPost(...args) {
|
|
164
|
+
try {
|
|
165
|
+
return await providerPost(...args);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
throw translateProviderActivationError(
|
|
168
|
+
error,
|
|
169
|
+
"A Central de Ativações recusou a operação.",
|
|
170
|
+
);
|
|
171
|
+
}
|
|
136
172
|
}
|
|
137
173
|
|
|
138
174
|
function idOf(value) {
|
|
@@ -522,7 +558,7 @@ router.post(
|
|
|
522
558
|
});
|
|
523
559
|
|
|
524
560
|
try {
|
|
525
|
-
const response = await
|
|
561
|
+
const response = await activationProviderPost(
|
|
526
562
|
req,
|
|
527
563
|
PATHS.validar,
|
|
528
564
|
providerPayload(req, codigoAtivacao),
|
|
@@ -601,14 +637,14 @@ router.post(
|
|
|
601
637
|
});
|
|
602
638
|
}
|
|
603
639
|
|
|
604
|
-
const preview = await
|
|
640
|
+
const preview = await activationProviderPost(
|
|
605
641
|
req,
|
|
606
642
|
PATHS.validar,
|
|
607
643
|
providerPayload(req, codigoAtivacao),
|
|
608
644
|
);
|
|
609
645
|
assertApp(preview.data);
|
|
610
646
|
|
|
611
|
-
const activated = await
|
|
647
|
+
const activated = await activationProviderPost(
|
|
612
648
|
req,
|
|
613
649
|
PATHS.ativar,
|
|
614
650
|
providerPayload(req, codigoAtivacao, { nomeInstancia, metadata: {} }),
|
|
@@ -682,7 +718,7 @@ async function complete(req, instance, config) {
|
|
|
682
718
|
});
|
|
683
719
|
}
|
|
684
720
|
|
|
685
|
-
await
|
|
721
|
+
await activationProviderPost(
|
|
686
722
|
req,
|
|
687
723
|
PATHS.concluir,
|
|
688
724
|
{
|
|
@@ -746,3 +782,4 @@ router.post(
|
|
|
746
782
|
);
|
|
747
783
|
|
|
748
784
|
module.exports = router;
|
|
785
|
+
module.exports.translateProviderActivationError = translateProviderActivationError;
|
package/src/core/rbac/storage.js
CHANGED
|
@@ -9,6 +9,7 @@ const {
|
|
|
9
9
|
policy,
|
|
10
10
|
roleByCode,
|
|
11
11
|
rolePermissions,
|
|
12
|
+
unique,
|
|
12
13
|
legacyPermissions,
|
|
13
14
|
matchingRoleForLegacyUser,
|
|
14
15
|
} = require("./policy");
|
|
@@ -182,13 +183,17 @@ async function resolveUserAccess(user, { touch = true } = {}) {
|
|
|
182
183
|
(ctx.config.accessMode || ctx.config.ecosystem?.accessMode) === "authenticated_users";
|
|
183
184
|
if (!access && authenticatedAdmission) {
|
|
184
185
|
const globalPermissions = Array.isArray(user?.globalPermissions)
|
|
185
|
-
?
|
|
186
|
+
? user.globalPermissions.map(String)
|
|
186
187
|
: [];
|
|
188
|
+
const authenticatedRole = roleByCode("authenticated_user");
|
|
187
189
|
return {
|
|
188
190
|
mode: "authenticated_users",
|
|
189
191
|
status: "active",
|
|
190
192
|
roleCode: "authenticated_user",
|
|
191
|
-
permissions:
|
|
193
|
+
permissions: unique([
|
|
194
|
+
...rolePermissions(authenticatedRole),
|
|
195
|
+
...globalPermissions,
|
|
196
|
+
]),
|
|
192
197
|
mustChangePassword: Boolean(user?.mustChangePassword || user?.firstAccessPending),
|
|
193
198
|
};
|
|
194
199
|
}
|