addie-js 0.0.1
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 +22 -0
- package/addie.js +72 -0
- package/package.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Addie
|
|
2
|
+
|
|
3
|
+
This is the JavaScript client SDK for the Addie miniservice.
|
|
4
|
+
|
|
5
|
+
### Usage
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
import addie from 'addie-js';
|
|
9
|
+
|
|
10
|
+
const saveKeys = (keys) => { /* handle persisting keys here */ };
|
|
11
|
+
const getKeys = () => { /* return keys here. Can be async */ };
|
|
12
|
+
|
|
13
|
+
const stateHash = 'add a hash of the current state';
|
|
14
|
+
|
|
15
|
+
const uuid = await addie.createUser(stateHash, saveKeys, getKeys);
|
|
16
|
+
|
|
17
|
+
// unimplemented const updatedUser = await addie.addProcessorAccount(uuid, /* processorInfo - there is a reference stripe implementation in the repo, but not quite ready for public release yet */);
|
|
18
|
+
|
|
19
|
+
// unimplemented const paymentIntent = await addie.getPaymentIntent(uuid, <processor>, <processorInfo>);
|
|
20
|
+
|
|
21
|
+
const deleted = await addie.deleteUser(uuid, newStateHash); // returns true on success
|
|
22
|
+
```
|
package/addie.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import sessionless from 'sessionless-node';
|
|
2
|
+
import fetch from 'node-fetch';
|
|
3
|
+
|
|
4
|
+
const get = async (url) => {
|
|
5
|
+
return await fetch(url);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const post = async (url, payload) => {
|
|
9
|
+
return await fetch(url, {
|
|
10
|
+
method: 'post',
|
|
11
|
+
body: JSON.stringify(payload),
|
|
12
|
+
headers: {'Content-Type': 'application/json'}
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const put = async (url, payload) => {
|
|
17
|
+
return await fetch(url, {
|
|
18
|
+
method: 'put',
|
|
19
|
+
body: JSON.stringify(payload),
|
|
20
|
+
headers: {'Content-Type': 'application/json'}
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const _delete = async (url, payload) => {
|
|
25
|
+
return await fetch(url, {
|
|
26
|
+
method: 'delete',
|
|
27
|
+
body: JSON.stringify(payload),
|
|
28
|
+
headers: {'Content-Type': 'application/json'}
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const addie = {
|
|
33
|
+
baseURL: 'https://dev.addie.allyabase.com/',
|
|
34
|
+
|
|
35
|
+
createUser: async (saveKeys, getKeys) => {
|
|
36
|
+
const keys = await sessionless.generateKeys(saveKeys, getKeys);
|
|
37
|
+
|
|
38
|
+
const payload = {
|
|
39
|
+
timestamp: new Date().getTime() + '',
|
|
40
|
+
pubKey: keys.pubKey
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
payload.signature = await sessionless.sign(payload.timestamp + payload.pubKey);
|
|
44
|
+
|
|
45
|
+
const res = await put(`${addie.baseURL}user/create`, payload);
|
|
46
|
+
const user = await res.json();
|
|
47
|
+
const uuid = user.uuid;
|
|
48
|
+
|
|
49
|
+
return uuid;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
addProcessorAccount: async (uuid, processorPayload) => {
|
|
53
|
+
return 'unimplemented';
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
getPaymentIntent: async (uuid, processor, processorPayload) => {
|
|
57
|
+
return 'unimplemented';
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
deleteUser: async (uuid) => {
|
|
61
|
+
const timestamp = new Date().getTime() + '';
|
|
62
|
+
|
|
63
|
+
const signature = await sessionless.sign(timestamp + uuid);
|
|
64
|
+
const payload = {timestamp, uuid, signature};
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
const res = await _delete(`${addie.baseURL}user/${uuid}`, payload);
|
|
68
|
+
return res.status === 200;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default addie;
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "addie-js",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Addie JavaScript client",
|
|
5
|
+
"main": "addie.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/planet-nine-app/addie.git"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"author": "planetnineisaspaceship",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"node-fetch": "^3.3.2",
|
|
18
|
+
"sessionless-node": "^0.11.0"
|
|
19
|
+
}
|
|
20
|
+
}
|