@backstage/plugin-scaffolder-backend 0.15.9 → 0.15.13

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';
@@ -144,6 +146,204 @@ declare type RunCommandOptions = {
144
146
  };
145
147
  declare const runCommand: ({ command, args, logStream, }: RunCommandOptions) => Promise<void>;
146
148
 
149
+ /**
150
+ * Status
151
+ *
152
+ * @public
153
+ */
154
+ declare type Status = 'open' | 'processing' | 'failed' | 'cancelled' | 'completed';
155
+ /**
156
+ * CompletedTaskState
157
+ *
158
+ * @public
159
+ */
160
+ declare type CompletedTaskState = 'failed' | 'completed';
161
+ /**
162
+ * SerializedTask
163
+ *
164
+ * @public
165
+ */
166
+ declare type SerializedTask = {
167
+ id: string;
168
+ spec: TaskSpec;
169
+ status: Status;
170
+ createdAt: string;
171
+ lastHeartbeatAt?: string;
172
+ secrets?: TaskSecrets;
173
+ };
174
+ /**
175
+ * TaskEventType
176
+ *
177
+ * @public
178
+ */
179
+ declare type TaskEventType = 'completion' | 'log';
180
+ /**
181
+ * SerializedTaskEvent
182
+ *
183
+ * @public
184
+ */
185
+ declare type SerializedTaskEvent = {
186
+ id: number;
187
+ taskId: string;
188
+ body: JsonObject;
189
+ type: TaskEventType;
190
+ createdAt: string;
191
+ };
192
+ /**
193
+ * TemplateMetadata
194
+ *
195
+ * @public
196
+ */
197
+ declare type TemplateMetadata = {
198
+ name: string;
199
+ };
200
+ /**
201
+ * TaskSpecV1beta2
202
+ *
203
+ * @public
204
+ */
205
+ interface TaskSpecV1beta2 {
206
+ apiVersion: 'backstage.io/v1beta2';
207
+ baseUrl?: string;
208
+ values: JsonObject;
209
+ steps: Array<{
210
+ id: string;
211
+ name: string;
212
+ action: string;
213
+ input?: JsonObject;
214
+ if?: string | boolean;
215
+ }>;
216
+ output: {
217
+ [name: string]: string;
218
+ };
219
+ metadata?: TemplateMetadata;
220
+ }
221
+ interface TaskStep {
222
+ id: string;
223
+ name: string;
224
+ action: string;
225
+ input?: JsonObject;
226
+ if?: string | boolean;
227
+ }
228
+ /**
229
+ * TaskSpecV1beta3
230
+ *
231
+ * @public
232
+ */
233
+ interface TaskSpecV1beta3 {
234
+ apiVersion: 'scaffolder.backstage.io/v1beta3';
235
+ baseUrl?: string;
236
+ parameters: JsonObject;
237
+ steps: TaskStep[];
238
+ output: {
239
+ [name: string]: JsonValue;
240
+ };
241
+ metadata?: TemplateMetadata;
242
+ }
243
+ /**
244
+ * TaskSpec
245
+ *
246
+ * @public
247
+ */
248
+ declare type TaskSpec = TaskSpecV1beta2 | TaskSpecV1beta3;
249
+ /**
250
+ * TaskSecrets
251
+ *
252
+ * @public
253
+ */
254
+ declare type TaskSecrets = {
255
+ token: string | undefined;
256
+ };
257
+ /**
258
+ * DispatchResult
259
+ *
260
+ * @public
261
+ */
262
+ declare type DispatchResult = {
263
+ taskId: string;
264
+ };
265
+ /**
266
+ * Task
267
+ *
268
+ * @public
269
+ */
270
+ interface TaskContext {
271
+ spec: TaskSpec;
272
+ secrets?: TaskSecrets;
273
+ done: boolean;
274
+ emitLog(message: string, metadata?: JsonValue): Promise<void>;
275
+ complete(result: CompletedTaskState, metadata?: JsonValue): Promise<void>;
276
+ getWorkspaceName(): Promise<string>;
277
+ }
278
+ /**
279
+ * TaskBroker
280
+ *
281
+ * @public
282
+ */
283
+ interface TaskBroker {
284
+ claim(): Promise<TaskContext>;
285
+ dispatch(spec: TaskSpec, secrets?: TaskSecrets): Promise<DispatchResult>;
286
+ vacuumTasks(timeoutS: {
287
+ timeoutS: number;
288
+ }): Promise<void>;
289
+ observe(options: {
290
+ taskId: string;
291
+ after: number | undefined;
292
+ }, callback: (error: Error | undefined, result: {
293
+ events: SerializedTaskEvent[];
294
+ }) => void): {
295
+ unsubscribe: () => void;
296
+ };
297
+ get(taskId: string): Promise<SerializedTask>;
298
+ }
299
+ /**
300
+ * TaskStoreEmitOptions
301
+ *
302
+ * @public
303
+ */
304
+ declare type TaskStoreEmitOptions = {
305
+ taskId: string;
306
+ body: JsonObject;
307
+ };
308
+ /**
309
+ * TaskStoreListEventsOptions
310
+ *
311
+ * @public
312
+ */
313
+ declare type TaskStoreListEventsOptions = {
314
+ taskId: string;
315
+ after?: number | undefined;
316
+ };
317
+ /**
318
+ * TaskStore
319
+ *
320
+ * @public
321
+ */
322
+ interface TaskStore {
323
+ createTask(task: TaskSpec, secrets?: TaskSecrets): Promise<{
324
+ taskId: string;
325
+ }>;
326
+ getTask(taskId: string): Promise<SerializedTask>;
327
+ claimTask(): Promise<SerializedTask | undefined>;
328
+ completeTask(options: {
329
+ taskId: string;
330
+ status: Status;
331
+ eventBody: JsonObject;
332
+ }): Promise<void>;
333
+ heartbeatTask(taskId: string): Promise<void>;
334
+ listStaleTasks(options: {
335
+ timeoutS: number;
336
+ }): Promise<{
337
+ tasks: {
338
+ taskId: string;
339
+ }[];
340
+ }>;
341
+ emitLogEvent({ taskId, body }: TaskStoreEmitOptions): Promise<void>;
342
+ listEvents({ taskId, after, }: TaskStoreListEventsOptions): Promise<{
343
+ events: SerializedTaskEvent[];
344
+ }>;
345
+ }
346
+
147
347
  declare type PartialJsonObject = Partial<JsonObject>;
148
348
  declare type PartialJsonValue = PartialJsonObject | JsonValue | undefined;
149
349
  declare type InputBase = Partial<{
@@ -167,6 +367,7 @@ declare type ActionContext<Input extends InputBase> = {
167
367
  * Creates a temporary directory for use by the action, which is then cleaned up automatically.
168
368
  */
169
369
  createTemporaryDirectory(): Promise<string>;
370
+ metadata?: TemplateMetadata;
170
371
  };
171
372
  declare type TemplateAction<Input extends InputBase> = {
172
373
  id: string;
@@ -186,9 +387,112 @@ declare class TemplateActionRegistry {
186
387
  }
187
388
 
188
389
  declare const createTemplateAction: <Input extends Partial<{
189
- [name: string]: _backstage_config.JsonValue | Partial<_backstage_config.JsonObject> | undefined;
390
+ [name: string]: _backstage_types.JsonValue | Partial<_backstage_types.JsonObject> | undefined;
190
391
  }>>(templateAction: TemplateAction<Input>) => TemplateAction<any>;
191
392
 
393
+ /**
394
+ * DatabaseTaskStore
395
+ *
396
+ * @public
397
+ */
398
+ declare type DatabaseTaskStoreOptions = {
399
+ database: Knex;
400
+ };
401
+ /**
402
+ * DatabaseTaskStore
403
+ *
404
+ * @public
405
+ */
406
+ declare class DatabaseTaskStore implements TaskStore {
407
+ private readonly db;
408
+ static create(options: DatabaseTaskStoreOptions): Promise<DatabaseTaskStore>;
409
+ constructor(options: DatabaseTaskStoreOptions);
410
+ getTask(taskId: string): Promise<SerializedTask>;
411
+ createTask(spec: TaskSpec, secrets?: TaskSecrets): Promise<{
412
+ taskId: string;
413
+ }>;
414
+ claimTask(): Promise<SerializedTask | undefined>;
415
+ heartbeatTask(taskId: string): Promise<void>;
416
+ listStaleTasks({ timeoutS }: {
417
+ timeoutS: number;
418
+ }): Promise<{
419
+ tasks: {
420
+ taskId: string;
421
+ }[];
422
+ }>;
423
+ completeTask({ taskId, status, eventBody, }: {
424
+ taskId: string;
425
+ status: Status;
426
+ eventBody: JsonObject;
427
+ }): Promise<void>;
428
+ emitLogEvent({ taskId, body }: TaskStoreEmitOptions): Promise<void>;
429
+ listEvents({ taskId, after, }: TaskStoreListEventsOptions): Promise<{
430
+ events: SerializedTaskEvent[];
431
+ }>;
432
+ }
433
+
434
+ /**
435
+ * TaskManager
436
+ *
437
+ * @public
438
+ */
439
+ declare class TaskManager implements TaskContext {
440
+ private readonly state;
441
+ private readonly storage;
442
+ private readonly logger;
443
+ private isDone;
444
+ private heartbeatTimeoutId?;
445
+ static create(state: TaskState, storage: TaskStore, logger: Logger): TaskManager;
446
+ private constructor();
447
+ get spec(): TaskSpec;
448
+ get secrets(): TaskSecrets | undefined;
449
+ getWorkspaceName(): Promise<string>;
450
+ get done(): boolean;
451
+ emitLog(message: string, metadata?: JsonObject): Promise<void>;
452
+ complete(result: CompletedTaskState, metadata?: JsonObject): Promise<void>;
453
+ private startTimeout;
454
+ }
455
+ /**
456
+ * TaskState
457
+ *
458
+ * @public
459
+ */
460
+ interface TaskState {
461
+ spec: TaskSpec;
462
+ taskId: string;
463
+ secrets?: TaskSecrets;
464
+ }
465
+
466
+ /**
467
+ * CreateWorkerOptions
468
+ *
469
+ * @public
470
+ */
471
+ declare type CreateWorkerOptions = {
472
+ taskBroker: TaskBroker;
473
+ actionRegistry: TemplateActionRegistry;
474
+ integrations: ScmIntegrations;
475
+ workingDirectory: string;
476
+ logger: Logger;
477
+ };
478
+ /**
479
+ * TaskWorker
480
+ *
481
+ * @public
482
+ */
483
+ declare class TaskWorker {
484
+ private readonly options;
485
+ private constructor();
486
+ static create(options: CreateWorkerOptions): Promise<TaskWorker>;
487
+ start(): void;
488
+ runOneTask(task: TaskContext): Promise<void>;
489
+ }
490
+
491
+ /**
492
+ * RouterOptions
493
+ *
494
+ * @public
495
+ */
192
496
  interface RouterOptions {
193
497
  logger: Logger;
194
498
  config: Config;
@@ -198,6 +502,7 @@ interface RouterOptions {
198
502
  actions?: TemplateAction<any>[];
199
503
  taskWorkers?: number;
200
504
  containerRunner: ContainerRunner;
505
+ taskBroker?: TaskBroker;
201
506
  }
202
507
  declare function createRouter(options: RouterOptions): Promise<express.Router>;
203
508
 
@@ -224,4 +529,4 @@ declare class ScaffolderEntitiesProcessor implements CatalogProcessor {
224
529
  postProcessEntity(entity: Entity, _location: LocationSpec, emit: CatalogProcessorEmit): Promise<Entity>;
225
530
  }
226
531
 
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 };
532
+ 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, TemplateMetadata, 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.9",
4
+ "version": "0.15.13",
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.10",
34
+ "@backstage/catalog-client": "^0.5.2",
35
+ "@backstage/catalog-model": "^0.9.7",
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.4",
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.9.0",
75
+ "@backstage/test-utils": "^0.1.22",
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": "0995c9cc5bb68ff8b847a08dd46a20cf39048213"
94
+ "gitHead": "ddfdcd2b44dc9848cf550cea5346d5f9916a36d9"
94
95
  }