apps-sdk 1.0.19 → 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.19",
3
+ "version": "1.0.20",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,6 +2,7 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
2
2
  import * as MediaLibrary from 'expo-media-library';
3
3
  import * as FileSystem from 'expo-file-system';
4
4
  import * as Sharing from 'expo-sharing';
5
+ import utils from "./Utils";
5
6
 
6
7
  class Storage {
7
8
  async storeData(key, value) {
@@ -48,9 +49,14 @@ class Storage {
48
49
  async handleDownloadImage(url, fileName) {
49
50
  const { status } = await MediaLibrary.requestPermissionsAsync();
50
51
  if (status === 'granted') {
51
- const fileUri = FileSystem.documentDirectory + fileName;
52
- const { uri: localUri } = await FileSystem.downloadAsync(url, fileUri);
53
- const asset = await MediaLibrary.createAssetAsync(localUri);
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;
58
+ }
59
+ const asset = await MediaLibrary.createAssetAsync(fileUri);
54
60
  const albums = await MediaLibrary.getAlbumsAsync();
55
61
  let album = albums.find(a => a.title === 'Camera' || a.title === 'Camera Roll' || a.title === 'Pictures');
56
62
  if (album) {
@@ -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
@@ -67,6 +67,10 @@ declare module 'apps-sdk' {
67
67
  handleShareFile(url: string, filename: string): Promise<void>;
68
68
  }
69
69
 
70
+ export class Utils {
71
+ isBase64(str: string): boolean;
72
+ }
73
+
70
74
  export class NotificationsPush {
71
75
  initialize(): Promise<void>;
72
76
  registerForPushNotificationsAsync(): Promise<string>;