> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mercurjs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Approve, suspend, and terminate stores

> Move stores through their lifecycle from server code, extend each transition with a hook, and react to the events.

Drive a store through its lifecycle from your own server code, for example to auto-approve vetted sellers or to suspend a store when a risk check fails. Each transition is a workflow that validates the current status, writes the change, emits an event, and exposes a hook.

## Moderate a store

**1. Approve a pending store**

`approveSellerWorkflow` moves a `pending_approval` store to `open` and stamps `approved_at`.

```ts title="src/api/admin/stores/[id]/vet/route.ts" theme={null}
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { approveSellerWorkflow } from "@mercurjs/core/workflows"

export async function POST(req: MedusaRequest, res: MedusaResponse) {
  await approveSellerWorkflow(req.scope).run({
    input: { seller_id: req.params.id },
  })

  res.sendStatus(200)
}
```

**2. Suspend and reinstate a store**

`suspendSellerWorkflow` takes an optional `reason`, which it saves in `status_reason`. `unsuspendSellerWorkflow` reopens the store and clears the reason.

```ts theme={null}
import {
  suspendSellerWorkflow,
  unsuspendSellerWorkflow,
} from "@mercurjs/core/workflows"

await suspendSellerWorkflow(container).run({
  input: { seller_id: "sel_01JD8Q1234567", reason: "Chargeback review" },
})

await unsuspendSellerWorkflow(container).run({
  input: { seller_id: "sel_01JD8Q1234567" },
})
```

**3. Terminate a store**

`terminateSellerWorkflow` accepts a `pending_approval` or `suspended` store. Suspend an `open` store first.

```ts theme={null}
import { terminateSellerWorkflow } from "@mercurjs/core/workflows"

await terminateSellerWorkflow(container).run({
  input: { seller_id: "sel_01JD8Q1234567", reason: "Policy breach" },
})
```

To undo it, run `unterminateSellerWorkflow`. It returns the store to `suspended`, and you reopen it with `unsuspendSellerWorkflow`.

## Reject a pending application

Mercur has no separate reject workflow. Run `suspendSellerWorkflow` on the `pending_approval` store with a `reason`: it stamps `rejected_at` and keeps the store out of the Store API. Terminate it afterwards if the decision is final.

## Handle a failed transition

Each workflow checks the starting status and fails with a `NOT_ALLOWED` error when the transition isn’t allowed. Nothing is written in that case. Pass `throwOnError: false` to read the error instead of catching it.

```ts theme={null}
import { MedusaError } from "@medusajs/framework/utils"
import { terminateSellerWorkflow } from "@mercurjs/core/workflows"

const { errors } = await terminateSellerWorkflow(container).run({
  input: { seller_id: "sel_01JD8Q1234567" },
  throwOnError: false,
})

const notAllowed = errors.some(
  ({ error }) => error.type === MedusaError.Types.NOT_ALLOWED
)
```

An `open` store makes `notAllowed` true here, with the message “Cannot terminate an open seller. Suspend or close first.”

The workflow also fails when the seller id doesn’t exist, because its lookup step runs with `throwIfKeyNotFound`.

## Extend a transition with a hook

Each lifecycle workflow exposes a hook that receives `seller_id` and `additional_data`. Register a handler to run your own step inside the transition.

```ts title="src/workflows/hooks/seller-approved.ts" theme={null}
import { approveSellerWorkflow } from "@mercurjs/core/workflows"

approveSellerWorkflow.hooks.sellerApproved(
  async ({ seller_id }, { container }) => {
    const logger = container.resolve("logger")
    logger.info(`Store ${seller_id} approved`)
  }
)
```

The other hooks follow the same shape: `sellerSuspended`, `sellerUnsuspended`, `sellerTerminated`, and `sellerUnterminated`.

## Run side effects from a subscriber

Subscribe to the lifecycle events for work that shouldn’t block the transition, such as emails. Each event carries `{ id }`, the seller id.

```ts title="src/subscribers/store-suspended.ts" theme={null}
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"

export default async function storeSuspended({
  event,
  container,
}: SubscriberArgs<{ id: string }>) {
  const logger = container.resolve("logger")
  logger.info(`Store ${event.data.id} suspended`)
}

export const config: SubscriberConfig = {
  event: "seller.suspended",
}
```

## Next steps

* [Store statuses and transitions](https://docs.mercurjs.com/platform/store/concepts/lifecycle.md)
* [Event reference](https://docs.mercurjs.com/platform/store/reference/events.md)
* [Workflows reference](https://docs.mercurjs.com/platform/store/reference/workflows.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.