Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ae19812
refactor: align template block names to group
kriss145 Feb 14, 2026
a61c365
chore: update docs
kriss145 Feb 14, 2026
11c9b7e
chore: update docs
kriss145 Feb 14, 2026
1443683
Merge pull request #12 from codee-sh/docs/update-docs
kriss145 Feb 14, 2026
a13023d
chore: add chanegset
kriss145 Feb 14, 2026
b4f24d8
Merge pull request #13 from codee-sh/feature/rename-blocks
kriss145 Feb 14, 2026
b23be40
chore: update .gitignore to include additional IDE files
kriss145 Feb 14, 2026
279aacc
Merge pull request #14 from codee-sh/chore/agents-ai
kriss145 Feb 14, 2026
69146e1
docs: remove checklist item about template examples in SKILL.md
kriss145 Feb 23, 2026
5303f02
Add skill mention in changeset
kriss145 Feb 23, 2026
188102e
Merge pull request #15 from codee-sh/chore/update-skills
kriss145 Feb 23, 2026
106498e
refactor: update slack service to handle external templates
kriss145 Feb 26, 2026
9c61367
refactor: modify email service to support external templates
kriss145 Feb 26, 2026
b4b9a73
docs: clarify template ID resolution in README and configuration docu…
kriss145 Feb 26, 2026
5d51ecc
refactor: enhance email service to integrate external templates more …
kriss145 Feb 26, 2026
0f8ca6a
Merge pull request #16 from codee-sh/feat/improve-template-rendering
kriss145 Feb 26, 2026
2a6f504
chore: add create-pr script
kriss145 Feb 26, 2026
132cc21
test: add Medusa integration test setup
kriss145 Feb 26, 2026
1a846a1
docs: add tests guide to documentation and update skills references
kriss145 Feb 26, 2026
0228f56
docs: enhance tests documentation with database setup and cleanup ins…
kriss145 Feb 26, 2026
8ee02f0
chore: add database management scripts for testing in package.json
kriss145 Feb 26, 2026
615c839
docs: update AGENTS.md with new testing commands and shell script des…
kriss145 Feb 26, 2026
f843e6b
Merge pull request #17 from codee-sh/codex/feat/slack-workflow-tests
kriss145 Feb 26, 2026
c285af5
fix: update create-pr script to correctly find markdown changesets us…
kriss145 Feb 26, 2026
f6bd99f
fix: correct backend URL variable in Slack inventory-level template a…
kriss145 Feb 26, 2026
739af9e
refactor: streamline Slack service workflow tests and remove deprecat…
kriss145 Feb 26, 2026
0b15b39
Merge pull request #18 from codee-sh/codex/feat/slack-templates-tests
kriss145 Feb 26, 2026
e22df83
chore: version packages
kriss145 Feb 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .ai/skills/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Agent Skills (Cursor + Codex)

This directory contains project-level skills for AI coding agents.

## Structure

```
.ai/skills/
docs/
SKILL.md
```

## Linking to Cursor and Codex

Use a single source (`.ai/skills`) and symlink it for each tool:

```bash
mkdir -p .cursor .codex
ln -sfn ../.ai/skills .cursor/skills
ln -sfn ../.ai/skills .codex/skills
```
66 changes: 66 additions & 0 deletions .ai/skills/docs/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
name: plugin-docs-authoring
description: Rules for writing and updating plugin documentation. Use when creating new docs pages, updating existing docs (README, docs/*.md), or reviewing documentation changes.
---

## Prerequisites

Read `AGENTS.md` first for terminology, architecture, and template types.
This skill only covers documentation-specific rules.

## File Responsibilities

Each file has a strict scope. Do not mix responsibilities between files.

| File | Scope | Tone |
|------|-------|------|
| `README.md` | High-level overview, install, basic setup, links to docs | Short, navigational |
| `docs/configuration.md` | Plugin options only (`customTranslations`, `extend.services`, `backend_url`) | Technical, example-driven |
| `docs/templates.md` | Template types, resolve/render flow, workflows, API endpoints | Technical reference |
| `docs/blocks.md` | Block types, DB model vs final render model, block catalog | Technical reference |
| `docs/translations.md` | i18n system, interpolation, custom translations, adding locales | Technical reference |
| `docs/admin.md` | Admin panel user guide — what you can do, typical workflow | User-facing, no endpoints |
| `docs/tests.md` | Tests | User-facing, no endpoints |
| `docs/contributing/creating-templates.md` | Step-by-step guide for contributors creating new templates | Tutorial |

## Writing Rules

### Structure

1. Start every page with a one-sentence summary of what the page covers.
2. Use `##` for main sections, `###` for subsections. Do not go deeper than `####`.
3. Put "what the user can do" before technical details.
4. End pages with a `## See Also` section linking to related docs.

### Style

1. Write in English.
2. Use short sentences and short paragraphs.
3. Prefer bullet lists over long prose.
4. Use code blocks for every example — never inline large snippets.
5. Do not use emojis.

### Cross-referencing

1. Do not duplicate content between files — link to the authoritative page.
2. If you remove a page, update all references across docs and README.
3. Keep all internal links relative (`./blocks.md`, `../blocks.md`).

## Checklist (run before finishing)

- [ ] Does the content match the current architecture?
- [ ] Is `docs/admin.md` still non-technical (no raw endpoints)?
- [ ] Is `README.md` still short and navigational?
- [ ] Are there any dead links?
- [ ] Is there duplicated content between files?

## Workflow

When asked to update or create docs:

1. Read this skill first.
2. Identify which files are affected (use the File Responsibilities table).
3. Read the current state of those files.
4. Make changes following the rules above.
5. Run the checklist.
6. Report: list of changed files + short summary of what and why.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ build/
# IDE
.vscode/
.idea/
.cursor/
.codex/
.claude/
*.swp
*.swo
*~
Expand Down
190 changes: 190 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# AGENTS.md

Instructions for AI coding agents working on this repository.

## Project Overview

Medusa plugin for building and sending transactional notifications.
Renders notification content through workflows.
Delivery is handled by Medusa notification providers.

- Package: `@codee-sh/medusa-plugin-notification-emails`
- Medusa: `>= 2.8.8`
- Node.js: `>= 20`
- Package manager: `yarn` (v3, see `.yarnrc.yml`)

## Scripts

```bash
yarn install # install dependencies
yarn build # build plugin (medusa plugin:build)
yarn dev # develop plugin (medusa plugin:develop)
yarn prepublishOnly # build before publish (medusa plugin:build)
yarn publish-local # publish locally (npx medusa plugin:publish)
yarn publish-package # publish to npm (dotenv npm publish --access public)
yarn email:dev # preview email templates (react-email dev server)
yarn test:unit # run unit tests
yarn test:integration:http # run integration HTTP tests
yarn test:integration:modules # run integration module tests
yarn test:db:up # start test Postgres (Docker)
yarn test:db:down # stop and remove test Postgres (Docker)
```

## Shell Scripts

Daily workflow helpers in `scripts/`:

- `scripts/create-pr.sh` — create a PR (used by `yarn pr:create`).
- `scripts/prepare-release.sh` — prepare a release branch (used by `yarn prepare-release`).

## Code Style

- Prettier: 60-char print width, no semicolons, double quotes, trailing commas (es5)
- Config: `.prettierrc`
- TypeScript: ES2021, Node16 modules, strict null checks, decorators enabled
- Config: `tsconfig.json`

## Branch Model

- `main` — release-ready, every commit is tagged and deployable
- `develop` — nightly builds and upcoming release work
- Topic branches: `feat/<name>`, `fix/<name>`, `chore/<name>`, `docs/<name>`
- PRs target `develop` by default
- Hotfixes branch from `main`, merge back to `main` and `develop`

## Versioning and Release

- Uses [Changesets](https://github.com/changesets/changesets) for version management
- Add changeset: `yarn changeset`
- Version bump: `yarn changeset version`
- Release: merge release branch to `main`, tag is created automatically
- CI: GitHub Actions for PR labeling and release-on-merge

## Architecture

### High-Level Flow

```
Event (e.g. order.placed)
→ Subscriber
→ Rendering Workflow (emailServiceWorkflow / slackServiceWorkflow)
→ Template resolve (system / db / external)
→ Block interpolation ({{data.*}}, {{translations.*}})
→ Channel-specific render (HTML for email, Block Kit for Slack)
→ Medusa Notification Module (delivery)
```

### Source Tree

```
src/
├── admin/ # Admin panel UI (React, builder, routes, widgets)
├── api/ # Admin API routes (/api/admin/mpn/...)
├── hooks/ # React hooks for API calls
├── modules/
│ └── mpn-builder/ # Core module: models, services, migrations
├── subscribers/ # Medusa event subscribers (order-placed, order-completed)
├── templates/
│ ├── emails/ # Email templates (system) + React Email block components
│ ├── slack/ # Slack templates (system) + Block Kit format
│ └── shared/ # Shared template utilities, theme, abstract services
├── utils/ # Helpers: i18n, transforms, data modules, DnD
└── workflows/
├── mpn-builder/ # Template CRUD workflows
├── mpn-builder-services/ # Rendering workflows (email-service, slack-service)
├── order/ # Order data workflows
├── region/ # Region data workflows
└── store/ # Store data workflows
```

### Key Modules

| Module | Path | Purpose |
|--------|------|---------|
| `mpn-builder` | `src/modules/mpn-builder/` | Core: DB models, template services, migrations |
| Email service | `src/modules/mpn-builder/services-local/email-template-service.ts` | System email templates + block schema definitions |
| Slack service | `src/modules/mpn-builder/services-local/slack-template-service.ts` | System Slack templates + block schema definitions |
| Email workflows | `src/workflows/mpn-builder-services/email-service.ts` | `emailServiceWorkflow` — render email templates |
| Slack workflows | `src/workflows/mpn-builder-services/slack-service.ts` | `slackServiceWorkflow` — render Slack templates |

### Template Types

| Type | Prefix | Source | Editable in Admin |
|------|--------|--------|-------------------|
| `system` | `system_*` | Code (`src/templates/`) | No (read-only) |
| `db` | (any other ID) | Database via Admin builder | Yes |
| `external` | `external_*` | External packages via config | No |

### Template Resolution

- `template_id` starting with `system_` → code registry
- Other IDs → DB lookup
- `external` templates available in service registry when registered in plugin config

### Blocks

- DB model is channel-agnostic: `type`, `position`, `parent_id`, `metadata`
- Final render is channel-specific (email → React Email HTML, Slack → Block Kit JSON)
- Email block types: `section`, `heading`, `text`, `row`, `separator`, `group`, `repeater`, `product-item`
- Slack block types: `header`, `section`, `actions`, `divider` (Block Kit standard)

### Interpolation

Two-prefix system processed recursively:
- `{{data.*}}` — values from template input data
- `{{translations.*}}` — values from translation dictionaries (system/external templates)

For `db` templates: use `{{data.*}}` and literal text in block `metadata`.
Do not rely on `{{translations.*}}`.

### i18n

- Translation files: JSON with `general` wrapper, auto-flattened
- Location: `src/templates/<channel>/<template>/translations/`
- Custom overrides via plugin config (`customTranslations`) or per-render `options.translations`

## Admin API Endpoints

| Method | Endpoint | Purpose |
|--------|----------|---------|
| GET | `/api/admin/mpn/templates` | List DB templates |
| POST | `/api/admin/mpn/templates` | Create DB template |
| GET | `/api/admin/mpn/templates/:id/blocks` | Get template blocks |
| POST | `/api/admin/mpn/templates/:id/blocks` | Save template blocks |
| GET | `/api/admin/mpn/templates/types` | List template types |
| GET | `/api/admin/mpn/templates/types/:type/services` | Services by type |
| GET | `/api/admin/mpn/templates/types/:type/services/:service/templates` | Templates by type+service |
| GET | `/api/admin/mpn/available-templates` | Template services and builder metadata |
| GET | `/api/admin/mpn/notifications` | Notification history |
| GET | `/api/admin/mpn/events` | Available events |
| POST | `/api/admin/mpn/render-template` | Render template preview |


## Documentation

- `README.md` — overview, install, basic setup
- `docs/configuration.md` — plugin options
- `docs/templates.md` — template types, workflows, API
- `docs/blocks.md` — block system, DB model, final catalog
- `docs/translations.md` — i18n system, interpolation
- `docs/admin.md` — admin panel user guide
- `docs/tests.md` — tests guide
- `docs/contributing/creating-templates.md` — contributor template guide
- `CONTRIBUTING.md` — branch model, PR rules, release process

## AI Skills

Project skills are in `.ai/skills/` (symlinked to `.cursor/skills/` and `.codex/skills/`).

| Skill | When to use |
|-------|-------------|
| `docs` | Writing or updating documentation |

## Rules for Agents

1. Always run `yarn format` before committing.
2. Follow the branch model: feature work from `develop`, PRs to `develop`.
3. Add a changeset (`yarn changeset`) for any user-facing change.
4. Use consistent terminology: `system`, `db`, `external`, `blocks`, `mpn-builder`, `workflow`.
5. When changing docs, follow the `docs` skill.
6. Do not commit `.env`, `node_modules`, `.medusa/`, or build artifacts.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @codee-sh/medusa-plugin-notification-emails

## 1.0.1

### Patch Changes

- 132cc21: Add Medusa integration test setup and local Docker DB config for workflow testing.
- 5303f02: Add skils
- 5d51ecc: Fix external template rendering for Slack and Email workflows by treating `external_*` IDs as registry templates instead of DB templates. Update docs to clarify template ID resolution.
- a13023d: Rename blocks type

## 1.0.0

### Major Changes
Expand Down
Loading