this.me 3.0.0 → 3.0.2

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/README.md CHANGED
@@ -1,23 +1,17 @@
1
- <img src="https://docs.neurons.me/media/all-this/webP/this.me.webp" alt="SVG Image" width="250" height="250">
1
+ <img src="https://res.cloudinary.com/dkwnxf6gm/image/upload/v1761149332/this.me-removebg-preview_2_j1eoiy.png" alt="57b0b83e8518fecf9b3e2d06457421c7da70e0663f7490fab98f9ecbdbe5db6e-removebg-preview" style="zoom:55%;" />
2
2
 
3
- # THIS.ME
4
- > **This.Me** is a data-structured identity designed to generate and manage identities, attributes, properties and more. It combines privacy, user control, and secure interoperability.
3
+ # .ME
5
4
 
6
- <strong>.me</strong> is your identity that lives on your machine, under your control. It holds attributes, relationships, and keys that define who you are—and crucially, <strong>how you relate to others</strong>.
5
+ You can use **.me** both in **browser** and **Node** environments.
7
6
 
8
- # Getting Started:
9
-
10
- You can use **this.me** both in the browser and in Node environments. The library automatically detects the environment and provides a single global instance of `me` once initialized.
11
-
12
- ### **1. Installation**
13
-
14
- If you are using npm:
7
+ #### **1. Installation**
8
+ Using **npm**:
15
9
 
16
10
  ```bash
17
11
  npm install this.me
18
12
  ```
19
13
 
20
- Or load it directly in the browser (after building):
14
+ Or load it directly in the **browser** (build):
21
15
 
22
16
  ```html
23
17
  <script src="this.me.umd.js"></script>
@@ -29,8 +23,7 @@ Or load it directly in the browser (after building):
29
23
 
30
24
  ---
31
25
 
32
- ### **2. Initialization**
33
-
26
+ #### **2. Initialization**
34
27
  You need to initialize the `.me` instance before using it:
35
28
 
36
29
  ```js
@@ -45,8 +38,7 @@ Once initialized, the `me` instance will maintain its state (status, loaded iden
45
38
 
46
39
  ---
47
40
 
48
- ### **3. Checking Daemon Status**
49
-
41
+ #### **3. Checking Daemon Status**
50
42
  You can verify if the local daemon is running:
51
43
 
52
44
  ```js
@@ -58,21 +50,23 @@ The floating components or any GUI indicators (green/red) can rely directly on `
58
50
 
59
51
  ---
60
52
 
61
- ### **4. Listing Identities**
62
-
53
+ #### **4. Listing Identities**
63
54
  ```js
64
55
  const list = await me.listUs();
65
56
  console.log(list);
66
- /*
57
+ ```
58
+
59
+ ```bash
67
60
  [
68
61
  { alias: "suign", path: "/Users/abellae/.this/me/suign" }
69
62
  ]
70
- */
71
63
  ```
72
64
 
65
+
66
+
73
67
  ---
74
68
 
75
- ### **5. Loading an Identity**
69
+ #### **5. Loading an Identity**
76
70
 
77
71
  ```js
78
72
  await me.load("abellae", "mySecretHash");
@@ -83,7 +77,7 @@ After loading, you can use all available methods (`be`, `have`, `do`, etc.).
83
77
 
84
78
  ---
85
79
 
86
- ### **6. Example in the Browser Console**
80
+ #### **6. Example in the Browser Console**
87
81
 
88
82
  If you include the UMD bundle:
89
83
 
@@ -104,9 +98,9 @@ If you include the UMD bundle:
104
98
 
105
99
  ------
106
100
 
107
- # How this.me **Works (Simplified)**
101
+ ### How this.me **Works (Simplified)**
108
102
 
109
- The Me class creates and manages a **local, encrypted identity file** based on a username and a secret hash.
103
+ The **Me** class creates and manages a **local, encrypted identity file** based on a username and a secret hash.
110
104
 
111
105
  #### **Creating a new identity**
112
106
 
@@ -116,15 +110,6 @@ When you run:
116
110
  Me.create('abellae', 'mySecretHash');
117
111
  ```
118
112
 
119
- It does the following:
120
-
121
- - Builds a .me file path: ~/.this/me/abellae.me.
122
- - Creates some **identity data** (username, keys, attributes, etc.).
123
- - Uses the hash to **encrypt** that data with AES-256-CBC:
124
- - It generates a random iv (initialization vector).
125
- - Derives a key from the hash (sha256(hash)).
126
- - Stores the encrypted result as iv + encryptedData.
127
-
128
113
  > 🔒 The hash is **never saved** — it’s just used as a secret key.
129
114
 
130
115
  ------
@@ -199,18 +184,8 @@ Let me know if you’d like a diagram or visual flow to go with this explanation
199
184
  ---
200
185
  <img src="https://suign.github.io/assets/imgs/monads.png" alt="Cleak Me Please" width="244">Hello, I am **.me**
201
186
 
202
- ### ❯ add.me
203
187
  ----
204
188
 
205
- # What is All.This?
206
- ###### Modular Data Structures:
207
- **Each module** in **[all.this](https://neurons.me/all-this)** represents a specific **datastructure**. These **classes** encapsulate the functionalities and **data specific to their domain.**
208
-
209
- **[this.me](https://docs.neurons.me/this.me/index.html) - [this.audio](https://docs.neurons.me/this.audio/index.html) - [this.text](https://docs.neurons.me/this.text/index.html) - [this.wallet](https://docs.neurons.me/this.wallet/index.html) - [this.img](https://docs.neurons.me/this.img/index.html) - [this.pixel](https://docs.neurons.me/this.pixel/index.html) - [be.this](https://docs.neurons.me/be.this/index.html) - [this.DOM](https://docs.neurons.me/this.DOM/index.html) - [this.env](https://docs.neurons.me/this.env/index.html) - [this.GUI](https://docs.neurons.me/this.GUI/index.html) - [this.be](https://docs.neurons.me/this.be/index.html) - [this.video](https://docs.neurons.me/this.video/index.html) - [this.dictionaries](https://docs.neurons.me/this.dictionaries/index.html)**
210
-
211
- #### Contribution
212
- If you are interested in collaborating or wish to share your insights, please feel free to reach out or contribute to the project.
213
-
214
189
  #### License & Policies
215
190
  - **License**: MIT License.
216
191
  - **Learn more** at **https://neurons.me**
@@ -1,55 +1,34 @@
1
- "use strict";class c{constructor(t,s){this.me=t,this.url=s,this.ws=null,this.reconnectInterval=1e4,this.isConnected=!1,this.connect()}connect(){this.ws=new WebSocket(this.url),this.ws.onopen=()=>{console.log("[this.me][WS] Connected to daemon"),this.isConnected=!0,this.me.state?.status&&(this.me.state.status.active=!0,this.me.state.status.error=!1),this.#t()},this.ws.onmessage=t=>{try{const s=JSON.parse(t.data);this.#s(s)}catch{console.warn("[this.me][WS] Invalid message:",t.data)}},this.ws.onclose=()=>{console.warn("[this.me][WS] Disconnected, retrying in 10s"),this.isConnected=!1,this.me.state?.status&&(this.me.state.status.active=!1,this.me.state.status.error=!0),this.#t(),setTimeout(()=>this.connect(),this.reconnectInterval)},this.ws.onerror=t=>{console.error("[this.me][WS] Error:",t),this.ws.close()}}#s(t){switch(t.type){case"status":this.me.state.status={active:t.data.active,error:!1,data:t.data};break;case"listUs":this.me.state.listUs=t.data;break;case"update":console.log("[this.me][WS] Update event:",t.data);break;default:console.warn("[this.me][WS] Unknown message type:",t.type)}this.#t()}send(t,s){this.isConnected&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:t,data:s}))}#t(){this.me.subscribers?.size&&this.me.subscribers.forEach(t=>t(this.me.state))}}class u{constructor(t="http://localhost:7777/graphql"){this.endpoint=t,this.state={status:{active:!1,error:!1,loading:!0,data:null},listUs:[],activeMe:null},this.subscribers=new Set,this.status(),this.socket=null}async init(){return this.#s({status:{...this.state.status,loading:!0}}),(await this.status()).active&&(await this.startSocket(),await new Promise(s=>{let a=!1;const e=this.subscribe(i=>{!a&&i.status.active!==void 0&&(a=!0,e(),s())});setTimeout(()=>{a||(a=!0,e(),s())},2e3)})),this.#s({status:{...this.state.status,loading:!1}}),this.state.status}async startSocket(){if(this.state.status.active){if(this.socket){console.warn("[this.me] WebSocket already running");return}this.socket=new c(this.endpoint.replace("/graphql","")),this.socket.on("status",t=>{this._updateFromSocket({status:{active:!0,error:!1,data:t}})}),this.socket.on("listUs",t=>{this._updateFromSocket({listUs:t})}),this.socket.on("update",t=>{console.log("[this.me] update event",t)})}}_updateFromSocket(t){this.#s(t)}setEndpoint(t){typeof t=="string"&&t.trim()!==""&&(this.endpoint=t)}getState(){return this.state}#s(t){this.state={...this.state,...t},this.subscribers.forEach(s=>s(this.state))}subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)}async#t(t,s={}){const a=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,variables:s})});if(!a.ok)throw new Error(`GraphQL error: ${a.status}`);const{data:e,errors:i}=await a.json();if(i)throw new Error(i.map(o=>o.message).join(", "));return e}async status(){const t=`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class o{constructor(t="http://localhost:7777/graphql"){this.endpoint=t,this.state={status:{active:!1,error:!1,loading:!0,data:null},listUs:[]},this.subscribers=new Set,this.socket=null}async status(){const t=`
2
2
  query {
3
- status {
3
+ monadStatus {
4
4
  active
5
5
  version
6
- uptime
7
6
  }
8
7
  }
9
- `;try{const s=await this.#t(t),a=s.status?{active:s.status.active,version:s.status.version,uptime:s.status.uptime}:{active:!1,version:null,uptime:null};return this.#s({status:{active:a.active,error:!1,data:a}}),a}catch{const s={active:!1,version:null,uptime:null};return this.#s({status:{active:!1,error:!0,data:null}}),s}}async listUs(){const t=`
10
- query {
11
- listUs {
12
- alias
13
- path
8
+ `;try{const e=(await this.#e(t)).monadStatus??{active:!1,version:null};return this.#s({status:{...this.state.status,active:e.active,data:e}}),e}catch{return this.#s({status:{...this.state.status,error:!0,data:null}}),{active:!1,version:null}}}async publicInfo(t){const s=`
9
+ query($username: String!) {
10
+ publicInfo(username: $username) {
11
+ username
12
+ publicKey
14
13
  }
15
14
  }
16
- `;try{const s=await this.#t(t),a=Array.isArray(s.listUs)?s.listUs.map(({alias:e,path:i})=>({alias:e,path:i})):[];return this.#s({listUs:a}),a}catch{return this.#s({listUs:[]}),[]}}async loadMe(t,s){const a=`
17
- mutation($alias: String!, $hash: String!) {
18
- loadMe(alias: $alias, hash: $hash)
19
- }
20
- `;try{const i=!!(await this.#t(a,{alias:t,hash:s})).loadMe;return i&&this.#s({activeMe:t}),i}catch{return!1}}async be(t,s,a){const e=`
21
- mutation($alias: String!, $key: String!, $value: String!) {
22
- be(alias: $alias, key: $key, value: $value)
23
- }
24
- `;try{return!!(await this.#t(e,{alias:t,key:s,value:a})).be}catch{return!1}}async have(t,s,a){const e=`
25
- mutation($alias: String!, $key: String!, $value: String!) {
26
- have(alias: $alias, key: $key, value: $value)
27
- }
28
- `;try{return!!(await this.#t(e,{alias:t,key:s,value:a})).have}catch{return!1}}async do_(t,s,a){const e=`
29
- mutation($alias: String!, $key: String!, $value: String!) {
30
- do(alias: $alias, key: $key, value: $value)
31
- }
32
- `;try{return!!(await this.#t(e,{alias:t,key:s,value:a})).do}catch{return!1}}async at(t,s,a){const e=`
33
- mutation($alias: String!, $key: String!, $value: String!) {
34
- at(alias: $alias, key: $key, value: $value)
35
- }
36
- `;try{return!!(await this.#t(e,{alias:t,key:s,value:a})).at}catch{return!1}}async relate(t,s,a){const e=`
37
- mutation($alias: String!, $key: String!, $value: String!) {
38
- relate(alias: $alias, key: $key, value: $value)
39
- }
40
- `;try{return!!(await this.#t(e,{alias:t,key:s,value:a})).relate}catch{return!1}}async react(t,s,a){const e=`
41
- mutation($alias: String!, $key: String!, $value: String!) {
42
- react(alias: $alias, key: $key, value: $value)
43
- }
44
- `;try{return!!(await this.#t(e,{alias:t,key:s,value:a})).react}catch{return!1}}async communication(t,s,a){const e=`
45
- mutation($alias: String!, $key: String!, $value: String!) {
46
- communication(alias: $alias, key: $key, value: $value)
15
+ `;try{const r=(await this.#e(s,{username:t})).publicInfo;return r&&r.username&&r.publicKey?r:null}catch{return null}}async listIdentities(){const t=`
16
+ query {
17
+ listIdentities {
18
+ username
19
+ }
47
20
  }
48
- `;try{return!!(await this.#t(e,{alias:t,key:s,value:a})).communication}catch{return!1}}async me(t){const s=`
49
- query($alias: String!) {
50
- me(alias: $alias) {
51
- alias
52
- publicKey
21
+ `;try{const s=await this.#e(t),e=Array.isArray(s.listIdentities)?s.listIdentities.map(r=>({username:r.username,path:null})):[];return this.#s({listUs:e}),e}catch{return this.#s({listUs:[]}),[]}}async get(t,s,e={}){const r=`
22
+ query($username: String!, $password: String!, $filter: GetFilter!) {
23
+ get(username: $username, password: $password, filter: $filter) {
24
+ verb
25
+ key
26
+ value
27
+ timestamp
53
28
  }
54
29
  }
55
- `;try{const a=await this.#t(s,{alias:t});if(a.me&&typeof a.me=="object"){const{alias:e,publicKey:i}=a.me;return e&&i?{alias:e,publicKey:i}:null}return null}catch{return null}}}const n=new u;typeof window<"u"&&(window.me=n,console.log("[this.me] Global instance available as window.me"));module.exports=n;
30
+ `;try{return(await this.#e(r,{username:t,password:s,filter:e})).get||[]}catch{return[]}}async#t(t,s,e,r,a,n=null){const c=`
31
+ mutation($username: String!, $password: String!, $key: String!, $value: String!, $context_id: String) {
32
+ ${t}(username: $username, password: $password, key: $key, value: $value, context_id: $context_id)
33
+ }
34
+ `;try{return!!(await this.#e(c,{username:s,password:e,key:r,value:a,context_id:n}))[t]}catch{return!1}}async be(t,s,e,r,a=null){return this.#t("be",t,s,e,r,a)}async have(t,s,e,r,a=null){return this.#t("have",t,s,e,r,a)}async do(t,s,e,r,a=null){return this.#t("do",t,s,e,r,a)}async at(t,s,e,r,a=null){return this.#t("at",t,s,e,r,a)}async relate(t,s,e,r,a=null){return this.#t("relate",t,s,e,r,a)}async react(t,s,e,r,a=null){return this.#t("react",t,s,e,r,a)}async communicate(t,s,e,r,a=null){return this.#t("communicate",t,s,e,r,a)}setEndpoint(t){t.trim()&&(this.endpoint=t)}getState(){return this.state}subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)}#s(t){this.state={...this.state,...t},this.subscribers.forEach(s=>s(this.state))}async#e(t,s={}){const e=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,variables:s})});if(!e.ok)throw new Error(`GraphQL error: ${e.status}`);const{data:r,errors:a}=await e.json();if(a)throw new Error(a.map(n=>n.message).join(", "));return r}}const l=new o,i=new Proxy(l,{get(u,t,s){const e=Reflect.get(u,t,s);return typeof e!="function"?e:(...r)=>{const a=e.apply(u,r);return a instanceof Promise&&a.then(n=>console.log(`[this.me] ${String(t)} ✓`,n)).catch(n=>console.error(`[this.me] ${String(t)} ✗`,n)),a}}});typeof window<"u"&&(window.me=i,i.help=()=>console.table(Object.getOwnPropertyNames(o.prototype)));exports.default=i;exports.me=i;
@@ -1,324 +1,142 @@
1
1
  class o {
2
- constructor(t, s) {
3
- this.me = t, this.url = s, this.ws = null, this.reconnectInterval = 1e4, this.isConnected = !1, this.connect();
4
- }
5
- connect() {
6
- this.ws = new WebSocket(this.url), this.ws.onopen = () => {
7
- console.log("[this.me][WS] Connected to daemon"), this.isConnected = !0, this.me.state?.status && (this.me.state.status.active = !0, this.me.state.status.error = !1), this.#t();
8
- }, this.ws.onmessage = (t) => {
9
- try {
10
- const s = JSON.parse(t.data);
11
- this.#s(s);
12
- } catch {
13
- console.warn("[this.me][WS] Invalid message:", t.data);
14
- }
15
- }, this.ws.onclose = () => {
16
- console.warn("[this.me][WS] Disconnected, retrying in 10s"), this.isConnected = !1, this.me.state?.status && (this.me.state.status.active = !1, this.me.state.status.error = !0), this.#t(), setTimeout(() => this.connect(), this.reconnectInterval);
17
- }, this.ws.onerror = (t) => {
18
- console.error("[this.me][WS] Error:", t), this.ws.close();
19
- };
20
- }
21
- #s(t) {
22
- switch (t.type) {
23
- case "status":
24
- this.me.state.status = {
25
- active: t.data.active,
26
- error: !1,
27
- data: t.data
28
- };
29
- break;
30
- case "listUs":
31
- this.me.state.listUs = t.data;
32
- break;
33
- case "update":
34
- console.log("[this.me][WS] Update event:", t.data);
35
- break;
36
- default:
37
- console.warn("[this.me][WS] Unknown message type:", t.type);
38
- }
39
- this.#t();
40
- }
41
- send(t, s) {
42
- this.isConnected && this.ws.readyState === WebSocket.OPEN && this.ws.send(JSON.stringify({ type: t, data: s }));
43
- }
44
- #t() {
45
- this.me.subscribers?.size && this.me.subscribers.forEach((t) => t(this.me.state));
46
- }
47
- }
48
- class c {
49
2
  constructor(t = "http://localhost:7777/graphql") {
50
3
  this.endpoint = t, this.state = {
51
4
  status: { active: !1, error: !1, loading: !0, data: null },
52
- listUs: [],
53
- activeMe: null
54
- }, this.subscribers = /* @__PURE__ */ new Set(), this.status(), this.socket = null;
55
- }
56
- /** 🔹 Init
57
- * Manually initializes the daemon state (status + listUs).
58
- * Useful if you need to re-check after user actions.
59
- */
60
- async init() {
61
- return this.#s({
62
- status: { ...this.state.status, loading: !0 }
63
- }), (await this.status()).active && (await this.startSocket(), await new Promise((s) => {
64
- let a = !1;
65
- const e = this.subscribe((i) => {
66
- !a && i.status.active !== void 0 && (a = !0, e(), s());
67
- });
68
- setTimeout(() => {
69
- a || (a = !0, e(), s());
70
- }, 2e3);
71
- })), this.#s({
72
- status: { ...this.state.status, loading: !1 }
73
- }), this.state.status;
74
- }
75
- async startSocket() {
76
- if (this.state.status.active) {
77
- if (this.socket) {
78
- console.warn("[this.me] WebSocket already running");
79
- return;
80
- }
81
- this.socket = new o(this.endpoint.replace("/graphql", "")), this.socket.on("status", (t) => {
82
- this._updateFromSocket({
83
- status: { active: !0, error: !1, data: t }
84
- });
85
- }), this.socket.on("listUs", (t) => {
86
- this._updateFromSocket({ listUs: t });
87
- }), this.socket.on("update", (t) => {
88
- console.log("[this.me] update event", t);
89
- });
90
- }
91
- }
92
- _updateFromSocket(t) {
93
- this.#s(t);
94
- }
95
- setEndpoint(t) {
96
- typeof t == "string" && t.trim() !== "" && (this.endpoint = t);
97
- }
98
- getState() {
99
- return this.state;
100
- }
101
- #s(t) {
102
- this.state = { ...this.state, ...t }, this.subscribers.forEach((s) => s(this.state));
103
- }
104
- subscribe(t) {
105
- return this.subscribers.add(t), () => this.subscribers.delete(t);
5
+ listUs: []
6
+ }, this.subscribers = /* @__PURE__ */ new Set(), this.socket = null;
106
7
  }
107
- async #t(t, s = {}) {
108
- const a = await fetch(this.endpoint, {
109
- method: "POST",
110
- headers: { "Content-Type": "application/json" },
111
- body: JSON.stringify({ query: t, variables: s })
112
- });
113
- if (!a.ok) throw new Error(`GraphQL error: ${a.status}`);
114
- const { data: e, errors: i } = await a.json();
115
- if (i) throw new Error(i.map((r) => r.message).join(", "));
116
- return e;
117
- }
118
- // 🔹 Daemon-level helpers
119
- /** 🔹 Daemon status
120
- * Retrieves the current status of the daemon.
121
- * Use to check if the service is active and get version/uptime info.
122
- */
123
8
  async status() {
124
9
  const t = `
125
10
  query {
126
- status {
11
+ monadStatus {
127
12
  active
128
13
  version
129
- uptime
130
14
  }
131
15
  }
132
16
  `;
133
17
  try {
134
- const s = await this.#t(t), a = s.status ? {
135
- active: s.status.active,
136
- version: s.status.version,
137
- uptime: s.status.uptime
138
- } : { active: !1, version: null, uptime: null };
139
- return this.#s({ status: { active: a.active, error: !1, data: a } }), a;
18
+ const e = (await this.#e(t)).monadStatus ?? { active: !1, version: null };
19
+ return this.#s({ status: { ...this.state.status, active: e.active, data: e } }), e;
140
20
  } catch {
141
- const s = { active: !1, version: null, uptime: null };
142
- return this.#s({ status: { active: !1, error: !0, data: null } }), s;
21
+ return this.#s({ status: { ...this.state.status, error: !0, data: null } }), { active: !1, version: null };
143
22
  }
144
23
  }
145
- /** 🔹 List all identities
146
- * Fetches all available identities (users).
147
- * Use to display or manage the list of identities.
148
- */
149
- async listUs() {
150
- const t = `
151
- query {
152
- listUs {
153
- alias
154
- path
24
+ async publicInfo(t) {
25
+ const s = `
26
+ query($username: String!) {
27
+ publicInfo(username: $username) {
28
+ username
29
+ publicKey
155
30
  }
156
31
  }
157
32
  `;
158
33
  try {
159
- const s = await this.#t(t), a = Array.isArray(s.listUs) ? s.listUs.map(({ alias: e, path: i }) => ({ alias: e, path: i })) : [];
160
- return this.#s({ listUs: a }), a;
34
+ const r = (await this.#e(s, { username: t })).publicInfo;
35
+ return r && r.username && r.publicKey ? r : null;
161
36
  } catch {
162
- return this.#s({ listUs: [] }), [];
37
+ return null;
163
38
  }
164
39
  }
165
- /** 🔹 Load an identity
166
- * Loads a specific identity by alias and hash.
167
- * Use to activate or switch to a particular identity.
168
- */
169
- async loadMe(t, s) {
170
- const a = `
171
- mutation($alias: String!, $hash: String!) {
172
- loadMe(alias: $alias, hash: $hash)
40
+ async listIdentities() {
41
+ const t = `
42
+ query {
43
+ listIdentities {
44
+ username
45
+ }
173
46
  }
174
47
  `;
175
48
  try {
176
- const i = !!(await this.#t(a, { alias: t, hash: s })).loadMe;
177
- return i && this.#s({ activeMe: t }), i;
49
+ const s = await this.#e(t), e = Array.isArray(s.listIdentities) ? s.listIdentities.map((r) => ({ username: r.username, path: null })) : [];
50
+ return this.#s({ listUs: e }), e;
178
51
  } catch {
179
- return !1;
52
+ return this.#s({ listUs: [] }), [];
180
53
  }
181
54
  }
182
- // 🔹 Me-level operations
183
- /** 🔹 Be operation
184
- * Performs a 'be' mutation for given alias, key, and value.
185
- * Use to set or update identity attributes.
186
- */
187
- async be(t, s, a) {
188
- const e = `
189
- mutation($alias: String!, $key: String!, $value: String!) {
190
- be(alias: $alias, key: $key, value: $value)
55
+ async get(t, s, e = {}) {
56
+ const r = `
57
+ query($username: String!, $password: String!, $filter: GetFilter!) {
58
+ get(username: $username, password: $password, filter: $filter) {
59
+ verb
60
+ key
61
+ value
62
+ timestamp
63
+ }
191
64
  }
192
65
  `;
193
66
  try {
194
- return !!(await this.#t(e, { alias: t, key: s, value: a })).be;
67
+ return (await this.#e(r, { username: t, password: s, filter: e })).get || [];
195
68
  } catch {
196
- return !1;
69
+ return [];
197
70
  }
198
71
  }
199
- /** 🔹 Have operation
200
- * Performs a 'have' mutation for given alias, key, and value.
201
- * Use to declare possession or ownership related to identity.
202
- */
203
- async have(t, s, a) {
204
- const e = `
205
- mutation($alias: String!, $key: String!, $value: String!) {
206
- have(alias: $alias, key: $key, value: $value)
72
+ async #t(t, s, e, r, a, n = null) {
73
+ const c = `
74
+ mutation($username: String!, $password: String!, $key: String!, $value: String!, $context_id: String) {
75
+ ${t}(username: $username, password: $password, key: $key, value: $value, context_id: $context_id)
207
76
  }
208
77
  `;
209
78
  try {
210
- return !!(await this.#t(e, { alias: t, key: s, value: a })).have;
79
+ return !!(await this.#e(c, { username: s, password: e, key: r, value: a, context_id: n }))[t];
211
80
  } catch {
212
81
  return !1;
213
82
  }
214
83
  }
215
- /** 🔹 Do operation
216
- * Performs a 'do' mutation for given alias, key, and value.
217
- * Use to record actions or activities for the identity.
218
- */
219
- async do_(t, s, a) {
220
- const e = `
221
- mutation($alias: String!, $key: String!, $value: String!) {
222
- do(alias: $alias, key: $key, value: $value)
223
- }
224
- `;
225
- try {
226
- return !!(await this.#t(e, { alias: t, key: s, value: a })).do;
227
- } catch {
228
- return !1;
229
- }
84
+ async be(t, s, e, r, a = null) {
85
+ return this.#t("be", t, s, e, r, a);
230
86
  }
231
- /** 🔹 At operation
232
- * Performs an 'at' mutation for given alias, key, and value.
233
- * Use to set location or context related data for the identity.
234
- */
235
- async at(t, s, a) {
236
- const e = `
237
- mutation($alias: String!, $key: String!, $value: String!) {
238
- at(alias: $alias, key: $key, value: $value)
239
- }
240
- `;
241
- try {
242
- return !!(await this.#t(e, { alias: t, key: s, value: a })).at;
243
- } catch {
244
- return !1;
245
- }
87
+ async have(t, s, e, r, a = null) {
88
+ return this.#t("have", t, s, e, r, a);
246
89
  }
247
- /** 🔹 Relate operation
248
- * Performs a 'relate' mutation for given alias, key, and value.
249
- * Use to define relationships or connections for the identity.
250
- */
251
- async relate(t, s, a) {
252
- const e = `
253
- mutation($alias: String!, $key: String!, $value: String!) {
254
- relate(alias: $alias, key: $key, value: $value)
255
- }
256
- `;
257
- try {
258
- return !!(await this.#t(e, { alias: t, key: s, value: a })).relate;
259
- } catch {
260
- return !1;
261
- }
90
+ async do(t, s, e, r, a = null) {
91
+ return this.#t("do", t, s, e, r, a);
262
92
  }
263
- /** 🔹 React operation
264
- * Performs a 'react' mutation for given alias, key, and value.
265
- * Use to record reactions or responses by the identity.
266
- */
267
- async react(t, s, a) {
268
- const e = `
269
- mutation($alias: String!, $key: String!, $value: String!) {
270
- react(alias: $alias, key: $key, value: $value)
271
- }
272
- `;
273
- try {
274
- return !!(await this.#t(e, { alias: t, key: s, value: a })).react;
275
- } catch {
276
- return !1;
277
- }
93
+ async at(t, s, e, r, a = null) {
94
+ return this.#t("at", t, s, e, r, a);
278
95
  }
279
- /** 🔹 Communication operation
280
- * Performs a 'communication' mutation for given alias, key, and value.
281
- * Use to log communications or messages for the identity.
282
- */
283
- async communication(t, s, a) {
284
- const e = `
285
- mutation($alias: String!, $key: String!, $value: String!) {
286
- communication(alias: $alias, key: $key, value: $value)
287
- }
288
- `;
289
- try {
290
- return !!(await this.#t(e, { alias: t, key: s, value: a })).communication;
291
- } catch {
292
- return !1;
293
- }
96
+ async relate(t, s, e, r, a = null) {
97
+ return this.#t("relate", t, s, e, r, a);
294
98
  }
295
- /** 🔹 Get identity info
296
- * Queries detailed information about a specific identity by alias.
297
- * Use to retrieve public data like alias and publicKey.
298
- */
299
- async me(t) {
300
- const s = `
301
- query($alias: String!) {
302
- me(alias: $alias) {
303
- alias
304
- publicKey
305
- }
306
- }
307
- `;
308
- try {
309
- const a = await this.#t(s, { alias: t });
310
- if (a.me && typeof a.me == "object") {
311
- const { alias: e, publicKey: i } = a.me;
312
- return e && i ? { alias: e, publicKey: i } : null;
313
- }
314
- return null;
315
- } catch {
316
- return null;
317
- }
99
+ async react(t, s, e, r, a = null) {
100
+ return this.#t("react", t, s, e, r, a);
101
+ }
102
+ async communicate(t, s, e, r, a = null) {
103
+ return this.#t("communicate", t, s, e, r, a);
104
+ }
105
+ setEndpoint(t) {
106
+ t.trim() && (this.endpoint = t);
107
+ }
108
+ getState() {
109
+ return this.state;
110
+ }
111
+ subscribe(t) {
112
+ return this.subscribers.add(t), () => this.subscribers.delete(t);
113
+ }
114
+ #s(t) {
115
+ this.state = { ...this.state, ...t }, this.subscribers.forEach((s) => s(this.state));
116
+ }
117
+ async #e(t, s = {}) {
118
+ const e = await fetch(this.endpoint, {
119
+ method: "POST",
120
+ headers: { "Content-Type": "application/json" },
121
+ body: JSON.stringify({ query: t, variables: s })
122
+ });
123
+ if (!e.ok) throw new Error(`GraphQL error: ${e.status}`);
124
+ const { data: r, errors: a } = await e.json();
125
+ if (a) throw new Error(a.map((n) => n.message).join(", "));
126
+ return r;
318
127
  }
319
128
  }
320
- const u = new c();
321
- typeof window < "u" && (window.me = u, console.log("[this.me] Global instance available as window.me"));
129
+ const l = new o(), u = new Proxy(l, {
130
+ get(i, t, s) {
131
+ const e = Reflect.get(i, t, s);
132
+ return typeof e != "function" ? e : (...r) => {
133
+ const a = e.apply(i, r);
134
+ return a instanceof Promise && a.then((n) => console.log(`[this.me] ${String(t)} ✓`, n)).catch((n) => console.error(`[this.me] ${String(t)} ✗`, n)), a;
135
+ };
136
+ }
137
+ });
138
+ typeof window < "u" && (window.me = u, u.help = () => console.table(Object.getOwnPropertyNames(o.prototype)));
322
139
  export {
323
- u as default
140
+ u as default,
141
+ u as me
324
142
  };
@@ -1,55 +1,34 @@
1
- (function(n,r){typeof exports=="object"&&typeof module<"u"?module.exports=r():typeof define=="function"&&define.amd?define(r):(n=typeof globalThis<"u"?globalThis:n||self,n.Me=r())})(this,function(){"use strict";class n{constructor(t,s){this.me=t,this.url=s,this.ws=null,this.reconnectInterval=1e4,this.isConnected=!1,this.connect()}connect(){this.ws=new WebSocket(this.url),this.ws.onopen=()=>{console.log("[this.me][WS] Connected to daemon"),this.isConnected=!0,this.me.state?.status&&(this.me.state.status.active=!0,this.me.state.status.error=!1),this.#t()},this.ws.onmessage=t=>{try{const s=JSON.parse(t.data);this.#s(s)}catch{console.warn("[this.me][WS] Invalid message:",t.data)}},this.ws.onclose=()=>{console.warn("[this.me][WS] Disconnected, retrying in 10s"),this.isConnected=!1,this.me.state?.status&&(this.me.state.status.active=!1,this.me.state.status.error=!0),this.#t(),setTimeout(()=>this.connect(),this.reconnectInterval)},this.ws.onerror=t=>{console.error("[this.me][WS] Error:",t),this.ws.close()}}#s(t){switch(t.type){case"status":this.me.state.status={active:t.data.active,error:!1,data:t.data};break;case"listUs":this.me.state.listUs=t.data;break;case"update":console.log("[this.me][WS] Update event:",t.data);break;default:console.warn("[this.me][WS] Unknown message type:",t.type)}this.#t()}send(t,s){this.isConnected&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:t,data:s}))}#t(){this.me.subscribers?.size&&this.me.subscribers.forEach(t=>t(this.me.state))}}class r{constructor(t="http://localhost:7777/graphql"){this.endpoint=t,this.state={status:{active:!1,error:!1,loading:!0,data:null},listUs:[],activeMe:null},this.subscribers=new Set,this.status(),this.socket=null}async init(){return this.#s({status:{...this.state.status,loading:!0}}),(await this.status()).active&&(await this.startSocket(),await new Promise(s=>{let e=!1;const a=this.subscribe(i=>{!e&&i.status.active!==void 0&&(e=!0,a(),s())});setTimeout(()=>{e||(e=!0,a(),s())},2e3)})),this.#s({status:{...this.state.status,loading:!1}}),this.state.status}async startSocket(){if(this.state.status.active){if(this.socket){console.warn("[this.me] WebSocket already running");return}this.socket=new n(this.endpoint.replace("/graphql","")),this.socket.on("status",t=>{this._updateFromSocket({status:{active:!0,error:!1,data:t}})}),this.socket.on("listUs",t=>{this._updateFromSocket({listUs:t})}),this.socket.on("update",t=>{console.log("[this.me] update event",t)})}}_updateFromSocket(t){this.#s(t)}setEndpoint(t){typeof t=="string"&&t.trim()!==""&&(this.endpoint=t)}getState(){return this.state}#s(t){this.state={...this.state,...t},this.subscribers.forEach(s=>s(this.state))}subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)}async#t(t,s={}){const e=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,variables:s})});if(!e.ok)throw new Error(`GraphQL error: ${e.status}`);const{data:a,errors:i}=await e.json();if(i)throw new Error(i.map(u=>u.message).join(", "));return a}async status(){const t=`
1
+ (function(a,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(a=typeof globalThis<"u"?globalThis:a||self,u(a.Me={}))})(this,(function(a){"use strict";class u{constructor(t="http://localhost:7777/graphql"){this.endpoint=t,this.state={status:{active:!1,error:!1,loading:!0,data:null},listUs:[]},this.subscribers=new Set,this.socket=null}async status(){const t=`
2
2
  query {
3
- status {
3
+ monadStatus {
4
4
  active
5
5
  version
6
- uptime
7
6
  }
8
7
  }
9
- `;try{const s=await this.#t(t),e=s.status?{active:s.status.active,version:s.status.version,uptime:s.status.uptime}:{active:!1,version:null,uptime:null};return this.#s({status:{active:e.active,error:!1,data:e}}),e}catch{const s={active:!1,version:null,uptime:null};return this.#s({status:{active:!1,error:!0,data:null}}),s}}async listUs(){const t=`
10
- query {
11
- listUs {
12
- alias
13
- path
8
+ `;try{const e=(await this.#e(t)).monadStatus??{active:!1,version:null};return this.#s({status:{...this.state.status,active:e.active,data:e}}),e}catch{return this.#s({status:{...this.state.status,error:!0,data:null}}),{active:!1,version:null}}}async publicInfo(t){const s=`
9
+ query($username: String!) {
10
+ publicInfo(username: $username) {
11
+ username
12
+ publicKey
14
13
  }
15
14
  }
16
- `;try{const s=await this.#t(t),e=Array.isArray(s.listUs)?s.listUs.map(({alias:a,path:i})=>({alias:a,path:i})):[];return this.#s({listUs:e}),e}catch{return this.#s({listUs:[]}),[]}}async loadMe(t,s){const e=`
17
- mutation($alias: String!, $hash: String!) {
18
- loadMe(alias: $alias, hash: $hash)
19
- }
20
- `;try{const i=!!(await this.#t(e,{alias:t,hash:s})).loadMe;return i&&this.#s({activeMe:t}),i}catch{return!1}}async be(t,s,e){const a=`
21
- mutation($alias: String!, $key: String!, $value: String!) {
22
- be(alias: $alias, key: $key, value: $value)
23
- }
24
- `;try{return!!(await this.#t(a,{alias:t,key:s,value:e})).be}catch{return!1}}async have(t,s,e){const a=`
25
- mutation($alias: String!, $key: String!, $value: String!) {
26
- have(alias: $alias, key: $key, value: $value)
27
- }
28
- `;try{return!!(await this.#t(a,{alias:t,key:s,value:e})).have}catch{return!1}}async do_(t,s,e){const a=`
29
- mutation($alias: String!, $key: String!, $value: String!) {
30
- do(alias: $alias, key: $key, value: $value)
31
- }
32
- `;try{return!!(await this.#t(a,{alias:t,key:s,value:e})).do}catch{return!1}}async at(t,s,e){const a=`
33
- mutation($alias: String!, $key: String!, $value: String!) {
34
- at(alias: $alias, key: $key, value: $value)
35
- }
36
- `;try{return!!(await this.#t(a,{alias:t,key:s,value:e})).at}catch{return!1}}async relate(t,s,e){const a=`
37
- mutation($alias: String!, $key: String!, $value: String!) {
38
- relate(alias: $alias, key: $key, value: $value)
39
- }
40
- `;try{return!!(await this.#t(a,{alias:t,key:s,value:e})).relate}catch{return!1}}async react(t,s,e){const a=`
41
- mutation($alias: String!, $key: String!, $value: String!) {
42
- react(alias: $alias, key: $key, value: $value)
43
- }
44
- `;try{return!!(await this.#t(a,{alias:t,key:s,value:e})).react}catch{return!1}}async communication(t,s,e){const a=`
45
- mutation($alias: String!, $key: String!, $value: String!) {
46
- communication(alias: $alias, key: $key, value: $value)
15
+ `;try{const n=(await this.#e(s,{username:t})).publicInfo;return n&&n.username&&n.publicKey?n:null}catch{return null}}async listIdentities(){const t=`
16
+ query {
17
+ listIdentities {
18
+ username
19
+ }
47
20
  }
48
- `;try{return!!(await this.#t(a,{alias:t,key:s,value:e})).communication}catch{return!1}}async me(t){const s=`
49
- query($alias: String!) {
50
- me(alias: $alias) {
51
- alias
52
- publicKey
21
+ `;try{const s=await this.#e(t),e=Array.isArray(s.listIdentities)?s.listIdentities.map(n=>({username:n.username,path:null})):[];return this.#s({listUs:e}),e}catch{return this.#s({listUs:[]}),[]}}async get(t,s,e={}){const n=`
22
+ query($username: String!, $password: String!, $filter: GetFilter!) {
23
+ get(username: $username, password: $password, filter: $filter) {
24
+ verb
25
+ key
26
+ value
27
+ timestamp
53
28
  }
54
29
  }
55
- `;try{const e=await this.#t(s,{alias:t});if(e.me&&typeof e.me=="object"){const{alias:a,publicKey:i}=e.me;return a&&i?{alias:a,publicKey:i}:null}return null}catch{return null}}}const o=new r;return typeof window<"u"&&(window.me=o,console.log("[this.me] Global instance available as window.me")),o});
30
+ `;try{return(await this.#e(n,{username:t,password:s,filter:e})).get||[]}catch{return[]}}async#t(t,s,e,n,r,i=null){const d=`
31
+ mutation($username: String!, $password: String!, $key: String!, $value: String!, $context_id: String) {
32
+ ${t}(username: $username, password: $password, key: $key, value: $value, context_id: $context_id)
33
+ }
34
+ `;try{return!!(await this.#e(d,{username:s,password:e,key:n,value:r,context_id:i}))[t]}catch{return!1}}async be(t,s,e,n,r=null){return this.#t("be",t,s,e,n,r)}async have(t,s,e,n,r=null){return this.#t("have",t,s,e,n,r)}async do(t,s,e,n,r=null){return this.#t("do",t,s,e,n,r)}async at(t,s,e,n,r=null){return this.#t("at",t,s,e,n,r)}async relate(t,s,e,n,r=null){return this.#t("relate",t,s,e,n,r)}async react(t,s,e,n,r=null){return this.#t("react",t,s,e,n,r)}async communicate(t,s,e,n,r=null){return this.#t("communicate",t,s,e,n,r)}setEndpoint(t){t.trim()&&(this.endpoint=t)}getState(){return this.state}subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)}#s(t){this.state={...this.state,...t},this.subscribers.forEach(s=>s(this.state))}async#e(t,s={}){const e=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,variables:s})});if(!e.ok)throw new Error(`GraphQL error: ${e.status}`);const{data:n,errors:r}=await e.json();if(r)throw new Error(r.map(i=>i.message).join(", "));return n}}const l=new u,o=new Proxy(l,{get(c,t,s){const e=Reflect.get(c,t,s);return typeof e!="function"?e:(...n)=>{const r=e.apply(c,n);return r instanceof Promise&&r.then(i=>console.log(`[this.me] ${String(t)} ✓`,i)).catch(i=>console.error(`[this.me] ${String(t)} ✗`,i)),r}}});typeof window<"u"&&(window.me=o,o.help=()=>console.table(Object.getOwnPropertyNames(u.prototype))),a.default=o,a.me=o,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "this.me",
3
- "version": "3.0.0",
4
- "description": ".me is your identity. It enables decentralized trust through cryptographic signatures.",
5
- "main": "dist/this-me.cjs.js",
6
- "module": "dist/this-me.es.js",
7
- "browser": "dist/this-me.umd.js",
3
+ "version": "3.0.2",
4
+ "description": ".me is your identity decentralized trust through cryptographic signatures.",
5
+ "main": "dist/index.cjs.js",
6
+ "module": "dist/index.es.js",
7
+ "browser": "dist/index.umd.js",
8
8
  "exports": {
9
9
  ".": {
10
- "import": "./dist/this-me.es.js",
11
- "require": "./dist/this-me.cjs.js"
10
+ "import": "./dist/index.es.js",
11
+ "require": "./dist/index.cjs.js"
12
12
  }
13
13
  },
14
14
  "type": "module",