Skip to main content
Skip to main content
You're viewing the documentation for v1, which isn't the latest Medusa version.Latest documentation

RegionService

Provides layer to manipulate regions.

constructor​

Parameters​

__namedParametersInjectedDependenciesRequired

Properties​

manager_EntityManagerRequired
transactionManager_undefined | EntityManagerRequired
__container__anyRequired
EventsobjectRequired
Events.UPDATEDstringRequired

Default: "region.updated"

Events.CREATEDstringRequired

Default: "region.created"

Events.DELETEDstringRequired

Default: "region.deleted"

featureFlagRouter_FlagRouterRequired
eventBus_EventBusServiceRequired
storeService_StoreServiceRequired
paymentProviderService_PaymentProviderServiceRequired
fulfillmentProviderService_FulfillmentProviderServiceRequired
regionRepository_Repository<Region>Required
countryRepository_Repository<Country>Required
currencyRepository_Repository<Currency>Required
paymentProviderRepository_Repository<PaymentProvider>Required
fulfillmentProviderRepository_Repository<FulfillmentProvider>Required
taxProviderRepository_Repository<TaxProvider>Required
__configModule__Record<string, unknown>
__moduleDeclaration__Record<string, unknown>

Accessors​

activeManager_​

Returns​

EntityManagerEntityManagerRequired

Methods​

withTransaction​

Parameters​

transactionManagerEntityManager

Returns​

thisthisRequired

shouldRetryTransaction_​

Parameters​

errRecord<string, unknown> | objectRequired

Returns​

booleanbooleanRequired

atomicPhase_​

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​

TResultobjectRequired
TErrorobjectRequired

Parameters​

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler

Returns​

PromisePromise<TResult>Required
the result of the transactional work

create​

Creates a region.

Parameters​

dataCreateRegionInputRequired
the unvalidated region

Returns​

PromisePromise<Region>Required
the newly created region

update​

Updates a region

Parameters​

regionIdstringRequired
the region to update
updateUpdateRegionInputRequired
the data to update the region with

Returns​

PromisePromise<Region>Required
the result of the update operation

validateFields​

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​

TUpdateRegionInput | CreateRegionInputRequired

Parameters​

regionDataOmit<T, "metadata" | "currency_code">Required
the region data to validate
idT extends UpdateRegionInput ? string : undefined
optional id of the region to check against

Returns​

PromisePromise<DeepPartial<Region>>Required
the validated region data

validateTaxRate​

Validates a tax rate. Will throw if the tax rate is not between 0 and 1.

Parameters​

taxRatenumberRequired
a number representing the tax rate of the region

Returns​

voidvoidRequired
void

Throws​

if the tax rate isn't number between 0-100

validateCurrency​

Validates a currency code. Will throw if the currency code doesn't exist.

Parameters​

currencyCodestringRequired
an ISO currency code

Returns​

PromisePromise<void>Required
void

Throws​

if the provided currency code is invalid

validateCountry​

Validates a country code. Will normalize the code before checking for existence.

Parameters​

codestringRequired
a 2 digit alphanumeric ISO country code
regionIdstringRequired
the id of the current region to check against

Returns​

PromisePromise<Country>Required
the validated Country

retrieveByCountryCode​

Retrieve a region by country code.

Parameters​

codestringRequired
a 2 digit alphanumeric ISO country code
configFindConfig<Region>Required
region find config

Default: {}

Returns​

PromisePromise<Region>Required
a Region with country code

retrieveByName​

Retrieves a region by name.

Parameters​

namestringRequired
the name of the region to retrieve

Returns​

PromisePromise<Region>Required
region with the matching name

retrieve​

Retrieves a region by its id.

Parameters​

regionIdstringRequired
the id of the region to retrieve
configFindConfig<Region>Required
configuration settings

Default: {}

Returns​

PromisePromise<Region>Required
the region

list​

Lists all regions based on a query

Parameters​

selectorSelector<Region>Required
query object for find

Default: {}

configFindConfig<Region>Required
configuration settings

Returns​

PromisePromise<Region[]>Required
result of the find operation

listAndCount​

Lists all regions based on a query and returns them along with count

Parameters​

selectorSelector<Region> & objectRequired
query object for find

Default: {}

configFindConfig<Region>Required
configuration settings

Returns​

PromisePromise<[Region[], number]>Required
result of the find operation

delete​

Deletes a region.

Parameters​

regionIdstringRequired
the region to delete

Returns​

PromisePromise<void>Required
the result of the delete operation

addCountry​

Adds a country to the region.

Parameters​

regionIdstringRequired
the region to add a country to
codestringRequired
a 2 digit alphanumeric ISO country code.

Returns​

PromisePromise<Region>Required
the updated Region

removeCountry​

Removes a country from a Region.

Parameters​

regionIdstringRequired
the region to remove from
codestringRequired
a 2 digit alphanumeric ISO country code to remove

Returns​

PromisePromise<Region>Required
the updated Region

addPaymentProvider​

Adds a payment provider that is available in the region. Fails if the provider doesn't exist.

Parameters​

regionIdstringRequired
the region to add the provider to
providerIdstringRequired
the provider to add to the region

Returns​

PromisePromise<Region>Required
the updated Region

addFulfillmentProvider​

Adds a fulfillment provider that is available in the region. Fails if the provider doesn't exist.

Parameters​

regionIdstringRequired
the region to add the provider to
providerIdstringRequired
the provider to add to the region

Returns​

PromisePromise<Region>Required
the updated Region

removePaymentProvider​

Removes a payment provider from a region. Is idempotent.

Parameters​

regionIdstringRequired
the region to remove the provider from
providerIdstringRequired
the provider to remove from the region

Returns​

PromisePromise<Region>Required
the updated Region

removeFulfillmentProvider​

Removes a fulfillment provider from a region. Is idempotent.

Parameters​

regionIdstringRequired
the region to remove the provider from
providerIdstringRequired
the provider to remove from the region

Returns​

PromisePromise<Region>Required
the updated Region
Was this section helpful?