@backstage/plugin-search-backend-module-catalog 0.2.3-next.1 → 0.2.3

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,41 @@
1
1
  # @backstage/plugin-search-backend-module-catalog
2
2
 
3
+ ## 0.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 4b60e0c: Remove extension points from `/alpha` export, they're available from the main package already
8
+ - 094eaa3: Remove references to in-repo backend-common
9
+ - 3109c24: The export for the new backend system at the `/alpha` export is now also available via the main entry point, which means that you can remove the `/alpha` suffix from the import.
10
+ - 2f88f88: Updated backend installation instructions.
11
+ - Updated dependencies
12
+ - @backstage/plugin-search-backend-node@1.3.3
13
+ - @backstage/plugin-catalog-node@1.13.1
14
+ - @backstage/catalog-client@1.7.1
15
+ - @backstage/backend-plugin-api@1.0.1
16
+ - @backstage/catalog-model@1.7.0
17
+ - @backstage/config@1.2.0
18
+ - @backstage/errors@1.2.4
19
+ - @backstage/plugin-catalog-common@1.1.0
20
+ - @backstage/plugin-permission-common@0.8.1
21
+ - @backstage/plugin-search-common@1.2.14
22
+
23
+ ## 0.2.3-next.2
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies
28
+ - @backstage/plugin-catalog-node@1.13.1-next.1
29
+ - @backstage/catalog-client@1.7.1-next.0
30
+ - @backstage/backend-plugin-api@1.0.1-next.1
31
+ - @backstage/catalog-model@1.7.0
32
+ - @backstage/config@1.2.0
33
+ - @backstage/errors@1.2.4
34
+ - @backstage/plugin-catalog-common@1.1.0
35
+ - @backstage/plugin-permission-common@0.8.1
36
+ - @backstage/plugin-search-backend-node@1.3.3-next.2
37
+ - @backstage/plugin-search-common@1.2.14
38
+
3
39
  ## 0.2.3-next.1
4
40
 
5
41
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-search-backend-module-catalog__alpha",
3
- "version": "0.2.3-next.1",
3
+ "version": "0.2.3",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/dist/alpha.cjs.js CHANGED
@@ -2,62 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var backendPluginApi = require('@backstage/backend-plugin-api');
6
- var alpha$2 = require('@backstage/plugin-catalog-node/alpha');
7
- var pluginSearchBackendModuleCatalog = require('@backstage/plugin-search-backend-module-catalog');
8
- var alpha$1 = require('@backstage/plugin-search-backend-node/alpha');
9
- var config = require('./cjs/config-BgngnqUm.cjs.js');
10
- require('@backstage/errors');
5
+ var module$1 = require('./module.cjs.js');
11
6
 
12
- const catalogCollatorExtensionPoint = backendPluginApi.createExtensionPoint({
13
- id: "search.catalogCollator.extension"
14
- });
15
- var alpha = backendPluginApi.createBackendModule({
16
- pluginId: "search",
17
- moduleId: "catalog-collator",
18
- register(env) {
19
- let entityTransformer;
20
- env.registerExtensionPoint(catalogCollatorExtensionPoint, {
21
- setEntityTransformer(transformer) {
22
- if (entityTransformer) {
23
- throw new Error("setEntityTransformer can only be called once");
24
- }
25
- entityTransformer = transformer;
26
- }
27
- });
28
- env.registerInit({
29
- deps: {
30
- auth: backendPluginApi.coreServices.auth,
31
- config: backendPluginApi.coreServices.rootConfig,
32
- discovery: backendPluginApi.coreServices.discovery,
33
- scheduler: backendPluginApi.coreServices.scheduler,
34
- indexRegistry: alpha$1.searchIndexRegistryExtensionPoint,
35
- catalog: alpha$2.catalogServiceRef
36
- },
37
- async init({
38
- auth,
39
- config: config$1,
40
- discovery,
41
- scheduler,
42
- indexRegistry,
43
- catalog
44
- }) {
45
- indexRegistry.addCollator({
46
- schedule: scheduler.createScheduledTaskRunner(
47
- config.readScheduleConfigOptions(config$1)
48
- ),
49
- factory: pluginSearchBackendModuleCatalog.DefaultCatalogCollatorFactory.fromConfig(config$1, {
50
- auth,
51
- entityTransformer,
52
- discovery,
53
- catalogClient: catalog
54
- })
55
- });
56
- }
57
- });
58
- }
59
- });
7
+ const _feature = module$1.default;
60
8
 
61
- exports.catalogCollatorExtensionPoint = catalogCollatorExtensionPoint;
62
- exports.default = alpha;
9
+ exports.default = _feature;
63
10
  //# sourceMappingURL=alpha.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"alpha.cjs.js","sources":["../src/alpha.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @packageDocumentation\n * A module for the search backend that exports Catalog modules.\n */\n\nimport {\n coreServices,\n createBackendModule,\n createExtensionPoint,\n} from '@backstage/backend-plugin-api';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha';\nimport {\n CatalogCollatorEntityTransformer,\n DefaultCatalogCollatorFactory,\n} from '@backstage/plugin-search-backend-module-catalog';\nimport { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha';\nimport { readScheduleConfigOptions } from './collators/config';\n\n/**\n * Options for {@link catalogCollatorExtensionPoint}.\n *\n * @alpha\n */\nexport type CatalogCollatorExtensionPoint = {\n /**\n * Allows you to customize how entities are shaped into documents.\n */\n setEntityTransformer(transformer: CatalogCollatorEntityTransformer): void;\n};\n\n/**\n * Extension point for customizing how catalog entities are shaped into\n * documents for the search backend.\n *\n * @alpha\n */\nexport const catalogCollatorExtensionPoint =\n createExtensionPoint<CatalogCollatorExtensionPoint>({\n id: 'search.catalogCollator.extension',\n });\n\n/**\n * Search backend module for the Catalog index.\n *\n * @alpha\n */\nexport default createBackendModule({\n pluginId: 'search',\n moduleId: 'catalog-collator',\n register(env) {\n let entityTransformer: CatalogCollatorEntityTransformer | undefined;\n\n env.registerExtensionPoint(catalogCollatorExtensionPoint, {\n setEntityTransformer(transformer) {\n if (entityTransformer) {\n throw new Error('setEntityTransformer can only be called once');\n }\n entityTransformer = transformer;\n },\n });\n\n env.registerInit({\n deps: {\n auth: coreServices.auth,\n config: coreServices.rootConfig,\n discovery: coreServices.discovery,\n scheduler: coreServices.scheduler,\n indexRegistry: searchIndexRegistryExtensionPoint,\n catalog: catalogServiceRef,\n },\n async init({\n auth,\n config,\n discovery,\n scheduler,\n indexRegistry,\n catalog,\n }) {\n indexRegistry.addCollator({\n schedule: scheduler.createScheduledTaskRunner(\n readScheduleConfigOptions(config),\n ),\n factory: DefaultCatalogCollatorFactory.fromConfig(config, {\n auth,\n entityTransformer,\n discovery,\n catalogClient: catalog,\n }),\n });\n },\n });\n },\n});\n"],"names":["createExtensionPoint","createBackendModule","coreServices","searchIndexRegistryExtensionPoint","catalogServiceRef","config","readScheduleConfigOptions","DefaultCatalogCollatorFactory"],"mappings":";;;;;;;;;;;AAoDO,MAAM,gCACXA,qCAAoD,CAAA;AAAA,EAClD,EAAI,EAAA,kCAAA;AACN,CAAC,EAAA;AAOH,YAAeC,oCAAoB,CAAA;AAAA,EACjC,QAAU,EAAA,QAAA;AAAA,EACV,QAAU,EAAA,kBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAI,IAAA,iBAAA,CAAA;AAEJ,IAAA,GAAA,CAAI,uBAAuB,6BAA+B,EAAA;AAAA,MACxD,qBAAqB,WAAa,EAAA;AAChC,QAAA,IAAI,iBAAmB,EAAA;AACrB,UAAM,MAAA,IAAI,MAAM,8CAA8C,CAAA,CAAA;AAAA,SAChE;AACA,QAAoB,iBAAA,GAAA,WAAA,CAAA;AAAA,OACtB;AAAA,KACD,CAAA,CAAA;AAED,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,MAAMC,6BAAa,CAAA,IAAA;AAAA,QACnB,QAAQA,6BAAa,CAAA,UAAA;AAAA,QACrB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,aAAe,EAAAC,yCAAA;AAAA,QACf,OAAS,EAAAC,yBAAA;AAAA,OACX;AAAA,MACA,MAAM,IAAK,CAAA;AAAA,QACT,IAAA;AAAA,gBACAC,QAAA;AAAA,QACA,SAAA;AAAA,QACA,SAAA;AAAA,QACA,aAAA;AAAA,QACA,OAAA;AAAA,OACC,EAAA;AACD,QAAA,aAAA,CAAc,WAAY,CAAA;AAAA,UACxB,UAAU,SAAU,CAAA,yBAAA;AAAA,YAClBC,iCAA0BD,QAAM,CAAA;AAAA,WAClC;AAAA,UACA,OAAA,EAASE,8DAA8B,CAAA,UAAA,CAAWF,QAAQ,EAAA;AAAA,YACxD,IAAA;AAAA,YACA,iBAAA;AAAA,YACA,SAAA;AAAA,YACA,aAAe,EAAA,OAAA;AAAA,WAChB,CAAA;AAAA,SACF,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC,CAAA;;;;;"}
1
+ {"version":3,"file":"alpha.cjs.js","sources":["../src/alpha.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 { default as feature } from './module';\n\n/** @alpha */\nconst _feature = feature;\nexport default _feature;\n"],"names":["feature"],"mappings":";;;;;;AAmBA,MAAM,QAAW,GAAAA;;;;"}
package/dist/alpha.d.ts CHANGED
@@ -1,29 +1,6 @@
1
1
  import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
- import { CatalogCollatorEntityTransformer } from '@backstage/plugin-search-backend-module-catalog';
3
2
 
4
- /**
5
- * Options for {@link catalogCollatorExtensionPoint}.
6
- *
7
- * @alpha
8
- */
9
- type CatalogCollatorExtensionPoint = {
10
- /**
11
- * Allows you to customize how entities are shaped into documents.
12
- */
13
- setEntityTransformer(transformer: CatalogCollatorEntityTransformer): void;
14
- };
15
- /**
16
- * Extension point for customizing how catalog entities are shaped into
17
- * documents for the search backend.
18
- *
19
- * @alpha
20
- */
21
- declare const catalogCollatorExtensionPoint: _backstage_backend_plugin_api.ExtensionPoint<CatalogCollatorExtensionPoint>;
22
- /**
23
- * Search backend module for the Catalog index.
24
- *
25
- * @alpha
26
- */
27
- declare const _default: _backstage_backend_plugin_api.BackendFeature;
3
+ /** @alpha */
4
+ declare const _feature: _backstage_backend_plugin_api.BackendFeature;
28
5
 
29
- export { type CatalogCollatorExtensionPoint, catalogCollatorExtensionPoint, _default as default };
6
+ export { _feature as default };
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+
3
+ var backendCommon = require('@backstage/backend-common');
4
+ var catalogClient = require('@backstage/catalog-client');
5
+ var catalogModel = require('@backstage/catalog-model');
6
+ var alpha = require('@backstage/plugin-catalog-common/alpha');
7
+ var stream = require('stream');
8
+ var config = require('./config.cjs.js');
9
+ var defaultCatalogCollatorEntityTransformer = require('./defaultCatalogCollatorEntityTransformer.cjs.js');
10
+
11
+ class DefaultCatalogCollatorFactory {
12
+ type = "software-catalog";
13
+ visibilityPermission = alpha.catalogEntityReadPermission;
14
+ locationTemplate;
15
+ filter;
16
+ batchSize;
17
+ catalogClient;
18
+ entityTransformer;
19
+ auth;
20
+ static fromConfig(configRoot, options) {
21
+ const configOptions = config.readCollatorConfigOptions(configRoot);
22
+ const { auth: adaptedAuth } = backendCommon.createLegacyAuthAdapters({
23
+ auth: options.auth,
24
+ discovery: options.discovery,
25
+ tokenManager: options.tokenManager
26
+ });
27
+ return new DefaultCatalogCollatorFactory({
28
+ locationTemplate: options.locationTemplate ?? configOptions.locationTemplate,
29
+ filter: options.filter ?? configOptions.filter,
30
+ batchSize: options.batchSize ?? configOptions.batchSize,
31
+ entityTransformer: options.entityTransformer,
32
+ auth: adaptedAuth,
33
+ discovery: options.discovery,
34
+ catalogClient: options.catalogClient
35
+ });
36
+ }
37
+ constructor(options) {
38
+ const {
39
+ auth,
40
+ batchSize,
41
+ discovery,
42
+ locationTemplate,
43
+ filter,
44
+ catalogClient: catalogClient$1,
45
+ entityTransformer
46
+ } = options;
47
+ this.locationTemplate = locationTemplate;
48
+ this.filter = filter;
49
+ this.batchSize = batchSize;
50
+ this.catalogClient = catalogClient$1 || new catalogClient.CatalogClient({ discoveryApi: discovery });
51
+ this.entityTransformer = entityTransformer ?? defaultCatalogCollatorEntityTransformer.defaultCatalogCollatorEntityTransformer;
52
+ this.auth = auth;
53
+ }
54
+ async getCollator() {
55
+ return stream.Readable.from(this.execute());
56
+ }
57
+ async *execute() {
58
+ let entitiesRetrieved = 0;
59
+ let moreEntitiesToGet = true;
60
+ while (moreEntitiesToGet) {
61
+ const { token } = await this.auth.getPluginRequestToken({
62
+ onBehalfOf: await this.auth.getOwnServiceCredentials(),
63
+ targetPluginId: "catalog"
64
+ });
65
+ const entities = (await this.catalogClient.getEntities(
66
+ {
67
+ filter: this.filter,
68
+ limit: this.batchSize,
69
+ offset: entitiesRetrieved
70
+ },
71
+ { token }
72
+ )).items;
73
+ moreEntitiesToGet = entities.length === this.batchSize;
74
+ entitiesRetrieved += entities.length;
75
+ for (const entity of entities) {
76
+ yield {
77
+ ...this.entityTransformer(entity),
78
+ authorization: {
79
+ resourceRef: catalogModel.stringifyEntityRef(entity)
80
+ },
81
+ location: this.applyArgsToFormat(this.locationTemplate, {
82
+ namespace: entity.metadata.namespace || "default",
83
+ kind: entity.kind,
84
+ name: entity.metadata.name
85
+ })
86
+ };
87
+ }
88
+ }
89
+ }
90
+ applyArgsToFormat(format, args) {
91
+ let formatted = format;
92
+ for (const [key, value] of Object.entries(args)) {
93
+ formatted = formatted.replace(`:${key}`, value);
94
+ }
95
+ return formatted.toLowerCase();
96
+ }
97
+ }
98
+
99
+ exports.DefaultCatalogCollatorFactory = DefaultCatalogCollatorFactory;
100
+ //# sourceMappingURL=DefaultCatalogCollatorFactory.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultCatalogCollatorFactory.cjs.js","sources":["../../src/collators/DefaultCatalogCollatorFactory.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n TokenManager,\n createLegacyAuthAdapters,\n} from '@backstage/backend-common';\nimport {\n CatalogApi,\n CatalogClient,\n GetEntitiesRequest,\n} from '@backstage/catalog-client';\nimport { stringifyEntityRef } from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport { CatalogEntityDocument } from '@backstage/plugin-catalog-common';\nimport { catalogEntityReadPermission } from '@backstage/plugin-catalog-common/alpha';\nimport { Permission } from '@backstage/plugin-permission-common';\nimport { DocumentCollatorFactory } from '@backstage/plugin-search-common';\nimport { Readable } from 'stream';\nimport { CatalogCollatorEntityTransformer } from './CatalogCollatorEntityTransformer';\nimport { readCollatorConfigOptions } from './config';\nimport { defaultCatalogCollatorEntityTransformer } from './defaultCatalogCollatorEntityTransformer';\nimport { AuthService, DiscoveryService } from '@backstage/backend-plugin-api';\n\n/**\n * @public\n * @deprecated This type is deprecated along with the {@link DefaultCatalogCollatorFactory}.\n */\nexport type DefaultCatalogCollatorFactoryOptions = {\n auth?: AuthService;\n discovery: DiscoveryService;\n tokenManager?: TokenManager;\n /**\n * @deprecated Use the config key `search.collators.catalog.locationTemplate` instead.\n */\n locationTemplate?: string;\n /**\n * @deprecated Use the config key `search.collators.catalog.filter` instead.\n */\n filter?: GetEntitiesRequest['filter'];\n /**\n * @deprecated Use the config key `search.collators.catalog.batchSize` instead.\n */\n batchSize?: number;\n catalogClient?: CatalogApi;\n /**\n * Allows you to customize how entities are shaped into documents.\n */\n entityTransformer?: CatalogCollatorEntityTransformer;\n};\n\n/**\n * Collates entities from the Catalog into documents for the search backend.\n *\n * @public\n * @deprecated Migrate to the {@link https://backstage.io/docs/backend-system/building-backends/migrating | new backend system} and install this collator via module instead (see {@link https://github.com/backstage/backstage/blob/nbs10/search-deprecate-create-router/plugins/search-backend-module-catalog/README.md#installation | here} for more installation details).\n */\nexport class DefaultCatalogCollatorFactory implements DocumentCollatorFactory {\n public readonly type = 'software-catalog';\n public readonly visibilityPermission: Permission =\n catalogEntityReadPermission;\n\n private locationTemplate: string;\n private filter?: GetEntitiesRequest['filter'];\n private batchSize: number;\n private readonly catalogClient: CatalogApi;\n private entityTransformer: CatalogCollatorEntityTransformer;\n private auth: AuthService;\n\n static fromConfig(\n configRoot: Config,\n options: DefaultCatalogCollatorFactoryOptions,\n ) {\n const configOptions = readCollatorConfigOptions(configRoot);\n const { auth: adaptedAuth } = createLegacyAuthAdapters({\n auth: options.auth,\n discovery: options.discovery,\n tokenManager: options.tokenManager,\n });\n return new DefaultCatalogCollatorFactory({\n locationTemplate:\n options.locationTemplate ?? configOptions.locationTemplate,\n filter: options.filter ?? configOptions.filter,\n batchSize: options.batchSize ?? configOptions.batchSize,\n entityTransformer: options.entityTransformer,\n auth: adaptedAuth,\n discovery: options.discovery,\n catalogClient: options.catalogClient,\n });\n }\n\n private constructor(options: {\n locationTemplate: string;\n filter: GetEntitiesRequest['filter'];\n batchSize: number;\n entityTransformer?: CatalogCollatorEntityTransformer;\n auth: AuthService;\n discovery: DiscoveryService;\n catalogClient?: CatalogApi;\n }) {\n const {\n auth,\n batchSize,\n discovery,\n locationTemplate,\n filter,\n catalogClient,\n entityTransformer,\n } = options;\n\n this.locationTemplate = locationTemplate;\n this.filter = filter;\n this.batchSize = batchSize;\n this.catalogClient =\n catalogClient || new CatalogClient({ discoveryApi: discovery });\n this.entityTransformer =\n entityTransformer ?? defaultCatalogCollatorEntityTransformer;\n this.auth = auth;\n }\n\n async getCollator(): Promise<Readable> {\n return Readable.from(this.execute());\n }\n\n private async *execute(): AsyncGenerator<CatalogEntityDocument> {\n let entitiesRetrieved = 0;\n let moreEntitiesToGet = true;\n\n // Offset/limit pagination is used on the Catalog Client in order to\n // limit (and allow some control over) memory used by the search backend\n // at index-time.\n while (moreEntitiesToGet) {\n const { token } = await this.auth.getPluginRequestToken({\n onBehalfOf: await this.auth.getOwnServiceCredentials(),\n targetPluginId: 'catalog',\n });\n const entities = (\n await this.catalogClient.getEntities(\n {\n filter: this.filter,\n limit: this.batchSize,\n offset: entitiesRetrieved,\n },\n { token },\n )\n ).items;\n\n // Control looping through entity batches.\n moreEntitiesToGet = entities.length === this.batchSize;\n entitiesRetrieved += entities.length;\n\n for (const entity of entities) {\n yield {\n ...this.entityTransformer(entity),\n authorization: {\n resourceRef: stringifyEntityRef(entity),\n },\n location: this.applyArgsToFormat(this.locationTemplate, {\n namespace: entity.metadata.namespace || 'default',\n kind: entity.kind,\n name: entity.metadata.name,\n }),\n };\n }\n }\n }\n\n private applyArgsToFormat(\n format: string,\n args: Record<string, string>,\n ): string {\n let formatted = format;\n\n for (const [key, value] of Object.entries(args)) {\n formatted = formatted.replace(`:${key}`, value);\n }\n\n return formatted.toLowerCase();\n }\n}\n"],"names":["catalogEntityReadPermission","readCollatorConfigOptions","createLegacyAuthAdapters","catalogClient","CatalogClient","defaultCatalogCollatorEntityTransformer","Readable","stringifyEntityRef"],"mappings":";;;;;;;;;;AAsEO,MAAM,6BAAiE,CAAA;AAAA,EAC5D,IAAO,GAAA,kBAAA,CAAA;AAAA,EACP,o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,EAAA;AAAA,YACb,WAAA,EAAaC,gCAAmB,MAAM,CAAA;AAAA,WACxC;AAAA,UACA,QAAU,EAAA,IAAA,CAAK,iBAAkB,CAAA,IAAA,CAAK,gBAAkB,EAAA;AAAA,YACtD,SAAA,EAAW,MAAO,CAAA,QAAA,CAAS,SAAa,IAAA,SAAA;AAAA,YACxC,MAAM,MAAO,CAAA,IAAA;AAAA,YACb,IAAA,EAAM,OAAO,QAAS,CAAA,IAAA;AAAA,WACvB,CAAA;AAAA,SACH,CAAA;AAAA,OACF;AAAA,KACF;AAAA,GACF;AAAA,EAEQ,iBAAA,CACN,QACA,IACQ,EAAA;AACR,IAAA,IAAI,SAAY,GAAA,MAAA,CAAA;AAEhB,IAAA,KAAA,MAAW,CAAC,GAAK,EAAA,KAAK,KAAK,MAAO,CAAA,OAAA,CAAQ,IAAI,CAAG,EAAA;AAC/C,MAAA,SAAA,GAAY,SAAU,CAAA,OAAA,CAAQ,CAAI,CAAA,EAAA,GAAG,IAAI,KAAK,CAAA,CAAA;AAAA,KAChD;AAEA,IAAA,OAAO,UAAU,WAAY,EAAA,CAAA;AAAA,GAC/B;AACF;;;;"}
@@ -43,6 +43,7 @@ function readCollatorConfigOptions(configRoot) {
43
43
  };
44
44
  }
45
45
 
46
+ exports.defaults = defaults;
46
47
  exports.readCollatorConfigOptions = readCollatorConfigOptions;
47
48
  exports.readScheduleConfigOptions = readScheduleConfigOptions;
48
- //# sourceMappingURL=config-BgngnqUm.cjs.js.map
49
+ //# sourceMappingURL=config.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.cjs.js","sources":["../../src/collators/config.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 SchedulerServiceTaskScheduleDefinition,\n readSchedulerServiceTaskScheduleDefinitionFromConfig,\n} from '@backstage/backend-plugin-api';\nimport { EntityFilterQuery } from '@backstage/catalog-client';\nimport { Config } from '@backstage/config';\nimport { InputError } from '@backstage/errors';\n\nconst configKey = 'search.collators.catalog';\n\nexport const defaults = {\n schedule: {\n frequency: { minutes: 10 },\n timeout: { minutes: 15 },\n initialDelay: { seconds: 3 },\n },\n collatorOptions: {\n locationTemplate: '/catalog/:namespace/:kind/:name',\n filter: undefined,\n batchSize: 500,\n },\n};\n\nexport function readScheduleConfigOptions(\n configRoot: Config,\n): SchedulerServiceTaskScheduleDefinition {\n let schedule: SchedulerServiceTaskScheduleDefinition | undefined = undefined;\n\n const config = configRoot.getOptionalConfig(configKey);\n if (config) {\n const scheduleConfig = config.getOptionalConfig('schedule');\n if (scheduleConfig) {\n try {\n schedule =\n readSchedulerServiceTaskScheduleDefinitionFromConfig(scheduleConfig);\n } catch (error) {\n throw new InputError(`Invalid schedule at ${configKey}, ${error}`);\n }\n }\n }\n\n return schedule ?? defaults.schedule;\n}\n\nexport function readCollatorConfigOptions(configRoot: Config): {\n locationTemplate: string;\n filter: EntityFilterQuery | undefined;\n batchSize: number;\n} {\n const config = configRoot.getOptionalConfig(configKey);\n if (!config) {\n return defaults.collatorOptions;\n }\n\n return {\n locationTemplate:\n config.getOptionalString('locationTemplate') ??\n defaults.collatorOptions.locationTemplate,\n filter:\n config.getOptionalConfig('filter')?.get<EntityFilterQuery>() ??\n defaults.collatorOptions.filter,\n batchSize:\n config.getOptionalNumber('batchSize') ??\n defaults.collatorOptions.batchSize,\n };\n}\n"],"names":["readSchedulerServiceTaskScheduleDefinitionFromConfig","InputError"],"mappings":";;;;;AAwBA,MAAM,SAAY,GAAA,0BAAA,CAAA;AAEX,MAAM,QAAW,GAAA;AAAA,EACtB,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AAA,IAC3B,MAAA,EACE,OAAO,iBAAkB,CAAA,QAAQ,GAAG,GAAuB,EAAA,IAC3D,SAAS,eAAgB,CAAA,MAAA;AAAA,IAC3B,WACE,MAAO,CAAA,iBAAA,CAAkB,WAAW,CAAA,IACpC,SAAS,eAAgB,CAAA,SAAA;AAAA,GAC7B,CAAA;AACF;;;;;;"}
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ var catalogModel = require('@backstage/catalog-model');
4
+
5
+ const getDocumentText = (entity) => {
6
+ const documentTexts = [];
7
+ documentTexts.push(entity.metadata.description || "");
8
+ if (catalogModel.isUserEntity(entity) || catalogModel.isGroupEntity(entity)) {
9
+ if (entity.spec?.profile?.displayName) {
10
+ documentTexts.push(entity.spec.profile.displayName);
11
+ }
12
+ }
13
+ if (catalogModel.isUserEntity(entity)) {
14
+ if (entity.spec?.profile?.email) {
15
+ documentTexts.push(entity.spec.profile.email);
16
+ }
17
+ }
18
+ return documentTexts.join(" : ");
19
+ };
20
+ const defaultCatalogCollatorEntityTransformer = (entity) => {
21
+ return {
22
+ title: entity.metadata.title ?? entity.metadata.name,
23
+ text: getDocumentText(entity),
24
+ componentType: entity.spec?.type?.toString() || "other",
25
+ type: entity.spec?.type?.toString() || "other",
26
+ namespace: entity.metadata.namespace || "default",
27
+ kind: entity.kind,
28
+ lifecycle: entity.spec?.lifecycle || "",
29
+ owner: entity.spec?.owner || ""
30
+ };
31
+ };
32
+
33
+ exports.defaultCatalogCollatorEntityTransformer = defaultCatalogCollatorEntityTransformer;
34
+ //# sourceMappingURL=defaultCatalogCollatorEntityTransformer.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultCatalogCollatorEntityTransformer.cjs.js","sources":["../../src/collators/defaultCatalogCollatorEntityTransformer.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Entity, isGroupEntity, isUserEntity } from '@backstage/catalog-model';\nimport { CatalogCollatorEntityTransformer } from './CatalogCollatorEntityTransformer';\n\nconst getDocumentText = (entity: Entity): string => {\n const documentTexts: string[] = [];\n documentTexts.push(entity.metadata.description || '');\n\n if (isUserEntity(entity) || isGroupEntity(entity)) {\n if (entity.spec?.profile?.displayName) {\n documentTexts.push(entity.spec.profile.displayName);\n }\n }\n\n if (isUserEntity(entity)) {\n if (entity.spec?.profile?.email) {\n documentTexts.push(entity.spec.profile.email);\n }\n }\n\n return documentTexts.join(' : ');\n};\n\n/** @public */\nexport const defaultCatalogCollatorEntityTransformer: CatalogCollatorEntityTransformer =\n (entity: Entity) => {\n return {\n title: entity.metadata.title ?? entity.metadata.name,\n text: getDocumentText(entity),\n componentType: entity.spec?.type?.toString() || 'other',\n type: entity.spec?.type?.toString() || 'other',\n namespace: entity.metadata.namespace || 'default',\n kind: entity.kind,\n lifecycle: (entity.spec?.lifecycle as string) || '',\n owner: (entity.spec?.owner as string) || '',\n };\n };\n"],"names":["isUserEntity","isGroupEntity"],"mappings":";;;;AAmBA,MAAM,eAAA,GAAkB,CAAC,MAA2B,KAAA;AAClD,EAAA,MAAM,gBAA0B,EAAC,CAAA;AACjC,EAAA,aAAA,CAAc,IAAK,CAAA,MAAA,CAAO,QAAS,CAAA,WAAA,IAAe,EAAE,CAAA,CAAA;AAEpD,EAAA,IAAIA,yBAAa,CAAA,MAAM,CAAK,IAAAC,0BAAA,CAAc,MAAM,CAAG,EAAA;AACjD,IAAI,IAAA,MAAA,CAAO,IAAM,EAAA,OAAA,EAAS,WAAa,EAAA;AACrC,MAAA,aAAA,CAAc,IAAK,CAAA,MAAA,CAAO,IAAK,CAAA,OAAA,CAAQ,WAAW,CAAA,CAAA;AAAA,KACpD;AAAA,GACF;AAEA,EAAI,IAAAD,yBAAA,CAAa,MAAM,CAAG,EAAA;AACxB,IAAI,IAAA,MAAA,CAAO,IAAM,EAAA,OAAA,EAAS,KAAO,EAAA;AAC/B,MAAA,aAAA,CAAc,IAAK,CAAA,MAAA,CAAO,IAAK,CAAA,OAAA,CAAQ,KAAK,CAAA,CAAA;AAAA,KAC9C;AAAA,GACF;AAEA,EAAO,OAAA,aAAA,CAAc,KAAK,KAAK,CAAA,CAAA;AACjC,CAAA,CAAA;AAGa,MAAA,uCAAA,GACX,CAAC,MAAmB,KAAA;AAClB,EAAO,OAAA;AAAA,IACL,KAAO,EAAA,MAAA,CAAO,QAAS,CAAA,KAAA,IAAS,OAAO,QAAS,CAAA,IAAA;AAAA,IAChD,IAAA,EAAM,gBAAgB,MAAM,CAAA;AAAA,IAC5B,aAAe,EAAA,MAAA,CAAO,IAAM,EAAA,IAAA,EAAM,UAAc,IAAA,OAAA;AAAA,IAChD,IAAM,EAAA,MAAA,CAAO,IAAM,EAAA,IAAA,EAAM,UAAc,IAAA,OAAA;AAAA,IACvC,SAAA,EAAW,MAAO,CAAA,QAAA,CAAS,SAAa,IAAA,SAAA;AAAA,IACxC,MAAM,MAAO,CAAA,IAAA;AAAA,IACb,SAAA,EAAY,MAAO,CAAA,IAAA,EAAM,SAAwB,IAAA,EAAA;AAAA,IACjD,KAAA,EAAQ,MAAO,CAAA,IAAA,EAAM,KAAoB,IAAA,EAAA;AAAA,GAC3C,CAAA;AACF;;;;"}
package/dist/index.cjs.js CHANGED
@@ -1,130 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var backendCommon = require('@backstage/backend-common');
4
- var catalogClient = require('@backstage/catalog-client');
5
- var catalogModel = require('@backstage/catalog-model');
6
- var alpha = require('@backstage/plugin-catalog-common/alpha');
7
- var stream = require('stream');
8
- var config = require('./cjs/config-BgngnqUm.cjs.js');
9
- require('@backstage/backend-plugin-api');
10
- require('@backstage/errors');
3
+ Object.defineProperty(exports, '__esModule', { value: true });
11
4
 
12
- const getDocumentText = (entity) => {
13
- const documentTexts = [];
14
- documentTexts.push(entity.metadata.description || "");
15
- if (catalogModel.isUserEntity(entity) || catalogModel.isGroupEntity(entity)) {
16
- if (entity.spec?.profile?.displayName) {
17
- documentTexts.push(entity.spec.profile.displayName);
18
- }
19
- }
20
- if (catalogModel.isUserEntity(entity)) {
21
- if (entity.spec?.profile?.email) {
22
- documentTexts.push(entity.spec.profile.email);
23
- }
24
- }
25
- return documentTexts.join(" : ");
26
- };
27
- const defaultCatalogCollatorEntityTransformer = (entity) => {
28
- return {
29
- title: entity.metadata.title ?? entity.metadata.name,
30
- text: getDocumentText(entity),
31
- componentType: entity.spec?.type?.toString() || "other",
32
- type: entity.spec?.type?.toString() || "other",
33
- namespace: entity.metadata.namespace || "default",
34
- kind: entity.kind,
35
- lifecycle: entity.spec?.lifecycle || "",
36
- owner: entity.spec?.owner || ""
37
- };
38
- };
5
+ var module$1 = require('./module.cjs.js');
6
+ var DefaultCatalogCollatorFactory = require('./collators/DefaultCatalogCollatorFactory.cjs.js');
7
+ var defaultCatalogCollatorEntityTransformer = require('./collators/defaultCatalogCollatorEntityTransformer.cjs.js');
39
8
 
40
- class DefaultCatalogCollatorFactory {
41
- type = "software-catalog";
42
- visibilityPermission = alpha.catalogEntityReadPermission;
43
- locationTemplate;
44
- filter;
45
- batchSize;
46
- catalogClient;
47
- entityTransformer;
48
- auth;
49
- static fromConfig(configRoot, options) {
50
- const configOptions = config.readCollatorConfigOptions(configRoot);
51
- const { auth: adaptedAuth } = backendCommon.createLegacyAuthAdapters({
52
- auth: options.auth,
53
- discovery: options.discovery,
54
- tokenManager: options.tokenManager
55
- });
56
- return new DefaultCatalogCollatorFactory({
57
- locationTemplate: options.locationTemplate ?? configOptions.locationTemplate,
58
- filter: options.filter ?? configOptions.filter,
59
- batchSize: options.batchSize ?? configOptions.batchSize,
60
- entityTransformer: options.entityTransformer,
61
- auth: adaptedAuth,
62
- discovery: options.discovery,
63
- catalogClient: options.catalogClient
64
- });
65
- }
66
- constructor(options) {
67
- const {
68
- auth,
69
- batchSize,
70
- discovery,
71
- locationTemplate,
72
- filter,
73
- catalogClient: catalogClient$1,
74
- entityTransformer
75
- } = options;
76
- this.locationTemplate = locationTemplate;
77
- this.filter = filter;
78
- this.batchSize = batchSize;
79
- this.catalogClient = catalogClient$1 || new catalogClient.CatalogClient({ discoveryApi: discovery });
80
- this.entityTransformer = entityTransformer ?? defaultCatalogCollatorEntityTransformer;
81
- this.auth = auth;
82
- }
83
- async getCollator() {
84
- return stream.Readable.from(this.execute());
85
- }
86
- async *execute() {
87
- let entitiesRetrieved = 0;
88
- let moreEntitiesToGet = true;
89
- while (moreEntitiesToGet) {
90
- const { token } = await this.auth.getPluginRequestToken({
91
- onBehalfOf: await this.auth.getOwnServiceCredentials(),
92
- targetPluginId: "catalog"
93
- });
94
- const entities = (await this.catalogClient.getEntities(
95
- {
96
- filter: this.filter,
97
- limit: this.batchSize,
98
- offset: entitiesRetrieved
99
- },
100
- { token }
101
- )).items;
102
- moreEntitiesToGet = entities.length === this.batchSize;
103
- entitiesRetrieved += entities.length;
104
- for (const entity of entities) {
105
- yield {
106
- ...this.entityTransformer(entity),
107
- authorization: {
108
- resourceRef: catalogModel.stringifyEntityRef(entity)
109
- },
110
- location: this.applyArgsToFormat(this.locationTemplate, {
111
- namespace: entity.metadata.namespace || "default",
112
- kind: entity.kind,
113
- name: entity.metadata.name
114
- })
115
- };
116
- }
117
- }
118
- }
119
- applyArgsToFormat(format, args) {
120
- let formatted = format;
121
- for (const [key, value] of Object.entries(args)) {
122
- formatted = formatted.replace(`:${key}`, value);
123
- }
124
- return formatted.toLowerCase();
125
- }
126
- }
127
9
 
128
- exports.DefaultCatalogCollatorFactory = DefaultCatalogCollatorFactory;
129
- exports.defaultCatalogCollatorEntityTransformer = defaultCatalogCollatorEntityTransformer;
10
+
11
+ exports.catalogCollatorExtensionPoint = module$1.catalogCollatorExtensionPoint;
12
+ exports.default = module$1.default;
13
+ exports.DefaultCatalogCollatorFactory = DefaultCatalogCollatorFactory.DefaultCatalogCollatorFactory;
14
+ exports.defaultCatalogCollatorEntityTransformer = defaultCatalogCollatorEntityTransformer.defaultCatalogCollatorEntityTransformer;
130
15
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/collators/defaultCatalogCollatorEntityTransformer.ts","../src/collators/DefaultCatalogCollatorFactory.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Entity, isGroupEntity, isUserEntity } from '@backstage/catalog-model';\nimport { CatalogCollatorEntityTransformer } from './CatalogCollatorEntityTransformer';\n\nconst getDocumentText = (entity: Entity): string => {\n const documentTexts: string[] = [];\n documentTexts.push(entity.metadata.description || '');\n\n if (isUserEntity(entity) || isGroupEntity(entity)) {\n if (entity.spec?.profile?.displayName) {\n documentTexts.push(entity.spec.profile.displayName);\n }\n }\n\n if (isUserEntity(entity)) {\n if (entity.spec?.profile?.email) {\n documentTexts.push(entity.spec.profile.email);\n }\n }\n\n return documentTexts.join(' : ');\n};\n\n/** @public */\nexport const defaultCatalogCollatorEntityTransformer: CatalogCollatorEntityTransformer =\n (entity: Entity) => {\n return {\n title: entity.metadata.title ?? entity.metadata.name,\n text: getDocumentText(entity),\n componentType: entity.spec?.type?.toString() || 'other',\n type: entity.spec?.type?.toString() || 'other',\n namespace: entity.metadata.namespace || 'default',\n kind: entity.kind,\n lifecycle: (entity.spec?.lifecycle as string) || '',\n owner: (entity.spec?.owner as string) || '',\n };\n };\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n TokenManager,\n createLegacyAuthAdapters,\n} from '@backstage/backend-common';\nimport {\n CatalogApi,\n CatalogClient,\n GetEntitiesRequest,\n} from '@backstage/catalog-client';\nimport { stringifyEntityRef } from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport { CatalogEntityDocument } from '@backstage/plugin-catalog-common';\nimport { catalogEntityReadPermission } from '@backstage/plugin-catalog-common/alpha';\nimport { Permission } from '@backstage/plugin-permission-common';\nimport { DocumentCollatorFactory } from '@backstage/plugin-search-common';\nimport { Readable } from 'stream';\nimport { CatalogCollatorEntityTransformer } from './CatalogCollatorEntityTransformer';\nimport { readCollatorConfigOptions } from './config';\nimport { defaultCatalogCollatorEntityTransformer } from './defaultCatalogCollatorEntityTransformer';\nimport { AuthService, DiscoveryService } from '@backstage/backend-plugin-api';\n\n/**\n * @public\n * @deprecated This type is deprecated along with the {@link DefaultCatalogCollatorFactory}.\n */\nexport type DefaultCatalogCollatorFactoryOptions = {\n auth?: AuthService;\n discovery: DiscoveryService;\n tokenManager?: TokenManager;\n /**\n * @deprecated Use the config key `search.collators.catalog.locationTemplate` instead.\n */\n locationTemplate?: string;\n /**\n * @deprecated Use the config key `search.collators.catalog.filter` instead.\n */\n filter?: GetEntitiesRequest['filter'];\n /**\n * @deprecated Use the config key `search.collators.catalog.batchSize` instead.\n */\n batchSize?: number;\n catalogClient?: CatalogApi;\n /**\n * Allows you to customize how entities are shaped into documents.\n */\n entityTransformer?: CatalogCollatorEntityTransformer;\n};\n\n/**\n * Collates entities from the Catalog into documents for the search backend.\n *\n * @public\n * @deprecated Migrate to the {@link https://backstage.io/docs/backend-system/building-backends/migrating | new backend system} and install this collator via module instead (see {@link https://github.com/backstage/backstage/blob/nbs10/search-deprecate-create-router/plugins/search-backend-module-catalog/README.md#installation | here} for more installation details).\n */\nexport class DefaultCatalogCollatorFactory implements DocumentCollatorFactory {\n public readonly type = 'software-catalog';\n public readonly visibilityPermission: Permission =\n catalogEntityReadPermission;\n\n private locationTemplate: string;\n private filter?: GetEntitiesRequest['filter'];\n private batchSize: number;\n private readonly catalogClient: CatalogApi;\n private entityTransformer: CatalogCollatorEntityTransformer;\n private auth: AuthService;\n\n static fromConfig(\n configRoot: Config,\n options: DefaultCatalogCollatorFactoryOptions,\n ) {\n const configOptions = readCollatorConfigOptions(configRoot);\n const { auth: adaptedAuth } = createLegacyAuthAdapters({\n auth: options.auth,\n discovery: options.discovery,\n tokenManager: options.tokenManager,\n });\n return new DefaultCatalogCollatorFactory({\n locationTemplate:\n options.locationTemplate ?? configOptions.locationTemplate,\n filter: options.filter ?? configOptions.filter,\n batchSize: options.batchSize ?? configOptions.batchSize,\n entityTransformer: options.entityTransformer,\n auth: adaptedAuth,\n discovery: options.discovery,\n catalogClient: options.catalogClient,\n });\n }\n\n private constructor(options: {\n locationTemplate: string;\n filter: GetEntitiesRequest['filter'];\n batchSize: number;\n entityTransformer?: CatalogCollatorEntityTransformer;\n auth: AuthService;\n discovery: DiscoveryService;\n catalogClient?: CatalogApi;\n }) {\n const {\n auth,\n batchSize,\n discovery,\n locationTemplate,\n filter,\n catalogClient,\n entityTransformer,\n } = options;\n\n this.locationTemplate = locationTemplate;\n this.filter = filter;\n this.batchSize = batchSize;\n this.catalogClient =\n catalogClient || new CatalogClient({ discoveryApi: discovery });\n this.entityTransformer =\n entityTransformer ?? defaultCatalogCollatorEntityTransformer;\n this.auth = auth;\n }\n\n async getCollator(): Promise<Readable> {\n return Readable.from(this.execute());\n }\n\n private async *execute(): AsyncGenerator<CatalogEntityDocument> {\n let entitiesRetrieved = 0;\n let moreEntitiesToGet = true;\n\n // Offset/limit pagination is used on the Catalog Client in order to\n // limit (and allow some control over) memory used by the search backend\n // at index-time.\n while (moreEntitiesToGet) {\n const { token } = await this.auth.getPluginRequestToken({\n onBehalfOf: await this.auth.getOwnServiceCredentials(),\n targetPluginId: 'catalog',\n });\n const entities = (\n await this.catalogClient.getEntities(\n {\n filter: this.filter,\n limit: this.batchSize,\n offset: entitiesRetrieved,\n },\n { token },\n )\n ).items;\n\n // Control looping through entity batches.\n moreEntitiesToGet = entities.length === this.batchSize;\n entitiesRetrieved += entities.length;\n\n for (const entity of entities) {\n yield {\n ...this.entityTransformer(entity),\n authorization: {\n resourceRef: stringifyEntityRef(entity),\n },\n location: this.applyArgsToFormat(this.locationTemplate, {\n namespace: entity.metadata.namespace || 'default',\n kind: entity.kind,\n name: entity.metadata.name,\n }),\n };\n }\n }\n }\n\n private applyArgsToFormat(\n format: string,\n args: Record<string, string>,\n ): string {\n let formatted = format;\n\n for (const [key, value] of Object.entries(args)) {\n formatted = formatted.replace(`:${key}`, value);\n }\n\n return formatted.toLowerCase();\n }\n}\n"],"names":["isUserEntity","isGroupEntity","catalogEntityReadPermission","readCollatorConfigOptions","createLegacyAuthAdapters","catalogClient","CatalogClient","Readable","stringifyEntityRef"],"mappings":";;;;;;;;;;;AAmBA,MAAM,eAAA,GAAkB,CAAC,MAA2B,KAAA;AAClD,EAAA,MAAM,gBAA0B,EAAC,CAAA;AACjC,EAAA,aAAA,CAAc,IAAK,CAAA,MAAA,CAAO,QAAS,CAAA,WAAA,IAAe,EAAE,CAAA,CAAA;AAEpD,EAAA,IAAIA,yBAAa,CAAA,MAAM,CAAK,IAAAC,0BAAA,CAAc,MAAM,CAAG,EAAA;AACjD,IAAI,IAAA,MAAA,CAAO,IAAM,EAAA,OAAA,EAAS,WAAa,EAAA;AACrC,MAAA,aAAA,CAAc,IAAK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A,EAAW,MAAO,CAAA,QAAA,CAAS,SAAa,IAAA,SAAA;AAAA,YACxC,MAAM,MAAO,CAAA,IAAA;AAAA,YACb,IAAA,EAAM,OAAO,QAAS,CAAA,IAAA;AAAA,WACvB,CAAA;AAAA,SACH,CAAA;AAAA,OACF;AAAA,KACF;AAAA,GACF;AAAA,EAEQ,iBAAA,CACN,QACA,IACQ,EAAA;AACR,IAAA,IAAI,SAAY,GAAA,MAAA,CAAA;AAEhB,IAAA,KAAA,MAAW,CAAC,GAAK,EAAA,KAAK,KAAK,MAAO,CAAA,OAAA,CAAQ,IAAI,CAAG,EAAA;AAC/C,MAAA,SAAA,GAAY,SAAU,CAAA,OAAA,CAAQ,CAAI,CAAA,EAAA,GAAG,IAAI,KAAK,CAAA,CAAA;AAAA,KAChD;AAEA,IAAA,OAAO,UAAU,WAAY,EAAA,CAAA;AAAA,GAC/B;AACF;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  /// <reference types="node" />
2
+ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
3
+ import { AuthService, DiscoveryService } from '@backstage/backend-plugin-api';
4
+ import { CatalogCollatorEntityTransformer as CatalogCollatorEntityTransformer$1 } from '@backstage/plugin-search-backend-module-catalog';
2
5
  import { TokenManager } from '@backstage/backend-common';
3
6
  import { GetEntitiesRequest, CatalogApi } from '@backstage/catalog-client';
4
7
  import { Config } from '@backstage/config';
@@ -7,7 +10,31 @@ import { DocumentCollatorFactory } from '@backstage/plugin-search-common';
7
10
  import { Readable } from 'stream';
8
11
  import { Entity } from '@backstage/catalog-model';
9
12
  import { CatalogEntityDocument } from '@backstage/plugin-catalog-common';
10
- import { AuthService, DiscoveryService } from '@backstage/backend-plugin-api';
13
+
14
+ /**
15
+ * Options for {@link catalogCollatorExtensionPoint}.
16
+ *
17
+ * @public
18
+ */
19
+ type CatalogCollatorExtensionPoint = {
20
+ /**
21
+ * Allows you to customize how entities are shaped into documents.
22
+ */
23
+ setEntityTransformer(transformer: CatalogCollatorEntityTransformer$1): void;
24
+ };
25
+ /**
26
+ * Extension point for customizing how catalog entities are shaped into
27
+ * documents for the search backend.
28
+ *
29
+ * @public
30
+ */
31
+ declare const catalogCollatorExtensionPoint: _backstage_backend_plugin_api.ExtensionPoint<CatalogCollatorExtensionPoint>;
32
+ /**
33
+ * Search backend module for the Catalog index.
34
+ *
35
+ * @public
36
+ */
37
+ declare const _default: _backstage_backend_plugin_api.BackendFeature;
11
38
 
12
39
  /** @public */
13
40
  type CatalogCollatorEntityTransformer = (entity: Entity) => Omit<CatalogEntityDocument, 'location' | 'authorization'>;
@@ -63,4 +90,4 @@ declare class DefaultCatalogCollatorFactory implements DocumentCollatorFactory {
63
90
  /** @public */
64
91
  declare const defaultCatalogCollatorEntityTransformer: CatalogCollatorEntityTransformer;
65
92
 
66
- export { type CatalogCollatorEntityTransformer, DefaultCatalogCollatorFactory, type DefaultCatalogCollatorFactoryOptions, defaultCatalogCollatorEntityTransformer };
93
+ export { type CatalogCollatorEntityTransformer, type CatalogCollatorExtensionPoint, DefaultCatalogCollatorFactory, type DefaultCatalogCollatorFactoryOptions, catalogCollatorExtensionPoint, _default as default, defaultCatalogCollatorEntityTransformer };
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var backendPluginApi = require('@backstage/backend-plugin-api');
6
+ var alpha$1 = require('@backstage/plugin-catalog-node/alpha');
7
+ var pluginSearchBackendModuleCatalog = require('@backstage/plugin-search-backend-module-catalog');
8
+ var alpha = require('@backstage/plugin-search-backend-node/alpha');
9
+ var config = require('./collators/config.cjs.js');
10
+
11
+ const catalogCollatorExtensionPoint = backendPluginApi.createExtensionPoint({
12
+ id: "search.catalogCollator.extension"
13
+ });
14
+ var feature = backendPluginApi.createBackendModule({
15
+ pluginId: "search",
16
+ moduleId: "catalog-collator",
17
+ register(env) {
18
+ let entityTransformer;
19
+ env.registerExtensionPoint(catalogCollatorExtensionPoint, {
20
+ setEntityTransformer(transformer) {
21
+ if (entityTransformer) {
22
+ throw new Error("setEntityTransformer can only be called once");
23
+ }
24
+ entityTransformer = transformer;
25
+ }
26
+ });
27
+ env.registerInit({
28
+ deps: {
29
+ auth: backendPluginApi.coreServices.auth,
30
+ config: backendPluginApi.coreServices.rootConfig,
31
+ discovery: backendPluginApi.coreServices.discovery,
32
+ scheduler: backendPluginApi.coreServices.scheduler,
33
+ indexRegistry: alpha.searchIndexRegistryExtensionPoint,
34
+ catalog: alpha$1.catalogServiceRef
35
+ },
36
+ async init({
37
+ auth,
38
+ config: config$1,
39
+ discovery,
40
+ scheduler,
41
+ indexRegistry,
42
+ catalog
43
+ }) {
44
+ indexRegistry.addCollator({
45
+ schedule: scheduler.createScheduledTaskRunner(
46
+ config.readScheduleConfigOptions(config$1)
47
+ ),
48
+ factory: pluginSearchBackendModuleCatalog.DefaultCatalogCollatorFactory.fromConfig(config$1, {
49
+ auth,
50
+ entityTransformer,
51
+ discovery,
52
+ catalogClient: catalog
53
+ })
54
+ });
55
+ }
56
+ });
57
+ }
58
+ });
59
+
60
+ exports.catalogCollatorExtensionPoint = catalogCollatorExtensionPoint;
61
+ exports.default = feature;
62
+ //# sourceMappingURL=module.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * @packageDocumentation\n * A module for the search backend that exports Catalog modules.\n */\n\nimport {\n coreServices,\n createBackendModule,\n createExtensionPoint,\n} from '@backstage/backend-plugin-api';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha';\nimport {\n CatalogCollatorEntityTransformer,\n DefaultCatalogCollatorFactory,\n} from '@backstage/plugin-search-backend-module-catalog';\nimport { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha';\nimport { readScheduleConfigOptions } from './collators/config';\n\n/**\n * Options for {@link catalogCollatorExtensionPoint}.\n *\n * @public\n */\nexport type CatalogCollatorExtensionPoint = {\n /**\n * Allows you to customize how entities are shaped into documents.\n */\n setEntityTransformer(transformer: CatalogCollatorEntityTransformer): void;\n};\n\n/**\n * Extension point for customizing how catalog entities are shaped into\n * documents for the search backend.\n *\n * @public\n */\nexport const catalogCollatorExtensionPoint =\n createExtensionPoint<CatalogCollatorExtensionPoint>({\n id: 'search.catalogCollator.extension',\n });\n\n/**\n * Search backend module for the Catalog index.\n *\n * @public\n */\nexport default createBackendModule({\n pluginId: 'search',\n moduleId: 'catalog-collator',\n register(env) {\n let entityTransformer: CatalogCollatorEntityTransformer | undefined;\n\n env.registerExtensionPoint(catalogCollatorExtensionPoint, {\n setEntityTransformer(transformer) {\n if (entityTransformer) {\n throw new Error('setEntityTransformer can only be called once');\n }\n entityTransformer = transformer;\n },\n });\n\n env.registerInit({\n deps: {\n auth: coreServices.auth,\n config: coreServices.rootConfig,\n discovery: coreServices.discovery,\n scheduler: coreServices.scheduler,\n indexRegistry: searchIndexRegistryExtensionPoint,\n catalog: catalogServiceRef,\n },\n async init({\n auth,\n config,\n discovery,\n scheduler,\n indexRegistry,\n catalog,\n }) {\n indexRegistry.addCollator({\n schedule: scheduler.createScheduledTaskRunner(\n readScheduleConfigOptions(config),\n ),\n factory: DefaultCatalogCollatorFactory.fromConfig(config, {\n auth,\n entityTransformer,\n discovery,\n catalogClient: catalog,\n }),\n });\n },\n });\n },\n});\n"],"names":["createExtensionPoint","createBackendModule","coreServices","searchIndexRegistryExtensionPoint","catalogServiceRef","config","readScheduleConfigOptions","DefaultCatalogCollatorFactory"],"mappings":";;;;;;;;;;AAoDO,MAAM,gCACXA,qCAAoD,CAAA;AAAA,EAClD,EAAI,EAAA,kCAAA;AACN,CAAC,EAAA;AAOH,cAAeC,oCAAoB,CAAA;AAAA,EACjC,QAAU,EAAA,QAAA;AAAA,EACV,QAAU,EAAA,kBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAI,IAAA,iBAAA,CAAA;AAEJ,IAAA,GAAA,CAAI,uBAAuB,6BAA+B,EAAA;AAAA,MACxD,qBAAqB,WAAa,EAAA;AAChC,QAAA,IAAI,iBAAmB,EAAA;AACrB,UAAM,MAAA,IAAI,MAAM,8CAA8C,CAAA,CAAA;AAAA,SAChE;AACA,QAAoB,iBAAA,GAAA,WAAA,CAAA;AAAA,OACtB;AAAA,KACD,CAAA,CAAA;AAED,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,MAAMC,6BAAa,CAAA,IAAA;AAAA,QACnB,QAAQA,6BAAa,CAAA,UAAA;AAAA,QACrB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,aAAe,EAAAC,uCAAA;AAAA,QACf,OAAS,EAAAC,yBAAA;AAAA,OACX;AAAA,MACA,MAAM,IAAK,CAAA;AAAA,QACT,IAAA;AAAA,gBACAC,QAAA;AAAA,QACA,SAAA;AAAA,QACA,SAAA;AAAA,QACA,aAAA;AAAA,QACA,OAAA;AAAA,OACC,EAAA;AACD,QAAA,aAAA,CAAc,WAAY,CAAA;AAAA,UACxB,UAAU,SAAU,CAAA,yBAAA;AAAA,YAClBC,iCAA0BD,QAAM,CAAA;AAAA,WAClC;AAAA,UACA,OAAA,EAASE,8DAA8B,CAAA,UAAA,CAAWF,QAAQ,EAAA;AAAA,YACxD,IAAA;AAAA,YACA,iBAAA;AAAA,YACA,SAAA;AAAA,YACA,aAAe,EAAA,OAAA;AAAA,WAChB,CAAA;AAAA,SACF,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC,CAAA;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-search-backend-module-catalog",
3
- "version": "0.2.3-next.1",
3
+ "version": "0.2.3",
4
4
  "description": "A module for the search backend that exports catalog modules",
5
5
  "backstage": {
6
6
  "role": "backend-plugin-module",
@@ -19,6 +19,7 @@
19
19
  "license": "Apache-2.0",
20
20
  "exports": {
21
21
  ".": {
22
+ "backstage": "@backstage/BackendFeature",
22
23
  "require": "./dist/index.cjs.js",
23
24
  "types": "./dist/index.d.ts",
24
25
  "default": "./dist/index.cjs.js"
@@ -49,21 +50,21 @@
49
50
  },
50
51
  "dependencies": {
51
52
  "@backstage/backend-common": "^0.25.0",
52
- "@backstage/backend-plugin-api": "1.0.1-next.0",
53
- "@backstage/catalog-client": "1.7.0",
54
- "@backstage/catalog-model": "1.7.0",
55
- "@backstage/config": "1.2.0",
56
- "@backstage/errors": "1.2.4",
57
- "@backstage/plugin-catalog-common": "1.1.0",
58
- "@backstage/plugin-catalog-node": "1.13.1-next.0",
59
- "@backstage/plugin-permission-common": "0.8.1",
60
- "@backstage/plugin-search-backend-node": "1.3.3-next.1",
61
- "@backstage/plugin-search-common": "1.2.14"
53
+ "@backstage/backend-plugin-api": "^1.0.1",
54
+ "@backstage/catalog-client": "^1.7.1",
55
+ "@backstage/catalog-model": "^1.7.0",
56
+ "@backstage/config": "^1.2.0",
57
+ "@backstage/errors": "^1.2.4",
58
+ "@backstage/plugin-catalog-common": "^1.1.0",
59
+ "@backstage/plugin-catalog-node": "^1.13.1",
60
+ "@backstage/plugin-permission-common": "^0.8.1",
61
+ "@backstage/plugin-search-backend-node": "^1.3.3",
62
+ "@backstage/plugin-search-common": "^1.2.14"
62
63
  },
63
64
  "devDependencies": {
64
65
  "@backstage/backend-common": "^0.25.0",
65
- "@backstage/backend-test-utils": "1.0.1-next.1",
66
- "@backstage/cli": "0.28.0-next.1",
66
+ "@backstage/backend-test-utils": "^1.0.1",
67
+ "@backstage/cli": "^0.28.0",
67
68
  "msw": "^1.0.0"
68
69
  },
69
70
  "configSchema": "config.d.ts"
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-BgngnqUm.cjs.js","sources":["../../src/collators/config.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 SchedulerServiceTaskScheduleDefinition,\n readSchedulerServiceTaskScheduleDefinitionFromConfig,\n} from '@backstage/backend-plugin-api';\nimport { EntityFilterQuery } from '@backstage/catalog-client';\nimport { Config } from '@backstage/config';\nimport { InputError } from '@backstage/errors';\n\nconst configKey = 'search.collators.catalog';\n\nexport const defaults = {\n schedule: {\n frequency: { minutes: 10 },\n timeout: { minutes: 15 },\n initialDelay: { seconds: 3 },\n },\n collatorOptions: {\n locationTemplate: '/catalog/:namespace/:kind/:name',\n filter: undefined,\n batchSize: 500,\n },\n};\n\nexport function readScheduleConfigOptions(\n configRoot: Config,\n): SchedulerServiceTaskScheduleDefinition {\n let schedule: SchedulerServiceTaskScheduleDefinition | undefined = undefined;\n\n const config = configRoot.getOptionalConfig(configKey);\n if (config) {\n const scheduleConfig = config.getOptionalConfig('schedule');\n if (scheduleConfig) {\n try {\n schedule =\n readSchedulerServiceTaskScheduleDefinitionFromConfig(scheduleConfig);\n } catch (error) {\n throw new InputError(`Invalid schedule at ${configKey}, ${error}`);\n }\n }\n }\n\n return schedule ?? defaults.schedule;\n}\n\nexport function readCollatorConfigOptions(configRoot: Config): {\n locationTemplate: string;\n filter: EntityFilterQuery | undefined;\n batchSize: number;\n} {\n const config = configRoot.getOptionalConfig(configKey);\n if (!config) {\n return defaults.collatorOptions;\n }\n\n return {\n locationTemplate:\n config.getOptionalString('locationTemplate') ??\n defaults.collatorOptions.locationTemplate,\n filter:\n config.getOptionalConfig('filter')?.get<EntityFilterQuery>() ??\n defaults.collatorOptions.filter,\n batchSize:\n config.getOptionalNumber('batchSize') ??\n defaults.collatorOptions.batchSize,\n };\n}\n"],"names":["readSchedulerServiceTaskScheduleDefinitionFromConfig","InputError"],"mappings":";;;;;AAwBA,MAAM,SAAY,GAAA,0BAAA,CAAA;AAEX,MAAM,QAAW,GAAA;AAAA,EACtB,QAAU,EAAA;AAAA,IACR,SAAA,EAAW,EAAE,OAAA,EAAS,EAAG,EAAA;AAAA,IACzB,OAAA,EAAS,EAAE,OAAA,EAAS,EAAG,EAAA;AAAA,IACvB,YAAA,EAAc,EAAE,OAAA,EAAS,CAAE,EAAA;AAAA,GAC7B;AAAA,EACA,eAAiB,EAAA;AAAA,IACf,gBAAkB,EAAA,iCAAA;AAAA,IAClB,MAAQ,EAAA,KAAA,CAAA;AAAA,IACR,SAAW,EAAA,GAAA;AAAA,GACb;AACF,CAAA,CAAA;AAEO,SAAS,0BACd,UACwC,EAAA;AACxC,EAAA,IAAI,QAA+D,GAAA,KAAA,CAAA,CAAA;AAEnE,EAAM,MAAA,MAAA,GAAS,UAAW,CAAA,iBAAA,CAAkB,SAAS,CAAA,CAAA;AACrD,EAAA,IAAI,MAAQ,EAAA;AACV,IAAM,MAAA,cAAA,GAAiB,MAAO,CAAA,iBAAA,CAAkB,UAAU,CAAA,CAAA;AAC1D,IAAA,IAAI,cAAgB,EAAA;AAClB,MAAI,IAAA;AACF,QAAA,QAAA,GACEA,sEAAqD,cAAc,CAAA,CAAA;AAAA,eAC9D,KAAO,EAAA;AACd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