firebase-tools 13.0.3 → 13.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -484,13 +484,21 @@ function createAuthUri(state, reqBody) {
484
484
  }
485
485
  }
486
486
  }
487
- return {
488
- kind: "identitytoolkit#CreateAuthUriResponse",
489
- registered,
490
- allProviders,
491
- sessionId,
492
- signinMethods,
493
- };
487
+ if (state.enableImprovedEmailPrivacy) {
488
+ return {
489
+ kind: "identitytoolkit#CreateAuthUriResponse",
490
+ sessionId,
491
+ };
492
+ }
493
+ else {
494
+ return {
495
+ kind: "identitytoolkit#CreateAuthUriResponse",
496
+ registered,
497
+ allProviders,
498
+ sessionId,
499
+ signinMethods,
500
+ };
501
+ }
494
502
  }
495
503
  const SESSION_COOKIE_MIN_VALID_DURATION = 5 * 60;
496
504
  exports.SESSION_COOKIE_MAX_VALID_DURATION = 14 * 24 * 60 * 60;
@@ -634,7 +642,14 @@ function sendOobCode(state, reqBody, ctx) {
634
642
  mode = "resetPassword";
635
643
  (0, errors_1.assert)(reqBody.email, "MISSING_EMAIL");
636
644
  email = (0, utils_1.canonicalizeEmailAddress)(reqBody.email);
637
- (0, errors_1.assert)(state.getUserByEmail(email), "EMAIL_NOT_FOUND");
645
+ const maybeUser = state.getUserByEmail(email);
646
+ if (state.enableImprovedEmailPrivacy && !maybeUser) {
647
+ return {
648
+ kind: "identitytoolkit#GetOobConfirmationCodeResponse",
649
+ email,
650
+ };
651
+ }
652
+ (0, errors_1.assert)(maybeUser, "EMAIL_NOT_FOUND");
638
653
  break;
639
654
  case "VERIFY_EMAIL":
640
655
  mode = "verifyEmail";
@@ -1151,7 +1166,7 @@ async function signInWithIdp(state, reqBody) {
1151
1166
  }
1152
1167
  else {
1153
1168
  if (!response.localId) {
1154
- throw new Error("Internal assertion error: localId not set for exising user.");
1169
+ throw new Error("Internal assertion error: localId not set for existing user.");
1155
1170
  }
1156
1171
  const maybeUser = state.getUserByLocalId(response.localId);
1157
1172
  (0, errors_1.assert)(maybeUser, "USER_NOT_FOUND");
@@ -1199,10 +1214,18 @@ async function signInWithPassword(state, reqBody) {
1199
1214
  }
1200
1215
  const email = (0, utils_1.canonicalizeEmailAddress)(reqBody.email);
1201
1216
  let user = state.getUserByEmail(email);
1202
- (0, errors_1.assert)(user, "EMAIL_NOT_FOUND");
1203
- (0, errors_1.assert)(!user.disabled, "USER_DISABLED");
1204
- (0, errors_1.assert)(user.passwordHash && user.salt, "INVALID_PASSWORD");
1205
- (0, errors_1.assert)(user.passwordHash === hashPassword(reqBody.password, user.salt), "INVALID_PASSWORD");
1217
+ if (state.enableImprovedEmailPrivacy) {
1218
+ (0, errors_1.assert)(user, "INVALID_LOGIN_CREDENTIALS");
1219
+ (0, errors_1.assert)(!user.disabled, "USER_DISABLED");
1220
+ (0, errors_1.assert)(user.passwordHash && user.salt, "INVALID_LOGIN_CREDENTIALS");
1221
+ (0, errors_1.assert)(user.passwordHash === hashPassword(reqBody.password, user.salt), "INVALID_LOGIN_CREDENTIALS");
1222
+ }
1223
+ else {
1224
+ (0, errors_1.assert)(user, "EMAIL_NOT_FOUND");
1225
+ (0, errors_1.assert)(!user.disabled, "USER_DISABLED");
1226
+ (0, errors_1.assert)(user.passwordHash && user.salt, "INVALID_PASSWORD");
1227
+ (0, errors_1.assert)(user.passwordHash === hashPassword(reqBody.password, user.salt), "INVALID_PASSWORD");
1228
+ }
1206
1229
  const response = {
1207
1230
  kind: "identitytoolkit#VerifyPasswordResponse",
1208
1231
  registered: true,
@@ -1311,14 +1334,20 @@ function getEmulatorProjectConfig(state) {
1311
1334
  signIn: {
1312
1335
  allowDuplicateEmails: !state.oneAccountPerEmail,
1313
1336
  },
1337
+ emailPrivacyConfig: {
1338
+ enableImprovedEmailPrivacy: state.enableImprovedEmailPrivacy,
1339
+ },
1314
1340
  };
1315
1341
  }
1316
1342
  function updateEmulatorProjectConfig(state, reqBody, ctx) {
1317
- var _a;
1343
+ var _a, _b;
1318
1344
  const updateMask = [];
1319
1345
  if (((_a = reqBody.signIn) === null || _a === void 0 ? void 0 : _a.allowDuplicateEmails) != null) {
1320
1346
  updateMask.push("signIn.allowDuplicateEmails");
1321
1347
  }
1348
+ if (((_b = reqBody.emailPrivacyConfig) === null || _b === void 0 ? void 0 : _b.enableImprovedEmailPrivacy) != null) {
1349
+ updateMask.push("emailPrivacyConfig.enableImprovedEmailPrivacy");
1350
+ }
1322
1351
  ctx.params.query.updateMask = updateMask.join();
1323
1352
  updateConfig(state, reqBody, ctx);
1324
1353
  return getEmulatorProjectConfig(state);
@@ -414,6 +414,9 @@ class AgentProjectState extends ProjectState {
414
414
  this._config = {
415
415
  signIn: { allowDuplicateEmails: false },
416
416
  blockingFunctions: {},
417
+ emailPrivacyConfig: {
418
+ enableImprovedEmailPrivacy: false,
419
+ },
417
420
  };
418
421
  }
419
422
  get authCloudFunction() {
@@ -425,6 +428,12 @@ class AgentProjectState extends ProjectState {
425
428
  set oneAccountPerEmail(oneAccountPerEmail) {
426
429
  this._config.signIn.allowDuplicateEmails = !oneAccountPerEmail;
427
430
  }
431
+ get enableImprovedEmailPrivacy() {
432
+ return !!this._config.emailPrivacyConfig.enableImprovedEmailPrivacy;
433
+ }
434
+ set enableImprovedEmailPrivacy(improveEmailPrivacy) {
435
+ this._config.emailPrivacyConfig.enableImprovedEmailPrivacy = improveEmailPrivacy;
436
+ }
428
437
  get allowPasswordSignup() {
429
438
  return true;
430
439
  }
@@ -470,10 +479,12 @@ class AgentProjectState extends ProjectState {
470
479
  return undefined;
471
480
  }
472
481
  updateConfig(update, updateMask) {
473
- var _a, _b, _c;
482
+ var _a, _b, _c, _d, _e;
474
483
  if (!updateMask) {
475
484
  this.oneAccountPerEmail = (_b = !((_a = update.signIn) === null || _a === void 0 ? void 0 : _a.allowDuplicateEmails)) !== null && _b !== void 0 ? _b : true;
476
485
  this.blockingFunctionsConfig = (_c = update.blockingFunctions) !== null && _c !== void 0 ? _c : {};
486
+ this.enableImprovedEmailPrivacy =
487
+ (_e = (_d = update.emailPrivacyConfig) === null || _d === void 0 ? void 0 : _d.enableImprovedEmailPrivacy) !== null && _e !== void 0 ? _e : false;
477
488
  return this.config;
478
489
  }
479
490
  return applyMask(updateMask, this.config, update);
@@ -546,6 +557,9 @@ class TenantProjectState extends ProjectState {
546
557
  get oneAccountPerEmail() {
547
558
  return this.parentProject.oneAccountPerEmail;
548
559
  }
560
+ get enableImprovedEmailPrivacy() {
561
+ return this.parentProject.enableImprovedEmailPrivacy;
562
+ }
549
563
  get authCloudFunction() {
550
564
  return this.parentProject.authCloudFunction;
551
565
  }
@@ -22,7 +22,7 @@ async function discover(dir) {
22
22
  if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "angular.json"))))
23
23
  return;
24
24
  const version = (0, utils_2.getAngularVersion)(dir);
25
- return { mayWantBackend: true, publicDirectory: (0, path_1.join)(dir, "src", "assets"), version };
25
+ return { mayWantBackend: true, version };
26
26
  }
27
27
  exports.discover = discover;
28
28
  function init(setup, config) {
@@ -59,7 +59,7 @@ async function build(dir, configuration) {
59
59
  }
60
60
  exports.build = build;
61
61
  async function getDevModeHandle(dir, configuration) {
62
- const { targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
62
+ const { targetStringFromTarget } = await (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
63
63
  const { serveTarget } = await (0, utils_2.getContext)(dir, configuration);
64
64
  if (!serveTarget)
65
65
  throw new Error("Could not find the serveTarget");
@@ -9,7 +9,7 @@ const utils_2 = require("../../utils");
9
9
  const semver_1 = require("semver");
10
10
  async function localesForTarget(dir, architectHost, target, workspaceProject) {
11
11
  var _a;
12
- const { targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
12
+ const { targetStringFromTarget } = await (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
13
13
  const targetOptions = await architectHost.getOptionsForTarget(target);
14
14
  if (!targetOptions) {
15
15
  const targetString = targetStringFromTarget(target);
@@ -72,9 +72,11 @@ function getValidBuilders(purpose) {
72
72
  }
73
73
  async function getAllTargets(purpose, dir) {
74
74
  const validBuilders = getValidBuilders(purpose);
75
- const { NodeJsAsyncHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node");
76
- const { workspaces } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core");
77
- const { targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
75
+ const [{ NodeJsAsyncHost }, { workspaces }, { targetStringFromTarget }] = await Promise.all([
76
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node"),
77
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/core"),
78
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect"),
79
+ ]);
78
80
  const host = workspaces.createWorkspaceHost(new NodeJsAsyncHost());
79
81
  const { workspace } = await workspaces.readWorkspace(dir, host);
80
82
  const targets = [];
@@ -98,11 +100,13 @@ async function getAllTargets(purpose, dir) {
98
100
  }
99
101
  exports.getAllTargets = getAllTargets;
100
102
  async function getContext(dir, targetOrConfiguration) {
101
- const { NodeJsAsyncHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node");
102
- const { workspaces } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core");
103
- const { WorkspaceNodeModulesArchitectHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect/node");
104
- const { Architect, targetFromTargetString, targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
105
- const { parse } = (0, utils_1.relativeRequire)(dir, "jsonc-parser");
103
+ const [{ NodeJsAsyncHost }, { workspaces }, { WorkspaceNodeModulesArchitectHost }, { Architect, targetFromTargetString, targetStringFromTarget }, { parse },] = await Promise.all([
104
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node"),
105
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/core"),
106
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect/node"),
107
+ (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect"),
108
+ (0, utils_1.relativeRequire)(dir, "jsonc-parser"),
109
+ ]);
106
110
  const host = workspaces.createWorkspaceHost(new NodeJsAsyncHost());
107
111
  const { workspace } = await workspaces.readWorkspace(dir, host);
108
112
  const architectHost = new WorkspaceNodeModulesArchitectHost(workspace, dir);
@@ -427,7 +431,7 @@ async function getServerConfig(sourceDir, configuration) {
427
431
  }
428
432
  exports.getServerConfig = getServerConfig;
429
433
  async function getBuildConfig(sourceDir, configuration) {
430
- const { targetStringFromTarget } = (0, utils_1.relativeRequire)(sourceDir, "@angular-devkit/architect");
434
+ const { targetStringFromTarget } = await (0, utils_1.relativeRequire)(sourceDir, "@angular-devkit/architect");
431
435
  const { buildTarget, browserTarget, baseHref, prerenderTarget, serverTarget, architectHost, workspaceProject, serveOptimizedImages, ssr, } = await getContext(sourceDir, configuration);
432
436
  const targets = (buildTarget
433
437
  ? [buildTarget]
@@ -17,10 +17,9 @@ async function discover(dir) {
17
17
  const version = (0, utils_2.getAstroVersion)(dir);
18
18
  if (!version)
19
19
  return;
20
- const { output, publicDir: publicDirectory } = await (0, utils_2.getConfig)(dir);
20
+ const { output } = await (0, utils_2.getConfig)(dir);
21
21
  return {
22
22
  mayWantBackend: output !== "static",
23
- publicDirectory,
24
23
  version,
25
24
  };
26
25
  }
@@ -23,7 +23,7 @@ async function discover(dir) {
23
23
  const usingFlutter = (_a = pubSpec.dependencies) === null || _a === void 0 ? void 0 : _a.flutter;
24
24
  if (!usingFlutter)
25
25
  return;
26
- return { mayWantBackend: false, publicDirectory: (0, path_1.join)(dir, "web") };
26
+ return { mayWantBackend: false };
27
27
  }
28
28
  exports.discover = discover;
29
29
  function init(setup, config) {
@@ -189,7 +189,7 @@ async function prepareFrameworks(purpose, targetNames, context, options, emulato
189
189
  if (!results) {
190
190
  throw new error_1.FirebaseError((0, utils_1.frameworksCallToAction)("Unable to detect the web framework in use, check firebase-debug.log for more info."));
191
191
  }
192
- const { framework, mayWantBackend, publicDirectory } = results;
192
+ const { framework, mayWantBackend } = results;
193
193
  const { build, ɵcodegenPublicDirectory, ɵcodegenFunctionsDirectory: codegenProdModeFunctionsDirectory, getDevModeHandle, name, support, docsUrl, supportedRange, getValidBuildTargets = constants_2.GET_DEFAULT_BUILD_TARGETS, shouldUseDevModeHandle = constants_2.DEFAULT_SHOULD_USE_DEV_MODE_HANDLE, } = frameworks_1.WebFrameworks[framework];
194
194
  logger_1.logger.info(`\n${(0, utils_1.frameworksCallToAction)(constants_2.SupportLevelWarnings[support](name), docsUrl, " ", name, results.version, supportedRange, results.vite)}\n`);
195
195
  const hostingEmulatorInfo = emulators.find((e) => e.name === types_1.Emulators.HOSTING);
@@ -211,7 +211,6 @@ async function prepareFrameworks(purpose, targetNames, context, options, emulato
211
211
  getDevModeHandle &&
212
212
  (await getDevModeHandle(getProjectPath(), frameworksBuildTarget, hostingEmulatorInfo));
213
213
  if (devModeHandle) {
214
- config.public = (0, path_1.relative)(projectRoot, publicDirectory);
215
214
  options.frameworksDevModeHandle = devModeHandle;
216
215
  if (mayWantBackend && firebaseDefaults) {
217
216
  codegenFunctionsDirectory = codegenDevModeFunctionsDirectory;
@@ -239,10 +238,10 @@ async function prepareFrameworks(purpose, targetNames, context, options, emulato
239
238
  project,
240
239
  site,
241
240
  });
242
- config.public = (0, path_1.relative)(projectRoot, hostingDist);
243
241
  if (wantsBackend && !omitCloudFunction)
244
242
  codegenFunctionsDirectory = codegenProdModeFunctionsDirectory;
245
243
  }
244
+ config.public = (0, path_1.relative)(projectRoot, hostingDist);
246
245
  config.webFramework = `${framework}${codegenFunctionsDirectory ? "_ssr" : ""}`;
247
246
  if (codegenFunctionsDirectory) {
248
247
  if (firebaseDefaults) {
@@ -379,7 +379,7 @@ async function getDevModeHandle(dir, _, hostingEmulatorInfo) {
379
379
  throw new error_1.FirebaseError(`${clc.bold("firebase serve")} does not support Next.js Middleware. Please use ${clc.bold("firebase emulators:start")} instead.`);
380
380
  }
381
381
  }
382
- let next = (0, utils_1.relativeRequire)(dir, "next");
382
+ let next = await (0, utils_1.relativeRequire)(dir, "next");
383
383
  if ("default" in next)
384
384
  next = next.default;
385
385
  const nextApp = next({
@@ -405,8 +405,10 @@ async function getConfig(dir) {
405
405
  if (!version)
406
406
  throw new Error("Unable to find the next dep, try NPM installing?");
407
407
  if ((0, semver_1.gte)(version, "12.0.0")) {
408
- const { default: loadConfig } = (0, utils_1.relativeRequire)(dir, "next/dist/server/config");
409
- const { PHASE_PRODUCTION_BUILD } = (0, utils_1.relativeRequire)(dir, "next/constants");
408
+ const [{ default: loadConfig }, { PHASE_PRODUCTION_BUILD }] = await Promise.all([
409
+ (0, utils_1.relativeRequire)(dir, "next/dist/server/config"),
410
+ (0, utils_1.relativeRequire)(dir, "next/constants"),
411
+ ]);
410
412
  config = await loadConfig(PHASE_PRODUCTION_BUILD, dir);
411
413
  }
412
414
  else {
@@ -25,8 +25,8 @@ async function discover(dir) {
25
25
  return;
26
26
  if (version && (0, semver_1.lt)(version, "3.0.0-0"))
27
27
  return;
28
- const { dir: { public: publicDirectory }, ssr: mayWantBackend, } = await getConfig(dir);
29
- return { publicDirectory, mayWantBackend, version };
28
+ const { ssr: mayWantBackend } = await getConfig(dir);
29
+ return { mayWantBackend, version };
30
30
  }
31
31
  exports.discover = discover;
32
32
  async function build(cwd) {
@@ -25,8 +25,7 @@ async function discover(rootDir) {
25
25
  const version = (0, utils_2.getNuxtVersion)(rootDir);
26
26
  if (!version || (version && (0, semver_1.gte)(version, "3.0.0-0")))
27
27
  return;
28
- const { app } = await getAndLoadNuxt({ rootDir, for: "build" });
29
- return { mayWantBackend: true, publicDirectory: app.options.dir.static, version };
28
+ return { mayWantBackend: true, version };
30
29
  }
31
30
  exports.discover = discover;
32
31
  async function build(rootDir) {
@@ -13,11 +13,11 @@ exports.discover = (0, vite_1.viteDiscoverWithNpmDependency)("@sveltejs/kit");
13
13
  var vite_2 = require("../vite");
14
14
  Object.defineProperty(exports, "getDevModeHandle", { enumerable: true, get: function () { return vite_2.getDevModeHandle; } });
15
15
  Object.defineProperty(exports, "supportedRange", { enumerable: true, get: function () { return vite_2.supportedRange; } });
16
- async function build(root) {
16
+ async function build(root, target) {
17
17
  var _a;
18
18
  const config = await getConfig(root);
19
19
  const wantsBackend = ((_a = config.kit.adapter) === null || _a === void 0 ? void 0 : _a.name) !== "@sveltejs/adapter-static";
20
- await (0, vite_1.build)(root);
20
+ await (0, vite_1.build)(root, target);
21
21
  return { wantsBackend };
22
22
  }
23
23
  exports.build = build;
@@ -189,11 +189,20 @@ function findDependency(name, options = {}) {
189
189
  return scanDependencyTree(name, json.dependencies);
190
190
  }
191
191
  exports.findDependency = findDependency;
192
- function relativeRequire(dir, mod) {
192
+ async function relativeRequire(dir, mod) {
193
193
  try {
194
194
  const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
195
195
  const path = requireFunc.resolve(mod, { paths: [dir] });
196
- if ((0, path_1.extname)(path) === ".mjs") {
196
+ let packageJson;
197
+ let isEsm = (0, path_1.extname)(path) === ".mjs";
198
+ if (!isEsm) {
199
+ packageJson = await readJSON((0, path_1.join)((0, path_1.dirname)(path), "package.json")).catch(() => undefined);
200
+ isEsm = (packageJson === null || packageJson === void 0 ? void 0 : packageJson.type) === "module";
201
+ }
202
+ if (isEsm) {
203
+ if ((0, path_1.extname)(path) === ".cjs" && (packageJson === null || packageJson === void 0 ? void 0 : packageJson.main)) {
204
+ return dynamicImport((0, path_1.join)((0, path_1.dirname)(path), packageJson.main));
205
+ }
197
206
  return dynamicImport((0, url_1.pathToFileURL)(path).toString());
198
207
  }
199
208
  else {
@@ -68,13 +68,17 @@ async function discover(dir, plugin, npmDependency) {
68
68
  };
69
69
  }
70
70
  exports.discover = discover;
71
- async function build(root) {
72
- const { build } = (0, utils_1.relativeRequire)(root, "vite");
71
+ async function build(root, target) {
72
+ const { build } = await (0, utils_1.relativeRequire)(root, "vite");
73
73
  await (0, utils_1.warnIfCustomBuildScript)(root, exports.name, exports.DEFAULT_BUILD_SCRIPT);
74
74
  const cwd = process.cwd();
75
75
  process.chdir(root);
76
- await build({ root, mode: "production" });
76
+ const originalNodeEnv = process.env.NODE_ENV;
77
+ const envKey = "NODE_ENV";
78
+ process.env[envKey] = target;
79
+ await build({ root, mode: target });
77
80
  process.chdir(cwd);
81
+ process.env[envKey] = originalNodeEnv;
78
82
  return { rewrites: [{ source: "**", destination: "/index.html" }] };
79
83
  }
80
84
  exports.build = build;
@@ -104,7 +108,7 @@ async function getDevModeHandle(dir) {
104
108
  }
105
109
  exports.getDevModeHandle = getDevModeHandle;
106
110
  async function getConfig(root) {
107
- const { resolveConfig } = (0, utils_1.relativeRequire)(root, "vite");
111
+ const { resolveConfig } = await (0, utils_1.relativeRequire)(root, "vite");
108
112
  const cwd = process.cwd();
109
113
  process.chdir(root);
110
114
  const config = await resolveConfig({ root }, "build", "production");
@@ -1,79 +1,120 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensureApiEnabled = exports.listLocations = exports.updateTraffic = exports.listRollouts = exports.createRollout = exports.createBuild = exports.getBuild = exports.deleteBackend = exports.listBackends = exports.getBackend = exports.createBackend = exports.API_VERSION = exports.API_HOST = void 0;
3
+ exports.getNextRolloutId = exports.ensureApiEnabled = exports.listLocations = exports.updateTraffic = exports.listRollouts = exports.createRollout = exports.createBuild = exports.listBuilds = exports.getBuild = exports.deleteBackend = exports.listBackends = exports.getBackend = exports.createBackend = exports.client = exports.API_VERSION = exports.API_HOST = void 0;
4
4
  const proto = require("../gcp/proto");
5
5
  const apiv2_1 = require("../apiv2");
6
6
  const projectUtils_1 = require("../projectUtils");
7
7
  const api_1 = require("../api");
8
8
  const ensureApiEnabled_1 = require("../ensureApiEnabled");
9
+ const deploymentTool = require("../deploymentTool");
10
+ const error_1 = require("../error");
9
11
  exports.API_HOST = new URL(api_1.apphostingOrigin).host;
10
12
  exports.API_VERSION = "v1alpha";
11
- const client = new apiv2_1.Client({
13
+ exports.client = new apiv2_1.Client({
12
14
  urlPrefix: api_1.apphostingOrigin,
13
15
  auth: true,
14
16
  apiVersion: exports.API_VERSION,
15
17
  });
16
18
  async function createBackend(projectId, location, backendReqBoby, backendId) {
17
- const res = await client.post(`projects/${projectId}/locations/${location}/backends`, backendReqBoby, { queryParams: { backendId } });
19
+ const res = await exports.client.post(`projects/${projectId}/locations/${location}/backends`, Object.assign(Object.assign({}, backendReqBoby), { labels: Object.assign(Object.assign({}, backendReqBoby.labels), deploymentTool.labels()) }), { queryParams: { backendId } });
18
20
  return res.body;
19
21
  }
20
22
  exports.createBackend = createBackend;
21
23
  async function getBackend(projectId, location, backendId) {
22
24
  const name = `projects/${projectId}/locations/${location}/backends/${backendId}`;
23
- const res = await client.get(name);
25
+ const res = await exports.client.get(name);
24
26
  return res.body;
25
27
  }
26
28
  exports.getBackend = getBackend;
27
29
  async function listBackends(projectId, location) {
28
30
  const name = `projects/${projectId}/locations/${location}/backends`;
29
- const res = await client.get(name);
31
+ const res = await exports.client.get(name);
30
32
  return res.body;
31
33
  }
32
34
  exports.listBackends = listBackends;
33
35
  async function deleteBackend(projectId, location, backendId) {
34
36
  const name = `projects/${projectId}/locations/${location}/backends/${backendId}`;
35
- const res = await client.delete(name);
37
+ const res = await exports.client.delete(name, { queryParams: { force: "true" } });
36
38
  return res.body;
37
39
  }
38
40
  exports.deleteBackend = deleteBackend;
39
41
  async function getBuild(projectId, location, backendId, buildId) {
40
42
  const name = `projects/${projectId}/locations/${location}/backends/${backendId}/builds/${buildId}`;
41
- const res = await client.get(name);
43
+ const res = await exports.client.get(name);
42
44
  return res.body;
43
45
  }
44
46
  exports.getBuild = getBuild;
47
+ async function listBuilds(projectId, location, backendId) {
48
+ var _a;
49
+ const name = `projects/${projectId}/locations/${location}/backends/${backendId}/builds`;
50
+ let pageToken;
51
+ const res = {
52
+ builds: [],
53
+ unreachable: [],
54
+ };
55
+ do {
56
+ const queryParams = pageToken ? { pageToken } : {};
57
+ const int = await exports.client.get(name, { queryParams });
58
+ res.builds.push(...(int.body.builds || []));
59
+ (_a = res.unreachable) === null || _a === void 0 ? void 0 : _a.push(...(int.body.unreachable || []));
60
+ pageToken = int.body.nextPageToken;
61
+ } while (pageToken);
62
+ res.unreachable = [...new Set(res.unreachable)];
63
+ return res;
64
+ }
65
+ exports.listBuilds = listBuilds;
45
66
  async function createBuild(projectId, location, backendId, buildId, buildInput) {
46
- const res = await client.post(`projects/${projectId}/locations/${location}/backends/${backendId}/builds`, buildInput, { queryParams: { buildId } });
67
+ const res = await exports.client.post(`projects/${projectId}/locations/${location}/backends/${backendId}/builds`, Object.assign(Object.assign({}, buildInput), { labels: Object.assign(Object.assign({}, buildInput.labels), deploymentTool.labels()) }), { queryParams: { buildId } });
47
68
  return res.body;
48
69
  }
49
70
  exports.createBuild = createBuild;
50
71
  async function createRollout(projectId, location, backendId, rolloutId, rollout) {
51
- const res = await client.post(`projects/${projectId}/locations/${location}/backends/${backendId}/rollouts`, rollout, { queryParams: { rolloutId } });
72
+ const res = await exports.client.post(`projects/${projectId}/locations/${location}/backends/${backendId}/rollouts`, Object.assign(Object.assign({}, rollout), { labels: Object.assign(Object.assign({}, rollout.labels), deploymentTool.labels()) }), { queryParams: { rolloutId } });
52
73
  return res.body;
53
74
  }
54
75
  exports.createRollout = createRollout;
55
76
  async function listRollouts(projectId, location, backendId) {
56
- const res = await client.get(`projects/${projectId}/locations/${location}/backends/${backendId}/rollouts`);
57
- return res.body.rollouts;
77
+ const name = `projects/${projectId}/locations/${location}/backends/${backendId}/rollouts`;
78
+ let pageToken = undefined;
79
+ const res = {
80
+ rollouts: [],
81
+ unreachable: [],
82
+ };
83
+ do {
84
+ const queryParams = pageToken ? { pageToken } : {};
85
+ const int = await exports.client.get(name, { queryParams });
86
+ res.rollouts.splice(res.rollouts.length, 0, ...(int.body.rollouts || []));
87
+ res.unreachable.splice(res.unreachable.length, 0, ...(int.body.unreachable || []));
88
+ pageToken = int.body.nextPageToken;
89
+ } while (pageToken);
90
+ res.unreachable = [...new Set(res.unreachable)];
91
+ return res;
58
92
  }
59
93
  exports.listRollouts = listRollouts;
60
94
  async function updateTraffic(projectId, location, backendId, traffic) {
61
- const fieldMasks = proto.fieldMasks(traffic);
95
+ const trafficCopy = Object.assign({}, traffic);
96
+ if ("rolloutPolicy" in traffic) {
97
+ trafficCopy.rolloutPolicy = {};
98
+ }
99
+ const fieldMasks = proto.fieldMasks(trafficCopy);
62
100
  const queryParams = {
63
101
  updateMask: fieldMasks.join(","),
64
102
  };
65
103
  const name = `projects/${projectId}/locations/${location}/backends/${backendId}/traffic`;
66
- const res = await client.patch(name, Object.assign(Object.assign({}, traffic), { name }), {
104
+ const res = await exports.client.patch(name, Object.assign(Object.assign({}, traffic), { name }), {
67
105
  queryParams,
68
106
  });
69
107
  return res.body;
70
108
  }
71
109
  exports.updateTraffic = updateTraffic;
72
110
  async function listLocations(projectId) {
73
- let pageToken;
111
+ let pageToken = undefined;
74
112
  let locations = [];
75
113
  do {
76
- const response = await client.get(`projects/${projectId}/locations`);
114
+ const queryParams = pageToken ? { pageToken } : {};
115
+ const response = await exports.client.get(`projects/${projectId}/locations`, {
116
+ queryParams,
117
+ });
77
118
  if (response.body.locations && response.body.locations.length > 0) {
78
119
  locations = locations.concat(response.body.locations);
79
120
  }
@@ -87,3 +128,31 @@ async function ensureApiEnabled(options) {
87
128
  return await (0, ensureApiEnabled_1.ensure)(projectId, exports.API_HOST, "frameworks", true);
88
129
  }
89
130
  exports.ensureApiEnabled = ensureApiEnabled;
131
+ async function getNextRolloutId(projectId, location, backendId, counter) {
132
+ var _a;
133
+ const date = new Date();
134
+ const year = date.getUTCFullYear();
135
+ const month = String(date.getUTCMonth() + 1).padStart(2, "0");
136
+ const day = String(date.getUTCDay()).padStart(2, "0");
137
+ if (counter) {
138
+ return `build-${year}-${month}-${day}-${String(counter).padStart(3, "0")}`;
139
+ }
140
+ const builds = await exports.listRollouts(projectId, location, backendId);
141
+ if ((_a = builds.unreachable) === null || _a === void 0 ? void 0 : _a.includes(location)) {
142
+ throw new error_1.FirebaseError(`Firebase App Hosting is currently unreachable in location ${location}`);
143
+ }
144
+ let highest = 0;
145
+ const test = new RegExp(`projects/${projectId}/locations/${location}/backends/${backendId}/rollouts/build-${year}-${month}-${day}-(\\d+)`);
146
+ for (const rollout of builds.rollouts) {
147
+ const match = rollout.name.match(test);
148
+ if (!match) {
149
+ continue;
150
+ }
151
+ const n = Number(match[1]);
152
+ if (n > highest) {
153
+ highest = n;
154
+ }
155
+ }
156
+ return `build-${year}-${month}-${day}-${String(highest + 1).padStart(3, "0")}`;
157
+ }
158
+ exports.getNextRolloutId = getNextRolloutId;
@@ -91,7 +91,7 @@ async function createFunction(cloudFunction) {
91
91
  const components = cloudFunction.name.split("/");
92
92
  const functionId = components.splice(-1, 1)[0];
93
93
  cloudFunction.buildConfig.environmentVariables = Object.assign(Object.assign({}, cloudFunction.buildConfig.environmentVariables), { GOOGLE_NODE_RUN_SCRIPTS: "" });
94
- cloudFunction.serviceConfig.environmentVariables = Object.assign(Object.assign({}, cloudFunction.serviceConfig.environmentVariables), { FUNCTION_TARGET: functionId.replaceAll("-", ".") });
94
+ cloudFunction.serviceConfig.environmentVariables = Object.assign(Object.assign({}, cloudFunction.serviceConfig.environmentVariables), { FUNCTION_TARGET: cloudFunction.buildConfig.entryPoint.replaceAll("-", ".") });
95
95
  try {
96
96
  const res = await client.post(components.join("/"), cloudFunction, { queryParams: { functionId } });
97
97
  return res.body;
@@ -144,12 +144,10 @@ async function listFunctionsInternal(projectId, region) {
144
144
  }
145
145
  }
146
146
  async function updateFunction(cloudFunction) {
147
- const components = cloudFunction.name.split("/");
148
- const functionId = components.splice(-1, 1)[0];
149
147
  const fieldMasks = proto.fieldMasks(cloudFunction, "labels", "serviceConfig.environmentVariables", "serviceConfig.secretEnvironmentVariables");
150
148
  cloudFunction.buildConfig.environmentVariables = Object.assign(Object.assign({}, cloudFunction.buildConfig.environmentVariables), { GOOGLE_NODE_RUN_SCRIPTS: "" });
151
149
  fieldMasks.push("buildConfig.buildEnvironmentVariables");
152
- cloudFunction.serviceConfig.environmentVariables = Object.assign(Object.assign({}, cloudFunction.serviceConfig.environmentVariables), { FUNCTION_TARGET: functionId.replaceAll("-", ".") });
150
+ cloudFunction.serviceConfig.environmentVariables = Object.assign(Object.assign({}, cloudFunction.serviceConfig.environmentVariables), { FUNCTION_TARGET: cloudFunction.buildConfig.entryPoint.replaceAll("-", ".") });
153
151
  try {
154
152
  const queryParams = {
155
153
  updateMask: fieldMasks.join(","),
@@ -46,15 +46,13 @@ async function getChannel(project = "-", site, channelId) {
46
46
  }
47
47
  exports.getChannel = getChannel;
48
48
  async function listChannels(project = "-", site) {
49
+ var _a;
49
50
  const channels = [];
50
51
  let nextPageToken = "";
51
52
  for (;;) {
52
53
  try {
53
54
  const res = await apiClient.get(`/projects/${project}/sites/${site}/channels`, { queryParams: { pageToken: nextPageToken, pageSize: 10 } });
54
- const c = res.body.channels;
55
- if (c) {
56
- channels.push(...c);
57
- }
55
+ channels.push(...((_a = res.body.channels) !== null && _a !== void 0 ? _a : []));
58
56
  nextPageToken = res.body.nextPageToken || "";
59
57
  if (!nextPageToken) {
60
58
  return channels;
@@ -100,6 +98,7 @@ async function updateVersion(site, versionId, version) {
100
98
  }
101
99
  exports.updateVersion = updateVersion;
102
100
  async function listVersions(site) {
101
+ var _a;
103
102
  let pageToken = undefined;
104
103
  const versions = [];
105
104
  do {
@@ -110,7 +109,7 @@ async function listVersions(site) {
110
109
  const res = await apiClient.get(`projects/-/sites/${site}/versions`, {
111
110
  queryParams,
112
111
  });
113
- versions.push(...res.body.versions);
112
+ versions.push(...((_a = res.body.versions) !== null && _a !== void 0 ? _a : []));
114
113
  pageToken = res.body.nextPageToken;
115
114
  } while (pageToken);
116
115
  return versions;
@@ -137,15 +136,13 @@ async function createRelease(site, channel, version, partialRelease) {
137
136
  }
138
137
  exports.createRelease = createRelease;
139
138
  async function listSites(project) {
139
+ var _a;
140
140
  const sites = [];
141
141
  let nextPageToken = "";
142
142
  for (;;) {
143
143
  try {
144
144
  const res = await apiClient.get(`/projects/${project}/sites`, { queryParams: { pageToken: nextPageToken, pageSize: 10 } });
145
- const c = res.body.sites;
146
- if (c) {
147
- sites.push(...c);
148
- }
145
+ sites.push(...((_a = res.body.sites) !== null && _a !== void 0 ? _a : []));
149
146
  nextPageToken = res.body.nextPageToken || "";
150
147
  if (!nextPageToken) {
151
148
  return sites;