firebase-tools-with-isolate 13.16.0 → 13.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.
- package/lib/api.js +3 -1
- package/lib/apiv2.js +10 -3
- package/lib/appdistribution/client.js +62 -8
- package/lib/appdistribution/distribution.js +1 -1
- package/lib/apphosting/backend.js +299 -0
- package/lib/apphosting/config.js +31 -8
- package/lib/apphosting/githubConnections.js +70 -22
- package/lib/apphosting/index.js +3 -312
- package/lib/apphosting/rollout.js +138 -0
- package/lib/apphosting/secrets/index.js +70 -5
- package/lib/apphosting/utils.js +41 -0
- package/lib/apphosting/yaml.js +82 -0
- package/lib/archiveDirectory.js +1 -1
- package/lib/auth.js +31 -5
- package/lib/bin/firebase.js +2 -2
- package/lib/command.js +18 -4
- package/lib/commands/appdistribution-distribute.js +4 -4
- package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
- package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
- package/lib/commands/appdistribution-groups-list.js +55 -0
- package/lib/commands/appdistribution-testers-list.js +52 -0
- package/lib/commands/appdistribution-testers-remove.js +1 -1
- package/lib/commands/apphosting-backends-create.js +4 -4
- package/lib/commands/apphosting-backends-delete.js +7 -15
- package/lib/commands/apphosting-backends-get.js +1 -1
- package/lib/commands/apphosting-config-export.js +51 -0
- package/lib/commands/apphosting-repos-create.js +23 -0
- package/lib/commands/apphosting-rollouts-create.js +14 -15
- package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
- package/lib/commands/database-import.js +4 -2
- package/lib/commands/database-push.js +4 -2
- package/lib/commands/database-set.js +4 -2
- package/lib/commands/database-settings-get.js +1 -1
- package/lib/commands/database-settings-set.js +1 -1
- package/lib/commands/dataconnect-sdk-generate.js +4 -1
- package/lib/commands/dataconnect-services-list.js +4 -3
- package/lib/commands/dataconnect-sql-diff.js +1 -1
- package/lib/commands/dataconnect-sql-grant.js +37 -0
- package/lib/commands/dataconnect-sql-migrate.js +1 -1
- package/lib/commands/dataconnect-sql-shell.js +115 -0
- package/lib/commands/deploy.js +2 -0
- package/lib/commands/emulators-start.js +4 -1
- package/lib/commands/ext-dev-init.js +2 -2
- package/lib/commands/ext-dev-list.js +1 -1
- package/lib/commands/ext-dev-register.js +2 -2
- package/lib/commands/ext-dev-upload.js +2 -2
- package/lib/commands/ext-dev-usage.js +2 -2
- package/lib/commands/ext-info.js +3 -1
- package/lib/commands/ext-install.js +2 -2
- package/lib/commands/ext-sdk-install.js +88 -0
- package/lib/commands/ext.js +1 -0
- package/lib/commands/firestore-databases-restore.js +39 -1
- package/lib/commands/functions-secrets-access.js +2 -4
- package/lib/commands/index.js +15 -2
- package/lib/commands/init.js +25 -15
- package/lib/commands/setup-emulators-dataconnect.js +0 -13
- package/lib/commands/use.js +1 -1
- package/lib/config.js +14 -4
- package/lib/crashlytics/buildToolsJarHelper.js +2 -2
- package/lib/dataconnect/client.js +1 -1
- package/lib/dataconnect/dataplaneClient.js +12 -9
- package/lib/dataconnect/ensureApis.js +6 -1
- package/lib/dataconnect/fileUtils.js +15 -39
- package/lib/dataconnect/freeTrial.js +45 -9
- package/lib/dataconnect/load.js +3 -1
- package/lib/dataconnect/provisionCloudSql.js +39 -26
- package/lib/dataconnect/schemaMigration.js +215 -74
- package/lib/dataconnect/types.js +4 -1
- package/lib/dataconnect/webhook.js +32 -0
- package/lib/deploy/dataconnect/deploy.js +18 -15
- package/lib/deploy/dataconnect/prepare.js +41 -0
- package/lib/deploy/dataconnect/release.js +16 -7
- package/lib/deploy/extensions/deploy.js +3 -1
- package/lib/deploy/extensions/deploymentSummary.js +7 -3
- package/lib/deploy/extensions/planner.js +44 -5
- package/lib/deploy/extensions/prepare.js +45 -73
- package/lib/deploy/extensions/release.js +11 -10
- package/lib/deploy/extensions/tasks.js +32 -21
- package/lib/deploy/firestore/prepare.js +9 -0
- package/lib/deploy/firestore/release.js +3 -6
- package/lib/deploy/functions/checkIam.js +7 -2
- package/lib/deploy/functions/ensure.js +11 -3
- package/lib/deploy/functions/prepare.js +10 -2
- package/lib/deploy/functions/release/planner.js +2 -1
- package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
- package/lib/deploy/functions/runtimes/node/index.js +5 -0
- package/lib/deploy/functions/services/auth.js +34 -3
- package/lib/deploy/functions/services/index.js +2 -0
- package/lib/deploy/index.js +8 -5
- package/lib/deploy/lifecycleHooks.js +2 -1
- package/lib/emulator/apphosting/config.js +27 -0
- package/lib/emulator/apphosting/index.js +38 -0
- package/lib/emulator/apphosting/serve.js +50 -0
- package/lib/emulator/apphosting/utils.js +18 -0
- package/lib/emulator/auth/handlers.js +27 -0
- package/lib/emulator/auth/operations.js +41 -2
- package/lib/emulator/auth/state.js +2 -1
- package/lib/emulator/commandUtils.js +8 -3
- package/lib/emulator/constants.js +4 -1
- package/lib/emulator/controller.js +48 -5
- package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
- package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
- package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
- package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
- package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
- package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
- package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
- package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
- package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
- package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
- package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
- package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
- package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
- package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
- package/lib/emulator/dataconnect/pgliteServer.js +95 -0
- package/lib/emulator/dataconnectEmulator.js +58 -75
- package/lib/emulator/dataconnectToolkitController.js +44 -0
- package/lib/emulator/downloadableEmulators.js +27 -16
- package/lib/emulator/emulatorLogger.js +3 -0
- package/lib/emulator/eventarcEmulator.js +1 -1
- package/lib/emulator/extensionsEmulator.js +38 -6
- package/lib/emulator/functionsEmulator.js +85 -41
- package/lib/emulator/functionsEmulatorShared.js +2 -1
- package/lib/emulator/functionsRuntimeWorker.js +2 -1
- package/lib/emulator/hub.js +13 -9
- package/lib/emulator/hubExport.js +10 -3
- package/lib/emulator/loggingEmulator.js +2 -2
- package/lib/emulator/portUtils.js +10 -11
- package/lib/emulator/registry.js +1 -0
- package/lib/emulator/storage/persistence.js +2 -2
- package/lib/emulator/storage/rules/runtime.js +1 -1
- package/lib/emulator/tasksEmulator.js +5 -2
- package/lib/emulator/types.js +3 -0
- package/lib/emulator/ui.js +51 -25
- package/lib/error.js +31 -1
- package/lib/experiments.js +5 -0
- package/lib/extensions/emulator/triggerHelper.js +1 -1
- package/lib/extensions/extensionsApi.js +14 -10
- package/lib/extensions/extensionsHelper.js +15 -6
- package/lib/extensions/localHelper.js +31 -0
- package/lib/extensions/runtimes/common.js +179 -39
- package/lib/extensions/runtimes/node.js +401 -0
- package/lib/extensions/types.js +25 -14
- package/lib/extensions/warnings.js +5 -2
- package/lib/firestore/api.js +2 -1
- package/lib/firestore/checkDatabaseType.js +10 -3
- package/lib/firestore/delete.js +11 -0
- package/lib/firestore/options.js +7 -0
- package/lib/frameworks/angular/index.js +15 -3
- package/lib/frameworks/constants.js +1 -1
- package/lib/frameworks/flutter/index.js +6 -6
- package/lib/frameworks/flutter/utils.js +34 -1
- package/lib/frameworks/next/index.js +10 -2
- package/lib/frameworks/next/utils.js +8 -5
- package/lib/frameworks/vite/index.js +2 -2
- package/lib/fsutils.js +13 -1
- package/lib/functions/constants.js +4 -0
- package/lib/functions/events/v1.js +9 -2
- package/lib/gcp/apphosting.js +1 -1
- package/lib/gcp/cloudmonitoring.js +3 -3
- package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
- package/lib/gcp/cloudsql/connect.js +49 -37
- package/lib/gcp/cloudsql/interactive.js +49 -0
- package/lib/gcp/cloudsql/permissions.js +165 -0
- package/lib/gcp/devConnect.js +38 -1
- package/lib/gcp/firestore.js +5 -1
- package/lib/gcp/secretManager.js +12 -5
- package/lib/getProjectNumber.js +1 -1
- package/lib/init/features/apphosting.js +15 -0
- package/lib/init/features/dataconnect/index.js +159 -120
- package/lib/init/features/dataconnect/sdk.js +77 -84
- package/lib/init/features/emulators.js +2 -15
- package/lib/init/features/firestore/index.js +20 -1
- package/lib/init/features/firestore/indexes.js +4 -4
- package/lib/init/features/genkit/index.js +444 -0
- package/lib/init/features/hosting/index.js +2 -2
- package/lib/init/features/index.js +1 -1
- package/lib/init/features/project.js +6 -6
- package/lib/init/features/storage.js +0 -2
- package/lib/init/index.js +1 -0
- package/lib/init/spawn.js +23 -2
- package/lib/logger.js +2 -2
- package/lib/management/projects.js +24 -4
- package/lib/projectUtils.js +1 -1
- package/lib/prompt.js +1 -1
- package/lib/rc.js +1 -8
- package/lib/requireAuth.js +19 -5
- package/lib/requireDatabaseInstance.js +1 -1
- package/lib/requirePermissions.js +1 -1
- package/lib/responseToError.js +5 -2
- package/lib/rulesDeploy.js +1 -1
- package/lib/templates.js +2 -2
- package/lib/utils.js +16 -11
- package/lib/vsCodeUtils.js +8 -0
- package/package.json +7 -6
- package/schema/connector-yaml.json +57 -17
- package/schema/firebase-config.json +24 -0
- package/templates/extensions/javascript/package.lint.json +2 -2
- package/templates/extensions/javascript/package.nolint.json +2 -2
- package/templates/extensions/typescript/package.lint.json +2 -2
- package/templates/extensions/typescript/package.nolint.json +2 -2
- package/templates/genkit/firebase.0.9.0.template +57 -0
- package/templates/init/apphosting/apphosting.yaml +23 -0
- package/templates/init/dataconnect/connector.yaml +0 -1
- package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
- package/templates/init/dataconnect/dataconnect.yaml +1 -1
- package/templates/init/dataconnect/queries.gql +1 -2
- package/templates/init/functions/javascript/package.lint.json +2 -2
- package/templates/init/functions/javascript/package.nolint.json +2 -2
- package/templates/init/functions/typescript/package.lint.json +2 -2
- package/templates/init/functions/typescript/package.nolint.json +2 -2
- package/lib/ensureCloudResourceLocation.js +0 -12
- package/lib/init/features/genkit.js +0 -53
package/lib/error.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBillingError = exports.FirebaseError = void 0;
|
|
3
|
+
exports.isBillingError = exports.getError = exports.getErrStatus = exports.getErrMsg = exports.FirebaseError = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const DEFAULT_CHILDREN = [];
|
|
6
6
|
const DEFAULT_EXIT = 1;
|
|
@@ -18,6 +18,36 @@ class FirebaseError extends Error {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.FirebaseError = FirebaseError;
|
|
21
|
+
function getErrMsg(err, defaultMsg) {
|
|
22
|
+
if (err instanceof Error) {
|
|
23
|
+
return err.message;
|
|
24
|
+
}
|
|
25
|
+
else if (typeof err === "string") {
|
|
26
|
+
return err;
|
|
27
|
+
}
|
|
28
|
+
else if (defaultMsg) {
|
|
29
|
+
return defaultMsg;
|
|
30
|
+
}
|
|
31
|
+
return JSON.stringify(err);
|
|
32
|
+
}
|
|
33
|
+
exports.getErrMsg = getErrMsg;
|
|
34
|
+
function isObject(value) {
|
|
35
|
+
return typeof value === "object" && value !== null;
|
|
36
|
+
}
|
|
37
|
+
function getErrStatus(err, defaultStatus) {
|
|
38
|
+
if (isObject(err) && err.status && typeof err.status === "number") {
|
|
39
|
+
return err.status;
|
|
40
|
+
}
|
|
41
|
+
return defaultStatus || DEFAULT_STATUS;
|
|
42
|
+
}
|
|
43
|
+
exports.getErrStatus = getErrStatus;
|
|
44
|
+
function getError(err) {
|
|
45
|
+
if (err instanceof Error) {
|
|
46
|
+
return err;
|
|
47
|
+
}
|
|
48
|
+
return Error(getErrMsg(err));
|
|
49
|
+
}
|
|
50
|
+
exports.getError = getError;
|
|
21
51
|
function isBillingError(e) {
|
|
22
52
|
return !!e.context?.body?.error?.details?.find((d) => {
|
|
23
53
|
return (d.violations?.find((v) => v.type === "serviceusage/billing-enabled") ||
|
package/lib/experiments.js
CHANGED
|
@@ -56,6 +56,10 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
56
56
|
emulatoruisnapshot: {
|
|
57
57
|
shortDescription: "Load pre-release versions of the emulator UI",
|
|
58
58
|
},
|
|
59
|
+
emulatorapphosting: {
|
|
60
|
+
shortDescription: "App Hosting emulator",
|
|
61
|
+
public: false,
|
|
62
|
+
},
|
|
59
63
|
webframeworks: {
|
|
60
64
|
shortDescription: "Native support for popular web frameworks",
|
|
61
65
|
fullDescription: "Adds support for popular web frameworks such as Next.js " +
|
|
@@ -105,6 +109,7 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
105
109
|
fdccompatiblemode: {
|
|
106
110
|
shortDescription: "Enable Data Connect schema migrations in Compatible Mode",
|
|
107
111
|
fullDescription: "Enable Data Connect schema migrations in Compatible Mode",
|
|
112
|
+
default: true,
|
|
108
113
|
public: false,
|
|
109
114
|
},
|
|
110
115
|
});
|
|
@@ -58,7 +58,7 @@ function functionResourceToEmulatedTriggerDefintion(resource, systemParams = {})
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
|
-
emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.FUNCTIONS).log("WARN", `Function '${resource.name} is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored.`);
|
|
61
|
+
emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.FUNCTIONS).log("WARN", `Function '${resource.name}' is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored.`);
|
|
62
62
|
}
|
|
63
63
|
return etd;
|
|
64
64
|
}
|
|
@@ -9,16 +9,18 @@ const error_1 = require("../error");
|
|
|
9
9
|
const logger_1 = require("../logger");
|
|
10
10
|
const operationPoller = require("../operation-poller");
|
|
11
11
|
const refs = require("./refs");
|
|
12
|
+
const types_1 = require("./types");
|
|
12
13
|
const EXTENSIONS_API_VERSION = "v1beta";
|
|
13
14
|
const PAGE_SIZE_MAX = 100;
|
|
14
15
|
const extensionsApiClient = new apiv2_1.Client({
|
|
15
16
|
urlPrefix: (0, api_1.extensionsOrigin)(),
|
|
16
17
|
apiVersion: EXTENSIONS_API_VERSION,
|
|
17
18
|
});
|
|
18
|
-
async function createInstanceHelper(projectId, instanceId, config, validateOnly = false) {
|
|
19
|
+
async function createInstanceHelper(projectId, instanceId, config, labels, validateOnly = false) {
|
|
19
20
|
const createRes = await extensionsApiClient.post(`/projects/${projectId}/instances/`, {
|
|
20
21
|
name: `projects/${projectId}/instances/${instanceId}`,
|
|
21
22
|
config,
|
|
23
|
+
labels,
|
|
22
24
|
}, {
|
|
23
25
|
queryParams: {
|
|
24
26
|
validateOnly: validateOnly ? "true" : "false",
|
|
@@ -62,7 +64,7 @@ async function createInstance(args) {
|
|
|
62
64
|
if (args.eventarcChannel) {
|
|
63
65
|
config.eventarcChannel = args.eventarcChannel;
|
|
64
66
|
}
|
|
65
|
-
return createInstanceHelper(args.projectId, args.instanceId, config, args.validateOnly);
|
|
67
|
+
return await createInstanceHelper(args.projectId, args.instanceId, config, args.labels, args.validateOnly);
|
|
66
68
|
}
|
|
67
69
|
exports.createInstance = createInstance;
|
|
68
70
|
async function deleteInstance(projectId, instanceId) {
|
|
@@ -79,10 +81,12 @@ exports.deleteInstance = deleteInstance;
|
|
|
79
81
|
async function getInstance(projectId, instanceId) {
|
|
80
82
|
try {
|
|
81
83
|
const res = await extensionsApiClient.get(`/projects/${projectId}/instances/${instanceId}`);
|
|
82
|
-
|
|
84
|
+
if ((0, types_1.isExtensionInstance)(res.body)) {
|
|
85
|
+
return res.body;
|
|
86
|
+
}
|
|
83
87
|
}
|
|
84
88
|
catch (err) {
|
|
85
|
-
if (err
|
|
89
|
+
if ((0, error_1.getErrStatus)(err) === 404) {
|
|
86
90
|
throw new error_1.FirebaseError(`Extension instance '${clc.bold(instanceId)}' not found in project '${clc.bold(projectId)}'.`, { status: 404 });
|
|
87
91
|
}
|
|
88
92
|
throw err;
|
|
@@ -229,7 +233,7 @@ function populateSpec(spec) {
|
|
|
229
233
|
}
|
|
230
234
|
}
|
|
231
235
|
catch (err) {
|
|
232
|
-
logger_1.logger.debug(`[ext] failed to parse resource properties yaml: ${err}`);
|
|
236
|
+
logger_1.logger.debug(`[ext] failed to parse resource properties yaml: ${(0, error_1.getErrMsg)(err)}`);
|
|
233
237
|
}
|
|
234
238
|
}
|
|
235
239
|
spec.params = spec.params ?? [];
|
|
@@ -275,13 +279,13 @@ async function getExtensionVersion(extensionVersionRef) {
|
|
|
275
279
|
return res.body;
|
|
276
280
|
}
|
|
277
281
|
catch (err) {
|
|
278
|
-
if (err
|
|
282
|
+
if ((0, error_1.getErrStatus)(err) === 404) {
|
|
279
283
|
throw refNotFoundError(ref);
|
|
280
284
|
}
|
|
281
285
|
else if (err instanceof error_1.FirebaseError) {
|
|
282
286
|
throw err;
|
|
283
287
|
}
|
|
284
|
-
throw new error_1.FirebaseError(`Failed to query the extension version '${clc.bold(extensionVersionRef)}': ${err}`);
|
|
288
|
+
throw new error_1.FirebaseError(`Failed to query the extension version '${clc.bold(extensionVersionRef)}': ${(0, error_1.getErrMsg)(err)}`);
|
|
285
289
|
}
|
|
286
290
|
}
|
|
287
291
|
exports.getExtensionVersion = getExtensionVersion;
|
|
@@ -335,14 +339,14 @@ async function getExtension(extensionRef) {
|
|
|
335
339
|
return res.body;
|
|
336
340
|
}
|
|
337
341
|
catch (err) {
|
|
338
|
-
if (err
|
|
342
|
+
if ((0, error_1.getErrStatus)(err) === 404) {
|
|
339
343
|
throw refNotFoundError(ref);
|
|
340
344
|
}
|
|
341
345
|
else if (err instanceof error_1.FirebaseError) {
|
|
342
346
|
throw err;
|
|
343
347
|
}
|
|
344
|
-
throw new error_1.FirebaseError(`Failed to query the extension '${clc.bold(extensionRef)}': ${err}`, {
|
|
345
|
-
status: err
|
|
348
|
+
throw new error_1.FirebaseError(`Failed to query the extension '${clc.bold(extensionRef)}': ${(0, error_1.getErrMsg)(err)}`, {
|
|
349
|
+
status: (0, error_1.getErrStatus)(err),
|
|
346
350
|
});
|
|
347
351
|
}
|
|
348
352
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.diagnoseAndFixProject = exports.getSourceOrigin = exports.isLocalOrURLPath = exports.isLocalPath = exports.isUrlPath = exports.instanceIdExists = exports.promptForRepeatInstance = exports.promptForOfficialExtension = exports.displayReleaseNotes = exports.getPublisherProjectFromName = exports.createSourceFromLocation = exports.getMissingPublisherError = exports.uploadExtensionVersionFromLocalSource = exports.uploadExtensionVersionFromGitHubSource = exports.unpackExtensionState = exports.getNextVersionByStage = exports.ensureExtensionsPublisherApiEnabled = exports.ensureExtensionsApiEnabled = exports.checkExtensionsApiEnabled = exports.promptForExtensionRoot = exports.promptForValidRepoURI = exports.promptForValidInstanceId = exports.validateSpec = exports.validateCommandLineParams = exports.populateDefaultParams = exports.substituteSecretParams = exports.substituteParams = exports.getFirebaseProjectParams = exports.getDBInstanceFromURL = exports.resourceTypeToNiceName = exports.
|
|
3
|
+
exports.diagnoseAndFixProject = exports.getSourceOrigin = exports.isLocalOrURLPath = exports.isLocalPath = exports.isUrlPath = exports.instanceIdExists = exports.promptForRepeatInstance = exports.promptForOfficialExtension = exports.displayReleaseNotes = exports.getPublisherProjectFromName = exports.createSourceFromLocation = exports.getMissingPublisherError = exports.uploadExtensionVersionFromLocalSource = exports.uploadExtensionVersionFromGitHubSource = exports.unpackExtensionState = exports.getNextVersionByStage = exports.ensureExtensionsPublisherApiEnabled = exports.ensureExtensionsApiEnabled = exports.checkExtensionsApiEnabled = exports.promptForExtensionRoot = exports.promptForValidRepoURI = exports.promptForValidInstanceId = exports.validateSpec = exports.validateCommandLineParams = exports.populateDefaultParams = exports.substituteSecretParams = exports.substituteParams = exports.getFirebaseProjectParams = exports.getDBInstanceFromURL = exports.resourceTypeToNiceName = exports.AUTOPOPULATED_PARAM_PLACEHOLDERS = exports.EXTENSIONS_BUCKET_NAME = exports.URL_REGEX = exports.logPrefix = exports.SourceOrigin = exports.SpecParamType = void 0;
|
|
4
4
|
const clc = require("colorette");
|
|
5
5
|
const ora = require("ora");
|
|
6
6
|
const semver = require("semver");
|
|
@@ -62,7 +62,7 @@ const AUTOPOPULATED_PARAM_NAMES = [
|
|
|
62
62
|
"DATABASE_INSTANCE",
|
|
63
63
|
"DATABASE_URL",
|
|
64
64
|
];
|
|
65
|
-
exports.
|
|
65
|
+
exports.AUTOPOPULATED_PARAM_PLACEHOLDERS = {
|
|
66
66
|
PROJECT_ID: "project-id",
|
|
67
67
|
STORAGE_BUCKET: "project-id.appspot.com",
|
|
68
68
|
EXT_INSTANCE_ID: "extension-id",
|
|
@@ -90,9 +90,18 @@ async function getFirebaseProjectParams(projectId, emulatorMode = false) {
|
|
|
90
90
|
const body = emulatorMode
|
|
91
91
|
? await (0, adminSdkConfig_1.getProjectAdminSdkConfigOrCached)(projectId)
|
|
92
92
|
: await (0, functionsConfig_1.getFirebaseConfig)({ project: projectId });
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
let projectNumber = constants_1.Constants.FAKE_PROJECT_NUMBER;
|
|
94
|
+
if (!constants_1.Constants.isDemoProject(projectId)) {
|
|
95
|
+
try {
|
|
96
|
+
projectNumber = await (0, getProjectNumber_1.getProjectNumber)({ projectId });
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
(0, utils_2.logLabeledError)("extensions", `Unable to look up project number for ${projectId}.\n` +
|
|
100
|
+
" If this is a real project, ensure that you are logged in and have access to it.\n" +
|
|
101
|
+
" If this is a fake project, please use a project ID starting with 'demo-' to skip production calls.\n" +
|
|
102
|
+
" Continuing with a fake project number - secrets and other features that require production access may behave unexpectedly.");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
96
105
|
const databaseURL = body?.databaseURL ?? `https://${projectId}.firebaseio.com`;
|
|
97
106
|
const storageBucket = body?.storageBucket ?? `${projectId}.appspot.com`;
|
|
98
107
|
const FIREBASE_CONFIG = JSON.stringify({
|
|
@@ -423,7 +432,7 @@ async function validateExtensionSpec(rootDirectory, extensionId) {
|
|
|
423
432
|
throw new error_1.FirebaseError(`Extension ID '${clc.bold(extensionId)}' does not match the name in extension.yaml '${clc.bold(extensionSpec.name)}'.`);
|
|
424
433
|
}
|
|
425
434
|
const subbedSpec = JSON.parse(JSON.stringify(extensionSpec));
|
|
426
|
-
subbedSpec.params = substituteParams(extensionSpec.params || [], exports.
|
|
435
|
+
subbedSpec.params = substituteParams(extensionSpec.params || [], exports.AUTOPOPULATED_PARAM_PLACEHOLDERS);
|
|
427
436
|
validateSpec(subbedSpec);
|
|
428
437
|
return extensionSpec;
|
|
429
438
|
}
|
|
@@ -6,11 +6,20 @@ const path = require("path");
|
|
|
6
6
|
const yaml = require("yaml");
|
|
7
7
|
const fsutils_1 = require("../fsutils");
|
|
8
8
|
const error_1 = require("../error");
|
|
9
|
+
const types_1 = require("./types");
|
|
9
10
|
const logger_1 = require("../logger");
|
|
11
|
+
const extensionsHelper_1 = require("./extensionsHelper");
|
|
10
12
|
exports.EXTENSIONS_SPEC_FILE = "extension.yaml";
|
|
11
13
|
const EXTENSIONS_PREINSTALL_FILE = "PREINSTALL.md";
|
|
12
14
|
async function getLocalExtensionSpec(directory) {
|
|
13
15
|
const spec = await parseYAML(readFile(path.resolve(directory, exports.EXTENSIONS_SPEC_FILE)));
|
|
16
|
+
if (spec.lifecycleEvents) {
|
|
17
|
+
spec.lifecycleEvents = fixLifecycleEvents(spec.lifecycleEvents);
|
|
18
|
+
}
|
|
19
|
+
if (!(0, types_1.isExtensionSpec)(spec)) {
|
|
20
|
+
(0, extensionsHelper_1.validateSpec)(spec);
|
|
21
|
+
throw new error_1.FirebaseError("Error: extension.yaml does not contain a valid extension specification.");
|
|
22
|
+
}
|
|
14
23
|
try {
|
|
15
24
|
const preinstall = readFile(path.resolve(directory, EXTENSIONS_PREINSTALL_FILE));
|
|
16
25
|
spec.preinstallContent = preinstall;
|
|
@@ -21,6 +30,28 @@ async function getLocalExtensionSpec(directory) {
|
|
|
21
30
|
return spec;
|
|
22
31
|
}
|
|
23
32
|
exports.getLocalExtensionSpec = getLocalExtensionSpec;
|
|
33
|
+
function fixLifecycleEvents(lifecycleEvents) {
|
|
34
|
+
const stages = {
|
|
35
|
+
onInstall: "ON_INSTALL",
|
|
36
|
+
onUpdate: "ON_UPDATE",
|
|
37
|
+
onConfigure: "ON_CONFIGURE",
|
|
38
|
+
stageUnspecified: "STAGE_UNSPECIFIED",
|
|
39
|
+
};
|
|
40
|
+
const arrayLifecycle = [];
|
|
41
|
+
if ((0, types_1.isObject)(lifecycleEvents)) {
|
|
42
|
+
for (const [key, val] of Object.entries(lifecycleEvents)) {
|
|
43
|
+
if ((0, types_1.isObject)(val) &&
|
|
44
|
+
typeof val.function === "string" &&
|
|
45
|
+
typeof val.processingMessage === "string") {
|
|
46
|
+
arrayLifecycle.push({
|
|
47
|
+
stage: stages[key] || stages["stageUnspecified"],
|
|
48
|
+
taskQueueTriggerFunction: val.function,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return arrayLifecycle;
|
|
54
|
+
}
|
|
24
55
|
function findExtensionYaml(directory) {
|
|
25
56
|
while (!(0, fsutils_1.fileExistsSync)(path.resolve(directory, exports.EXTENSIONS_SPEC_FILE))) {
|
|
26
57
|
const parentDir = path.dirname(directory);
|
|
@@ -1,45 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractExtensionsFromBuilds = exports.
|
|
3
|
+
exports.longestCommonPrefix = exports.snakeToCamelCase = exports.lowercaseFirstLetter = exports.capitalizeFirstLetter = exports.toTitleCase = exports.getInstallPathPrefix = exports.getCodebaseDir = exports.writeSDK = exports.getCodebaseRuntime = exports.copyDirectory = exports.writeFile = exports.isTypescriptCodebase = exports.extensionMatchesAnyFilter = exports.extractExtensionsFromBuilds = exports.fixDarkBlueText = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const prompt_1 = require("../../prompt");
|
|
7
|
+
const fsutils = require("../../fsutils");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const error_1 = require("../../error");
|
|
4
10
|
const projectConfig_1 = require("../../functions/projectConfig");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
logger_1.logger.silent = true;
|
|
12
|
-
}
|
|
13
|
-
function resumeLogging() {
|
|
14
|
-
logger_1.logger.silent = savedLoggerSilent;
|
|
15
|
-
}
|
|
16
|
-
async function extractAllDynamicExtensions(options) {
|
|
17
|
-
const firebaseConfig = await (0, functionsConfig_1.getFirebaseConfig)(options);
|
|
18
|
-
const runtimeConfig = { firebase: firebaseConfig };
|
|
19
|
-
const functionsConfig = (0, projectConfig_1.normalizeAndValidate)(options.config.src.functions);
|
|
20
|
-
let functionsBuilds = {};
|
|
21
|
-
const codebases = (0, functionsDeployHelper_1.targetCodebases)(functionsConfig);
|
|
22
|
-
silenceLogging();
|
|
23
|
-
for (const codebase of codebases) {
|
|
24
|
-
try {
|
|
25
|
-
const filters = [{ codebase: `${codebase}` }];
|
|
26
|
-
const builds = await (0, prepare_1.loadCodebases)(functionsConfig, options, firebaseConfig, runtimeConfig, filters);
|
|
27
|
-
functionsBuilds = { ...functionsBuilds, ...builds };
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
resumeLogging();
|
|
33
|
-
return extractExtensionsFromBuilds(functionsBuilds);
|
|
11
|
+
const functionRuntimes = require("../../deploy/functions/runtimes");
|
|
12
|
+
const nodeRuntime = require("./node");
|
|
13
|
+
function fixDarkBlueText(txt) {
|
|
14
|
+
const DARK_BLUE = "\u001b[34m";
|
|
15
|
+
const BRIGHT_CYAN = "\u001b[36;1m";
|
|
16
|
+
return txt.replaceAll(DARK_BLUE, BRIGHT_CYAN);
|
|
34
17
|
}
|
|
35
|
-
exports.
|
|
18
|
+
exports.fixDarkBlueText = fixDarkBlueText;
|
|
36
19
|
function extractExtensionsFromBuilds(builds, filters) {
|
|
37
20
|
const extRecords = {};
|
|
38
21
|
for (const [codebase, build] of Object.entries(builds)) {
|
|
39
22
|
if (build.extensions) {
|
|
40
23
|
for (const [id, ext] of Object.entries(build.extensions)) {
|
|
41
24
|
if (extensionMatchesAnyFilter(codebase, id, filters)) {
|
|
42
|
-
extRecords[id]
|
|
25
|
+
if (extRecords[id]) {
|
|
26
|
+
throw new error_1.FirebaseError(`Duplicate extension id found: ${id}`);
|
|
27
|
+
}
|
|
28
|
+
extRecords[id] = { ...ext, labels: { createdBy: "SDK", codebase } };
|
|
43
29
|
}
|
|
44
30
|
}
|
|
45
31
|
}
|
|
@@ -53,6 +39,7 @@ function extensionMatchesAnyFilter(codebase, extensionId, filters) {
|
|
|
53
39
|
}
|
|
54
40
|
return filters.some((f) => extensionMatchesFilter(codebase, extensionId, f));
|
|
55
41
|
}
|
|
42
|
+
exports.extensionMatchesAnyFilter = extensionMatchesAnyFilter;
|
|
56
43
|
function extensionMatchesFilter(codebase, extensionId, filter) {
|
|
57
44
|
if (codebase && filter.codebase) {
|
|
58
45
|
if (codebase !== filter.codebase) {
|
|
@@ -62,14 +49,167 @@ function extensionMatchesFilter(codebase, extensionId, filter) {
|
|
|
62
49
|
if (!filter.idChunks) {
|
|
63
50
|
return true;
|
|
64
51
|
}
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
const filterId = filter.idChunks.join("-");
|
|
53
|
+
return extensionId === filterId;
|
|
54
|
+
}
|
|
55
|
+
function isTypescriptCodebase(codebaseDir) {
|
|
56
|
+
return fsutils.fileExistsSync(path.join(codebaseDir, "tsconfig.json"));
|
|
57
|
+
}
|
|
58
|
+
exports.isTypescriptCodebase = isTypescriptCodebase;
|
|
59
|
+
async function writeFile(filePath, data, options) {
|
|
60
|
+
const shortFilePath = filePath.replace(process.cwd(), ".");
|
|
61
|
+
if (fsutils.fileExistsSync(filePath)) {
|
|
62
|
+
if (await (0, prompt_1.confirm)({
|
|
63
|
+
message: `${shortFilePath} already exists. Overwite it?`,
|
|
64
|
+
nonInteractive: options.nonInteractive,
|
|
65
|
+
force: options.force,
|
|
66
|
+
default: false,
|
|
67
|
+
})) {
|
|
68
|
+
try {
|
|
69
|
+
await fs.promises.writeFile(filePath, data, { flag: "w" });
|
|
70
|
+
(0, utils_1.logLabeledBullet)("extensions", `successfully wrote ${shortFilePath}`);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
throw new error_1.FirebaseError(`Failed to write ${shortFilePath}:\n ${(0, error_1.getErrMsg)(err)}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
68
79
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
else {
|
|
81
|
+
try {
|
|
82
|
+
await fs.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
83
|
+
try {
|
|
84
|
+
await fs.promises.writeFile(`${filePath}`, data, { flag: "w" });
|
|
85
|
+
(0, utils_1.logLabeledBullet)("extensions", `successfully created ${shortFilePath}`);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
throw new error_1.FirebaseError(`Failed to create ${shortFilePath}:\n ${(0, error_1.getErrMsg)(err)}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
throw new error_1.FirebaseError(`Error during SDK file creation:\n ${(0, error_1.getErrMsg)(err)}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.writeFile = writeFile;
|
|
97
|
+
async function copyDirectory(src, dest, options) {
|
|
98
|
+
const shortDestPath = dest.replace(process.cwd(), ",");
|
|
99
|
+
if (fsutils.dirExistsSync(dest)) {
|
|
100
|
+
if (await (0, prompt_1.confirm)({
|
|
101
|
+
message: `${shortDestPath} already exists. Copy anyway?`,
|
|
102
|
+
nonInteractive: options.nonInteractive,
|
|
103
|
+
force: options.force,
|
|
104
|
+
default: false,
|
|
105
|
+
})) {
|
|
106
|
+
const entries = await fs.promises.readdir(src, { withFileTypes: true });
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
const srcPath = path.join(src, entry.name);
|
|
109
|
+
const destPath = path.join(dest, entry.name);
|
|
110
|
+
if (entry.isDirectory()) {
|
|
111
|
+
if (srcPath.includes("node_modules")) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
await copyDirectory(srcPath, destPath, { ...options, force: true });
|
|
115
|
+
}
|
|
116
|
+
else if (entry.isFile())
|
|
117
|
+
try {
|
|
118
|
+
await fs.promises.copyFile(srcPath, destPath);
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
throw new error_1.FirebaseError(`Failed to copy ${destPath.replace(process.cwd(), ".")}:\n ${(0, error_1.getErrMsg)(err)}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
await fs.promises.mkdir(dest, { recursive: true });
|
|
131
|
+
await copyDirectory(src, dest, { ...options, force: true });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.copyDirectory = copyDirectory;
|
|
135
|
+
async function getCodebaseRuntime(options) {
|
|
136
|
+
const config = (0, projectConfig_1.normalizeAndValidate)(options.config.src.functions);
|
|
137
|
+
const codebaseConfig = (0, projectConfig_1.configForCodebase)(config, options.codebase || projectConfig_1.DEFAULT_CODEBASE);
|
|
138
|
+
const sourceDirName = codebaseConfig.source;
|
|
139
|
+
const sourceDir = options.config.path(sourceDirName);
|
|
140
|
+
const delegateContext = {
|
|
141
|
+
projectId: "",
|
|
142
|
+
sourceDir,
|
|
143
|
+
projectDir: options.config.projectDir,
|
|
144
|
+
runtime: codebaseConfig.runtime,
|
|
145
|
+
};
|
|
146
|
+
let delegate;
|
|
147
|
+
try {
|
|
148
|
+
delegate = await functionRuntimes.getRuntimeDelegate(delegateContext);
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
throw new error_1.FirebaseError(`Could not detect target language for SDK at ${sourceDir}`);
|
|
152
|
+
}
|
|
153
|
+
return delegate.runtime;
|
|
154
|
+
}
|
|
155
|
+
exports.getCodebaseRuntime = getCodebaseRuntime;
|
|
156
|
+
async function writeSDK(extensionRef, localPath, spec, options) {
|
|
157
|
+
const runtime = await getCodebaseRuntime(options);
|
|
158
|
+
if (runtime.startsWith("nodejs")) {
|
|
159
|
+
let sampleImport = await nodeRuntime.writeSDK(extensionRef, localPath, spec, options);
|
|
160
|
+
sampleImport = fixDarkBlueText(sampleImport);
|
|
161
|
+
return sampleImport;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
throw new error_1.FirebaseError(`Extension SDK generation is currently only supported for NodeJs. We detected the target source to be: ${runtime}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.writeSDK = writeSDK;
|
|
168
|
+
function getCodebaseDir(options) {
|
|
169
|
+
if (!options.projectRoot) {
|
|
170
|
+
throw new error_1.FirebaseError("Unable to determine root directory of project");
|
|
171
|
+
}
|
|
172
|
+
const config = (0, projectConfig_1.normalizeAndValidate)(options.config.src.functions);
|
|
173
|
+
const codebaseConfig = (0, projectConfig_1.configForCodebase)(config, options.codebase || projectConfig_1.DEFAULT_CODEBASE);
|
|
174
|
+
return `${options.projectRoot}/${codebaseConfig.source}/`;
|
|
175
|
+
}
|
|
176
|
+
exports.getCodebaseDir = getCodebaseDir;
|
|
177
|
+
function getInstallPathPrefix(options) {
|
|
178
|
+
return `${getCodebaseDir(options)}generated/extensions/`;
|
|
179
|
+
}
|
|
180
|
+
exports.getInstallPathPrefix = getInstallPathPrefix;
|
|
181
|
+
function toTitleCase(txt) {
|
|
182
|
+
return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
|
|
183
|
+
}
|
|
184
|
+
exports.toTitleCase = toTitleCase;
|
|
185
|
+
function capitalizeFirstLetter(txt) {
|
|
186
|
+
return txt.charAt(0).toUpperCase() + txt.substring(1);
|
|
187
|
+
}
|
|
188
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
189
|
+
function lowercaseFirstLetter(txt) {
|
|
190
|
+
return txt.charAt(0).toLowerCase() + txt.substring(1);
|
|
191
|
+
}
|
|
192
|
+
exports.lowercaseFirstLetter = lowercaseFirstLetter;
|
|
193
|
+
function snakeToCamelCase(txt) {
|
|
194
|
+
let ret = txt.toLowerCase();
|
|
195
|
+
ret = ret.replace(/_/g, " ");
|
|
196
|
+
ret = ret.replace(/\w\S*/g, toTitleCase);
|
|
197
|
+
ret = ret.charAt(0).toLowerCase() + ret.substring(1);
|
|
198
|
+
return ret;
|
|
199
|
+
}
|
|
200
|
+
exports.snakeToCamelCase = snakeToCamelCase;
|
|
201
|
+
function longestCommonPrefix(arr) {
|
|
202
|
+
if (arr.length === 0) {
|
|
203
|
+
return "";
|
|
204
|
+
}
|
|
205
|
+
let prefix = "";
|
|
206
|
+
for (let pos = 0; pos < arr[0].length; pos++) {
|
|
207
|
+
if (arr.every((s) => s.charAt(pos) === arr[0][pos])) {
|
|
208
|
+
prefix += arr[0][pos];
|
|
72
209
|
}
|
|
210
|
+
else
|
|
211
|
+
break;
|
|
73
212
|
}
|
|
74
|
-
return
|
|
213
|
+
return prefix;
|
|
75
214
|
}
|
|
215
|
+
exports.longestCommonPrefix = longestCommonPrefix;
|