@progressive-development/pd-provider-firebase-functions 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth-trash.d.ts +51 -0
- package/dist/auth-trash.d.ts.map +1 -0
- package/dist/auth-trash.js +66 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/trash.d.ts +77 -0
- package/dist/trash.d.ts.map +1 -0
- package/dist/trash.js +80 -0
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { TrashItem } from './trash';
|
|
2
|
+
export interface AuthTrashOptions {
|
|
3
|
+
/**
|
|
4
|
+
* How to determine the Auth UID from the document.
|
|
5
|
+
* - 'documentId': Use the document ID as Auth UID (default)
|
|
6
|
+
* - string: Use this field name from the document data
|
|
7
|
+
*/
|
|
8
|
+
authUidSource?: "documentId" | string;
|
|
9
|
+
/** Optional named database */
|
|
10
|
+
databaseId?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Move document to trash AND disable the associated Auth user.
|
|
14
|
+
*
|
|
15
|
+
* Order of operations:
|
|
16
|
+
* 1. Disable Auth user (if this fails, nothing else happens)
|
|
17
|
+
* 2. Move document to trash
|
|
18
|
+
*
|
|
19
|
+
* @param collection - The collection path
|
|
20
|
+
* @param documentId - The document ID to trash
|
|
21
|
+
* @param deletedBy - UID of the user performing the deletion
|
|
22
|
+
* @param objectType - Type identifier for filtering
|
|
23
|
+
* @param options - Auth and database options
|
|
24
|
+
* @returns The created trash item
|
|
25
|
+
*/
|
|
26
|
+
export declare function moveToTrashWithAuth<T = unknown>(collection: string, documentId: string, deletedBy: string, objectType: string, options?: AuthTrashOptions): Promise<TrashItem<T>>;
|
|
27
|
+
/**
|
|
28
|
+
* Restore document from trash AND re-enable the Auth user.
|
|
29
|
+
*
|
|
30
|
+
* Order of operations:
|
|
31
|
+
* 1. Get trash item to find Auth UID
|
|
32
|
+
* 2. Restore document from trash
|
|
33
|
+
* 3. Re-enable Auth user
|
|
34
|
+
*
|
|
35
|
+
* @param trashItemId - The trash document ID
|
|
36
|
+
* @param options - Auth and database options
|
|
37
|
+
*/
|
|
38
|
+
export declare function restoreFromTrashWithAuth(trashItemId: string, options?: AuthTrashOptions): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Permanently delete from trash AND delete the Auth user.
|
|
41
|
+
*
|
|
42
|
+
* Order of operations:
|
|
43
|
+
* 1. Get trash item to find Auth UID
|
|
44
|
+
* 2. Delete from trash
|
|
45
|
+
* 3. Delete Auth user
|
|
46
|
+
*
|
|
47
|
+
* @param trashItemId - The trash document ID
|
|
48
|
+
* @param options - Auth and database options
|
|
49
|
+
*/
|
|
50
|
+
export declare function permanentDeleteWithAuth(trashItemId: string, options?: AuthTrashOptions): Promise<void>;
|
|
51
|
+
//# sourceMappingURL=auth-trash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-trash.d.ts","sourceRoot":"","sources":["../src/auth-trash.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAgE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAQvG,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,aAAa,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IAEtC,8BAA8B;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAkCD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,GAAG,OAAO,EACnD,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CA0BvB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,IAAI,CAAC,CAsBf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,IAAI,CAAC,CAqBf"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { getAuth } from 'firebase-admin/auth';
|
|
2
|
+
import { moveToTrash, getTrashItem, restoreFromTrash, permanentDelete } from './trash.js';
|
|
3
|
+
import { NotFoundError } from './errors.js';
|
|
4
|
+
import { logger } from './logger.js';
|
|
5
|
+
|
|
6
|
+
function getAuthUidFromTrashItem(trashItem, options) {
|
|
7
|
+
const source = options?.authUidSource ?? "documentId";
|
|
8
|
+
if (source === "documentId") {
|
|
9
|
+
return trashItem.originalId;
|
|
10
|
+
}
|
|
11
|
+
const data = trashItem.data;
|
|
12
|
+
const uid = data[source];
|
|
13
|
+
if (typeof uid !== "string" || !uid) {
|
|
14
|
+
throw new Error(`Auth UID field '${source}' not found or empty in trash item data`);
|
|
15
|
+
}
|
|
16
|
+
return uid;
|
|
17
|
+
}
|
|
18
|
+
async function moveToTrashWithAuth(collection, documentId, deletedBy, objectType, options) {
|
|
19
|
+
const authUid = options?.authUidSource === "documentId" || !options?.authUidSource ? documentId : documentId;
|
|
20
|
+
logger.info("Disabling Auth user before trash", { authUid, collection, documentId });
|
|
21
|
+
await getAuth().updateUser(authUid, { disabled: true });
|
|
22
|
+
logger.info("Auth user disabled", { authUid });
|
|
23
|
+
const trashItem = await moveToTrash(
|
|
24
|
+
collection,
|
|
25
|
+
documentId,
|
|
26
|
+
deletedBy,
|
|
27
|
+
objectType,
|
|
28
|
+
options?.databaseId
|
|
29
|
+
);
|
|
30
|
+
logger.info("Document moved to trash with Auth disabled", {
|
|
31
|
+
trashItemId: trashItem.id,
|
|
32
|
+
authUid
|
|
33
|
+
});
|
|
34
|
+
return trashItem;
|
|
35
|
+
}
|
|
36
|
+
async function restoreFromTrashWithAuth(trashItemId, options) {
|
|
37
|
+
const trashItem = await getTrashItem(trashItemId, options?.databaseId);
|
|
38
|
+
if (!trashItem) {
|
|
39
|
+
throw new NotFoundError(`Trash item ${trashItemId} not found`);
|
|
40
|
+
}
|
|
41
|
+
const authUid = getAuthUidFromTrashItem(trashItem, options);
|
|
42
|
+
logger.info("Restoring from trash with Auth re-enable", {
|
|
43
|
+
trashItemId,
|
|
44
|
+
authUid,
|
|
45
|
+
originalCollection: trashItem.originalCollection
|
|
46
|
+
});
|
|
47
|
+
await restoreFromTrash(trashItemId, options?.databaseId);
|
|
48
|
+
await getAuth().updateUser(authUid, { disabled: false });
|
|
49
|
+
logger.info("Document restored and Auth user re-enabled", { trashItemId, authUid });
|
|
50
|
+
}
|
|
51
|
+
async function permanentDeleteWithAuth(trashItemId, options) {
|
|
52
|
+
const trashItem = await getTrashItem(trashItemId, options?.databaseId);
|
|
53
|
+
if (!trashItem) {
|
|
54
|
+
throw new NotFoundError(`Trash item ${trashItemId} not found`);
|
|
55
|
+
}
|
|
56
|
+
const authUid = getAuthUidFromTrashItem(trashItem, options);
|
|
57
|
+
logger.info("Permanently deleting with Auth user deletion", {
|
|
58
|
+
trashItemId,
|
|
59
|
+
authUid
|
|
60
|
+
});
|
|
61
|
+
await permanentDelete(trashItemId, options?.databaseId);
|
|
62
|
+
await getAuth().deleteUser(authUid);
|
|
63
|
+
logger.info("Trash item and Auth user permanently deleted", { trashItemId, authUid });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { moveToTrashWithAuth, permanentDeleteWithAuth, restoreFromTrashWithAuth };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,9 @@ export { requireAuth, requireClaims, requireOwnership } from './auth';
|
|
|
5
5
|
export { success, created, handleError } from './response';
|
|
6
6
|
export { getDb } from './firestore';
|
|
7
7
|
export { getNextCounter } from './counter';
|
|
8
|
+
export type { TrashItem } from './trash';
|
|
9
|
+
export { moveToTrash, restoreFromTrash, permanentDelete, listTrash, getTrashItem } from './trash';
|
|
10
|
+
export type { AuthTrashOptions } from './auth-trash';
|
|
11
|
+
export { moveToTrashWithAuth, restoreFromTrashWithAuth, permanentDeleteWithAuth } from './auth-trash';
|
|
8
12
|
export { logger } from './logger';
|
|
9
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGvG,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAGtE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG3D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGvG,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAGtE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG3D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGlG,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAGtG,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,4 +4,6 @@ export { requireAuth, requireClaims, requireOwnership } from './auth.js';
|
|
|
4
4
|
export { created, handleError, success } from './response.js';
|
|
5
5
|
export { getDb } from './firestore.js';
|
|
6
6
|
export { getNextCounter } from './counter.js';
|
|
7
|
+
export { getTrashItem, listTrash, moveToTrash, permanentDelete, restoreFromTrash } from './trash.js';
|
|
8
|
+
export { moveToTrashWithAuth, permanentDeleteWithAuth, restoreFromTrashWithAuth } from './auth-trash.js';
|
|
7
9
|
export { logger } from './logger.js';
|
package/dist/trash.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Timestamp } from 'firebase-admin/firestore';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an item in the trash collection.
|
|
4
|
+
* Generic type T is the shape of the original document data.
|
|
5
|
+
*/
|
|
6
|
+
export interface TrashItem<T = unknown> {
|
|
7
|
+
/** Auto-generated trash document ID */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Original document ID */
|
|
10
|
+
originalId: string;
|
|
11
|
+
/** Original collection path */
|
|
12
|
+
originalCollection: string;
|
|
13
|
+
/** Object type for filtering (e.g., "djRequest", "event") */
|
|
14
|
+
objectType: string;
|
|
15
|
+
/** When the item was deleted */
|
|
16
|
+
deletedAt: Timestamp;
|
|
17
|
+
/** UID of user who deleted */
|
|
18
|
+
deletedBy: string;
|
|
19
|
+
/** The original document data */
|
|
20
|
+
data: T;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Move a document to trash.
|
|
24
|
+
*
|
|
25
|
+
* Atomically:
|
|
26
|
+
* 1. Reads the original document
|
|
27
|
+
* 2. Creates a trash entry with metadata
|
|
28
|
+
* 3. Deletes the original document
|
|
29
|
+
*
|
|
30
|
+
* @param collection - The collection path (e.g., "djRequests")
|
|
31
|
+
* @param documentId - The document ID to trash
|
|
32
|
+
* @param deletedBy - UID of the user performing the deletion
|
|
33
|
+
* @param objectType - Type identifier for filtering (e.g., "djRequest")
|
|
34
|
+
* @param databaseId - Optional named database
|
|
35
|
+
* @returns The created trash item
|
|
36
|
+
* @throws NotFoundError if document doesn't exist
|
|
37
|
+
*/
|
|
38
|
+
export declare function moveToTrash<T = unknown>(collection: string, documentId: string, deletedBy: string, objectType: string, databaseId?: string): Promise<TrashItem<T>>;
|
|
39
|
+
/**
|
|
40
|
+
* Restore a document from trash to its original location.
|
|
41
|
+
*
|
|
42
|
+
* Atomically:
|
|
43
|
+
* 1. Reads the trash entry
|
|
44
|
+
* 2. Recreates the original document
|
|
45
|
+
* 3. Deletes the trash entry
|
|
46
|
+
*
|
|
47
|
+
* @param trashItemId - The trash document ID
|
|
48
|
+
* @param databaseId - Optional named database
|
|
49
|
+
* @throws NotFoundError if trash item doesn't exist
|
|
50
|
+
*/
|
|
51
|
+
export declare function restoreFromTrash(trashItemId: string, databaseId?: string): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Permanently delete a document from trash.
|
|
54
|
+
*
|
|
55
|
+
* @param trashItemId - The trash document ID
|
|
56
|
+
* @param databaseId - Optional named database
|
|
57
|
+
* @throws NotFoundError if trash item doesn't exist
|
|
58
|
+
*/
|
|
59
|
+
export declare function permanentDelete(trashItemId: string, databaseId?: string): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* List items in trash, optionally filtered by object type.
|
|
62
|
+
*
|
|
63
|
+
* @param objectType - Optional filter by object type
|
|
64
|
+
* @param limit - Maximum items to return (default: 100)
|
|
65
|
+
* @param databaseId - Optional named database
|
|
66
|
+
* @returns Array of trash items, newest first
|
|
67
|
+
*/
|
|
68
|
+
export declare function listTrash<T = unknown>(objectType?: string, limit?: number, databaseId?: string): Promise<TrashItem<T>[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Get a single trash item by ID.
|
|
71
|
+
*
|
|
72
|
+
* @param trashItemId - The trash document ID
|
|
73
|
+
* @param databaseId - Optional named database
|
|
74
|
+
* @returns The trash item or null if not found
|
|
75
|
+
*/
|
|
76
|
+
export declare function getTrashItem<T = unknown>(trashItemId: string, databaseId?: string): Promise<TrashItem<T> | null>;
|
|
77
|
+
//# sourceMappingURL=trash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trash.d.ts","sourceRoot":"","sources":["../src/trash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAcrD;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACpC,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,6DAA6D;IAC7D,UAAU,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,SAAS,EAAE,SAAS,CAAC;IACrB,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,IAAI,EAAE,CAAC,CAAC;CACT;AASD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,WAAW,CAAC,CAAC,GAAG,OAAO,EAC3C,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAmCvB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAsBf;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAAC,CAAC,GAAG,OAAO,EACzC,UAAU,CAAC,EAAE,MAAM,EACnB,KAAK,GAAE,MAAY,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAiBzB;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,CAAC,GAAG,OAAO,EAC5C,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAa9B"}
|
package/dist/trash.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Timestamp } from 'firebase-admin/firestore';
|
|
2
|
+
import { getDb } from './firestore.js';
|
|
3
|
+
import { NotFoundError } from './errors.js';
|
|
4
|
+
|
|
5
|
+
const TRASH_COLLECTION = "_trash";
|
|
6
|
+
async function moveToTrash(collection, documentId, deletedBy, objectType, databaseId) {
|
|
7
|
+
const db = getDb(databaseId);
|
|
8
|
+
const originalRef = db.collection(collection).doc(documentId);
|
|
9
|
+
const trashRef = db.collection(TRASH_COLLECTION).doc();
|
|
10
|
+
return db.runTransaction(async (transaction) => {
|
|
11
|
+
const originalDoc = await transaction.get(originalRef);
|
|
12
|
+
if (!originalDoc.exists) {
|
|
13
|
+
throw new NotFoundError(`Document ${collection}/${documentId} not found`);
|
|
14
|
+
}
|
|
15
|
+
const originalData = originalDoc.data();
|
|
16
|
+
const trashData = {
|
|
17
|
+
originalId: documentId,
|
|
18
|
+
originalCollection: collection,
|
|
19
|
+
objectType,
|
|
20
|
+
deletedAt: Timestamp.now(),
|
|
21
|
+
deletedBy,
|
|
22
|
+
data: originalData
|
|
23
|
+
};
|
|
24
|
+
transaction.set(trashRef, trashData);
|
|
25
|
+
transaction.delete(originalRef);
|
|
26
|
+
return {
|
|
27
|
+
id: trashRef.id,
|
|
28
|
+
...trashData
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async function restoreFromTrash(trashItemId, databaseId) {
|
|
33
|
+
const db = getDb(databaseId);
|
|
34
|
+
const trashRef = db.collection(TRASH_COLLECTION).doc(trashItemId);
|
|
35
|
+
await db.runTransaction(async (transaction) => {
|
|
36
|
+
const trashDoc = await transaction.get(trashRef);
|
|
37
|
+
if (!trashDoc.exists) {
|
|
38
|
+
throw new NotFoundError(`Trash item ${trashItemId} not found`);
|
|
39
|
+
}
|
|
40
|
+
const trashData = trashDoc.data();
|
|
41
|
+
const originalRef = db.collection(trashData.originalCollection).doc(trashData.originalId);
|
|
42
|
+
transaction.set(originalRef, trashData.data);
|
|
43
|
+
transaction.delete(trashRef);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async function permanentDelete(trashItemId, databaseId) {
|
|
47
|
+
const db = getDb(databaseId);
|
|
48
|
+
const trashRef = db.collection(TRASH_COLLECTION).doc(trashItemId);
|
|
49
|
+
const trashDoc = await trashRef.get();
|
|
50
|
+
if (!trashDoc.exists) {
|
|
51
|
+
throw new NotFoundError(`Trash item ${trashItemId} not found`);
|
|
52
|
+
}
|
|
53
|
+
await trashRef.delete();
|
|
54
|
+
}
|
|
55
|
+
async function listTrash(objectType, limit = 100, databaseId) {
|
|
56
|
+
const db = getDb(databaseId);
|
|
57
|
+
let query = db.collection(TRASH_COLLECTION).orderBy("deletedAt", "desc").limit(limit);
|
|
58
|
+
if (objectType) {
|
|
59
|
+
query = query.where("objectType", "==", objectType);
|
|
60
|
+
}
|
|
61
|
+
const snapshot = await query.get();
|
|
62
|
+
return snapshot.docs.map((doc) => ({
|
|
63
|
+
id: doc.id,
|
|
64
|
+
...doc.data()
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
async function getTrashItem(trashItemId, databaseId) {
|
|
68
|
+
const db = getDb(databaseId);
|
|
69
|
+
const trashRef = db.collection(TRASH_COLLECTION).doc(trashItemId);
|
|
70
|
+
const doc = await trashRef.get();
|
|
71
|
+
if (!doc.exists) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
id: doc.id,
|
|
76
|
+
...doc.data()
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { getTrashItem, listTrash, moveToTrash, permanentDelete, restoreFromTrash };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@progressive-development/pd-provider-firebase-functions",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Firebase Functions v2 utilities for pd-spa-helper backend",
|
|
5
5
|
"author": "PD Progressive Development",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|