@itleanchatbot/shared-models-js-postgres 1.0.12 → 1.0.14

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/index.js CHANGED
@@ -29,6 +29,13 @@ const transhipConversations = require('./src/transhipConversations')
29
29
  const quickMessages = require('./src/quickMessages')
30
30
  const lineConfigurations = require('./src/lineConfigurations')
31
31
  const permissions = require('./src/permissions')
32
+ const apis = require('./src/apis')
33
+ const apiResources = require('./src/apiResources')
34
+ const apiAuthentications = require('./src/apiAuthentications')
35
+ const apiResourceBodies = require('./src/apiResourceBodies')
36
+ const apiResourceHeaders = require('./src/apiResourceHeaders')
37
+ const apiResourcePathParams = require('./src/apiResourcePathParams')
38
+ const apiResourceQueryStringParams = require('./src/apiResourceQueryStringParams')
32
39
 
33
40
  module.exports = {
34
41
  attendances,
@@ -61,5 +68,12 @@ module.exports = {
61
68
  transhipConversations,
62
69
  quickMessages,
63
70
  lineConfigurations,
64
- permissions
71
+ permissions,
72
+ apis,
73
+ apiResources,
74
+ apiAuthentications,
75
+ apiResourceBodies,
76
+ apiResourceHeaders,
77
+ apiResourcePathParams,
78
+ apiResourceQueryStringParams
65
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itleanchatbot/shared-models-js-postgres",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Shared Models JS Postgres",
5
5
  "main": "index.js",
6
6
  "license": "ISC",
@@ -0,0 +1,57 @@
1
+ const { HTTP_METHODS } = require('./apiResources')
2
+
3
+ const API_AUTHENTICATIONS_TYPES = {
4
+ NO_AUTH: 'noAuth',
5
+ API_KEY: 'apiKey',
6
+ BEARER_TOKEN: 'bearerToken',
7
+ BASIC_AUTH: 'basicAuth',
8
+ }
9
+ const API_AUTHENTICATIONS_TYPE = [
10
+ API_AUTHENTICATIONS_TYPES.NO_AUTH,
11
+ API_AUTHENTICATIONS_TYPES.API_KEY,
12
+ API_AUTHENTICATIONS_TYPES.BEARER_TOKEN,
13
+ API_AUTHENTICATIONS_TYPES.BASIC_AUTH,
14
+ ]
15
+
16
+
17
+ const ApiAuthenticationsModel = (sequelize, Sequelize) => {
18
+ const ApiAuthentications = sequelize.define('ApiAuthentications', {
19
+ type: {
20
+ type: Sequelize.ENUM({
21
+ values: API_AUTHENTICATIONS_TYPE,
22
+ }),
23
+ allowNull: false,
24
+ },
25
+ method: {
26
+ type: Sequelize.ENUM({
27
+ values: HTTP_METHODS,
28
+ }),
29
+ allowNull: true,
30
+ },
31
+ value: {
32
+ type: Sequelize.STRING,
33
+ allowNull: true,
34
+ },
35
+ endpoint: {
36
+ type: Sequelize.STRING,
37
+ allowNull: true,
38
+ },
39
+ credentials: {
40
+ type: Sequelize.JSON,
41
+ allowNull: true,
42
+ },
43
+ })
44
+
45
+ ApiAuthentications.associate = (models) => {
46
+ ApiAuthentications.hasOne(models.Apis)
47
+ }
48
+
49
+ return ApiAuthentications
50
+ }
51
+
52
+
53
+ module.exports = {
54
+ ApiAuthenticationsModel,
55
+ API_AUTHENTICATIONS_TYPE,
56
+ API_AUTHENTICATIONS_TYPES
57
+ }
@@ -0,0 +1,42 @@
1
+ const APIS_RESOURCES_BODY_TYPES = {
2
+ JSON: 'json',
3
+ HTML: 'html',
4
+ TEXT: 'text',
5
+ XML: 'xml',
6
+ }
7
+
8
+ const APIS_RESOURCES_BODY_TYPE = [
9
+ APIS_RESOURCES_BODY_TYPES.JSON,
10
+ APIS_RESOURCES_BODY_TYPES.HTML,
11
+ APIS_RESOURCES_BODY_TYPES.TEXT,
12
+ APIS_RESOURCES_BODY_TYPES.XML,
13
+ ]
14
+
15
+ const ApiResourcesBodiesModel = (sequelize, Sequelize) => {
16
+ const ApiResourcesBodies = sequelize.define('ApiResourcesBodies', {
17
+ content: {
18
+ type: Sequelize.TEXT,
19
+ allowNull: false,
20
+ },
21
+ type: {
22
+ type: Sequelize.ENUM({
23
+ values: APIS_RESOURCES_BODY_TYPE,
24
+ }),
25
+ allowNull: false,
26
+ defaultValue: APIS_RESOURCES_BODY_TYPES.JSON,
27
+ },
28
+ })
29
+
30
+ ApiResourcesBodies.associate = (models) => {
31
+ ApiResourcesBodies.hasOne(models.ApiResources)
32
+ }
33
+
34
+ return ApiResourcesBodies
35
+ }
36
+
37
+ module.exports = {
38
+ ApiResourcesBodiesModel,
39
+ APIS_RESOURCES_BODY_TYPE,
40
+ APIS_RESOURCES_BODY_TYPES
41
+ }
42
+
@@ -0,0 +1,30 @@
1
+ exports.ApiResourcesHeadersModel = (sequelize, Sequelize) => {
2
+ const ApiResourcesHeaders = sequelize.define('ApiResourcesHeaders', {
3
+ ApiResourceId: {
4
+ type: Sequelize.UUID,
5
+ allowNull: false,
6
+ references: {
7
+ model: 'ApiResources',
8
+ key: 'id',
9
+ },
10
+ onDelete: 'RESTRICT',
11
+ onUpdate: 'CASCADE',
12
+ },
13
+ value: {
14
+ type: Sequelize.STRING,
15
+ allowNull: false,
16
+ },
17
+ type: {
18
+ type: Sequelize.STRING(40),
19
+ allowNull: false,
20
+ defaultValue: 'string',
21
+ },
22
+ })
23
+
24
+ ApiResourcesHeaders.associate = (models) => {
25
+ ApiResourcesHeaders.belongsTo(models.ApiResources)
26
+ }
27
+
28
+ return ApiResourcesHeaders
29
+ }
30
+
@@ -0,0 +1,29 @@
1
+ exports.ApiResourcesPathParamsModel = (sequelize, Sequelize) => {
2
+ const ApiResourcesPathParams = sequelize.define('ApiResourcesPathParams', {
3
+ ApiResourceId: {
4
+ type: Sequelize.UUID,
5
+ allowNull: false,
6
+ references: {
7
+ model: 'ApiResources',
8
+ key: 'id',
9
+ },
10
+ onDelete: 'RESTRICT',
11
+ onUpdate: 'CASCADE',
12
+ },
13
+ key: {
14
+ type: Sequelize.STRING,
15
+ allowNull: false,
16
+ },
17
+ value: {
18
+ type: Sequelize.STRING,
19
+ allowNull: false,
20
+ },
21
+ })
22
+
23
+ ApiResourcesPathParams.associate = (models) => {
24
+ ApiResourcesPathParams.belongsTo(models.ApiResources)
25
+ }
26
+
27
+ return ApiResourcesPathParams
28
+ }
29
+
@@ -0,0 +1,37 @@
1
+ exports.ApiResourcesQueryStringParamsModel = (sequelize, Sequelize) => {
2
+ const ApiResourcesQueryStringParams = sequelize.define(
3
+ 'ApiResourcesQueryStringParams',
4
+ {
5
+ ApiResourceId: {
6
+ type: Sequelize.UUID,
7
+ allowNull: false,
8
+ references: {
9
+ model: 'ApiResources',
10
+ key: 'id',
11
+ },
12
+ onDelete: 'RESTRICT',
13
+ onUpdate: 'CASCADE',
14
+ },
15
+ key: {
16
+ type: Sequelize.STRING,
17
+ allowNull: false,
18
+ },
19
+ value: {
20
+ type: Sequelize.STRING,
21
+ allowNull: false,
22
+ },
23
+ type: {
24
+ type: Sequelize.STRING(40),
25
+ allowNull: false,
26
+ defaultValue: 'string',
27
+ },
28
+ }
29
+ )
30
+
31
+ ApiResourcesQueryStringParams.associate = (models) => {
32
+ ApiResourcesQueryStringParams.belongsTo(models.ApiResources)
33
+ }
34
+
35
+ return ApiResourcesQueryStringParams
36
+ }
37
+
@@ -0,0 +1,74 @@
1
+ const HTTP_METHODS = [
2
+ 'PUT',
3
+ 'GET',
4
+ 'DELETE',
5
+ 'POST',
6
+ 'COPY',
7
+ 'OPTIONS',
8
+ 'PATCH',
9
+ 'PURGE',
10
+ 'LINK',
11
+ 'UNLINK',
12
+ 'LOCK',
13
+ 'UNLOCK',
14
+ ]
15
+
16
+ const ApiResourcesModel = (sequelize, Sequelize) => {
17
+ const ApiResources = sequelize.define('ApiResources', {
18
+ ApiId: {
19
+ type: Sequelize.UUID,
20
+ allowNull: false,
21
+ references: {
22
+ model: 'Apis',
23
+ key: 'id',
24
+ },
25
+ onDelete: 'RESTRICT',
26
+ onUpdate: 'CASCADE',
27
+ },
28
+ ApiResourcesBodyId: {
29
+ type: Sequelize.UUID,
30
+ allowNull: true,
31
+ references: {
32
+ model: 'ApiResourcesBodies',
33
+ key: 'id',
34
+ },
35
+ onDelete: 'RESTRICT',
36
+ onUpdate: 'CASCADE',
37
+ },
38
+ uri: {
39
+ type: Sequelize.STRING,
40
+ allowNull: false,
41
+ },
42
+ method: {
43
+ type: Sequelize.ENUM({
44
+ values: HTTP_METHODS,
45
+ }),
46
+ allowNull: true,
47
+ },
48
+ name: {
49
+ type: Sequelize.STRING,
50
+ allowNull: true,
51
+ },
52
+ description: {
53
+ type: Sequelize.STRING,
54
+ allowNull: true,
55
+ },
56
+ })
57
+
58
+ ApiResources.associate = (models) => {
59
+ ApiResources.belongsTo(models.Apis)
60
+ ApiResources.belongsTo(models.ApiResourcesBodies)
61
+ ApiResources.hasMany(models.ApiResourcesHeaders)
62
+ ApiResources.hasMany(models.ApiResourcesQueryStringParams)
63
+ ApiResources.hasMany(models.ApiResourcesPathParams)
64
+ ApiResources.hasMany(models.Skill_ApiResources)
65
+ }
66
+
67
+ return ApiResources
68
+ }
69
+
70
+
71
+ module.exports = {
72
+ ApiResourcesModel,
73
+ HTTP_METHODS
74
+ }
package/src/apis.js ADDED
@@ -0,0 +1,68 @@
1
+ const API_INTEGRATION_TYPES = {
2
+ JSON: 'json',
3
+ XML: 'xml',
4
+ }
5
+
6
+ const API_INTEGRATION_TYPE = [
7
+ API_INTEGRATION_TYPES.JSON,
8
+ API_INTEGRATION_TYPES.XML,
9
+ ]
10
+
11
+ const ApisModel = (sequelize, Sequelize) => {
12
+ const Api = sequelize.define('Apis', {
13
+ baseUrl: {
14
+ type: Sequelize.STRING,
15
+ allowNull: false,
16
+ },
17
+ type: {
18
+ type: Sequelize.ENUM({
19
+ values: API_INTEGRATION_TYPE,
20
+ }),
21
+ defaultValue: API_INTEGRATION_TYPES.JSON,
22
+ allowNull: false,
23
+ },
24
+ name: {
25
+ type: Sequelize.STRING,
26
+ allowNull: true,
27
+ },
28
+ description: {
29
+ type: Sequelize.STRING,
30
+ allowNull: true,
31
+ },
32
+ ApiAuthenticationId: {
33
+ type: Sequelize.UUID,
34
+ defaultValue: null,
35
+ allowNull: true,
36
+ references: {
37
+ model: 'ApiAuthentications',
38
+ key: 'id',
39
+ },
40
+ onDelete: 'RESTRICT',
41
+ onUpdate: 'CASCADE',
42
+ },
43
+ EnterpriseId: {
44
+ type: Sequelize.UUID,
45
+ allowNull: true,
46
+ references: {
47
+ model: 'Enterprises',
48
+ key: 'id',
49
+ },
50
+ onDelete: 'RESTRICT',
51
+ onUpdate: 'CASCADE',
52
+ },
53
+ })
54
+
55
+ Api.associate = (models) => {
56
+ Api.hasMany(models.ApiResources)
57
+ Api.belongsTo(models.ApiAuthentications)
58
+ }
59
+
60
+ return Api
61
+ }
62
+
63
+
64
+ module.exports = {
65
+ ApisModel,
66
+ API_INTEGRATION_TYPE,
67
+ API_INTEGRATION_TYPES
68
+ }
@@ -24,7 +24,7 @@ exports.Skill_ApiResourcesModel = (sequelize, Sequelize) => {
24
24
 
25
25
  Skill_ApiResources.associate = models => {
26
26
  Skill_ApiResources.belongsTo(models.Skill)
27
- // Skill_ApiResources.belongsTo(models.ApiResources)
27
+ Skill_ApiResources.belongsTo(models.ApiResources)
28
28
  }
29
29
 
30
30
  return Skill_ApiResources
@@ -27,6 +27,13 @@ exports.SocketClientsModel = (sequelize, DataTypes) => {
27
27
  notEmpty: true,
28
28
  },
29
29
  },
30
+ serverId: {
31
+ type: DataTypes.UUID,
32
+ allowNull: false,
33
+ validate: {
34
+ notEmpty: true
35
+ }
36
+ },
30
37
  protocol: {
31
38
  type: DataTypes.STRING,
32
39
  allowNull: false,