@dereekb/firebase-server 13.2.2 → 13.3.1

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.
Files changed (166) hide show
  1. package/index.cjs.js +7506 -1884
  2. package/index.esm.js +7505 -1890
  3. package/mailgun/index.cjs.js +333 -31
  4. package/mailgun/index.esm.js +333 -31
  5. package/mailgun/package.json +8 -8
  6. package/mailgun/src/lib/auth.mailgun.d.ts +22 -3
  7. package/model/index.cjs.js +11334 -3830
  8. package/model/index.esm.js +11338 -3834
  9. package/model/package.json +10 -10
  10. package/model/src/lib/mailgun/notification.send.service.mailgun.d.ts +27 -1
  11. package/model/src/lib/notification/notification.action.init.service.d.ts +93 -1
  12. package/model/src/lib/notification/notification.action.service.d.ts +151 -2
  13. package/model/src/lib/notification/notification.config.d.ts +19 -7
  14. package/model/src/lib/notification/notification.config.service.d.ts +44 -6
  15. package/model/src/lib/notification/notification.create.run.d.ts +33 -5
  16. package/model/src/lib/notification/notification.error.d.ts +63 -0
  17. package/model/src/lib/notification/notification.module.d.ts +11 -0
  18. package/model/src/lib/notification/notification.send.d.ts +8 -1
  19. package/model/src/lib/notification/notification.send.service.d.ts +7 -1
  20. package/model/src/lib/notification/notification.send.service.notificationsummary.d.ts +32 -2
  21. package/model/src/lib/notification/notification.send.service.text.d.ts +11 -3
  22. package/model/src/lib/notification/notification.task.service.d.ts +13 -1
  23. package/model/src/lib/notification/notification.task.service.handler.d.ts +27 -3
  24. package/model/src/lib/notification/notification.task.service.util.d.ts +16 -4
  25. package/model/src/lib/notification/notification.task.subtask.handler.d.ts +31 -1
  26. package/model/src/lib/notification/notification.util.d.ts +70 -0
  27. package/model/src/lib/storagefile/storagefile.action.init.service.d.ts +62 -1
  28. package/model/src/lib/storagefile/storagefile.action.server.d.ts +124 -2
  29. package/model/src/lib/storagefile/storagefile.error.d.ts +44 -0
  30. package/model/src/lib/storagefile/storagefile.module.d.ts +11 -0
  31. package/model/src/lib/storagefile/storagefile.task.service.handler.d.ts +4 -1
  32. package/model/src/lib/storagefile/storagefile.upload.service.d.ts +13 -1
  33. package/model/src/lib/storagefile/storagefile.upload.service.initializer.d.ts +43 -1
  34. package/model/src/lib/storagefile/storagefile.util.d.ts +8 -0
  35. package/oidc/index.cjs.default.js +1 -0
  36. package/oidc/index.cjs.js +5607 -0
  37. package/oidc/index.cjs.mjs +2 -0
  38. package/oidc/index.d.ts +1 -0
  39. package/oidc/index.esm.js +5560 -0
  40. package/oidc/package.json +26 -0
  41. package/oidc/src/index.d.ts +1 -0
  42. package/oidc/src/lib/controller/index.d.ts +3 -0
  43. package/oidc/src/lib/controller/oidc.interaction.controller.d.ts +54 -0
  44. package/oidc/src/lib/controller/oidc.provider.controller.d.ts +18 -0
  45. package/oidc/src/lib/controller/oidc.wellknown.controller.d.ts +36 -0
  46. package/oidc/src/lib/index.d.ts +6 -0
  47. package/oidc/src/lib/middleware/index.d.ts +3 -0
  48. package/oidc/src/lib/middleware/oauth-auth.decorator.d.ts +14 -0
  49. package/oidc/src/lib/middleware/oauth-auth.middleware.d.ts +21 -0
  50. package/oidc/src/lib/middleware/oauth-auth.module.d.ts +50 -0
  51. package/oidc/src/lib/model/index.d.ts +3 -0
  52. package/oidc/src/lib/model/jwks/index.d.ts +3 -0
  53. package/oidc/src/lib/model/jwks/jwks.d.ts +107 -0
  54. package/oidc/src/lib/model/jwks/jwks.id.d.ts +9 -0
  55. package/oidc/src/lib/model/jwks/jwks.query.d.ts +18 -0
  56. package/oidc/src/lib/model/model.d.ts +12 -0
  57. package/oidc/src/lib/model/oidc/index.d.ts +2 -0
  58. package/oidc/src/lib/model/oidc/oidcmodel.action.server.d.ts +62 -0
  59. package/oidc/src/lib/model/oidc/oidcmodel.module.d.ts +23 -0
  60. package/oidc/src/lib/oidc.config.d.ts +175 -0
  61. package/oidc/src/lib/oidc.module.d.ts +100 -0
  62. package/oidc/src/lib/service/index.d.ts +10 -0
  63. package/oidc/src/lib/service/oidc.account.d.ts +36 -0
  64. package/oidc/src/lib/service/oidc.account.service.d.ts +104 -0
  65. package/oidc/src/lib/service/oidc.adapter.service.d.ts +20 -0
  66. package/oidc/src/lib/service/oidc.auth.d.ts +26 -0
  67. package/oidc/src/lib/service/oidc.client.service.d.ts +57 -0
  68. package/oidc/src/lib/service/oidc.config.service.d.ts +100 -0
  69. package/oidc/src/lib/service/oidc.encryption.service.d.ts +53 -0
  70. package/oidc/src/lib/service/oidc.interaction.service.d.ts +44 -0
  71. package/oidc/src/lib/service/oidc.jwks.service.d.ts +105 -0
  72. package/oidc/src/lib/service/oidc.service.d.ts +55 -0
  73. package/package.json +21 -14
  74. package/src/lib/auth/auth.context.d.ts +22 -2
  75. package/src/lib/auth/auth.service.d.ts +5 -0
  76. package/src/lib/auth/auth.service.error.d.ts +2 -1
  77. package/src/lib/auth/auth.util.d.ts +15 -3
  78. package/src/lib/env/env.config.d.ts +42 -0
  79. package/src/lib/env/env.service.d.ts +17 -0
  80. package/src/lib/env/index.d.ts +1 -0
  81. package/src/lib/firestore/array.d.ts +11 -3
  82. package/src/lib/firestore/driver.accessor.batch.d.ts +27 -4
  83. package/src/lib/firestore/driver.accessor.d.ts +43 -0
  84. package/src/lib/firestore/driver.accessor.default.d.ts +20 -0
  85. package/src/lib/firestore/driver.accessor.transaction.d.ts +28 -4
  86. package/src/lib/firestore/driver.d.ts +14 -0
  87. package/src/lib/firestore/driver.query.d.ts +25 -0
  88. package/src/lib/firestore/increment.d.ts +13 -3
  89. package/src/lib/firestore/snapshot/index.d.ts +1 -1
  90. package/src/lib/firestore/snapshot/{snapshot.field.d.ts → snapshot.field.encrypt.d.ts} +13 -27
  91. package/src/lib/function/assert.d.ts +32 -16
  92. package/src/lib/function/context.d.ts +26 -0
  93. package/src/lib/function/error.auth.d.ts +15 -0
  94. package/src/lib/function/error.d.ts +68 -4
  95. package/src/lib/nest/app.d.ts +53 -9
  96. package/src/lib/nest/app.module.d.ts +90 -0
  97. package/src/lib/nest/auth/auth.module.d.ts +30 -4
  98. package/src/lib/nest/auth/auth.util.d.ts +38 -0
  99. package/src/lib/nest/controller/auth.context.server.d.ts +27 -0
  100. package/src/lib/nest/controller/index.d.ts +1 -0
  101. package/src/lib/nest/development/development.app.function.d.ts +45 -0
  102. package/src/lib/nest/development/development.assert.function.d.ts +19 -1
  103. package/src/lib/nest/development/development.function.d.ts +42 -3
  104. package/src/lib/nest/development/development.schedule.function.d.ts +29 -0
  105. package/src/lib/nest/development/development.schedule.function.error.d.ts +21 -0
  106. package/src/lib/nest/env/env.service.d.ts +9 -0
  107. package/src/lib/nest/env/env.util.d.ts +16 -0
  108. package/src/lib/nest/firebase/firebase.module.d.ts +13 -1
  109. package/src/lib/nest/firestore/firestore.module.d.ts +24 -8
  110. package/src/lib/nest/function/call.d.ts +75 -6
  111. package/src/lib/nest/function/context.d.ts +85 -2
  112. package/src/lib/nest/function/nest.d.ts +46 -0
  113. package/src/lib/nest/function/schedule.d.ts +49 -0
  114. package/src/lib/nest/function/v2/blocking.d.ts +92 -8
  115. package/src/lib/nest/function/v2/call.d.ts +38 -8
  116. package/src/lib/nest/function/v2/event.d.ts +67 -4
  117. package/src/lib/nest/function/v2/schedule.d.ts +36 -5
  118. package/src/lib/nest/index.d.ts +3 -0
  119. package/src/lib/nest/middleware/appcheck.d.ts +5 -0
  120. package/src/lib/nest/middleware/appcheck.middleware.d.ts +44 -14
  121. package/src/lib/nest/middleware/appcheck.module.d.ts +10 -1
  122. package/src/lib/nest/middleware/globalprefix.d.ts +31 -3
  123. package/src/lib/nest/middleware/index.d.ts +2 -1
  124. package/src/lib/nest/middleware/rawbody.middleware.d.ts +6 -0
  125. package/src/lib/nest/model/call.model.function.d.ts +69 -3
  126. package/src/lib/nest/model/create.model.function.d.ts +66 -0
  127. package/src/lib/nest/model/crud.assert.function.d.ts +27 -1
  128. package/src/lib/nest/model/delete.model.function.d.ts +55 -0
  129. package/src/lib/nest/model/permission.error.d.ts +15 -0
  130. package/src/lib/nest/model/read.model.function.d.ts +57 -0
  131. package/src/lib/nest/model/specifier.function.d.ts +58 -1
  132. package/src/lib/nest/model/update.model.function.d.ts +58 -0
  133. package/src/lib/nest/nest.provider.d.ts +24 -11
  134. package/src/lib/nest/nest.provider.server.d.ts +12 -0
  135. package/src/lib/nest/storage/storage.module.d.ts +30 -4
  136. package/src/lib/storage/driver.accessor.d.ts +33 -0
  137. package/src/lib/storage/driver.d.ts +14 -0
  138. package/src/lib/storage/storage.d.ts +11 -4
  139. package/src/lib/storage/storage.service.d.ts +10 -1
  140. package/src/lib/type.d.ts +7 -2
  141. package/test/index.cjs.js +4072 -757
  142. package/test/index.esm.js +4073 -761
  143. package/test/package.json +10 -10
  144. package/test/src/lib/firebase/firebase.admin.auth.d.ts +82 -1
  145. package/test/src/lib/firebase/firebase.admin.collection.d.ts +55 -3
  146. package/test/src/lib/firebase/firebase.admin.d.ts +64 -0
  147. package/test/src/lib/firebase/firebase.admin.function.d.ts +84 -0
  148. package/test/src/lib/firebase/firebase.admin.nest.d.ts +125 -17
  149. package/test/src/lib/firebase/firebase.admin.nest.function.callable.context.d.ts +44 -0
  150. package/test/src/lib/firebase/firebase.admin.nest.function.cloud.context.d.ts +41 -0
  151. package/test/src/lib/firebase/firebase.admin.nest.function.d.ts +98 -0
  152. package/test/src/lib/firebase/firebase.admin.test.server.d.ts +26 -0
  153. package/test/src/lib/firebase/firebase.d.ts +57 -2
  154. package/test/src/lib/firebase/firebase.function.d.ts +138 -0
  155. package/test/src/lib/firestore/firestore.admin.d.ts +6 -0
  156. package/test/src/lib/firestore/firestore.d.ts +30 -0
  157. package/test/src/lib/storage/storage.admin.d.ts +9 -3
  158. package/test/src/lib/storage/storage.d.ts +30 -0
  159. package/zoho/index.cjs.js +406 -73
  160. package/zoho/index.esm.js +406 -73
  161. package/zoho/package.json +8 -8
  162. package/zoho/src/lib/zoho.accounts.firebase.d.ts +13 -2
  163. package/zoho/src/lib/zoho.accounts.firebase.system.d.ts +29 -6
  164. package/index.cjs.js.map +0 -1
  165. package/index.esm.js.map +0 -1
  166. /package/src/lib/nest/middleware/{webhook.d.ts → webhook.module.d.ts} +0 -0
package/test/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@dereekb/firebase-server/test",
3
- "version": "13.2.2",
3
+ "version": "13.3.1",
4
4
  "peerDependencies": {
5
- "@dereekb/date": "13.2.2",
6
- "@dereekb/firebase": "13.2.2",
7
- "@dereekb/firebase-server": "13.2.2",
8
- "@dereekb/model": "13.2.2",
9
- "@dereekb/nestjs": "13.2.2",
10
- "@dereekb/rxjs": "13.2.2",
11
- "@dereekb/util": "13.2.2",
5
+ "@dereekb/date": "13.3.1",
6
+ "@dereekb/firebase": "13.3.1",
7
+ "@dereekb/firebase-server": "13.3.1",
8
+ "@dereekb/model": "13.3.1",
9
+ "@dereekb/nestjs": "13.3.1",
10
+ "@dereekb/rxjs": "13.3.1",
11
+ "@dereekb/util": "13.3.1",
12
12
  "@google-cloud/firestore": "^7.11.6",
13
13
  "@google-cloud/storage": "^7.19.0",
14
- "@nestjs/common": "^11.0.0",
15
- "@nestjs/testing": "^11.0.0",
14
+ "@nestjs/common": "^11.1.16",
15
+ "@nestjs/testing": "^11.1.14",
16
16
  "firebase-admin": "^13.0.0",
17
17
  "firebase-functions": "^7.0.0",
18
18
  "firebase-functions-test": "3.4.1",
@@ -9,10 +9,27 @@ import { type WrappedBlockingFunction, type WrappedBlockingFunctionWithHandler,
9
9
  import { type ScheduledEvent } from 'firebase-functions/scheduler';
10
10
  import { type AuthData } from '@dereekb/firebase-server';
11
11
  import { type AuthBlockingEvent } from 'firebase-functions/identity';
12
+ /**
13
+ * Union of all cloud function wrapper types that can be invoked via {@link AuthorizedUserTestContext.callCloudFunction}.
14
+ *
15
+ * Includes gen 1 wrapped functions, gen 2 wrapped functions, blocking functions, and scheduled functions.
16
+ */
12
17
  export type CallCloudFunction = WrappedCloudFunctionV1<any> | WrappedBlockingFunctionWithHandler<any, any> | WrappedBlockingFunction | WrappedV2Function<any> | WrappedCloudFunctionV1<any>;
18
+ /**
19
+ * Infers the input parameter type for a given wrapped cloud function type.
20
+ *
21
+ * Used to extract the expected params type when calling a cloud function in tests.
22
+ */
13
23
  export type CallCloudFunctionParams<F> = F extends WrappedFunction<infer I> ? I : unknown | undefined | void;
14
24
  /**
15
- * Testing context for a single user.
25
+ * Test context interface representing an authorized Firebase user.
26
+ *
27
+ * Provides access to the user's UID, record, tokens, and the ability to invoke
28
+ * wrapped Firebase Cloud Functions (callable, scheduled, blocking, and event-based)
29
+ * as that user. Used within Jest test suites to simulate authenticated function calls.
30
+ *
31
+ * @see {@link AuthorizedUserTestContextInstance} for the concrete implementation
32
+ * @see {@link authorizedUserContextFactory} to create test contexts via a factory
16
33
  */
17
34
  export interface AuthorizedUserTestContext {
18
35
  readonly uid: FirebaseAuthUserId;
@@ -39,6 +56,13 @@ export interface AuthorizedUserTestContext {
39
56
  callCloudFunction<F extends WrappedCloudFunctionV1<any>, O = unknown>(fn: F, params: CallCloudFunctionParams<F>, skipJsonConversion?: boolean): Promise<O>;
40
57
  callCloudFunction<F extends WrappedFunction<any>, O = unknown>(fn: F, params: CallCloudFunctionParams<F>, skipJsonConversion?: boolean): Promise<O>;
41
58
  }
59
+ /**
60
+ * Fixture wrapper for {@link AuthorizedUserTestContextInstance} that delegates all
61
+ * {@link AuthorizedUserTestContext} operations to the underlying instance.
62
+ *
63
+ * Manages the lifecycle of the authorized user test context within the Jest test fixture hierarchy.
64
+ * Use this as the primary handle in test suites; it is created automatically by {@link authorizedUserContextFactory}.
65
+ */
42
66
  export declare class AuthorizedUserTestContextFixture<PI extends FirebaseAdminTestContext = FirebaseAdminTestContext, PF extends TestContextFixture<PI> = TestContextFixture<PI>, I extends AuthorizedUserTestContextInstance<PI> = AuthorizedUserTestContextInstance<PI>> extends AbstractChildTestContextFixture<I, PF> implements AuthorizedUserTestContext {
43
67
  get uid(): FirebaseAuthUserId;
44
68
  loadUserRecord(): Promise<UserRecord>;
@@ -58,7 +82,24 @@ export declare class AuthorizedUserTestContextFixture<PI extends FirebaseAdminTe
58
82
  callCloudFunction<F extends WrappedCloudFunctionV1<any>, O = unknown>(fn: F, params: CallCloudFunctionParams<F>, skipJsonConversion?: boolean): Promise<O>;
59
83
  callCloudFunction<F extends WrappedFunction<any>, O = unknown>(fn: F, params: CallCloudFunctionParams<F>, skipJsonConversion?: boolean): Promise<O>;
60
84
  }
85
+ /**
86
+ * Partial event context for gen 1 event-triggered cloud functions, with the `auth` field omitted
87
+ * since it is injected automatically by the test context.
88
+ *
89
+ * @deprecated Used only with gen 1 event cloud functions via {@link AuthorizedUserTestContextInstance.callEventCloudFunction}.
90
+ */
61
91
  export type CallEventFunctionEventContext = Partial<Omit<EventContext, 'auth'>>;
92
+ /**
93
+ * Concrete implementation of {@link AuthorizedUserTestContext} that holds a Firebase user UID
94
+ * and a reference to the parent {@link FirebaseAdminTestContext}.
95
+ *
96
+ * Provides methods to load the user's record/token, build context options, and invoke
97
+ * wrapped Cloud Functions (callable, scheduled, blocking, and event-based) as the authorized user.
98
+ * Automatically handles JSON round-trip simulation for function parameters unless `skipJsonConversion` is set.
99
+ *
100
+ * Created by {@link authorizedUserContextFactory} during test setup; typically accessed
101
+ * through the {@link AuthorizedUserTestContextFixture} wrapper.
102
+ */
62
103
  export declare class AuthorizedUserTestContextInstance<PI extends FirebaseAdminTestContext = FirebaseAdminTestContext> implements AuthorizedUserTestContext {
63
104
  readonly uid: FirebaseAuthUserId;
64
105
  readonly testContext: PI;
@@ -162,6 +203,10 @@ export interface AuthorizedUserTestContextParams<PI extends FirebaseAdminTestCon
162
203
  * Convenience function for using authorizedUserContextFactory directly and passing buildTests.
163
204
  */
164
205
  export declare function authorizedUserContext<PI extends FirebaseAdminTestContext = FirebaseAdminTestContext, PF extends TestContextFixture<PI> = TestContextFixture<PI>, I extends AuthorizedUserTestContextInstance<PI> = AuthorizedUserTestContextInstance<PI>, F extends AuthorizedUserTestContextFixture<PI, PF, I> = AuthorizedUserTestContextFixture<PI, PF, I>>(config: AuthorizedUserTestContextParams<PI, PF, I, F>, buildTests: (u: F) => void): void;
206
+ /**
207
+ * Configuration for {@link authorizedUserContextFactory}, which is {@link AuthorizedUserTestContextParams}
208
+ * without the fixture reference (`f`). The fixture is provided separately when the factory is invoked.
209
+ */
165
210
  export type AuthorizedUserTestContextFactoryConfig<PI extends FirebaseAdminTestContext = FirebaseAdminTestContext, PF extends TestContextFixture<PI> = TestContextFixture<PI>, I extends AuthorizedUserTestContextInstance<PI> = AuthorizedUserTestContextInstance<PI>, F extends AuthorizedUserTestContextFixture<PI, PF, I> = AuthorizedUserTestContextFixture<PI, PF, I>> = Omit<AuthorizedUserTestContextParams<PI, PF, I, F>, 'f'>;
166
211
  export interface AuthorizedUserTestContextFactoryParams<PI extends FirebaseAdminTestContext = FirebaseAdminTestContext, PF extends TestContextFixture<PI> = TestContextFixture<PI>> {
167
212
  readonly f: PF;
@@ -180,7 +225,19 @@ export interface AuthorizedUserTestContextFactoryParams<PI extends FirebaseAdmin
180
225
  */
181
226
  readonly template?: GetterOrValue<AuthorizedUserTestContextDetailsTemplate>;
182
227
  }
228
+ /**
229
+ * Factory that generates unique random email addresses for test users.
230
+ *
231
+ * Used by {@link authorizedUserContextFactory} when `addContactInfo` is enabled
232
+ * and no explicit email is provided in the user details template.
233
+ */
183
234
  export declare const AUTHORIZED_USER_RANDOM_EMAIL_FACTORY: import("@dereekb/util").RandomEmailFactory;
235
+ /**
236
+ * Factory that generates unique random E.164 phone numbers for test users.
237
+ *
238
+ * Used by {@link authorizedUserContextFactory} when `addContactInfo` is enabled
239
+ * and no explicit phone number is provided in the user details template.
240
+ */
184
241
  export declare const AUTHORIZED_USER_RANDOM_PHONE_NUMBER_FACTORY: import("@dereekb/util").RandomPhoneNumberFactory;
185
242
  /**
186
243
  * Creates a new Jest Context that has a random user for authorization for use in firebase server tests.
@@ -192,6 +249,12 @@ export declare function authorizedUserContextFactory<PI extends FirebaseAdminTes
192
249
  * Has the format 'test-uid-<number>'
193
250
  */
194
251
  export declare const testUidFactory: Factory<FirebaseAuthUserId>;
252
+ /**
253
+ * An encoded JWT string representing a Firebase custom token created for testing.
254
+ *
255
+ * @see {@link createEncodedTestFirestoreTokenForUserRecord} to create one
256
+ * @see {@link decodeEncodedCreateCustomTokenResult} to decode one
257
+ */
195
258
  export type TestEncodedFirestoreToken = string;
196
259
  /**
197
260
  * Structure of the token created by Auth.createCustomToken().
@@ -231,5 +294,23 @@ export declare function createTestFirestoreTokenForUserRecord(auth: Auth, userRe
231
294
  * @returns
232
295
  */
233
296
  export declare function createEncodedTestFirestoreTokenForUserRecord(auth: Auth, userRecord: UserRecord): Promise<TestEncodedFirestoreToken>;
297
+ /**
298
+ * Decodes an encoded custom token (JWT) into a {@link DecodedIdToken} suitable for test assertions.
299
+ *
300
+ * The custom token created by `Auth.createCustomToken()` nests custom claims under a `claims` key
301
+ * in the JWT payload. This function flattens those claims onto the top-level decoded token to match
302
+ * the structure of a real `DecodedIdToken`, and injects `auth_time` from the `iat` field.
303
+ *
304
+ * @see {@link createEncodedTestFirestoreTokenForUserRecord} for creating the encoded token
305
+ */
234
306
  export declare function decodeEncodedCreateCustomTokenResult(token: TestEncodedFirestoreToken): DecodedIdToken;
307
+ /**
308
+ * Builds a claims object from a {@link UserRecord} that mirrors the structure of a real {@link DecodedIdToken}.
309
+ *
310
+ * Copies standard identity fields (email, email_verified, picture) and merges in any
311
+ * custom claims already set on the user record. The resulting object is used as the
312
+ * custom claims parameter for `Auth.createCustomToken()` in test token generation.
313
+ *
314
+ * @see {@link createEncodedTestFirestoreTokenForUserRecord}
315
+ */
235
316
  export declare function testFirestoreClaimsFromUserRecord(userRecord: UserRecord): object;
@@ -3,7 +3,15 @@ import { type AsyncGetterOrValue, type PromiseOrValue } from '@dereekb/util';
3
3
  import { type TestContextFixture, AbstractChildTestContextFixture } from '@dereekb/util/test';
4
4
  import { type FirebaseAdminTestContext } from './firebase.admin';
5
5
  /**
6
- * Testing context for a single model.
6
+ * Test context interface representing a single Firestore document/model instance.
7
+ *
8
+ * Provides convenient access to the document's identifiers (ID, key, flat key),
9
+ * its {@link DocumentReference}, and the typed {@link FirestoreDocument} wrapper.
10
+ * Used within Jest test suites to interact with a specific document that was
11
+ * created during test setup.
12
+ *
13
+ * @see {@link ModelTestContextInstance} for the concrete implementation
14
+ * @see {@link modelTestContextFactory} to create model test contexts via a factory
7
15
  */
8
16
  export interface ModelTestContext<T, D extends FirestoreDocument<T> = FirestoreDocument<T>> {
9
17
  get documentId(): FirestoreModelId;
@@ -13,6 +21,13 @@ export interface ModelTestContext<T, D extends FirestoreDocument<T> = FirestoreD
13
21
  get documentRef(): DocumentReference<T>;
14
22
  get document(): D;
15
23
  }
24
+ /**
25
+ * Fixture wrapper for {@link ModelTestContextInstance} that delegates all
26
+ * {@link ModelTestContext} operations to the underlying instance.
27
+ *
28
+ * Manages the lifecycle of the model test context within the Jest test fixture hierarchy.
29
+ * Use this as the primary handle in test suites; it is created automatically by {@link modelTestContextFactory}.
30
+ */
16
31
  export declare class ModelTestContextFixture<T, D extends FirestoreDocument<T> = FirestoreDocument<T>, PI extends FirebaseAdminTestContext = FirebaseAdminTestContext, PF extends TestContextFixture<PI> = TestContextFixture<PI>, I extends ModelTestContextInstance<T, D, PI> = ModelTestContextInstance<T, D, PI>> extends AbstractChildTestContextFixture<I, PF> implements ModelTestContext<T, D> {
17
32
  get documentId(): FirestoreModelId;
18
33
  get documentKey(): FirestoreModelKey;
@@ -21,6 +36,16 @@ export declare class ModelTestContextFixture<T, D extends FirestoreDocument<T> =
21
36
  get documentRef(): DocumentReference<T>;
22
37
  get document(): D;
23
38
  }
39
+ /**
40
+ * Concrete implementation of {@link ModelTestContext} that holds a Firestore collection reference,
41
+ * a document reference, and the parent {@link FirebaseAdminTestContext}.
42
+ *
43
+ * Provides computed properties for the document's various key formats (path, flat, two-way flat)
44
+ * and lazily loads the typed {@link FirestoreDocument} wrapper on access.
45
+ *
46
+ * Created by {@link modelTestContextFactory} during test setup; typically accessed
47
+ * through the {@link ModelTestContextFixture} wrapper.
48
+ */
24
49
  export declare class ModelTestContextInstance<T, D extends FirestoreDocument<T> = FirestoreDocument<T>, PI extends FirebaseAdminTestContext = FirebaseAdminTestContext> implements ModelTestContext<T, D> {
25
50
  readonly collection: FirestoreCollectionLike<T, D>;
26
51
  readonly ref: DocumentReference<T>;
@@ -34,7 +59,12 @@ export declare class ModelTestContextInstance<T, D extends FirestoreDocument<T>
34
59
  get document(): D;
35
60
  }
36
61
  /**
37
- * authorizedUserContext/authorizedUserContextFactory parameters.
62
+ * Configuration for {@link modelTestContextFactory} that controls how model test contexts
63
+ * are created, initialized, and torn down.
64
+ *
65
+ * At minimum, `getCollection` must be provided to resolve the Firestore collection from the
66
+ * parent test context. Other hooks allow customizing fixture creation, document reference creation,
67
+ * instance construction, initialization, and cleanup.
38
68
  */
39
69
  export interface ModelTestContextFactoryParams<T, D extends FirestoreDocument<T> = FirestoreDocument<T>, C = any, PI extends FirebaseAdminTestContext = FirebaseAdminTestContext, PF extends TestContextFixture<PI> = TestContextFixture<PI>, I extends ModelTestContextInstance<T, D, PI> = ModelTestContextInstance<T, D, PI>, F extends ModelTestContextFixture<T, D, PI, PF, I> = ModelTestContextFixture<T, D, PI, PF, I>, CL extends FirestoreCollectionLike<T, D> = FirestoreCollectionLike<T, D>> {
40
70
  /**
@@ -70,16 +100,38 @@ export interface ModelTestContextFactoryParams<T, D extends FirestoreDocument<T>
70
100
  */
71
101
  destroyInstance?(instance: I): PromiseOrValue<void>;
72
102
  }
103
+ /**
104
+ * Alternative params for {@link modelTestContextFactory} that supplies a pre-existing document
105
+ * instead of creating a new one. When used, the factory skips document creation and
106
+ * `initDocument`, and instead wraps the provided document.
107
+ *
108
+ * Requires `collectionForDocument` to be set in {@link ModelTestContextFactoryParams} so the
109
+ * factory can resolve the collection for the given document.
110
+ */
73
111
  export interface ModelTestContextDocumentRefParams<D extends FirestoreDocument<any> = FirestoreDocument<any>> {
74
112
  /**
75
113
  * Custom document to use that is already initialized.
76
114
  */
77
115
  readonly doc: AsyncGetterOrValue<D>;
78
116
  }
117
+ /**
118
+ * Runtime parameters passed when invoking a model test context factory.
119
+ *
120
+ * Always includes the parent fixture (`f`). The remaining fields come from either the
121
+ * custom config type `C` (for new document creation) or {@link ModelTestContextDocumentRefParams}
122
+ * (for wrapping an existing document).
123
+ */
79
124
  export type ModelTestContextParams<C = any, PI extends FirebaseAdminTestContext = FirebaseAdminTestContext, PF extends TestContextFixture<PI> = TestContextFixture<PI>> = {
80
125
  f: PF;
81
126
  } & (C | ModelTestContextDocumentRefParams);
82
127
  /**
83
- * Creates a new Test Context that has a random user for authorization for use in firebase server tests.
128
+ * Creates a reusable factory function that sets up a {@link ModelTestContextFixture} for a specific
129
+ * Firestore model type within Jest test suites.
130
+ *
131
+ * The returned factory, when called with params and a `buildTests` callback, registers `beforeEach`/`afterEach`
132
+ * hooks that create a new document (or wrap an existing one via {@link ModelTestContextDocumentRefParams}),
133
+ * build the test context instance, optionally initialize the document, and clean up after each test.
134
+ *
135
+ * @see {@link ModelTestContextFactoryParams} for configuration options
84
136
  */
85
137
  export declare function modelTestContextFactory<T, D extends FirestoreDocument<T> = FirestoreDocument<T>, C = any, PI extends FirebaseAdminTestContext = FirebaseAdminTestContext, PF extends TestContextFixture<PI> = TestContextFixture<PI>, I extends ModelTestContextInstance<T, D, PI> = ModelTestContextInstance<T, D, PI>, F extends ModelTestContextFixture<T, D, PI, PF, I> = ModelTestContextFixture<T, D, PI, PF, I>, CL extends FirestoreCollectionLike<T, D> = FirestoreCollectionLike<T, D>>(config: ModelTestContextFactoryParams<T, D, C, PI, PF, I, F, CL>): (params: ModelTestContextParams<C, PI, PF>, buildTests: (u: F) => void) => void;
@@ -7,8 +7,20 @@ import { type FirebaseAdminCloudFunctionWrapper, type FirebaseAdminCloudFunction
7
7
  import { type Storage as GoogleCloudStorage } from '@google-cloud/storage';
8
8
  import { GoogleCloudTestFirebaseStorageInstance } from '../storage/storage';
9
9
  import { type Auth } from 'firebase-admin/auth';
10
+ /**
11
+ * Configuration for creating a {@link FirebaseAdminTestContextInstance}.
12
+ *
13
+ * Currently empty but exists as an extension point for future per-test configuration.
14
+ */
10
15
  export interface FirebaseAdminTestConfig {
11
16
  }
17
+ /**
18
+ * Provides access to all Firebase Admin services needed during testing.
19
+ *
20
+ * Implementations expose the Admin app, authentication, Firestore, and Cloud Storage
21
+ * along with their corresponding test driver instances and contexts. Also extends
22
+ * {@link FirebaseAdminCloudFunctionWrapperSource} for wrapping Cloud Functions in tests.
23
+ */
12
24
  export interface FirebaseAdminTestContext extends FirebaseAdminCloudFunctionWrapperSource {
13
25
  readonly app: admin.app.App;
14
26
  readonly auth: Auth;
@@ -19,6 +31,13 @@ export interface FirebaseAdminTestContext extends FirebaseAdminCloudFunctionWrap
19
31
  readonly storageInstance: TestFirebaseStorageInstance;
20
32
  readonly storageContext: TestFirebaseStorageContext;
21
33
  }
34
+ /**
35
+ * Test fixture that implements {@link FirebaseAdminTestContext} by forwarding all property access
36
+ * to the underlying {@link FirebaseAdminTestContextInstance}.
37
+ *
38
+ * Used with {@link firebaseAdminTestBuilder} to provide a stable reference that persists across
39
+ * the setup/teardown lifecycle while the inner instance is created and destroyed per test suite.
40
+ */
22
41
  export declare class FirebaseAdminTestContextFixture extends AbstractTestContextFixture<FirebaseAdminTestContextInstance> implements FirebaseAdminTestContext {
23
42
  get app(): admin.app.App;
24
43
  get auth(): Auth;
@@ -30,6 +49,17 @@ export declare class FirebaseAdminTestContextFixture extends AbstractTestContext
30
49
  get storageContext(): TestFirebaseStorageContext;
31
50
  get fnWrapper(): FirebaseAdminCloudFunctionWrapper;
32
51
  }
52
+ /**
53
+ * Wraps a `firebase-admin` {@link admin.app.App} and lazily creates test driver instances
54
+ * for Firestore and Cloud Storage.
55
+ *
56
+ * Each instance initializes its own Admin app with a unique project ID, ensuring test isolation
57
+ * when running against Firebase emulators. The Firestore and Storage test instances are created
58
+ * on first access via {@link cachedGetter} so they are only allocated when actually needed.
59
+ *
60
+ * @throws Error if {@link fnWrapper} is accessed, since Cloud Function wrapping requires a
61
+ * subclass (such as one provided by `firebase-functions-test`).
62
+ */
33
63
  export declare class FirebaseAdminTestContextInstance implements FirebaseAdminTestContext {
34
64
  readonly app: admin.app.App;
35
65
  readonly getTestFirestoreInstance: import("@dereekb/util").CachedFactoryWithInput<GoogleCloudTestFirestoreInstance, unknown>;
@@ -44,6 +74,15 @@ export declare class FirebaseAdminTestContextInstance implements FirebaseAdminTe
44
74
  get storageContext(): TestFirebaseStorageContext;
45
75
  get fnWrapper(): FirebaseAdminCloudFunctionWrapper;
46
76
  }
77
+ /**
78
+ * Base class for child test context instances that extend a {@link FirebaseAdminTestContextInstance}.
79
+ *
80
+ * Forwards all {@link FirebaseAdminTestContext} properties to the `parent` instance, allowing
81
+ * subclasses to layer additional behavior (e.g., Cloud Function wrapping, custom auth setup)
82
+ * while reusing the parent's Admin app and emulator connections.
83
+ *
84
+ * @typeParam F - The parent instance type, defaults to {@link FirebaseAdminTestContextInstance}.
85
+ */
47
86
  export declare abstract class AbstractFirebaseAdminTestContextInstanceChild<F extends FirebaseAdminTestContextInstance = FirebaseAdminTestContextInstance> implements FirebaseAdminTestContext {
48
87
  readonly parent: F;
49
88
  constructor(parent: F);
@@ -64,6 +103,20 @@ export declare abstract class AbstractFirebaseAdminTestContextInstanceChild<F ex
64
103
  */
65
104
  export declare const firebaseAdminTestBuilder: import("@dereekb/util/test").TestContextBuilderFunction<FirebaseAdminTestContextInstance, FirebaseAdminTestContextFixture, FirebaseAdminTestConfig>;
66
105
  export type FirebaseAdminTestContextFactory = TestContextFactory<FirebaseAdminTestContextFixture>;
106
+ /**
107
+ * Default {@link FirebaseAdminTestContextFactory} created with an empty config.
108
+ *
109
+ * Use this to quickly set up a Firebase Admin test context in your test suites:
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * firebaseAdminTestContextFactory((f) => {
114
+ * it('should access firestore', () => {
115
+ * expect(f.firestore).toBeDefined();
116
+ * });
117
+ * });
118
+ * ```
119
+ */
67
120
  export declare const firebaseAdminTestContextFactory: FirebaseAdminTestContextFactory;
68
121
  /**
69
122
  * Convenience function to build a TestFirestoreContextFactory from a FirebaseAdminTestContextFactory.
@@ -74,4 +127,15 @@ export declare const firebaseAdminTestContextFactory: FirebaseAdminTestContextFa
74
127
  * @returns
75
128
  */
76
129
  export declare function firebaseAdminFirestoreContextFixture(factory: TestContextFactory<TestContextFixture<FirebaseAdminTestContextInstance>>): JestTestFirestoreContextFactory;
130
+ /**
131
+ * Sets up a {@link TestFirestoreContextFixture} as a child context within an existing
132
+ * {@link FirebaseAdminTestContextInstance} fixture.
133
+ *
134
+ * Unlike {@link firebaseAdminFirestoreContextFixture}, this function operates directly on a fixture
135
+ * reference rather than a factory, making it suitable for composing Firestore tests inside a
136
+ * `describe` block that already has a Firebase Admin context available.
137
+ *
138
+ * @param f - The parent fixture providing the Admin test context instance.
139
+ * @param buildTests - Callback that receives the Firestore fixture and registers test cases.
140
+ */
77
141
  export declare function firebaseAdminFirestoreContextWithFixture(f: TestContextFixture<FirebaseAdminTestContextInstance>, buildTests: BuildTestsWithContextFunction<TestFirestoreContextFixture>): void;
@@ -6,7 +6,29 @@ import { type TestFirebaseStorageContext, type TestFirebaseStorageInstance, type
6
6
  import { AbstractTestContextFixture, type TestContextFactory, type TestContextFixture } from '@dereekb/util/test';
7
7
  import { type FirebaseAdminTestContext, FirebaseAdminTestContextInstance } from './firebase.admin';
8
8
  import { type Storage as GoogleCloudStorage } from '@google-cloud/storage';
9
+ /**
10
+ * Initializes (or re-initializes) the firebase-functions-test singleton used by all admin function tests.
11
+ *
12
+ * Must be called after {@link initFirebaseAdminTestEnvironment}. When `reroll` is true, a fresh
13
+ * GCloud project ID is generated so successive test suites run against isolated projects.
14
+ *
15
+ * @param reroll - When `true`, generates a new project ID instead of reusing the current one.
16
+ * @returns The initialized {@link FeaturesList} singleton.
17
+ *
18
+ * @throws Error if `initFirebaseAdminTestEnvironment()` has not been called.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * setupFirebaseAdminFunctionTestSingleton();
23
+ * ```
24
+ */
9
25
  export declare function setupFirebaseAdminFunctionTestSingleton(reroll?: boolean): FeaturesList;
26
+ /**
27
+ * Convenience wrapper around {@link setupFirebaseAdminFunctionTestSingleton} that always generates
28
+ * a new GCloud project ID, ensuring complete isolation between test runs.
29
+ *
30
+ * @returns The re-initialized {@link FeaturesList} singleton.
31
+ */
10
32
  export declare function rerollFirebaseAdminFunctionTestSingleton(): FeaturesList;
11
33
  export interface FirebaseAdminFunctionTestConfig {
12
34
  /**
@@ -18,9 +40,30 @@ export interface FirebaseAdminFunctionTestConfig {
18
40
  */
19
41
  useFunctionSingletonContext: boolean;
20
42
  }
43
+ /**
44
+ * Test context type for Firebase Admin function tests.
45
+ *
46
+ * Currently an alias for {@link FirebaseAdminTestContext}; exists as a semantic boundary
47
+ * so function-specific extensions can be added without changing downstream signatures.
48
+ */
21
49
  export type FirebaseAdminFunctionTestContext = FirebaseAdminTestContext;
50
+ /**
51
+ * Combined interface providing both the {@link FirebaseAdminFunctionTestContext} services
52
+ * and the {@link TestContextFixture} lifecycle for a {@link FirebaseAdminFunctionTestContextInstance}.
53
+ *
54
+ * Useful when test helpers need access to both the Firebase services and the fixture's
55
+ * `instance` / `parent` references in a single type constraint.
56
+ */
22
57
  export interface FullFirebaseAdminFunctionTestContext extends FirebaseAdminFunctionTestContext, TestContextFixture<FirebaseAdminFunctionTestContextInstance> {
23
58
  }
59
+ /**
60
+ * Fixture that wraps a {@link FirebaseAdminFunctionTestContextInstance} and forwards
61
+ * all {@link FirebaseAdminFunctionTestContext} properties to the underlying instance.
62
+ *
63
+ * Created automatically by {@link firebaseAdminFunctionTestBuilder}; tests receive this
64
+ * fixture and use it to access the Firebase Admin app, Firestore, Auth, Storage, and the
65
+ * firebase-functions-test wrapper during each test lifecycle.
66
+ */
24
67
  export declare class FirebaseAdminFunctionTestContextFixture extends AbstractTestContextFixture<FirebaseAdminFunctionTestContextInstance> implements FirebaseAdminFunctionTestContext {
25
68
  get app(): admin.app.App;
26
69
  get auth(): Auth;
@@ -32,13 +75,37 @@ export declare class FirebaseAdminFunctionTestContextFixture extends AbstractTes
32
75
  get storageContext(): TestFirebaseStorageContext;
33
76
  get fnWrapper(): import("./firebase.function").FirebaseAdminCloudFunctionWrapper;
34
77
  }
78
+ /**
79
+ * Concrete instance that extends {@link FirebaseAdminTestContextInstance} with the
80
+ * firebase-functions-test {@link FeaturesList} needed to wrap and invoke Cloud Functions
81
+ * in an emulated environment.
82
+ *
83
+ * Each instance holds a lazily-created {@link FirebaseAdminCloudFunctionWrapper} via `fnWrapper`
84
+ * so Cloud Functions can be wrapped and invoked against the test project.
85
+ */
35
86
  export declare class FirebaseAdminFunctionTestContextInstance extends FirebaseAdminTestContextInstance implements FirebaseAdminFunctionTestContext {
36
87
  readonly instance: FeaturesList;
37
88
  private _fnWrapper;
38
89
  constructor(instance: FeaturesList, app: admin.app.App);
39
90
  get fnWrapper(): import("./firebase.function").FirebaseAdminCloudFunctionWrapper;
40
91
  }
92
+ /**
93
+ * Module-level default for {@link FirebaseAdminFunctionTestConfig.useFunctionSingletonContext}.
94
+ *
95
+ * When `false` (the default), each test suite gets its own firebase-functions-test instance
96
+ * with a unique project ID. Change via {@link setDefaultFirebaseAdminFunctionTestUseFunctionSingleton}.
97
+ */
41
98
  export declare let DEFAULT_FIREBASE_ADMIN_FUNCTION_TEST_USE_FUNCTION_SINGLETON_CONTEXT: boolean;
99
+ /**
100
+ * Globally sets whether new {@link FirebaseAdminFunctionTestConfig} instances default to
101
+ * singleton mode. Primarily used in global test setup files.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * // in jest globalSetup
106
+ * setDefaultFirebaseAdminFunctionTestUseFunctionSingleton(true);
107
+ * ```
108
+ */
42
109
  export declare function setDefaultFirebaseAdminFunctionTestUseFunctionSingleton(use: boolean): void;
43
110
  /**
44
111
  * A TestContextBuilderFunction for building firebase test context factories using firebase-admin.
@@ -46,5 +113,22 @@ export declare function setDefaultFirebaseAdminFunctionTestUseFunctionSingleton(
46
113
  * This can be used to easily build a testing context that sets up RulesTestEnvironment for tests that sets itself up and tears itself down.
47
114
  */
48
115
  export declare const firebaseAdminFunctionTestBuilder: import("@dereekb/util/test").TestContextBuilderFunction<FirebaseAdminTestContextInstance, FirebaseAdminFunctionTestContextFixture, FirebaseAdminFunctionTestConfig>;
116
+ /**
117
+ * Factory type that produces a {@link FirebaseAdminFunctionTestContextFixture} for each test suite.
118
+ */
49
119
  export type FirebaseAdminFunctionTestContextFactory = TestContextFactory<FirebaseAdminFunctionTestContextFixture>;
120
+ /**
121
+ * Pre-built factory using default configuration. Drop this into any test file to get
122
+ * a fully configured Firebase Admin + functions test context with automatic setup/teardown.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * firebaseAdminFunctionTestContextFactory((f) => {
127
+ * it('should invoke cloud function', async () => {
128
+ * const app = f.app;
129
+ * // ... test logic
130
+ * });
131
+ * });
132
+ * ```
133
+ */
50
134
  export declare const firebaseAdminFunctionTestContextFactory: FirebaseAdminFunctionTestContextFactory;