Crystal Javascript SDK
This library provides access to Crystal, the world's largest and most accurate personality database!
FAQ
Want to use our raw API?
Find the docs here: https://developers.crystalknows.com/
Want to learn more about us?
Visit our website: https://www.crystalknows.com/
Need an Organization Access Token?
Get in touch with us at hello@crystalknows.com
Usage
Here's how to install it:
$ npm install --save crystal_sdk
Alternatively, you can embed it in a page:
Here's how you use it:
Synchronous Flow (Recommended)
Profile
const CrystalSDK = // Set your Organization Access TokenCrystalSDKkey = "OrgApiKey" // Fetch a profileCrystalSDKProfile
Email Samples
CrystalSDKEmailSampleall request_id: '4969f4c3-6d5e-42e1-bf73-342fe8c8a3f1'
Asynchronous Flow (For bulk analysis)
When requesting large amounts of profiles, or when wanting to have more fine-grained control over performance, we recommend using our asynchronous flow. It allows us to process your requests in parallel and get the information back to you more quickly. There are a couple options for using this capability.
Option 1: Background Processing (Large Lists + Passive Enrichment)
Sometimes, it isn't important to have the profile information immediately. Especially when dealing with larger jobs or passive data enrichment. In that case, we allow you to save the Request ID and pull information from the request at a later time via this ID.
// This example uses bluebird promisesconst Promise = const CrystalSDK = // Set your Organization Access TokenCrystalSDKkey = "OrgToken" // Send the request to Crystalconst query = first_name: "Drew" ... // Pull out the Profile Request ID (string)CrystalSDKProfileRequest // Later, pull up the Request ID and pull information about itconst savedReq = profileRequestID savedReq
We try and store your request for a few days after the request has been started. Your Request ID should work when you try to pull information from it for at least that period of time!
Option 2: Polling (Small Lists + Realtime Enrichment)
The option we use internally in the SDK, is to poll for request information periodically until a set timeout has been reached:
// This example uses bluebird promisesconst Promise = const CrystalSDK = // Decided on retry limit and time between pollsconst TIME_LIMIT = 30const MAX_POLLS = 10 // Set your Organization Access TokenCrystalSDKkey = "OrgToken" // Prepare the 'sleep' logicconst sleep = { return ;} // Prepare the polling logiclet pollsLeft = MAX_POLLSconst poll = { if!pollsLeft || pollsLeft <= 0 return Promise pollsLeft -= 1 return searchReq } // Start the requestconst query = first_name: "Drew" ... const searchPromise = CrystalSDKProfileRequest // Wait for the response or a timeoutsearchPromise
Polling can be extended to poll for multiple profiles. It gives the efficiency of our parallel processing, while writing code that behaves synchronously.
This option is great if you want information as fast as possible while keeping open network connections and code complexity to a minimum. It is especially useful if you are requesting multiple profiles and can process the profiles one at a time, as each individual profile comes in (as opposed to waiting for all of them to come in before processing anything).
Contributing
-
Clone the repository:
git clone git@github.com:crystal-project-inc/js_sdk.git
-
Run the tests:
npm test
-
Make a code change
-
Check that the tests still pass
-
Make a pull request!
We will review the Pull Request to make sure that it does not break the external specification of the gem and that it fits with the overall mission of the SDK!
We also encourage people to build further libraries that utilize our SDK and extend the use of the Connect API!