@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
package/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# @upfluxhq/capacitor
|
|
2
|
+
|
|
3
|
+
Capacitor SDK for Upflux OTA updates.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @upfluxhq/capacitor
|
|
9
|
+
# or
|
|
10
|
+
yarn add @upfluxhq/capacitor
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
**No additional native setup required!** The SDK uses Capacitor's built-in WebView APIs.
|
|
16
|
+
|
|
17
|
+
Just sync your Capacitor project after installing:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx cap sync
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Basic Setup
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
import { Upflux } from '@upfluxhq/capacitor';
|
|
29
|
+
|
|
30
|
+
// Configure the SDK
|
|
31
|
+
const upflux = new Upflux({
|
|
32
|
+
appId: 'your-app-id',
|
|
33
|
+
deployment: 'production',
|
|
34
|
+
clientKey: 'your-client-key',
|
|
35
|
+
serverUrl: 'https://your-api-server.com'
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Initialize on app startup
|
|
39
|
+
await upflux.init();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Check for Updates
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
const updateInfo = await upflux.checkForUpdates();
|
|
46
|
+
|
|
47
|
+
if (updateInfo.updateAvailable) {
|
|
48
|
+
console.log('Update available:', updateInfo.releaseLabel);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Download and Apply Update
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
if (updateInfo.updateAvailable) {
|
|
56
|
+
// Download the update
|
|
57
|
+
const downloadResult = await upflux.downloadUpdate(updateInfo, {
|
|
58
|
+
onProgress: (progress) => {
|
|
59
|
+
console.log(`Download progress: ${progress.percentage}%`);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (downloadResult.success) {
|
|
64
|
+
// Apply and reload
|
|
65
|
+
await upflux.applyUpdate(downloadResult);
|
|
66
|
+
// App will reload here
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Complete Example
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
import { Upflux } from '@upfluxhq/capacitor';
|
|
75
|
+
|
|
76
|
+
const upflux = new Upflux({
|
|
77
|
+
appId: 'my-app',
|
|
78
|
+
deployment: 'production',
|
|
79
|
+
clientKey: 'your-client-key',
|
|
80
|
+
serverUrl: 'http://localhost:4000'
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
async function initApp() {
|
|
84
|
+
// Initialize SDK
|
|
85
|
+
const startupBundle = await upflux.init();
|
|
86
|
+
|
|
87
|
+
if (startupBundle.isUpdate) {
|
|
88
|
+
console.log('Running OTA version:', startupBundle.releaseLabel);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function checkForUpdates() {
|
|
93
|
+
try {
|
|
94
|
+
const updateInfo = await upflux.checkForUpdates();
|
|
95
|
+
|
|
96
|
+
if (updateInfo.updateAvailable) {
|
|
97
|
+
if (confirm(`Update ${updateInfo.releaseLabel} available. Install now?`)) {
|
|
98
|
+
await installUpdate(updateInfo);
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
console.log('App is up to date');
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error('Error checking for updates:', error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function installUpdate(updateInfo) {
|
|
109
|
+
try {
|
|
110
|
+
const downloadResult = await upflux.downloadUpdate(updateInfo);
|
|
111
|
+
|
|
112
|
+
if (downloadResult.success) {
|
|
113
|
+
await upflux.applyUpdate(downloadResult);
|
|
114
|
+
// App will reload
|
|
115
|
+
}
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error('Error installing update:', error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Initialize on page load
|
|
122
|
+
initApp();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## API Reference
|
|
126
|
+
|
|
127
|
+
### `Upflux` Class
|
|
128
|
+
|
|
129
|
+
#### `constructor(config: UpfluxConfig)`
|
|
130
|
+
|
|
131
|
+
Create a new Upflux instance.
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
interface UpfluxConfig {
|
|
135
|
+
appId: string; // Your app identifier
|
|
136
|
+
deployment: string; // Deployment name (e.g., 'production', 'staging')
|
|
137
|
+
clientKey: string; // Client key from dashboard
|
|
138
|
+
serverUrl: string; // Upflux API server URL
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### `init(): Promise<StartupBundle>`
|
|
143
|
+
|
|
144
|
+
Initialize the SDK. Call this early in app startup.
|
|
145
|
+
|
|
146
|
+
#### `checkForUpdates(deviceInfo?: Partial<DeviceInfo>): Promise<UpdateInfo>`
|
|
147
|
+
|
|
148
|
+
Check if an update is available.
|
|
149
|
+
|
|
150
|
+
#### `downloadUpdate(info: UpdateInfo, options?: DownloadOptions): Promise<DownloadResult>`
|
|
151
|
+
|
|
152
|
+
Download an available update.
|
|
153
|
+
|
|
154
|
+
#### `applyUpdate(result: DownloadResult): Promise<ApplyResult>`
|
|
155
|
+
|
|
156
|
+
Apply a downloaded update and reload the app.
|
|
157
|
+
|
|
158
|
+
#### `clearUpdate(): Promise<void>`
|
|
159
|
+
|
|
160
|
+
Clear the current update and revert to default bundle on next reload.
|
|
161
|
+
|
|
162
|
+
## Creating Releases
|
|
163
|
+
|
|
164
|
+
The Upflux CLI auto-detects Capacitor projects and handles bundling:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Build your app first
|
|
168
|
+
npm run build
|
|
169
|
+
|
|
170
|
+
# Release to Upflux (auto-detects Capacitor and zips www/)
|
|
171
|
+
upflux release --label v1.0.0 --platform android
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The CLI will:
|
|
175
|
+
1. Detect `capacitor.config.json`/`ts`/`js`
|
|
176
|
+
2. Read the `webDir` setting (default: `www`)
|
|
177
|
+
3. Zip the web directory
|
|
178
|
+
4. Upload to Upflux
|
|
179
|
+
|
|
180
|
+
## Storage Location
|
|
181
|
+
|
|
182
|
+
Updates are stored in the app's data directory:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
<DataDirectory>/upflux/
|
|
186
|
+
├── activeBundle.json # Currently active release info
|
|
187
|
+
├── deviceId.txt # Persistent device ID
|
|
188
|
+
├── currentPath.txt # Current WebView path
|
|
189
|
+
└── v1.0.0/ # Extracted release
|
|
190
|
+
├── index.html
|
|
191
|
+
├── main.js
|
|
192
|
+
└── ...
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## How It Works
|
|
196
|
+
|
|
197
|
+
1. **Check**: App calls `/updates/check` with device info
|
|
198
|
+
2. **Download**: If update available, downloads zip bundle
|
|
199
|
+
3. **Extract**: Bundle is extracted using JSZip
|
|
200
|
+
4. **Apply**: `WebView.setServerBasePath()` points to new bundle
|
|
201
|
+
5. **Persist**: `WebView.persistServerBasePath()` survives restarts
|
|
202
|
+
6. **Reload**: Page reloads to apply changes
|
|
203
|
+
|
|
204
|
+
## Troubleshooting
|
|
205
|
+
|
|
206
|
+
### Update Not Persisting After Restart
|
|
207
|
+
|
|
208
|
+
Ensure your Capacitor version is 5.0+ which includes `persistServerBasePath()`.
|
|
209
|
+
|
|
210
|
+
### Bundle Not Loading
|
|
211
|
+
|
|
212
|
+
Check that your build output includes a valid `index.html` at the root.
|
|
213
|
+
|
|
214
|
+
### Network Errors
|
|
215
|
+
|
|
216
|
+
For local development, ensure your server is accessible from the device/emulator.
|
|
217
|
+
|
|
218
|
+
## License
|
|
219
|
+
|
|
220
|
+
MIT
|
package/dist/Upflux.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upflux Capacitor SDK
|
|
3
|
+
*
|
|
4
|
+
* Main SDK class providing high-level API for OTA update management.
|
|
5
|
+
*/
|
|
6
|
+
import { UpfluxConfig, UpdateInfo, DownloadResult, ApplyResult, StartupBundle, DownloadOptions, DeviceInfo } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Main Upflux SDK class for Capacitor.
|
|
9
|
+
*
|
|
10
|
+
* Provides a high-level API for OTA update management:
|
|
11
|
+
* - Check for available updates
|
|
12
|
+
* - Download update bundles
|
|
13
|
+
* - Apply updates (switch WebView path)
|
|
14
|
+
* - Resolve which bundle to load at startup
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Initialize the SDK
|
|
19
|
+
* const upflux = new Upflux({
|
|
20
|
+
* appId: 'my-app',
|
|
21
|
+
* deployment: 'production',
|
|
22
|
+
* clientKey: 'your-client-key',
|
|
23
|
+
* serverUrl: 'https://api.upflux.io'
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Initialize and resolve bundle at startup
|
|
27
|
+
* await upflux.init();
|
|
28
|
+
*
|
|
29
|
+
* // Check for updates
|
|
30
|
+
* const updateInfo = await upflux.checkForUpdates();
|
|
31
|
+
*
|
|
32
|
+
* if (updateInfo.updateAvailable) {
|
|
33
|
+
* // Download the update
|
|
34
|
+
* const downloadResult = await upflux.downloadUpdate(updateInfo);
|
|
35
|
+
*
|
|
36
|
+
* if (downloadResult.success) {
|
|
37
|
+
* // Apply and reload
|
|
38
|
+
* await upflux.applyUpdate(downloadResult);
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class Upflux {
|
|
44
|
+
private config;
|
|
45
|
+
private initialized;
|
|
46
|
+
private startupBundle;
|
|
47
|
+
/**
|
|
48
|
+
* Create a new Upflux SDK instance
|
|
49
|
+
*/
|
|
50
|
+
constructor(config: UpfluxConfig);
|
|
51
|
+
/**
|
|
52
|
+
* Initialize the SDK and resolve the initial bundle
|
|
53
|
+
*/
|
|
54
|
+
init(): Promise<StartupBundle>;
|
|
55
|
+
/**
|
|
56
|
+
* Check for available updates
|
|
57
|
+
*/
|
|
58
|
+
checkForUpdates(deviceInfo?: Partial<DeviceInfo>): Promise<UpdateInfo>;
|
|
59
|
+
/**
|
|
60
|
+
* Download an available update
|
|
61
|
+
*/
|
|
62
|
+
downloadUpdate(info: UpdateInfo, options?: DownloadOptions): Promise<DownloadResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Apply a downloaded update and reload the app
|
|
65
|
+
*/
|
|
66
|
+
applyUpdate(result: DownloadResult): Promise<ApplyResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Clear the current update and revert to default bundle
|
|
69
|
+
*/
|
|
70
|
+
clearUpdate(): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Check if the SDK has been initialized
|
|
73
|
+
*/
|
|
74
|
+
isInitialized(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Get the startup bundle info from init()
|
|
77
|
+
*/
|
|
78
|
+
getStartupBundle(): StartupBundle | null;
|
|
79
|
+
/**
|
|
80
|
+
* Get the current SDK configuration
|
|
81
|
+
*/
|
|
82
|
+
getConfig(): UpfluxConfig;
|
|
83
|
+
/**
|
|
84
|
+
* Destroy the SDK instance and clean up
|
|
85
|
+
*/
|
|
86
|
+
destroy(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Ensure SDK is initialized before operations
|
|
89
|
+
*/
|
|
90
|
+
private ensureInitialized;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=Upflux.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Upflux.d.ts","sourceRoot":"","sources":["../src/Upflux.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACH,YAAY,EACZ,UAAU,EACV,cAAc,EACd,WAAW,EACX,aAAa,EACb,eAAe,EACf,UAAU,EACb,MAAM,SAAS,CAAC;AAQjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,MAAM;IACf,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,aAAa,CAA8B;IAEnD;;OAEG;gBACS,MAAM,EAAE,YAAY;IAIhC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC;IAgBpC;;OAEG;IACG,eAAe,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAO5E;;OAEG;IACG,cAAc,CAChB,IAAI,EAAE,UAAU,EAChB,OAAO,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,cAAc,CAAC;IAiB1B;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;IAO/D;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAKlC;;OAEG;IACH,aAAa,IAAI,OAAO;IAIxB;;OAEG;IACH,gBAAgB,IAAI,aAAa,GAAG,IAAI;IAIxC;;OAEG;IACH,SAAS,IAAI,YAAY;IAIzB;;OAEG;IACH,OAAO,IAAI,IAAI;IAOf;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAK5B"}
|
package/dist/Upflux.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upflux Capacitor SDK
|
|
3
|
+
*
|
|
4
|
+
* Main SDK class providing high-level API for OTA update management.
|
|
5
|
+
*/
|
|
6
|
+
import { setConfig, clearConfig, isConfigured } from './config';
|
|
7
|
+
import { checkForUpdates } from './updates/checkForUpdates';
|
|
8
|
+
import { downloadUpdate } from './updates/downloadUpdate';
|
|
9
|
+
import { applyUpdate } from './updates/applyUpdate';
|
|
10
|
+
import { resolveInitialBundle } from './startup/resolveInitialBundle';
|
|
11
|
+
import { clearActiveBundle } from './storage/bundleStorage';
|
|
12
|
+
/**
|
|
13
|
+
* Main Upflux SDK class for Capacitor.
|
|
14
|
+
*
|
|
15
|
+
* Provides a high-level API for OTA update management:
|
|
16
|
+
* - Check for available updates
|
|
17
|
+
* - Download update bundles
|
|
18
|
+
* - Apply updates (switch WebView path)
|
|
19
|
+
* - Resolve which bundle to load at startup
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Initialize the SDK
|
|
24
|
+
* const upflux = new Upflux({
|
|
25
|
+
* appId: 'my-app',
|
|
26
|
+
* deployment: 'production',
|
|
27
|
+
* clientKey: 'your-client-key',
|
|
28
|
+
* serverUrl: 'https://api.upflux.io'
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Initialize and resolve bundle at startup
|
|
32
|
+
* await upflux.init();
|
|
33
|
+
*
|
|
34
|
+
* // Check for updates
|
|
35
|
+
* const updateInfo = await upflux.checkForUpdates();
|
|
36
|
+
*
|
|
37
|
+
* if (updateInfo.updateAvailable) {
|
|
38
|
+
* // Download the update
|
|
39
|
+
* const downloadResult = await upflux.downloadUpdate(updateInfo);
|
|
40
|
+
*
|
|
41
|
+
* if (downloadResult.success) {
|
|
42
|
+
* // Apply and reload
|
|
43
|
+
* await upflux.applyUpdate(downloadResult);
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export class Upflux {
|
|
49
|
+
/**
|
|
50
|
+
* Create a new Upflux SDK instance
|
|
51
|
+
*/
|
|
52
|
+
constructor(config) {
|
|
53
|
+
this.initialized = false;
|
|
54
|
+
this.startupBundle = null;
|
|
55
|
+
this.config = { ...config };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Initialize the SDK and resolve the initial bundle
|
|
59
|
+
*/
|
|
60
|
+
async init() {
|
|
61
|
+
console.log(`[Upflux] Initializing with appId: ${this.config.appId}`);
|
|
62
|
+
// Set global configuration
|
|
63
|
+
setConfig(this.config);
|
|
64
|
+
// Resolve which bundle to use
|
|
65
|
+
this.startupBundle = await resolveInitialBundle();
|
|
66
|
+
this.initialized = true;
|
|
67
|
+
console.log(`[Upflux] Initialized. Bundle: ${this.startupBundle.bundlePath ?? 'default'}`);
|
|
68
|
+
console.log(`[Upflux] Is update: ${this.startupBundle.isUpdate}`);
|
|
69
|
+
return this.startupBundle;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Check for available updates
|
|
73
|
+
*/
|
|
74
|
+
async checkForUpdates(deviceInfo) {
|
|
75
|
+
this.ensureInitialized();
|
|
76
|
+
console.log('[Upflux] Checking for updates...');
|
|
77
|
+
return checkForUpdates(deviceInfo);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Download an available update
|
|
81
|
+
*/
|
|
82
|
+
async downloadUpdate(info, options) {
|
|
83
|
+
this.ensureInitialized();
|
|
84
|
+
if (!info.updateAvailable) {
|
|
85
|
+
console.warn('[Upflux] No update available to download');
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
bundlePath: '',
|
|
89
|
+
assetPaths: [],
|
|
90
|
+
error: 'No update available',
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
console.log(`[Upflux] Downloading update: ${info.releaseLabel}`);
|
|
94
|
+
return downloadUpdate(info, options);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Apply a downloaded update and reload the app
|
|
98
|
+
*/
|
|
99
|
+
async applyUpdate(result) {
|
|
100
|
+
this.ensureInitialized();
|
|
101
|
+
console.log('[Upflux] Applying update and reloading...');
|
|
102
|
+
return applyUpdate(result);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Clear the current update and revert to default bundle
|
|
106
|
+
*/
|
|
107
|
+
async clearUpdate() {
|
|
108
|
+
console.log('[Upflux] Clearing current update...');
|
|
109
|
+
await clearActiveBundle();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if the SDK has been initialized
|
|
113
|
+
*/
|
|
114
|
+
isInitialized() {
|
|
115
|
+
return this.initialized;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get the startup bundle info from init()
|
|
119
|
+
*/
|
|
120
|
+
getStartupBundle() {
|
|
121
|
+
return this.startupBundle;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get the current SDK configuration
|
|
125
|
+
*/
|
|
126
|
+
getConfig() {
|
|
127
|
+
return { ...this.config };
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Destroy the SDK instance and clean up
|
|
131
|
+
*/
|
|
132
|
+
destroy() {
|
|
133
|
+
clearConfig();
|
|
134
|
+
this.initialized = false;
|
|
135
|
+
this.startupBundle = null;
|
|
136
|
+
console.log('[Upflux] SDK destroyed');
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Ensure SDK is initialized before operations
|
|
140
|
+
*/
|
|
141
|
+
ensureInitialized() {
|
|
142
|
+
if (!this.initialized || !isConfigured()) {
|
|
143
|
+
throw new Error('[Upflux] SDK not initialized. Call init() first.');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=Upflux.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Upflux.js","sourceRoot":"","sources":["../src/Upflux.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,OAAO,MAAM;IAKf;;OAEG;IACH,YAAY,MAAoB;QANxB,gBAAW,GAAY,KAAK,CAAC;QAC7B,kBAAa,GAAyB,IAAI,CAAC;QAM/C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACN,OAAO,CAAC,GAAG,CAAC,qCAAqC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QAEtE,2BAA2B;QAC3B,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEvB,8BAA8B;QAC9B,IAAI,CAAC,aAAa,GAAG,MAAM,oBAAoB,EAAE,CAAC;QAClD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAExB,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAI,CAAC,aAAa,CAAC,UAAU,IAAI,SAAS,EAAE,CAAC,CAAC;QAC3F,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;QAElE,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,UAAgC;QAClD,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAEzB,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;QAChD,OAAO,eAAe,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc,CAChB,IAAgB,EAChB,OAAyB;QAEzB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAEzB,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,OAAO,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;YACzD,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,UAAU,EAAE,EAAE;gBACd,UAAU,EAAE,EAAE;gBACd,KAAK,EAAE,qBAAqB;aAC/B,CAAC;QACN,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,gCAAgC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;QACjE,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,MAAsB;QACpC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAEzB,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACzD,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW;QACb,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;QACnD,MAAM,iBAAiB,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,aAAa;QACT,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,gBAAgB;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,SAAS;QACL,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,OAAO;QACH,WAAW,EAAE,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACK,iBAAiB;QACrB,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACxE,CAAC;IACL,CAAC;CACJ"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upflux Capacitor SDK Configuration
|
|
3
|
+
*/
|
|
4
|
+
import { UpfluxConfig } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Set the SDK configuration
|
|
7
|
+
*/
|
|
8
|
+
export declare function setConfig(config: UpfluxConfig): void;
|
|
9
|
+
/**
|
|
10
|
+
* Get the current configuration
|
|
11
|
+
* @throws Error if not configured
|
|
12
|
+
*/
|
|
13
|
+
export declare function getConfig(): UpfluxConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Check if SDK is configured
|
|
16
|
+
*/
|
|
17
|
+
export declare function isConfigured(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Clear the configuration
|
|
20
|
+
*/
|
|
21
|
+
export declare function clearConfig(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get the API base URL from config
|
|
24
|
+
*/
|
|
25
|
+
export declare function getApiBaseUrl(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Get the client key from config
|
|
28
|
+
*/
|
|
29
|
+
export declare function getClientKey(): string;
|
|
30
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAIvC;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CASpD;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,YAAY,CAKxC;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAGtC;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upflux Capacitor SDK Configuration
|
|
3
|
+
*/
|
|
4
|
+
let _config = null;
|
|
5
|
+
/**
|
|
6
|
+
* Set the SDK configuration
|
|
7
|
+
*/
|
|
8
|
+
export function setConfig(config) {
|
|
9
|
+
_config = { ...config };
|
|
10
|
+
console.log(`[Upflux] ========== CONFIG SET ==========`);
|
|
11
|
+
console.log(`[Upflux] appId: ${config.appId}`);
|
|
12
|
+
console.log(`[Upflux] deployment: ${config.deployment}`);
|
|
13
|
+
console.log(`[Upflux] serverUrl: ${config.serverUrl}`);
|
|
14
|
+
console.log(`[Upflux] clientKey: ${config.clientKey?.substring(0, 8)}...`);
|
|
15
|
+
console.log(`[Upflux] binaryVersion: ${config.binaryVersion || 'not set'}`);
|
|
16
|
+
console.log(`[Upflux] =====================================`);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the current configuration
|
|
20
|
+
* @throws Error if not configured
|
|
21
|
+
*/
|
|
22
|
+
export function getConfig() {
|
|
23
|
+
if (!_config) {
|
|
24
|
+
throw new Error('[Upflux] SDK not configured. Call setConfig() first.');
|
|
25
|
+
}
|
|
26
|
+
return { ..._config };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if SDK is configured
|
|
30
|
+
*/
|
|
31
|
+
export function isConfigured() {
|
|
32
|
+
return _config !== null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Clear the configuration
|
|
36
|
+
*/
|
|
37
|
+
export function clearConfig() {
|
|
38
|
+
_config = null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get the API base URL from config
|
|
42
|
+
*/
|
|
43
|
+
export function getApiBaseUrl() {
|
|
44
|
+
const config = getConfig();
|
|
45
|
+
return config.serverUrl.replace(/\/$/, '');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the client key from config
|
|
49
|
+
*/
|
|
50
|
+
export function getClientKey() {
|
|
51
|
+
return getConfig().clientKey;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,IAAI,OAAO,GAAwB,IAAI,CAAC;AAExC;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAoB;IAC1C,OAAO,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;IACzD,OAAO,CAAC,GAAG,CAAC,mBAAmB,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,GAAG,CAAC,wBAAwB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IACzD,OAAO,CAAC,GAAG,CAAC,uBAAuB,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IACvD,OAAO,CAAC,GAAG,CAAC,uBAAuB,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;IAC3E,OAAO,CAAC,GAAG,CAAC,2BAA2B,MAAM,CAAC,aAAa,IAAI,SAAS,EAAE,CAAC,CAAC;IAC5E,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;AAClE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS;IACrB,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY;IACxB,OAAO,OAAO,KAAK,IAAI,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACvB,OAAO,GAAG,IAAI,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa;IACzB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,OAAO,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY;IACxB,OAAO,SAAS,EAAE,CAAC,SAAS,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Client for Upflux Capacitor SDK
|
|
3
|
+
*
|
|
4
|
+
* Simple HTTP client using fetch API.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* HTTP Error class
|
|
8
|
+
*/
|
|
9
|
+
export declare class HttpError extends Error {
|
|
10
|
+
statusCode: number;
|
|
11
|
+
statusText: string;
|
|
12
|
+
responseBody?: string | undefined;
|
|
13
|
+
constructor(statusCode: number, statusText: string, responseBody?: string | undefined);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Make a GET request
|
|
17
|
+
*/
|
|
18
|
+
export declare function get<T>(path: string): Promise<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Make a POST request
|
|
21
|
+
*/
|
|
22
|
+
export declare function post<T>(path: string, body?: unknown): Promise<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Download a file from URL
|
|
25
|
+
* Returns the file content as ArrayBuffer
|
|
26
|
+
*/
|
|
27
|
+
export declare function downloadFile(url: string, onProgress?: (loaded: number, total: number) => void): Promise<ArrayBuffer>;
|
|
28
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/http/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAErB,UAAU,EAAE,MAAM;IAClB,UAAU,EAAE,MAAM;IAClB,YAAY,CAAC,EAAE,MAAM;gBAFrB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,MAAM,YAAA;CAKnC;AAYD;;GAEG;AACH,wBAAsB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAyBrD;AAED;;GAEG;AACH,wBAAsB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CA6BtE;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAC9B,GAAG,EAAE,MAAM,EACX,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GACrD,OAAO,CAAC,WAAW,CAAC,CA4CtB"}
|