@ondropp/dropplink-react-native 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +333 -2
  2. package/android/build.gradle +58 -0
  3. package/android/src/main/AndroidManifest.xml +2 -0
  4. package/android/src/main/java/app/ondropp/dropplink/reactnative/RNDropplinkModule.kt +158 -0
  5. package/android/src/main/java/app/ondropp/dropplink/reactnative/RNDropplinkPackage.kt +27 -0
  6. package/dropplink-react-native.podspec +28 -0
  7. package/ios/RNDropplink.m +40 -0
  8. package/ios/RNDropplink.swift +159 -0
  9. package/lib/module/Dropplink.js +163 -0
  10. package/lib/module/Dropplink.js.map +1 -0
  11. package/lib/module/NativeDropplink.js +17 -0
  12. package/lib/module/NativeDropplink.js.map +1 -0
  13. package/lib/module/index.js +5 -0
  14. package/lib/module/index.js.map +1 -0
  15. package/lib/module/package.json +1 -0
  16. package/lib/module/types.js +2 -0
  17. package/lib/module/types.js.map +1 -0
  18. package/lib/module/useDropplinkDeepLink.js +19 -0
  19. package/lib/module/useDropplinkDeepLink.js.map +1 -0
  20. package/lib/typescript/package.json +1 -0
  21. package/lib/typescript/src/Dropplink.d.ts +58 -0
  22. package/lib/typescript/src/Dropplink.d.ts.map +1 -0
  23. package/lib/typescript/src/NativeDropplink.d.ts +40 -0
  24. package/lib/typescript/src/NativeDropplink.d.ts.map +1 -0
  25. package/lib/typescript/src/index.d.ts +4 -0
  26. package/lib/typescript/src/index.d.ts.map +1 -0
  27. package/lib/typescript/src/types.d.ts +62 -0
  28. package/lib/typescript/src/types.d.ts.map +1 -0
  29. package/lib/typescript/src/useDropplinkDeepLink.d.ts +7 -0
  30. package/lib/typescript/src/useDropplinkDeepLink.d.ts.map +1 -0
  31. package/package.json +119 -4
  32. package/src/Dropplink.ts +202 -0
  33. package/src/NativeDropplink.ts +48 -0
  34. package/src/index.ts +12 -0
  35. package/src/types.ts +66 -0
  36. package/src/useDropplinkDeepLink.ts +19 -0
@@ -0,0 +1,159 @@
1
+ import Foundation
2
+ import React
3
+ import Dropplink
4
+
5
+ /// Thin bridge to the native Dropplink SDK. All behaviour (storage, signing, retries, pending-link
6
+ /// buffering) lives in the `Dropplink` pod; this class only converts arguments.
7
+ ///
8
+ /// A classic `RCTEventEmitter` module (exported in `RNDropplink.m`): React Native 0.76+ serves it
9
+ /// to JS through the TurboModule interop layer under the New Architecture.
10
+ @objc(RNDropplink)
11
+ final class RNDropplink: RCTEventEmitter {
12
+ private static let deepLinkEvent = "DropplinkDeepLink"
13
+ private static let platformWrapper = "rn"
14
+
15
+ override static func requiresMainQueueSetup() -> Bool { false }
16
+
17
+ override func supportedEvents() -> [String]! { [Self.deepLinkEvent] }
18
+
19
+ @objc(initializeSdk:resolver:rejecter:)
20
+ func initializeSdk(
21
+ _ config: NSDictionary,
22
+ resolver resolve: @escaping RCTPromiseResolveBlock,
23
+ rejecter reject: @escaping RCTPromiseRejectBlock
24
+ ) {
25
+ let keyId = config["keyId"] as? String ?? ""
26
+ let secret = config["secret"] as? String ?? ""
27
+ let debug = config["debug"] as? Bool ?? false
28
+
29
+ let sdkConfig: DropplinkConfig
30
+ if let baseUrl = config["baseUrl"] as? String {
31
+ guard let url = URL(string: baseUrl) else {
32
+ reject("dropplink_initialize_failed", "baseUrl is not a valid URL: \(baseUrl)", nil)
33
+ return
34
+ }
35
+ sdkConfig = DropplinkConfig(
36
+ keyId: keyId, secret: secret, debug: debug, baseURL: url,
37
+ platformWrapper: Self.platformWrapper)
38
+ } else {
39
+ // Leave the SDK's default baseURL in place.
40
+ sdkConfig = DropplinkConfig(
41
+ keyId: keyId, secret: secret, debug: debug, platformWrapper: Self.platformWrapper)
42
+ }
43
+ Dropplink.initialize(config: sdkConfig)
44
+ resolve(nil)
45
+ }
46
+
47
+ @objc(handleDeepLink:resolver:rejecter:)
48
+ func handleDeepLink(
49
+ _ url: String,
50
+ resolver resolve: @escaping RCTPromiseResolveBlock,
51
+ rejecter reject: @escaping RCTPromiseRejectBlock
52
+ ) {
53
+ // Unparseable strings are dropped, like non-http(s) URLs are by the SDK.
54
+ if let parsed = URL(string: url) {
55
+ Dropplink.handleDeepLink(parsed)
56
+ }
57
+ resolve(nil)
58
+ }
59
+
60
+ @objc(getAttribution:rejecter:)
61
+ func getAttribution(
62
+ _ resolve: @escaping RCTPromiseResolveBlock,
63
+ rejecter reject: @escaping RCTPromiseRejectBlock
64
+ ) {
65
+ resolve(Dropplink.attribution?.dictionary)
66
+ }
67
+
68
+ @objc(getInstallId:rejecter:)
69
+ func getInstallId(
70
+ _ resolve: @escaping RCTPromiseResolveBlock,
71
+ rejecter reject: @escaping RCTPromiseRejectBlock
72
+ ) {
73
+ resolve(Dropplink.installId)
74
+ }
75
+
76
+ /// JS calls this with `true` when its first deep-link listener is added (the SDK then delivers
77
+ /// any link it buffered) and `false` when the last one is removed (the SDK buffers again).
78
+ @objc(setDeepLinkListenerEnabled:)
79
+ func setDeepLinkListenerEnabled(_ enabled: Bool) {
80
+ guard enabled else {
81
+ Dropplink.setDeepLinkListener(nil)
82
+ return
83
+ }
84
+ Dropplink.setDeepLinkListener { [weak self] link in
85
+ self?.sendEvent(withName: Self.deepLinkEvent, body: link.dictionary)
86
+ }
87
+ }
88
+
89
+ // Events and users (sdk-spec section 11). The SDK validates, queues and sends; it never throws.
90
+
91
+ @objc(track:props:revenue:)
92
+ func track(_ name: String, props: NSDictionary?, revenue: NSDictionary?) {
93
+ Dropplink.track(
94
+ name, props: props.map(Self.props(from:)), revenue: revenue.map(Self.revenue(from:)))
95
+ }
96
+
97
+ @objc(identify:email:phone:)
98
+ func identify(_ userId: String, email: String?, phone: String?) {
99
+ Dropplink.identify(userId: userId, email: email, phone: phone)
100
+ }
101
+
102
+ @objc func logout() {
103
+ Dropplink.logout()
104
+ }
105
+
106
+ @objc(setTrackingEnabled:)
107
+ func setTrackingEnabled(_ enabled: Bool) {
108
+ Dropplink.setTrackingEnabled(enabled)
109
+ }
110
+
111
+ @objc(isTrackingEnabled:rejecter:)
112
+ func isTrackingEnabled(
113
+ _ resolve: @escaping RCTPromiseResolveBlock,
114
+ rejecter reject: @escaping RCTPromiseRejectBlock
115
+ ) {
116
+ resolve(Dropplink.isTrackingEnabled)
117
+ }
118
+
119
+ /// JS booleans and numbers both arrive as `NSNumber`; only the `CFBoolean` singletons are
120
+ /// booleans, so the SDK sends `true` rather than `1`. `NSNull` stays (a null prop), and arrays /
121
+ /// dictionaries are passed on so the SDK drops them with its own debug log.
122
+ private static func props(from dict: NSDictionary) -> [String: Any] {
123
+ var out: [String: Any] = [:]
124
+ for (key, value) in dict {
125
+ guard let key = key as? String else { continue }
126
+ if let number = value as? NSNumber, isBoolean(number) {
127
+ out[key] = number.boolValue
128
+ } else if let number = value as? NSNumber {
129
+ out[key] = number.doubleValue
130
+ } else {
131
+ out[key] = value
132
+ }
133
+ }
134
+ return out
135
+ }
136
+
137
+ /// A missing or mistyped amount / currency becomes NaN / "", which the SDK rejects (dropping the
138
+ /// event with a debug log), so validation stays in one place.
139
+ private static func revenue(from dict: NSDictionary) -> Revenue {
140
+ var amount = Double.nan
141
+ if let number = dict["amount"] as? NSNumber, !isBoolean(number) {
142
+ amount = number.doubleValue
143
+ }
144
+ return Revenue(
145
+ amount: amount,
146
+ currency: dict["currency"] as? String ?? "",
147
+ orderId: dict["orderId"] as? String)
148
+ }
149
+
150
+ private static func isBoolean(_ number: NSNumber) -> Bool {
151
+ CFGetTypeID(number) == CFBooleanGetTypeID()
152
+ }
153
+
154
+ override func invalidate() {
155
+ // JS context is going away (reload/teardown): let the SDK buffer links again.
156
+ Dropplink.setDeepLinkListener(nil)
157
+ super.invalidate()
158
+ }
159
+ }
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+
3
+ import { Linking, NativeEventEmitter, Platform } from 'react-native';
4
+ import NativeDropplink, { DEEP_LINK_EVENT } from "./NativeDropplink.js";
5
+ const LINKING_ERROR = `'@ondropp/dropplink-react-native' doesn't seem to be linked. Make sure:\n\n` + Platform.select({
6
+ ios: "- You have run 'pod install'\n",
7
+ default: ''
8
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go (use a development build)\n';
9
+ function native() {
10
+ if (!NativeDropplink) throw new Error(LINKING_ERROR);
11
+ return NativeDropplink;
12
+ }
13
+
14
+ // Events and users must never throw into the host app (docs/sdk-spec.md section 2), not even when
15
+ // the module isn't linked: warn once in development and drop the call.
16
+ let warnedUnavailable = false;
17
+ function safely(call) {
18
+ try {
19
+ call(native());
20
+ } catch (e) {
21
+ if (!warnedUnavailable && typeof __DEV__ !== 'undefined' && __DEV__) {
22
+ warnedUnavailable = true;
23
+ console.warn('Dropplink:', e instanceof Error ? e.message : e);
24
+ }
25
+ }
26
+ }
27
+ let emitter;
28
+ let listenerCount = 0;
29
+ let initialUrlHandled = false;
30
+
31
+ // Native maps cross the bridge with nulls for absent fields; normalise them to the TS types.
32
+
33
+ function toDeepLink(raw) {
34
+ return {
35
+ path: String(raw.path ?? '/'),
36
+ params: raw.params ?? {},
37
+ url: raw.url ?? null,
38
+ isDeferred: raw.isDeferred === true
39
+ };
40
+ }
41
+ function toAttribution(raw) {
42
+ if (raw == null) return null;
43
+ const out = {};
44
+ for (const [key, value] of Object.entries(raw)) {
45
+ if (value != null) out[key] = value;
46
+ }
47
+ return out;
48
+ }
49
+ export const Dropplink = {
50
+ /**
51
+ * Starts the SDK. Call once, as early as possible (top of `index.js`). Later calls are ignored
52
+ * by the native SDK, as are calls after a native `Dropplink.initialize` in MainApplication /
53
+ * AppDelegate.
54
+ */
55
+ initialize(config) {
56
+ return native().initializeSdk({
57
+ keyId: config.keyId,
58
+ secret: config.secret,
59
+ debug: config.debug ?? false,
60
+ baseUrl: config.baseUrl ?? null
61
+ });
62
+ },
63
+ /**
64
+ * Receives every deep link: the deferred one after a fresh install and App Link / Universal
65
+ * Link opens. The native SDK holds a link that arrives before the first listener is added and
66
+ * delivers it then.
67
+ */
68
+ addDeepLinkListener(listener) {
69
+ const module = native();
70
+ emitter ??= new NativeEventEmitter(module);
71
+ const sub = emitter.addListener(DEEP_LINK_EVENT, raw => listener(toDeepLink(raw)));
72
+ if (listenerCount++ === 0) module.setDeepLinkListenerEnabled(true);
73
+ let removed = false;
74
+ return {
75
+ remove() {
76
+ if (removed) return;
77
+ removed = true;
78
+ sub.remove();
79
+ if (--listenerCount === 0) module.setDeepLinkListenerEnabled(false);
80
+ }
81
+ };
82
+ },
83
+ /**
84
+ * Reports an App Link / Universal Link the OS opened the app with. The result arrives on the
85
+ * deep-link listener. Non-http(s) URLs are ignored natively.
86
+ */
87
+ handleDeepLink(url) {
88
+ return native().handleDeepLink(url);
89
+ },
90
+ /** The last attribution the server returned, or `null` before the first successful init. */
91
+ async getAttribution() {
92
+ return toAttribution(await native().getAttribution());
93
+ },
94
+ /** This install's id, for the dashboard's Install debugger. */
95
+ async getInstallId() {
96
+ return (await native().getInstallId()) ?? null;
97
+ },
98
+ /**
99
+ * Forwards React Native `Linking` URLs (the launch URL and every later `url` event) to
100
+ * `handleDeepLink`, so App Links / Universal Links work with one call. Returns an unsubscribe
101
+ * function. The launch URL is forwarded once per JS context, however often this is called.
102
+ */
103
+ listenToLinking() {
104
+ const forward = url => {
105
+ if (url) Dropplink.handleDeepLink(url).catch(() => {});
106
+ };
107
+
108
+ // The launch URL is a one-off for this JS context, not tied to the subscription: forward it
109
+ // even if unsubscribed meanwhile (e.g. a StrictMode mount/unmount/mount).
110
+ if (!initialUrlHandled) {
111
+ initialUrlHandled = true;
112
+ Linking.getInitialURL().then(forward).catch(() => {});
113
+ }
114
+ const sub = Linking.addEventListener('url', ({
115
+ url
116
+ }) => forward(url));
117
+ return () => sub.remove();
118
+ },
119
+ /**
120
+ * Records an in-app event, e.g. `track('add_to_cart', { props: { sku: 'A1' } })`. The native SDK
121
+ * validates it (invalid events are dropped with a debug log), queues it on disk and sends it in
122
+ * the background. Never throws.
123
+ */
124
+ track(name, options) {
125
+ const revenue = options?.revenue;
126
+ safely(m => m.track(name, options?.props ?? null, revenue ? {
127
+ amount: revenue.amount,
128
+ currency: revenue.currency,
129
+ orderId: revenue.orderId ?? null
130
+ } : null));
131
+ },
132
+ /**
133
+ * Links the brand's own user id to this install. Call after sign-up / login; calling again with
134
+ * the same id is a no-op natively, so calling it on every launch is fine. `email` and `phone`
135
+ * are hashed on the device. Never throws.
136
+ */
137
+ identify(userId, traits) {
138
+ safely(m => m.identify(userId, traits?.email ?? null, traits?.phone ?? null));
139
+ },
140
+ /** Unlinks the user; later events carry no user. Never throws. */
141
+ logout() {
142
+ safely(m => m.logout());
143
+ },
144
+ /**
145
+ * `false` clears the native event queue and stops events and identify until set back to `true`
146
+ * (for consent). Persisted natively across launches. Attribution and deep links keep working.
147
+ */
148
+ setTrackingEnabled(enabled) {
149
+ safely(m => m.setTrackingEnabled(enabled));
150
+ },
151
+ /**
152
+ * The current setting (default `true`). Resolves `false` if the native module isn't linked or
153
+ * fails, since nothing is tracked then. Never rejects.
154
+ */
155
+ async isTrackingEnabled() {
156
+ try {
157
+ return (await native().isTrackingEnabled()) === true;
158
+ } catch {
159
+ return false;
160
+ }
161
+ }
162
+ };
163
+ //# sourceMappingURL=Dropplink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Linking","NativeEventEmitter","Platform","NativeDropplink","DEEP_LINK_EVENT","LINKING_ERROR","select","ios","default","native","Error","warnedUnavailable","safely","call","e","__DEV__","console","warn","message","emitter","listenerCount","initialUrlHandled","toDeepLink","raw","path","String","params","url","isDeferred","toAttribution","out","key","value","Object","entries","Dropplink","initialize","config","initializeSdk","keyId","secret","debug","baseUrl","addDeepLinkListener","listener","module","sub","addListener","setDeepLinkListenerEnabled","removed","remove","handleDeepLink","getAttribution","getInstallId","listenToLinking","forward","catch","getInitialURL","then","addEventListener","track","name","options","revenue","m","props","amount","currency","orderId","identify","userId","traits","email","phone","logout","setTrackingEnabled","enabled","isTrackingEnabled"],"sourceRoot":"../../src","sources":["Dropplink.ts"],"mappings":";;AAA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AAK,CACLC,IAAI,EACJC,OAAO,EAAEG,KAAK,IAAI,IAAI,EACtBF,OAAO,GACH;MACEG,MAAM,EAAEH,OAAO,CAACG,MAAM;MACtBC,QAAQ,EAAEJ,OAAO,CAACI,QAAQ;MAC1BC,OAAO,EAAEL,OAAO,CAACK,OAAO,IAAI;IAC9B,CAAC,GACD,IACN,CACF,CAAC;EACH,CAAC;EAED;AACF;AACA;AACA;AACA;EACEC,QAAQA,CAACC,MAAc,EAAEC,MAAuB,EAAQ;IACtD3D,MAAM,CAAEoD,CAAC,IACPA,CAAC,CAACK,QAAQ,CAACC,MAAM,EAAEC,MAAM,EAAEC,KAAK,IAAI,IAAI,EAAED,MAAM,EAAEE,KAAK,IAAI,IAAI,CACjE,CAAC;EACH,CAAC;EAED;EACAC,MAAMA,CAAA,EAAS;IACb9D,MAAM,CAAEoD,CAAC,IAAKA,CAAC,CAACU,MAAM,CAAC,CAAC,CAAC;EAC3B,CAAC;EAED;AACF;AACA;AACA;EACEC,kBAAkBA,CAACC,OAAgB,EAAQ;IACzChE,MAAM,CAAEoD,CAAC,IAAKA,CAAC,CAACW,kBAAkB,CAACC,OAAO,CAAC,CAAC;EAC9C,CAAC;EAED;AACF;AACA;AACA;EACE,MAAMC,iBAAiBA,CAAA,EAAqB;IAC1C,IAAI;MACF,OAAO,CAAC,MAAMpE,MAAM,CAAC,CAAC,CAACoE,iBAAiB,CAAC,CAAC,MAAM,IAAI;IACtD,CAAC,CAAC,MAAM;MACN,OAAO,KAAK;IACd;EACF;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+
5
+ /**
6
+ * The native module's interface. Implemented by `RNDropplinkModule` (Kotlin) and `RNDropplink`
7
+ * (Swift) as classic native modules, which RN 0.76+ serves through the TurboModule interop layer.
8
+ * See README "Architecture".
9
+ */
10
+
11
+ export const MODULE_NAME = 'RNDropplink';
12
+ export const DEEP_LINK_EVENT = 'DropplinkDeepLink';
13
+
14
+ // `get` (not `getEnforcing`) so importing the package never throws, e.g. in Jest or on web.
15
+ // TurboModuleRegistry falls back to NativeModules and the interop layer by itself.
16
+ export default TurboModuleRegistry.get(MODULE_NAME);
17
+ //# sourceMappingURL=NativeDropplink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","MODULE_NAME","DEEP_LINK_EVENT","get"],"sourceRoot":"../../src","sources":["NativeDropplink.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;;AAEpE;AACA;AACA;AACA;AACA;;AAoCA,OAAO,MAAMC,WAAW,GAAG,aAAa;AACxC,OAAO,MAAMC,eAAe,GAAG,mBAAmB;;AAElD;AACA;AACA,eAAeF,mBAAmB,CAACG,GAAG,CAAOF,WAAW,CAAC","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ export { Dropplink } from "./Dropplink.js";
4
+ export { useDropplinkDeepLink } from "./useDropplinkDeepLink.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Dropplink","useDropplinkDeepLink"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,gBAAa;AACvC,SAASC,oBAAoB,QAAQ,2BAAwB","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ import { useEffect, useRef } from 'react';
4
+ import { Dropplink } from "./Dropplink.js";
5
+ /**
6
+ * Calls `handler` for every Dropplink deep link while the component is mounted. The latest
7
+ * `handler` is always used, so it doesn't need to be memoised.
8
+ */
9
+ export function useDropplinkDeepLink(handler) {
10
+ const ref = useRef(handler);
11
+ useEffect(() => {
12
+ ref.current = handler;
13
+ });
14
+ useEffect(() => {
15
+ const sub = Dropplink.addDeepLinkListener(link => ref.current(link));
16
+ return () => sub.remove();
17
+ }, []);
18
+ }
19
+ //# sourceMappingURL=useDropplinkDeepLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useRef","Dropplink","useDropplinkDeepLink","handler","ref","current","sub","addDeepLinkListener","link","remove"],"sourceRoot":"../../src","sources":["useDropplinkDeepLink.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACzC,SAASC,SAAS,QAAQ,gBAAa;AAGvC;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAACC,OAAyB,EAAQ;EACpE,MAAMC,GAAG,GAAGJ,MAAM,CAACG,OAAO,CAAC;EAC3BJ,SAAS,CAAC,MAAM;IACdK,GAAG,CAACC,OAAO,GAAGF,OAAO;EACvB,CAAC,CAAC;EAEFJ,SAAS,CAAC,MAAM;IACd,MAAMO,GAAG,GAAGL,SAAS,CAACM,mBAAmB,CAAEC,IAAI,IAAKJ,GAAG,CAACC,OAAO,CAACG,IAAI,CAAC,CAAC;IACtE,OAAO,MAAMF,GAAG,CAACG,MAAM,CAAC,CAAC;EAC3B,CAAC,EAAE,EAAE,CAAC;AACR","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,58 @@
1
+ import type { Attribution, DeepLinkListener, DropplinkConfig, EventProps, IdentifyTraits, Revenue, Subscription } from './types.js';
2
+ export declare const Dropplink: {
3
+ /**
4
+ * Starts the SDK. Call once, as early as possible (top of `index.js`). Later calls are ignored
5
+ * by the native SDK, as are calls after a native `Dropplink.initialize` in MainApplication /
6
+ * AppDelegate.
7
+ */
8
+ initialize(config: DropplinkConfig): Promise<void>;
9
+ /**
10
+ * Receives every deep link: the deferred one after a fresh install and App Link / Universal
11
+ * Link opens. The native SDK holds a link that arrives before the first listener is added and
12
+ * delivers it then.
13
+ */
14
+ addDeepLinkListener(listener: DeepLinkListener): Subscription;
15
+ /**
16
+ * Reports an App Link / Universal Link the OS opened the app with. The result arrives on the
17
+ * deep-link listener. Non-http(s) URLs are ignored natively.
18
+ */
19
+ handleDeepLink(url: string): Promise<void>;
20
+ /** The last attribution the server returned, or `null` before the first successful init. */
21
+ getAttribution(): Promise<Attribution | null>;
22
+ /** This install's id, for the dashboard's Install debugger. */
23
+ getInstallId(): Promise<string | null>;
24
+ /**
25
+ * Forwards React Native `Linking` URLs (the launch URL and every later `url` event) to
26
+ * `handleDeepLink`, so App Links / Universal Links work with one call. Returns an unsubscribe
27
+ * function. The launch URL is forwarded once per JS context, however often this is called.
28
+ */
29
+ listenToLinking(): () => void;
30
+ /**
31
+ * Records an in-app event, e.g. `track('add_to_cart', { props: { sku: 'A1' } })`. The native SDK
32
+ * validates it (invalid events are dropped with a debug log), queues it on disk and sends it in
33
+ * the background. Never throws.
34
+ */
35
+ track(name: string, options?: {
36
+ props?: EventProps;
37
+ revenue?: Revenue;
38
+ }): void;
39
+ /**
40
+ * Links the brand's own user id to this install. Call after sign-up / login; calling again with
41
+ * the same id is a no-op natively, so calling it on every launch is fine. `email` and `phone`
42
+ * are hashed on the device. Never throws.
43
+ */
44
+ identify(userId: string, traits?: IdentifyTraits): void;
45
+ /** Unlinks the user; later events carry no user. Never throws. */
46
+ logout(): void;
47
+ /**
48
+ * `false` clears the native event queue and stops events and identify until set back to `true`
49
+ * (for consent). Persisted natively across launches. Attribution and deep links keep working.
50
+ */
51
+ setTrackingEnabled(enabled: boolean): void;
52
+ /**
53
+ * The current setting (default `true`). Resolves `false` if the native module isn't linked or
54
+ * fails, since nothing is tracked then. Never rejects.
55
+ */
56
+ isTrackingEnabled(): Promise<boolean>;
57
+ };
58
+ //# sourceMappingURL=Dropplink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Dropplink.d.ts","sourceRoot":"","sources":["../../../src/Dropplink.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EAEX,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,cAAc,EACd,OAAO,EACP,YAAY,EACb,MAAM,YAAS,CAAC;AAmDjB,eAAO,MAAM,SAAS;IACpB;;;;OAIG;uBACgB,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IASlD;;;;OAIG;kCAC2B,gBAAgB,GAAG,YAAY;IAmB7D;;;OAGG;wBACiB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,4FAA4F;sBACpE,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAInD,+DAA+D;oBACzC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAI5C;;;;OAIG;uBACgB,MAAM,IAAI;IAiB7B;;;;OAIG;gBAEK,MAAM,YACF;QAAE,KAAK,CAAC,EAAE,UAAU,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAClD,IAAI;IAiBP;;;;OAIG;qBACc,MAAM,WAAW,cAAc,GAAG,IAAI;IAMvD,kEAAkE;cACxD,IAAI;IAId;;;OAGG;gCACyB,OAAO,GAAG,IAAI;IAI1C;;;OAGG;yBACwB,OAAO,CAAC,OAAO,CAAC;CAO5C,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { type TurboModule } from 'react-native';
2
+ /**
3
+ * The native module's interface. Implemented by `RNDropplinkModule` (Kotlin) and `RNDropplink`
4
+ * (Swift) as classic native modules, which RN 0.76+ serves through the TurboModule interop layer.
5
+ * See README "Architecture".
6
+ */
7
+ export interface Spec extends TurboModule {
8
+ /** `baseUrl: null` lets the native SDK apply its default. `platformWrapper` is set natively. */
9
+ initializeSdk(config: {
10
+ keyId: string;
11
+ secret: string;
12
+ debug: boolean;
13
+ baseUrl: string | null;
14
+ }): Promise<void>;
15
+ handleDeepLink(url: string): Promise<void>;
16
+ getAttribution(): Promise<Object | null>;
17
+ getInstallId(): Promise<string | null>;
18
+ /**
19
+ * `true` installs the native deep-link listener (delivering any link the native SDK buffered),
20
+ * `false` removes it so the native SDK buffers again.
21
+ */
22
+ setDeepLinkListenerEnabled(enabled: boolean): void;
23
+ /** `props` values keep their JS type (string, number, boolean, null); native drops the rest. */
24
+ track(name: string, props: Object | null, revenue: {
25
+ amount: number;
26
+ currency: string;
27
+ orderId: string | null;
28
+ } | null): void;
29
+ identify(userId: string, email: string | null, phone: string | null): void;
30
+ logout(): void;
31
+ setTrackingEnabled(enabled: boolean): void;
32
+ isTrackingEnabled(): Promise<boolean>;
33
+ addListener(eventName: string): void;
34
+ removeListeners(count: number): void;
35
+ }
36
+ export declare const MODULE_NAME = "RNDropplink";
37
+ export declare const DEEP_LINK_EVENT = "DropplinkDeepLink";
38
+ declare const _default: Spec | null | undefined;
39
+ export default _default;
40
+ //# sourceMappingURL=NativeDropplink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeDropplink.d.ts","sourceRoot":"","sources":["../../../src/NativeDropplink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE;;;;GAIG;AACH,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,gGAAgG;IAChG,aAAa,CAAC,MAAM,EAAE;QACpB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,OAAO,CAAC;QACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACxB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,cAAc,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzC,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACvC;;;OAGG;IACH,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAInD,gGAAgG;IAChG,KAAK,CACH,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI,GAC3E,IAAI,CAAC;IACR,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAC3E,MAAM,IAAI,IAAI,CAAC;IACf,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3C,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAGtC,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;AAED,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,eAAe,sBAAsB,CAAC;;AAInD,wBAA0D"}
@@ -0,0 +1,4 @@
1
+ export { Dropplink } from './Dropplink.js';
2
+ export { useDropplinkDeepLink } from './useDropplinkDeepLink.js';
3
+ export type { Attribution, DeepLink, DeepLinkListener, DropplinkConfig, EventProps, IdentifyTraits, Revenue, Subscription, } from './types.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAa,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAAwB,CAAC;AAC9D,YAAY,EACV,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,cAAc,EACd,OAAO,EACP,YAAY,GACb,MAAM,YAAS,CAAC"}
@@ -0,0 +1,62 @@
1
+ /** Options for {@link Dropplink.initialize}. See docs/sdk-spec.md section 2. */
2
+ export type DropplinkConfig = {
3
+ /** `ak_…` SDK key id for this platform, from the Dropplink dashboard. */
4
+ keyId: string;
5
+ /** The key's secret. Load it from build config; never commit it. */
6
+ secret: string;
7
+ /** Turns on native logging (tag `Dropplink`). Never ship `true`. Default `false`. */
8
+ debug?: boolean;
9
+ /** Defaults to `https://attribution.ondropp.app` (the native SDK's default). */
10
+ baseUrl?: string;
11
+ };
12
+ /**
13
+ * A resolved deep link: the deferred one after a fresh install (`isDeferred: true`, `url: null`)
14
+ * or an App Link / Universal Link open (`isDeferred: false`, `url` set).
15
+ */
16
+ export type DeepLink = {
17
+ path: string;
18
+ params: Record<string, string>;
19
+ url: string | null;
20
+ isDeferred: boolean;
21
+ };
22
+ /** The last attribution the server returned. */
23
+ export type Attribution = {
24
+ type: 'attributed' | 'organic';
25
+ method: 'install_referrer' | 'fingerprint' | 'none';
26
+ clickId?: string;
27
+ linkId?: string;
28
+ campaignId?: string;
29
+ creatorId?: string;
30
+ source?: string;
31
+ confidence?: number;
32
+ /** ISO 8601 timestamp. */
33
+ attributedAt?: string;
34
+ };
35
+ export type DeepLinkListener = (link: DeepLink) => void;
36
+ export type Subscription = {
37
+ remove(): void;
38
+ };
39
+ /**
40
+ * Properties for {@link Dropplink.track}. At most 20; keys `^[A-Za-z0-9_]{1,40}$`. The native SDK
41
+ * drops invalid keys and values (and anything that looks like an email or phone number).
42
+ */
43
+ export type EventProps = Record<string, string | number | boolean | null>;
44
+ /**
45
+ * Revenue the app reports with an event, shown as app-reported in the dashboard. Purchases that pay
46
+ * creators should come from the brand's server (`/v1/s2s/events`) instead.
47
+ */
48
+ export type Revenue = {
49
+ /** Finite and >= 0; rounded to 2 decimals natively. */
50
+ amount: number;
51
+ /** ISO 4217 code, e.g. `INR`. */
52
+ currency: string;
53
+ /** 1–128 chars. */
54
+ orderId?: string;
55
+ };
56
+ /** Optional traits for {@link Dropplink.identify}. Hashed (SHA-256) on the device before sending. */
57
+ export type IdentifyTraits = {
58
+ email?: string;
59
+ /** E.164, e.g. `+919812345678`. */
60
+ phone?: string;
61
+ };
62
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,MAAM,eAAe,GAAG;IAC5B,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;IACf,qFAAqF;IACrF,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,gDAAgD;AAChD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,YAAY,GAAG,SAAS,CAAC;IAC/B,MAAM,EAAE,kBAAkB,GAAG,aAAa,GAAG,MAAM,CAAC;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0BAA0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;AAExD,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,IAAI,IAAI,CAAA;CAAE,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC;AAE1E;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,qGAAqG;AACrG,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { DeepLinkListener } from './types.js';
2
+ /**
3
+ * Calls `handler` for every Dropplink deep link while the component is mounted. The latest
4
+ * `handler` is always used, so it doesn't need to be memoised.
5
+ */
6
+ export declare function useDropplinkDeepLink(handler: DeepLinkListener): void;
7
+ //# sourceMappingURL=useDropplinkDeepLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDropplinkDeepLink.d.ts","sourceRoot":"","sources":["../../../src/useDropplinkDeepLink.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAS,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAUpE"}