@cloudgrid-io/mcp 0.12.0 → 0.13.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/package.json +1 -1
- package/src/corpus/capability-map.md +21 -2
- package/src/corpus/examples/crm/index.md +273 -0
- package/src/corpus/examples/kanban/index.md +256 -0
- package/src/corpus/templates/admin-dashboard/README.md +75 -0
- package/src/corpus/templates/admin-dashboard/cloudgrid.yaml +15 -0
- package/src/corpus/templates/admin-dashboard/index.md +78 -0
- package/src/corpus/templates/admin-dashboard/services/web/app/api/orders/route.js +64 -0
- package/src/corpus/templates/admin-dashboard/services/web/app/api/users/route.js +63 -0
- package/src/corpus/templates/admin-dashboard/services/web/app/layout.js +39 -0
- package/src/corpus/templates/admin-dashboard/services/web/app/page.js +73 -0
- package/src/corpus/templates/admin-dashboard/services/web/app/resource-table.js +94 -0
- package/src/corpus/templates/admin-dashboard/services/web/lib/db.js +32 -0
- package/src/corpus/templates/admin-dashboard/services/web/package.json +16 -0
- package/src/corpus/templates/api-docs/README.md +28 -0
- package/src/corpus/templates/api-docs/cloudgrid.yaml +10 -0
- package/src/corpus/templates/api-docs/index.html +136 -0
- package/src/corpus/templates/api-docs/index.md +30 -0
- package/src/corpus/templates/changelog/README.md +27 -0
- package/src/corpus/templates/changelog/cloudgrid.yaml +10 -0
- package/src/corpus/templates/changelog/index.html +80 -0
- package/src/corpus/templates/changelog/index.md +30 -0
- package/src/corpus/templates/crm/README.md +72 -0
- package/src/corpus/templates/crm/cloudgrid.yaml +15 -0
- package/src/corpus/templates/crm/index.md +68 -0
- package/src/corpus/templates/crm/services/web/app/api/contacts/route.js +80 -0
- package/src/corpus/templates/crm/services/web/app/contact-manager.js +102 -0
- package/src/corpus/templates/crm/services/web/app/layout.js +35 -0
- package/src/corpus/templates/crm/services/web/app/page.js +34 -0
- package/src/corpus/templates/crm/services/web/lib/db.js +32 -0
- package/src/corpus/templates/crm/services/web/package.json +16 -0
- package/src/corpus/templates/docs-site/README.md +28 -0
- package/src/corpus/templates/docs-site/cloudgrid.yaml +10 -0
- package/src/corpus/templates/docs-site/index.html +122 -0
- package/src/corpus/templates/docs-site/index.md +30 -0
- package/src/corpus/templates/kanban/README.md +72 -0
- package/src/corpus/templates/kanban/cloudgrid.yaml +15 -0
- package/src/corpus/templates/kanban/index.md +68 -0
- package/src/corpus/templates/kanban/services/web/app/api/cards/route.js +70 -0
- package/src/corpus/templates/kanban/services/web/app/board.js +93 -0
- package/src/corpus/templates/kanban/services/web/app/layout.js +37 -0
- package/src/corpus/templates/kanban/services/web/app/page.js +32 -0
- package/src/corpus/templates/kanban/services/web/lib/db.js +32 -0
- package/src/corpus/templates/kanban/services/web/package.json +16 -0
- package/src/corpus/templates/portfolio/README.md +29 -0
- package/src/corpus/templates/portfolio/cloudgrid.yaml +10 -0
- package/src/corpus/templates/portfolio/index.html +126 -0
- package/src/corpus/templates/portfolio/index.md +30 -0
- package/src/corpus/templates/saas-marketing/README.md +30 -0
- package/src/corpus/templates/saas-marketing/cloudgrid.yaml +10 -0
- package/src/corpus/templates/saas-marketing/index.html +212 -0
- package/src/corpus/templates/saas-marketing/index.md +30 -0
- package/src/corpus/templates/status-page/README.md +28 -0
- package/src/corpus/templates/status-page/cloudgrid.yaml +10 -0
- package/src/corpus/templates/status-page/index.html +117 -0
- package/src/corpus/templates/status-page/index.md +30 -0
- package/src/corpus/templates/task-manager/README.md +72 -0
- package/src/corpus/templates/task-manager/cloudgrid.yaml +15 -0
- package/src/corpus/templates/task-manager/index.md +68 -0
- package/src/corpus/templates/task-manager/services/web/app/api/tasks/route.js +77 -0
- package/src/corpus/templates/task-manager/services/web/app/layout.js +39 -0
- package/src/corpus/templates/task-manager/services/web/app/page.js +33 -0
- package/src/corpus/templates/task-manager/services/web/app/task-list.js +110 -0
- package/src/corpus/templates/task-manager/services/web/lib/db.js +32 -0
- package/src/corpus/templates/task-manager/services/web/package.json +16 -0
- package/src/corpus/templates/waitlist/README.md +38 -0
- package/src/corpus/templates/waitlist/cloudgrid.yaml +10 -0
- package/src/corpus/templates/waitlist/index.html +69 -0
- package/src/corpus/templates/waitlist/index.md +41 -0
- package/src/corpus/workflows/admin-dashboard.md +102 -0
- package/src/corpus/workflows/api-docs.md +36 -0
- package/src/corpus/workflows/changelog.md +33 -0
- package/src/corpus/workflows/crm.md +101 -0
- package/src/corpus/workflows/docs-site.md +35 -0
- package/src/corpus/workflows/kanban.md +102 -0
- package/src/corpus/workflows/portfolio.md +35 -0
- package/src/corpus/workflows/saas-marketing.md +37 -0
- package/src/corpus/workflows/status-page.md +35 -0
- package/src/corpus/workflows/task-manager.md +101 -0
- package/src/corpus/workflows/waitlist.md +42 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Template: api-docs (static)
|
|
2
|
+
|
|
3
|
+
A single self-contained HTML API reference: a sidebar endpoint list, per-endpoint method badges (GET / POST / PUT / DELETE), a params table, and request / response examples in code blocks. **No infrastructure** — no database, no backend, no `needs:`.
|
|
4
|
+
State (if any) lives only in memory and is lost on refresh.
|
|
5
|
+
|
|
6
|
+
## How it deploys
|
|
7
|
+
|
|
8
|
+
To publish this page, use **`gridctl_drop`** (or `gridctl_plug` with the inline
|
|
9
|
+
HTML): it deploys as an **inspiration** — instant, and works on the **hosted**
|
|
10
|
+
edition (Claude Web) as well as local. The reference `cloudgrid.yaml` in this
|
|
11
|
+
directory (`type: static`) is ONLY for plugging the page as an OWNED static
|
|
12
|
+
runtime (async, local edition only); the fast path is `gridctl_drop`.
|
|
13
|
+
|
|
14
|
+
The fillable HTML is the real template — fetch it with
|
|
15
|
+
`gridctl_fetch("template", "api-docs")` and fill in the user's content.
|
|
16
|
+
|
|
17
|
+
## cloudgrid.yaml (reference only)
|
|
18
|
+
|
|
19
|
+
```yaml
|
|
20
|
+
# static — deploys as an inspiration (instant, works on hosted) via gridctl_drop;
|
|
21
|
+
# this yaml is only for plugging it as an OWNED static runtime (async, local
|
|
22
|
+
# edition only). To publish the page, prefer gridctl_drop, not grid plug.
|
|
23
|
+
#
|
|
24
|
+
# needs: {} # none — static, no infrastructure
|
|
25
|
+
name: api-docs
|
|
26
|
+
services:
|
|
27
|
+
web:
|
|
28
|
+
type: static
|
|
29
|
+
path: /
|
|
30
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# changelog
|
|
2
|
+
|
|
3
|
+
A single self-contained HTML changelog / release-notes page: reverse-chronological versioned entries, each with a date and tagged change items (added / fixed / changed / removed).
|
|
4
|
+
|
|
5
|
+
Static inspiration — a single self-contained `index.html` (inline CSS and JS,
|
|
6
|
+
no external CDNs). It deploys instantly via `gridctl_drop` and works on every
|
|
7
|
+
CloudGrid edition, including hosted.
|
|
8
|
+
|
|
9
|
+
## Fill it in
|
|
10
|
+
|
|
11
|
+
Fetch the template with `gridctl_fetch("template", "changelog")`, then replace the
|
|
12
|
+
placeholders:
|
|
13
|
+
|
|
14
|
+
- The product name and page intro.
|
|
15
|
+
- One entry per release, newest first: version, date, and a list of changes.
|
|
16
|
+
- Each change carries a tag pill — added, fixed, changed, or removed — set by its CSS class.
|
|
17
|
+
|
|
18
|
+
Keep it a single self-contained HTML file. Do not add external scripts,
|
|
19
|
+
stylesheets, fonts, or large embedded media.
|
|
20
|
+
|
|
21
|
+
## Deploy
|
|
22
|
+
|
|
23
|
+
- Hosted MCP edition: call the drop tool with the HTML.
|
|
24
|
+
- Local MCP / CLI edition: write the HTML to a file and run `gridctl plug`.
|
|
25
|
+
|
|
26
|
+
It deploys as an inspiration and returns a live share URL right away. Re-deploy
|
|
27
|
+
with the same entity id to update the same URL.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# static — deploys as an inspiration (instant, works on hosted) via gridctl_drop;
|
|
2
|
+
# this yaml is only for plugging it as an OWNED static runtime (async, local
|
|
3
|
+
# edition only). To publish the page, prefer gridctl_drop, not grid plug.
|
|
4
|
+
#
|
|
5
|
+
# needs: {} # none — static, no infrastructure
|
|
6
|
+
name: changelog
|
|
7
|
+
services:
|
|
8
|
+
web:
|
|
9
|
+
type: static
|
|
10
|
+
path: /
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>{{PRODUCT_NAME}} changelog</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
--bg: #0b0f17; --panel: #121826; --fg: #e8edf5; --muted: #9aa7bd;
|
|
10
|
+
--accent: #5b8cff; --border: #223049;
|
|
11
|
+
--added: #34d399; --fixed: #5b8cff; --changed: #fbbf24; --removed: #f87171;
|
|
12
|
+
}
|
|
13
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
14
|
+
body {
|
|
15
|
+
background: var(--bg); color: var(--fg);
|
|
16
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
17
|
+
-webkit-font-smoothing: antialiased; line-height: 1.6;
|
|
18
|
+
}
|
|
19
|
+
.wrap { max-width: 720px; margin: 0 auto; padding: clamp(1.5rem, 5vw, 3.5rem) 1.25rem; }
|
|
20
|
+
header { margin-bottom: 3rem; }
|
|
21
|
+
header h1 { font-size: clamp(2rem, 5vw, 2.8rem); letter-spacing: -0.02em; margin-bottom: 0.5rem; }
|
|
22
|
+
header p { color: var(--muted); }
|
|
23
|
+
|
|
24
|
+
.entry { position: relative; padding-left: 1.5rem; padding-bottom: 2.5rem; border-left: 2px solid var(--border); }
|
|
25
|
+
.entry:last-child { border-left-color: transparent; padding-bottom: 0; }
|
|
26
|
+
.entry::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); }
|
|
27
|
+
.entry .meta { display: flex; align-items: baseline; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
|
|
28
|
+
.entry .version { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.01em; }
|
|
29
|
+
.entry .date { color: var(--muted); font-size: 0.9rem; }
|
|
30
|
+
.entry ul { list-style: none; display: grid; gap: 0.6rem; }
|
|
31
|
+
.entry li { display: flex; gap: 0.65rem; align-items: baseline; color: var(--fg); }
|
|
32
|
+
.tag { flex: none; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
|
|
33
|
+
padding: 0.15rem 0.5rem; border-radius: 6px; min-width: 62px; text-align: center; }
|
|
34
|
+
.tag.added { color: var(--added); background: rgba(52,211,153,0.12); }
|
|
35
|
+
.tag.fixed { color: var(--fixed); background: rgba(91,140,255,0.12); }
|
|
36
|
+
.tag.changed { color: var(--changed); background: rgba(251,191,36,0.12); }
|
|
37
|
+
.tag.removed { color: var(--removed); background: rgba(248,113,113,0.12); }
|
|
38
|
+
.entry li span.text { color: var(--muted); }
|
|
39
|
+
footer { color: var(--muted); font-size: 0.85rem; margin-top: 2rem; text-align: center; }
|
|
40
|
+
</style>
|
|
41
|
+
</head>
|
|
42
|
+
<body>
|
|
43
|
+
<div class="wrap">
|
|
44
|
+
<header>
|
|
45
|
+
<h1>{{PRODUCT_NAME}} changelog</h1>
|
|
46
|
+
<p>{{CHANGELOG_INTRO}}</p>
|
|
47
|
+
</header>
|
|
48
|
+
|
|
49
|
+
<!-- ENTRIES_START -->
|
|
50
|
+
<!-- Newest release first. Each li: <span class="tag TYPE">TYPE</span>
|
|
51
|
+
where TYPE is added / fixed / changed / removed. -->
|
|
52
|
+
<div class="entry">
|
|
53
|
+
<div class="meta">
|
|
54
|
+
<span class="version">{{ENTRY_1_VERSION}}</span>
|
|
55
|
+
<span class="date">{{ENTRY_1_DATE}}</span>
|
|
56
|
+
</div>
|
|
57
|
+
<ul>
|
|
58
|
+
<li><span class="tag added">Added</span><span class="text">{{ENTRY_1_ITEM_1}}</span></li>
|
|
59
|
+
<li><span class="tag fixed">Fixed</span><span class="text">{{ENTRY_1_ITEM_2}}</span></li>
|
|
60
|
+
<li><span class="tag changed">Changed</span><span class="text">{{ENTRY_1_ITEM_3}}</span></li>
|
|
61
|
+
</ul>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div class="entry">
|
|
65
|
+
<div class="meta">
|
|
66
|
+
<span class="version">{{ENTRY_2_VERSION}}</span>
|
|
67
|
+
<span class="date">{{ENTRY_2_DATE}}</span>
|
|
68
|
+
</div>
|
|
69
|
+
<ul>
|
|
70
|
+
<li><span class="tag added">Added</span><span class="text">{{ENTRY_2_ITEM_1}}</span></li>
|
|
71
|
+
<li><span class="tag removed">Removed</span><span class="text">{{ENTRY_2_ITEM_2}}</span></li>
|
|
72
|
+
</ul>
|
|
73
|
+
</div>
|
|
74
|
+
<!-- Add more .entry blocks below, newest first. -->
|
|
75
|
+
<!-- ENTRIES_END -->
|
|
76
|
+
|
|
77
|
+
<footer>{{FOOTER_TEXT}}</footer>
|
|
78
|
+
</div>
|
|
79
|
+
</body>
|
|
80
|
+
</html>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Template: changelog (static)
|
|
2
|
+
|
|
3
|
+
A single self-contained HTML changelog / release-notes page: reverse-chronological versioned entries, each with a date and tagged change items (added / fixed / changed / removed). **No infrastructure** — no database, no backend, no `needs:`.
|
|
4
|
+
State (if any) lives only in memory and is lost on refresh.
|
|
5
|
+
|
|
6
|
+
## How it deploys
|
|
7
|
+
|
|
8
|
+
To publish this page, use **`gridctl_drop`** (or `gridctl_plug` with the inline
|
|
9
|
+
HTML): it deploys as an **inspiration** — instant, and works on the **hosted**
|
|
10
|
+
edition (Claude Web) as well as local. The reference `cloudgrid.yaml` in this
|
|
11
|
+
directory (`type: static`) is ONLY for plugging the page as an OWNED static
|
|
12
|
+
runtime (async, local edition only); the fast path is `gridctl_drop`.
|
|
13
|
+
|
|
14
|
+
The fillable HTML is the real template — fetch it with
|
|
15
|
+
`gridctl_fetch("template", "changelog")` and fill in the user's content.
|
|
16
|
+
|
|
17
|
+
## cloudgrid.yaml (reference only)
|
|
18
|
+
|
|
19
|
+
```yaml
|
|
20
|
+
# static — deploys as an inspiration (instant, works on hosted) via gridctl_drop;
|
|
21
|
+
# this yaml is only for plugging it as an OWNED static runtime (async, local
|
|
22
|
+
# edition only). To publish the page, prefer gridctl_drop, not grid plug.
|
|
23
|
+
#
|
|
24
|
+
# needs: {} # none — static, no infrastructure
|
|
25
|
+
name: changelog
|
|
26
|
+
services:
|
|
27
|
+
web:
|
|
28
|
+
type: static
|
|
29
|
+
path: /
|
|
30
|
+
```
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# crm template — persistent Next.js + Mongo contact manager
|
|
2
|
+
|
|
3
|
+
A real, deployable CRM. Contacts live in the grid-shared MongoDB, so they survive
|
|
4
|
+
refresh and are shared across users/sessions. Same proven shape as
|
|
5
|
+
`app-with-data`, adapted to a `contacts` domain (name, email, company, stage,
|
|
6
|
+
note) with a table view and per-row stage changes.
|
|
7
|
+
|
|
8
|
+
## How the grid gives you a database
|
|
9
|
+
|
|
10
|
+
You do **not** provision a database or set a connection string. In
|
|
11
|
+
`cloudgrid.yaml` you declare `needs: { database: true }`, and the grid:
|
|
12
|
+
|
|
13
|
+
- provisions shared Mongo for the app, and
|
|
14
|
+
- injects the connection string as the **`DATABASE_MONGODB_URL`** environment
|
|
15
|
+
variable (plus the legacy `MONGODB_URL` alias) — at dev-time (`grid dev`) and
|
|
16
|
+
at runtime (after `grid plug`).
|
|
17
|
+
|
|
18
|
+
The app reads it via `process.env.DATABASE_MONGODB_URL` (with a legacy
|
|
19
|
+
`process.env.MONGODB_URL` fallback) in `services/web/lib/db.js` — **lazily,
|
|
20
|
+
inside the `getDb` getter, never at module top level** (a top-level read fails
|
|
21
|
+
`next build`, which imports the module for route analysis before the grid injects
|
|
22
|
+
the var). Never hardcode a connection string; never commit a secret.
|
|
23
|
+
|
|
24
|
+
> **Declare `needs: { database: true }` (the canonical shape).** The deployer
|
|
25
|
+
> provisions Mongo and injects `DATABASE_MONGODB_URL` (plus the legacy
|
|
26
|
+
> `MONGODB_URL` alias). `requires:` is the deprecated v1 alias — don't author new
|
|
27
|
+
> yaml with it, and never set `needs:` and `requires:` together (the validator
|
|
28
|
+
> rejects the combination).
|
|
29
|
+
|
|
30
|
+
## Service layout
|
|
31
|
+
|
|
32
|
+
App code lives under **`services/web/`**, not the template root. `path:` in
|
|
33
|
+
`cloudgrid.yaml` is the URL mount, not the filesystem path — the service named
|
|
34
|
+
`web` means the CLI looks for `services/web/`. Files at the root fail with
|
|
35
|
+
`Error: Service directory not found: …/services/web`.
|
|
36
|
+
|
|
37
|
+
## Run locally
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install
|
|
41
|
+
grid dev # runs Next.js with DATABASE_MONGODB_URL injected against dev Mongo
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Deploy
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
grid plug # builds + deploys the folder (async — poll status until live)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
A runtime deploy is asynchronous: `plug` returns `status: building`; poll status
|
|
51
|
+
until the app is live, then use the returned live URL. Re-plug the same entity
|
|
52
|
+
to update the same URL.
|
|
53
|
+
|
|
54
|
+
## File tree
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
cloudgrid.yaml # name + services.web (nextjs) + needs: { database: true }
|
|
58
|
+
services/web/package.json # next, react, react-dom, mongodb driver only
|
|
59
|
+
services/web/lib/db.js # lazy Mongo client from DATABASE_MONGODB_URL (legacy MONGODB_URL fallback)
|
|
60
|
+
services/web/app/layout.js # root layout + inline CSS
|
|
61
|
+
services/web/app/page.js # server component: reads contacts from Mongo
|
|
62
|
+
services/web/app/contact-manager.js # client table: POST / PATCH (stage) / DELETE via the API
|
|
63
|
+
services/web/app/api/contacts/route.js # GET (list) / POST (add) / PATCH (stage) / DELETE (remove)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Adapt it
|
|
67
|
+
|
|
68
|
+
- Rename the `contacts` collection in `services/web/app/api/contacts/route.js`
|
|
69
|
+
and `services/web/app/page.js` (e.g. `deals`, `companies`).
|
|
70
|
+
- Change the document fields (stages, owners, timestamps, deal values).
|
|
71
|
+
- Add more routes/collections as the CRM grows (companies, deals, activities).
|
|
72
|
+
- Add `cache: true` to `needs:` only if you actually need Redis.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Rename this app. The grid injects the DB connection string as an environment
|
|
2
|
+
# variable at runtime — do NOT set it yourself, and never commit a connection
|
|
3
|
+
# string or secret.
|
|
4
|
+
#
|
|
5
|
+
# `needs: { database: true }` is the canonical, recommended shape. The deployer
|
|
6
|
+
# provisions Mongo and injects DATABASE_MONGODB_URL (plus the legacy MONGODB_URL
|
|
7
|
+
# alias). `requires:` is the deprecated v1 alias — don't author new yaml with it,
|
|
8
|
+
# and never set `needs:` and `requires:` together (the validator rejects it).
|
|
9
|
+
name: my-crm
|
|
10
|
+
services:
|
|
11
|
+
web:
|
|
12
|
+
type: nextjs
|
|
13
|
+
path: /
|
|
14
|
+
needs:
|
|
15
|
+
database: true
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Template: crm (persistent Next.js + Mongo contact manager)
|
|
2
|
+
|
|
3
|
+
A real, deployable CRM. Contacts live in the grid-shared MongoDB, so they survive
|
|
4
|
+
refresh and are shared across sessions. Same proven shape as `app-with-data`,
|
|
5
|
+
adapted to a `contacts` domain (name, email, company, stage, note) with a table
|
|
6
|
+
view and per-row stage changes.
|
|
7
|
+
|
|
8
|
+
**Key rules (all proven by the app-with-data end-to-end deploy):**
|
|
9
|
+
|
|
10
|
+
1. **Service code MUST live under `services/<name>/`, not the repo/template
|
|
11
|
+
root.** `path:` in `cloudgrid.yaml` is the URL mount, NOT the filesystem path.
|
|
12
|
+
The service named `web` → the CLI looks for `services/web/`. App files at the
|
|
13
|
+
root fail with `Error: Service directory not found: …/services/web`.
|
|
14
|
+
2. **Read the DB connection string LAZILY (inside the getter), never at module
|
|
15
|
+
top level.** The grid injects it as `DATABASE_MONGODB_URL` (plus the legacy
|
|
16
|
+
`MONGODB_URL` alias) at dev-time and runtime; the app reads
|
|
17
|
+
`process.env.DATABASE_MONGODB_URL || process.env.MONGODB_URL` inside `getDb`.
|
|
18
|
+
A top-level read fails `next build`. Never hardcode a connection string; never
|
|
19
|
+
commit a secret.
|
|
20
|
+
3. **Declare the datastore with `needs: { database: true }`.** The deployer
|
|
21
|
+
provisions Mongo and injects the connection string. `requires:` is the
|
|
22
|
+
deprecated v1 alias; don't author new yaml with it, and never set `needs:` and
|
|
23
|
+
`requires:` together (the validator rejects the combination).
|
|
24
|
+
|
|
25
|
+
## File tree
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
cloudgrid.yaml # name + services.web (nextjs) + needs: { database: true }
|
|
29
|
+
services/web/package.json # next, react, react-dom, mongodb driver only
|
|
30
|
+
services/web/lib/db.js # lazy Mongo client from DATABASE_MONGODB_URL (legacy MONGODB_URL fallback)
|
|
31
|
+
services/web/app/layout.js # root layout + inline CSS
|
|
32
|
+
services/web/app/page.js # server component: reads contacts from Mongo
|
|
33
|
+
services/web/app/contact-manager.js # client table: POST / PATCH (stage) / DELETE via the API
|
|
34
|
+
services/web/app/api/contacts/route.js # GET (list) / POST (add) / PATCH (stage) / DELETE (remove)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## cloudgrid.yaml
|
|
38
|
+
|
|
39
|
+
```yaml
|
|
40
|
+
name: my-crm
|
|
41
|
+
services:
|
|
42
|
+
web:
|
|
43
|
+
type: nextjs
|
|
44
|
+
path: /
|
|
45
|
+
needs:
|
|
46
|
+
database: true
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
> **Capability:** this template's need is `database: true`. The deployer
|
|
50
|
+
> provisions Mongo and injects `DATABASE_MONGODB_URL` (plus the legacy
|
|
51
|
+
> `MONGODB_URL` alias). `requires:` is the deprecated v1 alias — don't mix it with
|
|
52
|
+
> `needs:` (the validator rejects the combination). See the capability-map for
|
|
53
|
+
> the full injection table.
|
|
54
|
+
|
|
55
|
+
## The contacts collection
|
|
56
|
+
|
|
57
|
+
Documents: `{ name, email, company, stage, note, createdAt }` where `stage` is
|
|
58
|
+
one of `lead` / `qualified` / `customer`. The API route on `contacts` does GET
|
|
59
|
+
(list), POST (add), PATCH (change stage), DELETE (remove); the page is a server
|
|
60
|
+
component that reads the collection and hands it to a client table.
|
|
61
|
+
|
|
62
|
+
## Adapt it
|
|
63
|
+
|
|
64
|
+
- Rename the `contacts` collection to your data (`deals`, `companies`).
|
|
65
|
+
- Change the document fields; add owners, timestamps, deal values.
|
|
66
|
+
- Add more routes/collections as the CRM grows.
|
|
67
|
+
- Add `cache: true` to `needs:` only if you actually need Redis.
|
|
68
|
+
- Run `grid dev` to test locally, `grid plug` to deploy (async — poll to live).
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// App Router route handler for the `contacts` collection.
|
|
2
|
+
// GET -> list contacts, POST -> add a contact, PATCH -> update stage/fields,
|
|
3
|
+
// DELETE -> remove a contact by id.
|
|
4
|
+
//
|
|
5
|
+
// To adapt this app, rename the collection and change the fields to match your
|
|
6
|
+
// own data (e.g. a `companies` or `deals` collection).
|
|
7
|
+
import { NextResponse } from "next/server";
|
|
8
|
+
import { ObjectId } from "mongodb";
|
|
9
|
+
import { getDb } from "../../../lib/db.js";
|
|
10
|
+
|
|
11
|
+
// Never cache — always read/write live data.
|
|
12
|
+
export const dynamic = "force-dynamic";
|
|
13
|
+
|
|
14
|
+
const STAGES = ["lead", "qualified", "customer"];
|
|
15
|
+
|
|
16
|
+
async function contacts() {
|
|
17
|
+
const db = await getDb();
|
|
18
|
+
return db.collection("contacts");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function shape(c) {
|
|
22
|
+
return {
|
|
23
|
+
id: c._id.toString(),
|
|
24
|
+
name: c.name || "",
|
|
25
|
+
email: c.email || "",
|
|
26
|
+
company: c.company || "",
|
|
27
|
+
stage: STAGES.includes(c.stage) ? c.stage : "lead",
|
|
28
|
+
note: c.note || "",
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// GET /api/contacts — list all contacts, newest first.
|
|
33
|
+
export async function GET() {
|
|
34
|
+
const col = await contacts();
|
|
35
|
+
const items = await col.find({}).sort({ createdAt: -1 }).toArray();
|
|
36
|
+
return NextResponse.json(items.map(shape));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// POST /api/contacts — add a contact. Body: { name, email, company, stage, note }.
|
|
40
|
+
export async function POST(request) {
|
|
41
|
+
const body = await request.json().catch(() => ({}));
|
|
42
|
+
const name = typeof body.name === "string" ? body.name.trim() : "";
|
|
43
|
+
if (!name) {
|
|
44
|
+
return NextResponse.json({ error: "name is required" }, { status: 400 });
|
|
45
|
+
}
|
|
46
|
+
const doc = {
|
|
47
|
+
name,
|
|
48
|
+
email: typeof body.email === "string" ? body.email.trim() : "",
|
|
49
|
+
company: typeof body.company === "string" ? body.company.trim() : "",
|
|
50
|
+
stage: STAGES.includes(body.stage) ? body.stage : "lead",
|
|
51
|
+
note: typeof body.note === "string" ? body.note.trim() : "",
|
|
52
|
+
createdAt: new Date(),
|
|
53
|
+
};
|
|
54
|
+
const col = await contacts();
|
|
55
|
+
const res = await col.insertOne(doc);
|
|
56
|
+
return NextResponse.json({ id: res.insertedId.toString(), ...doc }, { status: 201 });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// PATCH /api/contacts — update a contact's stage (or other fields). Body: { id, stage }.
|
|
60
|
+
export async function PATCH(request) {
|
|
61
|
+
const body = await request.json().catch(() => ({}));
|
|
62
|
+
const { id, stage } = body;
|
|
63
|
+
if (!id || !ObjectId.isValid(id) || !STAGES.includes(stage)) {
|
|
64
|
+
return NextResponse.json({ error: "valid id and stage required" }, { status: 400 });
|
|
65
|
+
}
|
|
66
|
+
const col = await contacts();
|
|
67
|
+
await col.updateOne({ _id: new ObjectId(id) }, { $set: { stage } });
|
|
68
|
+
return NextResponse.json({ ok: true });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// DELETE /api/contacts?id=<id> — remove a contact.
|
|
72
|
+
export async function DELETE(request) {
|
|
73
|
+
const id = new URL(request.url).searchParams.get("id");
|
|
74
|
+
if (!id || !ObjectId.isValid(id)) {
|
|
75
|
+
return NextResponse.json({ error: "valid id is required" }, { status: 400 });
|
|
76
|
+
}
|
|
77
|
+
const col = await contacts();
|
|
78
|
+
await col.deleteOne({ _id: new ObjectId(id) });
|
|
79
|
+
return NextResponse.json({ ok: true });
|
|
80
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// Small client component: renders the contacts table and posts to /api/contacts.
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
|
|
6
|
+
const STAGES = ["lead", "qualified", "customer"];
|
|
7
|
+
const LABELS = { lead: "Lead", qualified: "Qualified", customer: "Customer" };
|
|
8
|
+
|
|
9
|
+
export default function ContactManager({ initialContacts }) {
|
|
10
|
+
const [contacts, setContacts] = useState(initialContacts);
|
|
11
|
+
const [name, setName] = useState("");
|
|
12
|
+
const [email, setEmail] = useState("");
|
|
13
|
+
const [company, setCompany] = useState("");
|
|
14
|
+
const [busy, setBusy] = useState(false);
|
|
15
|
+
|
|
16
|
+
async function add(e) {
|
|
17
|
+
e.preventDefault();
|
|
18
|
+
const value = name.trim();
|
|
19
|
+
if (!value) return;
|
|
20
|
+
setBusy(true);
|
|
21
|
+
const res = await fetch("/api/contacts", {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: { "content-type": "application/json" },
|
|
24
|
+
body: JSON.stringify({ name: value, email, company }),
|
|
25
|
+
});
|
|
26
|
+
if (res.ok) {
|
|
27
|
+
const contact = await res.json();
|
|
28
|
+
setContacts((prev) => [contact, ...prev]);
|
|
29
|
+
setName("");
|
|
30
|
+
setEmail("");
|
|
31
|
+
setCompany("");
|
|
32
|
+
}
|
|
33
|
+
setBusy(false);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function setStage(id, stage) {
|
|
37
|
+
setBusy(true);
|
|
38
|
+
const res = await fetch("/api/contacts", {
|
|
39
|
+
method: "PATCH",
|
|
40
|
+
headers: { "content-type": "application/json" },
|
|
41
|
+
body: JSON.stringify({ id, stage }),
|
|
42
|
+
});
|
|
43
|
+
if (res.ok) setContacts((prev) => prev.map((c) => (c.id === id ? { ...c, stage } : c)));
|
|
44
|
+
setBusy(false);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function remove(id) {
|
|
48
|
+
setBusy(true);
|
|
49
|
+
const res = await fetch(`/api/contacts?id=${encodeURIComponent(id)}`, { method: "DELETE" });
|
|
50
|
+
if (res.ok) setContacts((prev) => prev.filter((c) => c.id !== id));
|
|
51
|
+
setBusy(false);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div>
|
|
56
|
+
<form onSubmit={add} className="row">
|
|
57
|
+
<input value={name} onChange={(e) => setName(e.target.value)} placeholder="Name" aria-label="Name" />
|
|
58
|
+
<input value={email} onChange={(e) => setEmail(e.target.value)} placeholder="Email" aria-label="Email" />
|
|
59
|
+
<input value={company} onChange={(e) => setCompany(e.target.value)} placeholder="Company" aria-label="Company" />
|
|
60
|
+
<button type="submit" disabled={busy}>Add</button>
|
|
61
|
+
</form>
|
|
62
|
+
<table>
|
|
63
|
+
<thead>
|
|
64
|
+
<tr>
|
|
65
|
+
<th>Name</th>
|
|
66
|
+
<th>Email</th>
|
|
67
|
+
<th>Company</th>
|
|
68
|
+
<th>Stage</th>
|
|
69
|
+
<th></th>
|
|
70
|
+
</tr>
|
|
71
|
+
</thead>
|
|
72
|
+
<tbody>
|
|
73
|
+
{contacts.length === 0 && (
|
|
74
|
+
<tr><td className="empty" colSpan={5}>No contacts yet.</td></tr>
|
|
75
|
+
)}
|
|
76
|
+
{contacts.map((c) => (
|
|
77
|
+
<tr key={c.id}>
|
|
78
|
+
<td>{c.name}</td>
|
|
79
|
+
<td>{c.email}</td>
|
|
80
|
+
<td>{c.company}</td>
|
|
81
|
+
<td>
|
|
82
|
+
<select
|
|
83
|
+
value={c.stage}
|
|
84
|
+
onChange={(e) => setStage(c.id, e.target.value)}
|
|
85
|
+
disabled={busy}
|
|
86
|
+
aria-label="Stage"
|
|
87
|
+
>
|
|
88
|
+
{STAGES.map((s) => (
|
|
89
|
+
<option key={s} value={s}>{LABELS[s]}</option>
|
|
90
|
+
))}
|
|
91
|
+
</select>
|
|
92
|
+
</td>
|
|
93
|
+
<td>
|
|
94
|
+
<button type="button" onClick={() => remove(c.id)} disabled={busy}>Delete</button>
|
|
95
|
+
</td>
|
|
96
|
+
</tr>
|
|
97
|
+
))}
|
|
98
|
+
</tbody>
|
|
99
|
+
</table>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Root layout + plain inline CSS (no external CDNs, fonts, or stylesheets).
|
|
2
|
+
export const metadata = {
|
|
3
|
+
title: "CRM",
|
|
4
|
+
description: "A persistent contact CRM on CloudGrid, backed by grid-shared Mongo.",
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const css = `
|
|
8
|
+
:root { color-scheme: light dark; }
|
|
9
|
+
* { box-sizing: border-box; }
|
|
10
|
+
body { margin: 0; font-family: system-ui, -apple-system, sans-serif; line-height: 1.5; }
|
|
11
|
+
main { max-width: 60rem; margin: 3rem auto; padding: 0 1.25rem; }
|
|
12
|
+
h1 { margin: 0 0 .25rem; }
|
|
13
|
+
.hint { margin: 0 0 1.5rem; opacity: .7; font-size: .9rem; }
|
|
14
|
+
.row { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.5rem; }
|
|
15
|
+
input, select { padding: .5rem .75rem; border: 1px solid #8886; border-radius: .5rem; font: inherit; }
|
|
16
|
+
input { flex: 1; min-width: 8rem; }
|
|
17
|
+
button { padding: .5rem .9rem; border: 1px solid #8886; border-radius: .5rem; background: #6663; font: inherit; cursor: pointer; }
|
|
18
|
+
button:disabled { opacity: .5; cursor: default; }
|
|
19
|
+
table { width: 100%; border-collapse: collapse; }
|
|
20
|
+
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid #8883; vertical-align: top; }
|
|
21
|
+
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; opacity: .7; }
|
|
22
|
+
.stage { font-size: .8rem; padding: .15rem .5rem; border: 1px solid #8886; border-radius: 1rem; }
|
|
23
|
+
.empty { opacity: .6; }
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export default function RootLayout({ children }) {
|
|
27
|
+
return (
|
|
28
|
+
<html lang="en">
|
|
29
|
+
<head>
|
|
30
|
+
<style dangerouslySetInnerHTML={{ __html: css }} />
|
|
31
|
+
</head>
|
|
32
|
+
<body>{children}</body>
|
|
33
|
+
</html>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Home page: a server component reads the contacts straight from Mongo, and a
|
|
2
|
+
// small client component adds / restages / removes them via the API route. Data
|
|
3
|
+
// persists across refresh and across users because it lives in the grid-shared
|
|
4
|
+
// Mongo, not in memory.
|
|
5
|
+
import { getDb } from "../lib/db.js";
|
|
6
|
+
import ContactManager from "./contact-manager.js";
|
|
7
|
+
|
|
8
|
+
export const dynamic = "force-dynamic";
|
|
9
|
+
|
|
10
|
+
const STAGES = ["lead", "qualified", "customer"];
|
|
11
|
+
|
|
12
|
+
async function listContacts() {
|
|
13
|
+
const db = await getDb();
|
|
14
|
+
const items = await db.collection("contacts").find({}).sort({ createdAt: -1 }).toArray();
|
|
15
|
+
return items.map((c) => ({
|
|
16
|
+
id: c._id.toString(),
|
|
17
|
+
name: c.name || "",
|
|
18
|
+
email: c.email || "",
|
|
19
|
+
company: c.company || "",
|
|
20
|
+
stage: STAGES.includes(c.stage) ? c.stage : "lead",
|
|
21
|
+
note: c.note || "",
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default async function Page() {
|
|
26
|
+
const contacts = await listContacts();
|
|
27
|
+
return (
|
|
28
|
+
<main>
|
|
29
|
+
<h1>Contacts</h1>
|
|
30
|
+
<p className="hint">Persisted in the grid-shared Mongo — survives refresh.</p>
|
|
31
|
+
<ContactManager initialContacts={contacts} />
|
|
32
|
+
</main>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Cached MongoDB client for the App Router.
|
|
2
|
+
//
|
|
3
|
+
// The grid injects the connection string as the DATABASE_MONGODB_URL environment
|
|
4
|
+
// variable (plus the legacy MONGODB_URL alias) at dev-time (`grid dev`) and
|
|
5
|
+
// runtime (after `grid plug`). Read the canonical var first, fall back to the
|
|
6
|
+
// legacy alias. Never hardcode a connection string here and never commit a secret.
|
|
7
|
+
//
|
|
8
|
+
// The env var and client are resolved LAZILY (inside getDb), never at module top
|
|
9
|
+
// level — otherwise `next build` throws when it imports this module for route
|
|
10
|
+
// analysis, before the grid injects the var.
|
|
11
|
+
import { MongoClient } from "mongodb";
|
|
12
|
+
|
|
13
|
+
function clientPromise() {
|
|
14
|
+
const uri = process.env.DATABASE_MONGODB_URL || process.env.MONGODB_URL;
|
|
15
|
+
if (!uri) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
"DATABASE_MONGODB_URL is not set. The grid injects it automatically — run " +
|
|
18
|
+
"this app with `grid dev` locally, or deploy it with `grid plug` (the grid " +
|
|
19
|
+
"injects the DB connection string at runtime). Do not set it by hand.",
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
if (!globalThis.__mongoClientPromise) {
|
|
23
|
+
globalThis.__mongoClientPromise = new MongoClient(uri).connect();
|
|
24
|
+
}
|
|
25
|
+
return globalThis.__mongoClientPromise;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function getDb() {
|
|
29
|
+
const client = await clientPromise();
|
|
30
|
+
// The default DB comes from the connection-string path segment the grid injects.
|
|
31
|
+
return client.db();
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-crm",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "next dev",
|
|
7
|
+
"build": "next build",
|
|
8
|
+
"start": "next start"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"next": "^15.1.0",
|
|
12
|
+
"react": "^19.0.0",
|
|
13
|
+
"react-dom": "^19.0.0",
|
|
14
|
+
"mongodb": "^6.12.0"
|
|
15
|
+
}
|
|
16
|
+
}
|