@uninspired/auth-client 0.0.16 → 0.0.17
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 +1 -18
- package/dist/cjs/index.js.map +3 -4
- package/dist/esm/index.js +1 -18
- package/dist/esm/index.js.map +3 -4
- package/dist/types/index.d.ts +17 -21
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -37,8 +37,6 @@ __export(exports_src, {
|
|
|
37
37
|
makeCheckoutUrl: () => makeCheckoutUrl,
|
|
38
38
|
makeCheckoutClient: () => makeCheckoutClient,
|
|
39
39
|
makeAppClient: () => makeAppClient,
|
|
40
|
-
hasUserSubscribed: () => hasUserSubscribed,
|
|
41
|
-
hasUserPurchased: () => hasUserPurchased,
|
|
42
40
|
formatPrice: () => formatPrice
|
|
43
41
|
});
|
|
44
42
|
module.exports = __toCommonJS(exports_src);
|
|
@@ -147,21 +145,6 @@ function makeRedirectIntent(redirectUrl, appName) {
|
|
|
147
145
|
};
|
|
148
146
|
return JSON.stringify(obj);
|
|
149
147
|
}
|
|
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
148
|
// ../utils/src/intent.ts
|
|
166
149
|
var import_zod = require("zod");
|
|
167
150
|
var checkoutIntentSchema = import_zod.z.object({
|
|
@@ -213,5 +196,5 @@ function formatPrice(amountStr, currencyCode) {
|
|
|
213
196
|
}).format(amount / divisor);
|
|
214
197
|
}
|
|
215
198
|
|
|
216
|
-
//# debugId=
|
|
199
|
+
//# debugId=C9F4CF2385BA293964756E2164756E21
|
|
217
200
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -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", "
|
|
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
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,12 +8,11 @@
|
|
|
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 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
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",
|
|
13
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",
|
|
14
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"
|
|
15
14
|
],
|
|
16
|
-
"mappings": "
|
|
17
|
-
"debugId": "
|
|
15
|
+
"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;AAIO,IAAM,qBAAqB,CAChC,SACA,YACmB;AAAA,EACnB,OAAO,k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nE,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;",
|
|
16
|
+
"debugId": "C9F4CF2385BA293964756E2164756E21",
|
|
18
17
|
"names": []
|
|
19
18
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -107,21 +107,6 @@ function makeRedirectIntent(redirectUrl, appName) {
|
|
|
107
107
|
};
|
|
108
108
|
return JSON.stringify(obj);
|
|
109
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
110
|
// ../utils/src/intent.ts
|
|
126
111
|
import { z } from "zod";
|
|
127
112
|
var checkoutIntentSchema = z.object({
|
|
@@ -181,10 +166,8 @@ export {
|
|
|
181
166
|
makeCheckoutUrl,
|
|
182
167
|
makeCheckoutClient,
|
|
183
168
|
makeAppClient,
|
|
184
|
-
hasUserSubscribed,
|
|
185
|
-
hasUserPurchased,
|
|
186
169
|
formatPrice
|
|
187
170
|
};
|
|
188
171
|
|
|
189
|
-
//# debugId=
|
|
172
|
+
//# debugId=3D4AFF1091BAEAF564756E2164756E21
|
|
190
173
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -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", "
|
|
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
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,12 +8,11 @@
|
|
|
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 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
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",
|
|
13
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",
|
|
14
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"
|
|
15
14
|
],
|
|
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,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,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,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;",
|
|
16
|
+
"debugId": "3D4AFF1091BAEAF564756E2164756E21",
|
|
18
17
|
"names": []
|
|
19
18
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -268,9 +268,9 @@ declare const mailingListRouter: hono_hono_base.HonoBase<hono_types.BlankEnv, {
|
|
|
268
268
|
callbackUrl: string;
|
|
269
269
|
};
|
|
270
270
|
};
|
|
271
|
-
output: "
|
|
271
|
+
output: "Success";
|
|
272
272
|
outputFormat: "text";
|
|
273
|
-
status:
|
|
273
|
+
status: 200;
|
|
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: "
|
|
282
|
+
output: "Could not send email";
|
|
283
283
|
outputFormat: "text";
|
|
284
|
-
status:
|
|
284
|
+
status: 500;
|
|
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: "
|
|
293
|
+
output: "Contact already subscribed";
|
|
294
294
|
outputFormat: "text";
|
|
295
|
-
status:
|
|
295
|
+
status: 400;
|
|
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:
|
|
308
|
-
outputFormat: "
|
|
309
|
-
status:
|
|
307
|
+
output: undefined;
|
|
308
|
+
outputFormat: "redirect";
|
|
309
|
+
status: 302;
|
|
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: "
|
|
317
|
+
output: "Invalid opt-in token";
|
|
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: "
|
|
327
|
+
output: "Contact does not exist";
|
|
328
328
|
outputFormat: "text";
|
|
329
|
-
status:
|
|
329
|
+
status: 400;
|
|
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:
|
|
338
|
-
outputFormat: "
|
|
339
|
-
status:
|
|
337
|
+
output: "Could not opt in contact";
|
|
338
|
+
outputFormat: "text";
|
|
339
|
+
status: 500;
|
|
340
340
|
};
|
|
341
341
|
};
|
|
342
342
|
} & {
|
|
@@ -3549,11 +3549,7 @@ declare function makeLoginUrl(apiUrl: string, redirectUrl?: string, appName?: st
|
|
|
3549
3549
|
declare function makeCheckoutUrl(apiUrl: string, priceId: string, productId: string, discountCode?: string, loginUrl?: string, pricingUrl?: string, successUrl?: string): string;
|
|
3550
3550
|
declare function makeRedirectIntent(redirectUrl: string, appName?: string): string;
|
|
3551
3551
|
|
|
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
3552
|
declare function formatPrice(amountStr: string, currencyCode: string): string | null;
|
|
3557
3553
|
|
|
3558
|
-
export { formatPrice,
|
|
3559
|
-
export type { AppClient, AuthClient, CheckoutClient, MailingListClient, PublicClient
|
|
3554
|
+
export { formatPrice, makeAppClient, makeCheckoutClient, makeCheckoutUrl, makeLoginUrl, makeMailingListClient, makePublicClient, makeRedirectIntent, makeUsBetterAuthClient };
|
|
3555
|
+
export type { AppClient, AuthClient, CheckoutClient, MailingListClient, PublicClient };
|