@capawesome/capacitor-live-update 6.6.0 → 6.7.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.
Files changed (30) hide show
  1. package/README.md +147 -40
  2. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdate.java +53 -7
  3. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/LiveUpdatePlugin.java +76 -3
  4. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/api/GetLatestBundleResponse.java +3 -0
  5. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/FetchLatestBundleOptions.java +24 -0
  6. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/SetNextBundleOptions.java +20 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/options/SyncOptions.java +20 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/FetchLatestBundleResult.java +21 -2
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetCurrentBundleResult.java +22 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/liveupdate/classes/results/GetNextBundleResult.java +22 -0
  11. package/dist/docs.json +254 -17
  12. package/dist/esm/definitions.d.ts +118 -12
  13. package/dist/esm/definitions.js.map +1 -1
  14. package/dist/esm/web.d.ts +4 -1
  15. package/dist/esm/web.js +9 -0
  16. package/dist/esm/web.js.map +1 -1
  17. package/dist/plugin.cjs.js +9 -0
  18. package/dist/plugin.cjs.js.map +1 -1
  19. package/dist/plugin.js +9 -0
  20. package/dist/plugin.js.map +1 -1
  21. package/ios/Plugin/Classes/Options/FetchLatestBundleOptions.swift +18 -0
  22. package/ios/Plugin/Classes/Options/SetNextBundleOptions.swift +14 -0
  23. package/ios/Plugin/Classes/Options/SyncOptions.swift +14 -0
  24. package/ios/Plugin/Classes/Results/FetchLatestBundle.swift +14 -2
  25. package/ios/Plugin/Classes/Results/GetCurrentBundleResult.swift +16 -0
  26. package/ios/Plugin/Classes/Results/GetNextBundleResult.swift +16 -0
  27. package/ios/Plugin/LiveUpdate.swift +46 -7
  28. package/ios/Plugin/LiveUpdatePlugin.m +4 -1
  29. package/ios/Plugin/LiveUpdatePlugin.swift +66 -21
  30. package/package.json +2 -2
@@ -79,9 +79,9 @@ import CommonCrypto
79
79
  }
80
80
  }
81
81
 
82
- @objc public func fetchLatestBundle() async throws -> FetchLatestBundleResult {
83
- let response: GetLatestBundleResponse? = try await self.fetchLatestBundle()
84
- return FetchLatestBundleResult(bundleId: response?.bundleId)
82
+ @objc public func fetchLatestBundle(_ options: FetchLatestBundleOptions) async throws -> FetchLatestBundleResult {
83
+ let response: GetLatestBundleResponse? = try await self.fetchLatestBundle(options)
84
+ return FetchLatestBundleResult(artifactType: response?.artifactType, bundleId: response?.bundleId, downloadUrl: response?.url)
85
85
  }
86
86
 
87
87
  @objc public func getBundle(completion: @escaping (Result?, Error?) -> Void) {
@@ -105,6 +105,15 @@ import CommonCrypto
105
105
  completion(result, nil)
106
106
  }
107
107
 
108
+ @objc public func getCurrentBundle(completion: @escaping (Result?, Error?) -> Void) {
109
+ var bundleId = getCurrentBundleId()
110
+ if bundleId == defaultWebAssetDir {
111
+ bundleId = nil
112
+ }
113
+ let result = GetCurrentBundleResult(bundleId: bundleId)
114
+ completion(result, nil)
115
+ }
116
+
108
117
  @objc public func getCustomId(completion: @escaping (Result?, Error?) -> Void) {
109
118
  let customId = preferences.getCustomId()
110
119
 
@@ -118,6 +127,15 @@ import CommonCrypto
118
127
  completion(result, nil)
119
128
  }
120
129
 
130
+ @objc public func getNextBundle(completion: @escaping (Result?, Error?) -> Void) {
131
+ var bundleId: String? = getNextBundleId()
132
+ if bundleId == defaultWebAssetDir {
133
+ bundleId = nil
134
+ }
135
+ let result = GetNextBundleResult(bundleId: bundleId)
136
+ completion(result, nil)
137
+ }
138
+
121
139
  @objc public func getVersionCode(completion: @escaping (Result?, Error?) -> Void) {
122
140
  let versionCode = getVersionCode()
123
141
  let result = GetVersionCodeResult(versionCode: versionCode)
@@ -176,9 +194,29 @@ import CommonCrypto
176
194
  completion(nil)
177
195
  }
178
196
 
179
- @objc public func sync() async throws -> SyncResult {
197
+ @objc public func setNextBundle(_ options: SetNextBundleOptions, completion: @escaping (Error?) -> Void) {
198
+ let bundleId = options.getBundleId()
199
+
200
+ if let bundleId = bundleId {
201
+ if hasBundle(bundleId: bundleId) {
202
+ setNextBundle(bundleId: bundleId)
203
+ } else {
204
+ let error = CustomError.bundleNotFound
205
+ completion(error)
206
+ return
207
+ }
208
+ } else {
209
+ reset()
210
+ }
211
+
212
+ completion(nil)
213
+ }
214
+
215
+ @objc public func sync(_ options: SyncOptions) async throws -> SyncResult {
216
+ let channel = options.getChannel()
180
217
  // Fetch the latest bundle
181
- guard let response = try await fetchLatestBundle() else {
218
+ let fetchLatestBundleOptions = FetchLatestBundleOptions(channel: channel)
219
+ guard let response = try await fetchLatestBundle(fetchLatestBundleOptions) else {
182
220
  CAPLog.print("[", LiveUpdatePlugin.tag, "] ", "No update available.")
183
221
  return SyncResult(nextBundleId: nil)
184
222
  }
@@ -404,12 +442,13 @@ import CommonCrypto
404
442
  try await addBundleOfTypeZip(bundleId: bundleId, zipFile: temporaryZipFileUrl)
405
443
  }
406
444
 
407
- private func fetchLatestBundle() async throws -> GetLatestBundleResponse? {
445
+ private func fetchLatestBundle(_ options: FetchLatestBundleOptions) async throws -> GetLatestBundleResponse? {
446
+ let channel = options.getChannel() ?? getChannel()
408
447
  var parameters = [String: String]()
409
448
  parameters["appVersionCode"] = getVersionCode()
410
449
  parameters["appVersionName"] = getVersionName()
411
450
  parameters["bundleId"] = getCurrentBundleId()
412
- parameters["channelName"] = getChannel()
451
+ parameters["channelName"] = channel
413
452
  parameters["customId"] = preferences.getCustomId()
414
453
  parameters["deviceId"] = getDeviceId()
415
454
  parameters["osVersion"] = await UIDevice.current.systemVersion
@@ -10,8 +10,10 @@ CAP_PLUGIN(LiveUpdatePlugin, "LiveUpdate",
10
10
  CAP_PLUGIN_METHOD(getBundle, CAPPluginReturnPromise);
11
11
  CAP_PLUGIN_METHOD(getBundles, CAPPluginReturnPromise);
12
12
  CAP_PLUGIN_METHOD(getChannel, CAPPluginReturnPromise);
13
- CAP_PLUGIN_METHOD(getDeviceId, CAPPluginReturnPromise);
13
+ CAP_PLUGIN_METHOD(getCurrentBundle, CAPPluginReturnPromise);
14
14
  CAP_PLUGIN_METHOD(getCustomId, CAPPluginReturnPromise);
15
+ CAP_PLUGIN_METHOD(getDeviceId, CAPPluginReturnPromise);
16
+ CAP_PLUGIN_METHOD(getNextBundle, CAPPluginReturnPromise);
15
17
  CAP_PLUGIN_METHOD(getVersionCode, CAPPluginReturnPromise);
16
18
  CAP_PLUGIN_METHOD(getVersionName, CAPPluginReturnPromise);
17
19
  CAP_PLUGIN_METHOD(ready, CAPPluginReturnPromise);
@@ -20,5 +22,6 @@ CAP_PLUGIN(LiveUpdatePlugin, "LiveUpdate",
20
22
  CAP_PLUGIN_METHOD(setBundle, CAPPluginReturnPromise);
21
23
  CAP_PLUGIN_METHOD(setChannel, CAPPluginReturnPromise);
22
24
  CAP_PLUGIN_METHOD(setCustomId, CAPPluginReturnPromise);
25
+ CAP_PLUGIN_METHOD(setNextBundle, CAPPluginReturnPromise);
23
26
  CAP_PLUGIN_METHOD(sync, CAPPluginReturnPromise);
24
27
  )
@@ -8,7 +8,7 @@ import Capacitor
8
8
  @objc(LiveUpdatePlugin)
9
9
  public class LiveUpdatePlugin: CAPPlugin {
10
10
  public static let tag = "LiveUpdate"
11
- public static let version = "6.6.0"
11
+ public static let version = "6.7.1"
12
12
  public static let userDefaultsPrefix = "CapawesomeLiveUpdate" // DO NOT CHANGE
13
13
 
14
14
  private var config: LiveUpdateConfig?
@@ -33,7 +33,7 @@ public class LiveUpdatePlugin: CAPPlugin {
33
33
  self.rejectCall(call, error)
34
34
  return
35
35
  }
36
- call.resolve()
36
+ self.resolveCall(call)
37
37
  })
38
38
  }
39
39
 
@@ -54,7 +54,7 @@ public class LiveUpdatePlugin: CAPPlugin {
54
54
  let options = DownloadBundleOptions(artifactType: artifactType, bundleId: bundleId, checksum: checksum, url: url)
55
55
 
56
56
  try await implementation?.downloadBundle(options)
57
- call.resolve()
57
+ self.resolveCall(call)
58
58
  } catch {
59
59
  rejectCall(call, error)
60
60
  }
@@ -64,9 +64,10 @@ public class LiveUpdatePlugin: CAPPlugin {
64
64
  @objc func fetchLatestBundle(_ call: CAPPluginCall) {
65
65
  Task {
66
66
  do {
67
- let result = try await implementation?.fetchLatestBundle()
67
+ let options = FetchLatestBundleOptions(call)
68
+ let result = try await implementation?.fetchLatestBundle(options)
68
69
  if let result = result?.toJSObject() as? JSObject {
69
- call.resolve(result)
70
+ self.resolveCall(call, result)
70
71
  }
71
72
  } catch {
72
73
  rejectCall(call, error)
@@ -81,7 +82,7 @@ public class LiveUpdatePlugin: CAPPlugin {
81
82
  return
82
83
  }
83
84
  if let result = result?.toJSObject() as? JSObject {
84
- call.resolve(result)
85
+ self.resolveCall(call, result)
85
86
  }
86
87
  })
87
88
  }
@@ -93,7 +94,7 @@ public class LiveUpdatePlugin: CAPPlugin {
93
94
  return
94
95
  }
95
96
  if let result = result?.toJSObject() as? JSObject {
96
- call.resolve(result)
97
+ self.resolveCall(call, result)
97
98
  }
98
99
  })
99
100
  }
@@ -105,7 +106,19 @@ public class LiveUpdatePlugin: CAPPlugin {
105
106
  return
106
107
  }
107
108
  if let result = result?.toJSObject() as? JSObject {
108
- call.resolve(result)
109
+ self.resolveCall(call, result)
110
+ }
111
+ })
112
+ }
113
+
114
+ @objc func getCurrentBundle(_ call: CAPPluginCall) {
115
+ implementation?.getCurrentBundle(completion: { result, error in
116
+ if let error = error {
117
+ self.rejectCall(call, error)
118
+ return
119
+ }
120
+ if let result = result?.toJSObject() as? JSObject {
121
+ self.resolveCall(call, result)
109
122
  }
110
123
  })
111
124
  }
@@ -117,7 +130,7 @@ public class LiveUpdatePlugin: CAPPlugin {
117
130
  return
118
131
  }
119
132
  if let result = result?.toJSObject() as? JSObject {
120
- call.resolve(result)
133
+ self.resolveCall(call, result)
121
134
  }
122
135
  })
123
136
  }
@@ -129,7 +142,19 @@ public class LiveUpdatePlugin: CAPPlugin {
129
142
  return
130
143
  }
131
144
  if let result = result?.toJSObject() as? JSObject {
132
- call.resolve(result)
145
+ self.resolveCall(call, result)
146
+ }
147
+ })
148
+ }
149
+
150
+ @objc func getNextBundle(_ call: CAPPluginCall) {
151
+ implementation?.getNextBundle(completion: { result, error in
152
+ if let error = error {
153
+ self.rejectCall(call, error)
154
+ return
155
+ }
156
+ if let result = result?.toJSObject() as? JSObject {
157
+ self.resolveCall(call, result)
133
158
  }
134
159
  })
135
160
  }
@@ -141,7 +166,7 @@ public class LiveUpdatePlugin: CAPPlugin {
141
166
  return
142
167
  }
143
168
  if let result = result?.toJSObject() as? JSObject {
144
- call.resolve(result)
169
+ self.resolveCall(call, result)
145
170
  }
146
171
  })
147
172
  }
@@ -153,24 +178,24 @@ public class LiveUpdatePlugin: CAPPlugin {
153
178
  return
154
179
  }
155
180
  if let result = result?.toJSObject() as? JSObject {
156
- call.resolve(result)
181
+ self.resolveCall(call, result)
157
182
  }
158
183
  })
159
184
  }
160
185
 
161
186
  @objc func ready(_ call: CAPPluginCall) {
162
187
  implementation?.ready()
163
- call.resolve()
188
+ resolveCall(call)
164
189
  }
165
190
 
166
191
  @objc func reload(_ call: CAPPluginCall) {
167
192
  implementation?.reload()
168
- call.resolve()
193
+ resolveCall(call)
169
194
  }
170
195
 
171
196
  @objc func reset(_ call: CAPPluginCall) {
172
197
  implementation?.reset()
173
- call.resolve()
198
+ resolveCall(call)
174
199
  }
175
200
 
176
201
  @objc func setBundle(_ call: CAPPluginCall) {
@@ -186,8 +211,8 @@ public class LiveUpdatePlugin: CAPPlugin {
186
211
  self.rejectCall(call, error)
187
212
  return
188
213
  }
214
+ self.resolveCall(call)
189
215
  })
190
- call.resolve()
191
216
  }
192
217
 
193
218
  @objc func setChannel(_ call: CAPPluginCall) {
@@ -200,8 +225,8 @@ public class LiveUpdatePlugin: CAPPlugin {
200
225
  self.rejectCall(call, error)
201
226
  return
202
227
  }
228
+ self.resolveCall(call)
203
229
  })
204
- call.resolve()
205
230
  }
206
231
 
207
232
  @objc func setCustomId(_ call: CAPPluginCall) {
@@ -217,14 +242,25 @@ public class LiveUpdatePlugin: CAPPlugin {
217
242
  self.rejectCall(call, error)
218
243
  return
219
244
  }
245
+ self.resolveCall(call)
246
+ })
247
+ }
248
+
249
+ @objc func setNextBundle(_ call: CAPPluginCall) {
250
+ let options = SetNextBundleOptions(call)
251
+
252
+ implementation?.setNextBundle(options, completion: { error in
253
+ if let error = error {
254
+ self.rejectCall(call, error)
255
+ return
256
+ }
257
+ self.resolveCall(call)
220
258
  })
221
- call.resolve()
222
259
  }
223
260
 
224
261
  @objc func sync(_ call: CAPPluginCall) {
225
262
  Task {
226
263
  do {
227
-
228
264
  guard let _ = config?.appId else {
229
265
  call.reject(CustomError.appIdMissing.localizedDescription)
230
266
  return
@@ -236,10 +272,11 @@ public class LiveUpdatePlugin: CAPPlugin {
236
272
  }
237
273
  syncInProgress = true
238
274
 
239
- let result = try await implementation?.sync()
275
+ let options = SyncOptions(call)
276
+ let result = try await implementation?.sync(options)
240
277
  self.syncInProgress = false
241
278
  if let result = result?.toJSObject() as? JSObject {
242
- call.resolve(result)
279
+ resolveCall(call, result)
243
280
  }
244
281
  } catch {
245
282
  self.syncInProgress = false
@@ -274,4 +311,12 @@ public class LiveUpdatePlugin: CAPPlugin {
274
311
  }
275
312
  call.reject(message)
276
313
  }
314
+
315
+ private func resolveCall(_ call: CAPPluginCall) {
316
+ call.resolve()
317
+ }
318
+
319
+ private func resolveCall(_ call: CAPPluginCall, _ result: JSObject) {
320
+ call.resolve(result)
321
+ }
277
322
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-live-update",
3
- "version": "6.6.0",
3
+ "version": "6.7.1",
4
4
  "description": "Capacitor plugin to update your app remotely in real-time.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -67,7 +67,7 @@
67
67
  "@capacitor/android": "6.0.0",
68
68
  "@capacitor/cli": "6.0.0",
69
69
  "@capacitor/core": "6.0.0",
70
- "@capacitor/docgen": "0.0.17",
70
+ "@capacitor/docgen": "0.3.0",
71
71
  "@capacitor/ios": "6.0.0",
72
72
  "@ionic/eslint-config": "0.3.0",
73
73
  "@ionic/prettier-config": "2.0.0",