パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.1.0

firebase_admin_interop

公式のNode.js SDKをラップして作られたDart用Firebase Admin SDK。

30日間ダウンロード
134
いいね数
25
Pub ポイント
40

パッケージをインストール

flutter pub add firebase_admin_interop

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Dart用のFirebase Admin SDKは、公式Node.js SDKをラッパーとして実装されています。このパッケージは、Interopを通じてネイティブなNode.js機能を利用することで、Dart環境でのサーバーサイドFirebase操作を可能にします。認証、Firestore、メッセージングなどのFirebaseリソースへの管理アクセスが必要なバックエンドサービス、クラウドファンクション、サーバーアプリケーションに最適です。Node.jsでFirebase Adminに慣れている開発者には、馴染みのあるAPIを提供します。

用途

  • サーバーサイド Firebase 管理
  • Dart を使用したクラウド関数
  • バックエンドサービスの統合
  • 認証管理
  • Firestore データ操作

主な機能

  • Node.js SDKラッパー
  • 管理者レベルのFirebaseアクセス
  • Dart互換インターフェース
  • 既存のFirebaseワークフローとのシームレスな統合
  • 複数のFirebaseサービスをサポートしています

適している対象

  • Dart を使用するバックエンド開発者
  • Firebase 管理者アクセスを必要とするサーバーアプリケーション
  • クラウド関数環境
  • Firebase認証制御が必要なプロジェクト
  • Node.js での Firebase Admin に精通したチーム

注意事項

  • Node.js ランタイム環境が必要です
  • サーバーサイドでの利用に限定
  • Flutterモバイルアプリには適していません
  • 外部の Node.js プロセスに依存しています
  • プラットフォーム固有の設定要件がある可能性があります

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Build Status

Write server-side Firebase applications in Dart using Node.js as a runtime.

Firestore Timestamps migration:

Firestore deprecated usage of DateTime objects in favor of custom Timestamp type and recommends migrating as soon as possible. By default all timestamps are still returned as DateTime objects and you can access them with DocumentData.getDateTime or DocumentData.setDateTime. To start using Timestamps you must configure Firestore as follows:

final app = FirebaseAdmin.instance.initializeApp();
final firestore = app.firestore();
// Call Firestore.settings at the very beginning before any other calls:
firestore.settings(FirestoreSettings(timestampsInSnapshots: true));
// You can read and write data now, but make sure to use new `setTimestamp` and `getTimestamp`
// methods of `DocumentData`.

Installation

  1. Add this package as a dependency to your pubspec.yaml:
dependencies:
  firebase_admin_interop: [latest_version]

Run pub get.

  1. Create package.json file to install Node.js modules used by this library:
{
  "dependencies": {
    "firebase-admin": "8.5.0",
    "@google-cloud/firestore": "2.0.0"
  }
}

Run npm install.

Usage

Below is a simple example of using Realtime Database client:

import 'dart:async';
import 'package:firebase_admin_interop/firebase_admin_interop.dart';

Future<void> main() async {
  final serviceAccountKeyFilename = '/absolute/path/to/service-account.json';
  final admin = FirebaseAdmin.instance;
  final cert = admin.certFromPath(serviceAccountKeyFilename);
  final app = admin.initializeApp(new AppOptions(
    credential: cert,
    databaseURL: "YOUR_DB_URL",
  ));
  final ref = app.database().ref('/test-path');
  // Write value to the database at "/test-path" location.
  await ref.setValue("Hello world");
  // Read value from the same database location.
  var snapshot = await ref.once("value");
  print(snapshot.val()); // prints "Hello world".
}

Note that it is only possible to use JSON-compatible values when reading and writing data to the Realtime Database. This includes all primitive types (int, double, bool), string values (String) as well as any List or Map instance.

For Firestore there are a few more supported data types, like DateTime and GeoPoint.

Building

This library depends on node_interop package which provides Node.js bindings and build_node_compilers package which allows compiling Dart applications as Node.js modules.

To enable builders provided by build_node_compilers first add following dev dependencies to your pubspec.yaml:

dev_dependencies:
  build_runner: ^1.0.0
  build_node_compilers: ^0.2.0

Next, create build.yaml file with following contents:

targets:
  $default:
    sources:
      - "lib/**"
      - "node/**" # Assuming your main Dart files is in node/ folder (recommended).
      - "test/**"
    builders:
      build_node_compilers|entrypoint:
        options:
          compiler: dart2js # To compile with dart2js by default

You can now build your project using build_runner:

# By default compiles with DDC
pub run build_runner build --output=build

# To compile with dart2js:
pub run build_runner build \
  --define="build_node_compilers|entrypoint=compiler=dart2js" \
  --define="build_node_compilers|entrypoint=dart2js_args=[\"--minify\"]" \ # optional, minifies resulting code
  --output=build/

Status

This library is considered stable though not feature complete. It is recommended to check dev versions for latest updates and bug fixes.

Make sure to checkout CHANGELOG.md after every release, all notable changes and upgrade instructions will be described there.

Current implementation coverage report:

  • [x] admin
  • [x] admin.auth
  • [x] admin.app
  • [x] admin.credential
  • [x] admin.database
  • [x] admin.firestore
  • [x] admin.messaging
  • [ ] admin.storage

Features and bugs

Please file feature requests and bugs at the issue tracker.

カテゴリー

依存関係

依存関係一覧 4 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。