puresdk
v2.9.9
Published
SDK for PureProfile's Business Apps Development
Downloads
371
Readme
Purpose
The purpose of this library is to aim developers create applications for the PureProfile Business Platform. The library provides:
- authentication / authorization layer
- navigation through apps and accounts
- other help tools and features such as a notifications' mechanism are included
Distribution / Installation
The library is available through npm, bower and cdn.
versions x.x.x-alpha.x are not stable and are used only for development. For production purposes please always use "*" (for latest), x.x.x, >x.x.x, ^x.x.x etc semantic version. For development, in order to always have the latest version (either alpha or stable) please use ">x.y.z-alpha" semantic version. The npm repository is "puresdk". If you are working with npm you just need to require / import the library into your code. If you're loading the library in a script tag from CDN the library is exposed to window.PURESDK namespace.
The CDN version of the library is available on the urls:
Latest version:
http://purecdn.pureprofile.com/ppba.latest.minified.js
Specific version minified:
http://purecdn.pureprofile.com/ppba.<= version number >.minified.js
Specific version not-minified:
http://purecdn.pureprofile.com/ppba.<= version number >.js
Example: http://purecdn.pureprofile.com/ppba.2.1.14.minified.js http://purecdn.pureprofile.com/ppba.2.1.14.js
Warning:
CDN versions are available only from version 2.3.11 and up
Features
Initialize the library
First thing you should do is to initialize the library. This step is mandatory when using the library. In order to initialize the library use the "init" function exposed by it.
Commonjs version example:
CDN version example:
As noticed, init method takes one argument of type object which holds the initial configuration you want to pass to it. The supported params / keys of the configuration object are:
Authenticate / authorize the user
Second step (which is also absolutely mandatory) is to authenticate and authorize the current user. The library will automatically check if the user is logged in and also if the logged in user has access to the application. The flow goes as follows:
Commonjs version example:
CDN version example:
Mention the two ways of authentication provided by the library. You can either use the authenticatePromise method which returns a promise or the authenticate method which takes as parameter a success callback. Failure should not concern you as in such case the library automatically redirects the user to the login page.
getUserData
This function returns the full data of the user in an object.
Alert message boxes
The library provides a method for displaying message boxes on top of the page. The supported types are:
In order to show a message box just use the "setInfo" method exposed by the sdk. Here are a couple of examples:
Cloudinary image picker
A Cloudinary image picker is included out of the box. All images used among the various apps of an account are stored on a Cloudinary repository and can be reused at any time by either the same or any other app. In order to browse and pick an already existing image from Cloudinary you should use the openCloudinaryPicker method exposed by puresdk. This method will pop up an image picker modal allowing the user to browse, search and pick the image they want. The method accepts just one argument of type object. For now the only thing to set is the success callback function that will be executed once the user picks an image. Here is an example of how to use the Cloudinary image picker:
Loader
A loader is included on the sdk's top bar. It's positioned right next to the apps button and can be shown and hidden at any time. The methods that show/hide the loader are:
goToLoginPage
This method redirects the browser window to the login page. The method should be used in cases a 401 error code comes back from the backend (meaning the user is not logged in).
Development mode
Only for development reasons, in order to have puresdk running on any url (including localhost or any other) init method of puresdk supports the following configuration options:
the devKeys (key & secret) are unique for each organisation and should be acquired directly from the PureProfile Development Team.