npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nativescript/firebase-functions

v3.3.2

Published

NativeScript Firebase - Functions

Downloads

346

Readme

@nativescript/firebase-functions

Contents

Intro

This plugin allows you to use Firebase Cloud Functions with NativeScript.

image

Set up your app for Firebase

  • To set up and initialize Firebase for your NativeScript app, follow the instructions on the documentation of the @nativescript/firebase-core plugin.

Add the Firebase Functions SDK to your app

To add the Cloud Firebase Functions SDK to your app, install the @nativescript/firebase-functions plugin by running the following command in the root directory of your project.

npm install @nativescript/firebase-functions

Use @nativescript/firebase-functions

The Cloud Functions module provides the functionality to directly trigger deployed HTTPS callable functions, without worrying about security or implementing an HTTP request library.

Functions deployed to Firebase have unique names, allowing you to easily identify which endpoint you wish to send a request to.

Calling an endpoint

Assuming we have to deploy a callable endpoint named listProducts. To call the endpoint, the library exposes a httpsCallable method. For example:

// Deployed HTTPS callable
exports.listProducts = functions.https.onCall(() => {
	return [
		/* ... */
		// Return some data
	];
});

Within the application, the list of products returned can be directly accessed by passing the name of the endpoint to the httpsCallable method:

import { firebase } from '@nativescript/firebase-core';
import '@nativescript/firebase-functions';
firebase()
	.functions()
	.httpsCallable('listProducts')()
	.then((response) => {
		setProducts(response.data);
		setLoading(false);
	});

Set and access regional Cloud Functions endpoints

Cloud Functions are regional, which means the infrastructure that runs your Cloud Function is located in specific regions.

By default, functions run in the us-central1 region. To see supported regions, see supported regions.

Set regional function endpoint

To run functions in a different region after initializing Firebase App, set the region using firebase().app().functions(region).

The code below shows an example of setting a regional function endpoint(europe-west2):

// Deployed HTTPS callable
exports.listProducts = functions.region("europe-west2").https.onCall(() => {
	return [
		/* ... */
		// Return some data
	];
});

Access regional function endpoint

To access a regional function endpoint, call the firebase().app().functions(region) method on the Firebase App instance:

import { firebase } from '@nativescript/firebase-core';
import '@nativescript/firebase-functions';

firebase().initializeApp();
firebase().app().functions("europe-west2");

firebase()
	.functions()
	.httpsCallable('listProducts')()
	.then((response) => {
		setProducts(response.data);
		setLoading(false);
	});

Test Cloud Functions with a local emulator

Whilst developing your application with Cloud Functions, you can run the functions inside of a local emulator.

To call the emulated functions, connect the Cloud Functions to a local emulator by calling the useEmulator method on the Functions instance with the host and port of the emulator.

import { firebase } from '@nativescript/firebase-core';
firebase().functions().useEmulator('localhost', 5000);

API

Functions class

ios

functionsIOs: FIRFunctions = firebase.functions().ios;

A readonly property that returns the native iOS FIRFunctions instance.


android

functionsAndroid: com.google.firebase.functions.FirebaseFunctions = firebase.functions().android;

A readonly property that returns the native Android com.google.firebase.functions.FirebaseFunctions instance.


app

app: FirebaseApp = firebase().functions().app;

A readonly property that returns the FirebaseApp instance associated with the Functions instance.


constructor()

functions: Functions = new Functions(app);

Creates a new Functions instance.

| Parameter | Type | Description | | --- | --- | --- | | app | FirebaseApp | An optional FirebaseApp instance to use. |


httpsCallable()

task: HttpsCallable = firebase().functions().httpsCallable(name, options);

httpsCallable(data).then((response: HttpsCallableResult) => {
	// Do something with the response
}).catch((error: HttpsCallableError) => {
	console.log(error.code, error.message, error.details);

});

Returns a task function that can be called with optional data. The task function returns a Promise that will be resolved with the result(HttpsCallableResult) of the function execution. If the task fails, the Promise will be rejected with an HttpsCallableError.

| Parameter | Type | Description | | --- | --- | --- | | name | string | The name of the reference to the Callable HTTPS trigger. | | options | HttpsCallableOptions | An optional object that sets the length of timeout, in seconds, for calls for this Functions instance. |


useEmulator()

firebase().functions().useEmulator(host, port);

Allows you to test Cloud Functions locally by connecting to the emulator.

| Parameter | Type | Description | | --- | --- | --- | | host | string | The host of the emulator to connect to. | | port | number | The port of the emulator to connect to. |


License

Apache License Version 2.0