@zapiack/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.
package/dist/index.js ADDED
@@ -0,0 +1,490 @@
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 src_exports = {};
22
+ __export(src_exports, {
23
+ DEFAULT_REALTIME_URL: () => DEFAULT_REALTIME_URL,
24
+ ZapiackError: () => ZapiackError,
25
+ ZapiackPush: () => ZapiackPush,
26
+ ZapiackRealtime: () => ZapiackRealtime,
27
+ ZapiackRealtimeError: () => ZapiackRealtimeError,
28
+ browserRealtimeEnv: () => browserRealtimeEnv,
29
+ default: () => src_default
30
+ });
31
+ module.exports = __toCommonJS(src_exports);
32
+ var import_react_native = require("react-native");
33
+
34
+ // src/realtime.ts
35
+ var ZapiackRealtimeError = class extends Error {
36
+ constructor(message, code = 0, reason) {
37
+ super(message);
38
+ this.code = code;
39
+ this.reason = reason;
40
+ this.name = "ZapiackRealtimeError";
41
+ }
42
+ };
43
+ var DEFAULT_REALTIME_URL = "wss://rt.zapiack.com";
44
+ var OPEN = 1;
45
+ var MAX_OUTBOX = 100;
46
+ var browserRealtimeEnv = () => ({
47
+ socket: (url) => new globalThis.WebSocket(url),
48
+ setTimeout: (fn, ms) => setTimeout(fn, ms),
49
+ clearTimeout: (id) => clearTimeout(id),
50
+ setInterval: (fn, ms) => setInterval(fn, ms),
51
+ clearInterval: (id) => clearInterval(id),
52
+ random: () => Math.random()
53
+ });
54
+ var after = (a, b) => {
55
+ if (!b) return true;
56
+ const [am = 0, as = 0] = a.split("-").map(Number);
57
+ const [bm = 0, bs = 0] = b.split("-").map(Number);
58
+ return am > bm || am === bm && as > bs;
59
+ };
60
+ var ZapiackRealtime = class {
61
+ constructor(options, env = browserRealtimeEnv(), now = Date.now) {
62
+ this.env = env;
63
+ this.now = now;
64
+ this.ws = null;
65
+ this._state = "idle";
66
+ this.subs = /* @__PURE__ */ new Map();
67
+ this.presenceHandlers = /* @__PURE__ */ new Map();
68
+ this.members = /* @__PURE__ */ new Map();
69
+ this.waiting = /* @__PURE__ */ new Map();
70
+ this.pending = /* @__PURE__ */ new Map();
71
+ this.rpcSeq = 0;
72
+ this.stateHandlers = /* @__PURE__ */ new Set();
73
+ this.errorHandlers = /* @__PURE__ */ new Set();
74
+ this.outbox = [];
75
+ this.attempt = 0;
76
+ this.wanted = false;
77
+ this.heard = 0;
78
+ this.ackSeq = 0;
79
+ this.first = null;
80
+ /** Set by an error the server marks fatal, for runtimes that cannot see a custom close code. */
81
+ this.refused = false;
82
+ this._connId = null;
83
+ if (typeof options?.getToken !== "function") throw new ZapiackRealtimeError("getToken is required: a function that asks your server for a token.");
84
+ this.o = { url: DEFAULT_REALTIME_URL, heartbeatMs: 25e3, backoffMs: { min: 1e3, max: 3e4 }, ackTimeoutMs: 1e4, ...options };
85
+ }
86
+ get state() {
87
+ return this._state;
88
+ }
89
+ /** This connection's id, once connected. Other members use it to signal you. */
90
+ get connectionId() {
91
+ return this._connId;
92
+ }
93
+ onState(fn) {
94
+ this.stateHandlers.add(fn);
95
+ return () => this.stateHandlers.delete(fn);
96
+ }
97
+ onError(fn) {
98
+ this.errorHandlers.add(fn);
99
+ return () => this.errorHandlers.delete(fn);
100
+ }
101
+ /** Connects and resolves once the server has said hello. It keeps itself connected afterwards until `disconnect()`. */
102
+ connect() {
103
+ if (this._state === "connected") return Promise.resolve();
104
+ if (this.first) return new Promise((resolve, reject) => this.chain(resolve, reject));
105
+ this.wanted = true;
106
+ return new Promise((resolve, reject) => {
107
+ this.first = { resolve, reject };
108
+ void this.open();
109
+ });
110
+ }
111
+ chain(resolve, reject) {
112
+ const f = this.first;
113
+ this.first = {
114
+ resolve: () => {
115
+ f.resolve();
116
+ resolve();
117
+ },
118
+ reject: (e) => {
119
+ f.reject(e);
120
+ reject(e);
121
+ }
122
+ };
123
+ }
124
+ /** Leaves for good: closes the socket, forgets the pending sends. Subscriptions stay, for a later `connect()`. */
125
+ disconnect() {
126
+ this.wanted = false;
127
+ this.env.clearTimeout(this.retry);
128
+ this.stopBeat();
129
+ const ws = this.ws;
130
+ this.ws = null;
131
+ ws?.close(1e3, "bye");
132
+ this.failAll(new ZapiackRealtimeError("Disconnected."));
133
+ this.outbox = [];
134
+ this.set("closed");
135
+ }
136
+ /** Calls `handler` for every message on the channel, now and after reconnects. Returns how to stop. */
137
+ subscribe(channel, handler, options = {}) {
138
+ let sub = this.subs.get(channel);
139
+ const fresh = !sub;
140
+ if (!sub) this.subs.set(channel, sub = { handlers: /* @__PURE__ */ new Set(), cursor: options.resumeFrom });
141
+ sub.handlers.add(handler);
142
+ if (fresh) this.send({ op: "subscribe", channel, resumeFrom: sub.cursor });
143
+ return () => {
144
+ const s = this.subs.get(channel);
145
+ if (!s) return;
146
+ s.handlers.delete(handler);
147
+ if (s.handlers.size === 0) {
148
+ this.subs.delete(channel);
149
+ this.presenceHandlers.delete(channel);
150
+ this.members.delete(channel);
151
+ this.send({ op: "unsubscribe", channel });
152
+ }
153
+ };
154
+ }
155
+ /** Sends a message. Resolves when the server confirms, unless `ack: false`. */
156
+ publish(channel, data, options = {}) {
157
+ const frame = { op: "publish", channel, event: options.event ?? "message", data, persist: options.persist === true };
158
+ if (options.ack === false) {
159
+ this.send(frame);
160
+ return Promise.resolve();
161
+ }
162
+ const ackId = `a${++this.ackSeq}`;
163
+ frame["ackId"] = ackId;
164
+ return new Promise((resolve, reject) => {
165
+ const timer = this.env.setTimeout(() => {
166
+ this.waiting.delete(ackId);
167
+ reject(new ZapiackRealtimeError("The server did not confirm in time.", 0));
168
+ }, this.o.ackTimeoutMs);
169
+ this.waiting.set(ackId, { resolve, reject, timer });
170
+ if (!this.send(frame)) {
171
+ this.settle(ackId)?.reject(new ZapiackRealtimeError("Could not send: too many messages waiting for a connection.", 429));
172
+ }
173
+ });
174
+ }
175
+ /**
176
+ * Asks a Zapiack service something over this connection and waits for the answer: the way a call client talks to the media server.
177
+ * Needs a token minted for a call. It is never queued for later: if the line is down it fails at once, because an answer to an old
178
+ * question is worse than none.
179
+ */
180
+ request(method, data = {}) {
181
+ if (!this.ws || this.ws.readyState !== OPEN || this._state !== "connected") return Promise.reject(new ZapiackRealtimeError("Not connected.", 0, "no_route"));
182
+ const correlationId = `r${++this.rpcSeq}`;
183
+ return new Promise((resolve, reject) => {
184
+ const timer = this.env.setTimeout(() => {
185
+ this.pending.delete(correlationId);
186
+ reject(new ZapiackRealtimeError("The server did not answer in time.", 0, "timeout"));
187
+ }, this.o.ackTimeoutMs + 2e3);
188
+ this.pending.set(correlationId, { resolve, reject, timer });
189
+ this.ws.send(JSON.stringify({ op: "rpc", method, correlationId, data }));
190
+ });
191
+ }
192
+ /** Sends to one connection in a channel you are subscribed to. Used for peer-to-peer setup such as WebRTC. */
193
+ signal(channel, to, event, data) {
194
+ this.send({ op: "signal", channel, to, event, data });
195
+ }
196
+ /** Presence in a channel you are subscribed to. */
197
+ presence(channel) {
198
+ return {
199
+ enter: (data = null) => this.send({ op: "presence.enter", channel, data }),
200
+ update: (data) => this.send({ op: "presence.update", channel, data }),
201
+ leave: () => this.send({ op: "presence.leave", channel }),
202
+ /** Who is here now, as last told. */
203
+ members: () => [...this.members.get(channel)?.values() ?? []],
204
+ onChange: (fn) => {
205
+ let set = this.presenceHandlers.get(channel);
206
+ if (!set) this.presenceHandlers.set(channel, set = /* @__PURE__ */ new Set());
207
+ set.add(fn);
208
+ return () => set.delete(fn);
209
+ }
210
+ };
211
+ }
212
+ // ───────────────────────────── internals
213
+ set(s) {
214
+ if (this._state === s) return;
215
+ this._state = s;
216
+ for (const fn of this.stateHandlers) fn(s);
217
+ }
218
+ fail(e) {
219
+ for (const fn of this.errorHandlers) fn(e);
220
+ }
221
+ settle(ackId) {
222
+ const w = this.waiting.get(ackId);
223
+ if (!w) return void 0;
224
+ this.waiting.delete(ackId);
225
+ this.env.clearTimeout(w.timer);
226
+ return w;
227
+ }
228
+ failAll(e) {
229
+ for (const id of [...this.waiting.keys()]) this.settle(id)?.reject(e);
230
+ this.failRequests(e);
231
+ }
232
+ failRequests(e) {
233
+ for (const [id, p] of [...this.pending]) {
234
+ this.pending.delete(id);
235
+ this.env.clearTimeout(p.timer);
236
+ p.reject(e);
237
+ }
238
+ }
239
+ /** Writes now if the line is open, otherwise keeps it (a short while) for when it is. False when there is no room. */
240
+ send(frame) {
241
+ const text = JSON.stringify(frame);
242
+ if (this.ws && this.ws.readyState === OPEN && this._state === "connected") {
243
+ this.ws.send(text);
244
+ return true;
245
+ }
246
+ if (frame["op"] === "subscribe" || frame["op"] === "unsubscribe") return true;
247
+ if (this.outbox.length >= MAX_OUTBOX) return false;
248
+ this.outbox.push(text);
249
+ return true;
250
+ }
251
+ async open() {
252
+ if (!this.wanted) return;
253
+ this.set(this.attempt === 0 && this._state !== "reconnecting" ? "connecting" : "reconnecting");
254
+ let token;
255
+ try {
256
+ token = await this.o.getToken();
257
+ if (!token || typeof token !== "string") throw new Error("getToken returned no token.");
258
+ } catch (e) {
259
+ this.fail(new ZapiackRealtimeError(`Could not get a token: ${e instanceof Error ? e.message : String(e)}`, 0));
260
+ return this.later();
261
+ }
262
+ if (!this.wanted) return;
263
+ let ws;
264
+ try {
265
+ ws = this.env.socket(`${this.o.url.replace(/\/+$/, "")}/?token=${encodeURIComponent(token)}`);
266
+ } catch (e) {
267
+ this.fail(new ZapiackRealtimeError(`Could not open the connection: ${e instanceof Error ? e.message : String(e)}`, 0));
268
+ return this.later();
269
+ }
270
+ this.ws = ws;
271
+ ws.onmessage = (ev) => this.onFrame(ws, ev.data);
272
+ ws.onerror = () => void 0;
273
+ ws.onclose = (ev) => this.onClose(ws, ev?.code ?? 1006);
274
+ }
275
+ onFrame(ws, raw) {
276
+ if (ws !== this.ws) return;
277
+ this.heard = this.now();
278
+ let f;
279
+ try {
280
+ f = JSON.parse(String(raw));
281
+ } catch {
282
+ return;
283
+ }
284
+ switch (f["op"]) {
285
+ case "hello":
286
+ this._connId = f["connId"];
287
+ this.attempt = 0;
288
+ this.set("connected");
289
+ this.rejoin();
290
+ for (const text of this.outbox.splice(0)) ws.send(text);
291
+ this.startBeat(ws);
292
+ this.first?.resolve();
293
+ this.first = null;
294
+ return;
295
+ case "message":
296
+ return this.onMessage(f);
297
+ case "ack": {
298
+ this.settle(f["ackId"])?.resolve({ msgId: f["msgId"], delivered: f["delivered"] ?? 0 });
299
+ return;
300
+ }
301
+ case "rpc.result":
302
+ case "rpc.error": {
303
+ const id = String(f["correlationId"]);
304
+ const p = this.pending.get(id);
305
+ if (!p) return;
306
+ this.pending.delete(id);
307
+ this.env.clearTimeout(p.timer);
308
+ if (f["op"] === "rpc.result") p.resolve(f["data"]);
309
+ else p.reject(new ZapiackRealtimeError(String(f["message"] ?? "The request failed."), 0, String(f["code"] ?? "internal")));
310
+ return;
311
+ }
312
+ case "error": {
313
+ if (f["fatal"] === true) this.refused = true;
314
+ const err = new ZapiackRealtimeError(String(f["message"] ?? "Error"), Number(f["code"] ?? 0));
315
+ const ref = typeof f["ref"] === "string" ? f["ref"] : void 0;
316
+ if (ref && this.settle(ref)?.reject(err)) return;
317
+ return this.fail(err);
318
+ }
319
+ case "presence.members": {
320
+ const map = /* @__PURE__ */ new Map();
321
+ for (const m of f["members"] ?? []) map.set(m.connId, m);
322
+ this.members.set(f["channel"], map);
323
+ return;
324
+ }
325
+ case "resume.failed":
326
+ return this.fail(new ZapiackRealtimeError(`Missed messages on ${f["channel"]} could not be replayed. Reload its history.`, 410));
327
+ }
328
+ }
329
+ onMessage(m) {
330
+ if (m.event.startsWith("presence.")) return this.onPresence(m);
331
+ const sub = this.subs.get(m.channel);
332
+ if (!sub) return;
333
+ if (m.persisted) {
334
+ if (!after(m.msgId, sub.cursor)) return;
335
+ sub.cursor = m.msgId;
336
+ }
337
+ for (const h of [...sub.handlers]) {
338
+ try {
339
+ h(m);
340
+ } catch {
341
+ }
342
+ }
343
+ }
344
+ onPresence(m) {
345
+ const d = m.data;
346
+ const action = m.event.slice("presence.".length);
347
+ const map = this.members.get(m.channel) ?? /* @__PURE__ */ new Map();
348
+ this.members.set(m.channel, map);
349
+ if (action === "leave") map.delete(d.connId);
350
+ else map.set(d.connId, { connId: d.connId, user: d.user, data: d.data, at: m.ts });
351
+ for (const fn of this.presenceHandlers.get(m.channel) ?? []) fn({ action, member: { connId: d.connId, user: d.user, data: d.data } });
352
+ }
353
+ rejoin() {
354
+ for (const [channel, sub] of this.subs) this.ws?.send(JSON.stringify({ op: "subscribe", channel, resumeFrom: sub.cursor }));
355
+ }
356
+ startBeat(ws) {
357
+ this.stopBeat();
358
+ this.heard = this.now();
359
+ this.beat = this.env.setInterval(() => {
360
+ if (ws !== this.ws) return;
361
+ if (this.now() - this.heard > this.o.heartbeatMs * 2) return void ws.close(4e3, "no heartbeat");
362
+ if (ws.readyState === OPEN) ws.send('{"op":"ping"}');
363
+ }, this.o.heartbeatMs);
364
+ }
365
+ stopBeat() {
366
+ this.env.clearInterval(this.beat);
367
+ this.beat = void 0;
368
+ }
369
+ onClose(ws, code) {
370
+ if (ws !== this.ws) return;
371
+ this.ws = null;
372
+ this.stopBeat();
373
+ this._connId = null;
374
+ this.failRequests(new ZapiackRealtimeError("The connection dropped.", 0, "no_route"));
375
+ if (!this.wanted) return;
376
+ if (code === 4403 || this.refused) {
377
+ this.refused = false;
378
+ this.wanted = false;
379
+ this.failAll(new ZapiackRealtimeError("The project does not allow this connection.", 403));
380
+ this.first?.reject(new ZapiackRealtimeError("The project does not allow this connection.", 403));
381
+ this.first = null;
382
+ this.set("closed");
383
+ return;
384
+ }
385
+ this.set("reconnecting");
386
+ this.later(code === 4401 || code === 1012 ? 0 : void 0);
387
+ }
388
+ later(force) {
389
+ this.env.clearTimeout(this.retry);
390
+ this.attempt += 1;
391
+ const { min, max } = this.o.backoffMs;
392
+ const ceiling = Math.min(max, min * 2 ** (this.attempt - 1));
393
+ const wait = force ?? Math.round(min + this.env.random() * (ceiling - min));
394
+ this.set("reconnecting");
395
+ this.retry = this.env.setTimeout(() => void this.open(), wait);
396
+ }
397
+ };
398
+
399
+ // src/index.ts
400
+ var ZapiackError = class extends Error {
401
+ constructor(message) {
402
+ super(message);
403
+ this.name = "ZapiackError";
404
+ }
405
+ };
406
+ var TAP_EVENT = "zapiackTap";
407
+ function native() {
408
+ const module2 = import_react_native.NativeModules.ZapiackPush;
409
+ if (!module2) {
410
+ throw new ZapiackError(
411
+ "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."
412
+ );
413
+ }
414
+ return module2;
415
+ }
416
+ var emitter;
417
+ var ZapiackPush = {
418
+ /** Call once at start-up, before anything else. */
419
+ configure(options) {
420
+ if (!options.appKey.startsWith("pk_")) throw new ZapiackError("ZapiackPush needs the public app key, which starts with pk_");
421
+ if (import_react_native.Platform.OS === "ios" && !options.appGroup) {
422
+ throw new ZapiackError("On iOS, appGroup is required: it is how the app and its notification extension share what they need");
423
+ }
424
+ return native().configure({ appKey: options.appKey, baseUrl: options.baseUrl ?? null, appGroup: options.appGroup ?? null });
425
+ },
426
+ /** Shows the system permission prompt where there is one, registers for push, and says whether notifications are allowed. */
427
+ async requestPermission() {
428
+ return await native().requestPermission() === true;
429
+ },
430
+ /** The identifier that ties this install to the service, once `configure` has run. */
431
+ installationId() {
432
+ return native().installationId();
433
+ },
434
+ /** Link this install to the user your server knows. Send to `externalUserIds` from your server to reach them. */
435
+ login(userId) {
436
+ return native().login(userId);
437
+ },
438
+ /** Unlink this install from the user, on sign-out. */
439
+ logout() {
440
+ return native().logout();
441
+ },
442
+ /** Add or change tags; send to `tags` from your server to reach everyone who has them. */
443
+ addTags(tags) {
444
+ return native().addTags(tags);
445
+ },
446
+ removeTags(keys) {
447
+ return native().removeTags(keys);
448
+ },
449
+ /** A screen the user reached, credited to the push they tapped while its window is open. */
450
+ screen(name) {
451
+ return native().screen(name);
452
+ },
453
+ /** A named goal or event, credited to the push they tapped while its window is open. Resolves false when there is nothing to credit. */
454
+ async track(name, properties) {
455
+ return await native().track(name, properties ?? null) === true;
456
+ },
457
+ /** Sends anything waiting. Call when the app comes to the foreground. */
458
+ flush() {
459
+ return native().flush();
460
+ },
461
+ /**
462
+ * Lets Zapiack start Live Activities on iOS 17.2 and later: a template push with a timer or progress then counts down on the lock
463
+ * screen and in the Dynamic Island. Also add ZapiackLiveActivityWidget to a widget extension (see the iOS README). Does nothing on
464
+ * Android, where those pushes are drawn in the notification itself.
465
+ */
466
+ enableLiveActivities() {
467
+ return native().enableLiveActivities();
468
+ },
469
+ /** Notifications tapped while the app is running. Returns a function that stops listening. */
470
+ onTap(listener) {
471
+ const module2 = native();
472
+ emitter ?? (emitter = new import_react_native.NativeEventEmitter(module2));
473
+ const subscription = emitter.addListener(TAP_EVENT, listener);
474
+ return () => subscription.remove();
475
+ },
476
+ /** The notification that opened the app, if it was opened by tapping one. Resolves it once. */
477
+ initialTap() {
478
+ return native().initialTap();
479
+ }
480
+ };
481
+ var src_default = ZapiackPush;
482
+ // Annotate the CommonJS export names for ESM import in node:
483
+ 0 && (module.exports = {
484
+ DEFAULT_REALTIME_URL,
485
+ ZapiackError,
486
+ ZapiackPush,
487
+ ZapiackRealtime,
488
+ ZapiackRealtimeError,
489
+ browserRealtimeEnv
490
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,100 @@
1
+ import {
2
+ DEFAULT_REALTIME_URL,
3
+ ZapiackRealtime,
4
+ ZapiackRealtimeError,
5
+ browserRealtimeEnv
6
+ } from "./chunk-CCLICX3L.mjs";
7
+
8
+ // src/index.ts
9
+ import { NativeEventEmitter, NativeModules, Platform } from "react-native";
10
+ var ZapiackError = class extends Error {
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = "ZapiackError";
14
+ }
15
+ };
16
+ var TAP_EVENT = "zapiackTap";
17
+ function native() {
18
+ const module = NativeModules.ZapiackPush;
19
+ if (!module) {
20
+ throw new ZapiackError(
21
+ "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."
22
+ );
23
+ }
24
+ return module;
25
+ }
26
+ var emitter;
27
+ var ZapiackPush = {
28
+ /** Call once at start-up, before anything else. */
29
+ configure(options) {
30
+ if (!options.appKey.startsWith("pk_")) throw new ZapiackError("ZapiackPush needs the public app key, which starts with pk_");
31
+ if (Platform.OS === "ios" && !options.appGroup) {
32
+ throw new ZapiackError("On iOS, appGroup is required: it is how the app and its notification extension share what they need");
33
+ }
34
+ return native().configure({ appKey: options.appKey, baseUrl: options.baseUrl ?? null, appGroup: options.appGroup ?? null });
35
+ },
36
+ /** Shows the system permission prompt where there is one, registers for push, and says whether notifications are allowed. */
37
+ async requestPermission() {
38
+ return await native().requestPermission() === true;
39
+ },
40
+ /** The identifier that ties this install to the service, once `configure` has run. */
41
+ installationId() {
42
+ return native().installationId();
43
+ },
44
+ /** Link this install to the user your server knows. Send to `externalUserIds` from your server to reach them. */
45
+ login(userId) {
46
+ return native().login(userId);
47
+ },
48
+ /** Unlink this install from the user, on sign-out. */
49
+ logout() {
50
+ return native().logout();
51
+ },
52
+ /** Add or change tags; send to `tags` from your server to reach everyone who has them. */
53
+ addTags(tags) {
54
+ return native().addTags(tags);
55
+ },
56
+ removeTags(keys) {
57
+ return native().removeTags(keys);
58
+ },
59
+ /** A screen the user reached, credited to the push they tapped while its window is open. */
60
+ screen(name) {
61
+ return native().screen(name);
62
+ },
63
+ /** A named goal or event, credited to the push they tapped while its window is open. Resolves false when there is nothing to credit. */
64
+ async track(name, properties) {
65
+ return await native().track(name, properties ?? null) === true;
66
+ },
67
+ /** Sends anything waiting. Call when the app comes to the foreground. */
68
+ flush() {
69
+ return native().flush();
70
+ },
71
+ /**
72
+ * Lets Zapiack start Live Activities on iOS 17.2 and later: a template push with a timer or progress then counts down on the lock
73
+ * screen and in the Dynamic Island. Also add ZapiackLiveActivityWidget to a widget extension (see the iOS README). Does nothing on
74
+ * Android, where those pushes are drawn in the notification itself.
75
+ */
76
+ enableLiveActivities() {
77
+ return native().enableLiveActivities();
78
+ },
79
+ /** Notifications tapped while the app is running. Returns a function that stops listening. */
80
+ onTap(listener) {
81
+ const module = native();
82
+ emitter ?? (emitter = new NativeEventEmitter(module));
83
+ const subscription = emitter.addListener(TAP_EVENT, listener);
84
+ return () => subscription.remove();
85
+ },
86
+ /** The notification that opened the app, if it was opened by tapping one. Resolves it once. */
87
+ initialTap() {
88
+ return native().initialTap();
89
+ }
90
+ };
91
+ var src_default = ZapiackPush;
92
+ export {
93
+ DEFAULT_REALTIME_URL,
94
+ ZapiackError,
95
+ ZapiackPush,
96
+ ZapiackRealtime,
97
+ ZapiackRealtimeError,
98
+ browserRealtimeEnv,
99
+ src_default as default
100
+ };