@uninspired/auth-client 1.0.7 → 1.0.8
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/AuthClient.js +1 -1
- package/dist/AuthClient.js.map +1 -1
- package/package.json +1 -1
package/dist/AuthClient.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{emailOTPClient as e,magicLinkClient as t}from"better-auth/client/plugins";import{passkeyClient as n}from"@better-auth/passkey/client";import{createAuthClient as r}from"better-auth/client";import{hc as i}from"hono/client";var a=class{#e;#t;#n;#r;constructor(a,o,s,c){this.#e=o,this.#t=r({baseURL:a,plugins:[t(),e(),n()]
|
|
1
|
+
import{emailOTPClient as e,magicLinkClient as t}from"better-auth/client/plugins";import{passkeyClient as n}from"@better-auth/passkey/client";import{createAuthClient as r}from"better-auth/client";import{hc as i}from"hono/client";var a=class{#e;#t;#n;#r;#i;constructor(a,o,s,c){this.#i=s,this.#e=o,this.#t=r({baseURL:a,plugins:[t(),e(),n()]}),this.#n=i(new URL(`/api/app`,a).toString(),{fetch:(e,t)=>fetch(e,{...t,credentials:`include`})}),this.#r=i(new URL(`/api/mailing-list`,a).toString(),{fetch:(e,t)=>fetch(e,{...t,headers:{"Content-Type":`application/json`,"X-Public-Key":c,...t.headers}})})}getSession=async()=>{let{data:e,error:t}=await this.#t.getSession({},{headers:this.#i?{cookie:this.#i}:void 0});if(t)throw t;return e};signOut=async e=>{let{error:t}=await this.#t.signOut({fetchOptions:{onSuccess:e}},{headers:this.#i?{cookie:this.#i}:void 0});if(t)throw t};getPurchases=async()=>{let e=await this.#n.purchases.$get();if(!e.ok)throw Error(`Failed to get purchases`,{cause:await e.text()});return await e.json()};#a=(e,t)=>JSON.stringify({type:`redirect`,redirectUrl:e,appName:t});newsletterSubscribe=async(e,t,n)=>{let r=await this.#r.subscribe.$post({json:{email:e,userGroup:t??`us-auth`,callbackUrl:n??``}});if(!r.ok)throw Error(await r.text())};newsletterUnsubscribe=async e=>{let t=await this.#r.unsubscribe.$post({query:{email:e}});if(!t.ok)throw Error(await t.text())};getLoginUrl=e=>{let t=new URL(`/login`,this.#e);return e?.redirectUrl&&t.searchParams.set(`intent`,this.#a(e.redirectUrl,e.appName)),t.toString()};getCheckoutUrl=e=>{let t=new URL(`/auth/checkout`,this.#e);return t.searchParams.set(`priceId`,e.priceId),e.discountCode&&t.searchParams.set(`discountCode`,e.discountCode),e.successUrl&&t.searchParams.set(`successUrl`,e.successUrl),t.searchParams.set(`quantity`,e.quantity?.toString()??`1`),t.toString()}};export{a as AuthClient};
|
|
2
2
|
//# sourceMappingURL=AuthClient.js.map
|
package/dist/AuthClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthClient.js","names":["#frontendUrl","#authClient","#appClient","#mailingListClient","#getRedirectIntent"],"sources":["../src/AuthClient.ts"],"sourcesContent":["import { magicLinkClient, emailOTPClient } from \"better-auth/client/plugins\";\nimport { passkeyClient } from \"@better-auth/passkey/client\";\nimport { createAuthClient } from \"better-auth/client\";\nimport { hc } from \"hono/client\";\nimport type { AppRouter, MailingListRouter } from \"@us-auth/api\";\nimport type { UserPurchases, Session, RedirectIntent } from \"@us-auth/types\";\n\nexport class AuthClient {\n #frontendUrl: string;\n #authClient;\n #appClient: ReturnType<typeof hc<AppRouter>>;\n #mailingListClient: ReturnType<typeof hc<MailingListRouter>>;\n\n constructor(\n apiUrl: string,\n frontendUrl: string,\n cookie?: string,\n mailingListPublicKey?: string,\n ) {\n this.#frontendUrl = frontendUrl;\n this.#authClient = createAuthClient({\n baseURL: apiUrl,\n plugins: [magicLinkClient(), emailOTPClient(), passkeyClient()],\n
|
|
1
|
+
{"version":3,"file":"AuthClient.js","names":["#cookie","#frontendUrl","#authClient","#appClient","#mailingListClient","#getRedirectIntent"],"sources":["../src/AuthClient.ts"],"sourcesContent":["import { magicLinkClient, emailOTPClient } from \"better-auth/client/plugins\";\nimport { passkeyClient } from \"@better-auth/passkey/client\";\nimport { createAuthClient } from \"better-auth/client\";\nimport { hc } from \"hono/client\";\nimport type { AppRouter, MailingListRouter } from \"@us-auth/api\";\nimport type { UserPurchases, Session, RedirectIntent } from \"@us-auth/types\";\n\nexport class AuthClient {\n #frontendUrl: string;\n #authClient;\n #appClient: ReturnType<typeof hc<AppRouter>>;\n #mailingListClient: ReturnType<typeof hc<MailingListRouter>>;\n #cookie: string | undefined;\n\n constructor(\n apiUrl: string,\n frontendUrl: string,\n cookie?: string,\n mailingListPublicKey?: string,\n ) {\n this.#cookie = cookie;\n this.#frontendUrl = frontendUrl;\n this.#authClient = createAuthClient({\n baseURL: apiUrl,\n plugins: [magicLinkClient(), emailOTPClient(), passkeyClient()],\n });\n this.#appClient = hc<AppRouter>(new URL(\"/api/app\", apiUrl).toString(), {\n fetch: (url: any, init: any) =>\n fetch(url, {\n ...init,\n credentials: \"include\",\n }),\n });\n this.#mailingListClient = hc<MailingListRouter>(\n new URL(\"/api/mailing-list\", apiUrl).toString(),\n {\n fetch: (url: any, init: any) =>\n fetch(url, {\n ...init,\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-Public-Key\": mailingListPublicKey,\n ...init.headers,\n },\n }),\n },\n );\n }\n\n // Authentication\n getSession = async (): Promise<Session | null> => {\n const { data, error } = await this.#authClient.getSession(\n {},\n {\n headers: this.#cookie\n ? {\n cookie: this.#cookie,\n }\n : undefined,\n },\n );\n if (error) throw error;\n return data;\n };\n\n signOut = async (onSuccess?: () => void): Promise<void> => {\n const { error } = await this.#authClient.signOut(\n {\n fetchOptions: { onSuccess },\n },\n {\n headers: this.#cookie ? { cookie: this.#cookie } : undefined,\n },\n );\n if (error) throw error;\n return;\n };\n\n // Purchases\n getPurchases = async (): Promise<UserPurchases | null> => {\n const res = await this.#appClient.purchases.$get();\n if (!res.ok) {\n throw new Error(\"Failed to get purchases\", {\n cause: await res.text(),\n });\n }\n const data = await res.json();\n return data satisfies UserPurchases;\n };\n\n #getRedirectIntent = (redirectUrl: string, appName?: string) => {\n return JSON.stringify({\n type: \"redirect\",\n redirectUrl,\n appName,\n } satisfies RedirectIntent);\n };\n\n // Mailing List\n newsletterSubscribe = async (\n email: string,\n userGroup?: string,\n callbackUrl?: string,\n ): Promise<void> => {\n const res = await this.#mailingListClient.subscribe.$post({\n json: {\n email,\n userGroup: userGroup ?? \"us-auth\",\n callbackUrl: callbackUrl ?? \"\",\n },\n });\n if (!res.ok) {\n throw new Error(await res.text());\n }\n return;\n };\n\n newsletterUnsubscribe = async (email: string): Promise<void> => {\n const res = await this.#mailingListClient.unsubscribe.$post({\n query: {\n email,\n },\n });\n if (!res.ok) {\n throw new Error(await res.text());\n }\n return;\n };\n\n // Utils\n getLoginUrl = (options?: { redirectUrl?: string; appName?: string }) => {\n const url = new URL(\"/login\", this.#frontendUrl);\n if (options?.redirectUrl) {\n url.searchParams.set(\n \"intent\",\n this.#getRedirectIntent(options.redirectUrl, options.appName),\n );\n }\n return url.toString();\n };\n\n getCheckoutUrl = (options: {\n priceId: string;\n discountCode?: string;\n successUrl?: string;\n quantity?: number;\n }) => {\n const url = new URL(\"/auth/checkout\", this.#frontendUrl);\n url.searchParams.set(\"priceId\", options.priceId);\n if (options.discountCode) {\n url.searchParams.set(\"discountCode\", options.discountCode);\n }\n if (options.successUrl) {\n url.searchParams.set(\"successUrl\", options.successUrl);\n }\n url.searchParams.set(\"quantity\", options.quantity?.toString() ?? \"1\");\n return url.toString();\n };\n}\n"],"mappings":"oOAOA,IAAa,EAAb,KAAwB,CACtB,GACA,GACA,GACA,GACA,GAEA,YACE,EACA,EACA,EACA,EACA,CACA,MAAA,EAAe,EACf,MAAA,EAAoB,EACpB,MAAA,EAAmB,EAAiB,CAClC,QAAS,EACT,QAAS,CAAC,GAAiB,CAAE,GAAgB,CAAE,GAAe,CAAC,CAChE,CAAC,CACF,MAAA,EAAkB,EAAc,IAAI,IAAI,WAAY,EAAO,CAAC,UAAU,CAAE,CACtE,OAAQ,EAAU,IAChB,MAAM,EAA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