this.me 3.0.0 → 3.0.21
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 +18 -43
- package/dist/this-me.cjs.js +24 -45
- package/dist/this-me.es.js +90 -272
- package/dist/this-me.umd.js +24 -45
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
<img src="https://
|
|
1
|
+
<img src="https://res.cloudinary.com/dkwnxf6gm/image/upload/v1761149332/this.me-removebg-preview_2_j1eoiy.png" alt="57b0b83e8518fecf9b3e2d06457421c7da70e0663f7490fab98f9ecbdbe5db6e-removebg-preview" style="zoom:34%;" />
|
|
2
2
|
|
|
3
|
-
#
|
|
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
|
-
|
|
5
|
+
You can use **.me** both in **browser** and **Node** environments.
|
|
7
6
|
|
|
8
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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**
|
package/dist/this-me.cjs.js
CHANGED
|
@@ -1,55 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
-
|
|
3
|
+
monadStatus {
|
|
4
4
|
active
|
|
5
5
|
version
|
|
6
|
-
uptime
|
|
7
6
|
}
|
|
8
7
|
}
|
|
9
|
-
`;try{const
|
|
10
|
-
query {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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{
|
|
49
|
-
query($
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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{
|
|
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;
|
package/dist/this-me.es.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
11
|
+
monadStatus {
|
|
127
12
|
active
|
|
128
13
|
version
|
|
129
|
-
uptime
|
|
130
14
|
}
|
|
131
15
|
}
|
|
132
16
|
`;
|
|
133
17
|
try {
|
|
134
|
-
const
|
|
135
|
-
|
|
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
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
160
|
-
return
|
|
34
|
+
const r = (await this.#e(s, { username: t })).publicInfo;
|
|
35
|
+
return r && r.username && r.publicKey ? r : null;
|
|
161
36
|
} catch {
|
|
162
|
-
return
|
|
37
|
+
return null;
|
|
163
38
|
}
|
|
164
39
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
|
177
|
-
return
|
|
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
|
|
52
|
+
return this.#s({ listUs: [] }), [];
|
|
180
53
|
}
|
|
181
54
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
|
67
|
+
return (await this.#e(r, { username: t, password: s, filter: e })).get || [];
|
|
195
68
|
} catch {
|
|
196
|
-
return
|
|
69
|
+
return [];
|
|
197
70
|
}
|
|
198
71
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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.#
|
|
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
|
-
|
|
216
|
-
|
|
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
|
-
|
|
232
|
-
|
|
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
|
-
|
|
248
|
-
|
|
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
|
-
|
|
264
|
-
|
|
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
|
-
|
|
280
|
-
|
|
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
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
|
321
|
-
|
|
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
|
};
|
package/dist/this-me.umd.js
CHANGED
|
@@ -1,55 +1,34 @@
|
|
|
1
|
-
(function(
|
|
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
|
-
|
|
3
|
+
monadStatus {
|
|
4
4
|
active
|
|
5
5
|
version
|
|
6
|
-
uptime
|
|
7
6
|
}
|
|
8
7
|
}
|
|
9
|
-
`;try{const
|
|
10
|
-
query {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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{
|
|
49
|
-
query($
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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{
|
|
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.
|
|
4
|
-
"description": ".me is your identity
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"module": "dist/
|
|
7
|
-
"browser": "dist/
|
|
3
|
+
"version": "3.0.21",
|
|
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/
|
|
11
|
-
"require": "./dist/
|
|
10
|
+
"import": "./dist/index.es.js",
|
|
11
|
+
"require": "./dist/index.cjs.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"type": "module",
|