@chipmobilesdk/rn-ads 0.6.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.
- package/CHANGELOG.md +139 -0
- package/README.md +4 -2
- package/lib/commonjs/config/resolveAdUnit.js +80 -0
- package/lib/commonjs/config/resolveAdUnit.js.map +1 -0
- package/lib/commonjs/config/types.js +138 -0
- package/lib/commonjs/config/types.js.map +1 -0
- package/lib/commonjs/config/validate.js +150 -0
- package/lib/commonjs/config/validate.js.map +1 -0
- package/lib/commonjs/core/adOriginatedReturn.js +119 -0
- package/lib/commonjs/core/adOriginatedReturn.js.map +1 -0
- package/lib/commonjs/core/adsInstance.js +129 -0
- package/lib/commonjs/core/adsInstance.js.map +1 -0
- package/lib/commonjs/core/consentFlow.js +154 -0
- package/lib/commonjs/core/consentFlow.js.map +1 -0
- package/lib/commonjs/core/enablement.js +64 -0
- package/lib/commonjs/core/enablement.js.map +1 -0
- package/lib/commonjs/core/fullScreenLock.js +48 -0
- package/lib/commonjs/core/fullScreenLock.js.map +1 -0
- package/lib/commonjs/core/gates.js +95 -0
- package/lib/commonjs/core/gates.js.map +1 -0
- package/lib/commonjs/core/initMachine.js +159 -0
- package/lib/commonjs/core/initMachine.js.map +1 -0
- package/lib/commonjs/core/instance/consent.js +155 -0
- package/lib/commonjs/core/instance/consent.js.map +1 -0
- package/lib/commonjs/core/instance/context.js +217 -0
- package/lib/commonjs/core/instance/context.js.map +1 -0
- package/lib/commonjs/core/instance/gate.js +194 -0
- package/lib/commonjs/core/instance/gate.js.map +1 -0
- package/lib/commonjs/core/instance/init.js +326 -0
- package/lib/commonjs/core/instance/init.js.map +1 -0
- package/lib/commonjs/core/instance/internals.js +115 -0
- package/lib/commonjs/core/instance/internals.js.map +1 -0
- package/lib/commonjs/core/instance/load.js +458 -0
- package/lib/commonjs/core/instance/load.js.map +1 -0
- package/lib/commonjs/core/instance/show.js +243 -0
- package/lib/commonjs/core/instance/show.js.map +1 -0
- package/lib/commonjs/core/instance/types.js +6 -0
- package/lib/commonjs/core/instance/types.js.map +1 -0
- package/lib/commonjs/core/placementMachine.js +116 -0
- package/lib/commonjs/core/placementMachine.js.map +1 -0
- package/lib/commonjs/core/privacyGate.js +93 -0
- package/lib/commonjs/core/privacyGate.js.map +1 -0
- package/lib/commonjs/core/requestThrottle.js +152 -0
- package/lib/commonjs/core/requestThrottle.js.map +1 -0
- package/lib/commonjs/core/retryPolicy.js +120 -0
- package/lib/commonjs/core/retryPolicy.js.map +1 -0
- package/lib/commonjs/core/rewardedSession.js +65 -0
- package/lib/commonjs/core/rewardedSession.js.map +1 -0
- package/lib/commonjs/core/timers.js +162 -0
- package/lib/commonjs/core/timers.js.map +1 -0
- package/lib/commonjs/diagnostics/correlation.js +33 -0
- package/lib/commonjs/diagnostics/correlation.js.map +1 -0
- package/lib/commonjs/diagnostics/errors.js +152 -0
- package/lib/commonjs/diagnostics/errors.js.map +1 -0
- package/lib/commonjs/diagnostics/events.js +132 -0
- package/lib/commonjs/diagnostics/events.js.map +1 -0
- package/lib/commonjs/engine/admobBanner.js +58 -0
- package/lib/commonjs/engine/admobBanner.js.map +1 -0
- package/lib/commonjs/engine/admobEngine.js +343 -0
- package/lib/commonjs/engine/admobEngine.js.map +1 -0
- package/lib/commonjs/engine/admobErrors.js +45 -0
- package/lib/commonjs/engine/admobErrors.js.map +1 -0
- package/lib/commonjs/engine/port.js +6 -0
- package/lib/commonjs/engine/port.js.map +1 -0
- package/lib/commonjs/engine/testAdUnits.js +61 -0
- package/lib/commonjs/engine/testAdUnits.js.map +1 -0
- package/lib/commonjs/index.js +218 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/react/AdsBanner.js +317 -0
- package/lib/commonjs/react/AdsBanner.js.map +1 -0
- package/lib/commonjs/react/AdsProvider.js +54 -0
- package/lib/commonjs/react/AdsProvider.js.map +1 -0
- package/lib/commonjs/react/hooks.js +63 -0
- package/lib/commonjs/react/hooks.js.map +1 -0
- package/lib/commonjs/testing/clock.js +76 -0
- package/lib/commonjs/testing/clock.js.map +1 -0
- package/lib/commonjs/testing/conformance.js +99 -0
- package/lib/commonjs/testing/conformance.js.map +1 -0
- package/lib/commonjs/testing/index.js +389 -0
- package/lib/commonjs/testing/index.js.map +1 -0
- package/lib/module/config/resolveAdUnit.js +75 -0
- package/lib/module/config/resolveAdUnit.js.map +1 -0
- package/lib/module/config/types.js +134 -0
- package/lib/module/config/types.js.map +1 -0
- package/lib/module/config/validate.js +146 -0
- package/lib/module/config/validate.js.map +1 -0
- package/lib/module/core/adOriginatedReturn.js +115 -0
- package/lib/module/core/adOriginatedReturn.js.map +1 -0
- package/lib/module/core/adsInstance.js +121 -0
- package/lib/module/core/adsInstance.js.map +1 -0
- package/lib/module/core/consentFlow.js +143 -0
- package/lib/module/core/consentFlow.js.map +1 -0
- package/lib/module/core/enablement.js +58 -0
- package/lib/module/core/enablement.js.map +1 -0
- package/lib/module/core/fullScreenLock.js +44 -0
- package/lib/module/core/fullScreenLock.js.map +1 -0
- package/lib/module/core/gates.js +91 -0
- package/lib/module/core/gates.js.map +1 -0
- package/lib/module/core/initMachine.js +152 -0
- package/lib/module/core/initMachine.js.map +1 -0
- package/lib/module/core/instance/consent.js +151 -0
- package/lib/module/core/instance/consent.js.map +1 -0
- package/lib/module/core/instance/context.js +212 -0
- package/lib/module/core/instance/context.js.map +1 -0
- package/lib/module/core/instance/gate.js +183 -0
- package/lib/module/core/instance/gate.js.map +1 -0
- package/lib/module/core/instance/init.js +321 -0
- package/lib/module/core/instance/init.js.map +1 -0
- package/lib/module/core/instance/internals.js +109 -0
- package/lib/module/core/instance/internals.js.map +1 -0
- package/lib/module/core/instance/load.js +452 -0
- package/lib/module/core/instance/load.js.map +1 -0
- package/lib/module/core/instance/show.js +238 -0
- package/lib/module/core/instance/show.js.map +1 -0
- package/lib/module/core/instance/types.js +4 -0
- package/lib/module/core/instance/types.js.map +1 -0
- package/lib/module/core/placementMachine.js +109 -0
- package/lib/module/core/placementMachine.js.map +1 -0
- package/lib/module/core/privacyGate.js +86 -0
- package/lib/module/core/privacyGate.js.map +1 -0
- package/lib/module/core/requestThrottle.js +146 -0
- package/lib/module/core/requestThrottle.js.map +1 -0
- package/lib/module/core/retryPolicy.js +113 -0
- package/lib/module/core/retryPolicy.js.map +1 -0
- package/lib/module/core/rewardedSession.js +61 -0
- package/lib/module/core/rewardedSession.js.map +1 -0
- package/lib/module/core/timers.js +150 -0
- package/lib/module/core/timers.js.map +1 -0
- package/lib/module/diagnostics/correlation.js +29 -0
- package/lib/module/diagnostics/correlation.js.map +1 -0
- package/lib/module/diagnostics/errors.js +143 -0
- package/lib/module/diagnostics/errors.js.map +1 -0
- package/lib/module/diagnostics/events.js +128 -0
- package/lib/module/diagnostics/events.js.map +1 -0
- package/lib/module/engine/admobBanner.js +52 -0
- package/lib/module/engine/admobBanner.js.map +1 -0
- package/lib/module/engine/admobEngine.js +334 -0
- package/lib/module/engine/admobEngine.js.map +1 -0
- package/lib/module/engine/admobErrors.js +41 -0
- package/lib/module/engine/admobErrors.js.map +1 -0
- package/lib/module/engine/port.js +4 -0
- package/lib/module/engine/port.js.map +1 -0
- package/lib/module/engine/testAdUnits.js +56 -0
- package/lib/module/engine/testAdUnits.js.map +1 -0
- package/lib/module/index.js +59 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/react/AdsBanner.js +312 -0
- package/lib/module/react/AdsBanner.js.map +1 -0
- package/lib/module/react/AdsProvider.js +48 -0
- package/lib/module/react/AdsProvider.js.map +1 -0
- package/lib/module/react/hooks.js +58 -0
- package/lib/module/react/hooks.js.map +1 -0
- package/lib/module/testing/clock.js +72 -0
- package/lib/module/testing/clock.js.map +1 -0
- package/lib/module/testing/conformance.js +93 -0
- package/lib/module/testing/conformance.js.map +1 -0
- package/lib/module/testing/index.js +366 -0
- package/lib/module/testing/index.js.map +1 -0
- package/lib/typescript/commonjs/config/resolveAdUnit.d.ts +43 -0
- package/lib/typescript/commonjs/config/resolveAdUnit.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/types.d.ts +280 -0
- package/lib/typescript/commonjs/config/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/validate.d.ts +49 -0
- package/lib/typescript/commonjs/config/validate.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/adOriginatedReturn.d.ts +61 -0
- package/lib/typescript/commonjs/core/adOriginatedReturn.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/adsInstance.d.ts +33 -0
- package/lib/typescript/commonjs/core/adsInstance.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/consentFlow.d.ts +84 -0
- package/lib/typescript/commonjs/core/consentFlow.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/enablement.d.ts +74 -0
- package/lib/typescript/commonjs/core/enablement.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/fullScreenLock.d.ts +25 -0
- package/lib/typescript/commonjs/core/fullScreenLock.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/gates.d.ts +76 -0
- package/lib/typescript/commonjs/core/gates.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/initMachine.d.ts +66 -0
- package/lib/typescript/commonjs/core/initMachine.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/instance/consent.d.ts +4 -0
- package/lib/typescript/commonjs/core/instance/consent.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/instance/context.d.ts +118 -0
- package/lib/typescript/commonjs/core/instance/context.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/instance/gate.d.ts +38 -0
- package/lib/typescript/commonjs/core/instance/gate.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/instance/init.d.ts +13 -0
- package/lib/typescript/commonjs/core/instance/init.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/instance/internals.d.ts +60 -0
- package/lib/typescript/commonjs/core/instance/internals.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/instance/load.d.ts +9 -0
- package/lib/typescript/commonjs/core/instance/load.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/instance/show.d.ts +7 -0
- package/lib/typescript/commonjs/core/instance/show.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/instance/types.d.ts +240 -0
- package/lib/typescript/commonjs/core/instance/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/placementMachine.d.ts +55 -0
- package/lib/typescript/commonjs/core/placementMachine.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/privacyGate.d.ts +40 -0
- package/lib/typescript/commonjs/core/privacyGate.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/requestThrottle.d.ts +99 -0
- package/lib/typescript/commonjs/core/requestThrottle.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/retryPolicy.d.ts +66 -0
- package/lib/typescript/commonjs/core/retryPolicy.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/rewardedSession.d.ts +37 -0
- package/lib/typescript/commonjs/core/rewardedSession.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/timers.d.ts +135 -0
- package/lib/typescript/commonjs/core/timers.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/correlation.d.ts +18 -0
- package/lib/typescript/commonjs/diagnostics/correlation.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/errors.d.ts +59 -0
- package/lib/typescript/commonjs/diagnostics/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/events.d.ts +126 -0
- package/lib/typescript/commonjs/diagnostics/events.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/admobBanner.d.ts +10 -0
- package/lib/typescript/commonjs/engine/admobBanner.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/admobEngine.d.ts +71 -0
- package/lib/typescript/commonjs/engine/admobEngine.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/admobErrors.d.ts +9 -0
- package/lib/typescript/commonjs/engine/admobErrors.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/port.d.ts +171 -0
- package/lib/typescript/commonjs/engine/port.d.ts.map +1 -0
- package/lib/typescript/commonjs/engine/testAdUnits.d.ts +33 -0
- package/lib/typescript/commonjs/engine/testAdUnits.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +42 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/react/AdsBanner.d.ts +29 -0
- package/lib/typescript/commonjs/react/AdsBanner.d.ts.map +1 -0
- package/lib/typescript/commonjs/react/AdsProvider.d.ts +36 -0
- package/lib/typescript/commonjs/react/AdsProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/react/hooks.d.ts +27 -0
- package/lib/typescript/commonjs/react/hooks.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/clock.d.ts +29 -0
- package/lib/typescript/commonjs/testing/clock.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts +26 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/index.d.ts +133 -0
- package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
- package/lib/typescript/module/config/resolveAdUnit.d.ts +43 -0
- package/lib/typescript/module/config/resolveAdUnit.d.ts.map +1 -0
- package/lib/typescript/module/config/types.d.ts +280 -0
- package/lib/typescript/module/config/types.d.ts.map +1 -0
- package/lib/typescript/module/config/validate.d.ts +49 -0
- package/lib/typescript/module/config/validate.d.ts.map +1 -0
- package/lib/typescript/module/core/adOriginatedReturn.d.ts +61 -0
- package/lib/typescript/module/core/adOriginatedReturn.d.ts.map +1 -0
- package/lib/typescript/module/core/adsInstance.d.ts +33 -0
- package/lib/typescript/module/core/adsInstance.d.ts.map +1 -0
- package/lib/typescript/module/core/consentFlow.d.ts +84 -0
- package/lib/typescript/module/core/consentFlow.d.ts.map +1 -0
- package/lib/typescript/module/core/enablement.d.ts +74 -0
- package/lib/typescript/module/core/enablement.d.ts.map +1 -0
- package/lib/typescript/module/core/fullScreenLock.d.ts +25 -0
- package/lib/typescript/module/core/fullScreenLock.d.ts.map +1 -0
- package/lib/typescript/module/core/gates.d.ts +76 -0
- package/lib/typescript/module/core/gates.d.ts.map +1 -0
- package/lib/typescript/module/core/initMachine.d.ts +66 -0
- package/lib/typescript/module/core/initMachine.d.ts.map +1 -0
- package/lib/typescript/module/core/instance/consent.d.ts +4 -0
- package/lib/typescript/module/core/instance/consent.d.ts.map +1 -0
- package/lib/typescript/module/core/instance/context.d.ts +118 -0
- package/lib/typescript/module/core/instance/context.d.ts.map +1 -0
- package/lib/typescript/module/core/instance/gate.d.ts +38 -0
- package/lib/typescript/module/core/instance/gate.d.ts.map +1 -0
- package/lib/typescript/module/core/instance/init.d.ts +13 -0
- package/lib/typescript/module/core/instance/init.d.ts.map +1 -0
- package/lib/typescript/module/core/instance/internals.d.ts +60 -0
- package/lib/typescript/module/core/instance/internals.d.ts.map +1 -0
- package/lib/typescript/module/core/instance/load.d.ts +9 -0
- package/lib/typescript/module/core/instance/load.d.ts.map +1 -0
- package/lib/typescript/module/core/instance/show.d.ts +7 -0
- package/lib/typescript/module/core/instance/show.d.ts.map +1 -0
- package/lib/typescript/module/core/instance/types.d.ts +240 -0
- package/lib/typescript/module/core/instance/types.d.ts.map +1 -0
- package/lib/typescript/module/core/placementMachine.d.ts +55 -0
- package/lib/typescript/module/core/placementMachine.d.ts.map +1 -0
- package/lib/typescript/module/core/privacyGate.d.ts +40 -0
- package/lib/typescript/module/core/privacyGate.d.ts.map +1 -0
- package/lib/typescript/module/core/requestThrottle.d.ts +99 -0
- package/lib/typescript/module/core/requestThrottle.d.ts.map +1 -0
- package/lib/typescript/module/core/retryPolicy.d.ts +66 -0
- package/lib/typescript/module/core/retryPolicy.d.ts.map +1 -0
- package/lib/typescript/module/core/rewardedSession.d.ts +37 -0
- package/lib/typescript/module/core/rewardedSession.d.ts.map +1 -0
- package/lib/typescript/module/core/timers.d.ts +135 -0
- package/lib/typescript/module/core/timers.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/correlation.d.ts +18 -0
- package/lib/typescript/module/diagnostics/correlation.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/errors.d.ts +59 -0
- package/lib/typescript/module/diagnostics/errors.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/events.d.ts +126 -0
- package/lib/typescript/module/diagnostics/events.d.ts.map +1 -0
- package/lib/typescript/module/engine/admobBanner.d.ts +10 -0
- package/lib/typescript/module/engine/admobBanner.d.ts.map +1 -0
- package/lib/typescript/module/engine/admobEngine.d.ts +71 -0
- package/lib/typescript/module/engine/admobEngine.d.ts.map +1 -0
- package/lib/typescript/module/engine/admobErrors.d.ts +9 -0
- package/lib/typescript/module/engine/admobErrors.d.ts.map +1 -0
- package/lib/typescript/module/engine/port.d.ts +171 -0
- package/lib/typescript/module/engine/port.d.ts.map +1 -0
- package/lib/typescript/module/engine/testAdUnits.d.ts +33 -0
- package/lib/typescript/module/engine/testAdUnits.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +42 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/react/AdsBanner.d.ts +29 -0
- package/lib/typescript/module/react/AdsBanner.d.ts.map +1 -0
- package/lib/typescript/module/react/AdsProvider.d.ts +36 -0
- package/lib/typescript/module/react/AdsProvider.d.ts.map +1 -0
- package/lib/typescript/module/react/hooks.d.ts +27 -0
- package/lib/typescript/module/react/hooks.d.ts.map +1 -0
- package/lib/typescript/module/testing/clock.d.ts +29 -0
- package/lib/typescript/module/testing/clock.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance.d.ts +26 -0
- package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/module/testing/index.d.ts +133 -0
- package/lib/typescript/module/testing/index.d.ts.map +1 -0
- package/package.json +48 -12
- package/skills/sdk-rn-ads/SKILL.md +2 -1
- package/src/core/adsInstance.ts +72 -1829
- package/src/core/consentFlow.ts +1 -20
- package/src/core/instance/consent.ts +162 -0
- package/src/core/instance/context.ts +328 -0
- package/src/core/instance/gate.ts +147 -0
- package/src/core/instance/init.ts +262 -0
- package/src/core/instance/internals.ts +138 -0
- package/src/core/instance/load.ts +426 -0
- package/src/core/instance/show.ts +202 -0
- package/src/core/instance/types.ts +198 -0
- package/src/core/requestThrottle.ts +11 -17
- package/src/diagnostics/errors.ts +24 -5
- package/src/engine/admobBanner.tsx +55 -0
- package/src/engine/admobEngine.ts +21 -12
- package/src/engine/admobErrors.ts +44 -0
- package/src/engine/port.ts +46 -1
- package/src/engine/testAdUnits.ts +0 -5
- package/src/react/AdsBanner.tsx +81 -80
- package/src/testing/clock.ts +75 -0
- package/src/testing/index.ts +43 -68
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Adaptive banner host (FR-038 – FR-042).
|
|
5
|
+
*
|
|
6
|
+
* The app puts this where it wants a banner. The component never inserts itself
|
|
7
|
+
* into the tree, never overlays app content, and ships no placeholder — the
|
|
8
|
+
* surrounding layout, and any loading or fallback presentation, belong to the
|
|
9
|
+
* app and its theme (FR-040, UX-001).
|
|
10
|
+
*
|
|
11
|
+
* When ads are disabled or unavailable it renders `null` rather than a
|
|
12
|
+
* zero-height view. That is not a micro-optimization: a rendered empty view
|
|
13
|
+
* still sits in the accessibility tree and can take screen-reader focus ahead of
|
|
14
|
+
* real content. `null` leaves the tree entirely (UX-003).
|
|
15
|
+
*
|
|
16
|
+
* The provider owns the banner's whole lifecycle through its own component, so
|
|
17
|
+
* this adapts those callbacks into the normalized event model instead of routing
|
|
18
|
+
* a banner through the load/show handle model, which does not fit it.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import React, { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
22
|
+
import { View } from 'react-native';
|
|
23
|
+
import { normalizeProviderError } from "../diagnostics/errors.js";
|
|
24
|
+
import { useAds } from "./AdsProvider.js";
|
|
25
|
+
import { getInternals } from "../core/adsInstance.js";
|
|
26
|
+
import { useAdsStatus } from "./hooks.js";
|
|
27
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
|
+
export function AdsBanner({
|
|
29
|
+
placementKey,
|
|
30
|
+
onStateChange,
|
|
31
|
+
style
|
|
32
|
+
}) {
|
|
33
|
+
const ads = useAds();
|
|
34
|
+
// The instance's banner wiring (ADS-13). An instance the app wrote by hand has
|
|
35
|
+
// none, and is treated like a missing one.
|
|
36
|
+
const internals = useMemo(() => ads ? getInternals(ads) : null, [ads]);
|
|
37
|
+
// The throttle token for this mount: stable across renders and minted by React
|
|
38
|
+
// rather than by a counter, so a render that runs twice charges one slot.
|
|
39
|
+
const mountToken = useId();
|
|
40
|
+
// The reported state lives in a ref rather than in component state: the host
|
|
41
|
+
// itself renders the same tree for every state, so storing it would only
|
|
42
|
+
// force re-renders the PERF-002 budget does not need to spend. The instance
|
|
43
|
+
// holds the authoritative value; `onStateChange` tells the app.
|
|
44
|
+
const stateRef = useRef('idle');
|
|
45
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
46
|
+
// A new cycle id remounts the provider component, which is how a width change
|
|
47
|
+
// produces a genuinely re-adapted banner rather than a stretched old one.
|
|
48
|
+
const [cycle, setCycle] = useState(0);
|
|
49
|
+
const correlationRef = useRef(null);
|
|
50
|
+
// Whether the current correlation already reported `loaded`. The provider
|
|
51
|
+
// auto-refreshes a banner inside one mount; each refresh is a new cycle.
|
|
52
|
+
const loadedInCycleRef = useRef(false);
|
|
53
|
+
const startedAtRef = useRef(0);
|
|
54
|
+
// Whether this mount has already taken a throttle slot, and the refusal if it
|
|
55
|
+
// was refused. Resets with the mount, which is exactly the granularity FR-140
|
|
56
|
+
// needs.
|
|
57
|
+
const throttleRef = useRef({
|
|
58
|
+
decided: false,
|
|
59
|
+
refusal: null
|
|
60
|
+
});
|
|
61
|
+
// Which attempt this mount is on. A refused mount asks again once the window
|
|
62
|
+
// passes (ADS-06), and each attempt needs its own token: the throttle replays
|
|
63
|
+
// the stored verdict for a token it has seen.
|
|
64
|
+
const throttleAttemptRef = useRef(0);
|
|
65
|
+
|
|
66
|
+
// The engine's banner component (ADS-12): the host never names the provider.
|
|
67
|
+
const banner = useMemo(() => internals?.banner() ?? null, [internals]);
|
|
68
|
+
// Initialization is asynchronous and a banner is almost always mounted before
|
|
69
|
+
// it finishes. Without this the resolution below would be computed once, while
|
|
70
|
+
// the instance was still `not_started`, be refused, and never be retried — the
|
|
71
|
+
// banner would sit at `unavailable` forever on a perfectly healthy app.
|
|
72
|
+
const status = useAdsStatus();
|
|
73
|
+
|
|
74
|
+
// Keyed on `cycle` so a genuine width change starts a new, separately traceable
|
|
75
|
+
// load (FR-038, FR-052), and on `status` so the banner recovers the moment the
|
|
76
|
+
// instance becomes able to request. Pure: the cycle's correlation id is minted
|
|
77
|
+
// in the effect that starts it, not here (ADS-20).
|
|
78
|
+
const resolved = useMemo(() => internals && status === 'ready' ? {
|
|
79
|
+
cycle,
|
|
80
|
+
value: internals.resolveBanner(placementKey)
|
|
81
|
+
} : null, [internals, placementKey, cycle, status]);
|
|
82
|
+
const resolution = resolved?.value ?? null;
|
|
83
|
+
const move = useCallback(next => {
|
|
84
|
+
if (stateRef.current === next) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
stateRef.current = next;
|
|
88
|
+
internals?.setPlacementState(placementKey, next);
|
|
89
|
+
onStateChange?.(next);
|
|
90
|
+
}, [internals, onStateChange, placementKey]);
|
|
91
|
+
|
|
92
|
+
// FR-140. Decided **during render**, not in the effect below, because the
|
|
93
|
+
// provider component requests an ad as part of this very render — an effect
|
|
94
|
+
// would refuse a request that had already gone out.
|
|
95
|
+
//
|
|
96
|
+
// Charged once per mount, guarded by the ref. That granularity is the whole
|
|
97
|
+
// distinction the throttle turns on: a fresh mount is the navigation burst it
|
|
98
|
+
// exists to stop (swiping between days, switching tabs, a row scrolling in and
|
|
99
|
+
// out), while a later cycle in the *same* mount is a width re-adaptation —
|
|
100
|
+
// rotation — which must not be refused or a rotated screen loses its banner
|
|
101
|
+
// for up to a minute.
|
|
102
|
+
if (internals && resolution?.ok && containerWidth > 0 && !throttleRef.current.decided) {
|
|
103
|
+
throttleRef.current = {
|
|
104
|
+
decided: true,
|
|
105
|
+
refusal: internals.commitBannerRequest(placementKey, `${mountToken}:${throttleAttemptRef.current}`)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const throttleRefusal = throttleRef.current.refusal;
|
|
109
|
+
const usable = Boolean(internals && banner && resolution?.ok && containerWidth > 0 && !throttleRefusal);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!internals || !banner) {
|
|
112
|
+
move('unavailable');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// `not_started` and `initializing` are transient: the app is still on its
|
|
116
|
+
// way and the banner will resolve shortly, so report `idle` rather than
|
|
117
|
+
// `unavailable` and let the app keep its layout decision open. Every other
|
|
118
|
+
// non-ready status — disabled, blocked, failed, unsupported — means there
|
|
119
|
+
// will be no ad, and the app should reclaim the space (FR-039, FR-042).
|
|
120
|
+
//
|
|
121
|
+
// `undecided` is the exception added in 0.2.0, and it is the entire reason
|
|
122
|
+
// the third state exists. It is reported as itself rather than folded into
|
|
123
|
+
// either neighbour: `idle` would say "an ad is coming", which is not known
|
|
124
|
+
// yet, and `unavailable` would say "there will be none", which is also not
|
|
125
|
+
// known. Only by reporting it honestly can the app decide whether to hold
|
|
126
|
+
// the space — the choice that keeps a paying user from watching an ad
|
|
127
|
+
// flash in and out (FR-116).
|
|
128
|
+
if (status !== 'ready') {
|
|
129
|
+
move(status === 'undecided' ? 'undecided' : status === 'not_started' || status === 'initializing' ? 'idle' : 'unavailable');
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!resolution?.ok) {
|
|
133
|
+
move('unavailable');
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (containerWidth <= 0) {
|
|
137
|
+
// FR-039: a zero-width container is reported rather than turned into a
|
|
138
|
+
// request for an ad at a nonsensical size.
|
|
139
|
+
move('idle');
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// The slot was taken during render; here is where the refusal becomes
|
|
143
|
+
// observable. Reported as `throttled` rather than folded into
|
|
144
|
+
// `unavailable`: that would say "there will be no ad here", when in fact
|
|
145
|
+
// this placement asked too recently and will work again shortly. Most apps
|
|
146
|
+
// collapse the space for both, but only one is worth investigating.
|
|
147
|
+
if (throttleRefusal) {
|
|
148
|
+
move('throttled');
|
|
149
|
+
internals.emit({
|
|
150
|
+
type: 'request_throttled',
|
|
151
|
+
timestamp: internals.now(),
|
|
152
|
+
placementKey,
|
|
153
|
+
format: 'banner',
|
|
154
|
+
retryAfterMs: throttleRefusal.retryAfterMs,
|
|
155
|
+
minRequestIntervalMs: internals.throttleFloorFor(placementKey)
|
|
156
|
+
});
|
|
157
|
+
// ADS-06: ask again in this same mount once the window has passed. Until
|
|
158
|
+
// 0.7.0 a refused banner stayed empty until it was remounted, so a banner
|
|
159
|
+
// pinned to a screen the user returned to within a minute never filled.
|
|
160
|
+
return internals.schedule(throttleRefusal.retryAfterMs, () => {
|
|
161
|
+
throttleRef.current = {
|
|
162
|
+
decided: false,
|
|
163
|
+
refusal: null
|
|
164
|
+
};
|
|
165
|
+
throttleAttemptRef.current += 1;
|
|
166
|
+
setCycle(value => value + 1);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const correlationId = internals.nextCorrelationId();
|
|
170
|
+
correlationRef.current = correlationId;
|
|
171
|
+
loadedInCycleRef.current = false;
|
|
172
|
+
startedAtRef.current = internals.now();
|
|
173
|
+
move('loading');
|
|
174
|
+
internals.emit({
|
|
175
|
+
type: 'load_started',
|
|
176
|
+
timestamp: startedAtRef.current,
|
|
177
|
+
placementKey,
|
|
178
|
+
format: 'banner',
|
|
179
|
+
correlationId
|
|
180
|
+
});
|
|
181
|
+
// Deliberately keyed on `cycle`, not on every render: FR-041 forbids a
|
|
182
|
+
// re-render from producing a second uncontrolled request.
|
|
183
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
184
|
+
}, [internals, banner, status, resolution, containerWidth, cycle]);
|
|
185
|
+
const onLayout = useCallback(event => {
|
|
186
|
+
const width = Math.round(event.nativeEvent.layout.width);
|
|
187
|
+
setContainerWidth(previous => {
|
|
188
|
+
if (previous === width) {
|
|
189
|
+
return previous;
|
|
190
|
+
}
|
|
191
|
+
// FR-038: a genuine width or orientation change re-adapts. The
|
|
192
|
+
// rounding above stops sub-pixel layout jitter from doing so.
|
|
193
|
+
if (previous > 0 && width > 0) {
|
|
194
|
+
setCycle(value => value + 1);
|
|
195
|
+
}
|
|
196
|
+
return width;
|
|
197
|
+
});
|
|
198
|
+
}, []);
|
|
199
|
+
const emit = useCallback(event => {
|
|
200
|
+
internals?.emit(event);
|
|
201
|
+
}, [internals]);
|
|
202
|
+
const clock = useCallback(() => internals?.now() ?? Date.now(), [internals]);
|
|
203
|
+
const handleLoaded = useCallback(() => {
|
|
204
|
+
// A second load in one correlation is the provider's auto-refresh: a new
|
|
205
|
+
// ad, so a new cycle. Under the old correlation its `loaded` and
|
|
206
|
+
// `impression` were deduplicated away and revenue went uncounted (ADS-05).
|
|
207
|
+
// For a refresh, `durationMs` is the time since the previous load.
|
|
208
|
+
if (loadedInCycleRef.current && internals) {
|
|
209
|
+
correlationRef.current = internals.nextCorrelationId();
|
|
210
|
+
}
|
|
211
|
+
loadedInCycleRef.current = true;
|
|
212
|
+
const loadedAt = clock();
|
|
213
|
+
move('ready');
|
|
214
|
+
emit({
|
|
215
|
+
type: 'loaded',
|
|
216
|
+
timestamp: loadedAt,
|
|
217
|
+
placementKey,
|
|
218
|
+
format: 'banner',
|
|
219
|
+
correlationId: correlationRef.current ?? undefined,
|
|
220
|
+
durationMs: loadedAt - startedAtRef.current
|
|
221
|
+
});
|
|
222
|
+
startedAtRef.current = loadedAt;
|
|
223
|
+
}, [internals, clock, emit, move, placementKey]);
|
|
224
|
+
const handleFailed = useCallback((error, kind) => {
|
|
225
|
+
const normalized = normalizeProviderError(error, {
|
|
226
|
+
operation: 'load',
|
|
227
|
+
placementKey,
|
|
228
|
+
format: 'banner'
|
|
229
|
+
}, kind);
|
|
230
|
+
move('failed');
|
|
231
|
+
emit({
|
|
232
|
+
type: 'load_failed',
|
|
233
|
+
timestamp: clock(),
|
|
234
|
+
placementKey,
|
|
235
|
+
format: 'banner',
|
|
236
|
+
correlationId: correlationRef.current ?? undefined,
|
|
237
|
+
error: normalized
|
|
238
|
+
});
|
|
239
|
+
}, [clock, emit, move, placementKey]);
|
|
240
|
+
const handleImpression = useCallback(() => {
|
|
241
|
+
emit({
|
|
242
|
+
type: 'impression',
|
|
243
|
+
timestamp: clock(),
|
|
244
|
+
placementKey,
|
|
245
|
+
format: 'banner',
|
|
246
|
+
correlationId: correlationRef.current ?? undefined,
|
|
247
|
+
// A real provider impression, unlike the derived one full-screen
|
|
248
|
+
// formats get. The distinction is load-bearing for revenue
|
|
249
|
+
// reconciliation, so it is recorded rather than flattened (R5).
|
|
250
|
+
source: 'provider'
|
|
251
|
+
});
|
|
252
|
+
}, [clock, emit, placementKey]);
|
|
253
|
+
const handleClicked = useCallback(() => {
|
|
254
|
+
emit({
|
|
255
|
+
type: 'click',
|
|
256
|
+
timestamp: clock(),
|
|
257
|
+
placementKey,
|
|
258
|
+
format: 'banner',
|
|
259
|
+
correlationId: correlationRef.current ?? undefined
|
|
260
|
+
});
|
|
261
|
+
}, [clock, emit, placementKey]);
|
|
262
|
+
|
|
263
|
+
// FR-041: nothing survives unmount. No retained native view, no dangling
|
|
264
|
+
// correlation, no state written into a disposed instance.
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
return () => {
|
|
267
|
+
correlationRef.current = null;
|
|
268
|
+
};
|
|
269
|
+
}, []);
|
|
270
|
+
if (!internals || !banner) {
|
|
271
|
+
// FR-042, UX-003 — out of the tree entirely, blocking no touch.
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// A terminal non-ready status means there will be no ad at all, so leave the
|
|
276
|
+
// tree rather than render an empty host. `not_started` and `initializing` are
|
|
277
|
+
// excluded on purpose: the host must stay mounted through them, because it is
|
|
278
|
+
// what measures the container and starts the load once the instance is ready.
|
|
279
|
+
//
|
|
280
|
+
// `undecided` is excluded for the same reason: the app may still resolve it to
|
|
281
|
+
// enabled, and a host that unmounted would have to re-measure the container
|
|
282
|
+
// from scratch when it did. It renders no ad meanwhile — it renders the same
|
|
283
|
+
// empty measuring host it renders while initializing — and it reports
|
|
284
|
+
// `undecided` so the app can size the space it decided to keep.
|
|
285
|
+
if (status === 'disabled' || status === 'unavailable' || status === 'failed') {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
if (resolution && !resolution.ok) {
|
|
289
|
+
const refusal = resolution.result;
|
|
290
|
+
// `undecided` deliberately absent: unlike `disabled`, it is not a settled
|
|
291
|
+
// no, so the host stays mounted (FR-116).
|
|
292
|
+
if (refusal.status === 'disabled' || refusal.status === 'unavailable') {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const BannerComponent = banner.Component;
|
|
297
|
+
const adUnitId = resolution?.ok ? resolution.adUnitId : null;
|
|
298
|
+
return /*#__PURE__*/_jsx(View, {
|
|
299
|
+
style: style,
|
|
300
|
+
onLayout: onLayout,
|
|
301
|
+
testID: `ads-banner-${placementKey}`,
|
|
302
|
+
children: usable && adUnitId && resolution?.ok ? /*#__PURE__*/_jsx(BannerComponent, {
|
|
303
|
+
adUnitId: adUnitId,
|
|
304
|
+
personalizedAds: resolution.personalizedAds,
|
|
305
|
+
onLoaded: handleLoaded,
|
|
306
|
+
onFailed: handleFailed,
|
|
307
|
+
onImpression: handleImpression,
|
|
308
|
+
onClicked: handleClicked
|
|
309
|
+
}, `${placementKey}-${cycle}`) : null
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=AdsBanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useCallback","useEffect","useId","useMemo","useRef","useState","View","normalizeProviderError","useAds","getInternals","useAdsStatus","jsx","_jsx","AdsBanner","placementKey","onStateChange","style","ads","internals","mountToken","stateRef","containerWidth","setContainerWidth","cycle","setCycle","correlationRef","loadedInCycleRef","startedAtRef","throttleRef","decided","refusal","throttleAttemptRef","banner","status","resolved","value","resolveBanner","resolution","move","next","current","setPlacementState","ok","commitBannerRequest","throttleRefusal","usable","Boolean","emit","type","timestamp","now","format","retryAfterMs","minRequestIntervalMs","throttleFloorFor","schedule","correlationId","nextCorrelationId","onLayout","event","width","Math","round","nativeEvent","layout","previous","clock","Date","handleLoaded","loadedAt","undefined","durationMs","handleFailed","error","kind","normalized","operation","handleImpression","source","handleClicked","result","BannerComponent","Component","adUnitId","testID","children","personalizedAds","onLoaded","onFailed","onImpression","onClicked"],"sourceRoot":"../../../src","sources":["react/AdsBanner.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,SAAS,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACvF,SAASC,IAAI,QAAgD,cAAc;AAG3E,SAASC,sBAAsB,QAAQ,0BAAuB;AAG9D,SAASC,MAAM,QAAQ,kBAAe;AACtC,SAASC,YAAY,QAA8B,wBAAqB;AACxE,SAASC,YAAY,QAAQ,YAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAUvC,OAAO,SAASC,SAASA,CAAC;EAAEC,YAAY;EAAEC,aAAa;EAAEC;AAAsB,CAAC,EAAE;EACjF,MAAMC,GAAG,GAAGT,MAAM,CAAC,CAAC;EACpB;EACA;EACA,MAAMU,SAAS,GAAGf,OAAO,CAAC,MAAOc,GAAG,GAAGR,YAAY,CAACQ,GAAG,CA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I9C,UAAU,EAAEK,EAAE,gBACpC9B,IAAA,CAACqE,eAAe;MAEfE,QAAQ,EAAEA,QAAS;MACnBG,eAAe,EAAEjD,UAAU,CAACiD,eAAgB;MAC5CC,QAAQ,EAAEnB,YAAa;MACvBoB,QAAQ,EAAEhB,YAAa;MACvBiB,YAAY,EAAEZ,gBAAiB;MAC/Ba,SAAS,EAAEX;IAAc,GANpB,GAAGjE,YAAY,IAAIS,KAAK,EAO7B,CAAC,GACC;EAAI,CACH,CAAC;AAET","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Instance context (US1).
|
|
5
|
+
*
|
|
6
|
+
* Supplies one `AdsInstance` to the tree so `AdsBanner` and the hooks can reach
|
|
7
|
+
* it without every screen threading it through props.
|
|
8
|
+
*
|
|
9
|
+
* The provider does not create the instance. The app does, and passes it in —
|
|
10
|
+
* because `createAds` throws on a misconfigured catalog (FR-008, FR-012), and a
|
|
11
|
+
* throw during render is a far worse place to discover that than a throw at
|
|
12
|
+
* startup where the app can decide what to do about it.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { appLifecycle } from '@chipmobilesdk/rn-core';
|
|
16
|
+
import React, { createContext, useContext, useEffect } from 'react';
|
|
17
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
const AdsContext = /*#__PURE__*/createContext(null);
|
|
19
|
+
export function AdsProvider({
|
|
20
|
+
instance,
|
|
21
|
+
trackAppState = true,
|
|
22
|
+
children
|
|
23
|
+
}) {
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!trackAppState) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
return appLifecycle().subscribe(state => {
|
|
29
|
+
instance.setAppActive(state === 'active');
|
|
30
|
+
});
|
|
31
|
+
}, [instance, trackAppState]);
|
|
32
|
+
return /*#__PURE__*/_jsx(AdsContext.Provider, {
|
|
33
|
+
value: instance,
|
|
34
|
+
children: children
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns the instance, or null outside a provider.
|
|
40
|
+
*
|
|
41
|
+
* Null rather than a throw on purpose: a screen that renders a banner should
|
|
42
|
+
* degrade to rendering nothing when ads are not wired up, not take the screen
|
|
43
|
+
* down with it (NFR-005).
|
|
44
|
+
*/
|
|
45
|
+
export function useAds() {
|
|
46
|
+
return useContext(AdsContext);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=AdsProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["appLifecycle","React","createContext","useContext","useEffect","jsx","_jsx","AdsContext","AdsProvider","instance","trackAppState","children","subscribe","state","setAppActive","Provider","value","useAds"],"sourceRoot":"../../../src","sources":["react/AdsProvider.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,QAAQ,wBAAwB;AACrD,OAAOC,KAAK,IAAIC,aAAa,EAAEC,UAAU,EAAEC,SAAS,QAAwB,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAIpF,MAAMC,UAAU,gBAAGL,aAAa,CAAqB,IAAI,CAAC;AAgB1D,OAAO,SAASM,WAAWA,CAAC;EAAEC,QAAQ;EAAEC,aAAa,GAAG,IAAI;EAAEC;AAA2B,CAAC,EAAE;EAC3FP,SAAS,CAAC,MAAM;IACf,IAAI,CAACM,aAAa,EAAE;MACnB;IACD;IACA,OAAOV,YAAY,CAAC,CAAC,CAACY,SAAS,CAACC,KAAK,IAAI;MACxCJ,QAAQ,CAACK,YAAY,CAACD,KAAK,KAAK,QAAQ,CAAC;IAC1C,CAAC,CAAC;EACH,CAAC,EAAE,CAACJ,QAAQ,EAAEC,aAAa,CAAC,CAAC;EAE7B,oBAAOJ,IAAA,CAACC,UAAU,CAACQ,QAAQ;IAACC,KAAK,EAAEP,QAAS;IAAAE,QAAA,EAAEA;EAAQ,CAAsB,CAAC;AAC9E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,MAAMA,CAAA,EAAuB;EAC5C,OAAOd,UAAU,CAACI,UAAU,CAAC;AAC9B","ignoreList":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* React bindings (US1, FR-027).
|
|
5
|
+
*
|
|
6
|
+
* Each hook subscribes to exactly what it reads. `usePlacementState` subscribes
|
|
7
|
+
* to one placement rather than to the whole event stream, which is what keeps a
|
|
8
|
+
* banner from re-rendering because an unrelated interstitial was clicked —
|
|
9
|
+
* PERF-002's bounded re-render assertion depends on it.
|
|
10
|
+
*
|
|
11
|
+
* None of these hand back an ad object. A consumer queries and subscribes to
|
|
12
|
+
* state; it never holds provider-owned memory (FR-027).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { useExternalStore, useLatestCallback } from '@chipmobilesdk/rn-core/react';
|
|
16
|
+
import { useCallback, useEffect } from 'react';
|
|
17
|
+
import { useAds } from "./AdsProvider.js";
|
|
18
|
+
|
|
19
|
+
/** Live state for one placement. `unavailable` outside a provider. */
|
|
20
|
+
export function usePlacementState(placementKey) {
|
|
21
|
+
const ads = useAds();
|
|
22
|
+
const subscribe = useCallback(listener => ads ? ads.subscribePlacement(placementKey, listener) : NO_SUBSCRIPTION, [ads, placementKey]);
|
|
23
|
+
const getSnapshot = useCallback(() => ads ? ads.getPlacementState(placementKey) : 'unavailable', [ads, placementKey]);
|
|
24
|
+
// useSyncExternalStore: tear-free, and no transition lost between render and
|
|
25
|
+
// subscription, which the useState copy had to re-read to avoid.
|
|
26
|
+
return useExternalStore(subscribe, getSnapshot);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Live initialization status. `unavailable` outside a provider. */
|
|
30
|
+
export function useAdsStatus() {
|
|
31
|
+
const ads = useAds();
|
|
32
|
+
const subscribe = useCallback(listener => ads ? ads.subscribeStatus(listener) : NO_SUBSCRIPTION, [ads]);
|
|
33
|
+
const getSnapshot = useCallback(() => ads ? ads.getStatus() : 'unavailable', [ads]);
|
|
34
|
+
return useExternalStore(subscribe, getSnapshot);
|
|
35
|
+
}
|
|
36
|
+
const NO_SUBSCRIPTION = () => undefined;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Forwards every event to a listener without causing a render.
|
|
40
|
+
*
|
|
41
|
+
* Deliberately does not accumulate events into state: a package that kept an
|
|
42
|
+
* event log would be persisting exactly the kind of history it promises not to
|
|
43
|
+
* (FR-021), and re-rendering on every impression would defeat PERF-002. A screen
|
|
44
|
+
* that wants a visible log keeps its own.
|
|
45
|
+
*/
|
|
46
|
+
export function useAdsEvents(listener) {
|
|
47
|
+
const ads = useAds();
|
|
48
|
+
// An inline listener is a new function every render; subscribing through the
|
|
49
|
+
// latest one keeps a single subscription per instance (PERF-13).
|
|
50
|
+
const latest = useLatestCallback(listener);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!ads) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
return ads.subscribeEvents(latest);
|
|
56
|
+
}, [ads, latest]);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useExternalStore","useLatestCallback","useCallback","useEffect","useAds","usePlacementState","placementKey","ads","subscribe","listener","subscribePlacement","NO_SUBSCRIPTION","getSnapshot","getPlacementState","useAdsStatus","subscribeStatus","getStatus","undefined","useAdsEvents","latest","subscribeEvents"],"sourceRoot":"../../../src","sources":["react/hooks.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,gBAAgB,EAAEC,iBAAiB,QAAQ,8BAA8B;AAClF,SAASC,WAAW,EAAEC,SAAS,QAAQ,OAAO;AAI9C,SAASC,MAAM,QAAQ,kBAA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;MACT;IACD;IACA,OAAOA,GAAG,CAACa,eAAe,CAACD,MAAM,CAAC;EACnC,CAAC,EAAE,CAACZ,GAAG,EAAEY,MAAM,CAAC,CAAC;AAClB","ignoreList":[]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A clock the test drives (ADS-11).
|
|
5
|
+
*
|
|
6
|
+
* Every bounded wait in this package — retry backoff, the request throttle, a
|
|
7
|
+
* consent form that never answers — is measured against a clock. Injecting this
|
|
8
|
+
* one is what lets a suite assert the behaviour at the boundary instead of
|
|
9
|
+
* sleeping and hoping.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A clock a test can move by hand.
|
|
14
|
+
*
|
|
15
|
+
* Retry backoff, app-open expiry, the undecided-state warning, and the
|
|
16
|
+
* ad-originated-return windows are all time-dependent, and all four must be
|
|
17
|
+
* assertable exactly rather than approximately. Advancing a clock makes "two
|
|
18
|
+
* retries, 2s then 4s" a precise assertion; sleeping would make it a flaky one.
|
|
19
|
+
*
|
|
20
|
+
* Callbacks fire in due order, and a callback scheduled *during* an advance is
|
|
21
|
+
* honored within the same advance if its deadline has also passed — matching how
|
|
22
|
+
* real timers behave when work chains.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export function createTestClock(startMs = 1_000_000) {
|
|
26
|
+
let current = startMs;
|
|
27
|
+
let sequence = 0;
|
|
28
|
+
const timers = new Map();
|
|
29
|
+
const scheduler = {
|
|
30
|
+
setTimeout(callback, ms) {
|
|
31
|
+
sequence += 1;
|
|
32
|
+
timers.set(sequence, {
|
|
33
|
+
at: current + ms,
|
|
34
|
+
callback
|
|
35
|
+
});
|
|
36
|
+
return sequence;
|
|
37
|
+
},
|
|
38
|
+
clearTimeout(handle) {
|
|
39
|
+
timers.delete(handle);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
now: () => current,
|
|
44
|
+
advance(ms) {
|
|
45
|
+
const target = current + ms;
|
|
46
|
+
// Loop rather than iterate once: a fired callback may schedule another
|
|
47
|
+
// timer that is also due before `target`, which is exactly what a retry
|
|
48
|
+
// chain does.
|
|
49
|
+
for (;;) {
|
|
50
|
+
let nextId = null;
|
|
51
|
+
let nextAt = Number.POSITIVE_INFINITY;
|
|
52
|
+
for (const [id, timer] of timers) {
|
|
53
|
+
if (timer.at <= target && timer.at < nextAt) {
|
|
54
|
+
nextAt = timer.at;
|
|
55
|
+
nextId = id;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (nextId === null) {
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
const timer = timers.get(nextId);
|
|
62
|
+
timers.delete(nextId);
|
|
63
|
+
current = timer.at;
|
|
64
|
+
timer.callback();
|
|
65
|
+
}
|
|
66
|
+
current = target;
|
|
67
|
+
},
|
|
68
|
+
scheduler,
|
|
69
|
+
pending: () => timers.size
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createTestClock","startMs","current","sequence","timers","Map","scheduler","setTimeout","callback","ms","set","at","clearTimeout","handle","delete","now","advance","target","nextId","nextAt","Number","POSITIVE_INFINITY","id","timer","get","pending","size"],"sourceRoot":"../../../src","sources":["testing/clock.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,OAAO,SAASA,eAAeA,CAACC,OAAO,GAAG,SAAS,EAAa;EAC/D,IAAIC,OAAO,GAAGD,OAAO;EACrB,IAAIE,QAAQ,GAAG,CAAC;EAChB,MAAMC,MAAM,GAAG,IAAIC,GAAG,CAA+C,CAAC;EAEtE,MAAMC,SAAoB,GAAG;IAC5BC,UAAUA,CAACC,QAAQ,EAAEC,EAAE,EAAE;MACxBN,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|
+
* The same checks run against the fake engine and against the AdMob adapter over
|
|
7
|
+
* the provider mock (or the real provider, from a demo screen on a device), so a
|
|
8
|
+
* test that drives the fake proves something about the device path. The subject
|
|
9
|
+
* says how the provider delivers its callbacks; the checks only use the port.
|
|
10
|
+
*/
|
|
11
|
+
import { ensure, runChecks } from '@chipmobilesdk/rn-core/testing';
|
|
12
|
+
/** Lets callbacks a provider delivers on a later microtask arrive. */
|
|
13
|
+
async function settle() {
|
|
14
|
+
for (let turn = 0; turn < 3; turn += 1) {
|
|
15
|
+
await Promise.resolve();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export const adsEngineChecks = [{
|
|
19
|
+
name: 'is available, and initializes with privacy applied',
|
|
20
|
+
async run(harness) {
|
|
21
|
+
const {
|
|
22
|
+
engine
|
|
23
|
+
} = harness.create();
|
|
24
|
+
ensure(engine.isAvailable(), 'reported unavailable');
|
|
25
|
+
await engine.initialize({
|
|
26
|
+
childDirected: true,
|
|
27
|
+
maxAdContentRating: 'G'
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}, {
|
|
31
|
+
name: 'delivers loaded to a subscriber of an interstitial, and nothing after unsubscribing',
|
|
32
|
+
async run(harness) {
|
|
33
|
+
const subject = harness.create();
|
|
34
|
+
const handle = await subject.engine.createFullScreen('interstitial', 'conformance/1');
|
|
35
|
+
ensure(typeof handle.id === 'string' && handle.id !== '', 'handle has no id');
|
|
36
|
+
const seen = [];
|
|
37
|
+
const stop = subject.engine.subscribe(handle, event => seen.push(event.type));
|
|
38
|
+
subject.deliverLoad(handle);
|
|
39
|
+
await settle();
|
|
40
|
+
ensure(seen.join(',') === 'loaded', `subscriber saw ${seen.join(',') || 'nothing'}`);
|
|
41
|
+
stop();
|
|
42
|
+
stop();
|
|
43
|
+
subject.deliverDismiss(handle);
|
|
44
|
+
await settle();
|
|
45
|
+
ensure(seen.length === 1, `notified after unsubscribing: ${seen.join(',')}`);
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
name: 'delivers the reward and the dismissal of a rewarded ad',
|
|
49
|
+
async run(harness) {
|
|
50
|
+
const subject = harness.create();
|
|
51
|
+
const handle = await subject.engine.createFullScreen('rewarded', 'conformance/2', {
|
|
52
|
+
personalizedAds: false
|
|
53
|
+
});
|
|
54
|
+
const seen = [];
|
|
55
|
+
subject.engine.subscribe(handle, event => seen.push(event));
|
|
56
|
+
subject.deliverLoad(handle);
|
|
57
|
+
await settle();
|
|
58
|
+
subject.deliverReward(handle, {
|
|
59
|
+
type: 'coins',
|
|
60
|
+
amount: 5
|
|
61
|
+
});
|
|
62
|
+
subject.deliverDismiss(handle);
|
|
63
|
+
await settle();
|
|
64
|
+
const reward = seen.find(event => event.type === 'rewarded');
|
|
65
|
+
ensure(reward?.type === 'rewarded', `no reward among ${seen.map(e => e.type).join(',')}`);
|
|
66
|
+
ensure(reward.reward.type === 'coins' && reward.reward.amount === 5, `reward ${JSON.stringify(reward.reward)}`);
|
|
67
|
+
ensure(seen.at(-1)?.type === 'dismissed', `last event ${seen.at(-1)?.type}`);
|
|
68
|
+
}
|
|
69
|
+
}, {
|
|
70
|
+
name: 'gives every ad its own handle',
|
|
71
|
+
async run(harness) {
|
|
72
|
+
const {
|
|
73
|
+
engine
|
|
74
|
+
} = harness.create();
|
|
75
|
+
const first = await engine.createFullScreen('interstitial', 'conformance/1');
|
|
76
|
+
const second = await engine.createFullScreen('interstitial', 'conformance/1');
|
|
77
|
+
ensure(first.id !== second.id, 'two ads share a handle');
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
name: 'disposes safely twice',
|
|
81
|
+
async run(harness) {
|
|
82
|
+
const {
|
|
83
|
+
engine
|
|
84
|
+
} = harness.create();
|
|
85
|
+
const handle = await engine.createFullScreen('interstitial', 'conformance/1');
|
|
86
|
+
engine.dispose(handle);
|
|
87
|
+
engine.dispose(handle);
|
|
88
|
+
}
|
|
89
|
+
}];
|
|
90
|
+
export function runAdsEngineConformance(harness) {
|
|
91
|
+
return runChecks(() => harness, adsEngineChecks);
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=conformance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ensure","runChecks","settle","turn","Promise","resolve","adsEngineChecks","name","run","harness","engine","create","isAvailable","initialize","childDirected","maxAdContentRating","subject","handle","createFullScreen","id","seen","stop","subscribe","event","push","type","deliverLoad","join","deliverDismiss","length","personalizedAds","deliverReward","amount","reward","find","map","e","JSON","stringify","at","first","second","dispose","runAdsEngineConformance"],"sourceRoot":"../../../src","sources":["testing/conformance.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SACCA,MAAM,EACNC,SAAS,QAGH,gCAAgC;AAmBvC;AACA,eAAeC,MAAMA,CAAA,EAAkB;EACtC,KAAK,IAAIC,IAAI,GAAG,CAAC,EAAEA,IAAI,GAAG,CAAC,EAAEA,IAAI,IAAI,CAAC,EAAE;IACvC,MAAMC,OAAO,CAACC,OAAO,CAAC,CAAC;EACxB;AACD;AAEA,OAAO,MAAMC,eAAmD,GAAG,CAClE;EACCC,IAAI,EAAE,oDAAoD;EAC1D,MAAMC,GAAGA,CAACC,OAAO,EAAE;IAClB,MAAM;MAAEC;IAAO,CAAC,GAAGD,OAAO,CAACE,MAAM,CAAC,CAAC;IACnCX,MAAM,CAACU,MAAM,CAACE,WAAW,CAAC,CAAC,EAAE,sBAAsB,CAAC;IACpD,MAAMF,MAAM,CAACG,UAAU,CAAC;MAAEC,aAAa,EAAE,IAAI;MAAEC,kBAAkB,EAAE;IAAI,CAAC,CAAC;EAC1E;AACD,CAAC,EACD;EACCR,IAAI,EAAE,qFAAqF;EAC3F,MAAMC,GAAGA,CAACC,OAAO,EAAE;IAClB,MAAMO,OAAO,GAAGP,OAAO,CAACE,MAAM,CAAC,CAAC;IAChC,MAAMM,MAAM,GAAG,MAAMD,OAAO,CAACN,MAAM,CAACQ,gBAAgB,CAAC,cAAc,EAAE,eAAe,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