Skip to content

Commit

Permalink
chore: update scope
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomontalbano committed Sep 24, 2024
1 parent ea3831a commit ace0fde
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 112 deletions.
120 changes: 60 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions packages/setup/data/markets.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
"merchant": "merchant_1",
"inventory_model": "inventory_model_1",
"price_list": "price_list_1",
"name": "Europe"
"name": "Europe",
"code": "eu"
},
{
"reference": "market_2",
"merchant": "merchant_1",
"inventory_model": "inventory_model_2",
"price_list": "price_list_2",
"name": "USA"
"name": "USA",
"code": "us"
},
{
"reference": "market_3",
"merchant": "merchant_1",
"inventory_model": "inventory_model_1",
"price_list": "price_list_3",
"name": "UK"
"name": "UK",
"code": "uk"
}
]
19 changes: 17 additions & 2 deletions packages/setup/scripts/markets.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import util from 'util'
import { createCommerceLayerClient, getCurrentApplicationInfo } from './utils/application'

(async () => {
const currentApplicationInfo = getCurrentApplicationInfo()
const commerceLayer = await createCommerceLayerClient(currentApplicationInfo)

const markets = await commerceLayer.markets.list({
fields: ['number', 'name']
fields: ['name', 'id', 'code', 'number']
})

console.info('Your organization has', markets.length, 'markets:')

for (const market of markets) {
console.info(' - ', market.name, 'with number', market.number)
console.info(`\n - ${market.name}`)
console.info(
util.inspect(
{
id: market.id,
code: market.code,
number: market.number
},
{
colors: true,
compact: false
}
)
)
}

})()
12 changes: 9 additions & 3 deletions packages/types/src/json/countries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ type RawDataCountrySchema = z.ZodObject<{
*
* Market is an **optional** attribute. If you don't specify any market, then the country will be presented with a non-shoppable experience (no price, no availability, no cart).
* @see https://github.com/commercelayer/demo-store#4-choose-the-countries-where-youre-going-to-sell
* @example 11279
* @example "id:vlGRmhpEeg"
* @example "code:europe"
*/
market: z.ZodOptional<z.ZodNumber>
market: z.ZodOptional<z.ZodUnion<[z.ZodType<`id:${string}` | `code:${string}`, z.ZodTypeDef, `id:${string}` | `code:${string}`>, z.ZodNumber]>>

/**
* Reference to the `catalogs` id
Expand Down Expand Up @@ -58,7 +59,12 @@ type RawDataCountrySchema = z.ZodObject<{
const rawDataCountry_schema: RawDataCountrySchema = z.object({
name: z.string(),
code: z.string(),
market: z.number().optional(),
market: z
.custom<`id:${string}` | `code:${string}`>((val) => {
return typeof val === 'string' ? /^id:|code:/.test(val) : false;
})
.or(z.number())
.optional(),
catalog: z.string(),
languages: z.string().array().min(1),
region: z.string()
Expand Down
Loading

0 comments on commit ace0fde

Please sign in to comment.