@dereekb/firebase-server 13.2.2 → 13.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +7506 -1884
- package/index.esm.js +7505 -1890
- package/mailgun/index.cjs.js +333 -31
- package/mailgun/index.esm.js +333 -31
- package/mailgun/package.json +8 -8
- package/mailgun/src/lib/auth.mailgun.d.ts +22 -3
- package/model/index.cjs.js +11334 -3830
- package/model/index.esm.js +11338 -3834
- package/model/package.json +8 -8
- package/model/src/lib/mailgun/notification.send.service.mailgun.d.ts +27 -1
- package/model/src/lib/notification/notification.action.init.service.d.ts +93 -1
- package/model/src/lib/notification/notification.action.service.d.ts +151 -2
- package/model/src/lib/notification/notification.config.d.ts +19 -7
- package/model/src/lib/notification/notification.config.service.d.ts +44 -6
- package/model/src/lib/notification/notification.create.run.d.ts +33 -5
- package/model/src/lib/notification/notification.error.d.ts +63 -0
- package/model/src/lib/notification/notification.module.d.ts +11 -0
- package/model/src/lib/notification/notification.send.d.ts +8 -1
- package/model/src/lib/notification/notification.send.service.d.ts +7 -1
- package/model/src/lib/notification/notification.send.service.notificationsummary.d.ts +32 -2
- package/model/src/lib/notification/notification.send.service.text.d.ts +11 -3
- package/model/src/lib/notification/notification.task.service.d.ts +13 -1
- package/model/src/lib/notification/notification.task.service.handler.d.ts +27 -3
- package/model/src/lib/notification/notification.task.service.util.d.ts +16 -4
- package/model/src/lib/notification/notification.task.subtask.handler.d.ts +31 -1
- package/model/src/lib/notification/notification.util.d.ts +70 -0
- package/model/src/lib/storagefile/storagefile.action.init.service.d.ts +62 -1
- package/model/src/lib/storagefile/storagefile.action.server.d.ts +124 -2
- package/model/src/lib/storagefile/storagefile.error.d.ts +44 -0
- package/model/src/lib/storagefile/storagefile.module.d.ts +11 -0
- package/model/src/lib/storagefile/storagefile.task.service.handler.d.ts +4 -1
- package/model/src/lib/storagefile/storagefile.upload.service.d.ts +13 -1
- package/model/src/lib/storagefile/storagefile.upload.service.initializer.d.ts +43 -1
- package/model/src/lib/storagefile/storagefile.util.d.ts +8 -0
- package/oidc/index.cjs.default.js +1 -0
- package/oidc/index.cjs.js +5607 -0
- package/oidc/index.cjs.mjs +2 -0
- package/oidc/index.d.ts +1 -0
- package/oidc/index.esm.js +5560 -0
- package/oidc/package.json +26 -0
- package/oidc/src/index.d.ts +1 -0
- package/oidc/src/lib/controller/index.d.ts +3 -0
- package/oidc/src/lib/controller/oidc.interaction.controller.d.ts +54 -0
- package/oidc/src/lib/controller/oidc.provider.controller.d.ts +18 -0
- package/oidc/src/lib/controller/oidc.wellknown.controller.d.ts +36 -0
- package/oidc/src/lib/index.d.ts +6 -0
- package/oidc/src/lib/middleware/index.d.ts +3 -0
- package/oidc/src/lib/middleware/oauth-auth.decorator.d.ts +14 -0
- package/oidc/src/lib/middleware/oauth-auth.middleware.d.ts +21 -0
- package/oidc/src/lib/middleware/oauth-auth.module.d.ts +50 -0
- package/oidc/src/lib/model/index.d.ts +3 -0
- package/oidc/src/lib/model/jwks/index.d.ts +3 -0
- package/oidc/src/lib/model/jwks/jwks.d.ts +107 -0
- package/oidc/src/lib/model/jwks/jwks.id.d.ts +9 -0
- package/oidc/src/lib/model/jwks/jwks.query.d.ts +18 -0
- package/oidc/src/lib/model/model.d.ts +12 -0
- package/oidc/src/lib/model/oidc/index.d.ts +2 -0
- package/oidc/src/lib/model/oidc/oidcmodel.action.server.d.ts +62 -0
- package/oidc/src/lib/model/oidc/oidcmodel.module.d.ts +23 -0
- package/oidc/src/lib/oidc.config.d.ts +175 -0
- package/oidc/src/lib/oidc.module.d.ts +100 -0
- package/oidc/src/lib/service/index.d.ts +10 -0
- package/oidc/src/lib/service/oidc.account.d.ts +36 -0
- package/oidc/src/lib/service/oidc.account.service.d.ts +104 -0
- package/oidc/src/lib/service/oidc.adapter.service.d.ts +20 -0
- package/oidc/src/lib/service/oidc.auth.d.ts +26 -0
- package/oidc/src/lib/service/oidc.client.service.d.ts +57 -0
- package/oidc/src/lib/service/oidc.config.service.d.ts +100 -0
- package/oidc/src/lib/service/oidc.encryption.service.d.ts +53 -0
- package/oidc/src/lib/service/oidc.interaction.service.d.ts +44 -0
- package/oidc/src/lib/service/oidc.jwks.service.d.ts +105 -0
- package/oidc/src/lib/service/oidc.service.d.ts +55 -0
- package/package.json +15 -9
- package/src/lib/auth/auth.context.d.ts +22 -2
- package/src/lib/auth/auth.service.d.ts +5 -0
- package/src/lib/auth/auth.service.error.d.ts +2 -1
- package/src/lib/auth/auth.util.d.ts +15 -3
- package/src/lib/env/env.config.d.ts +42 -0
- package/src/lib/env/env.service.d.ts +17 -0
- package/src/lib/env/index.d.ts +1 -0
- package/src/lib/firestore/array.d.ts +11 -3
- package/src/lib/firestore/driver.accessor.batch.d.ts +27 -4
- package/src/lib/firestore/driver.accessor.d.ts +43 -0
- package/src/lib/firestore/driver.accessor.default.d.ts +20 -0
- package/src/lib/firestore/driver.accessor.transaction.d.ts +28 -4
- package/src/lib/firestore/driver.d.ts +14 -0
- package/src/lib/firestore/driver.query.d.ts +25 -0
- package/src/lib/firestore/increment.d.ts +13 -3
- package/src/lib/firestore/snapshot/index.d.ts +1 -1
- package/src/lib/firestore/snapshot/{snapshot.field.d.ts → snapshot.field.encrypt.d.ts} +13 -27
- package/src/lib/function/assert.d.ts +32 -16
- package/src/lib/function/context.d.ts +26 -0
- package/src/lib/function/error.auth.d.ts +15 -0
- package/src/lib/function/error.d.ts +68 -4
- package/src/lib/nest/app.d.ts +53 -9
- package/src/lib/nest/app.module.d.ts +90 -0
- package/src/lib/nest/auth/auth.module.d.ts +30 -4
- package/src/lib/nest/auth/auth.util.d.ts +38 -0
- package/src/lib/nest/controller/auth.context.server.d.ts +27 -0
- package/src/lib/nest/controller/index.d.ts +1 -0
- package/src/lib/nest/development/development.app.function.d.ts +45 -0
- package/src/lib/nest/development/development.assert.function.d.ts +19 -1
- package/src/lib/nest/development/development.function.d.ts +42 -3
- package/src/lib/nest/development/development.schedule.function.d.ts +29 -0
- package/src/lib/nest/development/development.schedule.function.error.d.ts +21 -0
- package/src/lib/nest/env/env.service.d.ts +9 -0
- package/src/lib/nest/env/env.util.d.ts +16 -0
- package/src/lib/nest/firebase/firebase.module.d.ts +13 -1
- package/src/lib/nest/firestore/firestore.module.d.ts +24 -8
- package/src/lib/nest/function/call.d.ts +75 -6
- package/src/lib/nest/function/context.d.ts +85 -2
- package/src/lib/nest/function/nest.d.ts +46 -0
- package/src/lib/nest/function/schedule.d.ts +49 -0
- package/src/lib/nest/function/v2/blocking.d.ts +92 -8
- package/src/lib/nest/function/v2/call.d.ts +38 -8
- package/src/lib/nest/function/v2/event.d.ts +67 -4
- package/src/lib/nest/function/v2/schedule.d.ts +36 -5
- package/src/lib/nest/index.d.ts +3 -0
- package/src/lib/nest/middleware/appcheck.d.ts +5 -0
- package/src/lib/nest/middleware/appcheck.middleware.d.ts +44 -14
- package/src/lib/nest/middleware/appcheck.module.d.ts +10 -1
- package/src/lib/nest/middleware/globalprefix.d.ts +31 -3
- package/src/lib/nest/middleware/index.d.ts +2 -1
- package/src/lib/nest/middleware/rawbody.middleware.d.ts +6 -0
- package/src/lib/nest/model/call.model.function.d.ts +69 -3
- package/src/lib/nest/model/create.model.function.d.ts +66 -0
- package/src/lib/nest/model/crud.assert.function.d.ts +27 -1
- package/src/lib/nest/model/delete.model.function.d.ts +55 -0
- package/src/lib/nest/model/permission.error.d.ts +15 -0
- package/src/lib/nest/model/read.model.function.d.ts +57 -0
- package/src/lib/nest/model/specifier.function.d.ts +58 -1
- package/src/lib/nest/model/update.model.function.d.ts +58 -0
- package/src/lib/nest/nest.provider.d.ts +24 -11
- package/src/lib/nest/nest.provider.server.d.ts +12 -0
- package/src/lib/nest/storage/storage.module.d.ts +30 -4
- package/src/lib/storage/driver.accessor.d.ts +33 -0
- package/src/lib/storage/driver.d.ts +14 -0
- package/src/lib/storage/storage.d.ts +11 -4
- package/src/lib/storage/storage.service.d.ts +10 -1
- package/src/lib/type.d.ts +7 -2
- package/test/index.cjs.js +4072 -757
- package/test/index.esm.js +4073 -761
- package/test/package.json +8 -8
- package/test/src/lib/firebase/firebase.admin.auth.d.ts +82 -1
- package/test/src/lib/firebase/firebase.admin.collection.d.ts +55 -3
- package/test/src/lib/firebase/firebase.admin.d.ts +64 -0
- package/test/src/lib/firebase/firebase.admin.function.d.ts +84 -0
- package/test/src/lib/firebase/firebase.admin.nest.d.ts +125 -17
- package/test/src/lib/firebase/firebase.admin.nest.function.callable.context.d.ts +44 -0
- package/test/src/lib/firebase/firebase.admin.nest.function.cloud.context.d.ts +41 -0
- package/test/src/lib/firebase/firebase.admin.nest.function.d.ts +98 -0
- package/test/src/lib/firebase/firebase.admin.test.server.d.ts +26 -0
- package/test/src/lib/firebase/firebase.d.ts +57 -2
- package/test/src/lib/firebase/firebase.function.d.ts +138 -0
- package/test/src/lib/firestore/firestore.admin.d.ts +6 -0
- package/test/src/lib/firestore/firestore.d.ts +30 -0
- package/test/src/lib/storage/storage.admin.d.ts +9 -3
- package/test/src/lib/storage/storage.d.ts +30 -0
- package/zoho/index.cjs.js +406 -73
- package/zoho/index.esm.js +406 -73
- package/zoho/package.json +8 -8
- package/zoho/src/lib/zoho.accounts.firebase.d.ts +13 -2
- package/zoho/src/lib/zoho.accounts.firebase.system.d.ts +29 -6
- package/index.cjs.js.map +0 -1
- package/index.esm.js.map +0 -1
- /package/src/lib/nest/middleware/{webhook.d.ts → webhook.module.d.ts} +0 -0
|
@@ -11,19 +11,45 @@ export declare const FIREBASE_AUTH_TOKEN: InjectionToken;
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class FirebaseServerAuthModule {
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Simplified provider config that receives only the Firebase Admin Auth instance.
|
|
16
|
+
*/
|
|
14
17
|
export type ProvideFirebaseServerAuthServiceSimple<T extends FirebaseServerAuthService> = Pick<FactoryProvider<T>, 'provide'> & {
|
|
15
18
|
useFactory: (auth: admin.auth.Auth) => T;
|
|
16
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Provider config for a custom {@link FirebaseServerAuthService} implementation — either a full factory
|
|
22
|
+
* provider or a simplified one that only needs the Auth instance.
|
|
23
|
+
*/
|
|
17
24
|
export type ProvideFirebaseServerAuthService<T extends FirebaseServerAuthService> = FactoryProvider<T> | ProvideFirebaseServerAuthServiceSimple<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates NestJS provider entries for a custom {@link FirebaseServerAuthService} implementation.
|
|
27
|
+
*
|
|
28
|
+
* Returns two providers: the concrete service and an alias that maps
|
|
29
|
+
* `FirebaseServerAuthService` to the concrete token, enabling injection by the abstract type.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const providers = provideFirebaseServerAuthService({
|
|
34
|
+
* provide: MyAuthService,
|
|
35
|
+
* useFactory: (auth) => new MyAuthService(auth)
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
18
39
|
export declare function provideFirebaseServerAuthService<T extends FirebaseServerAuthService>(provider: ProvideFirebaseServerAuthService<T>): [ProvideFirebaseServerAuthService<T>, Provider<T>];
|
|
19
40
|
export interface FirebaseServerAuthModuleMetadataConfig<T extends FirebaseServerAuthService> extends AdditionalModuleMetadata {
|
|
20
41
|
readonly serviceProvider: ProvideFirebaseServerAuthService<T>;
|
|
21
42
|
}
|
|
22
43
|
/**
|
|
23
|
-
*
|
|
44
|
+
* Generates NestJS {@link ModuleMetadata} for an app's auth module, including the {@link FirebaseServerAuthModule}
|
|
45
|
+
* import and the custom {@link FirebaseServerAuthService} provider.
|
|
24
46
|
*
|
|
25
|
-
* @
|
|
26
|
-
*
|
|
27
|
-
* @
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* @Module(firebaseServerAuthModuleMetadata({
|
|
50
|
+
* serviceProvider: { provide: MyAuthService, useFactory: (auth) => new MyAuthService(auth) }
|
|
51
|
+
* }))
|
|
52
|
+
* export class AppAuthModule {}
|
|
53
|
+
* ```
|
|
28
54
|
*/
|
|
29
55
|
export declare function firebaseServerAuthModuleMetadata<T extends FirebaseServerAuthService>(config: FirebaseServerAuthModuleMetadataConfig<T>): ModuleMetadata;
|
|
@@ -2,13 +2,51 @@ import { type UserRelated } from '@dereekb/firebase';
|
|
|
2
2
|
import { type ArrayOrValue, type AuthRole } from '@dereekb/util';
|
|
3
3
|
import { type NestContextCallableRequestWithOptionalAuth } from '../function/nest';
|
|
4
4
|
import { type AbstractFirebaseNestContext } from '../nest.provider';
|
|
5
|
+
/**
|
|
6
|
+
* Asserts that the caller has admin privileges in the request.
|
|
7
|
+
*
|
|
8
|
+
* @throws {HttpsError} Throws forbidden (403) if the caller is not an admin.
|
|
9
|
+
*/
|
|
5
10
|
export declare function assertIsAdminInRequest<N extends AbstractFirebaseNestContext<any, any> = AbstractFirebaseNestContext<any, any>, I = unknown>(request: NestContextCallableRequestWithOptionalAuth<N, I>): void;
|
|
11
|
+
/**
|
|
12
|
+
* Checks whether the caller has admin privileges in the request.
|
|
13
|
+
*/
|
|
6
14
|
export declare function isAdminInRequest<N extends AbstractFirebaseNestContext<any, any> = AbstractFirebaseNestContext<any, any>, I = unknown>(request: NestContextCallableRequestWithOptionalAuth<N, I>): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Asserts that the caller is either an admin or is targeting their own user record.
|
|
17
|
+
*
|
|
18
|
+
* If the request data contains a `uid` that differs from the caller's auth UID, admin status is required.
|
|
19
|
+
*
|
|
20
|
+
* @returns The resolved target UID (from request data or auth).
|
|
21
|
+
* @throws {HttpsError} Throws forbidden (403) if the caller is not authorized.
|
|
22
|
+
*/
|
|
7
23
|
export declare function assertIsAdminOrTargetUserInRequestData<N extends AbstractFirebaseNestContext<any, any> = AbstractFirebaseNestContext<any, any>, I extends Partial<UserRelated> = Partial<UserRelated>>(request: NestContextCallableRequestWithOptionalAuth<N, I>, requireUid?: boolean): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Checks whether the caller is an admin or is targeting their own user record in the request data.
|
|
26
|
+
*
|
|
27
|
+
* @param requireUid - If true, a UID must be present in the request data.
|
|
28
|
+
*/
|
|
8
29
|
export declare function isAdminOrTargetUserInRequestData<N extends AbstractFirebaseNestContext<any, any> = AbstractFirebaseNestContext<any, any>, I extends Partial<UserRelated> = Partial<UserRelated>>(request: NestContextCallableRequestWithOptionalAuth<N, I>, requireUid?: boolean): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Asserts that the caller has signed the Terms of Service.
|
|
32
|
+
*
|
|
33
|
+
* @throws {HttpsError} Throws forbidden (403) if ToS has not been signed.
|
|
34
|
+
*/
|
|
9
35
|
export declare function assertHasSignedTosInRequest<N extends AbstractFirebaseNestContext<any, any> = AbstractFirebaseNestContext<any, any>, I = unknown>(request: NestContextCallableRequestWithOptionalAuth<N, I>): void;
|
|
36
|
+
/**
|
|
37
|
+
* Checks whether the caller has signed the Terms of Service.
|
|
38
|
+
*/
|
|
10
39
|
export declare function hasSignedTosInRequest<N extends AbstractFirebaseNestContext<any, any> = AbstractFirebaseNestContext<any, any>, I = unknown>(request: NestContextCallableRequestWithOptionalAuth<N, I>): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Asserts that the caller has all of the specified auth roles.
|
|
42
|
+
*
|
|
43
|
+
* @param authRoles - One or more roles that must all be present.
|
|
44
|
+
* @throws {HttpsError} Throws forbidden (403) if any required role is missing.
|
|
45
|
+
*/
|
|
11
46
|
export declare function assertHasRolesInRequest<N extends AbstractFirebaseNestContext<any, any> = AbstractFirebaseNestContext<any, any>, I = unknown>(request: NestContextCallableRequestWithOptionalAuth<N, I>, authRoles: ArrayOrValue<AuthRole>): void;
|
|
47
|
+
/**
|
|
48
|
+
* Checks whether the caller has all of the specified auth roles.
|
|
49
|
+
*/
|
|
12
50
|
export declare function hasAuthRolesInRequest<N extends AbstractFirebaseNestContext<any, any> = AbstractFirebaseNestContext<any, any>, I = unknown>(request: NestContextCallableRequestWithOptionalAuth<N, I>, authRoles: ArrayOrValue<AuthRole>): boolean;
|
|
13
51
|
/**
|
|
14
52
|
* Returns true if the claims have a FIREBASE_SERVER_AUTH_CLAIMS_SETUP_PASSWORD_KEY claims value, indicating they are a newly invited user.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type AuthData } from '../../type';
|
|
2
|
+
import { type Request } from 'express';
|
|
3
|
+
/**
|
|
4
|
+
* Minimum auth data shape shared by all server-side auth contexts.
|
|
5
|
+
*
|
|
6
|
+
* Both Firebase's {@link AuthData} and OAuth auth contexts satisfy this interface.
|
|
7
|
+
*/
|
|
8
|
+
export interface FirebaseServerAuthData extends AuthData {
|
|
9
|
+
/**
|
|
10
|
+
* The authenticated user's UID.
|
|
11
|
+
*/
|
|
12
|
+
readonly uid: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Extends Express Request with an `auth` field for authenticated requests.
|
|
16
|
+
*
|
|
17
|
+
* Generic over the auth context type, constrained to {@link FirebaseServerAuthData}
|
|
18
|
+
* so all auth contexts guarantee at least a `uid`.
|
|
19
|
+
*
|
|
20
|
+
* @typeParam A - The auth context type. Defaults to {@link FirebaseServerAuthData}.
|
|
21
|
+
*/
|
|
22
|
+
export interface FirebaseServerAuthenticatedRequest<A extends FirebaseServerAuthData = FirebaseServerAuthData> extends Request {
|
|
23
|
+
/**
|
|
24
|
+
* The auth in this request. Should not be changed.
|
|
25
|
+
*/
|
|
26
|
+
readonly auth?: A;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './auth.context.server';
|
|
@@ -5,14 +5,30 @@ import { type NestApplicationScheduleConfiguredFunctionMap } from '../function/s
|
|
|
5
5
|
import { type OnCallHandlerWithNestContextFactory } from '../function/v2/call';
|
|
6
6
|
import { type AbstractFirebaseNestContext } from '../nest.provider';
|
|
7
7
|
import { type OnCallDevelopmentFunctionMap } from './development.function';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for {@link firebaseServerDevFunctions}.
|
|
10
|
+
*
|
|
11
|
+
* Controls whether development endpoints are active, what operations they expose,
|
|
12
|
+
* and whether they require authentication. In production, set `enabled: false`
|
|
13
|
+
* to replace dev endpoints with a stub that returns an "unavailable" error.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam N - The NestJS context type.
|
|
16
|
+
* @typeParam S - The schedule function map type.
|
|
17
|
+
*/
|
|
8
18
|
export interface FirebaseServerDevFunctionsConfig<N extends AbstractFirebaseNestContext<any, any>, S extends NestApplicationScheduleConfiguredFunctionMap> {
|
|
19
|
+
/** When false, dev endpoints return an "unavailable" error instead of executing. */
|
|
9
20
|
readonly enabled: boolean;
|
|
10
21
|
/**
|
|
11
22
|
* Whether or not to require an auth context when calling dev functions. True by default.
|
|
23
|
+
*
|
|
24
|
+
* Set to false only in local development where authentication is unavailable.
|
|
12
25
|
*/
|
|
13
26
|
readonly secure?: boolean;
|
|
27
|
+
/** Getter for the NestJS application promise, used to bootstrap the context. */
|
|
14
28
|
readonly nest: NestAppPromiseGetter;
|
|
29
|
+
/** Map of specifier keys to developer utility functions. */
|
|
15
30
|
readonly developerFunctionsMap: OnCallDevelopmentFunctionMap<N>;
|
|
31
|
+
/** Factory that wraps a handler function with NestJS context resolution. */
|
|
16
32
|
readonly onCallFactory: OnCallHandlerWithNestContextFactory<N>;
|
|
17
33
|
/**
|
|
18
34
|
* Whether or not to disable adding the dev schedule function. False by default.
|
|
@@ -23,7 +39,36 @@ export interface FirebaseServerDevFunctionsConfig<N extends AbstractFirebaseNest
|
|
|
23
39
|
*/
|
|
24
40
|
readonly allScheduledFunctions?: S;
|
|
25
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The output of {@link firebaseServerDevFunctions}, containing the `dev` callable function
|
|
44
|
+
* keyed by {@link RUN_DEV_FUNCTION_APP_FUNCTION_KEY}.
|
|
45
|
+
*
|
|
46
|
+
* Spread this into your Firebase Functions exports to register the dev endpoint.
|
|
47
|
+
*/
|
|
26
48
|
export interface FirebaseServerDevFunctions {
|
|
27
49
|
readonly [RUN_DEV_FUNCTION_APP_FUNCTION_KEY]: RunnableHttpFunction<OnCallDevelopmentParams> | CallableHttpFunction<OnCallDevelopmentParams>;
|
|
28
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates the development callable function bundle for a Firebase + NestJS server.
|
|
53
|
+
*
|
|
54
|
+
* When `enabled` is true, wires together the developer function map, optionally
|
|
55
|
+
* includes the scheduled-function runner, and wraps everything in the NestJS context.
|
|
56
|
+
* When `enabled` is false, returns a stub that throws an "unavailable" error.
|
|
57
|
+
*
|
|
58
|
+
* @param config - Controls which dev functions are exposed and how they are secured.
|
|
59
|
+
* @returns An object with the `dev` function, ready to be spread into Firebase exports.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const devFunctions = firebaseServerDevFunctions({
|
|
64
|
+
* enabled: environment.dev,
|
|
65
|
+
* nest: getNestApp,
|
|
66
|
+
* developerFunctionsMap: { initData: initDataFunction },
|
|
67
|
+
* onCallFactory: myOnCallFactory,
|
|
68
|
+
* allScheduledFunctions: scheduledFunctions
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* export const { dev } = devFunctions;
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
29
74
|
export declare function firebaseServerDevFunctions<N extends AbstractFirebaseNestContext<any, any>, S extends NestApplicationScheduleConfiguredFunctionMap>(config: FirebaseServerDevFunctionsConfig<N, S>): FirebaseServerDevFunctions;
|
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
import { type NestContextCallableRequest } from '../function/nest';
|
|
2
|
+
/**
|
|
3
|
+
* Context passed to a {@link AssertDevelopmentRequestFunction} before a development
|
|
4
|
+
* function handler executes.
|
|
5
|
+
*
|
|
6
|
+
* Provides the original request and the specifier identifying which dev function
|
|
7
|
+
* is being called, enabling assertions to gate access on a per-function basis.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam N - The NestJS context type.
|
|
10
|
+
* @typeParam I - The input data type of the request.
|
|
11
|
+
*/
|
|
2
12
|
export interface AssertDevelopmentRequestFunctionContext<N, I = unknown> {
|
|
13
|
+
/** The original callable request including the NestJS context and caller data. */
|
|
3
14
|
readonly request: NestContextCallableRequest<N, I>;
|
|
15
|
+
/** The development function specifier string identifying which dev operation was requested. */
|
|
4
16
|
readonly specifier: string;
|
|
5
17
|
}
|
|
6
18
|
/**
|
|
7
|
-
*
|
|
19
|
+
* Pre-assertion hook invoked before a development function handler executes.
|
|
20
|
+
*
|
|
21
|
+
* Throw an error to reject the request. Useful for restricting which development
|
|
22
|
+
* functions are accessible in certain environments or to specific callers.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam N - The NestJS context type.
|
|
25
|
+
* @typeParam I - The input data type of the request.
|
|
8
26
|
*/
|
|
9
27
|
export type AssertDevelopmentRequestFunction<N, I = unknown> = (context: AssertDevelopmentRequestFunctionContext<N, I>) => void;
|
|
@@ -3,18 +3,57 @@ import { type OnCallDevelopmentParams, type DevelopmentFirebaseFunctionSpecifier
|
|
|
3
3
|
import { type OnCallWithNestContext } from '../function/call';
|
|
4
4
|
import { type NestContextCallableRequest } from '../function/nest';
|
|
5
5
|
import { type AssertDevelopmentRequestFunction } from './development.assert.function';
|
|
6
|
+
/**
|
|
7
|
+
* A single development function handler.
|
|
8
|
+
*
|
|
9
|
+
* Receives the NestJS context request with unwrapped inner data and the specifier
|
|
10
|
+
* identifying which dev operation was requested.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam N - The NestJS context type.
|
|
13
|
+
* @typeParam I - The input data type.
|
|
14
|
+
* @typeParam O - The output type.
|
|
15
|
+
*/
|
|
6
16
|
export type OnCallDevelopmentFunction<N, I = unknown, O = unknown> = (request: NestContextCallableRequest<N, I> & DevelopmentFirebaseFunctionSpecifierRef) => PromiseOrValue<O>;
|
|
17
|
+
/**
|
|
18
|
+
* Maps specifier strings to development function handlers.
|
|
19
|
+
*
|
|
20
|
+
* Each key is a specifier that clients pass in the `specifier` field of
|
|
21
|
+
* {@link OnCallDevelopmentParams} to invoke a specific dev operation.
|
|
22
|
+
*
|
|
23
|
+
* @typeParam N - The NestJS context type.
|
|
24
|
+
*/
|
|
7
25
|
export type OnCallDevelopmentFunctionMap<N> = {
|
|
8
26
|
readonly [key: string]: OnCallDevelopmentFunction<N, any, any>;
|
|
9
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Configuration for {@link onCallDevelopmentFunction}.
|
|
30
|
+
*
|
|
31
|
+
* @typeParam N - The NestJS context type.
|
|
32
|
+
*/
|
|
10
33
|
export interface OnCallDevelopmentConfig<N> {
|
|
34
|
+
/** Optional assertion run before the dev handler; throw to reject the request. */
|
|
11
35
|
readonly preAssert?: AssertDevelopmentRequestFunction<N, OnCallDevelopmentParams>;
|
|
12
36
|
}
|
|
13
37
|
/**
|
|
14
|
-
*
|
|
38
|
+
* Factory that creates a callable function dispatching to development utility handlers.
|
|
39
|
+
*
|
|
40
|
+
* Incoming requests carry a `specifier` field that selects the appropriate handler
|
|
41
|
+
* from the provided map. The inner `data` payload is unwrapped and forwarded to the handler.
|
|
15
42
|
*
|
|
16
|
-
* @param map
|
|
17
|
-
* @
|
|
43
|
+
* @param map - Maps specifier strings to development function handlers.
|
|
44
|
+
* @param config - Optional configuration including a pre-assertion hook.
|
|
45
|
+
* @returns A callable function that dispatches to the correct dev handler by specifier.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const devFunction = onCallDevelopmentFunction<DemoNestContext>({
|
|
50
|
+
* initData: initDataFunction,
|
|
51
|
+
* resetData: resetDataFunction
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
18
54
|
*/
|
|
19
55
|
export declare function onCallDevelopmentFunction<N>(map: OnCallDevelopmentFunctionMap<N>, config?: OnCallDevelopmentConfig<N>): OnCallWithNestContext<N, OnCallDevelopmentParams>;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a bad-request error indicating the provided development function specifier is not recognized.
|
|
58
|
+
*/
|
|
20
59
|
export declare function developmentUnknownSpecifierError(specifier: DevelopmentFirebaseFunctionSpecifier): import("firebase-functions/https").HttpsError;
|
|
@@ -1,7 +1,36 @@
|
|
|
1
1
|
import { type ScheduledFunctionDevelopmentFirebaseFunctionParams, type ScheduledFunctionDevelopmentFirebaseFunctionResult } from '@dereekb/firebase';
|
|
2
2
|
import { type NestApplicationScheduleConfiguredFunctionMap } from '../function/schedule';
|
|
3
3
|
import { type OnCallDevelopmentFunction } from './development.function';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for {@link makeScheduledFunctionDevelopmentFunction}.
|
|
6
|
+
*/
|
|
4
7
|
export interface MakeScheduledFunctionDevelopmentFunctionConfig {
|
|
8
|
+
/** The complete map of registered scheduled functions that can be triggered manually. */
|
|
5
9
|
readonly allScheduledFunctions: NestApplicationScheduleConfiguredFunctionMap;
|
|
6
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a development function that allows manually triggering or listing scheduled functions.
|
|
13
|
+
*
|
|
14
|
+
* Supports two operation types:
|
|
15
|
+
* - `'run'` - Executes a scheduled function by name via its `_runNow()` method.
|
|
16
|
+
* - `'list'` - Returns a list of all available scheduled function names.
|
|
17
|
+
*
|
|
18
|
+
* This is intended for development and testing environments where you need to
|
|
19
|
+
* trigger scheduled jobs on demand without waiting for their cron schedule.
|
|
20
|
+
*
|
|
21
|
+
* @param config - Provides the map of all scheduled functions available for manual execution.
|
|
22
|
+
* @returns A development function handler compatible with {@link OnCallDevelopmentFunctionMap}.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const scheduleDev = makeScheduledFunctionDevelopmentFunction({
|
|
27
|
+
* allScheduledFunctions: myScheduledFunctions
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Register it in the dev function map:
|
|
31
|
+
* const devFunctions: OnCallDevelopmentFunctionMap<MyContext> = {
|
|
32
|
+
* [SCHEDULED_FUNCTION_DEV_FUNCTION_SPECIFIER]: scheduleDev
|
|
33
|
+
* };
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
7
36
|
export declare function makeScheduledFunctionDevelopmentFunction(config: MakeScheduledFunctionDevelopmentFunctionConfig): OnCallDevelopmentFunction<unknown, ScheduledFunctionDevelopmentFirebaseFunctionParams, ScheduledFunctionDevelopmentFirebaseFunctionResult>;
|
|
@@ -1,6 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error code used when a 'run' request is missing the target function name.
|
|
3
|
+
*/
|
|
1
4
|
export declare const NO_RUN_NAME_SPECIFIED_FOR_SCHEDULED_FUNCTION_DEVELOPMENT_FUNCTION_CODE = "NO_RUN_NAME_SPECIFIED_FOR_SCHEDULED_FUNCTION_DEVELOPMENT_FUNCTION";
|
|
5
|
+
/**
|
|
6
|
+
* Creates a bad-request error for when the caller sends a 'run' command
|
|
7
|
+
* without specifying which scheduled function to execute.
|
|
8
|
+
*/
|
|
2
9
|
export declare function noRunNameSpecifiedForScheduledFunctionDevelopmentFunction(): import("firebase-functions/https").HttpsError;
|
|
10
|
+
/**
|
|
11
|
+
* Error code used when the requested scheduled function name does not exist in the function map.
|
|
12
|
+
*/
|
|
3
13
|
export declare const UNKNOWN_SCHEDULED_FUNCTION_DEVELOPMENT_FUNCTION_NAME_CODE = "UNKNOWN_SCHEDULED_FUNCTION_DEVELOPMENT_FUNCTION_NAME";
|
|
14
|
+
/**
|
|
15
|
+
* Creates a bad-request error for when the requested scheduled function name
|
|
16
|
+
* is not found in the registered function map.
|
|
17
|
+
*/
|
|
4
18
|
export declare function unknownScheduledFunctionDevelopmentFunctionName(name: unknown): import("firebase-functions/https").HttpsError;
|
|
19
|
+
/**
|
|
20
|
+
* Error code used when the request `type` field is neither 'run' nor 'list'.
|
|
21
|
+
*/
|
|
5
22
|
export declare const UNKNOWN_SCHEDULED_FUNCTION_DEVELOPMENT_FUNCTION_TYPE_CODE = "UNKNOWN_SCHEDULED_FUNCTION_DEVELOPMENT_FUNCTION_TYPE";
|
|
23
|
+
/**
|
|
24
|
+
* Creates a bad-request error for when the request `type` field does not match
|
|
25
|
+
* any supported operation ('run' or 'list').
|
|
26
|
+
*/
|
|
6
27
|
export declare function unknownScheduledFunctionDevelopmentFunctionType(type: unknown): import("firebase-functions/https").HttpsError;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { ServerEnvironmentService } from '@dereekb/nestjs';
|
|
2
2
|
import { type FirebaseServerEnvService } from '../../env/env.service';
|
|
3
|
+
import { type Maybe, type WebsiteUrlDetails } from '@dereekb/util';
|
|
4
|
+
/**
|
|
5
|
+
* Default NestJS injectable implementation of {@link FirebaseServerEnvService}.
|
|
6
|
+
*
|
|
7
|
+
* Extends {@link ServerEnvironmentService} from `@dereekb/nestjs` and adds
|
|
8
|
+
* Firebase-specific environment properties like `appUrl` and `developmentSchedulerEnabled`.
|
|
9
|
+
*/
|
|
3
10
|
export declare class DefaultFirebaseServerEnvService extends ServerEnvironmentService implements FirebaseServerEnvService {
|
|
11
|
+
private readonly _appUrlDetails;
|
|
4
12
|
/**
|
|
5
13
|
* Enabled when not in production and not in a testing environment.
|
|
6
14
|
*/
|
|
7
15
|
get developmentSchedulerEnabled(): boolean;
|
|
16
|
+
get appUrlDetails(): Maybe<WebsiteUrlDetails>;
|
|
8
17
|
}
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { type AsyncDecisionFunction } from '@dereekb/util';
|
|
2
2
|
import { type NestAppPromiseGetter } from '../app';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an async decision function that resolves to `true` if the NestJS app is running in production.
|
|
5
|
+
*
|
|
6
|
+
* Useful for conditionally enabling production-only Cloud Functions (e.g., scheduled tasks).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const isProduction = nestAppIsProductionEnvironment(nestAppGetter);
|
|
11
|
+
* if (await isProduction()) { ... }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
3
14
|
export declare function nestAppIsProductionEnvironment(nest: NestAppPromiseGetter): AsyncDecisionFunction<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an async decision function that resolves to `true` if the development scheduler is enabled.
|
|
17
|
+
*
|
|
18
|
+
* The development scheduler is enabled in non-production, non-testing environments.
|
|
19
|
+
*/
|
|
4
20
|
export declare function nestAppHasDevelopmentSchedulerEnabled(nest: NestAppPromiseGetter): AsyncDecisionFunction<void>;
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import type * as admin from 'firebase-admin';
|
|
2
2
|
import { type FactoryProvider, type InjectionToken } from '@nestjs/common';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* NestJS injection token for the Firebase Admin {@link admin.app.App} instance.
|
|
5
|
+
*
|
|
6
|
+
* Injected globally by {@link nestServerInstance} during server initialization.
|
|
5
7
|
*/
|
|
6
8
|
export declare const FIREBASE_APP_TOKEN: InjectionToken;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a NestJS {@link FactoryProvider} that binds a Firebase Admin app getter to {@link FIREBASE_APP_TOKEN}.
|
|
11
|
+
*
|
|
12
|
+
* @param useFactory - Factory function returning the Firebase Admin app instance.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const provider = firebaseServerAppTokenProvider(() => admin.app());
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
7
19
|
export declare function firebaseServerAppTokenProvider(useFactory: () => admin.app.App): FactoryProvider<admin.app.App>;
|
|
@@ -19,26 +19,42 @@ export declare class FirebaseServerFirestoreModule {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare class FirebaseServerFirestoreContextModule {
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Factory function that creates an app's Firestore collections instance from a {@link FirestoreContext}.
|
|
24
|
+
*/
|
|
22
25
|
export type ProvideAppFirestoreCollectionsFactory<T> = (context: FirestoreContext) => T;
|
|
26
|
+
/**
|
|
27
|
+
* Configuration for providing an app's Firestore collections class via NestJS DI.
|
|
28
|
+
*/
|
|
23
29
|
export interface ProvideAppFirestoreCollectionsConfig<T> {
|
|
24
30
|
provide: ClassLikeType<T>;
|
|
25
31
|
useFactory: ProvideAppFirestoreCollectionsFactory<T>;
|
|
26
32
|
}
|
|
27
33
|
/**
|
|
28
|
-
*
|
|
34
|
+
* Creates a NestJS provider that initializes a Firestore collections instance from the app's {@link FirestoreContext}.
|
|
29
35
|
*
|
|
30
|
-
* @
|
|
31
|
-
*
|
|
32
|
-
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const [provider] = provideAppFirestoreCollections({
|
|
39
|
+
* provide: DemoFirestoreCollections,
|
|
40
|
+
* useFactory: (context) => new DemoFirestoreCollections(context)
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
33
43
|
*/
|
|
34
44
|
export declare function provideAppFirestoreCollections<T>({ provide, useFactory }: ProvideAppFirestoreCollectionsConfig<T>): [Provider<T>];
|
|
35
45
|
export interface ProvideAppFirestoreModuleMetadataConfig<T> extends ProvideAppFirestoreCollectionsConfig<T>, Pick<ModuleMetadata, 'imports' | 'exports' | 'providers'> {
|
|
36
46
|
}
|
|
37
47
|
/**
|
|
38
|
-
*
|
|
48
|
+
* Generates NestJS {@link ModuleMetadata} for an app's Firestore module, including the
|
|
49
|
+
* {@link FirebaseServerFirestoreContextModule} import and the app's collections provider.
|
|
39
50
|
*
|
|
40
|
-
* @
|
|
41
|
-
*
|
|
42
|
-
* @
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* @Module(appFirestoreModuleMetadata({
|
|
54
|
+
* provide: DemoFirestoreCollections,
|
|
55
|
+
* useFactory: (context) => new DemoFirestoreCollections(context)
|
|
56
|
+
* }))
|
|
57
|
+
* export class AppFirestoreModule {}
|
|
58
|
+
* ```
|
|
43
59
|
*/
|
|
44
60
|
export declare function appFirestoreModuleMetadata<T>(config: ProvideAppFirestoreModuleMetadataConfig<T>): ModuleMetadata;
|
|
@@ -2,31 +2,89 @@ import { type PromiseOrValue } from '@dereekb/util';
|
|
|
2
2
|
import { type CallableRequest } from 'firebase-functions/v2/https';
|
|
3
3
|
import { type NestApplicationContextRequest, type NestContextCallableRequest, type NestContextCallableRequestWithAuth } from './nest';
|
|
4
4
|
import { type MakeNestContext } from '../nest.provider';
|
|
5
|
+
/**
|
|
6
|
+
* Request type for callable functions that receive an {@link INestApplicationContext} alongside the Firebase callable request data.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam I - The expected input data type for the callable request.
|
|
9
|
+
*/
|
|
5
10
|
export type OnCallWithNestApplicationRequest<I> = NestApplicationContextRequest<CallableRequest<I>>;
|
|
6
11
|
/**
|
|
7
12
|
* Runnable function that is passed an INestApplicationContext in addition to the usual data/context provided by firebase.
|
|
8
13
|
*/
|
|
9
14
|
export type OnCallWithNestApplication<I = unknown, O = unknown> = (request: OnCallWithNestApplicationRequest<I>) => PromiseOrValue<O>;
|
|
15
|
+
/**
|
|
16
|
+
* Request type for callable functions that receive a typed nest context object alongside the Firebase callable request data.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam N - The nest context type, typically an application-specific context class.
|
|
19
|
+
* @typeParam I - The expected input data type for the callable request.
|
|
20
|
+
*/
|
|
10
21
|
export type OnCallWithNestContextRequest<N, I> = NestContextCallableRequest<N, I>;
|
|
11
22
|
/**
|
|
12
23
|
* Runnable function that is passed an arbitrary nest context object in addition to the usual data/context provided by firebase.
|
|
13
24
|
*/
|
|
14
25
|
export type OnCallWithNestContext<N, I = unknown, O = unknown> = (request: OnCallWithNestContextRequest<N, I>) => PromiseOrValue<O>;
|
|
26
|
+
/**
|
|
27
|
+
* Mutates the application-level request to attach a typed nest context, converting it to an {@link OnCallWithNestContextRequest}.
|
|
28
|
+
*
|
|
29
|
+
* This bridges the gap between the raw NestJS application context and the domain-specific context object
|
|
30
|
+
* used by callable function handlers.
|
|
31
|
+
*
|
|
32
|
+
* @param makeNestContext - Factory that creates the typed context from the application context.
|
|
33
|
+
* @param request - The application-level callable request to augment.
|
|
34
|
+
* @returns The same request object, now typed with the nest context attached.
|
|
35
|
+
*/
|
|
15
36
|
export declare function setNestContextOnRequest<N, I>(makeNestContext: MakeNestContext<N>, request: OnCallWithNestApplicationRequest<I>): OnCallWithNestContextRequest<N, I>;
|
|
37
|
+
/**
|
|
38
|
+
* Callable function handler that requires authenticated requests. The request's auth data is guaranteed to be present.
|
|
39
|
+
*
|
|
40
|
+
* Use {@link inAuthContext} to wrap this handler with runtime auth assertion, or use {@link assertRequestRequiresAuthForFunction}
|
|
41
|
+
* to check auth requirements dynamically.
|
|
42
|
+
*
|
|
43
|
+
* @typeParam N - The nest context type.
|
|
44
|
+
* @typeParam I - The expected input data type.
|
|
45
|
+
* @typeParam O - The return type.
|
|
46
|
+
*/
|
|
16
47
|
export type OnCallWithAuthorizedNestContext<N, I = unknown, O = unknown> = ((request: NestContextCallableRequestWithAuth<N, I>) => PromiseOrValue<O>) & {
|
|
17
48
|
readonly _requiresAuth?: true;
|
|
18
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Callable function handler that explicitly does not require authentication.
|
|
52
|
+
*
|
|
53
|
+
* Created via {@link optionalAuthContext} to flag a handler as accepting unauthenticated requests.
|
|
54
|
+
*
|
|
55
|
+
* @typeParam N - The nest context type.
|
|
56
|
+
* @typeParam I - The expected input data type.
|
|
57
|
+
* @typeParam O - The return type.
|
|
58
|
+
*/
|
|
19
59
|
export type OnCallWithOptionalAuthorizedNestContext<N, I = unknown, O = unknown> = OnCallWithNestContext<N, I, O> & {
|
|
20
60
|
readonly _requireAuth: false;
|
|
21
61
|
};
|
|
22
62
|
/**
|
|
23
|
-
* Wraps the input OnCallWithNestContext function to flag it as
|
|
63
|
+
* Wraps the input {@link OnCallWithNestContext} function to flag it as not requiring authentication.
|
|
24
64
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
65
|
+
* By default, callable functions with auth-aware nest context require auth. Use this wrapper to
|
|
66
|
+
* explicitly opt out of that requirement for endpoints that should be publicly accessible.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const handler = optionalAuthContext<MyContext, Input, Output>((request) => {
|
|
71
|
+
* // request.auth may be undefined
|
|
72
|
+
* return doSomething(request);
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @param fn - The callable function handler to wrap.
|
|
77
|
+
* @returns A new handler flagged with `_requireAuth: false`.
|
|
27
78
|
*/
|
|
28
79
|
export declare function optionalAuthContext<N, I, O>(fn: OnCallWithNestContext<N, I, O>): OnCallWithOptionalAuthorizedNestContext<N, I, O>;
|
|
80
|
+
/**
|
|
81
|
+
* Union type representing a callable function handler that may or may not require authentication,
|
|
82
|
+
* determined at runtime by the {@link OnCallWithAuthAwareNestRequireAuthRef._requireAuth} flag.
|
|
83
|
+
*/
|
|
29
84
|
export type OnCallWithAuthAwareNestContext<N, I = unknown, O = unknown> = (OnCallWithAuthorizedNestContext<N, I, O> | OnCallWithOptionalAuthorizedNestContext<N, I, O>) & OnCallWithAuthAwareNestRequireAuthRef;
|
|
85
|
+
/**
|
|
86
|
+
* Ref interface used to determine whether a callable function handler requires authentication at runtime.
|
|
87
|
+
*/
|
|
30
88
|
export interface OnCallWithAuthAwareNestRequireAuthRef {
|
|
31
89
|
/**
|
|
32
90
|
* If false, auth is not required.
|
|
@@ -43,9 +101,20 @@ export interface OnCallWithAuthAwareNestRequireAuthRef {
|
|
|
43
101
|
*/
|
|
44
102
|
export declare function assertRequestRequiresAuthForFunction(fn: OnCallWithAuthAwareNestRequireAuthRef, request: OnCallWithNestContextRequest<any, any>): void;
|
|
45
103
|
/**
|
|
46
|
-
*
|
|
104
|
+
* Wraps an {@link OnCallWithAuthorizedNestContext} handler to enforce authentication at runtime.
|
|
47
105
|
*
|
|
48
|
-
* @
|
|
49
|
-
*
|
|
106
|
+
* The wrapper calls {@link assertIsContextWithAuthData} before invoking the handler, ensuring that
|
|
107
|
+
* unauthenticated requests are rejected with an appropriate error before reaching handler logic.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const secureHandler = inAuthContext<MyContext, Input, Output>((request) => {
|
|
112
|
+
* // request.auth is guaranteed to be defined here
|
|
113
|
+
* return processAuthenticatedRequest(request);
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @param fn - The authorized handler to wrap with auth assertion.
|
|
118
|
+
* @returns A general {@link OnCallWithNestContext} handler that asserts auth before delegating.
|
|
50
119
|
*/
|
|
51
120
|
export declare function inAuthContext<N, I, O>(fn: OnCallWithAuthorizedNestContext<N, I, O>): OnCallWithNestContext<N, I, O>;
|