UNPKG

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