@softr/sdk 0.0.21 → 0.0.22-alpha.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.
- package/dist/auth/session.d.ts +16 -0
- package/dist/auth/session.js +25 -8
- package/dist/server.d.ts +2 -1
- package/dist/server.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "./context.js";
|
|
2
|
+
|
|
3
|
+
//#region src/auth/session.d.ts
|
|
4
|
+
|
|
5
|
+
declare function makeSessionTokenCookie(token: string, secure?: boolean): string;
|
|
6
|
+
/** The clearing pair, for the same out-of-context caller as `makeSessionTokenCookie`. */
|
|
7
|
+
declare function makeSessionClearingCookies(secure: boolean): Array<string>;
|
|
8
|
+
/**
|
|
9
|
+
* The name `readSessionToken` would look the token up under on a request of this
|
|
10
|
+
* scheme, for a caller that only needs to know whether one is present and cannot
|
|
11
|
+
* decode it. Same `secure` argument as `makeSessionTokenCookie`, so a caller that
|
|
12
|
+
* writes and a caller that probes cannot disagree about the name.
|
|
13
|
+
*/
|
|
14
|
+
declare function sessionTokenCookieName(secure: boolean): string;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { makeSessionClearingCookies, makeSessionTokenCookie, sessionTokenCookieName };
|
package/dist/auth/session.js
CHANGED
|
@@ -19,10 +19,13 @@ const HOST_PREFIX = "__Host-";
|
|
|
19
19
|
function requestIsSecure() {
|
|
20
20
|
return getRequestProtocol() === "https";
|
|
21
21
|
}
|
|
22
|
+
function sessionCookieName(base, secure) {
|
|
23
|
+
return secure ? HOST_PREFIX + base : base;
|
|
24
|
+
}
|
|
22
25
|
function sessionCookie(base) {
|
|
23
26
|
const secure = requestIsSecure();
|
|
24
27
|
return {
|
|
25
|
-
name:
|
|
28
|
+
name: sessionCookieName(base, secure),
|
|
26
29
|
secure
|
|
27
30
|
};
|
|
28
31
|
}
|
|
@@ -43,9 +46,8 @@ function readSessionData(sessionToken) {
|
|
|
43
46
|
permissions: payload.permissions
|
|
44
47
|
};
|
|
45
48
|
}
|
|
46
|
-
function makeSessionTokenCookie(token) {
|
|
47
|
-
|
|
48
|
-
return serializeCookie(name, sealEnvelope(token, SESSION_TOKEN), {
|
|
49
|
+
function makeSessionTokenCookie(token, secure = requestIsSecure()) {
|
|
50
|
+
return serializeCookie(sessionCookieName(SESSION_TOKEN, secure), sealEnvelope(token, SESSION_TOKEN), {
|
|
49
51
|
maxAge: sessionConfig().sessionMaxAge,
|
|
50
52
|
secure
|
|
51
53
|
});
|
|
@@ -69,6 +71,19 @@ function makeSessionDataCookie(session, sessionToken) {
|
|
|
69
71
|
function clearSession() {
|
|
70
72
|
clearCookies([SESSION_TOKEN, SESSION_DATA]);
|
|
71
73
|
}
|
|
74
|
+
/** The clearing pair, for the same out-of-context caller as `makeSessionTokenCookie`. */
|
|
75
|
+
function makeSessionClearingCookies(secure) {
|
|
76
|
+
return serializeClearingCookies([SESSION_TOKEN, SESSION_DATA], secure);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The name `readSessionToken` would look the token up under on a request of this
|
|
80
|
+
* scheme, for a caller that only needs to know whether one is present and cannot
|
|
81
|
+
* decode it. Same `secure` argument as `makeSessionTokenCookie`, so a caller that
|
|
82
|
+
* writes and a caller that probes cannot disagree about the name.
|
|
83
|
+
*/
|
|
84
|
+
function sessionTokenCookieName(secure) {
|
|
85
|
+
return sessionCookieName(SESSION_TOKEN, secure);
|
|
86
|
+
}
|
|
72
87
|
const sessionDataSchema = z.object({
|
|
73
88
|
user: userSchema.nullable(),
|
|
74
89
|
permissions: permissionsSchema,
|
|
@@ -80,11 +95,13 @@ const sessionDataSchema = z.object({
|
|
|
80
95
|
* schemes, and the one left behind would revive if the scheme changed back.
|
|
81
96
|
*/
|
|
82
97
|
function clearCookies(bases) {
|
|
83
|
-
|
|
84
|
-
|
|
98
|
+
writeCookies(serializeClearingCookies(bases, requestIsSecure()));
|
|
99
|
+
}
|
|
100
|
+
function serializeClearingCookies(bases, secure) {
|
|
101
|
+
return bases.flatMap((base) => secure ? [sessionCookieName(base, secure), base] : [base]).map((name) => serializeCookie(name, "", {
|
|
85
102
|
maxAge: 0,
|
|
86
103
|
secure
|
|
87
|
-
}))
|
|
104
|
+
}));
|
|
88
105
|
}
|
|
89
106
|
/**
|
|
90
107
|
* Over the plaintext token, never the cookie value: that is resealed with a
|
|
@@ -160,4 +177,4 @@ function openEnvelope(raw, purpose) {
|
|
|
160
177
|
}
|
|
161
178
|
|
|
162
179
|
//#endregion
|
|
163
|
-
export { clearSession, makeSessionDataCookie, makeSessionTokenCookie, readSessionData, readSessionToken };
|
|
180
|
+
export { clearSession, makeSessionClearingCookies, makeSessionDataCookie, makeSessionTokenCookie, readSessionData, readSessionToken, sessionTokenCookieName };
|
package/dist/server.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import { auth } from "./auth/server.js";
|
|
|
2
2
|
import { ds } from "./core/datasource.js";
|
|
3
3
|
import { workflow } from "./core/workflow.js";
|
|
4
4
|
import { integration } from "./core/integration.js";
|
|
5
|
+
import { makeSessionClearingCookies, makeSessionTokenCookie, sessionTokenCookieName } from "./auth/session.js";
|
|
5
6
|
import "@tanstack/react-start/server-only";
|
|
6
|
-
export { auth, ds, integration, workflow };
|
|
7
|
+
export { auth, ds, integration, makeSessionClearingCookies, makeSessionTokenCookie, sessionTokenCookieName, workflow };
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { makeSessionClearingCookies, makeSessionTokenCookie, sessionTokenCookieName } from "./auth/session.js";
|
|
1
2
|
import { auth } from "./auth/server.js";
|
|
2
3
|
import { ds } from "./core/datasource.js";
|
|
3
4
|
import { workflow } from "./core/workflow.js";
|
|
4
5
|
import { integration } from "./core/integration.js";
|
|
5
6
|
import "@tanstack/react-start/server-only";
|
|
6
7
|
|
|
7
|
-
export { auth, ds, integration, workflow };
|
|
8
|
+
export { auth, ds, integration, makeSessionClearingCookies, makeSessionTokenCookie, sessionTokenCookieName, workflow };
|