opengate-js 12.2.0 → 12.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/dump.json CHANGED
@@ -66923,7 +66923,7 @@
66923
66923
  "__docId__": 2537,
66924
66924
  "kind": "file",
66925
66925
  "name": "src/users/Users.js",
66926
- "content": "'use strict';\r\n\r\nimport BaseProvision from '../provision/BaseProvision';\r\nimport q from 'q';\r\nimport _ from 'lodash';\r\n\r\nconst _length_name = 100;\r\nconst _length_surname = 100;\r\nconst _length_email = 100;\r\nconst _length_password = 50;\r\n/**\r\n * This class allow make get request to user resource into Opengate North API.\r\n */\r\nexport default class User extends BaseProvision {\r\n\r\n\r\n /** \r\n * @param {InternalOpenGateAPI} Reference to the API object.\r\n */\r\n constructor(ogapi) {\r\n super(ogapi, \"/users\", undefined, [\"email\", \"workgroup\", \"domain\", \"profile\", \"countryCode\", \"langCode\"]);\r\n }\r\n\r\n\r\n\r\n /**\r\n * Set the name attribute\r\n * @param {string} name - required field\r\n * @return {User}\r\n */\r\n withName(name) {\r\n if (typeof name !== 'string' || name.length > _length_name)\r\n throw new Error('Parameter name must be a string and has a maximum length of ' + _length_name);\r\n this._name = name;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the surname attribute\r\n * @param {string} surname - required field\r\n * @return {User}\r\n */\r\n withSurname(surname) {\r\n if (typeof surname !== 'string' || surname.length > _length_surname)\r\n throw new Error('Parameter surname must be a string and has a maximum length of ' + _length_surname);\r\n this._surname = surname;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the email attribute\r\n * @param {string} email - required field\r\n * @return {User}\r\n */\r\n withEmail(email) {\r\n if (typeof email !== 'string' || email.length > _length_email)\r\n throw new Error('Parameter email must be a string and has a maximum length of ' + _length_email);\r\n this._email = email;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the password attribute\r\n * @param {string} password - required field\r\n * @return {User}\r\n */\r\n withPassword(password) {\r\n if (typeof password !== 'string' || password.length > _length_password)\r\n throw new Error('Parameter password must be a string and has a maximum length of ' + _length_password);\r\n this._password = password;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the workgroup attribute\r\n * @param {string} workgroup - required field\r\n * @return {User}\r\n */\r\n withWorkgroup(workgroup) {\r\n if (typeof workgroup !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_WORKGROUP');\r\n this._workgroup = workgroup;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the domain attribute\r\n * @param {string} domain - required field\r\n * @return {User}\r\n */\r\n withDomain(domain) {\r\n if (typeof domain !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_DOMAIN');\r\n this._domain = domain;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the profile attribute\r\n * @param {string} profile - required field\r\n * @return {User}\r\n */\r\n withProfile(profile) {\r\n if (typeof profile !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_PROFILE');\r\n this._profile = profile;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the countryCode attribute\r\n * @param {string} countryCode - required field\r\n * @return {User}\r\n */\r\n withCountryCode(countryCode) {\r\n if (typeof countryCode !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_COUNTRY_CODE');\r\n this._countryCode = countryCode;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the langCode attribute\r\n * @param {string} langCode - required field\r\n * @return {User}\r\n */\r\n withLangCode(langCode) {\r\n if (typeof langCode !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_LANGUAGE');\r\n this._langCode = langCode;\r\n return this;\r\n }\r\n\r\n\r\n /**\r\n * Set the description attribute\r\n * @param {string} description - required field\r\n * @return {User}\r\n */\r\n withDescription(description) {\r\n if (typeof description !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_DESCRIPTION');\r\n this._description = description;\r\n return this;\r\n\r\n }\r\n\r\n /**\r\n * Set the timezone attribute\r\n * @param {string} timezone - required field\r\n * @return {User}\r\n */\r\n withTimezone(timezone) {\r\n if (typeof timezone !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_TIMEZONE');\r\n this._timezone = timezone;\r\n return this;\r\n\r\n }\r\n\r\n /**\r\n * Compose url to delete an user\r\n * @return {String} This returns a string with the URL of the request.\r\n * @private\r\n */\r\n _buildURL() {\r\n if (this._email === undefined)\r\n throw new Error('OGAPI_EMAIL_MUST_BE_DEFINED');\r\n var url = this._resource + \"/\" + this._email;\r\n\r\n return url;\r\n\r\n }\r\n\r\n /**\r\n * Compose json message to create a user\r\n * @return {String} This returns a message with user's parameters\r\n * @private\r\n */\r\n _composeElement() {\r\n\r\n var data = {\r\n user: {\r\n name: this._name || undefined,\r\n surname: this._surname || undefined,\r\n password: this._password || undefined,\r\n description: this._description || undefined,\r\n email: this._email || undefined,\r\n workgroup: this._workgroup || undefined,\r\n domain: this._domain || undefined,\r\n profile: this._profile || undefined,\r\n countryCode: this._countryCode || undefined,\r\n langCode: this._langCode || undefined,\r\n timezone: this._timezone || undefined\r\n }\r\n };\r\n\r\n return data;\r\n\r\n }\r\n\r\n /**\r\n * Compose json message to update a user\r\n * @return {String} This returns a message with user's parameters\r\n * @private\r\n */\r\n _composeUpdateElement() {\r\n if (this._password) {\r\n throw new Error('OGAPI_PASSWORD_NOT_ALLOWED');\r\n }\r\n if (this._email === undefined)\r\n throw new Error('OGAPI_USER_UPDATE_PARAMETER_MUST_BE_DEFINED');\r\n\r\n var data = {\r\n user: {\r\n name: this._name || undefined,\r\n surname: this._surname || undefined,\r\n description: this._description || undefined,\r\n email: this._email || undefined,\r\n workgroup: this._workgroup || undefined,\r\n domain: this._domain || undefined,\r\n profile: this._profile || undefined,\r\n countryCode: this._countryCode || undefined,\r\n langCode: this._langCode || undefined,\r\n timezone: this._timezone || undefined\r\n }\r\n };\r\n return data;\r\n }\r\n\r\n _post(url, data) {\r\n var defered = q.defer();\r\n var promise = defered.promise;\r\n \r\n this._ogapi.Napi.post(url, data, undefined, this._getExtraHeaders(), this._getUrlParameters())\r\n .then((res) => {\r\n if (res.statusCode === 200) {\r\n defered.resolve({\r\n statusCode: res.statusCode\r\n });\r\n } else if (res.status === 200) {\r\n defered.resolve({\r\n statusCode: res.status\r\n });\r\n } else {\r\n defered.reject({\r\n errors: res.errors,\r\n statusCode: res.statusCode\r\n });\r\n }\r\n })\r\n .catch((error) => {\r\n defered.reject(error);\r\n });\r\n return promise;\r\n }\r\n /**\r\n * This invoke a request to OpenGate North API and the callback is managed by promises\r\n * This function updates a password of a user\r\n * @return {Promise}\r\n * @param {String} newPassword - required field\r\n * @property {function (result:object, statusCode:number)} then - When request it is OK\r\n * @property {function (error:string)} catch - When request it is NOK\r\n * @example\r\n * ogapi.usersBuilder().withEmail(example@example.es).withPassword(oldPassword).changePassword(newPassword);\r\n */\r\n changePassword(newPassword) {\r\n this._newPassword = newPassword;\r\n if (_.isEmpty(this._email) || _.isEmpty(this._password) || _.isEmpty(this._newPassword)) {\r\n throw new Error('OGAPI_USER_UPDATE_PASSWORD_PARAMETER_MUST_BE_DEFINED');\r\n }\r\n\r\n var data = {\r\n user: {\r\n password: this._newPassword\r\n }\r\n };\r\n\r\n this._setExtraHeaders({\r\n 'X-ApiPass': this._password\r\n });\r\n\r\n return this._doNorthPost(this._buildURL(), data);\r\n }\r\n\r\n /**\r\n * This invoke a request to OpenGate North API and the callback is managed by promises\r\n * This function request for new password when the user forgets it. \r\n * Sends a password recovery email\r\n * @return {Promise}\r\n * @property {function (result:object, statusCode:number)} then - When request it is OK\r\n * @property {function (error:string)} catch - When request it is NOK\r\n * @example\r\n * ogapi.usersBuilder().withEmail(example@example.es).requestResetPassword()\r\n */\r\n requestResetPassword() {\r\n if (_.isEmpty(this._email)) {\r\n throw new Error('OGAPI_USER_MAIL_RESET_PASSWORD_PARAMETER_MUST_BE_DEFINED');\r\n }\r\n var url = this._buildURL() + '/reset'\r\n return this._doNorthPost(url);\r\n }\r\n\r\n /**\r\n * This invoke a request to OpenGate North API and the callback is managed by promises\r\n * This function updates a password of a user with a tokenId\r\n * @param {String} newPassword - required field\r\n * @param {String} tokenId - required field\r\n * @return {Promise}\r\n * @property {function (result:object, statusCode:number)} then - When request it is OK\r\n * @property {function (error:string)} catch - When request it is NOK\r\n * @example\r\n * ogapi.usersBuilder().withEmail(example@example.es).updatePassword(newPassword, tokenid);\r\n */\r\n updatePassword(newPassword, tokenId) {\r\n this._newPassword = newPassword;\r\n this._tokenId = tokenId;\r\n if (_.isEmpty(this._email)){\r\n throw new Error('OGAPI_USER_MAIL_RESET_PASSWORD_PARAMETER_MUST_BE_DEFINED');\r\n }\r\n if(_.isEmpty(this._newPassword)){\r\n throw new Error('OGAPI_USER_PASSWORD_RESET_PASSWORD_PARAMETER_MUST_BE_DEFINED');\r\n }\r\n\r\n if(_.isEmpty(tokenId)){\r\n throw new Error('OGAPI_USER_TOKENID_RESET_PASSWORD_PARAMETER_MUST_BE_DEFINED');\r\n }\r\n\r\n var data = {\r\n password: this._newPassword\r\n };\r\n\r\n\r\n var url = this._buildURL() + '/reset/' + tokenId\r\n \r\n return this._doNorthPost(url, data);\r\n }\r\n \r\n}",
66926
+ "content": "'use strict';\r\n\r\nimport BaseProvision from '../provision/BaseProvision';\r\nimport q from 'q';\r\nimport _ from 'lodash';\r\n\r\nconst _length_name = 100;\r\nconst _length_surname = 100;\r\nconst _length_email = 100;\r\nconst _length_password = 50;\r\n/**\r\n * This class allow make get request to user resource into Opengate North API.\r\n */\r\nexport default class User extends BaseProvision {\r\n\r\n\r\n /** \r\n * @param {InternalOpenGateAPI} Reference to the API object.\r\n */\r\n constructor(ogapi) {\r\n super(ogapi, \"/users\", undefined, [\"email\", \"workgroup\", \"domain\", \"profile\", \"countryCode\", \"langCode\"]);\r\n }\r\n\r\n\r\n\r\n /**\r\n * Set the name attribute\r\n * @param {string} name - required field\r\n * @return {User}\r\n */\r\n withName(name) {\r\n if (typeof name !== 'string' || name.length > _length_name)\r\n throw new Error('Parameter name must be a string and has a maximum length of ' + _length_name);\r\n this._name = name;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the surname attribute\r\n * @param {string} surname - required field\r\n * @return {User}\r\n */\r\n withSurname(surname) {\r\n if (typeof surname !== 'string' || surname.length > _length_surname)\r\n throw new Error('Parameter surname must be a string and has a maximum length of ' + _length_surname);\r\n this._surname = surname;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the email attribute\r\n * @param {string} email - required field\r\n * @return {User}\r\n */\r\n withEmail(email) {\r\n if (typeof email !== 'string' || email.length > _length_email)\r\n throw new Error('Parameter email must be a string and has a maximum length of ' + _length_email);\r\n this._email = email;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the password attribute\r\n * @param {string} password - required field\r\n * @return {User}\r\n */\r\n withPassword(password) {\r\n if (typeof password !== 'string' || password.length > _length_password)\r\n throw new Error('Parameter password must be a string and has a maximum length of ' + _length_password);\r\n this._password = password;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the workgroup attribute\r\n * @param {string} workgroup - required field\r\n * @return {User}\r\n */\r\n withWorkgroup(workgroup) {\r\n if (typeof workgroup !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_WORKGROUP');\r\n this._workgroup = workgroup;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the domain attribute\r\n * @param {string} domain - required field\r\n * @return {User}\r\n */\r\n withDomain(domain) {\r\n if (typeof domain !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_DOMAIN');\r\n this._domain = domain;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the profile attribute\r\n * @param {string} profile - required field\r\n * @return {User}\r\n */\r\n withProfile(profile) {\r\n if (typeof profile !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_PROFILE');\r\n this._profile = profile;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the countryCode attribute\r\n * @param {string} countryCode - required field\r\n * @return {User}\r\n */\r\n withCountryCode(countryCode) {\r\n if (typeof countryCode !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_COUNTRY_CODE');\r\n this._countryCode = countryCode;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the langCode attribute\r\n * @param {string} langCode - required field\r\n * @return {User}\r\n */\r\n withLangCode(langCode) {\r\n if (typeof langCode !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_LANGUAGE');\r\n this._langCode = langCode;\r\n return this;\r\n }\r\n\r\n\r\n /**\r\n * Set the description attribute\r\n * @param {string} description - required field\r\n * @return {User}\r\n */\r\n withDescription(description) {\r\n if (typeof description !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_DESCRIPTION');\r\n this._description = description;\r\n return this;\r\n\r\n }\r\n\r\n /**\r\n * Set the timezone attribute\r\n * @param {string} timezone - required field\r\n * @return {User}\r\n */\r\n withTimezone(timezone) {\r\n if (typeof timezone !== 'string')\r\n throw new Error('OGAPI_STRING_PARAMETER_TIMEZONE');\r\n this._timezone = timezone;\r\n return this;\r\n\r\n }\r\n\r\n /**\r\n * Compose url to delete an user\r\n * @return {String} This returns a string with the URL of the request.\r\n * @private\r\n */\r\n _buildURL() {\r\n if (this._email === undefined)\r\n throw new Error('OGAPI_EMAIL_MUST_BE_DEFINED');\r\n var url = this._resource + \"/\" + this._email;\r\n\r\n return url;\r\n\r\n }\r\n\r\n /**\r\n * Compose json message to create a user\r\n * @return {String} This returns a message with user's parameters\r\n * @private\r\n */\r\n _composeElement() {\r\n\r\n var data = {\r\n user: {\r\n name: this._name || undefined,\r\n surname: this._surname || undefined,\r\n password: this._password || undefined,\r\n description: this._description || undefined,\r\n email: this._email || undefined,\r\n workgroup: this._workgroup || undefined,\r\n domain: this._domain || undefined,\r\n profile: this._profile || undefined,\r\n countryCode: this._countryCode || undefined,\r\n langCode: this._langCode || undefined,\r\n timezone: this._timezone || undefined\r\n }\r\n };\r\n\r\n return data;\r\n\r\n }\r\n\r\n /**\r\n * Compose json message to update a user\r\n * @return {String} This returns a message with user's parameters\r\n * @private\r\n */\r\n _composeUpdateElement() {\r\n if (this._password) {\r\n throw new Error('OGAPI_PASSWORD_NOT_ALLOWED');\r\n }\r\n if (this._email === undefined)\r\n throw new Error('OGAPI_USER_UPDATE_PARAMETER_MUST_BE_DEFINED');\r\n\r\n var data = {\r\n user: {\r\n name: this._name || undefined,\r\n surname: this._surname || undefined,\r\n description: this._description || undefined,\r\n email: this._email || undefined,\r\n workgroup: this._workgroup || undefined,\r\n domain: this._domain || undefined,\r\n profile: this._profile || undefined,\r\n countryCode: this._countryCode || undefined,\r\n langCode: this._langCode || undefined,\r\n timezone: this._timezone || undefined\r\n }\r\n };\r\n return data;\r\n }\r\n\r\n _post(url, data) {\r\n var defered = q.defer();\r\n var promise = defered.promise;\r\n \r\n this._ogapi.Napi.post(url, data, undefined, this._getExtraHeaders(), this._getUrlParameters())\r\n .then((res) => {\r\n if (res.statusCode === 200) {\r\n defered.resolve({\r\n statusCode: res.statusCode\r\n });\r\n } else if (res.status === 200) {\r\n defered.resolve({\r\n statusCode: res.status\r\n });\r\n } else {\r\n defered.reject({\r\n errors: res.errors,\r\n statusCode: res.statusCode\r\n });\r\n }\r\n })\r\n .catch((error) => {\r\n defered.reject(error);\r\n });\r\n return promise;\r\n }\r\n /**\r\n * This invoke a request to OpenGate North API and the callback is managed by promises\r\n * This function updates a password of a user\r\n * @return {Promise}\r\n * @param {String} newPassword - required field\r\n * @property {function (result:object, statusCode:number)} then - When request it is OK\r\n * @property {function (error:string)} catch - When request it is NOK\r\n * @example\r\n * ogapi.usersBuilder().withEmail(example@example.es).withPassword(oldPassword).changePassword(newPassword);\r\n */\r\n changePassword(newPassword) {\r\n this._newPassword = newPassword;\r\n if (_.isEmpty(this._email) || _.isEmpty(this._password) || _.isEmpty(this._newPassword)) {\r\n throw new Error('OGAPI_USER_UPDATE_PASSWORD_PARAMETER_MUST_BE_DEFINED');\r\n }\r\n\r\n var data = {\r\n user: {\r\n password: this._newPassword\r\n }\r\n };\r\n\r\n this._setExtraHeaders({\r\n 'X-ApiPass': this._password\r\n });\r\n\r\n return this._doNorthPut(this._buildURL(), data);\r\n }\r\n\r\n /**\r\n * This invoke a request to OpenGate North API and the callback is managed by promises\r\n * This function request for new password when the user forgets it. \r\n * Sends a password recovery email\r\n * @return {Promise}\r\n * @property {function (result:object, statusCode:number)} then - When request it is OK\r\n * @property {function (error:string)} catch - When request it is NOK\r\n * @example\r\n * ogapi.usersBuilder().withEmail(example@example.es).requestResetPassword()\r\n */\r\n requestResetPassword() {\r\n if (_.isEmpty(this._email)) {\r\n throw new Error('OGAPI_USER_MAIL_RESET_PASSWORD_PARAMETER_MUST_BE_DEFINED');\r\n }\r\n var url = this._buildURL() + '/reset'\r\n return this._doNorthPost(url);\r\n }\r\n\r\n /**\r\n * This invoke a request to OpenGate North API and the callback is managed by promises\r\n * This function updates a password of a user with a tokenId\r\n * @param {String} newPassword - required field\r\n * @param {String} tokenId - required field\r\n * @return {Promise}\r\n * @property {function (result:object, statusCode:number)} then - When request it is OK\r\n * @property {function (error:string)} catch - When request it is NOK\r\n * @example\r\n * ogapi.usersBuilder().withEmail(example@example.es).updatePassword(newPassword, tokenid);\r\n */\r\n updatePassword(newPassword, tokenId) {\r\n this._newPassword = newPassword;\r\n this._tokenId = tokenId;\r\n if (_.isEmpty(this._email)){\r\n throw new Error('OGAPI_USER_MAIL_RESET_PASSWORD_PARAMETER_MUST_BE_DEFINED');\r\n }\r\n if(_.isEmpty(this._newPassword)){\r\n throw new Error('OGAPI_USER_PASSWORD_RESET_PASSWORD_PARAMETER_MUST_BE_DEFINED');\r\n }\r\n\r\n if(_.isEmpty(tokenId)){\r\n throw new Error('OGAPI_USER_TOKENID_RESET_PASSWORD_PARAMETER_MUST_BE_DEFINED');\r\n }\r\n\r\n var data = {\r\n password: this._newPassword\r\n };\r\n\r\n\r\n var url = this._buildURL() + '/reset/' + tokenId\r\n \r\n return this._doNorthPost(url, data);\r\n }\r\n \r\n}",
66927
66927
  "static": true,
66928
66928
  "longname": "src/users/Users.js",
66929
66929
  "access": null,
@@ -560,7 +560,7 @@ export default class User extends BaseProvision {
560
560
  'X-ApiPass': this._password
561
561
  });
562
562
 
563
- return this._doNorthPost(this._buildURL(), data);
563
+ return this._doNorthPut(this._buildURL(), data);
564
564
  }
565
565
 
566
566
  /**
package/docs/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opengate-js",
3
- "version": "12.2.0",
3
+ "version": "12.2.1",
4
4
  "description": "",
5
5
  "main": "dist/opengate-api-npm.js",
6
6
  "repository": {