@amplytools/react-native-amply-sdk 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/AmplyReactNative.podspec +1 -1
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/tools/amply/sdk/reactnative/AmplyModule.kt +62 -0
  4. package/android/src/main/java/tools/amply/sdk/reactnative/core/AmplyClient.kt +35 -0
  5. package/android/src/main/java/tools/amply/sdk/reactnative/core/DefaultAmplyClient.kt +134 -0
  6. package/android/src/main/java/tools/amply/sdk/reactnative/model/CampaignPresentPayload.kt +16 -0
  7. package/android/src/main/java/tools/amply/sdk/reactnative/model/DeepLinkPayload.kt +15 -0
  8. package/android/src/newarch/java/tools/amply/sdk/reactnative/NativeAmplyModuleSpec.java +16 -0
  9. package/android/src/newarch/jni/AmplyReactNative-generated.cpp +19 -0
  10. package/dist/src/__tests__/campaignResolved.test.d.ts +2 -0
  11. package/dist/src/__tests__/campaignResolved.test.d.ts.map +1 -0
  12. package/dist/src/__tests__/campaignResolved.test.js +137 -0
  13. package/dist/src/index.d.ts +57 -2
  14. package/dist/src/index.d.ts.map +1 -1
  15. package/dist/src/index.js +84 -0
  16. package/dist/src/nativeSpecs/NativeAmplyModule.d.ts +56 -0
  17. package/dist/src/nativeSpecs/NativeAmplyModule.d.ts.map +1 -1
  18. package/dist/tsconfig.tsbuildinfo +1 -1
  19. package/ios/Sources/AmplyReactNative/AmplyModule.mm +156 -1
  20. package/ios/Sources/AmplyReactNative/AmplyReactNative/AmplyReactNative-generated.mm +26 -0
  21. package/ios/Sources/AmplyReactNative/AmplyReactNative/AmplyReactNative.h +8 -0
  22. package/package.json +1 -1
  23. package/src/__tests__/campaignResolved.test.ts +180 -0
  24. package/src/index.ts +157 -0
  25. package/src/nativeSpecs/NativeAmplyModule.ts +58 -0
@@ -84,10 +84,67 @@ export type DeepLinkEvent = {
84
84
  consumed: boolean;
85
85
  };
86
86
 
87
+ /**
88
+ * Terminal result reported by a campaign presenter back to the SDK.
89
+ *
90
+ * - 'Completed': the presenter satisfied the campaign condition (e.g. rewarded ad
91
+ * watched to completion). The continuation proceeds.
92
+ * - 'Dismissed': a USER-INITIATED dismiss without satisfying the condition. With an
93
+ * `onAbort=cancel` action this suppresses the continuation; with `onAbort=proceed`
94
+ * it proceeds. Reserved strictly for user intent — never infra failures.
95
+ * - 'Unavailable': any non-user failure (no-fill, failed-to-show, not-ready, missing
96
+ * precondition). Always fails open and proceeds.
97
+ *
98
+ * NOTE: this raw result is intentionally NOT surfaced to app continuation code —
99
+ * the public `trackEvent` continuation only ever sees `onProceed`/`onCancel`.
100
+ */
101
+ export type CampaignResult = 'Completed' | 'Dismissed' | 'Unavailable';
102
+
103
+ /**
104
+ * Payload delivered to JS when a campaign dispatches a present (blocking) action.
105
+ * The JS handler must eventually report a {@link CampaignResult} for `mediationId`
106
+ * via `resolveCampaign`.
107
+ */
108
+ export type CampaignPresentEvent = {
109
+ url: string;
110
+ /**
111
+ * Enriched, decoupled action info:
112
+ * `{ url, campaignId, campaignName, triggeringEvent, triggeringProperties, content }`.
113
+ */
114
+ info: JsonMap;
115
+ mediationId: string;
116
+ };
117
+
87
118
  export interface Spec extends TurboModule {
88
119
  initialize(config: AmplyInitializationConfig): Promise<void>;
89
120
  isInitialized(): boolean;
90
121
  track(payload: TrackEventPayload): Promise<void>;
122
+ /**
123
+ * Gated form of track: records the event, evaluates campaigns, and — if a
124
+ * blocking action matches and a presenter is registered — dispatches the campaign
125
+ * present and awaits its result. Resolves with the continuation decision:
126
+ * - 'complete': the continuation should proceed (onProceed).
127
+ * - 'cancel': the continuation should be suppressed (onCancel) — only ever
128
+ * returned for a user `Dismissed` against an `onAbort=cancel` action.
129
+ *
130
+ * The raw {@link CampaignResult} is never returned to JS; it is collapsed natively
131
+ * into this 'complete' | 'cancel' decision so app code can't branch on results.
132
+ * Every failure path fails open to 'complete'.
133
+ */
134
+ trackEventGated(event: string, properties: JsonMap): Promise<string>;
135
+ /**
136
+ * Report the terminal result of a campaign present dispatched to JS via the
137
+ * `onCampaignPresent` event. Idempotent natively — late/duplicate calls are ignored.
138
+ * @param mediationId The id carried by the matching `onCampaignPresent` event.
139
+ * @param result One of {@link CampaignResult} ('Completed' | 'Dismissed' | 'Unavailable').
140
+ */
141
+ resolveCampaign(mediationId: string, result: string): void;
142
+ /**
143
+ * Register the JS side as the recipient of campaign present dispatches. Wiring of
144
+ * the actual per-URL-pattern routing happens natively; JS receives every dispatch
145
+ * via the `onCampaignPresent` event and replies through `resolveCampaign`.
146
+ */
147
+ registerCampaignPresenter(): void;
91
148
  getRecentEvents(limit: number): Promise<EventRecord[]>;
92
149
  getDataSetSnapshot(type: DataSetType): Promise<DataSetSnapshot>;
93
150
  registerDeepLinkListener(): void;
@@ -128,6 +185,7 @@ export interface Spec extends TurboModule {
128
185
  clearCustomProperties(): void;
129
186
  readonly onSystemEvent: EventEmitter<SystemEventPayload>;
130
187
  readonly onDeepLink: EventEmitter<DeepLinkEvent>;
188
+ readonly onCampaignPresent: EventEmitter<CampaignPresentEvent>;
131
189
  addListener(eventName: string): void;
132
190
  removeListeners(count: number): void;
133
191
  }