Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.esm2017.js 25KB

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