From 823b98aaa1811139de22fef5c5956c4299db2c80 Mon Sep 17 00:00:00 2001 From: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Mon, 5 Feb 2024 17:03:26 +0100 Subject: [PATCH] feat: Region Module (basic CRUD) (#6315) --- .../src/handlers/region/find-region.ts | 5 +- packages/modules-sdk/src/definitions.ts | 16 + packages/region/.gitignore | 6 + packages/region/README.md | 1 + .../__tests__/region-module.spec.ts | 101 ++ .../region/integration-tests/setup-env.js | 6 + packages/region/integration-tests/setup.js | 3 + .../region/integration-tests/utils/config.ts | 6 + .../integration-tests/utils/database.ts | 18 + .../utils/get-init-module-config.ts | 33 + .../region/integration-tests/utils/index.ts | 3 + packages/region/jest.config.js | 22 + packages/region/mikro-orm.config.dev.ts | 8 + packages/region/package.json | 61 + packages/region/src/index.ts | 28 + packages/region/src/initialize/index.ts | 34 + packages/region/src/joiner-config.ts | 41 + packages/region/src/loaders/connection.ts | 35 + packages/region/src/loaders/container.ts | 10 + packages/region/src/loaders/defaults.ts | 7 + packages/region/src/loaders/index.ts | 4 + packages/region/src/models/country.ts | 54 + packages/region/src/models/currency.ts | 36 + packages/region/src/models/index.ts | 4 + packages/region/src/models/region.ts | 82 ++ packages/region/src/module-definition.ts | 14 + packages/region/src/repositories/index.ts | 1 + packages/region/src/scripts/bin/run-seed.ts | 31 + packages/region/src/scripts/seed-utils.ts | 16 + .../src/services/__tests__/index.spec.ts | 6 + packages/region/src/services/index.ts | 2 + packages/region/src/services/region-module.ts | 230 ++++ packages/region/src/types/index.ts | 25 + packages/region/tsconfig.json | 37 + packages/region/tsconfig.spec.json | 8 + packages/types/src/bundles.ts | 3 +- packages/types/src/index.ts | 2 + packages/types/src/region/common.ts | 65 +- packages/types/src/region/index.ts | 2 + packages/types/src/region/mutations.ts | 27 + packages/types/src/region/service.ts | 92 ++ packages/types/src/region__legacy/common.ts | 11 + packages/types/src/region__legacy/index.ts | 1 + packages/utils/src/bundles.ts | 4 +- packages/utils/src/defaults/countries.ts | 404 ++++++ packages/utils/src/defaults/currencies.ts | 1092 +++++++++++++++++ packages/utils/src/defaults/index.ts | 2 + packages/utils/src/index.ts | 1 + yarn.lock | 29 +- 49 files changed, 2716 insertions(+), 13 deletions(-) create mode 100644 packages/region/.gitignore create mode 100644 packages/region/README.md create mode 100644 packages/region/integration-tests/__tests__/region-module.spec.ts create mode 100644 packages/region/integration-tests/setup-env.js create mode 100644 packages/region/integration-tests/setup.js create mode 100644 packages/region/integration-tests/utils/config.ts create mode 100644 packages/region/integration-tests/utils/database.ts create mode 100644 packages/region/integration-tests/utils/get-init-module-config.ts create mode 100644 packages/region/integration-tests/utils/index.ts create mode 100644 packages/region/jest.config.js create mode 100644 packages/region/mikro-orm.config.dev.ts create mode 100644 packages/region/package.json create mode 100644 packages/region/src/index.ts create mode 100644 packages/region/src/initialize/index.ts create mode 100644 packages/region/src/joiner-config.ts create mode 100644 packages/region/src/loaders/connection.ts create mode 100644 packages/region/src/loaders/container.ts create mode 100644 packages/region/src/loaders/defaults.ts create mode 100644 packages/region/src/loaders/index.ts create mode 100644 packages/region/src/models/country.ts create mode 100644 packages/region/src/models/currency.ts create mode 100644 packages/region/src/models/index.ts create mode 100644 packages/region/src/models/region.ts create mode 100644 packages/region/src/module-definition.ts create mode 100644 packages/region/src/repositories/index.ts create mode 100644 packages/region/src/scripts/bin/run-seed.ts create mode 100644 packages/region/src/scripts/seed-utils.ts create mode 100644 packages/region/src/services/__tests__/index.spec.ts create mode 100644 packages/region/src/services/index.ts create mode 100644 packages/region/src/services/region-module.ts create mode 100644 packages/region/src/types/index.ts create mode 100644 packages/region/tsconfig.json create mode 100644 packages/region/tsconfig.spec.json create mode 100644 packages/types/src/region/mutations.ts create mode 100644 packages/types/src/region/service.ts create mode 100644 packages/types/src/region__legacy/common.ts create mode 100644 packages/types/src/region__legacy/index.ts create mode 100644 packages/utils/src/defaults/countries.ts create mode 100644 packages/utils/src/defaults/currencies.ts create mode 100644 packages/utils/src/defaults/index.ts diff --git a/packages/core-flows/src/handlers/region/find-region.ts b/packages/core-flows/src/handlers/region/find-region.ts index 71916e8de24ef..446152b39d556 100644 --- a/packages/core-flows/src/handlers/region/find-region.ts +++ b/packages/core-flows/src/handlers/region/find-region.ts @@ -1,12 +1,13 @@ -import { MedusaError } from "@medusajs/utils" import { RegionTypes } from "@medusajs/types" +import { MedusaError } from "@medusajs/utils" import { isDefined } from "medusa-core-utils" import { WorkflowArguments } from "@medusajs/workflows-sdk" type RegionResultDTO = { region_id?: string - region?: RegionTypes.RegionDTO + // TODO: Replace with RegionDTO from Region Module + region?: RegionTypes.RegionDTO__legacy } type HandlerInputData = { diff --git a/packages/modules-sdk/src/definitions.ts b/packages/modules-sdk/src/definitions.ts index 2bd73a32bdf91..c18cc548e13da 100644 --- a/packages/modules-sdk/src/definitions.ts +++ b/packages/modules-sdk/src/definitions.ts @@ -21,6 +21,7 @@ export enum Modules { CART = "cart", CUSTOMER = "customer", PAYMENT = "payment", + REGION = "region", } export enum ModuleRegistrationName { @@ -37,6 +38,7 @@ export enum ModuleRegistrationName { CART = "cartModuleService", CUSTOMER = "customerModuleService", PAYMENT = "paymentModuleService", + REGION = "regionModuleService", } export const MODULE_PACKAGE_NAMES = { @@ -54,6 +56,7 @@ export const MODULE_PACKAGE_NAMES = { [Modules.CART]: "@medusajs/cart", [Modules.CUSTOMER]: "@medusajs/customer", [Modules.PAYMENT]: "@medusajs/payment", + [Modules.REGION]: "@medusajs/region", } export const ModulesDefinition: { [key: string | Modules]: ModuleDefinition } = @@ -228,6 +231,19 @@ export const ModulesDefinition: { [key: string | Modules]: ModuleDefinition } = resources: MODULE_RESOURCE_TYPE.SHARED, }, }, + [Modules.REGION]: { + key: Modules.REGION, + registrationName: ModuleRegistrationName.REGION, + defaultPackage: false, + label: upperCaseFirst(ModuleRegistrationName.REGION), + isRequired: false, + isQueryable: true, + dependencies: ["logger"], + defaultModuleDeclaration: { + scope: MODULE_SCOPE.INTERNAL, + resources: MODULE_RESOURCE_TYPE.SHARED, + }, + }, } export const MODULE_DEFINITIONS: ModuleDefinition[] = diff --git a/packages/region/.gitignore b/packages/region/.gitignore new file mode 100644 index 0000000000000..874c6c69d3341 --- /dev/null +++ b/packages/region/.gitignore @@ -0,0 +1,6 @@ +/dist +node_modules +.DS_store +.env* +.env +*.sql diff --git a/packages/region/README.md b/packages/region/README.md new file mode 100644 index 0000000000000..77b575ff8e3c6 --- /dev/null +++ b/packages/region/README.md @@ -0,0 +1 @@ +# Region Module diff --git a/packages/region/integration-tests/__tests__/region-module.spec.ts b/packages/region/integration-tests/__tests__/region-module.spec.ts new file mode 100644 index 0000000000000..1c0435816dc96 --- /dev/null +++ b/packages/region/integration-tests/__tests__/region-module.spec.ts @@ -0,0 +1,101 @@ +import { Modules } from "@medusajs/modules-sdk" +import { IRegionModuleService } from "@medusajs/types" +import { DefaultsUtils } from "@medusajs/utils" +import { initModules } from "medusa-test-utils" +import { MikroOrmWrapper } from "../utils" +import { getInitModuleConfig } from "../utils/get-init-module-config" + +jest.setTimeout(30000) + +describe("Region Module Service", () => { + let service: IRegionModuleService + let shutdownFunc: () => Promise + + beforeEach(async () => { + await MikroOrmWrapper.setupDatabase() + + const initModulesConfig = getInitModuleConfig() + const { medusaApp, shutdown } = await initModules(initModulesConfig) + service = medusaApp.modules[Modules.REGION] + + shutdownFunc = shutdown + }) + + afterEach(async () => { + await MikroOrmWrapper.clearDatabase() + await shutdownFunc() + }) + + it("should create countries and currencies on application start", async () => { + const countries = await service.listCountries() + const currencies = await service.listCurrencies() + + expect(countries.length).toBeGreaterThan(0) + expect(currencies.length).toBeGreaterThan(0) + }) + + it("should create countries added to default ones", async () => { + const [, count] = await service.listAndCountCountries() + const initialCountries = DefaultsUtils.defaultCountries.length + + expect(count).toEqual(initialCountries) + + DefaultsUtils.defaultCountries.push({ + name: "Dogecoin", + alpha2: "DOGE", + alpha3: "DOGE", + numeric: "420", + }) + + await service.createDefaultCountriesAndCurrencies() + + const [, newCount] = await service.listAndCountCountries() + expect(newCount).toEqual(initialCountries + 1) + }) + + it("should create and list a region", async () => { + const createdRegion = await service.create({ + name: "Europe", + currency_code: "EUR", + }) + + expect(createdRegion).toEqual( + expect.objectContaining({ + id: createdRegion.id, + name: "Europe", + currency_code: "EUR", + currency: expect.objectContaining({ + code: "eur", + name: "Euro", + }), + countries: [], + }) + ) + + const region = await service.retrieve(createdRegion.id, { + relations: ["currency", "countries"], + }) + + expect(region).toEqual( + expect.objectContaining({ + id: region.id, + name: "Europe", + currency_code: "EUR", + currency: expect.objectContaining({ + code: "eur", + name: "Euro", + }), + countries: [], + }) + ) + }) + + it("should fail when currency does not exist", async () => { + await expect( + service.create({ + name: "Europe", + currency_code: "DOGECOIN", + }) + ).rejects.toThrowError("Currency with code: DOGECOIN was not found") + }) +}) diff --git a/packages/region/integration-tests/setup-env.js b/packages/region/integration-tests/setup-env.js new file mode 100644 index 0000000000000..10e738a7995a3 --- /dev/null +++ b/packages/region/integration-tests/setup-env.js @@ -0,0 +1,6 @@ +if (typeof process.env.DB_TEMP_NAME === "undefined") { + const tempName = parseInt(process.env.JEST_WORKER_ID || "1") + process.env.DB_TEMP_NAME = `medusa-region-integration-${tempName}` +} + +process.env.MEDUSA_REGION_DB_SCHEMA = "public" diff --git a/packages/region/integration-tests/setup.js b/packages/region/integration-tests/setup.js new file mode 100644 index 0000000000000..43f99aab4ac94 --- /dev/null +++ b/packages/region/integration-tests/setup.js @@ -0,0 +1,3 @@ +import { JestUtils } from "medusa-test-utils" + +JestUtils.afterAllHookDropDatabase() diff --git a/packages/region/integration-tests/utils/config.ts b/packages/region/integration-tests/utils/config.ts new file mode 100644 index 0000000000000..7c5cb65747df9 --- /dev/null +++ b/packages/region/integration-tests/utils/config.ts @@ -0,0 +1,6 @@ +import { ModuleServiceInitializeOptions } from "@medusajs/types" + +export const databaseOptions: ModuleServiceInitializeOptions["database"] = { + schema: "public", + clientUrl: "medusa-region-test", +} diff --git a/packages/region/integration-tests/utils/database.ts b/packages/region/integration-tests/utils/database.ts new file mode 100644 index 0000000000000..f412f49944a8a --- /dev/null +++ b/packages/region/integration-tests/utils/database.ts @@ -0,0 +1,18 @@ +import { TestDatabaseUtils } from "medusa-test-utils" + +import * as RegionModels from "@models" + +const pathToMigrations = "../../src/migrations" +const mikroOrmEntities = RegionModels as unknown as any[] + +export const MikroOrmWrapper = TestDatabaseUtils.getMikroOrmWrapper( + mikroOrmEntities, + pathToMigrations +) + +export const MikroOrmConfig = TestDatabaseUtils.getMikroOrmConfig( + mikroOrmEntities, + pathToMigrations +) + +export const DB_URL = TestDatabaseUtils.getDatabaseURL() diff --git a/packages/region/integration-tests/utils/get-init-module-config.ts b/packages/region/integration-tests/utils/get-init-module-config.ts new file mode 100644 index 0000000000000..1c891ce6f4bc4 --- /dev/null +++ b/packages/region/integration-tests/utils/get-init-module-config.ts @@ -0,0 +1,33 @@ +import { Modules, ModulesDefinition } from "@medusajs/modules-sdk" + +import { DB_URL } from "./database" + +export function getInitModuleConfig() { + const moduleOptions = { + defaultAdapterOptions: { + database: { + clientUrl: DB_URL, + schema: process.env.MEDUSA_REGION_DB_SCHEMA, + }, + }, + } + + const injectedDependencies = {} + + const modulesConfig_ = { + [Modules.REGION]: { + definition: ModulesDefinition[Modules.REGION], + options: moduleOptions, + }, + } + + return { + injectedDependencies, + modulesConfig: modulesConfig_, + databaseConfig: { + clientUrl: DB_URL, + schema: process.env.MEDUSA_REGION_DB_SCHEMA, + }, + joinerConfig: [], + } +} diff --git a/packages/region/integration-tests/utils/index.ts b/packages/region/integration-tests/utils/index.ts new file mode 100644 index 0000000000000..e930063cf1e28 --- /dev/null +++ b/packages/region/integration-tests/utils/index.ts @@ -0,0 +1,3 @@ +export * from "./config" +export * from "./database" + diff --git a/packages/region/jest.config.js b/packages/region/jest.config.js new file mode 100644 index 0000000000000..456054fe8ae27 --- /dev/null +++ b/packages/region/jest.config.js @@ -0,0 +1,22 @@ +module.exports = { + moduleNameMapper: { + "^@models": "/src/models", + "^@services": "/src/services", + "^@repositories": "/src/repositories", + "^@types": "/src/types", + }, + transform: { + "^.+\\.[jt]s?$": [ + "ts-jest", + { + tsConfig: "tsconfig.spec.json", + isolatedModules: true, + }, + ], + }, + testEnvironment: `node`, + moduleFileExtensions: [`js`, `ts`], + modulePathIgnorePatterns: ["dist/"], + setupFiles: ["/integration-tests/setup-env.js"], + setupFilesAfterEnv: ["/integration-tests/setup.js"], +} diff --git a/packages/region/mikro-orm.config.dev.ts b/packages/region/mikro-orm.config.dev.ts new file mode 100644 index 0000000000000..e6385291c7888 --- /dev/null +++ b/packages/region/mikro-orm.config.dev.ts @@ -0,0 +1,8 @@ +import * as entities from "./src/models" + +module.exports = { + entities: Object.values(entities), + schema: "public", + clientUrl: "postgres://postgres@localhost/medusa-region", + type: "postgresql", +} diff --git a/packages/region/package.json b/packages/region/package.json new file mode 100644 index 0000000000000..9f2ba72caa839 --- /dev/null +++ b/packages/region/package.json @@ -0,0 +1,61 @@ +{ + "name": "@medusajs/region", + "version": "0.1.0", + "description": "Medusa Region module", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "files": [ + "dist" + ], + "engines": { + "node": ">=16" + }, + "bin": { + "medusa-region-seed": "dist/scripts/bin/run-seed.js" + }, + "repository": { + "type": "git", + "url": "https://github.com/medusajs/medusa", + "directory": "packages/region" + }, + "publishConfig": { + "access": "public" + }, + "author": "Medusa", + "license": "MIT", + "scripts": { + "watch": "tsc --build --watch", + "watch:test": "tsc --build tsconfig.spec.json --watch", + "prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json", + "build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json", + "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts", + "test:integration": "jest --runInBand --forceExit -- integration-tests/**/__tests__/**/*.ts", + "migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:generate", + "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create --initial", + "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create", + "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:up", + "orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear" + }, + "devDependencies": { + "@mikro-orm/cli": "5.9.7", + "cross-env": "^5.2.1", + "jest": "^29.6.3", + "medusa-test-utils": "workspace:^", + "rimraf": "^3.0.2", + "ts-jest": "^29.1.1", + "ts-node": "^10.9.1", + "tsc-alias": "^1.8.6", + "typescript": "^5.1.6" + }, + "dependencies": { + "@medusajs/modules-sdk": "^1.12.4", + "@medusajs/types": "^1.11.8", + "@medusajs/utils": "^1.11.1", + "@mikro-orm/core": "5.9.7", + "@mikro-orm/migrations": "5.9.7", + "@mikro-orm/postgresql": "5.9.7", + "awilix": "^8.0.0", + "dotenv": "^16.1.4", + "knex": "2.4.2" + } +} diff --git a/packages/region/src/index.ts b/packages/region/src/index.ts new file mode 100644 index 0000000000000..f679a83abf4b6 --- /dev/null +++ b/packages/region/src/index.ts @@ -0,0 +1,28 @@ +import { Modules } from "@medusajs/modules-sdk" +import { ModulesSdkUtils } from "@medusajs/utils" + +import * as RegionModels from "@models" + +import { moduleDefinition } from "./module-definition" + +export default moduleDefinition + +const migrationScriptOptions = { + moduleName: Modules.REGION, + models: RegionModels, + pathToMigrations: __dirname + "/migrations", +} + +export const runMigrations = ModulesSdkUtils.buildMigrationScript( + migrationScriptOptions +) +export const revertMigration = ModulesSdkUtils.buildRevertMigrationScript( + migrationScriptOptions +) + +export * from "./initialize" +export * from "./loaders" +export * from "./models" +export * from "./services" +export * from "./types" + diff --git a/packages/region/src/initialize/index.ts b/packages/region/src/initialize/index.ts new file mode 100644 index 0000000000000..9cad528c589f3 --- /dev/null +++ b/packages/region/src/initialize/index.ts @@ -0,0 +1,34 @@ +import { + ExternalModuleDeclaration, + InternalModuleDeclaration, + MedusaModule, + MODULE_PACKAGE_NAMES, + Modules, +} from "@medusajs/modules-sdk" +import { IRegionModuleService, ModulesSdkTypes } from "@medusajs/types" +import { InitializeModuleInjectableDependencies } from "@types" + +import { moduleDefinition } from "../module-definition" + +export const initialize = async ( + options?: + | ModulesSdkTypes.ModuleServiceInitializeOptions + | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions + | ExternalModuleDeclaration + | InternalModuleDeclaration, + injectedDependencies?: InitializeModuleInjectableDependencies +): Promise => { + const serviceKey = Modules.REGION + + const loaded = await MedusaModule.bootstrap({ + moduleKey: serviceKey, + defaultPath: MODULE_PACKAGE_NAMES[Modules.REGION], + declaration: options as + | InternalModuleDeclaration + | ExternalModuleDeclaration, + injectedDependencies, + moduleExports: moduleDefinition, + }) + + return loaded[serviceKey] +} diff --git a/packages/region/src/joiner-config.ts b/packages/region/src/joiner-config.ts new file mode 100644 index 0000000000000..ae36880bd0b1e --- /dev/null +++ b/packages/region/src/joiner-config.ts @@ -0,0 +1,41 @@ +import { Modules } from "@medusajs/modules-sdk" +import { ModuleJoinerConfig } from "@medusajs/types" +import { MapToConfig } from "@medusajs/utils" +import { Country, Currency, Region } from "@models" + +export const LinkableKeys = { + region_id: Region.name, + currency_code: Country.name, + country_id: Region.name, +} + +const entityLinkableKeysMap: MapToConfig = {} +Object.entries(LinkableKeys).forEach(([key, value]) => { + entityLinkableKeysMap[value] ??= [] + entityLinkableKeysMap[value].push({ + mapTo: key, + valueFrom: key.split("_").pop()!, + }) +}) + +export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap + +export const joinerConfig: ModuleJoinerConfig = { + serviceName: Modules.REGION, + primaryKeys: ["id"], + linkableKeys: LinkableKeys, + alias: [ + { + name: ["region", "regions"], + args: { entity: Region.name }, + }, + { + name: ["currency", "currencies"], + args: { entity: Currency.name }, + }, + { + name: ["country", "countries"], + args: { entity: Country.name }, + }, + ], +} as ModuleJoinerConfig diff --git a/packages/region/src/loaders/connection.ts b/packages/region/src/loaders/connection.ts new file mode 100644 index 0000000000000..5fc66f57e87c9 --- /dev/null +++ b/packages/region/src/loaders/connection.ts @@ -0,0 +1,35 @@ +import { + InternalModuleDeclaration, + LoaderOptions, + Modules, +} from "@medusajs/modules-sdk" +import { ModulesSdkTypes } from "@medusajs/types" +import { ModulesSdkUtils } from "@medusajs/utils" +import { EntitySchema } from "@mikro-orm/core" + +import * as RegionModels from "@models" + +export default async ( + { + options, + container, + logger, + }: LoaderOptions< + | ModulesSdkTypes.ModuleServiceInitializeOptions + | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions + >, + moduleDeclaration?: InternalModuleDeclaration +): Promise => { + const entities = Object.values(RegionModels) as unknown as EntitySchema[] + const pathToMigrations = __dirname + "/../migrations" + + await ModulesSdkUtils.mikroOrmConnectionLoader({ + moduleName: Modules.REGION, + entities, + container, + options, + moduleDeclaration, + logger, + pathToMigrations, + }) +} diff --git a/packages/region/src/loaders/container.ts b/packages/region/src/loaders/container.ts new file mode 100644 index 0000000000000..28ea110f2dbd1 --- /dev/null +++ b/packages/region/src/loaders/container.ts @@ -0,0 +1,10 @@ +import { ModulesSdkUtils } from "@medusajs/utils" +import * as ModuleModels from "@models" +import * as ModuleRepositories from "@repositories" +import * as ModuleServices from "@services" + +export default ModulesSdkUtils.moduleContainerLoaderFactory({ + moduleModels: ModuleModels, + moduleRepositories: ModuleRepositories, + moduleServices: ModuleServices, +}) diff --git a/packages/region/src/loaders/defaults.ts b/packages/region/src/loaders/defaults.ts new file mode 100644 index 0000000000000..4f842f984fd39 --- /dev/null +++ b/packages/region/src/loaders/defaults.ts @@ -0,0 +1,7 @@ +import { ModuleRegistrationName } from "@medusajs/modules-sdk" +import { IRegionModuleService, LoaderOptions } from "@medusajs/types" + +export default async ({ container }: LoaderOptions): Promise => { + const service: IRegionModuleService = container.resolve(ModuleRegistrationName.REGION) + await service.createDefaultCountriesAndCurrencies() +} diff --git a/packages/region/src/loaders/index.ts b/packages/region/src/loaders/index.ts new file mode 100644 index 0000000000000..1f4af39e22a72 --- /dev/null +++ b/packages/region/src/loaders/index.ts @@ -0,0 +1,4 @@ +export * from "./connection" +export * from "./container" +export * from "./defaults" + diff --git a/packages/region/src/models/country.ts b/packages/region/src/models/country.ts new file mode 100644 index 0000000000000..1c7126eb47ca1 --- /dev/null +++ b/packages/region/src/models/country.ts @@ -0,0 +1,54 @@ +import { + BeforeCreate, + Cascade, + Entity, + ManyToOne, + OnInit, + PrimaryKey, + Property, +} from "@mikro-orm/core" + +import { generateEntityId } from "@medusajs/utils" +import Region from "./region" + +@Entity({ tableName: "region_country" }) +export default class Country { + @PrimaryKey({ columnType: "text" }) + id: string + + @Property({ columnType: "text" }) + iso_2: string + + @Property({ columnType: "text" }) + iso_3: string + + @Property({ columnType: "int" }) + num_code: number + + @Property({ columnType: "text" }) + name: string + + @Property({ columnType: "text" }) + display_name: string + + @Property({ columnType: "text", nullable: true }) + region_id: string | null = null + + @ManyToOne({ + entity: () => Region, + onDelete: "cascade", + index: "IDX_country_region_id", + cascade: [Cascade.REMOVE, Cascade.PERSIST], + }) + region: Region + + @BeforeCreate() + onCreate() { + this.id = generateEntityId(this.id, "reg_ctry") + } + + @OnInit() + onInit() { + this.id = generateEntityId(this.id, "reg_ctry") + } +} diff --git a/packages/region/src/models/currency.ts b/packages/region/src/models/currency.ts new file mode 100644 index 0000000000000..11700ab19817d --- /dev/null +++ b/packages/region/src/models/currency.ts @@ -0,0 +1,36 @@ +import { generateEntityId } from "@medusajs/utils" +import { + BeforeCreate, + Entity, + OnInit, + PrimaryKey, + Property, +} from "@mikro-orm/core" + +@Entity({ tableName: "region_currency" }) +export default class Currency { + @PrimaryKey({ columnType: "text" }) + id: string + + @Property({ columnType: "text" }) + code: string + + @Property({ columnType: "text" }) + symbol: string + + @Property({ columnType: "text" }) + symbol_native: string + + @Property({ columnType: "text" }) + name: string + + @BeforeCreate() + onCreate() { + this.id = generateEntityId(this.id, "reg_curr") + } + + @OnInit() + onInit() { + this.id = generateEntityId(this.id, "reg_curr") + } +} diff --git a/packages/region/src/models/index.ts b/packages/region/src/models/index.ts new file mode 100644 index 0000000000000..94a677257397d --- /dev/null +++ b/packages/region/src/models/index.ts @@ -0,0 +1,4 @@ +export { default as Country } from "./country" +export { default as Currency } from "./currency" +export { default as Region } from "./region" + diff --git a/packages/region/src/models/region.ts b/packages/region/src/models/region.ts new file mode 100644 index 0000000000000..79248fbad33e8 --- /dev/null +++ b/packages/region/src/models/region.ts @@ -0,0 +1,82 @@ +import { DAL } from "@medusajs/types" +import { DALUtils, generateEntityId } from "@medusajs/utils" +import { + BeforeCreate, + Cascade, + Collection, + Entity, + Filter, + Index, + ManyToOne, + OneToMany, + OptionalProps, + PrimaryKey, + Property, +} from "@mikro-orm/core" +import Country from "./country" +import Currency from "./currency" + +type RegionOptionalProps = + | "currency" + | "countries" + | DAL.SoftDeletableEntityDateColumns + +@Entity({ tableName: "region" }) +@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions) +export default class Region { + [OptionalProps]?: RegionOptionalProps + + @PrimaryKey({ columnType: "text" }) + id: string + + @Property({ columnType: "text" }) + name: string + + @Property({ columnType: "text" }) + currency_code: string + + @ManyToOne({ + entity: () => Currency, + onDelete: "cascade", + index: "IDX_region_currency_code", + cascade: [Cascade.PERSIST], + }) + currency: Currency + + @OneToMany(() => Country, (country) => country.region, { + cascade: [Cascade.REMOVE], + }) + countries = new Collection(this) + + @Property({ columnType: "jsonb", nullable: true }) + metadata: Record | null = null + + @Property({ + onCreate: () => new Date(), + columnType: "timestamptz", + defaultRaw: "now()", + }) + created_at: Date + + @Property({ + onCreate: () => new Date(), + onUpdate: () => new Date(), + columnType: "timestamptz", + defaultRaw: "now()", + }) + updated_at: Date + + @Index({ name: "IDX_region_deleted_at" }) + @Property({ columnType: "timestamptz", nullable: true }) + deleted_at: Date | null = null + + @BeforeCreate() + onCreate() { + this.id = generateEntityId(this.id, "reg") + } + + @BeforeCreate() + onInit() { + this.id = generateEntityId(this.id, "reg") + } +} diff --git a/packages/region/src/module-definition.ts b/packages/region/src/module-definition.ts new file mode 100644 index 0000000000000..24d9c5b777ab2 --- /dev/null +++ b/packages/region/src/module-definition.ts @@ -0,0 +1,14 @@ +import { ModuleExports } from "@medusajs/types" +import { RegionModuleService } from "@services" + +import loadConnection from "./loaders/connection" +import loadContainer from "./loaders/container" +import loadDefaults from "./loaders/defaults" + +const service = RegionModuleService +const loaders = [loadContainer, loadConnection, loadDefaults] as any + +export const moduleDefinition: ModuleExports = { + service, + loaders, +} diff --git a/packages/region/src/repositories/index.ts b/packages/region/src/repositories/index.ts new file mode 100644 index 0000000000000..147c9cc259fa4 --- /dev/null +++ b/packages/region/src/repositories/index.ts @@ -0,0 +1 @@ +export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils" diff --git a/packages/region/src/scripts/bin/run-seed.ts b/packages/region/src/scripts/bin/run-seed.ts new file mode 100644 index 0000000000000..1fd7d8d1782bb --- /dev/null +++ b/packages/region/src/scripts/bin/run-seed.ts @@ -0,0 +1,31 @@ +#!/usr/bin/env node + +import { Modules } from "@medusajs/modules-sdk" +import { ModulesSdkUtils } from "@medusajs/utils" +import * as RegionModels from "@models" +import { EOL } from "os" +import { createRegions } from "../seed-utils" + +const args = process.argv +const path = args.pop() as string + +export default (async () => { + const { config } = await import("dotenv") + config() + if (!path) { + throw new Error( + `filePath is required.${EOL}Example: medusa-region-seed ` + ) + } + + const run = ModulesSdkUtils.buildSeedScript({ + moduleName: Modules.REGION, + models: RegionModels, + pathToMigrations: __dirname + "/../../migrations", + seedHandler: async ({ manager, data }) => { + const { regionData } = data + await createRegions(manager, regionData) + }, + }) + await run({ path }) +})() diff --git a/packages/region/src/scripts/seed-utils.ts b/packages/region/src/scripts/seed-utils.ts new file mode 100644 index 0000000000000..0c41dd5cce81d --- /dev/null +++ b/packages/region/src/scripts/seed-utils.ts @@ -0,0 +1,16 @@ +import { RequiredEntityData } from "@mikro-orm/core" +import { SqlEntityManager } from "@mikro-orm/postgresql" +import { Region } from "@models" + +export async function createRegions( + manager: SqlEntityManager, + data: RequiredEntityData[] +) { + const regions = data.map((region) => { + return manager.create(Region, region) + }) + + await manager.persistAndFlush(regions) + + return regions +} diff --git a/packages/region/src/services/__tests__/index.spec.ts b/packages/region/src/services/__tests__/index.spec.ts new file mode 100644 index 0000000000000..1691dbec45d78 --- /dev/null +++ b/packages/region/src/services/__tests__/index.spec.ts @@ -0,0 +1,6 @@ +describe("Noop test", () => { + it("noop check", async () => { + expect(true).toBe(true) + }) + }) + \ No newline at end of file diff --git a/packages/region/src/services/index.ts b/packages/region/src/services/index.ts new file mode 100644 index 0000000000000..8cc30b5477e08 --- /dev/null +++ b/packages/region/src/services/index.ts @@ -0,0 +1,2 @@ +export { default as RegionModuleService } from "./region-module"; + diff --git a/packages/region/src/services/region-module.ts b/packages/region/src/services/region-module.ts new file mode 100644 index 0000000000000..ad10f20b1d7c2 --- /dev/null +++ b/packages/region/src/services/region-module.ts @@ -0,0 +1,230 @@ +import { + Context, + CreateRegionDTO, + DAL, + InternalModuleDeclaration, + IRegionModuleService, + ModuleJoinerConfig, + ModulesSdkTypes, + RegionCountryDTO, + RegionCurrencyDTO, + RegionDTO, + UpdateRegionDTO, +} from "@medusajs/types" +import { + InjectManager, + InjectTransactionManager, + MedusaContext, + MedusaError, + ModulesSdkUtils, + promiseAll, +} from "@medusajs/utils" + +import { Country, Currency, Region } from "@models" + +import { DefaultsUtils } from "@medusajs/utils" +import { CreateCountryDTO, CreateCurrencyDTO } from "@types" +import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" + +const COUNTRIES_LIMIT = 1000 + +type InjectedDependencies = { + baseRepository: DAL.RepositoryService + regionService: ModulesSdkTypes.InternalModuleService + countryService: ModulesSdkTypes.InternalModuleService + currencyService: ModulesSdkTypes.InternalModuleService +} + +const generateMethodForModels = [Country, Currency] + +export default class RegionModuleService< + TRegion extends Region = Region, + TCountry extends Country = Country, + TCurrency extends Currency = Currency + > + extends ModulesSdkUtils.abstractModuleServiceFactory< + InjectedDependencies, + RegionDTO, + { + Country: { + dto: RegionCountryDTO + } + Currency: { + dto: RegionCurrencyDTO + } + } + >(Region, generateMethodForModels, entityNameToLinkableKeysMap) + implements IRegionModuleService +{ + protected baseRepository_: DAL.RepositoryService + protected readonly regionService_: ModulesSdkTypes.InternalModuleService + protected readonly countryService_: ModulesSdkTypes.InternalModuleService + protected readonly currencyService_: ModulesSdkTypes.InternalModuleService + + constructor( + { + baseRepository, + regionService, + countryService, + currencyService, + }: InjectedDependencies, + protected readonly moduleDeclaration: InternalModuleDeclaration + ) { + // @ts-ignore + super(...arguments) + this.baseRepository_ = baseRepository + this.regionService_ = regionService + this.countryService_ = countryService + this.currencyService_ = currencyService + } + + __joinerConfig(): ModuleJoinerConfig { + return joinerConfig + } + + async create( + data: CreateRegionDTO[], + sharedContext?: Context + ): Promise + async create( + data: CreateRegionDTO, + sharedContext?: Context + ): Promise + @InjectManager("baseRepository_") + async create( + data: CreateRegionDTO | CreateRegionDTO[], + @MedusaContext() sharedContext: Context = {} + ): Promise { + const input = Array.isArray(data) ? data : [data] + + const result = await this.create_(input, sharedContext) + + return await this.baseRepository_.serialize( + Array.isArray(data) ? result : result[0], + { + populate: true, + } + ) + } + + @InjectTransactionManager("baseRepository_") + async create_( + data: CreateRegionDTO[], + @MedusaContext() sharedContext: Context = {} + ): Promise { + let currencies = await this.currencyService_.list( + { code: data.map((d) => d.currency_code.toLowerCase()) }, + {}, + sharedContext + ) + + let currencyMap = new Map(currencies.map((c) => [c.code.toLowerCase(), c])) + for (const reg of data) { + const lowerCasedCurrency = reg.currency_code.toLowerCase() + if (!currencyMap.has(lowerCasedCurrency)) { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Currency with code: ${reg.currency_code} was not found` + ) + } + + reg.currency = currencyMap.get(lowerCasedCurrency) as RegionCurrencyDTO + } + + const result = await this.regionService_.create(data, sharedContext) + + return result + } + + async update( + data: UpdateRegionDTO[], + sharedContext?: Context + ): Promise + async update( + data: UpdateRegionDTO, + sharedContext?: Context + ): Promise + @InjectTransactionManager("baseRepository_") + async update( + data: UpdateRegionDTO | UpdateRegionDTO[], + @MedusaContext() sharedContext: Context = {} + ): Promise { + const result = await this.regionService_.update(data, sharedContext) + + return await this.baseRepository_.serialize( + Array.isArray(data) ? result : result[0], + { + populate: true, + } + ) + } + + @InjectManager("baseRepository_") + public async createDefaultCountriesAndCurrencies( + @MedusaContext() sharedContext: Context = {} + ): Promise { + await promiseAll([ + await this.maybeCreateCountries(sharedContext), + await this.maybeCreateCurrencies(sharedContext), + ]) + } + + @InjectTransactionManager("baseRepository_") + private async maybeCreateCountries( + @MedusaContext() sharedContext: Context + ): Promise { + const [countries, count] = await this.countryService_.listAndCount( + {}, + { select: ["id", "iso_2"], take: COUNTRIES_LIMIT }, + sharedContext + ) + + let countsToCreate: CreateCountryDTO[] = [] + if (count !== DefaultsUtils.defaultCountries.length) { + const countriesInDb = new Set(countries.map((c) => c.iso_2)) + + const countriesToAdd = DefaultsUtils.defaultCountries.filter( + (c) => !countriesInDb.has(c.alpha2.toLowerCase()) + ) + + countsToCreate = countriesToAdd.map((c) => ({ + iso_2: c.alpha2.toLowerCase(), + iso_3: c.alpha3.toLowerCase(), + num_code: c.numeric, + name: c.name.toUpperCase(), + display_name: c.name, + })) + } + + if (countsToCreate.length) { + await this.countryService_.create(countsToCreate, sharedContext) + } + } + + @InjectTransactionManager("baseRepository_") + private async maybeCreateCurrencies( + @MedusaContext() sharedContext: Context + ): Promise { + const [currency] = await this.currencyService_.list( + {}, + { select: ["id"], take: 1 }, + sharedContext + ) + + let currsToCreate: CreateCurrencyDTO[] = [] + if (!currency) { + currsToCreate = Object.entries(DefaultsUtils.defaultCurrencies).map( + ([code, currency]) => ({ + code: code.toLowerCase(), + symbol: currency.symbol, + symbol_native: currency.symbol_native, + name: currency.name, + }) + ) + } + + if (currsToCreate.length) { + await this.currencyService_.create(currsToCreate, sharedContext) + } + } +} diff --git a/packages/region/src/types/index.ts b/packages/region/src/types/index.ts new file mode 100644 index 0000000000000..66a2deb8e07b5 --- /dev/null +++ b/packages/region/src/types/index.ts @@ -0,0 +1,25 @@ +import { Logger } from "@medusajs/types" + +export type InitializeModuleInjectableDependencies = { + logger?: Logger +} + +export type UpdateCountryRegion = { + id: string + region_id: string +} + +export type CreateCurrencyDTO = { + code: string + symbol: string + name: string + symbol_native: string +} + +export type CreateCountryDTO = { + iso_2: string + iso_3: string + num_code: string + name: string + display_name: string +} \ No newline at end of file diff --git a/packages/region/tsconfig.json b/packages/region/tsconfig.json new file mode 100644 index 0000000000000..4b79cd603235c --- /dev/null +++ b/packages/region/tsconfig.json @@ -0,0 +1,37 @@ +{ + "compilerOptions": { + "lib": ["es2020"], + "target": "es2020", + "outDir": "./dist", + "esModuleInterop": true, + "declaration": true, + "module": "commonjs", + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "sourceMap": false, + "noImplicitReturns": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "noImplicitThis": true, + "allowJs": true, + "skipLibCheck": true, + "downlevelIteration": true, // to use ES5 specific tooling + "baseUrl": ".", + "resolveJsonModule": true, + "paths": { + "@models": ["./src/models"], + "@services": ["./src/services"], + "@repositories": ["./src/repositories"], + "@types": ["./src/types"] + } + }, + "include": ["src"], + "exclude": [ + "dist", + "./src/**/__tests__", + "./src/**/__mocks__", + "./src/**/__fixtures__", + "node_modules" + ] +} diff --git a/packages/region/tsconfig.spec.json b/packages/region/tsconfig.spec.json new file mode 100644 index 0000000000000..48e47e8cbb3be --- /dev/null +++ b/packages/region/tsconfig.spec.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "include": ["src", "integration-tests"], + "exclude": ["node_modules", "dist"], + "compilerOptions": { + "sourceMap": true + } +} diff --git a/packages/types/src/bundles.ts b/packages/types/src/bundles.ts index 99dd3f5db9f2a..a57b9ef603997 100644 --- a/packages/types/src/bundles.ts +++ b/packages/types/src/bundles.ts @@ -12,9 +12,10 @@ export * as ModulesSdkTypes from "./modules-sdk" export * as PricingTypes from "./pricing" export * as ProductTypes from "./product" export * as PromotionTypes from "./promotion" -export * as RegionTypes from "./region" +export * as RegionTypes from "./region__legacy" export * as SalesChannelTypes from "./sales-channel" export * as SearchTypes from "./search" export * as StockLocationTypes from "./stock-location" export * as TransactionBaseTypes from "./transaction-base" export * as WorkflowTypes from "./workflow" + diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 63caf03a82622..2e347ce73e3b9 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -20,9 +20,11 @@ export * from "./product" export * from "./product-category" export * from "./promotion" export * from "./region" +export * from "./region__legacy" export * from "./sales-channel" export * from "./search" export * from "./shared-context" export * from "./stock-location" export * from "./transaction-base" export * from "./workflow" + diff --git a/packages/types/src/region/common.ts b/packages/types/src/region/common.ts index 2353257c2ea52..dd5cafd17d355 100644 --- a/packages/types/src/region/common.ts +++ b/packages/types/src/region/common.ts @@ -1,11 +1,60 @@ -export type RegionDTO = { +import { BaseFilterable } from "../dal" + +export interface RegionDTO { + id: string name: string currency_code: string - tax_rate?: number - tax_code?: string | null - gift_cards_taxable?: boolean - automatic_taxes?: boolean - tax_provider_id?: string | null - metadata?: Record - includes_tax?: boolean + currency: RegionCurrencyDTO + countries: CountryDTO[] +} + +export interface CountryDTO { + id: string + iso_2: string + iso_3: string + num_code: number + name: string + display_name: string +} + +export interface FilterableRegionProps + extends BaseFilterable { + id?: string[] + name?: string[] +} + +export interface RegionCountryDTO { + id: string + iso_2: string + iso_3: string + num_code: number + name: string + display_name: string +} + +export interface RegionCurrencyDTO { + id: string + code: string + symbol: string + name: string + symbol_native: string +} + +export interface FilterableRegionCurrencyProps + extends BaseFilterable { + id?: string[] | string + code?: string[] | string + symbol?: string[] | string + name?: string[] | string + symbol_native?: string[] | string +} + +export interface FilterableRegionCountryProps + extends BaseFilterable { + id?: string[] | string + iso_2?: string[] | string + iso_3?: string[] | string + num_code?: number[] | string + name?: string[] | string + display_name?: string[] | string } diff --git a/packages/types/src/region/index.ts b/packages/types/src/region/index.ts index 488a94fdffa50..0c73656566caa 100644 --- a/packages/types/src/region/index.ts +++ b/packages/types/src/region/index.ts @@ -1 +1,3 @@ export * from "./common" +export * from "./mutations" +export * from "./service" diff --git a/packages/types/src/region/mutations.ts b/packages/types/src/region/mutations.ts new file mode 100644 index 0000000000000..2ce1ba27b8c53 --- /dev/null +++ b/packages/types/src/region/mutations.ts @@ -0,0 +1,27 @@ +import { RegionCurrencyDTO } from "./common" + +export interface CreateRegionDTO { + name: string + currency_code: string + currency?: RegionCurrencyDTO + tax_code?: string + tax_rate?: number + tax_provider_id?: string +} + +export interface UpdateRegionDTO { + id: string + currency_code?: string + currency?: RegionCurrencyDTO + name?: string + tax_code?: string + tax_rate?: number + tax_provider_id?: string +} + +export interface AddCountryToRegionDTO { + region_id: string + country_id: string +} + +export interface RemoveCountryFromRegionDTO extends AddCountryToRegionDTO {} diff --git a/packages/types/src/region/service.ts b/packages/types/src/region/service.ts new file mode 100644 index 0000000000000..2dcc8655b6472 --- /dev/null +++ b/packages/types/src/region/service.ts @@ -0,0 +1,92 @@ +import { FindConfig } from "../common" +import { RestoreReturn, SoftDeleteReturn } from "../dal" +import { IModuleService } from "../modules-sdk" +import { Context } from "../shared-context" +import { + FilterableRegionCountryProps, + FilterableRegionCurrencyProps, + FilterableRegionProps, + RegionCountryDTO, + RegionCurrencyDTO, + RegionDTO, +} from "./common" +import { CreateRegionDTO, UpdateRegionDTO } from "./mutations" + +export interface IRegionModuleService extends IModuleService { + create(data: CreateRegionDTO[], sharedContext?: Context): Promise + create(data: CreateRegionDTO, sharedContext?: Context): Promise + + update(data: UpdateRegionDTO[], sharedContext?: Context): Promise + update(data: UpdateRegionDTO, sharedContext?: Context): Promise + + delete(ids: string[], sharedContext?: Context): Promise + delete(id: string, sharedContext?: Context): Promise + + retrieve( + id: string, + config?: FindConfig, + sharedContext?: Context + ): Promise + + list( + filters?: FilterableRegionProps, + config?: FindConfig, + sharedContext?: Context + ): Promise + + listAndCount( + filters?: FilterableRegionProps, + config?: FindConfig, + sharedContext?: Context + ): Promise<[RegionDTO[], number]> + + retrieveCountry( + countryId: string, + config?: FindConfig, + sharedContext?: Context + ): Promise + + listCountries( + filters?: FilterableRegionCountryProps, + config?: FindConfig, + sharedContext?: Context + ): Promise + + retrieveCurrency( + currencyId: string, + config?: FindConfig, + sharedContext?: Context + ): Promise + + listAndCountCountries( + filters?: FilterableRegionCountryProps, + config?: FindConfig, + sharedContext?: Context + ): Promise<[RegionCountryDTO[], number]> + + listCurrencies( + filters?: FilterableRegionCurrencyProps, + config?: FindConfig, + sharedContext?: Context + ): Promise + + listAndCountCurrencies( + filters?: FilterableRegionCurrencyProps, + config?: FindConfig, + sharedContext?: Context + ): Promise<[RegionCurrencyDTO[], number]> + + softDelete( + regionIds: string[], + config?: SoftDeleteReturn, + sharedContext?: Context + ): Promise | void> + + restore( + regionIds: string[], + config?: RestoreReturn, + sharedContext?: Context + ): Promise | void> + + createDefaultCountriesAndCurrencies(sharedContext?: Context): Promise +} diff --git a/packages/types/src/region__legacy/common.ts b/packages/types/src/region__legacy/common.ts new file mode 100644 index 0000000000000..9cf553ccada32 --- /dev/null +++ b/packages/types/src/region__legacy/common.ts @@ -0,0 +1,11 @@ +export type RegionDTO__legacy = { + name: string + currency_code: string + tax_rate?: number + tax_code?: string | null + gift_cards_taxable?: boolean + automatic_taxes?: boolean + tax_provider_id?: string | null + metadata?: Record + includes_tax?: boolean +} diff --git a/packages/types/src/region__legacy/index.ts b/packages/types/src/region__legacy/index.ts new file mode 100644 index 0000000000000..488a94fdffa50 --- /dev/null +++ b/packages/types/src/region__legacy/index.ts @@ -0,0 +1 @@ +export * from "./common" diff --git a/packages/utils/src/bundles.ts b/packages/utils/src/bundles.ts index bcbf67c44216d..3f43e1d849767 100644 --- a/packages/utils/src/bundles.ts +++ b/packages/utils/src/bundles.ts @@ -1,10 +1,12 @@ export * as DALUtils from "./dal" export * as DecoratorUtils from "./decorators" +export * as DefaultsUtils from "./defaults" export * as EventBusUtils from "./event-bus" export * as FeatureFlagUtils from "./feature-flags" export * as ModulesSdkUtils from "./modules-sdk" +export * as OrchestrationUtils from "./orchestration" export * as ProductUtils from "./product" export * as PromotionUtils from "./promotion" export * as SearchUtils from "./search" export * as ShippingProfileUtils from "./shipping" -export * as OrchestrationUtils from "./orchestration" + diff --git a/packages/utils/src/defaults/countries.ts b/packages/utils/src/defaults/countries.ts new file mode 100644 index 0000000000000..0234054b2a749 --- /dev/null +++ b/packages/utils/src/defaults/countries.ts @@ -0,0 +1,404 @@ +export type Country = { + alpha2: string + name: string + alpha3: string + numeric: string +} + +export const defaultCountries: Country[] = [ + { alpha2: "AF", name: "Afghanistan", alpha3: "AFG", numeric: "004" }, + { alpha2: "AL", name: "Albania", alpha3: "ALB", numeric: "008" }, + { alpha2: "DZ", name: "Algeria", alpha3: "DZA", numeric: "012" }, + { alpha2: "AS", name: "American Samoa", alpha3: "ASM", numeric: "016" }, + { alpha2: "AD", name: "Andorra", alpha3: "AND", numeric: "020" }, + { alpha2: "AO", name: "Angola", alpha3: "AGO", numeric: "024" }, + { alpha2: "AI", name: "Anguilla", alpha3: "AIA", numeric: "660" }, + { alpha2: "AQ", name: "Antarctica", alpha3: "ATA", numeric: "010" }, + { alpha2: "AG", name: "Antigua and Barbuda", alpha3: "ATG", numeric: "028" }, + { alpha2: "AR", name: "Argentina", alpha3: "ARG", numeric: "032" }, + { alpha2: "AM", name: "Armenia", alpha3: "ARM", numeric: "051" }, + { alpha2: "AW", name: "Aruba", alpha3: "ABW", numeric: "533" }, + { alpha2: "AU", name: "Australia", alpha3: "AUS", numeric: "036" }, + { alpha2: "AT", name: "Austria", alpha3: "AUT", numeric: "040" }, + { alpha2: "AZ", name: "Azerbaijan", alpha3: "AZE", numeric: "031" }, + { alpha2: "BS", name: "Bahamas", alpha3: "BHS", numeric: "044" }, + { alpha2: "BH", name: "Bahrain", alpha3: "BHR", numeric: "048" }, + { alpha2: "BD", name: "Bangladesh", alpha3: "BGD", numeric: "050" }, + { alpha2: "BB", name: "Barbados", alpha3: "BRB", numeric: "052" }, + { alpha2: "BY", name: "Belarus", alpha3: "BLR", numeric: "112" }, + { alpha2: "BE", name: "Belgium", alpha3: "BEL", numeric: "056" }, + { alpha2: "BZ", name: "Belize", alpha3: "BLZ", numeric: "084" }, + { alpha2: "BJ", name: "Benin", alpha3: "BEN", numeric: "204" }, + { alpha2: "BM", name: "Bermuda", alpha3: "BMU", numeric: "060" }, + { alpha2: "BT", name: "Bhutan", alpha3: "BTN", numeric: "064" }, + { alpha2: "BO", name: "Bolivia", alpha3: "BOL", numeric: "068" }, + { + alpha2: "BQ", + name: "Bonaire, Sint Eustatius and Saba", + alpha3: "BES", + numeric: "535", + }, + { + alpha2: "BA", + name: "Bosnia and Herzegovina", + alpha3: "BIH", + numeric: "070", + }, + { alpha2: "BW", name: "Botswana", alpha3: "BWA", numeric: "072" }, + { alpha2: "BV", name: "Bouvet Island", alpha3: "BVD", numeric: "074" }, + { alpha2: "BR", name: "Brazil", alpha3: "BRA", numeric: "076" }, + { + alpha2: "IO", + name: "British Indian Ocean Territory", + alpha3: "IOT", + numeric: "086", + }, + { alpha2: "BN", name: "Brunei Darussalam", alpha3: "BRN", numeric: "096" }, + { alpha2: "BG", name: "Bulgaria", alpha3: "BGR", numeric: "100" }, + { alpha2: "BF", name: "Burkina Faso", alpha3: "BFA", numeric: "854" }, + { alpha2: "BI", name: "Burundi", alpha3: "BDI", numeric: "108" }, + { alpha2: "KH", name: "Cambodia", alpha3: "KHM", numeric: "116" }, + { alpha2: "CM", name: "Cameroon", alpha3: "CMR", numeric: "120" }, + { alpha2: "CA", name: "Canada", alpha3: "CAN", numeric: "124" }, + { alpha2: "CV", name: "Cape Verde", alpha3: "CPV", numeric: "132" }, + { alpha2: "KY", name: "Cayman Islands", alpha3: "CYM", numeric: "136" }, + { + alpha2: "CF", + name: "Central African Republic", + alpha3: "CAF", + numeric: "140", + }, + { alpha2: "TD", name: "Chad", alpha3: "TCD", numeric: "148" }, + { alpha2: "CL", name: "Chile", alpha3: "CHL", numeric: "152" }, + { alpha2: "CN", name: "China", alpha3: "CHN", numeric: "156" }, + { alpha2: "CX", name: "Christmas Island", alpha3: "CXR", numeric: "162" }, + { + alpha2: "CC", + name: "Cocos (Keeling) Islands", + alpha3: "CCK", + numeric: "166", + }, + { alpha2: "CO", name: "Colombia", alpha3: "COL", numeric: "170" }, + { alpha2: "KM", name: "Comoros", alpha3: "COM", numeric: "174" }, + { alpha2: "CG", name: "Congo", alpha3: "COG", numeric: "178" }, + { + alpha2: "CD", + name: "Congo, the Democratic Republic of the", + alpha3: "COD", + numeric: "180", + }, + { alpha2: "CK", name: "Cook Islands", alpha3: "COK", numeric: "184" }, + { alpha2: "CR", name: "Costa Rica", alpha3: "CRI", numeric: "188" }, + { alpha2: "CI", name: "Cote D'Ivoire", alpha3: "CIV", numeric: "384" }, + { alpha2: "HR", name: "Croatia", alpha3: "HRV", numeric: "191" }, + { alpha2: "CU", name: "Cuba", alpha3: "CUB", numeric: "192" }, + { alpha2: "CW", name: "Curaçao", alpha3: "CUW", numeric: "531" }, + { alpha2: "CY", name: "Cyprus", alpha3: "CYP", numeric: "196" }, + { alpha2: "CZ", name: "Czech Republic", alpha3: "CZE", numeric: "203" }, + { alpha2: "DK", name: "Denmark", alpha3: "DNK", numeric: "208" }, + { alpha2: "DJ", name: "Djibouti", alpha3: "DJI", numeric: "262" }, + { alpha2: "DM", name: "Dominica", alpha3: "DMA", numeric: "212" }, + { alpha2: "DO", name: "Dominican Republic", alpha3: "DOM", numeric: "214" }, + { alpha2: "EC", name: "Ecuador", alpha3: "ECU", numeric: "218" }, + { alpha2: "EG", name: "Egypt", alpha3: "EGY", numeric: "818" }, + { alpha2: "SV", name: "El Salvador", alpha3: "SLV", numeric: "222" }, + { alpha2: "GQ", name: "Equatorial Guinea", alpha3: "GNQ", numeric: "226" }, + { alpha2: "ER", name: "Eritrea", alpha3: "ERI", numeric: "232" }, + { alpha2: "EE", name: "Estonia", alpha3: "EST", numeric: "233" }, + { alpha2: "ET", name: "Ethiopia", alpha3: "ETH", numeric: "231" }, + { + alpha2: "FK", + name: "Falkland Islands (Malvinas)", + alpha3: "FLK", + numeric: "238", + }, + { alpha2: "FO", name: "Faroe Islands", alpha3: "FRO", numeric: "234" }, + { alpha2: "FJ", name: "Fiji", alpha3: "FJI", numeric: "242" }, + { alpha2: "FI", name: "Finland", alpha3: "FIN", numeric: "246" }, + { alpha2: "FR", name: "France", alpha3: "FRA", numeric: "250" }, + { alpha2: "GF", name: "French Guiana", alpha3: "GUF", numeric: "254" }, + { alpha2: "PF", name: "French Polynesia", alpha3: "PYF", numeric: "258" }, + { + alpha2: "TF", + name: "French Southern Territories", + alpha3: "ATF", + numeric: "260", + }, + { alpha2: "GA", name: "Gabon", alpha3: "GAB", numeric: "266" }, + { alpha2: "GM", name: "Gambia", alpha3: "GMB", numeric: "270" }, + { alpha2: "GE", name: "Georgia", alpha3: "GEO", numeric: "268" }, + { alpha2: "DE", name: "Germany", alpha3: "DEU", numeric: "276" }, + { alpha2: "GH", name: "Ghana", alpha3: "GHA", numeric: "288" }, + { alpha2: "GI", name: "Gibraltar", alpha3: "GIB", numeric: "292" }, + { alpha2: "GR", name: "Greece", alpha3: "GRC", numeric: "300" }, + { alpha2: "GL", name: "Greenland", alpha3: "GRL", numeric: "304" }, + { alpha2: "GD", name: "Grenada", alpha3: "GRD", numeric: "308" }, + { alpha2: "GP", name: "Guadeloupe", alpha3: "GLP", numeric: "312" }, + { alpha2: "GU", name: "Guam", alpha3: "GUM", numeric: "316" }, + { alpha2: "GT", name: "Guatemala", alpha3: "GTM", numeric: "320" }, + { alpha2: "GG", name: "Guernsey", alpha3: "GGY", numeric: "831" }, + { alpha2: "GN", name: "Guinea", alpha3: "GIN", numeric: "324" }, + { alpha2: "GW", name: "Guinea-Bissau", alpha3: "GNB", numeric: "624" }, + { alpha2: "GY", name: "Guyana", alpha3: "GUY", numeric: "328" }, + { alpha2: "HT", name: "Haiti", alpha3: "HTI", numeric: "332" }, + { + alpha2: "HM", + name: "Heard Island And Mcdonald Islands", + alpha3: "HMD", + numeric: "334", + }, + { + alpha2: "VA", + name: "Holy See (Vatican City State)", + alpha3: "VAT", + numeric: "336", + }, + { alpha2: "HN", name: "Honduras", alpha3: "HND", numeric: "340" }, + { alpha2: "HK", name: "Hong Kong", alpha3: "HKG", numeric: "344" }, + { alpha2: "HU", name: "Hungary", alpha3: "HUN", numeric: "348" }, + { alpha2: "IS", name: "Iceland", alpha3: "ISL", numeric: "352" }, + { alpha2: "IN", name: "India", alpha3: "IND", numeric: "356" }, + { alpha2: "ID", name: "Indonesia", alpha3: "IDN", numeric: "360" }, + { + alpha2: "IR", + name: "Iran, Islamic Republic of", + alpha3: "IRN", + numeric: "364", + }, + { alpha2: "IQ", name: "Iraq", alpha3: "IRQ", numeric: "368" }, + { alpha2: "IE", name: "Ireland", alpha3: "IRL", numeric: "372" }, + { alpha2: "IM", name: "Isle Of Man", alpha3: "IMN", numeric: "833" }, + { alpha2: "IL", name: "Israel", alpha3: "ISR", numeric: "376" }, + { alpha2: "IT", name: "Italy", alpha3: "ITA", numeric: "380" }, + { alpha2: "JM", name: "Jamaica", alpha3: "JAM", numeric: "388" }, + { alpha2: "JP", name: "Japan", alpha3: "JPN", numeric: "392" }, + { alpha2: "JE", name: "Jersey", alpha3: "JEY", numeric: "832" }, + { alpha2: "JO", name: "Jordan", alpha3: "JOR", numeric: "400" }, + { alpha2: "KZ", name: "Kazakhstan", alpha3: "KAZ", numeric: "398" }, + { alpha2: "KE", name: "Kenya", alpha3: "KEN", numeric: "404" }, + { alpha2: "KI", name: "Kiribati", alpha3: "KIR", numeric: "296" }, + { + alpha2: "KP", + name: "Korea, Democratic People's Republic of", + alpha3: "PRK", + numeric: "408", + }, + { alpha2: "KR", name: "Korea, Republic of", alpha3: "KOR", numeric: "410" }, + { alpha2: "XK", name: "Kosovo", alpha3: "XKX", numeric: "900" }, + { alpha2: "KW", name: "Kuwait", alpha3: "KWT", numeric: "414" }, + { alpha2: "KG", name: "Kyrgyzstan", alpha3: "KGZ", numeric: "417" }, + { + alpha2: "LA", + name: "Lao People's Democratic Republic", + alpha3: "LAO", + numeric: "418", + }, + { alpha2: "LV", name: "Latvia", alpha3: "LVA", numeric: "428" }, + { alpha2: "LB", name: "Lebanon", alpha3: "LBN", numeric: "422" }, + { alpha2: "LS", name: "Lesotho", alpha3: "LSO", numeric: "426" }, + { alpha2: "LR", name: "Liberia", alpha3: "LBR", numeric: "430" }, + { alpha2: "LY", name: "Libya", alpha3: "LBY", numeric: "434" }, + { alpha2: "LI", name: "Liechtenstein", alpha3: "LIE", numeric: "438" }, + { alpha2: "LT", name: "Lithuania", alpha3: "LTU", numeric: "440" }, + { alpha2: "LU", name: "Luxembourg", alpha3: "LUX", numeric: "442" }, + { alpha2: "MO", name: "Macao", alpha3: "MAC", numeric: "446" }, + { + alpha2: "MK", + name: "Macedonia, the Former Yugoslav Republic of", + alpha3: "MKD", + numeric: "807", + }, + { alpha2: "MG", name: "Madagascar", alpha3: "MDG", numeric: "450" }, + { alpha2: "MW", name: "Malawi", alpha3: "MWI", numeric: "454" }, + { alpha2: "MY", name: "Malaysia", alpha3: "MYS", numeric: "458" }, + { alpha2: "MV", name: "Maldives", alpha3: "MDV", numeric: "462" }, + { alpha2: "ML", name: "Mali", alpha3: "MLI", numeric: "466" }, + { alpha2: "MT", name: "Malta", alpha3: "MLT", numeric: "470" }, + { alpha2: "MH", name: "Marshall Islands", alpha3: "MHL", numeric: "584" }, + { alpha2: "MQ", name: "Martinique", alpha3: "MTQ", numeric: "474" }, + { alpha2: "MR", name: "Mauritania", alpha3: "MRT", numeric: "478" }, + { alpha2: "MU", name: "Mauritius", alpha3: "MUS", numeric: "480" }, + { alpha2: "YT", name: "Mayotte", alpha3: "MYT", numeric: "175" }, + { alpha2: "MX", name: "Mexico", alpha3: "MEX", numeric: "484" }, + { + alpha2: "FM", + name: "Micronesia, Federated States of", + alpha3: "FSM", + numeric: "583", + }, + { alpha2: "MD", name: "Moldova, Republic of", alpha3: "MDA", numeric: "498" }, + { alpha2: "MC", name: "Monaco", alpha3: "MCO", numeric: "492" }, + { alpha2: "MN", name: "Mongolia", alpha3: "MNG", numeric: "496" }, + { alpha2: "ME", name: "Montenegro", alpha3: "MNE", numeric: "499" }, + { alpha2: "MS", name: "Montserrat", alpha3: "MSR", numeric: "500" }, + { alpha2: "MA", name: "Morocco", alpha3: "MAR", numeric: "504" }, + { alpha2: "MZ", name: "Mozambique", alpha3: "MOZ", numeric: "508" }, + { alpha2: "MM", name: "Myanmar", alpha3: "MMR", numeric: "104" }, + { alpha2: "NA", name: "Namibia", alpha3: "NAM", numeric: "516" }, + { alpha2: "NR", name: "Nauru", alpha3: "NRU", numeric: "520" }, + { alpha2: "NP", name: "Nepal", alpha3: "NPL", numeric: "524" }, + { alpha2: "NL", name: "Netherlands", alpha3: "NLD", numeric: "528" }, + { alpha2: "NC", name: "New Caledonia", alpha3: "NCL", numeric: "540" }, + { alpha2: "NZ", name: "New Zealand", alpha3: "NZL", numeric: "554" }, + { alpha2: "NI", name: "Nicaragua", alpha3: "NIC", numeric: "558" }, + { alpha2: "NE", name: "Niger", alpha3: "NER", numeric: "562" }, + { alpha2: "NG", name: "Nigeria", alpha3: "NGA", numeric: "566" }, + { alpha2: "NU", name: "Niue", alpha3: "NIU", numeric: "570" }, + { alpha2: "NF", name: "Norfolk Island", alpha3: "NFK", numeric: "574" }, + { + alpha2: "MP", + name: "Northern Mariana Islands", + alpha3: "MNP", + numeric: "580", + }, + { alpha2: "NO", name: "Norway", alpha3: "NOR", numeric: "578" }, + { alpha2: "OM", name: "Oman", alpha3: "OMN", numeric: "512" }, + { alpha2: "PK", name: "Pakistan", alpha3: "PAK", numeric: "586" }, + { alpha2: "PW", name: "Palau", alpha3: "PLW", numeric: "585" }, + { + alpha2: "PS", + name: "Palestinian Territory, Occupied", + alpha3: "PSE", + numeric: "275", + }, + { alpha2: "PA", name: "Panama", alpha3: "PAN", numeric: "591" }, + { alpha2: "PG", name: "Papua New Guinea", alpha3: "PNG", numeric: "598" }, + { alpha2: "PY", name: "Paraguay", alpha3: "PRY", numeric: "600" }, + { alpha2: "PE", name: "Peru", alpha3: "PER", numeric: "604" }, + { alpha2: "PH", name: "Philippines", alpha3: "PHL", numeric: "608" }, + { alpha2: "PN", name: "Pitcairn", alpha3: "PCN", numeric: "612" }, + { alpha2: "PL", name: "Poland", alpha3: "POL", numeric: "616" }, + { alpha2: "PT", name: "Portugal", alpha3: "PRT", numeric: "620" }, + { alpha2: "PR", name: "Puerto Rico", alpha3: "PRI", numeric: "630" }, + { alpha2: "QA", name: "Qatar", alpha3: "QAT", numeric: "634" }, + { alpha2: "RE", name: "Reunion", alpha3: "REU", numeric: "638" }, + { alpha2: "RO", name: "Romania", alpha3: "ROM", numeric: "642" }, + { alpha2: "RU", name: "Russian Federation", alpha3: "RUS", numeric: "643" }, + { alpha2: "RW", name: "Rwanda", alpha3: "RWA", numeric: "646" }, + { alpha2: "BL", name: "Saint Barthélemy", alpha3: "BLM", numeric: "652" }, + { alpha2: "SH", name: "Saint Helena", alpha3: "SHN", numeric: "654" }, + { + alpha2: "KN", + name: "Saint Kitts and Nevis", + alpha3: "KNA", + numeric: "659", + }, + { alpha2: "LC", name: "Saint Lucia", alpha3: "LCA", numeric: "662" }, + { + alpha2: "MF", + name: "Saint Martin (French part)", + alpha3: "MAF", + numeric: "663", + }, + { + alpha2: "PM", + name: "Saint Pierre and Miquelon", + alpha3: "SPM", + numeric: "666", + }, + { + alpha2: "VC", + name: "Saint Vincent and the Grenadines", + alpha3: "VCT", + numeric: "670", + }, + { alpha2: "WS", name: "Samoa", alpha3: "WSM", numeric: "882" }, + { alpha2: "SM", name: "San Marino", alpha3: "SMR", numeric: "674" }, + { + alpha2: "ST", + name: "Sao Tome and Principe", + alpha3: "STP", + numeric: "678", + }, + { alpha2: "SA", name: "Saudi Arabia", alpha3: "SAU", numeric: "682" }, + { alpha2: "SN", name: "Senegal", alpha3: "SEN", numeric: "686" }, + { alpha2: "RS", name: "Serbia", alpha3: "SRB", numeric: "688" }, + { alpha2: "SC", name: "Seychelles", alpha3: "SYC", numeric: "690" }, + { alpha2: "SL", name: "Sierra Leone", alpha3: "SLE", numeric: "694" }, + { alpha2: "SG", name: "Singapore", alpha3: "SGP", numeric: "702" }, + { alpha2: "SX", name: "Sint Maarten", alpha3: "SXM", numeric: "534" }, + { alpha2: "SK", name: "Slovakia", alpha3: "SVK", numeric: "703" }, + { alpha2: "SI", name: "Slovenia", alpha3: "SVN", numeric: "705" }, + { alpha2: "SB", name: "Solomon Islands", alpha3: "SLB", numeric: "090" }, + { alpha2: "SO", name: "Somalia", alpha3: "SOM", numeric: "706" }, + { alpha2: "ZA", name: "South Africa", alpha3: "ZAF", numeric: "710" }, + { + alpha2: "GS", + name: "South Georgia and the South Sandwich Islands", + alpha3: "SGS", + numeric: "239", + }, + { alpha2: "SS", name: "South Sudan", alpha3: "SSD", numeric: "728" }, + { alpha2: "ES", name: "Spain", alpha3: "ESP", numeric: "724" }, + { alpha2: "LK", name: "Sri Lanka", alpha3: "LKA", numeric: "144" }, + { alpha2: "SD", name: "Sudan", alpha3: "SDN", numeric: "729" }, + { alpha2: "SR", name: "Suriname", alpha3: "SUR", numeric: "740" }, + { + alpha2: "SJ", + name: "Svalbard and Jan Mayen", + alpha3: "SJM", + numeric: "744", + }, + { alpha2: "SZ", name: "Swaziland", alpha3: "SWZ", numeric: "748" }, + { alpha2: "SE", name: "Sweden", alpha3: "SWE", numeric: "752" }, + { alpha2: "CH", name: "Switzerland", alpha3: "CHE", numeric: "756" }, + { alpha2: "SY", name: "Syrian Arab Republic", alpha3: "SYR", numeric: "760" }, + { + alpha2: "TW", + name: "Taiwan, Province of China", + alpha3: "TWN", + numeric: "158", + }, + { alpha2: "TJ", name: "Tajikistan", alpha3: "TJK", numeric: "762" }, + { + alpha2: "TZ", + name: "Tanzania, United Republic of", + alpha3: "TZA", + numeric: "834", + }, + { alpha2: "TH", name: "Thailand", alpha3: "THA", numeric: "764" }, + { alpha2: "TL", name: "Timor Leste", alpha3: "TLS", numeric: "626" }, + { alpha2: "TG", name: "Togo", alpha3: "TGO", numeric: "768" }, + { alpha2: "TK", name: "Tokelau", alpha3: "TKL", numeric: "772" }, + { alpha2: "TO", name: "Tonga", alpha3: "TON", numeric: "776" }, + { alpha2: "TT", name: "Trinidad and Tobago", alpha3: "TTO", numeric: "780" }, + { alpha2: "TN", name: "Tunisia", alpha3: "TUN", numeric: "788" }, + { alpha2: "TR", name: "Turkey", alpha3: "TUR", numeric: "792" }, + { alpha2: "TM", name: "Turkmenistan", alpha3: "TKM", numeric: "795" }, + { + alpha2: "TC", + name: "Turks and Caicos Islands", + alpha3: "TCA", + numeric: "796", + }, + { alpha2: "TV", name: "Tuvalu", alpha3: "TUV", numeric: "798" }, + { alpha2: "UG", name: "Uganda", alpha3: "UGA", numeric: "800" }, + { alpha2: "UA", name: "Ukraine", alpha3: "UKR", numeric: "804" }, + { alpha2: "AE", name: "United Arab Emirates", alpha3: "ARE", numeric: "784" }, + { alpha2: "GB", name: "United Kingdom", alpha3: "GBR", numeric: "826" }, + { alpha2: "US", name: "United States", alpha3: "USA", numeric: "840" }, + { + alpha2: "UM", + name: "United States Minor Outlying Islands", + alpha3: "UMI", + numeric: "581", + }, + { alpha2: "UY", name: "Uruguay", alpha3: "URY", numeric: "858" }, + { alpha2: "UZ", name: "Uzbekistan", alpha3: "UZB", numeric: "860" }, + { alpha2: "VU", name: "Vanuatu", alpha3: "VUT", numeric: "548" }, + { alpha2: "VE", name: "Venezuela", alpha3: "VEN", numeric: "862" }, + { alpha2: "VN", name: "Viet Nam", alpha3: "VNM", numeric: "704" }, + { + alpha2: "VG", + name: "Virgin Islands, British", + alpha3: "VGB", + numeric: "092", + }, + { alpha2: "VI", name: "Virgin Islands, U.S.", alpha3: "VIR", numeric: "850" }, + { alpha2: "WF", name: "Wallis and Futuna", alpha3: "WLF", numeric: "876" }, + { alpha2: "EH", name: "Western Sahara", alpha3: "ESH", numeric: "732" }, + { alpha2: "YE", name: "Yemen", alpha3: "YEM", numeric: "887" }, + { alpha2: "ZM", name: "Zambia", alpha3: "ZMB", numeric: "894" }, + { alpha2: "ZW", name: "Zimbabwe", alpha3: "ZWE", numeric: "716" }, + { alpha2: "AX", name: "Åland Islands", alpha3: "ALA", numeric: "248" }, +] diff --git a/packages/utils/src/defaults/currencies.ts b/packages/utils/src/defaults/currencies.ts new file mode 100644 index 0000000000000..b5704f519a97d --- /dev/null +++ b/packages/utils/src/defaults/currencies.ts @@ -0,0 +1,1092 @@ +export type Currency = { + symbol: string + name: string + symbol_native: string + decimal_digits: number + rounding: number + code: string + name_plural: string +} + +export const defaultCurrencies: Record = { + USD: { + symbol: "$", + name: "US Dollar", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "USD", + name_plural: "US dollars", + }, + CAD: { + symbol: "CA$", + name: "Canadian Dollar", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "CAD", + name_plural: "Canadian dollars", + }, + EUR: { + symbol: "€", + name: "Euro", + symbol_native: "€", + decimal_digits: 2, + rounding: 0, + code: "EUR", + name_plural: "euros", + }, + AED: { + symbol: "AED", + name: "United Arab Emirates Dirham", + symbol_native: "د.إ.‏", + decimal_digits: 2, + rounding: 0, + code: "AED", + name_plural: "UAE dirhams", + }, + AFN: { + symbol: "Af", + name: "Afghan Afghani", + symbol_native: "؋", + decimal_digits: 0, + rounding: 0, + code: "AFN", + name_plural: "Afghan Afghanis", + }, + ALL: { + symbol: "ALL", + name: "Albanian Lek", + symbol_native: "Lek", + decimal_digits: 0, + rounding: 0, + code: "ALL", + name_plural: "Albanian lekë", + }, + AMD: { + symbol: "AMD", + name: "Armenian Dram", + symbol_native: "դր.", + decimal_digits: 0, + rounding: 0, + code: "AMD", + name_plural: "Armenian drams", + }, + ARS: { + symbol: "AR$", + name: "Argentine Peso", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "ARS", + name_plural: "Argentine pesos", + }, + AUD: { + symbol: "AU$", + name: "Australian Dollar", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "AUD", + name_plural: "Australian dollars", + }, + AZN: { + symbol: "man.", + name: "Azerbaijani Manat", + symbol_native: "ман.", + decimal_digits: 2, + rounding: 0, + code: "AZN", + name_plural: "Azerbaijani manats", + }, + BAM: { + symbol: "KM", + name: "Bosnia-Herzegovina Convertible Mark", + symbol_native: "KM", + decimal_digits: 2, + rounding: 0, + code: "BAM", + name_plural: "Bosnia-Herzegovina convertible marks", + }, + BDT: { + symbol: "Tk", + name: "Bangladeshi Taka", + symbol_native: "৳", + decimal_digits: 2, + rounding: 0, + code: "BDT", + name_plural: "Bangladeshi takas", + }, + BGN: { + symbol: "BGN", + name: "Bulgarian Lev", + symbol_native: "лв.", + decimal_digits: 2, + rounding: 0, + code: "BGN", + name_plural: "Bulgarian leva", + }, + BHD: { + symbol: "BD", + name: "Bahraini Dinar", + symbol_native: "د.ب.‏", + decimal_digits: 3, + rounding: 0, + code: "BHD", + name_plural: "Bahraini dinars", + }, + BIF: { + symbol: "FBu", + name: "Burundian Franc", + symbol_native: "FBu", + decimal_digits: 0, + rounding: 0, + code: "BIF", + name_plural: "Burundian francs", + }, + BND: { + symbol: "BN$", + name: "Brunei Dollar", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "BND", + name_plural: "Brunei dollars", + }, + BOB: { + symbol: "Bs", + name: "Bolivian Boliviano", + symbol_native: "Bs", + decimal_digits: 2, + rounding: 0, + code: "BOB", + name_plural: "Bolivian bolivianos", + }, + BRL: { + symbol: "R$", + name: "Brazilian Real", + symbol_native: "R$", + decimal_digits: 2, + rounding: 0, + code: "BRL", + name_plural: "Brazilian reals", + }, + BWP: { + symbol: "BWP", + name: "Botswanan Pula", + symbol_native: "P", + decimal_digits: 2, + rounding: 0, + code: "BWP", + name_plural: "Botswanan pulas", + }, + BYN: { + symbol: "Br", + name: "Belarusian Ruble", + symbol_native: "руб.", + decimal_digits: 2, + rounding: 0, + code: "BYN", + name_plural: "Belarusian rubles", + }, + BZD: { + symbol: "BZ$", + name: "Belize Dollar", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "BZD", + name_plural: "Belize dollars", + }, + CDF: { + symbol: "CDF", + name: "Congolese Franc", + symbol_native: "FrCD", + decimal_digits: 2, + rounding: 0, + code: "CDF", + name_plural: "Congolese francs", + }, + CHF: { + symbol: "CHF", + name: "Swiss Franc", + symbol_native: "CHF", + decimal_digits: 2, + rounding: 0.05, + code: "CHF", + name_plural: "Swiss francs", + }, + CLP: { + symbol: "CL$", + name: "Chilean Peso", + symbol_native: "$", + decimal_digits: 0, + rounding: 0, + code: "CLP", + name_plural: "Chilean pesos", + }, + CNY: { + symbol: "CN¥", + name: "Chinese Yuan", + symbol_native: "CN¥", + decimal_digits: 2, + rounding: 0, + code: "CNY", + name_plural: "Chinese yuan", + }, + COP: { + symbol: "CO$", + name: "Colombian Peso", + symbol_native: "$", + decimal_digits: 0, + rounding: 0, + code: "COP", + name_plural: "Colombian pesos", + }, + CRC: { + symbol: "₡", + name: "Costa Rican Colón", + symbol_native: "₡", + decimal_digits: 0, + rounding: 0, + code: "CRC", + name_plural: "Costa Rican colóns", + }, + CVE: { + symbol: "CV$", + name: "Cape Verdean Escudo", + symbol_native: "CV$", + decimal_digits: 2, + rounding: 0, + code: "CVE", + name_plural: "Cape Verdean escudos", + }, + CZK: { + symbol: "Kč", + name: "Czech Republic Koruna", + symbol_native: "Kč", + decimal_digits: 2, + rounding: 0, + code: "CZK", + name_plural: "Czech Republic korunas", + }, + DJF: { + symbol: "Fdj", + name: "Djiboutian Franc", + symbol_native: "Fdj", + decimal_digits: 0, + rounding: 0, + code: "DJF", + name_plural: "Djiboutian francs", + }, + DKK: { + symbol: "Dkr", + name: "Danish Krone", + symbol_native: "kr", + decimal_digits: 2, + rounding: 0, + code: "DKK", + name_plural: "Danish kroner", + }, + DOP: { + symbol: "RD$", + name: "Dominican Peso", + symbol_native: "RD$", + decimal_digits: 2, + rounding: 0, + code: "DOP", + name_plural: "Dominican pesos", + }, + DZD: { + symbol: "DA", + name: "Algerian Dinar", + symbol_native: "د.ج.‏", + decimal_digits: 2, + rounding: 0, + code: "DZD", + name_plural: "Algerian dinars", + }, + EEK: { + symbol: "Ekr", + name: "Estonian Kroon", + symbol_native: "kr", + decimal_digits: 2, + rounding: 0, + code: "EEK", + name_plural: "Estonian kroons", + }, + EGP: { + symbol: "EGP", + name: "Egyptian Pound", + symbol_native: "ج.م.‏", + decimal_digits: 2, + rounding: 0, + code: "EGP", + name_plural: "Egyptian pounds", + }, + ERN: { + symbol: "Nfk", + name: "Eritrean Nakfa", + symbol_native: "Nfk", + decimal_digits: 2, + rounding: 0, + code: "ERN", + name_plural: "Eritrean nakfas", + }, + ETB: { + symbol: "Br", + name: "Ethiopian Birr", + symbol_native: "Br", + decimal_digits: 2, + rounding: 0, + code: "ETB", + name_plural: "Ethiopian birrs", + }, + GBP: { + symbol: "£", + name: "British Pound Sterling", + symbol_native: "£", + decimal_digits: 2, + rounding: 0, + code: "GBP", + name_plural: "British pounds sterling", + }, + GEL: { + symbol: "GEL", + name: "Georgian Lari", + symbol_native: "GEL", + decimal_digits: 2, + rounding: 0, + code: "GEL", + name_plural: "Georgian laris", + }, + GHS: { + symbol: "GH₵", + name: "Ghanaian Cedi", + symbol_native: "GH₵", + decimal_digits: 2, + rounding: 0, + code: "GHS", + name_plural: "Ghanaian cedis", + }, + GNF: { + symbol: "FG", + name: "Guinean Franc", + symbol_native: "FG", + decimal_digits: 0, + rounding: 0, + code: "GNF", + name_plural: "Guinean francs", + }, + GTQ: { + symbol: "GTQ", + name: "Guatemalan Quetzal", + symbol_native: "Q", + decimal_digits: 2, + rounding: 0, + code: "GTQ", + name_plural: "Guatemalan quetzals", + }, + HKD: { + symbol: "HK$", + name: "Hong Kong Dollar", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "HKD", + name_plural: "Hong Kong dollars", + }, + HNL: { + symbol: "HNL", + name: "Honduran Lempira", + symbol_native: "L", + decimal_digits: 2, + rounding: 0, + code: "HNL", + name_plural: "Honduran lempiras", + }, + HRK: { + symbol: "kn", + name: "Croatian Kuna", + symbol_native: "kn", + decimal_digits: 2, + rounding: 0, + code: "HRK", + name_plural: "Croatian kunas", + }, + HUF: { + symbol: "Ft", + name: "Hungarian Forint", + symbol_native: "Ft", + decimal_digits: 0, + rounding: 0, + code: "HUF", + name_plural: "Hungarian forints", + }, + IDR: { + symbol: "Rp", + name: "Indonesian Rupiah", + symbol_native: "Rp", + decimal_digits: 0, + rounding: 0, + code: "IDR", + name_plural: "Indonesian rupiahs", + }, + ILS: { + symbol: "₪", + name: "Israeli New Sheqel", + symbol_native: "₪", + decimal_digits: 2, + rounding: 0, + code: "ILS", + name_plural: "Israeli new sheqels", + }, + INR: { + symbol: "Rs", + name: "Indian Rupee", + symbol_native: "টকা", + decimal_digits: 2, + rounding: 0, + code: "INR", + name_plural: "Indian rupees", + }, + IQD: { + symbol: "IQD", + name: "Iraqi Dinar", + symbol_native: "د.ع.‏", + decimal_digits: 0, + rounding: 0, + code: "IQD", + name_plural: "Iraqi dinars", + }, + IRR: { + symbol: "IRR", + name: "Iranian Rial", + symbol_native: "﷼", + decimal_digits: 0, + rounding: 0, + code: "IRR", + name_plural: "Iranian rials", + }, + ISK: { + symbol: "Ikr", + name: "Icelandic Króna", + symbol_native: "kr", + decimal_digits: 0, + rounding: 0, + code: "ISK", + name_plural: "Icelandic krónur", + }, + JMD: { + symbol: "J$", + name: "Jamaican Dollar", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "JMD", + name_plural: "Jamaican dollars", + }, + JOD: { + symbol: "JD", + name: "Jordanian Dinar", + symbol_native: "د.أ.‏", + decimal_digits: 3, + rounding: 0, + code: "JOD", + name_plural: "Jordanian dinars", + }, + JPY: { + symbol: "¥", + name: "Japanese Yen", + symbol_native: "¥", + decimal_digits: 0, + rounding: 0, + code: "JPY", + name_plural: "Japanese yen", + }, + KES: { + symbol: "Ksh", + name: "Kenyan Shilling", + symbol_native: "Ksh", + decimal_digits: 2, + rounding: 0, + code: "KES", + name_plural: "Kenyan shillings", + }, + KHR: { + symbol: "KHR", + name: "Cambodian Riel", + symbol_native: "៛", + decimal_digits: 2, + rounding: 0, + code: "KHR", + name_plural: "Cambodian riels", + }, + KMF: { + symbol: "CF", + name: "Comorian Franc", + symbol_native: "FC", + decimal_digits: 0, + rounding: 0, + code: "KMF", + name_plural: "Comorian francs", + }, + KRW: { + symbol: "₩", + name: "South Korean Won", + symbol_native: "₩", + decimal_digits: 0, + rounding: 0, + code: "KRW", + name_plural: "South Korean won", + }, + KWD: { + symbol: "KD", + name: "Kuwaiti Dinar", + symbol_native: "د.ك.‏", + decimal_digits: 3, + rounding: 0, + code: "KWD", + name_plural: "Kuwaiti dinars", + }, + KZT: { + symbol: "KZT", + name: "Kazakhstani Tenge", + symbol_native: "тңг.", + decimal_digits: 2, + rounding: 0, + code: "KZT", + name_plural: "Kazakhstani tenges", + }, + LBP: { + symbol: "LB£", + name: "Lebanese Pound", + symbol_native: "ل.ل.‏", + decimal_digits: 0, + rounding: 0, + code: "LBP", + name_plural: "Lebanese pounds", + }, + LKR: { + symbol: "SLRs", + name: "Sri Lankan Rupee", + symbol_native: "SL Re", + decimal_digits: 2, + rounding: 0, + code: "LKR", + name_plural: "Sri Lankan rupees", + }, + LTL: { + symbol: "Lt", + name: "Lithuanian Litas", + symbol_native: "Lt", + decimal_digits: 2, + rounding: 0, + code: "LTL", + name_plural: "Lithuanian litai", + }, + LVL: { + symbol: "Ls", + name: "Latvian Lats", + symbol_native: "Ls", + decimal_digits: 2, + rounding: 0, + code: "LVL", + name_plural: "Latvian lati", + }, + LYD: { + symbol: "LD", + name: "Libyan Dinar", + symbol_native: "د.ل.‏", + decimal_digits: 3, + rounding: 0, + code: "LYD", + name_plural: "Libyan dinars", + }, + MAD: { + symbol: "MAD", + name: "Moroccan Dirham", + symbol_native: "د.م.‏", + decimal_digits: 2, + rounding: 0, + code: "MAD", + name_plural: "Moroccan dirhams", + }, + MDL: { + symbol: "MDL", + name: "Moldovan Leu", + symbol_native: "MDL", + decimal_digits: 2, + rounding: 0, + code: "MDL", + name_plural: "Moldovan lei", + }, + MGA: { + symbol: "MGA", + name: "Malagasy Ariary", + symbol_native: "MGA", + decimal_digits: 0, + rounding: 0, + code: "MGA", + name_plural: "Malagasy Ariaries", + }, + MKD: { + symbol: "MKD", + name: "Macedonian Denar", + symbol_native: "MKD", + decimal_digits: 2, + rounding: 0, + code: "MKD", + name_plural: "Macedonian denari", + }, + MMK: { + symbol: "MMK", + name: "Myanma Kyat", + symbol_native: "K", + decimal_digits: 0, + rounding: 0, + code: "MMK", + name_plural: "Myanma kyats", + }, + MNT: { + symbol: "MNT", + name: "Mongolian Tugrig", + symbol_native: "₮", + decimal_digits: 0, + rounding: 0, + code: "MNT", + name_plural: "Mongolian Tugrugs", + }, + MOP: { + symbol: "MOP$", + name: "Macanese Pataca", + symbol_native: "MOP$", + decimal_digits: 2, + rounding: 0, + code: "MOP", + name_plural: "Macanese patacas", + }, + MUR: { + symbol: "MURs", + name: "Mauritian Rupee", + symbol_native: "MURs", + decimal_digits: 0, + rounding: 0, + code: "MUR", + name_plural: "Mauritian rupees", + }, + MXN: { + symbol: "MX$", + name: "Mexican Peso", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "MXN", + name_plural: "Mexican pesos", + }, + MYR: { + symbol: "RM", + name: "Malaysian Ringgit", + symbol_native: "RM", + decimal_digits: 2, + rounding: 0, + code: "MYR", + name_plural: "Malaysian ringgits", + }, + MZN: { + symbol: "MTn", + name: "Mozambican Metical", + symbol_native: "MTn", + decimal_digits: 2, + rounding: 0, + code: "MZN", + name_plural: "Mozambican meticals", + }, + NAD: { + symbol: "N$", + name: "Namibian Dollar", + symbol_native: "N$", + decimal_digits: 2, + rounding: 0, + code: "NAD", + name_plural: "Namibian dollars", + }, + NGN: { + symbol: "₦", + name: "Nigerian Naira", + symbol_native: "₦", + decimal_digits: 2, + rounding: 0, + code: "NGN", + name_plural: "Nigerian nairas", + }, + NIO: { + symbol: "C$", + name: "Nicaraguan Córdoba", + symbol_native: "C$", + decimal_digits: 2, + rounding: 0, + code: "NIO", + name_plural: "Nicaraguan córdobas", + }, + NOK: { + symbol: "Nkr", + name: "Norwegian Krone", + symbol_native: "kr", + decimal_digits: 2, + rounding: 0, + code: "NOK", + name_plural: "Norwegian kroner", + }, + NPR: { + symbol: "NPRs", + name: "Nepalese Rupee", + symbol_native: "नेरू", + decimal_digits: 2, + rounding: 0, + code: "NPR", + name_plural: "Nepalese rupees", + }, + NZD: { + symbol: "NZ$", + name: "New Zealand Dollar", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "NZD", + name_plural: "New Zealand dollars", + }, + OMR: { + symbol: "OMR", + name: "Omani Rial", + symbol_native: "ر.ع.‏", + decimal_digits: 3, + rounding: 0, + code: "OMR", + name_plural: "Omani rials", + }, + PAB: { + symbol: "B/.", + name: "Panamanian Balboa", + symbol_native: "B/.", + decimal_digits: 2, + rounding: 0, + code: "PAB", + name_plural: "Panamanian balboas", + }, + PEN: { + symbol: "S/.", + name: "Peruvian Nuevo Sol", + symbol_native: "S/.", + decimal_digits: 2, + rounding: 0, + code: "PEN", + name_plural: "Peruvian nuevos soles", + }, + PHP: { + symbol: "₱", + name: "Philippine Peso", + symbol_native: "₱", + decimal_digits: 2, + rounding: 0, + code: "PHP", + name_plural: "Philippine pesos", + }, + PKR: { + symbol: "PKRs", + name: "Pakistani Rupee", + symbol_native: "₨", + decimal_digits: 0, + rounding: 0, + code: "PKR", + name_plural: "Pakistani rupees", + }, + PLN: { + symbol: "zł", + name: "Polish Zloty", + symbol_native: "zł", + decimal_digits: 2, + rounding: 0, + code: "PLN", + name_plural: "Polish zlotys", + }, + PYG: { + symbol: "₲", + name: "Paraguayan Guarani", + symbol_native: "₲", + decimal_digits: 0, + rounding: 0, + code: "PYG", + name_plural: "Paraguayan guaranis", + }, + QAR: { + symbol: "QR", + name: "Qatari Rial", + symbol_native: "ر.ق.‏", + decimal_digits: 2, + rounding: 0, + code: "QAR", + name_plural: "Qatari rials", + }, + RON: { + symbol: "RON", + name: "Romanian Leu", + symbol_native: "RON", + decimal_digits: 2, + rounding: 0, + code: "RON", + name_plural: "Romanian lei", + }, + RSD: { + symbol: "din.", + name: "Serbian Dinar", + symbol_native: "дин.", + decimal_digits: 0, + rounding: 0, + code: "RSD", + name_plural: "Serbian dinars", + }, + RUB: { + symbol: "RUB", + name: "Russian Ruble", + symbol_native: "₽.", + decimal_digits: 2, + rounding: 0, + code: "RUB", + name_plural: "Russian rubles", + }, + RWF: { + symbol: "RWF", + name: "Rwandan Franc", + symbol_native: "FR", + decimal_digits: 0, + rounding: 0, + code: "RWF", + name_plural: "Rwandan francs", + }, + SAR: { + symbol: "SR", + name: "Saudi Riyal", + symbol_native: "ر.س.‏", + decimal_digits: 2, + rounding: 0, + code: "SAR", + name_plural: "Saudi riyals", + }, + SDG: { + symbol: "SDG", + name: "Sudanese Pound", + symbol_native: "SDG", + decimal_digits: 2, + rounding: 0, + code: "SDG", + name_plural: "Sudanese pounds", + }, + SEK: { + symbol: "Skr", + name: "Swedish Krona", + symbol_native: "kr", + decimal_digits: 2, + rounding: 0, + code: "SEK", + name_plural: "Swedish kronor", + }, + SGD: { + symbol: "S$", + name: "Singapore Dollar", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "SGD", + name_plural: "Singapore dollars", + }, + SOS: { + symbol: "Ssh", + name: "Somali Shilling", + symbol_native: "Ssh", + decimal_digits: 0, + rounding: 0, + code: "SOS", + name_plural: "Somali shillings", + }, + SYP: { + symbol: "SY£", + name: "Syrian Pound", + symbol_native: "ل.س.‏", + decimal_digits: 0, + rounding: 0, + code: "SYP", + name_plural: "Syrian pounds", + }, + THB: { + symbol: "฿", + name: "Thai Baht", + symbol_native: "฿", + decimal_digits: 2, + rounding: 0, + code: "THB", + name_plural: "Thai baht", + }, + TND: { + symbol: "DT", + name: "Tunisian Dinar", + symbol_native: "د.ت.‏", + decimal_digits: 3, + rounding: 0, + code: "TND", + name_plural: "Tunisian dinars", + }, + TOP: { + symbol: "T$", + name: "Tongan Paʻanga", + symbol_native: "T$", + decimal_digits: 2, + rounding: 0, + code: "TOP", + name_plural: "Tongan paʻanga", + }, + TRY: { + symbol: "TL", + name: "Turkish Lira", + symbol_native: "TL", + decimal_digits: 2, + rounding: 0, + code: "TRY", + name_plural: "Turkish Lira", + }, + TTD: { + symbol: "TT$", + name: "Trinidad and Tobago Dollar", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "TTD", + name_plural: "Trinidad and Tobago dollars", + }, + TWD: { + symbol: "NT$", + name: "New Taiwan Dollar", + symbol_native: "NT$", + decimal_digits: 2, + rounding: 0, + code: "TWD", + name_plural: "New Taiwan dollars", + }, + TZS: { + symbol: "TSh", + name: "Tanzanian Shilling", + symbol_native: "TSh", + decimal_digits: 0, + rounding: 0, + code: "TZS", + name_plural: "Tanzanian shillings", + }, + UAH: { + symbol: "₴", + name: "Ukrainian Hryvnia", + symbol_native: "₴", + decimal_digits: 2, + rounding: 0, + code: "UAH", + name_plural: "Ukrainian hryvnias", + }, + UGX: { + symbol: "USh", + name: "Ugandan Shilling", + symbol_native: "USh", + decimal_digits: 0, + rounding: 0, + code: "UGX", + name_plural: "Ugandan shillings", + }, + UYU: { + symbol: "$U", + name: "Uruguayan Peso", + symbol_native: "$", + decimal_digits: 2, + rounding: 0, + code: "UYU", + name_plural: "Uruguayan pesos", + }, + UZS: { + symbol: "UZS", + name: "Uzbekistan Som", + symbol_native: "UZS", + decimal_digits: 0, + rounding: 0, + code: "UZS", + name_plural: "Uzbekistan som", + }, + VEF: { + symbol: "Bs.F.", + name: "Venezuelan Bolívar", + symbol_native: "Bs.F.", + decimal_digits: 2, + rounding: 0, + code: "VEF", + name_plural: "Venezuelan bolívars", + }, + VND: { + symbol: "₫", + name: "Vietnamese Dong", + symbol_native: "₫", + decimal_digits: 0, + rounding: 0, + code: "VND", + name_plural: "Vietnamese dong", + }, + XAF: { + symbol: "FCFA", + name: "CFA Franc BEAC", + symbol_native: "FCFA", + decimal_digits: 0, + rounding: 0, + code: "XAF", + name_plural: "CFA francs BEAC", + }, + XOF: { + symbol: "CFA", + name: "CFA Franc BCEAO", + symbol_native: "CFA", + decimal_digits: 0, + rounding: 0, + code: "XOF", + name_plural: "CFA francs BCEAO", + }, + YER: { + symbol: "YR", + name: "Yemeni Rial", + symbol_native: "ر.ي.‏", + decimal_digits: 0, + rounding: 0, + code: "YER", + name_plural: "Yemeni rials", + }, + ZAR: { + symbol: "R", + name: "South African Rand", + symbol_native: "R", + decimal_digits: 2, + rounding: 0, + code: "ZAR", + name_plural: "South African rand", + }, + ZMK: { + symbol: "ZK", + name: "Zambian Kwacha", + symbol_native: "ZK", + decimal_digits: 0, + rounding: 0, + code: "ZMK", + name_plural: "Zambian kwachas", + }, + ZWL: { + symbol: "ZWL$", + name: "Zimbabwean Dollar", + symbol_native: "ZWL$", + decimal_digits: 0, + rounding: 0, + code: "ZWL", + name_plural: "Zimbabwean Dollar", + }, +} diff --git a/packages/utils/src/defaults/index.ts b/packages/utils/src/defaults/index.ts new file mode 100644 index 0000000000000..6375da30e3dff --- /dev/null +++ b/packages/utils/src/defaults/index.ts @@ -0,0 +1,2 @@ +export * from "./countries" +export * from "./currencies" diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 2d0c33da13719..b45e6910d78d3 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -3,6 +3,7 @@ export * from "./bundles" export * from "./common" export * from "./dal" export * from "./decorators" +export * from "./defaults" export * from "./event-bus" export * from "./exceptions" export * from "./feature-flags" diff --git a/yarn.lock b/yarn.lock index 793475f19b566..54469bd595e70 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8578,6 +8578,33 @@ __metadata: languageName: unknown linkType: soft +"@medusajs/region@workspace:packages/region": + version: 0.0.0-use.local + resolution: "@medusajs/region@workspace:packages/region" + dependencies: + "@medusajs/modules-sdk": ^1.12.4 + "@medusajs/types": ^1.11.8 + "@medusajs/utils": ^1.11.1 + "@mikro-orm/cli": 5.9.7 + "@mikro-orm/core": 5.9.7 + "@mikro-orm/migrations": 5.9.7 + "@mikro-orm/postgresql": 5.9.7 + awilix: ^8.0.0 + cross-env: ^5.2.1 + dotenv: ^16.1.4 + jest: ^29.6.3 + knex: 2.4.2 + medusa-test-utils: "workspace:^" + rimraf: ^3.0.2 + ts-jest: ^29.1.1 + ts-node: ^10.9.1 + tsc-alias: ^1.8.6 + typescript: ^5.1.6 + bin: + medusa-region-seed: dist/scripts/bin/run-seed.js + languageName: unknown + linkType: soft + "@medusajs/sales-channel@workspace:packages/sales-channel": version: 0.0.0-use.local resolution: "@medusajs/sales-channel@workspace:packages/sales-channel" @@ -37929,7 +37956,7 @@ __metadata: languageName: unknown linkType: soft -"medusa-test-utils@^1.1.40, medusa-test-utils@^1.1.41, medusa-test-utils@workspace:packages/medusa-test-utils": +"medusa-test-utils@^1.1.40, medusa-test-utils@^1.1.41, medusa-test-utils@workspace:^, medusa-test-utils@workspace:packages/medusa-test-utils": version: 0.0.0-use.local resolution: "medusa-test-utils@workspace:packages/medusa-test-utils" dependencies: