@progressive-development/pd-provider-firebase-functions 0.3.2 → 0.3.4

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.
@@ -13,7 +13,7 @@ export interface AuthTrashOptions {
13
13
  * Move document to trash AND disable the associated Auth user.
14
14
  *
15
15
  * Order of operations:
16
- * 1. Disable Auth user (if this fails, nothing else happens)
16
+ * 1. Disable Auth user (if user doesn't exist, continue anyway)
17
17
  * 2. Move document to trash
18
18
  *
19
19
  * @param collection - The collection path
@@ -30,7 +30,7 @@ export declare function moveToTrashWithAuth<T = unknown>(collection: string, doc
30
30
  * Order of operations:
31
31
  * 1. Get trash item to find Auth UID
32
32
  * 2. Restore document from trash
33
- * 3. Re-enable Auth user
33
+ * 3. Re-enable Auth user (if user doesn't exist, log warning)
34
34
  *
35
35
  * @param trashItemId - The trash document ID
36
36
  * @param options - Auth and database options
@@ -42,7 +42,7 @@ export declare function restoreFromTrashWithAuth(trashItemId: string, options?:
42
42
  * Order of operations:
43
43
  * 1. Get trash item to find Auth UID
44
44
  * 2. Delete from trash
45
- * 3. Delete Auth user
45
+ * 3. Delete Auth user (ignore if user doesn't exist)
46
46
  *
47
47
  * @param trashItemId - The trash document ID
48
48
  * @param options - Auth and database options
@@ -1 +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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A6Bf"}
@@ -18,8 +18,17 @@ function getAuthUidFromTrashItem(trashItem, options) {
18
18
  async function moveToTrashWithAuth(collection, documentId, deletedBy, objectType, options) {
19
19
  const authUid = options?.authUidSource === "documentId" || !options?.authUidSource ? documentId : documentId;
20
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 });
21
+ try {
22
+ await getAuth().updateUser(authUid, { disabled: true });
23
+ logger.info("Auth user disabled", { authUid });
24
+ } catch (error) {
25
+ const authError = error;
26
+ if (authError.code === "auth/user-not-found") {
27
+ logger.info("Auth user not found, continuing with trash operation", { authUid });
28
+ } else {
29
+ throw error;
30
+ }
31
+ }
23
32
  const trashItem = await moveToTrash(
24
33
  collection,
25
34
  documentId,
@@ -45,8 +54,20 @@ async function restoreFromTrashWithAuth(trashItemId, options) {
45
54
  originalCollection: trashItem.originalCollection
46
55
  });
47
56
  await restoreFromTrash(trashItemId, options?.databaseId);
48
- await getAuth().updateUser(authUid, { disabled: false });
49
- logger.info("Document restored and Auth user re-enabled", { trashItemId, authUid });
57
+ try {
58
+ await getAuth().updateUser(authUid, { disabled: false });
59
+ logger.info("Document restored and Auth user re-enabled", { trashItemId, authUid });
60
+ } catch (error) {
61
+ const authError = error;
62
+ if (authError.code === "auth/user-not-found") {
63
+ logger.warn("Document restored but Auth user not found - manual Auth user creation required", {
64
+ trashItemId,
65
+ authUid
66
+ });
67
+ } else {
68
+ throw error;
69
+ }
70
+ }
50
71
  }
51
72
  async function permanentDeleteWithAuth(trashItemId, options) {
52
73
  const trashItem = await getTrashItem(trashItemId, options?.databaseId);
@@ -59,8 +80,17 @@ async function permanentDeleteWithAuth(trashItemId, options) {
59
80
  authUid
60
81
  });
61
82
  await permanentDelete(trashItemId, options?.databaseId);
62
- await getAuth().deleteUser(authUid);
63
- logger.info("Trash item and Auth user permanently deleted", { trashItemId, authUid });
83
+ try {
84
+ await getAuth().deleteUser(authUid);
85
+ logger.info("Trash item and Auth user permanently deleted", { trashItemId, authUid });
86
+ } catch (error) {
87
+ const authError = error;
88
+ if (authError.code === "auth/user-not-found") {
89
+ logger.info("Auth user not found, trash item deleted", { trashItemId, authUid });
90
+ } else {
91
+ throw error;
92
+ }
93
+ }
64
94
  }
65
95
 
66
96
  export { moveToTrashWithAuth, permanentDeleteWithAuth, restoreFromTrashWithAuth };
package/dist/errors.d.ts CHANGED
@@ -15,4 +15,7 @@ export declare class ForbiddenError extends AppError {
15
15
  export declare class NotFoundError extends AppError {
16
16
  constructor(message: string);
17
17
  }
18
+ export declare class ConflictError extends AppError {
19
+ constructor(message: string, code?: string);
20
+ }
18
21
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAS,SAAQ,KAAK;aAGf,IAAI,EAAE,MAAM;aACZ,UAAU,EAAE,MAAM;gBAFlC,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM;CAKrC;AAED,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,OAAO,SAA4B;CAGhD;AAED,qBAAa,cAAe,SAAQ,QAAQ;gBAC9B,OAAO,SAAkB;CAGtC;AAED,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,MAAM;CAG5B"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAS,SAAQ,KAAK;aAGf,IAAI,EAAE,MAAM;aACZ,UAAU,EAAE,MAAM;gBAFlC,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM;CAKrC;AAED,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,OAAO,SAA4B;CAGhD;AAED,qBAAa,cAAe,SAAQ,QAAQ;gBAC9B,OAAO,SAAkB;CAGtC;AAED,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,MAAM,EAAE,IAAI,SAAa;CAG/C"}
package/dist/errors.js CHANGED
@@ -26,5 +26,10 @@ class NotFoundError extends AppError {
26
26
  super(message, "NOT_FOUND", 404);
27
27
  }
28
28
  }
29
+ class ConflictError extends AppError {
30
+ constructor(message, code = "CONFLICT") {
31
+ super(message, code, 409);
32
+ }
33
+ }
29
34
 
30
- export { AppError, ForbiddenError, NotFoundError, UnauthorizedError, ValidationError };
35
+ export { AppError, ConflictError, ForbiddenError, NotFoundError, UnauthorizedError, ValidationError };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type { ApiResponse, AuthContext } from './types';
2
2
  export { StatusCode } from './types';
3
- export { AppError, ValidationError, UnauthorizedError, ForbiddenError, NotFoundError } from './errors';
3
+ export { AppError, ValidationError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError } from './errors';
4
4
  export { requireAuth, requireClaims, requireOwnership } from './auth';
5
5
  export { success, created, handleError } from './response';
6
6
  export { getDb } from './firestore';
@@ -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,CA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c,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
@@ -1,5 +1,5 @@
1
1
  export { StatusCode } from './types.js';
2
- export { AppError, ForbiddenError, NotFoundError, UnauthorizedError, ValidationError } from './errors.js';
2
+ export { AppError, ConflictError, ForbiddenError, NotFoundError, UnauthorizedError, ValidationError } from './errors.js';
3
3
  export { requireAuth, requireClaims, requireOwnership } from './auth.js';
4
4
  export { created, handleError, success } from './response.js';
5
5
  export { getDb } from './firestore.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@progressive-development/pd-provider-firebase-functions",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
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",