agrs-sequelize-sdk 1.3.8 → 1.3.10

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.
@@ -0,0 +1,98 @@
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const AICampaignQueue = sequelize.define(
3
+ "AICampaignQueue",
4
+ {
5
+ id: {
6
+ type: DataTypes.INTEGER,
7
+ primaryKey: true,
8
+ autoIncrement: true,
9
+ },
10
+ article_id: {
11
+ type: DataTypes.STRING(255),
12
+ allowNull: false,
13
+ field: "article_id",
14
+ },
15
+ feed_provider: {
16
+ type: DataTypes.STRING(100),
17
+ allowNull: false,
18
+ field: "feed_provider",
19
+ },
20
+ payload: {
21
+ type: DataTypes.JSONB,
22
+ allowNull: false,
23
+ },
24
+ status: {
25
+ type: DataTypes.STRING(50),
26
+ allowNull: false,
27
+ defaultValue: "pending",
28
+ validate: {
29
+ isIn: [["pending", "processing", "completed", "failed"]],
30
+ },
31
+ },
32
+ created_at: {
33
+ type: DataTypes.DATE,
34
+ allowNull: false,
35
+ defaultValue: DataTypes.NOW,
36
+ field: "created_at",
37
+ },
38
+ processed_at: {
39
+ type: DataTypes.DATE,
40
+ allowNull: true,
41
+ field: "processed_at",
42
+ },
43
+ retry_count: {
44
+ type: DataTypes.INTEGER,
45
+ allowNull: false,
46
+ defaultValue: 0,
47
+ field: "retry_count",
48
+ },
49
+ error_message: {
50
+ type: DataTypes.TEXT,
51
+ allowNull: true,
52
+ field: "error_message",
53
+ },
54
+ facebook_campaign_id: {
55
+ type: DataTypes.STRING(255),
56
+ allowNull: true,
57
+ field: "facebook_campaign_id",
58
+ },
59
+ process_id: {
60
+ type: DataTypes.STRING(255),
61
+ allowNull: true,
62
+ field: "process_id",
63
+ },
64
+ },
65
+ {
66
+ tableName: "ai_campaign_queue",
67
+ timestamps: false, // We manage created_at manually
68
+ indexes: [
69
+ {
70
+ fields: ["status"],
71
+ },
72
+ {
73
+ fields: ["article_id"],
74
+ },
75
+ {
76
+ fields: ["created_at"],
77
+ },
78
+ {
79
+ fields: ["feed_provider"],
80
+ },
81
+ {
82
+ fields: ["process_id"],
83
+ },
84
+ ],
85
+ }
86
+ );
87
+
88
+ AICampaignQueue.associate = (models) => {
89
+ // Optional: Add association to Article model if needed
90
+ // AICampaignQueue.belongsTo(models.Article, {
91
+ // foreignKey: "article_id",
92
+ // targetKey: "AGRSAID",
93
+ // as: "Article",
94
+ // });
95
+ };
96
+
97
+ return AICampaignQueue;
98
+ };
@@ -23,6 +23,13 @@ module.exports = (sequelize, DataTypes) => {
23
23
  allowNull: false,
24
24
  comment: "Whether the rule is currently active",
25
25
  },
26
+ dryRun: {
27
+ type: DataTypes.BOOLEAN,
28
+ defaultValue: false,
29
+ allowNull: false,
30
+ comment:
31
+ "If true, rule will evaluate but not execute actions (simulation mode)",
32
+ },
26
33
  ruleType: {
27
34
  type: DataTypes.ENUM("PAUSE", "BUDGET", "BID", "STATUS", "CUSTOM"),
28
35
  allowNull: true,
@@ -0,0 +1,302 @@
1
+ // models/CampaignCreationLogV2.js
2
+ module.exports = (sequelize, DataTypes) => {
3
+ const CampaignCreationLogV2 = sequelize.define(
4
+ "CampaignCreationLogV2",
5
+ {
6
+ id: {
7
+ type: DataTypes.INTEGER,
8
+ primaryKey: true,
9
+ autoIncrement: true,
10
+ },
11
+ process_id: {
12
+ type: DataTypes.UUID,
13
+ allowNull: false,
14
+ comment: "Unique ID for the creation batch process",
15
+ },
16
+ status: {
17
+ type: DataTypes.ENUM(
18
+ "STARTED",
19
+ "IN_PROGRESS",
20
+ "COMPLETED",
21
+ "FAILED",
22
+ "PARTIALLY_COMPLETED"
23
+ ),
24
+ allowNull: false,
25
+ defaultValue: "STARTED",
26
+ },
27
+
28
+ // Location & Targeting
29
+ country: {
30
+ type: DataTypes.TEXT,
31
+ allowNull: true,
32
+ },
33
+ countries: {
34
+ type: DataTypes.ARRAY(DataTypes.TEXT),
35
+ allowNull: true,
36
+ },
37
+ country_type: {
38
+ type: DataTypes.ENUM("ww", "mix"),
39
+ allowNull: true,
40
+ comment:
41
+ "Computed: ww (has WW), mix (multiple countries without WW), or NULL (single country)",
42
+ },
43
+
44
+ // Campaign identifiers
45
+ feed_campaign_id: {
46
+ type: DataTypes.STRING,
47
+ allowNull: true,
48
+ },
49
+ facebook_campaign_id: {
50
+ type: DataTypes.STRING,
51
+ allowNull: true,
52
+ },
53
+ campaign_name: {
54
+ type: DataTypes.STRING(255),
55
+ allowNull: true,
56
+ },
57
+ facebook_campaign_name: {
58
+ type: DataTypes.STRING(255),
59
+ allowNull: true,
60
+ },
61
+
62
+ // Feed & Provider
63
+ feed_provider: {
64
+ type: DataTypes.STRING(100),
65
+ allowNull: true,
66
+ },
67
+ feed_name: {
68
+ type: DataTypes.STRING(100),
69
+ allowNull: true,
70
+ comment: "Display name (e.g., 'predicto.ai' -> 'Predicto')",
71
+ },
72
+
73
+ // User & Account
74
+ media_buyer: {
75
+ type: DataTypes.STRING(100),
76
+ allowNull: true,
77
+ },
78
+ assignee: {
79
+ type: DataTypes.STRING(100),
80
+ allowNull: true,
81
+ },
82
+ user_name: {
83
+ type: DataTypes.STRING(100),
84
+ allowNull: true,
85
+ comment: "Full name from user mapping",
86
+ },
87
+ account_id: {
88
+ type: DataTypes.STRING(100),
89
+ allowNull: true,
90
+ },
91
+ account_name: {
92
+ type: DataTypes.STRING(255),
93
+ allowNull: true,
94
+ comment: "From AdAccount table",
95
+ },
96
+
97
+ // Campaign metadata
98
+ vertical: {
99
+ type: DataTypes.STRING(100),
100
+ allowNull: true,
101
+ },
102
+ platform: {
103
+ type: DataTypes.STRING(50),
104
+ allowNull: true,
105
+ },
106
+ language: {
107
+ type: DataTypes.STRING(50),
108
+ allowNull: true,
109
+ },
110
+ domain: {
111
+ type: DataTypes.STRING(255),
112
+ allowNull: true,
113
+ },
114
+
115
+ // Keywords & Content
116
+ keywords: {
117
+ type: DataTypes.ARRAY(DataTypes.TEXT),
118
+ allowNull: true,
119
+ },
120
+ main_keyword: {
121
+ type: DataTypes.STRING(255),
122
+ allowNull: true,
123
+ },
124
+ article_style: {
125
+ type: DataTypes.STRING(50),
126
+ allowNull: true,
127
+ comment: "black, blue, green, white",
128
+ },
129
+ ad_title: {
130
+ type: DataTypes.STRING(500),
131
+ allowNull: true,
132
+ },
133
+ notes: {
134
+ type: DataTypes.TEXT,
135
+ allowNull: true,
136
+ },
137
+ free_text: {
138
+ type: DataTypes.TEXT,
139
+ allowNull: true,
140
+ },
141
+
142
+ // Facebook Campaign Settings
143
+ pixel_id: {
144
+ type: DataTypes.STRING(100),
145
+ allowNull: true,
146
+ },
147
+ pixel_name: {
148
+ type: DataTypes.STRING(255),
149
+ allowNull: true,
150
+ },
151
+ pixel_event: {
152
+ type: DataTypes.STRING(50),
153
+ allowNull: true,
154
+ },
155
+ bid_strategy: {
156
+ type: DataTypes.STRING(100),
157
+ allowNull: true,
158
+ },
159
+ daily_budget: {
160
+ type: DataTypes.DECIMAL(10, 2),
161
+ allowNull: true,
162
+ },
163
+ bid_amount: {
164
+ type: DataTypes.DECIMAL(10, 2),
165
+ allowNull: true,
166
+ },
167
+ optimization_goal: {
168
+ type: DataTypes.STRING(100),
169
+ allowNull: true,
170
+ },
171
+ special_ad_categories: {
172
+ type: DataTypes.ARRAY(DataTypes.TEXT),
173
+ allowNull: true,
174
+ comment: "Array of categories (CREDIT, HOUSING, EMPLOYMENT)",
175
+ },
176
+
177
+ // Page info
178
+ page_id: {
179
+ type: DataTypes.UUID,
180
+ allowNull: true,
181
+ },
182
+ page_code: {
183
+ type: DataTypes.STRING(100),
184
+ allowNull: true,
185
+ },
186
+ page_name: {
187
+ type: DataTypes.STRING(255),
188
+ allowNull: true,
189
+ },
190
+
191
+ // Article/Content
192
+ agrs_aid: {
193
+ type: DataTypes.STRING(255),
194
+ allowNull: true,
195
+ comment: "Article ID",
196
+ },
197
+ article_id: {
198
+ type: DataTypes.STRING(255),
199
+ allowNull: true,
200
+ comment: "For Mine/Predicto feeds",
201
+ },
202
+
203
+ // Error handling
204
+ error_message: {
205
+ type: DataTypes.TEXT,
206
+ allowNull: true,
207
+ },
208
+ error_user_title: {
209
+ type: DataTypes.STRING(255),
210
+ allowNull: true,
211
+ },
212
+ error_code: {
213
+ type: DataTypes.STRING(50),
214
+ allowNull: true,
215
+ },
216
+ error_subcode: {
217
+ type: DataTypes.STRING(50),
218
+ allowNull: true,
219
+ },
220
+
221
+ // JSON fields for backward compatibility
222
+ details: {
223
+ type: DataTypes.JSONB,
224
+ allowNull: true,
225
+ comment: "For backward compatibility and complex nested data",
226
+ },
227
+ original_request_data: {
228
+ type: DataTypes.JSONB,
229
+ allowNull: true,
230
+ comment: "Full original request for reference",
231
+ },
232
+ facebook_response: {
233
+ type: DataTypes.JSONB,
234
+ allowNull: true,
235
+ comment: "Facebook API response",
236
+ },
237
+ },
238
+ {
239
+ tableName: "CampaignCreationLogsV2",
240
+ timestamps: true,
241
+ createdAt: "created_at",
242
+ updatedAt: "updated_at",
243
+ indexes: [
244
+ { fields: ["process_id"] },
245
+ { fields: ["status"] },
246
+ { fields: ["country"] },
247
+ { fields: ["countries"], using: "gin" },
248
+ { fields: ["country_type"] },
249
+ { fields: ["feed_provider"] },
250
+ { fields: ["media_buyer"] },
251
+ { fields: ["account_id"] },
252
+ { fields: ["vertical"] },
253
+ { fields: ["keywords"], using: "gin" },
254
+ { fields: [{ name: "created_at", order: "DESC" }] },
255
+ {
256
+ fields: [
257
+ "process_id",
258
+ "status",
259
+ { name: "created_at", order: "DESC" },
260
+ ],
261
+ },
262
+ { fields: ["status", "country"] },
263
+ { fields: ["feed_provider", "status"] },
264
+ { fields: ["media_buyer", "status"] },
265
+ { fields: ["account_id", "status"] },
266
+ { fields: ["vertical", "feed_provider"] },
267
+ { fields: ["details"], using: "gin" },
268
+ ],
269
+ }
270
+ );
271
+
272
+ CampaignCreationLogV2.associate = (models) => {
273
+ if (models.CampaignCreationLog) {
274
+ CampaignCreationLogV2.belongsTo(models.CampaignCreationLog, {
275
+ foreignKey: "process_id",
276
+ targetKey: "process_id",
277
+ as: "OriginalLog",
278
+ constraints: false,
279
+ });
280
+ }
281
+
282
+ if (models.AdAccount) {
283
+ CampaignCreationLogV2.belongsTo(models.AdAccount, {
284
+ foreignKey: "account_id",
285
+ targetKey: "AdAccountID",
286
+ as: "Account",
287
+ constraints: false,
288
+ });
289
+ }
290
+
291
+ if (models.Pages) {
292
+ CampaignCreationLogV2.belongsTo(models.Pages, {
293
+ foreignKey: "page_code",
294
+ targetKey: "code",
295
+ as: "Page",
296
+ constraints: false,
297
+ });
298
+ }
299
+ };
300
+
301
+ return CampaignCreationLogV2;
302
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.3.8",
3
+ "version": "1.3.10",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",