agrs-sequelize-sdk 1.4.11 → 1.4.13

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 (65) hide show
  1. package/migrations/add-requested-from-dashboard-to-articles.js +17 -17
  2. package/migrations/change-adset-name-to-text.js +79 -79
  3. package/models/AICampaignQueue.js +136 -136
  4. package/models/AIGenerationLog.js +85 -85
  5. package/models/AIGenerationRequest.js +212 -212
  6. package/models/AdAccountValues.js +25 -25
  7. package/models/AdHistory.js +30 -30
  8. package/models/AdPerformance.js +94 -94
  9. package/models/AdSet.js +289 -289
  10. package/models/AdSetHistory.js +30 -30
  11. package/models/AdsetPerformance.js +126 -126
  12. package/models/AiArticleRetryQueue.js +150 -150
  13. package/models/AiCreationRetryQueue.js +127 -127
  14. package/models/Article.js +206 -206
  15. package/models/AutomationRule.js +173 -173
  16. package/models/BannerTemplate.js +129 -129
  17. package/models/Buyers.js +25 -25
  18. package/models/Campaign.js +157 -157
  19. package/models/CampaignActionHistory.js +86 -86
  20. package/models/CampaignCreationLog.js +309 -309
  21. package/models/CampaignCreationLogV2.js +314 -314
  22. package/models/CampaignHistory.js +33 -33
  23. package/models/Channel.js +55 -55
  24. package/models/Domain.js +43 -43
  25. package/models/DynamicFeed.js +212 -212
  26. package/models/ExplorAdsChannel.js +61 -61
  27. package/models/FacebookRetryQueue.js +156 -156
  28. package/models/Feed.js +33 -33
  29. package/models/FeedArticleConfiguration.js +80 -80
  30. package/models/FrontStoryChannel.js +59 -59
  31. package/models/FrontStoryChannelV2.js +60 -60
  32. package/models/GenericFlowRequest.js +114 -114
  33. package/models/MidoWebChannel.js +47 -47
  34. package/models/MineChannel.js +42 -42
  35. package/models/Pages.js +99 -99
  36. package/models/PipelineExecution.js +59 -59
  37. package/models/PolicyDogsCreativeCache.js +50 -50
  38. package/models/PolicyDogsImageCache.js +30 -30
  39. package/models/Presets.js +34 -34
  40. package/models/RSOCFeedCampaign.js +375 -375
  41. package/models/RsocKeywordPerformance.js +110 -110
  42. package/models/RuleAction.js +90 -90
  43. package/models/RuleCondition.js +137 -137
  44. package/models/RuleExecution.js +107 -107
  45. package/models/RulesValues.js +56 -56
  46. package/models/SupportedLocale.js +23 -23
  47. package/models/SyncHistory.js +249 -249
  48. package/models/TTQChannel.js +42 -42
  49. package/models/TemplateMetadata.js +260 -260
  50. package/models/Tier2_AdAccounts.js +110 -110
  51. package/models/Tier2_Assets.js +70 -70
  52. package/models/Tier2_BusinessManagers.js +105 -105
  53. package/models/Tier2_CreditLines.js +99 -99
  54. package/models/Tier2_Pages.js +91 -91
  55. package/models/Tier2_Pixels.js +82 -82
  56. package/models/Tier2_Tokens.js +64 -64
  57. package/models/Tier2_UserAdAccounts.js +83 -83
  58. package/models/TokenRotationState.js +121 -121
  59. package/models/TonicRSOCKeywordPerformance.js +122 -122
  60. package/models/Users.js +148 -148
  61. package/models/Vertical.js +25 -25
  62. package/models/newFiles.js +137 -137
  63. package/package.json +19 -21
  64. package/run.sh +214 -214
  65. package/services/sequelizeService.js +110 -110
@@ -1,250 +1,250 @@
1
- // models/SyncHistory.js
2
- module.exports = (sequelize, DataTypes) => {
3
- const SyncHistory = sequelize.define(
4
- "SyncHistory",
5
- {
6
- id: {
7
- type: DataTypes.INTEGER,
8
- primaryKey: true,
9
- autoIncrement: true,
10
- },
11
- syncId: {
12
- type: DataTypes.STRING,
13
- allowNull: false,
14
- unique: true,
15
- comment: "Unique identifier for the sync operation"
16
- },
17
- syncType: {
18
- type: DataTypes.ENUM('manual', 'quick_sync', 'group_sync', 'preset_sync', 'scheduled'),
19
- allowNull: false,
20
- defaultValue: 'manual',
21
- comment: "Type of sync operation performed"
22
- },
23
- initiatedBy: {
24
- type: DataTypes.STRING,
25
- allowNull: true,
26
- comment: "User who initiated the sync (username or user ID)"
27
- },
28
- startTime: {
29
- type: DataTypes.DATE,
30
- allowNull: false,
31
- comment: "When the sync operation started"
32
- },
33
- endTime: {
34
- type: DataTypes.DATE,
35
- allowNull: true,
36
- comment: "When the sync operation completed"
37
- },
38
- duration: {
39
- type: DataTypes.INTEGER,
40
- allowNull: true,
41
- comment: "Duration in milliseconds"
42
- },
43
- status: {
44
- type: DataTypes.ENUM('running', 'completed', 'failed', 'cancelled'),
45
- allowNull: false,
46
- defaultValue: 'running',
47
- comment: "Current status of the sync operation"
48
- },
49
- success: {
50
- type: DataTypes.BOOLEAN,
51
- allowNull: true,
52
- comment: "Whether the sync completed successfully"
53
- },
54
- totalTables: {
55
- type: DataTypes.INTEGER,
56
- allowNull: false,
57
- defaultValue: 0,
58
- comment: "Total number of tables in the sync"
59
- },
60
- successfulTables: {
61
- type: DataTypes.INTEGER,
62
- allowNull: false,
63
- defaultValue: 0,
64
- comment: "Number of tables synced successfully"
65
- },
66
- failedTables: {
67
- type: DataTypes.INTEGER,
68
- allowNull: false,
69
- defaultValue: 0,
70
- comment: "Number of tables that failed to sync"
71
- },
72
- totalRecords: {
73
- type: DataTypes.INTEGER,
74
- allowNull: false,
75
- defaultValue: 0,
76
- comment: "Total number of records synced"
77
- },
78
- tablesIncluded: {
79
- type: DataTypes.ARRAY(DataTypes.STRING),
80
- allowNull: false,
81
- defaultValue: [],
82
- comment: "List of tables included in this sync"
83
- },
84
- syncOptions: {
85
- type: DataTypes.JSONB,
86
- allowNull: true,
87
- comment: "Sync options used (truncateFirst, batchSize, etc.)"
88
- },
89
- errorCount: {
90
- type: DataTypes.INTEGER,
91
- allowNull: false,
92
- defaultValue: 0,
93
- comment: "Number of errors encountered"
94
- },
95
- errorSummary: {
96
- type: DataTypes.TEXT,
97
- allowNull: true,
98
- comment: "Brief summary of errors encountered"
99
- },
100
- detailedResults: {
101
- type: DataTypes.JSONB,
102
- allowNull: true,
103
- comment: "Detailed results for each table (success/failure, record counts, errors)"
104
- },
105
- safetyChecks: {
106
- type: DataTypes.JSONB,
107
- allowNull: true,
108
- comment: "Safety check results (hosts, direction, etc.)"
109
- },
110
- sourceHost: {
111
- type: DataTypes.STRING,
112
- allowNull: true,
113
- comment: "Production database host"
114
- },
115
- targetHost: {
116
- type: DataTypes.STRING,
117
- allowNull: true,
118
- comment: "Staging database host"
119
- },
120
- environment: {
121
- type: DataTypes.STRING,
122
- allowNull: true,
123
- comment: "Environment where sync was executed (development, staging, production)"
124
- },
125
- groupsOrPreset: {
126
- type: DataTypes.STRING,
127
- allowNull: true,
128
- comment: "If this was a group/preset sync, which one was used"
129
- }
130
- },
131
- {
132
- tableName: "SyncHistory",
133
- timestamps: true, // Adds createdAt and updatedAt
134
- indexes: [
135
- {
136
- fields: ["syncId"],
137
- unique: true
138
- },
139
- {
140
- fields: ["startTime"],
141
- name: "idx_sync_history_start_time"
142
- },
143
- {
144
- fields: ["status"],
145
- name: "idx_sync_history_status"
146
- },
147
- {
148
- fields: ["success"],
149
- name: "idx_sync_history_success"
150
- },
151
- {
152
- fields: ["syncType"],
153
- name: "idx_sync_history_type"
154
- },
155
- {
156
- fields: ["initiatedBy"],
157
- name: "idx_sync_history_user"
158
- },
159
- {
160
- fields: ["createdAt"],
161
- name: "idx_sync_history_created"
162
- }
163
- ]
164
- }
165
- );
166
-
167
- // Add model methods
168
- SyncHistory.prototype.getDurationInSeconds = function() {
169
- return this.duration ? (this.duration / 1000).toFixed(1) : null;
170
- };
171
-
172
- SyncHistory.prototype.getSuccessRate = function() {
173
- if (this.totalTables === 0) return 0;
174
- return ((this.successfulTables / this.totalTables) * 100).toFixed(1);
175
- };
176
-
177
- SyncHistory.prototype.isRunning = function() {
178
- return this.status === 'running';
179
- };
180
-
181
- SyncHistory.prototype.hasErrors = function() {
182
- return this.errorCount > 0;
183
- };
184
-
185
- // Static methods for common queries
186
- SyncHistory.getRecentHistory = async function(limit = 10) {
187
- return await this.findAll({
188
- order: [['startTime', 'DESC']],
189
- limit: limit
190
- });
191
- };
192
-
193
- SyncHistory.getRunningsyncs = async function() {
194
- return await this.findAll({
195
- where: { status: 'running' },
196
- order: [['startTime', 'DESC']]
197
- });
198
- };
199
-
200
- SyncHistory.getSuccessfulSyncs = async function(limit = 10) {
201
- return await this.findAll({
202
- where: { success: true },
203
- order: [['startTime', 'DESC']],
204
- limit: limit
205
- });
206
- };
207
-
208
- SyncHistory.getFailedSyncs = async function(limit = 10) {
209
- return await this.findAll({
210
- where: { success: false },
211
- order: [['startTime', 'DESC']],
212
- limit: limit
213
- });
214
- };
215
-
216
- SyncHistory.getSyncStats = async function() {
217
- const total = await this.count();
218
- const successful = await this.count({ where: { success: true } });
219
- const failed = await this.count({ where: { success: false } });
220
- const running = await this.count({ where: { status: 'running' } });
221
-
222
- const avgDuration = await this.findOne({
223
- attributes: [
224
- [sequelize.fn('AVG', sequelize.col('duration')), 'avgDuration']
225
- ],
226
- where: { success: true },
227
- raw: true
228
- });
229
-
230
- const totalRecords = await this.findOne({
231
- attributes: [
232
- [sequelize.fn('SUM', sequelize.col('totalRecords')), 'totalRecords']
233
- ],
234
- where: { success: true },
235
- raw: true
236
- });
237
-
238
- return {
239
- totalSyncs: total,
240
- successfulSyncs: successful,
241
- failedSyncs: failed,
242
- runningSyncs: running,
243
- successRate: total > 0 ? ((successful / total) * 100).toFixed(1) : 0,
244
- averageDuration: avgDuration?.avgDuration ? Math.round(avgDuration.avgDuration) : null,
245
- totalRecordsSynced: totalRecords?.totalRecords || 0
246
- };
247
- };
248
-
249
- return SyncHistory;
1
+ // models/SyncHistory.js
2
+ module.exports = (sequelize, DataTypes) => {
3
+ const SyncHistory = sequelize.define(
4
+ "SyncHistory",
5
+ {
6
+ id: {
7
+ type: DataTypes.INTEGER,
8
+ primaryKey: true,
9
+ autoIncrement: true,
10
+ },
11
+ syncId: {
12
+ type: DataTypes.STRING,
13
+ allowNull: false,
14
+ unique: true,
15
+ comment: "Unique identifier for the sync operation"
16
+ },
17
+ syncType: {
18
+ type: DataTypes.ENUM('manual', 'quick_sync', 'group_sync', 'preset_sync', 'scheduled'),
19
+ allowNull: false,
20
+ defaultValue: 'manual',
21
+ comment: "Type of sync operation performed"
22
+ },
23
+ initiatedBy: {
24
+ type: DataTypes.STRING,
25
+ allowNull: true,
26
+ comment: "User who initiated the sync (username or user ID)"
27
+ },
28
+ startTime: {
29
+ type: DataTypes.DATE,
30
+ allowNull: false,
31
+ comment: "When the sync operation started"
32
+ },
33
+ endTime: {
34
+ type: DataTypes.DATE,
35
+ allowNull: true,
36
+ comment: "When the sync operation completed"
37
+ },
38
+ duration: {
39
+ type: DataTypes.INTEGER,
40
+ allowNull: true,
41
+ comment: "Duration in milliseconds"
42
+ },
43
+ status: {
44
+ type: DataTypes.ENUM('running', 'completed', 'failed', 'cancelled'),
45
+ allowNull: false,
46
+ defaultValue: 'running',
47
+ comment: "Current status of the sync operation"
48
+ },
49
+ success: {
50
+ type: DataTypes.BOOLEAN,
51
+ allowNull: true,
52
+ comment: "Whether the sync completed successfully"
53
+ },
54
+ totalTables: {
55
+ type: DataTypes.INTEGER,
56
+ allowNull: false,
57
+ defaultValue: 0,
58
+ comment: "Total number of tables in the sync"
59
+ },
60
+ successfulTables: {
61
+ type: DataTypes.INTEGER,
62
+ allowNull: false,
63
+ defaultValue: 0,
64
+ comment: "Number of tables synced successfully"
65
+ },
66
+ failedTables: {
67
+ type: DataTypes.INTEGER,
68
+ allowNull: false,
69
+ defaultValue: 0,
70
+ comment: "Number of tables that failed to sync"
71
+ },
72
+ totalRecords: {
73
+ type: DataTypes.INTEGER,
74
+ allowNull: false,
75
+ defaultValue: 0,
76
+ comment: "Total number of records synced"
77
+ },
78
+ tablesIncluded: {
79
+ type: DataTypes.ARRAY(DataTypes.STRING),
80
+ allowNull: false,
81
+ defaultValue: [],
82
+ comment: "List of tables included in this sync"
83
+ },
84
+ syncOptions: {
85
+ type: DataTypes.JSONB,
86
+ allowNull: true,
87
+ comment: "Sync options used (truncateFirst, batchSize, etc.)"
88
+ },
89
+ errorCount: {
90
+ type: DataTypes.INTEGER,
91
+ allowNull: false,
92
+ defaultValue: 0,
93
+ comment: "Number of errors encountered"
94
+ },
95
+ errorSummary: {
96
+ type: DataTypes.TEXT,
97
+ allowNull: true,
98
+ comment: "Brief summary of errors encountered"
99
+ },
100
+ detailedResults: {
101
+ type: DataTypes.JSONB,
102
+ allowNull: true,
103
+ comment: "Detailed results for each table (success/failure, record counts, errors)"
104
+ },
105
+ safetyChecks: {
106
+ type: DataTypes.JSONB,
107
+ allowNull: true,
108
+ comment: "Safety check results (hosts, direction, etc.)"
109
+ },
110
+ sourceHost: {
111
+ type: DataTypes.STRING,
112
+ allowNull: true,
113
+ comment: "Production database host"
114
+ },
115
+ targetHost: {
116
+ type: DataTypes.STRING,
117
+ allowNull: true,
118
+ comment: "Staging database host"
119
+ },
120
+ environment: {
121
+ type: DataTypes.STRING,
122
+ allowNull: true,
123
+ comment: "Environment where sync was executed (development, staging, production)"
124
+ },
125
+ groupsOrPreset: {
126
+ type: DataTypes.STRING,
127
+ allowNull: true,
128
+ comment: "If this was a group/preset sync, which one was used"
129
+ }
130
+ },
131
+ {
132
+ tableName: "SyncHistory",
133
+ timestamps: true, // Adds createdAt and updatedAt
134
+ indexes: [
135
+ {
136
+ fields: ["syncId"],
137
+ unique: true
138
+ },
139
+ {
140
+ fields: ["startTime"],
141
+ name: "idx_sync_history_start_time"
142
+ },
143
+ {
144
+ fields: ["status"],
145
+ name: "idx_sync_history_status"
146
+ },
147
+ {
148
+ fields: ["success"],
149
+ name: "idx_sync_history_success"
150
+ },
151
+ {
152
+ fields: ["syncType"],
153
+ name: "idx_sync_history_type"
154
+ },
155
+ {
156
+ fields: ["initiatedBy"],
157
+ name: "idx_sync_history_user"
158
+ },
159
+ {
160
+ fields: ["createdAt"],
161
+ name: "idx_sync_history_created"
162
+ }
163
+ ]
164
+ }
165
+ );
166
+
167
+ // Add model methods
168
+ SyncHistory.prototype.getDurationInSeconds = function() {
169
+ return this.duration ? (this.duration / 1000).toFixed(1) : null;
170
+ };
171
+
172
+ SyncHistory.prototype.getSuccessRate = function() {
173
+ if (this.totalTables === 0) return 0;
174
+ return ((this.successfulTables / this.totalTables) * 100).toFixed(1);
175
+ };
176
+
177
+ SyncHistory.prototype.isRunning = function() {
178
+ return this.status === 'running';
179
+ };
180
+
181
+ SyncHistory.prototype.hasErrors = function() {
182
+ return this.errorCount > 0;
183
+ };
184
+
185
+ // Static methods for common queries
186
+ SyncHistory.getRecentHistory = async function(limit = 10) {
187
+ return await this.findAll({
188
+ order: [['startTime', 'DESC']],
189
+ limit: limit
190
+ });
191
+ };
192
+
193
+ SyncHistory.getRunningsyncs = async function() {
194
+ return await this.findAll({
195
+ where: { status: 'running' },
196
+ order: [['startTime', 'DESC']]
197
+ });
198
+ };
199
+
200
+ SyncHistory.getSuccessfulSyncs = async function(limit = 10) {
201
+ return await this.findAll({
202
+ where: { success: true },
203
+ order: [['startTime', 'DESC']],
204
+ limit: limit
205
+ });
206
+ };
207
+
208
+ SyncHistory.getFailedSyncs = async function(limit = 10) {
209
+ return await this.findAll({
210
+ where: { success: false },
211
+ order: [['startTime', 'DESC']],
212
+ limit: limit
213
+ });
214
+ };
215
+
216
+ SyncHistory.getSyncStats = async function() {
217
+ const total = await this.count();
218
+ const successful = await this.count({ where: { success: true } });
219
+ const failed = await this.count({ where: { success: false } });
220
+ const running = await this.count({ where: { status: 'running' } });
221
+
222
+ const avgDuration = await this.findOne({
223
+ attributes: [
224
+ [sequelize.fn('AVG', sequelize.col('duration')), 'avgDuration']
225
+ ],
226
+ where: { success: true },
227
+ raw: true
228
+ });
229
+
230
+ const totalRecords = await this.findOne({
231
+ attributes: [
232
+ [sequelize.fn('SUM', sequelize.col('totalRecords')), 'totalRecords']
233
+ ],
234
+ where: { success: true },
235
+ raw: true
236
+ });
237
+
238
+ return {
239
+ totalSyncs: total,
240
+ successfulSyncs: successful,
241
+ failedSyncs: failed,
242
+ runningSyncs: running,
243
+ successRate: total > 0 ? ((successful / total) * 100).toFixed(1) : 0,
244
+ averageDuration: avgDuration?.avgDuration ? Math.round(avgDuration.avgDuration) : null,
245
+ totalRecordsSynced: totalRecords?.totalRecords || 0
246
+ };
247
+ };
248
+
249
+ return SyncHistory;
250
250
  };
@@ -1,42 +1,42 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const TTQChannel = sequelize.define(
3
- "TTQChannel",
4
- {
5
- channelId: {
6
- type: DataTypes.STRING,
7
- allowNull: false,
8
- unique: true,
9
- },
10
- status: {
11
- type: DataTypes.STRING,
12
- allowNull: false,
13
- defaultValue: "free",
14
- validate: {
15
- isIn: [["free", "used", "archived"]],
16
- },
17
- },
18
- connectedCampaigns: {
19
- type: DataTypes.JSONB,
20
- allowNull: false,
21
- defaultValue: [],
22
- },
23
- },
24
- {
25
- tableName: "ttq_rsoc_channels",
26
- timestamps: true,
27
- }
28
- );
29
-
30
- TTQChannel.associate = (models) => {
31
- if (models.RSOCFeedCampaign) {
32
- TTQChannel.hasMany(models.RSOCFeedCampaign, {
33
- foreignKey: "channelId",
34
- sourceKey: "channelId",
35
- as: "RSOCFeedCampaigns",
36
- constraints: false,
37
- });
38
- }
39
- };
40
-
41
- return TTQChannel;
42
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const TTQChannel = sequelize.define(
3
+ "TTQChannel",
4
+ {
5
+ channelId: {
6
+ type: DataTypes.STRING,
7
+ allowNull: false,
8
+ unique: true,
9
+ },
10
+ status: {
11
+ type: DataTypes.STRING,
12
+ allowNull: false,
13
+ defaultValue: "free",
14
+ validate: {
15
+ isIn: [["free", "used", "archived"]],
16
+ },
17
+ },
18
+ connectedCampaigns: {
19
+ type: DataTypes.JSONB,
20
+ allowNull: false,
21
+ defaultValue: [],
22
+ },
23
+ },
24
+ {
25
+ tableName: "ttq_rsoc_channels",
26
+ timestamps: true,
27
+ }
28
+ );
29
+
30
+ TTQChannel.associate = (models) => {
31
+ if (models.RSOCFeedCampaign) {
32
+ TTQChannel.hasMany(models.RSOCFeedCampaign, {
33
+ foreignKey: "channelId",
34
+ sourceKey: "channelId",
35
+ as: "RSOCFeedCampaigns",
36
+ constraints: false,
37
+ });
38
+ }
39
+ };
40
+
41
+ return TTQChannel;
42
+ };