@backstage/plugin-catalog-backend 1.2.1-next.0 → 1.3.0-next.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,91 @@
1
1
  # @backstage/plugin-catalog-backend
2
2
 
3
+ ## 1.3.0-next.3
4
+
5
+ ### Minor Changes
6
+
7
+ - 1dd6c22cc8: Added an option to be able to trigger refreshes on entities based on a prestored arbitrary key.
8
+
9
+ The UrlReaderProcessor, FileReaderProcessor got updated to store the absolute URL of the catalog file as a refresh key. In the format of `<type>:<target>`
10
+ The PlaceholderProcessor got updated to store the resolverValues as refreshKeys for the entities.
11
+
12
+ The custom resolvers will need to be updated to pass in a `CatalogProcessorEmit` function as parameter and they should be updated to emit their refresh processingResults. You can see the updated resolvers in the `PlaceholderProcessor.ts`
13
+
14
+ ```ts
15
+ // yamlPlaceholderResolver
16
+ ...
17
+ const { content, url } = await readTextLocation(params);
18
+
19
+ params.emit(processingResult.refresh(`url:${url}`));
20
+ ...
21
+ ```
22
+
23
+ - 91c1d12123: Export experimental `catalogPlugin` for the new backend system. This export is not considered stable and should not be used in production.
24
+
25
+ ### Patch Changes
26
+
27
+ - 1e02fe46d6: Fixed bug where catalog metrics weren't being tracked.
28
+ - 5f6b847c15: Fix Error Code in Register Component DryRun
29
+ - a70869e775: Updated dependency `msw` to `^0.43.0`.
30
+ - 4e9a90e307: Updated dependency `luxon` to `^3.0.0`.
31
+ - 72622d9143: Updated dependency `yaml` to `^2.0.0`.
32
+ - fa0533e604: CatalogBuilder supports now subscription to processing engine errors.
33
+
34
+ ```ts
35
+ subscribe(options: {
36
+ onProcessingError: (event: { unprocessedEntity: Entity, error: Error }) => Promise<void> | void;
37
+ });
38
+ ```
39
+
40
+ If you want to get notified on errors while processing the entities, you call CatalogBuilder.subscribe
41
+ to get notifications with the parameters defined as above.
42
+
43
+ - 9a6aba1d85: Many symbol declarations have been moved to `@backstage/plugin-catalog-node`. This has no affect on users of this package as they are all re-exported. Modules that build on top of the catalog backend plugin should switch all of their imports to the `@backstage/plugin-catalog-node` package and remove the dependency on `@backstage/plugin-catalog-backend`.
44
+ - Updated dependencies
45
+ - @backstage/backend-plugin-api@0.1.0-next.0
46
+ - @backstage/plugin-catalog-node@1.0.0-next.0
47
+ - @backstage/backend-common@0.14.1-next.3
48
+ - @backstage/catalog-client@1.0.4-next.2
49
+ - @backstage/integration@1.2.2-next.3
50
+ - @backstage/plugin-permission-common@0.6.3-next.1
51
+ - @backstage/plugin-permission-node@0.6.3-next.2
52
+ - @backstage/catalog-model@1.1.0-next.3
53
+
54
+ ## 1.2.1-next.2
55
+
56
+ ### Patch Changes
57
+
58
+ - 679b32172e: Updated dependency `knex` to `^2.0.0`.
59
+ - e2d7b76f43: Upgrade git-url-parse to 12.0.0.
60
+
61
+ Motivation for upgrade is transitively upgrading parse-url which is vulnerable
62
+ to several CVEs detected by Snyk.
63
+
64
+ - SNYK-JS-PARSEURL-2935944
65
+ - SNYK-JS-PARSEURL-2935947
66
+ - SNYK-JS-PARSEURL-2936249
67
+
68
+ - Updated dependencies
69
+ - @backstage/catalog-model@1.1.0-next.2
70
+ - @backstage/backend-common@0.14.1-next.2
71
+ - @backstage/integration@1.2.2-next.2
72
+
73
+ ## 1.2.1-next.1
74
+
75
+ ### Patch Changes
76
+
77
+ - f1dcc6f3c6: Use entity type predicates from catalog-model
78
+ - Updated dependencies
79
+ - @backstage/catalog-model@1.1.0-next.1
80
+ - @backstage/backend-common@0.14.1-next.1
81
+ - @backstage/errors@1.1.0-next.0
82
+ - @backstage/catalog-client@1.0.4-next.1
83
+ - @backstage/integration@1.2.2-next.1
84
+ - @backstage/plugin-catalog-common@1.0.4-next.0
85
+ - @backstage/plugin-permission-common@0.6.3-next.0
86
+ - @backstage/plugin-permission-node@0.6.3-next.1
87
+ - @backstage/plugin-search-common@0.3.6-next.0
88
+
3
89
  ## 1.2.1-next.0
4
90
 
5
91
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend",
3
- "version": "1.2.1-next.0",
3
+ "version": "1.3.0-next.3",
4
4
  "main": "../dist/index.cjs.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -6,18 +6,34 @@
6
6
 
7
7
  /// <reference types="node" />
8
8
 
9
+ import { BackendRegistrable } from '@backstage/backend-plugin-api';
9
10
  import { CatalogApi } from '@backstage/catalog-client';
10
11
  import { CatalogEntityDocument } from '@backstage/plugin-catalog-common';
11
- import { CompoundEntityRef } from '@backstage/catalog-model';
12
+ import { CatalogProcessor } from '@backstage/plugin-catalog-node';
13
+ import { CatalogProcessorCache } from '@backstage/plugin-catalog-node';
14
+ import { CatalogProcessorEmit } from '@backstage/plugin-catalog-node';
15
+ import { CatalogProcessorEntityResult } from '@backstage/plugin-catalog-node';
16
+ import { CatalogProcessorErrorResult } from '@backstage/plugin-catalog-node';
17
+ import { CatalogProcessorLocationResult } from '@backstage/plugin-catalog-node';
18
+ import { CatalogProcessorParser } from '@backstage/plugin-catalog-node';
19
+ import { CatalogProcessorRefreshKeysResult } from '@backstage/plugin-catalog-node';
20
+ import { CatalogProcessorRelationResult } from '@backstage/plugin-catalog-node';
21
+ import { CatalogProcessorResult } from '@backstage/plugin-catalog-node';
12
22
  import { ConditionalPolicyDecision } from '@backstage/plugin-permission-common';
13
23
  import { Conditions } from '@backstage/plugin-permission-node';
14
24
  import { Config } from '@backstage/config';
25
+ import { DeferredEntity } from '@backstage/plugin-catalog-node';
15
26
  import { DocumentCollatorFactory } from '@backstage/plugin-search-common';
16
27
  import { Entity } from '@backstage/catalog-model';
17
28
  import { EntityPolicy } from '@backstage/catalog-model';
29
+ import { EntityProvider } from '@backstage/plugin-catalog-node';
30
+ import { EntityProviderConnection } from '@backstage/plugin-catalog-node';
31
+ import { EntityProviderMutation } from '@backstage/plugin-catalog-node';
32
+ import { EntityRelationSpec } from '@backstage/plugin-catalog-node';
18
33
  import { GetEntitiesRequest } from '@backstage/catalog-client';
19
34
  import { JsonValue } from '@backstage/types';
20
35
  import { LocationEntityV1alpha1 } from '@backstage/catalog-model';
36
+ import { LocationSpec } from '@backstage/plugin-catalog-node';
21
37
  import { Logger } from 'winston';
22
38
  import { Permission } from '@backstage/plugin-permission-common';
23
39
  import { PermissionAuthorizer } from '@backstage/plugin-permission-common';
@@ -27,6 +43,7 @@ import { PermissionEvaluator } from '@backstage/plugin-permission-common';
27
43
  import { PermissionRule } from '@backstage/plugin-permission-node';
28
44
  import { PluginDatabaseManager } from '@backstage/backend-common';
29
45
  import { PluginEndpointDiscovery } from '@backstage/backend-common';
46
+ import { processingResult } from '@backstage/plugin-catalog-node';
30
47
  import { Readable } from 'stream';
31
48
  import { ResourcePermission } from '@backstage/plugin-permission-common';
32
49
  import { Router } from 'express';
@@ -151,6 +168,7 @@ export declare class CatalogBuilder {
151
168
  private processors;
152
169
  private processorsReplace;
153
170
  private parser;
171
+ private onProcessingError?;
154
172
  private processingInterval;
155
173
  private locationAnalyzer;
156
174
  private permissionRules;
@@ -282,6 +300,12 @@ export declare class CatalogBuilder {
282
300
  processingEngine: CatalogProcessingEngine;
283
301
  router: Router;
284
302
  }>;
303
+ subscribe(options: {
304
+ onProcessingError: (event: {
305
+ unprocessedEntity: Entity;
306
+ errors: Error[];
307
+ }) => Promise<void> | void;
308
+ }): void;
285
309
  private buildEntityPolicy;
286
310
  private buildProcessors;
287
311
  private checkDeprecatedReaderProcessors;
@@ -321,143 +345,37 @@ export declare type CatalogEnvironment = {
321
345
  */
322
346
  export declare type CatalogPermissionRule<TParams extends unknown[] = unknown[]> = PermissionRule<Entity, EntitiesSearchFilter, 'catalog-entity', TParams>;
323
347
 
348
+ /**
349
+ * Catalog plugin
350
+ * @alpha
351
+ */
352
+ export declare const catalogPlugin: (option: unknown) => BackendRegistrable;
353
+
324
354
  /** @public */
325
355
  export declare interface CatalogProcessingEngine {
326
356
  start(): Promise<void>;
327
357
  stop(): Promise<void>;
328
358
  }
329
359
 
330
- /**
331
- * @public
332
- */
333
- export declare type CatalogProcessor = {
334
- /**
335
- * A unique identifier for the Catalog Processor.
336
- */
337
- getProcessorName(): string;
338
- /**
339
- * Reads the contents of a location.
340
- *
341
- * @param location - The location to read
342
- * @param optional - Whether a missing target should trigger an error
343
- * @param emit - A sink for items resulting from the read
344
- * @param parser - A parser, that is able to take the raw catalog descriptor
345
- * data and turn it into the actual result pieces.
346
- * @param cache - A cache for storing values local to this processor and the current entity.
347
- * @returns True if handled by this processor, false otherwise
348
- */
349
- readLocation?(location: LocationSpec, optional: boolean, emit: CatalogProcessorEmit, parser: CatalogProcessorParser, cache: CatalogProcessorCache): Promise<boolean>;
350
- /**
351
- * Pre-processes an emitted entity, after it has been emitted but before it
352
- * has been validated.
353
- *
354
- * This type of processing usually involves enriching the entity with
355
- * additional data, and the input entity may actually still be incomplete
356
- * when the processor is invoked.
357
- *
358
- * @param entity - The (possibly partial) entity to process
359
- * @param location - The location that the entity came from
360
- * @param emit - A sink for auxiliary items resulting from the processing
361
- * @param originLocation - The location that the entity originally came from.
362
- * While location resolves to the direct parent location, originLocation
363
- * tells which location was used to start the ingestion loop.
364
- * @param cache - A cache for storing values local to this processor and the current entity.
365
- * @returns The same entity or a modified version of it
366
- */
367
- preProcessEntity?(entity: Entity, location: LocationSpec, emit: CatalogProcessorEmit, originLocation: LocationSpec, cache: CatalogProcessorCache): Promise<Entity>;
368
- /**
369
- * Validates the entity as a known entity kind, after it has been pre-
370
- * processed and has passed through basic overall validation.
371
- *
372
- * @param entity - The entity to validate
373
- * @returns Resolves to true, if the entity was of a kind that was known and
374
- * handled by this processor, and was found to be valid. Resolves to false,
375
- * if the entity was not of a kind that was known by this processor.
376
- * Rejects to an Error describing the problem, if the entity was of a kind
377
- * that was known by this processor and was not valid.
378
- */
379
- validateEntityKind?(entity: Entity): Promise<boolean>;
380
- /**
381
- * Post-processes an emitted entity, after it has been validated.
382
- *
383
- * @param entity - The entity to process
384
- * @param location - The location that the entity came from
385
- * @param emit - A sink for auxiliary items resulting from the processing
386
- * @param cache - A cache for storing values local to this processor and the current entity.
387
- * @returns The same entity or a modified version of it
388
- */
389
- postProcessEntity?(entity: Entity, location: LocationSpec, emit: CatalogProcessorEmit, cache: CatalogProcessorCache): Promise<Entity>;
390
- };
360
+ export { CatalogProcessor }
391
361
 
392
- /**
393
- * A cache for storing data during processing.
394
- *
395
- * The values stored in the cache are always local to each processor, meaning
396
- * no processor can see cache values from other processors.
397
- *
398
- * The cache instance provided to the CatalogProcessor is also scoped to the
399
- * entity being processed, meaning that each processor run can't see cache
400
- * values from processing runs for other entities.
401
- *
402
- * Values that are set during a processing run will only be visible in the directly
403
- * following run. The cache will be overwritten every run unless no new cache items
404
- * are written, in which case the existing values remain in the cache.
405
- *
406
- * @public
407
- */
408
- export declare interface CatalogProcessorCache {
409
- /**
410
- * Retrieve a value from the cache.
411
- */
412
- get<ItemType extends JsonValue>(key: string): Promise<ItemType | undefined>;
413
- /**
414
- * Store a value in the cache.
415
- */
416
- set<ItemType extends JsonValue>(key: string, value: ItemType): Promise<void>;
417
- }
362
+ export { CatalogProcessorCache }
418
363
 
419
- /** @public */
420
- export declare type CatalogProcessorEmit = (generated: CatalogProcessorResult) => void;
364
+ export { CatalogProcessorEmit }
421
365
 
422
- /** @public */
423
- export declare type CatalogProcessorEntityResult = {
424
- type: 'entity';
425
- entity: Entity;
426
- location: LocationSpec;
427
- };
366
+ export { CatalogProcessorEntityResult }
428
367
 
429
- /** @public */
430
- export declare type CatalogProcessorErrorResult = {
431
- type: 'error';
432
- error: Error;
433
- location: LocationSpec;
434
- };
368
+ export { CatalogProcessorErrorResult }
435
369
 
436
- /** @public */
437
- export declare type CatalogProcessorLocationResult = {
438
- type: 'location';
439
- location: LocationSpec;
440
- };
370
+ export { CatalogProcessorLocationResult }
441
371
 
442
- /**
443
- * A parser, that is able to take the raw catalog descriptor data and turn it
444
- * into the actual result pieces. The default implementation performs a YAML
445
- * document parsing.
446
- * @public
447
- */
448
- export declare type CatalogProcessorParser = (options: {
449
- data: Buffer;
450
- location: LocationSpec;
451
- }) => AsyncIterable<CatalogProcessorResult>;
372
+ export { CatalogProcessorParser }
452
373
 
453
- /** @public */
454
- export declare type CatalogProcessorRelationResult = {
455
- type: 'relation';
456
- relation: EntityRelationSpec;
457
- };
374
+ export { CatalogProcessorRefreshKeysResult }
458
375
 
459
- /** @public */
460
- export declare type CatalogProcessorResult = CatalogProcessorLocationResult | CatalogProcessorEntityResult | CatalogProcessorRelationResult | CatalogProcessorErrorResult;
376
+ export { CatalogProcessorRelationResult }
377
+
378
+ export { CatalogProcessorResult }
461
379
 
462
380
  /** @public */
463
381
  export declare class CodeOwnersProcessor implements CatalogProcessor {
@@ -555,7 +473,6 @@ export declare class DefaultCatalogCollator {
555
473
  catalogClient?: CatalogApi;
556
474
  });
557
475
  protected applyArgsToFormat(format: string, args: Record<string, string>): string;
558
- private isUserEntity;
559
476
  private getDocumentText;
560
477
  execute(): Promise<CatalogEntityDocument[]>;
561
478
  }
@@ -586,14 +503,7 @@ export declare type DefaultCatalogCollatorFactoryOptions = {
586
503
  catalogClient?: CatalogApi;
587
504
  };
588
505
 
589
- /**
590
- * Entities that are not yet processed.
591
- * @public
592
- */
593
- export declare type DeferredEntity = {
594
- entity: Entity;
595
- locationKey?: string;
596
- };
506
+ export { DeferredEntity }
597
507
 
598
508
  /**
599
509
  * Matches rows in the search table.
@@ -630,64 +540,13 @@ export declare type EntityFilter = {
630
540
  not: EntityFilter;
631
541
  } | EntitiesSearchFilter;
632
542
 
633
- /**
634
- * An EntityProvider is able to provide entities to the catalog.
635
- * See https://backstage.io/docs/features/software-catalog/life-of-an-entity for more details.
636
- * @public
637
- */
638
- export declare interface EntityProvider {
639
- /** Unique provider name used internally for caching. */
640
- getProviderName(): string;
641
- /** Connect is called upon initialization by the catalog engine. */
642
- connect(connection: EntityProviderConnection): Promise<void>;
643
- }
543
+ export { EntityProvider }
644
544
 
645
- /**
646
- * The EntityProviderConnection is the connection between the catalog and the entity provider.
647
- * The EntityProvider use this connection to add and remove entities from the catalog.
648
- * @public
649
- */
650
- export declare interface EntityProviderConnection {
651
- /**
652
- * Applies either a full or delta update to the catalog engine.
653
- */
654
- applyMutation(mutation: EntityProviderMutation): Promise<void>;
655
- }
545
+ export { EntityProviderConnection }
656
546
 
657
- /**
658
- * @public
659
- * A 'full' mutation replaces all existing entities created by this entity provider with new ones.
660
- * A 'delta' mutation can both add and remove entities provided by this provider. Previously provided
661
- * entities from a 'full' mutation are not removed.
662
- */
663
- export declare type EntityProviderMutation = {
664
- type: 'full';
665
- entities: DeferredEntity[];
666
- } | {
667
- type: 'delta';
668
- added: DeferredEntity[];
669
- removed: DeferredEntity[];
670
- };
547
+ export { EntityProviderMutation }
671
548
 
672
- /**
673
- * Holds the relation data for entities.
674
- *
675
- * @public
676
- */
677
- export declare type EntityRelationSpec = {
678
- /**
679
- * The source entity of this relation.
680
- */
681
- source: CompoundEntityRef;
682
- /**
683
- * The type of the relation.
684
- */
685
- type: string;
686
- /**
687
- * The target entity of this relation.
688
- */
689
- target: CompoundEntityRef;
690
- };
549
+ export { EntityRelationSpec }
691
550
 
692
551
  /** @public */
693
552
  export declare class FileReaderProcessor implements CatalogProcessor {
@@ -719,22 +578,7 @@ export declare type LocationEntityProcessorOptions = {
719
578
  integrations: ScmIntegrationRegistry;
720
579
  };
721
580
 
722
- /**
723
- * Holds the entity location information.
724
- *
725
- * @remarks
726
- *
727
- * `presence` flag: when using repo importer plugin, location is being created before the component yaml file is merged to the main branch.
728
- * This flag is then set to indicate that the file can be not present.
729
- * default value: 'required'.
730
- *
731
- * @public
732
- */
733
- export declare type LocationSpec = {
734
- type: string;
735
- target: string;
736
- presence?: 'optional' | 'required';
737
- };
581
+ export { LocationSpec }
738
582
 
739
583
  /** @public */
740
584
  export declare function locationSpecToLocationEntity(opts: {
@@ -769,7 +613,7 @@ export declare class PlaceholderProcessor implements CatalogProcessor {
769
613
  private readonly options;
770
614
  constructor(options: PlaceholderProcessorOptions);
771
615
  getProcessorName(): string;
772
- preProcessEntity(entity: Entity, location: LocationSpec): Promise<Entity>;
616
+ preProcessEntity(entity: Entity, location: LocationSpec, emit: CatalogProcessorEmit): Promise<Entity>;
773
617
  }
774
618
 
775
619
  /** @public */
@@ -789,6 +633,7 @@ export declare type PlaceholderResolverParams = {
789
633
  baseUrl: string;
790
634
  read: PlaceholderResolverRead;
791
635
  resolveUrl: PlaceholderResolverResolveUrl;
636
+ emit: CatalogProcessorEmit;
792
637
  };
793
638
 
794
639
  /** @public */
@@ -803,19 +648,7 @@ export declare type PlaceholderResolverResolveUrl = (url: string, base: string)
803
648
  */
804
649
  export declare type ProcessingIntervalFunction = () => number;
805
650
 
806
- /**
807
- * Factory functions for the standard processing result types.
808
- *
809
- * @public
810
- */
811
- export declare const processingResult: Readonly<{
812
- readonly notFoundError: (atLocation: LocationSpec, message: string) => CatalogProcessorResult;
813
- readonly inputError: (atLocation: LocationSpec, message: string) => CatalogProcessorResult;
814
- readonly generalError: (atLocation: LocationSpec, message: string) => CatalogProcessorResult;
815
- readonly location: (newLocation: LocationSpec) => CatalogProcessorResult;
816
- readonly entity: (atLocation: LocationSpec, newEntity: Entity) => CatalogProcessorResult;
817
- readonly relation: (spec: EntityRelationSpec) => CatalogProcessorResult;
818
- }>;
651
+ export { processingResult }
819
652
 
820
653
  /**
821
654
  * Makes all keys of an entire hierarchy optional.