Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

2 lines
5.1 KiB
JavaScript

var P=new Set(["GET","POST","PUT","PATCH","DELETE"]),g=class{constructor(e){if(this.listeners=new Set,this.sessionToken=null,this.themeTokens={},e?.expectedParentOrigin)this.expectedParentOrigin=e.expectedParentOrigin;else if(typeof window<"u"){let r=new URLSearchParams(window.location.search);this.expectedParentOrigin=r.get("parentOrigin")||window.location.origin}else this.expectedParentOrigin="";let o=typeof process<"u"&&process.env&&!1,d=typeof window<"u"&&window.__ALGA_DEV__===!0;this.devWildcard=e?.devAllowWildcard??!!(o||d),typeof window<"u"&&window.addEventListener("message",r=>{if(!this.devWildcard&&this.expectedParentOrigin&&r.origin!==this.expectedParentOrigin)return;let t=r.data;if(!t||typeof t!="object")return;if(t.alga!==!0||t.version!=="1"||typeof t.type!="string"){console.warn("[SDK] Ignoring message with invalid envelope",{origin:r.origin,data:t});return}console.log("[SDK] Received host message",{type:t.type,origin:r.origin,requestId:t.request_id}),t.type==="apiproxy_response"&&console.log("[SDK] Received apiproxy_response",{requestId:t.request_id,hasBody:!!t.payload?.body,error:t.payload?.error,origin:r.origin});let i=t;if(i.type==="bootstrap"){let s=i.payload;if(s?.theme_tokens&&typeof document<"u"){this.themeTokens=s.theme_tokens;let l=document.documentElement;Object.entries(this.themeTokens).forEach(([c,a])=>{try{l.style.setProperty(c,String(a))}catch{}})}s?.session?.token&&(this.sessionToken=s.session.token)}this.listeners.forEach(s=>s(i))})}ready(e){this.emitToHost("ready",{},e)}on(e){return this.listeners.add(e),()=>this.listeners.delete(e)}emitToHost(e,o,d){if(typeof window>"u")return;let r={alga:!0,version:"1",type:e,request_id:d,payload:o},t=this.devWildcard?"*":this.expectedParentOrigin||"*";window.parent?.postMessage(r,t)}getSessionToken(){return this.sessionToken}getThemeTokens(){return this.themeTokens}setExpectedParentOrigin(e){this.expectedParentOrigin=e}resolveProxyMethod(e){let o=(e??"POST").toUpperCase();if(P.has(o))return o;throw new Error(`Unsupported proxy method: ${e}`)}async callProxy(e,o,d={}){return new Promise((r,t)=>{let i=typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():String(Math.random());console.log(`[SDK] Starting callProxy for route: ${e}, requestId: ${i}`);let s=this.resolveProxyMethod(d.method);if(s==="GET"&&o){t(new Error("GET requests cannot include a body"));return}let l=this.on(a=>{if(a.type==="apiproxy_response"&&a.request_id===i)if(console.log(`[SDK] Received apiproxy_response for requestId: ${i}`),l(),a.payload.error)console.warn(`[SDK] Proxy response error for requestId: ${i}, error: ${a.payload.error}`),t(new Error(a.payload.error));else{let p=a.payload.body||"";try{let h=atob(p),w=h.length,x=new Uint8Array(w);for(let m=0;m<w;m++)x[m]=h.charCodeAt(m);r(x)}catch(h){console.error(`[SDK] Failed to decode proxy response for requestId: ${i}`,h),t(new Error("Failed to decode proxy response"))}}}),c;if(o){let a="";for(let p=0;p<o.length;p++)a+=String.fromCharCode(o[p]);c=btoa(a)}console.log(`[SDK] Emitting 'apiproxy' message to host. requestId: ${i}`),this.emitToHost("apiproxy",{route:e,body:c,method:s},i),setTimeout(()=>{console.warn(`[SDK] Timeout reached for requestId: ${i}`),l(),t(new Error("Proxy request timed out"))},15e3)})}get uiProxy(){return{callRoute:this.callProxy.bind(this),call:this.callProxy.bind(this)}}};var b=new TextEncoder,S=new TextDecoder;function O(n){let e=n;return e.uiProxy?e.uiProxy:n}function D(n){let e=(n??"GET").toUpperCase();if(e==="GET"||e==="POST"||e==="PUT"||e==="PATCH"||e==="DELETE")return e;throw new Error(`Unsupported method: ${n}`)}async function E(n,e,o={}){let d=D(o.method),r=O(n),t=r.callRoute??r.call;if(!t)throw new Error("uiProxy host does not implement callRoute");if(d==="GET"&&typeof o.body<"u")throw new Error("GET requests cannot include a body");let i=o.body,s=typeof i>"u"?void 0:b.encode(JSON.stringify(i)),l=await t.call(r,e,s??void 0,{method:d}),c=S.decode(l);return c.length?JSON.parse(c):null}var T=document.getElementById("output"),y=document.getElementById("btn-create"),v=document.getElementById("btn-status");function f(n){T&&(T.textContent=JSON.stringify(n,null,2))}function u(n){return document.getElementById(n)?.value??""}async function I(){let n=new g({devAllowWildcard:!0});n.ready(),v?.addEventListener("click",async()=>{try{let e=await E(n,"/api/status");f({ok:!0,data:e})}catch(e){f({ok:!1,error:e instanceof Error?e.message:String(e)})}}),y?.addEventListener("click",async()=>{if(y){y.disabled=!0,y.textContent="Creating...";try{let e=u("clientId").trim(),o=u("serviceId").trim(),d=u("invoiceDate").trim(),r=u("dueDate").trim(),t=u("poNumber").trim(),i=Number(u("quantity")),s=Number(u("rateDollars")),l=u("description"),c=Number.isFinite(s)?Math.round(s*100):s,p=await E(n,"/api/create-manual-invoice",{method:"POST",body:{clientId:e,invoiceDate:d||void 0,dueDate:r||void 0,poNumber:t||null,items:[{serviceId:o,quantity:i,description:l,rate:c}]}});f({ok:!0,data:p})}catch(e){f({ok:!1,error:e instanceof Error?e.message:String(e)})}finally{y.disabled=!1,y.textContent="Create Draft Invoice"}}})}I().catch(n=>{f({ok:!1,error:n instanceof Error?n.message:String(n)})});