Options
All
  • Public
  • Public/Protected
  • All
Menu

The main SDK class

This class must be initialized before any Kii SDK functions are performed. This class also allows the application to make some high-level user calls and access some application-wide data at any time using static methods.

Hierarchy

  • Kii

Index

Methods

  • Authenticate as app admin.

    This api call must not placed on code which can be accessed by browser. This api is intended to be used by server side code like Node.js. If you use this api in code accessible by browser, your application id and application secret could be stolen. Attacker will be act as appadmin and all the data in your application will be suffered.

    example
    Kii.authenticateAsAppAdmin("your client id", "your client secret").then(adminContext => { // fulfill callback function
    // adminContext : KiiAppAdminContext instance
    // Operate entities with adminContext.
    }).catch(error => { // reject callback function
    // Authentication failed.
    let errorString = error.message;
    });

    Parameters

    • clientId: string

      assigned to your application.

    • clientSecret: string

      assigned to your application.

    • app: KiiApplication = KiiApplication.globalApp

      KiiApplication instance. When omitted, KiiApplication.globalApp is used.

    Returns Promise<KiiAppAdminContext>

    return promise object.

    • fulfill callback function: function(adminContext). adminContext is a KiiAppAdminContext instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • Authenticate as Thing.

    This api is intended to be used in a Thing device, where the user credentials or app admin context is not configured. This Thing must be already registered in Kii Cloud.

    example
    Kii.authenticateAsThing("vendor thing id", "password of this thing").then(thingContext => { // fulfill callback function
    // thingContext : KiiThingContext instance
    // Operate entities with thingContext.
    }).catch(error => { // reject callback function
    // Authentication failed.
    let errorString = error.message;
    });

    Parameters

    • vendorThingID: string

      vendorThingID of a registered Thing.

    • password: string

      password for the registered Thing.

    • app: KiiApplication = KiiApplication.globalApp

      KiiApplication instance. When omitted, KiiApplication.globalApp is used.

    Returns Promise<KiiThingContext>

    return promise object.

    • fulfill callback function: function(thingContext). thingContext is a KiiThingContext instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • Create a KiiThingContext reference

    This api is intended to be used in a Thing device, where the user credentials or app admin context is not configured. This Thing must be already registered in Kii Cloud.

    example
    Kii.authenticateAsThingWithToken("thing_id", "thing_token").then(thingContext => { // fulfill callback function
    // thingContext : KiiThingContext instance
    // Operate entities with thingContext.
    }).catch(error => { // reject callback function
    // Creation failed.
    let errorString = error.message;
    });

    Parameters

    • thingID: string

      thingID of a registered Thing.

    • token: string

      token for the registered Thing.

    • app: KiiApplication = KiiApplication.globalApp

      KiiApplication instance. When omitted, KiiApplication.globalApp is used.

    Returns Promise<KiiThingContext>

    return promise object.

    • fulfill callback function: function(thingContext). thingContext is a KiiThingContext instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • bucketWithName(bucketName: string): KiiBucket
  • Creates a reference to a bucket for this app

    The bucket will be created/accessed within this app's scope

    example
    const bucket = Kii.bucketWithName("myBucket");
    

    Parameters

    • bucketName: string

      The name of the bucket the app should create/access

    Returns KiiBucket

    A working KiiBucket object

  • Creates a reference to a encrypted bucket for this app

    The bucket will be created/accessed within this app's scope

    example
    const bucket = Kii.encryptedBucketWithName("myBucket");
    

    Parameters

    • bucketName: string

      The name of the bucket the app should create/access

    Returns KiiEncryptedBucket

    A working KiiEncryptedBucket object

  • getAppID(): string
  • Retrieve the current app ID

    Returns string

    The current app ID

  • getAppKey(): string
  • Retrieve the current app key

    Returns string

    The current app key

  • getBuildNumber(): string
  • Kii SDK Build Number

    Returns string

    current build number of the SDK

  • getSDKVersion(): string
  • Kii SDK Version Number

    Returns string

    current version number of the SDK

  • groupWithName(groupName: string): KiiGroup
  • Creates a reference to a group with the given name

    example
    const group = Kii.groupWithName("myGroup");
    

    Parameters

    • groupName: string

      groupName An application-specific group name

    Returns KiiGroup

    A new KiiGroup reference

  • groupWithNameAndMembers(groupName: string, members: any[]): any
  • Creates a reference to a group with the given name and a list of default members

    example
    const group = KiiGroup.groupWithName("myGroup", members);
    

    Parameters

    • groupName: string

      An application-specific group name

    • members: any[]

      An array of KiiUser objects to add to the group

    Returns any

    A new KiiGroup reference

  • Initialize the Kii SDK

    Should be the first Kii SDK action your application makes.

    example
    Kii.initialize("my-app-id", "my-app-key");
    

    Parameters

    • appID: string

      The application ID found in your Kii developer console

    • appKey: string

      The application key found in your Kii developer console

    Returns KiiApplication

    KiiApplication instance

  • initializeWithSite(appID: string, appKey: string, site: string): KiiApplication
  • Initialize the Kii SDK with a specific URL

    Should be the first Kii SDK action your application makes.

    example
    Kii.initializeWithSite("my-app-id", "my-app-key", KiiSite.JP);
    

    Parameters

    • appID: string

      The application ID found in your Kii developer console

    • appKey: string

      The application key found in your Kii developer console

    • site: string

      site Can be one of the constants KiiSite.US, KiiSite.JP, KiiSite.SG depending on your location.

    Returns KiiApplication

    KiiApplication instance

  • Gets a list of topics in app scope

    example
    Kii.listTopics().then(params => {
    let topicList = params[0];
    let nextPaginationKey = params[1];
    // do something with the result
    for (let i = 0; i < topicList.length; i++) {
    let topic = topicList[i];
    }
    if (nextPaginationKey != null) {
    Kii.listTopics(nextPaginationKey)
    .then(result => {...})
    .catch(error => {...});
    }
    }).catch(error => {
    // do something with the error response
    });

    Parameters

    • Optional paginationKey: string

      You can specify the pagination key with the nextPaginationKey passed by callbacks.success or fullfill callback of promise. If empty string or no string object is provided, this API regards no paginationKey specified.

    • app: KiiApplication = KiiApplication.globalApp

      KiiApplication instance. When omitted, KiiApplication.globalApp is used.

    Returns Promise<[KiiTopic[], null | string]>

    return promise object.

    • fulfill callback function: function(params).
      • params[0] is array of KiiTopic instances.
      • params[1] is string of nextPaginationKey.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • serverCodeEntry(entryName: string, version: string, environmentVersion: string): any
  • Instantiate KiiServerCodeEntry.

    throws

    {InvalidArgumentException} Thrown in the following cases:

    • entryName or version is not type of string
    • entryName or version is empty string
    • entryName is invalid string. Valid entryName pattern is "[a-zA-Z][_a-zA-Z0-9]*$".
    example
    let entry = Kii.serverCodeEntryWithVersion("main", "gulsdf6ful8jvf8uq6fe7vjy6", KiiServerCodeEnvironmentVersion.V0);
    

    Parameters

    • entryName: string

      Name of the entry.

    • version: string

      Version of the entry.

    • environmentVersion: string

      Version of the Node.js. Currently, supported versions are 0 and 6.

    Returns any

    KiiServerCodeEntry instance.

  • setAccessTokenExpiration(expiresIn: number, app?: KiiApplication): void
  • the access token lifetime in seconds. If you don't call this method or call it with 0, token won't be expired. Call this method if you like the access token to be expired after a certain period. Once called, token retrieved by each future authentication will have the specified lifetime. Note that, it will not update the lifetime of token received prior calling this method. Once expired, you have to login again to renew the token.

    example
    Kii.setAccessTokenExpiration(3600);
    

    Parameters

    Returns void

Generated using TypeDoc