@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/test/index.esm.js CHANGED
@@ -336,6 +336,9 @@ function _ts_generator$a(thisArg, body) {
336
336
  * where non-JSON-safe values (e.g., `Date` instances, `undefined` fields) are stripped
337
337
  * or transformed. Used internally by {@link AuthorizedUserTestContextInstance.callWrappedFunction}
338
338
  * to ensure test params match real-world serialization behavior.
339
+ *
340
+ * @param object - Arbitrary value to round-trip through `JSON.stringify` then `JSON.parse`.
341
+ * @returns The input value after a JSON serialize/parse cycle, with any non-JSON-safe fields stripped.
339
342
  */ function convertParamsToParsedJsonObjectAndBack(object) {
340
343
  var paramsAsJson = JSON.parse(JSON.stringify(object));
341
344
  return paramsAsJson;
@@ -419,9 +422,10 @@ function _ts_generator$a(thisArg, body) {
419
422
  /**
420
423
  * Calls a wrapped function with the input params and the context from makeContextOptions().
421
424
  *
422
- * @param fn
423
- * @param params
424
- * @param skipJsonConversion
425
+ * @param fn - Wrapped gen 2 callable request to invoke.
426
+ * @param params - Request payload to pass to the callable, simulating the JSON body of an HTTP call.
427
+ * @param skipJsonConversion - When `true`, skip the JSON serialize/parse round-trip applied to `params` (default `false`).
428
+ * @returns A promise resolving to the callable's return value.
425
429
  */ key: "callWrappedFunction",
426
430
  value: function callWrappedFunction(fn, params, skipJsonConversion) {
427
431
  // Parse to JSON then back to simulate sending JSON to the server, and the server parsing it as a POJO.
@@ -448,15 +452,19 @@ function _ts_generator$a(thisArg, body) {
448
452
  /**
449
453
  * Calls a wrapped gen 2 auth blocking function with the input params and context options from makeContextOptions().
450
454
  *
451
- * @param fn
452
- * @param userRecord
453
- * @param eventType
454
- * @param eventOverride
455
- * @param skipJsonConversion
456
- * @returns
455
+ * Synthesizes a minimal {@link AuthBlockingEvent} (filling in placeholder ip/user-agent/resource fields)
456
+ * from the supplied user record and event type, then dispatches it to the wrapped function.
457
+ *
458
+ * @param input - Options bag describing the blocking function invocation.
459
+ * @param input.fn - Wrapped gen 2 auth blocking function (e.g., from `beforeUserCreated`/`beforeUserSignedIn`) to invoke.
460
+ * @param input.userRecord - The Firebase Auth {@link UserRecord} that will be attached to the synthesized event's `data` field.
461
+ * @param input.eventType - Discriminator for the auth event being simulated (`google.firebase.auth.user.create` or `google.firebase.auth.user.delete`).
462
+ * @param input.eventOverride - Partial event fields used to override the default placeholder values (e.g., `ipAddress`, `userAgent`, `resource`).
463
+ * @param input.skipJsonConversion - When `true`, skip the JSON serialize/parse round-trip applied to the event payload (default `false`).
464
+ * @returns A promise that resolves once the blocking function has completed.
457
465
  */ key: "callAuthBlockingFunction",
458
- value: function callAuthBlockingFunction(fn, userRecord, eventType, eventOverride) {
459
- var skipJsonConversion = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : false;
466
+ value: function callAuthBlockingFunction(input) {
467
+ var fn = input.fn, userRecord = input.userRecord, eventType = input.eventType, eventOverride = input.eventOverride, _input_skipJsonConversion = input.skipJsonConversion, skipJsonConversion = _input_skipJsonConversion === void 0 ? false : _input_skipJsonConversion;
460
468
  var timestamp = new Date().toISOString();
461
469
  var event = _object_spread_props$3(_object_spread$5({
462
470
  ipAddress: '127.0.0.1',
@@ -484,7 +492,8 @@ function _ts_generator$a(thisArg, body) {
484
492
  * @param contextOptions
485
493
  * @param skipJsonConversion
486
494
  * @returns
487
- */ key: "callEventCloudFunction",
495
+ */ // eslint-disable-next-line @typescript-eslint/max-params -- deprecated gen 1 signature kept for downstream compatibility
496
+ key: "callEventCloudFunction",
488
497
  value: function callEventCloudFunction(fn, params, contextOptions) {
489
498
  var skipJsonConversion = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
490
499
  var parsedParams = params == null || skipJsonConversion ? params : convertParamsToParsedJsonObjectAndBack(params);
@@ -498,6 +507,9 @@ function _ts_generator$a(thisArg, body) {
498
507
  }();
499
508
  /**
500
509
  * Convenience function for using authorizedUserContextFactory directly and passing buildTests.
510
+ *
511
+ * @param config - Test context parameters (parent fixture, optional uid/template, custom factories) used to create the authorized user context.
512
+ * @param buildTests - Callback invoked with the built {@link AuthorizedUserTestContextFixture}; should register `it(...)`/`describe(...)` blocks against it.
501
513
  */ function authorizedUserContext(config, buildTests) {
502
514
  authorizedUserContextFactory(config)({
503
515
  f: config.f
@@ -517,6 +529,13 @@ function _ts_generator$a(thisArg, body) {
517
529
  */ var AUTHORIZED_USER_RANDOM_PHONE_NUMBER_FACTORY = randomPhoneNumberFactory();
518
530
  /**
519
531
  * Creates a new Jest Context that has a random user for authorization for use in firebase server tests.
532
+ *
533
+ * The returned function, when called with runtime params and a `buildTests` callback, registers the
534
+ * `beforeEach`/`afterEach` lifecycle hooks that create the test user (with optional contact info,
535
+ * custom claims, and post-create initialization) and tear it down afterward.
536
+ *
537
+ * @param config - Factory configuration: optional uid generator, custom fixture/instance constructors, user-detail builder, and `initUser` hook.
538
+ * @returns A function that, given runtime params and a `buildTests` callback, wires the authorized-user fixture into the active test context.
520
539
  */ function authorizedUserContextFactory(config) {
521
540
  var uidGetter = config.uid, _config_makeInstance = config.makeInstance, makeInstance = _config_makeInstance === void 0 ? function(uid, testInstance) {
522
541
  return new AuthorizedUserTestContextInstance(uid, testInstance);
@@ -751,6 +770,9 @@ function _ts_generator$a(thisArg, body) {
751
770
  * in the JWT payload. This function flattens those claims onto the top-level decoded token to match
752
771
  * the structure of a real `DecodedIdToken`, and injects `auth_time` from the `iat` field.
753
772
  *
773
+ * @param token - Encoded JWT string produced by {@link createEncodedTestFirestoreTokenForUserRecord}.
774
+ * @returns A {@link DecodedIdToken}-shaped object with custom claims hoisted to the top level and `claims` removed.
775
+ *
754
776
  * @see {@link createEncodedTestFirestoreTokenForUserRecord} for creating the encoded token
755
777
  */ function decodeEncodedCreateCustomTokenResult(token) {
756
778
  var _ref;
@@ -770,6 +792,9 @@ function _ts_generator$a(thisArg, body) {
770
792
  * custom claims already set on the user record. The resulting object is used as the
771
793
  * custom claims parameter for `Auth.createCustomToken()` in test token generation.
772
794
  *
795
+ * @param userRecord - Firebase Auth user record whose identity fields and existing custom claims should be folded into the returned claims.
796
+ * @returns A plain claims object suitable for passing to `Auth.createCustomToken()` in tests.
797
+ *
773
798
  * @see {@link createEncodedTestFirestoreTokenForUserRecord}
774
799
  */ function testFirestoreClaimsFromUserRecord(userRecord) {
775
800
  var _userRecord_emailVerified;
@@ -1120,6 +1145,9 @@ function _ts_generator$9(thisArg, body) {
1120
1145
  * hooks that create a new document (or wrap an existing one via {@link ModelTestContextDocumentRefParams}),
1121
1146
  * build the test context instance, optionally initialize the document, and clean up after each test.
1122
1147
  *
1148
+ * @param config - Factory configuration that resolves the collection, optionally produces document refs, builds fixtures/instances, and tears down state.
1149
+ * @returns A function that, given runtime params and a `buildTests` callback, registers the model fixture hooks against the active test context.
1150
+ *
1123
1151
  * @see {@link ModelTestContextFactoryParams} for configuration options
1124
1152
  */ function modelTestContextFactory(config) {
1125
1153
  var getCollection = config.getCollection, collectionForDocument = config.collectionForDocument, _config_makeRef = config.makeRef, makeRef = _config_makeRef === void 0 ? function(collection) {
@@ -1217,6 +1245,8 @@ var adminEnvironmentInitialized = false;
1217
1245
  *
1218
1246
  * Useful for guarding against double-initialization or verifying that setup has completed
1219
1247
  * before creating test contexts.
1248
+ *
1249
+ * @returns `true` once {@link initFirebaseAdminTestEnvironment} has run successfully; otherwise `false`.
1220
1250
  */ function isAdminEnvironmentInitialized() {
1221
1251
  return adminEnvironmentInitialized;
1222
1252
  }
@@ -1226,6 +1256,8 @@ var adminEnvironmentInitialized = false;
1226
1256
  * The generated ID has the format `firebase-test-<epoch-millis>`, ensuring each test run
1227
1257
  * operates against an isolated project namespace in the emulators.
1228
1258
  *
1259
+ * @returns A new project ID string of the form `firebase-test-<epoch-millis>`.
1260
+ *
1229
1261
  * @example
1230
1262
  * ```ts
1231
1263
  * const projectId = generateNewProjectId();
@@ -1253,6 +1285,8 @@ var adminEnvironmentInitialized = false;
1253
1285
  * Reads the current `GCLOUD_PROJECT` environment variable.
1254
1286
  *
1255
1287
  * This is the "active" project ID that the Firebase Admin SDK resolves at runtime.
1288
+ *
1289
+ * @returns The current value of `process.env.GCLOUD_PROJECT`, or `undefined` when unset.
1256
1290
  */ function getGCloudProjectId() {
1257
1291
  return process.env.GCLOUD_PROJECT;
1258
1292
  }
@@ -1262,6 +1296,8 @@ var adminEnvironmentInitialized = false;
1262
1296
  * This holds the canonical test project ID set during {@link rollNewGCloudProjectEnvironmentVariable},
1263
1297
  * and is used by {@link applyFirebaseGCloudTestProjectIdToFirebaseConfigEnv} as the source of truth
1264
1298
  * when re-applying the project ID after external libraries overwrite `FIREBASE_CONFIG`.
1299
+ *
1300
+ * @returns The current value of `process.env.GCLOUD_TEST_PROJECT`, or `undefined` when unset.
1265
1301
  */ function getGCloudTestProjectId() {
1266
1302
  return process.env.GCLOUD_TEST_PROJECT;
1267
1303
  }
@@ -1270,6 +1306,9 @@ var adminEnvironmentInitialized = false;
1270
1306
  *
1271
1307
  * This is done as some external testing libraries (firebase-functions-test) will overwrite but we want to enforce using our project id
1272
1308
  * so that each component can also
1309
+ *
1310
+ * @returns The test project ID that was re-applied to `FIREBASE_CONFIG`/`GCLOUD_PROJECT`.
1311
+ * @throws Error when no test project ID is present in the environment (i.e., {@link initFirebaseAdminTestEnvironment} has not been called).
1273
1312
  */ function applyFirebaseGCloudTestProjectIdToFirebaseConfigEnv() {
1274
1313
  var _process_env_FIREBASE_CONFIG;
1275
1314
  // firebase-functions-test overwrites this each time.
@@ -1287,6 +1326,8 @@ var adminEnvironmentInitialized = false;
1287
1326
  }
1288
1327
  /**
1289
1328
  * Should be called before calling/using adminFirebaseTestBuilder(). This should only be called once.
1329
+ *
1330
+ * @param config - Emulator host configuration; each emulator entry must be either a host string or `null` (any `undefined` non-null value will throw).
1290
1331
  */ function initFirebaseAdminTestEnvironment(config) {
1291
1332
  function crashForEmulator(emulator) {
1292
1333
  throw new Error("Emulator for ".concat(emulator, " was not set null or to a host. Crashing to prevent contamination."));
@@ -1503,6 +1544,7 @@ function _ts_generator$8(thisArg, body) {
1503
1544
  *
1504
1545
  * @param drivers - Testing-aware Firestore driver set to attach to the context.
1505
1546
  * @param firestore - The `@google-cloud/firestore` Firestore instance (typically pointed at an emulator).
1547
+ * @returns A {@link TestFirestoreContext} backed by the supplied Firestore client with `drivers` attached for test introspection.
1506
1548
  */ function makeGoogleFirestoreContext(drivers, firestore) {
1507
1549
  var context = firestoreContextFactory(drivers)(firestore);
1508
1550
  context.drivers = drivers;
@@ -1791,6 +1833,7 @@ function _ts_generator$7(thisArg, body) {
1791
1833
  * @param drivers - Testing-aware storage driver set to attach to the context.
1792
1834
  * @param firebaseStorage - The `@google-cloud/storage` Storage instance (typically pointed at an emulator).
1793
1835
  * @param defaultBucketId - Optional default bucket name; when provided, storage operations that omit a bucket will use this.
1836
+ * @returns A {@link TestFirebaseStorageContext} backed by the supplied storage client with `drivers` attached for test introspection.
1794
1837
  */ function makeGoogleFirebaseStorageContext(drivers, firebaseStorage, defaultBucketId) {
1795
1838
  var context = firebaseStorageContextFactory(drivers)(firebaseStorage, {
1796
1839
  defaultBucketId: defaultBucketId
@@ -2616,6 +2659,9 @@ function _ts_generator$5(thisArg, body) {
2616
2659
  * callable requests, and blocking functions for use in integration tests. Each method delegates
2617
2660
  * to the underlying `FeaturesList.wrap()` with appropriate type coercion.
2618
2661
  *
2662
+ * @param instance - The initialized `firebase-functions-test` features list whose `wrap()` is delegated to.
2663
+ * @returns A wrapper object exposing typed `wrap*` helpers for gen 1, gen 2, callable, and blocking functions.
2664
+ *
2619
2665
  * @example
2620
2666
  * ```ts
2621
2667
  * const testEnv = functionsTest();
@@ -2681,6 +2727,10 @@ function _ts_generator$5(thisArg, body) {
2681
2727
  * The returned getter re-wraps on every invocation, so it always reflects the latest function
2682
2728
  * reference from the provided getter — useful when the function under test is re-created between tests.
2683
2729
  *
2730
+ * @param wrapper - The cloud function wrapper providing gen 1 wrap support.
2731
+ * @param getter - Lazy accessor for the gen 1 cloud function under test; re-evaluated on every getter call.
2732
+ * @returns A getter that, when invoked, returns a freshly wrapped gen 1 cloud function ready for invocation in tests.
2733
+ *
2684
2734
  * @example
2685
2735
  * ```ts
2686
2736
  * const getWrapped = wrapCloudFunctionV1ForTests(wrapper, () => myV1Function);
@@ -2699,6 +2749,10 @@ function _ts_generator$5(thisArg, body) {
2699
2749
  * The wrapped callable accepts raw data and {@link CallableContextOptions} (e.g., auth context),
2700
2750
  * simulating an incoming HTTP callable request without needing a running server.
2701
2751
  *
2752
+ * @param wrapper - The cloud function wrapper providing the `wrapCallableRequest` accessor.
2753
+ * @param getter - Lazy accessor for the {@link CallableHttpFunction} under test; re-evaluated on every getter call.
2754
+ * @returns A getter that, when invoked, returns a freshly wrapped callable that accepts raw `data` and {@link CallableContextOptions}.
2755
+ *
2702
2756
  * @example
2703
2757
  * ```ts
2704
2758
  * const getWrapped = wrapCallableRequestForTests(wrapper, () => myCallable);
@@ -3122,6 +3176,8 @@ var functionsInitialized = false;
3122
3176
  * Globally sets whether new {@link FirebaseAdminFunctionTestConfig} instances default to
3123
3177
  * singleton mode. Primarily used in global test setup files.
3124
3178
  *
3179
+ * @param use - When `true`, new function-test configs reuse the firebase-functions-test singleton; when `false`, each suite gets its own instance.
3180
+ *
3125
3181
  * @example
3126
3182
  * ```ts
3127
3183
  * // in jest globalSetup
@@ -3834,6 +3890,9 @@ function _ts_generator$3(thisArg, body) {
3834
3890
  * {@link firebaseAdminTestContextFactory}. This is the simplest way to get a
3835
3891
  * fully configured Firebase Admin + NestJS test context.
3836
3892
  *
3893
+ * @param config - NestJS module + provider configuration plus optional fixture/instance overrides.
3894
+ * @returns A {@link FirebaseAdminNestTestContextFactory} that produces a configured fixture for each test suite.
3895
+ *
3837
3896
  * @example
3838
3897
  * ```ts
3839
3898
  * const f = firebaseAdminNestContextFactory({
@@ -4078,6 +4137,7 @@ function _is_native_reflect_construct$2() {
4078
4137
  * @param config - NestJS module, provider, and fixture configuration.
4079
4138
  * @param f - The parent fixture that is already set up.
4080
4139
  * @param buildTests - Callback that receives the child fixture and registers test cases.
4140
+ * @returns Whatever {@link firebaseAdminNestContextWithFixture} returns after registering the merged child fixture (typically `void`).
4081
4141
  */ function firebaseAdminFunctionNestContextWithFixture(config, f, buildTests) {
4082
4142
  var mergedConfig = _object_spread({
4083
4143
  makeFixture: function makeFixture(parent) {
@@ -4094,6 +4154,9 @@ function _is_native_reflect_construct$2() {
4094
4154
  * default {@link firebaseAdminFunctionTestContextFactory}. This is the simplest entry point
4095
4155
  * for tests that need both NestJS module access and Cloud Function wrapping.
4096
4156
  *
4157
+ * @param config - NestJS module + provider configuration plus optional fixture/instance overrides.
4158
+ * @returns A {@link FirebaseAdminFunctionNestTestContextFactory} that produces a configured fixture for each test suite.
4159
+ *
4097
4160
  * @example
4098
4161
  * ```ts
4099
4162
  * const f = firebaseAdminFunctionNestContextFactory({
@@ -4119,6 +4182,9 @@ var CallableRequestTestMultipleFixtureSuffix = 'WrappedFn';
4119
4182
  /**
4120
4183
  * Type guard that distinguishes a {@link CallableRequestTestSingleConfig} from a
4121
4184
  * {@link CallableRequestTestMultipleConfig} by checking for the presence of the `fn` property.
4185
+ *
4186
+ * @param config - Either a single-function or multiple-function callable test config to inspect.
4187
+ * @returns `true` when `config` carries a single `fn` (single-config variant); `false` when it carries `fns` (map variant).
4122
4188
  */ function isCallableRequestTestSingleConfig(config) {
4123
4189
  return Boolean(config.fn);
4124
4190
  }
@@ -4155,6 +4221,9 @@ function describeCallableRequestTest(label, config, buildTests) {
4155
4221
  /**
4156
4222
  * Type guard that distinguishes a {@link CloudFunctionTestSingleConfig} from a
4157
4223
  * {@link CloudFunctionTestMultipleConfig} by checking for the presence of the `fn` property.
4224
+ *
4225
+ * @param config - Either a single-function or multiple-function cloud function test config to inspect.
4226
+ * @returns `true` when `config` carries a single `fn` (single-config variant); `false` when it carries `fns` (map variant).
4158
4227
  */ function isCloudFunctionTestSingleConfig(config) {
4159
4228
  return Boolean(config.fn);
4160
4229
  }
@@ -4500,8 +4569,8 @@ function _is_native_reflect_construct$1() {
4500
4569
  * Throws a ExpectedErrorOfSpecificTypeError if the input is not a HttpsError.
4501
4570
  * Throws a ExpectedHttpErrorWithSpecificServerErrorCode if the input's server error data has a different error code.
4502
4571
  *
4503
- * @param expectedType
4504
- * @returns
4572
+ * @param expectedCode - The server error code (from the {@link ServerError} carried in `HttpsError.details`) that the caught error must match.
4573
+ * @returns An assertion function suitable for use with `ExpectFailAssertionFunction` that verifies both the error type and its server error code.
4505
4574
  */ function expectFailAssertHttpErrorServerErrorCode(expectedCode) {
4506
4575
  return function(error) {
4507
4576
  if (_instanceof(error, HttpsError)) {
@@ -4736,6 +4805,10 @@ function _ts_generator$1(thisArg, body) {
4736
4805
  *
4737
4806
  * The Auth emulator accepts unsigned JWTs (alg: "none") as long as the audience
4738
4807
  * matches the project ID the Admin SDK was initialized with.
4808
+ *
4809
+ * @param nestApp - Initialized NestJS application used to resolve {@link OidcAccountService} for the project ID.
4810
+ * @param uid - Firebase user ID to embed in the token's `sub`/`user_id` claims.
4811
+ * @returns An unsigned JWT (`alg: "none"`) string suitable for use against the Firebase Auth emulator.
4739
4812
  */ function createTestIdToken(nestApp, uid) {
4740
4813
  return _async_to_generator$1(function() {
4741
4814
  var accountService, projectId, now, payload, header, body;
@@ -4770,6 +4843,9 @@ function _ts_generator$1(thisArg, body) {
4770
4843
  }
4771
4844
  /**
4772
4845
  * Extracts the interaction UID from a redirect to the login/consent frontend URL.
4846
+ *
4847
+ * @param res - Supertest response whose `Location` header points at the login/consent frontend, with `?uid=...` carrying the interaction UID.
4848
+ * @returns The `uid` query parameter from the redirect URL (the interaction identifier issued by `oidc-provider`).
4773
4849
  */ function extractInteractionUid(res) {
4774
4850
  var location = res.headers['location'];
4775
4851
  var url = location.startsWith('/') ? new URL(location, 'http://localhost') : new URL(location);
@@ -4780,6 +4856,8 @@ function _ts_generator$1(thisArg, body) {
4780
4856
  *
4781
4857
  * oidc-provider scopes cookies to specific paths, so supertest.agent()
4782
4858
  * won't forward them between /oidc/* and /interaction/* controllers.
4859
+ *
4860
+ * @returns A pair of helpers — `collectCookies(res)` to absorb `Set-Cookie` headers from a response, and `cookieHeader()` to produce a combined `Cookie` header string for subsequent requests.
4783
4861
  */ function createCookieJar() {
4784
4862
  var cookieJar = new Map();
4785
4863
  function collectCookies(res) {
@@ -4823,6 +4901,10 @@ function _ts_generator$1(thisArg, body) {
4823
4901
  /**
4824
4902
  * Resolves the scopes string from config, or falls back to all registered scopes
4825
4903
  * from `OidcAccountService.allRegisteredScopes`.
4904
+ *
4905
+ * @param nestApp - Initialized NestJS application used to resolve {@link OidcAccountService} when no scopes override is given.
4906
+ * @param config - Optional flow config; when `config.scopes` is set, it is returned verbatim.
4907
+ * @returns The space-separated scope string to pass to the `/oidc/auth` endpoint.
4826
4908
  */ function resolveScopes(nestApp, config) {
4827
4909
  return _async_to_generator$1(function() {
4828
4910
  var accountService;
@@ -4841,17 +4923,26 @@ function _ts_generator$1(thisArg, body) {
4841
4923
  });
4842
4924
  })();
4843
4925
  }
4844
- // MARK: Flow
4845
4926
  /**
4846
4927
  * Performs the full OAuth authorization code flow with PKCE and returns tokens.
4847
4928
  *
4848
4929
  * Steps: create client → PKCE → auth redirect → login → consent → code exchange → token
4849
- */ function performFullOAuthFlow(server, oidcClientService, nestApp, uid, config) {
4930
+ *
4931
+ * @param input - Bag of services and overrides needed to drive the flow end-to-end.
4932
+ * @param input.server - HTTP server returned by `nestApp.getHttpServer()` against which all supertest requests are issued.
4933
+ * @param input.oidcClientService - Service used to create the OAuth client whose credentials drive the flow.
4934
+ * @param input.nestApp - Initialized NestJS application; used to resolve {@link OidcAccountService} for project-id-derived ID tokens and default scopes.
4935
+ * @param input.uid - Firebase user ID for whom the test ID token is minted and the OAuth flow is authorized.
4936
+ * @param input.config - Optional flow overrides (scopes, redirect URI, client name, token endpoint auth method).
4937
+ * @returns The exchanged access token and ID token from the OIDC `/token` endpoint.
4938
+ * @throws Error when the token exchange step fails (the response body and status are included in the message).
4939
+ */ function performFullOAuthFlow(input) {
4850
4940
  return _async_to_generator$1(function() {
4851
- var _ref, _ref1, _ref2, _createCookieJar, collectCookies, cookieHeader, redirectUri, clientName, tokenEndpointAuthMethod, scopes, _ref3, client_id, client_secret, codeVerifier, codeChallenge, authRes, loginUid, idToken, loginRes, resumeAfterLoginPath, consentRedirectRes, consentUid, consentRes, resumeAfterConsentPath, callbackRedirectRes, callbackUrl, authorizationCode, tokenRes;
4941
+ var _ref, _ref1, _ref2, server, oidcClientService, nestApp, uid, config, _createCookieJar, collectCookies, cookieHeader, redirectUri, clientName, tokenEndpointAuthMethod, scopes, _ref3, client_id, client_secret, codeVerifier, codeChallenge, authRes, loginUid, idToken, loginRes, resumeAfterLoginPath, consentRedirectRes, consentUid, consentRes, resumeAfterConsentPath, callbackRedirectRes, callbackUrl, authorizationCode, tokenRes;
4852
4942
  return _ts_generator$1(this, function(_state) {
4853
4943
  switch(_state.label){
4854
4944
  case 0:
4945
+ server = input.server, oidcClientService = input.oidcClientService, nestApp = input.nestApp, uid = input.uid, config = input.config;
4855
4946
  _createCookieJar = createCookieJar(), collectCookies = _createCookieJar.collectCookies, cookieHeader = _createCookieJar.cookieHeader;
4856
4947
  redirectUri = (_ref = config === null || config === void 0 ? void 0 : config.redirectUri) !== null && _ref !== void 0 ? _ref : 'https://example.com/callback';
4857
4948
  clientName = (_ref1 = config === null || config === void 0 ? void 0 : config.clientName) !== null && _ref1 !== void 0 ? _ref1 : 'test-oauth-context';
@@ -4970,6 +5061,11 @@ function _ts_generator$1(thisArg, body) {
4970
5061
  * rotates JWKS keys, and then performs the full OAuth flow.
4971
5062
  *
4972
5063
  * This avoids callers needing to import from `@dereekb/firebase-server/oidc` directly.
5064
+ *
5065
+ * @param nestApp - Initialized NestJS application from which {@link JwksService} and {@link OidcClientService} are resolved.
5066
+ * @param uid - Firebase user ID for whom the OAuth flow is authorized.
5067
+ * @param config - Optional flow overrides (scopes, redirect URI, client name, token endpoint auth method).
5068
+ * @returns The exchanged access token and ID token from {@link performFullOAuthFlow}.
4973
5069
  */ function setupAndPerformFullOAuthFlow(nestApp, uid, config) {
4974
5070
  return _async_to_generator$1(function() {
4975
5071
  var jwksService, oidcClientService, server;
@@ -4989,7 +5085,13 @@ function _ts_generator$1(thisArg, body) {
4989
5085
  server = nestApp.getHttpServer();
4990
5086
  return [
4991
5087
  2,
4992
- performFullOAuthFlow(server, oidcClientService, nestApp, uid, config)
5088
+ performFullOAuthFlow({
5089
+ server: server,
5090
+ oidcClientService: oidcClientService,
5091
+ nestApp: nestApp,
5092
+ uid: uid,
5093
+ config: config
5094
+ })
4993
5095
  ];
4994
5096
  }
4995
5097
  });
@@ -5261,6 +5363,9 @@ function _ts_generator(thisArg, body) {
5261
5363
  /**
5262
5364
  * Apply Bearer auth to a supertest request.
5263
5365
  *
5366
+ * @param test - An existing supertest request (e.g., `request(server).get(...)`) that should be authorized with this instance's access token.
5367
+ * @returns The same supertest request with an `Authorization: Bearer <accessToken>` header applied for chaining.
5368
+ *
5264
5369
  * @example
5265
5370
  * ```typescript
5266
5371
  * await oauth.withAuth(request(oauth.server).get('/oidc/me')).expect(200);
@@ -5275,6 +5380,10 @@ function _ts_generator(thisArg, body) {
5275
5380
  /**
5276
5381
  * Shorthand: create a supertest request with auth already applied.
5277
5382
  *
5383
+ * @param method - HTTP verb to use for the supertest request (`get`, `post`, `put`, `patch`, or `delete`).
5384
+ * @param path - The URL path on the wrapped server to issue the request against.
5385
+ * @returns A supertest request pointed at `path` and pre-authorized with this instance's `Bearer` access token.
5386
+ *
5278
5387
  * @example
5279
5388
  * ```typescript
5280
5389
  * await oauth.authRequest('get', '/oidc/me').expect(200);
@@ -5314,6 +5423,9 @@ function _ts_generator(thisArg, body) {
5314
5423
  /**
5315
5424
  * Apply Bearer auth to a supertest request.
5316
5425
  *
5426
+ * @param test - An existing supertest request (e.g., `request(server).get(...)`) that should be authorized with the underlying instance's access token.
5427
+ * @returns The same supertest request with an `Authorization: Bearer <accessToken>` header applied for chaining.
5428
+ *
5317
5429
  * @example
5318
5430
  * ```typescript
5319
5431
  * await oauth.withAuth(request(oauth.server).get('/oidc/me')).expect(200);
@@ -5327,6 +5439,10 @@ function _ts_generator(thisArg, body) {
5327
5439
  /**
5328
5440
  * Shorthand: create a supertest request with auth already applied.
5329
5441
  *
5442
+ * @param method - HTTP verb to use for the supertest request (`get`, `post`, `put`, `patch`, or `delete`).
5443
+ * @param path - The URL path on the wrapped server to issue the request against.
5444
+ * @returns A supertest request pointed at `path` and pre-authorized with the underlying instance's `Bearer` access token.
5445
+ *
5330
5446
  * @example
5331
5447
  * ```typescript
5332
5448
  * await oauth.authRequest('get', '/oidc/me').expect(200);
@@ -5353,6 +5469,9 @@ function _ts_generator(thisArg, body) {
5353
5469
  * The returned factory function performs a full OAuth authorization code flow
5354
5470
  * and provides an authenticated supertest agent and helper methods.
5355
5471
  *
5472
+ * @param config - Optional flow overrides (scopes, redirect URI, client name, timeout) and custom fixture/instance constructors.
5473
+ * @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.
5474
+ *
5356
5475
  * @example
5357
5476
  * ```typescript
5358
5477
  * // In shared test setup (e.g. fixture.oidc.ts)
package/test/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@dereekb/firebase-server/test",
3
- "version": "13.10.9",
3
+ "version": "13.11.0",
4
4
  "peerDependencies": {
5
- "@dereekb/analytics": "13.10.9",
6
- "@dereekb/date": "13.10.9",
7
- "@dereekb/firebase": "13.10.9",
8
- "@dereekb/firebase-server": "13.10.9",
9
- "@dereekb/firebase-server/oidc": "13.10.9",
10
- "@dereekb/model": "13.10.9",
11
- "@dereekb/nestjs": "13.10.9",
12
- "@dereekb/rxjs": "13.10.9",
13
- "@dereekb/util": "13.10.9",
5
+ "@dereekb/analytics": "13.11.0",
6
+ "@dereekb/date": "13.11.0",
7
+ "@dereekb/firebase": "13.11.0",
8
+ "@dereekb/firebase-server": "13.11.0",
9
+ "@dereekb/firebase-server/oidc": "13.11.0",
10
+ "@dereekb/model": "13.11.0",
11
+ "@dereekb/nestjs": "13.11.0",
12
+ "@dereekb/rxjs": "13.11.0",
13
+ "@dereekb/util": "13.11.0",
14
14
  "@google-cloud/firestore": "^7.11.6",
15
15
  "@google-cloud/storage": "^7.19.0",
16
16
  "@nestjs/common": "^11.1.19",
@@ -23,7 +23,7 @@
23
23
  "supertest": "^7.2.2"
24
24
  },
25
25
  "devDependencies": {
26
- "@dereekb/nestjs": "13.10.9"
26
+ "@dereekb/nestjs": "13.11.0"
27
27
  },
28
28
  "exports": {
29
29
  "./package.json": "./package.json",
@@ -116,9 +116,10 @@ export declare class AuthorizedUserTestContextInstance<PI extends FirebaseAdminT
116
116
  /**
117
117
  * Calls a wrapped function with the input params and the context from makeContextOptions().
118
118
  *
119
- * @param fn
120
- * @param params
121
- * @param skipJsonConversion
119
+ * @param fn - Wrapped gen 2 callable request to invoke.
120
+ * @param params - Request payload to pass to the callable, simulating the JSON body of an HTTP call.
121
+ * @param skipJsonConversion - When `true`, skip the JSON serialize/parse round-trip applied to `params` (default `false`).
122
+ * @returns A promise resolving to the callable's return value.
122
123
  */
123
124
  callWrappedFunction<F extends WrappedCallableRequest<any, any>>(fn: F, params: WrappedCallableRequestParams<F>, skipJsonConversion?: boolean): Promise<WrappedCallableRequestOutput<F>>;
124
125
  /**
@@ -136,14 +137,24 @@ export declare class AuthorizedUserTestContextInstance<PI extends FirebaseAdminT
136
137
  /**
137
138
  * Calls a wrapped gen 2 auth blocking function with the input params and context options from makeContextOptions().
138
139
  *
139
- * @param fn
140
- * @param userRecord
141
- * @param eventType
142
- * @param eventOverride
143
- * @param skipJsonConversion
144
- * @returns
140
+ * Synthesizes a minimal {@link AuthBlockingEvent} (filling in placeholder ip/user-agent/resource fields)
141
+ * from the supplied user record and event type, then dispatches it to the wrapped function.
142
+ *
143
+ * @param input - Options bag describing the blocking function invocation.
144
+ * @param input.fn - Wrapped gen 2 auth blocking function (e.g., from `beforeUserCreated`/`beforeUserSignedIn`) to invoke.
145
+ * @param input.userRecord - The Firebase Auth {@link UserRecord} that will be attached to the synthesized event's `data` field.
146
+ * @param input.eventType - Discriminator for the auth event being simulated (`google.firebase.auth.user.create` or `google.firebase.auth.user.delete`).
147
+ * @param input.eventOverride - Partial event fields used to override the default placeholder values (e.g., `ipAddress`, `userAgent`, `resource`).
148
+ * @param input.skipJsonConversion - When `true`, skip the JSON serialize/parse round-trip applied to the event payload (default `false`).
149
+ * @returns A promise that resolves once the blocking function has completed.
145
150
  */
146
- callAuthBlockingFunction(fn: WrappedBlockingFunctionWithHandler<AuthBlockingEvent, void>, userRecord: UserRecord, eventType: 'google.firebase.auth.user.create' | 'google.firebase.auth.user.delete', eventOverride?: Partial<AuthBlockingEvent>, skipJsonConversion?: boolean): Promise<void>;
151
+ callAuthBlockingFunction(input: {
152
+ fn: WrappedBlockingFunctionWithHandler<AuthBlockingEvent, void>;
153
+ userRecord: UserRecord;
154
+ eventType: 'google.firebase.auth.user.create' | 'google.firebase.auth.user.delete';
155
+ eventOverride?: Partial<AuthBlockingEvent>;
156
+ skipJsonConversion?: boolean;
157
+ }): Promise<void>;
147
158
  /**
148
159
  * @deprecated gen 1
149
160
  *
@@ -202,6 +213,9 @@ export interface AuthorizedUserTestContextParams<PI extends FirebaseAdminTestCon
202
213
  }
203
214
  /**
204
215
  * Convenience function for using authorizedUserContextFactory directly and passing buildTests.
216
+ *
217
+ * @param config - Test context parameters (parent fixture, optional uid/template, custom factories) used to create the authorized user context.
218
+ * @param buildTests - Callback invoked with the built {@link AuthorizedUserTestContextFixture}; should register `it(...)`/`describe(...)` blocks against it.
205
219
  */
206
220
  export declare function authorizedUserContext<PI extends FirebaseAdminTestContext = FirebaseAdminTestContext, PF extends TestContextFixture<PI> = TestContextFixture<PI>, I extends AuthorizedUserTestContextInstance<PI> = AuthorizedUserTestContextInstance<PI>, F extends AuthorizedUserTestContextFixture<PI, PF, I> = AuthorizedUserTestContextFixture<PI, PF, I>>(config: AuthorizedUserTestContextParams<PI, PF, I, F>, buildTests: (u: F) => void): void;
207
221
  /**
@@ -242,6 +256,13 @@ export declare const AUTHORIZED_USER_RANDOM_EMAIL_FACTORY: import("@dereekb/util
242
256
  export declare const AUTHORIZED_USER_RANDOM_PHONE_NUMBER_FACTORY: import("@dereekb/util").RandomPhoneNumberFactory;
243
257
  /**
244
258
  * Creates a new Jest Context that has a random user for authorization for use in firebase server tests.
259
+ *
260
+ * The returned function, when called with runtime params and a `buildTests` callback, registers the
261
+ * `beforeEach`/`afterEach` lifecycle hooks that create the test user (with optional contact info,
262
+ * custom claims, and post-create initialization) and tear it down afterward.
263
+ *
264
+ * @param config - Factory configuration: optional uid generator, custom fixture/instance constructors, user-detail builder, and `initUser` hook.
265
+ * @returns A function that, given runtime params and a `buildTests` callback, wires the authorized-user fixture into the active test context.
245
266
  */
246
267
  export declare function authorizedUserContextFactory<PI extends FirebaseAdminTestContext = FirebaseAdminTestContext, PF extends TestContextFixture<PI> = TestContextFixture<PI>, I extends AuthorizedUserTestContextInstance<PI> = AuthorizedUserTestContextInstance<PI>, F extends AuthorizedUserTestContextFixture<PI, PF, I> = AuthorizedUserTestContextFixture<PI, PF, I>, C extends AuthorizedUserTestContextFactoryParams<PI, PF> = AuthorizedUserTestContextFactoryParams<PI, PF>>(config: AuthorizedUserTestContextFactoryConfig<PI, PF, I, F>): (params: C, buildTests: (u: F) => void) => void;
247
268
  /**
@@ -306,6 +327,9 @@ export declare function createEncodedTestFirestoreTokenForUserRecord(auth: Auth,
306
327
  * in the JWT payload. This function flattens those claims onto the top-level decoded token to match
307
328
  * the structure of a real `DecodedIdToken`, and injects `auth_time` from the `iat` field.
308
329
  *
330
+ * @param token - Encoded JWT string produced by {@link createEncodedTestFirestoreTokenForUserRecord}.
331
+ * @returns A {@link DecodedIdToken}-shaped object with custom claims hoisted to the top level and `claims` removed.
332
+ *
309
333
  * @see {@link createEncodedTestFirestoreTokenForUserRecord} for creating the encoded token
310
334
  */
311
335
  export declare function decodeEncodedCreateCustomTokenResult(token: TestEncodedFirestoreToken): DecodedIdToken;
@@ -316,6 +340,9 @@ export declare function decodeEncodedCreateCustomTokenResult(token: TestEncodedF
316
340
  * custom claims already set on the user record. The resulting object is used as the
317
341
  * custom claims parameter for `Auth.createCustomToken()` in test token generation.
318
342
  *
343
+ * @param userRecord - Firebase Auth user record whose identity fields and existing custom claims should be folded into the returned claims.
344
+ * @returns A plain claims object suitable for passing to `Auth.createCustomToken()` in tests.
345
+ *
319
346
  * @see {@link createEncodedTestFirestoreTokenForUserRecord}
320
347
  */
321
348
  export declare function testFirestoreClaimsFromUserRecord(userRecord: UserRecord): object;
@@ -132,6 +132,9 @@ export type ModelTestContextParams<C = any, PI extends FirebaseAdminTestContext
132
132
  * hooks that create a new document (or wrap an existing one via {@link ModelTestContextDocumentRefParams}),
133
133
  * build the test context instance, optionally initialize the document, and clean up after each test.
134
134
  *
135
+ * @param config - Factory configuration that resolves the collection, optionally produces document refs, builds fixtures/instances, and tears down state.
136
+ * @returns A function that, given runtime params and a `buildTests` callback, registers the model fixture hooks against the active test context.
137
+ *
135
138
  * @see {@link ModelTestContextFactoryParams} for configuration options
136
139
  */
137
140
  export declare function modelTestContextFactory<T, D extends FirestoreDocument<T> = FirestoreDocument<T>, C = any, PI extends FirebaseAdminTestContext = FirebaseAdminTestContext, PF extends TestContextFixture<PI> = TestContextFixture<PI>, I extends ModelTestContextInstance<T, D, PI> = ModelTestContextInstance<T, D, PI>, F extends ModelTestContextFixture<T, D, PI, PF, I> = ModelTestContextFixture<T, D, PI, PF, I>, CL extends FirestoreCollectionLike<T, D> = FirestoreCollectionLike<T, D>>(config: ModelTestContextFactoryParams<T, D, C, PI, PF, I, F, CL>): (params: ModelTestContextParams<C, PI, PF>, buildTests: (u: F) => void) => void;
@@ -100,6 +100,8 @@ export declare let DEFAULT_FIREBASE_ADMIN_FUNCTION_TEST_USE_FUNCTION_SINGLETON_C
100
100
  * Globally sets whether new {@link FirebaseAdminFunctionTestConfig} instances default to
101
101
  * singleton mode. Primarily used in global test setup files.
102
102
  *
103
+ * @param use - When `true`, new function-test configs reuse the firebase-functions-test singleton; when `false`, each suite gets its own instance.
104
+ *
103
105
  * @example
104
106
  * ```ts
105
107
  * // in jest globalSetup
@@ -179,6 +179,9 @@ export declare function firebaseAdminNestContextWithFixture<PI extends FirebaseA
179
179
  * {@link firebaseAdminTestContextFactory}. This is the simplest way to get a
180
180
  * fully configured Firebase Admin + NestJS test context.
181
181
  *
182
+ * @param config - NestJS module + provider configuration plus optional fixture/instance overrides.
183
+ * @returns A {@link FirebaseAdminNestTestContextFactory} that produces a configured fixture for each test suite.
184
+ *
182
185
  * @example
183
186
  * ```ts
184
187
  * const f = firebaseAdminNestContextFactory({
@@ -67,6 +67,9 @@ export type CallableRequestTestMultipleFunction<T extends CallableRequestTestCon
67
67
  /**
68
68
  * Type guard that distinguishes a {@link CallableRequestTestSingleConfig} from a
69
69
  * {@link CallableRequestTestMultipleConfig} by checking for the presence of the `fn` property.
70
+ *
71
+ * @param config - Either a single-function or multiple-function callable test config to inspect.
72
+ * @returns `true` when `config` carries a single `fn` (single-config variant); `false` when it carries `fns` (map variant).
70
73
  */
71
74
  export declare function isCallableRequestTestSingleConfig<I, T extends CallableRequestTestConfigMapObject>(config: CallableRequestTestSingleConfig<I> | CallableRequestTestMultipleConfig<I, T>): config is CallableRequestTestSingleConfig<I>;
72
75
  /**
@@ -64,6 +64,9 @@ export type CloudFunctionTestMultipleFunction<T extends CloudFunctionTestConfigM
64
64
  /**
65
65
  * Type guard that distinguishes a {@link CloudFunctionTestSingleConfig} from a
66
66
  * {@link CloudFunctionTestMultipleConfig} by checking for the presence of the `fn` property.
67
+ *
68
+ * @param config - Either a single-function or multiple-function cloud function test config to inspect.
69
+ * @returns `true` when `config` carries a single `fn` (single-config variant); `false` when it carries `fns` (map variant).
67
70
  */
68
71
  export declare function isCloudFunctionTestSingleConfig<I extends object, T extends CloudFunctionTestConfigMapObject>(config: CloudFunctionTestSingleConfig<I> | CloudFunctionTestMultipleConfig<I, T>): config is CloudFunctionTestSingleConfig<I>;
69
72
  /**
@@ -106,6 +106,7 @@ export declare class FirebaseAdminFunctionNestRootModule {
106
106
  * @param config - NestJS module, provider, and fixture configuration.
107
107
  * @param f - The parent fixture that is already set up.
108
108
  * @param buildTests - Callback that receives the child fixture and registers test cases.
109
+ * @returns Whatever {@link firebaseAdminNestContextWithFixture} returns after registering the merged child fixture (typically `void`).
109
110
  */
110
111
  export declare function firebaseAdminFunctionNestContextWithFixture<PI extends FirebaseAdminFunctionTestContextInstance = FirebaseAdminFunctionTestContextInstance, PF extends TestContextFixture<PI> = TestContextFixture<PI>, I extends FirebaseAdminFunctionNestTestContextInstance<PI> = FirebaseAdminFunctionNestTestContextInstance<PI>, C extends FirebaseAdminFunctionNestTestContextFixture<PI, PF, I> = FirebaseAdminFunctionNestTestContextFixture<PI, PF, I>>(config: FirebaseAdminFunctionNestTestConfig<PI, PF, I, C>, f: PF, buildTests: BuildTestsWithContextFunction<C>): void;
111
112
  /**
@@ -113,6 +114,9 @@ export declare function firebaseAdminFunctionNestContextWithFixture<PI extends F
113
114
  * default {@link firebaseAdminFunctionTestContextFactory}. This is the simplest entry point
114
115
  * for tests that need both NestJS module access and Cloud Function wrapping.
115
116
  *
117
+ * @param config - NestJS module + provider configuration plus optional fixture/instance overrides.
118
+ * @returns A {@link FirebaseAdminFunctionNestTestContextFactory} that produces a configured fixture for each test suite.
119
+ *
116
120
  * @example
117
121
  * ```ts
118
122
  * const f = firebaseAdminFunctionNestContextFactory({