Skip to content

Commit

Permalink
Merge branch 'develop' into fix/update-region-on-cart
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl committed Oct 1, 2024
2 parents 84f1438 + 13a3c1b commit c70874b
Show file tree
Hide file tree
Showing 250 changed files with 2,834 additions and 1,742 deletions.
16 changes: 12 additions & 4 deletions integration-tests/http/__tests__/auth/admin/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,23 @@ medusaIntegrationTestRunner({
describe("Reset password flows", () => {
it("should generate a reset password token", async () => {
const response = await api.post("/auth/user/emailpass/reset-password", {
email: "[email protected]",
identifier: "[email protected]",
})

expect(response.status).toEqual(201)
})

it("should fail if identifier is not provided", async () => {
const errResponse = await api
.post("/auth/user/emailpass/reset-password", {})
.catch((e) => e)

expect(errResponse.response.status).toEqual(400)
})

it("should fail to generate token for non-existing user, but still respond with 201", async () => {
const response = await api.post("/auth/user/emailpass/reset-password", {
email: "[email protected]",
identifier: "[email protected]",
})

expect(response.status).toEqual(201)
Expand All @@ -156,7 +164,7 @@ medusaIntegrationTestRunner({
it("should fail to generate token for existing user but no provider, but still respond with 201", async () => {
const response = await api.post(
"/auth/user/non-existing-provider/reset-password",
{ email: "[email protected]" }
{ identifier: "[email protected]" }
)

expect(response.status).toEqual(201)
Expand All @@ -165,7 +173,7 @@ medusaIntegrationTestRunner({
it("should fail to generate token for existing user but no provider, but still respond with 201", async () => {
const response = await api.post(
"/auth/user/non-existing-provider/reset-password",
{ email: "[email protected]" }
{ identifier: "[email protected]" }
)

expect(response.status).toEqual(201)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type UseDataGridFormHandlersOptions<TData, TFieldValues extends FieldValues> = {

export const useDataGridFormHandlers = <
TData,
TFieldValues extends FieldValues
TFieldValues extends FieldValues,
>({
matrix,
form,
Expand Down Expand Up @@ -119,7 +119,7 @@ export function convertArrayToPrimitive(
): any[] {
switch (type) {
case "number":
return values.map(convertToNumber)
return values.map((v) => (v === "" ? v : convertToNumber(v)))
case "boolean":
return values.map(convertToBoolean)
case "text":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,29 @@ export function CreateShippingOptionsForm({
const handleSubmit = form.handleSubmit(async (data) => {
const currencyPrices = Object.entries(data.currency_prices)
.map(([code, value]) => {
const amount = value ? castNumber(value) : undefined
if (value === "" || value === undefined) {
return undefined
}

return {
currency_code: code,
amount: amount,
amount: castNumber(value),
}
})
.filter((o) => !!o.amount) as { currency_code: string; amount: number }[]
.filter((o) => !!o) as { currency_code: string; amount: number }[]

const regionPrices = Object.entries(data.region_prices)
.map(([region_id, value]) => {
const amount = value ? castNumber(value) : undefined
if (value === "" || value === undefined) {
return undefined
}

return {
region_id,
amount: amount,
amount: castNumber(value),
}
})
.filter((o) => !!o.amount) as { region_id: string; amount: number }[]
.filter((o) => !!o) as { region_id: string; amount: number }[]

await mutateAsync(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export type PriceListCreateProductsSchema = z.infer<
>

export const PriceListUpdateCurrencyPriceSchema = z.object({
amount: z.string().nullish(),
amount: z.string().or(z.number()).optional(),
id: z.string().nullish(),
})

Expand All @@ -66,7 +66,7 @@ export type PriceListUpdateCurrencyPrice = z.infer<
>

export const PriceListUpdateRegionPriceSchema = z.object({
amount: z.string().nullish(),
amount: z.string().or(z.number()).optional(),
id: z.string().nullish(),
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,13 @@ function convertToPriceArray(
) {
const prices: PriceObject[] = []

const regionCurrencyMap = regions.reduce((map, region) => {
map[region.id] = region.currency_code
return map
}, {} as Record<string, string>)
const regionCurrencyMap = regions.reduce(
(map, region) => {
map[region.id] = region.currency_code
return map
},
{} as Record<string, string>
)

for (const [_productId, product] of Object.entries(data || {})) {
const { variants } = product || {}
Expand All @@ -200,7 +203,10 @@ function convertToPriceArray(
for (const [currencyCode, currencyPrice] of Object.entries(
currencyPrices || {}
)) {
if (currencyPrice?.amount) {
if (
currencyPrice?.amount !== "" &&
typeof currencyPrice?.amount !== "undefined"
) {
prices.push({
variantId,
currencyCode,
Expand All @@ -213,7 +219,10 @@ function convertToPriceArray(
for (const [regionId, regionPrice] of Object.entries(
regionPrices || {}
)) {
if (regionPrice?.amount) {
if (
regionPrice?.amount !== "" &&
typeof regionPrice?.amount !== "undefined"
) {
prices.push({
variantId,
regionId,
Expand All @@ -240,15 +249,21 @@ function comparePrices(initialPrices: PriceObject[], newPrices: PriceObject[]) {
const pricesToCreate: HttpTypes.AdminCreatePriceListPrice[] = []
const pricesToDelete: string[] = []

const initialPriceMap = initialPrices.reduce((map, price) => {
map[createMapKey(price)] = price
return map
}, {} as Record<string, (typeof initialPrices)[0]>)
const initialPriceMap = initialPrices.reduce(
(map, price) => {
map[createMapKey(price)] = price
return map
},
{} as Record<string, (typeof initialPrices)[0]>
)

const newPriceMap = newPrices.reduce((map, price) => {
map[createMapKey(price)] = price
return map
}, {} as Record<string, (typeof newPrices)[0]>)
const newPriceMap = newPrices.reduce(
(map, price) => {
map[createMapKey(price)] = price
return map
},
{} as Record<string, (typeof newPrices)[0]>
)

const keys = new Set([
...Object.keys(initialPriceMap),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ export const CreateProductVariantForm = ({
return {}
}

return regions.reduce((acc, reg) => {
acc[reg.id] = reg.currency_code
return acc
}, {} as Record<string, string>)
return regions.reduce(
(acc, reg) => {
acc[reg.id] = reg.currency_code
return acc
},
{} as Record<string, string>
)
}, [regions])

const isManageInventoryEnabled = useWatch({
Expand Down Expand Up @@ -210,13 +213,13 @@ export const CreateProductVariantForm = ({
options: data.options,
prices: Object.entries(data.prices ?? {})
.map(([currencyOrRegion, value]) => {
const ret: AdminCreateProductVariantPrice = {}
const amount = castNumber(value)

if (isNaN(amount) || value === "") {
if (value === "" || value === undefined) {
return undefined
}

const ret: AdminCreateProductVariantPrice = {}
const amount = castNumber(value)

if (currencyOrRegion.startsWith("reg_")) {
ret.rules = { region_id: currencyOrRegion }
ret.currency_code = regionsCurrencyMap[currencyOrRegion]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export const normalizeVariants = (
.filter(Boolean),
prices: Object.entries(variant.prices || {})
.map(([key, value]: any) => {
if (value === "" || value === undefined) {
return undefined
}

if (key.startsWith("reg_")) {
return {
currency_code: regionsCurrencyMap[key],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ export const PricingEdit = ({
const handleSubmit = form.handleSubmit(async (values) => {
const reqData = values.variants.map((variant, ind) => ({
id: variants[ind].id,
prices: Object.entries(variant.prices || {}).map(
([currencyCodeOrRegionId, value]: any) => {
prices: Object.entries(variant.prices || {})
.filter(
([_, value]) => value !== "" && typeof value !== "undefined" // deleted cells
)
.map(([currencyCodeOrRegionId, value]: any) => {
const regionId = currencyCodeOrRegionId.startsWith("reg_")
? currencyCodeOrRegionId
: undefined
Expand Down Expand Up @@ -105,8 +108,7 @@ export const PricingEdit = ({
amount,
...(regionId ? { rules: { region_id: regionId } } : {}),
}
}
),
}),
}))

await mutateAsync(reqData, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const createLinksStepId = "create-remote-links"
* } from "@medusajs/framework/workflows-sdk"
* import {
* createRemoteLinkStep
* } from "@medusajs/core-flows"
* } from "@medusajs/medusa/core-flows"
* import {
* Modules
* } from "@medusajs/framework/utils"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const dismissRemoteLinkStepId = "dismiss-remote-links"
* } from "@medusajs/framework/workflows-sdk"
* import {
* dismissRemoteLinkStep
* } from "@medusajs/core-flows"
* } from "@medusajs/medusa/core-flows"
* import {
* Modules
* } from "@medusajs/framework/utils"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core-flows/src/common/steps/emit-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const emitEventStepId = "emit-event-step"
* } from "@medusajs/framework/workflows-sdk"
* import {
* emitEventStep
* } from "@medusajs/core-flows"
* } from "@medusajs/medusa/core-flows"
*
* const helloWorldWorkflow = createWorkflow(
* "hello-world",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const removeRemoteLinkStepId = "remove-remote-links"
* } from "@medusajs/framework/workflows-sdk"
* import {
* removeRemoteLinkStep
* } from "@medusajs/core-flows"
* } from "@medusajs/medusa/core-flows"
* import {
* Modules
* } from "@medusajs/framework/utils"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const useRemoteQueryStepId = "use-remote-query"
* } from "@medusajs/framework/workflows-sdk"
* import {
* useRemoteQueryStep
* } from "@medusajs/core-flows"
* } from "@medusajs/medusa/core-flows"
*
* const helloWorldWorkflow = createWorkflow(
* "hello-world",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/framework/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ export type ProjectConfigOptions = {
*
* The configurations for your Medusa application are in `medusa-config.js` located in the root of your Medusa project. The configurations include configurations for database, modules, and more.
*
* `medusa-config.js` exports the value returned by the `defineConfig` utility function imported from `@medusajs/utils`.
* `medusa-config.js` exports the value returned by the `defineConfig` utility function imported from `@medusajs/framework/utils`.
*
* `defineConfig` accepts as a parameter an object with the following properties:
*
Expand Down
4 changes: 2 additions & 2 deletions packages/core/types/src/tax/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export type ItemTaxCalculationLine = {
* ## How to Create a Tax Provider
*
* A tax provider class is defined in a TypeScript or JavaScript file. The class must implement the
* `ITaxProvider` interface imported from `@medusajs/types`.
* `ITaxProvider` interface imported from `@medusajs/framework/types`.
*
* The file can be defined in a plugin, a provider module, or under the `src/services` directory of your Medusa application. You can later pass the package's name or the
* path to the file in the `providers` option of the Tax Module.
*
* For example:
*
* ```ts title="src/services/my-tax.ts"
* import { ITaxProvider } from "@medusajs/types"
* import { ITaxProvider } from "@medusajs/framework/types"
*
* export default class MyTaxProvider implements ITaxProvider {
* // ...
Expand Down
18 changes: 9 additions & 9 deletions packages/core/utils/src/auth/abstract-auth-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
* #### Example
*
* ```ts
* import { AbstractAuthModuleProvider } from "@medusajs/utils"
* import { Logger } from "@medusajs/types"
* import { AbstractAuthModuleProvider } from "@medusajs/framework/utils"
* import { Logger } from "@medusajs/framework/types"
*
* type InjectedDependencies = {
* logger: Logger
Expand Down Expand Up @@ -136,7 +136,7 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
* AuthIdentityProviderService,
* AuthenticationInput,
* AuthenticationResponse
* } from "@medusajs/types"
* } from "@medusajs/framework/types"
* // ...
*
* class MyAuthProviderService extends AbstractAuthModuleProvider {
Expand Down Expand Up @@ -179,7 +179,7 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
* AuthIdentityProviderService,
* AuthenticationInput,
* AuthenticationResponse
* } from "@medusajs/types"
* } from "@medusajs/framework/types"
* // ...
*
* class MyAuthProviderService extends AbstractAuthModuleProvider {
Expand Down Expand Up @@ -238,8 +238,8 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
* AuthIdentityProviderService,
* AuthenticationInput,
* AuthenticationResponse
* } from "@medusajs/types"
* import { MedusaError } from "@medusajs/utils"
* } from "@medusajs/framework/types"
* import { MedusaError } from "@medusajs/framework/utils"
* // ...
*
* class MyAuthProviderService extends AbstractAuthModuleProvider {
Expand Down Expand Up @@ -305,8 +305,8 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
* AuthIdentityProviderService,
* AuthenticationInput,
* AuthenticationResponse
* } from "@medusajs/types"
* import { MedusaError } from "@medusajs/utils"
* } from "@medusajs/framework/types"
* import { MedusaError } from "@medusajs/framework/utils"
* // ...
*
* class MyAuthProviderService extends AbstractAuthModuleProvider {
Expand Down Expand Up @@ -371,7 +371,7 @@ export abstract class AbstractAuthModuleProvider implements IAuthProvider {
* AuthIdentityProviderService,
* AuthenticationInput,
* AuthenticationResponse
* } from "@medusajs/types"
* } from "@medusajs/framework/types"
* // ...
*
* class MyAuthProviderService extends AbstractAuthModuleProvider {
Expand Down
Loading

0 comments on commit c70874b

Please sign in to comment.