@every-app/sdk 0.1.13 → 0.1.14

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 (32) hide show
  1. package/dist/shared/bypassGatewayLocalOnly.d.ts +2 -1
  2. package/dist/shared/bypassGatewayLocalOnly.d.ts.map +1 -1
  3. package/dist/shared/bypassGatewayLocalOnly.js +6 -2
  4. package/dist/tanstack/server/authenticateRequest.d.ts +2 -0
  5. package/dist/tanstack/server/authenticateRequest.d.ts.map +1 -1
  6. package/dist/tanstack/server/authenticateRequest.js +75 -3
  7. package/package.json +3 -3
  8. package/src/cloudflare/getLocalD1Url.ts +0 -64
  9. package/src/cloudflare/index.ts +0 -1
  10. package/src/cloudflare/lazyInit.ts +0 -67
  11. package/src/cloudflare/server/gateway.test.ts +0 -262
  12. package/src/cloudflare/server/gateway.ts +0 -114
  13. package/src/cloudflare/server/index.ts +0 -2
  14. package/src/core/authenticatedFetch.ts +0 -54
  15. package/src/core/index.ts +0 -12
  16. package/src/core/sessionManager.test.ts +0 -939
  17. package/src/core/sessionManager.ts +0 -492
  18. package/src/env.d.ts +0 -13
  19. package/src/shared/bypassGatewayLocalOnly.ts +0 -55
  20. package/src/shared/parseMessagePayload.ts +0 -22
  21. package/src/tanstack/EmbeddedAppProvider.tsx +0 -96
  22. package/src/tanstack/GatewayRequiredError.tsx +0 -150
  23. package/src/tanstack/_internal/useEveryAppSession.test.ts +0 -40
  24. package/src/tanstack/_internal/useEveryAppSession.tsx +0 -74
  25. package/src/tanstack/index.ts +0 -3
  26. package/src/tanstack/server/authConfig.ts +0 -19
  27. package/src/tanstack/server/authenticateRequest.test.ts +0 -482
  28. package/src/tanstack/server/authenticateRequest.ts +0 -143
  29. package/src/tanstack/server/index.ts +0 -3
  30. package/src/tanstack/server/types.ts +0 -4
  31. package/src/tanstack/useEveryAppRouter.tsx +0 -83
  32. package/src/tanstack/useSessionTokenClientMiddleware.ts +0 -43
@@ -1,83 +0,0 @@
1
- import { useEffect } from "react";
2
- import { SessionManager } from "../core/sessionManager.js";
3
- import { useRouter } from "@tanstack/react-router";
4
- import { parseMessagePayload } from "../shared/parseMessagePayload.js";
5
-
6
- interface UseEveryAppRouterParams {
7
- sessionManager: SessionManager | null;
8
- }
9
-
10
- export function useEveryAppRouter({ sessionManager }: UseEveryAppRouterParams) {
11
- const router = useRouter();
12
- // Route synchronization effect
13
- useEffect(() => {
14
- if (!sessionManager) return;
15
-
16
- // Listen for route sync messages from parent
17
- const handleMessage = (event: MessageEvent) => {
18
- // Validate origin based on environment
19
- if (!sessionManager.isTrustedHostMessage(event)) return;
20
-
21
- const data = parseMessagePayload(event.data);
22
- if (!data) return;
23
-
24
- if (
25
- data.type === "ROUTE_CHANGE" &&
26
- data.direction === "parent-to-child"
27
- ) {
28
- const targetRoute = typeof data.route === "string" ? data.route : null;
29
- const currentRoute = window.location.pathname;
30
-
31
- // Only navigate if the route is different from current location
32
- if (targetRoute && targetRoute !== currentRoute) {
33
- router.navigate({ to: targetRoute });
34
- }
35
- }
36
- };
37
-
38
- window.addEventListener("message", handleMessage);
39
-
40
- // Simplified route change detection with 2 reliable methods
41
- let lastReportedPath = window.location.pathname;
42
-
43
- const handleRouteChange = () => {
44
- const currentPath = window.location.pathname;
45
-
46
- // Only report if the path actually changed
47
- if (currentPath === lastReportedPath) {
48
- return;
49
- }
50
-
51
- lastReportedPath = currentPath;
52
-
53
- const message = {
54
- type: "ROUTE_CHANGE",
55
- route: currentPath,
56
- appId: sessionManager.appId,
57
- direction: "child-to-parent",
58
- };
59
-
60
- try {
61
- sessionManager.postToHost(message);
62
- } catch {
63
- return;
64
- }
65
- };
66
- // Listen to popstate for browser back/forward
67
- window.addEventListener("popstate", handleRouteChange);
68
-
69
- // Polling to detect route changes (catches router navigation)
70
- const pollInterval = setInterval(() => {
71
- const currentPath = window.location.pathname;
72
- if (currentPath !== lastReportedPath) {
73
- handleRouteChange();
74
- }
75
- }, 100);
76
-
77
- return () => {
78
- window.removeEventListener("message", handleMessage);
79
- window.removeEventListener("popstate", handleRouteChange);
80
- clearInterval(pollInterval);
81
- };
82
- }, [sessionManager]);
83
- }
@@ -1,43 +0,0 @@
1
- import { createMiddleware } from "@tanstack/react-start";
2
- import type { SessionManager } from "../core/sessionManager.js";
3
- import {
4
- BYPASS_GATEWAY_LOCAL_ONLY_TOKEN,
5
- isBypassGatewayLocalOnlyClient,
6
- } from "../shared/bypassGatewayLocalOnly.js";
7
-
8
- export const useSessionTokenClientMiddleware = createMiddleware({
9
- type: "function",
10
- }).client(async ({ next }) => {
11
- if (isBypassGatewayLocalOnlyClient()) {
12
- return next({
13
- headers: {
14
- Authorization: `Bearer ${BYPASS_GATEWAY_LOCAL_ONLY_TOKEN}`,
15
- },
16
- });
17
- }
18
-
19
- // Get the global sessionManager - this MUST be available for embedded apps
20
- const sessionManager = (window as any)
21
- .__embeddedSessionManager as SessionManager;
22
-
23
- if (!sessionManager) {
24
- throw new Error(
25
- "[AuthMiddleware] SessionManager not available - embedded provider not initialized",
26
- );
27
- }
28
-
29
- // INVARIANT: This is just an extra check and should never be the case if the sessionManager exists.
30
- if (typeof sessionManager.getToken !== "function") {
31
- throw new Error(
32
- "[AuthMiddleware] SessionManager.getToken is not a function",
33
- );
34
- }
35
-
36
- const token = await sessionManager.getToken();
37
-
38
- return next({
39
- headers: {
40
- Authorization: `Bearer ${token}`,
41
- },
42
- });
43
- });