firebase-tools-with-isolate 13.7.3 → 13.11.2
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 +18 -8
- package/lib/apiv2.js +19 -13
- package/lib/apphosting/app.js +40 -59
- package/lib/apphosting/constants.js +2 -2
- package/lib/apphosting/githubConnections.js +7 -9
- package/lib/apphosting/index.js +122 -58
- package/lib/apphosting/repo.js +3 -3
- package/lib/apphosting/secrets/index.js +7 -1
- package/lib/checkValidTargetFilters.js +8 -1
- package/lib/commands/apphosting-backends-create.js +7 -6
- package/lib/commands/apphosting-backends-delete.js +24 -28
- package/lib/commands/apphosting-backends-list.js +4 -5
- package/lib/commands/apphosting-secrets-access.js +1 -1
- package/lib/commands/apphosting-secrets-grantaccess.js +11 -7
- package/lib/commands/apphosting-secrets-set.js +1 -1
- package/lib/commands/dataconnect-sdk-generate.js +43 -0
- package/lib/commands/dataconnect-services-list.js +74 -0
- package/lib/commands/dataconnect-sql-diff.js +25 -0
- package/lib/commands/dataconnect-sql-migrate.js +44 -0
- package/lib/commands/deploy.js +27 -1
- package/lib/commands/index.js +11 -0
- package/lib/commands/init.js +10 -3
- package/lib/commands/setup-emulators-dataconnect.js +12 -0
- package/lib/config.js +1 -0
- package/lib/crashlytics/buildToolsJarHelper.js +2 -1
- package/lib/dataconnect/build.js +14 -0
- package/lib/dataconnect/checkIam.js +30 -0
- package/lib/dataconnect/client.js +104 -0
- package/lib/dataconnect/dataplaneClient.js +16 -0
- package/lib/dataconnect/ensureApis.js +12 -0
- package/lib/dataconnect/errors.js +37 -0
- package/lib/dataconnect/fileUtils.js +92 -0
- package/lib/dataconnect/filters.js +45 -0
- package/lib/dataconnect/freeTrial.js +22 -0
- package/lib/dataconnect/graphqlError.js +15 -0
- package/lib/dataconnect/load.js +40 -0
- package/lib/dataconnect/names.js +66 -0
- package/lib/dataconnect/prompts.js +20 -0
- package/lib/dataconnect/provisionCloudSql.js +91 -0
- package/lib/dataconnect/schemaMigration.js +278 -0
- package/lib/dataconnect/types.js +22 -0
- package/lib/deploy/dataconnect/deploy.js +76 -0
- package/lib/deploy/dataconnect/index.js +9 -0
- package/lib/deploy/dataconnect/prepare.js +33 -0
- package/lib/deploy/dataconnect/release.js +64 -0
- package/lib/deploy/functions/checkIam.js +4 -34
- package/lib/deploy/functions/prepare.js +1 -1
- package/lib/deploy/functions/release/fabricator.js +7 -2
- package/lib/deploy/functions/runtimes/discovery/index.js +2 -1
- package/lib/deploy/functions/runtimes/supported/types.js +6 -0
- package/lib/deploy/index.js +2 -0
- package/lib/downloadUtils.js +2 -2
- package/lib/emulator/constants.js +3 -0
- package/lib/emulator/controller.js +40 -12
- package/lib/emulator/dataconnectEmulator.js +137 -0
- package/lib/emulator/download.js +5 -1
- package/lib/emulator/downloadableEmulators.js +92 -16
- package/lib/emulator/portUtils.js +13 -4
- package/lib/emulator/registry.js +6 -1
- package/lib/emulator/storage/rules/runtime.js +1 -1
- package/lib/emulator/types.js +3 -0
- package/lib/experiments.js +19 -6
- package/lib/extensions/emulator/specHelper.js +5 -39
- package/lib/frameworks/angular/utils.js +8 -3
- package/lib/frameworks/next/index.js +6 -4
- package/lib/frameworks/next/utils.js +1 -1
- package/lib/functions/python.js +4 -3
- package/lib/gcp/apphosting.js +11 -1
- package/lib/gcp/cloudsql/cloudsqladmin.js +187 -0
- package/lib/gcp/cloudsql/connect.js +144 -0
- package/lib/gcp/cloudsql/fbToolsAuthClient.js +44 -0
- package/lib/gcp/devConnect.js +1 -1
- package/lib/gcp/firedata.js +27 -0
- package/lib/gcp/iam.js +33 -1
- package/lib/gcp/secretManager.js +1 -1
- package/lib/hosting/interactive.js +4 -0
- package/lib/init/features/dataconnect/index.js +228 -0
- package/lib/init/features/emulators.js +13 -1
- package/lib/init/features/functions/index.js +19 -3
- package/lib/init/features/functions/npm-dependencies.js +12 -23
- package/lib/init/features/genkit.js +53 -0
- package/lib/init/features/index.js +5 -1
- package/lib/init/index.js +2 -0
- package/lib/init/spawn.js +23 -0
- package/lib/logger.js +22 -2
- package/lib/operation-poller.js +8 -2
- package/lib/rc.js +7 -1
- package/lib/requireAuth.js +4 -8
- package/lib/requireTosAcceptance.js +22 -0
- package/lib/track.js +29 -2
- package/lib/utils.js +55 -4
- package/package.json +10 -4
- package/schema/connector-yaml.json +54 -0
- package/schema/dataconnect-yaml.json +72 -0
- package/schema/firebase-config.json +105 -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/init/dataconnect/connector.yaml +2 -0
- package/templates/init/dataconnect/dataconnect.yaml +10 -0
- package/templates/init/dataconnect/mutations.gql +30 -0
- package/templates/init/dataconnect/queries.gql +51 -0
- package/templates/init/dataconnect/schema.gql +28 -0
- package/templates/init/functions/javascript/_gitignore +2 -1
- package/templates/init/functions/javascript/package.lint.json +2 -2
- package/templates/init/functions/javascript/package.nolint.json +2 -2
- package/templates/init/functions/python/_gitignore +1 -0
- package/templates/init/functions/typescript/_gitignore +1 -0
- package/templates/init/functions/typescript/package.lint.json +2 -2
- package/templates/init/functions/typescript/package.nolint.json +2 -2
- package/lib/monospace/index.js +0 -82
- /package/lib/{monospace/interfaces.js → gcp/cloudsql/types.js} +0 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrateSchema = exports.diffSchema = void 0;
|
|
4
|
+
const clc = require("colorette");
|
|
5
|
+
const sql_formatter_1 = require("sql-formatter");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
const client_1 = require("./client");
|
|
8
|
+
const connect_1 = require("../gcp/cloudsql/connect");
|
|
9
|
+
const prompt_1 = require("../prompt");
|
|
10
|
+
const logger_1 = require("../logger");
|
|
11
|
+
const error_1 = require("../error");
|
|
12
|
+
const projectUtils_1 = require("../projectUtils");
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
|
+
const errors = require("./errors");
|
|
15
|
+
async function diffSchema(schema) {
|
|
16
|
+
const { serviceName, instanceName, databaseId } = getIdentifiers(schema);
|
|
17
|
+
await ensureServiceIsConnectedToCloudSql(serviceName, instanceName, databaseId, false);
|
|
18
|
+
try {
|
|
19
|
+
await (0, client_1.upsertSchema)(schema, true);
|
|
20
|
+
(0, utils_1.logLabeledSuccess)("dataconnect", `Database schema is up to date.`);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
if (err.status !== 400) {
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
const invalidConnectors = errors.getInvalidConnectors(err);
|
|
27
|
+
const incompatible = errors.getIncompatibleSchemaError(err);
|
|
28
|
+
if (!incompatible && !invalidConnectors.length) {
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
if (invalidConnectors.length) {
|
|
32
|
+
displayInvalidConnectors(invalidConnectors);
|
|
33
|
+
}
|
|
34
|
+
if (incompatible) {
|
|
35
|
+
displaySchemaChanges(incompatible);
|
|
36
|
+
return incompatible.diffs;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
exports.diffSchema = diffSchema;
|
|
42
|
+
async function migrateSchema(args) {
|
|
43
|
+
const { options, schema, validateOnly } = args;
|
|
44
|
+
const { serviceName, instanceId, instanceName, databaseId } = getIdentifiers(schema);
|
|
45
|
+
await ensureServiceIsConnectedToCloudSql(serviceName, instanceName, databaseId, true);
|
|
46
|
+
try {
|
|
47
|
+
await (0, client_1.upsertSchema)(schema, validateOnly);
|
|
48
|
+
logger_1.logger.debug(`Database schema was up to date for ${instanceId}:${databaseId}`);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if (err.status !== 400) {
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
const incompatible = errors.getIncompatibleSchemaError(err);
|
|
55
|
+
const invalidConnectors = errors.getInvalidConnectors(err);
|
|
56
|
+
if (!incompatible && !invalidConnectors.length) {
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
const migrationMode = await promptForSchemaMigration(options, databaseId, incompatible, validateOnly);
|
|
60
|
+
const shouldDeleteInvalidConnectors = await promptForInvalidConnectorError(options, serviceName, invalidConnectors, validateOnly);
|
|
61
|
+
let diffs = [];
|
|
62
|
+
if (incompatible) {
|
|
63
|
+
diffs = await handleIncompatibleSchemaError({
|
|
64
|
+
options,
|
|
65
|
+
databaseId,
|
|
66
|
+
instanceId,
|
|
67
|
+
incompatibleSchemaError: incompatible,
|
|
68
|
+
choice: migrationMode,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (shouldDeleteInvalidConnectors) {
|
|
72
|
+
await deleteInvalidConnectors(invalidConnectors);
|
|
73
|
+
}
|
|
74
|
+
if (!validateOnly) {
|
|
75
|
+
await (0, client_1.upsertSchema)(schema, validateOnly);
|
|
76
|
+
}
|
|
77
|
+
return diffs;
|
|
78
|
+
}
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
exports.migrateSchema = migrateSchema;
|
|
82
|
+
function getIdentifiers(schema) {
|
|
83
|
+
const databaseId = schema.primaryDatasource.postgresql?.database;
|
|
84
|
+
if (!databaseId) {
|
|
85
|
+
throw new error_1.FirebaseError("Schema is missing primaryDatasource.postgresql?.database, cannot migrate");
|
|
86
|
+
}
|
|
87
|
+
const instanceName = schema.primaryDatasource.postgresql?.cloudSql.instance;
|
|
88
|
+
if (!instanceName) {
|
|
89
|
+
throw new error_1.FirebaseError("tried to migrate schema but instance name was not provided in dataconnect.yaml");
|
|
90
|
+
}
|
|
91
|
+
const instanceId = instanceName.split("/").pop();
|
|
92
|
+
const serviceName = schema.name.replace(`/schemas/${types_1.SCHEMA_ID}`, "");
|
|
93
|
+
return {
|
|
94
|
+
databaseId,
|
|
95
|
+
instanceId,
|
|
96
|
+
instanceName,
|
|
97
|
+
serviceName,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function suggestedCommand(serviceName, invalidConnectorNames) {
|
|
101
|
+
const serviceId = serviceName.split("/")[5];
|
|
102
|
+
const connectorIds = invalidConnectorNames.map((i) => i.split("/")[7]);
|
|
103
|
+
const onlys = connectorIds.map((c) => `dataconnect:${serviceId}:${c}`).join(",");
|
|
104
|
+
return `firebase deploy --only ${onlys}`;
|
|
105
|
+
}
|
|
106
|
+
async function handleIncompatibleSchemaError(args) {
|
|
107
|
+
const { incompatibleSchemaError, options, instanceId, databaseId, choice } = args;
|
|
108
|
+
if (incompatibleSchemaError.destructive && choice === "safe") {
|
|
109
|
+
throw new error_1.FirebaseError("This schema migration includes potentially destructive changes. If you'd like to execute it anyway, rerun this command with --force");
|
|
110
|
+
}
|
|
111
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
112
|
+
const iamUser = await (0, connect_1.setupIAMUser)(instanceId, databaseId, options);
|
|
113
|
+
const commandsToExecute = incompatibleSchemaError.diffs
|
|
114
|
+
.filter((d) => {
|
|
115
|
+
switch (choice) {
|
|
116
|
+
case "all":
|
|
117
|
+
return true;
|
|
118
|
+
case "safe":
|
|
119
|
+
return !d.destructive;
|
|
120
|
+
case "none":
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
.map((d) => d.sql);
|
|
125
|
+
if (commandsToExecute.length) {
|
|
126
|
+
await (0, connect_1.execute)([
|
|
127
|
+
`SET ROLE "${(0, connect_1.firebaseowner)(databaseId)}"`,
|
|
128
|
+
...commandsToExecute,
|
|
129
|
+
`GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA "public" TO PUBLIC`,
|
|
130
|
+
], {
|
|
131
|
+
projectId,
|
|
132
|
+
instanceId,
|
|
133
|
+
databaseId,
|
|
134
|
+
username: iamUser,
|
|
135
|
+
});
|
|
136
|
+
return incompatibleSchemaError.diffs;
|
|
137
|
+
}
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
async function promptForSchemaMigration(options, databaseName, err, validateOnly) {
|
|
141
|
+
if (!err) {
|
|
142
|
+
return "none";
|
|
143
|
+
}
|
|
144
|
+
displaySchemaChanges(err);
|
|
145
|
+
if (!options.nonInteractive) {
|
|
146
|
+
if (validateOnly && options.force) {
|
|
147
|
+
return "all";
|
|
148
|
+
}
|
|
149
|
+
const choices = err.destructive
|
|
150
|
+
? [
|
|
151
|
+
{ name: "Execute all changes (including destructive changes)", value: "all" },
|
|
152
|
+
{ name: "Abort changes", value: "none" },
|
|
153
|
+
]
|
|
154
|
+
: [
|
|
155
|
+
{ name: "Execute changes", value: "all" },
|
|
156
|
+
{ name: "Abort changes", value: "none" },
|
|
157
|
+
];
|
|
158
|
+
return await (0, prompt_1.promptOnce)({
|
|
159
|
+
message: `Would you like to execute these changes against ${databaseName}?`,
|
|
160
|
+
type: "list",
|
|
161
|
+
choices,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (!validateOnly) {
|
|
165
|
+
throw new error_1.FirebaseError("Command aborted. Your database schema is incompatible with your Data Connect schema. Run `firebase dataconnect:sql:migrate` to migrate your database schema");
|
|
166
|
+
}
|
|
167
|
+
else if (options.force) {
|
|
168
|
+
return "all";
|
|
169
|
+
}
|
|
170
|
+
else if (!err.destructive) {
|
|
171
|
+
return "all";
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
throw new error_1.FirebaseError("Command aborted. This schema migration includes potentially destructive changes. If you'd like to execute it anyway, rerun this command with --force");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async function promptForInvalidConnectorError(options, serviceName, invalidConnectors, validateOnly) {
|
|
178
|
+
if (!invalidConnectors.length) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
displayInvalidConnectors(invalidConnectors);
|
|
182
|
+
if (validateOnly) {
|
|
183
|
+
if (options.force) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
throw new error_1.FirebaseError(`Command aborted. If you'd like to migrate it anyway, you may override with --force.`);
|
|
187
|
+
}
|
|
188
|
+
if (options.force) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
if (!options.nonInteractive &&
|
|
192
|
+
(await (0, prompt_1.confirm)({
|
|
193
|
+
...options,
|
|
194
|
+
message: `Would you like to delete and recreate these connectors? This will cause ${clc.red(`downtime.`)}.`,
|
|
195
|
+
}))) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
const cmd = suggestedCommand(serviceName, invalidConnectors);
|
|
199
|
+
throw new error_1.FirebaseError(`Command aborted. Try deploying those connectors first with ${clc.bold(cmd)}`);
|
|
200
|
+
}
|
|
201
|
+
async function deleteInvalidConnectors(invalidConnectors) {
|
|
202
|
+
return Promise.all(invalidConnectors.map(client_1.deleteConnector));
|
|
203
|
+
}
|
|
204
|
+
function displayInvalidConnectors(invalidConnectors) {
|
|
205
|
+
const connectorIds = invalidConnectors.map((i) => i.split("/").pop()).join(", ");
|
|
206
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `The schema you are deploying is incompatible with the following existing connectors: ${connectorIds}.`);
|
|
207
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `This is a ${clc.red("breaking")} change and may break existing apps.`);
|
|
208
|
+
}
|
|
209
|
+
async function ensureServiceIsConnectedToCloudSql(serviceName, instanceId, databaseId, linkIfNotConnected) {
|
|
210
|
+
let currentSchema = await (0, client_1.getSchema)(serviceName);
|
|
211
|
+
if (!currentSchema) {
|
|
212
|
+
if (!linkIfNotConnected) {
|
|
213
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `Not yet linked to the Cloud SQL instance.`);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
(0, utils_1.logLabeledBullet)("dataconnect", `Linking the Cloud SQL instance...`);
|
|
217
|
+
currentSchema = {
|
|
218
|
+
name: `${serviceName}/schemas/${types_1.SCHEMA_ID}`,
|
|
219
|
+
source: {
|
|
220
|
+
files: [],
|
|
221
|
+
},
|
|
222
|
+
primaryDatasource: {
|
|
223
|
+
postgresql: {
|
|
224
|
+
database: databaseId,
|
|
225
|
+
cloudSql: {
|
|
226
|
+
instance: instanceId,
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
const postgresql = currentSchema.primaryDatasource.postgresql;
|
|
233
|
+
if (postgresql?.cloudSql.instance !== instanceId) {
|
|
234
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `Switching connected Cloud SQL instance\nFrom ${postgresql?.cloudSql.instance}\nTo ${instanceId}`);
|
|
235
|
+
}
|
|
236
|
+
if (postgresql?.database !== databaseId) {
|
|
237
|
+
(0, utils_1.logLabeledWarning)("dataconnect", `Switching connected Postgres database from ${postgresql?.database} to ${databaseId}`);
|
|
238
|
+
}
|
|
239
|
+
if (!postgresql || postgresql.schemaValidation === "STRICT") {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
postgresql.schemaValidation = "STRICT";
|
|
243
|
+
try {
|
|
244
|
+
await (0, client_1.upsertSchema)(currentSchema, false);
|
|
245
|
+
}
|
|
246
|
+
catch (err) {
|
|
247
|
+
if (err.status >= 500) {
|
|
248
|
+
throw err;
|
|
249
|
+
}
|
|
250
|
+
logger_1.logger.debug(err);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function displaySchemaChanges(error) {
|
|
254
|
+
switch (error.violationType) {
|
|
255
|
+
case "INCOMPATIBLE_SCHEMA":
|
|
256
|
+
{
|
|
257
|
+
const message = "Your new schema is incompatible with the schema of your CloudSQL database. " +
|
|
258
|
+
"The following SQL statements will migrate your database schema to match your new Data Connect schema.\n" +
|
|
259
|
+
error.diffs.map(toString).join("\n");
|
|
260
|
+
(0, utils_1.logLabeledWarning)("dataconnect", message);
|
|
261
|
+
}
|
|
262
|
+
break;
|
|
263
|
+
case "INACCESSIBLE_SCHEMA":
|
|
264
|
+
{
|
|
265
|
+
const message = "Cannot access your CloudSQL database to validate schema. " +
|
|
266
|
+
"The following SQL statements can setup a new database schema.\n" +
|
|
267
|
+
error.diffs.map(toString).join("\n");
|
|
268
|
+
(0, utils_1.logLabeledWarning)("dataconnect", message);
|
|
269
|
+
(0, utils_1.logLabeledWarning)("dataconnect", "Some SQL resources may already exist.");
|
|
270
|
+
}
|
|
271
|
+
break;
|
|
272
|
+
default:
|
|
273
|
+
throw new error_1.FirebaseError(`Unknown schema violation type: ${error.violationType}, IncompatibleSqlSchemaError: ${error}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function toString(diff) {
|
|
277
|
+
return `\/** ${diff.destructive ? clc.red("Destructive: ") : ""}${diff.description}*\/\n${(0, sql_formatter_1.format)(diff.sql, { language: "postgresql" })}`;
|
|
278
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toDatasource = exports.requiresVector = exports.SCHEMA_ID = void 0;
|
|
4
|
+
exports.SCHEMA_ID = "main";
|
|
5
|
+
function requiresVector(dm) {
|
|
6
|
+
return dm?.primaryDataSource?.postgres?.requiredExtensions?.includes("vector") ?? false;
|
|
7
|
+
}
|
|
8
|
+
exports.requiresVector = requiresVector;
|
|
9
|
+
function toDatasource(projectId, locationId, ds) {
|
|
10
|
+
if (ds.postgresql) {
|
|
11
|
+
return {
|
|
12
|
+
postgresql: {
|
|
13
|
+
database: ds.postgresql.database,
|
|
14
|
+
cloudSql: {
|
|
15
|
+
instance: `projects/${projectId}/locations/${locationId}/instances/${ds.postgresql.cloudSql.instanceId}`,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
exports.toDatasource = toDatasource;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client = require("../../dataconnect/client");
|
|
4
|
+
const utils = require("../../utils");
|
|
5
|
+
const types_1 = require("../../dataconnect/types");
|
|
6
|
+
const projectUtils_1 = require("../../projectUtils");
|
|
7
|
+
const provisionCloudSql_1 = require("../../dataconnect/provisionCloudSql");
|
|
8
|
+
const names_1 = require("../../dataconnect/names");
|
|
9
|
+
const api_1 = require("../../api");
|
|
10
|
+
const ensureApiEnabled = require("../../ensureApiEnabled");
|
|
11
|
+
async function default_1(context, options) {
|
|
12
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
13
|
+
const serviceInfos = context.dataconnect.serviceInfos;
|
|
14
|
+
const services = await client.listAllServices(projectId);
|
|
15
|
+
const filters = context.dataconnect.filters;
|
|
16
|
+
if (serviceInfos.some((si) => {
|
|
17
|
+
return (0, types_1.requiresVector)(si.deploymentMetadata);
|
|
18
|
+
})) {
|
|
19
|
+
await ensureApiEnabled.ensure(projectId, (0, api_1.vertexAIOrigin)(), "dataconnect");
|
|
20
|
+
}
|
|
21
|
+
const servicesToCreate = serviceInfos
|
|
22
|
+
.filter((si) => !services.some((s) => matches(si, s)))
|
|
23
|
+
.filter((si) => {
|
|
24
|
+
return !filters || filters?.some((f) => si.dataConnectYaml.serviceId === f.serviceId);
|
|
25
|
+
});
|
|
26
|
+
const servicesToDelete = filters
|
|
27
|
+
? []
|
|
28
|
+
: services.filter((s) => !serviceInfos.some((si) => matches(si, s)));
|
|
29
|
+
await Promise.all(servicesToCreate.map(async (s) => {
|
|
30
|
+
const { projectId, locationId, serviceId } = splitName(s.serviceName);
|
|
31
|
+
await client.createService(projectId, locationId, serviceId);
|
|
32
|
+
utils.logLabeledSuccess("dataconnect", `Created service ${s.serviceName}`);
|
|
33
|
+
}));
|
|
34
|
+
if (servicesToDelete.length) {
|
|
35
|
+
const warning = `The following services exist on ${projectId} but are not listed in your 'firebase.json'\n${servicesToDelete
|
|
36
|
+
.map((s) => s.name)
|
|
37
|
+
.join("\n")}\nConsider deleting these via the Firebase console if they are no longer needed.`;
|
|
38
|
+
utils.logLabeledWarning("dataconnect", warning);
|
|
39
|
+
}
|
|
40
|
+
utils.logLabeledBullet("dataconnect", "Checking for CloudSQL resources...");
|
|
41
|
+
await Promise.all(serviceInfos
|
|
42
|
+
.filter((si) => {
|
|
43
|
+
return !filters || filters?.some((f) => si.dataConnectYaml.serviceId === f.serviceId);
|
|
44
|
+
})
|
|
45
|
+
.map(async (s) => {
|
|
46
|
+
const instanceId = s.schema.primaryDatasource.postgresql?.cloudSql.instance
|
|
47
|
+
.split("/")
|
|
48
|
+
.pop();
|
|
49
|
+
const databaseId = s.schema.primaryDatasource.postgresql?.database;
|
|
50
|
+
if (!instanceId || !databaseId) {
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
}
|
|
53
|
+
const enableGoogleMlIntegration = (0, types_1.requiresVector)(s.deploymentMetadata);
|
|
54
|
+
return (0, provisionCloudSql_1.provisionCloudSql)({
|
|
55
|
+
projectId,
|
|
56
|
+
locationId: (0, names_1.parseServiceName)(s.serviceName).location,
|
|
57
|
+
instanceId,
|
|
58
|
+
databaseId,
|
|
59
|
+
enableGoogleMlIntegration,
|
|
60
|
+
waitForCreation: true,
|
|
61
|
+
});
|
|
62
|
+
}));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
exports.default = default_1;
|
|
66
|
+
function matches(si, s) {
|
|
67
|
+
return si.serviceName === s.name;
|
|
68
|
+
}
|
|
69
|
+
function splitName(serviceName) {
|
|
70
|
+
const parts = serviceName.split("/");
|
|
71
|
+
return {
|
|
72
|
+
projectId: parts[1],
|
|
73
|
+
locationId: parts[3],
|
|
74
|
+
serviceId: parts[5],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.release = exports.deploy = exports.prepare = void 0;
|
|
4
|
+
const prepare_1 = require("./prepare");
|
|
5
|
+
exports.prepare = prepare_1.default;
|
|
6
|
+
const deploy_1 = require("./deploy");
|
|
7
|
+
exports.deploy = deploy_1.default;
|
|
8
|
+
const release_1 = require("./release");
|
|
9
|
+
exports.release = release_1.default;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const load_1 = require("../../dataconnect/load");
|
|
5
|
+
const fileUtils_1 = require("../../dataconnect/fileUtils");
|
|
6
|
+
const logger_1 = require("../../logger");
|
|
7
|
+
const utils = require("../../utils");
|
|
8
|
+
const projectUtils_1 = require("../../projectUtils");
|
|
9
|
+
const filters_1 = require("../../dataconnect/filters");
|
|
10
|
+
const build_1 = require("../../dataconnect/build");
|
|
11
|
+
const ensureApis_1 = require("../../dataconnect/ensureApis");
|
|
12
|
+
const requireTosAcceptance_1 = require("../../requireTosAcceptance");
|
|
13
|
+
const firedata_1 = require("../../gcp/firedata");
|
|
14
|
+
async function default_1(context, options) {
|
|
15
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
16
|
+
await (0, ensureApis_1.ensureApis)(projectId);
|
|
17
|
+
await (0, requireTosAcceptance_1.requireTosAcceptance)(firedata_1.DATA_CONNECT_TOS_ID)(options);
|
|
18
|
+
const serviceCfgs = (0, fileUtils_1.readFirebaseJson)(options.config);
|
|
19
|
+
utils.logLabeledBullet("dataconnect", `Preparing to deploy`);
|
|
20
|
+
const filters = (0, filters_1.getResourceFilters)(options);
|
|
21
|
+
const serviceInfos = await Promise.all(serviceCfgs.map((c) => (0, load_1.load)(projectId, c.location, path.join(options.cwd || process.cwd(), c.source))));
|
|
22
|
+
for (const si of serviceInfos) {
|
|
23
|
+
si.deploymentMetadata = await (0, build_1.build)(options, si.sourceDirectory);
|
|
24
|
+
}
|
|
25
|
+
context.dataconnect = {
|
|
26
|
+
serviceInfos,
|
|
27
|
+
filters,
|
|
28
|
+
};
|
|
29
|
+
utils.logLabeledBullet("dataconnect", `Successfully prepared schema and connectors`);
|
|
30
|
+
logger_1.logger.debug(JSON.stringify(context.dataconnect, null, 2));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils = require("../../utils");
|
|
4
|
+
const client_1 = require("../../dataconnect/client");
|
|
5
|
+
const prompts_1 = require("../../dataconnect/prompts");
|
|
6
|
+
const schemaMigration_1 = require("../../dataconnect/schemaMigration");
|
|
7
|
+
async function default_1(context, options) {
|
|
8
|
+
const serviceInfos = context.dataconnect.serviceInfos;
|
|
9
|
+
const filters = context.dataconnect.filters;
|
|
10
|
+
const wantSchemas = serviceInfos
|
|
11
|
+
.filter((si) => {
|
|
12
|
+
return (!filters ||
|
|
13
|
+
filters.some((f) => {
|
|
14
|
+
return f.serviceId === si.dataConnectYaml.serviceId && (f.schemaOnly || f.fullService);
|
|
15
|
+
}));
|
|
16
|
+
})
|
|
17
|
+
.map((s) => s.schema);
|
|
18
|
+
if (wantSchemas.length) {
|
|
19
|
+
utils.logLabeledBullet("dataconnect", "Releasing Data Connect schemas...");
|
|
20
|
+
for (const s of wantSchemas) {
|
|
21
|
+
await (0, schemaMigration_1.migrateSchema)({
|
|
22
|
+
options,
|
|
23
|
+
schema: s,
|
|
24
|
+
validateOnly: false,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
utils.logLabeledBullet("dataconnect", "Schemas released.");
|
|
28
|
+
}
|
|
29
|
+
let wantConnectors = [];
|
|
30
|
+
wantConnectors = wantConnectors.concat(...serviceInfos.map((si) => si.connectorInfo
|
|
31
|
+
.filter((c) => {
|
|
32
|
+
return (!filters ||
|
|
33
|
+
filters.some((f) => {
|
|
34
|
+
return (f.serviceId === si.dataConnectYaml.serviceId &&
|
|
35
|
+
(f.connectorId === c.connectorYaml.connectorId || f.fullService));
|
|
36
|
+
}));
|
|
37
|
+
})
|
|
38
|
+
.map((c) => c.connector)));
|
|
39
|
+
const haveConnectors = await have(serviceInfos);
|
|
40
|
+
const connectorsToDelete = filters
|
|
41
|
+
? []
|
|
42
|
+
: haveConnectors.filter((h) => !wantConnectors.some((w) => w.name === h.name));
|
|
43
|
+
if (wantConnectors.length) {
|
|
44
|
+
utils.logLabeledBullet("dataconnect", "Releasing connectors...");
|
|
45
|
+
await Promise.all(wantConnectors.map(async (c) => {
|
|
46
|
+
await (0, client_1.upsertConnector)(c);
|
|
47
|
+
utils.logLabeledSuccess("dataconnect", `Deployed connector ${c.name}`);
|
|
48
|
+
}));
|
|
49
|
+
for (const c of connectorsToDelete) {
|
|
50
|
+
await (0, prompts_1.promptDeleteConnector)(options, c.name);
|
|
51
|
+
}
|
|
52
|
+
utils.logLabeledBullet("dataconnect", "Connectors released.");
|
|
53
|
+
}
|
|
54
|
+
utils.logLabeledSuccess("dataconnect", "Deploy complete!");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
exports.default = default_1;
|
|
58
|
+
async function have(serviceInfos) {
|
|
59
|
+
let connectors = [];
|
|
60
|
+
for (const si of serviceInfos) {
|
|
61
|
+
connectors = connectors.concat(await (0, client_1.listConnectors)(si.serviceName));
|
|
62
|
+
}
|
|
63
|
+
return connectors;
|
|
64
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ensureServiceAgentRoles = exports.
|
|
3
|
+
exports.ensureServiceAgentRoles = exports.obtainDefaultComputeServiceAgentBindings = exports.obtainPubSubServiceAgentBindings = exports.checkHttpIam = exports.checkServiceAccountIam = exports.EVENTARC_EVENT_RECEIVER_ROLE = exports.RUN_INVOKER_ROLE = exports.SERVICE_ACCOUNT_TOKEN_CREATOR_ROLE = void 0;
|
|
4
4
|
const colorette_1 = require("colorette");
|
|
5
5
|
const logger_1 = require("../../logger");
|
|
6
6
|
const functionsDeployHelper_1 = require("./functionsDeployHelper");
|
|
@@ -102,36 +102,6 @@ function obtainDefaultComputeServiceAgentBindings(projectNumber) {
|
|
|
102
102
|
return [runInvokerBinding, eventarcEventReceiverBinding];
|
|
103
103
|
}
|
|
104
104
|
exports.obtainDefaultComputeServiceAgentBindings = obtainDefaultComputeServiceAgentBindings;
|
|
105
|
-
function mergeBindings(policy, requiredBindings) {
|
|
106
|
-
let updated = false;
|
|
107
|
-
for (const requiredBinding of requiredBindings) {
|
|
108
|
-
const match = policy.bindings.find((b) => b.role === requiredBinding.role);
|
|
109
|
-
if (!match) {
|
|
110
|
-
updated = true;
|
|
111
|
-
policy.bindings.push(requiredBinding);
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
for (const requiredMember of requiredBinding.members) {
|
|
115
|
-
if (!match.members.find((m) => m === requiredMember)) {
|
|
116
|
-
updated = true;
|
|
117
|
-
match.members.push(requiredMember);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return updated;
|
|
122
|
-
}
|
|
123
|
-
exports.mergeBindings = mergeBindings;
|
|
124
|
-
function printManualIamConfig(requiredBindings, projectId) {
|
|
125
|
-
utils.logLabeledBullet("functions", "Failed to verify the project has the correct IAM bindings for a successful deployment.", "warn");
|
|
126
|
-
utils.logLabeledBullet("functions", "You can either re-run `firebase deploy` as a project owner or manually run the following set of `gcloud` commands:", "warn");
|
|
127
|
-
for (const binding of requiredBindings) {
|
|
128
|
-
for (const member of binding.members) {
|
|
129
|
-
utils.logLabeledBullet("functions", `\`gcloud projects add-iam-policy-binding ${projectId} ` +
|
|
130
|
-
`--member=${member} ` +
|
|
131
|
-
`--role=${binding.role}\``, "warn");
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
105
|
async function ensureServiceAgentRoles(projectId, projectNumber, want, have) {
|
|
136
106
|
const wantServices = backend.allEndpoints(want).reduce(reduceEventsToServices, []);
|
|
137
107
|
const haveServices = backend.allEndpoints(have).reduce(reduceEventsToServices, []);
|
|
@@ -157,13 +127,13 @@ async function ensureServiceAgentRoles(projectId, projectNumber, want, have) {
|
|
|
157
127
|
policy = await (0, resourceManager_1.getIamPolicy)(projectNumber);
|
|
158
128
|
}
|
|
159
129
|
catch (err) {
|
|
160
|
-
printManualIamConfig(requiredBindings, projectId);
|
|
130
|
+
iam.printManualIamConfig(requiredBindings, projectId, "functions");
|
|
161
131
|
utils.logLabeledBullet("functions", "Could not verify the necessary IAM configuration for the following newly-integrated services: " +
|
|
162
132
|
`${newServices.map((service) => service.api).join(", ")}` +
|
|
163
133
|
". Deployment may fail.", "warn");
|
|
164
134
|
return;
|
|
165
135
|
}
|
|
166
|
-
const hasUpdatedBindings = mergeBindings(policy, requiredBindings);
|
|
136
|
+
const hasUpdatedBindings = iam.mergeBindings(policy, requiredBindings);
|
|
167
137
|
if (!hasUpdatedBindings) {
|
|
168
138
|
return;
|
|
169
139
|
}
|
|
@@ -171,7 +141,7 @@ async function ensureServiceAgentRoles(projectId, projectNumber, want, have) {
|
|
|
171
141
|
await (0, resourceManager_1.setIamPolicy)(projectNumber, policy, "bindings");
|
|
172
142
|
}
|
|
173
143
|
catch (err) {
|
|
174
|
-
printManualIamConfig(requiredBindings, projectId);
|
|
144
|
+
iam.printManualIamConfig(requiredBindings, projectId, "functions");
|
|
175
145
|
throw new error_1.FirebaseError("We failed to modify the IAM policy for the project. The functions " +
|
|
176
146
|
"deployment requires specific roles to be granted to service agents," +
|
|
177
147
|
" otherwise the deployment will fail.", { original: err });
|
|
@@ -290,7 +290,7 @@ async function loadCodebases(config, options, firebaseConfig, runtimeConfig, fil
|
|
|
290
290
|
const firebaseJsonRuntime = codebaseConfig.runtime;
|
|
291
291
|
if (firebaseJsonRuntime && !supported.isRuntime(firebaseJsonRuntime)) {
|
|
292
292
|
throw new error_1.FirebaseError(`Functions codebase ${codebase} has invalid runtime ` +
|
|
293
|
-
`${firebaseJsonRuntime} specified in firebase.json. Valid values are: ` +
|
|
293
|
+
`${firebaseJsonRuntime} specified in firebase.json. Valid values are: \n` +
|
|
294
294
|
Object.keys(supported.RUNTIMES)
|
|
295
295
|
.map((s) => `- ${s}`)
|
|
296
296
|
.join("\n"));
|
|
@@ -16,6 +16,7 @@ const deploymentTool = require("../../../deploymentTool");
|
|
|
16
16
|
const gcf = require("../../../gcp/cloudfunctions");
|
|
17
17
|
const gcfV2 = require("../../../gcp/cloudfunctionsv2");
|
|
18
18
|
const eventarc = require("../../../gcp/eventarc");
|
|
19
|
+
const experiments = require("../../../experiments");
|
|
19
20
|
const helper = require("../functionsDeployHelper");
|
|
20
21
|
const poller = require("../../../operation-poller");
|
|
21
22
|
const pubsub = require("../../../gcp/pubsub");
|
|
@@ -283,7 +284,9 @@ class Fabricator {
|
|
|
283
284
|
while (!resultFunction) {
|
|
284
285
|
resultFunction = await this.functionExecutor
|
|
285
286
|
.run(async () => {
|
|
286
|
-
|
|
287
|
+
if (experiments.isEnabled("functionsv2deployoptimizations")) {
|
|
288
|
+
apiFunction.buildConfig.sourceToken = await scraper.getToken();
|
|
289
|
+
}
|
|
287
290
|
const op = await gcfV2.createFunction(apiFunction);
|
|
288
291
|
return await poller.pollOperation({
|
|
289
292
|
...gcfV2PollerOptions,
|
|
@@ -399,7 +402,9 @@ class Fabricator {
|
|
|
399
402
|
}
|
|
400
403
|
const resultFunction = await this.functionExecutor
|
|
401
404
|
.run(async () => {
|
|
402
|
-
|
|
405
|
+
if (experiments.isEnabled("functionsv2deployoptimizations")) {
|
|
406
|
+
apiFunction.buildConfig.sourceToken = await scraper.getToken();
|
|
407
|
+
}
|
|
403
408
|
const op = await gcfV2.updateFunction(apiFunction);
|
|
404
409
|
return await poller.pollOperation({
|
|
405
410
|
...gcfV2PollerOptions,
|
|
@@ -11,6 +11,7 @@ const api = require("../../.../../../../api");
|
|
|
11
11
|
const v1alpha1 = require("./v1alpha1");
|
|
12
12
|
const error_1 = require("../../../../error");
|
|
13
13
|
exports.readFileAsync = (0, util_1.promisify)(fs.readFile);
|
|
14
|
+
const TIMEOUT_OVERRIDE_ENV_VAR = "FUNCTIONS_DISCOVERY_TIMEOUT";
|
|
14
15
|
function yamlToBuild(yaml, project, region, runtime) {
|
|
15
16
|
try {
|
|
16
17
|
if (!yaml.specVersion) {
|
|
@@ -50,7 +51,7 @@ async function detectFromPort(port, project, runtime, timeout = 10000) {
|
|
|
50
51
|
const timedOut = new Promise((resolve, reject) => {
|
|
51
52
|
setTimeout(() => {
|
|
52
53
|
reject(new error_1.FirebaseError("User code failed to load. Cannot determine backend specification"));
|
|
53
|
-
}, timeout);
|
|
54
|
+
}, +(process.env[TIMEOUT_OVERRIDE_ENV_VAR] || 0) * 1000 || timeout);
|
|
54
55
|
});
|
|
55
56
|
while (true) {
|
|
56
57
|
try {
|
|
@@ -53,6 +53,12 @@ exports.RUNTIMES = runtimes({
|
|
|
53
53
|
deprecationDate: "2026-04-30",
|
|
54
54
|
decommissionDate: "2026-10-31",
|
|
55
55
|
},
|
|
56
|
+
nodejs22: {
|
|
57
|
+
friendly: "Node.js 22",
|
|
58
|
+
status: "beta",
|
|
59
|
+
deprecationDate: "2027-04-30",
|
|
60
|
+
decommissionDate: "2027-10-31",
|
|
61
|
+
},
|
|
56
62
|
python310: {
|
|
57
63
|
friendly: "Python 3.10",
|
|
58
64
|
status: "GA",
|
package/lib/deploy/index.js
CHANGED
|
@@ -19,6 +19,7 @@ const FunctionsTarget = require("./functions");
|
|
|
19
19
|
const StorageTarget = require("./storage");
|
|
20
20
|
const RemoteConfigTarget = require("./remoteconfig");
|
|
21
21
|
const ExtensionsTarget = require("./extensions");
|
|
22
|
+
const DataConnectTarget = require("./dataconnect");
|
|
22
23
|
const frameworks_1 = require("../frameworks");
|
|
23
24
|
const prepare_1 = require("./hosting/prepare");
|
|
24
25
|
const github_1 = require("../init/features/hosting/github");
|
|
@@ -32,6 +33,7 @@ const TARGETS = {
|
|
|
32
33
|
storage: StorageTarget,
|
|
33
34
|
remoteconfig: RemoteConfigTarget,
|
|
34
35
|
extensions: ExtensionsTarget,
|
|
36
|
+
dataconnect: DataConnectTarget,
|
|
35
37
|
};
|
|
36
38
|
const chain = async function (fns, context, options, payload) {
|
|
37
39
|
for (const latest of fns) {
|
package/lib/downloadUtils.js
CHANGED
|
@@ -7,9 +7,9 @@ const ProgressBar = require("progress");
|
|
|
7
7
|
const tmp = require("tmp");
|
|
8
8
|
const apiv2_1 = require("./apiv2");
|
|
9
9
|
const error_1 = require("./error");
|
|
10
|
-
async function downloadToTmp(remoteUrl) {
|
|
10
|
+
async function downloadToTmp(remoteUrl, auth = false) {
|
|
11
11
|
const u = new url_1.URL(remoteUrl);
|
|
12
|
-
const c = new apiv2_1.Client({ urlPrefix: u.origin, auth
|
|
12
|
+
const c = new apiv2_1.Client({ urlPrefix: u.origin, auth });
|
|
13
13
|
const tmpfile = tmp.fileSync();
|
|
14
14
|
const writeStream = fs.createWriteStream(tmpfile.name);
|
|
15
15
|
const res = await c.request({
|