@dereekb/firebase-server 13.10.9 → 13.11.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/mailgun/package.json +9 -9
- package/model/package.json +9 -9
- package/oidc/index.cjs.js +166 -2
- package/oidc/index.esm.js +161 -4
- package/oidc/package.json +10 -10
- package/oidc/src/lib/controller/oidc.provider.controller.d.ts +16 -1
- package/oidc/src/lib/index.d.ts +1 -0
- package/oidc/src/lib/scope.d.ts +59 -0
- package/oidc/src/lib/service/oidc.auth.d.ts +20 -0
- package/package.json +10 -10
- package/src/lib/nest/model/index.d.ts +1 -0
- package/test/index.cjs.js +137 -18
- package/test/index.esm.js +137 -18
- package/test/package.json +11 -11
- package/test/src/lib/firebase/firebase.admin.auth.d.ts +37 -10
- package/test/src/lib/firebase/firebase.admin.collection.d.ts +3 -0
- package/test/src/lib/firebase/firebase.admin.function.d.ts +2 -0
- package/test/src/lib/firebase/firebase.admin.nest.d.ts +3 -0
- package/test/src/lib/firebase/firebase.admin.nest.function.callable.context.d.ts +3 -0
- package/test/src/lib/firebase/firebase.admin.nest.function.cloud.context.d.ts +3 -0
- package/test/src/lib/firebase/firebase.admin.nest.function.d.ts +4 -0
- package/test/src/lib/firebase/firebase.d.ts +13 -0
- package/test/src/lib/firebase/firebase.function.d.ts +19 -0
- package/test/src/lib/firebase/firebase.test.d.ts +2 -2
- package/test/src/lib/firestore/firestore.d.ts +1 -0
- package/test/src/lib/oidc/oidc.test.fixture.d.ts +17 -0
- package/test/src/lib/oidc/oidc.test.flow.d.ts +25 -1
- package/test/src/lib/storage/storage.d.ts +1 -0
- package/zoho/package.json +9 -9
|
@@ -37,6 +37,8 @@ export interface FirebaseAdminTestEnvironmentConfig {
|
|
|
37
37
|
*
|
|
38
38
|
* Useful for guarding against double-initialization or verifying that setup has completed
|
|
39
39
|
* before creating test contexts.
|
|
40
|
+
*
|
|
41
|
+
* @returns `true` once {@link initFirebaseAdminTestEnvironment} has run successfully; otherwise `false`.
|
|
40
42
|
*/
|
|
41
43
|
export declare function isAdminEnvironmentInitialized(): boolean;
|
|
42
44
|
/**
|
|
@@ -45,6 +47,8 @@ export declare function isAdminEnvironmentInitialized(): boolean;
|
|
|
45
47
|
* The generated ID has the format `firebase-test-<epoch-millis>`, ensuring each test run
|
|
46
48
|
* operates against an isolated project namespace in the emulators.
|
|
47
49
|
*
|
|
50
|
+
* @returns A new project ID string of the form `firebase-test-<epoch-millis>`.
|
|
51
|
+
*
|
|
48
52
|
* @example
|
|
49
53
|
* ```ts
|
|
50
54
|
* const projectId = generateNewProjectId();
|
|
@@ -66,6 +70,8 @@ export declare function rollNewGCloudProjectEnvironmentVariable(): string;
|
|
|
66
70
|
* Reads the current `GCLOUD_PROJECT` environment variable.
|
|
67
71
|
*
|
|
68
72
|
* This is the "active" project ID that the Firebase Admin SDK resolves at runtime.
|
|
73
|
+
*
|
|
74
|
+
* @returns The current value of `process.env.GCLOUD_PROJECT`, or `undefined` when unset.
|
|
69
75
|
*/
|
|
70
76
|
export declare function getGCloudProjectId(): string | undefined;
|
|
71
77
|
/**
|
|
@@ -74,6 +80,8 @@ export declare function getGCloudProjectId(): string | undefined;
|
|
|
74
80
|
* This holds the canonical test project ID set during {@link rollNewGCloudProjectEnvironmentVariable},
|
|
75
81
|
* and is used by {@link applyFirebaseGCloudTestProjectIdToFirebaseConfigEnv} as the source of truth
|
|
76
82
|
* when re-applying the project ID after external libraries overwrite `FIREBASE_CONFIG`.
|
|
83
|
+
*
|
|
84
|
+
* @returns The current value of `process.env.GCLOUD_TEST_PROJECT`, or `undefined` when unset.
|
|
77
85
|
*/
|
|
78
86
|
export declare function getGCloudTestProjectId(): string | undefined;
|
|
79
87
|
/**
|
|
@@ -81,9 +89,14 @@ export declare function getGCloudTestProjectId(): string | undefined;
|
|
|
81
89
|
*
|
|
82
90
|
* This is done as some external testing libraries (firebase-functions-test) will overwrite but we want to enforce using our project id
|
|
83
91
|
* so that each component can also
|
|
92
|
+
*
|
|
93
|
+
* @returns The test project ID that was re-applied to `FIREBASE_CONFIG`/`GCLOUD_PROJECT`.
|
|
94
|
+
* @throws Error when no test project ID is present in the environment (i.e., {@link initFirebaseAdminTestEnvironment} has not been called).
|
|
84
95
|
*/
|
|
85
96
|
export declare function applyFirebaseGCloudTestProjectIdToFirebaseConfigEnv(): string;
|
|
86
97
|
/**
|
|
87
98
|
* Should be called before calling/using adminFirebaseTestBuilder(). This should only be called once.
|
|
99
|
+
*
|
|
100
|
+
* @param config - Emulator host configuration; each emulator entry must be either a host string or `null` (any `undefined` non-null value will throw).
|
|
88
101
|
*/
|
|
89
102
|
export declare function initFirebaseAdminTestEnvironment(config: FirebaseAdminTestEnvironmentConfig): void;
|
|
@@ -166,6 +166,9 @@ export interface FirebaseAdminCloudFunctionWrapper {
|
|
|
166
166
|
* callable requests, and blocking functions for use in integration tests. Each method delegates
|
|
167
167
|
* to the underlying `FeaturesList.wrap()` with appropriate type coercion.
|
|
168
168
|
*
|
|
169
|
+
* @param instance - The initialized `firebase-functions-test` features list whose `wrap()` is delegated to.
|
|
170
|
+
* @returns A wrapper object exposing typed `wrap*` helpers for gen 1, gen 2, callable, and blocking functions.
|
|
171
|
+
*
|
|
169
172
|
* @example
|
|
170
173
|
* ```ts
|
|
171
174
|
* const testEnv = functionsTest();
|
|
@@ -181,6 +184,10 @@ export declare function firebaseAdminCloudFunctionWrapper(instance: FeaturesList
|
|
|
181
184
|
* The returned getter re-wraps on every invocation, so it always reflects the latest function
|
|
182
185
|
* reference from the provided getter — useful when the function under test is re-created between tests.
|
|
183
186
|
*
|
|
187
|
+
* @param wrapper - The cloud function wrapper providing gen 1 wrap support.
|
|
188
|
+
* @param getter - Lazy accessor for the gen 1 cloud function under test; re-evaluated on every getter call.
|
|
189
|
+
* @returns A getter that, when invoked, returns a freshly wrapped gen 1 cloud function ready for invocation in tests.
|
|
190
|
+
*
|
|
184
191
|
* @example
|
|
185
192
|
* ```ts
|
|
186
193
|
* const getWrapped = wrapCloudFunctionV1ForTests(wrapper, () => myV1Function);
|
|
@@ -196,6 +203,10 @@ export declare function wrapCloudFunctionV1ForTests<I, T extends WrapCloudFuncti
|
|
|
196
203
|
* Re-wraps on every invocation so it always reflects the latest function reference,
|
|
197
204
|
* which is important when the function under test is re-created between test cases.
|
|
198
205
|
*
|
|
206
|
+
* @param wrapper - The cloud function wrapper providing gen 2 wrap support.
|
|
207
|
+
* @param getter - Lazy accessor for the gen 2 cloud function under test; re-evaluated on every getter call.
|
|
208
|
+
* @returns A getter that, when invoked, returns a freshly wrapped gen 2 cloud function ready for invocation in tests.
|
|
209
|
+
*
|
|
199
210
|
* @example
|
|
200
211
|
* ```ts
|
|
201
212
|
* const getWrapped = wrapCloudFunctionV2ForTests(wrapper, () => myV2CloudFunction);
|
|
@@ -210,6 +221,10 @@ export declare function wrapCloudFunctionV2ForTests<E extends CloudEvent<unknown
|
|
|
210
221
|
* This is the most general wrapper — use it when you do not need to distinguish between
|
|
211
222
|
* function generations in your test setup.
|
|
212
223
|
*
|
|
224
|
+
* @param wrapper - The cloud function wrapper providing the unified `wrapCloudFunction` accessor.
|
|
225
|
+
* @param getter - Lazy accessor for the cloud function under test (gen 1 or gen 2); re-evaluated on every getter call.
|
|
226
|
+
* @returns A getter that, when invoked, returns a freshly wrapped cloud function exposing the unified `WrappedCloudFunction` signature.
|
|
227
|
+
*
|
|
213
228
|
* @example
|
|
214
229
|
* ```ts
|
|
215
230
|
* const getWrapped = wrapCloudFunctionTests(wrapper, () => myFunction);
|
|
@@ -223,6 +238,10 @@ export declare function wrapCloudFunctionTests<I extends object>(wrapper: Fireba
|
|
|
223
238
|
* The wrapped callable accepts raw data and {@link CallableContextOptions} (e.g., auth context),
|
|
224
239
|
* simulating an incoming HTTP callable request without needing a running server.
|
|
225
240
|
*
|
|
241
|
+
* @param wrapper - The cloud function wrapper providing the `wrapCallableRequest` accessor.
|
|
242
|
+
* @param getter - Lazy accessor for the {@link CallableHttpFunction} under test; re-evaluated on every getter call.
|
|
243
|
+
* @returns A getter that, when invoked, returns a freshly wrapped callable that accepts raw `data` and {@link CallableContextOptions}.
|
|
244
|
+
*
|
|
226
245
|
* @example
|
|
227
246
|
* ```ts
|
|
228
247
|
* const getWrapped = wrapCallableRequestForTests(wrapper, () => myCallable);
|
|
@@ -15,8 +15,8 @@ export declare class ExpectedHttpErrorWithSpecificServerErrorCode extends BaseEr
|
|
|
15
15
|
* Throws a ExpectedErrorOfSpecificTypeError if the input is not a HttpsError.
|
|
16
16
|
* Throws a ExpectedHttpErrorWithSpecificServerErrorCode if the input's server error data has a different error code.
|
|
17
17
|
*
|
|
18
|
-
* @param
|
|
19
|
-
* @returns
|
|
18
|
+
* @param expectedCode - The server error code (from the {@link ServerError} carried in `HttpsError.details`) that the caught error must match.
|
|
19
|
+
* @returns An assertion function suitable for use with `ExpectFailAssertionFunction` that verifies both the error type and its server error code.
|
|
20
20
|
*/
|
|
21
21
|
export declare function expectFailAssertHttpErrorServerErrorCode(expectedCode: string): ExpectFailAssertionFunction;
|
|
22
22
|
/**
|
|
@@ -22,6 +22,7 @@ export type GoogleCloudTestFirestoreContext = TestFirestoreContext;
|
|
|
22
22
|
*
|
|
23
23
|
* @param drivers - Testing-aware Firestore driver set to attach to the context.
|
|
24
24
|
* @param firestore - The `@google-cloud/firestore` Firestore instance (typically pointed at an emulator).
|
|
25
|
+
* @returns A {@link TestFirestoreContext} backed by the supplied Firestore client with `drivers` attached for test introspection.
|
|
25
26
|
*/
|
|
26
27
|
export declare function makeGoogleFirestoreContext(drivers: TestingFirestoreDrivers, firestore: Firestore): TestFirestoreContext;
|
|
27
28
|
/**
|
|
@@ -56,6 +56,9 @@ export declare class OAuthAuthorizedSuperTestInstance {
|
|
|
56
56
|
/**
|
|
57
57
|
* Apply Bearer auth to a supertest request.
|
|
58
58
|
*
|
|
59
|
+
* @param test - An existing supertest request (e.g., `request(server).get(...)`) that should be authorized with this instance's access token.
|
|
60
|
+
* @returns The same supertest request with an `Authorization: Bearer <accessToken>` header applied for chaining.
|
|
61
|
+
*
|
|
59
62
|
* @example
|
|
60
63
|
* ```typescript
|
|
61
64
|
* await oauth.withAuth(request(oauth.server).get('/oidc/me')).expect(200);
|
|
@@ -66,6 +69,10 @@ export declare class OAuthAuthorizedSuperTestInstance {
|
|
|
66
69
|
/**
|
|
67
70
|
* Shorthand: create a supertest request with auth already applied.
|
|
68
71
|
*
|
|
72
|
+
* @param method - HTTP verb to use for the supertest request (`get`, `post`, `put`, `patch`, or `delete`).
|
|
73
|
+
* @param path - The URL path on the wrapped server to issue the request against.
|
|
74
|
+
* @returns A supertest request pointed at `path` and pre-authorized with this instance's `Bearer` access token.
|
|
75
|
+
*
|
|
69
76
|
* @example
|
|
70
77
|
* ```typescript
|
|
71
78
|
* await oauth.authRequest('get', '/oidc/me').expect(200);
|
|
@@ -83,6 +90,9 @@ export declare class OAuthAuthorizedSuperTestFixture extends AbstractTestContext
|
|
|
83
90
|
/**
|
|
84
91
|
* Apply Bearer auth to a supertest request.
|
|
85
92
|
*
|
|
93
|
+
* @param test - An existing supertest request (e.g., `request(server).get(...)`) that should be authorized with the underlying instance's access token.
|
|
94
|
+
* @returns The same supertest request with an `Authorization: Bearer <accessToken>` header applied for chaining.
|
|
95
|
+
*
|
|
86
96
|
* @example
|
|
87
97
|
* ```typescript
|
|
88
98
|
* await oauth.withAuth(request(oauth.server).get('/oidc/me')).expect(200);
|
|
@@ -92,6 +102,10 @@ export declare class OAuthAuthorizedSuperTestFixture extends AbstractTestContext
|
|
|
92
102
|
/**
|
|
93
103
|
* Shorthand: create a supertest request with auth already applied.
|
|
94
104
|
*
|
|
105
|
+
* @param method - HTTP verb to use for the supertest request (`get`, `post`, `put`, `patch`, or `delete`).
|
|
106
|
+
* @param path - The URL path on the wrapped server to issue the request against.
|
|
107
|
+
* @returns A supertest request pointed at `path` and pre-authorized with the underlying instance's `Bearer` access token.
|
|
108
|
+
*
|
|
95
109
|
* @example
|
|
96
110
|
* ```typescript
|
|
97
111
|
* await oauth.authRequest('get', '/oidc/me').expect(200);
|
|
@@ -106,6 +120,9 @@ export declare class OAuthAuthorizedSuperTestFixture extends AbstractTestContext
|
|
|
106
120
|
* The returned factory function performs a full OAuth authorization code flow
|
|
107
121
|
* and provides an authenticated supertest agent and helper methods.
|
|
108
122
|
*
|
|
123
|
+
* @param config - Optional flow overrides (scopes, redirect URI, client name, timeout) and custom fixture/instance constructors.
|
|
124
|
+
* @returns A function that, given parent fixtures and a `buildTests` callback, registers a `describe('(oauth)', ...)` block which performs the full OAuth flow and exposes the authenticated supertest fixture.
|
|
125
|
+
*
|
|
109
126
|
* @example
|
|
110
127
|
* ```typescript
|
|
111
128
|
* // In shared test setup (e.g. fixture.oidc.ts)
|
|
@@ -28,16 +28,40 @@ export interface PerformFullOAuthFlowResult {
|
|
|
28
28
|
readonly accessToken: string;
|
|
29
29
|
readonly idToken: string;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Input for {@link performFullOAuthFlow}.
|
|
33
|
+
*/
|
|
34
|
+
export interface PerformFullOAuthFlowInput {
|
|
35
|
+
readonly server: ReturnType<INestApplication['getHttpServer']>;
|
|
36
|
+
readonly oidcClientService: OidcClientService;
|
|
37
|
+
readonly nestApp: INestApplication;
|
|
38
|
+
readonly uid: string;
|
|
39
|
+
readonly config?: OAuthTestFlowConfig;
|
|
40
|
+
}
|
|
31
41
|
/**
|
|
32
42
|
* Performs the full OAuth authorization code flow with PKCE and returns tokens.
|
|
33
43
|
*
|
|
34
44
|
* Steps: create client → PKCE → auth redirect → login → consent → code exchange → token
|
|
45
|
+
*
|
|
46
|
+
* @param input - Bag of services and overrides needed to drive the flow end-to-end.
|
|
47
|
+
* @param input.server - HTTP server returned by `nestApp.getHttpServer()` against which all supertest requests are issued.
|
|
48
|
+
* @param input.oidcClientService - Service used to create the OAuth client whose credentials drive the flow.
|
|
49
|
+
* @param input.nestApp - Initialized NestJS application; used to resolve {@link OidcAccountService} for project-id-derived ID tokens and default scopes.
|
|
50
|
+
* @param input.uid - Firebase user ID for whom the test ID token is minted and the OAuth flow is authorized.
|
|
51
|
+
* @param input.config - Optional flow overrides (scopes, redirect URI, client name, token endpoint auth method).
|
|
52
|
+
* @returns The exchanged access token and ID token from the OIDC `/token` endpoint.
|
|
53
|
+
* @throws Error when the token exchange step fails (the response body and status are included in the message).
|
|
35
54
|
*/
|
|
36
|
-
export declare function performFullOAuthFlow(
|
|
55
|
+
export declare function performFullOAuthFlow(input: PerformFullOAuthFlowInput): Promise<PerformFullOAuthFlowResult>;
|
|
37
56
|
/**
|
|
38
57
|
* Higher-level helper that resolves OIDC services from the NestJS DI container,
|
|
39
58
|
* rotates JWKS keys, and then performs the full OAuth flow.
|
|
40
59
|
*
|
|
41
60
|
* This avoids callers needing to import from `@dereekb/firebase-server/oidc` directly.
|
|
61
|
+
*
|
|
62
|
+
* @param nestApp - Initialized NestJS application from which {@link JwksService} and {@link OidcClientService} are resolved.
|
|
63
|
+
* @param uid - Firebase user ID for whom the OAuth flow is authorized.
|
|
64
|
+
* @param config - Optional flow overrides (scopes, redirect URI, client name, token endpoint auth method).
|
|
65
|
+
* @returns The exchanged access token and ID token from {@link performFullOAuthFlow}.
|
|
42
66
|
*/
|
|
43
67
|
export declare function setupAndPerformFullOAuthFlow(nestApp: INestApplication, uid: string, config?: OAuthTestFlowConfig): Promise<PerformFullOAuthFlowResult>;
|
|
@@ -22,6 +22,7 @@ export type GoogleCloudTestFirebaseStorageContext = TestFirebaseStorageContext;
|
|
|
22
22
|
* @param drivers - Testing-aware storage driver set to attach to the context.
|
|
23
23
|
* @param firebaseStorage - The `@google-cloud/storage` Storage instance (typically pointed at an emulator).
|
|
24
24
|
* @param defaultBucketId - Optional default bucket name; when provided, storage operations that omit a bucket will use this.
|
|
25
|
+
* @returns A {@link TestFirebaseStorageContext} backed by the supplied storage client with `drivers` attached for test introspection.
|
|
25
26
|
*/
|
|
26
27
|
export declare function makeGoogleFirebaseStorageContext(drivers: TestingFirebaseStorageDrivers, firebaseStorage: FirebaseStorage, defaultBucketId?: string): TestFirebaseStorageContext;
|
|
27
28
|
/**
|
package/zoho/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/firebase-server/zoho",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.11.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@dereekb/analytics": "13.
|
|
6
|
-
"@dereekb/date": "13.
|
|
7
|
-
"@dereekb/model": "13.
|
|
8
|
-
"@dereekb/nestjs": "13.
|
|
9
|
-
"@dereekb/rxjs": "13.
|
|
10
|
-
"@dereekb/firebase": "13.
|
|
11
|
-
"@dereekb/util": "13.
|
|
12
|
-
"@dereekb/zoho": "13.
|
|
5
|
+
"@dereekb/analytics": "13.11.0",
|
|
6
|
+
"@dereekb/date": "13.11.0",
|
|
7
|
+
"@dereekb/model": "13.11.0",
|
|
8
|
+
"@dereekb/nestjs": "13.11.0",
|
|
9
|
+
"@dereekb/rxjs": "13.11.0",
|
|
10
|
+
"@dereekb/firebase": "13.11.0",
|
|
11
|
+
"@dereekb/util": "13.11.0",
|
|
12
|
+
"@dereekb/zoho": "13.11.0"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
"./package.json": "./package.json",
|