@vesk/vesk-cli 0.2.50-canary.5 → 0.2.50-canary.6

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/dist/cli.js +25 -11
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -22862,18 +22862,20 @@ function webhook(options) {
22862
22862
  secret,
22863
22863
  handler,
22864
22864
  headerName = "x-webhook-signature",
22865
- signaturePrefix = "sha256="
22865
+ signaturePrefix = "sha256=",
22866
+ algorithm = "SHA-256",
22867
+ signedPayload
22866
22868
  } = options;
22867
22869
  if (!secret) throw new Error("webhook() requires a secret");
22868
22870
  if (!handler) throw new Error("webhook() requires a handler function");
22869
- async function computeSignature(body) {
22871
+ async function computeSignature(payload) {
22870
22872
  const key = typeof secret === "string" ? new TextEncoder().encode(secret) : secret;
22871
- const data2 = typeof body === "string" ? new TextEncoder().encode(body) : body;
22873
+ const data2 = new TextEncoder().encode(payload);
22872
22874
  const crypto2 = globalThis.crypto;
22873
22875
  if (!crypto2?.subtle) {
22874
22876
  throw new Error("Web Crypto API not available (required for webhook signature verification)");
22875
22877
  }
22876
- return crypto2.subtle.importKey("raw", key, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]).then((k) => crypto2.subtle.sign("HMAC", k, data2)).then((sig) => {
22878
+ return crypto2.subtle.importKey("raw", key, { name: "HMAC", hash: algorithm }, false, ["sign"]).then((k) => crypto2.subtle.sign("HMAC", k, data2)).then((sig) => {
22877
22879
  const hex = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
22878
22880
  return hex;
22879
22881
  });
@@ -22893,7 +22895,25 @@ function webhook(options) {
22893
22895
  });
22894
22896
  }
22895
22897
  const body = await request.text();
22896
- const expectedSig = await computeSignature(body);
22898
+ let parsed;
22899
+ try {
22900
+ parsed = JSON.parse(body);
22901
+ } catch {
22902
+ parsed = body;
22903
+ }
22904
+ const event = parsed;
22905
+ let payload = body;
22906
+ if (signedPayload) {
22907
+ try {
22908
+ payload = signedPayload(event);
22909
+ } catch {
22910
+ return new Response(JSON.stringify({ error: "Invalid signature" }), {
22911
+ status: 401,
22912
+ headers: { "Content-Type": "application/json" }
22913
+ });
22914
+ }
22915
+ }
22916
+ const expectedSig = await computeSignature(payload);
22897
22917
  const prefixLen = signaturePrefix.length;
22898
22918
  const providedSig = signature.startsWith(signaturePrefix) ? signature.slice(prefixLen) : signature;
22899
22919
  if (providedSig.length !== expectedSig.length) {
@@ -22912,12 +22932,6 @@ function webhook(options) {
22912
22932
  headers: { "Content-Type": "application/json" }
22913
22933
  });
22914
22934
  }
22915
- let event;
22916
- try {
22917
- event = JSON.parse(body);
22918
- } catch {
22919
- event = body;
22920
- }
22921
22935
  return handler(event, request);
22922
22936
  }
22923
22937
  return webhookHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/vesk-cli",
3
- "version": "0.2.50-canary.5",
3
+ "version": "0.2.50-canary.6",
4
4
  "type": "module",
5
5
  "description": "Vesk — compiler-first framework for the post-VDOM web. vesk dev, vesk build.",
6
6
  "bin": {
@@ -8,10 +8,10 @@
8
8
  },
9
9
  "main": "./dist/cli.js",
10
10
  "dependencies": {
11
- "@vesk/adapter": "^0.2.50-canary.5",
12
- "@vesk/compiler": "^0.2.50-canary.5",
13
- "@vesk/plugin-tailwind": "^0.2.50-canary.5",
14
- "@vesk/runtime": "^0.2.50-canary.5",
11
+ "@vesk/adapter": "^0.2.50-canary.6",
12
+ "@vesk/compiler": "^0.2.50-canary.6",
13
+ "@vesk/plugin-tailwind": "^0.2.50-canary.6",
14
+ "@vesk/runtime": "^0.2.50-canary.6",
15
15
  "esrap": "^2.3.0",
16
16
  "typescript": "^5.8.0",
17
17
  "ws": "^8.18.0",