firebase-tools 15.25.1 → 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 (41) 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/services.js +135 -0
  5. package/lib/auth.js +33 -15
  6. package/lib/checkValidTargetFilters.js +1 -0
  7. package/lib/command.js +4 -1
  8. package/lib/commands/ailogic-templates-delete.js +53 -0
  9. package/lib/commands/ailogic-templates-get.js +33 -0
  10. package/lib/commands/ailogic-templates-list.js +49 -0
  11. package/lib/commands/ailogic-templates-lock.js +30 -0
  12. package/lib/commands/ailogic-templates-unlock.js +30 -0
  13. package/lib/commands/appcheck-services-get.js +40 -0
  14. package/lib/commands/appcheck-services-list.js +52 -0
  15. package/lib/commands/appcheck-services-set.js +90 -0
  16. package/lib/commands/crashlytics-onboard-web.js +56 -0
  17. package/lib/commands/deploy.js +3 -0
  18. package/lib/commands/firestore-locations.js +3 -1
  19. package/lib/commands/index.js +14 -0
  20. package/lib/commands/login.js +53 -6
  21. package/lib/config.js +1 -0
  22. package/lib/crashlytics/firebasetelemetry.js +36 -0
  23. package/lib/crashlytics/onboarding.js +41 -0
  24. package/lib/crashlytics/sourcemap.js +102 -12
  25. package/lib/deploy/ailogic/index.js +19 -0
  26. package/lib/deploy/ailogic/prepare.js +78 -0
  27. package/lib/deploy/ailogic/release.js +60 -0
  28. package/lib/deploy/index.js +9 -0
  29. package/lib/emulator/downloadableEmulatorInfo.json +24 -24
  30. package/lib/experiments.js +7 -0
  31. package/lib/extensions/checkProjectBilling.js +3 -73
  32. package/lib/gcp/ailogic.js +70 -1
  33. package/lib/gcp/cloudbilling.js +74 -0
  34. package/lib/gcp/cloudlogging.js +54 -0
  35. package/lib/management/apps.js +1 -2
  36. package/lib/prompt.js +10 -1
  37. package/lib/requirePermissions.js +1 -1
  38. package/lib/tsconfig.compile.tsbuildinfo +1 -1
  39. package/lib/tsconfig.publish.tsbuildinfo +1 -1
  40. package/package.json +1 -1
  41. package/schema/firebase-config.json +39 -0
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepare = prepare;
4
+ const clc = require("colorette");
5
+ const utils = require("../../utils");
6
+ const error_1 = require("../../error");
7
+ const prompt_1 = require("../../prompt");
8
+ const projectUtils_1 = require("../../projectUtils");
9
+ const fsutils_1 = require("../../fsutils");
10
+ const ailogic = require("../../gcp/ailogic");
11
+ const templates = require("../../ailogic/templates");
12
+ const VALID_FILTERS = ["templates"];
13
+ function filterIncludes(options, subTarget) {
14
+ if (!options.only) {
15
+ return true;
16
+ }
17
+ const filters = options.only
18
+ .split(",")
19
+ .filter((t) => t === "ailogic" || t.startsWith("ailogic:"))
20
+ .map((t) => t.split(":")[1]);
21
+ for (const f of filters) {
22
+ if (f && !VALID_FILTERS.includes(f)) {
23
+ throw new error_1.FirebaseError(`Unknown AI Logic deploy filter ${clc.bold(`ailogic:${f}`)}. Valid filters:\n\n` +
24
+ VALID_FILTERS.map((v) => ` ailogic:${v}`).join("\n"));
25
+ }
26
+ }
27
+ return filters.some((f) => f === undefined || f === subTarget);
28
+ }
29
+ async function prepare(context, options) {
30
+ if (!filterIncludes(options, "templates")) {
31
+ return;
32
+ }
33
+ const projectId = (0, projectUtils_1.needProjectId)(options);
34
+ const templatesDir = options.config.src.ailogic?.templates ?? templates.DEFAULT_PROMPTS_DIR;
35
+ const dir = options.config.path(templatesDir);
36
+ if (!(0, fsutils_1.dirExistsSync)(dir)) {
37
+ throw new error_1.FirebaseError(`AI Logic templates directory ${clc.bold(templatesDir)} (from firebase.json) does not exist.`);
38
+ }
39
+ const local = templates.readPromptDirectory(dir);
40
+ if (local.errors.length > 0) {
41
+ throw new error_1.FirebaseError(["The following prompt files failed validation:"]
42
+ .concat(local.errors.map((e) => ` ${e.file}: ${e.error}`))
43
+ .join("\n"));
44
+ }
45
+ await ailogic.ensureAILogicApiEnabled(projectId, options);
46
+ const remote = await ailogic.listTemplates(projectId);
47
+ const prune = local.templates.size > 0;
48
+ if (!prune && remote.length > 0) {
49
+ utils.logLabeledWarning("ailogic", `no ${templates.PROMPT_FILE_EXT} files found in ${clc.bold(templatesDir)}; ` +
50
+ `existing remote templates were left untouched.`);
51
+ }
52
+ const plan = templates.planTemplateDeploy(local.templates, remote, prune);
53
+ if (plan.lockedViolations.length > 0) {
54
+ throw new error_1.FirebaseError(`The following templates are locked and cannot be updated or deleted:\n\n` +
55
+ plan.lockedViolations.map((id) => ` ${id}`).join("\n") +
56
+ `\n\nUnlock them by running:\n\n firebase ailogic:templates:unlock <templateId>\n\nThen deploy again. No templates were deployed.`);
57
+ }
58
+ if (plan.unchanged.length > 0) {
59
+ utils.logLabeledBullet("ailogic", `skipping ${plan.unchanged.length} unchanged template(s): ${plan.unchanged.join(", ")}`);
60
+ }
61
+ if (plan.deletes.length > 0) {
62
+ const confirmed = await (0, prompt_1.confirm)({
63
+ message: `This will delete the following remote templates whose ${templates.PROMPT_FILE_EXT} files were removed:\n\n` +
64
+ plan.deletes.map((id) => ` ${id}`).join("\n") +
65
+ `\n\nAre you sure you want to proceed?`,
66
+ force: options.force,
67
+ nonInteractive: options.nonInteractive,
68
+ });
69
+ if (!confirmed) {
70
+ throw new error_1.FirebaseError("Command aborted.", { exit: 1 });
71
+ }
72
+ }
73
+ context.ailogic = {
74
+ templates: local.templates,
75
+ plan,
76
+ etags: new Map(remote.map((t) => [ailogic.templateIdFromName(t.name), t.etag])),
77
+ };
78
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.release = release;
4
+ const clc = require("colorette");
5
+ const utils = require("../../utils");
6
+ const error_1 = require("../../error");
7
+ const projectUtils_1 = require("../../projectUtils");
8
+ const ailogic = require("../../gcp/ailogic");
9
+ async function release(context, options) {
10
+ if (!context.ailogic) {
11
+ return;
12
+ }
13
+ const projectId = (0, projectUtils_1.needProjectId)(options);
14
+ const { templates, plan, etags } = context.ailogic;
15
+ for (const templateId of plan.creates) {
16
+ utils.logLabeledBullet("ailogic", `creating template ${clc.bold(templateId)}...`);
17
+ await ailogic.updateTemplate(projectId, templateId, {
18
+ templateString: templates.get(templateId) ?? "",
19
+ displayName: templateId,
20
+ });
21
+ }
22
+ for (const templateId of plan.updates) {
23
+ utils.logLabeledBullet("ailogic", `updating template ${clc.bold(templateId)}...`);
24
+ const etag = etags.get(templateId);
25
+ try {
26
+ await ailogic.updateTemplate(projectId, templateId, {
27
+ templateString: templates.get(templateId) ?? "",
28
+ ...(etag ? { etag } : {}),
29
+ }, ["templateString"]);
30
+ }
31
+ catch (err) {
32
+ if ((0, error_1.getErrStatus)(err) === 409) {
33
+ throw new error_1.FirebaseError(`Template ${clc.bold(templateId)} was modified while deploying. Re-run the deploy to apply your local files against the latest remote state.`);
34
+ }
35
+ throw err;
36
+ }
37
+ }
38
+ for (const templateId of plan.deletes) {
39
+ utils.logLabeledBullet("ailogic", `deleting template ${clc.bold(templateId)}...`);
40
+ try {
41
+ await ailogic.deleteTemplate(projectId, templateId, etags.get(templateId));
42
+ }
43
+ catch (err) {
44
+ if ((0, error_1.getErrStatus)(err) === 404) {
45
+ utils.logLabeledBullet("ailogic", `template ${clc.bold(templateId)} was already deleted.`);
46
+ continue;
47
+ }
48
+ if ((0, error_1.getErrStatus)(err) === 409) {
49
+ throw new error_1.FirebaseError(`Template ${clc.bold(templateId)} was modified while deploying, so it was not deleted. Re-run the deploy to plan against the latest remote state.`);
50
+ }
51
+ throw err;
52
+ }
53
+ }
54
+ if (plan.creates.length === 0 && plan.updates.length === 0 && plan.deletes.length === 0) {
55
+ utils.logLabeledSuccess("ailogic", "all templates are already up to date.");
56
+ }
57
+ else {
58
+ utils.logLabeledSuccess("ailogic", `templates deployed: ${plan.creates.length} created, ${plan.updates.length} updated, ${plan.deletes.length} deleted.`);
59
+ }
60
+ }
@@ -22,6 +22,7 @@ const ExtensionsTarget = require("./extensions");
22
22
  const DataConnectTarget = require("./dataconnect");
23
23
  const AppHostingTarget = require("./apphosting");
24
24
  const AuthTarget = require("./auth");
25
+ const AiLogicTarget = require("./ailogic");
25
26
  const frameworks_1 = require("../frameworks");
26
27
  const prepare_1 = require("./hosting/prepare");
27
28
  const requirePermissions_1 = require("../requirePermissions");
@@ -37,6 +38,7 @@ exports.VALID_DEPLOY_TARGETS = [
37
38
  "dataconnect",
38
39
  "apphosting",
39
40
  "auth",
41
+ "ailogic",
40
42
  ];
41
43
  exports.TARGET_PERMISSIONS = {
42
44
  database: ["firebasedatabase.instances.update"],
@@ -87,6 +89,12 @@ exports.TARGET_PERMISSIONS = {
87
89
  apphosting: [],
88
90
  extensions: [],
89
91
  auth: ["firebase.projects.update", "firebaseauth.configs.update"],
92
+ ailogic: [
93
+ "firebasevertexai.templates.update",
94
+ "firebasevertexai.templates.get",
95
+ "firebasevertexai.templates.delete",
96
+ "serviceusage.services.get",
97
+ ],
90
98
  };
91
99
  exports.TARGETS = {
92
100
  hosting: HostingTarget,
@@ -99,6 +107,7 @@ exports.TARGETS = {
99
107
  dataconnect: DataConnectTarget,
100
108
  apphosting: AppHostingTarget,
101
109
  auth: AuthTarget,
110
+ ailogic: AiLogicTarget,
102
111
  };
103
112
  const chain = async function (fns, context, options, payload) {
104
113
  for (const latest of fns) {
@@ -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
  }
@@ -121,6 +121,13 @@ exports.ALL_EXPERIMENTS = experiments({
121
121
  "These commands are not meant for public consumption and may break or disappear " +
122
122
  "without a notice.",
123
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
+ },
124
131
  ailogic: {
125
132
  shortDescription: "Manage Firebase AI Logic from the CLI.",
126
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,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
+ }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listEntries = listEntries;
4
+ exports.createOrUpdateLogBucket = createOrUpdateLogBucket;
5
+ exports.createOrUpdateLogSink = createOrUpdateLogSink;
4
6
  const api_1 = require("../api");
5
7
  const apiv2_1 = require("../apiv2");
6
8
  const error_1 = require("../error");
@@ -29,3 +31,55 @@ async function listEntries(projectId, filter, pageSize, order, pageToken) {
29
31
  });
30
32
  }
31
33
  }
34
+ async function createOrUpdateLogBucket(projectId, bucketId, location = "global", analyticsEnabled = true) {
35
+ const client = new apiv2_1.Client({ urlPrefix: (0, api_1.cloudloggingOrigin)(), apiVersion: API_VERSION });
36
+ const path = `/projects/${projectId}/locations/${location}/buckets`;
37
+ try {
38
+ const res = await client.post(`${path}?bucketId=${bucketId}`, { analyticsEnabled });
39
+ return res.body;
40
+ }
41
+ catch (err) {
42
+ if (err.status === 409) {
43
+ try {
44
+ const patchRes = await client.patch(`${path}/${bucketId}?updateMask=analyticsEnabled`, { analyticsEnabled });
45
+ return patchRes.body;
46
+ }
47
+ catch (patchErr) {
48
+ const msg = patchErr.message || JSON.stringify(patchErr.body) || patchErr;
49
+ throw new error_1.FirebaseError(`Failed to patch log bucket ${bucketId} (status ${patchErr.status}): ${msg}`, { original: patchErr });
50
+ }
51
+ }
52
+ const msg = err.message || JSON.stringify(err.body) || err;
53
+ if (typeof msg === "string" && msg.toLowerCase().includes("billing account")) {
54
+ throw new error_1.FirebaseError(`Creating a Cloud Logging bucket requires a valid linked billing account (Blaze plan). Please attach a billing account to project ${projectId} and try again.`, { original: err });
55
+ }
56
+ throw new error_1.FirebaseError(`Failed to create or update log bucket ${bucketId} (status ${err.status}): ${msg}`, { original: err });
57
+ }
58
+ }
59
+ async function createOrUpdateLogSink(projectId, sinkName, destination, filter) {
60
+ const client = new apiv2_1.Client({ urlPrefix: (0, api_1.cloudloggingOrigin)(), apiVersion: API_VERSION });
61
+ const path = `/projects/${projectId}/sinks`;
62
+ const body = {
63
+ name: sinkName,
64
+ destination,
65
+ filter,
66
+ };
67
+ try {
68
+ const res = await client.post(path, body);
69
+ return res.body;
70
+ }
71
+ catch (err) {
72
+ if (err.status === 409) {
73
+ try {
74
+ const putRes = await client.put(`${path}/${sinkName}`, body);
75
+ return putRes.body;
76
+ }
77
+ catch (putErr) {
78
+ const msg = putErr.message || JSON.stringify(putErr.body) || putErr;
79
+ throw new error_1.FirebaseError(`Failed to update log sink ${sinkName} (status ${putErr.status}): ${msg}`, { original: putErr });
80
+ }
81
+ }
82
+ const msg = err.message || JSON.stringify(err.body) || err;
83
+ throw new error_1.FirebaseError(`Failed to create or update log sink ${sinkName} (status ${err.status}): ${msg}`, { original: err });
84
+ }
85
+ }
@@ -547,8 +547,7 @@ async function findIntelligentPathForIOS(appDir, options) {
547
547
  return outputPath;
548
548
  }
549
549
  async function findIntelligentPathForAndroid(appDir, options) {
550
- const paths = appDir.split("/");
551
- if (paths[0] === "app") {
550
+ if (path.basename(appDir) === "app") {
552
551
  return appDir;
553
552
  }
554
553
  else {
package/lib/prompt.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Separator = void 0;
4
+ exports.setNonInteractive = setNonInteractive;
5
+ exports.isNonInteractive = isNonInteractive;
4
6
  exports.guard = guard;
5
7
  exports.input = input;
6
8
  exports.confirm = confirm;
@@ -13,8 +15,15 @@ const inquirer = require("@inquirer/prompts");
13
15
  const error_1 = require("./error");
14
16
  var prompts_1 = require("@inquirer/prompts");
15
17
  Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return prompts_1.Separator; } });
18
+ let globalNonInteractive = false;
19
+ function setNonInteractive(value) {
20
+ globalNonInteractive = value;
21
+ }
22
+ function isNonInteractive() {
23
+ return globalNonInteractive;
24
+ }
16
25
  function guard(opts) {
17
- if (!opts.nonInteractive) {
26
+ if (!opts.nonInteractive && !isNonInteractive()) {
18
27
  return { shouldReturn: false, value: undefined };
19
28
  }
20
29
  if (typeof opts.default !== "undefined") {
@@ -9,12 +9,12 @@ const error_1 = require("./error");
9
9
  const iam_1 = require("./gcp/iam");
10
10
  const BASE_PERMISSIONS = ["firebase.projects.get"];
11
11
  async function requirePermissions(options, permissions = []) {
12
+ await (0, requireAuth_1.requireAuth)(options);
12
13
  const projectId = (0, projectUtils_1.getProjectId)(options);
13
14
  if (!projectId) {
14
15
  return;
15
16
  }
16
17
  const requiredPermissions = BASE_PERMISSIONS.concat(permissions).sort();
17
- await (0, requireAuth_1.requireAuth)(options);
18
18
  logger_1.logger.debug(`[iam] checking project ${projectId} for permissions ${JSON.stringify(requiredPermissions)}`);
19
19
  try {
20
20
  const iamResult = await (0, iam_1.testIamPermissions)(projectId, requiredPermissions);