11/* eslint-disable @typescript-eslint/naming-convention */
2- import { randomUUID } from 'crypto' ;
2+ import { randomUUID } from 'node: crypto' ;
33import { inject } from '@loopback/core' ;
44import chargebee from 'chargebee' ;
55import {
@@ -21,6 +21,8 @@ import {
2121import { ChargeBeeBindings } from './key' ;
2222import {
2323 ChargeBeeConfig ,
24+ ChargebeePeriodUnit ,
25+ ChargebeePricingModel ,
2426 IChargeBeeCustomer ,
2527 IChargeBeeInvoice ,
2628 IChargeBeePaymentSource ,
@@ -310,14 +312,14 @@ export class ChargeBeeService implements IChargeBeeService {
310312 try {
311313 const itemId = product . name
312314 . toLowerCase ( )
313- . replace ( / [ ^ a - z 0 - 9 ] + / g, '-' )
314- . replace ( / ^ - | - $ / g, '' ) ;
315+ . replaceAll ( / [ ^ a - z 0 - 9 ] + / g, '-' )
316+ . replaceAll ( / ^ - | - $ / g, '' ) ;
315317
316318 // Strip item_family_id from metadata — it is a top-level Chargebee param,
317319 // and Chargebee rejects it if it appears inside metadata.
318320 // eslint-disable-next-line @typescript-eslint/no-unused-vars
319- const { item_family_id : _ignored , ...restMetadata } = ( product . metadata ??
320- { } ) as Record < string , unknown > ;
321+ const { item_family_id : _ignored , ...restMetadata } =
322+ product . metadata ?? { } ;
321323 const hasExtraMetadata = Object . keys ( restMetadata ) . length > 0 ;
322324
323325 const result = await chargebee . item
@@ -327,7 +329,7 @@ export class ChargeBeeService implements IChargeBeeService {
327329 description : product . description ,
328330 type : 'plan' ,
329331 item_family_id :
330- ( product . metadata ?. [ 'item_family_id' ] as string ) ??
332+ product . metadata ?. [ 'item_family_id' ] ??
331333 this . chargeBeeConfig . defaultItemFamilyId ??
332334 'default' ,
333335 // Only include metadata key if there are non-family fields to send.
@@ -367,17 +369,9 @@ export class ChargeBeeService implements IChargeBeeService {
367369 currency_code : price . currency . toUpperCase ( ) ,
368370 price : price . unitAmount ,
369371 pricing_model : ( this . chargeBeeConfig . defaultPricingModel ??
370- 'flat_fee' ) as
371- | 'flat_fee'
372- | 'per_unit'
373- | 'tiered'
374- | 'volume'
375- | 'stairstep' ,
372+ 'flat_fee' ) as ChargebeePricingModel ,
376373 period_unit : price . recurring ?. interval as
377- | 'day'
378- | 'week'
379- | 'month'
380- | 'year'
374+ | ChargebeePeriodUnit
381375 | undefined ,
382376 period : price . recurring ?. intervalCount ,
383377 tax_providers_fields : [ ] , // Required by SDK type but can be empty
@@ -585,10 +579,11 @@ export class ChargeBeeService implements IChargeBeeService {
585579 const result = await chargebee . item . retrieve ( productId ) . request ( ) ;
586580 return result . item . status === 'active' ;
587581 } catch ( error ) {
582+ const HTTP_NOT_FOUND = 404 ;
588583 const cbError = error as { api_error_code ?: string ; http_status ?: number } ;
589584 if (
590585 cbError . api_error_code === 'resource_not_found' ||
591- cbError . http_status === 404
586+ cbError . http_status === HTTP_NOT_FOUND
592587 ) {
593588 return false ;
594589 }
0 commit comments