@firebase/app-check 0.4.2 → 0.5.0-2021102231614

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/app-check-public.d.ts +22 -2
  3. package/dist/app-check.d.ts +32 -2
  4. package/dist/{index.esm.js → esm/index.esm.js} +143 -50
  5. package/dist/esm/index.esm.js.map +1 -0
  6. package/dist/{index.esm2017.js → esm/index.esm2017.js} +131 -43
  7. package/dist/esm/index.esm2017.js.map +1 -0
  8. package/dist/esm/package.json +1 -0
  9. package/dist/esm/src/api.d.ts +87 -0
  10. package/dist/esm/src/api.test.d.ts +17 -0
  11. package/dist/esm/src/client.d.ts +30 -0
  12. package/dist/esm/src/client.test.d.ts +17 -0
  13. package/dist/esm/src/constants.d.ts +36 -0
  14. package/dist/esm/src/debug.d.ts +22 -0
  15. package/dist/esm/src/debug.test.d.ts +17 -0
  16. package/dist/esm/src/errors.d.ts +56 -0
  17. package/dist/esm/src/factory.d.ts +31 -0
  18. package/dist/esm/src/index.d.ts +9 -0
  19. package/dist/esm/src/indexeddb.d.ts +22 -0
  20. package/dist/esm/src/internal-api.d.ts +38 -0
  21. package/dist/esm/src/internal-api.test.d.ts +17 -0
  22. package/dist/esm/src/logger.d.ts +18 -0
  23. package/dist/esm/src/proactive-refresh.d.ts +35 -0
  24. package/dist/esm/src/proactive-refresh.test.d.ts +17 -0
  25. package/dist/esm/src/providers.d.ts +98 -0
  26. package/dist/esm/src/public-types.d.ts +85 -0
  27. package/dist/esm/src/recaptcha.d.ts +41 -0
  28. package/dist/esm/src/recaptcha.test.d.ts +17 -0
  29. package/dist/esm/src/state.d.ts +45 -0
  30. package/dist/esm/src/storage.d.ts +27 -0
  31. package/dist/esm/src/storage.test.d.ts +17 -0
  32. package/dist/esm/src/types.d.ts +59 -0
  33. package/dist/esm/src/util.d.ts +24 -0
  34. package/dist/esm/test/setup.d.ts +17 -0
  35. package/dist/esm/test/util.d.ts +34 -0
  36. package/dist/index.cjs.js +143 -49
  37. package/dist/index.cjs.js.map +1 -1
  38. package/dist/src/api.d.ts +1 -1
  39. package/dist/src/client.d.ts +2 -1
  40. package/dist/src/constants.d.ts +1 -0
  41. package/dist/src/providers.d.ts +29 -0
  42. package/dist/src/public-types.d.ts +3 -3
  43. package/dist/src/recaptcha.d.ts +7 -2
  44. package/dist/src/util.d.ts +1 -1
  45. package/dist/test/util.d.ts +2 -2
  46. package/package.json +18 -11
  47. package/dist/index.esm.js.map +0 -1
  48. package/dist/index.esm2017.js.map +0 -1
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export declare const BASE_ENDPOINT = "https://content-firebaseappcheck.googleapis.com/v1beta";
18
+ export declare const EXCHANGE_RECAPTCHA_TOKEN_METHOD = "exchangeRecaptchaToken";
19
+ export declare const EXCHANGE_RECAPTCHA_ENTERPRISE_TOKEN_METHOD = "exchangeRecaptchaEnterpriseToken";
20
+ export declare const EXCHANGE_DEBUG_TOKEN_METHOD = "exchangeDebugToken";
21
+ export declare const TOKEN_REFRESH_TIME: {
22
+ /**
23
+ * The offset time before token natural expiration to run the refresh.
24
+ * This is currently 5 minutes.
25
+ */
26
+ OFFSET_DURATION: number;
27
+ /**
28
+ * This is the first retrial wait after an error. This is currently
29
+ * 30 seconds.
30
+ */
31
+ RETRIAL_MIN_WAIT: number;
32
+ /**
33
+ * This is the maximum retrial wait, currently 16 minutes.
34
+ */
35
+ RETRIAL_MAX_WAIT: number;
36
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ declare global {
18
+ var FIREBASE_APPCHECK_DEBUG_TOKEN: boolean | string | undefined;
19
+ }
20
+ export declare function isDebugMode(): boolean;
21
+ export declare function getDebugToken(): Promise<string>;
22
+ export declare function initializeDebugMode(): void;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import '../test/setup';
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { ErrorFactory } from '@firebase/util';
18
+ export declare const enum AppCheckError {
19
+ ALREADY_INITIALIZED = "already-initialized",
20
+ USE_BEFORE_ACTIVATION = "use-before-activation",
21
+ FETCH_NETWORK_ERROR = "fetch-network-error",
22
+ FETCH_PARSE_ERROR = "fetch-parse-error",
23
+ FETCH_STATUS_ERROR = "fetch-status-error",
24
+ STORAGE_OPEN = "storage-open",
25
+ STORAGE_GET = "storage-get",
26
+ STORAGE_WRITE = "storage-set",
27
+ RECAPTCHA_ERROR = "recaptcha-error"
28
+ }
29
+ interface ErrorParams {
30
+ [AppCheckError.ALREADY_INITIALIZED]: {
31
+ appName: string;
32
+ };
33
+ [AppCheckError.USE_BEFORE_ACTIVATION]: {
34
+ appName: string;
35
+ };
36
+ [AppCheckError.FETCH_NETWORK_ERROR]: {
37
+ originalErrorMessage: string;
38
+ };
39
+ [AppCheckError.FETCH_PARSE_ERROR]: {
40
+ originalErrorMessage: string;
41
+ };
42
+ [AppCheckError.FETCH_STATUS_ERROR]: {
43
+ httpStatus: number;
44
+ };
45
+ [AppCheckError.STORAGE_OPEN]: {
46
+ originalErrorMessage?: string;
47
+ };
48
+ [AppCheckError.STORAGE_GET]: {
49
+ originalErrorMessage?: string;
50
+ };
51
+ [AppCheckError.STORAGE_WRITE]: {
52
+ originalErrorMessage?: string;
53
+ };
54
+ }
55
+ export declare const ERROR_FACTORY: ErrorFactory<AppCheckError, ErrorParams>;
56
+ export {};
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { AppCheck } from './public-types';
18
+ import { FirebaseApp, _FirebaseService } from '@firebase/app';
19
+ import { FirebaseAppCheckInternal } from './types';
20
+ import { Provider } from '@firebase/component';
21
+ /**
22
+ * AppCheck Service class.
23
+ */
24
+ export declare class AppCheckService implements AppCheck, _FirebaseService {
25
+ app: FirebaseApp;
26
+ platformLoggerProvider: Provider<'platform-logger'>;
27
+ constructor(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>);
28
+ _delete(): Promise<void>;
29
+ }
30
+ export declare function factory(app: FirebaseApp, platformLoggerProvider: Provider<'platform-logger'>): AppCheckService;
31
+ export declare function internalFactory(appCheck: AppCheckService): FirebaseAppCheckInternal;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Firebase App Check
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import { _AppCheckInternalComponentName } from './types';
7
+ export { _AppCheckInternalComponentName };
8
+ export * from './api';
9
+ export * from './public-types';
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseApp } from '@firebase/app';
18
+ import { AppCheckTokenInternal } from './types';
19
+ export declare function readTokenFromIndexedDB(app: FirebaseApp): Promise<AppCheckTokenInternal | undefined>;
20
+ export declare function writeTokenToIndexedDB(app: FirebaseApp, token: AppCheckTokenInternal): Promise<void>;
21
+ export declare function writeDebugTokenToIndexedDB(token: string): Promise<void>;
22
+ export declare function readDebugTokenFromIndexedDB(): Promise<string | undefined>;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseApp } from '@firebase/app';
18
+ import { AppCheckTokenResult, AppCheckTokenInternal, ListenerType } from './types';
19
+ import { AppCheckTokenListener } from './public-types';
20
+ import { AppCheckService } from './factory';
21
+ export declare const defaultTokenErrorData: {
22
+ error: string;
23
+ };
24
+ /**
25
+ * Stringify and base64 encode token error data.
26
+ *
27
+ * @param tokenError Error data, currently hardcoded.
28
+ */
29
+ export declare function formatDummyToken(tokenErrorData: Record<string, string>): string;
30
+ /**
31
+ * This function always resolves.
32
+ * The result will contain an error field if there is any error.
33
+ * In case there is an error, the token field in the result will be populated with a dummy value
34
+ */
35
+ export declare function getToken(appCheck: AppCheckService, forceRefresh?: boolean): Promise<AppCheckTokenResult>;
36
+ export declare function addTokenListener(appCheck: AppCheckService, type: ListenerType, listener: AppCheckTokenListener, onError?: (error: Error) => void): void;
37
+ export declare function removeTokenListener(app: FirebaseApp, listener: AppCheckTokenListener): void;
38
+ export declare function isValid(token: AppCheckTokenInternal): boolean;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import '../test/setup';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { Logger } from '@firebase/logger';
18
+ export declare const logger: Logger;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Port from auth proactiverefresh.js
19
+ *
20
+ */
21
+ export declare class Refresher {
22
+ private readonly operation;
23
+ private readonly retryPolicy;
24
+ private readonly getWaitDuration;
25
+ private readonly lowerBound;
26
+ private readonly upperBound;
27
+ private pending;
28
+ private nextErrorWaitInterval;
29
+ constructor(operation: () => Promise<unknown>, retryPolicy: (error: unknown) => boolean, getWaitDuration: () => number, lowerBound: number, upperBound: number);
30
+ start(): void;
31
+ stop(): void;
32
+ isRunning(): boolean;
33
+ private process;
34
+ private getNextRun;
35
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import '../test/setup';
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseApp } from '@firebase/app';
18
+ import { CustomProviderOptions } from './public-types';
19
+ import { AppCheckProvider, AppCheckTokenInternal } from './types';
20
+ /**
21
+ * App Check provider that can obtain a reCAPTCHA V3 token and exchange it
22
+ * for an App Check token.
23
+ *
24
+ * @public
25
+ */
26
+ export declare class ReCaptchaV3Provider implements AppCheckProvider {
27
+ private _siteKey;
28
+ private _app?;
29
+ private _platformLoggerProvider?;
30
+ /**
31
+ * Create a ReCaptchaV3Provider instance.
32
+ * @param siteKey - ReCAPTCHA V3 siteKey.
33
+ */
34
+ constructor(_siteKey: string);
35
+ /**
36
+ * Returns an App Check token.
37
+ * @internal
38
+ */
39
+ getToken(): Promise<AppCheckTokenInternal>;
40
+ /**
41
+ * @internal
42
+ */
43
+ initialize(app: FirebaseApp): void;
44
+ /**
45
+ * @internal
46
+ */
47
+ isEqual(otherProvider: unknown): boolean;
48
+ }
49
+ /**
50
+ * App Check provider that can obtain a reCAPTCHA Enterprise token and exchange it
51
+ * for an App Check token.
52
+ *
53
+ * @public
54
+ */
55
+ export declare class ReCaptchaEnterpriseProvider implements AppCheckProvider {
56
+ private _siteKey;
57
+ private _app?;
58
+ private _platformLoggerProvider?;
59
+ /**
60
+ * Create a ReCaptchaEnterpriseProvider instance.
61
+ * @param siteKey - reCAPTCHA Enterprise score-based site key.
62
+ */
63
+ constructor(_siteKey: string);
64
+ /**
65
+ * Returns an App Check token.
66
+ * @internal
67
+ */
68
+ getToken(): Promise<AppCheckTokenInternal>;
69
+ /**
70
+ * @internal
71
+ */
72
+ initialize(app: FirebaseApp): void;
73
+ /**
74
+ * @internal
75
+ */
76
+ isEqual(otherProvider: unknown): boolean;
77
+ }
78
+ /**
79
+ * Custom provider class.
80
+ * @public
81
+ */
82
+ export declare class CustomProvider implements AppCheckProvider {
83
+ private _customProviderOptions;
84
+ private _app?;
85
+ constructor(_customProviderOptions: CustomProviderOptions);
86
+ /**
87
+ * @internal
88
+ */
89
+ getToken(): Promise<AppCheckTokenInternal>;
90
+ /**
91
+ * @internal
92
+ */
93
+ initialize(app: FirebaseApp): void;
94
+ /**
95
+ * @internal
96
+ */
97
+ isEqual(otherProvider: unknown): boolean;
98
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseApp } from '@firebase/app';
18
+ import { CustomProvider, ReCaptchaEnterpriseProvider, ReCaptchaV3Provider } from './providers';
19
+ export { Unsubscribe, PartialObserver } from '@firebase/util';
20
+ /**
21
+ * The Firebase App Check service interface.
22
+ *
23
+ * @public
24
+ */
25
+ export interface AppCheck {
26
+ /**
27
+ * The {@link @firebase/app#FirebaseApp} this `AppCheck` instance is associated with.
28
+ */
29
+ app: FirebaseApp;
30
+ }
31
+ /**
32
+ * The token returned from an App Check provider.
33
+ * @public
34
+ */
35
+ export interface AppCheckToken {
36
+ readonly token: string;
37
+ /**
38
+ * The local timestamp after which the token will expire.
39
+ */
40
+ readonly expireTimeMillis: number;
41
+ }
42
+ /**
43
+ * @internal
44
+ */
45
+ export declare type _AppCheckComponentName = 'app-check';
46
+ /**
47
+ * Options for App Check initialization.
48
+ * @public
49
+ */
50
+ export interface AppCheckOptions {
51
+ /**
52
+ * A reCAPTCHA V3 provider, reCAPTCHA Enterprise provider, or custom provider.
53
+ */
54
+ provider: CustomProvider | ReCaptchaV3Provider | ReCaptchaEnterpriseProvider;
55
+ /**
56
+ * If set to true, enables automatic background refresh of App Check token.
57
+ */
58
+ isTokenAutoRefreshEnabled?: boolean;
59
+ }
60
+ /**
61
+ * Options when creating a {@link CustomProvider}.
62
+ * @public
63
+ */
64
+ export interface CustomProviderOptions {
65
+ /**
66
+ * Function to get an App Check token through a custom provider
67
+ * service.
68
+ */
69
+ getToken: () => Promise<AppCheckToken>;
70
+ }
71
+ /**
72
+ * Result returned by `getToken()`.
73
+ * @public
74
+ */
75
+ export interface AppCheckTokenResult {
76
+ /**
77
+ * The token string in JWT format.
78
+ */
79
+ readonly token: string;
80
+ }
81
+ /**
82
+ * A listener that is called whenever the App Check token changes.
83
+ * @public
84
+ */
85
+ export declare type AppCheckTokenListener = (token: AppCheckTokenResult) => void;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseApp } from '@firebase/app';
18
+ export declare const RECAPTCHA_URL = "https://www.google.com/recaptcha/api.js";
19
+ export declare const RECAPTCHA_ENTERPRISE_URL = "https://www.google.com/recaptcha/enterprise.js";
20
+ export declare function initializeV3(app: FirebaseApp, siteKey: string): Promise<GreCAPTCHA>;
21
+ export declare function initializeEnterprise(app: FirebaseApp, siteKey: string): Promise<GreCAPTCHA>;
22
+ export declare function getToken(app: FirebaseApp): Promise<string>;
23
+ declare global {
24
+ interface Window {
25
+ grecaptcha: GreCAPTCHATopLevel | undefined;
26
+ }
27
+ }
28
+ export interface GreCAPTCHATopLevel extends GreCAPTCHA {
29
+ enterprise: GreCAPTCHA;
30
+ }
31
+ export interface GreCAPTCHA {
32
+ ready: (callback: () => void) => void;
33
+ execute: (siteKey: string, options: {
34
+ action: string;
35
+ }) => Promise<string>;
36
+ render: (container: string | HTMLElement, parameters: GreCAPTCHARenderOption) => string;
37
+ }
38
+ export interface GreCAPTCHARenderOption {
39
+ sitekey: string;
40
+ size: 'invisible';
41
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import '../test/setup';
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseApp } from '@firebase/app';
18
+ import { AppCheckProvider, AppCheckTokenInternal, AppCheckTokenObserver } from './types';
19
+ import { Refresher } from './proactive-refresh';
20
+ import { Deferred } from '@firebase/util';
21
+ import { GreCAPTCHA } from './recaptcha';
22
+ export interface AppCheckState {
23
+ activated: boolean;
24
+ tokenObservers: AppCheckTokenObserver[];
25
+ provider?: AppCheckProvider;
26
+ token?: AppCheckTokenInternal;
27
+ cachedTokenPromise?: Promise<AppCheckTokenInternal | undefined>;
28
+ tokenRefresher?: Refresher;
29
+ reCAPTCHAState?: ReCAPTCHAState;
30
+ isTokenAutoRefreshEnabled?: boolean;
31
+ }
32
+ export interface ReCAPTCHAState {
33
+ initialized: Deferred<GreCAPTCHA>;
34
+ widgetId?: string;
35
+ }
36
+ export interface DebugState {
37
+ initialized: boolean;
38
+ enabled: boolean;
39
+ token?: Deferred<string>;
40
+ }
41
+ export declare const DEFAULT_STATE: AppCheckState;
42
+ export declare function getState(app: FirebaseApp): AppCheckState;
43
+ export declare function setState(app: FirebaseApp, state: AppCheckState): void;
44
+ export declare function clearState(): void;
45
+ export declare function getDebugState(): DebugState;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseApp } from '@firebase/app';
18
+ import { AppCheckTokenInternal } from './types';
19
+ /**
20
+ * Always resolves. In case of an error reading from indexeddb, resolve with undefined
21
+ */
22
+ export declare function readTokenFromStorage(app: FirebaseApp): Promise<AppCheckTokenInternal | undefined>;
23
+ /**
24
+ * Always resolves. In case of an error writing to indexeddb, print a warning and resolve the promise
25
+ */
26
+ export declare function writeTokenToStorage(app: FirebaseApp, token: AppCheckTokenInternal): Promise<void>;
27
+ export declare function readOrCreateDebugTokenFromStorage(): Promise<string>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import '../test/setup';