agrs-sequelize-sdk 1.4.52 → 1.4.53

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 (116) hide show
  1. package/migrations/2026-05-17-PIXELS-FOLLOWUP.md +85 -85
  2. package/migrations/2026-05-17-add-platform-to-ad.js +19 -19
  3. package/migrations/2026-05-17-add-platform-to-adaccount.js +19 -19
  4. package/migrations/2026-05-17-add-platform-to-adperformance.js +19 -19
  5. package/migrations/2026-05-17-add-platform-to-adset.js +19 -19
  6. package/migrations/2026-05-17-add-platform-to-adsetperformance.js +19 -19
  7. package/migrations/2026-05-17-add-platform-to-aiarticleretryqueue.js +19 -19
  8. package/migrations/2026-05-17-add-platform-to-aicampaignqueue.js +19 -19
  9. package/migrations/2026-05-17-add-platform-to-article.js +19 -19
  10. package/migrations/2026-05-17-add-platform-to-campaign.js +19 -19
  11. package/migrations/2026-05-17-add-platform-to-codefuelcampaign.js +19 -19
  12. package/migrations/2026-05-17-add-platform-to-dynamicfeed.js +19 -19
  13. package/migrations/2026-05-17-add-platform-to-facebookretryqueue.js +19 -19
  14. package/migrations/2026-05-17-add-platform-to-pages.js +19 -19
  15. package/migrations/2026-05-17-add-platform-to-presets.js +19 -19
  16. package/migrations/2026-05-18-add-group-id-to-ai-campaign-queue.js +18 -18
  17. package/migrations/2026-05-18-add-platform-code-to-creation-logs.js +65 -65
  18. package/migrations/2026-05-18-add-platform-code-to-pixels.js +55 -55
  19. package/migrations/2026-05-18-add-platform-code-to-rsoc-feed-campaigns.js +55 -55
  20. package/migrations/2026-05-18-add-platform-date-index-to-adperformance.js +16 -16
  21. package/migrations/2026-05-18-add-platform-date-index-to-adsetperformance.js +16 -16
  22. package/migrations/2026-05-18-add-review-status-to-ad.js +36 -36
  23. package/migrations/2026-05-18-create-canonical-insights.js +84 -84
  24. package/migrations/2026-05-18-create-snapchat-public-profiles.js +68 -68
  25. package/migrations/2026-05-18-create-tiktok-identities.js +71 -71
  26. package/migrations/2026-05-18-create-tiktok-snapchat-campaigns.js +143 -143
  27. package/migrations/2026-05-18-create-tt-snp-adset-ad-tables.js +309 -309
  28. package/migrations/RUN_ME_MANUALLY_2026-05-17.sql +99 -99
  29. package/migrations/add-requested-from-dashboard-to-articles.js +17 -17
  30. package/migrations/change-adset-name-to-text.js +79 -79
  31. package/models/AICampaignQueue.js +152 -152
  32. package/models/AIGenerationLog.js +85 -85
  33. package/models/AIGenerationRequest.js +212 -212
  34. package/models/AdAccountValues.js +25 -25
  35. package/models/AdHistory.js +30 -30
  36. package/models/AdPerformance.js +104 -104
  37. package/models/AdSet.js +295 -295
  38. package/models/AdSetHistory.js +30 -30
  39. package/models/AdsetPerformance.js +137 -137
  40. package/models/AiArticleRetryQueue.js +157 -157
  41. package/models/AiCreationRetryQueue.js +134 -134
  42. package/models/ApiAuditLog.js +127 -127
  43. package/models/ApiToken.js +67 -67
  44. package/models/Article.js +222 -222
  45. package/models/AutomationRule.js +179 -179
  46. package/models/BannerTemplate.js +129 -129
  47. package/models/Buyers.js +25 -25
  48. package/models/Campaign.js +168 -163
  49. package/models/CampaignActionHistory.js +101 -101
  50. package/models/CampaignCreationLog.js +340 -340
  51. package/models/CampaignCreationLogV2.js +392 -392
  52. package/models/CampaignHistory.js +33 -33
  53. package/models/CampaignTag.js +46 -0
  54. package/models/CampaignTagAssignment.js +48 -0
  55. package/models/CanonicalInsights.js +68 -68
  56. package/models/Channel.js +55 -55
  57. package/models/Domain.js +44 -44
  58. package/models/DynamicFeed.js +218 -218
  59. package/models/ExplorAdsChannel.js +61 -61
  60. package/models/FacebookRetryQueue.js +163 -163
  61. package/models/Feed.js +33 -33
  62. package/models/FeedArticleConfiguration.js +80 -80
  63. package/models/FrontStoryChannel.js +59 -59
  64. package/models/FrontStoryChannelV2.js +60 -60
  65. package/models/GenericFlowRequest.js +114 -114
  66. package/models/MidoWebChannel.js +47 -47
  67. package/models/MineBrandBlocklist.js +40 -40
  68. package/models/MineChannel.js +42 -42
  69. package/models/MineRedirectDomain.js +36 -36
  70. package/models/MineWebhookEvent.js +53 -53
  71. package/models/Pages.js +117 -117
  72. package/models/PipelineExecution.js +59 -59
  73. package/models/PolicyDogsCreativeCache.js +50 -50
  74. package/models/PolicyDogsImageCache.js +30 -30
  75. package/models/Presets.js +40 -40
  76. package/models/PublicApiBatch.js +155 -155
  77. package/models/PublicApiBatchItem.js +166 -166
  78. package/models/PublicApiIdempotencyCache.js +135 -135
  79. package/models/RSOCFeedCampaign.js +387 -387
  80. package/models/RsocKeywordPerformance.js +110 -110
  81. package/models/RuleAction.js +90 -90
  82. package/models/RuleCondition.js +137 -137
  83. package/models/RuleExecution.js +107 -107
  84. package/models/RulesValues.js +56 -56
  85. package/models/SingularChannel.js +31 -31
  86. package/models/SnapchatAd.js +69 -69
  87. package/models/SnapchatAdSquad.js +92 -92
  88. package/models/SnapchatCampaign.js +69 -69
  89. package/models/SnapchatChannel.js +31 -31
  90. package/models/SnapchatPublicProfiles.js +67 -67
  91. package/models/SupportedLocale.js +23 -23
  92. package/models/SyncHistory.js +249 -249
  93. package/models/TTQChannel.js +42 -42
  94. package/models/TemplateMetadata.js +260 -260
  95. package/models/Tier2_AdAccounts.js +110 -110
  96. package/models/Tier2_Assets.js +70 -70
  97. package/models/Tier2_BusinessManagers.js +105 -105
  98. package/models/Tier2_CreditLines.js +99 -99
  99. package/models/Tier2_Pages.js +91 -91
  100. package/models/Tier2_Pixels.js +82 -82
  101. package/models/Tier2_Tokens.js +64 -64
  102. package/models/Tier2_UserAdAccounts.js +83 -83
  103. package/models/TikTokAd.js +71 -71
  104. package/models/TikTokAdGroup.js +82 -82
  105. package/models/TikTokCampaign.js +71 -71
  106. package/models/TiktokChannel.js +31 -31
  107. package/models/TiktokIdentities.js +65 -65
  108. package/models/TokenRotationState.js +121 -121
  109. package/models/TonicRSOCKeywordPerformance.js +122 -122
  110. package/models/Users.js +190 -185
  111. package/models/Vertical.js +25 -25
  112. package/models/newFiles.js +137 -137
  113. package/package.json +21 -19
  114. package/run.sh +214 -214
  115. package/services/sequelizeService.js +110 -110
  116. package/tarzo-skalio-integration-docs.md +691 -691
@@ -1,134 +1,134 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const AiCreationRetryQueue = sequelize.define(
3
- "AiCreationRetryQueue",
4
- {
5
- id: {
6
- type: DataTypes.INTEGER,
7
- primaryKey: true,
8
- autoIncrement: true,
9
- },
10
- agrs_cid: {
11
- type: DataTypes.STRING(255),
12
- allowNull: false,
13
- field: "agrs_cid",
14
- comment: "AGRS Campaign ID (links to the campaign combo)",
15
- },
16
- process_id: {
17
- type: DataTypes.STRING(255),
18
- allowNull: true,
19
- field: "process_id",
20
- comment: "Root process_id from createAICampaign",
21
- },
22
- controller_process_id: {
23
- type: DataTypes.UUID,
24
- allowNull: true,
25
- field: "controller_process_id",
26
- comment: "Per-combination process_id (for CampaignCreationLog)",
27
- },
28
- feed_provider: {
29
- type: DataTypes.STRING(100),
30
- allowNull: false,
31
- field: "feed_provider",
32
- comment: "Normalized feed name: Mine - RSOC, Predicto - RSOC, etc.",
33
- },
34
- failed_step: {
35
- type: DataTypes.STRING(50),
36
- allowNull: false,
37
- field: "failed_step",
38
- comment:
39
- "Step that failed: keywords, texts, banners, fb_creation, rabbitmq_publish",
40
- },
41
- original_payload: {
42
- type: DataTypes.JSONB,
43
- allowNull: false,
44
- field: "original_payload",
45
- comment: "Full combination payload for retry",
46
- },
47
- generated_assets: {
48
- type: DataTypes.JSONB,
49
- allowNull: true,
50
- defaultValue: {},
51
- field: "generated_assets",
52
- comment:
53
- "Assets generated before failure: { keywords, headlines, primaryTexts, bannerFiles }",
54
- },
55
- campaign_context: {
56
- type: DataTypes.JSONB,
57
- allowNull: true,
58
- defaultValue: {},
59
- field: "campaign_context",
60
- comment:
61
- "Additional context needed to resume campaign flow after retry",
62
- },
63
- status: {
64
- type: DataTypes.STRING(50),
65
- allowNull: false,
66
- defaultValue: "pending",
67
- validate: {
68
- isIn: [["pending", "processing", "completed", "failed", "abandoned"]],
69
- },
70
- },
71
- retry_count: {
72
- type: DataTypes.INTEGER,
73
- allowNull: false,
74
- defaultValue: 0,
75
- field: "retry_count",
76
- },
77
- max_retries: {
78
- type: DataTypes.INTEGER,
79
- allowNull: false,
80
- defaultValue: 5,
81
- field: "max_retries",
82
- },
83
- next_retry_at: {
84
- type: DataTypes.DATE,
85
- allowNull: false,
86
- field: "next_retry_at",
87
- comment: "When the next retry should be attempted",
88
- },
89
- last_error: {
90
- type: DataTypes.TEXT,
91
- allowNull: true,
92
- field: "last_error",
93
- },
94
- last_attempt_at: {
95
- type: DataTypes.DATE,
96
- allowNull: true,
97
- field: "last_attempt_at",
98
- },
99
- completed_at: {
100
- type: DataTypes.DATE,
101
- allowNull: true,
102
- field: "completed_at",
103
- },
104
- platform: {
105
- type: DataTypes.ENUM("fb", "tt", "snp"),
106
- allowNull: false,
107
- defaultValue: "fb",
108
- field: "platform",
109
- comment: "Ad platform: fb|tt|snp",
110
- },
111
- },
112
- {
113
- tableName: "ai_creation_retry_queue",
114
- timestamps: true,
115
- underscored: true,
116
- indexes: [
117
- {
118
- fields: ["status", "next_retry_at"],
119
- name: "idx_creation_retry_status_next",
120
- },
121
- {
122
- fields: ["agrs_cid"],
123
- name: "idx_creation_retry_agrs_cid",
124
- },
125
- ],
126
- }
127
- );
128
-
129
- AiCreationRetryQueue.associate = (models) => {
130
- // No associations needed for now
131
- };
132
-
133
- return AiCreationRetryQueue;
134
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const AiCreationRetryQueue = sequelize.define(
3
+ "AiCreationRetryQueue",
4
+ {
5
+ id: {
6
+ type: DataTypes.INTEGER,
7
+ primaryKey: true,
8
+ autoIncrement: true,
9
+ },
10
+ agrs_cid: {
11
+ type: DataTypes.STRING(255),
12
+ allowNull: false,
13
+ field: "agrs_cid",
14
+ comment: "AGRS Campaign ID (links to the campaign combo)",
15
+ },
16
+ process_id: {
17
+ type: DataTypes.STRING(255),
18
+ allowNull: true,
19
+ field: "process_id",
20
+ comment: "Root process_id from createAICampaign",
21
+ },
22
+ controller_process_id: {
23
+ type: DataTypes.UUID,
24
+ allowNull: true,
25
+ field: "controller_process_id",
26
+ comment: "Per-combination process_id (for CampaignCreationLog)",
27
+ },
28
+ feed_provider: {
29
+ type: DataTypes.STRING(100),
30
+ allowNull: false,
31
+ field: "feed_provider",
32
+ comment: "Normalized feed name: Mine - RSOC, Predicto - RSOC, etc.",
33
+ },
34
+ failed_step: {
35
+ type: DataTypes.STRING(50),
36
+ allowNull: false,
37
+ field: "failed_step",
38
+ comment:
39
+ "Step that failed: keywords, texts, banners, fb_creation, rabbitmq_publish",
40
+ },
41
+ original_payload: {
42
+ type: DataTypes.JSONB,
43
+ allowNull: false,
44
+ field: "original_payload",
45
+ comment: "Full combination payload for retry",
46
+ },
47
+ generated_assets: {
48
+ type: DataTypes.JSONB,
49
+ allowNull: true,
50
+ defaultValue: {},
51
+ field: "generated_assets",
52
+ comment:
53
+ "Assets generated before failure: { keywords, headlines, primaryTexts, bannerFiles }",
54
+ },
55
+ campaign_context: {
56
+ type: DataTypes.JSONB,
57
+ allowNull: true,
58
+ defaultValue: {},
59
+ field: "campaign_context",
60
+ comment:
61
+ "Additional context needed to resume campaign flow after retry",
62
+ },
63
+ status: {
64
+ type: DataTypes.STRING(50),
65
+ allowNull: false,
66
+ defaultValue: "pending",
67
+ validate: {
68
+ isIn: [["pending", "processing", "completed", "failed", "abandoned"]],
69
+ },
70
+ },
71
+ retry_count: {
72
+ type: DataTypes.INTEGER,
73
+ allowNull: false,
74
+ defaultValue: 0,
75
+ field: "retry_count",
76
+ },
77
+ max_retries: {
78
+ type: DataTypes.INTEGER,
79
+ allowNull: false,
80
+ defaultValue: 5,
81
+ field: "max_retries",
82
+ },
83
+ next_retry_at: {
84
+ type: DataTypes.DATE,
85
+ allowNull: false,
86
+ field: "next_retry_at",
87
+ comment: "When the next retry should be attempted",
88
+ },
89
+ last_error: {
90
+ type: DataTypes.TEXT,
91
+ allowNull: true,
92
+ field: "last_error",
93
+ },
94
+ last_attempt_at: {
95
+ type: DataTypes.DATE,
96
+ allowNull: true,
97
+ field: "last_attempt_at",
98
+ },
99
+ completed_at: {
100
+ type: DataTypes.DATE,
101
+ allowNull: true,
102
+ field: "completed_at",
103
+ },
104
+ platform: {
105
+ type: DataTypes.ENUM("fb", "tt", "snp"),
106
+ allowNull: false,
107
+ defaultValue: "fb",
108
+ field: "platform",
109
+ comment: "Ad platform: fb|tt|snp",
110
+ },
111
+ },
112
+ {
113
+ tableName: "ai_creation_retry_queue",
114
+ timestamps: true,
115
+ underscored: true,
116
+ indexes: [
117
+ {
118
+ fields: ["status", "next_retry_at"],
119
+ name: "idx_creation_retry_status_next",
120
+ },
121
+ {
122
+ fields: ["agrs_cid"],
123
+ name: "idx_creation_retry_agrs_cid",
124
+ },
125
+ ],
126
+ }
127
+ );
128
+
129
+ AiCreationRetryQueue.associate = (models) => {
130
+ // No associations needed for now
131
+ };
132
+
133
+ return AiCreationRetryQueue;
134
+ };
@@ -1,127 +1,127 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const ApiAuditLog = sequelize.define(
3
- "ApiAuditLog",
4
- {
5
- id: {
6
- type: DataTypes.UUID,
7
- defaultValue: DataTypes.UUIDV4,
8
- primaryKey: true,
9
- },
10
- user_id: {
11
- type: DataTypes.UUID,
12
- allowNull: false,
13
- references: {
14
- model: "Users",
15
- key: "id",
16
- },
17
- },
18
- token_id: {
19
- type: DataTypes.UUID,
20
- allowNull: true,
21
- references: {
22
- model: "ApiToken",
23
- key: "id",
24
- },
25
- },
26
- ts: {
27
- type: DataTypes.DATE,
28
- allowNull: false,
29
- defaultValue: DataTypes.NOW,
30
- },
31
- method: {
32
- type: DataTypes.STRING(10),
33
- allowNull: false,
34
- },
35
- path: {
36
- type: DataTypes.STRING,
37
- allowNull: false,
38
- },
39
- status_code: {
40
- type: DataTypes.INTEGER,
41
- allowNull: false,
42
- },
43
- ip: {
44
- type: DataTypes.STRING,
45
- allowNull: true,
46
- },
47
- resource_type: {
48
- type: DataTypes.STRING,
49
- allowNull: true,
50
- },
51
- resource_id: {
52
- type: DataTypes.STRING,
53
- allowNull: true,
54
- },
55
- payload_diff: {
56
- type: DataTypes.JSONB,
57
- allowNull: true,
58
- },
59
- dry_run: {
60
- type: DataTypes.BOOLEAN,
61
- allowNull: false,
62
- defaultValue: false,
63
- },
64
- // Client-supplied or middleware-minted X-Request-Id. Enables 1:1
65
- // joins to app logs, Cloud Run traces, CampaignCreationLogsV2, and
66
- // most importantly ends body_hash+30s guessing when clustering
67
- // retries (the exact gap that made the 7/9 triage so slow).
68
- // Nullable so the ALTER stays metadata-only on the existing rows.
69
- request_id: {
70
- type: DataTypes.STRING(64),
71
- allowNull: true,
72
- },
73
- // End-to-end request duration in milliseconds, computed as
74
- // Date.now() - startedAt in the res.on('finish' | 'close')
75
- // handler. Replaces the imprecise (createdAt - ts) subtraction we
76
- // fell back to during the 7/9 investigation. Nullable because old
77
- // rows have no measurement — filling those with (createdAt - ts)
78
- // would reproduce the exact signal we're trying to leave behind.
79
- duration_ms: {
80
- type: DataTypes.INTEGER,
81
- allowNull: true,
82
- },
83
- // Normalized endpoint identifier (e.g. "post_adsets_bulk_pause").
84
- // Every dashboard query wants to GROUP BY endpoint class, but `path`
85
- // has adset/campaign ids baked in — at 14M rows GROUP BY path is
86
- // useless and `path LIKE '%bulk/pause%'` is fragile + slow. Computed
87
- // from req.route?.path + req.method in the audit handler; falls back
88
- // to a normalized req.originalUrl when the route didn't match.
89
- endpoint_family: {
90
- type: DataTypes.STRING(30),
91
- allowNull: true,
92
- },
93
- },
94
- {
95
- tableName: "ApiAuditLog",
96
- indexes: [
97
- { fields: [{ name: "user_id" }, { name: "ts", order: "DESC" }] },
98
- { fields: [{ name: "token_id" }, { name: "ts", order: "DESC" }] },
99
- { fields: ["resource_type", "resource_id"] },
100
- // Primary incident-triage entry point — "give me every audit row
101
- // for this X-Request-Id" is the first query in every ticket. Not
102
- // unique because a retry that reuses the same id is exactly the
103
- // signal we want to see.
104
- { fields: ["request_id"] },
105
- // Primary dashboard GROUP BY axis — replaces regex-over-path
106
- // patterns. `ts DESC` because every query is a recent-window
107
- // scan ("last 1h/24h by endpoint_family").
108
- {
109
- fields: [
110
- { name: "endpoint_family" },
111
- { name: "ts", order: "DESC" },
112
- ],
113
- },
114
- ],
115
- }
116
- );
117
-
118
- ApiAuditLog.associate = (models) => {
119
- ApiAuditLog.belongsTo(models.Users, { foreignKey: "user_id", as: "user" });
120
- ApiAuditLog.belongsTo(models.ApiToken, {
121
- foreignKey: "token_id",
122
- as: "token",
123
- });
124
- };
125
-
126
- return ApiAuditLog;
127
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const ApiAuditLog = sequelize.define(
3
+ "ApiAuditLog",
4
+ {
5
+ id: {
6
+ type: DataTypes.UUID,
7
+ defaultValue: DataTypes.UUIDV4,
8
+ primaryKey: true,
9
+ },
10
+ user_id: {
11
+ type: DataTypes.UUID,
12
+ allowNull: false,
13
+ references: {
14
+ model: "Users",
15
+ key: "id",
16
+ },
17
+ },
18
+ token_id: {
19
+ type: DataTypes.UUID,
20
+ allowNull: true,
21
+ references: {
22
+ model: "ApiToken",
23
+ key: "id",
24
+ },
25
+ },
26
+ ts: {
27
+ type: DataTypes.DATE,
28
+ allowNull: false,
29
+ defaultValue: DataTypes.NOW,
30
+ },
31
+ method: {
32
+ type: DataTypes.STRING(10),
33
+ allowNull: false,
34
+ },
35
+ path: {
36
+ type: DataTypes.STRING,
37
+ allowNull: false,
38
+ },
39
+ status_code: {
40
+ type: DataTypes.INTEGER,
41
+ allowNull: false,
42
+ },
43
+ ip: {
44
+ type: DataTypes.STRING,
45
+ allowNull: true,
46
+ },
47
+ resource_type: {
48
+ type: DataTypes.STRING,
49
+ allowNull: true,
50
+ },
51
+ resource_id: {
52
+ type: DataTypes.STRING,
53
+ allowNull: true,
54
+ },
55
+ payload_diff: {
56
+ type: DataTypes.JSONB,
57
+ allowNull: true,
58
+ },
59
+ dry_run: {
60
+ type: DataTypes.BOOLEAN,
61
+ allowNull: false,
62
+ defaultValue: false,
63
+ },
64
+ // Client-supplied or middleware-minted X-Request-Id. Enables 1:1
65
+ // joins to app logs, Cloud Run traces, CampaignCreationLogsV2, and
66
+ // most importantly ends body_hash+30s guessing when clustering
67
+ // retries (the exact gap that made the 7/9 triage so slow).
68
+ // Nullable so the ALTER stays metadata-only on the existing rows.
69
+ request_id: {
70
+ type: DataTypes.STRING(64),
71
+ allowNull: true,
72
+ },
73
+ // End-to-end request duration in milliseconds, computed as
74
+ // Date.now() - startedAt in the res.on('finish' | 'close')
75
+ // handler. Replaces the imprecise (createdAt - ts) subtraction we
76
+ // fell back to during the 7/9 investigation. Nullable because old
77
+ // rows have no measurement — filling those with (createdAt - ts)
78
+ // would reproduce the exact signal we're trying to leave behind.
79
+ duration_ms: {
80
+ type: DataTypes.INTEGER,
81
+ allowNull: true,
82
+ },
83
+ // Normalized endpoint identifier (e.g. "post_adsets_bulk_pause").
84
+ // Every dashboard query wants to GROUP BY endpoint class, but `path`
85
+ // has adset/campaign ids baked in — at 14M rows GROUP BY path is
86
+ // useless and `path LIKE '%bulk/pause%'` is fragile + slow. Computed
87
+ // from req.route?.path + req.method in the audit handler; falls back
88
+ // to a normalized req.originalUrl when the route didn't match.
89
+ endpoint_family: {
90
+ type: DataTypes.STRING(30),
91
+ allowNull: true,
92
+ },
93
+ },
94
+ {
95
+ tableName: "ApiAuditLog",
96
+ indexes: [
97
+ { fields: [{ name: "user_id" }, { name: "ts", order: "DESC" }] },
98
+ { fields: [{ name: "token_id" }, { name: "ts", order: "DESC" }] },
99
+ { fields: ["resource_type", "resource_id"] },
100
+ // Primary incident-triage entry point — "give me every audit row
101
+ // for this X-Request-Id" is the first query in every ticket. Not
102
+ // unique because a retry that reuses the same id is exactly the
103
+ // signal we want to see.
104
+ { fields: ["request_id"] },
105
+ // Primary dashboard GROUP BY axis — replaces regex-over-path
106
+ // patterns. `ts DESC` because every query is a recent-window
107
+ // scan ("last 1h/24h by endpoint_family").
108
+ {
109
+ fields: [
110
+ { name: "endpoint_family" },
111
+ { name: "ts", order: "DESC" },
112
+ ],
113
+ },
114
+ ],
115
+ }
116
+ );
117
+
118
+ ApiAuditLog.associate = (models) => {
119
+ ApiAuditLog.belongsTo(models.Users, { foreignKey: "user_id", as: "user" });
120
+ ApiAuditLog.belongsTo(models.ApiToken, {
121
+ foreignKey: "token_id",
122
+ as: "token",
123
+ });
124
+ };
125
+
126
+ return ApiAuditLog;
127
+ };
@@ -1,67 +1,67 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const ApiToken = sequelize.define(
3
- "ApiToken",
4
- {
5
- id: {
6
- type: DataTypes.UUID,
7
- defaultValue: DataTypes.UUIDV4,
8
- primaryKey: true,
9
- },
10
- user_id: {
11
- type: DataTypes.UUID,
12
- allowNull: false,
13
- references: {
14
- model: "Users",
15
- key: "id",
16
- },
17
- },
18
- token_hash: {
19
- type: DataTypes.STRING(64),
20
- allowNull: false,
21
- unique: true,
22
- },
23
- prefix: {
24
- type: DataTypes.STRING(16),
25
- allowNull: false,
26
- },
27
- scopes: {
28
- type: DataTypes.JSONB,
29
- allowNull: false,
30
- defaultValue: ["read"],
31
- },
32
- expires_at: {
33
- type: DataTypes.DATE,
34
- allowNull: false,
35
- },
36
- last_used_at: {
37
- type: DataTypes.DATE,
38
- allowNull: true,
39
- },
40
- last_used_ip: {
41
- type: DataTypes.STRING,
42
- allowNull: true,
43
- },
44
- revoked_at: {
45
- type: DataTypes.DATE,
46
- allowNull: true,
47
- },
48
- },
49
- {
50
- tableName: "ApiToken",
51
- indexes: [
52
- { unique: true, fields: ["token_hash"] },
53
- { fields: ["user_id", "revoked_at"] },
54
- ],
55
- }
56
- );
57
-
58
- ApiToken.associate = (models) => {
59
- ApiToken.belongsTo(models.Users, { foreignKey: "user_id", as: "user" });
60
- ApiToken.hasMany(models.ApiAuditLog, {
61
- foreignKey: "token_id",
62
- as: "auditLogs",
63
- });
64
- };
65
-
66
- return ApiToken;
67
- };
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const ApiToken = sequelize.define(
3
+ "ApiToken",
4
+ {
5
+ id: {
6
+ type: DataTypes.UUID,
7
+ defaultValue: DataTypes.UUIDV4,
8
+ primaryKey: true,
9
+ },
10
+ user_id: {
11
+ type: DataTypes.UUID,
12
+ allowNull: false,
13
+ references: {
14
+ model: "Users",
15
+ key: "id",
16
+ },
17
+ },
18
+ token_hash: {
19
+ type: DataTypes.STRING(64),
20
+ allowNull: false,
21
+ unique: true,
22
+ },
23
+ prefix: {
24
+ type: DataTypes.STRING(16),
25
+ allowNull: false,
26
+ },
27
+ scopes: {
28
+ type: DataTypes.JSONB,
29
+ allowNull: false,
30
+ defaultValue: ["read"],
31
+ },
32
+ expires_at: {
33
+ type: DataTypes.DATE,
34
+ allowNull: false,
35
+ },
36
+ last_used_at: {
37
+ type: DataTypes.DATE,
38
+ allowNull: true,
39
+ },
40
+ last_used_ip: {
41
+ type: DataTypes.STRING,
42
+ allowNull: true,
43
+ },
44
+ revoked_at: {
45
+ type: DataTypes.DATE,
46
+ allowNull: true,
47
+ },
48
+ },
49
+ {
50
+ tableName: "ApiToken",
51
+ indexes: [
52
+ { unique: true, fields: ["token_hash"] },
53
+ { fields: ["user_id", "revoked_at"] },
54
+ ],
55
+ }
56
+ );
57
+
58
+ ApiToken.associate = (models) => {
59
+ ApiToken.belongsTo(models.Users, { foreignKey: "user_id", as: "user" });
60
+ ApiToken.hasMany(models.ApiAuditLog, {
61
+ foreignKey: "token_id",
62
+ as: "auditLogs",
63
+ });
64
+ };
65
+
66
+ return ApiToken;
67
+ };