firebase-tools-with-isolate 13.15.0-0 → 13.16.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/commands/deploy.js +3 -1
- package/lib/dataconnect/client.js +2 -1
- package/lib/dataconnect/fileUtils.js +52 -11
- package/lib/dataconnect/provisionCloudSql.js +5 -1
- package/lib/deploy/extensions/planner.js +52 -1
- package/lib/deploy/extensions/prepare.js +98 -23
- package/lib/deploy/extensions/release.js +6 -0
- package/lib/deploy/functions/build.js +5 -5
- package/lib/deploy/functions/deploy.js +12 -12
- package/lib/deploy/functions/params.js +5 -3
- package/lib/deploy/functions/prepare.js +8 -1
- package/lib/deploy/functions/release/index.js +4 -0
- package/lib/deploy/functions/runtimes/discovery/parsing.js +1 -1
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +46 -0
- package/lib/emulator/constants.js +7 -0
- package/lib/emulator/controller.js +11 -1
- package/lib/emulator/downloadableEmulators.js +12 -12
- package/lib/emulator/env.js +3 -0
- package/lib/emulator/functionsEmulator.js +30 -1
- package/lib/emulator/functionsEmulatorShared.js +16 -0
- package/lib/emulator/portUtils.js +1 -0
- package/lib/emulator/registry.js +1 -0
- package/lib/emulator/taskQueue.js +348 -0
- package/lib/emulator/tasksEmulator.js +237 -0
- package/lib/emulator/types.js +3 -0
- package/lib/extensions/askUserForEventsConfig.js +18 -8
- package/lib/extensions/askUserForParam.js +2 -1
- package/lib/extensions/displayExtensionInfo.js +5 -5
- package/lib/extensions/extensionsApi.js +1 -1
- package/lib/extensions/extensionsHelper.js +25 -3
- package/lib/extensions/localHelper.js +1 -1
- package/lib/extensions/refs.js +26 -11
- package/lib/extensions/runtimes/common.js +75 -0
- package/lib/extensions/types.js +56 -1
- package/lib/frameworks/constants.js +1 -1
- package/lib/frameworks/next/constants.js +1 -1
- package/lib/frameworks/next/index.js +35 -15
- package/lib/frameworks/next/utils.js +51 -1
- package/lib/init/features/dataconnect/index.js +14 -8
- package/lib/init/features/dataconnect/sdk.js +64 -48
- package/lib/prompt.js +22 -1
- package/package.json +3 -3
- package/schema/firebase-config.json +12 -0
- package/templates/init/dataconnect/connector.yaml +5 -3
- package/templates/init/dataconnect/dataconnect.yaml +5 -5
- package/templates/init/dataconnect/mutations.gql +44 -29
- package/templates/init/dataconnect/queries.gql +66 -38
- package/templates/init/dataconnect/schema.gql +38 -21
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TasksEmulator = exports.TaskQueueController = void 0;
|
|
4
|
+
const express = require("express");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const emulatorLogger_1 = require("./emulatorLogger");
|
|
9
|
+
const taskQueue_1 = require("./taskQueue");
|
|
10
|
+
const cors = require("cors");
|
|
11
|
+
const RETRY_CONFIG_DEFAULTS = {
|
|
12
|
+
maxAttempts: 3,
|
|
13
|
+
maxRetrySeconds: null,
|
|
14
|
+
maxBackoffSeconds: 60 * 60,
|
|
15
|
+
maxDoublings: 16,
|
|
16
|
+
minBackoffSeconds: 0.1,
|
|
17
|
+
};
|
|
18
|
+
const RATE_LIMITS_DEFAULT = {
|
|
19
|
+
maxConcurrentDispatches: 1000,
|
|
20
|
+
maxDispatchesPerSecond: 500,
|
|
21
|
+
};
|
|
22
|
+
class TaskQueueController {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.queues = {};
|
|
25
|
+
this.tokenRefillIds = [];
|
|
26
|
+
this.running = false;
|
|
27
|
+
this.listenId = null;
|
|
28
|
+
}
|
|
29
|
+
enqueue(key, task) {
|
|
30
|
+
if (!this.queues[key]) {
|
|
31
|
+
throw new Error("Queue does not exist");
|
|
32
|
+
}
|
|
33
|
+
this.queues[key].enqueue(task);
|
|
34
|
+
}
|
|
35
|
+
delete(key, taskId) {
|
|
36
|
+
if (!this.queues[key]) {
|
|
37
|
+
throw new Error("Queue does not exist");
|
|
38
|
+
}
|
|
39
|
+
this.queues[key].delete(taskId);
|
|
40
|
+
}
|
|
41
|
+
createQueue(key, config) {
|
|
42
|
+
const newQueue = new taskQueue_1.TaskQueue(key, config);
|
|
43
|
+
const intervalID = setInterval(() => newQueue.refillTokens(), TaskQueueController.TOKEN_REFRESH_INTERVAL);
|
|
44
|
+
this.tokenRefillIds.push(intervalID);
|
|
45
|
+
this.queues[key] = newQueue;
|
|
46
|
+
}
|
|
47
|
+
listen() {
|
|
48
|
+
let shouldUpdate = false;
|
|
49
|
+
for (const [_key, queue] of Object.entries(this.queues)) {
|
|
50
|
+
shouldUpdate = shouldUpdate || queue.isActive();
|
|
51
|
+
}
|
|
52
|
+
if (shouldUpdate) {
|
|
53
|
+
this.updateQueues();
|
|
54
|
+
this.listenId = setTimeout(() => this.listen(), TaskQueueController.UPDATE_TIMEOUT);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.listenId = setTimeout(() => this.listen(), TaskQueueController.LISTEN_TIMEOUT);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
updateQueues() {
|
|
61
|
+
for (const [_key, queue] of Object.entries(this.queues)) {
|
|
62
|
+
if (queue.isActive()) {
|
|
63
|
+
queue.dispatchTasks();
|
|
64
|
+
queue.processDispatch();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
start() {
|
|
69
|
+
this.running = true;
|
|
70
|
+
this.listen();
|
|
71
|
+
}
|
|
72
|
+
stop() {
|
|
73
|
+
if (this.listenId) {
|
|
74
|
+
clearTimeout(this.listenId);
|
|
75
|
+
}
|
|
76
|
+
this.tokenRefillIds.forEach(clearInterval);
|
|
77
|
+
this.running = false;
|
|
78
|
+
}
|
|
79
|
+
isRunning() {
|
|
80
|
+
return this.running;
|
|
81
|
+
}
|
|
82
|
+
getStatistics() {
|
|
83
|
+
const stats = {};
|
|
84
|
+
for (const [key, queue] of Object.entries(this.queues)) {
|
|
85
|
+
stats[key] = queue.getStatistics();
|
|
86
|
+
}
|
|
87
|
+
return stats;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.TaskQueueController = TaskQueueController;
|
|
91
|
+
TaskQueueController.UPDATE_TIMEOUT = 0;
|
|
92
|
+
TaskQueueController.LISTEN_TIMEOUT = 1000;
|
|
93
|
+
TaskQueueController.TOKEN_REFRESH_INTERVAL = 1000;
|
|
94
|
+
class TasksEmulator {
|
|
95
|
+
constructor(args) {
|
|
96
|
+
this.args = args;
|
|
97
|
+
this.logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.TASKS);
|
|
98
|
+
this.controller = new TaskQueueController();
|
|
99
|
+
}
|
|
100
|
+
validateQueueId(queueId) {
|
|
101
|
+
if (typeof queueId !== "string") {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (queueId.length > 100) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
const regex = /^[A-Za-z0-9-]+$/;
|
|
108
|
+
return regex.test(queueId);
|
|
109
|
+
}
|
|
110
|
+
createHubServer() {
|
|
111
|
+
const hub = express();
|
|
112
|
+
const createTaskQueueRoute = `/projects/:project_id/locations/:location_id/queues/:queue_name`;
|
|
113
|
+
const createTaskQueueHandler = (req, res) => {
|
|
114
|
+
const projectId = req.params.project_id;
|
|
115
|
+
const locationId = req.params.location_id;
|
|
116
|
+
const queueName = req.params.queue_name;
|
|
117
|
+
if (!this.validateQueueId(queueName)) {
|
|
118
|
+
res.status(400).send("Invalid Queue ID");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const key = `queue:${projectId}-${locationId}-${queueName}`;
|
|
122
|
+
this.logger.logLabeled("SUCCESS", "tasks", `Created queue with key: ${key}`);
|
|
123
|
+
const body = req.body;
|
|
124
|
+
const taskQueueConfig = {
|
|
125
|
+
retryConfig: {
|
|
126
|
+
maxAttempts: body.retryConfig?.maxAttempts ?? RETRY_CONFIG_DEFAULTS.maxAttempts,
|
|
127
|
+
maxRetrySeconds: body.retryConfig?.maxRetrySeconds ?? RETRY_CONFIG_DEFAULTS.maxRetrySeconds,
|
|
128
|
+
maxBackoffSeconds: body.retryConfig?.maxBackoffSeconds ?? RETRY_CONFIG_DEFAULTS.maxBackoffSeconds,
|
|
129
|
+
maxDoublings: body.retryConfig?.maxDoublings ?? RETRY_CONFIG_DEFAULTS.maxDoublings,
|
|
130
|
+
minBackoffSeconds: body.retryConfig?.minBackoffSeconds ?? RETRY_CONFIG_DEFAULTS.minBackoffSeconds,
|
|
131
|
+
},
|
|
132
|
+
rateLimits: {
|
|
133
|
+
maxConcurrentDispatches: body.rateLimits?.maxConcurrentDispatches ?? RATE_LIMITS_DEFAULT.maxConcurrentDispatches,
|
|
134
|
+
maxDispatchesPerSecond: body.rateLimits?.maxDispatchesPerSecond ?? RATE_LIMITS_DEFAULT.maxDispatchesPerSecond,
|
|
135
|
+
},
|
|
136
|
+
timeoutSeconds: body.timeoutSeconds ?? 10,
|
|
137
|
+
retry: body.retry ?? false,
|
|
138
|
+
defaultUri: body.defaultUri,
|
|
139
|
+
};
|
|
140
|
+
if (taskQueueConfig.rateLimits.maxConcurrentDispatches > 5000) {
|
|
141
|
+
res.status(400).send("cannot set maxConcurrentDispatches to a value over 5000");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
this.controller.createQueue(key, taskQueueConfig);
|
|
145
|
+
this.logger.log("DEBUG", `Created task queue ${key} with configuration: ${JSON.stringify(taskQueueConfig)}`);
|
|
146
|
+
res.status(200).send({ taskQueueConfig });
|
|
147
|
+
};
|
|
148
|
+
const enqueueTasksRoute = `/projects/:project_id/locations/:location_id/queues/:queue_name/tasks`;
|
|
149
|
+
const enqueueTasksHandler = (req, res) => {
|
|
150
|
+
if (!this.controller.isRunning()) {
|
|
151
|
+
this.controller.start();
|
|
152
|
+
}
|
|
153
|
+
const projectId = req.params.project_id;
|
|
154
|
+
const locationId = req.params.location_id;
|
|
155
|
+
const queueName = req.params.queue_name;
|
|
156
|
+
const queueKey = `queue:${projectId}-${locationId}-${queueName}`;
|
|
157
|
+
if (!this.controller.queues[queueKey]) {
|
|
158
|
+
this.logger.log("WARN", "Tried to queue a task into a non-existent queue");
|
|
159
|
+
res.status(404).send("Tried to queue a task from a non-existent queue");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
req.body.task.name =
|
|
163
|
+
req.body.task.name ??
|
|
164
|
+
`/projects/${projectId}/locations/${locationId}/queues/${queueName}/tasks/${Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)}`;
|
|
165
|
+
req.body.task.httpRequest.body = JSON.parse(atob(req.body.task.httpRequest.body));
|
|
166
|
+
const task = req.body.task;
|
|
167
|
+
try {
|
|
168
|
+
this.controller.enqueue(queueKey, task);
|
|
169
|
+
this.logger.log("DEBUG", `Enqueueing task ${task.name} onto ${queueKey}`);
|
|
170
|
+
res.status(200).send({ task: task });
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
res.status(409).send("A task with the same name already exists");
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const deleteTasksRoute = `/projects/:project_id/locations/:location_id/queues/:queue_name/tasks/:task_id`;
|
|
177
|
+
const deleteTasksHandler = (req, res) => {
|
|
178
|
+
const projectId = req.params.project_id;
|
|
179
|
+
const locationId = req.params.location_id;
|
|
180
|
+
const queueName = req.params.queue_name;
|
|
181
|
+
const taskId = req.params.task_id;
|
|
182
|
+
const queueKey = `queue:${projectId}-${locationId}-${queueName}`;
|
|
183
|
+
if (!this.controller.queues[queueKey]) {
|
|
184
|
+
this.logger.log("WARN", "Tried to remove a task from a non-existent queue");
|
|
185
|
+
res.status(404).send("Tried to remove a task from a non-existent queue");
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
const taskName = `projects/${projectId}/locations/${locationId}/queues/${queueName}/tasks/${taskId}`;
|
|
190
|
+
this.logger.log("DEBUG", `removing: ${taskName}`);
|
|
191
|
+
this.controller.delete(queueKey, taskName);
|
|
192
|
+
res.status(200).send({ res: "OK" });
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
this.logger.log("WARN", "Tried to remove a task that doesn't exist");
|
|
196
|
+
res.status(404).send("Tried to remove a task that doesn't exist");
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const getStatsRoute = `/queueStats`;
|
|
200
|
+
const getStatsHandler = (req, res) => {
|
|
201
|
+
res.json(this.controller.getStatistics());
|
|
202
|
+
};
|
|
203
|
+
hub.get([getStatsRoute], cors({ origin: true }), getStatsHandler);
|
|
204
|
+
hub.post([createTaskQueueRoute], express.json(), createTaskQueueHandler);
|
|
205
|
+
hub.post([enqueueTasksRoute], express.json(), enqueueTasksHandler);
|
|
206
|
+
hub.delete([deleteTasksRoute], express.json(), deleteTasksHandler);
|
|
207
|
+
return hub;
|
|
208
|
+
}
|
|
209
|
+
async start() {
|
|
210
|
+
const { host, port } = this.getInfo();
|
|
211
|
+
const server = this.createHubServer().listen(port, host);
|
|
212
|
+
this.destroyServer = (0, utils_1.createDestroyer)(server);
|
|
213
|
+
return Promise.resolve();
|
|
214
|
+
}
|
|
215
|
+
async connect() {
|
|
216
|
+
return Promise.resolve();
|
|
217
|
+
}
|
|
218
|
+
async stop() {
|
|
219
|
+
if (this.destroyServer) {
|
|
220
|
+
await this.destroyServer();
|
|
221
|
+
}
|
|
222
|
+
this.controller.stop();
|
|
223
|
+
}
|
|
224
|
+
getInfo() {
|
|
225
|
+
const host = this.args.host || constants_1.Constants.getDefaultHost();
|
|
226
|
+
const port = this.args.port || constants_1.Constants.getDefaultPort(types_1.Emulators.TASKS);
|
|
227
|
+
return {
|
|
228
|
+
name: this.getName(),
|
|
229
|
+
host,
|
|
230
|
+
port,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
getName() {
|
|
234
|
+
return types_1.Emulators.TASKS;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.TasksEmulator = TasksEmulator;
|
package/lib/emulator/types.js
CHANGED
|
@@ -16,6 +16,7 @@ var Emulators;
|
|
|
16
16
|
Emulators["EXTENSIONS"] = "extensions";
|
|
17
17
|
Emulators["EVENTARC"] = "eventarc";
|
|
18
18
|
Emulators["DATACONNECT"] = "dataconnect";
|
|
19
|
+
Emulators["TASKS"] = "tasks";
|
|
19
20
|
})(Emulators = exports.Emulators || (exports.Emulators = {}));
|
|
20
21
|
exports.DOWNLOADABLE_EMULATORS = [
|
|
21
22
|
Emulators.FIRESTORE,
|
|
@@ -41,6 +42,7 @@ exports.ALL_SERVICE_EMULATORS = [
|
|
|
41
42
|
Emulators.STORAGE,
|
|
42
43
|
Emulators.EVENTARC,
|
|
43
44
|
Emulators.DATACONNECT,
|
|
45
|
+
Emulators.TASKS,
|
|
44
46
|
].filter((v) => v);
|
|
45
47
|
exports.EMULATORS_SUPPORTED_BY_FUNCTIONS = [
|
|
46
48
|
Emulators.FIRESTORE,
|
|
@@ -48,6 +50,7 @@ exports.EMULATORS_SUPPORTED_BY_FUNCTIONS = [
|
|
|
48
50
|
Emulators.PUBSUB,
|
|
49
51
|
Emulators.STORAGE,
|
|
50
52
|
Emulators.EVENTARC,
|
|
53
|
+
Emulators.TASKS,
|
|
51
54
|
];
|
|
52
55
|
exports.EMULATORS_SUPPORTED_BY_UI = [
|
|
53
56
|
Emulators.AUTH,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.askForEventArcLocation = exports.askShouldCollectEventsConfig = exports.askForAllowedEventTypes = exports.askForEventsConfig = exports.checkAllowedEventTypesResponse = void 0;
|
|
3
|
+
exports.askForEventArcLocation = exports.EXTENSIONS_DEFAULT_EVENT_ARC_REGION = exports.ALLOWED_EVENT_ARC_REGIONS = exports.askShouldCollectEventsConfig = exports.askForAllowedEventTypes = exports.getEventArcChannel = exports.askForEventsConfig = exports.checkAllowedEventTypesResponse = void 0;
|
|
4
4
|
const prompt_1 = require("../prompt");
|
|
5
5
|
const extensionsApi = require("../extensions/extensionsApi");
|
|
6
6
|
const utils = require("../utils");
|
|
@@ -22,7 +22,7 @@ function checkAllowedEventTypesResponse(response, validEvents) {
|
|
|
22
22
|
}
|
|
23
23
|
exports.checkAllowedEventTypesResponse = checkAllowedEventTypesResponse;
|
|
24
24
|
async function askForEventsConfig(events, projectId, instanceId) {
|
|
25
|
-
logger_1.logger.info(`\n${clc.bold("Enable Events")}: ${(0, marked_1.marked)("If you enable events, you can write custom event handlers ([https://firebase.google.com/docs/extensions/install-extensions#eventarc](https://firebase.google.com/docs/extensions/install-extensions#eventarc)) that respond to these events.\n\nYou can always enable or disable events later. Events will be emitted via Eventarc. Fees apply ([https://cloud.google.com/eventarc/pricing](https://cloud.google.com/eventarc/pricing)).")}`);
|
|
25
|
+
logger_1.logger.info(`\n${clc.bold("Enable Events")}: ${await (0, marked_1.marked)("If you enable events, you can write custom event handlers ([https://firebase.google.com/docs/extensions/install-extensions#eventarc](https://firebase.google.com/docs/extensions/install-extensions#eventarc)) that respond to these events.\n\nYou can always enable or disable events later. Events will be emitted via Eventarc. Fees apply ([https://cloud.google.com/eventarc/pricing](https://cloud.google.com/eventarc/pricing)).")}`);
|
|
26
26
|
if (!(await askShouldCollectEventsConfig())) {
|
|
27
27
|
return undefined;
|
|
28
28
|
}
|
|
@@ -37,11 +37,15 @@ async function askForEventsConfig(events, projectId, instanceId) {
|
|
|
37
37
|
const preselectedTypes = existingInstance?.config.allowedEventTypes ?? [];
|
|
38
38
|
const oldLocation = existingInstance?.config.eventarcChannel?.split("/")[3];
|
|
39
39
|
const location = await askForEventArcLocation(oldLocation);
|
|
40
|
-
const channel =
|
|
40
|
+
const channel = getEventArcChannel(projectId, location);
|
|
41
41
|
const allowedEventTypes = await askForAllowedEventTypes(events, preselectedTypes);
|
|
42
42
|
return { channel, allowedEventTypes };
|
|
43
43
|
}
|
|
44
44
|
exports.askForEventsConfig = askForEventsConfig;
|
|
45
|
+
function getEventArcChannel(projectId, location) {
|
|
46
|
+
return `projects/${projectId}/locations/${location}/channels/firebase`;
|
|
47
|
+
}
|
|
48
|
+
exports.getEventArcChannel = getEventArcChannel;
|
|
45
49
|
async function askForAllowedEventTypes(eventDescriptors, preselectedTypes) {
|
|
46
50
|
let valid = false;
|
|
47
51
|
let response = [];
|
|
@@ -74,21 +78,27 @@ async function askShouldCollectEventsConfig() {
|
|
|
74
78
|
});
|
|
75
79
|
}
|
|
76
80
|
exports.askShouldCollectEventsConfig = askShouldCollectEventsConfig;
|
|
81
|
+
exports.ALLOWED_EVENT_ARC_REGIONS = [
|
|
82
|
+
"us-central1",
|
|
83
|
+
"us-west1",
|
|
84
|
+
"europe-west4",
|
|
85
|
+
"asia-northeast1",
|
|
86
|
+
];
|
|
87
|
+
exports.EXTENSIONS_DEFAULT_EVENT_ARC_REGION = "us-central1";
|
|
77
88
|
async function askForEventArcLocation(preselectedLocation) {
|
|
78
89
|
let valid = false;
|
|
79
|
-
const allowedRegions = ["us-central1", "us-west1", "europe-west4", "asia-northeast1"];
|
|
80
90
|
let location = "";
|
|
81
91
|
while (!valid) {
|
|
82
92
|
location = await (0, prompt_1.promptOnce)({
|
|
83
93
|
name: "input",
|
|
84
94
|
type: "list",
|
|
85
|
-
default: preselectedLocation ??
|
|
95
|
+
default: preselectedLocation ?? exports.EXTENSIONS_DEFAULT_EVENT_ARC_REGION,
|
|
86
96
|
message: "Which location would you like the Eventarc channel to live in? We recommend using the default option. A channel location that differs from the extension's Cloud Functions location can incur egress cost.",
|
|
87
|
-
choices:
|
|
97
|
+
choices: exports.ALLOWED_EVENT_ARC_REGIONS.map((e) => ({ checked: false, value: e })),
|
|
88
98
|
});
|
|
89
|
-
valid =
|
|
99
|
+
valid = exports.ALLOWED_EVENT_ARC_REGIONS.includes(location);
|
|
90
100
|
if (!valid) {
|
|
91
|
-
utils.logWarning(`Unexpected EventArc region '${location}' was specified. Allowed regions: ${
|
|
101
|
+
utils.logWarning(`Unexpected EventArc region '${location}' was specified. Allowed regions: ${exports.ALLOWED_EVENT_ARC_REGIONS.join(", ")}`);
|
|
92
102
|
}
|
|
93
103
|
}
|
|
94
104
|
return location;
|
|
@@ -254,7 +254,7 @@ async function promptReconfigureSecret(projectId, instanceId, paramSpec) {
|
|
|
254
254
|
],
|
|
255
255
|
});
|
|
256
256
|
switch (action) {
|
|
257
|
-
case SecretUpdateAction.SET_NEW:
|
|
257
|
+
case SecretUpdateAction.SET_NEW: {
|
|
258
258
|
let secret;
|
|
259
259
|
let secretName;
|
|
260
260
|
if (paramSpec.default) {
|
|
@@ -287,6 +287,7 @@ async function promptReconfigureSecret(projectId, instanceId, paramSpec) {
|
|
|
287
287
|
else {
|
|
288
288
|
return "";
|
|
289
289
|
}
|
|
290
|
+
}
|
|
290
291
|
case SecretUpdateAction.LEAVE:
|
|
291
292
|
default:
|
|
292
293
|
return paramSpec.default || "";
|
|
@@ -49,7 +49,7 @@ async function displayExtensionVersionInfo(args) {
|
|
|
49
49
|
if (extensionVersion.buildSourceUri) {
|
|
50
50
|
const buildSourceUri = new URL(extensionVersion.buildSourceUri);
|
|
51
51
|
buildSourceUri.pathname = path.join(buildSourceUri.pathname, extensionVersion.extensionRoot ?? "");
|
|
52
|
-
lines.push(`${clc.bold("Source in GitHub:")} ${buildSourceUri}`);
|
|
52
|
+
lines.push(`${clc.bold("Source in GitHub:")} ${buildSourceUri.toString()}`);
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
lines.push(`${clc.bold("Source download URI:")} ${extensionVersion.sourceDownloadUri ?? "-"}`);
|
|
@@ -101,24 +101,24 @@ function displayResources(spec) {
|
|
|
101
101
|
break;
|
|
102
102
|
default:
|
|
103
103
|
}
|
|
104
|
-
return ` - ${clc.
|
|
104
|
+
return ` - ${clc.blueBright(`${resource.name} (${type})`)}${resource.description ? `: ${resource.description}` : ""}`;
|
|
105
105
|
});
|
|
106
106
|
lines.push(...new Set(spec.lifecycleEvents?.map((event) => {
|
|
107
|
-
return ` - ${clc.
|
|
107
|
+
return ` - ${clc.blueBright(`${event.taskQueueTriggerFunction} (Cloud Task queue)`)}`;
|
|
108
108
|
})));
|
|
109
109
|
lines.push(...spec.params
|
|
110
110
|
.filter((param) => {
|
|
111
111
|
return param.type === "SECRET";
|
|
112
112
|
})
|
|
113
113
|
.map((param) => {
|
|
114
|
-
return ` - ${clc.
|
|
114
|
+
return ` - ${clc.blueBright(`${param.param} (Cloud Secret Manager secret)`)}`;
|
|
115
115
|
}));
|
|
116
116
|
return clc.bold("Resources created:\n") + (lines.length ? lines.join("\n") : " - None");
|
|
117
117
|
}
|
|
118
118
|
exports.displayResources = displayResources;
|
|
119
119
|
async function retrieveRoleInfo(role) {
|
|
120
120
|
const res = await iam.getRole(role);
|
|
121
|
-
return ` - ${clc.yellow(res.title)}${res.description ? `: ${res.description}` : ""}`;
|
|
121
|
+
return ` - ${clc.yellow(res.title || res.name)}${res.description ? `: ${res.description}` : ""}`;
|
|
122
122
|
}
|
|
123
123
|
exports.retrieveRoleInfo = retrieveRoleInfo;
|
|
124
124
|
async function displayRoles(roles) {
|
|
@@ -351,6 +351,6 @@ function refNotFoundError(ref) {
|
|
|
351
351
|
return new error_1.FirebaseError(`The extension reference '${clc.bold(ref.version ? refs.toExtensionVersionRef(ref) : refs.toExtensionRef(ref))}' doesn't exist. This could happen for two reasons:\n` +
|
|
352
352
|
` -The publisher ID '${clc.bold(ref.publisherId)}' doesn't exist or could be misspelled\n` +
|
|
353
353
|
` -The name of the ${ref.version ? "extension version" : "extension"} '${clc.bold(ref.version ? `${ref.extensionId}@${ref.version}` : ref.extensionId)}' doesn't exist or could be misspelled\n\n` +
|
|
354
|
-
`Please correct the extension reference and try again. If you meant to
|
|
354
|
+
`Please correct the extension reference and try again. If you meant to reference an extension from a local source, please provide a relative path prefixed with '${clc.bold("./")}', '${clc.bold("../")}', or '${clc.bold("~/")}'.}`, { status: 404 });
|
|
355
355
|
}
|
|
356
356
|
exports.refNotFoundError = refNotFoundError;
|
|
@@ -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.promptForExtensionRoot = exports.promptForValidRepoURI = exports.promptForValidInstanceId = exports.validateSpec = exports.validateCommandLineParams = exports.populateDefaultParams = exports.substituteParams = exports.getFirebaseProjectParams = exports.getDBInstanceFromURL = exports.resourceTypeToNiceName = exports.AUTOPOULATED_PARAM_PLACEHOLDERS = exports.EXTENSIONS_BUCKET_NAME = exports.URL_REGEX = exports.logPrefix = exports.SourceOrigin = exports.SpecParamType = void 0;
|
|
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.AUTOPOULATED_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");
|
|
@@ -125,6 +125,20 @@ function substituteParams(original, params) {
|
|
|
125
125
|
return JSON.parse(s);
|
|
126
126
|
}
|
|
127
127
|
exports.substituteParams = substituteParams;
|
|
128
|
+
async function substituteSecretParams(projectNumber, params) {
|
|
129
|
+
const newParams = {};
|
|
130
|
+
for await (const [key, value] of Object.entries(params)) {
|
|
131
|
+
if (typeof value !== "string") {
|
|
132
|
+
newParams[key] =
|
|
133
|
+
`projects/${projectNumber}/secrets/${value.name}/versions/latest`;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
newParams[key] = value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return newParams;
|
|
140
|
+
}
|
|
141
|
+
exports.substituteSecretParams = substituteSecretParams;
|
|
128
142
|
function populateDefaultParams(paramVars, paramSpecs) {
|
|
129
143
|
const newParams = paramVars;
|
|
130
144
|
for (const param of paramSpecs) {
|
|
@@ -345,6 +359,14 @@ async function promptForReleaseStage(args) {
|
|
|
345
359
|
}
|
|
346
360
|
return stage;
|
|
347
361
|
}
|
|
362
|
+
async function checkExtensionsApiEnabled(options) {
|
|
363
|
+
const projectId = (0, projectUtils_1.getProjectId)(options);
|
|
364
|
+
if (!projectId) {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
return await (0, ensureApiEnabled_1.check)(projectId, (0, api_1.extensionsOrigin)(), "extensions", options.markdown);
|
|
368
|
+
}
|
|
369
|
+
exports.checkExtensionsApiEnabled = checkExtensionsApiEnabled;
|
|
348
370
|
async function ensureExtensionsApiEnabled(options) {
|
|
349
371
|
const projectId = (0, projectUtils_1.getProjectId)(options);
|
|
350
372
|
if (!projectId) {
|
|
@@ -470,7 +492,7 @@ function displayExtensionHeader(extensionRef, extension, extensionRoot) {
|
|
|
470
492
|
}
|
|
471
493
|
else {
|
|
472
494
|
logger_1.logger.info(`\n${clc.bold("Extension:")} ${extensionRef}\n` +
|
|
473
|
-
`${clc.bold("State:")} ${clc.bold(clc.
|
|
495
|
+
`${clc.bold("State:")} ${clc.bold(clc.blueBright("New"))}\n`);
|
|
474
496
|
}
|
|
475
497
|
}
|
|
476
498
|
async function fetchExtensionSource(repoUri, sourceRef, extensionRoot) {
|
|
@@ -791,7 +813,7 @@ async function instanceIdExists(projectId, instanceId) {
|
|
|
791
813
|
if (err.status === 404) {
|
|
792
814
|
return false;
|
|
793
815
|
}
|
|
794
|
-
const msg = `Unexpected error when checking if instance ID exists: ${err}`;
|
|
816
|
+
const msg = `Unexpected error when checking if instance ID exists: ${err.message}`;
|
|
795
817
|
throw new error_1.FirebaseError(msg, {
|
|
796
818
|
original: err,
|
|
797
819
|
});
|
|
@@ -38,7 +38,7 @@ function readFile(pathToFile) {
|
|
|
38
38
|
}
|
|
39
39
|
catch (err) {
|
|
40
40
|
if (err.code === "ENOENT") {
|
|
41
|
-
throw new error_1.FirebaseError(`Could not find "${pathToFile}"
|
|
41
|
+
throw new error_1.FirebaseError(`Could not find "${pathToFile}"`, { original: err });
|
|
42
42
|
}
|
|
43
43
|
throw new error_1.FirebaseError(`Failed to read file at "${pathToFile}"`, { original: err });
|
|
44
44
|
}
|
package/lib/extensions/refs.js
CHANGED
|
@@ -7,13 +7,16 @@ const refRegex = new RegExp(/^([^/@\n]+)\/{1}([^/@\n]+)(@{1}([^\n]+)|)$/);
|
|
|
7
7
|
function parse(refOrName) {
|
|
8
8
|
const ret = parseRef(refOrName) || parseName(refOrName);
|
|
9
9
|
if (!ret || !ret.publisherId || !ret.extensionId) {
|
|
10
|
-
throw new error_1.FirebaseError(`Unable to parse ${refOrName} as an extension ref`
|
|
10
|
+
throw new error_1.FirebaseError(`Unable to parse ${refOrName} as an extension ref.\n` +
|
|
11
|
+
"Expected format is either publisherId/extensionId@version or " +
|
|
12
|
+
"publishers/publisherId/extensions/extensionId/versions/version. If you " +
|
|
13
|
+
"are referring to a local extension directory, please ensure the directory exists.");
|
|
11
14
|
}
|
|
12
15
|
if (ret.version &&
|
|
13
16
|
!semver.valid(ret.version) &&
|
|
14
17
|
!semver.validRange(ret.version) &&
|
|
15
18
|
!["latest", "latest-approved"].includes(ret.version)) {
|
|
16
|
-
throw new error_1.FirebaseError(`Extension reference ${ret} contains an invalid version ${ret.version}.`);
|
|
19
|
+
throw new error_1.FirebaseError(`Extension reference ${JSON.stringify(ret, null, 2)} contains an invalid version ${ret.version}.`);
|
|
17
20
|
}
|
|
18
21
|
return ret;
|
|
19
22
|
}
|
|
@@ -21,19 +24,31 @@ exports.parse = parse;
|
|
|
21
24
|
function parseRef(ref) {
|
|
22
25
|
const parts = refRegex.exec(ref);
|
|
23
26
|
if (parts && (parts.length === 5 || parts.length === 7)) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
return {
|
|
28
|
+
publisherId: parts[1],
|
|
29
|
+
extensionId: parts[2],
|
|
30
|
+
version: parts[4],
|
|
31
|
+
};
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
function parseName(name) {
|
|
31
35
|
const parts = name.split("/");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
if (parts[0] !== "publishers" || parts[2] !== "extensions") {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (parts.length === 4) {
|
|
40
|
+
return {
|
|
41
|
+
publisherId: parts[1],
|
|
42
|
+
extensionId: parts[3],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (parts.length === 6 && parts[4] === "versions") {
|
|
46
|
+
return {
|
|
47
|
+
publisherId: parts[1],
|
|
48
|
+
extensionId: parts[3],
|
|
49
|
+
version: parts[5],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
37
52
|
}
|
|
38
53
|
function toExtensionRef(ref) {
|
|
39
54
|
return `${ref.publisherId}/${ref.extensionId}`;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractExtensionsFromBuilds = exports.extractAllDynamicExtensions = void 0;
|
|
4
|
+
const projectConfig_1 = require("../../functions/projectConfig");
|
|
5
|
+
const prepare_1 = require("../../deploy/functions/prepare");
|
|
6
|
+
const functionsConfig_1 = require("../../functionsConfig");
|
|
7
|
+
const functionsDeployHelper_1 = require("../../deploy/functions/functionsDeployHelper");
|
|
8
|
+
const logger_1 = require("../../logger");
|
|
9
|
+
const savedLoggerSilent = logger_1.logger.silent;
|
|
10
|
+
function silenceLogging() {
|
|
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);
|
|
34
|
+
}
|
|
35
|
+
exports.extractAllDynamicExtensions = extractAllDynamicExtensions;
|
|
36
|
+
function extractExtensionsFromBuilds(builds, filters) {
|
|
37
|
+
const extRecords = {};
|
|
38
|
+
for (const [codebase, build] of Object.entries(builds)) {
|
|
39
|
+
if (build.extensions) {
|
|
40
|
+
for (const [id, ext] of Object.entries(build.extensions)) {
|
|
41
|
+
if (extensionMatchesAnyFilter(codebase, id, filters)) {
|
|
42
|
+
extRecords[id] = ext;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return extRecords;
|
|
48
|
+
}
|
|
49
|
+
exports.extractExtensionsFromBuilds = extractExtensionsFromBuilds;
|
|
50
|
+
function extensionMatchesAnyFilter(codebase, extensionId, filters) {
|
|
51
|
+
if (!filters) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return filters.some((f) => extensionMatchesFilter(codebase, extensionId, f));
|
|
55
|
+
}
|
|
56
|
+
function extensionMatchesFilter(codebase, extensionId, filter) {
|
|
57
|
+
if (codebase && filter.codebase) {
|
|
58
|
+
if (codebase !== filter.codebase) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (!filter.idChunks) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
const idChunks = extensionId.split("-");
|
|
66
|
+
if (idChunks.length < filter.idChunks.length) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
for (let i = 0; i < filter.idChunks.length; i++) {
|
|
70
|
+
if (idChunks[i] !== filter.idChunks[i]) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|