Skip to content

Commit a118f77

Browse files
authored
chore: update npm packages
chore: update npm packages
2 parents 3df0b1d + 7a0f857 commit a118f77

File tree

12 files changed

+1839
-1988
lines changed

12 files changed

+1839
-1988
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"dependencies": {},
55
"devDependencies": {
6-
"@types/node": "^20.14.8",
7-
"typescript": "~5.4.5"
6+
"@types/node": "^24.10.1",
7+
"typescript": "^5.9.3"
88
}
99
}

packages/capacitor-plugin/.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/capacitor-plugin/.prettierignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/capacitor-plugin/android/src/test/java/com/capacitorjs/plugins/filetransfer/ExampleUnitTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
*/
1212
public class ExampleUnitTest {
1313

14-
@Test
15-
public void addition_isCorrect() throws Exception {
16-
assertEquals(4, 2 + 2);
17-
}
14+
@Test
15+
public void addition_isCorrect() throws Exception {
16+
assertEquals(4, 2 + 2);
17+
}
1818
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import eslintjs from "@eslint/js";
2+
import tseslint from "@typescript-eslint/eslint-plugin";
3+
import tseslintparser from "@typescript-eslint/parser";
4+
import prettierConfig from "eslint-config-prettier";
5+
import prettierPlugin from "eslint-plugin-prettier";
6+
7+
export default [
8+
{
9+
ignores: ["node_modules/**", "dist/**", "build/**", "eslint.config.*"],
10+
},
11+
eslintjs.configs.recommended,
12+
{
13+
files: ["**/*.ts", "**/*.js"],
14+
languageOptions: {
15+
parser: tseslintparser,
16+
ecmaVersion: "latest",
17+
sourceType: "module",
18+
globals: {
19+
window: "readonly",
20+
document: "readonly",
21+
console: "readonly",
22+
Blob: "readonly",
23+
Headers: "readonly",
24+
RequestInit: "readonly",
25+
AbortController: "readonly",
26+
setTimeout: "readonly",
27+
clearTimeout: "readonly",
28+
fetch: "readonly",
29+
URL: "readonly",
30+
XMLHttpRequest: "readonly",
31+
FormData: "readonly",
32+
atob: "readonly",
33+
btoa: "readonly",
34+
FileReader: "readonly",
35+
},
36+
},
37+
plugins: {
38+
"@typescript-eslint": tseslint,
39+
prettier: prettierPlugin,
40+
},
41+
rules: {
42+
...tseslint.configs.recommended.rules,
43+
"@typescript-eslint/no-explicit-any": "off",
44+
"@typescript-eslint/no-unused-vars": [
45+
"error",
46+
{ argsIgnorePattern: "^_" },
47+
],
48+
"prettier/prettier": "error",
49+
},
50+
},
51+
prettierConfig,
52+
];

packages/capacitor-plugin/ios/Sources/FileTransferPlugin/FileTransferErrors.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import IONFileTransferLib
77
/// `FileTransferError` represents various error states that can occur during file uploads and downloads,
88
/// including validation issues, connection problems, HTTP response errors, and file system errors.
99
struct FileTransferError: Error {
10-
10+
1111
/// A error code in the format `OS-PLUG-FLTR-XXXX`.
1212
let code: String
13-
13+
1414
/// A human-readable error message.
1515
let message: String
16-
16+
1717
/// The source URL or path related to the error, if available.
1818
var source: String?
1919

@@ -62,7 +62,7 @@ struct FileTransferError: Error {
6262
self.headers = headers
6363
self.cause = cause
6464
}
65-
65+
6666
/// A dictionary representation of the error for use in JavaScript or other serialization contexts.
6767
///
6868
/// This includes the code, message, and optional metadata such as HTTP status,
@@ -89,11 +89,11 @@ struct FileTransferError: Error {
8989
// MARK: - Static Constructors
9090

9191
extension FileTransferError {
92-
92+
9393
static func invalidParameters(_ message: String? = nil) -> FileTransferError {
9494
.init(code: 4, message: message ?? "The method's input parameters aren't valid.")
9595
}
96-
96+
9797
static func invalidServerUrl(_ url: String?) -> FileTransferError {
9898
.init(
9999
code: 5,
@@ -103,23 +103,23 @@ extension FileTransferError {
103103
source: url
104104
)
105105
}
106-
106+
107107
static func fileDoesNotExist() -> FileTransferError {
108108
.init(code: 7, message: "Operation failed because file does not exist.")
109109
}
110110

111111
static func connectionError() -> FileTransferError {
112112
.init(code: 8, message: "Failed to connect to server.")
113113
}
114-
114+
115115
static func notModified() -> FileTransferError {
116116
.init(
117117
code: 9,
118118
message: "The server responded with HTTP 304 – Not Modified. If you want to avoid this, check your headers related to HTTP caching.",
119119
httpStatus: 304
120120
)
121121
}
122-
122+
123123
static func httpError(
124124
responseCode: Int,
125125
message: String,
@@ -136,7 +136,7 @@ extension FileTransferError {
136136
cause: cause
137137
)
138138
}
139-
139+
140140
static func genericError(
141141
cause: Error? = nil
142142
) -> FileTransferError {
@@ -151,7 +151,7 @@ extension FileTransferError {
151151
// MARK: - IONFLTRException Mapping
152152

153153
extension IONFLTRException {
154-
154+
155155
/// Converts an `IONFLTRException` to a corresponding `FileTransferError`.
156156
///
157157
/// This method maps specific cases of `IONFLTRException` to their
@@ -173,14 +173,14 @@ extension IONFLTRException {
173173
return FileTransferError.genericError(cause: self)
174174
case .httpError(let responseCode, let responseBody, let headers):
175175
return responseCode == 304
176-
? FileTransferError.notModified()
177-
: FileTransferError.httpError(
178-
responseCode: responseCode,
179-
message: self.description,
180-
responseBody: responseBody,
181-
headers: headers,
182-
cause: self
183-
)
176+
? FileTransferError.notModified()
177+
: FileTransferError.httpError(
178+
responseCode: responseCode,
179+
message: self.description,
180+
responseBody: responseBody,
181+
headers: headers,
182+
cause: self
183+
)
184184
case .connectionError:
185185
return FileTransferError.connectionError()
186186
case .transferError:

packages/capacitor-plugin/ios/Sources/FileTransferPlugin/FileTransferPlugin.swift

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,33 @@ public class FileTransferPlugin: CAPPlugin, CAPBridgedPlugin {
3131
/// - Parameter call: The Capacitor call containing `url`, `path`, and optional HTTP options.
3232
@objc func downloadFile(_ call: CAPPluginCall) {
3333
do {
34-
let (serverURL, fileURL, shouldTrackProgress, httpOptions) = try validateAndPrepare(call: call, action: .download)
34+
let prepData = try validateAndPrepare(call: call, action: .download)
3535

3636
try manager.downloadFile(
37-
fromServerURL: serverURL,
38-
toFileURL: fileURL,
39-
withHttpOptions: httpOptions
37+
fromServerURL: prepData.serverURL,
38+
toFileURL: prepData.fileURL,
39+
withHttpOptions: prepData.httpOptions
4040
).sink(
41-
receiveCompletion: handleCompletion(call: call, source: serverURL.absoluteString, target: fileURL.absoluteString),
41+
receiveCompletion: handleCompletion(call: call, source: prepData.serverURL.absoluteString, target: prepData.fileURL.absoluteString),
4242
receiveValue: handleReceiveValue(
4343
call: call,
4444
type: .download,
45-
url: serverURL.absoluteString,
46-
path: fileURL.path,
47-
shouldTrackProgress: shouldTrackProgress
45+
url: prepData.serverURL.absoluteString,
46+
path: prepData.fileURL.path,
47+
shouldTrackProgress: prepData.shouldTrackProgress
4848
)
4949
).store(in: &cancellables)
5050
} catch {
5151
call.sendError(error, source: call.getString("url"), target: call.getString("path"))
5252
}
5353
}
54-
54+
5555
/// Uploads a file from the provided path to the specified server URL.
5656
///
5757
/// - Parameter call: The Capacitor call containing `url`, `path`, `fileKey`, and optional HTTP options.
5858
@objc func uploadFile(_ call: CAPPluginCall) {
5959
do {
60-
let (serverURL, fileURL, shouldTrackProgress, httpOptions) = try validateAndPrepare(call: call, action: .upload)
60+
let prepData = try validateAndPrepare(call: call, action: .upload)
6161
let chunkedMode = call.getBool("chunkedMode", false)
6262
let mimeType = call.getString("mimeType")
6363
let fileKey = call.getString("fileKey") ?? "file"
@@ -66,55 +66,63 @@ public class FileTransferPlugin: CAPPlugin, CAPBridgedPlugin {
6666
mimeType: mimeType,
6767
fileKey: fileKey
6868
)
69-
69+
7070
try manager.uploadFile(
71-
fromFileURL: fileURL,
72-
toServerURL: serverURL,
71+
fromFileURL: prepData.fileURL,
72+
toServerURL: prepData.serverURL,
7373
withUploadOptions: uploadOptions,
74-
andHttpOptions: httpOptions
74+
andHttpOptions: prepData.httpOptions
7575
).sink(
76-
receiveCompletion: handleCompletion(call: call, source: fileURL.absoluteString, target: serverURL.absoluteString),
76+
receiveCompletion: handleCompletion(call: call, source: prepData.fileURL.absoluteString, target: prepData.serverURL.absoluteString),
7777
receiveValue: handleReceiveValue(
7878
call: call,
7979
type: .upload,
80-
url: serverURL.absoluteString,
81-
path: fileURL.path,
82-
shouldTrackProgress: shouldTrackProgress
80+
url: prepData.serverURL.absoluteString,
81+
path: prepData.fileURL.path,
82+
shouldTrackProgress: prepData.shouldTrackProgress
8383
)
8484
).store(in: &cancellables)
8585
} catch {
8686
call.sendError(error, source: call.getString("path"), target: call.getString("url"))
8787
}
8888
}
89-
89+
90+
/// Structure to hold transfer preparation data.
91+
private struct TransferPreparationData {
92+
let serverURL: URL
93+
let fileURL: URL
94+
let shouldTrackProgress: Bool
95+
let httpOptions: IONFLTRHttpOptions
96+
}
97+
9098
/// Validates parameters from the call and prepares transfer-related data.
9199
///
92100
/// - Parameters:
93101
/// - call: The plugin call.
94102
/// - action: The type of action (`upload` or `download`).
95103
/// - Throws: An error if validation fails.
96-
/// - Returns: Tuple containing server URL, file URL, progress flag, and HTTP options.
97-
private func validateAndPrepare(call: CAPPluginCall, action: Action) throws -> (URL, URL, Bool, IONFLTRHttpOptions) {
104+
/// - Returns: Structure containing server URL, file URL, progress flag, and HTTP options.
105+
private func validateAndPrepare(call: CAPPluginCall, action: Action) throws -> TransferPreparationData {
98106
guard let url = call.getString("url") else {
99107
throw FileTransferError.invalidServerUrl(nil)
100108
}
101-
109+
102110
guard let serverURL = URL(string: url) else {
103111
throw FileTransferError.invalidServerUrl(url)
104112
}
105-
113+
106114
guard let path = call.getString("path") else {
107115
throw FileTransferError.invalidParameters("Path is required.")
108116
}
109-
117+
110118
guard let fileURL = URL(string: path) else {
111119
throw FileTransferError.invalidParameters("Path is invalid.")
112120
}
113121

114122
let shouldTrackProgress = call.getBool("progress", false)
115123
let headers = call.getObject("headers") ?? JSObject()
116124
let params = call.getObject("params") ?? JSObject()
117-
125+
118126
let httpOptions = IONFLTRHttpOptions(
119127
method: call.getString("method") ?? defaultHTTPMethod(for: action),
120128
params: extractParams(from: params),
@@ -123,10 +131,15 @@ public class FileTransferPlugin: CAPPlugin, CAPBridgedPlugin {
123131
disableRedirects: call.getBool("disableRedirects", false),
124132
shouldEncodeUrlParams: call.getBool("shouldEncodeUrlParams", true)
125133
)
126-
127-
return (serverURL, fileURL, shouldTrackProgress, httpOptions)
134+
135+
return TransferPreparationData(
136+
serverURL: serverURL,
137+
fileURL: fileURL,
138+
shouldTrackProgress: shouldTrackProgress,
139+
httpOptions: httpOptions
140+
)
128141
}
129-
142+
130143
/// Provides the default HTTP method for the given action.
131144
private func defaultHTTPMethod(for action: Action) -> String {
132145
switch action {
@@ -136,7 +149,7 @@ public class FileTransferPlugin: CAPPlugin, CAPBridgedPlugin {
136149
return "POST"
137150
}
138151
}
139-
152+
140153
/// Converts a JSObject to a string dictionary used for headers.
141154
private func extractHeaders(from jsObject: JSObject) -> [String: String] {
142155
return jsObject.reduce(into: [String: String]()) { result, pair in
@@ -161,7 +174,7 @@ public class FileTransferPlugin: CAPPlugin, CAPBridgedPlugin {
161174
}
162175
return result
163176
}
164-
177+
165178
/// Handles completion of the upload or download Combine pipeline.
166179
private func handleCompletion(call: CAPPluginCall, source: String, target: String) -> (Subscribers.Completion<Error>) -> Void {
167180
return { completion in
@@ -228,7 +241,7 @@ public class FileTransferPlugin: CAPPlugin, CAPBridgedPlugin {
228241
}
229242
}
230243
}
231-
244+
232245
/// Reports a progress event to JavaScript listeners if conditions are met.
233246
///
234247
/// This method emits a `"progress"` event with details about the transfer status, including
@@ -274,12 +287,12 @@ extension CAPPluginCall {
274287
func sendError(_ error: Error, source: String?, target: String?) {
275288
var pluginError: FileTransferError
276289
switch error {
277-
case let error as FileTransferError:
278-
pluginError = error
279-
case let error as IONFLTRException:
280-
pluginError = error.toFileTransferError()
281-
default:
282-
pluginError = .genericError(cause: error)
290+
case let error as FileTransferError:
291+
pluginError = error
292+
case let error as IONFLTRException:
293+
pluginError = error.toFileTransferError()
294+
default:
295+
pluginError = .genericError(cause: error)
283296
}
284297
pluginError.source = source
285298
pluginError.target = target

0 commit comments

Comments
 (0)