@empoweredvote/ev-ui 0.6.1 → 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 +75 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2967,6 +2967,81 @@ var evContext = {
|
|
|
2967
2967
|
async clear() {
|
|
2968
2968
|
return send({ type: "ev-context:clear" });
|
|
2969
2969
|
},
|
|
2970
|
+
/**
|
|
2971
|
+
* Read the userId-stamped authed slice for the given user.
|
|
2972
|
+
*
|
|
2973
|
+
* Stored shape:
|
|
2974
|
+
* { compass?, address?, verdicts?, authed?: { userId, compass?, address?, verdicts? } }
|
|
2975
|
+
*
|
|
2976
|
+
* - Returns null if there is no stored value, no `authed` body, or the stored
|
|
2977
|
+
* `authed.userId` does not match the requested `userId` (mismatch = inert).
|
|
2978
|
+
* - Otherwise returns `{ compass, address, verdicts }` with undefined keys
|
|
2979
|
+
* omitted.
|
|
2980
|
+
*
|
|
2981
|
+
* Used by logged-in consumers to do SWR-style hydration: render this slice
|
|
2982
|
+
* synchronously on mount, then replace silently when the API responds.
|
|
2983
|
+
*/
|
|
2984
|
+
async getAuthedSlice(userId) {
|
|
2985
|
+
if (!userId) return null;
|
|
2986
|
+
const current = await this.get();
|
|
2987
|
+
if (!current || !current.authed || typeof current.authed !== "object") return null;
|
|
2988
|
+
if (current.authed.userId !== userId) return null;
|
|
2989
|
+
const out = {};
|
|
2990
|
+
if (current.authed.compass !== void 0) out.compass = current.authed.compass;
|
|
2991
|
+
if (current.authed.address !== void 0) out.address = current.authed.address;
|
|
2992
|
+
if (current.authed.verdicts !== void 0) out.verdicts = current.authed.verdicts;
|
|
2993
|
+
return out;
|
|
2994
|
+
},
|
|
2995
|
+
/**
|
|
2996
|
+
* Mirror an authed write into the userId-stamped `authed` slice.
|
|
2997
|
+
*
|
|
2998
|
+
* - `patch` may contain any subset of `{ compass, address, verdicts }`.
|
|
2999
|
+
* Unrecognized keys are dropped.
|
|
3000
|
+
* - If the existing `authed.userId` matches `userId`, the patch is merged
|
|
3001
|
+
* with the prior authed body (per-domain shallow merge — the patch's
|
|
3002
|
+
* compass/address/verdicts replace the prior values).
|
|
3003
|
+
* - If it does not match (user switch), the prior authed body is stomped.
|
|
3004
|
+
* - Guest top-level keys (compass, address, verdicts at the root) are
|
|
3005
|
+
* preserved untouched.
|
|
3006
|
+
*
|
|
3007
|
+
* Returns false on falsy `userId` or empty patch; otherwise returns the
|
|
3008
|
+
* underlying `set()` result.
|
|
3009
|
+
*/
|
|
3010
|
+
async setAuthedSlice(userId, patch) {
|
|
3011
|
+
if (!userId) return false;
|
|
3012
|
+
if (!patch || typeof patch !== "object") return false;
|
|
3013
|
+
const allowed = {};
|
|
3014
|
+
if (patch.compass !== void 0) allowed.compass = patch.compass;
|
|
3015
|
+
if (patch.address !== void 0) allowed.address = patch.address;
|
|
3016
|
+
if (patch.verdicts !== void 0) allowed.verdicts = patch.verdicts;
|
|
3017
|
+
if (Object.keys(allowed).length === 0) return false;
|
|
3018
|
+
const current = await this.get() || {};
|
|
3019
|
+
const priorAuthed = current.authed && current.authed.userId === userId ? current.authed : null;
|
|
3020
|
+
const nextAuthed = { userId };
|
|
3021
|
+
if (priorAuthed) {
|
|
3022
|
+
if (priorAuthed.compass !== void 0) nextAuthed.compass = priorAuthed.compass;
|
|
3023
|
+
if (priorAuthed.address !== void 0) nextAuthed.address = priorAuthed.address;
|
|
3024
|
+
if (priorAuthed.verdicts !== void 0) nextAuthed.verdicts = priorAuthed.verdicts;
|
|
3025
|
+
}
|
|
3026
|
+
if (allowed.compass !== void 0) nextAuthed.compass = allowed.compass;
|
|
3027
|
+
if (allowed.address !== void 0) nextAuthed.address = allowed.address;
|
|
3028
|
+
if (allowed.verdicts !== void 0) nextAuthed.verdicts = allowed.verdicts;
|
|
3029
|
+
return this.set({ ...current, authed: nextAuthed });
|
|
3030
|
+
},
|
|
3031
|
+
/**
|
|
3032
|
+
* Remove the `authed` slice entirely (preserving guest top-level keys).
|
|
3033
|
+
*
|
|
3034
|
+
* Provided for completeness — consumers in the v2026.4.5 wiring plan must
|
|
3035
|
+
* NOT call this on logout. The slice is intended to go inert via userId
|
|
3036
|
+
* mismatch, so a re-login as the same user can rehydrate from cache.
|
|
3037
|
+
*/
|
|
3038
|
+
async clearAuthedSlice() {
|
|
3039
|
+
const current = await this.get();
|
|
3040
|
+
if (!current || typeof current !== "object") return true;
|
|
3041
|
+
if (!("authed" in current)) return true;
|
|
3042
|
+
const { authed: _omit, ...rest } = current;
|
|
3043
|
+
return this.set(rest);
|
|
3044
|
+
},
|
|
2970
3045
|
/**
|
|
2971
3046
|
* Subscribe to live updates. Fires when this tab or any other tab
|
|
2972
3047
|
* (any subdomain) writes to the store. Returns an unsubscribe function.
|