agrs-sequelize-sdk 1.4.17 → 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 -39
  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,127 +1,127 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const AiCreationRetryQueue = sequelize.define(
3
- "AiCreationRetryQueue",
4
- {
5
- id: {
6
- type: DataTypes.INTEGER,
7
- primaryKey: true,
8
- autoIncrement: true,
9
- },
10
- agrs_cid: {
11
- type: DataTypes.STRING(255),
12
- allowNull: false,
13
- field: "agrs_cid",
14
- comment: "AGRS Campaign ID (links to the campaign combo)",
15
- },
16
- process_id: {
17
- type: DataTypes.STRING(255),
18
- allowNull: true,
19
- field: "process_id",
20
- comment: "Root process_id from createAICampaign",
21
- },
22
- controller_process_id: {
23
- type: DataTypes.UUID,
24
- allowNull: true,
25
- field: "controller_process_id",
26
- comment: "Per-combination process_id (for CampaignCreationLog)",
27
- },
28
- feed_provider: {
29
- type: DataTypes.STRING(100),
30
- allowNull: false,
31
- field: "feed_provider",
32
- comment: "Normalized feed name: Mine - RSOC, Predicto - RSOC, etc.",
33
- },
34
- failed_step: {
35
- type: DataTypes.STRING(50),
36
- allowNull: false,
37
- field: "failed_step",
38
- comment:
39
- "Step that failed: keywords, texts, banners, fb_creation, rabbitmq_publish",
40
- },
41
- original_payload: {
42
- type: DataTypes.JSONB,
43
- allowNull: false,
44
- field: "original_payload",
45
- comment: "Full combination payload for retry",
46
- },
47
- generated_assets: {
48
- type: DataTypes.JSONB,
49
- allowNull: true,
50
- defaultValue: {},
51
- field: "generated_assets",
52
- comment:
53
- "Assets generated before failure: { keywords, headlines, primaryTexts, bannerFiles }",
54
- },
55
- campaign_context: {
56
- type: DataTypes.JSONB,
57
- allowNull: true,
58
- defaultValue: {},
59
- field: "campaign_context",
60
- comment:
61
- "Additional context needed to resume campaign flow after retry",
62
- },
63
- status: {
64
- type: DataTypes.STRING(50),
65
- allowNull: false,
66
- defaultValue: "pending",
67
- validate: {
68
- isIn: [["pending", "processing", "completed", "failed", "abandoned"]],
69
- },
70
- },
71
- retry_count: {
72
- type: DataTypes.INTEGER,
73
- allowNull: false,
74
- defaultValue: 0,
75
- field: "retry_count",
76
- },
77
- max_retries: {
78
- type: DataTypes.INTEGER,
79
- allowNull: false,
80
- defaultValue: 5,
81
- field: "max_retries",
82
- },
83
- next_retry_at: {
84
- type: DataTypes.DATE,
85
- allowNull: false,
86
- field: "next_retry_at",
87
- comment: "When the next retry should be attempted",
88
- },
89
- last_error: {
90
- type: DataTypes.TEXT,
91
- allowNull: true,
92
- field: "last_error",
93
- },
94
- last_attempt_at: {
95
- type: DataTypes.DATE,
96
- allowNull: true,
97
- field: "last_attempt_at",
98
- },
99
- completed_at: {
100
- type: DataTypes.DATE,
101
- allowNull: true,
102
- field: "completed_at",
103
- },
104
- },
105
- {
106
- tableName: "ai_creation_retry_queue",
107
- timestamps: true,
108
- underscored: true,
109
- indexes: [
110
- {
111
- fields: ["status", "next_retry_at"],
112
- name: "idx_creation_retry_status_next",
113
- },
114
- {
115
- fields: ["agrs_cid"],
116
- name: "idx_creation_retry_agrs_cid",
117
- },
118
- ],
119
- }
120
- );
121
-
122
- AiCreationRetryQueue.associate = (models) => {
123
- // No associations needed for now
124
- };
125
-
126
- return AiCreationRetryQueue;
127
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const AiCreationRetryQueue = sequelize.define(
3
+ "AiCreationRetryQueue",
4
+ {
5
+ id: {
6
+ type: DataTypes.INTEGER,
7
+ primaryKey: true,
8
+ autoIncrement: true,
9
+ },
10
+ agrs_cid: {
11
+ type: DataTypes.STRING(255),
12
+ allowNull: false,
13
+ field: "agrs_cid",
14
+ comment: "AGRS Campaign ID (links to the campaign combo)",
15
+ },
16
+ process_id: {
17
+ type: DataTypes.STRING(255),
18
+ allowNull: true,
19
+ field: "process_id",
20
+ comment: "Root process_id from createAICampaign",
21
+ },
22
+ controller_process_id: {
23
+ type: DataTypes.UUID,
24
+ allowNull: true,
25
+ field: "controller_process_id",
26
+ comment: "Per-combination process_id (for CampaignCreationLog)",
27
+ },
28
+ feed_provider: {
29
+ type: DataTypes.STRING(100),
30
+ allowNull: false,
31
+ field: "feed_provider",
32
+ comment: "Normalized feed name: Mine - RSOC, Predicto - RSOC, etc.",
33
+ },
34
+ failed_step: {
35
+ type: DataTypes.STRING(50),
36
+ allowNull: false,
37
+ field: "failed_step",
38
+ comment:
39
+ "Step that failed: keywords, texts, banners, fb_creation, rabbitmq_publish",
40
+ },
41
+ original_payload: {
42
+ type: DataTypes.JSONB,
43
+ allowNull: false,
44
+ field: "original_payload",
45
+ comment: "Full combination payload for retry",
46
+ },
47
+ generated_assets: {
48
+ type: DataTypes.JSONB,
49
+ allowNull: true,
50
+ defaultValue: {},
51
+ field: "generated_assets",
52
+ comment:
53
+ "Assets generated before failure: { keywords, headlines, primaryTexts, bannerFiles }",
54
+ },
55
+ campaign_context: {
56
+ type: DataTypes.JSONB,
57
+ allowNull: true,
58
+ defaultValue: {},
59
+ field: "campaign_context",
60
+ comment:
61
+ "Additional context needed to resume campaign flow after retry",
62
+ },
63
+ status: {
64
+ type: DataTypes.STRING(50),
65
+ allowNull: false,
66
+ defaultValue: "pending",
67
+ validate: {
68
+ isIn: [["pending", "processing", "completed", "failed", "abandoned"]],
69
+ },
70
+ },
71
+ retry_count: {
72
+ type: DataTypes.INTEGER,
73
+ allowNull: false,
74
+ defaultValue: 0,
75
+ field: "retry_count",
76
+ },
77
+ max_retries: {
78
+ type: DataTypes.INTEGER,
79
+ allowNull: false,
80
+ defaultValue: 5,
81
+ field: "max_retries",
82
+ },
83
+ next_retry_at: {
84
+ type: DataTypes.DATE,
85
+ allowNull: false,
86
+ field: "next_retry_at",
87
+ comment: "When the next retry should be attempted",
88
+ },
89
+ last_error: {
90
+ type: DataTypes.TEXT,
91
+ allowNull: true,
92
+ field: "last_error",
93
+ },
94
+ last_attempt_at: {
95
+ type: DataTypes.DATE,
96
+ allowNull: true,
97
+ field: "last_attempt_at",
98
+ },
99
+ completed_at: {
100
+ type: DataTypes.DATE,
101
+ allowNull: true,
102
+ field: "completed_at",
103
+ },
104
+ },
105
+ {
106
+ tableName: "ai_creation_retry_queue",
107
+ timestamps: true,
108
+ underscored: true,
109
+ indexes: [
110
+ {
111
+ fields: ["status", "next_retry_at"],
112
+ name: "idx_creation_retry_status_next",
113
+ },
114
+ {
115
+ fields: ["agrs_cid"],
116
+ name: "idx_creation_retry_agrs_cid",
117
+ },
118
+ ],
119
+ }
120
+ );
121
+
122
+ AiCreationRetryQueue.associate = (models) => {
123
+ // No associations needed for now
124
+ };
125
+
126
+ return AiCreationRetryQueue;
127
+ };
package/models/Article.js CHANGED
@@ -1,206 +1,212 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const Article = sequelize.define(
3
- "Article",
4
- {
5
- providerId: {
6
- type: DataTypes.STRING,
7
- allowNull: true,
8
- },
9
- keywordId: {
10
- type: DataTypes.STRING,
11
- allowNull: true,
12
- comment: "ID of the keyword from Predicto keywords API",
13
- },
14
- requestedFromDashboard: {
15
- type: DataTypes.BOOLEAN,
16
- allowNull: false,
17
- defaultValue: false,
18
- comment:
19
- "Indicates if the article was created through our dashboard (true) or imported from external sources (false)",
20
- },
21
- category: {
22
- type: DataTypes.STRING,
23
- allowNull: true,
24
- },
25
- AGRSAID: {
26
- type: DataTypes.STRING,
27
- allowNull: false,
28
- unique: true,
29
- },
30
- articleUrl: {
31
- type: DataTypes.STRING(1024),
32
- allowNull: true,
33
- },
34
- feed: {
35
- type: DataTypes.STRING,
36
- allowNull: false,
37
- },
38
- feedName: {
39
- type: DataTypes.STRING,
40
- allowNull: false,
41
- },
42
- vertical: {
43
- type: DataTypes.STRING,
44
- allowNull: false,
45
- },
46
- language: {
47
- type: DataTypes.STRING,
48
- allowNull: false,
49
- defaultValue: "en",
50
- },
51
- headline: {
52
- type: DataTypes.STRING(1000),
53
- allowNull: true,
54
- },
55
- topics: {
56
- type: DataTypes.ARRAY(DataTypes.STRING(1000)),
57
- allowNull: true,
58
- },
59
- translatedTopics: {
60
- type: DataTypes.ARRAY(DataTypes.STRING(1000)),
61
- allowNull: true,
62
- comment: "Topics translated to English for display purposes",
63
- },
64
- mainKeyword: {
65
- type: DataTypes.STRING,
66
- allowNull: true,
67
- },
68
- predictoKeyword: {
69
- type: DataTypes.STRING,
70
- allowNull: true,
71
- comment: "Exact keyword sent to Predicto (with suffix for uniqueness). Used for search= URL param.",
72
- },
73
- keywords: {
74
- type: DataTypes.ARRAY(DataTypes.STRING),
75
- allowNull: true,
76
- },
77
- date: {
78
- type: DataTypes.DATE,
79
- allowNull: true,
80
- defaultValue: DataTypes.NOW,
81
- },
82
- nativeKeyword: {
83
- type: DataTypes.STRING,
84
- allowNull: false,
85
- },
86
- suggestedKeywords: {
87
- type: DataTypes.STRING,
88
- allowNull: true,
89
- },
90
- articleExcerpt: {
91
- type: DataTypes.TEXT,
92
- allowNull: true,
93
- },
94
- articleContent: {
95
- type: DataTypes.TEXT,
96
- allowNull: true,
97
- },
98
- fbPixelId: {
99
- type: DataTypes.STRING,
100
- allowNull: true,
101
- },
102
- status: {
103
- type: DataTypes.STRING,
104
- allowNull: false,
105
- defaultValue: "pending",
106
- },
107
- originalStatus: {
108
- type: DataTypes.STRING,
109
- allowNull: true,
110
- comment: "Original status from Predicto before any mapping",
111
- },
112
- rejectionReason: {
113
- type: DataTypes.TEXT,
114
- allowNull: true,
115
- comment: "Rejection reason from Predicto when keyword is disapproved",
116
- },
117
- creationType: {
118
- type: DataTypes.STRING,
119
- allowNull: false,
120
- defaultValue: "slug",
121
- validate: {
122
- isIn: [["search", "slug", "manual-tonic"]],
123
- },
124
- },
125
- createdAt: {
126
- type: DataTypes.DATE,
127
- defaultValue: DataTypes.NOW,
128
- },
129
- updatedAt: {
130
- type: DataTypes.DATE,
131
- defaultValue: DataTypes.NOW,
132
- },
133
- buyer: {
134
- type: DataTypes.STRING,
135
- allowNull: true,
136
- },
137
- country: {
138
- type: DataTypes.STRING,
139
- allowNull: true,
140
- },
141
- name: {
142
- type: DataTypes.STRING,
143
- allowNull: true,
144
- },
145
- submittedToMine: {
146
- type: DataTypes.BOOLEAN,
147
- allowNull: true,
148
- defaultValue: false,
149
- comment: "Tracks if article has been submitted to Mine Marketing API in bulk migration"
150
- },
151
- submittedToMineAt: {
152
- type: DataTypes.DATE,
153
- allowNull: true,
154
- comment: "Timestamp when article was submitted to Mine Marketing"
155
- },
156
- contentType: {
157
- type: DataTypes.STRING,
158
- allowNull: true,
159
- defaultValue: 'generate',
160
- validate: {
161
- isIn: [['generate', 'import']]
162
- },
163
- comment: "Type of content: 'generate' for AI-generated or 'import' from URL"
164
- }
165
- },
166
- {
167
- tableName: "articles",
168
- timestamps: true,
169
- indexes: [
170
- {
171
- unique: true,
172
- fields: ['providerId', 'feed'],
173
- name: 'unique_provider_per_feed'
174
- }
175
- ]
176
- }
177
- );
178
-
179
- Article.associate = (models) => {
180
- Article.hasMany(models.RSOCFeedCampaign, {
181
- foreignKey: "AGRSAID",
182
- sourceKey: "AGRSAID",
183
- as: "RSOCFeedCampaigns",
184
- constraints: false,
185
- });
186
- };
187
-
188
- Article.prototype.isAvailableForCampaign = function () {
189
- return ["approved", "keyword_already_exists"].includes(this.status);
190
- };
191
-
192
- // NEW METHODS FOR URL STRUCTURE HANDLING
193
- Article.prototype.isUnifiedStructure = function () {
194
- return this.url_structure === "unified";
195
- };
196
-
197
- Article.prototype.getTargetDomain = function () {
198
- return this.target_domain || "sportfoy.com";
199
- };
200
-
201
- Article.prototype.isLegacyStructure = function () {
202
- return this.url_structure === "legacy";
203
- };
204
-
205
- return Article;
206
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const Article = sequelize.define(
3
+ "Article",
4
+ {
5
+ providerId: {
6
+ type: DataTypes.STRING,
7
+ allowNull: true,
8
+ },
9
+ keywordId: {
10
+ type: DataTypes.STRING,
11
+ allowNull: true,
12
+ comment: "ID of the keyword from Predicto keywords API",
13
+ },
14
+ requestedFromDashboard: {
15
+ type: DataTypes.BOOLEAN,
16
+ allowNull: false,
17
+ defaultValue: false,
18
+ comment:
19
+ "Indicates if the article was created through our dashboard (true) or imported from external sources (false)",
20
+ },
21
+ category: {
22
+ type: DataTypes.STRING,
23
+ allowNull: true,
24
+ },
25
+ AGRSAID: {
26
+ type: DataTypes.STRING,
27
+ allowNull: false,
28
+ unique: true,
29
+ },
30
+ articleUrl: {
31
+ type: DataTypes.STRING(1024),
32
+ allowNull: true,
33
+ },
34
+ feed: {
35
+ type: DataTypes.STRING,
36
+ allowNull: false,
37
+ },
38
+ feedName: {
39
+ type: DataTypes.STRING,
40
+ allowNull: false,
41
+ },
42
+ vertical: {
43
+ type: DataTypes.STRING,
44
+ allowNull: false,
45
+ },
46
+ language: {
47
+ type: DataTypes.STRING,
48
+ allowNull: false,
49
+ defaultValue: "en",
50
+ },
51
+ headline: {
52
+ type: DataTypes.STRING(1000),
53
+ allowNull: true,
54
+ },
55
+ topics: {
56
+ type: DataTypes.ARRAY(DataTypes.STRING(1000)),
57
+ allowNull: true,
58
+ },
59
+ translatedTopics: {
60
+ type: DataTypes.ARRAY(DataTypes.STRING(1000)),
61
+ allowNull: true,
62
+ comment: "Topics translated to English for display purposes",
63
+ },
64
+ mainKeyword: {
65
+ type: DataTypes.STRING,
66
+ allowNull: true,
67
+ },
68
+ predictoKeyword: {
69
+ type: DataTypes.STRING,
70
+ allowNull: true,
71
+ comment: "Exact keyword sent to Predicto (with suffix for uniqueness). Used for search= URL param.",
72
+ },
73
+ keywords: {
74
+ type: DataTypes.ARRAY(DataTypes.STRING),
75
+ allowNull: true,
76
+ },
77
+ date: {
78
+ type: DataTypes.DATE,
79
+ allowNull: true,
80
+ defaultValue: DataTypes.NOW,
81
+ },
82
+ nativeKeyword: {
83
+ type: DataTypes.STRING,
84
+ allowNull: false,
85
+ },
86
+ suggestedKeywords: {
87
+ type: DataTypes.STRING,
88
+ allowNull: true,
89
+ },
90
+ articleExcerpt: {
91
+ type: DataTypes.TEXT,
92
+ allowNull: true,
93
+ },
94
+ articleContent: {
95
+ type: DataTypes.TEXT,
96
+ allowNull: true,
97
+ },
98
+ fbPixelId: {
99
+ type: DataTypes.STRING,
100
+ allowNull: true,
101
+ },
102
+ status: {
103
+ type: DataTypes.STRING,
104
+ allowNull: false,
105
+ defaultValue: "pending",
106
+ },
107
+ originalStatus: {
108
+ type: DataTypes.STRING,
109
+ allowNull: true,
110
+ comment: "Original status from Predicto before any mapping",
111
+ },
112
+ rejectionReason: {
113
+ type: DataTypes.TEXT,
114
+ allowNull: true,
115
+ comment: "Rejection reason from Predicto when keyword is disapproved",
116
+ },
117
+ creationType: {
118
+ type: DataTypes.STRING,
119
+ allowNull: false,
120
+ defaultValue: "slug",
121
+ validate: {
122
+ isIn: [["search", "slug", "manual-tonic"]],
123
+ },
124
+ },
125
+ createdAt: {
126
+ type: DataTypes.DATE,
127
+ defaultValue: DataTypes.NOW,
128
+ },
129
+ updatedAt: {
130
+ type: DataTypes.DATE,
131
+ defaultValue: DataTypes.NOW,
132
+ },
133
+ buyer: {
134
+ type: DataTypes.STRING,
135
+ allowNull: true,
136
+ },
137
+ country: {
138
+ type: DataTypes.STRING,
139
+ allowNull: true,
140
+ },
141
+ name: {
142
+ type: DataTypes.STRING,
143
+ allowNull: true,
144
+ },
145
+ submittedToMine: {
146
+ type: DataTypes.BOOLEAN,
147
+ allowNull: true,
148
+ defaultValue: false,
149
+ comment: "Tracks if article has been submitted to Mine Marketing API in bulk migration"
150
+ },
151
+ submittedToMineAt: {
152
+ type: DataTypes.DATE,
153
+ allowNull: true,
154
+ comment: "Timestamp when article was submitted to Mine Marketing"
155
+ },
156
+ contentType: {
157
+ type: DataTypes.STRING,
158
+ allowNull: true,
159
+ defaultValue: 'generate',
160
+ validate: {
161
+ isIn: [['generate', 'import']]
162
+ },
163
+ comment: "Type of content: 'generate' for AI-generated or 'import' from URL"
164
+ },
165
+ platform: {
166
+ type: DataTypes.ENUM("fb", "tt", "snp"),
167
+ allowNull: false,
168
+ defaultValue: "fb",
169
+ comment: "Ad platform identifier: fb=Facebook, tt=TikTok, snp=Snapchat",
170
+ }
171
+ },
172
+ {
173
+ tableName: "articles",
174
+ timestamps: true,
175
+ indexes: [
176
+ {
177
+ unique: true,
178
+ fields: ['providerId', 'feed'],
179
+ name: 'unique_provider_per_feed'
180
+ }
181
+ ]
182
+ }
183
+ );
184
+
185
+ Article.associate = (models) => {
186
+ Article.hasMany(models.RSOCFeedCampaign, {
187
+ foreignKey: "AGRSAID",
188
+ sourceKey: "AGRSAID",
189
+ as: "RSOCFeedCampaigns",
190
+ constraints: false,
191
+ });
192
+ };
193
+
194
+ Article.prototype.isAvailableForCampaign = function () {
195
+ return ["approved", "keyword_already_exists"].includes(this.status);
196
+ };
197
+
198
+ // NEW METHODS FOR URL STRUCTURE HANDLING
199
+ Article.prototype.isUnifiedStructure = function () {
200
+ return this.url_structure === "unified";
201
+ };
202
+
203
+ Article.prototype.getTargetDomain = function () {
204
+ return this.target_domain || "sportfoy.com";
205
+ };
206
+
207
+ Article.prototype.isLegacyStructure = function () {
208
+ return this.url_structure === "legacy";
209
+ };
210
+
211
+ return Article;
212
+ };