@backstage/plugin-search-backend-module-catalog 0.1.24-next.1 → 0.1.24
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 +27 -0
- package/README.md +2 -2
- package/alpha/package.json +1 -1
- package/dist/index.cjs.js +0 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @backstage/plugin-search-backend-module-catalog
|
|
2
2
|
|
|
3
|
+
## 0.1.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b192752: Updated `README.md` to point to `packages/backend` instead of `packages/backend-next`.
|
|
8
|
+
- d5fff66: Fix wiring of the module exported at the `/alpha` path, which was causing authentication failures.
|
|
9
|
+
- 5dc5f4f: Allow the `tokenManager` parameter to be optional when instantiating collator
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
- @backstage/plugin-catalog-node@1.12.0
|
|
12
|
+
- @backstage/catalog-model@1.5.0
|
|
13
|
+
- @backstage/backend-common@0.22.0
|
|
14
|
+
- @backstage/backend-plugin-api@0.6.18
|
|
15
|
+
- @backstage/backend-tasks@0.5.23
|
|
16
|
+
- @backstage/plugin-search-backend-node@1.2.22
|
|
17
|
+
- @backstage/catalog-client@1.6.5
|
|
18
|
+
- @backstage/plugin-catalog-common@1.0.23
|
|
19
|
+
|
|
20
|
+
## 0.1.24-next.2
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- b192752: Updated `README.md` to point to `packages/backend` instead of `packages/backend-next`.
|
|
25
|
+
- 5dc5f4f: Allow the `tokenManager` parameter to be optional when instantiating collator
|
|
26
|
+
- Updated dependencies
|
|
27
|
+
- @backstage/plugin-catalog-node@1.12.0-next.2
|
|
28
|
+
- @backstage/backend-common@0.22.0-next.2
|
|
29
|
+
|
|
3
30
|
## 0.1.24-next.1
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ yarn --cwd packages/backend add @backstage/plugin-search-backend-module-catalog
|
|
|
14
14
|
Add the collator to your backend instance, along with the search plugin itself:
|
|
15
15
|
|
|
16
16
|
```tsx
|
|
17
|
-
// packages/backend
|
|
17
|
+
// packages/backend/src/index.ts
|
|
18
18
|
import { createBackend } from '@backstage/backend-defaults';
|
|
19
19
|
import { searchPlugin } from '@backstage/plugin-search-backend/alpha';
|
|
20
20
|
import { searchModuleCatalogCollator } from '@backstage/plugin-search-backend-module-catalog/alpha';
|
|
@@ -32,7 +32,7 @@ You may also want to add configuration parameters to your app-config, for exampl
|
|
|
32
32
|
This module also has an extension point, which lets you inject advanced customizations. Here's an example of how to leverage that extension point to tweak the transformer used for building the search indexer documents:
|
|
33
33
|
|
|
34
34
|
```tsx
|
|
35
|
-
// packages/backend
|
|
35
|
+
// packages/backend/src/index.ts
|
|
36
36
|
import { createBackend } from '@backstage/backend-defaults';
|
|
37
37
|
import { createBackendModule } from '@backstage/backend-plugin-api';
|
|
38
38
|
import { searchPlugin } from '@backstage/plugin-search-backend/alpha';
|
package/alpha/package.json
CHANGED
package/dist/index.cjs.js
CHANGED
package/dist/index.cjs.js.map
CHANGED
|
@@ -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 PluginEndpointDiscovery,\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 } from '@backstage/backend-plugin-api';\n\n/** @public */\nexport type DefaultCatalogCollatorFactoryOptions = {\n auth?: AuthService;\n discovery: PluginEndpointDiscovery;\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 */\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 tokenManager: options.tokenManager,\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: PluginEndpointDiscovery;\n tokenManager: TokenManager;\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","catalogClient","CatalogClient","readCollatorConfigOptions","createLegacyAuthAdapters","Readable","stringifyEntityRef"],"mappings":";;;;;;;;;;;AAmBA,MAAM,eAAA,GAAkB,CAAC,MAA2B,KAAA;AAnBpD,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAoBE,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,IAAA,IAAA,CAAI,EAAO,GAAA,CAAA,EAAA,GAAA,MAAA,CAAA,IAAA,KAAP,IAAa,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAA,KAAb,mBAAsB,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,IAAA,IAAA,CAAI,EAAO,GAAA,CAAA,EAAA,GAAA,MAAA,CAAA,IAAA,KAAP,IAAa,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAA,KAAb,mBAAsB,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;AAxCtB,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,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AAA;AAGF,MAAoB,iBAAA,GAAA,QAAA,CAAS,WAAW,IAAK,CAAA,SAAA,CAAA;AAC7C,MAAA,iBAAA,IAAqB,QAAS,CAAA,MAAA,CAAA;AAE9B,MAAA,KAAA,MAAW,UAAU,QAAU,EAAA;AAC7B,QAAM,MAAA;AAAA,UACJ,GAAG,IAAK,CAAA,iBAAA,CAAkB,MAAM,CAAA;AAAA,UAChC,aAAe,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;;;;;"}
|
|
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 PluginEndpointDiscovery,\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 } from '@backstage/backend-plugin-api';\n\n/** @public */\nexport type DefaultCatalogCollatorFactoryOptions = {\n auth?: AuthService;\n discovery: PluginEndpointDiscovery;\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 */\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: PluginEndpointDiscovery;\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","catalogClient","CatalogClient","readCollatorConfigOptions","createLegacyAuthAdapters","Readable","stringifyEntityRef"],"mappings":";;;;;;;;;;;AAmBA,MAAM,eAAA,GAAkB,CAAC,MAA2B,KAAA;AAnBpD,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAoBE,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,IAAA,IAAA,CAAI,EAAO,GAAA,CAAA,EAAA,GAAA,MAAA,CAAA,IAAA,KAAP,IAAa,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAA,KAAb,mBAAsB,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,IAAA,IAAA,CAAI,EAAO,GAAA,CAAA,EAAA,GAAA,MAAA,CAAA,IAAA,KAAP,IAAa,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAA,KAAb,mBAAsB,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,MAA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iBAAA;AAAA,SACV;AAAA,QACA,EAAE,KAAM,EAAA;AAAA,OAEV,EAAA,KAAA,CAAA;AAGF,MAAoB,iBAAA,GAAA,QAAA,CAAS,WAAW,IAAK,CAAA,SAAA,CAAA;AAC7C,MAAA,iBAAA,IAAqB,QAAS,CAAA,MAAA,CAAA;AAE9B,MAAA,KAAA,MAAW,UAAU,QAAU,EAAA;AAC7B,QAAM,MAAA;AAAA,UACJ,GAAG,IAAK,CAAA,iBAAA,CAAkB,MAAM,CAAA;AAAA,UAChC,aAAe,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;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ type CatalogCollatorEntityTransformer = (entity: Entity) => Omit<CatalogEntityDo
|
|
|
16
16
|
type DefaultCatalogCollatorFactoryOptions = {
|
|
17
17
|
auth?: AuthService;
|
|
18
18
|
discovery: PluginEndpointDiscovery;
|
|
19
|
-
tokenManager
|
|
19
|
+
tokenManager?: TokenManager;
|
|
20
20
|
/**
|
|
21
21
|
* @deprecated Use the config key `search.collators.catalog.locationTemplate` instead.
|
|
22
22
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-search-backend-module-catalog",
|
|
3
|
-
"version": "0.1.24
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "A module for the search backend that exports catalog modules",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin-module"
|
|
@@ -45,23 +45,23 @@
|
|
|
45
45
|
"test": "backstage-cli package test"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@backstage/backend-common": "^0.22.0
|
|
49
|
-
"@backstage/backend-plugin-api": "^0.6.18
|
|
50
|
-
"@backstage/backend-tasks": "^0.5.23
|
|
51
|
-
"@backstage/catalog-client": "^1.6.5
|
|
52
|
-
"@backstage/catalog-model": "^1.5.0
|
|
48
|
+
"@backstage/backend-common": "^0.22.0",
|
|
49
|
+
"@backstage/backend-plugin-api": "^0.6.18",
|
|
50
|
+
"@backstage/backend-tasks": "^0.5.23",
|
|
51
|
+
"@backstage/catalog-client": "^1.6.5",
|
|
52
|
+
"@backstage/catalog-model": "^1.5.0",
|
|
53
53
|
"@backstage/config": "^1.2.0",
|
|
54
54
|
"@backstage/errors": "^1.2.4",
|
|
55
|
-
"@backstage/plugin-catalog-common": "^1.0.23
|
|
56
|
-
"@backstage/plugin-catalog-node": "^1.
|
|
55
|
+
"@backstage/plugin-catalog-common": "^1.0.23",
|
|
56
|
+
"@backstage/plugin-catalog-node": "^1.12.0",
|
|
57
57
|
"@backstage/plugin-permission-common": "^0.7.13",
|
|
58
|
-
"@backstage/plugin-search-backend-node": "^1.2.22
|
|
58
|
+
"@backstage/plugin-search-backend-node": "^1.2.22",
|
|
59
59
|
"@backstage/plugin-search-common": "^1.2.11"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@backstage/backend-common": "^0.22.0
|
|
63
|
-
"@backstage/backend-test-utils": "^0.3.8
|
|
64
|
-
"@backstage/cli": "^0.26.5
|
|
62
|
+
"@backstage/backend-common": "^0.22.0",
|
|
63
|
+
"@backstage/backend-test-utils": "^0.3.8",
|
|
64
|
+
"@backstage/cli": "^0.26.5",
|
|
65
65
|
"msw": "^1.0.0"
|
|
66
66
|
},
|
|
67
67
|
"configSchema": "config.d.ts"
|