agrs-sequelize-sdk 1.2.19 → 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,135 +1,135 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const Campaign = sequelize.define(
3
- "Campaign",
4
- {
5
- CampaignID: {
6
- type: DataTypes.STRING,
7
- primaryKey: true,
8
- },
9
- CampaignName: {
10
- type: DataTypes.STRING,
11
- allowNull: true,
12
- },
13
- pixelId: {
14
- type: DataTypes.STRING,
15
- allowNull: true,
16
- },
17
- customEventType: {
18
- type: DataTypes.STRING,
19
- allowNull: false,
20
- defaultValue: "PURCHASE",
21
- },
22
- objective: {
23
- type: DataTypes.STRING,
24
- allowNull: false,
25
- defaultValue: "OUTCOME_SALES",
26
- },
27
- status: {
28
- type: DataTypes.STRING,
29
- allowNull: true,
30
- },
31
- AdAccountID: {
32
- type: DataTypes.STRING,
33
- allowNull: false,
34
- references: {
35
- model: "AdAccount",
36
- key: "AdAccountID",
37
- },
38
- },
39
- CreatedTime: {
40
- type: DataTypes.DATE,
41
- allowNull: false,
42
- },
43
- CampaignDelivery: {
44
- type: DataTypes.STRING,
45
- allowNull: true,
46
- },
47
- DailyBudget: {
48
- type: DataTypes.INTEGER,
49
- allowNull: true,
50
- },
51
- Draft: {
52
- type: DataTypes.BOOLEAN,
53
- allowNull: true,
54
- defaultValue: false,
55
- },
56
- publish: {
57
- type: DataTypes.BOOLEAN,
58
- allowNull: true,
59
- defaultValue: true,
60
- },
61
- UserCreated: {
62
- type: DataTypes.STRING,
63
- allowNull: true,
64
- },
65
- special_ad_categories: {
66
- type: DataTypes.ARRAY(DataTypes.STRING),
67
- allowNull: true,
68
- },
69
- effectiveStatus: {
70
- type: DataTypes.STRING,
71
- allowNull: true,
72
- },
73
- issuesInfo: {
74
- type: DataTypes.JSONB,
75
- allowNull: true,
76
- },
77
- waiting: {
78
- type: DataTypes.BOOLEAN,
79
- defaultValue: false,
80
- },
81
- },
82
- {
83
- tableName: "Campaign",
84
- indexes: [
85
- {
86
- fields: ["AdAccountID"], // Index on AdAccountID for faster joins
87
- },
88
- ],
89
- }
90
- );
91
-
92
- // Define associations
93
- Campaign.associate = (models) => {
94
- Campaign.belongsTo(models.AdAccount, { foreignKey: "AdAccountID" });
95
- Campaign.hasMany(models.AdSet, { foreignKey: "CampaignID" });
96
- };
97
-
98
- // Combined beforeUpdate hook
99
- Campaign.addHook("beforeUpdate", async (campaign, options) => {
100
- if (campaign.changed("publish")) {
101
- if (campaign.previous("publish") === true && campaign.publish === false) {
102
- // Save current state to CampaignHistory
103
- await sequelize.models.CampaignHistory.create({
104
- CampaignID: campaign.CampaignID,
105
- DataSnapshot: campaign._previousDataValues, // Store current state as JSON
106
- });
107
- } else if (
108
- campaign.previous("publish") === false &&
109
- campaign.publish === true
110
- ) {
111
- // Delete the latest history entry
112
- const latestHistory = await sequelize.models.CampaignHistory.findOne({
113
- where: { CampaignID: campaign.CampaignID },
114
- order: [["timestamp", "DESC"]], // Get the latest history entry
115
- });
116
-
117
- if (latestHistory) {
118
- await latestHistory.destroy(); // Delete the latest history entry
119
- }
120
- }
121
- }
122
- });
123
-
124
- Campaign.addHook("afterCreate", async (campaign, options) => {
125
- if (campaign.publish === false) {
126
- // If publish is false on creation, save a snapshot to CampaignHistory
127
- await sequelize.models.CampaignHistory.create({
128
- CampaignID: campaign.CampaignID,
129
- DataSnapshot: campaign.toJSON(), // Save current state
130
- });
131
- }
132
- });
133
-
134
- return Campaign;
135
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const Campaign = sequelize.define(
3
+ "Campaign",
4
+ {
5
+ CampaignID: {
6
+ type: DataTypes.STRING,
7
+ primaryKey: true,
8
+ },
9
+ CampaignName: {
10
+ type: DataTypes.STRING,
11
+ allowNull: true,
12
+ },
13
+ pixelId: {
14
+ type: DataTypes.STRING,
15
+ allowNull: true,
16
+ },
17
+ customEventType: {
18
+ type: DataTypes.STRING,
19
+ allowNull: false,
20
+ defaultValue: "PURCHASE",
21
+ },
22
+ objective: {
23
+ type: DataTypes.STRING,
24
+ allowNull: false,
25
+ defaultValue: "OUTCOME_SALES",
26
+ },
27
+ status: {
28
+ type: DataTypes.STRING,
29
+ allowNull: true,
30
+ },
31
+ AdAccountID: {
32
+ type: DataTypes.STRING,
33
+ allowNull: false,
34
+ references: {
35
+ model: "AdAccount",
36
+ key: "AdAccountID",
37
+ },
38
+ },
39
+ CreatedTime: {
40
+ type: DataTypes.DATE,
41
+ allowNull: false,
42
+ },
43
+ CampaignDelivery: {
44
+ type: DataTypes.STRING,
45
+ allowNull: true,
46
+ },
47
+ DailyBudget: {
48
+ type: DataTypes.INTEGER,
49
+ allowNull: true,
50
+ },
51
+ Draft: {
52
+ type: DataTypes.BOOLEAN,
53
+ allowNull: true,
54
+ defaultValue: false,
55
+ },
56
+ publish: {
57
+ type: DataTypes.BOOLEAN,
58
+ allowNull: true,
59
+ defaultValue: true,
60
+ },
61
+ UserCreated: {
62
+ type: DataTypes.STRING,
63
+ allowNull: true,
64
+ },
65
+ special_ad_categories: {
66
+ type: DataTypes.ARRAY(DataTypes.STRING),
67
+ allowNull: true,
68
+ },
69
+ effectiveStatus: {
70
+ type: DataTypes.STRING,
71
+ allowNull: true,
72
+ },
73
+ issuesInfo: {
74
+ type: DataTypes.JSONB,
75
+ allowNull: true,
76
+ },
77
+ waiting: {
78
+ type: DataTypes.BOOLEAN,
79
+ defaultValue: false,
80
+ },
81
+ },
82
+ {
83
+ tableName: "Campaign",
84
+ indexes: [
85
+ {
86
+ fields: ["AdAccountID"], // Index on AdAccountID for faster joins
87
+ },
88
+ ],
89
+ }
90
+ );
91
+
92
+ // Define associations
93
+ Campaign.associate = (models) => {
94
+ Campaign.belongsTo(models.AdAccount, { foreignKey: "AdAccountID" });
95
+ Campaign.hasMany(models.AdSet, { foreignKey: "CampaignID" });
96
+ };
97
+
98
+ // Combined beforeUpdate hook
99
+ Campaign.addHook("beforeUpdate", async (campaign, options) => {
100
+ if (campaign.changed("publish")) {
101
+ if (campaign.previous("publish") === true && campaign.publish === false) {
102
+ // Save current state to CampaignHistory
103
+ await sequelize.models.CampaignHistory.create({
104
+ CampaignID: campaign.CampaignID,
105
+ DataSnapshot: campaign._previousDataValues, // Store current state as JSON
106
+ });
107
+ } else if (
108
+ campaign.previous("publish") === false &&
109
+ campaign.publish === true
110
+ ) {
111
+ // Delete the latest history entry
112
+ const latestHistory = await sequelize.models.CampaignHistory.findOne({
113
+ where: { CampaignID: campaign.CampaignID },
114
+ order: [["timestamp", "DESC"]], // Get the latest history entry
115
+ });
116
+
117
+ if (latestHistory) {
118
+ await latestHistory.destroy(); // Delete the latest history entry
119
+ }
120
+ }
121
+ }
122
+ });
123
+
124
+ Campaign.addHook("afterCreate", async (campaign, options) => {
125
+ if (campaign.publish === false) {
126
+ // If publish is false on creation, save a snapshot to CampaignHistory
127
+ await sequelize.models.CampaignHistory.create({
128
+ CampaignID: campaign.CampaignID,
129
+ DataSnapshot: campaign.toJSON(), // Save current state
130
+ });
131
+ }
132
+ });
133
+
134
+ return Campaign;
135
+ };
@@ -1,92 +1,92 @@
1
- // models/CampaignCreationLog.js
2
- module.exports = (sequelize, DataTypes) => {
3
- const CampaignCreationLog = sequelize.define(
4
- "CampaignCreationLog",
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
- country: {
28
- type: DataTypes.STRING,
29
- allowNull: true,
30
- comment: "Country being processed",
31
- },
32
- feed_campaign_id: {
33
- type: DataTypes.STRING,
34
- allowNull: true,
35
- comment: "AGRS_CID of the created feed campaign",
36
- },
37
- facebook_campaign_id: {
38
- type: DataTypes.STRING,
39
- allowNull: true,
40
- comment: "Facebook campaign ID if created",
41
- },
42
- details: {
43
- type: DataTypes.JSONB,
44
- allowNull: true,
45
- comment: "Additional details about the process or results",
46
- },
47
- error_message: {
48
- type: DataTypes.TEXT,
49
- allowNull: true,
50
- comment: "Error message if process failed",
51
- },
52
- },
53
- {
54
- tableName: "CampaignCreationLogs",
55
- timestamps: true,
56
- indexes: [
57
- {
58
- fields: ["process_id"],
59
- },
60
- {
61
- fields: ["status"],
62
- },
63
- {
64
- fields: ["country"],
65
- },
66
- {
67
- fields: ["feed_campaign_id"],
68
- },
69
- {
70
- fields: ["facebook_campaign_id"],
71
- },
72
- {
73
- fields: ["createdAt"],
74
- },
75
- ],
76
- }
77
- );
78
-
79
- CampaignCreationLog.associate = (models) => {
80
- // Add associations if needed
81
- if (models.CodefuelCampaign) {
82
- CampaignCreationLog.belongsTo(models.CodefuelCampaign, {
83
- foreignKey: "feed_campaign_id",
84
- targetKey: "AGRSCID",
85
- as: "FeedCampaign",
86
- constraints: false,
87
- });
88
- }
89
- };
90
-
91
- return CampaignCreationLog;
92
- };
1
+ // models/CampaignCreationLog.js
2
+ module.exports = (sequelize, DataTypes) => {
3
+ const CampaignCreationLog = sequelize.define(
4
+ "CampaignCreationLog",
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
+ country: {
28
+ type: DataTypes.STRING,
29
+ allowNull: true,
30
+ comment: "Country being processed",
31
+ },
32
+ feed_campaign_id: {
33
+ type: DataTypes.STRING,
34
+ allowNull: true,
35
+ comment: "AGRS_CID of the created feed campaign",
36
+ },
37
+ facebook_campaign_id: {
38
+ type: DataTypes.STRING,
39
+ allowNull: true,
40
+ comment: "Facebook campaign ID if created",
41
+ },
42
+ details: {
43
+ type: DataTypes.JSONB,
44
+ allowNull: true,
45
+ comment: "Additional details about the process or results",
46
+ },
47
+ error_message: {
48
+ type: DataTypes.TEXT,
49
+ allowNull: true,
50
+ comment: "Error message if process failed",
51
+ },
52
+ },
53
+ {
54
+ tableName: "CampaignCreationLogs",
55
+ timestamps: true,
56
+ indexes: [
57
+ {
58
+ fields: ["process_id"],
59
+ },
60
+ {
61
+ fields: ["status"],
62
+ },
63
+ {
64
+ fields: ["country"],
65
+ },
66
+ {
67
+ fields: ["feed_campaign_id"],
68
+ },
69
+ {
70
+ fields: ["facebook_campaign_id"],
71
+ },
72
+ {
73
+ fields: ["createdAt"],
74
+ },
75
+ ],
76
+ }
77
+ );
78
+
79
+ CampaignCreationLog.associate = (models) => {
80
+ // Add associations if needed
81
+ if (models.CodefuelCampaign) {
82
+ CampaignCreationLog.belongsTo(models.CodefuelCampaign, {
83
+ foreignKey: "feed_campaign_id",
84
+ targetKey: "AGRSCID",
85
+ as: "FeedCampaign",
86
+ constraints: false,
87
+ });
88
+ }
89
+ };
90
+
91
+ return CampaignCreationLog;
92
+ };
@@ -1,33 +1,33 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const CampaignHistory = sequelize.define(
3
- "CampaignHistory",
4
- {
5
- HistoryID: {
6
- type: DataTypes.UUID,
7
- defaultValue: DataTypes.UUIDV4,
8
- primaryKey: true,
9
- },
10
- CampaignID: {
11
- type: DataTypes.STRING,
12
- allowNull: false,
13
- },
14
- TableName: {
15
- type: DataTypes.STRING, // Useful for multi-table history tracking
16
- defaultValue: "Campaign",
17
- },
18
- DataSnapshot: {
19
- type: DataTypes.JSONB, // Store the entire row as JSON
20
- allowNull: false,
21
- },
22
- timestamp: {
23
- type: DataTypes.DATE,
24
- defaultValue: DataTypes.NOW,
25
- },
26
- },
27
- {
28
- tableName: "CampaignHistory",
29
- }
30
- );
31
-
32
- return CampaignHistory;
33
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const CampaignHistory = sequelize.define(
3
+ "CampaignHistory",
4
+ {
5
+ HistoryID: {
6
+ type: DataTypes.UUID,
7
+ defaultValue: DataTypes.UUIDV4,
8
+ primaryKey: true,
9
+ },
10
+ CampaignID: {
11
+ type: DataTypes.STRING,
12
+ allowNull: false,
13
+ },
14
+ TableName: {
15
+ type: DataTypes.STRING, // Useful for multi-table history tracking
16
+ defaultValue: "Campaign",
17
+ },
18
+ DataSnapshot: {
19
+ type: DataTypes.JSONB, // Store the entire row as JSON
20
+ allowNull: false,
21
+ },
22
+ timestamp: {
23
+ type: DataTypes.DATE,
24
+ defaultValue: DataTypes.NOW,
25
+ },
26
+ },
27
+ {
28
+ tableName: "CampaignHistory",
29
+ }
30
+ );
31
+
32
+ return CampaignHistory;
33
+ };
package/models/Channel.js CHANGED
@@ -1,55 +1,55 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const Channel = sequelize.define(
3
- "Channel",
4
- {
5
- channelId: {
6
- type: DataTypes.STRING,
7
- allowNull: false,
8
- // Not setting as primary key or unique since duplicates are allowed
9
- },
10
- styleId: {
11
- type: DataTypes.STRING,
12
- allowNull: false,
13
- },
14
- status: {
15
- type: DataTypes.STRING,
16
- allowNull: false,
17
- defaultValue: "free",
18
- validate: {
19
- isIn: [["free", "used", "archived"]],
20
- },
21
- },
22
- connectedCampaigns: {
23
- type: DataTypes.JSONB, // Use JSONB for better querying capabilities
24
- allowNull: false,
25
- defaultValue: [],
26
- },
27
- },
28
- {
29
- tableName: "channels",
30
- timestamps: true,
31
- indexes: [
32
- // Add a composite unique index on channelId and styleId if needed
33
- {
34
- unique: true,
35
- fields: ["channelId", "styleId"],
36
- name: "unique_channel_style",
37
- },
38
- ],
39
- }
40
- );
41
-
42
- // Define associations without enforcing constraints
43
- Channel.associate = (models) => {
44
- if (models.RSOCFeedCampaign) {
45
- Channel.hasMany(models.RSOCFeedCampaign, {
46
- foreignKey: "channelId",
47
- sourceKey: "channelId",
48
- as: "RSOCFeedCampaigns",
49
- constraints: false, // Disable FK constraint
50
- });
51
- }
52
- };
53
-
54
- return Channel;
55
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const Channel = sequelize.define(
3
+ "Channel",
4
+ {
5
+ channelId: {
6
+ type: DataTypes.STRING,
7
+ allowNull: false,
8
+ // Not setting as primary key or unique since duplicates are allowed
9
+ },
10
+ styleId: {
11
+ type: DataTypes.STRING,
12
+ allowNull: false,
13
+ },
14
+ status: {
15
+ type: DataTypes.STRING,
16
+ allowNull: false,
17
+ defaultValue: "free",
18
+ validate: {
19
+ isIn: [["free", "used", "archived"]],
20
+ },
21
+ },
22
+ connectedCampaigns: {
23
+ type: DataTypes.JSONB, // Use JSONB for better querying capabilities
24
+ allowNull: false,
25
+ defaultValue: [],
26
+ },
27
+ },
28
+ {
29
+ tableName: "channels",
30
+ timestamps: true,
31
+ indexes: [
32
+ // Add a composite unique index on channelId and styleId if needed
33
+ {
34
+ unique: true,
35
+ fields: ["channelId", "styleId"],
36
+ name: "unique_channel_style",
37
+ },
38
+ ],
39
+ }
40
+ );
41
+
42
+ // Define associations without enforcing constraints
43
+ Channel.associate = (models) => {
44
+ if (models.RSOCFeedCampaign) {
45
+ Channel.hasMany(models.RSOCFeedCampaign, {
46
+ foreignKey: "channelId",
47
+ sourceKey: "channelId",
48
+ as: "RSOCFeedCampaigns",
49
+ constraints: false, // Disable FK constraint
50
+ });
51
+ }
52
+ };
53
+
54
+ return Channel;
55
+ };
package/models/Domain.js CHANGED
@@ -1,26 +1,26 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const Domain = sequelize.define(
3
- "Domain",
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: "Domain",
22
- }
23
- );
24
-
25
- return Domain;
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const Domain = sequelize.define(
3
+ "Domain",
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: "Domain",
22
+ }
23
+ );
24
+
25
+ return Domain;
26
26
  };