@backstage/cli 0.36.0-next.1 → 0.36.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 (263) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/config/eslint-factory.js +1 -0
  3. package/config/getJestEnvironment.js +7 -29
  4. package/config/jest-environment-jsdom/index.js +9 -43
  5. package/config/jest.js +7 -401
  6. package/config/jestCacheResultProcessor.cjs +10 -6
  7. package/config/jestCachingModuleLoader.js +11 -19
  8. package/config/jestFileTransform.js +11 -28
  9. package/config/jestRejectNetworkRequests.js +10 -53
  10. package/config/jestSucraseTransform.js +10 -70
  11. package/config/jestSwcTransform.js +10 -27
  12. package/config/jestYamlTransform.js +11 -24
  13. package/config/nodeTransform.cjs +10 -70
  14. package/config/nodeTransformHooks.mjs +4 -278
  15. package/config/webpack-public-path.js +10 -14
  16. package/dist/cli-internal/src/InternalCliModule.cjs.js +11 -0
  17. package/dist/cli-internal/src/InternalCommandNode.cjs.js +25 -0
  18. package/dist/cli-internal/src/knownPluginPackages.cjs.js +40 -0
  19. package/dist/index.cjs.js +21 -10
  20. package/dist/wiring/CliInitializer.cjs.js +61 -20
  21. package/dist/wiring/CommandGraph.cjs.js +81 -23
  22. package/dist/wiring/discoverCliModules.cjs.js +44 -0
  23. package/package.json +27 -154
  24. package/dist/modules/build/commands/buildWorkspace.cjs.js +0 -24
  25. package/dist/modules/build/commands/package/build/command.cjs.js +0 -89
  26. package/dist/modules/build/commands/package/build/index.cjs.js +0 -8
  27. package/dist/modules/build/commands/package/clean.cjs.js +0 -21
  28. package/dist/modules/build/commands/package/postpack.cjs.js +0 -15
  29. package/dist/modules/build/commands/package/prepack.cjs.js +0 -29
  30. package/dist/modules/build/commands/package/start/command.cjs.js +0 -23
  31. package/dist/modules/build/commands/package/start/index.cjs.js +0 -8
  32. package/dist/modules/build/commands/package/start/resolveLinkedWorkspace.cjs.js +0 -34
  33. package/dist/modules/build/commands/package/start/startBackend.cjs.js +0 -46
  34. package/dist/modules/build/commands/package/start/startFrontend.cjs.js +0 -50
  35. package/dist/modules/build/commands/package/start/startPackage.cjs.js +0 -53
  36. package/dist/modules/build/commands/repo/build.cjs.js +0 -114
  37. package/dist/modules/build/commands/repo/clean.cjs.js +0 -41
  38. package/dist/modules/build/commands/repo/start.cjs.js +0 -150
  39. package/dist/modules/build/index.cjs.js +0 -192
  40. package/dist/modules/build/lib/buildBackend.cjs.js +0 -81
  41. package/dist/modules/build/lib/buildFrontend.cjs.js +0 -50
  42. package/dist/modules/build/lib/builder/config.cjs.js +0 -257
  43. package/dist/modules/build/lib/builder/packager.cjs.js +0 -131
  44. package/dist/modules/build/lib/builder/plugins.cjs.js +0 -125
  45. package/dist/modules/build/lib/builder/types.cjs.js +0 -10
  46. package/dist/modules/build/lib/bundler/ConfigInjectingHtmlWebpackPlugin.cjs.js +0 -43
  47. package/dist/modules/build/lib/bundler/bundle.cjs.js +0 -189
  48. package/dist/modules/build/lib/bundler/config.cjs.js +0 -308
  49. package/dist/modules/build/lib/bundler/hasReactDomClient.cjs.js +0 -17
  50. package/dist/modules/build/lib/bundler/linkWorkspaces.cjs.js +0 -34
  51. package/dist/modules/build/lib/bundler/moduleFederation.cjs.js +0 -135
  52. package/dist/modules/build/lib/bundler/optimization.cjs.js +0 -68
  53. package/dist/modules/build/lib/bundler/packageDetection.cjs.js +0 -124
  54. package/dist/modules/build/lib/bundler/paths.cjs.js +0 -62
  55. package/dist/modules/build/lib/bundler/server.cjs.js +0 -231
  56. package/dist/modules/build/lib/bundler/transforms.cjs.js +0 -145
  57. package/dist/modules/build/lib/config.cjs.js +0 -94
  58. package/dist/modules/build/lib/entryPoints.cjs.js +0 -49
  59. package/dist/modules/build/lib/ipc/IpcServer.cjs.js +0 -60
  60. package/dist/modules/build/lib/ipc/ServerDataStore.cjs.js +0 -36
  61. package/dist/modules/build/lib/optionsParser.cjs.js +0 -37
  62. package/dist/modules/build/lib/packager/createDistWorkspace.cjs.js +0 -235
  63. package/dist/modules/build/lib/packager/productionPack.cjs.js +0 -160
  64. package/dist/modules/build/lib/publishing.cjs.js +0 -40
  65. package/dist/modules/build/lib/role.cjs.js +0 -24
  66. package/dist/modules/build/lib/runner/runBackend.cjs.js +0 -136
  67. package/dist/modules/build/lib/typeDistProject.cjs.js +0 -89
  68. package/dist/modules/build/lib/urls.cjs.js +0 -13
  69. package/dist/modules/config/commands/docs.cjs.js +0 -62
  70. package/dist/modules/config/commands/print.cjs.js +0 -80
  71. package/dist/modules/config/commands/schema.cjs.js +0 -55
  72. package/dist/modules/config/commands/validate.cjs.js +0 -49
  73. package/dist/modules/config/index.cjs.js +0 -51
  74. package/dist/modules/config/lib/config.cjs.js +0 -94
  75. package/dist/modules/create-github-app/commands/create-github-app/GithubCreateAppServer.cjs.js +0 -127
  76. package/dist/modules/create-github-app/commands/create-github-app/index.cjs.js +0 -115
  77. package/dist/modules/create-github-app/index.cjs.js +0 -27
  78. package/dist/modules/info/commands/info.cjs.js +0 -181
  79. package/dist/modules/info/index.cjs.js +0 -19
  80. package/dist/modules/lint/commands/package/lint.cjs.js +0 -46
  81. package/dist/modules/lint/commands/repo/lint.cjs.js +0 -212
  82. package/dist/modules/lint/index.cjs.js +0 -82
  83. package/dist/modules/lint/lib/optionsParser.cjs.js +0 -37
  84. package/dist/modules/maintenance/commands/repo/fix.cjs.js +0 -400
  85. package/dist/modules/maintenance/commands/repo/list-deprecations.cjs.js +0 -74
  86. package/dist/modules/maintenance/index.cjs.js +0 -42
  87. package/dist/modules/migrate/commands/packageExports.cjs.js +0 -15
  88. package/dist/modules/migrate/commands/packageLintConfigs.cjs.js +0 -77
  89. package/dist/modules/migrate/commands/packageRole.cjs.js +0 -57
  90. package/dist/modules/migrate/commands/packageScripts.cjs.js +0 -87
  91. package/dist/modules/migrate/commands/reactRouterDeps.cjs.js +0 -51
  92. package/dist/modules/migrate/commands/versions/bump.cjs.js +0 -373
  93. package/dist/modules/migrate/commands/versions/migrate.cjs.js +0 -112
  94. package/dist/modules/migrate/index.cjs.js +0 -82
  95. package/dist/modules/migrate/lib/utils.cjs.js +0 -44
  96. package/dist/modules/migrate/lib/versioning/packages.cjs.js +0 -71
  97. package/dist/modules/migrate/lib/versioning/yarn.cjs.js +0 -28
  98. package/dist/modules/new/commands/new.cjs.js +0 -60
  99. package/dist/modules/new/index.cjs.js +0 -68
  100. package/dist/modules/new/lib/codeowners/codeowners.cjs.js +0 -92
  101. package/dist/modules/new/lib/createNewPackage.cjs.js +0 -32
  102. package/dist/modules/new/lib/defaultTemplates.cjs.js +0 -17
  103. package/dist/modules/new/lib/execution/PortableTemplater.cjs.js +0 -89
  104. package/dist/modules/new/lib/execution/executePortableTemplate.cjs.js +0 -66
  105. package/dist/modules/new/lib/execution/installNewPackage.cjs.js +0 -127
  106. package/dist/modules/new/lib/execution/writeTemplateContents.cjs.js +0 -116
  107. package/dist/modules/new/lib/preparation/collectPortableTemplateInput.cjs.js +0 -157
  108. package/dist/modules/new/lib/preparation/loadPortableTemplate.cjs.js +0 -81
  109. package/dist/modules/new/lib/preparation/loadPortableTemplateConfig.cjs.js +0 -132
  110. package/dist/modules/new/lib/preparation/resolvePackageParams.cjs.js +0 -40
  111. package/dist/modules/new/lib/preparation/selectTemplateInteractively.cjs.js +0 -38
  112. package/dist/modules/new/lib/tasks.cjs.js +0 -51
  113. package/dist/modules/new/lib/types.cjs.js +0 -19
  114. package/dist/modules/new/lib/version.cjs.js +0 -91
  115. package/dist/modules/test/commands/package/test.cjs.js +0 -65
  116. package/dist/modules/test/commands/repo/test.cjs.js +0 -288
  117. package/dist/modules/test/index.cjs.js +0 -54
  118. package/dist/modules/translations/commands/export.cjs.js +0 -127
  119. package/dist/modules/translations/commands/import.cjs.js +0 -164
  120. package/dist/modules/translations/index.cjs.js +0 -24
  121. package/dist/modules/translations/lib/discoverPackages.cjs.js +0 -121
  122. package/dist/modules/translations/lib/extractTranslations.cjs.js +0 -71
  123. package/dist/modules/translations/lib/messageFilePath.cjs.js +0 -43
  124. package/dist/packages/backend-defaults/package.json.cjs.js +0 -6
  125. package/dist/packages/backend-plugin-api/package.json.cjs.js +0 -6
  126. package/dist/packages/backend-test-utils/package.json.cjs.js +0 -6
  127. package/dist/packages/catalog-client/package.json.cjs.js +0 -6
  128. package/dist/packages/cli/package.json.cjs.js +0 -156
  129. package/dist/packages/config/package.json.cjs.js +0 -6
  130. package/dist/packages/core-app-api/package.json.cjs.js +0 -6
  131. package/dist/packages/core-components/package.json.cjs.js +0 -6
  132. package/dist/packages/core-plugin-api/package.json.cjs.js +0 -6
  133. package/dist/packages/dev-utils/package.json.cjs.js +0 -6
  134. package/dist/packages/errors/package.json.cjs.js +0 -6
  135. package/dist/packages/frontend-defaults/package.json.cjs.js +0 -6
  136. package/dist/packages/frontend-plugin-api/package.json.cjs.js +0 -6
  137. package/dist/packages/frontend-plugin-api/src/routing/describeParentCallSite.cjs.js +0 -26
  138. package/dist/packages/frontend-test-utils/package.json.cjs.js +0 -6
  139. package/dist/packages/test-utils/package.json.cjs.js +0 -6
  140. package/dist/packages/theme/package.json.cjs.js +0 -6
  141. package/dist/packages/types/package.json.cjs.js +0 -6
  142. package/dist/plugins/auth-backend/package.json.cjs.js +0 -6
  143. package/dist/plugins/auth-backend-module-guest-provider/package.json.cjs.js +0 -6
  144. package/dist/plugins/catalog-node/package.json.cjs.js +0 -6
  145. package/dist/plugins/scaffolder-node/package.json.cjs.js +0 -6
  146. package/dist/plugins/scaffolder-node-test-utils/package.json.cjs.js +0 -6
  147. package/dist/wiring/CommandRegistry.cjs.js +0 -14
  148. package/dist/wiring/factory.cjs.js +0 -15
  149. package/dist/wiring/lazy.cjs.js +0 -22
  150. package/dist/wiring/types.cjs.js +0 -11
  151. package/templates/backend-plugin/.eslintrc.js.hbs +0 -1
  152. package/templates/backend-plugin/README.md.hbs +0 -28
  153. package/templates/backend-plugin/dev/index.ts.hbs +0 -60
  154. package/templates/backend-plugin/package.json.hbs +0 -44
  155. package/templates/backend-plugin/portable-template.yaml +0 -5
  156. package/templates/backend-plugin/src/index.ts.hbs +0 -1
  157. package/templates/backend-plugin/src/plugin.test.ts.hbs +0 -129
  158. package/templates/backend-plugin/src/plugin.ts.hbs +0 -32
  159. package/templates/backend-plugin/src/router.test.ts +0 -67
  160. package/templates/backend-plugin/src/router.ts +0 -51
  161. package/templates/backend-plugin/src/services/TodoListService.ts +0 -155
  162. package/templates/backend-plugin/src/setupTests.ts +0 -1
  163. package/templates/backend-plugin-module/.eslintrc.js.hbs +0 -1
  164. package/templates/backend-plugin-module/README.md.hbs +0 -5
  165. package/templates/backend-plugin-module/package.json.hbs +0 -34
  166. package/templates/backend-plugin-module/portable-template.yaml +0 -5
  167. package/templates/backend-plugin-module/src/index.ts.hbs +0 -8
  168. package/templates/backend-plugin-module/src/module.ts.hbs +0 -17
  169. package/templates/catalog-provider-module/.eslintrc.js.hbs +0 -1
  170. package/templates/catalog-provider-module/README.md.hbs +0 -5
  171. package/templates/catalog-provider-module/config.d.ts.hbs +0 -34
  172. package/templates/catalog-provider-module/package.json.hbs +0 -36
  173. package/templates/catalog-provider-module/portable-template.yaml +0 -9
  174. package/templates/catalog-provider-module/src/index.ts.hbs +0 -8
  175. package/templates/catalog-provider-module/src/module.ts.hbs +0 -29
  176. package/templates/catalog-provider-module/src/provider/readProviderConfigs.ts.hbs +0 -78
  177. package/templates/catalog-provider-module/src/provider/{{providerClass}}.test.ts.hbs +0 -18
  178. package/templates/catalog-provider-module/src/provider/{{providerClass}}.ts.hbs +0 -109
  179. package/templates/frontend-plugin/.eslintrc.js.hbs +0 -1
  180. package/templates/frontend-plugin/README.md.hbs +0 -13
  181. package/templates/frontend-plugin/dev/index.tsx.hbs +0 -11
  182. package/templates/frontend-plugin/package.json.hbs +0 -54
  183. package/templates/frontend-plugin/portable-template.yaml +0 -6
  184. package/templates/frontend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +0 -28
  185. package/templates/frontend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs +0 -37
  186. package/templates/frontend-plugin/src/components/ExampleComponent/index.ts +0 -1
  187. package/templates/frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +0 -19
  188. package/templates/frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +0 -308
  189. package/templates/frontend-plugin/src/components/ExampleFetchComponent/index.ts +0 -1
  190. package/templates/frontend-plugin/src/index.ts.hbs +0 -1
  191. package/templates/frontend-plugin/src/plugin.test.ts.hbs +0 -7
  192. package/templates/frontend-plugin/src/plugin.ts.hbs +0 -22
  193. package/templates/frontend-plugin/src/routes.ts.hbs +0 -5
  194. package/templates/frontend-plugin/src/setupTests.ts +0 -1
  195. package/templates/new-frontend-plugin/.eslintrc.js.hbs +0 -1
  196. package/templates/new-frontend-plugin/README.md.hbs +0 -20
  197. package/templates/new-frontend-plugin/dev/index.tsx +0 -10
  198. package/templates/new-frontend-plugin/package.json.hbs +0 -49
  199. package/templates/new-frontend-plugin/portable-template.yaml +0 -5
  200. package/templates/new-frontend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +0 -28
  201. package/templates/new-frontend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs +0 -37
  202. package/templates/new-frontend-plugin/src/components/ExampleComponent/index.ts +0 -1
  203. package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +0 -19
  204. package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +0 -308
  205. package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/index.ts +0 -1
  206. package/templates/new-frontend-plugin/src/index.ts.hbs +0 -1
  207. package/templates/new-frontend-plugin/src/plugin.test.ts.hbs +0 -7
  208. package/templates/new-frontend-plugin/src/plugin.tsx.hbs +0 -25
  209. package/templates/new-frontend-plugin/src/routes.ts +0 -3
  210. package/templates/new-frontend-plugin/src/setupTests.ts +0 -1
  211. package/templates/new-frontend-plugin-module/.eslintrc.js.hbs +0 -1
  212. package/templates/new-frontend-plugin-module/README.md.hbs +0 -5
  213. package/templates/new-frontend-plugin-module/package.json.hbs +0 -35
  214. package/templates/new-frontend-plugin-module/portable-template.yaml +0 -5
  215. package/templates/new-frontend-plugin-module/src/index.ts.hbs +0 -1
  216. package/templates/new-frontend-plugin-module/src/module.tsx.hbs +0 -8
  217. package/templates/new-frontend-plugin-module/src/setupTests.ts +0 -1
  218. package/templates/node-library/.eslintrc.js.hbs +0 -1
  219. package/templates/node-library/README.md.hbs +0 -12
  220. package/templates/node-library/package.json.hbs +0 -29
  221. package/templates/node-library/portable-template.yaml +0 -3
  222. package/templates/node-library/src/index.ts.hbs +0 -1
  223. package/templates/node-library/src/setupTests.ts +0 -1
  224. package/templates/plugin-common-library/.eslintrc.js.hbs +0 -1
  225. package/templates/plugin-common-library/README.md.hbs +0 -5
  226. package/templates/plugin-common-library/package.json.hbs +0 -31
  227. package/templates/plugin-common-library/portable-template.yaml +0 -3
  228. package/templates/plugin-common-library/src/index.ts.hbs +0 -19
  229. package/templates/plugin-common-library/src/setupTests.ts +0 -1
  230. package/templates/plugin-node-library/.eslintrc.js.hbs +0 -1
  231. package/templates/plugin-node-library/README.md.hbs +0 -5
  232. package/templates/plugin-node-library/package.json.hbs +0 -30
  233. package/templates/plugin-node-library/portable-template.yaml +0 -3
  234. package/templates/plugin-node-library/src/index.ts.hbs +0 -18
  235. package/templates/plugin-node-library/src/setupTests.ts +0 -1
  236. package/templates/plugin-web-library/.eslintrc.js.hbs +0 -1
  237. package/templates/plugin-web-library/README.md.hbs +0 -5
  238. package/templates/plugin-web-library/package.json.hbs +0 -42
  239. package/templates/plugin-web-library/portable-template.yaml +0 -3
  240. package/templates/plugin-web-library/src/components/ExampleComponent/ExampleComponent.test.tsx +0 -17
  241. package/templates/plugin-web-library/src/components/ExampleComponent/ExampleComponent.tsx +0 -28
  242. package/templates/plugin-web-library/src/components/ExampleComponent/index.ts +0 -2
  243. package/templates/plugin-web-library/src/components/index.ts +0 -5
  244. package/templates/plugin-web-library/src/hooks/index.ts +0 -5
  245. package/templates/plugin-web-library/src/hooks/useExample/index.ts +0 -1
  246. package/templates/plugin-web-library/src/hooks/useExample/useExample.ts +0 -15
  247. package/templates/plugin-web-library/src/index.ts.hbs +0 -12
  248. package/templates/plugin-web-library/src/setupTests.ts +0 -1
  249. package/templates/scaffolder-backend-module/.eslintrc.js.hbs +0 -1
  250. package/templates/scaffolder-backend-module/README.md.hbs +0 -5
  251. package/templates/scaffolder-backend-module/package.json.hbs +0 -36
  252. package/templates/scaffolder-backend-module/portable-template.yaml +0 -6
  253. package/templates/scaffolder-backend-module/src/actions/example.test.ts +0 -24
  254. package/templates/scaffolder-backend-module/src/actions/example.ts +0 -39
  255. package/templates/scaffolder-backend-module/src/index.ts.hbs +0 -8
  256. package/templates/scaffolder-backend-module/src/module.ts +0 -21
  257. package/templates/web-library/.eslintrc.js.hbs +0 -1
  258. package/templates/web-library/README.md.hbs +0 -12
  259. package/templates/web-library/package.json.hbs +0 -30
  260. package/templates/web-library/portable-template.yaml +0 -3
  261. package/templates/web-library/src/index.ts.hbs +0 -1
  262. package/templates/web-library/src/setupTests.ts +0 -1
  263. /package/dist/{packages/opaque-internal → opaque-internal}/src/OpaqueType.cjs.js +0 -0
@@ -1,32 +0,0 @@
1
- import {
2
- coreServices,
3
- createBackendPlugin,
4
- } from '@backstage/backend-plugin-api';
5
- import { createRouter } from './router';
6
- import { todoListServiceRef } from './services/TodoListService';
7
-
8
- /**
9
- * {{pluginVar}} backend plugin
10
- *
11
- * @public
12
- */
13
- export const {{pluginVar}} = createBackendPlugin({
14
- pluginId: '{{pluginId}}',
15
- register(env) {
16
- env.registerInit({
17
- deps: {
18
- httpAuth: coreServices.httpAuth,
19
- httpRouter: coreServices.httpRouter,
20
- todoList: todoListServiceRef,
21
- },
22
- async init({ httpAuth, httpRouter, todoList }) {
23
- httpRouter.use(
24
- await createRouter({
25
- httpAuth,
26
- todoList,
27
- }),
28
- );
29
- },
30
- });
31
- },
32
- });
@@ -1,67 +0,0 @@
1
- import {
2
- mockCredentials,
3
- mockErrorHandler,
4
- mockServices,
5
- } from '@backstage/backend-test-utils';
6
- import express from 'express';
7
- import request from 'supertest';
8
-
9
- import { createRouter } from './router';
10
- import { todoListServiceRef } from './services/TodoListService';
11
-
12
- const mockTodoItem = {
13
- title: 'Do the thing',
14
- id: '123',
15
- createdBy: mockCredentials.user().principal.userEntityRef,
16
- createdAt: new Date().toISOString(),
17
- };
18
-
19
- // TEMPLATE NOTE:
20
- // Testing the router directly allows you to write a unit test that mocks the provided options.
21
- describe('createRouter', () => {
22
- let app: express.Express;
23
- let todoList: jest.Mocked<typeof todoListServiceRef.T>;
24
-
25
- beforeEach(async () => {
26
- todoList = {
27
- createTodo: jest.fn(),
28
- listTodos: jest.fn(),
29
- getTodo: jest.fn(),
30
- };
31
- const router = await createRouter({
32
- httpAuth: mockServices.httpAuth(),
33
- todoList,
34
- });
35
- app = express();
36
- app.use(router);
37
- app.use(mockErrorHandler());
38
- });
39
-
40
- it('should create a TODO', async () => {
41
- todoList.createTodo.mockResolvedValue(mockTodoItem);
42
-
43
- const response = await request(app).post('/todos').send({
44
- title: 'Do the thing',
45
- });
46
-
47
- expect(response.status).toBe(201);
48
- expect(response.body).toEqual(mockTodoItem);
49
- });
50
-
51
- it('should not allow unauthenticated requests to create a TODO', async () => {
52
- todoList.createTodo.mockResolvedValue(mockTodoItem);
53
-
54
- // TEMPLATE NOTE:
55
- // The HttpAuth mock service considers all requests to be authenticated as a
56
- // mock user by default. In order to test other cases we need to explicitly
57
- // pass an authorization header with mock credentials.
58
- const response = await request(app)
59
- .post('/todos')
60
- .set('Authorization', mockCredentials.none.header())
61
- .send({
62
- title: 'Do the thing',
63
- });
64
-
65
- expect(response.status).toBe(401);
66
- });
67
- });
@@ -1,51 +0,0 @@
1
- import { HttpAuthService } from '@backstage/backend-plugin-api';
2
- import { InputError } from '@backstage/errors';
3
- import { z } from 'zod';
4
- import express from 'express';
5
- import Router from 'express-promise-router';
6
- import { todoListServiceRef } from './services/TodoListService';
7
-
8
- export async function createRouter({
9
- httpAuth,
10
- todoList,
11
- }: {
12
- httpAuth: HttpAuthService;
13
- todoList: typeof todoListServiceRef.T;
14
- }): Promise<express.Router> {
15
- const router = Router();
16
- router.use(express.json());
17
-
18
- // TEMPLATE NOTE:
19
- // Zod is a powerful library for data validation and recommended in particular
20
- // for user-defined schemas. In this case we use it for input validation too.
21
- //
22
- // If you want to define a schema for your API we recommend using Backstage's
23
- // OpenAPI tooling: https://backstage.io/docs/next/openapi/01-getting-started
24
- const todoSchema = z.object({
25
- title: z.string(),
26
- entityRef: z.string().optional(),
27
- });
28
-
29
- router.post('/todos', async (req, res) => {
30
- const parsed = todoSchema.safeParse(req.body);
31
- if (!parsed.success) {
32
- throw new InputError(parsed.error.toString());
33
- }
34
-
35
- const result = await todoList.createTodo(parsed.data, {
36
- credentials: await httpAuth.credentials(req, { allow: ['user'] }),
37
- });
38
-
39
- res.status(201).json(result);
40
- });
41
-
42
- router.get('/todos', async (_req, res) => {
43
- res.json(await todoList.listTodos());
44
- });
45
-
46
- router.get('/todos/:id', async (req, res) => {
47
- res.json(await todoList.getTodo({ id: req.params.id }));
48
- });
49
-
50
- return router;
51
- }
@@ -1,155 +0,0 @@
1
- /*
2
- * Copyright 2025 The Backstage Authors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import crypto from 'node:crypto';
17
- import {
18
- coreServices,
19
- createServiceFactory,
20
- createServiceRef,
21
- LoggerService,
22
- } from '@backstage/backend-plugin-api';
23
- import { NotFoundError } from '@backstage/errors';
24
- import { catalogServiceRef } from '@backstage/plugin-catalog-node';
25
- import {
26
- BackstageCredentials,
27
- BackstageUserPrincipal,
28
- } from '@backstage/backend-plugin-api';
29
- import { Expand } from '@backstage/types';
30
-
31
- export interface TodoItem {
32
- title: string;
33
- id: string;
34
- createdBy: string;
35
- createdAt: string;
36
- }
37
-
38
- // TEMPLATE NOTE:
39
- // This is a simple in-memory todo list store. It is recommended to use a
40
- // database to store data in a real application. See the database service
41
- // documentation for more information on how to do this:
42
- // https://backstage.io/docs/backend-system/core-services/database
43
- export class TodoListService {
44
- readonly #logger: LoggerService;
45
- readonly #catalog: typeof catalogServiceRef.T;
46
-
47
- readonly #storedTodos = new Array<TodoItem>();
48
-
49
- static create(options: {
50
- logger: LoggerService;
51
- catalog: typeof catalogServiceRef.T;
52
- }) {
53
- return new TodoListService(options.logger, options.catalog);
54
- }
55
-
56
- private constructor(
57
- logger: LoggerService,
58
- catalog: typeof catalogServiceRef.T,
59
- ) {
60
- this.#logger = logger;
61
- this.#catalog = catalog;
62
- }
63
-
64
- async createTodo(
65
- input: {
66
- title: string;
67
- entityRef?: string;
68
- },
69
- options: {
70
- credentials: BackstageCredentials<BackstageUserPrincipal>;
71
- },
72
- ): Promise<TodoItem> {
73
- let title = input.title;
74
-
75
- // TEMPLATE NOTE:
76
- // A common pattern for Backstage plugins is to pass an entity reference
77
- // from the frontend to then fetch the entire entity from the catalog in the
78
- // backend plugin.
79
- if (input.entityRef) {
80
- // TEMPLATE NOTE:
81
- // Cross-plugin communication uses service-to-service authentication. The
82
- // `AuthService` lets you generate a token that is valid for communication
83
- // with the target plugin only. You must also provide credentials for the
84
- // identity that you are making the request on behalf of.
85
- //
86
- // If you want to make a request using the plugin backend's own identity,
87
- // you can access it via the `auth.getOwnServiceCredentials()` method.
88
- // Beware that this bypasses any user permission checks.
89
- const entity = await this.#catalog.getEntityByRef(
90
- input.entityRef,
91
- options,
92
- );
93
- if (!entity) {
94
- throw new NotFoundError(`No entity found for ref '${input.entityRef}'`);
95
- }
96
-
97
- // TEMPLATE NOTE:
98
- // Here you could read any form of data from the entity. A common use case
99
- // is to read the value of a custom annotation for your plugin. You can
100
- // read more about how to add custom annotations here:
101
- // https://backstage.io/docs/features/software-catalog/extending-the-model#adding-a-new-annotation
102
- //
103
- // In this example we just use the entity title to decorate the todo item.
104
-
105
- const entityDisplay = entity.metadata.title ?? input.entityRef;
106
- title = `[${entityDisplay}] ${input.title}`;
107
- }
108
-
109
- const id = crypto.randomUUID();
110
- const createdBy = options.credentials.principal.userEntityRef;
111
- const newTodo = {
112
- title,
113
- id,
114
- createdBy,
115
- createdAt: new Date().toISOString(),
116
- };
117
-
118
- this.#storedTodos.push(newTodo);
119
-
120
- // TEMPLATE NOTE:
121
- // The second argument of the logger methods can be used to pass
122
- // structured metadata. You can read more about the logger service here:
123
- // https://backstage.io/docs/backend-system/core-services/logger
124
- this.#logger.info('Created new todo item', { id, title, createdBy });
125
-
126
- return newTodo;
127
- }
128
-
129
- async listTodos(): Promise<{ items: TodoItem[] }> {
130
- return { items: Array.from(this.#storedTodos) };
131
- }
132
-
133
- async getTodo(request: { id: string }): Promise<TodoItem> {
134
- const todo = this.#storedTodos.find(item => item.id === request.id);
135
- if (!todo) {
136
- throw new NotFoundError(`No todo found with id '${request.id}'`);
137
- }
138
- return todo;
139
- }
140
- }
141
-
142
- export const todoListServiceRef = createServiceRef<Expand<TodoListService>>({
143
- id: 'todo.list',
144
- defaultFactory: async service =>
145
- createServiceFactory({
146
- service,
147
- deps: {
148
- logger: coreServices.logger,
149
- catalog: catalogServiceRef,
150
- },
151
- async factory(deps) {
152
- return TodoListService.create(deps);
153
- },
154
- }),
155
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
@@ -1,5 +0,0 @@
1
- # {{packageName}}
2
-
3
- The {{moduleId}} backend module for the {{pluginId}} plugin.
4
-
5
- _This plugin was created through the Backstage CLI_
@@ -1,34 +0,0 @@
1
- {
2
- "name": "{{packageName}}",
3
- "description": "The {{moduleId}} backend module for the {{pluginId}} plugin.",
4
- "main": "src/index.ts",
5
- "types": "src/index.ts",
6
- "publishConfig": {
7
- "access": "public",
8
- "main": "dist/index.cjs.js",
9
- "types": "dist/index.d.ts"
10
- },
11
- "backstage": {
12
- "role": "backend-plugin-module",
13
- "pluginId": "{{pluginId}}"
14
- },
15
- "scripts": {
16
- "start": "backstage-cli package start",
17
- "build": "backstage-cli package build",
18
- "lint": "backstage-cli package lint",
19
- "test": "backstage-cli package test",
20
- "clean": "backstage-cli package clean",
21
- "prepack": "backstage-cli package prepack",
22
- "postpack": "backstage-cli package postpack"
23
- },
24
- "dependencies": {
25
- "@backstage/backend-plugin-api": "{{versionQuery '@backstage/backend-plugin-api'}}"
26
- },
27
- "devDependencies": {
28
- "@backstage/backend-test-utils": "{{versionQuery '@backstage/backend-test-utils'}}",
29
- "@backstage/cli": "{{versionQuery '@backstage/cli'}}"
30
- },
31
- "files": [
32
- "dist"
33
- ]
34
- }
@@ -1,5 +0,0 @@
1
- name: backend-plugin-module
2
- role: backend-plugin-module
3
- description: A new backend module that extends an existing backend plugin
4
- values:
5
- moduleVar: '{{ camelCase pluginId }}Module{{ upperFirst ( camelCase moduleId ) }}'
@@ -1,8 +0,0 @@
1
- /***/
2
- /**
3
- * The {{moduleId}} backend module for the {{pluginId}} plugin.
4
- *
5
- * @packageDocumentation
6
- */
7
-
8
- export { {{moduleVar}} as default } from './module';
@@ -1,17 +0,0 @@
1
- import {
2
- coreServices,
3
- createBackendModule,
4
- } from '@backstage/backend-plugin-api';
5
-
6
- export const {{moduleVar}} = createBackendModule({
7
- pluginId: '{{pluginId}}',
8
- moduleId: '{{moduleId}}',
9
- register(reg) {
10
- reg.registerInit({
11
- deps: { logger: coreServices.logger },
12
- async init({ logger }) {
13
- logger.info('Hello World!');
14
- },
15
- });
16
- },
17
- });
@@ -1 +0,0 @@
1
- module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
@@ -1,5 +0,0 @@
1
- # {{packageName}}
2
-
3
- The {{fullModuleId}} module for [@backstage/plugin-catalog-backend](https://www.npmjs.com/package/@backstage/plugin-catalog-backend).
4
-
5
- _This plugin was created through the Backstage CLI_
@@ -1,34 +0,0 @@
1
- import { SchedulerServiceTaskScheduleDefinitionConfig } from '@backstage/backend-plugin-api';
2
-
3
- export interface Config {
4
- catalog?: {
5
- providers?: {
6
- /**
7
- * {{providerClass}} configuration.
8
- */
9
- {{providerVar}}?:
10
- | {
11
- /**
12
- * The target that this provider should consume.
13
- */
14
- target: string;
15
- /**
16
- * Overrides the schedule at which this provider runs.
17
- */
18
- schedule?: SchedulerServiceTaskScheduleDefinitionConfig;
19
- }
20
- | {
21
- [name: string]: {
22
- /**
23
- * The target that this provider should consume.
24
- */
25
- target: string;
26
- /**
27
- * Overrides the schedule at which this provider runs.
28
- */
29
- schedule?: SchedulerServiceTaskScheduleDefinitionConfig;
30
- };
31
- };
32
- };
33
- };
34
- }
@@ -1,36 +0,0 @@
1
- {
2
- "name": "{{packageName}}",
3
- "description": "The {{fullModuleId}} module for @backstage/plugin-catalog-backend",
4
- "main": "src/index.ts",
5
- "types": "src/index.ts",
6
- "publishConfig": {
7
- "access": "public",
8
- "main": "dist/index.cjs.js",
9
- "types": "dist/index.d.ts"
10
- },
11
- "backstage": {
12
- "role": "backend-plugin-module",
13
- "pluginId": "catalog",
14
- "pluginPackage": "@backstage/plugin-catalog-backend"
15
- },
16
- "scripts": {
17
- "start": "backstage-cli package start",
18
- "build": "backstage-cli package build",
19
- "lint": "backstage-cli package lint",
20
- "test": "backstage-cli package test",
21
- "clean": "backstage-cli package clean",
22
- "prepack": "backstage-cli package prepack",
23
- "postpack": "backstage-cli package postpack"
24
- },
25
- "dependencies": {
26
- "@backstage/backend-plugin-api": "{{versionQuery '@backstage/backend-plugin-api'}}",
27
- "@backstage/plugin-catalog-node": "{{versionQuery '@backstage/plugin-catalog-node'}}"
28
- },
29
- "devDependencies": {
30
- "@backstage/cli": "{{versionQuery '@backstage/cli'}}",
31
- "@backstage/backend-test-utils": "{{versionQuery '@backstage/backend-test-utils'}}"
32
- },
33
- "files": [
34
- "dist"
35
- ]
36
- }
@@ -1,9 +0,0 @@
1
- name: catalog-provider-module
2
- role: backend-plugin-module
3
- description: An Entity Provider module for the Software Catalog
4
- values:
5
- pluginId: catalog
6
- fullModuleId: '{{ moduleId }}-provider'
7
- moduleVar: '{{ camelCase pluginId }}Module{{ upperFirst ( camelCase moduleId ) }}'
8
- providerVar: '{{ camelCase moduleId }}Provider'
9
- providerClass: '{{ upperFirst ( camelCase moduleId ) }}Provider'
@@ -1,8 +0,0 @@
1
- /***/
2
- /**
3
- * The {{fullModuleId}} module for @backstage/plugin-catalog-backend
4
- *
5
- * @packageDocumentation
6
- */
7
-
8
- export { {{moduleVar}} as default } from './module';
@@ -1,29 +0,0 @@
1
- import {
2
- coreServices,
3
- createBackendModule,
4
- } from '@backstage/backend-plugin-api';
5
- import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node';
6
- import { {{providerClass}} } from './provider/{{providerClass}}';
7
-
8
- export const {{moduleVar}} = createBackendModule({
9
- moduleId: '{{fullModuleId}}',
10
- pluginId: '{{pluginId}}',
11
- register({ registerInit }) {
12
- registerInit({
13
- deps: {
14
- logger: coreServices.logger,
15
- config: coreServices.rootConfig,
16
- scheduler: coreServices.scheduler,
17
- processing: catalogProcessingExtensionPoint,
18
- },
19
- async init({ logger, scheduler, config, processing }) {
20
- processing.addEntityProvider(
21
- {{providerClass}}.fromConfig(config, {
22
- logger,
23
- scheduler,
24
- }),
25
- );
26
- }
27
- });
28
- },
29
- })
@@ -1,78 +0,0 @@
1
- import {
2
- readSchedulerServiceTaskScheduleDefinitionFromConfig,
3
- SchedulerServiceTaskScheduleDefinition,
4
- } from '@backstage/backend-plugin-api';
5
- import { Config } from '@backstage/config';
6
-
7
- const DEFAULT_PROVIDER_ID = 'default';
8
- const DEFAULT_SCHEDULE: SchedulerServiceTaskScheduleDefinition = {
9
- frequency: {
10
- minutes: 30,
11
- },
12
- timeout: {
13
- minutes: 3,
14
- },
15
- }
16
-
17
- export type {{providerClass}}ProviderConfig = {
18
- id: string;
19
- target: string;
20
- schedule: SchedulerServiceTaskScheduleDefinition;
21
- }
22
-
23
- /**
24
- * Parses all configured providers.
25
- *
26
- * @param config - The root of the provider config hierarchy
27
- *
28
- * @public
29
- */
30
- export function readProviderConfigs(
31
- config: Config,
32
- ): {{providerClass}}ProviderConfig[] {
33
- const providersConfig = config.getOptionalConfig(
34
- 'catalog.providers.{{providerVar}}',
35
- );
36
- if (!providersConfig) {
37
- return [];
38
- }
39
-
40
- if ((providersConfig).has('target')) {
41
- // simple/single config variant
42
- return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];
43
- }
44
-
45
- return providersConfig.keys().map(id => {
46
- const providerConfig = providersConfig.getConfig(id);
47
-
48
- return readProviderConfig(id, providerConfig);
49
- });
50
- }
51
-
52
- /**
53
- * Parses a single configured provider by id.
54
- *
55
- * @param id - the id of the provider to parse
56
- * @param config - The root of the provider config hierarchy
57
- *
58
- * @public
59
- */
60
- export function readProviderConfig(
61
- id: string,
62
- config: Config,
63
- ): {{providerClass}}ProviderConfig {
64
-
65
- const target = config.getString('target');
66
-
67
- const schedule = config.has('schedule')
68
- ? readSchedulerServiceTaskScheduleDefinitionFromConfig(
69
- config.getConfig('schedule'),
70
- )
71
- : DEFAULT_SCHEDULE;
72
-
73
- return {
74
- id,
75
- target,
76
- schedule,
77
- };
78
- }
@@ -1,18 +0,0 @@
1
- import { {{providerClass}} } from './{{providerClass}}';
2
- import { mockServices } from '@backstage/backend-test-utils';
3
-
4
- describe('{{providerClass}}', () => {
5
- it('should read entities from the target', async () => {
6
- const logger = mockServices.logger.mock();
7
- const provider = new {{providerClass}}({
8
- id: 'test',
9
- target: 'https://example.com',
10
- logger: mockServices.logger.mock(),
11
- taskRunner: { run: jest.fn() },
12
- });
13
-
14
- const entities = await provider.read({ logger });
15
-
16
- expect(entities).toEqual([]);
17
- });
18
- })