Skip to content

Commit

Permalink
Merge branch 'develop' into fix/location-ui-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fPolic authored May 13, 2024
2 parents f50bb34 + 3e3b8a4 commit 6057138
Show file tree
Hide file tree
Showing 147 changed files with 3,419 additions and 232 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-timers-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

chore(medusa): cleanup admin function
5 changes: 5 additions & 0 deletions .changeset/happy-mirrors-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

chore(medusa): strict zod versions in workspace
5 changes: 5 additions & 0 deletions .changeset/itchy-forks-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): Missing middlewares export
8 changes: 8 additions & 0 deletions .changeset/moody-days-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@medusajs/modules-sdk": minor
"@medusajs/types": minor
"@medusajs/utils": minor
"@medusajs/notification": patch
---

Add basic implementation of a notification module
5 changes: 5 additions & 0 deletions .changeset/old-candles-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---

chore(utils): Provide a mikro orm base entity
7 changes: 7 additions & 0 deletions .changeset/perfect-fishes-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@medusajs/notification-sendgrid": patch
"@medusajs/notification-logger": patch
"@medusajs/types": patch
---

Add sendgrid and logger notification providers
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'type: docs':
- changed-files:
- any-glob-to-any-file: www/**
13 changes: 13 additions & 0 deletions .github/workflows/docs-pr-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Add Docs PR Label"
on:
pull_request:

jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- id: label-the-PR
uses: actions/labeler@v5
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import {
CreateNotificationDTO,
INotificationModuleService,
Logger,
} from "@medusajs/types"
import { ContainerRegistrationKeys } from "@medusajs/utils"
import { medusaIntegrationTestRunner } from "medusa-test-utils"

jest.setTimeout(50000)

const env = { MEDUSA_FF_MEDUSA_V2: true }
medusaIntegrationTestRunner({
env,
testSuite: ({ getContainer }) => {
describe("Notification module", () => {
let service: INotificationModuleService
let logger: Logger

beforeAll(async () => {
service = getContainer().resolve(ModuleRegistrationName.NOTIFICATION)
logger = getContainer().resolve(ContainerRegistrationKeys.LOGGER)
})

afterEach(() => {
jest.restoreAllMocks()
})

it("should successfully send a notification for an available channel", async () => {
const logSpy = jest.spyOn(logger, "info")
const notification = {
to: "[email protected]",
channel: "email",
template: "order-created",
data: { username: "john-doe" },
trigger_type: "order-created",
resource_id: "order-id",
resource_type: "order",
} as CreateNotificationDTO

const result = await service.create(notification)
const fromDB = await service.retrieve(result.id)

expect(result).toEqual(
expect.objectContaining({
id: expect.any(String),
to: "[email protected]",
provider_id: "local-notification-provider",
})
)

delete fromDB.original_notification_id
delete fromDB.external_id
delete fromDB.receiver_id
delete (fromDB as any).idempotency_key
delete (fromDB as any).provider

expect(result).toEqual(fromDB)
expect(logSpy).toHaveBeenCalledWith(
'Attempting to send a notification to: [email protected] on the channel: email with template: order-created and data: {"username":"john-doe"}'
)
})

it("should throw an exception if there is no provider for the channel", async () => {
const notification = {
to: "[email protected]",
channel: "sms",
} as CreateNotificationDTO

const error = await service.create(notification).catch((e) => e)
expect(error.message).toEqual(
"Could not find a notification provider for channel: sms"
)
})

it("should allow listing all notifications with filters", async () => {
const notification1 = {
to: "[email protected]",
channel: "email",
template: "order-created",
} as CreateNotificationDTO

const notification2 = {
to: "[email protected]",
channel: "log",
template: "product-created",
} as CreateNotificationDTO

await service.create([notification1, notification2])

const notifications = await service.list({ channel: "log" })
expect(notifications).toHaveLength(1)
expect(notifications[0]).toEqual(
expect.objectContaining({
to: "[email protected]",
channel: "log",
template: "product-created",
})
)
})

it("should allow retrieving a notification", async () => {
const notification1 = {
to: "[email protected]",
channel: "email",
template: "order-created",
} as CreateNotificationDTO

const notification2 = {
to: "[email protected]",
channel: "log",
template: "product-created",
} as CreateNotificationDTO

const [first] = await service.create([notification1, notification2])

const notification = await service.retrieve(first.id)
expect(notification).toEqual(
expect.objectContaining({
to: "[email protected]",
channel: "email",
template: "order-created",
})
)
})
})
},
})
18 changes: 18 additions & 0 deletions integration-tests/modules/medusa-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,23 @@ module.exports = {
providers: [customFulfillmentProvider],
},
},
[Modules.NOTIFICATION]: {
/** @type {import('@medusajs/types').LocalNotificationServiceOptions} */
options: {
providers: [
{
resolve: "@medusajs/notification-local",
options: {
config: {
"local-notification-provider": {
name: "Local Notification Provider",
channels: ["log", "email"],
},
},
},
},
],
},
},
},
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
"test:integration:packages": "turbo run test:integration --concurrency=50% --no-daemon --no-cache --force --filter='./packages/*' --filter='./packages/core/*' --filter='./packages/cli/*' --filter='./packages/modules/*' --filter='./packages/modules/providers/*'",
"test:integration:api": "turbo run test:integration:chunk --concurrency=50% --no-daemon --no-cache --force --filter=integration-tests-api",
"test:integration:modules": "turbo run test:integration:chunk --concurrency=50% --no-daemon --no-cache --force --filter=integration-tests-modules",
"openapi:generate": "yarn ./packages/oas/oas-github-ci run ci --with-full-file --v2",
"medusa-oas": "yarn ./packages/oas/medusa-oas-cli run medusa-oas --v2",
"openapi:generate": "yarn ./packages/cli/oas/oas-github-ci run ci --with-full-file --v2",
"medusa-oas": "yarn ./packages/cli/oas/medusa-oas-cli run medusa-oas --v2",
"release:snapshot": "changeset publish --no-git-tags --snapshot --tag snapshot",
"release:next": "chgstangeset publish --no-git-tags --snapshot --tag next",
"version:next": "changeset version --snapshot next",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,16 @@
}
}
},
"promotions": {
"remove": {
"title": "Remove promotion from campaign",
"description": "You are about to remove {{count}} promotion(s) from the campaign. This action cannot be undone."
},
"alreadyAdded": "This promotion has already been added to the campaign.",
"toast": {
"success": "Successfully added {{count}} promotion(s) to campaign"
}
},
"deleteCampaignWarning": "You are about to delete the campaign {{name}}. This action cannot be undone.",
"totalSpend": "<0>{{amount}}</0> <1>{{currency}}</1>"
},
Expand Down
22 changes: 20 additions & 2 deletions packages/admin-next/dashboard/src/hooks/api/campaigns.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
AdminCampaignListResponse,
AdminCampaignResponse,
LinkMethodRequest,
} from "@medusajs/types"
import {
QueryKey,
Expand All @@ -14,6 +15,7 @@ import { queryClient } from "../../lib/medusa"
import { queryKeysFactory } from "../../lib/query-key-factory"
import { CreateCampaignReq, UpdateCampaignReq } from "../../types/api-payloads"
import { CampaignDeleteRes } from "../../types/api-responses"
import { promotionsQueryKeys } from "./promotions"

const REGIONS_QUERY_KEY = "campaigns" as const
export const campaignsQueryKeys = queryKeysFactory(REGIONS_QUERY_KEY)
Expand Down Expand Up @@ -82,7 +84,7 @@ export const useUpdateCampaign = (
mutationFn: (payload) => client.campaigns.update(id, payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.detail(id) })
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })

options?.onSuccess?.(data, variables, context)
},
Expand All @@ -98,10 +100,26 @@ export const useDeleteCampaign = (
mutationFn: () => client.campaigns.delete(id),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.lists() })
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.detail(id) })
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })

options?.onSuccess?.(data, variables, context)
},
...options,
})
}

export const useAddOrRemoveCampaignPromotions = (
id: string,
options?: UseMutationOptions<AdminCampaignResponse, Error, LinkMethodRequest>
) => {
return useMutation({
mutationFn: (payload) =>
client.campaigns.addOrRemovePromotions(id, payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({ queryKey: campaignsQueryKeys.details() })
queryClient.invalidateQueries({ queryKey: promotionsQueryKeys.lists() })
options?.onSuccess?.(data, variables, context)
},
...options,
})
}
12 changes: 12 additions & 0 deletions packages/admin-next/dashboard/src/lib/client/campaigns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AdminCampaignListResponse,
AdminCampaignResponse,
CreateCampaignDTO,
LinkMethodRequest,
UpdateCampaignDTO,
} from "@medusajs/types"
import { CampaignDeleteRes } from "../../types/api-responses"
Expand All @@ -27,10 +28,21 @@ async function deleteCampaign(id: string) {
return deleteRequest<CampaignDeleteRes>(`/admin/campaigns/${id}`)
}

async function addOrRemoveCampaignPromotions(
id: string,
payload: LinkMethodRequest
) {
return postRequest<AdminCampaignResponse>(
`/admin/campaigns/${id}/promotions`,
payload
)
}

export const campaigns = {
retrieve: retrieveCampaign,
list: listCampaigns,
create: createCampaign,
update: updateCampaign,
delete: deleteCampaign,
addOrRemovePromotions: addOrRemoveCampaignPromotions,
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ export const RouteMap: RouteObject[] = [
lazy: () =>
import("../../v2-routes/campaigns/campaign-budget-edit"),
},
{
path: "add-promotions",
lazy: () =>
import(
"../../v2-routes/campaigns/add-campaign-promotions"
),
},
],
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useParams } from "react-router-dom"
import { RouteFocusModal } from "../../../components/route-modal"
import { useCampaign } from "../../../hooks/api/campaigns"
import { AddCampaignPromotionsForm } from "./components"

export const AddCampaignPromotions = () => {
const { id } = useParams()
const { campaign, isError, error } = useCampaign(id!)

if (isError) {
throw error
}

return (
<RouteFocusModal>
{campaign && <AddCampaignPromotionsForm campaign={campaign} />}
</RouteFocusModal>
)
}
Loading

0 comments on commit 6057138

Please sign in to comment.