@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
@@ -1,28 +1,58 @@
1
1
  import { type NestMiddleware } from '@nestjs/common';
2
2
  import { type Request } from 'firebase-functions/v2/https';
3
3
  import { type Response } from 'express';
4
- import { type Maybe } from '@dereekb/util';
5
- import { GlobalRoutePrefixConfig } from './globalprefix';
4
+ import { type SlashPath, type Maybe } from '@dereekb/util';
5
+ /**
6
+ * Configuration for `FirebaseAppCheckMiddleware`.
7
+ *
8
+ * Controls which paths are excluded from AppCheck verification at the
9
+ * middleware consumer level via `.forRoutes()` and `.exclude()`.
10
+ */
11
+ export declare abstract class FirebaseAppCheckMiddlewareConfig {
12
+ /**
13
+ * Whether to protect webhook paths under the global route prefix.
14
+ *
15
+ * When false (default), paths like `/api/webhook/*` are excluded from AppCheck.
16
+ *
17
+ * Defaults to false, otherwise webhook calls would be rejected.
18
+ */
19
+ readonly protectGlobalWebhooksPath?: boolean;
20
+ /**
21
+ * Whether to protect paths outside the global route prefix.
22
+ *
23
+ * When false (default), only paths under the global prefix (e.g., `/api/*`) are protected.
24
+ * Paths like `/.well-known/*` or `/oidc/*` are not checked.
25
+ *
26
+ * Defaults to false, otherwise non-global paths would be rejected.
27
+ */
28
+ readonly protectNonGlobalPaths?: boolean;
29
+ /**
30
+ * Additional path patterns to protect with AppCheck verification.
31
+ *
32
+ * Each entry is a path prefix (e.g., '/health') that will be added
33
+ * to the protected routes. The global route prefix itself (e.g., '/api')
34
+ * is not allowed as a value since it is always protected.
35
+ *
36
+ * Defaults to an empty array.
37
+ */
38
+ readonly protectedPaths?: SlashPath[];
39
+ }
6
40
  /**
7
41
  * Middleware that verifies the X-Firebase-AppCheck header using admin.
8
42
  *
9
- * It ignores all webhook paths by default.
43
+ * Route-level exclusions (webhooks, non-global paths, custom paths) are
44
+ * handled by `ConfigureFirebaseAppCheckMiddlewareModule` via `.forRoutes()`
45
+ * and `.exclude()`. This middleware only checks the per-request `skipAppCheck`
46
+ * flag (set by the `@SkipAppCheck()` decorator) at runtime.
10
47
  */
11
48
  export declare class FirebaseAppCheckMiddleware implements NestMiddleware {
12
- private readonly globalRoutePrefixConfig?;
13
49
  private readonly logger;
14
- private readonly _ignoredWebhookPath;
15
- constructor(globalRoutePrefixConfig?: Maybe<GlobalRoutePrefixConfig>);
16
- use(req: Request, res: Response, next: (error?: Error | unknown) => void): Promise<void>;
17
- isIgnoredRequest(req: Request): boolean;
18
- isIgnoredPath(path: string): boolean;
50
+ use(req: Request, _res: Response, next: (error?: Error | unknown) => void): Promise<void>;
19
51
  }
20
52
  /**
21
- * Verifies the AppCheck parameter. If it fails, a value is returned.
53
+ * Verifies the `X-Firebase-AppCheck` header using Firebase Admin AppCheck.
22
54
  *
23
- * @param req
24
- * @param res
25
- * @param next
26
- * @returns
55
+ * @param req - The incoming request to verify.
56
+ * @returns A {@link ForbiddenException} if verification fails, or `undefined` if it passes.
27
57
  */
28
58
  export declare function verifyAppCheckInRequest(req: Request): Promise<Maybe<Error>>;
@@ -1,8 +1,17 @@
1
1
  import { type MiddlewareConsumer } from '@nestjs/common';
2
+ import { FirebaseAppCheckMiddlewareConfig } from './appcheck.middleware';
3
+ import { GlobalRoutePrefixConfig } from './globalprefix';
2
4
  /**
3
- * Convenience class that mirrors the ConfigureAppCheckMiddlewareModule class in @dereekb/nestjs, but for Firebase apps.
5
+ * Middleware module that configures `FirebaseAppCheckMiddleware` route coverage
6
+ * based on `FirebaseAppCheckMiddlewareConfig` and `GlobalRoutePrefixConfig`.
7
+ *
8
+ * Uses `.forRoutes()` and `.exclude()` to control which paths require AppCheck,
9
+ * so the middleware itself only needs to handle the per-request `skipAppCheck` flag.
4
10
  */
5
11
  export declare class ConfigureFirebaseAppCheckMiddlewareModule {
12
+ private readonly globalRoutePrefixConfig?;
13
+ private readonly config?;
6
14
  private readonly logger;
15
+ constructor(globalRoutePrefixConfig?: GlobalRoutePrefixConfig | undefined, config?: FirebaseAppCheckMiddlewareConfig | undefined);
7
16
  configure(consumer: MiddlewareConsumer): void;
8
17
  }
@@ -1,7 +1,35 @@
1
- import { type Maybe } from '@dereekb/util';
1
+ import { type MaybeSo, type Maybe } from '@dereekb/util';
2
+ import { type INestApplication } from '@nestjs/common';
2
3
  /**
3
- * Can be injected to retrieve information about the global prefix configured for the app.
4
+ * Configuration options accepted by NestJS `setGlobalPrefix()`, with all properties made required (non-optional).
5
+ *
6
+ * Derived from the second parameter of {@link INestApplication.setGlobalPrefix}.
4
7
  */
5
- export declare abstract class GlobalRoutePrefixConfig {
8
+ export type NestGlobalRoutePrefixConfig = MaybeSo<Parameters<INestApplication['setGlobalPrefix']>[1]>;
9
+ /**
10
+ * Route exclusion patterns from {@link NestGlobalRoutePrefixConfig}.
11
+ *
12
+ * Used to specify routes that should bypass the global prefix (e.g., webhook endpoints, health checks).
13
+ */
14
+ export type NestGlobalRoutePrefixConfigExclude = NestGlobalRoutePrefixConfig['exclude'];
15
+ /**
16
+ * Injectable configuration that exposes the global route prefix and exclusion rules for the NestJS application.
17
+ *
18
+ * Provided at the module level so that middleware, guards, and other components can read the prefix
19
+ * without coupling to the bootstrap code. Used by {@link buildNestServerRootModule} to wire up the prefix
20
+ * consistently across production and test environments.
21
+ *
22
+ * @see https://docs.nestjs.com/faq/global-prefix
23
+ */
24
+ export declare abstract class GlobalRoutePrefixConfig implements NestGlobalRoutePrefixConfig {
25
+ /**
26
+ * The global API route prefix applied to all controllers (e.g., `"api"`).
27
+ *
28
+ * When set, all controller routes are mounted under this prefix unless explicitly excluded.
29
+ */
6
30
  readonly globalApiRoutePrefix?: Maybe<string>;
31
+ /**
32
+ * Routes excluded from the global prefix, such as webhook endpoints or health checks.
33
+ */
34
+ readonly exclude?: NestGlobalRoutePrefixConfig['exclude'];
7
35
  }
@@ -1,6 +1,7 @@
1
1
  export * from './appcheck';
2
+ export * from './globalprefix';
2
3
  export * from './appcheck.middleware';
3
4
  export * from './appcheck.module';
4
5
  export * from './appcheck.decorator';
5
6
  export * from './rawbody.middleware';
6
- export * from './webhook';
7
+ export * from './webhook.module';
@@ -1,6 +1,12 @@
1
1
  import { type NestMiddleware } from '@nestjs/common';
2
2
  import { type Request } from 'firebase-functions/v2/https';
3
3
  import { type Response } from 'express';
4
+ /**
5
+ * Middleware that replaces `req.body` with `req.rawBody` for routes that need the unparsed request body.
6
+ *
7
+ * Used by webhook routes to support signature verification (e.g., Stripe, Mailgun) where
8
+ * the raw body must match the signed payload exactly.
9
+ */
4
10
  export declare class FirebaseRawBodyMiddleware implements NestMiddleware {
5
11
  use(req: Request, res: Response, next: () => void): void;
6
12
  }
@@ -4,28 +4,94 @@ import { type OnCallWithAuthAwareNestContext, type OnCallWithAuthAwareNestRequir
4
4
  import { type AssertModelCrudRequestFunctionContextCrudType, type AssertModelCrudRequestFunction } from './crud.assert.function';
5
5
  import { type NestContextCallableRequest } from '../function/nest';
6
6
  import { type OnCallApiDetailsRef } from './api.details';
7
+ /**
8
+ * Maps CRUD call type strings (e.g., 'create', 'read', 'update', 'delete') to their
9
+ * corresponding handler functions.
10
+ *
11
+ * Used by {@link onCallModel} to dispatch incoming requests to the correct CRUD handler.
12
+ */
7
13
  export type OnCallModelMap = {
8
14
  readonly [call: OnCallFunctionType]: OnCallWithNestContext<any, OnCallTypedModelParams>;
9
15
  };
16
+ /**
17
+ * Configuration for {@link onCallModel}.
18
+ *
19
+ * Allows injecting a pre-assertion hook that runs before any CRUD handler is invoked,
20
+ * useful for cross-cutting concerns like rate limiting or feature flags.
21
+ */
10
22
  export interface OnCallModelConfig {
23
+ /**
24
+ * Optional assertion function invoked before dispatching to the CRUD handler.
25
+ * Throw to reject the request.
26
+ */
11
27
  readonly preAssert?: AssertModelCrudRequestFunction<unknown, OnCallTypedModelParams>;
12
28
  }
13
29
  /**
14
- * Creates a OnCallWithAuthorizedNestContext function for creating a model.
30
+ * Top-level factory that creates a single callable function dispatching to CRUD operations.
15
31
  *
16
- * @param map
17
- * @returns
32
+ * Incoming requests carry a `call` field (e.g., 'create', 'read') that selects the
33
+ * appropriate handler from the provided map. API details from all handlers are aggregated
34
+ * for MCP tool generation.
35
+ *
36
+ * @param map - Maps call type strings to their CRUD handler functions.
37
+ * @param config - Optional configuration including a pre-assertion hook.
38
+ * @returns A callable function that dispatches to the correct CRUD handler, with aggregated {@link OnCallApiDetailsRef._apiDetails}.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const callModel = onCallModel({
43
+ * create: onCallCreateModel({ profile: createProfile, guestbook: createGuestbook }),
44
+ * read: onCallReadModel({ profile: readProfile }),
45
+ * update: onCallUpdateModel({ profile: updateProfile }),
46
+ * delete: onCallDeleteModel({ guestbook: deleteGuestbook })
47
+ * });
48
+ * ```
18
49
  */
19
50
  export declare function onCallModel(map: OnCallModelMap, config?: OnCallModelConfig): OnCallWithNestContext<unknown, OnCallTypedModelParams> & OnCallApiDetailsRef;
51
+ /**
52
+ * Creates a bad-request error indicating the `call` field was missing from the request payload.
53
+ */
20
54
  export declare function onCallModelMissingCallTypeError(): import("firebase-functions/https").HttpsError;
55
+ /**
56
+ * Creates a bad-request error indicating the provided `call` type is not recognized.
57
+ */
21
58
  export declare function onCallModelUnknownCallTypeError(call: OnCallFunctionType): import("firebase-functions/https").HttpsError;
59
+ /**
60
+ * Maps Firestore model type strings to their handler functions for a single CRUD operation.
61
+ *
62
+ * Each handler receives the NestContext request and an optional specifier, and may
63
+ * declare whether it requires authentication via {@link OnCallWithAuthAwareNestRequireAuthRef}.
64
+ *
65
+ * @typeParam N - The NestJS context type.
66
+ * @typeParam T - The Firestore model identity constraining which model type keys are valid.
67
+ */
22
68
  export type OnCallWithCallTypeModelMap<N, T extends FirestoreModelIdentity = FirestoreModelIdentity> = {
23
69
  readonly [K in FirestoreModelTypes<T>]?: ((request: NestContextCallableRequest<N, any> & ModelFirebaseCrudFunctionSpecifierRef) => PromiseOrValue<any>) & OnCallWithAuthAwareNestRequireAuthRef;
24
70
  };
71
+ /**
72
+ * Internal configuration for {@link _onCallWithCallTypeFunction}.
73
+ *
74
+ * Shared by the CRUD-specific factories (create, read, update, delete) to avoid
75
+ * duplicating dispatch and assertion logic.
76
+ *
77
+ * @typeParam N - The NestJS context type.
78
+ */
25
79
  export interface OnCallWithCallTypeModelConfig<N> {
80
+ /** The call type string (e.g., 'create', 'read') passed through to assertions. */
26
81
  readonly callType: string;
82
+ /** The CRUD category used by {@link AssertModelCrudRequestFunction}. */
27
83
  readonly crudType: AssertModelCrudRequestFunctionContextCrudType;
84
+ /** Optional assertion run before the model handler; throw to reject. */
28
85
  readonly preAssert?: AssertModelCrudRequestFunction<N, OnCallTypedModelParams>;
86
+ /** Error factory invoked when the requested model type has no handler in the map. */
29
87
  readonly throwOnUnknownModelType: (modelType: FirestoreModelType) => Error;
30
88
  }
89
+ /**
90
+ * Internal factory used by the CRUD-specific wrappers ({@link onCallCreateModel}, {@link onCallReadModel}, etc.).
91
+ *
92
+ * Dispatches to the correct model-type handler from the map, enforces auth requirements,
93
+ * runs pre-assertions, and aggregates API details from all handlers for MCP introspection.
94
+ *
95
+ * @internal Not intended for direct use outside the model CRUD module.
96
+ */
31
97
  export declare function _onCallWithCallTypeFunction<N>(map: OnCallWithCallTypeModelMap<N>, config: OnCallWithCallTypeModelConfig<N>): OnCallWithAuthAwareNestContext<N, OnCallTypedModelParams, unknown> & OnCallApiDetailsRef;
@@ -3,21 +3,87 @@ import { type FirestoreModelType, type FirestoreModelIdentity, type FirestoreMod
3
3
  import { type OnCallWithAuthAwareNestRequireAuthRef, type OnCallWithNestContext } from '../function/call';
4
4
  import { type NestContextCallableRequestWithOptionalAuth, type NestContextCallableRequestWithAuth } from '../function/nest';
5
5
  import { type AssertModelCrudRequestFunction } from './crud.assert.function';
6
+ /**
7
+ * Request type for model create handlers that require authentication.
8
+ *
9
+ * Combines the authenticated NestJS context with the optional CRUD function specifier,
10
+ * allowing handlers to access both auth data and identify sub-operations.
11
+ *
12
+ * @typeParam N - The NestJS context type.
13
+ * @typeParam I - The input data type for the create operation.
14
+ */
6
15
  export type OnCallCreateModelRequest<N, I = unknown> = NestContextCallableRequestWithAuth<N, I> & ModelFirebaseCrudFunctionSpecifierRef;
16
+ /**
17
+ * A model create handler function that requires an authenticated caller.
18
+ *
19
+ * @typeParam N - The NestJS context type.
20
+ * @typeParam I - The input data type for the create operation.
21
+ * @typeParam O - The output type returned on success.
22
+ */
7
23
  export type OnCallCreateModelFunctionWithAuth<N, I = unknown, O = unknown> = ((request: OnCallCreateModelRequest<N, I>) => PromiseOrValue<O>) & {
8
24
  readonly _requiresAuth?: true;
9
25
  };
26
+ /**
27
+ * Request type for model create handlers that allow unauthenticated callers.
28
+ */
10
29
  export type OnCallCreateModelRequestWithOptionalAuth<N, I = unknown> = NestContextCallableRequestWithOptionalAuth<N, I> & ModelFirebaseCrudFunctionSpecifierRef;
30
+ /**
31
+ * A model create handler function that does not require authentication.
32
+ *
33
+ * Useful for public-facing creation endpoints such as anonymous sign-up flows.
34
+ */
11
35
  export type OnCallCreateModelFunctionWithOptionalAuth<N, I = unknown, O = unknown> = ((request: OnCallCreateModelRequestWithOptionalAuth<N, I>) => PromiseOrValue<O>) & {
12
36
  readonly _requireAuth: false;
13
37
  };
38
+ /**
39
+ * Standard model create handler requiring auth (the common case).
40
+ */
14
41
  export type OnCallCreateModelFunction<N, I = unknown, O extends OnCallCreateModelResult = OnCallCreateModelResult> = OnCallCreateModelFunctionWithAuth<N, I, O> & OnCallWithAuthAwareNestRequireAuthRef;
42
+ /**
43
+ * Union of auth-required and optional-auth create handlers.
44
+ *
45
+ * Used in {@link OnCallCreateModelMap} so both variants can be registered side by side.
46
+ */
15
47
  export type OnCallCreateModelFunctionAuthAware<N, I = unknown, O extends OnCallCreateModelResult = OnCallCreateModelResult> = OnCallCreateModelFunction<N, I, O> | OnCallCreateModelFunctionWithOptionalAuth<N, I, O>;
48
+ /**
49
+ * Maps Firestore model type strings to their create handler functions.
50
+ *
51
+ * Pass this map to {@link onCallCreateModel} to register all model types
52
+ * that support creation through the call model system.
53
+ *
54
+ * @typeParam N - The NestJS context type.
55
+ * @typeParam T - The Firestore model identity constraining valid model type keys.
56
+ */
16
57
  export type OnCallCreateModelMap<N, T extends FirestoreModelIdentity = FirestoreModelIdentity> = {
17
58
  readonly [K in FirestoreModelTypes<T>]?: OnCallCreateModelFunctionAuthAware<N, any, OnCallCreateModelResult>;
18
59
  };
60
+ /**
61
+ * Configuration for {@link onCallCreateModel}.
62
+ */
19
63
  export interface OnCallCreateModelConfig<N> {
64
+ /** Optional assertion run before the create handler; throw to reject. */
20
65
  readonly preAssert?: AssertModelCrudRequestFunction<N, OnCallCreateModelParams>;
21
66
  }
67
+ /**
68
+ * Factory that creates a callable function handling model creation for multiple model types.
69
+ *
70
+ * Dispatches to the correct handler based on the `modelType` field in the request,
71
+ * enforces auth requirements per handler, and aggregates API details for MCP introspection.
72
+ *
73
+ * @param map - Maps model type strings to their create handler functions.
74
+ * @param config - Optional configuration including a pre-assertion hook.
75
+ * @returns A callable function for the 'create' CRUD operation.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const createHandler = onCallCreateModel<DemoNestContext>({
80
+ * profile: createProfile,
81
+ * guestbook: createGuestbook
82
+ * });
83
+ * ```
84
+ */
22
85
  export declare function onCallCreateModel<N>(map: OnCallCreateModelMap<N>, config?: OnCallCreateModelConfig<N>): OnCallWithNestContext<N, OnCallCreateModelParams, OnCallCreateModelResult>;
86
+ /**
87
+ * Creates a bad-request error indicating the requested model type is not valid for creation.
88
+ */
23
89
  export declare function createModelUnknownModelTypeError(modelType: FirestoreModelType): import("firebase-functions/https").HttpsError;
@@ -1,14 +1,40 @@
1
1
  import { type Maybe } from '@dereekb/util';
2
2
  import { type NestContextCallableRequest } from '../function/nest';
3
3
  import { type OnCallFunctionType } from '@dereekb/firebase';
4
+ /**
5
+ * Discriminator for the category of CRUD operation being asserted.
6
+ *
7
+ * Used by {@link AssertModelCrudRequestFunction} to let assertions branch on operation type,
8
+ * enabling cross-cutting rules like "block all deletes for archived models."
9
+ */
4
10
  export type AssertModelCrudRequestFunctionContextCrudType = 'call' | 'create' | 'read' | 'update' | 'delete';
11
+ /**
12
+ * Context passed to a {@link AssertModelCrudRequestFunction} before a CRUD handler executes.
13
+ *
14
+ * Provides the original request alongside routing metadata (call type, model type, specifier)
15
+ * so assertions can make fine-grained decisions without parsing the raw request.
16
+ *
17
+ * @typeParam N - The NestJS context type.
18
+ * @typeParam I - The input data type of the request.
19
+ */
5
20
  export interface AssertModelCrudRequestFunctionContext<N, I = unknown> {
21
+ /** The original callable request including the NestJS context and caller data. */
6
22
  readonly request: NestContextCallableRequest<N, I>;
23
+ /** The CRUD call type string (e.g., 'create', 'read'). */
7
24
  readonly call: OnCallFunctionType;
25
+ /** The Firestore model type being targeted (e.g., 'profile', 'guestbook'). */
8
26
  readonly modelType: string;
27
+ /** The optional sub-operation specifier (e.g., 'username', 'fromUpload'). */
9
28
  readonly specifier: Maybe<string>;
10
29
  }
11
30
  /**
12
- * Function that asserts something given the input request.
31
+ * Pre-assertion hook invoked before a model CRUD handler executes.
32
+ *
33
+ * Throw an error to reject the request. Useful for cross-cutting concerns such as
34
+ * feature flags, rate limiting, or role-based access restrictions that apply
35
+ * across multiple model types or operations.
36
+ *
37
+ * @typeParam N - The NestJS context type.
38
+ * @typeParam I - The input data type of the request.
13
39
  */
14
40
  export type AssertModelCrudRequestFunction<N, I = unknown> = (context: AssertModelCrudRequestFunctionContext<N, I>) => void;
@@ -3,21 +3,76 @@ import { type FirestoreModelType, type FirestoreModelIdentity, type FirestoreMod
3
3
  import { type NestContextCallableRequestWithOptionalAuth, type NestContextCallableRequestWithAuth } from '../function/nest';
4
4
  import { type OnCallWithAuthAwareNestRequireAuthRef, type OnCallWithNestContext } from '../function/call';
5
5
  import { type AssertModelCrudRequestFunction } from './crud.assert.function';
6
+ /**
7
+ * Request type for model delete handlers that require authentication.
8
+ *
9
+ * @typeParam N - The NestJS context type.
10
+ * @typeParam I - The input data type for the delete operation.
11
+ */
6
12
  export type OnCallDeleteModelRequest<N, I = unknown> = NestContextCallableRequestWithAuth<N, I> & ModelFirebaseCrudFunctionSpecifierRef;
13
+ /**
14
+ * A model delete handler function that requires an authenticated caller.
15
+ */
7
16
  export type OnCallDeleteModelFunctionWithAuth<N, I = unknown, O = void> = ((request: OnCallDeleteModelRequest<N, I>) => PromiseOrValue<O>) & {
8
17
  readonly _requiresAuth?: true;
9
18
  };
19
+ /**
20
+ * Request type for model delete handlers that allow unauthenticated callers.
21
+ */
10
22
  export type OnCallDeleteModelRequestWithOptionalAuth<N, I = unknown> = NestContextCallableRequestWithOptionalAuth<N, I> & ModelFirebaseCrudFunctionSpecifierRef;
23
+ /**
24
+ * A model delete handler function that does not require authentication.
25
+ */
11
26
  export type OnCallDeleteModelFunctionWithOptionalAuth<N, I = unknown, O = void> = ((request: OnCallDeleteModelRequestWithOptionalAuth<N, I>) => PromiseOrValue<O>) & {
12
27
  readonly _requireAuth: false;
13
28
  };
29
+ /**
30
+ * Standard model delete handler requiring auth (the common case).
31
+ */
14
32
  export type OnCallDeleteModelFunction<N, I = unknown, O = void> = OnCallDeleteModelFunctionWithAuth<N, I, O> & OnCallWithAuthAwareNestRequireAuthRef;
33
+ /**
34
+ * Union of auth-required and optional-auth delete handlers.
35
+ */
15
36
  export type OnCallDeleteModelFunctionAuthAware<N, I = unknown, O = void> = OnCallDeleteModelFunction<N, I, O> | OnCallDeleteModelFunctionWithOptionalAuth<N, I, O>;
37
+ /**
38
+ * Maps Firestore model type strings to their delete handler functions.
39
+ *
40
+ * Pass this map to {@link onCallDeleteModel} to register all model types
41
+ * that support deletion through the call model system.
42
+ *
43
+ * @typeParam N - The NestJS context type.
44
+ * @typeParam T - The Firestore model identity constraining valid model type keys.
45
+ */
16
46
  export type OnCallDeleteModelMap<N, T extends FirestoreModelIdentity = FirestoreModelIdentity> = {
17
47
  readonly [K in FirestoreModelTypes<T>]?: OnCallDeleteModelFunctionAuthAware<N, any, any>;
18
48
  };
49
+ /**
50
+ * Configuration for {@link onCallDeleteModel}.
51
+ */
19
52
  export interface OnCallDeleteModelConfig<N> {
53
+ /** Optional assertion run before the delete handler; throw to reject. */
20
54
  readonly preAssert?: AssertModelCrudRequestFunction<N, OnCallDeleteModelParams>;
21
55
  }
56
+ /**
57
+ * Factory that creates a callable function handling model deletion for multiple model types.
58
+ *
59
+ * Dispatches to the correct handler based on the `modelType` field in the request,
60
+ * enforces auth requirements per handler, and aggregates API details for MCP introspection.
61
+ *
62
+ * @param map - Maps model type strings to their delete handler functions.
63
+ * @param config - Optional configuration including a pre-assertion hook.
64
+ * @returns A callable function for the 'delete' CRUD operation.
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const deleteHandler = onCallDeleteModel<DemoNestContext>({
69
+ * guestbook: deleteGuestbook,
70
+ * guestbookEntry: deleteGuestbookEntry
71
+ * });
72
+ * ```
73
+ */
22
74
  export declare function onCallDeleteModel<N>(map: OnCallDeleteModelMap<N>, config?: OnCallDeleteModelConfig<N>): OnCallWithNestContext<N, OnCallDeleteModelParams, unknown>;
75
+ /**
76
+ * Creates a bad-request error indicating the requested model type is not valid for deletion.
77
+ */
23
78
  export declare function deleteModelUnknownModelTypeError(modelType: FirestoreModelType): import("firebase-functions/https").HttpsError;
@@ -1,3 +1,18 @@
1
1
  import { type FirebaseDoesNotExistErrorContextErrorFunction, type FirebasePermissionErrorContextErrorFunction } from '@dereekb/firebase';
2
+ /**
3
+ * NestJS-compatible error factory for when a Firestore document does not exist.
4
+ *
5
+ * Returns a "model not available" HTTP error including the document key and model type,
6
+ * which the client can use to display a meaningful "not found" message. Intended to be
7
+ * passed to Firebase permission/existence checking utilities as the
8
+ * {@link FirebaseDoesNotExistErrorContextErrorFunction} callback.
9
+ */
2
10
  export declare const nestFirebaseDoesNotExistError: FirebaseDoesNotExistErrorContextErrorFunction;
11
+ /**
12
+ * NestJS-compatible error factory for when the caller lacks required roles on a Firestore document.
13
+ *
14
+ * Returns a "forbidden" HTTP error including the document key, model type, and the roles
15
+ * that were required but not granted. Intended to be passed to Firebase permission checking
16
+ * utilities as the {@link FirebasePermissionErrorContextErrorFunction} callback.
17
+ */
3
18
  export declare const nestFirebaseForbiddenPermissionError: FirebasePermissionErrorContextErrorFunction;
@@ -3,21 +3,78 @@ import { type FirestoreModelType, type FirestoreModelIdentity, type FirestoreMod
3
3
  import { type OnCallWithAuthAwareNestRequireAuthRef, type OnCallWithNestContext } from '../function/call';
4
4
  import { type NestContextCallableRequestWithAuth, type NestContextCallableRequestWithOptionalAuth } from '../function/nest';
5
5
  import { type AssertModelCrudRequestFunction } from './crud.assert.function';
6
+ /**
7
+ * Request type for model read handlers that require authentication.
8
+ *
9
+ * @typeParam N - The NestJS context type.
10
+ * @typeParam I - The input data type for the read operation.
11
+ */
6
12
  export type OnCallReadModelRequest<N, I = unknown> = NestContextCallableRequestWithAuth<N, I> & ModelFirebaseCrudFunctionSpecifierRef;
13
+ /**
14
+ * A model read handler function that requires an authenticated caller.
15
+ */
7
16
  export type OnCallReadModelFunctionWithAuth<N, I = unknown, O = unknown> = ((request: OnCallReadModelRequest<N, I>) => PromiseOrValue<O>) & {
8
17
  readonly _requiresAuth?: true;
9
18
  };
19
+ /**
20
+ * Request type for model read handlers that allow unauthenticated callers.
21
+ */
10
22
  export type OnCallReadModelRequestWithOptionalAuth<N, I = unknown> = NestContextCallableRequestWithOptionalAuth<N, I> & ModelFirebaseCrudFunctionSpecifierRef;
23
+ /**
24
+ * A model read handler function that does not require authentication.
25
+ *
26
+ * Useful for public-facing read endpoints such as listing public content.
27
+ */
11
28
  export type OnCallReadModelFunctionWithOptionalAuth<N, I = unknown, O = unknown> = ((request: OnCallReadModelRequestWithOptionalAuth<N, I>) => PromiseOrValue<O>) & {
12
29
  readonly _requireAuth: false;
13
30
  };
31
+ /**
32
+ * Standard model read handler requiring auth (the common case).
33
+ */
14
34
  export type OnCallReadModelFunction<N, I = unknown, O = unknown> = OnCallReadModelFunctionWithAuth<N, I, O> & OnCallWithAuthAwareNestRequireAuthRef;
35
+ /**
36
+ * Union of auth-required and optional-auth read handlers.
37
+ */
15
38
  export type OnCallReadModelFunctionAuthAware<N, I = unknown, O = unknown> = OnCallReadModelFunction<N, I, O> | OnCallReadModelFunctionWithOptionalAuth<N, I, O>;
39
+ /**
40
+ * Maps Firestore model type strings to their read handler functions.
41
+ *
42
+ * Pass this map to {@link onCallReadModel} to register all model types
43
+ * that support reading through the call model system.
44
+ *
45
+ * @typeParam N - The NestJS context type.
46
+ * @typeParam T - The Firestore model identity constraining valid model type keys.
47
+ */
16
48
  export type OnCallReadModelMap<N, T extends FirestoreModelIdentity = FirestoreModelIdentity> = {
17
49
  readonly [K in FirestoreModelTypes<T>]?: OnCallReadModelFunctionAuthAware<N, any, any>;
18
50
  };
51
+ /**
52
+ * Configuration for {@link onCallReadModel}.
53
+ */
19
54
  export interface OnCallReadModelConfig<N> {
55
+ /** Optional assertion run before the read handler; throw to reject. */
20
56
  readonly preAssert?: AssertModelCrudRequestFunction<N, OnCallReadModelParams>;
21
57
  }
58
+ /**
59
+ * Factory that creates a callable function handling model reads for multiple model types.
60
+ *
61
+ * Dispatches to the correct handler based on the `modelType` field in the request,
62
+ * enforces auth requirements per handler, and aggregates API details for MCP introspection.
63
+ *
64
+ * @param map - Maps model type strings to their read handler functions.
65
+ * @param config - Optional configuration including a pre-assertion hook.
66
+ * @returns A callable function for the 'read' CRUD operation.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const readHandler = onCallReadModel<DemoNestContext>({
71
+ * profile: readProfile,
72
+ * guestbook: readGuestbook
73
+ * });
74
+ * ```
75
+ */
22
76
  export declare function onCallReadModel<N>(map: OnCallReadModelMap<N>, config?: OnCallReadModelConfig<N>): OnCallWithNestContext<N, OnCallReadModelParams, unknown>;
77
+ /**
78
+ * Creates a bad-request error indicating the requested model type is not valid for reading.
79
+ */
23
80
  export declare function readModelUnknownModelTypeError(modelType: FirestoreModelType): import("firebase-functions/https").HttpsError;
@@ -3,21 +3,78 @@ import { type Maybe, type PromiseOrValue } from '@dereekb/util';
3
3
  import { type NestContextCallableRequestWithOptionalAuth, type NestContextCallableRequestWithAuth } from '../function/nest';
4
4
  import { type OnCallWithAuthAwareNestRequireAuthRef, type OnCallWithNestContext } from '../function/call';
5
5
  import { type OnCallApiDetailsRef } from './api.details';
6
+ /**
7
+ * Request type for specifier-dispatched handlers that require authentication.
8
+ *
9
+ * @typeParam N - The NestJS context type.
10
+ * @typeParam I - The input data type.
11
+ */
6
12
  export type OnCallSpecifierHandlerNestContextRequest<N, I = unknown> = NestContextCallableRequestWithAuth<N, I> & ModelFirebaseCrudFunctionSpecifierRef;
13
+ /**
14
+ * A specifier handler function that requires an authenticated caller.
15
+ */
7
16
  export type OnCallSpecifierHandlerFunctionWithAuth<N, I = unknown, O = unknown> = ((request: OnCallSpecifierHandlerNestContextRequest<N, I>) => PromiseOrValue<O>) & {
8
17
  readonly _requiresAuth?: true;
9
18
  };
19
+ /**
20
+ * Request type for specifier-dispatched handlers that allow unauthenticated callers.
21
+ */
10
22
  export type OnCallSpecifierHandlerNestContextRequestWithOptionalAuth<N, I = unknown> = NestContextCallableRequestWithOptionalAuth<N, I> & ModelFirebaseCrudFunctionSpecifierRef;
23
+ /**
24
+ * A specifier handler function that does not require authentication.
25
+ */
11
26
  export type OnCallSpecifierHandlerFunctionWithOptionalAuth<N, I = unknown, O = unknown> = ((request: OnCallSpecifierHandlerNestContextRequestWithOptionalAuth<N, I>) => PromiseOrValue<O>) & {
12
27
  readonly _requireAuth: false;
13
28
  };
29
+ /**
30
+ * Union of auth-required and optional-auth specifier handler functions.
31
+ *
32
+ * Each specifier handler within an {@link OnCallSpecifierHandlerConfig} may independently
33
+ * declare its own auth requirements.
34
+ */
14
35
  export type OnCallSpecifierHandlerFunction<N, I = unknown, O = void> = (OnCallSpecifierHandlerFunctionWithAuth<N, I, O> | OnCallSpecifierHandlerFunctionWithOptionalAuth<N, I, O>) & OnCallWithAuthAwareNestRequireAuthRef;
36
+ /**
37
+ * Configuration object mapping specifier keys to handler functions.
38
+ *
39
+ * The special key `_` is the default handler invoked when no specifier (or the default
40
+ * specifier) is provided. Other keys correspond to named sub-operations on the same
41
+ * model type, allowing a single CRUD slot to support multiple behaviors.
42
+ *
43
+ * @typeParam N - The NestJS context type.
44
+ */
15
45
  export type OnCallSpecifierHandlerConfig<N> = {
16
46
  /**
17
- * The default handler function.
47
+ * The default handler function, invoked when the specifier is `_` or omitted.
18
48
  */
19
49
  readonly _?: Maybe<OnCallSpecifierHandlerFunction<N, any, any>>;
20
50
  readonly [key: string]: Maybe<OnCallSpecifierHandlerFunction<N, any, any>>;
21
51
  };
52
+ /**
53
+ * Factory that creates a handler dispatching to sub-operations based on a specifier string.
54
+ *
55
+ * Use this when a single model type + CRUD operation needs to support multiple behaviors
56
+ * (e.g., a profile update that can either update the default fields or change a username).
57
+ * The resulting function is marked `_requireAuth = false` because auth enforcement is
58
+ * delegated to each individual specifier handler.
59
+ *
60
+ * API details from all specifier handlers are aggregated into
61
+ * {@link OnCallSpecifierApiDetails} for MCP introspection.
62
+ *
63
+ * @param config - Maps specifier keys to their handler functions.
64
+ * @returns A callable function that dispatches by specifier, with aggregated API details.
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const updateProfile = onCallSpecifierHandler<DemoNestContext>({
69
+ * _: updateProfileDefault,
70
+ * username: updateProfileUsername,
71
+ * fromUpload: updateProfileFromUpload
72
+ * });
73
+ * ```
74
+ */
22
75
  export declare function onCallSpecifierHandler<N, I = any, O = any>(config: OnCallSpecifierHandlerConfig<N>): OnCallWithNestContext<N, I, O> & OnCallWithAuthAwareNestRequireAuthRef & OnCallApiDetailsRef;
76
+ /**
77
+ * Creates a bad-request error indicating the provided specifier is not recognized
78
+ * by the current model CRUD handler.
79
+ */
23
80
  export declare function unknownModelCrudFunctionSpecifierError(specifier: ModelFirebaseCrudFunctionSpecifier): import("firebase-functions/https").HttpsError;