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.
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.
Before using the parse Lib, we recommend for set .env file. you can copy .env file example from the right panel
/** * 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 */
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
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.
// 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
});
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.
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 |
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
})
}
}
}
{
"status": true,
"output": {
"objectId": "rT2tYub1",
"createdAt": ...
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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 |
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
})
}
}
}
{
"status": true,
"output": {
"objectId": "rT2tYub1",
"createdAt": ...
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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 |
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
})
}
}
}
{
"status": true,
"output": {
"objectId": "rT2tYub1",
"createdAt": ...
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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 |
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
})
}
}
}
{
"status": true,
"output": "deleted"
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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)
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
})
}
}
}
{
"status": true,
"output": [
{
"success": {
"createdAt": "2012-06-15T16:59:11.276Z",
"objectId": "YAfSAWwXbL"
}
}
]
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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:
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 |
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
})
}
}
}
{
"status": true,
"output":[
{
"objectId": "rT2tYub1",
"createdAt": ...
},
{
"objectId": "rT2tYub1",
"createdAt": ...
}
]
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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 |
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
})
}
}
}
{
"status": true,
"output":[
{
"objectId": "rT2tYub1",
"createdAt": ...
},
{
"objectId": "rT2tYub1",
"createdAt": ...
}
]
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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 |
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
})
}
}
}
{
"status": true,
"output": 10
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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:
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 |
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
})
}
}
}
{
"status": true,
"output": {
"objectId":"nr7hAYS43a",
"createdAt":"2018-11-08T13:08:42.914Z",
"sessionToken":"r:35c2ae1c1def6c38a469e41ce671cb7e"
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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)
import { ParseSignIn } from '@aacassandra/parse-lib'
export default {
methods:{
onSignin: () => {
ParseSignIn(your_username, your_password)
.then(response => {
//handle success
})
.catch(error => {
//handle error
})
}
}
}
{
"status": true,
"output": {
"objectId":"AHRLeYvh0d",
"username":"newUserName",
"createdAt":"2018-11-08T13:50:56.843Z",
"updatedAt":"2018-11-08T13:50:56.843Z",
"sessionToken":"r:8d975a0f207fab1211752da3be0a3c81"
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
(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
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 |
import { ParseVerifyingEmail } from '@aacassandra/parse-lib'
export default {
methods:{
onVerivyEmail: (email) => {
ParseVerifyingEmail(email)
.then(response => {
//handle success
})
.catch(error => {
//handle error
})
}
}
}
{
"status": true,
"output": 'Sended'
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
(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 |
import { ParseResettingPassword } from '@aacassandra/parse-lib'
export default {
methods:{
onReqResetPassword: (email) => {
ParseResettingPassword(email)
.then(response => {
//handle success
})
.catch(error => {
//handle error
})
}
}
}
{
"status": true,
"output": 'Sended'
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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)
import { ParseValidateSession } from '@aacassandra/parse-lib'
export default {
methods:{
onValidateSession: (sessionToken) => {
ParseValidateSession(sessionToken)
.then(response => {
//handle success
})
.catch(error => {
//handle error
})
}
}
}
{
"status": true,
"output": {
"objectId": "",
"createdAt": ...
}
}
{
"status": false,
"output": {
"code": 209,
"message": "invalid session token"
}
}
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 |
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
})
}
}
}
{
"status": true,
"output": {
"updatedAt": "2011-08-21T18:02:52.248Z"
}
}
{
"status": false,
"output": {
"code": "",
"message": ""
}
}
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 |
import { ParseRetrieveUser } from '@aacassandra/parse-lib'
export default {
methods:{
onRetrieveUser: (objectId) => {
ParseRetrieveUser(objectId)
.then(response => {
//handle success
})
.catch(error => {
//handle error
})
}
}
}
{
"status": true,
"output": {
"username": "jhon_doe",
"createdAt": "2011-08-21T18:02:52.248Z"
}
}
{
"status": false,
"output": {
"code": "",
"message": ""
}
}
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 |
import { ParseRetrieveUsers } from '@aacassandra/parse-lib'
export default {
methods:{
onRetrieveUsers: () => {
ParseRetrieveUsers()
.then(response => {
//handle success
})
.catch(error => {
//handle error
})
}
}
}
{
"status": true,
"output": [
{
"username": "jhon_doe",
"createdAt": "2011-08-21T18:02:52.248Z"
},
{
"username": "jhon_doe",
"createdAt": "2011-08-21T18:02:52.248Z"
}
]
}
{
"status": false,
"output": {
"code": "",
"message": ""
}
}
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
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
})
}
}
}
{
"status": true,
"output": "deleted"
}
{
"status": false,
"output": {
"code": "",
"message": ""
}
}
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.
User
, Session
, and Role
classes on Parse. Restricted sessions also cannot read unrestricted sessions.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).
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 |
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
})
}
}
}
{
"status": true,
"output": {
"createdAt": "2015-03-25T18:21:52.883Z",
"createdWith": {
"action": "create"
},
"objectId": "pla1TY9co3",
"restricted": true,
"sessionToken": "r:aVrtljyb7E8xKo9256gfvp4n2"
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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 |
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
})
}
}
}
{
"status": true,
"output": {
"objectId": "rT2tYub1",
"createdAt": ...
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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
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
})
}
}
}
{
"status": true,
"output": {
"objectId": "rT2tYub1",
"createdAt": ...
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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
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
})
}
}
}
{
"status": true,
"output": [
{
"objectId": "",
"createdAt": ""
},
{
"objectId": "",
"createdAt": ""
}
]
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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
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
})
}
}
}
{
"status": true,
"output": "deleted"
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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.
relation
to the set of users that will inherit permissions granted to the containing role.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 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 |
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
})
}
}
}
{
"status": true,
"output": {
"objectId": "rT2tYub1",
"createdAt": ...
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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 |
import { ParseRetriveRole } from '@aacassandra/parse-lib'
export default {
methods:{
onRetrievingRole: (roleName) => {
ParseRetriveRole(roleName)
.then(response => {
//handle success
})
.catch(error => {
//handle error
})
}
}
}
{
"status": true,
"output": {
"objectId": "rT2tYub1",
"createdAt": ...
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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 |
import { ParseUpdateRole } from '@aacassandra/parse-lib'
export default {
methods:{
onUpdatingRole: (roleName) => {
ParseUpdateRole(roleName, data)
.then(response => {
//handle success
})
.catch(error => {
//handle error
})
}
}
}
{
"status": true,
"output": {
"objectId": "rT2tYub1",
"createdAt": ...
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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
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
})
}
}
}
{
"status": true,
"output": "deleted"
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
If you want to uploading or deleting file, you can following like a right panel.
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 |
import { ParseUploadFile } from '@aacassandra/parse-lib'
export default {
methods:{
onUploadingFile: (file) => {
ParseUploadFile(file)
.then(response => {
//handle success
})
.catch(error => {
//handle error
})
}
}
}
{
"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"
}
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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
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
})
}
}
}
{
"status": true,
"output": "deleted"
}
{
"status": false,
"output": {
"code": "",
"message" : ""
}
}
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.
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;
}
}
}
}
}
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.
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);
});
});
});
So far we have tried to make it easier for you, where until now, there are several functions available as follows:
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.
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
})
}
}
}
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:
functionName(
...,
options:{
...
}
){
//
}
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.
const options = {
include: ['user', 'address.area']
}
functionName(...,options){
//
}
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.
const options = {
relation: ['user|born,area.adress','roles']
}
functionName(...,options){
//
}
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
.
Read more about where clause
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,...] |
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],
]
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:
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,
}
]
}
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 |
const ACL = {
acl:{
default: {
read: true
},
role:admin: {
read: true,
write: true
},
role:user: {
read: true,
write: false
},
role:guest: {
read: true
},
user:eXrT3T1
}
}