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