-
Notifications
You must be signed in to change notification settings - Fork 321
Expand file tree
/
Copy pathpricing.data.ts
More file actions
52 lines (44 loc) · 1.72 KB
/
pricing.data.ts
File metadata and controls
52 lines (44 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import fs from 'node:fs'
import path from 'node:path'
import { parse } from 'yaml'
export default {
watch: [`./plans/*.yaml`, `./pricing.yaml`],
load(files) {
// Separate global config from plan files
const configFile = files.find(
(f) => f.endsWith(`pricing.yaml`) && !f.includes(`plans/`)
)
const planFiles = files.filter((f) => f !== configFile)
const config = parse(fs.readFileSync(configFile, `utf-8`))
const plans = planFiles
.map((file) => {
const slug = path.basename(file, `.yaml`)
const data = parse(fs.readFileSync(file, `utf-8`))
// Derive effective rates for tier plans (per-service write rates)
if (data.type === `tier` && data.discountPercent !== undefined) {
const discount = data.discountPercent / 100
data.effectiveDurableStreamsWriteRate = +(
config.baseRates.durableStreamsWritesPerMillion *
(1 - discount)
).toFixed(4)
data.effectivePostgresSyncWriteRate = +(
config.baseRates.postgresSyncWritesPerMillion *
(1 - discount)
).toFixed(4)
data.effectiveRetentionRate = +(
config.baseRates.retentionPerGBMonth *
(1 - discount)
).toFixed(4)
}
return { slug, ...data }
})
.sort((a, b) => (a.order || 999) - (b.order || 999))
const tiers = plans.filter((p) => p.type === `tier`)
const services = plans.filter((p) => p.type === `service`)
const enterprise = plans.filter((p) => p.type === `enterprise`)
const comparisonPlans = plans.filter(
(p) => p.type === `tier` || p.type === `enterprise`
)
return { config, plans, tiers, services, enterprise, comparisonPlans }
},
}