|
1 |
| -# Image Processing API Utilities |
| 1 | +# Firestore Record Acknowledgements Utilities |
2 | 2 |
|
3 |
| -This package contains utilities for interacting with the Firebase Image Processing API Extension. |
| 3 | +# Utilty Library |
| 4 | + |
| 5 | +To assist with the usage of this Extension, a [utility library](https://www.npmjs.com/package/@invertase/firestore-record-acknowledgements) exists |
| 6 | +to help provide a typed API interface for easily constructing operations to send to the API. |
4 | 7 |
|
5 | 8 | ## Installation
|
6 | 9 |
|
7 | 10 | ```bash
|
8 |
| -npm i --save @invertase/image-processing-api |
| 11 | +npm i --save @invertase/firestore-record-acknowledgements |
9 | 12 | ```
|
10 | 13 |
|
| 14 | +> To use this library, you must also have the [`firebase`](https://www.npmjs.com/package/firebase) package installed and initialized before any usage. |
| 15 | +
|
11 | 16 | ## Usage
|
12 | 17 |
|
13 |
| -### `builder` |
| 18 | +The library exports a number of functions to assist sending the correct payloads to the correct extension endpoints, with fully typed responses. |
| 19 | +The user should be authenticated via the `firebase/auth` package before using any of the functions. |
| 20 | + |
| 21 | +```ts |
| 22 | +import { getNotice, acknowledgeNotice, unacknowledgeNotice, getAcknowledgments } from '@invertase/firestore-record-acknowledgements'; |
| 23 | + |
| 24 | +// ... |
| 25 | + |
| 26 | +// Get a notice by ID (and optional version). |
| 27 | +const notice = await getNotice({ type: 'banner', version: 2 }); |
| 28 | + |
| 29 | +// Acknowledge a notice by ID. |
| 30 | +await acknowledgeNotice({ noticeId: '...', metadata: { ... } }); |
14 | 31 |
|
15 |
| -Returns a `ImageProcessingApi` instance which can be used to build an array of operations to be applied to an image via the extension. |
| 32 | +// Unacknowledge a notice by ID. |
| 33 | +await unacknowledgeNotice({ noticeId: '...', metadata: { ... } }); |
| 34 | + |
| 35 | +// Get all acknowledgements for current user. |
| 36 | +const acknowledgements = await getAcknowledgments({ includeUnacknowledgments: true }); |
| 37 | +``` |
| 38 | + |
| 39 | +## Custom Functions Instance |
| 40 | + |
| 41 | +If you need to provide a custom functions instance, you can provide an instance to the `functions` argument. This |
| 42 | +is useful if you wish to use a secondary app instance or change the region of the functions instance. |
16 | 43 |
|
17 | 44 | ```ts
|
18 |
| -import { builder } from '@invertase/image-processing-api'; |
19 |
| - |
20 |
| -const output = builder() |
21 |
| - // Input required |
22 |
| - .input({ |
23 |
| - source: 'https://example.com/image.jpg', |
24 |
| - }) |
25 |
| - .flip() |
26 |
| - .grayscale() |
27 |
| - .rotate({ angle: 90 }) |
28 |
| - // Output required |
29 |
| - .output({ |
30 |
| - format: 'png', |
31 |
| - }); |
| 45 | +import { initializeApp } from 'firebase/app'; |
| 46 | +import { getFunctions } from 'firebase/functions'; |
| 47 | + |
| 48 | +const app = initializeApp({ ... }); |
| 49 | +const functions = getFunctions(app, 'europe-west1'); |
| 50 | + |
| 51 | +// Use the custom functions instance. |
| 52 | +const notice = await getNotice({ functions, type: 'banner' }); |
32 | 53 | ```
|
33 | 54 |
|
34 |
| -Once created, the api provides the means to return the operations as JSON, a JSON string or an encoded JSON string suitable for GET requests in your browser. |
| 55 | +## Multiple Extension Instances |
| 56 | + |
| 57 | +If you have multiple instances of the extension installed, you can provide the `extensionId` argument to the functions: |
35 | 58 |
|
36 | 59 | ```ts
|
37 |
| -const json = output.toJSON(); |
38 |
| -const jsonString = output.toJSONString(); |
39 |
| -const encodedJsonString = output.toEncodedJSONString(); |
| 60 | +// Makes a request to the uniuque deployed extension. |
| 61 | +const notice = await getNotice({ extensionId: '1234', type: 'banner' }); |
40 | 62 | ```
|
0 commit comments