• Public
  • Public/Protected
  • All

Class KiiApplication

KiiApplication represents an application info.

While initializing Kii, it automatically generates an KiiApplication instance, and that will be used by default.

Optionally, you may create a separate KiiApplication for switching the context.


example of copying an object from an app to the other

// Assume myBucket and object xxxx is already registered.
const usApp = Kii.initializeWithSite("my-app-id1", "my-app-key1", KiiSite.US);
// If no app is injected, the app in which Kii.initializeWithSite() will be used.
// i.e. In this case, usApp will be used.
const bucketUS = Kii.bucketWithName("myBucket");
KiiObject.objectWithURI("kiicloud://buckets/myBucket/objects/xxxx").refresh().then((obj1) => {
// create a separate app
const jpApp = new KiiApplication("my-app-id2", "my-app-key2", KiiSite.JP);
// Assume a myBucket and object yyyy is already registered.
const bucketJP = jpApp.bucketWithName("myBucket");
// Inject the jpApp while creating a object, so that this object will be created on jpApp.
const obj2 = KiiObject.objectWithURI("kiicloud://buckets/myBucket/objects/yyyy", jpApp);
obj1.getKeys().forEach((key) => {
obj2.set(key, obj1.get(key));
// authenticate in jpApp to write the object
return KiiUser.authenticate("myusername", "mypassword", jpApp).then(() => {
return obj2.save();

example of using multiple contexts at a time

const userApp = Kii.initializeWithSite("my-app-id", "my-app-key", KiiSite.US);
// authenticate as a normal user. Now the userApp & the default app works as a user context.
KiiUser.authenticate("myusername", "mypassword").then((user) => {
// get a list of topics that the user can subscribe.
return userApp.listTopics().then((userTopics) => {

// login as an app admin. This does not affect the user / userApp above.
Kii.authenticateAsAppAdmin("your client id", "your client secret").then((adminContext) => {
// this app has an admin context.
const adminApp = adminContext.getApp();
// get a full list of topics.
return adminApp.listTopics().then((allTopics) => {


  • KiiApplication



  • new KiiApplication(appId: string, appKey: string, baseURL: string, admin?: boolean): KiiApplication
  • Create a new KiiApplication.

    You don't have to create a KiiApplication by yourself unless you want to handle more than one context at a time.

    e.g. Either multiple applications or two different context with a same application (like App admin and App user)

    const app = new KiiApplication("my-app-id", "my-app-key", KiiSite.JP);


    • appId: string
    • appKey: string

      The application key found in your Kii developer console

    • baseURL: string
    • admin: boolean = false

      An internal flag to determine if the login user is admin context or not.

    Returns KiiApplication

    KiiApplication instance


globalApp: KiiApplication

Either a default KiiApplication or an injected KiiApplication.


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

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

    const bucket = app.bucketWithName("myBucket");


    • 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

    const bucket = app.encryptedBucketWithName("myBucket");


    • bucketName: string

      The name of the bucket the app should create/access

    Returns KiiEncryptedBucket

    A working KiiEncryptedBucket object

  • getAccessToken(): string
  • Get the access token for the user - only available if the user is currently logged in

    Returns string

    Access token

  • getAccessTokenExpiration(): number
  • Get the access token expiration.

    Returns number

  • 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

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

    const group = app.groupWithName("myGroup");


    • groupName: string

      groupName An application-specific group name

    Returns KiiGroup

    A new KiiGroup reference

  • listTopics(paginationKey?: string): Promise<[KiiTopic[], null | string]>
  • Get a list of topics.


    • paginationKey: string = ""

      You can specify the pagination key with the nextPaginationKey. If empty string or no string object is provided, this API regards no paginationKey specified.

    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.target is a KiiAppAdminContext instance which this method was called on.
      • error.message

Generated using TypeDoc