@uninspired/auth-client 0.0.18 → 1.0.1

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,185 +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/clients/mailingListAdminClient.ts
67
- import { hc as hc5 } from "hono/client";
68
- var makeMailingListAdminClient = (baseURL, apiKey, options) => {
69
- return hc5(baseURL, {
70
- ...options,
71
- headers: {
72
- ...options?.headers,
73
- "X-API-Key": apiKey
74
- }
75
- });
76
- };
77
- // src/utils/intent.ts
78
- function makeLoginUrl(apiUrl, redirectUrl, appName) {
79
- const url = new URL("/login", apiUrl);
80
- if (redirectUrl) {
81
- url.searchParams.set("intent", makeRedirectIntent(redirectUrl, appName));
82
- }
83
- return url.toString();
84
- }
85
- function noop(...args) {}
86
- function makeCheckoutUrl(apiUrl, priceId, productId, discountCode, loginUrl, pricingUrl, successUrl) {
87
- const obj = {
88
- priceId,
89
- productId,
90
- discountCode,
91
- loginUrl,
92
- pricingUrl,
93
- successUrl
94
- };
95
- noop(obj);
96
- const url = new URL("/auth/checkout", apiUrl);
97
- url.searchParams.set("priceId", priceId);
98
- url.searchParams.set("productId", productId);
99
- if (discountCode) {
100
- url.searchParams.set("discountCode", discountCode);
101
- }
102
- if (loginUrl) {
103
- url.searchParams.set("loginUrl", loginUrl);
104
- }
105
- if (pricingUrl) {
106
- url.searchParams.set("pricingUrl", pricingUrl);
107
- }
108
- if (successUrl) {
109
- url.searchParams.set("successUrl", successUrl);
110
- }
111
- return url.toString();
112
- }
113
- function makeRedirectIntent(redirectUrl, appName) {
114
- const obj = {
115
- type: "redirect",
116
- redirectUrl,
117
- appName
118
- };
119
- return JSON.stringify(obj);
120
- }
121
- // ../utils/src/intent.ts
122
- import { z } from "zod";
123
- var checkoutIntentSchema = z.object({
124
- type: z.literal("checkout"),
125
- priceId: z.string(),
126
- productId: z.string(),
127
- discountCode: z.string().optional(),
128
- loginUrl: z.url().optional(),
129
- pricingUrl: z.url().optional(),
130
- successUrl: z.url().optional()
131
- });
132
- var redirectIntentSchema = z.object({
133
- type: z.literal("redirect"),
134
- redirectUrl: z.url(),
135
- appName: z.string().optional()
136
- });
137
- var intentSchema = z.discriminatedUnion("type", [
138
- checkoutIntentSchema,
139
- redirectIntentSchema
140
- ]);
141
- var intentSearchSchema = z.object({
142
- intent: intentSchema.optional()
143
- });
144
- // ../utils/src/checkout.ts
145
- import { z as z2 } from "zod";
146
- var checkoutSearchSchema = z2.object({
147
- priceId: z2.string(),
148
- productId: z2.string(),
149
- discountCode: z2.string().optional(),
150
- loginUrl: z2.url().optional(),
151
- pricingUrl: z2.url().optional(),
152
- successUrl: z2.url().optional()
153
- });
154
- // ../utils/src/price.ts
155
- function formatPrice(amountStr, currencyCode) {
156
- const amount = parseInt(amountStr);
157
- if (!amount || !currencyCode)
158
- return null;
159
- const formatter = new Intl.NumberFormat("en-US", {
160
- style: "currency",
161
- currency: currencyCode
162
- });
163
- const parts = formatter.formatToParts(amount);
164
- const fractionDigits = parts.find((part) => part.type === "fraction")?.value.length || 0;
165
- const divisor = Math.pow(10, fractionDigits);
166
- return new Intl.NumberFormat("en-US", {
167
- style: "currency",
168
- currency: currencyCode
169
- }).format(amount / divisor);
170
- }
171
- export {
172
- makeUsBetterAuthClient,
173
- makeRedirectIntent,
174
- makePublicClient,
175
- makeMailingListClient,
176
- makeMailingListAdminClient,
177
- makeLoginUrl,
178
- makeCheckoutUrl,
179
- makeCheckoutClient,
180
- makeAppClient,
181
- formatPrice
182
- };
183
-
184
- //# debugId=CC5B6A629B049D6B64756E2164756E21
185
- //# sourceMappingURL=index.js.map
@@ -1,19 +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/clients/mailingListAdminClient.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 { MailingListAdminRouter } from \"@us-accounts/api\";\nimport { hc, type ClientRequestOptions } from \"hono/client\";\n\nexport type MailingListAdminClient = ReturnType<\n typeof hc<MailingListAdminRouter>\n>;\n\nexport const makeMailingListAdminClient = (\n baseURL: string,\n apiKey: string,\n options?: ClientRequestOptions,\n): MailingListAdminClient => {\n return hc<MailingListAdminRouter>(baseURL, {\n ...options,\n headers: {\n ...options?.headers,\n \"X-API-Key\": apiKey,\n },\n });\n};\n",
11
- "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",
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"
15
- ],
16
- "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;AAA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