@oxyhq/core 19.0.0 → 19.1.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/i18n/locales/en-US.json +1 -0
- package/dist/cjs/i18n/locales/es-ES.json +1 -0
- package/dist/cjs/i18n/locales/locales/en-US.json +1 -0
- package/dist/cjs/i18n/locales/locales/es-ES.json +1 -0
- package/dist/cjs/index.js +9 -2
- package/dist/cjs/mixins/OxyServices.accounts.js +42 -29
- package/dist/cjs/mixins/OxyServices.followGraph.js +204 -0
- package/dist/cjs/mixins/OxyServices.user.js +7 -4
- package/dist/cjs/mixins/index.js +4 -0
- package/dist/cjs/session/accountProjection.js +45 -9
- package/dist/cjs/utils/accountCacheSweep.js +80 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/i18n/locales/en-US.json +1 -0
- package/dist/esm/i18n/locales/es-ES.json +1 -0
- package/dist/esm/i18n/locales/locales/en-US.json +1 -0
- package/dist/esm/i18n/locales/locales/es-ES.json +1 -0
- package/dist/esm/index.js +7 -1
- package/dist/esm/mixins/OxyServices.accounts.js +42 -29
- package/dist/esm/mixins/OxyServices.followGraph.js +201 -0
- package/dist/esm/mixins/OxyServices.user.js +7 -4
- package/dist/esm/mixins/index.js +4 -0
- package/dist/esm/session/accountProjection.js +44 -9
- package/dist/esm/utils/accountCacheSweep.js +75 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/mixins/OxyServices.accounts.d.ts +52 -27
- package/dist/types/mixins/OxyServices.followGraph.d.ts +211 -0
- package/dist/types/mixins/OxyServices.user.d.ts +5 -4
- package/dist/types/mixins/index.d.ts +2 -1
- package/dist/types/session/accountProjection.d.ts +38 -4
- package/dist/types/utils/accountCacheSweep.d.ts +75 -0
- package/package.json +2 -2
- package/src/i18n/locales/en-US.json +1 -0
- package/src/i18n/locales/es-ES.json +1 -0
- package/src/index.ts +8 -1
- package/src/mixins/OxyServices.accounts.ts +65 -38
- package/src/mixins/OxyServices.followGraph.ts +266 -0
- package/src/mixins/OxyServices.user.ts +7 -4
- package/src/mixins/__tests__/accounts.test.ts +5 -0
- package/src/mixins/__tests__/followGraph.test.ts +128 -0
- package/src/mixins/__tests__/identityWriteCacheInvalidation.test.ts +37 -0
- package/src/mixins/index.ts +5 -0
- package/src/session/__tests__/accountProjection.test.ts +109 -2
- package/src/session/accountProjection.ts +47 -9
- package/src/utils/accountCacheSweep.ts +93 -0
package/dist/esm/index.js
CHANGED
|
@@ -173,7 +173,13 @@ export { deviceStateToClientSessions, activeSessionIdOf, activeUserOf, accountId
|
|
|
173
173
|
// chooser: device sign-ins ∪ account graph, deduped by accountId). Pure +
|
|
174
174
|
// I/O-free — the caller hydrates profiles via `getUsersByIds`. Shared by
|
|
175
175
|
// `@oxyhq/services` and auth.oxy.so so the list can't diverge.
|
|
176
|
-
|
|
176
|
+
// `isSwitchTargetAccount` is the switcher's own question ("can I become this
|
|
177
|
+
// account?"), exported so a surface that renders `AccountNode`s rather than the
|
|
178
|
+
// projection — the Console's workspace switcher, the accounts app's
|
|
179
|
+
// managed-accounts rows — asks the SAME question instead of testing a kind
|
|
180
|
+
// literal. It is NOT `isActAsEligibleKind`: that one is false for `personal`
|
|
181
|
+
// too, so gating a switcher on it alone empties the list.
|
|
182
|
+
export { isSwitchTargetAccount, projectSwitchableAccounts, switchableAccountIds, } from './session/accountProjection.js';
|
|
177
183
|
// Headless controller for the unified account dialog. Framework-agnostic
|
|
178
184
|
// state machine + subscribe/getSnapshot store (bind via `useSyncExternalStore`)
|
|
179
185
|
// — sign-in is passkey (WebAuthn) or the Commons QR / shared-keychain handoff;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { normalizeUserIdentity } from '../utils/userIdentity.js';
|
|
2
2
|
import { evictOxyIdentityCache } from '../utils/identityCacheSweep.js';
|
|
3
|
+
import { evictOxyAccountForestCache, oxyAccountDetailCacheKey, OXY_ACCOUNT_PER_ACCOUNT_CACHE_PREFIX } from '../utils/accountCacheSweep.js';
|
|
3
4
|
import { CACHE_TIMES } from './mixinHelpers.js';
|
|
4
5
|
export { ACCOUNT_CATEGORY_IDS, ACCOUNT_KINDS, MAX_ACCOUNT_CATEGORIES, SELECTABLE_ACCOUNT_CATEGORY_IDS, isActAsEligibleKind, isSelectableAccountCategoryId, kindAcceptsAccountCategories, } from '@oxyhq/contracts';
|
|
5
6
|
export function OxyServicesAccountsMixin(Base) {
|
|
@@ -113,7 +114,7 @@ export function OxyServicesAccountsMixin(Base) {
|
|
|
113
114
|
const res = await this.makeRequest('POST', '/accounts', data, { cache: false });
|
|
114
115
|
// A new account changes the accessible forest — bust every cached list
|
|
115
116
|
// (flat + tree) so it appears on the next `listAccounts()` read.
|
|
116
|
-
this
|
|
117
|
+
evictOxyAccountForestCache(this);
|
|
117
118
|
return res.account;
|
|
118
119
|
}
|
|
119
120
|
catch (error) {
|
|
@@ -179,8 +180,7 @@ export function OxyServicesAccountsMixin(Base) {
|
|
|
179
180
|
const res = await this.makeRequest('PATCH', `/accounts/${encodeURIComponent(accountId)}`, data, { cache: false });
|
|
180
181
|
// Bust the cached detail and every list (which embeds account profile
|
|
181
182
|
// data) so neither serves the pre-update snapshot.
|
|
182
|
-
this
|
|
183
|
-
this._invalidateAccountLists();
|
|
183
|
+
evictOxyAccountForestCache(this, accountId);
|
|
184
184
|
// The parent's children list embeds this account's profile and is keyed
|
|
185
185
|
// by the PARENT id, so it is reachable only from the response node.
|
|
186
186
|
const parentAccountId = res.account?.parentAccountId;
|
|
@@ -205,10 +205,9 @@ export function OxyServicesAccountsMixin(Base) {
|
|
|
205
205
|
try {
|
|
206
206
|
const result = await this.makeRequest('DELETE', `/accounts/${encodeURIComponent(accountId)}`, undefined, { cache: false });
|
|
207
207
|
// Bust every cached representation of the archived account.
|
|
208
|
-
this.clearCacheEntry(`GET:/accounts/${encodeURIComponent(accountId)}`);
|
|
209
208
|
this.clearCacheEntry(`GET:/accounts/${encodeURIComponent(accountId)}/members`);
|
|
210
209
|
this.clearCacheEntry(`GET:/accounts/${encodeURIComponent(accountId)}/credentials`);
|
|
211
|
-
this
|
|
210
|
+
evictOxyAccountForestCache(this, accountId);
|
|
212
211
|
return result;
|
|
213
212
|
}
|
|
214
213
|
catch (error) {
|
|
@@ -232,7 +231,27 @@ export function OxyServicesAccountsMixin(Base) {
|
|
|
232
231
|
// Account members
|
|
233
232
|
// =========================================================================
|
|
234
233
|
/**
|
|
235
|
-
* List members of an account
|
|
234
|
+
* List the members of an account: the membership rows ON it, plus the rows
|
|
235
|
+
* on its ancestors that cascade into it. Each entry carries `source`
|
|
236
|
+
* (`direct` | `inherited`) saying which it is.
|
|
237
|
+
*
|
|
238
|
+
* Inherited entries are members in every sense the server enforces — an
|
|
239
|
+
* ancestor row with `inherit: true` resolves through
|
|
240
|
+
* `resolveEffectiveAccess` and confers every account permission on the
|
|
241
|
+
* descendant, `account:act_as` included — so a roster that omitted them
|
|
242
|
+
* answered `[]` for accounts several people could act on.
|
|
243
|
+
*
|
|
244
|
+
* Two things follow for a caller. An entry's `accountId` is the account its
|
|
245
|
+
* ROW lives on, so an inherited entry names an ancestor rather than the
|
|
246
|
+
* account you asked about; and the member-mutation endpoints only accept
|
|
247
|
+
* rows on the account in the path, so gate any edit/remove/transfer
|
|
248
|
+
* affordance on `source === 'direct'`.
|
|
249
|
+
*
|
|
250
|
+
* Asking what the CALLER holds over an account is a different question, and
|
|
251
|
+
* scanning this list for yourself is the wrong way to answer it — use
|
|
252
|
+
* {@link OxyServicesAccountsMixin.getAccount}, whose `callerMembership` is
|
|
253
|
+
* the server's own resolution.
|
|
254
|
+
*
|
|
236
255
|
* @param accountId - The account's Mongo `_id`.
|
|
237
256
|
*/
|
|
238
257
|
async listAccountMembers(accountId) {
|
|
@@ -303,7 +322,7 @@ export function OxyServicesAccountsMixin(Base) {
|
|
|
303
322
|
// Ownership change alters roles in the member list AND the detail, and
|
|
304
323
|
// can change which accounts the caller "owns" in the list view.
|
|
305
324
|
this._invalidateAccountMembership(accountId);
|
|
306
|
-
this
|
|
325
|
+
evictOxyAccountForestCache(this);
|
|
307
326
|
return result;
|
|
308
327
|
}
|
|
309
328
|
catch (error) {
|
|
@@ -547,35 +566,29 @@ export function OxyServicesAccountsMixin(Base) {
|
|
|
547
566
|
// Cache-invalidation helpers
|
|
548
567
|
// =========================================================================
|
|
549
568
|
/**
|
|
550
|
-
* Bust
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* unscoped entry plus every `?`-query variant via a prefix sweep. The prefix
|
|
555
|
-
* `GET:/accounts?` matches only the query-string list variants, never the
|
|
556
|
-
* `GET:/accounts/<id>…` detail/sub-resource keys.
|
|
569
|
+
* Bust the cached member list and detail for an account after a membership
|
|
570
|
+
* mutation. The member list (`listAccountMembers`) and the detail
|
|
571
|
+
* (`getAccount`, which can embed the caller's membership) both go stale when
|
|
572
|
+
* the member set or a member's role changes.
|
|
557
573
|
*
|
|
558
574
|
* Internal helper (leading underscore); not part of the supported public
|
|
559
575
|
* surface. Public rather than `private` because mixins compose into an
|
|
560
576
|
* exported anonymous class, where TypeScript cannot represent a private
|
|
561
577
|
* member in the emitted declaration file (TS4094).
|
|
562
|
-
*/
|
|
563
|
-
_invalidateAccountLists() {
|
|
564
|
-
this.clearCacheEntry('GET:/accounts');
|
|
565
|
-
this.clearCacheByPrefix('GET:/accounts?');
|
|
566
|
-
}
|
|
567
|
-
/**
|
|
568
|
-
* Bust the cached member list and detail for an account after a membership
|
|
569
|
-
* mutation. The member list (`listAccountMembers`) and the detail
|
|
570
|
-
* (`getAccount`, which can embed the caller's membership) both go stale when
|
|
571
|
-
* the member set or a member's role changes.
|
|
572
578
|
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
579
|
+
* The forest keys themselves are NOT owned here — see
|
|
580
|
+
* `utils/accountCacheSweep`, which the user mixin has to reach as well.
|
|
575
581
|
*/
|
|
576
582
|
_invalidateAccountMembership(accountId) {
|
|
577
583
|
this.clearCacheEntry(`GET:/accounts/${encodeURIComponent(accountId)}/members`);
|
|
578
|
-
this.clearCacheEntry(
|
|
584
|
+
this.clearCacheEntry(oxyAccountDetailCacheKey(accountId));
|
|
585
|
+
// Inherited rows on descendant rosters are derived from this account's
|
|
586
|
+
// membership table — a targeted clear of only the mutated account's keys
|
|
587
|
+
// leaves every other cached `…/members` list serving stale inherited
|
|
588
|
+
// roles until MEDIUM TTL. Sweep all per-account sub-resource keys instead;
|
|
589
|
+
// the forest list keys (`GET:/accounts`, `GET:/accounts?…`) are excluded
|
|
590
|
+
// by the trailing slash on the prefix (see accountCacheSweep).
|
|
591
|
+
this.clearCacheByPrefix(OXY_ACCOUNT_PER_ACCOUNT_CACHE_PREFIX);
|
|
579
592
|
}
|
|
580
593
|
/**
|
|
581
594
|
* Bust every cached application list. `listAccountApps(accountId)` keys each
|
|
@@ -586,8 +599,8 @@ export function OxyServicesAccountsMixin(Base) {
|
|
|
586
599
|
* query-string list variants, never the `GET:/applications/<id>…`
|
|
587
600
|
* detail/sub-resource keys.
|
|
588
601
|
*
|
|
589
|
-
* Internal helper (leading underscore); see `
|
|
590
|
-
* this is public rather than `private`.
|
|
602
|
+
* Internal helper (leading underscore); see `_invalidateAccountMembership`
|
|
603
|
+
* for why this is public rather than `private`.
|
|
591
604
|
*/
|
|
592
605
|
_invalidateAppLists() {
|
|
593
606
|
this.clearCacheEntry('GET:/applications');
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Follow Graph Mixin (`/v2/follows`)
|
|
3
|
+
*
|
|
4
|
+
* The user-owned follow graph: one relationship per user and target, shared by
|
|
5
|
+
* every application, with per-application context on top. This is the SDK half
|
|
6
|
+
* of #809 and the replacement for the per-app follow endpoints each application
|
|
7
|
+
* grew for itself.
|
|
8
|
+
*
|
|
9
|
+
* ## Why this is not `followUser` with more parameters
|
|
10
|
+
*
|
|
11
|
+
* `followUser` answers "does A follow B" and nothing else. This answers "what
|
|
12
|
+
* does this user follow, anywhere, and which applications act on it" — a
|
|
13
|
+
* different question with a different owner. The legacy methods stay for the
|
|
14
|
+
* Mongo-backed social graph they were written for; new kinds (topics, stores,
|
|
15
|
+
* artists, channels) come here, and users will migrate behind an adapter rather
|
|
16
|
+
* than through a flag day.
|
|
17
|
+
*
|
|
18
|
+
* ## Caching
|
|
19
|
+
*
|
|
20
|
+
* Every method is `cache: false`. A follow status is exactly the shape that
|
|
21
|
+
* must never be served stale: the SDK's GET cache is identity-scoped but
|
|
22
|
+
* time-based, and a status cached across a write is the "follow reverts after
|
|
23
|
+
* navigating away and back" bug — which the legacy `followUser` had to fix with
|
|
24
|
+
* explicit invalidation. Not caching at this layer means an app's own store
|
|
25
|
+
* (React Query, Zustand) is the single cache authority, which is the rule the
|
|
26
|
+
* ecosystem already follows for anything written and read in the same session.
|
|
27
|
+
*/
|
|
28
|
+
import { buildUrl } from '../utils/apiUtils.js';
|
|
29
|
+
export function OxyServicesFollowGraphMixin(Base) {
|
|
30
|
+
return class extends Base {
|
|
31
|
+
constructor(...args) {
|
|
32
|
+
super(...args);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Follow a target. Idempotent — following something already followed
|
|
36
|
+
* returns the same relationship with `created: false`.
|
|
37
|
+
*
|
|
38
|
+
* The follower and the acting application are BOTH derived server-side from
|
|
39
|
+
* the session. There is deliberately no parameter for either: a client that
|
|
40
|
+
* could name them could forge a follow on another user's behalf, or record
|
|
41
|
+
* one as coming from an application it is not.
|
|
42
|
+
*
|
|
43
|
+
* @param targetId - The registered target's id, not its URI. Registration is
|
|
44
|
+
* a separate operation precisely so following cannot silently create
|
|
45
|
+
* targets — a typo would otherwise become a permanent row nobody follows.
|
|
46
|
+
* @param options.expiresIn - Seconds until the follow lapses on its own. For
|
|
47
|
+
* an event, a trial, a topic followed for a week. The server bounds it.
|
|
48
|
+
*/
|
|
49
|
+
async followTarget(targetId, options) {
|
|
50
|
+
try {
|
|
51
|
+
return await this.makeRequest('PUT', `/v2/follows/${encodeURIComponent(targetId)}`, options?.expiresIn !== undefined ? { expiresIn: options.expiresIn } : {}, { cache: false });
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
throw this.handleError(error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Unfollow everywhere.
|
|
59
|
+
*
|
|
60
|
+
* There is no "unfollow here" — that is `setFollowApplicationMode(...,
|
|
61
|
+
* 'disabled')`, and keeping the two distinct is the point of the design. An
|
|
62
|
+
* application that quietly turned a global unfollow into a local one would
|
|
63
|
+
* leave the user believing they had stopped following something they still
|
|
64
|
+
* follow everywhere else.
|
|
65
|
+
*
|
|
66
|
+
* Idempotent: `removed: false` when it was already gone, because the state
|
|
67
|
+
* the caller asked for is the state that holds.
|
|
68
|
+
*/
|
|
69
|
+
async unfollowTarget(relationshipId) {
|
|
70
|
+
try {
|
|
71
|
+
return await this.makeRequest('DELETE', `/v2/follows/${encodeURIComponent(relationshipId)}`, undefined, { cache: false });
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw this.handleError(error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The three-part status: globally, in this application, and in effect.
|
|
79
|
+
*
|
|
80
|
+
* Render `effectiveState` on the button and keep the other two for the
|
|
81
|
+
* explanation. A UI that collapses them cannot tell the user why a follow
|
|
82
|
+
* they can see in their list is not showing up in this app's feed.
|
|
83
|
+
*/
|
|
84
|
+
async getFollowTargetStatus(targetId) {
|
|
85
|
+
try {
|
|
86
|
+
return await this.makeRequest('GET', `/v2/follows/${encodeURIComponent(targetId)}/status`, undefined, { cache: false });
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throw this.handleError(error);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Turn a relationship off, or back on, in ONE application.
|
|
94
|
+
*
|
|
95
|
+
* Omit `applicationId` and it applies to the calling application, which is
|
|
96
|
+
* the only form an ordinary app should ever need. Naming a DIFFERENT
|
|
97
|
+
* application requires `follows:manage` server-side — acting on another
|
|
98
|
+
* app's behalf is exactly the cross-application authority this design
|
|
99
|
+
* otherwise refuses, so it is a distinct permission and not a parameter an
|
|
100
|
+
* app happens to fill in.
|
|
101
|
+
*/
|
|
102
|
+
async setFollowApplicationMode(relationshipId, mode, applicationId) {
|
|
103
|
+
try {
|
|
104
|
+
return await this.makeRequest('PUT', `/v2/follows/${encodeURIComponent(relationshipId)}/context`, { mode, ...(applicationId ? { applicationId } : {}) }, { cache: false });
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
throw this.handleError(error);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Drop the override so this application follows the global relationship
|
|
112
|
+
* again. Distinct from setting `enabled`: inheriting means a later global
|
|
113
|
+
* change takes effect here, and an explicit `enabled` means it does not.
|
|
114
|
+
*/
|
|
115
|
+
async restoreFollowInheritance(relationshipId, applicationId) {
|
|
116
|
+
try {
|
|
117
|
+
const path = buildUrl(`/v2/follows/${encodeURIComponent(relationshipId)}/context`, applicationId ? { applicationId } : {});
|
|
118
|
+
return await this.makeRequest('DELETE', path, undefined, { cache: false });
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
throw this.handleError(error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolve a target by canonical URI, registering it the first time anyone
|
|
126
|
+
* asks. The call an application makes on the way into a screen, before it
|
|
127
|
+
* can render a button.
|
|
128
|
+
*
|
|
129
|
+
* Idempotent on the URI, which is what makes two applications describing
|
|
130
|
+
* the same thing — the same fediverse actor, the same topic — arrive at ONE
|
|
131
|
+
* row, and therefore at one relationship per user rather than one per app.
|
|
132
|
+
*
|
|
133
|
+
* `metadata` is a display snapshot (name, handle, icon) and is refreshed
|
|
134
|
+
* only for the application that provides the target: a second application
|
|
135
|
+
* passing its own idea of the name would make the display flip depending on
|
|
136
|
+
* which app last looked.
|
|
137
|
+
*/
|
|
138
|
+
async ensureFollowTarget(input) {
|
|
139
|
+
try {
|
|
140
|
+
return await this.makeRequest('POST', '/v2/follow-targets', input, { cache: false });
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
throw this.handleError(error);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Claim a namespace for the calling application. First come, and idempotent
|
|
148
|
+
* for the holder — an application that registers on every boot must not
|
|
149
|
+
* fail the second time.
|
|
150
|
+
*/
|
|
151
|
+
async claimFollowNamespace(namespace) {
|
|
152
|
+
try {
|
|
153
|
+
return await this.makeRequest('POST', '/v2/follow-targets/namespaces', { namespace }, { cache: false });
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
throw this.handleError(error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Declare what following a kind of thing MEANS: the verb clients render,
|
|
161
|
+
* whether reverse lookups are public, whether it federates.
|
|
162
|
+
*
|
|
163
|
+
* Declared once by the application that owns the concept, rather than
|
|
164
|
+
* passed per call site — otherwise two screens of one app can disagree
|
|
165
|
+
* about whether a store is followed or subscribed to.
|
|
166
|
+
*/
|
|
167
|
+
async registerFollowKind(input) {
|
|
168
|
+
try {
|
|
169
|
+
return await this.makeRequest('POST', '/v2/follow-targets/kinds', input, {
|
|
170
|
+
cache: false,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
throw this.handleError(error);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Everything the signed-in user follows, newest first.
|
|
179
|
+
*
|
|
180
|
+
* Owner-only by construction server-side — there is no parameter naming a
|
|
181
|
+
* user, so this cannot be pointed at somebody else's graph.
|
|
182
|
+
*
|
|
183
|
+
* Paginate by passing back `nextCursor`, never an offset: the list changes
|
|
184
|
+
* while it is being read, and an offset silently skips or repeats rows
|
|
185
|
+
* exactly when it does.
|
|
186
|
+
*/
|
|
187
|
+
async listFollows(params) {
|
|
188
|
+
try {
|
|
189
|
+
const path = buildUrl('/v2/me/follows', {
|
|
190
|
+
...(params?.kind ? { kind: params.kind } : {}),
|
|
191
|
+
...(params?.cursor ? { cursor: params.cursor } : {}),
|
|
192
|
+
...(params?.limit ? { limit: params.limit } : {}),
|
|
193
|
+
});
|
|
194
|
+
return await this.makeRequest('GET', path, undefined, { cache: false });
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
throw this.handleError(error);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
@@ -4,6 +4,7 @@ import { KeyManager } from '../crypto/keyManager.js';
|
|
|
4
4
|
import { SignatureService } from '../crypto/signatureService.js';
|
|
5
5
|
import { normalizeUserIdentity, normalizeUserIdentityOrNull } from '../utils/userIdentity.js';
|
|
6
6
|
import { evictOxyIdentityCache } from '../utils/identityCacheSweep.js';
|
|
7
|
+
import { evictOxyAccountForestCache } from '../utils/accountCacheSweep.js';
|
|
7
8
|
import { logger } from '../logger/index.js';
|
|
8
9
|
import { extractErrorStatus } from '../utils/errorUtils.js';
|
|
9
10
|
/**
|
|
@@ -350,10 +351,11 @@ export function OxyServicesUserMixin(Base) {
|
|
|
350
351
|
* a new identity read is added in one place instead of to each writer
|
|
351
352
|
* separately (this method's own hand-written copy had already drifted from
|
|
352
353
|
* the server-side one, missing `GET /auth/lookup/*` and
|
|
353
|
-
* `GET /profiles/resolve`).
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
354
|
+
* `GET /profiles/resolve`). The account forest (`GET /accounts` and the
|
|
355
|
+
* caller's own detail row) is swept too — a personal account IS this user,
|
|
356
|
+
* and `AccountNode.account` embeds the whole profile — from the list that
|
|
357
|
+
* {@link evictOxyAccountForestCache} owns, for the same reason: the accounts
|
|
358
|
+
* mixin writes those keys as well, and two hand-written copies drift.
|
|
357
359
|
*
|
|
358
360
|
* TanStack Query handles offline queuing automatically.
|
|
359
361
|
*/
|
|
@@ -361,6 +363,7 @@ export function OxyServicesUserMixin(Base) {
|
|
|
361
363
|
try {
|
|
362
364
|
const result = normalizeUserIdentity(await this.makeRequest('PUT', '/users/me', updates, { cache: false }));
|
|
363
365
|
evictOxyIdentityCache(this, result?.id);
|
|
366
|
+
evictOxyAccountForestCache(this, result?.id);
|
|
364
367
|
return result;
|
|
365
368
|
}
|
|
366
369
|
catch (error) {
|
package/dist/esm/mixins/index.js
CHANGED
|
@@ -29,6 +29,7 @@ import { OxyServicesAppDataMixin } from './OxyServices.appData.js';
|
|
|
29
29
|
import { OxyServicesCivicMixin } from './OxyServices.civic.js';
|
|
30
30
|
import { OxyServicesNodesMixin } from './OxyServices.nodes.js';
|
|
31
31
|
import { OxyServicesLinksMixin } from './OxyServices.links.js';
|
|
32
|
+
import { OxyServicesFollowGraphMixin } from './OxyServices.followGraph.js';
|
|
32
33
|
import { OxyServicesDeviceBootMixin } from './OxyServices.deviceBoot.js';
|
|
33
34
|
import { OxyServicesDeviceTransferMixin } from './OxyServices.deviceTransfer.js';
|
|
34
35
|
/**
|
|
@@ -85,6 +86,9 @@ const MIXIN_PIPELINE = [
|
|
|
85
86
|
// Link previews / unfurls: SDK-owned link-metadata resolution via oxy-api,
|
|
86
87
|
// so apps stop scraping link metadata locally.
|
|
87
88
|
OxyServicesLinksMixin,
|
|
89
|
+
// The user-owned follow graph (#809). One relationship per user and target,
|
|
90
|
+
// shared across applications, with per-application context on top.
|
|
91
|
+
OxyServicesFollowGraphMixin,
|
|
88
92
|
// Device-first token mint: the client half of the zero-cookie transport
|
|
89
93
|
// (`mintFromDeviceSecret` → `POST /session/device/token`).
|
|
90
94
|
OxyServicesDeviceBootMixin,
|
|
@@ -19,6 +19,35 @@
|
|
|
19
19
|
import { isActAsEligibleKind } from '@oxyhq/contracts';
|
|
20
20
|
import { getAccountDisplayName, getAccountFallbackHandle } from '../utils/accountUtils.js';
|
|
21
21
|
import { getNormalizedUserHandle } from '../utils/userHandle.js';
|
|
22
|
+
/**
|
|
23
|
+
* Whether the caller can BECOME this account — the one question every account
|
|
24
|
+
* switcher asks, answered here so no surface has to re-derive it.
|
|
25
|
+
*
|
|
26
|
+
* Two independent grounds, either of which suffices:
|
|
27
|
+
*
|
|
28
|
+
* - **It is already the caller's own identity** (`relationship: 'self'`).
|
|
29
|
+
* `GET /accounts` resolves its caller through `resolveOperatorId`, so `self`
|
|
30
|
+
* is the HUMAN operator's personal account even while they are operating an
|
|
31
|
+
* org — never the operated account. Kind is irrelevant on this ground: the
|
|
32
|
+
* caller IS that account, so returning to it asks the server for nothing.
|
|
33
|
+
* - **The server will mint a session for it** — `isActAsEligibleKind(kind)` is
|
|
34
|
+
* the exact predicate `POST /accounts/:id/switch` enforces, so a row offered
|
|
35
|
+
* on this ground is never a dead button.
|
|
36
|
+
*
|
|
37
|
+
* `isActAsEligibleKind` ALONE is not this question, and reaching for it
|
|
38
|
+
* directly is the mistake this function exists to prevent: it is false for
|
|
39
|
+
* `personal` as well as `channel`, so a switcher gated on it alone renders an
|
|
40
|
+
* empty list rather than a filtered one. Equally, `kind !== 'channel'` is not
|
|
41
|
+
* this question either — it silently admits every kind invented after it was
|
|
42
|
+
* written, which is the same trap `isActAsEligibleKind` was introduced to close
|
|
43
|
+
* on the server.
|
|
44
|
+
*
|
|
45
|
+
* Takes a structural subset rather than a whole {@link AccountNode} so a caller
|
|
46
|
+
* holding a projected {@link SwitchableAccount} can ask it too.
|
|
47
|
+
*/
|
|
48
|
+
export function isSwitchTargetAccount(node) {
|
|
49
|
+
return node.relationship === 'self' || isActAsEligibleKind(node.kind);
|
|
50
|
+
}
|
|
22
51
|
/**
|
|
23
52
|
* Pure union of device sign-ins and account-graph nodes into the flat
|
|
24
53
|
* {@link SwitchableAccount}[] every switcher renders.
|
|
@@ -28,8 +57,9 @@ import { getNormalizedUserHandle } from '../utils/userHandle.js';
|
|
|
28
57
|
* and a graph node is deduped into ONE device row enriched with the graph
|
|
29
58
|
* metadata (relationship / kind / parent / membership).
|
|
30
59
|
*
|
|
31
|
-
* Graph nodes
|
|
32
|
-
*
|
|
60
|
+
* Graph nodes that are not switch targets — a `channel`, which nobody may act
|
|
61
|
+
* as — are omitted. {@link isSwitchTargetAccount} is the rule; see the filter
|
|
62
|
+
* below.
|
|
33
63
|
*/
|
|
34
64
|
export function projectSwitchableAccounts(input) {
|
|
35
65
|
const { state, graph, profilesById, activeUser, locale, resolveAvatarUrl } = input;
|
|
@@ -104,10 +134,12 @@ export function projectSwitchableAccounts(input) {
|
|
|
104
134
|
// construction": the graph contributes accounts that have no device session
|
|
105
135
|
// and no credentials at all, which is exactly how an org first becomes
|
|
106
136
|
// switchable. So a kind that must never be switched into has to be filtered
|
|
107
|
-
// HERE
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
|
|
137
|
+
// HERE — offering a row the server would 403 is a dead button.
|
|
138
|
+
//
|
|
139
|
+
// An account already on the device skipped this check via the branch above,
|
|
140
|
+
// and correctly: whatever its kind, the caller is signed into it, so
|
|
141
|
+
// switching is a local activation that asks the server for nothing.
|
|
142
|
+
if (!isSwitchTargetAccount(node)) {
|
|
111
143
|
continue;
|
|
112
144
|
}
|
|
113
145
|
remember(toRow(node.account, {
|
|
@@ -129,8 +161,11 @@ export function projectSwitchableAccounts(input) {
|
|
|
129
161
|
* document, but including their ids lets the caller pass one id set and lets the
|
|
130
162
|
* projection prefer freshly-fetched profiles uniformly.
|
|
131
163
|
*
|
|
132
|
-
* Applies the SAME
|
|
133
|
-
* nodes, so this never fetches a
|
|
164
|
+
* Applies the SAME {@link isSwitchTargetAccount} filter as
|
|
165
|
+
* {@link projectSwitchableAccounts} to graph nodes, so this never fetches a
|
|
166
|
+
* profile for a row the projection will drop — and, just as importantly, never
|
|
167
|
+
* SKIPS one the projection will keep, which would leave that row unrendered
|
|
168
|
+
* until some later fetch happened to resolve it.
|
|
134
169
|
*/
|
|
135
170
|
export function switchableAccountIds(state, graph) {
|
|
136
171
|
const ids = new Set();
|
|
@@ -140,7 +175,7 @@ export function switchableAccountIds(state, graph) {
|
|
|
140
175
|
}
|
|
141
176
|
}
|
|
142
177
|
for (const node of graph) {
|
|
143
|
-
if (node.accountId &&
|
|
178
|
+
if (node.accountId && isSwitchTargetAccount(node)) {
|
|
144
179
|
ids.add(node.accountId);
|
|
145
180
|
}
|
|
146
181
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE enumeration of `OxyServices` GET-cache keys that serve the ACCOUNT FOREST
|
|
3
|
+
* — the caller's accessible accounts, as lists and as individual detail rows —
|
|
4
|
+
* and the one sweep that clears them.
|
|
5
|
+
*
|
|
6
|
+
* WHY THIS IS NOT A METHOD ON THE ACCOUNTS MIXIN
|
|
7
|
+
* ---------------------------------------------
|
|
8
|
+
* `AccountNode.account` is a whole `User`, so a forest read embeds the very
|
|
9
|
+
* profile the identity reads serve. That makes an IDENTITY write a writer of
|
|
10
|
+
* these keys too: `updateProfile` edits the caller's own personal account,
|
|
11
|
+
* which is a row in `GET /accounts` and is its own `GET /accounts/<id>`. Leave
|
|
12
|
+
* those cached and the account switcher keeps drawing the pre-edit name and
|
|
13
|
+
* picture for the full TTL, against a perfectly healthy server.
|
|
14
|
+
*
|
|
15
|
+
* The mixins compose into one class at runtime but are typed one at a time, so
|
|
16
|
+
* the user mixin cannot call a method the accounts mixin owns. The key list
|
|
17
|
+
* therefore lives here, once, and every writer calls {@link
|
|
18
|
+
* evictOxyAccountForestCache} — exactly like the identity key list in
|
|
19
|
+
* `identityCacheSweep`, which the accounts mixin already calls for the
|
|
20
|
+
* mirror-image case (an account write staling the identity reads). The
|
|
21
|
+
* alternative — a second hand-written copy of these keys in the other mixin —
|
|
22
|
+
* is the drift that shipped the two stale-profile bugs `identityCacheSweep`
|
|
23
|
+
* documents.
|
|
24
|
+
*
|
|
25
|
+
* WHY THE LIST NEEDS A PREFIX AND THE DETAIL DOES NOT
|
|
26
|
+
* --------------------------------------------------
|
|
27
|
+
* `listAccounts({tree?})` keys the flat list as `GET:/accounts` and every
|
|
28
|
+
* option variant as `GET:/accounts?<query>` (the query string is part of the
|
|
29
|
+
* URL, hence of the key), and a writer cannot enumerate which variants a caller
|
|
30
|
+
* has read. The detail key, by contrast, is derivable from the account id the
|
|
31
|
+
* writer already holds.
|
|
32
|
+
*
|
|
33
|
+
* The `GET:/accounts?` prefix matches ONLY the query-string list variants —
|
|
34
|
+
* never `GET:/accounts/<id>` or its `…/members`, `…/credentials`, `…/children`
|
|
35
|
+
* sub-resources, which are the accounts mixin's own business and stay there.
|
|
36
|
+
*/
|
|
37
|
+
/** The cache key `listAccounts()` reads under with no options. */
|
|
38
|
+
export const OXY_ACCOUNT_LIST_CACHE_KEY = 'GET:/accounts';
|
|
39
|
+
/**
|
|
40
|
+
* The prefix covering every option-carrying `listAccounts(opts)` variant
|
|
41
|
+
* (`?tree=true`, …), none of which a writer can enumerate.
|
|
42
|
+
*/
|
|
43
|
+
export const OXY_ACCOUNT_LIST_CACHE_QUERY_PREFIX = 'GET:/accounts?';
|
|
44
|
+
/**
|
|
45
|
+
* Prefix covering every per-account sub-resource cache key
|
|
46
|
+
* (`GET:/accounts/<id>`, `…/members`, `…/credentials`, `…/children`). A
|
|
47
|
+
* membership mutation on an ancestor must sweep ALL of these, not only the
|
|
48
|
+
* account named in the path: descendant member rosters embed inherited rows
|
|
49
|
+
* resolved from that ancestor, and the writer cannot enumerate which descendant
|
|
50
|
+
* ids a caller has already read. The trailing slash deliberately excludes the
|
|
51
|
+
* forest list keys (`GET:/accounts`, `GET:/accounts?…`) documented above.
|
|
52
|
+
*/
|
|
53
|
+
export const OXY_ACCOUNT_PER_ACCOUNT_CACHE_PREFIX = 'GET:/accounts/';
|
|
54
|
+
/**
|
|
55
|
+
* Build the exact cache key `getAccount(accountId)` reads under.
|
|
56
|
+
*/
|
|
57
|
+
export function oxyAccountDetailCacheKey(accountId) {
|
|
58
|
+
return `GET:/accounts/${encodeURIComponent(accountId)}`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Sweep an `OxyServices` GET response cache of the account forest.
|
|
62
|
+
*
|
|
63
|
+
* @param oxy - Anything exposing the SDK's two eviction methods.
|
|
64
|
+
* @param accountId - The account whose detail row to drop as well. Optional: a
|
|
65
|
+
* writer that changed the SHAPE of the forest rather than one
|
|
66
|
+
* account in it (create, archive, ownership transfer) has no
|
|
67
|
+
* detail row to name, and clears only the lists.
|
|
68
|
+
*/
|
|
69
|
+
export function evictOxyAccountForestCache(oxy, accountId) {
|
|
70
|
+
oxy.clearCacheEntry(OXY_ACCOUNT_LIST_CACHE_KEY);
|
|
71
|
+
oxy.clearCacheByPrefix(OXY_ACCOUNT_LIST_CACHE_QUERY_PREFIX);
|
|
72
|
+
if (accountId) {
|
|
73
|
+
oxy.clearCacheEntry(oxyAccountDetailCacheKey(accountId));
|
|
74
|
+
}
|
|
75
|
+
}
|