@backstage/core-app-api 1.12.4 → 1.12.6-next.0
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 +44 -4
- package/dist/apis/implementations/AlertApi/AlertApiForwarder.esm.js +14 -0
- package/dist/apis/implementations/AlertApi/AlertApiForwarder.esm.js.map +1 -0
- package/dist/apis/implementations/AnalyticsApi/MultipleAnalyticsApi.esm.js +35 -0
- package/dist/apis/implementations/AnalyticsApi/MultipleAnalyticsApi.esm.js.map +1 -0
- package/dist/apis/implementations/AnalyticsApi/NoOpAnalyticsApi.esm.js +7 -0
- package/dist/apis/implementations/AnalyticsApi/NoOpAnalyticsApi.esm.js.map +1 -0
- package/dist/apis/implementations/AppLanguageApi/AppLanguageSelector.esm.js +89 -0
- package/dist/apis/implementations/AppLanguageApi/AppLanguageSelector.esm.js.map +1 -0
- package/dist/apis/implementations/AppThemeApi/AppThemeSelector.esm.js +48 -0
- package/dist/apis/implementations/AppThemeApi/AppThemeSelector.esm.js.map +1 -0
- package/dist/apis/implementations/DiscoveryApi/FrontendHostDiscovery.esm.js +52 -0
- package/dist/apis/implementations/DiscoveryApi/FrontendHostDiscovery.esm.js.map +1 -0
- package/dist/apis/implementations/DiscoveryApi/UrlPatternDiscovery.esm.js +39 -0
- package/dist/apis/implementations/DiscoveryApi/UrlPatternDiscovery.esm.js.map +1 -0
- package/dist/apis/implementations/ErrorApi/ErrorAlerter.esm.js +18 -0
- package/dist/apis/implementations/ErrorApi/ErrorAlerter.esm.js.map +1 -0
- package/dist/apis/implementations/ErrorApi/ErrorApiForwarder.esm.js +14 -0
- package/dist/apis/implementations/ErrorApi/ErrorApiForwarder.esm.js.map +1 -0
- package/dist/apis/implementations/ErrorApi/UnhandledErrorForwarder.esm.js +16 -0
- package/dist/apis/implementations/ErrorApi/UnhandledErrorForwarder.esm.js.map +1 -0
- package/dist/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.esm.js +76 -0
- package/dist/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.esm.js.map +1 -0
- package/dist/apis/implementations/FetchApi/FetchMiddlewares.esm.js +45 -0
- package/dist/apis/implementations/FetchApi/FetchMiddlewares.esm.js.map +1 -0
- package/dist/apis/implementations/FetchApi/IdentityAuthInjectorFetchMiddleware.esm.js +49 -0
- package/dist/apis/implementations/FetchApi/IdentityAuthInjectorFetchMiddleware.esm.js.map +1 -0
- package/dist/apis/implementations/FetchApi/PluginProtocolResolverFetchMiddleware.esm.js +40 -0
- package/dist/apis/implementations/FetchApi/PluginProtocolResolverFetchMiddleware.esm.js.map +1 -0
- package/dist/apis/implementations/FetchApi/createFetchApi.esm.js +13 -0
- package/dist/apis/implementations/FetchApi/createFetchApi.esm.js.map +1 -0
- package/dist/apis/implementations/IdentityApi/AppIdentityProxy.esm.js +101 -0
- package/dist/apis/implementations/IdentityApi/AppIdentityProxy.esm.js.map +1 -0
- package/dist/apis/implementations/IdentityApi/startCookieAuthRefresh.esm.js +105 -0
- package/dist/apis/implementations/IdentityApi/startCookieAuthRefresh.esm.js.map +1 -0
- package/dist/apis/implementations/OAuthRequestApi/OAuthPendingRequests.esm.js +71 -0
- package/dist/apis/implementations/OAuthRequestApi/OAuthPendingRequests.esm.js.map +1 -0
- package/dist/apis/implementations/OAuthRequestApi/OAuthRequestManager.esm.js +54 -0
- package/dist/apis/implementations/OAuthRequestApi/OAuthRequestManager.esm.js.map +1 -0
- package/dist/apis/implementations/StorageApi/WebStorage.esm.js +96 -0
- package/dist/apis/implementations/StorageApi/WebStorage.esm.js.map +1 -0
- package/dist/apis/implementations/TranslationApi/I18nextTranslationApi.esm.js +234 -0
- package/dist/apis/implementations/TranslationApi/I18nextTranslationApi.esm.js.map +1 -0
- package/dist/apis/implementations/auth/atlassian/AtlassianAuth.esm.js +28 -0
- package/dist/apis/implementations/auth/atlassian/AtlassianAuth.esm.js.map +1 -0
- package/dist/apis/implementations/auth/bitbucket/BitbucketAuth.esm.js +30 -0
- package/dist/apis/implementations/auth/bitbucket/BitbucketAuth.esm.js.map +1 -0
- package/dist/apis/implementations/auth/bitbucketServer/BitbucketServerAuth.esm.js +30 -0
- package/dist/apis/implementations/auth/bitbucketServer/BitbucketServerAuth.esm.js.map +1 -0
- package/dist/apis/implementations/auth/github/GithubAuth.esm.js +30 -0
- package/dist/apis/implementations/auth/github/GithubAuth.esm.js.map +1 -0
- package/dist/apis/implementations/auth/gitlab/GitlabAuth.esm.js +30 -0
- package/dist/apis/implementations/auth/gitlab/GitlabAuth.esm.js.map +1 -0
- package/dist/apis/implementations/auth/google/GoogleAuth.esm.js +49 -0
- package/dist/apis/implementations/auth/google/GoogleAuth.esm.js.map +1 -0
- package/dist/apis/implementations/auth/microsoft/MicrosoftAuth.esm.js +130 -0
- package/dist/apis/implementations/auth/microsoft/MicrosoftAuth.esm.js.map +1 -0
- package/dist/apis/implementations/auth/oauth2/OAuth2.esm.js +127 -0
- package/dist/apis/implementations/auth/oauth2/OAuth2.esm.js.map +1 -0
- package/dist/apis/implementations/auth/okta/OktaAuth.esm.js +51 -0
- package/dist/apis/implementations/auth/okta/OktaAuth.esm.js.map +1 -0
- package/dist/apis/implementations/auth/onelogin/OneLoginAuth.esm.js +50 -0
- package/dist/apis/implementations/auth/onelogin/OneLoginAuth.esm.js.map +1 -0
- package/dist/apis/implementations/auth/saml/SamlAuth.esm.js +58 -0
- package/dist/apis/implementations/auth/saml/SamlAuth.esm.js.map +1 -0
- package/dist/apis/implementations/auth/saml/types.esm.js +20 -0
- package/dist/apis/implementations/auth/saml/types.esm.js.map +1 -0
- package/dist/apis/implementations/auth/vmwareCloud/VMwareCloudAuth.esm.js +30 -0
- package/dist/apis/implementations/auth/vmwareCloud/VMwareCloudAuth.esm.js.map +1 -0
- package/dist/apis/system/ApiAggregator.esm.js +18 -0
- package/dist/apis/system/ApiAggregator.esm.js.map +1 -0
- package/dist/apis/system/ApiFactoryRegistry.esm.js +42 -0
- package/dist/apis/system/ApiFactoryRegistry.esm.js.map +1 -0
- package/dist/apis/system/ApiProvider.esm.js +25 -0
- package/dist/apis/system/ApiProvider.esm.js.map +1 -0
- package/dist/apis/system/ApiRegistry.esm.js +50 -0
- package/dist/apis/system/ApiRegistry.esm.js.map +1 -0
- package/dist/apis/system/ApiResolver.esm.js +71 -0
- package/dist/apis/system/ApiResolver.esm.js.map +1 -0
- package/dist/app/AppContext.esm.js +14 -0
- package/dist/app/AppContext.esm.js.map +1 -0
- package/dist/app/AppManager.esm.js +367 -0
- package/dist/app/AppManager.esm.js.map +1 -0
- package/dist/app/AppRouter.esm.js +100 -0
- package/dist/app/AppRouter.esm.js.map +1 -0
- package/dist/app/AppThemeProvider.esm.js +60 -0
- package/dist/app/AppThemeProvider.esm.js.map +1 -0
- package/dist/app/InternalAppContext.esm.js +6 -0
- package/dist/app/InternalAppContext.esm.js.map +1 -0
- package/dist/app/createSpecializedApp.esm.js +8 -0
- package/dist/app/createSpecializedApp.esm.js.map +1 -0
- package/dist/app/defaultConfigLoader.esm.js +34 -0
- package/dist/app/defaultConfigLoader.esm.js.map +1 -0
- package/dist/app/isProtectedApp.esm.js +8 -0
- package/dist/app/isProtectedApp.esm.js.map +1 -0
- package/dist/app/isReactRouterBeta.esm.js +10 -0
- package/dist/app/isReactRouterBeta.esm.js.map +1 -0
- package/dist/app/overrideBaseUrlConfigs.esm.js +50 -0
- package/dist/app/overrideBaseUrlConfigs.esm.js.map +1 -0
- package/dist/app/resolveRouteBindings.esm.js +85 -0
- package/dist/app/resolveRouteBindings.esm.js.map +1 -0
- package/dist/core-plugin-api/src/translation/TranslationRef.esm.js +13 -0
- package/dist/core-plugin-api/src/translation/TranslationRef.esm.js.map +1 -0
- package/dist/core-plugin-api/src/translation/TranslationResource.esm.js +13 -0
- package/dist/core-plugin-api/src/translation/TranslationResource.esm.js.map +1 -0
- package/dist/extensions/traversal.esm.js +65 -0
- package/dist/extensions/traversal.esm.js.map +1 -0
- package/dist/index.esm.js +34 -4226
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/AuthConnector/DefaultAuthConnector.esm.js +164 -0
- package/dist/lib/AuthConnector/DefaultAuthConnector.esm.js.map +1 -0
- package/dist/lib/AuthConnector/DirectAuthConnector.esm.js +52 -0
- package/dist/lib/AuthConnector/DirectAuthConnector.esm.js.map +1 -0
- package/dist/lib/AuthSessionManager/AuthSessionStore.esm.js +105 -0
- package/dist/lib/AuthSessionManager/AuthSessionStore.esm.js.map +1 -0
- package/dist/lib/AuthSessionManager/RefreshingAuthSessionManager.esm.js +91 -0
- package/dist/lib/AuthSessionManager/RefreshingAuthSessionManager.esm.js.map +1 -0
- package/dist/lib/AuthSessionManager/SessionStateTracker.esm.js +23 -0
- package/dist/lib/AuthSessionManager/SessionStateTracker.esm.js.map +1 -0
- package/dist/lib/AuthSessionManager/StaticAuthSessionManager.esm.js +48 -0
- package/dist/lib/AuthSessionManager/StaticAuthSessionManager.esm.js.map +1 -0
- package/dist/lib/AuthSessionManager/common.esm.js +44 -0
- package/dist/lib/AuthSessionManager/common.esm.js.map +1 -0
- package/dist/lib/loginPopup.esm.js +62 -0
- package/dist/lib/loginPopup.esm.js.map +1 -0
- package/dist/lib/subjects.esm.js +124 -0
- package/dist/lib/subjects.esm.js.map +1 -0
- package/dist/plugins/collectors.esm.js +15 -0
- package/dist/plugins/collectors.esm.js.map +1 -0
- package/dist/routing/FeatureFlagged.esm.js +13 -0
- package/dist/routing/FeatureFlagged.esm.js.map +1 -0
- package/dist/routing/FlatRoutes.esm.js +59 -0
- package/dist/routing/FlatRoutes.esm.js.map +1 -0
- package/dist/routing/RouteResolver.esm.js +135 -0
- package/dist/routing/RouteResolver.esm.js.map +1 -0
- package/dist/routing/RouteTracker.esm.js +77 -0
- package/dist/routing/RouteTracker.esm.js.map +1 -0
- package/dist/routing/RoutingProvider.esm.js +28 -0
- package/dist/routing/RoutingProvider.esm.js.map +1 -0
- package/dist/routing/collectors.esm.js +265 -0
- package/dist/routing/collectors.esm.js.map +1 -0
- package/dist/routing/helpers.esm.js +10 -0
- package/dist/routing/helpers.esm.js.map +1 -0
- package/dist/routing/types.esm.js +18 -0
- package/dist/routing/types.esm.js.map +1 -0
- package/dist/routing/validation.esm.js +55 -0
- package/dist/routing/validation.esm.js.map +1 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# @backstage/core-app-api
|
|
2
2
|
|
|
3
|
+
## 1.12.6-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 35fbe09: Added support for configuration of route bindings through static configuration, and default targets for external route refs.
|
|
8
|
+
|
|
9
|
+
In addition to configuring route bindings through code, it is now also possible to configure route bindings under the `app.routes.bindings` key, for example:
|
|
10
|
+
|
|
11
|
+
```yaml
|
|
12
|
+
app:
|
|
13
|
+
routes:
|
|
14
|
+
bindings:
|
|
15
|
+
catalog.createComponent: catalog-import.importPage
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Each key in the route binding object is of the form `<plugin-id>.<externalRouteName>`, where the route name is key used in the `externalRoutes` object passed to `createPlugin`. The value is of the same form, but with the name taken from the plugin `routes` option instead.
|
|
19
|
+
|
|
20
|
+
The equivalent of the above configuration in code is the following:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
const app = createApp({
|
|
24
|
+
// ...
|
|
25
|
+
bindRoutes({ bind }) {
|
|
26
|
+
bind(catalogPlugin.externalRoutes, {
|
|
27
|
+
createComponent: catalogImportPlugin.routes.importPage,
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- Updated dependencies
|
|
34
|
+
- @backstage/core-plugin-api@1.9.3-next.0
|
|
35
|
+
- @backstage/config@1.2.0
|
|
36
|
+
- @backstage/types@1.1.1
|
|
37
|
+
- @backstage/version-bridge@1.0.8
|
|
38
|
+
|
|
39
|
+
## 1.12.5
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- 1bed9a3: The Backstage identity session expiration check will no longer fall back to using the provider expiration. This was introduced to smooth out the rollout of Backstage release 1.18, and is no longer needed.
|
|
44
|
+
|
|
3
45
|
## 1.12.4
|
|
4
46
|
|
|
5
47
|
### Patch Changes
|
|
@@ -539,8 +581,7 @@
|
|
|
539
581
|
|
|
540
582
|
This change makes the dependence explicit, and removes the burden on
|
|
541
583
|
OAuth2-based providers which require an ID token (e.g. this is done by various
|
|
542
|
-
default [auth
|
|
543
|
-
handlers](https://backstage.io/docs/auth/identity-resolver/#authhandler)) to add
|
|
584
|
+
default [auth handlers](https://backstage.io/docs/auth/identity-resolver/#authhandler)) to add
|
|
544
585
|
`openid` to their default scopes. _That_ could carry another indirect benefit:
|
|
545
586
|
by removing `openid` from the default scopes for a provider, grants for
|
|
546
587
|
resource-specific access tokens can avoid requesting excess ID token-related
|
|
@@ -568,8 +609,7 @@
|
|
|
568
609
|
|
|
569
610
|
This change makes the dependence explicit, and removes the burden on
|
|
570
611
|
OAuth2-based providers which require an ID token (e.g. this is done by various
|
|
571
|
-
default [auth
|
|
572
|
-
handlers](https://backstage.io/docs/auth/identity-resolver/#authhandler)) to add
|
|
612
|
+
default [auth handlers](https://backstage.io/docs/auth/identity-resolver/#authhandler)) to add
|
|
573
613
|
`openid` to their default scopes. _That_ could carry another indirect benefit:
|
|
574
614
|
by removing `openid` from the default scopes for a provider, grants for
|
|
575
615
|
resource-specific access tokens can avoid requesting excess ID token-related
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PublishSubject } from '../../../lib/subjects.esm.js';
|
|
2
|
+
|
|
3
|
+
class AlertApiForwarder {
|
|
4
|
+
subject = new PublishSubject();
|
|
5
|
+
post(alert) {
|
|
6
|
+
this.subject.next(alert);
|
|
7
|
+
}
|
|
8
|
+
alert$() {
|
|
9
|
+
return this.subject;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { AlertApiForwarder };
|
|
14
|
+
//# sourceMappingURL=AlertApiForwarder.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlertApiForwarder.esm.js","sources":["../../../../src/apis/implementations/AlertApi/AlertApiForwarder.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 { AlertApi, AlertMessage } from '@backstage/core-plugin-api';\nimport { Observable } from '@backstage/types';\nimport { PublishSubject } from '../../../lib/subjects';\n\n/**\n * Base implementation for the AlertApi that simply forwards alerts to consumers.\n *\n * @public\n */\nexport class AlertApiForwarder implements AlertApi {\n private readonly subject = new PublishSubject<AlertMessage>();\n\n post(alert: AlertMessage) {\n this.subject.next(alert);\n }\n\n alert$(): Observable<AlertMessage> {\n return this.subject;\n }\n}\n"],"names":[],"mappings":";;AAyBO,MAAM,iBAAsC,CAAA;AAAA,EAChC,OAAA,GAAU,IAAI,cAA6B,EAAA,CAAA;AAAA,EAE5D,KAAK,KAAqB,EAAA;AACxB,IAAK,IAAA,CAAA,OAAA,CAAQ,KAAK,KAAK,CAAA,CAAA;AAAA,GACzB;AAAA,EAEA,MAAmC,GAAA;AACjC,IAAA,OAAO,IAAK,CAAA,OAAA,CAAA;AAAA,GACd;AACF;;;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class MultipleAnalyticsApi {
|
|
2
|
+
constructor(actualApis) {
|
|
3
|
+
this.actualApis = actualApis;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Create an AnalyticsApi implementation from an array of concrete
|
|
7
|
+
* implementations.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* ```jsx
|
|
12
|
+
* MultipleAnalyticsApi.fromApis([
|
|
13
|
+
* SomeAnalyticsApi.fromConfig(configApi),
|
|
14
|
+
* new CustomAnalyticsApi(),
|
|
15
|
+
* ]);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
static fromApis(actualApis) {
|
|
19
|
+
return new MultipleAnalyticsApi(actualApis);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Forward the event to all configured analytics API implementations.
|
|
23
|
+
*/
|
|
24
|
+
captureEvent(event) {
|
|
25
|
+
this.actualApis.forEach((analyticsApi) => {
|
|
26
|
+
try {
|
|
27
|
+
analyticsApi.captureEvent(event);
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { MultipleAnalyticsApi };
|
|
35
|
+
//# sourceMappingURL=MultipleAnalyticsApi.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultipleAnalyticsApi.esm.js","sources":["../../../../src/apis/implementations/AnalyticsApi/MultipleAnalyticsApi.ts"],"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 */\nimport { AnalyticsApi, AnalyticsEvent } from '@backstage/core-plugin-api';\n\n/**\n * An implementation of the AnalyticsApi that can be used to forward analytics\n * events to multiple concrete implementations.\n *\n * @public\n *\n * @example\n *\n * ```jsx\n * createApiFactory({\n * api: analyticsApiRef,\n * deps: { configApi: configApiRef, identityApi: identityApiRef, storageApi: storageApiRef },\n * factory: ({ configApi, identityApi, storageApi }) =>\n * MultipleAnalyticsApi.fromApis([\n * VendorAnalyticsApi.fromConfig(configApi, { identityApi }),\n * CustomAnalyticsApi.fromConfig(configApi, { identityApi, storageApi }),\n * ]),\n * });\n * ```\n */\nexport class MultipleAnalyticsApi implements AnalyticsApi {\n private constructor(private readonly actualApis: AnalyticsApi[]) {}\n\n /**\n * Create an AnalyticsApi implementation from an array of concrete\n * implementations.\n *\n * @example\n *\n * ```jsx\n * MultipleAnalyticsApi.fromApis([\n * SomeAnalyticsApi.fromConfig(configApi),\n * new CustomAnalyticsApi(),\n * ]);\n * ```\n */\n static fromApis(actualApis: AnalyticsApi[]) {\n return new MultipleAnalyticsApi(actualApis);\n }\n\n /**\n * Forward the event to all configured analytics API implementations.\n */\n captureEvent(event: AnalyticsEvent): void {\n this.actualApis.forEach(analyticsApi => {\n try {\n analyticsApi.captureEvent(event);\n } catch {\n /* ignored */\n }\n });\n }\n}\n"],"names":[],"mappings":"AAqCO,MAAM,oBAA6C,CAAA;AAAA,EAChD,YAA6B,UAA4B,EAAA;AAA5B,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA,CAAA;AAAA,GAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAelE,OAAO,SAAS,UAA4B,EAAA;AAC1C,IAAO,OAAA,IAAI,qBAAqB,UAAU,CAAA,CAAA;AAAA,GAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,KAA6B,EAAA;AACxC,IAAK,IAAA,CAAA,UAAA,CAAW,QAAQ,CAAgB,YAAA,KAAA;AACtC,MAAI,IAAA;AACF,QAAA,YAAA,CAAa,aAAa,KAAK,CAAA,CAAA;AAAA,OACzB,CAAA,MAAA;AAAA,OAER;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NoOpAnalyticsApi.esm.js","sources":["../../../../src/apis/implementations/AnalyticsApi/NoOpAnalyticsApi.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { AnalyticsApi, AnalyticsEvent } from '@backstage/core-plugin-api';\n\n/**\n * Base implementation for the AnalyticsApi that does nothing.\n *\n * @public\n */\nexport class NoOpAnalyticsApi implements AnalyticsApi {\n captureEvent(_event: AnalyticsEvent): void {}\n}\n"],"names":[],"mappings":"AAsBO,MAAM,gBAAyC,CAAA;AAAA,EACpD,aAAa,MAA8B,EAAA;AAAA,GAAC;AAC9C;;;;"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BehaviorSubject } from '../../../lib/subjects.esm.js';
|
|
2
|
+
import '@backstage/core-plugin-api';
|
|
3
|
+
|
|
4
|
+
const STORAGE_KEY = "language";
|
|
5
|
+
const DEFAULT_LANGUAGE = "en";
|
|
6
|
+
class AppLanguageSelector {
|
|
7
|
+
static create(options) {
|
|
8
|
+
const languages = options?.availableLanguages ?? [DEFAULT_LANGUAGE];
|
|
9
|
+
if (languages.length !== new Set(languages).size) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`Supported languages may not contain duplicates, got '${languages.join(
|
|
12
|
+
"', '"
|
|
13
|
+
)}'`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
if (!languages.includes(DEFAULT_LANGUAGE)) {
|
|
17
|
+
throw new Error(`Supported languages must include '${DEFAULT_LANGUAGE}'`);
|
|
18
|
+
}
|
|
19
|
+
const initialLanguage = options?.defaultLanguage ?? DEFAULT_LANGUAGE;
|
|
20
|
+
if (!languages.includes(initialLanguage)) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`Initial language must be one of the supported languages, got '${initialLanguage}'`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return new AppLanguageSelector(languages, initialLanguage);
|
|
26
|
+
}
|
|
27
|
+
static createWithStorage(options) {
|
|
28
|
+
const selector = AppLanguageSelector.create(options);
|
|
29
|
+
if (!window.localStorage) {
|
|
30
|
+
return selector;
|
|
31
|
+
}
|
|
32
|
+
const storedLanguage = window.localStorage.getItem(STORAGE_KEY);
|
|
33
|
+
const { languages } = selector.getAvailableLanguages();
|
|
34
|
+
if (storedLanguage && languages.includes(storedLanguage)) {
|
|
35
|
+
selector.setLanguage(storedLanguage);
|
|
36
|
+
}
|
|
37
|
+
selector.language$().subscribe(({ language }) => {
|
|
38
|
+
if (language !== window.localStorage.getItem(STORAGE_KEY)) {
|
|
39
|
+
window.localStorage.setItem(STORAGE_KEY, language);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
window.addEventListener("storage", (event) => {
|
|
43
|
+
if (event.key === STORAGE_KEY) {
|
|
44
|
+
const language = localStorage.getItem(STORAGE_KEY) ?? void 0;
|
|
45
|
+
if (language) {
|
|
46
|
+
selector.setLanguage(language);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return selector;
|
|
51
|
+
}
|
|
52
|
+
#languages;
|
|
53
|
+
#language;
|
|
54
|
+
#subject;
|
|
55
|
+
constructor(languages, initialLanguage) {
|
|
56
|
+
this.#languages = languages;
|
|
57
|
+
this.#language = initialLanguage;
|
|
58
|
+
this.#subject = new BehaviorSubject({
|
|
59
|
+
language: this.#language
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
getAvailableLanguages() {
|
|
63
|
+
return { languages: this.#languages.slice() };
|
|
64
|
+
}
|
|
65
|
+
setLanguage(language) {
|
|
66
|
+
const lng = language ?? DEFAULT_LANGUAGE;
|
|
67
|
+
if (lng === this.#language) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (lng && !this.#languages.includes(lng)) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Failed to change language to '${lng}', available languages are '${this.#languages.join(
|
|
73
|
+
"', '"
|
|
74
|
+
)}'`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
this.#language = lng;
|
|
78
|
+
this.#subject.next({ language: lng });
|
|
79
|
+
}
|
|
80
|
+
getLanguage() {
|
|
81
|
+
return { language: this.#language };
|
|
82
|
+
}
|
|
83
|
+
language$() {
|
|
84
|
+
return this.#subject;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { AppLanguageSelector, DEFAULT_LANGUAGE };
|
|
89
|
+
//# sourceMappingURL=AppLanguageSelector.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppLanguageSelector.esm.js","sources":["../../../../src/apis/implementations/AppLanguageApi/AppLanguageSelector.ts"],"sourcesContent":["/*\n * Copyright 2023 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// Internal import to avoid code duplication, this will lead to duplication in build output\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { AppLanguageApi } from '@backstage/core-plugin-api/alpha';\nimport { Observable } from '@backstage/types';\nimport { BehaviorSubject } from '../../../lib';\n\nconst STORAGE_KEY = 'language';\nexport const DEFAULT_LANGUAGE = 'en';\n\n/** @alpha */\nexport interface AppLanguageSelectorOptions {\n defaultLanguage?: string;\n availableLanguages?: string[];\n}\n\n/**\n * Exposes the available languages in the app and allows for switching of the active language.\n *\n * @alpha\n */\nexport class AppLanguageSelector implements AppLanguageApi {\n static create(options?: AppLanguageSelectorOptions) {\n const languages = options?.availableLanguages ?? [DEFAULT_LANGUAGE];\n if (languages.length !== new Set(languages).size) {\n throw new Error(\n `Supported languages may not contain duplicates, got '${languages.join(\n \"', '\",\n )}'`,\n );\n }\n if (!languages.includes(DEFAULT_LANGUAGE)) {\n throw new Error(`Supported languages must include '${DEFAULT_LANGUAGE}'`);\n }\n\n const initialLanguage = options?.defaultLanguage ?? DEFAULT_LANGUAGE;\n if (!languages.includes(initialLanguage)) {\n throw new Error(\n `Initial language must be one of the supported languages, got '${initialLanguage}'`,\n );\n }\n\n return new AppLanguageSelector(languages, initialLanguage);\n }\n\n static createWithStorage(options?: AppLanguageSelectorOptions) {\n const selector = AppLanguageSelector.create(options);\n\n if (!window.localStorage) {\n return selector;\n }\n\n const storedLanguage = window.localStorage.getItem(STORAGE_KEY);\n const { languages } = selector.getAvailableLanguages();\n if (storedLanguage && languages.includes(storedLanguage)) {\n selector.setLanguage(storedLanguage);\n }\n\n selector.language$().subscribe(({ language }) => {\n if (language !== window.localStorage.getItem(STORAGE_KEY)) {\n window.localStorage.setItem(STORAGE_KEY, language);\n }\n });\n\n window.addEventListener('storage', event => {\n if (event.key === STORAGE_KEY) {\n const language = localStorage.getItem(STORAGE_KEY) ?? undefined;\n if (language) {\n selector.setLanguage(language);\n }\n }\n });\n\n return selector;\n }\n\n #languages: string[];\n #language: string;\n #subject: BehaviorSubject<{ language: string }>;\n\n private constructor(languages: string[], initialLanguage: string) {\n this.#languages = languages;\n this.#language = initialLanguage;\n this.#subject = new BehaviorSubject<{ language: string }>({\n language: this.#language,\n });\n }\n\n getAvailableLanguages(): { languages: string[] } {\n return { languages: this.#languages.slice() };\n }\n\n setLanguage(language?: string | undefined): void {\n const lng = language ?? DEFAULT_LANGUAGE;\n if (lng === this.#language) {\n return;\n }\n if (lng && !this.#languages.includes(lng)) {\n throw new Error(\n `Failed to change language to '${lng}', available languages are '${this.#languages.join(\n \"', '\",\n )}'`,\n );\n }\n this.#language = lng;\n this.#subject.next({ language: lng });\n }\n\n getLanguage(): { language: string } {\n return { language: this.#language };\n }\n\n language$(): Observable<{ language: string }> {\n return this.#subject;\n }\n}\n"],"names":[],"mappings":";;;AAsBA,MAAM,WAAc,GAAA,UAAA,CAAA;AACb,MAAM,gBAAmB,GAAA,KAAA;AAazB,MAAM,mBAA8C,CAAA;AAAA,EACzD,OAAO,OAAO,OAAsC,EAAA;AAClD,IAAA,MAAM,SAAY,GAAA,OAAA,EAAS,kBAAsB,IAAA,CAAC,gBAAgB,CAAA,CAAA;AAClE,IAAA,IAAI,UAAU,MAAW,KAAA,IAAI,GAAI,CAAA,SAAS,EAAE,IAAM,EAAA;AAChD,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,wDAAwD,SAAU,CAAA,IAAA;AAAA,UAChE,MAAA;AAAA,SACD,CAAA,CAAA,CAAA;AAAA,OACH,CAAA;AAAA,KACF;AACA,IAAA,IAAI,CAAC,SAAA,CAAU,QAAS,CAAA,gBAAgB,CAAG,EAAA;AACzC,MAAA,MAAM,IAAI,KAAA,CAAM,CAAqC,kCAAA,EAAA,gBAAgB,CAAG,CAAA,CAAA,CAAA,CAAA;AAAA,KAC1E;AAEA,IAAM,MAAA,eAAA,GAAkB,SAAS,eAAmB,IAAA,gBAAA,CAAA;AACpD,IAAA,IAAI,CAAC,SAAA,CAAU,QAAS,CAAA,eAAe,CAAG,EAAA;AACxC,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,iEAAiE,eAAe,CAAA,CAAA,CAAA;AAAA,OAClF,CAAA;AAAA,KACF;AAEA,IAAO,OAAA,IAAI,mBAAoB,CAAA,SAAA,EAAW,eAAe,CAAA,CAAA;AAAA,GAC3D;AAAA,EAEA,OAAO,kBAAkB,OAAsC,EAAA;AAC7D,IAAM,MAAA,QAAA,GAAW,m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{
|
|
6
|
+
this.themes = themes;
|
|
7
|
+
}
|
|
8
|
+
static createWithStorage(themes) {
|
|
9
|
+
const selector = new AppThemeSelector(themes);
|
|
10
|
+
if (!window.localStorage) {
|
|
11
|
+
return selector;
|
|
12
|
+
}
|
|
13
|
+
const initialThemeId = window.localStorage.getItem(STORAGE_KEY) ?? void 0;
|
|
14
|
+
selector.setActiveThemeId(initialThemeId);
|
|
15
|
+
selector.activeThemeId$().subscribe((themeId) => {
|
|
16
|
+
if (themeId) {
|
|
17
|
+
window.localStorage.setItem(STORAGE_KEY, themeId);
|
|
18
|
+
} else {
|
|
19
|
+
window.localStorage.removeItem(STORAGE_KEY);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
window.addEventListener("storage", (event) => {
|
|
23
|
+
if (event.key === STORAGE_KEY) {
|
|
24
|
+
const themeId = localStorage.getItem(STORAGE_KEY) ?? void 0;
|
|
25
|
+
selector.setActiveThemeId(themeId);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return selector;
|
|
29
|
+
}
|
|
30
|
+
activeThemeId;
|
|
31
|
+
subject = new BehaviorSubject(void 0);
|
|
32
|
+
getInstalledThemes() {
|
|
33
|
+
return this.themes.slice();
|
|
34
|
+
}
|
|
35
|
+
activeThemeId$() {
|
|
36
|
+
return this.subject;
|
|
37
|
+
}
|
|
38
|
+
getActiveThemeId() {
|
|
39
|
+
return this.activeThemeId;
|
|
40
|
+
}
|
|
41
|
+
setActiveThemeId(themeId) {
|
|
42
|
+
this.activeThemeId = themeId;
|
|
43
|
+
this.subject.next(themeId);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { AppThemeSelector };
|
|
48
|
+
//# sourceMappingURL=AppThemeSelector.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppThemeSelector.esm.js","sources":["../../../../src/apis/implementations/AppThemeApi/AppThemeSelector.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 { AppThemeApi, AppTheme } from '@backstage/core-plugin-api';\nimport { Observable } from '@backstage/types';\nimport { BehaviorSubject } from '../../../lib/subjects';\n\nconst STORAGE_KEY = 'theme';\n\n/**\n * Exposes the themes installed in the app, and permits switching the currently\n * active theme.\n *\n * @public\n */\nexport class AppThemeSelector implements AppThemeApi {\n static createWithStorage(themes: AppTheme[]) {\n const selector = new AppThemeSelector(themes);\n\n if (!window.localStorage) {\n return selector;\n }\n\n const initialThemeId =\n window.localStorage.getItem(STORAGE_KEY) ?? undefined;\n\n selector.setActiveThemeId(initialThemeId);\n\n selector.activeThemeId$().subscribe(themeId => {\n if (themeId) {\n window.localStorage.setItem(STORAGE_KEY, themeId);\n } else {\n window.localStorage.removeItem(STORAGE_KEY);\n }\n });\n\n window.addEventListener('storage', event => {\n if (event.key === STORAGE_KEY) {\n const themeId = localStorage.getItem(STORAGE_KEY) ?? undefined;\n selector.setActiveThemeId(themeId);\n }\n });\n\n return selector;\n }\n\n private activeThemeId: string | undefined;\n private readonly subject = new BehaviorSubject<string | undefined>(undefined);\n\n constructor(private readonly themes: AppTheme[]) {}\n\n getInstalledThemes(): AppTheme[] {\n return this.themes.slice();\n }\n\n activeThemeId$(): Observable<string | undefined> {\n return this.subject;\n }\n\n getActiveThemeId(): string | undefined {\n return this.activeThemeId;\n }\n\n setActiveThemeId(themeId?: string): void {\n this.activeThemeId = themeId;\n this.subject.next(themeId);\n }\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,WAAc,GAAA,OAAA,CAAA;AAQb,MAAM,gBAAwC,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AO,KAAM,EAAA,CAAA;AAAA,GAC3B;AAAA,EAEA,cAAiD,GAAA;AAC/C,IAAA,OAAO,IAAK,CAAA,OAAA,CAAA;AAAA,GACd;AAAA,EAEA,gBAAuC,GAAA;AACrC,IAAA,OAAO,IAAK,CAAA,aAAA,CAAA;AAAA,GACd;AAAA,EAEA,iBAAiB,OAAwB,EAAA;AACvC,IAAA,IAAA,CAAK,aAAgB,GAAA,OAAA,CAAA;AACrB,IAAK,IAAA,CAAA,OAAA,CAAQ,KAAK,OAAO,CAAA,CAAA;AAAA,GAC3B;AACF;;;;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { UrlPatternDiscovery } from './UrlPatternDiscovery.esm.js';
|
|
2
|
+
|
|
3
|
+
class FrontendHostDiscovery {
|
|
4
|
+
constructor(endpoints, defaultEndpoint) {
|
|
5
|
+
this.endpoints = endpoints;
|
|
6
|
+
this.defaultEndpoint = defaultEndpoint;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new FrontendHostDiscovery discovery instance by reading
|
|
10
|
+
* the external target URL from the `discovery.endpoints` config section.
|
|
11
|
+
*
|
|
12
|
+
* eg.
|
|
13
|
+
* ```yaml
|
|
14
|
+
* discovery:
|
|
15
|
+
* endpoints:
|
|
16
|
+
* - target: https://internal.example.com/internal-catalog
|
|
17
|
+
* plugins: [catalog]
|
|
18
|
+
* - target: https://internal.example.com/secure/api/{{pluginId}}
|
|
19
|
+
* plugins: [auth, permissions]
|
|
20
|
+
* - target:
|
|
21
|
+
* internal: https://internal.example.com/search
|
|
22
|
+
* external: https://example.com/search
|
|
23
|
+
* plugins: [search]
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* If a plugin is not declared in the config, the discovery will fall back to using the baseUrl with
|
|
27
|
+
* the provided `pathPattern` appended. The default path pattern is `"/api/{{ pluginId }}"`.
|
|
28
|
+
*/
|
|
29
|
+
static fromConfig(config, options) {
|
|
30
|
+
const path = options?.pathPattern ?? "/api/{{ pluginId }}";
|
|
31
|
+
const baseUrl = config.getString("backend.baseUrl");
|
|
32
|
+
const endpoints = config.getOptionalConfigArray("discovery.endpoints")?.flatMap((e) => {
|
|
33
|
+
const target = typeof e.get("target") === "object" ? e.getString("target.external") : e.getString("target");
|
|
34
|
+
const discovery = UrlPatternDiscovery.compile(target);
|
|
35
|
+
return e.getStringArray("plugins").map((pluginId) => [pluginId, discovery]);
|
|
36
|
+
});
|
|
37
|
+
return new FrontendHostDiscovery(
|
|
38
|
+
new Map(endpoints),
|
|
39
|
+
UrlPatternDiscovery.compile(`${baseUrl}${path}`)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
async getBaseUrl(pluginId) {
|
|
43
|
+
const endpoint = this.endpoints.get(pluginId);
|
|
44
|
+
if (endpoint) {
|
|
45
|
+
return endpoint.getBaseUrl(pluginId);
|
|
46
|
+
}
|
|
47
|
+
return this.defaultEndpoint.getBaseUrl(pluginId);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { FrontendHostDiscovery };
|
|
52
|
+
//# sourceMappingURL=FrontendHostDiscovery.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FrontendHostDiscovery.esm.js","sources":["../../../../src/apis/implementations/DiscoveryApi/FrontendHostDiscovery.ts"],"sourcesContent":["/*\n * Copyright 2023 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 { Config } from '@backstage/config';\nimport { DiscoveryApi } from '@backstage/core-plugin-api';\nimport { UrlPatternDiscovery } from './UrlPatternDiscovery';\n\n/**\n * FrontendHostDiscovery is a config driven DiscoveryApi implementation.\n * It uses the app-config to determine the url for a plugin.\n *\n * @public\n */\nexport class FrontendHostDiscovery implements DiscoveryApi {\n /**\n * Creates a new FrontendHostDiscovery discovery instance by reading\n * the external target URL from the `discovery.endpoints` config section.\n *\n * eg.\n * ```yaml\n * discovery:\n * endpoints:\n * - target: https://internal.example.com/internal-catalog\n * plugins: [catalog]\n * - target: https://internal.example.com/secure/api/{{pluginId}}\n * plugins: [auth, permissions]\n * - target:\n * internal: https://internal.example.com/search\n * external: https://example.com/search\n * plugins: [search]\n * ```\n *\n * If a plugin is not declared in the config, the discovery will fall back to using the baseUrl with\n * the provided `pathPattern` appended. The default path pattern is `\"/api/{{ pluginId }}\"`.\n */\n static fromConfig(config: Config, options?: { pathPattern?: string }) {\n const path = options?.pathPattern ?? '/api/{{ pluginId }}';\n const baseUrl = config.getString('backend.baseUrl');\n\n const endpoints = config\n .getOptionalConfigArray('discovery.endpoints')\n ?.flatMap(e => {\n const target =\n typeof e.get('target') === 'object'\n ? e.getString('target.external')\n : e.getString('target');\n const discovery = UrlPatternDiscovery.compile(target);\n return e\n .getStringArray('plugins')\n .map(pluginId => [pluginId, discovery] as const);\n });\n\n return new FrontendHostDiscovery(\n new Map(endpoints),\n UrlPatternDiscovery.compile(`${baseUrl}${path}`),\n );\n }\n\n private constructor(\n private readonly endpoints: Map<string, DiscoveryApi>,\n private readonly defaultEndpoint: DiscoveryApi,\n ) {}\n\n async getBaseUrl(pluginId: string): Promise<string> {\n const endpoint = this.endpoints.get(pluginId);\n if (endpoint) {\n return endpoint.getBaseUrl(pluginId);\n }\n return this.defaultEndpoint.getBaseUrl(pluginId);\n }\n}\n"],"names":[],"mappings":";;AAyBO,MAAM,qBAA8C,CAAA;AAAA,EA6CjD,WAAA,CACW,WACA,eACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA,CAAA;AACA,IAAA,IAAA,CAAA,eAAA,GAAA,eAAA,CAAA;AAAA,G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AAA,IAAA,CAAK,eAAgB,CAAA,UAAA,CAAW,QAAQ,CAAA,CAAA;AAAA,GACjD;AACF;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const ERROR_PREFIX = "Invalid discovery URL pattern,";
|
|
2
|
+
class UrlPatternDiscovery {
|
|
3
|
+
constructor(parts) {
|
|
4
|
+
this.parts = parts;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new UrlPatternDiscovery given a template. The the only
|
|
8
|
+
* interpolation done for the template is to replace instances of `{{pluginId}}`
|
|
9
|
+
* with the ID of the plugin being requested.
|
|
10
|
+
*
|
|
11
|
+
* Example pattern: `http://localhost:7007/api/{{ pluginId }}`
|
|
12
|
+
*/
|
|
13
|
+
static compile(pattern) {
|
|
14
|
+
const parts = pattern.split(/\{\{\s*pluginId\s*\}\}/);
|
|
15
|
+
const urlStr = parts.join("pluginId");
|
|
16
|
+
let url;
|
|
17
|
+
try {
|
|
18
|
+
url = new URL(urlStr);
|
|
19
|
+
} catch {
|
|
20
|
+
throw new Error(`${ERROR_PREFIX} URL '${urlStr}' is invalid`);
|
|
21
|
+
}
|
|
22
|
+
if (url.hash) {
|
|
23
|
+
throw new Error(`${ERROR_PREFIX} URL must not have a hash`);
|
|
24
|
+
}
|
|
25
|
+
if (url.search) {
|
|
26
|
+
throw new Error(`${ERROR_PREFIX} URL must not have a query`);
|
|
27
|
+
}
|
|
28
|
+
if (urlStr.endsWith("/")) {
|
|
29
|
+
throw new Error(`${ERROR_PREFIX} URL must not end with a slash`);
|
|
30
|
+
}
|
|
31
|
+
return new UrlPatternDiscovery(parts);
|
|
32
|
+
}
|
|
33
|
+
async getBaseUrl(pluginId) {
|
|
34
|
+
return this.parts.join(encodeURIComponent(pluginId));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { UrlPatternDiscovery };
|
|
39
|
+
//# sourceMappingURL=UrlPatternDiscovery.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UrlPatternDiscovery.esm.js","sources":["../../../../src/apis/implementations/DiscoveryApi/UrlPatternDiscovery.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 { DiscoveryApi } from '@backstage/core-plugin-api';\n\nconst ERROR_PREFIX = 'Invalid discovery URL pattern,';\n\n/**\n * UrlPatternDiscovery is a lightweight DiscoveryApi implementation.\n * It uses a single template string to construct URLs for each plugin.\n *\n * @public\n */\nexport class UrlPatternDiscovery implements DiscoveryApi {\n /**\n * Creates a new UrlPatternDiscovery given a template. The the only\n * interpolation done for the template is to replace instances of `{{pluginId}}`\n * with the ID of the plugin being requested.\n *\n * Example pattern: `http://localhost:7007/api/{{ pluginId }}`\n */\n static compile(pattern: string): UrlPatternDiscovery {\n const parts = pattern.split(/\\{\\{\\s*pluginId\\s*\\}\\}/);\n const urlStr = parts.join('pluginId');\n\n let url;\n try {\n url = new URL(urlStr);\n } catch {\n throw new Error(`${ERROR_PREFIX} URL '${urlStr}' is invalid`);\n }\n if (url.hash) {\n throw new Error(`${ERROR_PREFIX} URL must not have a hash`);\n }\n if (url.search) {\n throw new Error(`${ERROR_PREFIX} URL must not have a query`);\n }\n if (urlStr.endsWith('/')) {\n throw new Error(`${ERROR_PREFIX} URL must not end with a slash`);\n }\n\n return new UrlPatternDiscovery(parts);\n }\n\n private constructor(private readonly parts: string[]) {}\n\n async getBaseUrl(pluginId: string): Promise<string> {\n return this.parts.join(encodeURIComponent(pluginId));\n }\n}\n"],"names":[],"mappings":"AAkBA,MAAM,YAA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CAAA,CAAA;AAAA,GACrD;AACF;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class ErrorAlerter {
|
|
2
|
+
constructor(alertApi, errorApi) {
|
|
3
|
+
this.alertApi = alertApi;
|
|
4
|
+
this.errorApi = errorApi;
|
|
5
|
+
}
|
|
6
|
+
post(error, context) {
|
|
7
|
+
if (!context?.hidden) {
|
|
8
|
+
this.alertApi.post({ message: error.message, severity: "error" });
|
|
9
|
+
}
|
|
10
|
+
return this.errorApi.post(error, context);
|
|
11
|
+
}
|
|
12
|
+
error$() {
|
|
13
|
+
return this.errorApi.error$();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { ErrorAlerter };
|
|
18
|
+
//# sourceMappingURL=ErrorAlerter.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorAlerter.esm.js","sources":["../../../../src/apis/implementations/ErrorApi/ErrorAlerter.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 ErrorApi,\n ErrorApiError,\n ErrorApiErrorContext,\n AlertApi,\n} from '@backstage/core-plugin-api';\n\n/**\n * Decorates an ErrorApi by also forwarding error messages\n * to the alertApi with an 'error' severity.\n *\n * @public\n */\nexport class ErrorAlerter implements ErrorApi {\n constructor(\n private readonly alertApi: AlertApi,\n private readonly errorApi: ErrorApi,\n ) {}\n\n post(error: ErrorApiError, context?: ErrorApiErrorContext) {\n if (!context?.hidden) {\n this.alertApi.post({ message: error.message, severity: 'error' });\n }\n\n return this.errorApi.post(error, context);\n }\n\n error$() {\n return this.errorApi.error$();\n }\n}\n"],"names":[],"mappings":"AA4BO,MAAM,YAAiC,CAAA;AAAA,EAC5C,WAAA,CACmB,UACA,QACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA,CAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA,CAAA;AAAA,GAChB;AAAA,EAEH,IAAA,CAAK,OAAsB,OAAgC,EAAA;AACzD,IAAI,IAAA,CAAC,SAAS,MAAQ,EAAA;AACpB,MAAK,IAAA,CAAA,QAAA,CAAS,KAAK,EAAE,OAAA,EAAS,MAAM,OAAS,EAAA,QAAA,EAAU,SAAS,CAAA,CAAA;AAAA,KAClE;AAEA,IAAA,OAAO,IAAK,CAAA,QAAA,CAAS,IAAK,CAAA,KAAA,EAAO,OAAO,CAAA,CAAA;AAAA,GAC1C;AAAA,EAEA,MAAS,GAAA;AACP,IAAO,OAAA,IAAA,CAAK,SAAS,MAAO,EAAA,CAAA;AAAA,GAC9B;AACF;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PublishSubject } from '../../../lib/subjects.esm.js';
|
|
2
|
+
|
|
3
|
+
class ErrorApiForwarder {
|
|
4
|
+
subject = new PublishSubject();
|
|
5
|
+
post(error, context) {
|
|
6
|
+
this.subject.next({ error, context });
|
|
7
|
+
}
|
|
8
|
+
error$() {
|
|
9
|
+
return this.subject;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { ErrorApiForwarder };
|
|
14
|
+
//# sourceMappingURL=ErrorApiForwarder.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorApiForwarder.esm.js","sources":["../../../../src/apis/implementations/ErrorApi/ErrorApiForwarder.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 ErrorApi,\n ErrorApiError,\n ErrorApiErrorContext,\n} from '@backstage/core-plugin-api';\nimport { Observable } from '@backstage/types';\nimport { PublishSubject } from '../../../lib/subjects';\n\n/**\n * Base implementation for the ErrorApi that simply forwards errors to consumers.\n *\n * @public\n */\nexport class ErrorApiForwarder implements ErrorApi {\n private readonly subject = new PublishSubject<{\n error: Error;\n context?: ErrorApiErrorContext;\n }>();\n\n post(error: ErrorApiError, context?: ErrorApiErrorContext) {\n this.subject.next({ error, context });\n }\n\n error$(): Observable<{ error: Error; context?: ErrorApiErrorContext }> {\n return this.subject;\n }\n}\n"],"names":[],"mappings":";;AA6BO,MAAM,iBAAsC,CAAA;AAAA,EAChC,OAAA,GAAU,IAAI,cAG5B,EAAA,CAAA;AAAA,EAEH,IAAA,CAAK,OAAsB,OAAgC,EAAA;AACzD,IAAA,IAAA,CAAK,OAAQ,CAAA,IAAA,CAAK,EAAE,KAAA,EAAO,SAAS,CAAA,CAAA;AAAA,GACtC;AAAA,EAEA,MAAuE,GAAA;AACrE,IAAA,OAAO,IAAK,CAAA,OAAA,CAAA;AAAA,GACd;AACF;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class UnhandledErrorForwarder {
|
|
2
|
+
/**
|
|
3
|
+
* Add event listener, such that unhandled errors can be forwarded using an given `ErrorApi` instance
|
|
4
|
+
*/
|
|
5
|
+
static forward(errorApi, errorContext) {
|
|
6
|
+
window.addEventListener(
|
|
7
|
+
"unhandledrejection",
|
|
8
|
+
(e) => {
|
|
9
|
+
errorApi.post(e.reason, errorContext);
|
|
10
|
+
}
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { UnhandledErrorForwarder };
|
|
16
|
+
//# sourceMappingURL=UnhandledErrorForwarder.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnhandledErrorForwarder.esm.js","sources":["../../../../src/apis/implementations/ErrorApi/UnhandledErrorForwarder.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 ErrorApi,\n ErrorApiError,\n ErrorApiErrorContext,\n} from '@backstage/core-plugin-api';\n\n/**\n * Utility class that helps with error forwarding.\n *\n * @public\n */\nexport class UnhandledErrorForwarder {\n /**\n * Add event listener, such that unhandled errors can be forwarded using an given `ErrorApi` instance\n */\n static forward(errorApi: ErrorApi, errorContext: ErrorApiErrorContext) {\n window.addEventListener(\n 'unhandledrejection',\n (e: PromiseRejectionEvent) => {\n errorApi.post(e.reason as ErrorApiError, errorContext);\n },\n );\n }\n}\n"],"names":[],"mappings":"AA2BO,MAAM,uBAAwB,CAAA;AAAA;AAAA;AAAA;AAAA,EAInC,OAAO,OAAQ,CAAA,QAAA,EAAoB,YAAoC,EAAA;AACrE,IAAO,MAAA,CAAA,gBAAA;AAAA,MACL,oBAAA;AAAA,MACA,CAAC,CAA6B,KAAA;AAC5B,QAAS,QAAA,CAAA,IAAA,CAAK,CAAE,CAAA,MAAA,EAAyB,YAAY,CAAA,CAAA;AAAA,OACvD;AAAA,KACF,CAAA;AAAA,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { FeatureFlagState } from '@backstage/core-plugin-api';
|
|
2
|
+
|
|
3
|
+
function validateFlagName(name) {
|
|
4
|
+
if (name.length < 3) {
|
|
5
|
+
throw new Error(
|
|
6
|
+
`The '${name}' feature flag must have a minimum length of three characters.`
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
if (name.length > 150) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`The '${name}' feature flag must not exceed 150 characters.`
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
if (!name.match(/^[a-z]+[a-z0-9-]+$/)) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`The '${name}' feature flag must start with a lowercase letter and only contain lowercase letters, numbers and hyphens. Examples: feature-flag-one, alpha, release-2020`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
class LocalStorageFeatureFlags {
|
|
21
|
+
registeredFeatureFlags = [];
|
|
22
|
+
flags;
|
|
23
|
+
registerFlag(flag) {
|
|
24
|
+
validateFlagName(flag.name);
|
|
25
|
+
this.registeredFeatureFlags.push(flag);
|
|
26
|
+
}
|
|
27
|
+
getRegisteredFlags() {
|
|
28
|
+
return this.registeredFeatureFlags.slice();
|
|
29
|
+
}
|
|
30
|
+
isActive(name) {
|
|
31
|
+
if (!this.flags) {
|
|
32
|
+
this.flags = this.load();
|
|
33
|
+
}
|
|
34
|
+
return this.flags.get(name) === FeatureFlagState.Active;
|
|
35
|
+
}
|
|
36
|
+
save(options) {
|
|
37
|
+
if (!this.flags) {
|
|
38
|
+
this.flags = this.load();
|
|
39
|
+
}
|
|
40
|
+
if (!options.merge) {
|
|
41
|
+
this.flags.clear();
|
|
42
|
+
}
|
|
43
|
+
for (const [name, state] of Object.entries(options.states)) {
|
|
44
|
+
this.flags.set(name, state);
|
|
45
|
+
}
|
|
46
|
+
const enabled = Array.from(this.flags.entries()).filter(
|
|
47
|
+
([, state]) => state === FeatureFlagState.Active
|
|
48
|
+
);
|
|
49
|
+
window.localStorage.setItem(
|
|
50
|
+
"featureFlags",
|
|
51
|
+
JSON.stringify(Object.fromEntries(enabled))
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
load() {
|
|
55
|
+
try {
|
|
56
|
+
const jsonStr = window.localStorage.getItem("featureFlags");
|
|
57
|
+
if (!jsonStr) {
|
|
58
|
+
return /* @__PURE__ */ new Map();
|
|
59
|
+
}
|
|
60
|
+
const json = JSON.parse(jsonStr);
|
|
61
|
+
if (typeof json !== "object" || json === null || Array.isArray(json)) {
|
|
62
|
+
return /* @__PURE__ */ new Map();
|
|
63
|
+
}
|
|
64
|
+
const entries = Object.entries(json).filter(([name, value]) => {
|
|
65
|
+
validateFlagName(name);
|
|
66
|
+
return value === FeatureFlagState.Active;
|
|
67
|
+
});
|
|
68
|
+
return new Map(entries);
|
|
69
|
+
} catch {
|
|
70
|
+
return /* @__PURE__ */ new Map();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { LocalStorageFeatureFlags, validateFlagName };
|
|
76
|
+
//# sourceMappingURL=LocalStorageFeatureFlags.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalStorageFeatureFlags.esm.js","sources":["../../../../src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.tsx"],"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 FeatureFlagState,\n FeatureFlagsApi,\n FeatureFlag,\n FeatureFlagsSaveOptions,\n} from '@backstage/core-plugin-api';\n\nexport function validateFlagName(name: string): void {\n if (name.length < 3) {\n throw new Error(\n `The '${name}' feature flag must have a minimum length of three characters.`,\n );\n }\n\n if (name.length > 150) {\n throw new Error(\n `The '${name}' feature flag must not exceed 150 characters.`,\n );\n }\n\n if (!name.match(/^[a-z]+[a-z0-9-]+$/)) {\n throw new Error(\n `The '${name}' feature flag must start with a lowercase letter and only contain lowercase letters, numbers and hyphens. ` +\n 'Examples: feature-flag-one, alpha, release-2020',\n );\n }\n}\n\n/**\n * A feature flags implementation that stores the flags in the browser's local\n * storage.\n *\n * @public\n */\nexport class LocalStorageFeatureFlags implements FeatureFlagsApi {\n private registeredFeatureFlags: FeatureFlag[] = [];\n private flags?: Map<string, FeatureFlagState>;\n\n registerFlag(flag: FeatureFlag) {\n validateFlagName(flag.name);\n this.registeredFeatureFlags.push(flag);\n }\n\n getRegisteredFlags(): FeatureFlag[] {\n return this.registeredFeatureFlags.slice();\n }\n\n isActive(name: string): boolean {\n if (!this.flags) {\n this.flags = this.load();\n }\n return this.flags.get(name) === FeatureFlagState.Active;\n }\n\n save(options: FeatureFlagsSaveOptions): void {\n if (!this.flags) {\n this.flags = this.load();\n }\n if (!options.merge) {\n this.flags.clear();\n }\n for (const [name, state] of Object.entries(options.states)) {\n this.flags.set(name, state);\n }\n\n const enabled = Array.from(this.flags.entries()).filter(\n ([, state]) => state === FeatureFlagState.Active,\n );\n window.localStorage.setItem(\n 'featureFlags',\n JSON.stringify(Object.fromEntries(enabled)),\n );\n }\n\n private load(): Map<string, FeatureFlagState> {\n try {\n const jsonStr = window.localStorage.getItem('featureFlags');\n if (!jsonStr) {\n return new Map();\n }\n const json = JSON.parse(jsonStr) as unknown;\n if (typeof json !== 'object' || json === null || Array.isArray(json)) {\n return new Map();\n }\n\n const entries = Object.entries(json).filter(([name, value]) => {\n validateFlagName(name);\n return value === FeatureFlagState.Active;\n });\n\n return new Map(entries);\n } catch {\n return new Map();\n }\n }\n}\n"],"names":[],"mappings":";;AAuBO,SAAS,iBAAiB,IAAoB,EAAA;AACnD,EAAI,IAAA,IAAA,CAAK,SAAS,CAAG,EA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AA,MAAA,CAAA;AAAA,OACnC,CAAA,CAAA;AAED,MAAO,OAAA,IAAI,IAAI,OAAO,CAAA,CAAA;AAAA,KAChB,CAAA,MAAA;AACN,MAAA,2BAAW,GAAI,EAAA,CAAA;AAAA,KACjB;AAAA,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IdentityAuthInjectorFetchMiddleware } from './IdentityAuthInjectorFetchMiddleware.esm.js';
|
|
2
|
+
import { PluginProtocolResolverFetchMiddleware } from './PluginProtocolResolverFetchMiddleware.esm.js';
|
|
3
|
+
|
|
4
|
+
class FetchMiddlewares {
|
|
5
|
+
/**
|
|
6
|
+
* Handles translation from `plugin://` URLs to concrete http(s) URLs based on
|
|
7
|
+
* the discovery API.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
*
|
|
11
|
+
* If the request is for `plugin://catalog/entities?filter=x=y`, the discovery
|
|
12
|
+
* API will be queried for `'catalog'`. If it returned
|
|
13
|
+
* `https://backstage.example.net/api/catalog`, the resulting query would be
|
|
14
|
+
* `https://backstage.example.net/api/catalog/entities?filter=x=y`.
|
|
15
|
+
*
|
|
16
|
+
* If the incoming URL protocol was not `plugin`, the request is just passed
|
|
17
|
+
* through verbatim to the underlying implementation.
|
|
18
|
+
*/
|
|
19
|
+
static resolvePluginProtocol(options) {
|
|
20
|
+
return new PluginProtocolResolverFetchMiddleware(options.discoveryApi);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Injects a Backstage token header when the user is signed in.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
*
|
|
27
|
+
* Per default, an `Authorization: Bearer <token>` is generated. This can be
|
|
28
|
+
* customized using the `header` option.
|
|
29
|
+
*
|
|
30
|
+
* The header injection only happens on allowlisted URLs. Per default, if the
|
|
31
|
+
* `config` option is passed in, the `backend.baseUrl` is allowlisted, unless
|
|
32
|
+
* the `urlPrefixAllowlist` or `allowUrl` options are passed in, in which case
|
|
33
|
+
* they take precedence. If you pass in neither config nor an
|
|
34
|
+
* allowlist/callback, the middleware will have no effect since effectively no
|
|
35
|
+
* request will match the (nonexistent) rules.
|
|
36
|
+
*/
|
|
37
|
+
static injectIdentityAuth(options) {
|
|
38
|
+
return IdentityAuthInjectorFetchMiddleware.create(options);
|
|
39
|
+
}
|
|
40
|
+
constructor() {
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { FetchMiddlewares };
|
|
45
|
+
//# sourceMappingURL=FetchMiddlewares.esm.js.map
|