@caartzee/theme-sdk 1.0.0 → 1.2.0

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.
Files changed (50) hide show
  1. package/README.md +208 -20
  2. package/dist/bin/caartzee-theme.js +1855 -81
  3. package/dist/lib/index.js +1857 -81
  4. package/dist/types/src/blocks/block-contract.d.ts +10 -10
  5. package/dist/types/src/cli/candy-mcp.d.ts +2 -0
  6. package/dist/types/src/cli/candy-tool-server.d.ts +39 -0
  7. package/dist/types/src/cli/mcp/component-tools.d.ts +2 -0
  8. package/dist/types/src/cli/mcp/docs-tools.d.ts +89 -0
  9. package/dist/types/src/cli/mcp/editor-tools.d.ts +22 -0
  10. package/dist/types/src/cli/mcp/resources-and-prompts.d.ts +2 -0
  11. package/dist/types/src/cli/mcp/testing-tools.d.ts +54 -0
  12. package/dist/types/src/contracts/manifest.d.ts +77 -77
  13. package/dist/types/src/dev-server/dev-server.d.ts +3 -0
  14. package/dist/types/src/dev-server/local-commerce-runtime.d.ts +76 -0
  15. package/dist/types/src/dev-server/local-editor-server.d.ts +22 -0
  16. package/dist/types/src/dev-server/theme-preview.d.ts +6 -2
  17. package/dist/types/src/sections/section-contract.d.ts +12 -12
  18. package/package.json +2 -1
  19. package/templates/theme-candy-boilerplate/.editorconfig +14 -0
  20. package/templates/theme-candy-boilerplate/.gitattributes +1 -0
  21. package/templates/theme-candy-boilerplate/.vscode/extensions.json +7 -0
  22. package/templates/theme-candy-boilerplate/.vscode/settings.json +17 -0
  23. package/templates/theme-candy-boilerplate/assets/theme.css +78 -0
  24. package/templates/theme-candy-boilerplate/assets/theme.js +7 -0
  25. package/templates/theme-candy-boilerplate/candy.config.json +40 -0
  26. package/templates/theme-candy-boilerplate/index.ts +39 -0
  27. package/templates/theme-candy-boilerplate/layout/theme.candy +25 -0
  28. package/templates/theme-candy-boilerplate/locales/en.default.json +37 -0
  29. package/templates/theme-candy-boilerplate/manifest.json +123 -0
  30. package/templates/theme-candy-boilerplate/package.json +16 -0
  31. package/templates/theme-candy-boilerplate/schemas/settings_schema.json +36 -0
  32. package/templates/theme-candy-boilerplate/sections/featured-products.candy +89 -0
  33. package/templates/theme-candy-boilerplate/sections/footer.candy +50 -0
  34. package/templates/theme-candy-boilerplate/sections/header.candy +116 -0
  35. package/templates/theme-candy-boilerplate/sections/hero-banner.candy +135 -0
  36. package/templates/theme-candy-boilerplate/sections/image-with-text.candy +85 -0
  37. package/templates/theme-candy-boilerplate/snippets/price.candy +19 -0
  38. package/templates/theme-candy-boilerplate/snippets/product-card.candy +43 -0
  39. package/templates/theme-candy-boilerplate/templates/404.candy +12 -0
  40. package/templates/theme-candy-boilerplate/templates/cart.candy +51 -0
  41. package/templates/theme-candy-boilerplate/templates/collection.candy +51 -0
  42. package/templates/theme-candy-boilerplate/templates/index.candy +7 -0
  43. package/templates/theme-candy-boilerplate/templates/page.candy +10 -0
  44. package/templates/theme-candy-boilerplate/templates/product.candy +59 -0
  45. package/templates/theme-candy-boilerplate/templates/search.candy +40 -0
  46. package/templates/vscode-candy/LICENSE +21 -0
  47. package/templates/vscode-candy/extension.js +689 -338
  48. package/templates/vscode-candy/icons/candy-logo.png +0 -0
  49. package/templates/vscode-candy/package.json +18 -3
  50. package/templates/vscode-candy/snippets/candy.code-snippets +91 -0
package/README.md CHANGED
@@ -1,35 +1,223 @@
1
- # Caartzee Theme SDK
1
+ # @caartzee/theme-sdk
2
2
 
3
- Build Candy storefront themes with Node.js 22 or later.
3
+ Official Theme SDK & CLI for building, previewing, validating, and publishing **Candy (`.candy`)** storefront themes on **Caartzee**.
4
4
 
5
- ## Create and preview a theme
5
+ - **npm:** `https://www.npmjs.com/package/@caartzee/theme-sdk`
6
+ - **CLI binary:** `caartzee-theme` (alias: `caartzee`)
7
+ - **IDE Extension (`.candy` syntax, IntelliSense, formatter & diagnostics):**
8
+ - **VS Code Marketplace:** https://marketplace.visualstudio.com/items?itemName=AkhilJinu.candy-language-support
9
+ - **Open VSX (Antigravity, Cursor, Windsurf, VSCodium):** https://open-vsx.org/extension/AkhilJinu/candy-language-support
10
+ - Install via CLI: `code --install-extension AkhilJinu.candy-language-support`
6
11
 
7
- ```sh
8
- npx --package "<path-to-sdk.tgz>" caartzee-theme init my-theme
12
+ ---
13
+
14
+ ## Quick Start
15
+
16
+ ```bash
17
+ # 1. Scaffold a new Candy theme
18
+ npx --package=@caartzee/theme-sdk caartzee-theme init my-theme --engine candy
9
19
  cd my-theme
10
- npm install "<path-to-sdk.tgz>"
11
- npm run dev
20
+ bun install # or npm install
21
+
22
+ # 2. Preview locally with mock catalog, cart, wishlist & auth
23
+ npx caartzee-theme dev --port 3333
24
+
25
+ # 3. Preview with a merchant-approved live catalog
26
+ npx caartzee-theme connect --clipboard # Windows (or --stdin on macOS/Linux)
27
+ npx caartzee-theme dev --port 3333 --store your-store.caartzee.com
28
+
29
+ # 4. Run full health & storefront readiness audit
30
+ npx caartzee-theme doctor .
31
+
32
+ # 5. Sync manifest, validate security, build & publish
33
+ npx caartzee-theme sync-manifest .
34
+ npx caartzee-theme validate .
35
+ npx caartzee-theme build .
36
+ npx caartzee-theme push .
37
+ ```
38
+
39
+ ---
40
+
41
+ ## CLI Commands
42
+
43
+ | Command | Description |
44
+ | --- | --- |
45
+ | `caartzee-theme init [name] --engine candy` | Scaffold a new Candy storefront theme |
46
+ | `caartzee-theme dev [--port 3333] [--store DOMAIN]` | Start local preview server (offline mock data or live merchant catalog) |
47
+ | `caartzee-theme doctor [path]` | Audit storefront shell, cart/variant hooks, auth forms, currency, menus & sliders |
48
+ | `caartzee-theme version <patch\|minor\|major\|x.y.z> [path]` | Bump theme version across `candy.config.json` and `manifest.json` |
49
+ | `caartzee-theme sync-manifest [path]` | Regenerate `manifest.json` from `candy.config.json` & section `{% schema %}` blocks |
50
+ | `caartzee-theme validate [path]` | Run security & schema validation (forbids `eval`, `process.env`, `fs`, `child_process`) |
51
+ | `caartzee-theme build [path]` | Compile `.candy` templates & assets into `dist/candy-theme-bundle.json` |
52
+ | `caartzee-theme connect --clipboard \| --stdin` | Connect to your Caartzee Developer Portal theme app |
53
+ | `caartzee-theme login --api URL --token-stdin` | Authenticate using an app SDK token |
54
+ | `caartzee-theme whoami` / `logout` | Check or clear saved developer credentials |
55
+ | `caartzee-theme ide-setup [path]` | Install `.candy` syntax highlighting for VS Code / Cursor / Antigravity |
56
+ | `caartzee-theme push [path]` | Validate and submit a new theme version to the Caartzee Partner Portal |
57
+
58
+ ---
59
+
60
+ ## Theme Directory Structure
61
+
62
+ ```text
63
+ my-theme/
64
+ ├── candy.config.json # Theme slug, version, engine: "candy", design tokens
65
+ ├── manifest.json # Generated via `caartzee-theme sync-manifest .`
66
+ ├── layout/
67
+ │ └── theme.candy # Used by local SDK dev preview
68
+ ├── templates/ # Page body fragments (NO {% layout %} in storefront-shell mode!)
69
+ │ ├── index.candy # Home page
70
+ │ ├── collection.candy # /products & /collections/:slug
71
+ │ ├── list-collections.candy # /collections
72
+ │ ├── product.candy # /products/:slug
73
+ │ ├── search.candy # /search
74
+ │ ├── wishlist.candy # /wishlist
75
+ │ ├── cart.candy # /cart
76
+ │ ├── login.candy # /login
77
+ │ ├── register.candy # /signup & /register
78
+ │ ├── page.candy # /pages/:slug
79
+ │ └── 404.candy # Not found
80
+ ├── sections/ # Editable Theme Editor sections (each has a {% schema %} block)
81
+ │ ├── header.candy
82
+ │ ├── footer.candy
83
+ │ ├── hero-banner.candy
84
+ │ ├── featured-products.candy
85
+ │ ├── collection-showcase.candy
86
+ │ ├── image-with-text.candy
87
+ │ └── value-props.candy
88
+ ├── snippets/ # Reusable partials (product-card.candy, price.candy, etc.)
89
+ ├── assets/
90
+ │ ├── theme.css # Auto-injected into Storefront Shell <head>
91
+ │ └── theme.js # Auto-injected into Storefront Shell before </body>
92
+ ├── locales/
93
+ │ └── en.default.json # Translations accessed via {{ 'key' | t }}
94
+ └── schemas/
95
+ └── settings_schema.json # Global theme settings shown in Theme Editor
12
96
  ```
13
97
 
14
- Use an absolute path to the SDK tarball. Open the local URL printed by the CLI for a preview with sample catalog data. Edit the homepage in `templates/index.candy`, shared product cards in `snippets/product-card.candy`, and styles in `assets/theme.css`. Refresh the preview after editing.
98
+ ---
99
+
100
+ ## Storefront Shell & Capabilities (Critical!)
15
101
 
16
- ## Use an approved store
102
+ On live Caartzee storefronts, Candy themes run inside the **Storefront Shell**, which provides live cart/wishlist sessions, checkout, customer authentication, payment gateways, and Theme Editor live preview.
17
103
 
18
- In **Developer Portal > Theme SDK**, select your theme app and request **Live Store Preview Access**. After the merchant approves, click **Copy SDK connection** and run the commands below from the theme directory on Windows. Copy the connection again if you have copied something else in the meantime.
104
+ Enable both capabilities in `manifest.json`:
19
105
 
20
- ```powershell
21
- npx caartzee-theme connect --clipboard
22
- npm run dev -- --store merchant.caartzee.com
106
+ ```json
107
+ "capabilities": {
108
+ "storefront-shell": true,
109
+ "commerce_pages": true
110
+ }
23
111
  ```
24
112
 
25
- On macOS, pipe the clipboard into the CLI with `pbpaste | npx caartzee-theme connect --stdin`.
113
+ ### Mandatory Rules for Storefront Shell Themes
114
+ 1. **Keep `templates/*.candy` as body fragments:** Do **NOT** include `{% layout 'theme' %}` inside `templates/*.candy`. The shell renders header, body, footer, `assets/theme.css`, and `assets/theme.js` once.
115
+ 2. **Load fonts inside `assets/theme.css`:** Because `layout/theme.candy` is bypassed in shell mode, include `@import url('https://fonts.googleapis.com/...');` at the top of `assets/theme.css` and style `body` directly (not only a custom body class).
116
+ 3. **Use delegated event listeners in `assets/theme.js`:** Always bind interactive controls (mobile menu drawer, search bar toggle, slider dots) via `document.addEventListener('click', ...)` so they continue working after Theme Editor live section re-renders.
117
+ 4. **Avoid `backdrop-filter` / `transform` on sticky `<header>`:** If your mobile drawer (`position: fixed; inset: 0;`) is rendered inside `<header>`, putting `backdrop-filter` or `transform` on `<header>` creates a CSS containing block that clips the drawer to the header height. Use a solid background on `<header>` instead.
26
118
 
27
- ## Submit for review
119
+ ---
28
120
 
29
- ```sh
30
- npm run validate
31
- npm run build
32
- npm run push
121
+ ## E-Commerce Storefront Contracts
122
+
123
+ ### 1. Currency & Pricing (Never Hardcode `$`)
124
+ Always format prices with `{{ amount | money }}` (or `money_with_currency`).
125
+ **Important:** Liquid `{% render %}` isolates variable scope! Always pass `shop` and `currency_info` explicitly into snippets that render prices:
126
+
127
+ ```liquid
128
+ {% render 'product-card', product: item, shop: shop, currency_info: currency_info %}
33
129
  ```
34
130
 
35
- Keep the theme slug aligned with your developer app and save the same version in `manifest.json` and `candy.config.json`. Check the submission in the Developer Portal.
131
+ Inside `snippets/price.candy`, `{{ price | money }}` will automatically render the merchant's live currency symbol (e.g., `₹22.00`, `$22.00`, `€22.00`).
132
+
133
+ ### 2. Add to Cart & Variants (`/_api/cart`)
134
+ Caartzee's storefront runtime binds to `.js-add-to-cart` buttons and reads `data-*` attributes:
135
+
136
+ ```html
137
+ <button
138
+ type="button"
139
+ class="js-add-to-cart"
140
+ data-product-id="{{ product.id }}"
141
+ {% if product.has_inventory_variants and product.selected_or_first_available_variant.id %}
142
+ data-variant-id="{{ product.selected_or_first_available_variant.id }}"
143
+ {% endif %}
144
+ data-quantity="1"
145
+ data-product-title="{{ product.title | escape }}"
146
+ data-product-price="{{ product.price }}"
147
+ data-product-image="{{ product.featured_image | image_url | escape }}"
148
+ >
149
+ Add to Bag
150
+ </button>
151
+ ```
152
+
153
+ > **CRITICAL (`422 Unprocessable Entity` prevention):**
154
+ > Never emit synthetic string IDs like `data-variant-id="1-default"` for products without real inventory variants! The `/_api/cart` endpoint expects a numeric `variant_id` (or omitted/`0` when no inventory variants exist). Always guard `data-variant-id` with `{% if product.has_inventory_variants %}`.
155
+
156
+ #### Header Cart Count Badge
157
+ Include both `js-cart-count` and `data-cart-count` on your header cart counter so live Add to Cart updates it without a page reload:
158
+
159
+ ```html
160
+ <span class="js-cart-count" data-cart-count>{{ cart.item_count | default: 0 }}</span>
161
+ ```
162
+
163
+ #### Product Detail Page (PDP) Hooks
164
+ Preserve these attributes in `templates/product.candy`:
165
+ - Wrapper: `data-product-detail`
166
+ - Gallery: `data-product-main-image`, `data-product-thumbnail="<url>"`
167
+ - Variant selector: `data-product-variant`, `data-variant-option`, `data-variant-value`, `data-variant-label`, `data-stock`, `data-price`, `data-formatted-price`
168
+ - Quantity & feedback: `data-product-quantity`, `data-quantity-step="-1"|"1"`, `data-product-stock`, `data-product-feedback`
169
+ - Wishlist button: `.js-wishlist-toggle` with `data-product-id="{{ product.id }}"`
170
+
171
+ #### Shopping Bag (`/cart`) Hooks
172
+ In `templates/cart.candy`:
173
+ - Quantity buttons: `.js-cart-qty-btn` with `data-product-id`, `data-variant-id`, `data-delta="-1"|"1"`
174
+ - Remove button: `.js-remove-cart-item` with `data-product-id`, `data-variant-id`
175
+ - Checkout CTA: `<a href="{{ routes.checkout_url | default: '/checkout' }}">Proceed to Checkout</a>` (checkout and payment gateways are handled by Caartzee's secure checkout runtime).
176
+
177
+ ### 3. Customer Login, Signup & Account (`/login`, `/signup`, `/account`)
178
+ - **Login template:** `templates/login.candy` (mapped automatically to `pageType: 'login'` at `/login`)
179
+ - **Signup template:** `templates/register.candy` (mapped automatically to `pageType: 'signup'` at `/signup` and `/register`)
180
+ - **Account & Checkout:** Delegated to Caartzee's built-in authenticated account portal (`/account`, `/account/orders`, `/account/addresses`, `/account/profile`) and checkout (`/checkout`).
181
+
182
+ #### Login Form Contract (`templates/login.candy`)
183
+ ```html
184
+ <form action="/_api/auth/login" method="POST" class="js-auth-form" data-redirect="{{ redirect_url | default: '/account' | escape }}">
185
+ <input type="hidden" name="redirect" value="{{ redirect_url | default: '/account' | escape }}" />
186
+ <input id="login-email" type="email" name="email" required autocomplete="email" />
187
+ <input id="login-password" type="password" name="password" required autocomplete="current-password" />
188
+ <button type="submit" class="js-submit-btn">Sign In</button>
189
+ </form>
190
+ ```
191
+
192
+ #### Signup Form Contract (`templates/register.candy`)
193
+ ```html
194
+ <form action="/_api/auth/register" method="POST" class="js-auth-form" data-redirect="{{ redirect_url | default: '/account' | escape }}">
195
+ <input type="hidden" name="redirect" value="{{ redirect_url | default: '/account' | escape }}" />
196
+ <input id="reg-first-name" type="text" name="firstName" required />
197
+ <input id="reg-last-name" type="text" name="lastName" required />
198
+ <input id="reg-email" type="email" name="email" required autocomplete="email" />
199
+ <input id="reg-phone" type="tel" name="mobile" required pattern="[0-9]{10}" maxlength="10" inputmode="numeric" />
200
+ <input id="reg-password" type="password" name="password" required minlength="8" autocomplete="new-password" />
201
+ <button type="submit" class="js-submit-btn">Create Account</button>
202
+ </form>
203
+ ```
204
+
205
+ ### 4. Header Menus & Hero Mobile Sliders (Theme Editor)
206
+ - **Header Navigation (`sections/header.candy`):**
207
+ - Include `{ "id": "menuId", "type": "select", "label": "Navigation Menu", "default": null, "options": [] }` in `{% schema %}` so merchants can pick any menu from **Menu Manage**.
208
+ - Render `linklists['main-menu'].links` first, falling back to `section.blocks`.
209
+ - **Hero Banner (`sections/hero-banner.candy`):**
210
+ - Include a `slide` block definition in `{% schema %}` so Theme Editor draft/publish validation always succeeds.
211
+ - Check `{% if mobile_sliders and mobile_sliders.size > 0 %}` and render each slide (`slide.title`, `slide.description`, `slide.image`, `slide.button_text`, `slide.button_url`) with pagination dots so changes in the merchant's **Mobile Slider** manager reflect immediately.
212
+
213
+ ---
214
+
215
+ ## Publishing & Live Deployment
216
+
217
+ 1. Bump the version: `npx caartzee-theme version patch .`
218
+ 2. Sync manifest: `npx caartzee-theme sync-manifest .`
219
+ 3. Audit & validate: `npx caartzee-theme doctor . && npx caartzee-theme validate .`
220
+ 4. Build bundle: `npx caartzee-theme build .`
221
+ 5. Submit to Caartzee Partner Portal: `npx caartzee-theme push .`
222
+
223
+ Once approved, Caartzee's `theme-rendering-engine` dynamically fetches and caches the approved theme package from `theme_packages` by `(slug, version)` — **no backend code changes or redeploys are required**. Merchants simply click **Activate** or **Update** in **Theme Manage**.