@uninspired/auth-client 0.0.12 → 0.0.14

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/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var{defineProperty:u,getOwnPropertyNames:y,getOwnPropertyDescriptor:g}=Object,R=Object.prototype.hasOwnProperty;var a=new WeakMap,k=(e)=>{var t=a.get(e),n;if(t)return t;if(t=u({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")y(e).map((r)=>!R.call(t,r)&&u(t,r,{get:()=>e[r],enumerable:!(n=g(e,r))||n.enumerable}));return a.set(e,t),t};var x=(e,t)=>{for(var n in t)u(e,n,{get:t[n],enumerable:!0,configurable:!0,set:(r)=>t[n]=()=>r})};var S={};x(S,{makeUsBetterAuthClient:()=>A,makeRedirectIntent:()=>C,makePublicClient:()=>P,makeLoginUrl:()=>O,makeCheckoutUrl:()=>q,makeCheckoutClient:()=>d,makeAppClient:()=>b});module.exports=k(S);var m=require("hono/client"),P=(e,t)=>{return m.hc(e,t)};var h=require("hono/client"),b=(e,t)=>{return h.hc(e,{...t,fetch:(n,r)=>(t?.fetch??fetch)(n,{...r,credentials:"include",headers:{...r.headers,"Content-Type":"application/json"}})})};var o=require("better-auth/client/plugins"),f=require("better-auth/react"),A=(e)=>{return f.createAuthClient({baseURL:e,plugins:[o.customSessionClient(),o.magicLinkClient(),o.emailOTPClient(),o.passkeyClient()]})};var l=require("hono/client"),d=(e,t)=>{return l.hc(e,{...t,fetch:(n,r)=>(t?.fetch??fetch)(n,{...r,credentials:"include",headers:{...r.headers,"Content-Type":"application/json"}})})};function O(e,t,n){let r=new URL("/login",e);if(t)r.searchParams.set("intent",C(t,n));return r.toString()}function j(...e){}function q(e,t,n,r,s,p,c){j({priceId:t,productId:n,discountCode:r,loginUrl:s,pricingUrl:p,successUrl:c});let i=new URL("/auth/checkout",e);if(i.searchParams.set("priceId",t),i.searchParams.set("productId",n),r)i.searchParams.set("discountCode",r);if(s)i.searchParams.set("loginUrl",s);if(p)i.searchParams.set("pricingUrl",p);if(c)i.searchParams.set("successUrl",c);return i.toString()}function C(e,t){return JSON.stringify({type:"redirect",redirectUrl:e,appName:t})}
1
+ var{defineProperty:a,getOwnPropertyNames:R,getOwnPropertyDescriptor:x}=Object,d=Object.prototype.hasOwnProperty;var c=new WeakMap,k=(t)=>{var e=c.get(t),r;if(e)return e;if(e=a({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function")R(t).map((n)=>!d.call(e,n)&&a(e,n,{get:()=>t[n],enumerable:!(r=x(t,n))||r.enumerable}));return c.set(t,e),e};var P=(t,e)=>{for(var r in e)a(t,r,{get:e[r],enumerable:!0,configurable:!0,set:(n)=>e[r]=()=>n})};var U={};P(U,{makeUsBetterAuthClient:()=>S,makeRedirectIntent:()=>y,makePublicClient:()=>b,makeMailingListClient:()=>O,makeLoginUrl:()=>T,makeCheckoutUrl:()=>j,makeCheckoutClient:()=>L,makeAppClient:()=>A,hasUserSubscribed:()=>I,hasUserPurchased:()=>M,formatPrice:()=>g.formatPrice});module.exports=k(U);var l=require("hono/client"),b=(t,e)=>{return l.hc(t,e)};var m=require("hono/client"),A=(t,e)=>{return m.hc(t,{...e,fetch:(r,n)=>(e?.fetch??fetch)(r,{...n,credentials:"include",headers:{...n.headers,"Content-Type":"application/json"}})})};var o=require("better-auth/client/plugins"),f=require("better-auth/react"),S=(t)=>{return f.createAuthClient({baseURL:t,plugins:[o.customSessionClient(),o.magicLinkClient(),o.emailOTPClient(),o.passkeyClient()]})};var h=require("hono/client"),L=(t,e)=>{return h.hc(t,{...e,fetch:(r,n)=>(e?.fetch??fetch)(r,{...n,credentials:"include",headers:{...n.headers,"Content-Type":"application/json"}})})};var C=require("hono/client"),O=(t,e,r)=>{return C.hc(t,{...r,headers:{...r?.headers,"X-Public-Key":e}})};function T(t,e,r){let n=new URL("/login",t);if(e)n.searchParams.set("intent",y(e,r));return n.toString()}function q(...t){}function j(t,e,r,n,s,p,u){q({priceId:e,productId:r,discountCode:n,loginUrl:s,pricingUrl:p,successUrl:u});let i=new URL("/auth/checkout",t);if(i.searchParams.set("priceId",e),i.searchParams.set("productId",r),n)i.searchParams.set("discountCode",n);if(s)i.searchParams.set("loginUrl",s);if(p)i.searchParams.set("pricingUrl",p);if(u)i.searchParams.set("successUrl",u);return i.toString()}function y(t,e){return JSON.stringify({type:"redirect",redirectUrl:t,appName:e})}function M(t,e){if(!t)return!1;return t.products.transactions.some((r)=>{r.productId===e&&r.status})}function I(t,e){if(!t)return!1;return t.products.subscriptions.some((r)=>{r.productId===e&&r.status})}var g=require("@us-accounts/utils");
2
2
 
3
- //# debugId=D2A8D8299A3497FE64756E2164756E21
3
+ //# debugId=F78CCA901C70F47064756E2164756E21
4
4
  //# sourceMappingURL=index.js.map
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/clients/publicClient.ts", "../../src/clients/appClient.ts", "../../src/clients/authClient.ts", "../../src/clients/checkoutClient.ts", "../../src/utils/intent.ts"],
3
+ "sources": ["../../src/clients/publicClient.ts", "../../src/clients/appClient.ts", "../../src/clients/authClient.ts", "../../src/clients/checkoutClient.ts", "../../src/clients/mailingListClient.ts", "../../src/utils/intent.ts", "../../src/utils/purchase.ts", "../../src/utils/index.ts"],
4
4
  "sourcesContent": [
5
5
  "import type { PublicRouter } from \"@us-accounts/api\";\nimport { hc, type ClientRequestOptions } from \"hono/client\";\n\nexport type PublicClient = ReturnType<typeof hc<PublicRouter>>;\n\nexport const makePublicClient = (\n baseURL: string,\n options?: ClientRequestOptions,\n): PublicClient => {\n return hc<PublicRouter>(baseURL, options);\n};\n",
6
6
  "import type { AppRouter } from \"@us-accounts/api\";\nimport { hc, type ClientRequestOptions } from \"hono/client\";\n\nexport type AppClient = ReturnType<typeof hc<AppRouter>>;\n\nexport const makeAppClient = (\n baseURL: string,\n options?: ClientRequestOptions,\n): AppClient => {\n return hc<AppRouter>(baseURL, {\n ...options,\n fetch: (url: any, init: any) =>\n (options?.fetch ?? fetch)(url, {\n ...init,\n credentials: \"include\",\n headers: {\n ...init.headers,\n \"Content-Type\": \"application/json\",\n },\n }),\n });\n};\n",
7
- "import {\n customSessionClient,\n magicLinkClient,\n emailOTPClient,\n passkeyClient,\n} from \"better-auth/client/plugins\";\nimport { createAuthClient } from \"better-auth/react\";\nimport type { Auth } from \"@us-accounts/api\";\n\nexport const makeUsBetterAuthClient = (baseURL: string) => {\n return createAuthClient({\n baseURL,\n plugins: [\n customSessionClient<Auth>(),\n magicLinkClient(),\n emailOTPClient(),\n passkeyClient(),\n ],\n });\n};\n",
7
+ "import {\n customSessionClient,\n magicLinkClient,\n emailOTPClient,\n passkeyClient,\n} from \"better-auth/client/plugins\";\nimport { createAuthClient } from \"better-auth/react\";\nimport type { Auth } from \"@us-accounts/api\";\n\nexport const makeUsBetterAuthClient = (baseURL: string) => {\n return createAuthClient({\n baseURL,\n plugins: [\n customSessionClient<Auth>(),\n magicLinkClient(),\n emailOTPClient(),\n passkeyClient(),\n ],\n });\n};\n\nexport type AuthClient = ReturnType<typeof makeUsBetterAuthClient>;\n",
8
8
  "import type { CheckoutRouter } from \"@us-accounts/api\";\nimport { hc, type ClientRequestOptions } from \"hono/client\";\n\nexport type CheckoutClient = ReturnType<typeof hc<CheckoutRouter>>;\n\nexport const makeCheckoutClient = (\n baseURL: string,\n options?: ClientRequestOptions,\n): CheckoutClient => {\n return hc<CheckoutRouter>(baseURL, {\n ...options,\n fetch: (url: any, init: any) =>\n (options?.fetch ?? fetch)(url, {\n ...init,\n credentials: \"include\",\n headers: {\n ...init.headers,\n \"Content-Type\": \"application/json\",\n },\n }),\n });\n};\n",
9
- "import type { CheckoutSearch, RedirectIntent } from \"@us-accounts/utils\";\n\nexport function makeLoginUrl(\n apiUrl: string,\n redirectUrl?: string,\n appName?: string,\n) {\n const url = new URL(\"/login\", apiUrl);\n if (redirectUrl) {\n url.searchParams.set(\"intent\", makeRedirectIntent(redirectUrl, appName));\n }\n return url.toString();\n}\n\nfunction noop(...args: any[]) {\n // Do nothing\n}\n\nexport function makeCheckoutUrl(\n apiUrl: string,\n priceId: string,\n productId: string,\n discountCode?: string,\n loginUrl?: string,\n pricingUrl?: string,\n successUrl?: string,\n) {\n const obj = {\n priceId,\n productId,\n discountCode,\n loginUrl,\n pricingUrl,\n successUrl,\n } satisfies CheckoutSearch;\n noop(obj);\n\n const url = new URL(\"/auth/checkout\", apiUrl);\n url.searchParams.set(\"priceId\", priceId);\n url.searchParams.set(\"productId\", productId);\n if (discountCode) {\n url.searchParams.set(\"discountCode\", discountCode);\n }\n if (loginUrl) {\n url.searchParams.set(\"loginUrl\", loginUrl);\n }\n if (pricingUrl) {\n url.searchParams.set(\"pricingUrl\", pricingUrl);\n }\n if (successUrl) {\n url.searchParams.set(\"successUrl\", successUrl);\n }\n return url.toString();\n}\n\nexport function makeRedirectIntent(\n redirectUrl: string,\n appName?: string,\n): string {\n const obj = {\n type: \"redirect\",\n redirectUrl,\n appName,\n } satisfies RedirectIntent;\n\n return JSON.stringify(obj);\n}\n"
9
+ "import type { MailingListRouter } from \"@us-accounts/api\";\nimport { hc, type ClientRequestOptions } from \"hono/client\";\n\nexport type MailingListClient = ReturnType<typeof hc<MailingListRouter>>;\n\nexport const makeMailingListClient = (\n baseURL: string,\n publicKey: string,\n options?: ClientRequestOptions,\n): MailingListClient => {\n return hc<MailingListRouter>(baseURL, {\n ...options,\n headers: {\n ...options?.headers,\n \"X-Public-Key\": publicKey,\n },\n });\n};\n",
10
+ "import type { CheckoutSearch, RedirectIntent } from \"@us-accounts/utils\";\n\nexport function makeLoginUrl(\n apiUrl: string,\n redirectUrl?: string,\n appName?: string,\n) {\n const url = new URL(\"/login\", apiUrl);\n if (redirectUrl) {\n url.searchParams.set(\"intent\", makeRedirectIntent(redirectUrl, appName));\n }\n return url.toString();\n}\n\nfunction noop(...args: any[]) {\n // Do nothing\n}\n\nexport function makeCheckoutUrl(\n apiUrl: string,\n priceId: string,\n productId: string,\n discountCode?: string,\n loginUrl?: string,\n pricingUrl?: string,\n successUrl?: string,\n) {\n const obj = {\n priceId,\n productId,\n discountCode,\n loginUrl,\n pricingUrl,\n successUrl,\n } satisfies CheckoutSearch;\n noop(obj);\n\n const url = new URL(\"/auth/checkout\", apiUrl);\n url.searchParams.set(\"priceId\", priceId);\n url.searchParams.set(\"productId\", productId);\n if (discountCode) {\n url.searchParams.set(\"discountCode\", discountCode);\n }\n if (loginUrl) {\n url.searchParams.set(\"loginUrl\", loginUrl);\n }\n if (pricingUrl) {\n url.searchParams.set(\"pricingUrl\", pricingUrl);\n }\n if (successUrl) {\n url.searchParams.set(\"successUrl\", successUrl);\n }\n return url.toString();\n}\n\nexport function makeRedirectIntent(\n redirectUrl: string,\n appName?: string,\n): string {\n const obj = {\n type: \"redirect\",\n redirectUrl,\n appName,\n } satisfies RedirectIntent;\n\n return JSON.stringify(obj);\n}\n",
11
+ "import type { AuthClient } from \"../clients/authClient\";\n\nexport type SessionData = ReturnType<AuthClient[\"useSession\"]>[\"data\"];\n\nexport function hasUserPurchased(\n sessionData: SessionData,\n productId: string,\n): boolean {\n if (!sessionData) return false;\n return sessionData.products.transactions.some((transaction) => {\n transaction.productId === productId && transaction.status === \"completed\";\n });\n}\n\nexport function hasUserSubscribed(\n sessionData: SessionData,\n productId: string,\n): boolean {\n if (!sessionData) return false;\n return sessionData.products.subscriptions.some((subscription) => {\n subscription.productId === productId && subscription.status === \"active\";\n });\n}\n",
12
+ "export * from \"./intent\";\nexport * from \"./purchase\";\nexport { formatPrice } from \"@us-accounts/utils\";\n"
10
13
  ],
11
- "mappings": "gpBAC8C,IAA9C,yBAIa,EAAmB,CAC9B,EACA,IACiB,CACjB,OAAO,KAAiB,EAAS,CAAO,GCRI,IAA9C,yBAIa,EAAgB,CAC3B,EACA,IACc,CACd,OAAO,KAAc,EAAS,IACzB,EACH,MAAO,CAAC,EAAU,KACf,GAAS,OAAS,OAAO,EAAK,IAC1B,EACH,Y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AAI,aAAa,IAAI,eAAgB,CAAY,EAEnD,GAAI,EACF,EAAI,aAAa,IAAI,WAAY,CAAQ,EAE3C,GAAI,EACF,EAAI,aAAa,IAAI,aAAc,CAAU,EAE/C,GAAI,EACF,EAAI,aAAa,IAAI,aAAc,CAAU,EAE/C,OAAO,EAAI,SAAS,EAGf,SAAS,CAAkB,CAChC,EACA,EACQ,CAOR,OAAO,KAAK,UANA,CACV,KAAM,WACN,cACA,SACF,CAEyB,EC7DpB,SAAS,CAAgB,CAC9B,EACA,EACS,CACT,GAAI,CAAC,EAAa,MAAO,GACzB,OAAO,EAAY,SAAS,aAAa,KAAK,CAAC,IAAgB,CAC7D,EAAY,YAAc,GAAa,EAAY,OACpD,EAGI,SAAS,CAAiB,CAC/B,EACA,EACS,CACT,GAAI,CAAC,EAAa,MAAO,GACzB,OAAO,EAAY,SAAS,cAAc,KAAK,CAAC,IAAiB,CAC/D,EAAa,YAAc,GAAa,EAAa,OACtD,ECnByB,IAA5B",
15
+ "debugId": "F78CCA901C70F47064756E2164756E21",
13
16
  "names": []
14
17
  }
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{hc as c}from"hono/client";var x=(e,t)=>{return c(e,t)};import{hc as u}from"hono/client";var A=(e,t)=>{return u(e,{...t,fetch:(n,r)=>(t?.fetch??fetch)(n,{...r,credentials:"include",headers:{...r.headers,"Content-Type":"application/json"}})})};import{customSessionClient as a,magicLinkClient as m,emailOTPClient as h,passkeyClient as f}from"better-auth/client/plugins";import{createAuthClient as l}from"better-auth/react";var q=(e)=>{return l({baseURL:e,plugins:[a(),m(),h(),f()]})};import{hc as C}from"hono/client";var L=(e,t)=>{return C(e,{...t,fetch:(n,r)=>(t?.fetch??fetch)(n,{...r,credentials:"include",headers:{...r.headers,"Content-Type":"application/json"}})})};function v(e,t,n){let r=new URL("/login",e);if(t)r.searchParams.set("intent",g(t,n));return r.toString()}function y(...e){}function z(e,t,n,r,i,s,p){y({priceId:t,productId:n,discountCode:r,loginUrl:i,pricingUrl:s,successUrl:p});let o=new URL("/auth/checkout",e);if(o.searchParams.set("priceId",t),o.searchParams.set("productId",n),r)o.searchParams.set("discountCode",r);if(i)o.searchParams.set("loginUrl",i);if(s)o.searchParams.set("pricingUrl",s);if(p)o.searchParams.set("successUrl",p);return o.toString()}function g(e,t){return JSON.stringify({type:"redirect",redirectUrl:e,appName:t})}export{q as makeUsBetterAuthClient,g as makeRedirectIntent,x as makePublicClient,v as makeLoginUrl,z as makeCheckoutUrl,L as makeCheckoutClient,A as makeAppClient};
1
+ import{hc as u}from"hono/client";var k=(t,e)=>{return u(t,e)};import{hc as a}from"hono/client";var A=(t,e)=>{return a(t,{...e,fetch:(r,n)=>(e?.fetch??fetch)(r,{...n,credentials:"include",headers:{...n.headers,"Content-Type":"application/json"}})})};import{customSessionClient as c,magicLinkClient as l,emailOTPClient as m,passkeyClient as f}from"better-auth/client/plugins";import{createAuthClient as h}from"better-auth/react";var T=(t)=>{return h({baseURL:t,plugins:[c(),l(),m(),f()]})};import{hc as C}from"hono/client";var M=(t,e)=>{return C(t,{...e,fetch:(r,n)=>(e?.fetch??fetch)(r,{...n,credentials:"include",headers:{...n.headers,"Content-Type":"application/json"}})})};import{hc as y}from"hono/client";var w=(t,e,r)=>{return y(t,{...r,headers:{...r?.headers,"X-Public-Key":e}})};function z(t,e,r){let n=new URL("/login",t);if(e)n.searchParams.set("intent",R(e,r));return n.toString()}function g(...t){}function E(t,e,r,n,i,s,p){g({priceId:e,productId:r,discountCode:n,loginUrl:i,pricingUrl:s,successUrl:p});let o=new URL("/auth/checkout",t);if(o.searchParams.set("priceId",e),o.searchParams.set("productId",r),n)o.searchParams.set("discountCode",n);if(i)o.searchParams.set("loginUrl",i);if(s)o.searchParams.set("pricingUrl",s);if(p)o.searchParams.set("successUrl",p);return o.toString()}function R(t,e){return JSON.stringify({type:"redirect",redirectUrl:t,appName:e})}function G(t,e){if(!t)return!1;return t.products.transactions.some((r)=>{r.productId===e&&r.status})}function H(t,e){if(!t)return!1;return t.products.subscriptions.some((r)=>{r.productId===e&&r.status})}import{formatPrice as _}from"@us-accounts/utils";export{T as makeUsBetterAuthClient,R as makeRedirectIntent,k as makePublicClient,w as makeMailingListClient,z as makeLoginUrl,E as makeCheckoutUrl,M as makeCheckoutClient,A as makeAppClient,H as hasUserSubscribed,G as hasUserPurchased,_ as formatPrice};
2
2
 
3
- //# debugId=F9376091D0570D8C64756E2164756E21
3
+ //# debugId=10219B7A43FFF4DC64756E2164756E21
4
4
  //# sourceMappingURL=index.js.map
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/clients/publicClient.ts", "../../src/clients/appClient.ts", "../../src/clients/authClient.ts", "../../src/clients/checkoutClient.ts", "../../src/utils/intent.ts"],
3
+ "sources": ["../../src/clients/publicClient.ts", "../../src/clients/appClient.ts", "../../src/clients/authClient.ts", "../../src/clients/checkoutClient.ts", "../../src/clients/mailingListClient.ts", "../../src/utils/intent.ts", "../../src/utils/purchase.ts", "../../src/utils/index.ts"],
4
4
  "sourcesContent": [
5
5
  "import type { PublicRouter } from \"@us-accounts/api\";\nimport { hc, type ClientRequestOptions } from \"hono/client\";\n\nexport type PublicClient = ReturnType<typeof hc<PublicRouter>>;\n\nexport const makePublicClient = (\n baseURL: string,\n options?: ClientRequestOptions,\n): PublicClient => {\n return hc<PublicRouter>(baseURL, options);\n};\n",
6
6
  "import type { AppRouter } from \"@us-accounts/api\";\nimport { hc, type ClientRequestOptions } from \"hono/client\";\n\nexport type AppClient = ReturnType<typeof hc<AppRouter>>;\n\nexport const makeAppClient = (\n baseURL: string,\n options?: ClientRequestOptions,\n): AppClient => {\n return hc<AppRouter>(baseURL, {\n ...options,\n fetch: (url: any, init: any) =>\n (options?.fetch ?? fetch)(url, {\n ...init,\n credentials: \"include\",\n headers: {\n ...init.headers,\n \"Content-Type\": \"application/json\",\n },\n }),\n });\n};\n",
7
- "import {\n customSessionClient,\n magicLinkClient,\n emailOTPClient,\n passkeyClient,\n} from \"better-auth/client/plugins\";\nimport { createAuthClient } from \"better-auth/react\";\nimport type { Auth } from \"@us-accounts/api\";\n\nexport const makeUsBetterAuthClient = (baseURL: string) => {\n return createAuthClient({\n baseURL,\n plugins: [\n customSessionClient<Auth>(),\n magicLinkClient(),\n emailOTPClient(),\n passkeyClient(),\n ],\n });\n};\n",
7
+ "import {\n customSessionClient,\n magicLinkClient,\n emailOTPClient,\n passkeyClient,\n} from \"better-auth/client/plugins\";\nimport { createAuthClient } from \"better-auth/react\";\nimport type { Auth } from \"@us-accounts/api\";\n\nexport const makeUsBetterAuthClient = (baseURL: string) => {\n return createAuthClient({\n baseURL,\n plugins: [\n customSessionClient<Auth>(),\n magicLinkClient(),\n emailOTPClient(),\n passkeyClient(),\n ],\n });\n};\n\nexport type AuthClient = ReturnType<typeof makeUsBetterAuthClient>;\n",
8
8
  "import type { CheckoutRouter } from \"@us-accounts/api\";\nimport { hc, type ClientRequestOptions } from \"hono/client\";\n\nexport type CheckoutClient = ReturnType<typeof hc<CheckoutRouter>>;\n\nexport const makeCheckoutClient = (\n baseURL: string,\n options?: ClientRequestOptions,\n): CheckoutClient => {\n return hc<CheckoutRouter>(baseURL, {\n ...options,\n fetch: (url: any, init: any) =>\n (options?.fetch ?? fetch)(url, {\n ...init,\n credentials: \"include\",\n headers: {\n ...init.headers,\n \"Content-Type\": \"application/json\",\n },\n }),\n });\n};\n",
9
- "import type { CheckoutSearch, RedirectIntent } from \"@us-accounts/utils\";\n\nexport function makeLoginUrl(\n apiUrl: string,\n redirectUrl?: string,\n appName?: string,\n) {\n const url = new URL(\"/login\", apiUrl);\n if (redirectUrl) {\n url.searchParams.set(\"intent\", makeRedirectIntent(redirectUrl, appName));\n }\n return url.toString();\n}\n\nfunction noop(...args: any[]) {\n // Do nothing\n}\n\nexport function makeCheckoutUrl(\n apiUrl: string,\n priceId: string,\n productId: string,\n discountCode?: string,\n loginUrl?: string,\n pricingUrl?: string,\n successUrl?: string,\n) {\n const obj = {\n priceId,\n productId,\n discountCode,\n loginUrl,\n pricingUrl,\n successUrl,\n } satisfies CheckoutSearch;\n noop(obj);\n\n const url = new URL(\"/auth/checkout\", apiUrl);\n url.searchParams.set(\"priceId\", priceId);\n url.searchParams.set(\"productId\", productId);\n if (discountCode) {\n url.searchParams.set(\"discountCode\", discountCode);\n }\n if (loginUrl) {\n url.searchParams.set(\"loginUrl\", loginUrl);\n }\n if (pricingUrl) {\n url.searchParams.set(\"pricingUrl\", pricingUrl);\n }\n if (successUrl) {\n url.searchParams.set(\"successUrl\", successUrl);\n }\n return url.toString();\n}\n\nexport function makeRedirectIntent(\n redirectUrl: string,\n appName?: string,\n): string {\n const obj = {\n type: \"redirect\",\n redirectUrl,\n appName,\n } satisfies RedirectIntent;\n\n return JSON.stringify(obj);\n}\n"
9
+ "import type { MailingListRouter } from \"@us-accounts/api\";\nimport { hc, type ClientRequestOptions } from \"hono/client\";\n\nexport type MailingListClient = ReturnType<typeof hc<MailingListRouter>>;\n\nexport const makeMailingListClient = (\n baseURL: string,\n publicKey: string,\n options?: ClientRequestOptions,\n): MailingListClient => {\n return hc<MailingListRouter>(baseURL, {\n ...options,\n headers: {\n ...options?.headers,\n \"X-Public-Key\": publicKey,\n },\n });\n};\n",
10
+ "import type { CheckoutSearch, RedirectIntent } from \"@us-accounts/utils\";\n\nexport function makeLoginUrl(\n apiUrl: string,\n redirectUrl?: string,\n appName?: string,\n) {\n const url = new URL(\"/login\", apiUrl);\n if (redirectUrl) {\n url.searchParams.set(\"intent\", makeRedirectIntent(redirectUrl, appName));\n }\n return url.toString();\n}\n\nfunction noop(...args: any[]) {\n // Do nothing\n}\n\nexport function makeCheckoutUrl(\n apiUrl: string,\n priceId: string,\n productId: string,\n discountCode?: string,\n loginUrl?: string,\n pricingUrl?: string,\n successUrl?: string,\n) {\n const obj = {\n priceId,\n productId,\n discountCode,\n loginUrl,\n pricingUrl,\n successUrl,\n } satisfies CheckoutSearch;\n noop(obj);\n\n const url = new URL(\"/auth/checkout\", apiUrl);\n url.searchParams.set(\"priceId\", priceId);\n url.searchParams.set(\"productId\", productId);\n if (discountCode) {\n url.searchParams.set(\"discountCode\", discountCode);\n }\n if (loginUrl) {\n url.searchParams.set(\"loginUrl\", loginUrl);\n }\n if (pricingUrl) {\n url.searchParams.set(\"pricingUrl\", pricingUrl);\n }\n if (successUrl) {\n url.searchParams.set(\"successUrl\", successUrl);\n }\n return url.toString();\n}\n\nexport function makeRedirectIntent(\n redirectUrl: string,\n appName?: string,\n): string {\n const obj = {\n type: \"redirect\",\n redirectUrl,\n appName,\n } satisfies RedirectIntent;\n\n return JSON.stringify(obj);\n}\n",
11
+ "import type { AuthClient } from \"../clients/authClient\";\n\nexport type SessionData = ReturnType<AuthClient[\"useSession\"]>[\"data\"];\n\nexport function hasUserPurchased(\n sessionData: SessionData,\n productId: string,\n): boolean {\n if (!sessionData) return false;\n return sessionData.products.transactions.some((transaction) => {\n transaction.productId === productId && transaction.status === \"completed\";\n });\n}\n\nexport function hasUserSubscribed(\n sessionData: SessionData,\n productId: string,\n): boolean {\n if (!sessionData) return false;\n return sessionData.products.subscriptions.some((subscription) => {\n subscription.productId === productId && subscription.status === \"active\";\n });\n}\n",
12
+ "export * from \"./intent\";\nexport * from \"./purchase\";\nexport { formatPrice } from \"@us-accounts/utils\";\n"
10
13
  ],
11
- "mappings": "AACA,aAAS,oBAIF,IAAM,EAAmB,CAC9B,EACA,IACiB,CACjB,OAAO,EAAiB,EAAS,CAAO,GCR1C,aAAS,oBAIF,IAAM,EAAgB,CAC3B,EACA,IACc,CACd,OAAO,EAAc,EAAS,IACzB,EACH,MAAO,CAAC,EAAU,KACf,GAAS,OAAS,OAAO,EAAK,IAC1B,EACH,YAAa,UACb,QAAS,IACJ,EAAK,QACR,eAAgB,kBAClB,CACF,CAAC,CACL,CAAC,GCpBH,8BACE,qBACA,oBACA,mBACA,mCAEF,2BAAS,0BAGF,IAAM,EAAyB,CAAC,IAAoB,CACzD,OAAO,EAAiB,C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AAI,aAAa,IAAI,aAAc,CAAU,EAE/C,GAAI,EACF,EAAI,aAAa,IAAI,aAAc,CAAU,EAE/C,OAAO,EAAI,SAAS,EAGf,SAAS,CAAkB,CAChC,EACA,EACQ,CAOR,OAAO,KAAK,UANA,CACV,KAAM,WACN,cACA,SACF,CAEyB,EC7DpB,SAAS,CAAgB,CAC9B,EACA,EACS,CACT,GAAI,CAAC,EAAa,MAAO,GACzB,OAAO,EAAY,SAAS,aAAa,KAAK,CAAC,IAAgB,CAC7D,EAAY,YAAc,GAAa,EAAY,OACpD,EAGI,SAAS,CAAiB,CAC/B,EACA,EACS,CACT,GAAI,CAAC,EAAa,MAAO,GACzB,OAAO,EAAY,SAAS,cAAc,KAAK,CAAC,IAAiB,CAC/D,EAAa,YAAc,GAAa,EAAa,OACtD,ECnBH,sBAAS",
15
+ "debugId": "10219B7A43FFF4DC64756E2164756E21",
13
16
  "names": []
14
17
  }
@@ -8,6 +8,7 @@ import * as undici_types from 'undici-types';
8
8
  import * as better_auth from 'better-auth';
9
9
  import * as _better_fetch_fetch from '@better-fetch/fetch';
10
10
  import * as better_auth_plugins_passkey from 'better-auth/plugins/passkey';
11
+ import * as hono_types from 'hono/types';
11
12
 
12
13
  declare const checkoutRouter: hono_hono_base.HonoBase<{
13
14
  Variables: {
@@ -93,7 +94,7 @@ declare const appRouter: hono_hono_base.HonoBase<{
93
94
  input: {
94
95
  param: {
95
96
  subscriptionId: string;
96
- action: "cancel" | "update";
97
+ action: "update" | "cancel";
97
98
  };
98
99
  };
99
100
  output: undefined;
@@ -246,6 +247,114 @@ declare const publicRouter: hono_hono_base.HonoBase<{
246
247
  }, "/">;
247
248
  type PublicRouter = typeof publicRouter;
248
249
 
250
+ declare const mailingListRouter: hono_hono_base.HonoBase<hono_types.BlankEnv, {
251
+ "/subscribe": {
252
+ $post: {
253
+ input: {
254
+ json: {
255
+ email: string;
256
+ userGroup: string;
257
+ callbackUrl: string;
258
+ };
259
+ };
260
+ output: "Unauthorized";
261
+ outputFormat: "text";
262
+ status: 401;
263
+ } | {
264
+ input: {
265
+ json: {
266
+ email: string;
267
+ userGroup: string;
268
+ callbackUrl: string;
269
+ };
270
+ };
271
+ output: "Success";
272
+ outputFormat: "text";
273
+ status: 200;
274
+ } | {
275
+ input: {
276
+ json: {
277
+ email: string;
278
+ userGroup: string;
279
+ callbackUrl: string;
280
+ };
281
+ };
282
+ output: "Could not send email";
283
+ outputFormat: "text";
284
+ status: 500;
285
+ } | {
286
+ input: {
287
+ json: {
288
+ email: string;
289
+ userGroup: string;
290
+ callbackUrl: string;
291
+ };
292
+ };
293
+ output: "Contact already subscribed";
294
+ outputFormat: "text";
295
+ status: 400;
296
+ };
297
+ };
298
+ } & {
299
+ "/opt-in": {
300
+ $get: {
301
+ input: {
302
+ query: {
303
+ code: string;
304
+ email: string;
305
+ };
306
+ };
307
+ output: undefined;
308
+ outputFormat: "redirect";
309
+ status: 302;
310
+ } | {
311
+ input: {
312
+ query: {
313
+ code: string;
314
+ email: string;
315
+ };
316
+ };
317
+ output: "Invalid opt-in token";
318
+ outputFormat: "text";
319
+ status: 400;
320
+ } | {
321
+ input: {
322
+ query: {
323
+ code: string;
324
+ email: string;
325
+ };
326
+ };
327
+ output: "Contact does not exist";
328
+ outputFormat: "text";
329
+ status: 400;
330
+ } | {
331
+ input: {
332
+ query: {
333
+ code: string;
334
+ email: string;
335
+ };
336
+ };
337
+ output: "Could not opt in contact";
338
+ outputFormat: "text";
339
+ status: 500;
340
+ };
341
+ };
342
+ } & {
343
+ "/unsubscribe": {
344
+ $post: {
345
+ input: {
346
+ query: {
347
+ email: string;
348
+ };
349
+ };
350
+ output: "Success";
351
+ outputFormat: "text";
352
+ status: 200;
353
+ };
354
+ };
355
+ }, "/">;
356
+ type MailingListRouter = typeof mailingListRouter;
357
+
249
358
  type PublicClient = ReturnType<typeof hc<PublicRouter>>;
250
359
  declare const makePublicClient: (baseURL: string, options?: ClientRequestOptions) => PublicClient;
251
360
 
@@ -3428,13 +3537,23 @@ declare const makeUsBetterAuthClient: (baseURL: string) => {
3428
3537
  USER_ALREADY_HAS_PASSWORD: string;
3429
3538
  };
3430
3539
  };
3540
+ type AuthClient = ReturnType<typeof makeUsBetterAuthClient>;
3431
3541
 
3432
3542
  type CheckoutClient = ReturnType<typeof hc<CheckoutRouter>>;
3433
3543
  declare const makeCheckoutClient: (baseURL: string, options?: ClientRequestOptions) => CheckoutClient;
3434
3544
 
3545
+ type MailingListClient = ReturnType<typeof hc<MailingListRouter>>;
3546
+ declare const makeMailingListClient: (baseURL: string, publicKey: string, options?: ClientRequestOptions) => MailingListClient;
3547
+
3435
3548
  declare function makeLoginUrl(apiUrl: string, redirectUrl?: string, appName?: string): string;
3436
3549
  declare function makeCheckoutUrl(apiUrl: string, priceId: string, productId: string, discountCode?: string, loginUrl?: string, pricingUrl?: string, successUrl?: string): string;
3437
3550
  declare function makeRedirectIntent(redirectUrl: string, appName?: string): string;
3438
3551
 
3439
- export { makeAppClient, makeCheckoutClient, makeCheckoutUrl, makeLoginUrl, makePublicClient, makeRedirectIntent, makeUsBetterAuthClient };
3440
- export type { AppClient, CheckoutClient, PublicClient };
3552
+ type SessionData = ReturnType<AuthClient["useSession"]>["data"];
3553
+ declare function hasUserPurchased(sessionData: SessionData, productId: string): boolean;
3554
+ declare function hasUserSubscribed(sessionData: SessionData, productId: string): boolean;
3555
+
3556
+ declare function formatPrice(amountStr: string, currencyCode: string): string | null;
3557
+
3558
+ export { formatPrice, hasUserPurchased, hasUserSubscribed, makeAppClient, makeCheckoutClient, makeCheckoutUrl, makeLoginUrl, makeMailingListClient, makePublicClient, makeRedirectIntent, makeUsBetterAuthClient };
3559
+ export type { AppClient, AuthClient, CheckoutClient, MailingListClient, PublicClient, SessionData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uninspired/auth-client",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Auth client for Uninspired Studio Products",
5
5
  "author": "Chris Kolb <chris@uninspired.studio>",
6
6
  "license": "MIT",