@amityco/ts-sdk-react-native 6.24.1 → 6.24.2-6f5059f.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk-react-native",
3
- "version": "6.24.1",
3
+ "version": "6.24.2-6f5059f.0",
4
4
  "license": "CC-BY-ND-4.0",
5
5
  "author": "amity.co <developers@amity.co> (https://amity.co)",
6
6
  "description": "Amity Social Cloud Typescript SDK",
@@ -46,12 +46,14 @@
46
46
  "@types/jest": "^27.5.1",
47
47
  "@types/node": "^18.6.4",
48
48
  "@types/object-hash": "^3.0.6",
49
+ "@types/react-native": "0.63.4",
49
50
  "@types/socket.io-client": "^1.4.34",
50
51
  "chalk": "^4.1.2",
51
52
  "concurrently": "^6.1.0",
52
53
  "form-data": "^4.0.0",
53
54
  "jest": "^28.1.0",
54
55
  "nock": "^13.3.0",
56
+ "react-native": "0.63.4",
55
57
  "react-native-web": "^0.19.8",
56
58
  "rimraf": "^3.0.2",
57
59
  "rollup": "^2.77.2",
package/rollup.config.js CHANGED
@@ -87,6 +87,12 @@ export default [
87
87
  name: 'Amity',
88
88
  file: pkg.unpkg,
89
89
  },
90
+ external: [
91
+ ...Object.keys(pkg.dependencies),
92
+ 'react-native',
93
+ 'react-native-web',
94
+ '@react-native-community/netinfo',
95
+ ],
90
96
  plugins: [
91
97
  ...config.plugins,
92
98
  replace({
@@ -16,3 +16,6 @@ export * from './renewal';
16
16
  export * from './markerSync';
17
17
 
18
18
  export * from './enableUnreadCount';
19
+
20
+ export * from './registerPushNotification';
21
+ export * from './unregisterPushNotification';
@@ -0,0 +1,37 @@
1
+ import { Platform } from 'react-native';
2
+ import { getActiveClient } from './activeClient';
3
+ import { getDeviceId } from '~/core/device';
4
+ import { ASCApiError, ASCInvalidParameterError } from '~/core/errors';
5
+
6
+ export const registerPushNotification = async (deviceToken: string): Promise<boolean> => {
7
+ const client = getActiveClient();
8
+
9
+ let platform: 'ios' | 'android';
10
+
11
+ if (Platform.OS === 'ios' || Platform.OS === 'android') {
12
+ platform = Platform.OS;
13
+ } else {
14
+ throw new ASCInvalidParameterError('Unsupported platform');
15
+ }
16
+
17
+ const deviceId = getDeviceId();
18
+
19
+ const {
20
+ data: { status, error },
21
+ } = await client.http.post<{ status: 'success' | 'error'; error?: string }>(
22
+ '/v1/notification',
23
+ {
24
+ userId: client.userId,
25
+ deviceId,
26
+ platform,
27
+ token: deviceToken,
28
+ },
29
+ { headers: { 'X-API-Key': client.apiKey } },
30
+ );
31
+
32
+ if (error) {
33
+ throw new ASCApiError(error, Amity.ServerError.BUSINESS_ERROR, Amity.ErrorLevel.ERROR);
34
+ }
35
+
36
+ return status === 'success';
37
+ };
@@ -0,0 +1,26 @@
1
+ import { getDeviceId } from '~/core/device';
2
+ import { getActiveClient } from './activeClient';
3
+ import { ASCApiError } from '~/core/errors';
4
+
5
+ export const unregisterPushNotification = async (): Promise<boolean> => {
6
+ const client = getActiveClient();
7
+ const deviceId = getDeviceId();
8
+
9
+ const {
10
+ data: { status, error },
11
+ } = await client.http.delete<{ status: 'success' | 'error'; error?: string }>(
12
+ '/v1/notification',
13
+ {
14
+ data: {
15
+ deviceId,
16
+ },
17
+ headers: { 'X-API-Key': client.apiKey },
18
+ },
19
+ );
20
+
21
+ if (error) {
22
+ throw new ASCApiError(error, Amity.ServerError.BUSINESS_ERROR, Amity.ErrorLevel.ERROR);
23
+ }
24
+
25
+ return status === 'success';
26
+ };