@myrjfa/state 3.0.9 → 3.0.11
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/lib/actions/auth.d.ts +2 -0
- package/dist/lib/actions/auth.d.ts.map +1 -1
- package/dist/lib/actions/auth.js +9 -0
- package/dist/lib/actions/chat.d.ts +10 -13
- package/dist/lib/actions/chat.d.ts.map +1 -1
- package/dist/lib/actions/chat.js +26 -3
- package/dist/lib/actions/companion.d.ts +134 -59
- package/dist/lib/actions/companion.d.ts.map +1 -1
- package/dist/lib/actions/companion.js +51 -50
- package/dist/lib/actions/companionUpload.d.ts +4 -6
- package/dist/lib/actions/companionUpload.d.ts.map +1 -1
- package/dist/lib/actions/companionUpload.js +2 -1
- package/dist/lib/actions/fetcher.d.ts.map +1 -1
- package/dist/lib/actions/fetcher.js +29 -54
- package/dist/lib/actions/serverActions.d.ts.map +1 -1
- package/dist/lib/actions/serverActions.js +3 -2
- package/dist/lib/actions/user.d.ts +7 -10
- package/dist/lib/actions/user.d.ts.map +1 -1
- package/dist/lib/actions/user.js +2 -2
- package/dist/lib/authSessionManager.d.ts.map +1 -1
- package/dist/lib/authSessionManager.js +42 -39
- package/dist/lib/authSessionPolicy.d.ts +2 -0
- package/dist/lib/authSessionPolicy.d.ts.map +1 -1
- package/dist/lib/authSessionPolicy.js +3 -1
- package/dist/lib/companion/eligibility.d.ts +14 -0
- package/dist/lib/companion/eligibility.d.ts.map +1 -0
- package/dist/lib/companion/eligibility.js +24 -0
- package/dist/lib/context/ChatContext.d.ts +1 -1
- package/dist/lib/context/ChatContext.d.ts.map +1 -1
- package/dist/lib/hooks/useCompanionEligibility.d.ts +13 -0
- package/dist/lib/hooks/useCompanionEligibility.d.ts.map +1 -0
- package/dist/lib/hooks/useCompanionEligibility.js +126 -0
- package/dist/lib/models/chat.d.ts +37 -2
- package/dist/lib/models/chat.d.ts.map +1 -1
- package/dist/lib/models/companion.d.ts +4 -0
- package/dist/lib/models/companion.d.ts.map +1 -1
- package/dist/lib/models/user.d.ts +9 -0
- package/dist/lib/models/user.d.ts.map +1 -1
- package/dist/lib/userAtom.d.ts.map +1 -1
- package/dist/lib/userAtom.js +16 -25
- package/dist/lib/utils/authCookies.d.ts +3 -0
- package/dist/lib/utils/authCookies.d.ts.map +1 -0
- package/dist/lib/utils/authCookies.js +4 -0
- package/package.json +1 -2
package/dist/lib/userAtom.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
import CryptoJS from 'crypto-js';
|
|
3
3
|
import { atom, getDefaultStore } from 'jotai';
|
|
4
4
|
import { atomWithStorage } from 'jotai/utils';
|
|
5
|
-
import {
|
|
6
|
-
import { canFinishAuthCleanup, clearCacheMissSessionBoundary, isAuthSessionPending, } from './authSessionPolicy';
|
|
5
|
+
import { canFinishAuthCleanup, isAuthSessionPending, } from './authSessionPolicy';
|
|
7
6
|
const STORAGE_KEY = process.env.NEXT_PUBLIC_USER_KEY;
|
|
8
7
|
const LOGIN_KEY = process.env.NEXT_PUBLIC_LOGIN_KEY;
|
|
9
8
|
const SECRET_KEY = process.env.NEXT_PUBLIC_RACE;
|
|
@@ -35,11 +34,16 @@ const getWithExpiry = (key) => {
|
|
|
35
34
|
if (!data)
|
|
36
35
|
return null;
|
|
37
36
|
const { value, expiry } = data;
|
|
37
|
+
if (!value || !value._id || typeof value.firstName !== 'string' || !Number.isFinite(expiry))
|
|
38
|
+
return null;
|
|
38
39
|
if (Date.now() > expiry) {
|
|
39
40
|
localStorage.removeItem(key);
|
|
40
41
|
return null;
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
+
const safe = { ...value };
|
|
44
|
+
for (const field of ['devices', 'password', 'accessToken', 'refreshToken', 'emailOtp', 'resetPasswordToken'])
|
|
45
|
+
delete safe[field];
|
|
46
|
+
return safe;
|
|
43
47
|
}
|
|
44
48
|
catch (e) {
|
|
45
49
|
console.warn('Invalid user data:', e);
|
|
@@ -131,32 +135,19 @@ export const initializeAuthSessionAtom = atom(null, async (get, set) => {
|
|
|
131
135
|
// Only run in browser
|
|
132
136
|
if (typeof window === 'undefined')
|
|
133
137
|
return;
|
|
134
|
-
// Try the local identity cache first. It remains provisional until the
|
|
135
|
-
// backend confirms that the cookies belong to the same actor.
|
|
136
138
|
const userData = getWithExpiry(STORAGE_KEY);
|
|
137
139
|
if (userData) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
// Missing persisted identity is always a cleanup boundary. The endpoint
|
|
143
|
-
// is idempotent for a fresh guest and revokes stale cookie-only sessions.
|
|
144
|
-
set(beginAuthCleanupAtom);
|
|
145
|
-
const cleanupRevision = get(authRevisionAtom);
|
|
146
|
-
try {
|
|
147
|
-
await clearCacheMissSessionBoundary({
|
|
148
|
-
cleanupRevision,
|
|
149
|
-
getCurrentRevision: () => get(authRevisionAtom),
|
|
150
|
-
clearSession: clearSessionCookies,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
catch {
|
|
154
|
-
// clearSessionCookies is bounded. Local signed-out state is still
|
|
155
|
-
// published only after the cleanup attempt has settled.
|
|
140
|
+
const safe = { ...userData };
|
|
141
|
+
delete safe.devices;
|
|
142
|
+
set(userAtom, safe);
|
|
143
|
+
set(isLoggedInAtom, true);
|
|
156
144
|
}
|
|
157
|
-
|
|
158
|
-
set(
|
|
145
|
+
else {
|
|
146
|
+
set(userAtom, null);
|
|
147
|
+
set(isLoggedInAtom, false);
|
|
159
148
|
}
|
|
149
|
+
set(storageInitializedAtom, true);
|
|
150
|
+
set(authSessionStatusAtom, "validating");
|
|
160
151
|
});
|
|
161
152
|
export function resetAuthState() {
|
|
162
153
|
if (typeof window === 'undefined') {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authCookies.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/authCookies.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myrjfa/state",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./dist/*": "./dist/*.js"
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@tanstack/react-query": "^5.89.0",
|
|
17
|
-
"@types/socket.io-client": "^3.0.0",
|
|
18
17
|
"cheerio": "^1.0.0",
|
|
19
18
|
"clsx": "^2.1.1",
|
|
20
19
|
"crypto-js": "^4.2.0",
|