@hadoku/prefs-client 1.1.30 → 1.1.32
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/index.d.ts +1 -8
- package/dist/index.js +2 -4
- package/dist/people.d.ts +9 -3
- package/dist/people.js +8 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -83,17 +83,10 @@ interface WhoamiResult {
|
|
|
83
83
|
* 'anon' means the key is shared with every other browser user.
|
|
84
84
|
*/
|
|
85
85
|
scope: IdentityScope;
|
|
86
|
-
/**
|
|
87
|
-
* The operator verifies this person (the edge's `isVerified`, the same
|
|
88
|
-
* answer as the `X-Hadoku-Verified` header): every tier above member, and a
|
|
89
|
-
* member the operator made or verified. Present only as `true`; absent
|
|
90
|
-
* means not verified, as the header's absence does.
|
|
91
|
-
*/
|
|
92
|
-
verified?: true;
|
|
93
86
|
/**
|
|
94
87
|
* This browser is a TV (the edge's `isTvUserAgent`, on every answer, signed
|
|
95
88
|
* in or not): an app may start in its 10-foot layout. Present only as
|
|
96
|
-
* `true
|
|
89
|
+
* `true`.
|
|
97
90
|
*/
|
|
98
91
|
tv?: true;
|
|
99
92
|
}
|
package/dist/index.js
CHANGED
|
@@ -131,9 +131,8 @@ function adaptWhoami(body) {
|
|
|
131
131
|
}
|
|
132
132
|
const userType = body.userType === "admin" || body.userType === "wife" || body.userType === "service" || body.userType === "friend" || body.userType === "member" || body.userType === "guest" || body.userType === "public" ? body.userType : "public";
|
|
133
133
|
const name = typeof body.name === "string" ? body.name : null;
|
|
134
|
-
const verified = body.verified === true ? { verified: true } : {};
|
|
135
134
|
if (typeof body.userId === "string" && body.userId) {
|
|
136
|
-
return { userId: body.userId, userType, name, scope: "user", ...
|
|
135
|
+
return { userId: body.userId, userType, name, scope: "user", ...tv };
|
|
137
136
|
}
|
|
138
137
|
if (typeof body.sessionId === "string" && body.sessionId) {
|
|
139
138
|
return {
|
|
@@ -141,11 +140,10 @@ function adaptWhoami(body) {
|
|
|
141
140
|
userType,
|
|
142
141
|
name,
|
|
143
142
|
scope: "session",
|
|
144
|
-
...verified,
|
|
145
143
|
...tv
|
|
146
144
|
};
|
|
147
145
|
}
|
|
148
|
-
return { userId: UNSCOPED_ID, userType, name, scope: "none", ...
|
|
146
|
+
return { userId: UNSCOPED_ID, userType, name, scope: "none", ...tv };
|
|
149
147
|
}
|
|
150
148
|
var WHOAMI_TIMEOUT_MS = 3e3;
|
|
151
149
|
async function fetchWhoamiRaw(url, userKey) {
|
package/dist/people.d.ts
CHANGED
|
@@ -13,8 +13,11 @@ import './cosmetics-contract-CKe1lNNV.js';
|
|
|
13
13
|
* shows within the minute. `fresh` skips the cache (the person has just changed theirs).
|
|
14
14
|
* - **An id asked twice at once is asked once.** A burst of joins after a restart waits on the
|
|
15
15
|
* lookup already in flight for an id rather than starting another.
|
|
16
|
-
* - **A failure answers
|
|
17
|
-
*
|
|
16
|
+
* - **A failure answers with the last answer it had**, however old (within `staleMs`, a day by
|
|
17
|
+
* default), and nobody it never had one for; the failure is not cached, so an outage recovers
|
|
18
|
+
* on the next ask. It is reported (`onError`), never thrown: a missing look costs a face its
|
|
19
|
+
* dressing, not a join. Without the old answer, one slow lookup a minute after the last drew a
|
|
20
|
+
* whole sign-up list as initials until the next one succeeded.
|
|
18
21
|
* - **No key, no lookups** (unless `keyless`, for an e2e stand-in that answers without one).
|
|
19
22
|
*
|
|
20
23
|
* The User-Agent is the caller's: hadoku.me's WAF challenges a bare client one. Each lookup gives
|
|
@@ -32,6 +35,8 @@ interface PeopleLookupOptions {
|
|
|
32
35
|
keyless?: boolean;
|
|
33
36
|
/** How long an answer is kept. Default a minute. */
|
|
34
37
|
ttlMs?: number;
|
|
38
|
+
/** How long past its ttl an answer still stands in for a lookup that failed. Default a day. */
|
|
39
|
+
staleMs?: number;
|
|
35
40
|
/** How long one lookup may take. Default 5 s. */
|
|
36
41
|
timeoutMs?: number;
|
|
37
42
|
/** Told of a failed lookup, with the ids it was for. */
|
|
@@ -42,7 +47,8 @@ interface PeopleLookupOptions {
|
|
|
42
47
|
interface PeopleLookup {
|
|
43
48
|
/**
|
|
44
49
|
* Each id prefs-api answered for, now or within the cache's minute. An id it gave no entry for
|
|
45
|
-
* (an unknown or closed account) is answered `null`; an id the lookup could not reach is
|
|
50
|
+
* (an unknown or closed account) is answered `null`; an id the lookup could not reach is answered
|
|
51
|
+
* as it last was (within `staleMs`), and is absent when it never was.
|
|
46
52
|
*/
|
|
47
53
|
resolve(userIds: readonly string[], opts?: {
|
|
48
54
|
fresh?: boolean;
|
package/dist/people.js
CHANGED
|
@@ -38,12 +38,14 @@ async function resolveAvatars(opts, userIds) {
|
|
|
38
38
|
|
|
39
39
|
// src/people.ts
|
|
40
40
|
var DEFAULT_TTL_MS = 6e4;
|
|
41
|
+
var DEFAULT_STALE_MS = 24 * 60 * 6e4;
|
|
41
42
|
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
42
43
|
var PRUNE_AT = 1024;
|
|
43
44
|
function createPeopleLookup(opts) {
|
|
44
45
|
const now = opts.now ?? Date.now;
|
|
45
46
|
const ttl = opts.ttlMs ?? DEFAULT_TTL_MS;
|
|
46
47
|
const timeout = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
48
|
+
const staleMs = opts.staleMs ?? DEFAULT_STALE_MS;
|
|
47
49
|
const baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
48
50
|
const cache = /* @__PURE__ */ new Map();
|
|
49
51
|
const inflight = /* @__PURE__ */ new Map();
|
|
@@ -59,6 +61,10 @@ function createPeopleLookup(opts) {
|
|
|
59
61
|
const hit = cache.get(userId);
|
|
60
62
|
return hit !== void 0 && hit.expiresAt > now() ? hit.person : void 0;
|
|
61
63
|
};
|
|
64
|
+
const last = (userId) => {
|
|
65
|
+
const hit = cache.get(userId);
|
|
66
|
+
return hit !== void 0 && hit.expiresAt + staleMs > now() ? hit.person : void 0;
|
|
67
|
+
};
|
|
62
68
|
const lookup = (ids) => {
|
|
63
69
|
const run = (async () => {
|
|
64
70
|
try {
|
|
@@ -69,7 +75,7 @@ function createPeopleLookup(opts) {
|
|
|
69
75
|
const at = now();
|
|
70
76
|
for (const id of ids) cache.set(id, { person: answer[id] ?? null, expiresAt: at + ttl });
|
|
71
77
|
if (cache.size > PRUNE_AT) {
|
|
72
|
-
for (const [k, e] of cache) if (e.expiresAt <= at) cache.delete(k);
|
|
78
|
+
for (const [k, e] of cache) if (e.expiresAt + staleMs <= at) cache.delete(k);
|
|
73
79
|
}
|
|
74
80
|
} catch (err) {
|
|
75
81
|
opts.onError?.(err, ids);
|
|
@@ -111,7 +117,7 @@ function createPeopleLookup(opts) {
|
|
|
111
117
|
if (missing.length > 0) waits.push(lookup(missing));
|
|
112
118
|
await Promise.all(waits);
|
|
113
119
|
for (const id of wanted) {
|
|
114
|
-
const hit =
|
|
120
|
+
const hit = last(id);
|
|
115
121
|
if (hit !== void 0) out.set(id, hit);
|
|
116
122
|
}
|
|
117
123
|
return out;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/prefs-client",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "1.1.32",
|
|
4
|
+
"gitHead": "cc5be66d5c8a25721efb205a9a208b544dd55aa7",
|
|
5
5
|
"description": "Client SDK for the hadoku unified preferences store. Wraps /prefs/api/v1/* with localStorage caching, debounced writes, Zod-validated reads, and a usePrefs() React hook, plus match history, ratings and leaderboards for every game (./games), the one resolved avatar per user (./avatar), and the avatar cosmetics renderer (./cosmetics).",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|