@backstage-community/plugin-npm-backend 1.20.0 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @backstage-community/plugin-npm-backend
2
2
 
3
+ ## 1.21.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 57f14ed: Backstage version bump to v1.50.2
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [57f14ed]
12
+ - @backstage-community/plugin-npm-common@1.21.0
13
+
3
14
  ## 1.20.0
4
15
 
5
16
  ### Minor Changes
package/README.md CHANGED
@@ -93,17 +93,15 @@ you must install also the backend plugin and [configure it](./registries.md).
93
93
 
94
94
  ### Load plugin via the new frontend system (alpha)
95
95
 
96
- For early adaopters of the new frontend system.
97
-
98
- Your Backstage frontend app must use that new frontend system which isn't the default at the moment.
96
+ Ensure that your Backstage frontend app is using that new frontend system.
99
97
 
100
98
  1. Install the frontend dependency:
101
99
 
102
100
  ```sh
103
- yarn workspace app-next add @backstage-community/plugin-npm
101
+ yarn workspace app add @backstage-community/plugin-npm
104
102
  ```
105
103
 
106
- 2. Add the package to your `packages/app-next/src/App.tsx`.
104
+ 2. Add the package to your `packages/app/src/App.tsx`.
107
105
 
108
106
  ```tsx
109
107
  import npmPlugin from '@backstage-community/plugin-npm/alpha';
@@ -120,35 +118,20 @@ Your Backstage frontend app must use that new frontend system which isn't the de
120
118
  });
121
119
  ```
122
120
 
123
- 3. Optional enable translation via the `TranslationBlueprint` extension:
121
+ 3. Optionally enable translation via an `app` module that adds one `TranslationBlueprint` extension:
124
122
 
125
123
  ```tsx
126
- import { TranslationBlueprint } from '@backstage/plugin-app-react';
127
-
128
124
  import npmPlugin, {
129
- npmTranslations,
125
+ npmTranslationsModule,
130
126
  } from '@backstage-community/plugin-npm/alpha';
131
127
  ```
132
128
 
133
129
  ```tsx
134
- const npmTranslation = TranslationBlueprint.make({
135
- name: 'npmTranslation',
136
- params: {
137
- resource: npmTranslations,
138
- },
139
- });
140
-
141
130
  export default createApp({
142
131
  features: [
143
- createFrontendModule({
144
- pluginId: 'app',
145
- extensions: [
146
- // ...other extensions
147
- npmTranslation,
148
- ],
149
- }),
150
132
  // ...other plugins
151
133
  npmPlugin,
134
+ npmTranslationsModule,
152
135
  ],
153
136
  });
154
137
  ```
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.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 {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node';\n\nimport { createRouter } from './router';\nimport { NpmRegistryServiceImpl } from './services/NpmRegistryServiceImpl';\n\n/**\n * npmPlugin backend plugin\n *\n * @public\n */\nexport const npmPlugin = createBackendPlugin({\n pluginId: 'npm',\n register(env) {\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n catalog: catalogServiceRef,\n },\n async init({ logger, config, httpAuth, httpRouter, catalog }) {\n const npmRegistryService = new NpmRegistryServiceImpl({\n logger,\n config,\n catalog,\n });\n\n httpRouter.use(\n await createRouter({\n httpAuth,\n npmRegistryService,\n }),\n );\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","catalogServiceRef","NpmRegistryServiceImpl","createRouter"],"mappings":";;;;;;;AA6BO,MAAM,YAAYA,oCAAoB,CAAA;AAAA,EAC3C,QAAU,EAAA,KAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQC,6BAAa,CAAA,MAAA;AAAA,QACrB,QAAQA,6BAAa,CAAA,UAAA;AAAA,QACrB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,YAAYA,6BAAa,CAAA,UAAA;AAAA,QACzB,OAAS,EAAAC;AAAA,OACX;AAAA,MACA,MAAM,KAAK,EAAE,MAAA,EAAQ,QAAQ,QAAU,EAAA,UAAA,EAAY,SAAW,EAAA;AAC5D,QAAM,MAAA,kBAAA,GAAqB,IAAIC,6CAAuB,CAAA;AAAA,UACpD,MAAA;AAAA,UACA,MAAA;AAAA,UACA;AAAA,SACD,CAAA;AAED,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAMC,mBAAa,CAAA;AAAA,YACjB,QAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AAAA;AACF,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.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 {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node';\n\nimport { createRouter } from './router';\nimport { NpmRegistryServiceImpl } from './services/NpmRegistryServiceImpl';\n\n/**\n * npmPlugin backend plugin\n *\n * @public\n */\nexport const npmPlugin = createBackendPlugin({\n pluginId: 'npm',\n register(env) {\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n catalog: catalogServiceRef,\n },\n async init({ logger, config, httpAuth, httpRouter, catalog }) {\n const npmRegistryService = new NpmRegistryServiceImpl({\n logger,\n config,\n catalog,\n });\n\n httpRouter.use(\n await createRouter({\n httpAuth,\n npmRegistryService,\n }),\n );\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","catalogServiceRef","NpmRegistryServiceImpl","createRouter"],"mappings":";;;;;;;AA6BO,MAAM,YAAYA,oCAAA,CAAoB;AAAA,EAC3C,QAAA,EAAU,KAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,QAAQC,6BAAA,CAAa,MAAA;AAAA,QACrB,QAAQA,6BAAA,CAAa,UAAA;AAAA,QACrB,UAAUA,6BAAA,CAAa,QAAA;AAAA,QACvB,YAAYA,6BAAA,CAAa,UAAA;AAAA,QACzB,OAAA,EAASC;AAAA,OACX;AAAA,MACA,MAAM,KAAK,EAAE,MAAA,EAAQ,QAAQ,QAAA,EAAU,UAAA,EAAY,SAAQ,EAAG;AAC5D,QAAA,MAAM,kBAAA,GAAqB,IAAIC,6CAAA,CAAuB;AAAA,UACpD,MAAA;AAAA,UACA,MAAA;AAAA,UACA;AAAA,SACD,CAAA;AAED,QAAA,UAAA,CAAW,GAAA;AAAA,UACT,MAAMC,mBAAA,CAAa;AAAA,YACjB,QAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"router.cjs.js","sources":["../src/router.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 { HttpAuthService } from '@backstage/backend-plugin-api';\nimport { ResponseError } from '@backstage/errors';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { NpmRegistryService } from './services';\n\nexport async function createRouter({\n httpAuth,\n npmRegistryService,\n}: {\n httpAuth: HttpAuthService;\n npmRegistryService: NpmRegistryService;\n}): Promise<express.Router> {\n const router = Router();\n router.use(express.json());\n\n router.get('/:entityRef/package-info', async (req, res) => {\n const entityRef = req.params.entityRef;\n const credentials = await httpAuth.credentials(req, { allow: ['user'] });\n try {\n const packageInfo = await npmRegistryService.getPackageInfo(entityRef, {\n credentials,\n });\n res.json(packageInfo);\n } catch (error) {\n if (error instanceof ResponseError) {\n res.status(error.statusCode).json(error.response);\n } else {\n throw error;\n }\n }\n });\n\n return router;\n}\n"],"names":["Router","express","ResponseError"],"mappings":";;;;;;;;;;;AAqBA,eAAsB,YAAa,CAAA;AAAA,EACjC,QAAA;AAAA,EACA;AACF,CAG4B,EAAA;AAC1B,EAAA,MAAM,SAASA,uBAAO,EAAA;AACtB,EAAO,MAAA,CAAA,GAAA,CAAIC,wBAAQ,CAAA,IAAA,EAAM,CAAA;AAEzB,EAAA,MAAA,CAAO,GAAI,CAAA,0BAAA,EAA4B,OAAO,GAAA,EAAK,GAAQ,KAAA;AACzD,IAAM,MAAA,SAAA,GAAY,IAAI,MAAO,CAAA,SAAA;AAC7B,IAAM,MAAA,WAAA,GAAc,MAAM,QAAA,CAAS,WAAY,CAAA,GAAA,EAAK,EAAE,KAAO,EAAA,CAAC,MAAM,CAAA,EAAG,CAAA;AACvE,IAAI,IAAA;AACF,MAAA,MAAM,WAAc,GAAA,MAAM,kBAAmB,CAAA,cAAA,CAAe,SAAW,EAAA;AAAA,QACrE;AAAA,OACD,CAAA;AACD,MAAA,GAAA,CAAI,KAAK,WAAW,CAAA;AAAA,aACb,KAAO,EAAA;AACd,MAAA,IAAI,iBAAiBC,oBAAe,EAAA;AAClC,QAAA,GAAA,CAAI,OAAO,KAAM,CAAA,UAAU,CAAE,CAAA,IAAA,CAAK,MAAM,QAAQ,CAAA;AAAA,OAC3C,MAAA;AACL,QAAM,MAAA,KAAA;AAAA;AACR;AACF,GACD,CAAA;AAED,EAAO,OAAA,MAAA;AACT;;;;"}
1
+ {"version":3,"file":"router.cjs.js","sources":["../src/router.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 { HttpAuthService } from '@backstage/backend-plugin-api';\nimport { ResponseError } from '@backstage/errors';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport { NpmRegistryService } from './services';\n\nexport async function createRouter({\n httpAuth,\n npmRegistryService,\n}: {\n httpAuth: HttpAuthService;\n npmRegistryService: NpmRegistryService;\n}): Promise<express.Router> {\n const router = Router();\n router.use(express.json());\n\n router.get('/:entityRef/package-info', async (req, res) => {\n const entityRef = req.params.entityRef;\n const credentials = await httpAuth.credentials(req, { allow: ['user'] });\n try {\n const packageInfo = await npmRegistryService.getPackageInfo(entityRef, {\n credentials,\n });\n res.json(packageInfo);\n } catch (error) {\n if (error instanceof ResponseError) {\n res.status(error.statusCode).json(error.response);\n } else {\n throw error;\n }\n }\n });\n\n return router;\n}\n"],"names":["Router","express","ResponseError"],"mappings":";;;;;;;;;;;AAqBA,eAAsB,YAAA,CAAa;AAAA,EACjC,QAAA;AAAA,EACA;AACF,CAAA,EAG4B;AAC1B,EAAA,MAAM,SAASA,uBAAA,EAAO;AACtB,EAAA,MAAA,CAAO,GAAA,CAAIC,wBAAA,CAAQ,IAAA,EAAM,CAAA;AAEzB,EAAA,MAAA,CAAO,GAAA,CAAI,0BAAA,EAA4B,OAAO,GAAA,EAAK,GAAA,KAAQ;AACzD,IAAA,MAAM,SAAA,GAAY,IAAI,MAAA,CAAO,SAAA;AAC7B,IAAA,MAAM,WAAA,GAAc,MAAM,QAAA,CAAS,WAAA,CAAY,GAAA,EAAK,EAAE,KAAA,EAAO,CAAC,MAAM,CAAA,EAAG,CAAA;AACvE,IAAA,IAAI;AACF,MAAA,MAAM,WAAA,GAAc,MAAM,kBAAA,CAAmB,cAAA,CAAe,SAAA,EAAW;AAAA,QACrE;AAAA,OACD,CAAA;AACD,MAAA,GAAA,CAAI,KAAK,WAAW,CAAA;AAAA,IACtB,SAAS,KAAA,EAAO;AACd,MAAA,IAAI,iBAAiBC,oBAAA,EAAe;AAClC,QAAA,GAAA,CAAI,OAAO,KAAA,CAAM,UAAU,CAAA,CAAE,IAAA,CAAK,MAAM,QAAQ,CAAA;AAAA,MAClD,CAAA,MAAO;AACL,QAAA,MAAM,KAAA;AAAA,MACR;AAAA,IACF;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"NpmRegistryServiceImpl.cjs.js","sources":["../../src/services/NpmRegistryServiceImpl.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 {\n BackstageCredentials,\n BackstageUserPrincipal,\n LoggerService,\n RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport { NotFoundError } from '@backstage/errors';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\n\nimport {\n NpmAnnotation,\n NpmRegistryClient,\n NpmRegistryPackageInfo,\n} from '@backstage-community/plugin-npm-common';\n\nimport { NpmRegistryService } from './NpmRegistryService';\nimport { Config } from '../../config';\n\nexport type Options = {\n logger: LoggerService;\n config: RootConfigService;\n catalog: CatalogService;\n};\n\nexport class NpmRegistryServiceImpl implements NpmRegistryService {\n private readonly logger: LoggerService;\n private readonly config: RootConfigService;\n private readonly catalog: CatalogService;\n\n constructor(options: Options) {\n this.logger = options.logger;\n this.config = options.config;\n this.catalog = options.catalog;\n }\n\n async getPackageInfo(\n entityRef: string,\n options: { credentials: BackstageCredentials<BackstageUserPrincipal> },\n ): Promise<NpmRegistryPackageInfo> {\n const entity = await this.catalog.getEntityByRef(entityRef, options);\n if (!entity) {\n throw new NotFoundError(`No entity found for ref '${entityRef}'`);\n }\n\n const config = this.config.getOptional<Config['npm']>('npm');\n const defaultRegistry = config?.defaultRegistry;\n\n const packageName =\n entity.metadata.annotations?.[NpmAnnotation.PACKAGE_NAME];\n const registryName =\n entity.metadata.annotations?.[NpmAnnotation.REGISTRY_NAME] ||\n defaultRegistry;\n if (!packageName) {\n throw new NotFoundError(\n `Npm package name not defined at entity '${entityRef}'`,\n );\n }\n\n const registry = config?.registries?.find(r => r.name === registryName);\n if (!registry && registryName !== 'default' && registryName !== 'npmjs') {\n throw new NotFoundError(\n `Npm registry config '${registryName}' not found as defined in entity '${entityRef}'`,\n );\n }\n\n this.logger.info('Will use npmjs package info:', {\n entityRef,\n packageName,\n registryUrl: registry?.url,\n registryToken: registry?.token ? 'yes' : 'no',\n });\n\n const client = new NpmRegistryClient({\n // TODO pass apiFetch.fetch\n baseUrl: registry?.url,\n token: registry?.token,\n extraRequestHeaders: registry?.extraRequestHeaders,\n });\n const packageInfo = await client.getPackageInfo(packageName);\n return packageInfo;\n }\n}\n"],"names":["NotFoundError","NpmAnnotation","NpmRegistryClient"],"mappings":";;;;;AAuCO,MAAM,sBAAqD,CAAA;AAAA,EAC/C,MAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EAEjB,YAAY,OAAkB,EAAA;AAC5B,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA;AACtB,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA;AACtB,IAAA,IAAA,CAAK,UAAU,OAAQ,CAAA,OAAA;AAAA;AACzB,EAEA,MAAM,cACJ,CAAA,SAAA,EACA,OACiC,EAAA;AACjC,IAAA,MAAM,SAAS,MAAM,IAAA,CAAK,OAAQ,CAAA,cAAA,CAAe,WAAW,OAAO,CAAA;AACnE,IAAA,IAAI,CAAC,MAAQ,EAAA;AACX,MAAA,MAAM,IAAIA,oBAAA,CAAc,CAA4B,yBAAA,EAAA,SAAS,CAAG,CAAA,CAAA,CAAA;AAAA;AAGlE,IAAA,MAAM,MAAS,GAAA,IAAA,CAAK,MAAO,CAAA,WAAA,CAA2B,KAAK,CAAA;AAC3D,IAAA,MAAM,kBAAkB,MAAQ,EAAA,eAAA;AAEhC,IAAA,MAAM,WACJ,GAAA,MAAA,CAAO,QAAS,CAAA,WAAA,GAAcC,8BAAc,YAAY,CAAA;AAC1D,IAAA,MAAM,eACJ,MAAO,CAAA,QAAA,CAAS,WAAc,GAAAA,6BAAA,CAAc,aAAa,CACzD,IAAA,eAAA;AACF,IAAA,IAAI,CAAC,WAAa,EAAA;AAChB,MAAA,MAAM,IAAID,oBAAA;AAAA,QACR,2CAA2C,SAAS,CAAA,CAAA;AAAA,OACtD;AAAA;AAGF,IAAA,MAAM,WAAW,MAAQ,EAAA,UAAA,EAAY,KAAK,CAAK,CAAA,KAAA,CAAA,CAAE,SAAS,YAAY,CAAA;AACtE,IAAA,IAAI,CAAC,QAAA,IAAY,YAAiB,KAAA,SAAA,IAAa,iBAAiB,OAAS,EAAA;AACvE,MAAA,MAAM,IAAIA,oBAAA;AAAA,QACR,CAAA,qBAAA,EAAwB,YAAY,CAAA,kCAAA,EAAqC,SAAS,CAAA,CAAA;AAAA,OACpF;AAAA;AAGF,IAAK,IAAA,CAAA,MAAA,CAAO,KAAK,8BAAgC,EAAA;AAAA,MAC/C,SAAA;AAAA,MACA,WAAA;AAAA,MACA,aAAa,QAAU,EAAA,GAAA;AAAA,MACvB,aAAA,EAAe,QAAU,EAAA,KAAA,GAAQ,KAAQ,GAAA;AAAA,KAC1C,CAAA;AAED,IAAM,MAAA,MAAA,GAAS,IAAIE,iCAAkB,CAAA;AAAA;AAAA,MAEnC,SAAS,QAAU,EAAA,GAAA;AAAA,MACnB,OAAO,QAAU,EAAA,KAAA;AAAA,MACjB,qBAAqB,QAAU,EAAA;AAAA,KAChC,CAAA;AACD,IAAA,MAAM,WAAc,GAAA,MAAM,MAAO,CAAA,cAAA,CAAe,WAAW,CAAA;AAC3D,IAAO,OAAA,WAAA;AAAA;AAEX;;;;"}
1
+ {"version":3,"file":"NpmRegistryServiceImpl.cjs.js","sources":["../../src/services/NpmRegistryServiceImpl.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 {\n BackstageCredentials,\n BackstageUserPrincipal,\n LoggerService,\n RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport { NotFoundError } from '@backstage/errors';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\n\nimport {\n NpmAnnotation,\n NpmRegistryClient,\n NpmRegistryPackageInfo,\n} from '@backstage-community/plugin-npm-common';\n\nimport { NpmRegistryService } from './NpmRegistryService';\nimport { Config } from '../../config';\n\nexport type Options = {\n logger: LoggerService;\n config: RootConfigService;\n catalog: CatalogService;\n};\n\nexport class NpmRegistryServiceImpl implements NpmRegistryService {\n private readonly logger: LoggerService;\n private readonly config: RootConfigService;\n private readonly catalog: CatalogService;\n\n constructor(options: Options) {\n this.logger = options.logger;\n this.config = options.config;\n this.catalog = options.catalog;\n }\n\n async getPackageInfo(\n entityRef: string,\n options: { credentials: BackstageCredentials<BackstageUserPrincipal> },\n ): Promise<NpmRegistryPackageInfo> {\n const entity = await this.catalog.getEntityByRef(entityRef, options);\n if (!entity) {\n throw new NotFoundError(`No entity found for ref '${entityRef}'`);\n }\n\n const config = this.config.getOptional<Config['npm']>('npm');\n const defaultRegistry = config?.defaultRegistry;\n\n const packageName =\n entity.metadata.annotations?.[NpmAnnotation.PACKAGE_NAME];\n const registryName =\n entity.metadata.annotations?.[NpmAnnotation.REGISTRY_NAME] ||\n defaultRegistry;\n if (!packageName) {\n throw new NotFoundError(\n `Npm package name not defined at entity '${entityRef}'`,\n );\n }\n\n const registry = config?.registries?.find(r => r.name === registryName);\n if (!registry && registryName !== 'default' && registryName !== 'npmjs') {\n throw new NotFoundError(\n `Npm registry config '${registryName}' not found as defined in entity '${entityRef}'`,\n );\n }\n\n this.logger.info('Will use npmjs package info:', {\n entityRef,\n packageName,\n registryUrl: registry?.url,\n registryToken: registry?.token ? 'yes' : 'no',\n });\n\n const client = new NpmRegistryClient({\n // TODO pass apiFetch.fetch\n baseUrl: registry?.url,\n token: registry?.token,\n extraRequestHeaders: registry?.extraRequestHeaders,\n });\n const packageInfo = await client.getPackageInfo(packageName);\n return packageInfo;\n }\n}\n"],"names":["NotFoundError","NpmAnnotation","NpmRegistryClient"],"mappings":";;;;;AAuCO,MAAM,sBAAA,CAAqD;AAAA,EAC/C,MAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EAEjB,YAAY,OAAA,EAAkB;AAC5B,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,OAAA;AAAA,EACzB;AAAA,EAEA,MAAM,cAAA,CACJ,SAAA,EACA,OAAA,EACiC;AACjC,IAAA,MAAM,SAAS,MAAM,IAAA,CAAK,OAAA,CAAQ,cAAA,CAAe,WAAW,OAAO,CAAA;AACnE,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAIA,oBAAA,CAAc,CAAA,yBAAA,EAA4B,SAAS,CAAA,CAAA,CAAG,CAAA;AAAA,IAClE;AAEA,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,MAAA,CAAO,WAAA,CAA2B,KAAK,CAAA;AAC3D,IAAA,MAAM,kBAAkB,MAAA,EAAQ,eAAA;AAEhC,IAAA,MAAM,WAAA,GACJ,MAAA,CAAO,QAAA,CAAS,WAAA,GAAcC,8BAAc,YAAY,CAAA;AAC1D,IAAA,MAAM,eACJ,MAAA,CAAO,QAAA,CAAS,WAAA,GAAcA,6BAAA,CAAc,aAAa,CAAA,IACzD,eAAA;AACF,IAAA,IAAI,CAAC,WAAA,EAAa;AAChB,MAAA,MAAM,IAAID,oBAAA;AAAA,QACR,2CAA2C,SAAS,CAAA,CAAA;AAAA,OACtD;AAAA,IACF;AAEA,IAAA,MAAM,WAAW,MAAA,EAAQ,UAAA,EAAY,KAAK,CAAA,CAAA,KAAK,CAAA,CAAE,SAAS,YAAY,CAAA;AACtE,IAAA,IAAI,CAAC,QAAA,IAAY,YAAA,KAAiB,SAAA,IAAa,iBAAiB,OAAA,EAAS;AACvE,MAAA,MAAM,IAAIA,oBAAA;AAAA,QACR,CAAA,qBAAA,EAAwB,YAAY,CAAA,kCAAA,EAAqC,SAAS,CAAA,CAAA;AAAA,OACpF;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,MAAA,CAAO,KAAK,8BAAA,EAAgC;AAAA,MAC/C,SAAA;AAAA,MACA,WAAA;AAAA,MACA,aAAa,QAAA,EAAU,GAAA;AAAA,MACvB,aAAA,EAAe,QAAA,EAAU,KAAA,GAAQ,KAAA,GAAQ;AAAA,KAC1C,CAAA;AAED,IAAA,MAAM,MAAA,GAAS,IAAIE,iCAAA,CAAkB;AAAA;AAAA,MAEnC,SAAS,QAAA,EAAU,GAAA;AAAA,MACnB,OAAO,QAAA,EAAU,KAAA;AAAA,MACjB,qBAAqB,QAAA,EAAU;AAAA,KAChC,CAAA;AACD,IAAA,MAAM,WAAA,GAAc,MAAM,MAAA,CAAO,cAAA,CAAe,WAAW,CAAA;AAC3D,IAAA,OAAO,WAAA;AAAA,EACT;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage-community/plugin-npm-backend",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "main": "dist/index.cjs.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -25,6 +25,7 @@
25
25
  },
26
26
  "scripts": {
27
27
  "start": "backstage-cli package start",
28
+ "start:alpha": "backstage-cli package start",
28
29
  "build": "backstage-cli package build",
29
30
  "lint": "backstage-cli package lint",
30
31
  "test": "backstage-cli package test",
@@ -33,17 +34,17 @@
33
34
  "postpack": "backstage-cli package postpack"
34
35
  },
35
36
  "dependencies": {
36
- "@backstage-community/plugin-npm-common": "^1.20.0",
37
- "@backstage/backend-defaults": "^0.16.0",
38
- "@backstage/backend-plugin-api": "^1.8.0",
39
- "@backstage/errors": "^1.2.7",
40
- "@backstage/plugin-catalog-node": "^2.1.0",
37
+ "@backstage-community/plugin-npm-common": "^1.21.0",
38
+ "@backstage/backend-defaults": "^0.17.0",
39
+ "@backstage/backend-plugin-api": "^1.9.0",
40
+ "@backstage/errors": "^1.3.0",
41
+ "@backstage/plugin-catalog-node": "^2.2.0",
41
42
  "express": "^4.17.1",
42
43
  "express-promise-router": "^4.1.0"
43
44
  },
44
45
  "devDependencies": {
45
- "@backstage/backend-test-utils": "^1.11.1",
46
- "@backstage/cli": "^0.36.0",
46
+ "@backstage/backend-test-utils": "^1.11.2",
47
+ "@backstage/cli": "^0.36.1",
47
48
  "@types/express": "^4.17.1"
48
49
  },
49
50
  "files": [