firebase-tools-with-isolate 15.3.1-0 → 15.11.0-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/README.md +59 -52
  2. package/lib/api.js +3 -1
  3. package/lib/apiv2.js +29 -10
  4. package/lib/appdistribution/client.js +20 -2
  5. package/lib/appdistribution/distribution.js +1 -1
  6. package/lib/appdistribution/options-parser-util.js +7 -0
  7. package/lib/appdistribution/yaml_helper.js +24 -16
  8. package/lib/apphosting/backend.js +1 -1
  9. package/lib/apphosting/config.js +24 -1
  10. package/lib/apphosting/rollout.js +1 -1
  11. package/lib/apphosting/secrets/dialogs.js +3 -3
  12. package/lib/apphosting/secrets/index.js +59 -0
  13. package/lib/apphosting/utils.js +14 -0
  14. package/lib/apptesting/parseTestFiles.js +104 -43
  15. package/lib/bin/cli.js +2 -2
  16. package/lib/bin/mcp.js +3 -2
  17. package/lib/command.js +3 -0
  18. package/lib/commands/appdistribution-distribute.js +5 -5
  19. package/lib/commands/apphosting-secrets-set.js +2 -53
  20. package/lib/commands/apptesting.js +93 -0
  21. package/lib/commands/dataconnect-compile.js +46 -0
  22. package/lib/commands/dataconnect-execute.js +14 -12
  23. package/lib/commands/dataconnect-sql-setup.js +3 -4
  24. package/lib/commands/dataconnect-sql-shell.js +2 -1
  25. package/lib/commands/deploy.js +3 -0
  26. package/lib/commands/firestore-databases-create.js +69 -12
  27. package/lib/commands/firestore-databases-update.js +6 -14
  28. package/lib/commands/index.js +8 -4
  29. package/lib/commands/init.js +5 -0
  30. package/lib/commands/studio-export.js +39 -0
  31. package/lib/config.js +1 -0
  32. package/lib/dataconnect/client.js +4 -3
  33. package/lib/dataconnect/load.js +24 -1
  34. package/lib/dataconnect/prompts.js +14 -0
  35. package/lib/dataconnect/schemaMigration.js +37 -18
  36. package/lib/dataconnect/types.js +9 -1
  37. package/lib/deploy/apphosting/release.js +7 -1
  38. package/lib/deploy/apphosting/util.js +1 -1
  39. package/lib/deploy/auth/deploy.js +63 -0
  40. package/lib/deploy/auth/index.js +9 -0
  41. package/lib/deploy/auth/prepare.js +26 -0
  42. package/lib/deploy/auth/release.js +5 -0
  43. package/lib/deploy/dataconnect/release.js +11 -0
  44. package/lib/deploy/extensions/prepare.js +13 -4
  45. package/lib/deploy/firestore/prepare.js +17 -0
  46. package/lib/deploy/functions/backend.js +10 -0
  47. package/lib/deploy/functions/build.js +26 -11
  48. package/lib/deploy/functions/checkIam.js +3 -2
  49. package/lib/deploy/functions/deploy.js +4 -2
  50. package/lib/deploy/functions/prepare.js +27 -24
  51. package/lib/deploy/functions/prepareFunctionsUpload.js +12 -10
  52. package/lib/deploy/functions/release/fabricator.js +96 -15
  53. package/lib/deploy/functions/release/index.js +2 -1
  54. package/lib/deploy/functions/runtimes/dart/index.js +282 -0
  55. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +12 -3
  56. package/lib/deploy/functions/runtimes/index.js +9 -1
  57. package/lib/deploy/functions/runtimes/supported/index.js +4 -0
  58. package/lib/deploy/functions/runtimes/supported/types.js +6 -0
  59. package/lib/deploy/functions/validate.js +25 -0
  60. package/lib/deploy/index.js +2 -0
  61. package/lib/downloadUtils.js +3 -1
  62. package/lib/emulator/apphosting/config.js +1 -21
  63. package/lib/emulator/apphosting/serve.js +13 -15
  64. package/lib/emulator/auth/index.js +23 -17
  65. package/lib/emulator/auth/operations.js +11 -3
  66. package/lib/emulator/controller.js +2 -1
  67. package/lib/emulator/dataconnect/pgliteServer.js +26 -33
  68. package/lib/emulator/dataconnectEmulator.js +0 -1
  69. package/lib/emulator/download.js +15 -1
  70. package/lib/emulator/downloadableEmulatorInfo.json +37 -37
  71. package/lib/emulator/downloadableEmulators.js +33 -6
  72. package/lib/emulator/functionsEmulator.js +103 -24
  73. package/lib/emulator/functionsRuntimeWorker.js +21 -18
  74. package/lib/emulator/hub.js +2 -0
  75. package/lib/emulator/hubExport.js +22 -7
  76. package/lib/ensureApiEnabled.js +2 -2
  77. package/lib/env.js +24 -1
  78. package/lib/experiments.js +7 -2
  79. package/lib/firebase_studio/migrate.js +653 -0
  80. package/lib/firestore/api-types.js +26 -11
  81. package/lib/firestore/api.js +3 -0
  82. package/lib/frameworks/next/constants.js +6 -1
  83. package/lib/frameworks/next/index.js +5 -1
  84. package/lib/functionsConfig.js +3 -3
  85. package/lib/gcp/cloudbilling.js +6 -3
  86. package/lib/gcp/cloudfunctionsv2.js +23 -2
  87. package/lib/gcp/cloudsql/cloudsqladmin.js +8 -3
  88. package/lib/gcp/cloudsql/fbToolsAuthClient.js +1 -1
  89. package/lib/gcp/cloudsql/permissionsSetup.js +4 -4
  90. package/lib/gcp/iam.js +2 -2
  91. package/lib/gcp/rules.js +5 -2
  92. package/lib/gcp/runv2.js +78 -5
  93. package/lib/gcp/serviceusage.js +2 -2
  94. package/lib/gemini/fdcExperience.js +0 -11
  95. package/lib/init/features/auth.js +72 -0
  96. package/lib/init/features/dataconnect/resolver.js +17 -3
  97. package/lib/init/features/firestore/indexes.js +1 -1
  98. package/lib/init/features/functions/dart.js +31 -0
  99. package/lib/init/features/functions/index.js +36 -14
  100. package/lib/init/features/functions/javascript.js +18 -3
  101. package/lib/init/features/functions/typescript.js +20 -3
  102. package/lib/init/features/functions/utils.js +10 -0
  103. package/lib/init/features/genkit/index.js +3 -2
  104. package/lib/init/features/hosting/index.js +71 -101
  105. package/lib/init/features/index.js +6 -2
  106. package/lib/init/features/{storage.js → storage/index.js} +12 -4
  107. package/lib/init/features/storage/rules.js +20 -0
  108. package/lib/init/index.js +11 -1
  109. package/lib/management/provisioning/provision.js +3 -0
  110. package/lib/management/provisioning/types.js +7 -0
  111. package/lib/mcp/index.js +18 -6
  112. package/lib/mcp/onemcp/index.js +14 -0
  113. package/lib/mcp/onemcp/onemcp_server.js +76 -0
  114. package/lib/mcp/prompts/apptesting/run_test.js +6 -5
  115. package/lib/mcp/prompts/index.js +1 -0
  116. package/lib/mcp/resources/guides/init_auth.js +19 -2
  117. package/lib/mcp/tools/apptesting/tests.js +12 -10
  118. package/lib/mcp/tools/core/get_security_rules.js +1 -1
  119. package/lib/mcp/tools/core/init.js +31 -0
  120. package/lib/mcp/tools/crashlytics/reports.js +1 -1
  121. package/lib/mcp/tools/firestore/index.js +1 -4
  122. package/lib/mcp/tools/firestore/query_collection.js +1 -1
  123. package/lib/mcp/tools/index.js +42 -22
  124. package/lib/mcp/types.js +1 -0
  125. package/lib/mcp/util/availability.js +2 -1
  126. package/lib/mcp/util.js +2 -0
  127. package/lib/track.js +2 -17
  128. package/lib/tsconfig.publish.tsbuildinfo +1 -1
  129. package/package.json +5 -4
  130. package/schema/dataconnect-yaml.json +4 -0
  131. package/schema/firebase-config.json +48 -0
  132. package/templates/firebase-studio-export/readme_template.md +17 -0
  133. package/templates/firebase-studio-export/system_instructions_template.md +39 -0
  134. package/templates/firebase-studio-export/workflows/cleanup.md +20 -0
  135. package/templates/init/apphosting/apphosting.yaml +1 -0
  136. package/templates/init/apptesting/smoke_test.yaml +2 -2
  137. package/templates/init/dataconnect/secondary_schema.gql +8 -0
  138. package/templates/init/functions/dart/_gitignore +11 -0
  139. package/templates/init/functions/dart/pubspec.yaml +14 -0
  140. package/templates/init/functions/dart/server.dart +15 -0
  141. package/templates/init/functions/javascript/index-ongraphrequest.js +36 -0
  142. package/templates/init/functions/javascript/package-ongraphrequest.lint.json +28 -0
  143. package/templates/init/functions/javascript/package-ongraphrequest.nolint.json +25 -0
  144. package/templates/init/functions/python/requirements.txt +1 -1
  145. package/templates/init/functions/typescript/index-ongraphrequest.ts +44 -0
  146. package/templates/init/functions/typescript/package-ongraphrequest.lint.json +33 -0
  147. package/templates/init/functions/typescript/package-ongraphrequest.nolint.json +27 -0
  148. package/lib/mcp/tools/firestore/delete_document.js +0 -50
  149. package/lib/mcp/tools/firestore/get_documents.js +0 -58
  150. package/lib/mcp/tools/firestore/list_collections.js +0 -33
  151. package/lib/mcp/util.test.js +0 -468
package/README.md CHANGED
@@ -1,55 +1,47 @@
1
1
  # Firebase CLI with monorepo support
2
2
 
3
- This is a fork of the [firebase-tools](https://github.com/firebase/firebase-tools) which integrates [isolate-package](https://github.com/0x80/isolate-package/) as part of the functions `deploy` command in order to [support monorepo setups](https://thijs-koerselman.medium.com/deploy-to-firebase-without-the-hacks-e685de39025e).
3
+ This is a fork of [firebase-tools](https://github.com/firebase/firebase-tools) that integrates [isolate-package](https://github.com/0x80/isolate-package/) into the functions `deploy` command to [support monorepo setups](https://thijs-koerselman.medium.com/deploy-to-firebase-without-the-hacks-e685de39025e).
4
4
 
5
- Alternatively, you can manually configure `isolate` as part of the `predeploy` step of your configuration, but having the process integrated and only running as part of the deploy command is essential if you want to have live code updates when running the Firebase emulators locally during development with a watch task.
6
-
7
- I suspect it will take some time before the Firebase team would agree to make isolate an integral part of the toolchain and that is why I have published this fork to be available on NPM.
8
-
9
- The fork is pretty much identical, and the integration with isolate-package does
10
- not affect any existing functionality, so I do not think there is a reason to worry
11
- about things breaking. I will sync the fork with the upstream firebase-tools on
12
- a regular basis. The fork versions will match the firebase-tools versions for
13
- clarity.
5
+ The integration is minimal — roughly 50 lines of code across 4 files — and does not affect any existing functionality. The `isolate` step is entirely opt-in via a flag in your `firebase.json`.
14
6
 
15
7
  ## Installation
16
8
 
17
- Add this dependency to the root of your monorepo, and co-locate all off your Firebase configurations there as well, as described in the docs.
18
-
19
- I encourage you to use `pnpm` over `npm` or `yarn`. Apart from being fast and
20
- efficient, PNPM has better support for monorepos, and the the lockfile isolation
21
- code is solid and works in parallel for multiple packages, [unlike NPM](https://github.com/0x80/isolate-package/README.md#npm)
9
+ Add this dependency to the root of your monorepo:
22
10
 
23
11
  ```bash
24
12
  pnpm add firebase-tools-with-isolate -D -w
25
13
  ```
26
14
 
27
- Or run the equivalent for NPM or Yarn.
15
+ Or the equivalent for NPM or Yarn. I encourage using `pnpm` — apart from being fast and efficient, it has better monorepo support, and the lockfile isolation code is solid and works in parallel for multiple packages, [unlike NPM](https://github.com/0x80/isolate-package/README.md#npm).
16
+
17
+ > **Important:** Remove/uninstall the original `firebase-tools` package if you have it installed, because otherwise that binary might get precedence over the forked one and `npx firebase deploy` will execute the wrong one.
28
18
 
29
- > !! Do not forget to remove/uninstall the original `firebase-tools` package from your repository if you have it installed as a local dependency on your project, because otherwise that binary might get precedence over the forked one, and `npx firebase deploy` will execute the wrong one.
19
+ ## Usage
30
20
 
31
- ## Commands
21
+ Installing the fork provides you with the same `firebase` command. On the command line, prefix it with `npx`:
32
22
 
33
- Installing the fork locally provides you with the same `firebase` command but in order to execute a command on the command line you prefix it with `npx` like `npx firebase deploy`.
23
+ ```bash
24
+ npx firebase deploy
25
+ ```
34
26
 
35
- If you are using the commands as part of a package.json script, `npx` is not required, because scripts already prefer locally installed binaries when available.
27
+ In package.json scripts, `npx` is not required — scripts already prefer locally installed binaries.
36
28
 
37
- ## Configure
29
+ ## Configuration
38
30
 
39
- You have to opt-in to the functions isolate process by setting `functions.isolate: true` in your `firebase.json`. For example:
31
+ Opt in to isolate-package by setting `isolate: true` in your `firebase.json`:
40
32
 
41
33
  ```json
42
34
  {
43
35
  "functions": {
44
36
  "source": ".",
45
- "runtime": "nodejs20",
37
+ "runtime": "nodejs22",
46
38
  "predeploy": ["turbo build"],
47
39
  "isolate": true
48
40
  }
49
41
  }
50
42
  ```
51
43
 
52
- If you have a monorepo, your firebase.json file should be located in the root listing all of the packages, emulator settings and other firebase related files. It would look something like this:
44
+ For a monorepo with multiple function packages, place `firebase.json` at the root:
53
45
 
54
46
  ```json
55
47
  {
@@ -68,38 +60,53 @@ If you have a monorepo, your firebase.json file should be located in the root li
68
60
  "codebase": "fns",
69
61
  "isolate": true
70
62
  }
71
- ],
72
- "firestore": {
73
- "rules": "firestore.rules",
74
- "indexes": "firestore.indexes.json"
75
- },
76
- "storage": {
77
- "rules": "storage.rules"
78
- },
79
- "emulators": {
80
- "ui": {
81
- "enabled": true
82
- },
83
- "auth": {
84
- "port": 9099
85
- },
86
- "functions": {
87
- "port": 5001
88
- },
89
- "firestore": {
90
- "port": 8080
91
- },
92
- "pubsub": {
93
- "port": 8085
94
- }
95
- }
63
+ ]
96
64
  }
97
65
  ```
98
66
 
99
- At the time of writing, firebase-tools has an seemingly odd limitation that prevents it from running predeploy commands with "=" in them. So `"turbo build --filter=@repo/api"` doesn't work. A workaround is to use `"pnpm build:api"` instead, and put `"build:api": "turbo build --filter=@repo/api"` in your root package.json.
67
+ > **Note:** firebase-tools has a limitation that prevents running predeploy commands containing `=`. So `"turbo build --filter=@repo/api"` won't work. Use `"pnpm build:api"` instead, with `"build:api": "turbo build --filter=@repo/api"` in your root package.json.
68
+
69
+ For a complete working example of a modern monorepo setup, check out [mono-ts](https://github.com/0x80/mono-ts).
70
+
71
+ ## How this fork stays in sync
72
+
73
+ Fork versions match upstream firebase-tools versions (e.g. `15.13.0-0` corresponds to upstream `v15.13.0`). The fork is kept in sync using automated tooling:
74
+
75
+ ### Scripts (`scripts/sync/`)
76
+
77
+ - **`apply-isolate-changes.mjs`** — Applies the isolate integration on top of any clean upstream release. Patches exactly 4 source files and `package.json`, using anchor-based string matching verified to be stable across upstream releases from v15.4.0 through v15.13.0.
78
+
79
+ - **`sync-upstream.sh`** — Orchestrates the full sync: fetches upstream, merges a release tag, re-applies the isolate changes, installs dependencies, and verifies the build compiles.
80
+
81
+ The sync can also be triggered manually:
82
+
83
+ ```bash
84
+ # Sync to the latest upstream release
85
+ ./scripts/sync/sync-upstream.sh
86
+
87
+ # Sync to a specific version
88
+ ./scripts/sync/sync-upstream.sh --target v15.13.0
89
+
90
+ # Dry run (no push)
91
+ ./scripts/sync/sync-upstream.sh --no-push --no-build
92
+ ```
93
+
94
+ ### GitHub Actions (`.github/workflows/`)
95
+
96
+ All workflows use Node 24 and npm OIDC trusted publishing (provenance).
97
+
98
+ - **[`sync-upstream.yml`](.github/workflows/sync-upstream.yml)** — Runs daily (09:00 UTC) and on manual dispatch. Checks for new upstream firebase-tools releases and opens a PR with the synced result. Can target a specific version.
99
+
100
+ - **[`update-isolate.yml`](.github/workflows/update-isolate.yml)** — Updates the `isolate-package` dependency to a given version, bumps the fork's pre-release number (e.g. `15.13.0-0` → `15.13.0-1`), and commits to master. Follow up with the publish workflow to release to npm.
101
+
102
+ - **[`publish.yml`](.github/workflows/publish.yml)** — Publishes the fork to npm. Choose `next` for pre-release testing or `latest` to promote a stable release (which strips the pre-release suffix, e.g. `15.13.0-0` → `15.13.0`). Creates a git tag and GitHub release.
103
+
104
+ ### Versioning
100
105
 
101
- If you would like to see a complete working example of a modern monorepo setup check out [mono-ts](https://github.com/0x80/mono-ts)
106
+ - Sync creates version `X.Y.Z-0` matching upstream `vX.Y.Z`
107
+ - Each isolate-package update bumps the suffix: `-0` → `-1` → `-2`
108
+ - Publishing to `latest` strips the suffix: `X.Y.Z-0` → `X.Y.Z`
102
109
 
103
110
  ## Documentation
104
111
 
105
- For all other documentation see the [original firebase tools](https://github.com/firebase/firebase-tools)
112
+ For all other documentation see the [official firebase-tools](https://github.com/firebase/firebase-tools).
package/lib/api.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.storageOrigin = exports.runtimeconfigOrigin = exports.rulesOrigin = exports.resourceManagerOrigin = exports.crashlyticsApiOrigin = exports.messagingApiOrigin = exports.remoteConfigApiOrigin = exports.rtdbMetadataOrigin = exports.rtdbManagementOrigin = exports.realtimeOrigin = exports.extensionsTOSOrigin = exports.extensionsPublisherOrigin = exports.extensionsOrigin = exports.iamOrigin = exports.identityOrigin = exports.hostingOrigin = exports.googleOrigin = exports.pubsubOrigin = exports.cloudTasksOrigin = exports.cloudschedulerOrigin = exports.cloudbuildOrigin = exports.functionsDefaultRegion = exports.runOrigin = exports.functionsV2Origin = exports.functionsOrigin = exports.firestoreOrigin = exports.firestoreOriginOrEmulator = exports.firedataOrigin = exports.firebaseExtensionsRegistryOrigin = exports.firebaseApiOrigin = exports.eventarcOrigin = exports.dynamicLinksKey = exports.dynamicLinksOrigin = exports.consoleOrigin = exports.authManagementOrigin = exports.authOrigin = exports.apphostingGitHubAppInstallationURL = exports.apphostingP4SADomain = exports.apphostingOrigin = exports.appDistributionOrigin = exports.artifactRegistryDomain = exports.developerConnectP4SADomain = exports.developerConnectOrigin = exports.containerRegistryDomain = exports.cloudMonitoringOrigin = exports.cloudloggingOrigin = exports.cloudbillingOrigin = exports.clientSecret = exports.clientId = exports.authProxyOrigin = void 0;
4
- exports.cloudTestingOrigin = exports.appTestingOrigin = exports.cloudAiCompanionOrigin = exports.vertexAIOrigin = exports.cloudSQLAdminOrigin = exports.dataConnectLocalConnString = exports.dataconnectP4SADomain = exports.dataconnectOrigin = exports.githubClientSecret = exports.githubClientId = exports.computeOrigin = exports.secretManagerOrigin = exports.githubApiOrigin = exports.githubOrigin = exports.studioApiOrigin = exports.serviceUsageOrigin = exports.cloudRunApiOrigin = exports.hostingApiOrigin = exports.firebaseStorageOrigin = void 0;
4
+ exports.developerKnowledgeOrigin = exports.cloudTestingOrigin = exports.appTestingOrigin = exports.cloudAiCompanionOrigin = exports.vertexAIOrigin = exports.cloudSQLAdminOrigin = exports.dataConnectLocalConnString = exports.dataconnectP4SADomain = exports.dataconnectOrigin = exports.githubClientSecret = exports.githubClientId = exports.computeOrigin = exports.secretManagerOrigin = exports.githubApiOrigin = exports.githubOrigin = exports.studioApiOrigin = exports.serviceUsageOrigin = exports.cloudRunApiOrigin = exports.hostingApiOrigin = exports.firebaseStorageOrigin = void 0;
5
5
  exports.getScopes = getScopes;
6
6
  exports.setScopes = setScopes;
7
7
  const constants_1 = require("./emulator/constants");
@@ -152,6 +152,8 @@ const appTestingOrigin = () => utils.envOverride("FIREBASE_APP_TESTING_URL", "ht
152
152
  exports.appTestingOrigin = appTestingOrigin;
153
153
  const cloudTestingOrigin = () => utils.envOverride("CLOUD_TESTING_URL", "https://testing.googleapis.com");
154
154
  exports.cloudTestingOrigin = cloudTestingOrigin;
155
+ const developerKnowledgeOrigin = () => utils.envOverride("DEVELOPER_KNOWLEDGE_URL", "https://developerknowledge.googleapis.com");
156
+ exports.developerKnowledgeOrigin = developerKnowledgeOrigin;
155
157
  function getScopes() {
156
158
  return Array.from(commandScopes);
157
159
  }
package/lib/apiv2.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Client = exports.STANDARD_HEADERS = void 0;
3
+ exports.Client = exports.CLI_OAUTH_PROJECT_NUMBER = exports.GOOG_USER_PROJECT_HEADER = exports.standardHeaders = void 0;
4
4
  exports.setRefreshToken = setRefreshToken;
5
5
  exports.setAccessToken = setAccessToken;
6
6
  exports.getAccessToken = getAccessToken;
@@ -13,19 +13,28 @@ const node_fetch_1 = require("node-fetch");
13
13
  const util_1 = require("util");
14
14
  const auth = require("./auth");
15
15
  const error_1 = require("./error");
16
+ const env_1 = require("./env");
16
17
  const logger_1 = require("./logger");
17
18
  const responseToError_1 = require("./responseToError");
18
19
  const FormData = require("form-data");
19
20
  const pkg = require("../package.json");
20
21
  const CLI_VERSION = pkg.version;
21
- exports.STANDARD_HEADERS = {
22
- Connection: "keep-alive",
23
- "User-Agent": `FirebaseCLI/${CLI_VERSION}`,
24
- "X-Client-Version": `FirebaseCLI/${CLI_VERSION}`,
22
+ const standardHeaders = () => {
23
+ const agent = (0, env_1.detectAIAgent)();
24
+ const agentStr = agent === "unknown" ? "" : ` agent-name/${agent}`;
25
+ const platform = (0, env_1.isFirebaseMcp)() ? "FirebaseMCP" : "FirebaseCLI";
26
+ const clientVersion = `${platform}/${CLI_VERSION}${agentStr}`;
27
+ return {
28
+ Connection: "keep-alive",
29
+ "User-Agent": clientVersion,
30
+ "X-Client-Version": clientVersion,
31
+ };
25
32
  };
33
+ exports.standardHeaders = standardHeaders;
26
34
  const GOOG_QUOTA_USER_HEADER = "x-goog-quota-user";
27
- const GOOG_USER_PROJECT_HEADER = "x-goog-user-project";
35
+ exports.GOOG_USER_PROJECT_HEADER = "x-goog-user-project";
28
36
  const GOOGLE_CLOUD_QUOTA_PROJECT = process.env.GOOGLE_CLOUD_QUOTA_PROJECT;
37
+ exports.CLI_OAUTH_PROJECT_NUMBER = "563584335869";
29
38
  let accessToken = "";
30
39
  let refreshToken = "";
31
40
  function setRefreshToken(token = "") {
@@ -123,6 +132,10 @@ class Client {
123
132
  return await this.doRequest(internalReqOptions);
124
133
  }
125
134
  catch (thrown) {
135
+ const originalErrorMessage = thrown.original?.message || thrown.message || "";
136
+ if (originalErrorMessage.includes(exports.CLI_OAUTH_PROJECT_NUMBER)) {
137
+ throw new error_1.FirebaseError("An Internal error has occurred. Please try again in a few minutes. If this error persists, please open an issue at https://github.com/firebase/firebase-tools", { original: thrown });
138
+ }
126
139
  if (thrown instanceof error_1.FirebaseError) {
127
140
  throw thrown;
128
141
  }
@@ -140,7 +153,7 @@ class Client {
140
153
  if (!reqOptions.headers) {
141
154
  reqOptions.headers = new node_fetch_1.Headers();
142
155
  }
143
- for (const [h, v] of Object.entries(exports.STANDARD_HEADERS)) {
156
+ for (const [h, v] of Object.entries((0, exports.standardHeaders)())) {
144
157
  if (!reqOptions.headers.has(h)) {
145
158
  reqOptions.headers.set(h, v);
146
159
  }
@@ -153,7 +166,7 @@ class Client {
153
166
  if (!reqOptions.ignoreQuotaProject &&
154
167
  GOOGLE_CLOUD_QUOTA_PROJECT &&
155
168
  GOOGLE_CLOUD_QUOTA_PROJECT !== "") {
156
- reqOptions.headers.set(GOOG_USER_PROJECT_HEADER, GOOGLE_CLOUD_QUOTA_PROJECT);
169
+ reqOptions.headers.set(exports.GOOG_USER_PROJECT_HEADER, GOOGLE_CLOUD_QUOTA_PROJECT);
157
170
  }
158
171
  return reqOptions;
159
172
  }
@@ -342,8 +355,14 @@ class Client {
342
355
  const logURL = this.requestURL(options);
343
356
  logger_1.logger.debug(`>>> [apiv2][query] ${options.method} ${logURL} ${queryParamsLog}`);
344
357
  const headers = options.headers;
345
- if (headers && headers.has(GOOG_QUOTA_USER_HEADER)) {
346
- logger_1.logger.debug(`>>> [apiv2][(partial)header] ${options.method} ${logURL} x-goog-quota-user=${headers.get(GOOG_QUOTA_USER_HEADER) || ""}`);
358
+ if (headers && (headers.has(GOOG_QUOTA_USER_HEADER) || headers.has(exports.GOOG_USER_PROJECT_HEADER))) {
359
+ const userHeader = headers.has(GOOG_QUOTA_USER_HEADER)
360
+ ? `${GOOG_QUOTA_USER_HEADER}=${headers.get(GOOG_QUOTA_USER_HEADER)}`
361
+ : "";
362
+ const projectHeader = headers.has(exports.GOOG_USER_PROJECT_HEADER)
363
+ ? `${exports.GOOG_USER_PROJECT_HEADER}=${headers.get(exports.GOOG_USER_PROJECT_HEADER)}`
364
+ : "";
365
+ logger_1.logger.debug(`>>> [apiv2][(partial)header] ${options.method} ${logURL} ${userHeader} ${projectHeader}`);
347
366
  }
348
367
  if (options.body !== undefined) {
349
368
  let logBody = "[omitted]";
@@ -225,7 +225,7 @@ class AppDistributionClient {
225
225
  }
226
226
  utils.logSuccess(`Testers removed from group successfully`);
227
227
  }
228
- async createReleaseTest(releaseName, devices, aiInstruction, loginCredential, testCaseName) {
228
+ async createReleaseTest(releaseName, devices, aiInstructions, loginCredential, testCaseName, displayName) {
229
229
  try {
230
230
  const response = await this.appDistroV1AlphaClient.request({
231
231
  method: "POST",
@@ -234,7 +234,8 @@ class AppDistributionClient {
234
234
  deviceExecutions: devices.map((device) => ({ device })),
235
235
  loginCredential,
236
236
  testCase: testCaseName,
237
- aiInstructions: aiInstruction,
237
+ aiInstructions: aiInstructions,
238
+ displayName: displayName,
238
239
  },
239
240
  });
240
241
  return response.body;
@@ -297,5 +298,22 @@ class AppDistributionClient {
297
298
  throw new error_1.FirebaseError(`Failed to upsert test cases ${(0, error_1.getErrMsg)(err)}`);
298
299
  }
299
300
  }
301
+ async getLatestRelease(appName) {
302
+ try {
303
+ const response = await this.appDistroV1Client.get(`/${appName}/releases`, {
304
+ queryParams: {
305
+ pageSize: "1",
306
+ orderBy: "createTime desc",
307
+ },
308
+ });
309
+ if (!response.body.releases?.length) {
310
+ return undefined;
311
+ }
312
+ return response.body.releases[0];
313
+ }
314
+ catch (err) {
315
+ throw new error_1.FirebaseError(`Failed to get latest release for app ${appName}: ${(0, error_1.getErrMsg)(err)}`);
316
+ }
317
+ }
300
318
  }
301
319
  exports.AppDistributionClient = AppDistributionClient;
@@ -39,7 +39,7 @@ async function upload(requests, appName, distribution) {
39
39
  utils.logSuccess(`View this release in the Firebase console: ${release.firebaseConsoleUri}`);
40
40
  utils.logSuccess(`Share this release with testers who have access: ${release.testingUri}`);
41
41
  utils.logSuccess(`Download the release binary (link expires in 1 hour): ${release.binaryDownloadUri}`);
42
- return uploadResponse.release.name;
42
+ return uploadResponse.release;
43
43
  }
44
44
  catch (err) {
45
45
  if ((0, error_1.getErrStatus)(err) === 404) {
@@ -50,7 +50,14 @@ function getAppName(options) {
50
50
  }
51
51
  return toAppName(options.app);
52
52
  }
53
+ const APP_ID_FORMAT = /^\d+:\d+:(android|ios|web):[a-fA-F0-9]+$/;
54
+ function validateAppId(appId) {
55
+ if (!APP_ID_FORMAT.test(appId)) {
56
+ throw new error_1.FirebaseError(`Invalid Firebase app ID: ${appId}`);
57
+ }
58
+ }
53
59
  function toAppName(appId) {
60
+ validateAppId(appId);
54
61
  return `projects/${appId.split(":")[1]}/apps/${appId}`;
55
62
  }
56
63
  function parseTestDevices(value, file = "") {
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toYaml = toYaml;
4
+ exports.fromYamlStep = fromYamlStep;
4
5
  exports.fromYaml = fromYaml;
5
6
  const jsYaml = require("js-yaml");
6
7
  const error_1 = require("../error");
7
- const ALLOWED_YAML_STEP_KEYS = new Set(["goal", "hint", "successCriteria"]);
8
+ const ALLOWED_YAML_STEP_KEYS = new Set(["goal", "hint", "finalScreenAssertion"]);
8
9
  const ALLOWED_YAML_TEST_CASE_KEYS = new Set([
9
10
  "displayName",
10
11
  "id",
@@ -24,12 +25,14 @@ function toYamlTestCases(testCases) {
24
25
  steps: testCase.aiInstructions.steps.map((step) => ({
25
26
  goal: step.goal,
26
27
  ...(step.hint && { hint: step.hint }),
27
- ...(step.successCriteria && { successCriteria: step.successCriteria }),
28
+ ...(step.successCriteria && {
29
+ finalScreenAssertion: step.successCriteria,
30
+ }),
28
31
  })),
29
32
  }));
30
33
  }
31
34
  function toYaml(testCases) {
32
- return jsYaml.safeDump(toYamlTestCases(testCases));
35
+ return jsYaml.safeDump({ tests: toYamlTestCases(testCases) });
33
36
  }
34
37
  function castExists(it, thing) {
35
38
  if (it == null) {
@@ -44,22 +47,23 @@ function checkAllowedKeys(allowedKeys, o) {
44
47
  }
45
48
  }
46
49
  }
50
+ function fromYamlStep(yamlStep) {
51
+ checkAllowedKeys(ALLOWED_YAML_STEP_KEYS, yamlStep);
52
+ return {
53
+ goal: castExists(yamlStep.goal, "goal"),
54
+ ...(yamlStep.hint && { hint: yamlStep.hint }),
55
+ ...(yamlStep.finalScreenAssertion && {
56
+ successCriteria: yamlStep.finalScreenAssertion,
57
+ }),
58
+ };
59
+ }
47
60
  function fromYamlTestCases(appName, yamlTestCases) {
48
61
  return yamlTestCases.map((yamlTestCase) => {
49
62
  checkAllowedKeys(ALLOWED_YAML_TEST_CASE_KEYS, yamlTestCase);
50
63
  return {
51
64
  displayName: castExists(yamlTestCase.displayName, "displayName"),
52
65
  aiInstructions: {
53
- steps: castExists(yamlTestCase.steps, "steps").map((yamlStep) => {
54
- checkAllowedKeys(ALLOWED_YAML_STEP_KEYS, yamlStep);
55
- return {
56
- goal: castExists(yamlStep.goal, "goal"),
57
- ...(yamlStep.hint && { hint: yamlStep.hint }),
58
- ...(yamlStep.successCriteria && {
59
- successCriteria: yamlStep.successCriteria,
60
- }),
61
- };
62
- }),
66
+ steps: castExists(yamlTestCase.steps, "steps").map((yamlStep) => fromYamlStep(yamlStep)),
63
67
  },
64
68
  ...(yamlTestCase.id && {
65
69
  name: `${appName}/testCases/${yamlTestCase.id}`,
@@ -78,8 +82,12 @@ function fromYaml(appName, yaml) {
78
82
  catch (err) {
79
83
  throw new error_1.FirebaseError(`Failed to parse YAML: ${(0, error_1.getErrMsg)(err)}`);
80
84
  }
81
- if (!Array.isArray(parsedYaml)) {
82
- throw new error_1.FirebaseError("YAML file must contain a list of test cases.");
85
+ if (!parsedYaml || typeof parsedYaml !== "object" || !("tests" in parsedYaml)) {
86
+ throw new error_1.FirebaseError("YAML file must contain a top-level 'tests' field with a list of test cases.");
87
+ }
88
+ const yamlTestCases = parsedYaml.tests;
89
+ if (!Array.isArray(yamlTestCases)) {
90
+ throw new error_1.FirebaseError("The 'tests' field in the YAML file must contain a list of test cases.");
83
91
  }
84
- return fromYamlTestCases(appName, parsedYaml);
92
+ return fromYamlTestCases(appName, yamlTestCases);
85
93
  }
@@ -190,7 +190,7 @@ async function ensureAppHostingComputeServiceAccount(projectId, serviceAccount)
190
190
  const sa = serviceAccount || defaultComputeServiceAccountEmail(projectId);
191
191
  const name = `projects/${projectId}/serviceAccounts/${sa}`;
192
192
  try {
193
- await iam.testResourceIamPermissions((0, api_1.iamOrigin)(), "v1", name, ["iam.serviceAccounts.actAs"], `projects/${projectId}`);
193
+ await iam.testResourceIamPermissions((0, api_1.iamOrigin)(), "v1", name, ["iam.serviceAccounts.actAs"], `${projectId}`);
194
194
  }
195
195
  catch (err) {
196
196
  if (!(err instanceof error_1.FirebaseError)) {
@@ -4,6 +4,7 @@ exports.APPHOSTING_YAML_FILE_REGEX = exports.APPHOSTING_LOCAL_YAML_FILE = export
4
4
  exports.discoverBackendRoot = discoverBackendRoot;
5
5
  exports.listAppHostingFilesInPath = listAppHostingFilesInPath;
6
6
  exports.load = load;
7
+ exports.getAppHostingConfiguration = getAppHostingConfiguration;
7
8
  exports.store = store;
8
9
  exports.findEnv = findEnv;
9
10
  exports.upsertEnv = upsertEnv;
@@ -22,6 +23,7 @@ const yaml_1 = require("./yaml");
22
23
  const logger_1 = require("../logger");
23
24
  const csm = require("../gcp/secretManager");
24
25
  const error_1 = require("../error");
26
+ const path_2 = require("path");
25
27
  exports.APPHOSTING_BASE_YAML_FILE = "apphosting.yaml";
26
28
  exports.APPHOSTING_EMULATORS_YAML_FILE = "apphosting.emulator.yaml";
27
29
  exports.APPHOSTING_LOCAL_YAML_FILE = "apphosting.local.yaml";
@@ -64,6 +66,28 @@ function load(yamlPath) {
64
66
  }
65
67
  return yaml.parseDocument(raw);
66
68
  }
69
+ const dynamicDispatch = exports;
70
+ async function getAppHostingConfiguration(backendDir) {
71
+ const appHostingConfigPaths = dynamicDispatch.listAppHostingFilesInPath(backendDir);
72
+ const fileNameToPathMap = Object.fromEntries(appHostingConfigPaths.map((path) => [(0, path_2.basename)(path), path]));
73
+ const output = yaml_1.AppHostingYamlConfig.empty();
74
+ const baseFilePath = fileNameToPathMap[exports.APPHOSTING_BASE_YAML_FILE];
75
+ const emulatorsFilePath = fileNameToPathMap[exports.APPHOSTING_EMULATORS_YAML_FILE];
76
+ const localFilePath = fileNameToPathMap[exports.APPHOSTING_LOCAL_YAML_FILE];
77
+ if (baseFilePath) {
78
+ const baseFile = await yaml_1.AppHostingYamlConfig.loadFromFile(baseFilePath);
79
+ output.merge(baseFile, false);
80
+ }
81
+ if (emulatorsFilePath) {
82
+ const emulatorsConfig = await yaml_1.AppHostingYamlConfig.loadFromFile(emulatorsFilePath);
83
+ output.merge(emulatorsConfig, false);
84
+ }
85
+ if (localFilePath) {
86
+ const localYamlConfig = await yaml_1.AppHostingYamlConfig.loadFromFile(localFilePath);
87
+ output.merge(localYamlConfig, true);
88
+ }
89
+ return output;
90
+ }
67
91
  function store(yamlPath, document) {
68
92
  (0, fs_1.writeFileSync)(yamlPath, document.toString());
69
93
  }
@@ -94,7 +118,6 @@ function upsertEnv(document, env) {
94
118
  }
95
119
  envs.add(envYaml);
96
120
  }
97
- const dynamicDispatch = exports;
98
121
  async function maybeAddSecretToYaml(secretName, fileName = exports.APPHOSTING_BASE_YAML_FILE) {
99
122
  const backendRoot = dynamicDispatch.discoverBackendRoot(process.cwd());
100
123
  let path;
@@ -125,7 +125,7 @@ async function orchestrateRollout(args) {
125
125
  throw new error_1.FirebaseError("Failed to build your app, but failed to get build logs as well. " +
126
126
  "This is an internal error and should be reported");
127
127
  }
128
- throw new error_1.FirebaseError(`Failed to build your app. Please inspect the build logs at ${build.buildLogsUri}.`, { children: [build.error] });
128
+ throw new error_1.FirebaseError(`Failed to build your app. Please inspect the build logs at ${build.buildLogsUri}`, { children: [build.error] });
129
129
  }
130
130
  return { rollout, build };
131
131
  }
@@ -71,7 +71,7 @@ exports.WARN_NO_BACKENDS = "To use this secret, your backend's service account m
71
71
  "It does not look like you have a backend yet. After creating a backend, grant access with " +
72
72
  clc.bold("firebase apphosting:secrets:grantaccess");
73
73
  exports.GRANT_ACCESS_IN_FUTURE = `To grant access in the future, run ${clc.bold("firebase apphosting:secrets:grantaccess")}`;
74
- async function selectBackendServiceAccounts(projectNumber, projectId, options) {
74
+ async function selectBackendServiceAccounts(projectNumber, projectId, nonInteractive) {
75
75
  const listBackends = await apphosting.listBackends(projectId, "-");
76
76
  if (listBackends.unreachable.length) {
77
77
  utils.logWarning(`Could not reach location(s) ${listBackends.unreachable.join(", ")}. You may need to run ` +
@@ -83,7 +83,7 @@ async function selectBackendServiceAccounts(projectNumber, projectId, options) {
83
83
  }
84
84
  if (listBackends.backends.length === 1) {
85
85
  const grant = await prompt.confirm({
86
- nonInteractive: options.nonInteractive,
86
+ nonInteractive,
87
87
  default: true,
88
88
  message: "To use this secret, your backend's service account must be granted access. Would you like to grant access now?",
89
89
  });
@@ -101,7 +101,7 @@ async function selectBackendServiceAccounts(projectNumber, projectId, options) {
101
101
  serviceAccountDisplay(metadata[0]) +
102
102
  ".\nGranting access to one backend will grant access to all backends.");
103
103
  const grant = await prompt.confirm({
104
- nonInteractive: options.nonInteractive,
104
+ nonInteractive,
105
105
  default: true,
106
106
  message: "Would you like to grant access to all backends now?",
107
107
  });
@@ -7,6 +7,8 @@ exports.grantEmailsSecretAccess = grantEmailsSecretAccess;
7
7
  exports.upsertSecret = upsertSecret;
8
8
  exports.fetchSecrets = fetchSecrets;
9
9
  exports.getSecretNameParts = getSecretNameParts;
10
+ exports.apphostingSecretsSetAction = apphostingSecretsSetAction;
11
+ const clc = require("colorette");
10
12
  const error_1 = require("../../error");
11
13
  const gcsm = require("../../gcp/secretManager");
12
14
  const gcb = require("../../gcp/cloudbuild");
@@ -16,6 +18,9 @@ const secretManager_1 = require("../../gcp/secretManager");
16
18
  const secretManager_2 = require("../../gcp/secretManager");
17
19
  const utils = require("../../utils");
18
20
  const prompt = require("../../prompt");
21
+ const dialogs = require("../../apphosting/secrets/dialogs");
22
+ const config = require("../../apphosting/config");
23
+ const projects_1 = require("../../management/projects");
19
24
  function toMulti(accounts) {
20
25
  const m = {
21
26
  buildServiceAccounts: [accounts.buildServiceAccount],
@@ -169,3 +174,57 @@ function getSecretNameParts(secret) {
169
174
  }
170
175
  return [name, version];
171
176
  }
177
+ async function apphostingSecretsSetAction(secretName, projectId, projectNumber, location, dataFile, nonInteractive) {
178
+ if (!projectNumber) {
179
+ projectNumber = (await (0, projects_1.getProject)(projectId)).projectNumber;
180
+ }
181
+ const created = await upsertSecret(projectId, secretName, location);
182
+ if (created === null) {
183
+ return;
184
+ }
185
+ else if (created) {
186
+ utils.logSuccess(`Created new secret projects/${projectId}/secrets/${secretName}`);
187
+ }
188
+ const secretValue = await utils.readSecretValue(`Enter a value for ${secretName}`, dataFile);
189
+ const version = await gcsm.addVersion(projectId, secretName, secretValue);
190
+ utils.logSuccess(`Created new secret version ${gcsm.toSecretVersionResourceName(version)}`);
191
+ utils.logBullet(`You can access the contents of the secret's latest value with ${clc.bold(`firebase apphosting:secrets:access ${secretName}\n`)}`);
192
+ if (!created) {
193
+ return;
194
+ }
195
+ const type = await prompt.select({
196
+ message: "Is this secret for production or only local testing?",
197
+ choices: [
198
+ { name: "Production", value: "production" },
199
+ { name: "Local testing only", value: "local" },
200
+ ],
201
+ nonInteractive: !!nonInteractive,
202
+ default: "production",
203
+ });
204
+ if (type === "local") {
205
+ const emailList = await prompt.input({
206
+ message: "Please enter a comma separated list of user or groups who should have access to this secret:",
207
+ });
208
+ if (emailList.length) {
209
+ await grantEmailsSecretAccess(projectId, [secretName], emailList.split(","));
210
+ }
211
+ else {
212
+ utils.logBullet("To grant access in the future run " +
213
+ clc.bold(`firebase apphosting:secrets:grantaccess ${secretName} --emails [email list]`));
214
+ }
215
+ await config.maybeAddSecretToYaml(secretName, config.APPHOSTING_EMULATORS_YAML_FILE);
216
+ return;
217
+ }
218
+ const accounts = await dialogs.selectBackendServiceAccounts(projectNumber, projectId, !!nonInteractive);
219
+ if (!accounts.buildServiceAccounts.length && !accounts.runServiceAccounts.length) {
220
+ utils.logWarning(`To use this secret in your backend, you must grant access. You can do so in the future with ${clc.bold("firebase apphosting:secrets:grantaccess")}`);
221
+ }
222
+ else {
223
+ await grantSecretAccess(projectId, projectNumber, secretName, accounts);
224
+ }
225
+ await config.maybeAddSecretToYaml(secretName, config.APPHOSTING_BASE_YAML_FILE);
226
+ utils.logBullet("To grant additional users access to this secret run " +
227
+ clc.bold(`firebase apphosting:secrets:grantaccess ${secretName} --email [email list]`) +
228
+ ".\nTo grant additional backends access to this secret run " +
229
+ clc.bold(`firebase apphosting:secrets:grantaccess ${secretName} --backend [backend ID]`));
230
+ }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getEnvironmentName = getEnvironmentName;
4
4
  exports.promptForAppHostingYaml = promptForAppHostingYaml;
5
+ exports.getAutoinitEnvVars = getAutoinitEnvVars;
5
6
  const error_1 = require("../error");
6
7
  const config_1 = require("./config");
7
8
  const prompt = require("../prompt");
@@ -36,3 +37,16 @@ async function promptForAppHostingYaml(apphostingFileNameToPathMap, promptMessag
36
37
  });
37
38
  return fileToExportPath;
38
39
  }
40
+ function getAutoinitEnvVars(webappConfig) {
41
+ if (!webappConfig) {
42
+ return {};
43
+ }
44
+ return {
45
+ FIREBASE_WEBAPP_CONFIG: JSON.stringify(webappConfig),
46
+ FIREBASE_CONFIG: JSON.stringify({
47
+ databaseURL: webappConfig.databaseURL,
48
+ storageBucket: webappConfig.storageBucket,
49
+ projectId: webappConfig.projectId,
50
+ }),
51
+ };
52
+ }