@upfluxhq/capacitor 0.1.0-beta.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.
- package/README.md +220 -0
- package/dist/Upflux.d.ts +92 -0
- package/dist/Upflux.d.ts.map +1 -0
- package/dist/Upflux.js +147 -0
- package/dist/Upflux.js.map +1 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +53 -0
- package/dist/config.js.map +1 -0
- package/dist/http/client.d.ts +28 -0
- package/dist/http/client.d.ts.map +1 -0
- package/dist/http/client.js +118 -0
- package/dist/http/client.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/native/UpfluxModule.d.ts +39 -0
- package/dist/native/UpfluxModule.d.ts.map +1 -0
- package/dist/native/UpfluxModule.js +111 -0
- package/dist/native/UpfluxModule.js.map +1 -0
- package/dist/startup/resolveInitialBundle.d.ts +19 -0
- package/dist/startup/resolveInitialBundle.d.ts.map +1 -0
- package/dist/startup/resolveInitialBundle.js +59 -0
- package/dist/startup/resolveInitialBundle.js.map +1 -0
- package/dist/storage/assetStorage.d.ts +31 -0
- package/dist/storage/assetStorage.d.ts.map +1 -0
- package/dist/storage/assetStorage.js +54 -0
- package/dist/storage/assetStorage.js.map +1 -0
- package/dist/storage/bundleStorage.d.ts +41 -0
- package/dist/storage/bundleStorage.d.ts.map +1 -0
- package/dist/storage/bundleStorage.js +110 -0
- package/dist/storage/bundleStorage.js.map +1 -0
- package/dist/storage/fileSystem.d.ts +69 -0
- package/dist/storage/fileSystem.d.ts.map +1 -0
- package/dist/storage/fileSystem.js +230 -0
- package/dist/storage/fileSystem.js.map +1 -0
- package/dist/types/index.d.ts +119 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/updates/applyUpdate.d.ts +16 -0
- package/dist/updates/applyUpdate.d.ts.map +1 -0
- package/dist/updates/applyUpdate.js +100 -0
- package/dist/updates/applyUpdate.js.map +1 -0
- package/dist/updates/checkForUpdates.d.ts +16 -0
- package/dist/updates/checkForUpdates.d.ts.map +1 -0
- package/dist/updates/checkForUpdates.js +215 -0
- package/dist/updates/checkForUpdates.js.map +1 -0
- package/dist/updates/downloadUpdate.d.ts +18 -0
- package/dist/updates/downloadUpdate.d.ts.map +1 -0
- package/dist/updates/downloadUpdate.js +76 -0
- package/dist/updates/downloadUpdate.js.map +1 -0
- package/dist/updates/manifest.d.ts +17 -0
- package/dist/updates/manifest.d.ts.map +1 -0
- package/dist/updates/manifest.js +42 -0
- package/dist/updates/manifest.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle Storage for Capacitor SDK
|
|
3
|
+
*
|
|
4
|
+
* Manages bundle files and active bundle metadata.
|
|
5
|
+
*/
|
|
6
|
+
import * as FileSystem from './fileSystem';
|
|
7
|
+
import { downloadFile } from '../http/client';
|
|
8
|
+
import JSZip from 'jszip';
|
|
9
|
+
/**
|
|
10
|
+
* Save a bundle from URL to local storage
|
|
11
|
+
* Capacitor bundles are zip files that need to be extracted
|
|
12
|
+
*
|
|
13
|
+
* @param bundleUrl - URL to download the bundle from
|
|
14
|
+
* @param releaseLabel - Release label for directory naming
|
|
15
|
+
* @returns Path to the extracted bundle directory
|
|
16
|
+
*/
|
|
17
|
+
export async function saveBundle(bundleUrl, releaseLabel) {
|
|
18
|
+
const bundleDir = await FileSystem.getBundleDir(releaseLabel);
|
|
19
|
+
console.log(`[BundleStorage] Downloading bundle for ${releaseLabel}...`);
|
|
20
|
+
// Download bundle as ArrayBuffer
|
|
21
|
+
const arrayBuffer = await downloadFile(bundleUrl);
|
|
22
|
+
// Extract the zip file
|
|
23
|
+
console.log(`[BundleStorage] Extracting bundle...`);
|
|
24
|
+
const zip = await JSZip.loadAsync(arrayBuffer);
|
|
25
|
+
// Ensure bundle directory exists
|
|
26
|
+
await FileSystem.mkdir(bundleDir);
|
|
27
|
+
// Extract all files
|
|
28
|
+
const files = Object.keys(zip.files);
|
|
29
|
+
for (const filename of files) {
|
|
30
|
+
const file = zip.files[filename];
|
|
31
|
+
if (file.dir) {
|
|
32
|
+
// Create directory
|
|
33
|
+
await FileSystem.mkdir(`${bundleDir}/${filename}`);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Extract file
|
|
37
|
+
const content = await file.async('blob');
|
|
38
|
+
await FileSystem.writeBinaryFile(`${bundleDir}/${filename}`, content);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
console.log(`[BundleStorage] Bundle extracted to: ${bundleDir}`);
|
|
42
|
+
return bundleDir;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get the currently active bundle metadata
|
|
46
|
+
*/
|
|
47
|
+
export async function getActiveBundleMetadata() {
|
|
48
|
+
try {
|
|
49
|
+
const activeBundlePath = await FileSystem.getActiveBundlePath();
|
|
50
|
+
const content = await FileSystem.readFile(activeBundlePath);
|
|
51
|
+
if (!content) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return JSON.parse(content);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error('[BundleStorage] Error reading active bundle:', error);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get the active bundle path (or null if no active bundle)
|
|
63
|
+
*/
|
|
64
|
+
export async function getActiveBundle() {
|
|
65
|
+
const metadata = await getActiveBundleMetadata();
|
|
66
|
+
return metadata?.bundlePath ?? null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Set the active bundle
|
|
70
|
+
*/
|
|
71
|
+
export async function setActiveBundle(bundlePath, assets, releaseLabel) {
|
|
72
|
+
const metadata = {
|
|
73
|
+
bundlePath,
|
|
74
|
+
assets,
|
|
75
|
+
releaseLabel,
|
|
76
|
+
updatedAt: new Date().toISOString(),
|
|
77
|
+
};
|
|
78
|
+
const activeBundlePath = await FileSystem.getActiveBundlePath();
|
|
79
|
+
await FileSystem.writeFile(activeBundlePath, JSON.stringify(metadata, null, 2));
|
|
80
|
+
console.log(`[BundleStorage] Active bundle set: ${releaseLabel}`);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Clear the active bundle (revert to default)
|
|
84
|
+
*/
|
|
85
|
+
export async function clearActiveBundle() {
|
|
86
|
+
try {
|
|
87
|
+
const activeBundlePath = await FileSystem.getActiveBundlePath();
|
|
88
|
+
await FileSystem.unlink(activeBundlePath);
|
|
89
|
+
console.log('[BundleStorage] Active bundle cleared');
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.warn('[BundleStorage] Error clearing active bundle:', error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Check if a bundle exists at the given path
|
|
97
|
+
*/
|
|
98
|
+
export async function bundleExists(bundlePath) {
|
|
99
|
+
// For Capacitor, check if the index.html exists in the bundle directory
|
|
100
|
+
const indexPath = `${bundlePath}/index.html`;
|
|
101
|
+
return FileSystem.exists(indexPath);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get the default bundle path (www folder in app)
|
|
105
|
+
* For Capacitor, this is handled by the WebView automatically
|
|
106
|
+
*/
|
|
107
|
+
export function getDefaultBundlePath() {
|
|
108
|
+
return '';
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=bundleStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleStorage.js","sourceRoot":"","sources":["../../src/storage/bundleStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,MAAM,OAAO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,gBAAgB,CAAC,CAAC;QAC1C,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,+CAA+C,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,UAAkB;IACjD,wEAAwE;IACxE,MAAM,SAAS,GAAG,GAAG,UAAU,aAAa,CAAC;IAC7C,OAAO,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IAChC,OAAO,EAAE,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File System for Capacitor SDK
|
|
3
|
+
*
|
|
4
|
+
* Uses @capacitor/filesystem for all file operations.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Get the base Upflux directory path
|
|
8
|
+
*/
|
|
9
|
+
export declare function getUpfluxDir(): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the bundle directory for a specific release
|
|
12
|
+
*/
|
|
13
|
+
export declare function getBundleDir(releaseLabel: string): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Get the assets directory for a specific release
|
|
16
|
+
*/
|
|
17
|
+
export declare function getAssetsDir(releaseLabel: string): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the path to activeBundle.json
|
|
20
|
+
*/
|
|
21
|
+
export declare function getActiveBundlePath(): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Read a file as string
|
|
24
|
+
*/
|
|
25
|
+
export declare function readFile(path: string): Promise<string | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Write content to a file
|
|
28
|
+
*/
|
|
29
|
+
export declare function writeFile(path: string, content: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Write binary data to a file
|
|
32
|
+
*/
|
|
33
|
+
export declare function writeBinaryFile(path: string, data: Blob): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Check if a file or directory exists
|
|
36
|
+
*/
|
|
37
|
+
export declare function exists(path: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Create a directory (and parent directories)
|
|
40
|
+
*/
|
|
41
|
+
export declare function mkdir(path: string): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Delete a file or directory
|
|
44
|
+
*/
|
|
45
|
+
export declare function unlink(path: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Delete a directory recursively
|
|
48
|
+
*/
|
|
49
|
+
export declare function rmdir(path: string): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* List files in a directory
|
|
52
|
+
*/
|
|
53
|
+
export declare function readdir(path: string): Promise<string[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Get the full URI for a file path
|
|
56
|
+
*/
|
|
57
|
+
export declare function getUri(path: string): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Copy a file
|
|
60
|
+
*/
|
|
61
|
+
export declare function copyFile(from: string, to: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Get file info
|
|
64
|
+
*/
|
|
65
|
+
export declare function stat(path: string): Promise<{
|
|
66
|
+
size: number;
|
|
67
|
+
mtime: Date;
|
|
68
|
+
} | null>;
|
|
69
|
+
//# sourceMappingURL=fileSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileSystem.d.ts","sourceRoot":"","sources":["../../src/storage/fileSystem.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAEpD;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAExE;AAED;;GAEG;AACH,wBAAsB,YAAY,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AAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG,IAAI,CAAC,CAatF"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File System for Capacitor SDK
|
|
3
|
+
*
|
|
4
|
+
* Uses @capacitor/filesystem for all file operations.
|
|
5
|
+
*/
|
|
6
|
+
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
|
7
|
+
/**
|
|
8
|
+
* Get the base Upflux directory path
|
|
9
|
+
*/
|
|
10
|
+
export async function getUpfluxDir() {
|
|
11
|
+
return 'upflux';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get the bundle directory for a specific release
|
|
15
|
+
*/
|
|
16
|
+
export async function getBundleDir(releaseLabel) {
|
|
17
|
+
return `upflux/${releaseLabel}`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get the assets directory for a specific release
|
|
21
|
+
*/
|
|
22
|
+
export async function getAssetsDir(releaseLabel) {
|
|
23
|
+
return `upflux/${releaseLabel}/assets`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the path to activeBundle.json
|
|
27
|
+
*/
|
|
28
|
+
export async function getActiveBundlePath() {
|
|
29
|
+
return 'upflux/activeBundle.json';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Read a file as string
|
|
33
|
+
*/
|
|
34
|
+
export async function readFile(path) {
|
|
35
|
+
try {
|
|
36
|
+
const result = await Filesystem.readFile({
|
|
37
|
+
path,
|
|
38
|
+
directory: Directory.Data,
|
|
39
|
+
encoding: Encoding.UTF8,
|
|
40
|
+
});
|
|
41
|
+
console.log(`[FileSystem] Read file: ${path}`);
|
|
42
|
+
return result.data;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.log(`[FileSystem] File not found: ${path}`);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Write content to a file
|
|
51
|
+
*/
|
|
52
|
+
export async function writeFile(path, content) {
|
|
53
|
+
try {
|
|
54
|
+
await Filesystem.writeFile({
|
|
55
|
+
path,
|
|
56
|
+
data: content,
|
|
57
|
+
directory: Directory.Data,
|
|
58
|
+
encoding: Encoding.UTF8,
|
|
59
|
+
recursive: true,
|
|
60
|
+
});
|
|
61
|
+
console.log(`[FileSystem] Wrote file: ${path}`);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error(`[FileSystem] Error writing file ${path}:`, error);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Write binary data to a file
|
|
70
|
+
*/
|
|
71
|
+
export async function writeBinaryFile(path, data) {
|
|
72
|
+
try {
|
|
73
|
+
// Convert Blob to base64
|
|
74
|
+
const base64 = await blobToBase64(data);
|
|
75
|
+
await Filesystem.writeFile({
|
|
76
|
+
path,
|
|
77
|
+
data: base64,
|
|
78
|
+
directory: Directory.Data,
|
|
79
|
+
recursive: true,
|
|
80
|
+
});
|
|
81
|
+
console.log(`[FileSystem] Wrote binary file: ${path}`);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error(`[FileSystem] Error writing binary file ${path}:`, error);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Convert Blob to base64 string
|
|
90
|
+
*/
|
|
91
|
+
async function blobToBase64(blob) {
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
const reader = new FileReader();
|
|
94
|
+
reader.onloadend = () => {
|
|
95
|
+
const result = reader.result;
|
|
96
|
+
// Remove data URL prefix if present
|
|
97
|
+
const base64 = result.includes(',') ? result.split(',')[1] : result;
|
|
98
|
+
resolve(base64);
|
|
99
|
+
};
|
|
100
|
+
reader.onerror = reject;
|
|
101
|
+
reader.readAsDataURL(blob);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check if a file or directory exists
|
|
106
|
+
*/
|
|
107
|
+
export async function exists(path) {
|
|
108
|
+
try {
|
|
109
|
+
await Filesystem.stat({
|
|
110
|
+
path,
|
|
111
|
+
directory: Directory.Data,
|
|
112
|
+
});
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Create a directory (and parent directories)
|
|
121
|
+
*/
|
|
122
|
+
export async function mkdir(path) {
|
|
123
|
+
try {
|
|
124
|
+
await Filesystem.mkdir({
|
|
125
|
+
path,
|
|
126
|
+
directory: Directory.Data,
|
|
127
|
+
recursive: true,
|
|
128
|
+
});
|
|
129
|
+
console.log(`[FileSystem] Created directory: ${path}`);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
// Ignore if directory already exists
|
|
133
|
+
if (!error.message?.includes('exists')) {
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Delete a file or directory
|
|
140
|
+
*/
|
|
141
|
+
export async function unlink(path) {
|
|
142
|
+
try {
|
|
143
|
+
await Filesystem.deleteFile({
|
|
144
|
+
path,
|
|
145
|
+
directory: Directory.Data,
|
|
146
|
+
});
|
|
147
|
+
console.log(`[FileSystem] Deleted: ${path}`);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.warn(`[FileSystem] Error deleting ${path}:`, error);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Delete a directory recursively
|
|
155
|
+
*/
|
|
156
|
+
export async function rmdir(path) {
|
|
157
|
+
try {
|
|
158
|
+
await Filesystem.rmdir({
|
|
159
|
+
path,
|
|
160
|
+
directory: Directory.Data,
|
|
161
|
+
recursive: true,
|
|
162
|
+
});
|
|
163
|
+
console.log(`[FileSystem] Deleted directory: ${path}`);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
console.warn(`[FileSystem] Error deleting directory ${path}:`, error);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* List files in a directory
|
|
171
|
+
*/
|
|
172
|
+
export async function readdir(path) {
|
|
173
|
+
try {
|
|
174
|
+
const result = await Filesystem.readdir({
|
|
175
|
+
path,
|
|
176
|
+
directory: Directory.Data,
|
|
177
|
+
});
|
|
178
|
+
return result.files.map((f) => f.name);
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get the full URI for a file path
|
|
186
|
+
*/
|
|
187
|
+
export async function getUri(path) {
|
|
188
|
+
const result = await Filesystem.getUri({
|
|
189
|
+
path,
|
|
190
|
+
directory: Directory.Data,
|
|
191
|
+
});
|
|
192
|
+
return result.uri;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Copy a file
|
|
196
|
+
*/
|
|
197
|
+
export async function copyFile(from, to) {
|
|
198
|
+
try {
|
|
199
|
+
await Filesystem.copy({
|
|
200
|
+
from,
|
|
201
|
+
to,
|
|
202
|
+
directory: Directory.Data,
|
|
203
|
+
toDirectory: Directory.Data,
|
|
204
|
+
});
|
|
205
|
+
console.log(`[FileSystem] Copied: ${from} -> ${to}`);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
console.error(`[FileSystem] Error copying file:`, error);
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get file info
|
|
214
|
+
*/
|
|
215
|
+
export async function stat(path) {
|
|
216
|
+
try {
|
|
217
|
+
const result = await Filesystem.stat({
|
|
218
|
+
path,
|
|
219
|
+
directory: Directory.Data,
|
|
220
|
+
});
|
|
221
|
+
return {
|
|
222
|
+
size: result.size,
|
|
223
|
+
mtime: new Date(result.mtime),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=fileSystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileSystem.js","sourceRoot":"","sources":["../../src/storage/fileSystem.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAExE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY;IAC9B,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,YAAoB;IACnD,OAAO,UAAU,YAAY,EAAE,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,YAAoB;IACnD,OAAO,UAAU,YAAY,SAAS,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACrC,OAAO,0BAA0B,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAY;IACvC,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC;YACrC,IAAI;YACJ,SAAS,EAAE,SAAS,CAAC,IAAI;YACzB,QAAQ,EAAE,QAAQ,CAAC,IAAI;SAC1B,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;QAC/C,OAAO,MAAM,CAAC,IAAc,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,gCAAgC,IAAI,EAAE,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC;IAChB,CAAC;AACL,CAAC;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S,CAAC,IAAI;KAC5B,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,GAAG,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAY,EAAE,EAAU;IACnD,IAAI,CAAC;QACD,MAAM,UAAU,CAAC,IAAI,CAAC;YAClB,IAAI;YACJ,EAAE;YACF,SAAS,EAAE,SAAS,CAAC,IAAI;YACzB,WAAW,EAAE,SAAS,CAAC,IAAI;SAC9B,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,OAAO,EAAE,EAAE,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;QACzD,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAY;IACnC,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC;YACjC,IAAI;YACJ,SAAS,EAAE,SAAS,CAAC,IAAI;SAC5B,CAAC,CAAC;QACH,OAAO;YACH,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,KAAK,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;SAChC,CAAC;IACN,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,IAAI,CAAC;IAChB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upflux Capacitor SDK Types
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* SDK Configuration
|
|
6
|
+
*/
|
|
7
|
+
export interface UpfluxConfig {
|
|
8
|
+
appId: string;
|
|
9
|
+
deployment: string;
|
|
10
|
+
clientKey: string;
|
|
11
|
+
serverUrl: string;
|
|
12
|
+
/** App binary version for update compatibility (e.g., "1.0.0") */
|
|
13
|
+
binaryVersion?: string;
|
|
14
|
+
/** Whether to collect device info (osVersion, deviceModel, etc). Default: true */
|
|
15
|
+
collectDeviceInfo?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Device information for update checks
|
|
19
|
+
*/
|
|
20
|
+
export interface DeviceInfo {
|
|
21
|
+
deviceId: string;
|
|
22
|
+
binaryVersion: string;
|
|
23
|
+
platform?: 'ios' | 'android' | 'web';
|
|
24
|
+
osVersion?: string;
|
|
25
|
+
deviceModel?: string;
|
|
26
|
+
webViewVersion?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Asset metadata from manifest
|
|
30
|
+
*/
|
|
31
|
+
export interface Asset {
|
|
32
|
+
name: string;
|
|
33
|
+
url: string;
|
|
34
|
+
hash?: string;
|
|
35
|
+
size?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Release manifest from server
|
|
39
|
+
*/
|
|
40
|
+
export interface ReleaseManifest {
|
|
41
|
+
releaseId: string;
|
|
42
|
+
releaseLabel: string;
|
|
43
|
+
bundleUrl: string;
|
|
44
|
+
assets: Asset[];
|
|
45
|
+
mandatory: boolean;
|
|
46
|
+
releaseNotes?: string;
|
|
47
|
+
targetBinaryVersion?: string;
|
|
48
|
+
rolloutPercentage?: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Response from update check endpoint
|
|
52
|
+
*/
|
|
53
|
+
export interface UpdateCheckResponse {
|
|
54
|
+
updateAvailable: boolean;
|
|
55
|
+
manifest?: ReleaseManifest;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Information about an available update
|
|
59
|
+
*/
|
|
60
|
+
export interface UpdateInfo {
|
|
61
|
+
updateAvailable: boolean;
|
|
62
|
+
releaseId?: string;
|
|
63
|
+
releaseLabel?: string;
|
|
64
|
+
bundleUrl?: string;
|
|
65
|
+
assets?: Asset[];
|
|
66
|
+
mandatory?: boolean;
|
|
67
|
+
releaseNotes?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Active bundle metadata stored locally
|
|
71
|
+
*/
|
|
72
|
+
export interface ActiveBundleMetadata {
|
|
73
|
+
bundlePath: string;
|
|
74
|
+
assets: string[];
|
|
75
|
+
releaseLabel: string;
|
|
76
|
+
updatedAt: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Result of download operation
|
|
80
|
+
*/
|
|
81
|
+
export interface DownloadResult {
|
|
82
|
+
success: boolean;
|
|
83
|
+
bundlePath: string;
|
|
84
|
+
assetPaths: string[];
|
|
85
|
+
releaseLabel?: string;
|
|
86
|
+
error?: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Result of apply update operation
|
|
90
|
+
*/
|
|
91
|
+
export interface ApplyResult {
|
|
92
|
+
applied: boolean;
|
|
93
|
+
bundlePath: string | null;
|
|
94
|
+
error?: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Startup bundle information
|
|
98
|
+
*/
|
|
99
|
+
export interface StartupBundle {
|
|
100
|
+
bundlePath: string | null;
|
|
101
|
+
isUpdate: boolean;
|
|
102
|
+
releaseLabel?: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Download progress information
|
|
106
|
+
*/
|
|
107
|
+
export interface DownloadProgress {
|
|
108
|
+
bytesDownloaded: number;
|
|
109
|
+
totalBytes: number;
|
|
110
|
+
percentage: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Download options
|
|
114
|
+
*/
|
|
115
|
+
export interface DownloadOptions {
|
|
116
|
+
onProgress?: (progress: DownloadProgress) => void;
|
|
117
|
+
timeout?: number;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;G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/index.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apply Update - Capacitor SDK
|
|
3
|
+
*
|
|
4
|
+
* Activates a downloaded update using Capacitor's WebView APIs.
|
|
5
|
+
*/
|
|
6
|
+
import { DownloadResult, ApplyResult } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* Apply a downloaded update and reload the app
|
|
9
|
+
*
|
|
10
|
+
* For Capacitor, this:
|
|
11
|
+
* 1. Sets the WebView to load from the extracted bundle directory
|
|
12
|
+
* 2. Persists the path for app restarts
|
|
13
|
+
* 3. Reloads the page to apply immediately
|
|
14
|
+
*/
|
|
15
|
+
export declare function applyUpdate(downloadResult: DownloadResult): Promise<ApplyResult>;
|
|
16
|
+
//# sourceMappingURL=applyUpdate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyUpdate.d.ts","sourceRoot":"","sources":["../../src/updates/applyUpdate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAoCvD;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CAoEtF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apply Update - Capacitor SDK
|
|
3
|
+
*
|
|
4
|
+
* Activates a downloaded update using Capacitor's WebView APIs.
|
|
5
|
+
*/
|
|
6
|
+
import { setActiveBundle, bundleExists, getActiveBundleMetadata } from '../storage/bundleStorage';
|
|
7
|
+
import { setCustomBundlePath, isNativeModuleAvailable, restartApp as nativeRestartApp, } from '../native/UpfluxModule';
|
|
8
|
+
import { getConfig } from '../config';
|
|
9
|
+
import * as http from '../http/client';
|
|
10
|
+
import { getOrCreateDeviceId } from './checkForUpdates';
|
|
11
|
+
/**
|
|
12
|
+
* Report successful install to the server
|
|
13
|
+
*/
|
|
14
|
+
async function reportInstall(releaseLabel, previousVersion) {
|
|
15
|
+
try {
|
|
16
|
+
const config = getConfig();
|
|
17
|
+
// Get consistent device ID (same as checkForUpdates uses)
|
|
18
|
+
const deviceId = await getOrCreateDeviceId();
|
|
19
|
+
await http.post('/devices/install', {
|
|
20
|
+
deviceId,
|
|
21
|
+
appId: config.appId,
|
|
22
|
+
releaseLabel,
|
|
23
|
+
newVersion: releaseLabel,
|
|
24
|
+
previousVersion,
|
|
25
|
+
binaryVersion: config.binaryVersion || '1.0.0',
|
|
26
|
+
});
|
|
27
|
+
console.log('[ApplyUpdate] Install event reported to server');
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.warn('[ApplyUpdate] Failed to report install event:', error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Apply a downloaded update and reload the app
|
|
35
|
+
*
|
|
36
|
+
* For Capacitor, this:
|
|
37
|
+
* 1. Sets the WebView to load from the extracted bundle directory
|
|
38
|
+
* 2. Persists the path for app restarts
|
|
39
|
+
* 3. Reloads the page to apply immediately
|
|
40
|
+
*/
|
|
41
|
+
export async function applyUpdate(downloadResult) {
|
|
42
|
+
const { bundlePath, assetPaths, releaseLabel, success } = downloadResult;
|
|
43
|
+
if (!success || !bundlePath) {
|
|
44
|
+
console.error('[ApplyUpdate] Cannot apply - download was not successful');
|
|
45
|
+
return {
|
|
46
|
+
applied: false,
|
|
47
|
+
bundlePath: null,
|
|
48
|
+
error: 'Download was not successful',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (!releaseLabel) {
|
|
52
|
+
console.error('[ApplyUpdate] Cannot apply - missing release label');
|
|
53
|
+
return {
|
|
54
|
+
applied: false,
|
|
55
|
+
bundlePath: null,
|
|
56
|
+
error: 'Missing release label',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
console.log(`[ApplyUpdate] Applying update: ${releaseLabel}`);
|
|
60
|
+
try {
|
|
61
|
+
// Get previous version before applying
|
|
62
|
+
const previousMetadata = await getActiveBundleMetadata();
|
|
63
|
+
const previousVersion = previousMetadata?.releaseLabel;
|
|
64
|
+
// Verify bundle exists (check for index.html)
|
|
65
|
+
const exists = await bundleExists(bundlePath);
|
|
66
|
+
if (!exists) {
|
|
67
|
+
throw new Error(`Bundle not found at path: ${bundlePath}`);
|
|
68
|
+
}
|
|
69
|
+
// Set as active bundle (for tracking)
|
|
70
|
+
await setActiveBundle(bundlePath, assetPaths, releaseLabel);
|
|
71
|
+
// Set WebView to load from the new bundle directory
|
|
72
|
+
if (isNativeModuleAvailable()) {
|
|
73
|
+
await setCustomBundlePath(bundlePath);
|
|
74
|
+
console.log(`[ApplyUpdate] WebView path set: ${bundlePath}`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
console.warn('[ApplyUpdate] Not on native platform - update may not persist');
|
|
78
|
+
}
|
|
79
|
+
// Report install event to server (async, don't block)
|
|
80
|
+
reportInstall(releaseLabel, previousVersion).catch(() => { });
|
|
81
|
+
console.log(`[ApplyUpdate] Update applied successfully: ${bundlePath}`);
|
|
82
|
+
console.log('[ApplyUpdate] Reloading app...');
|
|
83
|
+
// Reload the app to apply the update
|
|
84
|
+
await nativeRestartApp();
|
|
85
|
+
return {
|
|
86
|
+
applied: true,
|
|
87
|
+
bundlePath,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
92
|
+
console.error('[ApplyUpdate] Failed to apply update:', message);
|
|
93
|
+
return {
|
|
94
|
+
applied: false,
|
|
95
|
+
bundlePath: null,
|
|
96
|
+
error: message,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=applyUpdate.js.map
|