@foundrynorth/compass-schema 1.0.4 → 1.0.6

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/dist/schema.js CHANGED
@@ -3314,6 +3314,8 @@ export const mediaOrderLineItems = pgTable("media_order_line_items", {
3314
3314
  // Datasys 360 integration
3315
3315
  datasysCountId: varchar("datasys_count_id"),
3316
3316
  datasysCampaignId: varchar("datasys_campaign_id"),
3317
+ // Simpli.fi DSP integration
3318
+ simplifiCampaignId: varchar("simplifi_campaign_id"),
3317
3319
  // Fulfillment details (product-specific fields for HubSpot sync)
3318
3320
  fulfillmentDetails: jsonb("fulfillment_details"),
3319
3321
  creativeSource: varchar("creative_source"),
@@ -4826,6 +4828,7 @@ export const insertDatasysDeploymentSchema = createInsertSchema(datasysDeploymen
4826
4828
  export const programmaticVendorEnum = pgEnum("programmatic_vendor", [
4827
4829
  "ttd",
4828
4830
  "datasys",
4831
+ "simpli_fi",
4829
4832
  ]);
4830
4833
  /**
4831
4834
  * Account readiness status for a vendor.
@@ -5563,4 +5566,145 @@ export const geoTargets = pgTable("geo_targets", {
5563
5566
  index("geo_targets_client_name_idx").on(table.clientName),
5564
5567
  index("geo_targets_active_idx").on(table.isActive),
5565
5568
  ]);
5569
+ // ─── Business Intelligence Cache ──────────────────────────────────────────────
5570
+ // Migration: 0034_business_intel_cache.sql
5571
+ // Cross-flow enrichment cache keyed by domain or HubSpot company ID.
5572
+ // Populated by inline-assist, background enrichment, and deep research.
5573
+ export const businessIntelCache = pgTable("business_intel_cache", {
5574
+ id: uuid("id").primaryKey().defaultRandom(),
5575
+ partnerId: varchar("partner_id"),
5576
+ domain: text("domain"),
5577
+ hubspotCompanyId: text("hubspot_company_id"),
5578
+ clientName: text("client_name"),
5579
+ quickEnrichData: jsonb("quick_enrich_data"),
5580
+ trueNorthHistory: jsonb("true_north_history"),
5581
+ contractTier: text("contract_tier"),
5582
+ adActivity: jsonb("ad_activity"),
5583
+ seoSnapshot: jsonb("seo_snapshot"),
5584
+ techSignals: jsonb("tech_signals"),
5585
+ confidenceLevel: text("confidence_level"),
5586
+ sources: text("sources").array(),
5587
+ lastEnrichedAt: timestamp("last_enriched_at", { withTimezone: true }),
5588
+ ttlExpiresAt: timestamp("ttl_expires_at", { withTimezone: true }),
5589
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
5590
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
5591
+ }, (table) => [
5592
+ uniqueIndex("bic_partner_domain_unique_idx")
5593
+ .on(table.partnerId, table.domain)
5594
+ .where(sql `domain IS NOT NULL`),
5595
+ uniqueIndex("bic_partner_hubspot_company_id_unique_idx")
5596
+ .on(table.partnerId, table.hubspotCompanyId)
5597
+ .where(sql `hubspot_company_id IS NOT NULL`),
5598
+ ]);
5599
+ // =============================================================================
5600
+ // SIMPLI.FI DSP INTEGRATION
5601
+ // =============================================================================
5602
+ export const simplifiCampaignStatusEnum = pgEnum("simplifi_campaign_status", [
5603
+ "draft",
5604
+ "active",
5605
+ "paused",
5606
+ "ended",
5607
+ "error",
5608
+ ]);
5609
+ export const simplifiGeoFenceTypeEnum = pgEnum("simplifi_geo_fence_type", [
5610
+ "addressable",
5611
+ "location",
5612
+ "conversion_zone",
5613
+ "event",
5614
+ ]);
5615
+ /**
5616
+ * simplifi_campaigns — Tracks campaigns pushed to Simpli.fi DSP.
5617
+ * One campaign per eligible line item.
5618
+ */
5619
+ export const simplifiCampaigns = pgTable("simplifi_campaigns", {
5620
+ id: varchar("id")
5621
+ .primaryKey()
5622
+ .default(sql `gen_random_uuid()`),
5623
+ /** Simpli.fi's campaign ID */
5624
+ simplifiCampaignId: text("simplifi_campaign_id").notNull().unique(),
5625
+ /** Simpli.fi organization ID this campaign belongs to */
5626
+ organizationId: text("organization_id").notNull(),
5627
+ /** Campaign name as created in Simpli.fi */
5628
+ campaignName: text("campaign_name").notNull(),
5629
+ /** Campaign lifecycle status */
5630
+ status: simplifiCampaignStatusEnum("status").notNull().default("draft"),
5631
+ /** FK → media_orders.id */
5632
+ mediaOrderId: varchar("media_order_id"),
5633
+ /** FK → media_order_line_items.id */
5634
+ lineItemId: varchar("line_item_id"),
5635
+ /** Total campaign budget in dollars */
5636
+ totalBudget: numeric("total_budget", { precision: 12, scale: 2 }),
5637
+ /** Campaign start date */
5638
+ startDate: date("start_date"),
5639
+ /** Campaign end date */
5640
+ endDate: date("end_date"),
5641
+ /** Vendor-specific metadata (bid type, ad sizes, etc.) */
5642
+ simplifiMetadata: jsonb("simplifi_metadata").$type(),
5643
+ /** Last sync error message (null = no error) */
5644
+ syncError: text("sync_error"),
5645
+ /** Last time this campaign was synced with Simpli.fi API */
5646
+ lastSyncedAt: timestamp("last_synced_at"),
5647
+ createdAt: timestamp("created_at").notNull().defaultNow(),
5648
+ updatedAt: timestamp("updated_at").notNull().defaultNow(),
5649
+ }, (table) => [
5650
+ index("simplifi_campaigns_order_idx").on(table.mediaOrderId),
5651
+ index("simplifi_campaigns_line_item_idx").on(table.lineItemId),
5652
+ index("simplifi_campaigns_status_idx").on(table.status),
5653
+ ]);
5654
+ export const insertSimplifiCampaignSchema = createInsertSchema(simplifiCampaigns).omit({
5655
+ id: true,
5656
+ createdAt: true,
5657
+ updatedAt: true,
5658
+ });
5659
+ /**
5660
+ * simplifi_geo_fences — Tracks geo-fences pushed to Simpli.fi campaigns.
5661
+ * Links a Simpli.fi campaign to geo-targets from the shared geo_targets table.
5662
+ */
5663
+ export const simplifiGeoFences = pgTable("simplifi_geo_fences", {
5664
+ id: varchar("id")
5665
+ .primaryKey()
5666
+ .default(sql `gen_random_uuid()`),
5667
+ /** FK → simplifi_campaigns.simplifi_campaign_id */
5668
+ simplifiCampaignId: text("simplifi_campaign_id").notNull(),
5669
+ /** FK → geo_targets.id (nullable for ad-hoc fences without saved geo-targets) */
5670
+ geoTargetId: varchar("geo_target_id"),
5671
+ /** Fence type in Simpli.fi */
5672
+ fenceType: simplifiGeoFenceTypeEnum("fence_type").notNull().default("location"),
5673
+ /** Fence display name */
5674
+ name: text("name").notNull(),
5675
+ /** Latitude of fence center */
5676
+ lat: numeric("lat", { precision: 10, scale: 7 }).notNull(),
5677
+ /** Longitude of fence center */
5678
+ lng: numeric("lng", { precision: 10, scale: 7 }).notNull(),
5679
+ /** Fence radius in meters */
5680
+ radiusMeters: numeric("radius_meters", { precision: 10, scale: 2 }).notNull(),
5681
+ createdAt: timestamp("created_at").notNull().defaultNow(),
5682
+ }, (table) => [
5683
+ index("simplifi_geo_fences_campaign_idx").on(table.simplifiCampaignId),
5684
+ index("simplifi_geo_fences_geo_target_idx").on(table.geoTargetId),
5685
+ ]);
5686
+ /**
5687
+ * simplifi_budget_flights — Budget flights (monthly/periodic budget splits)
5688
+ * for Simpli.fi campaigns. Proportional to days in each period.
5689
+ */
5690
+ export const simplifiBudgetFlights = pgTable("simplifi_budget_flights", {
5691
+ id: varchar("id")
5692
+ .primaryKey()
5693
+ .default(sql `gen_random_uuid()`),
5694
+ /** FK → simplifi_campaigns.simplifi_campaign_id */
5695
+ simplifiCampaignId: text("simplifi_campaign_id").notNull(),
5696
+ /** Simpli.fi's budget flight ID */
5697
+ simplifiFlightId: text("simplifi_flight_id"),
5698
+ /** Flight start date */
5699
+ startDate: date("start_date").notNull(),
5700
+ /** Flight end date */
5701
+ endDate: date("end_date").notNull(),
5702
+ /** Budget allocated to this flight */
5703
+ budget: numeric("budget", { precision: 12, scale: 2 }).notNull(),
5704
+ /** Impression cap for this flight (if applicable) */
5705
+ impressionCap: integer("impression_cap"),
5706
+ createdAt: timestamp("created_at").notNull().defaultNow(),
5707
+ }, (table) => [
5708
+ index("simplifi_budget_flights_campaign_idx").on(table.simplifiCampaignId),
5709
+ ]);
5566
5710
  //# sourceMappingURL=schema.js.map