@itleanchatbot/shared-models-js-postgres 2.5.0 → 2.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itleanchatbot/shared-models-js-postgres",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "description": "Shared Models JS Postgres",
5
5
  "main": "index.js",
6
6
  "license": "ISC",
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ up: async (queryInterface, Sequelize) => {
5
+ await queryInterface.createTable('ApiPreRequests', {
6
+ id: {
7
+ allowNull: false,
8
+ defaultValue: Sequelize.literal('uuid_generate_v4()'),
9
+ primaryKey: true,
10
+ type: Sequelize.UUID,
11
+ },
12
+ ApiId: {
13
+ allowNull: true,
14
+ defaultValue: null,
15
+ type: Sequelize.UUID,
16
+ references: {
17
+ model: 'Apis',
18
+ key: 'id',
19
+ },
20
+ onDelete: 'SET NULL',
21
+ onUpdate: 'CASCADE',
22
+ },
23
+ ApiResourceId: {
24
+ allowNull: true,
25
+ defaultValue: null,
26
+ type: Sequelize.UUID,
27
+ references: {
28
+ model: 'ApiResources',
29
+ key: 'id',
30
+ },
31
+ onDelete: 'SET NULL',
32
+ onUpdate: 'CASCADE',
33
+ },
34
+ PreApiResourceId: {
35
+ allowNull: false,
36
+ type: Sequelize.UUID,
37
+ references: {
38
+ model: 'ApiResources',
39
+ key: 'id',
40
+ },
41
+ onDelete: 'SET NULL',
42
+ onUpdate: 'CASCADE',
43
+ },
44
+ result: {
45
+ allowNull: false,
46
+ type: Sequelize.STRING,
47
+ },
48
+ delayForNewRequest: {
49
+ allowNull: false,
50
+ type: Sequelize.STRING,
51
+ },
52
+ createdAt: {
53
+ allowNull: false,
54
+ type: Sequelize.DATE,
55
+ },
56
+ updatedAt: {
57
+ allowNull: false,
58
+ type: Sequelize.DATE,
59
+ },
60
+ })
61
+ },
62
+
63
+ down: async (queryInterface) => {
64
+ await queryInterface.dropTable('ApiPreRequests')
65
+ }
66
+ };
@@ -0,0 +1,56 @@
1
+
2
+ exports.model = (sequelize, Sequelize) => {
3
+ const ApiPreRequests = sequelize.define('ApiPreRequests', {
4
+ ApiId: {
5
+ allowNull: true,
6
+ defaultValue: null,
7
+ type: Sequelize.UUID,
8
+ references: {
9
+ model: 'Apis',
10
+ key: 'id',
11
+ },
12
+ onDelete: 'SET NULL',
13
+ onUpdate: 'CASCADE',
14
+ },
15
+ PreApiResourceId: {
16
+ allowNull: false,
17
+ type: Sequelize.UUID,
18
+ references: {
19
+ model: 'ApiResources',
20
+ key: 'id',
21
+ },
22
+ onDelete: 'SET NULL',
23
+ onUpdate: 'CASCADE',
24
+ },
25
+ ApiResourceId: {
26
+ allowNull: true,
27
+ defaultValue: null,
28
+ type: Sequelize.UUID,
29
+ references: {
30
+ model: 'ApiResources',
31
+ key: 'id',
32
+ },
33
+ onDelete: 'SET NULL',
34
+ onUpdate: 'CASCADE',
35
+ },
36
+ result: {
37
+ allowNull: false,
38
+ type: Sequelize.STRING,
39
+ },
40
+ delayForNewRequest: {
41
+ allowNull: false,
42
+ type: Sequelize.STRING,
43
+ },
44
+ })
45
+
46
+ ApiPreRequests.associate = (models) => {
47
+ ApiPreRequests.belongsTo(models.ApiResources)
48
+ ApiPreRequests.belongsTo(models.ApiResources, {
49
+ as: 'PreApiResource',
50
+ foreignKey: 'PreApiResourceId'
51
+ })
52
+ ApiPreRequests.belongsTo(models.Apis)
53
+ }
54
+
55
+ return ApiPreRequests
56
+ }
@@ -58,6 +58,11 @@ const ApiResourcesModel = (sequelize, Sequelize) => {
58
58
  ApiResources.associate = (models) => {
59
59
  ApiResources.belongsTo(models.Apis)
60
60
  ApiResources.belongsTo(models.ApiResourcesBodies)
61
+ ApiResources.hasMany(models.ApiPreRequests, {
62
+ as: 'PreApiResource',
63
+ foreignKey: 'PreApiResourceId'
64
+ })
65
+ ApiResources.hasMany(models.ApiPreRequests)
61
66
  ApiResources.hasMany(models.ApiResourcesHeaders)
62
67
  ApiResources.hasMany(models.ApiResourcesQueryStringParams)
63
68
  ApiResources.hasMany(models.ApiResourcesPathParams)
@@ -52,6 +52,7 @@ const API_AUTHENTICATIONS_TYPES = {
52
52
 
53
53
  Api.associate = (models) => {
54
54
  Api.hasMany(models.ApiResources)
55
+ Api.hasMany(models.ApiPreRequests)
55
56
  }
56
57
 
57
58
  return Api
@@ -0,0 +1,201 @@
1
+ 'use strict'
2
+
3
+ const apiId = 'f4f8f65e-565d-424e-9235-a17fcf019836'
4
+
5
+ const apiBodyId = '45f353da-db0d-4928-8b59-5b649f9c0349'
6
+
7
+ const apiResourceId = '618a7422-9d86-4ced-a0ca-8968474978d4'
8
+
9
+ const dialogNodeId = '3cc49a93-e327-48b9-b001-b859fcc840fb'
10
+
11
+ const SkillId = 'baee4f99-9966-4adb-a8de-596d5d4dd823'
12
+
13
+ module.exports = {
14
+ up: async (queryInterface, Sequelize) => {
15
+ await queryInterface.bulkInsert('Apis', [
16
+ {
17
+ id: apiId,
18
+ baseUrl: JSON.stringify([
19
+ {
20
+ url: 'https://leanbot.api.dev.itlean.com.br',
21
+ type: 'apiKey',
22
+ auth: {
23
+ key: 'x-api-key',
24
+ value: 'key',
25
+ addTo: 'header',
26
+ },
27
+ environment: 'test',
28
+ },
29
+ ]),
30
+ type: 'json',
31
+ name: 'Api Seeder',
32
+ description: 'Created by seeder to test pre-request',
33
+ EnterpriseId: null,
34
+ createdAt: Sequelize.literal('now()'),
35
+ updatedAt: Sequelize.literal('now()'),
36
+ },
37
+ ])
38
+
39
+ await queryInterface.bulkInsert('ApiResourcesBodies', [
40
+ {
41
+ id: apiBodyId,
42
+ content: JSON.stringify({
43
+ getContext: '$email',
44
+ notInContext: '$notInContext',
45
+ noReplace: 'noReplace',
46
+ }),
47
+ type: 'json',
48
+ createdAt: Sequelize.literal('now()'),
49
+ updatedAt: Sequelize.literal('now()'),
50
+ },
51
+ ])
52
+
53
+ const resourcePathParamToReplaceKey = '$lang'
54
+
55
+ await queryInterface.bulkInsert('ApiResources', [
56
+ {
57
+ id: apiResourceId,
58
+ uri: `/api/framework/${resourcePathParamToReplaceKey}`,
59
+ method: 'POST',
60
+ name: 'Api Resource Seeder',
61
+ description: 'Api Resource Seeder',
62
+ ApiId: apiId,
63
+ ApiResourcesBodyId: apiBodyId,
64
+ createdAt: Sequelize.literal('now()'),
65
+ updatedAt: Sequelize.literal('now()'),
66
+ },
67
+ ])
68
+
69
+ await queryInterface.bulkInsert('ApiResourcesHeaders', [
70
+ {
71
+ id: 'a9f0008a-84bb-4fd4-a2ae-1b76f1093422',
72
+ ApiResourceId: apiResourceId,
73
+ value: 'en',
74
+ type: 'Accept-Language',
75
+ createdAt: Sequelize.literal('now()'),
76
+ updatedAt: Sequelize.literal('now()'),
77
+ },
78
+ ])
79
+
80
+ await queryInterface.bulkInsert('ApiResourcesPathParams', [
81
+ {
82
+ id: 'c264f31d-f8fc-4a1a-ad21-f29c66e24ab4',
83
+ ApiResourceId: apiResourceId,
84
+ key: resourcePathParamToReplaceKey,
85
+ value: 'en',
86
+ createdAt: Sequelize.literal('now()'),
87
+ updatedAt: Sequelize.literal('now()'),
88
+ },
89
+ ])
90
+
91
+ await queryInterface.bulkInsert('ApiResourcesQueryStringParams', [
92
+ {
93
+ id: '0ea48ff6-914b-46dc-9c61-5179fcddbc7c',
94
+ ApiResourceId: apiResourceId,
95
+ key: 'lang',
96
+ type: 'string',
97
+ value: 'en',
98
+ createdAt: Sequelize.literal('now()'),
99
+ updatedAt: Sequelize.literal('now()'),
100
+ },
101
+ ])
102
+
103
+ await queryInterface.bulkInsert('ApiPreRequests', [
104
+ {
105
+ id: '2ab884ba-53f0-47d4-b4cb-376e5254ede2',
106
+ ApiResourceId: apiResourceId,
107
+ result: 'pre-result',
108
+ delayForNewRequest: '600000',
109
+ PreApiResourceId: '2ea2a347-bfdf-4209-b51f-7cacfa511299',
110
+ createdAt: Sequelize.literal('now()'),
111
+ updatedAt: Sequelize.literal('now()'),
112
+ }
113
+ ])
114
+
115
+ const ibmIntelligenceId = await queryInterface.rawSelect(
116
+ 'Intelligences',
117
+ {
118
+ where: {
119
+ providerType: 'ibm',
120
+ },
121
+ },
122
+ ['id']
123
+ )
124
+
125
+ const ibmProviderId = 'f5cc3829-e441-452f-9bea-70581bde9eff'
126
+
127
+ await queryInterface.bulkInsert('Skills', [
128
+ {
129
+ id: SkillId,
130
+ IntelligenceId: ibmIntelligenceId,
131
+ AwsProviderId: null,
132
+ ItleanProviderId: null,
133
+ IbmProviderId: ibmProviderId,
134
+ name: 'Skill Nlp Seed',
135
+ description: 'skill created by seeders',
136
+ lang: 'pt-br',
137
+ externalIbmId: '1c6e2489-6675-4c08-aa89-fdac4bc50de3',
138
+ createdAt: Sequelize.literal('now()'),
139
+ updatedAt: Sequelize.literal('now()'),
140
+ },
141
+ ])
142
+
143
+ await queryInterface.bulkInsert(
144
+ 'DialogNodes',
145
+ [
146
+ {
147
+ id: dialogNodeId,
148
+ name: 'api_pre_request',
149
+ SkillId,
150
+ condition: 'true',
151
+ contexts: '[]',
152
+ step: 1,
153
+ replayWait: true,
154
+ type: 'node',
155
+ isMultipleResponse: false,
156
+ JumpToDialogNodeId: null,
157
+ JumpToSkillId: null,
158
+ DialogNodeFolderId: null,
159
+ createdAt: Sequelize.literal('now()'),
160
+ updatedAt: Sequelize.literal('now()'),
161
+ },
162
+ ],
163
+ {}
164
+ )
165
+
166
+ await queryInterface.bulkInsert('DialogNodes_ApiResources', [
167
+ {
168
+ DialogNodeId: dialogNodeId,
169
+ ApiResourceId: apiResourceId,
170
+ response: 'api',
171
+ environment: 'auth',
172
+ createdAt: new Date(),
173
+ updatedAt: new Date(),
174
+ },
175
+ ])
176
+ },
177
+
178
+ down: async (queryInterface) => {
179
+ await queryInterface.bulkDelete('ApiResourcesQueryStringParams', [
180
+ { ApiResourceId: apiResourceId },
181
+ ])
182
+ await queryInterface.bulkDelete('ApiResourcesPathParams', [
183
+ { ApiResourceId: apiResourceId },
184
+ ])
185
+ await queryInterface.bulkDelete('ApiPreRequests', [
186
+ { ApiResourceId: apiResourceId },
187
+ ])
188
+ await queryInterface.bulkDelete('ApiResourcesHeaders', [
189
+ { ApiResourceId: apiResourceId },
190
+ ])
191
+ await queryInterface.bulkDelete('DialogNodes_ApiResources', [
192
+ { ApiResourceId: apiResourceId },
193
+ ])
194
+ await queryInterface.bulkDelete('ApiResources', [{ id: apiResourceId }])
195
+ await queryInterface.bulkDelete('ApiResourcesBodies', [{ id: apiBodyId }])
196
+ await queryInterface.bulkDelete('Apis', [{ id: apiId }])
197
+
198
+ await queryInterface.bulkDelete('Skills', [{ id: SkillId }])
199
+ await queryInterface.bulkDelete('DialogNodes', [{ id: dialogNodeId }])
200
+ },
201
+ }