From 5a2937c8d2e893fa176edbc3062807b556d8c656 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 23 Jan 2023 18:18:06 +0000 Subject: [PATCH] Adding events for environment variables (created, deleted, upgrade panel opened). --- .../events/publishers/environmentVariable.ts | 38 +++++++++++++++++++ .../src/events/publishers/index.ts | 1 + .../src/sdk/events/environmentVariable.ts | 14 +++++++ packages/types/src/sdk/events/event.ts | 5 +++ packages/types/src/sdk/events/index.ts | 1 + 5 files changed, 59 insertions(+) create mode 100644 packages/backend-core/src/events/publishers/environmentVariable.ts create mode 100644 packages/types/src/sdk/events/environmentVariable.ts diff --git a/packages/backend-core/src/events/publishers/environmentVariable.ts b/packages/backend-core/src/events/publishers/environmentVariable.ts new file mode 100644 index 0000000000..d28e259b82 --- /dev/null +++ b/packages/backend-core/src/events/publishers/environmentVariable.ts @@ -0,0 +1,38 @@ +import { + Event, + EnvironmentVariableCreatedEvent, + EnvironmentVariableDeletedEvent, + EnvironmentVariableUpgradePanelOpenedEvent, +} from "@budibase/types" +import { publishEvent } from "../events" + +async function created(name: string, environments: string[]) { + const properties: EnvironmentVariableCreatedEvent = { + name, + environments, + } + await publishEvent(Event.ENVIRONMENT_VARIABLE_CREATED, properties) +} + +async function deleted(name: string) { + const properties: EnvironmentVariableDeletedEvent = { + name, + } + await publishEvent(Event.ENVIRONMENT_VARIABLE_DELETED, properties) +} + +async function upgradePanelOpened(userId: string) { + const properties: EnvironmentVariableUpgradePanelOpenedEvent = { + userId, + } + await publishEvent( + Event.ENVIRONMENT_VARIABLE_UPGRADE_PANEL_OPENED, + properties + ) +} + +export default { + created, + deleted, + upgradePanelOpened, +} diff --git a/packages/backend-core/src/events/publishers/index.ts b/packages/backend-core/src/events/publishers/index.ts index 2316785ed7..34e47b2990 100644 --- a/packages/backend-core/src/events/publishers/index.ts +++ b/packages/backend-core/src/events/publishers/index.ts @@ -20,3 +20,4 @@ export { default as backfill } from "./backfill" export { default as group } from "./group" export { default as plugin } from "./plugin" export { default as backup } from "./backup" +export { default as environmentVariable } from "./environmentVariable" diff --git a/packages/types/src/sdk/events/environmentVariable.ts b/packages/types/src/sdk/events/environmentVariable.ts new file mode 100644 index 0000000000..0b81d78df8 --- /dev/null +++ b/packages/types/src/sdk/events/environmentVariable.ts @@ -0,0 +1,14 @@ +import { BaseEvent } from "./event" + +export interface EnvironmentVariableCreatedEvent extends BaseEvent { + name: string + environments: string[] +} + +export interface EnvironmentVariableDeletedEvent extends BaseEvent { + name: string +} + +export interface EnvironmentVariableUpgradePanelOpenedEvent extends BaseEvent { + userId: string +} diff --git a/packages/types/src/sdk/events/event.ts b/packages/types/src/sdk/events/event.ts index 2c197e7738..5d1f30883c 100644 --- a/packages/types/src/sdk/events/event.ts +++ b/packages/types/src/sdk/events/event.ts @@ -172,6 +172,11 @@ export enum Event { // BACKUP APP_BACKUP_RESTORED = "app:backup:restored", APP_BACKUP_TRIGGERED = "app:backup:triggered", + + // ENVIRONMENT VARIABLE + ENVIRONMENT_VARIABLE_CREATED = "environment_variable:created", + ENVIRONMENT_VARIABLE_DELETED = "environment_variable:deleted", + ENVIRONMENT_VARIABLE_UPGRADE_PANEL_OPENED = "environment_variable:upgrade_panel_opened", } // properties added at the final stage of the event pipeline diff --git a/packages/types/src/sdk/events/index.ts b/packages/types/src/sdk/events/index.ts index 5abc30f5b9..009d9beac4 100644 --- a/packages/types/src/sdk/events/index.ts +++ b/packages/types/src/sdk/events/index.ts @@ -21,3 +21,4 @@ export * from "./identification" export * from "./userGroup" export * from "./plugin" export * from "./backup" +export * from "./environmentVariable"