@uninspired/auth-client 0.0.14 → 0.0.16

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,217 @@
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");
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
2
28
 
3
- //# debugId=F78CCA901C70F47064756E2164756E21
29
+ // src/index.ts
30
+ var exports_src = {};
31
+ __export(exports_src, {
32
+ makeUsBetterAuthClient: () => makeUsBetterAuthClient,
33
+ makeRedirectIntent: () => makeRedirectIntent,
34
+ makePublicClient: () => makePublicClient,
35
+ makeMailingListClient: () => makeMailingListClient,
36
+ makeLoginUrl: () => makeLoginUrl,
37
+ makeCheckoutUrl: () => makeCheckoutUrl,
38
+ makeCheckoutClient: () => makeCheckoutClient,
39
+ makeAppClient: () => makeAppClient,
40
+ hasUserSubscribed: () => hasUserSubscribed,
41
+ hasUserPurchased: () => hasUserPurchased,
42
+ formatPrice: () => formatPrice
43
+ });
44
+ module.exports = __toCommonJS(exports_src);
45
+
46
+ // src/clients/publicClient.ts
47
+ var import_client = require("hono/client");
48
+ var makePublicClient = (baseURL, options) => {
49
+ return import_client.hc(baseURL, options);
50
+ };
51
+ // src/clients/appClient.ts
52
+ var import_client2 = require("hono/client");
53
+ var makeAppClient = (baseURL, options) => {
54
+ return import_client2.hc(baseURL, {
55
+ ...options,
56
+ fetch: (url, init) => (options?.fetch ?? fetch)(url, {
57
+ ...init,
58
+ credentials: "include",
59
+ headers: {
60
+ ...init.headers,
61
+ "Content-Type": "application/json"
62
+ }
63
+ })
64
+ });
65
+ };
66
+ // src/clients/authClient.ts
67
+ var import_plugins = require("better-auth/client/plugins");
68
+ var import_react = require("better-auth/react");
69
+ var makeUsBetterAuthClient = (baseURL) => {
70
+ return import_react.createAuthClient({
71
+ baseURL,
72
+ plugins: [
73
+ import_plugins.customSessionClient(),
74
+ import_plugins.magicLinkClient(),
75
+ import_plugins.emailOTPClient(),
76
+ import_plugins.passkeyClient()
77
+ ]
78
+ });
79
+ };
80
+ // src/clients/checkoutClient.ts
81
+ var import_client3 = require("hono/client");
82
+ var makeCheckoutClient = (baseURL, options) => {
83
+ return import_client3.hc(baseURL, {
84
+ ...options,
85
+ fetch: (url, init) => (options?.fetch ?? fetch)(url, {
86
+ ...init,
87
+ credentials: "include",
88
+ headers: {
89
+ ...init.headers,
90
+ "Content-Type": "application/json"
91
+ }
92
+ })
93
+ });
94
+ };
95
+ // src/clients/mailingListClient.ts
96
+ var import_client4 = require("hono/client");
97
+ var makeMailingListClient = (baseURL, publicKey, options) => {
98
+ return import_client4.hc(baseURL, {
99
+ ...options,
100
+ headers: {
101
+ ...options?.headers,
102
+ "X-Public-Key": publicKey
103
+ }
104
+ });
105
+ };
106
+ // src/utils/intent.ts
107
+ function makeLoginUrl(apiUrl, redirectUrl, appName) {
108
+ const url = new URL("/login", apiUrl);
109
+ if (redirectUrl) {
110
+ url.searchParams.set("intent", makeRedirectIntent(redirectUrl, appName));
111
+ }
112
+ return url.toString();
113
+ }
114
+ function noop(...args) {}
115
+ function makeCheckoutUrl(apiUrl, priceId, productId, discountCode, loginUrl, pricingUrl, successUrl) {
116
+ const obj = {
117
+ priceId,
118
+ productId,
119
+ discountCode,
120
+ loginUrl,
121
+ pricingUrl,
122
+ successUrl
123
+ };
124
+ noop(obj);
125
+ const url = new URL("/auth/checkout", apiUrl);
126
+ url.searchParams.set("priceId", priceId);
127
+ url.searchParams.set("productId", productId);
128
+ if (discountCode) {
129
+ url.searchParams.set("discountCode", discountCode);
130
+ }
131
+ if (loginUrl) {
132
+ url.searchParams.set("loginUrl", loginUrl);
133
+ }
134
+ if (pricingUrl) {
135
+ url.searchParams.set("pricingUrl", pricingUrl);
136
+ }
137
+ if (successUrl) {
138
+ url.searchParams.set("successUrl", successUrl);
139
+ }
140
+ return url.toString();
141
+ }
142
+ function makeRedirectIntent(redirectUrl, appName) {
143
+ const obj = {
144
+ type: "redirect",
145
+ redirectUrl,
146
+ appName
147
+ };
148
+ return JSON.stringify(obj);
149
+ }
150
+ // src/utils/purchase.ts
151
+ function hasUserPurchased(sessionData, productId, priceId) {
152
+ if (!sessionData)
153
+ return false;
154
+ return sessionData.products.transactions.some((transaction) => {
155
+ transaction.productId === productId && transaction.priceId === priceId && transaction.status;
156
+ });
157
+ }
158
+ function hasUserSubscribed(sessionData, productId, priceId) {
159
+ if (!sessionData)
160
+ return false;
161
+ return sessionData.products.subscriptions.some((subscription) => {
162
+ subscription.productId === productId && subscription.priceId === priceId && subscription.status;
163
+ });
164
+ }
165
+ // ../utils/src/intent.ts
166
+ var import_zod = require("zod");
167
+ var checkoutIntentSchema = import_zod.z.object({
168
+ type: import_zod.z.literal("checkout"),
169
+ priceId: import_zod.z.string(),
170
+ productId: import_zod.z.string(),
171
+ discountCode: import_zod.z.string().optional(),
172
+ loginUrl: import_zod.z.url().optional(),
173
+ pricingUrl: import_zod.z.url().optional(),
174
+ successUrl: import_zod.z.url().optional()
175
+ });
176
+ var redirectIntentSchema = import_zod.z.object({
177
+ type: import_zod.z.literal("redirect"),
178
+ redirectUrl: import_zod.z.url(),
179
+ appName: import_zod.z.string().optional()
180
+ });
181
+ var intentSchema = import_zod.z.discriminatedUnion("type", [
182
+ checkoutIntentSchema,
183
+ redirectIntentSchema
184
+ ]);
185
+ var intentSearchSchema = import_zod.z.object({
186
+ intent: intentSchema.optional()
187
+ });
188
+ // ../utils/src/checkout.ts
189
+ var import_zod2 = require("zod");
190
+ var checkoutSearchSchema = import_zod2.z.object({
191
+ priceId: import_zod2.z.string(),
192
+ productId: import_zod2.z.string(),
193
+ discountCode: import_zod2.z.string().optional(),
194
+ loginUrl: import_zod2.z.url().optional(),
195
+ pricingUrl: import_zod2.z.url().optional(),
196
+ successUrl: import_zod2.z.url().optional()
197
+ });
198
+ // ../utils/src/price.ts
199
+ function formatPrice(amountStr, currencyCode) {
200
+ const amount = parseInt(amountStr);
201
+ if (!amount || !currencyCode)
202
+ return null;
203
+ const formatter = new Intl.NumberFormat("en-US", {
204
+ style: "currency",
205
+ currency: currencyCode
206
+ });
207
+ const parts = formatter.formatToParts(amount);
208
+ const fractionDigits = parts.find((part) => part.type === "fraction")?.value.length || 0;
209
+ const divisor = Math.pow(10, fractionDigits);
210
+ return new Intl.NumberFormat("en-US", {
211
+ style: "currency",
212
+ currency: currencyCode
213
+ }).format(amount / divisor);
214
+ }
215
+
216
+ //# debugId=96C55C5A8C2E4F1464756E2164756E21
4
217
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
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/clients/mailingListClient.ts", "../../src/utils/intent.ts", "../../src/utils/purchase.ts", "../../src/utils/index.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", "../../../utils/src/intent.ts", "../../../utils/src/checkout.ts", "../../../utils/src/price.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",
@@ -8,10 +8,12 @@
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
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
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"
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 priceId: string,\n): boolean {\n if (!sessionData) return false;\n return sessionData.products.transactions.some((transaction) => {\n transaction.productId === productId &&\n transaction.priceId === priceId &&\n transaction.status === \"completed\";\n });\n}\n\nexport function hasUserSubscribed(\n sessionData: SessionData,\n productId: string,\n priceId: string,\n): boolean {\n if (!sessionData) return false;\n return sessionData.products.subscriptions.some((subscription) => {\n subscription.productId === productId &&\n subscription.priceId === priceId &&\n subscription.status === \"active\";\n });\n}\n",
12
+ "import { z } from \"zod\";\n\nexport const checkoutIntentSchema = z.object({\n type: z.literal(\"checkout\"),\n priceId: z.string(),\n productId: z.string(),\n discountCode: z.string().optional(),\n loginUrl: z.url().optional(),\n pricingUrl: z.url().optional(),\n successUrl: z.url().optional(),\n});\nexport type CheckoutIntent = z.infer<typeof checkoutIntentSchema>;\n\nexport const redirectIntentSchema = z.object({\n type: z.literal(\"redirect\"),\n redirectUrl: z.url(),\n appName: z.string().optional(),\n});\nexport type RedirectIntent = z.infer<typeof redirectIntentSchema>;\n\nexport const intentSchema = z.discriminatedUnion(\"type\", [\n checkoutIntentSchema,\n redirectIntentSchema,\n]);\nexport type Intent = z.infer<typeof intentSchema>;\n\nexport const intentSearchSchema = z.object({\n intent: intentSchema.optional(),\n});\n",
13
+ "import { z } from \"zod\";\n\nexport const checkoutSearchSchema = z.object({\n priceId: z.string(),\n productId: z.string(),\n discountCode: z.string().optional(),\n loginUrl: z.url().optional(),\n pricingUrl: z.url().optional(),\n successUrl: z.url().optional(),\n});\n\nexport type CheckoutSearch = z.infer<typeof checkoutSearchSchema>;\n",
14
+ "export function formatPrice(amountStr: string, currencyCode: string) {\n const amount = parseInt(amountStr);\n\n if (!amount || !currencyCode) return null;\n const formatter = new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: currencyCode,\n });\n\n const parts = formatter.formatToParts(amount);\n const fractionDigits =\n parts.find((part) => part.type === \"fraction\")?.value.length || 0;\n\n // Calculate the divisor based on decimal places\n const divisor = Math.pow(10, fractionDigits);\n\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: currencyCode,\n }).format(amount / divisor);\n}\n"
13
15
  ],
14
- "mappings": "yvBAC8C,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,YAAa,UACb,QAAS,IACJ,EAAK,QACR,eAAgB,kBAClB,CACF,CAAC,CACL,CAAC,GCfI,IALP,wCAMA,+BAGa,EAAyB,CAAC,IAAoB,CACzD,OAAO,mBAAiB,CACtB,UACA,QAAS,CACP,sBAA0B,EAC1B,kBAAgB,EAChB,iBAAe,EACf,gBAAc,CAChB,CACF,CAAC,GCjB2C,IAA9C,yBAIa,EAAqB,CAChC,EACA,IACmB,CACnB,OAAO,KAAmB,EAAS,IAC9B,EACH,MAAO,CAAC,EAAU,KACf,GAAS,OAAS,OAAO,EAAK,IAC1B,EACH,YAAa,UACb,QAAS,IACJ,EAAK,QACR,eAAgB,kBAClB,CACF,CAAC,CACL,CAAC,GCnB2C,IAA9C,yBAIa,EAAwB,CACnC,EACA,EACA,IACsB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M,YAAY,IAAI,KAAK,aAAa,SAAS;AAAA,IAC/C,OAAO;AAAA,IACP,UAAU;AAAA,EACZ,CAAC;AAAA,EAED,MAAM,QAAQ,UAAU,cAAc,MAAM;AAAA,EAC5C,MAAM,iBACJ,MAAM,KAAK,CAAC,SAAS,KAAK,SAAS,UAAU,GAAG,MAAM,UAAU;AAAA,EAGlE,MAAM,UAAU,KAAK,IAAI,IAAI,cAAc;AAAA,EAE3C,OAAO,IAAI,KAAK,aAAa,SAAS;AAAA,IACpC,OAAO;AAAA,IACP,UAAU;AAAA,EACZ,CAAC,EAAE,OAAO,SAAS,OAAO;AAAA;",
17
+ "debugId": "96C55C5A8C2E4F1464756E2164756E21",
16
18
  "names": []
17
19
  }
package/dist/esm/index.js CHANGED
@@ -1,4 +1,190 @@
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};
1
+ // src/clients/publicClient.ts
2
+ import { hc } from "hono/client";
3
+ var makePublicClient = (baseURL, options) => {
4
+ return hc(baseURL, options);
5
+ };
6
+ // src/clients/appClient.ts
7
+ import { hc as hc2 } from "hono/client";
8
+ var makeAppClient = (baseURL, options) => {
9
+ return hc2(baseURL, {
10
+ ...options,
11
+ fetch: (url, init) => (options?.fetch ?? fetch)(url, {
12
+ ...init,
13
+ credentials: "include",
14
+ headers: {
15
+ ...init.headers,
16
+ "Content-Type": "application/json"
17
+ }
18
+ })
19
+ });
20
+ };
21
+ // src/clients/authClient.ts
22
+ import {
23
+ customSessionClient,
24
+ magicLinkClient,
25
+ emailOTPClient,
26
+ passkeyClient
27
+ } from "better-auth/client/plugins";
28
+ import { createAuthClient } from "better-auth/react";
29
+ var makeUsBetterAuthClient = (baseURL) => {
30
+ return createAuthClient({
31
+ baseURL,
32
+ plugins: [
33
+ customSessionClient(),
34
+ magicLinkClient(),
35
+ emailOTPClient(),
36
+ passkeyClient()
37
+ ]
38
+ });
39
+ };
40
+ // src/clients/checkoutClient.ts
41
+ import { hc as hc3 } from "hono/client";
42
+ var makeCheckoutClient = (baseURL, options) => {
43
+ return hc3(baseURL, {
44
+ ...options,
45
+ fetch: (url, init) => (options?.fetch ?? fetch)(url, {
46
+ ...init,
47
+ credentials: "include",
48
+ headers: {
49
+ ...init.headers,
50
+ "Content-Type": "application/json"
51
+ }
52
+ })
53
+ });
54
+ };
55
+ // src/clients/mailingListClient.ts
56
+ import { hc as hc4 } from "hono/client";
57
+ var makeMailingListClient = (baseURL, publicKey, options) => {
58
+ return hc4(baseURL, {
59
+ ...options,
60
+ headers: {
61
+ ...options?.headers,
62
+ "X-Public-Key": publicKey
63
+ }
64
+ });
65
+ };
66
+ // src/utils/intent.ts
67
+ function makeLoginUrl(apiUrl, redirectUrl, appName) {
68
+ const url = new URL("/login", apiUrl);
69
+ if (redirectUrl) {
70
+ url.searchParams.set("intent", makeRedirectIntent(redirectUrl, appName));
71
+ }
72
+ return url.toString();
73
+ }
74
+ function noop(...args) {}
75
+ function makeCheckoutUrl(apiUrl, priceId, productId, discountCode, loginUrl, pricingUrl, successUrl) {
76
+ const obj = {
77
+ priceId,
78
+ productId,
79
+ discountCode,
80
+ loginUrl,
81
+ pricingUrl,
82
+ successUrl
83
+ };
84
+ noop(obj);
85
+ const url = new URL("/auth/checkout", apiUrl);
86
+ url.searchParams.set("priceId", priceId);
87
+ url.searchParams.set("productId", productId);
88
+ if (discountCode) {
89
+ url.searchParams.set("discountCode", discountCode);
90
+ }
91
+ if (loginUrl) {
92
+ url.searchParams.set("loginUrl", loginUrl);
93
+ }
94
+ if (pricingUrl) {
95
+ url.searchParams.set("pricingUrl", pricingUrl);
96
+ }
97
+ if (successUrl) {
98
+ url.searchParams.set("successUrl", successUrl);
99
+ }
100
+ return url.toString();
101
+ }
102
+ function makeRedirectIntent(redirectUrl, appName) {
103
+ const obj = {
104
+ type: "redirect",
105
+ redirectUrl,
106
+ appName
107
+ };
108
+ return JSON.stringify(obj);
109
+ }
110
+ // src/utils/purchase.ts
111
+ function hasUserPurchased(sessionData, productId, priceId) {
112
+ if (!sessionData)
113
+ return false;
114
+ return sessionData.products.transactions.some((transaction) => {
115
+ transaction.productId === productId && transaction.priceId === priceId && transaction.status;
116
+ });
117
+ }
118
+ function hasUserSubscribed(sessionData, productId, priceId) {
119
+ if (!sessionData)
120
+ return false;
121
+ return sessionData.products.subscriptions.some((subscription) => {
122
+ subscription.productId === productId && subscription.priceId === priceId && subscription.status;
123
+ });
124
+ }
125
+ // ../utils/src/intent.ts
126
+ import { z } from "zod";
127
+ var checkoutIntentSchema = z.object({
128
+ type: z.literal("checkout"),
129
+ priceId: z.string(),
130
+ productId: z.string(),
131
+ discountCode: z.string().optional(),
132
+ loginUrl: z.url().optional(),
133
+ pricingUrl: z.url().optional(),
134
+ successUrl: z.url().optional()
135
+ });
136
+ var redirectIntentSchema = z.object({
137
+ type: z.literal("redirect"),
138
+ redirectUrl: z.url(),
139
+ appName: z.string().optional()
140
+ });
141
+ var intentSchema = z.discriminatedUnion("type", [
142
+ checkoutIntentSchema,
143
+ redirectIntentSchema
144
+ ]);
145
+ var intentSearchSchema = z.object({
146
+ intent: intentSchema.optional()
147
+ });
148
+ // ../utils/src/checkout.ts
149
+ import { z as z2 } from "zod";
150
+ var checkoutSearchSchema = z2.object({
151
+ priceId: z2.string(),
152
+ productId: z2.string(),
153
+ discountCode: z2.string().optional(),
154
+ loginUrl: z2.url().optional(),
155
+ pricingUrl: z2.url().optional(),
156
+ successUrl: z2.url().optional()
157
+ });
158
+ // ../utils/src/price.ts
159
+ function formatPrice(amountStr, currencyCode) {
160
+ const amount = parseInt(amountStr);
161
+ if (!amount || !currencyCode)
162
+ return null;
163
+ const formatter = new Intl.NumberFormat("en-US", {
164
+ style: "currency",
165
+ currency: currencyCode
166
+ });
167
+ const parts = formatter.formatToParts(amount);
168
+ const fractionDigits = parts.find((part) => part.type === "fraction")?.value.length || 0;
169
+ const divisor = Math.pow(10, fractionDigits);
170
+ return new Intl.NumberFormat("en-US", {
171
+ style: "currency",
172
+ currency: currencyCode
173
+ }).format(amount / divisor);
174
+ }
175
+ export {
176
+ makeUsBetterAuthClient,
177
+ makeRedirectIntent,
178
+ makePublicClient,
179
+ makeMailingListClient,
180
+ makeLoginUrl,
181
+ makeCheckoutUrl,
182
+ makeCheckoutClient,
183
+ makeAppClient,
184
+ hasUserSubscribed,
185
+ hasUserPurchased,
186
+ formatPrice
187
+ };
2
188
 
3
- //# debugId=10219B7A43FFF4DC64756E2164756E21
189
+ //# debugId=DF6D39D97805B0D264756E2164756E21
4
190
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
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/clients/mailingListClient.ts", "../../src/utils/intent.ts", "../../src/utils/purchase.ts", "../../src/utils/index.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", "../../../utils/src/intent.ts", "../../../utils/src/checkout.ts", "../../../utils/src/price.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",
@@ -8,10 +8,12 @@
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
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
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"
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 priceId: string,\n): boolean {\n if (!sessionData) return false;\n return sessionData.products.transactions.some((transaction) => {\n transaction.productId === productId &&\n transaction.priceId === priceId &&\n transaction.status === \"completed\";\n });\n}\n\nexport function hasUserSubscribed(\n sessionData: SessionData,\n productId: string,\n priceId: string,\n): boolean {\n if (!sessionData) return false;\n return sessionData.products.subscriptions.some((subscription) => {\n subscription.productId === productId &&\n subscription.priceId === priceId &&\n subscription.status === \"active\";\n });\n}\n",
12
+ "import { z } from \"zod\";\n\nexport const checkoutIntentSchema = z.object({\n type: z.literal(\"checkout\"),\n priceId: z.string(),\n productId: z.string(),\n discountCode: z.string().optional(),\n loginUrl: z.url().optional(),\n pricingUrl: z.url().optional(),\n successUrl: z.url().optional(),\n});\nexport type CheckoutIntent = z.infer<typeof checkoutIntentSchema>;\n\nexport const redirectIntentSchema = z.object({\n type: z.literal(\"redirect\"),\n redirectUrl: z.url(),\n appName: z.string().optional(),\n});\nexport type RedirectIntent = z.infer<typeof redirectIntentSchema>;\n\nexport const intentSchema = z.discriminatedUnion(\"type\", [\n checkoutIntentSchema,\n redirectIntentSchema,\n]);\nexport type Intent = z.infer<typeof intentSchema>;\n\nexport const intentSearchSchema = z.object({\n intent: intentSchema.optional(),\n});\n",
13
+ "import { z } from \"zod\";\n\nexport const checkoutSearchSchema = z.object({\n priceId: z.string(),\n productId: z.string(),\n discountCode: z.string().optional(),\n loginUrl: z.url().optional(),\n pricingUrl: z.url().optional(),\n successUrl: z.url().optional(),\n});\n\nexport type CheckoutSearch = z.infer<typeof checkoutSearchSchema>;\n",
14
+ "export function formatPrice(amountStr: string, currencyCode: string) {\n const amount = parseInt(amountStr);\n\n if (!amount || !currencyCode) return null;\n const formatter = new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: currencyCode,\n });\n\n const parts = formatter.formatToParts(amount);\n const fractionDigits =\n parts.find((part) => part.type === \"fraction\")?.value.length || 0;\n\n // Calculate the divisor based on decimal places\n const divisor = Math.pow(10, fractionDigits);\n\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: currencyCode,\n }).format(amount / divisor);\n}\n"
13
15
  ],
14
- "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,CACtB,UACA,QAAS,CACP,EAA0B,EAC1B,EAAgB,EAChB,EAAe,EACf,E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GAAE,IAAI,EAAE,SAAS;AAAA,EAC7B,YAAY,GAAE,IAAI,EAAE,SAAS;AAC/B,CAAC;;ACTM,SAAS,WAAW,CAAC,WAAmB,cAAsB;AAAA,EACnE,MAAM,SAAS,SAAS,SAAS;AAAA,EAEjC,IAAI,CAAC,UAAU,CAAC;AAAA,IAAc,OAAO;AAAA,EACrC,MAAM,YAAY,IAAI,KAAK,aAAa,SAAS;AAAA,IAC/C,OAAO;AAAA,IACP,UAAU;AAAA,EACZ,CAAC;AAAA,EAED,MAAM,QAAQ,UAAU,cAAc,MAAM;AAAA,EAC5C,MAAM,iBACJ,MAAM,KAAK,CAAC,SAAS,KAAK,SAAS,UAAU,GAAG,MAAM,UAAU;AAAA,EAGlE,MAAM,UAAU,KAAK,IAAI,IAAI,cAAc;AAAA,EAE3C,OAAO,IAAI,KAAK,aAAa,SAAS;AAAA,IACpC,OAAO;AAAA,IACP,UAAU;AAAA,EACZ,CAAC,EAAE,OAAO,SAAS,OAAO;AAAA;",
17
+ "debugId": "DF6D39D97805B0D264756E2164756E21",
16
18
  "names": []
17
19
  }
@@ -94,7 +94,7 @@ declare const appRouter: hono_hono_base.HonoBase<{
94
94
  input: {
95
95
  param: {
96
96
  subscriptionId: string;
97
- action: "update" | "cancel";
97
+ action: "cancel" | "update";
98
98
  };
99
99
  };
100
100
  output: undefined;
@@ -268,9 +268,9 @@ declare const mailingListRouter: hono_hono_base.HonoBase<hono_types.BlankEnv, {
268
268
  callbackUrl: string;
269
269
  };
270
270
  };
271
- output: "Success";
271
+ output: "Could not send email";
272
272
  outputFormat: "text";
273
- status: 200;
273
+ status: 500;
274
274
  } | {
275
275
  input: {
276
276
  json: {
@@ -279,9 +279,9 @@ declare const mailingListRouter: hono_hono_base.HonoBase<hono_types.BlankEnv, {
279
279
  callbackUrl: string;
280
280
  };
281
281
  };
282
- output: "Could not send email";
282
+ output: "Contact already subscribed";
283
283
  outputFormat: "text";
284
- status: 500;
284
+ status: 400;
285
285
  } | {
286
286
  input: {
287
287
  json: {
@@ -290,9 +290,9 @@ declare const mailingListRouter: hono_hono_base.HonoBase<hono_types.BlankEnv, {
290
290
  callbackUrl: string;
291
291
  };
292
292
  };
293
- output: "Contact already subscribed";
293
+ output: "Success";
294
294
  outputFormat: "text";
295
- status: 400;
295
+ status: 200;
296
296
  };
297
297
  };
298
298
  } & {
@@ -304,9 +304,9 @@ declare const mailingListRouter: hono_hono_base.HonoBase<hono_types.BlankEnv, {
304
304
  email: string;
305
305
  };
306
306
  };
307
- output: undefined;
308
- outputFormat: "redirect";
309
- status: 302;
307
+ output: "Invalid opt-in token";
308
+ outputFormat: "text";
309
+ status: 400;
310
310
  } | {
311
311
  input: {
312
312
  query: {
@@ -314,7 +314,7 @@ declare const mailingListRouter: hono_hono_base.HonoBase<hono_types.BlankEnv, {
314
314
  email: string;
315
315
  };
316
316
  };
317
- output: "Invalid opt-in token";
317
+ output: "Contact does not exist";
318
318
  outputFormat: "text";
319
319
  status: 400;
320
320
  } | {
@@ -324,9 +324,9 @@ declare const mailingListRouter: hono_hono_base.HonoBase<hono_types.BlankEnv, {
324
324
  email: string;
325
325
  };
326
326
  };
327
- output: "Contact does not exist";
327
+ output: "Could not opt in contact";
328
328
  outputFormat: "text";
329
- status: 400;
329
+ status: 500;
330
330
  } | {
331
331
  input: {
332
332
  query: {
@@ -334,9 +334,9 @@ declare const mailingListRouter: hono_hono_base.HonoBase<hono_types.BlankEnv, {
334
334
  email: string;
335
335
  };
336
336
  };
337
- output: "Could not opt in contact";
338
- outputFormat: "text";
339
- status: 500;
337
+ output: undefined;
338
+ outputFormat: "redirect";
339
+ status: 302;
340
340
  };
341
341
  };
342
342
  } & {
@@ -3550,8 +3550,8 @@ declare function makeCheckoutUrl(apiUrl: string, priceId: string, productId: str
3550
3550
  declare function makeRedirectIntent(redirectUrl: string, appName?: string): string;
3551
3551
 
3552
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;
3553
+ declare function hasUserPurchased(sessionData: SessionData, productId: string, priceId: string): boolean;
3554
+ declare function hasUserSubscribed(sessionData: SessionData, productId: string, priceId: string): boolean;
3555
3555
 
3556
3556
  declare function formatPrice(amountStr: string, currencyCode: string): string | null;
3557
3557
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uninspired/auth-client",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Auth client for Uninspired Studio Products",
5
5
  "author": "Chris Kolb <chris@uninspired.studio>",
6
6
  "license": "MIT",
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/bun": "latest",
20
+ "@types/semver": "^7.7.1",
20
21
  "@us-accounts/api": "workspace:*",
21
22
  "@us-accounts/utils": "workspace:*",
22
23
  "rollup": "^4.52.5",
@@ -30,6 +31,7 @@
30
31
  },
31
32
  "dependencies": {
32
33
  "better-auth": "^1.3.12",
33
- "hono": "^4.9.8"
34
+ "hono": "^4.9.8",
35
+ "zod": "^4"
34
36
  }
35
37
  }