@oxyhq/core 17.1.0 → 19.0.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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/boot/sessionColdBoot.js +4 -5
- package/dist/cjs/i18n/locales/en-US.json +48 -5
- package/dist/cjs/i18n/locales/es-ES.json +48 -5
- package/dist/cjs/i18n/locales/locales/en-US.json +48 -5
- package/dist/cjs/i18n/locales/locales/es-ES.json +48 -5
- package/dist/cjs/index.js +10 -6
- package/dist/cjs/mixins/OxyServices.accounts.js +27 -2
- package/dist/cjs/mixins/OxyServices.deviceBoot.js +3 -2
- package/dist/cjs/mixins/OxyServices.user.js +14 -20
- package/dist/cjs/server/index.js +8 -2
- package/dist/cjs/server/userInvalidation.js +6 -28
- package/dist/cjs/session/refresh.js +9 -14
- package/dist/cjs/utils/identityCacheSweep.js +97 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/boot/sessionColdBoot.js +4 -5
- package/dist/esm/i18n/locales/en-US.json +48 -5
- package/dist/esm/i18n/locales/es-ES.json +48 -5
- package/dist/esm/i18n/locales/locales/en-US.json +48 -5
- package/dist/esm/i18n/locales/locales/es-ES.json +48 -5
- package/dist/esm/index.js +1 -1
- package/dist/esm/mixins/OxyServices.accounts.js +22 -1
- package/dist/esm/mixins/OxyServices.deviceBoot.js +3 -2
- package/dist/esm/mixins/OxyServices.user.js +14 -20
- package/dist/esm/server/index.js +5 -1
- package/dist/esm/server/userInvalidation.js +5 -26
- package/dist/esm/session/refresh.js +9 -14
- package/dist/esm/utils/identityCacheSweep.js +92 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/mixins/OxyServices.accounts.d.ts +54 -11
- package/dist/types/mixins/OxyServices.deviceBoot.d.ts +3 -2
- package/dist/types/mixins/OxyServices.user.d.ts +9 -7
- package/dist/types/models/interfaces.d.ts +11 -3
- package/dist/types/server/index.d.ts +4 -2
- package/dist/types/server/userInvalidation.d.ts +5 -24
- package/dist/types/session/refresh.d.ts +13 -18
- package/dist/types/utils/identityCacheSweep.d.ts +80 -0
- package/package.json +2 -2
- package/src/boot/sessionColdBoot.ts +4 -5
- package/src/i18n/locales/en-US.json +48 -5
- package/src/i18n/locales/es-ES.json +48 -5
- package/src/index.ts +8 -3
- package/src/mixins/OxyServices.accounts.ts +73 -12
- package/src/mixins/OxyServices.deviceBoot.ts +3 -2
- package/src/mixins/OxyServices.user.ts +14 -20
- package/src/mixins/__tests__/identityWriteCacheInvalidation.test.ts +370 -0
- package/src/models/interfaces.ts +11 -3
- package/src/server/__tests__/userInvalidation.test.ts +3 -20
- package/src/server/index.ts +5 -2
- package/src/server/userInvalidation.ts +8 -36
- package/src/session/refresh.ts +15 -20
- package/src/utils/__tests__/identityCacheSweep.test.ts +151 -0
- package/src/utils/identityCacheSweep.ts +104 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* THE enumeration of `OxyServices` GET-cache keys that can carry a single
|
|
4
|
+
* account's identity, and the one sweep that clears them.
|
|
5
|
+
*
|
|
6
|
+
* WHY THIS IS ONE LIST
|
|
7
|
+
* --------------------
|
|
8
|
+
* An Oxy account is readable under SEVERAL cache keys, and a write that only
|
|
9
|
+
* busts the key it happens to know about leaves every other one serving the
|
|
10
|
+
* pre-write snapshot for up to its TTL — from the caller's OWN in-memory cache,
|
|
11
|
+
* with a perfectly healthy server. That failure has already shipped twice with
|
|
12
|
+
* two different sets of keys:
|
|
13
|
+
*
|
|
14
|
+
* - `updateAccount` busted `GET:/accounts/<id>` and the account lists, but a
|
|
15
|
+
* profile screen reads `GET:/profiles/username/<name>` and
|
|
16
|
+
* `GET:/users/<id>`, so a channel's new picture stayed invisible for the
|
|
17
|
+
* full 5-minute profile TTL.
|
|
18
|
+
* - `updateProfile` busted four of the six keys below, missing
|
|
19
|
+
* `GET:/auth/lookup/` (the login-flow avatar/display-name lookup) and
|
|
20
|
+
* `GET:/profiles/resolve` (handle resolution) — two independently-drifted
|
|
21
|
+
* copies of a list that has to agree.
|
|
22
|
+
*
|
|
23
|
+
* So the list lives here, once, and every writer calls
|
|
24
|
+
* {@link evictOxyIdentityCache}. Adding a new identity read means adding its key
|
|
25
|
+
* HERE and every writer inherits it.
|
|
26
|
+
*
|
|
27
|
+
* WHERE THE LINE IS DRAWN
|
|
28
|
+
* -----------------------
|
|
29
|
+
* These are the SINGLE-PROFILE reads — the account is the subject of the
|
|
30
|
+
* response and is addressable by id, handle, or session. Reads that merely
|
|
31
|
+
* CONTAIN an account among many (`GET:/profiles/search`,
|
|
32
|
+
* `GET:/users/<other>/followers`, `GET:/profiles/<other>/similar`) are
|
|
33
|
+
* deliberately NOT swept: an account cannot be located in them without the very
|
|
34
|
+
* lookup being invalidated, so sweeping them means sweeping the whole namespace
|
|
35
|
+
* on every identity change — a real cost on a backend consuming the
|
|
36
|
+
* cross-service invalidation signal, for a surface where a stale thumbnail
|
|
37
|
+
* expires on its own in ~2 minutes.
|
|
38
|
+
*
|
|
39
|
+
* WHY PREFIXES RATHER THAN EXACT KEYS
|
|
40
|
+
* -----------------------------------
|
|
41
|
+
* Only the by-id key can be built from a user id. The handle-keyed and
|
|
42
|
+
* session-keyed entries cannot — deriving a handle from an id needs the lookup
|
|
43
|
+
* we are invalidating, and the SDK never tracks active session ids centrally.
|
|
44
|
+
* Prefix sweeping is also what makes a USERNAME CHANGE correct: the entry under
|
|
45
|
+
* the OLD handle is unreachable by construction (nothing in the write response
|
|
46
|
+
* carries it), and a sweep targeted at the new handle alone would leave the old
|
|
47
|
+
* one serving the pre-rename profile until its TTL. Over-eviction costs a
|
|
48
|
+
* refetch; under-eviction serves wrong data.
|
|
49
|
+
*
|
|
50
|
+
* Platform-neutral by construction (no imports, no `OxyServices` reference) so
|
|
51
|
+
* the client mixins and the Node-only `@oxyhq/core/server` invalidation
|
|
52
|
+
* subscriber can share it without either pulling in the other.
|
|
53
|
+
*/
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.OXY_IDENTITY_CACHE_PREFIXES = void 0;
|
|
56
|
+
exports.oxyUserByIdCacheKey = oxyUserByIdCacheKey;
|
|
57
|
+
exports.evictOxyIdentityCache = evictOxyIdentityCache;
|
|
58
|
+
/**
|
|
59
|
+
* Cache-key PREFIXES under which an account's identity can be served, for the
|
|
60
|
+
* reads whose key cannot be derived from a user id. Swept wholesale.
|
|
61
|
+
*/
|
|
62
|
+
exports.OXY_IDENTITY_CACHE_PREFIXES = [
|
|
63
|
+
// `getUserBySession` — keyed by session id, which the SDK never enumerates.
|
|
64
|
+
'GET:/session/user/',
|
|
65
|
+
// `getCurrentUser` (and `GET:/users/me/graph`, harmlessly included).
|
|
66
|
+
'GET:/users/me',
|
|
67
|
+
// `lookupUsername` — the pre-session login lookup; carries avatar + display name.
|
|
68
|
+
'GET:/auth/lookup/',
|
|
69
|
+
// `getProfileByUsername` — keyed by handle, including the pre-rename handle.
|
|
70
|
+
'GET:/profiles/username/',
|
|
71
|
+
// `resolveProfile` — keyed by fediverse handle in the query payload.
|
|
72
|
+
'GET:/profiles/resolve',
|
|
73
|
+
];
|
|
74
|
+
/**
|
|
75
|
+
* Build the exact cache key `getUserById` reads under. The only identity key
|
|
76
|
+
* derivable from a user id, so the only one that does not need a prefix sweep.
|
|
77
|
+
*/
|
|
78
|
+
function oxyUserByIdCacheKey(userId) {
|
|
79
|
+
return `GET:/users/${userId}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Sweep an `OxyServices` GET response cache of everything that could carry the
|
|
83
|
+
* given account's identity.
|
|
84
|
+
*
|
|
85
|
+
* @param oxy - Anything exposing the SDK's two eviction methods.
|
|
86
|
+
* @param userId - The account whose by-id entry to drop. Optional: a caller
|
|
87
|
+
* that does not know the id still clears every handle-, session-
|
|
88
|
+
* and self-keyed entry, which is the majority of the surface.
|
|
89
|
+
*/
|
|
90
|
+
function evictOxyIdentityCache(oxy, userId) {
|
|
91
|
+
for (const prefix of exports.OXY_IDENTITY_CACHE_PREFIXES) {
|
|
92
|
+
oxy.clearCacheByPrefix(prefix);
|
|
93
|
+
}
|
|
94
|
+
if (userId) {
|
|
95
|
+
oxy.clearCacheEntry(oxyUserByIdCacheKey(userId));
|
|
96
|
+
}
|
|
97
|
+
}
|