@firebase/app-check 0.5.8 → 0.5.9-canary.ebc17e27f

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.
@@ -1,266 +1,266 @@
1
- /**
2
- * Firebase App Check
3
- *
4
- * @packageDocumentation
5
- */
6
-
7
- import { FirebaseApp } from '@firebase/app';
8
- import { PartialObserver } from '@firebase/util';
9
- import { Unsubscribe } from '@firebase/util';
10
-
11
- /**
12
- * The Firebase App Check service interface.
13
- *
14
- * @public
15
- */
16
- export declare interface AppCheck {
17
- /**
18
- * The {@link @firebase/app#FirebaseApp} this `AppCheck` instance is associated with.
19
- */
20
- app: FirebaseApp;
21
- }
22
-
23
- /**
24
- * @internal
25
- */
26
- export declare type _AppCheckComponentName = 'app-check';
27
-
28
- /**
29
- * @internal
30
- */
31
- export declare type _AppCheckInternalComponentName = 'app-check-internal';
32
-
33
- /**
34
- * Options for App Check initialization.
35
- * @public
36
- */
37
- export declare interface AppCheckOptions {
38
- /**
39
- * A reCAPTCHA V3 provider, reCAPTCHA Enterprise provider, or custom provider.
40
- */
41
- provider: CustomProvider | ReCaptchaV3Provider | ReCaptchaEnterpriseProvider;
42
- /**
43
- * If set to true, enables automatic background refresh of App Check token.
44
- */
45
- isTokenAutoRefreshEnabled?: boolean;
46
- }
47
-
48
- declare interface AppCheckProvider {
49
- /**
50
- * Returns an App Check token.
51
- * @internal
52
- */
53
- getToken: () => Promise<AppCheckTokenInternal>;
54
- /**
55
- * @internal
56
- */
57
- initialize(app: FirebaseApp): void;
58
- }
59
-
60
- /**
61
- * The token returned from an App Check provider.
62
- * @public
63
- */
64
- export declare interface AppCheckToken {
65
- readonly token: string;
66
- /**
67
- * The local timestamp after which the token will expire.
68
- */
69
- readonly expireTimeMillis: number;
70
- }
71
-
72
- declare interface AppCheckTokenInternal extends AppCheckToken {
73
- issuedAtTimeMillis: number;
74
- }
75
-
76
- /**
77
- * A listener that is called whenever the App Check token changes.
78
- * @public
79
- */
80
- export declare type AppCheckTokenListener = (token: AppCheckTokenResult) => void;
81
-
82
- /**
83
- * Result returned by `getToken()`.
84
- * @public
85
- */
86
- export declare interface AppCheckTokenResult {
87
- /**
88
- * The token string in JWT format.
89
- */
90
- readonly token: string;
91
- }
92
-
93
- /**
94
- * Custom provider class.
95
- * @public
96
- */
97
- export declare class CustomProvider implements AppCheckProvider {
98
- private _customProviderOptions;
99
- private _app?;
100
- constructor(_customProviderOptions: CustomProviderOptions);
101
- /**
102
- * @internal
103
- */
104
- getToken(): Promise<AppCheckTokenInternal>;
105
- /**
106
- * @internal
107
- */
108
- initialize(app: FirebaseApp): void;
109
- /**
110
- * @internal
111
- */
112
- isEqual(otherProvider: unknown): boolean;
113
- }
114
-
115
- /**
116
- * Options when creating a {@link CustomProvider}.
117
- * @public
118
- */
119
- export declare interface CustomProviderOptions {
120
- /**
121
- * Function to get an App Check token through a custom provider
122
- * service.
123
- */
124
- getToken: () => Promise<AppCheckToken>;
125
- }
126
-
127
- /**
128
- * Get the current App Check token. Attaches to the most recent
129
- * in-flight request if one is present. Returns null if no token
130
- * is present and no token requests are in-flight.
131
- *
132
- * @param appCheckInstance - The App Check service instance.
133
- * @param forceRefresh - If true, will always try to fetch a fresh token.
134
- * If false, will use a cached token if found in storage.
135
- * @public
136
- */
137
- export declare function getToken(appCheckInstance: AppCheck, forceRefresh?: boolean): Promise<AppCheckTokenResult>;
138
-
139
- /**
140
- * Activate App Check for the given app. Can be called only once per app.
141
- * @param app - the {@link @firebase/app#FirebaseApp} to activate App Check for
142
- * @param options - App Check initialization options
143
- * @public
144
- */
145
- export declare function initializeAppCheck(app: FirebaseApp | undefined, options: AppCheckOptions): AppCheck;
146
-
147
- /**
148
- * Registers a listener to changes in the token state. There can be more
149
- * than one listener registered at the same time for one or more
150
- * App Check instances. The listeners call back on the UI thread whenever
151
- * the current token associated with this App Check instance changes.
152
- *
153
- * @param appCheckInstance - The App Check service instance.
154
- * @param observer - An object with `next`, `error`, and `complete`
155
- * properties. `next` is called with an
156
- * {@link AppCheckTokenResult}
157
- * whenever the token changes. `error` is optional and is called if an
158
- * error is thrown by the listener (the `next` function). `complete`
159
- * is unused, as the token stream is unending.
160
- *
161
- * @returns A function that unsubscribes this listener.
162
- * @public
163
- */
164
- export declare function onTokenChanged(appCheckInstance: AppCheck, observer: PartialObserver<AppCheckTokenResult>): Unsubscribe;
165
-
166
- /**
167
- * Registers a listener to changes in the token state. There can be more
168
- * than one listener registered at the same time for one or more
169
- * App Check instances. The listeners call back on the UI thread whenever
170
- * the current token associated with this App Check instance changes.
171
- *
172
- * @param appCheckInstance - The App Check service instance.
173
- * @param onNext - When the token changes, this function is called with aa
174
- * {@link AppCheckTokenResult}.
175
- * @param onError - Optional. Called if there is an error thrown by the
176
- * listener (the `onNext` function).
177
- * @param onCompletion - Currently unused, as the token stream is unending.
178
- * @returns A function that unsubscribes this listener.
179
- * @public
180
- */
181
- export declare function onTokenChanged(appCheckInstance: AppCheck, onNext: (tokenResult: AppCheckTokenResult) => void, onError?: (error: Error) => void, onCompletion?: () => void): Unsubscribe;
182
- export { PartialObserver }
183
-
184
- /**
185
- * App Check provider that can obtain a reCAPTCHA Enterprise token and exchange it
186
- * for an App Check token.
187
- *
188
- * @public
189
- */
190
- export declare class ReCaptchaEnterpriseProvider implements AppCheckProvider {
191
- private _siteKey;
192
- private _app?;
193
- private _heartbeatServiceProvider?;
194
- /**
195
- * Throttle requests on certain error codes to prevent too many retries
196
- * in a short time.
197
- */
198
- private _throttleData;
199
- /**
200
- * Create a ReCaptchaEnterpriseProvider instance.
201
- * @param siteKey - reCAPTCHA Enterprise score-based site key.
202
- */
203
- constructor(_siteKey: string);
204
- /**
205
- * Returns an App Check token.
206
- * @internal
207
- */
208
- getToken(): Promise<AppCheckTokenInternal>;
209
- /**
210
- * @internal
211
- */
212
- initialize(app: FirebaseApp): void;
213
- /**
214
- * @internal
215
- */
216
- isEqual(otherProvider: unknown): boolean;
217
- }
218
-
219
- /**
220
- * App Check provider that can obtain a reCAPTCHA V3 token and exchange it
221
- * for an App Check token.
222
- *
223
- * @public
224
- */
225
- export declare class ReCaptchaV3Provider implements AppCheckProvider {
226
- private _siteKey;
227
- private _app?;
228
- private _heartbeatServiceProvider?;
229
- /**
230
- * Throttle requests on certain error codes to prevent too many retries
231
- * in a short time.
232
- */
233
- private _throttleData;
234
- /**
235
- * Create a ReCaptchaV3Provider instance.
236
- * @param siteKey - ReCAPTCHA V3 siteKey.
237
- */
238
- constructor(_siteKey: string);
239
- /**
240
- * Returns an App Check token.
241
- * @internal
242
- */
243
- getToken(): Promise<AppCheckTokenInternal>;
244
- /**
245
- * @internal
246
- */
247
- initialize(app: FirebaseApp): void;
248
- /**
249
- * @internal
250
- */
251
- isEqual(otherProvider: unknown): boolean;
252
- }
253
-
254
- /**
255
- * Set whether App Check will automatically refresh tokens as needed.
256
- *
257
- * @param appCheckInstance - The App Check service instance.
258
- * @param isTokenAutoRefreshEnabled - If true, the SDK automatically
259
- * refreshes App Check tokens as needed. This overrides any value set
260
- * during `initializeAppCheck()`.
261
- * @public
262
- */
263
- export declare function setTokenAutoRefreshEnabled(appCheckInstance: AppCheck, isTokenAutoRefreshEnabled: boolean): void;
264
- export { Unsubscribe }
265
-
266
- export { }
1
+ /**
2
+ * Firebase App Check
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+
7
+ import { FirebaseApp } from '@firebase/app';
8
+ import { PartialObserver } from '@firebase/util';
9
+ import { Unsubscribe } from '@firebase/util';
10
+
11
+ /**
12
+ * The Firebase App Check service interface.
13
+ *
14
+ * @public
15
+ */
16
+ export declare interface AppCheck {
17
+ /**
18
+ * The {@link @firebase/app#FirebaseApp} this `AppCheck` instance is associated with.
19
+ */
20
+ app: FirebaseApp;
21
+ }
22
+
23
+ /**
24
+ * @internal
25
+ */
26
+ export declare type _AppCheckComponentName = 'app-check';
27
+
28
+ /**
29
+ * @internal
30
+ */
31
+ export declare type _AppCheckInternalComponentName = 'app-check-internal';
32
+
33
+ /**
34
+ * Options for App Check initialization.
35
+ * @public
36
+ */
37
+ export declare interface AppCheckOptions {
38
+ /**
39
+ * A reCAPTCHA V3 provider, reCAPTCHA Enterprise provider, or custom provider.
40
+ */
41
+ provider: CustomProvider | ReCaptchaV3Provider | ReCaptchaEnterpriseProvider;
42
+ /**
43
+ * If set to true, enables automatic background refresh of App Check token.
44
+ */
45
+ isTokenAutoRefreshEnabled?: boolean;
46
+ }
47
+
48
+ declare interface AppCheckProvider {
49
+ /**
50
+ * Returns an App Check token.
51
+ * @internal
52
+ */
53
+ getToken: () => Promise<AppCheckTokenInternal>;
54
+ /**
55
+ * @internal
56
+ */
57
+ initialize(app: FirebaseApp): void;
58
+ }
59
+
60
+ /**
61
+ * The token returned from an App Check provider.
62
+ * @public
63
+ */
64
+ export declare interface AppCheckToken {
65
+ readonly token: string;
66
+ /**
67
+ * The local timestamp after which the token will expire.
68
+ */
69
+ readonly expireTimeMillis: number;
70
+ }
71
+
72
+ declare interface AppCheckTokenInternal extends AppCheckToken {
73
+ issuedAtTimeMillis: number;
74
+ }
75
+
76
+ /**
77
+ * A listener that is called whenever the App Check token changes.
78
+ * @public
79
+ */
80
+ export declare type AppCheckTokenListener = (token: AppCheckTokenResult) => void;
81
+
82
+ /**
83
+ * Result returned by `getToken()`.
84
+ * @public
85
+ */
86
+ export declare interface AppCheckTokenResult {
87
+ /**
88
+ * The token string in JWT format.
89
+ */
90
+ readonly token: string;
91
+ }
92
+
93
+ /**
94
+ * Custom provider class.
95
+ * @public
96
+ */
97
+ export declare class CustomProvider implements AppCheckProvider {
98
+ private _customProviderOptions;
99
+ private _app?;
100
+ constructor(_customProviderOptions: CustomProviderOptions);
101
+ /**
102
+ * @internal
103
+ */
104
+ getToken(): Promise<AppCheckTokenInternal>;
105
+ /**
106
+ * @internal
107
+ */
108
+ initialize(app: FirebaseApp): void;
109
+ /**
110
+ * @internal
111
+ */
112
+ isEqual(otherProvider: unknown): boolean;
113
+ }
114
+
115
+ /**
116
+ * Options when creating a {@link CustomProvider}.
117
+ * @public
118
+ */
119
+ export declare interface CustomProviderOptions {
120
+ /**
121
+ * Function to get an App Check token through a custom provider
122
+ * service.
123
+ */
124
+ getToken: () => Promise<AppCheckToken>;
125
+ }
126
+
127
+ /**
128
+ * Get the current App Check token. Attaches to the most recent
129
+ * in-flight request if one is present. Returns null if no token
130
+ * is present and no token requests are in-flight.
131
+ *
132
+ * @param appCheckInstance - The App Check service instance.
133
+ * @param forceRefresh - If true, will always try to fetch a fresh token.
134
+ * If false, will use a cached token if found in storage.
135
+ * @public
136
+ */
137
+ export declare function getToken(appCheckInstance: AppCheck, forceRefresh?: boolean): Promise<AppCheckTokenResult>;
138
+
139
+ /**
140
+ * Activate App Check for the given app. Can be called only once per app.
141
+ * @param app - the {@link @firebase/app#FirebaseApp} to activate App Check for
142
+ * @param options - App Check initialization options
143
+ * @public
144
+ */
145
+ export declare function initializeAppCheck(app: FirebaseApp | undefined, options: AppCheckOptions): AppCheck;
146
+
147
+ /**
148
+ * Registers a listener to changes in the token state. There can be more
149
+ * than one listener registered at the same time for one or more
150
+ * App Check instances. The listeners call back on the UI thread whenever
151
+ * the current token associated with this App Check instance changes.
152
+ *
153
+ * @param appCheckInstance - The App Check service instance.
154
+ * @param observer - An object with `next`, `error`, and `complete`
155
+ * properties. `next` is called with an
156
+ * {@link AppCheckTokenResult}
157
+ * whenever the token changes. `error` is optional and is called if an
158
+ * error is thrown by the listener (the `next` function). `complete`
159
+ * is unused, as the token stream is unending.
160
+ *
161
+ * @returns A function that unsubscribes this listener.
162
+ * @public
163
+ */
164
+ export declare function onTokenChanged(appCheckInstance: AppCheck, observer: PartialObserver<AppCheckTokenResult>): Unsubscribe;
165
+
166
+ /**
167
+ * Registers a listener to changes in the token state. There can be more
168
+ * than one listener registered at the same time for one or more
169
+ * App Check instances. The listeners call back on the UI thread whenever
170
+ * the current token associated with this App Check instance changes.
171
+ *
172
+ * @param appCheckInstance - The App Check service instance.
173
+ * @param onNext - When the token changes, this function is called with aa
174
+ * {@link AppCheckTokenResult}.
175
+ * @param onError - Optional. Called if there is an error thrown by the
176
+ * listener (the `onNext` function).
177
+ * @param onCompletion - Currently unused, as the token stream is unending.
178
+ * @returns A function that unsubscribes this listener.
179
+ * @public
180
+ */
181
+ export declare function onTokenChanged(appCheckInstance: AppCheck, onNext: (tokenResult: AppCheckTokenResult) => void, onError?: (error: Error) => void, onCompletion?: () => void): Unsubscribe;
182
+ export { PartialObserver }
183
+
184
+ /**
185
+ * App Check provider that can obtain a reCAPTCHA Enterprise token and exchange it
186
+ * for an App Check token.
187
+ *
188
+ * @public
189
+ */
190
+ export declare class ReCaptchaEnterpriseProvider implements AppCheckProvider {
191
+ private _siteKey;
192
+ private _app?;
193
+ private _heartbeatServiceProvider?;
194
+ /**
195
+ * Throttle requests on certain error codes to prevent too many retries
196
+ * in a short time.
197
+ */
198
+ private _throttleData;
199
+ /**
200
+ * Create a ReCaptchaEnterpriseProvider instance.
201
+ * @param siteKey - reCAPTCHA Enterprise score-based site key.
202
+ */
203
+ constructor(_siteKey: string);
204
+ /**
205
+ * Returns an App Check token.
206
+ * @internal
207
+ */
208
+ getToken(): Promise<AppCheckTokenInternal>;
209
+ /**
210
+ * @internal
211
+ */
212
+ initialize(app: FirebaseApp): void;
213
+ /**
214
+ * @internal
215
+ */
216
+ isEqual(otherProvider: unknown): boolean;
217
+ }
218
+
219
+ /**
220
+ * App Check provider that can obtain a reCAPTCHA V3 token and exchange it
221
+ * for an App Check token.
222
+ *
223
+ * @public
224
+ */
225
+ export declare class ReCaptchaV3Provider implements AppCheckProvider {
226
+ private _siteKey;
227
+ private _app?;
228
+ private _heartbeatServiceProvider?;
229
+ /**
230
+ * Throttle requests on certain error codes to prevent too many retries
231
+ * in a short time.
232
+ */
233
+ private _throttleData;
234
+ /**
235
+ * Create a ReCaptchaV3Provider instance.
236
+ * @param siteKey - ReCAPTCHA V3 siteKey.
237
+ */
238
+ constructor(_siteKey: string);
239
+ /**
240
+ * Returns an App Check token.
241
+ * @internal
242
+ */
243
+ getToken(): Promise<AppCheckTokenInternal>;
244
+ /**
245
+ * @internal
246
+ */
247
+ initialize(app: FirebaseApp): void;
248
+ /**
249
+ * @internal
250
+ */
251
+ isEqual(otherProvider: unknown): boolean;
252
+ }
253
+
254
+ /**
255
+ * Set whether App Check will automatically refresh tokens as needed.
256
+ *
257
+ * @param appCheckInstance - The App Check service instance.
258
+ * @param isTokenAutoRefreshEnabled - If true, the SDK automatically
259
+ * refreshes App Check tokens as needed. This overrides any value set
260
+ * during `initializeAppCheck()`.
261
+ * @public
262
+ */
263
+ export declare function setTokenAutoRefreshEnabled(appCheckInstance: AppCheck, isTokenAutoRefreshEnabled: boolean): void;
264
+ export { Unsubscribe }
265
+
266
+ export { }
@@ -326,11 +326,12 @@ function pad(value) {
326
326
  * limitations under the License.
327
327
  */
328
328
  function exchangeToken(_a, heartbeatServiceProvider) {
329
+ var _b, _c;
329
330
  var url = _a.url, body = _a.body;
330
331
  return __awaiter(this, void 0, void 0, function () {
331
332
  var headers, heartbeatService, heartbeatsHeader, options, response, originalError_1, responseBody, originalError_2, match, timeToLiveAsNumber, now;
332
- return __generator(this, function (_b) {
333
- switch (_b.label) {
333
+ return __generator(this, function (_d) {
334
+ switch (_d.label) {
334
335
  case 0:
335
336
  headers = {
336
337
  'Content-Type': 'application/json'
@@ -341,28 +342,28 @@ function exchangeToken(_a, heartbeatServiceProvider) {
341
342
  if (!heartbeatService) return [3 /*break*/, 2];
342
343
  return [4 /*yield*/, heartbeatService.getHeartbeatsHeader()];
343
344
  case 1:
344
- heartbeatsHeader = _b.sent();
345
+ heartbeatsHeader = _d.sent();
345
346
  if (heartbeatsHeader) {
346
347
  headers['X-Firebase-Client'] = heartbeatsHeader;
347
348
  }
348
- _b.label = 2;
349
+ _d.label = 2;
349
350
  case 2:
350
351
  options = {
351
352
  method: 'POST',
352
353
  body: JSON.stringify(body),
353
354
  headers: headers
354
355
  };
355
- _b.label = 3;
356
+ _d.label = 3;
356
357
  case 3:
357
- _b.trys.push([3, 5, , 6]);
358
+ _d.trys.push([3, 5, , 6]);
358
359
  return [4 /*yield*/, fetch(url, options)];
359
360
  case 4:
360
- response = _b.sent();
361
+ response = _d.sent();
361
362
  return [3 /*break*/, 6];
362
363
  case 5:
363
- originalError_1 = _b.sent();
364
+ originalError_1 = _d.sent();
364
365
  throw ERROR_FACTORY.create("fetch-network-error" /* FETCH_NETWORK_ERROR */, {
365
- originalErrorMessage: originalError_1.message
366
+ originalErrorMessage: (_b = originalError_1) === null || _b === void 0 ? void 0 : _b.message
366
367
  });
367
368
  case 6:
368
369
  if (response.status !== 200) {
@@ -370,18 +371,18 @@ function exchangeToken(_a, heartbeatServiceProvider) {
370
371
  httpStatus: response.status
371
372
  });
372
373
  }
373
- _b.label = 7;
374
+ _d.label = 7;
374
375
  case 7:
375
- _b.trys.push([7, 9, , 10]);
376
+ _d.trys.push([7, 9, , 10]);
376
377
  return [4 /*yield*/, response.json()];
377
378
  case 8:
378
379
  // JSON parsing throws SyntaxError if the response body isn't a JSON string.
379
- responseBody = _b.sent();
380
+ responseBody = _d.sent();
380
381
  return [3 /*break*/, 10];
381
382
  case 9:
382
- originalError_2 = _b.sent();
383
+ originalError_2 = _d.sent();
383
384
  throw ERROR_FACTORY.create("fetch-parse-error" /* FETCH_PARSE_ERROR */, {
384
- originalErrorMessage: originalError_2.message
385
+ originalErrorMessage: (_c = originalError_2) === null || _c === void 0 ? void 0 : _c.message
385
386
  });
386
387
  case 10:
387
388
  match = responseBody.ttl.match(/^([\d.]+)(s)$/);
@@ -457,6 +458,7 @@ function getDBPromise() {
457
458
  return dbPromise;
458
459
  }
459
460
  dbPromise = new Promise(function (resolve, reject) {
461
+ var _a;
460
462
  try {
461
463
  var request = indexedDB.open(DB_NAME, DB_VERSION);
462
464
  request.onsuccess = function (event) {
@@ -485,7 +487,7 @@ function getDBPromise() {
485
487
  }
486
488
  catch (e) {
487
489
  reject(ERROR_FACTORY.create("storage-open" /* STORAGE_OPEN */, {
488
- originalErrorMessage: e.message
490
+ originalErrorMessage: (_a = e) === null || _a === void 0 ? void 0 : _a.message
489
491
  }));
490
492
  }
491
493
  });
@@ -1070,7 +1072,7 @@ function internalFactory(appCheck) {
1070
1072
  }
1071
1073
 
1072
1074
  var name = "@firebase/app-check";
1073
- var version = "0.5.8";
1075
+ var version = "0.5.9-canary.ebc17e27f";
1074
1076
 
1075
1077
  /**
1076
1078
  * @license