monoidentity 0.31.3 → 0.31.5

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.
@@ -0,0 +1,27 @@
1
+ //#region src/storageclient.svelte.d.ts
2
+ declare const SYNC_REQUEST_EVENT = "monoidentity-sync-request";
3
+ declare const STORAGE_EVENT = "monoidentity-storage";
4
+ type StorageEventDetail = {
5
+ key: string;
6
+ value: string | undefined;
7
+ isSync: boolean;
8
+ };
9
+ declare global {
10
+ interface WindowEventMap {
11
+ 'monoidentity-storage': CustomEvent<StorageEventDetail>;
12
+ }
13
+ }
14
+ declare const storageClient: (prefix?: (key: string) => string, unprefix?: (key: string) => string | undefined, serialize?: (data: any) => string, deserialize?: (data: string) => any, isSyncContext?: boolean) => Record<string, any>;
15
+ //#endregion
16
+ //#region src/index.d.ts
17
+ declare const getLoginRecognized: () => {
18
+ email: string;
19
+ password: string;
20
+ };
21
+ declare const setLoginRecognized: (login: string) => void;
22
+ declare const openHub: (path: string) => never;
23
+ declare const relog: () => never;
24
+ declare const getStorage: (realm: "config" | "userdata" | "cache" | (string & {})) => Record<string, any>;
25
+ declare const getScopedFS: (dir: string) => Record<string, any>;
26
+ //#endregion
27
+ export { STORAGE_EVENT, SYNC_REQUEST_EVENT, storageClient as _storageClient, getLoginRecognized, getScopedFS, getStorage, openHub, relog, setLoginRecognized };
package/dist/index.mjs ADDED
@@ -0,0 +1,40 @@
1
+ import { n as SYNC_REQUEST_EVENT, r as storageClient, t as STORAGE_EVENT } from "./storageclient.svelte-B-JE-dGU.mjs";
2
+ import { parse, stringify } from "devalue";
3
+ import { email, object, parse as parse$1, pipe, string } from "valibot";
4
+ import { decode } from "base36-esm";
5
+
6
+ //#region src/index.ts
7
+ const loginSchema = object({
8
+ email: pipe(string(), email()),
9
+ password: string()
10
+ });
11
+ const LOGIN_RECOGNIZED_PATH = ".local/login.encjson";
12
+ const getLoginRecognized = () => {
13
+ const login = storageClient()[LOGIN_RECOGNIZED_PATH];
14
+ if (!login) throw new Error("No login found");
15
+ return parse$1(loginSchema, JSON.parse(decode(login)));
16
+ };
17
+ const setLoginRecognized = (login) => {
18
+ const client = storageClient();
19
+ client[LOGIN_RECOGNIZED_PATH] = login;
20
+ };
21
+ const isLocalhostHost = (host) => host == "localhost" || host == "127.0.0.1" || host == "0.0.0.0" || host == "[::1]" || host.endsWith(".localhost");
22
+ const openHub = (path) => {
23
+ const target = new URL(`https://monoidentity.web.app/${path}`);
24
+ if (isLocalhostHost(location.hostname)) {
25
+ const redirectParams = new URLSearchParams();
26
+ redirectParams.set("redirect", location.origin);
27
+ target.hash = redirectParams.toString();
28
+ }
29
+ location.href = target.toString();
30
+ throw new Error("relogging");
31
+ };
32
+ const relog = () => openHub(MONOIDENTITY_APP_ID);
33
+ const getStorage = (realm) => {
34
+ const prefix = `.${realm}/${MONOIDENTITY_APP_ID}/`;
35
+ return storageClient((key) => `${prefix}${key}.devalue`, (key) => key.startsWith(prefix) ? key.slice(prefix.length, -8) : void 0, stringify, parse);
36
+ };
37
+ const getScopedFS = (dir) => storageClient((key) => `${dir}/${key}`, (key) => key.startsWith(dir + "/") ? key.slice(dir.length + 1) : void 0);
38
+
39
+ //#endregion
40
+ export { STORAGE_EVENT, SYNC_REQUEST_EVENT, storageClient as _storageClient, getLoginRecognized, getScopedFS, getStorage, openHub, relog, setLoginRecognized };
@@ -0,0 +1,5 @@
1
+ //#region src/receive-callback.d.ts
2
+ declare const loaded: boolean;
3
+ declare const monoidentitysync: string | undefined;
4
+ //#endregion
5
+ export { loaded, monoidentitysync };
@@ -0,0 +1,12 @@
1
+ import { setLoginRecognized } from "./index.mjs";
2
+
3
+ //#region src/receive-callback.ts
4
+ const params = new URLSearchParams(location.hash.slice(1));
5
+ const monoidentityloginrecognized = params.get("monoidentityloginrecognized");
6
+ if (monoidentityloginrecognized) setLoginRecognized(monoidentityloginrecognized);
7
+ const loaded = Boolean(params.size);
8
+ if (loaded) history.replaceState(null, "", location.pathname);
9
+ const monoidentitysync = params.get("monoidentitysync") || void 0;
10
+
11
+ //#endregion
12
+ export { loaded, monoidentitysync };
@@ -0,0 +1,86 @@
1
+ //#region src/storageclient.svelte.ts
2
+ const SYNC_REQUEST_EVENT = "monoidentity-sync-request";
3
+ const STORAGE_EVENT = "monoidentity-storage";
4
+ const waitForSync = async (key) => {
5
+ await new Promise((resolve, reject) => window.dispatchEvent(new CustomEvent(SYNC_REQUEST_EVENT, { detail: {
6
+ key,
7
+ resolve,
8
+ reject
9
+ } })));
10
+ };
11
+ const announce = (key, value, isSync = false) => {
12
+ window.dispatchEvent(new CustomEvent(STORAGE_EVENT, { detail: {
13
+ key,
14
+ value,
15
+ isSync
16
+ } }));
17
+ };
18
+ const storageCounters = $state({});
19
+ let allCounter = $state(0);
20
+ const increment = (key) => {
21
+ storageCounters[key] = (storageCounters[key] || 0) + 1;
22
+ allCounter++;
23
+ };
24
+ addEventListener(STORAGE_EVENT, (event) => increment(event.detail.key));
25
+ addEventListener("storage", (event) => {
26
+ if (event.storageArea != localStorage) return;
27
+ if (!event.key) return;
28
+ increment(event.key);
29
+ });
30
+ const storageClient = (prefix, unprefix, serialize, deserialize, isSyncContext = false) => {
31
+ if (prefix) {
32
+ const oldPrefix = prefix;
33
+ prefix = (key) => `monoidentity/${oldPrefix(key)}`;
34
+ } else prefix = (key) => `monoidentity/${key}`;
35
+ const getScopedKeys = () => {
36
+ const keys = [];
37
+ for (const key in localStorage) {
38
+ if (!key.startsWith("monoidentity/")) continue;
39
+ let scopedKey = key.slice(13);
40
+ if (unprefix) {
41
+ const unprefixed = unprefix(scopedKey);
42
+ if (!unprefixed) continue;
43
+ scopedKey = unprefixed;
44
+ }
45
+ keys.push(scopedKey);
46
+ }
47
+ return keys;
48
+ };
49
+ return new Proxy({}, {
50
+ get(_, key) {
51
+ if (typeof key == "symbol") return void 0;
52
+ if (key == "sync") return async (userKey) => {
53
+ await waitForSync(prefix(userKey));
54
+ };
55
+ key = prefix(key);
56
+ storageCounters[key];
57
+ const raw = localStorage[key];
58
+ return raw && deserialize ? deserialize(raw) : raw;
59
+ },
60
+ set(_, key, value) {
61
+ key = prefix(key);
62
+ if (serialize) value = serialize(value);
63
+ if (localStorage[key] != value) {
64
+ localStorage[key] = value;
65
+ announce(key, value, isSyncContext);
66
+ } else console.debug("[monoidentity storage] noop for", key);
67
+ return true;
68
+ },
69
+ deleteProperty(_, key) {
70
+ key = prefix(key);
71
+ delete localStorage[key];
72
+ announce(key, void 0, isSyncContext);
73
+ return true;
74
+ },
75
+ ownKeys() {
76
+ return getScopedKeys();
77
+ },
78
+ getOwnPropertyDescriptor(_, key) {
79
+ key = prefix(key);
80
+ return Reflect.getOwnPropertyDescriptor(localStorage, key);
81
+ }
82
+ });
83
+ };
84
+
85
+ //#endregion
86
+ export { SYNC_REQUEST_EVENT as n, storageClient as r, STORAGE_EVENT as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monoidentity",
3
- "version": "0.31.3",
3
+ "version": "0.31.5",
4
4
  "license": "ISC",
5
5
  "repository": "KTibow/monoidentity",
6
6
  "author": {
@@ -14,18 +14,17 @@
14
14
  "!dist/**/*.spec.*"
15
15
  ],
16
16
  "sideEffects": [
17
- "**/*.css",
18
- "**/+receive-callback.js"
17
+ "**/receive-callback.mjs"
19
18
  ],
20
19
  "type": "module",
21
20
  "exports": {
22
21
  ".": {
23
- "types": "./dist/+index.d.ts",
24
- "svelte": "./dist/+index.js"
22
+ "types": "./dist/index.d.mts",
23
+ "import": "./dist/index.mjs"
25
24
  },
26
25
  "./receive-callback": {
27
- "types": "./dist/+receive-callback.d.ts",
28
- "import": "./dist/+receive-callback.js"
26
+ "types": "./dist/receive-callback.d.mts",
27
+ "import": "./dist/receive-callback.mjs"
29
28
  }
30
29
  },
31
30
  "peerDependencies": {
@@ -37,22 +36,14 @@
37
36
  "valibot": "^1.2.0"
38
37
  },
39
38
  "devDependencies": {
40
- "@sveltejs/adapter-static": "^3.0.10",
41
- "@sveltejs/kit": "^2.53.0",
42
- "@sveltejs/package": "^2.5.7",
43
- "@sveltejs/vite-plugin-svelte": "^6.2.4",
44
- "publint": "^0.3.17",
45
- "svelte": "^5.53.2",
46
- "svelte-check": "^4.4.3",
47
- "vite": "8.0.0-beta.15"
39
+ "tsdown": "^0.20.3"
48
40
  },
49
41
  "keywords": [
50
42
  "svelte"
51
43
  ],
52
44
  "scripts": {
53
- "dev": "vite dev",
54
- "build": "pnpm run prepack",
55
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
56
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
45
+ "build": "tsdown",
46
+ "dev": "tsdown --watch",
47
+ "check": "tsc --noEmit"
57
48
  }
58
49
  }
package/dist/+index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export { SYNC_REQUEST_EVENT, STORAGE_EVENT, storageClient as _storageClient, } from './storageclient.svelte.js';
2
- export declare const getLoginRecognized: () => {
3
- email: string;
4
- password: string;
5
- };
6
- export declare const setLoginRecognized: (login: string) => void;
7
- export declare const openHub: (path: string) => never;
8
- export declare const relog: () => never;
9
- export declare const getStorage: (realm: "config" | "userdata" | "cache" | (string & {})) => Record<string, any>;
10
- export declare const getScopedFS: (dir: string) => Record<string, any>;
package/dist/+index.js DELETED
@@ -1,40 +0,0 @@
1
- import { stringify, parse } from 'devalue';
2
- import { parse as useSchema } from 'valibot';
3
- import { decode } from 'base36-esm';
4
- import { storageClient } from './storageclient.svelte.js';
5
- import { object, pipe, email, string } from 'valibot';
6
- export { SYNC_REQUEST_EVENT, STORAGE_EVENT, storageClient as _storageClient, } from './storageclient.svelte.js';
7
- const loginSchema = object({ email: pipe(string(), email()), password: string() });
8
- const LOGIN_RECOGNIZED_PATH = '.local/login.encjson';
9
- export const getLoginRecognized = () => {
10
- const client = storageClient();
11
- const login = client[LOGIN_RECOGNIZED_PATH];
12
- if (!login)
13
- throw new Error('No login found');
14
- return useSchema(loginSchema, JSON.parse(decode(login)));
15
- };
16
- export const setLoginRecognized = (login) => {
17
- const client = storageClient();
18
- client[LOGIN_RECOGNIZED_PATH] = login;
19
- };
20
- const isLocalhostHost = (host) => host == 'localhost' ||
21
- host == '127.0.0.1' ||
22
- host == '0.0.0.0' ||
23
- host == '[::1]' ||
24
- host.endsWith('.localhost');
25
- export const openHub = (path) => {
26
- const target = new URL(`https://monoidentity.web.app/${path}`);
27
- if (isLocalhostHost(location.hostname)) {
28
- const redirectParams = new URLSearchParams();
29
- redirectParams.set('redirect', location.origin);
30
- target.hash = redirectParams.toString();
31
- }
32
- location.href = target.toString();
33
- throw new Error('relogging');
34
- };
35
- export const relog = () => openHub(MONOIDENTITY_APP_ID);
36
- export const getStorage = (realm) => {
37
- const prefix = `.${realm}/${MONOIDENTITY_APP_ID}/`;
38
- return storageClient((key) => `${prefix}${key}.devalue`, (key) => (key.startsWith(prefix) ? key.slice(prefix.length, -'.devalue'.length) : undefined), stringify, parse);
39
- };
40
- export const getScopedFS = (dir) => storageClient((key) => `${dir}/${key}`, (key) => (key.startsWith(dir + '/') ? key.slice(dir.length + 1) : undefined));
@@ -1,2 +0,0 @@
1
- export declare const loaded: boolean;
2
- export declare const monoidentitysync: string | undefined;
@@ -1,11 +0,0 @@
1
- import { setLoginRecognized } from './+index.js';
2
- const params = new URLSearchParams(location.hash.slice(1));
3
- const monoidentityloginrecognized = params.get('monoidentityloginrecognized');
4
- if (monoidentityloginrecognized) {
5
- setLoginRecognized(monoidentityloginrecognized);
6
- }
7
- export const loaded = Boolean(params.size);
8
- if (loaded) {
9
- history.replaceState(null, '', location.pathname);
10
- }
11
- export const monoidentitysync = params.get('monoidentitysync') || undefined;
package/dist/+types.d.ts DELETED
@@ -1 +0,0 @@
1
- declare const MONOIDENTITY_APP_ID: string;
@@ -1,11 +0,0 @@
1
- export declare const SYNC_REQUEST_EVENT = "monoidentity-sync-request";
2
- export declare const STORAGE_EVENT = "monoidentity-storage";
3
- declare global {
4
- interface WindowEventMap {
5
- 'monoidentity-storage': CustomEvent<{
6
- key: string;
7
- value: string | undefined;
8
- }>;
9
- }
10
- }
11
- export declare const storageClient: (prefix?: (key: string) => string, unprefix?: (key: string) => string | undefined, serialize?: (data: any) => string, deserialize?: (data: string) => any) => Record<string, any>;
@@ -1,90 +0,0 @@
1
- export const SYNC_REQUEST_EVENT = 'monoidentity-sync-request';
2
- export const STORAGE_EVENT = 'monoidentity-storage';
3
- const waitForSync = async (key) => {
4
- await new Promise((resolve, reject) => window.dispatchEvent(new CustomEvent(SYNC_REQUEST_EVENT, { detail: { key, resolve, reject } })));
5
- };
6
- const announce = (key, value) => {
7
- // Announce to all, even third parties
8
- window.dispatchEvent(new CustomEvent(STORAGE_EVENT, { detail: { key, value } }));
9
- };
10
- const storageCounters = $state({});
11
- let allCounter = $state(0);
12
- const increment = (key) => {
13
- storageCounters[key] = (storageCounters[key] || 0) + 1;
14
- allCounter++;
15
- };
16
- addEventListener(STORAGE_EVENT, (event) => increment(event.detail.key));
17
- addEventListener('storage', (event) => {
18
- if (event.storageArea != localStorage)
19
- return;
20
- if (!event.key)
21
- return;
22
- increment(event.key);
23
- });
24
- export const storageClient = (prefix, unprefix, serialize, deserialize) => {
25
- if (prefix) {
26
- const oldPrefix = prefix;
27
- prefix = (key) => `monoidentity/${oldPrefix(key)}`;
28
- }
29
- else {
30
- prefix = (key) => `monoidentity/${key}`;
31
- }
32
- const getScopedKeys = () => {
33
- const keys = [];
34
- for (const key in localStorage) {
35
- if (!key.startsWith('monoidentity/'))
36
- continue;
37
- let scopedKey = key.slice('monoidentity/'.length);
38
- if (unprefix) {
39
- const unprefixed = unprefix(scopedKey);
40
- if (!unprefixed)
41
- continue;
42
- scopedKey = unprefixed;
43
- }
44
- keys.push(scopedKey);
45
- }
46
- return keys;
47
- };
48
- return new Proxy({}, {
49
- get(_, key) {
50
- if (typeof key == 'symbol')
51
- return undefined;
52
- if (key == 'sync') {
53
- return async (userKey) => {
54
- await waitForSync(prefix(userKey));
55
- };
56
- }
57
- key = prefix(key);
58
- storageCounters[key];
59
- const raw = localStorage[key];
60
- return raw && deserialize ? deserialize(raw) : raw;
61
- },
62
- set(_, key, value) {
63
- key = prefix(key);
64
- if (serialize)
65
- value = serialize(value);
66
- if (localStorage[key] != value) {
67
- localStorage[key] = value;
68
- announce(key, value);
69
- }
70
- else {
71
- console.debug('[monoidentity storage] noop for', key);
72
- }
73
- return true;
74
- },
75
- deleteProperty(_, key) {
76
- key = prefix(key);
77
- delete localStorage[key];
78
- announce(key);
79
- return true;
80
- },
81
- ownKeys() {
82
- allCounter;
83
- return getScopedKeys();
84
- },
85
- getOwnPropertyDescriptor(_, key) {
86
- key = prefix(key);
87
- return Reflect.getOwnPropertyDescriptor(localStorage, key);
88
- },
89
- });
90
- };