firebase-tools 15.34.2 → 15.36.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.
- package/lib/api.js +2 -4
- package/lib/appcheck/debugTokens.js +293 -0
- package/lib/appcheck/localConfig.js +191 -0
- package/lib/appdistribution/options-parser-util.js +1 -1
- package/lib/apphosting/constants.js +1 -4
- package/lib/apphosting/githubConnections.js +1 -1
- package/lib/apphosting/utils.js +0 -26
- package/lib/auth.js +8 -2
- package/lib/commands/appcheck-debugtokens-create.js +60 -35
- package/lib/commands/appcheck-debugtokens-delete.js +21 -7
- package/lib/commands/appcheck-debugtokens-list.js +37 -8
- package/lib/commands/appcheck-debugtokens-prune.js +59 -0
- package/lib/commands/crashlytics-heapdumps-status.js +1 -1
- package/lib/commands/{crashlytics-onboard-web.js → crashlytics-setup.js} +5 -5
- package/lib/commands/crashlytics-sourcemap-upload.js +4 -0
- package/lib/commands/deploy.js +1 -3
- package/lib/commands/emulators-start.js +2 -2
- package/lib/commands/hosting-channel-create.js +1 -3
- package/lib/commands/hosting-channel-delete.js +1 -3
- package/lib/commands/hosting-channel-deploy.js +1 -3
- package/lib/commands/hosting-channel-list.js +1 -3
- package/lib/commands/hosting-channel-open.js +1 -3
- package/lib/commands/hosting-clone.js +3 -5
- package/lib/commands/hosting-disable.js +2 -2
- package/lib/commands/hosting-sites-create.js +1 -3
- package/lib/commands/hosting-sites-delete.js +1 -3
- package/lib/commands/hosting-sites-get.js +1 -3
- package/lib/commands/hosting-sites-list.js +1 -3
- package/lib/commands/index.js +4 -2
- package/lib/commands/run-services-get.js +19 -0
- package/lib/commands/run-services-list.js +11 -0
- package/lib/crashlytics/alerts.js +1 -0
- package/lib/crashlytics/events.js +122 -1
- package/lib/crashlytics/filters.js +12 -6
- package/lib/crashlytics/firebasetelemetry.js +5 -3
- package/lib/crashlytics/onboarding.js +8 -7
- package/lib/crashlytics/profilingManager.js +14 -34
- package/lib/crashlytics/reports.js +46 -17
- package/lib/crashlytics/sourcemap.js +19 -5
- package/lib/crashlytics/utils.js +14 -0
- package/lib/database/import.js +5 -4
- package/lib/dataconnect/dataplaneClient.js +0 -10
- package/lib/dataconnect/names.js +3 -3
- package/lib/dataconnect/schemaMigration.js +1 -1
- package/lib/deploy/apphosting/deploy.js +20 -41
- package/lib/deploy/apphosting/localBuild.js +49 -0
- package/lib/deploy/apphosting/prepare.js +12 -25
- package/lib/deploy/apphosting/release.js +1 -1
- package/lib/deploy/apphosting/util.js +27 -4
- package/lib/deploy/functions/backend.js +0 -10
- package/lib/deploy/functions/cel.js +1 -1
- package/lib/deploy/functions/containerCleaner.js +1 -142
- package/lib/deploy/functions/functionsDeployHelper.js +0 -4
- package/lib/deploy/functions/release/reporter.js +0 -26
- package/lib/deploy/functions/runtimes/discovery/index.js +4 -1
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +1 -1
- package/lib/deploy/functions/services/index.js +13 -11
- package/lib/deploy/functions/validate.js +1 -1
- package/lib/deploy/hosting/prepare.js +1 -3
- package/lib/deploy/lifecycleHooks.js +1 -1
- package/lib/deploy/run/deploy.js +26 -43
- package/lib/deploy/run/get.js +30 -0
- package/lib/deploy/run/list.js +38 -0
- package/lib/deploy/run/prereqs.js +0 -3
- package/lib/deploy/run/util.js +9 -0
- package/lib/emulator/auth/operations.js +2 -2
- package/lib/emulator/auth/server.js +4 -2
- package/lib/emulator/auth/widget_ui.js +1 -1
- package/lib/emulator/commandUtils.js +109 -24
- package/lib/emulator/databaseEmulator.js +16 -11
- package/lib/emulator/dataconnect/pgliteServer.js +31 -24
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/downloadableEmulators.js +45 -7
- package/lib/emulator/extensions/postinstall.js +6 -6
- package/lib/emulator/firestoreEmulator.js +21 -15
- package/lib/emulator/functionsEmulator.js +11 -7
- package/lib/emulator/functionsEmulatorRuntime.js +7 -2
- package/lib/emulator/hub.js +12 -8
- package/lib/emulator/shared/express.js +30 -0
- package/lib/emulator/storage/apis/firebase.js +11 -10
- package/lib/emulator/storage/apis/gcloud.js +21 -20
- package/lib/emulator/storage/files.js +1 -1
- package/lib/emulator/storage/rules/manager.js +15 -12
- package/lib/emulator/storage/rules/runtime.js +1 -0
- package/lib/emulator/storage/server.js +10 -5
- package/lib/extensions/extensionsApi.js +0 -8
- package/lib/extensions/extensionsHelper.js +3 -24
- package/lib/extensions/paramHelper.js +1 -1
- package/lib/extensions/provisioningHelper.js +1 -6
- package/lib/extensions/secretsUtils.js +0 -24
- package/lib/firestore/util.js +3 -3
- package/lib/frameworks/angular/utils.js +1 -1
- package/lib/frameworks/next/utils.js +1 -12
- package/lib/fsAsync.js +34 -20
- package/lib/functions/kits/install.js +233 -628
- package/lib/functions/kits/sources/directory.js +91 -0
- package/lib/functions/kits/sources/npm.js +324 -0
- package/lib/functions/kits/sources/types.js +12 -0
- package/lib/functionsConfig.js +0 -4
- package/lib/functionsShellCommandAction.js +1 -1
- package/lib/gcp/artifactregistry.js +0 -5
- package/lib/gcp/cloudfunctionsv2.js +0 -6
- package/lib/gcp/devConnect.js +2 -2
- package/lib/gcp/iam.js +0 -4
- package/lib/gcp/pubsub.js +0 -14
- package/lib/gcp/storage.js +2 -1
- package/lib/hosting/api.js +79 -0
- package/lib/hosting/proxy.js +4 -1
- package/lib/init/features/hosting/github.js +6 -4
- package/lib/init/features/hosting/index.js +4 -0
- package/lib/init/features/run.js +3 -7
- package/lib/mcp/apps/init/mcp-app.js +4 -1
- package/lib/mcp/index.js +8 -2
- package/lib/mcp/prompts/apptesting/run_test.js +3 -3
- package/lib/mcp/prompts/core/deploy.js +3 -3
- package/lib/mcp/resources/guides/crashlytics_reports.js +33 -71
- package/lib/mcp/resources/guides/init_ai.js +10 -10
- package/lib/mcp/tools/crashlytics/events.js +18 -93
- package/lib/mcp/tools/crashlytics/index.js +2 -0
- package/lib/mcp/tools/crashlytics/reports.js +26 -31
- package/lib/mcp/tools/crashlytics/setup.js +392 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/utils.js +4 -10
- package/package.json +1 -2
- package/lib/deploy/hosting/args.js +0 -2
package/lib/api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rulesOrigin = exports.resourceManagerOrigin = exports.firebaseTelemetryAdminOrigin = exports.crashlyticsApiOrigin = exports.messagingApiOrigin = exports.remoteConfigApiOrigin = exports.rtdbMetadataOrigin = exports.rtdbManagementOrigin = exports.realtimeOrigin = exports.extensionsTOSOrigin = exports.extensionsPublisherOrigin = exports.extensionsOrigin = exports.iamOrigin = exports.identityOrigin = exports.hostingOrigin = exports.googleOrigin = exports.pubsubOrigin = exports.cloudTasksOrigin = exports.cloudschedulerOrigin = exports.cloudbuildOrigin = exports.functionsDefaultRegion = exports.runOrigin = exports.functionsV2Origin = exports.functionsOrigin = exports.firestoreOrigin = exports.firestoreOriginOrEmulator = exports.firedataOrigin = exports.
|
|
4
|
-
exports.developerKnowledgeOrigin = exports.cloudTestingOrigin = exports.appTestingOrigin = exports.aiLogicProxyOrigin = exports.vertexAIOrigin = exports.cloudSQLAdminOrigin = exports.dataConnectLocalConnString = exports.dataconnectP4SADomain = exports.dataconnectOrigin = exports.githubClientSecret = exports.githubClientId = exports.computeOrigin = exports.secretManagerOrigin = exports.githubApiOrigin = exports.githubOrigin = exports.studioApiOrigin = exports.serviceUsageOrigin = exports.cloudRunApiOrigin = exports.hostingApiOrigin = exports.firebaseStorageOrigin = exports.storageOrigin =
|
|
3
|
+
exports.runtimeconfigOrigin = exports.rulesOrigin = exports.resourceManagerOrigin = exports.firebaseTelemetryAdminOrigin = exports.crashlyticsApiOrigin = exports.messagingApiOrigin = exports.remoteConfigApiOrigin = exports.rtdbMetadataOrigin = exports.rtdbManagementOrigin = exports.realtimeOrigin = exports.extensionsTOSOrigin = exports.extensionsPublisherOrigin = exports.extensionsOrigin = exports.iamOrigin = exports.identityOrigin = exports.hostingOrigin = exports.googleOrigin = exports.pubsubOrigin = exports.cloudTasksOrigin = exports.cloudschedulerOrigin = exports.cloudbuildOrigin = exports.functionsDefaultRegion = exports.runOrigin = exports.functionsV2Origin = exports.functionsOrigin = exports.firestoreOrigin = exports.firestoreOriginOrEmulator = exports.firedataOrigin = exports.firebaseApiOrigin = exports.eventarcOrigin = exports.consoleOrigin = exports.authManagementOrigin = exports.authOrigin = exports.apphostingGitHubAppInstallationURL = exports.apphostingP4SADomain = exports.apphostingOrigin = exports.appDistributionOrigin = exports.appCheckOrigin = exports.apiKeysOrigin = exports.artifactRegistryDomain = exports.developerConnectP4SADomain = exports.developerConnectOrigin = exports.containerRegistryDomain = exports.cloudTraceOrigin = exports.cloudMonitoringOrigin = exports.cloudloggingOrigin = exports.cloudbillingOrigin = exports.clientSecret = exports.clientId = exports.authProxyOrigin = void 0;
|
|
4
|
+
exports.developerKnowledgeOrigin = exports.cloudTestingOrigin = exports.appTestingOrigin = exports.aiLogicProxyOrigin = exports.vertexAIOrigin = exports.cloudSQLAdminOrigin = exports.dataConnectLocalConnString = exports.dataconnectP4SADomain = exports.dataconnectOrigin = exports.githubClientSecret = exports.githubClientId = exports.computeOrigin = exports.secretManagerOrigin = exports.githubApiOrigin = exports.githubOrigin = exports.studioApiOrigin = exports.serviceUsageOrigin = exports.cloudRunApiOrigin = exports.hostingApiOrigin = exports.firebaseStorageOrigin = exports.storageOrigin = void 0;
|
|
5
5
|
exports.getScopes = getScopes;
|
|
6
6
|
exports.setScopes = setScopes;
|
|
7
7
|
const constants_1 = require("./emulator/constants");
|
|
@@ -53,8 +53,6 @@ const eventarcOrigin = () => utils.envOverride("EVENTARC_URL", "https://eventarc
|
|
|
53
53
|
exports.eventarcOrigin = eventarcOrigin;
|
|
54
54
|
const firebaseApiOrigin = () => utils.envOverride("FIREBASE_API_URL", "https://firebase.googleapis.com");
|
|
55
55
|
exports.firebaseApiOrigin = firebaseApiOrigin;
|
|
56
|
-
const firebaseExtensionsRegistryOrigin = () => utils.envOverride("FIREBASE_EXT_REGISTRY_ORIGIN", "https://extensions-registry.firebaseapp.com");
|
|
57
|
-
exports.firebaseExtensionsRegistryOrigin = firebaseExtensionsRegistryOrigin;
|
|
58
56
|
const firedataOrigin = () => utils.envOverride("FIREBASE_FIREDATA_URL", "https://mobilesdk-pa.googleapis.com");
|
|
59
57
|
exports.firedataOrigin = firedataOrigin;
|
|
60
58
|
const firestoreOriginOrEmulator = () => utils.envOverride(constants_1.Constants.FIRESTORE_EMULATOR_HOST, utils.envOverride("FIRESTORE_URL", "https://firestore.googleapis.com"), (val) => {
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDebugTokenValidationError = getDebugTokenValidationError;
|
|
4
|
+
exports.validateDebugTokenUuid = validateDebugTokenUuid;
|
|
5
|
+
exports.getDisplayNameValidationError = getDisplayNameValidationError;
|
|
6
|
+
exports.validateDisplayName = validateDisplayName;
|
|
7
|
+
exports.getDefaultDisplayName = getDefaultDisplayName;
|
|
8
|
+
exports.isWebAppId = isWebAppId;
|
|
9
|
+
exports.formatLocalTokenStatus = formatLocalTokenStatus;
|
|
10
|
+
exports.ensureCanCreateOrOverwriteDebugToken = ensureCanCreateOrOverwriteDebugToken;
|
|
11
|
+
exports.provisionDebugToken = provisionDebugToken;
|
|
12
|
+
exports.inspectLocalDebugTokens = inspectLocalDebugTokens;
|
|
13
|
+
exports.findStaleLocalDebugTokens = findStaleLocalDebugTokens;
|
|
14
|
+
exports.deleteDebugTokenAndCleanLocal = deleteDebugTokenAndCleanLocal;
|
|
15
|
+
const clc = require("colorette");
|
|
16
|
+
const os = require("os");
|
|
17
|
+
const error_1 = require("../error");
|
|
18
|
+
const logger_1 = require("../logger");
|
|
19
|
+
const apps_1 = require("../management/apps");
|
|
20
|
+
const projectUtils_1 = require("../projectUtils");
|
|
21
|
+
const requireAuth_1 = require("../requireAuth");
|
|
22
|
+
const utils_1 = require("../utils");
|
|
23
|
+
const api_1 = require("./api");
|
|
24
|
+
const localConfig_1 = require("./localConfig");
|
|
25
|
+
const MAX_DEBUG_TOKENS_PER_APP = 20;
|
|
26
|
+
const MAX_DISPLAY_NAME_LENGTH = 50;
|
|
27
|
+
const MASK_PREFIX_LENGTH = 8;
|
|
28
|
+
const UUID_V4_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
29
|
+
const GMP_APP_ID_PROJECT_NUMBER_REGEX = /^\d+:(\d+):/;
|
|
30
|
+
function extractProjectNumberFromAppId(appId) {
|
|
31
|
+
const match = GMP_APP_ID_PROJECT_NUMBER_REGEX.exec(appId);
|
|
32
|
+
return match ? match[1] : undefined;
|
|
33
|
+
}
|
|
34
|
+
function maskDebugToken(token) {
|
|
35
|
+
if (token.length <= MASK_PREFIX_LENGTH) {
|
|
36
|
+
return "********";
|
|
37
|
+
}
|
|
38
|
+
const prefix = token.slice(0, MASK_PREFIX_LENGTH);
|
|
39
|
+
return token[MASK_PREFIX_LENGTH] === "-" ? `${prefix}-...` : `${prefix}...`;
|
|
40
|
+
}
|
|
41
|
+
async function deleteServerTokensIgnoringNotFound(tokens) {
|
|
42
|
+
for (const existing of tokens) {
|
|
43
|
+
try {
|
|
44
|
+
await (0, api_1.deleteDebugToken)(existing.name);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if ((0, error_1.getErrStatus)(err) !== 404) {
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function checkAppServerTokenStatus(projectNumber, appId, recordedResourceName) {
|
|
54
|
+
let serverTokens;
|
|
55
|
+
try {
|
|
56
|
+
serverTokens = await (0, api_1.listDebugTokens)(projectNumber, appId);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
const status = (0, error_1.getErrStatus)(err);
|
|
60
|
+
if (status === 404 || status === 409) {
|
|
61
|
+
return "APP_DELETED";
|
|
62
|
+
}
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
if (serverTokens.length === 0) {
|
|
66
|
+
return "REVOKED";
|
|
67
|
+
}
|
|
68
|
+
if (recordedResourceName) {
|
|
69
|
+
return serverTokens.some((t) => t.name === recordedResourceName) ? "ACTIVE" : "REVOKED";
|
|
70
|
+
}
|
|
71
|
+
return "UNCHECKED";
|
|
72
|
+
}
|
|
73
|
+
async function resolveProjectTokenStatuses(params) {
|
|
74
|
+
const { projectId, projectNumber, candidateAppIds, tokenNames } = params;
|
|
75
|
+
const statuses = {};
|
|
76
|
+
if (candidateAppIds.length === 0) {
|
|
77
|
+
return statuses;
|
|
78
|
+
}
|
|
79
|
+
const apps = await (0, apps_1.listFirebaseApps)(projectId, apps_1.AppPlatform.ANY);
|
|
80
|
+
const activeProjectAppIds = new Set(apps.map((app) => app.appId));
|
|
81
|
+
await Promise.all(candidateAppIds.map(async (appId) => {
|
|
82
|
+
if (!activeProjectAppIds.has(appId)) {
|
|
83
|
+
statuses[appId] = "APP_DELETED";
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
statuses[appId] = await checkAppServerTokenStatus(projectNumber, appId, tokenNames[appId]);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
logger_1.logger.debug(`Failed to check server token status for app ${appId}: ${(0, error_1.getErrMsg)(err)}`);
|
|
91
|
+
statuses[appId] = "UNCHECKED";
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
return statuses;
|
|
95
|
+
}
|
|
96
|
+
function buildLocalTokenEntry(params) {
|
|
97
|
+
const { appId, token, status, resourceName } = params;
|
|
98
|
+
const entry = {
|
|
99
|
+
appId,
|
|
100
|
+
tokenPrefix: maskDebugToken(token),
|
|
101
|
+
status,
|
|
102
|
+
};
|
|
103
|
+
if (resourceName) {
|
|
104
|
+
entry.name = resourceName;
|
|
105
|
+
}
|
|
106
|
+
return entry;
|
|
107
|
+
}
|
|
108
|
+
function getDebugTokenValidationError(raw) {
|
|
109
|
+
const trimmed = raw.trim();
|
|
110
|
+
if (!trimmed) {
|
|
111
|
+
return "Debug token cannot be empty.";
|
|
112
|
+
}
|
|
113
|
+
if (!UUID_V4_REGEX.test(trimmed)) {
|
|
114
|
+
return (`Invalid debug token "${trimmed}". Expected a UUID v4 string ` +
|
|
115
|
+
`(for example, xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx). To specify a Firebase App ID, pass --app <appId>.`);
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
function validateDebugTokenUuid(raw) {
|
|
120
|
+
const error = getDebugTokenValidationError(raw);
|
|
121
|
+
if (error) {
|
|
122
|
+
throw new error_1.FirebaseError(error, { exit: 1 });
|
|
123
|
+
}
|
|
124
|
+
return raw.trim();
|
|
125
|
+
}
|
|
126
|
+
function getDisplayNameValidationError(raw) {
|
|
127
|
+
const trimmed = raw.trim();
|
|
128
|
+
if (!trimmed) {
|
|
129
|
+
return "Display name cannot be empty.";
|
|
130
|
+
}
|
|
131
|
+
if (trimmed.length > MAX_DISPLAY_NAME_LENGTH) {
|
|
132
|
+
return (`Display name "${trimmed}" exceeds the maximum length of ${MAX_DISPLAY_NAME_LENGTH} characters ` +
|
|
133
|
+
`(got ${trimmed.length}). Pass a shorter --display-name.`);
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
function validateDisplayName(raw) {
|
|
138
|
+
const error = getDisplayNameValidationError(raw);
|
|
139
|
+
if (error) {
|
|
140
|
+
throw new error_1.FirebaseError(error, { exit: 1 });
|
|
141
|
+
}
|
|
142
|
+
return raw.trim();
|
|
143
|
+
}
|
|
144
|
+
function getDefaultDisplayName(saveLocal = true) {
|
|
145
|
+
const fullHost = os.hostname() || "unknown-host";
|
|
146
|
+
const shortHost = fullHost.split(".")[0] || fullHost;
|
|
147
|
+
if (!saveLocal) {
|
|
148
|
+
return `CLI Debug Token (${shortHost})`.slice(0, MAX_DISPLAY_NAME_LENGTH);
|
|
149
|
+
}
|
|
150
|
+
let username = "user";
|
|
151
|
+
try {
|
|
152
|
+
const info = os.userInfo();
|
|
153
|
+
if (info.username) {
|
|
154
|
+
username = info.username;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
}
|
|
159
|
+
const fullCandidate = `${username}@${fullHost}`;
|
|
160
|
+
if (fullCandidate.length <= MAX_DISPLAY_NAME_LENGTH) {
|
|
161
|
+
return fullCandidate;
|
|
162
|
+
}
|
|
163
|
+
return `${username}@${shortHost}`.slice(0, MAX_DISPLAY_NAME_LENGTH);
|
|
164
|
+
}
|
|
165
|
+
function isWebAppId(appId) {
|
|
166
|
+
return appId.toLowerCase().includes(":web:");
|
|
167
|
+
}
|
|
168
|
+
function formatLocalTokenStatus(status) {
|
|
169
|
+
switch (status) {
|
|
170
|
+
case "ACTIVE":
|
|
171
|
+
return clc.green("Active");
|
|
172
|
+
case "REVOKED":
|
|
173
|
+
return clc.yellow("Revoked");
|
|
174
|
+
case "APP_DELETED":
|
|
175
|
+
return clc.red("App Deleted");
|
|
176
|
+
case "UNCHECKED":
|
|
177
|
+
return clc.gray("Unchecked");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function ensureCanCreateOrOverwriteDebugToken(params) {
|
|
181
|
+
const { appId, existingTokens, matchingTokens } = params;
|
|
182
|
+
if (matchingTokens.length === 0 && existingTokens.length >= MAX_DEBUG_TOKENS_PER_APP) {
|
|
183
|
+
throw new error_1.FirebaseError(`App ${appId} already has the maximum of ${MAX_DEBUG_TOKENS_PER_APP} debug tokens. ` +
|
|
184
|
+
`View existing tokens with "firebase appcheck:debugtokens:list --app ${appId}" and ` +
|
|
185
|
+
`revoke unused tokens with "firebase appcheck:debugtokens:delete <debugTokenId>".`, { exit: 1 });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async function provisionDebugToken(params) {
|
|
189
|
+
const { projectNumber, appId, displayName, token, existingTokens, matchingTokens, saveLocal } = params;
|
|
190
|
+
ensureCanCreateOrOverwriteDebugToken({ appId, existingTokens, matchingTokens });
|
|
191
|
+
const mustDeleteBeforeCreate = matchingTokens.length > 0 && existingTokens.length >= MAX_DEBUG_TOKENS_PER_APP;
|
|
192
|
+
if (mustDeleteBeforeCreate) {
|
|
193
|
+
await deleteServerTokensIgnoringNotFound(matchingTokens);
|
|
194
|
+
}
|
|
195
|
+
const created = await (0, api_1.createDebugToken)(projectNumber, appId, displayName, token);
|
|
196
|
+
if (matchingTokens.length > 0 && !mustDeleteBeforeCreate) {
|
|
197
|
+
await deleteServerTokensIgnoringNotFound(matchingTokens);
|
|
198
|
+
}
|
|
199
|
+
const finalToken = created.token || token;
|
|
200
|
+
const hydrated = {
|
|
201
|
+
...created,
|
|
202
|
+
token: finalToken,
|
|
203
|
+
};
|
|
204
|
+
if (saveLocal) {
|
|
205
|
+
(0, localConfig_1.saveLocalToken)(appId, finalToken, hydrated.name);
|
|
206
|
+
}
|
|
207
|
+
return hydrated;
|
|
208
|
+
}
|
|
209
|
+
async function inspectLocalDebugTokens(options) {
|
|
210
|
+
let tokens;
|
|
211
|
+
if (options.app) {
|
|
212
|
+
const single = (0, localConfig_1.getLocalToken)(options.app);
|
|
213
|
+
tokens = single ? { [options.app]: single } : {};
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
tokens = (0, localConfig_1.getAllLocalTokens)();
|
|
217
|
+
}
|
|
218
|
+
const appIds = Object.keys(tokens);
|
|
219
|
+
if (appIds.length === 0) {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
const tokenNames = (0, localConfig_1.getAllLocalTokenNames)();
|
|
223
|
+
const statusByAppId = {};
|
|
224
|
+
for (const appId of appIds) {
|
|
225
|
+
statusByAppId[appId] = "UNCHECKED";
|
|
226
|
+
}
|
|
227
|
+
if ((0, projectUtils_1.getProjectId)(options) || options.projectNumber) {
|
|
228
|
+
try {
|
|
229
|
+
await (0, requireAuth_1.requireAuth)(options);
|
|
230
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
231
|
+
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
232
|
+
const candidateAppIds = appIds.filter((appId) => extractProjectNumberFromAppId(appId) === projectNumber);
|
|
233
|
+
const resolvedStatuses = await resolveProjectTokenStatuses({
|
|
234
|
+
projectId,
|
|
235
|
+
projectNumber,
|
|
236
|
+
candidateAppIds,
|
|
237
|
+
tokenNames,
|
|
238
|
+
});
|
|
239
|
+
Object.assign(statusByAppId, resolvedStatuses);
|
|
240
|
+
}
|
|
241
|
+
catch (err) {
|
|
242
|
+
logger_1.logger.debug(`Skipping server status check for local App Check debug tokens: ${(0, error_1.getErrMsg)(err)}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return appIds.map((appId) => buildLocalTokenEntry({
|
|
246
|
+
appId,
|
|
247
|
+
token: tokens[appId],
|
|
248
|
+
status: statusByAppId[appId],
|
|
249
|
+
resourceName: tokenNames[appId],
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
async function findStaleLocalDebugTokens(params) {
|
|
253
|
+
const { projectId, projectNumber } = params;
|
|
254
|
+
const tokens = (0, localConfig_1.getAllLocalTokens)();
|
|
255
|
+
const candidateAppIds = Object.keys(tokens).filter((appId) => extractProjectNumberFromAppId(appId) === projectNumber);
|
|
256
|
+
if (candidateAppIds.length === 0) {
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
const tokenNames = (0, localConfig_1.getAllLocalTokenNames)();
|
|
260
|
+
const statuses = await resolveProjectTokenStatuses({
|
|
261
|
+
projectId,
|
|
262
|
+
projectNumber,
|
|
263
|
+
candidateAppIds,
|
|
264
|
+
tokenNames,
|
|
265
|
+
});
|
|
266
|
+
const stale = [];
|
|
267
|
+
for (const appId of candidateAppIds) {
|
|
268
|
+
const status = statuses[appId];
|
|
269
|
+
if (status === "APP_DELETED" || status === "REVOKED") {
|
|
270
|
+
stale.push(buildLocalTokenEntry({
|
|
271
|
+
appId,
|
|
272
|
+
token: tokens[appId],
|
|
273
|
+
status,
|
|
274
|
+
resourceName: tokenNames[appId],
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return stale;
|
|
279
|
+
}
|
|
280
|
+
async function deleteDebugTokenAndCleanLocal(params) {
|
|
281
|
+
const { appId, debugTokenName } = params;
|
|
282
|
+
await (0, api_1.deleteDebugToken)(debugTokenName);
|
|
283
|
+
try {
|
|
284
|
+
if ((0, localConfig_1.getLocalTokenName)(appId) === debugTokenName) {
|
|
285
|
+
(0, localConfig_1.removeLocalTokens)([appId]);
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
(0, utils_1.logWarning)(`Deleted server debug token, but failed to clean up local App Check config: ${(0, error_1.getErrMsg)(err)}`);
|
|
291
|
+
}
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLocalConfigPath = getLocalConfigPath;
|
|
4
|
+
exports.getAllLocalTokens = getAllLocalTokens;
|
|
5
|
+
exports.getAllLocalTokenNames = getAllLocalTokenNames;
|
|
6
|
+
exports.getLocalToken = getLocalToken;
|
|
7
|
+
exports.getLocalTokenName = getLocalTokenName;
|
|
8
|
+
exports.saveLocalToken = saveLocalToken;
|
|
9
|
+
exports.removeLocalTokens = removeLocalTokens;
|
|
10
|
+
const Configstore = require("configstore");
|
|
11
|
+
const fs = require("fs");
|
|
12
|
+
const os = require("os");
|
|
13
|
+
const path = require("path");
|
|
14
|
+
const error_1 = require("../error");
|
|
15
|
+
const CONFIGSTORE_ID = "firebase-appcheck";
|
|
16
|
+
const WARNING_COMMENT = "This file contains secrets and should not be committed to source repositories";
|
|
17
|
+
const FORBIDDEN_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
18
|
+
const MANAGED_TOP_LEVEL_KEYS = new Set(["_comment", "tokens", "tokenNames"]);
|
|
19
|
+
function getCanonicalConfigDir() {
|
|
20
|
+
return path.join(os.homedir(), ".config");
|
|
21
|
+
}
|
|
22
|
+
function areSameDirectory(dirA, dirB) {
|
|
23
|
+
const resolvedA = path.resolve(dirA);
|
|
24
|
+
const resolvedB = path.resolve(dirB);
|
|
25
|
+
const caseInsensitive = process.platform === "win32" || process.platform === "darwin";
|
|
26
|
+
if (caseInsensitive ? resolvedA.toLowerCase() === resolvedB.toLowerCase() : resolvedA === resolvedB) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
if (fs.existsSync(resolvedA) && fs.existsSync(resolvedB)) {
|
|
31
|
+
return fs.realpathSync(resolvedA) === fs.realpathSync(resolvedB);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
function getConfigStorePaths() {
|
|
39
|
+
const canonicalDir = getCanonicalConfigDir();
|
|
40
|
+
const canonicalPath = path.join(canonicalDir, "configstore", `${CONFIGSTORE_ID}.json`);
|
|
41
|
+
const xdgConfigHome = process.env.XDG_CONFIG_HOME?.trim();
|
|
42
|
+
if (xdgConfigHome &&
|
|
43
|
+
path.isAbsolute(xdgConfigHome) &&
|
|
44
|
+
!areSameDirectory(xdgConfigHome, canonicalDir)) {
|
|
45
|
+
const xdgPath = path.join(xdgConfigHome, "configstore", `${CONFIGSTORE_ID}.json`);
|
|
46
|
+
return [canonicalPath, xdgPath];
|
|
47
|
+
}
|
|
48
|
+
return [canonicalPath];
|
|
49
|
+
}
|
|
50
|
+
function extractStringRecord(raw) {
|
|
51
|
+
if (!(0, error_1.isObject)(raw) || Array.isArray(raw)) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
const result = {};
|
|
55
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
56
|
+
if (FORBIDDEN_KEYS.has(key)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (typeof value === "string" && value.length > 0) {
|
|
60
|
+
result[key] = value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
function readConfigFile(configPath) {
|
|
66
|
+
let content;
|
|
67
|
+
try {
|
|
68
|
+
content = fs.readFileSync(configPath, "utf8");
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
if (err?.code === "ENOENT") {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
throw new error_1.FirebaseError(`Failed to read local App Check config at ${configPath}: ${(0, error_1.getErrMsg)(err)}`, { exit: 1, original: err instanceof Error ? err : undefined });
|
|
75
|
+
}
|
|
76
|
+
if (!content.trim()) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
let parsed;
|
|
80
|
+
try {
|
|
81
|
+
parsed = JSON.parse(content);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
throw new error_1.FirebaseError(`Failed to parse local App Check config at ${configPath}: ${(0, error_1.getErrMsg)(err)}. Fix or delete the file and try again.`, { exit: 1, original: err instanceof Error ? err : undefined });
|
|
85
|
+
}
|
|
86
|
+
if (!(0, error_1.isObject)(parsed) || Array.isArray(parsed)) {
|
|
87
|
+
throw new error_1.FirebaseError(`Invalid local App Check config at ${configPath}: expected a top-level JSON object.`, { exit: 1 });
|
|
88
|
+
}
|
|
89
|
+
return parsed;
|
|
90
|
+
}
|
|
91
|
+
function readMergedConfig() {
|
|
92
|
+
const tokens = {};
|
|
93
|
+
const tokenNames = {};
|
|
94
|
+
const extraFields = {};
|
|
95
|
+
const paths = getConfigStorePaths();
|
|
96
|
+
for (let i = paths.length - 1; i >= 0; i--) {
|
|
97
|
+
const raw = readConfigFile(paths[i]);
|
|
98
|
+
if (!raw) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
102
|
+
if (!MANAGED_TOP_LEVEL_KEYS.has(key) && !FORBIDDEN_KEYS.has(key)) {
|
|
103
|
+
extraFields[key] = value;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
Object.assign(tokens, extractStringRecord(raw.tokens));
|
|
107
|
+
Object.assign(tokenNames, extractStringRecord(raw.tokenNames));
|
|
108
|
+
}
|
|
109
|
+
for (const appId of Object.keys(tokenNames)) {
|
|
110
|
+
if (!Object.prototype.hasOwnProperty.call(tokens, appId)) {
|
|
111
|
+
delete tokenNames[appId];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return { tokens, tokenNames, extraFields };
|
|
115
|
+
}
|
|
116
|
+
function writeLocalConfig(config) {
|
|
117
|
+
const payload = {
|
|
118
|
+
...config.extraFields,
|
|
119
|
+
_comment: WARNING_COMMENT,
|
|
120
|
+
tokens: config.tokens,
|
|
121
|
+
};
|
|
122
|
+
if (Object.keys(config.tokenNames).length > 0) {
|
|
123
|
+
payload.tokenNames = config.tokenNames;
|
|
124
|
+
}
|
|
125
|
+
for (const configPath of getConfigStorePaths()) {
|
|
126
|
+
const store = new Configstore(CONFIGSTORE_ID, undefined, { configPath });
|
|
127
|
+
store.all = payload;
|
|
128
|
+
try {
|
|
129
|
+
fs.chmodSync(configPath, 0o600);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function getLocalConfigPath() {
|
|
136
|
+
return path.join(getCanonicalConfigDir(), "configstore", `${CONFIGSTORE_ID}.json`);
|
|
137
|
+
}
|
|
138
|
+
function getAllLocalTokens() {
|
|
139
|
+
return readMergedConfig().tokens;
|
|
140
|
+
}
|
|
141
|
+
function getAllLocalTokenNames() {
|
|
142
|
+
return readMergedConfig().tokenNames;
|
|
143
|
+
}
|
|
144
|
+
function getLocalToken(appId) {
|
|
145
|
+
if (FORBIDDEN_KEYS.has(appId)) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
const tokens = getAllLocalTokens();
|
|
149
|
+
return Object.prototype.hasOwnProperty.call(tokens, appId) ? tokens[appId] : undefined;
|
|
150
|
+
}
|
|
151
|
+
function getLocalTokenName(appId) {
|
|
152
|
+
if (FORBIDDEN_KEYS.has(appId)) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
const tokenNames = getAllLocalTokenNames();
|
|
156
|
+
return Object.prototype.hasOwnProperty.call(tokenNames, appId) ? tokenNames[appId] : undefined;
|
|
157
|
+
}
|
|
158
|
+
function saveLocalToken(appId, token, resourceName) {
|
|
159
|
+
if (!appId || FORBIDDEN_KEYS.has(appId)) {
|
|
160
|
+
throw new error_1.FirebaseError(`Invalid Firebase App ID "${appId}".`, { exit: 1 });
|
|
161
|
+
}
|
|
162
|
+
const config = readMergedConfig();
|
|
163
|
+
config.tokens[appId] = token;
|
|
164
|
+
if (resourceName) {
|
|
165
|
+
config.tokenNames[appId] = resourceName;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
delete config.tokenNames[appId];
|
|
169
|
+
}
|
|
170
|
+
writeLocalConfig(config);
|
|
171
|
+
}
|
|
172
|
+
function removeLocalTokens(appIds) {
|
|
173
|
+
if (appIds.length === 0) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const config = readMergedConfig();
|
|
177
|
+
let modified = false;
|
|
178
|
+
for (const appId of appIds) {
|
|
179
|
+
if (FORBIDDEN_KEYS.has(appId)) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (Object.prototype.hasOwnProperty.call(config.tokens, appId)) {
|
|
183
|
+
delete config.tokens[appId];
|
|
184
|
+
delete config.tokenNames[appId];
|
|
185
|
+
modified = true;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (modified) {
|
|
189
|
+
writeLocalConfig(config);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -138,7 +138,7 @@ function getLoginCredential(args) {
|
|
|
138
138
|
function isPresenceMismatched(value1, value2) {
|
|
139
139
|
return (value1 && !value2) || (!value1 && value2);
|
|
140
140
|
}
|
|
141
|
-
const APP_NAME_REGEX = /^projects\/(?<projectNumber>[
|
|
141
|
+
const APP_NAME_REGEX = /^projects\/(?<projectNumber>[^/]+)\/apps\/(?<appId>[^/]+)$/;
|
|
142
142
|
const BUCKET_NAME_FORMAT_REGEX = /^[a-z0-9_.-]+$/;
|
|
143
143
|
function getResultsBucket(bucket, appName) {
|
|
144
144
|
if (!bucket) {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CLOUD_RUN_SIZE_LIMIT_BYTES = exports.
|
|
3
|
+
exports.CLOUD_RUN_SIZE_LIMIT_BYTES = exports.DEFAULT_LOCATION = void 0;
|
|
4
4
|
exports.DEFAULT_LOCATION = "us-east4";
|
|
5
|
-
exports.DEFAULT_DEPLOY_METHOD = "github";
|
|
6
|
-
exports.ALLOWED_DEPLOY_METHODS = [{ name: "Deploy using github", value: "github" }];
|
|
7
|
-
exports.LOCAL_BUILD_DIR_NAME = ".local_build";
|
|
8
5
|
exports.CLOUD_RUN_SIZE_LIMIT_BYTES = 250 * 1024 * 1024;
|
|
@@ -32,7 +32,7 @@ const fuzzy = require("fuzzy");
|
|
|
32
32
|
const apiv2_1 = require("../apiv2");
|
|
33
33
|
const githubApiClient = new apiv2_1.Client({ urlPrefix: (0, api_1.githubApiOrigin)(), auth: false });
|
|
34
34
|
const APPHOSTING_CONN_PATTERN = /.+\/apphosting-github-conn-.+$/;
|
|
35
|
-
const CONNECTION_NAME_REGEX = /^projects\/(?<projectId>[
|
|
35
|
+
const CONNECTION_NAME_REGEX = /^projects\/(?<projectId>[^/]+)\/locations\/(?<location>[^/]+)\/connections\/(?<id>[^/]+)$/;
|
|
36
36
|
function parseConnectionName(name) {
|
|
37
37
|
const match = CONNECTION_NAME_REGEX.exec(name);
|
|
38
38
|
if (!match || typeof match.groups === "undefined") {
|
package/lib/apphosting/utils.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEnvironmentName = getEnvironmentName;
|
|
4
|
-
exports.promptForAppHostingYaml = promptForAppHostingYaml;
|
|
5
4
|
exports.getAutoinitEnvVars = getAutoinitEnvVars;
|
|
6
5
|
const error_1 = require("../error");
|
|
7
6
|
const config_1 = require("./config");
|
|
8
|
-
const prompt = require("../prompt");
|
|
9
7
|
function getEnvironmentName(apphostingYamlFileName) {
|
|
10
8
|
const found = apphostingYamlFileName.match(config_1.APPHOSTING_YAML_FILE_REGEX);
|
|
11
9
|
if (!found || found.length < 2 || !found[1]) {
|
|
@@ -13,30 +11,6 @@ function getEnvironmentName(apphostingYamlFileName) {
|
|
|
13
11
|
}
|
|
14
12
|
return found[1].replaceAll(".", "");
|
|
15
13
|
}
|
|
16
|
-
async function promptForAppHostingYaml(apphostingFileNameToPathMap, promptMessage = "Please select an App Hosting config:") {
|
|
17
|
-
const fileNames = Array.from(apphostingFileNameToPathMap.keys());
|
|
18
|
-
const baseFilePath = apphostingFileNameToPathMap.get(config_1.APPHOSTING_BASE_YAML_FILE);
|
|
19
|
-
const listOptions = fileNames.map((fileName) => {
|
|
20
|
-
if (fileName === config_1.APPHOSTING_BASE_YAML_FILE) {
|
|
21
|
-
return {
|
|
22
|
-
name: `base (${config_1.APPHOSTING_BASE_YAML_FILE})`,
|
|
23
|
-
value: baseFilePath,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
const environment = getEnvironmentName(fileName);
|
|
27
|
-
return {
|
|
28
|
-
name: baseFilePath
|
|
29
|
-
? `${environment} (${config_1.APPHOSTING_BASE_YAML_FILE} + ${fileName})`
|
|
30
|
-
: `${environment} (${fileName})`,
|
|
31
|
-
value: apphostingFileNameToPathMap.get(fileName),
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
const fileToExportPath = await prompt.select({
|
|
35
|
-
message: promptMessage,
|
|
36
|
-
choices: listOptions,
|
|
37
|
-
});
|
|
38
|
-
return fileToExportPath;
|
|
39
|
-
}
|
|
40
14
|
function getAutoinitEnvVars(webappConfig) {
|
|
41
15
|
if (!webappConfig) {
|
|
42
16
|
return {};
|
package/lib/auth.js
CHANGED
|
@@ -413,7 +413,13 @@ async function loginWithLocalhostGitHub(port) {
|
|
|
413
413
|
}
|
|
414
414
|
async function loginWithLocalhost(port, callbackUrl, authUrl, successHtml, getTokens) {
|
|
415
415
|
return new Promise((resolve, reject) => {
|
|
416
|
-
const server = http.createServer(
|
|
416
|
+
const server = http.createServer((req, res) => {
|
|
417
|
+
handleCallback(req, res).catch((err) => {
|
|
418
|
+
reject(err);
|
|
419
|
+
server.close();
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
async function handleCallback(req, res) {
|
|
417
423
|
let searchParams;
|
|
418
424
|
try {
|
|
419
425
|
searchParams = new URL(req.url || "", callbackUrl).searchParams;
|
|
@@ -442,7 +448,7 @@ async function loginWithLocalhost(port, callbackUrl, authUrl, successHtml, getTo
|
|
|
442
448
|
}
|
|
443
449
|
server.close();
|
|
444
450
|
return;
|
|
445
|
-
}
|
|
451
|
+
}
|
|
446
452
|
server.listen(port, () => {
|
|
447
453
|
logger_1.logger.info();
|
|
448
454
|
logger_1.logger.info("Visit this URL on this device to log in:");
|