notifly-sdk 2.3.3 → 2.3.5
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/.eslintrc.cjs +40 -0
- package/.prettierrc.yml +14 -0
- package/README.md +8 -2
- package/index.js +190 -0
- package/package.json +28 -158
- package/src/auth.js +45 -0
- package/src/constant.js +8 -0
- package/src/in_app_message.js +258 -0
- package/src/log_event.js +189 -0
- package/src/user.js +51 -0
- package/src/utils.js +145 -0
- package/android/build.gradle +0 -100
- package/android/gradle.properties +0 -5
- package/android/src/main/AndroidManifest.xml +0 -4
- package/android/src/main/java/com/notiflysdk/NotiflySdkModule.kt +0 -100
- package/android/src/main/java/com/notiflysdk/NotiflySdkPackage.kt +0 -35
- package/android/src/newarch/NotiflySdkSpec.kt +0 -7
- package/android/src/oldarch/NotiflySdkSpec.kt +0 -24
- package/ios/NotiflySdk-Bridging-Header.h +0 -2
- package/ios/NotiflySdk.m +0 -22
- package/ios/NotiflySdk.swift +0 -39
- package/ios/NotiflySdk.xcodeproj/project.pbxproj +0 -273
- package/ios/NotiflySdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
- package/lib/commonjs/NativeNotiflySdk.js +0 -10
- package/lib/commonjs/NativeNotiflySdk.js.map +0 -1
- package/lib/commonjs/index.js +0 -85
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/types.js +0 -2
- package/lib/commonjs/types.js.map +0 -1
- package/lib/module/NativeNotiflySdk.js +0 -3
- package/lib/module/NativeNotiflySdk.js.map +0 -1
- package/lib/module/index.js +0 -70
- package/lib/module/index.js.map +0 -1
- package/lib/module/types.js +0 -2
- package/lib/module/types.js.map +0 -1
- package/lib/typescript/NativeNotiflySdk.d.ts +0 -15
- package/lib/typescript/NativeNotiflySdk.d.ts.map +0 -1
- package/lib/typescript/index.d.ts +0 -26
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/types.d.ts +0 -7
- package/lib/typescript/types.d.ts.map +0 -1
- package/notifly_react_native_sdk.podspec +0 -36
- package/src/NativeNotiflySdk.ts +0 -25
- package/src/index.tsx +0 -105
- package/src/types.ts +0 -7
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: {
|
|
4
|
+
es6: true,
|
|
5
|
+
jest: true,
|
|
6
|
+
node: true,
|
|
7
|
+
'react-native/react-native': true,
|
|
8
|
+
},
|
|
9
|
+
parser: '@babel/eslint-parser',
|
|
10
|
+
plugins: ['react', 'react-native'],
|
|
11
|
+
extends: ['eslint:recommended', 'plugin:react/recommended'],
|
|
12
|
+
rules: {
|
|
13
|
+
'react/prop-types': 'off',
|
|
14
|
+
'react/react-in-jsx-scope': 'off',
|
|
15
|
+
'no-console': 'off',
|
|
16
|
+
'no-unused-vars': 'warn',
|
|
17
|
+
'react-native/no-unused-styles': 'warn',
|
|
18
|
+
'react-native/split-platform-components': 'warn',
|
|
19
|
+
'react-native/no-inline-styles': 'warn',
|
|
20
|
+
'react-native/no-color-literals': 'warn',
|
|
21
|
+
'react-native/no-raw-text': 'warn',
|
|
22
|
+
},
|
|
23
|
+
settings: {
|
|
24
|
+
react: {
|
|
25
|
+
version: 'detect',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
parserOptions: {
|
|
29
|
+
requireConfigFile: false,
|
|
30
|
+
ecmaVersion: 2021,
|
|
31
|
+
sourceType: 'module',
|
|
32
|
+
ecmaFeatures: {
|
|
33
|
+
jsx: true,
|
|
34
|
+
},
|
|
35
|
+
babelOptions: {
|
|
36
|
+
presets: ['@babel/preset-env', '@babel/preset-react'],
|
|
37
|
+
plugins: ['@babel/plugin-syntax-import-assertions'],
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
package/.prettierrc.yml
ADDED
package/README.md
CHANGED
|
@@ -19,9 +19,15 @@ or
|
|
|
19
19
|
yarn add notifly-sdk@latest
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
Also, please install the peer dependencies manually:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
npm install @react-native-async-storage/async-storage@^1.17.11 @react-native-firebase/app@^16.4.3 @react-native-firebase/messaging@^16.4.3 react-native-device-info@^8.1.4 react-native-modal@^13.0.1 react-native-root-siblings@^4.1.1 react-native-webview@^11.26.1 uuid@^8.3.0
|
|
26
|
+
```
|
|
27
|
+
|
|
22
28
|
## Usage
|
|
23
29
|
|
|
24
30
|
Please refer to our official documentation:
|
|
25
31
|
|
|
26
|
-
* [English documentation](https://docs.notifly.tech/
|
|
27
|
-
* [Korean documentation](https://docs.notifly.tech/ko/
|
|
32
|
+
* [English documentation](https://docs.notifly.tech/client-sdk/react-native)
|
|
33
|
+
* [Korean documentation](https://docs.notifly.tech/ko/client-sdk/react-native)
|
package/index.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { Linking } from 'react-native';
|
|
2
|
+
import RootSiblings from 'react-native-root-siblings';
|
|
3
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
4
|
+
import messaging from '@react-native-firebase/messaging';
|
|
5
|
+
import logEvent from './src/log_event';
|
|
6
|
+
import { setUserProperties, removeUserId } from './src/user';
|
|
7
|
+
import { base64Decode, clickHandler, sessionStart } from './src/utils';
|
|
8
|
+
import { showInAppMessage } from './src/in_app_message';
|
|
9
|
+
let isSetBackgroundHandler = false;
|
|
10
|
+
let isNotiflyInitialized = false;
|
|
11
|
+
const openedInAppWebViewCount = { count: 0 };
|
|
12
|
+
|
|
13
|
+
exports.trackEvent = logEvent;
|
|
14
|
+
exports.setUserProperties = setUserProperties;
|
|
15
|
+
exports.clickHandler = clickHandler;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Sets the background message handler for the Notifly SDK.
|
|
19
|
+
* This method should be called in the index.js file of your app.
|
|
20
|
+
* Should be used when you don't have a custom background message handler.
|
|
21
|
+
* @returns {Promise<void>} - A promise that resolves when the background message handler is set.
|
|
22
|
+
* @example
|
|
23
|
+
* setNotiflyBackgroundMessageHandler();
|
|
24
|
+
*/
|
|
25
|
+
async function setNotiflyBackgroundMessageHandler() {
|
|
26
|
+
messaging().setBackgroundMessageHandler(notiflyBackgroundHandler);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The background message handler for the Notifly SDK.
|
|
31
|
+
* This method should be called in the index.js file of your app.
|
|
32
|
+
* Should be used when you have a custom background message handler.
|
|
33
|
+
* @param {Object} remoteMessage - The remote message to handle.
|
|
34
|
+
* @returns {Promise<void>} - A promise that resolves when the background message handler is set.
|
|
35
|
+
* @example
|
|
36
|
+
* messaging().setBackgroundMessageHandler(async remoteMessage => {
|
|
37
|
+
console.log('Existing handler: Background message received:', remoteMessage);
|
|
38
|
+
await notiflyBackgroundHandler(remoteMessage);
|
|
39
|
+
});
|
|
40
|
+
*/
|
|
41
|
+
async function notiflyBackgroundHandler(remoteMessage) {
|
|
42
|
+
if (!remoteMessage.notification) {
|
|
43
|
+
return; // TODO(minyong): Discuss if we should log only when notifly_message_type is push-notitification.
|
|
44
|
+
}
|
|
45
|
+
if (!isSetBackgroundHandler) {
|
|
46
|
+
await logEvent(
|
|
47
|
+
'push_delivered',
|
|
48
|
+
{
|
|
49
|
+
type: 'message_event',
|
|
50
|
+
channel: 'push-notification',
|
|
51
|
+
campaign_id: remoteMessage?.data?.campaign_id,
|
|
52
|
+
notifly_message_id: remoteMessage?.data?.notifly_message_id,
|
|
53
|
+
status: 'quit',
|
|
54
|
+
},
|
|
55
|
+
null,
|
|
56
|
+
true,
|
|
57
|
+
);
|
|
58
|
+
isSetBackgroundHandler = true;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
await logEvent(
|
|
62
|
+
'push_delivered',
|
|
63
|
+
{
|
|
64
|
+
type: 'message_event',
|
|
65
|
+
channel: 'push-notification',
|
|
66
|
+
campaign_id: remoteMessage?.data?.campaign_id,
|
|
67
|
+
notifly_message_id: remoteMessage.data?.notifly_message_id,
|
|
68
|
+
status: 'background',
|
|
69
|
+
},
|
|
70
|
+
null,
|
|
71
|
+
true,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Sets the external user ID for the user.
|
|
77
|
+
*
|
|
78
|
+
* @async
|
|
79
|
+
* @param {string} userID - The external user ID for the user.
|
|
80
|
+
* @returns {Promise<void>} - A promise that resolves when the user ID is set.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* await setUserId('123456789');
|
|
84
|
+
*/
|
|
85
|
+
exports.setUserId = async function (userID) {
|
|
86
|
+
try {
|
|
87
|
+
if (userID) {
|
|
88
|
+
await setUserProperties({
|
|
89
|
+
external_user_id: userID,
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
await removeUserId();
|
|
94
|
+
return;
|
|
95
|
+
} catch (err) {
|
|
96
|
+
console.warn('[Notifly] setUserId failed.');
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Initializes the Notifly SDK with the given project ID, user name, and password.
|
|
102
|
+
*
|
|
103
|
+
* @async
|
|
104
|
+
* @param {string} prjId - The project ID to use for initialization.
|
|
105
|
+
* @param {string} userName - The user name to use for authentication.
|
|
106
|
+
* @param {string} password - The password to use for authentication.
|
|
107
|
+
* @param {boolean} [useCustomClickHandler=false] - A flag indicating whether to use a custom click handler for push notifications.
|
|
108
|
+
* @returns {Promise<void>} A promise that resolves when initialization is complete, or rejects with an error.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* await initialize('myProjectId', 'myUserName', 'myPassword');
|
|
112
|
+
*/
|
|
113
|
+
exports.initialize = async function (prjId, userName, password, useCustomClickHandler = false) {
|
|
114
|
+
if (isNotiflyInitialized) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
await messaging().requestPermission();
|
|
119
|
+
// in-app-message
|
|
120
|
+
messaging().onMessage((remoteMessage) => {
|
|
121
|
+
new RootSiblings(null).destroy();
|
|
122
|
+
handleInAppMessage(remoteMessage, openedInAppWebViewCount);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
messaging().onNotificationOpenedApp(handleNotificationOpened);
|
|
127
|
+
|
|
128
|
+
// custom push click handler
|
|
129
|
+
if (!useCustomClickHandler) {
|
|
130
|
+
const initialNotification = await messaging().getInitialNotification();
|
|
131
|
+
if (initialNotification) {
|
|
132
|
+
await clickHandler(initialNotification);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
messaging().getToken();
|
|
137
|
+
messaging().setDeliveryMetricsExportToBigQuery(true);
|
|
138
|
+
|
|
139
|
+
await Promise.all([
|
|
140
|
+
AsyncStorage.setItem('notiflyProjectId', prjId),
|
|
141
|
+
AsyncStorage.setItem('notiflyUserName', userName),
|
|
142
|
+
AsyncStorage.setItem('notiflyUserPassword', password),
|
|
143
|
+
]);
|
|
144
|
+
await sessionStart();
|
|
145
|
+
isNotiflyInitialized = true;
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.warn('[Notifly]: ', err);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
async function handleInAppMessage(remoteMessage, openedInAppWebViewCount) {
|
|
152
|
+
try {
|
|
153
|
+
if (remoteMessage.data?.notifly_message_type === 'in-app-message' && remoteMessage.data?.notifly_in_app_message_data) {
|
|
154
|
+
const decodedJsonString = base64Decode(remoteMessage.data?.notifly_in_app_message_data);
|
|
155
|
+
const notiflyInAppMessageData = JSON.parse(decodedJsonString);
|
|
156
|
+
showInAppMessage(notiflyInAppMessageData, openedInAppWebViewCount);
|
|
157
|
+
}
|
|
158
|
+
} catch (err) {
|
|
159
|
+
console.warn('[Notifly] In-app message handling failed:', err);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function handleNotificationOpened(remoteMessage) {
|
|
164
|
+
try {
|
|
165
|
+
if (remoteMessage.data?.notifly_message_type != 'push-notification') {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const link = remoteMessage.data?.link;
|
|
169
|
+
if (link) {
|
|
170
|
+
Linking.openURL(link);
|
|
171
|
+
}
|
|
172
|
+
await logEvent(
|
|
173
|
+
'push_click',
|
|
174
|
+
{
|
|
175
|
+
type: 'message_event',
|
|
176
|
+
channel: 'push-notification',
|
|
177
|
+
campaign_id: remoteMessage.data.campaign_id,
|
|
178
|
+
notifly_message_id: remoteMessage.data?.notifly_message_id,
|
|
179
|
+
status: 'background',
|
|
180
|
+
},
|
|
181
|
+
null,
|
|
182
|
+
true
|
|
183
|
+
);
|
|
184
|
+
} catch (err) {
|
|
185
|
+
console.warn('[Notifly] Notification opened handling failed:', err);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
exports.setNotiflyBackgroundMessageHandler = setNotiflyBackgroundMessageHandler;
|
|
190
|
+
exports.notiflyBackgroundHandler = notiflyBackgroundHandler;
|
package/package.json
CHANGED
|
@@ -1,165 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notifly-sdk",
|
|
3
|
-
"version": "2.3.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "
|
|
6
|
-
"module": "lib/module/index",
|
|
7
|
-
"types": "lib/typescript/index.d.ts",
|
|
8
|
-
"react-native": "src/index",
|
|
9
|
-
"source": "src/index",
|
|
10
|
-
"files": [
|
|
11
|
-
"src",
|
|
12
|
-
"lib",
|
|
13
|
-
"android",
|
|
14
|
-
"ios",
|
|
15
|
-
"cpp",
|
|
16
|
-
"*.podspec",
|
|
17
|
-
"!lib/typescript/example",
|
|
18
|
-
"!ios/build",
|
|
19
|
-
"!android/build",
|
|
20
|
-
"!android/gradle",
|
|
21
|
-
"!android/gradlew",
|
|
22
|
-
"!android/gradlew.bat",
|
|
23
|
-
"!android/local.properties",
|
|
24
|
-
"!**/__tests__",
|
|
25
|
-
"!**/__fixtures__",
|
|
26
|
-
"!**/__mocks__",
|
|
27
|
-
"!**/.*"
|
|
28
|
-
],
|
|
3
|
+
"version": "2.3.5",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
29
6
|
"scripts": {
|
|
30
|
-
"test": "
|
|
31
|
-
"
|
|
32
|
-
"lint": "eslint
|
|
33
|
-
"prepack": "bob build",
|
|
34
|
-
"release": "release-it",
|
|
35
|
-
"example": "yarn --cwd example",
|
|
36
|
-
"bootstrap": "yarn example && yarn install && yarn example pods",
|
|
37
|
-
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
|
|
38
|
-
},
|
|
39
|
-
"keywords": [
|
|
40
|
-
"react-native",
|
|
41
|
-
"ios",
|
|
42
|
-
"android"
|
|
43
|
-
],
|
|
44
|
-
"repository": "https://github.com/team-michael/notifly-react-native-sdk",
|
|
45
|
-
"author": "minyonglee <minyong@workmichael.com> (https://github.com/minyonglee)",
|
|
46
|
-
"license": "MIT",
|
|
47
|
-
"bugs": {
|
|
48
|
-
"url": "https://github.com/team-michael/notifly-react-native-sdk/issues"
|
|
49
|
-
},
|
|
50
|
-
"homepage": "https://github.com/team-michael/notifly-react-native-sdk#readme",
|
|
51
|
-
"publishConfig": {
|
|
52
|
-
"registry": "https://registry.npmjs.org/"
|
|
53
|
-
},
|
|
54
|
-
"devDependencies": {
|
|
55
|
-
"@commitlint/config-conventional": "^17.0.2",
|
|
56
|
-
"@evilmartians/lefthook": "^1.2.2",
|
|
57
|
-
"@react-native-community/eslint-config": "^3.0.2",
|
|
58
|
-
"@release-it/conventional-changelog": "^5.0.0",
|
|
59
|
-
"@types/jest": "^28.1.2",
|
|
60
|
-
"@types/react": "~17.0.21",
|
|
61
|
-
"@types/react-native": "0.70.0",
|
|
62
|
-
"commitlint": "^17.0.2",
|
|
63
|
-
"del-cli": "^5.0.0",
|
|
64
|
-
"eslint": "^8.4.1",
|
|
65
|
-
"eslint-config-prettier": "^8.5.0",
|
|
66
|
-
"eslint-plugin-prettier": "^4.0.0",
|
|
67
|
-
"jest": "^28.1.1",
|
|
68
|
-
"pod-install": "^0.1.0",
|
|
69
|
-
"prettier": "^2.0.5",
|
|
70
|
-
"react": "18.2.0",
|
|
71
|
-
"react-native": "0.71.8",
|
|
72
|
-
"react-native-builder-bob": "^0.20.4",
|
|
73
|
-
"release-it": "^15.0.0",
|
|
74
|
-
"typescript": "^5.0.2"
|
|
75
|
-
},
|
|
76
|
-
"resolutions": {
|
|
77
|
-
"@types/react": "17.0.21"
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"pretty": "prettier --write \"**/*.{js,jsx,json}\"",
|
|
9
|
+
"lint": "eslint ."
|
|
78
10
|
},
|
|
79
11
|
"peerDependencies": {
|
|
80
|
-
"react": "
|
|
81
|
-
"react-native": "
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"
|
|
101
|
-
|
|
102
|
-
"tagName": "v${version}"
|
|
103
|
-
},
|
|
104
|
-
"npm": {
|
|
105
|
-
"publish": true
|
|
106
|
-
},
|
|
107
|
-
"github": {
|
|
108
|
-
"release": true
|
|
109
|
-
},
|
|
110
|
-
"plugins": {
|
|
111
|
-
"@release-it/conventional-changelog": {
|
|
112
|
-
"preset": "angular"
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
"eslintConfig": {
|
|
117
|
-
"root": true,
|
|
118
|
-
"extends": [
|
|
119
|
-
"@react-native-community",
|
|
120
|
-
"prettier"
|
|
121
|
-
],
|
|
122
|
-
"rules": {
|
|
123
|
-
"prettier/prettier": [
|
|
124
|
-
"error",
|
|
125
|
-
{
|
|
126
|
-
"quoteProps": "consistent",
|
|
127
|
-
"singleQuote": true,
|
|
128
|
-
"tabWidth": 2,
|
|
129
|
-
"trailingComma": "es5",
|
|
130
|
-
"useTabs": false
|
|
131
|
-
}
|
|
132
|
-
]
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
"eslintIgnore": [
|
|
136
|
-
"node_modules/",
|
|
137
|
-
"lib/"
|
|
138
|
-
],
|
|
139
|
-
"prettier": {
|
|
140
|
-
"quoteProps": "consistent",
|
|
141
|
-
"singleQuote": true,
|
|
142
|
-
"tabWidth": 2,
|
|
143
|
-
"trailingComma": "es5",
|
|
144
|
-
"useTabs": false
|
|
145
|
-
},
|
|
146
|
-
"react-native-builder-bob": {
|
|
147
|
-
"source": "src",
|
|
148
|
-
"output": "lib",
|
|
149
|
-
"targets": [
|
|
150
|
-
"commonjs",
|
|
151
|
-
"module",
|
|
152
|
-
[
|
|
153
|
-
"typescript",
|
|
154
|
-
{
|
|
155
|
-
"project": "tsconfig.build.json"
|
|
156
|
-
}
|
|
157
|
-
]
|
|
158
|
-
]
|
|
159
|
-
},
|
|
160
|
-
"codegenConfig": {
|
|
161
|
-
"name": "RNNotiflySdkSpec",
|
|
162
|
-
"type": "modules",
|
|
163
|
-
"jsSrcsDir": "src"
|
|
12
|
+
"@react-native-async-storage/async-storage": "^1.17.11",
|
|
13
|
+
"@react-native-firebase/app": "^16.4.3",
|
|
14
|
+
"@react-native-firebase/messaging": "^16.4.3",
|
|
15
|
+
"react-native-device-info": "^8.1.4",
|
|
16
|
+
"react-native-modal": "^13.0.1",
|
|
17
|
+
"react-native-root-siblings": "^4.1.1",
|
|
18
|
+
"react-native-webview": "^11.26.1",
|
|
19
|
+
"uuid": "^8.3.0"
|
|
20
|
+
},
|
|
21
|
+
"author": "daeseongKim",
|
|
22
|
+
"license": "ISC",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@babel/core": "^7.21.4",
|
|
26
|
+
"@babel/eslint-parser": "^7.21.3",
|
|
27
|
+
"@babel/plugin-syntax-import-assertions": "^7.20.0",
|
|
28
|
+
"@babel/preset-env": "^7.21.4",
|
|
29
|
+
"@babel/preset-react": "^7.18.6",
|
|
30
|
+
"eslint": "^8.38.0",
|
|
31
|
+
"eslint-plugin-react": "^7.32.2",
|
|
32
|
+
"eslint-plugin-react-native": "^4.0.0",
|
|
33
|
+
"prettier": "^2.8.7"
|
|
164
34
|
}
|
|
165
35
|
}
|
package/src/auth.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const NOTIFLY_AUTHORIZE_ENDPOINT = 'https://api.notifly.tech/authorize';
|
|
2
|
+
/**
|
|
3
|
+
* Fetches a Cognito ID token for the given user name and password.
|
|
4
|
+
*
|
|
5
|
+
* @async
|
|
6
|
+
* @param {string} userName - The user name to use for authentication.
|
|
7
|
+
* @param {string} password - The password to use for authentication.
|
|
8
|
+
* @returns {Promise<string>} A promise that resolves with the Cognito ID token, or rejects with an error.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const token = await getCognitoIdToken('myUserName', 'myPassword');
|
|
12
|
+
*/
|
|
13
|
+
export async function getCognitoIdToken(userName, password) {
|
|
14
|
+
try {
|
|
15
|
+
const headers = new Headers({
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const body = JSON.stringify({
|
|
20
|
+
password: password,
|
|
21
|
+
userName: userName,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const requestOptions = {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers,
|
|
27
|
+
body,
|
|
28
|
+
redirect: 'follow',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const response = await request(NOTIFLY_AUTHORIZE_ENDPOINT, requestOptions);
|
|
32
|
+
if (response.error || !response.data) {
|
|
33
|
+
throw new Error(response.error);
|
|
34
|
+
}
|
|
35
|
+
const token = response.data
|
|
36
|
+
return token;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.warn('[Notifly]: ', error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function request(apiUrl, requestOptions) {
|
|
43
|
+
const result = await fetch(apiUrl, requestOptions);
|
|
44
|
+
return result.json();
|
|
45
|
+
}
|
package/src/constant.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const SDK_VERSION = '2.3.5';
|
|
2
|
+
|
|
3
|
+
export const NAMESPACE = {
|
|
4
|
+
'EVENTID': '830b5f7b-e392-43db-a17b-d835f0bcab2b',
|
|
5
|
+
'REGISTERED_USERID': 'ce7c62f9-e8ae-4009-8fd6-468e9581fa21',
|
|
6
|
+
'UNREGISTERED_USERID': 'a6446dcf-c057-4de7-a360-56af8659d52f',
|
|
7
|
+
'DEVICEID': '830848b3-2444-467d-9cd8-3430d2738c57',
|
|
8
|
+
};
|