@rpcbase/client 0.283.0 → 0.285.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.
Files changed (57) hide show
  1. package/dist/RootProvider/index.d.ts +7 -0
  2. package/dist/RootProvider/index.d.ts.map +1 -0
  3. package/dist/RootProvider/index.js +8 -0
  4. package/dist/apiClient/getServerApiClient.d.ts +10 -0
  5. package/dist/apiClient/getServerApiClient.d.ts.map +1 -0
  6. package/dist/apiClient/getServerApiClient.js +97 -0
  7. package/dist/apiClient/index.d.ts +16 -0
  8. package/dist/apiClient/index.d.ts.map +1 -0
  9. package/dist/apiClient/index.js +50 -0
  10. package/dist/cleanupURL.d.ts +2 -0
  11. package/dist/cleanupURL.d.ts.map +1 -0
  12. package/dist/cleanupURL.js +37 -0
  13. package/dist/getFeatureFlag.d.ts +2 -0
  14. package/dist/getFeatureFlag.d.ts.map +1 -0
  15. package/dist/getFeatureFlag.js +43 -0
  16. package/dist/hooks/index.d.ts +3 -0
  17. package/dist/hooks/index.d.ts.map +1 -0
  18. package/dist/hooks/index.js +2 -0
  19. package/dist/hooks/useMediaQuery.d.ts +2 -0
  20. package/dist/hooks/useMediaQuery.d.ts.map +1 -0
  21. package/dist/hooks/useMediaQuery.js +24 -0
  22. package/dist/hooks/useThrottledMeasure.d.ts +11 -0
  23. package/dist/hooks/useThrottledMeasure.d.ts.map +1 -0
  24. package/dist/hooks/useThrottledMeasure.js +32 -0
  25. package/dist/hooks.d.ts +2 -0
  26. package/dist/hooks.d.ts.map +1 -0
  27. package/dist/hooks.js +1 -0
  28. package/dist/index.d.ts +6 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +5 -0
  31. package/dist/initWithRoutes.d.ts +8 -0
  32. package/dist/initWithRoutes.d.ts.map +1 -0
  33. package/dist/initWithRoutes.js +80 -0
  34. package/dist/instrument.d.ts +2 -0
  35. package/dist/instrument.d.ts.map +1 -0
  36. package/dist/instrument.js +29 -0
  37. package/dist/types.d.ts +8 -0
  38. package/dist/types.d.ts.map +1 -0
  39. package/dist/types.js +1 -0
  40. package/dist/utils/useApplyScroll.d.ts +2 -0
  41. package/dist/utils/useApplyScroll.d.ts.map +1 -0
  42. package/dist/utils/useApplyScroll.js +138 -0
  43. package/package.json +27 -7
  44. package/hooks.ts +0 -1
  45. package/instrument.ts +0 -32
  46. package/src/RootProvider/index.tsx +0 -15
  47. package/src/apiClient/getServerApiClient.ts +0 -133
  48. package/src/apiClient/index.ts +0 -86
  49. package/src/cleanupURL.ts +0 -46
  50. package/src/getFeatureFlag.ts +0 -58
  51. package/src/hooks/index.ts +0 -2
  52. package/src/hooks/useMediaQuery.ts +0 -31
  53. package/src/hooks/useThrottledMeasure.ts +0 -49
  54. package/src/index.ts +0 -5
  55. package/src/initWithRoutes.tsx +0 -115
  56. package/src/types.ts +0 -8
  57. package/src/utils/useApplyScroll.ts +0 -169
@@ -0,0 +1,7 @@
1
+ import { ReactNode } from "react";
2
+ type RootProviderProps = {
3
+ children: ReactNode;
4
+ };
5
+ export declare const RootProvider: ({ children }: RootProviderProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../pkg/client/src/RootProvider/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAOjC,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,SAAS,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,cAAY,iBAAiB,4CAQzD,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import posthog from "posthog-js";
3
+ import { PostHogProvider } from "posthog-js/react";
4
+ import { useApplyScroll } from "../utils/useApplyScroll";
5
+ export const RootProvider = ({ children }) => {
6
+ useApplyScroll();
7
+ return (_jsx(PostHogProvider, { client: posthog, children: children }));
8
+ };
@@ -0,0 +1,10 @@
1
+ import { Application } from "express";
2
+ type Ctx = any;
3
+ export declare const getServerApiClient: (app: Application) => Promise<{
4
+ get: <TResponse = Record<string, unknown>>(path: string, payload: Record<string, unknown>, ctx?: Ctx) => Promise<TResponse>;
5
+ post: <TResponse = Record<string, unknown>>(path: string, payload: Record<string, unknown>, ctx?: Ctx) => Promise<TResponse>;
6
+ put: <TResponse = Record<string, unknown>>(path: string, payload: Record<string, unknown>, ctx?: Ctx) => Promise<TResponse>;
7
+ delete: <TResponse = Record<string, unknown>>(path: string, payload: Record<string, unknown>, ctx?: Ctx) => Promise<TResponse>;
8
+ }>;
9
+ export default getServerApiClient;
10
+ //# sourceMappingURL=getServerApiClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getServerApiClient.d.ts","sourceRoot":"","sources":["../../../../../pkg/client/src/apiClient/getServerApiClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAA8B,MAAM,SAAS,CAAA;AAGjE,KAAK,GAAG,GAAG,GAAG,CAAA;AAGd,eAAO,MAAM,kBAAkB,GAAS,KAAK,WAAW;UAqGtC,SAAS,kCACf,MAAM,WACH,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAC1B,GAAG,KACR,OAAO,CAAC,SAAS,CAAC;WAJP,SAAS,kCACf,MAAM,WACH,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAC1B,GAAG,KACR,OAAO,CAAC,SAAS,CAAC;UAJP,SAAS,kCACf,MAAM,WACH,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAC1B,GAAG,KACR,OAAO,CAAC,SAAS,CAAC;aAJP,SAAS,kCACf,MAAM,WACH,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAC1B,GAAG,KACR,OAAO,CAAC,SAAS,CAAC;EAkBxB,CAAA;AAED,eAAe,kBAAkB,CAAA"}
@@ -0,0 +1,97 @@
1
+ export const getServerApiClient = async (app) => {
2
+ const callRoute = async (app, method, path, req, res) => {
3
+ return new Promise((resolve, reject) => {
4
+ let isEnded = false;
5
+ const mockReq = {
6
+ ...req,
7
+ method: method.toUpperCase(),
8
+ url: path
9
+ };
10
+ const mockRes = {
11
+ ...res,
12
+ json: (data) => {
13
+ if (!isEnded) {
14
+ isEnded = true;
15
+ resolve(data);
16
+ }
17
+ },
18
+ status: (statusCode) => {
19
+ console.log("Status:", statusCode);
20
+ return mockRes;
21
+ },
22
+ };
23
+ const routerStack = app.router.stack;
24
+ const firstApiMiddlewareIndex = routerStack.findIndex((layer) => layer.name === "__FIRST_API_MIDDLEWARE__");
25
+ if (!(firstApiMiddlewareIndex > -1)) {
26
+ throw new Error("middleware: __FIRST_API_MIDDLEWARE__ was not found in stack");
27
+ }
28
+ const apiStack = routerStack.slice(firstApiMiddlewareIndex + 1);
29
+ const processLayer = async (index) => {
30
+ if (index >= apiStack.length || isEnded)
31
+ return;
32
+ const layer = apiStack[index];
33
+ const isNonMatchingLayer = !layer.match(path);
34
+ if (isNonMatchingLayer) {
35
+ // console.log("not machthing route:", path, "to layer:", index, layer.name, layer, "reason: ", {isNonMatchingLayer})
36
+ await processLayer(index + 1);
37
+ return;
38
+ }
39
+ const runHandler = async (handler) => new Promise((resolveMiddleware, rejectMiddleware) => {
40
+ handler(mockReq, mockRes, (err) => {
41
+ if (err) {
42
+ console.error("Middleware error:", err);
43
+ if (!isEnded) {
44
+ isEnded = true;
45
+ rejectMiddleware(err);
46
+ }
47
+ return;
48
+ }
49
+ resolveMiddleware();
50
+ });
51
+ });
52
+ if (layer.route) {
53
+ if (!layer.route.methods[method.toLowerCase()]) {
54
+ // console.log("not machthing route:", path, "to route layer:", index, layer.name, layer, "reason: method not matching")
55
+ await processLayer(index + 1);
56
+ return;
57
+ }
58
+ if (layer.route.stack.length !== 1) {
59
+ throw new Error(`expected only one handler per route for route: ${layer.route.path}`);
60
+ }
61
+ await runHandler(layer.route.stack[0].handle);
62
+ }
63
+ else {
64
+ await runHandler(layer.handle);
65
+ }
66
+ if (!isEnded) {
67
+ await processLayer(index + 1);
68
+ }
69
+ };
70
+ // AWAIT ??
71
+ processLayer(0);
72
+ // Set a timeout to prevent hanging
73
+ setTimeout(() => {
74
+ if (!isEnded) {
75
+ reject("Route handler timed out");
76
+ }
77
+ }, 30000);
78
+ });
79
+ };
80
+ const createMethod = (method) => {
81
+ return async (path, payload, ctx) => {
82
+ if (!ctx) {
83
+ throw new Error("Context must be provided in SSR mode");
84
+ }
85
+ ctx.req.body = payload;
86
+ return callRoute(app, method, path, ctx.req, ctx.res);
87
+ };
88
+ };
89
+ const apiClient = {
90
+ get: createMethod("get"),
91
+ post: createMethod("post"),
92
+ put: createMethod("put"),
93
+ delete: createMethod("delete")
94
+ };
95
+ return apiClient;
96
+ };
97
+ export default getServerApiClient;
@@ -0,0 +1,16 @@
1
+ import type { Application } from "express";
2
+ type Ctx = any;
3
+ type ServerArgs = {
4
+ app: Application;
5
+ };
6
+ type PayloadNotCtx = Record<string, unknown> & {
7
+ [P in keyof Ctx]?: never;
8
+ };
9
+ type ApiClientMethod = <TResponse = Record<string, unknown>>(path: string, payload: PayloadNotCtx, ctx?: Ctx) => Promise<TResponse>;
10
+ export type HttpMethod = "get" | "put" | "post" | "delete";
11
+ type MethodRecord<T> = Record<HttpMethod, T>;
12
+ export type ApiClient = MethodRecord<ApiClientMethod>;
13
+ declare let apiClient: ApiClient;
14
+ export declare const initApiClient: (args?: ServerArgs) => Promise<void>;
15
+ export { apiClient };
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../pkg/client/src/apiClient/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAG1C,KAAK,GAAG,GAAG,GAAG,CAAA;AAGd,KAAK,UAAU,GAAG;IAChB,GAAG,EAAE,WAAW,CAAC;CAClB,CAAC;AAEF,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;KAC5C,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,EAAE,KAAK;CACzB,CAAC;AAEF,KAAK,eAAe,GAAG,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,aAAa,EACtB,GAAG,CAAC,EAAE,GAAG,KACN,OAAO,CAAC,SAAS,CAAC,CAAC;AAExB,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;AAC3D,KAAK,YAAY,CAAC,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,SAAS,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;AAEtD,QAAA,IAAI,SAAS,EAAE,SAAS,CAAA;AAExB,eAAO,MAAM,aAAa,GAAU,OAAO,UAAU,kBAuDpD,CAAA;AAED,OAAO,EAAE,SAAS,EAAE,CAAA"}
@@ -0,0 +1,50 @@
1
+ let apiClient;
2
+ export const initApiClient = async (args) => {
3
+ if (import.meta.env.SSR) {
4
+ if (!args) {
5
+ throw new Error("Server args must be provided in SSR mode");
6
+ }
7
+ const { getServerApiClient } = await import("./getServerApiClient");
8
+ apiClient = await getServerApiClient(args.app);
9
+ }
10
+ else {
11
+ const axios = (await import("axios")).default;
12
+ const axiosClient = axios.create({
13
+ baseURL: "/",
14
+ withCredentials: true,
15
+ headers: {
16
+ "Content-Type": "application/json",
17
+ },
18
+ });
19
+ const createMethod = (method) => {
20
+ return async (path, payload, _ctx) => {
21
+ const config = {
22
+ method,
23
+ url: path,
24
+ data: payload,
25
+ headers: {
26
+ // ...(typeof ctxOrPath !== 'string' && {
27
+ // // 'X-Custom-Header': ctxOrPath.someHeaderValue,
28
+ // // ...ctxOrPath.additionalHeaders,
29
+ // }),
30
+ },
31
+ };
32
+ try {
33
+ const response = await axiosClient(config);
34
+ return response.data;
35
+ }
36
+ catch (error) {
37
+ console.log("AXIOS API ERROR", error);
38
+ throw error;
39
+ }
40
+ };
41
+ };
42
+ apiClient = {
43
+ get: createMethod("get"),
44
+ put: createMethod("put"),
45
+ post: createMethod("post"),
46
+ delete: createMethod("delete"),
47
+ };
48
+ }
49
+ };
50
+ export { apiClient };
@@ -0,0 +1,2 @@
1
+ export declare const cleanupURL: () => void;
2
+ //# sourceMappingURL=cleanupURL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanupURL.d.ts","sourceRoot":"","sources":["../../../../pkg/client/src/cleanupURL.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU,YA0CtB,CAAA"}
@@ -0,0 +1,37 @@
1
+ const CLEANUP_WAIT_DELAY = 1000;
2
+ // Function to clean UTM params while preserving others
3
+ export const cleanupURL = () => {
4
+ if (import.meta.env.SSR) {
5
+ return;
6
+ }
7
+ const runCleanup = () => {
8
+ // Add a small delay before running cleanupURL
9
+ setTimeout(() => {
10
+ const url = new URL(window.location.href);
11
+ const params = new URLSearchParams(url.search);
12
+ // Get all current query parameter keys
13
+ const paramKeys = Array.from(params.keys());
14
+ // Remove any parameter starting with 'utm_'
15
+ paramKeys.forEach((key) => {
16
+ if (key.startsWith("utm_")) {
17
+ params.delete(key);
18
+ }
19
+ });
20
+ // Build the new URL: keep pathname and append remaining query params (if any)
21
+ const cleanUrl = url.pathname +
22
+ (params.toString() ? "?" + params.toString() : "") +
23
+ url.hash;
24
+ // Update the browser URL without reloading
25
+ window.history.replaceState({}, document.title, cleanUrl);
26
+ }, CLEANUP_WAIT_DELAY);
27
+ };
28
+ // If DOM is already loaded, schedule the cleanup
29
+ if (document.readyState === "complete" ||
30
+ document.readyState === "interactive") {
31
+ runCleanup();
32
+ }
33
+ else {
34
+ // Otherwise wait for the DOM content to be loaded
35
+ document.addEventListener("DOMContentLoaded", runCleanup, { once: true });
36
+ }
37
+ };
@@ -0,0 +1,2 @@
1
+ export declare const getFeatureFlag: (flag: string) => Promise<boolean | string | undefined>;
2
+ //# sourceMappingURL=getFeatureFlag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFeatureFlag.d.ts","sourceRoot":"","sources":["../../../../pkg/client/src/getFeatureFlag.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,GACzB,MAAM,MAAM,KACX,OAAO,CAAC,OAAO,GAAG,MAAM,GAAG,SAAS,CAoDtC,CAAA"}
@@ -0,0 +1,43 @@
1
+ import _snakeCase from "lodash/snakeCase";
2
+ export const getFeatureFlag = async (flag) => {
3
+ const envKey = `RB_PUBLIC_FLAG_${_snakeCase(flag).toUpperCase()}`;
4
+ if (import.meta.env.SSR) {
5
+ if (process.env[envKey] !== undefined) {
6
+ return process.env[envKey];
7
+ }
8
+ const startTime = performance.now();
9
+ const { PostHog } = await import("posthog-node");
10
+ const client = new PostHog(process.env.RB_PUBLIC_POSTHOG_KEY, { host: "https://eu.i.posthog.com" });
11
+ const distinctId = "server";
12
+ console.log("TODO: NYI server side feature flags client distinctId");
13
+ const value = await client.getFeatureFlag(flag, distinctId);
14
+ const endTime = performance.now();
15
+ console.log(`SSR: Feature flag "${flag}" loaded in ${(endTime - startTime).toFixed(2)}ms`);
16
+ return value;
17
+ }
18
+ else {
19
+ if (import.meta.env[envKey] !== undefined) {
20
+ return import.meta.env[envKey];
21
+ }
22
+ const startTime = performance.now();
23
+ const { posthog } = await import("posthog-js");
24
+ let hasLoadedFeatureFlags = false;
25
+ function waitForFeatureFlags() {
26
+ return new Promise((resolve) => {
27
+ if (hasLoadedFeatureFlags) {
28
+ resolve();
29
+ }
30
+ else {
31
+ posthog.onFeatureFlags(() => {
32
+ hasLoadedFeatureFlags = true;
33
+ resolve();
34
+ });
35
+ }
36
+ });
37
+ }
38
+ await waitForFeatureFlags();
39
+ const endTime = performance.now();
40
+ console.log(`Client: Feature flag "${flag}" loaded in ${(endTime - startTime).toFixed(2)}ms`);
41
+ return posthog.getFeatureFlag(flag);
42
+ }
43
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./useThrottledMeasure";
2
+ export * from "./useMediaQuery";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../pkg/client/src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "./useThrottledMeasure";
2
+ export * from "./useMediaQuery";
@@ -0,0 +1,2 @@
1
+ export declare const useMediaQuery: (query: string) => boolean;
2
+ //# sourceMappingURL=useMediaQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMediaQuery.d.ts","sourceRoot":"","sources":["../../../../../pkg/client/src/hooks/useMediaQuery.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,OAyB7C,CAAA"}
@@ -0,0 +1,24 @@
1
+ import { useSyncExternalStore } from "react";
2
+ const emptyUnsubscribe = () => { };
3
+ export const useMediaQuery = (query) => {
4
+ const isServer = typeof window === "undefined";
5
+ const subscribe = (callback) => {
6
+ if (isServer)
7
+ return emptyUnsubscribe;
8
+ const mql = window.matchMedia(query);
9
+ // Modern browsers
10
+ if (mql.addEventListener) {
11
+ mql.addEventListener("change", callback);
12
+ return () => mql.removeEventListener("change", callback);
13
+ }
14
+ // Legacy fallback
15
+ mql.addListener(callback);
16
+ return () => mql.removeListener(callback);
17
+ };
18
+ const getSnapshot = () => {
19
+ if (isServer)
20
+ return false;
21
+ return window.matchMedia(query).matches;
22
+ };
23
+ return useSyncExternalStore(subscribe, getSnapshot, () => false);
24
+ };
@@ -0,0 +1,11 @@
1
+ export declare const useThrottledMeasure: (throttleDuration?: number) => (import("react-use/lib/useMeasure").UseMeasureRef<Element> | {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ top: number;
7
+ left: number;
8
+ bottom: number;
9
+ right: number;
10
+ })[];
11
+ //# sourceMappingURL=useThrottledMeasure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useThrottledMeasure.d.ts","sourceRoot":"","sources":["../../../../../pkg/client/src/hooks/useThrottledMeasure.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,mBAAmB,GAAI,yBAAwC;;;;;;;;;IAsC3E,CAAA"}
@@ -0,0 +1,32 @@
1
+ import { useState, useEffect, useRef, useCallback } from "react";
2
+ import useMeasure from "react-use/lib/useMeasure";
3
+ import _throttle from "lodash/throttle";
4
+ import { deepEqual } from "fast-equals";
5
+ const useMeasureHook = useMeasure.default ?? useMeasure;
6
+ const DEFAULT_THROTTLE_TIME = 16;
7
+ export const useThrottledMeasure = (throttleDuration = DEFAULT_THROTTLE_TIME) => {
8
+ const hasInitialMeasure = useRef(false);
9
+ const [ref, measuredRect] = useMeasureHook();
10
+ const [rect, setRect] = useState(() => {
11
+ return { x: 0, y: 0, width: 0, height: 0, top: 0, left: 0, bottom: 0, right: 0 };
12
+ });
13
+ const throttledSetRect = useCallback(_throttle((newRect) => {
14
+ setRect((current) => {
15
+ return deepEqual(current, newRect) ? current : newRect;
16
+ });
17
+ }, throttleDuration, { leading: true, trailing: true }), [throttleDuration]);
18
+ useEffect(() => {
19
+ if (measuredRect.width > 0 && !hasInitialMeasure.current) {
20
+ hasInitialMeasure.current = true;
21
+ setRect((current) => {
22
+ return deepEqual(current, measuredRect) ? current : measuredRect;
23
+ });
24
+ return;
25
+ }
26
+ throttledSetRect(measuredRect);
27
+ return () => {
28
+ throttledSetRect.cancel();
29
+ };
30
+ }, [measuredRect, throttledSetRect]);
31
+ return [ref, rect];
32
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./src/hooks";
2
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../pkg/client/hooks.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
package/dist/hooks.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/hooks";
@@ -0,0 +1,6 @@
1
+ export * from "./apiClient";
2
+ export * from "./initWithRoutes";
3
+ export * from "./types";
4
+ export * from "./getFeatureFlag";
5
+ export * from "./RootProvider";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../pkg/client/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./apiClient";
2
+ export * from "./initWithRoutes";
3
+ export * from "./types";
4
+ export * from "./getFeatureFlag";
5
+ export * from "./RootProvider";
@@ -0,0 +1,8 @@
1
+ import { createRoutesFromElements } from "@rpcbase/router";
2
+ type InitWithRoutesOptions = {
3
+ devThrowsOnHydrationErrors?: boolean;
4
+ };
5
+ type RoutesElement = Parameters<typeof createRoutesFromElements>[0];
6
+ export declare const initWithRoutes: (routesElement: RoutesElement, opts?: InitWithRoutesOptions) => Promise<void>;
7
+ export {};
8
+ //# sourceMappingURL=initWithRoutes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initWithRoutes.d.ts","sourceRoot":"","sources":["../../../../pkg/client/src/initWithRoutes.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAsB,wBAAwB,EAAiB,MAAM,iBAAiB,CAAA;AAqC7F,KAAK,qBAAqB,GAAG;IAC3B,0BAA0B,CAAC,EAAE,OAAO,CAAA;CACrC,CAAA;AAED,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAA;AAEnE,eAAO,MAAM,cAAc,GACzB,eAAe,aAAa,EAC5B,OAAO,qBAAqB,kBA0E7B,CAAA"}
@@ -0,0 +1,80 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { StrictMode } from "react";
3
+ import posthog from "posthog-js";
4
+ import { createBrowserRouter, createRoutesFromElements, RouterProvider } from "@rpcbase/router";
5
+ import { hydrateRoot } from "react-dom/client";
6
+ import { initApiClient } from "./apiClient";
7
+ import { cleanupURL } from "./cleanupURL";
8
+ const isProduction = import.meta.env.MODE === "production";
9
+ /* eslint-disable @typescript-eslint/no-explicit-any */
10
+ const showErrorOverlay = (err) => {
11
+ const ErrorOverlay = customElements.get("vite-error-overlay");
12
+ // don't open outside vite environment
13
+ if (!ErrorOverlay) {
14
+ return;
15
+ }
16
+ console.log(err);
17
+ const overlay = new ErrorOverlay(err);
18
+ document.body.appendChild(overlay);
19
+ };
20
+ const handleServerErrors = () => {
21
+ if (window.__staticRouterHydrationData?.errors) {
22
+ const { errors } = window.__staticRouterHydrationData;
23
+ Object.values(errors).forEach((error) => {
24
+ showErrorOverlay({
25
+ plugin: "ssr-router",
26
+ ...error.reason
27
+ });
28
+ });
29
+ }
30
+ };
31
+ export const initWithRoutes = async (routesElement, opts) => {
32
+ await initApiClient();
33
+ cleanupURL();
34
+ handleServerErrors();
35
+ const routes = createRoutesFromElements(routesElement);
36
+ const router = createBrowserRouter(routes);
37
+ const toError = (error) => error instanceof Error ? error : new Error(String(error));
38
+ const mentionsHydration = (value, depth = 0) => {
39
+ if (depth > 5) {
40
+ return false;
41
+ }
42
+ if (typeof value === "string") {
43
+ return value.toLowerCase().includes("hydrat");
44
+ }
45
+ if (value instanceof Error) {
46
+ const digest = value.digest;
47
+ const cause = value.cause;
48
+ return (mentionsHydration(value.message, depth + 1) ||
49
+ mentionsHydration(digest, depth + 1) ||
50
+ mentionsHydration(cause, depth + 1));
51
+ }
52
+ return false;
53
+ };
54
+ const phReactHandler = (react_context) => (error, errorInfo) => {
55
+ const err = toError(error);
56
+ // send as exception (counts toward error tracking)
57
+ posthog.captureException(err, {
58
+ react_context,
59
+ component_stack: errorInfo?.componentStack
60
+ });
61
+ if (react_context === "uncaught") {
62
+ console.warn("Uncaught error", err, errorInfo?.componentStack);
63
+ }
64
+ };
65
+ const hydrationOptions = isProduction ? {
66
+ onUncaughtError: phReactHandler("uncaught"),
67
+ onCaughtError: phReactHandler("caught"),
68
+ onRecoverableError: phReactHandler("recoverable")
69
+ } : (opts?.devThrowsOnHydrationErrors ? {
70
+ onRecoverableError(error, errorInfo) {
71
+ const err = toError(error);
72
+ if (mentionsHydration(err) || mentionsHydration(errorInfo?.componentStack)) {
73
+ throw err;
74
+ }
75
+ // For non-hydration recoverable errors in dev, keep a visible signal.
76
+ console.error(err, errorInfo?.componentStack);
77
+ }
78
+ } : undefined);
79
+ hydrateRoot(document.getElementById("root"), _jsx(StrictMode, { children: _jsx(RouterProvider, { router: router }) }), hydrationOptions);
80
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=instrument.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrument.d.ts","sourceRoot":"","sources":["../../../pkg/client/instrument.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ import posthog from "posthog-js";
2
+ const isProduction = import.meta.env.MODE === "production";
3
+ const posthogKey = import.meta.env.RB_PUBLIC_POSTHOG_KEY;
4
+ if (isProduction) {
5
+ if (typeof posthogKey === "string" && posthogKey.length > 0) {
6
+ posthog.init(posthogKey, {
7
+ api_host: "/ingest",
8
+ ui_host: "https://eu.posthog.com",
9
+ person_profiles: "always",
10
+ session_recording: {
11
+ maskAllInputs: false
12
+ },
13
+ capture_pageview: isProduction,
14
+ capture_exceptions: {
15
+ capture_unhandled_errors: true,
16
+ capture_unhandled_rejections: true,
17
+ capture_console_errors: true,
18
+ },
19
+ autocapture: isProduction,
20
+ disable_session_recording: !isProduction,
21
+ });
22
+ }
23
+ else {
24
+ console.warn("missing POSTHOG_KEY");
25
+ }
26
+ }
27
+ else {
28
+ console.info("ℹ️ Not initializing posthog in development");
29
+ }
@@ -0,0 +1,8 @@
1
+ import { Ctx } from "@rpcbase/api";
2
+ import { Params } from "@rpcbase/router";
3
+ export type LoaderArgs = {
4
+ params: Params;
5
+ ctx: Ctx;
6
+ };
7
+ export type Loader = ({ params, ctx }: LoaderArgs) => Promise<any>;
8
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../pkg/client/src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAGxC,MAAM,MAAM,UAAU,GAAG;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAC,CAAA;AAGnD,MAAM,MAAM,MAAM,GAAG,CAAC,EAAC,MAAM,EAAE,GAAG,EAAC,EAAE,UAAU,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function useApplyScroll(): void;
2
+ //# sourceMappingURL=useApplyScroll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useApplyScroll.d.ts","sourceRoot":"","sources":["../../../../../pkg/client/src/utils/useApplyScroll.ts"],"names":[],"mappings":"AAiBA,wBAAgB,cAAc,SAuJ7B"}