agrs-sequelize-sdk 1.4.16 → 1.4.18

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 (84) hide show
  1. package/migrations/2026-05-17-PIXELS-FOLLOWUP.md +85 -0
  2. package/migrations/2026-05-17-add-platform-to-ad.js +19 -0
  3. package/migrations/2026-05-17-add-platform-to-adaccount.js +19 -0
  4. package/migrations/2026-05-17-add-platform-to-adperformance.js +19 -0
  5. package/migrations/2026-05-17-add-platform-to-adset.js +19 -0
  6. package/migrations/2026-05-17-add-platform-to-adsetperformance.js +19 -0
  7. package/migrations/2026-05-17-add-platform-to-aiarticleretryqueue.js +19 -0
  8. package/migrations/2026-05-17-add-platform-to-aicampaignqueue.js +19 -0
  9. package/migrations/2026-05-17-add-platform-to-article.js +19 -0
  10. package/migrations/2026-05-17-add-platform-to-campaign.js +19 -0
  11. package/migrations/2026-05-17-add-platform-to-codefuelcampaign.js +19 -0
  12. package/migrations/2026-05-17-add-platform-to-dynamicfeed.js +19 -0
  13. package/migrations/2026-05-17-add-platform-to-facebookretryqueue.js +19 -0
  14. package/migrations/2026-05-17-add-platform-to-pages.js +19 -0
  15. package/migrations/2026-05-17-add-platform-to-presets.js +19 -0
  16. package/migrations/RUN_ME_MANUALLY_2026-05-17.sql +99 -0
  17. package/migrations/add-requested-from-dashboard-to-articles.js +17 -17
  18. package/migrations/change-adset-name-to-text.js +79 -79
  19. package/models/AICampaignQueue.js +143 -136
  20. package/models/AIGenerationLog.js +85 -85
  21. package/models/AIGenerationRequest.js +212 -212
  22. package/models/Ad.js +6 -0
  23. package/models/AdAccount.js +6 -0
  24. package/models/AdAccountValues.js +25 -25
  25. package/models/AdHistory.js +30 -30
  26. package/models/AdPerformance.js +100 -94
  27. package/models/AdSet.js +295 -289
  28. package/models/AdSetHistory.js +30 -30
  29. package/models/AdsetPerformance.js +132 -126
  30. package/models/AiArticleRetryQueue.js +157 -150
  31. package/models/AiCreationRetryQueue.js +127 -127
  32. package/models/Article.js +212 -206
  33. package/models/AutomationRule.js +173 -173
  34. package/models/BannerTemplate.js +129 -129
  35. package/models/Buyers.js +25 -25
  36. package/models/Campaign.js +163 -157
  37. package/models/CampaignActionHistory.js +86 -86
  38. package/models/CampaignCreationLog.js +309 -309
  39. package/models/CampaignCreationLogV2.js +314 -314
  40. package/models/CampaignHistory.js +33 -33
  41. package/models/Channel.js +55 -55
  42. package/models/CodefuelCampaign.js +6 -0
  43. package/models/Domain.js +39 -47
  44. package/models/DynamicFeed.js +218 -212
  45. package/models/ExplorAdsChannel.js +61 -61
  46. package/models/FacebookRetryQueue.js +163 -156
  47. package/models/Feed.js +33 -33
  48. package/models/FeedArticleConfiguration.js +80 -80
  49. package/models/FrontStoryChannel.js +59 -59
  50. package/models/FrontStoryChannelV2.js +60 -60
  51. package/models/GenericFlowRequest.js +114 -114
  52. package/models/MidoWebChannel.js +47 -47
  53. package/models/MineChannel.js +42 -42
  54. package/models/Pages.js +105 -99
  55. package/models/PipelineExecution.js +59 -59
  56. package/models/PolicyDogsCreativeCache.js +50 -50
  57. package/models/PolicyDogsImageCache.js +30 -30
  58. package/models/Presets.js +40 -34
  59. package/models/RSOCFeedCampaign.js +375 -375
  60. package/models/RsocKeywordPerformance.js +110 -110
  61. package/models/RuleAction.js +90 -90
  62. package/models/RuleCondition.js +137 -137
  63. package/models/RuleExecution.js +107 -107
  64. package/models/RulesValues.js +56 -56
  65. package/models/SupportedLocale.js +23 -23
  66. package/models/SyncHistory.js +249 -249
  67. package/models/TTQChannel.js +42 -42
  68. package/models/TemplateMetadata.js +260 -260
  69. package/models/Tier2_AdAccounts.js +110 -110
  70. package/models/Tier2_Assets.js +70 -70
  71. package/models/Tier2_BusinessManagers.js +105 -105
  72. package/models/Tier2_CreditLines.js +99 -99
  73. package/models/Tier2_Pages.js +91 -91
  74. package/models/Tier2_Pixels.js +82 -82
  75. package/models/Tier2_Tokens.js +64 -64
  76. package/models/Tier2_UserAdAccounts.js +83 -83
  77. package/models/TokenRotationState.js +121 -121
  78. package/models/TonicRSOCKeywordPerformance.js +122 -122
  79. package/models/Users.js +148 -148
  80. package/models/Vertical.js +25 -25
  81. package/models/newFiles.js +137 -137
  82. package/package.json +19 -21
  83. package/run.sh +214 -214
  84. 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
+ };