@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,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @billdog.io/react-native — Analytics Module
|
|
3
|
+
*
|
|
4
|
+
* Native bridge to BillDogAnalytics (iOS) / billdog-analytics (Android).
|
|
5
|
+
* The native SDKs handle server-driven config (batch size, flush interval, sampling, etc.)
|
|
6
|
+
* fetched from the `sdk-config` edge function at init time.
|
|
7
|
+
* Config priority: client override > server config > SDK defaults (20 batch, 30s flush).
|
|
8
|
+
*/
|
|
9
|
+
export interface AnalyticsEvent {
|
|
10
|
+
name: string;
|
|
11
|
+
properties?: Record<string, any>;
|
|
12
|
+
timestamp?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface RevenueEvent {
|
|
15
|
+
/** Revenue amount (in the currency's base unit, e.g., dollars not cents) */
|
|
16
|
+
amount: number;
|
|
17
|
+
/** ISO 4217 currency code */
|
|
18
|
+
currency?: string;
|
|
19
|
+
/** Product identifier */
|
|
20
|
+
productId?: string;
|
|
21
|
+
/** Additional properties */
|
|
22
|
+
properties?: Record<string, any>;
|
|
23
|
+
}
|
|
24
|
+
export interface UserProperties {
|
|
25
|
+
[key: string]: string | number | boolean | null;
|
|
26
|
+
}
|
|
27
|
+
export type UserPropertyOperation = '$set' | '$set_once' | '$add' | '$append' | '$remove' | '$unset';
|
|
28
|
+
export declare class AnalyticsManager {
|
|
29
|
+
private static instance;
|
|
30
|
+
private initialized;
|
|
31
|
+
private constructor();
|
|
32
|
+
static getInstance(): AnalyticsManager;
|
|
33
|
+
/**
|
|
34
|
+
* Initialize the Analytics module.
|
|
35
|
+
* Called automatically when `BillDogConfiguration.configure()` includes `apiKey`.
|
|
36
|
+
*/
|
|
37
|
+
initialize(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Track a custom event.
|
|
40
|
+
*/
|
|
41
|
+
track(event: string | AnalyticsEvent, properties?: Record<string, any>): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Track a revenue event (standardized `$revenue` event).
|
|
44
|
+
*/
|
|
45
|
+
trackRevenue(revenue: RevenueEvent): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Identify a user.
|
|
48
|
+
*/
|
|
49
|
+
identify(userId: string, properties?: UserProperties): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Set super properties (persisted, merged into every event).
|
|
52
|
+
*/
|
|
53
|
+
setSuperProperties(properties: Record<string, any>): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Update user properties with a specific operation.
|
|
56
|
+
*/
|
|
57
|
+
updateUserProperties(operation: UserPropertyOperation, properties: Record<string, any>): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Flush pending events immediately.
|
|
60
|
+
*/
|
|
61
|
+
flush(): Promise<void>;
|
|
62
|
+
/** Opt out of analytics tracking (GDPR). */
|
|
63
|
+
optOut(): Promise<void>;
|
|
64
|
+
/** Opt back in to analytics tracking. */
|
|
65
|
+
optIn(): Promise<void>;
|
|
66
|
+
/** Reset analytics state (clears identity + super properties). */
|
|
67
|
+
reset(): Promise<void>;
|
|
68
|
+
/** Alias an anonymous user to a known identity. */
|
|
69
|
+
alias(newId: string, originalId?: string): Promise<void>;
|
|
70
|
+
/** Start timing an event — duration emitted on next track() of same name. */
|
|
71
|
+
timeEvent(eventName: string): Promise<void>;
|
|
72
|
+
/** Associate this user with a group (B2B analytics). */
|
|
73
|
+
setGroup(groupType: string, groupId: string): Promise<void>;
|
|
74
|
+
setGroupProperties(groupType: string, groupId: string, properties: Record<string, any>): Promise<void>;
|
|
75
|
+
/** Track a screen view manually. */
|
|
76
|
+
trackScreen(screenName: string, properties?: Record<string, any>): Promise<void>;
|
|
77
|
+
/** Track a deep-link URL. */
|
|
78
|
+
trackDeepLink(url: string): Promise<void>;
|
|
79
|
+
getDeviceId(): Promise<string | null>;
|
|
80
|
+
getDistinctId(): Promise<string | null>;
|
|
81
|
+
getSessionId(): Promise<string | null>;
|
|
82
|
+
registerSuperPropertiesOnce(properties: Record<string, any>): Promise<void>;
|
|
83
|
+
unregisterSuperProperty(key: string): Promise<void>;
|
|
84
|
+
clearSuperProperties(): Promise<void>;
|
|
85
|
+
/** Listen to flush events (debugging). */
|
|
86
|
+
onFlush(callback: (data: {
|
|
87
|
+
eventCount: number;
|
|
88
|
+
}) => void): import("react-native").EmitterSubscription | undefined;
|
|
89
|
+
}
|
|
90
|
+
declare const _default: AnalyticsManager;
|
|
91
|
+
export default _default;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @billdog.io/react-native — Analytics Module
|
|
4
|
+
*
|
|
5
|
+
* Native bridge to BillDogAnalytics (iOS) / billdog-analytics (Android).
|
|
6
|
+
* The native SDKs handle server-driven config (batch size, flush interval, sampling, etc.)
|
|
7
|
+
* fetched from the `sdk-config` edge function at init time.
|
|
8
|
+
* Config priority: client override > server config > SDK defaults (20 batch, 30s flush).
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.AnalyticsManager = void 0;
|
|
12
|
+
const react_native_1 = require("react-native");
|
|
13
|
+
const { BillDogAnalytics } = react_native_1.NativeModules;
|
|
14
|
+
const eventEmitter = BillDogAnalytics ? new react_native_1.NativeEventEmitter(BillDogAnalytics) : null;
|
|
15
|
+
// MARK: - Analytics Manager
|
|
16
|
+
class AnalyticsManager {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.initialized = false;
|
|
19
|
+
}
|
|
20
|
+
static getInstance() {
|
|
21
|
+
if (!AnalyticsManager.instance) {
|
|
22
|
+
AnalyticsManager.instance = new AnalyticsManager();
|
|
23
|
+
}
|
|
24
|
+
return AnalyticsManager.instance;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Initialize the Analytics module.
|
|
28
|
+
* Called automatically when `BillDogConfiguration.configure()` includes `apiKey`.
|
|
29
|
+
*/
|
|
30
|
+
async initialize() {
|
|
31
|
+
if (!BillDogAnalytics) {
|
|
32
|
+
console.warn('[BillDogAnalytics] Native module not linked. Analytics will be no-op.');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await BillDogAnalytics.initialize();
|
|
36
|
+
this.initialized = true;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Track a custom event.
|
|
40
|
+
*/
|
|
41
|
+
async track(event, properties) {
|
|
42
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
43
|
+
return;
|
|
44
|
+
const name = typeof event === 'string' ? event : event.name;
|
|
45
|
+
const props = typeof event === 'string' ? properties : event.properties;
|
|
46
|
+
await BillDogAnalytics.track(name, props || {});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Track a revenue event (standardized `$revenue` event).
|
|
50
|
+
*/
|
|
51
|
+
async trackRevenue(revenue) {
|
|
52
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
53
|
+
return;
|
|
54
|
+
await BillDogAnalytics.trackRevenue(revenue.amount, revenue.currency || 'USD', revenue.productId || null, revenue.properties || {});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Identify a user.
|
|
58
|
+
*/
|
|
59
|
+
async identify(userId, properties) {
|
|
60
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
61
|
+
return;
|
|
62
|
+
await BillDogAnalytics.identify(userId, properties || {});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Set super properties (persisted, merged into every event).
|
|
66
|
+
*/
|
|
67
|
+
async setSuperProperties(properties) {
|
|
68
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
69
|
+
return;
|
|
70
|
+
await BillDogAnalytics.setSuperProperties(properties);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Update user properties with a specific operation.
|
|
74
|
+
*/
|
|
75
|
+
async updateUserProperties(operation, properties) {
|
|
76
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
77
|
+
return;
|
|
78
|
+
await BillDogAnalytics.updateUserProperties(operation, properties);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Flush pending events immediately.
|
|
82
|
+
*/
|
|
83
|
+
async flush() {
|
|
84
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
85
|
+
return;
|
|
86
|
+
await BillDogAnalytics.flush();
|
|
87
|
+
}
|
|
88
|
+
/** Opt out of analytics tracking (GDPR). */
|
|
89
|
+
async optOut() {
|
|
90
|
+
if (!BillDogAnalytics)
|
|
91
|
+
return;
|
|
92
|
+
await BillDogAnalytics.optOut();
|
|
93
|
+
}
|
|
94
|
+
/** Opt back in to analytics tracking. */
|
|
95
|
+
async optIn() {
|
|
96
|
+
if (!BillDogAnalytics)
|
|
97
|
+
return;
|
|
98
|
+
await BillDogAnalytics.optIn();
|
|
99
|
+
}
|
|
100
|
+
/** Reset analytics state (clears identity + super properties). */
|
|
101
|
+
async reset() {
|
|
102
|
+
if (!BillDogAnalytics)
|
|
103
|
+
return;
|
|
104
|
+
await BillDogAnalytics.reset();
|
|
105
|
+
this.initialized = false;
|
|
106
|
+
}
|
|
107
|
+
// ── Parity surface (Sev 2.3 fix) ─────────────────────────────────────
|
|
108
|
+
// Native (iOS/Android) BillDogAnalytics already implements all of these;
|
|
109
|
+
// the RN bridge simply needs to expose them.
|
|
110
|
+
/** Alias an anonymous user to a known identity. */
|
|
111
|
+
async alias(newId, originalId) {
|
|
112
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
113
|
+
return;
|
|
114
|
+
await BillDogAnalytics.alias(newId, originalId !== null && originalId !== void 0 ? originalId : null);
|
|
115
|
+
}
|
|
116
|
+
/** Start timing an event — duration emitted on next track() of same name. */
|
|
117
|
+
async timeEvent(eventName) {
|
|
118
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
119
|
+
return;
|
|
120
|
+
await BillDogAnalytics.timeEvent(eventName);
|
|
121
|
+
}
|
|
122
|
+
/** Associate this user with a group (B2B analytics). */
|
|
123
|
+
async setGroup(groupType, groupId) {
|
|
124
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
125
|
+
return;
|
|
126
|
+
await BillDogAnalytics.setGroup(groupType, groupId);
|
|
127
|
+
}
|
|
128
|
+
async setGroupProperties(groupType, groupId, properties) {
|
|
129
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
130
|
+
return;
|
|
131
|
+
await BillDogAnalytics.setGroupProperties(groupType, groupId, properties);
|
|
132
|
+
}
|
|
133
|
+
/** Track a screen view manually. */
|
|
134
|
+
async trackScreen(screenName, properties) {
|
|
135
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
136
|
+
return;
|
|
137
|
+
await BillDogAnalytics.trackScreen(screenName, properties !== null && properties !== void 0 ? properties : {});
|
|
138
|
+
}
|
|
139
|
+
/** Track a deep-link URL. */
|
|
140
|
+
async trackDeepLink(url) {
|
|
141
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
142
|
+
return;
|
|
143
|
+
await BillDogAnalytics.trackDeepLink(url);
|
|
144
|
+
}
|
|
145
|
+
async getDeviceId() {
|
|
146
|
+
if (!BillDogAnalytics)
|
|
147
|
+
return null;
|
|
148
|
+
return BillDogAnalytics.getDeviceId();
|
|
149
|
+
}
|
|
150
|
+
async getDistinctId() {
|
|
151
|
+
if (!BillDogAnalytics)
|
|
152
|
+
return null;
|
|
153
|
+
return BillDogAnalytics.getDistinctId();
|
|
154
|
+
}
|
|
155
|
+
async getSessionId() {
|
|
156
|
+
if (!BillDogAnalytics)
|
|
157
|
+
return null;
|
|
158
|
+
return BillDogAnalytics.getSessionId();
|
|
159
|
+
}
|
|
160
|
+
async registerSuperPropertiesOnce(properties) {
|
|
161
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
162
|
+
return;
|
|
163
|
+
await BillDogAnalytics.registerSuperPropertiesOnce(properties);
|
|
164
|
+
}
|
|
165
|
+
async unregisterSuperProperty(key) {
|
|
166
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
167
|
+
return;
|
|
168
|
+
await BillDogAnalytics.unregisterSuperProperty(key);
|
|
169
|
+
}
|
|
170
|
+
async clearSuperProperties() {
|
|
171
|
+
if (!this.initialized || !BillDogAnalytics)
|
|
172
|
+
return;
|
|
173
|
+
await BillDogAnalytics.clearSuperProperties();
|
|
174
|
+
}
|
|
175
|
+
/** Listen to flush events (debugging). */
|
|
176
|
+
onFlush(callback) {
|
|
177
|
+
return eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.addListener('onAnalyticsFlush', callback);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.AnalyticsManager = AnalyticsManager;
|
|
181
|
+
AnalyticsManager.instance = null;
|
|
182
|
+
exports.default = AnalyticsManager.getInstance();
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @billdog.io/react-native — Survey Module
|
|
3
|
+
*
|
|
4
|
+
* Native bridge to BDSurvey (iOS) / billdog-survey (Android).
|
|
5
|
+
* Provides survey presentation, response collection, and template loading.
|
|
6
|
+
*/
|
|
7
|
+
import type { SurveyConfiguration, SurveyPage, SurveyQuestion, SurveyChoice, SurveyAnswer, SurveyMobileDisplayConfig } from '../survey-core/types';
|
|
8
|
+
export type { SurveyConfiguration, SurveyPage, SurveyQuestion, SurveyChoice, SurveyAnswer, SurveyMobileDisplayConfig };
|
|
9
|
+
/** Alias for backward compatibility */
|
|
10
|
+
export type Survey = SurveyConfiguration;
|
|
11
|
+
export interface SurveyResponse {
|
|
12
|
+
survey_id: string;
|
|
13
|
+
answers: SurveyAnswer[];
|
|
14
|
+
completed_at?: string;
|
|
15
|
+
duration_ms?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface SurveyPresentationOptions {
|
|
18
|
+
/** Survey identifier to display */
|
|
19
|
+
surveyIdentifier: string;
|
|
20
|
+
/** Optional customer ID for response attribution */
|
|
21
|
+
customerId?: string;
|
|
22
|
+
/** Optional context data passed to the survey */
|
|
23
|
+
context?: Record<string, any>;
|
|
24
|
+
/** Whether the survey can be dismissed */
|
|
25
|
+
isDismissible?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare class SurveyManager {
|
|
28
|
+
private static instance;
|
|
29
|
+
private initialized;
|
|
30
|
+
private constructor();
|
|
31
|
+
static getInstance(): SurveyManager;
|
|
32
|
+
/**
|
|
33
|
+
* Initialize the Survey module.
|
|
34
|
+
*/
|
|
35
|
+
initialize(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Present a survey to the user.
|
|
38
|
+
*/
|
|
39
|
+
presentSurvey(options: SurveyPresentationOptions): Promise<SurveyResponse | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Fetch a survey configuration without presenting it.
|
|
42
|
+
*/
|
|
43
|
+
fetchSurvey(surveyIdentifier: string): Promise<Survey | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Submit a survey response programmatically.
|
|
46
|
+
*/
|
|
47
|
+
submitResponse(response: SurveyResponse): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a survey is eligible to be shown to the current user.
|
|
50
|
+
*/
|
|
51
|
+
canShowSurvey(surveyIdentifier: string): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Listen to survey completion events.
|
|
54
|
+
*/
|
|
55
|
+
onSurveyCompleted(callback: (response: SurveyResponse) => void): import("react-native").EmitterSubscription | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Listen to survey dismissal events.
|
|
58
|
+
*/
|
|
59
|
+
onSurveyDismissed(callback: (data: {
|
|
60
|
+
surveyId: string;
|
|
61
|
+
pageIndex: number;
|
|
62
|
+
}) => void): import("react-native").EmitterSubscription | undefined;
|
|
63
|
+
}
|
|
64
|
+
declare const _default: SurveyManager;
|
|
65
|
+
export default _default;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @billdog.io/react-native — Survey Module
|
|
4
|
+
*
|
|
5
|
+
* Native bridge to BDSurvey (iOS) / billdog-survey (Android).
|
|
6
|
+
* Provides survey presentation, response collection, and template loading.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SurveyManager = void 0;
|
|
10
|
+
const react_native_1 = require("react-native");
|
|
11
|
+
const { BillDogSurvey } = react_native_1.NativeModules;
|
|
12
|
+
const eventEmitter = BillDogSurvey ? new react_native_1.NativeEventEmitter(BillDogSurvey) : null;
|
|
13
|
+
// MARK: - Survey Manager
|
|
14
|
+
class SurveyManager {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.initialized = false;
|
|
17
|
+
}
|
|
18
|
+
static getInstance() {
|
|
19
|
+
if (!SurveyManager.instance) {
|
|
20
|
+
SurveyManager.instance = new SurveyManager();
|
|
21
|
+
}
|
|
22
|
+
return SurveyManager.instance;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Initialize the Survey module.
|
|
26
|
+
*/
|
|
27
|
+
async initialize() {
|
|
28
|
+
if (!BillDogSurvey) {
|
|
29
|
+
console.warn('[BillDogSurvey] Native module not linked. Surveys will be no-op.');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
await BillDogSurvey.initialize();
|
|
33
|
+
this.initialized = true;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Present a survey to the user.
|
|
37
|
+
*/
|
|
38
|
+
async presentSurvey(options) {
|
|
39
|
+
if (!this.initialized || !BillDogSurvey)
|
|
40
|
+
return null;
|
|
41
|
+
return await BillDogSurvey.presentSurvey(options);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Fetch a survey configuration without presenting it.
|
|
45
|
+
*/
|
|
46
|
+
async fetchSurvey(surveyIdentifier) {
|
|
47
|
+
if (!this.initialized || !BillDogSurvey)
|
|
48
|
+
return null;
|
|
49
|
+
return await BillDogSurvey.fetchSurvey(surveyIdentifier);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Submit a survey response programmatically.
|
|
53
|
+
*/
|
|
54
|
+
async submitResponse(response) {
|
|
55
|
+
if (!this.initialized || !BillDogSurvey)
|
|
56
|
+
return false;
|
|
57
|
+
return await BillDogSurvey.submitResponse(response);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if a survey is eligible to be shown to the current user.
|
|
61
|
+
*/
|
|
62
|
+
async canShowSurvey(surveyIdentifier) {
|
|
63
|
+
if (!this.initialized || !BillDogSurvey)
|
|
64
|
+
return false;
|
|
65
|
+
return await BillDogSurvey.canShowSurvey(surveyIdentifier);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Listen to survey completion events.
|
|
69
|
+
*/
|
|
70
|
+
onSurveyCompleted(callback) {
|
|
71
|
+
return eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.addListener('onSurveyCompleted', callback);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Listen to survey dismissal events.
|
|
75
|
+
*/
|
|
76
|
+
onSurveyDismissed(callback) {
|
|
77
|
+
return eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.addListener('onSurveyDismissed', callback);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.SurveyManager = SurveyManager;
|
|
81
|
+
SurveyManager.instance = null;
|
|
82
|
+
exports.default = SurveyManager.getInstance();
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @billdog.io/react-native — Virtual Currency Module
|
|
3
|
+
* Version: 1.0.0
|
|
4
|
+
*/
|
|
5
|
+
export interface VirtualCurrency {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
code: string;
|
|
9
|
+
symbol: string;
|
|
10
|
+
balance: number;
|
|
11
|
+
}
|
|
12
|
+
export interface VirtualCurrencyTransaction {
|
|
13
|
+
id: string;
|
|
14
|
+
currencyId: string;
|
|
15
|
+
amount: number;
|
|
16
|
+
type: 'earn' | 'spend' | 'grant' | 'exchange';
|
|
17
|
+
reason?: string;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
metadata?: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
export interface ExchangeResult {
|
|
22
|
+
success: boolean;
|
|
23
|
+
fromCurrencyId: string;
|
|
24
|
+
toCurrencyId: string;
|
|
25
|
+
fromAmount: number;
|
|
26
|
+
toAmount: number;
|
|
27
|
+
exchangeRate: number;
|
|
28
|
+
newFromBalance: number;
|
|
29
|
+
newToBalance: number;
|
|
30
|
+
error?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface VirtualCurrencyConfig {
|
|
33
|
+
apiKey: string;
|
|
34
|
+
customerId: string;
|
|
35
|
+
enableLogging?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare class VirtualCurrencyManager {
|
|
38
|
+
private static instance;
|
|
39
|
+
private config;
|
|
40
|
+
private constructor();
|
|
41
|
+
static getInstance(): VirtualCurrencyManager;
|
|
42
|
+
initialize(config: VirtualCurrencyConfig): Promise<void>;
|
|
43
|
+
/** True when the native Virtual Currency bridge is linked into the host app. */
|
|
44
|
+
isAvailable(): boolean;
|
|
45
|
+
getBalance(currencyId: string): Promise<number>;
|
|
46
|
+
addCurrency(currencyId: string, amount: number, reason?: string, metadata?: Record<string, any>): Promise<number>;
|
|
47
|
+
deductCurrency(currencyId: string, amount: number, reason?: string, metadata?: Record<string, any>): Promise<number>;
|
|
48
|
+
grantCurrency(currencyId: string, amount: number, reason?: string): Promise<number>;
|
|
49
|
+
getTransactionHistory(currencyId?: string, limit?: number): Promise<VirtualCurrencyTransaction[]>;
|
|
50
|
+
exchangeCurrency(fromCurrencyId: string, toCurrencyId: string, fromAmount: number): Promise<ExchangeResult>;
|
|
51
|
+
getAllCurrencies(): Promise<VirtualCurrency[]>;
|
|
52
|
+
onBalanceChanged(callback: (data: {
|
|
53
|
+
currencyId: string;
|
|
54
|
+
newBalance: number;
|
|
55
|
+
}) => void): import("react-native").EmitterSubscription | {
|
|
56
|
+
remove(): void;
|
|
57
|
+
};
|
|
58
|
+
onTransaction(callback: (transaction: VirtualCurrencyTransaction) => void): import("react-native").EmitterSubscription | {
|
|
59
|
+
remove(): void;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
declare const _default: VirtualCurrencyManager;
|
|
63
|
+
export default _default;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @billdog.io/react-native — Virtual Currency Module
|
|
4
|
+
* Version: 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.VirtualCurrencyManager = void 0;
|
|
8
|
+
const react_native_1 = require("react-native");
|
|
9
|
+
const BillDogConfiguration_1 = require("../BillDogConfiguration");
|
|
10
|
+
const { BillDogVirtualCurrency } = react_native_1.NativeModules;
|
|
11
|
+
const eventEmitter = BillDogVirtualCurrency ? new react_native_1.NativeEventEmitter(BillDogVirtualCurrency) : null;
|
|
12
|
+
/**
|
|
13
|
+
* Fail loud with a clear, actionable message when the native module is not linked
|
|
14
|
+
* (e.g. Expo Go, a JS-only Metro run, or a host app that hasn't rebuilt after
|
|
15
|
+
* adding the SDK) instead of a cryptic `Cannot read property '…' of undefined`.
|
|
16
|
+
* The native module is registered by `BillDogVirtualCurrencyPackage` on Android
|
|
17
|
+
* and `BillDogVirtualCurrencyBridge` on iOS — both require a native rebuild.
|
|
18
|
+
*/
|
|
19
|
+
function requireNative() {
|
|
20
|
+
if (!BillDogVirtualCurrency) {
|
|
21
|
+
throw new Error('[BillDogVirtualCurrency] Native module not linked. Rebuild the app with the ' +
|
|
22
|
+
'native SDK (npx expo prebuild + a dev-client/EAS build, or pod install + ' +
|
|
23
|
+
'gradle sync) — the Virtual Currency bridge is not available in Expo Go.');
|
|
24
|
+
}
|
|
25
|
+
return BillDogVirtualCurrency;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Normalize a native transaction row into the declared `VirtualCurrencyTransaction`
|
|
29
|
+
* shape. The native bridges resolve the backend row as-is, which is snake_case
|
|
30
|
+
* (`currency_id`, `created_at`); this maps both snake_case and camelCase so the
|
|
31
|
+
* public type is honest on iOS and Android alike.
|
|
32
|
+
*/
|
|
33
|
+
function normalizeTransaction(raw) {
|
|
34
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
35
|
+
const ts = typeof (raw === null || raw === void 0 ? void 0 : raw.timestamp) === 'number'
|
|
36
|
+
? raw.timestamp
|
|
37
|
+
: (raw === null || raw === void 0 ? void 0 : raw.created_at)
|
|
38
|
+
? Date.parse(raw.created_at) || 0
|
|
39
|
+
: 0;
|
|
40
|
+
return {
|
|
41
|
+
id: String((_a = raw === null || raw === void 0 ? void 0 : raw.id) !== null && _a !== void 0 ? _a : ''),
|
|
42
|
+
currencyId: (_c = (_b = raw === null || raw === void 0 ? void 0 : raw.currencyId) !== null && _b !== void 0 ? _b : raw === null || raw === void 0 ? void 0 : raw.currency_id) !== null && _c !== void 0 ? _c : '',
|
|
43
|
+
amount: Number((_d = raw === null || raw === void 0 ? void 0 : raw.amount) !== null && _d !== void 0 ? _d : 0),
|
|
44
|
+
type: ((_e = raw === null || raw === void 0 ? void 0 : raw.type) !== null && _e !== void 0 ? _e : 'earn'),
|
|
45
|
+
reason: (_f = raw === null || raw === void 0 ? void 0 : raw.reason) !== null && _f !== void 0 ? _f : undefined,
|
|
46
|
+
timestamp: ts,
|
|
47
|
+
metadata: (_g = raw === null || raw === void 0 ? void 0 : raw.metadata) !== null && _g !== void 0 ? _g : undefined,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Normalize a native currency row into the declared `VirtualCurrency` shape.
|
|
52
|
+
* The all-balances backend route returns `{ currency: {id,code,name,icon}, balance }`
|
|
53
|
+
* (nested; the display symbol lives in `icon`), so map that shape as well as a
|
|
54
|
+
* flat one. See supabase/functions/virtual-currency/index.ts (handleGetAllBalances).
|
|
55
|
+
*/
|
|
56
|
+
function normalizeCurrency(raw) {
|
|
57
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
58
|
+
const c = (_a = raw === null || raw === void 0 ? void 0 : raw.currency) !== null && _a !== void 0 ? _a : raw;
|
|
59
|
+
return {
|
|
60
|
+
id: String((_b = c === null || c === void 0 ? void 0 : c.id) !== null && _b !== void 0 ? _b : ''),
|
|
61
|
+
name: (_c = c === null || c === void 0 ? void 0 : c.name) !== null && _c !== void 0 ? _c : '',
|
|
62
|
+
code: (_d = c === null || c === void 0 ? void 0 : c.code) !== null && _d !== void 0 ? _d : '',
|
|
63
|
+
symbol: (_f = (_e = c === null || c === void 0 ? void 0 : c.symbol) !== null && _e !== void 0 ? _e : c === null || c === void 0 ? void 0 : c.icon) !== null && _f !== void 0 ? _f : '',
|
|
64
|
+
balance: Number((_h = (_g = raw === null || raw === void 0 ? void 0 : raw.balance) !== null && _g !== void 0 ? _g : c === null || c === void 0 ? void 0 : c.balance) !== null && _h !== void 0 ? _h : 0),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Normalize a native exchange result into the declared `ExchangeResult` shape.
|
|
69
|
+
* The iOS bridge resolves the raw backend payload (snake_case: `to_amount`,
|
|
70
|
+
* `exchange_rate`, `new_from_balance`); the Android bridge already emits
|
|
71
|
+
* camelCase. Accept both so the public type is honest on either platform.
|
|
72
|
+
*/
|
|
73
|
+
function normalizeExchange(raw, fromCurrencyId, toCurrencyId, fromAmount) {
|
|
74
|
+
var _a, _b, _c, _d, _e, _f;
|
|
75
|
+
const num = (a, b, d = 0) => { var _a; return Number((_a = a !== null && a !== void 0 ? a : b) !== null && _a !== void 0 ? _a : d); };
|
|
76
|
+
return {
|
|
77
|
+
success: (_a = raw === null || raw === void 0 ? void 0 : raw.success) !== null && _a !== void 0 ? _a : !(raw === null || raw === void 0 ? void 0 : raw.error),
|
|
78
|
+
fromCurrencyId: (_c = (_b = raw === null || raw === void 0 ? void 0 : raw.fromCurrencyId) !== null && _b !== void 0 ? _b : raw === null || raw === void 0 ? void 0 : raw.from_currency_id) !== null && _c !== void 0 ? _c : fromCurrencyId,
|
|
79
|
+
toCurrencyId: (_e = (_d = raw === null || raw === void 0 ? void 0 : raw.toCurrencyId) !== null && _d !== void 0 ? _d : raw === null || raw === void 0 ? void 0 : raw.to_currency_id) !== null && _e !== void 0 ? _e : toCurrencyId,
|
|
80
|
+
fromAmount: num(raw === null || raw === void 0 ? void 0 : raw.fromAmount, raw === null || raw === void 0 ? void 0 : raw.from_amount, fromAmount),
|
|
81
|
+
toAmount: num(raw === null || raw === void 0 ? void 0 : raw.toAmount, raw === null || raw === void 0 ? void 0 : raw.to_amount),
|
|
82
|
+
exchangeRate: num(raw === null || raw === void 0 ? void 0 : raw.exchangeRate, raw === null || raw === void 0 ? void 0 : raw.exchange_rate),
|
|
83
|
+
newFromBalance: num(raw === null || raw === void 0 ? void 0 : raw.newFromBalance, raw === null || raw === void 0 ? void 0 : raw.new_from_balance),
|
|
84
|
+
newToBalance: num(raw === null || raw === void 0 ? void 0 : raw.newToBalance, raw === null || raw === void 0 ? void 0 : raw.new_to_balance),
|
|
85
|
+
error: (_f = raw === null || raw === void 0 ? void 0 : raw.error) !== null && _f !== void 0 ? _f : undefined,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
class VirtualCurrencyManager {
|
|
89
|
+
constructor() {
|
|
90
|
+
this.config = null;
|
|
91
|
+
}
|
|
92
|
+
static getInstance() {
|
|
93
|
+
if (!VirtualCurrencyManager.instance) {
|
|
94
|
+
VirtualCurrencyManager.instance = new VirtualCurrencyManager();
|
|
95
|
+
}
|
|
96
|
+
return VirtualCurrencyManager.instance;
|
|
97
|
+
}
|
|
98
|
+
async initialize(config) {
|
|
99
|
+
this.config = config;
|
|
100
|
+
// baseUrl is the single branded host (api.billdog.io/v1), not caller-supplied.
|
|
101
|
+
await requireNative().initialize({
|
|
102
|
+
...config,
|
|
103
|
+
baseUrl: BillDogConfiguration_1.BillDogConfiguration.getApiBaseUrl(),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/** True when the native Virtual Currency bridge is linked into the host app. */
|
|
107
|
+
isAvailable() {
|
|
108
|
+
return !!BillDogVirtualCurrency;
|
|
109
|
+
}
|
|
110
|
+
async getBalance(currencyId) {
|
|
111
|
+
return await requireNative().getBalance(currencyId);
|
|
112
|
+
}
|
|
113
|
+
async addCurrency(currencyId, amount, reason, metadata) {
|
|
114
|
+
return await requireNative().addCurrency(currencyId, amount, reason, metadata);
|
|
115
|
+
}
|
|
116
|
+
async deductCurrency(currencyId, amount, reason, metadata) {
|
|
117
|
+
return await requireNative().deductCurrency(currencyId, amount, reason, metadata);
|
|
118
|
+
}
|
|
119
|
+
async grantCurrency(currencyId, amount, reason) {
|
|
120
|
+
return await requireNative().grantCurrency(currencyId, amount, reason);
|
|
121
|
+
}
|
|
122
|
+
async getTransactionHistory(currencyId, limit = 50) {
|
|
123
|
+
const raw = await requireNative().getTransactionHistory(currencyId, limit);
|
|
124
|
+
return Array.isArray(raw) ? raw.map(normalizeTransaction) : [];
|
|
125
|
+
}
|
|
126
|
+
async exchangeCurrency(fromCurrencyId, toCurrencyId, fromAmount) {
|
|
127
|
+
const raw = await requireNative().exchangeCurrency(fromCurrencyId, toCurrencyId, fromAmount);
|
|
128
|
+
return normalizeExchange(raw, fromCurrencyId, toCurrencyId, fromAmount);
|
|
129
|
+
}
|
|
130
|
+
async getAllCurrencies() {
|
|
131
|
+
const raw = await requireNative().getAllCurrencies();
|
|
132
|
+
return Array.isArray(raw) ? raw.map(normalizeCurrency) : [];
|
|
133
|
+
}
|
|
134
|
+
onBalanceChanged(callback) {
|
|
135
|
+
if (!eventEmitter)
|
|
136
|
+
return { remove() { } };
|
|
137
|
+
return eventEmitter.addListener('onBalanceChanged', callback);
|
|
138
|
+
}
|
|
139
|
+
onTransaction(callback) {
|
|
140
|
+
if (!eventEmitter)
|
|
141
|
+
return { remove() { } };
|
|
142
|
+
return eventEmitter.addListener('onTransaction', callback);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.VirtualCurrencyManager = VirtualCurrencyManager;
|
|
146
|
+
VirtualCurrencyManager.instance = null;
|
|
147
|
+
exports.default = VirtualCurrencyManager.getInstance();
|
package/dist/murmur.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MurmurHash3 (x86_32) — the ONE canonical deterministic bucketing hash.
|
|
3
|
+
*
|
|
4
|
+
* React Native port of the backend canonical `murmurhash3`
|
|
5
|
+
* (`supabase/functions/_shared/edge-serving/pure.ts`) and the dashboard copy
|
|
6
|
+
* (`src/lib/murmur.ts`). Used to derive the render-time `user.seed` Dynamic
|
|
7
|
+
* Values variable so a user buckets IDENTICALLY on every surface.
|
|
8
|
+
*
|
|
9
|
+
* RN-SPECIFIC: uses a manual UTF-8 encoder instead of `TextEncoder`, because
|
|
10
|
+
* Hermes historically ships without `TextEncoder`. The bytes it produces are
|
|
11
|
+
* identical to `TextEncoder().encode(...)` for the fixture inputs (incl.
|
|
12
|
+
* surrogate-pair emoji), so it stays pinned to the same corpus.
|
|
13
|
+
*
|
|
14
|
+
* CONTRACT (do not change without regenerating the fixture on ALL ports):
|
|
15
|
+
* user.seed = murmurhash3(appUserId) % 1000 → range 0..999
|
|
16
|
+
*
|
|
17
|
+
* Conformance-pinned to `native-sdks/_test-fixtures/conformance/core_user_seed.json`.
|
|
18
|
+
* Never validated against another SDK port.
|
|
19
|
+
*/
|
|
20
|
+
export declare function murmurhash3(key: string, seed?: number): number;
|
|
21
|
+
export declare const USER_SEED_MODULUS = 1000;
|
|
22
|
+
/** Canonical `user.seed` derivation: 0..999 bucket from a stable user id. */
|
|
23
|
+
export declare function userSeedBucket(appUserId: string | null | undefined): number;
|