@uninspired/auth-client 0.0.17 → 1.0.0

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/esm/index.js DELETED
@@ -1,173 +0,0 @@
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
- // ../utils/src/intent.ts
111
- import { z } from "zod";
112
- var checkoutIntentSchema = z.object({
113
- type: z.literal("checkout"),
114
- priceId: z.string(),
115
- productId: z.string(),
116
- discountCode: z.string().optional(),
117
- loginUrl: z.url().optional(),
118
- pricingUrl: z.url().optional(),
119
- successUrl: z.url().optional()
120
- });
121
- var redirectIntentSchema = z.object({
122
- type: z.literal("redirect"),
123
- redirectUrl: z.url(),
124
- appName: z.string().optional()
125
- });
126
- var intentSchema = z.discriminatedUnion("type", [
127
- checkoutIntentSchema,
128
- redirectIntentSchema
129
- ]);
130
- var intentSearchSchema = z.object({
131
- intent: intentSchema.optional()
132
- });
133
- // ../utils/src/checkout.ts
134
- import { z as z2 } from "zod";
135
- var checkoutSearchSchema = z2.object({
136
- priceId: z2.string(),
137
- productId: z2.string(),
138
- discountCode: z2.string().optional(),
139
- loginUrl: z2.url().optional(),
140
- pricingUrl: z2.url().optional(),
141
- successUrl: z2.url().optional()
142
- });
143
- // ../utils/src/price.ts
144
- function formatPrice(amountStr, currencyCode) {
145
- const amount = parseInt(amountStr);
146
- if (!amount || !currencyCode)
147
- return null;
148
- const formatter = new Intl.NumberFormat("en-US", {
149
- style: "currency",
150
- currency: currencyCode
151
- });
152
- const parts = formatter.formatToParts(amount);
153
- const fractionDigits = parts.find((part) => part.type === "fraction")?.value.length || 0;
154
- const divisor = Math.pow(10, fractionDigits);
155
- return new Intl.NumberFormat("en-US", {
156
- style: "currency",
157
- currency: currencyCode
158
- }).format(amount / divisor);
159
- }
160
- export {
161
- makeUsBetterAuthClient,
162
- makeRedirectIntent,
163
- makePublicClient,
164
- makeMailingListClient,
165
- makeLoginUrl,
166
- makeCheckoutUrl,
167
- makeCheckoutClient,
168
- makeAppClient,
169
- formatPrice
170
- };
171
-
172
- //# debugId=3D4AFF1091BAEAF564756E2164756E21
173
- //# sourceMappingURL=index.js.map
@@ -1,18 +0,0 @@
1
- {
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", "../../../utils/src/intent.ts", "../../../utils/src/checkout.ts", "../../../utils/src/price.ts"],
4
- "sourcesContent": [
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
- "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\nexport type AuthClient = ReturnType<typeof makeUsBetterAuthClient>;\n",
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 { 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 { 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",
12
- "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",
13
- "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"
14
- ],
15
- "mappings": ";AACA;AAIO,IAAM,mBAAmB,CAC9B,SACA,YACiB;AAAA,EACjB,OAAO,GAAiB,SAAS,OAAO;AAAA;;ACR1C,eAAS;AAIF,IAAM,gBAAgB,CAC3B,SACA,YACc;AAAA,EACd,OAAO,IAAc,SAAS;AAAA,OACzB;AAAA,IACH,OAAO,CAAC,KAAU,UACf,SAAS,SAAS,OAAO,KAAK;AAAA,SAC1B;AAAA,MACH,aAAa;AAAA,MACb,SAAS;AAAA,WACJ,KAAK;AAAA,QACR,gBAAgB;AAAA,MAClB;AAAA,IACF,CAAC;AAAA,EACL,CAAC;AAAA;;ACpBH;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA;AAGO,IAAM,yBAAyB,CAAC,YAAoB;AAAA,EACzD,OAAO,iBAAiB;AAAA,IACtB;AAAA,IACA,SAAS;AAAA,MACP,oBAA0B;AAAA,MAC1B,gBAAgB;AAAA,MAChB,eAAe;AAAA,MACf,cAAc;AAAA,IAChB;AAAA,EACF,CAAC;AAAA;;ACjBH,eAAS;AAIF,IAAM,qBAAqB,CAChC,SACA,YACmB;AAAA,EACnB,OAAO,IAAmB,SAAS;AAAA,OAC9B;AAAA,IACH,OAAO,CAAC,KAAU,UACf,SAAS,SAAS,OAAO,KAAK;AAA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