@amityco/ts-sdk-react-native 6.28.0 → 6.28.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../../../src/fileRepository/api/uploadFile.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,6CACX,QAAQ,0BACK,MAAM,KAAK,IAAI,kBACrC,QAAQ,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC,CAmCpC,CAAC"}
1
+ {"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../../../src/fileRepository/api/uploadFile.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,6CACX,QAAQ,0BACK,MAAM,KAAK,IAAI,kBACrC,QAAQ,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC,CAuCpC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"uploadImage.d.ts","sourceRoot":"","sources":["../../../src/fileRepository/api/uploadImage.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,aACZ,QAAQ,0BACK,MAAM,KAAK,IAAI,kBACrC,QAAQ,MAAM,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAuC7C,CAAC"}
1
+ {"version":3,"file":"uploadImage.d.ts","sourceRoot":"","sources":["../../../src/fileRepository/api/uploadImage.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,aACZ,QAAQ,0BACK,MAAM,KAAK,IAAI,kBACrC,QAAQ,MAAM,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAuC7C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"uploadVideo.d.ts","sourceRoot":"","sources":["../../../src/fileRepository/api/uploadVideo.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,WAAW,aACZ,QAAQ,aACP,MAAM,eAAe,0BACT,MAAM,KAAK,IAAI,kBACrC,QAAQ,MAAM,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CA2C7C,CAAC"}
1
+ {"version":3,"file":"uploadVideo.d.ts","sourceRoot":"","sources":["../../../src/fileRepository/api/uploadVideo.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,WAAW,aACZ,QAAQ,aACP,MAAM,eAAe,0BACT,MAAM,KAAK,IAAI,kBACrC,QAAQ,MAAM,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CA2C7C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const rebuildFormDataWithMimeType: (formData: FormData) => FormData;
2
+ //# sourceMappingURL=rebuildFormDataWithMimeType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rebuildFormDataWithMimeType.d.ts","sourceRoot":"","sources":["../../../src/fileRepository/utils/rebuildFormDataWithMimeType.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,2BAA2B,aAAc,QAAQ,KAAG,QAahE,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -11,6 +11,7 @@ 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
13
  var reactNative = require('react-native');
14
+ var mime = require('mime');
14
15
  var hash = require('object-hash');
15
16
  var Hls = require('hls.js');
16
17
 
@@ -41,6 +42,7 @@ var HttpAgent__default = /*#__PURE__*/_interopDefaultLegacy(HttpAgent);
41
42
  var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
42
43
  var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
43
44
  var uuid__default = /*#__PURE__*/_interopDefaultLegacy(uuid$1);
45
+ var mime__default = /*#__PURE__*/_interopDefaultLegacy(mime);
44
46
  var hash__default = /*#__PURE__*/_interopDefaultLegacy(hash);
45
47
  var Hls__default = /*#__PURE__*/_interopDefaultLegacy(Hls);
46
48
 
@@ -123,8 +125,8 @@ const PostContentType = Object.freeze({
123
125
 
124
126
  function getVersion() {
125
127
  try {
126
- // the string ''v6.28.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
127
- return 'v6.28.0-cjs';
128
+ // the string ''v6.28.1-cjs'' should be replaced by actual value by @rollup/plugin-replace
129
+ return 'v6.28.1-cjs';
128
130
  }
129
131
  catch (error) {
130
132
  return '__dev__';
@@ -11974,6 +11976,19 @@ getFile.locally = (fileId) => {
11974
11976
  };
11975
11977
  };
11976
11978
 
11979
+ const rebuildFormDataWithMimeType = (formData) => {
11980
+ const files = formData.getAll('files') || [];
11981
+ if (!files.length)
11982
+ return formData;
11983
+ const newFormData = new FormData();
11984
+ const imageFile = files[0];
11985
+ // In ReactNative Android, we need to define a file type for all upload items; otherwise backend will reject a request
11986
+ // @ts-ignore - we need to modify `type` because in android this value will not set by default (https://github.com/axios/axios/issues/4823)
11987
+ imageFile.type = mime__default["default"].getType(imageFile.uri);
11988
+ newFormData.append('files', imageFile);
11989
+ return newFormData;
11990
+ };
11991
+
11977
11992
  /* begin_public_function
11978
11993
  id: file.upload.file
11979
11994
  */
@@ -12004,7 +12019,7 @@ const uploadFile = async (formData, onProgress) => {
12004
12019
  const headers = 'getHeaders' in formData
12005
12020
  ? formData.getHeaders()
12006
12021
  : { 'content-type': 'multipart/form-data' };
12007
- const { data } = await client.http.post('/api/v4/files', formData, {
12022
+ const { data } = await client.http.post('/api/v4/files', rebuildFormDataWithMimeType(formData), {
12008
12023
  headers,
12009
12024
  onUploadProgress({ loaded, total = 100 }) {
12010
12025
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -12094,7 +12109,7 @@ const uploadVideo = async (formData, feedType, onProgress) => {
12094
12109
  const headers = 'getHeaders' in formData
12095
12110
  ? formData.getHeaders()
12096
12111
  : { 'content-type': 'multipart/form-data' };
12097
- const { data } = await client.http.post('/api/v4/videos', formData, {
12112
+ const { data } = await client.http.post('/api/v4/videos', rebuildFormDataWithMimeType(formData), {
12098
12113
  headers,
12099
12114
  onUploadProgress({ loaded, total = 100 }) {
12100
12115
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -12142,7 +12157,7 @@ const uploadImage = async (formData, onProgress) => {
12142
12157
  const headers = 'getHeaders' in formData
12143
12158
  ? formData.getHeaders()
12144
12159
  : { 'content-type': 'multipart/form-data' };
12145
- const { data } = await client.http.post('/api/v4/images', formData, {
12160
+ const { data } = await client.http.post('/api/v4/images', rebuildFormDataWithMimeType(formData), {
12146
12161
  headers,
12147
12162
  onUploadProgress({ loaded, total = 100 }) {
12148
12163
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -23619,12 +23634,11 @@ const createOptimisticEvent = ({ payload, formData = undefined, isVideo = false,
23619
23634
  const fileObject = files[0] || undefined;
23620
23635
  if (!fileObject)
23621
23636
  return;
23622
- const fileData = new FileReader();
23623
- fileData.readAsDataURL(fileObject);
23624
- fileData.onload = () => {
23625
- return callback(saveOptimisticToCache(isVideo
23626
- ? Object.assign(Object.assign({}, payload), { data: Object.assign(Object.assign({}, payload.data), { fileId: undefined, videoFileId: { original: undefined }, fileData: fileData === null || fileData === void 0 ? void 0 : fileData.result }) }) : Object.assign(Object.assign({}, payload), { data: Object.assign(Object.assign({}, payload.data), { fileId: undefined, fileData: fileData === null || fileData === void 0 ? void 0 : fileData.result }) })));
23627
- };
23637
+ const optimisticData = Object.assign(Object.assign({}, payload), { data: Object.assign(Object.assign({}, payload.data), { fileId: undefined, fileData: fileObject.uri }) });
23638
+ if (isVideo) {
23639
+ optimisticData.data.videoFileId = { original: undefined };
23640
+ }
23641
+ return callback(saveOptimisticToCache(optimisticData));
23628
23642
  }
23629
23643
  return callback(saveOptimisticToCache(Object.assign(Object.assign({}, payload), { data: Object.assign(Object.assign({}, payload.data), { fileData: null }) })));
23630
23644
  };
package/dist/index.esm.js CHANGED
@@ -7,6 +7,7 @@ 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
9
  import { Platform } from 'react-native';
10
+ import mime from 'mime';
10
11
  import hash from 'object-hash';
11
12
  import Hls from 'hls.js';
12
13
 
@@ -89,8 +90,8 @@ const PostContentType = Object.freeze({
89
90
 
90
91
  function getVersion() {
91
92
  try {
92
- // the string ''v6.28.0-esm'' should be replaced by actual value by @rollup/plugin-replace
93
- return 'v6.28.0-esm';
93
+ // the string ''v6.28.1-esm'' should be replaced by actual value by @rollup/plugin-replace
94
+ return 'v6.28.1-esm';
94
95
  }
95
96
  catch (error) {
96
97
  return '__dev__';
@@ -28047,6 +28048,19 @@ getFile.locally = (fileId) => {
28047
28048
  };
28048
28049
  };
28049
28050
 
28051
+ const rebuildFormDataWithMimeType = (formData) => {
28052
+ const files = formData.getAll('files') || [];
28053
+ if (!files.length)
28054
+ return formData;
28055
+ const newFormData = new FormData();
28056
+ const imageFile = files[0];
28057
+ // In ReactNative Android, we need to define a file type for all upload items; otherwise backend will reject a request
28058
+ // @ts-ignore - we need to modify `type` because in android this value will not set by default (https://github.com/axios/axios/issues/4823)
28059
+ imageFile.type = mime.getType(imageFile.uri);
28060
+ newFormData.append('files', imageFile);
28061
+ return newFormData;
28062
+ };
28063
+
28050
28064
  /* begin_public_function
28051
28065
  id: file.upload.file
28052
28066
  */
@@ -28077,7 +28091,7 @@ const uploadFile = async (formData, onProgress) => {
28077
28091
  const headers = 'getHeaders' in formData
28078
28092
  ? formData.getHeaders()
28079
28093
  : { 'content-type': 'multipart/form-data' };
28080
- const { data } = await client.http.post('/api/v4/files', formData, {
28094
+ const { data } = await client.http.post('/api/v4/files', rebuildFormDataWithMimeType(formData), {
28081
28095
  headers,
28082
28096
  onUploadProgress({ loaded, total = 100 }) {
28083
28097
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -28167,7 +28181,7 @@ const uploadVideo = async (formData, feedType, onProgress) => {
28167
28181
  const headers = 'getHeaders' in formData
28168
28182
  ? formData.getHeaders()
28169
28183
  : { 'content-type': 'multipart/form-data' };
28170
- const { data } = await client.http.post('/api/v4/videos', formData, {
28184
+ const { data } = await client.http.post('/api/v4/videos', rebuildFormDataWithMimeType(formData), {
28171
28185
  headers,
28172
28186
  onUploadProgress({ loaded, total = 100 }) {
28173
28187
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -28215,7 +28229,7 @@ const uploadImage = async (formData, onProgress) => {
28215
28229
  const headers = 'getHeaders' in formData
28216
28230
  ? formData.getHeaders()
28217
28231
  : { 'content-type': 'multipart/form-data' };
28218
- const { data } = await client.http.post('/api/v4/images', formData, {
28232
+ const { data } = await client.http.post('/api/v4/images', rebuildFormDataWithMimeType(formData), {
28219
28233
  headers,
28220
28234
  onUploadProgress({ loaded, total = 100 }) {
28221
28235
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -39692,12 +39706,11 @@ const createOptimisticEvent = ({ payload, formData = undefined, isVideo = false,
39692
39706
  const fileObject = files[0] || undefined;
39693
39707
  if (!fileObject)
39694
39708
  return;
39695
- const fileData = new FileReader();
39696
- fileData.readAsDataURL(fileObject);
39697
- fileData.onload = () => {
39698
- return callback(saveOptimisticToCache(isVideo
39699
- ? Object.assign(Object.assign({}, payload), { data: Object.assign(Object.assign({}, payload.data), { fileId: undefined, videoFileId: { original: undefined }, fileData: fileData === null || fileData === void 0 ? void 0 : fileData.result }) }) : Object.assign(Object.assign({}, payload), { data: Object.assign(Object.assign({}, payload.data), { fileId: undefined, fileData: fileData === null || fileData === void 0 ? void 0 : fileData.result }) })));
39700
- };
39709
+ const optimisticData = Object.assign(Object.assign({}, payload), { data: Object.assign(Object.assign({}, payload.data), { fileId: undefined, fileData: fileObject.uri }) });
39710
+ if (isVideo) {
39711
+ optimisticData.data.videoFileId = { original: undefined };
39712
+ }
39713
+ return callback(saveOptimisticToCache(optimisticData));
39701
39714
  }
39702
39715
  return callback(saveOptimisticToCache(Object.assign(Object.assign({}, payload), { data: Object.assign(Object.assign({}, payload.data), { fileData: null }) })));
39703
39716
  };