@kwirthmagnify/kwirth-provider-http-pull-push 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/back.js +50 -0
  2. package/package.json +1 -1
package/back.js CHANGED
@@ -478,6 +478,56 @@ Gotchas:
478
478
  this.configs = new Map(configs.map((c) => [c.name, c]));
479
479
  this.reconcile();
480
480
  };
481
+ /*
482
+ ── Portabilidad de configuracion (IExtension) ──────────────────────────────────────────────
483
+
484
+ Las conexiones SON la configuracion de este provider: nombres, urls, intervalos, cabeceras y
485
+ credenciales. No guarda nada mas —lo que sondea no se persiste, se emite—, asi que aqui no hay
486
+ que separar configuracion de datos: viaja todo.
487
+
488
+ Lo que si hay que separar son las CREDENCIALES, y el store ya las tiene partidas en dos
489
+ almacenes; aqui solo hay que vaciarlas cuando no se piden. Se vacian, no se omiten: quien
490
+ importe tiene que poder ver que esa conexion necesita una contraseña.
491
+ */
492
+ this.exportConfig = async (options) => {
493
+ const configs = this.getConfigs();
494
+ if (options.includeCredentials) return { configs };
495
+ return {
496
+ configs: configs.map((c) => ({
497
+ ...c,
498
+ ...c.auth ? { auth: {
499
+ ...c.auth,
500
+ ...c.auth.password !== void 0 ? { password: "" } : {},
501
+ ...c.auth.token !== void 0 ? { token: "" } : {},
502
+ ...c.auth.headerValue !== void 0 ? { headerValue: "" } : {}
503
+ } } : {}
504
+ }))
505
+ };
506
+ };
507
+ this.importConfig = async (data) => {
508
+ const warnings = [];
509
+ const entrantes = data?.configs;
510
+ if (!Array.isArray(entrantes)) return { applied: 0, skipped: 0, warnings: ["no configs array in the imported data"] };
511
+ const errores = validateConfigs(entrantes);
512
+ if (errores.length > 0) return { applied: 0, skipped: entrantes.length, warnings: errores };
513
+ const conservarSecretos = (entrante) => {
514
+ const actual = this.configs.get(entrante.name);
515
+ if (!entrante.auth) return entrante;
516
+ const heredar = (campo) => {
517
+ const valor = entrante.auth?.[campo];
518
+ if (valor) return { [campo]: valor };
519
+ const previo = actual?.auth?.[campo];
520
+ if (previo) return { [campo]: previo };
521
+ if (valor === "") warnings.push(`connection '${entrante.name}' needs its ${campo} to be set`);
522
+ return {};
523
+ };
524
+ return { ...entrante, auth: { ...entrante.auth, ...heredar("password"), ...heredar("token"), ...heredar("headerValue") } };
525
+ };
526
+ const resultado = new Map(this.configs);
527
+ for (const entrante of entrantes) resultado.set(entrante.name, conservarSecretos(entrante));
528
+ await this.applyConfigs([...resultado.values()]);
529
+ return { applied: entrantes.length, skipped: 0, warnings };
530
+ };
481
531
  this.getConfigs = () => [...this.configs.values()];
482
532
  // Solo los nombres: alimenta el contador de la tarjeta en el gestor de extensiones.
483
533
  this.getConfigNames = () => [...this.configs.keys()];
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "id": "http-pull-push",
8
8
  "name": "@kwirthmagnify/kwirth-provider-http-pull-push",
9
9
  "displayName": "HTTP Pull-Push Provider",
10
- "version": "0.1.2",
10
+ "version": "0.1.3",
11
11
  "description": "HTTP polling provider for Kwirth — pulls remote HTTP endpoints on a schedule and pushes each result to the subscribed channels",
12
12
  "website": "https://kwirthmagnify.dev",
13
13
  "requiresRestart": true,