@zapiack/react-native 0.0.0-stage → 0.1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ All notable changes to @zapiack/react-native are listed here. Versions follow [semantic versioning](https://semver.org).
4
+
5
+ ## 0.1.0
6
+
7
+ First release.
8
+
9
+ Push for React Native on iOS and Android, as a thin bridge over the native libraries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zapiack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,82 @@
1
- # Temporary Holding Version
1
+ # @zapiack/react-native
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The one Zapiack package for React Native apps. Push notifications are in it today, and new Zapiack products arrive in the same package.
4
+
5
+ ## Push
6
+
7
+ Registers the device, shows pushes with pictures and buttons, reports taps, and
8
+ follows what the person does next, so you can see which pushes bring people back.
9
+
10
+ Android 5.0+ and iOS 13+, React Native 0.71+. It has native code, so it does not run in Expo Go: use a development build.
11
+
12
+ ```bash
13
+ npm install @zapiack/react-native
14
+ cd ios && pod install
15
+ ```
16
+
17
+ ## Use it
18
+
19
+ ```ts
20
+ import { ZapiackPush } from '@zapiack/react-native';
21
+
22
+ await ZapiackPush.configure({
23
+ appKey: 'pk_…',
24
+ appGroup: 'group.com.example.app', // iOS only: see below
25
+ });
26
+
27
+ // Ask when it makes sense for your users, for example after a tap on a button.
28
+ const allowed = await ZapiackPush.requestPermission();
29
+
30
+ const stop = ZapiackPush.onTap((tap) => {
31
+ // tap.link, tap.actionId (the button), tap.event
32
+ });
33
+ const opened = await ZapiackPush.initialTap(); // the push that started the app, if any
34
+ ```
35
+
36
+ Link a device to your user and group devices with tags:
37
+
38
+ ```ts
39
+ await ZapiackPush.login('user_123');
40
+ await ZapiackPush.logout();
41
+ await ZapiackPush.addTags({ plan: 'pro' });
42
+ ```
43
+
44
+ Follow what happens after a tap. Both are credited to the push only for a short window after it was tapped:
45
+
46
+ ```ts
47
+ await ZapiackPush.screen('OrderDetails');
48
+ await ZapiackPush.track('purchase', { total: 49 });
49
+ ```
50
+
51
+ ## Android
52
+
53
+ Firebase Cloud Messaging has to be set up as in any Android app (`google-services.json` and the Google services plugin). The
54
+ package adds its own Firebase service. If another library also registers one, such as `@react-native-firebase/messaging`, only one
55
+ of them receives a push: call `ZapiackMessagingService.handle` from yours, as described in the Android library's README.
56
+
57
+ ## iOS
58
+
59
+ 1. In Xcode, turn on **Push Notifications** and **Background Modes → Remote notifications** for the app target.
60
+ 2. Add an **App Group** to the app target, and use its name as `appGroup`.
61
+ 3. Add a **Notification Service Extension** target with the same App Group, and make its class a subclass of
62
+ `ZapiackNotificationService` from the Zapiack iOS package (`ZapiackNotificationExtension`). The extension reports that a push
63
+ arrived and shows its picture and buttons. Without it, pushes still show, with no arrival report, picture or buttons.
64
+ 4. React Native does not pass the push address on, so forward it from `AppDelegate`:
65
+
66
+ ```objc
67
+ #import <zapiack_react_native/zapiack_react_native-Swift.h>
68
+
69
+ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
70
+ [ZapiackPushModule didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
71
+ }
72
+ ```
73
+
74
+ ## Maintaining
75
+
76
+ The iOS code in this package is copied from the iOS library: run `npm run sync-ios` after changing it (it also runs before publishing).
77
+
78
+ ## Tests
79
+
80
+ ```
81
+ npm test
82
+ ```
@@ -0,0 +1,48 @@
1
+ def safeExtGet(prop, fallback) {
2
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
3
+ }
4
+
5
+ buildscript {
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+ dependencies {
11
+ classpath "com.android.tools.build:gradle:8.9.1"
12
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.20"
13
+ }
14
+ }
15
+
16
+ apply plugin: "com.android.library"
17
+ apply plugin: "kotlin-android"
18
+
19
+ android {
20
+ namespace "com.zapiack.reactnative"
21
+ compileSdk safeExtGet("compileSdkVersion", 35)
22
+
23
+ defaultConfig {
24
+ minSdk safeExtGet("minSdkVersion", 24)
25
+ }
26
+
27
+ compileOptions {
28
+ sourceCompatibility JavaVersion.VERSION_17
29
+ targetCompatibility JavaVersion.VERSION_17
30
+ }
31
+
32
+ kotlinOptions {
33
+ jvmTarget = "17"
34
+ }
35
+ }
36
+
37
+ repositories {
38
+ google()
39
+ mavenCentral()
40
+ // Only until the Android library is on Maven Central.
41
+ mavenLocal()
42
+ }
43
+
44
+ dependencies {
45
+ // The version comes from the app's React Native Gradle plugin.
46
+ implementation "com.facebook.react:react-android"
47
+ api "com.zapiack:zapiack-android:0.1.0"
48
+ }
@@ -0,0 +1 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" />
@@ -0,0 +1,110 @@
1
+ package com.zapiack.reactnative
2
+
3
+ import android.Manifest
4
+ import android.content.Intent
5
+ import android.content.pm.PackageManager
6
+ import android.os.Build
7
+ import com.facebook.react.bridge.ActivityEventListener
8
+ import com.facebook.react.bridge.Arguments
9
+ import com.facebook.react.bridge.Promise
10
+ import com.facebook.react.bridge.ReactApplicationContext
11
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
12
+ import com.facebook.react.bridge.ReactMethod
13
+ import com.facebook.react.bridge.ReadableMap
14
+ import com.facebook.react.bridge.ReadableArray
15
+ import com.facebook.react.bridge.WritableMap
16
+ import com.facebook.react.modules.core.DeviceEventManagerModule
17
+ import com.facebook.react.modules.core.PermissionAwareActivity
18
+ import com.facebook.react.modules.core.PermissionListener
19
+ import com.zapiack.push.ZapiackPush
20
+ import com.zapiack.push.core.Tap
21
+
22
+ /** Connects the JavaScript API to the Android library. */
23
+ class ZapiackPushModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext), ActivityEventListener {
24
+ init {
25
+ reactContext.addActivityEventListener(this)
26
+ }
27
+
28
+ override fun getName() = "ZapiackPush"
29
+
30
+ @ReactMethod
31
+ fun configure(options: ReadableMap, promise: Promise) {
32
+ val key = options.getString("appKey")
33
+ if (key == null || !key.startsWith("pk_")) return promise.reject("invalid_key", "The app key must start with pk_")
34
+ val base = if (options.hasKey("baseUrl")) options.getString("baseUrl") else null
35
+ if (base != null) ZapiackPush.configure(reactContext.applicationContext, key, base) else ZapiackPush.configure(reactContext.applicationContext, key)
36
+ promise.resolve(null)
37
+ }
38
+
39
+ @ReactMethod
40
+ fun requestPermission(promise: Promise) {
41
+ val context = reactContext.applicationContext
42
+ if (ZapiackPush.hasPermission(context)) {
43
+ promise.resolve(true)
44
+ return
45
+ }
46
+ val activity = reactContext.currentActivity
47
+ if (Build.VERSION.SDK_INT < 33 || activity !is PermissionAwareActivity) {
48
+ // Before Android 13 there is nothing to ask; without a React activity there is nobody to ask on.
49
+ promise.resolve(false)
50
+ return
51
+ }
52
+ // The answer has to come back through React's own activity, which is why the library's `requestPermission` is not used here.
53
+ activity.requestPermissions(arrayOf(Manifest.permission.POST_NOTIFICATIONS), REQUEST_CODE, PermissionListener { code, _, results ->
54
+ if (code != REQUEST_CODE) return@PermissionListener false
55
+ ZapiackPush.onPermissionResult(code)
56
+ promise.resolve(results.isNotEmpty() && results[0] == PackageManager.PERMISSION_GRANTED)
57
+ true
58
+ })
59
+ }
60
+
61
+ @ReactMethod fun installationId(promise: Promise) = promise.resolve(ZapiackPush.installationId)
62
+
63
+ @ReactMethod fun login(userId: String, promise: Promise) { ZapiackPush.login(userId); promise.resolve(null) }
64
+
65
+ @ReactMethod fun logout(promise: Promise) { ZapiackPush.logout(); promise.resolve(null) }
66
+
67
+ @ReactMethod fun addTags(tags: ReadableMap, promise: Promise) { ZapiackPush.addTags(tags.toHashMap()); promise.resolve(null) }
68
+
69
+ @ReactMethod fun removeTags(keys: ReadableArray, promise: Promise) { ZapiackPush.removeTags(keys.toArrayList().map { it.toString() }); promise.resolve(null) }
70
+
71
+ @ReactMethod fun screen(name: String, promise: Promise) { ZapiackPush.screen(name); promise.resolve(null) }
72
+
73
+ @ReactMethod
74
+ fun track(name: String, properties: ReadableMap?, promise: Promise) {
75
+ promise.resolve(ZapiackPush.track(name, properties?.toHashMap()))
76
+ }
77
+
78
+ @ReactMethod fun flush(promise: Promise) { ZapiackPush.flush(); promise.resolve(null) }
79
+
80
+ /** The tap that opened the app. The library takes a tap out of the intent when it handles it, so a second call finds nothing. */
81
+ @ReactMethod
82
+ fun initialTap(promise: Promise) {
83
+ promise.resolve(ZapiackPush.handleIntent(reactContext.currentActivity?.intent)?.toMap())
84
+ }
85
+
86
+ // Required by NativeEventEmitter.
87
+ @ReactMethod fun addListener(eventName: String) = Unit
88
+ @ReactMethod fun removeListeners(count: Int) = Unit
89
+
90
+ override fun onNewIntent(intent: Intent) {
91
+ val tap = ZapiackPush.handleIntent(intent) ?: return
92
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(TAP_EVENT, tap.toMap())
93
+ }
94
+
95
+ override fun onActivityResult(activity: android.app.Activity, requestCode: Int, resultCode: Int, data: Intent?) = Unit
96
+
97
+ private fun Tap.toMap(): WritableMap = Arguments.createMap().apply {
98
+ putString("messageId", messageId)
99
+ putString("deliveryId", deliveryId)
100
+ putString("sessionId", sessionId)
101
+ putString("actionId", actionId)
102
+ putString("event", event)
103
+ putString("link", link)
104
+ }
105
+
106
+ companion object {
107
+ private const val REQUEST_CODE = 7391
108
+ private const val TAP_EVENT = "zapiackTap"
109
+ }
110
+ }
@@ -0,0 +1,12 @@
1
+ package com.zapiack.reactnative
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+ class ZapiackPushPackage : ReactPackage {
9
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> = listOf(ZapiackPushModule(reactContext))
10
+
11
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> = emptyList()
12
+ }
@@ -0,0 +1,53 @@
1
+ /** What was tapped, handed to the app so it can route. */
2
+ interface ZapiackTap {
3
+ messageId: string;
4
+ deliveryId: string;
5
+ sessionId: string;
6
+ /** The button that was tapped, when it was a button. */
7
+ actionId?: string | null;
8
+ /** The event name set on the notification or the button. */
9
+ event?: string | null;
10
+ /** Where the notification or the button asked to go. Only links an app can route are given. */
11
+ link?: string | null;
12
+ }
13
+ interface ConfigureOptions {
14
+ /** The public app key, which starts with `pk_`. */
15
+ appKey: string;
16
+ /** Defaults to https://api.zapiack.com/v1 */
17
+ baseUrl?: string;
18
+ /** iOS only: the App Group shared with the notification extension, for example `group.com.example.app`. */
19
+ appGroup?: string;
20
+ }
21
+ type TagValue = string | number | boolean | null;
22
+ /** Thrown when the SDK is used wrongly, for example with a secret key. */
23
+ declare class ZapiackError extends Error {
24
+ constructor(message: string);
25
+ }
26
+ declare const ZapiackPush: {
27
+ /** Call once at start-up, before anything else. */
28
+ configure(options: ConfigureOptions): Promise<void>;
29
+ /** Shows the system permission prompt where there is one, registers for push, and says whether notifications are allowed. */
30
+ requestPermission(): Promise<boolean>;
31
+ /** The identifier that ties this install to the service, once `configure` has run. */
32
+ installationId(): Promise<string | null>;
33
+ /** Link this install to the user your server knows. Send to `externalUserIds` from your server to reach them. */
34
+ login(userId: string): Promise<void>;
35
+ /** Unlink this install from the user, on sign-out. */
36
+ logout(): Promise<void>;
37
+ /** Add or change tags; send to `tags` from your server to reach everyone who has them. */
38
+ addTags(tags: Record<string, TagValue>): Promise<void>;
39
+ removeTags(keys: string[]): Promise<void>;
40
+ /** A screen the user reached, credited to the push they tapped while its window is open. */
41
+ screen(name: string): Promise<void>;
42
+ /** A named goal or event, credited to the push they tapped while its window is open. Resolves false when there is nothing to credit. */
43
+ track(name: string, properties?: Record<string, unknown>): Promise<boolean>;
44
+ /** Sends anything waiting. Call when the app comes to the foreground. */
45
+ flush(): Promise<void>;
46
+ /** Notifications tapped while the app is running. Returns a function that stops listening. */
47
+ onTap(listener: (tap: ZapiackTap) => void): () => void;
48
+ /** The notification that opened the app, if it was opened by tapping one. Resolves it once. */
49
+ initialTap(): Promise<ZapiackTap | null>;
50
+ };
51
+
52
+ export { ZapiackError, ZapiackPush, ZapiackPush as default };
53
+ export type { ConfigureOptions, TagValue, ZapiackTap };
@@ -0,0 +1,53 @@
1
+ /** What was tapped, handed to the app so it can route. */
2
+ interface ZapiackTap {
3
+ messageId: string;
4
+ deliveryId: string;
5
+ sessionId: string;
6
+ /** The button that was tapped, when it was a button. */
7
+ actionId?: string | null;
8
+ /** The event name set on the notification or the button. */
9
+ event?: string | null;
10
+ /** Where the notification or the button asked to go. Only links an app can route are given. */
11
+ link?: string | null;
12
+ }
13
+ interface ConfigureOptions {
14
+ /** The public app key, which starts with `pk_`. */
15
+ appKey: string;
16
+ /** Defaults to https://api.zapiack.com/v1 */
17
+ baseUrl?: string;
18
+ /** iOS only: the App Group shared with the notification extension, for example `group.com.example.app`. */
19
+ appGroup?: string;
20
+ }
21
+ type TagValue = string | number | boolean | null;
22
+ /** Thrown when the SDK is used wrongly, for example with a secret key. */
23
+ declare class ZapiackError extends Error {
24
+ constructor(message: string);
25
+ }
26
+ declare const ZapiackPush: {
27
+ /** Call once at start-up, before anything else. */
28
+ configure(options: ConfigureOptions): Promise<void>;
29
+ /** Shows the system permission prompt where there is one, registers for push, and says whether notifications are allowed. */
30
+ requestPermission(): Promise<boolean>;
31
+ /** The identifier that ties this install to the service, once `configure` has run. */
32
+ installationId(): Promise<string | null>;
33
+ /** Link this install to the user your server knows. Send to `externalUserIds` from your server to reach them. */
34
+ login(userId: string): Promise<void>;
35
+ /** Unlink this install from the user, on sign-out. */
36
+ logout(): Promise<void>;
37
+ /** Add or change tags; send to `tags` from your server to reach everyone who has them. */
38
+ addTags(tags: Record<string, TagValue>): Promise<void>;
39
+ removeTags(keys: string[]): Promise<void>;
40
+ /** A screen the user reached, credited to the push they tapped while its window is open. */
41
+ screen(name: string): Promise<void>;
42
+ /** A named goal or event, credited to the push they tapped while its window is open. Resolves false when there is nothing to credit. */
43
+ track(name: string, properties?: Record<string, unknown>): Promise<boolean>;
44
+ /** Sends anything waiting. Call when the app comes to the foreground. */
45
+ flush(): Promise<void>;
46
+ /** Notifications tapped while the app is running. Returns a function that stops listening. */
47
+ onTap(listener: (tap: ZapiackTap) => void): () => void;
48
+ /** The notification that opened the app, if it was opened by tapping one. Resolves it once. */
49
+ initialTap(): Promise<ZapiackTap | null>;
50
+ };
51
+
52
+ export { ZapiackError, ZapiackPush, ZapiackPush as default };
53
+ export type { ConfigureOptions, TagValue, ZapiackTap };
package/dist/index.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ZapiackError: () => ZapiackError,
24
+ ZapiackPush: () => ZapiackPush,
25
+ default: () => index_default
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ var import_react_native = require("react-native");
29
+ var ZapiackError = class extends Error {
30
+ constructor(message) {
31
+ super(message);
32
+ this.name = "ZapiackError";
33
+ }
34
+ };
35
+ var TAP_EVENT = "zapiackTap";
36
+ function native() {
37
+ const module2 = import_react_native.NativeModules.ZapiackPush;
38
+ if (!module2) {
39
+ throw new ZapiackError(
40
+ "The native part of @zapiack/react-native is not linked. Rebuild the app (pod install on iOS, a clean Gradle build on Android), and note that Expo Go cannot run it: use a development build."
41
+ );
42
+ }
43
+ return module2;
44
+ }
45
+ var emitter;
46
+ var ZapiackPush = {
47
+ /** Call once at start-up, before anything else. */
48
+ configure(options) {
49
+ if (!options.appKey.startsWith("pk_")) throw new ZapiackError("ZapiackPush needs the public app key, which starts with pk_");
50
+ if (import_react_native.Platform.OS === "ios" && !options.appGroup) {
51
+ throw new ZapiackError("On iOS, appGroup is required: it is how the app and its notification extension share what they need");
52
+ }
53
+ return native().configure({ appKey: options.appKey, baseUrl: options.baseUrl ?? null, appGroup: options.appGroup ?? null });
54
+ },
55
+ /** Shows the system permission prompt where there is one, registers for push, and says whether notifications are allowed. */
56
+ async requestPermission() {
57
+ return await native().requestPermission() === true;
58
+ },
59
+ /** The identifier that ties this install to the service, once `configure` has run. */
60
+ installationId() {
61
+ return native().installationId();
62
+ },
63
+ /** Link this install to the user your server knows. Send to `externalUserIds` from your server to reach them. */
64
+ login(userId) {
65
+ return native().login(userId);
66
+ },
67
+ /** Unlink this install from the user, on sign-out. */
68
+ logout() {
69
+ return native().logout();
70
+ },
71
+ /** Add or change tags; send to `tags` from your server to reach everyone who has them. */
72
+ addTags(tags) {
73
+ return native().addTags(tags);
74
+ },
75
+ removeTags(keys) {
76
+ return native().removeTags(keys);
77
+ },
78
+ /** A screen the user reached, credited to the push they tapped while its window is open. */
79
+ screen(name) {
80
+ return native().screen(name);
81
+ },
82
+ /** A named goal or event, credited to the push they tapped while its window is open. Resolves false when there is nothing to credit. */
83
+ async track(name, properties) {
84
+ return await native().track(name, properties ?? null) === true;
85
+ },
86
+ /** Sends anything waiting. Call when the app comes to the foreground. */
87
+ flush() {
88
+ return native().flush();
89
+ },
90
+ /** Notifications tapped while the app is running. Returns a function that stops listening. */
91
+ onTap(listener) {
92
+ const module2 = native();
93
+ emitter ?? (emitter = new import_react_native.NativeEventEmitter(module2));
94
+ const subscription = emitter.addListener(TAP_EVENT, listener);
95
+ return () => subscription.remove();
96
+ },
97
+ /** The notification that opened the app, if it was opened by tapping one. Resolves it once. */
98
+ initialTap() {
99
+ return native().initialTap();
100
+ }
101
+ };
102
+ var index_default = ZapiackPush;
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ ZapiackError,
106
+ ZapiackPush
107
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,81 @@
1
+ // src/index.ts
2
+ import { NativeEventEmitter, NativeModules, Platform } from "react-native";
3
+ var ZapiackError = class extends Error {
4
+ constructor(message) {
5
+ super(message);
6
+ this.name = "ZapiackError";
7
+ }
8
+ };
9
+ var TAP_EVENT = "zapiackTap";
10
+ function native() {
11
+ const module = NativeModules.ZapiackPush;
12
+ if (!module) {
13
+ throw new ZapiackError(
14
+ "The native part of @zapiack/react-native is not linked. Rebuild the app (pod install on iOS, a clean Gradle build on Android), and note that Expo Go cannot run it: use a development build."
15
+ );
16
+ }
17
+ return module;
18
+ }
19
+ var emitter;
20
+ var ZapiackPush = {
21
+ /** Call once at start-up, before anything else. */
22
+ configure(options) {
23
+ if (!options.appKey.startsWith("pk_")) throw new ZapiackError("ZapiackPush needs the public app key, which starts with pk_");
24
+ if (Platform.OS === "ios" && !options.appGroup) {
25
+ throw new ZapiackError("On iOS, appGroup is required: it is how the app and its notification extension share what they need");
26
+ }
27
+ return native().configure({ appKey: options.appKey, baseUrl: options.baseUrl ?? null, appGroup: options.appGroup ?? null });
28
+ },
29
+ /** Shows the system permission prompt where there is one, registers for push, and says whether notifications are allowed. */
30
+ async requestPermission() {
31
+ return await native().requestPermission() === true;
32
+ },
33
+ /** The identifier that ties this install to the service, once `configure` has run. */
34
+ installationId() {
35
+ return native().installationId();
36
+ },
37
+ /** Link this install to the user your server knows. Send to `externalUserIds` from your server to reach them. */
38
+ login(userId) {
39
+ return native().login(userId);
40
+ },
41
+ /** Unlink this install from the user, on sign-out. */
42
+ logout() {
43
+ return native().logout();
44
+ },
45
+ /** Add or change tags; send to `tags` from your server to reach everyone who has them. */
46
+ addTags(tags) {
47
+ return native().addTags(tags);
48
+ },
49
+ removeTags(keys) {
50
+ return native().removeTags(keys);
51
+ },
52
+ /** A screen the user reached, credited to the push they tapped while its window is open. */
53
+ screen(name) {
54
+ return native().screen(name);
55
+ },
56
+ /** A named goal or event, credited to the push they tapped while its window is open. Resolves false when there is nothing to credit. */
57
+ async track(name, properties) {
58
+ return await native().track(name, properties ?? null) === true;
59
+ },
60
+ /** Sends anything waiting. Call when the app comes to the foreground. */
61
+ flush() {
62
+ return native().flush();
63
+ },
64
+ /** Notifications tapped while the app is running. Returns a function that stops listening. */
65
+ onTap(listener) {
66
+ const module = native();
67
+ emitter ?? (emitter = new NativeEventEmitter(module));
68
+ const subscription = emitter.addListener(TAP_EVENT, listener);
69
+ return () => subscription.remove();
70
+ },
71
+ /** The notification that opened the app, if it was opened by tapping one. Resolves it once. */
72
+ initialTap() {
73
+ return native().initialTap();
74
+ }
75
+ };
76
+ var index_default = ZapiackPush;
77
+ export {
78
+ ZapiackError,
79
+ ZapiackPush,
80
+ index_default as default
81
+ };