@amityco/ts-sdk-react-native 6.24.2-d89a258.0 → 6.24.2-dc02f91.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.
@@ -9,4 +9,6 @@ export * from './getFeedSettings';
9
9
  export * from './renewal';
10
10
  export * from './markerSync';
11
11
  export * from './enableUnreadCount';
12
+ export * from './registerPushNotification';
13
+ export * from './unregisterPushNotification';
12
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,cAAc,cAAc,CAAC;AAE7B,cAAc,gBAAgB,CAAC;AAE/B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAE/B,cAAc,eAAe,CAAC;AAE9B,cAAc,mBAAmB,CAAC;AAElC,cAAc,WAAW,CAAC;AAE1B,cAAc,cAAc,CAAC;AAE7B,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,cAAc,cAAc,CAAC;AAE7B,cAAc,gBAAgB,CAAC;AAE/B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAE/B,cAAc,eAAe,CAAC;AAE9B,cAAc,mBAAmB,CAAC;AAElC,cAAc,WAAW,CAAC;AAE1B,cAAc,cAAc,CAAC;AAE7B,cAAc,qBAAqB,CAAC;AAEpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const registerPushNotification: (deviceToken: string) => Promise<boolean>;
2
+ //# sourceMappingURL=registerPushNotification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registerPushNotification.d.ts","sourceRoot":"","sources":["../../../src/client/api/registerPushNotification.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,wBAAwB,gBAAuB,MAAM,KAAG,QAAQ,OAAO,CA+BnF,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const unregisterPushNotification: () => Promise<boolean>;
2
+ //# sourceMappingURL=unregisterPushNotification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unregisterPushNotification.d.ts","sourceRoot":"","sources":["../../../src/client/api/unregisterPushNotification.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,0BAA0B,QAAa,QAAQ,OAAO,CAqBlE,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -10,6 +10,7 @@ var HttpAgent = require('agentkeepalive');
10
10
  var io = require('socket.io-client');
11
11
  var AsyncStorage = require('@react-native-async-storage/async-storage');
12
12
  var uuid$1 = require('react-native-uuid');
13
+ var reactNative = require('react-native');
13
14
  var hash = require('object-hash');
14
15
  var Hls = require('hls.js');
15
16
 
@@ -673,6 +674,18 @@ class ASCConnectionError extends ASCError {
673
674
  : 800210 /* Amity.ClientError.CONNECTION_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
674
675
  this.event = event;
675
676
  }
677
+ }
678
+ /**
679
+ * Input sanitization related error
680
+ * @category Errors
681
+ */
682
+ class ASCInvalidParameterError extends ASCError {
683
+ /**
684
+ * @param message A custom error message
685
+ */
686
+ constructor(message) {
687
+ super(message, 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
688
+ }
676
689
  }
677
690
 
678
691
  let activeClient = null;
@@ -9150,6 +9163,43 @@ const isConnected = () => {
9150
9163
  client.ws.connected);
9151
9164
  };
9152
9165
 
9166
+ const registerPushNotification = async (deviceToken) => {
9167
+ const client = getActiveClient();
9168
+ let platform;
9169
+ if (reactNative.Platform.OS === 'ios' || reactNative.Platform.OS === 'android') {
9170
+ platform = reactNative.Platform.OS;
9171
+ }
9172
+ else {
9173
+ throw new ASCInvalidParameterError('Unsupported platform');
9174
+ }
9175
+ const deviceId = await getDeviceId();
9176
+ const { data: { status, error }, } = await client.http.post('/v1/notification', {
9177
+ userId: client.userId,
9178
+ deviceId,
9179
+ platform,
9180
+ token: deviceToken,
9181
+ }, { headers: { 'X-API-Key': client.apiKey } });
9182
+ if (error) {
9183
+ throw new ASCApiError(error, 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
9184
+ }
9185
+ return status === 'success';
9186
+ };
9187
+
9188
+ const unregisterPushNotification = async () => {
9189
+ const client = getActiveClient();
9190
+ const deviceId = getDeviceId();
9191
+ const { data: { status, error }, } = await client.http.delete('/v1/notification', {
9192
+ data: {
9193
+ deviceId,
9194
+ },
9195
+ headers: { 'X-API-Key': client.apiKey },
9196
+ });
9197
+ if (error) {
9198
+ throw new ASCApiError(error, 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
9199
+ }
9200
+ return status === 'success';
9201
+ };
9202
+
9153
9203
  /**
9154
9204
  * ```js
9155
9205
  * import { onChannelMarkerFetched } from '@amityco/ts-sdk-react-native'
@@ -9680,6 +9730,8 @@ var index$k = /*#__PURE__*/Object.freeze({
9680
9730
  renewal: renewal,
9681
9731
  markerSync: markerSync,
9682
9732
  enableUnreadCount: enableUnreadCount,
9733
+ registerPushNotification: registerPushNotification,
9734
+ unregisterPushNotification: unregisterPushNotification,
9683
9735
  onConnectionError: onConnectionError,
9684
9736
  onClientDisconnected: onClientDisconnected,
9685
9737
  onClientBanned: onClientBanned,
package/dist/index.esm.js CHANGED
@@ -6,6 +6,7 @@ import HttpAgent, { HttpsAgent } from 'agentkeepalive';
6
6
  import io from 'socket.io-client';
7
7
  import AsyncStorage from '@react-native-async-storage/async-storage';
8
8
  import uuid$1 from 'react-native-uuid';
9
+ import { Platform } from 'react-native';
9
10
  import hash from 'object-hash';
10
11
  import Hls from 'hls.js';
11
12
 
@@ -639,6 +640,18 @@ class ASCConnectionError extends ASCError {
639
640
  : 800210 /* Amity.ClientError.CONNECTION_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
640
641
  this.event = event;
641
642
  }
643
+ }
644
+ /**
645
+ * Input sanitization related error
646
+ * @category Errors
647
+ */
648
+ class ASCInvalidParameterError extends ASCError {
649
+ /**
650
+ * @param message A custom error message
651
+ */
652
+ constructor(message) {
653
+ super(message, 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
654
+ }
642
655
  }
643
656
 
644
657
  let activeClient = null;
@@ -25221,6 +25234,43 @@ const isConnected = () => {
25221
25234
  client.ws.connected);
25222
25235
  };
25223
25236
 
25237
+ const registerPushNotification = async (deviceToken) => {
25238
+ const client = getActiveClient();
25239
+ let platform;
25240
+ if (Platform.OS === 'ios' || Platform.OS === 'android') {
25241
+ platform = Platform.OS;
25242
+ }
25243
+ else {
25244
+ throw new ASCInvalidParameterError('Unsupported platform');
25245
+ }
25246
+ const deviceId = await getDeviceId();
25247
+ const { data: { status, error }, } = await client.http.post('/v1/notification', {
25248
+ userId: client.userId,
25249
+ deviceId,
25250
+ platform,
25251
+ token: deviceToken,
25252
+ }, { headers: { 'X-API-Key': client.apiKey } });
25253
+ if (error) {
25254
+ throw new ASCApiError(error, 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
25255
+ }
25256
+ return status === 'success';
25257
+ };
25258
+
25259
+ const unregisterPushNotification = async () => {
25260
+ const client = getActiveClient();
25261
+ const deviceId = getDeviceId();
25262
+ const { data: { status, error }, } = await client.http.delete('/v1/notification', {
25263
+ data: {
25264
+ deviceId,
25265
+ },
25266
+ headers: { 'X-API-Key': client.apiKey },
25267
+ });
25268
+ if (error) {
25269
+ throw new ASCApiError(error, 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
25270
+ }
25271
+ return status === 'success';
25272
+ };
25273
+
25224
25274
  /**
25225
25275
  * ```js
25226
25276
  * import { onChannelMarkerFetched } from '@amityco/ts-sdk-react-native'
@@ -25751,6 +25801,8 @@ var index$k = /*#__PURE__*/Object.freeze({
25751
25801
  renewal: renewal,
25752
25802
  markerSync: markerSync,
25753
25803
  enableUnreadCount: enableUnreadCount,
25804
+ registerPushNotification: registerPushNotification,
25805
+ unregisterPushNotification: unregisterPushNotification,
25754
25806
  onConnectionError: onConnectionError,
25755
25807
  onClientDisconnected: onClientDisconnected,
25756
25808
  onClientBanned: onClientBanned,