firebase-tools-with-isolate 13.16.0 → 13.26.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 (221) hide show
  1. package/lib/api.js +3 -1
  2. package/lib/apiv2.js +10 -3
  3. package/lib/appdistribution/client.js +62 -8
  4. package/lib/appdistribution/distribution.js +1 -1
  5. package/lib/apphosting/backend.js +299 -0
  6. package/lib/apphosting/config.js +31 -8
  7. package/lib/apphosting/githubConnections.js +70 -22
  8. package/lib/apphosting/index.js +3 -312
  9. package/lib/apphosting/rollout.js +138 -0
  10. package/lib/apphosting/secrets/index.js +70 -5
  11. package/lib/apphosting/utils.js +41 -0
  12. package/lib/apphosting/yaml.js +82 -0
  13. package/lib/archiveDirectory.js +1 -1
  14. package/lib/auth.js +31 -5
  15. package/lib/bin/firebase.js +2 -2
  16. package/lib/command.js +18 -4
  17. package/lib/commands/appdistribution-distribute.js +4 -4
  18. package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
  19. package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
  20. package/lib/commands/appdistribution-groups-list.js +55 -0
  21. package/lib/commands/appdistribution-testers-list.js +52 -0
  22. package/lib/commands/appdistribution-testers-remove.js +1 -1
  23. package/lib/commands/apphosting-backends-create.js +4 -4
  24. package/lib/commands/apphosting-backends-delete.js +7 -15
  25. package/lib/commands/apphosting-backends-get.js +1 -1
  26. package/lib/commands/apphosting-config-export.js +51 -0
  27. package/lib/commands/apphosting-repos-create.js +23 -0
  28. package/lib/commands/apphosting-rollouts-create.js +14 -15
  29. package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
  30. package/lib/commands/database-import.js +4 -2
  31. package/lib/commands/database-push.js +4 -2
  32. package/lib/commands/database-set.js +4 -2
  33. package/lib/commands/database-settings-get.js +1 -1
  34. package/lib/commands/database-settings-set.js +1 -1
  35. package/lib/commands/dataconnect-sdk-generate.js +4 -1
  36. package/lib/commands/dataconnect-services-list.js +4 -3
  37. package/lib/commands/dataconnect-sql-diff.js +1 -1
  38. package/lib/commands/dataconnect-sql-grant.js +37 -0
  39. package/lib/commands/dataconnect-sql-migrate.js +1 -1
  40. package/lib/commands/dataconnect-sql-shell.js +115 -0
  41. package/lib/commands/deploy.js +2 -0
  42. package/lib/commands/emulators-start.js +4 -1
  43. package/lib/commands/ext-dev-init.js +2 -2
  44. package/lib/commands/ext-dev-list.js +1 -1
  45. package/lib/commands/ext-dev-register.js +2 -2
  46. package/lib/commands/ext-dev-upload.js +2 -2
  47. package/lib/commands/ext-dev-usage.js +2 -2
  48. package/lib/commands/ext-info.js +3 -1
  49. package/lib/commands/ext-install.js +2 -2
  50. package/lib/commands/ext-sdk-install.js +88 -0
  51. package/lib/commands/ext.js +1 -0
  52. package/lib/commands/firestore-databases-restore.js +39 -1
  53. package/lib/commands/functions-secrets-access.js +2 -4
  54. package/lib/commands/index.js +15 -2
  55. package/lib/commands/init.js +25 -15
  56. package/lib/commands/setup-emulators-dataconnect.js +0 -13
  57. package/lib/commands/use.js +1 -1
  58. package/lib/config.js +14 -4
  59. package/lib/crashlytics/buildToolsJarHelper.js +2 -2
  60. package/lib/dataconnect/client.js +1 -1
  61. package/lib/dataconnect/dataplaneClient.js +12 -9
  62. package/lib/dataconnect/ensureApis.js +6 -1
  63. package/lib/dataconnect/fileUtils.js +15 -39
  64. package/lib/dataconnect/freeTrial.js +45 -9
  65. package/lib/dataconnect/load.js +3 -1
  66. package/lib/dataconnect/provisionCloudSql.js +39 -26
  67. package/lib/dataconnect/schemaMigration.js +215 -74
  68. package/lib/dataconnect/types.js +4 -1
  69. package/lib/dataconnect/webhook.js +32 -0
  70. package/lib/deploy/dataconnect/deploy.js +18 -15
  71. package/lib/deploy/dataconnect/prepare.js +41 -0
  72. package/lib/deploy/dataconnect/release.js +16 -7
  73. package/lib/deploy/extensions/deploy.js +3 -1
  74. package/lib/deploy/extensions/deploymentSummary.js +7 -3
  75. package/lib/deploy/extensions/planner.js +44 -5
  76. package/lib/deploy/extensions/prepare.js +45 -73
  77. package/lib/deploy/extensions/release.js +11 -10
  78. package/lib/deploy/extensions/tasks.js +32 -21
  79. package/lib/deploy/firestore/prepare.js +9 -0
  80. package/lib/deploy/firestore/release.js +3 -6
  81. package/lib/deploy/functions/checkIam.js +7 -2
  82. package/lib/deploy/functions/ensure.js +11 -3
  83. package/lib/deploy/functions/prepare.js +32 -21
  84. package/lib/deploy/functions/prepareFunctionsUpload.js +15 -16
  85. package/lib/deploy/functions/release/planner.js +2 -1
  86. package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
  87. package/lib/deploy/functions/runtimes/node/index.js +5 -0
  88. package/lib/deploy/functions/services/auth.js +34 -3
  89. package/lib/deploy/functions/services/index.js +2 -0
  90. package/lib/deploy/index.js +8 -5
  91. package/lib/deploy/lifecycleHooks.js +2 -1
  92. package/lib/emulator/apphosting/config.js +27 -0
  93. package/lib/emulator/apphosting/index.js +38 -0
  94. package/lib/emulator/apphosting/serve.js +50 -0
  95. package/lib/emulator/apphosting/utils.js +18 -0
  96. package/lib/emulator/auth/handlers.js +27 -0
  97. package/lib/emulator/auth/operations.js +41 -2
  98. package/lib/emulator/auth/state.js +2 -1
  99. package/lib/emulator/commandUtils.js +8 -3
  100. package/lib/emulator/constants.js +4 -1
  101. package/lib/emulator/controller.js +48 -5
  102. package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
  103. package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
  104. package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
  105. package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
  106. package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
  107. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
  108. package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
  109. package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
  110. package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
  111. package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
  112. package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
  113. package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
  114. package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
  115. package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
  116. package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
  117. package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
  118. package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
  119. package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
  120. package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
  121. package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
  122. package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
  123. package/lib/emulator/dataconnect/pgliteServer.js +95 -0
  124. package/lib/emulator/dataconnectEmulator.js +58 -75
  125. package/lib/emulator/dataconnectToolkitController.js +44 -0
  126. package/lib/emulator/downloadableEmulators.js +27 -16
  127. package/lib/emulator/emulatorLogger.js +3 -0
  128. package/lib/emulator/eventarcEmulator.js +1 -1
  129. package/lib/emulator/extensionsEmulator.js +38 -6
  130. package/lib/emulator/functionsEmulator.js +85 -41
  131. package/lib/emulator/functionsEmulatorShared.js +2 -1
  132. package/lib/emulator/functionsRuntimeWorker.js +2 -1
  133. package/lib/emulator/hub.js +13 -9
  134. package/lib/emulator/hubExport.js +10 -3
  135. package/lib/emulator/loggingEmulator.js +2 -2
  136. package/lib/emulator/portUtils.js +10 -11
  137. package/lib/emulator/registry.js +1 -0
  138. package/lib/emulator/storage/persistence.js +2 -2
  139. package/lib/emulator/storage/rules/runtime.js +1 -1
  140. package/lib/emulator/tasksEmulator.js +5 -2
  141. package/lib/emulator/types.js +3 -0
  142. package/lib/emulator/ui.js +51 -25
  143. package/lib/error.js +31 -1
  144. package/lib/experiments.js +5 -0
  145. package/lib/extensions/emulator/triggerHelper.js +1 -1
  146. package/lib/extensions/extensionsApi.js +14 -10
  147. package/lib/extensions/extensionsHelper.js +15 -6
  148. package/lib/extensions/localHelper.js +31 -0
  149. package/lib/extensions/runtimes/common.js +179 -39
  150. package/lib/extensions/runtimes/node.js +401 -0
  151. package/lib/extensions/types.js +25 -14
  152. package/lib/extensions/warnings.js +5 -2
  153. package/lib/firestore/api.js +2 -1
  154. package/lib/firestore/checkDatabaseType.js +10 -3
  155. package/lib/firestore/delete.js +11 -0
  156. package/lib/firestore/options.js +7 -0
  157. package/lib/frameworks/angular/index.js +15 -3
  158. package/lib/frameworks/constants.js +1 -1
  159. package/lib/frameworks/flutter/index.js +6 -6
  160. package/lib/frameworks/flutter/utils.js +34 -1
  161. package/lib/frameworks/next/index.js +10 -2
  162. package/lib/frameworks/next/utils.js +8 -5
  163. package/lib/frameworks/vite/index.js +2 -2
  164. package/lib/fsutils.js +13 -1
  165. package/lib/functions/constants.js +4 -0
  166. package/lib/functions/events/v1.js +9 -2
  167. package/lib/gcp/apphosting.js +1 -1
  168. package/lib/gcp/cloudmonitoring.js +3 -3
  169. package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
  170. package/lib/gcp/cloudsql/connect.js +49 -37
  171. package/lib/gcp/cloudsql/interactive.js +49 -0
  172. package/lib/gcp/cloudsql/permissions.js +165 -0
  173. package/lib/gcp/devConnect.js +38 -1
  174. package/lib/gcp/firestore.js +5 -1
  175. package/lib/gcp/secretManager.js +12 -5
  176. package/lib/getProjectNumber.js +1 -1
  177. package/lib/init/features/apphosting.js +15 -0
  178. package/lib/init/features/dataconnect/index.js +159 -120
  179. package/lib/init/features/dataconnect/sdk.js +77 -84
  180. package/lib/init/features/emulators.js +2 -15
  181. package/lib/init/features/firestore/index.js +20 -1
  182. package/lib/init/features/firestore/indexes.js +4 -4
  183. package/lib/init/features/genkit/index.js +444 -0
  184. package/lib/init/features/hosting/index.js +2 -2
  185. package/lib/init/features/index.js +1 -1
  186. package/lib/init/features/project.js +6 -6
  187. package/lib/init/features/storage.js +0 -2
  188. package/lib/init/index.js +1 -0
  189. package/lib/init/spawn.js +23 -2
  190. package/lib/logger.js +2 -2
  191. package/lib/management/projects.js +24 -4
  192. package/lib/projectUtils.js +1 -1
  193. package/lib/prompt.js +1 -1
  194. package/lib/rc.js +1 -8
  195. package/lib/requireAuth.js +19 -5
  196. package/lib/requireDatabaseInstance.js +1 -1
  197. package/lib/requirePermissions.js +1 -1
  198. package/lib/responseToError.js +5 -2
  199. package/lib/rulesDeploy.js +1 -1
  200. package/lib/templates.js +2 -2
  201. package/lib/utils.js +16 -11
  202. package/lib/vsCodeUtils.js +8 -0
  203. package/package.json +7 -6
  204. package/schema/connector-yaml.json +57 -17
  205. package/schema/firebase-config.json +24 -0
  206. package/templates/extensions/javascript/package.lint.json +2 -2
  207. package/templates/extensions/javascript/package.nolint.json +2 -2
  208. package/templates/extensions/typescript/package.lint.json +2 -2
  209. package/templates/extensions/typescript/package.nolint.json +2 -2
  210. package/templates/genkit/firebase.0.9.0.template +57 -0
  211. package/templates/init/apphosting/apphosting.yaml +23 -0
  212. package/templates/init/dataconnect/connector.yaml +0 -1
  213. package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
  214. package/templates/init/dataconnect/dataconnect.yaml +1 -1
  215. package/templates/init/dataconnect/queries.gql +1 -2
  216. package/templates/init/functions/javascript/package.lint.json +2 -2
  217. package/templates/init/functions/javascript/package.nolint.json +2 -2
  218. package/templates/init/functions/typescript/package.lint.json +2 -2
  219. package/templates/init/functions/typescript/package.nolint.json +2 -2
  220. package/lib/ensureCloudResourceLocation.js +0 -12
  221. package/lib/init/features/genkit.js +0 -53
@@ -15,7 +15,7 @@ const metadataCallCache = new Map();
15
15
  async function defaultServiceAccount(e) {
16
16
  let metadataCall = metadataCallCache.get(e.project);
17
17
  if (!metadataCall) {
18
- metadataCall = (0, projects_1.getFirebaseProject)(e.project);
18
+ metadataCall = (0, projects_1.getProject)(e.project);
19
19
  metadataCallCache.set(e.project, metadataCall);
20
20
  }
21
21
  const metadata = await metadataCall;
@@ -78,10 +78,18 @@ async function secretsToServiceAccounts(b) {
78
78
  }
79
79
  return secretsToSa;
80
80
  }
81
- async function secretAccess(projectId, wantBackend, haveBackend) {
81
+ async function secretAccess(projectId, wantBackend, haveBackend, dryRun) {
82
82
  const ensureAccess = async (secret, serviceAccounts) => {
83
83
  (0, utils_1.logLabeledBullet)("functions", `ensuring ${clc.bold(serviceAccounts.join(", "))} access to secret ${clc.bold(secret)}.`);
84
- await (0, secretManager_1.ensureServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
84
+ if (dryRun) {
85
+ const check = await (0, secretManager_1.checkServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
86
+ if (check.length) {
87
+ (0, utils_1.logLabeledBullet)("functions", `On your next deploy, ${clc.bold(serviceAccounts.join(", "))} will be granted access to secret ${clc.bold(secret)}.`);
88
+ }
89
+ }
90
+ else {
91
+ await (0, secretManager_1.ensureServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
92
+ }
85
93
  (0, utils_1.logLabeledSuccess)("functions", `ensured ${clc.bold(serviceAccounts.join(", "))} access to ${clc.bold(secret)}.`);
86
94
  };
87
95
  const wantSecrets = await secretsToServiceAccounts(wantBackend);
@@ -2,31 +2,32 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadCodebases = exports.resolveCpuAndConcurrency = exports.inferBlockingDetails = exports.updateEndpointTargetedStatus = exports.inferDetailsFromExisting = exports.prepare = exports.EVENTARC_SOURCE_ENV = void 0;
4
4
  const clc = require("colorette");
5
- const backend = require("./backend");
6
- const build = require("./build");
5
+ const api_1 = require("../../api");
7
6
  const ensureApiEnabled = require("../../ensureApiEnabled");
8
- const functionsConfig = require("../../functionsConfig");
7
+ const error_1 = require("../../error");
8
+ const functional_1 = require("../../functional");
9
9
  const functionsEnv = require("../../functions/env");
10
- const runtimes = require("./runtimes");
11
- const supported = require("./runtimes/supported");
12
- const validate = require("./validate");
10
+ const v1_1 = require("../../functions/events/v1");
11
+ const projectConfig_1 = require("../../functions/projectConfig");
12
+ const functionsConfig = require("../../functionsConfig");
13
+ const serviceusage_1 = require("../../gcp/serviceusage");
14
+ const logger_1 = require("../../logger");
15
+ const projectUtils_1 = require("../../projectUtils");
16
+ const utils_1 = require("../../utils");
17
+ const prepare_1 = require("../extensions/prepare");
18
+ const backend = require("./backend");
19
+ const backend_1 = require("./backend");
20
+ const build = require("./build");
21
+ const applyHash_1 = require("./cache/applyHash");
22
+ const checkIam_1 = require("./checkIam");
13
23
  const ensure = require("./ensure");
14
- const api_1 = require("../../api");
15
24
  const functionsDeployHelper_1 = require("./functionsDeployHelper");
16
- const utils_1 = require("../../utils");
17
25
  const prepareFunctionsUpload_1 = require("./prepareFunctionsUpload");
18
26
  const prompts_1 = require("./prompts");
19
- const projectUtils_1 = require("../../projectUtils");
20
- const logger_1 = require("../../logger");
27
+ const runtimes = require("./runtimes");
28
+ const supported = require("./runtimes/supported");
21
29
  const triggerRegionHelper_1 = require("./triggerRegionHelper");
22
- const checkIam_1 = require("./checkIam");
23
- const error_1 = require("../../error");
24
- const projectConfig_1 = require("../../functions/projectConfig");
25
- const v1_1 = require("../../functions/events/v1");
26
- const serviceusage_1 = require("../../gcp/serviceusage");
27
- const applyHash_1 = require("./cache/applyHash");
28
- const backend_1 = require("./backend");
29
- const functional_1 = require("../../functional");
30
+ const validate = require("./validate");
30
31
  exports.EVENTARC_SOURCE_ENV = "EVENTARC_CLOUD_EVENT_SOURCE";
31
32
  async function prepare(context, options, payload) {
32
33
  const projectId = (0, projectUtils_1.needProjectId)(options);
@@ -54,6 +55,13 @@ async function prepare(context, options, payload) {
54
55
  }
55
56
  context.codebaseDeployEvents = {};
56
57
  const wantBuilds = await loadCodebases(context.config, options, firebaseConfig, runtimeConfig, context.filters);
58
+ if (Object.values(wantBuilds).some((b) => b.extensions)) {
59
+ const extContext = {};
60
+ const extPayload = {};
61
+ await (0, prepare_1.prepareDynamicExtensions)(extContext, options, extPayload, wantBuilds);
62
+ context.extensions = extContext;
63
+ payload.extensions = extPayload;
64
+ }
57
65
  const codebaseUsesEnvs = [];
58
66
  const wantBackends = {};
59
67
  for (const [codebase, wantBuild] of Object.entries(wantBuilds)) {
@@ -129,11 +137,14 @@ async function prepare(context, options, payload) {
129
137
  for (const [codebase, wantBackend] of Object.entries(wantBackends)) {
130
138
  const config = (0, projectConfig_1.configForCodebase)(context.config, codebase);
131
139
  const sourceDirName = config.source;
132
- const sourceDir = options.config.path(sourceDirName);
140
+ let sourceDir = options.config.path(sourceDirName);
133
141
  const source = {};
134
142
  if (backend.someEndpoint(wantBackend, () => true)) {
135
143
  (0, utils_1.logLabeledBullet)("functions", `preparing ${clc.bold(sourceDirName)} directory for uploading...`);
136
144
  }
145
+ if (config.isolate === true) {
146
+ sourceDir = await (0, prepareFunctionsUpload_1.runIsolate)(config);
147
+ }
137
148
  if (backend.someEndpoint(wantBackend, (e) => e.platform === "gcfv2")) {
138
149
  const packagedSource = await (0, prepareFunctionsUpload_1.prepareFunctionsUpload)(sourceDir, config);
139
150
  source.functionsSourceV2 = packagedSource?.pathToSource;
@@ -182,9 +193,9 @@ async function prepare(context, options, payload) {
182
193
  await (0, prompts_1.promptForFailurePolicies)(options, matchingBackend, haveBackend);
183
194
  await (0, prompts_1.promptForMinInstances)(options, matchingBackend, haveBackend);
184
195
  await backend.checkAvailability(context, matchingBackend);
185
- await (0, checkIam_1.ensureServiceAgentRoles)(projectId, projectNumber, matchingBackend, haveBackend);
186
196
  await validate.secretsAreValid(projectId, matchingBackend);
187
- await ensure.secretAccess(projectId, matchingBackend, haveBackend);
197
+ await (0, checkIam_1.ensureServiceAgentRoles)(projectId, projectNumber, matchingBackend, haveBackend, options.dryRun);
198
+ await ensure.secretAccess(projectId, matchingBackend, haveBackend, options.dryRun);
188
199
  updateEndpointTargetedStatus(wantBackends, context.filters || []);
189
200
  (0, applyHash_1.applyBackendHashToBackends)(wantBackends, context);
190
201
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToSortedKeyValueArray = exports.prepareFunctionsUpload = exports.getFunctionsConfig = void 0;
3
+ exports.convertToSortedKeyValueArray = exports.runIsolate = exports.prepareFunctionsUpload = exports.getFunctionsConfig = void 0;
4
4
  const archiver = require("archiver");
5
5
  const clc = require("colorette");
6
6
  const filesize = require("filesize");
@@ -92,24 +92,23 @@ async function packageSource(sourceDir, config, runtimeConfig) {
92
92
  return { pathToSource: tmpFile, hash };
93
93
  }
94
94
  async function prepareFunctionsUpload(sourceDir, config, runtimeConfig) {
95
- if (config.isolate === true) {
96
- utils.logLabeledBullet("functions", `Start isolating the source folder...`);
97
- try {
98
- const { isolate } = (await (0, dynamicImport_1.dynamicImport)("isolate-package"));
99
- const isolateDir = await isolate();
100
- utils.logLabeledBullet("functions", `Finished isolation at ${clc.bold(isolateDir)}`);
101
- return packageSource(isolateDir, config, runtimeConfig);
102
- }
103
- catch (err) {
104
- utils.logLabeledBullet("functions", `+++ Failed to isolate: ${err.message}`);
105
- throw err;
106
- }
95
+ return packageSource(sourceDir, config, runtimeConfig);
96
+ }
97
+ exports.prepareFunctionsUpload = prepareFunctionsUpload;
98
+ async function runIsolate(_config) {
99
+ try {
100
+ utils.logLabeledBullet("functions", `Isolate the source`);
101
+ const { isolate } = (await (0, dynamicImport_1.dynamicImport)("isolate-package"));
102
+ const isolateDir = await isolate();
103
+ utils.logLabeledBullet("functions", `Finished isolation at ${clc.bold(isolateDir)}`);
104
+ return isolateDir;
107
105
  }
108
- else {
109
- return packageSource(sourceDir, config, runtimeConfig);
106
+ catch (err) {
107
+ utils.logLabeledBullet("functions", `Isolation failed: ${err.message}`, "error");
108
+ throw err;
110
109
  }
111
110
  }
112
- exports.prepareFunctionsUpload = prepareFunctionsUpload;
111
+ exports.runIsolate = runIsolate;
113
112
  function convertToSortedKeyValueArray(config) {
114
113
  if (typeof config !== "object" || config === null)
115
114
  return config;
@@ -206,7 +206,8 @@ function checkForIllegalUpdate(want, have) {
206
206
  exports.checkForIllegalUpdate = checkForIllegalUpdate;
207
207
  function checkForV2Upgrade(want, have) {
208
208
  if (want.platform === "gcfv2" && have.platform === "gcfv1") {
209
- throw new error_1.FirebaseError(`[${(0, functionsDeployHelper_1.getFunctionLabel)(have)}] Upgrading from GCFv1 to GCFv2 is not yet supported. Please delete your old function or wait for this feature to be ready.`);
209
+ throw new error_1.FirebaseError(`[${(0, functionsDeployHelper_1.getFunctionLabel)(have)}] Upgrading from 1st Gen to 2nd Gen is not yet supported. ` +
210
+ "See https://firebase.google.com/docs/functions/2nd-gen-upgrade before migrating to 2nd Gen.");
210
211
  }
211
212
  }
212
213
  exports.checkForV2Upgrade = checkForV2Upgrade;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectFromPort = exports.detectFromYaml = exports.yamlToBuild = exports.readFileAsync = void 0;
3
+ exports.detectFromPort = exports.detectFromYaml = exports.yamlToBuild = exports.getFunctionDiscoveryTimeout = exports.readFileAsync = void 0;
4
4
  const node_fetch_1 = require("node-fetch");
5
5
  const fs = require("fs");
6
6
  const path = require("path");
@@ -12,6 +12,10 @@ const v1alpha1 = require("./v1alpha1");
12
12
  const error_1 = require("../../../../error");
13
13
  exports.readFileAsync = (0, util_1.promisify)(fs.readFile);
14
14
  const TIMEOUT_OVERRIDE_ENV_VAR = "FUNCTIONS_DISCOVERY_TIMEOUT";
15
+ function getFunctionDiscoveryTimeout() {
16
+ return +(process.env[TIMEOUT_OVERRIDE_ENV_VAR] || 0) * 1000;
17
+ }
18
+ exports.getFunctionDiscoveryTimeout = getFunctionDiscoveryTimeout;
15
19
  function yamlToBuild(yaml, project, region, runtime) {
16
20
  try {
17
21
  if (!yaml.specVersion) {
@@ -51,7 +55,7 @@ async function detectFromPort(port, project, runtime, timeout = 10000) {
51
55
  const timedOut = new Promise((resolve, reject) => {
52
56
  setTimeout(() => {
53
57
  reject(new error_1.FirebaseError("User code failed to load. Cannot determine backend specification"));
54
- }, +(process.env[TIMEOUT_OVERRIDE_ENV_VAR] || 0) * 1000 || timeout);
58
+ }, getFunctionDiscoveryTimeout() || timeout);
55
59
  });
56
60
  while (true) {
57
61
  try {
@@ -19,6 +19,7 @@ const versioning = require("./versioning");
19
19
  const parseTriggers = require("./parseTriggers");
20
20
  const fsutils_1 = require("../../../../fsutils");
21
21
  const MIN_FUNCTIONS_SDK_VERSION = "3.20.0";
22
+ const MIN_FUNCTIONS_SDK_VERSION_FOR_EXTENSIONS_FEATURES = "5.1.0";
22
23
  async function tryCreateDelegate(context) {
23
24
  const packageJsonPath = path.join(context.sourceDir, "package.json");
24
25
  if (!(await (0, util_1.promisify)(fs.exists)(packageJsonPath))) {
@@ -163,6 +164,10 @@ class Delegate {
163
164
  `Please update firebase-functions SDK to >=${MIN_FUNCTIONS_SDK_VERSION}`);
164
165
  return parseTriggers.discoverBuild(this.projectId, this.sourceDir, this.runtime, config, env);
165
166
  }
167
+ if (semver.lt(this.sdkVersion, MIN_FUNCTIONS_SDK_VERSION_FOR_EXTENSIONS_FEATURES)) {
168
+ (0, utils_1.logLabeledBullet)("functions", `You are using a version of firebase-functions SDK (${this.sdkVersion}) that does not have support for the newest Firebase Extensions features. ` +
169
+ `Please update firebase-functions SDK to >=${MIN_FUNCTIONS_SDK_VERSION_FOR_EXTENSIONS_FEATURES} to use them correctly`);
170
+ }
166
171
  let discovered = await discovery.detectFromYaml(this.sourceDir, this.projectId, this.runtime);
167
172
  if (!discovered) {
168
173
  const basePort = 8000 + (0, utils_1.randomInt)(0, 1000);
@@ -29,7 +29,11 @@ class AuthBlockingService {
29
29
  configChanged(newConfig, config) {
30
30
  if (newConfig.triggers?.beforeCreate?.functionUri !==
31
31
  config.triggers?.beforeCreate?.functionUri ||
32
- newConfig.triggers?.beforeSignIn?.functionUri !== config.triggers?.beforeSignIn?.functionUri) {
32
+ newConfig.triggers?.beforeSignIn?.functionUri !==
33
+ config.triggers?.beforeSignIn?.functionUri ||
34
+ newConfig.triggers?.beforeSendEmail?.functionUri !==
35
+ config.triggers?.beforeSendEmail?.functionUri ||
36
+ newConfig.triggers?.beforeSendSms?.functionUri !== config.triggers?.beforeSendSms?.functionUri) {
33
37
  return true;
34
38
  }
35
39
  if (!!newConfig.forwardInboundCredentials?.accessToken !==
@@ -53,7 +57,7 @@ class AuthBlockingService {
53
57
  },
54
58
  };
55
59
  }
56
- else {
60
+ else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SIGN_IN_EVENT) {
57
61
  newBlockingConfig.triggers = {
58
62
  ...newBlockingConfig.triggers,
59
63
  beforeSignIn: {
@@ -61,6 +65,25 @@ class AuthBlockingService {
61
65
  },
62
66
  };
63
67
  }
68
+ else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SEND_EMAIL_EVENT) {
69
+ newBlockingConfig.triggers = {
70
+ ...newBlockingConfig.triggers,
71
+ beforeSendEmail: {
72
+ functionUri: endpoint.uri,
73
+ },
74
+ };
75
+ }
76
+ else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SEND_SMS_EVENT) {
77
+ newBlockingConfig.triggers = {
78
+ ...newBlockingConfig.triggers,
79
+ beforeSendSms: {
80
+ functionUri: endpoint.uri,
81
+ },
82
+ };
83
+ }
84
+ else {
85
+ throw new error_1.FirebaseError(`Received invalid blocking trigger event type ${endpoint.blockingTrigger.eventType}`);
86
+ }
64
87
  newBlockingConfig.forwardInboundCredentials = {
65
88
  ...oldBlockingConfig.forwardInboundCredentials,
66
89
  ...endpoint.blockingTrigger.options,
@@ -80,7 +103,9 @@ class AuthBlockingService {
80
103
  async unregisterTriggerLocked(endpoint) {
81
104
  const blockingConfig = await identityPlatform.getBlockingFunctionsConfig(endpoint.project);
82
105
  if (endpoint.uri !== blockingConfig.triggers?.beforeCreate?.functionUri &&
83
- endpoint.uri !== blockingConfig.triggers?.beforeSignIn?.functionUri) {
106
+ endpoint.uri !== blockingConfig.triggers?.beforeSignIn?.functionUri &&
107
+ endpoint.uri !== blockingConfig.triggers?.beforeSendEmail?.functionUri &&
108
+ endpoint.uri !== blockingConfig.triggers?.beforeSendSms?.functionUri) {
84
109
  return;
85
110
  }
86
111
  if (endpoint.uri === blockingConfig.triggers?.beforeCreate?.functionUri) {
@@ -89,6 +114,12 @@ class AuthBlockingService {
89
114
  if (endpoint.uri === blockingConfig.triggers?.beforeSignIn?.functionUri) {
90
115
  delete blockingConfig.triggers?.beforeSignIn;
91
116
  }
117
+ if (endpoint.uri === blockingConfig.triggers?.beforeSendEmail?.functionUri) {
118
+ delete blockingConfig.triggers?.beforeSendEmail;
119
+ }
120
+ if (endpoint.uri === blockingConfig.triggers?.beforeSendSms?.functionUri) {
121
+ delete blockingConfig.triggers?.beforeSendSms;
122
+ }
92
123
  await identityPlatform.setBlockingFunctionsConfig(endpoint.project, blockingConfig);
93
124
  }
94
125
  unregisterTrigger(ep) {
@@ -94,6 +94,8 @@ const EVENT_SERVICE_MAPPING = {
94
94
  "google.firebase.firebasealerts.alerts.v1.published": firebaseAlertsService,
95
95
  "providers/cloud.auth/eventTypes/user.beforeCreate": authBlockingService,
96
96
  "providers/cloud.auth/eventTypes/user.beforeSignIn": authBlockingService,
97
+ "providers/cloud.auth/eventTypes/user.beforeSendEmail": authBlockingService,
98
+ "providers/cloud.auth/eventTypes/user.beforeSendSms": authBlockingService,
97
99
  "google.firebase.database.ref.v1.written": databaseService,
98
100
  "google.firebase.database.ref.v1.created": databaseService,
99
101
  "google.firebase.database.ref.v1.updated": databaseService,
@@ -85,9 +85,11 @@ const deploy = async function (targetNames, options, customContext = {}) {
85
85
  }
86
86
  predeploys.push((0, lifecycleHooks_1.lifecycleHooks)(targetName, "predeploy"));
87
87
  prepares.push(target.prepare);
88
- deploys.push(target.deploy);
89
- releases.push(target.release);
90
- postdeploys.push((0, lifecycleHooks_1.lifecycleHooks)(targetName, "postdeploy"));
88
+ if (!options.dryRun) {
89
+ deploys.push(target.deploy);
90
+ releases.push(target.release);
91
+ postdeploys.push((0, lifecycleHooks_1.lifecycleHooks)(targetName, "postdeploy"));
92
+ }
91
93
  }
92
94
  logger_1.logger.info();
93
95
  logger_1.logger.info((0, colorette_1.bold)((0, colorette_1.white)("===") + " Deploying to '" + projectId + "'..."));
@@ -110,11 +112,12 @@ const deploy = async function (targetNames, options, customContext = {}) {
110
112
  analyticsParams[t] = "true";
111
113
  }
112
114
  await (0, track_1.trackGA4)("product_deploy", analyticsParams, duration);
115
+ const successMessage = options.dryRun ? "Dry run complete!" : "Deploy complete!";
113
116
  logger_1.logger.info();
114
- (0, utils_1.logSuccess)((0, colorette_1.bold)((0, colorette_1.underline)("Deploy complete!")));
117
+ (0, utils_1.logSuccess)((0, colorette_1.bold)((0, colorette_1.underline)(successMessage)));
115
118
  logger_1.logger.info();
116
119
  const deployedHosting = (0, lodash_1.includes)(targetNames, "hosting");
117
- logger_1.logger.info((0, colorette_1.bold)("Project Console:"), (0, utils_1.consoleUrl)(options.project, "/overview"));
120
+ logger_1.logger.info((0, colorette_1.bold)("Project Console:"), (0, utils_1.consoleUrl)(options.project ?? "_", "/overview"));
118
121
  if (deployedHosting) {
119
122
  (0, lodash_1.each)(context.hosting.deploys, (deploy) => {
120
123
  logger_1.logger.info((0, colorette_1.bold)("Hosting URL:"), (0, utils_1.addSubdomain)((0, api_1.hostingOrigin)(), deploy.config.site));
@@ -8,9 +8,10 @@ const error_1 = require("../error");
8
8
  const needProjectId = require("../projectUtils").needProjectId;
9
9
  const logger_1 = require("../logger");
10
10
  const path = require("path");
11
+ const vsCodeUtils_1 = require("../vsCodeUtils");
11
12
  function runCommand(command, childOptions) {
12
13
  const escapedCommand = command.replace(/\"/g, '\\"');
13
- const isVSCode = utils.isVSCodeExtension();
14
+ const isVSCode = (0, vsCodeUtils_1.isVSCodeExtension)();
14
15
  const nodeExecutable = isVSCode ? "node" : process.execPath;
15
16
  const crossEnvShellPath = isVSCode
16
17
  ? path.resolve(__dirname, "./cross-env/dist/bin/cross-env-shell.js")
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLocalAppHostingConfiguration = void 0;
4
+ const path_1 = require("path");
5
+ const config_1 = require("../../apphosting/config");
6
+ const yaml_1 = require("../../apphosting/yaml");
7
+ async function getLocalAppHostingConfiguration(backendDir) {
8
+ const appHostingConfigPaths = (0, config_1.listAppHostingFilesInPath)(backendDir);
9
+ const fileNameToPathMap = new Map();
10
+ for (const path of appHostingConfigPaths) {
11
+ const fileName = (0, path_1.basename)(path);
12
+ fileNameToPathMap.set(fileName, path);
13
+ }
14
+ const baseFilePath = fileNameToPathMap.get(config_1.APPHOSTING_BASE_YAML_FILE);
15
+ const localFilePath = fileNameToPathMap.get(config_1.APPHOSTING_LOCAL_YAML_FILE);
16
+ if (!baseFilePath && !localFilePath) {
17
+ return yaml_1.AppHostingYamlConfig.empty();
18
+ }
19
+ if (!baseFilePath || !localFilePath) {
20
+ return await yaml_1.AppHostingYamlConfig.loadFromFile((baseFilePath || localFilePath));
21
+ }
22
+ const localYamlConfig = await yaml_1.AppHostingYamlConfig.loadFromFile(localFilePath);
23
+ const baseConfig = await yaml_1.AppHostingYamlConfig.loadFromFile(baseFilePath);
24
+ baseConfig.merge(localYamlConfig);
25
+ return baseConfig;
26
+ }
27
+ exports.getLocalAppHostingConfiguration = getLocalAppHostingConfiguration;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppHostingEmulator = void 0;
4
+ const types_1 = require("../types");
5
+ const serve_1 = require("./serve");
6
+ const utils_1 = require("./utils");
7
+ class AppHostingEmulator {
8
+ constructor(args) {
9
+ this.args = args;
10
+ }
11
+ async start() {
12
+ const { hostname, port } = await (0, serve_1.start)({
13
+ startCommand: this.args.startCommandOverride,
14
+ rootDirectory: this.args.rootDirectory,
15
+ });
16
+ this.args.options.host = hostname;
17
+ this.args.options.port = port;
18
+ }
19
+ connect() {
20
+ utils_1.logger.logLabeled("INFO", types_1.Emulators.APPHOSTING, "connecting apphosting emulator");
21
+ return Promise.resolve();
22
+ }
23
+ stop() {
24
+ utils_1.logger.logLabeled("INFO", types_1.Emulators.APPHOSTING, "stopping apphosting emulator");
25
+ return Promise.resolve();
26
+ }
27
+ getInfo() {
28
+ return {
29
+ name: types_1.Emulators.APPHOSTING,
30
+ host: this.args.options.host,
31
+ port: this.args.options.port,
32
+ };
33
+ }
34
+ getName() {
35
+ return types_1.Emulators.APPHOSTING;
36
+ }
37
+ }
38
+ exports.AppHostingEmulator = AppHostingEmulator;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.start = void 0;
4
+ const net_1 = require("net");
5
+ const portUtils_1 = require("../portUtils");
6
+ const utils_1 = require("./utils");
7
+ const constants_1 = require("../constants");
8
+ const spawn_1 = require("../../init/spawn");
9
+ const utils_2 = require("./utils");
10
+ const types_1 = require("../types");
11
+ const config_1 = require("./config");
12
+ const projectPath_1 = require("../../projectPath");
13
+ async function start(options) {
14
+ const hostname = constants_1.DEFAULT_HOST;
15
+ let port = constants_1.DEFAULT_PORTS.apphosting;
16
+ while (!(await availablePort(hostname, port))) {
17
+ port += 1;
18
+ }
19
+ serve(port, options?.startCommand, options?.rootDirectory);
20
+ return { hostname, port };
21
+ }
22
+ exports.start = start;
23
+ async function serve(port, startCommand, backendRelativeDir) {
24
+ backendRelativeDir = backendRelativeDir ?? "./";
25
+ const backendRoot = (0, projectPath_1.resolveProjectPath)({}, backendRelativeDir);
26
+ const apphostingLocalConfig = await (0, config_1.getLocalAppHostingConfiguration)(backendRoot);
27
+ const environmentVariablesAsRecord = {};
28
+ for (const env of apphostingLocalConfig.environmentVariables) {
29
+ environmentVariablesAsRecord[env.variable] = env.value;
30
+ }
31
+ const environmentVariablesToInject = {
32
+ ...environmentVariablesAsRecord,
33
+ PORT: port.toString(),
34
+ };
35
+ if (startCommand) {
36
+ utils_2.logger.logLabeled("BULLET", types_1.Emulators.APPHOSTING, `running custom start command: '${startCommand}'`);
37
+ await (0, spawn_1.spawnWithCommandString)(startCommand, backendRoot, environmentVariablesToInject);
38
+ return;
39
+ }
40
+ const packageManager = await (0, utils_1.discoverPackageManager)(backendRoot);
41
+ utils_2.logger.logLabeled("BULLET", types_1.Emulators.APPHOSTING, `starting app with: '${packageManager} run dev'`);
42
+ await (0, spawn_1.wrapSpawn)(packageManager, ["run", "dev"], backendRoot, environmentVariablesToInject);
43
+ }
44
+ function availablePort(host, port) {
45
+ return (0, portUtils_1.checkListenable)({
46
+ address: host,
47
+ port,
48
+ family: (0, net_1.isIPv4)(host) ? "IPv4" : "IPv6",
49
+ });
50
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.discoverPackageManager = exports.logger = void 0;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const path_1 = require("path");
6
+ const emulatorLogger_1 = require("../emulatorLogger");
7
+ const types_1 = require("../types");
8
+ exports.logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.APPHOSTING);
9
+ async function discoverPackageManager(rootdir) {
10
+ if (await (0, fs_extra_1.pathExists)((0, path_1.join)(rootdir, "pnpm-lock.yaml"))) {
11
+ return "pnpm";
12
+ }
13
+ if (await (0, fs_extra_1.pathExists)((0, path_1.join)(rootdir, "yarn.lock"))) {
14
+ return "yarn";
15
+ }
16
+ return "npm";
17
+ }
18
+ exports.discoverPackageManager = discoverPackageManager;
@@ -131,6 +131,33 @@ function registerHandlers(app, getProjectStateByApiKey) {
131
131
  }
132
132
  }
133
133
  }
134
+ case "verifyAndChangeEmail": {
135
+ try {
136
+ const { newEmail } = (0, operations_1.setAccountInfoImpl)(state, { oobCode });
137
+ if (continueUrl) {
138
+ return res.redirect(303, continueUrl);
139
+ }
140
+ else {
141
+ return res.status(200).json({
142
+ authEmulator: { success: `The email has been successfully changed.`, newEmail },
143
+ });
144
+ }
145
+ }
146
+ catch (e) {
147
+ if (e instanceof errors_1.NotImplementedError ||
148
+ (e instanceof errors_1.BadRequestError && e.message === "INVALID_OOB_CODE")) {
149
+ return res.status(400).json({
150
+ authEmulator: {
151
+ error: `Your request to change your email has expired or the link has already been used.`,
152
+ instructions: `Try changing your email again.`,
153
+ },
154
+ });
155
+ }
156
+ else {
157
+ throw e;
158
+ }
159
+ }
160
+ }
134
161
  case "signIn": {
135
162
  if (!continueUrl) {
136
163
  return res.status(400).json({
@@ -619,6 +619,7 @@ function resetPassword(state, reqBody) {
619
619
  kind: "identitytoolkit#ResetPasswordResponse",
620
620
  requestType: oob.requestType,
621
621
  email: oob.requestType === "EMAIL_SIGNIN" ? undefined : oob.email,
622
+ newEmail: oob.newEmail,
622
623
  };
623
624
  }
624
625
  exports.resetPassword = resetPassword;
@@ -632,6 +633,7 @@ function sendOobCode(state, reqBody, ctx) {
632
633
  (0, errors_1.assert)((0, utils_1.parseAbsoluteUri)(reqBody.continueUrl), "INVALID_CONTINUE_URI : ((expected an absolute URI with valid scheme and host))");
633
634
  }
634
635
  let email;
636
+ let newEmail;
635
637
  let mode;
636
638
  switch (reqBody.requestType) {
637
639
  case "EMAIL_SIGNIN":
@@ -667,6 +669,24 @@ function sendOobCode(state, reqBody, ctx) {
667
669
  email = user.email;
668
670
  }
669
671
  break;
672
+ case "VERIFY_AND_CHANGE_EMAIL":
673
+ mode = "verifyAndChangeEmail";
674
+ (0, errors_1.assert)(reqBody.newEmail, "MISSING_NEW_EMAIL");
675
+ newEmail = (0, utils_1.canonicalizeEmailAddress)(reqBody.newEmail);
676
+ if (reqBody.returnOobLink && !reqBody.idToken) {
677
+ (0, errors_1.assert)(reqBody.email, "MISSING_EMAIL");
678
+ email = (0, utils_1.canonicalizeEmailAddress)(reqBody.email);
679
+ const maybeUser = state.getUserByEmail(email);
680
+ (0, errors_1.assert)(maybeUser, "USER_NOT_FOUND");
681
+ }
682
+ else {
683
+ (0, errors_1.assert)(reqBody.idToken, "MISSING_ID_TOKEN");
684
+ const user = parseIdToken(state, reqBody.idToken).user;
685
+ (0, errors_1.assert)(user.email, "MISSING_EMAIL");
686
+ email = user.email;
687
+ }
688
+ (0, errors_1.assert)(!state.getUserByEmail(newEmail), "EMAIL_EXISTS");
689
+ break;
670
690
  default:
671
691
  throw new errors_1.NotImplementedError(reqBody.requestType);
672
692
  }
@@ -678,6 +698,7 @@ function sendOobCode(state, reqBody, ctx) {
678
698
  requestType: reqBody.requestType,
679
699
  mode,
680
700
  continueUrl: reqBody.continueUrl,
701
+ newEmail,
681
702
  });
682
703
  if (reqBody.returnOobLink) {
683
704
  return {
@@ -746,6 +767,7 @@ function setAccountInfoImpl(state, reqBody, { privileged = false, emulatorUrl =
746
767
  let user;
747
768
  let signInProvider;
748
769
  let isEmailUpdate = false;
770
+ let newEmail;
749
771
  if (reqBody.oobCode) {
750
772
  const oob = state.validateOobCode(reqBody.oobCode);
751
773
  (0, errors_1.assert)(oob, "INVALID_OOB_CODE");
@@ -762,6 +784,19 @@ function setAccountInfoImpl(state, reqBody, { privileged = false, emulatorUrl =
762
784
  }
763
785
  break;
764
786
  }
787
+ case "VERIFY_AND_CHANGE_EMAIL":
788
+ state.deleteOobCode(reqBody.oobCode);
789
+ const maybeUser = state.getUserByEmail(oob.email);
790
+ (0, errors_1.assert)(maybeUser, "INVALID_OOB_CODE");
791
+ (0, errors_1.assert)(oob.newEmail, "INVALID_OOB_CODE");
792
+ (0, errors_1.assert)(!state.getUserByEmail(oob.newEmail), "EMAIL_EXISTS");
793
+ user = maybeUser;
794
+ if (oob.newEmail !== user.email) {
795
+ updates.email = oob.newEmail;
796
+ updates.emailVerified = true;
797
+ newEmail = oob.newEmail;
798
+ }
799
+ break;
765
800
  case "RECOVER_EMAIL": {
766
801
  state.deleteOobCode(reqBody.oobCode);
767
802
  const maybeUser = state.getUserByInitialEmail(oob.email);
@@ -791,7 +826,7 @@ function setAccountInfoImpl(state, reqBody, { privileged = false, emulatorUrl =
791
826
  }
792
827
  if (reqBody.email) {
793
828
  (0, errors_1.assert)((0, utils_1.isValidEmailAddress)(reqBody.email), "INVALID_EMAIL");
794
- const newEmail = (0, utils_1.canonicalizeEmailAddress)(reqBody.email);
829
+ newEmail = (0, utils_1.canonicalizeEmailAddress)(reqBody.email);
795
830
  if (newEmail !== user.email) {
796
831
  (0, errors_1.assert)(!state.getUserByEmail(newEmail), "EMAIL_EXISTS");
797
832
  updates.email = newEmail;
@@ -889,6 +924,7 @@ function setAccountInfoImpl(state, reqBody, { privileged = false, emulatorUrl =
889
924
  email: user.email,
890
925
  displayName: user.displayName,
891
926
  photoUrl: user.photoUrl,
927
+ newEmail,
892
928
  passwordHash: user.passwordHash,
893
929
  ...(updates.validSince && signInProvider ? issueTokens(state, user, signInProvider) : {}),
894
930
  });
@@ -902,7 +938,7 @@ function sendOobForEmailReset(state, initialEmail, url) {
902
938
  logOobMessage(oobRecord);
903
939
  }
904
940
  function createOobRecord(state, email, url, params) {
905
- const oobRecord = state.createOob(email, params.requestType, (oobCode) => {
941
+ const oobRecord = state.createOob(email, params.newEmail, params.requestType, (oobCode) => {
906
942
  url.pathname = "/emulator/action";
907
943
  url.searchParams.set("mode", params.mode);
908
944
  url.searchParams.set("lang", "en");
@@ -932,6 +968,9 @@ function logOobMessage(oobRecord) {
932
968
  case "VERIFY_EMAIL":
933
969
  maybeMessage = `To verify the email address ${email}, follow this link: ${oobLink}`;
934
970
  break;
971
+ case "VERIFY_AND_CHANGE_EMAIL":
972
+ maybeMessage = `To verify and change the email address from ${email} to ${oobRecord.newEmail}, follow this link: ${oobLink}`;
973
+ break;
935
974
  case "RECOVER_EMAIL":
936
975
  maybeMessage = `To reset your email address to ${email}, follow this link: ${oobLink}`;
937
976
  break;