@uninspired/auth-client 1.0.17 → 1.0.20
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/README.md +84 -71
- package/dist/index.d.ts +193 -9
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/package.json +28 -7
- package/dist/AuthClient.d.ts +0 -35
- package/dist/AuthClient.js +0 -2
- package/dist/AuthClient.js.map +0 -1
- package/dist/metaAttribution.d.ts +0 -11
- package/dist/metaAttribution.js +0 -2
- package/dist/metaAttribution.js.map +0 -1
- package/dist/react/AuthContext.d.ts +0 -29
- package/dist/react/AuthContext.js +0 -2
- package/dist/react/AuthContext.js.map +0 -1
- package/dist/react/AuthProvider.d.ts +0 -30
- package/dist/react/AuthProvider.js +0 -2
- package/dist/react/AuthProvider.js.map +0 -1
- package/dist/react/index.d.ts +0 -3
- package/dist/react/index.js +0 -1
- package/dist/react/useAuth.d.ts +0 -26
- package/dist/react/useAuth.js +0 -2
- package/dist/react/useAuth.js.map +0 -1
- package/dist/types/src/affiliate.d.ts +0 -1
- package/dist/types/src/checkout.d.ts +0 -1
- package/dist/types/src/index.d.ts +0 -3
- package/dist/types/src/intent.d.ts +0 -1
- package/dist/types/src/meta.d.ts +0 -25
- package/dist/types/src/promo.d.ts +0 -1
- package/dist/types/src/purchases.d.ts +0 -68
- package/dist/types/src/session.d.ts +0 -12
package/README.md
CHANGED
|
@@ -24,18 +24,18 @@ bun add react react-dom
|
|
|
24
24
|
|
|
25
25
|
## What it provides
|
|
26
26
|
|
|
27
|
-
| Feature
|
|
28
|
-
|
|
29
|
-
| **Session management**
|
|
30
|
-
| **Anonymous sign-in**
|
|
31
|
-
| **Sign out**
|
|
32
|
-
| **Purchase data**
|
|
33
|
-
| **Access checks**
|
|
34
|
-
| **Login URL builder**
|
|
35
|
-
| **Checkout URL builder** | Generate a link to the hosted checkout flow
|
|
36
|
-
| **Newsletter**
|
|
37
|
-
| **PostHog integration**
|
|
38
|
-
| **Meta ad attribution**
|
|
27
|
+
| Feature | Description |
|
|
28
|
+
| ------------------------ | ------------------------------------------------------------------------------------------------------------------- |
|
|
29
|
+
| **Session management** | Fetch the current user session (including anonymous sessions) |
|
|
30
|
+
| **Anonymous sign-in** | Automatically sign in visitors as anonymous users |
|
|
31
|
+
| **Sign out** | End the current session |
|
|
32
|
+
| **Purchase data** | Fetch Paddle transactions and Stripe/Paddle subscriptions |
|
|
33
|
+
| **Access checks** | `isPurchased()` and `isSubscribed()` helpers for gating features |
|
|
34
|
+
| **Login URL builder** | Generate a link to the accounts page with a post-login redirect back to your app |
|
|
35
|
+
| **Checkout URL builder** | Generate a link to the hosted checkout flow |
|
|
36
|
+
| **Newsletter** | Subscribe/unsubscribe from mailing lists |
|
|
37
|
+
| **PostHog integration** | Auto-identify users in PostHog when authenticated |
|
|
38
|
+
| **Meta ad attribution** | Auto-capture `fbclid` → `_fbc`/`_fbp` cookies; `trackViewContent` / `trackMetaEvent` for CAPI (no Pixel JS, no PII) |
|
|
39
39
|
|
|
40
40
|
Authentication methods (magic link, email OTP, passkey) are handled on the accounts page — this client manages sessions and purchase data, not the login UI itself.
|
|
41
41
|
|
|
@@ -49,7 +49,6 @@ function App() {
|
|
|
49
49
|
<AuthProvider
|
|
50
50
|
baseUrl="https://auth.uninspired.app"
|
|
51
51
|
frontendUrl="https://uninspired.app"
|
|
52
|
-
mailingListPublicKey="your-public-key"
|
|
53
52
|
>
|
|
54
53
|
<MyApp />
|
|
55
54
|
</AuthProvider>
|
|
@@ -61,7 +60,12 @@ function MyApp() {
|
|
|
61
60
|
|
|
62
61
|
if (!isLoggedIn) {
|
|
63
62
|
return (
|
|
64
|
-
<a
|
|
63
|
+
<a
|
|
64
|
+
href={getLoginUrl({
|
|
65
|
+
redirectUrl: window.location.href,
|
|
66
|
+
appName: "My App",
|
|
67
|
+
})}
|
|
68
|
+
>
|
|
65
69
|
Log in
|
|
66
70
|
</a>
|
|
67
71
|
);
|
|
@@ -87,10 +91,9 @@ Use `AuthClient` directly when you are not in a React tree, or in server-side re
|
|
|
87
91
|
import { AuthClient } from "@uninspired/auth-client";
|
|
88
92
|
|
|
89
93
|
const client = new AuthClient(
|
|
90
|
-
"https://auth.uninspired.app",
|
|
91
|
-
"https://uninspired.app",
|
|
92
|
-
request.headers.get("cookie"),
|
|
93
|
-
"your-mailing-list-public-key", // optional
|
|
94
|
+
"https://auth.uninspired.app", // API URL
|
|
95
|
+
"https://uninspired.app", // Accounts frontend URL
|
|
96
|
+
request.headers.get("cookie"), // optional: forward cookies for SSR
|
|
94
97
|
);
|
|
95
98
|
|
|
96
99
|
const session = await client.getSession();
|
|
@@ -100,15 +103,14 @@ const purchases = await client.getPurchases();
|
|
|
100
103
|
### Constructor
|
|
101
104
|
|
|
102
105
|
```ts
|
|
103
|
-
new AuthClient(apiUrl, frontendUrl, cookie
|
|
106
|
+
new AuthClient(apiUrl, frontendUrl, cookie?)
|
|
104
107
|
```
|
|
105
108
|
|
|
106
|
-
| Parameter
|
|
107
|
-
|
|
108
|
-
| `apiUrl`
|
|
109
|
-
| `frontendUrl` | Accounts frontend URL (e.g. `https://uninspired.app`)
|
|
110
|
-
| `cookie`
|
|
111
|
-
| `mailingListPublicKey` | Optional public key for mailing list endpoints |
|
|
109
|
+
| Parameter | Description |
|
|
110
|
+
| ------------- | ------------------------------------------------------------ |
|
|
111
|
+
| `apiUrl` | Auth API base URL (e.g. `https://auth.uninspired.app`) |
|
|
112
|
+
| `frontendUrl` | Accounts frontend URL (e.g. `https://uninspired.app`) |
|
|
113
|
+
| `cookie` | Optional cookie header string for server-side session lookup |
|
|
112
114
|
|
|
113
115
|
All API requests use `credentials: "include"` in the browser, so session cookies are sent automatically on the same root domain.
|
|
114
116
|
|
|
@@ -144,36 +146,30 @@ const purchases = await client.getPurchases();
|
|
|
144
146
|
transactions: Array<{ id, items: string[], adjustments: [...] }>;
|
|
145
147
|
};
|
|
146
148
|
stripe: Array<{ id, status, items: string[] }>;
|
|
147
|
-
mailingList: { subscribed: boolean };
|
|
148
149
|
}
|
|
149
150
|
```
|
|
150
151
|
|
|
152
|
+
Newsletter subscribe/unsubscribe uses [`@uninspired/newsletter-client`](../newsletter-client/README.md), not `AuthClient`.
|
|
153
|
+
|
|
151
154
|
#### URL builders
|
|
152
155
|
|
|
153
156
|
```ts
|
|
154
157
|
// Link to the accounts login page, redirect back after auth
|
|
155
158
|
const loginUrl = client.getLoginUrl({
|
|
156
159
|
redirectUrl: "https://myapp.uninspired.app/dashboard",
|
|
157
|
-
appName: "My App",
|
|
160
|
+
appName: "My App", // optional, shown on the login page
|
|
158
161
|
});
|
|
159
162
|
|
|
160
163
|
// Link to the hosted checkout flow
|
|
161
164
|
const checkoutUrl = client.getCheckoutUrl({
|
|
162
165
|
priceId: "pri_01234567890",
|
|
163
166
|
productId: "pro_01234567890",
|
|
164
|
-
discountCode: "SAVE20",
|
|
165
|
-
successUrl: "https://myapp.uninspired.app/welcome",
|
|
166
|
-
quantity: 1,
|
|
167
|
+
discountCode: "SAVE20", // optional
|
|
168
|
+
successUrl: "https://myapp.uninspired.app/welcome", // optional
|
|
169
|
+
quantity: 1, // optional, defaults to 1
|
|
167
170
|
});
|
|
168
171
|
```
|
|
169
172
|
|
|
170
|
-
#### Newsletter
|
|
171
|
-
|
|
172
|
-
```ts
|
|
173
|
-
await client.newsletterSubscribe("user@example.com", "my-app-group", "https://callback.url");
|
|
174
|
-
await client.newsletterUnsubscribe("user@example.com");
|
|
175
|
-
```
|
|
176
|
-
|
|
177
173
|
#### Meta ad attribution
|
|
178
174
|
|
|
179
175
|
`AuthProvider` auto-captures `fbclid` into `_fbc`/`_fbp` cookies. No Meta Pixel script is loaded.
|
|
@@ -197,15 +193,14 @@ See [docs/ad-attribution.md](../../docs/ad-attribution.md).
|
|
|
197
193
|
|
|
198
194
|
### `AuthProvider` props
|
|
199
195
|
|
|
200
|
-
| Prop
|
|
201
|
-
|
|
202
|
-
| `baseUrl`
|
|
203
|
-
| `frontendUrl`
|
|
204
|
-
| `
|
|
205
|
-
| `initialSession` | `Session \| null?` | Pre-fetched session for SSR |
|
|
196
|
+
| Prop | Type | Description |
|
|
197
|
+
| ------------------ | ------------------------ | ----------------------------- |
|
|
198
|
+
| `baseUrl` | `string` | Auth API URL |
|
|
199
|
+
| `frontendUrl` | `string` | Accounts frontend URL |
|
|
200
|
+
| `initialSession` | `Session \| null?` | Pre-fetched session for SSR |
|
|
206
201
|
| `initialPurchases` | `UserPurchases \| null?` | Pre-fetched purchases for SSR |
|
|
207
|
-
| `authClient`
|
|
208
|
-
| `queryClient`
|
|
202
|
+
| `authClient` | `AuthClient?` | Custom client instance |
|
|
203
|
+
| `queryClient` | `QueryClient?` | Custom TanStack Query client |
|
|
209
204
|
|
|
210
205
|
The provider automatically:
|
|
211
206
|
|
|
@@ -217,25 +212,23 @@ The provider automatically:
|
|
|
217
212
|
|
|
218
213
|
### `useAuth()` return value
|
|
219
214
|
|
|
220
|
-
| Property
|
|
221
|
-
|
|
222
|
-
| `session`
|
|
223
|
-
| `isLoggedIn`
|
|
224
|
-
| `isSessionFetching`
|
|
225
|
-
| `refetchSession`
|
|
226
|
-
| `purchases`
|
|
227
|
-
| `isPurchasesFetching` | `boolean`
|
|
228
|
-
| `refetchPurchases`
|
|
229
|
-
| `signOut`
|
|
230
|
-
| `getLoginUrl`
|
|
231
|
-
| `getCheckoutUrl`
|
|
232
|
-
| `trackMetaEvent`
|
|
233
|
-
| `trackViewContent`
|
|
234
|
-
| `getMetaAttribution`
|
|
235
|
-
| `isPurchased`
|
|
236
|
-
| `isSubscribed`
|
|
237
|
-
| `newsletterSubscribe` | `AuthClient["newsletterSubscribe"]` | Subscribe to newsletter |
|
|
238
|
-
| `newsletterUnsubscribe` | `AuthClient["newsletterUnsubscribe"]` | Unsubscribe from newsletter |
|
|
215
|
+
| Property | Type | Description |
|
|
216
|
+
| --------------------- | ---------------------------------------------------- | ----------------------------------------------- |
|
|
217
|
+
| `session` | `Session \| null` | Current session |
|
|
218
|
+
| `isLoggedIn` | `boolean` | `true` if user is authenticated (not anonymous) |
|
|
219
|
+
| `isSessionFetching` | `boolean` | Session query loading state |
|
|
220
|
+
| `refetchSession` | `() => Promise<void>` | Re-fetch session |
|
|
221
|
+
| `purchases` | `UserPurchases \| null` | User's purchase data |
|
|
222
|
+
| `isPurchasesFetching` | `boolean` | Purchases query loading state |
|
|
223
|
+
| `refetchPurchases` | `() => Promise<void>` | Re-fetch purchases |
|
|
224
|
+
| `signOut` | `(onSuccess?) => Promise<void>` | Sign out (resets PostHog) |
|
|
225
|
+
| `getLoginUrl` | `AuthClient["getLoginUrl"]` | Build login URL |
|
|
226
|
+
| `getCheckoutUrl` | `AuthClient["getCheckoutUrl"]` | Build checkout URL |
|
|
227
|
+
| `trackMetaEvent` | `AuthClient["trackMetaEvent"]` | Send Meta CAPI event (no PII) |
|
|
228
|
+
| `trackViewContent` | `AuthClient["trackViewContent"]` | Convenience wrapper for product views |
|
|
229
|
+
| `getMetaAttribution` | `AuthClient["getMetaAttribution"]` | Read `_fbc` / `_fbp` cookies |
|
|
230
|
+
| `isPurchased` | `(priceIds: string[]) => boolean` | Check one-time purchase |
|
|
231
|
+
| `isSubscribed` | `(priceIds: string[], productId: string) => boolean` | Check active subscription |
|
|
239
232
|
|
|
240
233
|
### Access checks
|
|
241
234
|
|
|
@@ -276,7 +269,7 @@ const [session, purchases] = await Promise.all([
|
|
|
276
269
|
initialPurchases={purchases}
|
|
277
270
|
>
|
|
278
271
|
{children}
|
|
279
|
-
</AuthProvider
|
|
272
|
+
</AuthProvider>;
|
|
280
273
|
```
|
|
281
274
|
|
|
282
275
|
Forward the request's `Cookie` header to the constructor so the API can resolve the session server-side.
|
|
@@ -297,19 +290,39 @@ import type { Session, UserPurchases } from "@uninspired/auth-client";
|
|
|
297
290
|
|
|
298
291
|
## Building from source
|
|
299
292
|
|
|
300
|
-
This package is part of the US Auth monorepo.
|
|
293
|
+
This package is part of the US Auth monorepo.
|
|
294
|
+
|
|
295
|
+
### Workspace consumers (monorepo)
|
|
296
|
+
|
|
297
|
+
Entry points resolve to TypeScript source (`./src/index.ts`) so Vite and `moduleResolution: "bundler"` can import the package without a pre-build:
|
|
298
|
+
|
|
299
|
+
```json
|
|
300
|
+
{
|
|
301
|
+
"main": "./src/index.ts",
|
|
302
|
+
"types": "./src/index.ts",
|
|
303
|
+
"exports": { ".": "./src/index.ts" }
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
No `bun run build` is required when developing apps inside this repo.
|
|
308
|
+
|
|
309
|
+
### Publishing (npm)
|
|
310
|
+
|
|
311
|
+
Published tarballs ship only compiled output in `dist/`. npm ignores `publishConfig` manifest overrides, so `prepack`/`postpack` apply them via `scripts/apply-publish-config.mjs` (build runs in `prepack` too):
|
|
301
312
|
|
|
302
313
|
```bash
|
|
303
314
|
cd packages/auth-client
|
|
304
|
-
|
|
315
|
+
npm publish
|
|
305
316
|
```
|
|
306
317
|
|
|
318
|
+
Product apps outside the monorepo install the compiled ESM + `.d.ts` from `dist/`.
|
|
319
|
+
|
|
307
320
|
Output goes to `dist/`.
|
|
308
321
|
|
|
309
322
|
## Environment URLs
|
|
310
323
|
|
|
311
|
-
| Environment | API
|
|
312
|
-
|
|
313
|
-
| Production
|
|
324
|
+
| Environment | API | Accounts frontend |
|
|
325
|
+
| ----------- | --------------------------------- | ---------------------------- |
|
|
326
|
+
| Production | `https://auth.uninspired.app` | `https://uninspired.app` |
|
|
314
327
|
| Development | `https://auth.dev.uninspired.app` | `https://dev.uninspired.app` |
|
|
315
|
-
| Local
|
|
328
|
+
| Local | `http://localhost:3000` | `http://localhost:5173` |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,193 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as _$react from "react";
|
|
3
|
+
import { PropsWithChildren } from "react";
|
|
4
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
5
|
+
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
6
|
+
import { Session as Session$1, User } from "better-auth";
|
|
7
|
+
|
|
8
|
+
//#region ../types/src/purchases.d.ts
|
|
9
|
+
declare const userPurchasesSchema: z.ZodObject<{
|
|
10
|
+
stripe: z.ZodArray<z.ZodObject<{
|
|
11
|
+
id: z.ZodString;
|
|
12
|
+
customerId: z.ZodString;
|
|
13
|
+
created: z.ZodCoercedDate<unknown>;
|
|
14
|
+
status: z.ZodEnum<{
|
|
15
|
+
active: "active";
|
|
16
|
+
trialing: "trialing";
|
|
17
|
+
canceled: "canceled";
|
|
18
|
+
past_due: "past_due";
|
|
19
|
+
paused: "paused";
|
|
20
|
+
incomplete: "incomplete";
|
|
21
|
+
incomplete_expired: "incomplete_expired";
|
|
22
|
+
unpaid: "unpaid";
|
|
23
|
+
}>;
|
|
24
|
+
items: z.ZodArray<z.ZodString>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
paddle: z.ZodObject<{
|
|
27
|
+
customerId: z.ZodOptional<z.ZodString>;
|
|
28
|
+
subscriptions: z.ZodArray<z.ZodObject<{
|
|
29
|
+
id: z.ZodString;
|
|
30
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
31
|
+
status: z.ZodString;
|
|
32
|
+
items: z.ZodArray<z.ZodObject<{
|
|
33
|
+
priceId: z.ZodString;
|
|
34
|
+
productId: z.ZodString;
|
|
35
|
+
}, z.core.$strip>>;
|
|
36
|
+
}, z.core.$strip>>;
|
|
37
|
+
transactions: z.ZodArray<z.ZodObject<{
|
|
38
|
+
id: z.ZodString;
|
|
39
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
40
|
+
adjustments: z.ZodArray<z.ZodObject<{
|
|
41
|
+
id: z.ZodString;
|
|
42
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
43
|
+
action: z.ZodEnum<{
|
|
44
|
+
credit: "credit";
|
|
45
|
+
refund: "refund";
|
|
46
|
+
chargeback: "chargeback";
|
|
47
|
+
chargeback_reverse: "chargeback_reverse";
|
|
48
|
+
chargeback_warning: "chargeback_warning";
|
|
49
|
+
chargeback_warning_reverse: "chargeback_warning_reverse";
|
|
50
|
+
credit_reverse: "credit_reverse";
|
|
51
|
+
}>;
|
|
52
|
+
type: z.ZodEnum<{
|
|
53
|
+
full: "full";
|
|
54
|
+
partial: "partial";
|
|
55
|
+
}>;
|
|
56
|
+
status: z.ZodEnum<{
|
|
57
|
+
pending_approval: "pending_approval";
|
|
58
|
+
approved: "approved";
|
|
59
|
+
rejected: "rejected";
|
|
60
|
+
reversed: "reversed";
|
|
61
|
+
}>;
|
|
62
|
+
}, z.core.$strip>>;
|
|
63
|
+
items: z.ZodArray<z.ZodString>;
|
|
64
|
+
}, z.core.$strip>>;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
type UserPurchases = z.infer<typeof userPurchasesSchema>;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region ../types/src/session.d.ts
|
|
70
|
+
interface Session {
|
|
71
|
+
session: Session$1;
|
|
72
|
+
user: User & {
|
|
73
|
+
isAnonymous?: boolean | null;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region ../types/src/meta.d.ts
|
|
78
|
+
declare const metaTrackEventSchema: z.ZodObject<{
|
|
79
|
+
event_name: z.ZodEnum<{
|
|
80
|
+
ViewContent: "ViewContent";
|
|
81
|
+
InitiateCheckout: "InitiateCheckout";
|
|
82
|
+
}>;
|
|
83
|
+
content_ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
84
|
+
content_type: z.ZodOptional<z.ZodString>;
|
|
85
|
+
event_source_url: z.ZodOptional<z.ZodString>;
|
|
86
|
+
value: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
88
|
+
event_id: z.ZodOptional<z.ZodString>;
|
|
89
|
+
}, z.core.$strip>;
|
|
90
|
+
type MetaTrackEventInput = z.infer<typeof metaTrackEventSchema>;
|
|
91
|
+
type MetaAttributionCookies = {
|
|
92
|
+
fbc?: string;
|
|
93
|
+
fbp?: string;
|
|
94
|
+
};
|
|
95
|
+
declare function parseMetaAttributionFromCookieHeader(cookieHeader: string | undefined): MetaAttributionCookies;
|
|
96
|
+
declare function buildFbcFromFbclid(fbclid: string, seenAtMs?: number): string;
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/metaAttribution.d.ts
|
|
99
|
+
declare function getMetaCookieDomain(frontendUrl: string): string | undefined;
|
|
100
|
+
declare function readMetaAttributionCookies(): MetaAttributionCookies;
|
|
101
|
+
declare function captureMetaClickId(options: {
|
|
102
|
+
frontendUrl: string;
|
|
103
|
+
stripFbclidFromUrl?: boolean;
|
|
104
|
+
}): MetaAttributionCookies;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/AuthClient.d.ts
|
|
107
|
+
declare class AuthClient {
|
|
108
|
+
#private;
|
|
109
|
+
constructor(apiUrl: string, frontendUrl: string, cookie?: string);
|
|
110
|
+
getSession: () => Promise<Session | null>;
|
|
111
|
+
signInAnonymously: () => Promise<Session | null>;
|
|
112
|
+
signOut: (onSuccess?: () => void) => Promise<void>;
|
|
113
|
+
getPurchases: () => Promise<UserPurchases | null>;
|
|
114
|
+
trackMetaEvent: (payload: MetaTrackEventInput) => Promise<void>;
|
|
115
|
+
trackViewContent: (options: {
|
|
116
|
+
contentIds: string[];
|
|
117
|
+
contentType?: string;
|
|
118
|
+
eventSourceUrl?: string;
|
|
119
|
+
}) => Promise<void>;
|
|
120
|
+
getMetaAttribution: () => MetaAttributionCookies;
|
|
121
|
+
getLoginUrl: (options?: {
|
|
122
|
+
redirectUrl?: string;
|
|
123
|
+
appName?: string;
|
|
124
|
+
}) => string;
|
|
125
|
+
getCheckoutUrl: (options: {
|
|
126
|
+
priceId: string;
|
|
127
|
+
productId: string;
|
|
128
|
+
discountCode?: string;
|
|
129
|
+
successUrl?: string;
|
|
130
|
+
quantity?: number;
|
|
131
|
+
}) => string;
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/react/AuthContext.d.ts
|
|
135
|
+
type AuthContextType = {
|
|
136
|
+
session: Session | null;
|
|
137
|
+
isSessionFetching: boolean;
|
|
138
|
+
refetchSession: () => Promise<void>;
|
|
139
|
+
purchases: UserPurchases | null;
|
|
140
|
+
isPurchasesFetching: boolean;
|
|
141
|
+
refetchPurchases: () => Promise<void>;
|
|
142
|
+
signOut: AuthClient["signOut"];
|
|
143
|
+
getLoginUrl: AuthClient["getLoginUrl"];
|
|
144
|
+
getCheckoutUrl: AuthClient["getCheckoutUrl"];
|
|
145
|
+
trackMetaEvent: AuthClient["trackMetaEvent"];
|
|
146
|
+
trackViewContent: AuthClient["trackViewContent"];
|
|
147
|
+
getMetaAttribution: AuthClient["getMetaAttribution"];
|
|
148
|
+
isPurchased: (priceIds: string[]) => boolean;
|
|
149
|
+
isSubscribed: (priceIds: string[], productId: string) => boolean;
|
|
150
|
+
isLoggedIn: boolean;
|
|
151
|
+
} | null;
|
|
152
|
+
declare const AuthContext: _$react.Context<AuthContextType>;
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/react/AuthProvider.d.ts
|
|
155
|
+
interface AuthProviderProps extends PropsWithChildren {
|
|
156
|
+
authClient?: AuthClient;
|
|
157
|
+
queryClient?: QueryClient;
|
|
158
|
+
baseUrl: string;
|
|
159
|
+
frontendUrl: string;
|
|
160
|
+
initialSession?: Session | null;
|
|
161
|
+
initialPurchases?: UserPurchases | null;
|
|
162
|
+
}
|
|
163
|
+
declare const AuthProvider: ({
|
|
164
|
+
children,
|
|
165
|
+
baseUrl,
|
|
166
|
+
frontendUrl,
|
|
167
|
+
initialSession,
|
|
168
|
+
initialPurchases,
|
|
169
|
+
authClient: providedAuthClient,
|
|
170
|
+
queryClient: providedQueryClient
|
|
171
|
+
}: AuthProviderProps) => _$react_jsx_runtime0.JSX.Element;
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/react/useAuth.d.ts
|
|
174
|
+
declare function useAuth(): {
|
|
175
|
+
session: Session | null;
|
|
176
|
+
isSessionFetching: boolean;
|
|
177
|
+
refetchSession: () => Promise<void>;
|
|
178
|
+
purchases: UserPurchases | null;
|
|
179
|
+
isPurchasesFetching: boolean;
|
|
180
|
+
refetchPurchases: () => Promise<void>;
|
|
181
|
+
signOut: AuthClient["signOut"];
|
|
182
|
+
getLoginUrl: AuthClient["getLoginUrl"];
|
|
183
|
+
getCheckoutUrl: AuthClient["getCheckoutUrl"];
|
|
184
|
+
trackMetaEvent: AuthClient["trackMetaEvent"];
|
|
185
|
+
trackViewContent: AuthClient["trackViewContent"];
|
|
186
|
+
getMetaAttribution: AuthClient["getMetaAttribution"];
|
|
187
|
+
isPurchased: (priceIds: string[]) => boolean;
|
|
188
|
+
isSubscribed: (priceIds: string[], productId: string) => boolean;
|
|
189
|
+
isLoggedIn: boolean;
|
|
190
|
+
};
|
|
191
|
+
//#endregion
|
|
192
|
+
export { AuthClient, AuthContext, AuthContextType, AuthProvider, AuthProviderProps, type MetaAttributionCookies, type Session, type UserPurchases, buildFbcFromFbclid, captureMetaClickId, getMetaCookieDomain, parseMetaAttributionFromCookieHeader, readMetaAttributionCookies, useAuth };
|
|
193
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{buildFbcFromFbclid as e,captureMetaClickId as t,getMetaCookieDomain as n,parseMetaAttributionFromCookieHeader as r,readMetaAttributionCookies as i}from"./metaAttribution.js";import{AuthClient as a}from"./AuthClient.js";import{AuthContext as o}from"./react/AuthContext.js";import{AuthProvider as s}from"./react/AuthProvider.js";import{useAuth as c}from"./react/useAuth.js";import"./react/index.js";export{a as AuthClient,o as AuthContext,s as AuthProvider,e as buildFbcFromFbclid,t as captureMetaClickId,n as getMetaCookieDomain,r as parseMetaAttributionFromCookieHeader,i as readMetaAttributionCookies,c as useAuth};
|
|
1
|
+
import{anonymousClient as e,emailOTPClient as t,magicLinkClient as n}from"better-auth/client/plugins";import{passkeyClient as r}from"@better-auth/passkey/client";import{createAuthClient as i}from"better-auth/client";import{hc as a}from"hono/client";import{z as o}from"zod";import{createContext as s,useCallback as c,useContext as l,useEffect as u,useMemo as d,useRef as f}from"react";import{QueryClient as p,useQuery as m}from"@tanstack/react-query";import{usePostHog as h}from"@posthog/react";import{jsx as g}from"react/jsx-runtime";const _=o.object({id:o.string(),createdAt:o.coerce.date(),status:o.string(),items:o.array(o.object({priceId:o.string(),productId:o.string()}))}),v=o.object({id:o.string(),createdAt:o.coerce.date(),adjustments:o.array(o.object({id:o.string(),createdAt:o.coerce.date(),action:o.enum([`credit`,`refund`,`chargeback`,`chargeback_reverse`,`chargeback_warning`,`chargeback_warning_reverse`,`credit_reverse`]),type:o.enum([`full`,`partial`]),status:o.enum([`pending_approval`,`approved`,`rejected`,`reversed`])})),items:o.array(o.string())}),y=o.object({id:o.string(),customerId:o.string(),created:o.coerce.date(),status:o.enum([`active`,`trialing`,`canceled`,`past_due`,`paused`,`incomplete`,`incomplete_expired`,`unpaid`]),items:o.array(o.string())}),b=o.array(y),x=o.object({customerId:o.string().optional(),subscriptions:o.array(_),transactions:o.array(v)});o.object({stripe:b,paddle:x});const S=o.object({type:o.literal(`checkout`),priceId:o.string(),additionalPriceIds:o.array(o.string()).optional(),productId:o.string().optional(),discountCode:o.string().optional(),loginUrl:o.string().refine(e=>{let t=decodeURIComponent(e);return o.url().safeParse(t).success}).transform(e=>decodeURIComponent(e)).optional(),pricingUrl:o.string().refine(e=>{let t=decodeURIComponent(e);return o.url().safeParse(t).success}).transform(e=>decodeURIComponent(e)).optional(),successUrl:o.string().refine(e=>{let t=decodeURIComponent(e);return o.url().safeParse(t).success}).transform(e=>decodeURIComponent(e)).optional()}),C=o.object({type:o.literal(`redirect`),redirectUrl:o.url(),appName:o.string().optional()}),w=o.object({type:o.literal(`auth`),returnUrl:o.string()}),T=o.discriminatedUnion(`type`,[S,C,w]);o.object({intent:T.optional()}),o.object({priceId:o.string(),additionalPriceIds:o.array(o.string()).optional(),productId:o.string(),quantity:o.coerce.number().int().min(1).max(999).optional(),discountCode:o.string().optional(),loginUrl:o.string().refine(e=>{let t=decodeURIComponent(e);return o.url().safeParse(t).success}).transform(e=>decodeURIComponent(e)).optional(),pricingUrl:o.string().refine(e=>{let t=decodeURIComponent(e);return o.url().safeParse(t).success}).transform(e=>decodeURIComponent(e)).optional(),successUrl:o.string().refine(e=>{let t=decodeURIComponent(e);return o.url().safeParse(t).success}).transform(e=>decodeURIComponent(e)).optional(),fbclid:o.string().optional()}),o.enum([`missing_purchases`,`invalid_redirect_hosts`,`already_owned`,`invalid_prices`,`invalid_discount`,`internal_server_error`]),o.object({slug:o.string().min(1).max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),productId:o.string().min(1),discountPercent:o.number().int().min(1).max(100),startsAt:o.coerce.date(),endsAt:o.coerce.date()}).extend({id:o.string().min(1)}),o.object({id:o.string().min(1)}),o.object({id:o.string(),slug:o.string(),productId:o.string(),discountPercent:o.number(),startsAt:o.coerce.date(),endsAt:o.coerce.date(),shortLinkUrl:o.string(),promoPageUrl:o.string(),createdAt:o.coerce.date()});const E=o.object({currencyCode:o.string(),originalAmount:o.string(),originalFormatted:o.string()}),D=o.object({id:o.string(),name:o.string().nullable(),description:o.string().nullable(),customData:o.custom(e=>e===null||typeof e==`object`).nullable(),billingCycle:o.object({interval:o.enum([`day`,`week`,`month`,`year`]),frequency:o.number()}).nullable(),unitPrice:o.object({amount:o.string(),currencyCode:o.string()}).nullable(),unitPriceOverrides:o.array(o.object({countryCodes:o.array(o.string()),unitPrice:o.object({amount:o.string(),currencyCode:o.string()})})).nullable(),owned:o.boolean(),preview:E.optional()});o.object({slug:o.string(),productId:o.string(),productName:o.string(),productDescription:o.string().nullable(),discountPercent:o.number(),isActive:o.boolean(),alreadyRedeemed:o.boolean(),prices:o.array(D)}),o.object({discountCode:o.string(),checkoutUrl:o.string()}),o.object({slug:o.string().min(1),priceId:o.string().min(1)}),o.object({productId:o.string(),productName:o.string(),productDescription:o.string().nullable(),discountPercent:o.number(),valid:o.boolean(),prices:o.array(D)}),o.object({productId:o.string().min(1),priceId:o.string().min(1),ref:o.string().min(1)}),o.object({discountCode:o.string(),checkoutUrl:o.string()}),o.enum([`ViewContent`,`InitiateCheckout`,`Purchase`]);const O=o.enum([`ViewContent`,`InitiateCheckout`]);o.object({event_name:O,content_ids:o.array(o.string()).optional(),content_type:o.string().optional(),event_source_url:o.string().url().optional(),value:o.number().optional(),currency:o.string().optional(),event_id:o.string().optional()});function k(e){if(!e)return{};let t={};for(let n of e.split(`;`)){let e=n.trim();if(!e)continue;let r=e.indexOf(`=`);if(r===-1)continue;let i=e.slice(0,r),a=e.slice(r+1);t[i]=decodeURIComponent(a)}return{fbc:t._fbc,fbp:t._fbp}}function A(e,t=Date.now()){return`fb.1.${t}.${e}`}const j=`_fbc`,M=`_fbp`;function N(){return Math.floor(Math.random()*1e10).toString()}function P(e){let t=new URL(e).hostname;if(!(t===`localhost`||t===`127.0.0.1`))return`.${t}`}function F(e){if(typeof document>`u`)return;let t=document.cookie.split(`;`).map(e=>e.trim()).find(t=>t.startsWith(`${e}=`));if(t)return decodeURIComponent(t.slice(e.length+1))}function I(e,t,n){if(typeof document>`u`)return;let r=P(n),i=[`${e}=${encodeURIComponent(t)}`,`Path=/`,`Secure`,`SameSite=Lax`,`Max-Age=7776000`];r&&i.push(`Domain=${r}`),document.cookie=i.join(`; `)}function L(){return{fbc:F(j),fbp:F(M)}}function R(e){if(typeof window>`u`)return{};let{frontendUrl:t,stripFbclidFromUrl:n=!0}=e,r=new URLSearchParams(window.location.search),i=r.get(`fbclid`);if(i&&(I(j,A(i),t),n)){r.delete(`fbclid`);let e=r.toString(),t=`${window.location.pathname}${e?`?${e}`:``}${window.location.hash}`;window.history.replaceState({},``,t)}let a=F(M);return a||(a=`fb.1.${Date.now()}.${N()}`,I(M,a,t)),L()}var z=class{#e;#t;#n;#r;constructor(o,s,c){this.#r=c,this.#e=s,this.#t=i({baseURL:o,plugins:[e(),n(),t(),r()]}),this.#n=a(new URL(`/api/app`,o).toString(),{fetch:(e,t)=>fetch(e,{...t,credentials:`include`})})}getSession=async()=>{let{data:e,error:t}=await this.#t.getSession({},{headers:this.#r?{Cookie:this.#r}:void 0});if(t)throw t;return e};signInAnonymously=async()=>{let{error:e}=await this.#t.signIn.anonymous();if(e)throw e;return this.getSession()};signOut=async e=>{let{error:t}=await this.#t.signOut({fetchOptions:{onSuccess:e}},{headers:this.#r?{Cookie:this.#r}:void 0});if(t)throw t};getPurchases=async()=>{let e=await this.#n.purchases.$get(void 0,{headers:this.#r?{Cookie:this.#r}:void 0});if(!e.ok)throw Error(`Failed to get purchases`,{cause:await e.text()});return await e.json()};#i=(e,t)=>JSON.stringify({type:`redirect`,redirectUrl:e,appName:t});trackMetaEvent=async e=>{let t=await this.#n.meta.events.$post({json:e});if(!t.ok)throw Error(`Failed to track Meta event`,{cause:await t.text()})};trackViewContent=async e=>{let t=e.eventSourceUrl??(typeof window<`u`?window.location.href:void 0);await this.trackMetaEvent({event_name:`ViewContent`,content_ids:e.contentIds,content_type:e.contentType??`product`,...t?{event_source_url:t}:{}})};getMetaAttribution=()=>L();getLoginUrl=e=>{let t=new URL(`/login`,this.#e);return e?.redirectUrl&&t.searchParams.set(`intent`,this.#i(e.redirectUrl,e.appName)),t.toString()};getCheckoutUrl=e=>{let t=new URL(`/auth/checkout`,this.#e);return t.searchParams.set(`priceId`,e.priceId),t.searchParams.set(`productId`,e.productId),e.discountCode&&t.searchParams.set(`discountCode`,e.discountCode),e.successUrl&&t.searchParams.set(`successUrl`,e.successUrl),t.searchParams.set(`quantity`,e.quantity?.toString()??`1`),t.toString()}};const B=s(null),V=({children:e,baseUrl:t,frontendUrl:n,initialSession:r,initialPurchases:i,authClient:a,queryClient:o})=>{let s=h(),l=d(()=>a??new z(t,n),[t,n,a]),_=d(()=>o??new p,[o]),{data:v,isFetching:y,refetch:b}=m({queryKey:[`us-auth-session`],staleTime:0,initialData:r,queryFn:l.getSession},_),x=d(()=>!(!v||v.user.isAnonymous),[v]),S=f(!1);u(()=>{R({frontendUrl:n})},[n]),u(()=>{y||v===null&&(S.current||(S.current=!0,l.signInAnonymously().then(e=>{_.setQueryData([`us-auth-session`],e)}).catch(e=>console.error(e))))},[l,y,_,v]),u(()=>{v?.user&&s&&s.get_distinct_id()!==v.user.id&&s.identify(v.user.id,{email:v.user.email})},[v,s]);let{data:C,isFetching:w,refetch:T}=m({queryKey:[`us-auth-purchases`],staleTime:1e3*60,initialData:i,queryFn:l.getPurchases},_),E=d(()=>l.getLoginUrl,[l]),D=d(()=>l.getCheckoutUrl,[l]),O=c(e=>l.signOut(()=>{s?.reset(),e?.()}),[l,s]),k=d(()=>l.trackMetaEvent,[l]),A=d(()=>l.trackViewContent,[l]),j=d(()=>l.getMetaAttribution,[l]),M=c(e=>C?C.paddle.transactions.some(t=>t.items.some(t=>e.includes(t))&&!t.adjustments.some(e=>e.status===`approved`&&e.action===`refund`)):!1,[C]),N=c((e,t)=>{if(!C)return!1;let n=C.paddle.subscriptions.some(n=>n.items.some(n=>e.includes(n.priceId)||t===n.productId)&&n.status===`active`),r=C.stripe.some(t=>t.status===`active`&&t.items.some(t=>e.includes(t)));return n||r},[C]);return g(B.Provider,{value:{session:v??null,isSessionFetching:y,refetchSession:async()=>{await b()},purchases:C??null,isPurchasesFetching:w,refetchPurchases:async()=>{await T()},signOut:O,getLoginUrl:E,getCheckoutUrl:D,trackMetaEvent:k,trackViewContent:A,getMetaAttribution:j,isSubscribed:N,isPurchased:M,isLoggedIn:x},children:e})};function H(){let e=l(B);if(!e)throw Error(`useAuth must be used within an AuthProvider`);return e}export{z as AuthClient,B as AuthContext,V as AuthProvider,A as buildFbcFromFbclid,R as captureMetaClickId,P as getMetaCookieDomain,k as parseMetaAttributionFromCookieHeader,L as readMetaAttributionCookies,H as useAuth};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["#cookie","#frontendUrl","#authClient","#appClient","#getRedirectIntent"],"sources":["../../types/src/purchases.ts","../../types/src/intent.ts","../../types/src/checkout.ts","../../types/src/promo.ts","../../types/src/affiliate.ts","../../types/src/meta.ts","../src/metaAttribution.ts","../src/AuthClient.ts","../src/react/AuthContext.ts","../src/react/AuthProvider.tsx","../src/react/useAuth.ts"],"sourcesContent":["import { z } from \"zod\";\n\nconst paddleSubscriptionSchema = z.object({\n id: z.string(),\n createdAt: z.coerce.date(),\n status: z.string(),\n items: z.array(\n z.object({\n priceId: z.string(),\n productId: z.string(),\n }),\n ),\n});\n\nexport const paddleTransactionSchema = z.object({\n id: z.string(),\n createdAt: z.coerce.date(),\n adjustments: z.array(\n z.object({\n id: z.string(),\n createdAt: z.coerce.date(),\n action: z.enum([\n \"credit\",\n \"refund\",\n \"chargeback\",\n \"chargeback_reverse\",\n \"chargeback_warning\",\n \"chargeback_warning_reverse\",\n \"credit_reverse\",\n ]),\n type: z.enum([\"full\", \"partial\"]),\n status: z.enum([\"pending_approval\", \"approved\", \"rejected\", \"reversed\"]),\n }),\n ),\n items: z.array(z.string()),\n});\n\nconst stripeSubscriptionSchema = z.object({\n id: z.string(),\n customerId: z.string(),\n created: z.coerce.date(),\n status: z.enum([\n \"active\",\n \"trialing\",\n \"canceled\",\n \"past_due\",\n \"paused\",\n \"incomplete\",\n \"incomplete_expired\",\n \"unpaid\",\n ]),\n items: z.array(z.string()),\n});\n\nexport const stripeDataSchema = z.array(stripeSubscriptionSchema);\n\nexport type StripeData = z.infer<typeof stripeDataSchema>;\n\nexport const paddleDataSchema = z.object({\n customerId: z.string().optional(),\n subscriptions: z.array(paddleSubscriptionSchema),\n transactions: z.array(paddleTransactionSchema),\n});\n\nexport type PaddleData = z.infer<typeof paddleDataSchema>;\n\nexport const userPurchasesSchema = z.object({\n stripe: stripeDataSchema,\n paddle: paddleDataSchema,\n});\n\nexport type UserPurchases = z.infer<typeof userPurchasesSchema>;\n","import { z } from \"zod\";\n\nexport const checkoutIntentSchema = z.object({\n type: z.literal(\"checkout\"),\n priceId: z.string(),\n additionalPriceIds: z.array(z.string()).optional(),\n productId: z.string().optional(),\n discountCode: z.string().optional(),\n loginUrl: z\n .string()\n .refine((v) => {\n const url = decodeURIComponent(v);\n return z.url().safeParse(url).success;\n })\n .transform((v) => decodeURIComponent(v))\n .optional(),\n pricingUrl: z\n .string()\n .refine((v) => {\n const url = decodeURIComponent(v);\n return z.url().safeParse(url).success;\n })\n .transform((v) => decodeURIComponent(v))\n .optional(),\n successUrl: z\n .string()\n .refine((v) => {\n const url = decodeURIComponent(v);\n return z.url().safeParse(url).success;\n })\n .transform((v) => decodeURIComponent(v))\n .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 authRouteIntentSchema = z.object({\n type: z.literal(\"auth\"),\n returnUrl: z.string(),\n});\nexport type AuthRouteIntent = z.infer<typeof authRouteIntentSchema>;\n\nexport const intentSchema = z.discriminatedUnion(\"type\", [\n checkoutIntentSchema,\n redirectIntentSchema,\n authRouteIntentSchema,\n]);\nexport type Intent = z.infer<typeof intentSchema>;\n\nexport const intentSearchSchema = z.object({\n intent: intentSchema.optional(),\n});\n","import { z } from \"zod\";\n\nexport const checkoutSearchSchema = z.object({\n priceId: z.string(),\n additionalPriceIds: z.array(z.string()).optional(),\n productId: z.string(),\n quantity: z.coerce.number().int().min(1).max(999).optional(),\n discountCode: z.string().optional(),\n loginUrl: z\n .string()\n .refine((v) => {\n const url = decodeURIComponent(v);\n return z.url().safeParse(url).success;\n })\n .transform((v) => decodeURIComponent(v))\n .optional(),\n pricingUrl: z\n .string()\n .refine((v) => {\n const url = decodeURIComponent(v);\n return z.url().safeParse(url).success;\n })\n .transform((v) => decodeURIComponent(v))\n .optional(),\n successUrl: z\n .string()\n .refine((v) => {\n const url = decodeURIComponent(v);\n return z.url().safeParse(url).success;\n })\n .transform((v) => decodeURIComponent(v))\n .optional(),\n fbclid: z.string().optional(),\n});\n\nexport type CheckoutSearch = z.infer<typeof checkoutSearchSchema>;\n\nexport const checkoutValidationErrorCodeSchema = z.enum([\n \"missing_purchases\",\n \"invalid_redirect_hosts\",\n \"already_owned\",\n \"invalid_prices\",\n \"invalid_discount\",\n \"internal_server_error\",\n]);\n\nexport type CheckoutValidationErrorCode = z.infer<\n typeof checkoutValidationErrorCodeSchema\n>;\n\nexport type CheckoutValidationError = {\n code: CheckoutValidationErrorCode;\n message: string;\n};\n","import { z } from \"zod\";\nimport type { PaddlePriceCustomData } from \"./catalog\";\n\nexport const createPromoInputSchema = z.object({\n slug: z\n .string()\n .min(1)\n .max(64)\n .regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),\n productId: z.string().min(1),\n discountPercent: z.number().int().min(1).max(100),\n startsAt: z.coerce.date(),\n endsAt: z.coerce.date(),\n});\n\nexport type CreatePromoInput = z.infer<typeof createPromoInputSchema>;\n\nexport const updatePromoInputSchema = createPromoInputSchema.extend({\n id: z.string().min(1),\n});\n\nexport type UpdatePromoInput = z.infer<typeof updatePromoInputSchema>;\n\nexport const deletePromoInputSchema = z.object({\n id: z.string().min(1),\n});\n\nexport type DeletePromoInput = z.infer<typeof deletePromoInputSchema>;\n\nexport const promoListItemSchema = z.object({\n id: z.string(),\n slug: z.string(),\n productId: z.string(),\n discountPercent: z.number(),\n startsAt: z.coerce.date(),\n endsAt: z.coerce.date(),\n shortLinkUrl: z.string(),\n promoPageUrl: z.string(),\n createdAt: z.coerce.date(),\n});\n\nexport type PromoListItem = z.infer<typeof promoListItemSchema>;\n\nexport const promoProductSelectPricePreviewSchema = z.object({\n currencyCode: z.string(),\n originalAmount: z.string(),\n originalFormatted: z.string(),\n});\n\nexport type PromoProductSelectPricePreview = z.infer<\n typeof promoProductSelectPricePreviewSchema\n>;\n\nexport const promoProductSelectPriceSchema = z.object({\n id: z.string(),\n name: z.string().nullable(),\n description: z.string().nullable(),\n customData: z.custom<PaddlePriceCustomData | null>(\n (val) => val === null || typeof val === \"object\",\n ).nullable(),\n billingCycle: z\n .object({\n interval: z.enum([\"day\", \"week\", \"month\", \"year\"]),\n frequency: z.number(),\n })\n .nullable(),\n unitPrice: z\n .object({\n amount: z.string(),\n currencyCode: z.string(),\n })\n .nullable(),\n unitPriceOverrides: z\n .array(\n z.object({\n countryCodes: z.array(z.string()),\n unitPrice: z.object({\n amount: z.string(),\n currencyCode: z.string(),\n }),\n }),\n )\n .nullable(),\n owned: z.boolean(),\n preview: promoProductSelectPricePreviewSchema.optional(),\n});\n\nexport const promoProductSelectSchema = z.object({\n slug: z.string(),\n productId: z.string(),\n productName: z.string(),\n productDescription: z.string().nullable(),\n discountPercent: z.number(),\n isActive: z.boolean(),\n alreadyRedeemed: z.boolean(),\n prices: z.array(promoProductSelectPriceSchema),\n});\n\nexport type PromoProductSelect = z.infer<typeof promoProductSelectSchema>;\n\nexport const createPromoCheckoutDiscountResponseSchema = z.object({\n discountCode: z.string(),\n checkoutUrl: z.string(),\n});\n\nexport type CreatePromoCheckoutDiscountResponse = z.infer<\n typeof createPromoCheckoutDiscountResponseSchema\n>;\n\nexport const createPromoCheckoutDiscountInputSchema = z.object({\n slug: z.string().min(1),\n priceId: z.string().min(1),\n});\n","import { z } from \"zod\";\nimport { promoProductSelectPriceSchema } from \"./promo\";\n\nexport const affiliateProductSelectSchema = z.object({\n productId: z.string(),\n productName: z.string(),\n productDescription: z.string().nullable(),\n discountPercent: z.number(),\n valid: z.boolean(),\n prices: z.array(promoProductSelectPriceSchema),\n});\n\nexport type AffiliateProductSelect = z.infer<typeof affiliateProductSelectSchema>;\n\nexport const createAffiliateCheckoutDiscountInputSchema = z.object({\n productId: z.string().min(1),\n priceId: z.string().min(1),\n ref: z.string().min(1),\n});\n\nexport type CreateAffiliateCheckoutDiscountInput = z.infer<\n typeof createAffiliateCheckoutDiscountInputSchema\n>;\n\nexport const createAffiliateCheckoutDiscountResponseSchema = z.object({\n discountCode: z.string(),\n checkoutUrl: z.string(),\n});\n\nexport type CreateAffiliateCheckoutDiscountResponse = z.infer<\n typeof createAffiliateCheckoutDiscountResponseSchema\n>;\n","import { z } from \"zod\";\n\nexport const metaEventNameSchema = z.enum([\n \"ViewContent\",\n \"InitiateCheckout\",\n \"Purchase\",\n]);\n\nexport type MetaEventName = z.infer<typeof metaEventNameSchema>;\n\n/** Client-callable events (Purchase is server/webhook-only). */\nexport const metaTrackEventNameSchema = z.enum([\n \"ViewContent\",\n \"InitiateCheckout\",\n]);\n\nexport type MetaTrackEventName = z.infer<typeof metaTrackEventNameSchema>;\n\nexport const metaTrackEventSchema = z.object({\n event_name: metaTrackEventNameSchema,\n content_ids: z.array(z.string()).optional(),\n content_type: z.string().optional(),\n event_source_url: z.string().url().optional(),\n value: z.number().optional(),\n currency: z.string().optional(),\n event_id: z.string().optional(),\n});\n\nexport type MetaTrackEventInput = z.infer<typeof metaTrackEventSchema>;\n\nexport type MetaAttributionCookies = {\n fbc?: string;\n fbp?: string;\n};\n\nexport function parseMetaAttributionFromCookieHeader(\n cookieHeader: string | undefined,\n): MetaAttributionCookies {\n if (!cookieHeader) return {};\n const cookies: Record<string, string> = {};\n for (const part of cookieHeader.split(\";\")) {\n const trimmed = part.trim();\n if (!trimmed) continue;\n const separator = trimmed.indexOf(\"=\");\n if (separator === -1) continue;\n const key = trimmed.slice(0, separator);\n const value = trimmed.slice(separator + 1);\n cookies[key] = decodeURIComponent(value);\n }\n return {\n fbc: cookies._fbc,\n fbp: cookies._fbp,\n };\n}\n\nexport function buildFbcFromFbclid(\n fbclid: string,\n seenAtMs = Date.now(),\n): string {\n return `fb.1.${seenAtMs}.${fbclid}`;\n}\n","const FBC_COOKIE = \"_fbc\";\nconst FBP_COOKIE = \"_fbp\";\nconst COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 90;\n\nexport type { MetaAttributionCookies } from \"@us-auth/types\";\nexport {\n buildFbcFromFbclid,\n parseMetaAttributionFromCookieHeader,\n} from \"@us-auth/types\";\nimport type { MetaAttributionCookies } from \"@us-auth/types\";\nimport { buildFbcFromFbclid } from \"@us-auth/types\";\n\nfunction randomId(): string {\n return Math.floor(Math.random() * 1e10).toString();\n}\n\nexport function getMetaCookieDomain(frontendUrl: string): string | undefined {\n const hostname = new URL(frontendUrl).hostname;\n if (hostname === \"localhost\" || hostname === \"127.0.0.1\") {\n return undefined;\n }\n return `.${hostname}`;\n}\n\nfunction readCookie(name: string): string | undefined {\n if (typeof document === \"undefined\") return undefined;\n const match = document.cookie\n .split(\";\")\n .map((part) => part.trim())\n .find((part) => part.startsWith(`${name}=`));\n if (!match) return undefined;\n return decodeURIComponent(match.slice(name.length + 1));\n}\n\nfunction writeCookie(\n name: string,\n value: string,\n frontendUrl: string,\n): void {\n if (typeof document === \"undefined\") return;\n const domain = getMetaCookieDomain(frontendUrl);\n const parts = [\n `${name}=${encodeURIComponent(value)}`,\n \"Path=/\",\n \"Secure\",\n \"SameSite=Lax\",\n `Max-Age=${COOKIE_MAX_AGE_SECONDS}`,\n ];\n if (domain) {\n parts.push(`Domain=${domain}`);\n }\n document.cookie = parts.join(\"; \");\n}\n\nexport function readMetaAttributionCookies(): MetaAttributionCookies {\n return {\n fbc: readCookie(FBC_COOKIE),\n fbp: readCookie(FBP_COOKIE),\n };\n}\n\nexport function captureMetaClickId(options: {\n frontendUrl: string;\n stripFbclidFromUrl?: boolean;\n}): MetaAttributionCookies {\n if (typeof window === \"undefined\") {\n return {};\n }\n\n const { frontendUrl, stripFbclidFromUrl = true } = options;\n const params = new URLSearchParams(window.location.search);\n const fbclid = params.get(\"fbclid\");\n\n if (fbclid) {\n writeCookie(FBC_COOKIE, buildFbcFromFbclid(fbclid), frontendUrl);\n if (stripFbclidFromUrl) {\n params.delete(\"fbclid\");\n const query = params.toString();\n const nextUrl = `${window.location.pathname}${query ? `?${query}` : \"\"}${window.location.hash}`;\n window.history.replaceState({}, \"\", nextUrl);\n }\n }\n\n let fbp = readCookie(FBP_COOKIE);\n if (!fbp) {\n fbp = `fb.1.${Date.now()}.${randomId()}`;\n writeCookie(FBP_COOKIE, fbp, frontendUrl);\n }\n\n return readMetaAttributionCookies();\n}\n","import {\n magicLinkClient,\n emailOTPClient,\n anonymousClient,\n} from \"better-auth/client/plugins\";\nimport { passkeyClient } from \"@better-auth/passkey/client\";\nimport { createAuthClient } from \"better-auth/client\";\nimport { hc } from \"hono/client\";\nimport type { AppRouter } from \"@us-auth/api/routers\";\nimport type {\n UserPurchases,\n Session,\n RedirectIntent,\n MetaTrackEventInput,\n} from \"@us-auth/types\";\nimport {\n readMetaAttributionCookies,\n type MetaAttributionCookies,\n} from \"./metaAttribution\";\n\nexport class AuthClient {\n #frontendUrl: string;\n #authClient;\n #appClient: ReturnType<typeof hc<AppRouter>>;\n #cookie: string | undefined;\n\n constructor(apiUrl: string, frontendUrl: string, cookie?: string) {\n this.#cookie = cookie;\n this.#frontendUrl = frontendUrl;\n this.#authClient = createAuthClient({\n baseURL: apiUrl,\n plugins: [\n anonymousClient(),\n magicLinkClient(),\n emailOTPClient(),\n passkeyClient(),\n ],\n });\n this.#appClient = hc<AppRouter>(new URL(\"/api/app\", apiUrl).toString(), {\n fetch: (url: any, init: any) =>\n fetch(url, {\n ...init,\n credentials: \"include\",\n }),\n });\n }\n\n // Authentication\n getSession = async (): Promise<Session | null> => {\n const { data, error } = await this.#authClient.getSession(\n {},\n {\n headers: this.#cookie\n ? {\n Cookie: this.#cookie,\n }\n : undefined,\n },\n );\n if (error) throw error;\n return data;\n };\n\n signInAnonymously = async (): Promise<Session | null> => {\n const { error } = await this.#authClient.signIn.anonymous();\n if (error) throw error;\n return this.getSession();\n };\n\n signOut = async (onSuccess?: () => void): Promise<void> => {\n const { error } = await this.#authClient.signOut(\n {\n fetchOptions: { onSuccess },\n },\n {\n headers: this.#cookie ? { Cookie: this.#cookie } : undefined,\n },\n );\n if (error) throw error;\n return;\n };\n\n // Purchases\n getPurchases = async (): Promise<UserPurchases | null> => {\n const res = await this.#appClient.purchases.$get(undefined, {\n headers: this.#cookie ? { Cookie: this.#cookie } : undefined,\n });\n if (!res.ok) {\n throw new Error(\"Failed to get purchases\", {\n cause: await res.text(),\n });\n }\n const data = await res.json();\n return data as UserPurchases | null;\n };\n\n #getRedirectIntent = (redirectUrl: string, appName?: string) => {\n return JSON.stringify({\n type: \"redirect\",\n redirectUrl,\n appName,\n } satisfies RedirectIntent);\n };\n\n // Meta CAPI attribution (no PII)\n trackMetaEvent = async (payload: MetaTrackEventInput): Promise<void> => {\n const res = await this.#appClient.meta.events.$post({\n json: payload,\n });\n if (!res.ok) {\n throw new Error(\"Failed to track Meta event\", {\n cause: await res.text(),\n });\n }\n };\n\n trackViewContent = async (options: {\n contentIds: string[];\n contentType?: string;\n eventSourceUrl?: string;\n }): Promise<void> => {\n const eventSourceUrl =\n options.eventSourceUrl ??\n (typeof window !== \"undefined\" ? window.location.href : undefined);\n await this.trackMetaEvent({\n event_name: \"ViewContent\",\n content_ids: options.contentIds,\n content_type: options.contentType ?? \"product\",\n ...(eventSourceUrl ? { event_source_url: eventSourceUrl } : {}),\n });\n };\n\n getMetaAttribution = (): MetaAttributionCookies => {\n return readMetaAttributionCookies();\n };\n\n // Utils\n getLoginUrl = (options?: { redirectUrl?: string; appName?: string }) => {\n const url = new URL(\"/login\", this.#frontendUrl);\n if (options?.redirectUrl) {\n url.searchParams.set(\n \"intent\",\n this.#getRedirectIntent(options.redirectUrl, options.appName),\n );\n }\n return url.toString();\n };\n\n getCheckoutUrl = (options: {\n priceId: string;\n productId: string;\n discountCode?: string;\n successUrl?: string;\n quantity?: number;\n }) => {\n const url = new URL(\"/auth/checkout\", this.#frontendUrl);\n url.searchParams.set(\"priceId\", options.priceId);\n url.searchParams.set(\"productId\", options.productId);\n if (options.discountCode) {\n url.searchParams.set(\"discountCode\", options.discountCode);\n }\n if (options.successUrl) {\n url.searchParams.set(\"successUrl\", options.successUrl);\n }\n url.searchParams.set(\"quantity\", options.quantity?.toString() ?? \"1\");\n return url.toString();\n };\n}\n","import { createContext } from \"react\";\nimport type { UserPurchases, Session } from \"@us-auth/types\";\nimport type { AuthClient } from \"../AuthClient\";\n\nexport type AuthContextType = {\n session: Session | null;\n isSessionFetching: boolean;\n refetchSession: () => Promise<void>;\n purchases: UserPurchases | null;\n isPurchasesFetching: boolean;\n refetchPurchases: () => Promise<void>;\n signOut: AuthClient[\"signOut\"];\n getLoginUrl: AuthClient[\"getLoginUrl\"];\n getCheckoutUrl: AuthClient[\"getCheckoutUrl\"];\n trackMetaEvent: AuthClient[\"trackMetaEvent\"];\n trackViewContent: AuthClient[\"trackViewContent\"];\n getMetaAttribution: AuthClient[\"getMetaAttribution\"];\n isPurchased: (priceIds: string[]) => boolean;\n isSubscribed: (priceIds: string[], productId: string) => boolean;\n isLoggedIn: boolean;\n} | null;\n\nexport const AuthContext = createContext<AuthContextType>(null);\n","import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n type PropsWithChildren,\n} from \"react\";\nimport { AuthContext } from \"./AuthContext\";\nimport { AuthClient } from \"../AuthClient\";\nimport type { Session, UserPurchases } from \"@us-auth/types\";\nimport { QueryClient, useQuery } from \"@tanstack/react-query\";\nimport { usePostHog } from \"@posthog/react\";\nimport { captureMetaClickId } from \"../metaAttribution\";\n\nexport interface AuthProviderProps extends PropsWithChildren {\n authClient?: AuthClient;\n queryClient?: QueryClient;\n baseUrl: string;\n frontendUrl: string;\n initialSession?: Session | null;\n initialPurchases?: UserPurchases | null;\n}\n\nexport const AuthProvider = ({\n children,\n baseUrl,\n frontendUrl,\n initialSession,\n initialPurchases,\n authClient: providedAuthClient,\n queryClient: providedQueryClient,\n}: AuthProviderProps) => {\n const ph = usePostHog();\n\n const authClient = useMemo(\n () =>\n providedAuthClient ?? new AuthClient(baseUrl, frontendUrl),\n [baseUrl, frontendUrl, providedAuthClient],\n );\n const queryClient = useMemo(\n () => providedQueryClient ?? new QueryClient(),\n [providedQueryClient],\n );\n\n const {\n data: session,\n isFetching: isSessionFetching,\n refetch: refetchSession,\n } = useQuery(\n {\n queryKey: [\"us-auth-session\"],\n staleTime: 0,\n initialData: initialSession,\n queryFn: authClient.getSession,\n },\n queryClient,\n );\n\n const isLoggedIn = useMemo(() => {\n if (!session || session.user.isAnonymous) return false;\n return true;\n }, [session]);\n\n const anonymousSignInAttempted = useRef(false);\n\n useEffect(() => {\n captureMetaClickId({ frontendUrl });\n }, [frontendUrl]);\n\n // Log unauthenticated users in anonymously automatically\n useEffect(() => {\n if (isSessionFetching) return;\n // Wait for the session query to settle to an explicit null, not undefined.\n if (session !== null) return;\n if (anonymousSignInAttempted.current) return;\n\n anonymousSignInAttempted.current = true;\n authClient\n .signInAnonymously()\n .then((newSession) => {\n queryClient.setQueryData([\"us-auth-session\"], newSession);\n })\n .catch((e) => console.error(e));\n }, [authClient, isSessionFetching, queryClient, session]);\n\n useEffect(() => {\n if (session?.user && ph) {\n const distinctId = ph.get_distinct_id();\n if (distinctId !== session.user.id) {\n ph.identify(session.user.id, {\n email: session.user.email,\n });\n }\n }\n }, [session, ph]);\n\n const {\n data: purchases,\n isFetching: isPurchasesFetching,\n refetch: refetchPurchases,\n } = useQuery(\n {\n queryKey: [\"us-auth-purchases\"],\n staleTime: 1000 * 60,\n initialData: initialPurchases,\n queryFn: authClient.getPurchases,\n },\n queryClient,\n );\n\n const getLoginUrl = useMemo(() => authClient.getLoginUrl, [authClient]);\n const getCheckoutUrl = useMemo(() => authClient.getCheckoutUrl, [authClient]);\n const signOut = useCallback(\n (onSuccess?: () => void) =>\n authClient.signOut(() => {\n ph?.reset();\n onSuccess?.();\n }),\n [authClient, ph],\n );\n const trackMetaEvent = useMemo(() => authClient.trackMetaEvent, [authClient]);\n const trackViewContent = useMemo(\n () => authClient.trackViewContent,\n [authClient],\n );\n const getMetaAttribution = useMemo(\n () => authClient.getMetaAttribution,\n [authClient],\n );\n\n const isPurchased = useCallback(\n (priceIds: string[]): boolean => {\n if (!purchases) return false;\n return purchases.paddle.transactions.some(\n (tra) =>\n tra.items.some((item) => priceIds.includes(item)) &&\n !tra.adjustments.some(\n (adj) => adj.status === \"approved\" && adj.action === \"refund\",\n ),\n );\n },\n [purchases],\n );\n\n const isSubscribed = useCallback(\n (priceIds: string[], productId: string): boolean => {\n if (!purchases) return false;\n\n const paddleSubscriptions = purchases.paddle.subscriptions.some(\n (sub) =>\n sub.items.some(\n (item) =>\n priceIds.includes(item.priceId) || productId === item.productId,\n ) && sub.status === \"active\",\n );\n\n const stripeSubscriptions = purchases.stripe.some(\n (sub) =>\n sub.status === \"active\" &&\n sub.items.some((item) => priceIds.includes(item)),\n );\n\n return paddleSubscriptions || stripeSubscriptions;\n },\n [purchases],\n );\n\n return (\n <AuthContext.Provider\n value={{\n session: session ?? null,\n isSessionFetching,\n refetchSession: async () => {\n await refetchSession();\n },\n purchases: purchases ?? null,\n isPurchasesFetching,\n refetchPurchases: async () => {\n await refetchPurchases();\n },\n signOut,\n getLoginUrl,\n getCheckoutUrl,\n trackMetaEvent,\n trackViewContent,\n getMetaAttribution,\n isSubscribed,\n isPurchased,\n isLoggedIn,\n }}\n >\n {children}\n </AuthContext.Provider>\n );\n};\n","import { useContext } from \"react\";\nimport { AuthContext } from \"./AuthContext\";\n\nexport function useAuth() {\n const ctx = useContext(AuthContext);\n if (!ctx) {\n throw new Error(\"useAuth must be used within an AuthProvider\");\n }\n return ctx;\n}\n"],"mappings":"shBAEA,MAAM,EAA2B,EAAE,OAAO,CACxC,GAAI,EAAE,QAAQ,CACd,UAAW,EAAE,OAAO,MAAM,CAC1B,OAAQ,EAAE,QAAQ,CAClB,MAAO,EAAE,MACP,EA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AAW,EAAY,CACnC,GAAI,CAAC,EACH,MAAU,MAAM,8CAA8C,CAEhE,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,21 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uninspired/auth-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "Auth client for Uninspired Studio Products",
|
|
5
5
|
"author": "Chris Kolb <chris@uninspired.studio>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"
|
|
9
|
-
"types": "dist/index.d.ts",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
10
9
|
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
11
17
|
"files": [
|
|
12
18
|
"package.json",
|
|
13
19
|
"dist"
|
|
14
20
|
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
15
33
|
"scripts": {
|
|
16
34
|
"build": "tsdown --config tsdown.config.ts",
|
|
17
|
-
"check": "tsc
|
|
18
|
-
"lint": "eslint ."
|
|
35
|
+
"check": "tsc --noEmit",
|
|
36
|
+
"lint": "eslint .",
|
|
37
|
+
"prepack": "bun run build && node ../../scripts/apply-publish-config.mjs apply",
|
|
38
|
+
"postpack": "node ../../scripts/apply-publish-config.mjs restore"
|
|
19
39
|
},
|
|
20
40
|
"devDependencies": {
|
|
21
41
|
"@us-auth/types": "workspace:*",
|
|
@@ -39,5 +59,6 @@
|
|
|
39
59
|
"better-auth": "^1.5.5",
|
|
40
60
|
"hono": "^4.12.7",
|
|
41
61
|
"zod": "^4.3.6"
|
|
42
|
-
}
|
|
62
|
+
},
|
|
63
|
+
"module": "./dist/index.js"
|
|
43
64
|
}
|
package/dist/AuthClient.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { UserPurchases } from "./types/src/purchases.js";
|
|
2
|
-
import { Session } from "./types/src/session.js";
|
|
3
|
-
import { MetaAttributionCookies, MetaTrackEventInput } from "./types/src/meta.js";
|
|
4
|
-
//#region src/AuthClient.d.ts
|
|
5
|
-
declare class AuthClient {
|
|
6
|
-
#private;
|
|
7
|
-
constructor(apiUrl: string, frontendUrl: string, cookie?: string, mailingListPublicKey?: string);
|
|
8
|
-
getSession: () => Promise<Session | null>;
|
|
9
|
-
signInAnonymously: () => Promise<Session | null>;
|
|
10
|
-
signOut: (onSuccess?: () => void) => Promise<void>;
|
|
11
|
-
getPurchases: () => Promise<UserPurchases | null>;
|
|
12
|
-
newsletterSubscribe: (email: string, userGroup?: string, callbackUrl?: string) => Promise<void>;
|
|
13
|
-
newsletterUnsubscribe: (email: string) => Promise<void>;
|
|
14
|
-
trackMetaEvent: (payload: MetaTrackEventInput) => Promise<void>;
|
|
15
|
-
trackViewContent: (options: {
|
|
16
|
-
contentIds: string[];
|
|
17
|
-
contentType?: string;
|
|
18
|
-
eventSourceUrl?: string;
|
|
19
|
-
}) => Promise<void>;
|
|
20
|
-
getMetaAttribution: () => MetaAttributionCookies;
|
|
21
|
-
getLoginUrl: (options?: {
|
|
22
|
-
redirectUrl?: string;
|
|
23
|
-
appName?: string;
|
|
24
|
-
}) => string;
|
|
25
|
-
getCheckoutUrl: (options: {
|
|
26
|
-
priceId: string;
|
|
27
|
-
productId: string;
|
|
28
|
-
discountCode?: string;
|
|
29
|
-
successUrl?: string;
|
|
30
|
-
quantity?: number;
|
|
31
|
-
}) => string;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
export { AuthClient };
|
|
35
|
-
//# sourceMappingURL=AuthClient.d.ts.map
|
package/dist/AuthClient.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{readMetaAttributionCookies as e}from"./metaAttribution.js";import{anonymousClient as t,emailOTPClient as n,magicLinkClient as r}from"better-auth/client/plugins";import{passkeyClient as i}from"@better-auth/passkey/client";import{createAuthClient as a}from"better-auth/client";import{hc as o}from"hono/client";var s=class{#e;#t;#n;#r;#i;constructor(e,s,c,l){this.#i=c,this.#e=s,this.#t=a({baseURL:e,plugins:[t(),r(),n(),i()]}),this.#n=o(new URL(`/api/app`,e).toString(),{fetch:(e,t)=>fetch(e,{...t,credentials:`include`})}),this.#r=o(new URL(`/api/mailing-list`,e).toString(),{fetch:(e,t)=>fetch(e,{...t,headers:{"Content-Type":`application/json`,"X-Public-Key":l,...t.headers}})})}getSession=async()=>{let{data:e,error:t}=await this.#t.getSession({},{headers:this.#i?{Cookie:this.#i}:void 0});if(t)throw t;return e};signInAnonymously=async()=>{let{error:e}=await this.#t.signIn.anonymous();if(e)throw e;return this.getSession()};signOut=async e=>{let{error:t}=await this.#t.signOut({fetchOptions:{onSuccess:e}},{headers:this.#i?{Cookie:this.#i}:void 0});if(t)throw t};getPurchases=async()=>{let e=await this.#n.purchases.$get(void 0,{headers:this.#i?{Cookie:this.#i}:void 0});if(!e.ok)throw Error(`Failed to get purchases`,{cause:await e.text()});return await e.json()};#a=(e,t)=>JSON.stringify({type:`redirect`,redirectUrl:e,appName:t});newsletterSubscribe=async(e,t,n)=>{let r=await this.#r.subscribe.$post({json:{email:e,userGroup:t??`us-auth`,callbackUrl:n??``}});if(!r.ok)throw Error(await r.text())};newsletterUnsubscribe=async e=>{let t=await this.#r.unsubscribe.$post({query:{email:e}});if(!t.ok)throw Error(await t.text())};trackMetaEvent=async e=>{let t=await this.#n.meta.events.$post({json:e});if(!t.ok)throw Error(`Failed to track Meta event`,{cause:await t.text()})};trackViewContent=async e=>{let t=e.eventSourceUrl??(typeof window<`u`?window.location.href:void 0);await this.trackMetaEvent({event_name:`ViewContent`,content_ids:e.contentIds,content_type:e.contentType??`product`,...t?{event_source_url:t}:{}})};getMetaAttribution=()=>e();getLoginUrl=e=>{let t=new URL(`/login`,this.#e);return e?.redirectUrl&&t.searchParams.set(`intent`,this.#a(e.redirectUrl,e.appName)),t.toString()};getCheckoutUrl=e=>{let t=new URL(`/auth/checkout`,this.#e);return t.searchParams.set(`priceId`,e.priceId),t.searchParams.set(`productId`,e.productId),e.discountCode&&t.searchParams.set(`discountCode`,e.discountCode),e.successUrl&&t.searchParams.set(`successUrl`,e.successUrl),t.searchParams.set(`quantity`,e.quantity?.toString()??`1`),t.toString()}};export{s as AuthClient};
|
|
2
|
-
//# sourceMappingURL=AuthClient.js.map
|
package/dist/AuthClient.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthClient.js","names":["#cookie","#frontendUrl","#authClient","#appClient","#mailingListClient","#getRedirectIntent"],"sources":["../src/AuthClient.ts"],"sourcesContent":["import {\n magicLinkClient,\n emailOTPClient,\n anonymousClient,\n} from \"better-auth/client/plugins\";\nimport { passkeyClient } from \"@better-auth/passkey/client\";\nimport { createAuthClient } from \"better-auth/client\";\nimport { hc } from \"hono/client\";\nimport type { AppRouter, MailingListRouter } from \"@us-auth/api\";\nimport type {\n UserPurchases,\n Session,\n RedirectIntent,\n MetaTrackEventInput,\n} from \"@us-auth/types\";\nimport {\n readMetaAttributionCookies,\n type MetaAttributionCookies,\n} from \"./metaAttribution\";\n\nexport class AuthClient {\n #frontendUrl: string;\n #authClient;\n #appClient: ReturnType<typeof hc<AppRouter>>;\n #mailingListClient: ReturnType<typeof hc<MailingListRouter>>;\n #cookie: string | undefined;\n\n constructor(\n apiUrl: string,\n frontendUrl: string,\n cookie?: string,\n mailingListPublicKey?: string,\n ) {\n this.#cookie = cookie;\n this.#frontendUrl = frontendUrl;\n this.#authClient = createAuthClient({\n baseURL: apiUrl,\n plugins: [\n anonymousClient(),\n magicLinkClient(),\n emailOTPClient(),\n passkeyClient(),\n ],\n });\n this.#appClient = hc<AppRouter>(new URL(\"/api/app\", apiUrl).toString(), {\n fetch: (url: any, init: any) =>\n fetch(url, {\n ...init,\n credentials: \"include\",\n }),\n });\n this.#mailingListClient = hc<MailingListRouter>(\n new URL(\"/api/mailing-list\", apiUrl).toString(),\n {\n fetch: (url: any, init: any) =>\n fetch(url, {\n ...init,\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-Public-Key\": mailingListPublicKey,\n ...init.headers,\n },\n }),\n },\n );\n }\n\n // Authentication\n getSession = async (): Promise<Session | null> => {\n const { data, error } = await this.#authClient.getSession(\n {},\n {\n headers: this.#cookie\n ? {\n Cookie: this.#cookie,\n }\n : undefined,\n },\n );\n if (error) throw error;\n return data;\n };\n\n signInAnonymously = async (): Promise<Session | null> => {\n const { error } = await this.#authClient.signIn.anonymous();\n if (error) throw error;\n return this.getSession();\n };\n\n signOut = async (onSuccess?: () => void): Promise<void> => {\n const { error } = await this.#authClient.signOut(\n {\n fetchOptions: { onSuccess },\n },\n {\n headers: this.#cookie ? { Cookie: this.#cookie } : undefined,\n },\n );\n if (error) throw error;\n return;\n };\n\n // Purchases\n getPurchases = async (): Promise<UserPurchases | null> => {\n const res = await this.#appClient.purchases.$get(undefined, {\n headers: this.#cookie ? { Cookie: this.#cookie } : undefined,\n });\n if (!res.ok) {\n throw new Error(\"Failed to get purchases\", {\n cause: await res.text(),\n });\n }\n const data = await res.json();\n return data as UserPurchases | null;\n };\n\n #getRedirectIntent = (redirectUrl: string, appName?: string) => {\n return JSON.stringify({\n type: \"redirect\",\n redirectUrl,\n appName,\n } satisfies RedirectIntent);\n };\n\n // Mailing List\n newsletterSubscribe = async (\n email: string,\n userGroup?: string,\n callbackUrl?: string,\n ): Promise<void> => {\n const res = await this.#mailingListClient.subscribe.$post({\n json: {\n email,\n userGroup: userGroup ?? \"us-auth\",\n callbackUrl: callbackUrl ?? \"\",\n },\n });\n if (!res.ok) {\n throw new Error(await res.text());\n }\n return;\n };\n\n newsletterUnsubscribe = async (email: string): Promise<void> => {\n const res = await this.#mailingListClient.unsubscribe.$post({\n query: {\n email,\n },\n });\n if (!res.ok) {\n throw new Error(await res.text());\n }\n return;\n };\n\n // Meta CAPI attribution (no PII)\n trackMetaEvent = async (payload: MetaTrackEventInput): Promise<void> => {\n const res = await this.#appClient.meta.events.$post({\n json: payload,\n });\n if (!res.ok) {\n throw new Error(\"Failed to track Meta event\", {\n cause: await res.text(),\n });\n }\n };\n\n trackViewContent = async (options: {\n contentIds: string[];\n contentType?: string;\n eventSourceUrl?: string;\n }): Promise<void> => {\n const eventSourceUrl =\n options.eventSourceUrl ??\n (typeof window !== \"undefined\" ? window.location.href : undefined);\n await this.trackMetaEvent({\n event_name: \"ViewContent\",\n content_ids: options.contentIds,\n content_type: options.contentType ?? \"product\",\n ...(eventSourceUrl ? { event_source_url: eventSourceUrl } : {}),\n });\n };\n\n getMetaAttribution = (): MetaAttributionCookies => {\n return readMetaAttributionCookies();\n };\n\n // Utils\n getLoginUrl = (options?: { redirectUrl?: string; appName?: string }) => {\n const url = new URL(\"/login\", this.#frontendUrl);\n if (options?.redirectUrl) {\n url.searchParams.set(\n \"intent\",\n this.#getRedirectIntent(options.redirectUrl, options.appName),\n );\n }\n return url.toString();\n };\n\n getCheckoutUrl = (options: {\n priceId: string;\n productId: string;\n discountCode?: string;\n successUrl?: string;\n quantity?: number;\n }) => {\n const url = new URL(\"/auth/checkout\", this.#frontendUrl);\n url.searchParams.set(\"priceId\", options.priceId);\n url.searchParams.set(\"productId\", options.productId);\n if (options.discountCode) {\n url.searchParams.set(\"discountCode\", options.discountCode);\n }\n if (options.successUrl) {\n url.searchParams.set(\"successUrl\", options.successUrl);\n }\n url.searchParams.set(\"quantity\", options.quantity?.toString() ?? \"1\");\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,EAAQ,YAAa,EAAQ,QAAQ,CAC9D,CAEI,EAAI,UAAU,EAGvB,eAAkB,GAMZ,CACJ,IAAM,EAAM,IAAI,IAAI,iBAAkB,MAAA,EAAkB,CAUxD,OATA,EAAI,aAAa,IAAI,UAAW,EAAQ,QAAQ,CAChD,EAAI,aAAa,IAAI,YAAa,EAAQ,UAAU,CAChD,EAAQ,cACV,EAAI,aAAa,IAAI,eAAgB,EAAQ,aAAa,CAExD,EAAQ,YACV,EAAI,aAAa,IAAI,aAAc,EAAQ,WAAW,CAExD,EAAI,aAAa,IAAI,WAAY,EAAQ,UAAU,UAAU,EAAI,IAAI,CAC9D,EAAI,UAAU"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { MetaAttributionCookies, buildFbcFromFbclid, parseMetaAttributionFromCookieHeader } from "./types/src/meta.js";
|
|
2
|
-
//#region src/metaAttribution.d.ts
|
|
3
|
-
declare function getMetaCookieDomain(frontendUrl: string): string | undefined;
|
|
4
|
-
declare function readMetaAttributionCookies(): MetaAttributionCookies;
|
|
5
|
-
declare function captureMetaClickId(options: {
|
|
6
|
-
frontendUrl: string;
|
|
7
|
-
stripFbclidFromUrl?: boolean;
|
|
8
|
-
}): MetaAttributionCookies;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { captureMetaClickId, getMetaCookieDomain, readMetaAttributionCookies };
|
|
11
|
-
//# sourceMappingURL=metaAttribution.d.ts.map
|
package/dist/metaAttribution.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{buildFbcFromFbclid as e,buildFbcFromFbclid as t,parseMetaAttributionFromCookieHeader as n}from"@us-auth/types";const r=`_fbc`,i=`_fbp`;function a(){return Math.floor(Math.random()*1e10).toString()}function o(e){let t=new URL(e).hostname;if(!(t===`localhost`||t===`127.0.0.1`))return`.${t}`}function s(e){if(typeof document>`u`)return;let t=document.cookie.split(`;`).map(e=>e.trim()).find(t=>t.startsWith(`${e}=`));if(t)return decodeURIComponent(t.slice(e.length+1))}function c(e,t,n){if(typeof document>`u`)return;let r=o(n),i=[`${e}=${encodeURIComponent(t)}`,`Path=/`,`Secure`,`SameSite=Lax`,`Max-Age=7776000`];r&&i.push(`Domain=${r}`),document.cookie=i.join(`; `)}function l(){return{fbc:s(r),fbp:s(i)}}function u(t){if(typeof window>`u`)return{};let{frontendUrl:n,stripFbclidFromUrl:o=!0}=t,u=new URLSearchParams(window.location.search),d=u.get(`fbclid`);if(d&&(c(r,e(d),n),o)){u.delete(`fbclid`);let e=u.toString(),t=`${window.location.pathname}${e?`?${e}`:``}${window.location.hash}`;window.history.replaceState({},``,t)}let f=s(i);return f||(f=`fb.1.${Date.now()}.${a()}`,c(i,f,n)),l()}export{t as buildFbcFromFbclid,u as captureMetaClickId,o as getMetaCookieDomain,n as parseMetaAttributionFromCookieHeader,l as readMetaAttributionCookies};
|
|
2
|
-
//# sourceMappingURL=metaAttribution.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metaAttribution.js","names":[],"sources":["../src/metaAttribution.ts"],"sourcesContent":["const FBC_COOKIE = \"_fbc\";\nconst FBP_COOKIE = \"_fbp\";\nconst COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 90;\n\nexport type { MetaAttributionCookies } from \"@us-auth/types\";\nexport {\n buildFbcFromFbclid,\n parseMetaAttributionFromCookieHeader,\n} from \"@us-auth/types\";\nimport type { MetaAttributionCookies } from \"@us-auth/types\";\nimport { buildFbcFromFbclid } from \"@us-auth/types\";\n\nfunction randomId(): string {\n return Math.floor(Math.random() * 1e10).toString();\n}\n\nexport function getMetaCookieDomain(frontendUrl: string): string | undefined {\n const hostname = new URL(frontendUrl).hostname;\n if (hostname === \"localhost\" || hostname === \"127.0.0.1\") {\n return undefined;\n }\n return `.${hostname}`;\n}\n\nfunction readCookie(name: string): string | undefined {\n if (typeof document === \"undefined\") return undefined;\n const match = document.cookie\n .split(\";\")\n .map((part) => part.trim())\n .find((part) => part.startsWith(`${name}=`));\n if (!match) return undefined;\n return decodeURIComponent(match.slice(name.length + 1));\n}\n\nfunction writeCookie(\n name: string,\n value: string,\n frontendUrl: string,\n): void {\n if (typeof document === \"undefined\") return;\n const domain = getMetaCookieDomain(frontendUrl);\n const parts = [\n `${name}=${encodeURIComponent(value)}`,\n \"Path=/\",\n \"Secure\",\n \"SameSite=Lax\",\n `Max-Age=${COOKIE_MAX_AGE_SECONDS}`,\n ];\n if (domain) {\n parts.push(`Domain=${domain}`);\n }\n document.cookie = parts.join(\"; \");\n}\n\nexport function readMetaAttributionCookies(): MetaAttributionCookies {\n return {\n fbc: readCookie(FBC_COOKIE),\n fbp: readCookie(FBP_COOKIE),\n };\n}\n\nexport function captureMetaClickId(options: {\n frontendUrl: string;\n stripFbclidFromUrl?: boolean;\n}): MetaAttributionCookies {\n if (typeof window === \"undefined\") {\n return {};\n }\n\n const { frontendUrl, stripFbclidFromUrl = true } = options;\n const params = new URLSearchParams(window.location.search);\n const fbclid = params.get(\"fbclid\");\n\n if (fbclid) {\n writeCookie(FBC_COOKIE, buildFbcFromFbclid(fbclid), frontendUrl);\n if (stripFbclidFromUrl) {\n params.delete(\"fbclid\");\n const query = params.toString();\n const nextUrl = `${window.location.pathname}${query ? `?${query}` : \"\"}${window.location.hash}`;\n window.history.replaceState({}, \"\", nextUrl);\n }\n }\n\n let fbp = readCookie(FBP_COOKIE);\n if (!fbp) {\n fbp = `fb.1.${Date.now()}.${randomId()}`;\n writeCookie(FBP_COOKIE, fbp, frontendUrl);\n }\n\n return readMetaAttributionCookies();\n}\n"],"mappings":"sHAAA,MAAM,EAAa,OACb,EAAa,OAWnB,SAAS,GAAmB,CAC1B,OAAO,KAAK,MAAM,KAAK,QAAQ,CAAG,KAAK,CAAC,UAAU,CAGpD,SAAgB,EAAoB,EAAyC,CAC3E,IAAM,EAAW,IAAI,IAAI,EAAY,CAAC,SAClC,SAAa,aAAe,IAAa,aAG7C,MAAO,IAAI,IAGb,SAAS,EAAW,EAAkC,CACpD,GAAI,OAAO,SAAa,IAAa,OACrC,IAAM,EAAQ,SAAS,OACpB,MAAM,IAAI,CACV,IAAK,GAAS,EAAK,MAAM,CAAC,CAC1B,KAAM,GAAS,EAAK,WAAW,GAAG,EAAK,GAAG,CAAC,CACzC,KACL,OAAO,mBAAmB,EAAM,MAAM,EAAK,OAAS,EAAE,CAAC,CAGzD,SAAS,EACP,EACA,EACA,EACM,CACN,GAAI,OAAO,SAAa,IAAa,OACrC,IAAM,EAAS,EAAoB,EAAY,CACzC,EAAQ,CACZ,GAAG,EAAK,GAAG,mBAAmB,EAAM,GACpC,SACA,SACA,eACA,kBACD,CACG,GACF,EAAM,KAAK,UAAU,IAAS,CAEhC,SAAS,OAAS,EAAM,KAAK,KAAK,CAGpC,SAAgB,GAAqD,CACnE,MAAO,CACL,IAAK,EAAW,EAAW,CAC3B,IAAK,EAAW,EAAW,CAC5B,CAGH,SAAgB,EAAmB,EAGR,CACzB,GAAI,OAAO,OAAW,IACpB,MAAO,EAAE,CAGX,GAAM,CAAE,cAAa,qBAAqB,IAAS,EAC7C,EAAS,IAAI,gBAAgB,OAAO,SAAS,OAAO,CACpD,EAAS,EAAO,IAAI,SAAS,CAEnC,GAAI,IACF,EAAY,EAAY,EAAmB,EAAO,CAAE,EAAY,CAC5D,GAAoB,CACtB,EAAO,OAAO,SAAS,CACvB,IAAM,EAAQ,EAAO,UAAU,CACzB,EAAU,GAAG,OAAO,SAAS,WAAW,EAAQ,IAAI,IAAU,KAAK,OAAO,SAAS,OACzF,OAAO,QAAQ,aAAa,EAAE,CAAE,GAAI,EAAQ,CAIhD,IAAI,EAAM,EAAW,EAAW,CAMhC,OALK,IACH,EAAM,QAAQ,KAAK,KAAK,CAAC,GAAG,GAAU,GACtC,EAAY,EAAY,EAAK,EAAY,EAGpC,GAA4B"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { UserPurchases } from "../types/src/purchases.js";
|
|
2
|
-
import { Session } from "../types/src/session.js";
|
|
3
|
-
import { AuthClient } from "../AuthClient.js";
|
|
4
|
-
import * as _$react from "react";
|
|
5
|
-
|
|
6
|
-
//#region src/react/AuthContext.d.ts
|
|
7
|
-
type AuthContextType = {
|
|
8
|
-
session: Session | null;
|
|
9
|
-
isSessionFetching: boolean;
|
|
10
|
-
refetchSession: () => Promise<void>;
|
|
11
|
-
purchases: UserPurchases | null;
|
|
12
|
-
isPurchasesFetching: boolean;
|
|
13
|
-
refetchPurchases: () => Promise<void>;
|
|
14
|
-
signOut: AuthClient["signOut"];
|
|
15
|
-
newsletterSubscribe: AuthClient["newsletterSubscribe"];
|
|
16
|
-
newsletterUnsubscribe: AuthClient["newsletterUnsubscribe"];
|
|
17
|
-
getLoginUrl: AuthClient["getLoginUrl"];
|
|
18
|
-
getCheckoutUrl: AuthClient["getCheckoutUrl"];
|
|
19
|
-
trackMetaEvent: AuthClient["trackMetaEvent"];
|
|
20
|
-
trackViewContent: AuthClient["trackViewContent"];
|
|
21
|
-
getMetaAttribution: AuthClient["getMetaAttribution"];
|
|
22
|
-
isPurchased: (priceIds: string[]) => boolean;
|
|
23
|
-
isSubscribed: (priceIds: string[], productId: string) => boolean;
|
|
24
|
-
isLoggedIn: boolean;
|
|
25
|
-
} | null;
|
|
26
|
-
declare const AuthContext: _$react.Context<AuthContextType>;
|
|
27
|
-
//#endregion
|
|
28
|
-
export { AuthContext, AuthContextType };
|
|
29
|
-
//# sourceMappingURL=AuthContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthContext.js","names":[],"sources":["../../src/react/AuthContext.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport type { UserPurchases, Session } from \"@us-auth/types\";\nimport type { AuthClient } from \"../AuthClient\";\n\nexport type AuthContextType = {\n session: Session | null;\n isSessionFetching: boolean;\n refetchSession: () => Promise<void>;\n purchases: UserPurchases | null;\n isPurchasesFetching: boolean;\n refetchPurchases: () => Promise<void>;\n signOut: AuthClient[\"signOut\"];\n newsletterSubscribe: AuthClient[\"newsletterSubscribe\"];\n newsletterUnsubscribe: AuthClient[\"newsletterUnsubscribe\"];\n getLoginUrl: AuthClient[\"getLoginUrl\"];\n getCheckoutUrl: AuthClient[\"getCheckoutUrl\"];\n trackMetaEvent: AuthClient[\"trackMetaEvent\"];\n trackViewContent: AuthClient[\"trackViewContent\"];\n getMetaAttribution: AuthClient[\"getMetaAttribution\"];\n isPurchased: (priceIds: string[]) => boolean;\n isSubscribed: (priceIds: string[], productId: string) => boolean;\n isLoggedIn: boolean;\n} | null;\n\nexport const AuthContext = createContext<AuthContextType>(null);\n"],"mappings":"sCAwBA,MAAa,EAAc,EAA+B,KAAK"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { UserPurchases } from "../types/src/purchases.js";
|
|
2
|
-
import { Session } from "../types/src/session.js";
|
|
3
|
-
import { AuthClient } from "../AuthClient.js";
|
|
4
|
-
import { PropsWithChildren } from "react";
|
|
5
|
-
import { QueryClient } from "@tanstack/react-query";
|
|
6
|
-
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
7
|
-
|
|
8
|
-
//#region src/react/AuthProvider.d.ts
|
|
9
|
-
interface AuthProviderProps extends PropsWithChildren {
|
|
10
|
-
authClient?: AuthClient;
|
|
11
|
-
queryClient?: QueryClient;
|
|
12
|
-
baseUrl: string;
|
|
13
|
-
frontendUrl: string;
|
|
14
|
-
initialSession?: Session | null;
|
|
15
|
-
initialPurchases?: UserPurchases | null;
|
|
16
|
-
mailingListPublicKey?: string;
|
|
17
|
-
}
|
|
18
|
-
declare const AuthProvider: ({
|
|
19
|
-
children,
|
|
20
|
-
baseUrl,
|
|
21
|
-
frontendUrl,
|
|
22
|
-
initialSession,
|
|
23
|
-
initialPurchases,
|
|
24
|
-
authClient: providedAuthClient,
|
|
25
|
-
queryClient: providedQueryClient,
|
|
26
|
-
mailingListPublicKey
|
|
27
|
-
}: AuthProviderProps) => _$react_jsx_runtime0.JSX.Element;
|
|
28
|
-
//#endregion
|
|
29
|
-
export { AuthProvider, AuthProviderProps };
|
|
30
|
-
//# sourceMappingURL=AuthProvider.d.ts.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{captureMetaClickId as e}from"../metaAttribution.js";import{AuthClient as t}from"../AuthClient.js";import{AuthContext as n}from"./AuthContext.js";import{useCallback as r,useEffect as i,useMemo as a,useRef as o}from"react";import{QueryClient as s,useQuery as c}from"@tanstack/react-query";import{usePostHog as l}from"@posthog/react";import{jsx as u}from"react/jsx-runtime";const d=({children:d,baseUrl:f,frontendUrl:p,initialSession:m,initialPurchases:h,authClient:g,queryClient:_,mailingListPublicKey:v})=>{let y=l(),b=a(()=>g??new t(f,p,void 0,v),[f,p,g,v]),x=a(()=>_??new s,[_]),{data:S,isFetching:C,refetch:w}=c({queryKey:[`us-auth-session`],staleTime:0,initialData:m,queryFn:b.getSession},x),T=a(()=>!(!S||S.user.isAnonymous),[S]),E=o(!1);i(()=>{e({frontendUrl:p})},[p]),i(()=>{C||S===null&&(E.current||(E.current=!0,b.signInAnonymously().then(e=>{x.setQueryData([`us-auth-session`],e)}).catch(e=>console.error(e))))},[b,C,x,S]),i(()=>{S?.user&&y&&y.get_distinct_id()!==S.user.id&&y.identify(S.user.id,{email:S.user.email})},[S,y]);let{data:D,isFetching:O,refetch:k}=c({queryKey:[`us-auth-purchases`],staleTime:1e3*60,initialData:h,queryFn:b.getPurchases},x),A=a(()=>b.getLoginUrl,[b]),j=a(()=>b.getCheckoutUrl,[b]),M=a(e=>()=>b.signOut(()=>{y?.reset(),e?.()}),[b,y]),N=a(()=>b.newsletterSubscribe,[b]),P=a(()=>b.newsletterUnsubscribe,[b]),F=a(()=>b.trackMetaEvent,[b]),I=a(()=>b.trackViewContent,[b]),L=a(()=>b.getMetaAttribution,[b]),R=r(e=>D?D.paddle.transactions.some(t=>t.items.some(t=>e.includes(t))&&!t.adjustments.some(e=>e.status===`approved`&&e.action===`refund`)):!1,[D]),z=r((e,t)=>{if(!D)return!1;let n=D.paddle.subscriptions.some(n=>n.items.some(n=>e.includes(n.priceId)||t===n.productId)&&n.status===`active`),r=D.stripe.some(t=>t.status===`active`&&t.items.some(t=>e.includes(t)));return n||r},[D]);return u(n.Provider,{value:{session:S??null,isSessionFetching:C,refetchSession:async()=>{await w()},purchases:D??null,isPurchasesFetching:O,refetchPurchases:async()=>{await k()},signOut:M,newsletterSubscribe:N,newsletterUnsubscribe:P,getLoginUrl:A,getCheckoutUrl:j,trackMetaEvent:F,trackViewContent:I,getMetaAttribution:L,isSubscribed:z,isPurchased:R,isLoggedIn:T},children:d})};export{d as AuthProvider};
|
|
2
|
-
//# sourceMappingURL=AuthProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthProvider.js","names":[],"sources":["../../src/react/AuthProvider.tsx"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n type PropsWithChildren,\n} from \"react\";\nimport { AuthContext } from \"./AuthContext\";\nimport { AuthClient } from \"../AuthClient\";\nimport type { Session, UserPurchases } from \"@us-auth/types\";\nimport { QueryClient, useQuery } from \"@tanstack/react-query\";\nimport { usePostHog } from \"@posthog/react\";\nimport { captureMetaClickId } from \"../metaAttribution\";\n\nexport interface AuthProviderProps extends PropsWithChildren {\n authClient?: AuthClient;\n queryClient?: QueryClient;\n baseUrl: string;\n frontendUrl: string;\n initialSession?: Session | null;\n initialPurchases?: UserPurchases | null;\n mailingListPublicKey?: string;\n}\n\nexport const AuthProvider = ({\n children,\n baseUrl,\n frontendUrl,\n initialSession,\n initialPurchases,\n authClient: providedAuthClient,\n queryClient: providedQueryClient,\n mailingListPublicKey,\n}: AuthProviderProps) => {\n const ph = usePostHog();\n\n const authClient = useMemo(\n () =>\n providedAuthClient ??\n new AuthClient(baseUrl, frontendUrl, undefined, mailingListPublicKey),\n [baseUrl, frontendUrl, providedAuthClient, mailingListPublicKey],\n );\n const queryClient = useMemo(\n () => providedQueryClient ?? new QueryClient(),\n [providedQueryClient],\n );\n\n const {\n data: session,\n isFetching: isSessionFetching,\n refetch: refetchSession,\n } = useQuery(\n {\n queryKey: [\"us-auth-session\"],\n staleTime: 0,\n initialData: initialSession,\n queryFn: authClient.getSession,\n },\n queryClient,\n );\n\n const isLoggedIn = useMemo(() => {\n if (!session || session.user.isAnonymous) return false;\n return true;\n }, [session]);\n\n const anonymousSignInAttempted = useRef(false);\n\n useEffect(() => {\n captureMetaClickId({ frontendUrl });\n }, [frontendUrl]);\n\n // Log unauthenticated users in anonymously automatically\n useEffect(() => {\n if (isSessionFetching) return;\n // Wait for the session query to settle to an explicit null, not undefined.\n if (session !== null) return;\n if (anonymousSignInAttempted.current) return;\n\n anonymousSignInAttempted.current = true;\n authClient\n .signInAnonymously()\n .then((newSession) => {\n queryClient.setQueryData([\"us-auth-session\"], newSession);\n })\n .catch((e) => console.error(e));\n }, [authClient, isSessionFetching, queryClient, session]);\n\n useEffect(() => {\n if (session?.user && ph) {\n const distinctId = ph.get_distinct_id();\n if (distinctId !== session.user.id) {\n ph.identify(session.user.id, {\n email: session.user.email,\n });\n }\n }\n }, [session, ph]);\n\n const {\n data: purchases,\n isFetching: isPurchasesFetching,\n refetch: refetchPurchases,\n } = useQuery(\n {\n queryKey: [\"us-auth-purchases\"],\n staleTime: 1000 * 60,\n initialData: initialPurchases,\n queryFn: authClient.getPurchases,\n },\n queryClient,\n );\n\n const getLoginUrl = useMemo(() => authClient.getLoginUrl, [authClient]);\n const getCheckoutUrl = useMemo(() => authClient.getCheckoutUrl, [authClient]);\n const signOut = useMemo(\n (onSuccess?: () => void) => () =>\n authClient.signOut(() => {\n ph?.reset();\n onSuccess?.();\n }),\n [authClient, ph],\n );\n const newsletterSubscribe = useMemo(\n () => authClient.newsletterSubscribe,\n [authClient],\n );\n const newsletterUnsubscribe = useMemo(\n () => authClient.newsletterUnsubscribe,\n [authClient],\n );\n const trackMetaEvent = useMemo(() => authClient.trackMetaEvent, [authClient]);\n const trackViewContent = useMemo(\n () => authClient.trackViewContent,\n [authClient],\n );\n const getMetaAttribution = useMemo(\n () => authClient.getMetaAttribution,\n [authClient],\n );\n\n const isPurchased = useCallback(\n (priceIds: string[]): boolean => {\n if (!purchases) return false;\n return purchases.paddle.transactions.some(\n (tra) =>\n tra.items.some((item) => priceIds.includes(item)) &&\n !tra.adjustments.some(\n (adj) => adj.status === \"approved\" && adj.action === \"refund\",\n ),\n );\n },\n [purchases],\n );\n\n const isSubscribed = useCallback(\n (priceIds: string[], productId: string): boolean => {\n if (!purchases) return false;\n\n const paddleSubscriptions = purchases.paddle.subscriptions.some(\n (sub) =>\n sub.items.some(\n (item) =>\n priceIds.includes(item.priceId) || productId === item.productId,\n ) && sub.status === \"active\",\n );\n\n const stripeSubscriptions = purchases.stripe.some(\n (sub) =>\n sub.status === \"active\" &&\n sub.items.some((item) => priceIds.includes(item)),\n );\n\n return paddleSubscriptions || stripeSubscriptions;\n },\n [purchases],\n );\n\n return (\n <AuthContext.Provider\n value={{\n session: session ?? null,\n isSessionFetching,\n refetchSession: async () => {\n await refetchSession();\n },\n purchases: purchases ?? null,\n isPurchasesFetching,\n refetchPurchases: async () => {\n await refetchPurchases();\n },\n signOut,\n newsletterSubscribe,\n newsletterUnsubscribe,\n getLoginUrl,\n getCheckoutUrl,\n trackMetaEvent,\n trackViewContent,\n getMetaAttribution,\n isSubscribed,\n isPurchased,\n isLoggedIn,\n }}\n >\n {children}\n </AuthContext.Provider>\n );\n};\n"],"mappings":"0XAwBA,MAAa,GAAgB,CAC3B,WACA,UACA,cACA,iBACA,mBACA,WAAY,EACZ,YAAa,EACb,0BACuB,CACvB,IAAM,EAAK,GAAY,CAEjB,EAAa,MAEf,GACA,IAAI,EAAW,EAAS,EAAa,IAAA,GAAW,EAAqB,CACvE,CAAC,EAAS,EAAa,EAAoB,EAAqB,CACjE,CACK,EAAc,MACZ,GAAuB,IAAI,EACjC,CAAC,EAAoB,CACtB,CAEK,CACJ,KAAM,EACN,WAAY,EACZ,QAAS,GACP,EACF,CACE,SAAU,CAA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,CACb,CAEK,EAAc,EACjB,GACM,EACE,EAAU,OAAO,aAAa,KAClC,GACC,EAAI,MAAM,KAAM,GAAS,EAAS,SAAS,EAAK,CAAC,EACjD,CAAC,EAAI,YAAY,KACd,GAAQ,EAAI,SAAW,YAAc,EAAI,SAAW,SACtD,CACJ,CAPsB,GASzB,CAAC,EAAU,CACZ,CAEK,EAAe,GAClB,EAAoB,IAA+B,CAClD,GAAI,CAAC,EAAW,MAAO,GAEvB,IAAM,EAAsB,EAAU,OAAO,cAAc,KACxD,GACC,EAAI,MAAM,KACP,GACC,EAAS,SAAS,EAAK,QAAQ,EAAI,IAAc,EAAK,UACzD,EAAI,EAAI,SAAW,SACvB,CAEK,EAAsB,EAAU,OAAO,KAC1C,GACC,EAAI,SAAW,UACf,EAAI,MAAM,KAAM,GAAS,EAAS,SAAS,EAAK,CAAC,CACpD,CAED,OAAO,GAAuB,GAEhC,CAAC,EAAU,CACZ,CAED,OACE,EAAC,EAAY,SAAb,CACE,MAAO,CACL,QAAS,GAAW,KACpB,oBACA,eAAgB,SAAY,CAC1B,MAAM,GAAgB,EAExB,UAAW,GAAa,KACxB,sBACA,iBAAkB,SAAY,CAC5B,MAAM,GAAkB,EAE1B,UACA,sBACA,wBACA,cACA,iBACA,iBACA,mBACA,qBACA,eACA,cACA,aACD,CAEA,WACoB,CAAA"}
|
package/dist/react/index.d.ts
DELETED
package/dist/react/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./AuthContext.js";import"./AuthProvider.js";import"./useAuth.js";
|
package/dist/react/useAuth.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { UserPurchases } from "../types/src/purchases.js";
|
|
2
|
-
import { Session } from "../types/src/session.js";
|
|
3
|
-
import { AuthClient } from "../AuthClient.js";
|
|
4
|
-
//#region src/react/useAuth.d.ts
|
|
5
|
-
declare function useAuth(): {
|
|
6
|
-
session: Session | null;
|
|
7
|
-
isSessionFetching: boolean;
|
|
8
|
-
refetchSession: () => Promise<void>;
|
|
9
|
-
purchases: UserPurchases | null;
|
|
10
|
-
isPurchasesFetching: boolean;
|
|
11
|
-
refetchPurchases: () => Promise<void>;
|
|
12
|
-
signOut: AuthClient["signOut"];
|
|
13
|
-
newsletterSubscribe: AuthClient["newsletterSubscribe"];
|
|
14
|
-
newsletterUnsubscribe: AuthClient["newsletterUnsubscribe"];
|
|
15
|
-
getLoginUrl: AuthClient["getLoginUrl"];
|
|
16
|
-
getCheckoutUrl: AuthClient["getCheckoutUrl"];
|
|
17
|
-
trackMetaEvent: AuthClient["trackMetaEvent"];
|
|
18
|
-
trackViewContent: AuthClient["trackViewContent"];
|
|
19
|
-
getMetaAttribution: AuthClient["getMetaAttribution"];
|
|
20
|
-
isPurchased: (priceIds: string[]) => boolean;
|
|
21
|
-
isSubscribed: (priceIds: string[], productId: string) => boolean;
|
|
22
|
-
isLoggedIn: boolean;
|
|
23
|
-
};
|
|
24
|
-
//#endregion
|
|
25
|
-
export { useAuth };
|
|
26
|
-
//# sourceMappingURL=useAuth.d.ts.map
|
package/dist/react/useAuth.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.js","names":[],"sources":["../../src/react/useAuth.ts"],"sourcesContent":["import { useContext } from \"react\";\nimport { AuthContext } from \"./AuthContext\";\n\nexport function useAuth() {\n const ctx = useContext(AuthContext);\n if (!ctx) {\n throw new Error(\"useAuth must be used within an AuthProvider\");\n }\n return ctx;\n}\n"],"mappings":"kFAGA,SAAgB,GAAU,CACxB,IAAM,EAAM,EAAW,EAAY,CACnC,GAAI,CAAC,EACH,MAAU,MAAM,8CAA8C,CAEhE,OAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
package/dist/types/src/meta.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
//#region ../types/src/meta.d.ts
|
|
4
|
-
declare const metaTrackEventSchema: z.ZodObject<{
|
|
5
|
-
event_name: z.ZodEnum<{
|
|
6
|
-
ViewContent: "ViewContent";
|
|
7
|
-
InitiateCheckout: "InitiateCheckout";
|
|
8
|
-
}>;
|
|
9
|
-
content_ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
10
|
-
content_type: z.ZodOptional<z.ZodString>;
|
|
11
|
-
event_source_url: z.ZodOptional<z.ZodString>;
|
|
12
|
-
value: z.ZodOptional<z.ZodNumber>;
|
|
13
|
-
currency: z.ZodOptional<z.ZodString>;
|
|
14
|
-
event_id: z.ZodOptional<z.ZodString>;
|
|
15
|
-
}, z.core.$strip>;
|
|
16
|
-
type MetaTrackEventInput = z.infer<typeof metaTrackEventSchema>;
|
|
17
|
-
type MetaAttributionCookies = {
|
|
18
|
-
fbc?: string;
|
|
19
|
-
fbp?: string;
|
|
20
|
-
};
|
|
21
|
-
declare function parseMetaAttributionFromCookieHeader(cookieHeader: string | undefined): MetaAttributionCookies;
|
|
22
|
-
declare function buildFbcFromFbclid(fbclid: string, seenAtMs?: number): string;
|
|
23
|
-
//#endregion
|
|
24
|
-
export { MetaAttributionCookies, MetaTrackEventInput, buildFbcFromFbclid, metaTrackEventSchema, parseMetaAttributionFromCookieHeader };
|
|
25
|
-
//# sourceMappingURL=meta.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
//#region ../types/src/purchases.d.ts
|
|
4
|
-
declare const userPurchasesSchema: z.ZodObject<{
|
|
5
|
-
stripe: z.ZodArray<z.ZodObject<{
|
|
6
|
-
id: z.ZodString;
|
|
7
|
-
customerId: z.ZodString;
|
|
8
|
-
created: z.ZodCoercedDate<unknown>;
|
|
9
|
-
status: z.ZodEnum<{
|
|
10
|
-
active: "active";
|
|
11
|
-
trialing: "trialing";
|
|
12
|
-
canceled: "canceled";
|
|
13
|
-
past_due: "past_due";
|
|
14
|
-
paused: "paused";
|
|
15
|
-
incomplete: "incomplete";
|
|
16
|
-
incomplete_expired: "incomplete_expired";
|
|
17
|
-
unpaid: "unpaid";
|
|
18
|
-
}>;
|
|
19
|
-
items: z.ZodArray<z.ZodString>;
|
|
20
|
-
}, z.core.$strip>>;
|
|
21
|
-
paddle: z.ZodObject<{
|
|
22
|
-
customerId: z.ZodOptional<z.ZodString>;
|
|
23
|
-
subscriptions: z.ZodArray<z.ZodObject<{
|
|
24
|
-
id: z.ZodString;
|
|
25
|
-
createdAt: z.ZodCoercedDate<unknown>;
|
|
26
|
-
status: z.ZodString;
|
|
27
|
-
items: z.ZodArray<z.ZodObject<{
|
|
28
|
-
priceId: z.ZodString;
|
|
29
|
-
productId: z.ZodString;
|
|
30
|
-
}, z.core.$strip>>;
|
|
31
|
-
}, z.core.$strip>>;
|
|
32
|
-
transactions: z.ZodArray<z.ZodObject<{
|
|
33
|
-
id: z.ZodString;
|
|
34
|
-
createdAt: z.ZodCoercedDate<unknown>;
|
|
35
|
-
adjustments: z.ZodArray<z.ZodObject<{
|
|
36
|
-
id: z.ZodString;
|
|
37
|
-
createdAt: z.ZodCoercedDate<unknown>;
|
|
38
|
-
action: z.ZodEnum<{
|
|
39
|
-
credit: "credit";
|
|
40
|
-
refund: "refund";
|
|
41
|
-
chargeback: "chargeback";
|
|
42
|
-
chargeback_reverse: "chargeback_reverse";
|
|
43
|
-
chargeback_warning: "chargeback_warning";
|
|
44
|
-
chargeback_warning_reverse: "chargeback_warning_reverse";
|
|
45
|
-
credit_reverse: "credit_reverse";
|
|
46
|
-
}>;
|
|
47
|
-
type: z.ZodEnum<{
|
|
48
|
-
full: "full";
|
|
49
|
-
partial: "partial";
|
|
50
|
-
}>;
|
|
51
|
-
status: z.ZodEnum<{
|
|
52
|
-
pending_approval: "pending_approval";
|
|
53
|
-
approved: "approved";
|
|
54
|
-
rejected: "rejected";
|
|
55
|
-
reversed: "reversed";
|
|
56
|
-
}>;
|
|
57
|
-
}, z.core.$strip>>;
|
|
58
|
-
items: z.ZodArray<z.ZodString>;
|
|
59
|
-
}, z.core.$strip>>;
|
|
60
|
-
}, z.core.$strip>;
|
|
61
|
-
mailingList: z.ZodObject<{
|
|
62
|
-
subscribed: z.ZodBoolean;
|
|
63
|
-
}, z.core.$strip>;
|
|
64
|
-
}, z.core.$strip>;
|
|
65
|
-
type UserPurchases = z.infer<typeof userPurchasesSchema>;
|
|
66
|
-
//#endregion
|
|
67
|
-
export { UserPurchases, userPurchasesSchema };
|
|
68
|
-
//# sourceMappingURL=purchases.d.ts.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Session, User } from "better-auth";
|
|
2
|
-
|
|
3
|
-
//#region ../types/src/session.d.ts
|
|
4
|
-
interface Session$1 {
|
|
5
|
-
session: Session;
|
|
6
|
-
user: User & {
|
|
7
|
-
isAnonymous?: boolean | null;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
export { Session$1 as Session };
|
|
12
|
-
//# sourceMappingURL=session.d.ts.map
|