agrs-sequelize-sdk 1.2.99 → 1.3.1

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.
Files changed (47) hide show
  1. package/migrations/add-requested-from-dashboard-to-articles.js +17 -17
  2. package/models/AdAccountValues.js +25 -25
  3. package/models/AdHistory.js +30 -30
  4. package/models/AdPerformance.js +94 -94
  5. package/models/AdSet.js +289 -289
  6. package/models/AdSetHistory.js +30 -30
  7. package/models/AdsetPerformance.js +126 -126
  8. package/models/Article.js +190 -190
  9. package/models/AutomationRule.js +161 -127
  10. package/models/Buyers.js +25 -25
  11. package/models/Campaign.js +157 -157
  12. package/models/CampaignActionHistory.js +86 -86
  13. package/models/CampaignCreationLog.js +309 -309
  14. package/models/CampaignHistory.js +33 -33
  15. package/models/Channel.js +55 -55
  16. package/models/Domain.js +25 -25
  17. package/models/DynamicFeed.js +212 -212
  18. package/models/ExplorAdsChannel.js +61 -61
  19. package/models/Feed.js +33 -33
  20. package/models/FrontStoryChannel.js +59 -59
  21. package/models/MineChannel.js +42 -42
  22. package/models/Pages.js +81 -81
  23. package/models/PipelineExecution.js +59 -59
  24. package/models/Presets.js +34 -34
  25. package/models/RSOCFeedCampaign.js +357 -357
  26. package/models/RsocKeywordPerformance.js +110 -110
  27. package/models/RuleAction.js +90 -90
  28. package/models/RuleCondition.js +98 -98
  29. package/models/RuleExecution.js +107 -107
  30. package/models/RulesValues.js +56 -56
  31. package/models/SupportedLocale.js +23 -23
  32. package/models/SyncHistory.js +249 -249
  33. package/models/Tier2_AdAccounts.js +110 -110
  34. package/models/Tier2_Assets.js +70 -70
  35. package/models/Tier2_BusinessManagers.js +105 -105
  36. package/models/Tier2_CreditLines.js +99 -99
  37. package/models/Tier2_Pages.js +91 -91
  38. package/models/Tier2_Pixels.js +82 -82
  39. package/models/Tier2_Tokens.js +64 -64
  40. package/models/Tier2_UserAdAccounts.js +83 -83
  41. package/models/TokenRotationState.js +121 -121
  42. package/models/TonicRSOCKeywordPerformance.js +122 -122
  43. package/models/Vertical.js +25 -25
  44. package/models/newFiles.js +110 -110
  45. package/package.json +19 -21
  46. package/run.sh +214 -214
  47. package/services/sequelizeService.js +63 -63
@@ -1,127 +1,161 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const AutomationRule = sequelize.define(
3
- "AutomationRule",
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
- comment: "Rule name for identification",
14
- },
15
- description: {
16
- type: DataTypes.TEXT,
17
- allowNull: true,
18
- comment: "Optional description of what this rule does",
19
- },
20
- isActive: {
21
- type: DataTypes.BOOLEAN,
22
- defaultValue: true,
23
- allowNull: false,
24
- comment: "Whether the rule is currently active",
25
- },
26
- ruleType: {
27
- type: DataTypes.ENUM("PAUSE", "BUDGET", "BID", "STATUS", "CUSTOM"),
28
- allowNull: true,
29
- comment: "Type of rule - determines the action category",
30
- },
31
- targetLevel: {
32
- type: DataTypes.ENUM("CAMPAIGN", "ADSET", "AD"),
33
- allowNull: true,
34
- comment: "Level at which the rule operates",
35
- },
36
- scheduleType: {
37
- type: DataTypes.ENUM("INTERVAL", "CRON", "MANUAL"),
38
- allowNull: true,
39
- defaultValue: "MANUAL",
40
- comment: "How the rule is triggered",
41
- },
42
- scheduleConfig: {
43
- type: DataTypes.JSONB,
44
- allowNull: true,
45
- comment:
46
- "Schedule configuration (interval minutes, cron expression, etc.)",
47
- },
48
- gcpJobName: {
49
- type: DataTypes.STRING(255),
50
- allowNull: true,
51
- comment: "GCP Cloud Scheduler job name for this rule",
52
- },
53
- lastExecuted: {
54
- type: DataTypes.DATE,
55
- allowNull: true,
56
- comment: "When the rule was last executed",
57
- },
58
- nextExecution: {
59
- type: DataTypes.DATE,
60
- allowNull: true,
61
- comment: "When the rule is scheduled to run next",
62
- },
63
- executionCount: {
64
- type: DataTypes.INTEGER,
65
- defaultValue: 0,
66
- allowNull: false,
67
- comment: "Number of times this rule has been executed",
68
- },
69
- successCount: {
70
- type: DataTypes.INTEGER,
71
- defaultValue: 0,
72
- allowNull: false,
73
- comment: "Number of successful executions",
74
- },
75
- failureCount: {
76
- type: DataTypes.INTEGER,
77
- defaultValue: 0,
78
- allowNull: false,
79
- comment: "Number of failed executions",
80
- },
81
- createdBy: {
82
- type: DataTypes.STRING(255),
83
- allowNull: true,
84
- comment: "User who created this rule",
85
- },
86
- updatedBy: {
87
- type: DataTypes.STRING(255),
88
- allowNull: true,
89
- comment: "User who last updated this rule",
90
- },
91
- mediaBuyer: {
92
- type: DataTypes.STRING(255),
93
- allowNull: true,
94
- comment: "Media buyer assigned to this rule for permissions",
95
- },
96
- },
97
- {
98
- tableName: "AutomationRules", // New table name
99
- timestamps: true,
100
- }
101
- );
102
-
103
- AutomationRule.associate = (models) => {
104
- // A rule has many conditions
105
- AutomationRule.hasMany(models.RuleCondition, {
106
- foreignKey: "ruleId",
107
- as: "conditions",
108
- onDelete: "CASCADE",
109
- });
110
-
111
- // A rule has many actions
112
- AutomationRule.hasMany(models.RuleAction, {
113
- foreignKey: "ruleId",
114
- as: "actions",
115
- onDelete: "CASCADE",
116
- });
117
-
118
- // A rule has many execution logs
119
- AutomationRule.hasMany(models.RuleExecution, {
120
- foreignKey: "ruleId",
121
- as: "executions",
122
- onDelete: "CASCADE",
123
- });
124
- };
125
-
126
- return AutomationRule;
127
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const AutomationRule = sequelize.define(
3
+ "AutomationRule",
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
+ comment: "Rule name for identification",
14
+ },
15
+ description: {
16
+ type: DataTypes.TEXT,
17
+ allowNull: true,
18
+ comment: "Optional description of what this rule does",
19
+ },
20
+ isActive: {
21
+ type: DataTypes.BOOLEAN,
22
+ defaultValue: true,
23
+ allowNull: false,
24
+ comment: "Whether the rule is currently active",
25
+ },
26
+ ruleType: {
27
+ type: DataTypes.ENUM("PAUSE", "BUDGET", "BID", "STATUS", "CUSTOM"),
28
+ allowNull: true,
29
+ comment: "Type of rule - determines the action category",
30
+ },
31
+ targetLevel: {
32
+ type: DataTypes.ENUM("CAMPAIGN", "ADSET", "AD"),
33
+ allowNull: true,
34
+ comment: "Level at which the rule operates",
35
+ },
36
+ scheduleType: {
37
+ type: DataTypes.ENUM("INTERVAL", "CRON", "MANUAL"),
38
+ allowNull: true,
39
+ defaultValue: "MANUAL",
40
+ comment: "How the rule is triggered",
41
+ },
42
+ scheduleConfig: {
43
+ type: DataTypes.JSONB,
44
+ allowNull: true,
45
+ comment:
46
+ "Schedule configuration (interval minutes, cron expression, etc.)",
47
+ },
48
+ gcpJobName: {
49
+ type: DataTypes.STRING(255),
50
+ allowNull: true,
51
+ comment: "GCP Cloud Scheduler job name for this rule",
52
+ },
53
+ lastExecuted: {
54
+ type: DataTypes.DATE,
55
+ allowNull: true,
56
+ comment: "When the rule was last executed",
57
+ },
58
+ nextExecution: {
59
+ type: DataTypes.DATE,
60
+ allowNull: true,
61
+ comment: "When the rule is scheduled to run next",
62
+ },
63
+ executionCount: {
64
+ type: DataTypes.INTEGER,
65
+ defaultValue: 0,
66
+ allowNull: false,
67
+ comment: "Number of times this rule has been executed",
68
+ },
69
+ successCount: {
70
+ type: DataTypes.INTEGER,
71
+ defaultValue: 0,
72
+ allowNull: false,
73
+ comment: "Number of successful executions",
74
+ },
75
+ failureCount: {
76
+ type: DataTypes.INTEGER,
77
+ defaultValue: 0,
78
+ allowNull: false,
79
+ comment: "Number of failed executions",
80
+ },
81
+ createdBy: {
82
+ type: DataTypes.STRING(255),
83
+ allowNull: true,
84
+ comment: "User who created this rule",
85
+ },
86
+ updatedBy: {
87
+ type: DataTypes.STRING(255),
88
+ allowNull: true,
89
+ comment: "User who last updated this rule",
90
+ },
91
+ mediaBuyer: {
92
+ type: DataTypes.STRING(255),
93
+ allowNull: true,
94
+ comment: "Media buyer assigned to this rule for permissions",
95
+ },
96
+ dateRangeType: {
97
+ type: DataTypes.ENUM("LAST_N_DAYS", "CUSTOM_RANGE"),
98
+ allowNull: true,
99
+ defaultValue: "LAST_N_DAYS",
100
+ comment: "Type of date range for rule evaluation",
101
+ },
102
+ dateRangeValue: {
103
+ type: DataTypes.INTEGER,
104
+ allowNull: true,
105
+ defaultValue: 7,
106
+ comment: "Number of days for LAST_N_DAYS type",
107
+ },
108
+ customStartDate: {
109
+ type: DataTypes.DATEONLY,
110
+ allowNull: true,
111
+ comment: "Custom start date for CUSTOM_RANGE type",
112
+ },
113
+ customEndDate: {
114
+ type: DataTypes.DATEONLY,
115
+ allowNull: true,
116
+ comment: "Custom end date for CUSTOM_RANGE type",
117
+ },
118
+ allowedAccounts: {
119
+ type: DataTypes.ARRAY(DataTypes.STRING),
120
+ allowNull: true,
121
+ defaultValue: [],
122
+ comment: "Array of account IDs that this rule can run on",
123
+ },
124
+ allowedMediaBuyers: {
125
+ type: DataTypes.ARRAY(DataTypes.STRING),
126
+ allowNull: true,
127
+ defaultValue: [],
128
+ comment: "Array of media buyer codes that this rule can be assigned to",
129
+ },
130
+ },
131
+ {
132
+ tableName: "AutomationRules", // New table name
133
+ timestamps: true,
134
+ }
135
+ );
136
+
137
+ AutomationRule.associate = (models) => {
138
+ // A rule has many conditions
139
+ AutomationRule.hasMany(models.RuleCondition, {
140
+ foreignKey: "ruleId",
141
+ as: "conditions",
142
+ onDelete: "CASCADE",
143
+ });
144
+
145
+ // A rule has many actions
146
+ AutomationRule.hasMany(models.RuleAction, {
147
+ foreignKey: "ruleId",
148
+ as: "actions",
149
+ onDelete: "CASCADE",
150
+ });
151
+
152
+ // A rule has many execution logs
153
+ AutomationRule.hasMany(models.RuleExecution, {
154
+ foreignKey: "ruleId",
155
+ as: "executions",
156
+ onDelete: "CASCADE",
157
+ });
158
+ };
159
+
160
+ return AutomationRule;
161
+ };
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
  };
@@ -1,157 +1,157 @@
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
- policy_status: {
82
- type: DataTypes.STRING,
83
- allowNull: true,
84
- comment: "Facebook policy status: APPROVED, DENIED, PENDING, etc.",
85
- },
86
- policy_rejection_reason: {
87
- type: DataTypes.TEXT,
88
- allowNull: true,
89
- comment: "Detailed reason for policy rejection",
90
- },
91
- first_spend_date: {
92
- type: DataTypes.DATEONLY,
93
- allowNull: true,
94
- comment:
95
- "First date when campaign had spend > 0 (for accurate days_running calculation)",
96
- },
97
- },
98
- {
99
- tableName: "Campaign",
100
- indexes: [
101
- {
102
- fields: ["AdAccountID"], // Index on AdAccountID for faster joins
103
- },
104
- {
105
- fields: ["first_spend_date"], // Index for days_running calculations
106
- },
107
- {
108
- fields: ["CampaignID", "first_spend_date"], // Composite index for performance queries
109
- },
110
- ],
111
- }
112
- );
113
-
114
- // Define associations
115
- Campaign.associate = (models) => {
116
- Campaign.belongsTo(models.AdAccount, { foreignKey: "AdAccountID" });
117
- Campaign.hasMany(models.AdSet, { foreignKey: "CampaignID" });
118
- };
119
-
120
- // Combined beforeUpdate hook
121
- Campaign.addHook("beforeUpdate", async (campaign, options) => {
122
- if (campaign.changed("publish")) {
123
- if (campaign.previous("publish") === true && campaign.publish === false) {
124
- // Save current state to CampaignHistory
125
- await sequelize.models.CampaignHistory.create({
126
- CampaignID: campaign.CampaignID,
127
- DataSnapshot: campaign._previousDataValues, // Store current state as JSON
128
- });
129
- } else if (
130
- campaign.previous("publish") === false &&
131
- campaign.publish === true
132
- ) {
133
- // Delete the latest history entry
134
- const latestHistory = await sequelize.models.CampaignHistory.findOne({
135
- where: { CampaignID: campaign.CampaignID },
136
- order: [["timestamp", "DESC"]], // Get the latest history entry
137
- });
138
-
139
- if (latestHistory) {
140
- await latestHistory.destroy(); // Delete the latest history entry
141
- }
142
- }
143
- }
144
- });
145
-
146
- Campaign.addHook("afterCreate", async (campaign, options) => {
147
- if (campaign.publish === false) {
148
- // If publish is false on creation, save a snapshot to CampaignHistory
149
- await sequelize.models.CampaignHistory.create({
150
- CampaignID: campaign.CampaignID,
151
- DataSnapshot: campaign.toJSON(), // Save current state
152
- });
153
- }
154
- });
155
-
156
- return Campaign;
157
- };
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
+ policy_status: {
82
+ type: DataTypes.STRING,
83
+ allowNull: true,
84
+ comment: "Facebook policy status: APPROVED, DENIED, PENDING, etc.",
85
+ },
86
+ policy_rejection_reason: {
87
+ type: DataTypes.TEXT,
88
+ allowNull: true,
89
+ comment: "Detailed reason for policy rejection",
90
+ },
91
+ first_spend_date: {
92
+ type: DataTypes.DATEONLY,
93
+ allowNull: true,
94
+ comment:
95
+ "First date when campaign had spend > 0 (for accurate days_running calculation)",
96
+ },
97
+ },
98
+ {
99
+ tableName: "Campaign",
100
+ indexes: [
101
+ {
102
+ fields: ["AdAccountID"], // Index on AdAccountID for faster joins
103
+ },
104
+ {
105
+ fields: ["first_spend_date"], // Index for days_running calculations
106
+ },
107
+ {
108
+ fields: ["CampaignID", "first_spend_date"], // Composite index for performance queries
109
+ },
110
+ ],
111
+ }
112
+ );
113
+
114
+ // Define associations
115
+ Campaign.associate = (models) => {
116
+ Campaign.belongsTo(models.AdAccount, { foreignKey: "AdAccountID" });
117
+ Campaign.hasMany(models.AdSet, { foreignKey: "CampaignID" });
118
+ };
119
+
120
+ // Combined beforeUpdate hook
121
+ Campaign.addHook("beforeUpdate", async (campaign, options) => {
122
+ if (campaign.changed("publish")) {
123
+ if (campaign.previous("publish") === true && campaign.publish === false) {
124
+ // Save current state to CampaignHistory
125
+ await sequelize.models.CampaignHistory.create({
126
+ CampaignID: campaign.CampaignID,
127
+ DataSnapshot: campaign._previousDataValues, // Store current state as JSON
128
+ });
129
+ } else if (
130
+ campaign.previous("publish") === false &&
131
+ campaign.publish === true
132
+ ) {
133
+ // Delete the latest history entry
134
+ const latestHistory = await sequelize.models.CampaignHistory.findOne({
135
+ where: { CampaignID: campaign.CampaignID },
136
+ order: [["timestamp", "DESC"]], // Get the latest history entry
137
+ });
138
+
139
+ if (latestHistory) {
140
+ await latestHistory.destroy(); // Delete the latest history entry
141
+ }
142
+ }
143
+ }
144
+ });
145
+
146
+ Campaign.addHook("afterCreate", async (campaign, options) => {
147
+ if (campaign.publish === false) {
148
+ // If publish is false on creation, save a snapshot to CampaignHistory
149
+ await sequelize.models.CampaignHistory.create({
150
+ CampaignID: campaign.CampaignID,
151
+ DataSnapshot: campaign.toJSON(), // Save current state
152
+ });
153
+ }
154
+ });
155
+
156
+ return Campaign;
157
+ };