agrs-sequelize-sdk 1.2.20 → 1.2.21

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,116 +1,116 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const AdSetPerformance = sequelize.define(
3
- "AdSetPerformance",
4
- {
5
- AdSetID: {
6
- type: DataTypes.STRING,
7
- allowNull: false,
8
- primaryKey: true,
9
- // Part of the composite primary key identifying the AdSet
10
- },
11
- Date: {
12
- type: DataTypes.DATEONLY,
13
- allowNull: false,
14
- primaryKey: true,
15
- // Part of the composite primary key representing the performance date
16
- },
17
- ChannelID: {
18
- type: DataTypes.STRING,
19
- allowNull: true,
20
- // Optional identifier for the channel, extracted from AdSet name if available
21
- },
22
- StyleID: {
23
- type: DataTypes.STRING,
24
- allowNull: true,
25
- // Optional identifier for the style, extracted from AdSet name if available
26
- },
27
- Spend: {
28
- type: DataTypes.FLOAT,
29
- defaultValue: 0,
30
- // Total spend on the AdSet from the source platform (e.g., Facebook)
31
- },
32
- Impressions: {
33
- type: DataTypes.INTEGER,
34
- defaultValue: 0,
35
- // Number of impressions recorded by the source platform
36
- },
37
- LinkClicks: {
38
- type: DataTypes.INTEGER,
39
- defaultValue: 0,
40
- // Number of link clicks recorded by the source platform
41
- },
42
- ViewContent: {
43
- type: DataTypes.INTEGER,
44
- defaultValue: 0,
45
- // Number of view content events recorded by the source platform
46
- },
47
- Search: {
48
- type: DataTypes.INTEGER,
49
- defaultValue: 0,
50
- // Number of search events recorded by the source platform
51
- },
52
- Purchase: {
53
- type: DataTypes.INTEGER,
54
- defaultValue: 0,
55
- // Number of purchase events recorded by the source platform
56
- },
57
- ExternalRevenue: {
58
- type: DataTypes.FLOAT,
59
- defaultValue: 0,
60
- // Revenue data from an external source (e.g., analytics or monetization platforms)
61
- },
62
- ExternalImpressions: {
63
- type: DataTypes.INTEGER,
64
- defaultValue: 0,
65
- // Number of impressions recorded by an external source
66
- },
67
- ExternalClicks: {
68
- type: DataTypes.INTEGER,
69
- defaultValue: 0,
70
- // Number of clicks recorded by an external source
71
- },
72
- ExternalRequests: {
73
- type: DataTypes.INTEGER,
74
- defaultValue: 0,
75
- // Number of requests recorded by an external source
76
- },
77
- ROI: {
78
- type: DataTypes.FLOAT,
79
- defaultValue: 0,
80
- // Calculated Return on Investment (ExternalRevenue / Spend)
81
- },
82
- agrscid: {
83
- type: DataTypes.STRING,
84
- allowNull: true,
85
- // Optional identifier for the AdSet, extracted from AdSet url if available
86
- },
87
- originalRevenue: {
88
- type: DataTypes.FLOAT,
89
- defaultValue: 0,
90
- // Original revenue value before any modifications or calculations
91
- }
92
- },
93
- {
94
- tableName: "AdSetPerformance",
95
- timestamps: false, // No need for createdAt/updatedAt timestamps
96
- indexes: [
97
- {
98
- unique: true,
99
- fields: ["AdSetID", "Date"],
100
- // Composite unique index to ensure one record per AdSet per date
101
- },
102
- ],
103
- }
104
- );
105
-
106
- // Define associations with other models
107
- AdSetPerformance.associate = (models) => {
108
- AdSetPerformance.belongsTo(models.AdSet, {
109
- foreignKey: "AdSetID",
110
- targetKey: "AdSetID",
111
- // Links to the AdSet model for additional AdSet details
112
- });
113
- };
114
-
115
- return AdSetPerformance;
116
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const AdSetPerformance = sequelize.define(
3
+ "AdSetPerformance",
4
+ {
5
+ AdSetID: {
6
+ type: DataTypes.STRING,
7
+ allowNull: false,
8
+ primaryKey: true,
9
+ // Part of the composite primary key identifying the AdSet
10
+ },
11
+ Date: {
12
+ type: DataTypes.DATEONLY,
13
+ allowNull: false,
14
+ primaryKey: true,
15
+ // Part of the composite primary key representing the performance date
16
+ },
17
+ ChannelID: {
18
+ type: DataTypes.STRING,
19
+ allowNull: true,
20
+ // Optional identifier for the channel, extracted from AdSet name if available
21
+ },
22
+ StyleID: {
23
+ type: DataTypes.STRING,
24
+ allowNull: true,
25
+ // Optional identifier for the style, extracted from AdSet name if available
26
+ },
27
+ Spend: {
28
+ type: DataTypes.FLOAT,
29
+ defaultValue: 0,
30
+ // Total spend on the AdSet from the source platform (e.g., Facebook)
31
+ },
32
+ Impressions: {
33
+ type: DataTypes.INTEGER,
34
+ defaultValue: 0,
35
+ // Number of impressions recorded by the source platform
36
+ },
37
+ LinkClicks: {
38
+ type: DataTypes.INTEGER,
39
+ defaultValue: 0,
40
+ // Number of link clicks recorded by the source platform
41
+ },
42
+ ViewContent: {
43
+ type: DataTypes.INTEGER,
44
+ defaultValue: 0,
45
+ // Number of view content events recorded by the source platform
46
+ },
47
+ Search: {
48
+ type: DataTypes.INTEGER,
49
+ defaultValue: 0,
50
+ // Number of search events recorded by the source platform
51
+ },
52
+ Purchase: {
53
+ type: DataTypes.INTEGER,
54
+ defaultValue: 0,
55
+ // Number of purchase events recorded by the source platform
56
+ },
57
+ ExternalRevenue: {
58
+ type: DataTypes.FLOAT,
59
+ defaultValue: 0,
60
+ // Revenue data from an external source (e.g., analytics or monetization platforms)
61
+ },
62
+ ExternalImpressions: {
63
+ type: DataTypes.INTEGER,
64
+ defaultValue: 0,
65
+ // Number of impressions recorded by an external source
66
+ },
67
+ ExternalClicks: {
68
+ type: DataTypes.INTEGER,
69
+ defaultValue: 0,
70
+ // Number of clicks recorded by an external source
71
+ },
72
+ ExternalRequests: {
73
+ type: DataTypes.INTEGER,
74
+ defaultValue: 0,
75
+ // Number of requests recorded by an external source
76
+ },
77
+ ROI: {
78
+ type: DataTypes.FLOAT,
79
+ defaultValue: 0,
80
+ // Calculated Return on Investment (ExternalRevenue / Spend)
81
+ },
82
+ agrscid: {
83
+ type: DataTypes.STRING,
84
+ allowNull: true,
85
+ // Optional identifier for the AdSet, extracted from AdSet url if available
86
+ },
87
+ originalRevenue: {
88
+ type: DataTypes.FLOAT,
89
+ defaultValue: 0,
90
+ // Original revenue value before any modifications or calculations
91
+ }
92
+ },
93
+ {
94
+ tableName: "AdSetPerformance",
95
+ timestamps: false, // No need for createdAt/updatedAt timestamps
96
+ indexes: [
97
+ {
98
+ unique: true,
99
+ fields: ["AdSetID", "Date"],
100
+ // Composite unique index to ensure one record per AdSet per date
101
+ },
102
+ ],
103
+ }
104
+ );
105
+
106
+ // Define associations with other models
107
+ AdSetPerformance.associate = (models) => {
108
+ AdSetPerformance.belongsTo(models.AdSet, {
109
+ foreignKey: "AdSetID",
110
+ targetKey: "AdSetID",
111
+ // Links to the AdSet model for additional AdSet details
112
+ });
113
+ };
114
+
115
+ return AdSetPerformance;
116
+ };
package/models/Article.js CHANGED
@@ -1,156 +1,187 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const Article = sequelize.define(
3
- "Article",
4
- {
5
- providerId: {
6
- type: DataTypes.STRING,
7
- allowNull: true,
8
- unique: true,
9
- },
10
- category: {
11
- type: DataTypes.STRING,
12
- allowNull: true,
13
- },
14
- AGRSAID: {
15
- type: DataTypes.STRING,
16
- allowNull: false,
17
- unique: true,
18
- },
19
- articleUrl: {
20
- type: DataTypes.STRING(1024),
21
- allowNull: true,
22
- },
23
- feed: {
24
- type: DataTypes.STRING,
25
- allowNull: false,
26
- },
27
- feedName: {
28
- type: DataTypes.STRING,
29
- allowNull: false,
30
- },
31
- vertical: {
32
- type: DataTypes.STRING,
33
- allowNull: false,
34
- },
35
- language: {
36
- type: DataTypes.STRING,
37
- allowNull: false,
38
- defaultValue: "en",
39
- },
40
- headline: {
41
- type: DataTypes.STRING,
42
- allowNull: true,
43
- },
44
- topics: {
45
- type: DataTypes.ARRAY(DataTypes.STRING),
46
- allowNull: true,
47
- },
48
- mainKeyword: {
49
- type: DataTypes.STRING,
50
- allowNull: true,
51
- },
52
- keywords: {
53
- type: DataTypes.ARRAY(DataTypes.STRING),
54
- allowNull: true,
55
- },
56
- date: {
57
- type: DataTypes.DATE,
58
- allowNull: true,
59
- defaultValue: DataTypes.NOW,
60
- },
61
- nativeKeyword: {
62
- type: DataTypes.STRING,
63
- allowNull: false,
64
- },
65
- suggestedKeywords: {
66
- type: DataTypes.STRING,
67
- allowNull: true,
68
- },
69
- articleExcerpt: {
70
- type: DataTypes.TEXT,
71
- allowNull: true,
72
- },
73
- articleContent: {
74
- type: DataTypes.TEXT,
75
- allowNull: true,
76
- },
77
- fbPixelId: {
78
- type: DataTypes.STRING,
79
- allowNull: true,
80
- },
81
- status: {
82
- type: DataTypes.STRING,
83
- allowNull: false,
84
- defaultValue: "pending",
85
- validate: {
86
- isIn: [
87
- [
88
- "pending",
89
- "approved",
90
- "rejected",
91
- "disapproved",
92
- "duplicated",
93
- "keyword_already_exists",
94
- "invalid_vertical",
95
- "invalid_language",
96
- "in_review",
97
- "error",
98
- ],
99
- ],
100
- },
101
- },
102
- originalStatus: {
103
- type: DataTypes.STRING,
104
- allowNull: true,
105
- comment: "Original status from Predicto before any mapping",
106
- },
107
- creationType: {
108
- type: DataTypes.STRING,
109
- allowNull: false,
110
- defaultValue: "slug",
111
- validate: {
112
- isIn: [["search", "slug"]],
113
- },
114
- },
115
- createdAt: {
116
- type: DataTypes.DATE,
117
- defaultValue: DataTypes.NOW,
118
- },
119
- updatedAt: {
120
- type: DataTypes.DATE,
121
- defaultValue: DataTypes.NOW,
122
- },
123
- buyer: {
124
- type: DataTypes.STRING,
125
- allowNull: true,
126
- },
127
- country: {
128
- type: DataTypes.STRING,
129
- allowNull: true,
130
- },
131
- name: {
132
- type: DataTypes.STRING,
133
- allowNull: true,
134
- },
135
- },
136
- {
137
- tableName: "articles",
138
- timestamps: true,
139
- }
140
- );
141
-
142
- Article.associate = (models) => {
143
- Article.hasMany(models.RSOCFeedCampaign, {
144
- foreignKey: "AGRSAID",
145
- sourceKey: "AGRSAID",
146
- as: "RSOCFeedCampaigns",
147
- constraints: false,
148
- });
149
- };
150
-
151
- Article.prototype.isAvailableForCampaign = function () {
152
- return ["approved", "keyword_already_exists"].includes(this.status);
153
- };
154
-
155
- return Article;
156
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const Article = sequelize.define(
3
+ "Article",
4
+ {
5
+ providerId: {
6
+ type: DataTypes.STRING,
7
+ allowNull: true,
8
+ unique: true,
9
+ },
10
+ category: {
11
+ type: DataTypes.STRING,
12
+ allowNull: true,
13
+ },
14
+ AGRSAID: {
15
+ type: DataTypes.STRING,
16
+ allowNull: false,
17
+ unique: true,
18
+ },
19
+ articleUrl: {
20
+ type: DataTypes.STRING(1024),
21
+ allowNull: true,
22
+ },
23
+ feed: {
24
+ type: DataTypes.STRING,
25
+ allowNull: false,
26
+ },
27
+ feedName: {
28
+ type: DataTypes.STRING,
29
+ allowNull: false,
30
+ },
31
+ vertical: {
32
+ type: DataTypes.STRING,
33
+ allowNull: false,
34
+ },
35
+ language: {
36
+ type: DataTypes.STRING,
37
+ allowNull: false,
38
+ defaultValue: "en",
39
+ },
40
+ headline: {
41
+ type: DataTypes.STRING,
42
+ allowNull: true,
43
+ },
44
+ topics: {
45
+ type: DataTypes.ARRAY(DataTypes.STRING),
46
+ allowNull: true,
47
+ },
48
+ mainKeyword: {
49
+ type: DataTypes.STRING,
50
+ allowNull: true,
51
+ },
52
+ keywords: {
53
+ type: DataTypes.ARRAY(DataTypes.STRING),
54
+ allowNull: true,
55
+ },
56
+ date: {
57
+ type: DataTypes.DATE,
58
+ allowNull: true,
59
+ defaultValue: DataTypes.NOW,
60
+ },
61
+ nativeKeyword: {
62
+ type: DataTypes.STRING,
63
+ allowNull: false,
64
+ },
65
+ suggestedKeywords: {
66
+ type: DataTypes.STRING,
67
+ allowNull: true,
68
+ },
69
+ articleExcerpt: {
70
+ type: DataTypes.TEXT,
71
+ allowNull: true,
72
+ },
73
+ articleContent: {
74
+ type: DataTypes.TEXT,
75
+ allowNull: true,
76
+ },
77
+ fbPixelId: {
78
+ type: DataTypes.STRING,
79
+ allowNull: true,
80
+ },
81
+ status: {
82
+ type: DataTypes.STRING,
83
+ allowNull: false,
84
+ defaultValue: "pending",
85
+ validate: {
86
+ isIn: [
87
+ [
88
+ "pending",
89
+ "approved",
90
+ "rejected",
91
+ "disapproved",
92
+ "duplicated",
93
+ "keyword_already_exists",
94
+ "invalid_vertical",
95
+ "invalid_language",
96
+ "in_review",
97
+ "error",
98
+ ],
99
+ ],
100
+ },
101
+ },
102
+ originalStatus: {
103
+ type: DataTypes.STRING,
104
+ allowNull: true,
105
+ comment: "Original status from Predicto before any mapping",
106
+ },
107
+ creationType: {
108
+ type: DataTypes.STRING,
109
+ allowNull: false,
110
+ defaultValue: "slug",
111
+ validate: {
112
+ isIn: [["search", "slug"]],
113
+ },
114
+ },
115
+ createdAt: {
116
+ type: DataTypes.DATE,
117
+ defaultValue: DataTypes.NOW,
118
+ },
119
+ updatedAt: {
120
+ type: DataTypes.DATE,
121
+ defaultValue: DataTypes.NOW,
122
+ },
123
+ buyer: {
124
+ type: DataTypes.STRING,
125
+ allowNull: true,
126
+ },
127
+ country: {
128
+ type: DataTypes.STRING,
129
+ allowNull: true,
130
+ },
131
+ // NEW FIELDS FOR DOMAIN MIGRATION
132
+ target_domain: {
133
+ type: DataTypes.STRING(100),
134
+ allowNull: false,
135
+ defaultValue: "searchlabz.com",
136
+ comment:
137
+ "Target domain for the article URL (searchlabz.com or sportfoy.com)",
138
+ validate: {
139
+ isIn: [["searchlabz.com", "sportfoy.com"]],
140
+ },
141
+ },
142
+ url_structure: {
143
+ type: DataTypes.ENUM("legacy", "unified"),
144
+ allowNull: false,
145
+ defaultValue: "legacy",
146
+ comment:
147
+ "URL structure type: legacy (slug-based) or unified (search-based)",
148
+ },
149
+ name: {
150
+ type: DataTypes.STRING,
151
+ allowNull: true,
152
+ },
153
+ },
154
+ {
155
+ tableName: "articles",
156
+ timestamps: true,
157
+ }
158
+ );
159
+
160
+ Article.associate = (models) => {
161
+ Article.hasMany(models.RSOCFeedCampaign, {
162
+ foreignKey: "AGRSAID",
163
+ sourceKey: "AGRSAID",
164
+ as: "RSOCFeedCampaigns",
165
+ constraints: false,
166
+ });
167
+ };
168
+
169
+ Article.prototype.isAvailableForCampaign = function () {
170
+ return ["approved", "keyword_already_exists"].includes(this.status);
171
+ };
172
+
173
+ // NEW METHODS FOR URL STRUCTURE HANDLING
174
+ Article.prototype.isUnifiedStructure = function () {
175
+ return this.url_structure === "unified";
176
+ };
177
+
178
+ Article.prototype.getTargetDomain = function () {
179
+ return this.target_domain || "searchlabz.com";
180
+ };
181
+
182
+ Article.prototype.isLegacyStructure = function () {
183
+ return this.url_structure === "legacy";
184
+ };
185
+
186
+ return Article;
187
+ };
package/models/Buyers.js CHANGED
@@ -1,26 +1,26 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const Buyers = sequelize.define(
3
- "Buyers",
4
- {
5
- id: {
6
- type: DataTypes.UUID,
7
- defaultValue: DataTypes.UUIDV4,
8
- primaryKey: true,
9
- },
10
- name: {
11
- type: DataTypes.STRING,
12
- allowNull: false,
13
- },
14
- code: {
15
- type: DataTypes.STRING,
16
- allowNull: false,
17
- unique: true,
18
- },
19
- },
20
- {
21
- tableName: "Buyers",
22
- }
23
- );
24
-
25
- return Buyers;
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const Buyers = sequelize.define(
3
+ "Buyers",
4
+ {
5
+ id: {
6
+ type: DataTypes.UUID,
7
+ defaultValue: DataTypes.UUIDV4,
8
+ primaryKey: true,
9
+ },
10
+ name: {
11
+ type: DataTypes.STRING,
12
+ allowNull: false,
13
+ },
14
+ code: {
15
+ type: DataTypes.STRING,
16
+ allowNull: false,
17
+ unique: true,
18
+ },
19
+ },
20
+ {
21
+ tableName: "Buyers",
22
+ }
23
+ );
24
+
25
+ return Buyers;
26
26
  };