ripplo 0.7.37 → 0.7.39

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ripplo",
3
- "version": "0.7.37",
3
+ "version": "0.7.39",
4
4
  "description": "CLI for Ripplo — AI-powered end-to-end testing",
5
5
  "type": "module",
6
6
  "homepage": "https://ripplo.ai",
@@ -60,11 +60,11 @@
60
60
  "tsup": "^8.5.1",
61
61
  "vitest": "^4.1.4",
62
62
  "@ripplo/core": "^0.0.0",
63
+ "@ripplo/run-report": "0.0.0",
63
64
  "@ripplo/eslint-config": "0.0.0",
64
- "@ripplo/graphql": "^0.0.0",
65
65
  "@ripplo/runtime": "^0.0.0",
66
66
  "@ripplo/rrweb-bundle": "0.0.0",
67
- "@ripplo/run-report": "0.0.0",
67
+ "@ripplo/graphql": "^0.0.0",
68
68
  "@ripplo/spec": "^0.0.0"
69
69
  },
70
70
  "scripts": {
@@ -1,46 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as q}from"./chunk-IHSHBPJY.js";import{b as G}from"./chunk-7UWDMECF.js";import{execFileSync as O}from"child_process";import U from"fs";import p from"path";function F(e){let r=L(e);return r??P(e)}function P(e){let r=p.dirname(e);return N(p.join(e,".ripplo"))?e:r===e?null:P(r)}function N(e){try{return U.statSync(e).isDirectory()}catch{return!1}}function L(e){let r=j(["rev-parse","--show-toplevel"],e);if(r==null)return null;let t=r.trim();return t.length===0?null:p.isAbsolute(t)?t:p.resolve(e,t)}function j(e,r){try{return O("git",e,{cwd:r,encoding:"utf8",stdio:["ignore","pipe","ignore"]})}catch{return null}}var f=class extends Error{detail;serverUrl;constructor({detail:r,serverUrl:t}){super(`Failed to connect to Ripplo server at ${t}. Check the server is running and reachable. Details: ${r}`),this.name="GqlConnectionError",this.detail=r,this.serverUrl=t}},c=class extends Error{errors;constructor(r){super(r.map(t=>t.message).join(", ")),this.name="GqlRequestError",this.errors=r}};function B(e){if(e instanceof c)return e.errors[0]?.extensions?.code}async function x(e){let{print:r}=await import("graphql"),t=r(e.document),n=JSON.stringify({query:t,variables:e.variables}),o=`${e.config.ripploServerUrl}/graphql`,d=await W({init:{body:n,headers:{Authorization:`Bearer ${e.config.token}`,"Content-Type":"application/json"},method:"POST"},serverUrl:e.config.ripploServerUrl,url:o}),s=await Q({res:d,url:o});if(!J(s))throw new Error("Invalid GraphQL response");if(K(s))throw new c(s.errors);if(s.data==null)throw new Error("No data returned from server");return s.data}async function W({init:e,serverUrl:r,url:t}){let n=1,o=await E({init:e,url:t});for(;o.retryable&&n<3;)await H(V(n)),n+=1,o=await E({init:e,url:t});if(o.response!=null)return o.response;throw new f({detail:o.detail,serverUrl:r})}async function E({init:e,url:r}){try{let t=await fetch(r,{...e,signal:AbortSignal.timeout(15e3)});return{detail:"",response:t,retryable:t.status>=500}}catch(t){return{detail:t instanceof Error?t.message:String(t),response:void 0,retryable:!0}}}function V(e){return 300*3**(e-1)*(.5+Math.random())}function H(e){return new Promise(r=>{setTimeout(r,e)})}async function Q({res:e,url:r}){let t=await e.text();if(t.length===0)throw new Error(`Empty response from Ripplo server at ${r} (status ${String(e.status)}). The server may have restarted or the request was rejected before a body was sent.`);try{return JSON.parse(t)}catch{throw new Error(`Non-JSON response from Ripplo server at ${r} (status ${String(e.status)}): ${t.slice(0,200)}`)}}function J(e){return typeof e=="object"&&e!=null&&("data"in e||"errors"in e)}function K(e){return Array.isArray(e.errors)&&e.errors.length>0}import X from"pino";import z from"pino-pretty";var y=X({level:process.env.LOG_LEVEL??"info"},z({ignore:"pid,hostname"}));import{readdir as Y,rm as Z,stat as ee}from"fs/promises";import k from"path";var b=k.join(process.cwd(),".ripplo","debug"),T=360*60*1e3;async function re({maxRuns:e}){try{let t=(await Y(b,{withFileTypes:!0})).filter(i=>i.isDirectory()),n=Date.now(),o=await Promise.all(t.map(async i=>{let m=k.join(b,i.name),$=await ee(m);return{dirPath:m,mtime:$.mtimeMs}})),d=o.filter(i=>n-i.mtime>T),M=o.filter(i=>n-i.mtime<=T).toSorted((i,m)=>m.mtime-i.mtime).slice(e),R=[...d,...M];if(R.length===0)return;await Promise.allSettled(R.map(i=>Z(i.dirPath,{force:!0,recursive:!0}))),y.debug("Pruned %d old debug run(s)",R.length)}catch{y.warn("Debug run pruning failed, ignoring")}}import{Agent as te,RetryAgent as ne,setGlobalDispatcher as oe}from"undici";var ie=1500,se=4e3,ae=3,le=50,de=100,C=!1;function ce(){if(C)return;C=!0;let e=new te({connections:de,keepAliveMaxTimeout:se,keepAliveTimeout:ie}),r=new ne(e,{errorCodes:["ECONNRESET","ECONNREFUSED","EPIPE","ETIMEDOUT","UND_ERR_REQ_CONTENT_LENGTH_MISMATCH","UND_ERR_SOCKET"],maxRetries:ae,methods:["GET","POST","HEAD","OPTIONS","PUT","DELETE"],minTimeout:le});oe(r)}import{graphql as u}from"gql.tada";var Ue=u(`
3
- query AgentReviewContextWorker($reviewId: String!) {
4
- agentReview(id: $reviewId) {
5
- id
6
- runId
7
- agentProfile {
8
- id
9
- name
10
- description
11
- output
12
- successCriteria
13
- }
14
- }
15
- }
16
- `);var Fe=u(`
17
- mutation StartAgentReviewWorker($reviewId: String!) {
18
- startAgentReview(reviewId: $reviewId)
19
- }
20
- `);var Ne=u(`
21
- mutation CompleteAgentReviewWorker(
22
- $reviewId: String!
23
- $markdown: String!
24
- $shortSummary: String!
25
- $verdict: AgentReviewVerdict!
26
- $comments: [AgentReviewCommentInput!]!
27
- ) {
28
- completeAgentReview(
29
- reviewId: $reviewId
30
- markdown: $markdown
31
- shortSummary: $shortSummary
32
- verdict: $verdict
33
- comments: $comments
34
- )
35
- }
36
- `);var Le=u(`
37
- mutation UpdateAgentReviewProgressWorker($reviewId: String!, $text: String!) {
38
- updateAgentReviewProgress(reviewId: $reviewId, text: $text)
39
- }
40
- `);var je=u(`
41
- mutation FailAgentReviewWorker($reviewId: String!, $reason: String!) {
42
- failAgentReview(reviewId: $reviewId, reason: $reason)
43
- }
44
- `);import l from"fs";import I from"path";import a from"fs";import ue from"os";import g from"path";var ge=".local",me=".ripplo";function v(e){return g.join(e,".ripplo",ge)}function pe(e){let r=v(e);a.existsSync(r)||a.mkdirSync(r,{recursive:!0});let t=g.join(r,".gitignore");return a.existsSync(t)||a.writeFileSync(t,`*
45
- `),r}function fe(e,r){return g.join(v(e),r)}function h(){return g.join(ue.homedir(),me)}function S(){let e=h();return a.existsSync(e)?a.chmodSync(e,448):a.mkdirSync(e,{mode:448,recursive:!0}),e}function A(e){return g.join(h(),e)}function ye(e){let r=process.env.RIPPLO_TOKEN;if(r!=null&&r.trim().length>0)return r.trim();let t=w(e);if(!l.existsSync(t))return null;let n=l.readFileSync(t,"utf8").trim();return n.length===0?null:n}function we({serverUrl:e,token:r}){S();let t=w(e);l.mkdirSync(I.dirname(t),{mode:448,recursive:!0}),l.writeFileSync(t,r+`
46
- `,{mode:384})}function Re(e){let r=w(e);return l.existsSync(r)?(l.unlinkSync(r),!0):!1}function w(e){return A(I.join("tokens",ve(e)))}function ve(e){return new URL(e).host.replaceAll(/[^a-zA-Z0-9.]/g,"_")}var D=G(q(),1);import _ from"crypto";function he({body:e,secret:r}){let t=new D.Webhook(r),n=`msg_${_.randomUUID()}`,o=new Date,d=t.sign(n,o,e),s=Math.floor(o.getTime()/1e3);return{"webhook-id":n,"webhook-signature":d,"webhook-timestamp":String(s)}}function Se(){return`whsec_${_.randomBytes(24).toString("base64")}`}export{F as a,f as b,B as c,x as d,y as e,re as f,pe as g,fe as h,ye as i,we as j,Re as k,w as l,ce as m,he as n,Se as o};
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- var g=Object.create;var f=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var m=(b,a)=>()=>(a||b((a={exports:{}}).exports,a),a.exports);var l=(b,a,c,e)=>{if(a&&typeof a=="object"||typeof a=="function")for(let d of i(a))!k.call(b,d)&&d!==c&&f(b,d,{get:()=>a[d],enumerable:!(e=h(a,d))||e.enumerable});return b};var n=(b,a,c)=>(c=b!=null?g(j(b)):{},l(a||!b||!b.__esModule?f(c,"default",{value:b,enumerable:!0}):c,b));export{m as a,n as b};
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as P}from"./chunk-7UWDMECF.js";var T=P(V=>{"use strict";Object.defineProperty(V,"__esModule",{value:!0});V.timingSafeEqual=void 0;function N(n,e=""){if(!n)throw new Error(e)}function F(n,e){if(n.byteLength!==e.byteLength)return!1;n instanceof DataView||(n=new DataView(ArrayBuffer.isView(n)?n.buffer:n)),e instanceof DataView||(e=new DataView(ArrayBuffer.isView(e)?e.buffer:e)),N(n instanceof DataView),N(e instanceof DataView);let r=n.byteLength,i=0,a=-1;for(;++a<r;)i|=n.getUint8(a)^e.getUint8(a);return i===0}V.timingSafeEqual=F});var W=P(S=>{"use strict";var G=S&&S.__extends||(function(){var n=function(e,r){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,a){i.__proto__=a}||function(i,a){for(var g in a)a.hasOwnProperty(g)&&(i[g]=a[g])},n(e,r)};return function(e,r){n(e,r);function i(){this.constructor=e}e.prototype=r===null?Object.create(r):(i.prototype=r.prototype,new i)}})();Object.defineProperty(S,"__esModule",{value:!0});var l=256,z=(function(){function n(e){e===void 0&&(e="="),this._paddingCharacter=e}return n.prototype.encodedLength=function(e){return this._paddingCharacter?(e+2)/3*4|0:(e*8+5)/6|0},n.prototype.encode=function(e){for(var r="",i=0;i<e.length-2;i+=3){var a=e[i]<<16|e[i+1]<<8|e[i+2];r+=this._encodeByte(a>>>18&63),r+=this._encodeByte(a>>>12&63),r+=this._encodeByte(a>>>6&63),r+=this._encodeByte(a>>>0&63)}var g=e.length-i;if(g>0){var a=e[i]<<16|(g===2?e[i+1]<<8:0);r+=this._encodeByte(a>>>18&63),r+=this._encodeByte(a>>>12&63),g===2?r+=this._encodeByte(a>>>6&63):r+=this._paddingCharacter||"",r+=this._paddingCharacter||""}return r},n.prototype.maxDecodedLength=function(e){return this._paddingCharacter?e/4*3|0:(e*6+7)/8|0},n.prototype.decodedLength=function(e){return this.maxDecodedLength(e.length-this._getPaddingLength(e))},n.prototype.decode=function(e){if(e.length===0)return new Uint8Array(0);for(var r=this._getPaddingLength(e),i=e.length-r,a=new Uint8Array(this.maxDecodedLength(i)),g=0,p=0,m=0,E=0,C=0,A=0,s=0;p<i-4;p+=4)E=this._decodeChar(e.charCodeAt(p+0)),C=this._decodeChar(e.charCodeAt(p+1)),A=this._decodeChar(e.charCodeAt(p+2)),s=this._decodeChar(e.charCodeAt(p+3)),a[g++]=E<<2|C>>>4,a[g++]=C<<4|A>>>2,a[g++]=A<<6|s,m|=E&l,m|=C&l,m|=A&l,m|=s&l;if(p<i-1&&(E=this._decodeChar(e.charCodeAt(p)),C=this._decodeChar(e.charCodeAt(p+1)),a[g++]=E<<2|C>>>4,m|=E&l,m|=C&l),p<i-2&&(A=this._decodeChar(e.charCodeAt(p+2)),a[g++]=C<<4|A>>>2,m|=A&l),p<i-3&&(s=this._decodeChar(e.charCodeAt(p+3)),a[g++]=A<<6|s,m|=s&l),m!==0)throw new Error("Base64Coder: incorrect characters for decoding");return a},n.prototype._encodeByte=function(e){var r=e;return r+=65,r+=25-e>>>8&6,r+=51-e>>>8&-75,r+=61-e>>>8&-15,r+=62-e>>>8&3,String.fromCharCode(r)},n.prototype._decodeChar=function(e){var r=l;return r+=(42-e&e-44)>>>8&-l+e-43+62,r+=(46-e&e-48)>>>8&-l+e-47+63,r+=(47-e&e-58)>>>8&-l+e-48+52,r+=(64-e&e-91)>>>8&-l+e-65+0,r+=(96-e&e-123)>>>8&-l+e-97+26,r},n.prototype._getPaddingLength=function(e){var r=0;if(this._paddingCharacter){for(var i=e.length-1;i>=0&&e[i]===this._paddingCharacter;i--)r++;if(e.length<4||r>2)throw new Error("Base64Coder: incorrect padding")}return r},n})();S.Coder=z;var D=new z;function Q(n){return D.encode(n)}S.encode=Q;function X(n){return D.decode(n)}S.decode=X;var I=(function(n){G(e,n);function e(){return n!==null&&n.apply(this,arguments)||this}return e.prototype._encodeByte=function(r){var i=r;return i+=65,i+=25-r>>>8&6,i+=51-r>>>8&-75,i+=61-r>>>8&-13,i+=62-r>>>8&49,String.fromCharCode(i)},e.prototype._decodeChar=function(r){var i=l;return i+=(44-r&r-46)>>>8&-l+r-45+62,i+=(94-r&r-96)>>>8&-l+r-95+63,i+=(47-r&r-58)>>>8&-l+r-48+52,i+=(64-r&r-91)>>>8&-l+r-65+0,i+=(96-r&r-123)>>>8&-l+r-97+26,i},e})(z);S.URLSafeCoder=I;var R=new I;function Z(n){return R.encode(n)}S.encodeURLSafe=Z;function ee(n){return R.decode(n)}S.decodeURLSafe=ee;S.encodedLength=function(n){return D.encodedLength(n)};S.maxDecodedLength=function(n){return D.maxDecodedLength(n)};S.decodedLength=function(n){return D.decodedLength(n)}});var K=P(($,j)=>{"use strict";(function(n,e){var r={};e(r);var i=r.default;for(var a in r)i[a]=r[a];typeof j=="object"&&typeof j.exports=="object"?j.exports=i:typeof define=="function"&&define.amd?define(function(){return i}):n.sha256=i})($,function(n){"use strict";n.__esModule=!0,n.digestLength=32,n.blockSize=64;var e=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function r(s,t,o,f,x){for(var c,u,h,_,v,d,U,b,w,y,B,O,M;x>=64;){for(c=t[0],u=t[1],h=t[2],_=t[3],v=t[4],d=t[5],U=t[6],b=t[7],y=0;y<16;y++)B=f+y*4,s[y]=(o[B]&255)<<24|(o[B+1]&255)<<16|(o[B+2]&255)<<8|o[B+3]&255;for(y=16;y<64;y++)w=s[y-2],O=(w>>>17|w<<15)^(w>>>19|w<<13)^w>>>10,w=s[y-15],M=(w>>>7|w<<25)^(w>>>18|w<<14)^w>>>3,s[y]=(O+s[y-7]|0)+(M+s[y-16]|0);for(y=0;y<64;y++)O=(((v>>>6|v<<26)^(v>>>11|v<<21)^(v>>>25|v<<7))+(v&d^~v&U)|0)+(b+(e[y]+s[y]|0)|0)|0,M=((c>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10))+(c&u^c&h^u&h)|0,b=U,U=d,d=v,v=_+O|0,_=h,h=u,u=c,c=O+M|0;t[0]+=c,t[1]+=u,t[2]+=h,t[3]+=_,t[4]+=v,t[5]+=d,t[6]+=U,t[7]+=b,f+=64,x-=64}return f}var i=(function(){function s(){this.digestLength=n.digestLength,this.blockSize=n.blockSize,this.state=new Int32Array(8),this.temp=new Int32Array(64),this.buffer=new Uint8Array(128),this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this.reset()}return s.prototype.reset=function(){return this.state[0]=1779033703,this.state[1]=3144134277,this.state[2]=1013904242,this.state[3]=2773480762,this.state[4]=1359893119,this.state[5]=2600822924,this.state[6]=528734635,this.state[7]=1541459225,this.bufferLength=0,this.bytesHashed=0,this.finished=!1,this},s.prototype.clean=function(){for(var t=0;t<this.buffer.length;t++)this.buffer[t]=0;for(var t=0;t<this.temp.length;t++)this.temp[t]=0;this.reset()},s.prototype.update=function(t,o){if(o===void 0&&(o=t.length),this.finished)throw new Error("SHA256: can't update because hash was finished.");var f=0;if(this.bytesHashed+=o,this.bufferLength>0){for(;this.bufferLength<64&&o>0;)this.buffer[this.bufferLength++]=t[f++],o--;this.bufferLength===64&&(r(this.temp,this.state,this.buffer,0,64),this.bufferLength=0)}for(o>=64&&(f=r(this.temp,this.state,t,f,o),o%=64);o>0;)this.buffer[this.bufferLength++]=t[f++],o--;return this},s.prototype.finish=function(t){if(!this.finished){var o=this.bytesHashed,f=this.bufferLength,x=o/536870912|0,c=o<<3,u=o%64<56?64:128;this.buffer[f]=128;for(var h=f+1;h<u-8;h++)this.buffer[h]=0;this.buffer[u-8]=x>>>24&255,this.buffer[u-7]=x>>>16&255,this.buffer[u-6]=x>>>8&255,this.buffer[u-5]=x>>>0&255,this.buffer[u-4]=c>>>24&255,this.buffer[u-3]=c>>>16&255,this.buffer[u-2]=c>>>8&255,this.buffer[u-1]=c>>>0&255,r(this.temp,this.state,this.buffer,0,u),this.finished=!0}for(var h=0;h<8;h++)t[h*4+0]=this.state[h]>>>24&255,t[h*4+1]=this.state[h]>>>16&255,t[h*4+2]=this.state[h]>>>8&255,t[h*4+3]=this.state[h]>>>0&255;return this},s.prototype.digest=function(){var t=new Uint8Array(this.digestLength);return this.finish(t),t},s.prototype._saveState=function(t){for(var o=0;o<this.state.length;o++)t[o]=this.state[o]},s.prototype._restoreState=function(t,o){for(var f=0;f<this.state.length;f++)this.state[f]=t[f];this.bytesHashed=o,this.finished=!1,this.bufferLength=0},s})();n.Hash=i;var a=(function(){function s(t){this.inner=new i,this.outer=new i,this.blockSize=this.inner.blockSize,this.digestLength=this.inner.digestLength;var o=new Uint8Array(this.blockSize);if(t.length>this.blockSize)new i().update(t).finish(o).clean();else for(var f=0;f<t.length;f++)o[f]=t[f];for(var f=0;f<o.length;f++)o[f]^=54;this.inner.update(o);for(var f=0;f<o.length;f++)o[f]^=106;this.outer.update(o),this.istate=new Uint32Array(8),this.ostate=new Uint32Array(8),this.inner._saveState(this.istate),this.outer._saveState(this.ostate);for(var f=0;f<o.length;f++)o[f]=0}return s.prototype.reset=function(){return this.inner._restoreState(this.istate,this.inner.blockSize),this.outer._restoreState(this.ostate,this.outer.blockSize),this},s.prototype.clean=function(){for(var t=0;t<this.istate.length;t++)this.ostate[t]=this.istate[t]=0;this.inner.clean(),this.outer.clean()},s.prototype.update=function(t){return this.inner.update(t),this},s.prototype.finish=function(t){return this.outer.finished?this.outer.finish(t):(this.inner.finish(t),this.outer.update(t,this.digestLength).finish(t)),this},s.prototype.digest=function(){var t=new Uint8Array(this.digestLength);return this.finish(t),t},s})();n.HMAC=a;function g(s){var t=new i().update(s),o=t.digest();return t.clean(),o}n.hash=g,n.default=g;function p(s,t){var o=new a(s).update(t),f=o.digest();return o.clean(),f}n.hmac=p;function m(s,t,o,f){var x=f[0];if(x===0)throw new Error("hkdf: cannot expand more");t.reset(),x>1&&t.update(s),o&&t.update(o),t.update(f),t.finish(s),f[0]++}var E=new Uint8Array(n.digestLength);function C(s,t,o,f){t===void 0&&(t=E),f===void 0&&(f=32);for(var x=new Uint8Array([1]),c=p(t,s),u=new a(c),h=new Uint8Array(u.digestLength),_=h.length,v=new Uint8Array(f),d=0;d<f;d++)_===h.length&&(m(h,u,o,x),_=0),v[d]=h[_++];return u.clean(),h.fill(0),x.fill(0),v}n.hkdf=C;function A(s,t,o,f){for(var x=new a(s),c=x.digestLength,u=new Uint8Array(4),h=new Uint8Array(c),_=new Uint8Array(c),v=new Uint8Array(f),d=0;d*c<f;d++){var U=d+1;u[0]=U>>>24&255,u[1]=U>>>16&255,u[2]=U>>>8&255,u[3]=U>>>0&255,x.reset(),x.update(t),x.update(u),x.finish(_);for(var b=0;b<c;b++)h[b]=_[b];for(var b=2;b<=o;b++){x.reset(),x.update(_).finish(_);for(var w=0;w<c;w++)h[w]^=_[w]}for(var b=0;b<c&&d*c+b<f;b++)v[d*c+b]=h[b]}for(var d=0;d<c;d++)h[d]=_[d]=0;for(var d=0;d<4;d++)u[d]=0;return x.clean(),v}n.pbkdf2=A})});var ie=P(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});L.Webhook=L.WebhookVerificationError=void 0;var te=T(),J=W(),re=K(),Y=300,H=class n extends Error{constructor(e){super(e),Object.setPrototypeOf(this,n.prototype),this.name="ExtendableError",this.stack=new Error(e).stack}},k=class n extends H{constructor(e){super(e),Object.setPrototypeOf(this,n.prototype),this.name="WebhookVerificationError"}};L.WebhookVerificationError=k;var q=class n{constructor(e,r){if(!e)throw new Error("Secret can't be empty.");if(r?.format==="raw")e instanceof Uint8Array?this.key=e:this.key=Uint8Array.from(e,i=>i.charCodeAt(0));else{if(typeof e!="string")throw new Error("Expected secret to be of type string");e.startsWith(n.prefix)&&(e=e.substring(n.prefix.length)),this.key=J.decode(e)}}verify(e,r){let i={};for(let t of Object.keys(r))i[t.toLowerCase()]=r[t];let a=i["webhook-id"],g=i["webhook-signature"],p=i["webhook-timestamp"];if(!g||!a||!p)throw new k("Missing required headers");let m=this.verifyTimestamp(p),C=this.sign(a,m,e).split(",")[1],A=g.split(" "),s=new globalThis.TextEncoder;for(let t of A){let[o,f]=t.split(",");if(o==="v1"&&(0,te.timingSafeEqual)(s.encode(f),s.encode(C)))return JSON.parse(e.toString())}throw new k("No matching signature found")}sign(e,r,i){if(typeof i!="string")if(i.constructor.name==="Buffer")i=i.toString();else throw new Error("Expected payload to be of type string or Buffer.");let a=new TextEncoder,g=Math.floor(r.getTime()/1e3),p=a.encode(`${e}.${g}.${i}`);return`v1,${J.encode(re.hmac(this.key,p))}`}verifyTimestamp(e){let r=Math.floor(Date.now()/1e3),i=parseInt(e,10);if(isNaN(i))throw new k("Invalid Signature Headers");if(r-i>Y)throw new k("Message timestamp too old");if(i>r+Y)throw new k("Message timestamp too new");return new Date(i*1e3)}};L.Webhook=q;q.prefix="whsec_"});export{ie as a};