From ed98e4ae10c19add6e58d64c122b84b309e004b1 Mon Sep 17 00:00:00 2001 From: Piotr Szydelko Date: Wed, 2 Nov 2022 12:22:25 +0100 Subject: [PATCH] [firebase_functions] Add Firebase Cloud Functions plugin --- .github/labeler.yml | 2 + .github/recipe.yaml | 1 + README.md | 2 + packages/firebase_functions/.gitignore | 30 +++++ packages/firebase_functions/CHANGELOG.md | 3 + packages/firebase_functions/LICENSE | 29 +++++ packages/firebase_functions/README.md | 18 +++ .../firebase_functions/example/.gitignore | 46 +++++++ packages/firebase_functions/example/README.md | 16 +++ .../firebase_functions/example/lib/main.dart | 93 +++++++++++++++ .../firebase_functions/example/pubspec.yaml | 21 ++++ .../example/tizen/.gitignore | 5 + .../firebase_functions/example/tizen/App.cs | 20 ++++ .../example/tizen/Runner.csproj | 19 +++ .../example/tizen/shared/res/ic_launcher.png | Bin 0 -> 1443 bytes .../example/tizen/tizen-manifest.xml | 16 +++ .../firebase_functions/lib/desktop_utils.dart | 23 ++++ .../lib/firebase_functions_tizen.dart | 112 ++++++++++++++++++ packages/firebase_functions/pubspec.yaml | 28 +++++ 19 files changed, 484 insertions(+) create mode 100644 packages/firebase_functions/.gitignore create mode 100644 packages/firebase_functions/CHANGELOG.md create mode 100644 packages/firebase_functions/LICENSE create mode 100644 packages/firebase_functions/README.md create mode 100644 packages/firebase_functions/example/.gitignore create mode 100644 packages/firebase_functions/example/README.md create mode 100644 packages/firebase_functions/example/lib/main.dart create mode 100644 packages/firebase_functions/example/pubspec.yaml create mode 100644 packages/firebase_functions/example/tizen/.gitignore create mode 100644 packages/firebase_functions/example/tizen/App.cs create mode 100644 packages/firebase_functions/example/tizen/Runner.csproj create mode 100644 packages/firebase_functions/example/tizen/shared/res/ic_launcher.png create mode 100644 packages/firebase_functions/example/tizen/tizen-manifest.xml create mode 100644 packages/firebase_functions/lib/desktop_utils.dart create mode 100644 packages/firebase_functions/lib/firebase_functions_tizen.dart create mode 100644 packages/firebase_functions/pubspec.yaml diff --git a/.github/labeler.yml b/.github/labeler.yml index 9c3ec5028..17ea9e319 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -11,6 +11,8 @@ - packages/device_info_plus/**/* "p: firebase_core": - packages/firebase_core/**/* +"p: firebase_functions": + - packages/firebase_functions/**/* "p: flutter_app_badger": - packages/flutter_app_badger/**/* "p: flutter_secure_storage": diff --git a/.github/recipe.yaml b/.github/recipe.yaml index 1513a1e8d..5fd24f8db 100644 --- a/.github/recipe.yaml +++ b/.github/recipe.yaml @@ -27,6 +27,7 @@ plugins: google_sign_in: [] image_picker: [] firebase_core: [] + firebase_functions: [] tizen_log: [] tizen_notification: [] wearable_rotary: [] diff --git a/README.md b/README.md index e0c6f09f2..599d19ebe 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina | [**connectivity_plus_tizen**](packages/connectivity_plus) | [connectivity_plus](https://github.com/fluttercommunity/plus_plugins/tree/main/packages/connectivity_plus) (1st-party) | [![pub package](https://img.shields.io/pub/v/connectivity_plus_tizen.svg)](https://pub.dev/packages/connectivity_plus_tizen) | No | | [**device_info_plus_tizen**](packages/device_info_plus) | [device_info_plus](https://github.com/fluttercommunity/plus_plugins/tree/main/packages/device_info_plus) (1st-party) | [![pub package](https://img.shields.io/pub/v/device_info_plus_tizen.svg)](https://pub.dev/packages/device_info_plus_tizen) | No | | [**firebase_core_tizen**](packages/firebase_core) | [firebase_core](https://github.com/firebase/flutterfire/tree/master/packages/firebase_core) | [![pub package](https://img.shields.io/pub/v/firebase_core_tizen.svg)](https://pub.dev/packages/firebase_core_tizen) | No | +| [**firebase_functions_tizen**](packages/firebase_functions) | [firebase_functions](https://github.com/firebase/flutterfire/tree/master/packages/cloud_functions) | [![pub package](https://img.shields.io/pub/v/firebase_functions_tizen.svg)](https://pub.dev/packages/firebase_functions_tizen) | No | | [**flutter_app_badger_tizen**](packages/flutter_app_badger) | [flutter_app_badger](https://github.com/g123k/flutter_app_badger) (3rd-party) | [![pub package](https://img.shields.io/pub/v/flutter_app_badger_tizen.svg)](https://pub.dev/packages/flutter_app_badger_tizen) | No | | [**flutter_secure_storage_tizen**](packages/flutter_secure_storage) | [flutter_secure_storage](https://github.com/mogol/flutter_secure_storage) (3rd-party) | [![pub package](https://img.shields.io/pub/v/flutter_secure_storage_tizen.svg)](https://pub.dev/packages/flutter_secure_storage_tizen) | No | | [**flutter_tts_tizen**](packages/flutter_tts) | [flutter_tts](https://github.com/dlutton/flutter_tts) (3rd-party) | [![pub package](https://img.shields.io/pub/v/flutter_tts_tizen.svg)](https://pub.dev/packages/flutter_tts_tizen) | No | @@ -61,6 +62,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina | [**connectivity_plus_tizen**](packages/connectivity_plus) | 4.0 | ✔️ | ⚠️ | ✔️ | ✔️ | Returns incorrect connection status | | [**device_info_plus_tizen**](packages/device_info_plus) | 4.0 | ✔️ | ✔️ | ✔️ | ✔️ | | [**firebase_core**](packages/firebase_core) | 4.0 | ✔️ | ✔️ | ✔️ | ✔️ | +| [**firebase_functions**](packages/firebase_functions) | 4.0 | ✔️ | ✔️ | ✔️ | ✔️ | | [**flutter_app_badger_tizen**](packages/flutter_app_badger) | 4.0 | ✔️ | ✔️ | ❌ | ❌ | API not supported | | [**flutter_secure_storage_tizen**](packages/flutter_secure_storage) | 4.0 | ✔️ | ✔️ | ✔️ | ✔️ | | [**flutter_tts_tizen**](packages/flutter_tts) | 4.0 | ✔️ | ✔️ | ✔️ | ✔️ | diff --git a/packages/firebase_functions/.gitignore b/packages/firebase_functions/.gitignore new file mode 100644 index 000000000..96486fd93 --- /dev/null +++ b/packages/firebase_functions/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/packages/firebase_functions/CHANGELOG.md b/packages/firebase_functions/CHANGELOG.md new file mode 100644 index 000000000..607323422 --- /dev/null +++ b/packages/firebase_functions/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.1.0 + +* Initial release. diff --git a/packages/firebase_functions/LICENSE b/packages/firebase_functions/LICENSE new file mode 100644 index 000000000..5841c4de2 --- /dev/null +++ b/packages/firebase_functions/LICENSE @@ -0,0 +1,29 @@ +BSD-3-Clause +------------ + +Copyright (c) 2016-present Invertase Limited & Contributors + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Creative Commons Attribution 3.0 License +---------------------------------------- + +Copyright (c) 2016-present Invertase Limited & Contributors + +Documentation and other instructional materials provided for this project +(including on a separate documentation repository or it's documentation website) are +licensed under the Creative Commons Attribution 3.0 License. Code samples/blocks +contained therein are licensed under the BSD-3-Clause License (the "License"), as above. + +You may obtain a copy of the Creative Commons Attribution 3.0 License at + + https://creativecommons.org/licenses/by/3.0/ diff --git a/packages/firebase_functions/README.md b/packages/firebase_functions/README.md new file mode 100644 index 000000000..78188b40c --- /dev/null +++ b/packages/firebase_functions/README.md @@ -0,0 +1,18 @@ +# firebase_functions_tizen + +A new Flutter plugin project. + +## Getting Started + +This project is a starting point for a Flutter +[plug-in package](https://flutter.dev/developing-packages/), +a specialized package that includes platform-specific implementation code for +Android and/or iOS. + +For help getting started with Flutter development, view the +[online documentation](https://flutter.dev/docs), which offers tutorials, +samples, guidance on mobile development, and a full API reference. + +The plugin project was generated without specifying the `--platforms` flag, no platforms are currently supported. +To add platforms, run `flutter create -t plugin --platforms .` in this directory. +You can also find a detailed instruction on how to add platforms in the `pubspec.yaml` at https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms. diff --git a/packages/firebase_functions/example/.gitignore b/packages/firebase_functions/example/.gitignore new file mode 100644 index 000000000..0fa6b675c --- /dev/null +++ b/packages/firebase_functions/example/.gitignore @@ -0,0 +1,46 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Web related +lib/generated_plugin_registrant.dart + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/packages/firebase_functions/example/README.md b/packages/firebase_functions/example/README.md new file mode 100644 index 000000000..a13562602 --- /dev/null +++ b/packages/firebase_functions/example/README.md @@ -0,0 +1,16 @@ +# example + +A new Flutter project. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) + +For help getting started with Flutter, view our +[online documentation](https://flutter.dev/docs), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/packages/firebase_functions/example/lib/main.dart b/packages/firebase_functions/example/lib/main.dart new file mode 100644 index 000000000..2b9a2a2a8 --- /dev/null +++ b/packages/firebase_functions/example/lib/main.dart @@ -0,0 +1,93 @@ +// ignore_for_file: require_trailing_commas, public_member_api_docs, library_private_types_in_public_api +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:core'; + +import 'package:cloud_functions/cloud_functions.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'package:flutter/material.dart'; + +FirebaseOptions get firebaseOptions => const FirebaseOptions( + apiKey: 'AIzaSyAgUhHU8wSJgO5MVNy95tMT07NEjzMOfz0', + authDomain: 'react-native-firebase-testing.firebaseapp.com', + databaseURL: 'https://react-native-firebase-testing.firebaseio.com', + projectId: 'react-native-firebase-testing', + storageBucket: 'react-native-firebase-testing.appspot.com', + messagingSenderId: '448618578101', + appId: '1:448618578101:web:0b650370bb29e29cac3efc', + measurementId: 'G-F79DJ0VFGS', + ); + +late FirebaseFunctions functions; + +Future main() async { + WidgetsFlutterBinding.ensureInitialized(); + await Firebase.initializeApp(options: firebaseOptions); + functions = FirebaseFunctions.instance + ..useFunctionsEmulator('localhost', 5001); + runApp(MyApp()); +} + +class MyApp extends StatefulWidget { + MyApp({Key? key}) : super(key: key); + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { + List fruit = []; + + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('Firebase Functions Example'), + ), + body: Center( + child: ListView.builder( + itemCount: fruit.length, + itemBuilder: (context, index) { + return ListTile( + title: Text('${fruit[index]}'), + ); + })), + floatingActionButton: Builder( + builder: (context) => FloatingActionButton.extended( + onPressed: () async { + // See index.js in the functions folder for the example function we + // are using for this example + final callable = functions.httpsCallable('listFruit', + options: HttpsCallableOptions( + timeout: const Duration(seconds: 5))); + + await callable().then((v) { + setState(() { + fruit.clear(); + // ignore: avoid_dynamic_calls + v.data.forEach((f) { + fruit.add(f); + }); + }); + }).catchError((e) { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text('ERROR: $e'), + )); + }); + }, + label: const Text('Call Function'), + icon: const Icon(Icons.cloud), + backgroundColor: Colors.deepOrange, + ), + ), + ), + ); + } +} diff --git a/packages/firebase_functions/example/pubspec.yaml b/packages/firebase_functions/example/pubspec.yaml new file mode 100644 index 000000000..b0a16e74f --- /dev/null +++ b/packages/firebase_functions/example/pubspec.yaml @@ -0,0 +1,21 @@ +name: firebase_functions_tizen_example +description: An example application demonstrating calls to Firebase Functions. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +version: 1.0.0 + +environment: + sdk: ">=2.12.0 <3.0.0" + +dependencies: + cloud_functions: + firebase_core: + firebase_core_tizen: + path: ../../firebase_core + firebase_functions_tizen: + path: ../ + flutter: + sdk: flutter + +flutter: + uses-material-design: true diff --git a/packages/firebase_functions/example/tizen/.gitignore b/packages/firebase_functions/example/tizen/.gitignore new file mode 100644 index 000000000..750f3af1b --- /dev/null +++ b/packages/firebase_functions/example/tizen/.gitignore @@ -0,0 +1,5 @@ +flutter/ +.vs/ +*.user +bin/ +obj/ diff --git a/packages/firebase_functions/example/tizen/App.cs b/packages/firebase_functions/example/tizen/App.cs new file mode 100644 index 000000000..6dd4a6356 --- /dev/null +++ b/packages/firebase_functions/example/tizen/App.cs @@ -0,0 +1,20 @@ +using Tizen.Flutter.Embedding; + +namespace Runner +{ + public class App : FlutterApplication + { + protected override void OnCreate() + { + base.OnCreate(); + + GeneratedPluginRegistrant.RegisterPlugins(this); + } + + static void Main(string[] args) + { + var app = new App(); + app.Run(args); + } + } +} diff --git a/packages/firebase_functions/example/tizen/Runner.csproj b/packages/firebase_functions/example/tizen/Runner.csproj new file mode 100644 index 000000000..f4e369d0c --- /dev/null +++ b/packages/firebase_functions/example/tizen/Runner.csproj @@ -0,0 +1,19 @@ + + + + Exe + tizen40 + + + + + + + + + + %(RecursiveDir) + + + + diff --git a/packages/firebase_functions/example/tizen/shared/res/ic_launcher.png b/packages/firebase_functions/example/tizen/shared/res/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..4d6372eebdb28e45604e46eeda8dd24651419bc0 GIT binary patch literal 1443 zcmb`G{WsKk6vsdJTdFg%tJav9_E4vzrOaqkWF|A724Nly!y+?N9`YV6wZ}5(X(D_N(?!*n3`|_r0Hc?=PQw&*vnU?QTFY zB_MsH|!j$PP;I}?dppoE_gA(4uc!jV&0!l7_;&p2^pxNo>PEcNJv za5_RT$o2Mf!<+r?&EbHH6nMoTsDOa;mN(wv8RNsHpG)`^ymG-S5By8=l9iVXzN_eG%Xg2@Xeq76tTZ*dGh~Lo9vl;Zfs+W#BydUw zCkZ$o1LqWQO$FC9aKlLl*7x9^0q%0}$OMlp@Kk_jHXOjofdePND+j!A{q!8~Jn+s3 z?~~w@4?egS02}8NuulUA=L~QQfm;MzCGd)XhiftT;+zFO&JVyp2mBww?;QByS_1w! zrQlx%{^cMj0|Bo1FjwY@Q8?Hx0cIPF*@-ZRFpPc#bBw{5@tD(5%sClzIfl8WU~V#u zm5Q;_F!wa$BSpqhN>W@2De?TKWR*!ujY;Yylk_X5#~V!L*Gw~;$%4Q8~Mad z@`-kG?yb$a9cHIApZDVZ^U6Xkp<*4rU82O7%}0jjHlK{id@?-wpN*fCHXyXh(bLt* zPc}H-x0e4E&nQ>y%B-(EL=9}RyC%MyX=upHuFhAk&MLbsF0LP-q`XnH78@fT+pKPW zu72MW`|?8ht^tz$iC}ZwLp4tB;Q49K!QCF3@!iB1qOI=?w z7In!}F~ij(18UYUjnbmC!qKhPo%24?8U1x{7o(+?^Zu0Hx81|FuS?bJ0jgBhEMzf< zCgUq7r2OCB(`XkKcN-TL>u5y#dD6D!)5W?`O5)V^>jb)P)GBdy%t$uUMpf$SNV31$ zb||OojAbvMP?T@$h_ZiFLFVHDmbyMhJF|-_)HX3%m=CDI+ID$0^C>kzxprBW)hw(v zr!Gmda);ICoQyhV_oP5+C%?jcG8v+D@9f?Dk*!BxY}dazmrT@64UrP3hlslANK)bq z$67n83eh}OeW&SV@HG95P|bjfqJ7gw$e+`Hxo!4cx`jdK1bJ>YDSpGKLPZ^1cv$ek zIB?0S<#tX?SJCLWdMd{-ME?$hc7A$zBOdIJ)4!KcAwb=VMov)nK;9z>x~rfT1>dS+ zZ6#`2v@`jgbqq)P22H)Tx2CpmM^o1$B+xT6`(v%5xJ(?j#>Q$+rx_R|7TzDZe{J6q zG1*EcU%tE?!kO%^M;3aM6JN*LAKUVb^xz8-Pxo#jR5(-KBeLJvA@-gxNHx0M-ZJLl z;#JwQoh~9V?`UVo#}{6ka@II>++D@%KqGpMdlQ}?9E*wFcf5(#XQnP$Dk5~%iX^>f z%$y;?M0BLp{O3a(-4A?ewryHrrD%cx#Q^%KY1H zNre$ve+vceSLZcNY4U(RBX&)oZn*Py()h)XkE?PL$!bNb{N5FVI2Y%LKEm%yvpyTP z(1P?z~7YxD~Rf<(a@_y` literal 0 HcmV?d00001 diff --git a/packages/firebase_functions/example/tizen/tizen-manifest.xml b/packages/firebase_functions/example/tizen/tizen-manifest.xml new file mode 100644 index 000000000..e2d219d93 --- /dev/null +++ b/packages/firebase_functions/example/tizen/tizen-manifest.xml @@ -0,0 +1,16 @@ + + + + + + ic_launcher.png + + + + T-INFOLINK2021-1000 + + + + http://tizen.org/privilege/internet + + diff --git a/packages/firebase_functions/lib/desktop_utils.dart b/packages/firebase_functions/lib/desktop_utils.dart new file mode 100644 index 000000000..babf0145c --- /dev/null +++ b/packages/firebase_functions/lib/desktop_utils.dart @@ -0,0 +1,23 @@ +// ignore_for_file: require_trailing_commas + +import 'package:cloud_functions/cloud_functions.dart'; +import 'package:firebase_core_dart/firebase_core_dart.dart' as core_dart; +import 'package:firebase_functions_dart/firebase_functions_dart.dart' + as functions_dart; + +/// Given a [FirebaseApp], a [core_dart.FirebaseApp] is returned. +core_dart.FirebaseApp app([String? name]) { + return name != null ? core_dart.Firebase.app(name) : core_dart.Firebase.app(); +} + +/// Given a dart error, a [FirebaseFunctionsException] is returned. +FirebaseFunctionsException convertFirebaseFunctionsException( + functions_dart.FirebaseFunctionsException exception, + [StackTrace? stackTrace]) { + return FirebaseFunctionsException( + code: exception.code, + message: exception.message!, + stackTrace: stackTrace, + details: exception.details, + ); +} diff --git a/packages/firebase_functions/lib/firebase_functions_tizen.dart b/packages/firebase_functions/lib/firebase_functions_tizen.dart new file mode 100644 index 000000000..380eb0e56 --- /dev/null +++ b/packages/firebase_functions/lib/firebase_functions_tizen.dart @@ -0,0 +1,112 @@ +// Copyright 2021 Invertase Limited. All rights reserved. +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file. + +library firebase_functions_tizen; + +import 'package:cloud_functions_platform_interface/cloud_functions_platform_interface.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_functions_dart/firebase_functions_dart.dart' + as functions_dart; + +import 'desktop_utils.dart' as desktop_utils; + +/// Desktop implementation of [FirebaseFunctionsPlatform] for managing FirebaseFunctions. +class FirebaseFunctionsDesktop extends FirebaseFunctionsPlatform { + /// Constructs a FirebaseFunctionsDesktop. + FirebaseFunctionsDesktop({ + required FirebaseApp? app, + String region = functions_dart.FirebaseFunctions.defaultRegion, + }) : super(app, region); + + FirebaseFunctionsDesktop._() + : _dartFunctions = null, + super(null, functions_dart.FirebaseFunctions.defaultRegion); + + /// Called by PluginRegistry to register this plugin as the implementation for Desktop. + static void registerWith() { + FirebaseFunctionsPlatform.instance = FirebaseFunctionsDesktop.instance; + } + + static void register() => registerWith(); + + /// Stub initializer to allow creating an instance without + /// registering delegates or listeners. + // ignore: prefer_constructors_over_static_methods + static FirebaseFunctionsDesktop get instance { + return FirebaseFunctionsDesktop._(); + } + + /// Instance of functions from the dart package. + functions_dart.FirebaseFunctions? _dartFunctions; + + /// Lazily initialize [_dartFunctions] on first method call. + functions_dart.FirebaseFunctions get _delegate { + return _dartFunctions ??= functions_dart.FirebaseFunctions.instanceFor( + app: desktop_utils.app(app?.name), + region: region, + ); + } + + @override + FirebaseFunctionsPlatform delegateFor({ + FirebaseApp? app, + required String region, + }) => + FirebaseFunctionsDesktop(app: app, region: region); + + @override + HttpsCallablePlatform httpsCallable( + String? origin, + String name, + HttpsCallableOptions options, + ) => + HttpsCallableDesktop(this, _delegate, origin, name, options); +} + +/// Desktop implementation of HttpsCallablePlatform for managing HttpsCallable +/// instances. +class HttpsCallableDesktop extends HttpsCallablePlatform { + /// Constructs a HttpsCallableDesktop + HttpsCallableDesktop( + FirebaseFunctionsDesktop functions, + this._delegate, + String? origin, + String name, + HttpsCallableOptions options, + ) : super(functions, origin, name, options); + + /// The dart functions instance for accessing the cloud functions API. + final functions_dart.FirebaseFunctions _delegate; + + @override + Future call([dynamic parameters]) async { + if (origin != null) { + _delegate.useFunctionsEmulator( + origin!.substring( + origin!.indexOf('://') + 3, + origin!.lastIndexOf(':'), + ), + int.parse( + origin!.substring(origin!.lastIndexOf(':') + 1), + ), + ); + } + + functions_dart.HttpsCallableResult response; + + try { + response = await _delegate + .httpsCallable( + name, + options: + functions_dart.HttpsCallableOptions(timeout: options.timeout), + ) + .call(parameters); + } on functions_dart.FirebaseFunctionsException catch (e, s) { + throw desktop_utils.convertFirebaseFunctionsException(e, s); + } + + return response.data; + } +} diff --git a/packages/firebase_functions/pubspec.yaml b/packages/firebase_functions/pubspec.yaml new file mode 100644 index 000000000..18b60d527 --- /dev/null +++ b/packages/firebase_functions/pubspec.yaml @@ -0,0 +1,28 @@ +name: firebase_functions_tizen +description: Firebase Functions for Tizen +version: 0.1.0 +homepage: https://github.com/flutter-tizen/plugins +repository: https://github.com/flutter-tizen/plugins/tree/master/packages/firebase_functions + +environment: + sdk: '>=2.18.0 <3.0.0' + flutter: ">=2.5.0" + +dependencies: + cloud_functions: ^3.3.1 + cloud_functions_platform_interface: ^5.1.10 + firebase_core: ^1.19.1 + firebase_core_dart: ^1.0.1 + firebase_functions_dart: ^0.1.1+2 + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.2 + +flutter: + plugin: + platforms: + tizen: + dartPluginClass: FirebaseFunctionsDesktop + +false_secrets: + - /example/lib/main.dart