@firebase/functions 0.11.8 → 0.11.9

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