@red-hat-developer-hub/backstage-plugin-bulk-import-backend 5.0.1

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 (56) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +161 -0
  3. package/app-config.yaml +0 -0
  4. package/config.d.ts +17 -0
  5. package/dist/catalog/catalogHttpClient.cjs.js +284 -0
  6. package/dist/catalog/catalogHttpClient.cjs.js.map +1 -0
  7. package/dist/catalog/catalogInfoGenerator.cjs.js +60 -0
  8. package/dist/catalog/catalogInfoGenerator.cjs.js.map +1 -0
  9. package/dist/catalog/catalogUtils.cjs.js +34 -0
  10. package/dist/catalog/catalogUtils.cjs.js.map +1 -0
  11. package/dist/generated/openapidocument.cjs.js +1168 -0
  12. package/dist/generated/openapidocument.cjs.js.map +1 -0
  13. package/dist/github/GithubAppManager.cjs.js +395 -0
  14. package/dist/github/GithubAppManager.cjs.js.map +1 -0
  15. package/dist/github/githubApiService.cjs.js +659 -0
  16. package/dist/github/githubApiService.cjs.js.map +1 -0
  17. package/dist/github/types.cjs.js +8 -0
  18. package/dist/github/types.cjs.js.map +1 -0
  19. package/dist/github/utils/ghUtils.cjs.js +103 -0
  20. package/dist/github/utils/ghUtils.cjs.js.map +1 -0
  21. package/dist/github/utils/orgUtils.cjs.js +151 -0
  22. package/dist/github/utils/orgUtils.cjs.js.map +1 -0
  23. package/dist/github/utils/prUtils.cjs.js +85 -0
  24. package/dist/github/utils/prUtils.cjs.js.map +1 -0
  25. package/dist/github/utils/repoUtils.cjs.js +307 -0
  26. package/dist/github/utils/repoUtils.cjs.js.map +1 -0
  27. package/dist/github/utils/utils.cjs.js +206 -0
  28. package/dist/github/utils/utils.cjs.js.map +1 -0
  29. package/dist/helpers/auditLogUtils.cjs.js +112 -0
  30. package/dist/helpers/auditLogUtils.cjs.js.map +1 -0
  31. package/dist/helpers/auth.cjs.js +36 -0
  32. package/dist/helpers/auth.cjs.js.map +1 -0
  33. package/dist/helpers/loggingUtils.cjs.js +19 -0
  34. package/dist/helpers/loggingUtils.cjs.js.map +1 -0
  35. package/dist/helpers/pagination.cjs.js +19 -0
  36. package/dist/helpers/pagination.cjs.js.map +1 -0
  37. package/dist/index.cjs.js +12 -0
  38. package/dist/index.cjs.js.map +1 -0
  39. package/dist/index.d.ts +25 -0
  40. package/dist/plugin.cjs.js +54 -0
  41. package/dist/plugin.cjs.js.map +1 -0
  42. package/dist/service/handlers/handlers.cjs.js +8 -0
  43. package/dist/service/handlers/handlers.cjs.js.map +1 -0
  44. package/dist/service/handlers/import/bulkImports.cjs.js +551 -0
  45. package/dist/service/handlers/import/bulkImports.cjs.js.map +1 -0
  46. package/dist/service/handlers/import/importStatus.cjs.js +49 -0
  47. package/dist/service/handlers/import/importStatus.cjs.js.map +1 -0
  48. package/dist/service/handlers/organization/organizations.cjs.js +77 -0
  49. package/dist/service/handlers/organization/organizations.cjs.js.map +1 -0
  50. package/dist/service/handlers/ping/ping.cjs.js +12 -0
  51. package/dist/service/handlers/ping/ping.cjs.js.map +1 -0
  52. package/dist/service/handlers/repository/repositories.cjs.js +99 -0
  53. package/dist/service/handlers/repository/repositories.cjs.js.map +1 -0
  54. package/dist/service/router.cjs.js +324 -0
  55. package/dist/service/router.cjs.js.map +1 -0
  56. package/package.json +110 -0
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@backstage/errors');
4
+
5
+ const EVENT_PREFIX = "BulkImport";
6
+ const UNKNOWN_ENDPOINT_EVENT = `${EVENT_PREFIX}UnknownEndpoint`;
7
+ async function auditLogRequestSuccess(auditLogger, openApiOperationId, req, responseStatus) {
8
+ if (!openApiOperationId) {
9
+ auditLogUnknownEndpoint(auditLogger, req);
10
+ return;
11
+ }
12
+ auditLogger.auditLog({
13
+ eventName: operationIdToEventName(openApiOperationId),
14
+ stage: "completion",
15
+ status: "succeeded",
16
+ level: "info",
17
+ request: req,
18
+ response: {
19
+ status: responseStatus
20
+ },
21
+ message: `'${req.method} ${req.path}' endpoint hit by ${await auditLogger.getActorId(req)}`
22
+ });
23
+ }
24
+ async function auditLogRequestError(auditLogger, openApiOperationId, req, error) {
25
+ if (!openApiOperationId) {
26
+ auditLogUnknownEndpoint(auditLogger, req);
27
+ return;
28
+ }
29
+ auditLogger.auditLog({
30
+ eventName: operationIdToEventName(openApiOperationId),
31
+ stage: "completion",
32
+ status: "failed",
33
+ level: "error",
34
+ request: req,
35
+ response: {
36
+ status: 500,
37
+ body: {
38
+ errors: [
39
+ {
40
+ name: error.name,
41
+ message: error.message || "internal server error"
42
+ }
43
+ ]
44
+ }
45
+ },
46
+ errors: [error],
47
+ message: `Error while requesting the '${req.method} ${req.path}' endpoint (request from ${await auditLogger.getActorId(req)})`
48
+ });
49
+ }
50
+ async function auditLogUnknownEndpoint(auditLogger, req) {
51
+ const error = new errors.NotFoundError(`'${req.method} ${req.path}' not found`);
52
+ auditLogger.auditLog({
53
+ eventName: UNKNOWN_ENDPOINT_EVENT,
54
+ stage: "initiation",
55
+ status: "failed",
56
+ level: "info",
57
+ request: req,
58
+ response: {
59
+ status: 404,
60
+ body: {
61
+ errors: [
62
+ {
63
+ name: error.name,
64
+ message: error.message
65
+ }
66
+ ]
67
+ }
68
+ },
69
+ errors: [error],
70
+ message: `${await auditLogger.getActorId(req)} requested the unknown '${req.method} ${req.path}' endpoint`
71
+ });
72
+ }
73
+ async function auditLogAuthError(auditLogger, openApiOperationId, req, error) {
74
+ if (!openApiOperationId) {
75
+ auditLogUnknownEndpoint(auditLogger, req);
76
+ return;
77
+ }
78
+ auditLogger.auditLog({
79
+ eventName: operationIdToEventName(openApiOperationId),
80
+ stage: "authorization",
81
+ status: "failed",
82
+ level: "warn",
83
+ request: req,
84
+ response: {
85
+ status: 403,
86
+ body: {
87
+ errors: [
88
+ {
89
+ name: error.name,
90
+ message: error.message
91
+ }
92
+ ]
93
+ }
94
+ },
95
+ errors: [error],
96
+ message: `${await auditLogger.getActorId(
97
+ req
98
+ )} not authorized to request the '${req.method} ${req.path}' endpoint`
99
+ });
100
+ }
101
+ function operationIdToEventName(openApiOperationId) {
102
+ if (openApiOperationId.length === 0) {
103
+ return EVENT_PREFIX;
104
+ }
105
+ return `${EVENT_PREFIX}${openApiOperationId.charAt(0).toUpperCase()}${openApiOperationId.slice(1)}`;
106
+ }
107
+
108
+ exports.auditLogAuthError = auditLogAuthError;
109
+ exports.auditLogRequestError = auditLogRequestError;
110
+ exports.auditLogRequestSuccess = auditLogRequestSuccess;
111
+ exports.auditLogUnknownEndpoint = auditLogUnknownEndpoint;
112
+ //# sourceMappingURL=auditLogUtils.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auditLogUtils.cjs.js","sources":["../../src/helpers/auditLogUtils.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 */\n\nimport { NotFoundError, type NotAllowedError } from '@backstage/errors';\n\nimport type { AuditLogger } from '@janus-idp/backstage-plugin-audit-log-node';\nimport express from 'express';\n\nconst EVENT_PREFIX = 'BulkImport';\nconst UNKNOWN_ENDPOINT_EVENT = `${EVENT_PREFIX}UnknownEndpoint`;\n\nexport async function auditLogRequestSuccess(\n auditLogger: AuditLogger,\n openApiOperationId: string | undefined,\n req: express.Request,\n responseStatus: number,\n) {\n if (!openApiOperationId) {\n auditLogUnknownEndpoint(auditLogger, req);\n return;\n }\n auditLogger.auditLog({\n eventName: operationIdToEventName(openApiOperationId),\n stage: 'completion',\n status: 'succeeded',\n level: 'info',\n request: req,\n response: {\n status: responseStatus,\n },\n message: `'${req.method} ${\n req.path\n }' endpoint hit by ${await auditLogger.getActorId(req)}`,\n });\n}\n\nexport async function auditLogRequestError(\n auditLogger: AuditLogger,\n openApiOperationId: string | undefined,\n req: express.Request,\n error: any,\n) {\n if (!openApiOperationId) {\n auditLogUnknownEndpoint(auditLogger, req);\n return;\n }\n auditLogger.auditLog({\n eventName: operationIdToEventName(openApiOperationId),\n stage: 'completion',\n status: 'failed',\n level: 'error',\n request: req,\n response: {\n status: 500,\n body: {\n errors: [\n {\n name: error.name,\n message: error.message || 'internal server error',\n },\n ],\n },\n },\n errors: [error],\n message: `Error while requesting the '${req.method} ${\n req.path\n }' endpoint (request from ${await auditLogger.getActorId(req)})`,\n });\n}\n\nexport async function auditLogUnknownEndpoint(\n auditLogger: AuditLogger,\n req: express.Request,\n) {\n const error = new NotFoundError(`'${req.method} ${req.path}' not found`);\n auditLogger.auditLog({\n eventName: UNKNOWN_ENDPOINT_EVENT,\n stage: 'initiation',\n status: 'failed',\n level: 'info',\n request: req,\n response: {\n status: 404,\n body: {\n errors: [\n {\n name: error.name,\n message: error.message,\n },\n ],\n },\n },\n errors: [error],\n message: `${await auditLogger.getActorId(req)} requested the unknown '${\n req.method\n } ${req.path}' endpoint`,\n });\n}\n\nexport async function auditLogAuthError(\n auditLogger: AuditLogger,\n openApiOperationId: string | undefined,\n req: express.Request,\n error: NotAllowedError,\n) {\n if (!openApiOperationId) {\n auditLogUnknownEndpoint(auditLogger, req);\n return;\n }\n auditLogger.auditLog({\n eventName: operationIdToEventName(openApiOperationId),\n stage: 'authorization',\n status: 'failed',\n level: 'warn',\n request: req,\n response: {\n status: 403,\n body: {\n errors: [\n {\n name: error.name,\n message: error.message,\n },\n ],\n },\n },\n errors: [error],\n message: `${await auditLogger.getActorId(\n req,\n )} not authorized to request the '${req.method} ${req.path}' endpoint`,\n });\n}\n\nfunction operationIdToEventName(openApiOperationId: string): string {\n if (openApiOperationId.length === 0) {\n return EVENT_PREFIX;\n }\n return `${EVENT_PREFIX}${openApiOperationId\n .charAt(0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AC,CAAA,CAAA,CAAA;AAChD;;;;;;;"}
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@backstage/errors');
4
+ var pluginPermissionCommon = require('@backstage/plugin-permission-common');
5
+ var backstagePluginBulkImportCommon = require('@red-hat-developer-hub/backstage-plugin-bulk-import-common');
6
+ var auditLogUtils = require('./auditLogUtils.cjs.js');
7
+
8
+ async function permissionCheck(auditLogger, openApiOperationId, permissions, httpAuth, req) {
9
+ const decision = (await permissions.authorize(
10
+ [
11
+ {
12
+ permission: backstagePluginBulkImportCommon.bulkImportPermission,
13
+ resourceRef: backstagePluginBulkImportCommon.bulkImportPermission.resourceType
14
+ }
15
+ ],
16
+ {
17
+ credentials: await httpAuth.credentials(req)
18
+ }
19
+ ))[0];
20
+ if (decision.result === pluginPermissionCommon.AuthorizeResult.DENY) {
21
+ const err = new errors.NotAllowedError("Unauthorized");
22
+ auditLogUtils.auditLogAuthError(auditLogger, openApiOperationId, req, err);
23
+ throw err;
24
+ }
25
+ }
26
+ async function getTokenForPlugin(auth, targetPluginId) {
27
+ const resp = await auth.getPluginRequestToken({
28
+ onBehalfOf: await auth.getOwnServiceCredentials(),
29
+ targetPluginId
30
+ });
31
+ return resp.token;
32
+ }
33
+
34
+ exports.getTokenForPlugin = getTokenForPlugin;
35
+ exports.permissionCheck = permissionCheck;
36
+ //# sourceMappingURL=auth.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.cjs.js","sources":["../../src/helpers/auth.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 */\n\nimport type {\n AuthService,\n HttpAuthService,\n PermissionsService,\n} from '@backstage/backend-plugin-api';\nimport { NotAllowedError } from '@backstage/errors';\nimport { AuthorizeResult } from '@backstage/plugin-permission-common';\n\nimport type { AuditLogger } from '@janus-idp/backstage-plugin-audit-log-node';\nimport express from 'express';\n\nimport { bulkImportPermission } from '@red-hat-developer-hub/backstage-plugin-bulk-import-common';\n\nimport { auditLogAuthError } from './auditLogUtils';\n\n/**\n * This will resolve to { result: AuthorizeResult.ALLOW } if the permission framework is disabled\n */\nexport async function permissionCheck(\n auditLogger: AuditLogger,\n openApiOperationId: string | undefined,\n permissions: PermissionsService,\n httpAuth: HttpAuthService,\n req: express.Request,\n) {\n const decision = (\n await permissions.authorize(\n [\n {\n permission: bulkImportPermission,\n resourceRef: bulkImportPermission.resourceType,\n },\n ],\n {\n credentials: await httpAuth.credentials(req),\n },\n )\n )[0];\n\n if (decision.result === AuthorizeResult.DENY) {\n const err = new NotAllowedError('Unauthorized');\n auditLogAuthError(auditLogger, openApiOperationId, req, err);\n throw err;\n }\n}\n\nexport async function getTokenForPlugin(\n auth: AuthService,\n targetPluginId: string,\n): Promise<string> {\n const resp = await auth.getPluginRequestToken({\n onBehalfOf: await auth.getOwnServiceCredentials(),\n targetPluginId,\n });\n return resp.token;\n}\n"],"names":["bulkImportPermission","AuthorizeResult","NotAllowedError","auditLogAuthError"],"mappings":";;;;;;;AAkCA,eAAsB,eACpB,CAAA,WAAA,EACA,kBACA,EAAA,WAAA,EACA,UACA,GACA,EAAA;AACA,EAAM,MAAA,QAAA,GAAA,CACJ,MAAM,WAAY,CAAA,SAAA;AAAA,IAChB;AAAA,MACE;AAAA,QACE,UAAY,EAAAA,oDAAA;AAAA,QACZ,aAAaA,oDAAqB,CAAA,YAAA;AAAA,OACpC;AAAA,KACF;AAAA,IACA;AAAA,MACE,WAAa,EAAA,MAAM,QAAS,CAAA,WAAA,CAAY,GAAG,CAAA;AAAA,KAC7C;AAAA,KAEF,CAAC,CAAA,CAAA;AAEH,EAAI,IAAA,QAAA,CAAS,MAAW,KAAAC,sCAAA,CAAgB,IAAM,EAAA;AAC5C,IAAM,MAAA,GAAA,GAAM,IAAIC,sBAAA,CAAgB,cAAc,CAAA,CAAA;AAC9C,IAAkBC,+BAAA,CAAA,WAAA,EAAa,kBAAoB,EAAA,GAAA,EAAK,GAAG,CAAA,CAAA;AAC3D,IAAM,MAAA,GAAA,CAAA;AAAA,GACR;AACF,CAAA;AAEsB,eAAA,iBAAA,CACpB,MACA,cACiB,EAAA;AACjB,EAAM,MAAA,IAAA,GAAO,MAAM,IAAA,CAAK,qBAAsB,CAAA;AAAA,IAC5C,UAAA,EAAY,MAAM,IAAA,CAAK,wBAAyB,EAAA;AAAA,IAChD,cAAA;AAAA,GACD,CAAA,CAAA;AACD,EAAA,OAAO,IAAK,CAAA,KAAA,CAAA;AACd;;;;;"}
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@backstage/errors');
4
+
5
+ function logErrorIfNeeded(logger, logMsg, error) {
6
+ if (errors.isError(error)) {
7
+ logger.error(logMsg, {
8
+ // Default Error properties:
9
+ name: error.name,
10
+ message: error.message,
11
+ stack: error.stack,
12
+ // Additional status code if available:
13
+ status: error.response?.status
14
+ });
15
+ }
16
+ }
17
+
18
+ exports.logErrorIfNeeded = logErrorIfNeeded;
19
+ //# sourceMappingURL=loggingUtils.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loggingUtils.cjs.js","sources":["../../src/helpers/loggingUtils.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 */\n\nimport type { LoggerService } from '@backstage/backend-plugin-api';\nimport { isError } from '@backstage/errors';\n\n/**\n * Logs the error specified by ensuring no sensitive internal data is disclosed.\n * @param logger the logger\n * @param logMsg the log message\n * @param error the error\n */\nexport function logErrorIfNeeded(\n logger: LoggerService,\n logMsg: string,\n error: any,\n) {\n if (isError(error)) {\n // Ensure that we don't log any sensitive internal data:\n logger.error(logMsg, {\n // Default Error properties:\n name: error.name,\n message: error.message,\n stack: error.stack,\n // Additional status code if available:\n status: (error.response as { status?: string })?.status,\n });\n }\n}\n"],"names":["isError"],"mappings":";;;;AAyBgB,SAAA,gBAAA,CACd,MACA,EAAA,MAAA,EACA,KACA,EAAA;AACA,EAAI,IAAAA,cAAA,CAAQ,KAAK,CAAG,EAAA;AAElB,IAAA,MAAA,CAAO,MAAM,MAAQ,EAAA;AAAA;AAAA,MAEnB,MAAM,KAAM,CAAA,IAAA;AAAA,MACZ,SAAS,KAAM,CAAA,OAAA;AAAA,MACf,OAAO,KAAM,CAAA,KAAA;AAAA;AAAA,MAEb,MAAA,EAAS,MAAM,QAAkC,EAAA,MAAA;AAAA,KAClD,CAAA,CAAA;AAAA,GACH;AACF;;;;"}
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ function paginateArray(array, page, size) {
4
+ if (page <= 0) {
5
+ throw new Error(`page must be >0. Got page=${page}`);
6
+ }
7
+ if (size < 0) {
8
+ throw new Error(`size must be >=0. Got size=${size}`);
9
+ }
10
+ const startIndex = (page - 1) * size;
11
+ const endIndex = startIndex + size;
12
+ return {
13
+ result: array?.slice(startIndex, endIndex) ?? [],
14
+ totalCount: array?.length ?? 0
15
+ };
16
+ }
17
+
18
+ exports.paginateArray = paginateArray;
19
+ //# sourceMappingURL=pagination.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.cjs.js","sources":["../../src/helpers/pagination.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 */\n\n/**\n * Returns a paginated chunk of the specified array\n * @param array the array to paginate\n * @param page the page number\n * @param size the maximum number of elements in each page\n */\nexport function paginateArray<T>(\n array: T[] | undefined,\n page: number,\n size: number,\n): { result: T[]; totalCount: number } {\n if (page <= 0) {\n throw new Error(`page must be >0. Got page=${page}`);\n }\n if (size < 0) {\n throw new Error(`size must be >=0. Got size=${size}`);\n }\n\n const startIndex = (page - 1) * size;\n const endIndex = startIndex + size;\n\n return {\n result: array?.slice(startIndex, endIndex) ?? [],\n totalCount: array?.length ?? 0,\n };\n}\n"],"names":[],"mappings":";;AAsBgB,SAAA,aAAA,CACd,KACA,EAAA,IAAA,EACA,IACqC,EAAA;AACrC,EAAA,IAAI,QAAQ,CAAG,EAAA;AACb,IAAA,MAAM,IAAI,KAAA,CAAM,CAA6B,0BAAA,EAAA,IAAI,CAAE,CAAA,CAAA,CAAA;AAAA,GACrD;AACA,EAAA,IAAI,OAAO,CAAG,EAAA;AACZ,IAAA,MAAM,IAAI,KAAA,CAAM,CAA8B,2BAAA,EAAA,IAAI,CAAE,CAAA,CAAA,CAAA;AAAA,GACtD;AAEA,EAAM,MAAA,UAAA,GAAA,CAAc,OAAO,CAAK,IAAA,IAAA,CAAA;AAChC,EAAA,MAAM,WAAW,UAAa,GAAA,IAAA,CAAA;AAE9B,EAAO,OAAA;AAAA,IACL,QAAQ,KAAO,EAAA,KAAA,CAAM,UAAY,EAAA,QAAQ,KAAK,EAAC;AAAA,IAC/C,UAAA,EAAY,OAAO,MAAU,IAAA,CAAA;AAAA,GAC/B,CAAA;AACF;;;;"}
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var plugin = require('./plugin.cjs.js');
6
+ var router = require('./service/router.cjs.js');
7
+
8
+
9
+
10
+ exports.default = plugin.bulkImportPlugin;
11
+ exports.createRouter = router.createRouter;
12
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -0,0 +1,25 @@
1
+ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
+ import { LoggerService, CacheService, DiscoveryService, HttpAuthService, AuthService } from '@backstage/backend-plugin-api';
3
+ import { CatalogApi } from '@backstage/catalog-client';
4
+ import { Config } from '@backstage/config';
5
+ import { PermissionEvaluator } from '@backstage/plugin-permission-common';
6
+ import express from 'express';
7
+
8
+ /**
9
+ * The bulk-import backend plugin.
10
+ */
11
+ declare const bulkImportPlugin: _backstage_backend_plugin_api.BackendFeature;
12
+
13
+ interface RouterOptions {
14
+ logger: LoggerService;
15
+ permissions: PermissionEvaluator;
16
+ config: Config;
17
+ cache: CacheService;
18
+ discovery: DiscoveryService;
19
+ httpAuth: HttpAuthService;
20
+ auth: AuthService;
21
+ catalogApi: CatalogApi;
22
+ }
23
+ declare function createRouter(options: RouterOptions): Promise<express.Router>;
24
+
25
+ export { type RouterOptions, createRouter, bulkImportPlugin as default };
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ var backendPluginApi = require('@backstage/backend-plugin-api');
4
+ var alpha = require('@backstage/plugin-catalog-node/alpha');
5
+ var router = require('./service/router.cjs.js');
6
+
7
+ const bulkImportPlugin = backendPluginApi.createBackendPlugin({
8
+ pluginId: "bulk-import",
9
+ register(env) {
10
+ env.registerInit({
11
+ deps: {
12
+ logger: backendPluginApi.coreServices.logger,
13
+ config: backendPluginApi.coreServices.rootConfig,
14
+ http: backendPluginApi.coreServices.httpRouter,
15
+ cache: backendPluginApi.coreServices.cache,
16
+ discovery: backendPluginApi.coreServices.discovery,
17
+ permissions: backendPluginApi.coreServices.permissions,
18
+ httpAuth: backendPluginApi.coreServices.httpAuth,
19
+ auth: backendPluginApi.coreServices.auth,
20
+ catalogApi: alpha.catalogServiceRef
21
+ },
22
+ async init({
23
+ config,
24
+ logger,
25
+ http,
26
+ cache,
27
+ discovery,
28
+ permissions,
29
+ httpAuth,
30
+ auth,
31
+ catalogApi
32
+ }) {
33
+ const router$1 = await router.createRouter({
34
+ config,
35
+ cache,
36
+ discovery,
37
+ permissions,
38
+ logger,
39
+ httpAuth,
40
+ auth,
41
+ catalogApi
42
+ });
43
+ http.use(router$1);
44
+ http.addAuthPolicy({
45
+ path: "/ping",
46
+ allow: "unauthenticated"
47
+ });
48
+ }
49
+ });
50
+ }
51
+ });
52
+
53
+ exports.bulkImportPlugin = bulkImportPlugin;
54
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +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 */\n\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha';\n\nimport { createRouter } from './service/router';\n\n/**\n * The bulk-import backend plugin.\n */\nexport const bulkImportPlugin = createBackendPlugin({\n pluginId: 'bulk-import',\n register(env) {\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n http: coreServices.httpRouter,\n cache: coreServices.cache,\n discovery: coreServices.discovery,\n permissions: coreServices.permissions,\n httpAuth: coreServices.httpAuth,\n auth: coreServices.auth,\n catalogApi: catalogServiceRef,\n },\n async init({\n config,\n logger,\n http,\n cache,\n discovery,\n permissions,\n httpAuth,\n auth,\n catalogApi,\n }) {\n const router = await createRouter({\n config,\n cache,\n discovery,\n permissions,\n logger,\n httpAuth,\n auth,\n catalogApi,\n });\n http.use(router);\n http.addAuthPolicy({\n path: '/ping',\n allow: 'unauthenticated',\n });\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","catalogServiceRef","router","createRouter"],"mappings":";;;;;;AA2BO,MAAM,mBAAmBA,oCAAoB,CAAA;AAAA,EAClD,QAAU,EAAA,aAAA;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,MAAMA,6BAAa,CAAA,UAAA;AAAA,QACnB,OAAOA,6BAAa,CAAA,KAAA;AAAA,QACpB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,aAAaA,6BAAa,CAAA,WAAA;AAAA,QAC1B,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,MAAMA,6BAAa,CAAA,IAAA;AAAA,QACnB,UAAY,EAAAC,uBAAA;AAAA,OACd;AAAA,MACA,MAAM,IAAK,CAAA;AAAA,QACT,MAAA;AAAA,QACA,MAAA;AAAA,QACA,IAAA;AAAA,QACA,KAAA;AAAA,QACA,SAAA;AAAA,QACA,WAAA;AAAA,QACA,QAAA;AAAA,QACA,IAAA;AAAA,QACA,UAAA;AAAA,OACC,EAAA;AACD,QAAM,MAAAC,QAAA,GAAS,MAAMC,mBAAa,CAAA;AAAA,UAChC,MAAA;AAAA,UACA,KAAA;AAAA,UACA,SAAA;AAAA,UACA,WAAA;AAAA,UACA,MAAA;AAAA,UACA,QAAA;AAAA,UACA,IAAA;AAAA,UACA,UAAA;AAAA,SACD,CAAA,CAAA;AACD,QAAA,IAAA,CAAK,IAAID,QAAM,CAAA,CAAA;AACf,QAAA,IAAA,CAAK,aAAc,CAAA;AAAA,UACjB,IAAM,EAAA,OAAA;AAAA,UACN,KAAO,EAAA,iBAAA;AAAA,SACR,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ const DefaultPageNumber = 1;
4
+ const DefaultPageSize = 20;
5
+
6
+ exports.DefaultPageNumber = DefaultPageNumber;
7
+ exports.DefaultPageSize = DefaultPageSize;
8
+ //# sourceMappingURL=handlers.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.cjs.js","sources":["../../../src/service/handlers/handlers.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 */\n\nexport const DefaultPageNumber = 1;\nexport const DefaultPageSize = 20;\n\nexport interface HandlerResponse<ResponseBody = any> {\n statusCode: number;\n responseBody?: ResponseBody;\n}\n"],"names":[],"mappings":";;AAgBO,MAAM,iBAAoB,GAAA,EAAA;AAC1B,MAAM,eAAkB,GAAA;;;;;"}