agrs-sequelize-sdk 1.4.29 → 1.4.31

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.
@@ -0,0 +1,53 @@
1
+ module.exports = (sequelize, DataTypes) => {
2
+ /**
3
+ * Durable audit log of every inbound Mine webhook call (article-ready / policy-decision).
4
+ * Purpose: observability, security audit (signature failures), idempotency, replay/reconcile.
5
+ * Correlation is by string ids (provider_id / adset_id / ad_id) — no FK, to stay decoupled
6
+ * from the article/ad lifecycle and tolerate webhooks that arrive before the local row exists.
7
+ */
8
+ const MineWebhookEvent = sequelize.define(
9
+ "MineWebhookEvent",
10
+ {
11
+ id: {
12
+ type: DataTypes.INTEGER,
13
+ primaryKey: true,
14
+ autoIncrement: true,
15
+ },
16
+ event_id: { type: DataTypes.STRING, allowNull: true }, // Mine's unique id (idempotency)
17
+ event_type: { type: DataTypes.STRING, allowNull: false }, // 'article-ready' | 'policy-decision'
18
+ endpoint: { type: DataTypes.STRING, allowNull: true },
19
+ source_ip: { type: DataTypes.STRING, allowNull: true },
20
+
21
+ signature_valid: { type: DataTypes.BOOLEAN, allowNull: true },
22
+ http_status: { type: DataTypes.INTEGER, allowNull: true },
23
+
24
+ payload: { type: DataTypes.JSONB, allowNull: true },
25
+
26
+ provider_id: { type: DataTypes.STRING, allowNull: true },
27
+ adset_id: { type: DataTypes.STRING, allowNull: true },
28
+ ad_id: { type: DataTypes.STRING, allowNull: true },
29
+ matched_agrsaid: { type: DataTypes.STRING, allowNull: true },
30
+
31
+ // received | processed | skipped | duplicate | rejected_signature | rejected_validation | failed
32
+ outcome: { type: DataTypes.STRING, allowNull: false, defaultValue: "received" },
33
+ outcome_reason: { type: DataTypes.TEXT, allowNull: true },
34
+
35
+ received_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
36
+ processed_at: { type: DataTypes.DATE, allowNull: true },
37
+ duration_ms: { type: DataTypes.INTEGER, allowNull: true },
38
+ },
39
+ {
40
+ tableName: "mine_webhook_events",
41
+ indexes: [
42
+ { fields: ["event_id"] },
43
+ { fields: ["event_type"] },
44
+ { fields: ["outcome"] },
45
+ { fields: ["provider_id"] },
46
+ { fields: ["adset_id"] },
47
+ { fields: [{ name: "received_at", order: "DESC" }] },
48
+ ],
49
+ }
50
+ );
51
+
52
+ return MineWebhookEvent;
53
+ };
@@ -11,7 +11,8 @@ module.exports = (sequelize, DataTypes) => {
11
11
  type: DataTypes.STRING(64),
12
12
  allowNull: false,
13
13
  unique: true,
14
- comment: "TikTok identity_id (CUSTOMIZED_USER) used as creative owner",
14
+ comment:
15
+ "TikTok identity_id (creative owner). ONE row per identity — mirrors FB Pages.code.",
15
16
  },
16
17
  identity_type: {
17
18
  type: DataTypes.STRING(32),
@@ -22,10 +23,21 @@ module.exports = (sequelize, DataTypes) => {
22
23
  type: DataTypes.STRING(255),
23
24
  allowNull: true,
24
25
  },
26
+ // Identities are scoped by business_center_id (mirrors FB Pages, tagged by
27
+ // BM with no ad-account binding) and selected at creation time (UI lets the
28
+ // user pick; the AI/feed flow random-picks via the resolver, which queries
29
+ // by the advertiser's BC and IGNORES ad_account_id). ad_account_id is kept
30
+ // NOT NULL (no schema mutation) and holds a representative advertiser.
25
31
  ad_account_id: {
26
32
  type: DataTypes.STRING(64),
27
33
  allowNull: false,
28
- comment: "TikTok advertiser_id this identity belongs to",
34
+ comment: "Representative advertiser (informational). Identity scope/selection is by business_center_id.",
35
+ },
36
+ business_center_id: {
37
+ type: DataTypes.STRING(64),
38
+ allowNull: true,
39
+ comment:
40
+ "TikTok Business Center the identity is authorized to. The resolver picks an identity whose BC matches the advertiser's owner BC (mirrors FB Pages.BusinessManager).",
29
41
  },
30
42
  status: {
31
43
  type: DataTypes.STRING(16),
@@ -43,7 +55,10 @@ module.exports = (sequelize, DataTypes) => {
43
55
  },
44
56
  {
45
57
  tableName: "tiktok_identities",
46
- indexes: [{ fields: ["ad_account_id", "status"] }],
58
+ indexes: [
59
+ { fields: ["ad_account_id", "status"] },
60
+ { fields: ["business_center_id", "status"] },
61
+ ],
47
62
  }
48
63
  );
49
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.4.29",
3
+ "version": "1.4.31",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",