@firebase/rules-unit-testing 2.0.1 → 2.0.2-canary.aaeab08ac

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @firebase/rules-unit-testing
2
2
 
3
+ ## 2.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`d612d6f6e`](https://github.com/firebase/firebase-js-sdk/commit/d612d6f6e4d3113d45427b7df68459c0a3e31a1f) [#5928](https://github.com/firebase/firebase-js-sdk/pull/5928) - Upgrade `node-fetch` dependency due to a security issue.
8
+
3
9
  ## 2.0.1
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -154,7 +154,7 @@ function makeUrl(hostAndPort, path) {
154
154
  * @private
155
155
  */
156
156
  function discoverEmulators(hub, fetch) {
157
- if (fetch === void 0) { fetch = fetch__default['default']; }
157
+ if (fetch === void 0) { fetch = fetch__default["default"]; }
158
158
  return __awaiter(this, void 0, void 0, function () {
159
159
  var res, emulators, data;
160
160
  return __generator(this, function (_a) {
@@ -341,7 +341,7 @@ var RulesTestEnvironmentImpl = /** @class */ (function () {
341
341
  case 0:
342
342
  this.checkNotDestroyed();
343
343
  assertEmulatorRunning(this.emulators, 'firestore');
344
- return [4 /*yield*/, fetch__default['default'](makeUrl(this.emulators.firestore, "/emulator/v1/projects/" + this.projectId + "/databases/(default)/documents"), {
344
+ return [4 /*yield*/, fetch__default["default"](makeUrl(this.emulators.firestore, "/emulator/v1/projects/" + this.projectId + "/databases/(default)/documents"), {
345
345
  method: 'DELETE'
346
346
  })];
347
347
  case 1:
@@ -457,7 +457,7 @@ var RulesTestContextImpl = /** @class */ (function () {
457
457
  'return a Promise that resolves when the operations are done.');
458
458
  }
459
459
  if (!this.app) {
460
- this.app = firebase__default['default'].initializeApp({ projectId: this.projectId }, "_Firebase_RulesUnitTesting_" + Date.now() + "_" + Math.random());
460
+ this.app = firebase__default["default"].initializeApp({ projectId: this.projectId }, "_Firebase_RulesUnitTesting_" + Date.now() + "_" + Math.random());
461
461
  }
462
462
  return this.app;
463
463
  };
@@ -504,7 +504,7 @@ function loadDatabaseRules(hostAndPort, databaseName, rules) {
504
504
  case 0:
505
505
  url = makeUrl(hostAndPort, '/.settings/rules.json');
506
506
  url.searchParams.append('ns', databaseName);
507
- return [4 /*yield*/, fetch__default['default'](url, {
507
+ return [4 /*yield*/, fetch__default["default"](url, {
508
508
  method: 'PUT',
509
509
  headers: { Authorization: 'Bearer owner' },
510
510
  body: rules
@@ -528,7 +528,7 @@ function loadFirestoreRules(hostAndPort, projectId, rules) {
528
528
  var resp, _a;
529
529
  return __generator(this, function (_b) {
530
530
  switch (_b.label) {
531
- case 0: return [4 /*yield*/, fetch__default['default'](makeUrl(hostAndPort, "/emulator/v1/projects/" + projectId + ":securityRules"), {
531
+ case 0: return [4 /*yield*/, fetch__default["default"](makeUrl(hostAndPort, "/emulator/v1/projects/" + projectId + ":securityRules"), {
532
532
  method: 'PUT',
533
533
  body: JSON.stringify({
534
534
  rules: {
@@ -555,7 +555,7 @@ function loadStorageRules(hostAndPort, rules) {
555
555
  var resp, _a;
556
556
  return __generator(this, function (_b) {
557
557
  switch (_b.label) {
558
- case 0: return [4 /*yield*/, fetch__default['default'](makeUrl(hostAndPort, '/internal/setRules'), {
558
+ case 0: return [4 /*yield*/, fetch__default["default"](makeUrl(hostAndPort, '/internal/setRules'), {
559
559
  method: 'PUT',
560
560
  headers: {
561
561
  'Content-Type': 'application/json'
@@ -601,7 +601,7 @@ function loadStorageRules(hostAndPort, rules) {
601
601
  * variables or through the Firebase Emulator hub if hosts and ports are unspecified. It is strongly
602
602
  * recommended to specify security rules for emulators used for testing. See minimal example below.
603
603
  *
604
- * @param config the configuration for emulators. most fields are optional if they can be discovered
604
+ * @param config - the configuration for emulators. Most fields are optional if they can be discovered
605
605
  * @returns a promise that resolves with an environment ready for testing, or rejects on error.
606
606
  * @public
607
607
  * @example
@@ -715,7 +715,7 @@ function withFunctionTriggersDisabled(fnOrHub, maybeFn) {
715
715
  }
716
716
  hub.host = fixHostname(hub.host);
717
717
  makeUrl(hub, '/functions/disableBackgroundTriggers');
718
- return [4 /*yield*/, fetch__default['default'](makeUrl(hub, '/functions/disableBackgroundTriggers'), {
718
+ return [4 /*yield*/, fetch__default["default"](makeUrl(hub, '/functions/disableBackgroundTriggers'), {
719
719
  method: 'PUT'
720
720
  })];
721
721
  case 1:
@@ -731,7 +731,7 @@ function withFunctionTriggersDisabled(fnOrHub, maybeFn) {
731
731
  case 3:
732
732
  result = _a.sent();
733
733
  return [3 /*break*/, 6];
734
- case 4: return [4 /*yield*/, fetch__default['default'](makeUrl(hub, '/functions/enableBackgroundTriggers'), {
734
+ case 4: return [4 /*yield*/, fetch__default["default"](makeUrl(hub, '/functions/enableBackgroundTriggers'), {
735
735
  method: 'PUT'
736
736
  })];
737
737
  case 5:
@@ -753,7 +753,7 @@ function withFunctionTriggersDisabled(fnOrHub, maybeFn) {
753
753
  * Useful to assert a certain request to be denied by Security Rules. See example below.
754
754
  * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs.
755
755
  *
756
- * @param pr the promise to be asserted
756
+ * @param pr - the promise to be asserted
757
757
  * @returns a Promise that is fulfilled if pr is rejected with "permission denied". If pr is
758
758
  * rejected with any other error or resolved, the returned promise rejects.
759
759
  * @public
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/impl/url.ts","../src/impl/discovery.ts","../src/impl/test_environment.ts","../src/impl/rules.ts","../src/initialize.ts","../src/util.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\n\n/**\n * Return a connectable hostname, replacing wildcard 0.0.0.0 or :: with loopback\n * addresses 127.0.0.1 / ::1 correspondingly. See below for why this is needed:\n * https://github.com/firebase/firebase-tools-ui/issues/286\n *\n * This assumes emulators are running on the same device as fallbackHost (e.g.\n * hub), which should hold if both are started from the same CLI command.\n * @private\n */\nexport function fixHostname(host: string, fallbackHost?: string): string {\n host = host.replace('[', '').replace(']', ''); // Remove IPv6 brackets\n if (host === '0.0.0.0') {\n host = fallbackHost || '127.0.0.1';\n } else if (host === '::') {\n host = fallbackHost || '::1';\n }\n return host;\n}\n\n/**\n * Create a URL with host, port, and path. Handles IPv6 bracketing correctly.\n * @private\n */\nexport function makeUrl(hostAndPort: HostAndPort | string, path: string): URL {\n if (typeof hostAndPort === 'object') {\n const { host, port } = hostAndPort;\n if (host.includes(':')) {\n hostAndPort = `[${host}]:${port}`;\n } else {\n hostAndPort = `${host}:${port}`;\n }\n }\n const url = new URL(`http://${hostAndPort}/`);\n url.pathname = path;\n return url;\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EmulatorConfig, HostAndPort } from '../public_types';\nimport nodeFetch from 'node-fetch';\nimport { makeUrl, fixHostname } from './url';\n\n/**\n * Use the Firebase Emulator hub to discover other running emulators.\n *\n * @param hub the host and port where the Emulator Hub is running\n * @private\n */\nexport async function discoverEmulators(\n hub: HostAndPort,\n fetch: typeof nodeFetch = nodeFetch\n): Promise<DiscoveredEmulators> {\n const res = await fetch(makeUrl(hub, '/emulators'));\n if (!res.ok) {\n throw new Error(\n `HTTP Error ${res.status} when attempting to reach Emulator Hub at ${res.url}, are you sure it is running?`\n );\n }\n\n const emulators: DiscoveredEmulators = {};\n\n const data = await res.json();\n\n if (data.database) {\n emulators.database = {\n host: data.database.host,\n port: data.database.port\n };\n }\n\n if (data.firestore) {\n emulators.firestore = {\n host: data.firestore.host,\n port: data.firestore.port\n };\n }\n\n if (data.storage) {\n emulators.storage = {\n host: data.storage.host,\n port: data.storage.port\n };\n }\n\n if (data.hub) {\n emulators.hub = {\n host: data.hub.host,\n port: data.hub.port\n };\n }\n return emulators;\n}\n\n/**\n * @private\n */\nexport interface DiscoveredEmulators {\n database?: HostAndPort;\n firestore?: HostAndPort;\n storage?: HostAndPort;\n hub?: HostAndPort;\n}\n\n/**\n * @private\n */\nexport function getEmulatorHostAndPort(\n emulator: keyof DiscoveredEmulators,\n conf?: EmulatorConfig,\n discovered?: DiscoveredEmulators\n) {\n if (conf && ('host' in conf || 'port' in conf)) {\n const { host, port } = conf;\n if (host || port) {\n if (!host || !port) {\n throw new Error(\n `Invalid configuration ${emulator}.host=${host} and ${emulator}.port=${port}. ` +\n 'If either parameter is supplied, both must be defined.'\n );\n }\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: config for the ${emulator} emulator is specified, but the Emulator hub ` +\n 'reports it as not running. This may lead to errors such as connection refused.'\n );\n }\n return {\n host: fixHostname(conf.host, discovered?.hub?.host),\n port: conf.port\n };\n }\n }\n const envVar = EMULATOR_HOST_ENV_VARS[emulator];\n const fallback = discovered?.[emulator] || emulatorFromEnvVar(envVar);\n if (fallback) {\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: the environment variable ${envVar} is set, but the Emulator hub reports the ` +\n `${emulator} emulator as not running. This may lead to errors such as connection refused.`\n );\n }\n return {\n host: fixHostname(fallback.host, discovered?.hub?.host),\n port: fallback.port\n };\n }\n}\n\n// Visible for testing.\nexport const EMULATOR_HOST_ENV_VARS = {\n 'database': 'FIREBASE_DATABASE_EMULATOR_HOST',\n 'firestore': 'FIRESTORE_EMULATOR_HOST',\n 'hub': 'FIREBASE_EMULATOR_HUB',\n 'storage': 'FIREBASE_STORAGE_EMULATOR_HOST'\n};\n\nfunction emulatorFromEnvVar(envVar: string): HostAndPort | undefined {\n const hostAndPort = process.env[envVar];\n if (!hostAndPort) {\n return undefined;\n }\n\n let parsed: URL;\n try {\n parsed = new URL(`http://${hostAndPort}`);\n } catch {\n throw new Error(\n `Invalid format in environment variable ${envVar}=${hostAndPort} (expected host:port)`\n );\n }\n let host = parsed.hostname;\n const port = Number(parsed.port || '80');\n if (!Number.isInteger(port)) {\n throw new Error(\n `Invalid port in environment variable ${envVar}=${hostAndPort}`\n );\n }\n return { host, port };\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fetch from 'node-fetch';\nimport firebase from 'firebase/compat/app';\nimport 'firebase/compat/firestore';\nimport 'firebase/compat/database';\nimport 'firebase/compat/storage';\n\nimport {\n HostAndPort,\n RulesTestContext,\n RulesTestEnvironment,\n TokenOptions\n} from '../public_types';\n\nimport { DiscoveredEmulators } from './discovery';\nimport { makeUrl } from './url';\n\n/**\n * An implementation of {@code RulesTestEnvironment}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nexport class RulesTestEnvironmentImpl implements RulesTestEnvironment {\n private contexts = new Set<RulesTestContextImpl>();\n private destroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators\n ) {}\n\n authenticatedContext(\n user_id: string,\n tokenOptions?: TokenOptions\n ): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext({\n ...tokenOptions,\n sub: user_id,\n user_id: user_id\n });\n }\n\n unauthenticatedContext(): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext(/* authToken = */ undefined);\n }\n\n async withSecurityRulesDisabled(\n callback: (context: RulesTestContext) => Promise<void>\n ): Promise<void> {\n this.checkNotDestroyed();\n // The \"owner\" token is recognized by the emulators as a special value that bypasses Security\n // Rules. This should only ever be used in withSecurityRulesDisabled.\n // If you're reading this and thinking about doing this in your own app / tests / scripts, think\n // twice. Instead, just use withSecurityRulesDisabled for unit testing OR connect your Firebase\n // Admin SDKs to the emulators for integration testing via environment variables.\n // See: https://firebase.google.com/docs/emulator-suite/connect_firestore#admin_sdks\n const context = this.createContext('owner');\n try {\n await callback(context);\n } finally {\n // We eagarly clean up this context to actively prevent misuse outside of the callback, e.g.\n // storing the context in a variable.\n context.cleanup();\n this.contexts.delete(context);\n }\n }\n\n private createContext(\n authToken: string | firebase.EmulatorMockTokenOptions | undefined\n ): RulesTestContextImpl {\n const context = new RulesTestContextImpl(\n this.projectId,\n this.emulators,\n authToken\n );\n this.contexts.add(context);\n return context;\n }\n\n clearDatabase(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(context => {\n return context.database().ref('/').set(null);\n });\n }\n\n async clearFirestore(): Promise<void> {\n this.checkNotDestroyed();\n assertEmulatorRunning(this.emulators, 'firestore');\n\n const resp = await fetch(\n makeUrl(\n this.emulators.firestore,\n `/emulator/v1/projects/${this.projectId}/databases/(default)/documents`\n ),\n {\n method: 'DELETE'\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n }\n\n clearStorage(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(async context => {\n const { items } = await context.storage().ref().listAll();\n await Promise.all(\n items.map(item => {\n return item.delete();\n })\n );\n });\n }\n\n async cleanup(): Promise<void> {\n this.destroyed = true;\n this.contexts.forEach(context => {\n context.envDestroyed = true;\n context.cleanup();\n });\n this.contexts.clear();\n }\n\n private checkNotDestroyed() {\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestEnvironment has already been cleaned up. ' +\n '(This may indicate a leak or missing `await` in your test cases. If you do intend to ' +\n 'perform more tests, please call cleanup() later or create another RulesTestEnvironment.)'\n );\n }\n }\n}\n/**\n * An implementation of {@code RulesTestContext}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nclass RulesTestContextImpl implements RulesTestContext {\n private app?: firebase.app.App;\n private destroyed = false;\n envDestroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators,\n readonly authToken: firebase.EmulatorMockTokenOptions | string | undefined\n ) {}\n\n cleanup() {\n this.destroyed = true;\n this.app?.delete();\n\n this.app = undefined;\n }\n\n firestore(\n settings?: firebase.firestore.Settings\n ): firebase.firestore.Firestore {\n assertEmulatorRunning(this.emulators, 'firestore');\n const firestore = this.getApp().firestore();\n if (settings) {\n firestore.settings(settings);\n }\n firestore.useEmulator(\n this.emulators.firestore.host,\n this.emulators.firestore.port,\n { mockUserToken: this.authToken }\n );\n return firestore;\n }\n database(databaseURL?: string): firebase.database.Database {\n assertEmulatorRunning(this.emulators, 'database');\n if (!databaseURL) {\n const url = makeUrl(this.emulators.database, '');\n // Make sure to set the namespace equal to projectId -- otherwise the RTDB SDK will by default\n // use `${projectId}-default-rtdb`, which is treated as a different DB by the RTDB emulator\n // (and thus WON'T apply any rules set for the `projectId` DB during initialization).\n url.searchParams.append('ns', this.projectId);\n databaseURL = url.toString();\n }\n const database = this.getApp().database(databaseURL);\n database.useEmulator(\n this.emulators.database.host,\n this.emulators.database.port,\n { mockUserToken: this.authToken }\n );\n return database;\n }\n storage(bucketUrl = `gs://${this.projectId}`): firebase.storage.Storage {\n assertEmulatorRunning(this.emulators, 'storage');\n const storage = this.getApp().storage(bucketUrl);\n storage.useEmulator(\n this.emulators.storage.host,\n this.emulators.storage.port,\n { mockUserToken: this.authToken }\n );\n return storage;\n }\n\n private getApp(): firebase.app.App {\n if (this.envDestroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid because its RulesTestEnvironment has been ' +\n 'cleaned up. (This may indicate a leak or missing `await` in your test cases.)'\n );\n }\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid. When using withSecurityRulesDisabled, ' +\n 'make sure to perform all operations on the context within the callback function and ' +\n 'return a Promise that resolves when the operations are done.'\n );\n }\n if (!this.app) {\n this.app = firebase.initializeApp(\n { projectId: this.projectId },\n `_Firebase_RulesUnitTesting_${Date.now()}_${Math.random()}`\n );\n }\n return this.app;\n }\n}\n\nexport function assertEmulatorRunning<E extends keyof DiscoveredEmulators>(\n emulators: DiscoveredEmulators,\n emulator: E\n): asserts emulators is Record<E, HostAndPort> {\n if (!emulators[emulator]) {\n if (emulators.hub) {\n throw new Error(\n `The ${emulator} emulator is not running (according to Emulator hub). To force ` +\n 'connecting anyway, please specify its host and port in initializeTestEnvironment({...}).'\n );\n } else {\n throw new Error(\n `The host and port of the ${emulator} emulator must be specified. (You may wrap the test ` +\n \"script with `firebase emulators:exec './your-test-script'` to enable automatic \" +\n `discovery, or specify manually via initializeTestEnvironment({${emulator}: {host, port}}).`\n );\n }\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\nimport { makeUrl } from './url';\nimport fetch from 'node-fetch';\n\n/**\n * @private\n */\nexport async function loadDatabaseRules(\n hostAndPort: HostAndPort,\n databaseName: string,\n rules: string\n): Promise<void> {\n const url = makeUrl(hostAndPort, '/.settings/rules.json');\n url.searchParams.append('ns', databaseName);\n const resp = await fetch(url, {\n method: 'PUT',\n headers: { Authorization: 'Bearer owner' },\n body: rules\n });\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadFirestoreRules(\n hostAndPort: HostAndPort,\n projectId: string,\n rules: string\n): Promise<void> {\n const resp = await fetch(\n makeUrl(hostAndPort, `/emulator/v1/projects/${projectId}:securityRules`),\n {\n method: 'PUT',\n body: JSON.stringify({\n rules: {\n files: [{ content: rules }]\n }\n })\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadStorageRules(\n hostAndPort: HostAndPort,\n rules: string\n): Promise<void> {\n const resp = await fetch(makeUrl(hostAndPort, '/internal/setRules'), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n rules: {\n files: [{ name: 'storage.rules', content: rules }]\n }\n })\n });\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RulesTestEnvironment, TestEnvironmentConfig } from './public_types';\nimport {\n DiscoveredEmulators,\n discoverEmulators,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport {\n assertEmulatorRunning,\n RulesTestEnvironmentImpl\n} from './impl/test_environment';\nimport {\n loadDatabaseRules,\n loadFirestoreRules,\n loadStorageRules\n} from './impl/rules';\n\n/**\n * Initializes a test environment for rules unit testing. Call this function first for test setup.\n *\n * Requires emulators to be running. This function tries to discover those emulators via environment\n * variables or through the Firebase Emulator hub if hosts and ports are unspecified. It is strongly\n * recommended to specify security rules for emulators used for testing. See minimal example below.\n *\n * @param config the configuration for emulators. most fields are optional if they can be discovered\n * @returns a promise that resolves with an environment ready for testing, or rejects on error.\n * @public\n * @example\n * ```javascript\n * const testEnv = await initializeTestEnvironment({\n * firestore: {\n * rules: fs.readFileSync(\"/path/to/firestore.rules\", \"utf8\"), // Load rules from file\n * // host and port can be omitted if they can be discovered from the hub.\n * },\n * // ...\n * });\n * ```\n */\nexport async function initializeTestEnvironment(\n config: TestEnvironmentConfig\n): Promise<RulesTestEnvironment> {\n const projectId = config.projectId || process.env.GCLOUD_PROJECT;\n if (!projectId) {\n throw new Error(\n 'Missing projectId option or env var GCLOUD_PROJECT! Please specify the projectId either ' +\n 'way.\\n(A demo-* projectId is strongly recommended for unit tests, such as \"demo-test\".)'\n );\n }\n const hub = getEmulatorHostAndPort('hub', config.hub);\n let discovered = hub ? { ...(await discoverEmulators(hub)), hub } : undefined;\n\n const emulators: DiscoveredEmulators = {};\n if (hub) {\n emulators.hub = hub;\n }\n\n for (const emulator of SUPPORTED_EMULATORS) {\n const hostAndPort = getEmulatorHostAndPort(\n emulator,\n config[emulator],\n discovered\n );\n if (hostAndPort) {\n emulators[emulator] = hostAndPort;\n }\n }\n\n if (config.database?.rules) {\n assertEmulatorRunning(emulators, 'database');\n await loadDatabaseRules(\n emulators.database,\n projectId,\n config.database.rules\n );\n }\n if (config.firestore?.rules) {\n assertEmulatorRunning(emulators, 'firestore');\n await loadFirestoreRules(\n emulators.firestore,\n projectId,\n config.firestore.rules\n );\n }\n if (config.storage?.rules) {\n assertEmulatorRunning(emulators, 'storage');\n await loadStorageRules(emulators.storage, config.storage.rules);\n }\n\n return new RulesTestEnvironmentImpl(projectId, emulators);\n}\n\nconst SUPPORTED_EMULATORS = ['database', 'firestore', 'storage'] as const;\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n EMULATOR_HOST_ENV_VARS,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport { fixHostname, makeUrl } from './impl/url';\nimport { HostAndPort } from './public_types';\nimport fetch from 'node-fetch';\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. This overload works only if\n * the Emulator hub host:port is specified by the environment variable FIREBASE_EMULATOR_HUB.\n *\n * @param fn an function which may be sync or async (returns a promise)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. The Emulator hub must be\n * running, which host and port are specified in this overload.\n *\n * @param fn an function which may be sync or async (returns a promise)\n * @param hub the host and port of the Emulator Hub (ex: `{host: 'localhost', port: 4400}`)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n hub: { host: string; port: number },\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\nexport async function withFunctionTriggersDisabled<TResult>(\n fnOrHub: { host: string; port: number } | (() => TResult | Promise<TResult>),\n maybeFn?: () => TResult | Promise<TResult>\n): Promise<TResult> {\n let hub: HostAndPort | undefined;\n if (typeof fnOrHub === 'function') {\n maybeFn = fnOrHub;\n hub = getEmulatorHostAndPort('hub');\n } else {\n hub = getEmulatorHostAndPort('hub', fnOrHub);\n if (!maybeFn) {\n throw new Error('The callback function must be specified!');\n }\n }\n if (!hub) {\n throw new Error(\n 'Please specify the Emulator Hub host and port via arguments or set the environment ' +\n `varible ${EMULATOR_HOST_ENV_VARS.hub}!`\n );\n }\n\n hub.host = fixHostname(hub.host);\n makeUrl(hub, '/functions/disableBackgroundTriggers');\n // Disable background triggers\n const disableRes = await fetch(\n makeUrl(hub, '/functions/disableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n if (!disableRes.ok) {\n throw new Error(\n `HTTP Error ${disableRes.status} when disabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n\n // Run the user's function\n let result: TResult | undefined = undefined;\n try {\n result = await maybeFn();\n } finally {\n // Re-enable background triggers\n const enableRes = await fetch(\n makeUrl(hub, '/functions/enableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n\n if (!enableRes.ok) {\n throw new Error(\n `HTTP Error ${enableRes.status} when enabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n }\n\n // Return the user's function result\n return result;\n}\n\n/**\n * Assert the promise to be rejected with a \"permission denied\" error.\n *\n * Useful to assert a certain request to be denied by Security Rules. See example below.\n * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs.\n *\n * @param pr the promise to be asserted\n * @returns a Promise that is fulfilled if pr is rejected with \"permission denied\". If pr is\n * rejected with any other error or resolved, the returned promise rejects.\n * @public\n * @example\n * ```javascript\n * const unauthed = testEnv.unauthenticatedContext();\n * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });\n * ```\n */\nexport function assertFails(pr: Promise<any>): Promise<any> {\n return pr.then(\n () => {\n return Promise.reject(\n new Error('Expected request to fail, but it succeeded.')\n );\n },\n (err: any) => {\n const errCode = err?.code?.toLowerCase() || '';\n const errMessage = err?.message?.toLowerCase() || '';\n const isPermissionDenied =\n errCode === 'permission-denied' ||\n errCode === 'permission_denied' ||\n errMessage.indexOf('permission_denied') >= 0 ||\n errMessage.indexOf('permission denied') >= 0 ||\n // Storage permission errors contain message: (storage/unauthorized)\n errMessage.indexOf('unauthorized') >= 0;\n\n if (!isPermissionDenied) {\n return Promise.reject(\n new Error(\n `Expected PERMISSION_DENIED but got unexpected error: ${err}`\n )\n );\n }\n return err;\n }\n );\n}\n\n/**\n * Assert the promise to be rejected with a \"permission denied\" error.\n *\n * This is a no-op function returning the passed promise as-is, but can be used for documentational\n * purposes in test code to emphasize that a certain request should succeed (e.g. allowed by rules).\n *\n * @public\n * @example\n * ```javascript\n * const alice = testEnv.authenticatedContext('alice');\n * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });\n * ```\n */\nexport function assertSucceeds<T>(pr: Promise<T>): Promise<T> {\n return pr;\n}\n"],"names":["fetch","firebase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;SASgB,WAAW,CAAC,IAAY,EAAE,YAAqB;IAC7D,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC9C,IAAI,IAAI,KAAK,SAAS,EAAE;QACtB,IAAI,GAAG,YAAY,IAAI,WAAW,CAAC;KACpC;SAAM,IAAI,IAAI,KAAK,IAAI,EAAE;QACxB,IAAI,GAAG,YAAY,IAAI,KAAK,CAAC;KAC9B;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;SAIgB,OAAO,CAAC,WAAiC,EAAE,IAAY;IACrE,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QAC3B,IAAA,IAAI,GAAW,WAAW,KAAtB,EAAE,IAAI,GAAK,WAAW,KAAhB,CAAiB;QACnC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;Y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DAAwD,GAAK,CAC9D,CACF,CAAC;SACH;QACD,OAAO,GAAG,CAAC;KACZ,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;SAagB,cAAc,CAAI,EAAc;IAC9C,OAAO,EAAE,CAAC;AACZ;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/impl/url.ts","../src/impl/discovery.ts","../src/impl/test_environment.ts","../src/impl/rules.ts","../src/initialize.ts","../src/util.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\n\n/**\n * Return a connectable hostname, replacing wildcard 0.0.0.0 or :: with loopback\n * addresses 127.0.0.1 / ::1 correspondingly. See below for why this is needed:\n * https://github.com/firebase/firebase-tools-ui/issues/286\n *\n * This assumes emulators are running on the same device as fallbackHost (e.g.\n * hub), which should hold if both are started from the same CLI command.\n * @private\n */\nexport function fixHostname(host: string, fallbackHost?: string): string {\n host = host.replace('[', '').replace(']', ''); // Remove IPv6 brackets\n if (host === '0.0.0.0') {\n host = fallbackHost || '127.0.0.1';\n } else if (host === '::') {\n host = fallbackHost || '::1';\n }\n return host;\n}\n\n/**\n * Create a URL with host, port, and path. Handles IPv6 bracketing correctly.\n * @private\n */\nexport function makeUrl(hostAndPort: HostAndPort | string, path: string): URL {\n if (typeof hostAndPort === 'object') {\n const { host, port } = hostAndPort;\n if (host.includes(':')) {\n hostAndPort = `[${host}]:${port}`;\n } else {\n hostAndPort = `${host}:${port}`;\n }\n }\n const url = new URL(`http://${hostAndPort}/`);\n url.pathname = path;\n return url;\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EmulatorConfig, HostAndPort } from '../public_types';\nimport nodeFetch from 'node-fetch';\nimport { makeUrl, fixHostname } from './url';\n\n/**\n * Use the Firebase Emulator hub to discover other running emulators.\n *\n * @param hub the host and port where the Emulator Hub is running\n * @private\n */\nexport async function discoverEmulators(\n hub: HostAndPort,\n fetch: typeof nodeFetch = nodeFetch\n): Promise<DiscoveredEmulators> {\n const res = await fetch(makeUrl(hub, '/emulators'));\n if (!res.ok) {\n throw new Error(\n `HTTP Error ${res.status} when attempting to reach Emulator Hub at ${res.url}, are you sure it is running?`\n );\n }\n\n const emulators: DiscoveredEmulators = {};\n\n const data = await res.json();\n\n if (data.database) {\n emulators.database = {\n host: data.database.host,\n port: data.database.port\n };\n }\n\n if (data.firestore) {\n emulators.firestore = {\n host: data.firestore.host,\n port: data.firestore.port\n };\n }\n\n if (data.storage) {\n emulators.storage = {\n host: data.storage.host,\n port: data.storage.port\n };\n }\n\n if (data.hub) {\n emulators.hub = {\n host: data.hub.host,\n port: data.hub.port\n };\n }\n return emulators;\n}\n\n/**\n * @private\n */\nexport interface DiscoveredEmulators {\n database?: HostAndPort;\n firestore?: HostAndPort;\n storage?: HostAndPort;\n hub?: HostAndPort;\n}\n\n/**\n * @private\n */\nexport function getEmulatorHostAndPort(\n emulator: keyof DiscoveredEmulators,\n conf?: EmulatorConfig,\n discovered?: DiscoveredEmulators\n) {\n if (conf && ('host' in conf || 'port' in conf)) {\n const { host, port } = conf;\n if (host || port) {\n if (!host || !port) {\n throw new Error(\n `Invalid configuration ${emulator}.host=${host} and ${emulator}.port=${port}. ` +\n 'If either parameter is supplied, both must be defined.'\n );\n }\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: config for the ${emulator} emulator is specified, but the Emulator hub ` +\n 'reports it as not running. This may lead to errors such as connection refused.'\n );\n }\n return {\n host: fixHostname(conf.host, discovered?.hub?.host),\n port: conf.port\n };\n }\n }\n const envVar = EMULATOR_HOST_ENV_VARS[emulator];\n const fallback = discovered?.[emulator] || emulatorFromEnvVar(envVar);\n if (fallback) {\n if (discovered && !discovered[emulator]) {\n console.warn(\n `Warning: the environment variable ${envVar} is set, but the Emulator hub reports the ` +\n `${emulator} emulator as not running. This may lead to errors such as connection refused.`\n );\n }\n return {\n host: fixHostname(fallback.host, discovered?.hub?.host),\n port: fallback.port\n };\n }\n}\n\n// Visible for testing.\nexport const EMULATOR_HOST_ENV_VARS = {\n 'database': 'FIREBASE_DATABASE_EMULATOR_HOST',\n 'firestore': 'FIRESTORE_EMULATOR_HOST',\n 'hub': 'FIREBASE_EMULATOR_HUB',\n 'storage': 'FIREBASE_STORAGE_EMULATOR_HOST'\n};\n\nfunction emulatorFromEnvVar(envVar: string): HostAndPort | undefined {\n const hostAndPort = process.env[envVar];\n if (!hostAndPort) {\n return undefined;\n }\n\n let parsed: URL;\n try {\n parsed = new URL(`http://${hostAndPort}`);\n } catch {\n throw new Error(\n `Invalid format in environment variable ${envVar}=${hostAndPort} (expected host:port)`\n );\n }\n let host = parsed.hostname;\n const port = Number(parsed.port || '80');\n if (!Number.isInteger(port)) {\n throw new Error(\n `Invalid port in environment variable ${envVar}=${hostAndPort}`\n );\n }\n return { host, port };\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fetch from 'node-fetch';\nimport firebase from 'firebase/compat/app';\nimport 'firebase/compat/firestore';\nimport 'firebase/compat/database';\nimport 'firebase/compat/storage';\n\nimport {\n HostAndPort,\n RulesTestContext,\n RulesTestEnvironment,\n TokenOptions\n} from '../public_types';\n\nimport { DiscoveredEmulators } from './discovery';\nimport { makeUrl } from './url';\n\n/**\n * An implementation of {@code RulesTestEnvironment}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nexport class RulesTestEnvironmentImpl implements RulesTestEnvironment {\n private contexts = new Set<RulesTestContextImpl>();\n private destroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators\n ) {}\n\n authenticatedContext(\n user_id: string,\n tokenOptions?: TokenOptions\n ): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext({\n ...tokenOptions,\n sub: user_id,\n user_id: user_id\n });\n }\n\n unauthenticatedContext(): RulesTestContext {\n this.checkNotDestroyed();\n return this.createContext(/* authToken = */ undefined);\n }\n\n async withSecurityRulesDisabled(\n callback: (context: RulesTestContext) => Promise<void>\n ): Promise<void> {\n this.checkNotDestroyed();\n // The \"owner\" token is recognized by the emulators as a special value that bypasses Security\n // Rules. This should only ever be used in withSecurityRulesDisabled.\n // If you're reading this and thinking about doing this in your own app / tests / scripts, think\n // twice. Instead, just use withSecurityRulesDisabled for unit testing OR connect your Firebase\n // Admin SDKs to the emulators for integration testing via environment variables.\n // See: https://firebase.google.com/docs/emulator-suite/connect_firestore#admin_sdks\n const context = this.createContext('owner');\n try {\n await callback(context);\n } finally {\n // We eagarly clean up this context to actively prevent misuse outside of the callback, e.g.\n // storing the context in a variable.\n context.cleanup();\n this.contexts.delete(context);\n }\n }\n\n private createContext(\n authToken: string | firebase.EmulatorMockTokenOptions | undefined\n ): RulesTestContextImpl {\n const context = new RulesTestContextImpl(\n this.projectId,\n this.emulators,\n authToken\n );\n this.contexts.add(context);\n return context;\n }\n\n clearDatabase(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(context => {\n return context.database().ref('/').set(null);\n });\n }\n\n async clearFirestore(): Promise<void> {\n this.checkNotDestroyed();\n assertEmulatorRunning(this.emulators, 'firestore');\n\n const resp = await fetch(\n makeUrl(\n this.emulators.firestore,\n `/emulator/v1/projects/${this.projectId}/databases/(default)/documents`\n ),\n {\n method: 'DELETE'\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n }\n\n clearStorage(): Promise<void> {\n this.checkNotDestroyed();\n return this.withSecurityRulesDisabled(async context => {\n const { items } = await context.storage().ref().listAll();\n await Promise.all(\n items.map(item => {\n return item.delete();\n })\n );\n });\n }\n\n async cleanup(): Promise<void> {\n this.destroyed = true;\n this.contexts.forEach(context => {\n context.envDestroyed = true;\n context.cleanup();\n });\n this.contexts.clear();\n }\n\n private checkNotDestroyed() {\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestEnvironment has already been cleaned up. ' +\n '(This may indicate a leak or missing `await` in your test cases. If you do intend to ' +\n 'perform more tests, please call cleanup() later or create another RulesTestEnvironment.)'\n );\n }\n }\n}\n/**\n * An implementation of {@code RulesTestContext}. This is private to hide the constructor,\n * which should never be directly called by the developer.\n * @private\n */\nclass RulesTestContextImpl implements RulesTestContext {\n private app?: firebase.app.App;\n private destroyed = false;\n envDestroyed = false;\n\n constructor(\n readonly projectId: string,\n readonly emulators: DiscoveredEmulators,\n readonly authToken: firebase.EmulatorMockTokenOptions | string | undefined\n ) {}\n\n cleanup() {\n this.destroyed = true;\n this.app?.delete();\n\n this.app = undefined;\n }\n\n firestore(\n settings?: firebase.firestore.Settings\n ): firebase.firestore.Firestore {\n assertEmulatorRunning(this.emulators, 'firestore');\n const firestore = this.getApp().firestore();\n if (settings) {\n firestore.settings(settings);\n }\n firestore.useEmulator(\n this.emulators.firestore.host,\n this.emulators.firestore.port,\n { mockUserToken: this.authToken }\n );\n return firestore;\n }\n database(databaseURL?: string): firebase.database.Database {\n assertEmulatorRunning(this.emulators, 'database');\n if (!databaseURL) {\n const url = makeUrl(this.emulators.database, '');\n // Make sure to set the namespace equal to projectId -- otherwise the RTDB SDK will by default\n // use `${projectId}-default-rtdb`, which is treated as a different DB by the RTDB emulator\n // (and thus WON'T apply any rules set for the `projectId` DB during initialization).\n url.searchParams.append('ns', this.projectId);\n databaseURL = url.toString();\n }\n const database = this.getApp().database(databaseURL);\n database.useEmulator(\n this.emulators.database.host,\n this.emulators.database.port,\n { mockUserToken: this.authToken }\n );\n return database;\n }\n storage(bucketUrl = `gs://${this.projectId}`): firebase.storage.Storage {\n assertEmulatorRunning(this.emulators, 'storage');\n const storage = this.getApp().storage(bucketUrl);\n storage.useEmulator(\n this.emulators.storage.host,\n this.emulators.storage.port,\n { mockUserToken: this.authToken }\n );\n return storage;\n }\n\n private getApp(): firebase.app.App {\n if (this.envDestroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid because its RulesTestEnvironment has been ' +\n 'cleaned up. (This may indicate a leak or missing `await` in your test cases.)'\n );\n }\n if (this.destroyed) {\n throw new Error(\n 'This RulesTestContext is no longer valid. When using withSecurityRulesDisabled, ' +\n 'make sure to perform all operations on the context within the callback function and ' +\n 'return a Promise that resolves when the operations are done.'\n );\n }\n if (!this.app) {\n this.app = firebase.initializeApp(\n { projectId: this.projectId },\n `_Firebase_RulesUnitTesting_${Date.now()}_${Math.random()}`\n );\n }\n return this.app;\n }\n}\n\nexport function assertEmulatorRunning<E extends keyof DiscoveredEmulators>(\n emulators: DiscoveredEmulators,\n emulator: E\n): asserts emulators is Record<E, HostAndPort> {\n if (!emulators[emulator]) {\n if (emulators.hub) {\n throw new Error(\n `The ${emulator} emulator is not running (according to Emulator hub). To force ` +\n 'connecting anyway, please specify its host and port in initializeTestEnvironment({...}).'\n );\n } else {\n throw new Error(\n `The host and port of the ${emulator} emulator must be specified. (You may wrap the test ` +\n \"script with `firebase emulators:exec './your-test-script'` to enable automatic \" +\n `discovery, or specify manually via initializeTestEnvironment({${emulator}: {host, port}}).`\n );\n }\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HostAndPort } from '../public_types';\nimport { makeUrl } from './url';\nimport fetch from 'node-fetch';\n\n/**\n * @private\n */\nexport async function loadDatabaseRules(\n hostAndPort: HostAndPort,\n databaseName: string,\n rules: string\n): Promise<void> {\n const url = makeUrl(hostAndPort, '/.settings/rules.json');\n url.searchParams.append('ns', databaseName);\n const resp = await fetch(url, {\n method: 'PUT',\n headers: { Authorization: 'Bearer owner' },\n body: rules\n });\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadFirestoreRules(\n hostAndPort: HostAndPort,\n projectId: string,\n rules: string\n): Promise<void> {\n const resp = await fetch(\n makeUrl(hostAndPort, `/emulator/v1/projects/${projectId}:securityRules`),\n {\n method: 'PUT',\n body: JSON.stringify({\n rules: {\n files: [{ content: rules }]\n }\n })\n }\n );\n\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n\n/**\n * @private\n */\nexport async function loadStorageRules(\n hostAndPort: HostAndPort,\n rules: string\n): Promise<void> {\n const resp = await fetch(makeUrl(hostAndPort, '/internal/setRules'), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n rules: {\n files: [{ name: 'storage.rules', content: rules }]\n }\n })\n });\n if (!resp.ok) {\n throw new Error(await resp.text());\n }\n}\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RulesTestEnvironment, TestEnvironmentConfig } from './public_types';\nimport {\n DiscoveredEmulators,\n discoverEmulators,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport {\n assertEmulatorRunning,\n RulesTestEnvironmentImpl\n} from './impl/test_environment';\nimport {\n loadDatabaseRules,\n loadFirestoreRules,\n loadStorageRules\n} from './impl/rules';\n\n/**\n * Initializes a test environment for rules unit testing. Call this function first for test setup.\n *\n * Requires emulators to be running. This function tries to discover those emulators via environment\n * variables or through the Firebase Emulator hub if hosts and ports are unspecified. It is strongly\n * recommended to specify security rules for emulators used for testing. See minimal example below.\n *\n * @param config - the configuration for emulators. Most fields are optional if they can be discovered\n * @returns a promise that resolves with an environment ready for testing, or rejects on error.\n * @public\n * @example\n * ```javascript\n * const testEnv = await initializeTestEnvironment({\n * firestore: {\n * rules: fs.readFileSync(\"/path/to/firestore.rules\", \"utf8\"), // Load rules from file\n * // host and port can be omitted if they can be discovered from the hub.\n * },\n * // ...\n * });\n * ```\n */\nexport async function initializeTestEnvironment(\n config: TestEnvironmentConfig\n): Promise<RulesTestEnvironment> {\n const projectId = config.projectId || process.env.GCLOUD_PROJECT;\n if (!projectId) {\n throw new Error(\n 'Missing projectId option or env var GCLOUD_PROJECT! Please specify the projectId either ' +\n 'way.\\n(A demo-* projectId is strongly recommended for unit tests, such as \"demo-test\".)'\n );\n }\n const hub = getEmulatorHostAndPort('hub', config.hub);\n let discovered = hub ? { ...(await discoverEmulators(hub)), hub } : undefined;\n\n const emulators: DiscoveredEmulators = {};\n if (hub) {\n emulators.hub = hub;\n }\n\n for (const emulator of SUPPORTED_EMULATORS) {\n const hostAndPort = getEmulatorHostAndPort(\n emulator,\n config[emulator],\n discovered\n );\n if (hostAndPort) {\n emulators[emulator] = hostAndPort;\n }\n }\n\n if (config.database?.rules) {\n assertEmulatorRunning(emulators, 'database');\n await loadDatabaseRules(\n emulators.database,\n projectId,\n config.database.rules\n );\n }\n if (config.firestore?.rules) {\n assertEmulatorRunning(emulators, 'firestore');\n await loadFirestoreRules(\n emulators.firestore,\n projectId,\n config.firestore.rules\n );\n }\n if (config.storage?.rules) {\n assertEmulatorRunning(emulators, 'storage');\n await loadStorageRules(emulators.storage, config.storage.rules);\n }\n\n return new RulesTestEnvironmentImpl(projectId, emulators);\n}\n\nconst SUPPORTED_EMULATORS = ['database', 'firestore', 'storage'] as const;\n","/**\n * @license\n * Copyright 2021 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n EMULATOR_HOST_ENV_VARS,\n getEmulatorHostAndPort\n} from './impl/discovery';\nimport { fixHostname, makeUrl } from './impl/url';\nimport { HostAndPort } from './public_types';\nimport fetch from 'node-fetch';\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. This overload works only if\n * the Emulator hub host:port is specified by the environment variable FIREBASE_EMULATOR_HUB.\n *\n * @param fn - a function which may be sync or async (returns a promise)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\n/**\n * Run a setup function with background Cloud Functions triggers disabled. This can be used to\n * import data into the Realtime Database or Cloud Firestore emulator without triggering locally\n * emulated Cloud Functions.\n *\n * This method only works with Firebase CLI version 8.13.0 or higher. The Emulator hub must be\n * running, which host and port are specified in this overload.\n *\n * @param fn - a function which may be sync or async (returns a promise)\n * @param hub - the host and port of the Emulator Hub (ex: `{host: 'localhost', port: 4400}`)\n * @public\n */\nexport async function withFunctionTriggersDisabled<TResult>(\n hub: { host: string; port: number },\n fn: () => TResult | Promise<TResult>\n): Promise<TResult>;\n\nexport async function withFunctionTriggersDisabled<TResult>(\n fnOrHub: { host: string; port: number } | (() => TResult | Promise<TResult>),\n maybeFn?: () => TResult | Promise<TResult>\n): Promise<TResult> {\n let hub: HostAndPort | undefined;\n if (typeof fnOrHub === 'function') {\n maybeFn = fnOrHub;\n hub = getEmulatorHostAndPort('hub');\n } else {\n hub = getEmulatorHostAndPort('hub', fnOrHub);\n if (!maybeFn) {\n throw new Error('The callback function must be specified!');\n }\n }\n if (!hub) {\n throw new Error(\n 'Please specify the Emulator Hub host and port via arguments or set the environment ' +\n `varible ${EMULATOR_HOST_ENV_VARS.hub}!`\n );\n }\n\n hub.host = fixHostname(hub.host);\n makeUrl(hub, '/functions/disableBackgroundTriggers');\n // Disable background triggers\n const disableRes = await fetch(\n makeUrl(hub, '/functions/disableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n if (!disableRes.ok) {\n throw new Error(\n `HTTP Error ${disableRes.status} when disabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n\n // Run the user's function\n let result: TResult | undefined = undefined;\n try {\n result = await maybeFn();\n } finally {\n // Re-enable background triggers\n const enableRes = await fetch(\n makeUrl(hub, '/functions/enableBackgroundTriggers'),\n {\n method: 'PUT'\n }\n );\n\n if (!enableRes.ok) {\n throw new Error(\n `HTTP Error ${enableRes.status} when enabling functions triggers, are you using firebase-tools 8.13.0 or higher?`\n );\n }\n }\n\n // Return the user's function result\n return result;\n}\n\n/**\n * Assert the promise to be rejected with a \"permission denied\" error.\n *\n * Useful to assert a certain request to be denied by Security Rules. See example below.\n * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs.\n *\n * @param pr - the promise to be asserted\n * @returns a Promise that is fulfilled if pr is rejected with \"permission denied\". If pr is\n * rejected with any other error or resolved, the returned promise rejects.\n * @public\n * @example\n * ```javascript\n * const unauthed = testEnv.unauthenticatedContext();\n * await assertFails(get(doc(unauthed.firestore(), '/private/doc'), { ... });\n * ```\n */\nexport function assertFails(pr: Promise<any>): Promise<any> {\n return pr.then(\n () => {\n return Promise.reject(\n new Error('Expected request to fail, but it succeeded.')\n );\n },\n (err: any) => {\n const errCode = err?.code?.toLowerCase() || '';\n const errMessage = err?.message?.toLowerCase() || '';\n const isPermissionDenied =\n errCode === 'permission-denied' ||\n errCode === 'permission_denied' ||\n errMessage.indexOf('permission_denied') >= 0 ||\n errMessage.indexOf('permission denied') >= 0 ||\n // Storage permission errors contain message: (storage/unauthorized)\n errMessage.indexOf('unauthorized') >= 0;\n\n if (!isPermissionDenied) {\n return Promise.reject(\n new Error(\n `Expected PERMISSION_DENIED but got unexpected error: ${err}`\n )\n );\n }\n return err;\n }\n );\n}\n\n/**\n * Assert the promise to be rejected with a \"permission denied\" error.\n *\n * This is a no-op function returning the passed promise as-is, but can be used for documentational\n * purposes in test code to emphasize that a certain request should succeed (e.g. allowed by rules).\n *\n * @public\n * @example\n * ```javascript\n * const alice = testEnv.authenticatedContext('alice');\n * await assertSucceeds(get(doc(alice.firestore(), '/doc/readable/by/alice'), { ... });\n * ```\n */\nexport function assertSucceeds<T>(pr: Promise<T>): Promise<T> {\n return pr;\n}\n"],"names":["fetch","firebase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;SASgB,WAAW,CAAC,IAAY,EAAE,YAAqB;IA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A,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,0CAAE,WAAW,EAAE,KAAI,EAAE,CAAC;QAC/C,IAAM,UAAU,GAAG,CAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,0CAAE,WAAW,EAAE,KAAI,EAAE,CAAC;QACrD,IAAM,kBAAkB,GACtB,OAAO,KAAK,mBAAmB;YAC/B,OAAO,KAAK,mBAAmB;YAC/B,UAAU,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;YAC5C,UAAU,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;;YAE5C,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAE1C,IAAI,CAAC,kBAAkB,EAAE;YACvB,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CACP,0DAAwD,GAAK,CAC9D,CACF,CAAC;SACH;QACD,OAAO,GAAG,CAAC;KACZ,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;SAagB,cAAc,CAAI,EAAc;IAC9C,OAAO,EAAE,CAAC;AACZ;;;;;;;"}
@@ -22,7 +22,7 @@ import { RulesTestEnvironment, TestEnvironmentConfig } from './public_types';
22
22
  * variables or through the Firebase Emulator hub if hosts and ports are unspecified. It is strongly
23
23
  * recommended to specify security rules for emulators used for testing. See minimal example below.
24
24
  *
25
- * @param config the configuration for emulators. most fields are optional if they can be discovered
25
+ * @param config - the configuration for emulators. Most fields are optional if they can be discovered
26
26
  * @returns a promise that resolves with an environment ready for testing, or rejects on error.
27
27
  * @public
28
28
  * @example
@@ -106,12 +106,12 @@ export interface TestEnvironmentConfig {
106
106
  export interface HostAndPort {
107
107
  /**
108
108
  * The host of the emulator. Can be omitted if discovered automatically through the hub or
109
- * specified via environment variables. See {@code TestEnvironmentConfig} for details.
109
+ * specified via environment variables. See `TestEnvironmentConfig` for details.
110
110
  */
111
111
  host: string;
112
112
  /**
113
113
  * The port of the emulator. Can be omitted if discovered automatically through the hub or
114
- * specified via environment variables. See {@code TestEnvironmentConfig} for details.
114
+ * specified via environment variables. See `TestEnvironmentConfig` for details.
115
115
  */
116
116
  port: number;
117
117
  }
@@ -140,12 +140,12 @@ export interface RulesTestEnvironment {
140
140
  storage?: HostAndPort;
141
141
  };
142
142
  /**
143
- * Create a {@code RulesTestContext} which behaves like an authenticated Firebase Auth user.
143
+ * Create a `RulesTestContext` which behaves like an authenticated Firebase Auth user.
144
144
  *
145
145
  * Requests created via the returned context will have a mock Firebase Auth token attached.
146
146
  *
147
- * @param user_id the User ID of the user. Specifies the value of "user_id" and "sub" on the token
148
- * @param tokenOptions custom claims or overrides for Firebase Auth token payloads
147
+ * @param user_id - the User ID of the user. Specifies the value of "user_id" and "sub" on the token
148
+ * @param tokenOptions - custom claims or overrides for Firebase Auth token payloads
149
149
  *
150
150
  * @example
151
151
  * ```javascript
@@ -155,7 +155,7 @@ export interface RulesTestEnvironment {
155
155
  */
156
156
  authenticatedContext(user_id: string, tokenOptions?: TokenOptions): RulesTestContext;
157
157
  /**
158
- * Create a {@code RulesTestContext} which behaves like client that is NOT logged in via Firebase
158
+ * Create a `RulesTestContext` which behaves like client that is NOT logged in via Firebase
159
159
  * Auth.
160
160
  *
161
161
  * Requests created via the returned context will not have Firebase Auth tokens attached.
@@ -173,7 +173,7 @@ export interface RulesTestEnvironment {
173
173
  */
174
174
  clearDatabase(): Promise<void>;
175
175
  /**
176
- * Clear data in the Firestore that belongs to the {@code projectId} in the Firestore emulator.
176
+ * Clear data in the Firestore that belongs to the `projectId` in the Firestore emulator.
177
177
  */
178
178
  clearFirestore(): Promise<void>;
179
179
  /**
@@ -185,7 +185,7 @@ export interface RulesTestEnvironment {
185
185
  * created in test environment and clean up the underlying resources, allowing a clean exit.
186
186
  *
187
187
  * This method does not change the state in emulators in any way. To reset data between tests,
188
- * see {@code clearDatabase()}, {@code clearFirestore()} and {@code clearStorage()}.
188
+ * see `clearDatabase()`, `clearFirestore()` and `clearStorage()`.
189
189
  */
190
190
  cleanup(): Promise<void>;
191
191
  }
@@ -195,34 +195,34 @@ export interface RulesTestEnvironment {
195
195
  */
196
196
  export interface RulesTestContext {
197
197
  /**
198
- * Get a Firestore instance for this test context. The returned Firebase JS Client SDK instance
198
+ * Get a {@link @firebase/firestore#Firestore} instance for this test context. The returned Firebase JS Client SDK instance
199
199
  * can be used with the client SDK APIs (v9 modular or v9 compat).
200
200
  *
201
- * See: https://firebase.google.com/docs/reference/js/v9/firestore_
202
- * @param settings a settings object to configure the {@code Firestore} instance
203
- * @returns a Firestore instance configured to connect to the emulator
201
+ * See: {@link @firebase/firestore#Firestore}
202
+ * @param settings - a settings object to configure the {@link @firebase/firestore#Firestore} instance
203
+ * @returns a `Firestore` instance configured to connect to the emulator
204
204
  * @public
205
205
  */
206
206
  firestore(settings?: firebase.firestore.Settings): firebase.firestore.Firestore;
207
207
  /**
208
- * Get a Firestore instance for this test context. The returned Firebase JS Client SDK instance
208
+ * Get a {@link @firebase/database#Database} instance for this test context. The returned Firebase JS Client SDK instance
209
209
  * can be used with the client SDK APIs (v9 modular or v9 compat).
210
210
  *
211
- * See: https://firebase.google.com/docs/reference/js/v9/firestore_
212
- * @param databaseURL the URL of the Realtime Database instance. If specified, returns an instance
211
+ * See: {@link @firebase/database#Database}
212
+ * @param databaseURL - the URL of the Realtime Database instance. If specified, returns an instance
213
213
  * for an emulated version of the namespace with parameters extracted from URL
214
- * @returns a Database instance configured to connect to the emulator. It never connects to
215
- * production even if a production databaseURL is specified
214
+ * @returns a `Database` instance configured to connect to the emulator. It never connects to
215
+ * production even if a production `databaseURL` is specified
216
216
  */
217
217
  database(databaseURL?: string): firebase.database.Database;
218
218
  /**
219
- * Get a Storage instance for this test context. The returned Firebase JS Client SDK instance
219
+ * Get a {@link @firebase/storage#FirebaseStorage} instance for this test context. The returned Firebase JS Client SDK instance
220
220
  * can be used with the client SDK APIs (v9 modular or v9 compat).
221
221
  *
222
- * See: https://firebase.google.com/docs/reference/js/v9/firestore_
223
- * @param settings the gs:// url to the Firebase Storage Bucket for testing. If specified,
224
- * returns a Storage instance for an emulated version of the bucket name
225
- * @returns a Storage instance configured to connect to the emulator
222
+ * See: {@link @firebase/storage#FirebaseStorage}
223
+ * @param settings - the gs:// url to the Firebase Storage Bucket for testing. If specified,
224
+ * returns a `Storage` instance for an emulated version of the bucket name
225
+ * @returns a `Storage` instance configured to connect to the emulator
226
226
  */
227
227
  storage(bucketUrl?: string): firebase.storage.Storage;
228
228
  }
@@ -22,7 +22,7 @@
22
22
  * This method only works with Firebase CLI version 8.13.0 or higher. This overload works only if
23
23
  * the Emulator hub host:port is specified by the environment variable FIREBASE_EMULATOR_HUB.
24
24
  *
25
- * @param fn an function which may be sync or async (returns a promise)
25
+ * @param fn - a function which may be sync or async (returns a promise)
26
26
  * @public
27
27
  */
28
28
  export declare function withFunctionTriggersDisabled<TResult>(fn: () => TResult | Promise<TResult>): Promise<TResult>;
@@ -34,8 +34,8 @@ export declare function withFunctionTriggersDisabled<TResult>(fn: () => TResult
34
34
  * This method only works with Firebase CLI version 8.13.0 or higher. The Emulator hub must be
35
35
  * running, which host and port are specified in this overload.
36
36
  *
37
- * @param fn an function which may be sync or async (returns a promise)
38
- * @param hub the host and port of the Emulator Hub (ex: `{host: 'localhost', port: 4400}`)
37
+ * @param fn - a function which may be sync or async (returns a promise)
38
+ * @param hub - the host and port of the Emulator Hub (ex: `{host: 'localhost', port: 4400}`)
39
39
  * @public
40
40
  */
41
41
  export declare function withFunctionTriggersDisabled<TResult>(hub: {
@@ -48,7 +48,7 @@ export declare function withFunctionTriggersDisabled<TResult>(hub: {
48
48
  * Useful to assert a certain request to be denied by Security Rules. See example below.
49
49
  * This function recognizes permission-denied errors from Database, Firestore, and Storage JS SDKs.
50
50
  *
51
- * @param pr the promise to be asserted
51
+ * @param pr - the promise to be asserted
52
52
  * @returns a Promise that is fulfilled if pr is rejected with "permission denied". If pr is
53
53
  * rejected with any other error or resolved, the returned promise rejects.
54
54
  * @public
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "0.1.2"
9
+ }
10
+ ]
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firebase/rules-unit-testing",
3
- "version": "2.0.1",
3
+ "version": "2.0.2-canary.aaeab08ac",
4
4
  "description": "",
5
5
  "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
6
6
  "main": "dist/index.cjs.js",
@@ -11,20 +11,23 @@
11
11
  "dist"
12
12
  ],
13
13
  "scripts": {
14
- "build": "rollup -c",
14
+ "build": "rollup -c && yarn api-report",
15
15
  "build:deps": "lerna run --scope @firebase/rules-unit-testing --include-dependencies build",
16
16
  "dev": "rollup -c -w",
17
17
  "test:nyc": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --config ./mocharc.node.js",
18
18
  "test": "(cd functions && yarn) && firebase --project=demo-foo --debug emulators:exec 'yarn test:nyc'",
19
- "test:ci": "node ../../scripts/run_tests_in_ci.js -s test"
19
+ "test:ci": "node ../../scripts/run_tests_in_ci.js -s test",
20
+ "api-report": "api-extractor run --local --verbose",
21
+ "doc": "api-documenter markdown --input temp --output docs",
22
+ "build:doc": "yarn build && yarn doc"
20
23
  },
21
24
  "license": "Apache-2.0",
22
25
  "devDependencies": {
23
- "rollup": "2.56.3",
26
+ "rollup": "2.57.0",
24
27
  "rollup-plugin-typescript2": "0.30.0"
25
28
  },
26
29
  "peerDependencies": {
27
- "firebase": "^9.0.0"
30
+ "firebase": "9.6.5-canary.aaeab08ac"
28
31
  },
29
32
  "repository": {
30
33
  "directory": "packages/rules-unit-testing",
@@ -36,6 +39,6 @@
36
39
  "url": "https://github.com/firebase/firebase-js-sdk/issues"
37
40
  },
38
41
  "dependencies": {
39
- "node-fetch": "2.6.2"
42
+ "node-fetch": "2.6.7"
40
43
  }
41
44
  }