Merge pull request #10441 from Budibase/pricing/events
Type updates for plan changed event
This commit is contained in:
commit
aad87d7c0c
|
@ -3,7 +3,6 @@ import {
|
||||||
Event,
|
Event,
|
||||||
LicenseActivatedEvent,
|
LicenseActivatedEvent,
|
||||||
LicensePlanChangedEvent,
|
LicensePlanChangedEvent,
|
||||||
LicenseTierChangedEvent,
|
|
||||||
PlanType,
|
PlanType,
|
||||||
Account,
|
Account,
|
||||||
LicensePortalOpenedEvent,
|
LicensePortalOpenedEvent,
|
||||||
|
@ -11,22 +10,22 @@ import {
|
||||||
LicenseCheckoutOpenedEvent,
|
LicenseCheckoutOpenedEvent,
|
||||||
LicensePaymentFailedEvent,
|
LicensePaymentFailedEvent,
|
||||||
LicensePaymentRecoveredEvent,
|
LicensePaymentRecoveredEvent,
|
||||||
|
PriceDuration,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
async function tierChanged(account: Account, from: number, to: number) {
|
async function planChanged(
|
||||||
const properties: LicenseTierChangedEvent = {
|
account: Account,
|
||||||
accountId: account.accountId,
|
from: PlanType,
|
||||||
to,
|
to: PlanType,
|
||||||
from,
|
quantity: number | undefined,
|
||||||
}
|
duration: PriceDuration | undefined
|
||||||
await publishEvent(Event.LICENSE_TIER_CHANGED, properties)
|
) {
|
||||||
}
|
|
||||||
|
|
||||||
async function planChanged(account: Account, from: PlanType, to: PlanType) {
|
|
||||||
const properties: LicensePlanChangedEvent = {
|
const properties: LicensePlanChangedEvent = {
|
||||||
accountId: account.accountId,
|
accountId: account.accountId,
|
||||||
to,
|
to,
|
||||||
from,
|
from,
|
||||||
|
quantity,
|
||||||
|
duration,
|
||||||
}
|
}
|
||||||
await publishEvent(Event.LICENSE_PLAN_CHANGED, properties)
|
await publishEvent(Event.LICENSE_PLAN_CHANGED, properties)
|
||||||
}
|
}
|
||||||
|
@ -74,7 +73,6 @@ async function paymentRecovered(account: Account) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
tierChanged,
|
|
||||||
planChanged,
|
planChanged,
|
||||||
activated,
|
activated,
|
||||||
checkoutOpened,
|
checkoutOpened,
|
||||||
|
|
|
@ -123,7 +123,6 @@ beforeAll(async () => {
|
||||||
jest.spyOn(events.plugin, "imported")
|
jest.spyOn(events.plugin, "imported")
|
||||||
jest.spyOn(events.plugin, "deleted")
|
jest.spyOn(events.plugin, "deleted")
|
||||||
|
|
||||||
jest.spyOn(events.license, "tierChanged")
|
|
||||||
jest.spyOn(events.license, "planChanged")
|
jest.spyOn(events.license, "planChanged")
|
||||||
jest.spyOn(events.license, "activated")
|
jest.spyOn(events.license, "activated")
|
||||||
jest.spyOn(events.license, "checkoutOpened")
|
jest.spyOn(events.license, "checkoutOpened")
|
||||||
|
|
|
@ -7,16 +7,30 @@ import {
|
||||||
PlanType,
|
PlanType,
|
||||||
PriceDuration,
|
PriceDuration,
|
||||||
PurchasedPlan,
|
PurchasedPlan,
|
||||||
|
PurchasedPrice,
|
||||||
Quotas,
|
Quotas,
|
||||||
Subscription,
|
Subscription,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
|
export function price(): PurchasedPrice {
|
||||||
|
return {
|
||||||
|
amount: 10000,
|
||||||
|
amountMonthly: 10000,
|
||||||
|
currency: "usd",
|
||||||
|
duration: PriceDuration.MONTHLY,
|
||||||
|
priceId: "price_123",
|
||||||
|
dayPasses: undefined,
|
||||||
|
isPerUser: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const plan = (type: PlanType = PlanType.FREE): PurchasedPlan => {
|
export const plan = (type: PlanType = PlanType.FREE): PurchasedPlan => {
|
||||||
return {
|
return {
|
||||||
type,
|
type,
|
||||||
usesInvoicing: false,
|
usesInvoicing: false,
|
||||||
minUsers: 1,
|
minUsers: 1,
|
||||||
model: PlanModel.PER_USER,
|
model: PlanModel.PER_USER,
|
||||||
|
price: price(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ export interface Account extends CreateAccount {
|
||||||
// licensing
|
// licensing
|
||||||
tier: string // deprecated
|
tier: string // deprecated
|
||||||
planType?: PlanType
|
planType?: PlanType
|
||||||
|
/** @deprecated */
|
||||||
planTier?: number
|
planTier?: number
|
||||||
license?: License
|
license?: License
|
||||||
installId?: string
|
installId?: string
|
||||||
|
|
|
@ -138,7 +138,6 @@ export enum Event {
|
||||||
|
|
||||||
// LICENSE
|
// LICENSE
|
||||||
LICENSE_PLAN_CHANGED = "license:plan:changed",
|
LICENSE_PLAN_CHANGED = "license:plan:changed",
|
||||||
LICENSE_TIER_CHANGED = "license:tier:changed",
|
|
||||||
LICENSE_ACTIVATED = "license:activated",
|
LICENSE_ACTIVATED = "license:activated",
|
||||||
LICENSE_PAYMENT_FAILED = "license:payment:failed",
|
LICENSE_PAYMENT_FAILED = "license:payment:failed",
|
||||||
LICENSE_PAYMENT_RECOVERED = "license:payment:recovered",
|
LICENSE_PAYMENT_RECOVERED = "license:payment:recovered",
|
||||||
|
@ -328,7 +327,6 @@ export const AuditedEventFriendlyName: Record<Event, string | undefined> = {
|
||||||
|
|
||||||
// LICENSE - NOT AUDITED
|
// LICENSE - NOT AUDITED
|
||||||
[Event.LICENSE_PLAN_CHANGED]: undefined,
|
[Event.LICENSE_PLAN_CHANGED]: undefined,
|
||||||
[Event.LICENSE_TIER_CHANGED]: undefined,
|
|
||||||
[Event.LICENSE_ACTIVATED]: undefined,
|
[Event.LICENSE_ACTIVATED]: undefined,
|
||||||
[Event.LICENSE_PAYMENT_FAILED]: undefined,
|
[Event.LICENSE_PAYMENT_FAILED]: undefined,
|
||||||
[Event.LICENSE_PAYMENT_RECOVERED]: undefined,
|
[Event.LICENSE_PAYMENT_RECOVERED]: undefined,
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import { PlanType } from "../licensing"
|
import { PlanType, PriceDuration } from "../licensing"
|
||||||
|
|
||||||
export interface LicenseTierChangedEvent {
|
|
||||||
accountId: string
|
|
||||||
from: number
|
|
||||||
to: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LicensePlanChangedEvent {
|
export interface LicensePlanChangedEvent {
|
||||||
accountId: string
|
accountId: string
|
||||||
from: PlanType
|
from: PlanType
|
||||||
to: PlanType
|
to: PlanType
|
||||||
|
// may not be on historical events
|
||||||
|
// free plans won't have a duration
|
||||||
|
duration: PriceDuration | undefined
|
||||||
|
// may not be on historical events
|
||||||
|
// free plans won't have a quantity
|
||||||
|
quantity: number | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LicenseActivatedEvent {
|
export interface LicenseActivatedEvent {
|
||||||
|
|
12
yarn.lock
12
yarn.lock
|
@ -1486,15 +1486,15 @@
|
||||||
pouchdb-promise "^6.0.4"
|
pouchdb-promise "^6.0.4"
|
||||||
through2 "^2.0.0"
|
through2 "^2.0.0"
|
||||||
|
|
||||||
"@budibase/pro@2.5.6-alpha.38":
|
"@budibase/pro@2.5.6-alpha.39":
|
||||||
version "2.5.6-alpha.38"
|
version "2.5.6-alpha.39"
|
||||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.5.6-alpha.38.tgz#09e8dfbb6cefe856b5c01845a5a5c02a406faedf"
|
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.5.6-alpha.39.tgz#31ff637f01936cc55a21cb39c01c26afb42a7c54"
|
||||||
integrity sha512-CBZv6V+163USHPN0SuEIrXeGA+9gB1QNmHrMEPSmwlOCZbNW2dhniz00EVSuVh3ypHSjDECgozasDJTNRhiufQ==
|
integrity sha512-Y33wjTLJ8P1KuYdz9T0QRrFxuvCNG9J6gkzp4lPZvrYr1RLFbvDIyz2wVMe5A0379EsYzTxuca7sXNvY21np/g==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@budibase/backend-core" "2.5.6-alpha.38"
|
"@budibase/backend-core" "2.5.6-alpha.39"
|
||||||
"@budibase/shared-core" "2.4.44-alpha.1"
|
"@budibase/shared-core" "2.4.44-alpha.1"
|
||||||
"@budibase/string-templates" "2.4.44-alpha.1"
|
"@budibase/string-templates" "2.4.44-alpha.1"
|
||||||
"@budibase/types" "2.5.6-alpha.38"
|
"@budibase/types" "2.5.6-alpha.39"
|
||||||
"@koa/router" "8.0.8"
|
"@koa/router" "8.0.8"
|
||||||
bull "4.10.1"
|
bull "4.10.1"
|
||||||
joi "17.6.0"
|
joi "17.6.0"
|
||||||
|
|
Loading…
Reference in New Issue