adserver-dashboard 1.0.0

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 (525) hide show
  1. package/.ci/staging.yml +191 -0
  2. package/.dockerignore +117 -0
  3. package/.env +40 -0
  4. package/.env.staging +38 -0
  5. package/.gitlab-ci.yml +16 -0
  6. package/DEMO_STATUS.md +579 -0
  7. package/Dockerfile +61 -0
  8. package/Influence-MW-AdServer-12-02-2026/client/index.html +17 -0
  9. package/Influence-MW-AdServer-12-02-2026/client/public/favicon.png +0 -0
  10. package/Influence-MW-AdServer-12-02-2026/client/src/App.tsx +91 -0
  11. package/Influence-MW-AdServer-12-02-2026/client/src/components/advanced-map-drawer.tsx +1131 -0
  12. package/Influence-MW-AdServer-12-02-2026/client/src/components/ai-recommendation-panel.tsx +379 -0
  13. package/Influence-MW-AdServer-12-02-2026/client/src/components/app-sidebar.tsx +183 -0
  14. package/Influence-MW-AdServer-12-02-2026/client/src/components/auto-optimize-button.tsx +184 -0
  15. package/Influence-MW-AdServer-12-02-2026/client/src/components/availability-drawer.tsx +385 -0
  16. package/Influence-MW-AdServer-12-02-2026/client/src/components/brand-insights-panel.tsx +87 -0
  17. package/Influence-MW-AdServer-12-02-2026/client/src/components/create-agency-drawer.tsx +198 -0
  18. package/Influence-MW-AdServer-12-02-2026/client/src/components/create-brand-drawer.tsx +275 -0
  19. package/Influence-MW-AdServer-12-02-2026/client/src/components/creative-assignment.tsx +526 -0
  20. package/Influence-MW-AdServer-12-02-2026/client/src/components/data-table-toolbar.tsx +148 -0
  21. package/Influence-MW-AdServer-12-02-2026/client/src/components/data-table.tsx +158 -0
  22. package/Influence-MW-AdServer-12-02-2026/client/src/components/filter-drawer.tsx +356 -0
  23. package/Influence-MW-AdServer-12-02-2026/client/src/components/form-insights-panel.tsx +82 -0
  24. package/Influence-MW-AdServer-12-02-2026/client/src/components/geography-selector.tsx +699 -0
  25. package/Influence-MW-AdServer-12-02-2026/client/src/components/header-user-menu.tsx +178 -0
  26. package/Influence-MW-AdServer-12-02-2026/client/src/components/history-drawer.tsx +313 -0
  27. package/Influence-MW-AdServer-12-02-2026/client/src/components/inventory-availability-section.tsx +176 -0
  28. package/Influence-MW-AdServer-12-02-2026/client/src/components/inventory-format-drawer.tsx +173 -0
  29. package/Influence-MW-AdServer-12-02-2026/client/src/components/inventory-selector.tsx +401 -0
  30. package/Influence-MW-AdServer-12-02-2026/client/src/components/manual-inventory-drawer.tsx +368 -0
  31. package/Influence-MW-AdServer-12-02-2026/client/src/components/mapbox-map.tsx +368 -0
  32. package/Influence-MW-AdServer-12-02-2026/client/src/components/market-insights-panel.tsx +202 -0
  33. package/Influence-MW-AdServer-12-02-2026/client/src/components/media-owner-drawer.tsx +217 -0
  34. package/Influence-MW-AdServer-12-02-2026/client/src/components/metric-card.tsx +58 -0
  35. package/Influence-MW-AdServer-12-02-2026/client/src/components/page-header.tsx +27 -0
  36. package/Influence-MW-AdServer-12-02-2026/client/src/components/player-status-indicator.tsx +137 -0
  37. package/Influence-MW-AdServer-12-02-2026/client/src/components/poi-targeting-drawer.tsx +298 -0
  38. package/Influence-MW-AdServer-12-02-2026/client/src/components/recommendation-score-badge.tsx +102 -0
  39. package/Influence-MW-AdServer-12-02-2026/client/src/components/recommended-inventories-panel.tsx +248 -0
  40. package/Influence-MW-AdServer-12-02-2026/client/src/components/searchable-combobox.tsx +134 -0
  41. package/Influence-MW-AdServer-12-02-2026/client/src/components/signal-visualizations.tsx +407 -0
  42. package/Influence-MW-AdServer-12-02-2026/client/src/components/status-badge.tsx +35 -0
  43. package/Influence-MW-AdServer-12-02-2026/client/src/components/theme-provider.tsx +73 -0
  44. package/Influence-MW-AdServer-12-02-2026/client/src/components/theme-toggle.tsx +37 -0
  45. package/Influence-MW-AdServer-12-02-2026/client/src/components/traffic-slider.tsx +75 -0
  46. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/accordion.tsx +56 -0
  47. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/alert-dialog.tsx +139 -0
  48. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/alert.tsx +59 -0
  49. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/aspect-ratio.tsx +5 -0
  50. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/avatar.tsx +51 -0
  51. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/badge.tsx +38 -0
  52. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/breadcrumb.tsx +115 -0
  53. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/button.tsx +62 -0
  54. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/calendar.tsx +68 -0
  55. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/card.tsx +85 -0
  56. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/carousel.tsx +260 -0
  57. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/chart.tsx +365 -0
  58. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/checkbox.tsx +28 -0
  59. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/collapsible.tsx +11 -0
  60. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/command.tsx +151 -0
  61. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/context-menu.tsx +198 -0
  62. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/dialog.tsx +122 -0
  63. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/drawer.tsx +118 -0
  64. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/dropdown-menu.tsx +198 -0
  65. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/form.tsx +178 -0
  66. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/hover-card.tsx +29 -0
  67. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/input-otp.tsx +69 -0
  68. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/input.tsx +23 -0
  69. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/label.tsx +24 -0
  70. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/menubar.tsx +256 -0
  71. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/navigation-menu.tsx +128 -0
  72. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/pagination.tsx +117 -0
  73. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/popover.tsx +29 -0
  74. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/progress.tsx +28 -0
  75. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/radio-group.tsx +42 -0
  76. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/resizable.tsx +45 -0
  77. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/scroll-area.tsx +46 -0
  78. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/select.tsx +160 -0
  79. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/separator.tsx +29 -0
  80. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/sheet.tsx +140 -0
  81. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/sidebar.tsx +727 -0
  82. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/skeleton.tsx +15 -0
  83. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/slider.tsx +26 -0
  84. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/switch.tsx +27 -0
  85. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/table.tsx +117 -0
  86. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/tabs.tsx +53 -0
  87. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/textarea.tsx +22 -0
  88. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/toast.tsx +127 -0
  89. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/toaster.tsx +33 -0
  90. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/toggle-group.tsx +61 -0
  91. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/toggle.tsx +43 -0
  92. package/Influence-MW-AdServer-12-02-2026/client/src/components/ui/tooltip.tsx +30 -0
  93. package/Influence-MW-AdServer-12-02-2026/client/src/components/vendor-stores-modal.tsx +336 -0
  94. package/Influence-MW-AdServer-12-02-2026/client/src/components/venue-type-drawer.tsx +359 -0
  95. package/Influence-MW-AdServer-12-02-2026/client/src/components/venue-type-selector.tsx +436 -0
  96. package/Influence-MW-AdServer-12-02-2026/client/src/hooks/use-mobile.tsx +19 -0
  97. package/Influence-MW-AdServer-12-02-2026/client/src/hooks/use-toast.ts +191 -0
  98. package/Influence-MW-AdServer-12-02-2026/client/src/index.css +244 -0
  99. package/Influence-MW-AdServer-12-02-2026/client/src/lib/queryClient.ts +57 -0
  100. package/Influence-MW-AdServer-12-02-2026/client/src/lib/utils.ts +39 -0
  101. package/Influence-MW-AdServer-12-02-2026/client/src/lib/venue-taxonomy.ts +532 -0
  102. package/Influence-MW-AdServer-12-02-2026/client/src/main.tsx +5 -0
  103. package/Influence-MW-AdServer-12-02-2026/client/src/pages/assign-creative.tsx +781 -0
  104. package/Influence-MW-AdServer-12-02-2026/client/src/pages/content-hub.tsx +995 -0
  105. package/Influence-MW-AdServer-12-02-2026/client/src/pages/custom-pois.tsx +431 -0
  106. package/Influence-MW-AdServer-12-02-2026/client/src/pages/dashboard.tsx +620 -0
  107. package/Influence-MW-AdServer-12-02-2026/client/src/pages/deal-detail.tsx +1062 -0
  108. package/Influence-MW-AdServer-12-02-2026/client/src/pages/deal-form.tsx +1570 -0
  109. package/Influence-MW-AdServer-12-02-2026/client/src/pages/deals.tsx +716 -0
  110. package/Influence-MW-AdServer-12-02-2026/client/src/pages/edit-creative-assignment.tsx +1051 -0
  111. package/Influence-MW-AdServer-12-02-2026/client/src/pages/geotargeting.tsx +675 -0
  112. package/Influence-MW-AdServer-12-02-2026/client/src/pages/integrations.tsx +425 -0
  113. package/Influence-MW-AdServer-12-02-2026/client/src/pages/line-item-creatives.tsx +622 -0
  114. package/Influence-MW-AdServer-12-02-2026/client/src/pages/line-item-form.tsx +3132 -0
  115. package/Influence-MW-AdServer-12-02-2026/client/src/pages/line-items.tsx +530 -0
  116. package/Influence-MW-AdServer-12-02-2026/client/src/pages/not-found.tsx +21 -0
  117. package/Influence-MW-AdServer-12-02-2026/client/src/pages/proof-of-play-upload.tsx +479 -0
  118. package/Influence-MW-AdServer-12-02-2026/client/src/pages/proof-of-play.tsx +880 -0
  119. package/Influence-MW-AdServer-12-02-2026/client/src/pages/reports.tsx +235 -0
  120. package/Influence-MW-AdServer-12-02-2026/client/src/pages/settings.tsx +652 -0
  121. package/Influence-MW-AdServer-12-02-2026/client/src/pages/signal-form.tsx +1117 -0
  122. package/Influence-MW-AdServer-12-02-2026/client/src/pages/signals.tsx +366 -0
  123. package/Influence-MW-AdServer-12-02-2026/client/src/pages/tags.tsx +332 -0
  124. package/Influence-MW-AdServer-12-02-2026/client/src/pages/venues.tsx +381 -0
  125. package/Influence-MW-AdServer-12-02-2026/client/src/types/mapbox-gl-draw.d.ts +37 -0
  126. package/Influence-MW-AdServer-12-02-2026/client/src/types/react-simple-maps.d.ts +57 -0
  127. package/Influence-MW-AdServer-12-02-2026/components.json +20 -0
  128. package/Influence-MW-AdServer-12-02-2026/docs/PRD.md +3373 -0
  129. package/Influence-MW-AdServer-12-02-2026/docs/influence-feature-mapping.csv +498 -0
  130. package/Influence-MW-AdServer-12-02-2026/drizzle.config.ts +14 -0
  131. package/Influence-MW-AdServer-12-02-2026/package-lock.json +9672 -0
  132. package/Influence-MW-AdServer-12-02-2026/package.json +118 -0
  133. package/Influence-MW-AdServer-12-02-2026/postcss.config.js +6 -0
  134. package/Influence-MW-AdServer-12-02-2026/replit.md +91 -0
  135. package/Influence-MW-AdServer-12-02-2026/script/build.ts +67 -0
  136. package/Influence-MW-AdServer-12-02-2026/scripts/create-miro-diagrams.cjs +318 -0
  137. package/Influence-MW-AdServer-12-02-2026/scripts/create-remaining-diagrams.cjs +270 -0
  138. package/Influence-MW-AdServer-12-02-2026/server/index.ts +103 -0
  139. package/Influence-MW-AdServer-12-02-2026/server/recommendation-service.ts +319 -0
  140. package/Influence-MW-AdServer-12-02-2026/server/routes.ts +1890 -0
  141. package/Influence-MW-AdServer-12-02-2026/server/static.ts +19 -0
  142. package/Influence-MW-AdServer-12-02-2026/server/storage.ts +2058 -0
  143. package/Influence-MW-AdServer-12-02-2026/server/vite.ts +58 -0
  144. package/Influence-MW-AdServer-12-02-2026/shared/schema.ts +1595 -0
  145. package/Influence-MW-AdServer-12-02-2026/tailwind.config.ts +107 -0
  146. package/Influence-MW-AdServer-12-02-2026/tsconfig.json +23 -0
  147. package/Influence-MW-AdServer-12-02-2026/vite.config.ts +40 -0
  148. package/LINE_ITEM_BUDGET_FIELD_MAPPING.md +178 -0
  149. package/PCM/.env.example +92 -0
  150. package/PCM/README.md +558 -0
  151. package/PCM/docs/TEST_CASES.md +422 -0
  152. package/PCM/index.js +106 -0
  153. package/PCM/package-lock.json +3282 -0
  154. package/PCM/package.json +32 -0
  155. package/PCM/replit.md +64 -0
  156. package/PCM/schema.sql +495 -0
  157. package/PCM/scripts/export-schema.js +183 -0
  158. package/PCM/scripts/seed-comprehensive.js +631 -0
  159. package/PCM/scripts/seed-production.js +477 -0
  160. package/PCM/src/config/db.js +56 -0
  161. package/PCM/src/config/swagger.js +5975 -0
  162. package/PCM/src/dto/EmailRequestDTO.js +166 -0
  163. package/PCM/src/middleware/errorHandler.js +52 -0
  164. package/PCM/src/middleware/logger.js +26 -0
  165. package/PCM/src/migrations/001_add_campaign_mode_fields.sql +36 -0
  166. package/PCM/src/migrations/002_create_deal_id_counters.sql +22 -0
  167. package/PCM/src/migrations/003_update_publishers_column.sql +15 -0
  168. package/PCM/src/migrations/004_add_direct_dealtype_and_advertiser.sql +5 -0
  169. package/PCM/src/migrations/005_add_programmatic_fields_and_update_enums.sql +31 -0
  170. package/PCM/src/migrations/006_add_line_item_programmatic_fields.sql +12 -0
  171. package/PCM/src/migrations/007_add_line_item_direct_fields.sql +15 -0
  172. package/PCM/src/migrations/008_add_inventory_fields.sql +45 -0
  173. package/PCM/src/migrations/009_move_inventory_fields_to_metadata.sql +32 -0
  174. package/PCM/src/migrations/010_add_draft_status_and_line_items_count.sql +23 -0
  175. package/PCM/src/migrations/011_add_planning_field.sql +21 -0
  176. package/PCM/src/migrations/012_fix_inventory_composite_pk.sql +17 -0
  177. package/PCM/src/migrations/013_make_external_id_optional.sql +3 -0
  178. package/PCM/src/migrations/014_create_change_history.sql +38 -0
  179. package/PCM/src/migrations/016_create_publisher_insertion_orders.sql +33 -0
  180. package/PCM/src/migrations/017_fix_line_item_id_fk_reference.sql +86 -0
  181. package/PCM/src/migrations/018_create_approval_tables.sql +44 -0
  182. package/PCM/src/migrations/019_add_encrypted_token_column.sql +2 -0
  183. package/PCM/src/migrations/020_add_rejection_reason_to_deals.sql +10 -0
  184. package/PCM/src/migrations/021_add_publisher_external_id_to_inventories.sql +12 -0
  185. package/PCM/src/migrations/022_add_line_item_extended_fields.sql +24 -0
  186. package/PCM/src/migrations/023_add_base_price_fields.sql +8 -0
  187. package/PCM/src/migrations/run-migrations.js +46 -0
  188. package/PCM/src/models/ApprovalOTP.js +51 -0
  189. package/PCM/src/models/ApprovalToken.js +79 -0
  190. package/PCM/src/models/ChangeHistory.js +107 -0
  191. package/PCM/src/models/Deal.js +186 -0
  192. package/PCM/src/models/DealIdCounter.js +28 -0
  193. package/PCM/src/models/LineItem.js +227 -0
  194. package/PCM/src/models/LineItemCreative.js +89 -0
  195. package/PCM/src/models/LineItemInventory.js +115 -0
  196. package/PCM/src/models/PublisherInsertionOrder.js +93 -0
  197. package/PCM/src/models/TransactionHistory.js +34 -0
  198. package/PCM/src/models/associations.js +81 -0
  199. package/PCM/src/routes/approval.js +321 -0
  200. package/PCM/src/routes/creatives.js +437 -0
  201. package/PCM/src/routes/deals.js +1638 -0
  202. package/PCM/src/routes/digitalSignage.js +242 -0
  203. package/PCM/src/routes/insertionOrders.js +380 -0
  204. package/PCM/src/routes/lineItems.js +926 -0
  205. package/PCM/src/routes/system.js +384 -0
  206. package/PCM/src/services/ApprovalService.js +885 -0
  207. package/PCM/src/services/CampaignImportConverter.js +631 -0
  208. package/PCM/src/services/CampaignModeService.js +273 -0
  209. package/PCM/src/services/CampaignStatusService.js +395 -0
  210. package/PCM/src/services/ChangeHistoryService.js +316 -0
  211. package/PCM/src/services/DealIdService.js +94 -0
  212. package/PCM/src/services/DealResponseFormatter.js +90 -0
  213. package/PCM/src/services/EmailNotificationService.js +315 -0
  214. package/PCM/src/services/LineItemResponseFormatter.js +122 -0
  215. package/PCM/src/services/LineItemStatusService.js +380 -0
  216. package/PCM/src/tests/comprehensiveTestRunner.js +360 -0
  217. package/PCM/src/tests/comprehensiveTests.js +1277 -0
  218. package/PCM/src/tests/dealTypeUnitTests.js +1058 -0
  219. package/PCM/src/tests/testRunner.js +248 -0
  220. package/PCM/src/utils/caseConverter.js +92 -0
  221. package/PCM/src/utils/dealCalculations.js +206 -0
  222. package/PCM/src/utils/lineItemPayloadNormalizer.js +41 -0
  223. package/PCM/src/utils/payloadNormalizer.js +34 -0
  224. package/PCM/src/utils/sourceNormalizer.js +56 -0
  225. package/PCM/src/validators/creativeValidator.js +27 -0
  226. package/PCM/src/validators/dealValidator.js +203 -0
  227. package/PCM/src/validators/lineItemValidator.js +489 -0
  228. package/PCM/tests/approval-flows.test.js +238 -0
  229. package/PCM/tests/approval-workflow.test.js +291 -0
  230. package/PCM/tests/campaign-import-converter.test.js +543 -0
  231. package/PCM/tests/campaign-import-e2e.test.js +520 -0
  232. package/PCM/tests/campaign-status.test.js +539 -0
  233. package/PCM/tests/direct-publisher-split-reimport.test.js +460 -0
  234. package/PCM/tests/e2e/digital-signage.test.js +145 -0
  235. package/PCM/tests/e2e/search-filter-pagination.test.js +399 -0
  236. package/PCM/tests/e2e-comprehensive.test.js +3446 -0
  237. package/PCM/tests/edge-cases.test.js +340 -0
  238. package/PCM/tests/line-item-status.test.js +340 -0
  239. package/PCM/tests/seller-account-external-ids.test.js +877 -0
  240. package/PCM/tests/source-validation.test.js +324 -0
  241. package/PRD.md +3373 -0
  242. package/README.md +186 -0
  243. package/client/index.html +35 -0
  244. package/client/public/DEMO_STATUS.md +579 -0
  245. package/client/public/img/MW-logo-trans_1754045676555.png +0 -0
  246. package/client/public/locales/ar/approval.json +144 -0
  247. package/client/public/locales/ar/buyer.json +61 -0
  248. package/client/public/locales/ar/campaigns.json +1 -0
  249. package/client/public/locales/ar/common.json +218 -0
  250. package/client/public/locales/ar/contentHub.json +266 -0
  251. package/client/public/locales/ar/creatives.json +79 -0
  252. package/client/public/locales/ar/dashboard.json +57 -0
  253. package/client/public/locales/ar/deals.json +886 -0
  254. package/client/public/locales/ar/dsp.json +131 -0
  255. package/client/public/locales/ar/inventory.json +201 -0
  256. package/client/public/locales/ar/lineItems.json +553 -0
  257. package/client/public/locales/ar/navigation.json +48 -0
  258. package/client/public/locales/ar/wizard.json +1 -0
  259. package/client/public/locales/en/approval.json +144 -0
  260. package/client/public/locales/en/buyer.json +65 -0
  261. package/client/public/locales/en/campaigns.json +1 -0
  262. package/client/public/locales/en/common.json +218 -0
  263. package/client/public/locales/en/contentHub.json +266 -0
  264. package/client/public/locales/en/creatives.json +79 -0
  265. package/client/public/locales/en/dashboard.json +57 -0
  266. package/client/public/locales/en/deals.json +886 -0
  267. package/client/public/locales/en/dsp.json +131 -0
  268. package/client/public/locales/en/inventory.json +201 -0
  269. package/client/public/locales/en/lineItems.json +659 -0
  270. package/client/public/locales/en/navigation.json +48 -0
  271. package/client/public/locales/en/wizard.json +1 -0
  272. package/client/public/locales/ja/approval.json +144 -0
  273. package/client/public/locales/ja/buyer.json +61 -0
  274. package/client/public/locales/ja/campaigns.json +1 -0
  275. package/client/public/locales/ja/common.json +218 -0
  276. package/client/public/locales/ja/contentHub.json +266 -0
  277. package/client/public/locales/ja/creatives.json +79 -0
  278. package/client/public/locales/ja/dashboard.json +57 -0
  279. package/client/public/locales/ja/deals.json +886 -0
  280. package/client/public/locales/ja/dsp.json +131 -0
  281. package/client/public/locales/ja/inventory.json +201 -0
  282. package/client/public/locales/ja/lineItems.json +553 -0
  283. package/client/public/locales/ja/navigation.json +48 -0
  284. package/client/public/locales/ja/wizard.json +1 -0
  285. package/client/public/locales/zh/approval.json +144 -0
  286. package/client/public/locales/zh/buyer.json +61 -0
  287. package/client/public/locales/zh/campaigns.json +1 -0
  288. package/client/public/locales/zh/common.json +218 -0
  289. package/client/public/locales/zh/contentHub.json +266 -0
  290. package/client/public/locales/zh/creatives.json +79 -0
  291. package/client/public/locales/zh/dashboard.json +57 -0
  292. package/client/public/locales/zh/deals.json +886 -0
  293. package/client/public/locales/zh/dsp.json +131 -0
  294. package/client/public/locales/zh/inventory.json +201 -0
  295. package/client/public/locales/zh/lineItems.json +553 -0
  296. package/client/public/locales/zh/navigation.json +48 -0
  297. package/client/public/locales/zh/wizard.json +1 -0
  298. package/client/public/manifest.json +36 -0
  299. package/client/src/App.tsx +464 -0
  300. package/client/src/components/app-sidebar.tsx +312 -0
  301. package/client/src/components/approval/approval-decision-form.test.tsx +294 -0
  302. package/client/src/components/approval/approval-decision-form.tsx +326 -0
  303. package/client/src/components/approval/approval-sheet.tsx +631 -0
  304. package/client/src/components/approval/line-item-details-sheet.tsx +371 -0
  305. package/client/src/components/approval/otp-verification.test.tsx +337 -0
  306. package/client/src/components/approval/otp-verification.tsx +180 -0
  307. package/client/src/components/content-hub/bulk-transcode-dialog.tsx +379 -0
  308. package/client/src/components/content-hub/content-hub-manager-v2.tsx +574 -0
  309. package/client/src/components/content-hub/content-hub-manager.tsx +330 -0
  310. package/client/src/components/content-hub/creative-card.tsx +456 -0
  311. package/client/src/components/content-hub/creative-detail-sheet.tsx +685 -0
  312. package/client/src/components/content-hub/creative-filters.tsx +457 -0
  313. package/client/src/components/content-hub/creative-grid.tsx +329 -0
  314. package/client/src/components/content-hub/creative-selector.tsx +415 -0
  315. package/client/src/components/content-hub/creative-upload.tsx +547 -0
  316. package/client/src/components/content-hub/folder-dialogs.tsx +445 -0
  317. package/client/src/components/content-hub/folder-list.tsx +280 -0
  318. package/client/src/components/content-hub/review-dialogs.tsx +268 -0
  319. package/client/src/components/content-hub/transcode-dialog.tsx +226 -0
  320. package/client/src/components/creative-library/creative-details-view.tsx +446 -0
  321. package/client/src/components/creative-library/creative-filters-panel.tsx +203 -0
  322. package/client/src/components/creative-library/creative-list.tsx +360 -0
  323. package/client/src/components/creative-library/creative-status-badge.tsx +71 -0
  324. package/client/src/components/creative-library/folder-card.tsx +78 -0
  325. package/client/src/components/creative-library/index.ts +27 -0
  326. package/client/src/components/creative-library/new-creative-card.tsx +211 -0
  327. package/client/src/components/creative-library/upload-creative-dialog.tsx +261 -0
  328. package/client/src/components/dashboard-overview.tsx +109 -0
  329. package/client/src/components/deals/approval-history-panel.test.tsx +240 -0
  330. package/client/src/components/deals/approval-history-panel.tsx +156 -0
  331. package/client/src/components/deals/deal-status-badge.tsx +92 -0
  332. package/client/src/components/deals/import-from-planner-dialog.tsx +399 -0
  333. package/client/src/components/deals/market-insights-panel.tsx +237 -0
  334. package/client/src/components/deals/reopen-deal-sheet.tsx +191 -0
  335. package/client/src/components/deals/request-approval-sheet.test.tsx +323 -0
  336. package/client/src/components/deals/request-approval-sheet.tsx +136 -0
  337. package/client/src/components/deals/resend-approval-sheet.tsx +201 -0
  338. package/client/src/components/direct-campaigns/campaign-card.tsx +283 -0
  339. package/client/src/components/direct-campaigns/deal-filter-panel.tsx +325 -0
  340. package/client/src/components/inventory/advanced-filters-panel.tsx +273 -0
  341. package/client/src/components/inventory/csv-upload-modal.tsx +639 -0
  342. package/client/src/components/inventory/inventory-availability-view.tsx +486 -0
  343. package/client/src/components/inventory/inventory-details-sheet.tsx +376 -0
  344. package/client/src/components/inventory/inventory-map-view.tsx +596 -0
  345. package/client/src/components/inventory/inventory-settings-menu.tsx +52 -0
  346. package/client/src/components/language-switcher.tsx +53 -0
  347. package/client/src/components/line-items/campaign-forecast-panel.tsx +138 -0
  348. package/client/src/components/line-items/form-insights.tsx +89 -0
  349. package/client/src/components/line-items/geofencing/LocationCsvUploadDrawer.tsx +100 -0
  350. package/client/src/components/line-items/geofencing/POIDropdown.tsx +379 -0
  351. package/client/src/components/line-items/geofencing/SelectedLocationsSidebar.tsx +436 -0
  352. package/client/src/components/line-items/geofencing/ViewFileLocationDrawer.tsx +199 -0
  353. package/client/src/components/line-items/geofencing/components/ExistingFilesTab.tsx +268 -0
  354. package/client/src/components/line-items/geofencing/components/TemplateDownloadSection.tsx +59 -0
  355. package/client/src/components/line-items/geofencing/components/UploadTab.tsx +215 -0
  356. package/client/src/components/line-items/geofencing-map.tsx +1270 -0
  357. package/client/src/components/line-items/inventory-availability-section.tsx +178 -0
  358. package/client/src/components/line-items/line-item-schedule-manager.tsx +313 -0
  359. package/client/src/components/line-items/manual-inventory-drawer.tsx +346 -0
  360. package/client/src/components/line-items/planner-inventory-card.tsx +495 -0
  361. package/client/src/components/line-items/planner-schedule-grid.tsx +495 -0
  362. package/client/src/components/line-items/schedule-rule-editor.tsx +649 -0
  363. package/client/src/components/line-items/schedule-rule-types.ts +122 -0
  364. package/client/src/components/line-items/steps/creatives-step.tsx +681 -0
  365. package/client/src/components/line-items/steps/inventory-schedule-step.tsx +1596 -0
  366. package/client/src/components/line-items/steps/inventory-step.tsx +1533 -0
  367. package/client/src/components/line-items/steps/line-item-details-step.tsx +916 -0
  368. package/client/src/components/line-items/steps/schedule-step.tsx +273 -0
  369. package/client/src/components/line-items/steps/summary-step.tsx +680 -0
  370. package/client/src/components/line-items/steps/targeting-step.tsx +1708 -0
  371. package/client/src/components/product-switcher.tsx +105 -0
  372. package/client/src/components/protected-route.tsx +49 -0
  373. package/client/src/components/skip-link.tsx +22 -0
  374. package/client/src/components/stat-card.tsx +53 -0
  375. package/client/src/components/status-badge.tsx +96 -0
  376. package/client/src/components/ui/hierarchical-venue-selector.tsx +389 -0
  377. package/client/src/components/ui/toaster.tsx +111 -0
  378. package/client/src/contexts/auth-context.tsx +181 -0
  379. package/client/src/contexts/sidebar-state.tsx +50 -0
  380. package/client/src/contexts/theme-context.tsx +66 -0
  381. package/client/src/data/campaign-data.json +107 -0
  382. package/client/src/data/countries.json +22 -0
  383. package/client/src/hooks/use-approval.ts +366 -0
  384. package/client/src/hooks/use-keyboard-shortcuts.ts +74 -0
  385. package/client/src/hooks/use-media-query.ts +46 -0
  386. package/client/src/hooks/use-mobile.tsx +19 -0
  387. package/client/src/hooks/use-page-title.ts +21 -0
  388. package/client/src/hooks/use-toast.ts +195 -0
  389. package/client/src/index.css +694 -0
  390. package/client/src/lib/__tests__/accessibility.test.ts +104 -0
  391. package/client/src/lib/__tests__/date-utils.test.ts +199 -0
  392. package/client/src/lib/__tests__/dsp-buyer-api.test.ts +127 -0
  393. package/client/src/lib/__tests__/dsp-buyer-integration.test.ts +247 -0
  394. package/client/src/lib/__tests__/storage-utils.test.ts +167 -0
  395. package/client/src/lib/__tests__/utils.test.ts +57 -0
  396. package/client/src/lib/accessibility.ts +141 -0
  397. package/client/src/lib/api-config.ts +9 -0
  398. package/client/src/lib/auth-service.ts +209 -0
  399. package/client/src/lib/campaign-creative-api.ts +82 -0
  400. package/client/src/lib/company-api.ts +61 -0
  401. package/client/src/lib/content-hub-api.ts +407 -0
  402. package/client/src/lib/creative-mapper.ts +61 -0
  403. package/client/src/lib/date-utils.ts +119 -0
  404. package/client/src/lib/deal-helpers.ts +220 -0
  405. package/client/src/lib/dsp-buyer-api.ts +196 -0
  406. package/client/src/lib/geo-import-api.ts +151 -0
  407. package/client/src/lib/google-poi-api.ts +305 -0
  408. package/client/src/lib/i18n/__tests__/formatting.test.ts +202 -0
  409. package/client/src/lib/i18n/formatting.ts +130 -0
  410. package/client/src/lib/i18n/index.ts +8 -0
  411. package/client/src/lib/i18n-compat.ts +76 -0
  412. package/client/src/lib/influence-deals-api.ts +896 -0
  413. package/client/src/lib/inventory-api.ts +399 -0
  414. package/client/src/lib/oauth-service.ts +678 -0
  415. package/client/src/lib/poi-types.ts +75 -0
  416. package/client/src/lib/queryClient.ts +144 -0
  417. package/client/src/lib/recommendation-api.ts +380 -0
  418. package/client/src/lib/storage-utils.ts +104 -0
  419. package/client/src/lib/tolgee.ts +85 -0
  420. package/client/src/lib/utils.ts +0 -0
  421. package/client/src/main.tsx +67 -0
  422. package/client/src/mapbox-draw-modes.d.ts +32 -0
  423. package/client/src/pages/all-folders.tsx +203 -0
  424. package/client/src/pages/auth-callback.tsx +115 -0
  425. package/client/src/pages/buyer-form.tsx +339 -0
  426. package/client/src/pages/buyer-list.tsx +622 -0
  427. package/client/src/pages/content-hub.tsx +1358 -0
  428. package/client/src/pages/create-deal.tsx +2093 -0
  429. package/client/src/pages/creative-assignment-page.tsx +548 -0
  430. package/client/src/pages/creatives.tsx +5 -0
  431. package/client/src/pages/custom-pois.tsx +425 -0
  432. package/client/src/pages/dashboard.tsx +615 -0
  433. package/client/src/pages/deal-history.tsx +434 -0
  434. package/client/src/pages/deal-line-items.tsx +1703 -0
  435. package/client/src/pages/demo-status.tsx +113 -0
  436. package/client/src/pages/direct-campaign-details.tsx +361 -0
  437. package/client/src/pages/direct-campaigns-new.tsx +824 -0
  438. package/client/src/pages/dsp-form.tsx +803 -0
  439. package/client/src/pages/dsp-list.tsx +239 -0
  440. package/client/src/pages/folder-content.tsx +336 -0
  441. package/client/src/pages/integrations.tsx +429 -0
  442. package/client/src/pages/line-item-creatives.tsx +789 -0
  443. package/client/src/pages/line-item-detail-page.tsx +684 -0
  444. package/client/src/pages/line-item-form-page.tsx +3261 -0
  445. package/client/src/pages/line-item-wizard.tsx +1207 -0
  446. package/client/src/pages/login.tsx +154 -0
  447. package/client/src/pages/not-found.tsx +23 -0
  448. package/client/src/pages/proof-of-play.tsx +397 -0
  449. package/client/src/pages/public-approval.tsx +551 -0
  450. package/client/src/pages/reports.tsx +231 -0
  451. package/client/src/pages/settings.tsx +760 -0
  452. package/client/src/pages/signals.tsx +389 -0
  453. package/client/src/pages/tags.tsx +318 -0
  454. package/client/src/pages/test-results.tsx +328 -0
  455. package/client/src/store/hooks.ts +5 -0
  456. package/client/src/store/index.ts +15 -0
  457. package/client/src/store/mapMarkerLocationsSlice.ts +241 -0
  458. package/client/src/styles/design-tokens.css +324 -0
  459. package/client/src/test/setup.ts +261 -0
  460. package/client/src/test/test-utils.tsx +40 -0
  461. package/client/src/types/approval.ts +221 -0
  462. package/client/src/types/content-hub.ts +209 -0
  463. package/client/src/types/geofencing.ts +67 -0
  464. package/client/src/types/transcoding.ts +140 -0
  465. package/client/src/vite-env.d.ts +18 -0
  466. package/components.json +20 -0
  467. package/creative-api.json +1 -0
  468. package/docs/AI_REFERENCE.md +459 -0
  469. package/docs/MWDesign-Prompt.md +132 -0
  470. package/docs/MWDesign-System.md +344 -0
  471. package/docs/test-plan.md +277 -0
  472. package/e2e/AUTONOMOUS-TESTING.md +406 -0
  473. package/e2e/README.md +219 -0
  474. package/e2e/autonomous-flow.spec.ts +308 -0
  475. package/e2e/debug-sso.spec.ts +163 -0
  476. package/e2e/direct-campaigns.spec.ts +219 -0
  477. package/e2e/explore-sso.spec.ts +149 -0
  478. package/e2e/fixtures/auth.ts +26 -0
  479. package/e2e/fixtures/enhanced-test.ts +331 -0
  480. package/e2e/pagination.spec.ts +280 -0
  481. package/e2e/view-toggle.spec.ts +312 -0
  482. package/generated-icon.png +0 -0
  483. package/i18next-scanner.config.cjs +46 -0
  484. package/package.json +141 -0
  485. package/playwright.config.ts +93 -0
  486. package/postcss.config.js +6 -0
  487. package/replit.md +196 -0
  488. package/screenshot-after-login.png +0 -0
  489. package/screenshot-contenthub-grid.png +0 -0
  490. package/screenshot-contenthub-list-fixed.png +0 -0
  491. package/screenshot-contenthub-list.png +0 -0
  492. package/screenshot-create-deal.png +0 -0
  493. package/screenshot-dashboard.png +0 -0
  494. package/screenshot-deals.png +0 -0
  495. package/screenshot-login-filled.png +0 -0
  496. package/screenshot-login.png +0 -0
  497. package/screenshot.mjs +24 -0
  498. package/scripts/deploy-stg.sh +185 -0
  499. package/shared/direct-io-schema.ts +383 -0
  500. package/shared/schema.ts +439 -0
  501. package/shared/screen-types.ts +149 -0
  502. package/springdocDefault.json +1 -0
  503. package/swagger-ui-bundle.js +2 -0
  504. package/swagger-ui-init.js +10316 -0
  505. package/tailwind.config.ts +282 -0
  506. package/terraform/README.md +306 -0
  507. package/terraform/cloudfront.tf +289 -0
  508. package/terraform/ecs.tf +727 -0
  509. package/terraform/environments/dev.tfvars +59 -0
  510. package/terraform/environments/production.tfvars +60 -0
  511. package/terraform/main.tf +47 -0
  512. package/terraform/outputs.tf +145 -0
  513. package/terraform/s3.tf +192 -0
  514. package/terraform/variables.tf +226 -0
  515. package/terraform/waf.tf +165 -0
  516. package/terraform-frontend/.terraform.lock.hcl +25 -0
  517. package/terraform-frontend/README.md +85 -0
  518. package/terraform-frontend/cloudfront.tf +125 -0
  519. package/terraform-frontend/main.tf +31 -0
  520. package/terraform-frontend/outputs.tf +24 -0
  521. package/terraform-frontend/terraform.tfvars +12 -0
  522. package/terraform-frontend/variables.tf +53 -0
  523. package/tsconfig.json +23 -0
  524. package/vite.config.ts +226 -0
  525. package/vitest.config.ts +56 -0
@@ -0,0 +1,896 @@
1
+ // Influence Deals API Client
2
+ // Manages deals, line items, creatives, and inventories
3
+
4
+ import { directCampaignAuth } from "./auth-service";
5
+
6
+ // ============================================================================
7
+ // CUSTOM API ERROR CLASS
8
+ // ============================================================================
9
+
10
+ export interface APIValidationError {
11
+ field: string;
12
+ message: string;
13
+ }
14
+
15
+ export interface APIErrorResponse {
16
+ code?: string;
17
+ message?: string;
18
+ errors?: APIValidationError[];
19
+ }
20
+
21
+ export class APIError extends Error {
22
+ public readonly code: string;
23
+ public readonly errors: APIValidationError[];
24
+ public readonly statusCode: number;
25
+
26
+ constructor(
27
+ message: string,
28
+ code: string = "UNKNOWN_ERROR",
29
+ errors: APIValidationError[] = [],
30
+ statusCode: number = 500,
31
+ ) {
32
+ super(message);
33
+ this.name = "APIError";
34
+ this.code = code;
35
+ this.errors = errors;
36
+ this.statusCode = statusCode;
37
+ }
38
+
39
+ isValidationError(): boolean {
40
+ return this.code === "VALIDATION_ERROR" && this.errors.length > 0;
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Format API error for display in toast messages
46
+ * Shows validation errors if available, otherwise shows generic message
47
+ */
48
+ export function formatAPIErrorForToast(error: unknown): string {
49
+ if (error instanceof APIError) {
50
+ if (error.isValidationError() && error.errors.length > 0) {
51
+ return error.errors.map((e) => `${e.field}: ${e.message}`).join("\n");
52
+ }
53
+ return error.message;
54
+ }
55
+
56
+ if (error && typeof error === "object") {
57
+ const err = error as any;
58
+ if (err.errors && Array.isArray(err.errors) && err.errors.length > 0) {
59
+ return err.errors
60
+ .map((e: APIValidationError) => `${e.field}: ${e.message}`)
61
+ .join("\n");
62
+ }
63
+ if (err.message) {
64
+ return err.message;
65
+ }
66
+ }
67
+
68
+ if (error instanceof Error) {
69
+ return error.message;
70
+ }
71
+
72
+ return "An unexpected error occurred. Please try again.";
73
+ }
74
+
75
+ // API endpoint from environment variable
76
+ const INFLUENCE_DEALS_BASE_URL = import.meta.env.VITE_INFLUENCE_DEALS_API_URL;
77
+
78
+ // Public Approval API base URL (no auth required)
79
+ // Uses the same external API server as authenticated endpoints
80
+ const PUBLIC_APPROVAL_BASE_URL = (() => {
81
+ if (INFLUENCE_DEALS_BASE_URL) {
82
+ try {
83
+ const url = new URL(INFLUENCE_DEALS_BASE_URL);
84
+ return `${url.origin}/api/v1/public/approval`;
85
+ } catch {
86
+ const baseUrl = INFLUENCE_DEALS_BASE_URL.replace(/\/api\/v1\/rest$/, '');
87
+ return `${baseUrl}/api/v1/public/approval`;
88
+ }
89
+ }
90
+ console.warn('[Public Approval API] VITE_INFLUENCE_DEALS_API_URL is not set. Public approval endpoints may not work.');
91
+ return '/api/v1/public/approval';
92
+ })();
93
+
94
+ // Helper function to construct public approval URLs
95
+ function buildPublicApprovalUrl(path: string, params?: Record<string, any>): string {
96
+ const url = `${PUBLIC_APPROVAL_BASE_URL}${path}`;
97
+ if (!params) return url;
98
+
99
+ const searchParams = new URLSearchParams();
100
+ Object.entries(params).forEach(([key, value]) => {
101
+ if (value !== undefined && value !== null) {
102
+ searchParams.set(key, String(value));
103
+ }
104
+ });
105
+
106
+ const query = searchParams.toString();
107
+ return query ? `${url}?${query}` : url;
108
+ }
109
+
110
+ // Helper function to construct URLs
111
+ function buildUrl(path: string, params?: Record<string, any>): string {
112
+ const url = `${INFLUENCE_DEALS_BASE_URL}${path}`;
113
+ if (!params) return url;
114
+
115
+ const searchParams = new URLSearchParams();
116
+ Object.entries(params).forEach(([key, value]) => {
117
+ if (value !== undefined && value !== null) {
118
+ searchParams.set(key, String(value));
119
+ }
120
+ });
121
+
122
+ const query = searchParams.toString();
123
+ return query ? `${url}?${query}` : url;
124
+ }
125
+
126
+ // Generate a unique external ID for deals and line items
127
+ export function generateExternalId(): string {
128
+ return `ext-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
129
+ }
130
+
131
+ // Editable deal statuses - only these statuses allow editing deals and line items
132
+ const EDITABLE_DEAL_STATUSES = ['DRAFT', 'GENERATED', 'REOPENED'];
133
+
134
+ /**
135
+ * Check if a deal status allows editing operations (edit deal, edit/clone/delete line items)
136
+ * Only DRAFT, GENERATED, and REOPENED statuses are editable
137
+ */
138
+ export function isDealEditable(status: string | undefined | null): boolean {
139
+ if (!status) return false;
140
+ return EDITABLE_DEAL_STATUSES.includes(status.toUpperCase());
141
+ }
142
+
143
+ // ============================================================================
144
+ // TYPE DEFINITIONS
145
+ // ============================================================================
146
+
147
+ export interface DealSeller {
148
+ publisher_id: string;
149
+ publisher_name: string;
150
+ }
151
+
152
+ export interface DealAccount {
153
+ account_id: string;
154
+ account_name: string;
155
+ }
156
+
157
+ export interface DealBuyer {
158
+ dsp: string;
159
+ seatId: string;
160
+ buyerName: string;
161
+ }
162
+
163
+ export interface DealProgrammatic {
164
+ buyers: DealBuyer[];
165
+ auctionType: number;
166
+ transactionType: string;
167
+ costType: string;
168
+ published: boolean;
169
+ reopened: boolean;
170
+ nonBillable: boolean;
171
+ stopBidRequests: boolean;
172
+ }
173
+
174
+ export interface DealBudgetSetup {
175
+ budgetAmount?: number;
176
+ budgetType?: string;
177
+ }
178
+
179
+ export interface DealDirect {
180
+ budgetSetup?: DealBudgetSetup;
181
+ approvalEmails?: string[];
182
+ }
183
+
184
+ export interface Deal {
185
+ id: string;
186
+ source: string;
187
+ externalId: string;
188
+ dealId: string;
189
+ name: string;
190
+ dealType:
191
+ | "GUARANTEED"
192
+ | "PREFERRED_DEAL"
193
+ | "PRIVATE_AUCTION"
194
+ | "EVERGREEN_PMP";
195
+ advertiser: string | null;
196
+ seller: DealSeller;
197
+ currency: string;
198
+ timezoneId: string | null;
199
+ startDate: string | null;
200
+ endDate: string | null;
201
+ account: DealAccount;
202
+ country: string;
203
+ status: "DRAFT" | "LIVE" | "PAUSED" | "COMPLETED" | "ARCHIVED" | "APPROVED" | "REJECTED" | "PENDING" | "REVIEWING" | "REOPENED" | "EXPIRED" | "REQUESTED" | "GENERATED" | "ACTIVE";
204
+ active: boolean;
205
+ isPlaying: boolean;
206
+ publishers: { id: string; name: string }[];
207
+ metadata: any;
208
+ version: number;
209
+ mode: string | null;
210
+ createdAt: string;
211
+ updatedAt: string;
212
+ programmatic: DealProgrammatic;
213
+ direct?: DealDirect;
214
+ // Additional fields for campaign wizard
215
+ brand?: string;
216
+ clientType?: string;
217
+ approvalEmails?: string[];
218
+ targetCountry?: string;
219
+ totalBudget?: number;
220
+ dailyBudgetCap?: number;
221
+ }
222
+
223
+ export interface LineItemBudgetSetup {
224
+ currency?: string;
225
+ budgetType?: string;
226
+ budgetAmount?: number;
227
+ }
228
+
229
+ export interface LineItemCampaignGoal {
230
+ type?: string;
231
+ targetValue?: number;
232
+ }
233
+
234
+ export interface LineItemDirect {
235
+ budgetSetup?: LineItemBudgetSetup;
236
+ campaignGoal?: LineItemCampaignGoal;
237
+ pricing?: {
238
+ cpmBase?: number;
239
+ estimatedCostBase?: number;
240
+ };
241
+ }
242
+
243
+ export interface LineItemProgrammatic {
244
+ bidFloor?: number;
245
+ bidFloorBase?: number;
246
+ netCost?: number;
247
+ impressions?: number;
248
+ impMultiplier?: number;
249
+ }
250
+
251
+ export interface ProgrammaticLineItem {
252
+ name: string;
253
+ startDate: string;
254
+ endDate: string;
255
+ status: string;
256
+ inventories: LineItemInventory[];
257
+ programmatic: LineItemProgrammatic;
258
+ targeting?: any;
259
+ }
260
+
261
+ export interface DirectLineItem {
262
+ name: string;
263
+ startDate: string;
264
+ endDate: string;
265
+ status: string;
266
+ inventories: LineItemInventory[];
267
+ targetQuantity?: number;
268
+ budget?: number;
269
+ pacing?: any;
270
+ direct?: LineItemDirect;
271
+ deliveryTargeting?: any;
272
+ planning?: any;
273
+ pricing?: {
274
+ cpmBase?: number;
275
+ estimatedCostBase?: number;
276
+ };
277
+ }
278
+
279
+ export interface LineItem {
280
+ id: string;
281
+ name: string;
282
+ goalType: "IMPRESSIONS" | "BUDGET" | "UNLIMITED";
283
+ targetQuantity: number;
284
+ budget: number;
285
+ pacing: "EVEN" | "ASAP" | "CUSTOM";
286
+ startDate: string;
287
+ totalInventories: number;
288
+ endDate: string;
289
+ status: "DRAFT" | "ACTIVE" | "PAUSED" | "COMPLETED";
290
+ inventories: LineItemInventory[];
291
+ scheduleGrids?: ScheduleGrid[];
292
+ direct?: LineItemDirect;
293
+ programmatic?: LineItemProgrammatic;
294
+ createdAt?: string;
295
+ updatedAt?: string;
296
+ dealId?: string;
297
+ pricing?: {
298
+ cpmBase?: number;
299
+ estimatedCostBase?: number;
300
+ };
301
+ }
302
+
303
+ export interface LineItemInventory {
304
+ id: string;
305
+ inventoryId: string;
306
+ name: string;
307
+ type: "SCREEN" | "NETWORK" | "PACKAGE";
308
+ address?: string;
309
+ tags?: string[];
310
+ screenCount?: number;
311
+ pricePerDay?: number;
312
+ }
313
+
314
+ export interface ScheduleGrid {
315
+ date: string;
316
+ hours: number[]; // 0-23 representing active hours
317
+ }
318
+
319
+ export interface Creative {
320
+ id: string;
321
+ name: string;
322
+ type: "IMAGE" | "VIDEO";
323
+ mimeType: string;
324
+ size: number;
325
+ resolution: string;
326
+ duration?: number;
327
+ url: string;
328
+ thumbnailUrl?: string;
329
+ status: "PROCESSING" | "ACCEPTED" | "REJECTED" | "INADEQUATE";
330
+ tags?: string[];
331
+ uploadedBy?: string;
332
+ lineItemIds?: string[]; // Creatives can be assigned to multiple line items
333
+ createdAt?: string;
334
+ updatedAt?: string;
335
+ }
336
+
337
+ export interface DealListResponse {
338
+ requestId: string;
339
+ status: number;
340
+ result: {
341
+ data: Deal[];
342
+ pagination: {
343
+ page: number;
344
+ limit: number;
345
+ total: number;
346
+ totalPages: number;
347
+ };
348
+ };
349
+ }
350
+
351
+ export interface DealResponse {
352
+ requestId: string;
353
+ status: number;
354
+ result: Deal;
355
+ }
356
+
357
+ // ============================================================================
358
+ // API ENDPOINTS
359
+ // ============================================================================
360
+
361
+ export const InfluenceDealsAPI = {
362
+ // ============================================================================
363
+ // DEALS (Campaigns)
364
+ // ============================================================================
365
+ deals: {
366
+ // List deals with pagination and filters
367
+ list: (params?: {
368
+ page?: number;
369
+ limit?: number;
370
+ search?: string;
371
+ source?: string;
372
+ currency?: string;
373
+ brand?: string;
374
+ advertiser?: string;
375
+ publisher?: string;
376
+ publisherId?: string;
377
+ startDate?: string;
378
+ endDate?: string;
379
+ status?: string;
380
+ }) => buildUrl("/deals", params),
381
+
382
+ // Get single deal by ID
383
+ get: (dealId: string) => buildUrl(`/deals/${dealId}`),
384
+
385
+ // Create deal
386
+ create: () => `${INFLUENCE_DEALS_BASE_URL}/deals`,
387
+
388
+ // Update deal
389
+ update: (dealId: string) => `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}`,
390
+
391
+ // Archive deal
392
+ archive: (dealId: string) => `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}`,
393
+
394
+ // Bulk sync deals with line items, inventories, and creatives
395
+ sync: () => `${INFLUENCE_DEALS_BASE_URL}/deals/sync`,
396
+
397
+ // Get deal history/activity log
398
+ history: (
399
+ dealId: string,
400
+ params?: { page?: number; limit?: number; action?: string },
401
+ ) => buildUrl(`/deals/${dealId}/history`, params),
402
+
403
+ // Get deal-level inventories (minified format)
404
+ inventoriesMinified: (dealId: string) =>
405
+ buildUrl(`/deals/${dealId}/inventories/minified`),
406
+ },
407
+
408
+ // ============================================================================
409
+ // LINE ITEMS
410
+ // ============================================================================
411
+ lineItems: {
412
+ // List line items by deal
413
+ list: (dealId: string, params?: { page?: number; limit?: number }) =>
414
+ buildUrl(`/deals/${dealId}/line-items`, params),
415
+
416
+ // Get single line item
417
+ get: (dealId: string, lineItemId: string) =>
418
+ buildUrl(`/deals/${dealId}/line-items/${lineItemId}`),
419
+
420
+ // Create line item
421
+ create: (dealId: string) =>
422
+ `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}/line-items`,
423
+
424
+ // Update line item
425
+ update: (dealId: string, lineItemId: string) =>
426
+ `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}/line-items/${lineItemId}`,
427
+
428
+ // Delete line item
429
+ delete: (dealId: string, lineItemId: string) =>
430
+ `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}/line-items/${lineItemId}`,
431
+
432
+ // Get line item inventories with pagination
433
+ inventories: (
434
+ dealId: string,
435
+ lineItemId: string,
436
+ params?: { page?: number; limit?: number },
437
+ ) =>
438
+ buildUrl(`/deals/${dealId}/line-items/${lineItemId}/inventories`, params),
439
+
440
+ // Update line item inventories (separate endpoint from line item update)
441
+ updateInventories: (dealId: string, lineItemId: string) =>
442
+ `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}/line-items/${lineItemId}/inventories`,
443
+ },
444
+
445
+ // ============================================================================
446
+ // CREATIVES
447
+ // ============================================================================
448
+ creatives: {
449
+ // List creatives by deal
450
+ listByDeal: (dealId: string, params?: { page?: number; limit?: number }) =>
451
+ buildUrl(`/deals/${dealId}/creatives`, params),
452
+
453
+ // List creatives by line item
454
+ listByLineItem: (
455
+ dealId: string,
456
+ lineItemId: string,
457
+ params?: { page?: number; limit?: number },
458
+ ) =>
459
+ buildUrl(`/deals/${dealId}/line-items/${lineItemId}/creatives`, params),
460
+
461
+ // Create creative for line item
462
+ create: (dealId: string, lineItemId: string) =>
463
+ `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}/line-items/${lineItemId}/creatives`,
464
+
465
+ // Delete creative
466
+ delete: (dealId: string, lineItemId: string, creativeId: string) =>
467
+ `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}/line-items/${lineItemId}/creatives/${creativeId}`,
468
+ },
469
+
470
+ // ============================================================================
471
+ // SYSTEM
472
+ // ============================================================================
473
+ system: {
474
+ // Health check
475
+ health: () => `${INFLUENCE_DEALS_BASE_URL}/health`,
476
+ },
477
+
478
+ // ============================================================================
479
+ // CAMPAIGN APPROVAL (Internal - Authenticated)
480
+ // ============================================================================
481
+ approval: {
482
+ // Request campaign approval - sends emails to approvers
483
+ request: (dealId: string) =>
484
+ `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}/approval/request`,
485
+
486
+ // Get approval history for a deal
487
+ history: (dealId: string) =>
488
+ `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}/approval/history`,
489
+
490
+ // Resend approval email to selected approvers
491
+ resend: (dealId: string) =>
492
+ `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}/approval/resend`,
493
+ },
494
+
495
+ // ============================================================================
496
+ // DEAL REOPEN (DIRECT mode only)
497
+ // ============================================================================
498
+ reopen: {
499
+ // Reopen a DIRECT deal - allows further edits
500
+ // Allowed from: APPROVED, LIVE, COMPLETED, EXPIRED, REJECTED, ARCHIVED
501
+ reopen: (dealId: string) =>
502
+ `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}/reopen`,
503
+ },
504
+
505
+ // ============================================================================
506
+ // DEAL STATUS TRANSITIONS
507
+ // ============================================================================
508
+ status: {
509
+ // Transition a campaign to a new status with workflow-aware validation
510
+ // Guardrails: LIVE requires delivery confirmation, COMPLETED/EXPIRED by SCHEDULER only
511
+ transition: (dealId: string) =>
512
+ `${INFLUENCE_DEALS_BASE_URL}/deals/${dealId}/status`,
513
+
514
+ // Get all campaign status definitions
515
+ definitions: (workflow?: 'DIRECT' | 'PROGRAMMATIC') =>
516
+ `${INFLUENCE_DEALS_BASE_URL}/deals/status/definitions${workflow ? `?workflow=${workflow}` : ''}`,
517
+ },
518
+
519
+ // ============================================================================
520
+ // PUBLIC APPROVAL (External - Token-based, no auth)
521
+ // ============================================================================
522
+ publicApproval: {
523
+ // Get campaign details for approval
524
+ campaign: (token: string) =>
525
+ buildPublicApprovalUrl('/campaign', { token }),
526
+
527
+ // Get line items for approval
528
+ lineItems: (token: string) =>
529
+ buildPublicApprovalUrl('/line-items', { token }),
530
+
531
+ // Get inventories for approval
532
+ inventories: (token: string, lineItemId?: string) =>
533
+ buildPublicApprovalUrl('/inventories', { token, ...(lineItemId && { lineItemId }) }),
534
+
535
+ // Request OTP verification
536
+ requestOtp: () => `${PUBLIC_APPROVAL_BASE_URL}/otp/request`,
537
+
538
+ // Verify OTP
539
+ verifyOtp: () => `${PUBLIC_APPROVAL_BASE_URL}/otp/verify`,
540
+
541
+ // Submit approval decision
542
+ decision: () => `${PUBLIC_APPROVAL_BASE_URL}/decision`,
543
+ },
544
+ };
545
+
546
+ // ============================================================================
547
+ // RESPONSE HANDLERS
548
+ // ============================================================================
549
+
550
+ /**
551
+ * Helper function to handle API responses
552
+ * Throws APIError with validation errors preserved for toast display
553
+ */
554
+ export async function handleInfluenceDealsResponse<T>(
555
+ response: Response,
556
+ ): Promise<T> {
557
+ const data = await response.json();
558
+
559
+ if (!response.ok) {
560
+ const errorMessage = data.message || data.error || "API request failed";
561
+ const errorCode = data.code || "UNKNOWN_ERROR";
562
+ const validationErrors: APIValidationError[] = data.errors || [];
563
+
564
+ throw new APIError(
565
+ errorMessage,
566
+ errorCode,
567
+ validationErrors,
568
+ response.status,
569
+ );
570
+ }
571
+
572
+ // Return the result from the wrapped response
573
+ return data.result || data;
574
+ }
575
+
576
+ /**
577
+ * Make an authenticated request to the Influence Deals API
578
+ */
579
+ export async function influenceDealsRequest<T>(
580
+ url: string,
581
+ method: string = "GET",
582
+ body?: any,
583
+ ): Promise<T> {
584
+ const options: RequestInit = {
585
+ method,
586
+ headers: {
587
+ "Content-Type": "application/json",
588
+ Accept: "application/json",
589
+ },
590
+ };
591
+
592
+ if (body) {
593
+ options.body = JSON.stringify(body);
594
+ }
595
+
596
+ const response = await directCampaignAuth.fetch(url, options);
597
+ return handleInfluenceDealsResponse<T>(response);
598
+ }
599
+
600
+ // ============================================================================
601
+ // DATA MAPPERS - Convert between old and new formats
602
+ // ============================================================================
603
+
604
+ /**
605
+ * Map old campaign format to new deal format
606
+ */
607
+ export function mapCampaignToDeal(
608
+ campaign: any,
609
+ existingExternalId?: string,
610
+ ): Partial<Deal> & { externalId: string } {
611
+ return {
612
+ externalId:
613
+ existingExternalId || campaign.externalId || generateExternalId(),
614
+ name: campaign.name,
615
+ dealType: campaign.dealType || "GUARANTEED",
616
+ advertiser: campaign.brand,
617
+ currency: campaign.currency || "MYR",
618
+ startDate: campaign.startDate,
619
+ endDate: campaign.endDate,
620
+ country: campaign.targetCountry || campaign.country,
621
+ status: campaign.status || "DRAFT",
622
+ // Extended fields for wizard
623
+ brand: campaign.brand,
624
+ clientType: campaign.clientType,
625
+ approvalEmails: campaign.approvalEmails,
626
+ targetCountry: campaign.targetCountry,
627
+ totalBudget: campaign.totalBudget,
628
+ dailyBudgetCap: campaign.dailyBudgetCap,
629
+ };
630
+ }
631
+
632
+ /**
633
+ * Map deal format back to campaign format for compatibility
634
+ */
635
+ export function mapDealToCampaign(deal: Deal): any {
636
+ return {
637
+ id: deal.id,
638
+ name: deal.name,
639
+ dealType: deal.dealType,
640
+ brand: deal.advertiser || deal.brand,
641
+ clientType: deal.clientType,
642
+ currency: deal.currency,
643
+ startDate: deal.startDate,
644
+ endDate: deal.endDate,
645
+ country: deal.country,
646
+ targetCountry: deal.targetCountry || deal.country,
647
+ status: deal.status,
648
+ approvalEmails: deal.approvalEmails,
649
+ totalBudget: deal.totalBudget,
650
+ dailyBudgetCap: deal.dailyBudgetCap,
651
+ createdAt: deal.createdAt,
652
+ updatedAt: deal.updatedAt,
653
+ };
654
+ }
655
+
656
+ /**
657
+ * Build PROGRAMMATIC line item payload
658
+ * Programmatic deals only support basic targeting, bidFloor, netCost, impressions, and impMultiplier
659
+ * No deliveryTargeting or planning data for programmatic
660
+ */
661
+ export function buildProgrammaticLineItemPayload(
662
+ lineItem: any,
663
+ dealType: string,
664
+ ): ProgrammaticLineItem {
665
+ const payload: any = {
666
+ name: lineItem.name,
667
+ startDate: lineItem.startDate,
668
+ endDate: lineItem.endDate,
669
+ status: lineItem.status || "DRAFT",
670
+ inventories: lineItem.inventories || [],
671
+ programmatic: lineItem.programmatic || {
672
+ bidFloor: 0,
673
+ netCost: 0,
674
+ impressions: 0,
675
+ impMultiplier: { type: "ALL_TIME" },
676
+ },
677
+ targeting: lineItem.targeting,
678
+ };
679
+
680
+ if (lineItem.priority !== undefined) payload.priority = lineItem.priority;
681
+ if (lineItem.creativeType) payload.creativeType = lineItem.creativeType;
682
+ if (lineItem.duration !== undefined) payload.duration = lineItem.duration;
683
+ if (lineItem.creativeSource) payload.creativeSource = lineItem.creativeSource;
684
+ if (lineItem.timezoneId) payload.timezoneId = lineItem.timezoneId;
685
+ if (lineItem.publisherId) payload.publisherId = lineItem.publisherId;
686
+ if (lineItem.currency) payload.currency = lineItem.currency;
687
+ if (lineItem.resolutions?.length) payload.resolutions = lineItem.resolutions;
688
+ if (lineItem.schedule?.length) payload.schedule = lineItem.schedule;
689
+ if (lineItem.pacing) payload.pacing = lineItem.pacing;
690
+ if (lineItem.bidFloor !== undefined) payload.bidFloor = lineItem.bidFloor;
691
+ if (lineItem.bidFloorBase !== undefined) payload.bidFloorBase = lineItem.bidFloorBase;
692
+ if (lineItem.netCost !== undefined) payload.netCost = lineItem.netCost;
693
+ if (lineItem.impressions !== undefined) payload.impressions = lineItem.impressions;
694
+
695
+ if (lineItem.customFees?.length) payload.customFees = lineItem.customFees;
696
+ if (lineItem.frequencyCap) payload.frequencyCap = lineItem.frequencyCap;
697
+ if (lineItem.trafficAllocation !== undefined) payload.trafficAllocation = lineItem.trafficAllocation;
698
+ if (lineItem.inventorySource) payload.inventorySource = lineItem.inventorySource;
699
+
700
+ if (dealType === "GUARANTEED" && lineItem.thresholdCountPerDay) {
701
+ payload.thresholdCountPerDay = lineItem.thresholdCountPerDay;
702
+ }
703
+
704
+ return payload;
705
+ }
706
+
707
+ /**
708
+ * Build DIRECT line item payload
709
+ * Direct deals support full targeting, deliveryTargeting, planning, budgetSetup, campaignGoal, and pacing
710
+ */
711
+ export function buildDirectLineItemPayload(
712
+ lineItem: any,
713
+ ): DirectLineItem {
714
+ const payload: any = {
715
+ name: lineItem.name,
716
+ startDate: lineItem.startDate,
717
+ endDate: lineItem.endDate,
718
+ status: lineItem.status || "DRAFT",
719
+ inventories: lineItem.inventories || [],
720
+ targetQuantity: lineItem.targetQuantity || lineItem.impressionsGoal,
721
+ budget: lineItem.budget,
722
+ pacing: lineItem.pacing,
723
+ direct: lineItem.direct,
724
+ deliveryTargeting: lineItem.deliveryTargeting,
725
+ planning: lineItem.planning,
726
+ };
727
+
728
+ if (lineItem.priority !== undefined) payload.priority = lineItem.priority;
729
+ if (lineItem.creativeType) payload.creativeType = lineItem.creativeType;
730
+ if (lineItem.duration !== undefined) payload.duration = lineItem.duration;
731
+ if (lineItem.creativeSource) payload.creativeSource = lineItem.creativeSource;
732
+ if (lineItem.timezoneId) payload.timezoneId = lineItem.timezoneId;
733
+ if (lineItem.publisherId) payload.publisherId = lineItem.publisherId;
734
+ if (lineItem.currency) payload.currency = lineItem.currency;
735
+ if (lineItem.resolutions?.length) payload.resolutions = lineItem.resolutions;
736
+ if (lineItem.schedule?.length) payload.schedule = lineItem.schedule;
737
+ if (lineItem.customFees?.length) payload.customFees = lineItem.customFees;
738
+ if (lineItem.frequencyCap) payload.frequencyCap = lineItem.frequencyCap;
739
+ if (lineItem.trafficAllocation !== undefined) payload.trafficAllocation = lineItem.trafficAllocation;
740
+ if (lineItem.inventorySource) payload.inventorySource = lineItem.inventorySource;
741
+
742
+ return payload;
743
+ }
744
+
745
+ /**
746
+ * Map line item with embedded inventories and schedule
747
+ * Supports both DIRECT and PROGRAMMATIC deal modes
748
+ * @param lineItem The line item data
749
+ * @param mode The deal mode (DIRECT or PROGRAMMATIC)
750
+ * @param dealType The deal type (for PROGRAMMATIC: GUARANTEED, PRIVATE_AUCTION, EVERGREEN_PMP, PREFERRED_DEAL)
751
+ */
752
+ export function mapLineItemForAPI(
753
+ lineItem: any,
754
+ mode?: string,
755
+ dealType?: string,
756
+ ): ProgrammaticLineItem | DirectLineItem | Partial<LineItem> {
757
+ // If mode is provided, use the appropriate builder
758
+ if (mode) {
759
+ const upperMode = mode.toUpperCase();
760
+ if (upperMode === "PROGRAMMATIC") {
761
+ return buildProgrammaticLineItemPayload(lineItem, dealType || "GUARANTEED");
762
+ } else if (upperMode === "DIRECT") {
763
+ return buildDirectLineItemPayload(lineItem);
764
+ }
765
+ }
766
+
767
+ // Fallback to original behavior for backward compatibility
768
+ return {
769
+ name: lineItem.name,
770
+ targetQuantity: lineItem.targetQuantity || lineItem.impressionsGoal,
771
+ budget: lineItem.budget,
772
+ pacing: lineItem.pacing,
773
+ startDate: lineItem.startDate,
774
+ endDate: lineItem.endDate,
775
+ status: lineItem.status || "DRAFT",
776
+ inventories: lineItem.inventories || [],
777
+ };
778
+ }
779
+
780
+ /**
781
+ * Parse latitude and longitude from POINT geometry string
782
+ * Format: "POINT(longitude latitude)"
783
+ */
784
+ function parsePointGeometry(geom: string): { latitude: number; longitude: number } | null {
785
+ if (!geom || typeof geom !== 'string') return null;
786
+ const match = geom.match(/POINT\(([-\d.]+)\s+([-\d.]+)\)/i);
787
+ if (match) {
788
+ return {
789
+ longitude: parseFloat(match[1]),
790
+ latitude: parseFloat(match[2]),
791
+ };
792
+ }
793
+ return null;
794
+ }
795
+
796
+ /**
797
+ * Map inventory data from JAD API format to Influence Deals API format
798
+ * Includes all relevant fields for the inventory update payload
799
+ */
800
+ export function mapInventoryForAPI(inv: any): Record<string, any> {
801
+ const inventory: Record<string, any> = {
802
+ id: inv.id || inv.inventoryId,
803
+ };
804
+
805
+ if (inv.name) {
806
+ inventory.name = inv.name;
807
+ }
808
+
809
+ if (inv.timeZone) {
810
+ inventory.timezone = inv.timeZone;
811
+ }
812
+
813
+ if (inv.thumbnailUrl) {
814
+ inventory.thumbnail = inv.thumbnailUrl;
815
+ }
816
+
817
+ if (inv.typeName) {
818
+ inventory.venueType = inv.typeName;
819
+ } else if (inv.environment) {
820
+ inventory.venueType = inv.environment.toUpperCase();
821
+ }
822
+
823
+ if (inv.mediaOwnerId || inv.mediaOwnerName) {
824
+ inventory.publisher = {
825
+ id: inv.mediaOwnerId,
826
+ name: inv.mediaOwnerName,
827
+ };
828
+ }
829
+
830
+ if (inv.geoms && Array.isArray(inv.geoms) && inv.geoms.length > 0) {
831
+ const coords = parsePointGeometry(inv.geoms[0]);
832
+ if (coords) {
833
+ inventory.latitude = coords.latitude;
834
+ inventory.longitude = coords.longitude;
835
+ }
836
+ }
837
+
838
+ if (inv.panels && Array.isArray(inv.panels) && inv.panels.length > 0) {
839
+ const panel = inv.panels[0];
840
+ if (panel.pixelWidth && panel.pixelHeight) {
841
+ inventory.size = `${panel.pixelWidth}x${panel.pixelHeight}`;
842
+ }
843
+ }
844
+
845
+ if (inv.digitalFields) {
846
+ if (inv.digitalFields.spotDuration) {
847
+ inventory.spotDuration = inv.digitalFields.spotDuration;
848
+ }
849
+ if (inv.digitalFields.loopsPerHour && inv.digitalFields.spotsPerLoop) {
850
+ inventory.spotsPerHour = inv.digitalFields.loopsPerHour * inv.digitalFields.spotsPerLoop;
851
+ } else if (inv.digitalFields.loopsPerHour) {
852
+ inventory.spotsPerHour = inv.digitalFields.loopsPerHour;
853
+ }
854
+ }
855
+
856
+ if (inv.typePath) {
857
+ inventory.venueTypeIds = [inv.typePath];
858
+ }
859
+
860
+ if (inv.externalIds && Array.isArray(inv.externalIds)) {
861
+ const lmxEntry = inv.externalIds.find((ext: any) => ext.platform === 'LMX');
862
+ if (lmxEntry && lmxEntry.externalId) {
863
+ inventory.referenceId = lmxEntry.externalId;
864
+ }
865
+ }
866
+
867
+ if (inv.planning) {
868
+ inventory.planning = {
869
+ capacity: inv.planning.capacity ? {
870
+ campaignDays: inv.planning.capacity.campaignDays,
871
+ available: inv.planning.capacity.available ? {
872
+ slots: inv.planning.capacity.available.slots || 0,
873
+ playTimeSec: inv.planning.capacity.available.playTimeSec || 0,
874
+ maxImpressions: inv.planning.capacity.available.maxImpressions || 0,
875
+ } : undefined,
876
+ } : undefined,
877
+ allocation: inv.planning.allocation ? {
878
+ slots: inv.planning.allocation.slots || 0,
879
+ playTimeSec: inv.planning.allocation.playTimeSec || 0,
880
+ sov: inv.planning.allocation.sov || 0,
881
+ sot: inv.planning.allocation.sot || 0,
882
+ } : undefined,
883
+ estimates: inv.planning.estimates ? {
884
+ impressions: inv.planning.estimates.impressions || 0,
885
+ reach: inv.planning.estimates.reach || 0,
886
+ frequency: inv.planning.estimates.frequency || 0,
887
+ } : undefined,
888
+ pricing: inv.planning.pricing ? {
889
+ cpm: inv.planning.pricing.cpm || 0,
890
+ estimatedCost: inv.planning.pricing.estimatedCost || 0,
891
+ } : undefined,
892
+ };
893
+ }
894
+
895
+ return inventory;
896
+ }