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.cjs.js 5.6KB

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