@pushpushgo/react-native-push 0.4.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 (40) hide show
  1. package/LICENSE +20 -0
  2. package/PushPushGoRNPush.podspec +22 -0
  3. package/README.md +412 -0
  4. package/android/build.gradle +79 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +10 -0
  7. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsActivityCallbacks.kt +36 -0
  8. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsBeaconTranslator.kt +107 -0
  9. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsContentProvider.kt +72 -0
  10. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsError.kt +6 -0
  11. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsModule.kt +54 -0
  12. package/android/src/main/java/com/pushpushgo/bridge/reactnative/push/PushNotificationsPackage.kt +36 -0
  13. package/ios/Bridge/PushNotificationsBeaconTranslator.swift +80 -0
  14. package/ios/Bridge/PushNotificationsModule.h +10 -0
  15. package/ios/Bridge/PushNotificationsModule.mm +53 -0
  16. package/ios/Bridge/PushNotificationsModuleDelegate.swift +68 -0
  17. package/ios/PushNotificationsRN.swift +35 -0
  18. package/lib/module/beacon/Beacon.js +51 -0
  19. package/lib/module/beacon/Beacon.js.map +1 -0
  20. package/lib/module/beacon/BeaconTag.js +32 -0
  21. package/lib/module/beacon/BeaconTag.js.map +1 -0
  22. package/lib/module/index.js +37 -0
  23. package/lib/module/index.js.map +1 -0
  24. package/lib/module/package.json +1 -0
  25. package/lib/module/specs/NativePushNotifications.js +5 -0
  26. package/lib/module/specs/NativePushNotifications.js.map +1 -0
  27. package/lib/typescript/package.json +1 -0
  28. package/lib/typescript/src/beacon/Beacon.d.ts +38 -0
  29. package/lib/typescript/src/beacon/Beacon.d.ts.map +1 -0
  30. package/lib/typescript/src/beacon/BeaconTag.d.ts +31 -0
  31. package/lib/typescript/src/beacon/BeaconTag.d.ts.map +1 -0
  32. package/lib/typescript/src/index.d.ts +12 -0
  33. package/lib/typescript/src/index.d.ts.map +1 -0
  34. package/lib/typescript/src/specs/NativePushNotifications.d.ts +22 -0
  35. package/lib/typescript/src/specs/NativePushNotifications.d.ts.map +1 -0
  36. package/package.json +168 -0
  37. package/src/beacon/Beacon.ts +84 -0
  38. package/src/beacon/BeaconTag.ts +52 -0
  39. package/src/index.tsx +62 -0
  40. package/src/specs/NativePushNotifications.ts +25 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAG9C,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,WAAW,kBAAkB;IACjC,eAAe,EAAE,MAAM,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACpD,wBAAwB,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;IACtD,4BAA4B,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C;AAED,eAAO,MAAM,iBAAiB,EAAE,kBAwC/B,CAAC;AAEF,OAAO,EACL,MAAM,EACN,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import type { BeaconTag } from '../beacon/BeaconTag';
3
+ export type SubscriberId = string;
4
+ interface SpecBeacon {
5
+ selectors: {
6
+ [key: string]: string | number | boolean;
7
+ };
8
+ tags: BeaconTag[];
9
+ tagsToDelete: BeaconTag[];
10
+ customId: string | null;
11
+ assignToGroup: string | null;
12
+ unassignFromGroup: string | null;
13
+ }
14
+ export interface Spec extends TurboModule {
15
+ getSubscriberId: () => Promise<SubscriberId | null>;
16
+ subscribeToNotifications: () => Promise<SubscriberId>;
17
+ unsubscribeFromNotifications: () => Promise<void>;
18
+ sendBeacon: (beacon: SpecBeacon) => Promise<void>;
19
+ }
20
+ declare const _default: Spec;
21
+ export default _default;
22
+ //# sourceMappingURL=NativePushNotifications.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativePushNotifications.d.ts","sourceRoot":"","sources":["../../../../src/specs/NativePushNotifications.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC,UAAU,UAAU;IAClB,SAAS,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IACxD,IAAI,EAAE,SAAS,EAAE,CAAC;IAClB,YAAY,EAAE,SAAS,EAAE,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,eAAe,EAAE,MAAM,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACpD,wBAAwB,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;IACtD,4BAA4B,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,UAAU,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACnD;;AAED,wBAEE"}
package/package.json ADDED
@@ -0,0 +1,168 @@
1
+ {
2
+ "name": "@pushpushgo/react-native-push",
3
+ "version": "0.4.0",
4
+ "description": "PushPushGo Push Notifications SDK for React Native",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "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
+ "*.podspec",
21
+ "react-native.config.js",
22
+ "!ios/build",
23
+ "!android/build",
24
+ "!android/gradle",
25
+ "!android/gradlew",
26
+ "!android/gradlew.bat",
27
+ "!android/local.properties",
28
+ "!**/__tests__",
29
+ "!**/__fixtures__",
30
+ "!**/__mocks__",
31
+ "!**/.*"
32
+ ],
33
+ "scripts": {
34
+ "example": "yarn workspace @pushpushgo/react-native-push-example",
35
+ "test": "jest",
36
+ "typecheck": "tsc",
37
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
38
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
39
+ "prepare": "bob build",
40
+ "release": "release-it --only-version"
41
+ },
42
+ "keywords": [
43
+ "react-native",
44
+ "ios",
45
+ "android"
46
+ ],
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/ppgco/react-native-sdk.git"
50
+ },
51
+ "author": "PushPushGo <mobile-dev@pushpushgo.com> (https://github.com/ppgco)",
52
+ "license": "MIT",
53
+ "bugs": {
54
+ "url": "https://github.com/ppgco/react-native-sdk/issues"
55
+ },
56
+ "homepage": "https://github.com/ppgco/react-native-sdk#readme",
57
+ "publishConfig": {
58
+ "registry": "https://registry.npmjs.org/"
59
+ },
60
+ "devDependencies": {
61
+ "@commitlint/config-conventional": "^19.8.1",
62
+ "@eslint/compat": "^1.3.2",
63
+ "@eslint/eslintrc": "^3.3.1",
64
+ "@eslint/js": "^9.35.0",
65
+ "@evilmartians/lefthook": "^1.12.3",
66
+ "@react-native-community/cli": "20.0.1",
67
+ "@react-native/babel-preset": "0.81.1",
68
+ "@react-native/eslint-config": "^0.81.1",
69
+ "@release-it/conventional-changelog": "^10.0.1",
70
+ "@types/jest": "^29.5.14",
71
+ "@types/react": "^19.1.0",
72
+ "commitlint": "^19.8.1",
73
+ "del-cli": "^6.0.0",
74
+ "eslint": "^9.35.0",
75
+ "eslint-config-prettier": "^10.1.8",
76
+ "eslint-plugin-prettier": "^5.5.4",
77
+ "jest": "^29.7.0",
78
+ "prettier": "^3.6.2",
79
+ "react": "19.1.0",
80
+ "react-native": "0.81.1",
81
+ "react-native-builder-bob": "^0.40.13",
82
+ "release-it": "^19.0.4",
83
+ "turbo": "^2.5.6",
84
+ "typescript": "^5.9.2"
85
+ },
86
+ "peerDependencies": {
87
+ "react": ">=18",
88
+ "react-native": ">=0.72"
89
+ },
90
+ "workspaces": [
91
+ "example"
92
+ ],
93
+ "packageManager": "yarn@3.6.1",
94
+ "jest": {
95
+ "preset": "react-native",
96
+ "modulePathIgnorePatterns": [
97
+ "<rootDir>/example/node_modules",
98
+ "<rootDir>/lib/"
99
+ ]
100
+ },
101
+ "commitlint": {
102
+ "extends": [
103
+ "@commitlint/config-conventional"
104
+ ]
105
+ },
106
+ "release-it": {
107
+ "git": {
108
+ "commitMessage": "chore: release ${version}",
109
+ "tagName": "v${version}"
110
+ },
111
+ "npm": {
112
+ "publish": true
113
+ },
114
+ "github": {
115
+ "release": false
116
+ },
117
+ "plugins": {
118
+ "@release-it/conventional-changelog": {
119
+ "preset": {
120
+ "name": "angular"
121
+ }
122
+ }
123
+ }
124
+ },
125
+ "prettier": {
126
+ "quoteProps": "consistent",
127
+ "singleQuote": true,
128
+ "tabWidth": 2,
129
+ "trailingComma": "es5",
130
+ "useTabs": false
131
+ },
132
+ "react-native-builder-bob": {
133
+ "source": "src",
134
+ "output": "lib",
135
+ "targets": [
136
+ [
137
+ "module",
138
+ {
139
+ "esm": true
140
+ }
141
+ ],
142
+ [
143
+ "typescript",
144
+ {
145
+ "project": "tsconfig.build.json"
146
+ }
147
+ ]
148
+ ]
149
+ },
150
+ "codegenConfig": {
151
+ "name": "PushNotificationsSpec",
152
+ "type": "modules",
153
+ "jsSrcsDir": "src/specs",
154
+ "android": {
155
+ "javaPackageName": "com.pushpushgo.bridge.reactnative.push"
156
+ },
157
+ "ios": {
158
+ "modulesProvider": {
159
+ "PushPushGoPushNotifications": "PushNotificationsModule"
160
+ }
161
+ }
162
+ },
163
+ "create-react-native-library": {
164
+ "languages": "kotlin-objc",
165
+ "type": "turbo-module",
166
+ "version": "0.54.3"
167
+ }
168
+ }
@@ -0,0 +1,84 @@
1
+ import type { BeaconTag } from './BeaconTag';
2
+
3
+ export type BeaconSelectorKey = string;
4
+ export type BeaconSelectorValue = string | number | boolean;
5
+
6
+ export interface IBeacon {
7
+ selectors: Map<BeaconSelectorKey, BeaconSelectorValue>;
8
+ tags: BeaconTag[];
9
+ tagsToDelete: BeaconTag[];
10
+ customId: string | null;
11
+ assignToGroup: string | null;
12
+ unassignFromGroup: string | null;
13
+ }
14
+
15
+ class BeaconBuilder {
16
+ private selectors = new Map<BeaconSelectorKey, BeaconSelectorValue>();
17
+ private tags: BeaconTag[] = [];
18
+ private tagsToDelete: BeaconTag[] = [];
19
+ private customId: string | null = null;
20
+ private _assignToGroup: string | null = null;
21
+ private _unassignFromGroup: string | null = null;
22
+
23
+ set(key: BeaconSelectorKey, value: BeaconSelectorValue): BeaconBuilder {
24
+ this.selectors.set(key, value);
25
+
26
+ return this;
27
+ }
28
+
29
+ appendTag(tag: BeaconTag): BeaconBuilder {
30
+ this.tags.push(tag);
31
+
32
+ return this;
33
+ }
34
+
35
+ removeTag(tag: BeaconTag): BeaconBuilder {
36
+ this.tagsToDelete.push(tag);
37
+
38
+ return this;
39
+ }
40
+
41
+ setCustomId(id: string | null): BeaconBuilder {
42
+ this.customId = id;
43
+
44
+ return this;
45
+ }
46
+
47
+ assignToGroup(groupId: string): BeaconBuilder {
48
+ this._assignToGroup = groupId;
49
+
50
+ return this;
51
+ }
52
+
53
+ unassignFromGroup(groupId: string): BeaconBuilder {
54
+ this._unassignFromGroup = groupId;
55
+
56
+ return this;
57
+ }
58
+
59
+ build(): Beacon {
60
+ return new Beacon(
61
+ this.selectors,
62
+ this.tags,
63
+ this.tagsToDelete,
64
+ this.customId,
65
+ this._assignToGroup,
66
+ this._unassignFromGroup
67
+ );
68
+ }
69
+ }
70
+
71
+ export class Beacon implements IBeacon {
72
+ constructor(
73
+ readonly selectors: Map<BeaconSelectorKey, BeaconSelectorValue>,
74
+ readonly tags: BeaconTag[],
75
+ readonly tagsToDelete: BeaconTag[],
76
+ readonly customId: string | null,
77
+ readonly assignToGroup: string | null,
78
+ readonly unassignFromGroup: string | null
79
+ ) {}
80
+
81
+ static builder(): BeaconBuilder {
82
+ return new BeaconBuilder();
83
+ }
84
+ }
@@ -0,0 +1,52 @@
1
+ export enum BeaconTagStrategy {
2
+ APPEND = 'append',
3
+ REWRITE = 'rewrite',
4
+ }
5
+
6
+ export interface IBeaconTag {
7
+ tag: string;
8
+ label: string;
9
+ strategy: BeaconTagStrategy;
10
+ ttl: number;
11
+ }
12
+
13
+ interface IBeaconTagProps {
14
+ /** Tag name */
15
+ tag: string;
16
+
17
+ /** Optional tag label */
18
+ label?: string;
19
+
20
+ /** Strategy dictating whether the tags assigned to the given label should be accumulated (APPEND) or overwritten (REWRITE) */
21
+ strategy?: BeaconTagStrategy;
22
+
23
+ /** Time-to-live for the tag in seconds (0 means no expiration) */
24
+ ttl?: number;
25
+ }
26
+
27
+ export class BeaconTag implements IBeaconTag {
28
+ readonly tag: string;
29
+ readonly label: string;
30
+ readonly strategy: BeaconTagStrategy;
31
+ readonly ttl: number;
32
+
33
+ constructor({
34
+ tag,
35
+ label = 'default',
36
+ strategy = BeaconTagStrategy.APPEND,
37
+ ttl = 0,
38
+ }: IBeaconTagProps) {
39
+ this.tag = tag;
40
+ this.label = label;
41
+ this.strategy = strategy;
42
+ this.ttl = ttl;
43
+ }
44
+
45
+ static fromTag(tag: string): BeaconTag {
46
+ return new BeaconTag({ tag });
47
+ }
48
+
49
+ static fromTagAndLabel(tag: string, label: string) {
50
+ return new BeaconTag({ tag, label });
51
+ }
52
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,62 @@
1
+ import { PermissionsAndroid, Platform } from 'react-native';
2
+ import type { Beacon } from './beacon/Beacon';
3
+ import NativePushNotifications from './specs/NativePushNotifications';
4
+
5
+ export type SubscriberId = string;
6
+
7
+ export interface IPushNotifications {
8
+ getSubscriberId: () => Promise<SubscriberId | null>;
9
+ subscribeToNotifications: () => Promise<SubscriberId>;
10
+ unsubscribeFromNotifications: () => Promise<void>;
11
+ sendBeacon: (beacon: Beacon) => Promise<void>;
12
+ }
13
+
14
+ export const PushNotifications: IPushNotifications = {
15
+ getSubscriberId: async () => {
16
+ return await NativePushNotifications.getSubscriberId();
17
+ },
18
+
19
+ subscribeToNotifications: async () => {
20
+ if (Platform.OS === 'android' && Platform.Version >= 33) {
21
+ const hasNotificationsPermission = await PermissionsAndroid.check(
22
+ PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS
23
+ );
24
+
25
+ if (!hasNotificationsPermission) {
26
+ const hasGrantedNotificationsPermission =
27
+ await PermissionsAndroid.request(
28
+ PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS
29
+ );
30
+
31
+ if (!hasGrantedNotificationsPermission) {
32
+ throw new Error('Cannot subscribe to notifications: no permission');
33
+ }
34
+ }
35
+ }
36
+
37
+ return await NativePushNotifications.subscribeToNotifications();
38
+ },
39
+
40
+ unsubscribeFromNotifications: async () => {
41
+ await NativePushNotifications.unsubscribeFromNotifications();
42
+ },
43
+
44
+ sendBeacon: async (beacon) => {
45
+ await NativePushNotifications.sendBeacon({
46
+ selectors: Object.fromEntries(beacon.selectors.entries()),
47
+ tags: beacon.tags,
48
+ tagsToDelete: beacon.tagsToDelete,
49
+ customId: beacon.customId,
50
+ assignToGroup: beacon.assignToGroup,
51
+ unassignFromGroup: beacon.unassignFromGroup,
52
+ });
53
+ },
54
+ };
55
+
56
+ export {
57
+ Beacon,
58
+ type BeaconSelectorKey,
59
+ type BeaconSelectorValue,
60
+ } from './beacon/Beacon';
61
+
62
+ export { BeaconTag, BeaconTagStrategy } from './beacon/BeaconTag';
@@ -0,0 +1,25 @@
1
+ import { TurboModuleRegistry } from 'react-native';
2
+ import type { TurboModule } from 'react-native';
3
+ import type { BeaconTag } from '../beacon/BeaconTag';
4
+
5
+ export type SubscriberId = string;
6
+
7
+ interface SpecBeacon {
8
+ selectors: { [key: string]: string | number | boolean };
9
+ tags: BeaconTag[];
10
+ tagsToDelete: BeaconTag[];
11
+ customId: string | null;
12
+ assignToGroup: string | null;
13
+ unassignFromGroup: string | null;
14
+ }
15
+
16
+ export interface Spec extends TurboModule {
17
+ getSubscriberId: () => Promise<SubscriberId | null>;
18
+ subscribeToNotifications: () => Promise<SubscriberId>;
19
+ unsubscribeFromNotifications: () => Promise<void>;
20
+ sendBeacon: (beacon: SpecBeacon) => Promise<void>;
21
+ }
22
+
23
+ export default TurboModuleRegistry.getEnforcing<Spec>(
24
+ 'PushPushGoPushNotifications'
25
+ );