@chipmobilesdk/rn-ads 0.7.0 → 0.8.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 (319) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/lib/commonjs/config/resolveAdUnit.js +80 -0
  3. package/lib/commonjs/config/resolveAdUnit.js.map +1 -0
  4. package/lib/commonjs/config/types.js +138 -0
  5. package/lib/commonjs/config/types.js.map +1 -0
  6. package/lib/commonjs/config/validate.js +150 -0
  7. package/lib/commonjs/config/validate.js.map +1 -0
  8. package/lib/commonjs/core/adOriginatedReturn.js +119 -0
  9. package/lib/commonjs/core/adOriginatedReturn.js.map +1 -0
  10. package/lib/commonjs/core/adsInstance.js +129 -0
  11. package/lib/commonjs/core/adsInstance.js.map +1 -0
  12. package/lib/commonjs/core/consentFlow.js +154 -0
  13. package/lib/commonjs/core/consentFlow.js.map +1 -0
  14. package/lib/commonjs/core/enablement.js +64 -0
  15. package/lib/commonjs/core/enablement.js.map +1 -0
  16. package/lib/commonjs/core/fullScreenLock.js +48 -0
  17. package/lib/commonjs/core/fullScreenLock.js.map +1 -0
  18. package/lib/commonjs/core/gates.js +95 -0
  19. package/lib/commonjs/core/gates.js.map +1 -0
  20. package/lib/commonjs/core/initMachine.js +159 -0
  21. package/lib/commonjs/core/initMachine.js.map +1 -0
  22. package/lib/commonjs/core/instance/consent.js +155 -0
  23. package/lib/commonjs/core/instance/consent.js.map +1 -0
  24. package/lib/commonjs/core/instance/context.js +217 -0
  25. package/lib/commonjs/core/instance/context.js.map +1 -0
  26. package/lib/commonjs/core/instance/gate.js +194 -0
  27. package/lib/commonjs/core/instance/gate.js.map +1 -0
  28. package/lib/commonjs/core/instance/init.js +326 -0
  29. package/lib/commonjs/core/instance/init.js.map +1 -0
  30. package/lib/commonjs/core/instance/internals.js +115 -0
  31. package/lib/commonjs/core/instance/internals.js.map +1 -0
  32. package/lib/commonjs/core/instance/load.js +458 -0
  33. package/lib/commonjs/core/instance/load.js.map +1 -0
  34. package/lib/commonjs/core/instance/show.js +243 -0
  35. package/lib/commonjs/core/instance/show.js.map +1 -0
  36. package/lib/commonjs/core/instance/types.js +6 -0
  37. package/lib/commonjs/core/instance/types.js.map +1 -0
  38. package/lib/commonjs/core/placementMachine.js +116 -0
  39. package/lib/commonjs/core/placementMachine.js.map +1 -0
  40. package/lib/commonjs/core/privacyGate.js +93 -0
  41. package/lib/commonjs/core/privacyGate.js.map +1 -0
  42. package/lib/commonjs/core/requestThrottle.js +152 -0
  43. package/lib/commonjs/core/requestThrottle.js.map +1 -0
  44. package/lib/commonjs/core/retryPolicy.js +120 -0
  45. package/lib/commonjs/core/retryPolicy.js.map +1 -0
  46. package/lib/commonjs/core/rewardedSession.js +65 -0
  47. package/lib/commonjs/core/rewardedSession.js.map +1 -0
  48. package/lib/commonjs/core/timers.js +162 -0
  49. package/lib/commonjs/core/timers.js.map +1 -0
  50. package/lib/commonjs/diagnostics/correlation.js +33 -0
  51. package/lib/commonjs/diagnostics/correlation.js.map +1 -0
  52. package/lib/commonjs/diagnostics/errors.js +152 -0
  53. package/lib/commonjs/diagnostics/errors.js.map +1 -0
  54. package/lib/commonjs/diagnostics/events.js +132 -0
  55. package/lib/commonjs/diagnostics/events.js.map +1 -0
  56. package/lib/commonjs/engine/admobBanner.js +58 -0
  57. package/lib/commonjs/engine/admobBanner.js.map +1 -0
  58. package/lib/commonjs/engine/admobEngine.js +343 -0
  59. package/lib/commonjs/engine/admobEngine.js.map +1 -0
  60. package/lib/commonjs/engine/admobErrors.js +45 -0
  61. package/lib/commonjs/engine/admobErrors.js.map +1 -0
  62. package/lib/commonjs/engine/port.js +6 -0
  63. package/lib/commonjs/engine/port.js.map +1 -0
  64. package/lib/commonjs/engine/testAdUnits.js +61 -0
  65. package/lib/commonjs/engine/testAdUnits.js.map +1 -0
  66. package/lib/commonjs/index.js +218 -0
  67. package/lib/commonjs/index.js.map +1 -0
  68. package/lib/commonjs/package.json +1 -0
  69. package/lib/commonjs/react/AdsBanner.js +317 -0
  70. package/lib/commonjs/react/AdsBanner.js.map +1 -0
  71. package/lib/commonjs/react/AdsProvider.js +54 -0
  72. package/lib/commonjs/react/AdsProvider.js.map +1 -0
  73. package/lib/commonjs/react/hooks.js +63 -0
  74. package/lib/commonjs/react/hooks.js.map +1 -0
  75. package/lib/commonjs/testing/clock.js +76 -0
  76. package/lib/commonjs/testing/clock.js.map +1 -0
  77. package/lib/commonjs/testing/conformance.js +99 -0
  78. package/lib/commonjs/testing/conformance.js.map +1 -0
  79. package/lib/commonjs/testing/index.js +389 -0
  80. package/lib/commonjs/testing/index.js.map +1 -0
  81. package/lib/module/config/resolveAdUnit.js +75 -0
  82. package/lib/module/config/resolveAdUnit.js.map +1 -0
  83. package/lib/module/config/types.js +134 -0
  84. package/lib/module/config/types.js.map +1 -0
  85. package/lib/module/config/validate.js +146 -0
  86. package/lib/module/config/validate.js.map +1 -0
  87. package/lib/module/core/adOriginatedReturn.js +115 -0
  88. package/lib/module/core/adOriginatedReturn.js.map +1 -0
  89. package/lib/module/core/adsInstance.js +121 -0
  90. package/lib/module/core/adsInstance.js.map +1 -0
  91. package/lib/module/core/consentFlow.js +143 -0
  92. package/lib/module/core/consentFlow.js.map +1 -0
  93. package/lib/module/core/enablement.js +58 -0
  94. package/lib/module/core/enablement.js.map +1 -0
  95. package/lib/module/core/fullScreenLock.js +44 -0
  96. package/lib/module/core/fullScreenLock.js.map +1 -0
  97. package/lib/module/core/gates.js +91 -0
  98. package/lib/module/core/gates.js.map +1 -0
  99. package/lib/module/core/initMachine.js +152 -0
  100. package/lib/module/core/initMachine.js.map +1 -0
  101. package/lib/module/core/instance/consent.js +151 -0
  102. package/lib/module/core/instance/consent.js.map +1 -0
  103. package/lib/module/core/instance/context.js +212 -0
  104. package/lib/module/core/instance/context.js.map +1 -0
  105. package/lib/module/core/instance/gate.js +183 -0
  106. package/lib/module/core/instance/gate.js.map +1 -0
  107. package/lib/module/core/instance/init.js +321 -0
  108. package/lib/module/core/instance/init.js.map +1 -0
  109. package/lib/module/core/instance/internals.js +109 -0
  110. package/lib/module/core/instance/internals.js.map +1 -0
  111. package/lib/module/core/instance/load.js +452 -0
  112. package/lib/module/core/instance/load.js.map +1 -0
  113. package/lib/module/core/instance/show.js +238 -0
  114. package/lib/module/core/instance/show.js.map +1 -0
  115. package/lib/module/core/instance/types.js +4 -0
  116. package/lib/module/core/instance/types.js.map +1 -0
  117. package/lib/module/core/placementMachine.js +109 -0
  118. package/lib/module/core/placementMachine.js.map +1 -0
  119. package/lib/module/core/privacyGate.js +86 -0
  120. package/lib/module/core/privacyGate.js.map +1 -0
  121. package/lib/module/core/requestThrottle.js +146 -0
  122. package/lib/module/core/requestThrottle.js.map +1 -0
  123. package/lib/module/core/retryPolicy.js +113 -0
  124. package/lib/module/core/retryPolicy.js.map +1 -0
  125. package/lib/module/core/rewardedSession.js +61 -0
  126. package/lib/module/core/rewardedSession.js.map +1 -0
  127. package/lib/module/core/timers.js +150 -0
  128. package/lib/module/core/timers.js.map +1 -0
  129. package/lib/module/diagnostics/correlation.js +29 -0
  130. package/lib/module/diagnostics/correlation.js.map +1 -0
  131. package/lib/module/diagnostics/errors.js +143 -0
  132. package/lib/module/diagnostics/errors.js.map +1 -0
  133. package/lib/module/diagnostics/events.js +128 -0
  134. package/lib/module/diagnostics/events.js.map +1 -0
  135. package/lib/module/engine/admobBanner.js +52 -0
  136. package/lib/module/engine/admobBanner.js.map +1 -0
  137. package/lib/module/engine/admobEngine.js +334 -0
  138. package/lib/module/engine/admobEngine.js.map +1 -0
  139. package/lib/module/engine/admobErrors.js +41 -0
  140. package/lib/module/engine/admobErrors.js.map +1 -0
  141. package/lib/module/engine/port.js +4 -0
  142. package/lib/module/engine/port.js.map +1 -0
  143. package/lib/module/engine/testAdUnits.js +56 -0
  144. package/lib/module/engine/testAdUnits.js.map +1 -0
  145. package/lib/module/index.js +59 -0
  146. package/lib/module/index.js.map +1 -0
  147. package/lib/module/package.json +1 -0
  148. package/lib/module/react/AdsBanner.js +312 -0
  149. package/lib/module/react/AdsBanner.js.map +1 -0
  150. package/lib/module/react/AdsProvider.js +48 -0
  151. package/lib/module/react/AdsProvider.js.map +1 -0
  152. package/lib/module/react/hooks.js +58 -0
  153. package/lib/module/react/hooks.js.map +1 -0
  154. package/lib/module/testing/clock.js +72 -0
  155. package/lib/module/testing/clock.js.map +1 -0
  156. package/lib/module/testing/conformance.js +93 -0
  157. package/lib/module/testing/conformance.js.map +1 -0
  158. package/lib/module/testing/index.js +366 -0
  159. package/lib/module/testing/index.js.map +1 -0
  160. package/lib/typescript/commonjs/config/resolveAdUnit.d.ts +43 -0
  161. package/lib/typescript/commonjs/config/resolveAdUnit.d.ts.map +1 -0
  162. package/lib/typescript/commonjs/config/types.d.ts +280 -0
  163. package/lib/typescript/commonjs/config/types.d.ts.map +1 -0
  164. package/lib/typescript/commonjs/config/validate.d.ts +49 -0
  165. package/lib/typescript/commonjs/config/validate.d.ts.map +1 -0
  166. package/lib/typescript/commonjs/core/adOriginatedReturn.d.ts +61 -0
  167. package/lib/typescript/commonjs/core/adOriginatedReturn.d.ts.map +1 -0
  168. package/lib/typescript/commonjs/core/adsInstance.d.ts +33 -0
  169. package/lib/typescript/commonjs/core/adsInstance.d.ts.map +1 -0
  170. package/lib/typescript/commonjs/core/consentFlow.d.ts +84 -0
  171. package/lib/typescript/commonjs/core/consentFlow.d.ts.map +1 -0
  172. package/lib/typescript/commonjs/core/enablement.d.ts +74 -0
  173. package/lib/typescript/commonjs/core/enablement.d.ts.map +1 -0
  174. package/lib/typescript/commonjs/core/fullScreenLock.d.ts +25 -0
  175. package/lib/typescript/commonjs/core/fullScreenLock.d.ts.map +1 -0
  176. package/lib/typescript/commonjs/core/gates.d.ts +76 -0
  177. package/lib/typescript/commonjs/core/gates.d.ts.map +1 -0
  178. package/lib/typescript/commonjs/core/initMachine.d.ts +66 -0
  179. package/lib/typescript/commonjs/core/initMachine.d.ts.map +1 -0
  180. package/lib/typescript/commonjs/core/instance/consent.d.ts +4 -0
  181. package/lib/typescript/commonjs/core/instance/consent.d.ts.map +1 -0
  182. package/lib/typescript/commonjs/core/instance/context.d.ts +118 -0
  183. package/lib/typescript/commonjs/core/instance/context.d.ts.map +1 -0
  184. package/lib/typescript/commonjs/core/instance/gate.d.ts +38 -0
  185. package/lib/typescript/commonjs/core/instance/gate.d.ts.map +1 -0
  186. package/lib/typescript/commonjs/core/instance/init.d.ts +13 -0
  187. package/lib/typescript/commonjs/core/instance/init.d.ts.map +1 -0
  188. package/lib/typescript/commonjs/core/instance/internals.d.ts +60 -0
  189. package/lib/typescript/commonjs/core/instance/internals.d.ts.map +1 -0
  190. package/lib/typescript/commonjs/core/instance/load.d.ts +9 -0
  191. package/lib/typescript/commonjs/core/instance/load.d.ts.map +1 -0
  192. package/lib/typescript/commonjs/core/instance/show.d.ts +7 -0
  193. package/lib/typescript/commonjs/core/instance/show.d.ts.map +1 -0
  194. package/lib/typescript/commonjs/core/instance/types.d.ts +240 -0
  195. package/lib/typescript/commonjs/core/instance/types.d.ts.map +1 -0
  196. package/lib/typescript/commonjs/core/placementMachine.d.ts +55 -0
  197. package/lib/typescript/commonjs/core/placementMachine.d.ts.map +1 -0
  198. package/lib/typescript/commonjs/core/privacyGate.d.ts +40 -0
  199. package/lib/typescript/commonjs/core/privacyGate.d.ts.map +1 -0
  200. package/lib/typescript/commonjs/core/requestThrottle.d.ts +99 -0
  201. package/lib/typescript/commonjs/core/requestThrottle.d.ts.map +1 -0
  202. package/lib/typescript/commonjs/core/retryPolicy.d.ts +66 -0
  203. package/lib/typescript/commonjs/core/retryPolicy.d.ts.map +1 -0
  204. package/lib/typescript/commonjs/core/rewardedSession.d.ts +37 -0
  205. package/lib/typescript/commonjs/core/rewardedSession.d.ts.map +1 -0
  206. package/lib/typescript/commonjs/core/timers.d.ts +135 -0
  207. package/lib/typescript/commonjs/core/timers.d.ts.map +1 -0
  208. package/lib/typescript/commonjs/diagnostics/correlation.d.ts +18 -0
  209. package/lib/typescript/commonjs/diagnostics/correlation.d.ts.map +1 -0
  210. package/lib/typescript/commonjs/diagnostics/errors.d.ts +59 -0
  211. package/lib/typescript/commonjs/diagnostics/errors.d.ts.map +1 -0
  212. package/lib/typescript/commonjs/diagnostics/events.d.ts +126 -0
  213. package/lib/typescript/commonjs/diagnostics/events.d.ts.map +1 -0
  214. package/lib/typescript/commonjs/engine/admobBanner.d.ts +10 -0
  215. package/lib/typescript/commonjs/engine/admobBanner.d.ts.map +1 -0
  216. package/lib/typescript/commonjs/engine/admobEngine.d.ts +71 -0
  217. package/lib/typescript/commonjs/engine/admobEngine.d.ts.map +1 -0
  218. package/lib/typescript/commonjs/engine/admobErrors.d.ts +9 -0
  219. package/lib/typescript/commonjs/engine/admobErrors.d.ts.map +1 -0
  220. package/lib/typescript/commonjs/engine/port.d.ts +171 -0
  221. package/lib/typescript/commonjs/engine/port.d.ts.map +1 -0
  222. package/lib/typescript/commonjs/engine/testAdUnits.d.ts +33 -0
  223. package/lib/typescript/commonjs/engine/testAdUnits.d.ts.map +1 -0
  224. package/lib/typescript/commonjs/index.d.ts +42 -0
  225. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  226. package/lib/typescript/commonjs/package.json +1 -0
  227. package/lib/typescript/commonjs/react/AdsBanner.d.ts +29 -0
  228. package/lib/typescript/commonjs/react/AdsBanner.d.ts.map +1 -0
  229. package/lib/typescript/commonjs/react/AdsProvider.d.ts +36 -0
  230. package/lib/typescript/commonjs/react/AdsProvider.d.ts.map +1 -0
  231. package/lib/typescript/commonjs/react/hooks.d.ts +27 -0
  232. package/lib/typescript/commonjs/react/hooks.d.ts.map +1 -0
  233. package/lib/typescript/commonjs/testing/clock.d.ts +29 -0
  234. package/lib/typescript/commonjs/testing/clock.d.ts.map +1 -0
  235. package/lib/typescript/commonjs/testing/conformance.d.ts +26 -0
  236. package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
  237. package/lib/typescript/commonjs/testing/index.d.ts +133 -0
  238. package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
  239. package/lib/typescript/module/config/resolveAdUnit.d.ts +43 -0
  240. package/lib/typescript/module/config/resolveAdUnit.d.ts.map +1 -0
  241. package/lib/typescript/module/config/types.d.ts +280 -0
  242. package/lib/typescript/module/config/types.d.ts.map +1 -0
  243. package/lib/typescript/module/config/validate.d.ts +49 -0
  244. package/lib/typescript/module/config/validate.d.ts.map +1 -0
  245. package/lib/typescript/module/core/adOriginatedReturn.d.ts +61 -0
  246. package/lib/typescript/module/core/adOriginatedReturn.d.ts.map +1 -0
  247. package/lib/typescript/module/core/adsInstance.d.ts +33 -0
  248. package/lib/typescript/module/core/adsInstance.d.ts.map +1 -0
  249. package/lib/typescript/module/core/consentFlow.d.ts +84 -0
  250. package/lib/typescript/module/core/consentFlow.d.ts.map +1 -0
  251. package/lib/typescript/module/core/enablement.d.ts +74 -0
  252. package/lib/typescript/module/core/enablement.d.ts.map +1 -0
  253. package/lib/typescript/module/core/fullScreenLock.d.ts +25 -0
  254. package/lib/typescript/module/core/fullScreenLock.d.ts.map +1 -0
  255. package/lib/typescript/module/core/gates.d.ts +76 -0
  256. package/lib/typescript/module/core/gates.d.ts.map +1 -0
  257. package/lib/typescript/module/core/initMachine.d.ts +66 -0
  258. package/lib/typescript/module/core/initMachine.d.ts.map +1 -0
  259. package/lib/typescript/module/core/instance/consent.d.ts +4 -0
  260. package/lib/typescript/module/core/instance/consent.d.ts.map +1 -0
  261. package/lib/typescript/module/core/instance/context.d.ts +118 -0
  262. package/lib/typescript/module/core/instance/context.d.ts.map +1 -0
  263. package/lib/typescript/module/core/instance/gate.d.ts +38 -0
  264. package/lib/typescript/module/core/instance/gate.d.ts.map +1 -0
  265. package/lib/typescript/module/core/instance/init.d.ts +13 -0
  266. package/lib/typescript/module/core/instance/init.d.ts.map +1 -0
  267. package/lib/typescript/module/core/instance/internals.d.ts +60 -0
  268. package/lib/typescript/module/core/instance/internals.d.ts.map +1 -0
  269. package/lib/typescript/module/core/instance/load.d.ts +9 -0
  270. package/lib/typescript/module/core/instance/load.d.ts.map +1 -0
  271. package/lib/typescript/module/core/instance/show.d.ts +7 -0
  272. package/lib/typescript/module/core/instance/show.d.ts.map +1 -0
  273. package/lib/typescript/module/core/instance/types.d.ts +240 -0
  274. package/lib/typescript/module/core/instance/types.d.ts.map +1 -0
  275. package/lib/typescript/module/core/placementMachine.d.ts +55 -0
  276. package/lib/typescript/module/core/placementMachine.d.ts.map +1 -0
  277. package/lib/typescript/module/core/privacyGate.d.ts +40 -0
  278. package/lib/typescript/module/core/privacyGate.d.ts.map +1 -0
  279. package/lib/typescript/module/core/requestThrottle.d.ts +99 -0
  280. package/lib/typescript/module/core/requestThrottle.d.ts.map +1 -0
  281. package/lib/typescript/module/core/retryPolicy.d.ts +66 -0
  282. package/lib/typescript/module/core/retryPolicy.d.ts.map +1 -0
  283. package/lib/typescript/module/core/rewardedSession.d.ts +37 -0
  284. package/lib/typescript/module/core/rewardedSession.d.ts.map +1 -0
  285. package/lib/typescript/module/core/timers.d.ts +135 -0
  286. package/lib/typescript/module/core/timers.d.ts.map +1 -0
  287. package/lib/typescript/module/diagnostics/correlation.d.ts +18 -0
  288. package/lib/typescript/module/diagnostics/correlation.d.ts.map +1 -0
  289. package/lib/typescript/module/diagnostics/errors.d.ts +59 -0
  290. package/lib/typescript/module/diagnostics/errors.d.ts.map +1 -0
  291. package/lib/typescript/module/diagnostics/events.d.ts +126 -0
  292. package/lib/typescript/module/diagnostics/events.d.ts.map +1 -0
  293. package/lib/typescript/module/engine/admobBanner.d.ts +10 -0
  294. package/lib/typescript/module/engine/admobBanner.d.ts.map +1 -0
  295. package/lib/typescript/module/engine/admobEngine.d.ts +71 -0
  296. package/lib/typescript/module/engine/admobEngine.d.ts.map +1 -0
  297. package/lib/typescript/module/engine/admobErrors.d.ts +9 -0
  298. package/lib/typescript/module/engine/admobErrors.d.ts.map +1 -0
  299. package/lib/typescript/module/engine/port.d.ts +171 -0
  300. package/lib/typescript/module/engine/port.d.ts.map +1 -0
  301. package/lib/typescript/module/engine/testAdUnits.d.ts +33 -0
  302. package/lib/typescript/module/engine/testAdUnits.d.ts.map +1 -0
  303. package/lib/typescript/module/index.d.ts +42 -0
  304. package/lib/typescript/module/index.d.ts.map +1 -0
  305. package/lib/typescript/module/package.json +1 -0
  306. package/lib/typescript/module/react/AdsBanner.d.ts +29 -0
  307. package/lib/typescript/module/react/AdsBanner.d.ts.map +1 -0
  308. package/lib/typescript/module/react/AdsProvider.d.ts +36 -0
  309. package/lib/typescript/module/react/AdsProvider.d.ts.map +1 -0
  310. package/lib/typescript/module/react/hooks.d.ts +27 -0
  311. package/lib/typescript/module/react/hooks.d.ts.map +1 -0
  312. package/lib/typescript/module/testing/clock.d.ts +29 -0
  313. package/lib/typescript/module/testing/clock.d.ts.map +1 -0
  314. package/lib/typescript/module/testing/conformance.d.ts +26 -0
  315. package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
  316. package/lib/typescript/module/testing/index.d.ts +133 -0
  317. package/lib/typescript/module/testing/index.d.ts.map +1 -0
  318. package/package.json +48 -12
  319. package/src/testing/index.ts +17 -3
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Showing full-screen ads (FR-028, FR-030, FR-034, FR-128) and the foreground
5
+ * re-evaluation of what was loaded.
6
+ */
7
+ import { isFullScreenFormat } from "../../config/types.js";
8
+ import { AdsError, normalizeProviderError } from "../../diagnostics/errors.js";
9
+ import { canShow } from "../placementMachine.js";
10
+ import { createRewardedSession } from "../rewardedSession.js";
11
+ import { isStale } from "../timers.js";
12
+ import { validityFor } from "./context.js";
13
+ import { gateRefusal } from "./gate.js";
14
+ import { unknownPlacement } from "./load.js";
15
+ export function createShower(context) {
16
+ const {
17
+ state,
18
+ engine,
19
+ events,
20
+ timers,
21
+ resolved,
22
+ lock,
23
+ adReturn,
24
+ now
25
+ } = context;
26
+
27
+ /** Releases and expires a `ready` ad that outlived its validity (FR-034). */
28
+ function expireIfStale(key, at) {
29
+ const found = context.placement(key);
30
+ if (!found) {
31
+ return false;
32
+ }
33
+ const {
34
+ snapshot
35
+ } = found.runtime;
36
+ if (snapshot.state !== 'ready' || snapshot.loadedAtMs === null || !isStale(snapshot.loadedAtMs, at, validityFor(context, found.definition.format))) {
37
+ return false;
38
+ }
39
+ context.releasePlacementResources(key);
40
+ context.dispatchPlacement(key, {
41
+ type: 'EXPIRE'
42
+ });
43
+ return true;
44
+ }
45
+ return {
46
+ async show(placementKey) {
47
+ if (state.disposed) {
48
+ return {
49
+ status: 'unavailable',
50
+ reason: 'provider_missing'
51
+ };
52
+ }
53
+ const found = context.placement(placementKey);
54
+ if (!found) {
55
+ return unknownPlacement(context, placementKey, 'show');
56
+ }
57
+ const {
58
+ runtime,
59
+ definition
60
+ } = found;
61
+ if (!isFullScreenFormat(definition.format)) {
62
+ return {
63
+ status: 'failed',
64
+ error: new AdsError('format_mismatch', {
65
+ operation: 'show',
66
+ placementKey,
67
+ format: definition.format,
68
+ message: `"${placementKey}" is a banner; banners are rendered, not shown`
69
+ })
70
+ };
71
+ }
72
+ const refusal = gateRefusal(context);
73
+ if (refusal) {
74
+ context.emitRefusal('show', refusal, placementKey, definition.format);
75
+ return refusal;
76
+ }
77
+ // FR-028: never open an ad while the app is not in front of the user.
78
+ if (!state.appActive) {
79
+ return {
80
+ status: 'app_inactive'
81
+ };
82
+ }
83
+ // FR-128. Only app-open is refused: it is the format that would fire on
84
+ // the return from an ad. An interstitial at the same moment is the app's
85
+ // own choice, and refusing it would be policy rather than capability.
86
+ if (definition.format === 'app_open' && adReturn.isRefusing(now())) {
87
+ return {
88
+ status: 'ad_originated_return'
89
+ };
90
+ }
91
+ if (runtime.snapshot.state === 'consumed') {
92
+ return {
93
+ status: 'consumed'
94
+ };
95
+ }
96
+ // FR-034: a stale ad is not shown and is not reported ready.
97
+ if (expireIfStale(placementKey, now())) {
98
+ return {
99
+ status: 'not_ready'
100
+ };
101
+ }
102
+ const handle = runtime.handle;
103
+ if (!canShow(runtime.snapshot.state) || !handle) {
104
+ return {
105
+ status: 'not_ready'
106
+ };
107
+ }
108
+ // FR-030. Never queued: a refused show is refused now, not deferred to a
109
+ // moment the app never chose.
110
+ if (!lock.acquire(placementKey)) {
111
+ return {
112
+ status: 'busy'
113
+ };
114
+ }
115
+ const correlationId = runtime.correlationId ?? context.correlation.next();
116
+ runtime.rewarded = definition.format === 'rewarded' ? createRewardedSession() : null;
117
+ context.dispatchPlacement(placementKey, {
118
+ type: 'SHOW'
119
+ });
120
+ const failShow = error => {
121
+ lock.release(placementKey);
122
+ events.emit({
123
+ type: 'display_failed',
124
+ timestamp: now(),
125
+ placementKey,
126
+ format: definition.format,
127
+ correlationId,
128
+ error
129
+ });
130
+ context.dispatchPlacement(placementKey, {
131
+ type: 'SHOW_FAILED',
132
+ error
133
+ });
134
+ context.releasePlacementResources(placementKey);
135
+ };
136
+
137
+ // ADS-09. Whichever of the provider's answer and the timeout comes first
138
+ // decides the result; the other must not act on it a second time.
139
+ let settled = false;
140
+ const showTimeout = new Promise(resolve => {
141
+ runtime.cancelShowTimer = timers.after(resolved.timeouts.show, () => {
142
+ runtime.cancelShowTimer = null;
143
+ if (settled) {
144
+ return;
145
+ }
146
+ settled = true;
147
+ // The provider may still open the ad. Its handle and listener stay, so
148
+ // a late open, reward or dismissal is still heard and the reward is not
149
+ // lost (FR-049); they go with the next load or with dispose. The lock is
150
+ // released now and taken back if the ad does open.
151
+ lock.release(placementKey);
152
+ const error = new AdsError('show_timeout', {
153
+ operation: 'show',
154
+ placementKey,
155
+ format: definition.format,
156
+ message: `show timed out after ${resolved.timeouts.show}ms`
157
+ });
158
+ events.emit({
159
+ type: 'display_failed',
160
+ timestamp: now(),
161
+ placementKey,
162
+ format: definition.format,
163
+ correlationId,
164
+ error
165
+ });
166
+ context.dispatchPlacement(placementKey, {
167
+ type: 'SHOW_FAILED',
168
+ error
169
+ });
170
+ resolve({
171
+ status: 'timeout'
172
+ });
173
+ });
174
+ });
175
+ const attempt = engine.show(handle).then(() => {
176
+ if (settled) {
177
+ // Opened after the timeout was reported. It is on screen now, so it
178
+ // holds the one full-screen lock until it is dismissed (FR-030).
179
+ lock.acquire(placementKey);
180
+ return {
181
+ status: 'timeout'
182
+ };
183
+ }
184
+ settled = true;
185
+ runtime.cancelShowTimer?.();
186
+ runtime.cancelShowTimer = null;
187
+ return {
188
+ status: 'shown',
189
+ correlationId
190
+ };
191
+ }).catch(error => {
192
+ if (settled) {
193
+ // Failed after the timeout already said so: nothing new to report,
194
+ // and nothing will show, so its resources can go.
195
+ context.releasePlacementResources(placementKey);
196
+ return {
197
+ status: 'timeout'
198
+ };
199
+ }
200
+ settled = true;
201
+ runtime.cancelShowTimer?.();
202
+ runtime.cancelShowTimer = null;
203
+ const normalized = normalizeProviderError(error, {
204
+ operation: 'show',
205
+ placementKey,
206
+ format: definition.format
207
+ });
208
+ failShow(normalized);
209
+ return {
210
+ status: 'failed',
211
+ error: normalized
212
+ };
213
+ });
214
+ return Promise.race([attempt, showTimeout]);
215
+ },
216
+ setAppActive(active) {
217
+ if (state.disposed) {
218
+ return;
219
+ }
220
+ state.appActive = active;
221
+ if (!active) {
222
+ // Arming happens when the provider reports an ad opened; this event can
223
+ // arrive after the ad is gone. All it adds is the browser case, a
224
+ // background closely following a click (FR-128).
225
+ adReturn.noteBackground(now());
226
+ return;
227
+ }
228
+ adReturn.noteForeground(now());
229
+ // FR-034: an ad that went stale while the app was away stops reporting
230
+ // `ready` before the app offers a button that would fail on tap.
231
+ const current = now();
232
+ for (const key of context.placements.keys()) {
233
+ expireIfStale(key, current);
234
+ }
235
+ }
236
+ };
237
+ }
238
+ //# sourceMappingURL=show.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isFullScreenFormat","AdsError","normalizeProviderError","canShow","createRewardedSession","isStale","validityFor","gateRefusal","unknownPlacement","createShower","context","state","engine","events","timers","resolved","lock","adReturn","now","expireIfStale","key","at","found","placement","snapshot","runtime","loadedAtMs","definition","format","releasePlacementResources","dispatchPlacement","type","show","placementKey","disposed","status","reason","error","operation","message","refusal","emitRefusal","appActive","isRefusing","handle","acquire","correlationId","correlation","next","rewarded","failShow","release","emit","timestamp","settled","showTimeout","Promise","resolve","cancelShowTimer","after","timeouts","attempt","then","catch","normalized","race","setAppActive","active","noteBackground","noteForeground","current","placements","keys"],"sourceRoot":"../../../../src","sources":["core/instance/show.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA,SAASA,kBAAkB,QAAQ,uBAAoB;AACvD,SAASC,QAAQ,EAAEC,sBAAsB,QAAQ,6BAA0B;AAC3E,SAASC,OAAO,QAAQ,wBAAqB;AAC7C,SAASC,qBAAqB,QAAQ,uBAAoB;AAC1D,SAASC,OAAO,QAAQ,cAAW;AACnC,SAASC,WAAW,QAA8B,cAAW;AAC7D,SAASC,WAAW,QAAQ,WAAQ;AACpC,SAASC,gBAAgB,QAAQ,WAAQ;AAGzC,OAAO,SAASC,YAAYA,CAACC,OAAwB,EAGnD;EACD,MAAM;IAAEC,KAAK;IAAEC,MAAM;IAAEC,MAAM;IAAEC,MAAM;IAAEC,QAAQ;IAAEC,IAAI;IAAEC,QAAQ;IAAEC;EAAI,CAAC,GAAGR,OAAO;;EAEhF;EACA,SAASS,aAAaA,CAACC,GAAW,EAAEC,EAAU,EAAW;IACxD,MAAMC,KAAK,GAAGZ,OAAO,CAACa,SAAS,CAACH,GAAG,CAAC;IACpC,IAAI,CAACE,KAAK,EAAE;MACX,OAAO,KAAK;IACb;IACA,MAAM;MAAEE;IAAS,CAAC,GAAGF,KAAK,CAACG,OAAO;IAClC,IACCD,QAAQ,CAACb,KAAK,KAAK,OAAO,IAC1Ba,QAAQ,CAACE,UAAU,KAAK,IAAI,IAC5B,CAACrB,OAAO,CAACmB,QAAQ,CAACE,UAAU,EAAEL,EAAE,EAAEf,WAAW,CAACI,OAAO,EAAEY,KAAK,CAACK,UAAU,CAACC,MAAM,CAAC,CAAC,EAC/E;MACD,OAAO,KAAK;IACb;IACAlB,O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ACA,MAAMoD,OAAO,GAAGpD,GAAG,CAAC,CAAC;MACrB,KAAK,MAAME,GAAG,IAAIV,OAAO,CAAC6D,UAAU,CAACC,IAAI,CAAC,CAAC,EAAE;QAC5CrD,aAAa,CAACC,GAAG,EAAEkD,OAAO,CAAC;MAC5B;IACD;EACD,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["core/instance/types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Per-placement lifecycle (FR-026 – FR-031, FR-034).
5
+ *
6
+ * Pure and synchronous, per data-model.md §3.2. Two variants share one reducer:
7
+ *
8
+ * full-screen — load, show once, become `consumed`, reload before the next show
9
+ * banner — continuous; it renders and may refresh, and never reaches
10
+ * `consumed`, because a banner is not a single-use resource
11
+ *
12
+ * Staleness is handled here rather than at the show site so that a stale ad can
13
+ * never be *reported* ready either — a consumer that renders a "Watch ad" button
14
+ * from `state === 'ready'` would otherwise offer a button that fails on tap.
15
+ */
16
+
17
+ export const initialPlacement = {
18
+ state: 'idle',
19
+ loadedAtMs: null,
20
+ error: null,
21
+ correlationId: null
22
+ };
23
+
24
+ /**
25
+ * A load is only legal from a settled state; `loading` is where FR-029 bites.
26
+ * `throttled` is settled too: it records that the last request was refused, and
27
+ * the throttle itself decides whether the next one may proceed.
28
+ */
29
+ export function canLoad(state) {
30
+ return state === 'idle' || state === 'failed' || state === 'consumed' || state === 'ready' || state === 'throttled';
31
+ }
32
+
33
+ /** Only a ready ad may be shown. Everything else is a determinate refusal (FR-028). */
34
+ export function canShow(state) {
35
+ return state === 'ready';
36
+ }
37
+ export function placementReducer(state, event, format) {
38
+ switch (event.type) {
39
+ case 'LOAD':
40
+ // FR-029: a load while already loading is absorbed. The instance
41
+ // returns the in-flight promise; the state does not restart.
42
+ if (state.state === 'loading' || state.state === 'showing') {
43
+ return state;
44
+ }
45
+ if (state.state === 'unavailable') {
46
+ return state;
47
+ }
48
+ return {
49
+ ...initialPlacement,
50
+ state: 'loading'
51
+ };
52
+ case 'LOADED':
53
+ return state.state === 'loading' ? {
54
+ ...state,
55
+ state: 'ready',
56
+ loadedAtMs: event.atMs,
57
+ error: null
58
+ } : state;
59
+ case 'LOAD_FAILED':
60
+ return state.state === 'loading' ? {
61
+ ...initialPlacement,
62
+ state: 'failed',
63
+ error: event.error
64
+ } : state;
65
+ case 'SHOW':
66
+ return state.state === 'ready' ? {
67
+ ...state,
68
+ state: 'showing'
69
+ } : state;
70
+ case 'SHOW_FAILED':
71
+ // A failed presentation consumes the ad regardless: the provider has
72
+ // taken it, and re-showing the same object is what FR-031 forbids.
73
+ return state.state === 'showing' ? {
74
+ ...initialPlacement,
75
+ state: 'failed',
76
+ error: event.error
77
+ } : state;
78
+ case 'DISMISSED':
79
+ if (state.state !== 'showing') {
80
+ return state;
81
+ }
82
+ // A banner is continuous — dismissal is not part of its life. A
83
+ // full-screen ad is spent, and must be reloaded before the next show.
84
+ return format === 'banner' ? {
85
+ ...initialPlacement,
86
+ state: 'idle'
87
+ } : {
88
+ ...initialPlacement,
89
+ state: 'consumed'
90
+ };
91
+ case 'EXPIRE':
92
+ // FR-034. Only a ready-and-waiting ad can go stale; one being shown is
93
+ // already in the user's hands.
94
+ return state.state === 'ready' ? {
95
+ ...initialPlacement,
96
+ state: 'idle'
97
+ } : state;
98
+ case 'UNAVAILABLE':
99
+ return {
100
+ ...initialPlacement,
101
+ state: 'unavailable'
102
+ };
103
+ case 'RESET':
104
+ return initialPlacement;
105
+ default:
106
+ return state;
107
+ }
108
+ }
109
+ //# sourceMappingURL=placementMachine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["initialPlacement","state","loadedAtMs","error","correlationId","canLoad","canShow","placementReducer","event","format","type","atMs"],"sourceRoot":"../../../src","sources":["core/placementMachine.ts"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,CAACL;MAAM,CAAC,GAC5DF,KAAK;IAET,KAAK,MAAM;MACV,OAAOA,KAAK,CAACA,KAAK,KAAK,OAAO,GAAG;QAAE,GAAGA,KAAK;QAAEA,KAAK,EAAE;MAAU,CAAC,GAAGA,KAAK;IAExE,KAAK,aAAa;MACjB;MACA;MACA,OAAOA,KAAK,CAACA,KAAK,KAAK,SAAS,GAC7B;QAAE,GAAGD,gBAAgB;QAAEC,KAAK,EAAE,QAAQ;QAAEE,KAAK,EAAEK,KAAK,CAACL;MAAM,CAAC,GAC5DF,KAAK;IAET,KAAK,WAAW;MACf,IAAIA,KAAK,CAACA,KAAK,KAAK,SAAS,EAAE;QAC9B,OAAOA,KAAK;MACb;MACA;MACA;MACA,OAAOQ,MAAM,KAAK,QAAQ,GACvB;QAAE,GAAGT,gBAAgB;QAAEC,KAAK,EAAE;MAAO,CAAC,GACtC;QAAE,GAAGD,gBAAgB;QAAEC,KAAK,EAAE;MAAW,CAAC;IAE9C,KAAK,QAAQ;MACZ;MACA;MACA,OAAOA,KAAK,CAACA,KAAK,KAAK,OAAO,GAAG;QAAE,GAAGD,gBAAgB;QAAEC,KAAK,EAAE;MAAO,CAAC,GAAGA,KAAK;IAEhF,KAAK,aAAa;MACjB,OAAO;QAAE,GAAGD,gBAAgB;QAAEC,KAAK,EAAE;MAAc,CAAC;IAErD,KAAK,OAAO;MACX,OAAOD,gBAAgB;IAExB;MACC,OAAOC,KAAK;EACd;AACD","ignoreList":[]}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * The privacy gate (FR-016 – FR-021).
5
+ *
6
+ * The package enforces ordering; the app owns policy. It renders no consent UI,
7
+ * writes no legal copy, and decides nothing about a jurisdiction — it accepts a
8
+ * gate outcome and refuses to let any request precede it.
9
+ *
10
+ * That refusal is the whole value. Consent ordering is easy to get wrong by
11
+ * accident, and the failure is invisible: an ad request that should not have
12
+ * happened looks exactly like one that should. A package that enforces the order
13
+ * is worth more than documentation that describes it.
14
+ *
15
+ * Pure — no provider, no React, no I/O. The engine adapter translates the
16
+ * outcome into provider configuration.
17
+ */
18
+
19
+ export function evaluateGate(privacy) {
20
+ if (!privacy) {
21
+ return {
22
+ allowed: false,
23
+ reason: 'consent_required'
24
+ };
25
+ }
26
+ if (privacy.canRequestAds) {
27
+ return {
28
+ allowed: true
29
+ };
30
+ }
31
+ // Distinguishing "not asked yet" from "asked and refused" matters: the first
32
+ // is a prompt the app still owes the user, the second is a settled answer.
33
+ // Collapsing them would leave the app unable to tell which (FR-018).
34
+ return {
35
+ allowed: false,
36
+ reason: privacy.consentUndetermined ? 'consent_undetermined' : 'consent_required'
37
+ };
38
+ }
39
+
40
+ /**
41
+ * Flags the provider only honors at initialization time.
42
+ *
43
+ * Changing one of these after `initialize()` cannot take effect, which is why
44
+ * `updatePrivacy` reports `requires_reinitialization` instead of accepting the
45
+ * change and leaving the package in a state that is half old and half new
46
+ * (FR-020).
47
+ *
48
+ * `canRequestAds` is absent on purpose: resolving the gate after being blocked
49
+ * is the normal, supported flow, not a reinitialization (FR-019).
50
+ */
51
+ const INIT_TIME_ONLY = ['childDirected', 'underAgeOfConsent', 'maxAdContentRating'];
52
+ export function requiresReinitialization(applied, next) {
53
+ if (!applied) {
54
+ return false;
55
+ }
56
+ return INIT_TIME_ONLY.some(field => applied[field] !== next[field]);
57
+ }
58
+
59
+ /**
60
+ * Projects consumer privacy options onto what the engine needs.
61
+ *
62
+ * `personalizedAds` is carried through rather than inverted here; the adapter
63
+ * owns the translation to the provider's `requestNonPersonalizedAdsOnly`, so
64
+ * the polarity flip lives next to the API that requires it.
65
+ */
66
+ export function toEnginePrivacy(privacy, testDeviceIds) {
67
+ return {
68
+ childDirected: privacy.childDirected,
69
+ underAgeOfConsent: privacy.underAgeOfConsent,
70
+ maxAdContentRating: privacy.maxAdContentRating,
71
+ personalizedAds: privacy.personalizedAds,
72
+ testDeviceIds
73
+ };
74
+ }
75
+
76
+ /**
77
+ * What every ad request carries. Unset means personalized, matching the
78
+ * documented default of `PrivacyOptions.personalizedAds`; only an explicit
79
+ * `false` opts out.
80
+ */
81
+ export function toEngineRequest(privacy) {
82
+ return {
83
+ personalizedAds: privacy?.personalizedAds !== false
84
+ };
85
+ }
86
+ //# sourceMappingURL=privacyGate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["evaluateGate","privacy","allowed","reason","canRequestAds","consentUndetermined","INIT_TIME_ONLY","requiresReinitialization","applied","next","some","field","toEnginePrivacy","testDeviceIds","childDirected","underAgeOfConsent","maxAdContentRating","personalizedAds","toEngineRequest"],"sourceRoot":"../../../src","sources":["core/privacyGate.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,OAAO,SAASA,YAAYA,CAACC,OAA8B,EAAgB;EAC1E,IAAI,CAACA,OAAO,EAAE;IACb,OAAO;MAAEC,OAAO,EAAE,KAAK;MAAEC,MAAM,EAAE;IAAmB,CAAC;EACtD;EACA,IAAIF,OAAO,CAACG,aAAa,EAAE;IAC1B,OAAO;MAAEF,OAAO,EAAE;IAAK,CAAC;EACzB;EACA;EACA;EACA;EACA,OAAO;IACNA,OAAO,EAAE,KAAK;IACdC,MAAM,EAAEF,OAAO,CAACI,mBAAmB,GAAG,sBAAsB,GAAG;EAChE,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,cAAc,GAAG,CACtB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,CACiC;AAEtD,OAAO,SAASC,wBAAwBA,CACvCC,OAA8B,EAC9BC,IAAoB,EACV;EACV,IAAI,CAACD,OAAO,EAAE;IACb,OAAO,KAAK;EACb;EACA,OAAOF,cAAc,CAACI,IAAI,CAACC,KAAK,IAAIH,OAAO,CAACG,KAAK,CAAC,KAAKF,IAAI,CAACE,KAAK,CAAC,CAAC;AACpE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC9BX,OAAuB,EACvBY,aAAgC,EAChB;EAChB,OAAO;IACNC,aAAa,EAAEb,OAAO,CAACa,aAAa;IACpCC,iBAAiB,EAAEd,OAAO,CAACc,iBAAiB;IAC5CC,kBAAkB,EAAEf,OAAO,CAACe,kBAAkB;IAC9CC,eAAe,EAAEhB,OAAO,CAACgB,eAAe;IACxCJ;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,eAAeA,CAACjB,OAA8B,EAAwB;EACrF,OAAO;IAAEgB,eAAe,EAAEhB,OAAO,EAAEgB,eAAe,KAAK;EAAM,CAAC;AAC/D","ignoreList":[]}
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Per-placement request throttle (FR-140).
5
+ *
6
+ * This exists to protect the **ad account**, not to shape product behaviour, and
7
+ * that distinction is the whole reason it lives in the package:
8
+ *
9
+ * | Decision | Owner |
10
+ * |---|---|
11
+ * | How often to *show* an interstitial | the app — product policy |
12
+ * | How often the same placement may *request* | the package — account safety |
13
+ *
14
+ * Rapid repeat requests for one placement are read by ad networks as invalid
15
+ * traffic, and the penalty is account-level and not recoverable by shipping a
16
+ * fix. That puts it in the same class as the test-ad substitution the package
17
+ * already enforces: a safety property the library guarantees rather than
18
+ * documents and hopes each app remembers.
19
+ *
20
+ * ## The pattern it is built for
21
+ *
22
+ * A banner mounted inside a view the user navigates between — a day in a
23
+ * calendar, a tab, a row in a list — is unmounted and remounted by React on every
24
+ * navigation. Each remount is a fresh provider request. A user swiping quickly
25
+ * through ten days produces ten requests in a few seconds, and nothing about that
26
+ * is the app author doing something wrong.
27
+ *
28
+ * Full-screen formats do not have this problem: they are loaded by an explicit
29
+ * call, not mounted by a renderer. That asymmetry is why the default differs by
30
+ * format — see `defaultMinRequestIntervalMs`.
31
+ *
32
+ * The better *architectural* answer is to keep the banner outside the subtree that
33
+ * remounts. This throttle is the safety net for when that is not possible, not a
34
+ * licence to ignore the problem; the README says so where an app author will read
35
+ * it.
36
+ */
37
+
38
+ /**
39
+ * AdMob's own documented floor for banner auto-refresh is 60 seconds, so
40
+ * requesting the same banner placement more often than that is, by the provider's
41
+ * own standard, more often than it considers reasonable. Taking the provider's
42
+ * number rather than inventing one means the default is defensible rather than
43
+ * arbitrary.
44
+ */
45
+ export const DEFAULT_BANNER_MIN_REQUEST_INTERVAL_MS = 60_000;
46
+
47
+ /**
48
+ * Off by default for full-screen formats.
49
+ *
50
+ * `load` → `show` → `load` is the normal, healthy cycle for an interstitial, and
51
+ * an app that sells three things in two minutes legitimately loads three times.
52
+ * Throttling that by default would break correct apps to solve a problem those
53
+ * formats do not have. An app that wants a floor here can set one.
54
+ */
55
+ export const DEFAULT_FULL_SCREEN_MIN_REQUEST_INTERVAL_MS = 0;
56
+ export const MIN_REQUEST_INTERVAL_BOUNDS = {
57
+ min: 0,
58
+ max: 600_000
59
+ };
60
+
61
+ /** The format-aware default, applied when a placement configures nothing. */
62
+ export function defaultMinRequestIntervalMs(format) {
63
+ return format === 'banner' ? DEFAULT_BANNER_MIN_REQUEST_INTERVAL_MS : DEFAULT_FULL_SCREEN_MIN_REQUEST_INTERVAL_MS;
64
+ }
65
+ export function createRequestThrottle(now) {
66
+ const lastAt = new Map();
67
+ /** The token and verdict of the most recent acquisition, for idempotency. */
68
+ const lastToken = new Map();
69
+ const decide = (key, minIntervalMs) => {
70
+ // Zero is the documented way to turn the throttle off, so it must never
71
+ // consult the clock — an app that sets 0 should behave exactly as it did
72
+ // before this feature existed.
73
+ if (minIntervalMs <= 0) {
74
+ return {
75
+ allowed: true
76
+ };
77
+ }
78
+ const previous = lastAt.get(key);
79
+ if (previous === undefined) {
80
+ return {
81
+ allowed: true
82
+ };
83
+ }
84
+ const elapsed = now() - previous;
85
+ // A clock that moved backwards — a manual time change, or an NTP
86
+ // correction — must not lock a placement out until the clock catches up.
87
+ // Treating it as "enough time passed" fails open, which is right: the
88
+ // throttle protects against bursts, and a backwards clock is not a burst.
89
+ if (elapsed < 0) {
90
+ return {
91
+ allowed: true
92
+ };
93
+ }
94
+ if (elapsed >= minIntervalMs) {
95
+ return {
96
+ allowed: true
97
+ };
98
+ }
99
+ return {
100
+ allowed: false,
101
+ retryAfterMs: minIntervalMs - elapsed
102
+ };
103
+ };
104
+ return {
105
+ waitFor(key, minIntervalMs) {
106
+ const decision = decide(key, minIntervalMs);
107
+ return decision.allowed ? 0 : decision.retryAfterMs;
108
+ },
109
+ tryAcquire(key, minIntervalMs, token) {
110
+ if (token !== undefined) {
111
+ const previous = lastToken.get(key);
112
+ if (previous?.token === token) {
113
+ // Same cycle asking again. Replaying the stored verdict keeps a
114
+ // double-invoked render from charging twice, and keeps a refused
115
+ // cycle refused rather than letting a retry slip through.
116
+ return previous.decision;
117
+ }
118
+ }
119
+
120
+ // Nothing is recorded when the throttle is off for this placement.
121
+ // Recording would be dead work, and it would also mean that turning the
122
+ // throttle on later immediately compared against a stale timestamp.
123
+ if (minIntervalMs <= 0) {
124
+ return {
125
+ allowed: true
126
+ };
127
+ }
128
+ const decision = decide(key, minIntervalMs);
129
+ if (decision.allowed) {
130
+ lastAt.set(key, now());
131
+ }
132
+ if (token !== undefined) {
133
+ lastToken.set(key, {
134
+ token,
135
+ decision
136
+ });
137
+ }
138
+ return decision;
139
+ },
140
+ clear() {
141
+ lastAt.clear();
142
+ lastToken.clear();
143
+ }
144
+ };
145
+ }
146
+ //# sourceMappingURL=requestThrottle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DEFAULT_BANNER_MIN_REQUEST_INTERVAL_MS","DEFAULT_FULL_SCREEN_MIN_REQUEST_INTERVAL_MS","MIN_REQUEST_INTERVAL_BOUNDS","min","max","defaultMinRequestIntervalMs","format","createRequestThrottle","now","lastAt","Map","lastToken","decide","key","minIntervalMs","allowed","previous","get","undefined","elapsed","retryAfterMs","waitFor","decision","tryAcquire","token","set","clear"],"sourceRoot":"../../../src","sources":["core/requestThrottle.ts"],"mappings":";;AAAA;AACA;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