bitloops
NodeJS library for the Bitloops
Usage
Installing
Using npm:
$ npm install bitloops
Using yarn:
$ yarn add bitloops
TypeScript Frontend usage Example
import Bitloops, { AuthTypes, BitloopsUser, getAuth } from 'bitloops';
// You will get this from your Console in your Workflow information
const bitloopsConfig = {
apiKey: "kgyst344ktst43kyygk4tkt4s",
server: "bitloops.net",
environmentId: "3c42a5ef-fe21-4b50-8128-8596ea47da93",
workspaceId: "4f7a0fc5-fe2f-450a-b246-11a0873e91f0",
messagingSenderId: "742387243782",
auth: {
authenticationType: AuthTypes.User,
providerId: 'myProviderId', // You create this in the Bitloops Console
clientId: 'myWebAppId', // You create this in the Bitloops Console
}
}
const bitloops = Bitloops.initialize(bitloopsConfig);
bitloops.auth.authenticateWithUsername('username', 'email', 'password');
bitloops.auth.authenticateWithEmail('email', 'password');
bitloops.auth.authenticateWithEmailLink('email');
bitloops.auth.authenticateWithEmailLinkVerification('link');
bitloops.auth.forgotPassword('email', 'username');
bitloops.auth.forgotPassword('email');
bitloops.auth.forgotPasswordLink('link');
bitloops.auth.forgotPasswordLink('link', 'new-password');
bitloops.auth.authenticateWithGoogle();
bitloops.auth.registerWithGoogle();
bitloops.auth.addGoogle();
bitloops.auth.authenticateWithGitHub();
bitloops.auth.registerWithGitHub();
bitloops.auth.addGitHub();
bitloops.auth.authenticateWithTwitter();
bitloops.auth.registerWithTwitter();
bitloops.auth.addTwitter();
bitloops.auth.sendVerificationCode(phone);
bitloops.auth.verifyPhoneCode(phone, code);
bitloops.auth.getUser();
bitloops.auth.clear();
bitloops.auth.onAuthStateChanged((user: BitloopsUser) => {
if (user) {
// Do stuff when authenticated
} else {
// Do stuff if authentication is cleared
}
});
...
const userInfo = await bitloops.request('db7a654a-1e2c-4f9c-b2d0-8ff2e2d6cbfe', '70e3084f-9056-4905-ac45-a5b65c926b1b');
const productInfo = await bitloops.request('64f264ad-76b1-4ba1-975c-c7b9795e55ce', '70e3084f-9056-4905-ac45-a5b65c926b1b', { productId: '7829' });
bitloops.publish('page-visited-event', { page: 'landing-page'});
PRO TIP: The second argument passed in the product.getProductInfo request and in the page-visited-event publish message containing the data of the request/publish message is using a shortcut notation which you can use if the only arguments other than the requestId or the messageId are the payload parameters. The full form is the following:
bitloops.publish('page-visited-event', { payload: { page: 'landing-page' } });
The above is equivalent to:
bitloops.p('page-visited-event', { page: 'landing-page' });
This means that if you need to pass more settings to the request / publish message then you need to explicitly define the payload argument.
Testing Example
To ask your workflows to return mocked values based on your test scenarios you can pass the testScenarioId along with your request.
const productInfo = await bitloops.request('product.getProductInfo', {
payload: { productId: '7829' },
testScenarioId: 'Test-Scenario-1',
});
Subscriptions
const callback = (data: any) => {
console.log('Received', data);
};
bitloops.subscribe('ride-requested', callback);
Questions?
Please post your questions on Stack Overflow making sure you use the Bitloops tag and someone from the Bitloops team or the community will make sure to help you.
Alternatively feel free to submit an Issue on GitHub.