@thorprovider/create-storefront 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -0
- package/bin/install.js +116 -0
- package/commands/sf-add-view.md +21 -0
- package/commands/sf-init.md +16 -0
- package/commands/sf-theme.md +15 -0
- package/commands/sf-view.md +20 -0
- package/package.json +40 -0
- package/recipes/archetype.schema.json +39 -0
- package/recipes/archetypes.json +148 -0
- package/recipes/recipe.schema.json +59 -0
- package/recipes/recipes.json +90 -0
- package/recipes/sections.json +46 -0
- package/recipes/validate.mjs +190 -0
- package/skills/building-storefronts/SKILL.md +178 -0
- package/skills/building-storefronts/references/frontend-integration.md +229 -0
- package/skills/json-render-core/SKILL.md +291 -0
- package/skills/json-render-next/SKILL.md +194 -0
- package/skills/json-render-react/SKILL.md +298 -0
- package/skills/json-render-remotion/SKILL.md +111 -0
- package/skills/json-render-shadcn/SKILL.md +159 -0
- package/skills/json-render-solid/SKILL.md +204 -0
- package/skills/nextjs-shadcn/SKILL.md +303 -0
- package/skills/nextjs-shadcn/references/architecture.md +499 -0
- package/skills/nextjs-shadcn/references/project-setup.md +127 -0
- package/skills/nextjs-shadcn/references/shadcn-platform.md +258 -0
- package/skills/nextjs-shadcn/references/sidebar.md +274 -0
- package/skills/nextjs-shadcn/references/styling.md +555 -0
- package/skills/sf-scaffold/SKILL.md +118 -0
- package/skills/sf-theme-gen/SKILL.md +44 -0
- package/skills/sf-view-gen/SKILL.md +94 -0
- package/skills/shadcn-component-discovery/SKILL.md +273 -0
- package/skills/shadcn-component-discovery/references/registries.md +226 -0
- package/skills/shadcn-theming/SKILL.md +104 -0
- package/skills/shadcn-theming/references/templates/theme-setup.md +109 -0
- package/skills/shadcn-theming/references/theming-guide.md +90 -0
- package/skills/storefront-best-practices/SKILL.md +421 -0
- package/skills/storefront-best-practices/reference/components/breadcrumbs.md +123 -0
- package/skills/storefront-best-practices/reference/components/cart-popup.md +189 -0
- package/skills/storefront-best-practices/reference/components/country-selector.md +298 -0
- package/skills/storefront-best-practices/reference/components/footer.md +112 -0
- package/skills/storefront-best-practices/reference/components/hero.md +241 -0
- package/skills/storefront-best-practices/reference/components/megamenu.md +239 -0
- package/skills/storefront-best-practices/reference/components/navbar.md +397 -0
- package/skills/storefront-best-practices/reference/components/popups.md +221 -0
- package/skills/storefront-best-practices/reference/components/product-card.md +125 -0
- package/skills/storefront-best-practices/reference/components/product-reviews.md +217 -0
- package/skills/storefront-best-practices/reference/components/product-slider.md +174 -0
- package/skills/storefront-best-practices/reference/components/search.md +101 -0
- package/skills/storefront-best-practices/reference/connecting-to-backend.md +391 -0
- package/skills/storefront-best-practices/reference/design.md +388 -0
- package/skills/storefront-best-practices/reference/features/promotions.md +307 -0
- package/skills/storefront-best-practices/reference/features/wishlist.md +230 -0
- package/skills/storefront-best-practices/reference/layouts/account.md +380 -0
- package/skills/storefront-best-practices/reference/layouts/cart.md +316 -0
- package/skills/storefront-best-practices/reference/layouts/checkout.md +486 -0
- package/skills/storefront-best-practices/reference/layouts/home-page.md +264 -0
- package/skills/storefront-best-practices/reference/layouts/order-confirmation.md +231 -0
- package/skills/storefront-best-practices/reference/layouts/product-details.md +527 -0
- package/skills/storefront-best-practices/reference/layouts/product-listing.md +520 -0
- package/skills/storefront-best-practices/reference/layouts/static-pages.md +356 -0
- package/skills/storefront-best-practices/reference/medusa.md +307 -0
- package/skills/storefront-best-practices/reference/mobile-responsiveness.md +183 -0
- package/skills/storefront-best-practices/reference/seo.md +195 -0
- package/templates/app/app/[[...slug]]/page.tsx +17 -0
- package/templates/app/app/[[...slug]]/renderer.tsx +10 -0
- package/templates/app/app/globals.css +101 -0
- package/templates/app/app/layout.tsx +35 -0
- package/templates/app/lib/__STOREFRONT__/catalog.ts +132 -0
- package/templates/app/lib/__STOREFRONT__/handlers.ts +33 -0
- package/templates/app/lib/__STOREFRONT__/registry.tsx +134 -0
- package/templates/app/lib/__STOREFRONT__/runtime.ts +25 -0
- package/templates/app/lib/__STOREFRONT__/spec/home.ts +62 -0
- package/templates/app/lib/__STOREFRONT__/spec/index.ts +59 -0
- package/templates/app/lib/__STOREFRONT__/spec/types.ts +14 -0
- package/templates/app/lib/__STOREFRONT__/state.ts +35 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
# Static Pages
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- [Overview](#overview)
|
|
6
|
+
- [FAQ Page](#faq-page)
|
|
7
|
+
- [About Page](#about-page)
|
|
8
|
+
- [Contact Page](#contact-page)
|
|
9
|
+
- [Shipping and Returns](#shipping-and-returns)
|
|
10
|
+
- [Privacy Policy and Terms](#privacy-policy-and-terms)
|
|
11
|
+
- [Size Guide](#size-guide)
|
|
12
|
+
- [Mobile and SEO](#mobile-and-seo)
|
|
13
|
+
- [Checklist](#checklist)
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
Static pages provide essential information about the store, policies, and customer support. Purpose: Build trust, reduce support inquiries, meet legal requirements, improve SEO.
|
|
18
|
+
|
|
19
|
+
### Essential Static Pages
|
|
20
|
+
|
|
21
|
+
**Required:**
|
|
22
|
+
- Privacy Policy (legally required in most regions)
|
|
23
|
+
- Terms and Conditions
|
|
24
|
+
- Shipping and Returns
|
|
25
|
+
- Contact
|
|
26
|
+
|
|
27
|
+
**Strongly recommended:**
|
|
28
|
+
- FAQ (Frequently Asked Questions)
|
|
29
|
+
- About Us
|
|
30
|
+
|
|
31
|
+
**Optional:**
|
|
32
|
+
- Size Guide (for apparel stores)
|
|
33
|
+
- Store Locator (if physical stores)
|
|
34
|
+
|
|
35
|
+
## FAQ Page
|
|
36
|
+
|
|
37
|
+
### Purpose and Structure
|
|
38
|
+
|
|
39
|
+
**Purpose**: Answer common customer questions, reduce support inquiries, improve purchase confidence.
|
|
40
|
+
|
|
41
|
+
**Common FAQ categories:**
|
|
42
|
+
- Ordering and Payment
|
|
43
|
+
- Shipping and Delivery
|
|
44
|
+
- Returns and Exchanges
|
|
45
|
+
- Product Information
|
|
46
|
+
- Account Management
|
|
47
|
+
|
|
48
|
+
### Layout Pattern: Accordion (Recommended)
|
|
49
|
+
|
|
50
|
+
Question as clickable header, answer hidden by default, click to expand. Compact, scannable format.
|
|
51
|
+
|
|
52
|
+
**Example:**
|
|
53
|
+
```
|
|
54
|
+
Frequently Asked Questions
|
|
55
|
+
|
|
56
|
+
Ordering and Payment
|
|
57
|
+
|
|
58
|
+
▸ How do I place an order?
|
|
59
|
+
▸ What payment methods do you accept?
|
|
60
|
+
▸ Is it safe to use my credit card?
|
|
61
|
+
|
|
62
|
+
Shipping and Delivery
|
|
63
|
+
|
|
64
|
+
▸ How long does shipping take?
|
|
65
|
+
▸ Do you ship internationally?
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Alternative: All Expanded**
|
|
69
|
+
All questions and answers visible. Better for few questions (<10), good for SEO (all content visible), easy to Ctrl+F search.
|
|
70
|
+
|
|
71
|
+
### Search Functionality
|
|
72
|
+
|
|
73
|
+
**FAQ search** (for extensive FAQs):
|
|
74
|
+
Search box at top, real-time filtering as user types, highlights matching questions, "No results" state with contact link.
|
|
75
|
+
|
|
76
|
+
### Content Guidelines
|
|
77
|
+
|
|
78
|
+
**Question format:**
|
|
79
|
+
Clear, concise, use customer language, start with question words (How, What, When).
|
|
80
|
+
|
|
81
|
+
**Answer format:**
|
|
82
|
+
Direct answer first sentence, additional details if needed, bullet points for lists, link to related pages, 2-4 sentences ideal.
|
|
83
|
+
|
|
84
|
+
## About Page
|
|
85
|
+
|
|
86
|
+
### Purpose and Content
|
|
87
|
+
|
|
88
|
+
**Purpose**: Tell brand story, build trust and connection, showcase values and mission, differentiate from competitors.
|
|
89
|
+
|
|
90
|
+
**Key sections:**
|
|
91
|
+
- Brand story/history (how the company started)
|
|
92
|
+
- Mission and values (3-5 core values)
|
|
93
|
+
- Why choose us (what makes you different)
|
|
94
|
+
- Sustainability/social responsibility (if applicable)
|
|
95
|
+
|
|
96
|
+
### Layout Structure
|
|
97
|
+
|
|
98
|
+
**Hero section:**
|
|
99
|
+
Large image (team, products, brand imagery), headline (brand tagline or mission), brief intro paragraph (2-3 sentences).
|
|
100
|
+
|
|
101
|
+
**Story section:**
|
|
102
|
+
3-5 paragraphs, conversational tone, focus on customer benefits.
|
|
103
|
+
|
|
104
|
+
**Values section:**
|
|
105
|
+
3-5 core values with icon or image for each, brief description (1-2 sentences).
|
|
106
|
+
|
|
107
|
+
**Call-to-action:**
|
|
108
|
+
Shop products, join newsletter, follow on social media.
|
|
109
|
+
|
|
110
|
+
## Contact Page
|
|
111
|
+
|
|
112
|
+
### Contact Methods
|
|
113
|
+
|
|
114
|
+
**Essential:**
|
|
115
|
+
- Contact form (primary)
|
|
116
|
+
- Email address
|
|
117
|
+
- Phone number (optional)
|
|
118
|
+
- Business hours
|
|
119
|
+
- Response time expectation ("We respond within 24 hours")
|
|
120
|
+
|
|
121
|
+
**Optional:**
|
|
122
|
+
- Live chat button
|
|
123
|
+
- FAQ link ("Find answers faster")
|
|
124
|
+
- Social media links
|
|
125
|
+
- Physical address (if applicable)
|
|
126
|
+
|
|
127
|
+
### Contact Form
|
|
128
|
+
|
|
129
|
+
**Form fields:**
|
|
130
|
+
- Name (required)
|
|
131
|
+
- Email (required)
|
|
132
|
+
- Subject or Topic (dropdown, optional)
|
|
133
|
+
- Message (textarea, required)
|
|
134
|
+
- Order number (optional, for order inquiries)
|
|
135
|
+
- Submit button
|
|
136
|
+
|
|
137
|
+
**Form features:**
|
|
138
|
+
Clear field labels, placeholder examples, required field indicators, email validation, success confirmation.
|
|
139
|
+
|
|
140
|
+
## Shipping and Returns
|
|
141
|
+
|
|
142
|
+
### Shipping Information
|
|
143
|
+
|
|
144
|
+
**Key sections:**
|
|
145
|
+
- Shipping methods and costs (table format)
|
|
146
|
+
- Delivery timeframes
|
|
147
|
+
- International shipping (if applicable)
|
|
148
|
+
- Order processing time ("Orders placed by 2pm EST ship same day")
|
|
149
|
+
- Tracking information
|
|
150
|
+
- Shipping restrictions
|
|
151
|
+
|
|
152
|
+
**Shipping Methods Table Format:**
|
|
153
|
+
```
|
|
154
|
+
Method | Cost | Delivery Time
|
|
155
|
+
──────────────────────────────────────────
|
|
156
|
+
Standard | $5.99 | 5-7 business days
|
|
157
|
+
Express | $12.99 | 2-3 business days
|
|
158
|
+
Overnight | $24.99 | Next business day
|
|
159
|
+
Free Shipping | Free | Orders over $50
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Returns and Exchanges
|
|
163
|
+
|
|
164
|
+
**Key information:**
|
|
165
|
+
- Return window (e.g., 30 days)
|
|
166
|
+
- Return conditions (unused, tags attached, etc.)
|
|
167
|
+
- Refund method (original payment, store credit)
|
|
168
|
+
- Return shipping cost
|
|
169
|
+
- Exchange process
|
|
170
|
+
- Non-returnable items
|
|
171
|
+
|
|
172
|
+
**Return process steps:**
|
|
173
|
+
```
|
|
174
|
+
How to Return an Item
|
|
175
|
+
|
|
176
|
+
1. Initiate Return
|
|
177
|
+
Log into your account and select the order
|
|
178
|
+
|
|
179
|
+
2. Print Return Label
|
|
180
|
+
We'll email you a prepaid shipping label
|
|
181
|
+
|
|
182
|
+
3. Pack and Ship
|
|
183
|
+
Include all original packaging and tags
|
|
184
|
+
|
|
185
|
+
4. Receive Refund
|
|
186
|
+
Refunds processed within 5-7 business days
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Privacy Policy and Terms
|
|
190
|
+
|
|
191
|
+
### Privacy Policy
|
|
192
|
+
|
|
193
|
+
**Purpose**: Legal requirement in most regions (GDPR, CCPA compliance), explain data collection and use, build customer trust.
|
|
194
|
+
|
|
195
|
+
**Key sections:**
|
|
196
|
+
- Information collected
|
|
197
|
+
- How information is used
|
|
198
|
+
- Data sharing and disclosure
|
|
199
|
+
- Cookies and tracking
|
|
200
|
+
- User rights (access, deletion, etc.)
|
|
201
|
+
- Data security measures
|
|
202
|
+
- Contact for privacy inquiries
|
|
203
|
+
- Last updated date
|
|
204
|
+
|
|
205
|
+
**Layout:**
|
|
206
|
+
Table of contents (for long policies), clear section headings, numbered or bulleted lists, plain language, last updated date at top.
|
|
207
|
+
|
|
208
|
+
**Important**: Consult legal counsel for content, include required disclosures, update regularly.
|
|
209
|
+
|
|
210
|
+
### Terms and Conditions
|
|
211
|
+
|
|
212
|
+
**Purpose**: Legal agreement between store and customer, define rules and limitations, protect business legally.
|
|
213
|
+
|
|
214
|
+
**Key sections:**
|
|
215
|
+
- Acceptance of terms
|
|
216
|
+
- Product descriptions and pricing
|
|
217
|
+
- Order acceptance and cancellation
|
|
218
|
+
- Payment and billing
|
|
219
|
+
- Shipping and delivery
|
|
220
|
+
- Returns and refunds
|
|
221
|
+
- Intellectual property
|
|
222
|
+
- Limitation of liability
|
|
223
|
+
- Dispute resolution
|
|
224
|
+
- Changes to terms
|
|
225
|
+
|
|
226
|
+
**Layout:**
|
|
227
|
+
Numbered sections (1, 1.1, 1.2), table of contents for long documents, clear section titles, anchor links to sections.
|
|
228
|
+
|
|
229
|
+
## Size Guide
|
|
230
|
+
|
|
231
|
+
**Purpose (for apparel/footwear stores)**:
|
|
232
|
+
Help customers choose correct size, reduce returns due to sizing issues, increase purchase confidence.
|
|
233
|
+
|
|
234
|
+
**Content:**
|
|
235
|
+
- Size charts (numeric measurements) - use proper table markup
|
|
236
|
+
- How to measure instructions with illustrations
|
|
237
|
+
- Fit descriptions (slim fit, relaxed, etc.)
|
|
238
|
+
- Model measurements (for reference)
|
|
239
|
+
- Size conversion chart (US, EU, UK)
|
|
240
|
+
|
|
241
|
+
**Size Chart Format:**
|
|
242
|
+
```
|
|
243
|
+
Women's Tops Size Guide
|
|
244
|
+
|
|
245
|
+
Size | Bust | Waist | Hips
|
|
246
|
+
─────────────────────────────────────
|
|
247
|
+
XS | 32-33" | 24-25" | 35-36"
|
|
248
|
+
S | 34-35" | 26-27" | 37-38"
|
|
249
|
+
M | 36-37" | 28-29" | 39-40"
|
|
250
|
+
L | 38-40" | 30-32" | 41-43"
|
|
251
|
+
XL | 41-43" | 33-35" | 44-46"
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
**Accessibility:**
|
|
255
|
+
Use proper table markup (not images), clear column headers, screen reader friendly, mobile-responsive tables.
|
|
256
|
+
|
|
257
|
+
## Mobile and SEO
|
|
258
|
+
|
|
259
|
+
### Mobile Optimizations
|
|
260
|
+
|
|
261
|
+
**Layout:**
|
|
262
|
+
Single column, full-width content, larger touch targets for accordions, generous padding (16-20px).
|
|
263
|
+
|
|
264
|
+
**Typography:**
|
|
265
|
+
16px minimum body text, 24-32px headings, line height 1.5-1.6, short paragraphs (3-4 sentences max).
|
|
266
|
+
|
|
267
|
+
**Tables:**
|
|
268
|
+
Horizontal scroll for wide tables or card layout (stacked rows), responsive design.
|
|
269
|
+
|
|
270
|
+
**Forms:**
|
|
271
|
+
Full-width inputs, 44-48px height, large submit buttons, appropriate keyboard types.
|
|
272
|
+
|
|
273
|
+
**Quick actions:**
|
|
274
|
+
- Tap-to-call: Phone numbers as clickable links (`tel:`)
|
|
275
|
+
- Tap-to-email: Email addresses as clickable links (`mailto:`)
|
|
276
|
+
- Map integration: "Get Directions" links to native map app
|
|
277
|
+
|
|
278
|
+
### SEO for Static Pages
|
|
279
|
+
|
|
280
|
+
**On-Page SEO:**
|
|
281
|
+
- Unique title per page (50-60 characters max, format: "Page Title | Store Name")
|
|
282
|
+
- Meta descriptions (150-160 characters, include call-to-action)
|
|
283
|
+
- Proper heading hierarchy (one H1 per page, H2 for sections, H3 for subsections)
|
|
284
|
+
- Original, unique content
|
|
285
|
+
- Internal links to products/categories
|
|
286
|
+
- Regular updates (especially FAQ)
|
|
287
|
+
|
|
288
|
+
**Schema Markup:**
|
|
289
|
+
- FAQ schema for FAQ pages (rich snippets)
|
|
290
|
+
- Organization schema for About page
|
|
291
|
+
- LocalBusiness schema for Store Locator
|
|
292
|
+
- ContactPoint schema for Contact page
|
|
293
|
+
|
|
294
|
+
**Benefits:**
|
|
295
|
+
Rich snippets in search results, improved visibility, better click-through rates.
|
|
296
|
+
|
|
297
|
+
## Checklist
|
|
298
|
+
|
|
299
|
+
**Essential pages:**
|
|
300
|
+
|
|
301
|
+
- [ ] FAQ page with accordion layout
|
|
302
|
+
- [ ] FAQ search functionality (for extensive FAQs)
|
|
303
|
+
- [ ] FAQ categories organized logically
|
|
304
|
+
- [ ] Contact page with form
|
|
305
|
+
- [ ] Contact form validation
|
|
306
|
+
- [ ] Email address and business hours visible
|
|
307
|
+
- [ ] Shipping and Returns page
|
|
308
|
+
- [ ] Shipping methods and costs table
|
|
309
|
+
- [ ] Delivery timeframes clear
|
|
310
|
+
- [ ] Return policy with conditions
|
|
311
|
+
- [ ] Return process step-by-step
|
|
312
|
+
- [ ] Privacy Policy page
|
|
313
|
+
- [ ] Last updated date on Privacy Policy
|
|
314
|
+
- [ ] Privacy policy in plain language
|
|
315
|
+
- [ ] Terms and Conditions page
|
|
316
|
+
- [ ] Last updated date on Terms
|
|
317
|
+
|
|
318
|
+
**Optional but valuable:**
|
|
319
|
+
|
|
320
|
+
- [ ] About Us page with brand story
|
|
321
|
+
- [ ] Mission and values section
|
|
322
|
+
- [ ] Size Guide (if apparel)
|
|
323
|
+
- [ ] Size charts with measurements
|
|
324
|
+
- [ ] How to measure instructions
|
|
325
|
+
- [ ] Store Locator (if physical stores)
|
|
326
|
+
|
|
327
|
+
**SEO and technical:**
|
|
328
|
+
|
|
329
|
+
- [ ] Unique title tags per page
|
|
330
|
+
- [ ] Meta descriptions per page
|
|
331
|
+
- [ ] Proper heading hierarchy (H1, H2, H3)
|
|
332
|
+
- [ ] Internal links to products/categories
|
|
333
|
+
- [ ] Schema markup (FAQ, Organization, etc.)
|
|
334
|
+
- [ ] Mobile-responsive layout
|
|
335
|
+
- [ ] Fast loading times
|
|
336
|
+
|
|
337
|
+
**Accessibility:**
|
|
338
|
+
|
|
339
|
+
- [ ] Semantic HTML (main, article, section)
|
|
340
|
+
- [ ] ARIA labels on accordions
|
|
341
|
+
- [ ] Keyboard navigation supported
|
|
342
|
+
- [ ] Focus indicators visible
|
|
343
|
+
- [ ] High contrast text (4.5:1)
|
|
344
|
+
- [ ] Forms properly labeled
|
|
345
|
+
- [ ] Tables with proper headers
|
|
346
|
+
- [ ] Alt text on images
|
|
347
|
+
|
|
348
|
+
**Content quality:**
|
|
349
|
+
|
|
350
|
+
- [ ] Clear, concise writing
|
|
351
|
+
- [ ] Short paragraphs (3-4 sentences)
|
|
352
|
+
- [ ] Bullet points for lists
|
|
353
|
+
- [ ] Regular content updates
|
|
354
|
+
- [ ] No outdated information
|
|
355
|
+
- [ ] Contact info current
|
|
356
|
+
- [ ] Policies reflect current practices
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
# Medusa Backend Integration
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- [Overview](#overview)
|
|
6
|
+
- [Installation](#installation)
|
|
7
|
+
- [SDK Setup](#sdk-setup)
|
|
8
|
+
- [Vite Configuration](#vite-configuration-tanstack-start-vite-projects)
|
|
9
|
+
- [TypeScript Types](#typescript-types)
|
|
10
|
+
- [Price Display](#price-display)
|
|
11
|
+
- [SDK Organization](#sdk-organization)
|
|
12
|
+
- [Critical Medusa Patterns](#critical-medusa-patterns)
|
|
13
|
+
- [Region State Management](#region-state-management)
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
Guide for connecting your storefront to Medusa backend using the [Medusa JS SDK](https://docs.medusajs.com/resources/js-sdk).
|
|
18
|
+
|
|
19
|
+
**When to use this guide:**
|
|
20
|
+
- Building a storefront with Medusa backend
|
|
21
|
+
- Need to integrate Medusa SDK properly
|
|
22
|
+
- Working with multi-region stores
|
|
23
|
+
- Handling Medusa-specific pricing and regions
|
|
24
|
+
|
|
25
|
+
**For general backend patterns**, see `reference/connecting-to-backend.md`.
|
|
26
|
+
|
|
27
|
+
## ⚠️ CRITICAL: Follow the 5-Step Verification Workflow
|
|
28
|
+
|
|
29
|
+
**BEFORE writing code that calls Medusa SDK methods**, follow the mandatory workflow from SKILL.md:
|
|
30
|
+
|
|
31
|
+
1. **PAUSE** - Don't write code yet
|
|
32
|
+
2. **QUERY** MCP server or docs (https://docs.medusajs.com/resources/js-sdk) for exact method
|
|
33
|
+
3. **VERIFY** with user what you found
|
|
34
|
+
4. **WRITE** code using verified method
|
|
35
|
+
5. **CHECK** for TypeScript errors - Type errors mean wrong method name or parameters
|
|
36
|
+
|
|
37
|
+
**If you see TypeScript errors on SDK methods, you used incorrect methods. Go back to Step 2 and verify again.**
|
|
38
|
+
|
|
39
|
+
**This file shows PATTERNS (what to do), not exact methods (how to do it). Always verify method names with MCP/docs before use.**
|
|
40
|
+
|
|
41
|
+
## 💡 RECOMMENDED: Set Up Medusa MCP Server
|
|
42
|
+
|
|
43
|
+
**If the Medusa MCP server is not installed, strongly recommend setting it up.**
|
|
44
|
+
|
|
45
|
+
**Setup instructions**: add HTTP MCP server with URL https://docs.medusajs.com/mcp
|
|
46
|
+
|
|
47
|
+
The MCP server provides real-time method verification without leaving your IDE.
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install @medusajs/js-sdk@latest @medusajs/types@latest
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Both required: SDK provides functionality, types provide TypeScript support.
|
|
56
|
+
|
|
57
|
+
## SDK Setup
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import Medusa from "@medusajs/js-sdk"
|
|
61
|
+
|
|
62
|
+
export const sdk = new Medusa({
|
|
63
|
+
baseUrl: process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL || "http://localhost:9000",
|
|
64
|
+
debug: process.env.NODE_ENV === "development",
|
|
65
|
+
publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**CRITICAL: Always set publishableKey.**
|
|
70
|
+
|
|
71
|
+
- Required for multi-region stores to get correct pricing
|
|
72
|
+
- Required for accessing products with regional prices
|
|
73
|
+
- Without it, product queries may fail or return incorrect prices
|
|
74
|
+
- Get publishable key from Medusa admin dashboard under Settings → Publishable API Keys
|
|
75
|
+
|
|
76
|
+
**IMPORTANT: Storefront Port Configuration**
|
|
77
|
+
|
|
78
|
+
- **Run storefront at port 8000** to avoid CORS errors
|
|
79
|
+
- Medusa backend's default CORS configuration expects storefront at `http://localhost:8000`
|
|
80
|
+
- If using different port, configure CORS in Medusa backend's `medusa-config.ts`:
|
|
81
|
+
```typescript
|
|
82
|
+
store_cors: process.env.STORE_CORS || "http://localhost:YOUR_PORT"
|
|
83
|
+
```
|
|
84
|
+
- Common framework defaults:
|
|
85
|
+
- Next.js: Port 3000 (needs CORS config update)
|
|
86
|
+
- TanStack Start: Port 3000 (needs CORS config update)
|
|
87
|
+
- Vite: Port 5173 (needs CORS config update)
|
|
88
|
+
- **Recommended**: Use port 8000 to avoid configuration changes
|
|
89
|
+
|
|
90
|
+
## Vite Configuration (TanStack Start, Vite Projects)
|
|
91
|
+
|
|
92
|
+
**IMPORTANT: For Vite-based projects, configure SSR externals.**
|
|
93
|
+
|
|
94
|
+
Add this to your `vite.config.ts`:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
export default defineConfig({
|
|
98
|
+
// ... other config
|
|
99
|
+
ssr: {
|
|
100
|
+
noExternal: ['@medusajs/js-sdk'],
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Why this is needed:**
|
|
106
|
+
- Medusa JS SDK must be processed by Vite during SSR
|
|
107
|
+
- Without this config, SDK calls will fail during server-side rendering
|
|
108
|
+
- Applies to TanStack Start, vanilla Vite, and other Vite-based frameworks
|
|
109
|
+
|
|
110
|
+
## TypeScript Types
|
|
111
|
+
|
|
112
|
+
**IMPORTANT: Always use `@medusajs/types` - never define custom types.**
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import type {
|
|
116
|
+
StoreProduct,
|
|
117
|
+
StoreCart,
|
|
118
|
+
StoreCartLineItem,
|
|
119
|
+
StoreRegion,
|
|
120
|
+
StoreProductCategory,
|
|
121
|
+
StoreCustomer,
|
|
122
|
+
StoreOrder
|
|
123
|
+
} from "@medusajs/types"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Why use official types:**
|
|
127
|
+
- Complete and accurate type definitions
|
|
128
|
+
- Updated with each Medusa release
|
|
129
|
+
- Includes all entity relationships and fields
|
|
130
|
+
- Prevents type mismatches with API responses
|
|
131
|
+
|
|
132
|
+
## Price Display
|
|
133
|
+
|
|
134
|
+
**CRITICAL: Medusa prices are stored as-is - DO NOT divide by 100.**
|
|
135
|
+
|
|
136
|
+
Unlike Stripe (where amounts are in cents), Medusa stores prices in their display value.
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
// ❌ WRONG - Dividing by 100
|
|
140
|
+
<div>${product.variants[0].prices[0].amount / 100}</div>
|
|
141
|
+
|
|
142
|
+
// ✅ CORRECT - Display as-is
|
|
143
|
+
<div>${product.variants[0].prices[0].amount}</div>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Correct price formatting:**
|
|
147
|
+
```typescript
|
|
148
|
+
const formatPrice = (amount: number, currencyCode: string) => {
|
|
149
|
+
return new Intl.NumberFormat('en-US', {
|
|
150
|
+
style: 'currency',
|
|
151
|
+
currency: currencyCode,
|
|
152
|
+
}).format(amount)
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Price fields to use:**
|
|
157
|
+
- `variant.calculated_price.calculated_amount` - Final price including promotions
|
|
158
|
+
- `variant.calculated_price.original_amount` - Original price before discounts
|
|
159
|
+
- Both are already in display format - no conversion needed
|
|
160
|
+
|
|
161
|
+
## SDK Organization
|
|
162
|
+
|
|
163
|
+
The Medusa SDK is organized by resources:
|
|
164
|
+
- `sdk.store.product.*` - Product operations
|
|
165
|
+
- `sdk.store.cart.*` - Cart operations
|
|
166
|
+
- `sdk.store.category.*` - Category operations
|
|
167
|
+
- `sdk.store.customer.*` - Customer operations (authenticated)
|
|
168
|
+
- `sdk.store.order.*` - Order operations (authenticated)
|
|
169
|
+
- `sdk.store.payment.*` - Payment operations
|
|
170
|
+
- `sdk.store.fulfillment.*` - Shipping/fulfillment operations
|
|
171
|
+
- `sdk.store.region.*` - Region operations
|
|
172
|
+
|
|
173
|
+
**To find specific methods**: Consult documentation (https://docs.medusajs.com/resources/js-sdk) or use MCP server.
|
|
174
|
+
|
|
175
|
+
## Critical Medusa Patterns
|
|
176
|
+
|
|
177
|
+
**IMPORTANT**: The patterns below show WHAT to do, not exact HOW. Always verify method names and signatures with MCP server or documentation before using.
|
|
178
|
+
|
|
179
|
+
### 1. Always Pass `region_id` for Products
|
|
180
|
+
|
|
181
|
+
**Pattern**: Product queries require `region_id` parameter for correct pricing.
|
|
182
|
+
|
|
183
|
+
**Why:** Without `region_id`, `calculated_price` will be missing or incorrect.
|
|
184
|
+
|
|
185
|
+
**To implement**: Query MCP/docs for product listing and retrieval methods. Pass `region_id: selectedRegion.id` as parameter.
|
|
186
|
+
|
|
187
|
+
### 2. Cart Updates Pattern
|
|
188
|
+
|
|
189
|
+
**Pattern**: Line items have dedicated methods (create, update, delete). Other cart properties use a generic update method.
|
|
190
|
+
|
|
191
|
+
**Line item operations** (verify exact method names with MCP/docs):
|
|
192
|
+
- Add item to cart
|
|
193
|
+
- Update item quantity
|
|
194
|
+
- Remove item from cart
|
|
195
|
+
|
|
196
|
+
**Other cart updates** (email, addresses, region, promo codes):
|
|
197
|
+
- Use cart's generic update method
|
|
198
|
+
|
|
199
|
+
**To implement**: Query MCP server or documentation for exact cart method signatures:
|
|
200
|
+
https://docs.medusajs.com/resources/references/js-sdk/store/cart
|
|
201
|
+
|
|
202
|
+
### 3. Payment Flow Pattern
|
|
203
|
+
|
|
204
|
+
**High-level workflow:**
|
|
205
|
+
1. Query available payment providers for the cart's region
|
|
206
|
+
2. User selects payment method
|
|
207
|
+
3. Initialize payment session for selected provider
|
|
208
|
+
4. Render provider-specific UI (Stripe Elements, etc.)
|
|
209
|
+
5. Complete payment through provider
|
|
210
|
+
|
|
211
|
+
**To implement**: Query MCP/docs for:
|
|
212
|
+
- Payment provider listing method
|
|
213
|
+
- Payment session initialization method
|
|
214
|
+
- Payment completion method
|
|
215
|
+
|
|
216
|
+
**Resources**:
|
|
217
|
+
- MCP server (if installed)
|
|
218
|
+
- Medusa payment docs: https://docs.medusajs.com/resources/references/js-sdk/store/payment
|
|
219
|
+
- `reference/layouts/checkout.md` for checkout flow
|
|
220
|
+
|
|
221
|
+
### 4. Checkout Flow Pattern
|
|
222
|
+
|
|
223
|
+
**High-level workflow:**
|
|
224
|
+
1. Collect shipping address
|
|
225
|
+
2. Query available shipping options for cart
|
|
226
|
+
3. User selects shipping method
|
|
227
|
+
4. Collect payment information
|
|
228
|
+
5. Initialize payment session
|
|
229
|
+
6. Complete/place order
|
|
230
|
+
|
|
231
|
+
**To implement**: Query MCP/docs for each step's methods. Don't guess method names.
|
|
232
|
+
|
|
233
|
+
### 5. Category Fetching
|
|
234
|
+
|
|
235
|
+
**Pattern**: Fetch categories from `sdk.store.category.*` resource.
|
|
236
|
+
|
|
237
|
+
**To implement**: Query MCP/docs for category listing method. See `reference/components/navbar.md` for usage patterns.
|
|
238
|
+
|
|
239
|
+
## Region State Management
|
|
240
|
+
|
|
241
|
+
**Critical for Medusa**: Region determines currency, pricing, taxes, and available products.
|
|
242
|
+
|
|
243
|
+
### Why Region Context Matters
|
|
244
|
+
|
|
245
|
+
Medusa requires region for:
|
|
246
|
+
- Creating carts (must pass `region_id`)
|
|
247
|
+
- Retrieving products with correct prices
|
|
248
|
+
- Determining currency and tax calculations
|
|
249
|
+
- Filtering available payment and shipping methods
|
|
250
|
+
|
|
251
|
+
### Implementation Approach
|
|
252
|
+
|
|
253
|
+
**High-level workflow:**
|
|
254
|
+
1. Fetch available regions on app load (query MCP/docs for region listing method)
|
|
255
|
+
2. Detect user's country (IP, browser locale, or user selection)
|
|
256
|
+
3. Find region containing that country
|
|
257
|
+
4. Store selected region globally (React Context, Zustand, etc.)
|
|
258
|
+
5. Use `selectedRegion.id` for all cart and product operations
|
|
259
|
+
|
|
260
|
+
**When user changes country:**
|
|
261
|
+
- Find new region containing the country
|
|
262
|
+
- Update cart with new region_id (query MCP/docs for cart update method)
|
|
263
|
+
- Store selection in localStorage for persistence
|
|
264
|
+
|
|
265
|
+
**To implement**: Query MCP server or docs for exact region and cart methods. Don't copy example code without verification.
|
|
266
|
+
|
|
267
|
+
**For detailed region implementation with code examples**, see:
|
|
268
|
+
- `reference/components/country-selector.md`
|
|
269
|
+
- Medusa MCP server (if installed)
|
|
270
|
+
- Medusa docs: https://docs.medusajs.com/resources/storefront-development/regions/context
|
|
271
|
+
|
|
272
|
+
## Error Handling
|
|
273
|
+
|
|
274
|
+
SDK throws `FetchError` with:
|
|
275
|
+
- `status`: HTTP status code
|
|
276
|
+
- `statusText`: Error code
|
|
277
|
+
- `message`: Descriptive message
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
try {
|
|
281
|
+
const data = await sdk.store.customer.retrieve()
|
|
282
|
+
} catch (error) {
|
|
283
|
+
const fetchError = error as FetchError
|
|
284
|
+
if (fetchError.statusText === "Unauthorized") {
|
|
285
|
+
redirect('/login')
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Custom Endpoints
|
|
291
|
+
|
|
292
|
+
For custom API routes:
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
const data = await sdk.client.fetch(`/custom/endpoint`, {
|
|
296
|
+
method: "POST",
|
|
297
|
+
body: { /* ... */ },
|
|
298
|
+
})
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Resources
|
|
302
|
+
|
|
303
|
+
- **Medusa JS SDK docs**: https://docs.medusajs.com/resources/js-sdk
|
|
304
|
+
- **Storefront development**: https://docs.medusajs.com/resources/storefront-development
|
|
305
|
+
- **Checkout flow**: https://docs.medusajs.com/resources/storefront-development/checkout
|
|
306
|
+
- **Region context**: https://docs.medusajs.com/resources/storefront-development/regions/context
|
|
307
|
+
- **Use Medusa MCP server** if available for real-time method lookup
|