@stacksjs/testing 0.75.599 → 0.75.600

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 (3) hide show
  1. package/dist/hq.d.ts +0 -1
  2. package/dist/hq.js +2 -2
  3. package/package.json +15 -15
package/dist/hq.d.ts CHANGED
@@ -24,7 +24,6 @@ export declare interface FakeHqServiceOptions {
24
24
  service?: string
25
25
  origin?: string
26
26
  meters?: MeterReading[]
27
- confirmCode?: boolean
28
27
  contract?: boolean
29
28
  approveOnPoll?: number
30
29
  storeIngest?: boolean
package/dist/hq.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{createHqService as K,createMemoryConnectCodeStore as T}from"@stacksjs/hq/service";function g(s,d=200){return new Response(JSON.stringify(s),{status:d,headers:{"Content-Type":"application/json"}})}function E(s){return/^Bearer\s+(\S+)$/i.exec(s.headers.get("authorization")??"")?.[1]??null}function B(s={}){let d=s.service??"fakehq",v=(s.origin??`https://${d}.test`).replace(/\/+$/,""),q=s.meters??[{meter:"events",used:0,limit:500}],y=s.now??(()=>new Date),f=new Map,U=new Map,j=[],I=new Map,b=[],R=[],P=[],H=[],_={id:"fake-user"};function x(e,t){let r=`${e}/${t}`,i=f.get(r);if(!i){let k=crypto.randomUUID();i={owner:e,grant:{project:{id:k,name:t},ingestKey:`${d}_ingest_${crypto.randomUUID()}`,readKey:`${d}_read_${crypto.randomUUID()}`,dashboardUrl:`${s.relativeDashboardUrl?"":v}/projects/${k}`}},f.set(r,i)}return i.grant}function G(e,t){let r=`${e}/${t}`,i=U.get(r);if(!i){let k=crypto.randomUUID();i={owner:e,grant:{project:{id:k,name:t},licenseKey:`rhq_lic_${crypto.randomUUID().replaceAll("-","")}`,dashboardUrl:`${v}/account`}},U.set(r,i)}return i.grant}let C=K({service:d,approveUrl:(e)=>`${v}/cli/connect?code=${encodeURIComponent(e)}`,upgradeUrl:`${v}/pricing`,codes:T(),provision:async(e,{app:t})=>s.license?G(e.id,t):x(e.id,t),...s.license?{}:{async authenticateReadKey(e){for(let{grant:t,owner:r}of f.values())if(t.readKey===e)return{owner:r,project:t.project.id};return null},usage:async()=>q.map((e)=>({...e}))}},{now:y}),D=(e)=>e?[...f.values()].find((t)=>t.grant.ingestKey===e):void 0,F=(e,t)=>{let r=E(e);return[...f.values()].some((i)=>i.grant.project.id===t&&i.grant.readKey===r)},w=(e)=>`${e.slice(0,3)}-${e.slice(3,6)}`.toUpperCase();async function M(e){let t=new URL(e.url),r=t.pathname.replace(/\/+$/,"")||"/",i=e.method.toUpperCase();if(H.push(`${i} ${r}`),(r.startsWith("/api/cli/connect")||r==="/api/v1/usage")&&s.contract===!1)return g({error:"not found"},404);if(i==="POST"&&r==="/api/cli/connect"){let n=await C.startConnect(e),c=await n.json();return j.push(c.code),g(s.confirmCode?{...c,confirmCode:w(c.code)}:c,n.status)}if(i==="GET"&&r.startsWith("/api/cli/connect/")){let n=decodeURIComponent(r.slice(17)),c=(I.get(n)??0)+1;if(I.set(n,c),s.approveOnPoll!==void 0&&c===s.approveOnPoll)await C.approveConnect(n,_);return C.pollConnect(e,n)}if(i==="GET"&&r==="/api/v1/usage")return C.usage(e);if(i==="POST"&&(r==="/logs"||r==="/errors")){let n=await e.json().catch(()=>({})),c=e.headers.get(r==="/logs"?"x-loghq-key":"x-bughq-key"),l=D(c??(typeof n.key==="string"?n.key:null));if(!l)return g({error:"invalid ingest key"},401);let p=y().toISOString();if(r==="/logs"){let o=Array.isArray(n.logs)?n.logs:[n],u=o.filter((a)=>a&&a.message!=null);if(!u.length)return g({error:"no log entries"},400);if(s.storeIngest!==!1)for(let a of u)b.push({id:crypto.randomUUID(),project:l.grant.project.id,level:String(a.level??"info"),message:String(a.message),timestamp:String(a.timestamp??p)});return g({ok:!0,stored:s.storeIngest===!1?0:u.length,dropped:0,skipped:o.length-u.length},201)}if(!n.message)return g({error:"missing message"},400);let h=String(n.type??"Error"),m=`${h}: ${String(n.message).split(`
3
- `)[0]}`;if(s.storeIngest!==!1){let o=R.find((u)=>u.project===l.grant.project.id&&u.title===m);if(o)o.count+=1,o.last_seen=p;else R.push({id:crypto.randomUUID(),project:l.grant.project.id,title:m,error_type:h,level:String(n.level??"error"),status:"unresolved",count:1,first_seen:p,last_seen:p})}return s.storeIngest===!1?g({ok:!0,sampled:!0}):g({ok:!0},201)}let L=/^\/api\/v1\/projects\/([^/]+)\/conversations$/.exec(r);if(i==="GET"&&L){let n=decodeURIComponent(L[1]);if(!F(e,n))return g({error:"not found"},404);let c=t.searchParams.get("status"),l=t.searchParams.get("before"),p=Math.min(100,Math.max(1,Number(t.searchParams.get("limit"))||100)),h=P.filter((o)=>o.project===n&&(!c||o.status===c)&&(!l||o.updated_at<l)).sort((o,u)=>u.updated_at.localeCompare(o.updated_at)),m=h.slice(0,p);return g({conversations:m.map((o)=>({id:o.id,subject:o.subject,status:o.status,customer_id:o.customer_id,updated_at:o.updated_at,unread_count:o.unread_count})),nextCursor:h.length>p?m[m.length-1].updated_at:null})}let S=/^\/api\/projects\/([^/]+)\/(logs|issues)$/.exec(r);if(i==="GET"&&S){let n=decodeURIComponent(S[1]);if(!F(e,n))return g({error:"not found"},404);if(S[2]==="logs"){let l=(t.searchParams.get("q")??"").toLowerCase(),p=(t.searchParams.get("level")??"").split(",").filter(Boolean),h=t.searchParams.get("before"),m=Math.min(200,Math.max(1,Number(t.searchParams.get("limit"))||100)),o=b.filter((a)=>a.project===n).filter((a)=>!l||a.message.toLowerCase().includes(l)).filter((a)=>!p.length||p.includes(a.level)).filter((a)=>!h||a.timestamp<h).sort((a,O)=>O.timestamp.localeCompare(a.timestamp)),u=o.slice(0,m);return g({logs:u.map((a)=>({id:a.id,level:a.level,message:a.message,channel:null,environment:null,timestamp:a.timestamp,created_at:a.timestamp})),nextCursor:o.length>m?u[u.length-1].timestamp:null})}let c=t.searchParams.get("status");return g({issues:R.filter((l)=>l.project===n&&(!c||l.status===c)).map((l)=>({...l,project:void 0,culprit:null}))})}return g({error:"not found"},404)}return{service:d,origin:v,fetch:(e,t)=>M(e instanceof Request?e:new Request(String(e),t)),approve:async(e)=>{let t=e??j[j.length-1];return t?C.approveConnect(t,_):{ok:!1,reason:"expired"}},project:(e="app")=>x(_.id,e),codes:()=>[...j],confirmCodeFor:(e)=>s.confirmCode&&j.includes(e)?w(e):void 0,grants:()=>[...f.values()].map((e)=>e.grant),licenses:()=>[...U.values()].map((e)=>e.grant),logs:()=>[...b],issues:()=>[...R],seedConversation:(e)=>P.push({...e}),requests:()=>[...H]}}function N(...s){return async(d,v)=>{let q=new URL(d instanceof Request?d.url:String(d)),y=s.find((f)=>f.origin===q.origin);if(!y)throw TypeError(`fetch failed: nothing answers ${q.origin}`);return y.fetch(d,v)}}export{B as createFakeHqService,N as fakeHqFetch};
2
+ import{createHqService as K,createMemoryConnectCodeStore as T}from"@stacksjs/hq/service";function g(a,d=200){return new Response(JSON.stringify(a),{status:d,headers:{"Content-Type":"application/json"}})}function E(a){return/^Bearer\s+(\S+)$/i.exec(a.headers.get("authorization")??"")?.[1]??null}function B(a={}){let d=a.service??"fakehq",v=(a.origin??`https://${d}.test`).replace(/\/+$/,""),C=a.meters??[{meter:"events",used:0,limit:500}],y=a.now??(()=>new Date),f=new Map,b=new Map,q=[],P=new Map,_=[],R=[],H=[],x=[],S={id:"fake-user"};function F(e,t){let r=`${e}/${t}`,i=f.get(r);if(!i){let k=crypto.randomUUID();i={owner:e,grant:{project:{id:k,name:t},ingestKey:`${d}_ingest_${crypto.randomUUID()}`,readKey:`${d}_read_${crypto.randomUUID()}`,dashboardUrl:`${a.relativeDashboardUrl?"":v}/projects/${k}`}},f.set(r,i)}return i.grant}function G(e,t){let r=`${e}/${t}`,i=b.get(r);if(!i){let k=crypto.randomUUID();i={owner:e,grant:{project:{id:k,name:t},licenseKey:`rhq_lic_${crypto.randomUUID().replaceAll("-","")}`,dashboardUrl:`${v}/account`}},b.set(r,i)}return i.grant}let j=K({service:d,approveUrl:(e)=>`${v}/cli/connect?code=${encodeURIComponent(e)}`,upgradeUrl:`${v}/pricing`,codes:T(),provision:async(e,{app:t})=>a.license?G(e.id,t):F(e.id,t),...a.license?{}:{async authenticateReadKey(e){for(let{grant:t,owner:r}of f.values())if(t.readKey===e)return{owner:r,project:t.project.id};return null},usage:async()=>C.map((e)=>({...e}))}},{now:y}),D=(e)=>e?[...f.values()].find((t)=>t.grant.ingestKey===e):void 0,w=(e,t)=>{let r=E(e);return[...f.values()].some((i)=>i.grant.project.id===t&&i.grant.readKey===r)},U=new Map;async function M(e){let t=new URL(e.url),r=t.pathname.replace(/\/+$/,"")||"/",i=e.method.toUpperCase();if(x.push(`${i} ${r}`),(r.startsWith("/api/cli/connect")||r==="/api/v1/usage")&&a.contract===!1)return g({error:"not found"},404);if(i==="POST"&&r==="/api/cli/connect"){let n=await j.startConnect(e),c=await n.json();return q.push(c.code),U.set(c.code,c.confirmCode),g(c,n.status)}if(i==="GET"&&r.startsWith("/api/cli/connect/")){let n=decodeURIComponent(r.slice(17)),c=(P.get(n)??0)+1;if(P.set(n,c),a.approveOnPoll!==void 0&&c===a.approveOnPoll)await j.approveConnect(n,S,U.get(n));return j.pollConnect(e,n)}if(i==="GET"&&r==="/api/v1/usage")return j.usage(e);if(i==="POST"&&(r==="/logs"||r==="/errors")){let n=await e.json().catch(()=>({})),c=e.headers.get(r==="/logs"?"x-loghq-key":"x-bughq-key"),l=D(c??(typeof n.key==="string"?n.key:null));if(!l)return g({error:"invalid ingest key"},401);let p=y().toISOString();if(r==="/logs"){let s=Array.isArray(n.logs)?n.logs:[n],u=s.filter((o)=>o&&o.message!=null);if(!u.length)return g({error:"no log entries"},400);if(a.storeIngest!==!1)for(let o of u)_.push({id:crypto.randomUUID(),project:l.grant.project.id,level:String(o.level??"info"),message:String(o.message),timestamp:String(o.timestamp??p)});return g({ok:!0,stored:a.storeIngest===!1?0:u.length,dropped:0,skipped:s.length-u.length},201)}if(!n.message)return g({error:"missing message"},400);let h=String(n.type??"Error"),m=`${h}: ${String(n.message).split(`
3
+ `)[0]}`;if(a.storeIngest!==!1){let s=R.find((u)=>u.project===l.grant.project.id&&u.title===m);if(s)s.count+=1,s.last_seen=p;else R.push({id:crypto.randomUUID(),project:l.grant.project.id,title:m,error_type:h,level:String(n.level??"error"),status:"unresolved",count:1,first_seen:p,last_seen:p})}return a.storeIngest===!1?g({ok:!0,sampled:!0}):g({ok:!0},201)}let L=/^\/api\/v1\/projects\/([^/]+)\/conversations$/.exec(r);if(i==="GET"&&L){let n=decodeURIComponent(L[1]);if(!w(e,n))return g({error:"not found"},404);let c=t.searchParams.get("status"),l=t.searchParams.get("before"),p=Math.min(100,Math.max(1,Number(t.searchParams.get("limit"))||100)),h=H.filter((s)=>s.project===n&&(!c||s.status===c)&&(!l||s.updated_at<l)).sort((s,u)=>u.updated_at.localeCompare(s.updated_at)),m=h.slice(0,p);return g({conversations:m.map((s)=>({id:s.id,subject:s.subject,status:s.status,customer_id:s.customer_id,updated_at:s.updated_at,unread_count:s.unread_count})),nextCursor:h.length>p?m[m.length-1].updated_at:null})}let I=/^\/api\/projects\/([^/]+)\/(logs|issues)$/.exec(r);if(i==="GET"&&I){let n=decodeURIComponent(I[1]);if(!w(e,n))return g({error:"not found"},404);if(I[2]==="logs"){let l=(t.searchParams.get("q")??"").toLowerCase(),p=(t.searchParams.get("level")??"").split(",").filter(Boolean),h=t.searchParams.get("before"),m=Math.min(200,Math.max(1,Number(t.searchParams.get("limit"))||100)),s=_.filter((o)=>o.project===n).filter((o)=>!l||o.message.toLowerCase().includes(l)).filter((o)=>!p.length||p.includes(o.level)).filter((o)=>!h||o.timestamp<h).sort((o,O)=>O.timestamp.localeCompare(o.timestamp)),u=s.slice(0,m);return g({logs:u.map((o)=>({id:o.id,level:o.level,message:o.message,channel:null,environment:null,timestamp:o.timestamp,created_at:o.timestamp})),nextCursor:s.length>m?u[u.length-1].timestamp:null})}let c=t.searchParams.get("status");return g({issues:R.filter((l)=>l.project===n&&(!c||l.status===c)).map((l)=>({...l,project:void 0,culprit:null}))})}return g({error:"not found"},404)}return{service:d,origin:v,fetch:(e,t)=>M(e instanceof Request?e:new Request(String(e),t)),approve:async(e)=>{let t=e??q[q.length-1];return t?j.approveConnect(t,S,U.get(t)):{ok:!1,reason:"expired"}},project:(e="app")=>F(S.id,e),codes:()=>[...q],confirmCodeFor:(e)=>U.get(e),grants:()=>[...f.values()].map((e)=>e.grant),licenses:()=>[...b.values()].map((e)=>e.grant),logs:()=>[..._],issues:()=>[...R],seedConversation:(e)=>H.push({...e}),requests:()=>[...x]}}function N(...a){return async(d,v)=>{let C=new URL(d instanceof Request?d.url:String(d)),y=a.find((f)=>f.origin===C.origin);if(!y)throw TypeError(`fetch failed: nothing answers ${C.origin}`);return y.fetch(d,v)}}export{B as createFakeHqService,N as fakeHqFetch};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/testing",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.599",
5
+ "version": "0.75.600",
6
6
  "description": "The Stacks way of testing.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -91,20 +91,20 @@
91
91
  "prepublishOnly": "bun run build"
92
92
  },
93
93
  "dependencies": {
94
- "@stacksjs/auth": "0.75.599",
95
- "@stacksjs/cache": "0.75.599",
96
- "@stacksjs/cli": "0.75.599",
97
- "@stacksjs/config": "0.75.599",
98
- "@stacksjs/database": "0.75.599",
99
- "@stacksjs/email": "0.75.599",
100
- "@stacksjs/events": "0.75.599",
101
- "@stacksjs/hq": "0.75.599",
102
- "@stacksjs/path": "0.75.599",
103
- "@stacksjs/router": "0.75.599",
104
- "@stacksjs/server": "0.75.599",
105
- "@stacksjs/storage": "0.75.599",
106
- "@stacksjs/strings": "0.75.599",
107
- "@stacksjs/ts-cloud": "^0.16.129",
94
+ "@stacksjs/auth": "0.75.600",
95
+ "@stacksjs/cache": "0.75.600",
96
+ "@stacksjs/cli": "0.75.600",
97
+ "@stacksjs/config": "0.75.600",
98
+ "@stacksjs/database": "0.75.600",
99
+ "@stacksjs/email": "0.75.600",
100
+ "@stacksjs/events": "0.75.600",
101
+ "@stacksjs/hq": "0.75.600",
102
+ "@stacksjs/path": "0.75.600",
103
+ "@stacksjs/router": "0.75.600",
104
+ "@stacksjs/server": "0.75.600",
105
+ "@stacksjs/storage": "0.75.600",
106
+ "@stacksjs/strings": "0.75.600",
107
+ "@stacksjs/ts-cloud": "^0.16.135",
108
108
  "very-happy-dom": "^0.4.1"
109
109
  },
110
110
  "devDependencies": {