Skip to content

Commit

Permalink
Merge branch 'develop' into chore/job-sub-loader-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p authored Mar 4, 2025
2 parents f4c763a + c2e24b6 commit c95d08a
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .changeset/thick-readers-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/order": patch
"@medusajs/core-flows": patch
---

fix(order): summary raw totals
33 changes: 15 additions & 18 deletions packages/core/core-flows/src/payment/workflows/refund-payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export type ValidateRefundStepInput = {
/**
* This step validates that the refund is valid for the order.
* If the order does not have an outstanding balance to refund, the step throws an error.
*
*
* :::note
*
*
* You can retrieve an order or payment's details using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query),
* or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep).
*
*
* :::
*
*
* @example
* const data = validateRefundStep({
* order: {
Expand All @@ -56,12 +56,11 @@ export type ValidateRefundStepInput = {
*/
export const validateRefundStep = createStep(
"validate-refund-step",
async function ({
order,
payment,
amount,
}: ValidateRefundStepInput) {
const pendingDifference = order.summary?.raw_pending_difference!
async function ({ order, payment, amount }: ValidateRefundStepInput) {
const pendingDifference =
order.summary?.raw_pending_difference! ??
order.summary?.pending_difference! ??
0

if (MathBN.gte(pendingDifference, 0)) {
throw new MedusaError(
Expand Down Expand Up @@ -102,29 +101,27 @@ export type RefundPaymentWorkflowInput = {

export const refundPaymentWorkflowId = "refund-payment-workflow"
/**
* This workflow refunds a payment. It's used by the
* This workflow refunds a payment. It's used by the
* [Refund Payment Admin API Route](https://docs.medusajs.com/api/admin#payments_postpaymentsidrefund).
*
*
* You can use this workflow within your own customizations or custom workflows, allowing you
* to refund a payment in your custom flows.
*
*
* @example
* const { result } = await refundPaymentWorkflow(container)
* .run({
* input: {
* payment_id: "payment_123",
* }
* })
*
*
* @summary
*
*
* Refund a payment.
*/
export const refundPaymentWorkflow = createWorkflow(
refundPaymentWorkflowId,
(
input: WorkflowData<RefundPaymentWorkflowInput>
) => {
(input: WorkflowData<RefundPaymentWorkflowInput>) => {
const payment = useRemoteQueryStep({
entry_point: "payment",
fields: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
WorkflowData,
WorkflowResponse,
createHook,
createWorkflow,
} from "@medusajs/framework/workflows-sdk"

Expand Down Expand Up @@ -44,6 +45,14 @@ export const createStockLocationsWorkflowId = "create-stock-locations-workflow"
export const createStockLocationsWorkflow = createWorkflow(
createStockLocationsWorkflowId,
(input: WorkflowData<CreateStockLocationsWorkflowInput>) => {
return new WorkflowResponse(createStockLocations(input.locations))
const stockLocations = createStockLocations(input.locations)

const stockLocationsCreated = createHook("stockLocationsCreated", {
stockLocations,
})

return new WorkflowResponse(stockLocations, {
hooks: [stockLocationsCreated],
})
}
)
7 changes: 5 additions & 2 deletions packages/modules/order/src/utils/apply-order-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,17 @@ export async function applyChangesToOrder(
}

const orderSummary = order.summary
summariesToUpsert.push({
const upsertSummary = {
id: orderSummary?.version === version ? orderSummary.id : undefined,
order_id: order.id,
version,
totals: calculated.getSummaryFromOrder(
calculated.order as unknown as OrderDTO
),
})
}

createRawPropertiesFromBigNumber(upsertSummary)
summariesToUpsert.push(upsertSummary)

if (Object.keys(orderAttributes).length > 0) {
orderToUpdate.push({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useBaseSpecs } from "@/providers/base-specs"
import type { OpenAPIV3 } from "openapi-types"
import { Card } from "docs-ui"
import { useMemo } from "react"

export type TagsOperationDescriptionSectionSecurityProps = {
security: OpenAPIV3.SecurityRequirementObject[]
Expand All @@ -11,6 +12,15 @@ const TagsOperationDescriptionSectionSecurity = ({
}: TagsOperationDescriptionSectionSecurityProps) => {
const { getSecuritySchema } = useBaseSpecs()

const linkToAuth = useMemo(() => {
const hasNoAuth = security.some((item) => {
const schema = getSecuritySchema(Object.keys(item)[0])
return schema && schema["x-is-auth"] === false
})

return !hasNoAuth
}, [security, getSecuritySchema])

const getDescription = () => {
let str = ""
security.forEach((item) => {
Expand All @@ -27,7 +37,7 @@ const TagsOperationDescriptionSectionSecurity = ({
<Card
title="Authorization"
text={getDescription()}
href="#authentication"
href={linkToAuth ? "#authentication" : undefined}
/>
</div>
)
Expand Down
1 change: 1 addition & 0 deletions www/apps/api-reference/types/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export type PropertiesObject = {

export type SecuritySchemeObject = OpenAPIV3.SecuritySchemeObject & {
"x-displayName"?: string
"x-is-auth"?: boolean
}

export type Parameter = OpenAPIV3.ParameterObject & {
Expand Down
5 changes: 5 additions & 0 deletions www/utils/generated/oas-output/base/admin.oas.base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -749,3 +749,8 @@ components:
in: cookie
name: connect.sid
x-displayName: Cookie Session ID
reset_password:
type: http
x-displayName: Reset Password Token
scheme: bearer
x-is-auth: false
5 changes: 5 additions & 0 deletions www/utils/generated/oas-output/base/store.oas.base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,8 @@ components:
x-displayName: Cookie Session ID
in: cookie
name: connect.sid
reset_password:
type: http
x-displayName: Reset Password Token
scheme: bearer
x-is-auth: false
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* operationId: PostActor_typeAuth_providerUpdate
* summary: Reset an Admin User's Password
* x-sidebar-summary: Reset Password
* description: Reset an admin user's password using a reset-password token generated with the [Generate Reset Password Token API route](https://docs.medusajs.com/api/admin#auth_postactor_typeauth_providerresetpassword).
* description: Reset an admin user's password using a reset-password token generated with the [Generate Reset Password Token API route](https://docs.medusajs.com/api/admin#auth_postactor_typeauth_providerresetpassword). You pass the token as a bearer token in the request's Authorization header.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/commerce-modules/auth/authentication-route#reset-password-route
* description: Learn more about this API route.
* x-authenticated: false
* x-authenticated: true
* parameters:
* - name: auth_provider
* in: path
Expand All @@ -16,12 +16,6 @@
* schema:
* type: string
* example: "emailpass"
* - name: token
* in: query
* description: The reset password token received using the Get Reset Password API route.
* required: true
* schema:
* type: string
* requestBody:
* content:
* application/json:
Expand All @@ -36,12 +30,15 @@
* - lang: Shell
* label: cURL
* source: |-
* curl -X POST '{backend_url}/auth/user/emailpass/update?token=123' \
* curl -X POST '{backend_url}/auth/user/emailpass/update' \
* -H 'Content-Type: application/json' \
* -H 'Authorization: Bearer {token}' \
* --data-raw '{
* "email": "admin@medusa-test.com",
* "password": "supersecret"
* }'
* security:
* - reset_password: []
* tags:
* - Auth
* responses:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* operationId: PostActor_typeAuth_providerUpdate
* summary: Reset a Customer's Password
* x-sidebar-summary: Reset Password
* description: Reset a customer's password using a reset-password token generated with the [Generate Reset Password Token API route](https://docs.medusajs.com/api/store#auth_postactor_typeauth_providerresetpassword).
* description: Reset a customer's password using a reset-password token generated with the [Generate Reset Password Token API route](https://docs.medusajs.com/api/store#auth_postactor_typeauth_providerresetpassword). You pass the token as a bearer token in the request's Authorization header.
* externalDocs:
* url: https://docs.medusajs.com/v2/resources/storefront-development/customers/reset-password#2-reset-password-page
* description: "Storefront development: How to create the reset password page."
* x-authenticated: false
* x-authenticated: true
* parameters:
* - name: auth_provider
* in: path
Expand All @@ -16,12 +16,6 @@
* schema:
* type: string
* example: "emailpass"
* - name: token
* in: query
* description: The reset password token received using the Get Reset Password API route.
* required: true
* schema:
* type: string
* requestBody:
* content:
* application/json:
Expand All @@ -36,12 +30,15 @@
* - lang: Shell
* label: cURL
* source: |-
* curl -X POST '{backend_url}/auth/customer/emailpass/update?token=123' \
* curl -X POST '{backend_url}/auth/customer/emailpass/update' \
* -H 'Content-Type: application/json' \
* -H 'Authorization: Bearer {token}' \
* --data-raw '{
* "email": "customer@gmail.com",
* "password": "supersecret"
* }'
* security:
* - reset_password: []
* tags:
* - Auth
* responses:
Expand Down

0 comments on commit c95d08a

Please sign in to comment.