firebase-functions 3.15.3 → 3.15.7
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/apps.js +1 -1
- package/lib/cloud-functions.d.ts +3 -2
- package/lib/cloud-functions.js +6 -7
- package/lib/common/encoding.js +7 -1
- package/lib/common/providers/https.js +3 -3
- package/lib/function-configuration.d.ts +0 -1
- package/lib/handler-builder.js +2 -2
- package/lib/index.js +1 -1
- package/lib/logger/compat.js +1 -1
- package/lib/providers/analytics.js +1 -1
- package/lib/providers/auth.js +1 -1
- package/lib/providers/database.js +11 -11
- package/lib/providers/firestore.js +7 -7
- package/lib/providers/https.js +9 -3
- package/lib/providers/pubsub.js +2 -2
- package/lib/providers/remoteConfig.js +1 -1
- package/lib/providers/storage.js +2 -2
- package/lib/providers/testLab.js +1 -1
- package/lib/setup.js +3 -3
- package/lib/v2/options.d.ts +1 -1
- package/lib/v2/options.js +7 -8
- package/lib/v2/providers/https.d.ts +1 -1
- package/lib/v2/providers/https.js +8 -2
- package/package.json +1 -1
package/lib/apps.js
CHANGED
|
@@ -103,7 +103,7 @@ exports.apps = apps;
|
|
|
103
103
|
this._emulatedAdminApp = app;
|
|
104
104
|
}
|
|
105
105
|
get firebaseArgs() {
|
|
106
|
-
return _.assign({}, config_1.firebaseConfig(), {
|
|
106
|
+
return _.assign({}, (0, config_1.firebaseConfig)(), {
|
|
107
107
|
credential: firebase.credential.applicationDefault(),
|
|
108
108
|
});
|
|
109
109
|
}
|
package/lib/cloud-functions.d.ts
CHANGED
|
@@ -185,7 +185,9 @@ export interface TriggerAnnotated {
|
|
|
185
185
|
service: string;
|
|
186
186
|
};
|
|
187
187
|
failurePolicy?: FailurePolicy;
|
|
188
|
-
httpsTrigger?: {
|
|
188
|
+
httpsTrigger?: {
|
|
189
|
+
invoker?: string[];
|
|
190
|
+
};
|
|
189
191
|
labels?: {
|
|
190
192
|
[key: string]: string;
|
|
191
193
|
};
|
|
@@ -196,7 +198,6 @@ export interface TriggerAnnotated {
|
|
|
196
198
|
vpcConnectorEgressSettings?: string;
|
|
197
199
|
serviceAccountEmail?: string;
|
|
198
200
|
ingressSettings?: string;
|
|
199
|
-
invoker?: string[];
|
|
200
201
|
};
|
|
201
202
|
}
|
|
202
203
|
/**
|
package/lib/cloud-functions.js
CHANGED
|
@@ -135,7 +135,7 @@ function makeCloudFunction({ after = () => { }, before = () => { }, contextOnlyH
|
|
|
135
135
|
promise = handler(dataOrChange, context);
|
|
136
136
|
}
|
|
137
137
|
if (typeof promise === 'undefined') {
|
|
138
|
-
logger_1.warn('Function returned undefined, expected Promise or value');
|
|
138
|
+
(0, logger_1.warn)('Function returned undefined, expected Promise or value');
|
|
139
139
|
}
|
|
140
140
|
return Promise.resolve(promise)
|
|
141
141
|
.then((result) => {
|
|
@@ -216,8 +216,8 @@ function _detectAuthType(event) {
|
|
|
216
216
|
/** @hidden */
|
|
217
217
|
function optionsToTrigger(options) {
|
|
218
218
|
const trigger = {};
|
|
219
|
-
encoding_1.copyIfPresent(trigger, options, 'regions', 'schedule', 'minInstances', 'maxInstances', 'ingressSettings', 'vpcConnectorEgressSettings', 'vpcConnector', 'labels');
|
|
220
|
-
encoding_1.convertIfPresent(trigger, options, 'failurePolicy', 'failurePolicy', (policy) => {
|
|
219
|
+
(0, encoding_1.copyIfPresent)(trigger, options, 'regions', 'schedule', 'minInstances', 'maxInstances', 'ingressSettings', 'vpcConnectorEgressSettings', 'vpcConnector', 'labels');
|
|
220
|
+
(0, encoding_1.convertIfPresent)(trigger, options, 'failurePolicy', 'failurePolicy', (policy) => {
|
|
221
221
|
if (policy === false) {
|
|
222
222
|
return undefined;
|
|
223
223
|
}
|
|
@@ -228,8 +228,8 @@ function optionsToTrigger(options) {
|
|
|
228
228
|
return policy;
|
|
229
229
|
}
|
|
230
230
|
});
|
|
231
|
-
encoding_1.convertIfPresent(trigger, options, 'timeout', 'timeoutSeconds', encoding_1.durationFromSeconds);
|
|
232
|
-
encoding_1.convertIfPresent(trigger, options, 'availableMemoryMb', 'memory', (mem) => {
|
|
231
|
+
(0, encoding_1.convertIfPresent)(trigger, options, 'timeout', 'timeoutSeconds', encoding_1.durationFromSeconds);
|
|
232
|
+
(0, encoding_1.convertIfPresent)(trigger, options, 'availableMemoryMb', 'memory', (mem) => {
|
|
233
233
|
const memoryLookup = {
|
|
234
234
|
'128MB': 128,
|
|
235
235
|
'256MB': 256,
|
|
@@ -241,8 +241,7 @@ function optionsToTrigger(options) {
|
|
|
241
241
|
};
|
|
242
242
|
return memoryLookup[mem];
|
|
243
243
|
});
|
|
244
|
-
encoding_1.convertIfPresent(trigger, options, 'serviceAccountEmail', 'serviceAccount', encoding_1.serviceAccountFromShorthand);
|
|
245
|
-
encoding_1.convertIfPresent(trigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
244
|
+
(0, encoding_1.convertIfPresent)(trigger, options, 'serviceAccountEmail', 'serviceAccount', encoding_1.serviceAccountFromShorthand);
|
|
246
245
|
return trigger;
|
|
247
246
|
}
|
|
248
247
|
exports.optionsToTrigger = optionsToTrigger;
|
package/lib/common/encoding.js
CHANGED
|
@@ -52,9 +52,15 @@ function convertInvoker(invoker) {
|
|
|
52
52
|
if (typeof invoker === 'string') {
|
|
53
53
|
invoker = [invoker];
|
|
54
54
|
}
|
|
55
|
+
if (invoker.length === 0) {
|
|
56
|
+
throw new Error('Invalid option for invoker: Must be a non-empty array.');
|
|
57
|
+
}
|
|
58
|
+
if (invoker.find((inv) => inv.length === 0)) {
|
|
59
|
+
throw new Error('Invalid option for invoker: Must be a non-empty string.');
|
|
60
|
+
}
|
|
55
61
|
if (invoker.length > 1 &&
|
|
56
62
|
invoker.find((inv) => inv === 'public' || inv === 'private')) {
|
|
57
|
-
throw new Error("Invalid option for invoker
|
|
63
|
+
throw new Error("Invalid option for invoker: Cannot have 'public' or 'private' in an array of service accounts.");
|
|
58
64
|
}
|
|
59
65
|
return invoker;
|
|
60
66
|
}
|
|
@@ -224,10 +224,10 @@ async function checkTokens(req, ctx) {
|
|
|
224
224
|
if (appCheck) {
|
|
225
225
|
verifications.app = 'INVALID';
|
|
226
226
|
try {
|
|
227
|
-
if (!apps_1.apps().admin.appCheck) {
|
|
227
|
+
if (!(0, apps_1.apps)().admin.appCheck) {
|
|
228
228
|
throw new Error('Cannot validate AppCheck token. Please update Firebase Admin SDK to >= v9.8.0');
|
|
229
229
|
}
|
|
230
|
-
const appCheckToken = await apps_1.apps()
|
|
230
|
+
const appCheckToken = await (0, apps_1.apps)()
|
|
231
231
|
.admin.appCheck()
|
|
232
232
|
.verifyToken(appCheck);
|
|
233
233
|
ctx.app = {
|
|
@@ -247,7 +247,7 @@ async function checkTokens(req, ctx) {
|
|
|
247
247
|
if (match) {
|
|
248
248
|
const idToken = match[1];
|
|
249
249
|
try {
|
|
250
|
-
const authToken = await apps_1.apps()
|
|
250
|
+
const authToken = await (0, apps_1.apps)()
|
|
251
251
|
.admin.auth()
|
|
252
252
|
.verifyIdToken(idToken);
|
|
253
253
|
verifications.auth = 'VALID';
|
package/lib/handler-builder.js
CHANGED
|
@@ -111,12 +111,12 @@ class HandlerBuilder {
|
|
|
111
111
|
get instance() {
|
|
112
112
|
return {
|
|
113
113
|
get ref() {
|
|
114
|
-
return new database.RefBuilder(apps_1.apps(), () => null, {});
|
|
114
|
+
return new database.RefBuilder((0, apps_1.apps)(), () => null, {});
|
|
115
115
|
},
|
|
116
116
|
};
|
|
117
117
|
},
|
|
118
118
|
get ref() {
|
|
119
|
-
return new database.RefBuilder(apps_1.apps(), () => null, {});
|
|
119
|
+
return new database.RefBuilder((0, apps_1.apps)(), () => null, {});
|
|
120
120
|
},
|
|
121
121
|
};
|
|
122
122
|
}
|
package/lib/index.js
CHANGED
package/lib/logger/compat.js
CHANGED
|
@@ -6,7 +6,7 @@ const common_1 = require("./common");
|
|
|
6
6
|
function patchedConsole(severity) {
|
|
7
7
|
return function (data, ...args) {
|
|
8
8
|
if (common_1.SUPPORTS_STRUCTURED_LOGS) {
|
|
9
|
-
common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](JSON.stringify({ severity, message: util_1.format(data, ...args) }));
|
|
9
|
+
common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](JSON.stringify({ severity, message: (0, util_1.format)(data, ...args) }));
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](data, ...args);
|
|
@@ -73,7 +73,7 @@ class AnalyticsEventBuilder {
|
|
|
73
73
|
const dataConstructor = (raw) => {
|
|
74
74
|
return new AnalyticsEvent(raw.data);
|
|
75
75
|
};
|
|
76
|
-
return cloud_functions_1.makeCloudFunction({
|
|
76
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
77
77
|
handler,
|
|
78
78
|
provider: exports.provider,
|
|
79
79
|
eventType: 'event.log',
|
package/lib/providers/auth.js
CHANGED
|
@@ -78,7 +78,7 @@ class UserBuilder {
|
|
|
78
78
|
return this.onOperation(handler, 'user.delete');
|
|
79
79
|
}
|
|
80
80
|
onOperation(handler, eventType) {
|
|
81
|
-
return cloud_functions_1.makeCloudFunction({
|
|
81
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
82
82
|
handler,
|
|
83
83
|
provider: exports.provider,
|
|
84
84
|
eventType,
|
|
@@ -104,20 +104,20 @@ class InstanceBuilder {
|
|
|
104
104
|
* @return Firebase Realtime Database reference builder interface.
|
|
105
105
|
*/
|
|
106
106
|
ref(path) {
|
|
107
|
-
const normalized = path_1.normalizePath(path);
|
|
108
|
-
return new RefBuilder(apps_1.apps(), () => `projects/_/instances/${this.instance}/refs/${normalized}`, this.options);
|
|
107
|
+
const normalized = (0, path_1.normalizePath)(path);
|
|
108
|
+
return new RefBuilder((0, apps_1.apps)(), () => `projects/_/instances/${this.instance}/refs/${normalized}`, this.options);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
exports.InstanceBuilder = InstanceBuilder;
|
|
112
112
|
/** @hidden */
|
|
113
113
|
function _refWithOptions(path, options) {
|
|
114
114
|
const resourceGetter = () => {
|
|
115
|
-
const normalized = path_1.normalizePath(path);
|
|
116
|
-
const databaseURL = config_1.firebaseConfig().databaseURL;
|
|
115
|
+
const normalized = (0, path_1.normalizePath)(path);
|
|
116
|
+
const databaseURL = (0, config_1.firebaseConfig)().databaseURL;
|
|
117
117
|
if (!databaseURL) {
|
|
118
118
|
throw new Error('Missing expected firebase config value databaseURL, ' +
|
|
119
119
|
'config is actually' +
|
|
120
|
-
JSON.stringify(config_1.firebaseConfig()) +
|
|
120
|
+
JSON.stringify((0, config_1.firebaseConfig)()) +
|
|
121
121
|
'\n If you are unit testing, please set process.env.FIREBASE_CONFIG');
|
|
122
122
|
}
|
|
123
123
|
let instance;
|
|
@@ -136,7 +136,7 @@ function _refWithOptions(path, options) {
|
|
|
136
136
|
}
|
|
137
137
|
return `projects/_/instances/${instance}/refs/${normalized}`;
|
|
138
138
|
};
|
|
139
|
-
return new RefBuilder(apps_1.apps(), resourceGetter, options);
|
|
139
|
+
return new RefBuilder((0, apps_1.apps)(), resourceGetter, options);
|
|
140
140
|
}
|
|
141
141
|
exports._refWithOptions = _refWithOptions;
|
|
142
142
|
/**
|
|
@@ -153,7 +153,7 @@ class RefBuilder {
|
|
|
153
153
|
this.changeConstructor = (raw) => {
|
|
154
154
|
const [dbInstance, path] = extractInstanceAndPath(raw.context.resource.name, raw.context.domain);
|
|
155
155
|
const before = new DataSnapshot(raw.data.data, path, this.apps.admin, dbInstance);
|
|
156
|
-
const after = new DataSnapshot(utils_1.applyChange(raw.data.data, raw.data.delta), path, this.apps.admin, dbInstance);
|
|
156
|
+
const after = new DataSnapshot((0, utils_1.applyChange)(raw.data.data, raw.data.delta), path, this.apps.admin, dbInstance);
|
|
157
157
|
return {
|
|
158
158
|
before,
|
|
159
159
|
after,
|
|
@@ -214,7 +214,7 @@ class RefBuilder {
|
|
|
214
214
|
return this.onOperation(handler, 'ref.delete', dataConstructor);
|
|
215
215
|
}
|
|
216
216
|
onOperation(handler, eventType, dataConstructor) {
|
|
217
|
-
return cloud_functions_1.makeCloudFunction({
|
|
217
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
218
218
|
handler,
|
|
219
219
|
provider: exports.provider,
|
|
220
220
|
service: exports.service,
|
|
@@ -310,7 +310,7 @@ class DataSnapshot {
|
|
|
310
310
|
* However, accessing the key on the root URL of a Database will return `null`.
|
|
311
311
|
*/
|
|
312
312
|
get key() {
|
|
313
|
-
const last = _.last(path_1.pathParts(this._fullPath()));
|
|
313
|
+
const last = _.last((0, path_1.pathParts)(this._fullPath()));
|
|
314
314
|
return !last || last === '' ? null : last;
|
|
315
315
|
}
|
|
316
316
|
/**
|
|
@@ -325,7 +325,7 @@ class DataSnapshot {
|
|
|
325
325
|
* Array, string, number, boolean, or `null`).
|
|
326
326
|
*/
|
|
327
327
|
val() {
|
|
328
|
-
const parts = path_1.pathParts(this._childPath);
|
|
328
|
+
const parts = (0, path_1.pathParts)(this._childPath);
|
|
329
329
|
const source = this._data;
|
|
330
330
|
const node = _.cloneDeep(parts.length ? _.get(source, parts, null) : source);
|
|
331
331
|
return this._checkAndConvertToArray(node);
|
|
@@ -493,7 +493,7 @@ class DataSnapshot {
|
|
|
493
493
|
const dup = new DataSnapshot(this._data, undefined, this.app, this.instance);
|
|
494
494
|
[dup._path, dup._childPath] = [this._path, this._childPath];
|
|
495
495
|
if (childPath) {
|
|
496
|
-
dup._childPath = path_1.joinPath(dup._childPath, childPath);
|
|
496
|
+
dup._childPath = (0, path_1.joinPath)(dup._childPath, childPath);
|
|
497
497
|
}
|
|
498
498
|
return dup;
|
|
499
499
|
}
|
|
@@ -113,8 +113,8 @@ function _getValueProto(data, resource, valueFieldName) {
|
|
|
113
113
|
}
|
|
114
114
|
const proto = {
|
|
115
115
|
fields: _.get(data, [valueFieldName, 'fields'], {}),
|
|
116
|
-
createTime: encoder_1.dateToTimestampProto(_.get(data, [valueFieldName, 'createTime'])),
|
|
117
|
-
updateTime: encoder_1.dateToTimestampProto(_.get(data, [valueFieldName, 'updateTime'])),
|
|
116
|
+
createTime: (0, encoder_1.dateToTimestampProto)(_.get(data, [valueFieldName, 'createTime'])),
|
|
117
|
+
updateTime: (0, encoder_1.dateToTimestampProto)(_.get(data, [valueFieldName, 'updateTime'])),
|
|
118
118
|
name: _.get(data, [valueFieldName, 'name'], resource),
|
|
119
119
|
};
|
|
120
120
|
return proto;
|
|
@@ -123,7 +123,7 @@ function _getValueProto(data, resource, valueFieldName) {
|
|
|
123
123
|
function snapshotConstructor(event) {
|
|
124
124
|
var _a;
|
|
125
125
|
if (!firestoreInstance) {
|
|
126
|
-
firestoreInstance = firebase.firestore(apps_1.apps().admin);
|
|
126
|
+
firestoreInstance = firebase.firestore((0, apps_1.apps)().admin);
|
|
127
127
|
}
|
|
128
128
|
const valueProto = _getValueProto(event.data, event.context.resource.name, 'value');
|
|
129
129
|
let timeString = (_a = _.get(event, 'data.value.readTime')) !== null && _a !== void 0 ? _a : _.get(event, 'data.value.updateTime');
|
|
@@ -131,7 +131,7 @@ function snapshotConstructor(event) {
|
|
|
131
131
|
logger.warn('Snapshot has no readTime. Using now()');
|
|
132
132
|
timeString = new Date().toISOString();
|
|
133
133
|
}
|
|
134
|
-
const readTime = encoder_1.dateToTimestampProto(timeString);
|
|
134
|
+
const readTime = (0, encoder_1.dateToTimestampProto)(timeString);
|
|
135
135
|
return firestoreInstance.snapshot_(valueProto, readTime, 'json');
|
|
136
136
|
}
|
|
137
137
|
exports.snapshotConstructor = snapshotConstructor;
|
|
@@ -139,10 +139,10 @@ exports.snapshotConstructor = snapshotConstructor;
|
|
|
139
139
|
// TODO remove this function when wire format changes to new format
|
|
140
140
|
function beforeSnapshotConstructor(event) {
|
|
141
141
|
if (!firestoreInstance) {
|
|
142
|
-
firestoreInstance = firebase.firestore(apps_1.apps().admin);
|
|
142
|
+
firestoreInstance = firebase.firestore((0, apps_1.apps)().admin);
|
|
143
143
|
}
|
|
144
144
|
const oldValueProto = _getValueProto(event.data, event.context.resource.name, 'oldValue');
|
|
145
|
-
const oldReadTime = encoder_1.dateToTimestampProto(_.get(event, 'data.oldValue.readTime'));
|
|
145
|
+
const oldReadTime = (0, encoder_1.dateToTimestampProto)(_.get(event, 'data.oldValue.readTime'));
|
|
146
146
|
return firestoreInstance.snapshot_(oldValueProto, oldReadTime, 'json');
|
|
147
147
|
}
|
|
148
148
|
exports.beforeSnapshotConstructor = beforeSnapshotConstructor;
|
|
@@ -173,7 +173,7 @@ class DocumentBuilder {
|
|
|
173
173
|
return this.onOperation(handler, 'document.delete', beforeSnapshotConstructor);
|
|
174
174
|
}
|
|
175
175
|
onOperation(handler, eventType, dataConstructor) {
|
|
176
|
-
return cloud_functions_1.makeCloudFunction({
|
|
176
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
177
177
|
handler,
|
|
178
178
|
provider: exports.provider,
|
|
179
179
|
eventType,
|
package/lib/providers/https.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports._onCallWithOptions = exports._onRequestWithOptions = exports.onCall = exports.onRequest = exports.HttpsError = void 0;
|
|
25
25
|
const cloud_functions_1 = require("../cloud-functions");
|
|
26
|
+
const encoding_1 = require("../common/encoding");
|
|
26
27
|
const https_1 = require("../common/providers/https");
|
|
27
28
|
Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return https_1.HttpsError; } });
|
|
28
29
|
/**
|
|
@@ -49,19 +50,24 @@ function _onRequestWithOptions(handler, options) {
|
|
|
49
50
|
return handler(req, res);
|
|
50
51
|
};
|
|
51
52
|
cloudFunction.__trigger = {
|
|
52
|
-
...cloud_functions_1.optionsToTrigger(options),
|
|
53
|
+
...(0, cloud_functions_1.optionsToTrigger)(options),
|
|
53
54
|
httpsTrigger: {},
|
|
54
55
|
};
|
|
56
|
+
(0, encoding_1.convertIfPresent)(cloudFunction.__trigger.httpsTrigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
55
57
|
// TODO parse the options
|
|
56
58
|
return cloudFunction;
|
|
57
59
|
}
|
|
58
60
|
exports._onRequestWithOptions = _onRequestWithOptions;
|
|
59
61
|
/** @hidden */
|
|
60
62
|
function _onCallWithOptions(handler, options) {
|
|
61
|
-
|
|
63
|
+
// onCallHandler sniffs the function length of the passed-in callback
|
|
64
|
+
// and the user could have only tried to listen to data. Wrap their handler
|
|
65
|
+
// in another handler to avoid accidentally triggering the v2 API
|
|
66
|
+
const fixedLen = (data, context) => handler(data, context);
|
|
67
|
+
const func = (0, https_1.onCallHandler)({ origin: true, methods: 'POST' }, fixedLen);
|
|
62
68
|
func.__trigger = {
|
|
63
69
|
labels: {},
|
|
64
|
-
...cloud_functions_1.optionsToTrigger(options),
|
|
70
|
+
...(0, cloud_functions_1.optionsToTrigger)(options),
|
|
65
71
|
httpsTrigger: {},
|
|
66
72
|
};
|
|
67
73
|
func.__trigger.labels['deployment-callable'] = 'true';
|
package/lib/providers/pubsub.js
CHANGED
|
@@ -71,7 +71,7 @@ class TopicBuilder {
|
|
|
71
71
|
* @return A Cloud Function that you can export and deploy.
|
|
72
72
|
*/
|
|
73
73
|
onPublish(handler) {
|
|
74
|
-
return cloud_functions_1.makeCloudFunction({
|
|
74
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
75
75
|
handler,
|
|
76
76
|
provider: exports.provider,
|
|
77
77
|
service: exports.service,
|
|
@@ -140,7 +140,7 @@ class ScheduleBuilder {
|
|
|
140
140
|
* @return A Cloud Function that you can export and deploy.
|
|
141
141
|
*/
|
|
142
142
|
onRun(handler) {
|
|
143
|
-
const cloudFunction = cloud_functions_1.makeCloudFunction({
|
|
143
|
+
const cloudFunction = (0, cloud_functions_1.makeCloudFunction)({
|
|
144
144
|
contextOnlyHandler: handler,
|
|
145
145
|
provider: exports.provider,
|
|
146
146
|
service: exports.service,
|
|
@@ -65,7 +65,7 @@ class UpdateBuilder {
|
|
|
65
65
|
* version metadata as an argument.
|
|
66
66
|
*/
|
|
67
67
|
onUpdate(handler) {
|
|
68
|
-
return cloud_functions_1.makeCloudFunction({
|
|
68
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
69
69
|
handler,
|
|
70
70
|
provider: exports.provider,
|
|
71
71
|
service: exports.service,
|
package/lib/providers/storage.js
CHANGED
|
@@ -53,7 +53,7 @@ exports.object = object;
|
|
|
53
53
|
/** @hidden */
|
|
54
54
|
function _bucketWithOptions(options, bucket) {
|
|
55
55
|
const resourceGetter = () => {
|
|
56
|
-
bucket = bucket || config_1.firebaseConfig().storageBucket;
|
|
56
|
+
bucket = bucket || (0, config_1.firebaseConfig)().storageBucket;
|
|
57
57
|
if (!bucket) {
|
|
58
58
|
throw new Error('Missing bucket name. If you are unit testing, please provide a bucket name' +
|
|
59
59
|
' through `functions.storage.bucket(bucketName)`, or set process.env.FIREBASE_CONFIG.');
|
|
@@ -170,7 +170,7 @@ class ObjectBuilder {
|
|
|
170
170
|
}
|
|
171
171
|
/** @hidden */
|
|
172
172
|
onOperation(handler, eventType) {
|
|
173
|
-
return cloud_functions_1.makeCloudFunction({
|
|
173
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
174
174
|
handler,
|
|
175
175
|
provider: exports.provider,
|
|
176
176
|
service: exports.service,
|
package/lib/providers/testLab.js
CHANGED
|
@@ -57,7 +57,7 @@ class TestMatrixBuilder {
|
|
|
57
57
|
const dataConstructor = (raw) => {
|
|
58
58
|
return new TestMatrix(raw.data);
|
|
59
59
|
};
|
|
60
|
-
return cloud_functions_1.makeCloudFunction({
|
|
60
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
61
61
|
provider: exports.PROVIDER,
|
|
62
62
|
eventType: exports.TEST_MATRIX_COMPLETE_EVENT_TYPE,
|
|
63
63
|
triggerResource: this.triggerResource,
|
package/lib/setup.js
CHANGED
|
@@ -31,7 +31,7 @@ function setup() {
|
|
|
31
31
|
// Until the Cloud Functions builder can publish FIREBASE_CONFIG, automatically provide it on import based on what
|
|
32
32
|
// we can deduce.
|
|
33
33
|
if (!process.env.FIREBASE_CONFIG) {
|
|
34
|
-
const cfg = config_1.firebaseConfig();
|
|
34
|
+
const cfg = (0, config_1.firebaseConfig)();
|
|
35
35
|
if (cfg) {
|
|
36
36
|
process.env.FIREBASE_CONFIG = JSON.stringify(cfg);
|
|
37
37
|
}
|
|
@@ -43,7 +43,7 @@ function setup() {
|
|
|
43
43
|
// If FIREBASE_CONFIG is still not found, try using GCLOUD_PROJECT to estimate
|
|
44
44
|
if (!process.env.FIREBASE_CONFIG) {
|
|
45
45
|
if (process.env.GCLOUD_PROJECT) {
|
|
46
|
-
logger_1.warn('Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail');
|
|
46
|
+
(0, logger_1.warn)('Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail');
|
|
47
47
|
process.env.FIREBASE_CONFIG = JSON.stringify({
|
|
48
48
|
databaseURL: process.env.DATABASE_URL ||
|
|
49
49
|
`https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
|
|
@@ -53,7 +53,7 @@ function setup() {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
|
-
logger_1.warn('Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail');
|
|
56
|
+
(0, logger_1.warn)('Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail');
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
package/lib/v2/options.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ParamSpec } from './params/types';
|
|
|
2
2
|
/**
|
|
3
3
|
* List of all regions supported by Cloud Functions v2
|
|
4
4
|
*/
|
|
5
|
-
export declare const SUPPORTED_REGIONS: readonly ["us-west1"];
|
|
5
|
+
export declare const SUPPORTED_REGIONS: readonly ["us-west1", "europe-west4"];
|
|
6
6
|
/**
|
|
7
7
|
* A region known to be supported by CloudFunctions v2
|
|
8
8
|
*/
|
package/lib/v2/options.js
CHANGED
|
@@ -29,7 +29,7 @@ const params_1 = require("./params");
|
|
|
29
29
|
/**
|
|
30
30
|
* List of all regions supported by Cloud Functions v2
|
|
31
31
|
*/
|
|
32
|
-
exports.SUPPORTED_REGIONS = ['us-west1'];
|
|
32
|
+
exports.SUPPORTED_REGIONS = ['us-west1', 'europe-west4'];
|
|
33
33
|
/**
|
|
34
34
|
* Cloud Functions v2 min timeout value.
|
|
35
35
|
*/
|
|
@@ -107,22 +107,21 @@ exports.getGlobalOptions = getGlobalOptions;
|
|
|
107
107
|
*/
|
|
108
108
|
function optionsToTriggerAnnotations(opts) {
|
|
109
109
|
const annotation = {};
|
|
110
|
-
encoding_2.copyIfPresent(annotation, opts, 'concurrency', 'minInstances', 'maxInstances', 'ingressSettings', 'labels', 'vpcConnector', 'vpcConnectorEgressSettings');
|
|
111
|
-
encoding_2.convertIfPresent(annotation, opts, 'availableMemoryMb', 'memory', (mem) => {
|
|
110
|
+
(0, encoding_2.copyIfPresent)(annotation, opts, 'concurrency', 'minInstances', 'maxInstances', 'ingressSettings', 'labels', 'vpcConnector', 'vpcConnectorEgressSettings');
|
|
111
|
+
(0, encoding_2.convertIfPresent)(annotation, opts, 'availableMemoryMb', 'memory', (mem) => {
|
|
112
112
|
return MemoryOptionToMB[mem];
|
|
113
113
|
});
|
|
114
|
-
encoding_2.convertIfPresent(annotation, opts, 'regions', 'region', (region) => {
|
|
114
|
+
(0, encoding_2.convertIfPresent)(annotation, opts, 'regions', 'region', (region) => {
|
|
115
115
|
if (typeof region === 'string') {
|
|
116
116
|
return [region];
|
|
117
117
|
}
|
|
118
118
|
return region;
|
|
119
119
|
});
|
|
120
|
-
encoding_2.convertIfPresent(annotation, opts, 'serviceAccountEmail', 'serviceAccount', encoding_1.serviceAccountFromShorthand);
|
|
121
|
-
encoding_2.convertIfPresent(annotation, opts, 'timeout', 'timeoutSeconds', encoding_1.durationFromSeconds);
|
|
122
|
-
encoding_2.convertIfPresent(annotation, opts, 'failurePolicy', 'retry', (retry) => {
|
|
120
|
+
(0, encoding_2.convertIfPresent)(annotation, opts, 'serviceAccountEmail', 'serviceAccount', encoding_1.serviceAccountFromShorthand);
|
|
121
|
+
(0, encoding_2.convertIfPresent)(annotation, opts, 'timeout', 'timeoutSeconds', encoding_1.durationFromSeconds);
|
|
122
|
+
(0, encoding_2.convertIfPresent)(annotation, opts, 'failurePolicy', 'retry', (retry) => {
|
|
123
123
|
return retry ? { retry: true } : null;
|
|
124
124
|
});
|
|
125
|
-
encoding_2.convertIfPresent(annotation, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
126
125
|
return annotation;
|
|
127
126
|
}
|
|
128
127
|
exports.optionsToTriggerAnnotations = optionsToTriggerAnnotations;
|
|
@@ -4,7 +4,7 @@ import * as options from '../options';
|
|
|
4
4
|
export { Request, CallableRequest, FunctionsErrorCode, HttpsError };
|
|
5
5
|
export interface HttpsOptions extends Omit<options.GlobalOptions, 'region'> {
|
|
6
6
|
region?: options.SupportedRegion | string | Array<options.SupportedRegion | string>;
|
|
7
|
-
cors?: string | boolean
|
|
7
|
+
cors?: string | boolean | RegExp | Array<string | RegExp>;
|
|
8
8
|
}
|
|
9
9
|
export declare type HttpsFunction = ((req: Request, res: express.Response) => void | Promise<void>) & {
|
|
10
10
|
__trigger: unknown;
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.onCall = exports.onRequest = exports.HttpsError = void 0;
|
|
25
25
|
const cors = require("cors");
|
|
26
|
+
const encoding_1 = require("../../common/encoding");
|
|
26
27
|
const https_1 = require("../../common/providers/https");
|
|
27
28
|
Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return https_1.HttpsError; } });
|
|
28
29
|
const options = require("../options");
|
|
@@ -52,7 +53,7 @@ function onRequest(optsOrHandler, handler) {
|
|
|
52
53
|
// global options calls region a scalar and https allows it to be an array,
|
|
53
54
|
// but optionsToTriggerAnnotations handles both cases.
|
|
54
55
|
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
55
|
-
|
|
56
|
+
const trigger = {
|
|
56
57
|
// TODO(inlined): Remove "apiVersion" once the latest version of the CLI
|
|
57
58
|
// has migrated to "platform".
|
|
58
59
|
apiVersion: 2,
|
|
@@ -67,6 +68,8 @@ function onRequest(optsOrHandler, handler) {
|
|
|
67
68
|
allowInsecure: false,
|
|
68
69
|
},
|
|
69
70
|
};
|
|
71
|
+
(0, encoding_1.convertIfPresent)(trigger.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
72
|
+
return trigger;
|
|
70
73
|
},
|
|
71
74
|
});
|
|
72
75
|
return handler;
|
|
@@ -82,7 +85,10 @@ function onCall(optsOrHandler, handler) {
|
|
|
82
85
|
opts = optsOrHandler;
|
|
83
86
|
}
|
|
84
87
|
const origin = 'cors' in opts ? opts.cors : true;
|
|
85
|
-
|
|
88
|
+
// onCallHandler sniffs the function length to determine which API to present.
|
|
89
|
+
// fix the length to prevent api versions from being mismatched.
|
|
90
|
+
const fixedLen = (req) => handler(req);
|
|
91
|
+
const func = (0, https_1.onCallHandler)({ origin, methods: 'POST' }, fixedLen);
|
|
86
92
|
Object.defineProperty(func, '__trigger', {
|
|
87
93
|
get: () => {
|
|
88
94
|
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|