diff --git a/packages/backend-core/src/events/processors/LoggingProcessor.ts b/packages/backend-core/src/events/processors/LoggingProcessor.ts index a517fba09c..d41a82fbb4 100644 --- a/packages/backend-core/src/events/processors/LoggingProcessor.ts +++ b/packages/backend-core/src/events/processors/LoggingProcessor.ts @@ -23,9 +23,11 @@ export default class LoggingProcessor implements EventProcessor { return } let timestampString = getTimestampString(timestamp) - console.log( - `[audit] [tenant=${identity.tenantId}] [identityType=${identity.type}] [identity=${identity.id}] ${timestampString} ${event} ` - ) + let message = `[audit] [tenant=${identity.tenantId}] [identityType=${identity.type}] [identity=${identity.id}] ${timestampString} ${event} ` + if (env.isDev()) { + message = message + `[debug: [properties=${JSON.stringify(properties)}] ]` + } + console.log(message) } async identify(identity: Identity, timestamp?: string | number) { diff --git a/packages/backend-core/src/events/publishers/license.ts b/packages/backend-core/src/events/publishers/license.ts index 1adc71652e..84472e408f 100644 --- a/packages/backend-core/src/events/publishers/license.ts +++ b/packages/backend-core/src/events/publishers/license.ts @@ -1,27 +1,78 @@ import { publishEvent } from "../events" import { Event, - License, LicenseActivatedEvent, - LicenseDowngradedEvent, - LicenseUpdatedEvent, - LicenseUpgradedEvent, + LicensePlanChangedEvent, + LicenseTierChangedEvent, + PlanType, + Account, + LicensePortalOpenedEvent, + LicenseCheckoutSuccessEvent, + LicenseCheckoutOpenedEvent, + LicensePaymentFailedEvent, + LicensePaymentRecoveredEvent, } from "@budibase/types" -// TODO -export async function updgraded(license: License) { - const properties: LicenseUpgradedEvent = {} - await publishEvent(Event.LICENSE_UPGRADED, properties) +export async function tierChanged(account: Account, from: number, to: number) { + const properties: LicenseTierChangedEvent = { + accountId: account.accountId, + to, + from, + } + await publishEvent(Event.LICENSE_TIER_CHANGED, properties) } -// TODO -export async function downgraded(license: License) { - const properties: LicenseDowngradedEvent = {} - await publishEvent(Event.LICENSE_DOWNGRADED, properties) +export async function planChanged( + account: Account, + from: PlanType, + to: PlanType +) { + const properties: LicensePlanChangedEvent = { + accountId: account.accountId, + to, + from, + } + await publishEvent(Event.LICENSE_PLAN_CHANGED, properties) } -// TODO -export async function activated(license: License) { - const properties: LicenseActivatedEvent = {} +export async function activated(account: Account) { + const properties: LicenseActivatedEvent = { + accountId: account.accountId, + } await publishEvent(Event.LICENSE_ACTIVATED, properties) } + +export async function checkoutOpened(account: Account) { + const properties: LicenseCheckoutOpenedEvent = { + accountId: account.accountId, + } + await publishEvent(Event.LICENSE_CHECKOUT_OPENED, properties) +} + +export async function checkoutSuccess(account: Account) { + const properties: LicenseCheckoutSuccessEvent = { + accountId: account.accountId, + } + await publishEvent(Event.LICENSE_CHECKOUT_SUCCESS, properties) +} + +export async function portalOpened(account: Account) { + const properties: LicensePortalOpenedEvent = { + accountId: account.accountId, + } + await publishEvent(Event.LICENSE_PORTAL_OPENED, properties) +} + +export async function paymentFailed(account: Account) { + const properties: LicensePaymentFailedEvent = { + accountId: account.accountId, + } + await publishEvent(Event.LICENSE_PAYMENT_FAILED, properties) +} + +export async function paymentRecovered(account: Account) { + const properties: LicensePaymentRecoveredEvent = { + accountId: account.accountId, + } + await publishEvent(Event.LICENSE_PAYMENT_RECOVERED, properties) +} diff --git a/packages/server/src/api/routes/tests/row.spec.js b/packages/server/src/api/routes/tests/row.spec.js index 5cd282bb34..e85ffddee7 100644 --- a/packages/server/src/api/routes/tests/row.spec.js +++ b/packages/server/src/api/routes/tests/row.spec.js @@ -5,10 +5,12 @@ const { doInAppContext } = require("@budibase/backend-core/context") const { doInTenant } = require("@budibase/backend-core/tenancy") const { quotas, +} = require("@budibase/pro") +const { QuotaUsageType, StaticQuotaName, MonthlyQuotaName, -} = require("@budibase/pro") +} = require("@budibase/types") describe("/rows", () => { let request = setup.getRequest() diff --git a/packages/types/src/documents/account/account.ts b/packages/types/src/documents/account/account.ts index 2f7767ca36..e7dcf2d89f 100644 --- a/packages/types/src/documents/account/account.ts +++ b/packages/types/src/documents/account/account.ts @@ -37,6 +37,7 @@ export interface Account extends CreateAccount { // licensing tier: string // deprecated planType?: PlanType + planTier?: number stripeCustomerId?: string licenseKey?: string licenseKeyActivatedAt?: number diff --git a/packages/types/src/sdk/events/event.ts b/packages/types/src/sdk/events/event.ts index de56740e44..73e5315713 100644 --- a/packages/types/src/sdk/events/event.ts +++ b/packages/types/src/sdk/events/event.ts @@ -133,9 +133,14 @@ export enum Event { AUTOMATION_TRIGGER_UPDATED = "automation:trigger:updated", // LICENSE - LICENSE_UPGRADED = "license:upgraded", - LICENSE_DOWNGRADED = "license:downgraded", + LICENSE_PLAN_CHANGED = "license:plan:changed", + LICENSE_TIER_CHANGED = "license:tier:changed", LICENSE_ACTIVATED = "license:activated", + LICENSE_PAYMENT_FAILED = "license:payment:failed", + LICENSE_PAYMENT_RECOVERED = "license:payment:recovered", + LICENSE_CHECKOUT_OPENED = "license:checkout:opened", + LICENSE_CHECKOUT_SUCCESS = "license:checkout:success", + LICENSE_PORTAL_OPENED = "license:portal:opened", // ACCOUNT ACCOUNT_CREATED = "account:created", diff --git a/packages/types/src/sdk/events/license.ts b/packages/types/src/sdk/events/license.ts index 771327c960..a12fc6bbb5 100644 --- a/packages/types/src/sdk/events/license.ts +++ b/packages/types/src/sdk/events/license.ts @@ -1,7 +1,37 @@ -export interface LicenseUpgradedEvent {} +import { PlanType } from "../licensing" -export interface LicenseDowngradedEvent {} +export interface LicenseTierChangedEvent { + accountId: string + from: number + to: number +} -export interface LicenseUpdatedEvent {} +export interface LicensePlanChangedEvent { + accountId: string + from: PlanType + to: PlanType +} -export interface LicenseActivatedEvent {} +export interface LicenseActivatedEvent { + accountId: string +} + +export interface LicenseCheckoutOpenedEvent { + accountId: string +} + +export interface LicenseCheckoutSuccessEvent { + accountId: string +} + +export interface LicensePortalOpenedEvent { + accountId: string +} + +export interface LicensePaymentFailedEvent { + accountId: string +} + +export interface LicensePaymentRecoveredEvent { + accountId: string +}