@every-app/sdk 0.1.0 → 0.1.2
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 +9 -0
- package/dist/core/sessionManager.d.ts.map +1 -1
- package/dist/core/sessionManager.js +31 -0
- package/dist/tanstack/_internal/useEveryAppSession.d.ts.map +1 -1
- package/dist/tanstack/_internal/useEveryAppSession.js +8 -1
- package/package.json +2 -1
- package/src/tanstack/_internal/useEveryAppSession.tsx +13 -7
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @every-app/sdk
|
|
2
|
+
|
|
3
|
+
The embedded SDK for building apps on the Every App platform.
|
|
4
|
+
|
|
5
|
+
This SDK handles authentication and session management for apps running within the Every App Gateway. It provides integrations for TanStack Start and Cloudflare Workers.
|
|
6
|
+
|
|
7
|
+
## Documentation
|
|
8
|
+
|
|
9
|
+
For full API reference and usage guides, see the [Embedded SDK documentation](https://everyapp.dev/docs/embedded-sdk/overview/).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionManager.d.ts","sourceRoot":"","sources":["../../src/core/sessionManager.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;CACf;AAMD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAQ3C;AAED,qBAAa,cAAc;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,cAAc,CAAgC;gBAE1C,MAAM,EAAE,oBAAoB;IAqBxC,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,uBAAuB;
|
|
1
|
+
{"version":3,"file":"sessionManager.d.ts","sourceRoot":"","sources":["../../src/core/sessionManager.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;CACf;AAMD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAQ3C;AAED,qBAAa,cAAc;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,cAAc,CAAgC;gBAE1C,MAAM,EAAE,oBAAoB;IAqBxC,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,uBAAuB;IAuDzB,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IA+DlC,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAOjC,aAAa,IAAI;QACf,MAAM,EAAE,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,YAAY,CAAC;QACxD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;KACtB;IAgBD;;;OAGG;IACH,OAAO,IAAI;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CAwBpD"}
|
|
@@ -46,6 +46,7 @@ export class SessionManager {
|
|
|
46
46
|
}
|
|
47
47
|
postMessageWithResponse(request, responseType, requestId) {
|
|
48
48
|
return new Promise((resolve, reject) => {
|
|
49
|
+
const startTime = Date.now();
|
|
49
50
|
const cleanup = () => {
|
|
50
51
|
clearTimeout(timeout);
|
|
51
52
|
window.removeEventListener("message", handler);
|
|
@@ -60,6 +61,11 @@ export class SessionManager {
|
|
|
60
61
|
if (event.data.type === responseType &&
|
|
61
62
|
event.data.requestId === requestId) {
|
|
62
63
|
cleanup();
|
|
64
|
+
console.log("[SessionManager] postMessage response received", {
|
|
65
|
+
requestId,
|
|
66
|
+
responseType,
|
|
67
|
+
elapsedMs: Date.now() - startTime,
|
|
68
|
+
});
|
|
63
69
|
if (event.data.error) {
|
|
64
70
|
reject(new Error(event.data.error));
|
|
65
71
|
}
|
|
@@ -70,18 +76,38 @@ export class SessionManager {
|
|
|
70
76
|
};
|
|
71
77
|
const timeout = setTimeout(() => {
|
|
72
78
|
cleanup();
|
|
79
|
+
console.log("[SessionManager] postMessage response timeout", {
|
|
80
|
+
requestId,
|
|
81
|
+
responseType,
|
|
82
|
+
timeoutMs: MESSAGE_TIMEOUT_MS,
|
|
83
|
+
});
|
|
73
84
|
reject(new Error("Token request timeout - parent did not respond"));
|
|
74
85
|
}, MESSAGE_TIMEOUT_MS);
|
|
75
86
|
window.addEventListener("message", handler);
|
|
87
|
+
console.log("[SessionManager] postMessage request sent", {
|
|
88
|
+
requestId,
|
|
89
|
+
requestType: request.type,
|
|
90
|
+
parentOrigin: this.parentOrigin,
|
|
91
|
+
});
|
|
76
92
|
window.parent.postMessage(request, this.parentOrigin);
|
|
77
93
|
});
|
|
78
94
|
}
|
|
79
95
|
async requestNewToken() {
|
|
80
96
|
if (this.refreshPromise) {
|
|
97
|
+
console.log("[SessionManager] Reusing in-flight token request", {
|
|
98
|
+
appId: this.appId,
|
|
99
|
+
});
|
|
81
100
|
return this.refreshPromise;
|
|
82
101
|
}
|
|
83
102
|
this.refreshPromise = (async () => {
|
|
84
103
|
const requestId = crypto.randomUUID();
|
|
104
|
+
const startTime = Date.now();
|
|
105
|
+
console.log("[SessionManager] Requesting new session token", {
|
|
106
|
+
requestId,
|
|
107
|
+
appId: this.appId,
|
|
108
|
+
parentOrigin: this.parentOrigin,
|
|
109
|
+
isInIframe: this.isInIframe,
|
|
110
|
+
});
|
|
85
111
|
const response = await this.postMessageWithResponse({
|
|
86
112
|
type: "SESSION_TOKEN_REQUEST",
|
|
87
113
|
requestId,
|
|
@@ -102,6 +128,11 @@ export class SessionManager {
|
|
|
102
128
|
token: response.token,
|
|
103
129
|
expiresAt,
|
|
104
130
|
};
|
|
131
|
+
console.log("[SessionManager] Session token stored", {
|
|
132
|
+
requestId,
|
|
133
|
+
elapsedMs: Date.now() - startTime,
|
|
134
|
+
expiresAt,
|
|
135
|
+
});
|
|
105
136
|
return this.token.token;
|
|
106
137
|
})();
|
|
107
138
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEveryAppSession.d.ts","sourceRoot":"","sources":["../../../src/tanstack/_internal/useEveryAppSession.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,oBAAoB,EACrB,MAAM,2BAA2B,CAAC;AAEnC,UAAU,wBAAwB;IAChC,oBAAoB,EAAE,oBAAoB,CAAC;CAC5C;AAED,wBAAgB,kBAAkB,CAAC,EACjC,oBAAoB,GACrB,EAAE,wBAAwB;;;;;;
|
|
1
|
+
{"version":3,"file":"useEveryAppSession.d.ts","sourceRoot":"","sources":["../../../src/tanstack/_internal/useEveryAppSession.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,oBAAoB,EACrB,MAAM,2BAA2B,CAAC;AAEnC,UAAU,wBAAwB;IAChC,oBAAoB,EAAE,oBAAoB,CAAC;CAC5C;AAED,wBAAgB,kBAAkB,CAAC,EACjC,oBAAoB,GACrB,EAAE,wBAAwB;;;;;;EAiD1B"}
|
|
@@ -16,9 +16,16 @@ export function useEveryAppSession({ sessionManagerConfig, }) {
|
|
|
16
16
|
// Skip token requests when not in iframe - the app will show GatewayRequiredError instead
|
|
17
17
|
if (!sessionManager.isInIframe)
|
|
18
18
|
return;
|
|
19
|
+
console.log("[EmbeddedProvider] Initializing session token flow", {
|
|
20
|
+
appId: sessionManager.appId,
|
|
21
|
+
parentOrigin: sessionManager.parentOrigin,
|
|
22
|
+
});
|
|
19
23
|
const interval = setInterval(() => {
|
|
20
|
-
|
|
24
|
+
const tokenState = sessionManager.getTokenState();
|
|
25
|
+
console.log("[EmbeddedProvider] Session token state", tokenState);
|
|
26
|
+
setSessionTokenState(tokenState);
|
|
21
27
|
}, 5000);
|
|
28
|
+
console.log("[EmbeddedProvider] Requesting initial session token");
|
|
22
29
|
sessionManager.getToken().catch((err) => {
|
|
23
30
|
console.error("[EmbeddedProvider] Initial token request failed:", err);
|
|
24
31
|
});
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { SessionManager } from "../../core/sessionManager";
|
|
3
|
+
|
|
4
|
+
interface SessionManagerConfig {
|
|
5
|
+
appId: string;
|
|
6
|
+
}
|
|
6
7
|
|
|
7
8
|
interface UseEveryAppSessionParams {
|
|
8
9
|
sessionManagerConfig: SessionManagerConfig;
|
|
@@ -34,9 +35,14 @@ export function useEveryAppSession({
|
|
|
34
35
|
setSessionTokenState(sessionManager.getTokenState());
|
|
35
36
|
}, 5000);
|
|
36
37
|
|
|
37
|
-
sessionManager
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
sessionManager
|
|
39
|
+
.getToken()
|
|
40
|
+
.then(() => {
|
|
41
|
+
setSessionTokenState(sessionManager.getTokenState());
|
|
42
|
+
})
|
|
43
|
+
.catch((err) => {
|
|
44
|
+
console.error("[EmbeddedProvider] Initial token request failed:", err);
|
|
45
|
+
});
|
|
40
46
|
|
|
41
47
|
return () => {
|
|
42
48
|
clearInterval(interval);
|