tauri-plugin-mobile-push-api 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/dist/index.cjs ADDED
@@ -0,0 +1,68 @@
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
+ // index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ getToken: () => getToken,
24
+ onNotificationReceived: () => onNotificationReceived,
25
+ onNotificationTapped: () => onNotificationTapped,
26
+ onTokenRefresh: () => onTokenRefresh,
27
+ requestPermission: () => requestPermission
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+ var import_core = require("@tauri-apps/api/core");
31
+ async function requestPermission() {
32
+ return (0, import_core.invoke)("plugin:mobile-push|request_permission");
33
+ }
34
+ async function getToken() {
35
+ const result = await (0, import_core.invoke)(
36
+ "plugin:mobile-push|get_token"
37
+ );
38
+ return result.token;
39
+ }
40
+ async function onNotificationReceived(handler) {
41
+ return (0, import_core.addPluginListener)(
42
+ "plugin:mobile-push",
43
+ "notification-received",
44
+ handler
45
+ );
46
+ }
47
+ async function onNotificationTapped(handler) {
48
+ return (0, import_core.addPluginListener)(
49
+ "plugin:mobile-push",
50
+ "notification-tapped",
51
+ handler
52
+ );
53
+ }
54
+ async function onTokenRefresh(handler) {
55
+ return (0, import_core.addPluginListener)(
56
+ "plugin:mobile-push",
57
+ "token-received",
58
+ handler
59
+ );
60
+ }
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ getToken,
64
+ onNotificationReceived,
65
+ onNotificationTapped,
66
+ onTokenRefresh,
67
+ requestPermission
68
+ });
@@ -0,0 +1,49 @@
1
+ import { PluginListener } from '@tauri-apps/api/core';
2
+
3
+ /** Payload delivered with push notification events. */
4
+ interface PushNotification {
5
+ title?: string;
6
+ body?: string;
7
+ data: Record<string, unknown>;
8
+ badge?: number;
9
+ sound?: string;
10
+ }
11
+ /**
12
+ * Request permission to display push notifications.
13
+ *
14
+ * On iOS this triggers the system permission dialog. On Android 13+
15
+ * (API 33) it requests the `POST_NOTIFICATIONS` runtime permission.
16
+ * Earlier Android versions return `{ granted: true }` immediately.
17
+ */
18
+ declare function requestPermission(): Promise<{
19
+ granted: boolean;
20
+ }>;
21
+ /**
22
+ * Return the current device push token.
23
+ *
24
+ * - iOS: APNs device token (hex string)
25
+ * - Android: FCM registration token
26
+ *
27
+ * The token may change over the lifetime of the app. Use
28
+ * {@link onTokenRefresh} to stay up-to-date.
29
+ */
30
+ declare function getToken(): Promise<string>;
31
+ /**
32
+ * Called when a push notification is received while the app is in the
33
+ * foreground.
34
+ */
35
+ declare function onNotificationReceived(handler: (notification: PushNotification) => void): Promise<PluginListener>;
36
+ /**
37
+ * Called when the user taps a push notification to open the app.
38
+ */
39
+ declare function onNotificationTapped(handler: (notification: PushNotification) => void): Promise<PluginListener>;
40
+ /**
41
+ * Called when the platform issues a new push token (e.g., after an
42
+ * APNs token refresh or FCM token rotation). Send the new token to
43
+ * your backend whenever this fires.
44
+ */
45
+ declare function onTokenRefresh(handler: (payload: {
46
+ token: string;
47
+ }) => void): Promise<PluginListener>;
48
+
49
+ export { type PushNotification, getToken, onNotificationReceived, onNotificationTapped, onTokenRefresh, requestPermission };
@@ -0,0 +1,49 @@
1
+ import { PluginListener } from '@tauri-apps/api/core';
2
+
3
+ /** Payload delivered with push notification events. */
4
+ interface PushNotification {
5
+ title?: string;
6
+ body?: string;
7
+ data: Record<string, unknown>;
8
+ badge?: number;
9
+ sound?: string;
10
+ }
11
+ /**
12
+ * Request permission to display push notifications.
13
+ *
14
+ * On iOS this triggers the system permission dialog. On Android 13+
15
+ * (API 33) it requests the `POST_NOTIFICATIONS` runtime permission.
16
+ * Earlier Android versions return `{ granted: true }` immediately.
17
+ */
18
+ declare function requestPermission(): Promise<{
19
+ granted: boolean;
20
+ }>;
21
+ /**
22
+ * Return the current device push token.
23
+ *
24
+ * - iOS: APNs device token (hex string)
25
+ * - Android: FCM registration token
26
+ *
27
+ * The token may change over the lifetime of the app. Use
28
+ * {@link onTokenRefresh} to stay up-to-date.
29
+ */
30
+ declare function getToken(): Promise<string>;
31
+ /**
32
+ * Called when a push notification is received while the app is in the
33
+ * foreground.
34
+ */
35
+ declare function onNotificationReceived(handler: (notification: PushNotification) => void): Promise<PluginListener>;
36
+ /**
37
+ * Called when the user taps a push notification to open the app.
38
+ */
39
+ declare function onNotificationTapped(handler: (notification: PushNotification) => void): Promise<PluginListener>;
40
+ /**
41
+ * Called when the platform issues a new push token (e.g., after an
42
+ * APNs token refresh or FCM token rotation). Send the new token to
43
+ * your backend whenever this fires.
44
+ */
45
+ declare function onTokenRefresh(handler: (payload: {
46
+ token: string;
47
+ }) => void): Promise<PluginListener>;
48
+
49
+ export { type PushNotification, getToken, onNotificationReceived, onNotificationTapped, onTokenRefresh, requestPermission };
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ // index.ts
2
+ import {
3
+ invoke,
4
+ addPluginListener
5
+ } from "@tauri-apps/api/core";
6
+ async function requestPermission() {
7
+ return invoke("plugin:mobile-push|request_permission");
8
+ }
9
+ async function getToken() {
10
+ const result = await invoke(
11
+ "plugin:mobile-push|get_token"
12
+ );
13
+ return result.token;
14
+ }
15
+ async function onNotificationReceived(handler) {
16
+ return addPluginListener(
17
+ "plugin:mobile-push",
18
+ "notification-received",
19
+ handler
20
+ );
21
+ }
22
+ async function onNotificationTapped(handler) {
23
+ return addPluginListener(
24
+ "plugin:mobile-push",
25
+ "notification-tapped",
26
+ handler
27
+ );
28
+ }
29
+ async function onTokenRefresh(handler) {
30
+ return addPluginListener(
31
+ "plugin:mobile-push",
32
+ "token-received",
33
+ handler
34
+ );
35
+ }
36
+ export {
37
+ getToken,
38
+ onNotificationReceived,
39
+ onNotificationTapped,
40
+ onTokenRefresh,
41
+ requestPermission
42
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "tauri-plugin-mobile-push-api",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript API for tauri-plugin-mobile-push — push notifications for iOS (APNs) and Android (FCM)",
5
+ "license": "(MIT OR Apache-2.0)",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/yanqianglu/tauri-plugin-mobile-push.git"
9
+ },
10
+ "type": "module",
11
+ "main": "dist/index.cjs",
12
+ "module": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "require": "./dist/index.cjs"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsup index.ts --format esm,cjs --dts --clean",
27
+ "prepublishOnly": "npm run build"
28
+ },
29
+ "peerDependencies": {
30
+ "@tauri-apps/api": ">=2.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@tauri-apps/api": "^2.10.1",
34
+ "tsup": "^8.5.1",
35
+ "typescript": "^5.9.3"
36
+ },
37
+ "keywords": [
38
+ "tauri",
39
+ "tauri-plugin",
40
+ "push-notifications",
41
+ "apns",
42
+ "fcm",
43
+ "ios",
44
+ "android",
45
+ "mobile",
46
+ "remote-push",
47
+ "firebase",
48
+ "apple-push"
49
+ ]
50
+ }