monoidentity 0.27.0 → 0.28.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 +1 @@
1
- export {};
1
+ export declare const monoidentitysync: string | undefined;
@@ -1,12 +1,10 @@
1
- import { setLoginRecognized } from "./storage.js";
1
+ import { setLoginRecognized } from './storage.js';
2
2
  const params = new URLSearchParams(location.hash.slice(1));
3
- const cb = params.get("monoidentitycallback");
4
- if (cb) {
5
- history.replaceState(null, "", location.pathname);
6
- const { provisions } = JSON.parse(cb);
7
- for (const provision of provisions) {
8
- if ("createLoginRecognized" in provision) {
9
- setLoginRecognized(provision.createLoginRecognized);
10
- }
11
- }
3
+ const monoidentityloginrecognized = params.get('monoidentityloginrecognized');
4
+ if (monoidentityloginrecognized) {
5
+ setLoginRecognized(monoidentityloginrecognized);
12
6
  }
7
+ if (params.size) {
8
+ history.replaceState(null, '', location.pathname);
9
+ }
10
+ export const monoidentitysync = params.get('monoidentitysync') || undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ // import { fn } from "monoserve";
3
+ // import { string } from "valibot";
4
+ // import { encodeBucket } from "./specific-utils";
5
+ // import { useVerification } from "monoidentity/server";
6
+ // import { CF_ACCOUNT_ID, CF_KEY } from "$env/static/private";
7
+ // const KV_NAMESPACE_ID = "6b33cf77a0bf4a029bc17b738c9f2cdb";
8
+ // async function sha256(text: string): Promise<string> {
9
+ // const encoder = new TextEncoder();
10
+ // const data = encoder.encode(text);
11
+ // const hashBuffer = await crypto.subtle.digest("SHA-256", data);
12
+ // const hashArray = Array.from(new Uint8Array(hashBuffer));
13
+ // return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
14
+ // }
15
+ // export default fn(string(), async (jwt) => {
16
+ // // Verify JWT and get user email
17
+ // const { payload } = await useVerification(jwt);
18
+ // const user = payload.sub!.replace(/[@.]/g, "-");
19
+ // // Check if credentials already exist in KV
20
+ // const existingCreds = await fetch(
21
+ // `https://api.cloudflare.com/client/v4/accounts/${CF_ACCOUNT_ID}/storage/kv/namespaces/${KV_NAMESPACE_ID}/values/${user}`,
22
+ // {
23
+ // headers: { authorization: `Bearer ${CF_KEY}` },
24
+ // },
25
+ // );
26
+ // if (existingCreds.ok) {
27
+ // return await existingCreds.text(); // Already encoded
28
+ // }
29
+ // // Generate unique bucket name
30
+ // const bucketName = `monoidentity-cloud-${user}`;
31
+ // // 1. Create R2 bucket
32
+ // const bucketRes = await fetch(
33
+ // `https://api.cloudflare.com/client/v4/accounts/${CF_ACCOUNT_ID}/r2/buckets`,
34
+ // {
35
+ // method: "POST",
36
+ // headers: {
37
+ // authorization: `Bearer ${CF_KEY}`,
38
+ // "content-type": "application/json",
39
+ // },
40
+ // body: JSON.stringify({ name: bucketName }),
41
+ // },
42
+ // );
43
+ // if (!bucketRes.ok) {
44
+ // throw new Error(`Failed to create bucket: ${await bucketRes.text()}`);
45
+ // }
46
+ // // 2. Set CORS policy
47
+ // const corsConfig = {
48
+ // rules: [
49
+ // {
50
+ // allowed: {
51
+ // origins: ["*"],
52
+ // methods: ["GET", "PUT", "POST", "DELETE", "HEAD"],
53
+ // headers: [
54
+ // "authorization",
55
+ // "content-type",
56
+ // "if-match",
57
+ // "if-none-match",
58
+ // "x-amz-date",
59
+ // "x-amz-content-sha256",
60
+ // ],
61
+ // },
62
+ // exposeHeaders: ["ETag"],
63
+ // maxAgeSeconds: 3600,
64
+ // },
65
+ // ],
66
+ // };
67
+ // const corsRes = await fetch(
68
+ // `https://api.cloudflare.com/client/v4/accounts/${CF_ACCOUNT_ID}/r2/buckets/${bucketName}/cors`,
69
+ // {
70
+ // method: "PUT",
71
+ // headers: {
72
+ // authorization: `Bearer ${CF_KEY}`,
73
+ // "content-type": "application/json",
74
+ // },
75
+ // body: JSON.stringify(corsConfig),
76
+ // },
77
+ // );
78
+ // if (!corsRes.ok) {
79
+ // throw new Error(`Failed to set CORS: ${await corsRes.text()}`);
80
+ // }
81
+ // // 3. Create scoped API token
82
+ // const tokenRes = await fetch(`https://api.cloudflare.com/client/v4/user/tokens`, {
83
+ // method: "POST",
84
+ // headers: {
85
+ // authorization: `Bearer ${CF_KEY}`,
86
+ // "content-type": "application/json",
87
+ // },
88
+ // body: JSON.stringify({
89
+ // name: `monoidentity-cloud-token-${user}`,
90
+ // policies: [
91
+ // {
92
+ // effect: "allow",
93
+ // resources: {
94
+ // [`com.cloudflare.edge.r2.bucket.${CF_ACCOUNT_ID}_default_${bucketName}`]: "*",
95
+ // },
96
+ // permission_groups: [{ id: "2efd5506f9c8494dacb1fa10a3e7d5b6" }], // Workers R2 Storage Bucket Item Write
97
+ // },
98
+ // ],
99
+ // }),
100
+ // });
101
+ // if (!tokenRes.ok) {
102
+ // throw new Error(`Failed to create token: ${await tokenRes.text()}`);
103
+ // }
104
+ // const {
105
+ // result: { id: accessKeyId, value: secretAccessKeyInput },
106
+ // } = await tokenRes.json();
107
+ // const secretAccessKey = await sha256(secretAccessKeyInput);
108
+ // // 4. Encode and store in KV
109
+ // const encoded = encodeBucket({
110
+ // base: `https://${CF_ACCOUNT_ID}.r2.cloudflarestorage.com/${bucketName}`,
111
+ // accessKeyId,
112
+ // secretAccessKey,
113
+ // });
114
+ // const kvRes = await fetch(
115
+ // `https://api.cloudflare.com/client/v4/accounts/${CF_ACCOUNT_ID}/storage/kv/namespaces/${KV_NAMESPACE_ID}/values/${user}`,
116
+ // {
117
+ // method: "PUT",
118
+ // headers: { authorization: `Bearer ${CF_KEY}` },
119
+ // body: encoded,
120
+ // },
121
+ // );
122
+ // if (!kvRes.ok) {
123
+ // throw new Error(`Failed to store credentials in KV: ${await kvRes.text()}`);
124
+ // }
125
+ // return encoded;
126
+ // });
package/dist/storage.js CHANGED
@@ -3,7 +3,6 @@ import { parse as useSchema } from "valibot";
3
3
  import { decode } from "./utils-base36.js";
4
4
  import { login as loginSchema } from "./utils-transport.js";
5
5
  import { storageClient } from "./storageclient.svelte.js";
6
- import { switchToHub } from "./utils-hub.js";
7
6
  const LOGIN_RECOGNIZED_PATH = ".local/login.encjson";
8
7
  export const getLoginRecognized = () => {
9
8
  const client = storageClient();
@@ -17,7 +16,9 @@ export const setLoginRecognized = (login) => {
17
16
  client[LOGIN_RECOGNIZED_PATH] = login;
18
17
  };
19
18
  export const relog = () => {
20
- switchToHub([{ loginRecognized: true }]);
19
+ location.href =
20
+ "https://monoidentity.web.app/" + location.origin.replace(/^https?:\/\//, "");
21
+ throw new Error("relogging");
21
22
  };
22
23
  export const VERIFICATION_PATH = ".local/verification.jwt";
23
24
  export const getStorage = (realm) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monoidentity",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "license": "ISC",
5
5
  "repository": "KTibow/monoidentity",
6
6
  "author": {
@@ -1,2 +0,0 @@
1
- import type { Intent } from "./utils-transport.js";
2
- export declare const switchToHub: (intents: Intent[]) => never;
package/dist/utils-hub.js DELETED
@@ -1,6 +0,0 @@
1
- export const switchToHub = (intents) => {
2
- const target = new URL("https://monoidentity.web.app");
3
- target.hash = JSON.stringify({ intents, redirectURI: location.origin });
4
- location.href = target.toString();
5
- throw new Error("halting");
6
- };