@empoweredvote/ev-ui 0.6.0 → 0.6.2
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.js +78 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2811,13 +2811,14 @@ function onMessage(event) {
|
|
|
2811
2811
|
if (!data || typeof data !== "object") return;
|
|
2812
2812
|
if (data.type === "ev-context:value" || data.type === "ev-context:ack") {
|
|
2813
2813
|
const id = data.requestId;
|
|
2814
|
-
|
|
2814
|
+
const wasPending = id && pendingRequests.has(id);
|
|
2815
|
+
if (wasPending) {
|
|
2815
2816
|
const { resolve, timeout } = pendingRequests.get(id);
|
|
2816
2817
|
clearTimeout(timeout);
|
|
2817
2818
|
pendingRequests.delete(id);
|
|
2818
2819
|
resolve(data.type === "ev-context:value" ? (_a = data.value) != null ? _a : null : data.ok);
|
|
2819
2820
|
}
|
|
2820
|
-
if (data.type === "ev-context:value") {
|
|
2821
|
+
if (data.type === "ev-context:value" && !wasPending) {
|
|
2821
2822
|
lastValue = (_b = data.value) != null ? _b : null;
|
|
2822
2823
|
notifySubscribers();
|
|
2823
2824
|
}
|
|
@@ -2889,6 +2890,81 @@ var evContext = {
|
|
|
2889
2890
|
async clear() {
|
|
2890
2891
|
return send({ type: "ev-context:clear" });
|
|
2891
2892
|
},
|
|
2893
|
+
/**
|
|
2894
|
+
* Read the userId-stamped authed slice for the given user.
|
|
2895
|
+
*
|
|
2896
|
+
* Stored shape:
|
|
2897
|
+
* { compass?, address?, verdicts?, authed?: { userId, compass?, address?, verdicts? } }
|
|
2898
|
+
*
|
|
2899
|
+
* - Returns null if there is no stored value, no `authed` body, or the stored
|
|
2900
|
+
* `authed.userId` does not match the requested `userId` (mismatch = inert).
|
|
2901
|
+
* - Otherwise returns `{ compass, address, verdicts }` with undefined keys
|
|
2902
|
+
* omitted.
|
|
2903
|
+
*
|
|
2904
|
+
* Used by logged-in consumers to do SWR-style hydration: render this slice
|
|
2905
|
+
* synchronously on mount, then replace silently when the API responds.
|
|
2906
|
+
*/
|
|
2907
|
+
async getAuthedSlice(userId) {
|
|
2908
|
+
if (!userId) return null;
|
|
2909
|
+
const current = await this.get();
|
|
2910
|
+
if (!current || !current.authed || typeof current.authed !== "object") return null;
|
|
2911
|
+
if (current.authed.userId !== userId) return null;
|
|
2912
|
+
const out = {};
|
|
2913
|
+
if (current.authed.compass !== void 0) out.compass = current.authed.compass;
|
|
2914
|
+
if (current.authed.address !== void 0) out.address = current.authed.address;
|
|
2915
|
+
if (current.authed.verdicts !== void 0) out.verdicts = current.authed.verdicts;
|
|
2916
|
+
return out;
|
|
2917
|
+
},
|
|
2918
|
+
/**
|
|
2919
|
+
* Mirror an authed write into the userId-stamped `authed` slice.
|
|
2920
|
+
*
|
|
2921
|
+
* - `patch` may contain any subset of `{ compass, address, verdicts }`.
|
|
2922
|
+
* Unrecognized keys are dropped.
|
|
2923
|
+
* - If the existing `authed.userId` matches `userId`, the patch is merged
|
|
2924
|
+
* with the prior authed body (per-domain shallow merge — the patch's
|
|
2925
|
+
* compass/address/verdicts replace the prior values).
|
|
2926
|
+
* - If it does not match (user switch), the prior authed body is stomped.
|
|
2927
|
+
* - Guest top-level keys (compass, address, verdicts at the root) are
|
|
2928
|
+
* preserved untouched.
|
|
2929
|
+
*
|
|
2930
|
+
* Returns false on falsy `userId` or empty patch; otherwise returns the
|
|
2931
|
+
* underlying `set()` result.
|
|
2932
|
+
*/
|
|
2933
|
+
async setAuthedSlice(userId, patch) {
|
|
2934
|
+
if (!userId) return false;
|
|
2935
|
+
if (!patch || typeof patch !== "object") return false;
|
|
2936
|
+
const allowed = {};
|
|
2937
|
+
if (patch.compass !== void 0) allowed.compass = patch.compass;
|
|
2938
|
+
if (patch.address !== void 0) allowed.address = patch.address;
|
|
2939
|
+
if (patch.verdicts !== void 0) allowed.verdicts = patch.verdicts;
|
|
2940
|
+
if (Object.keys(allowed).length === 0) return false;
|
|
2941
|
+
const current = await this.get() || {};
|
|
2942
|
+
const priorAuthed = current.authed && current.authed.userId === userId ? current.authed : null;
|
|
2943
|
+
const nextAuthed = { userId };
|
|
2944
|
+
if (priorAuthed) {
|
|
2945
|
+
if (priorAuthed.compass !== void 0) nextAuthed.compass = priorAuthed.compass;
|
|
2946
|
+
if (priorAuthed.address !== void 0) nextAuthed.address = priorAuthed.address;
|
|
2947
|
+
if (priorAuthed.verdicts !== void 0) nextAuthed.verdicts = priorAuthed.verdicts;
|
|
2948
|
+
}
|
|
2949
|
+
if (allowed.compass !== void 0) nextAuthed.compass = allowed.compass;
|
|
2950
|
+
if (allowed.address !== void 0) nextAuthed.address = allowed.address;
|
|
2951
|
+
if (allowed.verdicts !== void 0) nextAuthed.verdicts = allowed.verdicts;
|
|
2952
|
+
return this.set({ ...current, authed: nextAuthed });
|
|
2953
|
+
},
|
|
2954
|
+
/**
|
|
2955
|
+
* Remove the `authed` slice entirely (preserving guest top-level keys).
|
|
2956
|
+
*
|
|
2957
|
+
* Provided for completeness — consumers in the v2026.4.5 wiring plan must
|
|
2958
|
+
* NOT call this on logout. The slice is intended to go inert via userId
|
|
2959
|
+
* mismatch, so a re-login as the same user can rehydrate from cache.
|
|
2960
|
+
*/
|
|
2961
|
+
async clearAuthedSlice() {
|
|
2962
|
+
const current = await this.get();
|
|
2963
|
+
if (!current || typeof current !== "object") return true;
|
|
2964
|
+
if (!("authed" in current)) return true;
|
|
2965
|
+
const { authed: _omit, ...rest } = current;
|
|
2966
|
+
return this.set(rest);
|
|
2967
|
+
},
|
|
2892
2968
|
/**
|
|
2893
2969
|
* Subscribe to live updates. Fires when this tab or any other tab
|
|
2894
2970
|
* (any subdomain) writes to the store. Returns an unsubscribe function.
|