@uninspired/auth-client 1.0.15 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,6 +35,7 @@ bun add react react-dom
35
35
  | **Checkout URL builder** | Generate a link to the hosted checkout flow |
36
36
  | **Newsletter** | Subscribe/unsubscribe from mailing lists |
37
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) |
38
39
 
39
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.
40
41
 
@@ -173,6 +174,25 @@ await client.newsletterSubscribe("user@example.com", "my-app-group", "https://ca
173
174
  await client.newsletterUnsubscribe("user@example.com");
174
175
  ```
175
176
 
177
+ #### Meta ad attribution
178
+
179
+ `AuthProvider` auto-captures `fbclid` into `_fbc`/`_fbp` cookies. No Meta Pixel script is loaded.
180
+
181
+ ```ts
182
+ await client.trackViewContent({ contentIds: ["pro_123"] });
183
+ const { fbc, fbp } = client.getMetaAttribution();
184
+ ```
185
+
186
+ Standalone capture (e.g. accounts frontend without `AuthProvider`):
187
+
188
+ ```ts
189
+ import { captureMetaClickId } from "@uninspired/auth-client";
190
+
191
+ captureMetaClickId({ frontendUrl: "https://uninspired.app" });
192
+ ```
193
+
194
+ See [docs/ad-attribution.md](../../docs/ad-attribution.md).
195
+
176
196
  ## `AuthProvider` and `useAuth` (React)
177
197
 
178
198
  ### `AuthProvider` props
@@ -189,10 +209,11 @@ await client.newsletterUnsubscribe("user@example.com");
189
209
 
190
210
  The provider automatically:
191
211
 
192
- 1. Fetches the session on mount (with 1-minute stale time)
193
- 2. Signs in anonymously if no session exists
212
+ 1. Revalidates the session on mount via `get-session` (with 1-minute stale time; SSR `initialSession` is shown immediately while revalidating)
213
+ 2. Signs in anonymously only after revalidation confirms no session exists
194
214
  3. Fetches purchases when a session is available
195
215
  4. Identifies the user in PostHog when authenticated
216
+ 5. Captures Meta click ids (`fbclid` → `_fbc`/`_fbp`) on mount
196
217
 
197
218
  ### `useAuth()` return value
198
219
 
@@ -208,6 +229,9 @@ The provider automatically:
208
229
  | `signOut` | `(onSuccess?) => Promise<void>` | Sign out (resets PostHog) |
209
230
  | `getLoginUrl` | `AuthClient["getLoginUrl"]` | Build login URL |
210
231
  | `getCheckoutUrl` | `AuthClient["getCheckoutUrl"]` | Build checkout URL |
232
+ | `trackMetaEvent` | `AuthClient["trackMetaEvent"]` | Send Meta CAPI event (no PII) |
233
+ | `trackViewContent` | `AuthClient["trackViewContent"]` | Convenience wrapper for product views |
234
+ | `getMetaAttribution` | `AuthClient["getMetaAttribution"]` | Read `_fbc` / `_fbp` cookies |
211
235
  | `isPurchased` | `(priceIds: string[]) => boolean` | Check one-time purchase |
212
236
  | `isSubscribed` | `(priceIds: string[], productId: string) => boolean` | Check active subscription |
213
237
  | `newsletterSubscribe` | `AuthClient["newsletterSubscribe"]` | Subscribe to newsletter |
@@ -1,5 +1,6 @@
1
1
  import { UserPurchases } from "./types/src/purchases.js";
2
2
  import { Session } from "./types/src/session.js";
3
+ import { MetaAttributionCookies, MetaTrackEventInput } from "./types/src/meta.js";
3
4
  //#region src/AuthClient.d.ts
4
5
  declare class AuthClient {
5
6
  #private;
@@ -10,6 +11,13 @@ declare class AuthClient {
10
11
  getPurchases: () => Promise<UserPurchases | null>;
11
12
  newsletterSubscribe: (email: string, userGroup?: string, callbackUrl?: string) => Promise<void>;
12
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;
13
21
  getLoginUrl: (options?: {
14
22
  redirectUrl?: string;
15
23
  appName?: string;
@@ -1,2 +1,2 @@
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";var o=class{#e;#t;#n;#r;#i;constructor(o,s,c,l){this.#i=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`})}),this.#r=a(new URL(`/api/mailing-list`,o).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())};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{o as AuthClient};
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
2
  //# sourceMappingURL=AuthClient.js.map
@@ -1 +1 @@
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 { UserPurchases, Session, RedirectIntent } from \"@us-auth/types\";\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 // 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"],"mappings":"yPAWA,IAAa,EAAb,KAAwB,CACtB,GACA,GACA,GACA,GACA,GAEA,YACE,EACA,EACA,EACA,EACA,CACA,MAAA,EAAe,EACf,MAAA,EAAoB,EACpB,MAAA,EAAmB,EAAiB,CAClC,QAAS,EACT,QAAS,CACP,GAAiB,CACjB,GAAiB,CACjB,GAAgB,CAChB,GAAe,CAChB,CACF,CAAC,CACF,MAAA,EAAkB,EAAc,IAAI,IAAI,WAAY,EAAO,CAAC,UAAU,CAAE,CACtE,OAAQ,EAAU,IAChB,MAAM,EAAK,CACT,GAAG,EACH,YAAa,UACd,CAAC,CACL,CAAC,CACF,MAAA,EAA0B,EACxB,IAAI,IAAI,oBAAqB,EAAO,CAAC,UAAU,CAC/C,CACE,OAAQ,EAAU,IAChB,MAAM,EAAK,CACT,GAAG,EACH,QAAS,CACP,eAAgB,mBAChB,eAAgB,EAChB,GAAG,EAAK,QACT,CACF,CAAC,CACL,CACF,CAIH,WAAa,SAAqC,CAChD,GAAM,CAAE,OAAM,SAAU,MAAM,MAAA,EAAiB,WAC7C,EAAE,CACF,CACE,QAAS,MAAA,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CAOhD,OANI,GAAS,aACX,EAAI,aAAa,IACf,SACA,MAAA,EAAwB,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
+ {"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\");\n return url.toString();\n };\n}\n"],"mappings":"2TAoBA,IAAa,EAAb,KAAwB,CACtB,GACA,GACA,GACA,GACA,GAEA,YACE,EACA,EACA,EACA,EACA,CACA,MAAA,EAAe,EACf,MAAA,EAAoB,EACpB,M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AAI,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"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { UserPurchases } from "./types/src/purchases.js";
2
2
  import { Session } from "./types/src/session.js";
3
+ import { MetaAttributionCookies, buildFbcFromFbclid, parseMetaAttributionFromCookieHeader } from "./types/src/meta.js";
4
+ import { captureMetaClickId, getMetaCookieDomain, readMetaAttributionCookies } from "./metaAttribution.js";
3
5
  import { AuthClient } from "./AuthClient.js";
4
6
  import { AuthContext, AuthContextType } from "./react/AuthContext.js";
5
7
  import { AuthProvider, AuthProviderProps } from "./react/AuthProvider.js";
6
8
  import { useAuth } from "./react/useAuth.js";
7
- export { AuthClient, AuthContext, AuthContextType, AuthProvider, AuthProviderProps, type Session, type UserPurchases, useAuth };
9
+ export { AuthClient, AuthContext, AuthContextType, AuthProvider, AuthProviderProps, MetaAttributionCookies, type Session, type UserPurchases, buildFbcFromFbclid, captureMetaClickId, getMetaCookieDomain, parseMetaAttributionFromCookieHeader, readMetaAttributionCookies, useAuth };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{AuthClient as e}from"./AuthClient.js";import{AuthContext as t}from"./react/AuthContext.js";import{AuthProvider as n}from"./react/AuthProvider.js";import{useAuth as r}from"./react/useAuth.js";import"./react/index.js";export{e as AuthClient,t as AuthContext,n as AuthProvider,r as useAuth};
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};
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,2 @@
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
@@ -0,0 +1 @@
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"}
@@ -16,6 +16,9 @@ type AuthContextType = {
16
16
  newsletterUnsubscribe: AuthClient["newsletterUnsubscribe"];
17
17
  getLoginUrl: AuthClient["getLoginUrl"];
18
18
  getCheckoutUrl: AuthClient["getCheckoutUrl"];
19
+ trackMetaEvent: AuthClient["trackMetaEvent"];
20
+ trackViewContent: AuthClient["trackViewContent"];
21
+ getMetaAttribution: AuthClient["getMetaAttribution"];
19
22
  isPurchased: (priceIds: string[]) => boolean;
20
23
  isSubscribed: (priceIds: string[], productId: string) => boolean;
21
24
  isLoggedIn: boolean;
@@ -1 +1 @@
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 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":"sCAqBA,MAAa,EAAc,EAA+B,KAAK"}
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,2 +1,2 @@
1
- import{AuthClient as e}from"../AuthClient.js";import{AuthContext as t}from"./AuthContext.js";import{useCallback as n,useEffect as r,useMemo as i,useRef as a}from"react";import{QueryClient as o,useQuery as s}from"@tanstack/react-query";import{usePostHog as c}from"@posthog/react";import{jsx as l}from"react/jsx-runtime";const u=({children:u,baseUrl:d,frontendUrl:f,initialSession:p,initialPurchases:m,authClient:h,queryClient:g,mailingListPublicKey:_})=>{let v=c(),y=i(()=>h??new e(d,f,void 0,_),[d,h,_]),b=i(()=>g??new o,[g]),{data:x,isFetching:S,refetch:C}=s({queryKey:[`us-auth-session`],staleTime:1e3*60,initialData:p,queryFn:y.getSession},b),w=i(()=>!(!x||x.user.isAnonymous),[x]),T=a(!1);r(()=>{S||x===null&&(T.current||(T.current=!0,y.signInAnonymously().then(e=>{b.setQueryData([`us-auth-session`],e)}).catch(e=>console.error(e))))},[y,S,b,x]),r(()=>{x?.user&&v&&v.get_distinct_id()!==x.user.id&&v.identify(x.user.id,{email:x.user.email})},[x,v]);let{data:E,isFetching:D,refetch:O}=s({queryKey:[`us-auth-purchases`],staleTime:1e3*60,initialData:m,queryFn:y.getPurchases},b),k=i(()=>y.getLoginUrl,[y]),A=i(()=>y.getCheckoutUrl,[y]),j=i(e=>()=>y.signOut(()=>{v?.reset(),e?.()}),[y,v]),M=i(()=>y.newsletterSubscribe,[y]),N=i(()=>y.newsletterUnsubscribe,[y]),P=n(e=>E?E.paddle.transactions.some(t=>t.items.some(t=>e.includes(t))&&!t.adjustments.some(e=>e.status===`approved`&&e.action===`refund`)):!1,[E]),F=n((e,t)=>{if(!E)return!1;let n=E.paddle.subscriptions.some(n=>n.items.some(n=>e.includes(n.priceId)||t===n.productId)&&n.status===`active`),r=E.stripe.some(t=>t.status===`active`&&t.items.some(t=>e.includes(t)));return n||r},[E]);return l(t.Provider,{value:{session:x??null,isSessionFetching:S,refetchSession:async()=>{await C()},purchases:E??null,isPurchasesFetching:D,refetchPurchases:async()=>{await O()},signOut:j,newsletterSubscribe:M,newsletterUnsubscribe:N,getLoginUrl:k,getCheckoutUrl:A,isSubscribed:F,isPurchased:P,isLoggedIn:w},children:u})};export{u as AuthProvider};
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
2
  //# sourceMappingURL=AuthProvider.js.map
@@ -1 +1 @@
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\";\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, 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: 1000 * 60,\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 // 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\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 isSubscribed,\n isPurchased,\n isLoggedIn,\n }}\n >\n {children}\n </AuthContext.Provider>\n );\n};\n"],"mappings":"+TAuBA,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,EAAoB,EAAqB,CACpD,CACK,EAAc,MACZ,GAAuB,IAAI,EACjC,CAAC,EAAoB,CACtB,CAEK,CACJ,KAAM,EACN,WAAY,EACZ,QAAS,GACP,EACF,CACE,SAAU,CAAC,kBAAkB,CAC7B,UAAW,IAAO,GAClB,YAAa,EACb,QAAS,EAAW,WACrB,CACD,EACD,CAEK,EAAa,MACjB,EAAI,CAAC,GAAW,EAAQ,KAAK,aAE5B,CAAC,EAAQ,CAAC,CAEP,EAA2B,EAAO,GAAM,CAG9C,MAAgB,CACV,GAEA,IAAY,OACZ,EAAyB,UAE7B,EAAyB,QAAU,GACnC,EACG,mBAAmB,CACnB,KAAM,GAAe,CACpB,EAAY,aAAa,CAAC,kBAAkB,CAA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,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,eACA,cACA,aACD,CAEA,WACoB,CAAA"}
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,CAAC,kBAAkB,CAC7B,UAAW,EACX,YAAa,EACb,QAAS,EAAW,WACrB,CACD,EACD,CAEK,EAAa,MACjB,EAAI,CAAC,GAAW,EAAQ,KAAK,aAE5B,CAAC,EAAQ,CAAC,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Q,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"}
@@ -14,6 +14,9 @@ declare function useAuth(): {
14
14
  newsletterUnsubscribe: AuthClient["newsletterUnsubscribe"];
15
15
  getLoginUrl: AuthClient["getLoginUrl"];
16
16
  getCheckoutUrl: AuthClient["getCheckoutUrl"];
17
+ trackMetaEvent: AuthClient["trackMetaEvent"];
18
+ trackViewContent: AuthClient["trackViewContent"];
19
+ getMetaAttribution: AuthClient["getMetaAttribution"];
17
20
  isPurchased: (priceIds: string[]) => boolean;
18
21
  isSubscribed: (priceIds: string[], productId: string) => boolean;
19
22
  isLoggedIn: boolean;
@@ -0,0 +1 @@
1
+ import { z } from "zod";
@@ -1,2 +1,3 @@
1
1
  import { UserPurchases, userPurchasesSchema } from "./purchases.js";
2
- import { Session } from "./session.js";
2
+ import { Session } from "./session.js";
3
+ import { MetaAttributionCookies, MetaTrackEventInput, buildFbcFromFbclid, metaTrackEventSchema, parseMetaAttributionFromCookieHeader } from "./meta.js";
@@ -0,0 +1,25 @@
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uninspired/auth-client",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Auth client for Uninspired Studio Products",
5
5
  "author": "Chris Kolb <chris@uninspired.studio>",
6
6
  "license": "MIT",