ras-stack 0.32.0 → 0.33.0

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.
@@ -5,8 +5,9 @@ export type PostHogCoverage = {
5
5
  browser: {
6
6
  analytics: PostHogCoverageDecision;
7
7
  errorTracking: PostHogCoverageDecision;
8
- sessionReplay: PostHogCoverageDecision;
9
8
  featureFlags: PostHogCoverageDecision;
9
+ identity: PostHogCoverageDecision;
10
+ sessionReplay: PostHogCoverageDecision;
10
11
  };
11
12
  server: {
12
13
  analytics: PostHogCoverageDecision;
@@ -14,8 +14,9 @@ function coverageDecisions(coverage) {
14
14
  return [
15
15
  ['browser.analytics', coverage.browser.analytics],
16
16
  ['browser.errorTracking', coverage.browser.errorTracking],
17
- ['browser.sessionReplay', coverage.browser.sessionReplay],
18
17
  ['browser.featureFlags', coverage.browser.featureFlags],
18
+ ['browser.identity', coverage.browser.identity],
19
+ ['browser.sessionReplay', coverage.browser.sessionReplay],
19
20
  ['server.analytics', coverage.server.analytics],
20
21
  ['server.errorTracking', coverage.server.errorTracking],
21
22
  ['server.logs', coverage.server.logs],
@@ -1 +1 @@
1
- {"version":3,"file":"coverage.js","sourceRoot":"","sources":["../../src/posthog/coverage.ts"],"names":[],"mappings":"AAiBA,MAAM,UAAU,qBAAqB,CAAC,QAAyB;IAC7D,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3D,IAAI,QAAQ,KAAK,IAAI;YAAE,SAAQ;QAC/B,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,OAAO,QAAQ,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACvF,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,+CAA+C,CAAC,CAAA;QACzE,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,oCAAoC,CAAC,CAAA;IAC7F,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAyB;IAClD,OAAO;QACL,CAAC,mBAAmB,EAAE,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC;QACjD,CAAC,uBAAuB,EAAE,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC;QACzD,CAAC,uBAAuB,EAAE,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC;QACzD,CAAC,sBAAsB,EAAE,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC;QACvD,CAAC,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC;QAC/C,CAAC,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC;QACvD,CAAC,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;QACrC,CAAC,YAAY,EAAE,QAAQ,CAAC,UAAU,CAAC;KACpC,CAAA;AACH,CAAC","sourcesContent":["export type PostHogCoverageDecision = true | { disabled: string }\n\nexport type PostHogCoverage = {\n browser: {\n analytics: PostHogCoverageDecision\n errorTracking: PostHogCoverageDecision\n sessionReplay: PostHogCoverageDecision\n featureFlags: PostHogCoverageDecision\n }\n server: {\n analytics: PostHogCoverageDecision\n errorTracking: PostHogCoverageDecision\n logs: PostHogCoverageDecision\n }\n sourceMaps: PostHogCoverageDecision\n}\n\nexport function definePostHogCoverage(coverage: PostHogCoverage) {\n for (const [area, decision] of coverageDecisions(coverage)) {\n if (decision === true) continue\n if (!decision || typeof decision !== 'object' || typeof decision.disabled !== 'string') {\n throw new Error(`${area} must be enabled or include a disabled reason`)\n }\n if (!decision.disabled.trim()) throw new Error(`${area} disabled reason must not be empty`)\n }\n return coverage\n}\n\nfunction coverageDecisions(coverage: PostHogCoverage): Array<[string, PostHogCoverageDecision]> {\n return [\n ['browser.analytics', coverage.browser.analytics],\n ['browser.errorTracking', coverage.browser.errorTracking],\n ['browser.sessionReplay', coverage.browser.sessionReplay],\n ['browser.featureFlags', coverage.browser.featureFlags],\n ['server.analytics', coverage.server.analytics],\n ['server.errorTracking', coverage.server.errorTracking],\n ['server.logs', coverage.server.logs],\n ['sourceMaps', coverage.sourceMaps],\n ]\n}\n"]}
1
+ {"version":3,"file":"coverage.js","sourceRoot":"","sources":["../../src/posthog/coverage.ts"],"names":[],"mappings":"AAkBA,MAAM,UAAU,qBAAqB,CAAC,QAAyB;IAC7D,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3D,IAAI,QAAQ,KAAK,IAAI;YAAE,SAAQ;QAC/B,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,OAAO,QAAQ,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACvF,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,+CAA+C,CAAC,CAAA;QACzE,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,oCAAoC,CAAC,CAAA;IAC7F,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAyB;IAClD,OAAO;QACL,CAAC,mBAAmB,EAAE,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC;QACjD,CAAC,uBAAuB,EAAE,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC;QACzD,CAAC,sBAAsB,EAAE,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC;QACvD,CAAC,kBAAkB,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC/C,CAAC,uBAAuB,EAAE,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC;QACzD,CAAC,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC;QAC/C,CAAC,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC;QACvD,CAAC,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;QACrC,CAAC,YAAY,EAAE,QAAQ,CAAC,UAAU,CAAC;KACpC,CAAA;AACH,CAAC","sourcesContent":["export type PostHogCoverageDecision = true | { disabled: string }\n\nexport type PostHogCoverage = {\n browser: {\n analytics: PostHogCoverageDecision\n errorTracking: PostHogCoverageDecision\n featureFlags: PostHogCoverageDecision\n identity: PostHogCoverageDecision\n sessionReplay: PostHogCoverageDecision\n }\n server: {\n analytics: PostHogCoverageDecision\n errorTracking: PostHogCoverageDecision\n logs: PostHogCoverageDecision\n }\n sourceMaps: PostHogCoverageDecision\n}\n\nexport function definePostHogCoverage(coverage: PostHogCoverage) {\n for (const [area, decision] of coverageDecisions(coverage)) {\n if (decision === true) continue\n if (!decision || typeof decision !== 'object' || typeof decision.disabled !== 'string') {\n throw new Error(`${area} must be enabled or include a disabled reason`)\n }\n if (!decision.disabled.trim()) throw new Error(`${area} disabled reason must not be empty`)\n }\n return coverage\n}\n\nfunction coverageDecisions(coverage: PostHogCoverage): Array<[string, PostHogCoverageDecision]> {\n return [\n ['browser.analytics', coverage.browser.analytics],\n ['browser.errorTracking', coverage.browser.errorTracking],\n ['browser.featureFlags', coverage.browser.featureFlags],\n ['browser.identity', coverage.browser.identity],\n ['browser.sessionReplay', coverage.browser.sessionReplay],\n ['server.analytics', coverage.server.analytics],\n ['server.errorTracking', coverage.server.errorTracking],\n ['server.logs', coverage.server.logs],\n ['sourceMaps', coverage.sourceMaps],\n ]\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from 'react';
2
- import type { PostHogConfig } from 'posthog-js';
2
+ import type { PostHogConfig, Properties } from 'posthog-js';
3
3
  import type { PostHogEnvironment } from './config.js';
4
4
  export declare function PostHogIntegration({ children, environment, fallback, options, }: {
5
5
  children?: ReactNode;
@@ -17,3 +17,21 @@ export declare function PostHogIntegration({ children, environment, fallback, op
17
17
  }) & {
18
18
  children?: ReactNode | undefined;
19
19
  }> | Iterable<ReactNode> | Promise<string | number | bigint | boolean | Iterable<ReactNode> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | null | undefined> | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null | undefined;
20
+ export type BetterAuthUser = {
21
+ id: string;
22
+ };
23
+ export type BetterAuthSession<User extends BetterAuthUser = BetterAuthUser> = {
24
+ user: User;
25
+ };
26
+ export type BetterAuthSessionState<User extends BetterAuthUser = BetterAuthUser> = {
27
+ data?: BetterAuthSession<User> | null;
28
+ error?: unknown;
29
+ isPending: boolean;
30
+ };
31
+ export type BetterAuthReactClient<User extends BetterAuthUser = BetterAuthUser> = {
32
+ useSession: () => BetterAuthSessionState<User>;
33
+ };
34
+ export declare function PostHogBetterAuthIdentity<User extends BetterAuthUser>({ authClient, properties, }: {
35
+ authClient: BetterAuthReactClient<User>;
36
+ properties?: (user: User) => Properties;
37
+ }): null;
@@ -1,5 +1,5 @@
1
- import { PostHogErrorBoundary, PostHogProvider } from '@posthog/react';
2
- import { createElement } from 'react';
1
+ import { PostHogErrorBoundary, PostHogProvider, usePostHog } from '@posthog/react';
2
+ import { createElement, useEffect, useRef } from 'react';
3
3
  import { postHogBrowserOptions } from './client.js';
4
4
  export function PostHogIntegration({ children, environment, fallback = createElement('main', null, 'Something went wrong. Refresh the page to try again.'), options, }) {
5
5
  if (!environment)
@@ -15,4 +15,25 @@ export function PostHogIntegration({ children, environment, fallback = createEle
15
15
  }),
16
16
  }, createElement(PostHogErrorBoundary, { fallback }, children));
17
17
  }
18
+ export function PostHogBetterAuthIdentity({ authClient, properties, }) {
19
+ const session = authClient.useSession();
20
+ const posthog = usePostHog();
21
+ const identified = useRef(undefined);
22
+ const propertiesRef = useRef(properties);
23
+ propertiesRef.current = properties;
24
+ useEffect(() => {
25
+ if (session.isPending || session.error)
26
+ return;
27
+ const user = session.data?.user;
28
+ if (user) {
29
+ posthog.identify(user.id, propertiesRef.current?.(user));
30
+ identified.current = user.id;
31
+ }
32
+ else if (identified.current) {
33
+ posthog.reset();
34
+ identified.current = undefined;
35
+ }
36
+ }, [posthog, session.data?.user, session.error, session.isPending]);
37
+ return null;
38
+ }
18
39
  //# sourceMappingURL=react.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/posthog/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,EAAE,aAAa,EAAkB,MAAM,OAAO,CAAA;AAErD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGnD,MAAM,UAAU,kBAAkB,CAAC,EACjC,QAAQ,EACR,WAAW,EACX,QAAQ,GAAG,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,sDAAsD,CAAC,EAC9F,OAAO,GAMR;IACC,IAAI,CAAC,WAAW;QAAE,OAAO,QAAQ,CAAA;IACjC,MAAM,gBAAgB,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAC/F,OAAO,aAAa,CAClB,eAAe,EACf;QACE,MAAM,EAAE,WAAW,CAAC,YAAY;QAChC,OAAO,EAAE,qBAAqB,CAAC;YAC7B,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjD,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChC,CAAC;KACH,EACD,aAAa,CAAC,oBAAoB,EAAE,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAC5D,CAAA;AACH,CAAC","sourcesContent":["import { PostHogErrorBoundary, PostHogProvider } from '@posthog/react'\nimport { createElement, type ReactNode } from 'react'\nimport type { PostHogConfig } from 'posthog-js'\nimport { postHogBrowserOptions } from './client.js'\nimport type { PostHogEnvironment } from './config.js'\n\nexport function PostHogIntegration({\n children,\n environment,\n fallback = createElement('main', null, 'Something went wrong. Refresh the page to try again.'),\n options,\n}: {\n children?: ReactNode\n environment: PostHogEnvironment | undefined\n fallback?: ReactNode\n options?: Partial<PostHogConfig>\n}) {\n if (!environment) return children\n const tracingHostnames = typeof window === 'undefined' ? undefined : [window.location.hostname]\n return createElement(\n PostHogProvider,\n {\n apiKey: environment.projectToken,\n options: postHogBrowserOptions({\n apiHost: '/ingest',\n uiHost: environment.uiHost,\n ...(tracingHostnames ? { tracingHostnames } : {}),\n ...(options ? { options } : {}),\n }),\n },\n createElement(PostHogErrorBoundary, { fallback }, children),\n )\n}\n"]}
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/posthog/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAClF,OAAO,EAAE,aAAa,EAAkB,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAExE,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAGnD,MAAM,UAAU,kBAAkB,CAAC,EACjC,QAAQ,EACR,WAAW,EACX,QAAQ,GAAG,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,sDAAsD,CAAC,EAC9F,OAAO,GAMR;IACC,IAAI,CAAC,WAAW;QAAE,OAAO,QAAQ,CAAA;IACjC,MAAM,gBAAgB,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;I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AAO,GAAG,SAAS,CAAA;QAChC,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;IAEnE,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { PostHogErrorBoundary, PostHogProvider, usePostHog } from '@posthog/react'\nimport { createElement, type ReactNode, useEffect, useRef } from 'react'\nimport type { PostHogConfig, Properties } from 'posthog-js'\nimport { postHogBrowserOptions } from './client.js'\nimport type { PostHogEnvironment } from './config.js'\n\nexport function PostHogIntegration({\n children,\n environment,\n fallback = createElement('main', null, 'Something went wrong. Refresh the page to try again.'),\n options,\n}: {\n children?: ReactNode\n environment: PostHogEnvironment | undefined\n fallback?: ReactNode\n options?: Partial<PostHogConfig>\n}) {\n if (!environment) return children\n const tracingHostnames = typeof window === 'undefined' ? undefined : [window.location.hostname]\n return createElement(\n PostHogProvider,\n {\n apiKey: environment.projectToken,\n options: postHogBrowserOptions({\n apiHost: '/ingest',\n uiHost: environment.uiHost,\n ...(tracingHostnames ? { tracingHostnames } : {}),\n ...(options ? { options } : {}),\n }),\n },\n createElement(PostHogErrorBoundary, { fallback }, children),\n )\n}\n\nexport type BetterAuthUser = { id: string }\nexport type BetterAuthSession<User extends BetterAuthUser = BetterAuthUser> = { user: User }\nexport type BetterAuthSessionState<User extends BetterAuthUser = BetterAuthUser> = {\n data?: BetterAuthSession<User> | null\n error?: unknown\n isPending: boolean\n}\nexport type BetterAuthReactClient<User extends BetterAuthUser = BetterAuthUser> = {\n useSession: () => BetterAuthSessionState<User>\n}\n\nexport function PostHogBetterAuthIdentity<User extends BetterAuthUser>({\n authClient,\n properties,\n}: {\n authClient: BetterAuthReactClient<User>\n properties?: (user: User) => Properties\n}) {\n const session = authClient.useSession()\n const posthog = usePostHog()\n const identified = useRef<string | undefined>(undefined)\n const propertiesRef = useRef(properties)\n propertiesRef.current = properties\n\n useEffect(() => {\n if (session.isPending || session.error) return\n const user = session.data?.user\n if (user) {\n posthog.identify(user.id, propertiesRef.current?.(user))\n identified.current = user.id\n } else if (identified.current) {\n posthog.reset()\n identified.current = undefined\n }\n }, [posthog, session.data?.user, session.error, session.isPending])\n\n return null\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ras-stack",
3
- "version": "0.32.0",
3
+ "version": "0.33.0",
4
4
  "description": "Composable full-stack primitives shared across Richard Solomou's applications.",
5
5
  "keywords": [
6
6
  "authentication",