@cloud-cli/on 1.2.18 → 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;
@@ -3401,10 +3403,12 @@ var dn = {
3401
3403
  r = m.timingSafeEqual(Buffer.from(a), Buffer.from(e));
3402
3404
  }
3403
3405
  if (r) {
3404
- let n = JSON.parse(t.toString("utf-8"));
3406
+ let n = JSON.parse(t.toString("utf-8")), r = e["x-github-event"] || "unknown", a = (n.ref || "").replace("refs/heads/", "").replace("refs/tags/", ""), [o, s] = (n.repository?.full_name || "").split("/");
3405
3407
  i = {
3406
- event: e["x-github-event"] || "unknown",
3407
- branch: (n.ref || "").replace("refs/heads/", "").replace("refs/tags/", ""),
3408
+ event: r,
3409
+ branch: a,
3410
+ owner: o,
3411
+ repo: s,
3408
3412
  clone_url: n.repository?.clone_url,
3409
3413
  commit_sha: n.after || n.head_commit?.id,
3410
3414
  author: n.pusher?.name || n.sender?.login,
@@ -3891,40 +3895,17 @@ var vn, yn, bn, xn = class {
3891
3895
  }
3892
3896
  async handleWebhook(e, t, n) {
3893
3897
  try {
3894
- let r = [], i = 0;
3895
- for await (let e of t) {
3896
- if (i += e.length, i > 5242880) return n.writeHead(413, { "Content-Type": "application/json" }), n.end(JSON.stringify({ error: "Payload size exceeds limit" }));
3897
- r.push(typeof e == "string" ? Buffer.from(e) : e);
3898
- }
3899
- 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;
3900
- if (s) {
3901
- let e = s.parse(o, a, c);
3902
- u = e.isValid, l = e.inputs;
3903
- } else try {
3904
- l = JSON.parse(a.toString("utf-8"));
3905
- } catch {}
3906
- if (!u) return n.writeHead(401, { "Content-Type": "application/json" }), n.end(JSON.stringify({ error: "Invalid HMAC signature or authentication failed" }));
3907
- let d = [];
3908
- for (let t of this.workflows) {
3909
- if (t.on.provider !== e) continue;
3910
- if (t.on.if) try {
3911
- if (!fn.evaluateCondition(t.on.if, { inputs: l })) continue;
3912
- } catch (e) {
3913
- console.error(`⚠️ Condition evaluation error in workflow [${t.id}]:`, e.message);
3914
- continue;
3915
- }
3916
- let n;
3917
- t.concurrency?.group && (n = await fn.evaluateValue(t.concurrency.group, { inputs: l }));
3918
- let r = {
3919
- workflowId: t.id,
3920
- steps: t.steps,
3921
- inputs: l
3922
- };
3923
- 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;
3924
3904
  }
3905
+ let s = this.matchWorkflows(e, o);
3925
3906
  n.writeHead(202, { "Content-Type": "application/json" }), n.end(JSON.stringify({
3926
3907
  message: "Webhook processed",
3927
- triggeredWorkflows: d
3908
+ triggeredWorkflows: s
3928
3909
  }));
3929
3910
  } catch (e) {
3930
3911
  console.error("❌ Webhook Ingress Error:", e), n.writeHead(500, { "Content-Type": "application/json" }), n.end(JSON.stringify({
@@ -3933,6 +3914,62 @@ var vn, yn, bn, xn = class {
3933
3914
  }));
3934
3915
  }
3935
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
+ }
3936
3973
  async handleSecretReload(e, t) {
3937
3974
  if (e.headers.authorization !== `Bearer ${this.adminToken}`) return t.writeHead(403, { "Content-Type": "application/json" }), t.end(JSON.stringify({ error: "Unauthorized" }));
3938
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" }));
@@ -8360,16 +8397,23 @@ var wo = class e {
8360
8397
  let n = [];
8361
8398
  try {
8362
8399
  let r = Co(t.resolve(e));
8363
- for (let e of r) n.push({
8364
- id: (e.id || e.name)?.toLowerCase().replace(/[^a-z0-9]/g, "-") ?? h(),
8365
- name: e.name,
8366
- on: {
8367
- provider: Object.keys(e.on || {})[0] || "generic",
8368
- if: e.on?.[Object.keys(e.on || {})[0]]?.if
8369
- },
8370
- concurrency: e.concurrency,
8371
- steps: e.steps
8372
- });
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
+ }
8373
8417
  } catch (t) {
8374
8418
  return console.error(`❌ Error parsing workflow '${e}':`, t.message), [];
8375
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"}
@@ -1 +1 @@
1
- {"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/preprocessors/github.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE5E,qBAAa,kBAAmB,YAAW,mBAAmB;IAC5D,IAAI,SAAY;IAEhB,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,mBAAmB;CAmCpG"}
1
+ {"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/preprocessors/github.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE5E,qBAAa,kBAAmB,YAAW,mBAAmB;IAC5D,IAAI,SAAY;IAEhB,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,mBAAmB;CAuCpG"}
@@ -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.2.18",
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",