Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(live-update): add artifactType property to FetchLatestBundleResult #368

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cool-mirrors-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capawesome/capacitor-live-update': minor
---

feat: add `artifactType` property to `FetchLatestBundleResult`
9 changes: 5 additions & 4 deletions packages/live-update/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,11 @@ Only available on Android and iOS.

#### FetchLatestBundleResult

| Prop | Type | Description | Since |
| ----------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------- | ----- |
| **`bundleId`** | <code>string \| null</code> | The unique identifier of the latest bundle. If `null`, no bundle is available. | 6.6.0 |
| **`downloadUrl`** | <code>string</code> | The URL of the latest bundle to download. Pass this URL to the `downloadBundle(...)` method to download the bundle. | 6.7.0 |
| Prop | Type | Description | Since |
| ------------------ | -------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ----- |
| **`artifactType`** | <code>'manifest' \| 'zip'</code> | The artifact type of the bundle. | 6.7.0 |
| **`bundleId`** | <code>string \| null</code> | The unique identifier of the latest bundle. If `null`, no bundle is available. | 6.6.0 |
| **`downloadUrl`** | <code>string</code> | The URL of the latest bundle to download. Pass this URL to the `downloadBundle(...)` method to download the bundle. | 6.7.0 |


#### FetchLatestBundleOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ public void downloadBundle(@NonNull DownloadBundleOptions options, @NonNull Empt

public void fetchLatestBundle(@NonNull FetchLatestBundleOptions options, @NonNull NonEmptyCallback callback) throws Exception {
GetLatestBundleResponse response = fetchLatestBundle(options);
ArtifactType artifactType = response == null ? null : response.getArtifactType();
String bundleId = response == null ? null : response.getBundleId();
String downloadUrl = response == null ? null : response.getUrl();
FetchLatestBundleResult result = new FetchLatestBundleResult(bundleId, downloadUrl);
FetchLatestBundleResult result = new FetchLatestBundleResult(artifactType, bundleId, downloadUrl);
callback.success(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,35 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.getcapacitor.JSObject;
import io.capawesome.capacitorjs.plugins.liveupdate.enums.ArtifactType;
import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.Result;
import org.json.JSONObject;

public class FetchLatestBundleResult implements Result {

@Nullable
private final ArtifactType artifactType;

@Nullable
private final String bundleId;

@Nullable
private final String downloadUrl;

public FetchLatestBundleResult(@Nullable String bundleId, @Nullable String downloadUrl) {
public FetchLatestBundleResult(@Nullable ArtifactType artifactType, @Nullable String bundleId, @Nullable String downloadUrl) {
this.artifactType = artifactType;
this.bundleId = bundleId;
this.downloadUrl = downloadUrl;
}

@NonNull
public JSObject toJSObject() {
JSObject result = new JSObject();
if (artifactType == ArtifactType.MANIFEST) {
result.put("artifactType", "manifest");
} else if (artifactType == ArtifactType.ZIP) {
result.put("artifactType", "zip");
}
result.put("bundleId", bundleId == null ? JSONObject.NULL : bundleId);
if (downloadUrl != null) {
result.put("downloadUrl", downloadUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ import Foundation
import Capacitor

@objc public class FetchLatestBundleResult: NSObject, Result {
let bundleId: String?
let downloadUrl: String?
private let artifactType: ArtifactType?
private let bundleId: String?
private let downloadUrl: String?

init(bundleId: String?, downloadUrl: String?) {
init(artifactType: ArtifactType?, bundleId: String?, downloadUrl: String?) {
self.artifactType = artifactType
self.bundleId = bundleId
self.downloadUrl = downloadUrl
}

public func toJSObject() -> AnyObject {
var result = JSObject()
if artifactType == .manifest {
result["artifactType"] = "manifest"
} else if artifactType == .zip {
result["artifactType"] = "zip"
}
result["bundleId"] = bundleId == nil ? NSNull() : bundleId
if let downloadUrl = downloadUrl {
result["downloadUrl"] = downloadUrl
Expand Down
2 changes: 1 addition & 1 deletion packages/live-update/ios/Plugin/LiveUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import CommonCrypto

@objc public func fetchLatestBundle(_ options: FetchLatestBundleOptions) async throws -> FetchLatestBundleResult {
let response: GetLatestBundleResponse? = try await self.fetchLatestBundle(options)
return FetchLatestBundleResult(bundleId: response?.bundleId, downloadUrl: response?.url)
return FetchLatestBundleResult(artifactType: response?.artifactType, bundleId: response?.bundleId, downloadUrl: response?.url)
}

@objc public func getBundle(completion: @escaping (Result?, Error?) -> Void) {
Expand Down
6 changes: 6 additions & 0 deletions packages/live-update/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ export interface FetchLatestBundleOptions {
* @since 6.6.0
*/
export interface FetchLatestBundleResult {
/**
* The artifact type of the bundle.
*
* @since 6.7.0
*/
artifactType?: 'manifest' | 'zip';
/**
* The unique identifier of the latest bundle.
*
Expand Down
Loading