@strimz/shared-config 0.3.0 → 0.5.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/dist/tiers.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tiers.ts"],"names":[],"mappings":";AA2BO,IAAM,KAAA,GAA8C;AAAA,EACzD,IAAA,EAAM;AAAA,IACJ,EAAA,EAAI,MAAA;AAAA,IACJ,IAAA,EAAM,MAAA;AAAA,IACN,kBAAA,EAAoB,CAAA;AAAA,IACpB,aAAA,EAAe,GAAA;AAAA;AAAA,IACf,sBAAA,EAAwB,EAAA;AAAA;AAAA,IACxB,wBAAA,EAA0B,GAAA;AAAA;AAAA,IAC1B,kBAAA,EAAoB,KAAA;AAAA,IACpB,eAAA,EAAiB;AAAA,GACnB;AAAA,EACA,MAAA,EAAQ;AAAA,IACN,EAAA,EAAI,QAAA;AAAA,IACJ,IAAA,EAAM,QAAA;AAAA,IACN,kBAAA,EAAoB,IAAA;AAAA;AAAA,IACpB,aAAA,EAAe,EAAA;AAAA;AAAA,IACf,sBAAA,EAAwB,EAAA;AAAA;AAAA,IACxB,wBAAA,EAA0B,GAAA;AAAA;AAAA,IAC1B,kBAAA,EAAoB,IAAA;AAAA,IACpB,eAAA,EAAiB;AAAA,GACnB;AAAA,EACA,QAAA,EAAU;AAAA,IACR,EAAA,EAAI,UAAA;AAAA,IACJ,IAAA,EAAM,UAAA;AAAA,IACN,kBAAA,EAAoB,KAAA;AAAA;AAAA,IACpB,aAAA,EAAe,EAAA;AAAA;AAAA,IACf,sBAAA,EAAwB,EAAA;AAAA;AAAA,IACxB,wBAAA,EAA0B,GAAA;AAAA;AAAA,IAC1B,kBAAA,EAAoB,IAAA;AAAA,IACpB,eAAA,EAAiB;AAAA,GACnB;AAAA,EACA,UAAA,EAAY;AAAA,IACV,EAAA,EAAI,YAAA;AAAA,IACJ,IAAA,EAAM,YAAA;AAAA,IACN,kBAAA,EAAoB,IAAA;AAAA,IACpB,aAAA,EAAe,IAAA;AAAA,IACf,sBAAA,EAAwB,IAAA;AAAA,IACxB,wBAAA,EAA0B,IAAA;AAAA,IAC1B,kBAAA,EAAoB,IAAA;AAAA,IACpB,eAAA,EAAiB;AAAA;AAErB;AAEO,IAAM,YAAA,GAA6B;AAEnC,SAAS,QAAQ,EAAA,EAAkC;AACxD,EAAA,OAAO,MAAM,EAAE,CAAA;AACjB;AAMO,SAAS,eAAA,CACd,MACA,IAAA,EACe;AACf,EAAA,MAAM,GAAA,GAAM,MAAM,IAAI,CAAA;AACtB,EAAA,IAAI,GAAA,CAAI,aAAA,KAAkB,IAAA,EAAM,OAAO,IAAA;AACvC,EAAA,IAAI,IAAA,KAAS,UAAA,EAAY,OAAO,GAAA,CAAI,aAAA;AACpC,EAAA,OAAO,GAAA,CAAI,aAAA,IAAiB,GAAA,CAAI,sBAAA,IAA0B,CAAA,CAAA;AAC5D","file":"tiers.js","sourcesContent":["/**\n * Strimz pricing tiers.\n *\n * Fees are expressed in basis points (bps): 100 bps = 1%.\n * The subscription premium is added to the per-transaction rate when the\n * payment is recurring (i.e. originated from a SubscriptionPlan).\n */\n\nexport type MerchantTier = 'free' | 'growth' | 'business' | 'enterprise'\n\nexport interface TierDefinition {\n id: MerchantTier\n name: string\n /** Monthly fee in USD cents (0 for free, null for custom enterprise). */\n monthlyFeeUsdCents: number | null\n /** Per-transaction fee on one-shot payments, in basis points. */\n oneShotFeeBps: number | null\n /** Per-transaction premium added on subscription payments, in basis points. */\n subscriptionPremiumBps: number | null\n /** Monthly transaction volume cap in USD cents. `null` for unlimited. */\n monthlyVolumeCapUsdCents: number | null\n /** Whether the \"Powered by Strimz\" badge can be removed from checkout. */\n whiteLabelEligible: boolean\n /** Whether the tier includes priority support. */\n prioritySupport: boolean\n}\n\nexport const TIERS: Record<MerchantTier, TierDefinition> = {\n free: {\n id: 'free',\n name: 'Free',\n monthlyFeeUsdCents: 0,\n oneShotFeeBps: 150, // 1.5%\n subscriptionPremiumBps: 20, // +0.2% on recurring => 1.7% effective\n monthlyVolumeCapUsdCents: 1_000_000, // $10,000\n whiteLabelEligible: false,\n prioritySupport: false,\n },\n growth: {\n id: 'growth',\n name: 'Growth',\n monthlyFeeUsdCents: 4_900, // $49\n oneShotFeeBps: 80, // 0.8%\n subscriptionPremiumBps: 20, // 1.0% effective\n monthlyVolumeCapUsdCents: 10_000_000, // $100,000\n whiteLabelEligible: true,\n prioritySupport: false,\n },\n business: {\n id: 'business',\n name: 'Business',\n monthlyFeeUsdCents: 19_900, // $199\n oneShotFeeBps: 50, // 0.5%\n subscriptionPremiumBps: 20, // 0.7% effective\n monthlyVolumeCapUsdCents: 100_000_000, // $1,000,000\n whiteLabelEligible: true,\n prioritySupport: true,\n },\n enterprise: {\n id: 'enterprise',\n name: 'Enterprise',\n monthlyFeeUsdCents: null,\n oneShotFeeBps: null,\n subscriptionPremiumBps: null,\n monthlyVolumeCapUsdCents: null,\n whiteLabelEligible: true,\n prioritySupport: true,\n },\n}\n\nexport const DEFAULT_TIER: MerchantTier = 'free'\n\nexport function getTier(id: MerchantTier): TierDefinition {\n return TIERS[id]\n}\n\n/**\n * Effective fee in bps for a given tier and payment kind.\n * Returns `null` for the enterprise tier (custom-priced).\n */\nexport function effectiveFeeBps(\n tier: MerchantTier,\n kind: 'one_shot' | 'subscription',\n): number | null {\n const def = TIERS[tier]\n if (def.oneShotFeeBps === null) return null\n if (kind === 'one_shot') return def.oneShotFeeBps\n return def.oneShotFeeBps + (def.subscriptionPremiumBps ?? 0)\n}\n"]}
1
+ {"version":3,"sources":["../src/tokens.ts","../src/tiers.ts"],"names":[],"mappings":";AAkBO,IAAM,cAAA,GAA0C,CAAC,MAAA,EAAQ,MAAM,CAAA;AAkB/D,IAAM,MAAA,GAA+C;AAAA,EAC1D,IAAA,EAAM;AAAA,IACJ,MAAA,EAAQ,MAAA;AAAA,IACR,IAAA,EAAM,UAAA;AAAA,IACN,QAAA,EAAU,CAAA;AAAA,IACV,eA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CAAM,CAAA,EAAG,IAAI,CAAA,wBAAA,CAA0B,CAAA;AAC1E,EAAA,OAAO,MAAA,CAAO,UAAU,CAAA,GAAI,GAAA,IAAO,OAAO,MAAA,CAAO,KAAK,EAAE,QAAQ,CAAA;AAClE;AAEO,SAAS,cAAc,OAAA,EAAqC;AACjE,EAAA,IAAI,OAAA,GAAsB,MAAA;AAC1B,EAAA,KAAA,MAAW,QAAQ,YAAA,EAAc;AAC/B,IAAA,IAAI,cAAA,CAAe,IAAA,CAAK,CAAC,KAAA,KAAU,OAAA,CAAQ,KAAK,CAAA,IAAK,oBAAA,CAAqB,IAAA,EAAM,KAAK,CAAC,CAAA,EAAG;AACvF,MAAA,OAAA,GAAU,IAAA;AAAA,IACZ;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAEO,SAAS,cAAA,CAAe,SAAuB,OAAA,EAA4C;AAChG,EAAA,IAAI,OAAA,KAAY,cAAc,OAAO,IAAA;AACrC,EAAA,MAAM,MAAA,GAAS,cAAc,OAAO,CAAA;AACpC,EAAA,OAAO,UAAA,CAAW,QAAQ,MAAM,CAAA,GAAI,WAAW,OAAA,CAAQ,OAAO,IAAI,MAAA,GAAS,IAAA;AAC7E","file":"tiers.js","sourcesContent":["/**\n * Token registry for Arc.\n *\n * USDC and EURC are first-class payment tokens. They can be requested in a\n * payment session and used as a subscription currency.\n *\n * USYC is yield-bearing and is treated as a treasury asset only. Merchants\n * can hold it and earn yield, but a payer cannot pay in USYC.\n */\n\nimport type { Address } from 'viem'\nimport { getArcChain, parseArcEnvironment, type ArcEnvironment } from './chains.js'\n\nexport type TokenSymbol = 'USDC' | 'EURC' | 'USYC'\n\n/** Tokens accepted as direct payment by Strimz. USYC is excluded by design. */\nexport type PaymentToken = Extract<TokenSymbol, 'USDC' | 'EURC'>\n\nexport const PAYMENT_TOKENS: readonly PaymentToken[] = ['USDC', 'EURC'] as const\n\nexport interface TokenDescriptor {\n symbol: TokenSymbol\n name: string\n decimals: number\n /** Whether the token is accepted as direct payment. */\n paymentEligible: boolean\n /** Whether the token is yield-bearing. */\n yieldBearing: boolean\n}\n\nexport interface TokenAddress {\n symbol: TokenSymbol\n address: Address\n chainId: number\n}\n\nexport const TOKENS: Record<TokenSymbol, TokenDescriptor> = {\n USDC: {\n symbol: 'USDC',\n name: 'USD Coin',\n decimals: 6,\n paymentEligible: true,\n yieldBearing: false,\n },\n EURC: {\n symbol: 'EURC',\n name: 'Euro Coin',\n decimals: 6,\n paymentEligible: true,\n yieldBearing: false,\n },\n USYC: {\n symbol: 'USYC',\n name: 'US Yield Coin',\n decimals: 6,\n paymentEligible: false,\n yieldBearing: true,\n },\n}\n\n/**\n * Native, Circle-issued addresses on Arc.\n * The same address is reused across testnet and mainnet for native tokens\n * since Arc preserves canonical addresses across environments where possible.\n */\nexport const TOKEN_ADDRESSES: Record<ArcEnvironment, Record<TokenSymbol, Address>> = {\n testnet: {\n USDC: '0x3600000000000000000000000000000000000000',\n EURC: '0x89B50855Aa3bE2F677cD6303Cec089B5F319D72a',\n USYC: '0xe9185F0c5F296Ed1797AaE4238D26CCaBEadb86C',\n },\n mainnet: {\n // Mainnet addresses pending Arc mainnet beta launch; placeholders mirror\n // testnet for now and must be replaced when Circle publishes the canonical\n // mainnet token registry.\n USDC: '0x3600000000000000000000000000000000000000',\n EURC: '0xbEf5f6d51CB62b58e6A8f77868681825C6fe21c1',\n USYC: '0x8a5D989Bbb96929F689B0200f435f53dA42bF490',\n },\n}\n\nexport function getTokenAddress(env: ArcEnvironment, symbol: TokenSymbol): Address {\n return TOKEN_ADDRESSES[parseArcEnvironment(env)][symbol]\n}\n\nexport function getTokenBySymbol(symbol: string): TokenDescriptor | undefined {\n return (TOKENS as Record<string, TokenDescriptor>)[symbol]\n}\n\nexport function isPaymentToken(symbol: string): symbol is PaymentToken {\n return PAYMENT_TOKENS.includes(symbol as PaymentToken)\n}\n\nexport function chainIdFor(env: ArcEnvironment): number {\n return getArcChain(env).id\n}\n","/**\n * Strimz pricing tiers.\n *\n * Fees are expressed in basis points (bps): 100 bps = 1%.\n * The subscription premium is added to the per-transaction rate when the\n * payment is recurring (i.e. originated from a SubscriptionPlan).\n */\n\nimport { PAYMENT_TOKENS, TOKENS, type PaymentToken } from './tokens.js'\n\nexport type MerchantTier = 'free' | 'starter' | 'growth' | 'enterprise'\n\nexport type VolumePlan = Exclude<MerchantTier, 'enterprise'>\n\nexport type PlanFeature = 'storefront' | 'anomaly_alerts' | 'yield_recommendations'\n\nexport interface PlanDefinition {\n id: MerchantTier\n name: string\n feeBps: number | null\n entersAtVolume: number | null\n features: readonly PlanFeature[]\n prioritySupport: boolean\n}\n\nconst PAID_FEATURES: readonly PlanFeature[] = [\n 'storefront',\n 'anomaly_alerts',\n 'yield_recommendations',\n]\n\nexport const PLANS: Record<MerchantTier, PlanDefinition> = {\n free: {\n id: 'free',\n name: 'Free',\n feeBps: 0,\n entersAtVolume: 0,\n features: [],\n prioritySupport: false,\n },\n starter: {\n id: 'starter',\n name: 'Starter',\n feeBps: 50,\n entersAtVolume: 1_000,\n features: PAID_FEATURES,\n prioritySupport: true,\n },\n growth: {\n id: 'growth',\n name: 'Growth',\n feeBps: 40,\n entersAtVolume: 50_000,\n features: PAID_FEATURES,\n prioritySupport: true,\n },\n enterprise: {\n id: 'enterprise',\n name: 'Enterprise',\n feeBps: null,\n entersAtVolume: null,\n features: PAID_FEATURES,\n prioritySupport: true,\n },\n}\n\nexport const DEFAULT_TIER: MerchantTier = 'free'\n\nconst PLAN_ORDER: readonly MerchantTier[] = ['free', 'starter', 'growth', 'enterprise']\n\nconst VOLUME_PLANS: readonly VolumePlan[] = ['free', 'starter', 'growth']\n\nexport const PLAN_FEE_CEILING_BPS: number = Math.max(\n ...VOLUME_PLANS.map((plan) => PLANS[plan].feeBps ?? 0),\n)\n\nexport function planFeeBps(plan: MerchantTier): number | null {\n return PLANS[plan].feeBps\n}\n\nexport function planIncludes(plan: MerchantTier, feature: PlanFeature): boolean {\n return PLANS[plan].features.includes(feature)\n}\n\nexport function plansWith(feature: PlanFeature): MerchantTier[] {\n return PLAN_ORDER.filter((plan) => planIncludes(plan, feature))\n}\n\nexport function lowestPlanWith(feature: PlanFeature): MerchantTier {\n const plan = PLAN_ORDER.find((candidate) => planIncludes(candidate, feature))\n if (!plan) throw new Error(`no plan includes ${feature}`)\n return plan\n}\n\nexport type PaymentVolumes = Readonly<Record<PaymentToken, bigint>>\n\nfunction thresholdInBaseUnits(plan: VolumePlan, token: PaymentToken): bigint {\n const wholeUnits = PLANS[plan].entersAtVolume\n if (wholeUnits === null) throw new Error(`${plan} has no volume threshold`)\n return BigInt(wholeUnits) * 10n ** BigInt(TOKENS[token].decimals)\n}\n\nexport function planForVolume(volumes: PaymentVolumes): VolumePlan {\n let reached: VolumePlan = 'free'\n for (const plan of VOLUME_PLANS) {\n if (PAYMENT_TOKENS.some((token) => volumes[token] >= thresholdInBaseUnits(plan, token))) {\n reached = plan\n }\n }\n return reached\n}\n\nexport function planUpgradeFor(current: MerchantTier, volumes: PaymentVolumes): VolumePlan | null {\n if (current === 'enterprise') return null\n const earned = planForVolume(volumes)\n return PLAN_ORDER.indexOf(earned) > PLAN_ORDER.indexOf(current) ? earned : null\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strimz/shared-config",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Single source of truth for chain definitions, token registry, fee tiers, webhook events, and agent flags.",
5
5
  "license": "MIT",
6
6
  "author": "Strimz <hello@strimz.finance>",
package/src/tiers.ts CHANGED
@@ -6,84 +6,112 @@
6
6
  * payment is recurring (i.e. originated from a SubscriptionPlan).
7
7
  */
8
8
 
9
- export type MerchantTier = 'free' | 'growth' | 'business' | 'enterprise'
9
+ import { PAYMENT_TOKENS, TOKENS, type PaymentToken } from './tokens.js'
10
10
 
11
- export interface TierDefinition {
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
- /** Monthly fee in USD cents (0 for free, null for custom enterprise). */
15
- monthlyFeeUsdCents: number | null
16
- /** Per-transaction fee on one-shot payments, in basis points. */
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
- export const TIERS: Record<MerchantTier, TierDefinition> = {
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
- monthlyFeeUsdCents: 0,
33
- oneShotFeeBps: 150, // 1.5%
34
- subscriptionPremiumBps: 20, // +0.2% on recurring => 1.7% effective
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
- monthlyFeeUsdCents: 4_900, // $49
43
- oneShotFeeBps: 80, // 0.8%
44
- subscriptionPremiumBps: 20, // 1.0% effective
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
- monthlyFeeUsdCents: null,
63
- oneShotFeeBps: null,
64
- subscriptionPremiumBps: null,
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
- export function getTier(id: MerchantTier): TierDefinition {
74
- return TIERS[id]
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
- * Effective fee in bps for a given tier and payment kind.
79
- * Returns `null` for the enterprise tier (custom-priced).
80
- */
81
- export function effectiveFeeBps(
82
- tier: MerchantTier,
83
- kind: 'one_shot' | 'subscription',
84
- ): number | null {
85
- const def = TIERS[tier]
86
- if (def.oneShotFeeBps === null) return null
87
- if (kind === 'one_shot') return def.oneShotFeeBps
88
- return def.oneShotFeeBps + (def.subscriptionPremiumBps ?? 0)
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
111
+ }
112
+
113
+ export function planUpgradeFor(current: MerchantTier, volumes: PaymentVolumes): VolumePlan | null {
114
+ if (current === 'enterprise') return null
115
+ const earned = planForVolume(volumes)
116
+ return PLAN_ORDER.indexOf(earned) > PLAN_ORDER.indexOf(current) ? earned : null
89
117
  }