@oondemand/oon-core-back 0.1.0
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/LICENSE +91 -0
- package/README.md +130 -0
- package/bin/cli.js +95 -0
- package/bin/dev-runner.js +8 -0
- package/package.json +53 -0
- package/src/api/auth.routes.js +20 -0
- package/src/api/core.routes.js +75 -0
- package/src/api/status.routes.js +21 -0
- package/src/boot/activation.js +31 -0
- package/src/boot/createApp.js +56 -0
- package/src/boot/database.js +35 -0
- package/src/boot/loadCentral.js +51 -0
- package/src/boot/startServer.js +31 -0
- package/src/core/context.js +35 -0
- package/src/core/define.js +171 -0
- package/src/core/errors/GenericError.js +14 -0
- package/src/core/factories/crudController.js +66 -0
- package/src/core/factories/crudService.js +96 -0
- package/src/core/factories/modelRouter.js +67 -0
- package/src/core/fields.js +92 -0
- package/src/core/middlewares/auth.js +65 -0
- package/src/core/middlewares/correlationId.js +12 -0
- package/src/core/middlewares/error.js +46 -0
- package/src/core/middlewares/mutationAudit.js +40 -0
- package/src/core/middlewares/rbac.js +22 -0
- package/src/core/middlewares/requestLog.js +28 -0
- package/src/core/models/ControleAlteracao.js +28 -0
- package/src/core/models/Log.js +22 -0
- package/src/core/models/Sistema.js +27 -0
- package/src/core/registry.js +117 -0
- package/src/core/utils/helpers.js +44 -0
- package/src/deploy/render.js +88 -0
- package/src/deploy/templates/Dockerfile +19 -0
- package/src/deploy/templates/certificate.yaml +12 -0
- package/src/deploy/templates/configmap.yaml +16 -0
- package/src/deploy/templates/deployment.yaml +32 -0
- package/src/deploy/templates/hpa.yaml +19 -0
- package/src/deploy/templates/ingress.yaml +24 -0
- package/src/deploy/templates/secret.yaml +12 -0
- package/src/deploy/templates/service.yaml +14 -0
- package/src/index.js +43 -0
- package/src/modules/assistants/index.js +33 -0
- package/src/modules/currencies/index.js +31 -0
- package/src/modules/documents/index.js +19 -0
- package/src/modules/omie/index.js +69 -0
- package/src/modules/pipelines/index.js +19 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const registry = require("../../core/registry");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Módulo Documentos (Seção 16) — resolve um documento declarado via
|
|
5
|
+
* `defineDocument` e renderiza a partir de um template + dados.
|
|
6
|
+
*/
|
|
7
|
+
function get(name) {
|
|
8
|
+
return registry.listDocuments().find((d) => d.name === name);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function render(name, data = {}) {
|
|
12
|
+
const def = get(name);
|
|
13
|
+
if (!def) throw new Error(`Documento "${name}" não registrado.`);
|
|
14
|
+
if (typeof def.render === "function") return def.render(data);
|
|
15
|
+
// Template string simples: {{campo}}.
|
|
16
|
+
return String(def.template || "").replace(/\{\{\s*(\w+)\s*\}\}/g, (_, k) => data[k] ?? "");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = { get, render };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
const registry = require("../../core/registry");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Módulo Omie (Seção 12) — engine + fila + retry. O dev declara
|
|
6
|
+
* `defineOmieMapping(...)` ou usa `omie.sync(...)` em triggers; toda a
|
|
7
|
+
* mecânica de chamada/retentativa fica aqui.
|
|
8
|
+
*/
|
|
9
|
+
const queue = [];
|
|
10
|
+
let draining = false;
|
|
11
|
+
|
|
12
|
+
async function callOmie({ endpoint, call, param }, { retries = 3 } = {}) {
|
|
13
|
+
const base = process.env.API_OMIE || "https://app.omie.com.br/api/v1";
|
|
14
|
+
const body = {
|
|
15
|
+
call,
|
|
16
|
+
app_key: process.env.OMIE_APP_KEY,
|
|
17
|
+
app_secret: process.env.OMIE_APP_SECRET,
|
|
18
|
+
param: Array.isArray(param) ? param : [param],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
let lastErr;
|
|
22
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
23
|
+
try {
|
|
24
|
+
const { data } = await axios.post(`${base}/${endpoint}/`, body);
|
|
25
|
+
return data;
|
|
26
|
+
} catch (err) {
|
|
27
|
+
lastErr = err;
|
|
28
|
+
await new Promise((r) => setTimeout(r, attempt * 500));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
throw lastErr;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function enqueue(job) {
|
|
35
|
+
queue.push(job);
|
|
36
|
+
drain();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function drain() {
|
|
40
|
+
if (draining) return;
|
|
41
|
+
draining = true;
|
|
42
|
+
while (queue.length) {
|
|
43
|
+
const job = queue.shift();
|
|
44
|
+
try {
|
|
45
|
+
await job();
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.log("[omie] job falhou:", err?.message);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
draining = false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Helper usado em triggers: resolve o mapping registrado e enfileira o
|
|
55
|
+
* sync. Se não houver app_key configurada, vira no-op seguro.
|
|
56
|
+
*/
|
|
57
|
+
const omie = {
|
|
58
|
+
async sync({ mapping, payload, ...rest }) {
|
|
59
|
+
if (!process.env.OMIE_APP_KEY) return { skipped: true };
|
|
60
|
+
const def = mapping ? registry.listOmieMappings().find((m) => m.name === mapping) : null;
|
|
61
|
+
const request = def?.toOmie ? def.toOmie(payload) : { ...rest, param: payload };
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
enqueue(() => callOmie(request).then(resolve).catch(reject));
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
call: callOmie,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
module.exports = { omie };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const registry = require("../../core/registry");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Módulo Esteiras (Seção 15) — executa um pipeline declarado via
|
|
5
|
+
* `definePipeline`. Cada etapa é uma função `async (ctx) => ctx`.
|
|
6
|
+
*/
|
|
7
|
+
async function run(pipelineName, input = {}) {
|
|
8
|
+
const def = registry.listPipelines().find((p) => p.name === pipelineName);
|
|
9
|
+
if (!def) throw new Error(`Pipeline "${pipelineName}" não registrada.`);
|
|
10
|
+
|
|
11
|
+
let ctx = { ...input };
|
|
12
|
+
for (const etapa of def.stages || def.etapas || []) {
|
|
13
|
+
const fn = typeof etapa === "function" ? etapa : etapa.run;
|
|
14
|
+
ctx = (await fn(ctx)) || ctx;
|
|
15
|
+
}
|
|
16
|
+
return ctx;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = { run };
|