@stacksjs/testing 0.75.599 → 0.75.602
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/hq.d.ts +0 -1
- package/dist/hq.js +2 -2
- package/package.json +15 -15
package/dist/hq.d.ts
CHANGED
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(
|
|
3
|
-
`)[0]}`;if(
|
|
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.
|
|
5
|
+
"version": "0.75.602",
|
|
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.
|
|
95
|
-
"@stacksjs/cache": "0.75.
|
|
96
|
-
"@stacksjs/cli": "0.75.
|
|
97
|
-
"@stacksjs/config": "0.75.
|
|
98
|
-
"@stacksjs/database": "0.75.
|
|
99
|
-
"@stacksjs/email": "0.75.
|
|
100
|
-
"@stacksjs/events": "0.75.
|
|
101
|
-
"@stacksjs/hq": "0.75.
|
|
102
|
-
"@stacksjs/path": "0.75.
|
|
103
|
-
"@stacksjs/router": "0.75.
|
|
104
|
-
"@stacksjs/server": "0.75.
|
|
105
|
-
"@stacksjs/storage": "0.75.
|
|
106
|
-
"@stacksjs/strings": "0.75.
|
|
107
|
-
"@stacksjs/ts-cloud": "^0.16.
|
|
94
|
+
"@stacksjs/auth": "0.75.602",
|
|
95
|
+
"@stacksjs/cache": "0.75.602",
|
|
96
|
+
"@stacksjs/cli": "0.75.602",
|
|
97
|
+
"@stacksjs/config": "0.75.602",
|
|
98
|
+
"@stacksjs/database": "0.75.602",
|
|
99
|
+
"@stacksjs/email": "0.75.602",
|
|
100
|
+
"@stacksjs/events": "0.75.602",
|
|
101
|
+
"@stacksjs/hq": "0.75.602",
|
|
102
|
+
"@stacksjs/path": "0.75.602",
|
|
103
|
+
"@stacksjs/router": "0.75.602",
|
|
104
|
+
"@stacksjs/server": "0.75.602",
|
|
105
|
+
"@stacksjs/storage": "0.75.602",
|
|
106
|
+
"@stacksjs/strings": "0.75.602",
|
|
107
|
+
"@stacksjs/ts-cloud": "^0.16.135",
|
|
108
108
|
"very-happy-dom": "^0.4.1"
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|