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