@docbrasil/api-systemmanager 1.0.65 → 1.0.68
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/user/index.js +2 -0
- package/api/user/notification.js +101 -0
- package/dist/bundle.cjs +97 -0
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +48 -0
- package/package.json +1 -1
package/api/user/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import Process from './process';
|
|
|
7
7
|
import Task from './task';
|
|
8
8
|
import User from './user';
|
|
9
9
|
import Register from './register';
|
|
10
|
+
import Notification from './notification';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @class API request, user permission level
|
|
@@ -29,6 +30,7 @@ class Users {
|
|
|
29
30
|
self.task = new Task(options);
|
|
30
31
|
self.user = self.profile = new User(options);
|
|
31
32
|
self.register = new Register(options);
|
|
33
|
+
self.notification = new Notification(options);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import Boom from '@hapi/boom';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Class for user registration in a user
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
class Notification {
|
|
10
|
+
|
|
11
|
+
constructor(options) {
|
|
12
|
+
Joi.assert(options, Joi.object().required());
|
|
13
|
+
Joi.assert(options.parent, Joi.object().required());
|
|
14
|
+
|
|
15
|
+
const self = this;
|
|
16
|
+
self.parent = options.parent;
|
|
17
|
+
self._client = self.parent.dispatch.getClient();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
22
|
+
* @description Get the return data and check for errors
|
|
23
|
+
* @param {object} retData Response HTTP
|
|
24
|
+
* @return {*}
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
_returnData(retData, def = {}) {
|
|
28
|
+
if (retData.status !== 200) {
|
|
29
|
+
return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
|
|
30
|
+
} else {
|
|
31
|
+
return _.get(retData, 'data', def);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
37
|
+
* @description Set header with new session
|
|
38
|
+
* @param {string} session Session, token JWT
|
|
39
|
+
* @return {object} header with new session
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
_setHeader(session) {
|
|
43
|
+
return {
|
|
44
|
+
headers: {
|
|
45
|
+
authorization: session,
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
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
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
63
|
+
* @description Method to add a notification token
|
|
64
|
+
* @param {object} params Params to add notification token
|
|
65
|
+
* @param {string} params.token The token
|
|
66
|
+
* @param {object} params.type The token type
|
|
67
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
68
|
+
* @returns {promise<object>} data
|
|
69
|
+
* @returns {boolean} data._id the id of the added token
|
|
70
|
+
* @public
|
|
71
|
+
* @example
|
|
72
|
+
*
|
|
73
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
74
|
+
* const api = new API();
|
|
75
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
76
|
+
* const params = {
|
|
77
|
+
* token: 'V6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz2',
|
|
78
|
+
* type: 'FCM_WEB'
|
|
79
|
+
* };
|
|
80
|
+
* const retData = await api.user.notification.addToken(params, session);
|
|
81
|
+
*/
|
|
82
|
+
async addToken(params = {}, session) {
|
|
83
|
+
const self = this;
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
Joi.assert(params, Joi.object().required(), 'Params to get task');
|
|
87
|
+
Joi.assert(params.token, Joi.string().required(), 'Token is required');
|
|
88
|
+
Joi.assert(params.type, Joi.string().required(), ' The token type');
|
|
89
|
+
|
|
90
|
+
const apiCall = self._client
|
|
91
|
+
.put(`/users/notifications/token`, params, self._setHeader(session));
|
|
92
|
+
|
|
93
|
+
const retData = self._returnData(await apiCall);
|
|
94
|
+
return retData;
|
|
95
|
+
} catch (ex) {
|
|
96
|
+
throw ex;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default Notification;
|
package/dist/bundle.cjs
CHANGED
|
@@ -8870,6 +8870,102 @@ class Register {
|
|
|
8870
8870
|
}
|
|
8871
8871
|
}
|
|
8872
8872
|
|
|
8873
|
+
/**
|
|
8874
|
+
* Class for user registration in a user
|
|
8875
|
+
* @class
|
|
8876
|
+
*/
|
|
8877
|
+
class Notification {
|
|
8878
|
+
|
|
8879
|
+
constructor(options) {
|
|
8880
|
+
Joi__default["default"].assert(options, Joi__default["default"].object().required());
|
|
8881
|
+
Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
|
|
8882
|
+
|
|
8883
|
+
const self = this;
|
|
8884
|
+
self.parent = options.parent;
|
|
8885
|
+
self._client = self.parent.dispatch.getClient();
|
|
8886
|
+
}
|
|
8887
|
+
|
|
8888
|
+
/**
|
|
8889
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
8890
|
+
* @description Get the return data and check for errors
|
|
8891
|
+
* @param {object} retData Response HTTP
|
|
8892
|
+
* @return {*}
|
|
8893
|
+
* @private
|
|
8894
|
+
*/
|
|
8895
|
+
_returnData(retData, def = {}) {
|
|
8896
|
+
if (retData.status !== 200) {
|
|
8897
|
+
return Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
|
|
8898
|
+
} else {
|
|
8899
|
+
return ___default["default"].get(retData, 'data', def);
|
|
8900
|
+
}
|
|
8901
|
+
}
|
|
8902
|
+
|
|
8903
|
+
/**
|
|
8904
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
8905
|
+
* @description Set header with new session
|
|
8906
|
+
* @param {string} session Session, token JWT
|
|
8907
|
+
* @return {object} header with new session
|
|
8908
|
+
* @private
|
|
8909
|
+
*/
|
|
8910
|
+
_setHeader(session) {
|
|
8911
|
+
return {
|
|
8912
|
+
headers: {
|
|
8913
|
+
authorization: session,
|
|
8914
|
+
}
|
|
8915
|
+
};
|
|
8916
|
+
}
|
|
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
|
+
}
|
|
8928
|
+
|
|
8929
|
+
/**
|
|
8930
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
8931
|
+
* @description Method to add a notification token
|
|
8932
|
+
* @param {object} params Params to add notification token
|
|
8933
|
+
* @param {string} params.token The token
|
|
8934
|
+
* @param {object} params.type The token type
|
|
8935
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
8936
|
+
* @returns {promise<object>} data
|
|
8937
|
+
* @returns {boolean} data._id the id of the added token
|
|
8938
|
+
* @public
|
|
8939
|
+
* @example
|
|
8940
|
+
*
|
|
8941
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
8942
|
+
* const api = new API();
|
|
8943
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
8944
|
+
* const params = {
|
|
8945
|
+
* token: 'V6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz2',
|
|
8946
|
+
* type: 'FCM_WEB'
|
|
8947
|
+
* };
|
|
8948
|
+
* const retData = await api.user.notification.addToken(params, session);
|
|
8949
|
+
*/
|
|
8950
|
+
async addToken(params = {}, session) {
|
|
8951
|
+
const self = this;
|
|
8952
|
+
|
|
8953
|
+
try {
|
|
8954
|
+
Joi__default["default"].assert(params, Joi__default["default"].object().required(), 'Params to get task');
|
|
8955
|
+
Joi__default["default"].assert(params.token, Joi__default["default"].string().required(), 'Token is required');
|
|
8956
|
+
Joi__default["default"].assert(params.type, Joi__default["default"].string().required(), ' The token type');
|
|
8957
|
+
|
|
8958
|
+
const apiCall = self._client
|
|
8959
|
+
.put(`/users/notifications/token`, params, self._setHeader(session));
|
|
8960
|
+
|
|
8961
|
+
const retData = self._returnData(await apiCall);
|
|
8962
|
+
return retData;
|
|
8963
|
+
} catch (ex) {
|
|
8964
|
+
throw ex;
|
|
8965
|
+
}
|
|
8966
|
+
}
|
|
8967
|
+
}
|
|
8968
|
+
|
|
8873
8969
|
/**
|
|
8874
8970
|
* @class API request, user permission level
|
|
8875
8971
|
*/
|
|
@@ -8891,6 +8987,7 @@ class Users {
|
|
|
8891
8987
|
self.task = new Task(options);
|
|
8892
8988
|
self.user = self.profile = new User(options);
|
|
8893
8989
|
self.register = new Register(options);
|
|
8990
|
+
self.notification = new Notification(options);
|
|
8894
8991
|
}
|
|
8895
8992
|
}
|
|
8896
8993
|
|