Options
All
  • Public
  • Public/Protected
  • All
Menu

Class KiiAppAdminContext

represents the app admin context

This class must not referred from code accessible from browser. This class is intended to be used by server side code like Node.js. If you use this class in code accessible by browser, your application client id and client secret could be stolen. Attacker will be act as application admin and all the data in your application will be suffered.

Application administrator context. Entities obtained from this class will be manipulated by application admin.

Hierarchy

  • KiiAppAdminContext

Index

Methods

  • bucketWithName(bucketName: string): KiiBucket
  • Creates a reference to a bucket operated by app admin.

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

    example
    Kii.authenticateAsAppAdmin("client-id", "client-secret").then(adminContext => {
    let bucket = adminContext.bucketWithName("myBucket");
    // KiiBucket operation by app admin is available now.
    }).catch(error => {
    // auth failed.
    });

    Parameters

    • bucketName: string

    Returns KiiBucket

    A working KiiBucket object

  • Creates a reference to a encrypted bucket operated by app admin.

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

    example
    Kii.authenticateAsAppAdmin("client-id", "client-secret").then(adminContext) {
    let bucket = adminContext.encryptedBucketWithName("myBucket");
    // KiiBucket operation by app admin is available now.
    }).catch(error => {
    // auth failed.
    });

    Parameters

    • bucketName: string

    Returns KiiEncryptedBucket

    A working KiiBucket object

  • findUserByEmail(email: string): Promise<KiiUser>
  • Find registered KiiUser with the email.
    If there are no user registers with the specified email or if there are but not verified email yet, callbacks.failure or reject callback of promise will be called.
    If the email is null or empty, callbacks.failure or reject callback of promise will be callded.

    Note:

    • If "Expose Full User Data To Others" is enabled in the application console, the response will contain full of the user data.
    • Otherwise, the response will only contain "userID", "loginName" and "displayName" field values if exist.
    example
    Kii.authenticateAsAppAdmin("client-id", "client-secret").then(adminContext => {
    adminContext.findUserByEmail("user_to_find@example.com").then(user => { // fullfill callback function
    // Do something with the found user
    }).catch(error => { // reject callback function
    let adminContext = error.target;
    let anErrorString = error.message;
    // Do something with the error response
    });
    }).catch(error => {
    // Auth failed.
    });

    Parameters

    • email: string

      The email to find KiiUser who owns it.
      Don't add prefix of "EMAIL:" described in REST API documentation. SDK will take care of it.

    Returns Promise<KiiUser>

    return promise object.

    • fulfill callback function: function(user).
      • user is a found KiiUser instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is a KiiAppAdminContext instance which this method was called on.
      • error.message

  • findUserByPhone(phone: string): Promise<KiiUser>
  • Find registered KiiUser with the phone.
    If there are no user registers with the specified phone or if there are but not verified phone yet, callbacks.failure or reject callback of promise will be called.
    If the phone is null or empty, callbacks.failure or reject callback of promise will be called.

    Note:

    • If "Expose Full User Data To Others" is enabled in the application console, the response will contain full of the user data.
    • Otherwise, the response will only contain "userID", "loginName" and "displayName" field values if exist.
    example
    Kii.authenticateAsAppAdmin("client-id", "client-secret").then(adminContext => {
    adminContext.findUserByPhone("phone_number_to_find").then(user => { // fullfill callback function
    // Do something with the found user
    }).catch(error => { // reject callback function
    let adminContext = error.target;
    let anErrorString = error.message;
    // Do something with the error response
    });
    }).catch(error => {
    // Auth failed.
    });

    Parameters

    • phone: string

      The phone number to find KiiUser who owns it.
      Don't add prefix of "PHONE:" described in REST API documentation. SDK will take care of it.

    Returns Promise<KiiUser>

    return promise object.

    • fulfill callback function: function(user).
      • user is a found KiiUser instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is a KiiAppAdminContext instance which this method was called on.
      • error.message

  • findUserByUsername(username: string): Promise<KiiUser>
  • Find registered KiiUser with the user name.
    If there are no user registers with the specified user name, callbacks.failure or reject callback of promise will be called.
    If the user name is null or empty, callbacks.failure or reject callback of promise will be called.

    Note:

    • If "Expose Full User Data To Others" is enabled in the application console, the response will contain full of the user data.
    • Otherwise, the response will only contain "userID", "loginName" and "displayName" field values if exist.
    example
    Kii.authenticateAsAppAdmin("client-id", "client-secret").then(adminContext => {
    adminContext.findUserByUsername("user_name_to_find").then(user => { // fullfill callback function
    // Do something with the found user
    }.catch(error => { // reject callback function
    let adminContext = error.target;
    let anErrorString = error.message;
    // Do something with the error response
    });
    }.catch(error => {
    // Auth failed.
    });

    Parameters

    • username: string

      The user name to find KiiUser who owns it.
      Don't add prefix of "LOGIN_NAME:" described in REST API documentation. SDK will take care of it.

    Returns Promise<KiiUser>

    return promise object.

    • fulfill callback function: function(user).
      • user is a found KiiUser instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is a KiiAppAdminContext instance which this method was called on.
      • error.message

  • getAccessToken(): string
  • Get access token published for app admin.

    Returns string

    access token published for app admin.

  • Creates a reference to a group operated by app admin using group's ID.

    Note: Returned instance from this API can operate existing KiiGroup.
    If you want to create a new KiiGroup, please use KiiAppAdminContext.groupWithName.

    throws

    {InvalidArgumentException} Thrown if passed groupID is null or empty.

    example
    Kii.authenticateAsAppAdmin("client-id", "client-secret").then(adminContext => {
    let groupID = "0123456789abcdefghijklmno";
    let group = adminContext.groupWithID(groupID);
    // KiiGroup operation by app admin is available now.
    }).catch(error => {
    // auth failed.
    });

    Parameters

    • groupID: string

    Returns KiiGroup

    A working KiiGroup object

  • groupWithName(groupName: string): KiiGroup
  • Creates a reference to a group operated by app admin.

    Note: Returned instance from this API can not operate existing KiiGroup.
    If you want to operate existing KiiGroup, please use KiiAppAdminContext.groupWithURI or KiiAppAdminContext.groupWithID.

    example
    Kii.authenticateAsAppAdmin("client-id", "client-secret").then(adminContext => {
    let group = adminContext.groupWithName("newGroup");
    // KiiGroup operation by app admin is available now.
    }).catch(error => {
    // auth failed.
    });

    Parameters

    • groupName: string

    Returns KiiGroup

    A working KiiGroup object

  • groupWithURI(groupUri: string): KiiGroup
  • Creates a reference to a group operated by app admin using group's URI.

    Note: Returned instance from this API can operate existing KiiGroup.
    If you want to create a new KiiGroup, please use KiiAppAdminContext.groupWithName.

    throws

    {InvalidURIException} Thrown if the URI is null, empty or does not have correct format.

    example
    Kii.authenticateAsAppAdmin("client-id", "client-secret").then(adminContext => {
    let groupUri = ...; // KiiGroup's URI
    let group = adminContext.groupWithURI(groupUri);
    // KiiGroup operation by app admin is available now.
    }).catch(error => {
    // auth failed.
    });

    Parameters

    • groupUri: string

    Returns KiiGroup

    A working KiiGroup object

  • listTopics(paginationKey: string): Promise<[KiiTopic[], null | string]>
  • Gets a list of topics in app scope

    example
    adminContext.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) {
    adminContext.listTopics(nextPaginationKey)
    .then(result => {...})
    .catch(error => {...});
    }
    }).catch(error => {
    // do something with the error response
    });

    Parameters

    • paginationKey: string

      You can specify the pagination key with the nextPaginationKey passed by callbacks.success. 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

  • loadThingWithThingID(thingID: string): Promise<KiiThing>
  • Load thing with thing ID by app admin. Method interface is same as KiiThing.loadWithThingID. Please refer to KiiThing document for details.

    example
    adminContext.loadThingWithThingID("thing-xxxx-yyyy").then(thing => {
    // Load succeeded.
    // Operation using thing instance in the parameter
    // is authored by app admin.
    }).catch(error => {
    // Handle error.
    });

    Parameters

    • thingID: string

      registered thing id.

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is KiiThing instance with adminToken.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • loadThingWithVendorThingID(vendorThingID: string): Promise<KiiThing>
  • Load thing with vendor thing ID by app admin. Method interface is same as KiiThing.loadWithVendorThingID. Please refer to KiiThing document for details.

    example
    adminContext.loadThingWithVendorThingID("thing-xxxx-yyyy").then(thing => {
    // Load succeeded.
    // Operation using thing instance in the parameter
    // is authored by app admin.
    }).catch(error => {
    // Handle error.
    });

    Parameters

    • vendorThingID: string

      registered vendor thing id.

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is KiiThing instance with adminToken.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • Creates a reference to an object operated by app admin using object`s URI.

    throws

    {InvalidURIException} If the URI is null, empty or does not have correct format.

    Parameters

    • objectUri: string

    Returns KiiObject

    A working KiiObject instance

  • registerGroupWithOwnerAndID(groupID: string, groupName: string, owner: string, members: KiiUser[]): Promise<KiiGroup>
  • Register new group own by specified user on Kii Cloud with specified ID. This method can be used only by app admin.



    If the group that has specified id already exists, registration will be failed.

    example
    Kii.authenticateAsAppAdmin("client-id", "client-secret").then(adminContext => {
    let owner = KiiUser.userWithID("Owner User Id");
    let members = [];
    members.push(KiiUser.userWithID("Member User Id"));
    return adminContext.registerGroupWithOwnerAndID("Group ID", "Group Name", "Owner User ID", members);
    }).then(group => {
    // do something with the saved group
    });

    Parameters

    • groupID: string

      ID of the KiiGroup

    • groupName: string

      Name of the KiiGroup

    • owner: string
    • members: KiiUser[]

      An array of KiiUser objects to add to the group

    Returns Promise<KiiGroup>

    return promise object.

    • fulfill callback function: function(theSavedGroup). theSavedGroup is KiiGroup instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiGroup instance which this method was called on.
      • error.message
      • error.addMembersArray is array of KiiUser to be added as memebers of this group.
      • error.removeMembersArray is array of KiiUser to be removed from the memebers list of this group.

  • registerOwnerWithThingID<T>(thingID: string, owner: T): Promise<T>
  • Register user/group as owner of specified thing by app admin.

    example
    // assume thing/group is already registered.
    let owner = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
    // example to use Promise
    adminContext.registerOwnerWithThingID("th.xxxx-yyyy-zzzz", owner).then(registeredOwner => {
    // Register owner succeeded.
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • thingID: string

      The ID of thing

    • owner: T

      instnce of KiiUser/KiiGroup to be registered as owner.

    Returns Promise<T>

    return promise object.

    • fulfill callback function: function(params). params is an Array instance.
      • params[0] is a KiiUser/KiiGroup instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • registerOwnerWithThingIDAndPassword<T>(thingID: string, owner: T, password: string): Promise<T>
  • Register user/group as owner of specified thing with password by app admin.

    example
    // assume thing/group is already registered.
    let owner = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
    // example to use Promise
    adminContext.registerOwnerWithThingIDAndPassword("th.xxxx-yyyy-zzzz", owner, "password").then(registeredOwner => {
    // Register owner succeeded.
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • thingID: string

      The ID of thing

    • owner: T

      instnce of KiiUser/KiiGroup to be registered as owner.

    • password: string

      The password of thing

    Returns Promise<T>

    return promise object.

    • fulfill callback function: function(params). params is an Array instance.
      • params[0] is a KiiUser/KiiGroup instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • registerOwnerWithVendorThingID<T>(vendorThingID: string, owner: T): Promise<T>
  • Register user/group as owner of specified thing by app admin.

    example
    // assume thing/group is already registered.
    let owner = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
    // example to use Promise
    adminContext.registerOwnerWithVendorThingID("xxxx-yyyy-zzzz", owner).then(registeredOwner => {
    // Register owner succeeded.
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • vendorThingID: string

      The vendor thing ID of thing

    • owner: T

      instance of KiiUser/KiiGroupd to be registered as owner.

    Returns Promise<T>

    return promise object.

    • fulfill callback function: function(params). params is an Array instance.
      • params[0] is a KiiUser/KiiGroup instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • registerOwnerWithVendorThingIDAndPassword<T>(vendorThingID: string, owner: T, password: string): Promise<T>
  • Register user/group as owner of specified thing with password by app admin.

    example
    // assume thing/group is already registered.
    let owner = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
    // example to use Promise
    adminContext.registerOwnerWithVendorThingIDAndPassword("xxxx-yyyy-zzzz", owner, "password").then(registeredOwner => {
    // Register owner succeeded.
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • vendorThingID: string

      The vendor thing ID of thing

    • owner: T

      instance of KiiUser/KiiGroupd to be registered as owner.

    • password: string

      The password of thing

    Returns Promise<T>

    return promise object.

    • fulfill callback function: function(params). params is an Array instance.
      • params[0] is a KiiUser/KiiGroup instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • Register thing by app admin. Method interface is same as KiiThing.register. Please refer to KiiThing document for details.

    example
    adminContext.registerThing(
    {
    _vendorThingID: "thing-XXXX-YYYY-ZZZZZ",
    _password: "thing-password",
    _thingType: "thermometer",
    yourCustomObj: // Arbitrary key can be used.
    { // Object, Array, Number, String can be used. Should be compatible with JSON.
    yourCustomKey1: "value",
    yourCustomKey2: 100
    }
    }
    ).then(thing => {
    // Register Thing succeeded.
    // Operation using thing instance in the parameter
    // is authored by app admin.
    }).catch(error) {
    // Handle error.
    });

    Parameters

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is KiiThing instance with adminToken.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • Creates a reference to a thing operated by app admin.

    example
    Kii.authenticateAsAppAdmin("client-id", "client-secret").then(adminContext => {
    let thing = adminContext.thingWithID("th.xxxx-yyyy");
    // KiiThing operation by app admin is available now.
    }).catch(error => {
    // auth failed.
    });

    Parameters

    • thingID: string

    Returns KiiThing

    A working KiiThing object

  • topicWithName(topicName: string): KiiTopic
  • Creates a reference to a topic operated by app admin

    Parameters

    • topicName: string

      name of the topic. Must be a not empty string.

    Returns KiiTopic

    topic instance.

  • userWithID(userid: string): KiiUser
  • Creates a reference to a user operated by app admin.

    example
    Kii.authenticateAsAppAdmin("client-id", "client-secret").then(adminContext => {
    let user = adminContext.userWithID("userid");
    // KiiUser operation by app admin is available now.
    }).catch(error => {
    // auth failed.
    });

    Parameters

    • userid: string

    Returns KiiUser

    A working KiiUser object

Generated using TypeDoc