monoidentity 0.0.2 → 0.0.3
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/Monoidentity.svelte +1 -1
- package/dist/Monoidentity.svelte.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/storage.d.ts +2 -0
- package/dist/storage.js +10 -0
- package/dist/trackready.d.ts +1 -1
- package/dist/trackready.js +17 -4
- package/dist/{utils.d.ts → utils-callback.d.ts} +1 -9
- package/dist/{utils.js → utils-callback.js} +10 -9
- package/dist/utils-login.d.ts +6 -0
- package/dist/utils-login.js +16 -0
- package/dist/utils-scope.d.ts +9 -0
- package/dist/utils-scope.js +8 -0
- package/package.json +1 -1
package/dist/Monoidentity.svelte
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from "svelte";
|
|
3
|
-
import type { Scope } from "./utils.js";
|
|
3
|
+
import type { Scope } from "./utils-scope.js";
|
|
4
4
|
import { trackReady } from "./trackready.js";
|
|
5
5
|
|
|
6
6
|
let { app, scopes, children }: { app: string; scopes: Scope[]; children: Snippet } = $props();
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/storage.d.ts
CHANGED
package/dist/storage.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { stringify, parse } from "devalue";
|
|
2
|
+
import { decode } from "./utils-login.js";
|
|
2
3
|
let implementation;
|
|
3
4
|
let app = "";
|
|
4
5
|
export const setup = (i, a) => {
|
|
5
6
|
implementation = i;
|
|
6
7
|
app = a;
|
|
7
8
|
};
|
|
9
|
+
export const getLogin = () => {
|
|
10
|
+
const storage = implementation;
|
|
11
|
+
if (!storage)
|
|
12
|
+
throw new Error("No implementation set");
|
|
13
|
+
const login = storage[".core/login.encjson"];
|
|
14
|
+
if (!login)
|
|
15
|
+
throw new Error("No login found");
|
|
16
|
+
return JSON.parse(decode(login));
|
|
17
|
+
};
|
|
8
18
|
export const getStorage = (realm) => {
|
|
9
19
|
const prefix = (text) => `.${realm}/${app}/${text}`;
|
|
10
20
|
const storage = implementation;
|
package/dist/trackready.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type Scope } from "./utils.js";
|
|
1
|
+
import { type Scope } from "./utils-scope.js";
|
|
2
2
|
export declare const trackReady: (app: string, scopes: Scope[], callback: () => void) => void;
|
package/dist/trackready.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { rememberCallback } from "./utils.js";
|
|
1
|
+
import { rememberCallback } from "./utils-callback.js";
|
|
2
|
+
import {} from "./utils-scope.js";
|
|
2
3
|
import { init as initLocal } from "./storage-private-local.js";
|
|
3
4
|
import { setup } from "./storage.js";
|
|
4
5
|
export const trackReady = (app, scopes, callback) => {
|
|
@@ -7,16 +8,18 @@ export const trackReady = (app, scopes, callback) => {
|
|
|
7
8
|
? JSON.parse(localStorage.monoidentityMemory)
|
|
8
9
|
: undefined;
|
|
9
10
|
let createNew = false;
|
|
11
|
+
let fileTasks = undefined;
|
|
10
12
|
const paramCB = params.get("monoidentitycallback");
|
|
11
13
|
if (paramCB) {
|
|
12
14
|
history.replaceState(null, "", location.pathname);
|
|
13
15
|
const cb = JSON.parse(paramCB);
|
|
14
16
|
console.log("got callback", cb); // todo remove
|
|
17
|
+
memory = rememberCallback(cb, memory);
|
|
18
|
+
localStorage.monoidentityMemory = JSON.stringify(memory);
|
|
15
19
|
if (cb.connect.method == "file" && cb.connect.createNew) {
|
|
16
20
|
createNew = true;
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
localStorage.monoidentityMemory = JSON.stringify(memory);
|
|
22
|
+
fileTasks = cb.fileTasks;
|
|
20
23
|
}
|
|
21
24
|
if (!memory) {
|
|
22
25
|
const params = new URLSearchParams();
|
|
@@ -26,14 +29,24 @@ export const trackReady = (app, scopes, callback) => {
|
|
|
26
29
|
location.href = `https://usemonoidentity.web.app/#${params.toString()}`;
|
|
27
30
|
return;
|
|
28
31
|
}
|
|
32
|
+
let storage;
|
|
29
33
|
if (memory.method == "cloud") {
|
|
30
34
|
// TODO
|
|
35
|
+
throw new Error("unimplemented");
|
|
31
36
|
}
|
|
32
37
|
else if (memory.method == "file") {
|
|
33
38
|
// TODO (use createNew here)
|
|
39
|
+
throw new Error("unimplemented");
|
|
34
40
|
}
|
|
35
41
|
else if (memory.method == "localStorage") {
|
|
36
|
-
|
|
42
|
+
storage = initLocal();
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new Error("unreachable");
|
|
46
|
+
}
|
|
47
|
+
setup(storage, app);
|
|
48
|
+
for (const file in fileTasks) {
|
|
49
|
+
storage[file] = fileTasks[file];
|
|
37
50
|
}
|
|
38
51
|
callback();
|
|
39
52
|
};
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
export declare const scopeDefs: {
|
|
2
|
-
"login-recognized": {
|
|
3
|
-
files: string[];
|
|
4
|
-
};
|
|
5
|
-
storage: {
|
|
6
|
-
files: never[];
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
export type Scope = keyof typeof scopeDefs;
|
|
10
1
|
export declare const supportsFile: boolean;
|
|
11
2
|
type Setup = {
|
|
12
3
|
method: "cloud";
|
|
@@ -21,6 +12,7 @@ export type Memory = Setup & {
|
|
|
21
12
|
knownFiles: string[];
|
|
22
13
|
};
|
|
23
14
|
export type Callback = {
|
|
15
|
+
scopes: string[];
|
|
24
16
|
connect: Setup | {
|
|
25
17
|
method: "file";
|
|
26
18
|
createNew: boolean;
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
export const scopeDefs = {
|
|
2
|
-
"login-recognized": {
|
|
3
|
-
files: [".config/login.encjson"],
|
|
4
|
-
},
|
|
5
|
-
storage: {
|
|
6
|
-
files: [],
|
|
7
|
-
},
|
|
8
|
-
};
|
|
9
1
|
export const supportsFile = "showSaveFilePicker" in window;
|
|
10
2
|
export const rememberCallback = (data, pastMemory) => {
|
|
11
|
-
const { connect, fileTasks } = data;
|
|
3
|
+
const { scopes, connect, fileTasks } = data;
|
|
12
4
|
const setup = connect.method == "cloud" ? { method: "cloud", jwt: connect.jwt } : { method: connect.method };
|
|
13
5
|
let knownFilesSet = new Set();
|
|
14
6
|
if (pastMemory) {
|
|
@@ -21,6 +13,15 @@ export const rememberCallback = (data, pastMemory) => {
|
|
|
21
13
|
knownFilesSet.add(file);
|
|
22
14
|
}
|
|
23
15
|
}
|
|
16
|
+
if (scopes.includes("login-recognized")) {
|
|
17
|
+
const path = ".core/login.encjson";
|
|
18
|
+
if (connect.method == "cloud") {
|
|
19
|
+
knownFilesSet.add(path);
|
|
20
|
+
}
|
|
21
|
+
else if (!knownFilesSet.has(path)) {
|
|
22
|
+
console.warn("unexpected login deficit");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
24
25
|
const knownFiles = Array.from(knownFilesSet);
|
|
25
26
|
return { ...setup, knownFiles };
|
|
26
27
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const encode = (text) => {
|
|
2
|
+
let output = "";
|
|
3
|
+
for (let i = 0; i < text.length; i++) {
|
|
4
|
+
const charCode = text.charCodeAt(i);
|
|
5
|
+
output += charCode.toString(36).padStart(2, "0");
|
|
6
|
+
}
|
|
7
|
+
return output;
|
|
8
|
+
};
|
|
9
|
+
export const decode = (text) => {
|
|
10
|
+
let output = "";
|
|
11
|
+
for (let i = 0; i < text.length; i += 2) {
|
|
12
|
+
const charCode = parseInt(text.slice(i, i + 2), 36);
|
|
13
|
+
output += String.fromCharCode(charCode);
|
|
14
|
+
}
|
|
15
|
+
return output;
|
|
16
|
+
};
|