apps-sdk 1.0.18 → 1.0.20

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import {NotificationsPush, Networking, Storage, Session} from "./src/libraries";
1
+ import {NotificationsPush, Networking, Storage, Session, Utils} from "./src/libraries";
2
2
 
3
3
  class AppsSDK {
4
4
  initializePushNotifications = async() => {
@@ -16,5 +16,6 @@ export default {
16
16
  initializePushNotifications: Core.initializePushNotifications,
17
17
  networking: Networking,
18
18
  storage: Storage,
19
- session: Session
19
+ session: Session,
20
+ utils: Utils
20
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,9 +13,11 @@
13
13
  "crypto-es": "^2.1.0",
14
14
  "expo-constants": "^15.4.5",
15
15
  "expo-device": "^5.9.3",
16
+ "expo-file-system": "^16.0.6",
16
17
  "expo-localization": "^14.8.3",
17
18
  "expo-media-library": "^15.9.1",
18
19
  "expo-notifications": "^0.23.0",
20
+ "expo-sharing": "^11.10.0",
19
21
  "react-native": "^0.73.2"
20
22
  },
21
23
  "types": "./types/index.d.ts"
@@ -1,5 +1,8 @@
1
1
  import AsyncStorage from "@react-native-async-storage/async-storage";
2
2
  import * as MediaLibrary from 'expo-media-library';
3
+ import * as FileSystem from 'expo-file-system';
4
+ import * as Sharing from 'expo-sharing';
5
+ import utils from "./Utils";
3
6
 
4
7
  class Storage {
5
8
  async storeData(key, value) {
@@ -43,17 +46,17 @@ class Storage {
43
46
  }
44
47
  }
45
48
 
46
- async handleDownloadImage(url) {
49
+ async handleDownloadImage(url, fileName) {
47
50
  const { status } = await MediaLibrary.requestPermissionsAsync();
48
51
  if (status === 'granted') {
49
- const parsedUrl = new URL(url);
50
- let fileName = parsedUrl.pathname.split('/').pop();
51
- if (parsedUrl.searchParams.has('f')) {
52
- fileName = decodeURIComponent(parsedUrl.searchParams.get('f')).split('/').pop();
52
+ let fileUri = FileSystem.documentDirectory + fileName;
53
+ if (utils.isBase64(url)) {
54
+ await FileSystem.writeAsStringAsync(fileUri, url, { encoding: FileSystem.EncodingType.Base64 });
55
+ } else {
56
+ const { uri: localUri } = await FileSystem.downloadAsync(url, fileUri);
57
+ fileUri = localUri;
53
58
  }
54
- const fileUri = FileSystem.documentDirectory + fileName;
55
- const { uri: localUri } = await FileSystem.downloadAsync(url, fileUri);
56
- const asset = await MediaLibrary.createAssetAsync(localUri);
59
+ const asset = await MediaLibrary.createAssetAsync(fileUri);
57
60
  const albums = await MediaLibrary.getAlbumsAsync();
58
61
  let album = albums.find(a => a.title === 'Camera' || a.title === 'Camera Roll' || a.title === 'Pictures');
59
62
  if (album) {
@@ -65,6 +68,16 @@ class Storage {
65
68
  console.log('Permiso de galería denegado');
66
69
  }
67
70
  }
71
+
72
+ async handleShareFile(url, fileName) {
73
+ const fileUri = FileSystem.documentDirectory + fileName;
74
+ const { uri: localUri } = await FileSystem.downloadAsync(url, fileUri);
75
+ if (!(await Sharing.isAvailableAsync())) {
76
+ alert('Compartir no está disponible en tu plataforma.');
77
+ return;
78
+ }
79
+ await Sharing.shareAsync(localUri);
80
+ }
68
81
  }
69
82
 
70
83
  export default new Storage();
@@ -0,0 +1,12 @@
1
+ class Utils {
2
+ isBase64(str) {
3
+ if (str ==='' || str.trim() ===''){ return false; }
4
+ try {
5
+ return btoa(atob(str)) === str;
6
+ } catch (err) {
7
+ return false;
8
+ }
9
+ }
10
+ }
11
+
12
+ export default new Utils();
@@ -2,4 +2,5 @@ export { default as NotificationsPush } from './Notifications';
2
2
  export { default as Networking } from './Networking';
3
3
  export { default as Storage } from './Storage';
4
4
  export { default as Session } from './Session';
5
+ export { default as Utils } from './Utils';
5
6
 
package/types/index.d.ts CHANGED
@@ -64,6 +64,11 @@ declare module 'apps-sdk' {
64
64
  printAllKeys(): Promise<void>;
65
65
  removeData(key: string): Promise<void>;
66
66
  handleDownloadImage(url: string, filename: string): Promise<void>;
67
+ handleShareFile(url: string, filename: string): Promise<void>;
68
+ }
69
+
70
+ export class Utils {
71
+ isBase64(str: string): boolean;
67
72
  }
68
73
 
69
74
  export class NotificationsPush {