firebase-tools 11.7.0 → 11.8.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/deploy/functions/build.js +2 -2
- package/lib/deploy/functions/params.js +7 -1
- package/lib/deploy/functions/prepare.js +1 -1
- package/lib/emulator/storage/apis/firebase.js +139 -125
- package/lib/emulator/storage/apis/gcloud.js +102 -42
- package/lib/emulator/storage/files.js +25 -15
- package/lib/emulator/storage/metadata.js +76 -55
- package/lib/emulator/storage/rules/runtime.js +10 -2
- package/lib/emulator/storage/upload.js +45 -9
- package/lib/functions/constants.js +14 -0
- package/lib/gcp/cloudfunctions.js +15 -18
- package/lib/gcp/cloudfunctionsv2.js +15 -18
- package/lib/gcp/cloudscheduler.js +2 -1
- package/lib/track.js +1 -1
- package/npm-shrinkwrap.json +33 -9
- package/package.json +4 -4
|
@@ -7,19 +7,19 @@ const registry_1 = require("../registry");
|
|
|
7
7
|
const types_1 = require("../types");
|
|
8
8
|
const crc_1 = require("./crc");
|
|
9
9
|
class StoredFileMetadata {
|
|
10
|
-
constructor(opts, _cloudFunctions, bytes
|
|
10
|
+
constructor(opts, _cloudFunctions, bytes) {
|
|
11
11
|
this._cloudFunctions = _cloudFunctions;
|
|
12
12
|
this.name = opts.name;
|
|
13
13
|
this.bucket = opts.bucket;
|
|
14
|
-
this.contentType = opts.contentType;
|
|
15
14
|
this.metageneration = opts.metageneration || 1;
|
|
16
15
|
this.generation = opts.generation || Date.now();
|
|
16
|
+
this.contentType = opts.contentType || "application/octet-stream";
|
|
17
17
|
this.storageClass = opts.storageClass || "STANDARD";
|
|
18
|
-
this.contentDisposition = opts.contentDisposition
|
|
19
|
-
this.cacheControl = opts.cacheControl
|
|
18
|
+
this.contentDisposition = opts.contentDisposition;
|
|
19
|
+
this.cacheControl = opts.cacheControl;
|
|
20
20
|
this.contentLanguage = opts.contentLanguage;
|
|
21
21
|
this.customTime = opts.customTime;
|
|
22
|
-
this.contentEncoding = opts.contentEncoding
|
|
22
|
+
this.contentEncoding = opts.contentEncoding;
|
|
23
23
|
this.customMetadata = opts.customMetadata;
|
|
24
24
|
this.downloadTokens = opts.downloadTokens || [];
|
|
25
25
|
if (opts.etag) {
|
|
@@ -43,42 +43,54 @@ class StoredFileMetadata {
|
|
|
43
43
|
else {
|
|
44
44
|
throw new Error("Must pass bytes array or opts object with size, md5hash, and crc32c");
|
|
45
45
|
}
|
|
46
|
-
if (incomingMetadata) {
|
|
47
|
-
this.update(incomingMetadata, false);
|
|
48
|
-
}
|
|
49
46
|
this.deleteFieldsSetAsNull();
|
|
50
47
|
this.setDownloadTokensFromCustomMetadata();
|
|
51
48
|
}
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
clone() {
|
|
50
|
+
const clone = new StoredFileMetadata({
|
|
54
51
|
name: this.name,
|
|
55
52
|
bucket: this.bucket,
|
|
56
53
|
generation: this.generation,
|
|
57
54
|
metageneration: this.metageneration,
|
|
55
|
+
contentType: this.contentType,
|
|
56
|
+
storageClass: this.storageClass,
|
|
58
57
|
size: this.size,
|
|
59
|
-
timeCreated: this.timeCreated,
|
|
60
|
-
updated: this.updated,
|
|
61
58
|
md5Hash: this.md5Hash,
|
|
59
|
+
contentEncoding: this.contentEncoding,
|
|
60
|
+
contentDisposition: this.contentDisposition,
|
|
61
|
+
contentLanguage: this.contentLanguage,
|
|
62
|
+
cacheControl: this.cacheControl,
|
|
63
|
+
customTime: this.customTime,
|
|
62
64
|
crc32c: this.crc32c,
|
|
63
65
|
etag: this.etag,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
downloadTokens: this.downloadTokens,
|
|
67
|
+
customMetadata: this.customMetadata,
|
|
68
|
+
}, this._cloudFunctions);
|
|
69
|
+
clone.timeCreated = this.timeCreated;
|
|
70
|
+
clone.updated = this.updated;
|
|
71
|
+
return clone;
|
|
72
|
+
}
|
|
73
|
+
asRulesResource(proposedChanges) {
|
|
74
|
+
const proposedMetadata = this.clone();
|
|
69
75
|
if (proposedChanges) {
|
|
70
|
-
|
|
71
|
-
rulesResource.generation = Date.now();
|
|
72
|
-
rulesResource.metageneration = 1;
|
|
73
|
-
rulesResource.timeCreated = new Date();
|
|
74
|
-
rulesResource.updated = rulesResource.timeCreated;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
rulesResource.metageneration++;
|
|
78
|
-
}
|
|
79
|
-
rulesResource = Object.assign(Object.assign({}, rulesResource), proposedChanges);
|
|
76
|
+
proposedMetadata.update(proposedChanges, false);
|
|
80
77
|
}
|
|
81
|
-
return
|
|
78
|
+
return {
|
|
79
|
+
name: proposedMetadata.name,
|
|
80
|
+
bucket: proposedMetadata.bucket,
|
|
81
|
+
generation: proposedMetadata.generation,
|
|
82
|
+
metageneration: proposedMetadata.metageneration,
|
|
83
|
+
size: proposedMetadata.size,
|
|
84
|
+
timeCreated: proposedMetadata.timeCreated,
|
|
85
|
+
updated: proposedMetadata.updated,
|
|
86
|
+
md5Hash: proposedMetadata.md5Hash,
|
|
87
|
+
crc32c: proposedMetadata.crc32c,
|
|
88
|
+
etag: proposedMetadata.etag,
|
|
89
|
+
contentDisposition: proposedMetadata.contentDisposition,
|
|
90
|
+
contentEncoding: proposedMetadata.contentEncoding,
|
|
91
|
+
contentType: proposedMetadata.contentType,
|
|
92
|
+
metadata: proposedMetadata.customMetadata || {},
|
|
93
|
+
};
|
|
82
94
|
}
|
|
83
95
|
setDownloadTokensFromCustomMetadata() {
|
|
84
96
|
if (!this.customMetadata) {
|
|
@@ -118,43 +130,52 @@ class StoredFileMetadata {
|
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
132
|
update(incoming, shouldTrigger = true) {
|
|
121
|
-
if (incoming.contentDisposition) {
|
|
122
|
-
this.contentDisposition =
|
|
133
|
+
if (incoming.contentDisposition !== undefined) {
|
|
134
|
+
this.contentDisposition =
|
|
135
|
+
incoming.contentDisposition === null ? undefined : incoming.contentDisposition;
|
|
123
136
|
}
|
|
124
|
-
if (incoming.contentType) {
|
|
125
|
-
this.contentType = incoming.contentType;
|
|
137
|
+
if (incoming.contentType !== undefined) {
|
|
138
|
+
this.contentType = incoming.contentType === null ? undefined : incoming.contentType;
|
|
126
139
|
}
|
|
127
|
-
if (incoming.
|
|
128
|
-
this.
|
|
129
|
-
|
|
130
|
-
this.customMetadata[k] = v === null ? null : String(v);
|
|
131
|
-
}
|
|
140
|
+
if (incoming.contentLanguage !== undefined) {
|
|
141
|
+
this.contentLanguage =
|
|
142
|
+
incoming.contentLanguage === null ? undefined : incoming.contentLanguage;
|
|
132
143
|
}
|
|
133
|
-
if (incoming.
|
|
134
|
-
this.
|
|
144
|
+
if (incoming.contentEncoding !== undefined) {
|
|
145
|
+
this.contentEncoding =
|
|
146
|
+
incoming.contentEncoding === null ? undefined : incoming.contentEncoding;
|
|
135
147
|
}
|
|
136
|
-
if (incoming.
|
|
137
|
-
this.
|
|
148
|
+
if (incoming.cacheControl !== undefined) {
|
|
149
|
+
this.cacheControl = incoming.cacheControl === null ? undefined : incoming.cacheControl;
|
|
138
150
|
}
|
|
139
|
-
if (
|
|
140
|
-
|
|
151
|
+
if (incoming.metadata !== undefined) {
|
|
152
|
+
if (incoming.metadata === null) {
|
|
153
|
+
this.customMetadata = undefined;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
this.customMetadata = this.customMetadata || {};
|
|
157
|
+
for (const [k, v] of Object.entries(incoming.metadata)) {
|
|
158
|
+
if (v === null) {
|
|
159
|
+
delete this.customMetadata[k];
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this.customMetadata[k] = String(v);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (Object.keys(this.customMetadata).length === 0) {
|
|
166
|
+
this.customMetadata = undefined;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
141
169
|
}
|
|
170
|
+
this.metageneration++;
|
|
142
171
|
this.updated = new Date();
|
|
143
|
-
if (incoming.cacheControl) {
|
|
144
|
-
this.cacheControl = incoming.cacheControl;
|
|
145
|
-
}
|
|
146
172
|
this.setDownloadTokensFromCustomMetadata();
|
|
147
|
-
this.deleteFieldsSetAsNull();
|
|
148
173
|
if (shouldTrigger) {
|
|
149
174
|
this._cloudFunctions.dispatch("metadataUpdate", new CloudStorageObjectMetadata(this));
|
|
150
175
|
}
|
|
151
176
|
}
|
|
152
177
|
addDownloadToken(shouldTrigger = true) {
|
|
153
|
-
|
|
154
|
-
this.downloadTokens.push(uuid.v4());
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
this.downloadTokens = [...this.downloadTokens, uuid.v4()];
|
|
178
|
+
this.downloadTokens = [...(this.downloadTokens || []), uuid.v4()];
|
|
158
179
|
this.update({}, shouldTrigger);
|
|
159
180
|
}
|
|
160
181
|
deleteDownloadToken(token) {
|
|
@@ -197,7 +218,7 @@ class OutgoingFirebaseMetadata {
|
|
|
197
218
|
this.crc32c = metadata.crc32c;
|
|
198
219
|
this.etag = metadata.etag;
|
|
199
220
|
this.downloadTokens = metadata.downloadTokens.join(",");
|
|
200
|
-
this.contentEncoding = metadata.contentEncoding;
|
|
221
|
+
this.contentEncoding = metadata.contentEncoding || "identity";
|
|
201
222
|
this.contentDisposition = metadata.contentDisposition;
|
|
202
223
|
this.metadata = metadata.customMetadata;
|
|
203
224
|
this.contentLanguage = metadata.contentLanguage;
|
|
@@ -208,7 +229,7 @@ exports.OutgoingFirebaseMetadata = OutgoingFirebaseMetadata;
|
|
|
208
229
|
class CloudStorageBucketMetadata {
|
|
209
230
|
constructor(id) {
|
|
210
231
|
var _a, _b;
|
|
211
|
-
this.kind = "#
|
|
232
|
+
this.kind = "storage#bucket";
|
|
212
233
|
this.name = id;
|
|
213
234
|
this.id = id;
|
|
214
235
|
this.selfLink = `http://${(_a = registry_1.EmulatorRegistry.getInfo(types_1.Emulators.STORAGE)) === null || _a === void 0 ? void 0 : _a.host}:${(_b = registry_1.EmulatorRegistry.getInfo(types_1.Emulators.STORAGE)) === null || _b === void 0 ? void 0 : _b.port}/v1/b/${this.id}`;
|
|
@@ -240,7 +261,7 @@ exports.CloudStorageObjectAccessControlMetadata = CloudStorageObjectAccessContro
|
|
|
240
261
|
class CloudStorageObjectMetadata {
|
|
241
262
|
constructor(metadata) {
|
|
242
263
|
var _a, _b, _c, _d;
|
|
243
|
-
this.kind = "
|
|
264
|
+
this.kind = "storage#object";
|
|
244
265
|
this.name = metadata.name;
|
|
245
266
|
this.bucket = metadata.bucket;
|
|
246
267
|
this.generation = metadata.generation.toString();
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.StorageRulesRuntime = exports.StorageRulesIssues = exports.StorageRulesetInstance = void 0;
|
|
4
4
|
const cross_spawn_1 = require("cross-spawn");
|
|
5
5
|
const error_1 = require("../../../error");
|
|
6
|
+
const AsyncLock = require("async-lock");
|
|
6
7
|
const types_1 = require("./types");
|
|
7
8
|
const jwt = require("jsonwebtoken");
|
|
8
9
|
const emulatorLogger_1 = require("../../emulatorLogger");
|
|
@@ -13,6 +14,8 @@ const constants_1 = require("../../constants");
|
|
|
13
14
|
const download_1 = require("../../download");
|
|
14
15
|
const fs = require("fs-extra");
|
|
15
16
|
const downloadableEmulators_1 = require("../../downloadableEmulators");
|
|
17
|
+
const lock = new AsyncLock();
|
|
18
|
+
const synchonizationKey = "key";
|
|
16
19
|
class StorageRulesetInstance {
|
|
17
20
|
constructor(runtime, rulesVersion, rulesetName) {
|
|
18
21
|
this.runtime = runtime;
|
|
@@ -154,13 +157,18 @@ class StorageRulesRuntime {
|
|
|
154
157
|
throw new error_1.FirebaseError("Attempted to send Cloud Storage rules request with stale id");
|
|
155
158
|
}
|
|
156
159
|
return new Promise((resolve) => {
|
|
157
|
-
var _a, _b;
|
|
158
160
|
this._requests[runtimeActionRequest.id] = {
|
|
159
161
|
request: runtimeActionRequest,
|
|
160
162
|
handler: resolve,
|
|
161
163
|
};
|
|
162
164
|
const serializedRequest = JSON.stringify(runtimeActionRequest);
|
|
163
|
-
(
|
|
165
|
+
lock.acquire(synchonizationKey, (done) => {
|
|
166
|
+
var _a, _b;
|
|
167
|
+
(_b = (_a = this._childprocess) === null || _a === void 0 ? void 0 : _a.stdin) === null || _b === void 0 ? void 0 : _b.write(serializedRequest + "\n");
|
|
168
|
+
setTimeout(() => {
|
|
169
|
+
done();
|
|
170
|
+
}, 15);
|
|
171
|
+
});
|
|
164
172
|
});
|
|
165
173
|
}
|
|
166
174
|
async loadRuleset(source) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UploadService = exports.NotCancellableError = exports.UploadNotActiveError = exports.UploadStatus = exports.UploadType = void 0;
|
|
3
|
+
exports.UploadService = exports.NotCancellableError = exports.UploadPreviouslyFinalizedError = exports.UploadNotActiveError = exports.UploadStatus = exports.UploadType = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const errors_1 = require("./errors");
|
|
6
6
|
var UploadType;
|
|
7
7
|
(function (UploadType) {
|
|
8
|
-
UploadType[UploadType["
|
|
9
|
-
UploadType[UploadType["
|
|
8
|
+
UploadType[UploadType["MEDIA"] = 0] = "MEDIA";
|
|
9
|
+
UploadType[UploadType["MULTIPART"] = 1] = "MULTIPART";
|
|
10
|
+
UploadType[UploadType["RESUMABLE"] = 2] = "RESUMABLE";
|
|
10
11
|
})(UploadType = exports.UploadType || (exports.UploadType = {}));
|
|
11
12
|
var UploadStatus;
|
|
12
13
|
(function (UploadStatus) {
|
|
@@ -17,6 +18,9 @@ var UploadStatus;
|
|
|
17
18
|
class UploadNotActiveError extends Error {
|
|
18
19
|
}
|
|
19
20
|
exports.UploadNotActiveError = UploadNotActiveError;
|
|
21
|
+
class UploadPreviouslyFinalizedError extends Error {
|
|
22
|
+
}
|
|
23
|
+
exports.UploadPreviouslyFinalizedError = UploadPreviouslyFinalizedError;
|
|
20
24
|
class NotCancellableError extends Error {
|
|
21
25
|
}
|
|
22
26
|
exports.NotCancellableError = NotCancellableError;
|
|
@@ -28,23 +32,42 @@ class UploadService {
|
|
|
28
32
|
reset() {
|
|
29
33
|
this._uploads = new Map();
|
|
30
34
|
}
|
|
35
|
+
mediaUpload(request) {
|
|
36
|
+
const upload = this.startOneShotUpload({
|
|
37
|
+
bucketId: request.bucketId,
|
|
38
|
+
objectId: request.objectId,
|
|
39
|
+
uploadType: UploadType.MEDIA,
|
|
40
|
+
dataRaw: request.dataRaw,
|
|
41
|
+
authorization: request.authorization,
|
|
42
|
+
});
|
|
43
|
+
this._persistence.deleteFile(upload.path, true);
|
|
44
|
+
this._persistence.appendBytes(upload.path, request.dataRaw);
|
|
45
|
+
return upload;
|
|
46
|
+
}
|
|
31
47
|
multipartUpload(request) {
|
|
32
|
-
const upload = this.
|
|
48
|
+
const upload = this.startOneShotUpload({
|
|
49
|
+
bucketId: request.bucketId,
|
|
50
|
+
objectId: request.objectId,
|
|
51
|
+
uploadType: UploadType.MULTIPART,
|
|
52
|
+
dataRaw: request.dataRaw,
|
|
53
|
+
metadata: JSON.parse(request.metadataRaw),
|
|
54
|
+
authorization: request.authorization,
|
|
55
|
+
});
|
|
33
56
|
this._persistence.deleteFile(upload.path, true);
|
|
34
57
|
this._persistence.appendBytes(upload.path, request.dataRaw);
|
|
35
58
|
return upload;
|
|
36
59
|
}
|
|
37
|
-
|
|
60
|
+
startOneShotUpload(request) {
|
|
38
61
|
const id = (0, uuid_1.v4)();
|
|
39
62
|
const upload = {
|
|
40
|
-
id
|
|
63
|
+
id,
|
|
41
64
|
bucketId: request.bucketId,
|
|
42
65
|
objectId: request.objectId,
|
|
43
|
-
type:
|
|
66
|
+
type: request.uploadType,
|
|
44
67
|
path: this.getStagingFileName(id, request.bucketId, request.objectId),
|
|
45
68
|
status: UploadStatus.FINISHED,
|
|
46
|
-
metadata:
|
|
47
|
-
size:
|
|
69
|
+
metadata: request.metadata,
|
|
70
|
+
size: request.dataRaw.byteLength,
|
|
48
71
|
authorization: request.authorization,
|
|
49
72
|
};
|
|
50
73
|
this._uploads.set(upload.id, upload);
|
|
@@ -94,12 +117,25 @@ class UploadService {
|
|
|
94
117
|
}
|
|
95
118
|
finalizeResumableUpload(uploadId) {
|
|
96
119
|
const upload = this.getResumableUpload(uploadId);
|
|
120
|
+
if (upload.status === UploadStatus.FINISHED) {
|
|
121
|
+
throw new UploadPreviouslyFinalizedError();
|
|
122
|
+
}
|
|
97
123
|
if (upload.status === UploadStatus.CANCELLED) {
|
|
98
124
|
throw new UploadNotActiveError();
|
|
99
125
|
}
|
|
100
126
|
upload.status = UploadStatus.FINISHED;
|
|
101
127
|
return upload;
|
|
102
128
|
}
|
|
129
|
+
setResponseCode(uploadId, code) {
|
|
130
|
+
const upload = this._uploads.get(uploadId);
|
|
131
|
+
if (upload) {
|
|
132
|
+
upload.prevResponseCode = code;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
getPreviousResponseCode(uploadId) {
|
|
136
|
+
var _a;
|
|
137
|
+
return ((_a = this._uploads.get(uploadId)) === null || _a === void 0 ? void 0 : _a.prevResponseCode) || 200;
|
|
138
|
+
}
|
|
103
139
|
getStagingFileName(uploadId, bucketId, objectId) {
|
|
104
140
|
return encodeURIComponent(`${uploadId}_b_${bucketId}_o_${objectId}`);
|
|
105
141
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BLOCKING_EVENT_TO_LABEL_KEY = exports.BLOCKING_LABEL_KEY_TO_EVENT = exports.BLOCKING_LABEL = exports.HASH_LABEL = exports.CODEBASE_LABEL = void 0;
|
|
4
|
+
exports.CODEBASE_LABEL = "firebase-functions-codebase";
|
|
5
|
+
exports.HASH_LABEL = "firebase-functions-hash";
|
|
6
|
+
exports.BLOCKING_LABEL = "deployment-blocking";
|
|
7
|
+
exports.BLOCKING_LABEL_KEY_TO_EVENT = {
|
|
8
|
+
"before-create": "providers/cloud.auth/eventTypes/user.beforeCreate",
|
|
9
|
+
"before-sign-in": "providers/cloud.auth/eventTypes/user.beforeSignIn",
|
|
10
|
+
};
|
|
11
|
+
exports.BLOCKING_EVENT_TO_LABEL_KEY = {
|
|
12
|
+
"providers/cloud.auth/eventTypes/user.beforeCreate": "before-create",
|
|
13
|
+
"providers/cloud.auth/eventTypes/user.beforeSignIn": "before-sign-in",
|
|
14
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.functionFromEndpoint = exports.endpointFromFunction = exports.listAllFunctions = exports.listFunctions = exports.deleteFunction = exports.updateFunction = exports.setInvokerUpdate = exports.setInvokerCreate = exports.getIamPolicy = exports.setIamPolicy = exports.createFunction = exports.generateUploadUrl = exports.
|
|
3
|
+
exports.functionFromEndpoint = exports.endpointFromFunction = exports.listAllFunctions = exports.listFunctions = exports.deleteFunction = exports.updateFunction = exports.setInvokerUpdate = exports.setInvokerCreate = exports.getIamPolicy = exports.setIamPolicy = exports.createFunction = exports.generateUploadUrl = exports.API_VERSION = void 0;
|
|
4
4
|
const clc = require("colorette");
|
|
5
5
|
const error_1 = require("../error");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
@@ -11,18 +11,9 @@ const runtimes = require("../deploy/functions/runtimes");
|
|
|
11
11
|
const projectConfig = require("../functions/projectConfig");
|
|
12
12
|
const apiv2_1 = require("../apiv2");
|
|
13
13
|
const api_1 = require("../api");
|
|
14
|
+
const constants_1 = require("../functions/constants");
|
|
14
15
|
exports.API_VERSION = "v1";
|
|
15
|
-
exports.CODEBASE_LABEL = "firebase-functions-codebase";
|
|
16
16
|
const client = new apiv2_1.Client({ urlPrefix: api_1.functionsOrigin, apiVersion: exports.API_VERSION });
|
|
17
|
-
exports.BLOCKING_LABEL = "deployment-blocking";
|
|
18
|
-
const BLOCKING_LABEL_KEY_TO_EVENT = {
|
|
19
|
-
"before-create": "providers/cloud.auth/eventTypes/user.beforeCreate",
|
|
20
|
-
"before-sign-in": "providers/cloud.auth/eventTypes/user.beforeSignIn",
|
|
21
|
-
};
|
|
22
|
-
const BLOCKING_EVENT_TO_LABEL_KEY = {
|
|
23
|
-
"providers/cloud.auth/eventTypes/user.beforeCreate": "before-create",
|
|
24
|
-
"providers/cloud.auth/eventTypes/user.beforeSignIn": "before-sign-in",
|
|
25
|
-
};
|
|
26
17
|
function functionsOpLogReject(funcName, type, err) {
|
|
27
18
|
var _a, _b;
|
|
28
19
|
if (((_b = (_a = err === null || err === void 0 ? void 0 : err.context) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.statusCode) === 429) {
|
|
@@ -199,7 +190,7 @@ async function listAllFunctions(projectId) {
|
|
|
199
190
|
}
|
|
200
191
|
exports.listAllFunctions = listAllFunctions;
|
|
201
192
|
function endpointFromFunction(gcfFunction) {
|
|
202
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
193
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
203
194
|
const [, project, , region, , id] = gcfFunction.name.split("/");
|
|
204
195
|
let trigger;
|
|
205
196
|
let uri;
|
|
@@ -220,10 +211,10 @@ function endpointFromFunction(gcfFunction) {
|
|
|
220
211
|
callableTrigger: {},
|
|
221
212
|
};
|
|
222
213
|
}
|
|
223
|
-
else if ((_e = gcfFunction.labels) === null || _e === void 0 ? void 0 : _e[
|
|
214
|
+
else if ((_e = gcfFunction.labels) === null || _e === void 0 ? void 0 : _e[constants_1.BLOCKING_LABEL]) {
|
|
224
215
|
trigger = {
|
|
225
216
|
blockingTrigger: {
|
|
226
|
-
eventType: BLOCKING_LABEL_KEY_TO_EVENT[gcfFunction.labels[
|
|
217
|
+
eventType: constants_1.BLOCKING_LABEL_KEY_TO_EVENT[gcfFunction.labels[constants_1.BLOCKING_LABEL]],
|
|
227
218
|
},
|
|
228
219
|
};
|
|
229
220
|
}
|
|
@@ -263,7 +254,10 @@ function endpointFromFunction(gcfFunction) {
|
|
|
263
254
|
endpoint.vpc = { connector: gcfFunction.vpcConnector };
|
|
264
255
|
proto.convertIfPresent(endpoint.vpc, gcfFunction, "egressSettings", "vpcConnectorEgressSettings", (raw) => raw);
|
|
265
256
|
}
|
|
266
|
-
endpoint.codebase = ((_g = gcfFunction.labels) === null || _g === void 0 ? void 0 : _g[
|
|
257
|
+
endpoint.codebase = ((_g = gcfFunction.labels) === null || _g === void 0 ? void 0 : _g[constants_1.CODEBASE_LABEL]) || projectConfig.DEFAULT_CODEBASE;
|
|
258
|
+
if ((_h = gcfFunction.labels) === null || _h === void 0 ? void 0 : _h[constants_1.HASH_LABEL]) {
|
|
259
|
+
endpoint.hash = gcfFunction.labels[constants_1.HASH_LABEL];
|
|
260
|
+
}
|
|
267
261
|
return endpoint;
|
|
268
262
|
}
|
|
269
263
|
exports.endpointFromFunction = endpointFromFunction;
|
|
@@ -312,7 +306,7 @@ function functionFromEndpoint(endpoint, sourceUploadUrl) {
|
|
|
312
306
|
}
|
|
313
307
|
else if (backend.isBlockingTriggered(endpoint)) {
|
|
314
308
|
gcfFunction.httpsTrigger = {};
|
|
315
|
-
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [
|
|
309
|
+
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [constants_1.BLOCKING_LABEL]: constants_1.BLOCKING_EVENT_TO_LABEL_KEY[endpoint.blockingTrigger.eventType] });
|
|
316
310
|
}
|
|
317
311
|
else {
|
|
318
312
|
gcfFunction.httpsTrigger = {};
|
|
@@ -337,10 +331,13 @@ function functionFromEndpoint(endpoint, sourceUploadUrl) {
|
|
|
337
331
|
}
|
|
338
332
|
const codebase = endpoint.codebase || projectConfig.DEFAULT_CODEBASE;
|
|
339
333
|
if (codebase !== projectConfig.DEFAULT_CODEBASE) {
|
|
340
|
-
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [
|
|
334
|
+
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [constants_1.CODEBASE_LABEL]: codebase });
|
|
341
335
|
}
|
|
342
336
|
else {
|
|
343
|
-
(_b = gcfFunction.labels) === null || _b === void 0 ? true : delete _b[
|
|
337
|
+
(_b = gcfFunction.labels) === null || _b === void 0 ? true : delete _b[constants_1.CODEBASE_LABEL];
|
|
338
|
+
}
|
|
339
|
+
if (endpoint.hash) {
|
|
340
|
+
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [constants_1.HASH_LABEL]: endpoint.hash });
|
|
344
341
|
}
|
|
345
342
|
return gcfFunction;
|
|
346
343
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.endpointFromFunction = exports.functionFromEndpoint = exports.deleteFunction = exports.updateFunction = exports.listAllFunctions = exports.listFunctions = exports.getFunction = exports.createFunction = exports.generateUploadUrl = exports.mebibytes = exports.
|
|
3
|
+
exports.endpointFromFunction = exports.functionFromEndpoint = exports.deleteFunction = exports.updateFunction = exports.listAllFunctions = exports.listFunctions = exports.getFunction = exports.createFunction = exports.generateUploadUrl = exports.mebibytes = exports.API_VERSION = void 0;
|
|
4
4
|
const clc = require("colorette");
|
|
5
5
|
const apiv2_1 = require("../apiv2");
|
|
6
6
|
const error_1 = require("../error");
|
|
@@ -12,22 +12,13 @@ const runtimes = require("../deploy/functions/runtimes");
|
|
|
12
12
|
const proto = require("./proto");
|
|
13
13
|
const utils = require("../utils");
|
|
14
14
|
const projectConfig = require("../functions/projectConfig");
|
|
15
|
+
const constants_1 = require("../functions/constants");
|
|
15
16
|
exports.API_VERSION = "v2alpha";
|
|
16
|
-
exports.CODEBASE_LABEL = "firebase-functions-codebase";
|
|
17
17
|
const client = new apiv2_1.Client({
|
|
18
18
|
urlPrefix: api_1.functionsV2Origin,
|
|
19
19
|
auth: true,
|
|
20
20
|
apiVersion: exports.API_VERSION,
|
|
21
21
|
});
|
|
22
|
-
exports.BLOCKING_LABEL = "deployment-blocking";
|
|
23
|
-
const BLOCKING_LABEL_KEY_TO_EVENT = {
|
|
24
|
-
"before-create": "providers/cloud.auth/eventTypes/user.beforeCreate",
|
|
25
|
-
"before-sign-in": "providers/cloud.auth/eventTypes/user.beforeSignIn",
|
|
26
|
-
};
|
|
27
|
-
const BLOCKING_EVENT_TO_LABEL_KEY = {
|
|
28
|
-
"providers/cloud.auth/eventTypes/user.beforeCreate": "before-create",
|
|
29
|
-
"providers/cloud.auth/eventTypes/user.beforeSignIn": "before-sign-in",
|
|
30
|
-
};
|
|
31
22
|
const BYTES_PER_UNIT = {
|
|
32
23
|
"": 1,
|
|
33
24
|
k: 1e3,
|
|
@@ -243,20 +234,23 @@ function functionFromEndpoint(endpoint, source) {
|
|
|
243
234
|
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { "deployment-callable": "true" });
|
|
244
235
|
}
|
|
245
236
|
else if (backend.isBlockingTriggered(endpoint)) {
|
|
246
|
-
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [
|
|
237
|
+
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [constants_1.BLOCKING_LABEL]: constants_1.BLOCKING_EVENT_TO_LABEL_KEY[endpoint.blockingTrigger.eventType] });
|
|
247
238
|
}
|
|
248
239
|
const codebase = endpoint.codebase || projectConfig.DEFAULT_CODEBASE;
|
|
249
240
|
if (codebase !== projectConfig.DEFAULT_CODEBASE) {
|
|
250
|
-
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [
|
|
241
|
+
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [constants_1.CODEBASE_LABEL]: codebase });
|
|
251
242
|
}
|
|
252
243
|
else {
|
|
253
|
-
(_b = gcfFunction.labels) === null || _b === void 0 ? true : delete _b[
|
|
244
|
+
(_b = gcfFunction.labels) === null || _b === void 0 ? true : delete _b[constants_1.CODEBASE_LABEL];
|
|
245
|
+
}
|
|
246
|
+
if (endpoint.hash) {
|
|
247
|
+
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [constants_1.HASH_LABEL]: endpoint.hash });
|
|
254
248
|
}
|
|
255
249
|
return gcfFunction;
|
|
256
250
|
}
|
|
257
251
|
exports.functionFromEndpoint = functionFromEndpoint;
|
|
258
252
|
function endpointFromFunction(gcfFunction) {
|
|
259
|
-
var _a, _b, _c, _d, _e;
|
|
253
|
+
var _a, _b, _c, _d, _e, _f;
|
|
260
254
|
const [, project, , region, , id] = gcfFunction.name.split("/");
|
|
261
255
|
let trigger;
|
|
262
256
|
if (((_a = gcfFunction.labels) === null || _a === void 0 ? void 0 : _a["deployment-scheduled"]) === "true") {
|
|
@@ -274,10 +268,10 @@ function endpointFromFunction(gcfFunction) {
|
|
|
274
268
|
callableTrigger: {},
|
|
275
269
|
};
|
|
276
270
|
}
|
|
277
|
-
else if ((_d = gcfFunction.labels) === null || _d === void 0 ? void 0 : _d[
|
|
271
|
+
else if ((_d = gcfFunction.labels) === null || _d === void 0 ? void 0 : _d[constants_1.BLOCKING_LABEL]) {
|
|
278
272
|
trigger = {
|
|
279
273
|
blockingTrigger: {
|
|
280
|
-
eventType: BLOCKING_LABEL_KEY_TO_EVENT[gcfFunction.labels[
|
|
274
|
+
eventType: constants_1.BLOCKING_LABEL_KEY_TO_EVENT[gcfFunction.labels[constants_1.BLOCKING_LABEL]],
|
|
281
275
|
},
|
|
282
276
|
};
|
|
283
277
|
}
|
|
@@ -341,7 +335,10 @@ function endpointFromFunction(gcfFunction) {
|
|
|
341
335
|
endpoint.vpc = { connector: gcfFunction.serviceConfig.vpcConnector };
|
|
342
336
|
proto.renameIfPresent(endpoint.vpc, gcfFunction.serviceConfig, "egressSettings", "vpcConnectorEgressSettings");
|
|
343
337
|
}
|
|
344
|
-
endpoint.codebase = ((_e = gcfFunction.labels) === null || _e === void 0 ? void 0 : _e[
|
|
338
|
+
endpoint.codebase = ((_e = gcfFunction.labels) === null || _e === void 0 ? void 0 : _e[constants_1.CODEBASE_LABEL]) || projectConfig.DEFAULT_CODEBASE;
|
|
339
|
+
if ((_f = gcfFunction.labels) === null || _f === void 0 ? void 0 : _f[constants_1.HASH_LABEL]) {
|
|
340
|
+
endpoint.hash = gcfFunction.labels[constants_1.HASH_LABEL];
|
|
341
|
+
}
|
|
345
342
|
return endpoint;
|
|
346
343
|
}
|
|
347
344
|
exports.endpointFromFunction = endpointFromFunction;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jobFromEndpoint = exports.topicNameForEndpoint = exports.jobNameForEndpoint = exports.createOrReplaceJob = exports.deleteJob = void 0;
|
|
3
|
+
exports.jobFromEndpoint = exports.topicNameForEndpoint = exports.jobNameForEndpoint = exports.createOrReplaceJob = exports.getJob = exports.deleteJob = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
5
|
const error_1 = require("../error");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
@@ -29,6 +29,7 @@ function getJob(name) {
|
|
|
29
29
|
resolveOnHTTPError: true,
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
+
exports.getJob = getJob;
|
|
32
33
|
function updateJob(job) {
|
|
33
34
|
let fieldMasks;
|
|
34
35
|
let json;
|