monoidentity 0.6.0 → 0.7.0

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,21 +1,20 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from "svelte";
3
- import type { Scope } from "./utils-scope.js";
4
3
  import { trackReady } from "./trackready.js";
4
+ import type { Intent } from "./utils-transport.js";
5
5
 
6
- let { app, scopes, children }: { app: string; scopes: Scope[]; children: Snippet } = $props();
6
+ let { app, intents, children }: { app: string; intents?: Intent[]; children: Snippet } = $props();
7
7
 
8
8
  let ready = $state(false);
9
9
  let backup: (() => void) | undefined = $state();
10
10
  trackReady(
11
11
  app,
12
- scopes,
13
- (callback) => {
14
- backup = () => {
15
- callback();
12
+ intents || [],
13
+ (startBackup) =>
14
+ (backup = () => {
15
+ startBackup();
16
16
  backup = undefined;
17
- };
18
- },
17
+ }),
19
18
  () => (ready = true),
20
19
  );
21
20
  </script>
@@ -1,8 +1,8 @@
1
1
  import type { Snippet } from "svelte";
2
- import type { Scope } from "./utils-scope.js";
2
+ import type { Intent } from "./utils-transport.js";
3
3
  type $$ComponentProps = {
4
4
  app: string;
5
- scopes: Scope[];
5
+ intents?: Intent[];
6
6
  children: Snippet;
7
7
  };
8
8
  declare const Monoidentity: import("svelte").Component<$$ComponentProps, {}, "">;
@@ -1,3 +1,3 @@
1
1
  import { type Dict } from "./_createstore.js";
2
2
  export declare const init: () => Record<string, string>;
3
- export declare const wrapWithBackup: (storage: Dict, requestBackup: (callback: () => void) => void) => Dict;
3
+ export declare const wrapWithBackup: (storage: Dict, requestBackup: (startBackup: () => void) => void) => Dict;
@@ -1,6 +1,6 @@
1
1
  import { createStore } from "./_createstore.js";
2
2
  import { wrapWithReplay } from "./_replay.js";
3
- import { canBackup } from "./utils-callback.js";
3
+ import { canBackup } from "./utils-transport.js";
4
4
  import { openDB } from "idb";
5
5
  const prefix = "monoidentity/";
6
6
  const prefixed = (key) => `${prefix}${key}`;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { getLogin, getStorage } from "./storage.js";
2
- export * from "./trackready.js";
1
+ export { getLoginRecognized, getStorage } from "./storage.js";
2
+ export { trackReady } from "./trackready.js";
3
3
  export { encode, decode } from "./utils-base36.js";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { getLogin, getStorage } from "./storage.js";
2
- export * from "./trackready.js";
1
+ export { getLoginRecognized, getStorage } from "./storage.js";
2
+ export { trackReady } from "./trackready.js";
3
3
  export { encode, decode } from "./utils-base36.js";
package/dist/storage.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Login } from "./utils-callback.js";
1
+ import type { Login } from "./utils-transport.js";
2
2
  export declare const setup: (i: Record<string, string>, a: string) => void;
3
3
  export declare const LOGIN_RECOGNIZED_PATH = ".core/login.encjson";
4
4
  export declare const getLoginRecognized: () => Login;
@@ -1,2 +1,2 @@
1
- import { type Scope } from "./utils-scope.js";
2
- export declare const trackReady: (app: string, scopes: Scope[], requestBackup: (callback: () => void) => void, callback: () => void) => void;
1
+ import { type Intent } from "./utils-transport.js";
2
+ export declare const trackReady: (app: string, intents: Intent[], requestBackup: (startBackup: () => void) => void, ready: () => void) => void;
@@ -1,30 +1,30 @@
1
- import {} from "./utils-callback.js";
2
- import {} from "./utils-scope.js";
1
+ import {} from "./utils-transport.js";
3
2
  import { init as initLocal, wrapWithBackup } from "./_localstorage.js";
4
3
  import { LOGIN_RECOGNIZED_PATH, setup } from "./storage.js";
5
- export const trackReady = (app, scopes, requestBackup, callback) => {
4
+ export const trackReady = (app, intents, requestBackup, ready) => {
6
5
  const params = new URLSearchParams(location.hash.slice(1));
7
6
  let memory = localStorage.monoidentityMemory
8
7
  ? JSON.parse(localStorage.monoidentityMemory)
9
8
  : undefined;
10
- const paramCB = params.get("monoidentitycallback");
11
- let cb = [];
12
- if (paramCB) {
9
+ let provisions = [];
10
+ const cb = params.get("monoidentitycallback");
11
+ if (cb) {
13
12
  history.replaceState(null, "", location.pathname);
14
- cb = JSON.parse(paramCB);
13
+ ({ provisions } = JSON.parse(cb));
15
14
  }
16
- for (const task of cb) {
17
- if ("setup" in task) {
18
- memory = task.setup;
15
+ for (const provision of provisions) {
16
+ if ("setup" in provision) {
17
+ memory = provision.setup;
19
18
  localStorage.monoidentityMemory = JSON.stringify(memory);
20
19
  }
21
20
  }
22
21
  if (!memory) {
23
- const params = new URLSearchParams();
24
- params.set("app", app);
25
- params.set("scopes", scopes.join(","));
26
- params.set("redirectURI", location.origin);
27
- location.href = `https://usemonoidentity.web.app/#${params.toString()}`;
22
+ const target = new URL("https://usemonoidentity.web.app");
23
+ target.hash = JSON.stringify({
24
+ intents: [{ storage: true }, ...intents],
25
+ redirectURI: location.origin,
26
+ });
27
+ location.href = target.toString();
28
28
  return;
29
29
  }
30
30
  let storage;
@@ -40,13 +40,13 @@ export const trackReady = (app, scopes, requestBackup, callback) => {
40
40
  throw new Error("unreachable");
41
41
  }
42
42
  setup(storage, app);
43
- for (const task of cb) {
44
- if ("createLoginRecognized" in task) {
45
- storage[LOGIN_RECOGNIZED_PATH] = task.createLoginRecognized;
43
+ for (const provision of provisions) {
44
+ if ("createLoginRecognized" in provision) {
45
+ storage[LOGIN_RECOGNIZED_PATH] = provision.createLoginRecognized;
46
46
  }
47
- else if ("createVerification" in task) {
48
- storage[".core/verification.jwt"] = task.createVerification;
47
+ else if ("createVerification" in provision) {
48
+ storage[".core/verification.jwt"] = provision.createVerification;
49
49
  }
50
50
  }
51
- callback();
51
+ ready();
52
52
  };
@@ -0,0 +1,31 @@
1
+ export type Intent = {
2
+ storage: true;
3
+ } | {
4
+ loginRecognized: true;
5
+ };
6
+ export type IntentEnvelope = {
7
+ intents: Intent[];
8
+ redirectURI: string;
9
+ };
10
+ export type StorageSetup = {
11
+ method: "cloud";
12
+ jwt: string;
13
+ } | {
14
+ method: "localStorage";
15
+ };
16
+ export type Provision = {
17
+ setup: StorageSetup;
18
+ } | {
19
+ createLoginRecognized: string;
20
+ } | {
21
+ createVerification: string;
22
+ };
23
+ /** @knipexternal */
24
+ export type ProvisionEnvelope = {
25
+ provisions: Provision[];
26
+ };
27
+ export type Login = {
28
+ email: string;
29
+ password: string;
30
+ };
31
+ export declare const canBackup: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monoidentity",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "repository": "KTibow/monoidentity",
5
5
  "author": {
6
6
  "name": "KTibow"
@@ -1,20 +0,0 @@
1
- export type Setup = {
2
- method: "cloud";
3
- jwt: string;
4
- } | {
5
- method: "localStorage";
6
- };
7
- type CallbackTask = {
8
- setup: Setup;
9
- } | {
10
- createLoginRecognized: string;
11
- } | {
12
- createVerification: string;
13
- };
14
- export type Callback = CallbackTask[];
15
- export type Login = {
16
- email: string;
17
- password: string;
18
- };
19
- export declare const canBackup: boolean;
20
- export {};
@@ -1,6 +0,0 @@
1
- /** @knipexternal */
2
- export declare const scopeDefs: {
3
- "login-recognized": {};
4
- storage: {};
5
- };
6
- export type Scope = keyof typeof scopeDefs;
@@ -1,5 +0,0 @@
1
- /** @knipexternal */
2
- export const scopeDefs = {
3
- "login-recognized": {},
4
- storage: {},
5
- };
File without changes