Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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