@uninspired/auth-client 0.0.16 → 0.0.18
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 +13 -18
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +13 -18
- package/dist/esm/index.js.map +4 -4
- package/dist/types/index.d.ts +54 -7
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -33,12 +33,11 @@ __export(exports_src, {
|
|
|
33
33
|
makeRedirectIntent: () => makeRedirectIntent,
|
|
34
34
|
makePublicClient: () => makePublicClient,
|
|
35
35
|
makeMailingListClient: () => makeMailingListClient,
|
|
36
|
+
makeMailingListAdminClient: () => makeMailingListAdminClient,
|
|
36
37
|
makeLoginUrl: () => makeLoginUrl,
|
|
37
38
|
makeCheckoutUrl: () => makeCheckoutUrl,
|
|
38
39
|
makeCheckoutClient: () => makeCheckoutClient,
|
|
39
40
|
makeAppClient: () => makeAppClient,
|
|
40
|
-
hasUserSubscribed: () => hasUserSubscribed,
|
|
41
|
-
hasUserPurchased: () => hasUserPurchased,
|
|
42
41
|
formatPrice: () => formatPrice
|
|
43
42
|
});
|
|
44
43
|
module.exports = __toCommonJS(exports_src);
|
|
@@ -103,6 +102,17 @@ var makeMailingListClient = (baseURL, publicKey, options) => {
|
|
|
103
102
|
}
|
|
104
103
|
});
|
|
105
104
|
};
|
|
105
|
+
// src/clients/mailingListAdminClient.ts
|
|
106
|
+
var import_client5 = require("hono/client");
|
|
107
|
+
var makeMailingListAdminClient = (baseURL, apiKey, options) => {
|
|
108
|
+
return import_client5.hc(baseURL, {
|
|
109
|
+
...options,
|
|
110
|
+
headers: {
|
|
111
|
+
...options?.headers,
|
|
112
|
+
"X-API-Key": apiKey
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
};
|
|
106
116
|
// src/utils/intent.ts
|
|
107
117
|
function makeLoginUrl(apiUrl, redirectUrl, appName) {
|
|
108
118
|
const url = new URL("/login", apiUrl);
|
|
@@ -147,21 +157,6 @@ function makeRedirectIntent(redirectUrl, appName) {
|
|
|
147
157
|
};
|
|
148
158
|
return JSON.stringify(obj);
|
|
149
159
|
}
|
|
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
160
|
// ../utils/src/intent.ts
|
|
166
161
|
var import_zod = require("zod");
|
|
167
162
|
var checkoutIntentSchema = import_zod.z.object({
|
|
@@ -213,5 +208,5 @@ function formatPrice(amountStr, currencyCode) {
|
|
|
213
208
|
}).format(amount / divisor);
|
|
214
209
|
}
|
|
215
210
|
|
|
216
|
-
//# debugId=
|
|
211
|
+
//# debugId=2013C2F3B5BDF6CD64756E2164756E21
|
|
217
212
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
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/
|
|
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
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
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
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",
|
|
10
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",
|
|
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
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
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
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
15
|
],
|
|
16
|
-
"mappings": "
|
|
17
|
-
"debugId": "
|
|
16
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAC8C,IAA9C;AAIO,IAAM,mBAAmB,CAC9B,SACA,YACiB;AAAA,EACjB,OAAO,iBAAiB,SAAS,OAAO;AAAA;;ACRI,IAA9C;AAIO,IAAM,gBAAgB,CAC3B,SACA,YACc;AAAA,EACd,OAAO,kBAAc,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;;ACfI,IALP;AAMiC,IAAjC;AAGO,IAAM,yBAAyB,CAAC,YAAoB;AAAA,EACzD,OAAO,8BAAiB;AAAA,IACtB;AAAA,IACA,SAAS;AAAA,MACP,mCAA0B;AAAA,MAC1B,+BAAgB;AAAA,MAChB,8BAAe;AAAA,MACf,6BAAc;AAAA,IAChB;AAAA,EACF,CAAC;AAAA;;ACjB2C,IAA9C;AA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,cAAE,OAAO;AAAA,EACpB,cAAc,cAAE,OAAO,EAAE,SAAS;AAAA,EAClC,UAAU,cAAE,IAAI,EAAE,SAAS;AAAA,EAC3B,YAAY,cAAE,IAAI,EAAE,SAAS;AAAA,EAC7B,YAAY,cAAE,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": "2013C2F3B5BDF6CD64756E2164756E21",
|
|
18
18
|
"names": []
|
|
19
19
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -63,6 +63,17 @@ var makeMailingListClient = (baseURL, publicKey, options) => {
|
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
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
|
+
};
|
|
66
77
|
// src/utils/intent.ts
|
|
67
78
|
function makeLoginUrl(apiUrl, redirectUrl, appName) {
|
|
68
79
|
const url = new URL("/login", apiUrl);
|
|
@@ -107,21 +118,6 @@ function makeRedirectIntent(redirectUrl, appName) {
|
|
|
107
118
|
};
|
|
108
119
|
return JSON.stringify(obj);
|
|
109
120
|
}
|
|
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
121
|
// ../utils/src/intent.ts
|
|
126
122
|
import { z } from "zod";
|
|
127
123
|
var checkoutIntentSchema = z.object({
|
|
@@ -177,14 +173,13 @@ export {
|
|
|
177
173
|
makeRedirectIntent,
|
|
178
174
|
makePublicClient,
|
|
179
175
|
makeMailingListClient,
|
|
176
|
+
makeMailingListAdminClient,
|
|
180
177
|
makeLoginUrl,
|
|
181
178
|
makeCheckoutUrl,
|
|
182
179
|
makeCheckoutClient,
|
|
183
180
|
makeAppClient,
|
|
184
|
-
hasUserSubscribed,
|
|
185
|
-
hasUserPurchased,
|
|
186
181
|
formatPrice
|
|
187
182
|
};
|
|
188
183
|
|
|
189
|
-
//# debugId=
|
|
184
|
+
//# debugId=CC5B6A629B049D6B64756E2164756E21
|
|
190
185
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
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/
|
|
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
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
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
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",
|
|
10
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",
|
|
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
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
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
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
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;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,YAA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AEF,IAAM,uBAAuB,GAAE,OAAO;AAAA,EAC3C,SAAS,GAAE,OAAO;AAAA,EAClB,WAAW,GAAE,OAAO;AAAA,EACpB,cAAc,GAAE,OAAO,EAAE,SAAS;AAAA,EAClC,UAAU,GAAE,IAAI,EAAE,SAAS;AAAA,EAC3B,YAAY,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": "CC5B6A629B049D6B64756E2164756E21",
|
|
18
18
|
"names": []
|
|
19
19
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ declare const appRouter: hono_hono_base.HonoBase<{
|
|
|
94
94
|
input: {
|
|
95
95
|
param: {
|
|
96
96
|
subscriptionId: string;
|
|
97
|
-
action: "
|
|
97
|
+
action: "update" | "cancel";
|
|
98
98
|
};
|
|
99
99
|
};
|
|
100
100
|
output: undefined;
|
|
@@ -355,6 +355,54 @@ declare const mailingListRouter: hono_hono_base.HonoBase<hono_types.BlankEnv, {
|
|
|
355
355
|
}, "/">;
|
|
356
356
|
type MailingListRouter = typeof mailingListRouter;
|
|
357
357
|
|
|
358
|
+
declare const mailingListAdminRouter: hono_hono_base.HonoBase<{}, {
|
|
359
|
+
"/exists": {
|
|
360
|
+
$get: {
|
|
361
|
+
input: {
|
|
362
|
+
query: {
|
|
363
|
+
email: string;
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
output: {
|
|
367
|
+
exists: boolean;
|
|
368
|
+
};
|
|
369
|
+
outputFormat: "json";
|
|
370
|
+
status: hono_utils_http_status.ContentfulStatusCode;
|
|
371
|
+
};
|
|
372
|
+
};
|
|
373
|
+
} & {
|
|
374
|
+
"/subscribe": {
|
|
375
|
+
$post: {
|
|
376
|
+
input: {
|
|
377
|
+
json: {
|
|
378
|
+
email: string;
|
|
379
|
+
};
|
|
380
|
+
};
|
|
381
|
+
output: {
|
|
382
|
+
success: true;
|
|
383
|
+
};
|
|
384
|
+
outputFormat: "json";
|
|
385
|
+
status: hono_utils_http_status.ContentfulStatusCode;
|
|
386
|
+
};
|
|
387
|
+
};
|
|
388
|
+
} & {
|
|
389
|
+
"/unsubscribe": {
|
|
390
|
+
$post: {
|
|
391
|
+
input: {
|
|
392
|
+
json: {
|
|
393
|
+
email: string;
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
output: {
|
|
397
|
+
success: true;
|
|
398
|
+
};
|
|
399
|
+
outputFormat: "json";
|
|
400
|
+
status: hono_utils_http_status.ContentfulStatusCode;
|
|
401
|
+
};
|
|
402
|
+
};
|
|
403
|
+
}, "/">;
|
|
404
|
+
type MailingListAdminRouter = typeof mailingListAdminRouter;
|
|
405
|
+
|
|
358
406
|
type PublicClient = ReturnType<typeof hc<PublicRouter>>;
|
|
359
407
|
declare const makePublicClient: (baseURL: string, options?: ClientRequestOptions) => PublicClient;
|
|
360
408
|
|
|
@@ -3545,15 +3593,14 @@ declare const makeCheckoutClient: (baseURL: string, options?: ClientRequestOptio
|
|
|
3545
3593
|
type MailingListClient = ReturnType<typeof hc<MailingListRouter>>;
|
|
3546
3594
|
declare const makeMailingListClient: (baseURL: string, publicKey: string, options?: ClientRequestOptions) => MailingListClient;
|
|
3547
3595
|
|
|
3596
|
+
type MailingListAdminClient = ReturnType<typeof hc<MailingListAdminRouter>>;
|
|
3597
|
+
declare const makeMailingListAdminClient: (baseURL: string, apiKey: string, options?: ClientRequestOptions) => MailingListAdminClient;
|
|
3598
|
+
|
|
3548
3599
|
declare function makeLoginUrl(apiUrl: string, redirectUrl?: string, appName?: string): string;
|
|
3549
3600
|
declare function makeCheckoutUrl(apiUrl: string, priceId: string, productId: string, discountCode?: string, loginUrl?: string, pricingUrl?: string, successUrl?: string): string;
|
|
3550
3601
|
declare function makeRedirectIntent(redirectUrl: string, appName?: string): string;
|
|
3551
3602
|
|
|
3552
|
-
type SessionData = ReturnType<AuthClient["useSession"]>["data"];
|
|
3553
|
-
declare function hasUserPurchased(sessionData: SessionData, productId: string, priceId: string): boolean;
|
|
3554
|
-
declare function hasUserSubscribed(sessionData: SessionData, productId: string, priceId: string): boolean;
|
|
3555
|
-
|
|
3556
3603
|
declare function formatPrice(amountStr: string, currencyCode: string): string | null;
|
|
3557
3604
|
|
|
3558
|
-
export { formatPrice,
|
|
3559
|
-
export type { AppClient, AuthClient, CheckoutClient, MailingListClient, PublicClient
|
|
3605
|
+
export { formatPrice, makeAppClient, makeCheckoutClient, makeCheckoutUrl, makeLoginUrl, makeMailingListAdminClient, makeMailingListClient, makePublicClient, makeRedirectIntent, makeUsBetterAuthClient };
|
|
3606
|
+
export type { AppClient, AuthClient, CheckoutClient, MailingListAdminClient, MailingListClient, PublicClient };
|