react-onesignal 3.2.0 → 3.2.2
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/.eslintignore +2 -0
- package/.eslintrc.cjs +7 -2
- package/CHANGELOG.md +13 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +174 -180
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.test.d.ts +1 -0
- package/index.test.ts +50 -0
- package/index.ts +26 -17
- package/package.json +12 -9
- package/tsconfig.json +3 -2
- package/vitest.config.ts +8 -0
- package/.babelrc +0 -9
package/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const ONESIGNAL_SDK_ID = 'onesignal-sdk';
|
|
2
|
-
const ONE_SIGNAL_SCRIPT_SRC =
|
|
2
|
+
const ONE_SIGNAL_SCRIPT_SRC =
|
|
3
|
+
'https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js';
|
|
3
4
|
|
|
4
5
|
// true if the script is successfully loaded from CDN.
|
|
5
6
|
let isOneSignalInitialized = false;
|
|
@@ -39,7 +40,7 @@ function addSDKScript() {
|
|
|
39
40
|
// This is important for users who may block cdn.onesignal.com w/ adblock.
|
|
40
41
|
script.onerror = () => {
|
|
41
42
|
handleOnError();
|
|
42
|
-
}
|
|
43
|
+
};
|
|
43
44
|
|
|
44
45
|
document.head.appendChild(script);
|
|
45
46
|
}
|
|
@@ -57,20 +58,26 @@ function isPushNotificationsSupported() {
|
|
|
57
58
|
|
|
58
59
|
function isMacOSSafariInIframe(): boolean {
|
|
59
60
|
// Fallback detection for Safari on macOS in an iframe context
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
return (
|
|
62
|
+
window.top !== window && // isContextIframe
|
|
63
|
+
navigator.vendor === 'Apple Computer, Inc.' && // isSafari
|
|
64
|
+
navigator.platform === 'MacIntel'
|
|
65
|
+
); // isMacOS
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
function supportsSafariPush(): boolean {
|
|
66
|
-
return (
|
|
67
|
-
|
|
69
|
+
return (
|
|
70
|
+
(window.safari && typeof window.safari.pushNotification !== 'undefined') ||
|
|
71
|
+
isMacOSSafariInIframe()
|
|
72
|
+
);
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
// Does the browser support the standard Push API
|
|
71
76
|
function supportsVapidPush(): boolean {
|
|
72
|
-
return
|
|
73
|
-
|
|
77
|
+
return (
|
|
78
|
+
typeof PushSubscriptionOptions !== 'undefined' &&
|
|
79
|
+
PushSubscriptionOptions.prototype.hasOwnProperty('applicationServerKey')
|
|
80
|
+
);
|
|
74
81
|
}
|
|
75
82
|
/* E N D */
|
|
76
83
|
|
|
@@ -82,7 +89,7 @@ function supportsVapidPush(): boolean {
|
|
|
82
89
|
*/
|
|
83
90
|
const isPushSupported = (): boolean => {
|
|
84
91
|
return isPushNotificationsSupported();
|
|
85
|
-
}
|
|
92
|
+
};
|
|
86
93
|
|
|
87
94
|
/**
|
|
88
95
|
* @PublicApi
|
|
@@ -93,19 +100,21 @@ const init = (options: IInitObject): Promise<void> => {
|
|
|
93
100
|
}
|
|
94
101
|
|
|
95
102
|
if (!options || !options.appId) {
|
|
96
|
-
|
|
103
|
+
return Promise.reject('You need to provide your OneSignal appId.');
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
if (!document) {
|
|
100
107
|
return Promise.reject(`Document is not defined.`);
|
|
101
108
|
}
|
|
102
109
|
|
|
103
|
-
return new Promise<void>((resolve) => {
|
|
110
|
+
return new Promise<void>((resolve, reject) => {
|
|
104
111
|
window.OneSignalDeferred?.push((OneSignal) => {
|
|
105
|
-
OneSignal.init(options)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
OneSignal.init(options)
|
|
113
|
+
.then(() => {
|
|
114
|
+
isOneSignalInitialized = true;
|
|
115
|
+
resolve();
|
|
116
|
+
})
|
|
117
|
+
.catch(reject);
|
|
109
118
|
});
|
|
110
119
|
});
|
|
111
120
|
};
|
|
@@ -117,7 +126,7 @@ export interface IOneSignalTagCategory { tag: string; label: string; checked?: b
|
|
|
117
126
|
export type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; };
|
|
118
127
|
export type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };
|
|
119
128
|
export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
|
|
120
|
-
export type SlidedownEventName = 'slidedownShown';
|
|
129
|
+
export type SlidedownEventName = 'slidedownAllowClick' | 'slidedownCancelClick' | 'slidedownClosed' | 'slidedownQueued' | 'slidedownShown';
|
|
121
130
|
export type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
|
|
122
131
|
export interface IOSNotification {
|
|
123
132
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-onesignal",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.2",
|
|
4
4
|
"description": "React OneSignal Module: Make it easy to integrate OneSignal with your React App!",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"contributors": [
|
|
@@ -24,24 +24,27 @@
|
|
|
24
24
|
"module": "dist/index.es.js",
|
|
25
25
|
"types": "dist/index.d.ts",
|
|
26
26
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
28
|
-
"npm": ">=
|
|
27
|
+
"node": ">=14",
|
|
28
|
+
"npm": ">=6"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
32
32
|
"build": "vite build",
|
|
33
|
-
"
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"prepare": "npm run lint && npm run test && npm run build"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
37
|
-
"@typescript-eslint/parser": "^
|
|
38
|
-
"eslint": "^8.
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^8.28.0",
|
|
38
|
+
"@typescript-eslint/parser": "^8.28.0",
|
|
39
|
+
"eslint": "^8.57.1",
|
|
39
40
|
"eslint-plugin-import": "^2.31.0",
|
|
40
41
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
41
|
-
"eslint-plugin-react": "
|
|
42
|
+
"eslint-plugin-react": "7.37.4",
|
|
43
|
+
"jsdom": "^26.0.0",
|
|
42
44
|
"typescript": "^5.8.2",
|
|
43
45
|
"vite": "^6.2.1",
|
|
44
|
-
"vite-plugin-dts": "^4.5.3"
|
|
46
|
+
"vite-plugin-dts": "^4.5.3",
|
|
47
|
+
"vitest": "^3.0.9"
|
|
45
48
|
},
|
|
46
49
|
"keywords": [
|
|
47
50
|
"onesignal",
|
package/tsconfig.json
CHANGED
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
"noUnusedParameters": true,
|
|
18
18
|
"allowSyntheticDefaultImports": true,
|
|
19
19
|
"downlevelIteration": true,
|
|
20
|
-
"skipLibCheck": true
|
|
20
|
+
"skipLibCheck": true,
|
|
21
|
+
"types": ["vitest/globals"]
|
|
21
22
|
},
|
|
22
|
-
"include": ["index.ts"],
|
|
23
|
+
"include": ["index.ts", "index.test.ts"],
|
|
23
24
|
"exclude": ["node_modules", "build", "dist", "example", "rollup.config.js"]
|
|
24
25
|
}
|
package/vitest.config.ts
ADDED