Skip to content

Commit 62dc91b

Browse files
Ehespdackers86
andauthored
feat: migrate record-user-acknowledgements
Co-authored-by: dackers86 <[email protected]>
1 parent 00d85a7 commit 62dc91b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+18862
-4
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ build
33
**/functions/lib/**/*.js
44
**/extensions/image-processing-api/lib/src/types/**/*.ts
55
package-lock.json
6+
**/public/build/**

dictionary.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ module.exports = [
5959
/^firebase/,
6060
/^href/,
6161
/^stringified/,
62+
/^acknowledgement/,
63+
/^acknowledgements/,
64+
/^unacknowledge/,
6265
];

docs.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
["Types", "/image-processing-api/types"],
1515
["Utility Library", "/image-processing-api/utility-library"]
1616
]
17+
],
18+
[
19+
"Record User Acknowledgements",
20+
[
21+
["Overview", "/record-user-acknowledgements"],
22+
["Refernce API", "/record-user-acknowledgements/reference"]
23+
]
1724
]
1825
]
1926
}

docs/index.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<h2 align="center">Invertase Firebase Extensions</h2>
77
</p>
88

9-
| Name | Description |
10-
| --------------------------------------------- | :-------------------------------------------------------------: |
11-
| [Image Processing Api](/image-processing-api) | Firebase deployed function for processing and rendering images. |
9+
| Name | Description |
10+
| ------------------------------------------------------------- | :----------------------------------------------------------------------------: |
11+
| [Image Processing Api](/image-processing-api) | Firebase deployed function for processing and rendering images. |
12+
| [Record User Acknowledgements](/record-user-acknowledgements) | Provides an out of the box acknowledgement management extension for Firestore. |
112 KB
Loading
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Record User Acknowledgements
2+
3+
The extension stores notices and acknowledgements as documents in a collection inside Firestore. You configure the collection during the installation process, when you set up the extension instance's configuration parameters.
4+
5+
The extensions' source code contains a [web app providing admin utilities](https://github.com/invertase/firebase-extensions/tree/main/extensions/firestore-record-user-acknowledgements/admin-dashboard) that you can run locally. This contains a notice builder UI that you can use to easily create and customize notices. Setup instructions are available in the above link provided. Once set up, navigate to [localhost:3000](http://localhost:3000) to see the notice builder tool.
6+
7+
![Admin Dashboard](/record-user-acknowldegements/assets/admin-dashboard-example.png)
8+
9+
## Retrieving a notice
10+
11+
After creating a notice, you can use the following snippet in your web/mobile app to get the notice you want to show to your users, using the notice `type`:
12+
13+
```js
14+
import { getFunctions, httpsCallable } from 'firebase/functions';
15+
16+
const functions = getFunctions();
17+
const notice = await httpsCallable(
18+
functions,
19+
'ext-firestore-record-user-acknowledgements-getNotice',
20+
)({
21+
type: 'banner',
22+
});
23+
```
24+
25+
Note: if multiple instances of this extension are installed the callable function name might contain a unique identifier, e.g. `ext-firestore-record-user-acknowledgements-<id>-getNotice`.
26+
27+
The response of the function call will contain the notice document data, along with whether the current authenticated user has acknowledged the notice.
28+
29+
To retrieve a notice by a specific version, provide the `version` parameter:
30+
31+
```js
32+
import { getFunctions, httpsCallable } from 'firebase/functions';
33+
34+
const functions = getFunctions();
35+
const notice = await httpsCallable(
36+
functions,
37+
'ext-firestore-record-user-acknowledgements-getNotice',
38+
)({
39+
type: 'banner',
40+
version: 2,
41+
});
42+
```
43+
44+
View the [reference API](/record-user-acknowldegements/reference) for full details on the response interface.
45+
46+
## Acknowledging a notice
47+
48+
To acknowledge a notice, the extension provides two callable functions which accept the notice ID: `acknowledgeNotice` & `unacknowledgeNotice`. The extension will keep historical records of each acknowledgement the callable functions are called multiple times for the same user and notice.
49+
50+
For example, to acknowledge a notice:
51+
52+
```js
53+
import { getFunctions, httpsCallable } from "firebase/functions";
54+
55+
const functions = getFunctions();
56+
await httpsCallable(functions, 'ext-firestore-record-user-acknowledgements-acknowledgeNotice)({
57+
noticeId: 'EA9QhZKKta9KXcckiasc',
58+
});
59+
```
60+
61+
In-case you need to capture custom preferences relating to an acknowledgement, you can provide custom metadata to the function, for example:
62+
63+
```js
64+
await httpsCallable(functions, 'ext-firestore-record-user-acknowledgements-acknowledgeNotice)({
65+
noticeId: 'EA9QhZKKta9KXcckiasc',
66+
metadata: { preference1: true, preference2: false },
67+
});
68+
```
69+
70+
You can also provide a custom “type” of acknowledgement (the default type is “seen”), for example:
71+
72+
```js
73+
await httpsCallable(functions, 'ext-firestore-record-user-acknowledgements-acknowledgeNotice)({
74+
noticeId: 'EA9QhZKKta9KXcckiasc',
75+
type: 'seen',
76+
});
77+
```
78+
79+
If you wish to unacknowledge a notice, call the `unacknowledgeNotice` function:
80+
81+
```js
82+
await httpsCallable(functions, 'ext-firestore-record-user-acknowledgements-unacknowledgeNotice)({
83+
noticeId: 'EA9QhZKKta9KXcckiasc',
84+
metadata: { reason: '...' },
85+
});
86+
```
87+
88+
## Retrieving acknowledgements
89+
90+
To retrieve all previous user notice acknowledgements, call the `getAcknowledgements` callable function. This function will return an ordered array of all acknowledgements along with the notice data:
91+
92+
```js
93+
import { getFunctions, httpsCallable } from "firebase/functions";
94+
95+
const functions = getFunctions();
96+
const acknowledgements = await httpsCallable(functions, 'ext-firestore-record-user-acknowledgements-getAcknowledgements)();
97+
```
98+
99+
By default this won’t include unacknowledgement documents, however if those are required you can provide a `includeUnacknowledgements` property to the call:
100+
101+
```js
102+
import { getFunctions, httpsCallable } from "firebase/functions";
103+
104+
const functions = getFunctions();
105+
const acknowledgements = await httpsCallable(functions, 'ext-firestore-record-user-acknowledgements-getAcknowledgements)({
106+
includeUnacknowledgements: true,
107+
});
108+
```
109+
110+
## User specific acknowledgements
111+
112+
You may need to create custom notices that are shown to and can only be acknowledged by a specific subset of users. To accomplish this, specify an `allowList` array of UIDs to the notice document. If the user requesting a notice by type is not within the list of UIDs, a `not-found` error will be returned.
113+
114+
## Updating a notice
115+
116+
When it's time to update a notice, for example when additional user preferences are required, create a new notice document with the same `type` as the existing notice you wish to update.
117+
118+
When the notice is retrieved, a new notice document will be returned with no user acknowledgement, allowing users to acknowledge the newer notice.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# API Reference
2+
3+
Below contains an overview of the specifications for the Record User Acknowledgements extension, including TypeScript definitions & detailed descriptions.
4+
5+
## `NoticeDocument` Interface
6+
7+
The specification for a single document within the configured collection:
8+
9+
```ts
10+
export interface NoticeDocument {
11+
// The document ID.
12+
id: string;
13+
// The type of notice, e.g. `banner` | `terms-and-condition` | `privacy-policy`.
14+
type: string;
15+
// An optional notice version. This can be used to filter a specific notice versions via the `getNotice` callable function.
16+
version?: number;
17+
// The optional title of the notice.
18+
title?: string;
19+
// The optional description of the notice.
20+
description?: string;
21+
// The optional link of the notice.
22+
link?: string;
23+
// The timestamp when the notice was created.
24+
createdAt: Timestamp;
25+
// A list of user IDs that are allowed to see the notice.
26+
allowList: string[];
27+
}
28+
```
29+
30+
## `AcknowledgementDocument` Interface
31+
32+
The specification for a single document within a notice sub-collection:
33+
34+
```ts
35+
type BaseAcknowledgement = {
36+
// The document ID.
37+
id: string;
38+
// The UID of the user who acknowledged the notice.
39+
userId: string;
40+
// The ID of the notice that was acknowledged.
41+
noticeId: string;
42+
// The timestamp when the notice was acknowledged.
43+
createdAt: Timestamp;
44+
// The optional metadata of the acknowledgement.
45+
metadata: any;
46+
};
47+
48+
export type AcknowledgementDocument =
49+
| (BaseAcknowledgement & {
50+
// The type of the acknowledgement.
51+
ackEvent: 'acknowledged';
52+
// The type of the acknowledgement. Defaults to `seen`.
53+
type: string;
54+
})
55+
| (BaseAcknowledgement & {
56+
// The type of the acknowledgement.
57+
ackEvent: 'unacknowledged';
58+
});
59+
```
60+
61+
## `GetNoticeRequest` Interface
62+
63+
The response interface provided to a `getNotice` callable function:
64+
65+
```ts
66+
export interface GetNoticeRequest {
67+
// The `type` of the notice to get.
68+
type: string;
69+
// If provided, the specific version of this notice (if exists) will be returned.
70+
version?: number;
71+
}
72+
```
73+
74+
## `GetNoticeResponse` Interface
75+
76+
The result interface returned from a `getNotice` callable function:
77+
78+
```ts
79+
export type GetNoticeResponse = Omit<NoticeDocument, ‘allowList’> & {
80+
// The timestamp when the notice was unacknowledged by the user (undefined if the user has not unacknowledged this notice).
81+
unacknowledgedAt?: Timestamp;
82+
83+
// An ordered array of user acknowledgements.
84+
acknowledgements: AcknowledgementDocument[];
85+
}
86+
```
87+
88+
## `AcknowledgeNoticeRequest` Interface
89+
90+
The response interface provided to a `acknowledgeNotice` callable function:
91+
92+
```ts
93+
export interface AcknowledgeNoticeRequest {
94+
// The notice ID to acknowledge.
95+
noticeId: string;
96+
// A custom type to provide as the acknowledgement. Defaults to `seen`.
97+
type?: string;
98+
// Optional preference metadata to store with this acknowledgement.
99+
metadata?: any;
100+
}
101+
```
102+
103+
## `UnacknowledgeNoticeRequest` Interface
104+
105+
The response interface provided to a `unacknowledgeNotice` callable function:
106+
107+
```ts
108+
export interface UnacknowledgeNoticeRequest {
109+
// The notice ID to unacknowledge.
110+
noticeId: string;
111+
// Optional preference metadata to store with this unacknowledgement.
112+
metadata?: any;
113+
}
114+
```
115+
116+
## `GetAcknowledgementsRequest` Interface
117+
118+
The response interface provided to a `getAcknowledgements` callable function:
119+
120+
```ts
121+
export interface GetAcknowledgementsRequest {
122+
// If true, include unacknowledgement documents.
123+
includeUnacknowledgements?: boolean;
124+
}
125+
```
126+
127+
## `GetAcknowledgementsResponse` Interface
128+
129+
The response interface provided to a `getAcknowledgements` callable function:
130+
131+
```ts
132+
export type GetAcknowledgementsResponse = (AcknowledgementDocument & {
133+
// The notice of this acknowledgement, excluding the allowList.
134+
notice: Omit<NoticeDocument, ‘allowList’>;
135+
})[];
136+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Version 0.1.0
2+
3+
Stable release with documentation.

0 commit comments

Comments
 (0)