@billdog.io/react-native 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BillDogReactNative.podspec +30 -0
- package/LICENSE +21 -0
- package/README.md +330 -0
- package/android/build.gradle +99 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/kotlin/io/billdog/reactnative/BillDogABTestModule.kt +317 -0
- package/android/src/main/kotlin/io/billdog/reactnative/BillDogAnalyticsModule.kt +389 -0
- package/android/src/main/kotlin/io/billdog/reactnative/BillDogModule.kt +817 -0
- package/android/src/main/kotlin/io/billdog/reactnative/BillDogPaywallViewManager.kt +383 -0
- package/android/src/main/kotlin/io/billdog/reactnative/BillDogSurveyModule.kt +427 -0
- package/android/src/main/kotlin/io/billdog/reactnative/BillDogVirtualCurrencyModule.kt +407 -0
- package/android/src/main/kotlin/io/billdog/virtualcurrency/BillDogVirtualCurrencyPackage.kt +44 -0
- package/dist/AdvancedPaywallCache.d.ts +70 -0
- package/dist/AdvancedPaywallCache.js +344 -0
- package/dist/BillDog.d.ts +255 -0
- package/dist/BillDog.js +918 -0
- package/dist/BillDogConfiguration.d.ts +145 -0
- package/dist/BillDogConfiguration.js +229 -0
- package/dist/ComponentRenderer.d.ts +17 -0
- package/dist/ComponentRenderer.js +886 -0
- package/dist/LayoutEngine.d.ts +101 -0
- package/dist/LayoutEngine.js +394 -0
- package/dist/LocalizationResolver.d.ts +99 -0
- package/dist/LocalizationResolver.js +266 -0
- package/dist/NativePaywallView.d.ts +36 -0
- package/dist/NativePaywallView.js +59 -0
- package/dist/PaywallCache.d.ts +74 -0
- package/dist/PaywallCache.js +293 -0
- package/dist/PaywallStateManager.d.ts +62 -0
- package/dist/PaywallStateManager.js +147 -0
- package/dist/PaywallView.d.ts +42 -0
- package/dist/PaywallView.js +275 -0
- package/dist/ProductVariableProvider.d.ts +60 -0
- package/dist/ProductVariableProvider.js +239 -0
- package/dist/VariableResolver.d.ts +120 -0
- package/dist/VariableResolver.js +379 -0
- package/dist/WebViewPaywall.d.ts +75 -0
- package/dist/WebViewPaywall.js +360 -0
- package/dist/animations/presets.d.ts +49 -0
- package/dist/animations/presets.js +367 -0
- package/dist/components/AccoladeCpsComponent.d.ts +13 -0
- package/dist/components/AccoladeCpsComponent.js +248 -0
- package/dist/components/AccordionComponent.d.ts +10 -0
- package/dist/components/AccordionComponent.js +187 -0
- package/dist/components/AnimatedWrapper.d.ts +35 -0
- package/dist/components/AnimatedWrapper.js +277 -0
- package/dist/components/CarouselComponent.d.ts +23 -0
- package/dist/components/CarouselComponent.js +484 -0
- package/dist/components/ChartCurveComponent.d.ts +13 -0
- package/dist/components/ChartCurveComponent.js +333 -0
- package/dist/components/CheckboxComponent.d.ts +9 -0
- package/dist/components/CheckboxComponent.js +172 -0
- package/dist/components/ConfettiComponent.d.ts +9 -0
- package/dist/components/ConfettiComponent.js +172 -0
- package/dist/components/CountdownComponent.d.ts +16 -0
- package/dist/components/CountdownComponent.js +414 -0
- package/dist/components/DelayedXComponent.d.ts +12 -0
- package/dist/components/DelayedXComponent.js +240 -0
- package/dist/components/DrawerModalComponent.d.ts +20 -0
- package/dist/components/DrawerModalComponent.js +286 -0
- package/dist/components/GradientView.d.ts +38 -0
- package/dist/components/GradientView.js +126 -0
- package/dist/components/HapticFeedbackComponent.d.ts +16 -0
- package/dist/components/HapticFeedbackComponent.js +64 -0
- package/dist/components/HorizontalProductsComponent.d.ts +17 -0
- package/dist/components/HorizontalProductsComponent.js +284 -0
- package/dist/components/MultiChoiceGridComponent.d.ts +13 -0
- package/dist/components/MultiChoiceGridComponent.js +234 -0
- package/dist/components/NPSScaleComponent.d.ts +16 -0
- package/dist/components/NPSScaleComponent.js +260 -0
- package/dist/components/NavigationComponent.d.ts +26 -0
- package/dist/components/NavigationComponent.js +302 -0
- package/dist/components/OAuthButtonComponent.d.ts +20 -0
- package/dist/components/OAuthButtonComponent.js +237 -0
- package/dist/components/ProgressLoaderComponent.d.ts +13 -0
- package/dist/components/ProgressLoaderComponent.js +308 -0
- package/dist/components/ProgressStepperComponent.d.ts +18 -0
- package/dist/components/ProgressStepperComponent.js +228 -0
- package/dist/components/SegmentedPickerComponent.d.ts +10 -0
- package/dist/components/SegmentedPickerComponent.js +221 -0
- package/dist/components/ShareButtonsComponent.d.ts +21 -0
- package/dist/components/ShareButtonsComponent.js +265 -0
- package/dist/components/ShareCodeComponent.d.ts +16 -0
- package/dist/components/ShareCodeComponent.js +274 -0
- package/dist/components/SingleChoiceGridComponent.d.ts +13 -0
- package/dist/components/SingleChoiceGridComponent.js +210 -0
- package/dist/components/SliderComponent.d.ts +9 -0
- package/dist/components/SliderComponent.js +263 -0
- package/dist/components/StarRatingInputComponent.d.ts +20 -0
- package/dist/components/StarRatingInputComponent.js +198 -0
- package/dist/components/StickerCompositeComponent.d.ts +13 -0
- package/dist/components/StickerCompositeComponent.js +136 -0
- package/dist/components/TabsComponent.d.ts +19 -0
- package/dist/components/TabsComponent.js +431 -0
- package/dist/components/TextInputComponent.d.ts +18 -0
- package/dist/components/TextInputComponent.js +227 -0
- package/dist/components/TimelineComponent.d.ts +19 -0
- package/dist/components/TimelineComponent.js +104 -0
- package/dist/components/ToggleComponent.d.ts +14 -0
- package/dist/components/ToggleComponent.js +132 -0
- package/dist/components/VerticalProductsComponent.d.ts +17 -0
- package/dist/components/VerticalProductsComponent.js +311 -0
- package/dist/dynamicValues.d.ts +36 -0
- package/dist/dynamicValues.js +142 -0
- package/dist/filters/dateFilters.d.ts +50 -0
- package/dist/filters/dateFilters.js +390 -0
- package/dist/filters/index.d.ts +18 -0
- package/dist/filters/index.js +253 -0
- package/dist/hooks/useOfferings.d.ts +76 -0
- package/dist/hooks/useOfferings.js +99 -0
- package/dist/hooks/usePaywall.d.ts +27 -0
- package/dist/hooks/usePaywall.js +114 -0
- package/dist/hooks/usePlacement.d.ts +34 -0
- package/dist/hooks/usePlacement.js +89 -0
- package/dist/hooks/useSubscription.d.ts +40 -0
- package/dist/hooks/useSubscription.js +97 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.js +198 -0
- package/dist/models/BillDogError.d.ts +40 -0
- package/dist/models/BillDogError.js +11 -0
- package/dist/models/CacheFetchPolicy.d.ts +8 -0
- package/dist/models/CacheFetchPolicy.js +4 -0
- package/dist/models/CustomProduct.d.ts +32 -0
- package/dist/models/CustomProduct.js +15 -0
- package/dist/models/CustomerInfo.d.ts +17 -0
- package/dist/models/CustomerInfo.js +11 -0
- package/dist/models/Delegate.d.ts +20 -0
- package/dist/models/Delegate.js +11 -0
- package/dist/models/EntitlementInfo.d.ts +19 -0
- package/dist/models/EntitlementInfo.js +2 -0
- package/dist/models/Placement.d.ts +54 -0
- package/dist/models/Placement.js +15 -0
- package/dist/models/PurchaseParams.d.ts +39 -0
- package/dist/models/PurchaseParams.js +60 -0
- package/dist/models/PurchaseResult.d.ts +30 -0
- package/dist/models/PurchaseResult.js +15 -0
- package/dist/models/RestoreResult.d.ts +30 -0
- package/dist/models/RestoreResult.js +22 -0
- package/dist/models/RestoredItem.d.ts +26 -0
- package/dist/models/RestoredItem.js +13 -0
- package/dist/modules/ABTest.d.ts +65 -0
- package/dist/modules/ABTest.js +113 -0
- package/dist/modules/Analytics.d.ts +91 -0
- package/dist/modules/Analytics.js +182 -0
- package/dist/modules/Survey.d.ts +65 -0
- package/dist/modules/Survey.js +82 -0
- package/dist/modules/VirtualCurrency.d.ts +63 -0
- package/dist/modules/VirtualCurrency.js +147 -0
- package/dist/murmur.d.ts +23 -0
- package/dist/murmur.js +104 -0
- package/dist/notifications/LiveActivitiesManager.d.ts +47 -0
- package/dist/notifications/LiveActivitiesManager.js +106 -0
- package/dist/notifications/NotificationScheduler.d.ts +55 -0
- package/dist/notifications/NotificationScheduler.js +199 -0
- package/dist/notifications/PurchaseNotificationHandler.d.ts +24 -0
- package/dist/notifications/PurchaseNotificationHandler.js +55 -0
- package/dist/notifications/useDeviceToken.d.ts +36 -0
- package/dist/notifications/useDeviceToken.js +97 -0
- package/dist/notifications/useLiveActivity.d.ts +39 -0
- package/dist/notifications/useLiveActivity.js +104 -0
- package/dist/review/ReviewAnalytics.d.ts +34 -0
- package/dist/review/ReviewAnalytics.js +73 -0
- package/dist/review/ReviewManager.d.ts +83 -0
- package/dist/review/ReviewManager.js +339 -0
- package/dist/review/ReviewTimingManager.d.ts +82 -0
- package/dist/review/ReviewTimingManager.js +224 -0
- package/dist/survey-core/types.d.ts +215 -0
- package/dist/survey-core/types.js +8 -0
- package/dist/types.d.ts +438 -0
- package/dist/types.js +158 -0
- package/dist/utils/ApiClient.d.ts +65 -0
- package/dist/utils/ApiClient.js +132 -0
- package/dist/utils/CSSConverter.d.ts +49 -0
- package/dist/utils/CSSConverter.js +470 -0
- package/dist/utils/animations.d.ts +41 -0
- package/dist/utils/animations.js +194 -0
- package/dist/utils/calendarIntegration.d.ts +36 -0
- package/dist/utils/calendarIntegration.js +89 -0
- package/dist/utils/configurationResolver.d.ts +23 -0
- package/dist/utils/configurationResolver.js +78 -0
- package/dist/utils/deviceDetection.d.ts +38 -0
- package/dist/utils/deviceDetection.js +59 -0
- package/dist/utils/hapticFeedback.d.ts +17 -0
- package/dist/utils/hapticFeedback.js +53 -0
- package/dist/utils/iconMapper.d.ts +26 -0
- package/dist/utils/iconMapper.js +113 -0
- package/dist/utils/notificationPermissions.d.ts +13 -0
- package/dist/utils/notificationPermissions.js +51 -0
- package/dist/utils/priceFormatting.d.ts +19 -0
- package/dist/utils/priceFormatting.js +99 -0
- package/dist/utils/shareSheet.d.ts +17 -0
- package/dist/utils/shareSheet.js +42 -0
- package/dist/utils/subscriptionUpgrade.d.ts +84 -0
- package/dist/utils/subscriptionUpgrade.js +100 -0
- package/dist/valueUtils.d.ts +48 -0
- package/dist/valueUtils.js +129 -0
- package/dist/xFlowTags.d.ts +18 -0
- package/dist/xFlowTags.js +385 -0
- package/ios/BillDogABTest.m +50 -0
- package/ios/BillDogABTest.swift +188 -0
- package/ios/BillDogAnalytics.m +105 -0
- package/ios/BillDogAnalytics.swift +324 -0
- package/ios/BillDogBridge.m +222 -0
- package/ios/BillDogBridge.swift +715 -0
- package/ios/BillDogLiveActivities.m +41 -0
- package/ios/BillDogLiveActivities.swift +104 -0
- package/ios/BillDogPaywallViewManager.m +39 -0
- package/ios/BillDogPaywallViewManager.swift +361 -0
- package/ios/BillDogSurvey.m +34 -0
- package/ios/BillDogSurvey.swift +257 -0
- package/ios/BillDogVirtualCurrencyBridge.m +63 -0
- package/ios/BillDogVirtualCurrencyBridge.swift +511 -0
- package/junit.xml +25 -0
- package/package.json +61 -0
- package/react-native.config.js +13 -0
- package/src/AdvancedPaywallCache.ts +433 -0
- package/src/BillDog.ts +983 -0
- package/src/BillDogConfiguration.ts +318 -0
- package/src/ComponentRenderer.tsx +1325 -0
- package/src/LayoutEngine.ts +459 -0
- package/src/LocalizationResolver.ts +311 -0
- package/src/NativePaywallView.tsx +132 -0
- package/src/PaywallCache.ts +358 -0
- package/src/PaywallStateManager.ts +154 -0
- package/src/PaywallView.tsx +328 -0
- package/src/ProductVariableProvider.ts +282 -0
- package/src/VariableResolver.ts +516 -0
- package/src/WebViewPaywall.tsx +454 -0
- package/src/animations/presets.ts +421 -0
- package/src/components/AccoladeCpsComponent.tsx +259 -0
- package/src/components/AccordionComponent.tsx +213 -0
- package/src/components/AnimatedWrapper.tsx +316 -0
- package/src/components/CarouselComponent.tsx +615 -0
- package/src/components/ChartCurveComponent.tsx +452 -0
- package/src/components/CheckboxComponent.tsx +185 -0
- package/src/components/ConfettiComponent.tsx +178 -0
- package/src/components/CountdownComponent.tsx +454 -0
- package/src/components/DelayedXComponent.tsx +266 -0
- package/src/components/DrawerModalComponent.tsx +324 -0
- package/src/components/GradientView.tsx +129 -0
- package/src/components/HapticFeedbackComponent.tsx +39 -0
- package/src/components/HorizontalProductsComponent.tsx +329 -0
- package/src/components/MultiChoiceGridComponent.tsx +265 -0
- package/src/components/NPSScaleComponent.tsx +294 -0
- package/src/components/NavigationComponent.tsx +329 -0
- package/src/components/OAuthButtonComponent.tsx +266 -0
- package/src/components/ProgressLoaderComponent.tsx +366 -0
- package/src/components/ProgressStepperComponent.tsx +250 -0
- package/src/components/SegmentedPickerComponent.tsx +245 -0
- package/src/components/ShareButtonsComponent.tsx +299 -0
- package/src/components/ShareCodeComponent.tsx +303 -0
- package/src/components/SingleChoiceGridComponent.tsx +229 -0
- package/src/components/SliderComponent.tsx +280 -0
- package/src/components/StarRatingInputComponent.tsx +223 -0
- package/src/components/StickerCompositeComponent.tsx +168 -0
- package/src/components/TabsComponent.tsx +496 -0
- package/src/components/TextInputComponent.tsx +258 -0
- package/src/components/TimelineComponent.tsx +129 -0
- package/src/components/ToggleComponent.tsx +142 -0
- package/src/components/VerticalProductsComponent.tsx +357 -0
- package/src/dynamicValues.ts +180 -0
- package/src/filters/dateFilters.ts +411 -0
- package/src/filters/index.ts +281 -0
- package/src/hooks/useOfferings.ts +192 -0
- package/src/hooks/usePaywall.ts +154 -0
- package/src/hooks/usePlacement.ts +143 -0
- package/src/hooks/useSubscription.ts +154 -0
- package/src/index.ts +245 -0
- package/src/models/BillDogError.ts +24 -0
- package/src/models/CacheFetchPolicy.ts +13 -0
- package/src/models/CustomProduct.ts +33 -0
- package/src/models/CustomerInfo.ts +26 -0
- package/src/models/Delegate.ts +22 -0
- package/src/models/EntitlementInfo.ts +27 -0
- package/src/models/Placement.ts +50 -0
- package/src/models/PurchaseParams.ts +81 -0
- package/src/models/PurchaseResult.ts +32 -0
- package/src/models/RestoreResult.ts +27 -0
- package/src/models/RestoredItem.ts +25 -0
- package/src/modules/ABTest.ts +131 -0
- package/src/modules/Analytics.ts +227 -0
- package/src/modules/Survey.ts +126 -0
- package/src/modules/VirtualCurrency.ts +223 -0
- package/src/murmur.ts +102 -0
- package/src/notifications/LiveActivitiesManager.ts +140 -0
- package/src/notifications/NotificationScheduler.ts +292 -0
- package/src/notifications/PurchaseNotificationHandler.ts +67 -0
- package/src/notifications/useDeviceToken.ts +116 -0
- package/src/notifications/useLiveActivity.ts +125 -0
- package/src/review/ReviewAnalytics.ts +89 -0
- package/src/review/ReviewManager.ts +355 -0
- package/src/review/ReviewTimingManager.ts +265 -0
- package/src/survey-core/types.ts +244 -0
- package/src/types/ambient.d.ts +9 -0
- package/src/types.ts +680 -0
- package/src/utils/ApiClient.ts +163 -0
- package/src/utils/CSSConverter.ts +552 -0
- package/src/utils/animations.ts +232 -0
- package/src/utils/calendarIntegration.ts +113 -0
- package/src/utils/configurationResolver.ts +106 -0
- package/src/utils/deviceDetection.ts +83 -0
- package/src/utils/hapticFeedback.ts +55 -0
- package/src/utils/iconMapper.ts +102 -0
- package/src/utils/notificationPermissions.ts +48 -0
- package/src/utils/priceFormatting.ts +119 -0
- package/src/utils/shareSheet.ts +55 -0
- package/src/utils/subscriptionUpgrade.ts +183 -0
- package/src/valueUtils.ts +108 -0
- package/src/xFlowTags.ts +463 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default API base URL — routes through BillDog's Cloudflare proxy.
|
|
3
|
+
* Matches Android's `BillDogConfig.apiBaseUrl` and iOS's `BillDogConfig.API_BASE_URL`.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_API_BASE_URL = 'https://api.billdog.io/v1';
|
|
6
|
+
|
|
7
|
+
// Optional native module — present in a native build (Android/iOS), null in a
|
|
8
|
+
// JS-only Metro run / Expo Go. `configure()` propagates the apiKey to the native
|
|
9
|
+
// BillDog singleton so delegating calls (getCustomerInfo/register/purchase/…)
|
|
10
|
+
// actually reach the configured native SDK.
|
|
11
|
+
const _nativeBillDog: any = (() => {
|
|
12
|
+
try {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
|
+
return require('react-native')?.NativeModules?.BillDog ?? null;
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
})();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* BillDog Paywalls SDK configuration
|
|
22
|
+
*/
|
|
23
|
+
export interface BillDogConfig {
|
|
24
|
+
/** API key for authentication (must start with "bd_") */
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Base URL for all API calls.
|
|
29
|
+
* Defaults to `https://api.billdog.io/v1` (the branded API host).
|
|
30
|
+
* Override only for testing or self-hosted deployments — the override must
|
|
31
|
+
* point at a host that behaves like the BillDog edge Worker.
|
|
32
|
+
*/
|
|
33
|
+
apiBaseUrl: string;
|
|
34
|
+
|
|
35
|
+
/** Enable advanced caching features (compression, multi-level cache) */
|
|
36
|
+
enableAdvancedCaching: boolean;
|
|
37
|
+
|
|
38
|
+
/** Maximum cache size in bytes (default: 50MB) */
|
|
39
|
+
maxCacheSize?: number;
|
|
40
|
+
|
|
41
|
+
/** Cache TTL in milliseconds (default: 7 days) */
|
|
42
|
+
cacheTTL?: number;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Override device locale for all paywalls.
|
|
47
|
+
* Use ISO 639-1 language codes (e.g., "es", "fr", "de", "ja").
|
|
48
|
+
* Set to undefined to use device locale (default).
|
|
49
|
+
*/
|
|
50
|
+
localeOverride?: string;
|
|
51
|
+
|
|
52
|
+
/** SDK environment */
|
|
53
|
+
environment?: 'sandbox' | 'production';
|
|
54
|
+
|
|
55
|
+
/** Enable debug logging */
|
|
56
|
+
enableLogging?: boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* PUR-262: granular log level. When set, overrides `enableLogging`.
|
|
60
|
+
* Canonical 5-level set: `verbose, debug, info, warn, error`.
|
|
61
|
+
*/
|
|
62
|
+
logLevel?: import('./models/BillDogError').BillDogLogLevel;
|
|
63
|
+
|
|
64
|
+
// Analytics configuration overrides (client override > server config > SDK defaults)
|
|
65
|
+
|
|
66
|
+
/** Override analytics enabled state (master kill switch). undefined = use server config. */
|
|
67
|
+
analyticsEnabled?: boolean;
|
|
68
|
+
|
|
69
|
+
/** Override flush interval in seconds. Minimum: 10s. undefined = use server config. */
|
|
70
|
+
analyticsFlushInterval?: number;
|
|
71
|
+
|
|
72
|
+
/** Override batch size (events before auto-flush). Minimum: 5. undefined = use server config. */
|
|
73
|
+
analyticsBatchSize?: number;
|
|
74
|
+
|
|
75
|
+
/** Override max queue size. undefined = use server config. */
|
|
76
|
+
analyticsMaxQueueSize?: number;
|
|
77
|
+
|
|
78
|
+
/** Override session timeout in seconds. undefined = use server config. */
|
|
79
|
+
analyticsSessionTimeout?: number;
|
|
80
|
+
|
|
81
|
+
/** Override sampling rate (0.0–1.0). undefined = use server config. */
|
|
82
|
+
analyticsSamplingRate?: number;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* App Store numeric ID (iOS) — used only for the Smart Review store-page
|
|
86
|
+
* fallback when the native `react-native-in-app-review` module isn't installed.
|
|
87
|
+
* e.g. '1234567890'. Without it (and without the native module) iOS review
|
|
88
|
+
* requests report unavailable instead of opening a broken URL.
|
|
89
|
+
*/
|
|
90
|
+
appStoreId?: string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Google Play package name (Android) — used only for the Smart Review
|
|
94
|
+
* store-page fallback when `react-native-in-app-review` isn't installed.
|
|
95
|
+
* e.g. 'com.acme.app'.
|
|
96
|
+
*/
|
|
97
|
+
androidPackageName?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Global configuration singleton
|
|
102
|
+
*/
|
|
103
|
+
export const BillDogConfiguration = {
|
|
104
|
+
config: {
|
|
105
|
+
apiKey: undefined,
|
|
106
|
+
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
107
|
+
enableAdvancedCaching: true,
|
|
108
|
+
maxCacheSize: 50 * 1024 * 1024, // 50MB
|
|
109
|
+
cacheTTL: 7 * 24 * 60 * 60 * 1000, // 7 days
|
|
110
|
+
localeOverride: undefined,
|
|
111
|
+
environment: 'production' as const,
|
|
112
|
+
enableLogging: false,
|
|
113
|
+
} as BillDogConfig,
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Configure the SDK with custom settings.
|
|
117
|
+
* Should be called early in app initialization (e.g., App.tsx or index.js).
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Minimal configuration
|
|
122
|
+
* BillDogConfiguration.configure({
|
|
123
|
+
* apiKey: 'bd_live_abc123',
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* // Full configuration
|
|
127
|
+
* BillDogConfiguration.configure({
|
|
128
|
+
* apiKey: 'bd_live_abc123',
|
|
129
|
+
* environment: 'production',
|
|
130
|
+
* localeOverride: 'es',
|
|
131
|
+
* });
|
|
132
|
+
*
|
|
133
|
+
* // Self-hosted / testing
|
|
134
|
+
* BillDogConfiguration.configure({
|
|
135
|
+
* apiKey: 'bd_test_abc123',
|
|
136
|
+
* apiBaseUrl: 'https://my-proxy.example.com',
|
|
137
|
+
* environment: 'sandbox',
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
configure(newConfig: Partial<BillDogConfig>) {
|
|
142
|
+
this.config = { ...this.config, ...newConfig };
|
|
143
|
+
if (this.config.enableLogging) {
|
|
144
|
+
console.log('[BillDogConfiguration] Updated:', {
|
|
145
|
+
apiBaseUrl: this.config.apiBaseUrl,
|
|
146
|
+
hasApiKey: !!this.config.apiKey,
|
|
147
|
+
environment: this.config.environment,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
// Propagate to the native SDK so its singleton is configured (thin-bridge
|
|
151
|
+
// calls delegate to it). Fire-and-forget — best-effort, never blocks JS.
|
|
152
|
+
if (this.config.apiKey && _nativeBillDog?.configure) {
|
|
153
|
+
try {
|
|
154
|
+
const result = _nativeBillDog.configure(this.config.apiKey, {
|
|
155
|
+
enableLogging: !!this.config.enableLogging,
|
|
156
|
+
environment: this.config.environment,
|
|
157
|
+
localeOverride: this.config.localeOverride,
|
|
158
|
+
});
|
|
159
|
+
if (result && typeof result.catch === 'function') result.catch(() => {});
|
|
160
|
+
} catch {
|
|
161
|
+
/* native configure is best-effort */
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Fetch remote SDK config in background (non-blocking)
|
|
165
|
+
if (this.config.apiKey) {
|
|
166
|
+
this.fetchSdkConfig().catch(() => {});
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
/** Cached server-driven SDK config */
|
|
171
|
+
_serverConfig: null as Record<string, any> | null,
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Fetch server-driven SDK configuration.
|
|
175
|
+
* Applies server config under client overrides (client > server > defaults).
|
|
176
|
+
* Called automatically during `configure()` — can also be called manually to refresh.
|
|
177
|
+
*/
|
|
178
|
+
async fetchSdkConfig(): Promise<Record<string, any> | null> {
|
|
179
|
+
try {
|
|
180
|
+
const endpoint = this.resolveEndpoint('sdk-config');
|
|
181
|
+
const response = await fetch(endpoint, {
|
|
182
|
+
method: 'GET',
|
|
183
|
+
headers: {
|
|
184
|
+
'Content-Type': 'application/json',
|
|
185
|
+
'X-BillDog-API-Key': this.config.apiKey!,
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
if (!response.ok) return null;
|
|
189
|
+
const json = await response.json();
|
|
190
|
+
const data = json?.data;
|
|
191
|
+
if (!data) return null;
|
|
192
|
+
|
|
193
|
+
this._serverConfig = data;
|
|
194
|
+
|
|
195
|
+
// Apply server analytics config where client hasn't overridden
|
|
196
|
+
const analytics = data.analytics;
|
|
197
|
+
if (analytics) {
|
|
198
|
+
if (this.config.analyticsEnabled === undefined) {
|
|
199
|
+
this.config.analyticsEnabled = analytics.enabled ?? true;
|
|
200
|
+
}
|
|
201
|
+
if (this.config.analyticsFlushInterval === undefined) {
|
|
202
|
+
const serverInterval = (analytics.flush_interval_seconds ?? 30);
|
|
203
|
+
this.config.analyticsFlushInterval = Math.max(serverInterval, 10);
|
|
204
|
+
}
|
|
205
|
+
if (this.config.analyticsBatchSize === undefined) {
|
|
206
|
+
this.config.analyticsBatchSize = Math.max(analytics.batch_size ?? 20, 5);
|
|
207
|
+
}
|
|
208
|
+
if (this.config.analyticsMaxQueueSize === undefined) {
|
|
209
|
+
this.config.analyticsMaxQueueSize = Math.max(analytics.max_queue_size ?? 1000, 100);
|
|
210
|
+
}
|
|
211
|
+
if (this.config.analyticsSamplingRate === undefined) {
|
|
212
|
+
this.config.analyticsSamplingRate = Math.min(Math.max(analytics.sampling_rate ?? 1.0, 0), 1);
|
|
213
|
+
}
|
|
214
|
+
if (this.config.analyticsSessionTimeout === undefined) {
|
|
215
|
+
this.config.analyticsSessionTimeout = analytics.session_timeout_seconds ?? 300;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (this.config.enableLogging) {
|
|
220
|
+
console.log('[BillDogConfiguration] Server SDK config applied:', {
|
|
221
|
+
analyticsEnabled: this.config.analyticsEnabled,
|
|
222
|
+
flushInterval: this.config.analyticsFlushInterval,
|
|
223
|
+
batchSize: this.config.analyticsBatchSize,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return data;
|
|
228
|
+
} catch (e) {
|
|
229
|
+
if (this.config.enableLogging) {
|
|
230
|
+
console.warn('[BillDogConfiguration] Failed to fetch SDK config:', e);
|
|
231
|
+
}
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Get the resolved server SDK config (null if not yet fetched).
|
|
238
|
+
*/
|
|
239
|
+
getServerConfig(): Record<string, any> | null {
|
|
240
|
+
return this._serverConfig;
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Get the resolved API base URL.
|
|
245
|
+
* Returns the configured `apiBaseUrl` (defaults to `https://api.billdog.io/v1`).
|
|
246
|
+
*/
|
|
247
|
+
getApiBaseUrl(): string {
|
|
248
|
+
return this.config.apiBaseUrl || DEFAULT_API_BASE_URL;
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Get the configured API key.
|
|
253
|
+
* @throws if API key has not been configured.
|
|
254
|
+
*/
|
|
255
|
+
getApiKey(): string {
|
|
256
|
+
if (!this.config.apiKey) {
|
|
257
|
+
throw new Error(
|
|
258
|
+
'[BillDogConfiguration] API key not configured. Call BillDogConfiguration.configure({ apiKey: "bd_..." }) first.'
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
return this.config.apiKey;
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Check if the SDK has been configured with an API key.
|
|
266
|
+
*/
|
|
267
|
+
isConfigured(): boolean {
|
|
268
|
+
return !!this.config.apiKey;
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Build a full endpoint URL from a function name.
|
|
273
|
+
* e.g., `resolveEndpoint('fetch-paywall')` → `https://api.billdog.io/v1/fetch-paywall`
|
|
274
|
+
*/
|
|
275
|
+
resolveEndpoint(functionName: string): string {
|
|
276
|
+
const base = this.getApiBaseUrl().replace(/\/$/, '');
|
|
277
|
+
return `${base}/${functionName}`;
|
|
278
|
+
},
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Set the locale override at runtime.
|
|
282
|
+
* This will affect all future paywall displays.
|
|
283
|
+
*
|
|
284
|
+
* @param locale - ISO 639-1 language code (e.g., "es", "fr", "de") or undefined to use device locale
|
|
285
|
+
*/
|
|
286
|
+
setLocaleOverride(locale: string | undefined) {
|
|
287
|
+
this.config.localeOverride = locale;
|
|
288
|
+
if (this.config.enableLogging) {
|
|
289
|
+
console.log(`[BillDogConfiguration] Locale override set to: ${locale ?? 'device default'}`);
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Get the current locale override.
|
|
295
|
+
* @returns The current locale override, or undefined if using device locale
|
|
296
|
+
*/
|
|
297
|
+
getLocaleOverride(): string | undefined {
|
|
298
|
+
return this.config.localeOverride;
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Reset to default configuration
|
|
303
|
+
*/
|
|
304
|
+
reset() {
|
|
305
|
+
this.config = {
|
|
306
|
+
apiKey: undefined,
|
|
307
|
+
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
308
|
+
enableAdvancedCaching: true,
|
|
309
|
+
maxCacheSize: 50 * 1024 * 1024,
|
|
310
|
+
cacheTTL: 7 * 24 * 60 * 60 * 1000,
|
|
311
|
+
|
|
312
|
+
localeOverride: undefined,
|
|
313
|
+
environment: 'production',
|
|
314
|
+
enableLogging: false,
|
|
315
|
+
};
|
|
316
|
+
console.log('[BillDogConfiguration] Reset to defaults');
|
|
317
|
+
}
|
|
318
|
+
};
|