monoidentity 0.21.1 → 0.22.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.
package/dist/+client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./+common.js";
1
+ export * from "./_common.js";
2
2
  export { getLoginRecognized, relog, getVerification, getStorage, getScopedFS } from "./storage.js";
3
3
  export type { SyncStrategy } from "./storage/utils-storage.js";
4
4
  export { waitForSync } from "./storage/utils-sync.js";
package/dist/+client.js CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./+common.js";
1
+ export * from "./_common.js";
2
2
  export { getLoginRecognized, relog, getVerification, getStorage, getScopedFS } from "./storage.js";
3
3
  export { waitForSync } from "./storage/utils-sync.js";
4
4
  export { retrieveVerification } from "./verification-client.js";
package/dist/+server.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./+common.js";
1
+ export * from "./_common.js";
2
2
  export { useVerification } from "./verification-server.js";
package/dist/+server.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./+common.js";
1
+ export * from "./_common.js";
2
2
  export { useVerification } from "./verification-server.js";
@@ -5,12 +5,10 @@
5
5
  import type { SyncStrategy } from "./storage/utils-storage.js";
6
6
 
7
7
  let {
8
- app,
9
8
  intents,
10
9
  getSyncStrategy,
11
10
  children,
12
11
  }: {
13
- app: string;
14
12
  intents?: Intent[];
15
13
  getSyncStrategy: (path: string) => SyncStrategy;
16
14
  children: Snippet;
@@ -23,7 +21,6 @@
23
21
 
24
22
  let backup: (() => void) | undefined = $state();
25
23
  readyUp(
26
- app,
27
24
  intents || [],
28
25
  getSyncStrategy,
29
26
  aborter.signal,
@@ -2,7 +2,6 @@ import { type Snippet } from "svelte";
2
2
  import type { Intent } from "./utils-transport.js";
3
3
  import type { SyncStrategy } from "./storage/utils-storage.js";
4
4
  type $$ComponentProps = {
5
- app: string;
6
5
  intents?: Intent[];
7
6
  getSyncStrategy: (path: string) => SyncStrategy;
8
7
  children: Snippet;
@@ -0,0 +1 @@
1
+ declare const MONOIDENTITY_APP_ID: string;
package/dist/readyup.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { type Intent } from "./utils-transport.js";
2
2
  import type { SyncStrategy } from "./storage/utils-storage.js";
3
- export declare const readyUp: (app: string, intents: Intent[], getSyncStrategy: (path: string) => SyncStrategy, signal: AbortSignal, requestBackup: (startBackup: () => void) => void) => void;
3
+ export declare const readyUp: (intents: Intent[], getSyncStrategy: (path: string) => SyncStrategy, signal: AbortSignal, requestBackup: (startBackup: () => void) => void) => void;
package/dist/readyup.js CHANGED
@@ -2,15 +2,14 @@ import {} from "./utils-transport.js";
2
2
  // import { createLocalStorage } from "./storage/createlocalstorage.js";
3
3
  // import { wrapBackup } from "./storage/wrapbackup.js";
4
4
  // import { wrapCloud } from "./storage/wrapcloud.js";
5
- import { conf, setLoginRecognized } from "./storage.js";
5
+ import { setLoginRecognized } from "./storage.js";
6
6
  import { pullFromLocalBackup } from "./storage/backuplocally-pull.js";
7
7
  import { mountLocalBackupPush } from "./storage/backuplocally-push.js";
8
8
  import { createCloudClient } from "./storage/backupcloud-connection.js";
9
9
  import { mountCloudPull, pullFromCloud } from "./storage/backupcloud-pull.js";
10
10
  import { mountCloudPush } from "./storage/backupcloud-push.js";
11
11
  import { switchToHub } from "./utils-hub.js";
12
- export const readyUp = (app, intents, getSyncStrategy, signal, requestBackup) => {
13
- conf(app);
12
+ export const readyUp = (intents, getSyncStrategy, signal, requestBackup) => {
14
13
  let setup = localStorage["monoidentity-x/setup"]
15
14
  ? JSON.parse(localStorage["monoidentity-x/setup"])
16
15
  : undefined;
@@ -50,11 +49,11 @@ export const readyUp = (app, intents, getSyncStrategy, signal, requestBackup) =>
50
49
  }
51
50
  if (setup.method == "cloud") {
52
51
  const client = createCloudClient(setup);
53
- void pullFromCloud(getSyncStrategy, setup, client)
52
+ void pullFromCloud(getSyncStrategy, client)
54
53
  .then(() => {
55
54
  signal.throwIfAborted();
56
- mountCloudPull(getSyncStrategy, setup, client, signal);
57
- mountCloudPush(getSyncStrategy, setup, client, signal);
55
+ mountCloudPull(getSyncStrategy, client, signal);
56
+ mountCloudPush(getSyncStrategy, client, signal);
58
57
  })
59
58
  .catch((err) => {
60
59
  console.error("[monoidentity cloud] pull failed", err);
@@ -1,3 +1,3 @@
1
1
  import type { Bucket } from "../utils-transport.js";
2
- import type { AwsFetch } from "./backupcloud-pull.js";
2
+ export type AwsFetch = (path: string, options?: RequestInit) => Promise<Response>;
3
3
  export declare const createCloudClient: (bucket: Bucket) => AwsFetch;
@@ -4,5 +4,6 @@ export const createCloudClient = (bucket) => {
4
4
  accessKeyId: bucket.accessKeyId,
5
5
  secretAccessKey: bucket.secretAccessKey,
6
6
  });
7
- return (url, options) => awsClient.fetch(url, { ...options, aws: { signQuery: true } });
7
+ const base = bucket.base.endsWith("/") ? bucket.base : bucket.base + "/";
8
+ return (path, options) => awsClient.fetch(base + path, { ...options, aws: { signQuery: true } });
8
9
  };
@@ -1,6 +1,5 @@
1
- import type { Bucket } from "../utils-transport.js";
2
1
  import { type SyncStrategy } from "./utils-storage.js";
3
- export type AwsFetch = (url: string, options?: RequestInit) => Promise<Response>;
2
+ import type { AwsFetch } from "./backupcloud-connection.js";
4
3
  export declare const setCloudCacheEntry: (key: string, etag: string, content: string) => Promise<void>;
5
- export declare const pullFromCloud: (getSyncStrategy: (path: string) => SyncStrategy, bucket: Bucket, client: AwsFetch) => Promise<void>;
6
- export declare const mountCloudPull: (getSyncStrategy: (path: string) => SyncStrategy, bucket: Bucket, client: AwsFetch, signal: AbortSignal) => () => void;
4
+ export declare const pullFromCloud: (getSyncStrategy: (path: string) => SyncStrategy, client: AwsFetch) => Promise<void>;
5
+ export declare const mountCloudPull: (getSyncStrategy: (path: string) => SyncStrategy, client: AwsFetch, signal: AbortSignal) => () => void;
@@ -22,17 +22,17 @@ export const setCloudCacheEntry = async (key, etag, content) => {
22
22
  getCache()[key] = { etag, content };
23
23
  await saveCache();
24
24
  };
25
- const loadFromCloud = async (getSyncStrategy, base, client) => {
26
- const cacheInit = initCache();
27
- const listResp = await client(base);
25
+ const listCloud = async (getSyncStrategy, client) => {
26
+ const listResp = await client("");
28
27
  if (!listResp.ok)
29
28
  throw new Error(`List bucket failed: ${listResp.status}`);
30
29
  const listXml = await listResp.text();
31
- const objects = [...listXml.matchAll(/<Key>(.*?)<\/Key>.*?<ETag>(.*?)<\/ETag>/gs)]
30
+ return [...listXml.matchAll(/<Key>(.*?)<\/Key>.*?<ETag>(.*?)<\/ETag>/gs)]
32
31
  .map((m) => m.slice(1).map((s) => s.replaceAll("&quot;", `"`).replaceAll("&apos;", `'`)))
33
32
  .map(([key, etag]) => ({ key, etag: etag.replaceAll(`"`, "") }))
34
33
  .filter(({ key }) => getSyncStrategy(key));
35
- await cacheInit;
34
+ };
35
+ const loadFromCloud = async (objects, client) => {
36
36
  const prevCache = getCache();
37
37
  const nextCache = {};
38
38
  const model = {};
@@ -44,7 +44,7 @@ const loadFromCloud = async (getSyncStrategy, base, client) => {
44
44
  return;
45
45
  }
46
46
  console.debug("[monoidentity cloud] loading", key);
47
- const r = await client(`${base}/${key}`);
47
+ const r = await client(key);
48
48
  if (!r.ok)
49
49
  throw new Error(`Fetch ${key} failed: ${r.status}`);
50
50
  const content = await decodeCloudContent(key, r);
@@ -55,8 +55,11 @@ const loadFromCloud = async (getSyncStrategy, base, client) => {
55
55
  await saveCache();
56
56
  return model;
57
57
  };
58
- const _pullFromCloud = async (getSyncStrategy, bucket, client) => {
59
- const remote = await loadFromCloud(getSyncStrategy, bucket.base, client);
58
+ const _pullFromCloud = async (getSyncStrategy, client) => {
59
+ const cachePromise = initCache();
60
+ const objects = await listCloud(getSyncStrategy, client);
61
+ await cachePromise;
62
+ const remote = await loadFromCloud(objects, client);
60
63
  const local = storageClient();
61
64
  for (const key of Object.keys(local)) {
62
65
  if (key in remote)
@@ -71,15 +74,15 @@ const _pullFromCloud = async (getSyncStrategy, bucket, client) => {
71
74
  local[key] = value;
72
75
  }
73
76
  };
74
- export const pullFromCloud = async (getSyncStrategy, bucket, client) => {
75
- const promise = _pullFromCloud(getSyncStrategy, bucket, client);
77
+ export const pullFromCloud = async (getSyncStrategy, client) => {
78
+ const promise = _pullFromCloud(getSyncStrategy, client);
76
79
  addSync("*", promise);
77
80
  await promise;
78
81
  };
79
- export const mountCloudPull = (getSyncStrategy, bucket, client, signal) => {
82
+ export const mountCloudPull = (getSyncStrategy, client, signal) => {
80
83
  signal.throwIfAborted();
81
84
  const syncIntervalId = setInterval(() => {
82
- pullFromCloud(getSyncStrategy, bucket, client).catch((err) => {
85
+ pullFromCloud(getSyncStrategy, client).catch((err) => {
83
86
  console.error("[monoidentity cloud] pull failed", err);
84
87
  });
85
88
  }, 15 * 60 * 1000);
@@ -1,4 +1,3 @@
1
- import type { Bucket } from "../utils-transport.js";
2
1
  import { type SyncStrategy } from "./utils-storage.js";
3
- import { type AwsFetch } from "./backupcloud-pull.js";
4
- export declare const mountCloudPush: (getSyncStrategy: (path: string) => SyncStrategy, bucket: Bucket, client: AwsFetch, signal: AbortSignal) => () => void;
2
+ import type { AwsFetch } from "./backupcloud-connection.js";
3
+ export declare const mountCloudPush: (getSyncStrategy: (path: string) => SyncStrategy, client: AwsFetch, signal: AbortSignal) => () => void;
@@ -3,11 +3,10 @@ import { addSync, scheduleSync } from "./utils-sync.js";
3
3
  import { shouldPersist } from "./utils-storage.js";
4
4
  import { setCloudCacheEntry } from "./backupcloud-pull.js";
5
5
  import { encodeCloudContent } from "./_backupcloud.js";
6
- const write = async (key, value, bucket, client) => {
6
+ const write = async (key, value, client) => {
7
7
  console.debug("[monoidentity cloud] saving", key);
8
- const url = `${bucket.base}/${key}`;
9
8
  if (value != undefined) {
10
- const r = await client(url, {
9
+ const r = await client(key, {
11
10
  method: "PUT",
12
11
  headers: { "content-type": "application/octet-stream" },
13
12
  body: encodeCloudContent(key, value),
@@ -20,13 +19,13 @@ const write = async (key, value, bucket, client) => {
20
19
  }
21
20
  return;
22
21
  }
23
- const r = await client(url, { method: "DELETE" });
22
+ const r = await client(key, { method: "DELETE" });
24
23
  if (!r.ok && r.status != 404)
25
24
  throw new Error(`DELETE ${key} failed: ${r.status}`);
26
25
  };
27
- export const mountCloudPush = (getSyncStrategy, bucket, client, signal) => {
26
+ export const mountCloudPush = (getSyncStrategy, client, signal) => {
28
27
  signal.throwIfAborted();
29
- const writeWrapped = async (key, value) => write(key, value, bucket, client).catch((err) => {
28
+ const writeWrapped = async (key, value) => write(key, value, client).catch((err) => {
30
29
  console.error("[monoidentity cloud] save failed", key, err);
31
30
  });
32
31
  const listener = (event) => {
package/dist/storage.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export declare const conf: (a: string) => void;
2
1
  export declare const getLoginRecognized: () => {
3
2
  email: string;
4
3
  password: string;
package/dist/storage.js CHANGED
@@ -6,10 +6,6 @@ import { verify } from "@tsndr/cloudflare-worker-jwt";
6
6
  import publicKey from "./verification/public-key.js";
7
7
  import { storageClient } from "./storage/storageclient.svelte.js";
8
8
  import { switchToHub } from "./utils-hub.js";
9
- let app = "unknown";
10
- export const conf = (a) => {
11
- app = a;
12
- };
13
9
  const LOGIN_RECOGNIZED_PATH = ".local/login.encjson";
14
10
  export const getLoginRecognized = () => {
15
11
  const client = storageClient();
@@ -43,7 +39,7 @@ export const setVerification = (jwt) => {
43
39
  client[VERIFICATION_PATH] = jwt;
44
40
  };
45
41
  export const getStorage = (realm) => {
46
- const prefix = `.${realm}/${app}/`;
42
+ const prefix = `.${realm}/${MONOIDENTITY_APP_ID}/`;
47
43
  return storageClient((key) => `${prefix}${key}.devalue`, (key) => (key.startsWith(prefix) ? key.slice(prefix.length, -".devalue".length) : undefined), stringify, parse);
48
44
  };
49
45
  export const getScopedFS = (dir) => storageClient((key) => `${dir}/${key}`, (key) => (key.startsWith(dir + "/") ? key.slice(dir.length + 1) : undefined));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monoidentity",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "license": "ISC",
5
5
  "repository": "KTibow/monoidentity",
6
6
  "author": {
File without changes
File without changes