@aglyn/tenant-feature-instance 1.0.0-beta.201 → 1.0.0-beta.202
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/tenant-feature-instance",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.202",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.0.0-beta.
|
|
29
|
-
"@aglyn/shared-data-enums": "1.0.0-beta.
|
|
30
|
-
"@aglyn/shared-ui-jsx": "1.0.0-beta.
|
|
31
|
-
"@aglyn/shared-util-http": "1.0.0-beta.
|
|
32
|
-
"@aglyn/shared-util-timestamp": "1.0.0-beta.
|
|
28
|
+
"@aglyn/aglyn": "1.0.0-beta.202",
|
|
29
|
+
"@aglyn/shared-data-enums": "1.0.0-beta.202",
|
|
30
|
+
"@aglyn/shared-ui-jsx": "1.0.0-beta.202",
|
|
31
|
+
"@aglyn/shared-util-http": "1.0.0-beta.202",
|
|
32
|
+
"@aglyn/shared-util-timestamp": "1.0.0-beta.202",
|
|
33
33
|
"@swc/helpers": "0.5.23",
|
|
34
34
|
"lodash-es": "^4.18.1"
|
|
35
35
|
},
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
interface ActorRowLike {
|
|
18
|
+
actorId?: string | null;
|
|
19
|
+
actorEmail?: string | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A site activity feed's rows, each one that recorded a uid and no address
|
|
23
|
+
* given the address that uid holds now as `actorEmailNow` (AGL-3369).
|
|
24
|
+
*
|
|
25
|
+
* The site feeds read `hosts/{hostId}/activity` in the browser, which sees a
|
|
26
|
+
* uid but cannot turn one into an address; `/api/hosts/activity-actors`
|
|
27
|
+
* does, for members of the site and only for uids its log names. Rows render
|
|
28
|
+
* at once and gain the address when it arrives; a failed lookup leaves them
|
|
29
|
+
* as they were, and the presenter names the uid instead.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useResolvedActivityActors<T extends ActorRowLike>(hostId: string | null | undefined, rows: readonly T[]): Array<T & {
|
|
32
|
+
actorEmailNow?: string;
|
|
33
|
+
}>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ import { useEffect, useMemo, useRef, useState } from "react";
|
|
18
|
+
import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
|
|
19
|
+
import { useUser } from "./firebase/firebase-services.js";
|
|
20
|
+
/** What the route resolves per request; a larger page asks in turns. */ const ACTORS_PER_REQUEST = 50;
|
|
21
|
+
/** A uid the row recorded with no address beside it, or null. */ function unaddressedUid(row) {
|
|
22
|
+
if (row.actorEmail) return null;
|
|
23
|
+
const uid = typeof row.actorId === 'string' ? row.actorId.trim() : '';
|
|
24
|
+
return uid && uid !== 'api' && !uid.startsWith('system:') ? uid : null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A site activity feed's rows, each one that recorded a uid and no address
|
|
28
|
+
* given the address that uid holds now as `actorEmailNow` (AGL-3369).
|
|
29
|
+
*
|
|
30
|
+
* The site feeds read `hosts/{hostId}/activity` in the browser, which sees a
|
|
31
|
+
* uid but cannot turn one into an address; `/api/hosts/activity-actors`
|
|
32
|
+
* does, for members of the site and only for uids its log names. Rows render
|
|
33
|
+
* at once and gain the address when it arrives; a failed lookup leaves them
|
|
34
|
+
* as they were, and the presenter names the uid instead.
|
|
35
|
+
*/ export function useResolvedActivityActors(hostId, rows) {
|
|
36
|
+
const { data: user } = useUser();
|
|
37
|
+
const [resolved, setResolved] = useState({});
|
|
38
|
+
// Asked once per site, in a ref: marking a uid asked must not re-run the
|
|
39
|
+
// effect that is still waiting on its answer.
|
|
40
|
+
const asked = useRef(new Set());
|
|
41
|
+
const currentHost = useRef(hostId);
|
|
42
|
+
// A different site is a different log: nothing resolved for one is asked
|
|
43
|
+
// of another's.
|
|
44
|
+
useEffect(()=>{
|
|
45
|
+
currentHost.current = hostId;
|
|
46
|
+
asked.current = new Set();
|
|
47
|
+
setResolved({});
|
|
48
|
+
}, [
|
|
49
|
+
hostId
|
|
50
|
+
]);
|
|
51
|
+
useEffect(()=>{
|
|
52
|
+
if (!hostId || !user) return;
|
|
53
|
+
const fresh = [
|
|
54
|
+
...new Set(rows.map(unaddressedUid).filter((uid)=>Boolean(uid)))
|
|
55
|
+
].filter((uid)=>!asked.current.has(uid));
|
|
56
|
+
if (!fresh.length) return;
|
|
57
|
+
for (const uid of fresh)asked.current.add(uid);
|
|
58
|
+
void (async ()=>{
|
|
59
|
+
for(let start = 0; start < fresh.length; start += ACTORS_PER_REQUEST){
|
|
60
|
+
const url = new URL('/api/hosts/activity-actors', window.location.origin);
|
|
61
|
+
url.searchParams.set('hostId', hostId);
|
|
62
|
+
url.searchParams.set('uids', fresh.slice(start, start + ACTORS_PER_REQUEST).join(','));
|
|
63
|
+
try {
|
|
64
|
+
const response = await authorizedFetch(user, url.toString());
|
|
65
|
+
if (!response.ok) continue;
|
|
66
|
+
const payload = await response.json();
|
|
67
|
+
if (currentHost.current === hostId && payload.actors) {
|
|
68
|
+
setResolved((previous)=>_extends({}, previous, payload.actors));
|
|
69
|
+
}
|
|
70
|
+
} catch (unused) {
|
|
71
|
+
// The row keeps its uid; the presenter names it.
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
})();
|
|
75
|
+
}, [
|
|
76
|
+
hostId,
|
|
77
|
+
user,
|
|
78
|
+
rows
|
|
79
|
+
]);
|
|
80
|
+
return useMemo(()=>rows.map((row)=>{
|
|
81
|
+
const uid = unaddressedUid(row);
|
|
82
|
+
const now = uid ? resolved[uid] : undefined;
|
|
83
|
+
return now ? _extends({}, row, {
|
|
84
|
+
actorEmailNow: now
|
|
85
|
+
}) : row;
|
|
86
|
+
}), [
|
|
87
|
+
rows,
|
|
88
|
+
resolved
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=use-resolved-activity-actors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/tenant/feature/instance/src/lib/hooks/use-resolved-activity-actors.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEffect, useMemo, useRef, useState } from 'react'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { useUser } from './firebase/firebase-services'\n\n/** What the route resolves per request; a larger page asks in turns. */\nconst ACTORS_PER_REQUEST = 50\n\ninterface ActorRowLike {\n actorId?: string | null\n actorEmail?: string | null\n}\n\n/** A uid the row recorded with no address beside it, or null. */\nfunction unaddressedUid(row: ActorRowLike): string | null {\n if (row.actorEmail) return null\n const uid = typeof row.actorId === 'string' ? row.actorId.trim() : ''\n return uid && uid !== 'api' && !uid.startsWith('system:') ? uid : null\n}\n\n/**\n * A site activity feed's rows, each one that recorded a uid and no address\n * given the address that uid holds now as `actorEmailNow` (AGL-3369).\n *\n * The site feeds read `hosts/{hostId}/activity` in the browser, which sees a\n * uid but cannot turn one into an address; `/api/hosts/activity-actors`\n * does, for members of the site and only for uids its log names. Rows render\n * at once and gain the address when it arrives; a failed lookup leaves them\n * as they were, and the presenter names the uid instead.\n */\nexport function useResolvedActivityActors<T extends ActorRowLike>(\n hostId: string | null | undefined,\n rows: readonly T[],\n): Array<T & { actorEmailNow?: string }> {\n const { data: user } = useUser()\n const [resolved, setResolved] = useState<Record<string, string>>({})\n // Asked once per site, in a ref: marking a uid asked must not re-run the\n // effect that is still waiting on its answer.\n const asked = useRef(new Set<string>())\n const currentHost = useRef(hostId)\n\n // A different site is a different log: nothing resolved for one is asked\n // of another's.\n useEffect(() => {\n currentHost.current = hostId\n asked.current = new Set()\n setResolved({})\n }, [hostId])\n\n useEffect(() => {\n if (!hostId || !user) return\n const fresh = [\n ...new Set(rows.map(unaddressedUid).filter((uid): uid is string => Boolean(uid))),\n ].filter((uid) => !asked.current.has(uid))\n if (!fresh.length) return\n for (const uid of fresh) asked.current.add(uid)\n void (async () => {\n for (let start = 0; start < fresh.length; start += ACTORS_PER_REQUEST) {\n const url = new URL('/api/hosts/activity-actors', window.location.origin)\n url.searchParams.set('hostId', hostId)\n url.searchParams.set('uids', fresh.slice(start, start + ACTORS_PER_REQUEST).join(','))\n try {\n const response = await authorizedFetch(user, url.toString())\n if (!response.ok) continue\n const payload = (await response.json()) as { actors?: Record<string, string> }\n if (currentHost.current === hostId && payload.actors) {\n setResolved((previous) => ({ ...previous, ...payload.actors }))\n }\n } catch {\n // The row keeps its uid; the presenter names it.\n }\n }\n })()\n }, [hostId, user, rows])\n\n return useMemo(\n () =>\n rows.map((row) => {\n const uid = unaddressedUid(row)\n const now = uid ? resolved[uid] : undefined\n return now ? { ...row, actorEmailNow: now } : row\n }),\n [rows, resolved],\n )\n}\n"],"names":["useEffect","useMemo","useRef","useState","authorizedFetch","useUser","ACTORS_PER_REQUEST","unaddressedUid","row","actorEmail","uid","actorId","trim","startsWith","useResolvedActivityActors","hostId","rows","data","user","resolved","setResolved","asked","Set","currentHost","current","fresh","map","filter","Boolean","has","length","add","start","url","URL","window","location","origin","searchParams","set","slice","join","response","toString","ok","payload","json","actors","previous","now","undefined","actorEmailNow"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAC5D,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,OAAO,QAAQ,kCAA8B;AAEtD,sEAAsE,GACtE,MAAMC,qBAAqB;AAO3B,+DAA+D,GAC/D,SAASC,eAAeC,GAAiB;IACvC,IAAIA,IAAIC,UAAU,EAAE,OAAO;IAC3B,MAA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