util-public.d.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  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 promiseified 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. */
  532. export declare function isBrowser(): boolean;
  533. export declare function isBrowserExtension(): boolean;
  534. /** Detects Electron apps. */
  535. export declare function isElectron(): boolean;
  536. export declare function isEmpty(obj: object): obj is {};
  537. /** Detects Internet Explorer. */
  538. export declare function isIE(): boolean;
  539. /**
  540. * This method checks if indexedDB is supported by current browser/service worker context
  541. * @return true if indexedDB is supported by current browser/service worker context
  542. */
  543. export declare function isIndexedDBAvailable(): boolean;
  544. /**
  545. * Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
  546. *
  547. * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap
  548. * in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally
  549. * wait for a callback.
  550. */
  551. export declare function isMobileCordova(): boolean;
  552. /**
  553. * Detect Node.js.
  554. *
  555. * @return true if Node.js environment is detected or specified.
  556. */
  557. export declare function isNode(): boolean;
  558. /**
  559. * Detect whether the current SDK build is the Node version.
  560. *
  561. * @return true if it's the Node SDK build.
  562. */
  563. export declare function isNodeSdk(): boolean;
  564. /**
  565. * Detect React Native.
  566. *
  567. * @return true if ReactNative environment is detected.
  568. */
  569. export declare function isReactNative(): boolean;
  570. /** Returns true if we are running in Safari. */
  571. export declare function isSafari(): boolean;
  572. /**
  573. * Decodes a Firebase auth. token and returns its issued at time if valid, null otherwise.
  574. *
  575. * Notes:
  576. * - May return null if there's no native base64 decoding support.
  577. * - Doesn't check if the token is actually valid.
  578. */
  579. export declare const issuedAtTime: (token: string) => number | null;
  580. /** Detects Universal Windows Platform apps. */
  581. export declare function isUWP(): boolean;
  582. /**
  583. * Decodes a Firebase auth. token and checks the validity of its format. Expects a valid issued-at time.
  584. *
  585. * Notes:
  586. * - May return a false negative if there's no native base64 decoding support.
  587. * - Doesn't check if the token is actually valid.
  588. */
  589. export declare const isValidFormat: (token: string) => boolean;
  590. /**
  591. * Decodes a Firebase auth. token and checks the validity of its time-based claims. Will return true if the
  592. * token is within the time window authorized by the 'nbf' (not-before) and 'iat' (issued-at) claims.
  593. *
  594. * Notes:
  595. * - May return a false negative if there's no native base64 decoding support.
  596. * - Doesn't check if the token is actually valid.
  597. */
  598. export declare const isValidTimestamp: (token: string) => boolean;
  599. /**
  600. * @license
  601. * Copyright 2017 Google LLC
  602. *
  603. * Licensed under the Apache License, Version 2.0 (the "License");
  604. * you may not use this file except in compliance with the License.
  605. * You may obtain a copy of the License at
  606. *
  607. * http://www.apache.org/licenses/LICENSE-2.0
  608. *
  609. * Unless required by applicable law or agreed to in writing, software
  610. * distributed under the License is distributed on an "AS IS" BASIS,
  611. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  612. * See the License for the specific language governing permissions and
  613. * limitations under the License.
  614. */
  615. /**
  616. * Evaluates a JSON string into a javascript object.
  617. *
  618. * @param {string} str A string containing JSON.
  619. * @return {*} The javascript object representing the specified JSON.
  620. */
  621. export declare function jsonEval(str: string): unknown;
  622. export declare function map<K extends string, V, U>(obj: {
  623. [key in K]: V;
  624. }, fn: (value: V, key: K, obj: {
  625. [key in K]: V;
  626. }) => U, contextObj?: unknown): {
  627. [key in K]: U;
  628. };
  629. /**
  630. * The maximum milliseconds to increase to.
  631. *
  632. * <p>Visible for testing
  633. */
  634. export declare const MAX_VALUE_MILLIS: number;
  635. /**
  636. * @license
  637. * Copyright 2017 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. export declare type NextFn<T> = (value: T) => void;
  652. export declare interface Observable<T> {
  653. subscribe: Subscribe<T>;
  654. }
  655. export declare interface Observer<T> {
  656. next: NextFn<T>;
  657. error: ErrorFn;
  658. complete: CompleteFn;
  659. }
  660. /**
  661. * @license
  662. * Copyright 2020 Google LLC
  663. *
  664. * Licensed under the Apache License, Version 2.0 (the "License");
  665. * you may not use this file except in compliance with the License.
  666. * You may obtain a copy of the License at
  667. *
  668. * http://www.apache.org/licenses/LICENSE-2.0
  669. *
  670. * Unless required by applicable law or agreed to in writing, software
  671. * distributed under the License is distributed on an "AS IS" BASIS,
  672. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  673. * See the License for the specific language governing permissions and
  674. * limitations under the License.
  675. */
  676. /**
  677. * Provide English ordinal letters after a number
  678. */
  679. export declare function ordinal(i: number): string;
  680. export declare type PartialObserver<T> = Partial<Observer<T>>;
  681. /* Excluded from this release type: promiseWithTimeout */
  682. /**
  683. * @license
  684. * Copyright 2017 Google LLC
  685. *
  686. * Licensed under the Apache License, Version 2.0 (the "License");
  687. * you may not use this file except in compliance with the License.
  688. * You may obtain a copy of the License at
  689. *
  690. * http://www.apache.org/licenses/LICENSE-2.0
  691. *
  692. * Unless required by applicable law or agreed to in writing, software
  693. * distributed under the License is distributed on an "AS IS" BASIS,
  694. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  695. * See the License for the specific language governing permissions and
  696. * limitations under the License.
  697. */
  698. /**
  699. * Returns a querystring-formatted string (e.g. &arg=val&arg2=val2) from a
  700. * params object (e.g. {arg: 'val', arg2: 'val2'})
  701. * Note: You must prepend it with ? when adding it to a URL.
  702. */
  703. export declare function querystring(querystringParams: {
  704. [key: string]: string | number;
  705. }): string;
  706. /**
  707. * Decodes a querystring (e.g. ?arg=val&arg2=val2) into a params object
  708. * (e.g. {arg: 'val', arg2: 'val2'})
  709. */
  710. export declare function querystringDecode(querystring: string): Record<string, string>;
  711. /**
  712. * The percentage of backoff time to randomize by.
  713. * See
  714. * http://go/safe-client-behavior#step-1-determine-the-appropriate-retry-interval-to-handle-spike-traffic
  715. * for context.
  716. *
  717. * <p>Visible for testing
  718. */
  719. export declare const RANDOM_FACTOR = 0.5;
  720. export declare function safeGet<T extends object, K extends keyof T>(obj: T, key: K): T[K] | undefined;
  721. /**
  722. * @license
  723. * Copyright 2017 Google LLC
  724. *
  725. * Licensed under the Apache License, Version 2.0 (the "License");
  726. * you may not use this file except in compliance with the License.
  727. * You may obtain a copy of the License at
  728. *
  729. * http://www.apache.org/licenses/LICENSE-2.0
  730. *
  731. * Unless required by applicable law or agreed to in writing, software
  732. * distributed under the License is distributed on an "AS IS" BASIS,
  733. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  734. * See the License for the specific language governing permissions and
  735. * limitations under the License.
  736. */
  737. /**
  738. * @fileoverview SHA-1 cryptographic hash.
  739. * Variable names follow the notation in FIPS PUB 180-3:
  740. * http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf.
  741. *
  742. * Usage:
  743. * var sha1 = new sha1();
  744. * sha1.update(bytes);
  745. * var hash = sha1.digest();
  746. *
  747. * Performance:
  748. * Chrome 23: ~400 Mbit/s
  749. * Firefox 16: ~250 Mbit/s
  750. *
  751. */
  752. /**
  753. * SHA-1 cryptographic hash constructor.
  754. *
  755. * The properties declared here are discussed in the above algorithm document.
  756. * @constructor
  757. * @final
  758. * @struct
  759. */
  760. export declare class Sha1 {
  761. /**
  762. * Holds the previous values of accumulated variables a-e in the compress_
  763. * function.
  764. * @private
  765. */
  766. private chain_;
  767. /**
  768. * A buffer holding the partially computed hash result.
  769. * @private
  770. */
  771. private buf_;
  772. /**
  773. * An array of 80 bytes, each a part of the message to be hashed. Referred to
  774. * as the message schedule in the docs.
  775. * @private
  776. */
  777. private W_;
  778. /**
  779. * Contains data needed to pad messages less than 64 bytes.
  780. * @private
  781. */
  782. private pad_;
  783. /**
  784. * @private {number}
  785. */
  786. private inbuf_;
  787. /**
  788. * @private {number}
  789. */
  790. private total_;
  791. blockSize: number;
  792. constructor();
  793. reset(): void;
  794. /**
  795. * Internal compress helper function.
  796. * @param buf Block to compress.
  797. * @param offset Offset of the block in the buffer.
  798. * @private
  799. */
  800. compress_(buf: number[] | Uint8Array | string, offset?: number): void;
  801. update(bytes?: number[] | Uint8Array | string, length?: number): void;
  802. /** @override */
  803. digest(): number[];
  804. }
  805. /**
  806. * Returns JSON representing a javascript object.
  807. * @param {*} data Javascript object to be stringified.
  808. * @return {string} The JSON contents of the object.
  809. */
  810. export declare function stringify(data: unknown): string;
  811. /**
  812. * Calculate length without actually converting; useful for doing cheaper validation.
  813. * @param {string} str
  814. * @return {number}
  815. */
  816. export declare const stringLength: (str: string) => number;
  817. export declare interface StringLike {
  818. toString(): string;
  819. }
  820. /**
  821. * @param {string} str
  822. * @return {Array}
  823. */
  824. export declare const stringToByteArray: (str: string) => number[];
  825. /**
  826. * The Subscribe interface has two forms - passing the inline function
  827. * callbacks, or a object interface with callback properties.
  828. */
  829. export declare interface Subscribe<T> {
  830. (next?: NextFn<T>, error?: ErrorFn, complete?: CompleteFn): Unsubscribe;
  831. (observer: PartialObserver<T>): Unsubscribe;
  832. }
  833. export declare type Unsubscribe = () => void;
  834. /**
  835. * Copied from https://stackoverflow.com/a/2117523
  836. * Generates a new uuid.
  837. * @public
  838. */
  839. export declare const uuidv4: () => string;
  840. /**
  841. * Check to make sure the appropriate number of arguments are provided for a public function.
  842. * Throws an error if it fails.
  843. *
  844. * @param fnName The function name
  845. * @param minCount The minimum number of arguments to allow for the function call
  846. * @param maxCount The maximum number of argument to allow for the function call
  847. * @param argCount The actual number of arguments provided.
  848. */
  849. export declare const validateArgCount: (fnName: string, minCount: number, maxCount: number, argCount: number) => void;
  850. export declare function validateCallback(fnName: string, argumentName: string, callback: Function, optional: boolean): void;
  851. export declare function validateContextObject(fnName: string, argumentName: string, context: unknown, optional: boolean): void;
  852. /**
  853. * This method validates browser/sw context for indexedDB by opening a dummy indexedDB database and reject
  854. * if errors occur during the database open operation.
  855. *
  856. * @throws exception if current browser/sw context can't run idb.open (ex: Safari iframe, Firefox
  857. * private browsing)
  858. */
  859. export declare function validateIndexedDBOpenable(): Promise<boolean>;
  860. /**
  861. * @param fnName
  862. * @param argumentNumber
  863. * @param namespace
  864. * @param optional
  865. */
  866. export declare function validateNamespace(fnName: string, namespace: string, optional: boolean): void;
  867. export { }