diff --git a/.changeset/tame-areas-behave.md b/.changeset/tame-areas-behave.md new file mode 100644 index 0000000000..6d5c776d8b --- /dev/null +++ b/.changeset/tame-areas-behave.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-notifications': patch +--- + +Change notification send scaffolder action to use native zod schemas diff --git a/plugins/scaffolder-backend-module-notifications/report.api.md b/plugins/scaffolder-backend-module-notifications/report.api.md index cb796e5033..1d437cebd7 100644 --- a/plugins/scaffolder-backend-module-notifications/report.api.md +++ b/plugins/scaffolder-backend-module-notifications/report.api.md @@ -4,9 +4,7 @@ ```ts import { BackendFeature } from '@backstage/backend-plugin-api'; -import { JsonObject } from '@backstage/types'; import { NotificationService } from '@backstage/plugin-notifications-node'; -import { NotificationSeverity } from '@backstage/plugin-notifications-common'; import { TemplateAction } from '@backstage/plugin-scaffolder-node'; // @public (undocumented) @@ -14,17 +12,19 @@ export function createSendNotificationAction(options: { notifications: NotificationService; }): TemplateAction< { - recipients: string; - entityRefs?: string[]; + recipients: 'entity' | 'broadcast'; title: string; - info?: string; - link?: string; - severity?: NotificationSeverity; - scope?: string; - optional?: boolean; + entityRefs?: string[] | undefined; + info?: string | undefined; + link?: string | undefined; + severity?: 'normal' | 'high' | 'low' | 'critical' | undefined; + scope?: string | undefined; + optional?: boolean | undefined; }, - JsonObject, - 'v1' + { + [x: string]: any; + }, + 'v2' >; // @public diff --git a/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.examples.test.ts b/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.examples.test.ts index 84473335e0..cd6fb54c51 100644 --- a/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.examples.test.ts +++ b/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.examples.test.ts @@ -25,7 +25,7 @@ describe('notification:send', () => { send: jest.fn(), }; - let action: TemplateAction; + let action: TemplateAction; beforeEach(() => { jest.resetAllMocks(); diff --git a/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.test.ts b/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.test.ts index efd1377cae..ee87991c73 100644 --- a/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.test.ts +++ b/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.test.ts @@ -23,7 +23,7 @@ describe('notification:send', () => { send: jest.fn(), }; - let action: TemplateAction; + let action: TemplateAction; beforeEach(() => { jest.resetAllMocks(); diff --git a/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.ts b/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.ts index d1954dfd8c..a8e86f9b48 100644 --- a/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.ts +++ b/plugins/scaffolder-backend-module-notifications/src/actions/sendNotification.ts @@ -17,10 +17,7 @@ import { NotificationRecipients, NotificationService, } from '@backstage/plugin-notifications-node'; -import { - NotificationPayload, - NotificationSeverity, -} from '@backstage/plugin-notifications-common'; +import { NotificationPayload } from '@backstage/plugin-notifications-common'; import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; import { examples } from './sendNotification.examples'; @@ -31,73 +28,41 @@ export function createSendNotificationAction(options: { notifications: NotificationService; }) { const { notifications } = options; - return createTemplateAction<{ - recipients: string; - entityRefs?: string[]; - title: string; - info?: string; - link?: string; - severity?: NotificationSeverity; - scope?: string; - optional?: boolean; - }>({ + return createTemplateAction({ id: 'notification:send', description: 'Sends a notification using NotificationService', examples, schema: { input: { - type: 'object', - required: ['recipients', 'title'], - properties: { - recipients: { - title: 'Recipient', - enum: ['broadcast', 'entity'], - description: + recipients: z => + z + .enum(['broadcast', 'entity']) + .describe( 'The recipient of the notification, either broadcast or entity. If using entity, also entityRef must be provided', - type: 'string', - }, - entityRefs: { - title: 'Entity references', - description: + ), + entityRefs: z => + z + .array(z.string()) + .optional() + .describe( 'The entity references to send the notification to, required if using recipient of entity', - type: 'array', - items: { - type: 'string', - }, - }, - title: { - title: 'Title', - description: 'Notification title', - type: 'string', - }, - info: { - title: 'Description', - description: 'Notification description', - type: 'string', - }, - link: { - title: 'Link', - description: 'Notification link', - type: 'string', - }, - severity: { - title: 'Severity', - type: 'string', - description: `Notification severity`, - enum: ['low', 'normal', 'high', 'critical'], - }, - scope: { - title: 'Scope', - description: 'Notification scope', - type: 'string', - }, - optional: { - title: 'Optional', - description: + ), + title: z => z.string().describe('Notification title'), + info: z => z.string().optional().describe('Notification description'), + link: z => z.string().optional().describe('Notification link'), + severity: z => + z + .enum(['low', 'normal', 'high', 'critical']) + .optional() + .describe('Notification severity'), + scope: z => z.string().optional().describe('Notification scope'), + optional: z => + z + .boolean() + .optional() + .describe( 'Do not fail the action if the notification sending fails', - type: 'boolean', - }, - }, + ), }, }, async handler(ctx) {