util.d.ts 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  1. /**
  2. *
  3. * This method checks whether cookie is enabled within current browser
  4. * @return true if cookie is enabled within current browser
  5. */
  6. export declare function areCookiesEnabled(): boolean;
  7. /**
  8. * Throws an error if the provided assertion is falsy
  9. */
  10. export declare const assert: (assertion: unknown, message: string) => void;
  11. /**
  12. * Returns an Error object suitable for throwing.
  13. */
  14. export declare const assertionError: (message: string) => Error;
  15. /** Turn synchronous function into one called asynchronously. */
  16. export declare function async(fn: Function, onError?: ErrorFn): Function;
  17. /**
  18. * @license
  19. * Copyright 2017 Google LLC
  20. *
  21. * Licensed under the Apache License, Version 2.0 (the "License");
  22. * you may not use this file except in compliance with the License.
  23. * You may obtain a copy of the License at
  24. *
  25. * http://www.apache.org/licenses/LICENSE-2.0
  26. *
  27. * Unless required by applicable law or agreed to in writing, software
  28. * distributed under the License is distributed on an "AS IS" BASIS,
  29. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  30. * See the License for the specific language governing permissions and
  31. * limitations under the License.
  32. */
  33. declare interface Base64 {
  34. byteToCharMap_: {
  35. [key: number]: string;
  36. } | null;
  37. charToByteMap_: {
  38. [key: string]: number;
  39. } | null;
  40. byteToCharMapWebSafe_: {
  41. [key: number]: string;
  42. } | null;
  43. charToByteMapWebSafe_: {
  44. [key: string]: number;
  45. } | null;
  46. ENCODED_VALS_BASE: string;
  47. readonly ENCODED_VALS: string;
  48. readonly ENCODED_VALS_WEBSAFE: string;
  49. HAS_NATIVE_SUPPORT: boolean;
  50. encodeByteArray(input: number[] | Uint8Array, webSafe?: boolean): string;
  51. encodeString(input: string, webSafe?: boolean): string;
  52. decodeString(input: string, webSafe: boolean): string;
  53. decodeStringToByteArray(input: string, webSafe: boolean): number[];
  54. init_(): void;
  55. }
  56. export declare const base64: Base64;
  57. /**
  58. * URL-safe base64 decoding
  59. *
  60. * NOTE: DO NOT use the global atob() function - it does NOT support the
  61. * base64Url variant encoding.
  62. *
  63. * @param str To be decoded
  64. * @return Decoded result, if possible
  65. */
  66. export declare const base64Decode: (str: string) => string | null;
  67. /**
  68. * URL-safe base64 encoding
  69. */
  70. export declare const base64Encode: (str: string) => string;
  71. /**
  72. * URL-safe base64 encoding (without "." padding in the end).
  73. * e.g. Used in JSON Web Token (JWT) parts.
  74. */
  75. export declare const base64urlEncodeWithoutPadding: (str: string) => string;
  76. /**
  77. * Based on the backoff method from
  78. * https://github.com/google/closure-library/blob/master/closure/goog/math/exponentialbackoff.js.
  79. * Extracted here so we don't need to pass metadata and a stateful ExponentialBackoff object around.
  80. */
  81. export declare function calculateBackoffMillis(backoffCount: number, intervalMillis?: number, backoffFactor?: number): number;
  82. /**
  83. * @license
  84. * Copyright 2017 Google LLC
  85. *
  86. * Licensed under the Apache License, Version 2.0 (the "License");
  87. * you may not use this file except in compliance with the License.
  88. * You may obtain a copy of the License at
  89. *
  90. * http://www.apache.org/licenses/LICENSE-2.0
  91. *
  92. * Unless required by applicable law or agreed to in writing, software
  93. * distributed under the License is distributed on an "AS IS" BASIS,
  94. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  95. * See the License for the specific language governing permissions and
  96. * limitations under the License.
  97. */
  98. declare interface Claims {
  99. [key: string]: {};
  100. }
  101. /**
  102. * @license
  103. * Copyright 2021 Google LLC
  104. *
  105. * Licensed under the Apache License, Version 2.0 (the "License");
  106. * you may not use this file except in compliance with the License.
  107. * You may obtain a copy of the License at
  108. *
  109. * http://www.apache.org/licenses/LICENSE-2.0
  110. *
  111. * Unless required by applicable law or agreed to in writing, software
  112. * distributed under the License is distributed on an "AS IS" BASIS,
  113. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  114. * See the License for the specific language governing permissions and
  115. * limitations under the License.
  116. */
  117. export declare interface Compat<T> {
  118. _delegate: T;
  119. }
  120. export declare type CompleteFn = () => void;
  121. /**
  122. * @fileoverview Firebase constants. Some of these (@defines) can be overridden at compile-time.
  123. */
  124. export declare const CONSTANTS: {
  125. /**
  126. * @define {boolean} Whether this is the client Node.js SDK.
  127. */
  128. NODE_CLIENT: boolean;
  129. /**
  130. * @define {boolean} Whether this is the Admin Node.js SDK.
  131. */
  132. NODE_ADMIN: boolean;
  133. /**
  134. * Firebase SDK Version
  135. */
  136. SDK_VERSION: string;
  137. };
  138. /**
  139. * @license
  140. * Copyright 2017 Google LLC
  141. *
  142. * Licensed under the Apache License, Version 2.0 (the "License");
  143. * you may not use this file except in compliance with the License.
  144. * You may obtain a copy of the License at
  145. *
  146. * http://www.apache.org/licenses/LICENSE-2.0
  147. *
  148. * Unless required by applicable law or agreed to in writing, software
  149. * distributed under the License is distributed on an "AS IS" BASIS,
  150. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  151. * See the License for the specific language governing permissions and
  152. * limitations under the License.
  153. */
  154. export declare function contains<T extends object>(obj: T, key: string): boolean;
  155. export declare function createMockUserToken(token: EmulatorMockTokenOptions, projectId?: string): string;
  156. /**
  157. * Helper to make a Subscribe function (just like Promise helps make a
  158. * Thenable).
  159. *
  160. * @param executor Function which can make calls to a single Observer
  161. * as a proxy.
  162. * @param onNoObservers Callback when count of Observers goes to zero.
  163. */
  164. export declare function createSubscribe<T>(executor: Executor<T>, onNoObservers?: Executor<T>): Subscribe<T>;
  165. /**
  166. * Decodes a Firebase auth. token into constituent parts.
  167. *
  168. * Notes:
  169. * - May return with invalid / incomplete claims if there's no native base64 decoding support.
  170. * - Doesn't check if the token is actually valid.
  171. */
  172. export declare const decode: (token: string) => DecodedToken;
  173. /**
  174. * An error encountered while decoding base64 string.
  175. */
  176. export declare class DecodeBase64StringError extends Error {
  177. readonly name = "DecodeBase64StringError";
  178. }
  179. declare interface DecodedToken {
  180. header: object;
  181. claims: Claims;
  182. data: object;
  183. signature: string;
  184. }
  185. declare interface DecodedToken {
  186. header: object;
  187. claims: Claims;
  188. data: object;
  189. signature: string;
  190. }
  191. /**
  192. * @license
  193. * Copyright 2017 Google LLC
  194. *
  195. * Licensed under the Apache License, Version 2.0 (the "License");
  196. * you may not use this file except in compliance with the License.
  197. * You may obtain a copy of the License at
  198. *
  199. * http://www.apache.org/licenses/LICENSE-2.0
  200. *
  201. * Unless required by applicable law or agreed to in writing, software
  202. * distributed under the License is distributed on an "AS IS" BASIS,
  203. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  204. * See the License for the specific language governing permissions and
  205. * limitations under the License.
  206. */
  207. /**
  208. * Do a deep-copy of basic JavaScript Objects or Arrays.
  209. */
  210. export declare function deepCopy<T>(value: T): T;
  211. /**
  212. * Deep equal two objects. Support Arrays and Objects.
  213. */
  214. export declare function deepEqual(a: object, b: object): boolean;
  215. /**
  216. * Copy properties from source to target (recursively allows extension
  217. * of Objects and Arrays). Scalar values in the target are over-written.
  218. * If target is undefined, an object of the appropriate type will be created
  219. * (and returned).
  220. *
  221. * We recursively copy all child properties of plain Objects in the source- so
  222. * that namespace- like dictionaries are merged.
  223. *
  224. * Note that the target can be a function, in which case the properties in
  225. * the source Object are copied onto it as static properties of the Function.
  226. *
  227. * Note: we don't merge __proto__ to prevent prototype pollution
  228. */
  229. export declare function deepExtend(target: unknown, source: unknown): unknown;
  230. /**
  231. * @license
  232. * Copyright 2017 Google LLC
  233. *
  234. * Licensed under the Apache License, Version 2.0 (the "License");
  235. * you may not use this file except in compliance with the License.
  236. * You may obtain a copy of the License at
  237. *
  238. * http://www.apache.org/licenses/LICENSE-2.0
  239. *
  240. * Unless required by applicable law or agreed to in writing, software
  241. * distributed under the License is distributed on an "AS IS" BASIS,
  242. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  243. * See the License for the specific language governing permissions and
  244. * limitations under the License.
  245. */
  246. export declare class Deferred<R> {
  247. promise: Promise<R>;
  248. reject: (value?: unknown) => void;
  249. resolve: (value?: unknown) => void;
  250. constructor();
  251. /**
  252. * Our API internals are not promisified and cannot because our callback APIs have subtle expectations around
  253. * invoking promises inline, which Promises are forbidden to do. This method accepts an optional node-style callback
  254. * and returns a node-style callback which will resolve or reject the Deferred's promise.
  255. */
  256. wrapCallback(callback?: (error?: unknown, value?: unknown) => void): (error: unknown, value?: unknown) => void;
  257. }
  258. export declare type EmulatorMockTokenOptions = ({
  259. user_id: string;
  260. } | {
  261. sub: string;
  262. }) & Partial<FirebaseIdToken>;
  263. export declare interface ErrorData {
  264. [key: string]: unknown;
  265. }
  266. export declare class ErrorFactory<ErrorCode extends string, ErrorParams extends {
  267. readonly [K in ErrorCode]?: ErrorData;
  268. } = {}> {
  269. private readonly service;
  270. private readonly serviceName;
  271. private readonly errors;
  272. constructor(service: string, serviceName: string, errors: ErrorMap<ErrorCode>);
  273. create<K extends ErrorCode>(code: K, ...data: K extends keyof ErrorParams ? [ErrorParams[K]] : []): FirebaseError;
  274. }
  275. export declare type ErrorFn = (error: Error) => void;
  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. * @fileoverview Standardized Firebase Error.
  294. *
  295. * Usage:
  296. *
  297. * // TypeScript string literals for type-safe codes
  298. * type Err =
  299. * 'unknown' |
  300. * 'object-not-found'
  301. * ;
  302. *
  303. * // Closure enum for type-safe error codes
  304. * // at-enum {string}
  305. * var Err = {
  306. * UNKNOWN: 'unknown',
  307. * OBJECT_NOT_FOUND: 'object-not-found',
  308. * }
  309. *
  310. * let errors: Map<Err, string> = {
  311. * 'generic-error': "Unknown error",
  312. * 'file-not-found': "Could not find file: {$file}",
  313. * };
  314. *
  315. * // Type-safe function - must pass a valid error code as param.
  316. * let error = new ErrorFactory<Err>('service', 'Service', errors);
  317. *
  318. * ...
  319. * throw error.create(Err.GENERIC);
  320. * ...
  321. * throw error.create(Err.FILE_NOT_FOUND, {'file': fileName});
  322. * ...
  323. * // Service: Could not file file: foo.txt (service/file-not-found).
  324. *
  325. * catch (e) {
  326. * assert(e.message === "Could not find file: foo.txt.");
  327. * if ((e as FirebaseError)?.code === 'service/file-not-found') {
  328. * console.log("Could not read file: " + e['file']);
  329. * }
  330. * }
  331. */
  332. export declare type ErrorMap<ErrorCode extends string> = {
  333. readonly [K in ErrorCode]: string;
  334. };
  335. /**
  336. * Generates a string to prefix an error message about failed argument validation
  337. *
  338. * @param fnName The function name
  339. * @param argName The name of the argument
  340. * @return The prefix to add to the error thrown for validation.
  341. */
  342. export declare function errorPrefix(fnName: string, argName: string): string;
  343. export declare type Executor<T> = (observer: Observer<T>) => void;
  344. /**
  345. * @license
  346. * Copyright 2022 Google LLC
  347. *
  348. * Licensed under the Apache License, Version 2.0 (the "License");
  349. * you may not use this file except in compliance with the License.
  350. * You may obtain a copy of the License at
  351. *
  352. * http://www.apache.org/licenses/LICENSE-2.0
  353. *
  354. * Unless required by applicable law or agreed to in writing, software
  355. * distributed under the License is distributed on an "AS IS" BASIS,
  356. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  357. * See the License for the specific language governing permissions and
  358. * limitations under the License.
  359. */
  360. /**
  361. * Keys for experimental properties on the `FirebaseDefaults` object.
  362. * @public
  363. */
  364. export declare type ExperimentalKey = 'authTokenSyncURL' | 'authIdTokenMaxAge';
  365. /**
  366. * Extract the query string part of a URL, including the leading question mark (if present).
  367. */
  368. export declare function extractQuerystring(url: string): string;
  369. /**
  370. * An object that can be injected into the environment as __FIREBASE_DEFAULTS__,
  371. * either as a property of globalThis, a shell environment variable, or a
  372. * cookie.
  373. *
  374. * This object can be used to automatically configure and initialize
  375. * a Firebase app as well as any emulators.
  376. *
  377. * @public
  378. */
  379. export declare interface FirebaseDefaults {
  380. config?: Record<string, string>;
  381. emulatorHosts?: Record<string, string>;
  382. _authTokenSyncURL?: string;
  383. _authIdTokenMaxAge?: number;
  384. /**
  385. * Override Firebase's runtime environment detection and
  386. * force the SDK to act as if it were in the specified environment.
  387. */
  388. forceEnvironment?: 'browser' | 'node';
  389. [key: string]: unknown;
  390. }
  391. export declare class FirebaseError extends Error {
  392. /** The error code for this error. */
  393. readonly code: string;
  394. /** Custom data for this error. */
  395. customData?: Record<string, unknown> | undefined;
  396. /** The custom name for all FirebaseErrors. */
  397. readonly name: string;
  398. constructor(
  399. /** The error code for this error. */
  400. code: string, message: string,
  401. /** Custom data for this error. */
  402. customData?: Record<string, unknown> | undefined);
  403. }
  404. declare interface FirebaseIdToken {
  405. iss: string;
  406. aud: string;
  407. sub: string;
  408. iat: number;
  409. exp: number;
  410. user_id: string;
  411. auth_time: number;
  412. provider_id?: 'anonymous';
  413. email?: string;
  414. email_verified?: boolean;
  415. phone_number?: string;
  416. name?: string;
  417. picture?: string;
  418. firebase: {
  419. sign_in_provider: FirebaseSignInProvider;
  420. identities?: {
  421. [provider in FirebaseSignInProvider]?: string[];
  422. };
  423. };
  424. [claim: string]: unknown;
  425. uid?: never;
  426. }
  427. /**
  428. * @license
  429. * Copyright 2021 Google LLC
  430. *
  431. * Licensed under the Apache License, Version 2.0 (the "License");
  432. * you may not use this file except in compliance with the License.
  433. * You may obtain a copy of the License at
  434. *
  435. * http://www.apache.org/licenses/LICENSE-2.0
  436. *
  437. * Unless required by applicable law or agreed to in writing, software
  438. * distributed under the License is distributed on an "AS IS" BASIS,
  439. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  440. * See the License for the specific language governing permissions and
  441. * limitations under the License.
  442. */
  443. export declare type FirebaseSignInProvider = 'custom' | 'email' | 'password' | 'phone' | 'anonymous' | 'google.com' | 'facebook.com' | 'github.com' | 'twitter.com' | 'microsoft.com' | 'apple.com';
  444. /**
  445. * Returns Firebase app config stored in the __FIREBASE_DEFAULTS__ object.
  446. * @public
  447. */
  448. export declare const getDefaultAppConfig: () => Record<string, string> | undefined;
  449. /**
  450. * Returns emulator host stored in the __FIREBASE_DEFAULTS__ object
  451. * for the given product.
  452. * @returns a URL host formatted like `127.0.0.1:9999` or `[::1]:4000` if available
  453. * @public
  454. */
  455. export declare const getDefaultEmulatorHost: (productName: string) => string | undefined;
  456. /**
  457. * Returns emulator hostname and port stored in the __FIREBASE_DEFAULTS__ object
  458. * for the given product.
  459. * @returns a pair of hostname and port like `["::1", 4000]` if available
  460. * @public
  461. */
  462. export declare const getDefaultEmulatorHostnameAndPort: (productName: string) => [hostname: string, port: number] | undefined;
  463. /**
  464. * Get the __FIREBASE_DEFAULTS__ object. It checks in order:
  465. * (1) if such an object exists as a property of `globalThis`
  466. * (2) if such an object was provided on a shell environment variable
  467. * (3) if such an object exists in a cookie
  468. * @public
  469. */
  470. export declare const getDefaults: () => FirebaseDefaults | undefined;
  471. /**
  472. * Returns an experimental setting on the __FIREBASE_DEFAULTS__ object (properties
  473. * prefixed by "_")
  474. * @public
  475. */
  476. export declare const getExperimentalSetting: <T extends ExperimentalKey>(name: T) => FirebaseDefaults[`_${T}`];
  477. /**
  478. * @license
  479. * Copyright 2022 Google LLC
  480. *
  481. * Licensed under the Apache License, Version 2.0 (the "License");
  482. * you may not use this file except in compliance with the License.
  483. * You may obtain a copy of the License at
  484. *
  485. * http://www.apache.org/licenses/LICENSE-2.0
  486. *
  487. * Unless required by applicable law or agreed to in writing, software
  488. * distributed under the License is distributed on an "AS IS" BASIS,
  489. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  490. * See the License for the specific language governing permissions and
  491. * limitations under the License.
  492. */
  493. /**
  494. * Polyfill for `globalThis` object.
  495. * @returns the `globalThis` object for the given environment.
  496. * @public
  497. */
  498. export declare function getGlobal(): typeof globalThis;
  499. export declare function getModularInstance<ExpService>(service: Compat<ExpService> | ExpService): ExpService;
  500. /**
  501. * @license
  502. * Copyright 2017 Google LLC
  503. *
  504. * Licensed under the Apache License, Version 2.0 (the "License");
  505. * you may not use this file except in compliance with the License.
  506. * You may obtain a copy of the License at
  507. *
  508. * http://www.apache.org/licenses/LICENSE-2.0
  509. *
  510. * Unless required by applicable law or agreed to in writing, software
  511. * distributed under the License is distributed on an "AS IS" BASIS,
  512. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  513. * See the License for the specific language governing permissions and
  514. * limitations under the License.
  515. */
  516. /**
  517. * Returns navigator.userAgent string or '' if it's not defined.
  518. * @return user agent string
  519. */
  520. export declare function getUA(): string;
  521. /**
  522. * Attempts to peer into an auth token and determine if it's an admin auth token by looking at the claims portion.
  523. *
  524. * Notes:
  525. * - May return a false negative if there's no native base64 decoding support.
  526. * - Doesn't check if the token is actually valid.
  527. */
  528. export declare const isAdmin: (token: string) => boolean;
  529. /**
  530. * Detect Browser Environment.
  531. * Note: This will return true for certain test frameworks that are incompletely
  532. * mimicking a browser, and should not lead to assuming all browser APIs are
  533. * available.
  534. */
  535. export declare function isBrowser(): boolean;
  536. export declare function isBrowserExtension(): boolean;
  537. /**
  538. * Detect Cloudflare Worker context.
  539. */
  540. export declare function isCloudflareWorker(): boolean;
  541. /** Detects Electron apps. */
  542. export declare function isElectron(): boolean;
  543. export declare function isEmpty(obj: object): obj is {};
  544. /** Detects Internet Explorer. */
  545. export declare function isIE(): boolean;
  546. /**
  547. * This method checks if indexedDB is supported by current browser/service worker context
  548. * @return true if indexedDB is supported by current browser/service worker context
  549. */
  550. export declare function isIndexedDBAvailable(): boolean;
  551. /**
  552. * Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
  553. *
  554. * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap
  555. * in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally
  556. * wait for a callback.
  557. */
  558. export declare function isMobileCordova(): boolean;
  559. /**
  560. * Detect Node.js.
  561. *
  562. * @return true if Node.js environment is detected or specified.
  563. */
  564. export declare function isNode(): boolean;
  565. /**
  566. * Detect whether the current SDK build is the Node version.
  567. *
  568. * @return true if it's the Node SDK build.
  569. */
  570. export declare function isNodeSdk(): boolean;
  571. /**
  572. * Detect React Native.
  573. *
  574. * @return true if ReactNative environment is detected.
  575. */
  576. export declare function isReactNative(): boolean;
  577. /** Returns true if we are running in Safari. */
  578. export declare function isSafari(): boolean;
  579. /**
  580. * Decodes a Firebase auth. token and returns its issued at time if valid, null otherwise.
  581. *
  582. * Notes:
  583. * - May return null if there's no native base64 decoding support.
  584. * - Doesn't check if the token is actually valid.
  585. */
  586. export declare const issuedAtTime: (token: string) => number | null;
  587. /** Detects Universal Windows Platform apps. */
  588. export declare function isUWP(): boolean;
  589. /**
  590. * Decodes a Firebase auth. token and checks the validity of its format. Expects a valid issued-at time.
  591. *
  592. * Notes:
  593. * - May return a false negative if there's no native base64 decoding support.
  594. * - Doesn't check if the token is actually valid.
  595. */
  596. export declare const isValidFormat: (token: string) => boolean;
  597. /**
  598. * Decodes a Firebase auth. token and checks the validity of its time-based claims. Will return true if the
  599. * token is within the time window authorized by the 'nbf' (not-before) and 'iat' (issued-at) claims.
  600. *
  601. * Notes:
  602. * - May return a false negative if there's no native base64 decoding support.
  603. * - Doesn't check if the token is actually valid.
  604. */
  605. export declare const isValidTimestamp: (token: string) => boolean;
  606. /**
  607. * Detect Web Worker context.
  608. */
  609. export declare function isWebWorker(): boolean;
  610. /**
  611. * @license
  612. * Copyright 2017 Google LLC
  613. *
  614. * Licensed under the Apache License, Version 2.0 (the "License");
  615. * you may not use this file except in compliance with the License.
  616. * You may obtain a copy of the License at
  617. *
  618. * http://www.apache.org/licenses/LICENSE-2.0
  619. *
  620. * Unless required by applicable law or agreed to in writing, software
  621. * distributed under the License is distributed on an "AS IS" BASIS,
  622. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  623. * See the License for the specific language governing permissions and
  624. * limitations under the License.
  625. */
  626. /**
  627. * Evaluates a JSON string into a javascript object.
  628. *
  629. * @param {string} str A string containing JSON.
  630. * @return {*} The javascript object representing the specified JSON.
  631. */
  632. export declare function jsonEval(str: string): unknown;
  633. export declare function map<K extends string, V, U>(obj: {
  634. [key in K]: V;
  635. }, fn: (value: V, key: K, obj: {
  636. [key in K]: V;
  637. }) => U, contextObj?: unknown): {
  638. [key in K]: U;
  639. };
  640. /**
  641. * The maximum milliseconds to increase to.
  642. *
  643. * <p>Visible for testing
  644. */
  645. export declare const MAX_VALUE_MILLIS: number;
  646. /**
  647. * @license
  648. * Copyright 2017 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. export declare type NextFn<T> = (value: T) => void;
  663. export declare interface Observable<T> {
  664. subscribe: Subscribe<T>;
  665. }
  666. export declare interface Observer<T> {
  667. next: NextFn<T>;
  668. error: ErrorFn;
  669. complete: CompleteFn;
  670. }
  671. /**
  672. * @license
  673. * Copyright 2020 Google LLC
  674. *
  675. * Licensed under the Apache License, Version 2.0 (the "License");
  676. * you may not use this file except in compliance with the License.
  677. * You may obtain a copy of the License at
  678. *
  679. * http://www.apache.org/licenses/LICENSE-2.0
  680. *
  681. * Unless required by applicable law or agreed to in writing, software
  682. * distributed under the License is distributed on an "AS IS" BASIS,
  683. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  684. * See the License for the specific language governing permissions and
  685. * limitations under the License.
  686. */
  687. /**
  688. * Provide English ordinal letters after a number
  689. */
  690. export declare function ordinal(i: number): string;
  691. export declare type PartialObserver<T> = Partial<Observer<T>>;
  692. /**
  693. * @license
  694. * Copyright 2022 Google LLC
  695. *
  696. * Licensed under the Apache License, Version 2.0 (the "License");
  697. * you may not use this file except in compliance with the License.
  698. * You may obtain a copy of the License at
  699. *
  700. * http://www.apache.org/licenses/LICENSE-2.0
  701. *
  702. * Unless required by applicable law or agreed to in writing, software
  703. * distributed under the License is distributed on an "AS IS" BASIS,
  704. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  705. * See the License for the specific language governing permissions and
  706. * limitations under the License.
  707. */
  708. /**
  709. * Rejects if the given promise doesn't resolve in timeInMS milliseconds.
  710. * @internal
  711. */
  712. export declare function promiseWithTimeout<T>(promise: Promise<T>, timeInMS?: number): Promise<T>;
  713. /**
  714. * @license
  715. * Copyright 2017 Google LLC
  716. *
  717. * Licensed under the Apache License, Version 2.0 (the "License");
  718. * you may not use this file except in compliance with the License.
  719. * You may obtain a copy of the License at
  720. *
  721. * http://www.apache.org/licenses/LICENSE-2.0
  722. *
  723. * Unless required by applicable law or agreed to in writing, software
  724. * distributed under the License is distributed on an "AS IS" BASIS,
  725. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  726. * See the License for the specific language governing permissions and
  727. * limitations under the License.
  728. */
  729. /**
  730. * Returns a querystring-formatted string (e.g. &arg=val&arg2=val2) from a
  731. * params object (e.g. {arg: 'val', arg2: 'val2'})
  732. * Note: You must prepend it with ? when adding it to a URL.
  733. */
  734. export declare function querystring(querystringParams: {
  735. [key: string]: string | number;
  736. }): string;
  737. /**
  738. * Decodes a querystring (e.g. ?arg=val&arg2=val2) into a params object
  739. * (e.g. {arg: 'val', arg2: 'val2'})
  740. */
  741. export declare function querystringDecode(querystring: string): Record<string, string>;
  742. /**
  743. * The percentage of backoff time to randomize by.
  744. * See
  745. * http://go/safe-client-behavior#step-1-determine-the-appropriate-retry-interval-to-handle-spike-traffic
  746. * for context.
  747. *
  748. * <p>Visible for testing
  749. */
  750. export declare const RANDOM_FACTOR = 0.5;
  751. export declare function safeGet<T extends object, K extends keyof T>(obj: T, key: K): T[K] | undefined;
  752. /**
  753. * @license
  754. * Copyright 2017 Google LLC
  755. *
  756. * Licensed under the Apache License, Version 2.0 (the "License");
  757. * you may not use this file except in compliance with the License.
  758. * You may obtain a copy of the License at
  759. *
  760. * http://www.apache.org/licenses/LICENSE-2.0
  761. *
  762. * Unless required by applicable law or agreed to in writing, software
  763. * distributed under the License is distributed on an "AS IS" BASIS,
  764. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  765. * See the License for the specific language governing permissions and
  766. * limitations under the License.
  767. */
  768. /**
  769. * @fileoverview SHA-1 cryptographic hash.
  770. * Variable names follow the notation in FIPS PUB 180-3:
  771. * http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf.
  772. *
  773. * Usage:
  774. * var sha1 = new sha1();
  775. * sha1.update(bytes);
  776. * var hash = sha1.digest();
  777. *
  778. * Performance:
  779. * Chrome 23: ~400 Mbit/s
  780. * Firefox 16: ~250 Mbit/s
  781. *
  782. */
  783. /**
  784. * SHA-1 cryptographic hash constructor.
  785. *
  786. * The properties declared here are discussed in the above algorithm document.
  787. * @constructor
  788. * @final
  789. * @struct
  790. */
  791. export declare class Sha1 {
  792. /**
  793. * Holds the previous values of accumulated variables a-e in the compress_
  794. * function.
  795. * @private
  796. */
  797. private chain_;
  798. /**
  799. * A buffer holding the partially computed hash result.
  800. * @private
  801. */
  802. private buf_;
  803. /**
  804. * An array of 80 bytes, each a part of the message to be hashed. Referred to
  805. * as the message schedule in the docs.
  806. * @private
  807. */
  808. private W_;
  809. /**
  810. * Contains data needed to pad messages less than 64 bytes.
  811. * @private
  812. */
  813. private pad_;
  814. /**
  815. * @private {number}
  816. */
  817. private inbuf_;
  818. /**
  819. * @private {number}
  820. */
  821. private total_;
  822. blockSize: number;
  823. constructor();
  824. reset(): void;
  825. /**
  826. * Internal compress helper function.
  827. * @param buf Block to compress.
  828. * @param offset Offset of the block in the buffer.
  829. * @private
  830. */
  831. compress_(buf: number[] | Uint8Array | string, offset?: number): void;
  832. update(bytes?: number[] | Uint8Array | string, length?: number): void;
  833. /** @override */
  834. digest(): number[];
  835. }
  836. /**
  837. * Returns JSON representing a javascript object.
  838. * @param {*} data JavaScript object to be stringified.
  839. * @return {string} The JSON contents of the object.
  840. */
  841. export declare function stringify(data: unknown): string;
  842. /**
  843. * Calculate length without actually converting; useful for doing cheaper validation.
  844. * @param {string} str
  845. * @return {number}
  846. */
  847. export declare const stringLength: (str: string) => number;
  848. export declare interface StringLike {
  849. toString(): string;
  850. }
  851. /**
  852. * @param {string} str
  853. * @return {Array}
  854. */
  855. export declare const stringToByteArray: (str: string) => number[];
  856. /**
  857. * The Subscribe interface has two forms - passing the inline function
  858. * callbacks, or a object interface with callback properties.
  859. */
  860. export declare interface Subscribe<T> {
  861. (next?: NextFn<T>, error?: ErrorFn, complete?: CompleteFn): Unsubscribe;
  862. (observer: PartialObserver<T>): Unsubscribe;
  863. }
  864. export declare type Unsubscribe = () => void;
  865. /**
  866. * Copied from https://stackoverflow.com/a/2117523
  867. * Generates a new uuid.
  868. * @public
  869. */
  870. export declare const uuidv4: () => string;
  871. /**
  872. * Check to make sure the appropriate number of arguments are provided for a public function.
  873. * Throws an error if it fails.
  874. *
  875. * @param fnName The function name
  876. * @param minCount The minimum number of arguments to allow for the function call
  877. * @param maxCount The maximum number of argument to allow for the function call
  878. * @param argCount The actual number of arguments provided.
  879. */
  880. export declare const validateArgCount: (fnName: string, minCount: number, maxCount: number, argCount: number) => void;
  881. export declare function validateCallback(fnName: string, argumentName: string, callback: Function, optional: boolean): void;
  882. export declare function validateContextObject(fnName: string, argumentName: string, context: unknown, optional: boolean): void;
  883. /**
  884. * This method validates browser/sw context for indexedDB by opening a dummy indexedDB database and reject
  885. * if errors occur during the database open operation.
  886. *
  887. * @throws exception if current browser/sw context can't run idb.open (ex: Safari iframe, Firefox
  888. * private browsing)
  889. */
  890. export declare function validateIndexedDBOpenable(): Promise<boolean>;
  891. /**
  892. * @param fnName
  893. * @param argumentNumber
  894. * @param namespace
  895. * @param optional
  896. */
  897. export declare function validateNamespace(fnName: string, namespace: string, optional: boolean): void;
  898. export { }