firebase-tools 15.30.0 → 15.30.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/commands/ext-export.js +10 -1
- package/lib/commands/ext-migrate.js +11 -5
- package/lib/commands/ext-uninstall.js +40 -1
- package/lib/commands/functions-kits-install.js +4 -1
- package/lib/commands/functions-kits-uninstall.js +2 -1
- package/lib/deploy/functions/build.js +53 -19
- package/lib/deploy/functions/ensure.js +42 -2
- package/lib/deploy/functions/functionsDeployHelper.js +7 -0
- package/lib/deploy/functions/params.js +37 -61
- package/lib/deploy/functions/prepare.js +8 -6
- package/lib/deploy/functions/release/planner.js +2 -4
- package/lib/emulator/auth/cloudFunctions.js +40 -5
- package/lib/emulator/downloadableEmulatorInfo.json +31 -31
- package/lib/emulator/functionsEmulator.js +13 -4
- package/lib/emulator/functionsEmulatorShared.js +14 -3
- package/lib/experiments.js +1 -1
- package/lib/extensions/export.js +63 -1
- package/lib/extensions/migrate.js +16 -2
- package/lib/fsutils.js +20 -2
- package/lib/functions/env.js +21 -4
- package/lib/functions/kits/install.js +162 -80
- package/lib/gcp/iam.js +8 -17
- package/lib/prompt.js +4 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/templates/init/functions/typescript/tsconfig.json +2 -1
|
@@ -57,8 +57,7 @@ async function discoverSecurityDetails(codebase, want, have, projectId, filters)
|
|
|
57
57
|
const requiredRoles = want.requiredRoles;
|
|
58
58
|
const existingManagedSA = backend.findEndpoint(have, (e) => typeof e.serviceAccount === "string" && e.serviceAccount.startsWith("firebase-fn-"))?.serviceAccount ?? undefined;
|
|
59
59
|
const haveRolesEtag = backend.findEndpoint(have, (e) => !!e.labels?.[exports.DECLARATIVE_SECURITY_ETAG_LABEL])?.labels?.[exports.DECLARATIVE_SECURITY_ETAG_LABEL];
|
|
60
|
-
const isPartiallyFiltered =
|
|
61
|
-
filters.some((f) => (!f.codebase || f.codebase === codebase) && f.idChunks && f.idChunks.length > 0));
|
|
60
|
+
const isPartiallyFiltered = (0, functionsDeployHelper_1.isCodebasePartiallyFiltered)(codebase, filters);
|
|
62
61
|
const isEnrolling = !!requiredRoles && !existingManagedSA;
|
|
63
62
|
const isUnenrolling = !requiredRoles && !!existingManagedSA && !!haveRolesEtag;
|
|
64
63
|
if (isPartiallyFiltered && (isEnrolling || isUnenrolling)) {
|
|
@@ -95,13 +94,13 @@ async function discoverSecurityDetails(codebase, want, have, projectId, filters)
|
|
|
95
94
|
existingManagedSA,
|
|
96
95
|
};
|
|
97
96
|
}
|
|
97
|
+
await ensure.checkDeclarativeSecurityApisEnabled(projectId, codebase);
|
|
98
98
|
let managedSA = existingManagedSA;
|
|
99
99
|
if (!managedSA) {
|
|
100
100
|
const saToCreate = await iam.generateManagedServiceAccountName(projectId, "firebase-fn");
|
|
101
101
|
managedSA = `${saToCreate}@${projectId}.iam.gserviceaccount.com`;
|
|
102
102
|
}
|
|
103
|
-
const
|
|
104
|
-
const newEtag = iam.computeRolesEtag(requiredRoles, existingSalt);
|
|
103
|
+
const newEtag = iam.computeRolesEtag(requiredRoles);
|
|
105
104
|
for (const endpoint of backend.allEndpoints(want)) {
|
|
106
105
|
endpoint.serviceAccount = managedSA;
|
|
107
106
|
endpoint.labels = endpoint.labels || {};
|
|
@@ -212,7 +211,7 @@ async function prepare(context, options, payload) {
|
|
|
212
211
|
.filter((e) => e.codebase === codebase || e.codebase === undefined);
|
|
213
212
|
await resolveDefaultRegionsForBuild(wantBuild, backend.of(...relevantEndpoints));
|
|
214
213
|
const parsedSecretRefs = (0, functional_1.mapObject)(secretRefs, (unparsed) => build.parseSecretRef(unparsed));
|
|
215
|
-
build.
|
|
214
|
+
await build.applyEnvSecretBindingsToBuild(wantBuild, parsedSecretRefs);
|
|
216
215
|
const { backend: wantBackend, envs: resolvedEnvs, secretRefs: resolvedSecretRefs, } = await build.resolveBackend({
|
|
217
216
|
build: wantBuild,
|
|
218
217
|
firebaseConfig,
|
|
@@ -538,7 +537,10 @@ async function loadCodebases(config, options, firebaseConfig, runtimeConfig, fil
|
|
|
538
537
|
const prefix = (0, projectConfig_1.isKitConfig)(codebaseConfig)
|
|
539
538
|
? (0, projectConfig_1.addKitPrefix)(codebase)
|
|
540
539
|
: codebaseConfig.prefix || "";
|
|
541
|
-
build.
|
|
540
|
+
build.applyEndpointPrefix(discoveredBuild, prefix);
|
|
541
|
+
if ((0, projectConfig_1.isKitConfig)(codebaseConfig)) {
|
|
542
|
+
build.applyKitSecretRefPrefix(discoveredBuild, codebase);
|
|
543
|
+
}
|
|
542
544
|
wantBuilds[codebase] = discoveredBuild;
|
|
543
545
|
}
|
|
544
546
|
return wantBuilds;
|
|
@@ -84,9 +84,7 @@ async function createDeploymentPlan(args) {
|
|
|
84
84
|
let rolesToRemove;
|
|
85
85
|
let serviceAccountToCreate;
|
|
86
86
|
let serviceAccountToDelete;
|
|
87
|
-
const
|
|
88
|
-
filters.some((f) => f.idChunks && f.idChunks.length > 0) &&
|
|
89
|
-
!deleteAll);
|
|
87
|
+
const isPartiallyFiltered = (0, functionsDeployHelper_1.isCodebasePartiallyFiltered)(codebase, filters);
|
|
90
88
|
const hasWantEndpoints = backend.someEndpoint(wantBackend, () => true);
|
|
91
89
|
if (requiredRoles && hasWantEndpoints) {
|
|
92
90
|
rolesToAdd = requiredRoles.filter((r) => !roles.includes(r));
|
|
@@ -95,7 +93,7 @@ async function createDeploymentPlan(args) {
|
|
|
95
93
|
serviceAccountToCreate = managedSA;
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
|
-
else if (existingManagedSA && !
|
|
96
|
+
else if (existingManagedSA && (!isPartiallyFiltered || deleteAll)) {
|
|
99
97
|
serviceAccountToDelete = existingManagedSA;
|
|
100
98
|
}
|
|
101
99
|
wantBackend = backend.matchingBackend(wantBackend, (endpoint) => {
|
|
@@ -5,6 +5,10 @@ const crypto_1 = require("crypto");
|
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const emulatorLogger_1 = require("../emulatorLogger");
|
|
7
7
|
const registry_1 = require("../registry");
|
|
8
|
+
const AUTH_V2_ACTION_MAP = {
|
|
9
|
+
create: "created",
|
|
10
|
+
delete: "deleted",
|
|
11
|
+
};
|
|
8
12
|
class AuthCloudFunction {
|
|
9
13
|
constructor(projectId) {
|
|
10
14
|
this.projectId = projectId;
|
|
@@ -16,17 +20,32 @@ class AuthCloudFunction {
|
|
|
16
20
|
if (!this.enabled)
|
|
17
21
|
return;
|
|
18
22
|
const userInfoPayload = this.createUserInfoPayload(user);
|
|
19
|
-
const
|
|
23
|
+
const legacyEventBody = this.createEventRequestBody(action, userInfoPayload);
|
|
24
|
+
const v2CloudEventBody = this.createCloudEventRequestBody(action, userInfoPayload);
|
|
20
25
|
const c = registry_1.EmulatorRegistry.client(types_1.Emulators.FUNCTIONS);
|
|
21
|
-
|
|
26
|
+
const errStatus = [];
|
|
22
27
|
let err;
|
|
23
28
|
try {
|
|
24
|
-
|
|
29
|
+
const legacyRes = await c.post(`/functions/projects/${this.projectId}/trigger_multicast`, legacyEventBody);
|
|
30
|
+
if (legacyRes.status !== 200) {
|
|
31
|
+
errStatus.push(legacyRes.status);
|
|
32
|
+
}
|
|
25
33
|
}
|
|
26
34
|
catch (e) {
|
|
27
|
-
err = e;
|
|
35
|
+
err = e instanceof Error ? e : new Error(String(e));
|
|
28
36
|
}
|
|
29
|
-
|
|
37
|
+
try {
|
|
38
|
+
const v2Res = await c.post(`/functions/projects/${this.projectId}/trigger_multicast`, v2CloudEventBody, {
|
|
39
|
+
headers: { "Content-Type": "application/cloudevents+json; charset=UTF-8" },
|
|
40
|
+
});
|
|
41
|
+
if (v2Res.status !== 200) {
|
|
42
|
+
errStatus.push(v2Res.status);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
err = e instanceof Error ? e : new Error(String(e));
|
|
47
|
+
}
|
|
48
|
+
if (err || errStatus.length > 0) {
|
|
30
49
|
this.logger.logLabeled("WARN", "functions", `Firebase Authentication function was not triggered due to emulation error. Please file a bug.`);
|
|
31
50
|
}
|
|
32
51
|
}
|
|
@@ -43,6 +62,22 @@ class AuthCloudFunction {
|
|
|
43
62
|
data: userInfoPayload,
|
|
44
63
|
};
|
|
45
64
|
}
|
|
65
|
+
createCloudEventRequestBody(action, userInfoPayload) {
|
|
66
|
+
const ceAction = AUTH_V2_ACTION_MAP[action];
|
|
67
|
+
const cloudEvent = {
|
|
68
|
+
specversion: "1.0",
|
|
69
|
+
id: (0, crypto_1.randomUUID)(),
|
|
70
|
+
time: new Date().toISOString(),
|
|
71
|
+
type: `google.firebase.auth.user.v2.${ceAction}`,
|
|
72
|
+
source: `//identitytoolkit.googleapis.com/projects/${this.projectId}`,
|
|
73
|
+
subject: `users/${userInfoPayload.uid}`,
|
|
74
|
+
data: action === "create" ? { value: userInfoPayload } : { oldValue: userInfoPayload },
|
|
75
|
+
};
|
|
76
|
+
if (userInfoPayload.tenantId) {
|
|
77
|
+
cloudEvent.tenantid = userInfoPayload.tenantId;
|
|
78
|
+
}
|
|
79
|
+
return cloudEvent;
|
|
80
|
+
}
|
|
46
81
|
createUserInfoPayload(user) {
|
|
47
82
|
return {
|
|
48
83
|
uid: user.localId,
|
|
@@ -44,46 +44,46 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"pubsub": {
|
|
47
|
-
"version": "0.8.
|
|
48
|
-
"expectedSize":
|
|
49
|
-
"expectedChecksum": "
|
|
50
|
-
"expectedChecksumSHA256": "
|
|
51
|
-
"remoteUrl": "https://storage.googleapis.com/firebase-preview-drop/emulator/pubsub-emulator-0.8.
|
|
52
|
-
"downloadPathRelativeToCacheDir": "pubsub-emulator-0.8.
|
|
53
|
-
"binaryPathRelativeToCacheDir": "pubsub-emulator-0.8.
|
|
47
|
+
"version": "0.8.36",
|
|
48
|
+
"expectedSize": 53026271,
|
|
49
|
+
"expectedChecksum": "f62d997f52619f4800f34f42136178ef",
|
|
50
|
+
"expectedChecksumSHA256": "0b3a030b3a92aba50082aeed7ee63008a45b032b7231090d3a1bcd8744e0e2e5",
|
|
51
|
+
"remoteUrl": "https://storage.googleapis.com/firebase-preview-drop/emulator/pubsub-emulator-0.8.36.zip",
|
|
52
|
+
"downloadPathRelativeToCacheDir": "pubsub-emulator-0.8.36.zip",
|
|
53
|
+
"binaryPathRelativeToCacheDir": "pubsub-emulator-0.8.36/pubsub-emulator/bin/cloud-pubsub-emulator"
|
|
54
54
|
},
|
|
55
55
|
"dataconnect": {
|
|
56
56
|
"darwin": {
|
|
57
|
-
"version": "3.4.
|
|
58
|
-
"expectedSize":
|
|
59
|
-
"expectedChecksum": "
|
|
60
|
-
"expectedChecksumSHA256": "
|
|
61
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.
|
|
62
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
57
|
+
"version": "3.4.20",
|
|
58
|
+
"expectedSize": 33787120,
|
|
59
|
+
"expectedChecksum": "a8c044198a62239fc20a31ef545f8eea",
|
|
60
|
+
"expectedChecksumSHA256": "4cbef4430bb5ad72f8fbe2293b938463a1e912b5c17b5577c6546343fe3149a9",
|
|
61
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.20",
|
|
62
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.20"
|
|
63
63
|
},
|
|
64
64
|
"darwin_arm64": {
|
|
65
|
-
"version": "3.4.
|
|
66
|
-
"expectedSize":
|
|
67
|
-
"expectedChecksum": "
|
|
68
|
-
"expectedChecksumSHA256": "
|
|
69
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.
|
|
70
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
65
|
+
"version": "3.4.20",
|
|
66
|
+
"expectedSize": 31883698,
|
|
67
|
+
"expectedChecksum": "8c8cf2b1c8b99cb7ebd459ca383aa8ed",
|
|
68
|
+
"expectedChecksumSHA256": "873e9aab3aa09a946d4a729e5755d38c5d607655796f5a031f7b21c339fa5ef7",
|
|
69
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.20",
|
|
70
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.20"
|
|
71
71
|
},
|
|
72
72
|
"win32": {
|
|
73
|
-
"version": "3.4.
|
|
74
|
-
"expectedSize":
|
|
75
|
-
"expectedChecksum": "
|
|
76
|
-
"expectedChecksumSHA256": "
|
|
77
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.
|
|
78
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
73
|
+
"version": "3.4.20",
|
|
74
|
+
"expectedSize": 33819136,
|
|
75
|
+
"expectedChecksum": "2bb404ba566f5e2d7224a802c860035c",
|
|
76
|
+
"expectedChecksumSHA256": "5e613eddc18378c8b917a94bd7380e6174918ccb29f5bed915927434078bc4a7",
|
|
77
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.20",
|
|
78
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.20.exe"
|
|
79
79
|
},
|
|
80
80
|
"linux": {
|
|
81
|
-
"version": "3.4.
|
|
82
|
-
"expectedSize":
|
|
83
|
-
"expectedChecksum": "
|
|
84
|
-
"expectedChecksumSHA256": "
|
|
85
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.
|
|
86
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
81
|
+
"version": "3.4.20",
|
|
82
|
+
"expectedSize": 32911544,
|
|
83
|
+
"expectedChecksum": "9ae887603b8085e50ff992dd7c86385c",
|
|
84
|
+
"expectedChecksumSHA256": "0500ecb9f22c8e26df1f650e656497b542f26b47b3b5730fde850a918643ca2f",
|
|
85
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.20",
|
|
86
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.20"
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -170,12 +170,18 @@ class FunctionsEmulator {
|
|
|
170
170
|
else {
|
|
171
171
|
triggerKey = `${this.args.projectId}:${event.eventType}`;
|
|
172
172
|
}
|
|
173
|
-
if (event.data
|
|
173
|
+
if (event.data?.bucket) {
|
|
174
174
|
triggerKey += `:${event.data.bucket}`;
|
|
175
175
|
}
|
|
176
176
|
const triggers = this.multicastTriggers[triggerKey] || [];
|
|
177
177
|
const { host, port } = this.getInfo();
|
|
178
|
-
|
|
178
|
+
const eventTenantId = (0, functionsEmulatorShared_1.getEventTenantId)(event);
|
|
179
|
+
for (const triggerId of triggers) {
|
|
180
|
+
const record = this.getTriggerRecordByKey(triggerId);
|
|
181
|
+
const filterTenantId = record?.def?.eventTrigger?.eventFilters?.tenantid;
|
|
182
|
+
if (filterTenantId && filterTenantId !== eventTenantId) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
179
185
|
const work = () => {
|
|
180
186
|
return new Promise((resolve, reject) => {
|
|
181
187
|
const trigReq = http.request({
|
|
@@ -193,7 +199,7 @@ class FunctionsEmulator {
|
|
|
193
199
|
};
|
|
194
200
|
work.type = `${triggerId}-${new Date().toISOString()}`;
|
|
195
201
|
this.workQueue.submit(work);
|
|
196
|
-
}
|
|
202
|
+
}
|
|
197
203
|
res.json({ status: "multicast_acknowledged" });
|
|
198
204
|
};
|
|
199
205
|
const listBackendsHandler = (req, res) => {
|
|
@@ -378,7 +384,10 @@ class FunctionsEmulator {
|
|
|
378
384
|
await this.args.extensionsEmulator.addDynamicExtensions(emulatableBackend.codebase, discoveredBuild);
|
|
379
385
|
await this.loadDynamicExtensionBackends();
|
|
380
386
|
}
|
|
381
|
-
build.
|
|
387
|
+
build.applyEndpointPrefix(discoveredBuild, emulatableBackend.prefix || "");
|
|
388
|
+
if (emulatableBackend.env?.FIREBASE_KIT_INSTANCE_ID) {
|
|
389
|
+
build.applyKitSecretRefPrefix(discoveredBuild, emulatableBackend.env.FIREBASE_KIT_INSTANCE_ID);
|
|
390
|
+
}
|
|
382
391
|
const resolution = await (0, build_1.resolveBackend)({
|
|
383
392
|
build: discoveredBuild,
|
|
384
393
|
firebaseConfig: JSON.parse(firebaseConfig),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EmulatedTrigger = exports.EVENTARC_SOURCE_ENV = void 0;
|
|
4
|
+
exports.getEventTenantId = getEventTenantId;
|
|
4
5
|
exports.eventServiceImplemented = eventServiceImplemented;
|
|
5
6
|
exports.prepareEndpoints = prepareEndpoints;
|
|
6
7
|
exports.emulatedFunctionsFromEndpoints = emulatedFunctionsFromEndpoints;
|
|
@@ -36,7 +37,17 @@ const V2_EVENTS = [
|
|
|
36
37
|
...events.v2.STORAGE_EVENTS,
|
|
37
38
|
...events.v2.DATABASE_EVENTS,
|
|
38
39
|
...events.v2.FIRESTORE_EVENTS,
|
|
40
|
+
...events.v2.AUTH_EVENTS,
|
|
39
41
|
];
|
|
42
|
+
function getEventTenantId(eventPayload) {
|
|
43
|
+
if (!eventPayload || typeof eventPayload !== "object") {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
if (typeof eventPayload.tenantid === "string") {
|
|
47
|
+
return eventPayload.tenantid;
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
40
51
|
exports.EVENTARC_SOURCE_ENV = "EVENTARC_CLOUD_EVENT_SOURCE";
|
|
41
52
|
class EmulatedTrigger {
|
|
42
53
|
constructor(definition, module) {
|
|
@@ -229,12 +240,12 @@ function getServiceFromEventType(eventType) {
|
|
|
229
240
|
if (eventType.includes("firebasealerts")) {
|
|
230
241
|
return constants_1.Constants.SERVICE_FIREALERTS;
|
|
231
242
|
}
|
|
232
|
-
if (eventType.includes("analytics")) {
|
|
233
|
-
return constants_1.Constants.SERVICE_ANALYTICS;
|
|
234
|
-
}
|
|
235
243
|
if (eventType.includes("auth")) {
|
|
236
244
|
return constants_1.Constants.SERVICE_AUTH;
|
|
237
245
|
}
|
|
246
|
+
if (eventType.includes("analytics")) {
|
|
247
|
+
return constants_1.Constants.SERVICE_ANALYTICS;
|
|
248
|
+
}
|
|
238
249
|
if (eventType.includes("crashlytics")) {
|
|
239
250
|
return constants_1.Constants.SERVICE_CRASHLYTICS;
|
|
240
251
|
}
|
package/lib/experiments.js
CHANGED
|
@@ -224,7 +224,7 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
224
224
|
fdcapimigration: {
|
|
225
225
|
shortDescription: "Enable the FDC API schema migration path.",
|
|
226
226
|
fullDescription: "API based Schema Migration behind experimental flag.",
|
|
227
|
-
default:
|
|
227
|
+
default: false,
|
|
228
228
|
public: false,
|
|
229
229
|
},
|
|
230
230
|
});
|
package/lib/extensions/export.js
CHANGED
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parameterizeProject = parameterizeProject;
|
|
4
4
|
exports.setSecretParamsToLatest = setSecretParamsToLatest;
|
|
5
5
|
exports.displayExportInfo = displayExportInfo;
|
|
6
|
+
exports.memoryToMb = memoryToMb;
|
|
7
|
+
exports.parseMemory = parseMemory;
|
|
8
|
+
exports.resolveMigratedMemory = resolveMigratedMemory;
|
|
6
9
|
exports.functionsEnvFromInstance = functionsEnvFromInstance;
|
|
7
10
|
exports.secretsNeedingEjection = secretsNeedingEjection;
|
|
8
11
|
exports.ejectSecretsFromInstance = ejectSecretsFromInstance;
|
|
@@ -66,6 +69,58 @@ function displaySpecs(specs) {
|
|
|
66
69
|
logger_1.logger.info("");
|
|
67
70
|
}
|
|
68
71
|
}
|
|
72
|
+
const GIB_REGEX = /^\d+(?:\.\d+)?(?:Gi|GiB|G|GB)$/i;
|
|
73
|
+
const MIB_REGEX = /^\d+(?:\.\d+)?(?:Mi|MiB|M|MB)?$/i;
|
|
74
|
+
function memoryToMb(memory) {
|
|
75
|
+
if (!memory) {
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
const trimmed = memory.trim();
|
|
79
|
+
if (GIB_REGEX.test(trimmed)) {
|
|
80
|
+
return Math.round(parseFloat(trimmed) * 1024);
|
|
81
|
+
}
|
|
82
|
+
if (MIB_REGEX.test(trimmed)) {
|
|
83
|
+
const parsed = parseFloat(trimmed);
|
|
84
|
+
return isNaN(parsed) || parsed < 0 ? 0 : parsed;
|
|
85
|
+
}
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
const MB_TO_MEMORY_OPTION = {
|
|
89
|
+
128: "128MiB",
|
|
90
|
+
256: "256MiB",
|
|
91
|
+
512: "512MiB",
|
|
92
|
+
1024: "1GiB",
|
|
93
|
+
2048: "2GiB",
|
|
94
|
+
4096: "4GiB",
|
|
95
|
+
8192: "8GiB",
|
|
96
|
+
16384: "16GiB",
|
|
97
|
+
32768: "32GiB",
|
|
98
|
+
};
|
|
99
|
+
function parseMemory(raw) {
|
|
100
|
+
if (!raw) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
const mb = memoryToMb(raw);
|
|
104
|
+
return MB_TO_MEMORY_OPTION[mb];
|
|
105
|
+
}
|
|
106
|
+
const V1_MEMORY_PARAM = "firebaseextensions.v1beta.function/memory";
|
|
107
|
+
const V2_MEMORY_PARAM = "firebaseextensions.v1beta.v2function/memory";
|
|
108
|
+
const MEMORY_PARAMS = new Set([V1_MEMORY_PARAM, V2_MEMORY_PARAM]);
|
|
109
|
+
function resolveMigratedMemory(liveSystemParams = {}, specSystemParams = []) {
|
|
110
|
+
const getParam = (paramName) => {
|
|
111
|
+
if (paramName in liveSystemParams) {
|
|
112
|
+
return liveSystemParams[paramName];
|
|
113
|
+
}
|
|
114
|
+
const defaultVal = specSystemParams.find((p) => p.param === paramName)?.default;
|
|
115
|
+
return defaultVal !== undefined ? String(defaultVal) : undefined;
|
|
116
|
+
};
|
|
117
|
+
const v1 = getParam(V1_MEMORY_PARAM);
|
|
118
|
+
const v2 = getParam(V2_MEMORY_PARAM);
|
|
119
|
+
if (v1 && v2) {
|
|
120
|
+
return memoryToMb(v1) > memoryToMb(v2) ? v1 : v2;
|
|
121
|
+
}
|
|
122
|
+
return v2 ?? v1;
|
|
123
|
+
}
|
|
69
124
|
function functionsEnvFromInstance(instance) {
|
|
70
125
|
const liveParams = instance.config?.params || {};
|
|
71
126
|
const liveSystemParams = instance.config?.systemParams || {};
|
|
@@ -85,6 +140,9 @@ function functionsEnvFromInstance(instance) {
|
|
|
85
140
|
}
|
|
86
141
|
});
|
|
87
142
|
for (const [sysParamName, sysParamValue] of Object.entries(liveSystemParams)) {
|
|
143
|
+
if (MEMORY_PARAMS.has(sysParamName)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
88
146
|
let renamed = sysParamName
|
|
89
147
|
.replace(/^firebaseextensions\.v1beta\.(v2)?function\//, "EXT_MIGRATED_SYSTEM_")
|
|
90
148
|
.toUpperCase();
|
|
@@ -94,7 +152,7 @@ function functionsEnvFromInstance(instance) {
|
|
|
94
152
|
envs[renamed] = sysParamValue;
|
|
95
153
|
}
|
|
96
154
|
for (const specSystemParam of specSystemParams) {
|
|
97
|
-
if (specSystemParam.param in liveSystemParams) {
|
|
155
|
+
if (specSystemParam.param in liveSystemParams || MEMORY_PARAMS.has(specSystemParam.param)) {
|
|
98
156
|
continue;
|
|
99
157
|
}
|
|
100
158
|
if ("default" in specSystemParam) {
|
|
@@ -107,6 +165,10 @@ function functionsEnvFromInstance(instance) {
|
|
|
107
165
|
envs[renamed] = String(specSystemParam.default ?? "");
|
|
108
166
|
}
|
|
109
167
|
}
|
|
168
|
+
const memory = resolveMigratedMemory(liveSystemParams, specSystemParams);
|
|
169
|
+
if (memory) {
|
|
170
|
+
envs["EXT_MIGRATED_SYSTEM_MEMORY"] = parseMemory(memory) ?? memory;
|
|
171
|
+
}
|
|
110
172
|
if (typeof instance.config.allowedEventTypes !== "undefined") {
|
|
111
173
|
envs["EXT_SELECTED_EVENTS"] = instance.config.allowedEventTypes.toString();
|
|
112
174
|
}
|
|
@@ -222,7 +222,11 @@ async function ensureInstanceUpToDate(projectId, instance, options) {
|
|
|
222
222
|
try {
|
|
223
223
|
const parsed = refs.parse(rawRef);
|
|
224
224
|
baseRef = refs.toExtensionRef(parsed);
|
|
225
|
-
currentVersion =
|
|
225
|
+
currentVersion =
|
|
226
|
+
parsed.version ||
|
|
227
|
+
instance.config?.source?.spec?.version ||
|
|
228
|
+
instance.config?.extensionVersion ||
|
|
229
|
+
instance.extensionVersion;
|
|
226
230
|
}
|
|
227
231
|
catch (err) {
|
|
228
232
|
logger_1.logger.debug(`[ensureInstanceUpToDate] Could not parse extension reference '${rawRef}':`, err);
|
|
@@ -245,6 +249,16 @@ async function ensureInstanceUpToDate(projectId, instance, options) {
|
|
|
245
249
|
if (!latestVersion || currentVersion === latestVersion) {
|
|
246
250
|
return instance;
|
|
247
251
|
}
|
|
252
|
+
const shouldUpgrade = await (0, prompt_1.confirm)({
|
|
253
|
+
message: `Extension instance ${clc.bold(instanceId)} is on version ${clc.bold(currentVersion)}, but the latest version is ${clc.bold(latestVersion)}. An upgrade is strongly recommended before migrating to avoid breaking changes. Upgrade it now?`,
|
|
254
|
+
default: true,
|
|
255
|
+
nonInteractive: options?.nonInteractive,
|
|
256
|
+
force: options?.force,
|
|
257
|
+
});
|
|
258
|
+
if (!shouldUpgrade) {
|
|
259
|
+
(0, utils_1.logLabeledWarning)(extensionsHelper_1.logPrefix, `Continuing migration with extension instance ${clc.bold(instanceId)} on outdated version ${clc.bold(currentVersion)}.`);
|
|
260
|
+
return instance;
|
|
261
|
+
}
|
|
248
262
|
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Upgrading extension instance ${clc.bold(instanceId)} from version ${clc.bold(currentVersion)} to ${clc.bold(latestVersion)} to ensure a smooth migration...`);
|
|
249
263
|
const targetRef = `${baseRef}@${latestVersion}`;
|
|
250
264
|
let finalParams = {
|
|
@@ -290,7 +304,7 @@ async function ensureInstanceUpToDate(projectId, instance, options) {
|
|
|
290
304
|
throw new error_1.FirebaseError(`Failed to automatically upgrade extension instance ${instanceId} to version ${latestVersion}: ${message}. Please upgrade your extension instance manually using 'firebase ext:update ${instanceId}' before attempting migration.`, { original: err instanceof Error ? err : undefined });
|
|
291
305
|
}
|
|
292
306
|
const updatedInstance = await extensionsApi.getInstance(projectId, instanceId);
|
|
293
|
-
return updatedInstance
|
|
307
|
+
return updatedInstance ? await (0, extensionsHelper_1.ensureInstanceSpec)(updatedInstance) : instance;
|
|
294
308
|
}
|
|
295
309
|
async function migrateSecrets(instance, options) {
|
|
296
310
|
const secrets = await (0, export_1.secretsNeedingEjection)(instance);
|
package/lib/fsutils.js
CHANGED
|
@@ -5,10 +5,12 @@ exports.dirExistsSync = dirExistsSync;
|
|
|
5
5
|
exports.readFile = readFile;
|
|
6
6
|
exports.listFiles = listFiles;
|
|
7
7
|
exports.moveAll = moveAll;
|
|
8
|
+
exports.removeDirectoryIfEmpty = removeDirectoryIfEmpty;
|
|
8
9
|
const fs_1 = require("fs");
|
|
9
10
|
const path = require("path");
|
|
11
|
+
const fs = require("fs-extra");
|
|
10
12
|
const error_1 = require("./error");
|
|
11
|
-
const
|
|
13
|
+
const logger_1 = require("./logger");
|
|
12
14
|
function fileExistsSync(path) {
|
|
13
15
|
try {
|
|
14
16
|
return (0, fs_1.statSync)(path).isFile();
|
|
@@ -56,6 +58,22 @@ function moveAll(srcDir, destDir) {
|
|
|
56
58
|
const srcPath = path.join(srcDir, f);
|
|
57
59
|
if (srcPath === destDir)
|
|
58
60
|
continue;
|
|
59
|
-
|
|
61
|
+
fs.moveSync(srcPath, path.join(destDir, f));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function removeDirectoryIfEmpty(absDirPath) {
|
|
65
|
+
try {
|
|
66
|
+
if (await fs.pathExists(absDirPath)) {
|
|
67
|
+
const stat = await fs.stat(absDirPath);
|
|
68
|
+
if (stat.isDirectory()) {
|
|
69
|
+
const entries = await fs.readdir(absDirPath);
|
|
70
|
+
if (entries.length === 0) {
|
|
71
|
+
await fs.remove(absDirPath);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
logger_1.logger.debug(`Failed to clean up directory '${absDirPath}' if empty: ${(0, error_1.getErrMsg)(err)}`);
|
|
60
78
|
}
|
|
61
79
|
}
|
package/lib/functions/env.js
CHANGED
|
@@ -127,12 +127,29 @@ function validateKey(key) {
|
|
|
127
127
|
if (keyConflictsWithReservedPrefixes(key)) {
|
|
128
128
|
throw new KeyValidationError(key, `Key ${key} starts with a reserved prefix (${RESERVED_PREFIXES.join(" ")})`);
|
|
129
129
|
}
|
|
130
|
-
if (RESERVED_PREFIX_ALLOWLIST.some((prefix) => key === prefix)) {
|
|
131
|
-
throw new KeyValidationError(key, `Key ${key} is a known prefix with an empty suffix`);
|
|
132
|
-
}
|
|
133
130
|
}
|
|
134
131
|
function keyConflictsWithReservedPrefixes(key) {
|
|
135
|
-
|
|
132
|
+
if (!RESERVED_PREFIXES.some((prefix) => key.startsWith(prefix))) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
for (const allowedPrefix of RESERVED_PREFIX_ALLOWLIST) {
|
|
136
|
+
if (keyPermittedByKnownPrefix(key, allowedPrefix)) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
function keyPermittedByKnownPrefix(key, prefix) {
|
|
143
|
+
if (!key.startsWith(prefix)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (prefix.endsWith("_") && key === prefix) {
|
|
147
|
+
throw new KeyValidationError(key, `Key ${key} is a known prefix that requires a suffix`);
|
|
148
|
+
}
|
|
149
|
+
if (!prefix.endsWith("_") && key !== prefix) {
|
|
150
|
+
throw new KeyValidationError(key, `Key ${key} conflicts with known key ${prefix} that does not permit a suffix`);
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
136
153
|
}
|
|
137
154
|
function parseStrict(data) {
|
|
138
155
|
const { envs, errors } = parse(data);
|