agrs-sequelize-sdk 1.1.77 → 1.1.78

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.
@@ -1,293 +1,293 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const RSOCFeedCampaign = sequelize.define(
3
- "RSOCFeedCampaign",
4
- {
5
- AGRS_CID: {
6
- type: DataTypes.STRING,
7
- allowNull: false,
8
- unique: true,
9
- primaryKey: true,
10
- },
11
- AGRSAID: {
12
- type: DataTypes.STRING,
13
- allowNull: false,
14
- comment: "ID referencing Article.AGRSAID",
15
- },
16
- articleName: {
17
- type: DataTypes.STRING,
18
- allowNull: false,
19
- comment: "Name of the associated article",
20
- },
21
- channelId: {
22
- type: DataTypes.STRING,
23
- allowNull: false,
24
- comment: "ID referencing Channel.channelId",
25
- },
26
- styleId: {
27
- type: DataTypes.STRING,
28
- allowNull: true,
29
- comment: "Style ID (stid) inherited from Channel",
30
- },
31
- assignee: {
32
- type: DataTypes.STRING,
33
- allowNull: false,
34
- },
35
- status: {
36
- type: DataTypes.STRING,
37
- allowNull: false,
38
- defaultValue: "active",
39
- validate: {
40
- isIn: [["active", "inactive", "archived"]],
41
- },
42
- },
43
- country: {
44
- type: DataTypes.STRING,
45
- allowNull: false,
46
- },
47
- vertical: {
48
- type: DataTypes.STRING,
49
- allowNull: false,
50
- comment: "Maps to Article.category for dynamic selection",
51
- },
52
- freeText: {
53
- type: DataTypes.TEXT,
54
- allowNull: true,
55
- },
56
- campaignName: {
57
- type: DataTypes.STRING,
58
- allowNull: false,
59
- },
60
- campaignId: {
61
- type: DataTypes.STRING,
62
- allowNull: true,
63
- },
64
- keywords: {
65
- type: DataTypes.ARRAY(DataTypes.STRING),
66
- allowNull: true,
67
- },
68
- link: {
69
- type: DataTypes.STRING(1024),
70
- allowNull: true,
71
- comment: "Campaign-specific URL based on article URL with parameters",
72
- },
73
- redirectLink: {
74
- type: DataTypes.STRING(1024),
75
- allowNull: true,
76
- },
77
- pixelId: {
78
- type: DataTypes.STRING(1024),
79
- allowNull: true,
80
- },
81
- token: {
82
- type: DataTypes.STRING(1024),
83
- allowNull: true,
84
- },
85
- accountId: {
86
- type: DataTypes.STRING,
87
- allowNull: false,
88
- },
89
- feedName: {
90
- type: DataTypes.STRING,
91
- allowNull: true,
92
- defaultValue: "RSOC",
93
- },
94
- adTitle: {
95
- type: DataTypes.STRING,
96
- allowNull: true,
97
- },
98
- domain: {
99
- type: DataTypes.STRING,
100
- allowNull: true,
101
- },
102
- feedProvider: {
103
- type: DataTypes.STRING,
104
- allowNull: false,
105
- defaultValue: "RSOC",
106
- },
107
- createdCampaignAt: {
108
- type: DataTypes.DATE,
109
- allowNull: true,
110
- defaultValue: DataTypes.NOW,
111
- },
112
- draft: {
113
- type: DataTypes.BOOLEAN,
114
- allowNull: true,
115
- defaultValue: false,
116
- },
117
- createdAt: {
118
- type: DataTypes.DATE,
119
- allowNull: false,
120
- defaultValue: DataTypes.NOW,
121
- },
122
- updatedAt: {
123
- type: DataTypes.DATE,
124
- allowNull: false,
125
- defaultValue: DataTypes.NOW,
126
- },
127
- platform: {
128
- type: DataTypes.STRING,
129
- allowNull: false,
130
- },
131
- mediaBuyer: {
132
- type: DataTypes.STRING,
133
- allowNull: true,
134
- },
135
- },
136
- {
137
- tableName: "rsoc_feed_campaigns",
138
- timestamps: true,
139
- }
140
- );
141
-
142
- // Define associations without enforcing foreign key constraints
143
- RSOCFeedCampaign.associate = (models) => {
144
- if (models.Article) {
145
- RSOCFeedCampaign.belongsTo(models.Article, {
146
- foreignKey: "AGRSAID",
147
- targetKey: "AGRSAID",
148
- as: "Article",
149
- constraints: false,
150
- });
151
- }
152
-
153
- if (models.Channel) {
154
- RSOCFeedCampaign.belongsTo(models.Channel, {
155
- foreignKey: "channelId",
156
- targetKey: "channelId",
157
- as: "Channel",
158
- constraints: false,
159
- });
160
- }
161
- };
162
-
163
- // BeforeCreate hook: Update Channel status and connectedCampaigns
164
- RSOCFeedCampaign.beforeCreate(async (campaign, options) => {
165
- campaign.setDataValue("redirectLink", null);
166
-
167
- // Skip channel update if in a silent operation (e.g., during sync)
168
- if (options.silent) return;
169
-
170
- try {
171
- const channel = await sequelize.models.Channel.findOne({
172
- where: {
173
- channelId: campaign.channelId,
174
- styleId: campaign.styleId || null,
175
- },
176
- });
177
-
178
- if (channel) {
179
- const connectedCampaigns = channel.connectedCampaigns || [];
180
- if (
181
- !connectedCampaigns.some((c) => c.campaignId === campaign.AGRS_CID)
182
- ) {
183
- connectedCampaigns.push({
184
- campaignId: campaign.AGRS_CID,
185
- assignedAt: new Date(),
186
- releasedAt: null,
187
- });
188
- await channel.update(
189
- {
190
- status: "used",
191
- connectedCampaigns,
192
- },
193
- { silent: true }
194
- );
195
- }
196
- } else {
197
- console.warn(
198
- `Channel not found for channelId: ${campaign.channelId}, styleId: ${campaign.styleId}`
199
- );
200
- }
201
- } catch (error) {
202
- console.error("Error in beforeCreate hook:", error.message);
203
- }
204
- });
205
-
206
- // BeforeUpdate hook: Handle channel reassignment
207
- RSOCFeedCampaign.beforeUpdate(async (campaign, options) => {
208
- campaign.setDataValue("redirectLink", null);
209
-
210
- // Skip channel update if in a silent operation or no relevant changes
211
- if (
212
- options.silent ||
213
- (!campaign.changed("channelId") && !campaign.changed("styleId"))
214
- ) {
215
- return;
216
- }
217
-
218
- try {
219
- const oldChannelId = campaign.previous("channelId");
220
- const oldStyleId = campaign.previous("styleId") || null;
221
- const newChannelId = campaign.channelId;
222
- const newStyleId = campaign.styleId || null;
223
-
224
- // Release old channel
225
- if (
226
- oldChannelId &&
227
- (oldChannelId !== newChannelId || oldStyleId !== newStyleId)
228
- ) {
229
- const oldChannel = await sequelize.models.Channel.findOne({
230
- where: {
231
- channelId: oldChannelId,
232
- styleId: oldStyleId,
233
- },
234
- });
235
-
236
- if (oldChannel) {
237
- const connectedCampaigns = oldChannel.connectedCampaigns || [];
238
- const updatedCampaigns = connectedCampaigns
239
- .map((c) =>
240
- c.campaignId === campaign.AGRS_CID
241
- ? { ...c, releasedAt: new Date() }
242
- : c
243
- )
244
- .filter((c) => !c.releasedAt);
245
-
246
- await oldChannel.update(
247
- {
248
- connectedCampaigns: updatedCampaigns,
249
- status: updatedCampaigns.length > 0 ? "used" : "free",
250
- },
251
- { silent: true }
252
- );
253
- }
254
- }
255
-
256
- // Assign new channel
257
- const newChannel = await sequelize.models.Channel.findOne({
258
- where: {
259
- channelId: newChannelId,
260
- styleId: newStyleId,
261
- },
262
- });
263
-
264
- if (newChannel) {
265
- const connectedCampaigns = newChannel.connectedCampaigns || [];
266
- if (
267
- !connectedCampaigns.some((c) => c.campaignId === campaign.AGRS_CID)
268
- ) {
269
- connectedCampaigns.push({
270
- campaignId: campaign.AGRS_CID,
271
- assignedAt: new Date(),
272
- releasedAt: null,
273
- });
274
- await newChannel.update(
275
- {
276
- status: "used",
277
- connectedCampaigns,
278
- },
279
- { silent: true }
280
- );
281
- }
282
- } else {
283
- console.warn(
284
- `New channel not found for channelId: ${newChannelId}, styleId: ${newStyleId}`
285
- );
286
- }
287
- } catch (error) {
288
- console.error("Error in beforeUpdate hook:", error.message);
289
- }
290
- });
291
-
292
- return RSOCFeedCampaign;
293
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const RSOCFeedCampaign = sequelize.define(
3
+ "RSOCFeedCampaign",
4
+ {
5
+ AGRS_CID: {
6
+ type: DataTypes.STRING,
7
+ allowNull: false,
8
+ unique: true,
9
+ primaryKey: true,
10
+ },
11
+ AGRSAID: {
12
+ type: DataTypes.STRING,
13
+ allowNull: false,
14
+ comment: "ID referencing Article.AGRSAID",
15
+ },
16
+ articleName: {
17
+ type: DataTypes.STRING,
18
+ allowNull: false,
19
+ comment: "Name of the associated article",
20
+ },
21
+ channelId: {
22
+ type: DataTypes.STRING,
23
+ allowNull: false,
24
+ comment: "ID referencing Channel.channelId",
25
+ },
26
+ styleId: {
27
+ type: DataTypes.STRING,
28
+ allowNull: true,
29
+ comment: "Style ID (stid) inherited from Channel",
30
+ },
31
+ assignee: {
32
+ type: DataTypes.STRING,
33
+ allowNull: false,
34
+ },
35
+ status: {
36
+ type: DataTypes.STRING,
37
+ allowNull: false,
38
+ defaultValue: "active",
39
+ validate: {
40
+ isIn: [["active", "inactive", "archived"]],
41
+ },
42
+ },
43
+ country: {
44
+ type: DataTypes.STRING,
45
+ allowNull: false,
46
+ },
47
+ vertical: {
48
+ type: DataTypes.STRING,
49
+ allowNull: false,
50
+ comment: "Maps to Article.category for dynamic selection",
51
+ },
52
+ freeText: {
53
+ type: DataTypes.TEXT,
54
+ allowNull: true,
55
+ },
56
+ campaignName: {
57
+ type: DataTypes.STRING,
58
+ allowNull: false,
59
+ },
60
+ campaignId: {
61
+ type: DataTypes.STRING,
62
+ allowNull: true,
63
+ },
64
+ keywords: {
65
+ type: DataTypes.ARRAY(DataTypes.STRING),
66
+ allowNull: true,
67
+ },
68
+ link: {
69
+ type: DataTypes.STRING(1024),
70
+ allowNull: true,
71
+ comment: "Campaign-specific URL based on article URL with parameters",
72
+ },
73
+ redirectLink: {
74
+ type: DataTypes.STRING(1024),
75
+ allowNull: true,
76
+ },
77
+ pixelId: {
78
+ type: DataTypes.STRING(1024),
79
+ allowNull: true,
80
+ },
81
+ token: {
82
+ type: DataTypes.STRING(1024),
83
+ allowNull: true,
84
+ },
85
+ accountId: {
86
+ type: DataTypes.STRING,
87
+ allowNull: false,
88
+ },
89
+ feedName: {
90
+ type: DataTypes.STRING,
91
+ allowNull: true,
92
+ defaultValue: "RSOC",
93
+ },
94
+ adTitle: {
95
+ type: DataTypes.STRING,
96
+ allowNull: true,
97
+ },
98
+ domain: {
99
+ type: DataTypes.STRING,
100
+ allowNull: true,
101
+ },
102
+ feedProvider: {
103
+ type: DataTypes.STRING,
104
+ allowNull: false,
105
+ defaultValue: "RSOC",
106
+ },
107
+ createdCampaignAt: {
108
+ type: DataTypes.DATE,
109
+ allowNull: true,
110
+ defaultValue: DataTypes.NOW,
111
+ },
112
+ draft: {
113
+ type: DataTypes.BOOLEAN,
114
+ allowNull: true,
115
+ defaultValue: false,
116
+ },
117
+ createdAt: {
118
+ type: DataTypes.DATE,
119
+ allowNull: false,
120
+ defaultValue: DataTypes.NOW,
121
+ },
122
+ updatedAt: {
123
+ type: DataTypes.DATE,
124
+ allowNull: false,
125
+ defaultValue: DataTypes.NOW,
126
+ },
127
+ platform: {
128
+ type: DataTypes.STRING,
129
+ allowNull: false,
130
+ },
131
+ mediaBuyer: {
132
+ type: DataTypes.STRING,
133
+ allowNull: true,
134
+ },
135
+ },
136
+ {
137
+ tableName: "rsoc_feed_campaigns",
138
+ timestamps: true,
139
+ }
140
+ );
141
+
142
+ // Define associations without enforcing foreign key constraints
143
+ RSOCFeedCampaign.associate = (models) => {
144
+ if (models.Article) {
145
+ RSOCFeedCampaign.belongsTo(models.Article, {
146
+ foreignKey: "AGRSAID",
147
+ targetKey: "AGRSAID",
148
+ as: "Article",
149
+ constraints: false,
150
+ });
151
+ }
152
+
153
+ if (models.Channel) {
154
+ RSOCFeedCampaign.belongsTo(models.Channel, {
155
+ foreignKey: "channelId",
156
+ targetKey: "channelId",
157
+ as: "Channel",
158
+ constraints: false,
159
+ });
160
+ }
161
+ };
162
+
163
+ // BeforeCreate hook: Update Channel status and connectedCampaigns
164
+ RSOCFeedCampaign.beforeCreate(async (campaign, options) => {
165
+ campaign.setDataValue("redirectLink", null);
166
+
167
+ // Skip channel update if in a silent operation (e.g., during sync)
168
+ if (options.silent) return;
169
+
170
+ try {
171
+ const channel = await sequelize.models.Channel.findOne({
172
+ where: {
173
+ channelId: campaign.channelId,
174
+ styleId: campaign.styleId || null,
175
+ },
176
+ });
177
+
178
+ if (channel) {
179
+ const connectedCampaigns = channel.connectedCampaigns || [];
180
+ if (
181
+ !connectedCampaigns.some((c) => c.campaignId === campaign.AGRS_CID)
182
+ ) {
183
+ connectedCampaigns.push({
184
+ campaignId: campaign.AGRS_CID,
185
+ assignedAt: new Date(),
186
+ releasedAt: null,
187
+ });
188
+ await channel.update(
189
+ {
190
+ status: "used",
191
+ connectedCampaigns,
192
+ },
193
+ { silent: true }
194
+ );
195
+ }
196
+ } else {
197
+ console.warn(
198
+ `Channel not found for channelId: ${campaign.channelId}, styleId: ${campaign.styleId}`
199
+ );
200
+ }
201
+ } catch (error) {
202
+ console.error("Error in beforeCreate hook:", error.message);
203
+ }
204
+ });
205
+
206
+ // BeforeUpdate hook: Handle channel reassignment
207
+ RSOCFeedCampaign.beforeUpdate(async (campaign, options) => {
208
+ campaign.setDataValue("redirectLink", null);
209
+
210
+ // Skip channel update if in a silent operation or no relevant changes
211
+ if (
212
+ options.silent ||
213
+ (!campaign.changed("channelId") && !campaign.changed("styleId"))
214
+ ) {
215
+ return;
216
+ }
217
+
218
+ try {
219
+ const oldChannelId = campaign.previous("channelId");
220
+ const oldStyleId = campaign.previous("styleId") || null;
221
+ const newChannelId = campaign.channelId;
222
+ const newStyleId = campaign.styleId || null;
223
+
224
+ // Release old channel
225
+ if (
226
+ oldChannelId &&
227
+ (oldChannelId !== newChannelId || oldStyleId !== newStyleId)
228
+ ) {
229
+ const oldChannel = await sequelize.models.Channel.findOne({
230
+ where: {
231
+ channelId: oldChannelId,
232
+ styleId: oldStyleId,
233
+ },
234
+ });
235
+
236
+ if (oldChannel) {
237
+ const connectedCampaigns = oldChannel.connectedCampaigns || [];
238
+ const updatedCampaigns = connectedCampaigns
239
+ .map((c) =>
240
+ c.campaignId === campaign.AGRS_CID
241
+ ? { ...c, releasedAt: new Date() }
242
+ : c
243
+ )
244
+ .filter((c) => !c.releasedAt);
245
+
246
+ await oldChannel.update(
247
+ {
248
+ connectedCampaigns: updatedCampaigns,
249
+ status: updatedCampaigns.length > 0 ? "used" : "free",
250
+ },
251
+ { silent: true }
252
+ );
253
+ }
254
+ }
255
+
256
+ // Assign new channel
257
+ const newChannel = await sequelize.models.Channel.findOne({
258
+ where: {
259
+ channelId: newChannelId,
260
+ styleId: newStyleId,
261
+ },
262
+ });
263
+
264
+ if (newChannel) {
265
+ const connectedCampaigns = newChannel.connectedCampaigns || [];
266
+ if (
267
+ !connectedCampaigns.some((c) => c.campaignId === campaign.AGRS_CID)
268
+ ) {
269
+ connectedCampaigns.push({
270
+ campaignId: campaign.AGRS_CID,
271
+ assignedAt: new Date(),
272
+ releasedAt: null,
273
+ });
274
+ await newChannel.update(
275
+ {
276
+ status: "used",
277
+ connectedCampaigns,
278
+ },
279
+ { silent: true }
280
+ );
281
+ }
282
+ } else {
283
+ console.warn(
284
+ `New channel not found for channelId: ${newChannelId}, styleId: ${newStyleId}`
285
+ );
286
+ }
287
+ } catch (error) {
288
+ console.error("Error in beforeUpdate hook:", error.message);
289
+ }
290
+ });
291
+
292
+ return RSOCFeedCampaign;
293
+ };
@@ -0,0 +1,102 @@
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const RsocKeywordPerformance = sequelize.define('RsocKeywordPerformance', {
3
+ id: {
4
+ type: DataTypes.INTEGER,
5
+ primaryKey: true,
6
+ autoIncrement: true,
7
+ allowNull: false
8
+ },
9
+ ts: {
10
+ type: DataTypes.DATE,
11
+ allowNull: false,
12
+ comment: 'Timestamp of the record'
13
+ },
14
+ channel_id: {
15
+ type: DataTypes.STRING,
16
+ allowNull: false,
17
+ comment: 'Channel identifier'
18
+ },
19
+ style_id: {
20
+ type: DataTypes.STRING,
21
+ allowNull: true,
22
+ comment: 'Style identifier'
23
+ },
24
+ country_code: {
25
+ type: DataTypes.STRING(2),
26
+ allowNull: true,
27
+ comment: 'Country code (ISO 2-letter)'
28
+ },
29
+ custom_query: {
30
+ type: DataTypes.TEXT,
31
+ allowNull: true,
32
+ comment: 'Custom search query'
33
+ },
34
+ query: {
35
+ type: DataTypes.TEXT,
36
+ allowNull: true,
37
+ comment: 'Standard search query'
38
+ },
39
+ funnel_page_views: {
40
+ type: DataTypes.INTEGER,
41
+ allowNull: true,
42
+ defaultValue: 0,
43
+ comment: 'Number of funnel page views'
44
+ },
45
+ funnel_impressions: {
46
+ type: DataTypes.INTEGER,
47
+ allowNull: true,
48
+ defaultValue: 0,
49
+ comment: 'Number of funnel impressions'
50
+ },
51
+ funnel_clicks: {
52
+ type: DataTypes.INTEGER,
53
+ allowNull: true,
54
+ defaultValue: 0,
55
+ comment: 'Number of funnel clicks'
56
+ },
57
+ page_views: {
58
+ type: DataTypes.INTEGER,
59
+ allowNull: true,
60
+ defaultValue: 0,
61
+ comment: 'Number of page views'
62
+ },
63
+ impressions: {
64
+ type: DataTypes.INTEGER,
65
+ allowNull: true,
66
+ defaultValue: 0,
67
+ comment: 'Number of impressions'
68
+ },
69
+ clicks: {
70
+ type: DataTypes.INTEGER,
71
+ allowNull: true,
72
+ defaultValue: 0,
73
+ comment: 'Number of clicks'
74
+ }
75
+ }, {
76
+ tableName: 'rsoc_keyword_performance',
77
+ timestamps: true, // Adds createdAt and updatedAt columns
78
+ indexes: [
79
+ {
80
+ fields: ['channel_id', 'ts'],
81
+ name: 'idx_rsoc_keyword_channel_time'
82
+ },
83
+ {
84
+ fields: ['style_id'],
85
+ name: 'idx_rsoc_keyword_style'
86
+ },
87
+ {
88
+ fields: ['country_code'],
89
+ name: 'idx_rsoc_keyword_country'
90
+ }
91
+ ]
92
+ });
93
+
94
+ // Define associations if needed
95
+ RsocKeywordPerformance.associate = (models) => {
96
+ // Add associations here if your table needs to reference other tables
97
+ // For example:
98
+ // RsocKeywordPerformance.belongsTo(models.Channel, { foreignKey: 'channel_id' });
99
+ };
100
+
101
+ return RsocKeywordPerformance;
102
+ };