@oondemand/oon-core-back 0.4.22 → 0.4.23
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
|
@@ -114,6 +114,27 @@ function role() {
|
|
|
114
114
|
return ctx.config.ecosystem?.role === "root" ? "root" : "member";
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
function deploymentBootstrap() {
|
|
118
|
+
const deploymentId = String(process.env.OON_DEPLOYMENT_ID || "").trim();
|
|
119
|
+
const token = String(process.env.OON_DEPLOYMENT_TOKEN || "").trim();
|
|
120
|
+
if (!deploymentId && !token) return null;
|
|
121
|
+
if (!deploymentId || !token) {
|
|
122
|
+
throw new GenericError(
|
|
123
|
+
"OON_DEPLOYMENT_ID e OON_DEPLOYMENT_TOKEN devem ser configurados juntos.",
|
|
124
|
+
{ statusCode: 500, code: "DEPLOYMENT_BOOTSTRAP_INCOMPLETE" },
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
const tenancyModel =
|
|
128
|
+
ctx.config.tenancyModel || ctx.config.ecosystem?.tenancyModel;
|
|
129
|
+
if (tenancyModel !== "none") {
|
|
130
|
+
throw new GenericError(
|
|
131
|
+
"Bootstrap direto de deployment é permitido somente para Apps globais.",
|
|
132
|
+
{ statusCode: 500, code: "DEPLOYMENT_BOOTSTRAP_TENANCY_INVALID" },
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return { deploymentId, token };
|
|
136
|
+
}
|
|
137
|
+
|
|
117
138
|
function ambiente() {
|
|
118
139
|
const value =
|
|
119
140
|
process.env.APP_ENVIRONMENT || process.env.NODE_ENV || "desenvolvimento";
|
|
@@ -264,6 +285,38 @@ async function ensureInstance() {
|
|
|
264
285
|
await instance.save();
|
|
265
286
|
}
|
|
266
287
|
|
|
288
|
+
const bootstrap = deploymentBootstrap();
|
|
289
|
+
if (bootstrap) {
|
|
290
|
+
let currentToken = null;
|
|
291
|
+
try {
|
|
292
|
+
currentToken = decrypt(instance);
|
|
293
|
+
} catch {
|
|
294
|
+
currentToken = null;
|
|
295
|
+
}
|
|
296
|
+
if (
|
|
297
|
+
instance.deploymentId !== bootstrap.deploymentId ||
|
|
298
|
+
instance.credentialType !== "deployment" ||
|
|
299
|
+
currentToken !== bootstrap.token ||
|
|
300
|
+
instance.status !== "ativa"
|
|
301
|
+
) {
|
|
302
|
+
clearInstanceIdentity(instance);
|
|
303
|
+
instance.deploymentId = bootstrap.deploymentId;
|
|
304
|
+
instance.credentialType = "deployment";
|
|
305
|
+
instance.status = "ativa";
|
|
306
|
+
instance.appCode = getAppCode();
|
|
307
|
+
instance.ambiente = ambiente();
|
|
308
|
+
instance.ecosystemUrl = process.env.CENTRAL_ATIVACAO_URL;
|
|
309
|
+
instance.publicUrl = process.env.PUBLIC_APP_URL;
|
|
310
|
+
instance.coreVersion = version();
|
|
311
|
+
instance.appVersion = version();
|
|
312
|
+
instance.ativadaEm = new Date();
|
|
313
|
+
instance.concluidaEm = new Date();
|
|
314
|
+
instance.credentialVersion = Number(instance.credentialVersion || 0) + 1;
|
|
315
|
+
Object.assign(instance, encrypt(bootstrap.token));
|
|
316
|
+
await instance.save();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
267
320
|
// Versões anteriores do Core marcavam a aplicação root como ativa sem criar
|
|
268
321
|
// o App root e o grafo mínimo do ecossistema. Quando o domínio disponibiliza
|
|
269
322
|
// o verificador, o App cadastrado passa a ser a fonte de verdade.
|
|
@@ -530,6 +583,7 @@ module.exports = {
|
|
|
530
583
|
globalFields,
|
|
531
584
|
rootFields,
|
|
532
585
|
role,
|
|
586
|
+
deploymentBootstrap,
|
|
533
587
|
ambiente,
|
|
534
588
|
publicUrl,
|
|
535
589
|
version,
|