npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

inbrain-cordova-test

v1.0.1

Published

Inbrain Cordova wrapper

Downloads

7

Readme

inBrainCordova Cordova Plugin

Use this plugin to integrate native inBrain SDKs in your iOS and Android Cordova apps. In addition to Javascript, the plugin also provides a TypeScript type definitions.

Compatibility

The plugin is compatible with Cordova 8+ / cordova-ios 4.5+ / cordova-android 8.0+ / iOS 10+ / Android 5+.

Preparation

Installing plugin

  1. Clone the plugin into a folder beside your Cordova app from https://github.com/inbrainai/inbrainCordova.
  2. Goto your Cordova app's root folder and issue the command

 ionic cordova plugin add ../inbrainCordova

Setting up your ionic project

To use the plugin, import the followings.

import InBrainCordova from "inbrain-cordova";
import * as InBrain from "inbrain-cordova";

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
...

InBrainCordova

InBrainCordova class represents the wrapper of the InBrain SDK for Cordova. We have the following methods

init

Initializes the SDK. Use this method after platform ready.

InBrainCordova.init(
        <<API_CLIENT_ID>>,
        <<API_SECRET>>,
        <<S2S>>, 
        <<USER_ID>>,
        <<SESSION_ID>>,
        <<InitOptions>>
      ): Promise<void>

where the parameters are the following:

API_CLIENT_ID:
The apiCientID provided in inBrain.ai dashboard

API_SECRET:
The apiSecret provided in inBrain.ai dashboard

S2S:
Bool value. true if it is a server-to-server communication.

USER_ID:
User ID

SESSION_ID:
Session ID.


InitOptions:

type ConfigOptionName = "sessionID" | "userID" | "dataOptions";
type StylingOptionName = "title" | "navbarColor";
type InitOptionName = ConfigOptionName | StylingOptionName;
type ConfigOptionTypes = {
    sessionID: string;
    userID: string;
    dataOptions: DataOptions;
};
type ConfigOptions = {
    [opt in ConfigOptionName]?: ConfigOptionTypes[opt];
};
type StylingOptionType = {
    title: string;
    navbarColor: string;
};
type StylingOptions = {
    [opt in StylingOptionName]?: StylingOptionType[opt];
};
type InitOptions = ConfigOptions & StylingOptions;

Example:

InBrainCordova.init(
        "c0bbffc5-3c2b-44e7-a89e-f720c1a5867f",
        "5iwiMGX3nWBLtNFHDinib7OfHb1mLUVII9x6Q+5bCLT+CMZZ9YbN9MWdywT/rfGFkmvRV+EwD2ltTAFzGGx1lQ==",
        false,
        "[email protected]",
        "[email protected]",
        {
          dataOptions: data,
          title: "Test title",
          navbarColor: "#FF00FF"
        }
      ).then(() => {
        console.log("Init success...");
        // ...
      })
      .catch((err: InBrain.InBrainError) => {
        console.log("Error happened in init: " + JSON.stringify(err))
      })

Fields for init options:

title: string;
The title of the Surveys' nav bar.

navbarColor: string;
The color of the nav bar in hexcode string.

dataOptions: DataOptions;
Array of key-value pairs of strings to provide InBrain profiler data for custom profiler user experience.
e.g.
{ age : “23”, gender : “female” }

showSurveys

Shows surveys.

InBrainCordova.showSurveys(): Promise<void>

getRewards

Get the details of all the rewards, in case the server mode is YES.

InBrainCordova.getRewards(): Promise<InBrainReward[]>

Where InBrainReward is

type InBrainReward = {
    transactionId: number;
    amount: number;
    currency: string;
    transactionType: number;
};

Callback functions

The survey SDK can trigger some events that we can get through callbacks. To take effect, the callbacks needs to set by the following method.

setListeners

Sets the callbacks.

static setListeners(callbacks: InBrainCallbacks): Promise<void>;

Where InBrainCallbacks is defined like

type InBrainCallbacks = {
    surveyClosed: () => void,
    rewardsReceived: (rewards: InBrainReward[]) => void
};

surveyClosed: Triggered when the survey is closed

rewardsReceived: Triggered when new rewards are received.

Example:

InBrainCordova.setListeners({
            surveyClosed : () => {
              console.log("inBrain form is closed")
            },
            rewardsReceived: (rewards: [InBrain.InBrainReward]) => {
              console.log("inBrain receive a reward: " + JSON.stringify(rewards));
              this.zone.run(() => {
                this.numTokens = this.getTokens(rewards);
              })
            }
          })
          .then(() => {
            console.log("Callback setListeners successfully set");
          })
          .catch((err: InBrain.InBrainError) => {
            console.log("setListeners error: " + JSON.stringify(err));
          });