@decocms/start 0.19.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.
- package/.cursor/skills/deco-api-call-dedup/SKILL.md +443 -0
- package/.cursor/skills/deco-apps-architecture/SKILL.md +255 -0
- package/.cursor/skills/deco-apps-architecture/app-pattern.md +288 -0
- package/.cursor/skills/deco-apps-architecture/commerce-types.md +239 -0
- package/.cursor/skills/deco-apps-architecture/new-app-guide.md +268 -0
- package/.cursor/skills/deco-apps-architecture/scripts-codegen.md +148 -0
- package/.cursor/skills/deco-apps-architecture/shared-utils.md +181 -0
- package/.cursor/skills/deco-apps-architecture/vtex-deep-structure.md +253 -0
- package/.cursor/skills/deco-apps-architecture/website-app.md +169 -0
- package/.cursor/skills/deco-apps-vtex-porting/SKILL.md +189 -0
- package/.cursor/skills/deco-apps-vtex-porting/adaptation-patterns.md +335 -0
- package/.cursor/skills/deco-apps-vtex-porting/commerce-porting.md +155 -0
- package/.cursor/skills/deco-apps-vtex-porting/cookie-auth-patterns.md +148 -0
- package/.cursor/skills/deco-apps-vtex-porting/structure-map.md +234 -0
- package/.cursor/skills/deco-apps-vtex-porting/transform-mapping.md +99 -0
- package/.cursor/skills/deco-apps-vtex-porting/website-porting.md +194 -0
- package/.cursor/skills/deco-apps-vtex-review/SKILL.md +234 -0
- package/.cursor/skills/deco-async-rendering-architecture/SKILL.md +270 -0
- package/.cursor/skills/deco-async-rendering-site-guide/SKILL.md +417 -0
- package/.cursor/skills/deco-cms-layout-caching/SKILL.md +293 -0
- package/.cursor/skills/deco-cms-route-config/SKILL.md +388 -0
- package/.cursor/skills/deco-core-architecture/SKILL.md +185 -0
- package/.cursor/skills/deco-core-architecture/blocks.md +196 -0
- package/.cursor/skills/deco-core-architecture/deco-vs-deco-start.md +191 -0
- package/.cursor/skills/deco-core-architecture/engine.md +220 -0
- package/.cursor/skills/deco-core-architecture/hooks-components.md +157 -0
- package/.cursor/skills/deco-core-architecture/plugins-clients.md +136 -0
- package/.cursor/skills/deco-core-architecture/runtime.md +116 -0
- package/.cursor/skills/deco-core-architecture/site-usage.md +165 -0
- package/.cursor/skills/deco-e2e-testing/SKILL.md +372 -0
- package/.cursor/skills/deco-e2e-testing/discovery.md +337 -0
- package/.cursor/skills/deco-e2e-testing/scripts/scaffold.sh +81 -0
- package/.cursor/skills/deco-e2e-testing/selectors.md +175 -0
- package/.cursor/skills/deco-e2e-testing/templates/package.json +18 -0
- package/.cursor/skills/deco-e2e-testing/templates/playwright.config.ts +65 -0
- package/.cursor/skills/deco-e2e-testing/templates/scripts/baseline.ts +279 -0
- package/.cursor/skills/deco-e2e-testing/templates/scripts/run-e2e.ts +194 -0
- package/.cursor/skills/deco-e2e-testing/templates/specs/ecommerce-flow.spec.ts +612 -0
- package/.cursor/skills/deco-e2e-testing/templates/tsconfig.json +12 -0
- package/.cursor/skills/deco-e2e-testing/templates/utils/metrics-collector.ts +918 -0
- package/.cursor/skills/deco-e2e-testing/troubleshooting.md +602 -0
- package/.cursor/skills/deco-edge-caching/SKILL.md +316 -0
- package/.cursor/skills/deco-full-analysis/SKILL.md +898 -0
- package/.cursor/skills/deco-full-analysis/checklists/asset-optimization.md +251 -0
- package/.cursor/skills/deco-full-analysis/checklists/bug-fix.md +189 -0
- package/.cursor/skills/deco-full-analysis/checklists/cache-strategy.md +144 -0
- package/.cursor/skills/deco-full-analysis/checklists/dependency-update.md +150 -0
- package/.cursor/skills/deco-full-analysis/checklists/hydration-fix.md +191 -0
- package/.cursor/skills/deco-full-analysis/checklists/image-optimization.md +180 -0
- package/.cursor/skills/deco-full-analysis/checklists/loader-optimization.md +165 -0
- package/.cursor/skills/deco-full-analysis/checklists/seo-fix.md +183 -0
- package/.cursor/skills/deco-full-analysis/checklists/site-cleanup.md +281 -0
- package/.cursor/skills/deco-full-analysis/discovery.md +548 -0
- package/.cursor/skills/deco-incident-debugging/SKILL.md +378 -0
- package/.cursor/skills/deco-incident-debugging/headless-mode.md +510 -0
- package/.cursor/skills/deco-incident-debugging/learnings-index.md +227 -0
- package/.cursor/skills/deco-incident-debugging/triage-workflow.md +312 -0
- package/.cursor/skills/deco-islands-migration/SKILL.md +251 -0
- package/.cursor/skills/deco-loader-n-plus-1-detector/SKILL.md +275 -0
- package/.cursor/skills/deco-performance-audit/SKILL.md +530 -0
- package/.cursor/skills/deco-performance-audit/tools-reference.md +428 -0
- package/.cursor/skills/deco-performance-audit/workflow.md +457 -0
- package/.cursor/skills/deco-server-functions-invoke/SKILL.md +92 -0
- package/.cursor/skills/deco-server-functions-invoke/architecture.md +166 -0
- package/.cursor/skills/deco-server-functions-invoke/generator.md +122 -0
- package/.cursor/skills/deco-server-functions-invoke/problem.md +98 -0
- package/.cursor/skills/deco-server-functions-invoke/troubleshooting.md +110 -0
- package/.cursor/skills/deco-site-deployment/SKILL.md +396 -0
- package/.cursor/skills/deco-site-memory-debugging/SKILL.md +121 -0
- package/.cursor/skills/deco-site-memory-debugging/cdp-connection.md +222 -0
- package/.cursor/skills/deco-site-memory-debugging/memory-analysis.md +362 -0
- package/.cursor/skills/deco-site-patterns/SKILL.md +124 -0
- package/.cursor/skills/deco-site-patterns/app-composition.md +337 -0
- package/.cursor/skills/deco-site-patterns/client-patterns.md +341 -0
- package/.cursor/skills/deco-site-patterns/cms-wiring.md +230 -0
- package/.cursor/skills/deco-site-patterns/section-patterns.md +340 -0
- package/.cursor/skills/deco-site-scaling-tuning/SKILL.md +240 -0
- package/.cursor/skills/deco-site-scaling-tuning/analysis-scripts.md +267 -0
- package/.cursor/skills/deco-start-architecture/SKILL.md +218 -0
- package/.cursor/skills/deco-start-architecture/admin-protocol.md +156 -0
- package/.cursor/skills/deco-start-architecture/cms-resolution.md +201 -0
- package/.cursor/skills/deco-start-architecture/code-quality.md +158 -0
- package/.cursor/skills/deco-start-architecture/gap-analysis.md +129 -0
- package/.cursor/skills/deco-start-architecture/sdk-utilities.md +197 -0
- package/.cursor/skills/deco-start-architecture/worker-entry-caching.md +154 -0
- package/.cursor/skills/deco-startup-analysis/SKILL.md +248 -0
- package/.cursor/skills/deco-storefront-test-checklist/SKILL.md +369 -0
- package/.cursor/skills/deco-tanstack-hydration-fixes/SKILL.md +468 -0
- package/.cursor/skills/deco-tanstack-navigation/SKILL.md +681 -0
- package/.cursor/skills/deco-tanstack-search/SKILL.md +411 -0
- package/.cursor/skills/deco-tanstack-storefront-patterns/SKILL.md +1013 -0
- package/.cursor/skills/deco-to-tanstack-migration/SKILL.md +518 -0
- package/.cursor/skills/deco-to-tanstack-migration/references/codemod-commands.md +174 -0
- package/.cursor/skills/deco-to-tanstack-migration/references/commerce/README.md +78 -0
- package/.cursor/skills/deco-to-tanstack-migration/references/deco-framework/README.md +128 -0
- package/.cursor/skills/deco-to-tanstack-migration/references/gotchas.md +719 -0
- package/.cursor/skills/deco-to-tanstack-migration/references/imports/README.md +70 -0
- package/.cursor/skills/deco-to-tanstack-migration/references/platform-hooks/README.md +154 -0
- package/.cursor/skills/deco-to-tanstack-migration/references/signals/README.md +220 -0
- package/.cursor/skills/deco-to-tanstack-migration/references/vite-config/README.md +78 -0
- package/.cursor/skills/deco-to-tanstack-migration/templates/package-json.md +55 -0
- package/.cursor/skills/deco-to-tanstack-migration/templates/root-route.md +110 -0
- package/.cursor/skills/deco-to-tanstack-migration/templates/router.md +96 -0
- package/.cursor/skills/deco-to-tanstack-migration/templates/setup-ts.md +167 -0
- package/.cursor/skills/deco-to-tanstack-migration/templates/vite-config.md +122 -0
- package/.cursor/skills/deco-to-tanstack-migration/templates/worker-entry.md +67 -0
- package/.cursor/skills/deco-typescript-fixes/SKILL.md +178 -0
- package/.cursor/skills/deco-typescript-fixes/common-fixes.md +330 -0
- package/.cursor/skills/deco-typescript-fixes/strategy.md +148 -0
- package/.cursor/skills/deco-variant-selection-perf/SKILL.md +272 -0
- package/.cursor/skills/deco-vtex-fetch-cache/SKILL.md +225 -0
- package/.cursor/skills/find-skills/SKILL.md +133 -0
- package/.cursor/skills/incident-report/SKILL.md +179 -0
- package/.cursor/skills/incident-report/references/5-whys.md +75 -0
- package/.cursor/skills/incident-report/templates/client-report.md +187 -0
- package/.cursor/skills/incident-report/templates/internal-report.md +206 -0
- package/.cursor/skills/template-skill/SKILL.md +38 -0
- package/.github/workflows/release.yml +32 -0
- package/.releaserc.json +25 -0
- package/CLAUDE.md +135 -0
- package/GAP_ANALYSIS.md +224 -0
- package/GAP_ANALYSIS_V2.md +1013 -0
- package/biome.json +39 -0
- package/knip.json +5 -0
- package/package.json +87 -0
- package/scripts/generate-blocks.ts +69 -0
- package/scripts/generate-invoke.ts +378 -0
- package/scripts/generate-schema.ts +657 -0
- package/src/admin/cors.ts +29 -0
- package/src/admin/decofile.ts +72 -0
- package/src/admin/index.ts +24 -0
- package/src/admin/invoke.ts +163 -0
- package/src/admin/liveControls.ts +29 -0
- package/src/admin/meta.ts +70 -0
- package/src/admin/render.ts +205 -0
- package/src/admin/schema.ts +686 -0
- package/src/admin/setup.ts +44 -0
- package/src/cms/index.ts +59 -0
- package/src/cms/loader.ts +180 -0
- package/src/cms/registry.ts +162 -0
- package/src/cms/resolve.ts +1005 -0
- package/src/cms/sectionLoaders.ts +294 -0
- package/src/hooks/DecoPageRenderer.tsx +444 -0
- package/src/hooks/LazySection.tsx +109 -0
- package/src/hooks/LiveControls.tsx +108 -0
- package/src/hooks/SectionErrorFallback.tsx +85 -0
- package/src/hooks/index.ts +8 -0
- package/src/index.ts +5 -0
- package/src/matchers/builtins.ts +184 -0
- package/src/matchers/posthog.ts +154 -0
- package/src/middleware/decoState.ts +55 -0
- package/src/middleware/healthMetrics.ts +131 -0
- package/src/middleware/index.ts +80 -0
- package/src/middleware/liveness.ts +21 -0
- package/src/middleware/observability.ts +205 -0
- package/src/routes/adminRoutes.ts +83 -0
- package/src/routes/cmsRoute.ts +302 -0
- package/src/routes/components.tsx +34 -0
- package/src/routes/index.ts +15 -0
- package/src/sdk/analytics.ts +72 -0
- package/src/sdk/cacheHeaders.ts +268 -0
- package/src/sdk/cachedLoader.ts +206 -0
- package/src/sdk/clx.ts +3 -0
- package/src/sdk/cookie.ts +39 -0
- package/src/sdk/createInvoke.ts +57 -0
- package/src/sdk/csp.ts +59 -0
- package/src/sdk/env.ts +27 -0
- package/src/sdk/index.ts +63 -0
- package/src/sdk/instrumentedFetch.ts +137 -0
- package/src/sdk/invoke.ts +133 -0
- package/src/sdk/mergeCacheControl.ts +150 -0
- package/src/sdk/redirects.ts +217 -0
- package/src/sdk/requestContext.ts +184 -0
- package/src/sdk/serverTimings.ts +68 -0
- package/src/sdk/signal.ts +41 -0
- package/src/sdk/sitemap.ts +143 -0
- package/src/sdk/urlUtils.ts +117 -0
- package/src/sdk/useDevice.ts +82 -0
- package/src/sdk/useId.ts +7 -0
- package/src/sdk/useScript.ts +101 -0
- package/src/sdk/workerEntry.ts +703 -0
- package/src/sdk/wrapCaughtErrors.ts +107 -0
- package/src/types/index.ts +39 -0
- package/src/types/widgets.ts +13 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
# Performance Audit Workflow
|
|
2
|
+
|
|
3
|
+
Detailed step-by-step process for running a performance audit.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
1. **Site Information**
|
|
8
|
+
- Sitename (e.g., `mystore`)
|
|
9
|
+
- Production hostname (e.g., `www.mystore.com`)
|
|
10
|
+
- Date range to analyze
|
|
11
|
+
|
|
12
|
+
2. **Access to MCP Tools**
|
|
13
|
+
- MONITOR_* tools (CDN metrics)
|
|
14
|
+
- SEARCH_LOGS, GET_LOG_DETAILS (error logs)
|
|
15
|
+
|
|
16
|
+
3. **Best Practices**
|
|
17
|
+
- Use `granularity: "hourly"` for latency metrics (daily returns 0)
|
|
18
|
+
- Run deco-full-analysis skill first to understand site structure
|
|
19
|
+
- Compare with previous period when possible
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Step 1: Overall Health Check
|
|
24
|
+
|
|
25
|
+
### Get Summary Metrics
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
MONITOR_SUMMARY({
|
|
29
|
+
sitename: "mystore",
|
|
30
|
+
hostname: "www.mystore.com",
|
|
31
|
+
startDate: "2026-01-17",
|
|
32
|
+
endDate: "2026-01-18",
|
|
33
|
+
granularity: "daily"
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**What to look for**:
|
|
38
|
+
| Metric | Good | Warning | Critical |
|
|
39
|
+
|--------|------|---------|----------|
|
|
40
|
+
| cache_hit_ratio | >80% | 50-80% | <50% |
|
|
41
|
+
| status_5xx_count / total | <0.1% | 0.1-0.5% | >0.5% |
|
|
42
|
+
| status_4xx_count / total | <5% | 5-10% | >10% |
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Step 2: Traffic Pattern Analysis
|
|
47
|
+
|
|
48
|
+
### Get Top Paths
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
MONITOR_TOP_PATHS({
|
|
52
|
+
sitename: "mystore",
|
|
53
|
+
hostname: "www.mystore.com",
|
|
54
|
+
startDate: "2026-01-17",
|
|
55
|
+
endDate: "2026-01-18",
|
|
56
|
+
limit: 30,
|
|
57
|
+
granularity: "daily"
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Categorize results**:
|
|
62
|
+
|
|
63
|
+
| Category | Pattern | Expected % |
|
|
64
|
+
|----------|---------|------------|
|
|
65
|
+
| API Calls | `/live/invoke/*` | 20-40% |
|
|
66
|
+
| Static Assets | `/_frsh/js/*`, `/fonts/*`, `/sprites.svg` | 20-30% |
|
|
67
|
+
| Pages | `/`, `/p`, `/category` | 10-20% |
|
|
68
|
+
| Other | Favicon, SW, etc. | 10-20% |
|
|
69
|
+
|
|
70
|
+
**Red flags**:
|
|
71
|
+
- Single path > 10% (potential hotspot)
|
|
72
|
+
- High bandwidth on small files (inefficient)
|
|
73
|
+
- API calls > 50% (too many fetches)
|
|
74
|
+
|
|
75
|
+
### Group by Content Type
|
|
76
|
+
|
|
77
|
+
Manually categorize the top paths results:
|
|
78
|
+
|
|
79
|
+
| Content Type | Path Pattern | How to Identify |
|
|
80
|
+
|--------------|--------------|-----------------|
|
|
81
|
+
| API Calls | `/live/invoke/*` | Loader/action invocations |
|
|
82
|
+
| Lazy Sections | `/deco/render` | Section lazy loading |
|
|
83
|
+
| JavaScript | `/_frsh/js/*`, `*.js` | Fresh JS bundles |
|
|
84
|
+
| CSS/Styles | `*.css`, `/_frsh/css/*` | Stylesheets |
|
|
85
|
+
| Images | `/image/*`, `*.png/jpg/webp` | Product/banner images |
|
|
86
|
+
| Fonts | `*.woff2`, `/fonts/*` | Web fonts |
|
|
87
|
+
| Static | `/sprites.svg`, `/favicon.ico` | Icons, misc |
|
|
88
|
+
| HTML Pages | `/`, `/s`, `/:slug/p` | Server-rendered pages |
|
|
89
|
+
|
|
90
|
+
Create a summary table:
|
|
91
|
+
|
|
92
|
+
```markdown
|
|
93
|
+
| Type | Requests | Bandwidth | Cache Rate | Status |
|
|
94
|
+
|------|----------|-----------|------------|--------|
|
|
95
|
+
| API | 2.1M | 89GB | 0.05% | 🔴 |
|
|
96
|
+
| Lazy Sections | 450K | 12GB | 15% | 🟡 |
|
|
97
|
+
| JavaScript | 1.8M | 45GB | 94% | 🟢 |
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Identify Bandwidth Hotspots
|
|
101
|
+
|
|
102
|
+
Sort the top paths by bandwidth descending. The top 5-10 by bandwidth often reveal:
|
|
103
|
+
|
|
104
|
+
1. **Uncached large JSON** - API responses that should be cached
|
|
105
|
+
2. **Unoptimized images** - Not going through image proxy
|
|
106
|
+
3. **Large JS bundles** - Code splitting opportunities
|
|
107
|
+
4. **Repeated lazy sections** - Sections fetched too often
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Step 2.5: Lazy Section Analysis
|
|
112
|
+
|
|
113
|
+
### Filter for /deco/render
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
MONITOR_TOP_PATHS({
|
|
117
|
+
sitename: "mystore",
|
|
118
|
+
hostname: "www.mystore.com",
|
|
119
|
+
startDate: "2026-01-17",
|
|
120
|
+
endDate: "2026-01-18",
|
|
121
|
+
limit: 20,
|
|
122
|
+
filters: [
|
|
123
|
+
{ type: "path", operator: "contains", value: "/deco/render" }
|
|
124
|
+
]
|
|
125
|
+
})
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**What to look for**:
|
|
129
|
+
- Which sections are lazy-loaded most
|
|
130
|
+
- Cache hit rate per section
|
|
131
|
+
- Latency (high latency = slow scroll experience)
|
|
132
|
+
|
|
133
|
+
**Create section analysis table**:
|
|
134
|
+
|
|
135
|
+
```markdown
|
|
136
|
+
| Section | Requests | Bandwidth | Cache Hit | Avg Latency |
|
|
137
|
+
|---------|----------|-----------|-----------|-------------|
|
|
138
|
+
| ProductShelf | 120K | 3.2GB | 12% | 180ms |
|
|
139
|
+
| Reviews | 85K | 1.8GB | 5% | 220ms |
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Common issues**:
|
|
143
|
+
- Lazy sections with 0% cache = origin fetch on every scroll
|
|
144
|
+
- High volume sections with low cache = optimization opportunity
|
|
145
|
+
- Consider making some sections non-lazy if always visible
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Step 3: Cache Analysis
|
|
150
|
+
|
|
151
|
+
### Get Cache Status Breakdown
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
MONITOR_CACHE_STATUS({
|
|
155
|
+
sitename: "mystore",
|
|
156
|
+
hostname: "www.mystore.com",
|
|
157
|
+
startDate: "2026-01-17",
|
|
158
|
+
endDate: "2026-01-18",
|
|
159
|
+
granularity: "daily"
|
|
160
|
+
})
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Expected distribution (healthy site)**:
|
|
164
|
+
| Status | Target % |
|
|
165
|
+
|--------|----------|
|
|
166
|
+
| hit | >60% |
|
|
167
|
+
| miss | <25% |
|
|
168
|
+
| unknown | <10% |
|
|
169
|
+
| expired | <5% |
|
|
170
|
+
|
|
171
|
+
**Fixing low hit rate**:
|
|
172
|
+
1. Check if loaders have `export const cache = "..."`
|
|
173
|
+
2. Add cache-control headers
|
|
174
|
+
3. Use stale-while-revalidate
|
|
175
|
+
|
|
176
|
+
### Find uncached hot paths
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
MONITOR_TOP_PATHS({
|
|
180
|
+
sitename: "mystore",
|
|
181
|
+
hostname: "www.mystore.com",
|
|
182
|
+
startDate: "2026-01-17",
|
|
183
|
+
endDate: "2026-01-18",
|
|
184
|
+
limit: 20,
|
|
185
|
+
filters: [
|
|
186
|
+
{ type: "cache_status", operator: "equals", value: "miss" }
|
|
187
|
+
]
|
|
188
|
+
})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Step 4: Error Analysis
|
|
194
|
+
|
|
195
|
+
### Get Status Code Distribution
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
MONITOR_STATUS_CODES({
|
|
199
|
+
sitename: "mystore",
|
|
200
|
+
hostname: "www.mystore.com",
|
|
201
|
+
startDate: "2026-01-17",
|
|
202
|
+
endDate: "2026-01-18",
|
|
203
|
+
granularity: "daily"
|
|
204
|
+
})
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Key status codes**:
|
|
208
|
+
| Code | Meaning | Action |
|
|
209
|
+
|------|---------|--------|
|
|
210
|
+
| 200 | Success | Good |
|
|
211
|
+
| 301/302 | Redirect | Minimize |
|
|
212
|
+
| 304 | Not Modified | Good (client cache) |
|
|
213
|
+
| 400 | Bad Request | Check client code |
|
|
214
|
+
| 404 | Not Found | Fix links or add redirects |
|
|
215
|
+
| 429 | Rate Limited | Reduce API calls |
|
|
216
|
+
| 500 | Server Error | Investigate logs |
|
|
217
|
+
| 502/504 | Gateway Error | Origin issues |
|
|
218
|
+
|
|
219
|
+
### Find paths with errors
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
MONITOR_TOP_PATHS({
|
|
223
|
+
sitename: "mystore",
|
|
224
|
+
hostname: "www.mystore.com",
|
|
225
|
+
startDate: "2026-01-17",
|
|
226
|
+
endDate: "2026-01-18",
|
|
227
|
+
limit: 20,
|
|
228
|
+
filters: [
|
|
229
|
+
{ type: "status_code", operator: "equals", value: "500" }
|
|
230
|
+
]
|
|
231
|
+
})
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Step 5: Error Log Deep Dive
|
|
237
|
+
|
|
238
|
+
### Search for Error Logs
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
SEARCH_LOGS({
|
|
242
|
+
query: "level:error site:mystore",
|
|
243
|
+
limit: 50
|
|
244
|
+
})
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**Common error patterns**:
|
|
248
|
+
|
|
249
|
+
| Pattern | Cause | Fix |
|
|
250
|
+
|---------|-------|-----|
|
|
251
|
+
| "Too Many Requests" | VTEX rate limiting | Add caching |
|
|
252
|
+
| "TypeError: Cannot read" | JS null reference | Add null checks |
|
|
253
|
+
| "Failed to fetch" | Network error | Add retry logic |
|
|
254
|
+
| "dangling reference" | Missing block | Fix block config |
|
|
255
|
+
|
|
256
|
+
### Get Error Details
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
GET_LOG_DETAILS({
|
|
260
|
+
query: "level:error site:mystore",
|
|
261
|
+
groupBy: ["body", "service", "site"],
|
|
262
|
+
limit: 20
|
|
263
|
+
})
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Check Error Trend
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
QUERY_CHART_DATA({
|
|
270
|
+
startTime: 1737100800000, // epoch ms
|
|
271
|
+
endTime: 1737187200000,
|
|
272
|
+
granularity: "1 hour",
|
|
273
|
+
series: [{
|
|
274
|
+
dataSource: "events",
|
|
275
|
+
aggFn: "count",
|
|
276
|
+
where: "level:error site:mystore",
|
|
277
|
+
groupBy: []
|
|
278
|
+
}]
|
|
279
|
+
})
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## Step 6: Geographic Analysis
|
|
285
|
+
|
|
286
|
+
### Get Top Countries
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
MONITOR_TOP_COUNTRIES({
|
|
290
|
+
sitename: "mystore",
|
|
291
|
+
hostname: "www.mystore.com",
|
|
292
|
+
startDate: "2026-01-17",
|
|
293
|
+
endDate: "2026-01-18",
|
|
294
|
+
limit: 10,
|
|
295
|
+
granularity: "daily"
|
|
296
|
+
})
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**What to look for**:
|
|
300
|
+
- Traffic from unexpected regions (bot traffic?)
|
|
301
|
+
- High latency for top regions
|
|
302
|
+
- Edge cache effectiveness by region
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Step 7: Time Series Analysis
|
|
307
|
+
|
|
308
|
+
### Get Usage Timeline
|
|
309
|
+
|
|
310
|
+
```
|
|
311
|
+
MONITOR_USAGE_TIMELINE({
|
|
312
|
+
sitename: "mystore",
|
|
313
|
+
hostname: "www.mystore.com",
|
|
314
|
+
startDate: "2026-01-17",
|
|
315
|
+
endDate: "2026-01-18",
|
|
316
|
+
granularity: "hourly"
|
|
317
|
+
})
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**What to look for**:
|
|
321
|
+
- Traffic patterns (peak hours)
|
|
322
|
+
- Cache ratio fluctuations
|
|
323
|
+
- Correlation with deployments
|
|
324
|
+
|
|
325
|
+
### Create 24h Pattern Table
|
|
326
|
+
|
|
327
|
+
Group hourly data into readable periods:
|
|
328
|
+
|
|
329
|
+
```markdown
|
|
330
|
+
| Period | Requests/hr | 5xx | 429s | Cache Hit | Notes |
|
|
331
|
+
|--------|-------------|-----|------|-----------|-------|
|
|
332
|
+
| 00:00-06:00 | 85K | <10 | 120 | 52% | Low traffic |
|
|
333
|
+
| 06:00-10:00 | 180K | 25 | 450 | 48% | Morning ramp |
|
|
334
|
+
| 10:00-14:00 | 320K | 45 | 1.2K | 45% | Peak |
|
|
335
|
+
| 14:00-18:00 | 280K | 40 | 980 | 46% | Steady |
|
|
336
|
+
| 18:00-22:00 | 380K | 120 | 1.8K | 44% | Evening peak |
|
|
337
|
+
| 22:00-00:00 | 150K | 20 | 320 | 50% | Wind down |
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**Insights to draw**:
|
|
341
|
+
1. Peak hours = when NOT to deploy
|
|
342
|
+
2. Error spikes correlating with traffic = capacity issues
|
|
343
|
+
3. Cache hit degradation under load = cache thrashing
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## Step 8: Correlate with Code
|
|
348
|
+
|
|
349
|
+
Using insights from `deco-full-analysis`:
|
|
350
|
+
|
|
351
|
+
### Match paths to loaders
|
|
352
|
+
|
|
353
|
+
| Hot Path | Loader | Has Cache? |
|
|
354
|
+
|----------|--------|------------|
|
|
355
|
+
| `/live/invoke/site/loaders/search/...` | `loaders/search/intelligenseSearch.ts` | Check file |
|
|
356
|
+
| `/live/invoke/vtex/loaders/...` | VTEX app loader | App handles |
|
|
357
|
+
|
|
358
|
+
### Check loader cache settings
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
// In loader file, look for:
|
|
362
|
+
export const cache = "stale-while-revalidate";
|
|
363
|
+
export const cacheKey = (props: Props) => props.id;
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## Step 9: Generate Report
|
|
369
|
+
|
|
370
|
+
Compile findings into a structured report. **MUST include these sections**:
|
|
371
|
+
|
|
372
|
+
### Required Report Sections
|
|
373
|
+
|
|
374
|
+
1. **Executive Summary** - Key metrics with status indicators
|
|
375
|
+
2. **Hot Paths Table** - Top 15 paths by requests AND by bandwidth
|
|
376
|
+
3. **Content Type Breakdown** - Grouped analysis
|
|
377
|
+
4. **Lazy Section Analysis** - /deco/render performance
|
|
378
|
+
5. **Time Series Pattern** - 24h traffic table
|
|
379
|
+
6. **Cache Analysis** - Status breakdown with drill-down
|
|
380
|
+
7. **Error Analysis** - Status codes and log patterns
|
|
381
|
+
8. **Actionable Recommendations** - Prioritized with specific fixes
|
|
382
|
+
|
|
383
|
+
### Report Checklist
|
|
384
|
+
|
|
385
|
+
Before finalizing, verify:
|
|
386
|
+
- [ ] Hot paths table shows BOTH requests and bandwidth columns
|
|
387
|
+
- [ ] Bandwidth hotspots are identified separately
|
|
388
|
+
- [ ] Content types are grouped (API, JS, Images, etc.)
|
|
389
|
+
- [ ] Lazy sections are analyzed with cache rates
|
|
390
|
+
- [ ] Time series shows peak hours
|
|
391
|
+
- [ ] Recommendations have specific file paths to fix
|
|
392
|
+
- [ ] Targets table shows current vs goal
|
|
393
|
+
|
|
394
|
+
See SKILL.md for full report template.
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
## Common Issues & Fixes
|
|
399
|
+
|
|
400
|
+
### Issue: Low Cache Hit Ratio
|
|
401
|
+
|
|
402
|
+
**Symptoms**: cache_hit_ratio < 50%
|
|
403
|
+
|
|
404
|
+
**Diagnose**:
|
|
405
|
+
```
|
|
406
|
+
MONITOR_CACHE_STATUS → high "unknown" or "miss"
|
|
407
|
+
MONITOR_TOP_PATHS with cache_status:miss filter → which paths
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
**Fix**:
|
|
411
|
+
1. Add cache headers to loaders
|
|
412
|
+
2. Use stale-while-revalidate
|
|
413
|
+
3. Increase cache TTLs
|
|
414
|
+
|
|
415
|
+
### Issue: High 429 Rate
|
|
416
|
+
|
|
417
|
+
**Symptoms**: 429 errors > 1%
|
|
418
|
+
|
|
419
|
+
**Diagnose**:
|
|
420
|
+
```
|
|
421
|
+
SEARCH_LOGS({ query: "429 site:mystore" })
|
|
422
|
+
MONITOR_TOP_PATHS → which paths hit rate limits
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
**Fix**:
|
|
426
|
+
1. Implement request deduplication
|
|
427
|
+
2. Add caching for frequently called APIs
|
|
428
|
+
3. Use batch APIs where available
|
|
429
|
+
|
|
430
|
+
### Issue: High 404 Rate
|
|
431
|
+
|
|
432
|
+
**Symptoms**: 404 errors > 5%
|
|
433
|
+
|
|
434
|
+
**Diagnose**:
|
|
435
|
+
```
|
|
436
|
+
MONITOR_TOP_PATHS with status_code:404 filter
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**Fix**:
|
|
440
|
+
1. Add redirects for old URLs
|
|
441
|
+
2. Fix broken links in content
|
|
442
|
+
3. Update sitemap
|
|
443
|
+
|
|
444
|
+
### Issue: 5xx Errors Spiking
|
|
445
|
+
|
|
446
|
+
**Symptoms**: 5xx errors > 0.1%
|
|
447
|
+
|
|
448
|
+
**Diagnose**:
|
|
449
|
+
```
|
|
450
|
+
SEARCH_LOGS({ query: "level:error site:mystore" })
|
|
451
|
+
GET_LOG_DETAILS → specific error messages
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
**Fix**:
|
|
455
|
+
1. Check error logs for patterns
|
|
456
|
+
2. Add error handling/fallbacks
|
|
457
|
+
3. Fix root cause in code
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deco-server-functions-invoke
|
|
3
|
+
description: How server functions (invoke) work in Deco storefronts — the generate-invoke pipeline that bridges @decocms/apps pure functions to TanStack Start createServerFn with top-level declarations. Covers the root cause of CORS issues with VTEX API calls, why createServerFn must be top-level, the three-layer architecture (apps=pure functions, start=generator, site=generated invoke), the generate-invoke.ts script, and the comparison with deco-cx/deco's Proxy+HTTP invoke. Use when debugging CORS in cart/checkout, adding new server actions, understanding why invoke calls hit VTEX directly from the browser, or setting up invoke for a new site.
|
|
4
|
+
globs:
|
|
5
|
+
- "**/invoke.gen.ts"
|
|
6
|
+
- "**/invoke.ts"
|
|
7
|
+
- "**/useCart.ts"
|
|
8
|
+
- "**/createInvoke.ts"
|
|
9
|
+
- "**/generate-invoke.ts"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Sub-documents
|
|
13
|
+
|
|
14
|
+
| Document | Topic |
|
|
15
|
+
|----------|-------|
|
|
16
|
+
| [problem.md](./problem.md) | The CORS problem — root cause analysis of why createServerFn inside a factory function doesn't work |
|
|
17
|
+
| [architecture.md](./architecture.md) | Three-layer invoke architecture and comparison with deco-cx/deco |
|
|
18
|
+
| [generator.md](./generator.md) | The generate-invoke.ts script — how it works, how to run it, how to extend |
|
|
19
|
+
| [troubleshooting.md](./troubleshooting.md) | Common issues and how to debug them |
|
|
20
|
+
|
|
21
|
+
# Deco Server Functions & Invoke
|
|
22
|
+
|
|
23
|
+
How server-side actions (cart, checkout, newsletter, masterdata) are called from the browser in Deco TanStack Start storefronts.
|
|
24
|
+
|
|
25
|
+
## The Problem in One Sentence
|
|
26
|
+
|
|
27
|
+
TanStack Start's `createServerFn` compiler only transforms `.handler()` calls at **module top-level** — wrapping it in a factory function (`createInvokeFn`) causes the compiler's "fast path" to skip it, sending raw VTEX API calls to the browser and causing CORS errors.
|
|
28
|
+
|
|
29
|
+
## The Solution in One Sentence
|
|
30
|
+
|
|
31
|
+
A build-time generator (`generate-invoke.ts`) reads the action definitions from `@decocms/apps` and emits `invoke.gen.ts` with each `createServerFn().handler()` as a **top-level const**, which the compiler correctly transforms into RPC stubs.
|
|
32
|
+
|
|
33
|
+
## Quick Reference
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
Client (useCart)
|
|
37
|
+
→ invoke.vtex.actions.addItemsToCart({ data: {...} })
|
|
38
|
+
→ createClientRpc("base64id") ← compiler-generated stub
|
|
39
|
+
→ POST /_server ← same domain, no CORS
|
|
40
|
+
→ TanStack Start server handler
|
|
41
|
+
→ addItemsToCart(orderFormId, items) ← pure function from @decocms/apps
|
|
42
|
+
→ vtexFetch → VTEX API ← server-to-server, has credentials
|
|
43
|
+
→ Response → client
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Layer Responsibilities
|
|
47
|
+
|
|
48
|
+
| Layer | Package | Role |
|
|
49
|
+
|-------|---------|------|
|
|
50
|
+
| **Commerce functions** | `@decocms/apps` | Pure async functions (`addItemsToCart`, `subscribe`, etc.) — no framework deps |
|
|
51
|
+
| **Generator** | `@decocms/start` | `generate-invoke.ts` script that creates top-level `createServerFn` declarations |
|
|
52
|
+
| **Generated bridge** | Site (`invoke.gen.ts`) | Auto-generated file with RPC-transformable server functions |
|
|
53
|
+
| **Consumer** | Site components | Import `invoke` from `~/server/invoke.gen` |
|
|
54
|
+
|
|
55
|
+
## Setup for a New Site
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# 1. Generate the invoke file
|
|
59
|
+
npx tsx node_modules/@decocms/start/scripts/generate-invoke.ts
|
|
60
|
+
|
|
61
|
+
# 2. Import in components
|
|
62
|
+
import { invoke } from "~/server/invoke.gen";
|
|
63
|
+
const cart = await invoke.vtex.actions.addItemsToCart({
|
|
64
|
+
data: { orderFormId, orderItems }
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Add to `package.json`:
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"scripts": {
|
|
72
|
+
"generate:invoke": "tsx node_modules/@decocms/start/scripts/generate-invoke.ts",
|
|
73
|
+
"build": "npm run generate:blocks && npm run generate:invoke && npm run generate:schema && tsr generate && vite build"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Key Files
|
|
79
|
+
|
|
80
|
+
| File | Location | Purpose |
|
|
81
|
+
|------|----------|---------|
|
|
82
|
+
| `generate-invoke.ts` | `@decocms/start/scripts/` | Build-time generator script |
|
|
83
|
+
| `invoke.gen.ts` | Site `src/server/` | Generated file with top-level server functions |
|
|
84
|
+
| `vtex/invoke.ts` | `@decocms/apps/` | Source of truth for action definitions (parsed by generator) |
|
|
85
|
+
| `vtex/actions/*.ts` | `@decocms/apps/` | Pure commerce functions |
|
|
86
|
+
|
|
87
|
+
## When to Re-generate
|
|
88
|
+
|
|
89
|
+
Re-run `npm run generate:invoke` when:
|
|
90
|
+
- Adding new actions to `@decocms/apps/vtex/invoke.ts`
|
|
91
|
+
- Changing action signatures (input types, return types)
|
|
92
|
+
- Updating `@decocms/apps` dependency
|