@strimz/shared-config 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/index.cjs +61 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +55 -45
- package/dist/index.js.map +1 -1
- package/dist/tiers.cjs +87 -47
- package/dist/tiers.cjs.map +1 -1
- package/dist/tiers.d.cts +21 -21
- package/dist/tiers.d.ts +21 -21
- package/dist/tiers.js +81 -45
- package/dist/tiers.js.map +1 -1
- package/package.json +1 -1
- package/src/tiers.ts +75 -53
package/src/tiers.ts
CHANGED
|
@@ -6,84 +6,106 @@
|
|
|
6
6
|
* payment is recurring (i.e. originated from a SubscriptionPlan).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
import { PAYMENT_TOKENS, TOKENS, type PaymentToken } from './tokens.js'
|
|
10
10
|
|
|
11
|
-
export
|
|
11
|
+
export type MerchantTier = 'free' | 'starter' | 'growth' | 'enterprise'
|
|
12
|
+
|
|
13
|
+
export type VolumePlan = Exclude<MerchantTier, 'enterprise'>
|
|
14
|
+
|
|
15
|
+
export type PlanFeature = 'storefront' | 'anomaly_alerts' | 'yield_recommendations'
|
|
16
|
+
|
|
17
|
+
export interface PlanDefinition {
|
|
12
18
|
id: MerchantTier
|
|
13
19
|
name: string
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
oneShotFeeBps: number | null
|
|
18
|
-
/** Per-transaction premium added on subscription payments, in basis points. */
|
|
19
|
-
subscriptionPremiumBps: number | null
|
|
20
|
-
/** Monthly transaction volume cap in USD cents. `null` for unlimited. */
|
|
21
|
-
monthlyVolumeCapUsdCents: number | null
|
|
22
|
-
/** Whether the "Powered by Strimz" badge can be removed from checkout. */
|
|
23
|
-
whiteLabelEligible: boolean
|
|
24
|
-
/** Whether the tier includes priority support. */
|
|
20
|
+
feeBps: number | null
|
|
21
|
+
entersAtVolume: number | null
|
|
22
|
+
features: readonly PlanFeature[]
|
|
25
23
|
prioritySupport: boolean
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
const PAID_FEATURES: readonly PlanFeature[] = [
|
|
27
|
+
'storefront',
|
|
28
|
+
'anomaly_alerts',
|
|
29
|
+
'yield_recommendations',
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
export const PLANS: Record<MerchantTier, PlanDefinition> = {
|
|
29
33
|
free: {
|
|
30
34
|
id: 'free',
|
|
31
35
|
name: 'Free',
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
monthlyVolumeCapUsdCents: 1_000_000, // $10,000
|
|
36
|
-
whiteLabelEligible: false,
|
|
36
|
+
feeBps: 0,
|
|
37
|
+
entersAtVolume: 0,
|
|
38
|
+
features: [],
|
|
37
39
|
prioritySupport: false,
|
|
38
40
|
},
|
|
41
|
+
starter: {
|
|
42
|
+
id: 'starter',
|
|
43
|
+
name: 'Starter',
|
|
44
|
+
feeBps: 50,
|
|
45
|
+
entersAtVolume: 1_000,
|
|
46
|
+
features: PAID_FEATURES,
|
|
47
|
+
prioritySupport: true,
|
|
48
|
+
},
|
|
39
49
|
growth: {
|
|
40
50
|
id: 'growth',
|
|
41
51
|
name: 'Growth',
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
monthlyVolumeCapUsdCents: 10_000_000, // $100,000
|
|
46
|
-
whiteLabelEligible: true,
|
|
47
|
-
prioritySupport: false,
|
|
48
|
-
},
|
|
49
|
-
business: {
|
|
50
|
-
id: 'business',
|
|
51
|
-
name: 'Business',
|
|
52
|
-
monthlyFeeUsdCents: 19_900, // $199
|
|
53
|
-
oneShotFeeBps: 50, // 0.5%
|
|
54
|
-
subscriptionPremiumBps: 20, // 0.7% effective
|
|
55
|
-
monthlyVolumeCapUsdCents: 100_000_000, // $1,000,000
|
|
56
|
-
whiteLabelEligible: true,
|
|
52
|
+
feeBps: 40,
|
|
53
|
+
entersAtVolume: 50_000,
|
|
54
|
+
features: PAID_FEATURES,
|
|
57
55
|
prioritySupport: true,
|
|
58
56
|
},
|
|
59
57
|
enterprise: {
|
|
60
58
|
id: 'enterprise',
|
|
61
59
|
name: 'Enterprise',
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
monthlyVolumeCapUsdCents: null,
|
|
66
|
-
whiteLabelEligible: true,
|
|
60
|
+
feeBps: null,
|
|
61
|
+
entersAtVolume: null,
|
|
62
|
+
features: PAID_FEATURES,
|
|
67
63
|
prioritySupport: true,
|
|
68
64
|
},
|
|
69
65
|
}
|
|
70
66
|
|
|
71
67
|
export const DEFAULT_TIER: MerchantTier = 'free'
|
|
72
68
|
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
const PLAN_ORDER: readonly MerchantTier[] = ['free', 'starter', 'growth', 'enterprise']
|
|
70
|
+
|
|
71
|
+
const VOLUME_PLANS: readonly VolumePlan[] = ['free', 'starter', 'growth']
|
|
72
|
+
|
|
73
|
+
export const PLAN_FEE_CEILING_BPS: number = Math.max(
|
|
74
|
+
...VOLUME_PLANS.map((plan) => PLANS[plan].feeBps ?? 0),
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
export function planFeeBps(plan: MerchantTier): number | null {
|
|
78
|
+
return PLANS[plan].feeBps
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
export function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
return
|
|
81
|
+
export function planIncludes(plan: MerchantTier, feature: PlanFeature): boolean {
|
|
82
|
+
return PLANS[plan].features.includes(feature)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function plansWith(feature: PlanFeature): MerchantTier[] {
|
|
86
|
+
return PLAN_ORDER.filter((plan) => planIncludes(plan, feature))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function lowestPlanWith(feature: PlanFeature): MerchantTier {
|
|
90
|
+
const plan = PLAN_ORDER.find((candidate) => planIncludes(candidate, feature))
|
|
91
|
+
if (!plan) throw new Error(`no plan includes ${feature}`)
|
|
92
|
+
return plan
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type PaymentVolumes = Readonly<Record<PaymentToken, bigint>>
|
|
96
|
+
|
|
97
|
+
function thresholdInBaseUnits(plan: VolumePlan, token: PaymentToken): bigint {
|
|
98
|
+
const wholeUnits = PLANS[plan].entersAtVolume
|
|
99
|
+
if (wholeUnits === null) throw new Error(`${plan} has no volume threshold`)
|
|
100
|
+
return BigInt(wholeUnits) * 10n ** BigInt(TOKENS[token].decimals)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function planForVolume(volumes: PaymentVolumes): VolumePlan {
|
|
104
|
+
let reached: VolumePlan = 'free'
|
|
105
|
+
for (const plan of VOLUME_PLANS) {
|
|
106
|
+
if (PAYMENT_TOKENS.some((token) => volumes[token] >= thresholdInBaseUnits(plan, token))) {
|
|
107
|
+
reached = plan
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return reached
|
|
89
111
|
}
|