@backstage/plugin-scaffolder-node 0.8.3-next.1 → 0.9.0

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,149 @@
1
1
  # @backstage/plugin-scaffolder-node
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5863b04: **BREAKING CHANGES**
8
+
9
+ The legacy methods to define `createTemplateActions` have been replaced with the new native `zod` approaches for defining input and output schemas.
10
+
11
+ You can migrate actions that look like the following with the below examples:
12
+
13
+ ```ts
14
+ // really old legacy json schema
15
+ createTemplateAction<{ repoUrl: string }, { repoOutput: string }>({
16
+ id: 'test',
17
+ schema: {
18
+ input: {
19
+ type: 'object'
20
+ required: ['repoUrl']
21
+ properties: {
22
+ repoUrl: {
23
+ type: 'string',
24
+ description: 'repository url description'
25
+ }
26
+ }
27
+ }
28
+ }
29
+ });
30
+
31
+ // old zod method
32
+ createTemplateAction({
33
+ id: 'test'
34
+ schema: {
35
+ input: {
36
+ repoUrl: z.string({ description: 'repository url description' })
37
+ }
38
+ }
39
+ })
40
+
41
+ // new method:
42
+ createTemplateAction({
43
+ id: 'test',
44
+ schema: {
45
+ input: {
46
+ repoUrl: z => z.string({ description: 'repository url description' })
47
+ }
48
+ }
49
+ })
50
+
51
+ // or for more complex zod types like unions
52
+ createTemplateAction({
53
+ id: 'test',
54
+ schema: {
55
+ input: z => z.object({
56
+ repoUrl: z.string({ description: 'repository url description' })
57
+ })
58
+ }
59
+ })
60
+ ```
61
+
62
+ This breaking change also means that `logStream` has been removed entirely from `ActionsContext`, and that the `logger` is now just a `LoggerService` implementation instead. There is no replacement for the `logStream`, if you wish to still keep using a `logStream` we recommend that you create your own stream that writes to `ctx.logger` instead.
63
+
64
+ ### Patch Changes
65
+
66
+ - e89d7b6: Use `LoggerService` instead of `Logger`. This is a non-breaking change, as the `LoggerService` is a subset of the `Logger` interface.
67
+ - 9c8ff0c: Update pull request creation filter to include .gitignore files in the created pull request
68
+ - Updated dependencies
69
+ - @backstage/backend-plugin-api@1.4.0
70
+ - @backstage/catalog-model@1.7.4
71
+ - @backstage/errors@1.2.7
72
+ - @backstage/integration@1.17.0
73
+ - @backstage/types@1.2.1
74
+ - @backstage/plugin-scaffolder-common@1.5.11
75
+
76
+ ## 0.9.0-next.2
77
+
78
+ ### Minor Changes
79
+
80
+ - 5863b04: **BREAKING CHANGES**
81
+
82
+ The legacy methods to define `createTemplateActions` have been replaced with the new native `zod` approaches for defining input and output schemas.
83
+
84
+ You can migrate actions that look like the following with the below examples:
85
+
86
+ ```ts
87
+ // really old legacy json schema
88
+ createTemplateAction<{ repoUrl: string }, { repoOutput: string }>({
89
+ id: 'test',
90
+ schema: {
91
+ input: {
92
+ type: 'object'
93
+ required: ['repoUrl']
94
+ properties: {
95
+ repoUrl: {
96
+ type: 'string',
97
+ description: 'repository url description'
98
+ }
99
+ }
100
+ }
101
+ }
102
+ });
103
+
104
+ // old zod method
105
+ createTemplateAction({
106
+ id: 'test'
107
+ schema: {
108
+ input: {
109
+ repoUrl: z.string({ description: 'repository url description' })
110
+ }
111
+ }
112
+ })
113
+
114
+ // new method:
115
+ createTemplateAction({
116
+ id: 'test',
117
+ schema: {
118
+ input: {
119
+ repoUrl: z => z.string({ description: 'repository url description' })
120
+ }
121
+ }
122
+ })
123
+
124
+ // or for more complex zod types like unions
125
+ createTemplateAction({
126
+ id: 'test',
127
+ schema: {
128
+ input: z => z.object({
129
+ repoUrl: z.string({ description: 'repository url description' })
130
+ })
131
+ }
132
+ })
133
+ ```
134
+
135
+ This breaking change also means that `logStream` has been removed entirely from `ActionsContext`, and that the `logger` is now just a `LoggerService` implementation instead. There is no replacement for the `logStream`, if you wish to still keep using a `logStream` we recommend that you create your own stream that writes to `ctx.logger` instead.
136
+
137
+ ### Patch Changes
138
+
139
+ - Updated dependencies
140
+ - @backstage/backend-plugin-api@1.4.0-next.1
141
+ - @backstage/catalog-model@1.7.4
142
+ - @backstage/errors@1.2.7
143
+ - @backstage/integration@1.17.0
144
+ - @backstage/types@1.2.1
145
+ - @backstage/plugin-scaffolder-common@1.5.11
146
+
3
147
  ## 0.8.3-next.1
4
148
 
5
149
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"createTemplateAction.cjs.js","sources":["../../src/actions/createTemplateAction.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { ActionContext, TemplateAction } from './types';\nimport { z } from 'zod';\nimport { Expand, JsonObject } from '@backstage/types';\nimport { parseSchemas } from './util';\n\n/** @public */\nexport type TemplateExample = {\n description: string;\n example: string;\n};\n\n/** @public */\nexport type TemplateActionOptions<\n TActionInput extends JsonObject = {},\n TActionOutput extends JsonObject = {},\n TInputSchema extends\n | JsonObject\n | z.ZodType\n | { [key in string]: (zImpl: typeof z) => z.ZodType } = JsonObject,\n TOutputSchema extends\n | JsonObject\n | z.ZodType\n | { [key in string]: (zImpl: typeof z) => z.ZodType } = JsonObject,\n TSchemaType extends 'v1' | 'v2' = 'v1' | 'v2',\n> = {\n id: string;\n description?: string;\n examples?: TemplateExample[];\n supportsDryRun?: boolean;\n schema?: {\n input?: TInputSchema;\n output?: TOutputSchema;\n };\n handler: (\n ctx: ActionContext<TActionInput, TActionOutput, TSchemaType>,\n ) => Promise<void>;\n};\n\n/**\n * @ignore\n */\ntype FlattenOptionalProperties<T extends { [key in string]: unknown }> = Expand<\n {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K];\n } & {\n [K in keyof T as undefined extends T[K] ? K : never]?: T[K];\n }\n>;\n\n/**\n * @public\n * @deprecated migrate to using the new built in zod schema definitions for schemas\n */\nexport function createTemplateAction<\n TInputParams extends JsonObject = JsonObject,\n TOutputParams extends JsonObject = JsonObject,\n TInputSchema extends JsonObject = JsonObject,\n TOutputSchema extends JsonObject = JsonObject,\n TActionInput extends JsonObject = TInputParams,\n TActionOutput extends JsonObject = TOutputParams,\n>(\n action: TemplateActionOptions<\n TActionInput,\n TActionOutput,\n TInputSchema,\n TOutputSchema,\n 'v1'\n >,\n): TemplateAction<TActionInput, TActionOutput, 'v1'>;\n/**\n * @public\n * @deprecated migrate to using the new built in zod schema definitions for schemas\n */\nexport function createTemplateAction<\n TInputParams extends JsonObject = JsonObject,\n TOutputParams extends JsonObject = JsonObject,\n TInputSchema extends z.ZodType = z.ZodType,\n TOutputSchema extends z.ZodType = z.ZodType,\n TActionInput extends JsonObject = z.infer<TInputSchema>,\n TActionOutput extends JsonObject = z.infer<TOutputSchema>,\n>(\n action: TemplateActionOptions<\n TActionInput,\n TActionOutput,\n TInputSchema,\n TOutputSchema,\n 'v1'\n >,\n): TemplateAction<TActionInput, TActionOutput, 'v1'>;\n/**\n * This function is used to create new template actions to get type safety.\n * Will convert zod schemas to json schemas for use throughout the system.\n * @public\n */\nexport function createTemplateAction<\n TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType },\n TOutputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType },\n>(\n action: TemplateActionOptions<\n {\n [key in keyof TInputSchema]: z.infer<ReturnType<TInputSchema[key]>>;\n },\n {\n [key in keyof TOutputSchema]: z.infer<ReturnType<TOutputSchema[key]>>;\n },\n TInputSchema,\n TOutputSchema,\n 'v2'\n >,\n): TemplateAction<\n FlattenOptionalProperties<{\n [key in keyof TInputSchema]: z.output<ReturnType<TInputSchema[key]>>;\n }>,\n FlattenOptionalProperties<{\n [key in keyof TOutputSchema]: z.output<ReturnType<TOutputSchema[key]>>;\n }>,\n 'v2'\n>;\nexport function createTemplateAction<\n TInputParams extends JsonObject = JsonObject,\n TOutputParams extends JsonObject = JsonObject,\n TInputSchema extends\n | JsonObject\n | z.ZodType\n | { [key in string]: (zImpl: typeof z) => z.ZodType } = JsonObject,\n TOutputSchema extends\n | JsonObject\n | z.ZodType\n | { [key in string]: (zImpl: typeof z) => z.ZodType } = JsonObject,\n TActionInput extends JsonObject = TInputSchema extends z.ZodType<\n any,\n any,\n infer IReturn\n >\n ? IReturn\n : TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? Expand<{\n [key in keyof TInputSchema]: z.infer<ReturnType<TInputSchema[key]>>;\n }>\n : TInputParams,\n TActionOutput extends JsonObject = TOutputSchema extends z.ZodType<\n any,\n any,\n infer IReturn\n >\n ? IReturn\n : TOutputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? Expand<{\n [key in keyof TOutputSchema]: z.infer<ReturnType<TOutputSchema[key]>>;\n }>\n : TOutputParams,\n>(\n action: TemplateActionOptions<\n TActionInput,\n TActionOutput,\n TInputSchema,\n TOutputSchema\n >,\n): TemplateAction<\n TActionInput,\n TActionOutput,\n TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? 'v2'\n : 'v1'\n> {\n const { inputSchema, outputSchema } = parseSchemas(\n action as TemplateActionOptions<any, any, any>,\n );\n\n return {\n ...action,\n schema: {\n ...action.schema,\n input: inputSchema,\n output: outputSchema,\n },\n };\n}\n"],"names":["parseSchemas"],"mappings":";;;;AAsIO,SAAS,qBAkCd,MAYA,EAAA;AACA,EAAM,MAAA,EAAE,WAAa,EAAA,YAAA,EAAiB,GAAAA,iBAAA;AAAA,IACpC;AAAA,GACF;AAEA,EAAO,OAAA;AAAA,IACL,GAAG,MAAA;AAAA,IACH,MAAQ,EAAA;AAAA,MACN,GAAG,MAAO,CAAA,MAAA;AAAA,MACV,KAAO,EAAA,WAAA;AAAA,MACP,MAAQ,EAAA;AAAA;AACV,GACF;AACF;;;;"}
1
+ {"version":3,"file":"createTemplateAction.cjs.js","sources":["../../src/actions/createTemplateAction.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { ActionContext, TemplateAction } from './types';\nimport { z } from 'zod';\nimport { Expand, JsonObject } from '@backstage/types';\nimport { parseSchemas } from './util';\n\n/** @public */\nexport type TemplateExample = {\n description: string;\n example: string;\n};\n\n/** @public */\nexport type TemplateActionOptions<\n TActionInput extends JsonObject = {},\n TActionOutput extends JsonObject = {},\n TInputSchema extends\n | { [key in string]: (zImpl: typeof z) => z.ZodType }\n | ((zImpl: typeof z) => z.ZodType) = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TOutputSchema extends\n | {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n }\n | ((zImpl: typeof z) => z.ZodType) = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TSchemaType extends 'v2' = 'v2',\n> = {\n id: string;\n description?: string;\n examples?: TemplateExample[];\n supportsDryRun?: boolean;\n schema?: {\n input?: TInputSchema;\n output?: TOutputSchema;\n };\n handler: (\n ctx: ActionContext<TActionInput, TActionOutput, TSchemaType>,\n ) => Promise<void>;\n};\n\n/**\n * @ignore\n */\ntype FlattenOptionalProperties<T extends { [key in string]: unknown }> = Expand<\n {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K];\n } & {\n [K in keyof T as undefined extends T[K] ? K : never]?: T[K];\n }\n>;\n/**\n * This function is used to create new template actions to get type safety.\n * Will convert zod schemas to json schemas for use throughout the system.\n * @public\n */\nexport function createTemplateAction<\n TInputSchema extends\n | { [key in string]: (zImpl: typeof z) => z.ZodType }\n | ((zImpl: typeof z) => z.ZodType),\n TOutputSchema extends\n | { [key in string]: (zImpl: typeof z) => z.ZodType }\n | ((zImpl: typeof z) => z.ZodType),\n>(\n action: TemplateActionOptions<\n TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TInputSchema]: z.infer<ReturnType<TInputSchema[key]>>;\n }\n : TInputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.infer<ReturnType<TInputSchema>>\n : never,\n TOutputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TOutputSchema]: z.infer<ReturnType<TOutputSchema[key]>>;\n }\n : TOutputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.infer<ReturnType<TOutputSchema>>\n : never,\n TInputSchema,\n TOutputSchema,\n 'v2'\n >,\n): TemplateAction<\n FlattenOptionalProperties<\n TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TInputSchema]: z.output<ReturnType<TInputSchema[key]>>;\n }\n : TInputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.output<ReturnType<TInputSchema>>\n : never\n >,\n FlattenOptionalProperties<\n TOutputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType }\n ? {\n [key in keyof TOutputSchema]: z.output<\n ReturnType<TOutputSchema[key]>\n >;\n }\n : TOutputSchema extends (zImpl: typeof z) => z.ZodType\n ? z.output<ReturnType<TOutputSchema>>\n : never\n >,\n 'v2'\n>;\nexport function createTemplateAction<\n TInputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType } = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TOutputSchema extends { [key in string]: (zImpl: typeof z) => z.ZodType } = {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n },\n TActionInput extends JsonObject = TInputSchema extends {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n }\n ? Expand<{\n [key in keyof TInputSchema]: z.infer<ReturnType<TInputSchema[key]>>;\n }>\n : never,\n TActionOutput extends JsonObject = TOutputSchema extends {\n [key in string]: (zImpl: typeof z) => z.ZodType;\n }\n ? Expand<{\n [key in keyof TOutputSchema]: z.infer<ReturnType<TOutputSchema[key]>>;\n }>\n : never,\n>(\n action: TemplateActionOptions<\n TActionInput,\n TActionOutput,\n TInputSchema,\n TOutputSchema\n >,\n): TemplateAction<TActionInput, TActionOutput, 'v2'> {\n const { inputSchema, outputSchema } = parseSchemas(\n action as TemplateActionOptions<any, any, any>,\n );\n\n return {\n ...action,\n schema: {\n ...action.schema,\n input: inputSchema,\n output: outputSchema,\n },\n };\n}\n"],"names":["parseSchemas"],"mappings":";;;;AA2HO,SAAS,qBAsBd,MAMmD,EAAA;AACnD,EAAM,MAAA,EAAE,WAAa,EAAA,YAAA,EAAiB,GAAAA,iBAAA;AAAA,IACpC;AAAA,GACF;AAEA,EAAO,OAAA;AAAA,IACL,GAAG,MAAA;AAAA,IACH,MAAQ,EAAA;AAAA,MACN,GAAG,MAAO,CAAA,MAAA;AAAA,MACV,KAAO,EAAA,WAAA;AAAA,MACP,MAAQ,EAAA;AAAA;AACV,GACF;AACF;;;;"}
@@ -89,23 +89,17 @@ function checkRequiredParams(repoUrl, ...params) {
89
89
  }
90
90
  }
91
91
  }
92
- const isZodSchema = (schema) => {
93
- return typeof schema === "object" && !!schema && "safeParseAsync" in schema;
94
- };
95
- const isNativeZodSchema = (schema) => {
92
+ const isKeyValueZodCallback = (schema) => {
96
93
  return typeof schema === "object" && !!schema && Object.values(schema).every((v) => typeof v === "function");
97
94
  };
95
+ const isZodFunctionDefinition = (schema) => {
96
+ return typeof schema === "function";
97
+ };
98
98
  const parseSchemas = (action) => {
99
99
  if (!action.schema) {
100
100
  return { inputSchema: void 0, outputSchema: void 0 };
101
101
  }
102
- if (isZodSchema(action.schema.input)) {
103
- return {
104
- inputSchema: zodToJsonSchema__default.default(action.schema.input),
105
- outputSchema: isZodSchema(action.schema.output) ? zodToJsonSchema__default.default(action.schema.output) : void 0
106
- };
107
- }
108
- if (isNativeZodSchema(action.schema.input)) {
102
+ if (isKeyValueZodCallback(action.schema.input)) {
109
103
  const input = zod.z.object(
110
104
  Object.fromEntries(
111
105
  Object.entries(action.schema.input).map(([k, v]) => [k, v(zod.z)])
@@ -113,7 +107,7 @@ const parseSchemas = (action) => {
113
107
  );
114
108
  return {
115
109
  inputSchema: zodToJsonSchema__default.default(input),
116
- outputSchema: isNativeZodSchema(action.schema.output) ? zodToJsonSchema__default.default(
110
+ outputSchema: isKeyValueZodCallback(action.schema.output) ? zodToJsonSchema__default.default(
117
111
  zod.z.object(
118
112
  Object.fromEntries(
119
113
  Object.entries(action.schema.output).map(([k, v]) => [k, v(zod.z)])
@@ -122,9 +116,15 @@ const parseSchemas = (action) => {
122
116
  ) : void 0
123
117
  };
124
118
  }
119
+ if (isZodFunctionDefinition(action.schema.input)) {
120
+ return {
121
+ inputSchema: zodToJsonSchema__default.default(action.schema.input(zod.z)),
122
+ outputSchema: isZodFunctionDefinition(action.schema.output) ? zodToJsonSchema__default.default(action.schema.output(zod.z)) : void 0
123
+ };
124
+ }
125
125
  return {
126
- inputSchema: action.schema.input,
127
- outputSchema: action.schema.output
126
+ inputSchema: void 0,
127
+ outputSchema: void 0
128
128
  };
129
129
  };
130
130
  function isNotGitDirectoryOrContents(path) {
@@ -1 +1 @@
1
- {"version":3,"file":"util.cjs.js","sources":["../../src/actions/util.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { InputError } from '@backstage/errors';\nimport { isChildPath } from '@backstage/backend-plugin-api';\nimport { join as joinPath, normalize as normalizePath } from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { TemplateActionOptions } from './createTemplateAction';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { z } from 'zod';\nimport { Schema } from 'jsonschema';\nimport { trim } from 'lodash';\n\n/**\n * @public\n */\nexport const getRepoSourceDirectory = (\n workspacePath: string,\n sourcePath: string | undefined,\n) => {\n if (sourcePath) {\n const safeSuffix = normalizePath(sourcePath).replace(\n /^(\\.\\.(\\/|\\\\|$))+/,\n '',\n );\n const path = joinPath(workspacePath, safeSuffix);\n if (!isChildPath(workspacePath, path)) {\n throw new Error('Invalid source path');\n }\n return path;\n }\n return workspacePath;\n};\n\n/**\n * @public\n */\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): {\n repo: string;\n host: string;\n owner?: string;\n organization?: string;\n workspace?: string;\n project?: string;\n} => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n const { owner, organization, workspace, project, repo } = Object.fromEntries(\n ['owner', 'organization', 'workspace', 'project', 'repo'].map(param => [\n param,\n parsed.searchParams.has(param)\n ? trim(parsed.searchParams.get(param)!, '/')\n : undefined,\n ]),\n );\n switch (type) {\n case 'bitbucket': {\n if (host === 'www.bitbucket.org') {\n checkRequiredParams(parsed, 'workspace');\n }\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'azure': {\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'gitlab': {\n // project is the projectID, and if defined, owner and repo won't be needed.\n if (!project) {\n checkRequiredParams(parsed, 'owner', 'repo');\n }\n break;\n }\n case 'gitea': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n case 'gerrit': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n default: {\n checkRequiredParams(parsed, 'repo', 'owner');\n break;\n }\n }\n return { host, owner, repo: repo!, organization, workspace, project };\n};\n\nfunction checkRequiredParams(repoUrl: URL, ...params: string[]) {\n for (let i = 0; i < params.length; i++) {\n if (!repoUrl.searchParams.get(params[i])) {\n throw new InputError(\n `Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${\n params[i]\n }`,\n );\n }\n }\n}\n\nconst isZodSchema = (schema: unknown): schema is z.ZodType => {\n return typeof schema === 'object' && !!schema && 'safeParseAsync' in schema;\n};\n\nconst isNativeZodSchema = (\n schema: unknown,\n): schema is { [key in string]: (zImpl: typeof z) => z.ZodType } => {\n return (\n typeof schema === 'object' &&\n !!schema &&\n Object.values(schema).every(v => typeof v === 'function')\n );\n};\n\nexport const parseSchemas = (\n action: TemplateActionOptions,\n): { inputSchema?: Schema; outputSchema?: Schema } => {\n if (!action.schema) {\n return { inputSchema: undefined, outputSchema: undefined };\n }\n\n if (isZodSchema(action.schema.input)) {\n return {\n inputSchema: zodToJsonSchema(action.schema.input) as Schema,\n outputSchema: isZodSchema(action.schema.output)\n ? (zodToJsonSchema(action.schema.output) as Schema)\n : undefined,\n };\n }\n\n if (isNativeZodSchema(action.schema.input)) {\n const input = z.object(\n Object.fromEntries(\n Object.entries(action.schema.input).map(([k, v]) => [k, v(z)]),\n ),\n );\n\n return {\n inputSchema: zodToJsonSchema(input) as Schema,\n outputSchema: isNativeZodSchema(action.schema.output)\n ? (zodToJsonSchema(\n z.object(\n Object.fromEntries(\n Object.entries(action.schema.output).map(([k, v]) => [k, v(z)]),\n ),\n ),\n ) as Schema)\n : undefined,\n };\n }\n\n return {\n inputSchema: action.schema.input,\n outputSchema: action.schema.output,\n };\n};\n\n/**\n * Filter function to exclude the .git directory and its contents\n * while keeping other files like .gitignore\n * @public\n */\nexport function isNotGitDirectoryOrContents(path: string): boolean {\n return !(path.endsWith('.git') || path.includes('.git/'));\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A;AAAA,MACd,MAAO,CAAA,WAAA;AAAA,QACL,OAAO,OAAQ,CAAA,MAAA,CAAO,MAAO,CAAA,KAAK,EAAE,GAAI,CAAA,CAAC,CAAC,CAAA,EAAG,CAAC,CAAM,KAAA,CAAC,GAAG,CAAE,CAAAA,KAAC,CAAC,CAAC;AAAA;AAC/D,KACF;AAEA,IAAO,OAAA;AAAA,MACL,WAAA,EAAaD,iCAAgB,KAAK,CAAA;AAAA,MAClC,YAAc,EAAA,iBAAA,CAAkB,MAAO,CAAA,MAAA,CAAO,MAAM,CAC/C,GAAAA,gCAAA;AAAA,QACCC,KAAE,CAAA,MAAA;AAAA,UACA,MAAO,CAAA,WAAA;AAAA,YACL,OAAO,OAAQ,CAAA,MAAA,CAAO,MAAO,CAAA,MAAM,EAAE,GAAI,CAAA,CAAC,CAAC,CAAA,EAAG,CAAC,CAAM,KAAA,CAAC,GAAG,CAAE,CAAAA,KAAC,CAAC,CAAC;AAAA;AAChE;AACF,OAEF,GAAA,KAAA;AAAA,KACN;AAAA;AAGF,EAAO,OAAA;AAAA,IACL,WAAA,EAAa,OAAO,MAAO,CAAA,KAAA;AAAA,IAC3B,YAAA,EAAc,OAAO,MAAO,CAAA;AAAA,GAC9B;AACF;AAOO,SAAS,4BAA4B,IAAuB,EAAA;AACjE,EAAA,OAAO,EAAE,IAAK,CAAA,QAAA,CAAS,MAAM,CAAK,IAAA,IAAA,CAAK,SAAS,OAAO,CAAA,CAAA;AACzD;;;;;;;"}
1
+ {"version":3,"file":"util.cjs.js","sources":["../../src/actions/util.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { InputError } from '@backstage/errors';\nimport { isChildPath } from '@backstage/backend-plugin-api';\nimport { join as joinPath, normalize as normalizePath } from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { TemplateActionOptions } from './createTemplateAction';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { z } from 'zod';\nimport { Schema } from 'jsonschema';\nimport { trim } from 'lodash';\n\n/**\n * @public\n */\nexport const getRepoSourceDirectory = (\n workspacePath: string,\n sourcePath: string | undefined,\n) => {\n if (sourcePath) {\n const safeSuffix = normalizePath(sourcePath).replace(\n /^(\\.\\.(\\/|\\\\|$))+/,\n '',\n );\n const path = joinPath(workspacePath, safeSuffix);\n if (!isChildPath(workspacePath, path)) {\n throw new Error('Invalid source path');\n }\n return path;\n }\n return workspacePath;\n};\n\n/**\n * @public\n */\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): {\n repo: string;\n host: string;\n owner?: string;\n organization?: string;\n workspace?: string;\n project?: string;\n} => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n const { owner, organization, workspace, project, repo } = Object.fromEntries(\n ['owner', 'organization', 'workspace', 'project', 'repo'].map(param => [\n param,\n parsed.searchParams.has(param)\n ? trim(parsed.searchParams.get(param)!, '/')\n : undefined,\n ]),\n );\n switch (type) {\n case 'bitbucket': {\n if (host === 'www.bitbucket.org') {\n checkRequiredParams(parsed, 'workspace');\n }\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'azure': {\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'gitlab': {\n // project is the projectID, and if defined, owner and repo won't be needed.\n if (!project) {\n checkRequiredParams(parsed, 'owner', 'repo');\n }\n break;\n }\n case 'gitea': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n case 'gerrit': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n default: {\n checkRequiredParams(parsed, 'repo', 'owner');\n break;\n }\n }\n return { host, owner, repo: repo!, organization, workspace, project };\n};\n\nfunction checkRequiredParams(repoUrl: URL, ...params: string[]) {\n for (let i = 0; i < params.length; i++) {\n if (!repoUrl.searchParams.get(params[i])) {\n throw new InputError(\n `Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${\n params[i]\n }`,\n );\n }\n }\n}\n\nconst isKeyValueZodCallback = (\n schema: unknown,\n): schema is { [key in string]: (zImpl: typeof z) => z.ZodType } => {\n return (\n typeof schema === 'object' &&\n !!schema &&\n Object.values(schema).every(v => typeof v === 'function')\n );\n};\n\nconst isZodFunctionDefinition = (\n schema: unknown,\n): schema is (zImpl: typeof z) => z.ZodType => {\n return typeof schema === 'function';\n};\n\nexport const parseSchemas = (\n action: TemplateActionOptions<any, any, any>,\n): { inputSchema?: Schema; outputSchema?: Schema } => {\n if (!action.schema) {\n return { inputSchema: undefined, outputSchema: undefined };\n }\n\n if (isKeyValueZodCallback(action.schema.input)) {\n const input = z.object(\n Object.fromEntries(\n Object.entries(action.schema.input).map(([k, v]) => [k, v(z)]),\n ),\n );\n\n return {\n inputSchema: zodToJsonSchema(input) as Schema,\n outputSchema: isKeyValueZodCallback(action.schema.output)\n ? (zodToJsonSchema(\n z.object(\n Object.fromEntries(\n Object.entries(action.schema.output).map(([k, v]) => [k, v(z)]),\n ),\n ),\n ) as Schema)\n : undefined,\n };\n }\n\n if (isZodFunctionDefinition(action.schema.input)) {\n return {\n inputSchema: zodToJsonSchema(action.schema.input(z)) as Schema,\n outputSchema: isZodFunctionDefinition(action.schema.output)\n ? (zodToJsonSchema(action.schema.output(z)) as Schema)\n : undefined,\n };\n }\n\n return {\n inputSchema: undefined,\n outputSchema: undefined,\n };\n};\n\n/**\n * Filter function to exclude the .git directory and its contents\n * while keeping other files like .gitignore\n * @public\n */\nexport function isNotGitDirectoryOrContents(path: string): boolean {\n return !(path.endsWith('.git') || path.includes('.git/'));\n}\n"],"names":["normalizePath","path","joinPath","isChildPath","InputError","trim","z","zodToJsonSchema"],"mappings":";;;;;;;;;;;;;AA6Ba,MAAA,sBAAA,GAAyB,CACpC,aAAA,EACA,UACG,KAAA;AACH,EAAA,IAAI,UAAY,EAAA;AACd,IAAM,MAAA,UAAA,GAAaA,cAAc,CAAA,UAAU,CAAE,CAAA,OAAA;AAAA,MAC3C,mBAAA;AAAA,MACA;AAAA,KACF;AACA,IAAM,MAAAC,MAAA,GAAOC,SAAS,CAAA,aAAA,EAAe,UAAU,CAAA;AAC/C,IAAA,IAAI,CAACC,4BAAA,CAAY,aAAe,EAAAF,MAAI,CAAG,EAAA;AACrC,MAAM,MAAA,IAAI,MAAM,qBAAqB,CAAA;AAAA;AAEvC,IAAO,OAAAA,MAAA;AAAA;AAET,EAAO,OAAA,aAAA;AACT;AAKa,MAAA,YAAA,GAAe,CAC1B,OAAA,EACA,YAQG,KAAA;AACH,EAAI,IAAA,MAAA;AACJ,EAAI,IAAA;AACF,IAAA,MAAA,GAAS,IAAI,GAAA,CAAI,CAAW,QAAA,EAAA,OAAO,CAAE,CAAA,CAAA;AAAA,WAC9B,KAAO,EAAA;AACd,IAAA,MAAM,IAAIG,iBAAA;AAAA,MACR,CAAA,0CAAA,EAA6C,OAAO,CAAA,EAAA,EAAK,KAAK,CAAA;AAAA,KAChE;AAAA;AAEF,EAAA,MAAM,OAAO,MAAO,CAAA,IAAA;AACpB,EAAA,MAAM,IAAO,GAAA,YAAA,CAAa,MAAO,CAAA,IAAI,CAAG,EAAA,IAAA;AAExC,EAAA,IAAI,CAAC,IAAM,EAAA;AACT,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR,kDAAkD,IAAI,CAAA,uCAAA;AAAA,KACxD;AAAA;AAEF,EAAA,MAAM,EAAE,KA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MACL,WAAA,EAAaC,iCAAgB,KAAK,CAAA;AAAA,MAClC,YAAc,EAAA,qBAAA,CAAsB,MAAO,CAAA,MAAA,CAAO,MAAM,CACnD,GAAAA,gCAAA;AAAA,QACCD,KAAE,CAAA,MAAA;AAAA,UACA,MAAO,CAAA,WAAA;AAAA,YACL,OAAO,OAAQ,CAAA,MAAA,CAAO,MAAO,CAAA,MAAM,EAAE,GAAI,CAAA,CAAC,CAAC,CAAA,EAAG,CAAC,CAAM,KAAA,CAAC,GAAG,CAAE,CAAAA,KAAC,CAAC,CAAC;AAAA;AAChE;AACF,OAEF,GAAA,KAAA;AAAA,KACN;AAAA;AAGF,EAAA,IAAI,uBAAwB,CAAA,MAAA,CAAO,MAAO,CAAA,KAAK,CAAG,EAAA;AAChD,IAAO,OAAA;AAAA,MACL,aAAaC,gCAAgB,CAAA,MAAA,CAAO,MAAO,CAAA,KAAA,CAAMD,KAAC,CAAC,CAAA;AAAA,MACnD,YAAc,EAAA,uBAAA,CAAwB,MAAO,CAAA,MAAA,CAAO,MAAM,CAAA,GACrDC,gCAAgB,CAAA,MAAA,CAAO,MAAO,CAAA,MAAA,CAAOD,KAAC,CAAC,CACxC,GAAA,KAAA;AAAA,KACN;AAAA;AAGF,EAAO,OAAA;AAAA,IACL,WAAa,EAAA,KAAA,CAAA;AAAA,IACb,YAAc,EAAA,KAAA;AAAA,GAChB;AACF;AAOO,SAAS,4BAA4B,IAAuB,EAAA;AACjE,EAAA,OAAO,EAAE,IAAK,CAAA,QAAA,CAAS,MAAM,CAAK,IAAA,IAAA,CAAK,SAAS,OAAO,CAAA,CAAA;AACzD;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { Logger } from 'winston';
2
- import { Writable } from 'stream';
3
1
  import { JsonObject, JsonValue, Observable, Expand } from '@backstage/types';
4
2
  import { BackstageCredentials, LoggerService, UrlReaderService } from '@backstage/backend-plugin-api';
5
3
  import { TaskSpec, TemplateInfo } from '@backstage/plugin-scaffolder-common';
@@ -7,6 +5,7 @@ import { UserEntity } from '@backstage/catalog-model';
7
5
  import { Schema } from 'jsonschema';
8
6
  import { z } from 'zod';
9
7
  import { SpawnOptionsWithoutStdio } from 'child_process';
8
+ import { Writable } from 'stream';
10
9
  import { ScmIntegrations, ScmIntegrationRegistry } from '@backstage/integration';
11
10
  export { T as TemplateFilter, a as TemplateGlobal } from './types/types.d-C0fXdKnD.js';
12
11
 
@@ -178,7 +177,7 @@ interface TaskBroker {
178
177
  * ActionContext is passed into scaffolder actions.
179
178
  * @public
180
179
  */
181
- type ActionContext<TActionInput extends JsonObject, TActionOutput extends JsonObject = JsonObject, TSchemaType extends 'v1' | 'v2' = 'v1'> = TSchemaType extends 'v2' ? {
180
+ type ActionContext<TActionInput extends JsonObject, TActionOutput extends JsonObject = JsonObject, _TSchemaType extends 'v2' = 'v2'> = {
182
181
  logger: LoggerService;
183
182
  secrets?: TaskSecrets;
184
183
  workspacePath: string;
@@ -229,62 +228,9 @@ type ActionContext<TActionInput extends JsonObject, TActionOutput extends JsonOb
229
228
  * Optional value of each invocation
230
229
  */
231
230
  each?: JsonObject;
232
- } : {
233
- logger: Logger;
234
- /** @deprecated - use `ctx.logger` instead */
235
- logStream: Writable;
236
- secrets?: TaskSecrets;
237
- workspacePath: string;
238
- input: TActionInput;
239
- checkpoint<T extends JsonValue | void>(opts: {
240
- key: string;
241
- fn: () => Promise<T> | T;
242
- }): Promise<T>;
243
- output(name: keyof TActionOutput, value: TActionOutput[keyof TActionOutput]): void;
244
- /**
245
- * Creates a temporary directory for use by the action, which is then cleaned up automatically.
246
- */
247
- createTemporaryDirectory(): Promise<string>;
248
- /**
249
- * Get the credentials for the current request
250
- */
251
- getInitiatorCredentials(): Promise<BackstageCredentials>;
252
- /**
253
- * Task information
254
- */
255
- task: {
256
- id: string;
257
- };
258
- templateInfo?: TemplateInfo;
259
- /**
260
- * Whether this action invocation is a dry-run or not.
261
- * This will only ever be true if the actions as marked as supporting dry-runs.
262
- */
263
- isDryRun?: boolean;
264
- /**
265
- * The user which triggered the action.
266
- */
267
- user?: {
268
- /**
269
- * The decorated entity from the Catalog
270
- */
271
- entity?: UserEntity;
272
- /**
273
- * An entity ref for the author of the task
274
- */
275
- ref?: string;
276
- };
277
- /**
278
- * Implement the signal to make your custom step abortable https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
279
- */
280
- signal?: AbortSignal;
281
- /**
282
- * Optional value of each invocation
283
- */
284
- each?: JsonObject;
285
231
  };
286
232
  /** @public */
287
- type TemplateAction<TActionInput extends JsonObject = JsonObject, TActionOutput extends JsonObject = JsonObject, TSchemaType extends 'v1' | 'v2' = 'v1'> = {
233
+ type TemplateAction<TActionInput extends JsonObject = JsonObject, TActionOutput extends JsonObject = JsonObject, TSchemaType extends 'v2' = 'v2'> = {
288
234
  id: string;
289
235
  description?: string;
290
236
  examples?: {
@@ -305,11 +251,15 @@ type TemplateExample = {
305
251
  example: string;
306
252
  };
307
253
  /** @public */
308
- type TemplateActionOptions<TActionInput extends JsonObject = {}, TActionOutput extends JsonObject = {}, TInputSchema extends JsonObject | z.ZodType | {
254
+ type TemplateActionOptions<TActionInput extends JsonObject = {}, TActionOutput extends JsonObject = {}, TInputSchema extends {
255
+ [key in string]: (zImpl: typeof z) => z.ZodType;
256
+ } | ((zImpl: typeof z) => z.ZodType) = {
257
+ [key in string]: (zImpl: typeof z) => z.ZodType;
258
+ }, TOutputSchema extends {
309
259
  [key in string]: (zImpl: typeof z) => z.ZodType;
310
- } = JsonObject, TOutputSchema extends JsonObject | z.ZodType | {
260
+ } | ((zImpl: typeof z) => z.ZodType) = {
311
261
  [key in string]: (zImpl: typeof z) => z.ZodType;
312
- } = JsonObject, TSchemaType extends 'v1' | 'v2' = 'v1' | 'v2'> = {
262
+ }, TSchemaType extends 'v2' = 'v2'> = {
313
263
  id: string;
314
264
  description?: string;
315
265
  examples?: TemplateExample[];
@@ -330,16 +280,6 @@ type FlattenOptionalProperties<T extends {
330
280
  } & {
331
281
  [K in keyof T as undefined extends T[K] ? K : never]?: T[K];
332
282
  }>;
333
- /**
334
- * @public
335
- * @deprecated migrate to using the new built in zod schema definitions for schemas
336
- */
337
- declare function createTemplateAction<TInputParams extends JsonObject = JsonObject, TOutputParams extends JsonObject = JsonObject, TInputSchema extends JsonObject = JsonObject, TOutputSchema extends JsonObject = JsonObject, TActionInput extends JsonObject = TInputParams, TActionOutput extends JsonObject = TOutputParams>(action: TemplateActionOptions<TActionInput, TActionOutput, TInputSchema, TOutputSchema, 'v1'>): TemplateAction<TActionInput, TActionOutput, 'v1'>;
338
- /**
339
- * @public
340
- * @deprecated migrate to using the new built in zod schema definitions for schemas
341
- */
342
- declare function createTemplateAction<TInputParams extends JsonObject = JsonObject, TOutputParams extends JsonObject = JsonObject, TInputSchema extends z.ZodType = z.ZodType, TOutputSchema extends z.ZodType = z.ZodType, TActionInput extends JsonObject = z.infer<TInputSchema>, TActionOutput extends JsonObject = z.infer<TOutputSchema>>(action: TemplateActionOptions<TActionInput, TActionOutput, TInputSchema, TOutputSchema, 'v1'>): TemplateAction<TActionInput, TActionOutput, 'v1'>;
343
283
  /**
344
284
  * This function is used to create new template actions to get type safety.
345
285
  * Will convert zod schemas to json schemas for use throughout the system.
@@ -347,17 +287,25 @@ declare function createTemplateAction<TInputParams extends JsonObject = JsonObje
347
287
  */
348
288
  declare function createTemplateAction<TInputSchema extends {
349
289
  [key in string]: (zImpl: typeof z) => z.ZodType;
350
- }, TOutputSchema extends {
290
+ } | ((zImpl: typeof z) => z.ZodType), TOutputSchema extends {
351
291
  [key in string]: (zImpl: typeof z) => z.ZodType;
352
- }>(action: TemplateActionOptions<{
292
+ } | ((zImpl: typeof z) => z.ZodType)>(action: TemplateActionOptions<TInputSchema extends {
293
+ [key in string]: (zImpl: typeof z) => z.ZodType;
294
+ } ? {
353
295
  [key in keyof TInputSchema]: z.infer<ReturnType<TInputSchema[key]>>;
354
- }, {
296
+ } : TInputSchema extends (zImpl: typeof z) => z.ZodType ? z.infer<ReturnType<TInputSchema>> : never, TOutputSchema extends {
297
+ [key in string]: (zImpl: typeof z) => z.ZodType;
298
+ } ? {
355
299
  [key in keyof TOutputSchema]: z.infer<ReturnType<TOutputSchema[key]>>;
356
- }, TInputSchema, TOutputSchema, 'v2'>): TemplateAction<FlattenOptionalProperties<{
300
+ } : TOutputSchema extends (zImpl: typeof z) => z.ZodType ? z.infer<ReturnType<TOutputSchema>> : never, TInputSchema, TOutputSchema, 'v2'>): TemplateAction<FlattenOptionalProperties<TInputSchema extends {
301
+ [key in string]: (zImpl: typeof z) => z.ZodType;
302
+ } ? {
357
303
  [key in keyof TInputSchema]: z.output<ReturnType<TInputSchema[key]>>;
358
- }>, FlattenOptionalProperties<{
304
+ } : TInputSchema extends (zImpl: typeof z) => z.ZodType ? z.output<ReturnType<TInputSchema>> : never>, FlattenOptionalProperties<TOutputSchema extends {
305
+ [key in string]: (zImpl: typeof z) => z.ZodType;
306
+ } ? {
359
307
  [key in keyof TOutputSchema]: z.output<ReturnType<TOutputSchema[key]>>;
360
- }>, 'v2'>;
308
+ } : TOutputSchema extends (zImpl: typeof z) => z.ZodType ? z.output<ReturnType<TOutputSchema>> : never>, 'v2'>;
361
309
 
362
310
  /**
363
311
  * Options for {@link executeShellCommand}.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-node",
3
- "version": "0.8.3-next.1",
3
+ "version": "0.9.0",
4
4
  "description": "The plugin-scaffolder-node module for @backstage/plugin-scaffolder-backend",
5
5
  "backstage": {
6
6
  "role": "node-library",
@@ -62,12 +62,12 @@
62
62
  "test": "backstage-cli package test"
63
63
  },
64
64
  "dependencies": {
65
- "@backstage/backend-plugin-api": "1.4.0-next.1",
66
- "@backstage/catalog-model": "1.7.4",
67
- "@backstage/errors": "1.2.7",
68
- "@backstage/integration": "1.17.0",
69
- "@backstage/plugin-scaffolder-common": "1.5.11",
70
- "@backstage/types": "1.2.1",
65
+ "@backstage/backend-plugin-api": "^1.4.0",
66
+ "@backstage/catalog-model": "^1.7.4",
67
+ "@backstage/errors": "^1.2.7",
68
+ "@backstage/integration": "^1.17.0",
69
+ "@backstage/plugin-scaffolder-common": "^1.5.11",
70
+ "@backstage/types": "^1.2.1",
71
71
  "@isomorphic-git/pgp-plugin": "^0.0.7",
72
72
  "concat-stream": "^2.0.0",
73
73
  "fs-extra": "^11.2.0",
@@ -83,9 +83,9 @@
83
83
  "zod-to-json-schema": "^3.20.4"
84
84
  },
85
85
  "devDependencies": {
86
- "@backstage/backend-test-utils": "1.6.0-next.1",
87
- "@backstage/cli": "0.32.2-next.0",
88
- "@backstage/config": "1.3.2",
86
+ "@backstage/backend-test-utils": "^1.6.0",
87
+ "@backstage/cli": "^0.33.0",
88
+ "@backstage/config": "^1.3.2",
89
89
  "@types/lodash": "^4.14.151"
90
90
  }
91
91
  }