@surfside/ads-core 2.0.1 → 2.0.2

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 (274) hide show
  1. package/README.md +15 -15
  2. package/lib/cjs/Api.js +195 -0
  3. package/lib/cjs/Api.js.map +1 -0
  4. package/lib/cjs/helpers/Generator.js +50 -0
  5. package/lib/cjs/helpers/Generator.js.map +1 -0
  6. package/lib/cjs/helpers/Handlebars.js +270 -0
  7. package/lib/cjs/helpers/Handlebars.js.map +1 -0
  8. package/lib/cjs/helpers/NativeRequestBuilder.js +174 -0
  9. package/lib/cjs/helpers/NativeRequestBuilder.js.map +1 -0
  10. package/lib/cjs/helpers/RequestBuilder.js +160 -0
  11. package/lib/cjs/helpers/RequestBuilder.js.map +1 -0
  12. package/lib/cjs/helpers/TryGet.js +14 -0
  13. package/lib/cjs/helpers/TryGet.js.map +1 -0
  14. package/lib/cjs/helpers/Window.js +24 -0
  15. package/lib/cjs/helpers/Window.js.map +1 -0
  16. package/lib/cjs/helpers/index.js +24 -0
  17. package/lib/cjs/helpers/index.js.map +1 -0
  18. package/lib/cjs/helpers/response/Banner.js +4 -0
  19. package/lib/cjs/helpers/response/Banner.js.map +1 -0
  20. package/lib/cjs/helpers/response/BuiltResponse.js +27 -0
  21. package/lib/cjs/helpers/response/BuiltResponse.js.map +1 -0
  22. package/lib/cjs/helpers/response/Carousel.js +282 -0
  23. package/lib/cjs/helpers/response/Carousel.js.map +1 -0
  24. package/lib/cjs/helpers/response/Clickthrough.js +24 -0
  25. package/lib/cjs/helpers/response/Clickthrough.js.map +1 -0
  26. package/lib/cjs/helpers/response/ProductCard.js +198 -0
  27. package/lib/cjs/helpers/response/ProductCard.js.map +1 -0
  28. package/lib/cjs/helpers/response/Video.js +4 -0
  29. package/lib/cjs/helpers/response/Video.js.map +1 -0
  30. package/lib/cjs/helpers/response/index.js +23 -0
  31. package/lib/cjs/helpers/response/index.js.map +1 -0
  32. package/lib/cjs/index.js +21 -3488
  33. package/lib/cjs/index.js.map +1 -54
  34. package/lib/cjs/models/dynamic/DynamicZone.js +12 -0
  35. package/lib/cjs/models/dynamic/DynamicZone.js.map +1 -0
  36. package/lib/cjs/models/dynamic/index.js +18 -0
  37. package/lib/cjs/models/dynamic/index.js.map +1 -0
  38. package/lib/cjs/models/index.js +22 -0
  39. package/lib/cjs/models/index.js.map +1 -0
  40. package/lib/cjs/models/retail/Configuration.js +10 -0
  41. package/lib/cjs/models/retail/Configuration.js.map +1 -0
  42. package/lib/cjs/models/retail/Product.js +4 -0
  43. package/lib/cjs/models/retail/Product.js.map +1 -0
  44. package/lib/cjs/models/retail/Recommended.js +3 -0
  45. package/lib/cjs/models/retail/Recommended.js.map +1 -0
  46. package/lib/cjs/models/retail/index.js +20 -0
  47. package/lib/cjs/models/retail/index.js.map +1 -0
  48. package/lib/cjs/models/rtb/BidRequest.js +20 -0
  49. package/lib/cjs/models/rtb/BidRequest.js.map +1 -0
  50. package/lib/cjs/models/rtb/BidResponse.js +3 -0
  51. package/lib/cjs/models/rtb/BidResponse.js.map +1 -0
  52. package/lib/cjs/models/rtb/NativeRequest.js +122 -0
  53. package/lib/cjs/models/rtb/NativeRequest.js.map +1 -0
  54. package/lib/cjs/models/rtb/NativeResponse.js +26 -0
  55. package/lib/cjs/models/rtb/NativeResponse.js.map +1 -0
  56. package/lib/cjs/models/rtb/index.js +21 -0
  57. package/lib/cjs/models/rtb/index.js.map +1 -0
  58. package/lib/cjs/models/tracking/Geo.js +3 -0
  59. package/lib/cjs/models/tracking/Geo.js.map +1 -0
  60. package/lib/cjs/models/tracking/index.js +18 -0
  61. package/lib/cjs/models/tracking/index.js.map +1 -0
  62. package/lib/cjs/models/vast/Vast.js +4 -0
  63. package/lib/cjs/models/vast/Vast.js.map +1 -0
  64. package/lib/cjs/models/vast/index.js +18 -0
  65. package/lib/cjs/models/vast/index.js.map +1 -0
  66. package/lib/cjs/services/Bidder.js +128 -0
  67. package/lib/cjs/services/Bidder.js.map +1 -0
  68. package/lib/cjs/services/Configuration.js +93 -0
  69. package/lib/cjs/services/Configuration.js.map +1 -0
  70. package/lib/cjs/services/Device.js +236 -0
  71. package/lib/cjs/services/Device.js.map +1 -0
  72. package/lib/cjs/services/Dynamic.js +129 -0
  73. package/lib/cjs/services/Dynamic.js.map +1 -0
  74. package/lib/cjs/services/Geo.js +35 -0
  75. package/lib/cjs/services/Geo.js.map +1 -0
  76. package/lib/cjs/services/Logger.js +57 -0
  77. package/lib/cjs/services/Logger.js.map +1 -0
  78. package/lib/cjs/services/Memoization.js +17 -0
  79. package/lib/cjs/services/Memoization.js.map +1 -0
  80. package/lib/cjs/services/Product.js +127 -0
  81. package/lib/cjs/services/Product.js.map +1 -0
  82. package/lib/cjs/services/Recommender.js +83 -0
  83. package/lib/cjs/services/Recommender.js.map +1 -0
  84. package/lib/cjs/services/Result.js +220 -0
  85. package/lib/cjs/services/Result.js.map +1 -0
  86. package/lib/cjs/services/Template.js +43 -0
  87. package/lib/cjs/services/Template.js.map +1 -0
  88. package/lib/cjs/services/index.js +28 -0
  89. package/lib/cjs/services/index.js.map +1 -0
  90. package/lib/cjs/services/mock/Bidder.js +3 -0
  91. package/lib/cjs/services/mock/Bidder.js.map +1 -0
  92. package/lib/cjs/services/mock/index.js +18 -0
  93. package/lib/cjs/services/mock/index.js.map +1 -0
  94. package/lib/esm/Api.js +183 -0
  95. package/lib/esm/Api.js.map +1 -0
  96. package/lib/esm/helpers/Generator.js +42 -0
  97. package/lib/esm/helpers/Generator.js.map +1 -0
  98. package/lib/esm/helpers/Handlebars.js +251 -0
  99. package/lib/esm/helpers/Handlebars.js.map +1 -0
  100. package/lib/esm/helpers/NativeRequestBuilder.js +169 -0
  101. package/lib/esm/helpers/NativeRequestBuilder.js.map +1 -0
  102. package/lib/esm/helpers/RequestBuilder.js +157 -0
  103. package/lib/esm/helpers/RequestBuilder.js.map +1 -0
  104. package/lib/esm/helpers/TryGet.js +10 -0
  105. package/lib/esm/helpers/TryGet.js.map +1 -0
  106. package/lib/esm/helpers/Window.js +20 -0
  107. package/lib/esm/helpers/Window.js.map +1 -0
  108. package/lib/esm/helpers/index.js +8 -0
  109. package/lib/esm/helpers/index.js.map +1 -0
  110. package/lib/esm/helpers/response/Banner.js +3 -0
  111. package/lib/esm/helpers/response/Banner.js.map +1 -0
  112. package/lib/esm/helpers/response/BuiltResponse.js +22 -0
  113. package/lib/esm/helpers/response/BuiltResponse.js.map +1 -0
  114. package/lib/esm/helpers/response/Carousel.js +273 -0
  115. package/lib/esm/helpers/response/Carousel.js.map +1 -0
  116. package/lib/esm/helpers/response/Clickthrough.js +20 -0
  117. package/lib/esm/helpers/response/Clickthrough.js.map +1 -0
  118. package/lib/esm/helpers/response/ProductCard.js +189 -0
  119. package/lib/esm/helpers/response/ProductCard.js.map +1 -0
  120. package/lib/esm/helpers/response/Video.js +3 -0
  121. package/lib/esm/helpers/response/Video.js.map +1 -0
  122. package/lib/esm/helpers/response/index.js +7 -0
  123. package/lib/esm/helpers/response/index.js.map +1 -0
  124. package/lib/esm/index.js +5 -3460
  125. package/lib/esm/index.js.map +1 -54
  126. package/lib/esm/models/dynamic/DynamicZone.js +11 -0
  127. package/lib/esm/models/dynamic/DynamicZone.js.map +1 -0
  128. package/lib/esm/models/dynamic/index.js +2 -0
  129. package/lib/esm/models/dynamic/index.js.map +1 -0
  130. package/lib/esm/models/index.js +6 -0
  131. package/lib/esm/models/index.js.map +1 -0
  132. package/lib/esm/models/retail/Configuration.js +9 -0
  133. package/lib/esm/models/retail/Configuration.js.map +1 -0
  134. package/lib/esm/models/retail/Product.js +3 -0
  135. package/lib/esm/models/retail/Product.js.map +1 -0
  136. package/lib/esm/models/retail/Recommended.js +2 -0
  137. package/lib/esm/models/retail/Recommended.js.map +1 -0
  138. package/lib/esm/models/retail/index.js +4 -0
  139. package/lib/esm/models/retail/index.js.map +1 -0
  140. package/lib/esm/models/rtb/BidRequest.js +17 -0
  141. package/lib/esm/models/rtb/BidRequest.js.map +1 -0
  142. package/lib/esm/models/rtb/BidResponse.js +2 -0
  143. package/lib/esm/models/rtb/BidResponse.js.map +1 -0
  144. package/lib/esm/models/rtb/NativeRequest.js +119 -0
  145. package/lib/esm/models/rtb/NativeRequest.js.map +1 -0
  146. package/lib/esm/models/rtb/NativeResponse.js +23 -0
  147. package/lib/esm/models/rtb/NativeResponse.js.map +1 -0
  148. package/lib/esm/models/rtb/index.js +5 -0
  149. package/lib/esm/models/rtb/index.js.map +1 -0
  150. package/lib/esm/models/tracking/Geo.js +2 -0
  151. package/lib/esm/models/tracking/Geo.js.map +1 -0
  152. package/lib/esm/models/tracking/index.js +2 -0
  153. package/lib/esm/models/tracking/index.js.map +1 -0
  154. package/lib/esm/models/vast/Vast.js +3 -0
  155. package/lib/esm/models/vast/Vast.js.map +1 -0
  156. package/lib/esm/models/vast/index.js +2 -0
  157. package/lib/esm/models/vast/index.js.map +1 -0
  158. package/lib/esm/services/Bidder.js +119 -0
  159. package/lib/esm/services/Bidder.js.map +1 -0
  160. package/lib/esm/services/Configuration.js +56 -0
  161. package/lib/esm/services/Configuration.js.map +1 -0
  162. package/lib/esm/services/Device.js +232 -0
  163. package/lib/esm/services/Device.js.map +1 -0
  164. package/lib/esm/services/Dynamic.js +120 -0
  165. package/lib/esm/services/Dynamic.js.map +1 -0
  166. package/lib/esm/services/Geo.js +30 -0
  167. package/lib/esm/services/Geo.js.map +1 -0
  168. package/lib/esm/services/Logger.js +52 -0
  169. package/lib/esm/services/Logger.js.map +1 -0
  170. package/lib/esm/services/Memoization.js +13 -0
  171. package/lib/esm/services/Memoization.js.map +1 -0
  172. package/lib/esm/services/Product.js +120 -0
  173. package/lib/esm/services/Product.js.map +1 -0
  174. package/lib/esm/services/Recommender.js +78 -0
  175. package/lib/esm/services/Recommender.js.map +1 -0
  176. package/lib/esm/services/Result.js +199 -0
  177. package/lib/esm/services/Result.js.map +1 -0
  178. package/lib/esm/services/Template.js +38 -0
  179. package/lib/esm/services/Template.js.map +1 -0
  180. package/lib/esm/services/index.js +12 -0
  181. package/lib/esm/services/index.js.map +1 -0
  182. package/lib/esm/services/mock/Bidder.js +2 -0
  183. package/lib/esm/services/mock/Bidder.js.map +1 -0
  184. package/lib/esm/services/mock/index.js +2 -0
  185. package/lib/esm/services/mock/index.js.map +1 -0
  186. package/lib/types/Api.d.ts +5 -5
  187. package/lib/types/helpers/Handlebars.d.ts +3 -3
  188. package/lib/types/helpers/NativeRequestBuilder.d.ts +1 -1
  189. package/lib/types/helpers/RequestBuilder.d.ts +1 -1
  190. package/lib/types/helpers/TryGet.d.ts +1 -1
  191. package/lib/types/helpers/Window.d.ts +2 -2
  192. package/lib/types/helpers/response/Banner.d.ts +1 -1
  193. package/lib/types/helpers/response/BuiltResponse.d.ts +1 -1
  194. package/lib/types/helpers/response/Carousel.d.ts +1 -1
  195. package/lib/types/helpers/response/Clickthrough.d.ts +1 -1
  196. package/lib/types/helpers/response/ProductCard.d.ts +3 -3
  197. package/lib/types/helpers/response/Video.d.ts +2 -2
  198. package/lib/types/services/Bidder.d.ts +3 -3
  199. package/lib/types/services/Configuration.d.ts +1 -1
  200. package/lib/types/services/Dynamic.d.ts +6 -6
  201. package/lib/types/services/Geo.d.ts +1 -1
  202. package/lib/types/services/Product.d.ts +1 -1
  203. package/lib/types/services/Template.d.ts +3 -3
  204. package/package.json +41 -33
  205. package/lib/index.js +0 -1
  206. package/lib/index.js.map +0 -1
  207. package/lib/types/constant-values/index.d.ts +0 -46
  208. package/lib/types/errors/index.d.ts +0 -3
  209. package/lib/types/helpers/generators/CollectN.d.ts +0 -2
  210. package/lib/types/helpers/generators/index.d.ts +0 -1
  211. package/lib/types/helpers/handlebars/index.d.ts +0 -119
  212. package/lib/types/helpers/requests/RequestBuilder.d.ts +0 -124
  213. package/lib/types/helpers/requests/SimpleBannerRequest.d.ts +0 -26
  214. package/lib/types/helpers/requests/index.d.ts +0 -2
  215. package/lib/types/helpers/responses/BuildBannerResponse.d.ts +0 -10
  216. package/lib/types/helpers/responses/BuildNativeResponse.d.ts +0 -21
  217. package/lib/types/helpers/responses/BuildVideoResponse.d.ts +0 -0
  218. package/lib/types/helpers/responses/ClickthroughHelpers.d.ts +0 -2
  219. package/lib/types/helpers/responses/VastHelpers.d.ts +0 -4
  220. package/lib/types/helpers/responses/index.d.ts +0 -4
  221. package/lib/types/middleware/DeviceMiddleware.d.ts +0 -3
  222. package/lib/types/middleware/GeoMiddleware.d.ts +0 -3
  223. package/lib/types/middleware/IdentityMiddleware.d.ts +0 -4
  224. package/lib/types/middleware/index.d.ts +0 -3
  225. package/lib/types/models/retail/IProductInformation.d.ts +0 -37
  226. package/lib/types/models/retail/IPublisherConfiguration.d.ts +0 -64
  227. package/lib/types/models/retail/IRecommenderResponse.d.ts +0 -10
  228. package/lib/types/models/rtb/IBidRequest.d.ts +0 -399
  229. package/lib/types/models/rtb/IBidResponse.d.ts +0 -47
  230. package/lib/types/models/rtb/native/Constants.d.ts +0 -60
  231. package/lib/types/models/rtb/native/INativeRequest.d.ts +0 -54
  232. package/lib/types/models/rtb/native/INativeResponse.d.ts +0 -60
  233. package/lib/types/models/rtb/native/NativeConstants.d.ts +0 -120
  234. package/lib/types/models/rtb/native/NativeRequestBuilder.d.ts +0 -158
  235. package/lib/types/models/rtb/native/index.d.ts +0 -4
  236. package/lib/types/models/tracking/IEvents.d.ts +0 -82
  237. package/lib/types/models/tracking/IGeoContext.d.ts +0 -14
  238. package/lib/types/models/tracking/IUserID.d.ts +0 -1
  239. package/lib/types/services/OverrideService.d.ts +0 -10
  240. package/lib/types/services/logger/ILoggerService.d.ts +0 -39
  241. package/lib/types/services/logger/LocalLoggerService.d.ts +0 -19
  242. package/lib/types/services/logger/index.d.ts +0 -2
  243. package/lib/types/services/product-feed/IProductFeedService.d.ts +0 -5
  244. package/lib/types/services/product-feed/SurfsideProductFeedService.d.ts +0 -11
  245. package/lib/types/services/product-feed/index.d.ts +0 -2
  246. package/lib/types/services/recommender/IRecommenderService.d.ts +0 -47
  247. package/lib/types/services/recommender/SurfsideRecommenderService.d.ts +0 -31
  248. package/lib/types/services/recommender/index.d.ts +0 -2
  249. package/lib/types/services/rtb/bidder/IBidderService.d.ts +0 -12
  250. package/lib/types/services/rtb/bidder/SurfsideBidderService.d.ts +0 -28
  251. package/lib/types/services/rtb/bidder/index.d.ts +0 -2
  252. package/lib/types/services/rtb/configuration/IConfigurationService.d.ts +0 -14
  253. package/lib/types/services/rtb/configuration/SurfsideConfigurationService.d.ts +0 -29
  254. package/lib/types/services/rtb/configuration/index.d.ts +0 -2
  255. package/lib/types/services/rtb/index.d.ts +0 -2
  256. package/lib/types/services/tracking/device/DeviceOverrideService.d.ts +0 -8
  257. package/lib/types/services/tracking/device/IDeviceService.d.ts +0 -4
  258. package/lib/types/services/tracking/device/SurfsideDeviceService.d.ts +0 -16
  259. package/lib/types/services/tracking/device/index.d.ts +0 -3
  260. package/lib/types/services/tracking/events/IEventService.d.ts +0 -5
  261. package/lib/types/services/tracking/events/SurfsideEventService.d.ts +0 -42
  262. package/lib/types/services/tracking/events/index.d.ts +0 -2
  263. package/lib/types/services/tracking/geo/GeoOverrideService.d.ts +0 -8
  264. package/lib/types/services/tracking/geo/IGeoService.d.ts +0 -12
  265. package/lib/types/services/tracking/geo/SurfsideGeoService.d.ts +0 -7
  266. package/lib/types/services/tracking/geo/index.d.ts +0 -3
  267. package/lib/types/services/tracking/index.d.ts +0 -4
  268. package/lib/types/services/tracking/user/IUserIDService.d.ts +0 -4
  269. package/lib/types/services/tracking/user/SurfsideUserIDService.d.ts +0 -7
  270. package/lib/types/services/tracking/user/UserOverrideService.d.ts +0 -8
  271. package/lib/types/services/tracking/user/index.d.ts +0 -3
  272. package/lib/types/utils/Protocol.d.ts +0 -1
  273. package/lib/types/utils/Rendering.d.ts +0 -44
  274. package/lib/types/utils/index.d.ts +0 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Product.js","sourceRoot":"src/","sources":["services/Product.ts"],"names":[],"mappings":";;;AAgBA,kDA+BC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C,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC;QAC1B,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC;QAC9B,GAAG,EAAE,IAAI;KACZ,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,IAAyB,EAAE,KAAa,EAAsB,EAAE;IAClF,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAEF,MAAa,aAAc,SAAQ,KAAK;IACjB;IAAnB,YAAmB,QAAgB;QAC/B,KAAK,CAAC,2CAA2C,GAAG,QAAQ,CAAC,CAAC;QAD/C,aAAQ,GAAR,QAAQ,CAAQ;IAEnC,CAAC;CACJ;AAJD,sCAIC;AAED,iBAAiB;AACjB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GenerateTopProducts = GenerateTopProducts;
4
+ exports.GenerateForYou = GenerateForYou;
5
+ exports.GeneratePreviousPurchases = GeneratePreviousPurchases;
6
+ const Logger_1 = require("./Logger");
7
+ const Result_1 = require("./Result");
8
+ async function* GenerateTopProducts(logger, productFeed, url, accountId, siteId, locationId) {
9
+ const log = (0, Logger_1.Ctx)(logger)?.with('GenerateTopProducts').with(accountId).with(siteId).with(locationId);
10
+ log?.info('Generating top products');
11
+ yield* generateProductRecommendation(logger, productFeed, url, accountId, siteId, locationId, undefined, 'top-products');
12
+ }
13
+ async function* GenerateForYou(logger, productFeed, url, accountId, siteId, locationId, userId) {
14
+ const log = (0, Logger_1.Ctx)(logger)?.with('GenerateForYou').with(accountId).with(siteId).with(locationId).with(userId);
15
+ log?.info('Generating for you');
16
+ yield* generateProductRecommendation(logger, productFeed, url, accountId, siteId, locationId, userId, 'for-you');
17
+ }
18
+ async function* GeneratePreviousPurchases(logger, productFeed, url, accountId, siteId, locationId, userId) {
19
+ const log = (0, Logger_1.Ctx)(logger)
20
+ ?.with('GeneratePreviousPurchases')
21
+ .with(accountId)
22
+ .with(siteId)
23
+ .with(locationId)
24
+ .with(userId);
25
+ log?.info('Generating previous purchases');
26
+ yield* generateProductRecommendation(log, productFeed, url, accountId, siteId, locationId, userId, 'buy-again');
27
+ }
28
+ async function* generateProductRecommendation(logger, productFeed, url, accountId, siteId, locationId, userId, type) {
29
+ const log = (0, Logger_1.Ctx)(logger)?.with('generatreProductRecommendation');
30
+ log?.debug('Generating product recommendation');
31
+ const recommendations = await fetchRecommendations(log, url, accountId, siteId, locationId, userId, type);
32
+ if (!recommendations.ok) {
33
+ log?.error(recommendations.error);
34
+ return;
35
+ }
36
+ yield* generateProduct(log, productFeed, accountId, locationId, recommendations.value);
37
+ log?.debug('out of recommendations');
38
+ }
39
+ const fetchRecommendations = async (logger, url, accountId, siteId, locationId, userId, type) => {
40
+ const log = (0, Logger_1.Ctx)(logger)?.with('fetchRecommendations');
41
+ log?.debug('Fetching recommendations');
42
+ const key = `accountId=${accountId}&siteId=${siteId}&locationId=${locationId}&userId=${userId ?? 'null'}`;
43
+ try {
44
+ const results = await fetch(`${url}/r/${type}?${key}&limit=100`);
45
+ if (!results.ok) {
46
+ return (0, Result_1.Err)(new Error('Failed to load recommendations. Service returned ' + results.status));
47
+ }
48
+ /* On error, the result will be IRecommenderResponse.
49
+ * On success, it will just be a set of recommended products */
50
+ const recommendations = await results.json();
51
+ const error = recommendations.error;
52
+ if (error !== undefined) {
53
+ return (0, Result_1.Err)(new Error(error));
54
+ }
55
+ return (0, Result_1.Ok)(recommendations);
56
+ }
57
+ catch (err) {
58
+ return (0, Result_1.Err)(err);
59
+ }
60
+ };
61
+ async function* generateProduct(logger, productFeed, accountId, locationId, results) {
62
+ const log = (0, Logger_1.Ctx)(logger)?.with('generateProduct');
63
+ log?.debug('generating product info');
64
+ for (const item of results) {
65
+ const itemId = item.item_id;
66
+ try {
67
+ log?.debug('itemId', itemId);
68
+ const product = await productFeed(itemId);
69
+ log?.debug('product', itemId, product);
70
+ if (product.ok) {
71
+ yield product.value;
72
+ }
73
+ else {
74
+ log?.warn('item was missing from product feed', itemId);
75
+ }
76
+ }
77
+ catch (err) {
78
+ log?.warn('couldn\'t get product', err);
79
+ }
80
+ }
81
+ log?.info('no more products. Exiting');
82
+ }
83
+ //# sourceMappingURL=Recommender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Recommender.js","sourceRoot":"src/","sources":["services/Recommender.ts"],"names":[],"mappings":";;AAQA,kDAqBC;AAED,wCAsBC;AAED,8DA0BC;AAhFD,qCAA6C;AAE7C,qCAAqD;AAK9C,KAAK,SAAU,CAAC,CAAA,mBAAmB,CACtC,MAA2B,EAC3B,WAAiD,EACjD,GAAW,EACX,SAAiB,EACjB,MAAc,EACd,UAAkB;IAElB,MAAM,GAAG,GAAG,IAAA,YAAG,EAAC,MAAM,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACnG,GAAG,EAAE,IAAI,CAAC,yBAAyB,CAAC,CAAC;IAErC,KAAK,CAAC,CAAC,6BAA6B,CAChC,MAAM,EACN,WAAW,EACX,GAAG,EACH,SAAS,EACT,MAAM,EACN,UAAU,EACV,SAAS,EACT,cAAc,CACjB,CAAC;AACN,CAAC;AAEM,KAAK,SAAU,CAAC,CAAA,cAAc,CACjC,MAA2B,EAC3B,WAAiD,EACjD,GAAW,EACX,SAAiB,EACjB,MAAc,EACd,UAAkB,EAClB,MAAc;IAEd,MAAM,GAAG,GAAG,IAAA,YAAG,EAAC,MAAM,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAA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IACxD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,OAAO,IAAA,YAAG,EAAC,GAAY,CAAC,CAAC;IAC7B,CAAC;AACL,CAAC,CAAC;AAEF,KAAK,SAAS,CAAC,CAAC,eAAe,CAC3B,MAA2B,EAC3B,WAAiD,EACjD,SAAiB,EACjB,UAAkB,EAClB,OAA8B;IAE9B,MAAM,GAAG,GAAG,IAAA,YAAG,EAAC,MAAM,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACjD,GAAG,EAAE,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAEtC,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC;YACD,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAC7B,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;YAC1C,GAAG,EAAE,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACvC,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;gBACb,MAAM,OAAO,CAAC,KAAK,CAAC;YACxB,CAAC;iBAAM,CAAC;gBACJ,GAAG,EAAE,IAAI,CAAC,oCAAoC,EAAE,MAAM,CAAC,CAAC;YAC5D,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,GAAG,EAAE,IAAI,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;QAC5C,CAAC;IACL,CAAC;IAED,GAAG,EAAE,IAAI,CAAC,2BAA2B,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoValueError = exports.ResultStream = exports.AsyncPipe = exports.Pipe = exports.MultipleErrorsError = exports.AnyFailed = exports.Filter = exports.Some = exports.AllOrNone = exports.AssertValue = exports.WrapValue = exports.GetValueOrThrow = exports.ValueOr = exports.GetValue = exports.TryDoAsync = exports.TryDoFlat = exports.TryDo = exports.Err = exports.Ok = void 0;
4
+ const Ok = (t) => ({
5
+ ok: true,
6
+ value: t
7
+ });
8
+ exports.Ok = Ok;
9
+ const Err = (e) => ({
10
+ ok: false,
11
+ error: e
12
+ });
13
+ exports.Err = Err;
14
+ const TryDo = (fn) => {
15
+ try {
16
+ return (0, exports.Ok)(fn());
17
+ }
18
+ catch (err) {
19
+ return (0, exports.Err)(err);
20
+ }
21
+ };
22
+ exports.TryDo = TryDo;
23
+ const TryDoFlat = (fn) => {
24
+ try {
25
+ return fn();
26
+ }
27
+ catch (err) {
28
+ return (0, exports.Err)(err);
29
+ }
30
+ };
31
+ exports.TryDoFlat = TryDoFlat;
32
+ const TryDoAsync = async (fn) => {
33
+ try {
34
+ return (0, exports.Ok)(await fn());
35
+ }
36
+ catch (err) {
37
+ return (0, exports.Err)(err);
38
+ }
39
+ };
40
+ exports.TryDoAsync = TryDoAsync;
41
+ const GetValue = (result) => result?.ok === true ? result.value : undefined;
42
+ exports.GetValue = GetValue;
43
+ const ValueOr = (result, or) => result?.ok === true ? result.value : or;
44
+ exports.ValueOr = ValueOr;
45
+ const GetValueOrThrow = (result) => {
46
+ if (result.ok) {
47
+ return result.value;
48
+ }
49
+ throw result.error;
50
+ };
51
+ exports.GetValueOrThrow = GetValueOrThrow;
52
+ const WrapValue = (value) => {
53
+ if (value === undefined || value === null) {
54
+ return (0, exports.Err)(new NoValueError(value));
55
+ }
56
+ return (0, exports.Ok)(value);
57
+ };
58
+ exports.WrapValue = WrapValue;
59
+ exports.AssertValue = exports.GetValueOrThrow;
60
+ const AllOrNone = (results) => {
61
+ const failed = results.filter(res => !res.ok).map(res => res.error);
62
+ if (failed.length > 0) {
63
+ return (0, exports.Err)(new MultipleErrorsError(failed));
64
+ }
65
+ const success = results.filter(res => res.ok).map(res => res.value);
66
+ return (0, exports.Ok)(success);
67
+ };
68
+ exports.AllOrNone = AllOrNone;
69
+ const Some = (results) => {
70
+ const success = results.filter(res => res.ok).map(res => res.value);
71
+ return (0, exports.Ok)(success);
72
+ };
73
+ exports.Some = Some;
74
+ const Filter = (...results) => {
75
+ const success = (0, exports.Some)(results).value.map(val => (0, exports.Ok)(val));
76
+ const failed = results.filter(res => !res.ok);
77
+ return [success, failed];
78
+ };
79
+ exports.Filter = Filter;
80
+ const AnyFailed = (...results) => {
81
+ const errors = results.filter(res => !res.ok).map(res => res.error);
82
+ if (errors.length > 0) {
83
+ return [true, errors];
84
+ }
85
+ return [false];
86
+ };
87
+ exports.AnyFailed = AnyFailed;
88
+ class MultipleErrorsError extends Error {
89
+ errors;
90
+ constructor(errors) {
91
+ super('Got multiple errors:\n' +
92
+ errors.map(err => '\t' + err.message.substring(0, 32).padEnd(35, '.')).join('\n'));
93
+ this.errors = errors;
94
+ }
95
+ }
96
+ exports.MultipleErrorsError = MultipleErrorsError;
97
+ const Pipe = (result) => ({
98
+ then: pipeThen(result),
99
+ result: pipeResult(result),
100
+ value: pipeValue(result),
101
+ valueOr: pipeValueOr(result),
102
+ valueOrThrow: pipeValueOrThrow(result)
103
+ });
104
+ exports.Pipe = Pipe;
105
+ const pipeThen = (result) => (fn) => {
106
+ if (!result.ok) {
107
+ return (0, exports.Pipe)(result);
108
+ }
109
+ return (0, exports.Pipe)((0, exports.Ok)(fn(result.value)));
110
+ };
111
+ const pipeResult = (result) => () => result;
112
+ const pipeValue = (result) => () => (0, exports.GetValue)(result);
113
+ const pipeValueOr = (result) => (or) => (0, exports.GetValue)(result) ?? or;
114
+ const pipeValueOrThrow = (result) => () => {
115
+ if (result.ok) {
116
+ return result.value;
117
+ }
118
+ throw result.error;
119
+ };
120
+ const AsyncPipe = (result) => ({
121
+ then: asyncPipeThen(result),
122
+ result: asyncPipeResult(result),
123
+ value: asyncPipeValue(result),
124
+ valueOr: asyncPipeValueOr(result),
125
+ valueOrThrow: asyncPipeValueOrThrow(result)
126
+ });
127
+ exports.AsyncPipe = AsyncPipe;
128
+ const asyncPipeThen = (result) => (fn) => {
129
+ const asyncResult = result;
130
+ const wrappedPromiseResult = asyncResult.then(unwrappedResult => {
131
+ if (unwrappedResult.ok) {
132
+ try {
133
+ const fnRes = fn(unwrappedResult.value);
134
+ return Promise.resolve(fnRes)
135
+ .catch(exports.Err);
136
+ }
137
+ catch (err) {
138
+ return (0, exports.Err)(err);
139
+ }
140
+ }
141
+ else {
142
+ return unwrappedResult;
143
+ }
144
+ });
145
+ return (0, exports.AsyncPipe)(wrappedPromiseResult);
146
+ };
147
+ const asyncPipeResult = (result) => () => result;
148
+ const asyncPipeValue = (result) => async () => {
149
+ try {
150
+ const res = await result;
151
+ if (res.ok) {
152
+ return res.value;
153
+ }
154
+ return undefined;
155
+ }
156
+ catch {
157
+ return undefined;
158
+ }
159
+ };
160
+ const asyncPipeValueOr = (result) => async (or) => {
161
+ try {
162
+ const res = await result;
163
+ if (res.ok) {
164
+ return res.value;
165
+ }
166
+ return or;
167
+ }
168
+ catch {
169
+ return or;
170
+ }
171
+ };
172
+ const asyncPipeValueOrThrow = (result) => async () => {
173
+ const res = await result;
174
+ if (res.ok) {
175
+ return res.value;
176
+ }
177
+ throw res.error;
178
+ };
179
+ const ResultStream = (results) => ({
180
+ map: streamMap(results),
181
+ filter: streamFilter(results),
182
+ results: streamResults(results),
183
+ value: streamValue(results),
184
+ valueOr: streamValueOr(results),
185
+ valueOrThrow: streamValueOrThrow(results)
186
+ });
187
+ exports.ResultStream = ResultStream;
188
+ const streamMap = (results) => (fn) => {
189
+ if (!results.ok) {
190
+ return (0, exports.ResultStream)(results);
191
+ }
192
+ return (0, exports.ResultStream)((0, exports.Ok)(results.value.map(fn)));
193
+ };
194
+ const streamFilter = (results) => (fn) => {
195
+ if (!results.ok) {
196
+ return (0, exports.ResultStream)(results);
197
+ }
198
+ return (0, exports.ResultStream)((0, exports.Ok)(results.value.filter(fn)));
199
+ };
200
+ const streamResults = (results) => () => results;
201
+ const streamValue = (results) => () => results.ok ? results.value : undefined;
202
+ const streamValueOr = (results) => (or) => results.ok ? results.value : or;
203
+ const streamValueOrThrow = (results) => () => {
204
+ if (results.ok) {
205
+ return results.value;
206
+ }
207
+ else {
208
+ throw results.error;
209
+ }
210
+ };
211
+ class NoValueError extends Error {
212
+ value;
213
+ constructor(value) {
214
+ super('Value was undefined or null');
215
+ this.value = value;
216
+ }
217
+ }
218
+ exports.NoValueError = NoValueError;
219
+ ;
220
+ //# sourceMappingURL=Result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Result.js","sourceRoot":"src/","sources":["services/Result.ts"],"names":[],"mappings":";;;AASO,MAAM,EAAE,GAAG,CAAI,CAAI,EAAe,EAAE,CAAC,CAAC;IACzC,EAAE,EAAE,IAAI;IACR,KAAK,EAAE,CAAC;CACX,CAAC,CAAC;AAHU,QAAA,EAAE,MAGZ;AAEI,MAAM,GAAG,GAAG,CAAY,CAAI,EAAgB,EAAE,CAAC,CAAC;IACnD,EAAE,EAAE,KAAK;IACT,KAAK,EAAE,CAAC;CACX,CAAC,CAAC;AAHU,QAAA,GAAG,OAGb;AAEI,MAAM,KAAK,GAAG,CAAe,EAAW,EAAgB,EAAE;IAC7D,IAAI,CAAC;QACD,OAAO,IAAA,UAAE,EAAC,EAAE,EAAE,CAAC,CAAC;IACpB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,OAAO,IAAA,WAAG,EAAC,GAAQ,CAAC,CAAC;IACzB,CAAC;AACL,CAAC,CAAC;AANW,QAAA,KAAK,SAMhB;AAEK,MAAM,SAAS,GAAG,CAAe,EAAsB,EAAgB,EAAE;IAC5E,IAAI,CAAC;QACD,OAAO,EAAE,EAAE,CAAC;IAChB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,OAAO,IAAA,WAAG,EAAC,GAAQ,CAAC,CAAC;IACzB,CAAC;AACL,CAAC,CAAC;AANW,QAAA,SAAS,aAMpB;AAEK,MAAM,UAAU,GAAG,KAAK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A,UAAE,EAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAO,OAAuB,EAAE,EAAE,CAAC,GAAmB,EAAE,CAAC,OAAO,CAAC;AAEvF,MAAM,WAAW,GAAG,CAAO,OAAuB,EAAE,EAAE,CAAC,GAAoB,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAErH,MAAM,aAAa,GAAG,CAAO,OAAuB,EAAG,EAAE,CAAC,CAAI,EAAK,EAAW,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAEjH,MAAM,kBAAkB,GAAG,CAAO,OAAuB,EAAE,EAAE,CAAC,GAAQ,EAAE;IACpE,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;QACb,OAAO,OAAO,CAAC,KAAK,CAAC;IACzB,CAAC;SAAM,CAAC;QACJ,MAAM,OAAO,CAAC,KAAK,CAAC;IACxB,CAAC;AACL,CAAC,CAAC;AAEF,MAAa,YAAa,SAAQ,KAAK;IACP;IAA5B,YAA4B,KAAuB;QAC/C,KAAK,CAAC,6BAA6B,CAAC,CAAC;QADb,UAAK,GAAL,KAAK,CAAkB;IAEnD,CAAC;CACJ;AAJD,oCAIC;AAAA,CAAC"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EvaluateHandlebarsClickthroughTemplate = exports.EvaluateHandlebarsProductCardTemplate = void 0;
4
+ const Logger_1 = require("./Logger");
5
+ const Result_1 = require("./Result");
6
+ const EvaluateHandlebarsProductCardTemplate = (logger, windowInfo, publisher, product, clickthrough) => {
7
+ const log = (0, Logger_1.Ctx)(logger)?.with('EvaluateHandlebarsProductCardTemplate');
8
+ log?.info('Evaluating handlebars product card template', product);
9
+ try {
10
+ const renderedClickthrough = clickthrough ?? (0, Result_1.GetValueOrThrow)((0, exports.EvaluateHandlebarsClickthroughTemplate)(log, windowInfo, publisher, product));
11
+ log?.debug('Got clickthrough URL', renderedClickthrough);
12
+ return (0, Result_1.Ok)(publisher.templates.productCardTemplate({
13
+ ...product,
14
+ product,
15
+ window: windowInfo,
16
+ publisher,
17
+ catalog: product,
18
+ clickthrough: renderedClickthrough
19
+ }));
20
+ }
21
+ catch (error) {
22
+ return (0, Result_1.Err)(error);
23
+ }
24
+ };
25
+ exports.EvaluateHandlebarsProductCardTemplate = EvaluateHandlebarsProductCardTemplate;
26
+ const EvaluateHandlebarsClickthroughTemplate = (logger, windowInfo, publisher, product) => {
27
+ const log = (0, Logger_1.Ctx)(logger)?.with('EvaluateHandlebarsClickthroughTemplate');
28
+ log?.info('Evaluating handlebars clickthrough URL template', product);
29
+ try {
30
+ return (0, Result_1.Ok)(publisher.templates.clickThroughUrlTemplate({
31
+ product,
32
+ catalog: product,
33
+ window: windowInfo,
34
+ publisher,
35
+ ...product
36
+ }));
37
+ }
38
+ catch (error) {
39
+ return (0, Result_1.Err)(error);
40
+ }
41
+ };
42
+ exports.EvaluateHandlebarsClickthroughTemplate = EvaluateHandlebarsClickthroughTemplate;
43
+ //# sourceMappingURL=Template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Template.js","sourceRoot":"src/","sources":["services/Template.ts"],"names":[],"mappings":";;;AAKA,qCAA6C;AAC7C,qCAAiE;AAW1D,MAAM,qCAAqC,GAAG,CAAC,MAA2B,EAC7E,UAAyC,EACzC,SAA0C,EAC1C,OAA4B,EAC5B,YAAqB,EACP,EAAE;IAChB,MAAM,GAAG,GAAG,IAAA,YAAG,EAAC,MAAM,CAAC,EAAE,IAAI,CAAC,uCAAuC,CAAC,CAAC;IACvE,GAAG,EAAE,IAAI,CAAC,6CAA6C,EAAE,OAAO,CAAC,CAAC;IAElE,IAAI,CAAC;Q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
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Geo"), exports);
18
+ __exportStar(require("./Logger"), exports);
19
+ __exportStar(require("./Result"), exports);
20
+ __exportStar(require("./Device"), exports);
21
+ __exportStar(require("./Configuration"), exports);
22
+ __exportStar(require("./Bidder"), exports);
23
+ __exportStar(require("./Product"), exports);
24
+ __exportStar(require("./Recommender"), exports);
25
+ __exportStar(require("./mock"), exports);
26
+ __exportStar(require("./Template"), exports);
27
+ __exportStar(require("./Dynamic"), exports);
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB;AACzB,kDAAgC;AAChC,2CAAyB;AACzB,4CAA0B;AAC1B,gDAA8B;AAC9B,yCAAuB;AACvB,6CAA2B;AAC3B,4CAA0B"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Bidder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Bidder.js","sourceRoot":"src/","sources":["services/mock/Bidder.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Bidder"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["services/mock/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
package/lib/esm/Api.js ADDED
@@ -0,0 +1,183 @@
1
+ import { Err, GetValue, Ok, RequestBids, GetConfiguration, GetGeo, GetDevice, GetSponsoredProduct, GetRecommendedProduct, GenerateTopProducts, GenerateForYou, GeneratePreviousPurchases, GetAllSponsoredProducts, } from './services';
2
+ import { BuildAllSponsoredProductCardResponses, DefaultNative, GenerateSponsoredProductCardResponse, GetHelpers, StartNative, StartRequest } from './helpers';
3
+ import Handlebars from 'handlebars/runtime';
4
+ import { BuildHybridCarousel, BuildHybridCarouselFromInitialBid, BuildRecommendedCarousel, BuildSponsoredCarousel, BuildSponsoredCarouselFromInitialBid } from './helpers/response/Carousel';
5
+ import { GetWindowInfo } from './helpers/Window';
6
+ import { EvaluateHandlebarsClickthroughTemplate, EvaluateHandlebarsProductCardTemplate } from './services/Template';
7
+ import { BuildDynamicZoneRequest, GetDynamicZone } from './services/Dynamic';
8
+ export const PROD_BIDDER = '//bid.surfside.io/rtb/bids/surfside';
9
+ export const PROD_CONFIGURATION_SERVICE = '//r.surfside.io';
10
+ export const PROD_SPONSORED_PRODUCT_FEED = '//creative.surfside.io';
11
+ export const PROD_RECOMMENDED_PRODUCT_FEED = '//creative.surfside.io';
12
+ export const PROD_RECOMMENDER_SERVICE = '//t.surfside.io';
13
+ export const PROD_DYNAMIC_ZONE_SERVICE = '//r.surfside.io/';
14
+ const TLS = (url) => 'http:' + url;
15
+ /**
16
+ * Initializes the API with the services explicitly passed to it. This function is used by the framework for overloading
17
+ * mock services. It should not be used in an application
18
+ * @param internalApiDto The list of services and helpers to inject
19
+ * @returns An initialized Surfside API
20
+ */
21
+ export async function InitSurfAdsCoreInternal(internalApiDto) {
22
+ const { getDevice, mobile, navigator, ip, getGeo, geoProviderToken, getConfiguration, accountId, siteId, logger, channelId, locationId, userId, handlebars, windowInfo, screenInfo, requestBids, getSponsoredProduct, getAllSponsoredProducts, getRecommendedProduct, generateTopProducts, generateForYou, generatePreviousPurchases, getDynamicZone, buildAllSponsoredProductCardResponses, generateSponsoredProductCardResponse, evaluateProductCardTemplate, evaluateClickthroughTemplate, } = internalApiDto;
23
+ const device = getDevice(screenInfo, navigator, mobile);
24
+ const geo = await getGeo(geoProviderToken, ip);
25
+ const configuration = await getConfiguration();
26
+ if (!configuration.ok) {
27
+ return Err(new MissingConfigurationError(accountId, siteId));
28
+ }
29
+ const startRequestBound = StartRequest.bind(undefined, logger, accountId, siteId, channelId, locationId, GetValue(device), GetValue(geo), userId);
30
+ const startRequest = (zoneId, id) => startRequestBound(zoneId, id)
31
+ .withApp({
32
+ bundle: windowInfo.host,
33
+ name: windowInfo.host,
34
+ id: siteId,
35
+ domain: windowInfo.host,
36
+ publisher: {
37
+ domain: windowInfo.host,
38
+ }
39
+ })
40
+ .withSite({
41
+ name: windowInfo.host,
42
+ id: siteId,
43
+ kwarray: [],
44
+ mobile: isMobile() ? 1 : 0,
45
+ page: windowInfo.href,
46
+ domain: windowInfo.host,
47
+ publisher: {
48
+ id: siteId,
49
+ name: windowInfo.host,
50
+ domain: windowInfo.host,
51
+ },
52
+ ref: '',
53
+ search: windowInfo.search
54
+ });
55
+ const startNative = StartNative.bind(undefined, logger);
56
+ const defaultNative = DefaultNative.bind(undefined, logger);
57
+ return Ok({
58
+ logger,
59
+ getDevice,
60
+ device: GetValue(device),
61
+ getGeo,
62
+ geo: GetValue(geo),
63
+ configuration: configuration.value,
64
+ getConfiguration,
65
+ handlebars,
66
+ requestBids,
67
+ startRequest,
68
+ startNative,
69
+ defaultNative,
70
+ getSponsoredProduct,
71
+ getAllSponsoredProducts,
72
+ getRecommendedProduct,
73
+ generateTopProducts,
74
+ generateForYou,
75
+ generatePreviousPurchases,
76
+ buildAllSponsoredProductCardResponses,
77
+ generateSponsoredProductCardResponse,
78
+ evaluateProductCardTemplate,
79
+ evaluateClickthroughTemplate,
80
+ buildSponsoredCarousel: BuildSponsoredCarousel.bind(undefined, logger, requestBids, generateSponsoredProductCardResponse),
81
+ buildSponsoredCarouselFromInitialBid: BuildSponsoredCarouselFromInitialBid.bind(undefined, logger, requestBids, generateSponsoredProductCardResponse),
82
+ buildHybridCarouselFromInitialBid: BuildHybridCarouselFromInitialBid.bind(undefined, logger, evaluateClickthroughTemplate, requestBids, generateSponsoredProductCardResponse, generateTopProducts, generatePreviousPurchases, generateForYou, userId),
83
+ buildRecommendedCarousel: BuildRecommendedCarousel.bind(undefined, logger, evaluateClickthroughTemplate, generateTopProducts, generatePreviousPurchases, generateForYou, userId),
84
+ buildHybridCarousel: BuildHybridCarousel.bind(undefined, logger, evaluateClickthroughTemplate, requestBids, generateSponsoredProductCardResponse, generateTopProducts, generatePreviousPurchases, generateForYou, userId),
85
+ getDynamicZone,
86
+ buildDynamicZoneRequest: BuildDynamicZoneRequest.bind(undefined, logger, startRequest, defaultNative, screenInfo)
87
+ });
88
+ }
89
+ export const InitSurfAdsCoreServices = async (logger, bidderServiceUrl, configurationServiceUrl, productFeedUrl, recommendedProductFeedUrl, recommenderServiceUrl, dynamicZoneServiceUrl, windowInfo, screenInfo, navigator, mobile, ip, geoProviderToken, accountId, siteId, channelId, locationId, userId) => {
90
+ const handlebars = Handlebars.create();
91
+ const helpers = GetHelpers();
92
+ const recommendedProductFeed = GetRecommendedProduct.bind(undefined, logger, recommendedProductFeedUrl, accountId, locationId);
93
+ const configurationService = GetConfiguration.bind(undefined, logger, configurationServiceUrl, handlebars, helpers, accountId, siteId);
94
+ const configuration = await configurationService();
95
+ if (!configuration.ok) {
96
+ return configuration;
97
+ }
98
+ const getAllSponsoredProducts = GetAllSponsoredProducts.bind(undefined, logger, productFeedUrl, accountId, locationId);
99
+ const generateProductCardResponse = GenerateSponsoredProductCardResponse.bind(undefined, logger, getAllSponsoredProducts, windowInfo, configuration.value);
100
+ const evaluateClickthroughTemplate = EvaluateHandlebarsClickthroughTemplate.bind(undefined, logger, windowInfo, configuration.value);
101
+ const evaluateProductCardTemplate = EvaluateHandlebarsProductCardTemplate.bind(undefined, logger, windowInfo, configuration.value);
102
+ return await InitSurfAdsCoreInternal({
103
+ logger,
104
+ requestBids: RequestBids.bind(undefined, logger, bidderServiceUrl, accountId, siteId, locationId, channelId),
105
+ getConfiguration: configurationService,
106
+ getGeo: GetGeo.bind(undefined, logger),
107
+ getDevice: GetDevice.bind(undefined, logger),
108
+ getSponsoredProduct: GetSponsoredProduct.bind(undefined, logger, productFeedUrl, accountId, locationId),
109
+ getAllSponsoredProducts,
110
+ getRecommendedProduct: GetRecommendedProduct.bind(undefined, logger, recommendedProductFeedUrl, accountId, locationId),
111
+ generateTopProducts: GenerateTopProducts.bind(undefined, logger, recommendedProductFeed, recommenderServiceUrl, accountId, siteId, locationId),
112
+ generateForYou: GenerateForYou.bind(undefined, logger, recommendedProductFeed, recommenderServiceUrl, accountId, siteId, locationId, userId ?? 'undefined'),
113
+ generatePreviousPurchases: GeneratePreviousPurchases.bind(undefined, logger, recommendedProductFeed, recommenderServiceUrl, accountId, siteId, locationId, userId ?? 'undefined'),
114
+ buildAllSponsoredProductCardResponses: BuildAllSponsoredProductCardResponses.bind(undefined, logger, getAllSponsoredProducts, windowInfo, configuration.value),
115
+ generateSponsoredProductCardResponse: generateProductCardResponse,
116
+ evaluateProductCardTemplate,
117
+ evaluateClickthroughTemplate,
118
+ handlebars,
119
+ windowInfo,
120
+ screenInfo,
121
+ navigator,
122
+ mobile,
123
+ ip,
124
+ geoProviderToken,
125
+ accountId,
126
+ siteId,
127
+ channelId,
128
+ locationId,
129
+ userId,
130
+ getDynamicZone: GetDynamicZone.bind(undefined, logger, configuration.value)
131
+ });
132
+ };
133
+ /* For use in serverside rendering */
134
+ // TODO: Rename this?
135
+ export const InitSurfAdsCoreSSR = async (windowInfo, screen, navigator, mobile, ip, geoProviderToken, accountId, siteId, channelId, locationId, userId, logger) => InitSurfAdsCoreServices(logger, TLS(PROD_BIDDER), TLS(PROD_CONFIGURATION_SERVICE), TLS(PROD_SPONSORED_PRODUCT_FEED), TLS(PROD_RECOMMENDED_PRODUCT_FEED), TLS(PROD_RECOMMENDER_SERVICE), TLS(PROD_DYNAMIC_ZONE_SERVICE), windowInfo, screen, navigator, mobile, ip, geoProviderToken, accountId, siteId, channelId, locationId, userId);
136
+ /* For use in web browsers */
137
+ export const InitSurfAdsCore = async (channelId, accountId, siteId, locationId, userId, logger) => {
138
+ /* Not in a browser */
139
+ const windowInfo = GetWindowInfo();
140
+ if (!windowInfo.ok) {
141
+ return windowInfo;
142
+ }
143
+ return InitSurfAdsCoreServices(logger, TLS(PROD_BIDDER), TLS(PROD_CONFIGURATION_SERVICE), TLS(PROD_SPONSORED_PRODUCT_FEED), TLS(PROD_RECOMMENDED_PRODUCT_FEED), TLS(PROD_RECOMMENDER_SERVICE), TLS(PROD_DYNAMIC_ZONE_SERVICE), windowInfo.value, window.screen, window.navigator, isMobile(), undefined, undefined, accountId, siteId, channelId, locationId, userId);
144
+ };
145
+ export class MissingConfigurationError extends Error {
146
+ constructor(accountId, siteId) {
147
+ super('Missing configuration for\n' +
148
+ ` accountId: ${accountId}\n` +
149
+ ` siteId: ${siteId}\n` +
150
+ '1. Check to make sure that these are the correct values for each field' +
151
+ '2. Check your publisher configuration at ' +
152
+ `https://app.surfside.io/inventory/sites/publisher/${accountId}/${siteId}`);
153
+ }
154
+ }
155
+ ;
156
+ export class NotABrowserError extends Error {
157
+ constructor() {
158
+ super('You are not running Surfside Ads Core in a Web browser, so you cannot use "InitSurfAdsCore". ' +
159
+ 'Instead, use InitSurfAdsCoreSSR, and pass the user\'s screen, navigator, and IP address explicitly ' +
160
+ 'so that Surfside Ads Core can initialize geo and device information services. e.g: \n' +
161
+ ' InitSurfAdsCoreSSR(\n' +
162
+ ' /* width and height of the user\'s screen: */\n' +
163
+ ' { width: screenWidth, height: screenHeight },\n' +
164
+ ' /* userAgent string and language of the user: */\n' +
165
+ ' { userAgent: userAgent, language: userLanguage },\n' +
166
+ ' /* whether the user is on mobile or not: */\n' +
167
+ ' true,\n' +
168
+ ' /* the requesting User\'s IP */\n' +
169
+ ' request.ipAddress,\n' +
170
+ ' /* Your API Token for the Surfside Geo Service: */\n' +
171
+ ' geoProviderToken,\n' +
172
+ ' accountId,\n' +
173
+ ' siteId,\n' +
174
+ ' channelId,\n' +
175
+ ' locationId,\n' +
176
+ ' userId,\n' +
177
+ ' /* Optional logger: */\n' +
178
+ ' logger\n' +
179
+ ' )');
180
+ }
181
+ }
182
+ const isMobile = () => typeof window !== 'undefined' ? (window.ontouchstart !== undefined) : false;
183
+ //# sourceMappingURL=Api.js.map