Parse Lib

Welcome to Parse Lib! This is our API documentation. This documentation is generated from normal Markdown files using docbox, so it can use Markdown syntax, like bold, emphasis, strikethrough, code, and more. Thankyou docbox.

Thanks in advance to the Parse community, which makes it easy for us open source developers.

Parse Lib is a tool that will facilitate your project to access Parse Server, especially with the javascript / nodejs language. Parse Lib uses a base of REST API with a size of more than 68kb, so that it will not aggravate the performance of your application.

Getting Started

Because the Parse Lib using base with RESTful APIs from Parse. The Parse Lib documentation is not much different in how it is used with the official REST API from Parse. With Parse Lib we make it easier to do broader things. Please find out for yourself how to install on frameworks such as vue, angular and react js.

Enviroment

Before using the parse Lib, we recommend for set .env file. you can copy .env file example from the right panel

Example .env file

/**
* VUE_APP_NAME=Ads Tracker
* VUE_APP_VERSION=2.3.0
* VUE_APP_COMPANY_NAME=PT. Eyro Digital Teknologi
* VUE_APP_COMPANY_DOMAIN=https://cubeacon.com/
* VUE_APP_MODE=production
* VUE_APP_LOGGING=true
* VUE_APP_SESSION_VALIDATION=true
* VUE_APP_PROTOCOL=https
* VUE_APP_HOST=ads-tracker.back4app.io
* VUE_APP_PORT=443
* VUE_APP_SOCKET=wss
* VUE_APP_SURL=none
* VUE_APP_PARSE_ID=RWLjJiQLJoqcNE5pLnPuASASOFcPbET3ogaQtFpN
* VUE_APP_PARSE_JS_KEY=xk0RKSVoNQrvaEBIS3fjIqw8TYpKOnxh2H9lfzTr
* VUE_APP_PARSE_CLIENT_KEY=KB5Bzm0QqCYNd9DfreagZHgas9cQS9cAQDvNq2Ab
* VUE_APP_PARSE_REST_KEY=tsBx9UweIEOohal4LQ7iQL9P5bp4OESTEKqZSIHD
* VUE_APP_PARSE_MASTER_KEY=EOk5PqeHPEqo5bZ1g15UnONquHTLLeCZzwYRFrIg
* VUE_APP_PARSE_REVOCABLE_SESSION=1
* VUE_APP_PARSE_HEADER_ID=X-Parse-Application-Id
* VUE_APP_PARSE_HEADER_CLIENT_KEY=X-Parse-Client-Key
* VUE_APP_PARSE_HEADER_REST_KEY=X-Parse-REST-API-Key
* VUE_APP_PARSE_HEADER_MASTER_KEY=X-Parse-Master-Key
* VUE_APP_PARSE_HEADER_REVOCABLE_SESSION=X-Parse-Revocable-Session
* VUE_APP_PARSE_HEADER_SESSION_TOKEN=X-Parse-Session-Token
*/

Installing Parse Lib

No difference installing methods on spesifi framework or others nodejs project, you can installing this library like a below

npm i -save @aacassandra/parse-lib

Initializing Parse Lib

After installing the Parse Lib, you have to initialize the Lib using your App keys on your main.js file. You can copy from the right panel code snippets.

Example initializing

// In the main.js file on src directory
import { ParseConfig } from '@aacassandra/parse-lib';

ParseConfig({
  mode: process.env.VUE_APP_MODE,
  protocol: process.env.VUE_APP_PROTOCOL,
  host: process.env.VUE_APP_HOST,
  port: process.env.VUE_APP_PORT,
  socket: process.env.VUE_APP_SOCKET,
  surl: process.env.VUE_APP_SURL,
  appId: process.env.VUE_APP_PARSE_ID,
  clientKey: process.env.VUE_APP_PARSE_CLIENT_KEY,
  resKey: process.env.VUE_APP_PARSE_REST_KEY,
  masterKey: process.env.VUE_APP_PARSE_MASTER_KEY,
  revocableSession: process.env.VUE_APP_PARSE_REVOCABLE_SESSION,
  headerAppId: process.env.VUE_APP_PARSE_HEADER_ID,
  headerClientKey: process.env.VUE_APP_PARSE_HEADER_CLIENT_KEY,
  headerResKey: process.env.VUE_APP_PARSE_HEADER_REST_KEY,
  headerMasterKey: process.env.VUE_APP_PARSE_HEADER_MASTER_KEY,
  headerRevocableSession: process.env.VUE_APP_PARSE_HEADER_REVOCABLE_SESSION,
  headerSessionToken: process.env.VUE_APP_PARSE_HEADER_SESSION_TOKEN
});

Objects Intro

Performing CRUD (create, read, update and delete) operations through Parse Lib - is really simple and can be done using the Objects API. Each object consists of a set of key-value pairs that are transacted through the API as a JSON document.

Storing data through the Parse REST API is built around a JSON encoding of the object’s data. This data is schemaless, which means that you don’t need to specify ahead of time what keys exist on each object. You simply set whatever key-value pairs you want, and the backend will store it.

Creating Object

You must include the className and you can include as many key-value pairs as you want. This task can be easily accomplished just by calling the appropriated method like below.

Function

ParseCreateObject(className, data, options)

Options

Property Type Value Default
include Array nested column was supported: ['school', 'users.born'] null
relation Array nested column was unsupported: ['school', 'users']. Read more about relation. null
masterKey boolean true / false false

Example Code

import { ParseCreateObject } from '@aacassandra/parse-lib'

export default {
    methods:{
        onCreate: () => {
            const data = [
                ['string', 'name', 'alan'],
                ['number', 'age', 18],
                ['boolean', 'paid', true],
                ['pointer', 'area', 'rT2tYub1', 'Area']
            ];

            //optional
            const options = {
                include:['age', 'skills.years']
            }

            ParseCreateObject('Players', data, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "objectId": "rT2tYub1",
        "createdAt": ...
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Retrieving Object

To retrieve an object, the className and objectId must be include. Please check how to do it in the right panel of this documentation.

Function

ParseRetrieveObject(className, objectId, options)

Options

Property Type Value Default
where Array Read more about where clause null
include Array nested column was supported: ['school', 'users.born'] null
relation Array nested column was unsupported: ['school', 'users']. Read more about relation. null
masterKey boolean true / false false

Example Code

import { ParseRetrieveObject } from '@aacassandra/parse-lib'

export default {
    methods:{
        onRetrieve: (objectId) => {
            //optional
            const options = {
                include: ['age', 'skills.years']
            }

            ParseRetrieveObject('Players', objectId, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "objectId": "rT2tYub1",
        "createdAt": ...
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Updating Object

To update data on an object that already exists. Any keys you don’t specify will remain unchanged, so you can update just a subset of the object’s data. This task can be easily accomplished just by calling the appropriated method of your preferred Parse Lib. Please check how to do it in the right panel of this documentation.

Function

ParseUpdateObject(className, objectId, data, options)

Options

Property Type Value Default
include Array nested column was supported: ['school', 'users.born'] null
relation Array nested column was unsupported: ['school', 'users']. Read more about relation. null
masterKey boolean true / false false

Example Code

import { ParseUpdateObject } from '@aacassandra/parse-lib'

export default {
    methods:{
        onUpdate: (objectId) => {
            const data = [
                ['string', 'name', 'alan'],
                ['number', 'age', 18],
                ['boolean', 'paid', true],
                ['pointer', 'area', 'rT2tYub1', 'Area']
            ]; 
 
            //optional
            const options = {
                include:['age', 'skills.years']
            }

            ParseUpdateObject('Players', objectId, data, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "objectId": "rT2tYub1",
        "createdAt": ...
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Deleting Object

To destroying an object send, the className and objectId must be include. This task can be easily accomplished just by calling the appropriated method of like below. Please check how to do it in the right panel of this documentation.

Function

ParseDeleteObject(className, objectId, options)

Options

Property Type Value Default
masterKey boolean true / false false

Example Code

import { ParseDeleteObject } from '@aacassandra/parse-lib'

export default {
    methods:{
        onDelete: (objectId) => {
            //optional
            const options = {
                masterKey: true //default: false
            }

            ParseDeleteObject('Players', objectId, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": "deleted"
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Batch Operation

To reduce the amount of time spent on network round trips, you can create, update, or delete up to 50 objects in one call, using the batch endpoint.

Each command in a batch has method, path, and body parameters that specify the HTTP command that would normally be used for that command. The commands are run in the order they are given. For example, please check how to do it in the right panel of this documentation.

Funtion

ParseBatch(data)

Example Code

import { ParseBatch } from '@aacassandra/parse-lib'

export default {
    methods:{
        onBatchOps: (objectId) => {
            const data = [
                {
                    method: 'POST',
                    data:[
                        ['string', 'name', 'jhon_doe'],
                        ['number', 'age', 26]
                    ],
                    className: '_User'
                },
                {
                    method: 'PUT',
                    data:[
                        ['string', 'name', 'jhon_doe'],
                        ['number', 'age', 26]
                    ],
                    className: '_User',
                    objectId: 'xWe3RwXY'
                },
                {
                    method: 'DELETE',
                    className: '_User',
                    objectId: 'xWe3RwXY'
                }
            ]

            ParseBatch(data)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": [
        {
            "success": {
                "createdAt": "2012-06-15T16:59:11.276Z",
                "objectId": "YAfSAWwXbL"
            }
        }
    ]
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Queries Intro

Sometimes you will find that the get method from the Parse Object is not enough to retrieve the exact data that you want. In this section, we will explore the Query capabilities, which allows us to fetch an array of objects, apply different constraints to filter our query results, or even get unique results given a specific field.

You can retrieve multiple objects at once by sending a GET request to the class URL. Without any URL parameters, this simply lists objects in the class:

Basic Queries

You can retrieve multiple objects at once by sending only className and options for optional. Please check how to do it in the right panel of this documentation.

Function

ParseRetrieveObjects(className, options)

Options

Property Type Value Default
where Array Read more about where clause null
include Array nested column was supported: ['school', 'users.born'] null
relation Array nested column was unsupported: ['school', 'users']. Read more about relation. null
masterKey boolean true / false false

Example Code

import { ParseRetrieveObjects } from '@aacassandra/parse-lib'

export default {
    methods:{
        onRetrieveObjects: () => {
            //optional
            const options = {
                where:[{
                    column: 'age',
                    greaterThan: 22
                }],
                include:['age', 'skills.years']
            }

            ParseRetrieveObjects('Players', options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output":[
        {
            "objectId": "rT2tYub1",
            "createdAt": ...
        },
        {
            "objectId": "rT2tYub1",
            "createdAt": ...
        }
    ]
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Relational Queries

Query supports creating constraints that evaluates if a field matches a particular Parse Object. It allows you to fetch only the objects that contains a specific relation with another object.

There are cases when you need to evaluate some related object fields in order to build a query with refined results.

That can be done by creating a inner query whose constraints will be applied only on the related field you want to evaluate, those are known as relational constraints and are also demonstrated in this section.

Using A

Function

ParseRetrieveRelation(className, objectId, columnName, options)

Options

Property Type Value Default
include Array nested column was supported: ['school', 'users.born'] null
masterKey boolean true / false false

Example Code

import { ParseRetrieveRelation } from '@aacassandra/parse-lib'

export default {
    methods:{
        onRetrievesRelation: (objectId) => {
            const column = {
                name: "", 
                className: "" //relational from class ... ?
            }

            //optional
            const options = {
                include:['age', 'skills.years'], //className
                masterKey: true //default: false
            }

            ParseRetrieveRelation('Players', objectId, column, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output":[
        {
            "objectId": "rT2tYub1",
            "createdAt": ...
        },
        {
            "objectId": "rT2tYub1",
            "createdAt": ...
        }
    ]
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Counting Objects

If you do not need to retrieve any data from the objects, but count them, we have it covered.

Function

ParseCountingObjects(className, options)

Options

Property Type Value Default
where Array Read more about where clause null
include Array nested column was supported: ['school', 'users.born'] null
masterKey boolean true / false

Example Code

import { ParseCountingObjects } from '@aacassandra/parse-lib'

export default {
    methods:{
        onCountingObjects: () => {
            //optional
            const options = {
                where: [
                    {
                        column: 'age',
                        equalToPointer: true,
                        className: 'Age',
                        objectId: 'xVT2irB'
                    }
                ],
                include:['age', 'skills.years']
            }

            ParseCountingObjects('Players', options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": 10
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Users Intro

User is a subclass of Object, what meanings that has the same properties and methods as a generic object. The difference is that Parse.User has some special additions specific to user accounts.

As others objects, users have a flexible schema, the differences are that the username and password fields are required and username and email must be unique per user.

For each new custom class that you create in your app's schema (either through API or just sending the data), a new endpoint is generated at the address below through which you can perform your CRUD operations:

Signin Up

Signing up a new user differs from creating a generic object in that the username and password fields are required. The password field is handled differently than the others; it is encrypted with bcrypt when stored in the Parse Cloud.

You can ask Parse to verify user email addresses in your application settings page. With this setting enabled, all new user registrations with an email field will generate an email confirmation at that address. You can check whether the user has verified their email with the emailVerified field. Please check how to do it in the right panel of this documentation.

Function

ParseSignUp(userName, passWord, data, options)

Options

Property Type Value Default
masterKey boolean true / false false

Example Code

import { ParseSignUp } from '@aacassandra/parse-lib'

export default {
    methods:{
        onSignup: () => {
            const data = [
                ['string', 'name', 'alan'],
                ['number', 'age', 18],
                ['boolean', 'paid', true],
                ['pointer', 'area', 'rT2tYub1', 'Area']
            ];

            ParseSignUp(your_username, your_password, data)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": { 
        "objectId":"nr7hAYS43a",
        "createdAt":"2018-11-08T13:08:42.914Z",
        "sessionToken":"r:35c2ae1c1def6c38a469e41ce671cb7e"
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Logging In

After you allow users to sign up, you need to let them log in to their account with a username and password in the future. Please check how to do it in the right panel of this documentation.

Function

ParseSignIn(userName, passWord)

Example Code

import { ParseSignIn } from '@aacassandra/parse-lib'

export default {
    methods:{
        onSignin: () => {
            ParseSignIn(your_username, your_password)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "objectId":"AHRLeYvh0d",
        "username":"newUserName",
        "createdAt":"2018-11-08T13:50:56.843Z",
        "updatedAt":"2018-11-08T13:50:56.843Z",
        "sessionToken":"r:8d975a0f207fab1211752da3be0a3c81"
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Verifying Emails

(Verifying Emails) was comming soon. Enabling email verification in an application’s settings allows the application to reserve part of its experience for users with confirmed email addresses. Email verification adds the emailVerified field to the User object. When a User’s email is set or modified, emailVerified is set to false. Parse then emails the user a link which will set emailVerified to true.

There are three emailVerified states to consider:

  • true - the user confirmed his or her email address by clicking on the link Parse emailed them. Users can never have a true value when the user account is first created.
  • false - at the time the User object was last refreshed, the user had not confirmed his or her email address. If emailVerified is false, consider refreshing the User
  • missing - the User was created when email verification was off or the User does not have an email.

Please check how to do it in the right panel of this documentation.

Function

ParseVerifyingEmail(email, options)

Options

Property Type Value Default
masterKey boolean true / false false

Example Code

import { ParseVerifyingEmail } from '@aacassandra/parse-lib'

export default {
    methods:{
        onVerivyEmail: (email) => {
            ParseVerifyingEmail(email)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": 'Sended'
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Requesting A Password Reset

(Requesting A Password Reset) was comming soon. You can initiate password resets for users who have emails associated with their account. Please check how to do it in the right panel of this documentation.

Function

ParseResettingPassword(email, options)

Options

Property Type Value Default
masterKey boolean true / false false

Example Code

import { ParseResettingPassword } from '@aacassandra/parse-lib'

export default {
    methods:{
        onReqResetPassword: (email) => {
            ParseResettingPassword(email)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": 'Sended'
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Validating Session

With a valid session token, you can checking session expired time with validating session. Please check how to do it in the right panel of this documentation.

Function

ParseValidateSession(sessionToken)

Example Code

import { ParseValidateSession } from '@aacassandra/parse-lib'

export default {
    methods:{
        onValidateSession: (sessionToken) => {
            ParseValidateSession(sessionToken)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "objectId": "",
        "createdAt": ... 
    }
}

Example Session Has Expired

{
    "status": false,
    "output": {
        "code": 209,
        "message": "invalid session token"
    }
}

Updating Users

In normal usage, nobody except the user is allowed to modify their own data. To authenticate themselves. But sometimes for editing the another user like a react native project, you can use masterKey. For recommended, don't use masterKey on client side.

To change the data on a user that already exists, send a PUT request to the user URL. Any keys you don’t specify will remain unchanged, so you can update just a subset of the user’s data. username and password may be changed, but the new username must not already be in use.

Function

ParseUpdateUser(objectId, data, options)

Options

Property Type Value Default
include Array nested column was supported: ['school', 'users.born'] null
relation Array nested column was unsupported: ['school', 'users']. Read more about relation. null
sessionToken String "r:pnktnjyb996sj4p156gjtp4im" null
masterKey boolean true / false false

Example Code

import { ParseUpdateUser } from '@aacassandra/parse-lib'

export default {
    methods:{
        onUpdatingUser: (objectId) => {
            const data = [
                ['string', 'name', 'alan'],
                ['number', 'age', 18],
                ['boolean', 'paid', true],
                ['pointer', 'area', 'rT2tYub1', 'Area']
            ];

            const options = {
                sessionToken: 'r:pnktnjyb996sj4p156gjtp4im'
            }
            
            ParseUpdateUser(objectId, data, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "updatedAt": "2011-08-21T18:02:52.248Z"
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message": ""
    }
}

Retrieve User

You can retrieve single user. you only including an objectId of user. Please check how to do it in the right panel of this documentation.

Function

ParseRetrieveUser(objectId, options)

Options

Property Type Value Default
include Array nested column was supported: ['school', 'users.born'] null
relation Array nested column was unsupported: ['school', 'users']. Read more about relation. null
masterKey boolean true / false false

Example Code

import { ParseRetrieveUser } from '@aacassandra/parse-lib'

export default {
    methods:{
        onRetrieveUser: (objectId) => {
            ParseRetrieveUser(objectId)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "username": "jhon_doe",
        "createdAt": "2011-08-21T18:02:52.248Z"
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message": ""
    }
}

Retrieve Users

You can retrieve multiple user by call like below. For example you can follow in the right panel.

Function

ParseRetrieveUsers(options)

Options

Property Type Value Default
include Array nested column was supported: ['school', 'users.born'] null
relation Array nested column was unsupported: ['school', 'users']. Read more about relation. null
masterKey boolean true / false false

Example Code

import { ParseRetrieveUsers } from '@aacassandra/parse-lib'

export default {
    methods:{
        onRetrieveUsers: () => {
            ParseRetrieveUsers()
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": [
        {
            "username": "jhon_doe",
            "createdAt": "2011-08-21T18:02:52.248Z"
        },
        {
            "username": "jhon_doe",
            "createdAt": "2011-08-21T18:02:52.248Z"
        }
    ]
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message": ""
    }
}

Deleting Users

To delete an user, this task can be easily accomplished just by calling like a bellow. Please check how to do it in the right panel of this documentation.

Function

ParseDeleteUser(objectId, options)

Options

Property Type Value Default
sessionToken String "r:pnktnjyb996sj4p156gjtp4im" null
masterKey boolean true / false false

By using sessionToken, you can only delete the account yourself. If you want to delete another user, you can use with masterKey, but the solution is not recommended in the web app. Make sure your sessionToken is valid with objectId which will be removed.

You can also delete other users in terms of other interests safely through ParseCloud, read more about ParseCloud

Example Code

import { ParseDeleteUser } from '@aacassandra/parse-lib'

export default {
    methods:{
        onDeletingUser: (objectId) => {
            const options = {
                sessionToken: "r:pnktnjyb996sj4p156gjtp4im"
            }
            
            ParseDeleteUser(objectId, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": "deleted"
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message": ""
    }
}

Sessions Intro

Sessions represent an instance of a user logged into a device. Sessions are automatically created when users log in or sign up. They are automatically deleted when users log out. There is one distinct Session object for each user-installation pair; if a user issues a login request from a device they’re already logged into, that user’s previous Session object for that Installation is automatically deleted. Session objects are stored on Parse in the Session class, and you can view them on the Parse Dashboard Data Browser. We provide a set of APIs to manage Session objects in your app.

A Session is a subclass of a Parse Object, so you can query, update, and delete sessions in the same way that you manipulate normal objects on Parse. Because the Parse Cloud automatically creates sessions when you log in or sign up users, you should not manually create Session objects unless you are building a “Parse for IoT” app (e.g. Arduino or Embedded C). Deleting a will log the user out of the device that is currently using this session’s token.

Unlike other Parse objects, the Session class does not have Cloud Code triggers. So you cannot register a beforeSave or afterSave handler for the Session class.

  • sessionToken (readonly): String token for authentication on Parse API requests. In the response of Session queries, only your current Session object will contain a session token.

  • user: (readonly) Pointer to the User object that this session is for.

  • createdWith (readonly): Information about how this session was created (e.g. { "action": "login", "authProvider": "password"}).

    • action could have values: login, signup, create, or upgrade. The create action is when the developer manually creates the session by saving a Session object. The upgrade action is when the user is upgraded to revocable session from a legacy session token.
    • authProvider could have values: password, anonymous, facebook, or twitter.
  • restricted (readonly): Boolean for whether this session is restricted.

    • Restricted sessions do not have write permissions on User, Session, and Role classes on Parse. Restricted sessions also cannot read unrestricted sessions.
    • All sessions that the Parse Cloud automatically creates during user login/signup will be unrestricted. All sessions that the developer manually creates by saving a new Session object from the client (only needed for “Parse for IoT” apps) will be restricted.
  • expiresAt (readonly): Approximate UTC date when this Session object will be automatically deleted. You can configure session expiration settings (either 1-year inactivity expiration or no expiration) in your app’s Parse Dashboard settings page.

  • installationId (can be set only once): String referring to the Installation where the session is logged in from. For the REST API, you can set this by passing the X-Parse-Installation-Id header on login and signup requests. All special fields except installationId can only be set automatically by the Parse Cloud. You can add custom fields onto Session objects, but please keep in mind that any logged-in device (with session token) can read other sessions that belong to the same user (unless you disable Class-Level Permissions, see below).

Creating Session

For mobile apps and websites, you should not create Session objects manually. Instead, you should call GET /parse/login and POST /parse/users (signup), which will automatically generate a Session object in the Parse Cloud. The session token for this automatically-created session will be sent back on the login and signup response. Same for Facebook/Twitter login and signup requests.

In “Parse for IoT” apps (e.g. Arduino or Embedded C), you may want to programmatically create a restricted session that can be transferred to an IoT device. In order to do this, you must first log in normally to obtain an unrestricted session token. Then, you can create a restricted session by providing this unrestricted session token:

Function

ParseCreateSession(sessionToken, data, options)

Options

Property Type Value Default
masterKey boolean true / false false

Example Code

import { ParseCreateSession } from '@aacassandra/parse-lib'

export default {
    methods:{
        onCreatingSession: (sessionToken) => {
            const data = [
                ['string', 'customField', 'value']
            ];

            ParseCreateSession(sessionToken, data)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "createdAt": "2015-03-25T18:21:52.883Z",
        "createdWith": {
            "action": "create"
        },
        "objectId": "pla1TY9co3",
        "restricted": true,
        "sessionToken": "r:aVrtljyb7E8xKo9256gfvp4n2"
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Retrieving Session

If you have the session’s objectId, you fetch the Session object as long as it belongs to the same user as your current session:

Function

ParseRetrieveSession(objectId, options)

Options

Property Type Value Default
masterKey boolean true / false false

Example Code

import { ParseRetrieveSession } from '@aacassandra/parse-lib'

export default {
    methods:{
        onRetrieveSession: (objectId) => {
            //optional
            const options = {
                masterKey: false
            }

            ParseRetrieveSession(objectId, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "objectId": "rT2tYub1",
        "createdAt": ...
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Updating Session

Updating a session is analogous to updating a Parse object.

Function

ParseUpdateSession(objectId, data, options)

Options

Property Type Value Default
sessionToken String "r:pnktnjyb996sj4p156gjtp4im" null
masterKey boolean true / false false

Must be select one from options

Example Code

import { ParseUpdateSession } from '@aacassandra/parse-lib'

export default {
    methods:{
        onUpdatingSession: (objectId) => {
            const data = [
                ['string', 'name', 'alan'],
                ['number', 'age', 18],
                ['boolean', 'paid', true],
                ['pointer', 'area', 'rT2tYub1', 'Area']
            ];

            const options = {
                sessionToken: "r:pnktnjyb996sj4p156gjtp4im"
            }

            ParseUpdateSession(objectId, data, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "objectId": "rT2tYub1",
        "createdAt": ...
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Querying Sessions

Querying for Session objects will only return objects belonging to the same user as your current session (due to the Session ACL). You can also add a where clause to your query, just like normal Parse objects.

Function

ParseRetrieveSessions(options)

Options

Property Type Value Default
sessionToken String "r:pnktnjyb996sj4p156gjtp4im" null
masterKey boolean true / false false

Must be select one from options

Example Code

import { ParseRetrieveSessions } from '@aacassandra/parse-lib'

export default {
    methods:{
        onRetrievingSessions: () => {
            //optional
            const options = {
                sessionToken: "r:pnktnjyb996sj4p156gjtp4im"
            }

            ParseRetrieveSessions(options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": [
        {
            "objectId": "",
            "createdAt": ""
        },
        {
            "objectId": "",
            "createdAt": ""
        }
    ]
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Delete Session

If you want to delete another Session object for your user, and you have its objectId, you can delete it (but not log yourself out) by:

Function

ParseDeleteSession(objectId, options)

Options

Property Type Value Default
sessionToken String "r:pnktnjyb996sj4p156gjtp4im" null
masterKey boolean true / false false

Must be select one from options

Example Code

import { ParseDeleteSession } from '@aacassandra/parse-lib'

export default {
    methods:{
        onDeletingSession: (objectId) => {
            //optional
            const options = {
                sessionToken: "r:pnktnjyb996sj4p156gjtp4im"
            }

            ParseDeleteSession(objectId, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": "deleted"
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Roles Intro

As your app grows in scope and user-base, you may find yourself needing more coarse-grained control over access to pieces of your data than user-linked ACLs can provide. To address this requirement, Parse supports a form of Role-based Access Control. Roles provide a logical way of grouping users with common access privileges to your Parse data. Roles are named objects that contain users and other roles. Any permission granted to a role is implicitly granted to its users as well as to the users of any roles that it contains.

For example, in your application with curated content, you may have a number of users that are considered “Moderators” and can modify and delete content created by other users. You may also have a set of users that are “Administrators” and are allowed all of the same privileges as Moderators, but can also modify the global settings for the application. By adding users to these roles, you can ensure that new users can be made moderators or administrators, without having to manually grant permission to every resource for each user.

We provide a specialized role class to represent these groupings of users for the purposes of assigning permissions. Roles have a few special fields that set them apart from other objects.

  • name: The name for the role. This value is required, and can only be set once as a role is being created. The name must consist of alphanumeric characters, spaces, -, or _. This name will be used to identify the Role without needing its objectId.
  • users: A relation to the set of users that will inherit permissions granted to the containing role.
  • roles: A relation to the set of child roles whose users and roles will inherit permissions granted to the containing role.

Often, in order to keep these roles secure, your mobile apps won’t be directly responsible for managing creation and membership of your roles. Instead, roles may be managed by a separate interface on the web or manually managed by an administrator. Our REST API allows you to manage your roles without requiring a mobile client.

Creating Role

Creating a new role differs from creating a generic object in that the name field is required. Roles must also specify an ACL, which should be as restrictive as possible to avoid allowing the wrong users to modify a role.

Function

ParseCreateRole(roleName, options)

Options

Property Type Value Default
acl Object Read more about ACL or see the example code null
users Array Fill the _User pointer of array like the example code null
roles Array Fill the _Role pointer of array like the example code null
include Array nested column was supported: ['school', 'users.born'] null
masterKey boolean true / false false

Example Code

import { ParseCreateRole } from '@aacassandra/parse-lib'

export default {
    methods:{
        onCreatingRole: (roleName) => {
            //optional
            const options = {
                acl:{
                    default: {
                        read: true
                    },
                    role:admin: {
                        read: true,
                        write: true
                    },
                    user:eXrT3T1
                },
                //relation of users
                users:[
                    {
                        __type:"Pointer",
                        objectId: "...",
                        className: "..."
                    },
                    {
                        __type:"Pointer",
                        objectId: "...",
                        className: "..."
                    }
                ],
                //relation of roles
                roles:[
                    {
                        __type:"Pointer",
                        objectId: "...",
                        className: "..."
                    },
                    {
                        __type:"Pointer",
                        objectId: "...",
                        className: "..."
                    }
                ]
                include:[],
                masterKey: false
            }

            ParseCreateRole(roleName, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "objectId": "rT2tYub1",
        "createdAt": ...
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Retrieving Role

You can also retrieve the contents of a role object by sending a GET request to the URL returned in the location header when it was created. For example, to retrieve the role created above:

Function

ParseRetriveRole(roleName, options)

Options

Property Type Value Default
where Array Read more about where clause null
include Array nested column was supported: ['school', 'users.born'] null
masterKey boolean true / false false

Example Code

import { ParseRetriveRole } from '@aacassandra/parse-lib'

export default {
    methods:{
        onRetrievingRole: (roleName) => {
            ParseRetriveRole(roleName)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "objectId": "rT2tYub1",
        "createdAt": ...
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Updating Role

Updating a role generally works like updating any other object, but the name field on the role cannot be changed. Adding and removing users and roles to the users and roles relations can be accomplished by using the AddRelation and RemoveRelation operators.

Function

ParseUpdateRole(roleName, data, options)

Options

Property Type Value Default
include Array nested column was supported: ['school', 'users.born'] null
masterKey boolean true / false false

Example Code

import { ParseUpdateRole } from '@aacassandra/parse-lib'

export default {
    methods:{
        onUpdatingRole: (roleName) => {
            ParseUpdateRole(roleName, data)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
        "objectId": "rT2tYub1",
        "createdAt": ...
    }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Deleting Role

To delete a role from the Parse Cloud, send a DELETE request to its URL. For example:

Function

ParseDeleteRole(roleName, options)

Options

Property Type Value Default
sessionToken String "r:pnktnjyb996sj4p156gjtp4im" null
masterKey boolean true / false false

Must be select one from options

Example Code

import { ParseDeleteRole } from '@aacassandra/parse-lib'

export default {
    methods:{
        onDeletingRole: (roleName) => {
            const options = {                
                sessionToken: "r:pnktnjyb996sj4p156gjtp4im"
            }

            ParseDeleteRole(roleName, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": "deleted"
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Files Intro

If you want to uploading or deleting file, you can following like a right panel.

Uploading Files

To upload a file to Parse, send a POST request to the files URL, postfixed with the name of the file. The request must contain the Content-Type header associated with the file. Keep in mind that files are limited to 10 megabytes. Here’s a simple example that’ll create a file named hello.txt containing a string:

Function

ParseUploadFile(file, options)

Options

Property Type Value Default
masterKey boolean true / false false

Example Code

import { ParseUploadFile } from '@aacassandra/parse-lib'

export default {
    methods:{
        onUploadingFile: (file) => {
            ParseUploadFile(file)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": {
                "url": "http://files.parsetfss.com/bc9f32df-2957-4bb1-93c9-ec47d9870a05/tfss-db295fb2-8a8b-49f3-aad3-dd911142f64f-hello.txt",
                "name": "db295fb2-8a8b-49f3-aad3-dd911142f64f-hello.txt"
            }
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Deleting Files

Users holding the master key are allowed to delete files using the REST API. To delete a file, send a DELETE request to the files URL, postfixed with the name of the file. Note that the name of the file must be the name in the response of the upload operation, rather than the original filename. Note that the X-Parse-Master-Key must be provided in headers.

Recommended for security reason, we are recommend for you about deleting file, if your project is web client side, please using deleting file feature on the ParseCloud.DeletingFile()

Function

ParseDeleteFile(fileUrl, options)

Options

Property Type Value Default
masterKey boolean true / false false

The masterKey must be define

Example Code

import { ParseDeleteFile } from '@aacassandra/parse-lib'

export default {
    methods:{
        onDeletingFile: (fileUrl) => {
            const options = {              
                masterKey: true
            }

            ParseDeleteFile(fileUrl, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })
        }
    }
}

Example Response

{
    "status": true,
    "output": "deleted"
}

Example Error

{
    "status": false,
    "output": {
        "code": "",
        "message" : ""
    }
}

Live Query Intro

As we see in the LiveQuery protocol Parse documentation. They maintain a WebSocket connection to communicate with the Parse LiveQuery server. When used server side, they use the ws package and in their browser they use window.WebSocket. We think in most cases there is no need to deal with a WebSocket connection directly. Because they developed a simple API to allow you to focus on your own business logic.

Example

import {ParseLiveQuery} from '@aacassandra/parse-lib';

export default {
    methods: {
        onLiveQuery: async () => {
            const ws = await ParseLiveQuery();

            ws.open();
            const subscription = ws.subscribe('StaffReport');
            subscription.on(response => {
                switch (response.on) {
                    case 'create':
                        //handle of creating data
                        console.log(response.object)
                        break;
                    case 'update':
                        //handle of updating data
                        console.log(response.object)
                        break;
                    case 'delete':
                        //handle of deleting data
                        console.log(response.object)
                        break;
                }
            }
        }
    }
}

Cloud Code Intro

Parse Lib also provides a library for Parse Cloud Code. In certain circumstances you might want to use masterKey, with ParseCloud your masterKey will be safe. So far we have tried to facilitate you.

Install

ParseCloud is in a separate library because it is nested in ParseServer. Therefore, you must install this if you want to use ParseCloud from Parse Lib.

In your Parse Server include this library

npm i @aacassandra/parse-cloud-code

Next, and in the main.js file from src diretory, copy this:

var ParseCloud = require("@aacassandra/parse-cloud-code");

Parse.Cloud.define("cloud", async request => {
  return new Promise(resolve => {
    ParseCloud(Parse, request, callback => {
      resolve(callback);
    });
  });
});

If are you using Back4App, you can download this libraries at @aacassandra/parse-cloud-code

Before uploading, please rename index.js file to parseLib.js and uploading all to cloud directory, and paste this into your main.js file

var ParseCloud = require("./parseLib");

Parse.Cloud.define("cloud", async request => {
  return new Promise(resolve => {
    ParseCloud(Parse, request, callback => {
      resolve(callback);
    });
  });
});

Feature

So far we have tried to make it easier for you, where until now, there are several functions available as follows:

  • ParseCloud.UpdateUser
  • ParseCloud.DeleteUser
  • ParseCloud.UpdateObject
  • ParseCloud.DeleteObject
  • ParseCloud.RetrieveObject
  • ParseCloud.RetrievesObject

How To Use It

ParseCloud and Parse Lib parameters are really not much different, we try to make it easier for you to use our library. You can see more examples in the right panel.

Examples

import { ParseCloud } from '@aacassandra/parse-lib'

export default {
    methods: {
        onUpdateUser: (objectId) => {
            const data = [
                ['string', 'name', 'alan'],
                ['number', 'age', 18],
                ['boolean', 'paid', true],
                ['pointer', 'area', 'rT2tYub1', 'Area']
            ];
            
            const options = {
                include: [], 
                relation: [], 
                masterKey: false
            }

            ParseCloud.UpdateUser(objectId, data, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })           
        },
        onDeleteUser: (objectId) => {
            ParseCloud.DeleteUser(objectId)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })  
        },
        onRetrieveObject: (
            className = '',
            objectId = '',
            options = {
                where: [],
                include: [],
                relation: [],
                masterKey: false
            }
        ) => {
            ParseCloud.RetrieveObject(className, objectId, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })  
        },
        onRetrieveObjects: (
            className = '',
            options = {
                where: [],
                include: [],
                relation: [],
                masterKey: false
            }
        ) => {
            ParseCloud.RetrieveObjects(className, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })  
        },
        onUpdateObject: (className, objectId, data, options = {
            include: [],
            relation: [],
            masterKey: false
        }) => {
            ParseCloud.UpdateObject(className, objectId, data, options)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })  
        },
        onDeleteObject: (className, objectId) => {
            ParseCloud.DeleteObject(className, objectId)
            .then(response => {
                //handle success
            })
            .catch(error => {
                //handle error
            })  
        }
    }
}

Option Parameters

Parse Lib make to easy on Parse user, when the user call function with simple options. Like in the right panel.

You need to know about what are the parameter options in the parse lib and its uses. There are several options available for each function available, as below:

Example

functionName(
    ...,
    options:{
        ...
    }
){
    // 
}

include

if you want getting the include data object or queries, you can use this like a below:

Can you see the code like in the right panel, you can using '.' for nested include.

Example

  const options = {
      include: ['user', 'address.area']
  }
  functionName(...,options){
      //
  }

relation

Difference with include. On the relation, you can not use dot '.' notation on relation. But you can set a include data of relation after '|' notation.

Parameter

['relation|pointer', 'relation|pointer', ...]

Can you see the code above, pointer is optional you can set or unset, that's very beauty 💎. Look our example in the right panel.

Example

  const options = {
      relation: ['user|born,area.adress','roles']
  }
  functionName(...,options){
      //
  }

masterKey

For security reason the masterKey we are recommended for you don't used this on the client side, unless you use it like on an IoT device or mobile device. On the masterKey field you only fill the value must true or false. Default value of masterKey is false.

where

Read more about where clause

Data Type

On the Parse Lib we will make to easy for creating or updating file formatting data. So far we have only used values that can be encoded with standard JSON. The Parse mobile client libraries also support dates, geolocations, and relational data. In the REST API, these values are encoded as JSON hashes with the __type field set to indicate their type, so you can read or write these fields if you use the correct encoding. Overall, the following types are allowed for each field in your object:

Type Parameter Example Value
string [type, columnName, value] 'string'
number [type, columnName, value] 88
boolean [type, columnName, value] true or false
array [type, columnName, value] []
object [type, columnName, value] {}
date [type, columnName, value] new Date()
file [type, columnName, value] Files[0]
pointer [type, columnName, value, className] objectId
addRelation [type, columnName, value, className] [objectId,...]
removeRelation [type, columnName, value, className] [objectId,...]

Example Formating

const data = [
    ['string', 'name', 'Jhon Doe'],
    ['number', 'age', 23],
    ['boolean', 'regisred', false],
    ['array', 'scors', [88,76,90]],
    ['object', 'statistic', {goal:23, pinalty: 4}],
    ['date', 'born', new Date()],
    ['file', 'avatar', files[0]],
    ['pointer', 'class', 'eRt1UxOR', className],
    ['addRelation', 'follower', ['eRt1UxOR', 'Re3xtu9P', 'ads2iP9x'], className],
    ['removeRelation', 'follower', ['eRt1UxOR', 'Re3xtu9P', 'ads2iP9x'], className],
]

Where Clause

The values of the where parameter also support comparisons besides exact matching. Instead of an exact value, provide a hash with keys corresponding to the comparisons to do. The where parameter supports these options:

  • equalTo
  • equalToPointer
  • notEqualTo
  • notEqualToPointer
  • containedIn
  • notContainedIn
  • greaterThan
  • greaterThanOrEqualTo
  • lessThan
  • lessThanOrEqualTo

Example Formating

const options = {
    where:[
        {
            column: 'name',
            equalTo: 'jhon_doe'
        },
        {
            column: 'born',
            equalToPointer: true,
            objectId: 'wXy34YpiA',
            className: 'Born'
        },
        {
            column: 'name',
            notEqualTo: 'eric'
        },
        {
            column: 'born',
            notEqualToPointer: true,
            objectId: 'pGy14TxiA',
            className: 'Born'
        },
        {
            column: 'category',
            containedIn: ['Sport', 'Games'],
        },
        {
            column: 'category',
            notContainedIn: ['Sport', 'Games'],
        },
        {
            column: 'category',
            greaterThanOrEqualTo: 65,
        },
        {
            column: 'category',
            greaterThanOrEqualTo: 65,
        },
        {
            column: 'scors',
            lessThan: 60,
        },
        {
            column: 'category',
            lessThanOrEqualTo: 60,
        }
    ]
}

User Security

When you access Parse via the REST API key, access can be restricted by ACL just like in the iOS and Android SDKs. You can still read and modify acls via the REST API, just by accessing the "ACL" key of an object.

The ACL is formatted as a JSON object where the keys are either object ids or the special key "*" to indicate public access permissions. The values of the ACL are “permission objects”, JSON objects whose keys are the permission names and whose values are always true.

For example, if you want the user with id "3KmCvT7Zsb" to have read and write access to an object, plus the object should be publicly readable, that corresponds to an ACL of:

Options

Property Value
default default
role role:roleName
user user:objectId

Example Formating

const ACL = {
    acl:{
        default: {
            read: true
        },
        role:admin: {
            read: true,
            write: true
        },
        role:user: {
            read: true,
            write: false
        },
        role:guest: {
            read: true
        },
        user:eXrT3T1
    }
}
Show examples in:
Parse Lib API Documentation