Utility Library
To assist with the usage of this Extension, a utility library exists to help provide a typed API interface for easily constructing operations to send to the API.
Installation
npm i --save @invertase/firestore-record-acknowledgements
To use this library, you must also have the
firebase
package installed and initialized before any usage.
Usage
The library exports a number of functions to assist sending the correct payloads to the correct extension endpoints, with fully typed responses.
The user should be authenticated via the firebase/auth
package before using any of the functions.
import { getNotice, acknowledgeNotice, unacknowledgeNotice, getAcknowledgments } from '@invertase/firestore-record-acknowledgements';
// ...
// Get a notice by ID (and optional version).
const notice = await getNotice({ type: 'banner', version: 2 });
// Acknowledge a notice by ID.
await acknowledgeNotice({ noticeId: '...', metadata: { ... } });
// Unacknowledge a notice by ID.
await unacknowledgeNotice({ noticeId: '...', metadata: { ... } });
// Get all acknowledgements for current user.
const acknowledgements = await getAcknowledgments({ includeUnacknowledgments: true });
Custom Functions Instance
If you need to provide a custom functions instance, you can provide an instance to the functions
argument. This
is useful if you wish to use a secondary app instance or change the region of the functions instance.
import { initializeApp } from 'firebase/app';
import { getFunctions } from 'firebase/functions';
const app = initializeApp({ ... });
const functions = getFunctions(app, 'europe-west1');
// Use the custom functions instance.
const notice = await getNotice({ functions, type: 'banner' });