No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.esm.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import firebase from '@firebase/app-compat';
  2. import { Component } from '@firebase/component';
  3. import { ReCaptchaV3Provider, ReCaptchaEnterpriseProvider, CustomProvider, initializeAppCheck, setTokenAutoRefreshEnabled, getToken, onTokenChanged } from '@firebase/app-check';
  4. import { ErrorFactory } from '@firebase/util';
  5. var name = "@firebase/app-check-compat";
  6. var version = "0.3.1";
  7. /**
  8. * @license
  9. * Copyright 2021 Google LLC
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. var _a;
  24. var ERRORS = (_a = {},
  25. _a["use-before-activation" /* AppCheckError.USE_BEFORE_ACTIVATION */] = 'App Check is being used before activate() is called for FirebaseApp {$appName}. ' +
  26. 'Call activate() before instantiating other Firebase services.',
  27. _a);
  28. var ERROR_FACTORY = new ErrorFactory('appCheck', 'AppCheck', ERRORS);
  29. /**
  30. * @license
  31. * Copyright 2021 Google LLC
  32. *
  33. * Licensed under the Apache License, Version 2.0 (the "License");
  34. * you may not use this file except in compliance with the License.
  35. * You may obtain a copy of the License at
  36. *
  37. * http://www.apache.org/licenses/LICENSE-2.0
  38. *
  39. * Unless required by applicable law or agreed to in writing, software
  40. * distributed under the License is distributed on an "AS IS" BASIS,
  41. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  42. * See the License for the specific language governing permissions and
  43. * limitations under the License.
  44. */
  45. var AppCheckService = /** @class */ (function () {
  46. function AppCheckService(app) {
  47. this.app = app;
  48. }
  49. AppCheckService.prototype.activate = function (siteKeyOrProvider, isTokenAutoRefreshEnabled) {
  50. var provider;
  51. if (typeof siteKeyOrProvider === 'string') {
  52. provider = new ReCaptchaV3Provider(siteKeyOrProvider);
  53. }
  54. else if (siteKeyOrProvider instanceof ReCaptchaEnterpriseProvider ||
  55. siteKeyOrProvider instanceof ReCaptchaV3Provider ||
  56. siteKeyOrProvider instanceof CustomProvider) {
  57. provider = siteKeyOrProvider;
  58. }
  59. else {
  60. provider = new CustomProvider({ getToken: siteKeyOrProvider.getToken });
  61. }
  62. this._delegate = initializeAppCheck(this.app, {
  63. provider: provider,
  64. isTokenAutoRefreshEnabled: isTokenAutoRefreshEnabled
  65. });
  66. };
  67. AppCheckService.prototype.setTokenAutoRefreshEnabled = function (isTokenAutoRefreshEnabled) {
  68. if (!this._delegate) {
  69. throw ERROR_FACTORY.create("use-before-activation" /* AppCheckError.USE_BEFORE_ACTIVATION */, {
  70. appName: this.app.name
  71. });
  72. }
  73. setTokenAutoRefreshEnabled(this._delegate, isTokenAutoRefreshEnabled);
  74. };
  75. AppCheckService.prototype.getToken = function (forceRefresh) {
  76. if (!this._delegate) {
  77. throw ERROR_FACTORY.create("use-before-activation" /* AppCheckError.USE_BEFORE_ACTIVATION */, {
  78. appName: this.app.name
  79. });
  80. }
  81. return getToken(this._delegate, forceRefresh);
  82. };
  83. AppCheckService.prototype.onTokenChanged = function (onNextOrObserver, onError, onCompletion) {
  84. if (!this._delegate) {
  85. throw ERROR_FACTORY.create("use-before-activation" /* AppCheckError.USE_BEFORE_ACTIVATION */, {
  86. appName: this.app.name
  87. });
  88. }
  89. return onTokenChanged(this._delegate,
  90. /**
  91. * Exp onTokenChanged() will handle both overloads but we need
  92. * to specify one to not confuse Typescript.
  93. */
  94. onNextOrObserver, onError, onCompletion);
  95. };
  96. return AppCheckService;
  97. }());
  98. /**
  99. * @license
  100. * Copyright 2021 Google LLC
  101. *
  102. * Licensed under the Apache License, Version 2.0 (the "License");
  103. * you may not use this file except in compliance with the License.
  104. * You may obtain a copy of the License at
  105. *
  106. * http://www.apache.org/licenses/LICENSE-2.0
  107. *
  108. * Unless required by applicable law or agreed to in writing, software
  109. * distributed under the License is distributed on an "AS IS" BASIS,
  110. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  111. * See the License for the specific language governing permissions and
  112. * limitations under the License.
  113. */
  114. var factory = function (container) {
  115. // Dependencies
  116. var app = container.getProvider('app-compat').getImmediate();
  117. return new AppCheckService(app);
  118. };
  119. function registerAppCheck() {
  120. firebase.INTERNAL.registerComponent(new Component('appCheck-compat', factory, "PUBLIC" /* ComponentType.PUBLIC */).setServiceProps({
  121. ReCaptchaEnterpriseProvider: ReCaptchaEnterpriseProvider,
  122. ReCaptchaV3Provider: ReCaptchaV3Provider,
  123. CustomProvider: CustomProvider
  124. }));
  125. }
  126. registerAppCheck();
  127. firebase.registerVersion(name, version);
  128. export { registerAppCheck };
  129. //# sourceMappingURL=index.esm.js.map