@docbrasil/api-systemmanager 1.1.30 → 1.1.32

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 (81) hide show
  1. package/api/ai.js +97 -0
  2. package/api/user/notification.js +47 -6
  3. package/dist/bundle.cjs +140 -6
  4. package/dist/bundle.mjs +1 -1
  5. package/doc/api.md +77 -4
  6. package/docs/Admin.html +1 -1
  7. package/docs/AdminDocuments.html +1 -1
  8. package/docs/AdminForm.html +1 -1
  9. package/docs/AdminLists.html +1 -1
  10. package/docs/AdminMessage.html +1 -1
  11. package/docs/AdminNotification.html +1 -1
  12. package/docs/AdminPlugin.html +1 -1
  13. package/docs/AdminPolicy.html +1 -1
  14. package/docs/AdminProcesses.html +1 -1
  15. package/docs/AdminTask.html +1 -1
  16. package/docs/AdminUser.html +1 -1
  17. package/docs/Application.html +1 -1
  18. package/docs/Chart.html +1 -1
  19. package/docs/Dashboard.html +1 -1
  20. package/docs/Datasource.html +1 -1
  21. package/docs/Dispatch.html +1 -1
  22. package/docs/Documents.html +1 -1
  23. package/docs/External.html +1 -1
  24. package/docs/GeoLocation.html +1 -1
  25. package/docs/Help.html +1 -1
  26. package/docs/Login.html +1 -1
  27. package/docs/MyTasks.html +1 -1
  28. package/docs/MyndAI.html +650 -0
  29. package/docs/Notification.html +325 -11
  30. package/docs/Organization.html +1 -1
  31. package/docs/Page.html +1 -1
  32. package/docs/Process.html +1 -1
  33. package/docs/Register.html +1 -1
  34. package/docs/Session.html +1 -1
  35. package/docs/Settings.html +1 -1
  36. package/docs/Task.html +1 -1
  37. package/docs/TaskAvailable.html +1 -1
  38. package/docs/Updates.html +1 -1
  39. package/docs/User.html +1 -1
  40. package/docs/Users.html +1 -1
  41. package/docs/admin_doctypes.js.html +1 -1
  42. package/docs/admin_document.js.html +1 -1
  43. package/docs/admin_form.js.html +1 -1
  44. package/docs/admin_index.js.html +1 -1
  45. package/docs/admin_list.js.html +1 -1
  46. package/docs/admin_message.js.html +1 -1
  47. package/docs/admin_notification.js.html +1 -1
  48. package/docs/admin_organization.js.html +1 -1
  49. package/docs/admin_plugin.js.html +1 -1
  50. package/docs/admin_policy.js.html +1 -1
  51. package/docs/admin_processes.js.html +1 -1
  52. package/docs/admin_task.js.html +1 -1
  53. package/docs/admin_user.js.html +1 -1
  54. package/docs/ai.js.html +214 -0
  55. package/docs/dispatch.js.html +1 -1
  56. package/docs/external.js.html +1 -1
  57. package/docs/general_geoLocation.js.html +1 -1
  58. package/docs/general_index.js.html +1 -1
  59. package/docs/index.html +1 -1
  60. package/docs/login.js.html +1 -1
  61. package/docs/session.js.html +1 -1
  62. package/docs/user_application.js.html +1 -1
  63. package/docs/user_dashboard.js.html +1 -1
  64. package/docs/user_datasource.js.html +1 -1
  65. package/docs/user_document.js.html +1 -1
  66. package/docs/user_help.js.html +1 -1
  67. package/docs/user_index.js.html +1 -1
  68. package/docs/user_my_tasks.js.html +1 -1
  69. package/docs/user_notification.js.html +48 -7
  70. package/docs/user_organization.js.html +1 -1
  71. package/docs/user_page.js.html +1 -1
  72. package/docs/user_process.js.html +1 -1
  73. package/docs/user_register.js.html +1 -1
  74. package/docs/user_settings.js.html +1 -1
  75. package/docs/user_task.js.html +1 -1
  76. package/docs/user_task_available.js.html +1 -1
  77. package/docs/user_updates.js.html +1 -1
  78. package/docs/user_user.js.html +1 -1
  79. package/docs/utils_promises.js.html +1 -1
  80. package/index.js +2 -0
  81. package/package.json +1 -1
package/api/ai.js ADDED
@@ -0,0 +1,97 @@
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+
5
+ /**
6
+ * Class using AI
7
+ * @class
8
+ */
9
+ class MyndAI {
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
+ throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
30
+ } else {
31
+ return _.get(retData, 'data', def);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @author Myndware <augusto.pissarra@myndware.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(authorization) {
43
+ return {
44
+ headers: {
45
+ authorization,
46
+ }
47
+ };
48
+ }
49
+
50
+ /**
51
+ * @author Myndware <augusto.pissarra@myndware.com>
52
+ * @description Create new document
53
+ * @param {object} params Object for add new document
54
+ * @param {string} params.model The model to use for the explain
55
+ * @param {object} params.context The context to apply to a prompt
56
+ * @param {string} params.text The text to add to the prompt
57
+ * @param {array<base64>} params.medias Medias to add to the case in base64 (PDF, Image, Video, Audio)
58
+ * @param {string} params.propmpt The actual prompt with context and text to apply to
59
+ * @return {Promise<object>} data
60
+ * @return {boolean} data.success true|false for success
61
+ * @return {object} data.result the result of the AI call
62
+ * @return {string} data.result.response The actual text response according the prompt
63
+ * @return {number} data.result.tokens The quantity of token used in this request
64
+ * @public
65
+ * @async
66
+ * @example
67
+ *
68
+ * const API = require('@docbrasil/api-systemmanager');
69
+ * const api = new API();
70
+ * const authorization = '...';
71
+ * const params = {
72
+ * model: 'model-name',
73
+ * context: { name: 'Some name' },
74
+ * text: 'Say hello to the world',
75
+ * medias: ['...'],
76
+ * prompt: 'Write a story about {{name}} with the following theme: {{text}}',
77
+ * };
78
+ * const retData = await api.ai.explain(params, authorization);
79
+ */
80
+ async explain(params, authorization) {
81
+ const self = this;
82
+
83
+ try {
84
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
85
+ Joi.assert(params.propmpt, Joi.string().required().error(new Error('Provide a prompt')));
86
+
87
+ const apiCall = self._client
88
+ .post('/agents/explain', params, self._setHeader(authorization));
89
+
90
+ return self._returnData(await apiCall);
91
+ } catch (ex) {
92
+ throw ex;
93
+ }
94
+ }
95
+ }
96
+
97
+ export default MyndAI;
@@ -62,8 +62,10 @@ class Notification {
62
62
  * @author Myndware <augusto.pissarra@myndware.com>
63
63
  * @description Method to add a notification token
64
64
  * @param {object} params Params to add notification token
65
- * @param {string} params.token The token
66
- * @param {object} params.type The token type
65
+ * @param {obhect} params.token The token
66
+ * @param {object} params.token.value The token value
67
+ * @param {object} params.token.type The token type
68
+ * @param {object} params.token.data The extra data of a token, if there is.
67
69
  * @param {string} session Is token JWT of user NOT allow SU
68
70
  * @returns {promise<object>} data
69
71
  * @returns {boolean} data._id the id of the added token
@@ -74,21 +76,60 @@ class Notification {
74
76
  * const api = new API();
75
77
  * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
76
78
  * const params = {
77
- * token: 'V6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz2',
78
- * type: 'FCM_WEB'
79
+ * token: {
80
+ * value: 'V6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz2',
81
+ * type: 'FCM_CAPACITOR'
82
+ * }
79
83
  * };
80
84
  * const retData = await api.user.notification.addToken(params, session);
81
85
  */
82
86
  async addToken(params = {}, session) {
83
87
  const self = this;
84
88
 
89
+ try {
90
+ Joi.assert(params, Joi.object().required(), 'Params to get task');
91
+ Joi.assert(params.token, Joi.object().required(), 'Token information to add');
92
+ Joi.assert(params.token.value, Joi.string().required(), 'Token token value');
93
+ Joi.assert(params.token.type, Joi.string().required(), 'The type of the token');
94
+
95
+ const apiCall = self._client
96
+ .put(`/notifications/token`, params, self._setHeader(session));
97
+
98
+ const retData = self._returnData(await apiCall);
99
+ return retData;
100
+ } catch (ex) {
101
+ throw ex;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * @author Myndware <augusto.pissarra@myndware.com>
107
+ * @description Method to remove a notification token
108
+ * @param {object} params Params to add notification token
109
+ * @param {obhect} params.token The token value
110
+ * @param {string} session Is token JWT of user NOT allow SU
111
+ * @returns {promise<object>} data
112
+ * @returns {boolean} data._id the id of the added token
113
+ * @public
114
+ * @example
115
+ *
116
+ * const API = require('@docbrasil/api-systemmanager');
117
+ * const api = new API();
118
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
119
+ * const params = {
120
+ * token:'V6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz2'
121
+ * };
122
+ * const retData = await api.user.notification.removeToken(params, session);
123
+ */
124
+ async removeToken(params = {}, session) {
125
+ const self = this;
126
+
85
127
  try {
86
128
  Joi.assert(params, Joi.object().required(), 'Params to get task');
87
129
  Joi.assert(params.token, Joi.string().required(), 'Token is required');
88
- Joi.assert(params.type, Joi.string().required(), ' The token type');
89
130
 
90
131
  const apiCall = self._client
91
- .put(`/users/notifications/token`, params, self._setHeader(session));
132
+ .delete(`/notifications/token/${params.token}`, self._setHeader(session));
92
133
 
93
134
  const retData = self._returnData(await apiCall);
94
135
  return retData;
package/dist/bundle.cjs CHANGED
@@ -10384,8 +10384,10 @@ class Notification {
10384
10384
  * @author Myndware <augusto.pissarra@myndware.com>
10385
10385
  * @description Method to add a notification token
10386
10386
  * @param {object} params Params to add notification token
10387
- * @param {string} params.token The token
10388
- * @param {object} params.type The token type
10387
+ * @param {obhect} params.token The token
10388
+ * @param {object} params.token.value The token value
10389
+ * @param {object} params.token.type The token type
10390
+ * @param {object} params.token.data The extra data of a token, if there is.
10389
10391
  * @param {string} session Is token JWT of user NOT allow SU
10390
10392
  * @returns {promise<object>} data
10391
10393
  * @returns {boolean} data._id the id of the added token
@@ -10396,21 +10398,60 @@ class Notification {
10396
10398
  * const api = new API();
10397
10399
  * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
10398
10400
  * const params = {
10399
- * token: 'V6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz2',
10400
- * type: 'FCM_WEB'
10401
+ * token: {
10402
+ * value: 'V6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz2',
10403
+ * type: 'FCM_CAPACITOR'
10404
+ * }
10401
10405
  * };
10402
10406
  * const retData = await api.user.notification.addToken(params, session);
10403
10407
  */
10404
10408
  async addToken(params = {}, session) {
10405
10409
  const self = this;
10406
10410
 
10411
+ try {
10412
+ Joi__default["default"].assert(params, Joi__default["default"].object().required(), 'Params to get task');
10413
+ Joi__default["default"].assert(params.token, Joi__default["default"].object().required(), 'Token information to add');
10414
+ Joi__default["default"].assert(params.token.value, Joi__default["default"].string().required(), 'Token token value');
10415
+ Joi__default["default"].assert(params.token.type, Joi__default["default"].string().required(), 'The type of the token');
10416
+
10417
+ const apiCall = self._client
10418
+ .put(`/notifications/token`, params, self._setHeader(session));
10419
+
10420
+ const retData = self._returnData(await apiCall);
10421
+ return retData;
10422
+ } catch (ex) {
10423
+ throw ex;
10424
+ }
10425
+ }
10426
+
10427
+ /**
10428
+ * @author Myndware <augusto.pissarra@myndware.com>
10429
+ * @description Method to remove a notification token
10430
+ * @param {object} params Params to add notification token
10431
+ * @param {obhect} params.token The token value
10432
+ * @param {string} session Is token JWT of user NOT allow SU
10433
+ * @returns {promise<object>} data
10434
+ * @returns {boolean} data._id the id of the added token
10435
+ * @public
10436
+ * @example
10437
+ *
10438
+ * const API = require('@docbrasil/api-systemmanager');
10439
+ * const api = new API();
10440
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
10441
+ * const params = {
10442
+ * token:'V6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz2'
10443
+ * };
10444
+ * const retData = await api.user.notification.removeToken(params, session);
10445
+ */
10446
+ async removeToken(params = {}, session) {
10447
+ const self = this;
10448
+
10407
10449
  try {
10408
10450
  Joi__default["default"].assert(params, Joi__default["default"].object().required(), 'Params to get task');
10409
10451
  Joi__default["default"].assert(params.token, Joi__default["default"].string().required(), 'Token is required');
10410
- Joi__default["default"].assert(params.type, Joi__default["default"].string().required(), ' The token type');
10411
10452
 
10412
10453
  const apiCall = self._client
10413
- .put(`/users/notifications/token`, params, self._setHeader(session));
10454
+ .delete(`/notifications/token/${params.token}`, self._setHeader(session));
10414
10455
 
10415
10456
  const retData = self._returnData(await apiCall);
10416
10457
  return retData;
@@ -13929,6 +13970,98 @@ class External {
13929
13970
 
13930
13971
  }
13931
13972
 
13973
+ /**
13974
+ * Class using AI
13975
+ * @class
13976
+ */
13977
+ class MyndAI {
13978
+
13979
+ constructor(options) {
13980
+ Joi__default["default"].assert(options, Joi__default["default"].object().required());
13981
+ Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
13982
+
13983
+ const self = this;
13984
+ self.parent = options.parent;
13985
+ self._client = self.parent.dispatch.getClient();
13986
+ }
13987
+
13988
+ /**
13989
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
13990
+ * @description Get the return data and check for errors
13991
+ * @param {object} retData Response HTTP
13992
+ * @return {*}
13993
+ * @private
13994
+ */
13995
+ _returnData(retData, def = {}) {
13996
+ if (retData.status !== 200) {
13997
+ throw Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
13998
+ } else {
13999
+ return ___default["default"].get(retData, 'data', def);
14000
+ }
14001
+ }
14002
+
14003
+ /**
14004
+ * @author Myndware <augusto.pissarra@myndware.com>
14005
+ * @description Set header with new session
14006
+ * @param {string} session Session, token JWT
14007
+ * @return {object} header with new session
14008
+ * @private
14009
+ */
14010
+ _setHeader(authorization) {
14011
+ return {
14012
+ headers: {
14013
+ authorization,
14014
+ }
14015
+ };
14016
+ }
14017
+
14018
+ /**
14019
+ * @author Myndware <augusto.pissarra@myndware.com>
14020
+ * @description Create new document
14021
+ * @param {object} params Object for add new document
14022
+ * @param {string} params.model The model to use for the explain
14023
+ * @param {object} params.context The context to apply to a prompt
14024
+ * @param {string} params.text The text to add to the prompt
14025
+ * @param {array<base64>} params.medias Medias to add to the case in base64 (PDF, Image, Video, Audio)
14026
+ * @param {string} params.propmpt The actual prompt with context and text to apply to
14027
+ * @return {Promise<object>} data
14028
+ * @return {boolean} data.success true|false for success
14029
+ * @return {object} data.result the result of the AI call
14030
+ * @return {string} data.result.response The actual text response according the prompt
14031
+ * @return {number} data.result.tokens The quantity of token used in this request
14032
+ * @public
14033
+ * @async
14034
+ * @example
14035
+ *
14036
+ * const API = require('@docbrasil/api-systemmanager');
14037
+ * const api = new API();
14038
+ * const authorization = '...';
14039
+ * const params = {
14040
+ * model: 'model-name',
14041
+ * context: { name: 'Some name' },
14042
+ * text: 'Say hello to the world',
14043
+ * medias: ['...'],
14044
+ * prompt: 'Write a story about {{name}} with the following theme: {{text}}',
14045
+ * };
14046
+ * const retData = await api.ai.explain(params, authorization);
14047
+ */
14048
+ async explain(params, authorization) {
14049
+ const self = this;
14050
+
14051
+ try {
14052
+ Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
14053
+ Joi__default["default"].assert(params.propmpt, Joi__default["default"].string().required().error(new Error('Provide a prompt')));
14054
+
14055
+ const apiCall = self._client
14056
+ .post('/agents/explain', params, self._setHeader(authorization));
14057
+
14058
+ return self._returnData(await apiCall);
14059
+ } catch (ex) {
14060
+ throw ex;
14061
+ }
14062
+ }
14063
+ }
14064
+
13932
14065
  /**
13933
14066
  * Class API
13934
14067
  */
@@ -14000,6 +14133,7 @@ class API {
14000
14133
  self.user = new Users({parent: self});
14001
14134
  self.admin = new Admin({parent: self});
14002
14135
  self.external = new External({parent: self});
14136
+ self.ai = new MyndAI({parent: self});
14003
14137
  }
14004
14138
  }
14005
14139