Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #238 from 3box/release/1.1.0
Browse files Browse the repository at this point in the history
Release/1.1.0
  • Loading branch information
Joel Torstensson authored Dec 27, 2018
2 parents 1f4a35f + 18732cb commit c64b8ac
Show file tree
Hide file tree
Showing 18 changed files with 2,559 additions and 708 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ lib/
dist/
coverage/
tmp/
.js-ipfs
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[![CircleCI](https://img.shields.io/circleci/project/github/3box/3box-js/master.svg?style=for-the-badge)](https://circleci.com/gh/3box/3box-js)
[![CircleCI](https://img.shields.io/circleci/project/github/3box/3box-js.svg?style=for-the-badge)](https://circleci.com/gh/3box/3box-js)
[![Discord](https://img.shields.io/discord/484729862368526356.svg?style=for-the-badge)](https://discordapp.com/invite/Z3f3Cxy)
[![npm](https://img.shields.io/npm/dt/3box.svg?style=for-the-badge)](https://www.npmjs.com/package/3box)
[![npm](https://img.shields.io/npm/v/3box.svg?style=for-the-badge)](https://www.npmjs.com/package/3box)
[![Codecov](https://img.shields.io/codecov/c/github/uport-project/3box-js.svg?style=for-the-badge)](https://codecov.io/gh/uport-project/3box-js)
[![Twitter Follow](https://img.shields.io/twitter/follow/3boxdb.svg?style=for-the-badge&label=Twitter)](https://twitter.com/3boxdb)
[![Greenkeeper badge](https://badges.greenkeeper.io/3box/3box-js.svg)](https://greenkeeper.io/)

[Install](#install) | [Usage](#usage) | [Dapp data](#dappdata) | [Example](#example) | [API Docs](#api)

Expand Down Expand Up @@ -155,6 +156,8 @@ This runs a simple server at `http://localhost:3000/` that serves the static `ex
* [.logout()](#Box+logout)
* _static_
* [.getProfile(address, opts)](#Box.getProfile) ⇒ <code>Object</code>
* [.getProfiles(address, opts)](#Box.getProfiles) ⇒ <code>Object</code>
* [.profileGraphQL(query, opts)](#Box.profileGraphQL) ⇒ <code>Object</code>
* [.openBox(address, ethereumProvider, opts)](#Box.openBox)[<code>Box</code>](#Box)
* [.isLoggedIn(address)](#Box.isLoggedIn) ⇒ <code>Boolean</code>

Expand Down Expand Up @@ -223,8 +226,38 @@ Get the public profile of a given address
| address | <code>String</code> | An ethereum address |
| opts | <code>Object</code> | Optional parameters |
| opts.addressServer | <code>String</code> | URL of the Address Server |
| opts.ipfsOptions | <code>Object</code> | A ipfs options object to pass to the js-ipfs constructor |
| opts.ipfs | <code>Object</code> | A js-ipfs ipfs object |
| opts.orbitPath | <code>String</code> | A custom path for orbitdb storage |
| opts.iframeStore | <code>Boolean</code> | Use iframe for storage, allows shared store across domains. Default true when run in browser. |
| opts.useCacheService | <code>Boolean</code> | Use 3Box API and Cache Service to fetch profile instead of OrbitDB. Default true. |

<a name="Box.getProfiles"></a>

#### Box.getProfiles(address, opts) ⇒ <code>Object</code>
Get a list of public profiles for given addresses. This relies on 3Box profile API.

**Kind**: static method of [<code>Box</code>](#Box)
**Returns**: <code>Object</code> - a json object with each key an address and value the profile

| Param | Type | Description |
| --- | --- | --- |
| address | <code>Array</code> | An array of ethereum addresses |
| opts | <code>Object</code> | Optional parameters |
| opts.profileServer | <code>String</code> | URL of Profile API server |

<a name="Box.profileGraphQL"></a>

#### Box.profileGraphQL(query, opts) ⇒ <code>Object</code>
GraphQL for 3Box profile API

**Kind**: static method of [<code>Box</code>](#Box)
**Returns**: <code>Object</code> - a json object with each key an address and value the profile

| Param | Type | Description |
| --- | --- | --- |
| query | <code>Object</code> | A graphQL query object. |
| opts | <code>Object</code> | Optional parameters |
| opts.graphqlServer | <code>String</code> | URL of graphQL 3Box profile service |

<a name="Box.openBox"></a>

Expand All @@ -241,9 +274,10 @@ Opens the user space associated with the given address
| opts | <code>Object</code> | Optional parameters |
| opts.consentCallback | <code>function</code> | A function that will be called when the user has consented to opening the box |
| opts.pinningNode | <code>String</code> | A string with an ipfs multi-address to a 3box pinning node |
| opts.ipfsOptions | <code>Object</code> | A ipfs options object to pass to the js-ipfs constructor |
| opts.ipfs | <code>Object</code> | A js-ipfs ipfs object |
| opts.orbitPath | <code>String</code> | A custom path for orbitdb storage |
| opts.addressServer | <code>String</code> | URL of the Address Server |
| opts.iframeStore | <code>Boolean</code> | Use iframe for storage, allows shared store across domains. Default true when run in browser. |

<a name="Box.isLoggedIn"></a>

Expand Down Expand Up @@ -325,3 +359,4 @@ Remove the value for the given key
| Param | Type | Description |
| --- | --- | --- |
| key | <code>String</code> | the key |

11 changes: 11 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Release Notes

## v1.1.0 - 2018-12-27
### Features
* Local cache using an iframe
IPFS and OrbitDB data is now shared between dapps. The data is now stored in an iframe instead of being replicated between each dapp.
* Network cache
When syncing public profiles of users a centralized caching service is now used by default. This speeds up the process of getting multiple public profiles at once. This feature can be disabled in favor for the decentralized approach.
* GraphQL queries
It's now possible to encode GraphQL queries for public profiles. This allows for queries of only the relevant information of profiles.
* Ethereum address proof
The proof that links users ethereum address to their 3Box profile is now stored in their 3Box.

## v1.0.6 - 2018-12-4
Improve error handling
Publish DID in public profile
Expand Down
41 changes: 39 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html>
<head>
<title>3box Demo</title>
<script type="text/javascript" src="../dist/3box.js"></script>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>

Expand All @@ -21,6 +21,17 @@ <h2> Public Store </h2>
<input type="text" id="prvalue" placeholder="Profile Value" >
<button id="setProfile" type="button" class="btn btn-primary">Set Profile Data</button>

<h3> Verified Accounts </h3>
<p>
<span id="verifiedAccounts"></span>
</p>
<input type="text" id="gisturl" placeholder="Gist URL" >
<button id="verifyGithub" type="button" class="btn btn-primary">Verify Github</button>

<p><b>Verified Github:</b>
<span id="githubUser"></span>
</p>

<h5 style="padding: 20px 0px 10px 0px"> Profile: </h5>
<p>
<span id="profileData"></span>
Expand Down Expand Up @@ -64,8 +75,34 @@ <h5 style="padding: 20px 0px 10px 0px"> Profile: </h5>
</p>
</div>
</div>
</body>

<div style="padding: 5px 100px; width: 100%;">
<!-- Get Profile GraphQL Div -->
<div style="padding: 0px 0px 25px 0px;">
<h2> Get Profile GraphQL </h2>
<div style="width: 100%;">
<textarea id="profileGraphQLQuery" rows="9" cols="70">
{
profile(id: "PUT_AN_ADDRESS_HERE") {
name
did
email
website
}
}
</textarea>
</div>

<button id="profileGraphQL" type="button" class="btn btn-primary">Query Profiles </button>

<h5 style="padding: 20px 0px 10px 0px"> Profile: </h5>
<p>
<span id="profileGraphQLData"></span>
</p>
</div>
</div>
</body>
<script type="text/javascript" src="../dist/3box.js"></script>
<script type="text/javascript" src="index.js"></script>

</html>
55 changes: 48 additions & 7 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
bopen.addEventListener('click', event => {

const syncComplete = (res) => {
console.log('Sync Complete')
updateProfileData(window.box)
}

window.ethereum.enable().then(addresses => {
Box.openBox(addresses[0], window.ethereum).then(box => {
Box.openBox(addresses[0], window.ethereum, {}).then(box => {
box.onSyncDone(syncComplete)
window.box = box
console.log(box)
Expand All @@ -19,6 +21,13 @@ bopen.addEventListener('click', event => {
updateProfileData(box)
})
})
verifyGithub.addEventListener('click', () => {
box.verified.addGithub(gisturl.value).then(() => {
updateProfileData(box)
}).catch(error => {
githubUser.innerHTML = error
})
})

setPrivateStore.addEventListener('click', () => {
box.private.set(pskey.value, psvalue.value).then(() => {
Expand All @@ -44,33 +53,65 @@ bopen.addEventListener('click', event => {

getProfile.addEventListener('click', () => {
console.log(ethAddr.value)
Box.getProfile(ethAddr.value).then(profile => {
Box.getProfile(ethAddr.value, {}).then(profile => {
console.log(profile)
Object.entries(profile).map(kv => {
getProfileData.innerHTML +=kv[0] + ': ' + kv[1] + '<br />'
getProfileData.innerHTML += kv[0] + ': ' + kv[1] + '<br />'
})
})
})

profileGraphQL.addEventListener('click', () => {
const query = profileGraphQLQuery.value
console.log(query)
Box.profileGraphQL(query).then(res => {
console.log(res)
profileGraphQLData.innerHTML = ''
if (res.profile) {
Object.entries(res.profile).map(kv => {
profileGraphQLData.innerHTML +=kv[0] + ': ' + kv[1] + '<br />'
})
} else if (res.profiles) {
res.profiles.map(profile => {
Object.entries(profile).map(kv => {
profileGraphQLData.innerHTML +=kv[0] + ': ' + kv[1] + '<br />'
})
profileGraphQLData.innerHTML += '<hr />'
})
}
})
})

function updateProfileData(box) {
profileData.innerHTML = ''
box.public.all().then(profile => {
console.log(profile)
Object.entries(profile).map(kv => {
profileData.innerHTML +=kv[0] + ': ' + kv[1] + '<br />'
profileData.innerHTML += kv[0] + ': ' + kv[1] + '<br />'
})
})
updateGithubUser(box)
}

function updatePrivateData(key, value) {
function updatePrivateData (key, value) {
privateStoreData.innerHTML = ''
privateStoreData.innerHTML = key + ': ' + value
privateStoreData.innerHTML = key + ': ' + value
}

function logout(box){
function logout (box) {
box.logout().then(() => {
privateStoreData.innerHTML = ''
profileData.innerHTML = ''
controlls.style.display = 'none'
})
}

function updateGithubUser (box) {
githubUser.innerHTML = ''
box.verified.github().then(username => {
console.log(username)
githubUser.innerHTML = username
}).catch(error => {
githubUser.innerHTML = error
})
}
Loading

0 comments on commit c64b8ac

Please sign in to comment.