UNPKG

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