@@ -87,66 +87,66 @@ function planToOffer(plan: RawPlan, baseUrl: string) {
8787 } ) ;
8888 }
8989
90+ const items = plan . items . filter (
91+ ( i ) : i is Extract < RawItem , { type : 'priced_feature' } > =>
92+ i . type === 'priced_feature'
93+ ) ;
94+
9095 // priced_feature with tiers (events, extra websites, etc.)
91- plan . items
92- . filter (
93- ( i ) : i is Extract < RawItem , { type : 'priced_feature' } > =>
94- i . type === 'priced_feature'
95- )
96- . forEach ( ( pf ) => {
97- // Event overage tiers → convert per-event micro price to per-1,000 events
98- if ( pf . feature ?. id === 'events' && pf . tiers ?. length ) {
99- // Start tier ranges right after included quota (if any)
100- let prevMax : number | undefined =
101- typeof pf . included_usage === 'number' ? pf . included_usage : undefined ;
102-
103- pf . tiers . forEach ( ( t ) => {
104- const minValue = prevMax != null ? prevMax + 1 : undefined ;
105- const maxValue = t . to === 'inf' ? undefined : ( t . to as number ) ;
106-
107- priceSpecs . push ( {
108- '@type' : 'UnitPriceSpecification' ,
109- price : priceStr ( t . amount * BLOCK_UNITS_FOR_EVENTS , 2 ) , // e.g. "0.03" per 1,000 events
110- priceCurrency : 'USD' ,
111- referenceQuantity : {
112- '@type' : 'QuantitativeValue' ,
113- value : BLOCK_UNITS_FOR_EVENTS ,
114- unitText : 'events' ,
115- } ,
116- eligibleQuantity : {
117- '@type' : 'QuantitativeValue' ,
118- minValue,
119- maxValue,
120- unitText : 'events' ,
121- } ,
122- unitText : 'per 1,000 events (overage)' ,
123- } ) ;
124-
125- if ( t . to !== 'inf' ) {
126- prevMax = t . to as number ;
127- }
128- } ) ;
129- }
130- // Other priced features (e.g., extra websites per month)
131- else if ( typeof pf . price === 'number' ) {
132- const refUnit = toUnitCode ( pf . interval ) ;
96+ for ( const pf of items ) {
97+ // Event overage tiers → convert per-event micro price to per-1,000 events
98+ if ( pf . feature ?. id === 'events' && pf . tiers ?. length ) {
99+ // Start tier ranges right after included quota (if any)
100+ let prevMax : number | undefined =
101+ typeof pf . included_usage === 'number' ? pf . included_usage : undefined ;
102+
103+ for ( const t of pf . tiers ) {
104+ const minValue = prevMax != null ? prevMax + 1 : undefined ;
105+ const maxValue = t . to === 'inf' ? undefined : ( t . to as number ) ;
106+
133107 priceSpecs . push ( {
134108 '@type' : 'UnitPriceSpecification' ,
135- price : priceStr ( pf . price , 2 ) , // e.g. "0.50"
109+ price : priceStr ( t . amount * BLOCK_UNITS_FOR_EVENTS , 2 ) , // e.g. "0.03" per 1,000 events
136110 priceCurrency : 'USD' ,
137- unitText : `per ${ pf . feature ?. display ?. singular ?? 'unit' } ` ,
138- ...( refUnit
139- ? {
140- referenceQuantity : {
141- '@type' : 'QuantitativeValue' ,
142- value : 1 ,
143- unitCode : refUnit , // MON or DAY
144- } ,
145- }
146- : { } ) ,
111+ referenceQuantity : {
112+ '@type' : 'QuantitativeValue' ,
113+ value : BLOCK_UNITS_FOR_EVENTS ,
114+ unitText : 'events' ,
115+ } ,
116+ eligibleQuantity : {
117+ '@type' : 'QuantitativeValue' ,
118+ minValue,
119+ maxValue,
120+ unitText : 'events' ,
121+ } ,
122+ unitText : 'per 1,000 events (overage)' ,
147123 } ) ;
124+
125+ if ( t . to !== 'inf' ) {
126+ prevMax = t . to as number ;
127+ }
148128 }
149- } ) ;
129+ }
130+ // Other priced features (e.g., extra websites per month)
131+ else if ( typeof pf . price === 'number' ) {
132+ const refUnit = toUnitCode ( pf . interval ) ;
133+ priceSpecs . push ( {
134+ '@type' : 'UnitPriceSpecification' ,
135+ price : priceStr ( pf . price , 2 ) , // e.g. "0.50"
136+ priceCurrency : 'USD' ,
137+ unitText : `per ${ pf . feature ?. display ?. singular ?? 'unit' } ` ,
138+ ...( refUnit
139+ ? {
140+ referenceQuantity : {
141+ '@type' : 'QuantitativeValue' ,
142+ value : 1 ,
143+ unitCode : refUnit , // MON or DAY
144+ } ,
145+ }
146+ : { } ) ,
147+ } ) ;
148+ }
149+ }
150150
151151 return {
152152 '@type' : 'Offer' ,
0 commit comments