@swishapp/auth-proxy 0.2.0 → 0.3.0-unstable.20260706101112

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.
@@ -1 +1 @@
1
- var y=Object.defineProperty;var o=(e,t)=>y(e,"name",{value:t,configurable:!0});const l="https://swish.app/api",f="2026-04",T=new Set(["2025-04","2025-07","2025-10","2026-01","2026-04","2026-07","unstable"]),w=o(e=>new A(e),"createAuthProxy");class A{static{o(this,"AuthProxy")}constructor({authToken:t,authenticate:n,onError:r}){this.authToken=t,this.authenticate=n,this.onError=r}async createToken(t){try{const n=await this.authenticate(t)||null,r=typeof this.authToken=="function"?await this.authToken(t):this.authToken,s=await t.text(),a=s?JSON.parse(s):{};if(a.customer){const c=n?u(n):null,d=u(String(a.customer));if(c!==d)return new Response(JSON.stringify({error:"Unauthorized"}),{status:401,headers:{"Content-Type":"application/json"}})}const h=O(t),p=`${l}/${h}/profiles/token`,i=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:s||void 0});return new Response(i.body,{status:i.status,headers:i.headers})}catch(n){return this.onError?.(n),new Response(JSON.stringify({error:"Unauthorized",cause:n}),{status:401,headers:{"Content-Type":"application/json"}})}}}function O(e){const t=e.headers.get("swish-api-version");return t&&T.has(t)?t:f}o(O,"resolveApiVersion");function u(e){return e.startsWith("gid://")?e:`gid://shopify/Customer/${e.split("/").pop()}`}o(u,"toCustomerGid");export{A as AuthProxy,w as createAuthProxy};
1
+ var y=Object.defineProperty;var o=(e,t)=>y(e,"name",{value:t,configurable:!0});const l="https://swish.app/api",f="2026-04",A="https://unstable.swish.app/api/2026-07",T=new Set(["2025-04","2025-07","2025-10","2026-01","2026-04","2026-07","unstable"]),S=o(e=>new P(e),"createAuthProxy");class P{static{o(this,"AuthProxy")}constructor({authToken:t,authenticate:n,onError:s}){this.authToken=t,this.authenticate=n,this.onError=s}async createToken(t){try{const n=await this.authenticate(t)||null,s=typeof this.authToken=="function"?await this.authToken(t):this.authToken,r=await t.text(),a=r?JSON.parse(r):{};if(a.customer){const c=n?h(n):null,d=h(String(a.customer));if(c!==d)return new Response(JSON.stringify({error:"Unauthorized"}),{status:401,headers:{"Content-Type":"application/json"}})}const u=w(t),p=u==="unstable"?`${A}/profiles/token`:`${l}/${u}/profiles/token`,i=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:r||void 0});return new Response(i.body,{status:i.status,headers:i.headers})}catch(n){return this.onError?.(n),new Response(JSON.stringify({error:"Unauthorized",cause:n}),{status:401,headers:{"Content-Type":"application/json"}})}}}function w(e){const t=e.headers.get("swish-api-version");return t&&T.has(t)?t:f}o(w,"resolveApiVersion");function h(e){return e.startsWith("gid://")?e:`gid://shopify/Customer/${e.split("/").pop()}`}o(h,"toCustomerGid");export{P as AuthProxy,S as createAuthProxy};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swishapp/auth-proxy",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-unstable.20260706101112",
4
4
  "description": "Server-side auth token proxy for Swish on custom storefronts.",
5
5
  "author": "Swish",
6
6
  "license": "UNLICENSED",