1.0.7 • Published 13 days ago

firebase-functions-middleware v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
13 days ago

firebase functions middleware

functions v1 thin wrapper for append middlewares

how to use

import {
    Functions,
    parameterLogger,
    timeoutLogger,
    idempotenceGuarantor
} from 'firebase-functions-middleware'
import { getFirestore, initializeFirestore } from 'firebase-admin/firestore';
import { getApps, initializeApp } from 'firebase-admin/app';

if (getApps().length === 0) {
    const firebase = initializeApp();
    initializeFirestore(firebase);
}

const app = new Functions()
app.use(parameterLogger())
app.use(idempotenceGuarantor(getFirestore))
app.use(timeoutLogger())
app.use(({ functionType, options, parameters, next }) => {
    switch (functionType) {
        case 'https.onCall': {
            const [data, context] = parameters;
            // ...
            return next(data, context);
        }
        default:
            return next(...parameters);
    }
});
app.useDeployment(({ options }) => ({
    // for reduce cold start latency
    memory: '1GB',
    ...options,
}));

export const functions = app.builder
import { functions } from '../functions'

export const helloWorld = functions().https.onCall(() => {
    return "Hello world!"
})

parameterLogger

Logging data, contexts and response.

Note:

  • Some data will be filtered
  • Sensitive data may be displayed
functions.use(parameterLogger({
    target: {
        data: true,
        contexts: true,
        response: true
    },
    level: "DEBUG"
}))

idempotenceGuarantor

For functions running at least once, use firestore to achieve exactly once.

functions.use(idempotenceGuarantor({
    firestoreCollectionName: "events" // default
}))

timeoutLogger

Report an error before timeout.

functions.use(timeoutLogger({
    timing: (timeout) => timeout * 0.9 // default
}))
1.0.7

13 days ago

1.0.6

3 months ago

1.0.5

9 months ago

1.0.4

11 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago