@backstage/plugin-app 0.2.0-next.2 → 0.2.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.
Files changed (93) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/alpha/appModulePublicSignIn.esm.js.map +1 -1
  3. package/dist/apis/DefaultDialogApi.esm.js.map +1 -1
  4. package/dist/apis/SwappableComponentsApi/DefaultSwappableComponentsApi.esm.js.map +1 -1
  5. package/dist/defaultApis.esm.js +3 -3
  6. package/dist/defaultApis.esm.js.map +1 -1
  7. package/dist/extensions/AnalyticsApi.esm.js.map +1 -1
  8. package/dist/extensions/App.esm.js +1 -1
  9. package/dist/extensions/App.esm.js.map +1 -1
  10. package/dist/extensions/AppLanguageApi.esm.js.map +1 -1
  11. package/dist/extensions/AppLayout.esm.js +1 -1
  12. package/dist/extensions/AppLayout.esm.js.map +1 -1
  13. package/dist/extensions/AppNav.esm.js +1 -1
  14. package/dist/extensions/AppNav.esm.js.map +1 -1
  15. package/dist/extensions/AppRoot.esm.js +1 -1
  16. package/dist/extensions/AppRoot.esm.js.map +1 -1
  17. package/dist/extensions/AppRoutes.esm.js +1 -1
  18. package/dist/extensions/AppRoutes.esm.js.map +1 -1
  19. package/dist/extensions/AppThemeApi.esm.js +1 -1
  20. package/dist/extensions/AppThemeApi.esm.js.map +1 -1
  21. package/dist/extensions/DefaultSignInPage.esm.js.map +1 -1
  22. package/dist/extensions/DialogDisplay.esm.js.map +1 -1
  23. package/dist/extensions/FeatureFlagsApi.esm.js.map +1 -1
  24. package/dist/extensions/IconsApi.esm.js +1 -1
  25. package/dist/extensions/IconsApi.esm.js.map +1 -1
  26. package/dist/extensions/LegacyComponentsApi.esm.js.map +1 -1
  27. package/dist/extensions/SwappableComponentsApi.esm.js +1 -1
  28. package/dist/extensions/SwappableComponentsApi.esm.js.map +1 -1
  29. package/dist/extensions/TranslationsApi.esm.js +1 -1
  30. package/dist/extensions/TranslationsApi.esm.js.map +1 -1
  31. package/dist/extensions/components.esm.js +4 -4
  32. package/dist/extensions/components.esm.js.map +1 -1
  33. package/dist/extensions/elements.esm.js.map +1 -1
  34. package/dist/index.d.ts +1 -1
  35. package/dist/packages/app-defaults/src/defaults/apis.esm.js +2 -2
  36. package/dist/packages/app-defaults/src/defaults/apis.esm.js.map +1 -1
  37. package/dist/packages/app-defaults/src/defaults/icons.esm.js.map +1 -1
  38. package/dist/packages/core-app-api/src/apis/implementations/AlertApi/AlertApiForwarder.esm.js.map +1 -1
  39. package/dist/packages/core-app-api/src/apis/implementations/AppLanguageApi/AppLanguageSelector.esm.js.map +1 -1
  40. package/dist/packages/core-app-api/src/apis/implementations/AppThemeApi/AppThemeSelector.esm.js.map +1 -1
  41. package/dist/packages/core-app-api/src/apis/implementations/DiscoveryApi/UrlPatternDiscovery.esm.js.map +1 -1
  42. package/dist/packages/core-app-api/src/apis/implementations/ErrorApi/ErrorAlerter.esm.js.map +1 -1
  43. package/dist/packages/core-app-api/src/apis/implementations/ErrorApi/ErrorApiForwarder.esm.js.map +1 -1
  44. package/dist/packages/core-app-api/src/apis/implementations/ErrorApi/UnhandledErrorForwarder.esm.js.map +1 -1
  45. package/dist/packages/core-app-api/src/apis/implementations/FeatureFlagsApi/LocalStorageFeatureFlags.esm.js.map +1 -1
  46. package/dist/packages/core-app-api/src/apis/implementations/FetchApi/FetchMiddlewares.esm.js.map +1 -1
  47. package/dist/packages/core-app-api/src/apis/implementations/FetchApi/IdentityAuthInjectorFetchMiddleware.esm.js.map +1 -1
  48. package/dist/packages/core-app-api/src/apis/implementations/FetchApi/PluginProtocolResolverFetchMiddleware.esm.js.map +1 -1
  49. package/dist/packages/core-app-api/src/apis/implementations/FetchApi/createFetchApi.esm.js.map +1 -1
  50. package/dist/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.esm.js.map +1 -1
  51. package/dist/packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.esm.js.map +1 -1
  52. package/dist/packages/core-app-api/src/apis/implementations/StorageApi/WebStorage.esm.js.map +1 -1
  53. package/dist/packages/core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.esm.js.map +1 -1
  54. package/dist/packages/core-app-api/src/apis/implementations/auth/atlassian/AtlassianAuth.esm.js.map +1 -1
  55. package/dist/packages/core-app-api/src/apis/implementations/auth/bitbucket/BitbucketAuth.esm.js.map +1 -1
  56. package/dist/packages/core-app-api/src/apis/implementations/auth/bitbucketServer/BitbucketServerAuth.esm.js.map +1 -1
  57. package/dist/packages/core-app-api/src/apis/implementations/auth/github/GithubAuth.esm.js.map +1 -1
  58. package/dist/packages/core-app-api/src/apis/implementations/auth/gitlab/GitlabAuth.esm.js.map +1 -1
  59. package/dist/packages/core-app-api/src/apis/implementations/auth/google/GoogleAuth.esm.js.map +1 -1
  60. package/dist/packages/core-app-api/src/apis/implementations/auth/microsoft/MicrosoftAuth.esm.js.map +1 -1
  61. package/dist/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.esm.js.map +1 -1
  62. package/dist/packages/core-app-api/src/apis/implementations/auth/okta/OktaAuth.esm.js.map +1 -1
  63. package/dist/packages/core-app-api/src/apis/implementations/auth/onelogin/OneLoginAuth.esm.js.map +1 -1
  64. package/dist/packages/core-app-api/src/apis/implementations/auth/saml/types.esm.js.map +1 -1
  65. package/dist/packages/core-app-api/src/apis/implementations/auth/vmwareCloud/VMwareCloudAuth.esm.js.map +1 -1
  66. package/dist/packages/core-app-api/src/apis/system/ApiAggregator.esm.js.map +1 -1
  67. package/dist/packages/core-app-api/src/apis/system/ApiProvider.esm.js.map +1 -1
  68. package/dist/packages/core-app-api/src/app/AppRouter.esm.js.map +1 -1
  69. package/dist/packages/core-app-api/src/app/AppThemeProvider.esm.js.map +1 -1
  70. package/dist/packages/core-app-api/src/app/InternalAppContext.esm.js.map +1 -1
  71. package/dist/packages/core-app-api/src/app/isProtectedApp.esm.js.map +1 -1
  72. package/dist/packages/core-app-api/src/app/isReactRouterBeta.esm.js.map +1 -1
  73. package/dist/packages/core-app-api/src/lib/AuthConnector/DefaultAuthConnector.esm.js.map +1 -1
  74. package/dist/packages/core-app-api/src/lib/AuthSessionManager/RefreshingAuthSessionManager.esm.js.map +1 -1
  75. package/dist/packages/core-app-api/src/lib/AuthSessionManager/SessionStateTracker.esm.js.map +1 -1
  76. package/dist/packages/core-app-api/src/lib/AuthSessionManager/common.esm.js.map +1 -1
  77. package/dist/packages/core-app-api/src/lib/loginPopup.esm.js.map +1 -1
  78. package/dist/packages/core-app-api/src/lib/subjects.esm.js.map +1 -1
  79. package/dist/packages/core-app-api/src/routing/FeatureFlagged.esm.js.map +1 -1
  80. package/dist/packages/core-app-api/src/routing/FlatRoutes.esm.js.map +1 -1
  81. package/dist/packages/core-app-api/src/routing/RouteTracker.esm.js.map +1 -1
  82. package/dist/packages/core-plugin-api/src/translation/TranslationRef.esm.js.map +1 -1
  83. package/dist/packages/core-plugin-api/src/translation/TranslationResource.esm.js.map +1 -1
  84. package/dist/packages/frontend-app-api/src/apis/implementations/IconsApi/DefaultIconsApi.esm.js.map +1 -1
  85. package/dist/packages/frontend-app-api/src/routing/RouteTracker.esm.js.map +1 -1
  86. package/dist/packages/frontend-app-api/src/routing/getBasePath.esm.js.map +1 -1
  87. package/dist/packages/frontend-internal/src/wiring/InternalExtensionDefinition.esm.js.map +1 -1
  88. package/dist/packages/frontend-internal/src/wiring/InternalFrontendPlugin.esm.js.map +1 -1
  89. package/dist/packages/frontend-internal/src/wiring/InternalSwappableComponentRef.esm.js.map +1 -1
  90. package/dist/packages/opaque-internal/src/OpaqueType.esm.js.map +1 -1
  91. package/dist/plugin.esm.js.map +1 -1
  92. package/dist/plugins/app/package.json.esm.js +1 -1
  93. package/package.json +14 -14
@@ -1 +1 @@
1
- {"version":3,"file":"OAuthPendingRequests.esm.js","sources":["../../../../../../../../../packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.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 { BehaviorSubject } from '../../../lib/subjects';\n\ntype RequestQueueEntry<ResultType> = {\n scopes: Set<string>;\n resolve: (value: ResultType | PromiseLike<ResultType>) => void;\n reject: (reason: Error) => void;\n};\n\nexport type PendingRequest<ResultType> = {\n scopes: Set<string> | undefined;\n resolve: (value: ResultType) => void;\n reject: (reason: Error) => void;\n};\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\nexport function joinScopes(\n scopes: Set<string>,\n ...moreScopess: Set<string>[]\n): Set<string> {\n const result = new Set(scopes);\n\n for (const moreScopes of moreScopess) {\n for (const scope of moreScopes) {\n result.add(scope);\n }\n }\n\n return result;\n}\n\n/**\n * The OAuthPendingRequests class is a utility for managing and observing\n * a stream of requests for oauth scopes for a single provider, and resolving\n * them correctly once requests are fulfilled.\n */\nexport class OAuthPendingRequests<ResultType> {\n private requests: RequestQueueEntry<ResultType>[] = [];\n private subject = new BehaviorSubject<PendingRequest<ResultType>>(\n this.getCurrentPending(),\n );\n\n request(scopes: Set<string>): Promise<ResultType> {\n return new Promise((resolve, reject) => {\n this.requests.push({ scopes, resolve, reject });\n\n this.subject.next(this.getCurrentPending());\n });\n }\n\n resolve(scopes: Set<string>, result: ResultType): void {\n this.requests = this.requests.filter(request => {\n if (hasScopes(scopes, request.scopes)) {\n request.resolve(result);\n return false;\n }\n return true;\n });\n\n this.subject.next(this.getCurrentPending());\n }\n\n reject(error: Error) {\n this.requests.forEach(request => request.reject(error));\n this.requests = [];\n\n this.subject.next(this.getCurrentPending());\n }\n\n pending(): Observable<PendingRequest<ResultType>> {\n return this.subject;\n }\n\n private getCurrentPending(): PendingRequest<ResultType> {\n const currentScopes =\n this.requests.length === 0\n ? undefined\n : this.requests\n .slice(1)\n .reduce(\n (acc, current) => joinScopes(acc, current.scopes),\n this.requests[0].scopes,\n );\n\n return {\n scopes: currentScopes,\n resolve: (value: ResultType) => {\n if (currentScopes) {\n this.resolve(currentScopes, value);\n }\n },\n reject: (reason: Error) => {\n if (currentScopes) {\n this.reject(reason);\n }\n },\n };\n }\n}\n"],"names":[],"mappings":";;AA+BgB,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;AAAA;AACT;AAEF,EAAO,OAAA,IAAA;AACT;AAEgB,SAAA,UAAA,CACd,WACG,WACU,EAAA;AACb,EAAM,MAAA,MAAA,GAAS,IAAI,GAAA,CAAI,MAAM,CAAA;AAE7B,EAAA,KAAA,MAAW,cAAc,WAAa,EAAA;AACpC,IAAA,KAAA,MAAW,SAAS,UAAY,EAAA;AAC9B,MAAA,MAAA,CAAO,IAAI,KAAK,CAAA;AAAA;AAClB;AAGF,EAAO,OAAA,MAAA;AACT;AAOO,MAAM,oBAAiC,CAAA;AAAA,EACpC,WAA4C,EAAC;AAAA,EAC7C,UAAU,IAAI,eAAA;AAAA,IACpB,KAAK,iBAAkB;AAAA,GACzB;AAAA,EAEA,QAAQ,MAA0C,EAAA;AAChD,IAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAW,KAAA;AACtC,MAAA,IAAA,CAAK,SAAS,IAAK,CAAA,EAAE,MAAQ,EAAA,OAAA,EAAS,QAAQ,CAAA;AAE9C,MAAA,IAAA,CAAK,O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C9B,QAAA,IAAI,aAAe,EAAA;AACjB,UAAK,IAAA,CAAA,OAAA,CAAQ,eAAe,KAAK,CAAA;AAAA;AACnC,OACF;AAAA,MACA,MAAA,EAAQ,CAAC,MAAkB,KAAA;AACzB,QAAA,IAAI,aAAe,EAAA;AACjB,UAAA,IAAA,CAAK,OAAO,MAAM,CAAA;AAAA;AACpB;AACF,KACF;AAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"OAuthPendingRequests.esm.js","sources":["../../../../../../../../../packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthPendingRequests.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 { BehaviorSubject } from '../../../lib/subjects';\n\ntype RequestQueueEntry<ResultType> = {\n scopes: Set<string>;\n resolve: (value: ResultType | PromiseLike<ResultType>) => void;\n reject: (reason: Error) => void;\n};\n\nexport type PendingRequest<ResultType> = {\n scopes: Set<string> | undefined;\n resolve: (value: ResultType) => void;\n reject: (reason: Error) => void;\n};\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\nexport function joinScopes(\n scopes: Set<string>,\n ...moreScopess: Set<string>[]\n): Set<string> {\n const result = new Set(scopes);\n\n for (const moreScopes of moreScopess) {\n for (const scope of moreScopes) {\n result.add(scope);\n }\n }\n\n return result;\n}\n\n/**\n * The OAuthPendingRequests class is a utility for managing and observing\n * a stream of requests for oauth scopes for a single provider, and resolving\n * them correctly once requests are fulfilled.\n */\nexport class OAuthPendingRequests<ResultType> {\n private requests: RequestQueueEntry<ResultType>[] = [];\n private subject = new BehaviorSubject<PendingRequest<ResultType>>(\n this.getCurrentPending(),\n );\n\n request(scopes: Set<string>): Promise<ResultType> {\n return new Promise((resolve, reject) => {\n this.requests.push({ scopes, resolve, reject });\n\n this.subject.next(this.getCurrentPending());\n });\n }\n\n resolve(scopes: Set<string>, result: ResultType): void {\n this.requests = this.requests.filter(request => {\n if (hasScopes(scopes, request.scopes)) {\n request.resolve(result);\n return false;\n }\n return true;\n });\n\n this.subject.next(this.getCurrentPending());\n }\n\n reject(error: Error) {\n this.requests.forEach(request => request.reject(error));\n this.requests = [];\n\n this.subject.next(this.getCurrentPending());\n }\n\n pending(): Observable<PendingRequest<ResultType>> {\n return this.subject;\n }\n\n private getCurrentPending(): PendingRequest<ResultType> {\n const currentScopes =\n this.requests.length === 0\n ? undefined\n : this.requests\n .slice(1)\n .reduce(\n (acc, current) => joinScopes(acc, current.scopes),\n this.requests[0].scopes,\n );\n\n return {\n scopes: currentScopes,\n resolve: (value: ResultType) => {\n if (currentScopes) {\n this.resolve(currentScopes, value);\n }\n },\n reject: (reason: Error) => {\n if (currentScopes) {\n this.reject(reason);\n }\n },\n };\n }\n}\n"],"names":[],"mappings":";;AA+BO,SAAS,SAAA,CACd,UACA,SAAA,EACS;AACT,EAAA,KAAA,MAAW,SAAS,SAAA,EAAW;AAC7B,IAAA,IAAI,CAAC,QAAA,CAAS,GAAA,CAAI,KAAK,CAAA,EAAG;AACxB,MAAA,OAAO,KAAA;AAAA,IACT;AAAA,EACF;AACA,EAAA,OAAO,IAAA;AACT;AAEO,SAAS,UAAA,CACd,WACG,WAAA,EACU;AACb,EAAA,MAAM,MAAA,GAAS,IAAI,GAAA,CAAI,MAAM,CAAA;AAE7B,EAAA,KAAA,MAAW,cAAc,WAAA,EAAa;AACpC,IAAA,KAAA,MAAW,SAAS,UAAA,EAAY;AAC9B,MAAA,MAAA,CA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AA,OAAO,IAAA,CAAK,OAAA;AAAA,EACd;AAAA,EAEQ,iBAAA,GAAgD;AACtD,IAAA,MAAM,aAAA,GACJ,IAAA,CAAK,QAAA,CAAS,MAAA,KAAW,CAAA,GACrB,SACA,IAAA,CAAK,QAAA,CACF,KAAA,CAAM,CAAC,CAAA,CACP,MAAA;AAAA,MACC,CAAC,GAAA,EAAK,OAAA,KAAY,UAAA,CAAW,GAAA,EAAK,QAAQ,MAAM,CAAA;AAAA,MAChD,IAAA,CAAK,QAAA,CAAS,CAAC,CAAA,CAAE;AAAA,KACnB;AAER,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,aAAA;AAAA,MACR,OAAA,EAAS,CAAC,KAAA,KAAsB;AAC9B,QAAA,IAAI,aAAA,EAAe;AACjB,UAAA,IAAA,CAAK,OAAA,CAAQ,eAAe,KAAK,CAAA;AAAA,QACnC;AAAA,MACF,CAAA;AAAA,MACA,MAAA,EAAQ,CAAC,MAAA,KAAkB;AACzB,QAAA,IAAI,aAAA,EAAe;AACjB,UAAA,IAAA,CAAK,OAAO,MAAM,CAAA;AAAA,QACpB;AAAA,MACF;AAAA,KACF;AAAA,EACF;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"OAuthRequestManager.esm.js","sources":["../../../../../../../../../packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.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 OAuthRequestApi,\n PendingOAuthRequest,\n OAuthRequester,\n OAuthRequesterOptions,\n} from '@backstage/core-plugin-api';\nimport { Observable } from '@backstage/types';\nimport { OAuthPendingRequests, PendingRequest } from './OAuthPendingRequests';\nimport { PublishSubject } from '../../../lib/subjects';\n\n/**\n * The OAuthRequestManager is an implementation of the OAuthRequestApi.\n *\n * The purpose of this class and the API is to read a stream of incoming requests\n * of OAuth access tokens from different providers with varying scope, and funnel\n * them all together into a single request for each OAuth provider.\n *\n * @public\n */\nexport class OAuthRequestManager implements OAuthRequestApi {\n private readonly subject = new PublishSubject<PendingOAuthRequest[]>();\n private currentRequests: PendingOAuthRequest[] = [];\n private handlerCount = 0;\n\n createAuthRequester<T>(options: OAuthRequesterOptions<T>): OAuthRequester<T> {\n const handler = new OAuthPendingRequests<T>();\n\n const index = this.handlerCount;\n this.handlerCount++;\n\n handler.pending().subscribe({\n next: scopeRequest => {\n const newRequests = this.currentRequests.slice();\n const request = this.makeAuthRequest(scopeRequest, options);\n if (!request) {\n delete newRequests[index];\n } else {\n newRequests[index] = request;\n }\n this.currentRequests = newRequests;\n // Convert from sparse array to array of present items only\n this.subject.next(newRequests.filter(Boolean));\n },\n });\n\n return scopes => {\n return handler.request(scopes);\n };\n }\n\n // Converts the pending request and popup options into a popup request that we can forward to subscribers.\n private makeAuthRequest(\n request: PendingRequest<any>,\n options: OAuthRequesterOptions<any>,\n ): PendingOAuthRequest | undefined {\n const { scopes } = request;\n if (!scopes) {\n return undefined;\n }\n\n return {\n provider: options.provider,\n trigger: async () => {\n const result = await options.onAuthRequest(scopes);\n request.resolve(result);\n },\n reject: () => {\n const error = new Error('Login failed, rejected by user');\n error.name = 'RejectedError';\n request.reject(error);\n },\n };\n }\n\n authRequest$(): Observable<PendingOAuthRequest[]> {\n return this.subject;\n }\n}\n"],"names":[],"mappings":";;;AAmCO,MAAM,mBAA+C,CAAA;AAAA,EACzC,OAAA,GAAU,IAAI,cAAsC,EAAA;AAAA,EAC7D,kBAAyC,EAAC;AAAA,EAC1C,YAAe,GAAA,CAAA;AAAA,EAEvB,oBAAuB,OAAsD,EAAA;AA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ACxD,QAAA,KAAA,CAAM,IAAO,GAAA,eAAA;AACb,QAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA;AACtB,KACF;AAAA;AACF,EAEA,YAAkD,GAAA;AAChD,IAAA,OAAO,IAAK,CAAA,OAAA;AAAA;AAEhB;;;;"}
1
+ {"version":3,"file":"OAuthRequestManager.esm.js","sources":["../../../../../../../../../packages/core-app-api/src/apis/implementations/OAuthRequestApi/OAuthRequestManager.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 OAuthRequestApi,\n PendingOAuthRequest,\n OAuthRequester,\n OAuthRequesterOptions,\n} from '@backstage/core-plugin-api';\nimport { Observable } from '@backstage/types';\nimport { OAuthPendingRequests, PendingRequest } from './OAuthPendingRequests';\nimport { PublishSubject } from '../../../lib/subjects';\n\n/**\n * The OAuthRequestManager is an implementation of the OAuthRequestApi.\n *\n * The purpose of this class and the API is to read a stream of incoming requests\n * of OAuth access tokens from different providers with varying scope, and funnel\n * them all together into a single request for each OAuth provider.\n *\n * @public\n */\nexport class OAuthRequestManager implements OAuthRequestApi {\n private readonly subject = new PublishSubject<PendingOAuthRequest[]>();\n private currentRequests: PendingOAuthRequest[] = [];\n private handlerCount = 0;\n\n createAuthRequester<T>(options: OAuthRequesterOptions<T>): OAuthRequester<T> {\n const handler = new OAuthPendingRequests<T>();\n\n const index = this.handlerCount;\n this.handlerCount++;\n\n handler.pending().subscribe({\n next: scopeRequest => {\n const newRequests = this.currentRequests.slice();\n const request = this.makeAuthRequest(scopeRequest, options);\n if (!request) {\n delete newRequests[index];\n } else {\n newRequests[index] = request;\n }\n this.currentRequests = newRequests;\n // Convert from sparse array to array of present items only\n this.subject.next(newRequests.filter(Boolean));\n },\n });\n\n return scopes => {\n return handler.request(scopes);\n };\n }\n\n // Converts the pending request and popup options into a popup request that we can forward to subscribers.\n private makeAuthRequest(\n request: PendingRequest<any>,\n options: OAuthRequesterOptions<any>,\n ): PendingOAuthRequest | undefined {\n const { scopes } = request;\n if (!scopes) {\n return undefined;\n }\n\n return {\n provider: options.provider,\n trigger: async () => {\n const result = await options.onAuthRequest(scopes);\n request.resolve(result);\n },\n reject: () => {\n const error = new Error('Login failed, rejected by user');\n error.name = 'RejectedError';\n request.reject(error);\n },\n };\n }\n\n authRequest$(): Observable<PendingOAuthRequest[]> {\n return this.subject;\n }\n}\n"],"names":[],"mappings":";;;AAmCO,MAAM,mBAAA,CAA+C;AAAA,EACzC,OAAA,GAAU,IAAI,cAAA,EAAsC;AAAA,EAC7D,kBAAyC,EAAC;AAAA,EAC1C,YAAA,GAAe,CAAA;AAAA,EAEvB,oBAAuB,OAAA,EAAsD;AAC3E,IAAA,MAAM,OAAA,GAAU,IAAI,oBAAA,EAAwB;AAE5C,IAAA,MAAM,QAAQ,IAAA,CAAK,YAAA;AACnB,IAAA,IAAA,CAAK,YAAA,EAAA;AAEL,IAAA,OAAA,CAAQ,OAAA,GAAU,SAAA,CAAU;AAAA,MAC1B,MAAM,CAAA,YAAA,KAAgB;AACpB,QAAA,MAAM,WAAA,GAAc,IAAA,CAAK,eAAA,CAAgB,KAAA,EAAM;AAC/C,QAAA,MAAM,OAAA,GAAU,IAAA,CAAK,eAAA,CAAgB,YAAA,EAAc,OAAO,CAAA;AAC1D,QAAA,IAAI,CAAC,OAAA,EAAS;AACZ,UAAA,OAAO,YAAY,KAAK,CAAA;AAAA,QAC1B,CAAA,MAAO;AACL,UAAA,WAAA,CAAY,KAAK,CAAA,GAAI,OAAA;AAAA,QACvB;AACA,QAAA,IAAA,CAAK,eAAA,GAAkB,WAAA;AAEvB,QAAA,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,WAAA,CAAY,MAAA,CAAO,OAAO,CAAC,CAAA;AAAA,MAC/C;AAAA,KACD,CAAA;AAED,IAAA,OAAO,CAAA,MAAA,KAAU;AACf,MAAA,OAAO,OAAA,CAAQ,QAAQ,MAAM,CAAA;AAAA,IAC/B,CAAA;AAAA,EACF;AAAA;AAAA,EAGQ,eAAA,CACN,SACA,OAAA,EACiC;AACjC,IAAA,MAAM,EAAE,QAAO,GAAI,OAAA;AACnB,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,OAAO,MAAA;AAAA,IACT;AAEA,IAAA,OAAO;AAAA,MACL,UAAU,OAAA,CAAQ,QAAA;AAAA,MAClB,SAAS,YAAY;AACnB,QAAA,MAAM,MAAA,GAAS,MAAM,OAAA,CAAQ,aAAA,CAAc,MAAM,CAAA;AACjD,QAAA,OAAA,CAAQ,QAAQ,MAAM,CAAA;AAAA,MACxB,CAAA;AAAA,MACA,QAAQ,MAAM;AACZ,QAAA,MAAM,KAAA,GAAQ,IAAI,KAAA,CAAM,gCAAgC,CAAA;AACxD,QAAA,KAAA,CAAM,IAAA,GAAO,eAAA;AACb,QAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,MACtB;AAAA,KACF;AAAA,EACF;AAAA,EAEA,YAAA,GAAkD;AAChD,IAAA,OAAO,IAAA,CAAK,OAAA;AAAA,EACd;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"WebStorage.esm.js","sources":["../../../../../../../../../packages/core-app-api/src/apis/implementations/StorageApi/WebStorage.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 StorageApi,\n StorageValueSnapshot,\n ErrorApi,\n} from '@backstage/core-plugin-api';\nimport { JsonValue, Observable } from '@backstage/types';\nimport ObservableImpl from 'zen-observable';\n\nexport const buckets = new Map<string, WebStorage>();\n\n/**\n * An implementation of the storage API, that uses the browser's local storage.\n *\n * @public\n */\nexport class WebStorage implements StorageApi {\n constructor(\n private readonly namespace: string,\n private readonly errorApi: ErrorApi,\n ) {}\n\n private static hasSubscribed = false;\n\n static create(options: {\n errorApi: ErrorApi;\n namespace?: string;\n }): WebStorage {\n return new WebStorage(options.namespace ?? '', options.errorApi);\n }\n\n private static addStorageEventListener() {\n window.addEventListener('storage', event => {\n for (const [bucketPath, webStorage] of buckets.entries()) {\n if (event.key?.startsWith(bucketPath)) {\n webStorage.handleStorageChange(event.key);\n }\n }\n });\n }\n\n get<T>(key: string): T | undefined {\n return this.snapshot(key).value as T | undefined;\n }\n\n snapshot<T extends JsonValue>(key: string): StorageValueSnapshot<T> {\n let value = undefined;\n let presence: 'present' | 'absent' = 'absent';\n try {\n const item = localStorage.getItem(this.getKeyName(key));\n if (item) {\n value = JSON.parse(item, (_key, val) => {\n if (typeof val === 'object' && val !== null) {\n Object.freeze(val);\n }\n return val;\n });\n presence = 'present';\n }\n } catch (e) {\n this.errorApi.post(\n new Error(`Error when parsing JSON config from storage for: ${key}`),\n );\n }\n return { key, value, presence };\n }\n\n forBucket(name: string): WebStorage {\n const bucketPath = `${this.namespace}/${name}`;\n if (!buckets.has(bucketPath)) {\n buckets.set(bucketPath, new WebStorage(bucketPath, this.errorApi));\n }\n return buckets.get(bucketPath)!;\n }\n\n async set<T>(key: string, data: T): Promise<void> {\n localStorage.setItem(this.getKeyName(key), JSON.stringify(data));\n this.notifyChanges(key);\n }\n\n async remove(key: string): Promise<void> {\n localStorage.removeItem(this.getKeyName(key));\n this.notifyChanges(key);\n }\n\n observe$<T extends JsonValue>(\n key: string,\n ): Observable<StorageValueSnapshot<T>> {\n if (!WebStorage.hasSubscribed) {\n WebStorage.addStorageEventListener();\n WebStorage.hasSubscribed = true;\n }\n return this.observable.filter(({ key: messageKey }) => messageKey === key);\n }\n\n private handleStorageChange(eventKey: StorageEvent['key']) {\n if (!eventKey?.startsWith(this.namespace)) {\n return;\n }\n // Grab the part of this key that is local to this bucket\n const trimmedKey = eventKey?.slice(`${this.namespace}/`.length);\n\n // If the key still contains a slash, it means it's a sub-bucket\n if (!trimmedKey.includes('/')) {\n this.notifyChanges(decodeURIComponent(trimmedKey));\n }\n }\n\n private getKeyName(key: string) {\n return `${this.namespace}/${encodeURIComponent(key)}`;\n }\n\n private notifyChanges(key: string) {\n const snapshot = this.snapshot(key);\n for (const subscription of this.subscribers) {\n subscription.next(snapshot);\n }\n }\n\n private subscribers = new Set<\n ZenObservable.SubscriptionObserver<StorageValueSnapshot<JsonValue>>\n >();\n\n private readonly observable = new ObservableImpl<\n StorageValueSnapshot<JsonValue>\n >(subscriber => {\n this.subscribers.add(subscriber);\n return () => {\n this.subscribers.delete(subscriber);\n };\n });\n}\n"],"names":[],"mappings":";;AAwBa,MAAA,OAAA,uBAAc,GAAwB;AAO5C,MAAM,UAAiC,CAAA;AAAA,EAC5C,WAAA,CACmB,WACA,QACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAAA;AAChB,EAEH,OAAe,aAAgB,GAAA,KAAA;AAAA,EAE/B,OAAO,OAAO,OAGC,EAAA;AACb,IAAA,OAAO,IAAI,UAAW,CAAA,OAAA,CAAQ,SAAa,IAAA,EAAA,EAAI,QAAQ,QAAQ,CAAA;AAAA;AACjE,EAEA,OAAe,uBAA0B,GAAA;AACvC,IAAO,MAAA,CAAA,gBAAA,CAAiB,WAAW,CAAS,KAAA,KAAA;AAC1C,MAAA,KAAA,MAAW,CAAC,UAAY,EAAA,UA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a,EAAA;AAC9B,IAAA,OAAO,GAAG,IAAK,CAAA,SAAS,CAAI,CAAA,EAAA,kBAAA,CAAmB,GAAG,CAAC,CAAA,CAAA;AAAA;AACrD,EAEQ,cAAc,GAAa,EAAA;AACjC,IAAM,MAAA,QAAA,GAAW,IAAK,CAAA,QAAA,CAAS,GAAG,CAAA;AAClC,IAAW,KAAA,MAAA,YAAA,IAAgB,KAAK,WAAa,EAAA;AAC3C,MAAA,YAAA,CAAa,KAAK,QAAQ,CAAA;AAAA;AAC5B;AACF,EAEQ,WAAA,uBAAkB,GAExB,EAAA;AAAA,EAEe,UAAA,GAAa,IAAI,cAAA,CAEhC,CAAc,UAAA,KAAA;AACd,IAAK,IAAA,CAAA,WAAA,CAAY,IAAI,UAAU,CAAA;AAC/B,IAAA,OAAO,MAAM;AACX,MAAK,IAAA,CAAA,WAAA,CAAY,OAAO,UAAU,CAAA;AAAA,KACpC;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"WebStorage.esm.js","sources":["../../../../../../../../../packages/core-app-api/src/apis/implementations/StorageApi/WebStorage.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 StorageApi,\n StorageValueSnapshot,\n ErrorApi,\n} from '@backstage/core-plugin-api';\nimport { JsonValue, Observable } from '@backstage/types';\nimport ObservableImpl from 'zen-observable';\n\nexport const buckets = new Map<string, WebStorage>();\n\n/**\n * An implementation of the storage API, that uses the browser's local storage.\n *\n * @public\n */\nexport class WebStorage implements StorageApi {\n constructor(\n private readonly namespace: string,\n private readonly errorApi: ErrorApi,\n ) {}\n\n private static hasSubscribed = false;\n\n static create(options: {\n errorApi: ErrorApi;\n namespace?: string;\n }): WebStorage {\n return new WebStorage(options.namespace ?? '', options.errorApi);\n }\n\n private static addStorageEventListener() {\n window.addEventListener('storage', event => {\n for (const [bucketPath, webStorage] of buckets.entries()) {\n if (event.key?.startsWith(bucketPath)) {\n webStorage.handleStorageChange(event.key);\n }\n }\n });\n }\n\n get<T>(key: string): T | undefined {\n return this.snapshot(key).value as T | undefined;\n }\n\n snapshot<T extends JsonValue>(key: string): StorageValueSnapshot<T> {\n let value = undefined;\n let presence: 'present' | 'absent' = 'absent';\n try {\n const item = localStorage.getItem(this.getKeyName(key));\n if (item) {\n value = JSON.parse(item, (_key, val) => {\n if (typeof val === 'object' && val !== null) {\n Object.freeze(val);\n }\n return val;\n });\n presence = 'present';\n }\n } catch (e) {\n this.errorApi.post(\n new Error(`Error when parsing JSON config from storage for: ${key}`),\n );\n }\n return { key, value, presence };\n }\n\n forBucket(name: string): WebStorage {\n const bucketPath = `${this.namespace}/${name}`;\n if (!buckets.has(bucketPath)) {\n buckets.set(bucketPath, new WebStorage(bucketPath, this.errorApi));\n }\n return buckets.get(bucketPath)!;\n }\n\n async set<T>(key: string, data: T): Promise<void> {\n localStorage.setItem(this.getKeyName(key), JSON.stringify(data));\n this.notifyChanges(key);\n }\n\n async remove(key: string): Promise<void> {\n localStorage.removeItem(this.getKeyName(key));\n this.notifyChanges(key);\n }\n\n observe$<T extends JsonValue>(\n key: string,\n ): Observable<StorageValueSnapshot<T>> {\n if (!WebStorage.hasSubscribed) {\n WebStorage.addStorageEventListener();\n WebStorage.hasSubscribed = true;\n }\n return this.observable.filter(({ key: messageKey }) => messageKey === key);\n }\n\n private handleStorageChange(eventKey: StorageEvent['key']) {\n if (!eventKey?.startsWith(this.namespace)) {\n return;\n }\n // Grab the part of this key that is local to this bucket\n const trimmedKey = eventKey?.slice(`${this.namespace}/`.length);\n\n // If the key still contains a slash, it means it's a sub-bucket\n if (!trimmedKey.includes('/')) {\n this.notifyChanges(decodeURIComponent(trimmedKey));\n }\n }\n\n private getKeyName(key: string) {\n return `${this.namespace}/${encodeURIComponent(key)}`;\n }\n\n private notifyChanges(key: string) {\n const snapshot = this.snapshot(key);\n for (const subscription of this.subscribers) {\n subscription.next(snapshot);\n }\n }\n\n private subscribers = new Set<\n ZenObservable.SubscriptionObserver<StorageValueSnapshot<JsonValue>>\n >();\n\n private readonly observable = new ObservableImpl<\n StorageValueSnapshot<JsonValue>\n >(subscriber => {\n this.subscribers.add(subscriber);\n return () => {\n this.subscribers.delete(subscriber);\n };\n });\n}\n"],"names":[],"mappings":";;AAwBO,MAAM,OAAA,uBAAc,GAAA;AAOpB,MAAM,UAAA,CAAiC;AAAA,EAC5C,WAAA,CACmB,WACA,QAAA,EACjB;AAFiB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAAA,EAChB;AAAA,EAEH,OAAe,aAAA,GAAgB,KAAA;AAAA,EAE/B,OAAO,OAAO,OAAA,EAGC;AACb,IAAA,OAAO,IAAI,UAAA,CAAW,OAAA,CAAQ,SAAA,IAAa,EAAA,EAAI,QAAQ,QAAQ,CAAA;AAAA,EACjE;AAAA,EAEA,OAAe,uBAAA,GAA0B;AACvC,IAAA,MAAA,CAAO,gBAAA,CAAiB,WAAW,CAAA,KAAA,KAAS;AAC1C,MAAA,KAAA,MAAW,CAAC,UAAA,EAAY,UAAU,CAAA,IAAK,OAAA,CAAQ,SAAQ,EAAG;AACxD,QAAA,IAAI,KAAA,CAAM,GAAA,EAAK,UAAA,CAAW,UAAU,CAAA,EAAG;AACrC,UAAA,UAAA,CAAW,mBAAA,CAAoB,MAAM,GAAG,CAAA;AAAA,QAC1C;AAAA,MACF;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AAAA,EAEA,IAAO,GAAA,EAA4B;AACjC,IAAA,OAAO,IAAA,CAAK,QAAA,CAAS,GAAG,CAA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AAG,CAAA;AAClC,IAAA,KAAA,MAAW,YAAA,IAAgB,KAAK,WAAA,EAAa;AAC3C,MAAA,YAAA,CAAa,KAAK,QAAQ,CAAA;AAAA,IAC5B;AAAA,EACF;AAAA,EAEQ,WAAA,uBAAkB,GAAA,EAExB;AAAA,EAEe,UAAA,GAAa,IAAI,cAAA,CAEhC,CAAA,UAAA,KAAc;AACd,IAAA,IAAA,CAAK,WAAA,CAAY,IAAI,UAAU,CAAA;AAC/B,IAAA,OAAO,MAAM;AACX,MAAA,IAAA,CAAK,WAAA,CAAY,OAAO,UAAU,CAAA;AAAA,IACpC,CAAA;AAAA,EACF,CAAC,CAAA;AACH;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"I18nextTranslationApi.esm.js","sources":["../../../../../../../../../packages/core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.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\nimport {\n AppLanguageApi,\n TranslationApi,\n TranslationFunction,\n TranslationMessages,\n TranslationRef,\n TranslationResource,\n TranslationSnapshot,\n} from '@backstage/core-plugin-api/alpha';\nimport {\n createInstance as createI18n,\n FormatFunction,\n Interpolator,\n TFunction,\n type i18n as I18n,\n} from 'i18next';\nimport ObservableImpl from 'zen-observable';\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 {\n toInternalTranslationResource,\n InternalTranslationResourceLoader,\n} from '../../../../../core-plugin-api/src/translation/TranslationResource';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport {\n toInternalTranslationRef,\n InternalTranslationRef,\n} from '../../../../../core-plugin-api/src/translation/TranslationRef';\nimport { Observable } from '@backstage/types';\nimport { DEFAULT_LANGUAGE } from '../AppLanguageApi/AppLanguageSelector';\nimport { createElement, Fragment, ReactNode, isValidElement } from 'react';\n\n/** @alpha */\nexport interface I18nextTranslationApiOptions {\n languageApi: AppLanguageApi;\n resources?: Array<TranslationMessages | TranslationResource>;\n}\n\nfunction removeNulls(\n messages: Record<string, string | null>,\n): Record<string, string> {\n return Object.fromEntries(\n Object.entries(messages).filter(\n (e): e is [string, string] => e[1] !== null,\n ),\n );\n}\n\n/**\n * The built-in i18next backend loading logic doesn't handle on the fly switches\n * of language very well. It gets a bit confused about whether resources are actually\n * loaded or not, so instead we implement our own resource loader.\n */\nclass ResourceLoader {\n /** Loaded resources by loader key */\n #loaded = new Set<string>();\n /** Resource loading promises by loader key */\n #loading = new Map<string, Promise<void>>();\n /** Loaders for each resource language */\n #loaders = new Map<string, InternalTranslationResourceLoader>();\n\n constructor(\n private readonly onLoad: (loaded: {\n language: string;\n namespace: string;\n messages: Record<string, string | null>;\n }) => void,\n ) {}\n\n addTranslationResource(resource: TranslationResource) {\n const internalResource = toInternalTranslationResource(resource);\n for (const entry of internalResource.resources) {\n const key = this.#getLoaderKey(entry.language, internalResource.id);\n\n // First loader to register wins, this means that resources registered in the app\n // have priority over default resource from translation refs\n if (!this.#loaders.has(key)) {\n this.#loaders.set(key, entry.loader);\n }\n }\n }\n\n #getLoaderKey(language: string, namespace: string) {\n return `${language}/${namespace}`;\n }\n\n needsLoading(language: string, namespace: string) {\n const key = this.#getLoaderKey(language, namespace);\n const loader = this.#loaders.get(key);\n if (!loader) {\n return false;\n }\n\n return !this.#loaded.has(key);\n }\n\n async load(language: string, namespace: string): Promise<void> {\n const key = this.#getLoaderKey(language, namespace);\n\n const loader = this.#loaders.get(key);\n if (!loader) {\n return;\n }\n\n if (this.#loaded.has(key)) {\n return;\n }\n\n const loading = this.#loading.get(key);\n if (loading) {\n await loading;\n return;\n }\n\n const load = loader().then(\n result => {\n this.onLoad({ language, namespace, messages: result.messages });\n this.#loaded.add(key);\n },\n error => {\n this.#loaded.add(key); // Do not try to load failed resources again\n throw error;\n },\n );\n this.#loading.set(key, load);\n await load;\n }\n}\n\n/**\n * A helper for implementing JSX interpolation\n */\nexport class JsxInterpolator {\n readonly #setFormatHook: (hook: FormatFunction) => void;\n readonly #marker: string;\n readonly #pattern: RegExp;\n\n static fromI18n(i18n: I18n) {\n const interpolator = i18n.services.interpolator as Interpolator & {\n format: FormatFunction;\n };\n const originalFormat = interpolator.format;\n\n let formatHook: FormatFunction | undefined;\n\n // This is the only way to override the format function of the interpolator\n // without overriding the default formatters. See the behavior here:\n // https://github.com/i18next/i18next/blob/c633121e57e2b6024080142d78027842bf2a6e5e/src/i18next.js#L120-L125\n interpolator.format = (value, format, lng, formatOpts) => {\n if (format) {\n return originalFormat(value, format, lng, formatOpts);\n }\n return formatHook?.(value, format, lng, formatOpts) ?? value;\n };\n\n return new JsxInterpolator(\n // Using a random marker to ensure it can't be misused\n Math.random().toString(36).substring(2, 8),\n hook => {\n formatHook = hook;\n },\n );\n }\n\n private constructor(\n marker: string,\n setFormatHook: (hook: FormatFunction) => void,\n ) {\n this.#setFormatHook = setFormatHook;\n this.#marker = marker;\n this.#pattern = new RegExp(`\\\\$${marker}\\\\(([^)]+)\\\\)`);\n }\n\n wrapT<TMessages extends { [key in string]: string }>(\n originalT: TFunction,\n ): TranslationFunction<TMessages> {\n return ((key, options) => {\n let elementsMap: Map<string, ReactNode> | undefined = undefined;\n\n // There's no way to override the format hook via the translation function\n // options, event though types indicate that it might be possible.\n // Instead, override the format function hook before every invocation and\n // rely on synchronous execution.\n this.#setFormatHook(value => {\n if (isValidElement(value)) {\n if (!elementsMap) {\n elementsMap = new Map();\n }\n const elementKey = elementsMap.size.toString();\n elementsMap.set(elementKey, value);\n\n return `$${this.#marker}(${elementKey})`;\n }\n return value;\n });\n\n // Overriding the return options is not allowed via TranslationFunction,\n // so this will always be a string\n const result = originalT(key, options as any) as unknown as string;\n if (!elementsMap) {\n return result;\n }\n\n const split = result.split(this.#pattern);\n\n return createElement(\n Fragment,\n null,\n ...split\n .map((part, index) => {\n if (index % 2 === 0) {\n return part;\n }\n return elementsMap?.get(part);\n })\n .filter(Boolean),\n );\n }) as TranslationFunction<TMessages>;\n }\n}\n\n/** @alpha */\nexport class I18nextTranslationApi implements TranslationApi {\n static create(options: I18nextTranslationApiOptions) {\n const { languages } = options.languageApi.getAvailableLanguages();\n\n const i18n = createI18n({\n fallbackLng: DEFAULT_LANGUAGE,\n supportedLngs: languages,\n interpolation: {\n escapeValue: false,\n // Used for the JsxInterpolator format hook\n alwaysFormat: true,\n },\n ns: [],\n defaultNS: false,\n fallbackNS: false,\n\n // Disable resource loading on init, meaning i18n will be ready to use immediately\n initImmediate: false,\n });\n\n i18n.init();\n if (!i18n.isInitialized) {\n throw new Error('i18next was unexpectedly not initialized');\n }\n\n const interpolator = JsxInterpolator.fromI18n(i18n);\n\n const { language: initialLanguage } = options.languageApi.getLanguage();\n if (initialLanguage !== DEFAULT_LANGUAGE) {\n i18n.changeLanguage(initialLanguage);\n }\n\n const loader = new ResourceLoader(loaded => {\n i18n.addResourceBundle(\n loaded.language,\n loaded.namespace,\n removeNulls(loaded.messages),\n false, // do not merge with existing translations\n true, // overwrite translations\n );\n });\n\n const resources = options?.resources || [];\n // Iterate in reverse, giving higher priority to resources registered later\n for (let i = resources.length - 1; i >= 0; i--) {\n const resource = resources[i];\n if (resource.$$type === '@backstage/TranslationResource') {\n loader.addTranslationResource(resource);\n } else if (resource.$$type === '@backstage/TranslationMessages') {\n // Overrides for default messages, created with createTranslationMessages and installed via app\n i18n.addResourceBundle(\n DEFAULT_LANGUAGE,\n resource.id,\n removeNulls(resource.messages),\n true, // merge with existing translations\n false, // do not overwrite translations\n );\n }\n }\n\n const instance = new I18nextTranslationApi(\n i18n,\n loader,\n options.languageApi.getLanguage().language,\n interpolator,\n );\n\n options.languageApi.language$().subscribe(({ language }) => {\n instance.#changeLanguage(language);\n });\n\n return instance;\n }\n\n #i18n: I18n;\n #loader: ResourceLoader;\n #language: string;\n #jsxInterpolator: JsxInterpolator;\n\n /** Keep track of which refs we have registered default resources for */\n #registeredRefs = new Set<string>();\n /** Notify observers when language changes */\n #languageChangeListeners = new Set<() => void>();\n\n private constructor(\n i18n: I18n,\n loader: ResourceLoader,\n language: string,\n jsxInterpolator: JsxInterpolator,\n ) {\n this.#i18n = i18n;\n this.#loader = loader;\n this.#language = language;\n this.#jsxInterpolator = jsxInterpolator;\n }\n\n getTranslation<TMessages extends { [key in string]: string }>(\n translationRef: TranslationRef<string, TMessages>,\n ): TranslationSnapshot<TMessages> {\n const internalRef = toInternalTranslationRef(translationRef);\n\n this.#registerDefaults(internalRef);\n\n return this.#createSnapshot(internalRef);\n }\n\n translation$<TMessages extends { [key in string]: string }>(\n translationRef: TranslationRef<string, TMessages>,\n ): Observable<TranslationSnapshot<TMessages>> {\n const internalRef = toInternalTranslationRef(translationRef);\n\n this.#registerDefaults(internalRef);\n\n return new ObservableImpl<TranslationSnapshot<TMessages>>(subscriber => {\n let loadTicket = {}; // To check for stale loads\n\n const loadResource = () => {\n loadTicket = {};\n const ticket = loadTicket;\n this.#loader.load(this.#language, internalRef.id).then(\n () => {\n if (ticket === loadTicket) {\n const snapshot = this.#createSnapshot(internalRef);\n if (snapshot.ready) {\n subscriber.next(snapshot);\n }\n }\n },\n error => {\n if (ticket === loadTicket) {\n subscriber.error(Array.isArray(error) ? error[0] : error);\n }\n },\n );\n };\n\n const onChange = () => {\n const snapshot = this.#createSnapshot(internalRef);\n if (snapshot.ready) {\n subscriber.next(snapshot);\n } else {\n loadResource();\n }\n };\n\n if (this.#loader.needsLoading(this.#language, internalRef.id)) {\n loadResource();\n }\n\n this.#languageChangeListeners.add(onChange);\n return () => {\n this.#languageChangeListeners.delete(onChange);\n };\n });\n }\n\n #changeLanguage(language: string): void {\n if (this.#language !== language) {\n this.#language = language;\n this.#i18n.changeLanguage(language);\n this.#languageChangeListeners.forEach(listener => listener());\n }\n }\n\n #createSnapshot<TMessages extends { [key in string]: string }>(\n internalRef: InternalTranslationRef<string, TMessages>,\n ): TranslationSnapshot<TMessages> {\n if (this.#loader.needsLoading(this.#language, internalRef.id)) {\n return { ready: false };\n }\n\n const unwrappedT = this.#i18n.getFixedT(null, internalRef.id);\n const t = this.#jsxInterpolator.wrapT<TMessages>(unwrappedT);\n\n return {\n ready: true,\n t,\n };\n }\n\n #registerDefaults(internalRef: InternalTranslationRef): void {\n if (this.#registeredRefs.has(internalRef.id)) {\n return;\n }\n this.#registeredRefs.add(internalRef.id);\n\n const defaultMessages = internalRef.getDefaultMessages();\n this.#i18n.addResourceBundle(\n DEFAULT_LANGUAGE,\n internalRef.id,\n defaultMessages,\n true, // merge with existing translations\n false, // do not overwrite translations\n );\n\n const defaultResource = internalRef.getDefaultResource();\n if (defaultResource) {\n this.#loader.addTranslationResource(defaultResource);\n }\n }\n}\n"],"names":["createI18n"],"mappings":";;;;;;;AAuDA,SAAS,YACP,QACwB,EAAA;AACxB,EAAA,OAAO,MAAO,CAAA,WAAA;AAAA,IACZ,MAAA,CAAO,OAAQ,CAAA,QAAQ,CAAE,CAAA,MAAA;AAAA,MACvB,CAAC,CAAA,KAA6B,CAAE,CAAA,CAAC,CAAM,KAAA;AAAA;AACzC,GACF;AACF;AAOA,MAAM,cAAe,CAAA;AAAA,EAQnB,YACmB,MAKjB,EAAA;AALiB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA;AAKhB;AAAA,EAZH,OAAA,uBAAc,GAAY,EAAA;AAAA;AAAA,EAE1B,QAAA,uBAAe,GAA2B,EAAA;AAAA;AAAA,EAE1C,QAAA,uBAAe,GAA+C,EAAA;AAAA,EAU9D,uBAAuB,QAA+B,EAAA;AACpD,IAAM,MAAA,gBAAA,GAAmB,8BAA8B,QAAQ,CAAA;AAC/D,IAAW,KAAA,MAAA,K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A;AAEF,IAAK,IAAA,CAAA,eAAA,CAAgB,GAAI,CAAA,WAAA,CAAY,EAAE,CAAA;AAEvC,IAAM,MAAA,eAAA,GAAkB,YAAY,kBAAmB,EAAA;AACvD,IAAA,IAAA,CAAK,KAAM,CAAA,iBAAA;AAAA,MACT,gBAAA;AAAA,MACA,WAAY,CAAA,EAAA;AAAA,MACZ,eAAA;AAAA,MACA,IAAA;AAAA;AAAA,MACA;AAAA;AAAA,KACF;AAEA,IAAM,MAAA,eAAA,GAAkB,YAAY,kBAAmB,EAAA;AACvD,IAAA,IAAI,eAAiB,EAAA;AACnB,MAAK,IAAA,CAAA,OAAA,CAAQ,uBAAuB,eAAe,CAAA;AAAA;AACrD;AAEJ;;;;"}
1
+ {"version":3,"file":"I18nextTranslationApi.esm.js","sources":["../../../../../../../../../packages/core-app-api/src/apis/implementations/TranslationApi/I18nextTranslationApi.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\nimport {\n AppLanguageApi,\n TranslationApi,\n TranslationFunction,\n TranslationMessages,\n TranslationRef,\n TranslationResource,\n TranslationSnapshot,\n} from '@backstage/core-plugin-api/alpha';\nimport {\n createInstance as createI18n,\n FormatFunction,\n Interpolator,\n TFunction,\n type i18n as I18n,\n} from 'i18next';\nimport ObservableImpl from 'zen-observable';\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 {\n toInternalTranslationResource,\n InternalTranslationResourceLoader,\n} from '../../../../../core-plugin-api/src/translation/TranslationResource';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport {\n toInternalTranslationRef,\n InternalTranslationRef,\n} from '../../../../../core-plugin-api/src/translation/TranslationRef';\nimport { Observable } from '@backstage/types';\nimport { DEFAULT_LANGUAGE } from '../AppLanguageApi/AppLanguageSelector';\nimport { createElement, Fragment, ReactNode, isValidElement } from 'react';\n\n/** @alpha */\nexport interface I18nextTranslationApiOptions {\n languageApi: AppLanguageApi;\n resources?: Array<TranslationMessages | TranslationResource>;\n}\n\nfunction removeNulls(\n messages: Record<string, string | null>,\n): Record<string, string> {\n return Object.fromEntries(\n Object.entries(messages).filter(\n (e): e is [string, string] => e[1] !== null,\n ),\n );\n}\n\n/**\n * The built-in i18next backend loading logic doesn't handle on the fly switches\n * of language very well. It gets a bit confused about whether resources are actually\n * loaded or not, so instead we implement our own resource loader.\n */\nclass ResourceLoader {\n /** Loaded resources by loader key */\n #loaded = new Set<string>();\n /** Resource loading promises by loader key */\n #loading = new Map<string, Promise<void>>();\n /** Loaders for each resource language */\n #loaders = new Map<string, InternalTranslationResourceLoader>();\n\n constructor(\n private readonly onLoad: (loaded: {\n language: string;\n namespace: string;\n messages: Record<string, string | null>;\n }) => void,\n ) {}\n\n addTranslationResource(resource: TranslationResource) {\n const internalResource = toInternalTranslationResource(resource);\n for (const entry of internalResource.resources) {\n const key = this.#getLoaderKey(entry.language, internalResource.id);\n\n // First loader to register wins, this means that resources registered in the app\n // have priority over default resource from translation refs\n if (!this.#loaders.has(key)) {\n this.#loaders.set(key, entry.loader);\n }\n }\n }\n\n #getLoaderKey(language: string, namespace: string) {\n return `${language}/${namespace}`;\n }\n\n needsLoading(language: string, namespace: string) {\n const key = this.#getLoaderKey(language, namespace);\n const loader = this.#loaders.get(key);\n if (!loader) {\n return false;\n }\n\n return !this.#loaded.has(key);\n }\n\n async load(language: string, namespace: string): Promise<void> {\n const key = this.#getLoaderKey(language, namespace);\n\n const loader = this.#loaders.get(key);\n if (!loader) {\n return;\n }\n\n if (this.#loaded.has(key)) {\n return;\n }\n\n const loading = this.#loading.get(key);\n if (loading) {\n await loading;\n return;\n }\n\n const load = loader().then(\n result => {\n this.onLoad({ language, namespace, messages: result.messages });\n this.#loaded.add(key);\n },\n error => {\n this.#loaded.add(key); // Do not try to load failed resources again\n throw error;\n },\n );\n this.#loading.set(key, load);\n await load;\n }\n}\n\n/**\n * A helper for implementing JSX interpolation\n */\nexport class JsxInterpolator {\n readonly #setFormatHook: (hook: FormatFunction) => void;\n readonly #marker: string;\n readonly #pattern: RegExp;\n\n static fromI18n(i18n: I18n) {\n const interpolator = i18n.services.interpolator as Interpolator & {\n format: FormatFunction;\n };\n const originalFormat = interpolator.format;\n\n let formatHook: FormatFunction | undefined;\n\n // This is the only way to override the format function of the interpolator\n // without overriding the default formatters. See the behavior here:\n // https://github.com/i18next/i18next/blob/c633121e57e2b6024080142d78027842bf2a6e5e/src/i18next.js#L120-L125\n interpolator.format = (value, format, lng, formatOpts) => {\n if (format) {\n return originalFormat(value, format, lng, formatOpts);\n }\n return formatHook?.(value, format, lng, formatOpts) ?? value;\n };\n\n return new JsxInterpolator(\n // Using a random marker to ensure it can't be misused\n Math.random().toString(36).substring(2, 8),\n hook => {\n formatHook = hook;\n },\n );\n }\n\n private constructor(\n marker: string,\n setFormatHook: (hook: FormatFunction) => void,\n ) {\n this.#setFormatHook = setFormatHook;\n this.#marker = marker;\n this.#pattern = new RegExp(`\\\\$${marker}\\\\(([^)]+)\\\\)`);\n }\n\n wrapT<TMessages extends { [key in string]: string }>(\n originalT: TFunction,\n ): TranslationFunction<TMessages> {\n return ((key, options) => {\n let elementsMap: Map<string, ReactNode> | undefined = undefined;\n\n // There's no way to override the format hook via the translation function\n // options, event though types indicate that it might be possible.\n // Instead, override the format function hook before every invocation and\n // rely on synchronous execution.\n this.#setFormatHook(value => {\n if (isValidElement(value)) {\n if (!elementsMap) {\n elementsMap = new Map();\n }\n const elementKey = elementsMap.size.toString();\n elementsMap.set(elementKey, value);\n\n return `$${this.#marker}(${elementKey})`;\n }\n return value;\n });\n\n // Overriding the return options is not allowed via TranslationFunction,\n // so this will always be a string\n const result = originalT(key, options as any) as unknown as string;\n if (!elementsMap) {\n return result;\n }\n\n const split = result.split(this.#pattern);\n\n return createElement(\n Fragment,\n null,\n ...split\n .map((part, index) => {\n if (index % 2 === 0) {\n return part;\n }\n return elementsMap?.get(part);\n })\n .filter(Boolean),\n );\n }) as TranslationFunction<TMessages>;\n }\n}\n\n/** @alpha */\nexport class I18nextTranslationApi implements TranslationApi {\n static create(options: I18nextTranslationApiOptions) {\n const { languages } = options.languageApi.getAvailableLanguages();\n\n const i18n = createI18n({\n fallbackLng: DEFAULT_LANGUAGE,\n supportedLngs: languages,\n interpolation: {\n escapeValue: false,\n // Used for the JsxInterpolator format hook\n alwaysFormat: true,\n },\n ns: [],\n defaultNS: false,\n fallbackNS: false,\n\n // Disable resource loading on init, meaning i18n will be ready to use immediately\n initImmediate: false,\n });\n\n i18n.init();\n if (!i18n.isInitialized) {\n throw new Error('i18next was unexpectedly not initialized');\n }\n\n const interpolator = JsxInterpolator.fromI18n(i18n);\n\n const { language: initialLanguage } = options.languageApi.getLanguage();\n if (initialLanguage !== DEFAULT_LANGUAGE) {\n i18n.changeLanguage(initialLanguage);\n }\n\n const loader = new ResourceLoader(loaded => {\n i18n.addResourceBundle(\n loaded.language,\n loaded.namespace,\n removeNulls(loaded.messages),\n false, // do not merge with existing translations\n true, // overwrite translations\n );\n });\n\n const resources = options?.resources || [];\n // Iterate in reverse, giving higher priority to resources registered later\n for (let i = resources.length - 1; i >= 0; i--) {\n const resource = resources[i];\n if (resource.$$type === '@backstage/TranslationResource') {\n loader.addTranslationResource(resource);\n } else if (resource.$$type === '@backstage/TranslationMessages') {\n // Overrides for default messages, created with createTranslationMessages and installed via app\n i18n.addResourceBundle(\n DEFAULT_LANGUAGE,\n resource.id,\n removeNulls(resource.messages),\n true, // merge with existing translations\n false, // do not overwrite translations\n );\n }\n }\n\n const instance = new I18nextTranslationApi(\n i18n,\n loader,\n options.languageApi.getLanguage().language,\n interpolator,\n );\n\n options.languageApi.language$().subscribe(({ language }) => {\n instance.#changeLanguage(language);\n });\n\n return instance;\n }\n\n #i18n: I18n;\n #loader: ResourceLoader;\n #language: string;\n #jsxInterpolator: JsxInterpolator;\n\n /** Keep track of which refs we have registered default resources for */\n #registeredRefs = new Set<string>();\n /** Notify observers when language changes */\n #languageChangeListeners = new Set<() => void>();\n\n private constructor(\n i18n: I18n,\n loader: ResourceLoader,\n language: string,\n jsxInterpolator: JsxInterpolator,\n ) {\n this.#i18n = i18n;\n this.#loader = loader;\n this.#language = language;\n this.#jsxInterpolator = jsxInterpolator;\n }\n\n getTranslation<TMessages extends { [key in string]: string }>(\n translationRef: TranslationRef<string, TMessages>,\n ): TranslationSnapshot<TMessages> {\n const internalRef = toInternalTranslationRef(translationRef);\n\n this.#registerDefaults(internalRef);\n\n return this.#createSnapshot(internalRef);\n }\n\n translation$<TMessages extends { [key in string]: string }>(\n translationRef: TranslationRef<string, TMessages>,\n ): Observable<TranslationSnapshot<TMessages>> {\n const internalRef = toInternalTranslationRef(translationRef);\n\n this.#registerDefaults(internalRef);\n\n return new ObservableImpl<TranslationSnapshot<TMessages>>(subscriber => {\n let loadTicket = {}; // To check for stale loads\n\n const loadResource = () => {\n loadTicket = {};\n const ticket = loadTicket;\n this.#loader.load(this.#language, internalRef.id).then(\n () => {\n if (ticket === loadTicket) {\n const snapshot = this.#createSnapshot(internalRef);\n if (snapshot.ready) {\n subscriber.next(snapshot);\n }\n }\n },\n error => {\n if (ticket === loadTicket) {\n subscriber.error(Array.isArray(error) ? error[0] : error);\n }\n },\n );\n };\n\n const onChange = () => {\n const snapshot = this.#createSnapshot(internalRef);\n if (snapshot.ready) {\n subscriber.next(snapshot);\n } else {\n loadResource();\n }\n };\n\n if (this.#loader.needsLoading(this.#language, internalRef.id)) {\n loadResource();\n }\n\n this.#languageChangeListeners.add(onChange);\n return () => {\n this.#languageChangeListeners.delete(onChange);\n };\n });\n }\n\n #changeLanguage(language: string): void {\n if (this.#language !== language) {\n this.#language = language;\n this.#i18n.changeLanguage(language);\n this.#languageChangeListeners.forEach(listener => listener());\n }\n }\n\n #createSnapshot<TMessages extends { [key in string]: string }>(\n internalRef: InternalTranslationRef<string, TMessages>,\n ): TranslationSnapshot<TMessages> {\n if (this.#loader.needsLoading(this.#language, internalRef.id)) {\n return { ready: false };\n }\n\n const unwrappedT = this.#i18n.getFixedT(null, internalRef.id);\n const t = this.#jsxInterpolator.wrapT<TMessages>(unwrappedT);\n\n return {\n ready: true,\n t,\n };\n }\n\n #registerDefaults(internalRef: InternalTranslationRef): void {\n if (this.#registeredRefs.has(internalRef.id)) {\n return;\n }\n this.#registeredRefs.add(internalRef.id);\n\n const defaultMessages = internalRef.getDefaultMessages();\n this.#i18n.addResourceBundle(\n DEFAULT_LANGUAGE,\n internalRef.id,\n defaultMessages,\n true, // merge with existing translations\n false, // do not overwrite translations\n );\n\n const defaultResource = internalRef.getDefaultResource();\n if (defaultResource) {\n this.#loader.addTranslationResource(defaultResource);\n }\n }\n}\n"],"names":["createI18n"],"mappings":";;;;;;;AAuDA,SAAS,YACP,QAAA,EACwB;AACxB,EAAA,OAAO,MAAA,CAAO,WAAA;AAAA,IACZ,MAAA,CAAO,OAAA,CAAQ,QAAQ,CAAA,CAAE,MAAA;AAAA,MACvB,CAAC,CAAA,KAA6B,CAAA,CAAE,CAAC,CAAA,KAAM;AAAA;AACzC,GACF;AACF;AAOA,MAAM,cAAA,CAAe;AAAA,EAQnB,YACmB,MAAA,EAKjB;AALiB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAKhB;AAAA;AAAA,EAZH,OAAA,uBAAc,GAAA,EAAY;AAAA;AAAA,EAE1B,QAAA,uBAAe,GAAA,EAA2B;AAAA;AAAA,EAE1C,QAAA,uBAAe,GAAA,EAA+C;AAAA,EAU9D,uBAAuB,QAAA,EAA+B;AACpD,IAAA,MAAM,gBAAA,GAAmB,8BAA8B,QAAQ,CAAA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AAE,CAAA;AAC5D,IAAA,MAAM,CAAA,GAAI,IAAA,CAAK,gBAAA,CAAiB,KAAA,CAAiB,UAAU,CAAA;AAE3D,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,IAAA;AAAA,MACP;AAAA,KACF;AAAA,EACF;AAAA,EAEA,kBAAkB,WAAA,EAA2C;AAC3D,IAAA,IAAI,IAAA,CAAK,eAAA,CAAgB,GAAA,CAAI,WAAA,CAAY,EAAE,CAAA,EAAG;AAC5C,MAAA;AAAA,IACF;AACA,IAAA,IAAA,CAAK,eAAA,CAAgB,GAAA,CAAI,WAAA,CAAY,EAAE,CAAA;AAEvC,IAAA,MAAM,eAAA,GAAkB,YAAY,kBAAA,EAAmB;AACvD,IAAA,IAAA,CAAK,KAAA,CAAM,iBAAA;AAAA,MACT,gBAAA;AAAA,MACA,WAAA,CAAY,EAAA;AAAA,MACZ,eAAA;AAAA,MACA,IAAA;AAAA;AAAA,MACA;AAAA;AAAA,KACF;AAEA,IAAA,MAAM,eAAA,GAAkB,YAAY,kBAAA,EAAmB;AACvD,IAAA,IAAI,eAAA,EAAiB;AACnB,MAAA,IAAA,CAAK,OAAA,CAAQ,uBAAuB,eAAe,CAAA;AAAA,IACrD;AAAA,EACF;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"AtlassianAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/atlassian/AtlassianAuth.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 { atlassianAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'atlassian',\n title: 'Atlassian',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to Atlassian products.\n *\n * @public\n */\nexport default class AtlassianAuth {\n static create(options: OAuthApiCreateOptions): typeof atlassianAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n });\n }\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,gBAAmB,GAAA;AAAA,EACvB,EAAI,EAAA,WAAA;AAAA,EACJ,KAAO,EAAA,WAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAOA,MAAqB,aAAc,CAAA;AAAA,EACjC,OAAO,OAAO,OAA8D,EAAA;AAC1E,IAAM,MAAA;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAc,GAAA,aAAA;AAAA,MACd,QAAW,GAAA,gBAAA;AAAA,MACX;AAAA,KACE,GAAA,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAO,CAAA;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"AtlassianAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/atlassian/AtlassianAuth.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 { atlassianAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'atlassian',\n title: 'Atlassian',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to Atlassian products.\n *\n * @public\n */\nexport default class AtlassianAuth {\n static create(options: OAuthApiCreateOptions): typeof atlassianAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n });\n }\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,gBAAA,GAAmB;AAAA,EACvB,EAAA,EAAI,WAAA;AAAA,EACJ,KAAA,EAAO,WAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAOA,MAAqB,aAAA,CAAc;AAAA,EACjC,OAAO,OAAO,OAAA,EAA8D;AAC1E,IAAA,MAAM;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA,GAAc,aAAA;AAAA,MACd,QAAA,GAAW,gBAAA;AAAA,MACX;AAAA,KACF,GAAI,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAA,CAAO;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,EACH;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"BitbucketAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/bitbucket/BitbucketAuth.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 BackstageIdentityResponse,\n bitbucketAuthApiRef,\n ProfileInfo,\n} from '@backstage/core-plugin-api';\n\nimport { OAuthApiCreateOptions } from '../types';\nimport { OAuth2 } from '../oauth2';\n\nexport type BitbucketAuthResponse = {\n providerInfo: {\n accessToken: string;\n scope: string;\n expiresInSeconds: number;\n };\n profile: ProfileInfo;\n backstageIdentity: BackstageIdentityResponse;\n};\n\nconst DEFAULT_PROVIDER = {\n id: 'bitbucket',\n title: 'Bitbucket',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to Bitbucket products.\n *\n * @public\n */\nexport default class BitbucketAuth {\n static create(options: OAuthApiCreateOptions): typeof bitbucketAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n defaultScopes = ['account'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n });\n }\n}\n"],"names":[],"mappings":";;AAmCA,MAAM,gBAAmB,GAAA;AAAA,EACvB,EAAI,EAAA,WAAA;AAAA,EACJ,KAAO,EAAA,WAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAOA,MAAqB,aAAc,CAAA;AAAA,EACjC,OAAO,OAAO,OAA8D,EAAA;AAC1E,IAAM,MAAA;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAc,GAAA,aAAA;AAAA,MACd,QAAW,GAAA,gBAAA;AAAA,MACX,eAAA;AAAA,MACA,aAAA,GAAgB,CAAC,SAAS;AAAA,KACxB,GAAA,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAO,CAAA;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"BitbucketAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/bitbucket/BitbucketAuth.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 BackstageIdentityResponse,\n bitbucketAuthApiRef,\n ProfileInfo,\n} from '@backstage/core-plugin-api';\n\nimport { OAuthApiCreateOptions } from '../types';\nimport { OAuth2 } from '../oauth2';\n\nexport type BitbucketAuthResponse = {\n providerInfo: {\n accessToken: string;\n scope: string;\n expiresInSeconds: number;\n };\n profile: ProfileInfo;\n backstageIdentity: BackstageIdentityResponse;\n};\n\nconst DEFAULT_PROVIDER = {\n id: 'bitbucket',\n title: 'Bitbucket',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to Bitbucket products.\n *\n * @public\n */\nexport default class BitbucketAuth {\n static create(options: OAuthApiCreateOptions): typeof bitbucketAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n defaultScopes = ['account'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n });\n }\n}\n"],"names":[],"mappings":";;AAmCA,MAAM,gBAAA,GAAmB;AAAA,EACvB,EAAA,EAAI,WAAA;AAAA,EACJ,KAAA,EAAO,WAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAOA,MAAqB,aAAA,CAAc;AAAA,EACjC,OAAO,OAAO,OAAA,EAA8D;AAC1E,IAAA,MAAM;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA,GAAc,aAAA;AAAA,MACd,QAAA,GAAW,gBAAA;AAAA,MACX,eAAA;AAAA,MACA,aAAA,GAAgB,CAAC,SAAS;AAAA,KAC5B,GAAI,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAA,CAAO;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,EACH;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"BitbucketServerAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/bitbucketServer/BitbucketServerAuth.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 BackstageIdentityResponse,\n bitbucketServerAuthApiRef,\n ProfileInfo,\n} from '@backstage/core-plugin-api';\n\nimport { OAuthApiCreateOptions } from '../types';\nimport { OAuth2 } from '../oauth2';\n\nexport type BitbucketServerAuthResponse = {\n providerInfo: {\n accessToken: string;\n scope: string;\n expiresInSeconds: number;\n };\n profile: ProfileInfo;\n backstageIdentity: BackstageIdentityResponse;\n};\n\nconst DEFAULT_PROVIDER = {\n id: 'bitbucketServer',\n title: 'Bitbucket Server',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to Bitbucket Server.\n * @public\n */\nexport default class BitbucketServerAuth {\n static create(\n options: OAuthApiCreateOptions,\n ): typeof bitbucketServerAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n defaultScopes = ['PROJECT_ADMIN'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n });\n }\n}\n"],"names":[],"mappings":";;AAmCA,MAAM,gBAAmB,GAAA;AAAA,EACvB,EAAI,EAAA,iBAAA;AAAA,EACJ,KAAO,EAAA,kBAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAMA,MAAqB,mBAAoB,CAAA;AAAA,EACvC,OAAO,OACL,OACoC,EAAA;AACpC,IAAM,MAAA;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAc,GAAA,aAAA;AAAA,MACd,QAAW,GAAA,gBAAA;AAAA,MACX,eAAA;AAAA,MACA,aAAA,GAAgB,CAAC,eAAe;AAAA,KAC9B,GAAA,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAO,CAAA;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"BitbucketServerAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/bitbucketServer/BitbucketServerAuth.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 BackstageIdentityResponse,\n bitbucketServerAuthApiRef,\n ProfileInfo,\n} from '@backstage/core-plugin-api';\n\nimport { OAuthApiCreateOptions } from '../types';\nimport { OAuth2 } from '../oauth2';\n\nexport type BitbucketServerAuthResponse = {\n providerInfo: {\n accessToken: string;\n scope: string;\n expiresInSeconds: number;\n };\n profile: ProfileInfo;\n backstageIdentity: BackstageIdentityResponse;\n};\n\nconst DEFAULT_PROVIDER = {\n id: 'bitbucketServer',\n title: 'Bitbucket Server',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to Bitbucket Server.\n * @public\n */\nexport default class BitbucketServerAuth {\n static create(\n options: OAuthApiCreateOptions,\n ): typeof bitbucketServerAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n defaultScopes = ['PROJECT_ADMIN'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n });\n }\n}\n"],"names":[],"mappings":";;AAmCA,MAAM,gBAAA,GAAmB;AAAA,EACvB,EAAA,EAAI,iBAAA;AAAA,EACJ,KAAA,EAAO,kBAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAMA,MAAqB,mBAAA,CAAoB;AAAA,EACvC,OAAO,OACL,OAAA,EACoC;AACpC,IAAA,MAAM;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA,GAAc,aAAA;AAAA,MACd,QAAA,GAAW,gBAAA;AAAA,MACX,eAAA;AAAA,MACA,aAAA,GAAgB,CAAC,eAAe;AAAA,KAClC,GAAI,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAA,CAAO;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,EACH;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"GithubAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/github/GithubAuth.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 { githubAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'github',\n title: 'GitHub',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to GitHub products.\n *\n * @public\n */\nexport default class GithubAuth {\n static create(options: OAuthApiCreateOptions): typeof githubAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n defaultScopes = ['read:user'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n });\n }\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,gBAAmB,GAAA;AAAA,EACvB,EAAI,EAAA,QAAA;AAAA,EACJ,KAAO,EAAA,QAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAOA,MAAqB,UAAW,CAAA;AAAA,EAC9B,OAAO,OAAO,OAA2D,EAAA;AACvE,IAAM,MAAA;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAc,GAAA,aAAA;AAAA,MACd,QAAW,GAAA,gBAAA;AAAA,MACX,eAAA;AAAA,MACA,aAAA,GAAgB,CAAC,WAAW;AAAA,KAC1B,GAAA,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAO,CAAA;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"GithubAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/github/GithubAuth.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 { githubAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'github',\n title: 'GitHub',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to GitHub products.\n *\n * @public\n */\nexport default class GithubAuth {\n static create(options: OAuthApiCreateOptions): typeof githubAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n defaultScopes = ['read:user'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n });\n }\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,gBAAA,GAAmB;AAAA,EACvB,EAAA,EAAI,QAAA;AAAA,EACJ,KAAA,EAAO,QAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAOA,MAAqB,UAAA,CAAW;AAAA,EAC9B,OAAO,OAAO,OAAA,EAA2D;AACvE,IAAA,MAAM;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA,GAAc,aAAA;AAAA,MACd,QAAA,GAAW,gBAAA;AAAA,MACX,eAAA;AAAA,MACA,aAAA,GAAgB,CAAC,WAAW;AAAA,KAC9B,GAAI,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAA,CAAO;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,EACH;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"GitlabAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/gitlab/GitlabAuth.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 { gitlabAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'gitlab',\n title: 'GitLab',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to GitLab products.\n *\n * @public\n */\nexport default class GitlabAuth {\n static create(options: OAuthApiCreateOptions): typeof gitlabAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n defaultScopes = ['read_user'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n });\n }\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,gBAAmB,GAAA;AAAA,EACvB,EAAI,EAAA,QAAA;AAAA,EACJ,KAAO,EAAA,QAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAOA,MAAqB,UAAW,CAAA;AAAA,EAC9B,OAAO,OAAO,OAA2D,EAAA;AACvE,IAAM,MAAA;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAc,GAAA,aAAA;AAAA,MACd,QAAW,GAAA,gBAAA;AAAA,MACX,eAAA;AAAA,MACA,aAAA,GAAgB,CAAC,WAAW;AAAA,KAC1B,GAAA,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAO,CAAA;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"GitlabAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/gitlab/GitlabAuth.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 { gitlabAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'gitlab',\n title: 'GitLab',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to GitLab products.\n *\n * @public\n */\nexport default class GitlabAuth {\n static create(options: OAuthApiCreateOptions): typeof gitlabAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n defaultScopes = ['read_user'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n });\n }\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,gBAAA,GAAmB;AAAA,EACvB,EAAA,EAAI,QAAA;AAAA,EACJ,KAAA,EAAO,QAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAOA,MAAqB,UAAA,CAAW;AAAA,EAC9B,OAAO,OAAO,OAAA,EAA2D;AACvE,IAAA,MAAM;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA,GAAc,aAAA;AAAA,MACd,QAAA,GAAW,gBAAA;AAAA,MACX,eAAA;AAAA,MACA,aAAA,GAAgB,CAAC,WAAW;AAAA,KAC9B,GAAI,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAA,CAAO;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,EACH;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/google/GoogleAuth.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 { googleAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'google',\n title: 'Google',\n icon: () => null,\n};\n\nconst SCOPE_PREFIX = 'https://www.googleapis.com/auth/';\n\n/**\n * Implements the OAuth flow to Google products.\n *\n * @public\n */\nexport default class GoogleAuth {\n static create(options: OAuthApiCreateOptions): typeof googleAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n oauthRequestApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n defaultScopes = [\n 'openid',\n `${SCOPE_PREFIX}userinfo.email`,\n `${SCOPE_PREFIX}userinfo.profile`,\n ],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n scopeTransform(scopes: string[]) {\n return scopes.map(scope => {\n if (scope === 'openid') {\n return scope;\n }\n\n if (scope === 'profile' || scope === 'email') {\n return `${SCOPE_PREFIX}userinfo.${scope}`;\n }\n\n if (scope.startsWith(SCOPE_PREFIX)) {\n return scope;\n }\n\n return `${SCOPE_PREFIX}${scope}`;\n });\n },\n });\n }\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,gBAAmB,GAAA;AAAA,EACvB,EAAI,EAAA,QAAA;AAAA,EACJ,KAAO,EAAA,QAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAEA,MAAM,YAAe,GAAA,kCAAA;AAOrB,MAAqB,UAAW,CAAA;AAAA,EAC9B,OAAO,OAAO,OAA2D,EAAA;AACvE,IAAM,MAAA;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,WAAc,GAAA,aAAA;AAAA,MACd,QAAW,GAAA,gBAAA;AAAA,MACX,aAAgB,GAAA;AAAA,QACd,QAAA;AAAA,QACA,GAAG,YAAY,CAAA,cAAA,CAAA;AAAA,QACf,GAAG,YAAY,CAAA,gBAAA;AAAA;AACjB,KACE,GAAA,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAO,CAAA;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA,aAAA;AAAA,MACA,eAAe,MAAkB,EAAA;AAC/B,QAAO,OAAA,MAAA,CAAO,IAAI,CAAS,KAAA,KAAA;AACzB,UAAA,IAAI,UAAU,QAAU,EAAA;AACtB,YAAO,OAAA,KAAA;AAAA;AAGT,UAAI,IAAA,KAAA,KAAU,SAAa,IAAA,KAAA,KAAU,OAAS,EAAA;AAC5C,YAAO,OAAA,CAAA,EAAG,YAAY,CAAA,SAAA,EAAY,KAAK,CAAA,CAAA;AAAA;AAGzC,UAAI,IAAA,KAAA,CAAM,UAAW,CAAA,YAAY,CAAG,EAAA;AAClC,YAAO,OAAA,KAAA;AAAA;AAGT,UAAO,OAAA,CAAA,EAAG,YAAY,CAAA,EAAG,KAAK,CAAA,CAAA;AAAA,SAC/B,CAAA;AAAA;AACH,KACD,CAAA;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"GoogleAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/google/GoogleAuth.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 { googleAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'google',\n title: 'Google',\n icon: () => null,\n};\n\nconst SCOPE_PREFIX = 'https://www.googleapis.com/auth/';\n\n/**\n * Implements the OAuth flow to Google products.\n *\n * @public\n */\nexport default class GoogleAuth {\n static create(options: OAuthApiCreateOptions): typeof googleAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n oauthRequestApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n defaultScopes = [\n 'openid',\n `${SCOPE_PREFIX}userinfo.email`,\n `${SCOPE_PREFIX}userinfo.profile`,\n ],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n scopeTransform(scopes: string[]) {\n return scopes.map(scope => {\n if (scope === 'openid') {\n return scope;\n }\n\n if (scope === 'profile' || scope === 'email') {\n return `${SCOPE_PREFIX}userinfo.${scope}`;\n }\n\n if (scope.startsWith(SCOPE_PREFIX)) {\n return scope;\n }\n\n return `${SCOPE_PREFIX}${scope}`;\n });\n },\n });\n }\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,gBAAA,GAAmB;AAAA,EACvB,EAAA,EAAI,QAAA;AAAA,EACJ,KAAA,EAAO,QAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAEA,MAAM,YAAA,GAAe,kCAAA;AAOrB,MAAqB,UAAA,CAAW;AAAA,EAC9B,OAAO,OAAO,OAAA,EAA2D;AACvE,IAAA,MAAM;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,WAAA,GAAc,aAAA;AAAA,MACd,QAAA,GAAW,gBAAA;AAAA,MACX,aAAA,GAAgB;AAAA,QACd,QAAA;AAAA,QACA,GAAG,YAAY,CAAA,cAAA,CAAA;AAAA,QACf,GAAG,YAAY,CAAA,gBAAA;AAAA;AACjB,KACF,GAAI,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAA,CAAO;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA,aAAA;AAAA,MACA,eAAe,MAAA,EAAkB;AAC/B,QAAA,OAAO,MAAA,CAAO,IAAI,CAAA,KAAA,KAAS;AACzB,UAAA,IAAI,UAAU,QAAA,EAAU;AACtB,YAAA,OAAO,KAAA;AAAA,UACT;AAEA,UAAA,IAAI,KAAA,KAAU,SAAA,IAAa,KAAA,KAAU,OAAA,EAAS;AAC5C,YAAA,OAAO,CAAA,EAAG,YAAY,CAAA,SAAA,EAAY,KAAK,CAAA,CAAA;AAAA,UACzC;AAEA,UAAA,IAAI,KAAA,CAAM,UAAA,CAAW,YAAY,CAAA,EAAG;AAClC,YAAA,OAAO,KAAA;AAAA,UACT;AAEA,UAAA,OAAO,CAAA,EAAG,YAAY,CAAA,EAAG,KAAK,CAAA,CAAA;AAAA,QAChC,CAAC,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MicrosoftAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/microsoft/MicrosoftAuth.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 microsoftAuthApiRef,\n AuthRequestOptions,\n AuthProviderInfo,\n ConfigApi,\n DiscoveryApi,\n OAuthRequestApi,\n} from '@backstage/core-plugin-api';\nimport { OAuth2, OAuth2CreateOptions } from '../oauth2';\n\nconst DEFAULT_PROVIDER = {\n id: 'microsoft',\n title: 'Microsoft',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to Microsoft products.\n *\n * @public\n */\nexport default class MicrosoftAuth {\n private oauth2: { [aud: string]: OAuth2 };\n private configApi: ConfigApi | undefined;\n private environment: string;\n private provider: AuthProviderInfo;\n private oauthRequestApi: OAuthRequestApi;\n private discoveryApi: DiscoveryApi;\n private scopeTransform: (scopes: string[]) => string[];\n\n private static MicrosoftGraphID = '00000003-0000-0000-c000-000000000000';\n\n static create(options: OAuth2CreateOptions): typeof microsoftAuthApiRef.T {\n return new MicrosoftAuth(options);\n }\n private constructor(options: OAuth2CreateOptions) {\n const {\n configApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n discoveryApi,\n defaultScopes = [\n 'openid',\n 'offline_access',\n 'profile',\n 'email',\n 'User.Read',\n ],\n scopeTransform = scopes => scopes.concat('offline_access'),\n } = options;\n\n this.configApi = configApi;\n this.environment = environment;\n this.provider = provider;\n this.oauthRequestApi = oauthRequestApi;\n this.discoveryApi = discoveryApi;\n this.scopeTransform = scopeTransform;\n\n this.oauth2 = {\n [MicrosoftAuth.MicrosoftGraphID]: OAuth2.create({\n configApi: this.configApi,\n discoveryApi: this.discoveryApi,\n oauthRequestApi: this.oauthRequestApi,\n provider: this.provider,\n environment: this.environment,\n scopeTransform: this.scopeTransform,\n defaultScopes,\n }),\n };\n }\n\n private microsoftGraph(): OAuth2 {\n return this.oauth2[MicrosoftAuth.MicrosoftGraphID];\n }\n\n private static resourceForScopes(scope: string): Promise<string> {\n const audiences = [\n ...new Set(\n scope\n .split(' ')\n .map(MicrosoftAuth.resourceForScope)\n .filter(aud => aud !== 'openid'),\n ),\n ];\n\n if (audiences.length > 1) {\n return Promise.reject(\n new Error(\n `Requested access token with scopes from multiple Azure resources: ${audiences.join(\n ', ',\n )}. Access tokens can only have a single audience.`,\n ),\n );\n }\n const audience = audiences[0] ?? MicrosoftAuth.MicrosoftGraphID;\n return Promise.resolve(audience);\n }\n\n private static resourceForScope(scope: string): string {\n const groups = scope.match(/^(?<resourceURI>.*)\\/(?<scp>[^\\/]*)$/)?.groups;\n if (groups) {\n const { resourceURI } = groups;\n const aud = resourceURI.replace(/^api:\\/\\//, '');\n return aud;\n }\n switch (scope) {\n case 'email':\n case 'openid':\n case 'offline_access':\n case 'profile': {\n return 'openid';\n }\n default:\n return MicrosoftAuth.MicrosoftGraphID;\n }\n }\n\n async getAccessToken(\n scope?: string | string[],\n options?: AuthRequestOptions,\n ): Promise<string> {\n const aud =\n scope === undefined\n ? MicrosoftAuth.MicrosoftGraphID\n : await MicrosoftAuth.resourceForScopes(\n Array.isArray(scope) ? scope.join(' ') : scope,\n );\n if (!(aud in this.oauth2)) {\n this.oauth2[aud] = OAuth2.create({\n configApi: this.configApi,\n discoveryApi: this.discoveryApi,\n oauthRequestApi: this.oauthRequestApi,\n provider: this.provider,\n environment: this.environment,\n scopeTransform: this.scopeTransform,\n });\n }\n return this.oauth2[aud].getAccessToken(scope, options);\n }\n\n getIdToken(options?: AuthRequestOptions) {\n return this.microsoftGraph().getIdToken(options);\n }\n\n getProfile(options?: AuthRequestOptions) {\n return this.microsoftGraph().getProfile(options);\n }\n\n getBackstageIdentity(options?: AuthRequestOptions) {\n return this.microsoftGraph().getBackstageIdentity(options);\n }\n\n signIn() {\n return this.microsoftGraph().signIn();\n }\n\n signOut() {\n return this.microsoftGraph().signOut();\n }\n\n sessionState$() {\n return this.microsoftGraph().sessionState$();\n }\n}\n"],"names":[],"mappings":";;AA0BA,MAAM,gBAAmB,GAAA;AAAA,EACvB,EAAI,EAAA,WAAA;AAAA,EACJ,KAAO,EAAA,WAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAOA,MAAqB,aAAc,CAAA;AAAA,EACzB,MAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAA;AAAA,EACA,QAAA;AAAA,EACA,eAAA;AAAA,EACA,YAAA;AAAA,EACA,cAAA;AAAA,EAER,OAAe,gBAAmB,GAAA,sCAAA;AAAA,EAElC,OAAO,OAAO,OAA4D,EAAA;AACxE,IAAO,OAAA,IAAI,cAAc,OAAO,CAAA;AAAA;AAClC,EACQ,YAAY,OAA8B,EAAA;AAChD,IAAM,MAAA;AAAA,MACJ,SAAA;AAAA,MACA,WAAc,GAAA,aAAA;AAAA,MACd,QAAW,GAAA,gBAAA;AAAA,MACX,eAAA;AAAA,MACA,YAAA;AAAA,MACA,aAAgB,GAAA;AAAA,QACd,QAAA;AAAA,QACA,gBAAA;AAAA,QACA,SAAA;AAAA,QACA,OAAA;A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;AAAA,QACtB,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,aAAa,IAAK,CAAA,WAAA;AAAA,QAClB,gBAAgB,IAAK,CAAA;AAAA,OACtB,CAAA;AAAA;AAEH,IAAA,OAAO,KAAK,MAAO,CAAA,GAAG,CAAE,CAAA,cAAA,CAAe,OAAO,OAAO,CAAA;AAAA;AACvD,EAEA,WAAW,OAA8B,EAAA;AACvC,IAAA,OAAO,IAAK,CAAA,cAAA,EAAiB,CAAA,UAAA,CAAW,OAAO,CAAA;AAAA;AACjD,EAEA,WAAW,OAA8B,EAAA;AACvC,IAAA,OAAO,IAAK,CAAA,cAAA,EAAiB,CAAA,UAAA,CAAW,OAAO,CAAA;AAAA;AACjD,EAEA,qBAAqB,OAA8B,EAAA;AACjD,IAAA,OAAO,IAAK,CAAA,cAAA,EAAiB,CAAA,oBAAA,CAAqB,OAAO,CAAA;AAAA;AAC3D,EAEA,MAAS,GAAA;AACP,IAAO,OAAA,IAAA,CAAK,cAAe,EAAA,CAAE,MAAO,EAAA;AAAA;AACtC,EAEA,OAAU,GAAA;AACR,IAAO,OAAA,IAAA,CAAK,cAAe,EAAA,CAAE,OAAQ,EAAA;AAAA;AACvC,EAEA,aAAgB,GAAA;AACd,IAAO,OAAA,IAAA,CAAK,cAAe,EAAA,CAAE,aAAc,EAAA;AAAA;AAE/C;;;;"}
1
+ {"version":3,"file":"MicrosoftAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/microsoft/MicrosoftAuth.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 microsoftAuthApiRef,\n AuthRequestOptions,\n AuthProviderInfo,\n ConfigApi,\n DiscoveryApi,\n OAuthRequestApi,\n} from '@backstage/core-plugin-api';\nimport { OAuth2, OAuth2CreateOptions } from '../oauth2';\n\nconst DEFAULT_PROVIDER = {\n id: 'microsoft',\n title: 'Microsoft',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow to Microsoft products.\n *\n * @public\n */\nexport default class MicrosoftAuth {\n private oauth2: { [aud: string]: OAuth2 };\n private configApi: ConfigApi | undefined;\n private environment: string;\n private provider: AuthProviderInfo;\n private oauthRequestApi: OAuthRequestApi;\n private discoveryApi: DiscoveryApi;\n private scopeTransform: (scopes: string[]) => string[];\n\n private static MicrosoftGraphID = '00000003-0000-0000-c000-000000000000';\n\n static create(options: OAuth2CreateOptions): typeof microsoftAuthApiRef.T {\n return new MicrosoftAuth(options);\n }\n private constructor(options: OAuth2CreateOptions) {\n const {\n configApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n discoveryApi,\n defaultScopes = [\n 'openid',\n 'offline_access',\n 'profile',\n 'email',\n 'User.Read',\n ],\n scopeTransform = scopes => scopes.concat('offline_access'),\n } = options;\n\n this.configApi = configApi;\n this.environment = environment;\n this.provider = provider;\n this.oauthRequestApi = oauthRequestApi;\n this.discoveryApi = discoveryApi;\n this.scopeTransform = scopeTransform;\n\n this.oauth2 = {\n [MicrosoftAuth.MicrosoftGraphID]: OAuth2.create({\n configApi: this.configApi,\n discoveryApi: this.discoveryApi,\n oauthRequestApi: this.oauthRequestApi,\n provider: this.provider,\n environment: this.environment,\n scopeTransform: this.scopeTransform,\n defaultScopes,\n }),\n };\n }\n\n private microsoftGraph(): OAuth2 {\n return this.oauth2[MicrosoftAuth.MicrosoftGraphID];\n }\n\n private static resourceForScopes(scope: string): Promise<string> {\n const audiences = [\n ...new Set(\n scope\n .split(' ')\n .map(MicrosoftAuth.resourceForScope)\n .filter(aud => aud !== 'openid'),\n ),\n ];\n\n if (audiences.length > 1) {\n return Promise.reject(\n new Error(\n `Requested access token with scopes from multiple Azure resources: ${audiences.join(\n ', ',\n )}. Access tokens can only have a single audience.`,\n ),\n );\n }\n const audience = audiences[0] ?? MicrosoftAuth.MicrosoftGraphID;\n return Promise.resolve(audience);\n }\n\n private static resourceForScope(scope: string): string {\n const groups = scope.match(/^(?<resourceURI>.*)\\/(?<scp>[^\\/]*)$/)?.groups;\n if (groups) {\n const { resourceURI } = groups;\n const aud = resourceURI.replace(/^api:\\/\\//, '');\n return aud;\n }\n switch (scope) {\n case 'email':\n case 'openid':\n case 'offline_access':\n case 'profile': {\n return 'openid';\n }\n default:\n return MicrosoftAuth.MicrosoftGraphID;\n }\n }\n\n async getAccessToken(\n scope?: string | string[],\n options?: AuthRequestOptions,\n ): Promise<string> {\n const aud =\n scope === undefined\n ? MicrosoftAuth.MicrosoftGraphID\n : await MicrosoftAuth.resourceForScopes(\n Array.isArray(scope) ? scope.join(' ') : scope,\n );\n if (!(aud in this.oauth2)) {\n this.oauth2[aud] = OAuth2.create({\n configApi: this.configApi,\n discoveryApi: this.discoveryApi,\n oauthRequestApi: this.oauthRequestApi,\n provider: this.provider,\n environment: this.environment,\n scopeTransform: this.scopeTransform,\n });\n }\n return this.oauth2[aud].getAccessToken(scope, options);\n }\n\n getIdToken(options?: AuthRequestOptions) {\n return this.microsoftGraph().getIdToken(options);\n }\n\n getProfile(options?: AuthRequestOptions) {\n return this.microsoftGraph().getProfile(options);\n }\n\n getBackstageIdentity(options?: AuthRequestOptions) {\n return this.microsoftGraph().getBackstageIdentity(options);\n }\n\n signIn() {\n return this.microsoftGraph().signIn();\n }\n\n signOut() {\n return this.microsoftGraph().signOut();\n }\n\n sessionState$() {\n return this.microsoftGraph().sessionState$();\n }\n}\n"],"names":[],"mappings":";;AA0BA,MAAM,gBAAA,GAAmB;AAAA,EACvB,EAAA,EAAI,WAAA;AAAA,EACJ,KAAA,EAAO,WAAA;AAAA,EACP,MAAM,MA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,EAAO;AAAA,EACtC;AAAA,EAEA,OAAA,GAAU;AACR,IAAA,OAAO,IAAA,CAAK,cAAA,EAAe,CAAE,OAAA,EAAQ;AAAA,EACvC;AAAA,EAEA,aAAA,GAAgB;AACd,IAAA,OAAO,IAAA,CAAK,cAAA,EAAe,CAAE,aAAA,EAAc;AAAA,EAC7C;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"OAuth2.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.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 { DefaultAuthConnector } from '../../../../lib/AuthConnector';\nimport { RefreshingAuthSessionManager } from '../../../../lib/AuthSessionManager';\nimport { SessionManager } from '../../../../lib/AuthSessionManager/types';\nimport {\n AuthRequestOptions,\n BackstageIdentityApi,\n BackstageIdentityResponse,\n BackstageUserIdentity,\n OAuthApi,\n OpenIdConnectApi,\n ProfileInfo,\n ProfileInfoApi,\n SessionApi,\n SessionState,\n} from '@backstage/core-plugin-api';\nimport { Observable } from '@backstage/types';\nimport {\n OAuth2CreateOptions,\n OAuth2CreateOptionsWithAuthConnector,\n OAuth2Session,\n} from './types';\n\nconst DEFAULT_PROVIDER = {\n id: 'oauth2',\n title: 'Your Identity Provider',\n icon: () => null,\n};\n\nexport type OAuth2Response = {\n providerInfo: {\n accessToken: string;\n idToken: string;\n scope: string;\n expiresInSeconds?: number;\n };\n profile: ProfileInfo;\n backstageIdentity: {\n token: string;\n expiresInSeconds?: number;\n identity: BackstageUserIdentity;\n };\n};\n\n/**\n * Implements a generic OAuth2 flow for auth.\n *\n * @public\n */\nexport default class OAuth2\n implements\n OAuthApi,\n OpenIdConnectApi,\n ProfileInfoApi,\n BackstageIdentityApi,\n SessionApi\n{\n private static createAuthConnector(\n options: OAuth2CreateOptions | OAuth2CreateOptionsWithAuthConnector,\n ) {\n if ('authConnector' in options) {\n return options.authConnector;\n }\n const {\n scopeTransform = x => x,\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n popupOptions,\n } = options;\n\n return new DefaultAuthConnector({\n configApi,\n discoveryApi,\n environment,\n provider,\n oauthRequestApi: oauthRequestApi,\n sessionTransform({\n backstageIdentity,\n ...res\n }: OAuth2Response): OAuth2Session {\n const session: OAuth2Session = {\n ...res,\n providerInfo: {\n idToken: res.providerInfo.idToken,\n accessToken: res.providerInfo.accessToken,\n scopes: OAuth2.normalizeScopes(res.providerInfo.scope, {\n scopeTransform,\n }),\n expiresAt: res.providerInfo.expiresInSeconds\n ? new Date(Date.now() + res.providerInfo.expiresInSeconds * 1000)\n : undefined,\n },\n };\n if (backstageIdentity) {\n session.backstageIdentity = {\n token: backstageIdentity.token,\n identity: backstageIdentity.identity,\n expiresAt: backstageIdentity.expiresInSeconds\n ? new Date(Date.now() + backstageIdentity.expiresInSeconds * 1000)\n : undefined,\n };\n }\n return session;\n },\n popupOptions,\n });\n }\n\n static create(\n options: OAuth2CreateOptions | OAuth2CreateOptionsWithAuthConnector,\n ) {\n const { defaultScopes = [], scopeTransform = x => x } = options;\n\n const connector = OAuth2.createAuthConnector(options);\n\n const sessionManager = new RefreshingAuthSessionManager({\n connector,\n defaultScopes: new Set(defaultScopes),\n sessionScopes: (session: OAuth2Session) => session.providerInfo.scopes,\n sessionShouldRefresh: (session: OAuth2Session) => {\n // TODO(Rugvip): Optimize to use separate checks for provider vs backstage session expiration\n let min = Infinity;\n if (session.providerInfo?.expiresAt) {\n min = Math.min(\n min,\n (session.providerInfo.expiresAt.getTime() - Date.now()) / 1000,\n );\n }\n if (session.backstageIdentity?.expiresAt) {\n min = Math.min(\n min,\n (session.backstageIdentity.expiresAt.getTime() - Date.now()) / 1000,\n );\n }\n return min < 60 * 3;\n },\n });\n\n return new OAuth2({ sessionManager, scopeTransform });\n }\n\n private readonly sessionManager: SessionManager<OAuth2Session>;\n private readonly scopeTransform: (scopes: string[]) => string[];\n\n private constructor(options: {\n sessionManager: SessionManager<OAuth2Session>;\n scopeTransform: (scopes: string[]) => string[];\n }) {\n this.sessionManager = options.sessionManager;\n this.scopeTransform = options.scopeTransform;\n }\n\n async signIn() {\n await this.getAccessToken();\n }\n\n async signOut() {\n await this.sessionManager.removeSession();\n }\n\n sessionState$(): Observable<SessionState> {\n return this.sessionManager.sessionState$();\n }\n\n async getAccessToken(\n scope?: string | string[],\n options?: AuthRequestOptions,\n ) {\n const normalizedScopes = OAuth2.normalizeScopes(scope, {\n scopeTransform: this.scopeTransform,\n });\n const session = await this.sessionManager.getSession({\n ...options,\n scopes: normalizedScopes,\n });\n return session?.providerInfo.accessToken ?? '';\n }\n\n async getIdToken(options: AuthRequestOptions = {}) {\n const session = await this.sessionManager.getSession({\n ...options,\n scopes: new Set(['openid']),\n });\n return session?.providerInfo.idToken ?? '';\n }\n\n async getBackstageIdentity(\n options: AuthRequestOptions = {},\n ): Promise<BackstageIdentityResponse | undefined> {\n const session = await this.sessionManager.getSession(options);\n return session?.backstageIdentity;\n }\n\n async getProfile(options: AuthRequestOptions = {}) {\n const session = await this.sessionManager.getSession(options);\n return session?.profile;\n }\n\n /**\n * @public\n */\n public static normalizeScopes(\n scopes?: string | string[],\n options?: { scopeTransform: (scopes: string[]) => string[] },\n ): Set<string> {\n if (!scopes) {\n return new Set();\n }\n\n const scopeList = Array.isArray(scopes)\n ? scopes\n : scopes.split(/[\\s|,]/).filter(Boolean);\n\n const transformedScopes = options\n ? options.scopeTransform(scopeList)\n : scopeList;\n\n return new Set(transformedScopes);\n }\n}\n"],"names":[],"mappings":";;;;;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B,GAAA,EACkB,EAAA;AAChD,IAAA,MAAM,OAAU,GAAA,MAAM,IAAK,CAAA,cAAA,CAAe,WAAW,OAAO,CAAA;AAC5D,IAAA,OAAO,OAAS,EAAA,iBAAA;AAAA;AAClB,EAEA,MAAM,UAAA,CAAW,OAA8B,GAAA,EAAI,EAAA;AACjD,IAAA,MAAM,OAAU,GAAA,MAAM,IAAK,CAAA,cAAA,CAAe,WAAW,OAAO,CAAA;AAC5D,IAAA,OAAO,OAAS,EAAA,OAAA;AAAA;AAClB;AAAA;AAAA;AAAA,EAKA,OAAc,eACZ,CAAA,MAAA,EACA,OACa,EAAA;AACb,IAAA,IAAI,CAAC,MAAQ,EAAA;AACX,MAAA,2BAAW,GAAI,EAAA;AAAA;AAGjB,IAAM,MAAA,SAAA,GAAY,KAAM,CAAA,OAAA,CAAQ,MAAM,CAAA,GAClC,MACA,GAAA,MAAA,CAAO,KAAM,CAAA,QAAQ,CAAE,CAAA,MAAA,CAAO,OAAO,CAAA;AAEzC,IAAA,MAAM,iBAAoB,GAAA,OAAA,GACtB,OAAQ,CAAA,cAAA,CAAe,SAAS,CAChC,GAAA,SAAA;AAEJ,IAAO,OAAA,IAAI,IAAI,iBAAiB,CAAA;AAAA;AAEpC;;;;"}
1
+ {"version":3,"file":"OAuth2.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.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 { DefaultAuthConnector } from '../../../../lib/AuthConnector';\nimport { RefreshingAuthSessionManager } from '../../../../lib/AuthSessionManager';\nimport { SessionManager } from '../../../../lib/AuthSessionManager/types';\nimport {\n AuthRequestOptions,\n BackstageIdentityApi,\n BackstageIdentityResponse,\n BackstageUserIdentity,\n OAuthApi,\n OpenIdConnectApi,\n ProfileInfo,\n ProfileInfoApi,\n SessionApi,\n SessionState,\n} from '@backstage/core-plugin-api';\nimport { Observable } from '@backstage/types';\nimport {\n OAuth2CreateOptions,\n OAuth2CreateOptionsWithAuthConnector,\n OAuth2Session,\n} from './types';\n\nconst DEFAULT_PROVIDER = {\n id: 'oauth2',\n title: 'Your Identity Provider',\n icon: () => null,\n};\n\nexport type OAuth2Response = {\n providerInfo: {\n accessToken: string;\n idToken: string;\n scope: string;\n expiresInSeconds?: number;\n };\n profile: ProfileInfo;\n backstageIdentity: {\n token: string;\n expiresInSeconds?: number;\n identity: BackstageUserIdentity;\n };\n};\n\n/**\n * Implements a generic OAuth2 flow for auth.\n *\n * @public\n */\nexport default class OAuth2\n implements\n OAuthApi,\n OpenIdConnectApi,\n ProfileInfoApi,\n BackstageIdentityApi,\n SessionApi\n{\n private static createAuthConnector(\n options: OAuth2CreateOptions | OAuth2CreateOptionsWithAuthConnector,\n ) {\n if ('authConnector' in options) {\n return options.authConnector;\n }\n const {\n scopeTransform = x => x,\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n popupOptions,\n } = options;\n\n return new DefaultAuthConnector({\n configApi,\n discoveryApi,\n environment,\n provider,\n oauthRequestApi: oauthRequestApi,\n sessionTransform({\n backstageIdentity,\n ...res\n }: OAuth2Response): OAuth2Session {\n const session: OAuth2Session = {\n ...res,\n providerInfo: {\n idToken: res.providerInfo.idToken,\n accessToken: res.providerInfo.accessToken,\n scopes: OAuth2.normalizeScopes(res.providerInfo.scope, {\n scopeTransform,\n }),\n expiresAt: res.providerInfo.expiresInSeconds\n ? new Date(Date.now() + res.providerInfo.expiresInSeconds * 1000)\n : undefined,\n },\n };\n if (backstageIdentity) {\n session.backstageIdentity = {\n token: backstageIdentity.token,\n identity: backstageIdentity.identity,\n expiresAt: backstageIdentity.expiresInSeconds\n ? new Date(Date.now() + backstageIdentity.expiresInSeconds * 1000)\n : undefined,\n };\n }\n return session;\n },\n popupOptions,\n });\n }\n\n static create(\n options: OAuth2CreateOptions | OAuth2CreateOptionsWithAuthConnector,\n ) {\n const { defaultScopes = [], scopeTransform = x => x } = options;\n\n const connector = OAuth2.createAuthConnector(options);\n\n const sessionManager = new RefreshingAuthSessionManager({\n connector,\n defaultScopes: new Set(defaultScopes),\n sessionScopes: (session: OAuth2Session) => session.providerInfo.scopes,\n sessionShouldRefresh: (session: OAuth2Session) => {\n // TODO(Rugvip): Optimize to use separate checks for provider vs backstage session expiration\n let min = Infinity;\n if (session.providerInfo?.expiresAt) {\n min = Math.min(\n min,\n (session.providerInfo.expiresAt.getTime() - Date.now()) / 1000,\n );\n }\n if (session.backstageIdentity?.expiresAt) {\n min = Math.min(\n min,\n (session.backstageIdentity.expiresAt.getTime() - Date.now()) / 1000,\n );\n }\n return min < 60 * 3;\n },\n });\n\n return new OAuth2({ sessionManager, scopeTransform });\n }\n\n private readonly sessionManager: SessionManager<OAuth2Session>;\n private readonly scopeTransform: (scopes: string[]) => string[];\n\n private constructor(options: {\n sessionManager: SessionManager<OAuth2Session>;\n scopeTransform: (scopes: string[]) => string[];\n }) {\n this.sessionManager = options.sessionManager;\n this.scopeTransform = options.scopeTransform;\n }\n\n async signIn() {\n await this.getAccessToken();\n }\n\n async signOut() {\n await this.sessionManager.removeSession();\n }\n\n sessionState$(): Observable<SessionState> {\n return this.sessionManager.sessionState$();\n }\n\n async getAccessToken(\n scope?: string | string[],\n options?: AuthRequestOptions,\n ) {\n const normalizedScopes = OAuth2.normalizeScopes(scope, {\n scopeTransform: this.scopeTransform,\n });\n const session = await this.sessionManager.getSession({\n ...options,\n scopes: normalizedScopes,\n });\n return session?.providerInfo.accessToken ?? '';\n }\n\n async getIdToken(options: AuthRequestOptions = {}) {\n const session = await this.sessionManager.getSession({\n ...options,\n scopes: new Set(['openid']),\n });\n return session?.providerInfo.idToken ?? '';\n }\n\n async getBackstageIdentity(\n options: AuthRequestOptions = {},\n ): Promise<BackstageIdentityResponse | undefined> {\n const session = await this.sessionManager.getSession(options);\n return session?.backstageIdentity;\n }\n\n async getProfile(options: AuthRequestOptions = {}) {\n const session = await this.sessionManager.getSession(options);\n return session?.profile;\n }\n\n /**\n * @public\n */\n public static normalizeScopes(\n scopes?: string | string[],\n options?: { scopeTransform: (scopes: string[]) => string[] },\n ): Set<string> {\n if (!scopes) {\n return new Set();\n }\n\n const scopeList = Array.isArray(scopes)\n ? scopes\n : scopes.split(/[\\s|,]/).filter(Boolean);\n\n const transformedScopes = options\n ? options.scopeTransform(scopeList)\n : scopeList;\n\n return new Set(transformedScopes);\n }\n}\n"],"names":[],"mappings":";;;;;AAsCA,MAAM,gBAAA,GAAmB;AAAA,EACvB,EAAA,EAAI,QAAA;AAAA,EACJ,KAAA,EAAO,wBAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAsBA,MAAqB,MAAA,CAOrB;AAAA,EACE,OAAe,oBACb,OAAA,EACA;AACA,IAAA,IAAI,mBAAmB,OAAA,EAAS;AAC9B,MAAA,OAAO,OAAA,CAAQ,aAAA;AAAA,IACjB;AACA,IAAA,MAAM;AAAA,MACJ,iBAAiB,CAAA,CAAA,KAAK,CAAA;AAAA,MACtB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA,GAAc,aAAA;AAAA,MACd,QAAA,GAAW,gBAAA;AAAA,MACX,eAAA;AAAA,MACA;AAAA,KACF,GAAI,OAAA;AAEJ,IAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,MAC9B,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA;AAAA,MACA,QAAA;AAAA,MACA,eAAA;AAAA,MACA,gBAAA,CAAiB;AAAA,QACf,iBAAA;AAAA,QACA,GAAG;AAAA,OACL,EAAkC;AAChC,QAAA,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AEzC,IAAA,MAAM,iBAAA,GAAoB,OAAA,GACtB,OAAA,CAAQ,cAAA,CAAe,SAAS,CAAA,GAChC,SAAA;AAEJ,IAAA,OAAO,IAAI,IAAI,iBAAiB,CAAA;AAAA,EAClC;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"OktaAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/okta/OktaAuth.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 { oktaAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'okta',\n title: 'Okta',\n icon: () => null,\n};\n\nconst OKTA_OIDC_SCOPES: Set<String> = new Set([\n 'openid',\n 'profile',\n 'email',\n 'phone',\n 'address',\n 'groups',\n 'offline_access',\n]);\n\nconst OKTA_SCOPE_PREFIX: string = 'okta.';\n\n/**\n * Implements the OAuth flow to Okta products.\n *\n * @public\n */\nexport default class OktaAuth {\n static create(options: OAuthApiCreateOptions): typeof oktaAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n defaultScopes = ['openid', 'email', 'profile', 'offline_access'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n scopeTransform(scopes) {\n return scopes.map(scope => {\n if (OKTA_OIDC_SCOPES.has(scope)) {\n return scope;\n }\n\n if (scope.startsW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,CAAA;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"OktaAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/okta/OktaAuth.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 { oktaAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'okta',\n title: 'Okta',\n icon: () => null,\n};\n\nconst OKTA_OIDC_SCOPES: Set<String> = new Set([\n 'openid',\n 'profile',\n 'email',\n 'phone',\n 'address',\n 'groups',\n 'offline_access',\n]);\n\nconst OKTA_SCOPE_PREFIX: string = 'okta.';\n\n/**\n * Implements the OAuth flow to Okta products.\n *\n * @public\n */\nexport default class OktaAuth {\n static create(options: OAuthApiCreateOptions): typeof oktaAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n defaultScopes = ['openid', 'email', 'profile', 'offline_access'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n scopeTransform(scopes) {\n return scopes.map(scope => {\n if (OKTA_OIDC_SCOPES.has(scope)) {\n return scope;\n }\n\n if (scope.startsWith(OKTA_SCOPE_PREFIX)) {\n return scope;\n }\n\n return `${OKTA_SCOPE_PREFIX}${scope}`;\n });\n },\n });\n }\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,gBAAA,GAAmB;AAAA,EACvB,EAAA,EAAI,MAAA;AAAA,EACJ,KAAA,EAAO,MAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAEA,MAAM,gBAAA,uBAAoC,GAAA,CAAI;AAAA,EAC5C,QAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,MAAM,iBAAA,GAA4B,OAAA;AAOlC,MAAqB,QAAA,CAAS;AAAA,EAC5B,OAAO,OAAO,OAAA,EAAyD;AACrE,IAAA,MAAM;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA,GAAc,aAAA;AAAA,MACd,QAAA,GAAW,gBAAA;AAAA,MACX,eAAA;AAAA,MACA,aAAA,GAAgB,CAAC,QAAA,EAAU,OAAA,EAAS,WAAW,gBAAgB;AAAA,KACjE,GAAI,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAA,CAAO;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA,aAAA;AAAA,MACA,eAAe,MAAA,EAAQ;AACrB,QAAA,OAAO,MAAA,CAAO,IAAI,CAAA,KAAA,KAAS;AACzB,UAAA,IAAI,gBAAA,CAAiB,GAAA,CAAI,KAAK,CAAA,EAAG;AAC/B,YAAA,OAAO,KAAA;AAAA,UACT;AAEA,UAAA,IAAI,KAAA,CAAM,UAAA,CAAW,iBAAiB,CAAA,EAAG;AACvC,YAAA,OAAO,KAAA;AAAA,UACT;AAEA,UAAA,OAAO,CAAA,EAAG,iBAAiB,CAAA,EAAG,KAAK,CAAA,CAAA;AAAA,QACrC,CAAC,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"OneLoginAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/onelogin/OneLoginAuth.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 oneloginAuthApiRef,\n OAuthRequestApi,\n AuthProviderInfo,\n ConfigApi,\n DiscoveryApi,\n} from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\n\n/**\n * OneLogin auth provider create options.\n * @public\n */\nexport type OneLoginAuthCreateOptions = {\n configApi?: ConfigApi;\n discoveryApi: DiscoveryApi;\n oauthRequestApi: OAuthRequestApi;\n environment?: string;\n provider?: AuthProviderInfo;\n};\n\nconst DEFAULT_PROVIDER = {\n id: 'onelogin',\n title: 'onelogin',\n icon: () => null,\n};\n\nconst OIDC_SCOPES: Set<String> = new Set([\n 'openid',\n 'profile',\n 'email',\n 'phone',\n 'address',\n 'groups',\n 'offline_access',\n]);\n\nconst SCOPE_PREFIX: string = 'onelogin.';\n\n/**\n * Implements a OneLogin OAuth flow.\n *\n * @public\n */\nexport default class OneLoginAuth {\n static create(\n options: OneLoginAuthCreateOptions,\n ): typeof oneloginAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes: ['openid', 'email', 'profile', 'offline_access'],\n scopeTransform(scopes) {\n return scopes.map(scope => {\n if (OIDC_SCOPES.has(scope)) {\n return scope;\n }\n\n if (scope.startsWith(SCOPE_PREFIX)) {\n return scope;\n }\n\n return `${SCOPE_PREFIX}${scope}`;\n });\n },\n });\n }\n}\n"],"names":[],"mappings":";;AAqCA,MAAM,gBAAmB,GAAA;AAAA,EACvB,EAAI,EAAA,UAAA;AAAA,EACJ,KAAO,EAAA,UAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAEA,MAAM,WAAA,uBAA+B,GAAI,CAAA;AAAA,EACvC,QAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,MAAM,YAAuB,GAAA,WAAA;AAO7B,MAAqB,YAAa,CAAA;AAAA,EAChC,OAAO,OACL,OAC6B,EAAA;AAC7B,IAAM,MAAA;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAc,GAAA,aAAA;AAAA,MACd,QAAW,GAAA,gBAAA;AAAA,MACX;AAAA,KACE,GAAA,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAO,CAAA;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA,aAAe,EAAA,CAAC,QAAU,EAAA,OAAA,EAAS,WAAW,gBAAgB,CAAA;AAAA,MAC9D,eAAe,MAAQ,EAAA;AACrB,QAAO,OAAA,MAAA,CAAO,IAAI,CAAS,KAAA,KAAA;AACzB,UAAI,IAAA,WAAA,CAAY,GAAI,CAAA,KAAK,CAAG,EAAA;AAC1B,YAAO,OAAA,KAAA;AAAA;AAGT,UAAI,IAAA,KAAA,CAAM,UAAW,CAAA,YAAY,CAAG,EAAA;AAClC,YAAO,OAAA,KAAA;AAAA;AAGT,UAAO,OAAA,CAAA,EAAG,YAAY,CAAA,EAAG,KAAK,CAAA,CAAA;AAAA,SAC/B,CAAA;AAAA;AACH,KACD,CAAA;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"OneLoginAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/onelogin/OneLoginAuth.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 oneloginAuthApiRef,\n OAuthRequestApi,\n AuthProviderInfo,\n ConfigApi,\n DiscoveryApi,\n} from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\n\n/**\n * OneLogin auth provider create options.\n * @public\n */\nexport type OneLoginAuthCreateOptions = {\n configApi?: ConfigApi;\n discoveryApi: DiscoveryApi;\n oauthRequestApi: OAuthRequestApi;\n environment?: string;\n provider?: AuthProviderInfo;\n};\n\nconst DEFAULT_PROVIDER = {\n id: 'onelogin',\n title: 'onelogin',\n icon: () => null,\n};\n\nconst OIDC_SCOPES: Set<String> = new Set([\n 'openid',\n 'profile',\n 'email',\n 'phone',\n 'address',\n 'groups',\n 'offline_access',\n]);\n\nconst SCOPE_PREFIX: string = 'onelogin.';\n\n/**\n * Implements a OneLogin OAuth flow.\n *\n * @public\n */\nexport default class OneLoginAuth {\n static create(\n options: OneLoginAuthCreateOptions,\n ): typeof oneloginAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n oauthRequestApi,\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes: ['openid', 'email', 'profile', 'offline_access'],\n scopeTransform(scopes) {\n return scopes.map(scope => {\n if (OIDC_SCOPES.has(scope)) {\n return scope;\n }\n\n if (scope.startsWith(SCOPE_PREFIX)) {\n return scope;\n }\n\n return `${SCOPE_PREFIX}${scope}`;\n });\n },\n });\n }\n}\n"],"names":[],"mappings":";;AAqCA,MAAM,gBAAA,GAAmB;AAAA,EACvB,EAAA,EAAI,UAAA;AAAA,EACJ,KAAA,EAAO,UAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAEA,MAAM,WAAA,uBAA+B,GAAA,CAAI;AAAA,EACvC,QAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,MAAM,YAAA,GAAuB,WAAA;AAO7B,MAAqB,YAAA,CAAa;AAAA,EAChC,OAAO,OACL,OAAA,EAC6B;AAC7B,IAAA,MAAM;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,WAAA,GAAc,aAAA;AAAA,MACd,QAAA,GAAW,gBAAA;AAAA,MACX;AAAA,KACF,GAAI,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAA,CAAO;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA,aAAA,EAAe,CAAC,QAAA,EAAU,OAAA,EAAS,WAAW,gBAAgB,CAAA;AAAA,MAC9D,eAAe,MAAA,EAAQ;AACrB,QAAA,OAAO,MAAA,CAAO,IAAI,CAAA,KAAA,KAAS;AACzB,UAAA,IAAI,WAAA,CAAY,GAAA,CAAI,KAAK,CAAA,EAAG;AAC1B,YAAA,OAAO,KAAA;AAAA,UACT;AAEA,UAAA,IAAI,KAAA,CAAM,UAAA,CAAW,YAAY,CAAA,EAAG;AAClC,YAAA,OAAO,KAAA;AAAA,UACT;AAEA,UAAA,OAAO,CAAA,EAAG,YAAY,CAAA,EAAG,KAAK,CAAA,CAAA;AAAA,QAChC,CAAC,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/saml/types.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 BackstageIdentityResponse,\n ProfileInfo,\n} from '@backstage/core-plugin-api';\nimport { z } from 'zod';\n\n/** @internal */\nexport type SamlSession = {\n profile: ProfileInfo;\n backstageIdentity: BackstageIdentityResponse;\n};\n\n/** @internal */\nexport const samlSessionSchema: z.ZodSchema<SamlSession> = z.object({\n profile: z.object({\n email: z.string().optional(),\n displayName: z.string().optional(),\n picture: z.string().optional(),\n }),\n backstageIdentity: z.object({\n token: z.string(),\n identity: z.object({\n type: z.literal('user'),\n userEntityRef: z.string(),\n ownershipEntityRefs: z.array(z.string()),\n }),\n }),\n});\n"],"names":[],"mappings":";;AA6B2D,EAAE,MAAO,CAAA;AAAA,EAClE,OAAA,EAAS,EAAE,MAAO,CAAA;AAAA,IAChB,KAAO,EAAA,CAAA,CAAE,MAAO,EAAA,CAAE,QAAS,EAAA;AAAA,IAC3B,WAAa,EAAA,CAAA,CAAE,MAAO,EAAA,CAAE,QAAS,EAAA;AAAA,IACjC,OAAS,EAAA,CAAA,CAAE,MAAO,EAAA,CAAE,QAAS;AAAA,GAC9B,CAAA;AAAA,EACD,iBAAA,EAAmB,EAAE,MAAO,CAAA;AAAA,IAC1B,KAAA,EAAO,EAAE,MAAO,EAAA;AAAA,IAChB,QAAA,EAAU,EAAE,MAAO,CAAA;AAAA,MACjB,IAAA,EAAM,CAAE,CAAA,OAAA,CAAQ,MAAM,CAAA;AAAA,MACtB,aAAA,EAAe,EAAE,MAAO,EAAA;AAAA,MACxB,mBAAqB,EAAA,CAAA,CAAE,KAAM,CAAA,CAAA,CAAE,QAAQ;AAAA,KACxC;AAAA,GACF;AACH,CAAC"}
1
+ {"version":3,"file":"types.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/saml/types.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 BackstageIdentityResponse,\n ProfileInfo,\n} from '@backstage/core-plugin-api';\nimport { z } from 'zod';\n\n/** @internal */\nexport type SamlSession = {\n profile: ProfileInfo;\n backstageIdentity: BackstageIdentityResponse;\n};\n\n/** @internal */\nexport const samlSessionSchema: z.ZodSchema<SamlSession> = z.object({\n profile: z.object({\n email: z.string().optional(),\n displayName: z.string().optional(),\n picture: z.string().optional(),\n }),\n backstageIdentity: z.object({\n token: z.string(),\n identity: z.object({\n type: z.literal('user'),\n userEntityRef: z.string(),\n ownershipEntityRefs: z.array(z.string()),\n }),\n }),\n});\n"],"names":[],"mappings":";;AA6B2D,EAAE,MAAA,CAAO;AAAA,EAClE,OAAA,EAAS,EAAE,MAAA,CAAO;AAAA,IAChB,KAAA,EAAO,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,IAC3B,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,IACjC,OAAA,EAAS,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AAAS,GAC9B,CAAA;AAAA,EACD,iBAAA,EAAmB,EAAE,MAAA,CAAO;AAAA,IAC1B,KAAA,EAAO,EAAE,MAAA,EAAO;AAAA,IAChB,QAAA,EAAU,EAAE,MAAA,CAAO;AAAA,MACjB,IAAA,EAAM,CAAA,CAAE,OAAA,CAAQ,MAAM,CAAA;AAAA,MACtB,aAAA,EAAe,EAAE,MAAA,EAAO;AAAA,MACxB,mBAAA,EAAqB,CAAA,CAAE,KAAA,CAAM,CAAA,CAAE,QAAQ;AAAA,KACxC;AAAA,GACF;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"VMwareCloudAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/vmwareCloud/VMwareCloudAuth.ts"],"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 */\nimport { vmwareCloudAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'vmwareCloudServices',\n title: 'VMware Cloud',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow for VMware Cloud Services\n *\n * @public\n */\nexport default class VMwareCloudAuth {\n static create(\n options: OAuthApiCreateOptions,\n ): typeof vmwareCloudAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n oauthRequestApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n defaultScopes = ['openid'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n });\n }\n}\n"],"names":[],"mappings":";;AAmBA,MAAM,gBAAmB,GAAA;AAAA,EACvB,EAAI,EAAA,qBAAA;AAAA,EACJ,KAAO,EAAA,cAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAOA,MAAqB,eAAgB,CAAA;AAAA,EACnC,OAAO,OACL,OACgC,EAAA;AAChC,IAAM,MAAA;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,WAAc,GAAA,aAAA;AAAA,MACd,QAAW,GAAA,gBAAA;AAAA,MACX,aAAA,GAAgB,CAAC,QAAQ;AAAA,KACvB,GAAA,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAO,CAAA;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"VMwareCloudAuth.esm.js","sources":["../../../../../../../../../../packages/core-app-api/src/apis/implementations/auth/vmwareCloud/VMwareCloudAuth.ts"],"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 */\nimport { vmwareCloudAuthApiRef } from '@backstage/core-plugin-api';\nimport { OAuth2 } from '../oauth2';\nimport { OAuthApiCreateOptions } from '../types';\n\nconst DEFAULT_PROVIDER = {\n id: 'vmwareCloudServices',\n title: 'VMware Cloud',\n icon: () => null,\n};\n\n/**\n * Implements the OAuth flow for VMware Cloud Services\n *\n * @public\n */\nexport default class VMwareCloudAuth {\n static create(\n options: OAuthApiCreateOptions,\n ): typeof vmwareCloudAuthApiRef.T {\n const {\n configApi,\n discoveryApi,\n oauthRequestApi,\n environment = 'development',\n provider = DEFAULT_PROVIDER,\n defaultScopes = ['openid'],\n } = options;\n\n return OAuth2.create({\n configApi,\n discoveryApi,\n oauthRequestApi,\n provider,\n environment,\n defaultScopes,\n });\n }\n}\n"],"names":[],"mappings":";;AAmBA,MAAM,gBAAA,GAAmB;AAAA,EACvB,EAAA,EAAI,qBAAA;AAAA,EACJ,KAAA,EAAO,cAAA;AAAA,EACP,MAAM,MAAM;AACd,CAAA;AAOA,MAAqB,eAAA,CAAgB;AAAA,EACnC,OAAO,OACL,OAAA,EACgC;AAChC,IAAA,MAAM;AAAA,MACJ,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,WAAA,GAAc,aAAA;AAAA,MACd,QAAA,GAAW,gBAAA;AAAA,MACX,aAAA,GAAgB,CAAC,QAAQ;AAAA,KAC3B,GAAI,OAAA;AAEJ,IAAA,OAAO,OAAO,MAAA,CAAO;AAAA,MACnB,SAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,EACH;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ApiAggregator.esm.js","sources":["../../../../../../../../packages/core-app-api/src/apis/system/ApiAggregator.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 { ApiRef, ApiHolder } from '@backstage/core-plugin-api';\n\n/**\n * An ApiHolder that queries multiple other holders from for\n * an Api implementation, returning the first one encountered..\n */\nexport class ApiAggregator implements ApiHolder {\n private readonly holders: ApiHolder[];\n\n constructor(...holders: ApiHolder[]) {\n this.holders = holders;\n }\n\n get<T>(apiRef: ApiRef<T>): T | undefined {\n for (const holder of this.holders) {\n const api = holder.get(apiRef);\n if (api) {\n return api;\n }\n }\n return undefined;\n }\n}\n"],"names":[],"mappings":"AAsBO,MAAM,aAAmC,CAAA;AAAA,EAC7B,OAAA;AAAA,EAEjB,eAAe,OAAsB,EAAA;AACnC,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA;AAAA;AACjB,EAEA,IAAO,MAAkC,EAAA;AACvC,IAAW,KAAA,MAAA,MAAA,IAAU,KAAK,OAAS,EAAA;AACjC,MAAM,MAAA,GAAA,GAAM,MAAO,CAAA,GAAA,CAAI,MAAM,CAAA;AAC7B,MAAA,IAAI,GAAK,EAAA;AACP,QAAO,OAAA,GAAA;AAAA;AACT;AAEF,IAAO,OAAA,KAAA,CAAA;AAAA;AAEX;;;;"}
1
+ {"version":3,"file":"ApiAggregator.esm.js","sources":["../../../../../../../../packages/core-app-api/src/apis/system/ApiAggregator.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 { ApiRef, ApiHolder } from '@backstage/core-plugin-api';\n\n/**\n * An ApiHolder that queries multiple other holders from for\n * an Api implementation, returning the first one encountered..\n */\nexport class ApiAggregator implements ApiHolder {\n private readonly holders: ApiHolder[];\n\n constructor(...holders: ApiHolder[]) {\n this.holders = holders;\n }\n\n get<T>(apiRef: ApiRef<T>): T | undefined {\n for (const holder of this.holders) {\n const api = holder.get(apiRef);\n if (api) {\n return api;\n }\n }\n return undefined;\n }\n}\n"],"names":[],"mappings":"AAsBO,MAAM,aAAA,CAAmC;AAAA,EAC7B,OAAA;AAAA,EAEjB,eAAe,OAAA,EAAsB;AACnC,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AAAA,EAEA,IAAO,MAAA,EAAkC;AACvC,IAAA,KAAA,MAAW,MAAA,IAAU,KAAK,OAAA,EAAS;AACjC,MAAA,MAAM,GAAA,GAAM,MAAA,CAAO,GAAA,CAAI,MAAM,CAAA;AAC7B,MAAA,IAAI,GAAA,EAAK;AACP,QAAA,OAAO,GAAA;AAAA,MACT;AAAA,IACF;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ApiProvider.esm.js","sources":["../../../../../../../../packages/core-app-api/src/apis/system/ApiProvider.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 { useContext, ReactNode, PropsWithChildren } from 'react';\nimport PropTypes from 'prop-types';\nimport { ApiHolder } from '@backstage/core-plugin-api';\nimport { ApiAggregator } from './ApiAggregator';\nimport {\n createVersionedValueMap,\n createVersionedContext,\n} from '@backstage/version-bridge';\n\n/**\n * Prop types for the ApiProvider component.\n * @public\n */\nexport type ApiProviderProps = {\n apis: ApiHolder;\n children: ReactNode;\n};\n\nconst ApiContext = createVersionedContext<{ 1: ApiHolder }>('api-context');\n\n/**\n * Provides an {@link @backstage/core-plugin-api#ApiHolder} for consumption in\n * the React tree.\n *\n * @public\n */\nexport const ApiProvider = (props: PropsWithChildren<ApiProviderProps>) => {\n const { apis, children } = props;\n const parentHolder = useContext(ApiContext)?.atVersion(1);\n const holder = parentHolder ? new ApiAggregator(apis, parentHolder) : apis;\n\n return (\n <ApiContext.Provider\n value={createVersionedValueMap({ 1: holder })}\n children={children}\n />\n );\n};\n\nApiProvider.propTypes = {\n apis: PropTypes.shape({ get: PropTypes.func.isRequired }).isRequired,\n children: PropTypes.node,\n};\n"],"names":[],"mappings":";;;;;;AAkCA,MAAM,UAAA,GAAa,uBAAyC,aAAa,CAAA;AAQ5D,MAAA,WAAA,GAAc,CAAC,KAA+C,KAAA;AACzE,EAAM,MAAA,EAAE,IAAM,EAAA,QAAA,EAAa,GAAA,KAAA;AAC3B,EAAA,MAAM,YAAe,GAAA,UAAA,CAAW,UAAU,CAAA,EAAG,UAAU,CAAC,CAAA;AACxD,EAAA,MAAM,SAAS,YAAe,GAAA,IAAI,aAAc,CAAA,IAAA,EAAM,YAAY,CAAI,GAAA,IAAA;AAEtE,EACE,uBAAA,GAAA;AAAA,IAAC,UAAW,CAAA,QAAA;AAAA,IAAX;AAAA,MACC,KAAO,EAAA,uBAAA,CAAwB,EAAE,CAAA,EAAG,QAAQ,CAAA;AAAA,MAC5C;AAAA;AAAA,GACF;AAEJ;AAEA,WAAA,CAAY,SAAY,GAAA;AAAA,EACtB,IAAA,EAAM,UAAU,KAAM,CAAA,EAAE,KAAK,SAAU,CAAA,IAAA,CAAK,UAAW,EAAC,CAAE,CAAA,UAAA;AAAA,EAC1D,UAAU,SAAU,CAAA;AACtB,CAAA;;;;"}
1
+ {"version":3,"file":"ApiProvider.esm.js","sources":["../../../../../../../../packages/core-app-api/src/apis/system/ApiProvider.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 { useContext, ReactNode, PropsWithChildren } from 'react';\nimport PropTypes from 'prop-types';\nimport { ApiHolder } from '@backstage/core-plugin-api';\nimport { ApiAggregator } from './ApiAggregator';\nimport {\n createVersionedValueMap,\n createVersionedContext,\n} from '@backstage/version-bridge';\n\n/**\n * Prop types for the ApiProvider component.\n * @public\n */\nexport type ApiProviderProps = {\n apis: ApiHolder;\n children: ReactNode;\n};\n\nconst ApiContext = createVersionedContext<{ 1: ApiHolder }>('api-context');\n\n/**\n * Provides an {@link @backstage/core-plugin-api#ApiHolder} for consumption in\n * the React tree.\n *\n * @public\n */\nexport const ApiProvider = (props: PropsWithChildren<ApiProviderProps>) => {\n const { apis, children } = props;\n const parentHolder = useContext(ApiContext)?.atVersion(1);\n const holder = parentHolder ? new ApiAggregator(apis, parentHolder) : apis;\n\n return (\n <ApiContext.Provider\n value={createVersionedValueMap({ 1: holder })}\n children={children}\n />\n );\n};\n\nApiProvider.propTypes = {\n apis: PropTypes.shape({ get: PropTypes.func.isRequired }).isRequired,\n children: PropTypes.node,\n};\n"],"names":[],"mappings":";;;;;;AAkCA,MAAM,UAAA,GAAa,uBAAyC,aAAa,CAAA;AAQlE,MAAM,WAAA,GAAc,CAAC,KAAA,KAA+C;AACzE,EAAA,MAAM,EAAE,IAAA,EAAM,QAAA,EAAS,GAAI,KAAA;AAC3B,EAAA,MAAM,YAAA,GAAe,UAAA,CAAW,UAAU,CAAA,EAAG,UAAU,CAAC,CAAA;AACxD,EAAA,MAAM,SAAS,YAAA,GAAe,IAAI,aAAA,CAAc,IAAA,EAAM,YAAY,CAAA,GAAI,IAAA;AAEtE,EAAA,uBACE,GAAA;AAAA,IAAC,UAAA,CAAW,QAAA;AAAA,IAAX;AAAA,MACC,KAAA,EAAO,uBAAA,CAAwB,EAAE,CAAA,EAAG,QAAQ,CAAA;AAAA,MAC5C;AAAA;AAAA,GACF;AAEJ;AAEA,WAAA,CAAY,SAAA,GAAY;AAAA,EACtB,IAAA,EAAM,UAAU,KAAA,CAAM,EAAE,KAAK,SAAA,CAAU,IAAA,CAAK,UAAA,EAAY,CAAA,CAAE,UAAA;AAAA,EAC1D,UAAU,SAAA,CAAU;AACtB,CAAA;;;;"}