opengate-js 13.0.0 → 13.2.0

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.
Files changed (30) hide show
  1. package/bower.json +1 -1
  2. package/dist/{opengate-api-bower-13.0.0.js → opengate-api-bower-13.2.0.js} +1189 -236
  3. package/dist/opengate-api-bower-13.2.0.js.map +1 -0
  4. package/dist/opengate-api-bower-13.2.0.min.js +62 -0
  5. package/dist/opengate-api-bower-13.2.0.min.js.map +1 -0
  6. package/dist/src/users/Users.js +64 -7
  7. package/dist/src/users/Users.js.map +1 -1
  8. package/dist/src/util/searchingFields/IotFields.js +2 -1
  9. package/dist/src/util/searchingFields/IotFields.js.map +1 -1
  10. package/docs/ast/source/users/Users.js.json +21752 -13474
  11. package/docs/ast/source/util/searchingFields/IotFields.js.json +556 -392
  12. package/docs/class/src/users/Users.js~User.html +336 -19
  13. package/docs/coverage.json +8 -6
  14. package/docs/dump.json +686 -490
  15. package/docs/file/src/users/Users.js.html +58 -4
  16. package/docs/file/src/util/searchingFields/IotFields.js.html +2 -1
  17. package/docs/package.json +4 -3
  18. package/docs/script/search_index.js +18 -0
  19. package/docs/source.html +237 -237
  20. package/features/features/provision/users/update_password.feature +11 -0
  21. package/features/features/provision/users/update_user.feature +3 -0
  22. package/features/step_definitions/when_step_definitions.js +29 -0
  23. package/features/support/create_provision_model.js +3 -1
  24. package/package.json +4 -3
  25. package/scripts/compile_sources.js +2 -2
  26. package/src/users/Users.js +58 -4
  27. package/src/util/searchingFields/IotFields.js +2 -1
  28. package/dist/opengate-api-bower-13.0.0.js.map +0 -1
  29. package/dist/opengate-api-bower-13.0.0.min.js +0 -47
  30. package/dist/opengate-api-bower-13.0.0.min.js.map +0 -1
@@ -2,6 +2,7 @@
2
2
  @provision
3
3
  @users
4
4
  @update_password
5
+ @wip
5
6
 
6
7
  Feature: Update password with logged in user or because it is not secure
7
8
  As a user of JsApi
@@ -57,6 +58,16 @@ Feature: Update password with logged in user or because it is not secure
57
58
  Then I update password with "Nvoiqewvouoiu32j@#!!"
58
59
  And response code should be: 200
59
60
 
61
+ Scenario: Update apiKey
62
+ Given an user remove her authorization options
63
+ Given an ogapi "users builder" util
64
+ Then I want to update a "user"
65
+ And the "email" "ogux_ogapi@amplia.com"
66
+ And the "password" "Nvoiqewvouoiu32j@"
67
+ #npx uuid v4 for generate UUID
68
+ Then I update apiKey with "7d58d9e2-c372-4792-b87e-f9b368dc46b7"
69
+ And response code should be: 200
70
+
60
71
  Scenario: Deleting an user and organization to use
61
72
  Given an email "YOUR_EMAIL" and password "YOUR_PASSWORD" the user logs in
62
73
  And an ogapi "users builder" util
@@ -4,6 +4,7 @@
4
4
  @users
5
5
  @update_user
6
6
  @urlParameters
7
+ @wip
7
8
 
8
9
  Feature: Delete and Create an user
9
10
  As a user of JsApi
@@ -56,6 +57,8 @@ Feature: Delete and Create an user
56
57
  And the "name" "test name updated"
57
58
  And the "surname" "surname updated"
58
59
  And the "description" "user description updated"
60
+ And the "password" "Nvoiqewvouoiu32j@"
61
+ And the "apiKey" "7d58d9e2-c372-4792-b87e-f9b368dc46b7"
59
62
  And the "2FaType" "NONE"
60
63
  Then I update it
61
64
  And response code should be: 200
@@ -1056,6 +1056,35 @@ When(/^I update password with "([^"]*)"$/, function (field) {
1056
1056
  }
1057
1057
  });
1058
1058
 
1059
+ When(/^I update apiKey with "([^"]*)"$/, function (field) {
1060
+ var _this = this;
1061
+ _this.error = undefined;
1062
+ _this.responseData = undefined;
1063
+
1064
+ function catchResponse(data) {
1065
+ //console.log('catchResponse', data);
1066
+ _this.responseData = data;
1067
+ _this.error = undefined;
1068
+
1069
+ }
1070
+
1071
+ function catchErrorResponse(err) {
1072
+ console.error('catchErrorResponse', err);
1073
+ _this.responseData = err;
1074
+ _this.error = err;
1075
+
1076
+ }
1077
+
1078
+ try {
1079
+ return _this.util.changeApiKey(field).then(catchResponse).catch(catchErrorResponse);
1080
+ } catch (err) {
1081
+ console.error('ERROR: ', err);
1082
+ this.error = err;
1083
+
1084
+ return;
1085
+ }
1086
+ });
1087
+
1059
1088
  When(/^I update password with "([^"]*)" and token$/, function (password) {
1060
1089
  var _this = this;
1061
1090
  _this.error = undefined;
@@ -29,7 +29,9 @@ module.exports = {
29
29
  'langCode': 'withLangCode',
30
30
  'name': 'withName',
31
31
  'surname': 'withSurname',
32
- '2FaType': 'with2FaType'
32
+ '2FaType': 'with2FaType',
33
+ 'apiKey': 'withApiKey',
34
+ 'password': 'withPassword',
33
35
  },
34
36
  'organization': {
35
37
  'name': 'withName',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opengate-js",
3
- "version": "13.0.0",
3
+ "version": "13.2.0",
4
4
  "description": "",
5
5
  "main": "dist/opengate-api-npm.js",
6
6
  "repository": {
@@ -28,7 +28,8 @@
28
28
  "superagent": "^3.8.3",
29
29
  "superagent-mocker": "^0.5.2",
30
30
  "underscore": "^1.9.0",
31
- "urlencode": "^1.1.0"
31
+ "urlencode": "^1.1.0",
32
+ "uuid": "9.0.1"
32
33
  },
33
34
  "scripts": {
34
35
  "test-wip": "export NODE_OPTIONS='--max-old-space-size=8192'; gulp cucumber --tags @wip"
@@ -54,7 +55,7 @@
54
55
  "gulp-rename": "^1.2.2",
55
56
  "gulp-sourcemaps": "^1.5.2",
56
57
  "gulp-tag-version": "^1.3.0",
57
- "gulp-uglify": "^2.0.0",
58
+ "gulp-terser": "^2.1.0",
58
59
  "gulp-ver": "^0.1.0",
59
60
  "jsdom": "^16.4.0",
60
61
  "minimist": "^1.2.5",
@@ -1,5 +1,5 @@
1
1
  var gulp = require('gulp'),
2
- uglify = require('gulp-uglify'),
2
+ terser = require('gulp-terser'),
3
3
  ver = require('gulp-ver'),
4
4
  esdoc = require("gulp-esdoc"),
5
5
  clean = require('gulp-clean'),
@@ -79,7 +79,7 @@ gulp.task('bower:min', function() {
79
79
  debug: false,
80
80
  transform: ['babelify']
81
81
  }))
82
- .pipe(uglify())
82
+ .pipe(terser())
83
83
  .pipe(ver())
84
84
  .pipe(rename({
85
85
  suffix: ".min"
@@ -1,8 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  import BaseProvision from '../provision/BaseProvision';
4
- import q from 'q';
5
4
  import _ from 'lodash';
5
+ import { version as uuidVersion } from 'uuid';
6
+ import { validate as uuidValidate } from 'uuid';
7
+ import { v4 as uuidv4 } from 'uuid';
6
8
 
7
9
  const _length_name = 100;
8
10
  const _length_surname = 100;
@@ -72,6 +74,19 @@ export default class User extends BaseProvision {
72
74
  return this;
73
75
  }
74
76
 
77
+ /**
78
+ * Set the apiKey attribute. Only on update user
79
+ * @param {string} apiKey - required field
80
+ * @return {User}
81
+ */
82
+ withApiKey(apiKey) {
83
+ if(!this._validateUUID(apiKey)){
84
+ throw new Error({ message: "OGAPI_USER_UPDATE_APIKEY_PARAMETER_INVALID", parameter: 'apiKey' });
85
+ }
86
+ this._apiKey = apiKey;
87
+ return this;
88
+ }
89
+
75
90
  /**
76
91
  * Set the workgroup attribute
77
92
  * @param {string} workgroup - required field
@@ -219,9 +234,6 @@ export default class User extends BaseProvision {
219
234
  * @private
220
235
  */
221
236
  _composeUpdateElement() {
222
- if (this._password) {
223
- throw new Error('OGAPI_PASSWORD_NOT_ALLOWED');
224
- }
225
237
  if (this._email === undefined)
226
238
  throw new Error('OGAPI_USER_UPDATE_PARAMETER_MUST_BE_DEFINED');
227
239
 
@@ -237,6 +249,8 @@ export default class User extends BaseProvision {
237
249
  countryCode: this._countryCode || undefined,
238
250
  langCode: this._langCode || undefined,
239
251
  timezone: this._timezone || undefined,
252
+ apiKey: this._apiKey || undefined,
253
+ password: this._password || undefined,
240
254
  "2FaType": this._twoFaType || undefined
241
255
  }
242
256
  };
@@ -273,6 +287,42 @@ export default class User extends BaseProvision {
273
287
  return this._doNorthPut(this._buildURL(), data);
274
288
  }
275
289
 
290
+ _validateUUID(UUID){
291
+ return uuidValidate(UUID) && uuidVersion(UUID) === 4
292
+ }
293
+ /**
294
+ * This invoke a request to OpenGate North API and the callback is managed by promises
295
+ * This function updates a apiKey of a user
296
+ * @return {Promise}
297
+ * @param {String} apiKey - required field
298
+ * @property {function (result:object, statusCode:number)} then - When request it is OK
299
+ * @property {function (error:string)} catch - When request it is NOK
300
+ * @example
301
+ * ogapi.usersBuilder().withEmail(example@example.es).withPassword(oldPassword).changeApiKey(newPassword);
302
+ */
303
+ changeApiKey(apiKey) {
304
+ this._apiKey = apiKey;
305
+ if (_.isEmpty(this._email) || _.isEmpty(this._password) || _.isEmpty(this._apiKey)) {
306
+ throw new Error('OGAPI_USER_UPDATE_APIKEY_PARAMETER_MUST_BE_DEFINED');
307
+ }
308
+
309
+ if(!this._validateUUID(apiKey)){
310
+ throw new Error({ message: "OGAPI_USER_UPDATE_APIKEY_PARAMETER_INVALID", parameter: 'apiKey' });
311
+ }
312
+
313
+ var data = {
314
+ user: {
315
+ apiKey: this._apiKey
316
+ }
317
+ };
318
+
319
+ this._setExtraHeaders({
320
+ 'X-ApiPass': this._password
321
+ });
322
+
323
+ return this._doNorthPut(this._buildURL(), data);
324
+ }
325
+
276
326
  /**
277
327
  * This invoke a request to OpenGate North API and the callback is managed by promises
278
328
  * This function request for new password when the user forgets it.
@@ -355,4 +405,8 @@ export default class User extends BaseProvision {
355
405
 
356
406
  return this._doNorthPost(url, data, true)
357
407
  }
408
+
409
+ generateApiKey(){
410
+ return uuidv4()
411
+ }
358
412
  }
@@ -286,7 +286,8 @@ export const IOT_FIELDS = {
286
286
  "alarmAttentionNote": "alarm.attentionNote",
287
287
  "alarmClosureDate": "alarm.closureDate",
288
288
  "alarmClosureUser": "alarm.closureUser",
289
- "alarmClosureNote": "alarm.closureNote"
289
+ "alarmClosureNote": "alarm.closureNote",
290
+ "alarmExtraInfo": "alarm.extra_info"
290
291
  }
291
292
  },
292
293
  "GENERAL": {
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"mappings":"","sources":["opengate-api-bower.js"],"file":"opengate-api-bower-13.0.0.js","sourceRoot":".."}