@pushpilotai/react-native 0.0.0-stage → 2.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.
@@ -0,0 +1,96 @@
1
+ import PushPilot
2
+ import UIKit
3
+ import UserNotifications
4
+
5
+ /// Gets taps on notifications to the PushPilot SDK by joining the app's notification-center delegate
6
+ /// chain, the way React Native Firebase and expo-notifications do, so the app adds no tap code.
7
+ @objc(RNPushPilotNotifications)
8
+ public final class RNPushPilotNotifications: NSObject {
9
+ private static let delegate = NotificationDelegate()
10
+ /// Receives the id and custom data of each tap that opens the app; set once at launch. Main thread.
11
+ static var tapHandler: (([String: Any]) -> Void)?
12
+
13
+ /// Sets where taps go; called by the module's launch hook before `installAtLaunch`.
14
+ @objc public static func setTapHandler(_ handler: @escaping ([String: Any]) -> Void) {
15
+ tapHandler = handler
16
+ }
17
+
18
+ /// Ids of the taps already sent to `tapHandler`, so a tap forwarded twice is reported once. Main thread.
19
+ private static var reported: Set<String> = []
20
+
21
+ /// Hands a tap to the SDK, which records the click and opens or passes on the link, then reports it to
22
+ /// `tapHandler` if it opened the app. Returns false for pushes not from PushPilot. Main thread.
23
+ static func handle(_ response: UNNotificationResponse) -> Bool {
24
+ guard PushPilot.handleNotificationResponse(response) else { return false }
25
+ if let tap = tap(response.notification.request.content.userInfo, action: response.actionIdentifier),
26
+ let id = tap["notificationId"] as? String, reported.insert(id).inserted {
27
+ tapHandler?(tap)
28
+ }
29
+ return true
30
+ }
31
+
32
+ /// The id and custom data of a tapped PushPilot push, as Android's `TappedNotification` has them. Nil
33
+ /// without an id, and for a tap that leaves the app closed: a dismissal or a button without a `url`.
34
+ private static func tap(_ userInfo: [AnyHashable: Any], action: String) -> [String: Any]? {
35
+ guard let id = userInfo["notification_id"] as? String, !id.isEmpty else { return nil }
36
+ if action != UNNotificationDefaultActionIdentifier {
37
+ let button = (userInfo["buttons"] as? [[String: Any]])?.first { $0["id"] as? String == action }
38
+ guard (button?["url"] as? String)?.isEmpty == false else { return nil } // the SDK's rule for opening the app
39
+ }
40
+ return ["notificationId": id, "data": userInfo["data"] as? [String: String] ?? [:]]
41
+ }
42
+
43
+ /// Runs once launch has finished: becomes the delegate, keeping the earlier one, and asks for the device token when allowed.
44
+ @objc public static func installAtLaunch() {
45
+ let center = UNUserNotificationCenter.current()
46
+ if center.delegate !== delegate {
47
+ delegate.previous = center.delegate
48
+ center.delegate = delegate
49
+ }
50
+ registerIfAllowed()
51
+ // didBecomeActive also fires when the permission alert closes, so a new permission gets a token at once.
52
+ NotificationCenter.default.addObserver(
53
+ forName: UIApplication.didBecomeActiveNotification, object: nil, queue: .main
54
+ ) { _ in registerIfAllowed() }
55
+ }
56
+
57
+ /// Registers for remote notifications once the user has allowed them; iOS then hands the token to the app delegate.
58
+ private static func registerIfAllowed() {
59
+ UNUserNotificationCenter.current().getNotificationSettings { settings in
60
+ guard [.authorized, .provisional, .ephemeral].contains(settings.authorizationStatus) else { return }
61
+ DispatchQueue.main.async { UIApplication.shared.registerForRemoteNotifications() }
62
+ }
63
+ }
64
+ }
65
+
66
+ /// The delegate itself; private so the generated Objective-C header needs no UserNotifications import.
67
+ private final class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
68
+ /// The delegate set before this one (the app's own or another library's); every call is passed on to it.
69
+ weak var previous: UNUserNotificationCenterDelegate?
70
+
71
+ /// A tap on a push or one of its buttons: PushPilot taps are handled, then the earlier delegate gets every tap.
72
+ func userNotificationCenter(
73
+ _ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse,
74
+ withCompletionHandler completionHandler: @escaping () -> Void
75
+ ) {
76
+ _ = RNPushPilotNotifications.handle(response)
77
+ if previous?.userNotificationCenter?(center, didReceive: response, withCompletionHandler: completionHandler) == nil {
78
+ completionHandler()
79
+ }
80
+ }
81
+
82
+ /// A push while the app is open: the earlier delegate decides; without one, iOS's default of not showing it.
83
+ func userNotificationCenter(
84
+ _ center: UNUserNotificationCenter, willPresent notification: UNNotification,
85
+ withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
86
+ ) {
87
+ if previous?.userNotificationCenter?(center, willPresent: notification, withCompletionHandler: completionHandler) == nil {
88
+ completionHandler([])
89
+ }
90
+ }
91
+
92
+ /// The in-app notification settings request, passed on unchanged.
93
+ func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?) {
94
+ previous?.userNotificationCenter?(center, openSettingsFor: notification)
95
+ }
96
+ }
@@ -0,0 +1,29 @@
1
+ import Foundation
2
+
3
+ /// Reads an APNs device token written as hex text. expo-notifications writes it in lowercase,
4
+ /// React Native Firebase's `getAPNSToken` in uppercase; both are accepted.
5
+ enum RNPushPilotToken {
6
+ /// The token's bytes, or nil when the text is empty, of odd length or not hex: an FCM token or a
7
+ /// Firebase Installation ID, which the iOS SDK no longer uses.
8
+ static func data(fromHex hex: String) -> Data? {
9
+ let digits = Array(hex.utf8)
10
+ guard !digits.isEmpty, digits.count % 2 == 0 else { return nil }
11
+ var bytes = [UInt8]()
12
+ bytes.reserveCapacity(digits.count / 2)
13
+ for i in stride(from: 0, to: digits.count, by: 2) {
14
+ guard let high = nibble(digits[i]), let low = nibble(digits[i + 1]) else { return nil }
15
+ bytes.append(high << 4 | low)
16
+ }
17
+ return Data(bytes)
18
+ }
19
+
20
+ /// The value of one ASCII hex digit, or nil for any other byte.
21
+ private static func nibble(_ c: UInt8) -> UInt8? {
22
+ switch c {
23
+ case 48...57: return c - 48 // 0-9
24
+ case 65...70: return c - 55 // A-F
25
+ case 97...102: return c - 87 // a-f
26
+ default: return nil
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+
5
+ // The native module's shape; codegen turns it into the Kotlin and Objective-C interfaces.
6
+
7
+ // `get`, not `getEnforcing`: a missing native module (Expo Go, not rebuilt) must not throw at import.
8
+ export default TurboModuleRegistry.get('PushPilot');
9
+ //# sourceMappingURL=NativePushPilot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","get"],"sourceRoot":"../../src","sources":["NativePushPilot.ts"],"mappings":";;AAAA,SACEA,mBAAmB,QAGd,cAAc;;AAErB;;AA+BA;AACA,eAAeA,mBAAmB,CAACC,GAAG,CAAO,WAAW,CAAC","ignoreList":[]}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ import { NativeEventEmitter, Platform, findNodeHandle } from 'react-native';
4
+ import Native from "./NativePushPilot.js";
5
+
6
+ /** A custom attribute value; `null` removes the attribute. Pass dates as RFC 3339 strings. */
7
+
8
+ /** A tapped PushPilot push that opened the app. */
9
+
10
+ /** Options for `PushPilot.init`. */
11
+
12
+ // Runs one native call, logging instead of throwing so the SDK can never crash the app.
13
+ function call(name, run) {
14
+ try {
15
+ if (Native) {
16
+ run(Native);
17
+ } else {
18
+ console.warn(`[PushPilot] ${name} ignored: the native module is not linked. Rebuild the app (Expo Go is not supported).`);
19
+ }
20
+ } catch (e) {
21
+ console.warn(`[PushPilot] ${name} failed: ${String(e)}`);
22
+ }
23
+ }
24
+
25
+ // An APNs device token as hex: what iOS needs since 2.0. FCM tokens and FIDs contain other characters.
26
+ const APNS_HEX = /^(?:[0-9a-fA-F]{2})+$/;
27
+ // JavaScript's current link and tap handlers, if any.
28
+ const subscriptions = {};
29
+
30
+ // Replaces the handler for one event and tells native whether one is set now.
31
+ function setHandler(event, handler, enable) {
32
+ call(event === 'PushPilotLink' ? 'setLinkHandler' : 'setTapHandler', n => {
33
+ subscriptions[event]?.remove();
34
+ subscriptions[event] = handler ? new NativeEventEmitter(n).addListener(event, handler) : undefined;
35
+ enable(n, handler !== null);
36
+ });
37
+ }
38
+ const PushPilot = {
39
+ /** Starts the SDK with the app's public SDK key. Later calls are ignored; earlier calls are queued. */
40
+ init(sdkKey, options) {
41
+ const baseUrl = options?.baseUrl ?? null;
42
+ const appGroup = options?.appGroup;
43
+ call('init', n => appGroup ? n.initializeWithAppGroup(sdkKey, baseUrl, appGroup) : n.initialize(sdkKey, baseUrl));
44
+ },
45
+ /**
46
+ * Pass every URL your app is opened with (React Native's `Linking`). For a tap on an iOS live
47
+ * activity it records the click once and resolves to the activity's own link without PushPilot's
48
+ * marker, or `null` when the activity has none (just show the app). Any other URL, and every URL on
49
+ * Android, resolves unchanged. Never rejects: on a failure it resolves to the URL as given.
50
+ */
51
+ async handleLiveActivityURL(url) {
52
+ try {
53
+ if (Native) return await Native.handleLiveActivityURL(url);
54
+ console.warn('[PushPilot] handleLiveActivityURL ignored: the native module is not linked. Rebuild the app (Expo Go is not supported).');
55
+ } catch (e) {
56
+ console.warn(`[PushPilot] handleLiveActivityURL failed: ${String(e)}`);
57
+ }
58
+ return url;
59
+ },
60
+ /**
61
+ * Passes the push identifier; `null` clears it.
62
+ * - Android: the Firebase Installation ID from `register` / `onRegistered` where your Firebase
63
+ * library has it, otherwise the FCM token from `getToken` / `onTokenRefresh`. Pass only one kind.
64
+ * (Not PushPilot's own installation id.)
65
+ * - iOS: the APNs device token as hex, e.g. from expo-notifications' `getDevicePushTokenAsync()` or
66
+ * React Native Firebase's `getAPNSToken()`. Not needed when your AppDelegate forwards the token
67
+ * natively. Anything else (an FCM token or FID, the 1.x iOS path) is ignored with a warning.
68
+ */
69
+ setPushToken(token) {
70
+ if (Platform.OS === 'ios' && token !== null && !APNS_HEX.test(token)) {
71
+ console.warn('[PushPilot] setPushToken ignored: on iOS pass the APNs device token as hex, not an FCM token or Firebase Installation ID.');
72
+ return;
73
+ }
74
+ call('setPushToken', n => n.setPushToken(token));
75
+ },
76
+ /** Links this installation to your own user id after login; `null` clears it. */
77
+ setExternalUserId(id) {
78
+ call('setExternalUserId', n => n.setExternalUserId(id));
79
+ },
80
+ /** Merges custom attributes declared in the dashboard. */
81
+ setAttributes(attributes) {
82
+ call('setAttributes', n => n.setAttributes(attributes));
83
+ },
84
+ /** Replaces this installation's topic list. */
85
+ setTopics(topics) {
86
+ call('setTopics', n => n.setTopics(topics));
87
+ },
88
+ /** Clears the external user id; the device stays registered and keeps receiving pushes. */
89
+ logout() {
90
+ call('logout', n => n.logout());
91
+ },
92
+ /** Deletes this installation from PushPilot and clears all local SDK state. */
93
+ forget() {
94
+ call('forget', n => n.forget());
95
+ },
96
+ /**
97
+ * Receives the link of each tapped PushPilot push (the button's link, or the push's own) instead of
98
+ * the system opening it, like the native SDKs' `setLinkHandler`; `null` lets the system open links
99
+ * again. Set it before `init` to also get the tap that launched the app; each link arrives once.
100
+ */
101
+ setLinkHandler(handler) {
102
+ setHandler('PushPilotLink', handler, (n, on) => n.setLinkHandlerEnabled(on));
103
+ },
104
+ /**
105
+ * Receives the id and custom data of each tapped PushPilot push that opens the app; `null` stops it.
106
+ * Set it before `init` to also get the tap that launched the app; each tap arrives once.
107
+ */
108
+ setTapHandler(handler) {
109
+ setHandler('PushPilotTap', handler, (n, on) => n.setTapHandlerEnabled(on));
110
+ },
111
+ /**
112
+ * Shows the first eligible cached in-app message whose trigger name is `name` and resolves to whether
113
+ * one is now on screen: `false` when none is cached and eligible, another message is showing, or the
114
+ * SDK has not started. No network call. Never rejects: on a failure it resolves to `false`.
115
+ */
116
+ async showInApp(name) {
117
+ try {
118
+ if (Native) return await Native.showInApp(name);
119
+ console.warn('[PushPilot] showInApp ignored: the native module is not linked. Rebuild the app (Expo Go is not supported).');
120
+ } catch (e) {
121
+ console.warn(`[PushPilot] showInApp failed: ${String(e)}`);
122
+ }
123
+ return false;
124
+ },
125
+ /**
126
+ * Names a mounted view for coach-mark messages whose target is `name`: pass its `ref` (or a view tag
127
+ * from `findNodeHandle`). Give a plain `<View>` `collapsable={false}` so it has a native view. The SDK
128
+ * holds the view weakly; a later view with the same name replaces it.
129
+ */
130
+ // `any`: refs of every host component type (View, Pressable, TextInput...) are accepted.
131
+ markView(ref, name) {
132
+ const tag = typeof ref === 'number' ? ref : findNodeHandle(ref.current);
133
+ if (tag == null) {
134
+ console.warn('[PushPilot] markView ignored: the ref has no mounted native view yet.');
135
+ return;
136
+ }
137
+ call('markView', n => n.markView(tag, name));
138
+ },
139
+ /** Forgets the view marked with `name`. */
140
+ unmarkView(name) {
141
+ call('unmarkView', n => n.unmarkView(name));
142
+ },
143
+ /** True when a received push's data came from PushPilot. Same rule as the native SDKs; no native call. */
144
+ handleMessage(data) {
145
+ return data?.source === 'pushpilot';
146
+ }
147
+ };
148
+ export default PushPilot;
149
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeEventEmitter","Platform","findNodeHandle","Native","call","name","run","console","warn","e","String","APNS_HEX","subscriptions","setHandler","event","handler","enable","n","remove","addListener","undefined","PushPilot","init","sdkKey","options","baseUrl","appGroup","initializeWithAppGroup","initialize","handleLiveActivityURL","url","setPushToken","token","OS","test","setExternalUserId","id","setAttributes","attributes","setTopics","topics","logout","forget","setLinkHandler","on","setLinkHandlerEnabled","setTapHandler","setTapHandlerEnabled","showInApp","markView","ref","tag","current","unmarkView","handleMessage","data","source"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AACA,SACEA,kBAAkB,EAClBC,QAAQ,EACRC,cAAc,QAET,cAAc;AACrB,OAAOC,MAAM,MAAqB,sBAAmB;;AAErD;;AAGA;;AAQA;;AAWA;AACA,SAASC,IAAIA,CAACC,IAAY,EAAEC,GAA2B,EAAQ;EAC7D,IAAI;IACF,IAAIH,MAAM,EAAE;MACVG,GAAG,CAACH,MAAM,CAAC;IACb,CAAC,MAAM;MACLI,OAAO,CAACC,IAAI,CACV,eAAeH,IAAI,wFACrB,CAAC;IACH;EACF,CAAC,CAAC,OAAOI,CAAC,EAAE;IACVF,OAAO,CAACC,IAAI,CAAC,eAAeH,IAAI,YAAYK,MAAM,CAACD,CAAC,CAAC,EAAE,CAAC;EAC1D;AACF;;AAEA;AACA,MAAME,QAAQ,GAAG,uBAAuB;AAIxC;AACA,MAAMC,aAA4D,GAAG,CAAC,CAAC;;AAEvE;AACA,SAASC,UAAUA,CACjBC,KAAQ,EACRC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TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ initialize(sdkKey: string, baseUrl: string | null): void;
4
+ initializeWithAppGroup(sdkKey: string, baseUrl: string | null, appGroup: string): void;
5
+ handleLiveActivityURL(url: string): Promise<string | null>;
6
+ setPushToken(token: string | null): void;
7
+ setExternalUserId(id: string | null): void;
8
+ setAttributes(attributes: CodegenTypes.UnsafeObject): void;
9
+ setTopics(topics: string[]): void;
10
+ logout(): void;
11
+ forget(): void;
12
+ showInApp(name: string): Promise<boolean>;
13
+ markView(viewTag: number, name: string): void;
14
+ unmarkView(name: string): void;
15
+ setLinkHandlerEnabled(enabled: boolean): void;
16
+ setTapHandlerEnabled(enabled: boolean): void;
17
+ addListener(eventName: string): void;
18
+ removeListeners(count: number): void;
19
+ }
20
+ declare const _default: Spec | null | undefined;
21
+ export default _default;
22
+ //# sourceMappingURL=NativePushPilot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativePushPilot.d.ts","sourceRoot":"","sources":["../../../src/NativePushPilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,IAAK,SAAQ,WAAW;IAEvC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAEzD,sBAAsB,CACpB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,QAAQ,EAAE,MAAM,GACf,IAAI,CAAC;IAER,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC3D,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACzC,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAC3C,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3D,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAClC,MAAM,IAAI,IAAI,CAAC;IACf,MAAM,IAAI,IAAI,CAAC;IAEf,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1C,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9C,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAE7C,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;;AAGD,wBAA0D"}
@@ -0,0 +1,82 @@
1
+ import type { RefObject } from 'react';
2
+ /** A custom attribute value; `null` removes the attribute. Pass dates as RFC 3339 strings. */
3
+ export type AttributeValue = string | number | boolean | null;
4
+ /** A tapped PushPilot push that opened the app. */
5
+ export interface TappedNotification {
6
+ /** PushPilot's id for the notification, the same one its events carry. */
7
+ notificationId: string;
8
+ /** The push's custom data; empty when it had none. */
9
+ data: Record<string, string>;
10
+ }
11
+ /** Options for `PushPilot.init`. */
12
+ export interface InitOptions {
13
+ /** Your own server, for self-hosted PushPilot. Defaults to https://pushpilot.ai. */
14
+ baseUrl?: string;
15
+ /**
16
+ * iOS: the App Group shared with your Widget Extension, so images in live activity layouts can be
17
+ * shown. Pass the same id to `PushPilotLiveActivityWidget(appGroup:)`. Ignored on Android.
18
+ */
19
+ appGroup?: string;
20
+ }
21
+ declare const PushPilot: {
22
+ /** Starts the SDK with the app's public SDK key. Later calls are ignored; earlier calls are queued. */
23
+ init(sdkKey: string, options?: InitOptions): void;
24
+ /**
25
+ * Pass every URL your app is opened with (React Native's `Linking`). For a tap on an iOS live
26
+ * activity it records the click once and resolves to the activity's own link without PushPilot's
27
+ * marker, or `null` when the activity has none (just show the app). Any other URL, and every URL on
28
+ * Android, resolves unchanged. Never rejects: on a failure it resolves to the URL as given.
29
+ */
30
+ handleLiveActivityURL(url: string): Promise<string | null>;
31
+ /**
32
+ * Passes the push identifier; `null` clears it.
33
+ * - Android: the Firebase Installation ID from `register` / `onRegistered` where your Firebase
34
+ * library has it, otherwise the FCM token from `getToken` / `onTokenRefresh`. Pass only one kind.
35
+ * (Not PushPilot's own installation id.)
36
+ * - iOS: the APNs device token as hex, e.g. from expo-notifications' `getDevicePushTokenAsync()` or
37
+ * React Native Firebase's `getAPNSToken()`. Not needed when your AppDelegate forwards the token
38
+ * natively. Anything else (an FCM token or FID, the 1.x iOS path) is ignored with a warning.
39
+ */
40
+ setPushToken(token: string | null): void;
41
+ /** Links this installation to your own user id after login; `null` clears it. */
42
+ setExternalUserId(id: string | null): void;
43
+ /** Merges custom attributes declared in the dashboard. */
44
+ setAttributes(attributes: Record<string, AttributeValue>): void;
45
+ /** Replaces this installation's topic list. */
46
+ setTopics(topics: string[]): void;
47
+ /** Clears the external user id; the device stays registered and keeps receiving pushes. */
48
+ logout(): void;
49
+ /** Deletes this installation from PushPilot and clears all local SDK state. */
50
+ forget(): void;
51
+ /**
52
+ * Receives the link of each tapped PushPilot push (the button's link, or the push's own) instead of
53
+ * the system opening it, like the native SDKs' `setLinkHandler`; `null` lets the system open links
54
+ * again. Set it before `init` to also get the tap that launched the app; each link arrives once.
55
+ */
56
+ setLinkHandler(handler: ((url: string) => void) | null): void;
57
+ /**
58
+ * Receives the id and custom data of each tapped PushPilot push that opens the app; `null` stops it.
59
+ * Set it before `init` to also get the tap that launched the app; each tap arrives once.
60
+ */
61
+ setTapHandler(handler: ((tap: TappedNotification) => void) | null): void;
62
+ /**
63
+ * Shows the first eligible cached in-app message whose trigger name is `name` and resolves to whether
64
+ * one is now on screen: `false` when none is cached and eligible, another message is showing, or the
65
+ * SDK has not started. No network call. Never rejects: on a failure it resolves to `false`.
66
+ */
67
+ showInApp(name: string): Promise<boolean>;
68
+ /**
69
+ * Names a mounted view for coach-mark messages whose target is `name`: pass its `ref` (or a view tag
70
+ * from `findNodeHandle`). Give a plain `<View>` `collapsable={false}` so it has a native view. The SDK
71
+ * holds the view weakly; a later view with the same name replaces it.
72
+ */
73
+ markView(ref: RefObject<any> | number, name: string): void;
74
+ /** Forgets the view marked with `name`. */
75
+ unmarkView(name: string): void;
76
+ /** True when a received push's data came from PushPilot. Same rule as the native SDKs; no native call. */
77
+ handleMessage(data: {
78
+ [key: string]: unknown;
79
+ } | null | undefined): boolean;
80
+ };
81
+ export default PushPilot;
82
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AASvC,8FAA8F;AAC9F,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE9D,mDAAmD;AACnD,MAAM,WAAW,kBAAkB;IACjC,0EAA0E;IAC1E,cAAc,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC1B,oFAAoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAwCD,QAAA,MAAM,SAAS;IACb,uGAAuG;iBAC1F,MAAM,YAAY,WAAW,GAAG,IAAI;IAUjD;;;;;OAKG;+BAC8B,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAYhE;;;;;;;;OAQG;wBACiB,MAAM,GAAG,IAAI,GAAG,IAAI;IAUxC,iFAAiF;0BAC3D,MAAM,GAAG,IAAI,GAAG,IAAI;IAI1C,0DAA0D;8BAChC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,IAAI;IAI/D,+CAA+C;sBAC7B,MAAM,EAAE,GAAG,IAAI;IAIjC,2FAA2F;cACjF,IAAI;IAId,+EAA+E;cACrE,IAAI;IAId;;;;OAIG;4BACqB,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI;IAM7D;;;OAGG;2BACoB,CAAC,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI;IAIxE;;;;OAIG;oBACmB,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAY/C;;;;OAIG;kBAEW,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,QAAQ,MAAM,GAAG,IAAI;IAW1D,2CAA2C;qBAC1B,MAAM,GAAG,IAAI;IAI9B,0GAA0G;wBACtF;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO;CAG5E,CAAC;AAEF,eAAe,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,149 @@
1
1
  {
2
2
  "name": "@pushpilotai/react-native",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.2.0",
4
+ "description": "PushPilot push notifications for React Native",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "pushpilot-react-native-source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/src/test",
26
+ "!android/gradle",
27
+ "!android/gradlew",
28
+ "!android/gradlew.bat",
29
+ "!android/local.properties",
30
+ "!**/__tests__",
31
+ "!**/__fixtures__",
32
+ "!**/__mocks__",
33
+ "!**/.*"
34
+ ],
35
+ "scripts": {
36
+ "example": "yarn workspace @pushpilotai/react-native-example",
37
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
38
+ "prepare": "bob build",
39
+ "typecheck": "tsc",
40
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
41
+ "test": "jest",
42
+ "test:ios": "swiftc -o \"${TMPDIR:-/tmp}/pushpilot-token-test\" ios/RNPushPilotToken.swift test/ios/main.swift && \"${TMPDIR:-/tmp}/pushpilot-token-test\""
43
+ },
44
+ "keywords": [
45
+ "react-native",
46
+ "ios",
47
+ "android",
48
+ "push-notifications",
49
+ "pushpilot"
50
+ ],
51
+ "author": "PushPilot <sdk@pushpilot.ai> (https://pushpilot.ai)",
52
+ "license": "Apache-2.0",
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/pushpilotai/pushpilot-react-native.git"
56
+ },
57
+ "bugs": {
58
+ "url": "https://github.com/pushpilotai/pushpilot-react-native/issues"
59
+ },
60
+ "homepage": "https://pushpilot.ai",
61
+ "publishConfig": {
62
+ "registry": "https://registry.npmjs.org/",
63
+ "access": "public"
64
+ },
65
+ "devDependencies": {
66
+ "@eslint/compat": "^2.1.1",
67
+ "@eslint/eslintrc": "^3.3.7",
68
+ "@eslint/js": "^9.39.5",
69
+ "@react-native/babel-preset": "0.88.0",
70
+ "@react-native/eslint-config": "0.88.0",
71
+ "@react-native/jest-preset": "0.88.0",
72
+ "@types/jest": "^29.5.14",
73
+ "@types/react": "^19.2.0",
74
+ "del-cli": "^8.0.1",
75
+ "eslint": "^9.39.5",
76
+ "eslint-config-prettier": "^10.1.8",
77
+ "eslint-plugin-ft-flow": "^3.0.11",
78
+ "eslint-plugin-prettier": "^5.5.7",
79
+ "jest": "^29.7.0",
80
+ "prettier": "^3.9.10",
81
+ "react": "19.3.0",
82
+ "react-native": "0.88.0",
83
+ "react-native-builder-bob": "^0.44.1",
84
+ "turbo": "^2.11.10",
85
+ "typescript": "^6.0.3"
86
+ },
87
+ "peerDependencies": {
88
+ "react": "*",
89
+ "react-native": "*"
90
+ },
91
+ "workspaces": [
92
+ "example"
93
+ ],
94
+ "packageManager": "yarn@4.18.1",
95
+ "react-native-builder-bob": {
96
+ "source": "src",
97
+ "output": "lib",
98
+ "targets": [
99
+ [
100
+ "module",
101
+ {
102
+ "esm": true
103
+ }
104
+ ],
105
+ [
106
+ "typescript",
107
+ {
108
+ "project": "tsconfig.build.json"
109
+ }
110
+ ]
111
+ ]
112
+ },
113
+ "codegenConfig": {
114
+ "name": "RNPushPilotSpec",
115
+ "type": "modules",
116
+ "jsSrcsDir": "src",
117
+ "android": {
118
+ "javaPackageName": "ai.pushpilot.reactnative"
119
+ },
120
+ "ios": {
121
+ "modulesProvider": {
122
+ "PushPilot": "RNPushPilot"
123
+ }
124
+ }
125
+ },
126
+ "prettier": {
127
+ "quoteProps": "consistent",
128
+ "singleQuote": true,
129
+ "tabWidth": 2,
130
+ "trailingComma": "es5",
131
+ "useTabs": false
132
+ },
133
+ "create-react-native-library": {
134
+ "type": "turbo-module",
135
+ "languages": "kotlin-objc",
136
+ "tools": [
137
+ "eslint",
138
+ "jest"
139
+ ],
140
+ "version": "0.64.0"
141
+ },
142
+ "jest": {
143
+ "preset": "@react-native/jest-preset",
144
+ "modulePathIgnorePatterns": [
145
+ "<rootDir>/example/node_modules",
146
+ "<rootDir>/lib/"
147
+ ]
148
+ }
149
+ }
@@ -0,0 +1,39 @@
1
+ import {
2
+ TurboModuleRegistry,
3
+ type CodegenTypes,
4
+ type TurboModule,
5
+ } from 'react-native';
6
+
7
+ // The native module's shape; codegen turns it into the Kotlin and Objective-C interfaces.
8
+ export interface Spec extends TurboModule {
9
+ // Named `initialize` because Objective-C reserves methods starting with `init`.
10
+ initialize(sdkKey: string, baseUrl: string | null): void;
11
+ // `initialize` plus the App Group shared with the iOS Widget Extension; Android ignores the group.
12
+ initializeWithAppGroup(
13
+ sdkKey: string,
14
+ baseUrl: string | null,
15
+ appGroup: string
16
+ ): void;
17
+ // The link of a live activity tap without PushPilot's marker, or null; other URLs come back unchanged.
18
+ handleLiveActivityURL(url: string): Promise<string | null>;
19
+ setPushToken(token: string | null): void;
20
+ setExternalUserId(id: string | null): void;
21
+ setAttributes(attributes: CodegenTypes.UnsafeObject): void;
22
+ setTopics(topics: string[]): void;
23
+ logout(): void;
24
+ forget(): void;
25
+ // The first eligible cached in-app message with this trigger name; resolves whether it is now on screen.
26
+ showInApp(name: string): Promise<boolean>;
27
+ // Names the native view with this React tag (from findNodeHandle) for coach-mark messages, or forgets one.
28
+ markView(viewTag: number, name: string): void;
29
+ unmarkView(name: string): void;
30
+ // Whether JavaScript has a link handler / tap handler; native sends those events only while it does.
31
+ setLinkHandlerEnabled(enabled: boolean): void;
32
+ setTapHandlerEnabled(enabled: boolean): void;
33
+ // Event-emitter hooks for NativeEventEmitter (events PushPilotLink and PushPilotTap).
34
+ addListener(eventName: string): void;
35
+ removeListeners(count: number): void;
36
+ }
37
+
38
+ // `get`, not `getEnforcing`: a missing native module (Expo Go, not rebuilt) must not throw at import.
39
+ export default TurboModuleRegistry.get<Spec>('PushPilot');