agrs-sequelize-sdk 1.1.59 → 1.1.61

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.
package/models/AdSet.js CHANGED
@@ -1,3 +1,147 @@
1
+ // module.exports = (sequelize, DataTypes) => {
2
+ // const AdSet = sequelize.define(
3
+ // "AdSet",
4
+ // {
5
+ // AdSetID: {
6
+ // type: DataTypes.STRING,
7
+ // primaryKey: true,
8
+ // },
9
+ // AdSetName: {
10
+ // type: DataTypes.STRING,
11
+ // allowNull: true,
12
+ // },
13
+ // Status: {
14
+ // type: DataTypes.STRING,
15
+ // allowNull: true,
16
+ // },
17
+ // daily_budget: {
18
+ // type: DataTypes.INTEGER,
19
+ // allowNull: true,
20
+ // },
21
+ // start_time: {
22
+ // type: DataTypes.DATE,
23
+ // allowNull: true,
24
+ // },
25
+ // end_time: {
26
+ // type: DataTypes.DATE,
27
+ // allowNull: true,
28
+ // },
29
+ // targeting: {
30
+ // type: DataTypes.JSONB,
31
+ // allowNull: true,
32
+ // },
33
+ // promotedObject: {
34
+ // type: DataTypes.JSONB, // Storing promoted object as a JSON object
35
+ // allowNull: true,
36
+ // },
37
+ // BillingEvent: {
38
+ // type: DataTypes.STRING,
39
+ // allowNull: false,
40
+ // defaultValue: "impressions", // Default value for BillingEvent
41
+ // },
42
+ // OptimizationGoal: {
43
+ // type: DataTypes.STRING,
44
+ // allowNull: false,
45
+ // defaultValue: "offsite_conversions", // Default value for OptimizationGoal
46
+ // },
47
+ // Draft: {
48
+ // type: DataTypes.BOOLEAN,
49
+ // allowNull: true,
50
+ // defaultValue: false,
51
+ // },
52
+ // UserCreated: {
53
+ // type: DataTypes.STRING,
54
+ // allowNull: true,
55
+ // },
56
+ // publish: {
57
+ // type: DataTypes.BOOLEAN,
58
+ // allowNull: true,
59
+ // defaultValue: true,
60
+ // },
61
+ // CampaignID: {
62
+ // type: DataTypes.STRING,
63
+ // allowNull: false,
64
+ // references: {
65
+ // model: "Campaign",
66
+ // key: "CampaignID",
67
+ // },
68
+ // },
69
+ // effectiveStatus: {
70
+ // type: DataTypes.STRING,
71
+ // allowNull: true,
72
+ // },
73
+ // // add issues_info field
74
+ // issuesInfo: {
75
+ // type: DataTypes.JSONB,
76
+ // allowNull: true,
77
+ // },
78
+ // bid_strategy: {
79
+ // type: DataTypes.STRING,
80
+ // allowNull: true,
81
+ // },
82
+ // // bid amount
83
+ // bid_amount: {
84
+ // type: DataTypes.INTEGER,
85
+ // allowNull: true,
86
+ // },
87
+ // waiting: {
88
+ // type: DataTypes.BOOLEAN,
89
+ // defaultValue: false,
90
+ // },
91
+ // },
92
+ // {
93
+ // tableName: "AdSet",
94
+ // indexes: [
95
+ // {
96
+ // fields: ["CampaignID"], // Index on CampaignID for faster join
97
+ // },
98
+ // ],
99
+ // }
100
+ // );
101
+
102
+ // AdSet.associate = (models) => {
103
+ // AdSet.belongsTo(models.Campaign, { foreignKey: "CampaignID" });
104
+ // AdSet.hasMany(models.Ad, { foreignKey: "AdSetID" });
105
+ // };
106
+
107
+ // AdSet.addHook("beforeUpdate", async (adSet, options) => {
108
+ // if (adSet.changed("publish")) {
109
+ // if (adSet.previous("publish") === true && adSet.publish === false) {
110
+ // // Save current state to AdSetHistory
111
+ // await sequelize.models.AdSetHistory.create({
112
+ // AdSetID: adSet.AdSetID,
113
+ // DataSnapshot: adSet._previousDataValues, // Save the full AdSet data as JSON
114
+ // });
115
+ // } else if (
116
+ // adSet.previous("publish") === false &&
117
+ // adSet.publish === true
118
+ // ) {
119
+ // // Delete the latest history entry
120
+ // const latestHistory = await sequelize.models.AdSetHistory.findOne({
121
+ // where: { AdSetID: adSet.AdSetID },
122
+ // order: [["timestamp", "DESC"]], // Get the latest history entry
123
+ // });
124
+
125
+ // if (latestHistory) {
126
+ // await latestHistory.destroy();
127
+ // }
128
+ // }
129
+ // }
130
+ // });
131
+
132
+ // AdSet.addHook("afterCreate", async (adSet, options) => {
133
+ // if (adSet.publish === false) {
134
+ // // If publish is false on creation, save a snapshot to AdSetHistory
135
+ // await sequelize.models.AdSetHistory.create({
136
+ // AdSetID: adSet.AdSetID,
137
+ // DataSnapshot: adSet.toJSON(), // Save the full AdSet data as JSON
138
+ // });
139
+ // }
140
+ // });
141
+
142
+ // return AdSet;
143
+ // };
144
+
1
145
  module.exports = (sequelize, DataTypes) => {
2
146
  const AdSet = sequelize.define(
3
147
  "AdSet",
@@ -31,18 +175,18 @@ module.exports = (sequelize, DataTypes) => {
31
175
  allowNull: true,
32
176
  },
33
177
  promotedObject: {
34
- type: DataTypes.JSONB, // Storing promoted object as a JSON object
178
+ type: DataTypes.JSONB,
35
179
  allowNull: true,
36
180
  },
37
181
  BillingEvent: {
38
182
  type: DataTypes.STRING,
39
183
  allowNull: false,
40
- defaultValue: "impressions", // Default value for BillingEvent
184
+ defaultValue: "impressions",
41
185
  },
42
186
  OptimizationGoal: {
43
187
  type: DataTypes.STRING,
44
188
  allowNull: false,
45
- defaultValue: "offsite_conversions", // Default value for OptimizationGoal
189
+ defaultValue: "offsite_conversions",
46
190
  },
47
191
  Draft: {
48
192
  type: DataTypes.BOOLEAN,
@@ -70,7 +214,6 @@ module.exports = (sequelize, DataTypes) => {
70
214
  type: DataTypes.STRING,
71
215
  allowNull: true,
72
216
  },
73
- // add issues_info field
74
217
  issuesInfo: {
75
218
  type: DataTypes.JSONB,
76
219
  allowNull: true,
@@ -79,7 +222,6 @@ module.exports = (sequelize, DataTypes) => {
79
222
  type: DataTypes.STRING,
80
223
  allowNull: true,
81
224
  },
82
- // bid amount
83
225
  bid_amount: {
84
226
  type: DataTypes.INTEGER,
85
227
  allowNull: true,
@@ -93,7 +235,7 @@ module.exports = (sequelize, DataTypes) => {
93
235
  tableName: "AdSet",
94
236
  indexes: [
95
237
  {
96
- fields: ["CampaignID"], // Index on CampaignID for faster join
238
+ fields: ["CampaignID"],
97
239
  },
98
240
  ],
99
241
  }
@@ -102,24 +244,24 @@ module.exports = (sequelize, DataTypes) => {
102
244
  AdSet.associate = (models) => {
103
245
  AdSet.belongsTo(models.Campaign, { foreignKey: "CampaignID" });
104
246
  AdSet.hasMany(models.Ad, { foreignKey: "AdSetID" });
247
+ // Add this line to define the relationship with AdSetPerformance
248
+ AdSet.hasMany(models.AdSetPerformance, { foreignKey: "AdSetID" });
105
249
  };
106
250
 
107
251
  AdSet.addHook("beforeUpdate", async (adSet, options) => {
108
252
  if (adSet.changed("publish")) {
109
253
  if (adSet.previous("publish") === true && adSet.publish === false) {
110
- // Save current state to AdSetHistory
111
254
  await sequelize.models.AdSetHistory.create({
112
255
  AdSetID: adSet.AdSetID,
113
- DataSnapshot: adSet._previousDataValues, // Save the full AdSet data as JSON
256
+ DataSnapshot: adSet._previousDataValues,
114
257
  });
115
258
  } else if (
116
259
  adSet.previous("publish") === false &&
117
260
  adSet.publish === true
118
261
  ) {
119
- // Delete the latest history entry
120
262
  const latestHistory = await sequelize.models.AdSetHistory.findOne({
121
263
  where: { AdSetID: adSet.AdSetID },
122
- order: [["timestamp", "DESC"]], // Get the latest history entry
264
+ order: [["timestamp", "DESC"]],
123
265
  });
124
266
 
125
267
  if (latestHistory) {
@@ -131,13 +273,12 @@ module.exports = (sequelize, DataTypes) => {
131
273
 
132
274
  AdSet.addHook("afterCreate", async (adSet, options) => {
133
275
  if (adSet.publish === false) {
134
- // If publish is false on creation, save a snapshot to AdSetHistory
135
276
  await sequelize.models.AdSetHistory.create({
136
277
  AdSetID: adSet.AdSetID,
137
- DataSnapshot: adSet.toJSON(), // Save the full AdSet data as JSON
278
+ DataSnapshot: adSet.toJSON(),
138
279
  });
139
280
  }
140
281
  });
141
-
282
+
142
283
  return AdSet;
143
284
  };
@@ -0,0 +1,106 @@
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
+ },
83
+ {
84
+ tableName: "AdSetPerformance",
85
+ timestamps: false, // No need for createdAt/updatedAt timestamps
86
+ indexes: [
87
+ {
88
+ unique: true,
89
+ fields: ["AdSetID", "Date"],
90
+ // Composite unique index to ensure one record per AdSet per date
91
+ },
92
+ ],
93
+ }
94
+ );
95
+
96
+ // Define associations with other models
97
+ AdSetPerformance.associate = (models) => {
98
+ AdSetPerformance.belongsTo(models.AdSet, {
99
+ foreignKey: "AdSetID",
100
+ targetKey: "AdSetID",
101
+ // Links to the AdSet model for additional AdSet details
102
+ });
103
+ };
104
+
105
+ return AdSetPerformance;
106
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.1.59",
3
+ "version": "1.1.61",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",