---
displayed_sidebar: servicesSidebar
---

import TypeList from "@site/src/components/TypeList"

# RegionService

Provides layer to manipulate regions.

## constructor

### Parameters

<TypeList types={[{"name":"__namedParameters","type":"`InjectedDependencies`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="new RegionService"/>

___

## Properties

<TypeList types={[{"name":"manager_","type":"`EntityManager`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionManager_","type":"`undefined` \\| `EntityManager`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"__container__","type":"`any`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"Events","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"Events.UPDATED","type":"`string`","description":"","optional":false,"defaultValue":"\"region.updated\"","expandable":false,"children":[]},{"name":"Events.CREATED","type":"`string`","description":"","optional":false,"defaultValue":"\"region.created\"","expandable":false,"children":[]},{"name":"Events.DELETED","type":"`string`","description":"","optional":false,"defaultValue":"\"region.deleted\"","expandable":false,"children":[]},{"name":"featureFlagRouter_","type":"`FlagRouter`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"eventBus_","type":"[EventBusService](services.EventBusService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"storeService_","type":"[StoreService](services.StoreService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"paymentProviderService_","type":"[PaymentProviderService](services.PaymentProviderService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillmentProviderService_","type":"[FulfillmentProviderService](services.FulfillmentProviderService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"regionRepository_","type":"Repository&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"countryRepository_","type":"Repository&#60;[Country](../../entities/classes/entities.Country.mdx)&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"currencyRepository_","type":"Repository&#60;[Currency](../../entities/classes/entities.Currency.mdx)&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"paymentProviderRepository_","type":"Repository&#60;[PaymentProvider](../../entities/classes/entities.PaymentProvider.mdx)&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillmentProviderRepository_","type":"Repository&#60;[FulfillmentProvider](../../entities/classes/entities.FulfillmentProvider.mdx)&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"taxProviderRepository_","type":"Repository&#60;[TaxProvider](../../entities/classes/entities.TaxProvider.mdx)&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"__configModule__","type":"`Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"__moduleDeclaration__","type":"`Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="RegionService"/>

___

## Accessors

### activeManager\_

#### Returns

<TypeList types={[{"name":"EntityManager","type":"`EntityManager`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}  sectionTitle="activeManager_"/>

___

## Methods

### withTransaction

#### Parameters

<TypeList types={[{"name":"transactionManager","type":"`EntityManager`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="withTransaction"/>

#### Returns

<TypeList types={[{"name":"this","type":"`this`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}  sectionTitle="withTransaction"/>

### shouldRetryTransaction\_

#### Parameters

<TypeList types={[{"name":"err","type":"`Record<string, unknown>` \\| `object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="shouldRetryTransaction_"/>

#### Returns

<TypeList types={[{"name":"boolean","type":"`boolean`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}  sectionTitle="shouldRetryTransaction_"/>

### 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

<TypeList types={[{"name":"TResult","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TError","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="atomicPhase_"/>

#### Parameters

<TypeList types={[{"name":"work","type":"(`transactionManager`: `EntityManager`) => Promise&#60;TResult&#62;","description":"the transactional work to be done","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationOrErrorHandler","type":"`IsolationLevel` \\| (`error`: TError) => Promise&#60;void \\| TResult&#62;","description":"the isolation level to be used for the work.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"maybeErrorHandlerOrDontFail","type":"(`error`: TError) => Promise&#60;void \\| TResult&#62;","description":"Potential error handler","optional":true,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="atomicPhase_"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;TResult&#62;","optional":false,"defaultValue":"","description":"the result of the transactional work","expandable":false,"children":[]}]}  sectionTitle="atomicPhase_"/>

### create

Creates a region.

#### Parameters

<TypeList types={[{"name":"data","type":"`CreateRegionInput`","description":"the unvalidated region","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="create"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","optional":false,"defaultValue":"","description":"the newly created region","expandable":false,"children":[]}]}  sectionTitle="create"/>

### update

Updates a region

#### Parameters

<TypeList types={[{"name":"regionId","type":"`string`","description":"the region to update","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"update","type":"`UpdateRegionInput`","description":"the data to update the region with","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="update"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","optional":false,"defaultValue":"","description":"the result of the update operation","expandable":false,"children":[]}]}  sectionTitle="update"/>

### 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

<TypeList types={[{"name":"T","type":"`UpdateRegionInput` \\| `CreateRegionInput`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="validateFields"/>

#### Parameters

<TypeList types={[{"name":"regionData","type":"Omit&#60;T, \"metadata\" \\| \"currency_code\"&#62;","description":"the region data to validate","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"id","type":"T extends `UpdateRegionInput` ? `string` : `undefined`","description":"optional id of the region to check against","optional":true,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="validateFields"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;DeepPartial&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;&#62;","optional":false,"defaultValue":"","description":"the validated region data","expandable":false,"children":[]}]}  sectionTitle="validateFields"/>

### validateTaxRate

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

#### Parameters

<TypeList types={[{"name":"taxRate","type":"`number`","description":"a number representing the tax rate of the region","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="validateTaxRate"/>

#### Returns

<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"void","expandable":false,"children":[]}]}  sectionTitle="validateTaxRate"/>

#### 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

<TypeList types={[{"name":"currencyCode","type":"`string`","description":"an ISO currency code","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="validateCurrency"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;void&#62;","optional":false,"defaultValue":"","description":"void","expandable":false,"children":[]}]}  sectionTitle="validateCurrency"/>

#### Throws

if the provided currency code is invalid

### validateCountry

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

#### Parameters

<TypeList types={[{"name":"code","type":"`string`","description":"a 2 digit alphanumeric ISO country code","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"regionId","type":"`string`","description":"the id of the current region to check against","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="validateCountry"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Country](../../entities/classes/entities.Country.mdx)&#62;","optional":false,"defaultValue":"","description":"the validated Country","expandable":false,"children":[]}]}  sectionTitle="validateCountry"/>

### retrieveByCountryCode

Retrieve a region by country code.

#### Parameters

<TypeList types={[{"name":"code","type":"`string`","description":"a 2 digit alphanumeric ISO country code","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"config","type":"[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","description":"region find config","optional":false,"defaultValue":"{}","expandable":false,"children":[]}]}  sectionTitle="retrieveByCountryCode"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","optional":false,"defaultValue":"","description":"a Region with country code","expandable":false,"children":[]}]}  sectionTitle="retrieveByCountryCode"/>

### retrieveByName

Retrieves a region by name.

#### Parameters

<TypeList types={[{"name":"name","type":"`string`","description":"the name of the region to retrieve","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="retrieveByName"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","optional":false,"defaultValue":"","description":"region with the matching name","expandable":false,"children":[]}]}  sectionTitle="retrieveByName"/>

### retrieve

Retrieves a region by its id.

#### Parameters

<TypeList types={[{"name":"regionId","type":"`string`","description":"the id of the region to retrieve","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"config","type":"[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","description":"configuration settings","optional":false,"defaultValue":"{}","expandable":false,"children":[]}]}  sectionTitle="retrieve"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","optional":false,"defaultValue":"","description":"the region","expandable":false,"children":[]}]}  sectionTitle="retrieve"/>

### list

Lists all regions based on a query

#### Parameters

<TypeList types={[{"name":"selector","type":"[Selector](../../medusa/types/medusa.Selector.mdx)&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","description":"query object for find","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"config","type":"[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","description":"configuration settings","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="list"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)[]&#62;","optional":false,"defaultValue":"","description":"result of the find operation","expandable":false,"children":[]}]}  sectionTitle="list"/>

### listAndCount

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

#### Parameters

<TypeList types={[{"name":"selector","type":"[Selector](../../medusa/types/medusa.Selector.mdx)&#60;[Region](../../entities/classes/entities.Region.mdx)&#62; & `object`","description":"query object for find","optional":false,"defaultValue":"{}","expandable":false,"children":[]},{"name":"config","type":"[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","description":"configuration settings","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="listAndCount"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[[Region](../../entities/classes/entities.Region.mdx)[], number]&#62;","optional":false,"defaultValue":"","description":"result of the find operation","expandable":false,"children":[]}]}  sectionTitle="listAndCount"/>

### delete

Deletes a region.

#### Parameters

<TypeList types={[{"name":"regionId","type":"`string`","description":"the region to delete","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="delete"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;void&#62;","optional":false,"defaultValue":"","description":"the result of the delete operation","expandable":false,"children":[]}]}  sectionTitle="delete"/>

### addCountry

Adds a country to the region.

#### Parameters

<TypeList types={[{"name":"regionId","type":"`string`","description":"the region to add a country to","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"code","type":"`string`","description":"a 2 digit alphanumeric ISO country code.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="addCountry"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","optional":false,"defaultValue":"","description":"the updated Region","expandable":false,"children":[]}]}  sectionTitle="addCountry"/>

### removeCountry

Removes a country from a Region.

#### Parameters

<TypeList types={[{"name":"regionId","type":"`string`","description":"the region to remove from","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"code","type":"`string`","description":"a 2 digit alphanumeric ISO country code to remove","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="removeCountry"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","optional":false,"defaultValue":"","description":"the updated Region","expandable":false,"children":[]}]}  sectionTitle="removeCountry"/>

### addPaymentProvider

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

#### Parameters

<TypeList types={[{"name":"regionId","type":"`string`","description":"the region to add the provider to","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"providerId","type":"`string`","description":"the provider to add to the region","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="addPaymentProvider"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","optional":false,"defaultValue":"","description":"the updated Region","expandable":false,"children":[]}]}  sectionTitle="addPaymentProvider"/>

### addFulfillmentProvider

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

#### Parameters

<TypeList types={[{"name":"regionId","type":"`string`","description":"the region to add the provider to","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"providerId","type":"`string`","description":"the provider to add to the region","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="addFulfillmentProvider"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","optional":false,"defaultValue":"","description":"the updated Region","expandable":false,"children":[]}]}  sectionTitle="addFulfillmentProvider"/>

### removePaymentProvider

Removes a payment provider from a region. Is idempotent.

#### Parameters

<TypeList types={[{"name":"regionId","type":"`string`","description":"the region to remove the provider from","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"providerId","type":"`string`","description":"the provider to remove from the region","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="removePaymentProvider"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","optional":false,"defaultValue":"","description":"the updated Region","expandable":false,"children":[]}]}  sectionTitle="removePaymentProvider"/>

### removeFulfillmentProvider

Removes a fulfillment provider from a region. Is idempotent.

#### Parameters

<TypeList types={[{"name":"regionId","type":"`string`","description":"the region to remove the provider from","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"providerId","type":"`string`","description":"the provider to remove from the region","optional":false,"defaultValue":"","expandable":false,"children":[]}]}  sectionTitle="removeFulfillmentProvider"/>

#### Returns

<TypeList types={[{"name":"Promise","type":"Promise&#60;[Region](../../entities/classes/entities.Region.mdx)&#62;","optional":false,"defaultValue":"","description":"the updated Region","expandable":false,"children":[]}]}  sectionTitle="removeFulfillmentProvider"/>
