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

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 +57 -0
  2. package/package.json +1 -1
package/back.js CHANGED
@@ -331,6 +331,13 @@ var HttpPullPushProvider = class {
331
331
  this.configRouter = import_express.default.Router();
332
332
  this.configs = /* @__PURE__ */ new Map();
333
333
  this.subscribers = /* @__PURE__ */ new Map();
334
+ /*
335
+ Lo que este provider sabe de si mismo: cuantos consumidores tiene AHORA. El contrato
336
+ (IProvider.getStats, opcional desde kwirth-common-back 0.5.50) pide que sea BARATO — se devuelve
337
+ lo que ya se tiene, no se calcula —, y de aqui sale que kwirth pueda decir si esto esta siendo
338
+ consumido o emitiendo para nadie.
339
+ */
340
+ this.getStats = () => ({ subscribers: this.subscribers.size });
334
341
  this.pollers = /* @__PURE__ */ new Map();
335
342
  this.started = false;
336
343
  // ── IProvider ───────────────────────────────────────────────────────────────
@@ -478,6 +485,56 @@ Gotchas:
478
485
  this.configs = new Map(configs.map((c) => [c.name, c]));
479
486
  this.reconcile();
480
487
  };
488
+ /*
489
+ ── Portabilidad de configuracion (IExtension) ──────────────────────────────────────────────
490
+
491
+ Las conexiones SON la configuracion de este provider: nombres, urls, intervalos, cabeceras y
492
+ credenciales. No guarda nada mas —lo que sondea no se persiste, se emite—, asi que aqui no hay
493
+ que separar configuracion de datos: viaja todo.
494
+
495
+ Lo que si hay que separar son las CREDENCIALES, y el store ya las tiene partidas en dos
496
+ almacenes; aqui solo hay que vaciarlas cuando no se piden. Se vacian, no se omiten: quien
497
+ importe tiene que poder ver que esa conexion necesita una contraseña.
498
+ */
499
+ this.exportConfig = async (options) => {
500
+ const configs = this.getConfigs();
501
+ if (options.includeCredentials) return { configs };
502
+ return {
503
+ configs: configs.map((c) => ({
504
+ ...c,
505
+ ...c.auth ? { auth: {
506
+ ...c.auth,
507
+ ...c.auth.password !== void 0 ? { password: "" } : {},
508
+ ...c.auth.token !== void 0 ? { token: "" } : {},
509
+ ...c.auth.headerValue !== void 0 ? { headerValue: "" } : {}
510
+ } } : {}
511
+ }))
512
+ };
513
+ };
514
+ this.importConfig = async (data) => {
515
+ const warnings = [];
516
+ const entrantes = data?.configs;
517
+ if (!Array.isArray(entrantes)) return { applied: 0, skipped: 0, warnings: ["no configs array in the imported data"] };
518
+ const errores = validateConfigs(entrantes);
519
+ if (errores.length > 0) return { applied: 0, skipped: entrantes.length, warnings: errores };
520
+ const conservarSecretos = (entrante) => {
521
+ const actual = this.configs.get(entrante.name);
522
+ if (!entrante.auth) return entrante;
523
+ const heredar = (campo) => {
524
+ const valor = entrante.auth?.[campo];
525
+ if (valor) return { [campo]: valor };
526
+ const previo = actual?.auth?.[campo];
527
+ if (previo) return { [campo]: previo };
528
+ if (valor === "") warnings.push(`connection '${entrante.name}' needs its ${campo} to be set`);
529
+ return {};
530
+ };
531
+ return { ...entrante, auth: { ...entrante.auth, ...heredar("password"), ...heredar("token"), ...heredar("headerValue") } };
532
+ };
533
+ const resultado = new Map(this.configs);
534
+ for (const entrante of entrantes) resultado.set(entrante.name, conservarSecretos(entrante));
535
+ await this.applyConfigs([...resultado.values()]);
536
+ return { applied: entrantes.length, skipped: 0, warnings };
537
+ };
481
538
  this.getConfigs = () => [...this.configs.values()];
482
539
  // Solo los nombres: alimenta el contador de la tarjeta en el gestor de extensiones.
483
540
  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.4",
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,