@backstage/plugin-scaffolder-backend 0.15.8 → 0.15.12

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/dist/index.d.ts CHANGED
@@ -3,13 +3,15 @@ import { ScmIntegrations, ScmIntegrationRegistry } from '@backstage/integration'
3
3
  import { CatalogApi } from '@backstage/catalog-client';
4
4
  import { Logger } from 'winston';
5
5
  import { Writable } from 'stream';
6
- import * as _backstage_config from '@backstage/config';
7
- import { Config, JsonValue, JsonObject } from '@backstage/config';
6
+ import * as _backstage_types from '@backstage/types';
7
+ import { JsonValue, JsonObject } from '@backstage/types';
8
8
  import { Schema } from 'jsonschema';
9
9
  import { UrlReader, ContainerRunner, PluginDatabaseManager } from '@backstage/backend-common';
10
+ import { Config } from '@backstage/config';
10
11
  import { createPullRequest } from 'octokit-plugin-create-pull-request';
11
12
  import { Octokit } from '@octokit/rest';
12
13
  export { createFetchCookiecutterAction } from '@backstage/plugin-scaffolder-backend-module-cookiecutter';
14
+ import { Knex } from 'knex';
13
15
  import express from 'express';
14
16
  import { TemplateEntityV1beta2, Entity, LocationSpec } from '@backstage/catalog-model';
15
17
  import { CatalogProcessor, CatalogProcessorEmit } from '@backstage/plugin-catalog-backend';
@@ -186,9 +188,300 @@ declare class TemplateActionRegistry {
186
188
  }
187
189
 
188
190
  declare const createTemplateAction: <Input extends Partial<{
189
- [name: string]: _backstage_config.JsonValue | Partial<_backstage_config.JsonObject> | undefined;
191
+ [name: string]: _backstage_types.JsonValue | Partial<_backstage_types.JsonObject> | undefined;
190
192
  }>>(templateAction: TemplateAction<Input>) => TemplateAction<any>;
191
193
 
194
+ /**
195
+ * Status
196
+ *
197
+ * @public
198
+ */
199
+ declare type Status = 'open' | 'processing' | 'failed' | 'cancelled' | 'completed';
200
+ /**
201
+ * CompletedTaskState
202
+ *
203
+ * @public
204
+ */
205
+ declare type CompletedTaskState = 'failed' | 'completed';
206
+ /**
207
+ * SerializedTask
208
+ *
209
+ * @public
210
+ */
211
+ declare type SerializedTask = {
212
+ id: string;
213
+ spec: TaskSpec;
214
+ status: Status;
215
+ createdAt: string;
216
+ lastHeartbeatAt?: string;
217
+ secrets?: TaskSecrets;
218
+ };
219
+ /**
220
+ * TaskEventType
221
+ *
222
+ * @public
223
+ */
224
+ declare type TaskEventType = 'completion' | 'log';
225
+ /**
226
+ * SerializedTaskEvent
227
+ *
228
+ * @public
229
+ */
230
+ declare type SerializedTaskEvent = {
231
+ id: number;
232
+ taskId: string;
233
+ body: JsonObject;
234
+ type: TaskEventType;
235
+ createdAt: string;
236
+ };
237
+ /**
238
+ * TaskSpecV1beta2
239
+ *
240
+ * @public
241
+ */
242
+ interface TaskSpecV1beta2 {
243
+ apiVersion: 'backstage.io/v1beta2';
244
+ baseUrl?: string;
245
+ values: JsonObject;
246
+ steps: Array<{
247
+ id: string;
248
+ name: string;
249
+ action: string;
250
+ input?: JsonObject;
251
+ if?: string | boolean;
252
+ }>;
253
+ output: {
254
+ [name: string]: string;
255
+ };
256
+ }
257
+ interface TaskStep {
258
+ id: string;
259
+ name: string;
260
+ action: string;
261
+ input?: JsonObject;
262
+ if?: string | boolean;
263
+ }
264
+ /**
265
+ * TaskSpecV1beta3
266
+ *
267
+ * @public
268
+ */
269
+ interface TaskSpecV1beta3 {
270
+ apiVersion: 'scaffolder.backstage.io/v1beta3';
271
+ baseUrl?: string;
272
+ parameters: JsonObject;
273
+ steps: TaskStep[];
274
+ output: {
275
+ [name: string]: JsonValue;
276
+ };
277
+ }
278
+ /**
279
+ * TaskSpec
280
+ *
281
+ * @public
282
+ */
283
+ declare type TaskSpec = TaskSpecV1beta2 | TaskSpecV1beta3;
284
+ /**
285
+ * TaskSecrets
286
+ *
287
+ * @public
288
+ */
289
+ declare type TaskSecrets = {
290
+ token: string | undefined;
291
+ };
292
+ /**
293
+ * DispatchResult
294
+ *
295
+ * @public
296
+ */
297
+ declare type DispatchResult = {
298
+ taskId: string;
299
+ };
300
+ /**
301
+ * Task
302
+ *
303
+ * @public
304
+ */
305
+ interface TaskContext {
306
+ spec: TaskSpec;
307
+ secrets?: TaskSecrets;
308
+ done: boolean;
309
+ emitLog(message: string, metadata?: JsonValue): Promise<void>;
310
+ complete(result: CompletedTaskState, metadata?: JsonValue): Promise<void>;
311
+ getWorkspaceName(): Promise<string>;
312
+ }
313
+ /**
314
+ * TaskBroker
315
+ *
316
+ * @public
317
+ */
318
+ interface TaskBroker {
319
+ claim(): Promise<TaskContext>;
320
+ dispatch(spec: TaskSpec, secrets?: TaskSecrets): Promise<DispatchResult>;
321
+ vacuumTasks(timeoutS: {
322
+ timeoutS: number;
323
+ }): Promise<void>;
324
+ observe(options: {
325
+ taskId: string;
326
+ after: number | undefined;
327
+ }, callback: (error: Error | undefined, result: {
328
+ events: SerializedTaskEvent[];
329
+ }) => void): {
330
+ unsubscribe: () => void;
331
+ };
332
+ get(taskId: string): Promise<SerializedTask>;
333
+ }
334
+ /**
335
+ * TaskStoreEmitOptions
336
+ *
337
+ * @public
338
+ */
339
+ declare type TaskStoreEmitOptions = {
340
+ taskId: string;
341
+ body: JsonObject;
342
+ };
343
+ /**
344
+ * TaskStoreListEventsOptions
345
+ *
346
+ * @public
347
+ */
348
+ declare type TaskStoreListEventsOptions = {
349
+ taskId: string;
350
+ after?: number | undefined;
351
+ };
352
+ /**
353
+ * TaskStore
354
+ *
355
+ * @public
356
+ */
357
+ interface TaskStore {
358
+ createTask(task: TaskSpec, secrets?: TaskSecrets): Promise<{
359
+ taskId: string;
360
+ }>;
361
+ getTask(taskId: string): Promise<SerializedTask>;
362
+ claimTask(): Promise<SerializedTask | undefined>;
363
+ completeTask(options: {
364
+ taskId: string;
365
+ status: Status;
366
+ eventBody: JsonObject;
367
+ }): Promise<void>;
368
+ heartbeatTask(taskId: string): Promise<void>;
369
+ listStaleTasks(options: {
370
+ timeoutS: number;
371
+ }): Promise<{
372
+ tasks: {
373
+ taskId: string;
374
+ }[];
375
+ }>;
376
+ emitLogEvent({ taskId, body }: TaskStoreEmitOptions): Promise<void>;
377
+ listEvents({ taskId, after, }: TaskStoreListEventsOptions): Promise<{
378
+ events: SerializedTaskEvent[];
379
+ }>;
380
+ }
381
+
382
+ /**
383
+ * DatabaseTaskStore
384
+ *
385
+ * @public
386
+ */
387
+ declare type DatabaseTaskStoreOptions = {
388
+ database: Knex;
389
+ };
390
+ /**
391
+ * DatabaseTaskStore
392
+ *
393
+ * @public
394
+ */
395
+ declare class DatabaseTaskStore implements TaskStore {
396
+ private readonly db;
397
+ static create(options: DatabaseTaskStoreOptions): Promise<DatabaseTaskStore>;
398
+ constructor(options: DatabaseTaskStoreOptions);
399
+ getTask(taskId: string): Promise<SerializedTask>;
400
+ createTask(spec: TaskSpec, secrets?: TaskSecrets): Promise<{
401
+ taskId: string;
402
+ }>;
403
+ claimTask(): Promise<SerializedTask | undefined>;
404
+ heartbeatTask(taskId: string): Promise<void>;
405
+ listStaleTasks({ timeoutS }: {
406
+ timeoutS: number;
407
+ }): Promise<{
408
+ tasks: {
409
+ taskId: string;
410
+ }[];
411
+ }>;
412
+ completeTask({ taskId, status, eventBody, }: {
413
+ taskId: string;
414
+ status: Status;
415
+ eventBody: JsonObject;
416
+ }): Promise<void>;
417
+ emitLogEvent({ taskId, body }: TaskStoreEmitOptions): Promise<void>;
418
+ listEvents({ taskId, after, }: TaskStoreListEventsOptions): Promise<{
419
+ events: SerializedTaskEvent[];
420
+ }>;
421
+ }
422
+
423
+ /**
424
+ * TaskManager
425
+ *
426
+ * @public
427
+ */
428
+ declare class TaskManager implements TaskContext {
429
+ private readonly state;
430
+ private readonly storage;
431
+ private readonly logger;
432
+ private isDone;
433
+ private heartbeatTimeoutId?;
434
+ static create(state: TaskState, storage: TaskStore, logger: Logger): TaskManager;
435
+ private constructor();
436
+ get spec(): TaskSpec;
437
+ get secrets(): TaskSecrets | undefined;
438
+ getWorkspaceName(): Promise<string>;
439
+ get done(): boolean;
440
+ emitLog(message: string, metadata?: JsonObject): Promise<void>;
441
+ complete(result: CompletedTaskState, metadata?: JsonObject): Promise<void>;
442
+ private startTimeout;
443
+ }
444
+ /**
445
+ * TaskState
446
+ *
447
+ * @public
448
+ */
449
+ interface TaskState {
450
+ spec: TaskSpec;
451
+ taskId: string;
452
+ secrets?: TaskSecrets;
453
+ }
454
+
455
+ /**
456
+ * CreateWorkerOptions
457
+ *
458
+ * @public
459
+ */
460
+ declare type CreateWorkerOptions = {
461
+ taskBroker: TaskBroker;
462
+ actionRegistry: TemplateActionRegistry;
463
+ integrations: ScmIntegrations;
464
+ workingDirectory: string;
465
+ logger: Logger;
466
+ };
467
+ /**
468
+ * TaskWorker
469
+ *
470
+ * @public
471
+ */
472
+ declare class TaskWorker {
473
+ private readonly options;
474
+ private constructor();
475
+ static create(options: CreateWorkerOptions): Promise<TaskWorker>;
476
+ start(): void;
477
+ runOneTask(task: TaskContext): Promise<void>;
478
+ }
479
+
480
+ /**
481
+ * RouterOptions
482
+ *
483
+ * @public
484
+ */
192
485
  interface RouterOptions {
193
486
  logger: Logger;
194
487
  config: Config;
@@ -198,6 +491,7 @@ interface RouterOptions {
198
491
  actions?: TemplateAction<any>[];
199
492
  taskWorkers?: number;
200
493
  containerRunner: ContainerRunner;
494
+ taskBroker?: TaskBroker;
201
495
  }
202
496
  declare function createRouter(options: RouterOptions): Promise<express.Router>;
203
497
 
@@ -224,4 +518,4 @@ declare class ScaffolderEntitiesProcessor implements CatalogProcessor {
224
518
  postProcessEntity(entity: Entity, _location: LocationSpec, emit: CatalogProcessorEmit): Promise<Entity>;
225
519
  }
226
520
 
227
- export { ActionContext, CatalogEntityClient, OctokitProvider, RouterOptions, ScaffolderEntitiesProcessor, TemplateAction, TemplateActionRegistry, createBuiltinActions, createCatalogRegisterAction, createCatalogWriteAction, createDebugLogAction, createFetchPlainAction, createFetchTemplateAction, createFilesystemDeleteAction, createFilesystemRenameAction, createGithubActionsDispatchAction, createGithubWebhookAction, createPublishAzureAction, createPublishBitbucketAction, createPublishFileAction, createPublishGithubAction, createPublishGithubPullRequestAction, createPublishGitlabAction, createRouter, createTemplateAction, fetchContents, runCommand };
521
+ export { ActionContext, CatalogEntityClient, CompletedTaskState, CreateWorkerOptions, DatabaseTaskStore, DispatchResult, OctokitProvider, RouterOptions, ScaffolderEntitiesProcessor, SerializedTask, SerializedTaskEvent, Status, TaskBroker, TaskContext, TaskEventType, TaskManager, TaskSecrets, TaskSpec, TaskSpecV1beta2, TaskSpecV1beta3, TaskState, TaskStore, TaskStoreEmitOptions, TaskStoreListEventsOptions, TaskWorker, TemplateAction, TemplateActionRegistry, createBuiltinActions, createCatalogRegisterAction, createCatalogWriteAction, createDebugLogAction, createFetchPlainAction, createFetchTemplateAction, createFilesystemDeleteAction, createFilesystemRenameAction, createGithubActionsDispatchAction, createGithubWebhookAction, createPublishAzureAction, createPublishBitbucketAction, createPublishFileAction, createPublishGithubAction, createPublishGithubPullRequestAction, createPublishGitlabAction, createRouter, createTemplateAction, fetchContents, runCommand };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend",
3
3
  "description": "The Backstage backend plugin that helps you create new things",
4
- "version": "0.15.8",
4
+ "version": "0.15.12",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -30,15 +30,16 @@
30
30
  "clean": "backstage-cli clean"
31
31
  },
32
32
  "dependencies": {
33
- "@backstage/backend-common": "^0.9.6",
34
- "@backstage/catalog-client": "^0.5.0",
35
- "@backstage/catalog-model": "^0.9.4",
36
- "@backstage/config": "^0.1.10",
37
- "@backstage/errors": "^0.1.2",
38
- "@backstage/integration": "^0.6.8",
39
- "@backstage/plugin-catalog-backend": "^0.17.0",
40
- "@backstage/plugin-scaffolder-backend-module-cookiecutter": "^0.1.2",
41
- "@backstage/plugin-scaffolder-common": "^0.1.0",
33
+ "@backstage/backend-common": "^0.9.9",
34
+ "@backstage/catalog-client": "^0.5.1",
35
+ "@backstage/catalog-model": "^0.9.6",
36
+ "@backstage/config": "^0.1.11",
37
+ "@backstage/errors": "^0.1.4",
38
+ "@backstage/integration": "^0.6.9",
39
+ "@backstage/plugin-catalog-backend": "^0.17.3",
40
+ "@backstage/plugin-scaffolder-backend-module-cookiecutter": "^0.1.4",
41
+ "@backstage/plugin-scaffolder-common": "^0.1.1",
42
+ "@backstage/types": "^0.1.1",
42
43
  "@gitbeaker/core": "^30.2.0",
43
44
  "@gitbeaker/node": "^30.2.0",
44
45
  "@octokit/rest": "^18.5.3",
@@ -64,14 +65,14 @@
64
65
  "luxon": "^2.0.2",
65
66
  "morgan": "^1.10.0",
66
67
  "nunjucks": "^3.2.3",
67
- "octokit-plugin-create-pull-request": "^3.9.3",
68
+ "octokit-plugin-create-pull-request": "^3.10.0",
68
69
  "uuid": "^8.2.0",
69
70
  "winston": "^3.2.1",
70
71
  "yaml": "^1.10.0"
71
72
  },
72
73
  "devDependencies": {
73
- "@backstage/cli": "^0.7.16",
74
- "@backstage/test-utils": "^0.1.19",
74
+ "@backstage/cli": "^0.8.2",
75
+ "@backstage/test-utils": "^0.1.21",
75
76
  "@types/command-exists": "^1.2.0",
76
77
  "@types/fs-extra": "^9.0.1",
77
78
  "@types/git-url-parse": "^9.0.0",
@@ -80,7 +81,7 @@
80
81
  "@types/supertest": "^2.0.8",
81
82
  "jest-when": "^3.1.0",
82
83
  "mock-fs": "^5.1.0",
83
- "msw": "^0.29.0",
84
+ "msw": "^0.35.0",
84
85
  "supertest": "^6.1.3",
85
86
  "yaml": "^1.10.0"
86
87
  },
@@ -90,5 +91,5 @@
90
91
  "config.d.ts"
91
92
  ],
92
93
  "configSchema": "config.d.ts",
93
- "gitHead": "1b02df9f467ea11a4571df46faabe655c3ee10c8"
94
+ "gitHead": "5bdaccc40b4a814cf0b45d429f15a3afacc2f60b"
94
95
  }