@cloud-cli/on 1.3.0 → 1.4.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/dist/on.js CHANGED
@@ -3290,7 +3290,9 @@ var dn = {
3290
3290
  return this.evaluateExpression(n, t);
3291
3291
  }
3292
3292
  static async evaluateCondition(e, t = {}) {
3293
- return !!await this.evaluateExpression(e, t);
3293
+ typeof e == "string" && (e = [e]);
3294
+ for (let n of e) if (await this.evaluateExpression(n, t)) return !0;
3295
+ return !1;
3294
3296
  }
3295
3297
  static async evaluateExpression(e, t = {}) {
3296
3298
  if (!e || typeof e != "string") return e;
@@ -3893,40 +3895,17 @@ var vn, yn, bn, xn = class {
3893
3895
  }
3894
3896
  async handleWebhook(e, t, n) {
3895
3897
  try {
3896
- let r = [], i = 0;
3897
- for await (let e of t) {
3898
- if (i += e.length, i > 5242880) return n.writeHead(413, { "Content-Type": "application/json" }), n.end(JSON.stringify({ error: "Payload size exceeds limit" }));
3899
- r.push(typeof e == "string" ? Buffer.from(e) : e);
3900
- }
3901
- let a = Buffer.concat(r), o = Object.fromEntries(Object.entries(t.headers).map(([e, t]) => [e.toLowerCase(), Array.isArray(t) ? t[0] : t || ""])), s = this.preprocessors.get(e), c = this.secrets.get(`${e.toUpperCase()}_WEBHOOK_SECRET`), l = {}, u = !0;
3902
- if (s) {
3903
- let e = s.parse(o, a, c);
3904
- u = e.isValid, l = e.inputs;
3905
- } else try {
3906
- l = JSON.parse(a.toString("utf-8"));
3907
- } catch {}
3908
- if (!u) return n.writeHead(401, { "Content-Type": "application/json" }), n.end(JSON.stringify({ error: "Invalid HMAC signature or authentication failed" }));
3909
- let d = [];
3910
- for (let t of this.workflows) {
3911
- if (t.on.provider !== e) continue;
3912
- if (t.on.if) try {
3913
- if (!fn.evaluateCondition(t.on.if, { inputs: l })) continue;
3914
- } catch (e) {
3915
- console.error(`⚠️ Condition evaluation error in workflow [${t.id}]:`, e.message);
3916
- continue;
3917
- }
3918
- let n;
3919
- t.concurrency?.group && (n = await fn.evaluateValue(t.concurrency.group, { inputs: l }));
3920
- let r = {
3921
- workflowId: t.id,
3922
- steps: t.steps,
3923
- inputs: l
3924
- };
3925
- await this.queue.enqueue(t.id, r, n), d.push(t.id);
3898
+ let { rawBuffer: r, headers: i } = await this.readRequest(t, n);
3899
+ if (n.headersSent || !r) return;
3900
+ let { isValid: a, inputs: o } = this.preprocess(e, i, r);
3901
+ if (!a) {
3902
+ n.writeHead(401, { "Content-Type": "application/json" }), n.end(JSON.stringify({ error: "Invalid HMAC signature or authentication failed" }));
3903
+ return;
3926
3904
  }
3905
+ let s = this.matchWorkflows(e, o);
3927
3906
  n.writeHead(202, { "Content-Type": "application/json" }), n.end(JSON.stringify({
3928
3907
  message: "Webhook processed",
3929
- triggeredWorkflows: d
3908
+ triggeredWorkflows: s
3930
3909
  }));
3931
3910
  } catch (e) {
3932
3911
  console.error("❌ Webhook Ingress Error:", e), n.writeHead(500, { "Content-Type": "application/json" }), n.end(JSON.stringify({
@@ -3935,6 +3914,62 @@ var vn, yn, bn, xn = class {
3935
3914
  }));
3936
3915
  }
3937
3916
  }
3917
+ async readRequest(e, t) {
3918
+ let n = [], r = 0;
3919
+ for await (let i of e) {
3920
+ if (r += i.length, r > 5242880) return t.writeHead(413, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "Payload size exceeds limit" })), {
3921
+ rawBuffer: null,
3922
+ headers: {}
3923
+ };
3924
+ n.push(typeof i == "string" ? Buffer.from(i) : i);
3925
+ }
3926
+ return {
3927
+ rawBuffer: Buffer.concat(n),
3928
+ headers: Object.fromEntries(Object.entries(e.headers).map(([e, t]) => [e.toLowerCase(), Array.isArray(t) ? t[0] : t || ""]))
3929
+ };
3930
+ }
3931
+ preprocess(e, t, n) {
3932
+ let r = this.secrets.get(`${e.toUpperCase()}_WEBHOOK_SECRET`), i = this.preprocessors.get(e);
3933
+ try {
3934
+ if (i) {
3935
+ let { inputs: e, isValid: a } = i.parse(t, n, r);
3936
+ return {
3937
+ inputs: e,
3938
+ isValid: a
3939
+ };
3940
+ }
3941
+ return {
3942
+ isValid: !0,
3943
+ inputs: JSON.parse(n.toString("utf-8"))
3944
+ };
3945
+ } catch {
3946
+ return {
3947
+ isValid: !1,
3948
+ inputs: null
3949
+ };
3950
+ }
3951
+ }
3952
+ async matchWorkflows(e, t) {
3953
+ let n = [];
3954
+ for (let r of this.workflows) {
3955
+ if (r.on.provider !== e) continue;
3956
+ if (r.on.if) try {
3957
+ if (!fn.evaluateCondition(r.on.if, { inputs: t })) continue;
3958
+ } catch (e) {
3959
+ console.error(`⚠️ Condition evaluation error in workflow [${r.id}]:`, e.message);
3960
+ continue;
3961
+ }
3962
+ let i;
3963
+ r.concurrency?.group && (i = await fn.evaluateValue(r.concurrency.group, { inputs: t }));
3964
+ let a = {
3965
+ workflowId: r.id,
3966
+ steps: r.steps,
3967
+ inputs: t
3968
+ };
3969
+ await this.queue.enqueue(r.id, a, i), n.push(r.id);
3970
+ }
3971
+ return n;
3972
+ }
3938
3973
  async handleSecretReload(e, t) {
3939
3974
  if (e.headers.authorization !== `Bearer ${this.adminToken}`) return t.writeHead(403, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "Unauthorized" }));
3940
3975
  this.secrets.reload(), console.log("🔄 SecretStore reloaded successfully without downtime!"), t.writeHead(200, { "Content-Type": "application/json" }), t.end(JSON.stringify({ message: "Secrets reloaded successfully" }));
@@ -8362,16 +8397,23 @@ var wo = class e {
8362
8397
  let n = [];
8363
8398
  try {
8364
8399
  let r = Co(t.resolve(e));
8365
- for (let e of r) n.push({
8366
- id: (e.id || e.name)?.toLowerCase().replace(/[^a-z0-9]/g, "-") ?? h(),
8367
- name: e.name,
8368
- on: {
8369
- provider: Object.keys(e.on || {})[0] || "generic",
8370
- if: e.on?.[Object.keys(e.on || {})[0]]?.if
8371
- },
8372
- concurrency: e.concurrency,
8373
- steps: e.steps
8374
- });
8400
+ for (let t of r) {
8401
+ if (typeof t.on != "object") {
8402
+ console.error(`on: not defined in ${e}! Ignoring this workflow.`);
8403
+ continue;
8404
+ }
8405
+ let r = Object.keys(t.on)[0] || "generic";
8406
+ n.push({
8407
+ id: (t.id || t.name)?.toLowerCase().replace(/[^a-z0-9]/g, "-") ?? h(),
8408
+ name: t.name,
8409
+ on: {
8410
+ provider: r,
8411
+ if: t.on[r]?.if
8412
+ },
8413
+ concurrency: t.concurrency,
8414
+ steps: t.steps
8415
+ });
8416
+ }
8375
8417
  } catch (t) {
8376
8418
  return console.error(`❌ Error parsing workflow '${e}':`, t.message), [];
8377
8419
  }
@@ -1 +1 @@
1
- {"version":3,"file":"yaml-loader.d.ts","sourceRoot":"","sources":["../../src/parser/yaml-loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,qBAAa,UAAU;WACR,IAAI,CAAC,IAAI,EAAE,MAAM;IAiB9B,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,uBAAuB;CA6BhE"}
1
+ {"version":3,"file":"yaml-loader.d.ts","sourceRoot":"","sources":["../../src/parser/yaml-loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,qBAAa,UAAU;WACR,IAAI,CAAC,IAAI,EAAE,MAAM;IAiB9B,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,uBAAuB;CAmChE"}
@@ -12,7 +12,7 @@ export declare class SafeExpressionEvaluator {
12
12
  * Strictly parses code as a JavaScript expression and coerces result to boolean.
13
13
  * Throws an explicit AST Parse Error on invalid syntax (fails fast and loud).
14
14
  */
15
- static evaluateCondition(code: string, context?: Record<string, any>): Promise<boolean>;
15
+ static evaluateCondition(code: string | string[], context?: Record<string, any>): Promise<boolean>;
16
16
  /**
17
17
  * Evaluates direct JS code (Used for `eval:` steps or internal expression resolution).
18
18
  */
@@ -1 +1 @@
1
- {"version":3,"file":"safe-eval.d.ts","sourceRoot":"","sources":["../src/safe-eval.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAQ/C,CAAC;AAEF,qBAAa,uBAAuB;IAClC;;;;;OAKG;WACU,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAerF;;;;OAIG;WACU,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKjG;;OAEG;WACU,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAoB9F;;OAEG;WACU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAIzF;;OAEG;mBACkB,aAAa;CAgKnC"}
1
+ {"version":3,"file":"safe-eval.d.ts","sourceRoot":"","sources":["../src/safe-eval.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAQ/C,CAAC;AAEF,qBAAa,uBAAuB;IAClC;;;;;OAKG;WACU,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAerF;;;;OAIG;WACU,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAgB5G;;OAEG;WACU,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAoB9F;;OAEG;WACU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAIzF;;OAEG;mBACkB,aAAa;CAgKnC"}
package/dist/server.d.ts CHANGED
@@ -16,6 +16,9 @@ export declare class WebhookServer {
16
16
  * Processes incoming HTTP webhooks
17
17
  */
18
18
  private handleWebhook;
19
+ private readRequest;
20
+ private preprocess;
21
+ private matchWorkflows;
19
22
  /**
20
23
  * Handles Zero-Downtime Secret Reload
21
24
  */
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAA+C,MAAM,YAAY,CAAC;AAGpH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,aAAa,CAA0C;IAC/D,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,UAAU,CAAS;WAEd,QAAQ,CAAC,OAAO,EAAE,oBAAoB,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;gBAK1D,OAAO,EAAE,oBAAoB;IAWzC,oBAAoB,CAAC,YAAY,EAAE,mBAAmB;YAIxC,aAAa;IA6B3B;;OAEG;YACW,aAAa;IA+F3B;;OAEG;YACW,kBAAkB;IAehC;;OAEG;YACW,eAAe;IA2E7B;;OAEG;YAGW,gBAAgB;IA2B9B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAStC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ5B"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAA+C,MAAM,YAAY,CAAC;AAGpH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,aAAa,CAA0C;IAC/D,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,UAAU,CAAS;WAEd,QAAQ,CAAC,OAAO,EAAE,oBAAoB,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;gBAK1D,OAAO,EAAE,oBAAoB;IAWzC,oBAAoB,CAAC,YAAY,EAAE,mBAAmB;YAIxC,aAAa;IA6B3B;;OAEG;YACW,aAAa;YA8Bb,WAAW;IAwBzB,OAAO,CAAC,UAAU;YAiBJ,cAAc;IAqC5B;;OAEG;YACW,kBAAkB;IAehC;;OAEG;YACW,eAAe;IA2E7B;;OAEG;YAGW,gBAAgB;IA2B9B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAStC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ5B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/on",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "CLI entry point for the on plugin ecosystem.",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@10.30.3",