Class: RegionService
Provides layer to manipulate regions.
Hierarchy
TransactionBaseService
↳
RegionService
Constructors
constructor
• new RegionService(__namedParameters
)
Parameters
Name | Type |
---|---|
__namedParameters | InjectedDependencies |
Overrides
TransactionBaseService.constructor
Defined in
packages/medusa/src/services/region.ts:67
Properties
__configModule__
• Protected
Optional
Readonly
__configModule__: Record
<string
, unknown
>
Inherited from
TransactionBaseService.__configModule__
Defined in
packages/medusa/src/interfaces/transaction-base-service.ts:10
__container__
• Protected
Readonly
__container__: any
Inherited from
TransactionBaseService.__container__
Defined in
packages/medusa/src/interfaces/transaction-base-service.ts:9
__moduleDeclaration__
• Protected
Optional
Readonly
__moduleDeclaration__: Record
<string
, unknown
>
Inherited from
TransactionBaseService.__moduleDeclaration__
Defined in
packages/medusa/src/interfaces/transaction-base-service.ts:11
countryRepository_
• Protected
Readonly
countryRepository_: typeof CountryRepository
Defined in
packages/medusa/src/services/region.ts:59
currencyRepository_
• Protected
Readonly
currencyRepository_: typeof CurrencyRepository
Defined in
packages/medusa/src/services/region.ts:60
eventBus_
• Protected
Readonly
eventBus_: EventBusService
Defined in
packages/medusa/src/services/region.ts:54
featureFlagRouter_
• Protected
featureFlagRouter_: FlagRouter
Defined in
packages/medusa/src/services/region.ts:52
fulfillmentProviderRepository_
• Protected
Readonly
fulfillmentProviderRepository_: typeof FulfillmentProviderRepository
Defined in
packages/medusa/src/services/region.ts:64
fulfillmentProviderService_
• Protected
Readonly
fulfillmentProviderService_: FulfillmentProviderService
Defined in
packages/medusa/src/services/region.ts:57
manager_
• Protected
manager_: EntityManager
Overrides
TransactionBaseService.manager_
Defined in
packages/medusa/src/services/region.ts:50
paymentProviderRepository_
• Protected
Readonly
paymentProviderRepository_: typeof PaymentProviderRepository
Defined in
packages/medusa/src/services/region.ts:62
paymentProviderService_
• Protected
Readonly
paymentProviderService_: PaymentProviderService
Defined in
packages/medusa/src/services/region.ts:56
regionRepository_
• Protected
Readonly
regionRepository_: typeof RegionRepository
Defined in
packages/medusa/src/services/region.ts:58
storeService_
• Protected
Readonly
storeService_: StoreService
Defined in
packages/medusa/src/services/region.ts:55
taxProviderRepository_
• Protected
Readonly
taxProviderRepository_: typeof TaxProviderRepository
Defined in
packages/medusa/src/services/region.ts:65
transactionManager_
• Protected
transactionManager_: undefined
| EntityManager
Overrides
TransactionBaseService.transactionManager_
Defined in
packages/medusa/src/services/region.ts:51
Events
▪ Static
Events: Object
Type declaration
Name | Type |
---|---|
CREATED | string |
DELETED | string |
UPDATED | string |
Defined in
packages/medusa/src/services/region.ts:44
Methods
addCountry
▸ addCountry(regionId
, code
): Promise
<Region
>
Adds a country to the region.
Parameters
Name | Type | Description |
---|---|---|
regionId | string | the region to add a country to |
code | string | a 2 digit alphanumeric ISO country code. |
Returns
Promise
<Region
>
the updated Region
Defined in
packages/medusa/src/services/region.ts:580
addFulfillmentProvider
▸ addFulfillmentProvider(regionId
, providerId
): Promise
<Region
>
Adds a fulfillment provider that is available in the region. Fails if the provider doesn't exist.
Parameters
Name | Type | Description |
---|---|---|
regionId | string | the region to add the provider to |
providerId | string | the provider to add to the region |
Returns
Promise
<Region
>
the updated Region
Defined in
packages/medusa/src/services/region.ts:710
addPaymentProvider
▸ addPaymentProvider(regionId
, providerId
): Promise
<Region
>
Adds a payment provider that is available in the region. Fails if the provider doesn't exist.
Parameters
Name | Type | Description |
---|---|---|
regionId | string | the region to add the provider to |
providerId | string | the provider to add to the region |
Returns
Promise
<Region
>
the updated Region
Defined in
packages/medusa/src/services/region.ts:659
atomicPhase_
▸ Protected
atomicPhase_<TResult
, TError
>(work
, isolationOrErrorHandler?
, maybeErrorHandlerOrDontFail?
): Promise
<TResult
>
Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.
Type parameters
Name |
---|
TResult |
TError |
Parameters
Name | Type | Description |
---|---|---|
work | (transactionManager : EntityManager ) => Promise <TResult > | the transactional work to be done |
isolationOrErrorHandler? | IsolationLevel | (error : TError ) => Promise <void | TResult > | the isolation level to be used for the work. |
maybeErrorHandlerOrDontFail? | (error : TError ) => Promise <void | TResult > | Potential error handler |
Returns
Promise
<TResult
>
the result of the transactional work
Inherited from
TransactionBaseService.atomicPhase_
Defined in
packages/medusa/src/interfaces/transaction-base-service.ts:50
create
▸ create(data
): Promise
<Region
>
Creates a region.
Parameters
Name | Type | Description |
---|---|---|
data | CreateRegionInput | the unvalidated region |
Returns
Promise
<Region
>
the newly created region
Defined in
packages/medusa/src/services/region.ts:117
delete
▸ delete(regionId
): Promise
<void
>
Deletes a region.
Parameters
Name | Type | Description |
---|---|---|
regionId | string | the region to delete |
Returns
Promise
<void
>
the result of the delete operation
Defined in
packages/medusa/src/services/region.ts:549
list
▸ list(selector?
, config?
): Promise
<Region
[]>
Lists all regions based on a query
Parameters
Name | Type | Description |
---|---|---|
selector | Selector <Region > | query object for find |
config | FindConfig <Region > | configuration settings |
Returns
Promise
<Region
[]>
result of the find operation
Defined in
packages/medusa/src/services/region.ts:529
removeCountry
▸ removeCountry(regionId
, code
): Promise
<Region
>
Removes a country from a Region.
Parameters
Name | Type | Description |
---|---|---|
regionId | string | the region to remove from |
code | string | a 2 digit alphanumeric ISO country code to remove |
Returns
Promise
<Region
>
the updated Region
Defined in
packages/medusa/src/services/region.ts:618
removeFulfillmentProvider
▸ removeFulfillmentProvider(regionId
, providerId
): Promise
<Region
>
Removes a fulfillment provider from a region. Is idempotent.
Parameters
Name | Type | Description |
---|---|---|
regionId | string | the region to remove the provider from |
providerId | string | the provider to remove from the region |
Returns
Promise
<Region
>
the updated Region
Defined in
packages/medusa/src/services/region.ts:798
removePaymentProvider
▸ removePaymentProvider(regionId
, providerId
): Promise
<Region
>
Removes a payment provider from a region. Is idempotent.
Parameters
Name | Type | Description |
---|---|---|
regionId | string | the region to remove the provider from |
providerId | string | the provider to remove from the region |
Returns
Promise
<Region
>
the updated Region
Defined in
packages/medusa/src/services/region.ts:759
retrieve
▸ retrieve(regionId
, config?
): Promise
<Region
>
Retrieves a region by its id.
Parameters
Name | Type | Description |
---|---|---|
regionId | string | the id of the region to retrieve |
config | FindConfig <Region > | configuration settings |
Returns
Promise
<Region
>
the region
Defined in
packages/medusa/src/services/region.ts:494
retrieveByCountryCode
▸ retrieveByCountryCode(code
, config?
): Promise
<Region
>
Retrieve a region by country code.
Parameters
Name | Type | Description |
---|---|---|
code | string | a 2 digit alphanumeric ISO country code |
config | FindConfig <Region > | region find config |
Returns
Promise
<Region
>
a Region with country code
Defined in
packages/medusa/src/services/region.ts:437
retrieveByName
▸ retrieveByName(name
): Promise
<Region
>
Retrieves a region by name.
Parameters
Name | Type | Description |
---|---|---|
name | string | the name of the region to retrieve |
Returns
Promise
<Region
>
region with the matching name
Defined in
packages/medusa/src/services/region.ts:474
shouldRetryTransaction_
▸ Protected
shouldRetryTransaction_(err
): boolean
Parameters
Name | Type |
---|---|
err | Record <string , unknown > | { code : string } |
Returns
boolean
Inherited from
TransactionBaseService.shouldRetryTransaction_
Defined in
packages/medusa/src/interfaces/transaction-base-service.ts:31
update
▸ update(regionId
, update
): Promise
<Region
>
Updates a region
Parameters
Name | Type | Description |
---|---|---|
regionId | string | the region to update |
update | UpdateRegionInput | the data to update the region with |
Returns
Promise
<Region
>
the result of the update operation
Defined in
packages/medusa/src/services/region.ts:190
validateCountry
▸ Protected
validateCountry(code
, regionId
): Promise
<Country
>
Validates a country code. Will normalize the code before checking for existence.
Parameters
Name | Type | Description |
---|---|---|
code | string | a 2 digit alphanumeric ISO country code |
regionId | string | the id of the current region to check against |
Returns
Promise
<Country
>
the validated Country
Defined in
packages/medusa/src/services/region.ts:388
validateCurrency
▸ Protected
validateCurrency(currencyCode
): Promise
<void
>
Validates a currency code. Will throw if the currency code doesn't exist.
Throws
if the provided currency code is invalid
Parameters
Name | Type | Description |
---|---|---|
currencyCode | string | an ISO currency code |
Returns
Promise
<void
>
void
Defined in
packages/medusa/src/services/region.ts:363
validateFields
▸ Protected
validateFields<T
>(regionData
, id?
): Promise
<{ automatic_taxes?
: boolean
; countries?
: (undefined
| { id?: number | undefined; iso_2?: string | undefined; iso_3?: string | undefined; num_code?: number | undefined; name?: string | undefined; display_name?: string | undefined; region_id?: string | ... 1 more ... | undefined; region?: { ...; } | undefined; })[] ; created_at?
: { toString?: {} | undefined; toDateString?: {} | undefined; toTimeString?: {} | undefined; toLocaleString?: {} | undefined; toLocaleDateString?: {} | undefined; toLocaleTimeString?: {} | undefined; ... 37 more ...; [Symbol.toPrimitive]?: {} | undefined; } ; currency?
: { code?: string | undefined; symbol?: string | undefined; symbol_native?: string | undefined; name?: string | undefined; includes_tax?: boolean | undefined; } ; currency_code?
: string
; deleted_at?
: null
| { toString?: {} | undefined; toDateString?: {} | undefined; toTimeString?: {} | undefined; toLocaleString?: {} | undefined; toLocaleDateString?: {} | undefined; toLocaleTimeString?: {} | undefined; ... 37 more ...; [Symbol.toPrimitive]?: {} | undefined; } ; fulfillment_providers?
: (undefined
| { id?: string | undefined; is_installed?: boolean | undefined; })[] ; gift_cards_taxable?
: boolean
; id?
: string
; includes_tax?
: boolean
; metadata?
: { [x: string]: unknown; } ; name?
: string
; payment_providers?
: (undefined
| { id?: string | undefined; is_installed?: boolean | undefined; })[] ; tax_code?
: string
; tax_provider?
: { id?: string | undefined; is_installed?: boolean | undefined; } ; tax_provider_id?
: null
| string
; tax_rate?
: number
; tax_rates?
: null
| (undefined
| { rate?: number | null | undefined; code?: string | null | undefined; name?: string | undefined; region_id?: string | undefined; region?: { name?: string | undefined; currency_code?: string | undefined; ... 16 more ...; updated_at?: { ...; } | undefined; } | undefined; ... 9 more ...; updated_at?: { ...; } | undefin...)[] ; updated_at?
: { toString?: {} | undefined; toDateString?: {} | undefined; toTimeString?: {} | undefined; toLocaleString?: {} | undefined; toLocaleDateString?: {} | undefined; toLocaleTimeString?: {} | undefined; ... 37 more ...; [Symbol.toPrimitive]?: {} | undefined; } }>
Validates fields for creation and updates. If the region already exists the id can be passed to check that country updates are allowed.
Type parameters
Name | Type |
---|---|
T | extends UpdateRegionInput | CreateRegionInput |
Parameters
Name | Type | Description |
---|---|---|
regionData | Omit <T , "metadata" | "currency_code" > | the region data to validate |
id? | T extends UpdateRegionInput ? string : undefined | optional id of the region to check against |
Returns
Promise
<{ automatic_taxes?
: boolean
; countries?
: (undefined
| { id?: number | undefined; iso_2?: string | undefined; iso_3?: string | undefined; num_code?: number | undefined; name?: string | undefined; display_name?: string | undefined; region_id?: string | ... 1 more ... | undefined; region?: { ...; } | undefined; })[] ; created_at?
: { toString?: {} | undefined; toDateString?: {} | undefined; toTimeString?: {} | undefined; toLocaleString?: {} | undefined; toLocaleDateString?: {} | undefined; toLocaleTimeString?: {} | undefined; ... 37 more ...; [Symbol.toPrimitive]?: {} | undefined; } ; currency?
: { code?: string | undefined; symbol?: string | undefined; symbol_native?: string | undefined; name?: string | undefined; includes_tax?: boolean | undefined; } ; currency_code?
: string
; deleted_at?
: null
| { toString?: {} | undefined; toDateString?: {} | undefined; toTimeString?: {} | undefined; toLocaleString?: {} | undefined; toLocaleDateString?: {} | undefined; toLocaleTimeString?: {} | undefined; ... 37 more ...; [Symbol.toPrimitive]?: {} | undefined; } ; fulfillment_providers?
: (undefined
| { id?: string | undefined; is_installed?: boolean | undefined; })[] ; gift_cards_taxable?
: boolean
; id?
: string
; includes_tax?
: boolean
; metadata?
: { [x: string]: unknown; } ; name?
: string
; payment_providers?
: (undefined
| { id?: string | undefined; is_installed?: boolean | undefined; })[] ; tax_code?
: string
; tax_provider?
: { id?: string | undefined; is_installed?: boolean | undefined; } ; tax_provider_id?
: null
| string
; tax_rate?
: number
; tax_rates?
: null
| (undefined
| { rate?: number | null | undefined; code?: string | null | undefined; name?: string | undefined; region_id?: string | undefined; region?: { name?: string | undefined; currency_code?: string | undefined; ... 16 more ...; updated_at?: { ...; } | undefined; } | undefined; ... 9 more ...; updated_at?: { ...; } | undefin...)[] ; updated_at?
: { toString?: {} | undefined; toDateString?: {} | undefined; toTimeString?: {} | undefined; toLocaleString?: {} | undefined; toLocaleDateString?: {} | undefined; toLocaleTimeString?: {} | undefined; ... 37 more ...; [Symbol.toPrimitive]?: {} | undefined; } }>
the validated region data
Defined in
packages/medusa/src/services/region.ts:261
validateTaxRate
▸ Protected
validateTaxRate(taxRate
): void
Validates a tax rate. Will throw if the tax rate is not between 0 and 1.
Throws
if the tax rate isn't number between 0-100
Parameters
Name | Type | Description |
---|---|---|
taxRate | number | a number representing the tax rate of the region |
Returns
void
void
Defined in
packages/medusa/src/services/region.ts:347
withTransaction
▸ withTransaction(transactionManager?
): RegionService
Parameters
Name | Type |
---|---|
transactionManager? | EntityManager |
Returns
Inherited from
TransactionBaseService.withTransaction
Defined in
packages/medusa/src/interfaces/transaction-base-service.ts:14