@docbrasil/api-systemmanager 1.0.66 → 1.0.69

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/api/login.js CHANGED
@@ -173,7 +173,7 @@ class Login {
173
173
  *
174
174
  * const API = require('@docbrasil/api-systemmanager');
175
175
  *
176
- * // Params of the instance
176
+ * // Params of the instance
177
177
  * const params = {...}
178
178
  * const api = new API(params);
179
179
  * const params = {
@@ -1,13 +1,12 @@
1
1
  import _ from 'lodash';
2
2
  import Boom from '@hapi/boom';
3
3
  import Joi from 'joi';
4
- import Cypher from '../utils/cypher';
5
4
 
6
5
  /**
7
6
  * Class for user registration in a user
8
7
  * @class
9
8
  */
10
- class Register {
9
+ class Notification {
11
10
 
12
11
  constructor(options) {
13
12
  Joi.assert(options, Joi.object().required());
@@ -48,6 +47,16 @@ class Register {
48
47
  };
49
48
  }
50
49
 
50
+ /**
51
+ * Notification token types
52
+ * @return {{FCM_CAPACITOR: string, FCM_WEB: string}}
53
+ */
54
+ get tokenTypes () {
55
+ return {
56
+ FCM_WEB: 'FCM_WEB',
57
+ FCM_CAPACITOR: 'FCM_CAPACITOR'
58
+ };
59
+ }
51
60
 
52
61
  /**
53
62
  * @author CloudBrasil <abernardo.br@gmail.com>
@@ -55,6 +64,7 @@ class Register {
55
64
  * @param {object} params Params to add notification token
56
65
  * @param {string} params.token The token
57
66
  * @param {object} params.type The token type
67
+ * @param {string} session Is token JWT of user NOT allow SU
58
68
  * @returns {promise<object>} data
59
69
  * @returns {boolean} data._id the id of the added token
60
70
  * @public
@@ -62,13 +72,14 @@ class Register {
62
72
  *
63
73
  * const API = require('@docbrasil/api-systemmanager');
64
74
  * const api = new API();
75
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
65
76
  * const params = {
66
77
  * token: 'V6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz2',
67
78
  * type: 'FCM_WEB'
68
79
  * };
69
- * const retData = await api.user.notification.addToken(params);
80
+ * const retData = await api.user.notification.addToken(params, session);
70
81
  */
71
- async addToken(params = {}) {
82
+ async addToken(params = {}, session) {
72
83
  const self = this;
73
84
 
74
85
  try {
@@ -77,7 +88,7 @@ class Register {
77
88
  Joi.assert(params.type, Joi.string().required(), ' The token type');
78
89
 
79
90
  const apiCall = self._client
80
- .put(`/users/notifications/token`, params);
91
+ .put(`/users/notifications/token`, params, self._setHeader(session));
81
92
 
82
93
  const retData = self._returnData(await apiCall);
83
94
  return retData;
@@ -85,89 +96,6 @@ class Register {
85
96
  throw ex;
86
97
  }
87
98
  }
88
-
89
- /**
90
- * @author CloudBrasil <abernardo.br@gmail.com>
91
- * @description Method to register a user
92
- * @param {object} params Params to get task
93
- * @param {string} params.registerId The registerId that comes with the registration page context
94
- * @param {string} params.type=sign The type of the registration. By defailt,
95
- * @param {boolean} params.login=false If we want to login the user directly after registering the user successfully. If you have a redirect, the best option is to login automatically.
96
- * @param {object} params.emailInfo The information for the email validation
97
- * @param {string} params.emailInfo.email The email validation information
98
- * @param {string} params.emailInfo.code The 4 digit code to validate the email
99
- * @param {object} params.registerData The registration data
100
- * @param {string} params.registerData.name The name if the user
101
- * @param {string} params.registerData.registerEmail The email of the user
102
- * @param {string} params.registerData.phone The phone of the user
103
- * @param {string} params.registerData.idcard The ID card of the user
104
- * @param {string} params.registerData.registerPassword The user password in open text
105
- * @param {string} params.registerData.emailValidationCode The code used to validate the email
106
- * @param {string} params.registerData.phoneValidationCode The code used to validate the phone
107
- * @param {string} params.registerData.language The defaulf navigator language (i.e.: navigator.language)
108
- * @param {string} params.registerData.timezone The defaulf navigator timezone (i.e.: Intl.DateTimeFormat().resolvedOptions().timeZone)
109
- * @returns {promise<object>} data
110
- * @returns {boolean} data.success If the operation was successfully done (true|false)
111
- * @returns {boolean} data.userAlreadyExists If the user already exists (true|false), if true, then the other information is not returned
112
- * @returns {object} auth The full authentication data with session, if login is true.
113
- * @returns {string} auth.redirectUrl The url to redirect.
114
- * @public
115
- * @example
116
- *
117
- * const API = require('@docbrasil/api-systemmanager');
118
- * const api = new API();
119
- * const params ={
120
- * "registerId": 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...',
121
- * "type": 'sign',
122
- * "login": false,
123
- * "emailInfo": {
124
- * "code": "5974",
125
- * "email": "cbtoto_1@mailinator.com"
126
- * },
127
- * "registerData": {
128
- * "name": "Augusto Totlo",
129
- * "registerEmail": "cbtoto_1@mailinator.com",
130
- * "phone": "",
131
- * "idcard": "",
132
- * "dob": "1978-01-12T03:00:00.000Z",
133
- * "registerPassword": "123456",
134
- * "emailValidationCode": "5974",
135
- * "phoneValidationCode": "",
136
- * "language": "en-US",
137
- * "timezone": "Europe/Dublin"
138
- * }
139
- * };
140
- * const retData = await api.user.register.execute(params);
141
- */
142
- async execute(params = {}) {
143
- const self = this;
144
-
145
- try {
146
- Joi.assert(params, Joi.object().required(), 'Params to get task');
147
- Joi.assert(params.registerId, Joi.string().required(), ' RegisterId for registration');
148
- Joi.assert(params.emailInfo, Joi.object().required(), ' The email info');
149
- Joi.assert(params.registerData, Joi.object().required(), ' The registerData');
150
-
151
- const {
152
- type = 'sign',
153
- registerId = '',
154
- emailInfo = {},
155
- registerData = {},
156
- login = false
157
- } = params;
158
- const registerInfo = Cypher.get(registerId) || {};
159
- const payload = { ...registerInfo, type, login, emailInfo, registerData };
160
- const payloadInfo = { info: Cypher.set(payload) };
161
- const apiCall = self._client
162
- .put(`/users/register`, payloadInfo);
163
-
164
- const { success = false, userAlreadyExists = false, auth } = self._returnData(await apiCall);
165
- const retData = { success, userAlreadyExists, auth };
166
- return retData;
167
- } catch (ex) {
168
- throw ex;
169
- }
170
- }
171
99
  }
172
100
 
173
- export default Register;
101
+ export default Notification;
package/api/user/user.js CHANGED
@@ -186,7 +186,7 @@ class User {
186
186
  Joi.assert(data.file, Joi.string().required());
187
187
  Joi.assert(session, Joi.string().required());
188
188
 
189
- const apiCall = self._client.delete(`/users/signature`, self._setHeader(session));
189
+ const apiCall = self._client.put(`/users/signature`, self._setHeader(session));
190
190
  return self._returnData(await apiCall);
191
191
  } catch (ex) {
192
192
  throw ex;
package/dist/bundle.cjs CHANGED
@@ -362,7 +362,7 @@ class Login {
362
362
  *
363
363
  * const API = require('@docbrasil/api-systemmanager');
364
364
  *
365
- * // Params of the instance
365
+ * // Params of the instance
366
366
  * const params = {...}
367
367
  * const api = new API(params);
368
368
  * const params = {
@@ -1837,7 +1837,7 @@ class User {
1837
1837
  Joi__default["default"].assert(data.file, Joi__default["default"].string().required());
1838
1838
  Joi__default["default"].assert(session, Joi__default["default"].string().required());
1839
1839
 
1840
- const apiCall = self._client.delete(`/users/signature`, self._setHeader(session));
1840
+ const apiCall = self._client.put(`/users/signature`, self._setHeader(session));
1841
1841
  return self._returnData(await apiCall);
1842
1842
  } catch (ex) {
1843
1843
  throw ex;
@@ -8675,7 +8675,7 @@ const cypher = new Cypher();
8675
8675
  * Class for user registration in a user
8676
8676
  * @class
8677
8677
  */
8678
- class Register$1 {
8678
+ class Register {
8679
8679
 
8680
8680
  constructor(options) {
8681
8681
  Joi__default["default"].assert(options, Joi__default["default"].object().required());
@@ -8874,7 +8874,7 @@ class Register$1 {
8874
8874
  * Class for user registration in a user
8875
8875
  * @class
8876
8876
  */
8877
- class Register {
8877
+ class Notification {
8878
8878
 
8879
8879
  constructor(options) {
8880
8880
  Joi__default["default"].assert(options, Joi__default["default"].object().required());
@@ -8915,6 +8915,16 @@ class Register {
8915
8915
  };
8916
8916
  }
8917
8917
 
8918
+ /**
8919
+ * Notification token types
8920
+ * @return {{FCM_CAPACITOR: string, FCM_WEB: string}}
8921
+ */
8922
+ get tokenTypes () {
8923
+ return {
8924
+ FCM_WEB: 'FCM_WEB',
8925
+ FCM_CAPACITOR: 'FCM_CAPACITOR'
8926
+ };
8927
+ }
8918
8928
 
8919
8929
  /**
8920
8930
  * @author CloudBrasil <abernardo.br@gmail.com>
@@ -8922,6 +8932,7 @@ class Register {
8922
8932
  * @param {object} params Params to add notification token
8923
8933
  * @param {string} params.token The token
8924
8934
  * @param {object} params.type The token type
8935
+ * @param {string} session Is token JWT of user NOT allow SU
8925
8936
  * @returns {promise<object>} data
8926
8937
  * @returns {boolean} data._id the id of the added token
8927
8938
  * @public
@@ -8929,13 +8940,14 @@ class Register {
8929
8940
  *
8930
8941
  * const API = require('@docbrasil/api-systemmanager');
8931
8942
  * const api = new API();
8943
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
8932
8944
  * const params = {
8933
8945
  * token: 'V6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz2',
8934
8946
  * type: 'FCM_WEB'
8935
8947
  * };
8936
- * const retData = await api.user.notification.addToken(params);
8948
+ * const retData = await api.user.notification.addToken(params, session);
8937
8949
  */
8938
- async addToken(params = {}) {
8950
+ async addToken(params = {}, session) {
8939
8951
  const self = this;
8940
8952
 
8941
8953
  try {
@@ -8944,7 +8956,7 @@ class Register {
8944
8956
  Joi__default["default"].assert(params.type, Joi__default["default"].string().required(), ' The token type');
8945
8957
 
8946
8958
  const apiCall = self._client
8947
- .put(`/users/notifications/token`, params);
8959
+ .put(`/users/notifications/token`, params, self._setHeader(session));
8948
8960
 
8949
8961
  const retData = self._returnData(await apiCall);
8950
8962
  return retData;
@@ -8952,89 +8964,6 @@ class Register {
8952
8964
  throw ex;
8953
8965
  }
8954
8966
  }
8955
-
8956
- /**
8957
- * @author CloudBrasil <abernardo.br@gmail.com>
8958
- * @description Method to register a user
8959
- * @param {object} params Params to get task
8960
- * @param {string} params.registerId The registerId that comes with the registration page context
8961
- * @param {string} params.type=sign The type of the registration. By defailt,
8962
- * @param {boolean} params.login=false If we want to login the user directly after registering the user successfully. If you have a redirect, the best option is to login automatically.
8963
- * @param {object} params.emailInfo The information for the email validation
8964
- * @param {string} params.emailInfo.email The email validation information
8965
- * @param {string} params.emailInfo.code The 4 digit code to validate the email
8966
- * @param {object} params.registerData The registration data
8967
- * @param {string} params.registerData.name The name if the user
8968
- * @param {string} params.registerData.registerEmail The email of the user
8969
- * @param {string} params.registerData.phone The phone of the user
8970
- * @param {string} params.registerData.idcard The ID card of the user
8971
- * @param {string} params.registerData.registerPassword The user password in open text
8972
- * @param {string} params.registerData.emailValidationCode The code used to validate the email
8973
- * @param {string} params.registerData.phoneValidationCode The code used to validate the phone
8974
- * @param {string} params.registerData.language The defaulf navigator language (i.e.: navigator.language)
8975
- * @param {string} params.registerData.timezone The defaulf navigator timezone (i.e.: Intl.DateTimeFormat().resolvedOptions().timeZone)
8976
- * @returns {promise<object>} data
8977
- * @returns {boolean} data.success If the operation was successfully done (true|false)
8978
- * @returns {boolean} data.userAlreadyExists If the user already exists (true|false), if true, then the other information is not returned
8979
- * @returns {object} auth The full authentication data with session, if login is true.
8980
- * @returns {string} auth.redirectUrl The url to redirect.
8981
- * @public
8982
- * @example
8983
- *
8984
- * const API = require('@docbrasil/api-systemmanager');
8985
- * const api = new API();
8986
- * const params ={
8987
- * "registerId": 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...',
8988
- * "type": 'sign',
8989
- * "login": false,
8990
- * "emailInfo": {
8991
- * "code": "5974",
8992
- * "email": "cbtoto_1@mailinator.com"
8993
- * },
8994
- * "registerData": {
8995
- * "name": "Augusto Totlo",
8996
- * "registerEmail": "cbtoto_1@mailinator.com",
8997
- * "phone": "",
8998
- * "idcard": "",
8999
- * "dob": "1978-01-12T03:00:00.000Z",
9000
- * "registerPassword": "123456",
9001
- * "emailValidationCode": "5974",
9002
- * "phoneValidationCode": "",
9003
- * "language": "en-US",
9004
- * "timezone": "Europe/Dublin"
9005
- * }
9006
- * };
9007
- * const retData = await api.user.register.execute(params);
9008
- */
9009
- async execute(params = {}) {
9010
- const self = this;
9011
-
9012
- try {
9013
- Joi__default["default"].assert(params, Joi__default["default"].object().required(), 'Params to get task');
9014
- Joi__default["default"].assert(params.registerId, Joi__default["default"].string().required(), ' RegisterId for registration');
9015
- Joi__default["default"].assert(params.emailInfo, Joi__default["default"].object().required(), ' The email info');
9016
- Joi__default["default"].assert(params.registerData, Joi__default["default"].object().required(), ' The registerData');
9017
-
9018
- const {
9019
- type = 'sign',
9020
- registerId = '',
9021
- emailInfo = {},
9022
- registerData = {},
9023
- login = false
9024
- } = params;
9025
- const registerInfo = cypher.get(registerId) || {};
9026
- const payload = { ...registerInfo, type, login, emailInfo, registerData };
9027
- const payloadInfo = { info: cypher.set(payload) };
9028
- const apiCall = self._client
9029
- .put(`/users/register`, payloadInfo);
9030
-
9031
- const { success = false, userAlreadyExists = false, auth } = self._returnData(await apiCall);
9032
- const retData = { success, userAlreadyExists, auth };
9033
- return retData;
9034
- } catch (ex) {
9035
- throw ex;
9036
- }
9037
- }
9038
8967
  }
9039
8968
 
9040
8969
  /**
@@ -9057,8 +8986,8 @@ class Users {
9057
8986
  self.process = new Process(options);
9058
8987
  self.task = new Task(options);
9059
8988
  self.user = self.profile = new User(options);
9060
- self.register = new Register$1(options);
9061
- self.notification = new Register(options);
8989
+ self.register = new Register(options);
8990
+ self.notification = new Notification(options);
9062
8991
  }
9063
8992
  }
9064
8993