-
Notifications
You must be signed in to change notification settings - Fork 4
/
KiiSDK.min.js
7 lines (7 loc) · 206 KB
/
KiiSDK.min.js
1
2
3
4
5
6
7
if("undefined"==typeof jQuery&&"object"==typeof process&&"object"==typeof process.versions)var XMLHttpRequest=require("xmlhttprequest").XMLHttpRequest;!function(){var t=function(){Object.keys||(Object.keys=function(){var t=Object.prototype.hasOwnProperty,e=!{toString:null}.propertyIsEnumerable("toString"),i=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],n=i.length;return function(r){if("object"!=typeof r&&"function"!=typeof r||null===r)throw new TypeError("Object.keys called on non-object");var s=[];for(var o in r)t.call(r,o)&&s.push(o);if(e)for(var u=0;n>u;u++)t.call(r,i[u])&&s.push(i[u]);return s}}()),"undefined"==typeof Promise&&!function(t,e){function i(t,e){return(typeof e)[0]==t}function n(s,o){return o=function u(a,l,h,c,p,f){function _(t){return function(e){p&&(p=0,u(i,t,e))}}if(c=u.q,a!=i)return n(function(t,e){c.push({p:this,r:t,j:e,1:a,0:l})});if(h&&i(t,h)|i(e,h))try{p=h.then}catch(g){l=0,h=g}if(i(t,p))try{p.call(h,_(1),l=_(0))}catch(g){l(g)}else for(o=function(e,o){return i(t,e=l?e:o)?n(function(t,i){r(this,t,i,h,e)}):s},f=0;f<c.length;)p=c[f++],i(t,a=p[l])?r(p.p,p.r,p.j,h,a):(l?p.r:p.j)(h)},o.q=[],s.call(s={then:function(t,e){return o(t,e)},"catch":function(t){return o(0,t)}},function(t){o(i,1,t)},function(t){o(i,0,t)}),s}function r(n,r,s,o,u){setTimeout(function(){try{o=u(o),u=o&&i(e,o)|i(t,o)&&o.then,i(t,u)?o==n?s(TypeError()):u.call(o,r,s):r(o)}catch(a){s(a)}})}function s(t){return n(function(e){e(t)})}Promise=n,n.resolve=s,n.reject=function(t){return n(function(e,i){i(t)})},n.all=function(t){return n(function(e,i,n,r){r=[],n=t.length||e(r),t.map(function(t,o){s(t).then(function(t){r[o]=t,--n||e(r)},i)})})}}("f","o");var t,e,i,n,r,s,o,u,a,l,h,c,p=function(t,e){return function(){return t.apply(e,arguments)}},f={}.hasOwnProperty,_=function(t,e){function i(){this.constructor=t}for(var n in e)f.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};return l="undefined"!=typeof exports&&null!==exports?new Object:this,l.KiiSocialNetworkName={FACEBOOK:1,TWITTER:2,QQ:3,GOOGLEPLUS:4,RENREN:5},l.KiiSite={US:"https://api.kii.com/api",JP:"https://api-jp.kii.com/api",SG:"https://api-sg.kii.com/api",EU:"https://api-eu.kii.com/api"},l.KiiServerCodeEnvironmentVersion={V0:"0",V6:"6"},l.Kii=function(){function t(){}var e,n;return n=null,e=null,t.getBuildNumber=function(){return"1"},t.getSDKVersion=function(){return"2.4.19"},t.getBaseURL=function(){return n._baseURL},t.getAppID=function(){return n._appID},t.getAdditionalHeaders=function(){return e},t.setAdditionalHeaders=function(t){return e=t},t.getAppKey=function(){return n._appKey},t.isLogging=function(){return n._logging},t.setLogging=function(t){return n._logging=t,l.Kii.logger("Setting logging: "+t),l.Kii.logger("Base URL: "+n._baseURL)},t.setAccessTokenExpiration=function(t){if(!n)throw new l.IllegalStateException("Kii is not initialized");if(isNaN(parseInt(t,10)))throw new l.InvalidArgumentException("expiresIn should be a number");if(0>t)throw new l.InvalidArgumentException("expiresIn should not negative number");return n?n._expiresIn=t:void 0},t.getAccessTokenExpiration=function(){if(!n)throw new l.IllegalStateException("Kii is not initialized");return n._expiresIn},t.initializeWithSite=function(t,e,i){return n=new h(t,e,i),l.Kii.logger("Initialized "+t+", "+e+", "+i)},t.initialize=function(t,e){return l.Kii.initializeWithSite(t,e,l.KiiSite.US)},t.logger=function(t){return n._logging?console.log(t):void 0},t.bucketWithName=function(t){var e;return e=new l.KiiBucket(t,null)},t.encryptedBucketWithName=function(t){var e;return e=new l.KiiEncryptedBucket(t,null)},t.groupWithName=function(t){return new l.Kii.groupWithNameAndMembers(t,null)},t.groupWithNameAndMembers=function(t,e){return new l.KiiGroup.groupWithNameAndMembers(t,e)},t.logOut=function(){return n._currentUser=null,l.KiiSocialConnect.logOutAll()},t.loggedIn=function(){return null!=n._currentUser},t.getCurrentUser=function(){var t;return null!=n._currentUser?t=s._clone(n._currentUser):null},t.setCurrentUser=function(t){return n._currentUser=s._clone(t)},t.authenticateAsAppAdmin=function(t,e,i){return new Promise(function(n){return function(r,o){var u;return u={success:function(){return null!=i&&i.success.apply(i,arguments),r(arguments[0])},failure:function(){return null!=i&&i.failure.apply(i,arguments),o(s._Error(arguments[0]))}},n._authenticateAsAppAdminUsingCallbacks(t,e,u)}}(this))},t._authenticateAsAppAdminUsingCallbacks=function(t,e,n){var r,s;return s=new i("/oauth2/token",!1),s.setAnonymous(!0),s.setMethod("POST"),s.setData({client_id:t,client_secret:e}),r={success:function(t){return function(t){var e,i,r;return r=t.access_token,i=t.id,l.Kii.logger("token: "+r),l.Kii.logger("id: "+i),e=new l.KiiAppAdminContext({token:r,id:i}),null!=n?n.success(e):void 0}}(this),failure:function(t){return function(t,e){return l.Kii.logger("error: "+t),l.Kii.logger("statusCode: "+e),null!=n?n.failure(t,e):void 0}}(this)},s.execute(r,!1)},t.authenticateAsAdminWithToken=function(t){return new l.KiiAppAdminContext({token:t})},t.serverCodeEntry=function(t,e,i){if(!s._validateServerCodeEntryName(t))throw new l.InvalidArgumentException("entryName is invalid");if(e&&!s._validateServerCodeEnryVersion(e))throw new l.InvalidArgumentException("version is invalid");return new l.KiiServerCodeEntry(t,e,i)},t.serverCodeEntryWithVersion=function(t,e){if(!s._validateServerCodeEntryName(t))throw new l.InvalidArgumentException("entryName is invalid");if(!s._validateServerCodeEnryVersion(e))throw new l.InvalidArgumentException("version is invalid");return new l.KiiServerCodeEntry(t,e)},t._setHttpRequestType=function(t){return l.Kii.logger("Set http request as "+t),n._httpRequestType=t},t._getHttpRequestType=function(){return n._httpRequestType},t._getKiiUtilities=function(){return s},t.topicWithName=function(t){var e;if("string"!=typeof t||""===t)throw new l.InvalidArgumentException("topicName should not null or empty");return e=""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID(),new l.KiiTopic(e,t)},t.listTopics=function(e,i){return t._listTopics(e,i)},t._listTopics=function(e,i,n){return new Promise(function(r,s){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),r(arguments)},failure:function(){return null!=e&&e.failure.apply(e,arguments),s(arguments[0])}},t._listTopicsUsingCallbacks(o,i,n)})},t._listTopicsUsingCallbacks=function(e,i,n){var r,o,a;return o=""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/topics","string"==typeof i&&""!==i&&(o=o+"?paginationKey="+encodeURIComponent(i)),a=u.createXHRWrapper("GET",o),a.setKiiHeaders(),null!=n?a.setAuthToken(n._getToken()):a.setCurrentUserToken(),r={success:function(){var i,n,r,s,o,u;for(i=JSON.parse(a.xhr.responseText),r=[],u=i.topics,s=0,o=u.length;o>s;s++)n=u[s],r.push(t.topicWithName(n.topicID));return null!=e?e.success(r,void 0===i.paginationKey?null:i.paginationKey):void 0},failure:function(){var i,n;return n=a.getErrorString("list topics"),i=s._Error(n,t),null!=e?e.failure(i):void 0}},a.send(r)},t.authenticateAsThing=function(t,e,i){return new Promise(function(n){return function(n,r){var o,a,h;return s._isNonEmptyString(t)&&s._isNonEmptyString(e)?(h=u.createXHRWrapper("POST",""+l.Kii.getBaseURL()+"/oauth2/token"),h.setKiiHeaders(),h.setContentType("application/vnd.kii.OauthTokenRequest+json"),a={success:function(){var e,u,a,c,p;return a=JSON.parse(decodeURIComponent(h.xhr.responseText)),p=a.id,e=a.access_token,null!=p&&null!=e?(c=new l.KiiThingContext({thingId:p,token:e,vendorThingID:t}),null!=i&&i.success(c),n(c)):(u=h.getErrorString("invalid format response when authenticate thing "),o=s._Error(u),null!=i&&i.failure(o),r(o))},failure:function(){var t;return t=h.getErrorString("authenticate as thing"),o=s._Error(t),null!=i&&i.failure(o),r(o)}},h.sendData(JSON.stringify({username:"VENDOR_THING_ID:"+t,password:e}),a)):(o=s._Error("vendorThingID or password is invalid"),null!=i&&i.failure(o),void r(o))}}(this))},t.authenticateAsThingWithToken=function(t,e,i){return new Promise(function(n){return function(n,r){var o,u;return s._isNonEmptyString(t)&&s._isNonEmptyString(e)?(u=new l.KiiThingContext({thingId:t,token:e}),null!=i&&i.success(u),n(u)):(o=s._Error("thingID or token is invalid"),null!=i&&i.failure(o),r(o))}}(this))},t}(),l._KiiHttpRequestType={jQuery:"jQuery",XMLHttpRequest:"XMLHttpRequest",Titanium:"Titanium"},h=function(){function t(t,e,i){this._appKey=e,this._appID=t,this._baseURL=i,this._expiresIn=0}return t.prototype._logging=!1,t.prototype._baseURL=null,t.prototype._currentUser=null,t.prototype._httpRequestType=null,t}(),l.KiiACL=function(){function t(){this._thingWithID=p(this._thingWithID,this),this._userWithID=p(this._userWithID,this),this._groupWithID=p(this._groupWithID,this),this._getRequest=p(this._getRequest,this),this._saveItr=p(this._saveItr,this),this._saveUsingCallbacks=p(this._saveUsingCallbacks,this),this.save=p(this.save,this),this._getKeyOfEntry=p(this._getKeyOfEntry,this),this.removeACLEntry=p(this.removeACLEntry,this),this.putACLEntry=p(this.putACLEntry,this),this._listACLEntriesUsingCallbacks=p(this._listACLEntriesUsingCallbacks,this),this.listACLEntries=p(this.listACLEntries,this),this.aclPath=p(this.aclPath,this),this._setParent=p(this._setParent,this),this._entriesMap={}}return t.prototype._setParent=function(t){this._parent=t},t.prototype.aclPath=function(){var t,e,i,n,r,s,o,u,a,h;return this._parent instanceof l.KiiObject?(n=this._parent,null!=n.getBucket().getUser()?h=n.getBucket().getUser():null!=n.getBucket().getGroup()?i=n.getBucket().getGroup():null!=n.getBucket().getThing()&&(u=n.getBucket().getThing()),e=n.getBucket()._getQualifiedBucketName(),r=n.getUUID()):this._parent instanceof l.KiiBucket?(t=this._parent,null!=t.getUser()?h=t.getUser():null!=t.getGroup()?i=t.getGroup():null!=t.getThing()&&(u=t.getThing()),e=t._getQualifiedBucketName()):this._parent instanceof l.KiiTopic?a=this._parent:l.Kii.logger("Invalid ACL parent. Must belong to a KiiObject"),s="/",null!=i?s+="groups/"+i.getUUID()+"/":null!=h?s+="users/"+h.getUUID()+"/":null!=u&&(s+="things/"+u.getThingID()+"/"),a?(o=""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/",0!==a._uri.indexOf(o)?s=null:s+=a._uri.substr(o.length)+"/acl"):s+=null!=r?"buckets/"+e+"/objects/"+r+"/acl":"buckets/"+e+"/acl",s},t.prototype.listACLEntries=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments)},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._listACLEntriesUsingCallbacks(r)}}(this))},t.prototype._listACLEntriesUsingCallbacks=function(t){var e,i;return l.Kii.logger("Listing ACL entries"),i=this._getRequest({path:this.aclPath(),withApp:!0}),e={success:function(e){return function(i,n){var r,s,o,u,a,h,c,p;if(300>n&&n>=200){u=[];for(o in i){if(h=i[o],"WRITE_EXISTING_OBJECT"===o)r=l.KiiACLAction.KiiACLObjectActionWrite;else if("READ_EXISTING_OBJECT"===o)r=l.KiiACLAction.KiiACLObjectActionRead;else if("QUERY_OBJECTS_IN_BUCKET"===o)r=l.KiiACLAction.KiiACLBucketActionQueryObjects;else if("CREATE_OBJECTS_IN_BUCKET"===o)r=l.KiiACLAction.KiiACLBucketActionCreateObjects;else if("DROP_BUCKET_WITH_ALL_CONTENT"===o)r=l.KiiACLAction.KiiACLBucketActionDropBucket;else if("READ_OBJECTS_IN_BUCKET"===o)r=l.KiiACLAction.KiiACLBucketActionReadObjects;else if("SUBSCRIBE_TO_TOPIC"===o)r=l.KiiACLAction.KiiACLSubscribeToTopic;else{if("SEND_MESSAGE_TO_TOPIC"!==o)continue;r=l.KiiACLAction.KiiACLSendMessageToTopic}for(c=0,p=h.length;p>c;c++){if(s=h[c],null!=s.groupID)a=e._groupWithID(s.groupID);else if(null!=s.userID)a=e._userWithID(s.userID);else{if(null==s.thingID)continue;a=e._thingWithID(s.thingID)}u.push(l.KiiACLEntry.entryWithSubject(a,r))}}return t.success(e,u)}return t.failure(e,"Unable to retrieve ACL list")}}(this),failure:function(e){return function(i,n){return t.failure(e,i)}}(this)},i.execute(e,!1)},t.prototype.putACLEntry=function(t){var e;if(!(t instanceof l.KiiACLEntry))throw new l.InvalidArgumentException("invalid entry");return e=this._getKeyOfEntry(t),this._entriesMap[e]=t},t.prototype.removeACLEntry=function(t){var e;if(!(t instanceof l.KiiACLEntry))throw new l.InvalidArgumentException("invalid entry");return e=this._getKeyOfEntry(t),delete this._entriesMap[e]},t.prototype._getKeyOfEntry=function(t){var e,i,n;return e=t.getActionString(),i=t.getEntityString(),n=t.getGrant(),""+e+"/"+i+":"+n},t.prototype.save=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._saveUsingCallbacks(r)}}(this))},t.prototype._saveUsingCallbacks=function(t){var e;return l.Kii.logger("SAving acl"),this._entriesMap?(e=Object.keys(this._entriesMap),l.Kii.logger("Saving total entries : "+e.length),e.length<1?void t.failure(this,"There is no entry to save."):this._saveItr(e,0,t)):void t.failure(this,"There is no entry to save.")},t.prototype._saveItr=function(t,e,i){var n,r,s,o;return n=this._entriesMap[t[e]],r=""+this.aclPath()+"/"+n.getActionString()+"/"+n.getEntityString(),l.Kii.logger("Saving single @path: "+r),l.Kii.logger("Saving entries index : "+e),s=this._getRequest({path:r,withApp:!0}),s.setMethod(n.getGrant()===!0?"PUT":"DELETE"),o=null,s.execute({success:function(r){return function(s,o,u){return r.removeACLEntry(n),e<t.length-1?r._saveItr(t,e+1,i):i.success(r)}}(this),failure:function(t){return function(e,n,r){return i.failure(t,e)}}(this)},!1)},t.aclWithParent=function(t){var e;return e=new l.KiiACL,e._setParent(t),e},t.prototype._getRequest=function(t){var e,n,r;return e=t.path,r=t.withApp,n=new i(e,r)},t.prototype._groupWithID=function(t){var e;return e=l.KiiGroup.groupWithID(t)},t.prototype._userWithID=function(t){return"ANONYMOUS_USER"===t?new l.KiiAnonymousUser:"ANY_AUTHENTICATED_USER"===t?new l.KiiAnyAuthenticatedUser:l.KiiUser.userWithID(t)},t.prototype._thingWithID=function(t){return l.KiiThing.thingWithID(t)},t}(),l.KiiACLAction={KiiACLActionStart:-1,KiiACLBucketActionCreateObjects:0,KiiACLBucketActionQueryObjects:1,KiiACLBucketActionDropBucket:2,KiiACLBucketActionReadObjects:3,KiiACLObjectActionRead:4,KiiACLObjectActionWrite:5,KiiACLSubscribeToTopic:6,KiiACLSendMessageToTopic:7,KiiACLActionEnd:8},l.KiiACLEntry=function(){function t(){this.getEntityString=p(this.getEntityString,this),this.getActionString=p(this.getActionString,this),this.getGrant=p(this.getGrant,this),this.setGrant=p(this.setGrant,this),this.getSubject=p(this.getSubject,this),this.setSubject=p(this.setSubject,this),this.getAction=p(this.getAction,this),this.setAction=p(this.setAction,this),this._action=-1,this._grant=!0}return t.prototype.setAction=function(t){if(t>l.KiiACLAction.KiiACLActionStart&&t<l.KiiACLAction.KiiACLActionEnd)return this._action=t;throw new l.InvalidACLAction},t.prototype.getAction=function(){return this._action},t.prototype.setSubject=function(t){if(t instanceof l.KiiGroup&&null!=t.getID()||t instanceof l.KiiUser&&null!=t.getID()||t instanceof l.KiiAnyAuthenticatedUser||t instanceof l.KiiAnonymousUser||t instanceof l.KiiThing&&null!=t.getThingID())return this._subject=t;throw new l.InvalidACLSubject},t.prototype.getSubject=function(){return this._subject},t.prototype.setGrant=function(t){if(t===!0||t===!1)return this._grant=t;throw new l.InvalidACLGrant},t.prototype.getGrant=function(){return this._grant},t.entryWithSubject=function(t,e){var i;return l.Kii.logger("EWS: "+t+", "+e),i=new l.KiiACLEntry,i.setSubject(t),i.setAction(e),i},t.prototype.getActionString=function(){var t;switch(l.Kii.logger("Action: "+this.action),this._action){case l.KiiACLAction.KiiACLBucketActionCreateObjects:t="CREATE_OBJECTS_IN_BUCKET";break;case l.KiiACLAction.KiiACLBucketActionQueryObjects:t="QUERY_OBJECTS_IN_BUCKET";break;case l.KiiACLAction.KiiACLBucketActionDropBucket:t="DROP_BUCKET_WITH_ALL_CONTENT";break;case l.KiiACLAction.KiiACLBucketActionReadObjects:t="READ_OBJECTS_IN_BUCKET";break;case l.KiiACLAction.KiiACLObjectActionRead:t="READ_EXISTING_OBJECT";break;case l.KiiACLAction.KiiACLObjectActionWrite:t="WRITE_EXISTING_OBJECT";break;case l.KiiACLAction.KiiACLSubscribeToTopic:t="SUBSCRIBE_TO_TOPIC";break;case l.KiiACLAction.KiiACLSendMessageToTopic:t="SEND_MESSAGE_TO_TOPIC";break;default:return t}return t},t.prototype.getEntityString=function(){var t,e;return this._subject instanceof l.KiiGroup?(t=this._subject.getUUID(),e="GroupID"):this._subject instanceof l.KiiUser?(t=this._subject.getUUID(),e="UserID"):this._subject instanceof l.KiiAnyAuthenticatedUser?(e="UserID",t="ANY_AUTHENTICATED_USER"):this._subject instanceof l.KiiAnonymousUser?(e="UserID",t="ANONYMOUS_USER"):this._subject instanceof l.KiiThing&&(e="ThingID",t=this._subject.getThingID()),""+e+":"+t},t}(),l.KiiBucket=function(){function t(t,e){if(this.objectWithJSON=p(this.objectWithJSON,this),this._getHttpUri=p(this._getHttpUri,this),this._generatePath=p(this._generatePath,this),this._getRequest=p(this._getRequest,this),this._deleteUsingCallbacks=p(this._deleteUsingCallbacks,this),this["delete"]=p(this["delete"],this),this.count=p(this.count,this),this._countWithQueryUsingCallbacks=p(this._countWithQueryUsingCallbacks,this),this.countWithQuery=p(this.countWithQuery,this),this._executeQueryUsingCallbacks=p(this._executeQueryUsingCallbacks,this),this.executeQuery=p(this.executeQuery,this),this.acl=p(this.acl,this),this.createObjectWithID=p(this.createObjectWithID,this),this.createObjectWithType=p(this.createObjectWithType,this),this.createObject=p(this.createObject,this),this._getQualifiedBucketName=p(this._getQualifiedBucketName,this),this._setBucketName=p(this._setBucketName,this),this.getBucketName=p(this.getBucketName,this),this.getThing=p(this.getThing,this),this.getGroup=p(this.getGroup,this),this.getUser=p(this.getUser,this),!s._isNonEmptyString(t))throw l.InvalidArgumentException("Specified bucket name is null or empty.");this._bucketName=t,null!=e&&(e instanceof l.KiiGroup?this._group=e:e instanceof l.KiiUser?this._user=e:e instanceof l.KiiThing&&(this._thing=e))}return t.prototype._className="KiiBucket",t.prototype.getUser=function(){return this._user},t.prototype.getGroup=function(){return this._group},t.prototype.getThing=function(){return this._thing},t.prototype.getBucketName=function(){return this._bucketName},t.prototype._setBucketName=function(t){this._bucketName=t},t.prototype._getQualifiedBucketName=function(){return this._bucketName},t.prototype.createObject=function(){return l.KiiObject.objectWithBucket(this,null)},t.prototype.createObjectWithType=function(t){return l.KiiObject.objectWithBucket(this,t)},t.prototype.createObjectWithID=function(t){if(!l.KiiObject.isValidObjectID(t))throw l.InvalidArgumentException("Specified obejctID is invalid.");return l.KiiObject.objectWithID(this,t)},t.prototype.acl=function(){return l.KiiACL.aclWithParent(this)},t.prototype.executeQuery=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments)},failure:function(){return null!=e&&e.failure.apply(e,arguments),r(s._Error(arguments[1],i))}},i._executeQueryUsingCallbacks(t,o)}}(this))},t.prototype._executeQueryUsingCallbacks=function(t,e){var i,n,r,s,o;try{return s=this._generatePath()+"/query",i={},null!=t?i=t._dictValue():i.bucketQuery={clause:l.KiiQuery._emptyDictValue()},o=this._getRequest({path:s,withApp:!0}),o.setMethod("POST"),o.setContentType("application/vnd.kii.QueryRequest+json"),o.setData(i),r={success:function(i){return function(n,r){var s,o,u,a,h,c;if(300>r&&r>=200){for(u=[],c=n.results,a=0,h=c.length;h>a;a++)o=c[a],u.push(i.objectWithJSON(o));if(null!=n.nextPaginationKey?(s=new l.KiiQuery(t),s.setPaginationKey(n.nextPaginationKey)):s=null,null!=e)return e.success(t,u,s)}else if(null!=e)return e.failure(i,"Unable to parse response")}}(this),failure:function(t){return function(i,n){return null!=e?e.failure(t,i):void 0}}(this)},o.execute(r,!1)}catch(u){return n=u,e.failure(this,n)}},t.prototype.countWithQuery=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments)},failure:function(){return null!=e&&e.failure.apply(e,arguments),r(s._Error(arguments[1],i))}},i._countWithQueryUsingCallbacks(t,o)}}(this))},t.prototype._countWithQueryUsingCallbacks=function(t,e){var i,n,r,s;return r=this._generatePath()+"/query",i={},null!=t?i=t._dictValue():(i.bucketQuery={clause:l.KiiQuery._emptyDictValue()},t=l.KiiQuery.queryWithClause()),i.bucketQuery.aggregations=[{type:"COUNT",putAggregationInto:"count_field"}],s=this._getRequest({path:r,withApp:!0}),s.setMethod("POST"),s.setContentType("application/vnd.kii.QueryRequest+json"),s.setData(i),n={success:function(i){return function(n,r){var s;if(300>r&&r>=200){if(s=n.aggregations.count_field,null!=e)return e.success(i,t,s)}else if(null!=e)return e.failure(i,"Unable to parse response")}}(this),failure:function(t){return function(i,n){return null!=e?e.failure(t,i):void 0}}(this)},s.execute(n,!1)},t.prototype.count=function(t){var e;return e=l.KiiQuery.queryWithClause(),this.countWithQuery(e,t)},t.prototype["delete"]=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._deleteUsingCallbacks(r)}}(this))},t.prototype._deleteUsingCallbacks=function(t){var e,i;return i=this._getRequest({path:this._generatePath(),withApp:!0}),i.setMethod("DELETE"),e={success:function(e){return function(i,n){return null!=t?t.success(e):void 0}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},i.execute(e,!0)},t._bucketWithName=function(t,e){var i;return i=new l.KiiBucket(t,e)},t.prototype._getRequest=function(t){var e,n,r;return e=t.path,r=t.withApp,n=new i(e,r)},t.prototype._generatePath=function(){var t;return t=null!=this._user?"/users/"+this._user.getUUID()+"/buckets/"+this._getQualifiedBucketName():null!=this._group?"/groups/"+this._group.getUUID()+"/buckets/"+this._getQualifiedBucketName():null!=this._thing?"/things/"+this._thing.getThingID()+"/buckets/"+this._getQualifiedBucketName():"/buckets/"+this._getQualifiedBucketName()},t.prototype._getHttpUri=function(){return""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/"+this._generatePath()},t.prototype.objectWithJSON=function(t){var e;return e=this.createObject(),e._updateWithJSON(t),e},t}(),l.KiiEncryptedBucket=function(t){function e(t,i){if(this._getQualifiedBucketName=p(this._getQualifiedBucketName,this),!s._isNonEmptyString(t))throw l.InvalidArgumentException("Specified bucket name is null or empty.");l.KiiEncryptedBucket._isEncrypted(t)?e.__super__.constructor.call(this,t.replace("CRYPTO:",""),i):e.__super__.constructor.call(this,t,i)}return _(e,t),e.prototype._getQualifiedBucketName=function(){return"CRYPTO:"+this._bucketName},e._bucketWithName=function(t,e){var i;return i=new l.KiiEncryptedBucket(t,e)},e._isEncrypted=function(t){var e;return e=0===t.indexOf("CRYPTO:")},e}(l.KiiBucket),l.KiiEncryptedBucketWithToken=function(t){function e(t,i,n){this.acl=p(this.acl,this),this.createObjectWithID=p(this.createObjectWithID,this),this.createObjectWithType=p(this.createObjectWithType,this),this.createObject=p(this.createObject,this),this._getRequest=p(this._getRequest,this),e.__super__.constructor.call(this,t,i),this._authToken=n}return _(e,t),e.prototype._getRequest=function(t){var i;return i=e.__super__._getRequest.call(this,t),i.setAdminToken(this._authToken),i},e.prototype.createObject=function(){return l.KiiObjectWithToken.objectWithBucket(this,null,this._authToken)},e.prototype.createObjectWithType=function(t){return l.KiiObjectWithToken.objectWithBucket(this,t,this._authToken)},e.prototype.createObjectWithID=function(t){return l.KiiObjectWithToken.objectWithID(this,t,this._authToken)},e.prototype.acl=function(){var t;return t=new l.KiiACLWithToken(this,this._authToken)},e}(l.KiiEncryptedBucket),l.KiiBucketWithToken=function(t){function e(t,i,n){this.acl=p(this.acl,this),this.createObjectWithID=p(this.createObjectWithID,this),this.createObjectWithType=p(this.createObjectWithType,this),this.createObject=p(this.createObject,this),this._getRequest=p(this._getRequest,this),e.__super__.constructor.call(this,t,i),this._authToken=n}return _(e,t),e.prototype._getRequest=function(t){var i;return i=e.__super__._getRequest.call(this,t),i.setAdminToken(this._authToken),i},e.prototype.createObject=function(){return l.KiiObjectWithToken.objectWithBucket(this,null,this._authToken)},e.prototype.createObjectWithType=function(t){return l.KiiObjectWithToken.objectWithBucket(this,t,this._authToken)},e.prototype.createObjectWithID=function(t){return l.KiiObjectWithToken.objectWithID(this,t,this._authToken)},e.prototype.acl=function(){var t;return t=new l.KiiACLWithToken(this,this._authToken)},e}(l.KiiBucket),l.KiiGroup=function(){function t(){this._setAuthToken=p(this._setAuthToken,this),this._getHttpURI=p(this._getHttpURI,this),this._listTopicsUsingCallbacks=p(this._listTopicsUsingCallbacks,this),this.listTopics=p(this.listTopics,this),this.topicWithName=p(this.topicWithName,this),this._setOwnerFromContext=p(this._setOwnerFromContext,this),this._userWithID=p(this._userWithID,this),this._getRequest=p(this._getRequest,this),this._updateWithJSON=p(this._updateWithJSON,this),this._getOwnerUsingCallbacks=p(this._getOwnerUsingCallbacks,this),this.getOwner=p(this.getOwner,this),this._deleteUsingCallbacks=p(this._deleteUsingCallbacks,this),this["delete"]=p(this["delete"],this),this._refreshUsingCallbacks=p(this._refreshUsingCallbacks,this),this.refresh=p(this.refresh,this),this._saveWithOwnerUsingCallbacks=p(this._saveWithOwnerUsingCallbacks,this),this.saveWithOwner=p(this.saveWithOwner,this),this._saveUsingCallbacks=p(this._saveUsingCallbacks,this),this.save=p(this.save,this),this._changeGroupNameUsingCallbacks=p(this._changeGroupNameUsingCallbacks,this),this.changeGroupName=p(this.changeGroupName,this),this._changeOwner=p(this._changeOwner,this),this._saveMembers=p(this._saveMembers,this),this._getMemberListUsingCallbacks=p(this._getMemberListUsingCallbacks,this),this.getMemberList=p(this.getMemberList,this),this._removeMember=p(this._removeMember,this),this._addMember=p(this._addMember,this),this.removeUser=p(this.removeUser,this),this.addUser=p(this.addUser,this),this.encryptedBucketWithName=p(this.encryptedBucketWithName,this),this.bucketWithName=p(this.bucketWithName,this),this.objectURI=p(this.objectURI,this),this._setOwner=p(this._setOwner,this),this.getCachedOwner=p(this.getCachedOwner,this),this._setName=p(this._setName,this),this.getName=p(this.getName,this),this.getID=p(this.getID,this),this._setUUID=p(this._setUUID,this),this.getUUID=p(this.getUUID,this),this._setAddMembers=p(this._setAddMembers,this),this._getRemoveMembers=p(this._getRemoveMembers,this),this._getAddMembers=p(this._getAddMembers,this),this._addMembers={},this._removeMembers={}}return t.prototype._getAddMembers=function(){return this._addMembers},t.prototype._getRemoveMembers=function(){return this._removeMembers},t.prototype._setAddMembers=function(t){var e,i,n,r;if(null!=t){for(r=[],i=0,n=t.length;n>i;i++)e=t[i],r.push(this.addUser(e));return r}},t.prototype.getUUID=function(){return this._uuid},t.prototype._setUUID=function(t){this._uuid=t},t.prototype.getID=function(){return this._uuid},t.prototype.getName=function(){return this._groupName},t.prototype._setName=function(t){this._groupName=t},t.prototype.getCachedOwner=function(){return this._owner},t.prototype._setOwner=function(t){this._owner=t},t.prototype.objectURI=function(){return null!=this._uuid?"kiicloud://groups/"+this._uuid:null},t.registerGroupWithID=function(e,i,n,r){return new Promise(function(o,u){var a,h,c;return a={success:function(){return null!=r&&r.success.apply(r,arguments),o(arguments[0])},failure:function(){var t;return null!=r&&r.failure.apply(r,arguments),t=s._Error(arguments[1],arguments[0]),t.addMembersArray=arguments[2],t.removeMembersArray=arguments[3],u(t)}},t._registerGroupWithIDUsingCallbacks(null!=(h=l.KiiUser.getCurrentUser())?h.getAccessToken():void 0,e,i,null!=(c=l.Kii.getCurrentUser())?c.getID():void 0,n,a)})},t._registerGroupWithIDUsingCallbacks=function(e,i,n,r,o,a){var h,c,p,f,_,g,d,y,m,k;if(!s._isNonEmptyString(i))return void a.failure(null,"groupID is null or empty",o,null);if(!s._validateGroupID(i))return void a.failure(null,"invalid groupID : "+i,o,null);if(!s._isNonEmptyString(n))return void a.failure(null,"groupName is null or empty",o,null);if(null==r)return void a.failure(null,"owner is null",o,null);if(g=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/groups/"+i,d=u.createXHRWrapper("PUT",g),y=d.xhr,d.setKiiHeaders(),d.setAuthToken(e),d.setContentType("application/vnd.kii.GroupCreationRequest+json"),h={},h.name=n,h.owner=r,null!=o&&o.length>0){for(f=[],c=m=0,k=o.length;k>m;c=++m)p=o[c],f.push(p.getID());h.members=f}return _={success:function(){var e;try{return e=t.groupWithNameAndMembers(n,o),e._setUUID(i),a.success(e)}catch(r){return a.failure(null,d.getErrorString("failed to register group."))}},failure:function(){var t;return t=d.getErrorString("failed to register group."),a.failure(null,t,o,null)}},d.sendData(JSON.stringify(h),_)},t.prototype.bucketWithName=function(t){var e;return e=new l.KiiBucket(t,this)},t.prototype.encryptedBucketWithName=function(t){var e;return e=new l.KiiEncryptedBucket(t,this)},t.prototype.addUser=function(t){var e;return null==t?void l.Kii.logger("Passed member is null"):null==t.getUUID()?void l.Kii.logger("Passed member ID is null"):(e=t.getUUID(),e in this._addMembers||(this._addMembers[e]=t),e in this._removeMembers?delete this._removeMembers[e]:void 0)},t.prototype.removeUser=function(t){var e;return null==t?void l.Kii.logger("Passed member is null"):null==t.getUUID()?void l.Kii.logger("Passed member uuid is null"):(e=t.getUUID(),e in this._removeMembers||(this._removeMembers[e]=t),e in this._addMembers?delete this._addMembers[e]:void 0)},t.prototype._addMember=function(t,e){var i,n;return l.Kii.logger("Adding member "+t.getUUID()+" to group "+this._groupName),n=this._getRequest({path:"/groups/"+this._uuid+"/members/"+t.getUUID(),withApp:!0}),n.setMethod("PUT"),i={success:function(i){return function(n,r){return delete i._addMembers[t.getUUID()],i._saveMembers(e)}}(this),failure:function(i){return function(n,r){var s,o,u;return s=function(){var e,i;e=this._addMembers,i=[];for(u in e)t=e[u],i.push(t);return i}.call(i),o=function(){var e,i;e=this._removeMembers,i=[];for(u in e)t=e[u],i.push(t);return i}.call(i),e.failure(i,n,s,o)}}(this)},n.execute(i,!1)},t.prototype._removeMember=function(t,e){var i,n;return l.Kii.logger("Removing member "+t.getUUID()+" to group "+this._groupName),n=this._getRequest({path:"/groups/"+this._uuid+"/members/"+t.getUUID(),withApp:!0}),n.setMethod("DELETE"),i={success:function(i){return function(n,r){return delete i._getRemoveMembers()[t.getUUID()],i._saveMembers(e)}}(this),failure:function(i){return function(n,r){var s,o,u;return s=function(){var e,i;e=this._addMembers,i=[];for(u in e)t=e[u],i.push(t);return i}.call(i),o=function(){var e,i;e=this._removeMembers,i=[];for(u in e)t=e[u],i.push(t);return i}.call(i),e.failure(i,n,s,o)}}(this)},n.execute(i,!1)},t.prototype.getMemberList=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments)},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._getMemberListUsingCallbacks(r)}}(this))},t.prototype._getMemberListUsingCallbacks=function(t){var e,i;
return l.Kii.logger("Getting member list for group "+this._groupName),i=this._getRequest({path:"/groups/"+this._uuid+"/members",withApp:!0}),i.setAccept("application/vnd.kii.MembersRetrievalResponse+json"),e={success:function(e){return function(i,n){var r,s,o,u,a;if(300>n&&n>=200){for(s=[],o=i.members,u=0,a=o.length;a>u;u++)r=o[u],s.push(e._userWithID(r.userID));if(null!=t)return t.success(e,s)}else if(null!=t)return t.failure(e,"Unable to get member list of group")}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},i.execute(e,!1)},t.prototype._saveMembers=function(t){var e,i;return e=Object.keys(this._addMembers),i=Object.keys(this._removeMembers),0===e.length&&0===i.length&&t.success(this),e.length>0?void this._addMember(this._addMembers[e[0]],t):void(i.length>0&&this._removeMember(this._removeMembers[i[0]],t))},t.prototype._changeOwner=function(t,e){var i,n,r;return n=this._getRequest({path:"/groups/"+this._uuid+"/owner",withApp:!0}),n.setContentType("application/vnd.kii.GroupOwnerChangeRequest+json"),n.setMethod("PUT"),i={},i.owner=t,n.setData(i),r={success:function(t){return function(i,n){return 300>n&&n>=200?e.success(t):void 0}}(this),failure:function(t){return function(i,n){return null!=e?e.failure(t,i):void 0}}(this)},n.execute(r,!1)},t.prototype.changeGroupName=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments[0])},failure:function(){return null!=e&&e.failure.apply(e,arguments),r(s._Error(arguments[1],i))}},i._changeGroupNameUsingCallbacks(t,o)}}(this))},t.prototype._changeGroupNameUsingCallbacks=function(t,e){var i,n;return l.Kii.logger("Saving group: "+this.name),null!=this._uuid?(i=this._getRequest({path:"/groups/"+this._uuid+"/name",withApp:!0}),i.setContentType("text/plain"),i.setMethod("PUT"),i.setData(t),n={success:function(i){return function(n,r){if(300>r&&r>=200){if(i._setName(t),null!=e)return e.success(i)}else if(null!=e)return e.failure(i,"Unable to change group name - invalid response")}}(this),failure:function(t){return function(i,n){return null!=e?e.failure(t,i):void 0}}(this)},i.execute(n,!0)):e.failure(this,"Invalid group. Save the group on the server before updating the name.")},t.prototype.save=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){var i;return null!=t&&t.failure.apply(t,arguments),i=s._Error(arguments[1],e),i.addMembersArray=arguments[2],i.removeMembersArray=arguments[3],n(i)}},e._saveUsingCallbacks(r)}}(this))},t.prototype._saveUsingCallbacks=function(t){var e,i,n;return l.Kii.logger("Saving group: "+this.name),null==this._uuid?(i=this._getRequest({path:"/groups",withApp:!0}),i.setContentType("application/vnd.kii.GroupCreationRequest+json"),i.setMethod("POST"),e={},null!=this._groupName&&(e.name=this._groupName),this._setOwnerFromContext(e),i.setData(e),n={success:function(e){return function(i,n){return 300>n&&n>=200?(e._setUUID(i.groupID),e._saveMembers(t)):void 0}}(this),failure:function(e){return function(i,n){var r,s,o,u;return null!=t?(r=function(){var t,e;t=this._addMembers,e=[];for(u in t)s=t[u],e.push(s);return e}.call(e),o=function(){var t,e;t=this._removeMembers,e=[];for(u in t)s=t[u],e.push(s);return e}.call(e),t.failure(e,i,r,o)):void 0}}(this)},i.execute(n,!1)):this._saveMembers(t)},t.prototype.saveWithOwner=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments[0])},failure:function(){var t;return null!=e&&e.failure.apply(e,arguments),t=s._Error(arguments[1],i),t.addMembersArray=arguments[2],t.removeMembersArray=arguments[3],r(t)}},i._saveWithOwnerUsingCallbacks(t,o)}}(this))},t.prototype._saveWithOwnerUsingCallbacks=function(t,e){var i,n,r,s;return null==this._uuid?(n=this._getRequest({path:"/groups",withApp:!0}),n.setContentType("application/vnd.kii.GroupCreationRequest+json"),n.setMethod("POST"),i={},null!=this._groupName&&(i.name=this._groupName),i.owner=t,n.setData(i),r={success:function(t){return function(i,n){return 300>n&&n>=200?(t._setUUID(i.groupID),t._saveMembers(e)):void 0}}(this),failure:function(t){return function(i,n){var r,s,o,u;return null!=e?(r=function(){var t,e;t=this._addMembers,e=[];for(u in t)s=t[u],e.push(s);return e}.call(t),o=function(){var t,e;t=this._removeMembers,e=[];for(u in t)s=t[u],e.push(s);return e}.call(t),e.failure(t,i,r,o)):void 0}}(this)},n.execute(r,!1)):(s={success:function(i){return function(n){return i._changeOwner(t,e)}}(this),failure:function(t){return function(i,n){var r,s,o,u;return r=function(){var t,e;t=this._addMembers,e=[];for(u in t)s=t[u],e.push(s);return e}.call(t),o=function(){var t,e;t=this._removeMembers,e=[];for(u in t)s=t[u],e.push(s);return e}.call(t),e.failure(t,n,r,o)}}(this)},this._saveMembers(s))},t.prototype.refresh=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._refreshUsingCallbacks(r)}}(this))},t.prototype._refreshUsingCallbacks=function(t){var e,i;return l.Kii.logger("Refreshing group: "+this._groupName),i=new this._getRequest({path:"/groups/"+this._uuid,withApp:!0}),i.setAccept("application/vnd.kii.GroupRetrievalResponse+json"),e={success:function(e){return function(i,n){return e._updateWithJSON(i),null!=t?t.success(e):void 0}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},i.execute(e,!1)},t.prototype["delete"]=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._deleteUsingCallbacks(r)}}(this))},t.prototype._deleteUsingCallbacks=function(t){var e,i;return l.Kii.logger("Deleting group: "+this._groupName),i=this._getRequest({path:"/groups/"+this._uuid,withApp:!0}),i.setMethod("DELETE"),e={success:function(e){return function(i,n){return 300>n&&n>=200&&null!=t?t.success(e):null!=t?t.failure(e,"Unable to parse response"):void 0}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},i.execute(e,!0)},t.prototype.getOwner=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments)},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._getOwnerUsingCallbacks(r)}}(this))},t.prototype._getOwnerUsingCallbacks=function(t){return l.Kii.logger("Getting owner of group "+this._groupName),this.refresh({success:function(e){return function(e){return null!=t?t.success(e,e.getCachedOwner()):void 0}}(this),failure:function(e){return function(e,i){return null!=t?t.failure(e,i):void 0}}(this)})},t.groupWithName=function(t){return l.KiiGroup.groupWithNameAndMembers(t,null)},t.groupWithNameAndMembers=function(t,e){var i;return i=new l.KiiGroup,i._setName(t),i._setAddMembers(e),i},t.groupWithID=function(t){var e;if(null==t||""===t)throw new l.InvalidArgumentException("groupID should not null or empty");return e=new l.KiiGroup,e._setUUID(t),e},t.groupWithURI=function(t){var e,i,n,r;if(n=null,r=t.substr("kiicloud://".length),i=r.split("/"),e=i.length,!(e>0))throw new l.InvalidURIException;return n=new l.KiiGroup,n._setUUID(i[e-1]),n},t._groupWithJSON=function(t){var e;return e=new l.KiiGroup,null!=t.groupID&&e._setUUID(t.groupID),null!=t.name&&e._setName(t.name),null!=t.owner&&e._setOwner(l.KiiUser.userWithID(t.owner)),e},t.prototype._updateWithJSON=function(t){return null!=t.groupID&&this._setUUID(t.groupID),null!=t.name?this._setName(t.name):this._setName(null),null!=t.owner?this._setOwner(this._userWithID(t.owner)):this._setOwner(null)},t.prototype._getRequest=function(t){var e,n,r;return e=t.path,r=t.withApp,n=new i(e,r)},t.prototype._userWithID=function(t){var e;return e=l.KiiUser.userWithID(t)},t.prototype._setOwnerFromContext=function(t){return null!=l.Kii.getCurrentUser()?(this._owner=l.Kii.getCurrentUser(),t.owner=this._owner.getUUID()):void 0},t.prototype.topicWithName=function(t){var e,i;if("string"!=typeof t||""===t)throw new l.InvalidArgumentException("topicName should not null or empty");if(e=this.getID(),!e)throw"can not instantiate topic from instance which doesn't have ID";return i=this._getHttpURI(),new l.KiiTopic(i,t)},t.prototype.listTopics=function(t,e){return new Promise(function(i){return function(n,r){var s;return s={success:function(){return null!=t&&t.success.apply(t,arguments),n(arguments)},failure:function(){return null!=t&&t.failure.apply(t,arguments),r(arguments[0])}},i._listTopicsUsingCallbacks(s,e)}}(this))},t.prototype._listTopicsUsingCallbacks=function(t,e){var i,n,r;return n=""+this._getHttpURI()+"/topics","string"==typeof e&&""!==e&&(n=n+"?paginationKey="+encodeURIComponent(e)),r=u.createXHRWrapper("GET",n),r.setKiiHeaders(),this._setAuthToken(r),i={success:function(e){return function(){var i,n,s,o,u,a;for(i=JSON.parse(r.xhr.responseText),s=[],a=i.topics,o=0,u=a.length;u>o;o++)n=a[o],s.push(e.topicWithName(n.topicID));return null!=t?t.success(s,void 0===i.paginationKey?null:i.paginationKey):void 0}}(this),failure:function(e){return function(){var i,n;return n=r.getErrorString("list topics"),i=s._Error(n,e),null!=t?t.failure(i):void 0}}(this)},r.send(i)},t.prototype._getHttpURI=function(){return""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/groups/"+this.getID()},t.prototype._setAuthToken=function(t){return t.setCurrentUserToken()},t}(),l.KiiObject=function(){function t(){this._deleteBodyUsingCallbacks=p(this._deleteBodyUsingCallbacks,this),this.deleteBody=p(this.deleteBody,this),this._publishBodyExpiresInUsingCallbacks=p(this._publishBodyExpiresInUsingCallbacks,this),this.publishBodyExpiresIn=p(this.publishBodyExpiresIn,this),this._publishBodyExpiresAtUsingCallbacks=p(this._publishBodyExpiresAtUsingCallbacks,this),this.publishBodyExpiresAt=p(this.publishBodyExpiresAt,this),this._publishBodyUsingCallbacks=p(this._publishBodyUsingCallbacks,this),this.publishBody=p(this.publishBody,this),this._downloadBodyUsingCallbacks=p(this._downloadBodyUsingCallbacks,this),this.downloadBody=p(this.downloadBody,this),this._uploadBodyUsingCallbacks=p(this._uploadBodyUsingCallbacks,this),this.uploadBody=p(this.uploadBody,this),this._moveBodyUsingCallbacks=p(this._moveBodyUsingCallbacks,this),this.moveBody=p(this.moveBody,this),this._parseObjectUri=p(this._parseObjectUri,this),this._userWithID=p(this._userWithID,this),this._setAuthorizationHeader=p(this._setAuthorizationHeader,this),this._getToken=p(this._getToken,this),this._getRequest=p(this._getRequest,this),this._setETag=p(this._setETag,this),this._deleteUsingCallbacks=p(this._deleteUsingCallbacks,this),this["delete"]=p(this["delete"],this),this._refreshUsingCallbacks=p(this._refreshUsingCallbacks,this),this.refresh=p(this.refresh,this),this._saveUsingCallbacks=p(this._saveUsingCallbacks,this),this.save=p(this.save,this),this._saveAllFieldsUsingCallbacks=p(this._saveAllFieldsUsingCallbacks,this),this.saveAllFields=p(this.saveAllFields,this),this._performUpdate=p(this._performUpdate,this),this._performSave=p(this._performSave,this),this._updateWithJSON=p(this._updateWithJSON,this),this._convertToObjectType=p(this._convertToObjectType,this),this.objectURI=p(this.objectURI,this),this.objectACL=p(this.objectACL,this),this.getGeoPoint=p(this.getGeoPoint,this),this.setGeoPoint=p(this.setGeoPoint,this),this.remove=p(this.remove,this),this.getKeys=p(this.getKeys,this),this.get=p(this.get,this),this.set=p(this.set,this),this._getPath=p(this._getPath,this),this._setBodyContentType=p(this._setBodyContentType,this),this.getBodyContentType=p(this.getBodyContentType,this),this._setBucket=p(this._setBucket,this),this.getBucket=p(this.getBucket,this),this._setObjectType=p(this._setObjectType,this),this.getObjectType=p(this.getObjectType,this),this._setModified=p(this._setModified,this),this.getModified=p(this.getModified,this),this._setCreated=p(this._setCreated,this),this.getCreated=p(this.getCreated,this),this.getID=p(this.getID,this),this._setUUID=p(this._setUUID,this),this.getUUID=p(this.getUUID,this),this._customInfo={},this._alteredFields=[]}return t.prototype.getUUID=function(){return this._uuid},t.prototype._setUUID=function(t){this._uuid=t},t.prototype.getID=function(){return this._uuid},t.prototype.getCreated=function(){return this._created},t.prototype._setCreated=function(t){this._created=t},t.prototype.getModified=function(){return this._modified},t.prototype._setModified=function(t){this._modified=t},t.prototype.getObjectType=function(){return this._objectType},t.prototype._setObjectType=function(t){this._objectType=t},t.prototype.getBucket=function(){return l.Kii.logger("GEtting bucket "+this._bucket),this._bucket},t.prototype._setBucket=function(t){this._bucket=t},t.prototype.getBodyContentType=function(){return this._bodyContentType},t.prototype._setBodyContentType=function(t){this._bodyContentType=t},t.prototype._getPath=function(){var t;return t=null!=this._bucket.getUser()?"/users/"+this._bucket.getUser().getUUID()+"/buckets/"+this._bucket._getQualifiedBucketName()+"/objects/":null!=this._bucket.getGroup()?"/groups/"+this._bucket.getGroup().getUUID()+"/buckets/"+this._bucket._getQualifiedBucketName()+"/objects/":null!=this._bucket.getThing()?"/things/"+this._bucket.getThing().getThingID()+"/buckets/"+this._bucket._getQualifiedBucketName()+"/objects/":"/buckets/"+this._bucket._getQualifiedBucketName()+"/objects/",null!=this._uuid&&(t+=this._uuid),t},t.prototype.set=function(t,e){return s._isNonEmptyString(t)&&0!==t.indexOf("_")?(this._customInfo[t]=e,this._alteredFields.push(t)):void l.Kii.logger("[WARN] Reserved key is used for custom field. key="+t)},t.prototype.get=function(t){return this._customInfo[t]},t.prototype.getKeys=function(){var t,e;e=[];for(t in this._customInfo)e.push(t);return e},t.prototype.remove=function(t){var e;return delete this._customInfo[t],e=this._alteredFields.indexOf(t),e>=0?this._alteredFields.splice(e,1):void 0},t.prototype.setGeoPoint=function(t,e){if(!(e instanceof l.KiiGeoPoint))throw l.InvalidArgumentException("Specified kiiGeoPoint is not an instance of KiiGeoPoint");return this._customInfo[t]=e._toDict(),this._alteredFields.push(t)},t.prototype.getGeoPoint=function(t){var e,i,n;return n=this._customInfo[t],e=n.lat,i=n.lon,l.KiiGeoPoint.geoPoint(e,i)},t.prototype.objectACL=function(){return l.KiiACL.aclWithParent(this)},t.prototype.objectURI=function(){var t,e;return t="kiicloud://",null!=this._bucket&&null!=this._uuid&&(e=t,null!=this._bucket.getGroup()?e+="groups/"+this._bucket.getGroup().getUUID()+"/":null!=this._bucket.getUser()?e+="users/"+this._bucket.getUser().getUUID()+"/":null!=this._bucket.getThing()&&(e+="things/"+this._bucket.getThing().getThingID()+"/"),e+="buckets/"+this._bucket._getQualifiedBucketName()+"/objects/"+this._uuid),e},t.prototype._convertToObjectType=function(t){var e;return"application/json"===t?{success:!0,type:null}:(e=t.match(RegExp("$application/vnd\\."+l.Kii.getAppID()+"\\.([^\\.])+\\+json")),null!=e?{success:!0,type:e}:{success:!1,type:null})},t.prototype._updateWithJSON=function(t,e){var i,n,r;e||(this._customInfo={}),r=[];for(i in t)n=t[i],"_id"===i?null==this._uuid?(l.Kii.logger("Setting uuid: "+n),r.push(this._uuid=n)):r.push(void 0):"_created"===i?r.push(this._created=n):"_modified"===i?r.push(this._modified=n):"_owner"===i?r.push(this._owner=this._userWithID(n)):"_dataType"===i?r.push(this._objectType=n):"_calculated"===i?r.push(this._customInfo[i]=n):"_"!==i[0]?r.push(this._customInfo[i]=n):"_version"===i?r.push(this._etag=n):r.push(void 0);return r},t.prototype._performSave=function(t){var e,i,n,r;return i=this._getPath(),i=i.slice(0,+(i.length-2)+1||9e9),n=new this._getRequest({path:i,withApp:!0}),n.setMethod("POST"),e=this._customInfo,n.setData(e),null!=this._objectType&&n.setContentType("application/vnd."+l.Kii.getAppID()+"."+this._objectType+"+json"),r={success:function(e){return function(i,n,r){var s;if(300>n&&n>=200){if(e._etag=r.etag,null==i.objectID)return t.failure(e,"No objectID response");if(e._uuid=i.objectID,null!=i.createdAt&&(e._created=i.createdAt),null!=i.dataType&&(s=e._convertToObjectType(i.dataType),s.success&&(e._objectType=s.type)),e._modified=e._created,e._alteredFields=[],null!=t)return t.success(e)}else if(null!=t)return t.failure(e,"Unable to parse response")}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},n.execute(r,!1)},t.prototype._performUpdate=function(t,e,i){var n,r,s,o,u,a,h,c,p;if(o=this._getPath(),u=new this._getRequest({path:o,withApp:!0}),n={},t)for(u.addHeader("X-HTTP-Method-Override","PATCH"),u.setMethod("POST"),p=this._alteredFields,h=0,c=p.length;c>h;h++)s=p[h],n[s]=this._customInfo[s];else u.setMethod("PUT"),n=this._customInfo;if(u.setData(n),r=this._created>0,!i)if(r){if(null==this._etag)return void e.failure(this,"IllegalState! Call KiiObject#refresh() prior call this method.");u.addHeader("If-Match",this._etag)}else{if(t&&null==this._etag)return void e.failure(this,"IllegalState! Call KiiObject#refresh() prior call this method.");u.addHeader("If-None-Match","*")}return null!=this._objectType&&u.setContentType("application/vnd."+l.Kii.getAppID()+"."+this._objectType+"+json"),a={success:function(i){return function(n,r,s){if(300>r&&r>=200){if(i._etag=s.etag,t?i._updateWithJSON(n,!0):(null!=n.createdAt&&(i._created=n.createdAt),null!=n.modifiedAt&&(i._modified=n.modifiedAt)),i._alteredFields=[],null!=e)return e.success(i)}else if(null!=e)return e.failure(i,"Unable to parse response")}}(this),failure:function(t){return function(i,n){return null!=e?e.failure(t,i):void 0}}(this)},u.execute(a,!1)},t.prototype.saveAllFields=function(t,e){return null==e&&(e=!0),new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=t&&t.success.apply(t,arguments),n(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),r(s._Error(arguments[1],i))}},i._saveAllFieldsUsingCallbacks(o,e)}}(this))},t.prototype._saveAllFieldsUsingCallbacks=function(t,e){return null==e&&(e=!0),null!=this._uuid?this._performUpdate(!1,t,e):this._performSave(t)},t.prototype.save=function(t,e){return null==e&&(e=!0),new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=t&&t.success.apply(t,arguments),n(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),r(s._Error(arguments[1],i))}},i._saveUsingCallbacks(o,e)}}(this))},t.prototype._saveUsingCallbacks=function(t,e){return null==e&&(e=!0),null!=this._uuid?this._performUpdate(!0,t,e):this._performSave(t)},t.prototype.refresh=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._refreshUsingCallbacks(r)}}(this))},t.prototype._refreshUsingCallbacks=function(t){var e,i,n;return e=this._getPath(),n=new this._getRequest({path:e,withApp:!0}),i={success:function(e){return function(i,n,r){if(300>n&&n>=200){if(e._etag=r.etag,e._updateWithJSON(i,!1),null!=t)return t.success(e)}else if(null!=t)return t.failure(e,"Unable to parse response")}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},n.execute(i,!1)},t.prototype["delete"]=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._deleteUsingCallbacks(r)}}(this))},t.prototype._deleteUsingCallbacks=function(t){var e,i,n;return e=this._getPath(),n=new this._getRequest({path:e,withApp:!0}),n.setMethod("DELETE"),i={success:function(e){return function(i,n){return 300>n&&n>=200&&null!=t?t.success(e):null!=t?t.failure(e,"Unable to parse response"):void 0}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},n.execute(i,!0)},t.objectWithBucket=function(t,e){var i;return l.Kii.logger("Creating object w type: "+e),i=new l.KiiObject,i._setBucket(t),i._setObjectType(e),l.Kii.logger(i),i},t.objectWithID=function(t,e){var i;return l.Kii.logger("Creating object with id: "+e),i=new l.KiiObject,i._setBucket(t),i._setUUID(e),l.Kii.logger(i),i},t.prototype._setETag=function(t){this._etag=t},t.objectWithURI=function(t){var e,i,n,r,s,o,u,a;if(o=t.substr("kiicloud://".length),s=o.split("/"),r=s.length,l.Kii.logger(s),!(r>=4))throw new l.InvalidURIException;return i=4===r?1:3,n=s[i],a=null,"groups"===s[0]?a=new l.KiiGroup.groupWithID(s[1]):"users"===s[0]?a=l.KiiUser.userWithID(s[1]):"things"===s[0]&&(a=l.KiiThing.thingWithID(s[1])),e=null,e=l.KiiEncryptedBucket._isEncrypted(n)?new l.KiiEncryptedBucket._bucketWithName(n,a):new l.KiiBucket._bucketWithName(n,a),l.Kii.logger(e),u=e.createObject(),u._setUUID(s[r-1]),l.Kii.logger(u),u},t.prototype._getRequest=function(t){var e,n,r;return e=t.path,r=t.withApp,n=new i(e,r)},t.prototype._getToken=function(){var t,e;return t=l.KiiUser.getCurrentUser(),e=t?t.getAccessToken():null,e?e:null},t.prototype._setAuthorizationHeader=function(t){var e;return e=this._getToken(),e?t.setRequestHeader("Authorization","Bearer "+e):void 0},t.prototype._userWithID=function(t){var e;return e=l.KiiUser.userWithID(t)},t.prototype._parseObjectUri=function(t){var e,i,n,r;if(n=t.replace(/^kiicloud:\/\//g,"").split("/"),r=n[0],"users"===r)i={appID:l.Kii.getAppID(),userID:n[1],type:"APP_AND_USER"},e=l.KiiEncryptedBucket._isEncrypted(n[3])?{targetObjectScope:i,targetBucketType:"crypto",targetBucketID:n[3].replace("CRYPTO:",""),targetObjectID:n[5]}:{targetObjectScope:i,targetBucketID:n[3],targetObjectID:n[5]};else if("groups"===r)i={appID:l.Kii.getAppID(),groupID:n[1],type:"APP_AND_GROUP"},e=l.KiiEncryptedBucket._isEncrypted(n[3])?{targetObjectScope:i,targetBucketType:"crypto",targetBucketID:n[3].replace("CRYPTO:",""),targetObjectID:n[5]}:{targetObjectScope:i,targetBucketID:n[3],targetObjectID:n[5]};else{if("things"===r)throw new l.InvalidURIException;i={appID:l.Kii.getAppID(),type:"APP"},e=l.KiiEncryptedBucket._isEncrypted(n[1])?{targetObjectScope:i,targetBucketType:"crypto",targetBucketID:n[1].replace("CRYPTO:",""),targetObjectID:n[3]}:{targetObjectScope:i,targetBucketID:n[1],targetObjectID:n[3]}}return e},t.prototype.moveBody=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments)},failure:function(){var t;return null!=e&&e.failure.apply(e,arguments),t=s._Error(arguments[2],i),t.targetObjectUri=arguments[1],r(t)}},i._moveBodyUsingCallbacks(t,o)}}(this))},t.prototype._moveBodyUsingCallbacks=function(t,e){var i,n,r,s;if(null==t)return e.failure(this,null,l.InvalidArgumentException("targetObjectUri is required"));if(null==this.getUUID())return e.failure(this,t,l.InvalidArgumentException("Source object is not saved on the cloud"));r=this._getPath()+"/body/move",s=new this._getRequest({path:r,withApp:!0}),s.setMethod("POST"),s.setContentType("application/vnd.kii.ObjectBodyMoveRequest+json");try{s.setData(this._parseObjectUri(t))}catch(o){return i=o,e.failure(this,t,"Not support to move body of thing scope object.")}return n={success:function(i){return function(n,r){return 300>r&&r>=200&&null!=e?e.success(i,t):null!=e?e.failure(i,t,"Unable to parse response"):void 0}}(this),failure:function(i){return function(n,r){return null!=e?e.failure(i,t,n):void 0}}(this)},s.execute(n,!0)},t.prototype.uploadBody=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){var t;return null!=e&&null!=(t=e.success)&&t.apply(e,arguments),n(arguments[0])},failure:function(){var t;return null!=e&&null!=(t=e.failure)&&t.apply(e,arguments),r(s._Error(arguments[1],i))},progress:function(){var t;return null!=e&&null!=(t=e.progress)?t.apply(e,arguments):void 0}},i._uploadBodyUsingCallbacks(t,o)}}(this))},t.prototype._uploadBodyUsingCallbacks=function(t,e){var i,n,r,s,o;return t&&t instanceof Blob?(r=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+this._getPath()+"/body",i="application/octet-stream",t.type&&(i=t.type),s=u.createXHRWrapper("PUT",r),o=s.xhr,o.setRequestHeader("Content-Type",i),o.setRequestHeader("x-kii-appid",l.Kii.getAppID()),o.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),o.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),this._setAuthorizationHeader(o),n={success:function(t){return function(){var n;return n=JSON.parse(o.responseText),null!=n.modifiedAt&&(t._modified=n.modifiedAt),t._setBodyContentType(i),null!=e?e.success(t):void 0}}(this),failure:function(t){return function(){var i,n;if(i="failed to upload body. statusCode: "+o.status,null!=e)try{if(n=JSON.parse(decodeURIComponent(o.responseText)),null!=n.errorCode&&(i+=" error code: "+n.errorCode),null!=n.message)return i+=" message: "+n.message}catch(r){}finally{l.Kii.logger("Failure: "+i),l.Kii.logger(o.responseText),e.failure(t,i)}}}(this),progress:function(t){return function(t){return e&&e.progress?e.progress(t):void 0}}(this)},s.sendData(t,n)):void e.failure(this,"Invalid parameter")},t.prototype.downloadBody=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){var e;return null!=t&&null!=(e=t.success)&&e.apply(t,arguments),i(arguments)},failure:function(){var i;return null!=t&&null!=(i=t.failure)&&i.apply(t,arguments),n(s._Error(arguments[1],e))},progress:function(){var e;return null!=t&&null!=(e=t.progress)?e.apply(t,arguments):void 0}},e._downloadBodyUsingCallbacks(r)}}(this))},t.prototype._downloadBodyUsingCallbacks=function(t){var e,i,n,r;return i=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+this._getPath()+"/body",n=u.createXHRWrapper("GET",i),r=n.xhr,r.setRequestHeader("x-kii-appid",l.Kii.getAppID()),r.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),r.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),this._setAuthorizationHeader(r),r.responseType="blob",e={success:function(e){return function(){var i;return i=r.status,e._setBodyContentType(r.getResponseHeader("content-type")),null!=t?t.success(e,r.response):void 0}}(this),failure:function(e){return function(){var i,n,s,o;return null!=t?(i="failed to download body. statusCode: "+r.status,n=new FileReader,o=null,s=e,n.onload=function(){var e;o=this.result;try{if(e=JSON.parse(decodeURIComponent(o)),null!=e.errorCode&&(i+=" error code: "+e.errorCode),null!=e.message)return i+=" message: "+e.message}catch(n){}finally{l.Kii.logger("Failure: "+i),l.Kii.logger(r.response),t.failure(s,i)}},n.readAsText(r.response)):void 0}}(this),progress:function(e){return function(e){return t&&t.progress?t.progress(e):void 0}}(this)},n.send(e)},t.prototype.publishBody=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments)},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._publishBodyUsingCallbacks(r)}}(this))},t.prototype._publishBodyUsingCallbacks=function(t){var e,i,n,r,s,o;return r=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+this._getPath()+"/body/publish",s=u.createXHRWrapper("POST",r),o=s.xhr,o.setRequestHeader("x-kii-appid",l.Kii.getAppID()),o.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),o.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),o.setRequestHeader("Content-Type","application/vnd.kii.ObjectBodyPublicationRequest+json"),this._setAuthorizationHeader(o),n={success:function(e){return function(){var i;if(null!=t)try{return i=JSON.parse(o.responseText),i.url?t.success(e,i.url):t.failure(e,"failed to parse response")}catch(n){return t.failure(e,"failed to parse response")}}}(this),failure:function(e){return function(){var i,n;if(null!=t){i="failed to publish body. statusCode: "+o.status;try{if(n=JSON.parse(o.responseText),null!=n.errorCode&&(i+=" error code: "+n.errorCode),null!=n.message)return i+=" error message: "+n.message}catch(r){}finally{t.failure(e,i)}}}}(this)},i={},e=JSON.stringify(i),s.sendData(e,n)},t.prototype.publishBodyExpiresAt=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments)},failure:function(){return null!=e&&e.failure.apply(e,arguments),r(s._Error(arguments[1],i))}},i._publishBodyExpiresAtUsingCallbacks(t,o)}}(this))},t.prototype._publishBodyExpiresAtUsingCallbacks=function(t,e){var i,n,r,s,o,a;return s=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+this._getPath()+"/body/publish",o=u.createXHRWrapper("POST",s),a=o.xhr,a.setRequestHeader("x-kii-appid",l.Kii.getAppID()),a.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),a.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),a.setRequestHeader("Content-Type","application/vnd.kii.ObjectBodyPublicationRequest+json"),this._setAuthorizationHeader(a),r={success:function(t){return function(){var i;if(null!=e)try{return i=JSON.parse(a.responseText),i.url?e.success(t,i.url):e.failure(t,"failed to parse response")}catch(n){return e.failure(t,"failed to parse response")}}}(this),failure:function(t){return function(){var i,n;if(null!=e){i="failed to publish body. statusCode: "+a.status,null==a.responseText&&(e.failure(t,i),retunr);try{if(n=JSON.parse(a.responseText),null!=n.errorCode&&(i+=" error code: "+n.errorCode),null!=n.message)return i+=" error message: "+n.message}catch(r){}finally{e.failure(t,i)}}}}(this)},n={},n.expiresAt=t,i=JSON.stringify(n),o.sendData(i,r)},t.prototype.publishBodyExpiresIn=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments)},failure:function(){return null!=e&&e.failure.apply(e,arguments),r(s._Error(arguments[1],i))}},i._publishBodyExpiresInUsingCallbacks(t,o)}}(this))},t.prototype._publishBodyExpiresInUsingCallbacks=function(t,e){var i,n,r,s,o,a;return s=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+this._getPath()+"/body/publish",o=u.createXHRWrapper("POST",s),a=o.xhr,a.setRequestHeader("x-kii-appid",l.Kii.getAppID()),a.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),a.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),a.setRequestHeader("Content-Type","application/vnd.kii.ObjectBodyPublicationRequest+json"),this._setAuthorizationHeader(a),r={success:function(t){return function(){var i;try{return i=JSON.parse(a.responseText),i.url?e.success(t,i.url):e.failure(t,"failed to parse response")}catch(n){return e.failure(t,"failed to parse response")}}}(this),failure:function(t){return function(){var i,n;i="failed to publish body. statusCode: "+a.status;try{if(n=JSON.parse(a.responseText),null!=n.errorCode&&(i+=" error code: "+n.errorCode),null!=n.message)return i+=" error message: "+n.message}catch(r){}finally{e.failure(t,i)}}}(this)},n={},n.expiresIn=t,i=JSON.stringify(n),o.sendData(i,r)},t.prototype.deleteBody=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._deleteBodyUsingCallbacks(r)}}(this))},t.prototype._deleteBodyUsingCallbacks=function(t){var e,i,n,r;return i=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+this._getPath()+"/body",n=u.createXHRWrapper("DELETE",i),r=n.xhr,r.setRequestHeader("x-kii-appid",l.Kii.getAppID()),
r.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),r.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),this._setAuthorizationHeader(r),e={success:function(e){return function(){return e._setBodyContentType(null),null!=t?t.success(e):void 0}}(this),failure:function(e){return function(){var i,n;if(null!=t){i="failed to delete body. statusCode: "+r.status;try{if(n=JSON.parse(r.responseText),null!=n.errorCode&&(i+=" error code: "+n.errorCode),null!=n.message)return i+=" error message: "+n.message}catch(s){}finally{t.failure(e,i)}}}}(this)},n.send(e)},t.isValidObjectID=function(t){var e;return e=/^[a-zA-Z0-9-_.]{2,100}$/i,"string"!==(typeof t).toLowerCase()?!1:null!==t.match(e)},t}(),l.KiiQuery=function(){function t(t){return this._dictValue=p(this._dictValue,this),this.sortByAsc=p(this.sortByAsc,this),this.sortByDesc=p(this.sortByDesc,this),this.setLimit=p(this.setLimit,this),this.getLimit=p(this.getLimit,this),this._setClause=p(this._setClause,this),this.setPaginationKey=p(this.setPaginationKey,this),this.getPaginationKey=p(this.getPaginationKey,this),this._clone=p(this._clone,this),this._clone(t)}return t.prototype._clone=function(t){var e,i;if(null==t||"object"!=typeof t)return t;i=new t.constructor;for(e in t)i[e]=this._clone(t[e]);return i},t.prototype.getPaginationKey=function(){return this._paginationKey},t.prototype.setPaginationKey=function(t){this._paginationKey=t},t.prototype._setClause=function(t){this._clause=t},t.prototype.getLimit=function(){return this._limit},t.prototype.setLimit=function(t){if(t>0)return this._limit=t;throw new l.InvalidLimitException},t.queryWithClause=function(t){var e;return e=new l.KiiQuery,e._setClause(t),e},t.prototype.sortByDesc=function(t){return this._sortField=t,this._sortDescending=!0},t.prototype.sortByAsc=function(t){return this._sortField=t,this._sortDescending=!1},t._emptyDictValue=function(){return{type:"all"}},t.prototype._dictValue=function(){var t,e;return e={},e.bestEffortLimit=this._limit,null!=this._paginationKey&&(e.paginationKey=this._paginationKey),t={descending:this._sortDescending},null!=this._clause?t.clause=this._clause._getDictValue():t.clause=l.KiiQuery._emptyDictValue(),null!=this._sortField&&(t.orderBy=this._sortField),e.bucketQuery=t,e},t}(),l.KiiClause=function(){function t(){this._getDictValue=p(this._getDictValue,this),this._setDictValue=p(this._setDictValue,this),this._setWhereClauses=p(this._setWhereClauses,this),this._setWhereType=p(this._setWhereType,this)}return t.constructor=function(){return t._whereClauses=[],t._dictExpression={}},t.prototype._setWhereType=function(t){this._whereType=t},t.prototype._setWhereClauses=function(t){this._whereClauses=t},t.prototype._setDictValue=function(t){this._dictExpression=t},t.prototype._getDictValue=function(){var t,e,i,n,r,s;if(i={},null!=this._whereClauses&&null!=this._whereType)if(e=[],1===this._whereClauses.length)t=this._whereClauses[0],i="not"===this._whereType?{type:this._whereType,clause:t._getDictValue()}:t._getDictValue();else{for(s=this._whereClauses,n=0,r=s.length;r>n;n++)t=s[n],e.push(t._getDictValue());i={type:this._whereType,clauses:e}}else null!=this._whereClauses?this._whereClauses.length>0&&(i=this._whereClauses[0]._getDictValue()):null!=this._dictExpression&&(i=this._dictExpression);return null==i&&(i=l.KiiQuery.emptyDictValue()),i},t.createWithWhere=function(t,e){var i;return i=new l.KiiClause,i._setWhereType(t),i._setWhereClauses(e),i},t.create=function(t,e,i){var n,r;return n=new l.KiiClause,r={},"="===t?(r.type="eq",r.field=e,r.value=i):"<"===t?(r.type="range",r.field=e,r.upperLimit=i,r.upperIncluded=!1):"<="===t?(r.type="range",r.field=e,r.upperLimit=i,r.upperIncluded=!0):">"===t?(r.type="range",r.field=e,r.lowerLimit=i,r.lowerIncluded=!1):">="===t?(r.type="range",r.field=e,r.lowerLimit=i,r.lowerIncluded=!0):"in"===t?(r.type="in",r.field=e,r.values=i):"prefix"===t?(r.type="prefix",r.field=e,r.prefix=i):"hasField"===t&&(r.type="hasField",r.field=e,r.fieldType=i),n._setDictValue(r),n},t.and=function(){return t.createWithWhere("and",arguments)},t.or=function(){return t.createWithWhere("or",arguments)},t.not=function(e){return t.createWithWhere("not",[e])},t.equals=function(t,e){return null!=e._className&&(e=e.objectURI),l.KiiClause.create("=",t,e)},t.notEquals=function(t,e){return null!=e._className&&(e=e.objectURI),l.KiiClause.createWithWhere("not",[l.KiiClause.equals(t,e)])},t.greaterThan=function(t,e){return l.KiiClause.create(">",t,e)},t.greaterThanOrEqual=function(t,e){return l.KiiClause.create(">=",t,e)},t.lessThan=function(t,e){return l.KiiClause.create("<",t,e)},t.lessThanOrEqual=function(t,e){return l.KiiClause.create("<=",t,e)},t["in"]=function(t,e){return l.KiiClause.create("in",t,e)},t.inClause=function(t,e){return l.KiiClause.create("in",t,e)},t.startsWith=function(t,e){return l.KiiClause.create("prefix",t,e)},t.geoDistance=function(t,e,i,n){var r,s,o,u,a;if(o=function(t){return"string"==typeof t&&t.length>0},s=function(t){return null==t?!1:t instanceof l.KiiGeoPoint},!o(t))throw l.InvalidArgumentException("Specified key is not a string or is an empty string.");if(!s(e))throw l.InvalidArgumentException("center is not a reference of KiiGeoPoint.");if(u="^[a-zA-Z_][a-zA-Z0-9_]*$",null!=n&&!n.match(u))throw l.InvalidArgumentException("putDistanceInto is invalid.");if(0>=i||i>2e7||isNaN(i))throw l.InvalidArgumentException("radius is invalid.");return r=new l.KiiClause,a={},a.type="geodistance",a.field=t,e=e._toDict(),a.center=e,a.radius=i,a.putDistanceInto=n,r._setDictValue(a),r},t.geoBox=function(t,e,i){var n,r,s,o,u,a;if(s=function(t){return"string"==typeof t&&t.length>0},r=function(t){return null==t?!1:t instanceof l.KiiGeoPoint},!s(t))throw l.InvalidArgumentException("Specified key is not a string or is an empty string.");if(!r(e)||!r(i))throw l.InvalidArgumentException("northEast or southWest is not a reference of KiiGeoPoint.");return n=new l.KiiClause,a={},a.type="geobox",a.field=t,o=e._toDict(),u=i._toDict(),a.box={ne:o,sw:u},n._setDictValue(a),n},t.hasField=function(t,e){if("STRING"!==e&&"INTEGER"!==e&&"DECIMAL"!==e&&"BOOLEAN"!==e)throw l.InvalidArgumentException("fieldType is invalid.");return l.KiiClause.create("hasField",t,e)},t}(),i=function(){function t(t,e){this.execute=p(this.execute,this),this.setAdminToken=p(this.setAdminToken,this),this.addHeader=p(this.addHeader,this),this.setAccept=p(this.setAccept,this),this.getAccept=p(this.getAccept,this),this.setAnonymous=p(this.setAnonymous,this),this.isAnonymous=p(this.isAnonymous,this),this.setContentType=p(this.setContentType,this),this.getContentType=p(this.getContentType,this),this.setData=p(this.setData,this),this.getData=p(this.getData,this),this.setHeaders=p(this.setHeaders,this),this.getHeaders=p(this.getHeaders,this),this.setMethod=p(this.setMethod,this),this.getMethod=p(this.getMethod,this),this.setPath=p(this.setPath,this),this.getPath=p(this.getPath,this),this._path=e?"/apps/"+l.Kii.getAppID()+t:t,this._method="GET",this._headers={accept:"*/*"},this._contentType="application/json",this._anonymous=!1,this._success=function(t){return function(){}}(this),this._failure=function(t){return function(){}}(this),this._httpRequest=null}return t.prototype.getPath=function(){return this._path},t.prototype.setPath=function(t){this._path=t},t.prototype.getMethod=function(){return this._method},t.prototype.setMethod=function(t){this._method=t},t.prototype.getHeaders=function(){return this._headers},t.prototype.setHeaders=function(t){this._headers=t},t.prototype.getData=function(){return this._data},t.prototype.setData=function(t){this._data=t},t.prototype.getContentType=function(){return this._contentType},t.prototype.setContentType=function(t){this._contentType=t},t.prototype.isAnonymous=function(){return this._anonymous},t.prototype.setAnonymous=function(t){this._anonymous=t},t.prototype.getAccept=function(){return this._accept},t.prototype.setAccept=function(t){this._accept=t},t.prototype.addHeader=function(t,e){return this._headers[t]=e},t.prototype.setAdminToken=function(t){return this._adminToken=t},t.prototype.execute=function(t,e){var i,n,r,o,u,a,h;if(this._success=null!=t.success?t.success:this._success,this._failure=null!=t.failure?t.failure:this._failure,this._ignoreBody=e,u=l.Kii.getBaseURL()+this._path,l.Kii.logger("POSTING: "),l.Kii.logger(JSON.stringify(this._data)),o=s._isJSONType(this._contentType)?JSON.stringify(this._data):this._data,l.Kii.logger("Making request["+this._method+"] to "+u+" with data: "+o),i=l.Kii.getAdditionalHeaders(),null!=i)for(r in i)a=i[r],this._headers[r]=a;this._headers["x-kii-appid"]=l.Kii.getAppID(),this._headers["x-kii-appkey"]=l.Kii.getAppKey(),this._headers["x-kii-sdk"]=l.KiiSDKClientInfo.getSDKClientInfo(),null!=this._accept&&(this._headers.accept=this._accept),this._anonymous||null==l.KiiUser.getCurrentUser()||(this._headers.Authorization="Bearer "+l.KiiUser.getCurrentUser().getAccessToken()),null!=this._adminToken&&(this._headers.Authorization="Bearer "+this._adminToken),null!=this._contentType&&(this._headers["Content-Type"]=this._contentType),l.Kii.logger("Headers: "),l.Kii.logger(JSON.stringify(this._headers)),t={onComplete:function(t){return function(){var e,i,n,r,s,o,u;if(o=t._httpRequest.xhr,4===o.readyState){if(200<=(u=o.status)&&400>u){if(l.Kii.logger("Completed Request["+o.status+"]"),l.Kii.logger(o.responseText),s=t._parseResponseHeaders(o.getAllResponseHeaders()),t._ignoreBody)return t._success(null,o.status);try{r=JSON.parse(o.responseText)}catch(a){e=a,r=null}return null!=r?null!=r.errorCode?(i=r.errorCode,null!=r.message?i+=": "+r.message:null!=r.error_description&&(i+=": "+r.error_description),t._failure(i,o.status,r.errorCode)):t._success(r,o.status,s):t._success(null,o.status,null)}l.Kii.logger("Error loading data..."),i=o.status+" : "+l.Kii.getBaseURL()+t._path;try{r=JSON.parse(decodeURIComponent(o.responseText))}catch(a){n=a,r=null}return null!=r&&null!=r.errorCode&&(i=r.errorCode,null!=r.message?i+=": "+r.message:null!=r.error_description&&(i+=": "+r.error_description)),l.Kii.logger("Failure: "+i),l.Kii.logger(o.responseText),t._failure(i,o.status)}}}(this),onError:function(t){return function(){var e,i,n,r;r=t._httpRequest.xhr,l.Kii.logger("Error loading data..."),e=r.status+" : "+l.Kii.getBaseURL()+t._path;try{n=JSON.parse(decodeURIComponent(r.responseText))}catch(s){i=s,n=null}return null!=n&&null!=n.errorCode&&(e=n.errorCode,null!=n.message?e+=": "+n.message:null!=n.error_description&&(e+=": "+n.error_description)),l.Kii.logger("Failure: "+e),l.Kii.logger(r.responseText),t._failure(e,r.status)}}(this)},this._httpRequest=this._createHttpRequest(this._method,u,t),null==this._httpRequest.xhr&&this._failure("Cross-Origin Resource Sharing is not supported by the browser.",0),h=this._headers;for(n in h)a=h[n],this._httpRequest.xhr.setRequestHeader(n,a);return"GET"!==this._method&&"DELETE"!==this._method?this._httpRequest.xhr.send(o):this._httpRequest.xhr.send()},t.prototype._createHttpRequest=function(t,i,n){var s;return s=null,null===l.Kii._getHttpRequestType()?"undefined"!=typeof jQuery?(l.Kii.logger("Use jQuery "+t+":"+i),s=new e(t,i,n)):"undefined"!=typeof XMLHttpRequest?(l.Kii.logger("Use XMLHttpRequest "+t+":"+i),s=new a(t,i,n)):"undefined"!=typeof Titanium&&(l.Kii.logger("Use Titanium "+t+":"+i),s=new r(t,i,n)):(l.Kii.logger("Use http request backdoor"),l.Kii._getHttpRequestType()===l._KiiHttpRequestType.jQuery?(l.Kii.logger("Use jQuery "+t+":"+i),s=new e(t,i,n)):l.Kii._getHttpRequestType()===l._KiiHttpRequestType.XMLHttpRequest?(l.Kii.logger("Use XMLHttpRequest "+t+":"+i),s=new a(t,i,n)):l.Kii._getHttpRequestType()===l._KiiHttpRequestType.Titanium&&(l.Kii.logger("Use Titanium "+t+":"+i),s=new r(t,i,n))),s},t.prototype._parseResponseHeaders=function(t){var e,i,n,r,s,o,u;if(n={},!t)return n;for(i=t.split("\r\n"),r=0;r<i.length;)e=i[r],s=e.indexOf(": "),s>0&&(o=e.substring(0,s).toLowerCase(),u=e.substring(s+2),n[o]=u),r++;return n},t}(),l.KiiUser=function(){function t(){this._setAuthToken=p(this._setAuthToken,this),this._getHttpURI=p(this._getHttpURI,this),this._clone=p(this._clone,this),this._getSubscriberPath=p(this._getSubscriberPath,this),this.pushInstallation=p(this.pushInstallation,this),this.pushSubscription=p(this.pushSubscription,this),this._listTopicsUsingCallbacks=p(this._listTopicsUsingCallbacks,this),this.listTopics=p(this.listTopics,this),this.topicWithName=p(this.topicWithName,this),this._groupWithJSON=p(this._groupWithJSON,this),this._setAuthHeader=p(this._setAuthHeader,this),this._getXhrWrapper=p(this._getXhrWrapper,this),this._getRequest=p(this._getRequest,this),this._updateWithJSON=p(this._updateWithJSON,this),this._validateLocalPhoneNumber=p(this._validateLocalPhoneNumber,this),this._validateIdentityData=p(this._validateIdentityData,this),this._updateWithUserFields=p(this._updateWithUserFields,this),this._updateWithIdentityData=p(this._updateWithIdentityData,this),this._deleteUsingCallbacks=p(this._deleteUsingCallbacks,this),this["delete"]=p(this["delete"],this),this._refreshUsingCallbacks=p(this._refreshUsingCallbacks,this),this.refresh=p(this.refresh,this),this._saveUsingCallbacks=p(this._saveUsingCallbacks,this),this.save=p(this.save,this),this._changeEmailUsingCallbacks=p(this._changeEmailUsingCallbacks,this),this.changeEmail=p(this.changeEmail,this),this._changePhoneUsingCallbacks=p(this._changePhoneUsingCallbacks,this),this.changePhone=p(this.changePhone,this),this._ownerOfGroupsUsingCallbacks=p(this._ownerOfGroupsUsingCallbacks,this),this.ownerOfGroups=p(this.ownerOfGroups,this),this._memberOfGroupsUsingCallbacks=p(this._memberOfGroupsUsingCallbacks,this),this.memberOfGroups=p(this.memberOfGroups,this),this.resendPhoneNumberVerification=p(this.resendPhoneNumberVerification,this),this.resendEmailVerification=p(this.resendEmailVerification,this),this._resendVerificationUsingCallbacks=p(this._resendVerificationUsingCallbacks,this),this.resendVerification=p(this.resendVerification,this),this.verifyPhoneNumber=p(this.verifyPhoneNumber,this),this._verifyCredentialsUsingCallbacks=p(this._verifyCredentialsUsingCallbacks,this),this.verifyCredentials=p(this.verifyCredentials,this),this._updatePasswordUsingCallbacks=p(this._updatePasswordUsingCallbacks,this),this.updatePassword=p(this.updatePassword,this),this._updateUsingCallbacks=p(this._updateUsingCallbacks,this),this.update=p(this.update,this),this._putIdentityUsingCallbacks=p(this._putIdentityUsingCallbacks,this),this.putIdentity=p(this.putIdentity,this),this._registerUsingCallbacks=p(this._registerUsingCallbacks,this),this.register=p(this.register,this),this._authenticateWithMfa=p(this._authenticateWithMfa,this),this._authenticateWithToken=p(this._authenticateWithToken,this),this._authenticate=p(this._authenticate,this),this.encryptedBucketWithName=p(this.encryptedBucketWithName,this),this.bucketWithName=p(this.bucketWithName,this),this.get=p(this.get,this),this.set=p(this.set,this),this.objectURI=p(this.objectURI,this),this._setScope=p(this._setScope,this),this.getScope=p(this.getScope,this),this.getAccessTokenObject=p(this.getAccessTokenObject,this),this._setExpiresAt=p(this._setExpiresAt,this),this._setAccessToken=p(this._setAccessToken,this),this.getAccessToken=p(this.getAccessToken,this),this.getLinkedSocialAccounts=p(this.getLinkedSocialAccounts,this),this._setPhoneVerified=p(this._setPhoneVerified,this),this.getPhoneVerified=p(this.getPhoneVerified,this),this._setEmailVerified=p(this._setEmailVerified,this),this.getEmailVerified=p(this.getEmailVerified,this),this._setModified=p(this._setModified,this),this.getModified=p(this.getModified,this),this._setCreated=p(this._setCreated,this),this.getCreated=p(this.getCreated,this),this.setLocale=p(this.setLocale,this),this.getLocale=p(this.getLocale,this),this.setCountry=p(this.setCountry,this),this.getCountry=p(this.getCountry,this),this._clearPassword=p(this._clearPassword,this),this._setPassword=p(this._setPassword,this),this._setLocalPhone=p(this._setLocalPhone,this),this.getPendingPhoneNumber=p(this.getPendingPhoneNumber,this),this._setPhoneNumber=p(this._setPhoneNumber,this),this.getPhoneNumber=p(this.getPhoneNumber,this),this.getPendingEmailAddress=p(this.getPendingEmailAddress,this),this._setEmailAddress=p(this._setEmailAddress,this),this.getEmailAddress=p(this.getEmailAddress,this),this.isPseudoUser=p(this.isPseudoUser,this),this.setDisplayName=p(this.setDisplayName,this),this.getDisplayName=p(this.getDisplayName,this),this._setDisabled=p(this._setDisabled,this),this.disabled=p(this.disabled,this),this._setUsername=p(this._setUsername,this),this.getUsername=p(this.getUsername,this),this.getID=p(this.getID,this),this._setUUID=p(this._setUUID,this),this.getUUID=p(this.getUUID,this),this._customInfo={}}return t.prototype.getUUID=function(){return this._uuid},t.prototype._setUUID=function(t){this._uuid=t},t.prototype.getID=function(){return this._uuid},t.prototype.getUsername=function(){return this._username},t.prototype._setUsername=function(t){var e;if(e=s._trim(t),l.Kii.logger("Setting username: "+e),s._validateUsername(e))return this._username=e;throw new l.InvalidUsernameException},t.prototype.disabled=function(){return this._disabled},t.prototype._setDisabled=function(t){this._disabled=t},t.prototype.getDisplayName=function(){return this._displayName},t.prototype.setDisplayName=function(t){if(!s._validateDisplayName(t))throw new l.InvalidDisplayNameException;return this._displayName=t},t.prototype.isPseudoUser=function(){return null!=this._hasPassword?!this._hasPassword:!this._username&&!this._emailAddress&&!this._phoneNumber},t.prototype.getEmailAddress=function(){return this._emailAddress},t.prototype._setEmailAddress=function(t){var e;if(e=s._trim(t),l.Kii.logger("Setting email: "+e),s._validateEmail(e))return this._emailAddress=e;throw new l.InvalidEmailException},t.prototype.getPendingEmailAddress=function(){return this._emailAddressPending},t.prototype.getPhoneNumber=function(){return this._phoneNumber},t.prototype._setPhoneNumber=function(t){if(l.Kii.logger("Setting phone number: "+t),s._validatePhoneNumber(t))return this._phoneNumber=t;throw new l.InvalidPhoneNumberException},t.prototype.getPendingPhoneNumber=function(){return this._phoneNumberPending},t.prototype._setLocalPhone=function(t,e){if(l.Kii.logger("Setting local phone number: "+t+", country: "+e),!s._validateLocalPhone(t))throw new l.InvalidPhoneNumberException;if(!s._validateCountryCode(e))throw new l.InvalidCountryException;return this._phoneNumber=t,this._country=e},t.prototype._setPassword=function(t){if(s._validatePassword(t))return this._password=t;throw new l.InvalidPasswordException},t.prototype._clearPassword=function(){return this._password=null},t.prototype.getCountry=function(){return this._country},t.prototype.setCountry=function(t){if(s._validateCountryCode(t))return this._country=t;throw new l.InvalidCountryException},t.prototype.getLocale=function(){return this._locale},t.prototype.setLocale=function(t){return this._locale=t},t.prototype.getCreated=function(){return this._created},t.prototype._setCreated=function(t){this._created=t},t.prototype.getModified=function(){return this._modified},t.prototype._setModified=function(t){this._modified=t},t.prototype.getEmailVerified=function(){return this._emailVerified},t.prototype._setEmailVerified=function(t){this._emailVerified=t},t.prototype.getPhoneVerified=function(){return this._phoneVerified},t.prototype._setPhoneVerified=function(t){this._phoneVerified=t},t.prototype.getLinkedSocialAccounts=function(){return l.Kii.logger("third party accounts: "+this._thirdPartyAccounts),null!=this._thirdPartyAccounts?this._thirdPartyAccounts:this._thirdPartyAccounts={}},t.prototype.getAccessToken=function(){return l.Kii.logger("Getting access token: "+this._accessToken),this._accessToken},t.prototype._setAccessToken=function(t){return this._accessToken=t,l.Kii.logger("Setting access token: "+this._accessToken)},t.prototype._setExpiresAt=function(t){return this._expiresAt=t,l.Kii.logger("Setting expires at: "+this._expiresAt)},t.prototype.getAccessTokenObject=function(){var t;return t=null,null!=this._accessToken&&(t={access_token:this._accessToken,expires_at:this._expiresAt}),t},t.prototype.getScope=function(){return this._scope},t.prototype._setScope=function(t){this._scope=t},t.prototype.objectURI=function(){var t;return t=null,null!=this._uuid&&(t="kiicloud://users/"+this._uuid),t},t.prototype.set=function(t,e){return s._isNonEmptyString(t)&&0!==t.indexOf("_")?(l.Kii.logger(this),l.Kii.logger(this._customInfo),this._customInfo[t]=e):void l.Kii.logger("[WARN] Reserved key is used for custom field. key="+t)},t.prototype.get=function(t){return this._customInfo[t]},t.getCurrentUser=function(){return l.Kii.getCurrentUser()},t.userWithUsername=function(t,e){var i;return i=new l.KiiUser,i._setUsername(t),i._setPassword(e),i},t._userWithEmailAddress=function(t,e){var i;return i=new l.KiiUser,i._setEmailAddress(t),i._setPassword(e),i},t._userWithPhoneNumber=function(t,e){var i;return i=new l.KiiUser,i._setPhoneNumber(t),i._setPassword(e),i},t.userWithPhoneNumber=function(e,i){return t._userWithPhoneNumber(e,i)},t.userWithPhoneNumberAndUsername=function(t,e,i){var n;return n=new l.KiiUser,n._setPhoneNumber(t),n._setUsername(e),n._setPassword(i),n},t.userWithEmailAddress=function(e,i){return t._userWithEmailAddress(e,i)},t.userWithEmailAddressAndUsername=function(t,e,i){var n;return n=new l.KiiUser,n._setEmailAddress(t),n._setUsername(e),n._setPassword(i),n},t.userWithEmailAddressAndPhoneNumber=function(t,e,i){var n;return n=new l.KiiUser,n._setEmailAddress(t),n._setPhoneNumber(e),n._setPassword(i),n},t.userWithCredentials=function(t,e,i,n){var r;return r=new l.KiiUser,r._setEmailAddress(t),r._setPhoneNumber(e),r._setUsername(i),r._setPassword(n),r},t._validateURI=function(t){var e,i,n;return t=s._trim(t),i=/^kiicloud:\/\/users\/(.*$)/i,"string"===(typeof t).toLowerCase()&&(e=t.match(i),null!=e&&(n=e[1])),n},t.userWithID=function(t){var e;if(null==t||""===t)throw new l.InvalidArgumentException("userID should not null or empty");return e=new l.KiiUser,e._setUUID(t),e},t.userWithURI=function(t){var e,i;if(l.Kii.logger("About to extract from: "+t),i=l.KiiUser._validateURI(t),l.Kii.logger("Extracted uuid from uri: "+i),null==i)throw new l.InvalidURIException;return e=new l.KiiUser,e._setUUID(i),e},t.prototype.bucketWithName=function(t){var e;return e=new l.KiiBucket(t,this)},t.prototype.encryptedBucketWithName=function(t){var e;return e=new l.KiiEncryptedBucket(t,this)},t.prototype._authenticate=function(t){var e,i,n,r,o,u;return l.Kii.logger("Authenticating user:"),l.Kii.logger(this),l.Kii.logger("Email verified: "+this._emailVerified),l.Kii.logger("Phone verified: "+this._phoneVerified),null!=this._username?u=this._username:null!=this._emailAddress&&this._emailVerified===!0?u=this._emailAddress:null!=this._phoneNumber&&this._phoneVerified===!0?u=this._phoneNumber:null!=this._emailAddress?u=this._emailAddress:null!=this._phoneNumber&&(u=this._phoneNumber),n={username:u,password:this._password},r=new Date,i=r.getTime(),l.Kii.getAccessTokenExpiration()>0&&(n.expiresAt=s._safeCalculateExpiresAtAsNumber(l.Kii.getAccessTokenExpiration(),i)),o=this._getRequest({path:"/oauth2/token",withApp:!1}),o.setAnonymous(!0),o.setMethod("POST"),o.setData(n),e={success:function(e){return function(n){return e._setUUID(n.id),e._clearPassword(),e._setAccessToken(n.access_token),e._setScope(n.scope),null!=n.expires_in&&(r=new Date,i=r.getTime(),e._expiresAt=s._safeCalculateExpiresAtAsDate(n.expires_in,i)),l.Kii.setCurrentUser(e),null!=t?t.success(l.Kii.getCurrentUser()):void 0}}(this),failure:function(e){return function(i,n){return e._clearPassword(),null!=t?t.failure(e,i):void 0}}(this)},o.execute(e,!1)},t.prototype._authenticateWithToken=function(t,e,i){var n,r;return l.Kii.logger("Authenticating user "+this),l.Kii.logger(e),r=this._getRequest({path:"/users/me",withApp:!0}),r.setAnonymous(!0),r.addHeader("Authorization","Bearer "+t),n={success:function(n){return function(r){return n._updateWithJSON(r),n._setAccessToken(t),"undefined"==typeof i?n._setExpiresAt(new Date(s.MAX_DATE_IN_MILLIS)):n._setExpiresAt(i),l.Kii.setCurrentUser(n),null!=e?e.success(l.Kii.getCurrentUser()):void 0}}(this),failure:function(t){return function(i,n){return null!=e?e.failure(t,i):void 0}}(this)},r.execute(n,!1)},t.prototype._authenticateWithMfa=function(t,e){var i,n;return l.Kii.logger("Authenticating user "+this),l.Kii.logger(e),n=this._getRequest({path:"/oauth2/token",withApp:!0}),n.setMethod("POST"),n.setData(t),i={success:function(t){return function(i){var n,r;return t._setUUID(i.id),t._clearPassword(),t._setAccessToken(i.access_token),null!=i.expires_in&&(r=new Date,n=r.getTime(),t._expiresAt=s._safeCalculateExpiresAtAsDate(i.expires_in,n)),l.Kii.setCurrentUser(t),null!=e?e.success(l.Kii.getCurrentUser()):void 0}}(this),failure:function(t){return function(i,n){return t._clearPassword(),null!=e?e.failure(t,i):void 0}}(this)},n.execute(i,!1)},t.authenticate=function(e,i,n){return new Promise(function(r,o){var u;return u={success:function(){return null!=n&&n.success.apply(n,arguments),r(arguments[0])},failure:function(){var t;return null!=n&&n.failure.apply(n,arguments),t=s._Error(arguments[1]),t.target=arguments[0],o(t)}},t._authenticateUsingCallbacks(e,i,u)})},t._authenticateUsingCallbacks=function(t,e,i){var n,r;try{if(l.Kii.logger("UserIdentifier: "+t),!s._validatePassword(e))throw new l.InvalidPasswordException;if(s._validateEmail(t))r=l.KiiUser._userWithEmailAddress(t,e);else if(s._validatePhoneNumber(t))r=l.KiiUser._userWithPhoneNumber(t,e);else{if(!s._validateUsername(t))throw new l.InvalidUserIdentifierException;r=l.KiiUser.userWithUsername(t,e)}return r._authenticate(i)}catch(o){if(n=o,null!=r&&r._clearPassword(),null!=i)return i.failure(null,n.message)}},t.authenticateWithToken=function(e,i,n){return new Promise(function(r,o){var u;return u={success:function(){return null!=i&&i.success.apply(i,arguments),r(arguments[0])},failure:function(){var t;return null!=i&&i.failure.apply(i,arguments),t=s._Error(arguments[1]),t.target=arguments[0],o(t)}},t._authenticateWithTokenUsingCallbacks(e,u,n)})},t._authenticateWithTokenUsingCallbacks=function(t,e,i){var n,r;return n=s._type(i),"undefined"!==n&&"date"!==n?e.failure(null,l.InvalidArgumentException("Specified expiresAt must be a Date")):(r=new l.KiiUser,r._authenticateWithToken(t,e,i))},t.authenticateWithTotp=function(e,i){return new Promise(function(n,r){var o;return o={success:function(){return null!=i&&i.success.apply(i,arguments),n(arguments[0])},failure:function(){var t;return null!=i&&i.failure.apply(i,arguments),t=s._Error(arguments[1]),t.target=arguments[0],r(t)}},t._authenticateWithTotpUsingCallbacks(e,o)})},t._authenticateWithTotpUsingCallbacks=function(t,e){var i,n;return i={grant_type:"mfa",totp_code:t},n=new l.KiiUser,n._authenticateWithMfa(i,e)},t.authenticateWithRecoveryCode=function(e,i){return new Promise(function(n,r){var o;return o={success:function(){return null!=i&&i.success.apply(i,arguments),n(arguments[0])},failure:function(){var t;return null!=i&&i.failure.apply(i,arguments),t=s._Error(arguments[1]),t.target=arguments[0],r(t)}},t._authenticateWithRecoveryCodeUsingCallbacks(e,o)})},t._authenticateWithRecoveryCodeUsingCallbacks=function(t,e){var i,n;return i={grant_type:"mfa",recovery_code:t},n=new l.KiiUser,n._authenticateWithMfa(i,e)},t.prototype.register=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._registerUsingCallbacks(r)}}(this))},t.prototype._registerUsingCallbacks=function(t){var e,i,n,r,s,o;if(l.Kii.logger("Registering user "+this),e={password:this._password},null!=this._username&&(e.loginName=this._username),null!=this._displayName&&(e.displayName=this._displayName),null!=this._emailAddress&&(e.emailAddress=this._emailAddress),null!=this._phoneNumber&&(e.phoneNumber=this._phoneNumber),!this._validateLocalPhoneNumber(this._phoneNumber,this._country))return void t.failure(this,"needs to provide country for the local phone number");null!=this._country&&(e.country=this._country),null!=this._locale&&(e.locale=this._locale),l.Kii.logger("CINFO"),l.Kii.logger(JSON.stringify(this._customInfo)),o=this._customInfo;for(i in o)s=o[i],l.Kii.logger("Key/val: "+i+"/"+s),e[i]=s;return r=this._getRequest({path:"/users",withApp:!0}),r.setMethod("POST"),r.setData(e),r.setAnonymous(!0),r.setContentType("application/vnd.kii.RegistrationRequest+json"),n={success:function(e){return function(i){return l.Kii.logger("Succreg"),e._updateWithJSON(i),e._authenticate(t)}}(this),failure:function(e){return function(i,n){return l.Kii.logger("Failreg"),e._clearPassword(),null!=t?t.failure(e,i):void 0}}(this)},r.execute(n,!1)},t.registerAsPseudoUser=function(e,i){return new Promise(function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments[0])},failure:function(){return null!=e&&e.failure.apply(e,arguments),r(s._Error(arguments[1]))}},t._registerAsPseudoUserUsingCallbacks(o,i)})},t._registerAsPseudoUserUsingCallbacks=function(t,e){var i,n,r,o,a;return r=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/users",o=u.createXHRWrapper("POST",r),a=o.xhr,a.setRequestHeader("x-kii-appid",l.Kii.getAppID()),a.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),a.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),a.setRequestHeader("Content-Type","application/vnd.kii.RegistrationAndAuthorizationRequest+json"),n={success:function(){var e,i,n,o;try{return a.status<300&&a.status>=200?(n=JSON.parse(a.responseText),e=n._accessToken,o=new l.KiiUser,o._updateWithJSON(n),o._setAccessToken(e),o._setExpiresAt(new Date(s.MAX_DATE_IN_MILLIS)),l.Kii.setCurrentUser(o),t.success(o)):(i=a.status+" : "+r,t.failure(null,i))}catch(u){return t.failure(null,"failed to parse response")}},failure:function(){var e,i;e="failed to register pseudo user. statusCode: "+a.status;try{if(i=JSON.parse(a.responseText),null!=i.errorCode&&(e+=" error code: "+i.errorCode),null!=i.message)return e+=" error message: "+i.message}catch(n){}finally{t.failure(null,e)}}},null==e&&(e={}),i=JSON.stringify(e),o.sendData(i,n)},t.prototype.putIdentity=function(t,e,i,n,r){return new Promise(function(o){return function(u,a){var l;return l={success:function(){return null!=i&&i.success.apply(i,arguments),u(arguments[0])},failure:function(){return null!=i&&i.failure.apply(i,arguments),a(s._Error(arguments[1],o))}},o._putIdentityUsingCallbacks(t,e,l,n,r)}}(this))},t.prototype._putIdentityUsingCallbacks=function(t,e,i,n,r){var o,u,a,h;if(l.Kii.logger("Put identity user: "+this._uuid+", data: "+JSON.stringify(t)),u={},!this.isPseudoUser())return void(null!=i&&i.failure(this,"This user has the identity already"));if(null==t)return void(null!=i&&i.failure(this,"identityData is null"));try{this._validateIdentityData(t)}catch(c){return a=c,void(null!=i&&i.failure(this,a))}return h=!1,null!=t.emailAddress&&(h=!0),null!=t.phoneNumber&&(h=!0),null!=t.username&&(h=!0),h?null==e?void(null!=i&&i.failure(this,"password is null")):s._validatePassword(e)?(o=null!=n?n.country:null,null==t.phoneNumber||this._validateLocalPhoneNumber(t.phoneNumber,o)?this.refresh({failure:function(t){return function(e,n){return l.Kii.logger("Failreg"),null!=i?i.failure(t,n):void 0}}(this),success:function(s){return function(o){var a,h,c,p,f,_,g,d,y,m;if(!o.isPseudoUser())return void(null!=i&&i.failure(o,"This user has the identity already"));if(u=s._clone(o._customInfo),null!=t.emailAddress&&(u.emailAddress=t.emailAddress),null!=t.phoneNumber&&(u.phoneNumber=t.phoneNumber),null!=t.username&&(u.loginName=t.username),u.password=e,null!=n)for(h in n)_=n[h],u[h]=_;if(null!=r)for(y=0,m=r.length;m>y;y++)c=r[y],delete u[c];return f=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+("/users/"+s._uuid),
g=s._getXhrWrapper("POST",f),d=g.xhr,s._setAuthHeader(d),d.setRequestHeader("Content-Type","application/vnd.kii.UserUpdateRequest+json"),p={success:function(){var e,u;try{return u=JSON.parse(d.responseText),d.status<300&&d.status>=200?(o._setModified(u.modifiedAt),o._updateWithIdentityData(t),o._updateWithUserFields(n,r),s._hasPassword=!0,i.success(o)):(e=d.status+" : "+f,i.failure(s,e))}catch(a){return i.failure(s,"failed to parse response")}},failure:function(){var t,e;t="failed to put identity data. statusCode: "+d.status;try{if(e=JSON.parse(d.responseText),null!=e.errorCode&&(t+=" error code: "+e.errorCode),null!=e.message)return t+=" error message: "+e.message}catch(n){}finally{i.failure(s,t)}}},a=JSON.stringify(u),l.Kii.logger(a),g.sendData(a,p)}}(this)}):void i.failure(this,"needs to provide country for the local phone number")):void(null!=i&&i.failure(this,"invalid password")):void(null!=i&&i.failure(this,"needs to provide at least one of login name, email address or phone number"))},t.prototype.update=function(t,e,i,n){return new Promise(function(r){return function(o,u){var a;return a={success:function(){return null!=e&&e.success.apply(e,arguments),o(arguments[0])},failure:function(){return null!=e&&e.failure.apply(e,arguments),u(s._Error(arguments[1],r))}},r._updateUsingCallbacks(t,a,i,n)}}(this))},t.prototype._updateUsingCallbacks=function(t,e,i,n){var r,s,o,u,a,h,c,p,f,_,g;if(l.Kii.logger("update user: "+this._uuid),s={},u=!1,h=!1,a=!1,null!=t){try{this._validateIdentityData(t)}catch(d){return o=d,void(null!=e&&e.failure(this,o))}null!=t.emailAddress&&(u=!0),null!=t.phoneNumber&&(u=!0),null!=t.username&&(u=!0)}if(null!=i)for(c in i){f=i[c],h=!0;break}if(null!=n)for(_=0,g=n.length;g>_;_++){p=n[_],a=!0;break}return u||h||a?(r=null!=i?i.country:null,null==t||null==t.phoneNumber||this._validateLocalPhoneNumber(t.phoneNumber,r)?this.refresh({failure:function(t){return function(i,n){return l.Kii.logger("Failreg"),null!=e?e.failure(t,n):void 0}}(this),success:function(r){return function(o){var a,h,_,g,d,y,m;if(o.isPseudoUser()&&u)return void(null!=e&&e.failure(o,"Pseudo user must use putIdentity()"));if(s=r._clone(o._customInfo),null!=t&&(null!=t.emailAddress&&(s.emailAddress=t.emailAddress),null!=t.phoneNumber&&(s.phoneNumber=t.phoneNumber),null!=t.username&&(s.loginName=t.username)),null!=i)for(c in i)f=i[c],s[c]=f;if(null!=n)for(y=0,m=n.length;m>y;y++)p=n[y],delete s[p];return _=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+("/users/"+r._uuid),g=r._getXhrWrapper("POST",_,!1),d=g.xhr,r._setAuthHeader(d),d.setRequestHeader("Content-Type","application/vnd.kii.UserUpdateRequest+json"),h={success:function(){var u,a;try{return a=JSON.parse(d.responseText),d.status<300&&d.status>=200?(o._setModified(s.modifiedAt),o._updateWithIdentityData(t),o._updateWithUserFields(i,n),e.success(o)):(u=d.status+" : "+_,e.failure(r,u))}catch(l){return e.failure(r,"failed to parse response")}},failure:function(){var t,i;t="failed to update user. statusCode: "+d.status;try{if(i=JSON.parse(d.responseText),null!=i.errorCode&&(t+=" error code: "+i.errorCode),null!=i.message)return t+=" error message: "+i.message}catch(n){}finally{e.failure(r,t)}}},a=JSON.stringify(s),g.sendData(a,h)}}(this)}):void e.failure(this,"needs to provide country for the local phone number")):void e.failure(this,"all arguments are null or empty")},t.prototype.updatePassword=function(t,e,i){return new Promise(function(n){return function(r,o){var u;return u={success:function(){return null!=i&&i.success.apply(i,arguments),r(arguments[0])},failure:function(){return null!=i&&i.failure.apply(i,arguments),o(s._Error(arguments[1],n))}},n._updatePasswordUsingCallbacks(t,e,u)}}(this))},t.prototype._updatePasswordUsingCallbacks=function(t,e,i){var n,r,o,u;return l.Kii.logger("Updating password from "+t+" to "+e),s._validatePassword(e)?(n={oldPassword:t,newPassword:e},r="/users/"+this._uuid+"/password",o=this._getRequest({path:r,withApp:!0}),o.setMethod("PUT"),o.setData(n),o.setContentType("application/vnd.kii.ChangePasswordRequest+json"),u={success:function(t){return function(e,n){if(t._clearPassword,300>n&&n>=200){if(null!=i)return i.success(t)}else if(null!=i)return i.failure(t,"Unable to change password")}}(this),failure:function(t){return function(e,n){return t._clearPassword,null!=i?i.failure(t,e):void 0}}(this)},o.execute(u,!0)):null!=i?i.failure(this,(new l.InvalidPasswordException).message):void 0},t.resetPassword=function(e,i){return new Promise(function(n,r){var o;return o={success:function(){return null!=i&&i.success(),n()},failure:function(){return null!=i&&i.failure(arguments[0]),r(s._Error(arguments[0]))}},t._resetPasswordUsingCallbacks(e,o)})},t._resetPasswordUsingCallbacks=function(t,e){var n,r,o,u;if(l.Kii.logger("Resetting password with identifier: "+t),s._validateEmail(t))n="EMAIL";else if(null!=e)return void e.failure("Invalid user identifier. Must be a valid email address");return null!=n?(r="/users/"+n+":"+t+"/password/request-reset",o=new i(r,!0),o.setMethod("POST"),o.setAnonymous(!0),u={success:function(t,i){return 300>i&&i>=200&&null!=e?e.success():null!=e?e.failure("Unable to reset password"):void 0},failure:function(t,i){return null!=e?e.failure(t):void 0}},o.execute(u,!0)):void 0},t.resetPasswordWithNotificationMethod=function(e,i,n){return new Promise(function(r,o){var u;return u={success:function(){return null!=n&&n.success(),r()},failure:function(){return null!=n&&n.failure(arguments[0]),o(s._Error(arguments[0]))}},t._resetPasswordWithNotificationMethodUsingCallbacks(e,i,u)})},t._resetPasswordWithNotificationMethodUsingCallbacks=function(t,e,i){var n,r,o,a,h,c;return"string"!=typeof t?void(null!=i&&i.failure("given userIdentifier is not string")):""===t?void(null!=i&&i.failure("given userIdentifier is empty")):"EMAIL"!==e&&"SMS"!==e&&"SMS_PIN"!==e?void(null!=i&&i.failure("notificationMethod should be 'EMAIL' or 'SMS' or 'SMS_PIN'")):(r=s._validateEmail(t)?"EMAIL:"+t:s._isGlobalPhoneNumber(t)?"PHONE:"+t:t,r=encodeURIComponent(r),n={notificationMethod:e},"SMS_PIN"===e&&(n.notificationMethod="SMS",n.smsResetMethod="PIN"),a=""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/users/"+r+"/password/request-reset",h=u.createXHRWrapper("POST",a),c=h.xhr,c.setRequestHeader("x-kii-appid",l.Kii.getAppID()),c.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),c.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),c.setRequestHeader("Content-Type","application/vnd.kii.ResetPasswordRequest+json"),o={success:function(){return null!=i?i.success():void 0},failure:function(){var t,e;t="failed to reset password. statusCode: "+c.status;try{if(e=JSON.parse(c.responseText),null!=e.errorCode&&(t+=" error code: "+e.errorCode),null!=e.message)return t+=" error message: "+e.message}catch(n){}finally{null!=i&&i.failure(t)}}},h.sendData(JSON.stringify(n),o))},t.completeResetPassword=function(e,i,n,r){return new Promise(function(o,u){var a;return a={success:function(){return null!=r&&r.success(),o()},failure:function(){return null!=r&&r.failure(arguments[0]),u(s._Error(arguments[0]))}},t._completeResetPasswordUsingCallbacks(e,i,n,a)})},t._completeResetPasswordUsingCallbacks=function(t,e,i,n){var r,o,a,h,c,p;return s._isNonEmptyString(t)?s._isNonEmptyString(e)?(o=s._validateEmail(t)?"EMAIL:"+t:s._isGlobalPhoneNumber(t)?"PHONE:"+t:t,o=encodeURIComponent(o),r={pinCode:e},s._isNonEmptyString(i)&&(r.newPassword=i),h=""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/users/"+o+"/password/complete-reset",c=u.createXHRWrapper("POST",h),p=c.xhr,p.setRequestHeader("x-kii-appid",l.Kii.getAppID()),p.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),p.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),p.setRequestHeader("Content-Type","application/vnd.kii.CompletePasswordResetRequest+json"),a={success:function(){return null!=n?n.success():void 0},failure:function(){var t,e;t="failed to reset password. statusCode: "+p.status;try{if(e=JSON.parse(p.responseText),null!=e.errorCode&&(t+=" error code: "+e.errorCode),null!=e.message)return t+=" error message: "+e.message}catch(i){}finally{null!=n&&n.failure(t)}}},c.sendData(JSON.stringify(r),a)):void(null!=n&&n.failure("given pinCode is null or empty")):void(null!=n&&n.failure("given userIdentifier is null or empty"))},t.prototype.verifyCredentials=function(t,e,i){return new Promise(function(n){return function(r,o){var u;return u={success:function(){return null!=i&&i.success.apply(i,arguments),r(arguments[0])},failure:function(){return null!=i&&i.failure.apply(i,arguments),o(s._Error(arguments[1],n))}},n._verifyCredentialsUsingCallbacks(t,e,u)}}(this))},t.prototype._verifyCredentialsUsingCallbacks=function(t,e,i){var n,r,s;return l.Kii.logger("Verifying "+t+" with code: "+e),n="/users/me/"+t+"/verify",r=this._getRequest({path:n,withApp:!0}),r.setMethod("POST"),r.setData({verificationCode:e}),r.setContentType("application/vnd.kii.AddressVerificationRequest+json"),s={success:function(e){return function(n,r){if(300>r&&r>=200){if("email-address"===t?e._setEmailVerified(!0):"phone-number"===t&&e._setPhoneVerified(!0),null!=i)return i.success(e)}else if(null!=i)return i.failure(e,"Unable to verify "+t)}}(this),failure:function(t){return function(e,n){return null!=i?i.failure(t,e):void 0}}(this)},r.execute(s,!0)},t.prototype.verifyPhoneNumber=function(t,e){return this.verifyCredentials("phone-number",t,e)},t.prototype.resendVerification=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments[0])},failure:function(){return null!=e&&e.failure.apply(e,arguments),r(s._Error(arguments[1],i))}},i._resendVerificationUsingCallbacks(t,o)}}(this))},t.prototype._resendVerificationUsingCallbacks=function(t,e){var i,n,r,s;return l.Kii.logger("Resending verification "+t),i=this.getID(),n="/users/"+i+"/"+t+"/resend-verification",r=this._getRequest({path:n,withApp:!0}),r.setMethod("POST"),s={success:function(i){return function(n,r){return 300>r&&r>=200&&null!=e?e.success(i):null!=e?e.failure(i,"Unable to resend "+t+" verification"):void 0}}(this),failure:function(t){return function(i,n){return null!=e?e.failure(t,i):void 0}}(this)},r.execute(s,!0)},t.prototype.resendEmailVerification=function(t){return this.resendVerification("email-address",t)},t.prototype.resendPhoneNumberVerification=function(t){return this.resendVerification("phone-number",t)},t.prototype.memberOfGroups=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments)},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._memberOfGroupsUsingCallbacks(r)}}(this))},t.prototype._memberOfGroupsUsingCallbacks=function(t){var e,i,n;return l.Kii.logger("Getting groups for member "+this._uuid),i="/groups/?is_member="+this._uuid,n=this._getRequest({path:i,withApp:!0}),n.setAccept("application/vnd.kii.GroupsRetrievalResponse+json"),e={success:function(e){return function(i,n){var r,s,o,u,a;if(300>n&&n>=200){for(s=[],a=i.groups,o=0,u=a.length;u>o;o++)r=a[o],s.push(e._groupWithJSON(r));if(null!=t)return t.success(e,s)}else if(null!=t)return t.failure(e,"Unable to retrieve groups")}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},n.execute(e,!1)},t.prototype.ownerOfGroups=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments)},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._ownerOfGroupsUsingCallbacks(r)}}(this))},t.prototype._ownerOfGroupsUsingCallbacks=function(t){var e,i,n;return l.Kii.logger("Getting groups owned by the user "+this._uuid),i="/groups/?owner="+this._uuid,n=this._getRequest({path:i,withApp:!0}),n.setAccept("application/vnd.kii.GroupsRetrievalResponse+json"),e={success:function(e){return function(i,n){var r,s,o,u,a;if(300>n&&n>=200){for(s=[],a=i.groups,o=0,u=a.length;u>o;o++)r=a[o],s.push(e._groupWithJSON(r));if(null!=t)return t.success(e,s)}else if(null!=t)return t.failure(e,"Unable to retrieve groups")}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},n.execute(e,!1)},t.prototype.changePhone=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments[0])},failure:function(){return null!=e&&e.failure.apply(e,arguments),r(s._Error(arguments[1],i))}},i._changePhoneUsingCallbacks(t,o)}}(this))},t.prototype._changePhoneUsingCallbacks=function(t,e){var i,n,r;return l.Kii.logger("Updating phone number to "+t),i="/users/"+this._uuid+"/phone-number",n=this._getRequest({path:i,withApp:!0}),n.setMethod("PUT"),n.setContentType("application/vnd.kii.PhoneNumberModificationRequest+json"),n.setData({phoneNumber:t}),r={success:function(t){return function(i,n){return 300>n&&n>=200&&null!=e?e.success(t):null!=e?e.failure(t,"Unable to update phone number"):void 0}}(this),failure:function(t){return function(i,n){return null!=e?e.failure(t,i):void 0}}(this)},n.execute(r,!0)},t.prototype.changeEmail=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments[0])},failure:function(){return null!=e&&e.failure.apply(e,arguments),r(s._Error(arguments[1],i))}},i._changeEmailUsingCallbacks(t,o)}}(this))},t.prototype._changeEmailUsingCallbacks=function(t,e){var i,n,r;return l.Kii.logger("Updating email address to: "+t),s._validateEmail(t)?(i="/users/"+this._uuid+"/email-address",n=this._getRequest({path:i,withApp:!0}),n.setMethod("PUT"),n.setContentType("application/vnd.kii.EmailAddressModificationRequest+json"),n.setData({emailAddress:t}),r={success:function(t){return function(i,n){return 300>n&&n>=200&&null!=e?e.success(t):null!=e?e.failure(t,"Unable to update email address"):void 0}}(this),failure:function(t){return function(i,n){return null!=e?e.failure(t,i):void 0}}(this)},n.execute(r,!0)):e.failure(this,"Invalid email address format")},t.prototype.save=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._saveUsingCallbacks(r)}}(this))},t.prototype._saveUsingCallbacks=function(t){var e,i,n,r;return l.Kii.logger("Saving user: "+this._uuid),i="/users/"+this._uuid,l.Kii.logger("CUSTOMINFO: "),l.Kii.logger(this._customInfo),n=this._getRequest({path:i,withApp:!0}),n.setMethod("POST"),n.setContentType("application/vnd.kii.UserUpdateRequest+json"),e=this._customInfo,null!=this._country&&(e.country=this._country),null!=this._locale&&(e.locale=this._locale),null!=this._displayName&&(e.displayName=this._displayName),n.setData(e),r={success:function(e){return function(i,n){if(300>n&&n>=200){if(e._setModified(i.modifiedAt),null!=t)return t.success(e)}else if(null!=t)return t.failure(e,"Unable to parse response")}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},n.execute(r,!1)},t.prototype.refresh=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._refreshUsingCallbacks(r)}}(this))},t.prototype._refreshUsingCallbacks=function(t){var e,i;return l.Kii.logger("Refreshing user: "+this._uuid),i=this._getRequest({path:"/users/"+this._uuid,withApp:!0}),e={success:function(e){return function(i,n){if(300>n&&n>=200){if(e._phoneNumberPending=null,e._emailAddressPending=null,e._updateWithJSON(i),null!=t)return t.success(e)}else if(null!=t)return t.failure(e,"Unable to parse response")}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},i.execute(e,!1)},t.prototype["delete"]=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(){return null!=t&&t.success.apply(t,arguments),i(arguments[0])},failure:function(){return null!=t&&t.failure.apply(t,arguments),n(s._Error(arguments[1],e))}},e._deleteUsingCallbacks(r)}}(this))},t.prototype._deleteUsingCallbacks=function(t){var e,i;return l.Kii.logger("Deleting user..."),i=this._getRequest({path:"/users/"+this._uuid,withApp:!0}),i.setMethod("DELETE"),e={success:function(e){return function(i,n){return 300>n&&n>=200&&null!=t?t.success(e):null!=t?t.failure(e,"Unable to parse response"):void 0}}(this),failure:function(e){return function(i,n){return null!=t?t.failure(e,i):void 0}}(this)},i.execute(e,!0)},t.logOut=function(){return l.Kii.logOut()},t.loggedIn=function(){return l.Kii.loggedIn()},t.prototype._updateWithIdentityData=function(t){return null!=t&&(null!=t.username&&(this._username=t.username),null!=t.emailAddress&&(this._emailAddress=t.emailAddress),null!=t.phoneNumber)?this._phoneNumber=t.phoneNumber:void 0},t.prototype._updateWithUserFields=function(t,e){var i,n,r,s,o,u;if(null!=t)for(i in t)r=t[i],"displayName"===i?this._displayName=r:"country"===i?this._country=r:"locale"===i?this._locale=r:""===i?(l.Kii.logger("Setting empty to custom info"),this._customInfo[i]=r):"_"!==i.substring(0,1)&&(l.Kii.logger("Setting to custom info"),this._customInfo[i]=r);if(null!=e){for(u=[],s=0,o=e.length;o>s;s++)n=e[s],u.push(delete this._customInfo[n]);return u}},t.prototype._validateIdentityData=function(t){if(null!=t){if(null!=t.emailAddress&&!s._validateEmail(t.emailAddress))throw"invalid email";if(null!=t.phoneNumber&&!s._validatePhoneNumber(t.phoneNumber))throw"invalid phone number";if(null!=t.username&&!s._validateUsername(t.username))throw"invalid username"}},t.prototype._validateLocalPhoneNumber=function(t,e){return null==t||s._isGlobalPhoneNumber(t)?!0:null!=e?s._validateCountryCode(e):!1},t.prototype._updateWithJSON=function(t){var e,i,n,r;l.Kii.logger("Updating with:"),l.Kii.logger(JSON.stringify(t)),this._thirdPartyAccounts={},r=[];for(e in t)n=t[e],l.Kii.logger("key/val => "+e+"/"+n),l.Kii.logger("Substr "+e.substring(0,1)),"userID"===e||"id"===e?r.push(this._uuid=n):"created"===e||"createdAt"===e||"_created"===e?r.push(this._created=n):"modified"===e||"modifiedAt"===e||"_modified"===e?r.push(this._modified=n):"loginName"===e?r.push(this._username=n):"displayName"===e?r.push(this._displayName=n):"country"===e?(l.Kii.logger("Is setting country"),r.push(this._country=n)):"locale"===e?r.push(this._locale=n):"emailAddress"===e?r.push(this._emailAddress=n):"_emailAddressPending"===e?r.push(this._emailAddressPending=n):"phoneNumber"===e?r.push(this._phoneNumber=n):"_phoneNumberPending"===e?r.push(this._phoneNumberPending=n):"emailAddressVerified"===e?(l.Kii.logger("Email verified: "+n),r.push(this._emailVerified=n)):"phoneNumberVerified"===e?(l.Kii.logger("Phone verified: "+n),r.push(this._phoneVerified=n)):"_hasPassword"===e?(l.Kii.logger("_hasPassword: "+n),r.push(this._hasPassword=n)):"_thirdPartyAccounts"===e?(null!=n.hotmail&&(i=n.hotmail,i.type="live",n.live=i,delete n.hotmail),l.Kii.logger("_thirdPartyAccounts: "+n),r.push(this._thirdPartyAccounts=n)):"_disabled"===e?(l.Kii.logger("disabled: "+n),r.push(this._disabled=n)):""===e?(l.Kii.logger("Setting empty to custom info"),r.push(this._customInfo[e]=n)):e.substring(0,!0)?(l.Kii.logger("Setting to custom info"),r.push(this._customInfo[e]=n)):r.push(l.Kii.logger("Doing nothing"));return r},t.prototype._getRequest=function(t){var e,n,r;return e=t.path,r=t.withApp,n=new i(e,r)},t.findUserByEmail=function(e,i){var n,r;return null==l.KiiUser.getCurrentUser()||null==l.KiiUser.getCurrentUser().getAccessToken()?(r=l.IllegalStateException("User is not logged in"),n=s._Error(r),null!=i&&"function"==typeof i.failure&&i.failure(r),Promise.reject(n)):t._findUserByEmail(e,i)},t._findUserByEmail=function(e,i,n){var r,o,u;return null==e||""===e?(o=l.InvalidArgumentException("email should not null or empty"),r=s._Error(o),null!=n?(null!=i&&"function"==typeof i.failure&&i.failure(n,o),r.target=n):null!=i&&"function"==typeof i.failure&&i.failure(o),Promise.reject(r)):(u=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+("/users/EMAIL:"+e),t._findUserRequestImpl(u,i,n))},t.findUserByPhone=function(e,i){var n,r;return null==l.KiiUser.getCurrentUser()||null==l.KiiUser.getCurrentUser().getAccessToken()?(r=l.IllegalStateException("User is not logged in"),n=s._Error(r),null!=i&&"function"==typeof i.failure&&i.failure(r),Promise.reject(n)):t._findUserByPhone(e,i)},t._findUserByPhone=function(e,i,n){var r,o,u;return null==e||""===e?(o=l.InvalidArgumentException("phone should not null or empty"),r=s._Error(o),null!=n?(null!=i&&"function"==typeof i.failure&&i.failure(n,o),r.target=n):null!=i&&"function"==typeof i.failure&&i.failure(o),Promise.reject(r)):(u=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+("/users/PHONE:"+e),t._findUserRequestImpl(u,i,n))},t.findUserByUsername=function(e,i){var n,r;return null==l.KiiUser.getCurrentUser()||null==l.KiiUser.getCurrentUser().getAccessToken()?(r=l.IllegalStateException("User is not logged in"),n=s._Error(r),null!=i&&"function"==typeof i.failure&&i.failure(r),Promise.reject(n)):t._findUserByUsername(e,i)},t._findUserByUsername=function(e,i,n){var r,o,u;return null==e||""===e?(o=l.InvalidArgumentException("username should not null or empty"),r=s._Error(o),null!=n?(null!=i&&"function"==typeof i.failure&&i.failure(n,o),r.target=n):null!=i&&"function"==typeof i.failure&&i.failure(o),Promise.reject(r)):(u=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+("/users/LOGIN_NAME:"+e),t._findUserRequestImpl(u,i,n))},t._findUserRequestImpl=function(e,i,n){return new Promise(function(r,o){var u;return u={success:function(){var t;return null!=i&&null!=(t=i.success)&&t.apply(i,arguments),r(null!=n?arguments:arguments[0])},failure:function(){var t;return null!=i&&null!=(t=i.failure)&&t.apply(i,arguments),o(null!=n?s._Error(arguments[1],arguments[0]):s._Error(arguments[0]))}},t._findUserRequestImplUsingCallbacks(e,u,n)})},t._findUserRequestImplUsingCallbacks=function(t,e,i){var n,r,s;return r=u.createXHRWrapper("GET",t),s=r.xhr,s.setRequestHeader("x-kii-appid",l.Kii.getAppID()),s.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),s.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),null!=i?s.setRequestHeader("Authorization","Bearer "+i._getToken()):s.setRequestHeader("Authorization","Bearer "+l.KiiUser.getCurrentUser().getAccessToken()),n={success:function(){var t,n;if(null!=e)try{return t=JSON.parse(s.responseText),null!=i?(n=new l.KiiUserWithToken(i._getToken()),n._updateWithJSON(t),e.success(i,n)):(n=new l.KiiUser,n._updateWithJSON(t),e.success(n))}catch(r){return null!=i?e.failure(i,"Unable to parse response"):e.failure("Unable to parse response")}},failure:function(){var t,n;if(null!=e){t="Failed to find user. statusCode: "+s.status;try{if(n=JSON.parse(s.responseText),null!=n.errorCode&&(t+=" error code: "+n.errorCode),null!=n.message)return t+=" error message: "+n.message}finally{null!=i?e.failure(i,t):e.failure(t)}}}},r.send(n)},t.prototype._getXhrWrapper=function(t,e){var i,n;return i=u.createXHRWrapper(t,e),n=i.xhr,n.setRequestHeader("x-kii-appid",l.Kii.getAppID()),n.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),n.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),i},t.prototype._setAuthHeader=function(t){var e;return e=l.KiiUser.getCurrentUser(),null!=e?t.setRequestHeader("Authorization","Bearer "+e.getAccessToken()):void 0},t.prototype._groupWithJSON=function(t){return l.KiiGroup._groupWithJSON(t)},t.prototype.topicWithName=function(t){var e,i;if("string"!=typeof t||""===t)throw new l.InvalidArgumentException("topicName should not null or empty");if(e=this.getID(),!e)throw"can not instantiate topic from instance which doesn't have ID";return i=this._getHttpURI(),new l.KiiTopic(i,t)},t.prototype.listTopics=function(t,e){return new Promise(function(i){return function(n,r){var s;return s={success:function(){return null!=t&&t.success.apply(t,arguments),n(arguments)},failure:function(){return null!=t&&t.failure.apply(t,arguments),r(arguments[0])}},i._listTopicsUsingCallbacks(s,e)}}(this))},t.prototype._listTopicsUsingCallbacks=function(t,e){var i,n,r;return n=""+this._getHttpURI()+"/topics","string"==typeof e&&""!==e&&(n=n+"?paginationKey="+encodeURIComponent(e)),r=u.createXHRWrapper("GET",n),r.setKiiHeaders(),this._setAuthToken(r),i={success:function(e){return function(){var i,n,s,o,u,a;for(i=JSON.parse(r.xhr.responseText),s=[],a=i.topics,o=0,u=a.length;u>o;o++)n=a[o],s.push(e.topicWithName(n.topicID));return null!=t?t.success(s,void 0===i.paginationKey?null:i.paginationKey):void 0}}(this),failure:function(e){return function(){var i,n;return n=r.getErrorString("list topics"),i=s._Error(n,e),null!=t?t.failure(i):void 0}}(this)},r.send(i)},t.prototype.pushSubscription=function(){return new l.KiiPushSubscription(this)},t.prototype.pushInstallation=function(){return new l.KiiPushInstallation(this)},t.prototype._getSubscriberPath=function(){return"users/"+this.getID()},t.prototype._clone=function(t){var e,i;if(null==t||"object"!=typeof t)return t;i=new t.constructor;for(e in t)i[e]=this._clone(t[e]);return i},t.prototype._getHttpURI=function(){return""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/users/"+this.getID()},t.prototype._setAuthToken=function(t){return t.setCurrentUserToken()},t}(),s=function(){function t(){}return t.MAX_DATE_IN_MILLIS=864e13,t.MIN_DATE_IN_MILLIS=-864e13,t._validateEmail=function(e){var i;return"string"!==(typeof e).toLowerCase()?(l.Kii.logger("Not string"),!1):(e=t._trim(e),i=/^[^@]+@[^@]+$/,i.test(e))},t._validatePhoneNumber=function(e){var i;return e=t._trim(e),i=/^[\\+]?[0-9]{10,}$/i,"string"!==(typeof e).toLowerCase()?(l.Kii.logger("Not string"),!1):!!e.match(i)},t._isGlobalPhoneNumber=function(e){var i;return e=t._trim(e),i=/^[\\+]{1}[0-9]{2}/,"string"!==(typeof e).toLowerCase()?(l.Kii.logger("Not string"),!1):!!e.match(i)},t._validateLocalPhone=function(e){var i;return e=t._trim(e),i=/^\d+$/,"string"!==(typeof e).toLowerCase()?(l.Kii.logger("Not string"),!1):e.match(i)?!0:(l.Kii.logger("Invalid format"),!1)},t._assertLocalPhoneIsValid=function(e){if(!t._validateLocalPhone(e))throw new l.InvalidLocalPhoneNumberException},t._validateCountryCode=function(e){var i;return e=t._trim(e),i=/^[a-z]{2}$/i,"string"!==(typeof e).toLowerCase()?(l.Kii.logger("Not string"),!1):e.match(i)?(l.Kii.logger("Is true"),!0):!1},t._assertCountryCodeIsValid=function(e){if(!t._validateCountryCode(e))throw new l.InvalidCountryException},t._validatePassword=function(t){var e;return l.Kii.logger("Validating password: "+t),e=/^[\x20-\x7E]{4,50}$/,"string"!==(typeof t).toLowerCase()?(l.Kii.logger("not string"),!1):t.match(e)?(l.Kii.logger("matched"),!0):(l.Kii.logger("other exception"),!1)},t._assertPasswordIsValid=function(e){if(!t._validatePassword(e))throw new l.InvalidPasswordException},t._validateUsername=function(t){var e;return e=/^[a-zA-Z0-9-_\\.]{3,64}$/i,"string"!==(typeof t).toLowerCase()?!1:!!t.match(e)},t._validateGroupID=function(t){var e;return e=/^[a-z0-9-_.]{1,30}$/,"string"!==(typeof t).toLowerCase()?!1:!!t.match(e)},t._validateDisplayName=function(e){var i;return"string"===t._type(e)&&1<=(i=e.length)&&50>=i},t._trim=function(t){var e;return e=/^(\s|\u00A0)+|(\s|\u00A0)+$/g,(t||"").replace(e,"")},t._safeAddTicks=function(e,i){if(isNaN(parseInt(e,10))||isNaN(parseInt(i,10)))throw new l.InvalidArgumentException("Parameters should be a number");if(Math.abs(e+i)>t.MAX_DATE_IN_MILLIS)throw new l.ArithmeticException("Addition of "+e+" and "+i+" result in long overflow");return e+i},t._safeMultiplyTicks=function(e,i){if(isNaN(parseInt(e,10))||isNaN(parseInt(i,10)))throw new l.InvalidArgumentException("Parameters should be a number");if(Math.abs(e*i)>t.MAX_DATE_IN_MILLIS)throw new l.ArithmeticException("Multiplication of "+e+" and "+i+" result in long overflow");return e*i},t._safeCalculateExpiresAtAsNumber=function(e,i){var n,r,s;s=0;try{r=t._safeMultiplyTicks(e,1e3),s=t._safeAddTicks(i,r)}catch(o){if(n=o,!(n instanceof l.ArithmeticException))throw n;s=t.MAX_DATE_IN_MILLIS}return s},t._safeCalculateExpiresAtAsDate=function(e,i){var n,r,s;s=0;try{r=t._safeMultiplyTicks(e,1e3),s=t._safeAddTicks(i,r)}catch(o){if(n=o,!(n instanceof l.ArithmeticException))throw n;s=t.MAX_DATE_IN_MILLIS}return new Date(s)},t._isJSONType=function(t){var e;return e=/\+?json(;.*)?$/i,t.match(e)},t._type=function(t){var e;return void 0===t||null===t?String(t):(e={"[object Boolean]":"boolean","[object Number]":"number","[object String]":"string","[object Function]":"function","[object Array]":"array","[object Date]":"date","[object RegExp]":"regexp","[object Object]":"object"},e[Object.prototype.toString.call(t)])},t._disableCacheURL=function(t){return t+=-1!==t.indexOf("?")?"&disable_cache=":"?disable_cache=",t+=(new Date).getTime()},t._validateServerCodeEntryName=function(e){var i;return i=/^[a-zA-Z][_a-zA-Z0-9]*$/i,"string"===t._type(e)&&e.match(i)},t._validateServerCodeEntryArgument=function(e){return"null"===t._type(e)||"object"===t._type(e)&&Object.keys(e).length>0},t._validateServerCodeEnryVersion=function(e){return"string"===t._type(e)&&""!==e},t._isNonEmptyString=function(t){return"string"!=typeof t?!1:t.length>0},t._Error=function(t,e){var i;return i=Error(t),i.target=e,i},t._clone=function(e){var i,n,r;if(null==e||"object"!=typeof e)return e;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return i="",e.global&&(i+="g"),e.ignoreCase&&(i+="i"),e.multiline&&(i+="m"),e.sticky&&(i+="y"),new RegExp(e.source,i);r=new e.constructor;for(n in e)r[n]=t._clone(e[n]);return r},t}(),l.KiiSocialConnect=function(){function t(){}var e;return e=null,t.setupNetwork=function(t,e,i,n){},t.logIn=function(i,n,r){return null==e&&(e=new c),new Promise(function(e,o){var u,a,l;l={success:function(){return null!=r&&r.success.apply(r,arguments),e(arguments)},failure:function(){var t;return null!=r&&r.failure.apply(r,arguments),t=s._Error(arguments[2]),t.network=i,o(t)}};try{return t._logInUsingCallbacks(i,n,l)}catch(h){return a=h,null!=r&&"function"==typeof r.failure&&r.failure(null,i,a),u=s._Error(a),u.network=i,o(u)}})},t._logInUsingCallbacks=function(t,i,n){var r;return r=!1,null!=e&&(l.Kii.logger("And manager: "),l.Kii.logger(e._getManager(t)),e._getManager(t)&&(e._getManager(t)._logIn(i,n),r=!0)),l.Kii.logger("Callbacks"),l.Kii.logger(n),r||null==n?void 0:n.failure(l.KiiUser.getCurrentUser(),t,"Unable to get network. Please ensure the network name is one of the supported KiiSocialNetworkName values")},t.linkCurrentUserWithNetwork=function(i,n,r){return null==e&&(e=new c),new Promise(function(e,o){var u,a,h,c;c={success:function(){return null!=r&&r.success.apply(r,arguments),e(arguments)},failure:function(){var t;return null!=r&&r.failure.apply(r,arguments),t=s._Error(arguments[2]),t.target=arguments[0],t.network=i,o(t)}};try{return t._linkCurrentUserWithNetworkUsingCallbacks(i,n,c)}catch(p){return h=p,u=l.KiiUser.getCurrentUser(),null!=r&&"function"==typeof r.failure&&r.failure(u,i,h),a=s._Error(h),a.target=u,a.network=i,o(a)}})},t._linkCurrentUserWithNetworkUsingCallbacks=function(t,i,n){var r;return l.Kii.logger("Trying with instance"),l.Kii.logger(e),r=!1,null!=e&&(l.Kii.logger("And manager: "),l.Kii.logger(e._getManager(t)),e._getManager(t)&&(e._getManager(t)._linkWithCurrentUser(i,n),r=!0)),l.Kii.logger("Callbacks"),l.Kii.logger(n),r||null==n?void 0:n.failure(l.KiiUser.getCurrentUser(),t,"Unable to get network. Please ensure the network name is one of the supported KiiSocialNetworkName values")},t.unLinkCurrentUserFromNetwork=function(i,n){return null==e&&(e=new c),new Promise(function(e,r){var o;return o={success:function(){return null!=n&&n.success.apply(n,arguments),
e(arguments)},failure:function(){var t;return null!=n&&n.failure.apply(n,arguments),t=s._Error(arguments[2]),t.target=arguments[0],t.network=i,r(t)}},t._unLinkCurrentUserWithNetworkUsingCallbacks(i,o)})},t._unLinkCurrentUserWithNetworkUsingCallbacks=function(t,i){if(l.Kii.logger("Trying with instance"),l.Kii.logger(e),null!=e){if(l.Kii.logger("And manager: "),l.Kii.logger(e._getManager(t)),e._getManager(t))return e._getManager(t)._unlinkFromCurrentUser(i)}else if(null!=i)return i.failure(l.KiiUser.getCurrentUser(),t,"Unable to get network. Please ensure the network name is one of the supported KiiSocialNetworkName values")},t.getAccessTokenForNetwork=function(t){return null!=e?e._getManager(t)._getToken():void 0},t.getAccessTokenExpirationForNetwork=function(t){return null!=e?e._getManager(t)._getTokenExpiration():void 0},t.getAccessTokenObjectForNetwork=function(t){return null!=e?e._getManager(t)._getTokenObject():void 0},t.logOutAll=function(){var t,i,n,r,s;return null!=e&&(t=e._getManager(l.KiiSocialNetworkName.FACEBOOK),null!=t&&t._logOut(),s=e._getManager(l.KiiSocialNetworkName.TWITTER),null!=s&&s._logOut(),n=e._getManager(l.KiiSocialNetworkName.QQ),null!=n&&n._logOut(),i=e._getManager(l.KiiSocialNetworkName.GOOGLEPLUS),null!=i&&i._logOut(),r=e._getManager(l.KiiSocialNetworkName.RENREN),null!=r)?r._logOut():void 0},t}(),c=function(){function t(){this._getManager=p(this._getManager,this)}return t.prototype._getManager=function(t){return t===l.KiiSocialNetworkName.FACEBOOK?null!=this._facebookManager?this._facebookManager:this._facebookManager=new l.KiiSCNFacebook:t===l.KiiSocialNetworkName.TWITTER?null!=this._twitterManager?this._twitterManager:this._twitterManager=new l.KiiSCNTwitter:t===l.KiiSocialNetworkName.QQ?null!=this._qqManager?this._qqManager:this._qqManager=new l.KiiSCNQQ:t===l.KiiSocialNetworkName.GOOGLEPLUS?null!=this._googleManager?this._googleManager:this._googleManager=new l.KiiSCNGoogle:t===l.KiiSocialNetworkName.RENREN?null!=this._renrenManager?this._renrenManager:this._renrenManager=new l.KiiSCNRenRen:void 0},t}(),l.KiiSocialConnectNetwork=function(){function t(t){this._network=t,this._unlink=p(this._unlink,this),this._link=p(this._link,this),this._register=p(this._register,this),this._getAccessToken=p(this._getAccessToken,this),this._createTokenObject=p(this._createTokenObject,this),this._unlinkFromCurrentUser=p(this._unlinkFromCurrentUser,this),this._linkWithCurrentUser=p(this._linkWithCurrentUser,this),this._logOut=p(this._logOut,this),this._logIn=p(this._logIn,this),this._isAuthenticated=p(this._isAuthenticated,this),this._getTokenObject=p(this._getTokenObject,this),this._setTokenObject=p(this._setTokenObject,this),this._getTokenExpiration=p(this._getTokenExpiration,this),this._setTokenExpiration=p(this._setTokenExpiration,this),this._getToken=p(this._getToken,this),this._setToken=p(this._setToken,this),this._getNetwork=p(this._getNetwork,this),this._setNetwork=p(this._setNetwork,this),this._tokenExpiration=null,this._token=null}return t.prototype._className="KiiSocialConnectNetwork",t.prototype._setNetwork=function(t){this._network=t},t.prototype._getNetwork=function(){return this._network},t.prototype._setToken=function(t){this._token=t},t.prototype._getToken=function(){return this._token},t.prototype._setTokenExpiration=function(t){this._tokenExpiration=t},t.prototype._getTokenExpiration=function(){return this._tokenExpiration},t.prototype._setTokenObject=function(t){this._tokenObject=t},t.prototype._getTokenObject=function(){return this._tokenObject},t.prototype._isAuthenticated=function(){return null!=this._tokenObject},t.prototype._logIn=function(t,e){},t.prototype._logOut=function(){return this._token=null,this._tokenExpiration=null,this._tokenObject=null},t.prototype._linkWithCurrentUser=function(t,e){},t.prototype._unlinkFromCurrentUser=function(t){},t.prototype._createTokenObject=function(t,e){},t.prototype._getAccessToken=function(t){},t.prototype._register=function(t,e,n,r,o){var u,a,h,c,p;return l.Kii.getAccessTokenExpiration()>0&&(a=new Date,u=a.getTime(),n.expiresAt=s._safeCalculateExpiresAtAsNumber(l.Kii.getAccessTokenExpiration(),u)),c=new i("/integration/"+t,!0),c.setMethod("POST"),c.setData(n),c.setAnonymous(!0),c.setContentType(e),p=this._getAccessToken(r),h={success:function(t){return function(e){var i,n,h,c;return t._setToken(p),n=t._createTokenObject(r,e),t._setTokenObject(n),h=new l.KiiUser,h._updateWithJSON(e),h._setAccessToken(e.access_token),null!=e.expires_in&&(a=new Date,u=a.getTime(),c=s._safeCalculateExpiresAtAsDate(e.expires_in,u),h._setExpiresAt(c)),l.Kii.setCurrentUser(h),i={success:function(e){return l.Kii.setCurrentUser(e),null!=o?o.success(e,t._network):void 0},failure:function(e,i){return null!=o?o.failure(e,t._network,i):void 0}},h.refresh(i)}}(this),failure:function(t){return function(e,i){return null!=o?o.failure(null,t._network,e):void 0}}(this)},c.execute(h,!1)},t.prototype._link=function(t,e,n,r,s){var o,u,a;return u=new i("/users/me/"+t+"/link",!0),u.setMethod("POST"),u.setData(n),u.setContentType(e),a=this._getAccessToken(r),o={success:function(t){return function(e){var i,n;return t._setToken(a),n=t._createTokenObject(r,e),t._setTokenObject(n),i={success:function(e){return l.Kii.setCurrentUser(e),null!=s?s.success(e,t._network):void 0},failure:function(e,i){return null!=s?s.failure(e,t._network,i):void 0}},l.KiiUser.getCurrentUser().refresh(i)}}(this),failure:function(t){return function(e,i){return null!=s?s.failure(l.KiiUser.getCurrentUser(),t._network,e):void 0}}(this)},u.execute(o,!0)},t.prototype._unlink=function(t,e){var n,r;return n=new i("/users/me/"+t+"/unlink",!0),n.setMethod("POST"),r={success:function(t){return function(i){var n;return t._setToken(null),t._setTokenExpiration(null),t._setTokenObject(null),n={success:function(i){return l.Kii.setCurrentUser(i),null!=e?e.success(i,t._network):void 0},failure:function(i,n){return null!=e?e.failure(i,t._network,n):void 0}},l.KiiUser.getCurrentUser().refresh(n)}}(this),failure:function(t){return function(i,n){return null!=e?e.failure(l.KiiUser.getCurrentUser(),t._network,i):void 0}}(this)},n.execute(r,!0)},t}(),l.KiiSCNFacebook=function(t){function e(){this._unlinkFromCurrentUser=p(this._unlinkFromCurrentUser,this),this._linkWithCurrentUser=p(this._linkWithCurrentUser,this),this._logOut=p(this._logOut,this),this._logIn=p(this._logIn,this),this._getAccessToken=p(this._getAccessToken,this),this._createTokenObject=p(this._createTokenObject,this),this._setup=p(this._setup,this),e.__super__.constructor.call(this,l.KiiSocialNetworkName.FACEBOOK)}return _(e,t),e.prototype._setup=function(t,i,n){return this._key=t,this._secret=i,this._extras=n,e.__super__._setup.call(this,this._key,this._secret,this._extras)},e.prototype._createTokenObject=function(t,e){var i;return i={access_token:t.access_token},null!=e&&null!=e.new_user_created&&(i.kii_new_user=e.new_user_created),i},e.prototype._getAccessToken=function(t){return t.access_token},e.prototype._logIn=function(t,e){var i;if(l.Kii.logger("should auth fb"),l.Kii.logger("Checking options"),null==t||!t.access_token)throw l.InvalidArgumentException("options.access_token is required");return null!=l.KiiUser.getCurrentUser()&&l.KiiUser.logOut(),i={accessToken:t.access_token},this._register("facebook","application/vnd.kii.AuthTokenFacebookRequest+json",i,t,e)},e.prototype._logOut=function(){return e.__super__._logOut.apply(this,arguments),l.Kii.logger("Log out fb")},e.prototype._linkWithCurrentUser=function(t,e){var i;if(null!=l.KiiUser.getCurrentUser()){if(null==t||!t.access_token)throw l.InvalidArgumentException("options.access_token is required");return i={accessToken:t.access_token},this._link("facebook","application/vnd.kii.LinkFacebookRequest+json",i,t,e)}return null!=e?e.failure(null,this._network,"A KiiUser must be logged in before linking to Facebook"):void 0},e.prototype._unlinkFromCurrentUser=function(t){return null!=l.KiiUser.getCurrentUser()?this._unlink("facebook",t):null!=t?t.failure("A KiiUser must be logged in before unlinking from Facebook"):void 0},e}(l.KiiSocialConnectNetwork),l.InvalidDisplayNameException=function(){return this.message="Unable to set displayName. Must be between 1-50 characters."},l.InvalidPasswordException=function(){return this.message="Unable to set password. Must be between 4-50 characters composed with ascii (exclude control character)"},l.InvalidUsernameException=function(){return this.message="Unable to set username. Must be between 3 and 64 characters, which can include alphanumeric characters as well as underscores '_' and periods '.'"},l.InvalidUserIdentifierException=function(){return this.message="User identifier should be one of user name, phone number or email"},l.InvalidEmailException=function(){return this.message="Unable to set email address. Must be a valid email"},l.InvalidPhoneNumberException=function(){return this.message="Unable to set phone number. Must begin with a '+' and be at least 10 digits"},l.InvalidLocalPhoneNumberException=function(){return this.message="Unable to set phone number. Must be a sequence of numbers"},l.InvalidCountryException=function(){return this.message="Unable to set country code. Must be 2 alphabetic characters. Ex: US, JP, CN"},l.InvalidURIException=function(){return this.message="Unable to set URI. Must be of the form kiicloud://some/path/to/object/or/entity"},l.InvalidACLAction=function(){return this.message="Unable to set ACL action. Must be one of the permitted values in KiiACLAction"},l.InvalidACLSubject=function(){return this.message="Unable to set ACL subject. Must be of type KiiUser or KiiGroup"},l.InvalidACLGrant=function(){return this.message="Unable to set ACL grant. Must be a boolean type"},l.InvalidLimitException=function(){return this.message="Unable to set query limit. Must be an integer > 0"},l.InvalidArgumentException=function(t){return this.message="InvalidArgument: "+t},l.IllegalStateException=function(t){return this.message="IllegalState: "+t},l.ArithmeticException=function(t){return this.message="ArithmeticException: "+t},l.UnsupportedOperationException=function(t){return this.message="UnsupportedOperationException: "+t},l.KiiAppAdminContext=function(){function t(t){this.listTopics=p(this.listTopics,this),this.topicWithName=p(this.topicWithName,this),this.loadThingWithThingID=p(this.loadThingWithThingID,this),this.loadThingWithVendorThingID=p(this.loadThingWithVendorThingID,this),this.registerOwnerWithVendorThingID=p(this.registerOwnerWithVendorThingID,this),this.registerOwnerWithThingID=p(this.registerOwnerWithThingID,this),this.thingWithID=p(this.thingWithID,this),this.registerThing=p(this.registerThing,this),this.registerGroupWithOwnerAndID=p(this.registerGroupWithOwnerAndID,this),this._getToken=p(this._getToken,this),this.getAccessToken=p(this.getAccessToken,this),this._getId=p(this._getId,this),this._objectWithURI=p(this._objectWithURI,this),this._token=t.token,this._id=t.id}return t.prototype.bucketWithName=function(t){var e;return e=new l.KiiBucketWithToken(t,null,this._token)},t.prototype.encryptedBucketWithName=function(t){var e;return e=new l.KiiEncryptedBucketWithToken(t,null,this._token)},t.prototype.groupWithName=function(t){var e;return e=l.KiiGroupWithToken._groupWithName(t,this._token)},t.prototype.userWithID=function(t){var e;return e=l.KiiUserWithToken._userWithID(t,this._token)},t.prototype.objectWithURI=function(t){var e;return e=this._objectWithURI(t)},t.prototype._userWithLoginName=function(t,e){var i,n,r;return r=new l.KiiUserWithToken(this._token),n=r._getRequest({path:"/users/LOGIN_NAME:"+t,withApp:!0}),n.setAdminToken(this._token),i={success:function(t){return function(t,i){if(300>i&&i>=200){if(r._updateWithJSON(t),null!=e)return e.success(r)}else if(null!=e)return e.failure("Unable to parse response")}}(this),failure:function(t){return function(t,i){return null!=e?e.failure(t):void 0}}(this)},n.execute(i,!1)},t.prototype._objectWithURI=function(t){var e,i,n,r,s,o,u,a,h;if(!t)throw new l.InvalidURIException;if(h=0===t.indexOf("kiicloud://"),o=t.substr("kiicloud://".length),s=o.split("/"),r=s.length,!(r>=4&&h))throw new l.InvalidURIException;if(i=4===r?1:3,n=s[i],a=null,"groups"===s[0]&&6===r)a=new l.KiiGroupWithToken._groupWithID(s[1],this._token);else if("users"===s[0]&&6===r)a=l.KiiUserWithToken._userWithID(s[1],this._token);else if("things"===s[0]&&6===r)a=l.KiiThingWithToken.thingWithID(s[1],this._token);else if(4!==r)throw new l.InvalidURIException;return e=new l.KiiBucketWithToken(n,a,this._token),u=e.createObject(),u._setUUID(s[r-1]),u},t.prototype._getId=function(){return this._id},t.prototype.getAccessToken=function(){return this._getToken()},t.prototype._getToken=function(){return this._token},t.prototype.groupWithID=function(t){var e;if(null==t||""===t)throw new l.InvalidArgumentException("groupID should not null or empty");return e=l.KiiGroupWithToken._groupWithID(t,this._token)},t.prototype.registerGroupWithOwnerAndID=function(t,e,i,n,r){return new Promise(function(o){return function(u,a){var h;return h={success:function(){return null!=r&&r.success.apply(r,arguments),u(arguments[0])},failure:function(){var t;return null!=r&&r.failure.apply(r,arguments),t=s._Error(arguments[1],arguments[0]),t.addMembersArray=arguments[2],t.removeMembersArray=arguments[3],a(t)}},l.KiiGroup._registerGroupWithIDUsingCallbacks(o._token,t,e,i,n,h)}}(this))},t.prototype.groupWithURI=function(t){var e,i,n;if(null==t)throw new l.InvalidURIException;if(0!==t.indexOf("kiicloud://"))throw new l.InvalidURIException;if(n=t.substr("kiicloud://".length),e=n.split("/"),2!==e.length||"groups"!==e[0])throw new l.InvalidURIException;return i=l.KiiGroupWithToken._groupWithID(e[1],this._token)},t.prototype.findUserByEmail=function(t,e){return l.KiiUser._findUserByEmail(t,e,this)},t.prototype.findUserByPhone=function(t,e){return l.KiiUser._findUserByPhone(t,e,this)},t.prototype.findUserByUsername=function(t,e){return l.KiiUser._findUserByUsername(t,e,this)},t.prototype.registerThing=function(t,e){return l.KiiThingWithToken.register(t,e,this._token)},t.prototype.thingWithID=function(t){return l.KiiThingWithToken.thingWithID(t,this._token)},t.prototype.registerOwnerWithThingID=function(t,e,i){return l.KiiThingWithToken.registerOwnerWithThingID(t,e,i,this._token)},t.prototype.registerOwnerWithVendorThingID=function(t,e,i){return l.KiiThingWithToken.registerOwnerWithVendorThingID(t,e,i,this._token)},t.prototype.thingWithID=function(t){return l.KiiThingWithToken.thingWithID(t,this._token)},t.prototype.loadThingWithVendorThingID=function(t,e){return l.KiiThingWithToken.loadWithVendorThingID(t,e,this._token)},t.prototype.loadThingWithThingID=function(t,e){return l.KiiThingWithToken.loadWithThingID(t,e,this._token)},t.prototype.topicWithName=function(t){if("string"!=typeof t||""===t)throw new l.InvalidArgumentException("topicName should not null or empty");return new l.KiiTopicWithToken(""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID(),t,this._token)},t.prototype.listTopics=function(t,e){return l.Kii._listTopics(t,e,this)},t}(),l.KiiACLWithToken=function(t){function e(t,i){this._userWithID=p(this._userWithID,this),this._groupWithID=p(this._groupWithID,this),this._getRequest=p(this._getRequest,this),e.__super__.constructor.call(this),this._setParent(t),this._authToken=i}return _(e,t),e.prototype._getRequest=function(t){var i;return i=e.__super__._getRequest.call(this,t),i.setAdminToken(this._authToken),i},e.prototype._groupWithID=function(t){var e;return e=l.KiiGroupWithToken._groupWithID(t,this._authToken)},e.prototype._userWithID=function(t){var e;return e=l.KiiUserWithToken._userWithID(t,this._authToken)},e}(l.KiiACL),l.KiiGroupWithToken=function(t){function e(t){this.topicWithName=p(this.topicWithName,this),this._setAuthToken=p(this._setAuthToken,this),this._setOwnerFromContext=p(this._setOwnerFromContext,this),this._userWithID=p(this._userWithID,this),this.bucketWithName=p(this.bucketWithName,this),this._getRequest=p(this._getRequest,this),e.__super__.constructor.call(this),this._authToken=t}return _(e,t),e.prototype._getRequest=function(t){var i;return i=e.__super__._getRequest.call(this,t),i.setAdminToken(this._authToken),i},e._groupWithName=function(t,e){return l.KiiGroupWithToken._groupWithNameAndMembers(t,null,e)},e._groupWithNameAndMembers=function(t,e,i){var n;return n=new l.KiiGroupWithToken(i),n._setName(t),n._setAddMembers(e),n},e._groupWithID=function(t,e){var i;return i=new l.KiiGroupWithToken(e),i._setUUID(t),i},e.prototype.bucketWithName=function(t){var e;return e=new l.KiiBucketWithToken(t,this,this._authToken)},e.prototype.encryptedBucketWithName=function(t){var e;return e=new l.KiiEncryptedBucketWithToken(t,this,this._authToken)},e.prototype._userWithID=function(t){var e;return e=l.KiiUserWithToken._userWithID(t,this._authToken)},e.prototype._setOwnerFromContext=function(t){},e._groupWithJSON=function(t,e){var i;return i=new l.KiiGroupWithToken(e),null!=t.groupID&&i._setUUID(t.groupID),null!=t.name&&i._setName(t.name),null!=t.owner&&i._setOwner(l.KiiUserWithToken._userWithID(t.owner,e)),i},e.prototype._setAuthToken=function(t){return t.setAuthToken(this._authToken)},e.prototype.topicWithName=function(t){var e,i;if("string"!=typeof t||""===t)throw new l.InvalidArgumentException("topicName should not null or empty");if(e=this.getID(),!e)throw"can not instantiate topic from instance which doesn't have ID";return i=this._getHttpURI(),new l.KiiTopicWithToken(i,t,this._authToken)},e}(l.KiiGroup),l.KiiObjectWithToken=function(t){function e(t){this._userWithID=p(this._userWithID,this),this.objectACL=p(this.objectACL,this),this._getToken=p(this._getToken,this),this._getRequest=p(this._getRequest,this),e.__super__.constructor.call(this),this._authToken=t}return _(e,t),e.prototype._getRequest=function(t){var i;return l.Kii.logger("admin req: "+this._authToken),i=e.__super__._getRequest.call(this,t),i.setAdminToken(this._authToken),i},e.prototype._getToken=function(){return this._authToken?this._authToken:null},e.objectWithBucket=function(t,e,i){var n;return l.Kii.logger("Creating object w type: "+e),n=new l.KiiObjectWithToken(i),n._setBucket(t),n._setObjectType(e),l.Kii.logger(n),n},e.objectWithID=function(t,e,i){var n;return l.Kii.logger("Creating object w id: "+e),n=new l.KiiObjectWithToken(i),n._setBucket(t),n._setUUID(e),l.Kii.logger(n),n},e.prototype.objectACL=function(){var t;return t=new l.KiiACLWithToken(this,this._authToken)},e.prototype._userWithID=function(t){var e;return e=l.KiiUserWithToken._userWithID(t,this._authToken)},e}(l.KiiObject),l.KiiUserWithToken=function(t){function e(t){this.pushInstallation=p(this.pushInstallation,this),this.topicWithName=p(this.topicWithName,this),this.pushSubscription=p(this.pushSubscription,this),this._groupWithJSON=p(this._groupWithJSON,this),this.bucketWithName=p(this.bucketWithName,this),this._setAuthHeader=p(this._setAuthHeader,this),this._setAuthToken=p(this._setAuthToken,this),this._getRequest=p(this._getRequest,this),e.__super__.constructor.call(this),this._authToken=t}return _(e,t),e._userWithID=function(t,e){var i;return i=new l.KiiUserWithToken(e),i._setUUID(t),i},e.prototype._getRequest=function(t){var i;return i=e.__super__._getRequest.call(this,t),i.setAdminToken(this._authToken),i},e.prototype._setAuthToken=function(t){return t.setAuthToken(this._authToken)},e.prototype._setAuthHeader=function(t){return t.setRequestHeader("Authorization","Bearer "+this._authToken)},e.prototype.bucketWithName=function(t){var e;return e=new l.KiiBucketWithToken(t,this,this._authToken)},e.prototype.encryptedBucketWithName=function(t){var e;return e=new l.KiiEncryptedBucketWithToken(t,this,this._authToken)},e.prototype._groupWithJSON=function(t){var e;return e=new l.KiiGroupWithToken._groupWithJSON(t,this._authToken)},e.prototype.pushSubscription=function(){return new l.KiiPushSubscriptionWithToken(this,this._authToken)},e.prototype.topicWithName=function(t){var e;if("string"!=typeof t||""===t)throw new l.InvalidArgumentException("topicName should not null or empty");if(e=this.getID(),!e)throw"can not instantiate topic from instance which doesn't have ID";return new l.KiiTopicWithToken(this._getHttpURI(),t,this._authToken)},e.prototype.pushInstallation=function(){throw new l.UnsupportedOperationException("Push installation is not supported by admin context")},e}(l.KiiUser),l.KiiAnonymousUser=function(){function t(){this.getID=p(this.getID,this)}return t.prototype.getID=function(){return"ANONYMOUS_USER"},t}(),l.KiiAnyAuthenticatedUser=function(){function t(){this.getID=p(this.getID,this)}return t.prototype.getID=function(){return"ANY_AUTHENTICATED_USER"},t}(),l.KiiSDKClientInfo=function(){function t(){}return t.getSDKClientInfo=function(){return null==t._clientInfo&&(t._clientInfo="sn=jss;sv="+l.Kii.getSDKVersion()),t._clientInfo},t}(),l.KiiSCNTwitter=function(t){function e(){this._unlinkFromCurrentUser=p(this._unlinkFromCurrentUser,this),this._linkWithCurrentUser=p(this._linkWithCurrentUser,this),this._logOut=p(this._logOut,this),this._logIn=p(this._logIn,this),this._getAccessToken=p(this._getAccessToken,this),this._createTokenObject=p(this._createTokenObject,this),this._setup=p(this._setup,this),e.__super__.constructor.call(this,l.KiiSocialNetworkName.TWITTER)}return _(e,t),e.prototype._setup=function(t,i,n){return this._key=t,this._secret=i,this._extras=n,e.__super__._setup.call(this,this._key,this._secret,this._extras)},e.prototype._createTokenObject=function(t,e){var i;return i={oauth_token:t.oauth_token,oauth_token_secret:t.oauth_token_secret},null!=e&&null!=e.new_user_created&&(i.kii_new_user=e.new_user_created),i},e.prototype._getAccessToken=function(t){return t.oauth_token},e.prototype._logIn=function(t,e){var i;if(l.Kii.logger("Checking options"),l.Kii.logger(t),null==t||!t.oauth_token&&!t.oauth_token_secret)throw l.InvalidArgumentException("Both options.oauth_token and options.oauth_token_secret are required");if(!t.oauth_token)throw l.InvalidArgumentException("options.oauth_token is required");if(!t.oauth_token_secret)throw l.InvalidArgumentException("options.oauth_token_secret is required");return null!=l.KiiUser.getCurrentUser()&&l.KiiUser.logOut(),i={accessToken:t.oauth_token,accessTokenSecret:t.oauth_token_secret},this._register("twitter","application/vnd.kii.AuthTokenTwitterRequest+json",i,t,e)},e.prototype._logOut=function(){return e.__super__._logOut.apply(this,arguments),l.Kii.logger("Log out twitter")},e.prototype._linkWithCurrentUser=function(t,e){var i;if(null==l.KiiUser.getCurrentUser())return void e.failure(null,this._network,"No user logged in");if(null==t||!t.oauth_token&&!t.oauth_token_secret)throw l.InvalidArgumentException("Both options.oauth_token and options.oauth_token_secret are required");if(!t.oauth_token)throw l.InvalidArgumentException("options.oauth_token is required");if(!t.oauth_token_secret)throw l.InvalidArgumentException("options.oauth_token_secret is required");return i={accessToken:t.oauth_token,accessTokenSecret:t.oauth_token_secret},this._link("twitter","application/vnd.kii.LinkTwitterRequest+json",i,t,e)},e.prototype._unlinkFromCurrentUser=function(t){return null==l.KiiUser.getCurrentUser()?void t.failure(null,this._network,"No user logged in"):this._unlink("twitter",t)},e}(l.KiiSocialConnectNetwork),l.KiiGeoPoint=function(){function t(t,e){var i;if(this._latitude=t,this._longitude=e,this._toDict=p(this._toDict,this),this.getLongitude=p(this.getLongitude,this),this.getLatitude=p(this.getLatitude,this),i=function(t,e,i){return i>t&&e>i&&!isNaN(i)},!i(-90,90,this._latitude)||!i(-180,180,this._longitude))throw l.InvalidArgumentException("Specified latitide or longitude is invalid")}return t.prototype.getLatitude=function(){return this._latitude},t.prototype.getLongitude=function(){return this._longitude},t.geoPoint=function(t,e){return new l.KiiGeoPoint(t,e)},t.prototype._toDict=function(){var t;return t={_type:"point",lat:this._latitude,lon:this._longitude}},t}(),e=function(){function t(t,e,i){this.xhr=$.ajaxSettings.xhr(),e=s._disableCacheURL(e),this.xhr.open(t,e,!0),this.xhr.onreadystatechange=i.onComplete}return t}(),a=function(){function t(t,e,i){e=s._disableCacheURL(e),this.xhr=new XMLHttpRequest,"withCredentials"in this.xhr?(this.xhr.open(t,e,!0),this.xhr.onreadystatechange=i.onComplete):this.xhr=null}return t}(),r=function(){function t(t,e,i){this.xhr=Ti.Network.createHTTPClient(),e=s._disableCacheURL(e),this.xhr.open(t,e,!0),this.xhr.onload=i.onComplete,this.xhr.onerror=i.onError}return t}(),u=function(){function e(){}return e.createXHRWrapper=function(e,i){var r;return r=null,null===l.Kii._getHttpRequestType()?"undefined"!=typeof jQuery?(l.Kii.logger("Use jQuery "+e+":"+i),r=new t(e,i)):"undefined"!=typeof XMLHttpRequest?(l.Kii.logger("Use XMLHttpRequest "+e+":"+i),r=new o(e,i)):"undefined"!=typeof Titanium&&(l.Kii.logger("Use Titanium "+e+":"+i),r=new n(e,i)):(l.Kii.logger("Use http request backdoor"),l.Kii._getHttpRequestType()===l._KiiHttpRequestType.jQuery?(l.Kii.logger("Use jQuery "+e+":"+i),r=new t(e,i)):l.Kii._getHttpRequestType()===l._KiiHttpRequestType.XMLHttpRequest?(l.Kii.logger("Use XMLHttpRequest "+e+":"+i),r=new o(e,i)):l.Kii._getHttpRequestType()===l._KiiHttpRequestType.Titanium&&(l.Kii.logger("Use Titanium "+e+":"+i),r=new n(e,i))),r},e}(),o=function(){function t(t,e){this.setAuthToken=p(this.setAuthToken,this),this.setAdminOrUserToken=p(this.setAdminOrUserToken,this),this.setCurrentUserToken=p(this.setCurrentUserToken,this),this.setContentType=p(this.setContentType,this),this.setKiiHeaders=p(this.setKiiHeaders,this),this.getErrorCode=p(this.getErrorCode,this),this.getErrorString=p(this.getErrorString,this),this.sendData=p(this.sendData,this),this.send=p(this.send,this),this._setUpCallbacks=p(this._setUpCallbacks,this);var i,n,r;if(e=s._disableCacheURL(e),this.xhr=new XMLHttpRequest,this.method=t,"withCredentials"in this.xhr){if(this.xhr.open(t,e,!0),i=l.Kii.getAdditionalHeaders(),null!=i)for(n in i)r=i[n],this.xhr.setRequestHeader(n,r)}else this.xhr=null}return t.prototype.getAppID=function(){return l.Kii.getAppID()},t.prototype.getAppKey=function(){return l.Kii.getAppKey()},t.prototype.getLogger=function(){return l.Kii.logger()},t.prototype._setUpCallbacks=function(t){return t&&t.progress?"PUT"===this.method?this.xhr.upload.addEventListener("progress",t.progress,!1):this.xhr.addEventListener("progress",t.progress,!1):void 0},t.prototype.send=function(t){var e;return this._setUpCallbacks(t),e={onComplete:function(e){return function(){var i;if(4===e.xhr.readyState)if(200<=(i=e.xhr.status)&&400>i){if(e.getLogger("Completed Request["+e.xhr.status+"]"),null!=t)return t.success()}else if(e.getLogger("Error loading data..."),e.getLogger("callback : "+t),null!=t)return t.failure()}}(this)},this.xhr.onreadystatechange=e.onComplete,this.xhr.send()},t.prototype.sendData=function(t,e){var i;return this.getLogger("SENDING:"),this.getLogger(JSON.stringify(t)),this._setUpCallbacks(e),i={onComplete:function(t){return function(){var i;if(4===t.xhr.readyState)if(200<=(i=t.xhr.status)&&400>i){if(t.getLogger("Completed Request["+t.xhr.status+"]"),null!=e)return e.success()}else if(t.getLogger("Error loading data..."),null!=e)return e.failure()}}(this)},this.xhr.onreadystatechange=i.onComplete,this.xhr.send(t)},t.prototype.getErrorString=function(t){var e,i;e=""+t+" failed. statusCode: "+this.xhr.status;try{return i=JSON.parse(decodeURIComponent(this.xhr.responseText)),null!=i.errorCode&&(e+=" error code: "+i.errorCode),null!=i.message&&(e+=" message: "+i.message),e}catch(n){return e}},t.prototype.getErrorCode=function(){var t;try{return t=JSON.parse(decodeURIComponent(this.xhr.responseText)),t.errorCode}catch(e){return null}},t.prototype.setKiiHeaders=function(){return this.xhr.setRequestHeader("x-kii-appid",this.getAppID()),this.xhr.setRequestHeader("x-kii-appkey",this.getAppKey()),this.xhr.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo())},t.prototype.setContentType=function(t){return this.xhr.setRequestHeader("Content-Type",t)},t.prototype.setCurrentUserToken=function(){var t,e;return t=null!=(e=this.getCurrentUser())?e.getAccessToken():void 0,null!=t?(this.xhr.setRequestHeader("authorization","bearer "+t),!0):!1},t.prototype.setAdminOrUserToken=function(t){var e,i;return e=null!=t?t._getToken():null!=(i=this.getCurrentUser())?i.getAccessToken():void 0,null!=e?(this.xhr.setRequestHeader("authorization","bearer "+e),!0):!1},t.prototype.setAuthToken=function(t){return null!=t?this.xhr.setRequestHeader("authorization","bearer "+t):void 0},t.prototype.getCurrentUser=function(){return l.KiiUser.getCurrentUser()},t}(),n=function(t){function e(t,e){this.sendData=p(this.sendData,this),this.send=p(this.send,this);var i,n,r;if(e=s._disableCacheURL(e),this.xhr=Ti.Network.createHTTPClient(),this.method=t,this.xhr.open(t,e,!0),i=l.Kii.getAdditionalHeaders(),null!=i)for(n in i)r=i[n],this.xhr.setRequestHeader(n,r)}return _(e,t),e.prototype.send=function(t){var e;return this._setUpCallbacks(t),e={onComplete:function(e){return function(){var i;if(4===e.xhr.readyState)if(200<=(i=e.xhr.status)&&400>i){if(l.Kii.logger("Completed Request["+e.xhr.status+"]"),null!=t)return t.success()}else if(l.Kii.logger("Error loading data..."),l.Kii.logger("callback : "+t),null!=t)return t.failure()}}(this),onError:function(e){return function(){return l.Kii.logger("Error loading data..."),l.Kii.logger("callback : "+t),null!=t?t.failure():void 0}}(this)},this.xhr.onload=e.onComplete,this.xhr.onerror=e.onError,this.xhr.send()},e.prototype.sendData=function(t,e){var i;return this._setUpCallbacks(e),i={onComplete:function(t){return function(){var i;if(4===t.xhr.readyState)if(200<=(i=t.xhr.status)&&400>i){if(l.Kii.logger("Completed Request["+t.xhr.status+"]"),null!=e)return e.success()}else if(l.Kii.logger("Error loading data..."),null!=e)return e.failure()}}(this),onError:function(t){return function(){return l.Kii.logger("Error loading data..."),l.Kii.logger("callback : "+e),null!=e?e.failure():void 0}}(this)},this.xhr.onload=i.onComplete,this.xhr.onerror=i.onError,this.xhr.send(t)},e}(o),t=function(t){function e(t,e){var i,n,r;if(e=s._disableCacheURL(e),this.xhr=$.ajaxSettings.xhr(),this.xhr.open(t,e,!0),this.method=t,i=l.Kii.getAdditionalHeaders(),null!=i)for(n in i)r=i[n],this.xhr.setRequestHeader(n,r)}return _(e,t),e}(o),l.KiiSCNQQ=function(t){function e(){this._unlinkFromCurrentUser=p(this._unlinkFromCurrentUser,this),this._linkWithCurrentUser=p(this._linkWithCurrentUser,this),this._logOut=p(this._logOut,this),this._logIn=p(this._logIn,this),this._getAccessToken=p(this._getAccessToken,this),this._createTokenObject=p(this._createTokenObject,this),this._setup=p(this._setup,this),e.__super__.constructor.call(this,l.KiiSocialNetworkName.QQ)}return _(e,t),e.prototype._setup=function(t,i,n){return this._key=t,this._secret=i,this._extras=n,e.__super__._setup.call(this,this._key,this._secret,this._extras)},e.prototype._createTokenObject=function(t,e){var i;return i={access_token:t.access_token,openID:t.openID},null!=e&&null!=e.new_user_created&&(i.kii_new_user=e.new_user_created),i},e.prototype._getAccessToken=function(t){return t.access_token},e.prototype._logIn=function(t,e){var i;if(l.Kii.logger("Checking options"),l.Kii.logger(t),null==t||!t.access_token&&!t.openID)throw l.InvalidArgumentException("Both options.access_token and options.openID are required");if(!t.access_token)throw l.InvalidArgumentException("options.access_token is required");if(!t.openID)throw l.InvalidArgumentException("options.openID is required");return null!=l.KiiUser.getCurrentUser()&&l.KiiUser.logOut(),i={accessToken:t.access_token,openID:t.openID},this._register("qq","application/vnd.kii.AuthTokenQQRequest+json",i,t,e)},e.prototype._logOut=function(){return e.__super__._logOut.apply(this,arguments),l.Kii.logger("Log out qq")},e.prototype._linkWithCurrentUser=function(t,e){var i;if(null==l.KiiUser.getCurrentUser())return void e.failure(null,this._network,"No user logged in");
if(null==t||!t.access_token&&!t.openID)throw l.InvalidArgumentException("Both options.access_token and options.openID are required");if(!t.access_token)throw l.InvalidArgumentException("options.access_token is required");if(!t.openID)throw l.InvalidArgumentException("options.openID is required");return i={accessToken:t.access_token,openID:t.openID},this._link("qq","application/vnd.kii.LinkQQRequest+json",i,t,e)},e.prototype._unlinkFromCurrentUser=function(t){return null==l.KiiUser.getCurrentUser()?void t.failure(null,this._network,"No user logged in"):this._unlink("qq",t)},e}(l.KiiSocialConnectNetwork),l.KiiServerCodeEntry=function(){function t(t,e,i){this.entryName=t,this.version=e,this.environmentVersion=i}return t.prototype.execute=function(t,e){return new Promise(function(i){return function(n,r){var o;return o={success:function(){return null!=e&&e.success.apply(e,arguments),n(arguments)},failure:function(){var t;return null!=e&&e.failure.apply(e,arguments),t=s._Error(arguments[3],i),t.argument=arguments[1],r(t)}},i._executeUsingCallbacks(t,o)}}(this))},t.prototype._executeUsingCallbacks=function(t,e){var i,n,r,o,a,h,c,p;return s._validateServerCodeEntryArgument(t)?(n=null!=t?t:{},a=null!=(p=this.version)?p:"current",i=JSON.stringify(n),o=l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+("/server-code/versions/"+a+"/"+this.entryName),this.environmentVersion&&(o+="?environment-version="+this.environmentVersion),h=u.createXHRWrapper("POST",o),c=h.xhr,c.setRequestHeader("x-kii-appid",l.Kii.getAppID()),c.setRequestHeader("x-kii-appkey",l.Kii.getAppKey()),c.setRequestHeader("x-kii-sdk",l.KiiSDKClientInfo.getSDKClientInfo()),c.setRequestHeader("Content-Type","application/json"),null!=l.KiiUser.getCurrentUser()&&c.setRequestHeader("Authorization","Bearer "+l.KiiUser.getCurrentUser().getAccessToken()),r={success:function(i){return function(){var n,r,s,o,u;u=c.getResponseHeader("x-step-count"),n=c.getResponseHeader("x-environment-version");try{if(o=JSON.parse(c.responseText),s=new l.KiiServerCodeExecResult(o,u,n),null!=e)return e.success(i,t,s)}catch(a){if(null!=e)return r="fail to parse response. statusCode: "+c.status+" executedSteps: "+u+" error code: failed_to_parse_response response: "+c.responseText,e.failure(i,t,null,r)}}}(this),failure:function(i){return function(){var n,r,s,o;o=c.getResponseHeader("x-step-count"),n={statusCode:c.status,executedSteps:o},r="fail to execute server code. statusCode: "+c.status+" executedSteps: "+o;try{if(s=JSON.parse(c.responseText),null!=s.errorCode&&(r+=" error code: "+s.errorCode),null!=s.message&&(r+=" message: "+s.message),null!=s.details&&null!=s.details.message)return r+=" detailMessage: "+s.details.message}catch(u){return r+=" error code: failed_to_parse_response message: "+c.responseText}finally{null!=e&&e.failure(i,t,null,r)}}}(this)},h.sendData(i,r)):e.failure(this,t,null,l.InvalidArgumentException("arugment is invalid"))},t.prototype.getEntryName=function(){return this.entryName},t}(),l.KiiServerCodeExecResult=function(){function t(t,e,i){this.returnObject=t,this.exeSteps=e,this.environmentVersion=i}return t.prototype.getExecutedSteps=function(){return this.exeSteps},t.prototype.getEnvironmentVersion=function(){return this.environmentVersion},t.prototype.getReturnedValue=function(){return this.returnObject},t}(),l.KiiThing=function(){function t(t){this.fields=t,this._getSubscriberPath=p(this._getSubscriberPath,this),this._setAuthToken=p(this._setAuthToken,this),this._getHttpURI=p(this._getHttpURI,this),this.pushSubscription=p(this.pushSubscription,this),this._listTopicsUsingCallbacks=p(this._listTopicsUsingCallbacks,this),this.listTopics=p(this.listTopics,this),this.topicWithName=p(this.topicWithName,this),this.encryptedBucketWithName=p(this.encryptedBucketWithName,this),this.bucketWithName=p(this.bucketWithName,this),this.updatePassword=p(this.updatePassword,this),this._changeStatus=p(this._changeStatus,this),this.enable=p(this.enable,this),this.disable=p(this.disable,this),this.unregisterOwner=p(this.unregisterOwner,this),this._getOwnerURL=p(this._getOwnerURL,this),this.registerOwnerWithPassword=p(this.registerOwnerWithPassword,this),this.registerOwner=p(this.registerOwner,this),this.isOwner=p(this.isOwner,this),this.deleteThing=p(this.deleteThing,this),this.update=p(this.update,this),this._refresh=p(this._refresh,this),this.refresh=p(this.refresh,this),this.getOnlineStatusModifiedAt=p(this.getOnlineStatusModifiedAt,this),this.isOnline=p(this.isOnline,this),this.getDisabled=p(this.getDisabled,this),this.getCreated=p(this.getCreated,this),this.getAccessToken=p(this.getAccessToken,this),this.getVendorThingID=p(this.getVendorThingID,this),this.getThingID=p(this.getThingID,this),this._renewThingFields=p(this._renewThingFields,this),null!=this.fields&&this._renewThingFields(this.fields)}return t.prototype._renewThingFields=function(t){return this._online=null,this._onlineStatusModifiedAt=null,this.fields=t,this._thingID=t._thingID,this._vendorThingID=t._vendorThingID,this._accessToken=t._accessToken,this._created=new Date(t._created),this._disabled=t._disabled,null!=t._online&&(this._online=t._online),null!=t._onlineStatusModifiedAt&&(this._onlineStatusModifiedAt=new Date(t._onlineStatusModifiedAt)),delete this.fields._thingID,delete this.fields._vendorThingID,delete this.fields._accessToken,delete this.fields._created,delete this.fields._disabled},t.prototype.getThingID=function(){return this._thingID},t.prototype.getVendorThingID=function(){return this._vendorThingID},t.prototype.getAccessToken=function(){return this._accessToken},t.prototype.getCreated=function(){return this._created},t.prototype.getDisabled=function(){return this._disabled},t.prototype.isOnline=function(){return this._online},t.prototype.getOnlineStatusModifiedAt=function(){return this._onlineStatusModifiedAt},t.register=function(t,e){return new Promise(function(i,n){var r,o;return o=u.createXHRWrapper("POST",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things"),o.setKiiHeaders(),o.setContentType("application/vnd.kii.ThingRegistrationAndAuthorizationRequest+json"),r={success:function(){var t,n;return t=JSON.parse(decodeURIComponent(o.xhr.responseText)),n=new l.KiiThing(t),null!=e&&e.success(n),i(n)},failure:function(){var t,i;return i=o.getErrorString("register thing"),t=s._Error(i),null!=e&&e.failure(t),n(t)}},o.sendData(JSON.stringify(t),r)})},t.executeQuery=function(t,e){return new Promise(function(i,n){var r,o,a;return null==t?(r=s._Error("thingQuery is null"),null!=e&&e.failure(r),void n(r)):(a=u.createXHRWrapper("POST",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things/query"),a.setKiiHeaders(),a.setCurrentUserToken(),a.setContentType("application/vnd.kii.ThingQueryRequest+json"),o={success:function(){var n,r,s,o,u,h,c;for(r=JSON.parse(decodeURIComponent(a.xhr.responseText)),o=[],c=r.results,u=0,h=c.length;h>u;u++)s=c[u],o.push(new l.KiiThing(s));return n=new l.KiiThingQueryResult(t,o,r.nextPaginationKey),null!=e&&e.success(n),i(n)},failure:function(){var t;return t=a.getErrorString("query thing"),r=s._Error(t),null!=e&&e.failure(r),n(r)}},a.sendData(JSON.stringify(t._dictValue()),o))})},t.prototype.refresh=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(n){return e._renewThingFields(n),null!=t&&t.success(e),i(e)},failure:function(i){var r;return r=s._Error(i,e),null!=t&&t.failure(r),n(r)}},e._refresh(r)}}(this))},t.prototype._refresh=function(t){var e,i,n;return e=null!=this._thingID?this._thingID:"VENDOR_THING_ID:"+this._vendorThingID,n=u.createXHRWrapper("GET",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things/"+e),n.setKiiHeaders(),this._setAuthToken(n),i={success:function(e){return function(){var e;return e=JSON.parse(decodeURIComponent(n.xhr.responseText)),t.success(e)}}(this),failure:function(e){return function(){var e;return e=n.getErrorString("refresh thing"),t.failure(e)}}(this)},n.send(i)},t.prototype.update=function(t){return new Promise(function(e){return function(i,n){var r;return r={success:function(r){var o,a,h,c,p;p=e.fields;for(o in p)h=p[o],r[o]=h;return e.fields=r,c=u.createXHRWrapper("PATCH",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things/"+e._thingID),c.setKiiHeaders(),c.setContentType("application/vnd.kii.ThingUpdateRequest+json"),e._setAuthToken(c),a={success:function(){return null!=t&&t.success(e),i(e)},failure:function(){var i,r;return r=c.getErrorString("update thing"),i=s._Error(r,e),null!=t&&t.failure(i),n(i)}},c.sendData(JSON.stringify(e.fields),a),"function"==typeof e._testOnUpdateRequest?e._testOnUpdateRequest():void 0},failure:function(i){var r;return r=s._Error(i,e),null!=t&&t.failure(r),n(r)}},e._refresh(r)}}(this))},t.prototype.deleteThing=function(t){return new Promise(function(e){return function(i,n){var r,o;return o=u.createXHRWrapper("DELETE",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things/"+e._thingID),o.setKiiHeaders(),e._setAuthToken(o),r={success:function(){return null!=t&&t.success(e),i(e)},failure:function(){var i,r;return r=o.getErrorString("delete thing"),i=s._Error(r,e),null!=t&&t.failure(i),n(i)}},o.send(r)}}(this))},t.prototype.isOwner=function(t,e){return new Promise(function(i){return function(n,r){var o,a,l,h,c;try{l=i._getOwnerURL(i._thingID,t)}catch(p){return a=p,o=s._Error(a,i),null!=e&&e.failure(o),void r(o)}return c=u.createXHRWrapper("HEAD",l),c.setKiiHeaders(),i._setAuthToken(c),h={success:function(){return null!=e&&e.success(i,t,!0),n([i,t,!0])},failure:function(){var u;return 404===c.xhr.status?(null!=e&&e.success(i,t,!1),void n([i,t,!1])):(u=c.getErrorString("register owner"),o=s._Error(u,i),null!=e&&e.failure(o),r(o))}},c.send(h)}}(this))},t.prototype.registerOwner=function(t,e){return new Promise(function(i){return function(n,r){var o,a,l,h,c;try{l=i._getOwnerURL(i._thingID,t)}catch(p){return a=p,o=s._Error(a,i),null!=e&&e.failure(o),void r(o)}return c=u.createXHRWrapper("PUT",l),c.setKiiHeaders(),i._setAuthToken(c),h={success:function(){return null!=e&&e.success(i,t),n([i,t])},failure:function(){var t;return t=c.getErrorString("register owner"),o=s._Error(t,i),null!=e&&e.failure(o),r(o)}},c.send(h)}}(this))},t.prototype.registerOwnerWithPassword=function(t,e,i){return new Promise(function(n){return function(r,s){var o;return o={success:function(){return null!=i&&i.success(n,t),r([n,t])},failure:function(t){return null!=i&&i.failure(t),s(t)}},l.KiiThing._registerOwnerWithIdentifierAndPassword(n._thingID,t,e,o)}}(this))},t.registerOwnerWithThingID=function(t,e,i){return l.KiiThing._registerOwnerWithIdentifier(t,e,i)},t.registerOwnerWithThingIDAndPassword=function(t,e,i,n){return l.KiiThing._registerOwnerWithIdentifierAndPassword(t,e,i,n)},t.registerOwnerWithVendorThingID=function(t,e,i){return s._isNonEmptyString(t)?l.KiiThing._registerOwnerWithIdentifier("VENDOR_THING_ID:"+t,e,i):l.KiiThing._registerOwnerWithIdentifier(null,e,i)},t.registerOwnerWithVendorThingIDAndPassword=function(t,e,i,n){return s._isNonEmptyString(t)?l.KiiThing._registerOwnerWithIdentifierAndPassword("VENDOR_THING_ID:"+t,e,i,n):l.KiiThing._registerOwnerWithIdentifierAndPassword(null,e,i,n)},t._registerOwnerWithIdentifier=function(t,e,i){return new Promise(function(n,r){var o,a,h,c,p;if(!s._isNonEmptyString(t))return o=s._Error("identifier is null or empty"),null!=i&&i.failure(o),void r(o);if(null==e)return o=s._Error("owner is null"),null!=i&&i.failure(o),void r(o);try{h=l.KiiThing.prototype._getOwnerURL(t,e)}catch(f){return a=f,o=s._Error(a),null!=i&&i.failure(o),void r(o)}return p=u.createXHRWrapper("PUT",h),p.setKiiHeaders(),l.KiiThing.prototype._setAuthToken(p),c={success:function(){return null!=i&&i.success(e),n([e])},failure:function(){var t;return t=p.getErrorString("register owner"),o=s._Error(t),null!=i&&i.failure(o),r(o)}},p.send(c)})},t._registerOwnerWithIdentifierAndPassword=function(t,e,i,n){return new Promise(function(r,o){var a,h,c,p,f;if(!s._isNonEmptyString(t))return a=s._Error("identifier is null or empty"),null!=n&&n.failure(a),void o(a);if(null==e)return a=s._Error("owner is null"),null!=n&&n.failure(a),void o(a);if(!s._isNonEmptyString(i))return a=s._Error("password is null or empty"),null!=n&&n.failure(a),void o(a);if(p=""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things/"+t+"/ownership",f=u.createXHRWrapper("POST",p),f.setKiiHeaders(),f.setContentType("application/vnd.kii.ThingOwnershipRequest+json"),l.KiiThing.prototype._setAuthToken(f),h={thingPassword:i},e instanceof l.KiiUser)h.userID=e.getID();else{if(!(e instanceof l.KiiGroup))return a=s._Error("owner should be instance of KiiUser or KiiGroup"),null!=n&&n.failure(a),void o(a);h.groupID=e.getID()}return c={success:function(){return null!=n&&n.success(e),r(e)},failure:function(){var t;return t=f.getErrorString("register owner"),a=s._Error(t),null!=n&&n.failure(a),o(a)}},f.sendData(JSON.stringify(h),c)})},t.prototype._getOwnerURL=function(t,e){var i,n;if(e instanceof l.KiiUser)i=e.getID(),n="user";else{if(!(e instanceof l.KiiGroup))throw"owner should be instance of user or group";i=e.getID(),n="group"}if(null==i)throw"owner instance does not have id";return""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things/"+t+"/ownership/"+n+":"+i},t.prototype.unregisterOwner=function(t,e){return new Promise(function(i){return function(n,r){var o,a,l,h,c;try{l=i._getOwnerURL(i._thingID,t)}catch(p){return a=p,o=s._Error(a,i),null!=e&&e.failure(o),void r(o)}return c=u.createXHRWrapper("DELETE",l),c.setKiiHeaders(),i._setAuthToken(c),h={success:function(){return null!=e&&e.success(i,t),n([i,t])},failure:function(){var t;return t=c.getErrorString("unregister owner"),o=s._Error(t,i),null!=e&&e.failure(o),r(o)}},c.send(h)}}(this))},t.prototype.disable=function(t){return this._changeStatus(!0,t)},t.prototype.enable=function(t){return this._changeStatus(!1,t)},t.prototype._changeStatus=function(t,e){return new Promise(function(i){return function(n,r){var o,a,h;return h=u.createXHRWrapper("PUT",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things/"+i._thingID+"/status"),h.setKiiHeaders(),i._setAuthToken(h),h.setContentType("application/vnd.kii.ThingStatusUpdateRequest+json"),a={success:function(){return i._disabled=t,null!=e&&e.success(i),n(i)},failure:function(){var n,o;return o=h.getErrorString("disable thing "+t),n=s._Error(o,i),null!=e&&e.failure(n),r(n)}},o={disabled:t},h.sendData(JSON.stringify(o),a)}}(this))},t.prototype.updatePassword=function(t,e){var i;return i=s._Error("updatePassword can be used only by app admin."),null!=e&&e.failure(i),Promise.reject(i)},t.loadWithVendorThingID=function(t,e){var i;return i="VENDOR_THING_ID:"+t,l.KiiThing._load(i,e)},t.loadWithThingID=function(t,e){return l.KiiThing._load(t,e)},t._load=function(t,e){return new Promise(function(i,n){var r,o;return o=u.createXHRWrapper("GET",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things/"+t),o.setKiiHeaders(),l.KiiThing.prototype._setAuthToken(o),r={success:function(){var t,n;return t=JSON.parse(decodeURIComponent(o.xhr.responseText)),n=new l.KiiThing(t),null!=e&&e.success(n),i(n)},failure:function(){var t,i;return i=o.getErrorString("load thing"),t=s._Error(i),null!=e&&e.failure(t),n(t)}},o.send(r)})},t.prototype.bucketWithName=function(t){return new l.KiiBucket._bucketWithName(t,this)},t.prototype.encryptedBucketWithName=function(t){return new l.KiiEncryptedBucket(t,this)},t.prototype.topicWithName=function(t){if("string"!=typeof t||""===t)throw new l.InvalidArgumentException("topicName should not null or empty");return new l.KiiTopic(this._getHttpURI(),t)},t.prototype.listTopics=function(t,e){return new Promise(function(i){return function(n,r){var s;return s={success:function(){return null!=t&&t.success.apply(t,arguments),n(arguments)},failure:function(){return null!=t&&t.failure.apply(t,arguments),r(arguments[0])}},i._listTopicsUsingCallbacks(s,e)}}(this))},t.prototype._listTopicsUsingCallbacks=function(t,e){var i,n,r;return n=""+this._getHttpURI()+"/topics","string"==typeof e&&""!==e&&(n=n+"?paginationKey="+encodeURIComponent(e)),r=u.createXHRWrapper("GET",n),r.setKiiHeaders(),this._setAuthToken(r),i={success:function(e){return function(){var i,n,s,o,u,a;for(i=JSON.parse(r.xhr.responseText),s=[],a=i.topics,o=0,u=a.length;u>o;o++)n=a[o],s.push(e.topicWithName(n.topicID));return null!=t?t.success(s,void 0===i.paginationKey?null:i.paginationKey):void 0}}(this),failure:function(e){return function(){var i,n;return n=r.getErrorString("list topics"),i=s._Error(n,e),null!=t?t.failure(i):void 0}}(this)},r.send(i)},t.prototype.pushSubscription=function(){return new l.KiiPushSubscription(this)},t.prototype._getHttpURI=function(){return""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things/"+this.getThingID()},t.thingWithID=function(t){var e;if(null==t||""===t)throw new l.InvalidArgumentException("thingID should not null or empty");return e=new l.KiiThing,e._thingID=t,e},t.prototype._setAuthToken=function(t){return t.setCurrentUserToken()},t.prototype._getSubscriberPath=function(){return"things/"+this.getThingID()},t}(),l.KiiTopic=function(){function t(t,e){this._getHttpUri=p(this._getHttpUri,this),this._setAuthToken=p(this._setAuthToken,this),this.acl=p(this.acl,this),this.deleteTopic=p(this.deleteTopic,this),this.sendMessage=p(this.sendMessage,this),this.save=p(this.save,this),this.exists=p(this.exists,this),this.getName=p(this.getName,this),this._uri=""+t+"/topics/"+e,this._name=e}return t.prototype.getName=function(){return this._name},t.prototype.exists=function(t){return new Promise(function(e){return function(i,n){var r,o;return o=u.createXHRWrapper("HEAD",e._uri),o.setKiiHeaders(),e._setAuthToken(o),r={success:function(){return null!=t&&t.success(!0),i(!0)},failure:function(){var r,u;return 404===o.xhr.status?(null!=t&&t.success(!1),void i(!1)):(u=o.getErrorString("check topic"),r=s._Error(u,e),null!=t&&t.failure(r),n(r))}},o.send(r)}}(this))},t.prototype.save=function(t){return new Promise(function(e){return function(i,n){var r,o;return o=u.createXHRWrapper("PUT",e._uri),o.setKiiHeaders(),e._setAuthToken(o),r={success:function(){return null!=t&&t.success(e),i(e)},failure:function(){var i,r;return r=o.getErrorString("save topic"),i=s._Error(r,e),null!=t&&t.failure(i),n(i)}},o.send(r)}}(this))},t.prototype.sendMessage=function(t,e){return new Promise(function(i){return function(n,r){var o,a;return a=u.createXHRWrapper("POST",""+i._uri+"/push/messages"),a.setKiiHeaders(),i._setAuthToken(a),a.setContentType("application/vnd.kii.SendPushMessageRequest+json"),o={success:function(){return null!=e&&e.success(i,t),n([i,t])},failure:function(){var t,n;return n=a.getErrorString("send messages"),t=s._Error(n,i),null!=e&&e.failure(t),r(t)}},a.sendData(JSON.stringify(t),o)}}(this))},t.prototype.deleteTopic=function(t){return new Promise(function(e){return function(i,n){var r,o;return o=u.createXHRWrapper("DELETE",e._uri),o.setKiiHeaders(),e._setAuthToken(o),r={success:function(){return null!=t&&t.success(e),i(e)},failure:function(){var i,r;return r=o.getErrorString("delete topic"),i=s._Error(r,e),null!=t&&t.failure(i),n(i)}},o.send(r)}}(this))},t.prototype.acl=function(){return l.KiiACL.aclWithParent(this)},t.prototype._setAuthToken=function(t){return t.setCurrentUserToken()},t.prototype._getHttpUri=function(){return this._uri},t}(),l.KiiPushMessageBuilder=function(){function t(t){this.data=t,this.mqttData=p(this.mqttData,this),this.jpushData=p(this.jpushData,this),this.apnsMutableContent=p(this.apnsMutableContent,this),this.apnsCategory=p(this.apnsCategory,this),this.apnsContentAvailable=p(this.apnsContentAvailable,this),this.apnsBadge=p(this.apnsBadge,this),this.apnsSound=p(this.apnsSound,this),this.apnsAlert=p(this.apnsAlert,this),this.apnsData=p(this.apnsData,this),this.gcmRestrictedPackageName=p(this.gcmRestrictedPackageName,this),this.gcmTimeToLive=p(this.gcmTimeToLive,this),this.gcmDelayWhileIdle=p(this.gcmDelayWhileIdle,this),this.gcmCollapseKey=p(this.gcmCollapseKey,this),this.gcmData=p(this.gcmData,this),this.enableMqtt=p(this.enableMqtt,this),this.enableJpush=p(this.enableJpush,this),this.enableApns=p(this.enableApns,this),this.enableGcm=p(this.enableGcm,this),this.setSendToProduction=p(this.setSendToProduction,this),this.setSendToDevelopment=p(this.setSendToDevelopment,this),this.build=p(this.build,this),this.gcm={},this.apns={},this.jpush={},this.mqtt={},this.gcm.enabled=!0,this.apns.enabled=!0,this.jpush.enabled=!0,this.mqtt.enabled=!0}return t.prototype.build=function(){var t;return t={},t.data=this.data,t.gcm=this.gcm,t.apns=this.apns,t.jpush=this.jpush,t.mqtt=this.mqtt,null!=this.sendToDevelopment&&(t.sendToDevelopment=this.sendToDevelopment),null!=this.sendToProduction&&(t.sendToProduction=this.sendToProduction),t},t.prototype.setSendToDevelopment=function(t){return this.sendToDevelopment=t,this},t.prototype.setSendToProduction=function(t){return this.sendToProduction=t,this},t.prototype.enableGcm=function(t){return this.gcm.enabled=t,this},t.prototype.enableApns=function(t){return this.apns.enabled=t,this},t.prototype.enableJpush=function(t){return this.jpush.enabled=t,this},t.prototype.enableMqtt=function(t){return this.mqtt.enabled=t,this},t.prototype.gcmData=function(t){return this.gcm.data=t,this},t.prototype.gcmCollapseKey=function(t){return this.gcm.collapseKey=t,this},t.prototype.gcmDelayWhileIdle=function(t){return this.gcm.delayWhileIdle=t,this},t.prototype.gcmTimeToLive=function(t){return this.gcm.timeToLive=t,this},t.prototype.gcmRestrictedPackageName=function(t){return this.gcm.restrictedPackageName=t,this},t.prototype.apnsData=function(t){return this.apns.data=t,this},t.prototype.apnsAlert=function(t){return this.apns.alert=t,this},t.prototype.apnsSound=function(t){return this.apns.sound=t,this},t.prototype.apnsBadge=function(t){return this.apns.badge=t,this},t.prototype.apnsContentAvailable=function(t){return t>0?this.apns.contentAvailable=!0:delete this.apns.contentAvailable,this},t.prototype.apnsCategory=function(t){return this.apns.category=t,this},t.prototype.apnsMutableContent=function(t){return t>0?this.apns.mutableContent=!0:delete this.apns.mutableContent,this},t.prototype.jpushData=function(t){return this.jpush.data=t,this},t.prototype.mqttData=function(t){return this.mqtt.data=t,this},t}(),l.KiiPushSubscription=function(){function t(t){this._subscriber=t,this._setAuthToken=p(this._setAuthToken,this),this._getRequestHTTPURI=p(this._getRequestHTTPURI,this),this._validateTarget=p(this._validateTarget,this),this.isSubscribed=p(this.isSubscribed,this),this.unsubscribe=p(this.unsubscribe,this),this.subscribe=p(this.subscribe,this)}return t.prototype.getSubscriber=function(){return this._subscriber},t.prototype.subscribe=function(t,e){return new Promise(function(i){return function(n,r){var o,a,h;return i._validateTarget(t)?(o=i._getRequestHTTPURI(t),h=u.createXHRWrapper("PUT",o),h.setKiiHeaders(),i._setAuthToken(h),a={success:function(){return null!=e&&e.success(i,t),n([i,t])},failure:function(){var t,n;return n=h.getErrorString("subscribe"),t=s._Error(n,i),null!=e&&e.failure(t),r(t)}},h.send(a)):(null!=e&&e.failure(l.InvalidArgumentException("target is invalid")),void r(s._Error(l.InvalidArgumentException("target is invalid"),i)))}}(this))},t.prototype.unsubscribe=function(t,e){return new Promise(function(i){return function(n,r){var o,a,h;return i._validateTarget(t)?(o=i._getRequestHTTPURI(t),h=u.createXHRWrapper("DELETE",o),h.setKiiHeaders(),i._setAuthToken(h),a={success:function(){return null!=e&&e.success(i,t),n([i,t])},failure:function(){var t,n;return n=h.getErrorString("unsubscribe"),t=s._Error(n,i),null!=e&&e.failure(t),r(t)}},h.send(a)):(null!=e&&e.failure(l.InvalidArgumentException("target is invalid")),void r(s._Error(l.InvalidArgumentException("target is invalid"),i)))}}(this))},t.prototype.isSubscribed=function(t,e){return new Promise(function(i){return function(n,r){var o,a,h;return i._validateTarget(t)?(o=i._getRequestHTTPURI(t),h=u.createXHRWrapper("GET",o),h.setKiiHeaders(),i._setAuthToken(h),a={success:function(){return null!=e&&e.success(i,t,!0),n([i,t,!0])},failure:function(){var o,u,a;return a=h.getErrorCode(),"FILTER_NOT_FOUND"===a||"PUSH_SUBSCRIPTION_NOT_FOUND"===a?(null!=e&&e.success(i,t,!1),n([i,t,!1])):(u=h.getErrorString("Check is subscribed"),o=s._Error(u,i),null!=e&&e.failure(o),r(o))}},h.send(a)):(null!=e&&e.failure(l.InvalidArgumentException("target is invalid")),void r(s._Error(l.InvalidArgumentException("target is invalid"),i)))}}(this))},t.prototype._validateTarget=function(t){return null!=t&&(t instanceof l.KiiBucket||t instanceof l.KiiTopic)},t.prototype._getRequestHTTPURI=function(t){var e;return t instanceof l.KiiBucket?e=""+t._getHttpUri()+"/filters/all/push/subscriptions/"+this._subscriber._getSubscriberPath():t instanceof l.KiiTopic?e=""+t._getHttpUri()+"/push/subscriptions/"+this._subscriber._getSubscriberPath():void 0},t.prototype._setAuthToken=function(t){return t.setCurrentUserToken()},t}(),l.KiiThingWithToken=function(t){function e(t,i,n,r){this._adminToken=r,this._getIdentifier=p(this._getIdentifier,this),this.updatePassword=p(this.updatePassword,this),this.topicWithName=p(this.topicWithName,this),this.bucketWithName=p(this.bucketWithName,this),this.pushSubscription=p(this.pushSubscription,this),this._setAuthToken=p(this._setAuthToken,this),e.__super__.constructor.call(this,t),null!=i&&(this._thingID=i),null!=n&&(this._vendorThingID=n)}return _(e,t),e.register=function(t,e,i){return new Promise(function(n,r){var o,a;return a=u.createXHRWrapper("POST",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things"),a.setKiiHeaders(),a.setContentType("application/vnd.kii.ThingRegistrationAndAuthorizationRequest+json"),a.setAuthToken(i),o={success:function(){var t,r;return t=JSON.parse(decodeURIComponent(a.xhr.responseText)),r=new l.KiiThingWithToken(t,null,null,i),null!=e&&e.success(r),n(r)},failure:function(){var t,i;return i=a.getErrorString("register thing"),t=s._Error(i),null!=e&&e.failure(t),r(t)}},a.sendData(JSON.stringify(t),o)})},e.registerOwnerWithThingID=function(t,e,i,n){return l.KiiThingWithToken._registerOwnerWithIdentifier(t,e,i,n)},e.registerOwnerWithVendorThingID=function(t,e,i,n){return l.KiiThingWithToken._registerOwnerWithIdentifier("VENDOR_THING_ID:"+t,e,i,n)},e._registerOwnerWithIdentifier=function(t,e,i,n){return new Promise(function(r,o){var a,h,c,p;if(e instanceof l.KiiUser)a=e.getID(),c="user";else{if(!(e instanceof l.KiiGroup))throw"owner should be instance of user or group";a=e.getID(),c="group"}if(null==a)throw"owner instance does not have id";return p=u.createXHRWrapper("PUT",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things/"+t+"/ownership/"+c+":"+a),p.setKiiHeaders(),p.setAuthToken(n),h={success:function(){return null!=i&&i.success(e),r([e])},failure:function(){var t,e;return e=p.getErrorString("register owner"),t=s._Error(e),null!=i&&i.failure(t),o(t)}},p.send(h)})},e.loadWithVendorThingID=function(t,e,i){var n;return n=new l.KiiThingWithToken(null,null,t,i),n.refresh(e)},e.loadWithThingID=function(t,e,i){var n;return n=new l.KiiThingWithToken(null,t,null,i),n.refresh(e)},e.prototype._setAuthToken=function(t){return t.setAuthToken(this._adminToken)},e.prototype.pushSubscription=function(){return new l.KiiPushSubscriptionWithToken(this,this._adminToken)},e.prototype.bucketWithName=function(t){return new l.KiiBucketWithToken(t,this,this._adminToken)},e.prototype.encryptedBucketWithName=function(t){return new l.KiiEncryptedBucketWithToken(t,this,this._adminToken)},e.prototype.topicWithName=function(t){if("string"!=typeof t||""===t)throw new l.InvalidArgumentException("topicName should not null or empty");return new l.KiiTopicWithToken(this._getHttpURI(),t,this._adminToken)},e.prototype.updatePassword=function(t,e){return new Promise(function(i){return function(n,r){var o,a,h,c;return s._isNonEmptyString(t)?(a={newPassword:t},c=u.createXHRWrapper("PUT",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/things/"+i._getIdentifier()+"/password"),c.setKiiHeaders(),c.setAuthToken(i._adminToken),c.setContentType("application/vnd.kii.ChangeThingPasswordRequest+json"),h={success:function(){return null!=e&&e.success(i),n(i)},failure:function(){var t;return t=c.getErrorString("changing thing password"),o=s._Error(t),null!=e&&e.failure(o),r(o)}},c.sendData(JSON.stringify(a),h)):(o=s._Error("newPassword is null or empty"),null!=e&&e.failure(o),void r(o))}}(this))},e.prototype._getIdentifier=function(){return null!=this._thingID?this._thingID:null!=this._vendorThingID?"VENDOR_THING_ID:"+this._vendorThingID:null},e.thingWithID=function(t,e){var i;return i=new l.KiiThingWithToken(null,t,null,e)},e}(l.KiiThing),l.KiiTopicWithToken=function(t){function e(t,i,n){this._authToken=n,this.acl=p(this.acl,this),this._setAuthToken=p(this._setAuthToken,this),e.__super__.constructor.call(this,t,i)}return _(e,t),e.prototype._setAuthToken=function(t){return t.setAuthToken(this._authToken)},e.prototype.acl=function(){return new l.KiiACLWithToken(this,this._authToken)},e}(l.KiiTopic),l.KiiPushSubscriptionWithToken=function(t){function e(t,i){this._authToken=i,this._setAuthToken=p(this._setAuthToken,this),e.__super__.constructor.call(this,t)}return _(e,t),e.prototype._setAuthToken=function(t){return t.setAuthToken(this._authToken)},e}(l.KiiPushSubscription),l.KiiSCNGoogle=function(t){function e(){this._unlinkFromCurrentUser=p(this._unlinkFromCurrentUser,this),this._linkWithCurrentUser=p(this._linkWithCurrentUser,this),this._logOut=p(this._logOut,this),this._logIn=p(this._logIn,this),this._getAccessToken=p(this._getAccessToken,this),this._createTokenObject=p(this._createTokenObject,this),this._setup=p(this._setup,this),e.__super__.constructor.call(this,l.KiiSocialNetworkName.GOOGLEPLUS)}return _(e,t),e.prototype._setup=function(t,i,n){return this._key=t,this._secret=i,this._extras=n,e.__super__._setup.call(this,this._key,this._secret,this._extras)},e.prototype._createTokenObject=function(t,e){var i;return i={access_token:t.access_token},null!=e&&null!=e.new_user_created&&(i.kii_new_user=e.new_user_created),i},e.prototype._getAccessToken=function(t){return t.access_token},e.prototype._logIn=function(t,e){var i;if(l.Kii.logger("should auth google"),l.Kii.logger("Checking options"),null==t||!t.access_token)throw l.InvalidArgumentException("options.access_token is required");return null!=l.KiiUser.getCurrentUser()&&l.KiiUser.logOut(),i={accessToken:t.access_token},this._register("google","application/vnd.kii.AuthTokenGoogleRequest+json",i,t,e)},e.prototype._logOut=function(){return e.__super__._logOut.apply(this,arguments),l.Kii.logger("Log out google")},e.prototype._linkWithCurrentUser=function(t,e){var i;if(null!=l.KiiUser.getCurrentUser()){if(null==t||!t.access_token)throw l.InvalidArgumentException("options.access_token is required");return i={accessToken:t.access_token},this._link("google","application/vnd.kii.LinkGoogleRequest+json",i,t,e)}return null!=e?e.failure(null,this._network,"A KiiUser must be logged in before linking to Google"):void 0},e.prototype._unlinkFromCurrentUser=function(t){return null!=l.KiiUser.getCurrentUser()?this._unlink("google",t):null!=t?t.failure("A KiiUser must be logged in before unlinking from Google"):void 0},e}(l.KiiSocialConnectNetwork),l.KiiSCNRenRen=function(t){function e(){this._unlinkFromCurrentUser=p(this._unlinkFromCurrentUser,this),this._linkWithCurrentUser=p(this._linkWithCurrentUser,this),this._logOut=p(this._logOut,this),this._logIn=p(this._logIn,this),this._getAccessToken=p(this._getAccessToken,this),this._createTokenObject=p(this._createTokenObject,this),this._setup=p(this._setup,this),e.__super__.constructor.call(this,l.KiiSocialNetworkName.RENREN)}return _(e,t),e.prototype._setup=function(t,i,n){return this._key=t,this._secret=i,this._extras=n,e.__super__._setup.call(this,this._key,this._secret,this._extras)},e.prototype._createTokenObject=function(t,e){var i;return i={access_token:t.access_token},null!=e&&null!=e.new_user_created&&(i.kii_new_user=e.new_user_created),i},e.prototype._getAccessToken=function(t){
return t.access_token},e.prototype._logIn=function(t,e){var i;if(l.Kii.logger("should auth renren"),l.Kii.logger("Checking options"),null==t||!t.access_token)throw l.InvalidArgumentException("options.access_token is required");return null!=l.KiiUser.getCurrentUser()&&l.KiiUser.logOut(),i={accessToken:t.access_token},this._register("renren","application/vnd.kii.AuthTokenRenRenRequest+json",i,t,e)},e.prototype._logOut=function(){return e.__super__._logOut.apply(this,arguments),l.Kii.logger("Log out renren")},e.prototype._linkWithCurrentUser=function(t,e){var i;if(null!=l.KiiUser.getCurrentUser()){if(null==t||!t.access_token)throw l.InvalidArgumentException("options.access_token is required");return i={accessToken:t.access_token},this._link("renren","application/vnd.kii.LinkRenRenRequest+json",i,t,e)}return null!=e?e.failure(null,this._network,"A KiiUser must be logged in before linking to RenRen"):void 0},e.prototype._unlinkFromCurrentUser=function(t){return null!=l.KiiUser.getCurrentUser()?this._unlink("renren",t):null!=t?t.failure("A KiiUser must be logged in before unlinking from RenRen"):void 0},e}(l.KiiSocialConnectNetwork),l.KiiThingContext=function(){function t(t){this._objectWithURI=p(this._objectWithURI,this),this._getToken=p(this._getToken,this),this.pushInstallation=p(this.pushInstallation,this),this.getAuthenticatedThing=p(this.getAuthenticatedThing,this),this.listTopics=p(this.listTopics,this),this.topicWithName=p(this.topicWithName,this),this._token=t.token,this._thingId=t.thingId,null!=t.vendorThingID&&(this._vendorThingID=t.vendorThingID)}return t.prototype.bucketWithName=function(t){var e;return e=new l.KiiBucketWithToken(t,null,this._token)},t.prototype.encryptedBucketWithName=function(t){var e;return e=new l.KiiEncryptedBucketWithToken(t,null,this._token)},t.prototype.objectWithURI=function(t){var e;return e=this._objectWithURI(t)},t.prototype.topicWithName=function(t){if("string"!=typeof t||""===t)throw new l.InvalidArgumentException("topicName should not null or empty");return new l.KiiTopicWithToken(""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID(),t,this._token)},t.prototype.listTopics=function(t,e){return l.Kii._listTopics(t,e,this)},t.prototype.getAuthenticatedThing=function(){var t;return t=l.KiiThingWithToken.thingWithID(this._thingId,this._token),t._accessToken=this._token,t._vendorThingID=this._vendorThingID,t},t.prototype.pushInstallation=function(){return new l.KiiPushInstallationWithToken(this._token)},t.prototype._getToken=function(){return this._token},t.prototype._objectWithURI=function(t){var e,i,n,r,s,o,u,a,h;if(!t)throw new l.InvalidURIException;if(h=0===t.indexOf("kiicloud://"),o=t.substr("kiicloud://".length),s=o.split("/"),r=s.length,!(r>=4&&h))throw new l.InvalidURIException;if(i=4===r?1:3,n=s[i],a=null,"groups"===s[0]&&6===r)a=new l.KiiGroupWithToken._groupWithID(s[1],this._token);else if("users"===s[0]&&6===r)a=l.KiiUserWithToken._userWithID(s[1],this._token);else if("things"===s[0]&&6===r)a=l.KiiThingWithToken.thingWithID(s[1],this._token);else if(4!==r)throw new l.InvalidURIException;return e=new l.KiiBucketWithToken(n,a,this._token),u=e.createObject(),u._setUUID(s[r-1]),u},t}(),l.KiiUserBuilder=function(){function t(){this._password=null,this._username=null,this._emailAddress=null,this._phoneNumber=null,this._country=null}return t.builderWithIdentifier=function(t,e){var i,n;if(null==t)throw new l.InvalidArgumentException("Identifier must not be null or undefined");if(!s._validatePassword(e))throw new l.InvalidPasswordException;if(i=new l.KiiUserBuilder,i._password=e,s._validatePhoneNumber(t))i._phoneNumber=t;else if(n=s._trim(t),s._validateEmail(n))i._emailAddress=n;else{if(!s._validateUsername(n))throw new l.InvalidArgumentException;i._username=n}return i},t.builderWithEmailAddress=function(t,e){var i;if(!s._validateEmail(t))throw new l.InvalidEmailException;if(!s._validatePassword(e))throw new l.InvalidPasswordException;return i=new l.KiiUserBuilder,i._emailAddress=s._trim(t),i._password=e,i},t.builderWithGlobalPhoneNumber=function(t,e){var i;if(!s._validatePhoneNumber(t))throw new l.InvalidPhoneNumberException;if(!s._isGlobalPhoneNumber(t))throw new l.InvalidPhoneNumberException;if(!s._validatePassword(e))throw new l.InvalidPasswordException;return i=new l.KiiUserBuilder,i._phoneNumber=t,i._password=e,i},t.builderWithLocalPhoneNumber=function(t,e,i){var n;if(!s._validateLocalPhone(t))throw new l.InvalidPhoneNumberException;if(!s._validateCountryCode(e))throw new l.InvalidCountryException;if(!s._validatePassword(i))throw new l.InvalidPasswordException;return n=new l.KiiUserBuilder,n._phoneNumber=t,n._country=e,n._password=i,n},t.builderWithUsername=function(t,e){var i,n;if(n=s._trim(t),!s._validateUsername(n))throw new l.InvalidUsernameException;if(!s._validatePassword(e))throw new l.InvalidPasswordException;return i=new l.KiiUserBuilder,i._username=n,i._password=e,i},t.prototype.setUsername=function(t){var e;if(null!=t){if(e=s._trim(t),!s._validateUsername(e))throw new l.InvalidUsernameException;this._username=e}return this},t.prototype.setEmailAddress=function(t){var e;if(null!=t){if(e=s._trim(t),!s._validateEmail(e))throw new l.InvalidEmailException;this._emailAddress=e}return this},t.prototype.setGlobalPhoneNumber=function(t){if(null!=t){if(!s._validatePhoneNumber(t))throw new l.InvalidPhoneNumberException;this._phoneNumber=t,this._country=null}return this},t.prototype.setLocalPhoneNumber=function(t,e){if(null!=t&&!s._validateLocalPhone(t))throw new l.InvalidPhoneNumberException;if(null!=e&&!s._validateCountryCode(e))throw new l.InvalidCountryException;return null!=t&&(this._phoneNumber=t),null!=e&&(this._country=e),this},t.prototype.build=function(){var t;return t=new l.KiiUser,null!=this._username&&t._setUsername(this._username),null!=this._emailAddress&&t._setEmailAddress(this._emailAddress),null!=this._country?t._setLocalPhone(this._phoneNumber,this._country):null!=this._phoneNumber&&t._setPhoneNumber(this._phoneNumber),t._setPassword(this._password),t},t}(),l.KiiPushInstallation=function(){function t(t){this._setAuthToken=p(this._setAuthToken,this),this.uninstallByInstallationID=p(this.uninstallByInstallationID,this),this.uninstall=p(this.uninstall,this),this._getMqttEndpoint=p(this._getMqttEndpoint,this),this.getMqttEndpoint=p(this.getMqttEndpoint,this),this._install=p(this._install,this),this.installMqtt=p(this.installMqtt,this),this.installApns=p(this.installApns,this),this.installGcm=p(this.installGcm,this),this._user=t}return t.prototype.installGcm=function(t,e,i){return s._isNonEmptyString(t)?this._install(t,"ANDROID",e,i):new Promise(function(t){return function(e,n){var r;return r=s._Error("installationRegistrationID must not be null or empty.",t),null!=i&&i.failure(r),n(r)}}(this))},t.prototype.installApns=function(t,e,i){return s._isNonEmptyString(t)?this._install(t,"IOS",e,i):new Promise(function(t){return function(e,n){var r;return r=s._Error("deviceToken must not be null or empty.",t),null!=i&&i.failure(r),n(r)}}(this))},t.prototype.installMqtt=function(t,e){return this._install(null,"MQTT",t,e)},t.prototype._install=function(t,e,i,n){return new Promise(function(r){return function(o,a){var h,c,p,f;return"boolean"!=typeof i&&(h=s._Error("type of development must be boolean.",r),null!=n&&n.failure(h),a(h)),f=u.createXHRWrapper("POST",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/installations"),f.setKiiHeaders(),r._setAuthToken(f),f.setContentType("application/vnd.kii.InstallationCreationRequest+json"),c={deviceType:e,development:i},null!=t&&(c.installationRegistrationID=t),p={success:function(){var t;return t=JSON.parse(decodeURIComponent(f.xhr.responseText)),null!=n&&n.success(t),o(t)},failure:function(){var t;return t=f.getErrorString("install push"),h=s._Error(t,r),null!=n&&n.failure(h),a(h)}},f.sendData(JSON.stringify(c),p)}}(this))},t.prototype.getMqttEndpoint=function(t,e){return new Promise(function(i){return function(n,r){var o,u;return s._isNonEmptyString(t)||(o=s._Error("installationID must not be null or empty.",i),null!=e&&e.failure(o),r(o)),u={success:function(t){return null!=e&&e.success(t),n(t)},failure:function(t){return null!=e&&e.failure(t),r(t)}},i._getMqttEndpoint(t,3,u)}}(this))},t.prototype._getMqttEndpoint=function(t,e,i){var n,r,o;return n=this,o=u.createXHRWrapper("GET",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/installations/"+t+"/mqtt-endpoint"),o.setKiiHeaders(),this._setAuthToken(o),r={success:function(t){return function(){var t;return t=JSON.parse(decodeURIComponent(o.xhr.responseText)),i.success(t)}}(this),failure:function(r){return function(){var r,u;return 503===o.xhr.status?(e--,0>=e?(u=o.getErrorString("get mqtt endpoint"),r=s._Error(u,n),i.failure(r)):setTimeout(function(){return n._getMqttEndpoint(t,e,i)},1e3)):(u=o.getErrorString("get mqtt endpoint"),r=s._Error(u,n),i.failure(r))}}(this)},o.send(r)},t.prototype.uninstall=function(t,e,i){return new Promise(function(n){return function(r,o){var a,h,c;return s._isNonEmptyString(t)||(a=s._Error("installationRegistrationID must not be null or empty.",n),null!=i&&i.failure(a),o(a)),l.KiiPushInstallation._validateDeviceType(e)||(a=s._Error("Unsupported deviceType "+e,n),null!=i&&i.failure(a),o(a)),c=u.createXHRWrapper("DELETE",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/installations/"+e+":"+t),c.setKiiHeaders(),n._setAuthToken(c),h={success:function(){return null!=i&&i.success(),r()},failure:function(){var t;return t=c.getErrorString("uninstall push"),a=s._Error(t,n),null!=i&&i.failure(a),o(a)}},c.send(h)}}(this))},t.prototype.uninstallByInstallationID=function(t,e){return new Promise(function(i){return function(n,r){var o,a,h;return s._isNonEmptyString(t)||(o=s._Error("installationID must not be null or empty.",i),null!=e&&e.failure(o),r(o)),h=u.createXHRWrapper("DELETE",""+l.Kii.getBaseURL()+"/apps/"+l.Kii.getAppID()+"/installations/"+t),h.setKiiHeaders(),i._setAuthToken(h),a={success:function(){return null!=e&&e.success(),n()},failure:function(){var t;return t=h.getErrorString("uninstall push"),o=s._Error(t,i),null!=e&&e.failure(o),r(o)}},h.send(a)}}(this))},t._validateDeviceType=function(t){return"ANDROID"===t||"MQTT"===t||"IOS"===t},t.prototype._setAuthToken=function(t){return t.setCurrentUserToken()},t}(),l.KiiPushInstallationWithToken=function(t){function e(t){this._authToken=t,this._setAuthToken=p(this._setAuthToken,this)}return _(e,t),e.prototype._setAuthToken=function(t){return t.setAuthToken(this._authToken)},e}(l.KiiPushInstallation),l.KiiErrorParser=function(){function t(){}var e,i,n,r,s,o,u;return u={APP_NOT_FOUND:404,APP_DISABLED:403,UNAUTHORIZED:401,USER_NOT_FOUND:404,THING_NOT_FOUND:404,THING_DISABLED:401,THING_ALREADY_EXISTS:409,THING_TYPE_NOT_FOUND:404,FIRMWARE_VERSION_NOT_FOUND:404,WRONG_TOKEN:403,WRONG_REFRESH_TOKEN:403,INVALID_BUCKET:400,OPERATION_NOT_ALLOWED:409,OPERATION_NOT_SUPPORTED:403,AUTHENTICATION_FAILED:401,USER_DISABLED:401,INVALID_DATA_TYPE:400,INVALID_INPUT_DATA:400,INVALID_JSON:400,INVALID_JSON_SCHEMA:400,MISSING_DATA:400,RESOURCE_TEMPORARILY_UNAVAILABLE:503,WRONG_PASSWORD:401,OAUTH2_ERROR:400,THING_END_NODE_DOES_NOT_BELONG_TO_GATEWAY:404,THING_END_NODE_ALREADY_BELONGS_TO_GATEWAY:409,UNDEFINED_ERROR:500,OPERATION_NOT_IMPLEMENTED:501,LOCK_FAILED:503,QUERY_NOT_SUPPORTED:400,QUERY_TIMEOUT:503,TEMPORARY_UNAVAILABLE_ERROR:503,APP_ALREADY_EXISTS:409,BUCKET_ALREADY_EXISTS:409,BUCKET_NOT_FOUND:404,FILTER_NOT_FOUND:404,INVALID_ACCOUNT_STATUS:400,INVALID_OBJECT_ID:400,INVALID_VERIFICATION_CODE:403,OBJECT_NOT_FOUND:404,OBJECT_VERSION_IS_STALE:409,OBJECT_ALREADY_EXISTS:409,OBJECT_CONFLICT:409,PUBLICATION_NOT_FOUND:404,PUBLICATION_EXPIRED:410,USER_ALREADY_EXISTS:409,USER_ADDRESS_NOT_FOUND:404,VERIFICATION_CODE_NOT_FOUND:404,ACCOUNT_TYPE_NOT_SUPPORTED:400,OBJECT_BODY_NOT_FOUND:404,OBJECT_BODY_RANGE_NOT_SATISFIABLE:416,OBJECT_BODY_INTEGRITY_NOT_ASSURED:412,OBJECT_BODY_UPLOAD_NOT_FOUND:404,OBJECT_BODY_UPLOAD_ALREADY_EXISTS:409,BUCKET_TYPE_NOT_SUPPORTED:400,GROUP_NOT_FOUND:404,GROUP_ALREADY_EXISTS:409,INSTALLATION_NOT_FOUND:404,INSTALLATION_ALREADY_EXISTS:409,ACL_NOT_FOUND:404,ACL_ALREADY_EXISTS:409,VERSIONED_UPDATES_NOT_SUPPORTED:400,NO_ACCOUNT_PROVIDED:400,FACEBOOK_USER_ALREADY_LINKED:409,QQ_USER_ALREADY_LINKED:409,GOOGLE_USER_ALREADY_LINKED:409,USER_ALREADY_LINKED:409,USER_NOT_LINKED:409,UNIQUE_CONSTRAINT_VIOLATED:409,GCMKEY_ALREADY_EXISTS:409,GCMKEY_NOT_FOUND:404,APNSKEY_NOT_FOUND:404,JSON_WEB_KEY_NOT_FOUND:404,JPUSHKEY_NOT_FOUND:404,PUSH_SUBSCRIPTION_ALREADY_EXISTS:409,PUSH_SUBSCRIPTION_NOT_FOUND:404,TOPIC_ALREADY_EXISTS:409,TOPIC_NOT_FOUND:404,USER_LOCALE_NOT_FOUND:404,TEMPLATE_NOT_FOUND:404,USER_COUNTRY_NOT_FOUND:404,USER_DISPLAY_NAME_NOT_FOUND:404,SERVER_CODE_VERSION_NOT_FOUND:404,SERVER_CODE_HOOK_VERSION_NOT_FOUND:404,SCHEDULE_EXECUTION_NOT_FOUND:404,ENDPOINT_INVOCATION_ERROR:400,SERVER_CODE_VERIFICATION_ERROR:400,PAYLOAD_ID_NOT_FOUND:404,REPLACEMENT_SQL_QUERY_NOT_FOUND:404,APP_CONFIG_PARAMETER_NOT_FOUND:404,TRANSACTION_ID_NOT_FOUND:404,TRANSACTION_ID_ALREADY_EXISTS:409,CLIENT_CREDENTIALS_NOT_FOUND:404,ACCESS_CODE_NOT_FOUND:404,THING_OWNERSHIP_NOT_FOUND:404,THING_OWNERSHIP_ALREADY_EXISTS:409,INVALID_THING_OWNERSHIP_CODE:409,MQTT_ENDPOINT_NOT_FOUND:404,TASK_NOT_FOUND:404,TASK_NOT_RECURRENT:400,INVALID_STATUS:409,PHONE_NUMBER_VERIFICATION_CODE_EXPIRED:410,PIN_CODE_EXPIRED:410,ADDRESS_VERIFICATION_CODE_NOT_FOUND:404,MQTT_ENDPOINT_NOT_READY:503,INDEX_FAILED:500},i=new RegExp("(^[A-Z_]+): (.*)"),o=new RegExp(" statusCode: (\\d{3}) error code: ([A-Z_]+) message: (.*)$"),s=new RegExp(" statusCode: (\\d{3}) error code: ([A-Z_]+) error message: (.*)$"),n=new RegExp(" statusCode: (\\d{3}) executedSteps: \\d+ error code: ([A-Z_]+) message: (.*) detailMessage: (.*)$"),r=new RegExp(" statusCode: (\\d{3}) executedSteps: null error code: ([A-Z_]+) message: (.*)$"),e=new RegExp("statusCode: (\\d{1,3})$"),t.parse=function(t){var a,l,h,c,p,f,_,g,d;if(h="string"===(typeof t).toLowerCase()?t:t.message,!h)return null;if(0===h.indexOf("0 : http"))return{status:0,code:null,message:"Network Error"};if(0===h.indexOf("429 : http"))return{status:429,code:"TOO_MANY_REQUESTS",message:"Number of requests exceeds the limit."};if(0===h.indexOf("fail to execute server code. statusCode: 0"))return{status:0,code:null,message:"Network Error"};if(0===h.indexOf("invalid_grant: "))return a=h.split(":",2),{status:400,code:"invalid_grant",message:a[1].substr(1)};if(a=e.exec(h))return f=Number(a[1]),429===f?{status:429,code:"TOO_MANY_REQUESTS",message:"Number of requests exceeds the limit."}:{status:0,code:null,message:"Network Error"};if(a=i.exec(h))return l=a[1],c=a[2],f=u[l],f||(f=-2),{status:f,code:l,message:c};for(d=[o,s,n,r],_=0,g=d.length;g>_;_++)if(p=d[_],a=p.exec(h))return f=Number(a[1]),l=a[2],c=a[3],{status:f,code:l,message:c};return{status:-1,code:null,message:h}},t}(),l.KiiThingQuery=function(){function t(t,e){if(this._dictValue=p(this._dictValue,this),this.clone=p(this.clone,this),this.getPaginationKey=p(this.getPaginationKey,this),this.setPaginationKey=p(this.setPaginationKey,this),this.getThingType=p(this.getThingType,this),this.setThingType=p(this.setThingType,this),this.getLimit=p(this.getLimit,this),this.setLimit=p(this.setLimit,this),null==t&&(null==e||0===e.length))throw l.InvalidArgumentException("Both the owner and groups parameter are optional, but at least one of them must be supplied.");this._owner=t,this._groups=e,this._limit=0}return t.thingQuery=function(t,e){return new l.KiiThingQuery(t,e)},t.prototype.setLimit=function(t){return t>0?this._limit=t:this._limit=0},t.prototype.getLimit=function(){return this._limit},t.prototype.setThingType=function(t){return this._thingType=t},t.prototype.getThingType=function(){return this._thingType},t.prototype.setPaginationKey=function(t){return this._paginationKey=t},t.prototype.getPaginationKey=function(){return this._paginationKey},t.prototype.clone=function(){var t;return t=new l.KiiThingQuery(l.KiiThingQuery._clone(this._owner),l.KiiThingQuery._clone(this._groups)),t._limit=this._limit,t._thingType=this._thingType,t._paginationKey=this._paginationKey,t},t._clone=function(e){var i,n;if(null==e||"object"!=typeof e)return e;n=new e.constructor;for(i in e)n[i]=t._clone(e[i]);return n},t.prototype._dictValue=function(){var t,e,i,n,r,s,o,u,a,h;if(r={},null!=this._limit&&this._limit>0&&(r.bestEffortLimit=this._limit),null!=this._paginationKey&&(r.paginationKey=this._paginationKey),n=[],null!=this._owner&&(o={type:"contains",field:"userOwners",value:this._owner.getID()},n.push(o)),null!=this._groups&&this._groups.length>0)for(h=this._groups,u=0,a=h.length;a>u;u++)t=h[u],e={type:"contains",field:"groupOwners",value:t.getID()},n.push(e);if(0===n.length)throw l.InvalidArgumentException("Query clause must include the 'contains' clause.");return i=1===n.length?n[0]:{type:"or",clauses:n},s=null!=this._thingType?{clause:{type:"and",clauses:[{type:"eq",field:"_thingType",value:this._thingType},i]}}:{clause:i},r.thingQuery=s,r},t}(),l.KiiThingQueryResult=function(){function t(t,e,i){this.getNextResult=p(this.getNextResult,this),this.getNextKiiThingQuery=p(this.getNextKiiThingQuery,this),this.hasNext=p(this.hasNext,this),this.getResult=p(this.getResult,this),this._query=t,this._results=e,this._paginationKey=i}return t.prototype.getResult=function(){return this._results},t.prototype.hasNext=function(){return null!=this._paginationKey},t.prototype.getNextKiiThingQuery=function(){var t;return this.hasNext()?(t=this._query.clone(),t.setPaginationKey(this._paginationKey),t):null},t.prototype.getNextResult=function(t){return this.hasNext()?l.KiiThing.executeQuery(this.getNextKiiThingQuery(),t):new Promise(function(e){return function(i,n){var r,o;return o="No more pages to fetch",r=s._Error(o,e),null!=t&&t.failure(r),n(r)}}(this))},t}(),l};!function(){var e="undefined"!=typeof module&&null!==module;e&&module.exports?module.exports={exportedClasses:["ForTest","Kii","KiiACL","KiiACLEntry","KiiACLWithToken","KiiAnonymousUser","KiiAnyAuthenticatedUser","KiiAppAdminContext","KiiBucket","KiiBucketWithToken","KiiClause","KiiEncryptedBucket","KiiEncryptedBucketWithToken","KiiErrorParser","KiiGeoPoint","KiiGroup","KiiGroupWithToken","KiiObject","KiiObjectWithToken","KiiPushInstallation","KiiPushInstallationWithToken","KiiPushSubscription","KiiPushSubscriptionWithToken","KiiQuery","KiiSCNFacebook","KiiSCNGoogle","KiiSCNQQ","KiiSCNRenRen","KiiSCNTwitter","KiiSDKClientInfo","KiiServerCodeEntry","KiiServerCodeExecResult","KiiSocialConnect","KiiSocialConnectNetwork","KiiThing","KiiThingContext","KiiThingQuery","KiiThingQueryResult","KiiThingWithToken","KiiTopic","KiiPushMessageBuilder","KiiTopicWithToken","KiiUser","KiiUserBuilder","KiiUserWithToken","KiiSocialNetworkName","KiiSite","KiiServerCodeEnvironmentVersion","_KiiHttpRequestType","KiiACLAction","InvalidDisplayNameException","InvalidPasswordException","InvalidUsernameException","InvalidUserIdentifierException","InvalidEmailException","InvalidPhoneNumberException","InvalidLocalPhoneNumberException","InvalidCountryException","InvalidURIException","InvalidACLAction","InvalidACLSubject","InvalidACLGrant","InvalidLimitException","InvalidArgumentException","IllegalStateException","ArithmeticException","UnsupportedOperationException"],create:function(){return t.call(this)}}:t()}()}();