@capacitor-firebase/functions 8.0.0 → 8.0.1-dev.66db168.1770636703
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 +1 -1
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/functions/FirebaseFunctions.java +19 -6
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/functions/FirebaseFunctionsPlugin.java +6 -3
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/functions/classes/options/CallByNameOptions.java +2 -2
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/functions/classes/options/CallByUrlOptions.java +3 -2
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/functions/classes/options/CallOptions.java +10 -1
- package/dist/esm/definitions.d.ts +6 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.js +6 -2
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +6 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +6 -2
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Classes/Options/CallByNameOptions.swift +2 -2
- package/ios/Plugin/Classes/Options/CallByUrlOptions.swift +2 -2
- package/ios/Plugin/Classes/Options/CallOptions.swift +7 -1
- package/ios/Plugin/FirebaseFunctions.swift +23 -10
- package/ios/Plugin/FirebaseFunctionsPlugin.swift +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Unofficial Capacitor plugin for [Firebase Cloud Functions](https://firebase.goog
|
|
|
4
4
|
|
|
5
5
|
<div class="capawesome-z29o10a">
|
|
6
6
|
<a href="https://cloud.capawesome.io/" target="_blank">
|
|
7
|
-
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-
|
|
7
|
+
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
|
|
8
8
|
</a>
|
|
9
9
|
</div>
|
|
10
10
|
|
|
@@ -7,6 +7,7 @@ import io.capawesome.capacitorjs.plugins.firebase.functions.classes.options.Call
|
|
|
7
7
|
import io.capawesome.capacitorjs.plugins.firebase.functions.classes.results.CallResult;
|
|
8
8
|
import io.capawesome.capacitorjs.plugins.firebase.functions.interfaces.NonEmptyResultCallback;
|
|
9
9
|
import java.net.URL;
|
|
10
|
+
import java.util.concurrent.TimeUnit;
|
|
10
11
|
|
|
11
12
|
public class FirebaseFunctions {
|
|
12
13
|
|
|
@@ -20,9 +21,15 @@ public class FirebaseFunctions {
|
|
|
20
21
|
String name = options.getName();
|
|
21
22
|
String region = options.getRegion();
|
|
22
23
|
Object data = options.getData();
|
|
24
|
+
Long timeout = options.getTimeout();
|
|
23
25
|
|
|
24
|
-
getFirebaseFunctionsInstance(region)
|
|
25
|
-
|
|
26
|
+
com.google.firebase.functions.HttpsCallableReference callable = getFirebaseFunctionsInstance(region).getHttpsCallable(name);
|
|
27
|
+
|
|
28
|
+
if (timeout != null) {
|
|
29
|
+
callable.setTimeout(timeout, TimeUnit.MILLISECONDS);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
callable
|
|
26
33
|
.call(data)
|
|
27
34
|
.addOnSuccessListener(task -> {
|
|
28
35
|
CallResult result = new CallResult(task.getData());
|
|
@@ -36,9 +43,15 @@ public class FirebaseFunctions {
|
|
|
36
43
|
public void callByUrl(@NonNull CallByUrlOptions options, @NonNull NonEmptyResultCallback callback) {
|
|
37
44
|
URL url = options.getUrl();
|
|
38
45
|
Object data = options.getData();
|
|
46
|
+
Long timeout = options.getTimeout();
|
|
47
|
+
|
|
48
|
+
com.google.firebase.functions.HttpsCallableReference callable = getFirebaseFunctionsInstance(null).getHttpsCallableFromUrl(url);
|
|
49
|
+
|
|
50
|
+
if (timeout != null) {
|
|
51
|
+
callable.setTimeout(timeout, TimeUnit.MILLISECONDS);
|
|
52
|
+
}
|
|
39
53
|
|
|
40
|
-
|
|
41
|
-
.getHttpsCallableFromUrl(url)
|
|
54
|
+
callable
|
|
42
55
|
.call(data)
|
|
43
56
|
.addOnSuccessListener(task -> {
|
|
44
57
|
CallResult result = new CallResult(task.getData());
|
|
@@ -49,8 +62,8 @@ public class FirebaseFunctions {
|
|
|
49
62
|
});
|
|
50
63
|
}
|
|
51
64
|
|
|
52
|
-
public void useEmulator(@NonNull String host, int port) {
|
|
53
|
-
getFirebaseFunctionsInstance(
|
|
65
|
+
public void useEmulator(@NonNull String host, int port, @Nullable String regionOrCustomDomain) {
|
|
66
|
+
getFirebaseFunctionsInstance(regionOrCustomDomain).useEmulator(host, port);
|
|
54
67
|
}
|
|
55
68
|
|
|
56
69
|
private com.google.firebase.functions.FirebaseFunctions getFirebaseFunctionsInstance(@Nullable String regionOrCustomDomain) {
|
|
@@ -36,8 +36,9 @@ public class FirebaseFunctionsPlugin extends Plugin {
|
|
|
36
36
|
}
|
|
37
37
|
String region = json.getString("region", null);
|
|
38
38
|
Object data = json.opt("data");
|
|
39
|
+
Long timeout = json.has("timeout") ? json.getLong("timeout") : null;
|
|
39
40
|
|
|
40
|
-
CallByNameOptions options = new CallByNameOptions(name, region, data);
|
|
41
|
+
CallByNameOptions options = new CallByNameOptions(name, region, data, timeout);
|
|
41
42
|
NonEmptyResultCallback callback = new NonEmptyResultCallback() {
|
|
42
43
|
@Override
|
|
43
44
|
public void success(Result result) {
|
|
@@ -68,8 +69,9 @@ public class FirebaseFunctionsPlugin extends Plugin {
|
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
71
|
Object data = json.opt("data");
|
|
72
|
+
Long timeout = json.has("timeout") ? json.getLong("timeout") : null;
|
|
71
73
|
|
|
72
|
-
CallByUrlOptions options = new CallByUrlOptions(url, data);
|
|
74
|
+
CallByUrlOptions options = new CallByUrlOptions(url, data, timeout);
|
|
73
75
|
NonEmptyResultCallback callback = new NonEmptyResultCallback() {
|
|
74
76
|
@Override
|
|
75
77
|
public void success(Result result) {
|
|
@@ -99,8 +101,9 @@ public class FirebaseFunctionsPlugin extends Plugin {
|
|
|
99
101
|
return;
|
|
100
102
|
}
|
|
101
103
|
int port = call.getInt("port", 5001);
|
|
104
|
+
String regionOrCustomDomain = call.getString("regionOrCustomDomain", null);
|
|
102
105
|
|
|
103
|
-
implementation.useEmulator(host, port);
|
|
106
|
+
implementation.useEmulator(host, port, regionOrCustomDomain);
|
|
104
107
|
call.resolve();
|
|
105
108
|
} catch (Exception exception) {
|
|
106
109
|
Logger.error(TAG, exception.getMessage(), exception);
|
|
@@ -11,8 +11,8 @@ public class CallByNameOptions extends CallOptions {
|
|
|
11
11
|
@Nullable
|
|
12
12
|
private String region;
|
|
13
13
|
|
|
14
|
-
public CallByNameOptions(@NonNull String name, @Nullable String region, Object data) {
|
|
15
|
-
super(data);
|
|
14
|
+
public CallByNameOptions(@NonNull String name, @Nullable String region, Object data, @Nullable Long timeout) {
|
|
15
|
+
super(data, timeout);
|
|
16
16
|
this.name = name;
|
|
17
17
|
this.region = region;
|
|
18
18
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package io.capawesome.capacitorjs.plugins.firebase.functions.classes.options;
|
|
2
2
|
|
|
3
3
|
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
4
5
|
import java.net.MalformedURLException;
|
|
5
6
|
import java.net.URL;
|
|
6
7
|
|
|
@@ -9,8 +10,8 @@ public class CallByUrlOptions extends CallOptions {
|
|
|
9
10
|
@NonNull
|
|
10
11
|
private URL url;
|
|
11
12
|
|
|
12
|
-
public CallByUrlOptions(@NonNull String url, Object data) throws MalformedURLException {
|
|
13
|
-
super(data);
|
|
13
|
+
public CallByUrlOptions(@NonNull String url, Object data, @Nullable Long timeout) throws MalformedURLException {
|
|
14
|
+
super(data, timeout);
|
|
14
15
|
this.url = new URL(url);
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -7,12 +7,21 @@ public class CallOptions {
|
|
|
7
7
|
@Nullable
|
|
8
8
|
private Object data;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
@Nullable
|
|
11
|
+
private Long timeout;
|
|
12
|
+
|
|
13
|
+
public CallOptions(@Nullable Object data, @Nullable Long timeout) {
|
|
11
14
|
this.data = data;
|
|
15
|
+
this.timeout = timeout;
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
@Nullable
|
|
15
19
|
public Object getData() {
|
|
16
20
|
return data;
|
|
17
21
|
}
|
|
22
|
+
|
|
23
|
+
@Nullable
|
|
24
|
+
public Long getTimeout() {
|
|
25
|
+
return timeout;
|
|
26
|
+
}
|
|
18
27
|
}
|
|
@@ -77,6 +77,12 @@ export interface CallOptions<RequestData = unknown> {
|
|
|
77
77
|
* @since 6.1.0
|
|
78
78
|
*/
|
|
79
79
|
data?: RequestData | null;
|
|
80
|
+
/**
|
|
81
|
+
* Time in milliseconds after which to cancel if there is no response.
|
|
82
|
+
*
|
|
83
|
+
* @since 8.1.0
|
|
84
|
+
*/
|
|
85
|
+
timeout?: number;
|
|
80
86
|
}
|
|
81
87
|
/**
|
|
82
88
|
* @since 6.1.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface FirebaseFunctionsPlugin {\n /**\n * Call a callable function by name.\n *\n * @since 6.1.0\n */\n callByName<RequestData = unknown, ResponseData = unknown>(\n options: CallByNameOptions<RequestData>,\n ): Promise<CallByNameResult<ResponseData>>;\n /**\n * Call a callable function by URL.\n *\n * @since 6.1.0\n */\n callByUrl<RequestData = unknown, ResponseData = unknown>(\n options: CallByUrlOptions<RequestData>,\n ): Promise<CallByUrlResult<ResponseData>>;\n /**\n * Instrument your app to talk to the Cloud Functions emulator.\n *\n * On Android, the cleartext traffic must be allowed. On the Capacitor configuration:\n * ```\n * {\n * server: {\n * cleartext: true\n * }\n * }\n * ```\n * **The cleartext traffic is not intended for use in production.**\n *\n * @since 6.1.0\n */\n useEmulator(options: UseEmulatorOptions): Promise<void>;\n}\n\n/**\n * @since 6.1.0\n */\nexport interface CallByNameOptions<RequestData = unknown>\n extends CallOptions<RequestData> {\n /**\n * The name of the callable function.\n *\n * @example 'myFunction'\n * @since 6.1.0\n */\n name: string;\n /**\n * The region of the callable function.\n *\n * @example 'us-central1'\n * @since 6.1.0\n */\n region?: string;\n}\n\n/**\n * @since 6.1.0\n */\nexport type CallByNameResult<ResponseData = unknown> = CallResult<ResponseData>;\n\n/**\n * @since 6.1.0\n */\nexport interface CallByUrlOptions<RequestData = unknown>\n extends CallOptions<RequestData> {\n /**\n * The URL of the callable function.\n *\n * @example 'https://us-central1-my-project.cloudfunctions.net/myFunction'\n * @since 6.1.0\n */\n url: string;\n}\n\n/**\n * @since 6.1.0\n */\nexport type CallByUrlResult<ResponseData = unknown> = CallResult<ResponseData>;\n\n/**\n * @since 6.1.0\n */\nexport interface CallOptions<RequestData = unknown> {\n /**\n * The data to pass to the callable function.\n *\n * @since 6.1.0\n */\n data?: RequestData | null;\n}\n\n/**\n * @since 6.1.0\n */\nexport interface CallResult<ResponseData = unknown> {\n /**\n * The result of the callable function.\n *\n * @since 6.1.0\n */\n data: ResponseData;\n}\n\n/**\n * @since 6.1.0\n */\nexport interface UseEmulatorOptions {\n /**\n * The emulator host without any port or scheme.\n *\n * Note when using a Android Emulator device: 10.0.2.2 is the special IP address to connect to the 'localhost' of the host computer.\n *\n * @since 6.1.0\n * @example \"127.0.0.1\"\n */\n host: string;\n /**\n * The emulator port.\n *\n * @since 6.1.0\n * @default 5001\n * @example 5001\n */\n port?: number;\n /**\n * The region the callable functions are located in or a custom domain hosting the callable functions.\n *\n * @example 'us-central1'\n * @example 'https://mydomain.com'\n */\n regionOrCustomDomain?: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface FirebaseFunctionsPlugin {\n /**\n * Call a callable function by name.\n *\n * @since 6.1.0\n */\n callByName<RequestData = unknown, ResponseData = unknown>(\n options: CallByNameOptions<RequestData>,\n ): Promise<CallByNameResult<ResponseData>>;\n /**\n * Call a callable function by URL.\n *\n * @since 6.1.0\n */\n callByUrl<RequestData = unknown, ResponseData = unknown>(\n options: CallByUrlOptions<RequestData>,\n ): Promise<CallByUrlResult<ResponseData>>;\n /**\n * Instrument your app to talk to the Cloud Functions emulator.\n *\n * On Android, the cleartext traffic must be allowed. On the Capacitor configuration:\n * ```\n * {\n * server: {\n * cleartext: true\n * }\n * }\n * ```\n * **The cleartext traffic is not intended for use in production.**\n *\n * @since 6.1.0\n */\n useEmulator(options: UseEmulatorOptions): Promise<void>;\n}\n\n/**\n * @since 6.1.0\n */\nexport interface CallByNameOptions<RequestData = unknown>\n extends CallOptions<RequestData> {\n /**\n * The name of the callable function.\n *\n * @example 'myFunction'\n * @since 6.1.0\n */\n name: string;\n /**\n * The region of the callable function.\n *\n * @example 'us-central1'\n * @since 6.1.0\n */\n region?: string;\n}\n\n/**\n * @since 6.1.0\n */\nexport type CallByNameResult<ResponseData = unknown> = CallResult<ResponseData>;\n\n/**\n * @since 6.1.0\n */\nexport interface CallByUrlOptions<RequestData = unknown>\n extends CallOptions<RequestData> {\n /**\n * The URL of the callable function.\n *\n * @example 'https://us-central1-my-project.cloudfunctions.net/myFunction'\n * @since 6.1.0\n */\n url: string;\n}\n\n/**\n * @since 6.1.0\n */\nexport type CallByUrlResult<ResponseData = unknown> = CallResult<ResponseData>;\n\n/**\n * @since 6.1.0\n */\nexport interface CallOptions<RequestData = unknown> {\n /**\n * The data to pass to the callable function.\n *\n * @since 6.1.0\n */\n data?: RequestData | null;\n /**\n * Time in milliseconds after which to cancel if there is no response.\n *\n * @since 8.1.0\n */\n timeout?: number;\n}\n\n/**\n * @since 6.1.0\n */\nexport interface CallResult<ResponseData = unknown> {\n /**\n * The result of the callable function.\n *\n * @since 6.1.0\n */\n data: ResponseData;\n}\n\n/**\n * @since 6.1.0\n */\nexport interface UseEmulatorOptions {\n /**\n * The emulator host without any port or scheme.\n *\n * Note when using a Android Emulator device: 10.0.2.2 is the special IP address to connect to the 'localhost' of the host computer.\n *\n * @since 6.1.0\n * @example \"127.0.0.1\"\n */\n host: string;\n /**\n * The emulator port.\n *\n * @since 6.1.0\n * @default 5001\n * @example 5001\n */\n port?: number;\n /**\n * The region the callable functions are located in or a custom domain hosting the callable functions.\n *\n * @example 'us-central1'\n * @example 'https://mydomain.com'\n */\n regionOrCustomDomain?: string;\n}\n"]}
|
package/dist/esm/web.js
CHANGED
|
@@ -3,7 +3,9 @@ import { connectFunctionsEmulator, getFunctions, httpsCallable, httpsCallableFro
|
|
|
3
3
|
export class FirebaseFunctionsWeb extends WebPlugin {
|
|
4
4
|
async callByName(options) {
|
|
5
5
|
const functions = getFunctions(undefined, options.region);
|
|
6
|
-
const callable = httpsCallable(functions, options.name
|
|
6
|
+
const callable = httpsCallable(functions, options.name, {
|
|
7
|
+
timeout: options.timeout,
|
|
8
|
+
});
|
|
7
9
|
const result = await callable(options.data);
|
|
8
10
|
return {
|
|
9
11
|
data: result.data,
|
|
@@ -11,7 +13,9 @@ export class FirebaseFunctionsWeb extends WebPlugin {
|
|
|
11
13
|
}
|
|
12
14
|
async callByUrl(options) {
|
|
13
15
|
const functions = getFunctions();
|
|
14
|
-
const callable = httpsCallableFromURL(functions, options.url
|
|
16
|
+
const callable = httpsCallableFromURL(functions, options.url, {
|
|
17
|
+
timeout: options.timeout,
|
|
18
|
+
});
|
|
15
19
|
const result = await callable(options.data);
|
|
16
20
|
return {
|
|
17
21
|
data: result.data,
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,aAAa,EACb,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAW5B,MAAM,OAAO,oBACX,SAAQ,SAAS;IAGV,KAAK,CAAC,UAAU,CACrB,OAAuC;QAEvC,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAC1D,MAAM,QAAQ,GAAG,aAAa,CAC5B,SAAS,EACT,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,aAAa,EACb,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAW5B,MAAM,OAAO,oBACX,SAAQ,SAAS;IAGV,KAAK,CAAC,UAAU,CACrB,OAAuC;QAEvC,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAC1D,MAAM,QAAQ,GAAG,aAAa,CAC5B,SAAS,EACT,OAAO,CAAC,IAAI,EACZ;YACE,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CACF,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,SAAS,CACpB,OAAsC;QAEtC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;QACjC,MAAM,QAAQ,GAAG,oBAAoB,CACnC,SAAS,EACT,OAAO,CAAC,GAAG,EACX;YACE,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CACF,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,OAA2B;QAClD,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;QACxE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC;QAClC,wBAAwB,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1D,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport {\n connectFunctionsEmulator,\n getFunctions,\n httpsCallable,\n httpsCallableFromURL,\n} from 'firebase/functions';\n\nimport type {\n CallByNameOptions,\n CallByNameResult,\n CallByUrlOptions,\n CallResult,\n FirebaseFunctionsPlugin,\n UseEmulatorOptions,\n} from './definitions';\n\nexport class FirebaseFunctionsWeb\n extends WebPlugin\n implements FirebaseFunctionsPlugin\n{\n public async callByName<RequestData = unknown, ResponseData = unknown>(\n options: CallByNameOptions<RequestData>,\n ): Promise<CallByNameResult<ResponseData>> {\n const functions = getFunctions(undefined, options.region);\n const callable = httpsCallable<RequestData, ResponseData>(\n functions,\n options.name,\n {\n timeout: options.timeout,\n },\n );\n const result = await callable(options.data);\n return {\n data: result.data,\n };\n }\n\n public async callByUrl<RequestData = unknown, ResponseData = unknown>(\n options: CallByUrlOptions<RequestData>,\n ): Promise<CallResult<ResponseData>> {\n const functions = getFunctions();\n const callable = httpsCallableFromURL<RequestData, ResponseData>(\n functions,\n options.url,\n {\n timeout: options.timeout,\n },\n );\n const result = await callable(options.data);\n return {\n data: result.data,\n };\n }\n\n public async useEmulator(options: UseEmulatorOptions): Promise<void> {\n const functions = getFunctions(undefined, options.regionOrCustomDomain);\n const port = options.port || 5001;\n connectFunctionsEmulator(functions, options.host, port);\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -10,7 +10,9 @@ const FirebaseFunctions = core.registerPlugin('FirebaseFunctions', {
|
|
|
10
10
|
class FirebaseFunctionsWeb extends core.WebPlugin {
|
|
11
11
|
async callByName(options) {
|
|
12
12
|
const functions$1 = functions.getFunctions(undefined, options.region);
|
|
13
|
-
const callable = functions.httpsCallable(functions$1, options.name
|
|
13
|
+
const callable = functions.httpsCallable(functions$1, options.name, {
|
|
14
|
+
timeout: options.timeout,
|
|
15
|
+
});
|
|
14
16
|
const result = await callable(options.data);
|
|
15
17
|
return {
|
|
16
18
|
data: result.data,
|
|
@@ -18,7 +20,9 @@ class FirebaseFunctionsWeb extends core.WebPlugin {
|
|
|
18
20
|
}
|
|
19
21
|
async callByUrl(options) {
|
|
20
22
|
const functions$1 = functions.getFunctions();
|
|
21
|
-
const callable = functions.httpsCallableFromURL(functions$1, options.url
|
|
23
|
+
const callable = functions.httpsCallableFromURL(functions$1, options.url, {
|
|
24
|
+
timeout: options.timeout,
|
|
25
|
+
});
|
|
22
26
|
const result = await callable(options.data);
|
|
23
27
|
return {
|
|
24
28
|
data: result.data,
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst FirebaseFunctions = registerPlugin('FirebaseFunctions', {\n web: () => import('./web').then(m => new m.FirebaseFunctionsWeb()),\n});\nexport * from './definitions';\nexport { FirebaseFunctions };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { connectFunctionsEmulator, getFunctions, httpsCallable, httpsCallableFromURL, } from 'firebase/functions';\nexport class FirebaseFunctionsWeb extends WebPlugin {\n async callByName(options) {\n const functions = getFunctions(undefined, options.region);\n const callable = httpsCallable(functions, options.name);\n const result = await callable(options.data);\n return {\n data: result.data,\n };\n }\n async callByUrl(options) {\n const functions = getFunctions();\n const callable = httpsCallableFromURL(functions, options.url);\n const result = await callable(options.data);\n return {\n data: result.data,\n };\n }\n async useEmulator(options) {\n const functions = getFunctions(undefined, options.regionOrCustomDomain);\n const port = options.port || 5001;\n connectFunctionsEmulator(functions, options.host, port);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","functions","getFunctions","httpsCallable","httpsCallableFromURL","connectFunctionsEmulator"],"mappings":";;;;;AACK,MAAC,iBAAiB,GAAGA,mBAAc,CAAC,mBAAmB,EAAE;AAC9D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,oBAAoB,EAAE,CAAC;AACtE,CAAC;;ACDM,MAAM,oBAAoB,SAASC,cAAS,CAAC;AACpD,IAAI,MAAM,UAAU,CAAC,OAAO,EAAE;AAC9B,QAAQ,MAAMC,WAAS,GAAGC,sBAAY,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC;AACjE,QAAQ,MAAM,QAAQ,GAAGC,uBAAa,CAACF,WAAS,EAAE,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst FirebaseFunctions = registerPlugin('FirebaseFunctions', {\n web: () => import('./web').then(m => new m.FirebaseFunctionsWeb()),\n});\nexport * from './definitions';\nexport { FirebaseFunctions };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { connectFunctionsEmulator, getFunctions, httpsCallable, httpsCallableFromURL, } from 'firebase/functions';\nexport class FirebaseFunctionsWeb extends WebPlugin {\n async callByName(options) {\n const functions = getFunctions(undefined, options.region);\n const callable = httpsCallable(functions, options.name, {\n timeout: options.timeout,\n });\n const result = await callable(options.data);\n return {\n data: result.data,\n };\n }\n async callByUrl(options) {\n const functions = getFunctions();\n const callable = httpsCallableFromURL(functions, options.url, {\n timeout: options.timeout,\n });\n const result = await callable(options.data);\n return {\n data: result.data,\n };\n }\n async useEmulator(options) {\n const functions = getFunctions(undefined, options.regionOrCustomDomain);\n const port = options.port || 5001;\n connectFunctionsEmulator(functions, options.host, port);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","functions","getFunctions","httpsCallable","httpsCallableFromURL","connectFunctionsEmulator"],"mappings":";;;;;AACK,MAAC,iBAAiB,GAAGA,mBAAc,CAAC,mBAAmB,EAAE;AAC9D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,oBAAoB,EAAE,CAAC;AACtE,CAAC;;ACDM,MAAM,oBAAoB,SAASC,cAAS,CAAC;AACpD,IAAI,MAAM,UAAU,CAAC,OAAO,EAAE;AAC9B,QAAQ,MAAMC,WAAS,GAAGC,sBAAY,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC;AACjE,QAAQ,MAAM,QAAQ,GAAGC,uBAAa,CAACF,WAAS,EAAE,OAAO,CAAC,IAAI,EAAE;AAChE,YAAY,OAAO,EAAE,OAAO,CAAC,OAAO;AACpC,SAAS,CAAC;AACV,QAAQ,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;AACnD,QAAQ,OAAO;AACf,YAAY,IAAI,EAAE,MAAM,CAAC,IAAI;AAC7B,SAAS;AACT,IAAI;AACJ,IAAI,MAAM,SAAS,CAAC,OAAO,EAAE;AAC7B,QAAQ,MAAMA,WAAS,GAAGC,sBAAY,EAAE;AACxC,QAAQ,MAAM,QAAQ,GAAGE,8BAAoB,CAACH,WAAS,EAAE,OAAO,CAAC,GAAG,EAAE;AACtE,YAAY,OAAO,EAAE,OAAO,CAAC,OAAO;AACpC,SAAS,CAAC;AACV,QAAQ,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;AACnD,QAAQ,OAAO;AACf,YAAY,IAAI,EAAE,MAAM,CAAC,IAAI;AAC7B,SAAS;AACT,IAAI;AACJ,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;AAC/B,QAAQ,MAAMA,WAAS,GAAGC,sBAAY,CAAC,SAAS,EAAE,OAAO,CAAC,oBAAoB,CAAC;AAC/E,QAAQ,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI;AACzC,QAAQG,kCAAwB,CAACJ,WAAS,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC;AAC/D,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -8,7 +8,9 @@ var capacitorFirebaseFunctions = (function (exports, core, functions) {
|
|
|
8
8
|
class FirebaseFunctionsWeb extends core.WebPlugin {
|
|
9
9
|
async callByName(options) {
|
|
10
10
|
const functions$1 = functions.getFunctions(undefined, options.region);
|
|
11
|
-
const callable = functions.httpsCallable(functions$1, options.name
|
|
11
|
+
const callable = functions.httpsCallable(functions$1, options.name, {
|
|
12
|
+
timeout: options.timeout,
|
|
13
|
+
});
|
|
12
14
|
const result = await callable(options.data);
|
|
13
15
|
return {
|
|
14
16
|
data: result.data,
|
|
@@ -16,7 +18,9 @@ var capacitorFirebaseFunctions = (function (exports, core, functions) {
|
|
|
16
18
|
}
|
|
17
19
|
async callByUrl(options) {
|
|
18
20
|
const functions$1 = functions.getFunctions();
|
|
19
|
-
const callable = functions.httpsCallableFromURL(functions$1, options.url
|
|
21
|
+
const callable = functions.httpsCallableFromURL(functions$1, options.url, {
|
|
22
|
+
timeout: options.timeout,
|
|
23
|
+
});
|
|
20
24
|
const result = await callable(options.data);
|
|
21
25
|
return {
|
|
22
26
|
data: result.data,
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst FirebaseFunctions = registerPlugin('FirebaseFunctions', {\n web: () => import('./web').then(m => new m.FirebaseFunctionsWeb()),\n});\nexport * from './definitions';\nexport { FirebaseFunctions };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { connectFunctionsEmulator, getFunctions, httpsCallable, httpsCallableFromURL, } from 'firebase/functions';\nexport class FirebaseFunctionsWeb extends WebPlugin {\n async callByName(options) {\n const functions = getFunctions(undefined, options.region);\n const callable = httpsCallable(functions, options.name);\n const result = await callable(options.data);\n return {\n data: result.data,\n };\n }\n async callByUrl(options) {\n const functions = getFunctions();\n const callable = httpsCallableFromURL(functions, options.url);\n const result = await callable(options.data);\n return {\n data: result.data,\n };\n }\n async useEmulator(options) {\n const functions = getFunctions(undefined, options.regionOrCustomDomain);\n const port = options.port || 5001;\n connectFunctionsEmulator(functions, options.host, port);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","functions","getFunctions","httpsCallable","httpsCallableFromURL","connectFunctionsEmulator"],"mappings":";;;AACK,UAAC,iBAAiB,GAAGA,mBAAc,CAAC,mBAAmB,EAAE;IAC9D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,oBAAoB,EAAE,CAAC;IACtE,CAAC;;ICDM,MAAM,oBAAoB,SAASC,cAAS,CAAC;IACpD,IAAI,MAAM,UAAU,CAAC,OAAO,EAAE;IAC9B,QAAQ,MAAMC,WAAS,GAAGC,sBAAY,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC;IACjE,QAAQ,MAAM,QAAQ,GAAGC,uBAAa,CAACF,WAAS,EAAE,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst FirebaseFunctions = registerPlugin('FirebaseFunctions', {\n web: () => import('./web').then(m => new m.FirebaseFunctionsWeb()),\n});\nexport * from './definitions';\nexport { FirebaseFunctions };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { connectFunctionsEmulator, getFunctions, httpsCallable, httpsCallableFromURL, } from 'firebase/functions';\nexport class FirebaseFunctionsWeb extends WebPlugin {\n async callByName(options) {\n const functions = getFunctions(undefined, options.region);\n const callable = httpsCallable(functions, options.name, {\n timeout: options.timeout,\n });\n const result = await callable(options.data);\n return {\n data: result.data,\n };\n }\n async callByUrl(options) {\n const functions = getFunctions();\n const callable = httpsCallableFromURL(functions, options.url, {\n timeout: options.timeout,\n });\n const result = await callable(options.data);\n return {\n data: result.data,\n };\n }\n async useEmulator(options) {\n const functions = getFunctions(undefined, options.regionOrCustomDomain);\n const port = options.port || 5001;\n connectFunctionsEmulator(functions, options.host, port);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","functions","getFunctions","httpsCallable","httpsCallableFromURL","connectFunctionsEmulator"],"mappings":";;;AACK,UAAC,iBAAiB,GAAGA,mBAAc,CAAC,mBAAmB,EAAE;IAC9D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,oBAAoB,EAAE,CAAC;IACtE,CAAC;;ICDM,MAAM,oBAAoB,SAASC,cAAS,CAAC;IACpD,IAAI,MAAM,UAAU,CAAC,OAAO,EAAE;IAC9B,QAAQ,MAAMC,WAAS,GAAGC,sBAAY,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC;IACjE,QAAQ,MAAM,QAAQ,GAAGC,uBAAa,CAACF,WAAS,EAAE,OAAO,CAAC,IAAI,EAAE;IAChE,YAAY,OAAO,EAAE,OAAO,CAAC,OAAO;IACpC,SAAS,CAAC;IACV,QAAQ,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;IACnD,QAAQ,OAAO;IACf,YAAY,IAAI,EAAE,MAAM,CAAC,IAAI;IAC7B,SAAS;IACT,IAAI;IACJ,IAAI,MAAM,SAAS,CAAC,OAAO,EAAE;IAC7B,QAAQ,MAAMA,WAAS,GAAGC,sBAAY,EAAE;IACxC,QAAQ,MAAM,QAAQ,GAAGE,8BAAoB,CAACH,WAAS,EAAE,OAAO,CAAC,GAAG,EAAE;IACtE,YAAY,OAAO,EAAE,OAAO,CAAC,OAAO;IACpC,SAAS,CAAC;IACV,QAAQ,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;IACnD,QAAQ,OAAO;IACf,YAAY,IAAI,EAAE,MAAM,CAAC,IAAI;IAC7B,SAAS;IACT,IAAI;IACJ,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;IAC/B,QAAQ,MAAMA,WAAS,GAAGC,sBAAY,CAAC,SAAS,EAAE,OAAO,CAAC,oBAAoB,CAAC;IAC/E,QAAQ,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI;IACzC,QAAQG,kCAAwB,CAACJ,WAAS,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC;IAC/D,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -4,10 +4,10 @@ import Foundation
|
|
|
4
4
|
private var name: String
|
|
5
5
|
private var region: String?
|
|
6
6
|
|
|
7
|
-
init(name: String, region: String?, data: Any?) {
|
|
7
|
+
init(name: String, region: String?, data: Any?, timeout: Int?) {
|
|
8
8
|
self.name = name
|
|
9
9
|
self.region = region
|
|
10
|
-
super.init(data: data)
|
|
10
|
+
super.init(data: data, timeout: timeout)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
func getName() -> String {
|
|
@@ -3,9 +3,9 @@ import Foundation
|
|
|
3
3
|
@objc public class CallByUrlOptions: CallOptions {
|
|
4
4
|
private var url: URL
|
|
5
5
|
|
|
6
|
-
init(url: String, data: Any?) {
|
|
6
|
+
init(url: String, data: Any?, timeout: Int?) {
|
|
7
7
|
self.url = URL(string: url)!
|
|
8
|
-
super.init(data: data)
|
|
8
|
+
super.init(data: data, timeout: timeout)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
func getUrl() -> URL {
|
|
@@ -2,12 +2,18 @@ import Foundation
|
|
|
2
2
|
|
|
3
3
|
@objc public class CallOptions: NSObject {
|
|
4
4
|
private var data: Any?
|
|
5
|
+
private var timeout: Int?
|
|
5
6
|
|
|
6
|
-
init(data: Any?) {
|
|
7
|
+
init(data: Any?, timeout: Int?) {
|
|
7
8
|
self.data = data
|
|
9
|
+
self.timeout = timeout
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
func getData() -> Any? {
|
|
11
13
|
return data
|
|
12
14
|
}
|
|
15
|
+
|
|
16
|
+
func getTimeout() -> Int? {
|
|
17
|
+
return timeout
|
|
18
|
+
}
|
|
13
19
|
}
|
|
@@ -15,16 +15,14 @@ import FirebaseFunctions
|
|
|
15
15
|
|
|
16
16
|
@objc public func callByName(_ options: CallByNameOptions, completion: @escaping (Result?, Error?) -> Void) {
|
|
17
17
|
let name = options.getName()
|
|
18
|
-
let region = options.getRegion()
|
|
19
18
|
let data = options.getData()
|
|
19
|
+
let timeout = options.getTimeout()
|
|
20
20
|
|
|
21
|
-
let functions
|
|
22
|
-
if let region = region {
|
|
23
|
-
functions = Functions.functions(region: region)
|
|
24
|
-
} else {
|
|
25
|
-
functions = Functions.functions()
|
|
26
|
-
}
|
|
21
|
+
let functions = getFunctions(options.getRegion())
|
|
27
22
|
let callable = functions.httpsCallable(name)
|
|
23
|
+
if let timeout = timeout {
|
|
24
|
+
callable.timeoutInterval = TimeInterval(timeout) / 1000.0
|
|
25
|
+
}
|
|
28
26
|
callable.call(data) { (result, error) in
|
|
29
27
|
if let error = error {
|
|
30
28
|
completion(nil, error)
|
|
@@ -38,9 +36,13 @@ import FirebaseFunctions
|
|
|
38
36
|
@objc public func callByUrl(_ options: CallByUrlOptions, completion: @escaping (Result?, Error?) -> Void) {
|
|
39
37
|
let url = options.getUrl()
|
|
40
38
|
let data = options.getData()
|
|
39
|
+
let timeout = options.getTimeout()
|
|
41
40
|
|
|
42
|
-
let functions =
|
|
41
|
+
let functions = getFunctions(nil)
|
|
43
42
|
let callable = functions.httpsCallable(url)
|
|
43
|
+
if let timeout = timeout {
|
|
44
|
+
callable.timeoutInterval = TimeInterval(timeout) / 1000.0
|
|
45
|
+
}
|
|
44
46
|
callable.call(data) { (result, error) in
|
|
45
47
|
if let error = error {
|
|
46
48
|
completion(nil, error)
|
|
@@ -51,7 +53,18 @@ import FirebaseFunctions
|
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
@objc func useEmulator(_ host: String, _ port: Int) {
|
|
55
|
-
|
|
56
|
+
@objc func useEmulator(_ host: String, _ port: Int, _ regionOrCustomDomain: String?) {
|
|
57
|
+
let functions = getFunctions(regionOrCustomDomain)
|
|
58
|
+
functions.useEmulator(withHost: host, port: port)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private func getFunctions(_ regionOrCustomDomain: String?) -> Functions {
|
|
62
|
+
guard let value = regionOrCustomDomain else {
|
|
63
|
+
return Functions.functions()
|
|
64
|
+
}
|
|
65
|
+
if value.hasPrefix("http://") || value.hasPrefix("https://") {
|
|
66
|
+
return Functions.functions(customDomain: value)
|
|
67
|
+
}
|
|
68
|
+
return Functions.functions(region: value)
|
|
56
69
|
}
|
|
57
70
|
}
|
|
@@ -30,8 +30,9 @@ public class FirebaseFunctionsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
30
30
|
}
|
|
31
31
|
let region = call.getString("region")
|
|
32
32
|
let data = call.getValue("data")
|
|
33
|
+
let timeout = call.getInt("timeout")
|
|
33
34
|
|
|
34
|
-
let options = CallByNameOptions(name: name, region: region, data: data)
|
|
35
|
+
let options = CallByNameOptions(name: name, region: region, data: data, timeout: timeout)
|
|
35
36
|
|
|
36
37
|
implementation?.callByName(options, completion: { result, error in
|
|
37
38
|
if let error = error {
|
|
@@ -51,8 +52,9 @@ public class FirebaseFunctionsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
51
52
|
return
|
|
52
53
|
}
|
|
53
54
|
let data = call.getValue("data")
|
|
55
|
+
let timeout = call.getInt("timeout")
|
|
54
56
|
|
|
55
|
-
let options = CallByUrlOptions(url: url, data: data)
|
|
57
|
+
let options = CallByUrlOptions(url: url, data: data, timeout: timeout)
|
|
56
58
|
|
|
57
59
|
implementation?.callByUrl(options, completion: { result, error in
|
|
58
60
|
if let error = error {
|
|
@@ -72,8 +74,9 @@ public class FirebaseFunctionsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
72
74
|
return
|
|
73
75
|
}
|
|
74
76
|
let port = call.getInt("port") ?? 5001
|
|
77
|
+
let regionOrCustomDomain = call.getString("regionOrCustomDomain") ?? nil
|
|
75
78
|
|
|
76
|
-
implementation?.useEmulator(host, port)
|
|
79
|
+
implementation?.useEmulator(host, port, regionOrCustomDomain)
|
|
77
80
|
call.resolve()
|
|
78
81
|
}
|
|
79
82
|
}
|
package/package.json
CHANGED