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 🙏

© 2025 – Pkg Stats / Ryan Hefner

thing-if-sdk

v0.2.6

Published

Javascript SDK for Kii Thing Interaction Framework.

Downloads

27

Readme

npm version CircleCI Coverage Status

Javascript SDK for Kii Thing Interaction Framework.

Dependecies

Build SDK

Install NPM packages

$ npm install

Install typings

$ npm install typings -g
$ typings install

Build SDK

thing-if-sdk is built as UMD(Universal Module Definition) library. So your code can load it either with CommonJS style, AMD style or script tag.

Normal build

Built with gulp command

$ npm run build-src

If succeeded, library file named thing-if-sdk.js is available under ./dist/ folder.

Use thing-if-sdk in browser app

Note: thing-if-sdk uses global Promise, so if the browser doesn't support Promise( like Mircrosoft IE11), it needs to polyfill promise to the browser app.

Basic operations of thing-if-sdk are tested and passed on the following browsers: Mozilla Firefox 49.0.1, Safari 9.1.3, Chrome 53.0, and Microsoft Edge 38.

  1. Clone this repository
$ git clone https://github.com/KiiPlatform/thing-if-JSSDK.git
  1. Bundle library using browserify.

browserify bundles all the dependencies into a single file.

$ cd thing-if-JSSDK
$ npm install
$ npm install browserify -g
$ browserify . -s ThingIF > thing-if-sdk.js
  1. Include the bundle file in your browser app
<!-- if the browser does not support promise, need to download polyfill promise library(i.e. https://raw.githubusercontent.com/taylorhakes/promise-polyfill/master/promise.js) and import like the following script -->
<script src="path/to/promise.js"></script>

<script src="path/to/thing-if-sdk.js"></script>

Test

Configure TestApp

You need to configure TestApp as env variable for testing, the format is [app-id]:[app-key]:[JP|CN3|US|EU|SG]:[client-id]:[client-secret]

$ export TestApp=[app-id]:[app-key]:[JP|CN3|US|EU|SG]:[client-id]:[client-secret]

Run npm test

$ npm test

Use cases in nodejs

Integrate with kii-cloud-sdk

You usally need to get user id and token from kii-cloud-sdk, you can simply integrate it with thing-if-sdk.

mkdir MyApp
cd MyApp
npm install kii-cloud-sdk

Copy thing-if-sdk.js in MyApp direcotry and create file named Onboarding.js in MyApp directory.

"use strict"
var kiicloud = require("kii-cloud-sdk").create();

var thingIF = require('./thing-if-sdk.js');

var appid = "****",
    appkey = "****",
    site = kiicloud.KiiSite.JP;

kiicloud.Kii.initializeWithSite(appid, appkey, site);

// an already registered kii user
var username = "user-name";
var pass = "pass";

kiicloud.KiiUser.authenticate(username, pass).then(function (authedUser) {
    var token = authedUser.getAccessToken();
    var ownerId = authedUser.getID();

    var apiAuthor = new thingIF.APIAuthor(
        token,
        new thingIF.App(
            kiicloud.Kii.getAppID(),
            kiicloud.Kii.getAppKey(),
            "https://api-jp.kii.com")
    );

    let onboardRequest = new thingIF.OnboardWithVendorThingIDRequest("vendorthing-id", "password", "USER:" + ownerId);
    return apiAuthor.onboardWithVendorThingID(onboardRequest);
}).then(function (res) {
    console.log("onboarded:"+JSON.stringify(res));
}).catch(function (err) {
    console.log(err);
});

Execute with node.

node Onboarding.js

onboard and send command to a thing

Create file named Command.js in YourApp directory.

var thingIF = require('./thing-if-sdk.js');

// <Replace those values>
var appID = "appID";
var appKey = "appKey";
var appSite = thingIF.Site.JP;

var ownerToken = "owner-token";
var ownerID = "owner-id";
var vendorThingID = "th.myTest";
var thingPassword = "password";
// <Replace those values/>

var app = new thingIF.App(appID, appKey, appSite);
var apiAuthor = new thingIF.APIAuthor(ownerToken ,app);
var onboardOptions = new thingIF.OnboardWithVendorThingIDRequest(vendorThingID, thingPassword, ownerID);

// using promise
apiAuthor.onboardWithVendorThingID(onboardOptions).then(function(res){
    var thingID = res.thingID;
    var commandOptions = new thingIF.PostCommandRequest(
        "led-schema",
        1,
        {turnPower:{power: true}},
        "issuer-id", // user id of issuer for this command
        "command-target-id" // thingID of thing to send this command
    );
    return apiAuthor.postNewCommand(thingID, commandOptions);
}).then(function(command){
    console.log("command created:"+command.commandID);
}).catch(function(err){
    console.log(err);
});

// using callbacks
apiAuthor.onboardWithVendorThingID(onboardOptions,
    function(err, res){
        if (err == null || err == undefined) {
            cosnole.log("onboard failed:" + err);
            // handling err
            return;
        }
        var thingID = res.thingID;
        var commandOptions = new thingIF.PostCommandRequest(
            "led-schema",
            1,
            {turnPower:{power: true}},
            "issuer-id", // user id of issuer for this command
            "command-target-id" // thingID of thing to send this command
        );
        apiAuthor.postNewCommand(thingID, commandOptions,
            function(err, command){
                if (err == null || err == undefined) {
                    cosnole.log("post command failed:" + err);
                    // handling err
                    return;
                }
                console.log("command created:"+command.commandID);
            }
        );
    }
);

Execute with node.

node Command.js

Use in Typescript Project

  • install thing-if-sdk with npm
npm install thing-if-sdk --save
  • install typings
typings install npm:thing-if-sdk --save
  • add reference to your code
/// <reference path="./typings/modules/thing-if-sdk/index.d.ts" />
import * as ThingIFSDK from 'thing-if-sdk'

License

thing-if-JSSDK is released under the Apache 2.0 license. See LICENSE for details.