@firebase/functions 0.11.9 → 0.11.10

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/dist/index.cjs.js CHANGED
@@ -6,724 +6,724 @@ var app = require('@firebase/app');
6
6
  var util = require('@firebase/util');
7
7
  var component = require('@firebase/component');
8
8
 
9
- /**
10
- * @license
11
- * Copyright 2017 Google LLC
12
- *
13
- * Licensed under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License.
15
- * You may obtain a copy of the License at
16
- *
17
- * http://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software
20
- * distributed under the License is distributed on an "AS IS" BASIS,
21
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
- * See the License for the specific language governing permissions and
23
- * limitations under the License.
24
- */
25
- const LONG_TYPE = 'type.googleapis.com/google.protobuf.Int64Value';
26
- const UNSIGNED_LONG_TYPE = 'type.googleapis.com/google.protobuf.UInt64Value';
27
- function mapValues(
28
- // { [k: string]: unknown } is no longer a wildcard assignment target after typescript 3.5
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- o, f) {
31
- const result = {};
32
- for (const key in o) {
33
- if (o.hasOwnProperty(key)) {
34
- result[key] = f(o[key]);
35
- }
36
- }
37
- return result;
38
- }
39
- /**
40
- * Takes data and encodes it in a JSON-friendly way, such that types such as
41
- * Date are preserved.
42
- * @internal
43
- * @param data - Data to encode.
44
- */
45
- function encode(data) {
46
- if (data == null) {
47
- return null;
48
- }
49
- if (data instanceof Number) {
50
- data = data.valueOf();
51
- }
52
- if (typeof data === 'number' && isFinite(data)) {
53
- // Any number in JS is safe to put directly in JSON and parse as a double
54
- // without any loss of precision.
55
- return data;
56
- }
57
- if (data === true || data === false) {
58
- return data;
59
- }
60
- if (Object.prototype.toString.call(data) === '[object String]') {
61
- return data;
62
- }
63
- if (data instanceof Date) {
64
- return data.toISOString();
65
- }
66
- if (Array.isArray(data)) {
67
- return data.map(x => encode(x));
68
- }
69
- if (typeof data === 'function' || typeof data === 'object') {
70
- return mapValues(data, x => encode(x));
71
- }
72
- // If we got this far, the data is not encodable.
73
- throw new Error('Data cannot be encoded in JSON: ' + data);
74
- }
75
- /**
76
- * Takes data that's been encoded in a JSON-friendly form and returns a form
77
- * with richer datatypes, such as Dates, etc.
78
- * @internal
79
- * @param json - JSON to convert.
80
- */
81
- function decode(json) {
82
- if (json == null) {
83
- return json;
84
- }
85
- if (json['@type']) {
86
- switch (json['@type']) {
87
- case LONG_TYPE:
88
- // Fall through and handle this the same as unsigned.
89
- case UNSIGNED_LONG_TYPE: {
90
- // Technically, this could work return a valid number for malformed
91
- // data if there was a number followed by garbage. But it's just not
92
- // worth all the extra code to detect that case.
93
- const value = Number(json['value']);
94
- if (isNaN(value)) {
95
- throw new Error('Data cannot be decoded from JSON: ' + json);
96
- }
97
- return value;
98
- }
99
- default: {
100
- throw new Error('Data cannot be decoded from JSON: ' + json);
101
- }
102
- }
103
- }
104
- if (Array.isArray(json)) {
105
- return json.map(x => decode(x));
106
- }
107
- if (typeof json === 'function' || typeof json === 'object') {
108
- return mapValues(json, x => decode(x));
109
- }
110
- // Anything else is safe to return.
111
- return json;
9
+ /**
10
+ * @license
11
+ * Copyright 2017 Google LLC
12
+ *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ const LONG_TYPE = 'type.googleapis.com/google.protobuf.Int64Value';
26
+ const UNSIGNED_LONG_TYPE = 'type.googleapis.com/google.protobuf.UInt64Value';
27
+ function mapValues(
28
+ // { [k: string]: unknown } is no longer a wildcard assignment target after typescript 3.5
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ o, f) {
31
+ const result = {};
32
+ for (const key in o) {
33
+ if (o.hasOwnProperty(key)) {
34
+ result[key] = f(o[key]);
35
+ }
36
+ }
37
+ return result;
38
+ }
39
+ /**
40
+ * Takes data and encodes it in a JSON-friendly way, such that types such as
41
+ * Date are preserved.
42
+ * @internal
43
+ * @param data - Data to encode.
44
+ */
45
+ function encode(data) {
46
+ if (data == null) {
47
+ return null;
48
+ }
49
+ if (data instanceof Number) {
50
+ data = data.valueOf();
51
+ }
52
+ if (typeof data === 'number' && isFinite(data)) {
53
+ // Any number in JS is safe to put directly in JSON and parse as a double
54
+ // without any loss of precision.
55
+ return data;
56
+ }
57
+ if (data === true || data === false) {
58
+ return data;
59
+ }
60
+ if (Object.prototype.toString.call(data) === '[object String]') {
61
+ return data;
62
+ }
63
+ if (data instanceof Date) {
64
+ return data.toISOString();
65
+ }
66
+ if (Array.isArray(data)) {
67
+ return data.map(x => encode(x));
68
+ }
69
+ if (typeof data === 'function' || typeof data === 'object') {
70
+ return mapValues(data, x => encode(x));
71
+ }
72
+ // If we got this far, the data is not encodable.
73
+ throw new Error('Data cannot be encoded in JSON: ' + data);
74
+ }
75
+ /**
76
+ * Takes data that's been encoded in a JSON-friendly form and returns a form
77
+ * with richer datatypes, such as Dates, etc.
78
+ * @internal
79
+ * @param json - JSON to convert.
80
+ */
81
+ function decode(json) {
82
+ if (json == null) {
83
+ return json;
84
+ }
85
+ if (json['@type']) {
86
+ switch (json['@type']) {
87
+ case LONG_TYPE:
88
+ // Fall through and handle this the same as unsigned.
89
+ case UNSIGNED_LONG_TYPE: {
90
+ // Technically, this could work return a valid number for malformed
91
+ // data if there was a number followed by garbage. But it's just not
92
+ // worth all the extra code to detect that case.
93
+ const value = Number(json['value']);
94
+ if (isNaN(value)) {
95
+ throw new Error('Data cannot be decoded from JSON: ' + json);
96
+ }
97
+ return value;
98
+ }
99
+ default: {
100
+ throw new Error('Data cannot be decoded from JSON: ' + json);
101
+ }
102
+ }
103
+ }
104
+ if (Array.isArray(json)) {
105
+ return json.map(x => decode(x));
106
+ }
107
+ if (typeof json === 'function' || typeof json === 'object') {
108
+ return mapValues(json, x => decode(x));
109
+ }
110
+ // Anything else is safe to return.
111
+ return json;
112
112
  }
113
113
 
114
- /**
115
- * @license
116
- * Copyright 2020 Google LLC
117
- *
118
- * Licensed under the Apache License, Version 2.0 (the "License");
119
- * you may not use this file except in compliance with the License.
120
- * You may obtain a copy of the License at
121
- *
122
- * http://www.apache.org/licenses/LICENSE-2.0
123
- *
124
- * Unless required by applicable law or agreed to in writing, software
125
- * distributed under the License is distributed on an "AS IS" BASIS,
126
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127
- * See the License for the specific language governing permissions and
128
- * limitations under the License.
129
- */
130
- /**
131
- * Type constant for Firebase Functions.
132
- */
114
+ /**
115
+ * @license
116
+ * Copyright 2020 Google LLC
117
+ *
118
+ * Licensed under the Apache License, Version 2.0 (the "License");
119
+ * you may not use this file except in compliance with the License.
120
+ * You may obtain a copy of the License at
121
+ *
122
+ * http://www.apache.org/licenses/LICENSE-2.0
123
+ *
124
+ * Unless required by applicable law or agreed to in writing, software
125
+ * distributed under the License is distributed on an "AS IS" BASIS,
126
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127
+ * See the License for the specific language governing permissions and
128
+ * limitations under the License.
129
+ */
130
+ /**
131
+ * Type constant for Firebase Functions.
132
+ */
133
133
  const FUNCTIONS_TYPE = 'functions';
134
134
 
135
- /**
136
- * @license
137
- * Copyright 2017 Google LLC
138
- *
139
- * Licensed under the Apache License, Version 2.0 (the "License");
140
- * you may not use this file except in compliance with the License.
141
- * You may obtain a copy of the License at
142
- *
143
- * http://www.apache.org/licenses/LICENSE-2.0
144
- *
145
- * Unless required by applicable law or agreed to in writing, software
146
- * distributed under the License is distributed on an "AS IS" BASIS,
147
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
148
- * See the License for the specific language governing permissions and
149
- * limitations under the License.
150
- */
151
- /**
152
- * Standard error codes for different ways a request can fail, as defined by:
153
- * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
154
- *
155
- * This map is used primarily to convert from a backend error code string to
156
- * a client SDK error code string, and make sure it's in the supported set.
157
- */
158
- const errorCodeMap = {
159
- OK: 'ok',
160
- CANCELLED: 'cancelled',
161
- UNKNOWN: 'unknown',
162
- INVALID_ARGUMENT: 'invalid-argument',
163
- DEADLINE_EXCEEDED: 'deadline-exceeded',
164
- NOT_FOUND: 'not-found',
165
- ALREADY_EXISTS: 'already-exists',
166
- PERMISSION_DENIED: 'permission-denied',
167
- UNAUTHENTICATED: 'unauthenticated',
168
- RESOURCE_EXHAUSTED: 'resource-exhausted',
169
- FAILED_PRECONDITION: 'failed-precondition',
170
- ABORTED: 'aborted',
171
- OUT_OF_RANGE: 'out-of-range',
172
- UNIMPLEMENTED: 'unimplemented',
173
- INTERNAL: 'internal',
174
- UNAVAILABLE: 'unavailable',
175
- DATA_LOSS: 'data-loss'
176
- };
177
- /**
178
- * An error returned by the Firebase Functions client SDK.
179
- *
180
- * See {@link FunctionsErrorCode} for full documentation of codes.
181
- *
182
- * @public
183
- */
184
- class FunctionsError extends util.FirebaseError {
185
- /**
186
- * Constructs a new instance of the `FunctionsError` class.
187
- */
188
- constructor(
189
- /**
190
- * A standard error code that will be returned to the client. This also
191
- * determines the HTTP status code of the response, as defined in code.proto.
192
- */
193
- code, message,
194
- /**
195
- * Additional details to be converted to JSON and included in the error response.
196
- */
197
- details) {
198
- super(`${FUNCTIONS_TYPE}/${code}`, message || '');
199
- this.details = details;
200
- // Since the FirebaseError constructor sets the prototype of `this` to FirebaseError.prototype,
201
- // we also have to do it in all subclasses to allow for correct `instanceof` checks.
202
- Object.setPrototypeOf(this, FunctionsError.prototype);
203
- }
204
- }
205
- /**
206
- * Takes an HTTP status code and returns the corresponding ErrorCode.
207
- * This is the standard HTTP status code -> error mapping defined in:
208
- * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
209
- *
210
- * @param status An HTTP status code.
211
- * @return The corresponding ErrorCode, or ErrorCode.UNKNOWN if none.
212
- */
213
- function codeForHTTPStatus(status) {
214
- // Make sure any successful status is OK.
215
- if (status >= 200 && status < 300) {
216
- return 'ok';
217
- }
218
- switch (status) {
219
- case 0:
220
- // This can happen if the server returns 500.
221
- return 'internal';
222
- case 400:
223
- return 'invalid-argument';
224
- case 401:
225
- return 'unauthenticated';
226
- case 403:
227
- return 'permission-denied';
228
- case 404:
229
- return 'not-found';
230
- case 409:
231
- return 'aborted';
232
- case 429:
233
- return 'resource-exhausted';
234
- case 499:
235
- return 'cancelled';
236
- case 500:
237
- return 'internal';
238
- case 501:
239
- return 'unimplemented';
240
- case 503:
241
- return 'unavailable';
242
- case 504:
243
- return 'deadline-exceeded';
244
- }
245
- return 'unknown';
246
- }
247
- /**
248
- * Takes an HTTP response and returns the corresponding Error, if any.
249
- */
250
- function _errorForResponse(status, bodyJSON) {
251
- let code = codeForHTTPStatus(status);
252
- // Start with reasonable defaults from the status code.
253
- let description = code;
254
- let details = undefined;
255
- // Then look through the body for explicit details.
256
- try {
257
- const errorJSON = bodyJSON && bodyJSON.error;
258
- if (errorJSON) {
259
- const status = errorJSON.status;
260
- if (typeof status === 'string') {
261
- if (!errorCodeMap[status]) {
262
- // They must've included an unknown error code in the body.
263
- return new FunctionsError('internal', 'internal');
264
- }
265
- code = errorCodeMap[status];
266
- // TODO(klimt): Add better default descriptions for error enums.
267
- // The default description needs to be updated for the new code.
268
- description = status;
269
- }
270
- const message = errorJSON.message;
271
- if (typeof message === 'string') {
272
- description = message;
273
- }
274
- details = errorJSON.details;
275
- if (details !== undefined) {
276
- details = decode(details);
277
- }
278
- }
279
- }
280
- catch (e) {
281
- // If we couldn't parse explicit error data, that's fine.
282
- }
283
- if (code === 'ok') {
284
- // Technically, there's an edge case where a developer could explicitly
285
- // return an error code of OK, and we will treat it as success, but that
286
- // seems reasonable.
287
- return null;
288
- }
289
- return new FunctionsError(code, description, details);
135
+ /**
136
+ * @license
137
+ * Copyright 2017 Google LLC
138
+ *
139
+ * Licensed under the Apache License, Version 2.0 (the "License");
140
+ * you may not use this file except in compliance with the License.
141
+ * You may obtain a copy of the License at
142
+ *
143
+ * http://www.apache.org/licenses/LICENSE-2.0
144
+ *
145
+ * Unless required by applicable law or agreed to in writing, software
146
+ * distributed under the License is distributed on an "AS IS" BASIS,
147
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
148
+ * See the License for the specific language governing permissions and
149
+ * limitations under the License.
150
+ */
151
+ /**
152
+ * Standard error codes for different ways a request can fail, as defined by:
153
+ * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
154
+ *
155
+ * This map is used primarily to convert from a backend error code string to
156
+ * a client SDK error code string, and make sure it's in the supported set.
157
+ */
158
+ const errorCodeMap = {
159
+ OK: 'ok',
160
+ CANCELLED: 'cancelled',
161
+ UNKNOWN: 'unknown',
162
+ INVALID_ARGUMENT: 'invalid-argument',
163
+ DEADLINE_EXCEEDED: 'deadline-exceeded',
164
+ NOT_FOUND: 'not-found',
165
+ ALREADY_EXISTS: 'already-exists',
166
+ PERMISSION_DENIED: 'permission-denied',
167
+ UNAUTHENTICATED: 'unauthenticated',
168
+ RESOURCE_EXHAUSTED: 'resource-exhausted',
169
+ FAILED_PRECONDITION: 'failed-precondition',
170
+ ABORTED: 'aborted',
171
+ OUT_OF_RANGE: 'out-of-range',
172
+ UNIMPLEMENTED: 'unimplemented',
173
+ INTERNAL: 'internal',
174
+ UNAVAILABLE: 'unavailable',
175
+ DATA_LOSS: 'data-loss'
176
+ };
177
+ /**
178
+ * An error returned by the Firebase Functions client SDK.
179
+ *
180
+ * See {@link FunctionsErrorCode} for full documentation of codes.
181
+ *
182
+ * @public
183
+ */
184
+ class FunctionsError extends util.FirebaseError {
185
+ /**
186
+ * Constructs a new instance of the `FunctionsError` class.
187
+ */
188
+ constructor(
189
+ /**
190
+ * A standard error code that will be returned to the client. This also
191
+ * determines the HTTP status code of the response, as defined in code.proto.
192
+ */
193
+ code, message,
194
+ /**
195
+ * Additional details to be converted to JSON and included in the error response.
196
+ */
197
+ details) {
198
+ super(`${FUNCTIONS_TYPE}/${code}`, message || '');
199
+ this.details = details;
200
+ // Since the FirebaseError constructor sets the prototype of `this` to FirebaseError.prototype,
201
+ // we also have to do it in all subclasses to allow for correct `instanceof` checks.
202
+ Object.setPrototypeOf(this, FunctionsError.prototype);
203
+ }
204
+ }
205
+ /**
206
+ * Takes an HTTP status code and returns the corresponding ErrorCode.
207
+ * This is the standard HTTP status code -> error mapping defined in:
208
+ * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
209
+ *
210
+ * @param status An HTTP status code.
211
+ * @return The corresponding ErrorCode, or ErrorCode.UNKNOWN if none.
212
+ */
213
+ function codeForHTTPStatus(status) {
214
+ // Make sure any successful status is OK.
215
+ if (status >= 200 && status < 300) {
216
+ return 'ok';
217
+ }
218
+ switch (status) {
219
+ case 0:
220
+ // This can happen if the server returns 500.
221
+ return 'internal';
222
+ case 400:
223
+ return 'invalid-argument';
224
+ case 401:
225
+ return 'unauthenticated';
226
+ case 403:
227
+ return 'permission-denied';
228
+ case 404:
229
+ return 'not-found';
230
+ case 409:
231
+ return 'aborted';
232
+ case 429:
233
+ return 'resource-exhausted';
234
+ case 499:
235
+ return 'cancelled';
236
+ case 500:
237
+ return 'internal';
238
+ case 501:
239
+ return 'unimplemented';
240
+ case 503:
241
+ return 'unavailable';
242
+ case 504:
243
+ return 'deadline-exceeded';
244
+ }
245
+ return 'unknown';
246
+ }
247
+ /**
248
+ * Takes an HTTP response and returns the corresponding Error, if any.
249
+ */
250
+ function _errorForResponse(status, bodyJSON) {
251
+ let code = codeForHTTPStatus(status);
252
+ // Start with reasonable defaults from the status code.
253
+ let description = code;
254
+ let details = undefined;
255
+ // Then look through the body for explicit details.
256
+ try {
257
+ const errorJSON = bodyJSON && bodyJSON.error;
258
+ if (errorJSON) {
259
+ const status = errorJSON.status;
260
+ if (typeof status === 'string') {
261
+ if (!errorCodeMap[status]) {
262
+ // They must've included an unknown error code in the body.
263
+ return new FunctionsError('internal', 'internal');
264
+ }
265
+ code = errorCodeMap[status];
266
+ // TODO(klimt): Add better default descriptions for error enums.
267
+ // The default description needs to be updated for the new code.
268
+ description = status;
269
+ }
270
+ const message = errorJSON.message;
271
+ if (typeof message === 'string') {
272
+ description = message;
273
+ }
274
+ details = errorJSON.details;
275
+ if (details !== undefined) {
276
+ details = decode(details);
277
+ }
278
+ }
279
+ }
280
+ catch (e) {
281
+ // If we couldn't parse explicit error data, that's fine.
282
+ }
283
+ if (code === 'ok') {
284
+ // Technically, there's an edge case where a developer could explicitly
285
+ // return an error code of OK, and we will treat it as success, but that
286
+ // seems reasonable.
287
+ return null;
288
+ }
289
+ return new FunctionsError(code, description, details);
290
290
  }
291
291
 
292
- /**
293
- * @license
294
- * Copyright 2017 Google LLC
295
- *
296
- * Licensed under the Apache License, Version 2.0 (the "License");
297
- * you may not use this file except in compliance with the License.
298
- * You may obtain a copy of the License at
299
- *
300
- * http://www.apache.org/licenses/LICENSE-2.0
301
- *
302
- * Unless required by applicable law or agreed to in writing, software
303
- * distributed under the License is distributed on an "AS IS" BASIS,
304
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
305
- * See the License for the specific language governing permissions and
306
- * limitations under the License.
307
- */
308
- /**
309
- * Helper class to get metadata that should be included with a function call.
310
- * @internal
311
- */
312
- class ContextProvider {
313
- constructor(authProvider, messagingProvider, appCheckProvider) {
314
- this.auth = null;
315
- this.messaging = null;
316
- this.appCheck = null;
317
- this.auth = authProvider.getImmediate({ optional: true });
318
- this.messaging = messagingProvider.getImmediate({
319
- optional: true
320
- });
321
- if (!this.auth) {
322
- authProvider.get().then(auth => (this.auth = auth), () => {
323
- /* get() never rejects */
324
- });
325
- }
326
- if (!this.messaging) {
327
- messagingProvider.get().then(messaging => (this.messaging = messaging), () => {
328
- /* get() never rejects */
329
- });
330
- }
331
- if (!this.appCheck) {
332
- appCheckProvider.get().then(appCheck => (this.appCheck = appCheck), () => {
333
- /* get() never rejects */
334
- });
335
- }
336
- }
337
- async getAuthToken() {
338
- if (!this.auth) {
339
- return undefined;
340
- }
341
- try {
342
- const token = await this.auth.getToken();
343
- return token === null || token === void 0 ? void 0 : token.accessToken;
344
- }
345
- catch (e) {
346
- // If there's any error when trying to get the auth token, leave it off.
347
- return undefined;
348
- }
349
- }
350
- async getMessagingToken() {
351
- if (!this.messaging ||
352
- !('Notification' in self) ||
353
- Notification.permission !== 'granted') {
354
- return undefined;
355
- }
356
- try {
357
- return await this.messaging.getToken();
358
- }
359
- catch (e) {
360
- // We don't warn on this, because it usually means messaging isn't set up.
361
- // console.warn('Failed to retrieve instance id token.', e);
362
- // If there's any error when trying to get the token, leave it off.
363
- return undefined;
364
- }
365
- }
366
- async getAppCheckToken(limitedUseAppCheckTokens) {
367
- if (this.appCheck) {
368
- const result = limitedUseAppCheckTokens
369
- ? await this.appCheck.getLimitedUseToken()
370
- : await this.appCheck.getToken();
371
- if (result.error) {
372
- // Do not send the App Check header to the functions endpoint if
373
- // there was an error from the App Check exchange endpoint. The App
374
- // Check SDK will already have logged the error to console.
375
- return null;
376
- }
377
- return result.token;
378
- }
379
- return null;
380
- }
381
- async getContext(limitedUseAppCheckTokens) {
382
- const authToken = await this.getAuthToken();
383
- const messagingToken = await this.getMessagingToken();
384
- const appCheckToken = await this.getAppCheckToken(limitedUseAppCheckTokens);
385
- return { authToken, messagingToken, appCheckToken };
386
- }
292
+ /**
293
+ * @license
294
+ * Copyright 2017 Google LLC
295
+ *
296
+ * Licensed under the Apache License, Version 2.0 (the "License");
297
+ * you may not use this file except in compliance with the License.
298
+ * You may obtain a copy of the License at
299
+ *
300
+ * http://www.apache.org/licenses/LICENSE-2.0
301
+ *
302
+ * Unless required by applicable law or agreed to in writing, software
303
+ * distributed under the License is distributed on an "AS IS" BASIS,
304
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
305
+ * See the License for the specific language governing permissions and
306
+ * limitations under the License.
307
+ */
308
+ /**
309
+ * Helper class to get metadata that should be included with a function call.
310
+ * @internal
311
+ */
312
+ class ContextProvider {
313
+ constructor(authProvider, messagingProvider, appCheckProvider) {
314
+ this.auth = null;
315
+ this.messaging = null;
316
+ this.appCheck = null;
317
+ this.auth = authProvider.getImmediate({ optional: true });
318
+ this.messaging = messagingProvider.getImmediate({
319
+ optional: true
320
+ });
321
+ if (!this.auth) {
322
+ authProvider.get().then(auth => (this.auth = auth), () => {
323
+ /* get() never rejects */
324
+ });
325
+ }
326
+ if (!this.messaging) {
327
+ messagingProvider.get().then(messaging => (this.messaging = messaging), () => {
328
+ /* get() never rejects */
329
+ });
330
+ }
331
+ if (!this.appCheck) {
332
+ appCheckProvider.get().then(appCheck => (this.appCheck = appCheck), () => {
333
+ /* get() never rejects */
334
+ });
335
+ }
336
+ }
337
+ async getAuthToken() {
338
+ if (!this.auth) {
339
+ return undefined;
340
+ }
341
+ try {
342
+ const token = await this.auth.getToken();
343
+ return token === null || token === void 0 ? void 0 : token.accessToken;
344
+ }
345
+ catch (e) {
346
+ // If there's any error when trying to get the auth token, leave it off.
347
+ return undefined;
348
+ }
349
+ }
350
+ async getMessagingToken() {
351
+ if (!this.messaging ||
352
+ !('Notification' in self) ||
353
+ Notification.permission !== 'granted') {
354
+ return undefined;
355
+ }
356
+ try {
357
+ return await this.messaging.getToken();
358
+ }
359
+ catch (e) {
360
+ // We don't warn on this, because it usually means messaging isn't set up.
361
+ // console.warn('Failed to retrieve instance id token.', e);
362
+ // If there's any error when trying to get the token, leave it off.
363
+ return undefined;
364
+ }
365
+ }
366
+ async getAppCheckToken(limitedUseAppCheckTokens) {
367
+ if (this.appCheck) {
368
+ const result = limitedUseAppCheckTokens
369
+ ? await this.appCheck.getLimitedUseToken()
370
+ : await this.appCheck.getToken();
371
+ if (result.error) {
372
+ // Do not send the App Check header to the functions endpoint if
373
+ // there was an error from the App Check exchange endpoint. The App
374
+ // Check SDK will already have logged the error to console.
375
+ return null;
376
+ }
377
+ return result.token;
378
+ }
379
+ return null;
380
+ }
381
+ async getContext(limitedUseAppCheckTokens) {
382
+ const authToken = await this.getAuthToken();
383
+ const messagingToken = await this.getMessagingToken();
384
+ const appCheckToken = await this.getAppCheckToken(limitedUseAppCheckTokens);
385
+ return { authToken, messagingToken, appCheckToken };
386
+ }
387
387
  }
388
388
 
389
- /**
390
- * @license
391
- * Copyright 2017 Google LLC
392
- *
393
- * Licensed under the Apache License, Version 2.0 (the "License");
394
- * you may not use this file except in compliance with the License.
395
- * You may obtain a copy of the License at
396
- *
397
- * http://www.apache.org/licenses/LICENSE-2.0
398
- *
399
- * Unless required by applicable law or agreed to in writing, software
400
- * distributed under the License is distributed on an "AS IS" BASIS,
401
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
402
- * See the License for the specific language governing permissions and
403
- * limitations under the License.
404
- */
405
- const DEFAULT_REGION = 'us-central1';
406
- /**
407
- * Returns a Promise that will be rejected after the given duration.
408
- * The error will be of type FunctionsError.
409
- *
410
- * @param millis Number of milliseconds to wait before rejecting.
411
- */
412
- function failAfter(millis) {
413
- // Node timers and browser timers are fundamentally incompatible, but we
414
- // don't care about the value here
415
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
416
- let timer = null;
417
- return {
418
- promise: new Promise((_, reject) => {
419
- timer = setTimeout(() => {
420
- reject(new FunctionsError('deadline-exceeded', 'deadline-exceeded'));
421
- }, millis);
422
- }),
423
- cancel: () => {
424
- if (timer) {
425
- clearTimeout(timer);
426
- }
427
- }
428
- };
429
- }
430
- /**
431
- * The main class for the Firebase Functions SDK.
432
- * @internal
433
- */
434
- class FunctionsService {
435
- /**
436
- * Creates a new Functions service for the given app.
437
- * @param app - The FirebaseApp to use.
438
- */
439
- constructor(app, authProvider, messagingProvider, appCheckProvider, regionOrCustomDomain = DEFAULT_REGION) {
440
- this.app = app;
441
- this.emulatorOrigin = null;
442
- this.contextProvider = new ContextProvider(authProvider, messagingProvider, appCheckProvider);
443
- // Cancels all ongoing requests when resolved.
444
- this.cancelAllRequests = new Promise(resolve => {
445
- this.deleteService = () => {
446
- return Promise.resolve(resolve());
447
- };
448
- });
449
- // Resolve the region or custom domain overload by attempting to parse it.
450
- try {
451
- const url = new URL(regionOrCustomDomain);
452
- this.customDomain =
453
- url.origin + (url.pathname === '/' ? '' : url.pathname);
454
- this.region = DEFAULT_REGION;
455
- }
456
- catch (e) {
457
- this.customDomain = null;
458
- this.region = regionOrCustomDomain;
459
- }
460
- }
461
- _delete() {
462
- return this.deleteService();
463
- }
464
- /**
465
- * Returns the URL for a callable with the given name.
466
- * @param name - The name of the callable.
467
- * @internal
468
- */
469
- _url(name) {
470
- const projectId = this.app.options.projectId;
471
- if (this.emulatorOrigin !== null) {
472
- const origin = this.emulatorOrigin;
473
- return `${origin}/${projectId}/${this.region}/${name}`;
474
- }
475
- if (this.customDomain !== null) {
476
- return `${this.customDomain}/${name}`;
477
- }
478
- return `https://${this.region}-${projectId}.cloudfunctions.net/${name}`;
479
- }
480
- }
481
- /**
482
- * Modify this instance to communicate with the Cloud Functions emulator.
483
- *
484
- * Note: this must be called before this instance has been used to do any operations.
485
- *
486
- * @param host The emulator host (ex: localhost)
487
- * @param port The emulator port (ex: 5001)
488
- * @public
489
- */
490
- function connectFunctionsEmulator$1(functionsInstance, host, port) {
491
- functionsInstance.emulatorOrigin = `http://${host}:${port}`;
492
- }
493
- /**
494
- * Returns a reference to the callable https trigger with the given name.
495
- * @param name - The name of the trigger.
496
- * @public
497
- */
498
- function httpsCallable$1(functionsInstance, name, options) {
499
- return (data => {
500
- return call(functionsInstance, name, data, options || {});
501
- });
502
- }
503
- /**
504
- * Returns a reference to the callable https trigger with the given url.
505
- * @param url - The url of the trigger.
506
- * @public
507
- */
508
- function httpsCallableFromURL$1(functionsInstance, url, options) {
509
- return (data => {
510
- return callAtURL(functionsInstance, url, data, options || {});
511
- });
512
- }
513
- /**
514
- * Does an HTTP POST and returns the completed response.
515
- * @param url The url to post to.
516
- * @param body The JSON body of the post.
517
- * @param headers The HTTP headers to include in the request.
518
- * @return A Promise that will succeed when the request finishes.
519
- */
520
- async function postJSON(url, body, headers) {
521
- headers['Content-Type'] = 'application/json';
522
- let response;
523
- try {
524
- response = await fetch(url, {
525
- method: 'POST',
526
- body: JSON.stringify(body),
527
- headers
528
- });
529
- }
530
- catch (e) {
531
- // This could be an unhandled error on the backend, or it could be a
532
- // network error. There's no way to know, since an unhandled error on the
533
- // backend will fail to set the proper CORS header, and thus will be
534
- // treated as a network error by fetch.
535
- return {
536
- status: 0,
537
- json: null
538
- };
539
- }
540
- let json = null;
541
- try {
542
- json = await response.json();
543
- }
544
- catch (e) {
545
- // If we fail to parse JSON, it will fail the same as an empty body.
546
- }
547
- return {
548
- status: response.status,
549
- json
550
- };
551
- }
552
- /**
553
- * Calls a callable function asynchronously and returns the result.
554
- * @param name The name of the callable trigger.
555
- * @param data The data to pass as params to the function.s
556
- */
557
- function call(functionsInstance, name, data, options) {
558
- const url = functionsInstance._url(name);
559
- return callAtURL(functionsInstance, url, data, options);
560
- }
561
- /**
562
- * Calls a callable function asynchronously and returns the result.
563
- * @param url The url of the callable trigger.
564
- * @param data The data to pass as params to the function.s
565
- */
566
- async function callAtURL(functionsInstance, url, data, options) {
567
- // Encode any special types, such as dates, in the input data.
568
- data = encode(data);
569
- const body = { data };
570
- // Add a header for the authToken.
571
- const headers = {};
572
- const context = await functionsInstance.contextProvider.getContext(options.limitedUseAppCheckTokens);
573
- if (context.authToken) {
574
- headers['Authorization'] = 'Bearer ' + context.authToken;
575
- }
576
- if (context.messagingToken) {
577
- headers['Firebase-Instance-ID-Token'] = context.messagingToken;
578
- }
579
- if (context.appCheckToken !== null) {
580
- headers['X-Firebase-AppCheck'] = context.appCheckToken;
581
- }
582
- // Default timeout to 70s, but let the options override it.
583
- const timeout = options.timeout || 70000;
584
- const failAfterHandle = failAfter(timeout);
585
- const response = await Promise.race([
586
- postJSON(url, body, headers),
587
- failAfterHandle.promise,
588
- functionsInstance.cancelAllRequests
589
- ]);
590
- // Always clear the failAfter timeout
591
- failAfterHandle.cancel();
592
- // If service was deleted, interrupted response throws an error.
593
- if (!response) {
594
- throw new FunctionsError('cancelled', 'Firebase Functions instance was deleted.');
595
- }
596
- // Check for an error status, regardless of http status.
597
- const error = _errorForResponse(response.status, response.json);
598
- if (error) {
599
- throw error;
600
- }
601
- if (!response.json) {
602
- throw new FunctionsError('internal', 'Response is not valid JSON object.');
603
- }
604
- let responseData = response.json.data;
605
- // TODO(klimt): For right now, allow "result" instead of "data", for
606
- // backwards compatibility.
607
- if (typeof responseData === 'undefined') {
608
- responseData = response.json.result;
609
- }
610
- if (typeof responseData === 'undefined') {
611
- // Consider the response malformed.
612
- throw new FunctionsError('internal', 'Response is missing data field.');
613
- }
614
- // Decode any special types, such as dates, in the returned data.
615
- const decodedData = decode(responseData);
616
- return { data: decodedData };
389
+ /**
390
+ * @license
391
+ * Copyright 2017 Google LLC
392
+ *
393
+ * Licensed under the Apache License, Version 2.0 (the "License");
394
+ * you may not use this file except in compliance with the License.
395
+ * You may obtain a copy of the License at
396
+ *
397
+ * http://www.apache.org/licenses/LICENSE-2.0
398
+ *
399
+ * Unless required by applicable law or agreed to in writing, software
400
+ * distributed under the License is distributed on an "AS IS" BASIS,
401
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
402
+ * See the License for the specific language governing permissions and
403
+ * limitations under the License.
404
+ */
405
+ const DEFAULT_REGION = 'us-central1';
406
+ /**
407
+ * Returns a Promise that will be rejected after the given duration.
408
+ * The error will be of type FunctionsError.
409
+ *
410
+ * @param millis Number of milliseconds to wait before rejecting.
411
+ */
412
+ function failAfter(millis) {
413
+ // Node timers and browser timers are fundamentally incompatible, but we
414
+ // don't care about the value here
415
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
416
+ let timer = null;
417
+ return {
418
+ promise: new Promise((_, reject) => {
419
+ timer = setTimeout(() => {
420
+ reject(new FunctionsError('deadline-exceeded', 'deadline-exceeded'));
421
+ }, millis);
422
+ }),
423
+ cancel: () => {
424
+ if (timer) {
425
+ clearTimeout(timer);
426
+ }
427
+ }
428
+ };
429
+ }
430
+ /**
431
+ * The main class for the Firebase Functions SDK.
432
+ * @internal
433
+ */
434
+ class FunctionsService {
435
+ /**
436
+ * Creates a new Functions service for the given app.
437
+ * @param app - The FirebaseApp to use.
438
+ */
439
+ constructor(app, authProvider, messagingProvider, appCheckProvider, regionOrCustomDomain = DEFAULT_REGION) {
440
+ this.app = app;
441
+ this.emulatorOrigin = null;
442
+ this.contextProvider = new ContextProvider(authProvider, messagingProvider, appCheckProvider);
443
+ // Cancels all ongoing requests when resolved.
444
+ this.cancelAllRequests = new Promise(resolve => {
445
+ this.deleteService = () => {
446
+ return Promise.resolve(resolve());
447
+ };
448
+ });
449
+ // Resolve the region or custom domain overload by attempting to parse it.
450
+ try {
451
+ const url = new URL(regionOrCustomDomain);
452
+ this.customDomain =
453
+ url.origin + (url.pathname === '/' ? '' : url.pathname);
454
+ this.region = DEFAULT_REGION;
455
+ }
456
+ catch (e) {
457
+ this.customDomain = null;
458
+ this.region = regionOrCustomDomain;
459
+ }
460
+ }
461
+ _delete() {
462
+ return this.deleteService();
463
+ }
464
+ /**
465
+ * Returns the URL for a callable with the given name.
466
+ * @param name - The name of the callable.
467
+ * @internal
468
+ */
469
+ _url(name) {
470
+ const projectId = this.app.options.projectId;
471
+ if (this.emulatorOrigin !== null) {
472
+ const origin = this.emulatorOrigin;
473
+ return `${origin}/${projectId}/${this.region}/${name}`;
474
+ }
475
+ if (this.customDomain !== null) {
476
+ return `${this.customDomain}/${name}`;
477
+ }
478
+ return `https://${this.region}-${projectId}.cloudfunctions.net/${name}`;
479
+ }
480
+ }
481
+ /**
482
+ * Modify this instance to communicate with the Cloud Functions emulator.
483
+ *
484
+ * Note: this must be called before this instance has been used to do any operations.
485
+ *
486
+ * @param host The emulator host (ex: localhost)
487
+ * @param port The emulator port (ex: 5001)
488
+ * @public
489
+ */
490
+ function connectFunctionsEmulator$1(functionsInstance, host, port) {
491
+ functionsInstance.emulatorOrigin = `http://${host}:${port}`;
492
+ }
493
+ /**
494
+ * Returns a reference to the callable https trigger with the given name.
495
+ * @param name - The name of the trigger.
496
+ * @public
497
+ */
498
+ function httpsCallable$1(functionsInstance, name, options) {
499
+ return (data => {
500
+ return call(functionsInstance, name, data, options || {});
501
+ });
502
+ }
503
+ /**
504
+ * Returns a reference to the callable https trigger with the given url.
505
+ * @param url - The url of the trigger.
506
+ * @public
507
+ */
508
+ function httpsCallableFromURL$1(functionsInstance, url, options) {
509
+ return (data => {
510
+ return callAtURL(functionsInstance, url, data, options || {});
511
+ });
512
+ }
513
+ /**
514
+ * Does an HTTP POST and returns the completed response.
515
+ * @param url The url to post to.
516
+ * @param body The JSON body of the post.
517
+ * @param headers The HTTP headers to include in the request.
518
+ * @return A Promise that will succeed when the request finishes.
519
+ */
520
+ async function postJSON(url, body, headers) {
521
+ headers['Content-Type'] = 'application/json';
522
+ let response;
523
+ try {
524
+ response = await fetch(url, {
525
+ method: 'POST',
526
+ body: JSON.stringify(body),
527
+ headers
528
+ });
529
+ }
530
+ catch (e) {
531
+ // This could be an unhandled error on the backend, or it could be a
532
+ // network error. There's no way to know, since an unhandled error on the
533
+ // backend will fail to set the proper CORS header, and thus will be
534
+ // treated as a network error by fetch.
535
+ return {
536
+ status: 0,
537
+ json: null
538
+ };
539
+ }
540
+ let json = null;
541
+ try {
542
+ json = await response.json();
543
+ }
544
+ catch (e) {
545
+ // If we fail to parse JSON, it will fail the same as an empty body.
546
+ }
547
+ return {
548
+ status: response.status,
549
+ json
550
+ };
551
+ }
552
+ /**
553
+ * Calls a callable function asynchronously and returns the result.
554
+ * @param name The name of the callable trigger.
555
+ * @param data The data to pass as params to the function.s
556
+ */
557
+ function call(functionsInstance, name, data, options) {
558
+ const url = functionsInstance._url(name);
559
+ return callAtURL(functionsInstance, url, data, options);
560
+ }
561
+ /**
562
+ * Calls a callable function asynchronously and returns the result.
563
+ * @param url The url of the callable trigger.
564
+ * @param data The data to pass as params to the function.s
565
+ */
566
+ async function callAtURL(functionsInstance, url, data, options) {
567
+ // Encode any special types, such as dates, in the input data.
568
+ data = encode(data);
569
+ const body = { data };
570
+ // Add a header for the authToken.
571
+ const headers = {};
572
+ const context = await functionsInstance.contextProvider.getContext(options.limitedUseAppCheckTokens);
573
+ if (context.authToken) {
574
+ headers['Authorization'] = 'Bearer ' + context.authToken;
575
+ }
576
+ if (context.messagingToken) {
577
+ headers['Firebase-Instance-ID-Token'] = context.messagingToken;
578
+ }
579
+ if (context.appCheckToken !== null) {
580
+ headers['X-Firebase-AppCheck'] = context.appCheckToken;
581
+ }
582
+ // Default timeout to 70s, but let the options override it.
583
+ const timeout = options.timeout || 70000;
584
+ const failAfterHandle = failAfter(timeout);
585
+ const response = await Promise.race([
586
+ postJSON(url, body, headers),
587
+ failAfterHandle.promise,
588
+ functionsInstance.cancelAllRequests
589
+ ]);
590
+ // Always clear the failAfter timeout
591
+ failAfterHandle.cancel();
592
+ // If service was deleted, interrupted response throws an error.
593
+ if (!response) {
594
+ throw new FunctionsError('cancelled', 'Firebase Functions instance was deleted.');
595
+ }
596
+ // Check for an error status, regardless of http status.
597
+ const error = _errorForResponse(response.status, response.json);
598
+ if (error) {
599
+ throw error;
600
+ }
601
+ if (!response.json) {
602
+ throw new FunctionsError('internal', 'Response is not valid JSON object.');
603
+ }
604
+ let responseData = response.json.data;
605
+ // TODO(klimt): For right now, allow "result" instead of "data", for
606
+ // backwards compatibility.
607
+ if (typeof responseData === 'undefined') {
608
+ responseData = response.json.result;
609
+ }
610
+ if (typeof responseData === 'undefined') {
611
+ // Consider the response malformed.
612
+ throw new FunctionsError('internal', 'Response is missing data field.');
613
+ }
614
+ // Decode any special types, such as dates, in the returned data.
615
+ const decodedData = decode(responseData);
616
+ return { data: decodedData };
617
617
  }
618
618
 
619
619
  const name = "@firebase/functions";
620
- const version = "0.11.9";
620
+ const version = "0.11.10";
621
621
 
622
- /**
623
- * @license
624
- * Copyright 2019 Google LLC
625
- *
626
- * Licensed under the Apache License, Version 2.0 (the "License");
627
- * you may not use this file except in compliance with the License.
628
- * You may obtain a copy of the License at
629
- *
630
- * http://www.apache.org/licenses/LICENSE-2.0
631
- *
632
- * Unless required by applicable law or agreed to in writing, software
633
- * distributed under the License is distributed on an "AS IS" BASIS,
634
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
635
- * See the License for the specific language governing permissions and
636
- * limitations under the License.
637
- */
638
- const AUTH_INTERNAL_NAME = 'auth-internal';
639
- const APP_CHECK_INTERNAL_NAME = 'app-check-internal';
640
- const MESSAGING_INTERNAL_NAME = 'messaging-internal';
641
- function registerFunctions(variant) {
642
- const factory = (container, { instanceIdentifier: regionOrCustomDomain }) => {
643
- // Dependencies
644
- const app = container.getProvider('app').getImmediate();
645
- const authProvider = container.getProvider(AUTH_INTERNAL_NAME);
646
- const messagingProvider = container.getProvider(MESSAGING_INTERNAL_NAME);
647
- const appCheckProvider = container.getProvider(APP_CHECK_INTERNAL_NAME);
648
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
649
- return new FunctionsService(app, authProvider, messagingProvider, appCheckProvider, regionOrCustomDomain);
650
- };
651
- app._registerComponent(new component.Component(FUNCTIONS_TYPE, factory, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
652
- app.registerVersion(name, version, variant);
653
- // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation
654
- app.registerVersion(name, version, 'cjs2017');
622
+ /**
623
+ * @license
624
+ * Copyright 2019 Google LLC
625
+ *
626
+ * Licensed under the Apache License, Version 2.0 (the "License");
627
+ * you may not use this file except in compliance with the License.
628
+ * You may obtain a copy of the License at
629
+ *
630
+ * http://www.apache.org/licenses/LICENSE-2.0
631
+ *
632
+ * Unless required by applicable law or agreed to in writing, software
633
+ * distributed under the License is distributed on an "AS IS" BASIS,
634
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
635
+ * See the License for the specific language governing permissions and
636
+ * limitations under the License.
637
+ */
638
+ const AUTH_INTERNAL_NAME = 'auth-internal';
639
+ const APP_CHECK_INTERNAL_NAME = 'app-check-internal';
640
+ const MESSAGING_INTERNAL_NAME = 'messaging-internal';
641
+ function registerFunctions(variant) {
642
+ const factory = (container, { instanceIdentifier: regionOrCustomDomain }) => {
643
+ // Dependencies
644
+ const app = container.getProvider('app').getImmediate();
645
+ const authProvider = container.getProvider(AUTH_INTERNAL_NAME);
646
+ const messagingProvider = container.getProvider(MESSAGING_INTERNAL_NAME);
647
+ const appCheckProvider = container.getProvider(APP_CHECK_INTERNAL_NAME);
648
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
649
+ return new FunctionsService(app, authProvider, messagingProvider, appCheckProvider, regionOrCustomDomain);
650
+ };
651
+ app._registerComponent(new component.Component(FUNCTIONS_TYPE, factory, "PUBLIC" /* ComponentType.PUBLIC */).setMultipleInstances(true));
652
+ app.registerVersion(name, version, variant);
653
+ // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation
654
+ app.registerVersion(name, version, 'cjs2017');
655
655
  }
656
656
 
657
- /**
658
- * @license
659
- * Copyright 2020 Google LLC
660
- *
661
- * Licensed under the Apache License, Version 2.0 (the "License");
662
- * you may not use this file except in compliance with the License.
663
- * You may obtain a copy of the License at
664
- *
665
- * http://www.apache.org/licenses/LICENSE-2.0
666
- *
667
- * Unless required by applicable law or agreed to in writing, software
668
- * distributed under the License is distributed on an "AS IS" BASIS,
669
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
670
- * See the License for the specific language governing permissions and
671
- * limitations under the License.
672
- */
673
- /**
674
- * Returns a {@link Functions} instance for the given app.
675
- * @param app - The {@link @firebase/app#FirebaseApp} to use.
676
- * @param regionOrCustomDomain - one of:
677
- * a) The region the callable functions are located in (ex: us-central1)
678
- * b) A custom domain hosting the callable functions (ex: https://mydomain.com)
679
- * @public
680
- */
681
- function getFunctions(app$1 = app.getApp(), regionOrCustomDomain = DEFAULT_REGION) {
682
- // Dependencies
683
- const functionsProvider = app._getProvider(util.getModularInstance(app$1), FUNCTIONS_TYPE);
684
- const functionsInstance = functionsProvider.getImmediate({
685
- identifier: regionOrCustomDomain
686
- });
687
- const emulator = util.getDefaultEmulatorHostnameAndPort('functions');
688
- if (emulator) {
689
- connectFunctionsEmulator(functionsInstance, ...emulator);
690
- }
691
- return functionsInstance;
692
- }
693
- /**
694
- * Modify this instance to communicate with the Cloud Functions emulator.
695
- *
696
- * Note: this must be called before this instance has been used to do any operations.
697
- *
698
- * @param host - The emulator host (ex: localhost)
699
- * @param port - The emulator port (ex: 5001)
700
- * @public
701
- */
702
- function connectFunctionsEmulator(functionsInstance, host, port) {
703
- connectFunctionsEmulator$1(util.getModularInstance(functionsInstance), host, port);
704
- }
705
- /**
706
- * Returns a reference to the callable HTTPS trigger with the given name.
707
- * @param name - The name of the trigger.
708
- * @public
709
- */
710
- function httpsCallable(functionsInstance, name, options) {
711
- return httpsCallable$1(util.getModularInstance(functionsInstance), name, options);
712
- }
713
- /**
714
- * Returns a reference to the callable HTTPS trigger with the specified url.
715
- * @param url - The url of the trigger.
716
- * @public
717
- */
718
- function httpsCallableFromURL(functionsInstance, url, options) {
719
- return httpsCallableFromURL$1(util.getModularInstance(functionsInstance), url, options);
657
+ /**
658
+ * @license
659
+ * Copyright 2020 Google LLC
660
+ *
661
+ * Licensed under the Apache License, Version 2.0 (the "License");
662
+ * you may not use this file except in compliance with the License.
663
+ * You may obtain a copy of the License at
664
+ *
665
+ * http://www.apache.org/licenses/LICENSE-2.0
666
+ *
667
+ * Unless required by applicable law or agreed to in writing, software
668
+ * distributed under the License is distributed on an "AS IS" BASIS,
669
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
670
+ * See the License for the specific language governing permissions and
671
+ * limitations under the License.
672
+ */
673
+ /**
674
+ * Returns a {@link Functions} instance for the given app.
675
+ * @param app - The {@link @firebase/app#FirebaseApp} to use.
676
+ * @param regionOrCustomDomain - one of:
677
+ * a) The region the callable functions are located in (ex: us-central1)
678
+ * b) A custom domain hosting the callable functions (ex: https://mydomain.com)
679
+ * @public
680
+ */
681
+ function getFunctions(app$1 = app.getApp(), regionOrCustomDomain = DEFAULT_REGION) {
682
+ // Dependencies
683
+ const functionsProvider = app._getProvider(util.getModularInstance(app$1), FUNCTIONS_TYPE);
684
+ const functionsInstance = functionsProvider.getImmediate({
685
+ identifier: regionOrCustomDomain
686
+ });
687
+ const emulator = util.getDefaultEmulatorHostnameAndPort('functions');
688
+ if (emulator) {
689
+ connectFunctionsEmulator(functionsInstance, ...emulator);
690
+ }
691
+ return functionsInstance;
692
+ }
693
+ /**
694
+ * Modify this instance to communicate with the Cloud Functions emulator.
695
+ *
696
+ * Note: this must be called before this instance has been used to do any operations.
697
+ *
698
+ * @param host - The emulator host (ex: localhost)
699
+ * @param port - The emulator port (ex: 5001)
700
+ * @public
701
+ */
702
+ function connectFunctionsEmulator(functionsInstance, host, port) {
703
+ connectFunctionsEmulator$1(util.getModularInstance(functionsInstance), host, port);
704
+ }
705
+ /**
706
+ * Returns a reference to the callable HTTPS trigger with the given name.
707
+ * @param name - The name of the trigger.
708
+ * @public
709
+ */
710
+ function httpsCallable(functionsInstance, name, options) {
711
+ return httpsCallable$1(util.getModularInstance(functionsInstance), name, options);
712
+ }
713
+ /**
714
+ * Returns a reference to the callable HTTPS trigger with the specified url.
715
+ * @param url - The url of the trigger.
716
+ * @public
717
+ */
718
+ function httpsCallableFromURL(functionsInstance, url, options) {
719
+ return httpsCallableFromURL$1(util.getModularInstance(functionsInstance), url, options);
720
720
  }
721
721
 
722
- /**
723
- * Cloud Functions for Firebase
724
- *
725
- * @packageDocumentation
726
- */
722
+ /**
723
+ * Cloud Functions for Firebase
724
+ *
725
+ * @packageDocumentation
726
+ */
727
727
  registerFunctions();
728
728
 
729
729
  exports.FunctionsError = FunctionsError;