Browse Source

Removing old file

Signed-off-by: Mary Anthony <mary@blockstack.com>
feat/clarity-updates
Mary Anthony 5 years ago
parent
commit
6dd9a488ce
  1. 108
      _develop/collections-tutorial.md
  2. 182
      _develop/collections.md

108
_develop/collections-tutorial.md

@ -1,108 +0,0 @@
# Collections Quickstart (Preview)
In this quick start guide, you will learn to use the collections data storage feature in Blockstack. In this guide we will be using the contacts collection.
Collections is a way to store common user data in a known location with a known structure. This allows different apps on Blockstack to access and write to the same collection of data. This allows users to use the same data in different apps. For example. a user can create a single store of contacts or photos that could be read and shared in many different apps with permission. For details on collections see the proposal: https://forum.blockstack.org/t/feedback-wanted-collections-design/7752
## The guide will cover the following:
1. Setting up your app to use collections
2. Requesting the collection scope when authenticating users
3. The collection object storage operations. (Write, Read, List, Delete)
4. Using and modifying collection objects
# Getting started
**Prerequisites:**
- Your app uses Blockstack auth (blockstack.js)
- Your app uses Gaia to store it’s data
- You have the pre-release version of the Blockstack browser with collections support installed [Download Blockstack Browser Collections Alpha](https://github.com/blockstack/blockstack-browser/releases/download/collections-alpha.1/Blockstack-for-macOS-collections-alpha.dmg)
To start using collections in your Blockstack app, you will need to first import the preview branch of blockstack.js.
npm install blockstack@20.0.0-alpha.3
Add the `blockstack-collection-schemas` package to your app.
npm install blockstack-collections@0.1.7
Import the `Contact` collection type
import { Contact } from 'blockstack-collections'
# Requesting Collection Scope
Customize your sign in request to include the contacts collection scope `Contact.scope`. This will grant your app permission to read and write to the user’s contacts collection.
import { UserSession, AppConfig, makeAuthRequest } from 'blockstack'
import { Contact } from 'blockstack-collection-schemas'
const scopes = ['store_write', 'publish_data', Contact.scope]
const appConfig = new AppConfig(scopes)
const userSession = new UserSession({appConfig: appConfig})
const authRequest = makeAuthRequest(undefined, undefined, undefined, scopes, undefined, undefined, {
solicitGaiaHubUrl: true,
recommendedGaiaHubUrl: 'https://develop-hub.blockstack.org'
})
userSession.redirectToSignInWithAuthRequest(authRequest)
*Note: This example enables the custom Gaia hub selection prompt to point at the pre-release hub that has collections features enabled.*
# Collection storage operations
Collection storage has been designed around an ORM-like interface. What this means is that you’ll be working with typed objects instead of the `getFile`, `putFile` functions provided by blockstack.js.
## Creating and saving a collection object
const newContact = {
lastName: 'Stackerson',
firstName: 'Blocky',
blockstackID: 'Blockstacker.id',
email: 'blockstacker@blockstack.org',
website: 'blockstack.org',
telephone: '123123123'
}
var contact = new Contact(newContact)
contact.save().then((contactID) => {
// contact saved successfully
})
## Reading a collection object
let contactID = 'Blocky Stackerson'
Contact.get(contactID).then((contact) => {
// Do something with the contact object
console.log(`Hello ${contact.firstName}`)
})
## Listing collection objects
let contacts = []
Contact.list((contactID) => {
// This callback is invoked for each contact identifier
// To get the actual object you'll need to use Contact.get
// Or you can add the IDs to an array for display
contacts.push(contactID)
// Return true to continue iterating, return false to stop
return true
})
## Deleting collection objects
var contact = new Contact(newContact)
contact.delete().then(() => {
// contact deleted successfully
})
# Demo app
A working demo app for the contacts collection is available here: https://github.com/yknl/blockstack-contacts
Blockstack contacts is a simple contacts manager that allows users to add and manage their contacts. The data stored by this app can be used in another app that receives the contacts collection permissions.

182
_develop/collections.md

@ -209,188 +209,6 @@ Collection storage was designed around an ORM-like interface. This approach ensu
### Example: Delete a Contact
```javascript
var contact = new Contact(newContact)
contact.delete().then(() => {
// contact deleted successfully
})
```
{:.no_toc}
Collections make data portable among Blockstack applications by storing a user's data in structured way in a Gaia location. On this page you learn about collections:
* TOC
{:toc}
{% include note.html content="Collections is a preview release. The purpose of this release is to allow developers to try out new collections functionality. The Blockstack team is interested in feedback on this release. Please feel free to report issues or request enhancements with collections on the <a href='https://github.com/blockstack/blockstack-collections/issues/new' target='_blank'>blockstack/blockstack-collections</a> repository. If you encounter problems with <code>blockstack.js</code> you can <a href='https://github.com/blockstack/blockstack.js/issues/new' target='_blank'>file issues or request enhancements on its repo</a>." %}
## Try the Contact Manager demo app
Before adding collections to your DApp, you can try it for yourself using the Contact Manager demo application. Blockstack Contacts is a simple contacts manager that allows users to add and manage their contacts. The data stored by this app can be used in another app that receives the contacts collection permissions.
The tutorial relies on the `npm` dependency manager. Before you begin, verify
you have installed `npm` using the `which` command to verify.
```bash
$ which npm
/usr/local/bin/npm
```
If you have `npm` installed, do the following to run the Contact Manager demo app:
1. If you have a local Blockstack installed, <a href="{{"/browser/local_browser.html" | prepend:site.baseurl}}" >uninstall it</a>.
2. Download and install the <a href="https://github.com/blockstack/blockstack-browser/releases/tag/collections-alpha.1" target="_blank">Collections Alpha Build</a> of the Blockstack Browser client for your OS.
3. Launch the alpha build of the local Blockstack Browser client.
{% include warning.html content="This alpha build interacts with a version of the Gaia Storage hub that supports collections. You cannot use an existing ID to test with, instead, you need to <strong>create a new, test ID using the alpha build</strong>. Additionally, <strong>you must create a custom Gaia hub during the Contact Manager onboarding</strong>. For this reason, wait to create a new ID." %}
4. Go to the local Blockstack Browser and make sure you see this:
![](images/confirm-local.png)
Do not create an ID yet.
5. In your Internet browser, visit the <a href="https://github.com/yknl/blockstack-contacts" target="_blank">https://github.com/yknl/blockstack-contacts</a> repository.
6. Download or clone the repository code to you local workstation.
7. In your workstation terminal, change directory where you downloaded the demo code.
8. Install the dependencies using `npm`.
```bash
npm install
```
9. Start the application running.
```bash
npm run start
```
The system starts the application and launches it in your browser at 127.0.0.1:3000
10. Choose **Sign In with Blockstack**.
This system displays this pop-up
![](images/contacts-manager.png)
11. Use the local browser by choosing **Open Blockstack.app**.
12. Choose **Create new ID** from the pop up.
The onboarding should prompt you to store your data with the `https://develop-hub.blockstack.org` provider.
13. Choose **Yes, use the recommended provider** and complete the creation of your test ID.
The system should return you to the Contact Manager demo application.
Try adding a contact using the Contact Manager. When you have successfully created a contact, the Contact Manager displays that contact on the list. Here you can see that Alfred Newman was entered as a contact.
![](images/added-contact.png)
## How to add collections to your DApp
In this section, you learn how to add collection functionality to an existing application. Before beginning, make sure your application is using Blockstack auth and is storing data with Gaia. To start using collections in your Blockstack app, do the following:
1. Change to the root directory of your app project.
2. Install the preview branch of the `blockstack.js`.
```
npm install blockstack@20.0.0-alpha.3
```
3. Add the `blockstack-collection-schemas` package to your app.
```
npm install blockstack-collections@0.1.7
```
4. Edit your code to import the `Contact` collection type.
```
import { Contact } from `blockstack-collections`
```
5. Customize your sign in request to include the contacts collection scope `Contact.scope`.
This will grant your app permission to read and write to the user’s contacts collection.
```javascript
import { UserSession, AppConfig, makeAuthRequest } from 'blockstack'
import { Contact } from 'blockstack-collection-schemas'
const scopes = ['store_write', 'publish_data', Contact.scope]
const appConfig = new AppConfig(scopes)
const userSession = new UserSession({appConfig: appConfig})
const authRequest = makeAuthRequest(undefined, undefined, undefined, scopes, undefined, undefined, {
solicitGaiaHubUrl: true,
recommendedGaiaHubUrl: 'https://develop-hub.blockstack.org'
})
userSession.redirectToSignInWithAuthRequest(authRequest)
```
{% include note.html content="This example enables the custom Gaia hub selection prompt to point at the pre-release hub that has collections features enabled." %}
## Collection storage operations
Collection storage has been designed around an ORM-like interface. What this means is that you’ll be working with typed objects instead of the `getFile`, `putFile` functions provided by blockstack.js.
### Creating and saving a collection object
```javascript
const newContact = {
lastName: 'Stackerson',
firstName: 'Blocky',
blockstackID: 'Blockstacker.id',
email: 'blockstacker@blockstack.org',
website: 'blockstack.org',
telephone: '123123123'
}
var contact = new Contact(newContact)
contact.save().then((contactID) => {
// contact saved successfully
})
```
### Reading a collection object
```javascript
let contactID = 'Blocky Stackerson'
Contact.get(contactID).then((contact) => {
// Do something with the contact object
console.log('Hello ${contact.firstName}')
})
```
### Listing collection objects
```javascript
let contacts = []
Contact.list((contactID) => {
// This callback is invoked for each contact identifier
// To get the actual object you'll need to use Contact.get
// Or you can add the IDs to an array for display
contacts.push(contactID)
// Return true to continue iterating, return false to stop
return true
})
```
### Deleting collection objects
```javascript
var contact = new Contact(newContact)
contact.delete().then(() => {

Loading…
Cancel
Save