Нема описа
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.node.esm.js 25KB

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