@backstage/plugin-app 0.0.0-nightly-20240828022712
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.
- package/CHANGELOG.md +31 -0
- package/README.md +9 -0
- package/dist/defaultApis.esm.js +334 -0
- package/dist/defaultApis.esm.js.map +1 -0
- package/dist/extensions/App.esm.js +39 -0
- package/dist/extensions/App.esm.js.map +1 -0
- package/dist/extensions/AppLanguageApi.esm.js +16 -0
- package/dist/extensions/AppLanguageApi.esm.js.map +1 -0
- package/dist/extensions/AppLayout.esm.js +26 -0
- package/dist/extensions/AppLayout.esm.js.map +1 -0
- package/dist/extensions/AppNav.esm.js +66 -0
- package/dist/extensions/AppNav.esm.js.map +1 -0
- package/dist/extensions/AppRoot.esm.js +153 -0
- package/dist/extensions/AppRoot.esm.js.map +1 -0
- package/dist/extensions/AppRoutes.esm.js +39 -0
- package/dist/extensions/AppRoutes.esm.js.map +1 -0
- package/dist/extensions/AppThemeApi.esm.js +56 -0
- package/dist/extensions/AppThemeApi.esm.js.map +1 -0
- package/dist/extensions/ComponentsApi.esm.js +27 -0
- package/dist/extensions/ComponentsApi.esm.js.map +1 -0
- package/dist/extensions/FeatureFlagsApi.esm.js +17 -0
- package/dist/extensions/FeatureFlagsApi.esm.js.map +1 -0
- package/dist/extensions/IconsApi.esm.js +33 -0
- package/dist/extensions/IconsApi.esm.js.map +1 -0
- package/dist/extensions/TranslationsApi.esm.js +30 -0
- package/dist/extensions/TranslationsApi.esm.js.map +1 -0
- package/dist/extensions/components.esm.js +52 -0
- package/dist/extensions/components.esm.js.map +1 -0
- package/dist/extensions/elements.esm.js +32 -0
- package/dist/extensions/elements.esm.js.map +1 -0
- package/dist/index.d.ts +430 -0
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/packages/app/src/components/Root/LogoFull.esm.js +33 -0
- package/dist/packages/app/src/components/Root/LogoFull.esm.js.map +1 -0
- package/dist/packages/app/src/components/Root/LogoIcon.esm.js +33 -0
- package/dist/packages/app/src/components/Root/LogoIcon.esm.js.map +1 -0
- package/dist/packages/app-defaults/src/defaults/apis.esm.js +219 -0
- package/dist/packages/app-defaults/src/defaults/apis.esm.js.map +1 -0
- package/dist/packages/app-defaults/src/defaults/components.esm.js +46 -0
- package/dist/packages/app-defaults/src/defaults/components.esm.js.map +1 -0
- package/dist/packages/app-defaults/src/defaults/icons.esm.js +51 -0
- package/dist/packages/app-defaults/src/defaults/icons.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/AlertApi/AlertApiForwarder.esm.js +14 -0
- package/dist/packages/core-app-api/src/apis/implementations/AlertApi/AlertApiForwarder.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/AnalyticsApi/NoOpAnalyticsApi.esm.js +7 -0
- package/dist/packages/core-app-api/src/apis/implementations/AnalyticsApi/NoOpAnalyticsApi.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/AppLanguageApi/AppLanguageSelector.esm.js +89 -0
- package/dist/packages/core-app-api/src/apis/implementations/AppLanguageApi/AppLanguageSelector.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.esm.js +48 -0
- package/dist/packages/core-app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/DiscoveryApi/UrlPatternDiscovery.esm.js +39 -0
- package/dist/packages/core-app-api/src/apis/implementations/DiscoveryApi/UrlPatternDiscovery.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/ErrorApi/ErrorAlerter.esm.js +18 -0
- package/dist/packages/core-app-api/src/apis/implementations/ErrorApi/ErrorAlerter.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.esm.js +14 -0
- package/dist/packages/core-app-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/ErrorApi/UnhandledErrorForwarder.esm.js +16 -0
- package/dist/packages/core-app-api/src/apis/implementations/ErrorApi/UnhandledErrorForwarder.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.esm.js +76 -0
- package/dist/packages/core-app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/FetchApi/FetchMiddlewares.esm.js +45 -0
- package/dist/packages/core-app-api/src/apis/implementations/FetchApi/FetchMiddlewares.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/FetchApi/IdentityAuthInjectorFetchMiddleware.esm.js +49 -0
- package/dist/packages/core-app-api/src/apis/implementations/FetchApi/IdentityAuthInjectorFetchMiddleware.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/FetchApi/PluginProtocolResolverFetchMiddleware.esm.js +40 -0
- package/dist/packages/core-app-api/src/apis/implementations/FetchApi/PluginProtocolResolverFetchMiddleware.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/FetchApi/createFetchApi.esm.js +13 -0
- package/dist/packages/core-app-api/src/apis/implementations/FetchApi/createFetchApi.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.esm.js +71 -0
- package/dist/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.esm.js +54 -0
- package/dist/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/StorageApi/WebStorage.esm.js +96 -0
- package/dist/packages/core-app-api/src/apis/implementations/StorageApi/WebStorage.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.esm.js +234 -0
- package/dist/packages/core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/atlassian/AtlassianAuth.esm.js +28 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/atlassian/AtlassianAuth.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/bitbucket/BitbucketAuth.esm.js +30 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/bitbucket/BitbucketAuth.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/bitbucketServer/BitbucketServerAuth.esm.js +30 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/bitbucketServer/BitbucketServerAuth.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/github/GithubAuth.esm.js +30 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/github/GithubAuth.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/gitlab/GitlabAuth.esm.js +30 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/gitlab/GitlabAuth.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/google/GoogleAuth.esm.js +49 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/google/GoogleAuth.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/microsoft/MicrosoftAuth.esm.js +130 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/microsoft/MicrosoftAuth.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.esm.js +127 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/okta/OktaAuth.esm.js +51 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/okta/OktaAuth.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/onelogin/OneLoginAuth.esm.js +50 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/onelogin/OneLoginAuth.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/saml/types.esm.js +18 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/saml/types.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/vmwareCloud/VMwareCloudAuth.esm.js +30 -0
- package/dist/packages/core-app-api/src/apis/implementations/auth/vmwareCloud/VMwareCloudAuth.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/system/ApiAggregator.esm.js +18 -0
- package/dist/packages/core-app-api/src/apis/system/ApiAggregator.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/apis/system/ApiProvider.esm.js +25 -0
- package/dist/packages/core-app-api/src/apis/system/ApiProvider.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/app/AppContext.esm.js +5 -0
- package/dist/packages/core-app-api/src/app/AppContext.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/app/AppRouter.esm.js +94 -0
- package/dist/packages/core-app-api/src/app/AppRouter.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/app/AppThemeProvider.esm.js +60 -0
- package/dist/packages/core-app-api/src/app/AppThemeProvider.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/app/InternalAppContext.esm.js +6 -0
- package/dist/packages/core-app-api/src/app/InternalAppContext.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/app/isProtectedApp.esm.js +8 -0
- package/dist/packages/core-app-api/src/app/isProtectedApp.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/app/isReactRouterBeta.esm.js +10 -0
- package/dist/packages/core-app-api/src/app/isReactRouterBeta.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/lib/AuthConnector/DefaultAuthConnector.esm.js +164 -0
- package/dist/packages/core-app-api/src/lib/AuthConnector/DefaultAuthConnector.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/lib/AuthSessionManager/RefreshingAuthSessionManager.esm.js +91 -0
- package/dist/packages/core-app-api/src/lib/AuthSessionManager/RefreshingAuthSessionManager.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/lib/AuthSessionManager/SessionStateTracker.esm.js +23 -0
- package/dist/packages/core-app-api/src/lib/AuthSessionManager/SessionStateTracker.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/lib/AuthSessionManager/common.esm.js +44 -0
- package/dist/packages/core-app-api/src/lib/AuthSessionManager/common.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/lib/loginPopup.esm.js +62 -0
- package/dist/packages/core-app-api/src/lib/loginPopup.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/lib/subjects.esm.js +124 -0
- package/dist/packages/core-app-api/src/lib/subjects.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/routing/FeatureFlagged.esm.js +13 -0
- package/dist/packages/core-app-api/src/routing/FeatureFlagged.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/routing/FlatRoutes.esm.js +59 -0
- package/dist/packages/core-app-api/src/routing/FlatRoutes.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/routing/RouteTracker.esm.js +77 -0
- package/dist/packages/core-app-api/src/routing/RouteTracker.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/routing/RoutingProvider.esm.js +10 -0
- package/dist/packages/core-app-api/src/routing/RoutingProvider.esm.js.map +1 -0
- package/dist/packages/core-app-api/src/routing/types.esm.js +7 -0
- package/dist/packages/core-app-api/src/routing/types.esm.js.map +1 -0
- package/dist/packages/core-plugin-api/src/translation/TranslationRef.esm.js +13 -0
- package/dist/packages/core-plugin-api/src/translation/TranslationRef.esm.js.map +1 -0
- package/dist/packages/core-plugin-api/src/translation/TranslationResource.esm.js +13 -0
- package/dist/packages/core-plugin-api/src/translation/TranslationResource.esm.js.map +1 -0
- package/dist/packages/frontend-app-api/src/apis/implementations/ComponentsApi/DefaultComponentsApi.esm.js +21 -0
- package/dist/packages/frontend-app-api/src/apis/implementations/ComponentsApi/DefaultComponentsApi.esm.js.map +1 -0
- package/dist/packages/frontend-app-api/src/apis/implementations/IconsApi/DefaultIconsApi.esm.js +15 -0
- package/dist/packages/frontend-app-api/src/apis/implementations/IconsApi/DefaultIconsApi.esm.js.map +1 -0
- package/dist/packages/frontend-app-api/src/routing/RouteTracker.esm.js +69 -0
- package/dist/packages/frontend-app-api/src/routing/RouteTracker.esm.js.map +1 -0
- package/dist/packages/frontend-app-api/src/routing/getBasePath.esm.js +12 -0
- package/dist/packages/frontend-app-api/src/routing/getBasePath.esm.js.map +1 -0
- package/dist/plugin.esm.js +43 -0
- package/dist/plugin.esm.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
function isProtectedApp() {
|
|
2
|
+
const element = document.querySelector('meta[name="backstage-app-mode"]');
|
|
3
|
+
const appMode = element?.getAttribute("content") ?? "public";
|
|
4
|
+
return appMode === "protected";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { isProtectedApp };
|
|
8
|
+
//# sourceMappingURL=isProtectedApp.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isProtectedApp.esm.js","sources":["../../../../../../../packages/core-app-api/src/app/isProtectedApp.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function isProtectedApp() {\n const element = document.querySelector('meta[name=\"backstage-app-mode\"]');\n const appMode = element?.getAttribute('content') ?? 'public';\n return appMode === 'protected';\n}\n"],"names":[],"mappings":"AAgBO,SAAS,cAAiB,GAAA;AAC/B,EAAM,MAAA,OAAA,GAAU,QAAS,CAAA,aAAA,CAAc,iCAAiC,CAAA,CAAA;AACxE,EAAA,MAAM,OAAU,GAAA,OAAA,EAAS,YAAa,CAAA,SAAS,CAAK,IAAA,QAAA,CAAA;AACpD,EAAA,OAAO,OAAY,KAAA,WAAA,CAAA;AACrB;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createRoutesFromChildren, Route } from 'react-router-dom';
|
|
3
|
+
|
|
4
|
+
function isReactRouterBeta() {
|
|
5
|
+
const [obj] = createRoutesFromChildren(/* @__PURE__ */ React.createElement(Route, { index: true, element: /* @__PURE__ */ React.createElement("div", null) }));
|
|
6
|
+
return !obj.index;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { isReactRouterBeta };
|
|
10
|
+
//# sourceMappingURL=isReactRouterBeta.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isReactRouterBeta.esm.js","sources":["../../../../../../../packages/core-app-api/src/app/isReactRouterBeta.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\nimport { createRoutesFromChildren, Route } from 'react-router-dom';\n\nexport function isReactRouterBeta(): boolean {\n const [obj] = createRoutesFromChildren(<Route index element={<div />} />);\n return !obj.index;\n}\n"],"names":[],"mappings":";;;AAmBO,SAAS,iBAA6B,GAAA;AAC3C,EAAA,MAAM,CAAC,GAAG,CAAI,GAAA,wBAAA,iBAA0B,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAM,KAAK,EAAA,IAAA,EAAC,OAAS,kBAAA,KAAA,CAAA,aAAA,CAAC,KAAI,EAAA,IAAA,CAAA,EAAI,CAAE,CAAA,CAAA;AACxE,EAAA,OAAO,CAAC,GAAI,CAAA,KAAA,CAAA;AACd;;;;"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { showLoginPopup } from '../loginPopup.esm.js';
|
|
2
|
+
|
|
3
|
+
let warned = false;
|
|
4
|
+
function defaultJoinScopes(scopes) {
|
|
5
|
+
return [...scopes].join(" ");
|
|
6
|
+
}
|
|
7
|
+
class DefaultAuthConnector {
|
|
8
|
+
discoveryApi;
|
|
9
|
+
environment;
|
|
10
|
+
provider;
|
|
11
|
+
joinScopesFunc;
|
|
12
|
+
authRequester;
|
|
13
|
+
sessionTransform;
|
|
14
|
+
enableExperimentalRedirectFlow;
|
|
15
|
+
popupOptions;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
const {
|
|
18
|
+
configApi,
|
|
19
|
+
discoveryApi,
|
|
20
|
+
environment,
|
|
21
|
+
provider,
|
|
22
|
+
joinScopes = defaultJoinScopes,
|
|
23
|
+
oauthRequestApi,
|
|
24
|
+
sessionTransform = (id) => id,
|
|
25
|
+
popupOptions
|
|
26
|
+
} = options;
|
|
27
|
+
if (!warned && !configApi) {
|
|
28
|
+
console.warn(
|
|
29
|
+
"DEPRECATION WARNING: Authentication providers require a configApi instance to configure the authentication flow. Please provide one to the authentication provider constructor."
|
|
30
|
+
);
|
|
31
|
+
warned = true;
|
|
32
|
+
}
|
|
33
|
+
this.enableExperimentalRedirectFlow = configApi ? configApi.getOptionalBoolean("enableExperimentalRedirectFlow") ?? false : false;
|
|
34
|
+
this.authRequester = oauthRequestApi.createAuthRequester({
|
|
35
|
+
provider,
|
|
36
|
+
onAuthRequest: async (scopes) => {
|
|
37
|
+
if (!this.enableExperimentalRedirectFlow) {
|
|
38
|
+
return this.showPopup(scopes);
|
|
39
|
+
}
|
|
40
|
+
return this.executeRedirect(scopes);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
this.discoveryApi = discoveryApi;
|
|
44
|
+
this.environment = environment;
|
|
45
|
+
this.provider = provider;
|
|
46
|
+
this.joinScopesFunc = joinScopes;
|
|
47
|
+
this.sessionTransform = sessionTransform;
|
|
48
|
+
this.popupOptions = popupOptions;
|
|
49
|
+
}
|
|
50
|
+
async createSession(options) {
|
|
51
|
+
if (options.instantPopup) {
|
|
52
|
+
if (this.enableExperimentalRedirectFlow) {
|
|
53
|
+
return this.executeRedirect(options.scopes);
|
|
54
|
+
}
|
|
55
|
+
return this.showPopup(options.scopes);
|
|
56
|
+
}
|
|
57
|
+
return this.authRequester(options.scopes);
|
|
58
|
+
}
|
|
59
|
+
async refreshSession(scopes) {
|
|
60
|
+
const res = await fetch(
|
|
61
|
+
await this.buildUrl("/refresh", {
|
|
62
|
+
optional: true,
|
|
63
|
+
...scopes && { scope: this.joinScopesFunc(scopes) }
|
|
64
|
+
}),
|
|
65
|
+
{
|
|
66
|
+
headers: {
|
|
67
|
+
"x-requested-with": "XMLHttpRequest"
|
|
68
|
+
},
|
|
69
|
+
credentials: "include"
|
|
70
|
+
}
|
|
71
|
+
).catch((error) => {
|
|
72
|
+
throw new Error(`Auth refresh request failed, ${error}`);
|
|
73
|
+
});
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
const error = new Error(
|
|
76
|
+
`Auth refresh request failed, ${res.statusText}`
|
|
77
|
+
);
|
|
78
|
+
error.status = res.status;
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
const authInfo = await res.json();
|
|
82
|
+
if (authInfo.error) {
|
|
83
|
+
const error = new Error(authInfo.error.message);
|
|
84
|
+
if (authInfo.error.name) {
|
|
85
|
+
error.name = authInfo.error.name;
|
|
86
|
+
}
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
return await this.sessionTransform(authInfo);
|
|
90
|
+
}
|
|
91
|
+
async removeSession() {
|
|
92
|
+
const res = await fetch(await this.buildUrl("/logout"), {
|
|
93
|
+
method: "POST",
|
|
94
|
+
headers: {
|
|
95
|
+
"x-requested-with": "XMLHttpRequest"
|
|
96
|
+
},
|
|
97
|
+
credentials: "include"
|
|
98
|
+
}).catch((error) => {
|
|
99
|
+
throw new Error(`Logout request failed, ${error}`);
|
|
100
|
+
});
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
const error = new Error(`Logout request failed, ${res.statusText}`);
|
|
103
|
+
error.status = res.status;
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async showPopup(scopes) {
|
|
108
|
+
const scope = this.joinScopesFunc(scopes);
|
|
109
|
+
const popupUrl = await this.buildUrl("/start", {
|
|
110
|
+
scope,
|
|
111
|
+
origin: window.location.origin,
|
|
112
|
+
flow: "popup"
|
|
113
|
+
});
|
|
114
|
+
const width = this.popupOptions?.size?.fullscreen ? window.screen.width : this.popupOptions?.size?.width || 450;
|
|
115
|
+
const height = this.popupOptions?.size?.fullscreen ? window.screen.height : this.popupOptions?.size?.height || 730;
|
|
116
|
+
const payload = await showLoginPopup({
|
|
117
|
+
url: popupUrl,
|
|
118
|
+
name: `${this.provider.title} Login`,
|
|
119
|
+
origin: new URL(popupUrl).origin,
|
|
120
|
+
width,
|
|
121
|
+
height
|
|
122
|
+
});
|
|
123
|
+
return await this.sessionTransform(payload);
|
|
124
|
+
}
|
|
125
|
+
async executeRedirect(scopes) {
|
|
126
|
+
const scope = this.joinScopesFunc(scopes);
|
|
127
|
+
window.location.href = await this.buildUrl("/start", {
|
|
128
|
+
scope,
|
|
129
|
+
origin: window.location.origin,
|
|
130
|
+
redirectUrl: window.location.href,
|
|
131
|
+
flow: "redirect"
|
|
132
|
+
});
|
|
133
|
+
return new Promise(() => {
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async buildUrl(path, query) {
|
|
137
|
+
const baseUrl = await this.discoveryApi.getBaseUrl("auth");
|
|
138
|
+
const queryString = this.buildQueryString({
|
|
139
|
+
...query,
|
|
140
|
+
env: this.environment
|
|
141
|
+
});
|
|
142
|
+
return `${baseUrl}/${this.provider.id}${path}${queryString}`;
|
|
143
|
+
}
|
|
144
|
+
buildQueryString(query) {
|
|
145
|
+
if (!query) {
|
|
146
|
+
return "";
|
|
147
|
+
}
|
|
148
|
+
const queryString = Object.entries(query).map(([key, value]) => {
|
|
149
|
+
if (typeof value === "string") {
|
|
150
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
151
|
+
} else if (value) {
|
|
152
|
+
return encodeURIComponent(key);
|
|
153
|
+
}
|
|
154
|
+
return void 0;
|
|
155
|
+
}).filter(Boolean).join("&");
|
|
156
|
+
if (!queryString) {
|
|
157
|
+
return "";
|
|
158
|
+
}
|
|
159
|
+
return `?${queryString}`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { DefaultAuthConnector };
|
|
164
|
+
//# sourceMappingURL=DefaultAuthConnector.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultAuthConnector.esm.js","sources":["../../../../../../../../packages/core-app-api/src/lib/AuthConnector/DefaultAuthConnector.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n AuthProviderInfo,\n ConfigApi,\n DiscoveryApi,\n OAuthRequestApi,\n OAuthRequester,\n} from '@backstage/core-plugin-api';\nimport { showLoginPopup } from '../loginPopup';\nimport { AuthConnector, CreateSessionOptions, PopupOptions } from './types';\n\nlet warned = false;\n\ntype Options<AuthSession> = {\n /**\n * DiscoveryApi instance used to locate the auth backend endpoint.\n */\n discoveryApi: DiscoveryApi;\n /**\n * Environment hint passed on to auth backend, for example 'production' or 'development'\n */\n environment: string;\n /**\n * Information about the auth provider to be shown to the user.\n * The ID Must match the backend auth plugin configuration, for example 'google'.\n */\n provider: AuthProviderInfo;\n /**\n * API used to instantiate an auth requester.\n */\n oauthRequestApi: OAuthRequestApi;\n /**\n * Function used to join together a set of scopes, defaults to joining with a space character.\n */\n joinScopes?: (scopes: Set<string>) => string;\n /**\n * Function used to transform an auth response into the session type.\n */\n sessionTransform?(response: any): AuthSession | Promise<AuthSession>;\n /**\n * ConfigApi instance used to configure authentication flow of pop-up or redirect.\n */\n configApi?: ConfigApi;\n /**\n * Options used to configure auth popup\n */\n popupOptions?: PopupOptions;\n};\n\nfunction defaultJoinScopes(scopes: Set<string>) {\n return [...scopes].join(' ');\n}\n\n/**\n * DefaultAuthConnector is the default auth connector in Backstage. It talks to the\n * backend auth plugin through the standardized API, and requests user permission\n * via the OAuthRequestApi.\n */\nexport class DefaultAuthConnector<AuthSession>\n implements AuthConnector<AuthSession>\n{\n private readonly discoveryApi: DiscoveryApi;\n private readonly environment: string;\n private readonly provider: AuthProviderInfo;\n private readonly joinScopesFunc: (scopes: Set<string>) => string;\n private readonly authRequester: OAuthRequester<AuthSession>;\n private readonly sessionTransform: (response: any) => Promise<AuthSession>;\n private readonly enableExperimentalRedirectFlow: boolean;\n private readonly popupOptions: PopupOptions | undefined;\n constructor(options: Options<AuthSession>) {\n const {\n configApi,\n discoveryApi,\n environment,\n provider,\n joinScopes = defaultJoinScopes,\n oauthRequestApi,\n sessionTransform = id => id,\n popupOptions,\n } = options;\n\n if (!warned && !configApi) {\n // eslint-disable-next-line no-console\n console.warn(\n 'DEPRECATION WARNING: Authentication providers require a configApi instance to configure the authentication flow. Please provide one to the authentication provider constructor.',\n );\n warned = true;\n }\n\n this.enableExperimentalRedirectFlow = configApi\n ? configApi.getOptionalBoolean('enableExperimentalRedirectFlow') ?? false\n : false;\n\n this.authRequester = oauthRequestApi.createAuthRequester({\n provider,\n onAuthRequest: async scopes => {\n if (!this.enableExperimentalRedirectFlow) {\n return this.showPopup(scopes);\n }\n return this.executeRedirect(scopes);\n },\n });\n\n this.discoveryApi = discoveryApi;\n this.environment = environment;\n this.provider = provider;\n this.joinScopesFunc = joinScopes;\n this.sessionTransform = sessionTransform;\n this.popupOptions = popupOptions;\n }\n\n async createSession(options: CreateSessionOptions): Promise<AuthSession> {\n if (options.instantPopup) {\n if (this.enableExperimentalRedirectFlow) {\n return this.executeRedirect(options.scopes);\n }\n return this.showPopup(options.scopes);\n }\n return this.authRequester(options.scopes);\n }\n\n async refreshSession(scopes?: Set<string>): Promise<any> {\n const res = await fetch(\n await this.buildUrl('/refresh', {\n optional: true,\n ...(scopes && { scope: this.joinScopesFunc(scopes) }),\n }),\n {\n headers: {\n 'x-requested-with': 'XMLHttpRequest',\n },\n credentials: 'include',\n },\n ).catch(error => {\n throw new Error(`Auth refresh request failed, ${error}`);\n });\n\n if (!res.ok) {\n const error: any = new Error(\n `Auth refresh request failed, ${res.statusText}`,\n );\n error.status = res.status;\n throw error;\n }\n\n const authInfo = await res.json();\n\n if (authInfo.error) {\n const error = new Error(authInfo.error.message);\n if (authInfo.error.name) {\n error.name = authInfo.error.name;\n }\n throw error;\n }\n return await this.sessionTransform(authInfo);\n }\n\n async removeSession(): Promise<void> {\n const res = await fetch(await this.buildUrl('/logout'), {\n method: 'POST',\n headers: {\n 'x-requested-with': 'XMLHttpRequest',\n },\n credentials: 'include',\n }).catch(error => {\n throw new Error(`Logout request failed, ${error}`);\n });\n\n if (!res.ok) {\n const error: any = new Error(`Logout request failed, ${res.statusText}`);\n error.status = res.status;\n throw error;\n }\n }\n\n private async showPopup(scopes: Set<string>): Promise<AuthSession> {\n const scope = this.joinScopesFunc(scopes);\n const popupUrl = await this.buildUrl('/start', {\n scope,\n origin: window.location.origin,\n flow: 'popup',\n });\n\n const width = this.popupOptions?.size?.fullscreen\n ? window.screen.width\n : this.popupOptions?.size?.width || 450;\n\n const height = this.popupOptions?.size?.fullscreen\n ? window.screen.height\n : this.popupOptions?.size?.height || 730;\n\n const payload = await showLoginPopup({\n url: popupUrl,\n name: `${this.provider.title} Login`,\n origin: new URL(popupUrl).origin,\n width,\n height,\n });\n\n return await this.sessionTransform(payload);\n }\n\n private async executeRedirect(scopes: Set<string>): Promise<AuthSession> {\n const scope = this.joinScopesFunc(scopes);\n // redirect to auth api\n window.location.href = await this.buildUrl('/start', {\n scope,\n origin: window.location.origin,\n redirectUrl: window.location.href,\n flow: 'redirect',\n });\n // return a promise that never resolves\n return new Promise(() => {});\n }\n\n private async buildUrl(\n path: string,\n query?: { [key: string]: string | boolean | undefined },\n ): Promise<string> {\n const baseUrl = await this.discoveryApi.getBaseUrl('auth');\n const queryString = this.buildQueryString({\n ...query,\n env: this.environment,\n });\n\n return `${baseUrl}/${this.provider.id}${path}${queryString}`;\n }\n\n private buildQueryString(query?: {\n [key: string]: string | boolean | undefined;\n }): string {\n if (!query) {\n return '';\n }\n\n const queryString = Object.entries<string | boolean | undefined>(query)\n .map(([key, value]) => {\n if (typeof value === 'string') {\n return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;\n } else if (value) {\n return encodeURIComponent(key);\n }\n return undefined;\n })\n .filter(Boolean)\n .join('&');\n\n if (!queryString) {\n return '';\n }\n return `?${queryString}`;\n }\n}\n"],"names":[],"mappings":";;AAyBA,IAAI,MAAS,GAAA,KAAA,CAAA;AAsCb,SAAS,kBAAkB,MAAqB,EAAA;AAC9C,EAAA,OAAO,CAAC,GAAG,MAAM,CAAA,CAAE,KAAK,GAAG,CAAA,CAAA;AAC7B,CAAA;AAOO,MAAM,oBAEb,CAAA;AAAA,EACmB,YAAA,CAAA;AAAA,EACA,WAAA,CAAA;AAAA,EACA,QAAA,CAAA;AAAA,EACA,cAAA,CAAA;AAAA,EACA,aAAA,CAAA;AAAA,EACA,gBAAA,CAAA;AAAA,EACA,8BAAA,CAAA;AAAA,EACA,YAAA,CAAA;AA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A,MAAM,OAAU,GAAA,MAAM,IAAK,CAAA,YAAA,CAAa,WAAW,MAAM,CAAA,CAAA;AACzD,IAAM,MAAA,WAAA,GAAc,KAAK,gBAAiB,CAAA;AAAA,MACxC,GAAG,KAAA;AAAA,MACH,KAAK,IAAK,CAAA,WAAA;AAAA,KACX,CAAA,CAAA;AAED,IAAO,OAAA,CAAA,EAAG,OAAO,CAAI,CAAA,EAAA,IAAA,CAAK,SAAS,EAAE,CAAA,EAAG,IAAI,CAAA,EAAG,WAAW,CAAA,CAAA,CAAA;AAAA,GAC5D;AAAA,EAEQ,iBAAiB,KAEd,EAAA;AACT,IAAA,IAAI,CAAC,KAAO,EAAA;AACV,MAAO,OAAA,EAAA,CAAA;AAAA,KACT;AAEA,IAAM,MAAA,WAAA,GAAc,MAAO,CAAA,OAAA,CAAsC,KAAK,CAAA,CACnE,IAAI,CAAC,CAAC,GAAK,EAAA,KAAK,CAAM,KAAA;AACrB,MAAI,IAAA,OAAO,UAAU,QAAU,EAAA;AAC7B,QAAA,OAAO,GAAG,kBAAmB,CAAA,GAAG,CAAC,CAAI,CAAA,EAAA,kBAAA,CAAmB,KAAK,CAAC,CAAA,CAAA,CAAA;AAAA,iBACrD,KAAO,EAAA;AAChB,QAAA,OAAO,mBAAmB,GAAG,CAAA,CAAA;AAAA,OAC/B;AACA,MAAO,OAAA,KAAA,CAAA,CAAA;AAAA,KACR,CACA,CAAA,MAAA,CAAO,OAAO,CAAA,CACd,KAAK,GAAG,CAAA,CAAA;AAEX,IAAA,IAAI,CAAC,WAAa,EAAA;AAChB,MAAO,OAAA,EAAA,CAAA;AAAA,KACT;AACA,IAAA,OAAO,IAAI,WAAW,CAAA,CAAA,CAAA;AAAA,GACxB;AACF;;;;"}
|
package/dist/packages/core-app-api/src/lib/AuthSessionManager/RefreshingAuthSessionManager.esm.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { SessionScopeHelper, hasScopes } from './common.esm.js';
|
|
2
|
+
import { SessionStateTracker } from './SessionStateTracker.esm.js';
|
|
3
|
+
|
|
4
|
+
class RefreshingAuthSessionManager {
|
|
5
|
+
connector;
|
|
6
|
+
helper;
|
|
7
|
+
sessionScopesFunc;
|
|
8
|
+
sessionShouldRefreshFunc;
|
|
9
|
+
stateTracker = new SessionStateTracker();
|
|
10
|
+
refreshPromise;
|
|
11
|
+
currentSession;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
const {
|
|
14
|
+
connector,
|
|
15
|
+
defaultScopes = /* @__PURE__ */ new Set(),
|
|
16
|
+
sessionScopes,
|
|
17
|
+
sessionShouldRefresh
|
|
18
|
+
} = options;
|
|
19
|
+
this.connector = connector;
|
|
20
|
+
this.sessionScopesFunc = sessionScopes;
|
|
21
|
+
this.sessionShouldRefreshFunc = sessionShouldRefresh;
|
|
22
|
+
this.helper = new SessionScopeHelper({ sessionScopes, defaultScopes });
|
|
23
|
+
}
|
|
24
|
+
async getSession(options) {
|
|
25
|
+
if (this.helper.sessionExistsAndHasScope(this.currentSession, options.scopes)) {
|
|
26
|
+
const shouldRefresh = this.sessionShouldRefreshFunc(this.currentSession);
|
|
27
|
+
if (!shouldRefresh) {
|
|
28
|
+
return this.currentSession;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const refreshedSession = await this.collapsedSessionRefresh(
|
|
32
|
+
options.scopes
|
|
33
|
+
);
|
|
34
|
+
const currentScopes = this.sessionScopesFunc(this.currentSession);
|
|
35
|
+
const refreshedScopes = this.sessionScopesFunc(refreshedSession);
|
|
36
|
+
if (hasScopes(refreshedScopes, currentScopes)) {
|
|
37
|
+
this.currentSession = refreshedSession;
|
|
38
|
+
}
|
|
39
|
+
return refreshedSession;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (options.optional) {
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!this.currentSession && !options.instantPopup) {
|
|
48
|
+
try {
|
|
49
|
+
const newSession = await this.collapsedSessionRefresh(options.scopes);
|
|
50
|
+
this.currentSession = newSession;
|
|
51
|
+
return this.getSession(options);
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (options.optional) {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
this.currentSession = await this.connector.createSession({
|
|
59
|
+
...options,
|
|
60
|
+
scopes: this.helper.getExtendedScope(this.currentSession, options.scopes)
|
|
61
|
+
});
|
|
62
|
+
this.stateTracker.setIsSignedIn(true);
|
|
63
|
+
return this.currentSession;
|
|
64
|
+
}
|
|
65
|
+
async removeSession() {
|
|
66
|
+
this.currentSession = void 0;
|
|
67
|
+
await this.connector.removeSession();
|
|
68
|
+
this.stateTracker.setIsSignedIn(false);
|
|
69
|
+
}
|
|
70
|
+
sessionState$() {
|
|
71
|
+
return this.stateTracker.sessionState$();
|
|
72
|
+
}
|
|
73
|
+
async collapsedSessionRefresh(scopes) {
|
|
74
|
+
if (this.refreshPromise) {
|
|
75
|
+
return this.refreshPromise;
|
|
76
|
+
}
|
|
77
|
+
this.refreshPromise = this.connector.refreshSession(
|
|
78
|
+
this.helper.getExtendedScope(this.currentSession, scopes)
|
|
79
|
+
);
|
|
80
|
+
try {
|
|
81
|
+
const session = await this.refreshPromise;
|
|
82
|
+
this.stateTracker.setIsSignedIn(true);
|
|
83
|
+
return session;
|
|
84
|
+
} finally {
|
|
85
|
+
delete this.refreshPromise;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { RefreshingAuthSessionManager };
|
|
91
|
+
//# sourceMappingURL=RefreshingAuthSessionManager.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RefreshingAuthSessionManager.esm.js","sources":["../../../../../../../../packages/core-app-api/src/lib/AuthSessionManager/RefreshingAuthSessionManager.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n SessionManager,\n SessionScopesFunc,\n SessionShouldRefreshFunc,\n GetSessionOptions,\n} from './types';\nimport { AuthConnector } from '../AuthConnector';\nimport { SessionScopeHelper, hasScopes } from './common';\nimport { SessionStateTracker } from './SessionStateTracker';\n\ntype Options<T> = {\n /** The connector used for acting on the auth session */\n connector: AuthConnector<T>;\n /** Used to get the scope of the session */\n sessionScopes: SessionScopesFunc<T>;\n /** Used to check if the session needs to be refreshed */\n sessionShouldRefresh: SessionShouldRefreshFunc<T>;\n /** The default scopes that should always be present in a session, defaults to none. */\n defaultScopes?: Set<string>;\n};\n\n/**\n * RefreshingAuthSessionManager manages an underlying session that has\n * and expiration time and needs to be refreshed periodically.\n */\nexport class RefreshingAuthSessionManager<T> implements SessionManager<T> {\n private readonly connector: AuthConnector<T>;\n private readonly helper: SessionScopeHelper<T>;\n private readonly sessionScopesFunc: SessionScopesFunc<T>;\n private readonly sessionShouldRefreshFunc: SessionShouldRefreshFunc<T>;\n private readonly stateTracker = new SessionStateTracker();\n\n private refreshPromise?: Promise<T>;\n private currentSession: T | undefined;\n\n constructor(options: Options<T>) {\n const {\n connector,\n defaultScopes = new Set(),\n sessionScopes,\n sessionShouldRefresh,\n } = options;\n\n this.connector = connector;\n this.sessionScopesFunc = sessionScopes;\n this.sessionShouldRefreshFunc = sessionShouldRefresh;\n this.helper = new SessionScopeHelper({ sessionScopes, defaultScopes });\n }\n\n async getSession(options: GetSessionOptions): Promise<T | undefined> {\n if (\n this.helper.sessionExistsAndHasScope(this.currentSession, options.scopes)\n ) {\n const shouldRefresh = this.sessionShouldRefreshFunc(this.currentSession!);\n if (!shouldRefresh) {\n return this.currentSession!;\n }\n\n try {\n const refreshedSession = await this.collapsedSessionRefresh(\n options.scopes,\n );\n const currentScopes = this.sessionScopesFunc(this.currentSession!);\n const refreshedScopes = this.sessionScopesFunc(refreshedSession);\n if (hasScopes(refreshedScopes, currentScopes)) {\n this.currentSession = refreshedSession;\n }\n return refreshedSession;\n } catch (error) {\n if (options.optional) {\n return undefined;\n }\n throw error;\n }\n }\n\n // The user may still have a valid refresh token in their cookies. Attempt to\n // initiate a fresh session through the backend using that refresh token.\n //\n // We skip this check if an instant login popup is requested, as we need to\n // stay in a synchronous call stack from the user interaction. The downside\n // is that the user will sometimes be requested to log in even if they\n // already had an existing session.\n if (!this.currentSession && !options.instantPopup) {\n try {\n const newSession = await this.collapsedSessionRefresh(options.scopes);\n this.currentSession = newSession;\n // The session might not have the scopes requested so go back and check again\n return this.getSession(options);\n } catch {\n // If the refresh attempt fails we assume we don't have a session, so continue to create one.\n }\n }\n\n // If we continue here we will show a popup, so exit if this is an optional session request.\n if (options.optional) {\n return undefined;\n }\n\n // We can call authRequester multiple times, the returned session will contain all requested scopes.\n this.currentSession = await this.connector.createSession({\n ...options,\n scopes: this.helper.getExtendedScope(this.currentSession, options.scopes),\n });\n this.stateTracker.setIsSignedIn(true);\n return this.currentSession;\n }\n\n async removeSession() {\n this.currentSession = undefined;\n await this.connector.removeSession();\n this.stateTracker.setIsSignedIn(false);\n }\n\n sessionState$() {\n return this.stateTracker.sessionState$();\n }\n\n private async collapsedSessionRefresh(scopes?: Set<string>): Promise<T> {\n if (this.refreshPromise) {\n return this.refreshPromise;\n }\n\n this.refreshPromise = this.connector.refreshSession(\n this.helper.getExtendedScope(this.currentSession, scopes),\n );\n\n try {\n const session = await this.refreshPromise;\n this.stateTracker.setIsSignedIn(true);\n return session;\n } finally {\n delete this.refreshPromise;\n }\n }\n}\n"],"names":[],"mappings":";;;AAyCO,MAAM,4BAA6D,CAAA;AAAA,EACvD,SAAA,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vC;AAAA,EAEA,aAAgB,GAAA;AACd,IAAO,OAAA,IAAA,CAAK,aAAa,aAAc,EAAA,CAAA;AAAA,GACzC;AAAA,EAEA,MAAc,wBAAwB,MAAkC,EAAA;AACtE,IAAA,IAAI,KAAK,cAAgB,EAAA;AACvB,MAAA,OAAO,IAAK,CAAA,cAAA,CAAA;AAAA,KACd;AAEA,IAAK,IAAA,CAAA,cAAA,GAAiB,KAAK,SAAU,CAAA,cAAA;AAAA,MACnC,IAAK,CAAA,MAAA,CAAO,gBAAiB,CAAA,IAAA,CAAK,gBAAgB,MAAM,CAAA;AAAA,KAC1D,CAAA;AAEA,IAAI,IAAA;AACF,MAAM,MAAA,OAAA,GAAU,MAAM,IAAK,CAAA,cAAA,CAAA;AAC3B,MAAK,IAAA,CAAA,YAAA,CAAa,cAAc,IAAI,CAAA,CAAA;AACpC,MAAO,OAAA,OAAA,CAAA;AAAA,KACP,SAAA;AACA,MAAA,OAAO,IAAK,CAAA,cAAA,CAAA;AAAA,KACd;AAAA,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BehaviorSubject } from '../subjects.esm.js';
|
|
2
|
+
import { SessionState } from '@backstage/core-plugin-api';
|
|
3
|
+
|
|
4
|
+
class SessionStateTracker {
|
|
5
|
+
subject = new BehaviorSubject(
|
|
6
|
+
SessionState.SignedOut
|
|
7
|
+
);
|
|
8
|
+
signedIn = false;
|
|
9
|
+
setIsSignedIn(isSignedIn) {
|
|
10
|
+
if (this.signedIn !== isSignedIn) {
|
|
11
|
+
this.signedIn = isSignedIn;
|
|
12
|
+
this.subject.next(
|
|
13
|
+
this.signedIn ? SessionState.SignedIn : SessionState.SignedOut
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
sessionState$() {
|
|
18
|
+
return this.subject;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { SessionStateTracker };
|
|
23
|
+
//# sourceMappingURL=SessionStateTracker.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionStateTracker.esm.js","sources":["../../../../../../../../packages/core-app-api/src/lib/AuthSessionManager/SessionStateTracker.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BehaviorSubject } from '../subjects';\nimport { SessionState } from '@backstage/core-plugin-api';\nimport { Observable } from '@backstage/types';\n\nexport class SessionStateTracker {\n private readonly subject = new BehaviorSubject<SessionState>(\n SessionState.SignedOut,\n );\n\n private signedIn: boolean = false;\n\n setIsSignedIn(isSignedIn: boolean) {\n if (this.signedIn !== isSignedIn) {\n this.signedIn = isSignedIn;\n this.subject.next(\n this.signedIn ? SessionState.SignedIn : SessionState.SignedOut,\n );\n }\n }\n\n sessionState$(): Observable<SessionState> {\n return this.subject;\n }\n}\n"],"names":[],"mappings":";;;AAoBO,MAAM,mBAAoB,CAAA;AAAA,EACd,UAAU,IAAI,eAAA;AAAA,IAC7B,YAAa,CAAA,SAAA;AAAA,GACf,CAAA;AAAA,EAEQ,QAAoB,GAAA,KAAA,CAAA;AAAA,EAE5B,cAAc,UAAqB,EAAA;AACjC,IAAI,IAAA,IAAA,CAAK,aAAa,UAAY,EAAA;AAChC,MAAA,IAAA,CAAK,QAAW,GAAA,UAAA,CAAA;AAChB,MAAA,IAAA,CAAK,OAAQ,CAAA,IAAA;AAAA,QACX,IAAK,CAAA,QAAA,GAAW,YAAa,CAAA,QAAA,GAAW,YAAa,CAAA,SAAA;AAAA,OACvD,CAAA;AAAA,KACF;AAAA,GACF;AAAA,EAEA,aAA0C,GAAA;AACxC,IAAA,OAAO,IAAK,CAAA,OAAA,CAAA;AAAA,GACd;AACF;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
function hasScopes(searched, searchFor) {
|
|
2
|
+
for (const scope of searchFor) {
|
|
3
|
+
if (!searched.has(scope)) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
class SessionScopeHelper {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
}
|
|
13
|
+
sessionExistsAndHasScope(session, scopes) {
|
|
14
|
+
if (!session) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (!scopes) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (this.options.sessionScopes === void 0) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
const sessionScopes = this.options.sessionScopes(session);
|
|
24
|
+
return hasScopes(sessionScopes, scopes);
|
|
25
|
+
}
|
|
26
|
+
getExtendedScope(session, scopes) {
|
|
27
|
+
const newScope = new Set(this.options.defaultScopes);
|
|
28
|
+
if (session && this.options.sessionScopes !== void 0) {
|
|
29
|
+
const sessionScopes = this.options.sessionScopes(session);
|
|
30
|
+
for (const scope of sessionScopes) {
|
|
31
|
+
newScope.add(scope);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (scopes) {
|
|
35
|
+
for (const scope of scopes) {
|
|
36
|
+
newScope.add(scope);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return newScope;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { SessionScopeHelper, hasScopes };
|
|
44
|
+
//# sourceMappingURL=common.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.esm.js","sources":["../../../../../../../../packages/core-app-api/src/lib/AuthSessionManager/common.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { SessionScopesFunc } from './types';\n\nexport function hasScopes(\n searched: Set<string>,\n searchFor: Set<string>,\n): boolean {\n for (const scope of searchFor) {\n if (!searched.has(scope)) {\n return false;\n }\n }\n return true;\n}\n\ntype ScopeHelperOptions<T> = {\n sessionScopes: SessionScopesFunc<T> | undefined;\n defaultScopes?: Set<string>;\n};\n\nexport class SessionScopeHelper<T> {\n constructor(private readonly options: ScopeHelperOptions<T>) {}\n\n sessionExistsAndHasScope(\n session: T | undefined,\n scopes?: Set<string>,\n ): boolean {\n if (!session) {\n return false;\n }\n if (!scopes) {\n return true;\n }\n if (this.options.sessionScopes === undefined) {\n return true;\n }\n const sessionScopes = this.options.sessionScopes(session);\n return hasScopes(sessionScopes, scopes);\n }\n\n getExtendedScope(session: T | undefined, scopes?: Set<string>) {\n const newScope = new Set(this.options.defaultScopes);\n if (session && this.options.sessionScopes !== undefined) {\n const sessionScopes = this.options.sessionScopes(session);\n for (const scope of sessionScopes) {\n newScope.add(scope);\n }\n }\n if (scopes) {\n for (const scope of scopes) {\n newScope.add(scope);\n }\n }\n return newScope;\n }\n}\n"],"names":[],"mappings":"AAkBgB,SAAA,SAAA,CACd,UACA,SACS,EAAA;AACT,EAAA,KAAA,MAAW,SAAS,SAAW,EAAA;AAC7B,IAAA,IAAI,CAAC,QAAA,CAAS,GAAI,CAAA,KAAK,CAAG,EAAA;AACxB,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAAA,GACF;AACA,EAAO,OAAA,IAAA,CAAA;AACT,CAAA;A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+
function showLoginPopup(options) {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
const width = options.width || 500;
|
|
4
|
+
const height = options.height || 700;
|
|
5
|
+
const left = window.screen.width / 2 - width / 2;
|
|
6
|
+
const top = window.screen.height / 2 - height / 2;
|
|
7
|
+
const popup = window.open(
|
|
8
|
+
options.url,
|
|
9
|
+
options.name,
|
|
10
|
+
`menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=${width},height=${height},top=${top},left=${left}`
|
|
11
|
+
);
|
|
12
|
+
let targetOrigin = "";
|
|
13
|
+
if (!popup || typeof popup.closed === "undefined" || popup.closed) {
|
|
14
|
+
const error = new Error("Failed to open auth popup.");
|
|
15
|
+
error.name = "PopupRejectedError";
|
|
16
|
+
reject(error);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const messageListener = (event) => {
|
|
20
|
+
if (event.source !== popup) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (event.origin !== options.origin) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const { data } = event;
|
|
27
|
+
if (data.type === "config_info") {
|
|
28
|
+
targetOrigin = data.targetOrigin;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (data.type !== "authorization_response") {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const authResult = data;
|
|
35
|
+
if ("error" in authResult) {
|
|
36
|
+
const error = new Error(authResult.error.message);
|
|
37
|
+
error.name = authResult.error.name;
|
|
38
|
+
reject(error);
|
|
39
|
+
} else {
|
|
40
|
+
resolve(authResult.response);
|
|
41
|
+
}
|
|
42
|
+
done();
|
|
43
|
+
};
|
|
44
|
+
const intervalId = setInterval(() => {
|
|
45
|
+
if (popup.closed) {
|
|
46
|
+
const errMessage = `Login failed, ${targetOrigin && targetOrigin !== window.location.origin ? `Incorrect app origin, expected ${targetOrigin}` : "popup was closed"}`;
|
|
47
|
+
const error = new Error(errMessage);
|
|
48
|
+
error.name = "PopupClosedError";
|
|
49
|
+
reject(error);
|
|
50
|
+
done();
|
|
51
|
+
}
|
|
52
|
+
}, 100);
|
|
53
|
+
function done() {
|
|
54
|
+
window.removeEventListener("message", messageListener);
|
|
55
|
+
clearInterval(intervalId);
|
|
56
|
+
}
|
|
57
|
+
window.addEventListener("message", messageListener);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { showLoginPopup };
|
|
62
|
+
//# sourceMappingURL=loginPopup.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loginPopup.esm.js","sources":["../../../../../../../packages/core-app-api/src/lib/loginPopup.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Options used to open a login popup.\n */\nexport type LoginPopupOptions = {\n /**\n * The URL that the auth popup should point to\n */\n url: string;\n\n /**\n * The name of the popup, as in second argument to window.open\n */\n name: string;\n\n /**\n * The origin of the final popup page that will post a message to this window.\n */\n origin: string;\n\n /**\n * The width of the popup in pixels, defaults to 500\n */\n width?: number;\n\n /**\n * The height of the popup in pixels, defaults to 700\n */\n height?: number;\n};\n\ntype AuthResult =\n | {\n type: 'authorization_response';\n response: unknown;\n }\n | {\n type: 'authorization_response';\n error: {\n name: string;\n message: string;\n };\n };\n\n/**\n * Show a popup pointing to a URL that starts an auth flow. Implementing the receiving\n * end of the postMessage mechanism outlined in https://tools.ietf.org/html/draft-sakimura-oauth-wmrm-00\n *\n * The redirect handler of the flow should use postMessage to communicate back\n * to the app window. The message posted to the app must match the AuthResult type.\n *\n * The returned promise resolves to the response of the message that was posted from the auth popup.\n */\nexport function showLoginPopup(options: LoginPopupOptions): Promise<any> {\n return new Promise((resolve, reject) => {\n const width = options.width || 500;\n const height = options.height || 700;\n const left = window.screen.width / 2 - width / 2;\n const top = window.screen.height / 2 - height / 2;\n\n const popup = window.open(\n options.url,\n options.name,\n `menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=${width},height=${height},top=${top},left=${left}`,\n );\n\n let targetOrigin = '';\n\n if (!popup || typeof popup.closed === 'undefined' || popup.closed) {\n const error = new Error('Failed to open auth popup.');\n error.name = 'PopupRejectedError';\n reject(error);\n return;\n }\n\n const messageListener = (event: MessageEvent) => {\n if (event.source !== popup) {\n return;\n }\n if (event.origin !== options.origin) {\n return;\n }\n const { data } = event;\n\n if (data.type === 'config_info') {\n targetOrigin = data.targetOrigin;\n return;\n }\n\n if (data.type !== 'authorization_response') {\n return;\n }\n const authResult = data as AuthResult;\n\n if ('error' in authResult) {\n const error = new Error(authResult.error.message);\n error.name = authResult.error.name;\n // TODO: proper error type\n // error.extra = authResult.error.extra;\n reject(error);\n } else {\n resolve(authResult.response);\n }\n done();\n };\n\n const intervalId = setInterval(() => {\n if (popup.closed) {\n const errMessage = `Login failed, ${\n targetOrigin && targetOrigin !== window.location.origin\n ? `Incorrect app origin, expected ${targetOrigin}`\n : 'popup was closed'\n }`;\n const error = new Error(errMessage);\n error.name = 'PopupClosedError';\n reject(error);\n done();\n }\n }, 100);\n\n function done() {\n window.removeEventListener('message', messageListener);\n clearInterval(intervalId);\n }\n\n window.addEventListener('message', messageListener);\n });\n}\n"],"names":[],"mappings":"AAoEO,SAAS,eAAe,OAA0C,EAAA;AACvE,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAW,KAAA;AACtC,IAAM,MAAA,KAAA,GAAQ,QAAQ,KAAS,IAAA,GAAA,CAAA;AAC/B,IAAM,MAAA,MAAA,GAAS,QAAQ,MAAU,IAAA,GAAA,CAAA;AACjC,IAA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
+
terminatingError;
|
|
6
|
+
observable = new ObservableImpl((subscriber) => {
|
|
7
|
+
if (this.isClosed) {
|
|
8
|
+
if (this.terminatingError) {
|
|
9
|
+
subscriber.error(this.terminatingError);
|
|
10
|
+
} else {
|
|
11
|
+
subscriber.complete();
|
|
12
|
+
}
|
|
13
|
+
return () => {
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
this.subscribers.add(subscriber);
|
|
17
|
+
return () => {
|
|
18
|
+
this.subscribers.delete(subscriber);
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
22
|
+
[Symbol.observable]() {
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
get closed() {
|
|
26
|
+
return this.isClosed;
|
|
27
|
+
}
|
|
28
|
+
next(value) {
|
|
29
|
+
if (this.isClosed) {
|
|
30
|
+
throw new Error("PublishSubject is closed");
|
|
31
|
+
}
|
|
32
|
+
this.subscribers.forEach((subscriber) => subscriber.next(value));
|
|
33
|
+
}
|
|
34
|
+
error(error) {
|
|
35
|
+
if (this.isClosed) {
|
|
36
|
+
throw new Error("PublishSubject is closed");
|
|
37
|
+
}
|
|
38
|
+
this.isClosed = true;
|
|
39
|
+
this.terminatingError = error;
|
|
40
|
+
this.subscribers.forEach((subscriber) => subscriber.error(error));
|
|
41
|
+
}
|
|
42
|
+
complete() {
|
|
43
|
+
if (this.isClosed) {
|
|
44
|
+
throw new Error("PublishSubject is closed");
|
|
45
|
+
}
|
|
46
|
+
this.isClosed = true;
|
|
47
|
+
this.subscribers.forEach((subscriber) => subscriber.complete());
|
|
48
|
+
}
|
|
49
|
+
subscribe(onNext, onError, onComplete) {
|
|
50
|
+
const observer = typeof onNext === "function" ? {
|
|
51
|
+
next: onNext,
|
|
52
|
+
error: onError,
|
|
53
|
+
complete: onComplete
|
|
54
|
+
} : onNext;
|
|
55
|
+
return this.observable.subscribe(observer);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
class BehaviorSubject {
|
|
59
|
+
isClosed;
|
|
60
|
+
currentValue;
|
|
61
|
+
terminatingError;
|
|
62
|
+
observable;
|
|
63
|
+
constructor(value) {
|
|
64
|
+
this.isClosed = false;
|
|
65
|
+
this.currentValue = value;
|
|
66
|
+
this.terminatingError = void 0;
|
|
67
|
+
this.observable = new ObservableImpl((subscriber) => {
|
|
68
|
+
if (this.isClosed) {
|
|
69
|
+
if (this.terminatingError) {
|
|
70
|
+
subscriber.error(this.terminatingError);
|
|
71
|
+
} else {
|
|
72
|
+
subscriber.complete();
|
|
73
|
+
}
|
|
74
|
+
return () => {
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
subscriber.next(this.currentValue);
|
|
78
|
+
this.subscribers.add(subscriber);
|
|
79
|
+
return () => {
|
|
80
|
+
this.subscribers.delete(subscriber);
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
85
|
+
[Symbol.observable]() {
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
get closed() {
|
|
89
|
+
return this.isClosed;
|
|
90
|
+
}
|
|
91
|
+
next(value) {
|
|
92
|
+
if (this.isClosed) {
|
|
93
|
+
throw new Error("BehaviorSubject is closed");
|
|
94
|
+
}
|
|
95
|
+
this.currentValue = value;
|
|
96
|
+
this.subscribers.forEach((subscriber) => subscriber.next(value));
|
|
97
|
+
}
|
|
98
|
+
error(error) {
|
|
99
|
+
if (this.isClosed) {
|
|
100
|
+
throw new Error("BehaviorSubject is closed");
|
|
101
|
+
}
|
|
102
|
+
this.isClosed = true;
|
|
103
|
+
this.terminatingError = error;
|
|
104
|
+
this.subscribers.forEach((subscriber) => subscriber.error(error));
|
|
105
|
+
}
|
|
106
|
+
complete() {
|
|
107
|
+
if (this.isClosed) {
|
|
108
|
+
throw new Error("BehaviorSubject is closed");
|
|
109
|
+
}
|
|
110
|
+
this.isClosed = true;
|
|
111
|
+
this.subscribers.forEach((subscriber) => subscriber.complete());
|
|
112
|
+
}
|
|
113
|
+
subscribe(onNext, onError, onComplete) {
|
|
114
|
+
const observer = typeof onNext === "function" ? {
|
|
115
|
+
next: onNext,
|
|
116
|
+
error: onError,
|
|
117
|
+
complete: onComplete
|
|
118
|
+
} : onNext;
|
|
119
|
+
return this.observable.subscribe(observer);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { BehaviorSubject, PublishSubject };
|
|
124
|
+
//# sourceMappingURL=subjects.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subjects.esm.js","sources":["../../../../../../../packages/core-app-api/src/lib/subjects.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Observable } from '@backstage/types';\nimport ObservableImpl from 'zen-observable';\n\n// TODO(Rugvip): These are stopgap and probably incomplete implementations of subjects.\n// If we add a more complete Observables library they should be replaced.\n\n/**\n * A basic implementation of ReactiveX publish subjects.\n *\n * A subject is a convenient way to create an observable when you want\n * to fan out a single value to all subscribers.\n *\n * See http://reactivex.io/documentation/subject.html\n */\nexport class PublishSubject<T>\n implements Observable<T>, ZenObservable.SubscriptionObserver<T>\n{\n private isClosed = false;\n private terminatingError?: Error;\n\n private readonly observable = new ObservableImpl<T>(subscriber => {\n if (this.isClosed) {\n if (this.terminatingError) {\n subscriber.error(this.terminatingError);\n } else {\n subscriber.complete();\n }\n return () => {};\n }\n\n this.subscribers.add(subscriber);\n return () => {\n this.subscribers.delete(subscriber);\n };\n });\n\n private readonly subscribers = new Set<\n ZenObservable.SubscriptionObserver<T>\n >();\n\n [Symbol.observable]() {\n return this;\n }\n\n get closed() {\n return this.isClosed;\n }\n\n next(value: T) {\n if (this.isClosed) {\n throw new Error('PublishSubject is closed');\n }\n this.subscribers.forEach(subscriber => subscriber.next(value));\n }\n\n error(error: Error) {\n if (this.isClosed) {\n throw new Error('PublishSubject is closed');\n }\n this.isClosed = true;\n this.terminatingError = error;\n this.subscribers.forEach(subscriber => subscriber.error(error));\n }\n\n complete() {\n if (this.isClosed) {\n throw new Error('PublishSubject is closed');\n }\n this.isClosed = true;\n this.subscribers.forEach(subscriber => subscriber.complete());\n }\n\n subscribe(observer: ZenObservable.Observer<T>): ZenObservable.Subscription;\n subscribe(\n onNext: (value: T) => void,\n onError?: (error: any) => void,\n onComplete?: () => void,\n ): ZenObservable.Subscription;\n subscribe(\n onNext: ZenObservable.Observer<T> | ((value: T) => void),\n onError?: (error: any) => void,\n onComplete?: () => void,\n ): ZenObservable.Subscription {\n const observer =\n typeof onNext === 'function'\n ? {\n next: onNext,\n error: onError,\n complete: onComplete,\n }\n : onNext;\n\n return this.observable.subscribe(observer);\n }\n}\n\n/**\n * A basic implementation of ReactiveX behavior subjects.\n *\n * A subject is a convenient way to create an observable when you want\n * to fan out a single value to all subscribers.\n *\n * The BehaviorSubject will emit the most recently emitted value or error\n * whenever a new observer subscribes to the subject.\n *\n * See http://reactivex.io/documentation/subject.html\n */\n\nexport class BehaviorSubject<T>\n implements Observable<T>, ZenObservable.SubscriptionObserver<T>\n{\n private isClosed: boolean;\n private currentValue: T;\n private terminatingError: Error | undefined;\n private readonly observable: Observable<T>;\n\n constructor(value: T) {\n this.isClosed = false;\n this.currentValue = value;\n this.terminatingError = undefined;\n this.observable = new ObservableImpl<T>(subscriber => {\n if (this.isClosed) {\n if (this.terminatingError) {\n subscriber.error(this.terminatingError);\n } else {\n subscriber.complete();\n }\n return () => {};\n }\n\n subscriber.next(this.currentValue);\n\n this.subscribers.add(subscriber);\n return () => {\n this.subscribers.delete(subscriber);\n };\n });\n }\n\n private readonly subscribers = new Set<\n ZenObservable.SubscriptionObserver<T>\n >();\n\n [Symbol.observable]() {\n return this;\n }\n\n get closed() {\n return this.isClosed;\n }\n\n next(value: T) {\n if (this.isClosed) {\n throw new Error('BehaviorSubject is closed');\n }\n this.currentValue = value;\n this.subscribers.forEach(subscriber => subscriber.next(value));\n }\n\n error(error: Error) {\n if (this.isClosed) {\n throw new Error('BehaviorSubject is closed');\n }\n this.isClosed = true;\n this.terminatingError = error;\n this.subscribers.forEach(subscriber => subscriber.error(error));\n }\n\n complete() {\n if (this.isClosed) {\n throw new Error('BehaviorSubject is closed');\n }\n this.isClosed = true;\n this.subscribers.forEach(subscriber => subscriber.complete());\n }\n\n subscribe(observer: ZenObservable.Observer<T>): ZenObservable.Subscription;\n subscribe(\n onNext: (value: T) => void,\n onError?: (error: any) => void,\n onComplete?: () => void,\n ): ZenObservable.Subscription;\n subscribe(\n onNext: ZenObservable.Observer<T> | ((value: T) => void),\n onError?: (error: any) => void,\n onComplete?: () => void,\n ): ZenObservable.Subscription {\n const observer =\n typeof onNext === 'function'\n ? {\n next: onNext,\n error: onError,\n complete: onComplete,\n }\n : onNext;\n\n return this.observable.subscribe(observer);\n }\n}\n"],"names":[],"mappings":";;AA8BO,MAAM,cAEb,CAAA;AAAA,EACU,QAAW,GAAA,KAAA,CAAA;AAAA,EACX,gBAAA,CAAA;AAAA,EAES,UAAA,GAAa,IAAI,cAAA,CAAkB,CAAc,UAAA,KAAA;AAChE,IAAA,IAAI,KAAK,QAAU,EAAA;AACjB,MAAA,IAAI,KAAK,gBAAkB,EAAA;AACzB,QAAW,UAAA,CAAA,KAAA,CAAM,KAAK,gBAAgB,CAAA,CAAA;AAAA,OACjC,MAAA;AACL,QAAA,UAAA,CAAW,QAAS,EAAA,CAAA;AAAA,OACtB;AACA,MAAA,OAAO,MAAM;AAAA,OAAC,CAAA;AAAA,KAChB;AAEA,IAAK,IAAA,CAAA,WAAA,C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