@backstage/plugin-techdocs-node 0.0.0-nightly-20220305022735 → 0.0.0-nightly-20220308022132

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,15 +1,15 @@
1
1
  # @backstage/plugin-techdocs-node
2
2
 
3
- ## 0.0.0-nightly-20220305022735
3
+ ## 0.0.0-nightly-20220308022132
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - 3e54f6c436: Use `@backstage/plugin-search-common` package instead of `@backstage/search-common`.
8
8
  - cea6f10b97: Renamed `@backstage/techdocs-common` to `@backstage/plugin-techdocs-node`.
9
9
  - Updated dependencies
10
- - @backstage/catalog-model@0.0.0-nightly-20220305022735
11
- - @backstage/backend-common@0.0.0-nightly-20220305022735
12
- - @backstage/plugin-search-common@0.0.0-nightly-20220305022735
10
+ - @backstage/backend-common@0.0.0-nightly-20220308022132
11
+ - @backstage/catalog-model@0.0.0-nightly-20220308022132
12
+ - @backstage/plugin-search-common@0.0.0-nightly-20220308022132
13
13
 
14
14
  ## 0.11.11
15
15
 
@@ -0,0 +1,472 @@
1
+ /// <reference types="node" />
2
+ import { UrlReader, ContainerRunner, PluginEndpointDiscovery } from '@backstage/backend-common';
3
+ import { Config } from '@backstage/config';
4
+ import { Logger } from 'winston';
5
+ import { ScmIntegrationRegistry } from '@backstage/integration';
6
+ import { Entity, CompoundEntityRef } from '@backstage/catalog-model';
7
+ import { Writable } from 'stream';
8
+ import express from 'express';
9
+ import { IndexableDocument } from '@backstage/plugin-search-common';
10
+
11
+ /**
12
+ * A unique identifier of the tree blob, usually the commit SHA or etag from the target.
13
+ * @public
14
+ */
15
+ declare type ETag = string;
16
+ /**
17
+ * Options for building preparers
18
+ * @public
19
+ */
20
+ declare type PreparerConfig = {
21
+ logger: Logger;
22
+ reader: UrlReader;
23
+ };
24
+ /**
25
+ * Options for configuring the content preparation process.
26
+ * @public
27
+ */
28
+ declare type PreparerOptions = {
29
+ /**
30
+ * An instance of the logger
31
+ */
32
+ logger?: Logger;
33
+ /**
34
+ * see {@link ETag}
35
+ */
36
+ etag?: ETag;
37
+ };
38
+ /**
39
+ * Result of the preparation step.
40
+ * @public
41
+ */
42
+ declare type PreparerResponse = {
43
+ /**
44
+ * The path to directory where the tree is downloaded.
45
+ */
46
+ preparedDir: string;
47
+ /**
48
+ * see {@link ETag}
49
+ */
50
+ etag: ETag;
51
+ };
52
+ /**
53
+ * Definition of a TechDocs preparer
54
+ * @public
55
+ */
56
+ declare type PreparerBase = {
57
+ /**
58
+ * Given an Entity definition from the Software Catalog, go and prepare a directory
59
+ * with contents from the location in temporary storage and return the path.
60
+ *
61
+ * @param entity - The entity from the Software Catalog
62
+ * @param options - If etag is provided, it will be used to check if the target has
63
+ * updated since the last build.
64
+ * @throws `NotModifiedError` when the prepared directory has not been changed since the last build.
65
+ */
66
+ prepare(entity: Entity, options?: PreparerOptions): Promise<PreparerResponse>;
67
+ };
68
+ /**
69
+ * Definition for a TechDocs preparer builder
70
+ * @public
71
+ */
72
+ declare type PreparerBuilder = {
73
+ register(protocol: RemoteProtocol, preparer: PreparerBase): void;
74
+ get(entity: Entity): PreparerBase;
75
+ };
76
+ /**
77
+ * Location where documentation files are stored
78
+ * @public
79
+ */
80
+ declare type RemoteProtocol = 'url' | 'dir';
81
+
82
+ /**
83
+ * Parsed location annotation
84
+ * @public
85
+ */
86
+ declare type ParsedLocationAnnotation = {
87
+ type: RemoteProtocol;
88
+ target: string;
89
+ };
90
+ /**
91
+ * Returns a parset locations annotation
92
+ * @public
93
+ * @param annotationName - The name of the annotation in the entity metadata
94
+ * @param entity - A TechDocs entity instance
95
+ */
96
+ declare const parseReferenceAnnotation: (annotationName: string, entity: Entity) => ParsedLocationAnnotation;
97
+ /**
98
+ * TechDocs references of type `dir` are relative the source location of the entity.
99
+ * This function transforms relative references to absolute ones, based on the
100
+ * location the entity was ingested from. If the entity was registered by a `url`
101
+ * location, it returns a `url` location with a resolved target that points to the
102
+ * targeted subfolder. If the entity was registered by a `file` location, it returns
103
+ * an absolute `dir` location.
104
+ * @public
105
+ * @param entity - the entity with annotations
106
+ * @param dirAnnotation - the parsed techdocs-ref annotation of type 'dir'
107
+ * @param scmIntegrations - access to the scmIntegration to do url transformations
108
+ * @throws if the entity doesn't specify a `dir` location or is ingested from an unsupported location.
109
+ * @returns the transformed location with an absolute target.
110
+ */
111
+ declare const transformDirLocation: (entity: Entity, dirAnnotation: ParsedLocationAnnotation, scmIntegrations: ScmIntegrationRegistry) => {
112
+ type: 'dir' | 'url';
113
+ target: string;
114
+ };
115
+ /**
116
+ * Returns a entity reference based on the TechDocs annotation type
117
+ * @public
118
+ * @param entity - A TechDocs instance
119
+ * @param scmIntegration - An implementation for SCM integration API
120
+ */
121
+ declare const getLocationForEntity: (entity: Entity, scmIntegration: ScmIntegrationRegistry) => ParsedLocationAnnotation;
122
+ /**
123
+ * Returns a preparer response {@link PreparerResponse}
124
+ * @public
125
+ * @param reader - Read a tree of files from a repository
126
+ * @param entity - A TechDocs entity instance
127
+ * @param opts - Options for configuring the reader, e.g. logger, etag, etc.
128
+ */
129
+ declare const getDocFilesFromRepository: (reader: UrlReader, entity: Entity, opts?: {
130
+ etag?: string | undefined;
131
+ logger?: Logger | undefined;
132
+ } | undefined) => Promise<PreparerResponse>;
133
+
134
+ /**
135
+ * Options for building generators
136
+ * @public
137
+ */
138
+ declare type GeneratorOptions = {
139
+ containerRunner: ContainerRunner;
140
+ logger: Logger;
141
+ };
142
+ /**
143
+ * The values that the generator will receive.
144
+ *
145
+ * @public
146
+ * @param inputDir - The directory of the uncompiled documentation, with the values from the frontend
147
+ * @param outputDir - Directory to store generated docs in. Usually - a newly created temporary directory.
148
+ * @param parsedLocationAnnotation - backstage.io/techdocs-ref annotation of an entity
149
+ * @param etag - A unique identifier for the prepared tree e.g. commit SHA. If provided it will be stored in techdocs_metadata.json.
150
+ * @param logger - A logger that forwards the messages to the caller to be displayed outside of the backend.
151
+ * @param logStream - A log stream that can send raw log messages to the caller to be displayed outside of the backend.
152
+ */
153
+ declare type GeneratorRunOptions = {
154
+ inputDir: string;
155
+ outputDir: string;
156
+ parsedLocationAnnotation?: ParsedLocationAnnotation;
157
+ etag?: string;
158
+ logger: Logger;
159
+ logStream?: Writable;
160
+ };
161
+ /**
162
+ * Generates documentation files
163
+ * @public
164
+ */
165
+ declare type GeneratorBase = {
166
+ /**
167
+ * Runs the generator with the values
168
+ * @public
169
+ */
170
+ run(opts: GeneratorRunOptions): Promise<void>;
171
+ };
172
+ /**
173
+ * List of supported generator options
174
+ * @public
175
+ */
176
+ declare type SupportedGeneratorKey = 'techdocs' | string;
177
+ /**
178
+ * The generator builder holds the generator ready for run time
179
+ * @public
180
+ */
181
+ declare type GeneratorBuilder = {
182
+ register(protocol: SupportedGeneratorKey, generator: GeneratorBase): void;
183
+ get(entity: Entity): GeneratorBase;
184
+ };
185
+
186
+ /**
187
+ * Generates documentation files
188
+ * @public
189
+ */
190
+ declare class TechdocsGenerator implements GeneratorBase {
191
+ /**
192
+ * The default docker image (and version) used to generate content. Public
193
+ * and static so that techdocs-node consumers can use the same version.
194
+ */
195
+ static readonly defaultDockerImage = "spotify/techdocs:v0.3.7";
196
+ private readonly logger;
197
+ private readonly containerRunner;
198
+ private readonly options;
199
+ private readonly scmIntegrations;
200
+ /**
201
+ * Returns a instance of TechDocs generator
202
+ * @param config - A Backstage configuration
203
+ * @param options - Options to configure the generator
204
+ */
205
+ static fromConfig(config: Config, options: GeneratorOptions): TechdocsGenerator;
206
+ constructor(options: {
207
+ logger: Logger;
208
+ containerRunner: ContainerRunner;
209
+ config: Config;
210
+ scmIntegrations: ScmIntegrationRegistry;
211
+ });
212
+ /** {@inheritDoc GeneratorBase.run} */
213
+ run(options: GeneratorRunOptions): Promise<void>;
214
+ }
215
+
216
+ /**
217
+ * Collection of docs generators
218
+ * @public
219
+ */
220
+ declare class Generators implements GeneratorBuilder {
221
+ private generatorMap;
222
+ /**
223
+ * Returns a generators instance containing a generator for TechDocs
224
+ * @param config - A Backstage configuration
225
+ * @param options - Options to configure the TechDocs generator
226
+ */
227
+ static fromConfig(config: Config, options: {
228
+ logger: Logger;
229
+ containerRunner: ContainerRunner;
230
+ }): Promise<GeneratorBuilder>;
231
+ /**
232
+ * Register a generator in the generators collection
233
+ * @param generatorKey - Unique identifier for the generator
234
+ * @param generator - The generator instance to register
235
+ */
236
+ register(generatorKey: SupportedGeneratorKey, generator: GeneratorBase): void;
237
+ /**
238
+ * Returns the generator for a given TechDocs entity
239
+ * @param entity - A TechDocs entity instance
240
+ */
241
+ get(entity: Entity): GeneratorBase;
242
+ }
243
+
244
+ /**
245
+ * Preparer used to retrieve documentation files from a local directory
246
+ * @public
247
+ */
248
+ declare class DirectoryPreparer implements PreparerBase {
249
+ private readonly scmIntegrations;
250
+ private readonly reader;
251
+ /** @deprecated use static fromConfig method instead */
252
+ constructor(config: Config, _logger: Logger | null, reader: UrlReader);
253
+ /**
254
+ * Returns a directory preparer instance
255
+ * @param config - A backstage config
256
+ * @param options - A directory preparer options containing a logger and reader
257
+ */
258
+ static fromConfig(config: Config, { logger, reader }: PreparerConfig): DirectoryPreparer;
259
+ /** {@inheritDoc PreparerBase.prepare} */
260
+ prepare(entity: Entity, options?: PreparerOptions): Promise<PreparerResponse>;
261
+ }
262
+
263
+ /**
264
+ * Preparer used to retrieve documentation files from a remote repository
265
+ * @public
266
+ */
267
+ declare class UrlPreparer implements PreparerBase {
268
+ private readonly logger;
269
+ private readonly reader;
270
+ /** @deprecated use static fromConfig method instead */
271
+ constructor(reader: UrlReader, logger: Logger);
272
+ /**
273
+ * Returns a directory preparer instance
274
+ * @param config - A URL preparer config containing the a logger and reader
275
+ */
276
+ static fromConfig({ reader, logger }: PreparerConfig): UrlPreparer;
277
+ /** {@inheritDoc PreparerBase.prepare} */
278
+ prepare(entity: Entity, options?: PreparerOptions): Promise<PreparerResponse>;
279
+ }
280
+
281
+ /**
282
+ * Collection of docs preparers (dir and url)
283
+ * @public
284
+ */
285
+ declare class Preparers implements PreparerBuilder {
286
+ private preparerMap;
287
+ /**
288
+ * Returns a generators instance containing a generator for TechDocs
289
+ * @public
290
+ * @param backstageConfig - A Backstage configuration
291
+ * @param preparerConfig - Options to configure preparers
292
+ */
293
+ static fromConfig(backstageConfig: Config, { logger, reader }: PreparerConfig): Promise<PreparerBuilder>;
294
+ /**
295
+ * Register a preparer in the preparers collection
296
+ * @param protocol - url or dir to associate with preparer
297
+ * @param preparer - The preparer instance to set
298
+ */
299
+ register(protocol: RemoteProtocol, preparer: PreparerBase): void;
300
+ /**
301
+ * Returns the preparer for a given TechDocs entity
302
+ * @param entity - A TechDocs entity instance
303
+ * @returns
304
+ */
305
+ get(entity: Entity): PreparerBase;
306
+ }
307
+
308
+ /**
309
+ * Options for building publishers
310
+ * @public
311
+ */
312
+ declare type PublisherFactory = {
313
+ logger: Logger;
314
+ discovery: PluginEndpointDiscovery;
315
+ };
316
+ /**
317
+ * Key for all the different types of TechDocs publishers that are supported.
318
+ * @public
319
+ */
320
+ declare type PublisherType = 'local' | 'googleGcs' | 'awsS3' | 'azureBlobStorage' | 'openStackSwift';
321
+ /**
322
+ * Request publish definition
323
+ * @public
324
+ */
325
+ declare type PublishRequest = {
326
+ entity: Entity;
327
+ directory: string;
328
+ };
329
+ /**
330
+ * Response containing metadata about where files were published and what may
331
+ * have been published or updated.
332
+ * @public
333
+ */
334
+ declare type PublishResponse = {
335
+ /**
336
+ * The URL which serves files from the local publisher's static directory.
337
+ */
338
+ remoteUrl?: string;
339
+ /**
340
+ * The list of objects (specifically their paths) that were published.
341
+ * Objects do not have a preceding slash, and match how one would load the
342
+ * object over the `/static/docs/*` TechDocs Backend Plugin endpoint.
343
+ */
344
+ objects?: string[];
345
+ } | void;
346
+ /**
347
+ * Result for the validation check.
348
+ * @public
349
+ */
350
+ declare type ReadinessResponse = {
351
+ /** If true, the publisher is able to interact with the backing storage. */
352
+ isAvailable: boolean;
353
+ };
354
+ /**
355
+ * Type to hold metadata found in techdocs_metadata.json and associated with each site
356
+ * @param etag - ETag of the resource used to generate the site. Usually the latest commit sha of the source repository.
357
+ * @public
358
+ */
359
+ declare type TechDocsMetadata = {
360
+ site_name: string;
361
+ site_description: string;
362
+ etag: string;
363
+ build_timestamp: number;
364
+ files?: string[];
365
+ };
366
+ /**
367
+ * TechDocs entity triplet migration request
368
+ * @public
369
+ */
370
+ declare type MigrateRequest = {
371
+ /**
372
+ * Whether or not to remove the source file. Defaults to false (acting like a
373
+ * copy instead of a move).
374
+ */
375
+ removeOriginal?: boolean;
376
+ /**
377
+ * Maximum number of files/objects to migrate at once. Defaults to 25.
378
+ */
379
+ concurrency?: number;
380
+ };
381
+ /**
382
+ * Base class for a TechDocs publisher (e.g. Local, Google GCS Bucket, AWS S3, etc.)
383
+ * The publisher handles publishing of the generated static files after the prepare and generate steps of TechDocs.
384
+ * It also provides APIs to communicate with the storage service.
385
+ *
386
+ * @public
387
+ */
388
+ interface PublisherBase {
389
+ /**
390
+ * Check if the publisher is ready. This check tries to perform certain checks to see if the
391
+ * publisher is configured correctly and can be used to publish or read documentations.
392
+ * The different implementations might e.g. use the provided service credentials to access the
393
+ * target or check if a folder/bucket is available.
394
+ */
395
+ getReadiness(): Promise<ReadinessResponse>;
396
+ /**
397
+ * Store the generated static files onto a storage service (either local filesystem or external service).
398
+ *
399
+ * @param request - Object containing the entity from the service
400
+ * catalog, and the directory that contains the generated static files from TechDocs.
401
+ */
402
+ publish(request: PublishRequest): Promise<PublishResponse>;
403
+ /**
404
+ * Retrieve TechDocs Metadata about a site e.g. name, contributors, last updated, etc.
405
+ * This API uses the techdocs_metadata.json file that co-exists along with the generated docs.
406
+ */
407
+ fetchTechDocsMetadata(entityName: CompoundEntityRef): Promise<TechDocsMetadata>;
408
+ /**
409
+ * Route middleware to serve static documentation files for an entity.
410
+ */
411
+ docsRouter(): express.Handler;
412
+ /**
413
+ * Check if the index.html is present for the Entity at the Storage location.
414
+ */
415
+ hasDocsBeenGenerated(entityName: Entity): Promise<boolean>;
416
+ /**
417
+ * Migrates documentation objects with case sensitive entity triplets to
418
+ * lowercase entity triplets. This was (will be) a change introduced in
419
+ * `techdocs-cli` version `{0.x.y}` and `techdocs-backend` version `{0.x.y}`.
420
+ *
421
+ * Implementation of this method is unnecessary in publishers introduced
422
+ * after version `{0.x.y}` of `techdocs-node`.
423
+ */
424
+ migrateDocsCase?(migrateRequest: MigrateRequest): Promise<void>;
425
+ }
426
+
427
+ /**
428
+ * Factory class to create a TechDocs publisher based on defined publisher type in app config.
429
+ * Uses `techdocs.publisher.type`.
430
+ * @public
431
+ */
432
+ declare class Publisher {
433
+ /**
434
+ * Returns a instance of TechDocs publisher
435
+ * @param config - A Backstage configuration
436
+ * @param options - Options for configuring the publisher factory
437
+ */
438
+ static fromConfig(config: Config, { logger, discovery }: PublisherFactory): Promise<PublisherBase>;
439
+ }
440
+
441
+ /**
442
+ * TechDocs indexable document interface
443
+ * @public
444
+ */
445
+ interface TechDocsDocument extends IndexableDocument {
446
+ /**
447
+ * Entity kind
448
+ */
449
+ kind: string;
450
+ /**
451
+ * Entity metadata namespace
452
+ */
453
+ namespace: string;
454
+ /**
455
+ * Entity metadata name
456
+ */
457
+ name: string;
458
+ /**
459
+ * Entity lifecycle
460
+ */
461
+ lifecycle: string;
462
+ /**
463
+ * Entity owner
464
+ */
465
+ owner: string;
466
+ /**
467
+ * Entity path
468
+ */
469
+ path: string;
470
+ }
471
+
472
+ export { DirectoryPreparer, ETag, GeneratorBase, GeneratorBuilder, GeneratorOptions, GeneratorRunOptions, Generators, MigrateRequest, ParsedLocationAnnotation, PreparerBase, PreparerBuilder, PreparerConfig, PreparerOptions, PreparerResponse, Preparers, PublishRequest, PublishResponse, Publisher, PublisherBase, PublisherFactory, PublisherType, ReadinessResponse, RemoteProtocol, SupportedGeneratorKey, TechDocsDocument, TechDocsMetadata, TechdocsGenerator, UrlPreparer, getDocFilesFromRepository, getLocationForEntity, parseReferenceAnnotation, transformDirLocation };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-techdocs-node",
3
3
  "description": "Common node.js functionalities for TechDocs, to be shared between techdocs-backend plugin and techdocs-cli",
4
- "version": "0.0.0-nightly-20220305022735",
4
+ "version": "0.0.0-nightly-20220308022132",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "private": false,
@@ -42,12 +42,12 @@
42
42
  "dependencies": {
43
43
  "@azure/identity": "^2.0.1",
44
44
  "@azure/storage-blob": "^12.5.0",
45
- "@backstage/backend-common": "^0.0.0-nightly-20220305022735",
46
- "@backstage/catalog-model": "^0.0.0-nightly-20220305022735",
45
+ "@backstage/backend-common": "^0.0.0-nightly-20220308022132",
46
+ "@backstage/catalog-model": "^0.0.0-nightly-20220308022132",
47
47
  "@backstage/config": "^0.1.15",
48
48
  "@backstage/errors": "^0.2.2",
49
49
  "@backstage/integration": "^0.8.0",
50
- "@backstage/plugin-search-common": "^0.0.0-nightly-20220305022735",
50
+ "@backstage/plugin-search-common": "^0.0.0-nightly-20220308022132",
51
51
  "@google-cloud/storage": "^5.6.0",
52
52
  "@trendyol-js/openstack-swift-sdk": "^0.0.5",
53
53
  "@types/express": "^4.17.6",
@@ -64,7 +64,7 @@
64
64
  "winston": "^3.2.1"
65
65
  },
66
66
  "devDependencies": {
67
- "@backstage/cli": "^0.0.0-nightly-20220305022735",
67
+ "@backstage/cli": "^0.0.0-nightly-20220308022132",
68
68
  "@types/fs-extra": "^9.0.5",
69
69
  "@types/js-yaml": "^4.0.0",
70
70
  "@types/mime-types": "^2.1.0",