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.
@@ -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();
@@ -1,5 +1,5 @@
1
1
  import type { Snippet } from "svelte";
2
- import type { Scope } from "./utils.js";
2
+ import type { Scope } from "./utils-scope.js";
3
3
  type $$ComponentProps = {
4
4
  app: string;
5
5
  scopes: Scope[];
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { default as Monoidentity } from "./Monoidentity.svelte";
2
- export { getStorage } from "./storage.js";
2
+ export { getLogin, getStorage } from "./storage.js";
3
3
  export * from "./trackready.js";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { default as Monoidentity } from "./Monoidentity.svelte";
2
- export { getStorage } from "./storage.js";
2
+ export { getLogin, getStorage } from "./storage.js";
3
3
  export * from "./trackready.js";
package/dist/storage.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ import { type Login } from "./utils-login.js";
1
2
  export declare const setup: (i: Record<string, string>, a: string) => void;
3
+ export declare const getLogin: () => Login;
2
4
  export declare const getStorage: (realm: "cache") => Record<string, any>;
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;
@@ -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;
@@ -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
- memory = rememberCallback(cb, memory);
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
- setup(initLocal(), app);
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,6 @@
1
+ export type Login = {
2
+ email: string;
3
+ password: string;
4
+ };
5
+ export declare const encode: (text: string) => string;
6
+ export declare const decode: (text: string) => string;
@@ -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
+ };
@@ -0,0 +1,9 @@
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;
@@ -0,0 +1,8 @@
1
+ export const scopeDefs = {
2
+ "login-recognized": {
3
+ files: [".core/login.encjson"],
4
+ },
5
+ storage: {
6
+ files: [],
7
+ },
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monoidentity",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "repository": "KTibow/monoidentity",
5
5
  "author": {
6
6
  "name": "KTibow"