firebase-tools 15.25.0 → 15.26.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.
Files changed (52) hide show
  1. package/lib/ailogic/templates.js +124 -0
  2. package/lib/api.js +6 -2
  3. package/lib/appcheck/api.js +33 -0
  4. package/lib/appcheck/prompts.js +2 -2
  5. package/lib/appcheck/services.js +135 -0
  6. package/lib/auth.js +33 -15
  7. package/lib/checkValidTargetFilters.js +1 -0
  8. package/lib/command.js +4 -1
  9. package/lib/commands/ailogic-templates-delete.js +53 -0
  10. package/lib/commands/ailogic-templates-get.js +33 -0
  11. package/lib/commands/ailogic-templates-list.js +49 -0
  12. package/lib/commands/ailogic-templates-lock.js +30 -0
  13. package/lib/commands/ailogic-templates-unlock.js +30 -0
  14. package/lib/commands/appcheck-debugtokens-delete.js +1 -1
  15. package/lib/commands/appcheck-debugtokens-list.js +1 -1
  16. package/lib/commands/appcheck-services-get.js +40 -0
  17. package/lib/commands/appcheck-services-list.js +52 -0
  18. package/lib/commands/appcheck-services-set.js +90 -0
  19. package/lib/commands/crashlytics-onboard-web.js +56 -0
  20. package/lib/commands/deploy.js +3 -0
  21. package/lib/commands/firestore-locations.js +3 -1
  22. package/lib/commands/index.js +14 -0
  23. package/lib/commands/login.js +53 -6
  24. package/lib/config.js +1 -0
  25. package/lib/crashlytics/firebasetelemetry.js +36 -0
  26. package/lib/crashlytics/onboarding.js +41 -0
  27. package/lib/crashlytics/sourcemap.js +102 -12
  28. package/lib/deploy/ailogic/index.js +19 -0
  29. package/lib/deploy/ailogic/prepare.js +78 -0
  30. package/lib/deploy/ailogic/release.js +60 -0
  31. package/lib/deploy/functions/build.js +1 -1
  32. package/lib/deploy/functions/functionsDeployHelper.js +18 -12
  33. package/lib/deploy/functions/prepare.js +16 -3
  34. package/lib/deploy/functions/release/executor.js +51 -8
  35. package/lib/deploy/functions/release/fabricator.js +34 -5
  36. package/lib/deploy/index.js +9 -0
  37. package/lib/emulator/controller.js +34 -15
  38. package/lib/emulator/downloadableEmulatorInfo.json +24 -24
  39. package/lib/experiments.js +13 -0
  40. package/lib/extensions/checkProjectBilling.js +3 -73
  41. package/lib/functions/projectConfig.js +98 -12
  42. package/lib/gcp/ailogic.js +70 -1
  43. package/lib/gcp/cloudbilling.js +74 -0
  44. package/lib/gcp/cloudlogging.js +54 -0
  45. package/lib/management/apps.js +1 -2
  46. package/lib/prompt.js +10 -1
  47. package/lib/requirePermissions.js +1 -1
  48. package/lib/serve/functions.js +25 -7
  49. package/lib/tsconfig.compile.tsbuildinfo +1 -1
  50. package/lib/tsconfig.publish.tsbuildinfo +1 -1
  51. package/package.json +1 -1
  52. package/schema/firebase-config.json +132 -0
@@ -11,7 +11,6 @@ const clc = require("colorette");
11
11
  const fs = require("fs");
12
12
  const path = require("path");
13
13
  const fsConfig = require("../firestore/fsConfig");
14
- const proto = require("../gcp/proto");
15
14
  const logger_1 = require("../logger");
16
15
  const track_1 = require("../track");
17
16
  const utils = require("../utils");
@@ -346,20 +345,40 @@ async function startAll(options, showUI = true, runningTestScript = false) {
346
345
  if (runtime && !(0, supported_1.isRuntime)(runtime)) {
347
346
  throw new error_1.FirebaseError(`Cannot load functions from ${functionsDir} because it has invalid runtime ${runtime}`);
348
347
  }
349
- const backend = {
350
- functionsDir,
351
- runtime,
352
- codebase: localCfg.codebase,
353
- prefix: localCfg.prefix,
354
- env: {
355
- ...options.extDevEnv,
356
- },
357
- secretEnv: [],
358
- predefinedTriggers: options.extDevTriggers,
359
- ignore: localCfg.ignore,
360
- };
361
- proto.convertIfPresent(backend, localCfg, "configDir", (cd) => path.join(projectDir, cd));
362
- emulatableBackends.push(backend);
348
+ if ((0, projectConfig_1.isKitConfig)(localCfg)) {
349
+ for (const [instanceId, configDir] of Object.entries(localCfg.instances)) {
350
+ const backend = {
351
+ functionsDir,
352
+ runtime,
353
+ codebase: instanceId,
354
+ prefix: (0, projectConfig_1.addKitPrefix)(instanceId),
355
+ configDir: path.join(projectDir, configDir),
356
+ env: {
357
+ ...options.extDevEnv,
358
+ },
359
+ secretEnv: [],
360
+ predefinedTriggers: options.extDevTriggers,
361
+ ignore: localCfg.ignore,
362
+ };
363
+ emulatableBackends.push(backend);
364
+ }
365
+ }
366
+ else {
367
+ const backend = {
368
+ functionsDir,
369
+ runtime,
370
+ codebase: localCfg.codebase,
371
+ ...(localCfg.prefix ? { prefix: localCfg.prefix } : {}),
372
+ ...(localCfg.configDir ? { configDir: path.join(projectDir, localCfg.configDir) } : {}),
373
+ env: {
374
+ ...options.extDevEnv,
375
+ },
376
+ secretEnv: [],
377
+ predefinedTriggers: options.extDevTriggers,
378
+ ignore: localCfg.ignore,
379
+ };
380
+ emulatableBackends.push(backend);
381
+ }
363
382
  }
364
383
  }
365
384
  if (extensionEmulator) {
@@ -54,36 +54,36 @@
54
54
  },
55
55
  "dataconnect": {
56
56
  "darwin": {
57
- "version": "3.4.16",
58
- "expectedSize": 32877328,
59
- "expectedChecksum": "48d472d8a9b009153d127bb0af9c0c77",
60
- "expectedChecksumSHA256": "c4764168d79977047a8891ef52a450a4843b36d6d506e35a2147abeee01d7dd0",
61
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.16",
62
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.16"
57
+ "version": "3.4.17",
58
+ "expectedSize": 32968592,
59
+ "expectedChecksum": "2658cdff6b7584aea118250a56217464",
60
+ "expectedChecksumSHA256": "43d5755fdeb51c6a66725ba45cf3355531bf3516367e54574080b17e2ab5f5b5",
61
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.17",
62
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.17"
63
63
  },
64
64
  "darwin_arm64": {
65
- "version": "3.4.16",
66
- "expectedSize": 30995666,
67
- "expectedChecksum": "71055082dbcf0a95451ac63839463a13",
68
- "expectedChecksumSHA256": "b31dc5e60046474c66033209ac93105b91195fffa0a4a50bba73fda2cbb14ba7",
69
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.16",
70
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.16"
65
+ "version": "3.4.17",
66
+ "expectedSize": 31079394,
67
+ "expectedChecksum": "fe73494081e3a0319dad298b7d05ff7c",
68
+ "expectedChecksumSHA256": "10ef4602874824ecb5ba655e016f44b856ce37374d64a03d58e7c70c75c67f83",
69
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.17",
70
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.17"
71
71
  },
72
72
  "win32": {
73
- "version": "3.4.16",
74
- "expectedSize": 32919040,
75
- "expectedChecksum": "d53acc32d9a996d99f8a8ac0abc82b04",
76
- "expectedChecksumSHA256": "962f6cbc62d39da102d49c463f225846ce64438bc95bdc28ee8f35b92b7bd6ef",
77
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.16",
78
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.16.exe"
73
+ "version": "3.4.17",
74
+ "expectedSize": 33011200,
75
+ "expectedChecksum": "8648cad58f7f2c0f9854825f4811cc03",
76
+ "expectedChecksumSHA256": "7bab1aba01d16dfbea53f476fc50b49000abe123387208dc3584c9486ac9c73a",
77
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.17",
78
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.17.exe"
79
79
  },
80
80
  "linux": {
81
- "version": "3.4.16",
82
- "expectedSize": 32030904,
83
- "expectedChecksum": "240d642c408929e609d75eeeefe22689",
84
- "expectedChecksumSHA256": "9963b3f1f011bf236a2a9908ebd7a282b79cd44405e77bdf8a566fd1c00dc4c7",
85
- "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.16",
86
- "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.16"
81
+ "version": "3.4.17",
82
+ "expectedSize": 32121016,
83
+ "expectedChecksum": "da3601940de713b05e783f40799db567",
84
+ "expectedChecksumSHA256": "9878cd2116d03fedd5085d8233563920c2fbf2b0926319aeaff21b81293b7330",
85
+ "remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.17",
86
+ "downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.17"
87
87
  }
88
88
  }
89
89
  }
@@ -78,6 +78,12 @@ exports.ALL_EXPERIMENTS = experiments({
78
78
  public: true,
79
79
  default: false,
80
80
  },
81
+ kits: {
82
+ shortDescription: "Enable Functions Kits.",
83
+ fullDescription: "Adds support for Function Kits.",
84
+ public: false,
85
+ default: false,
86
+ },
81
87
  emulatoruisnapshot: {
82
88
  shortDescription: "Load pre-release versions of the emulator UI",
83
89
  },
@@ -115,6 +121,13 @@ exports.ALL_EXPERIMENTS = experiments({
115
121
  "These commands are not meant for public consumption and may break or disappear " +
116
122
  "without a notice.",
117
123
  },
124
+ appcheckadmin: {
125
+ shortDescription: "Manage App Check enforcement from the CLI.",
126
+ fullDescription: "Enables the `firebase appcheck:services` commands for reading and changing App Check " +
127
+ "enforcement per service. These commands are in preview and may change until the " +
128
+ "surface is API council approved. The `firebase appcheck:debugtokens` commands are " +
129
+ "generally available and are not affected by this experiment.",
130
+ },
118
131
  ailogic: {
119
132
  shortDescription: "Manage Firebase AI Logic from the CLI.",
120
133
  fullDescription: "Enables the `firebase ailogic` command surface for managing Firebase AI Logic, " +
@@ -1,75 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.enableBilling = enableBilling;
4
- const clc = require("colorette");
5
- const opn = require("open");
6
- const cloudbilling = require("../gcp/cloudbilling");
7
- const error_1 = require("../error");
8
- const logger_1 = require("../logger");
9
- const extensionsHelper_1 = require("./extensionsHelper");
10
- const prompt = require("../prompt");
11
- const utils = require("../utils");
12
- const ADD_BILLING_ACCOUNT = "Add new billing account";
13
- function logBillingStatus(enabled, projectId) {
14
- if (!enabled) {
15
- throw new error_1.FirebaseError(`${extensionsHelper_1.logPrefix}: ${clc.bold(projectId)} could not be upgraded. Please add a billing account via the Firebase console before proceeding.`);
16
- }
17
- utils.logLabeledSuccess(extensionsHelper_1.logPrefix, `${clc.bold(projectId)} has successfully been upgraded.`);
18
- }
19
- async function openBillingAccount(projectId, url, open) {
20
- if (open) {
21
- try {
22
- opn(url);
23
- }
24
- catch (err) {
25
- logger_1.logger.debug("Unable to open billing URL: " + err.stack);
26
- }
27
- }
28
- await prompt.confirm({
29
- message: "Press enter when finished upgrading your project to continue setting up your extension.",
30
- default: true,
31
- });
32
- return cloudbilling.checkBillingEnabled(projectId, true);
33
- }
34
- async function chooseBillingAccount(projectId, accounts) {
35
- const choices = accounts.map((m) => m.displayName);
36
- choices.push(ADD_BILLING_ACCOUNT);
37
- const answer = await prompt.select({
38
- message: `Extensions require your project to be upgraded to the Blaze plan. You have access to the following billing accounts.
39
- Please select the one that you would like to associate with this project:`,
40
- choices: choices,
41
- });
42
- let billingEnabled;
43
- if (answer === ADD_BILLING_ACCOUNT) {
44
- const billingURL = `https://console.cloud.google.com/billing/linkedaccount?project=${projectId}`;
45
- billingEnabled = await openBillingAccount(projectId, billingURL, true);
46
- }
47
- else {
48
- const billingAccount = accounts.find((a) => a.displayName === answer);
49
- billingEnabled = await cloudbilling.setBillingAccount(projectId, billingAccount.name);
50
- }
51
- return logBillingStatus(billingEnabled, projectId);
52
- }
53
- async function setUpBillingAccount(projectId) {
54
- const billingURL = `https://console.cloud.google.com/billing/linkedaccount?project=${projectId}`;
55
- logger_1.logger.info();
56
- logger_1.logger.info(`Extension require your project to be upgraded to the Blaze plan. Please visit the following link to add a billing account:`);
57
- logger_1.logger.info();
58
- logger_1.logger.info(clc.bold(clc.underline(billingURL)));
59
- logger_1.logger.info();
60
- const open = await prompt.confirm({
61
- message: "Press enter to open the URL.",
62
- default: true,
63
- });
64
- const billingEnabled = await openBillingAccount(projectId, billingURL, open);
65
- return logBillingStatus(billingEnabled, projectId);
66
- }
67
- async function enableBilling(projectId) {
68
- const billingAccounts = await cloudbilling.listBillingAccounts(projectId);
69
- if (billingAccounts) {
70
- const accounts = billingAccounts.filter((account) => account.open);
71
- return accounts.length > 0
72
- ? chooseBillingAccount(projectId, accounts)
73
- : setUpBillingAccount(projectId);
74
- }
75
- }
3
+ exports.enableBilling = void 0;
4
+ const cloudbilling_1 = require("../gcp/cloudbilling");
5
+ Object.defineProperty(exports, "enableBilling", { enumerable: true, get: function () { return cloudbilling_1.enableBilling; } });
@@ -1,19 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_CODEBASE = void 0;
3
+ exports.KIT_PREFIX = exports.DEFAULT_CODEBASE = void 0;
4
4
  exports.normalize = normalize;
5
5
  exports.validateCodebase = validateCodebase;
6
+ exports.validateKit = validateKit;
6
7
  exports.validatePrefix = validatePrefix;
7
8
  exports.assertUnique = assertUnique;
9
+ exports.validateKitInstances = validateKitInstances;
8
10
  exports.validate = validate;
9
11
  exports.normalizeAndValidate = normalizeAndValidate;
10
12
  exports.configForCodebase = configForCodebase;
11
13
  exports.isLocalConfig = isLocalConfig;
12
14
  exports.isRemoteConfig = isRemoteConfig;
15
+ exports.isKitConfig = isKitConfig;
16
+ exports.addKitPrefix = addKitPrefix;
13
17
  exports.requireLocal = requireLocal;
14
18
  exports.resolveConfigDir = resolveConfigDir;
15
19
  exports.shouldUseRuntimeConfig = shouldUseRuntimeConfig;
16
20
  const error_1 = require("../error");
21
+ const experiments = require("../experiments");
17
22
  exports.DEFAULT_CODEBASE = "default";
18
23
  function normalize(config) {
19
24
  if (!config) {
@@ -33,6 +38,12 @@ function validateCodebase(codebase) {
33
38
  "can contain only lowercase letters, numeric characters, underscores, and dashes.");
34
39
  }
35
40
  }
41
+ function validateKit(kit) {
42
+ if (kit.length === 0 || kit.length > 40 || !/^[a-z0-9_-]+$/.test(kit)) {
43
+ throw new error_1.FirebaseError("Invalid kit name. Kit name must be 40 characters or less and " +
44
+ "can contain only lowercase letters, numeric characters, underscores, and dashes.");
45
+ }
46
+ }
36
47
  function validatePrefix(prefix) {
37
48
  if (prefix.length > 30) {
38
49
  throw new error_1.FirebaseError("Invalid prefix. Prefix must be 30 characters or less.");
@@ -42,6 +53,31 @@ function validatePrefix(prefix) {
42
53
  }
43
54
  }
44
55
  function validateSingle(config) {
56
+ if ("kit" in config) {
57
+ experiments.assertEnabled("kits", "use functions kits");
58
+ if (!config.kit) {
59
+ throw new error_1.FirebaseError("Must specify 'kit' name in a functions kit config.");
60
+ }
61
+ validateKit(config.kit);
62
+ if (config.codebase) {
63
+ throw new error_1.FirebaseError("Cannot specify both 'kit' and 'codebase' in a single functions config.");
64
+ }
65
+ if (config.remoteSource) {
66
+ throw new error_1.FirebaseError("Cannot specify both 'kit' and 'remoteSource' in a single functions config.");
67
+ }
68
+ if (config.prefix) {
69
+ throw new error_1.FirebaseError("Cannot specify 'prefix' in a functions kit config.");
70
+ }
71
+ if (!config.source) {
72
+ throw new error_1.FirebaseError("Must specify 'source' in a functions kit config.");
73
+ }
74
+ if (!config.instances ||
75
+ typeof config.instances !== "object" ||
76
+ Array.isArray(config.instances)) {
77
+ throw new error_1.FirebaseError("Must specify 'instances' as an object mapping instance IDs to configuration paths in a functions kit config.");
78
+ }
79
+ return config;
80
+ }
45
81
  const { source, remoteSource, runtime, codebase: providedCodebase, ...rest } = config;
46
82
  if (source && remoteSource) {
47
83
  throw new error_1.FirebaseError("Cannot specify both 'source' and 'remoteSource' in a single functions config. Please choose one.");
@@ -84,10 +120,12 @@ function assertUnique(config, property, propval) {
84
120
  }
85
121
  for (const single of config) {
86
122
  const value = single[property];
87
- if (values.has(value)) {
88
- throw new error_1.FirebaseError(`functions.${property} must be unique but '${value}' was used more than once.`);
123
+ if (value !== undefined) {
124
+ if (values.has(value)) {
125
+ throw new error_1.FirebaseError(`functions.${String(property)} must be unique but '${String(value)}' was used more than once.`);
126
+ }
127
+ values.add(value);
89
128
  }
90
- values.add(value);
91
129
  }
92
130
  }
93
131
  function assertUniqueSourcePrefixPair(config) {
@@ -113,38 +151,86 @@ function assertUniqueSourcePrefixPair(config) {
113
151
  sourcePrefixPairs.add(key);
114
152
  }
115
153
  }
154
+ function validateKitInstances(instances, allProjectInstanceIds) {
155
+ for (const instanceId of Object.keys(instances)) {
156
+ if (instanceId.length === 0 ||
157
+ instanceId.length > 40 ||
158
+ !/^[a-z0-9_](?:[a-z0-9_-]*[a-z0-9_])?$/.test(instanceId)) {
159
+ throw new error_1.FirebaseError(`Invalid kit instance ID '${instanceId}'. Instance ID must be 40 characters or less, ` +
160
+ "can contain only lowercase letters, numeric characters, underscores, and dashes, and cannot start or end with a dash.");
161
+ }
162
+ if (allProjectInstanceIds.has(instanceId)) {
163
+ throw new error_1.FirebaseError(`functions kit instance ID must be unique across all kits, but '${instanceId}' was used more than once.`);
164
+ }
165
+ allProjectInstanceIds.add(instanceId);
166
+ }
167
+ }
168
+ function assertUniqueKitInstancesAndCodebases(config) {
169
+ const codebases = new Set();
170
+ const instanceIds = new Set();
171
+ for (const c of config) {
172
+ if ("codebase" in c && c.codebase) {
173
+ codebases.add(c.codebase);
174
+ }
175
+ if ("instances" in c && c.instances) {
176
+ validateKitInstances(c.instances, instanceIds);
177
+ }
178
+ }
179
+ for (const instanceId of instanceIds) {
180
+ if (codebases.has(instanceId)) {
181
+ throw new error_1.FirebaseError(`functions codebase name and kit instance ID must be mutually exclusive, but '${instanceId}' was used as both a codebase name and a kit instance ID.`);
182
+ }
183
+ }
184
+ }
116
185
  function validate(config) {
117
186
  const validated = config.map((cfg) => validateSingle(cfg));
118
187
  assertUnique(validated, "codebase");
188
+ assertUnique(validated, "kit");
119
189
  assertUniqueSourcePrefixPair(validated);
190
+ assertUniqueKitInstancesAndCodebases(validated);
120
191
  return validated;
121
192
  }
122
193
  function normalizeAndValidate(config) {
123
194
  return validate(normalize(config));
124
195
  }
125
- function configForCodebase(config, codebase) {
126
- const codebaseCfg = config.find((c) => c.codebase === codebase);
196
+ function configForCodebase(config, codebaseOrInstance) {
197
+ const codebaseCfg = config.find((c) => {
198
+ if (isKitConfig(c)) {
199
+ return c.instances && codebaseOrInstance in c.instances;
200
+ }
201
+ return c.codebase === codebaseOrInstance;
202
+ });
127
203
  if (!codebaseCfg) {
128
- throw new error_1.FirebaseError(`No functions config found for codebase ${codebase}`);
204
+ throw new error_1.FirebaseError(`No functions config found for codebase or kit instance ${codebaseOrInstance}`);
129
205
  }
130
206
  return codebaseCfg;
131
207
  }
132
208
  function isLocalConfig(c) {
133
- return c.source !== undefined;
209
+ return "source" in c && !("kit" in c);
134
210
  }
135
211
  function isRemoteConfig(c) {
136
- return c.remoteSource !== undefined;
212
+ return "remoteSource" in c;
213
+ }
214
+ function isKitConfig(c) {
215
+ return "kit" in c;
216
+ }
217
+ exports.KIT_PREFIX = "kit-";
218
+ function addKitPrefix(instanceId) {
219
+ return `${exports.KIT_PREFIX}${instanceId}`;
137
220
  }
138
221
  function requireLocal(c, purpose) {
139
- if (!isLocalConfig(c)) {
222
+ if (isRemoteConfig(c)) {
140
223
  const msg = purpose ??
141
224
  "This operation requires a local functions source directory, but the codebase is configured with a remote source.";
142
225
  throw new error_1.FirebaseError(msg);
143
226
  }
144
227
  return c;
145
228
  }
146
- function resolveConfigDir(c) {
147
- return c.configDir || c.source;
229
+ function resolveConfigDir(c, instanceId) {
230
+ if (isKitConfig(c)) {
231
+ return instanceId ? c.instances[instanceId] : undefined;
232
+ }
233
+ return c.configDir || (isLocalConfig(c) ? c.source : undefined);
148
234
  }
149
235
  function shouldUseRuntimeConfig(cfg) {
150
236
  return isLocalConfig(cfg) && cfg.disallowLegacyRuntimeConfig !== true;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PROVIDER_TYPES = exports.WRITABLE_CONFIG_PATHS = exports.client = exports.AI_LOGIC_TRIGGERS_TO_EVENTS = exports.AI_LOGIC_EVENTS_TO_TRIGGER = exports.AI_LOGIC_AFTER_GENERATE_CONTENT = exports.AI_LOGIC_BEFORE_GENERATE_CONTENT = exports.GLOBAL_LOCATION = exports.AILOGIC_LOGGING_PREFIX = exports.API_VERSION = void 0;
3
+ exports.PROVIDER_TYPES = exports.WRITABLE_CONFIG_PATHS = exports.TEMPLATE_ID_REGEX = exports.client = exports.AI_LOGIC_TRIGGERS_TO_EVENTS = exports.AI_LOGIC_EVENTS_TO_TRIGGER = exports.AI_LOGIC_AFTER_GENERATE_CONTENT = exports.AI_LOGIC_BEFORE_GENERATE_CONTENT = exports.GLOBAL_LOCATION = exports.AILOGIC_LOGGING_PREFIX = exports.API_VERSION = void 0;
4
4
  exports.createTrigger = createTrigger;
5
5
  exports.getTrigger = getTrigger;
6
6
  exports.updateTrigger = updateTrigger;
@@ -8,9 +8,17 @@ exports.deleteTrigger = deleteTrigger;
8
8
  exports.listTriggers = listTriggers;
9
9
  exports.upsertBlockingFunction = upsertBlockingFunction;
10
10
  exports.deleteBlockingFunction = deleteBlockingFunction;
11
+ exports.templateIdFromName = templateIdFromName;
12
+ exports.assertValidTemplateId = assertValidTemplateId;
11
13
  exports.assertKnownConfigPath = assertKnownConfigPath;
14
+ exports.withTemplate404 = withTemplate404;
12
15
  exports.isProviderType = isProviderType;
13
16
  exports.parseProviderType = parseProviderType;
17
+ exports.getTemplate = getTemplate;
18
+ exports.updateTemplate = updateTemplate;
19
+ exports.deleteTemplate = deleteTemplate;
20
+ exports.setTemplateLocked = setTemplateLocked;
21
+ exports.listTemplates = listTemplates;
14
22
  exports.getConfig = getConfig;
15
23
  exports.updateConfig = updateConfig;
16
24
  exports.enableProvider = enableProvider;
@@ -129,6 +137,15 @@ async function deleteBlockingFunction(endpoint) {
129
137
  const location = endpoint.blockingTrigger.options?.regionalWebhook ? endpoint.region : "global";
130
138
  await deleteTrigger(endpoint.project, location, triggerId, true);
131
139
  }
140
+ function templateIdFromName(name) {
141
+ return name.split("/").pop() ?? "";
142
+ }
143
+ exports.TEMPLATE_ID_REGEX = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
144
+ function assertValidTemplateId(templateId) {
145
+ if (!exports.TEMPLATE_ID_REGEX.test(templateId)) {
146
+ throw new error_1.FirebaseError(`Invalid template id: ${(0, colorette_1.bold)(templateId)}. Template ids must start with a letter or digit and contain only letters, digits, '.', '_', and '-'.`);
147
+ }
148
+ }
132
149
  exports.WRITABLE_CONFIG_PATHS = [
133
150
  "security.auth-only",
134
151
  "security.template-only",
@@ -141,6 +158,20 @@ function assertKnownConfigPath(path, validPaths) {
141
158
  validPaths.map((p) => ` ${p}`).join("\n"));
142
159
  }
143
160
  }
161
+ function templateName(projectId, templateId) {
162
+ return `projects/${projectId}/locations/${exports.GLOBAL_LOCATION}/templates/${templateId}`;
163
+ }
164
+ async function withTemplate404(templateId, fn) {
165
+ try {
166
+ return await fn();
167
+ }
168
+ catch (err) {
169
+ if ((0, error_1.getErrStatus)(err) === 404) {
170
+ throw new error_1.FirebaseError(`Template ${(0, colorette_1.bold)(templateId)} does not exist.`);
171
+ }
172
+ throw err;
173
+ }
174
+ }
144
175
  exports.PROVIDER_TYPES = ["gemini-developer-api", "gemini-agent-platform-api"];
145
176
  function isProviderType(value) {
146
177
  return exports.PROVIDER_TYPES.some((p) => p === value);
@@ -151,6 +182,44 @@ function parseProviderType(value) {
151
182
  }
152
183
  return value;
153
184
  }
185
+ async function getTemplate(projectId, templateId) {
186
+ const res = await exports.client.get(templateName(projectId, templateId));
187
+ return res.body;
188
+ }
189
+ async function updateTemplate(projectId, templateId, template, updateMask, allowMissing = true) {
190
+ const queryParams = {
191
+ allowMissing: allowMissing ? "true" : "false",
192
+ };
193
+ if (updateMask && updateMask.length > 0) {
194
+ queryParams.updateMask = updateMask.join(",");
195
+ }
196
+ const res = await exports.client.patch(templateName(projectId, templateId), template, { queryParams });
197
+ return res.body;
198
+ }
199
+ async function deleteTemplate(projectId, templateId, etag) {
200
+ const queryParams = {};
201
+ if (etag) {
202
+ queryParams.etag = etag;
203
+ }
204
+ await exports.client.delete(templateName(projectId, templateId), { queryParams });
205
+ }
206
+ async function setTemplateLocked(projectId, templateId, locked) {
207
+ await exports.client.post(`${templateName(projectId, templateId)}:modifyLock`, { locked });
208
+ }
209
+ async function listTemplates(projectId) {
210
+ const parent = `projects/${projectId}/locations/${exports.GLOBAL_LOCATION}`;
211
+ let pageToken;
212
+ const templates = [];
213
+ do {
214
+ const queryParams = pageToken ? { pageToken } : {};
215
+ const res = await exports.client.get(`${parent}/templates`, { queryParams });
216
+ if (res.body?.templates) {
217
+ templates.push(...res.body.templates);
218
+ }
219
+ pageToken = res.body?.nextPageToken;
220
+ } while (pageToken);
221
+ return templates;
222
+ }
154
223
  async function getConfig(projectId) {
155
224
  const name = `projects/${projectId}/locations/${exports.GLOBAL_LOCATION}/config`;
156
225
  const res = await exports.client.get(name);
@@ -5,8 +5,14 @@ exports.clearCache = clearCache;
5
5
  exports.checkBillingEnabled = checkBillingEnabled;
6
6
  exports.setBillingAccount = setBillingAccount;
7
7
  exports.listBillingAccounts = listBillingAccounts;
8
+ exports.enableBilling = enableBilling;
9
+ const clc = require("colorette");
10
+ const opn = require("open");
8
11
  const api_1 = require("../api");
9
12
  const apiv2_1 = require("../apiv2");
13
+ const error_1 = require("../error");
14
+ const logger_1 = require("../logger");
15
+ const prompt = require("../prompt");
10
16
  const utils = require("../utils");
11
17
  const ensureApiEnabled_1 = require("../ensureApiEnabled");
12
18
  const API_VERSION = "v1";
@@ -69,3 +75,71 @@ async function listBillingAccounts(projectId) {
69
75
  });
70
76
  return res.body.billingAccounts || [];
71
77
  }
78
+ const ADD_BILLING_ACCOUNT = "Add new billing account";
79
+ function logBillingStatus(enabled, projectId, featureName) {
80
+ const prefix = featureName === "Extensions" ? "extensions" : featureName.toLowerCase();
81
+ if (!enabled) {
82
+ throw new error_1.FirebaseError(`${prefix}: ${clc.bold(projectId)} could not be upgraded. Please add a billing account via the Firebase console before proceeding.`);
83
+ }
84
+ utils.logLabeledSuccess(prefix, `${clc.bold(projectId)} has successfully been upgraded.`);
85
+ }
86
+ async function openBillingAccount(projectId, url, open, featureName = "Extensions") {
87
+ if (open) {
88
+ try {
89
+ opn(url);
90
+ }
91
+ catch (err) {
92
+ logger_1.logger.debug("Unable to open billing URL: " + err.stack);
93
+ }
94
+ }
95
+ const target = featureName === "Extensions" ? "your extension" : featureName.toLowerCase();
96
+ await prompt.confirm({
97
+ message: `Press enter when finished upgrading your project to continue setting up ${target}.`,
98
+ default: true,
99
+ });
100
+ return exports.checkBillingEnabled(projectId, true);
101
+ }
102
+ async function chooseBillingAccount(projectId, accounts, featureName) {
103
+ const choices = accounts.map((m) => m.displayName);
104
+ choices.push(ADD_BILLING_ACCOUNT);
105
+ const verb = featureName === "Extensions" ? "require" : "requires";
106
+ const answer = await prompt.select({
107
+ message: `${featureName} ${verb} your project to be upgraded to the Blaze plan. You have access to the following billing accounts.
108
+ Please select the one that you would like to associate with this project:`,
109
+ choices: choices,
110
+ });
111
+ let billingEnabled;
112
+ if (answer === ADD_BILLING_ACCOUNT) {
113
+ const billingURL = `https://console.cloud.google.com/billing/linkedaccount?project=${projectId}`;
114
+ billingEnabled = await openBillingAccount(projectId, billingURL, true, featureName);
115
+ }
116
+ else {
117
+ const billingAccount = accounts.find((a) => a.displayName === answer);
118
+ billingEnabled = await exports.setBillingAccount(projectId, billingAccount.name);
119
+ }
120
+ return logBillingStatus(billingEnabled, projectId, featureName);
121
+ }
122
+ async function setUpBillingAccount(projectId, featureName) {
123
+ const billingURL = `https://console.cloud.google.com/billing/linkedaccount?project=${projectId}`;
124
+ const verb = featureName === "Extensions" ? "require" : "requires";
125
+ logger_1.logger.info();
126
+ logger_1.logger.info(`${featureName} ${verb} your project to be upgraded to the Blaze plan. Please visit the following link to add a billing account:`);
127
+ logger_1.logger.info();
128
+ logger_1.logger.info(clc.bold(clc.underline(billingURL)));
129
+ logger_1.logger.info();
130
+ const open = await prompt.confirm({
131
+ message: "Press enter to open the URL.",
132
+ default: true,
133
+ });
134
+ const billingEnabled = await openBillingAccount(projectId, billingURL, open, featureName);
135
+ return logBillingStatus(billingEnabled, projectId, featureName);
136
+ }
137
+ async function enableBilling(projectId, featureName = "Extensions") {
138
+ const billingAccounts = await exports.listBillingAccounts(projectId);
139
+ if (billingAccounts) {
140
+ const accounts = billingAccounts.filter((account) => account.open);
141
+ return accounts.length > 0
142
+ ? chooseBillingAccount(projectId, accounts, featureName)
143
+ : setUpBillingAccount(projectId, featureName);
144
+ }
145
+ }