@unvired/react-native-unvired-sdk 0.0.45 → 0.0.47
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/BuildNo.txt +1 -1
- package/dist/database/DatabaseManager.d.ts +10 -1
- package/dist/database/DatabaseManager.js +22 -2
- package/dist/database/DatabaseManager.web.d.ts +7 -0
- package/dist/database/DatabaseManager.web.js +8 -1
- package/dist/database/index.d.ts +3 -0
- package/dist/database/index.js +3 -0
- package/dist/database/services/DatabaseExpo.d.ts +14 -0
- package/dist/database/services/DatabaseExpo.js +284 -0
- package/dist/database/services/DatabaseNative.d.ts +2 -0
- package/dist/database/services/DatabaseNative.js +134 -41
- package/dist/database/services/DatabaseWeb.d.ts +1 -0
- package/dist/database/services/DatabaseWeb.js +138 -34
- package/dist/device-info/services/DeviceInfoNative.js +50 -3
- package/dist/file-system/FileSystem.d.ts +12 -3
- package/dist/file-system/FileSystem.js +34 -6
- package/dist/file-system/index.d.ts +4 -1
- package/dist/file-system/index.js +3 -0
- package/dist/file-system/services/FileSystemExpo.d.ts +22 -0
- package/dist/file-system/services/FileSystemExpo.js +336 -0
- package/dist/file-system/services/FileSystemNative.d.ts +24 -3
- package/dist/file-system/services/FileSystemNative.js +127 -36
- package/dist/file-system/services/FileSystemWeb.d.ts +1 -1
- package/dist/file-system/services/FileSystemWeb.js +86 -94
- package/dist/local-storage/services/StorageNative.d.ts +1 -0
- package/dist/local-storage/services/StorageNative.js +51 -12
- package/dist/logger/BaseLogger.js +4 -0
- package/dist/main.d.ts +3 -3
- package/dist/main.js +2 -2
- package/dist/push-notification/services/PushNotificationNative.js +182 -68
- package/package.json +21 -1
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
let ExpoFS = null;
|
|
2
|
+
try {
|
|
3
|
+
ExpoFS = require('expo-file-system');
|
|
4
|
+
}
|
|
5
|
+
catch (e) {
|
|
6
|
+
ExpoFS = null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* DirectoryReader implementation for Expo
|
|
10
|
+
*/
|
|
11
|
+
class ExpoDirectoryReader {
|
|
12
|
+
constructor(dirPath) {
|
|
13
|
+
this.dirPath = dirPath.replace(/\/+$/, '');
|
|
14
|
+
}
|
|
15
|
+
readEntries(callback, errorCallback) {
|
|
16
|
+
if (!ExpoFS) {
|
|
17
|
+
errorCallback(new Error('expo-file-system is not installed'));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
ExpoFS.readDirectoryAsync(this.dirPath)
|
|
21
|
+
.then(async (names) => {
|
|
22
|
+
const entries = [];
|
|
23
|
+
for (const name of names) {
|
|
24
|
+
const itemPath = `${this.dirPath}/${name}`;
|
|
25
|
+
try {
|
|
26
|
+
const info = await ExpoFS.getInfoAsync(itemPath);
|
|
27
|
+
entries.push(new ExpoFileEntry(itemPath, info.isDirectory));
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
entries.push(new ExpoFileEntry(itemPath, false));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
callback(entries);
|
|
34
|
+
})
|
|
35
|
+
.catch(errorCallback);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* FileEntry implementation for Expo
|
|
40
|
+
*/
|
|
41
|
+
class ExpoFileEntry {
|
|
42
|
+
constructor(path, isDirectory = false) {
|
|
43
|
+
const cleanPath = path.replace(/^file:\/\//, '').replace(/\/+$/, '');
|
|
44
|
+
this.isDirectory = isDirectory;
|
|
45
|
+
this.isFile = !isDirectory;
|
|
46
|
+
// Cordova spec: directories must end with trailing slash in fullPath and nativeURL
|
|
47
|
+
this.fullPath = isDirectory ? `${cleanPath}/` : cleanPath;
|
|
48
|
+
this.nativeURL = `file://${this.fullPath}`;
|
|
49
|
+
this.name = cleanPath.split('/').pop() || '';
|
|
50
|
+
this.filesystem = null;
|
|
51
|
+
}
|
|
52
|
+
remove(callback, errorCallback) {
|
|
53
|
+
if (!ExpoFS) {
|
|
54
|
+
errorCallback(new Error('expo-file-system is not installed'));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const targetPath = this.fullPath.replace(/\/+$/, '');
|
|
58
|
+
ExpoFS.deleteAsync(targetPath, { idempotent: true })
|
|
59
|
+
.then(() => callback())
|
|
60
|
+
.catch(errorCallback);
|
|
61
|
+
}
|
|
62
|
+
removeRecursively(callback, errorCallback) {
|
|
63
|
+
if (!ExpoFS) {
|
|
64
|
+
errorCallback(new Error('expo-file-system is not installed'));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const targetPath = this.fullPath.replace(/\/+$/, '');
|
|
68
|
+
ExpoFS.deleteAsync(targetPath, { idempotent: true })
|
|
69
|
+
.then(() => callback())
|
|
70
|
+
.catch(errorCallback);
|
|
71
|
+
}
|
|
72
|
+
createReader() {
|
|
73
|
+
return new ExpoDirectoryReader(this.fullPath);
|
|
74
|
+
}
|
|
75
|
+
getDirectory(path, options, callback, errorCallback) {
|
|
76
|
+
if (!ExpoFS) {
|
|
77
|
+
errorCallback(new Error('expo-file-system is not installed'));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const basePath = this.fullPath.replace(/\/+$/, '');
|
|
81
|
+
const relPath = path.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
82
|
+
const dirPath = `${basePath}/${relPath}`;
|
|
83
|
+
ExpoFS.getInfoAsync(dirPath)
|
|
84
|
+
.then((info) => {
|
|
85
|
+
if (info.exists) {
|
|
86
|
+
if (info.isDirectory) {
|
|
87
|
+
callback(new ExpoFileEntry(dirPath, true));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
errorCallback(new Error('Path exists but is not a directory'));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (options.create) {
|
|
94
|
+
return ExpoFS.makeDirectoryAsync(dirPath, { intermediates: true }).then(() => {
|
|
95
|
+
callback(new ExpoFileEntry(dirPath, true));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
errorCallback(new Error('Directory does not exist'));
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
.catch(errorCallback);
|
|
103
|
+
}
|
|
104
|
+
getFile(path, options, callback, errorCallback) {
|
|
105
|
+
if (!ExpoFS) {
|
|
106
|
+
errorCallback(new Error('expo-file-system is not installed'));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const basePath = this.fullPath.replace(/\/+$/, '');
|
|
110
|
+
const relPath = path.replace(/^\/+/, '');
|
|
111
|
+
const filePath = `${basePath}/${relPath}`;
|
|
112
|
+
ExpoFS.getInfoAsync(filePath)
|
|
113
|
+
.then((info) => {
|
|
114
|
+
var _a;
|
|
115
|
+
if (info.exists) {
|
|
116
|
+
if (!info.isDirectory) {
|
|
117
|
+
callback(new ExpoFileEntry(filePath, false));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
errorCallback(new Error('Path exists but is a directory'));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else if (options.create) {
|
|
124
|
+
return ExpoFS.writeAsStringAsync(filePath, '', { encoding: ((_a = ExpoFS.EncodingType) === null || _a === void 0 ? void 0 : _a.UTF8) || 'utf8' }).then(() => {
|
|
125
|
+
callback(new ExpoFileEntry(filePath, false));
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
errorCallback(new Error('File does not exist'));
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
.catch(errorCallback);
|
|
133
|
+
}
|
|
134
|
+
file(callback, errorCallback) {
|
|
135
|
+
if (!ExpoFS) {
|
|
136
|
+
errorCallback(new Error('expo-file-system is not installed'));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const targetPath = this.fullPath.replace(/\/+$/, '');
|
|
140
|
+
ExpoFS.getInfoAsync(targetPath)
|
|
141
|
+
.then((info) => {
|
|
142
|
+
const fileObject = {
|
|
143
|
+
name: targetPath.split('/').pop() || '',
|
|
144
|
+
size: info.size || 0,
|
|
145
|
+
type: '',
|
|
146
|
+
lastModified: info.modificationTime ? info.modificationTime * 1000 : Date.now(),
|
|
147
|
+
lastModifiedDate: info.modificationTime ? new Date(info.modificationTime * 1000) : new Date(),
|
|
148
|
+
path: targetPath,
|
|
149
|
+
};
|
|
150
|
+
callback(fileObject);
|
|
151
|
+
})
|
|
152
|
+
.catch(errorCallback);
|
|
153
|
+
}
|
|
154
|
+
createWriter(callback, errorCallback) {
|
|
155
|
+
const filePath = this.fullPath.replace(/\/+$/, '');
|
|
156
|
+
const writer = {
|
|
157
|
+
filePath: filePath,
|
|
158
|
+
write: async (data) => {
|
|
159
|
+
var _a;
|
|
160
|
+
try {
|
|
161
|
+
await ExpoFS.writeAsStringAsync(filePath, data, { encoding: ((_a = ExpoFS.EncodingType) === null || _a === void 0 ? void 0 : _a.UTF8) || 'utf8' });
|
|
162
|
+
if (writer.onwriteend)
|
|
163
|
+
writer.onwriteend();
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
if (writer.onerror)
|
|
167
|
+
writer.onerror(err);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
append: async (data) => {
|
|
171
|
+
var _a, _b;
|
|
172
|
+
try {
|
|
173
|
+
let existing = '';
|
|
174
|
+
try {
|
|
175
|
+
existing = await ExpoFS.readAsStringAsync(filePath, { encoding: ((_a = ExpoFS.EncodingType) === null || _a === void 0 ? void 0 : _a.UTF8) || 'utf8' });
|
|
176
|
+
}
|
|
177
|
+
catch (e) { }
|
|
178
|
+
await ExpoFS.writeAsStringAsync(filePath, existing + data, { encoding: ((_b = ExpoFS.EncodingType) === null || _b === void 0 ? void 0 : _b.UTF8) || 'utf8' });
|
|
179
|
+
if (writer.onwriteend)
|
|
180
|
+
writer.onwriteend();
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
if (writer.onerror)
|
|
184
|
+
writer.onerror(err);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
truncate: async (size) => {
|
|
188
|
+
var _a, _b;
|
|
189
|
+
try {
|
|
190
|
+
const content = await ExpoFS.readAsStringAsync(filePath, { encoding: ((_a = ExpoFS.EncodingType) === null || _a === void 0 ? void 0 : _a.UTF8) || 'utf8' });
|
|
191
|
+
const truncated = content.substring(0, size);
|
|
192
|
+
await ExpoFS.writeAsStringAsync(filePath, truncated, { encoding: ((_b = ExpoFS.EncodingType) === null || _b === void 0 ? void 0 : _b.UTF8) || 'utf8' });
|
|
193
|
+
if (writer.onwriteend)
|
|
194
|
+
writer.onwriteend();
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
if (writer.onerror)
|
|
198
|
+
writer.onerror(err);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
seek: (_offset) => {
|
|
202
|
+
return Promise.resolve();
|
|
203
|
+
},
|
|
204
|
+
onwriteend: null,
|
|
205
|
+
onerror: null
|
|
206
|
+
};
|
|
207
|
+
try {
|
|
208
|
+
callback(writer);
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
errorCallback(error);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* FileSystem implementation for Expo using expo-file-system
|
|
217
|
+
*/
|
|
218
|
+
export class FileSystemExpo {
|
|
219
|
+
static isAvailable() {
|
|
220
|
+
return ExpoFS != null && (typeof ExpoFS.documentDirectory === 'string' || typeof ExpoFS.getInfoAsync === 'function');
|
|
221
|
+
}
|
|
222
|
+
normalizeEncoding(encoding = 'utf8') {
|
|
223
|
+
var _a, _b;
|
|
224
|
+
if (encoding === 'base64') {
|
|
225
|
+
return ((_a = ExpoFS === null || ExpoFS === void 0 ? void 0 : ExpoFS.EncodingType) === null || _a === void 0 ? void 0 : _a.Base64) || 'base64';
|
|
226
|
+
}
|
|
227
|
+
return ((_b = ExpoFS === null || ExpoFS === void 0 ? void 0 : ExpoFS.EncodingType) === null || _b === void 0 ? void 0 : _b.UTF8) || 'utf8';
|
|
228
|
+
}
|
|
229
|
+
getDocDir() {
|
|
230
|
+
const docDir = (ExpoFS === null || ExpoFS === void 0 ? void 0 : ExpoFS.documentDirectory) || '';
|
|
231
|
+
return docDir.replace(/^file:\/\//, '').replace(/\/$/, '');
|
|
232
|
+
}
|
|
233
|
+
getDocumentDirectory() {
|
|
234
|
+
return this.getDocDir();
|
|
235
|
+
}
|
|
236
|
+
async resolveLocalFileSystemURL(url) {
|
|
237
|
+
if (!ExpoFS) {
|
|
238
|
+
throw new Error('expo-file-system is not installed');
|
|
239
|
+
}
|
|
240
|
+
let cleanPath = url.replace(/^file:\/\//, '');
|
|
241
|
+
try {
|
|
242
|
+
cleanPath = decodeURIComponent(cleanPath);
|
|
243
|
+
}
|
|
244
|
+
catch (e) { }
|
|
245
|
+
cleanPath = cleanPath.replace(/\/+/g, '/').replace(/\/+$/, '');
|
|
246
|
+
const info = await ExpoFS.getInfoAsync(cleanPath);
|
|
247
|
+
if (!info.exists) {
|
|
248
|
+
throw new Error(`Path does not exist: ${cleanPath}`);
|
|
249
|
+
}
|
|
250
|
+
return new ExpoFileEntry(cleanPath, info.isDirectory);
|
|
251
|
+
}
|
|
252
|
+
async getFolderBasedOnUserId(userId) {
|
|
253
|
+
const userPath = `${this.getDocDir()}/${userId}`;
|
|
254
|
+
const info = await ExpoFS.getInfoAsync(userPath);
|
|
255
|
+
if (!info.exists) {
|
|
256
|
+
await ExpoFS.makeDirectoryAsync(userPath, { intermediates: true });
|
|
257
|
+
}
|
|
258
|
+
// Return native URL with trailing slash!
|
|
259
|
+
return `file://${userPath}/`;
|
|
260
|
+
}
|
|
261
|
+
async deleteUserFolder(userId) {
|
|
262
|
+
const userPath = `${this.getDocDir()}/${userId}`;
|
|
263
|
+
const info = await ExpoFS.getInfoAsync(userPath);
|
|
264
|
+
if (info.exists) {
|
|
265
|
+
await ExpoFS.deleteAsync(userPath, { idempotent: true });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async createDirectory(path) {
|
|
269
|
+
const cleanPath = path.replace(/^file:\/\//, '').replace(/\/+$/, '');
|
|
270
|
+
const info = await ExpoFS.getInfoAsync(cleanPath);
|
|
271
|
+
if (!info.exists) {
|
|
272
|
+
await ExpoFS.makeDirectoryAsync(cleanPath, { intermediates: true });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async readFile(path, encoding = 'utf8') {
|
|
276
|
+
const cleanPath = path.replace(/^file:\/\//, '').replace(/\/+$/, '');
|
|
277
|
+
return await ExpoFS.readAsStringAsync(cleanPath, { encoding: this.normalizeEncoding(encoding) });
|
|
278
|
+
}
|
|
279
|
+
async writeFile(path, content, encoding = 'utf8') {
|
|
280
|
+
const cleanPath = path.replace(/^file:\/\//, '').replace(/\/+$/, '');
|
|
281
|
+
await ExpoFS.writeAsStringAsync(cleanPath, content, { encoding: this.normalizeEncoding(encoding) });
|
|
282
|
+
}
|
|
283
|
+
async deleteFile(path) {
|
|
284
|
+
const cleanPath = path.replace(/^file:\/\//, '').replace(/\/+$/, '');
|
|
285
|
+
const info = await ExpoFS.getInfoAsync(cleanPath);
|
|
286
|
+
if (info.exists) {
|
|
287
|
+
await ExpoFS.deleteAsync(cleanPath, { idempotent: true });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async exists(path) {
|
|
291
|
+
const cleanPath = path.replace(/^file:\/\//, '').replace(/\/+$/, '');
|
|
292
|
+
const info = await ExpoFS.getInfoAsync(cleanPath);
|
|
293
|
+
return Boolean(info.exists);
|
|
294
|
+
}
|
|
295
|
+
async stat(path) {
|
|
296
|
+
const cleanPath = path.replace(/^file:\/\//, '').replace(/\/+$/, '');
|
|
297
|
+
const info = await ExpoFS.getInfoAsync(cleanPath);
|
|
298
|
+
return {
|
|
299
|
+
size: info.size || 0,
|
|
300
|
+
mtime: info.modificationTime ? new Date(info.modificationTime * 1000) : new Date(),
|
|
301
|
+
isDirectory: () => Boolean(info.isDirectory),
|
|
302
|
+
isFile: () => !Boolean(info.isDirectory),
|
|
303
|
+
path: cleanPath
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
async readDir(path) {
|
|
307
|
+
const cleanPath = path.replace(/^file:\/\//, '').replace(/\/+$/, '');
|
|
308
|
+
const names = await ExpoFS.readDirectoryAsync(cleanPath);
|
|
309
|
+
const results = [];
|
|
310
|
+
for (const name of names) {
|
|
311
|
+
const itemPath = `${cleanPath}/${name}`;
|
|
312
|
+
const info = await ExpoFS.getInfoAsync(itemPath);
|
|
313
|
+
results.push({
|
|
314
|
+
name: name,
|
|
315
|
+
path: itemPath,
|
|
316
|
+
size: info.size || 0,
|
|
317
|
+
mtime: info.modificationTime ? new Date(info.modificationTime * 1000) : new Date(),
|
|
318
|
+
isDirectory: () => Boolean(info.isDirectory),
|
|
319
|
+
isFile: () => !Boolean(info.isDirectory)
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return results;
|
|
323
|
+
}
|
|
324
|
+
async copyFile(source, destination) {
|
|
325
|
+
await ExpoFS.copyAsync({
|
|
326
|
+
from: source.replace(/^file:\/\//, '').replace(/\/+$/, ''),
|
|
327
|
+
to: destination.replace(/^file:\/\//, '').replace(/\/+$/, '')
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
async moveFile(source, destination) {
|
|
331
|
+
await ExpoFS.moveAsync({
|
|
332
|
+
from: source.replace(/^file:\/\//, '').replace(/\/+$/, ''),
|
|
333
|
+
to: destination.replace(/^file:\/\//, '').replace(/\/+$/, '')
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
import * as RNFS from 'react-native-fs';
|
|
2
1
|
import type { IFileEntry, IFileSystem, FileSystemEncoding } from '../FileSystem';
|
|
2
|
+
export interface RNFSStatResult {
|
|
3
|
+
name?: string;
|
|
4
|
+
path: string;
|
|
5
|
+
size: number;
|
|
6
|
+
mode?: number;
|
|
7
|
+
ctime?: number;
|
|
8
|
+
mtime?: number | Date;
|
|
9
|
+
originalFilepath?: string;
|
|
10
|
+
isFile: () => boolean;
|
|
11
|
+
isDirectory: () => boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface RNFSReadDirItem {
|
|
14
|
+
name: string;
|
|
15
|
+
path: string;
|
|
16
|
+
size: number;
|
|
17
|
+
isFile: () => boolean;
|
|
18
|
+
isDirectory: () => boolean;
|
|
19
|
+
}
|
|
3
20
|
export declare class FileSystemNative implements IFileSystem {
|
|
21
|
+
/**
|
|
22
|
+
* Check if react-native-fs is available in runtime
|
|
23
|
+
*/
|
|
24
|
+
static isAvailable(): boolean;
|
|
4
25
|
getDocumentDirectory(): string;
|
|
5
26
|
resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
|
|
6
27
|
getFolderBasedOnUserId(userId: string): Promise<string>;
|
|
@@ -10,8 +31,8 @@ export declare class FileSystemNative implements IFileSystem {
|
|
|
10
31
|
writeFile(path: string, content: string, encoding?: FileSystemEncoding): Promise<void>;
|
|
11
32
|
deleteFile(path: string): Promise<void>;
|
|
12
33
|
exists(path: string): Promise<boolean>;
|
|
13
|
-
stat(path: string): Promise<
|
|
14
|
-
readDir(path: string): Promise<
|
|
34
|
+
stat(path: string): Promise<RNFSStatResult>;
|
|
35
|
+
readDir(path: string): Promise<RNFSReadDirItem[]>;
|
|
15
36
|
copyFile(source: string, destination: string): Promise<void>;
|
|
16
37
|
moveFile(source: string, destination: string): Promise<void>;
|
|
17
38
|
}
|