Skip to content

Commit 1668fb4

Browse files
Merge pull request #383 from contentstack/fix/dx-6049-update-cursor-rules-skills
docs: add AGENTS.md, skills, and Cursor rules entry
2 parents 402adba + 98a69cd commit 1668fb4

File tree

7 files changed

+150
-187
lines changed

7 files changed

+150
-187
lines changed

.cursor/rules/README.md

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,5 @@
1-
# Cursor Rules Documentation
1+
# Cursor (optional)
22

3-
This directory contains **Cursor AI rules** for the **Contentstack JavaScript Content Delivery SDK** (`contentstack` on npm) — CDA client development in this repository.
3+
**Cursor** users: start at **[AGENTS.md](../../AGENTS.md)**. All conventions live in **`skills/*/SKILL.md`**.
44

5-
## Rules overview
6-
7-
| Rule | Role |
8-
|------|------|
9-
| [`dev-workflow.md`](dev-workflow.md) | Branches, lint/tests before PR, build + version bump guidance, links to skills |
10-
| [`javascript.mdc`](javascript.mdc) | JavaScript / TypeScript declaration style: `src/`, `webpack/`, root `index.d.ts` |
11-
| [`contentstack-javascript-cda.mdc`](contentstack-javascript-cda.mdc) | CDA SDK patterns: `Stack`, delivery token, host/region, request/cache/live preview |
12-
| [`testing.mdc`](testing.mdc) | Jest e2e (`test/**/*.js`) and TypeScript tests; `test/config.js` env |
13-
| [`code-review.mdc`](code-review.mdc) | PR checklist: JSDoc, `index.d.ts`, compat, errors, tests, CDA semantics (**always applied**) |
14-
15-
## Rule application
16-
17-
Rules load from **globs** and **`alwaysApply`** in each file’s frontmatter.
18-
19-
| Context | Typical rules |
20-
|---------|----------------|
21-
| **Every chat / session** | [`code-review.mdc`](code-review.mdc) (`alwaysApply: true`) |
22-
| **Most project files** | [`dev-workflow.md`](dev-workflow.md)`**/*.js`, `**/*.ts`, `**/*.json` |
23-
| **SDK implementation** | [`javascript.mdc`](javascript.mdc) + [`contentstack-javascript-cda.mdc`](contentstack-javascript-cda.mdc) for `src/**/*.js` |
24-
| **Build config** | [`javascript.mdc`](javascript.mdc) for `webpack/**/*.js` |
25-
| **Public types** | [`javascript.mdc`](javascript.mdc) for `index.d.ts` |
26-
| **Tests** | [`testing.mdc`](testing.mdc) for `test/**/*.js`, `test/**/*.ts` |
27-
28-
Overlaps are expected (e.g. editing `src/core/stack.js` can match `dev-workflow`, `javascript`, and `contentstack-javascript-cda`).
29-
30-
## Usage
31-
32-
- Rules load automatically when opened files match their globs (`code-review` is always in context).
33-
- You can **@ mention** rule files in chat when supported.
34-
35-
## Quick reference table
36-
37-
| File | `alwaysApply` | Globs (summary) |
38-
|------|---------------|-----------------|
39-
| `dev-workflow.md` | no | `**/*.js`, `**/*.ts`, `**/*.json` |
40-
| `javascript.mdc` | no | `src/**/*.js`, `webpack/**/*.js`, `index.d.ts` |
41-
| `contentstack-javascript-cda.mdc` | no | `src/**/*.js` |
42-
| `testing.mdc` | no | `test/**/*.js`, `test/**/*.ts` |
43-
| `code-review.mdc` | **yes** ||
44-
45-
## Skills & maintenance
46-
47-
- Deeper playbooks: [`skills/README.md`](../../skills/README.md).
48-
- Repo agent entry: [`AGENTS.md`](../../AGENTS.md).
49-
- When directories change, update **globs** in rule frontmatter; keep rules short and put detail in `skills/*/SKILL.md`.
5+
This folder only points contributors to **`AGENTS.md`** so editor-specific config does not duplicate the canonical docs.

AGENTS.md

Lines changed: 37 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,43 @@
1-
# AGENTS.md — AI / automation context
1+
# Contentstack JavaScript Delivery SDK – Agent guide
22

3-
## Project
3+
**Universal entry point** for contributors and AI agents. Detailed conventions live in **`skills/*/SKILL.md`**.
44

5-
| | |
6-
|---|---|
7-
| **Name** | **`contentstack`** (npm) — **Contentstack JavaScript Content Delivery SDK** |
8-
| **Purpose** | Client for the **Content Delivery API (CDA)**: read published content, assets, taxonomies, sync, and live preview from a stack. *(This is not the Content Management API / CMA client — see `@contentstack/management`.)* |
9-
| **Repository** | [contentstack/contentstack-javascript](https://github.com/contentstack/contentstack-javascript.git) |
5+
## What this repo is
106

11-
## Tech stack
7+
| Field | Detail |
8+
|--------|--------|
9+
| **Name:** | [contentstack-javascript](https://github.com/contentstack/contentstack-javascript) (npm package **`contentstack`**) |
10+
| **Purpose:** | Legacy **JavaScript** Content Delivery SDK for browsers, Node.js, React Native, and NativeScript—stack initialization, queries, entries, assets. |
11+
| **Out of scope:** | Not the TypeScript-first **`@contentstack/delivery-sdk`** (`contentstack-typescript`); new TypeScript projects should prefer that package when appropriate. |
12+
13+
## Tech stack (at a glance)
1214

1315
| Area | Details |
1416
|------|---------|
15-
| **Language** | JavaScript **ES modules** in `src/core/` and `src/runtime/`; public types in root **`index.d.ts`** |
16-
| **Runtime** | Node `>= 10.14.2` per `package.json` `engines` |
17-
| **Build** | **Webpack** bundles for `node`, `web`, `react-native`, `nativescript``dist/` (`npm run build`) |
18-
| **Lint / style** | **ESLint** with `eslint-config-standard`, **`@babel/eslint-parser`**; **semicolons required** (see `.eslintrc.js`) |
19-
| **Tests** | **Jest**: JS e2e-style suite (`jest.js.config.js`, `test/**/*.js`) and **TypeScript** tests (`jest.config.js`, `test/typescript/**/*.test.ts`) |
20-
| **HTTP** | Platform **`fetch`** via webpack alias `runtime/http.js` and `runtime/localstorage.js` (Node / web / React Native / NativeScript) |
21-
| **Helpers** | **`@contentstack/utils`** re-exported on the `Contentstack` instance |
22-
23-
## Source layout & public entrypoints
24-
25-
| Path | Role |
26-
|------|------|
27-
| `src/core/contentstack.js` | Package facade: `Stack()`, `CachePolicy`, `Region`, `Utils` |
28-
| `src/core/stack.js` | `Stack` class: delivery config, queries, sync, plugins, `fetchOptions` |
29-
| `src/core/lib/request.js` | CDA requests: query serialization, retries, plugins `onRequest` / `onResponse` |
30-
| `src/core/lib/utils.js` | Shared helpers |
31-
| `src/core/modules/*` | Entry, Query, Assets, Taxonomy, Result, etc. |
32-
| `src/core/cache*.js`, `src/core/cache-provider/` | Cache policies and providers |
33-
| `src/runtime/**` | Per-platform `http` and `localstorage` implementations |
34-
| `config.js` | Default CDN host, API version, URL paths (imported by `stack.js`) |
35-
| `webpack/` | Build configs per target |
36-
| `dist/**` | Built artifacts (`package.json` `main` / `browser` / `react-native`) |
37-
38-
## Common commands
39-
40-
```bash
41-
npm install
42-
npm run build # all webpack targets (also runs on prepare / pretest)
43-
npm run lint # eslint src test
44-
npm run format # eslint src test --fix
45-
npm run test # test:e2e + test:typescript (pretest runs build)
46-
npm run test:e2e # Jest JS tests under test/ (see jest.js.config.js)
47-
npm run test:typescript # Jest + ts-jest for test/typescript
48-
npm run generate-docs # JSDoc (docs-config.json)
49-
```
50-
51-
**Live API tests**
52-
53-
- **`test/config.js`** loads **`.env`** and **requires** `HOST`, `API_KEY`, `DELIVERY_TOKEN`, `ENVIRONMENT`. Without them, importing `test/config.js` throws.
54-
- Jest e2e tests use **`dist/node/contentstack.js`** (built output). Run **`npm run build`** (or `npm test`, which runs `pretest`) before relying on fresh `src/` changes.
55-
56-
## Further guidance
57-
58-
- **Cursor rules:** [`.cursor/rules/README.md`](.cursor/rules/README.md)
59-
- **Deeper playbooks:** [`skills/README.md`](skills/README.md)
60-
61-
When unsure about API behavior, prefer the official [Content Delivery API](https://www.contentstack.com/docs/developers/apis/content-delivery-api/) documentation and existing JSDoc in `src/core/`.
17+
| Language | JavaScript in **`src/`**; TypeScript tests via Jest (`test/typescript`) |
18+
| Build | Webpack configs under **`webpack/`**; outputs under **`dist/`** per target (`npm run build`) |
19+
| Tests | Jest: **`test:e2e`** (`jest.js.config.js`) and **`test:typescript`** (`jest.config.js`); **`pretest`** runs **`build`** first |
20+
| Lint / coverage | ESLint on `src` and `test` (`npm run lint`) |
21+
| CI | `.github/workflows/check-branch.yml`, `npm-publish.yml`, `sca-scan.yml`, `policy-scan.yml`, `codeql-analysis.yml`, `link-check.yml`, `issues-jira.yml` |
22+
23+
## Commands (quick reference)
24+
25+
| Command type | Command |
26+
|--------------|---------|
27+
| Build | `npm run build` |
28+
| Test | `npm test` (build via `pretest`, then e2e + TypeScript Jest suites) |
29+
| Lint | `npm run lint` |
30+
31+
## Where the documentation lives: skills
32+
33+
| Skill | Path | What it covers |
34+
|-------|------|----------------|
35+
| **Development workflow** | [`skills/dev-workflow/SKILL.md`](skills/dev-workflow/SKILL.md) | Branches, npm scripts, Husky, CI |
36+
| **JavaScript SDK** | [`skills/contentstack-javascript-sdk/SKILL.md`](skills/contentstack-javascript-sdk/SKILL.md) | Public API (`Stack`, regions), `@contentstack/utils` |
37+
| **JavaScript tooling** | [`skills/javascript/SKILL.md`](skills/javascript/SKILL.md) | Webpack targets, `dist/` layout, Babel |
38+
| **Testing** | [`skills/testing/SKILL.md`](skills/testing/SKILL.md) | Jest configs, e2e vs TypeScript tests |
39+
| **Code review** | [`skills/code-review/SKILL.md`](skills/code-review/SKILL.md) | PR checklist |
40+
41+
## Using Cursor (optional)
42+
43+
If you use **Cursor**, [`.cursor/rules/README.md`](.cursor/rules/README.md) only points to **`AGENTS.md`**—same docs as everyone else.

skills/code-review/SKILL.md

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,27 @@
11
---
22
name: code-review
3-
description: Use when reviewing PRs or before opening a PR — API design, errors, backward compatibility, dependencies, security, and test quality for the CDA SDK.
3+
description: Use when reviewing PRs for contentstack-javascript—API compatibility, bundles, Jest, and npm/CDN impact.
44
---
55

6-
# Code review — Contentstack JavaScript CDA SDK
7-
8-
Use this skill for pull request review or self-review of the **`contentstack`** package (**Content Delivery API** client — not `@contentstack/management` / CMA).
6+
# Code review – contentstack-javascript
97

108
## When to use
119

12-
- Reviewing someone else’s PR.
13-
- Self-reviewing before submission.
14-
- Checking API, error, compatibility, tests, and security expectations.
10+
- Reviewing SDK or Webpack changes
11+
- Assessing dependency bumps (`@contentstack/utils`, Babel, Webpack, Jest)
1512

1613
## Instructions
1714

18-
Work through the checklist. Optionally tag severity: **Blocker**, **Major**, **Minor**.
19-
20-
### 1. API design and stability
21-
22-
- [ ] **Public API:** New or changed exports are documented with **JSDoc**, consistent with `src/core/contentstack.js` and `src/core/stack.js`.
23-
- [ ] **TypeScript surface:** **`index.d.ts`** updated when consumers would see new or changed signatures.
24-
- [ ] **Backward compatibility:** No breaking changes to public signatures, option objects, or defaults without an agreed major bump.
25-
- [ ] **Naming:** Consistent with **CDA** concepts (stack, entry, query, asset, taxonomy, sync, environment).
26-
27-
**Severity:** Breaking public API without approval = **Blocker**. Missing JSDoc or types on new public API = **Major**.
28-
29-
### 2. Error handling and robustness
30-
31-
- [ ] **Errors:** Rejections align with **`src/core/lib/request.js`** patterns (`error_message`, `error_code`, `errors`, `status`, `statusText` when JSON is available).
32-
- [ ] **Null safety:** Guard optional nested fields from API responses.
33-
- [ ] **Secrets:** No logging of full **delivery_token**, **preview_token**, **management_token**, or **api_key**.
34-
35-
**Severity:** Missing or inconsistent error handling on new paths = **Major**.
36-
37-
### 3. Dependencies and security
38-
39-
- [ ] **Dependencies:** New or upgraded packages are justified; lockfile changes are intentional.
40-
- [ ] **SCA:** Address or explicitly track security findings from org tooling (Snyk, Dependabot, etc.).
41-
42-
**Severity:** Unaddressed critical/high issues in scope = **Blocker**.
43-
44-
### 4. Testing
45-
46-
- [ ] **Jest:** New or changed behavior has coverage under **`test/`** (JS and/or **`test/typescript/`**).
47-
- [ ] **Live tests:** If tests hit the network, they respect **`test/config.js`** (`HOST`, `API_KEY`, `DELIVERY_TOKEN`, `ENVIRONMENT`); no committed secrets.
48-
- [ ] **Build:** Fresh `src/` changes are validated against **`dist/node/contentstack.js`** after **`npm run build`** when tests import dist.
49-
50-
**Severity:** No tests for new behavior = **Blocker** (unless truly docs-only). Flaky tests = **Major**.
51-
52-
### 5. Optional severity summary
15+
### Checklist
5316

54-
- **Blocker:** Must fix before merge.
55-
- **Major:** Should fix before or soon after merge.
56-
- **Minor:** Nice to fix.
17+
- **Semver**: Breaking changes for npm and **jsDelivr** consumers called out with major bump and release notes.
18+
- **Bundles**: Each target still builds; `package.json` entry points remain valid.
19+
- **Tests**: `npm test` and `npm run lint` succeed for the change set.
20+
- **Docs**: README or JSDoc updated for user-visible behavior.
21+
- **Security**: No API keys in tests or docs.
5722

58-
## References
23+
### Severity hints
5924

60-
- `.cursor/rules/code-review.mdc`
61-
- `.cursor/rules/dev-workflow.md`
62-
- `skills/testing/SKILL.md`
25+
- **Blocker**: Broken `dist/` layout, failing CI, or regression in core `Stack` flow.
26+
- **Major**: Missing tests for new API surface or cross-environment behavior.
27+
- **Minor**: Internal refactors with full green tests.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: contentstack-javascript-sdk
3+
description: Use for the contentstack npm package API—Stack, regions, queries, and @contentstack/utils usage.
4+
---
5+
6+
# JavaScript Delivery SDK – contentstack-javascript
7+
8+
## When to use
9+
10+
- Changing how consumers call **`Contentstack.Stack(...)`** or Delivery API wrappers
11+
- Updating **`@contentstack/utils`** or cross-runtime behavior (browser vs Node vs RN)
12+
13+
## Instructions
14+
15+
### Package surface
16+
17+
- Published as **`contentstack`** on npm; entry fields in **`package.json`** point to **`dist/node`**, **`dist/web`**, **`dist/react-native`**, etc.
18+
19+
### API stability
20+
21+
- This SDK has a long-lived **3.x** line—treat breaking changes as **semver major** and document migration for CDN and npm users.
22+
23+
### Boundaries
24+
25+
- Keep browser bundles free of Node-only APIs; keep Node builds free of DOM assumptions unless guarded.
26+
- Align behavior with other CDA SDKs where features overlap (regions, preview, sync) and update **`README.md`** examples when user-facing options change.

skills/dev-workflow/SKILL.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: dev-workflow
3+
description: Use for npm scripts, Husky, CI, and branch workflow in contentstack-javascript.
4+
---
5+
6+
# Development workflow – contentstack-javascript
7+
8+
## When to use
9+
10+
- Running builds or tests before a PR
11+
- Aligning with GitHub Actions (branch checks, publish, SCA)
12+
13+
## Instructions
14+
15+
### Branches
16+
17+
- Default branch is **`master`** (`origin/HEAD`); **`development`** and **`next`** also exist—confirm PR target with the team.
18+
19+
### Commands
20+
21+
- **`npm run build`** — all Webpack targets (node, web, react-native, native-script).
22+
- **`npm test`** — runs **`pretest`** (which builds) then **`test:e2e`** and **`test:typescript`**.
23+
- **`npm run lint`** — ESLint on `src` and `test`.
24+
25+
### Hooks
26+
27+
- **`prepare`** runs **`build`** on install—expect compile time after dependency changes.
28+
- **`husky-check`** script wires Husky for pre-commit hooks when used.
29+
30+
### CI
31+
32+
- Workflows under **`.github/workflows/`** include npm publish, CodeQL, SCA, policy scans, and link checks.

skills/javascript/SKILL.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: javascript
3+
description: Use for Webpack configs, multi-target dist outputs, and Babel/loader setup in contentstack-javascript.
4+
---
5+
6+
# JavaScript tooling – contentstack-javascript
7+
8+
## When to use
9+
10+
- Editing **`webpack/*.js`** or changing how `src` is bundled per platform
11+
- Debugging path or env differences between **node**, **web**, **react-native**, and **nativescript** builds
12+
13+
## Instructions
14+
15+
### Webpack
16+
17+
- Each target has its own config (`webpack.node.js`, `webpack.web.js`, etc.)—keep shared options consistent via **`webpack-merge`** where the repo already does.
18+
19+
### Outputs
20+
21+
- Artifacts land under **`dist/`**—verify **`package.json`** `main` / `browser` / `react-native` fields after changing filenames or folders.
22+
23+
### Types
24+
25+
- **`index.d.ts`** ships typings—update when public JS exports or options change.

skills/testing/SKILL.md

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,26 @@
11
---
22
name: testing
3-
description: How to run and extend tests — Jest e2e (test/*.js), TypeScript tests, test/config.js env, dist build.
3+
description: Use for Jest e2e and TypeScript test suites, jest configs, and test layout in contentstack-javascript.
44
---
55

6-
# Testing skill — `contentstack` (CDA)
6+
# Testing contentstack-javascript
77

8-
## Commands (from `package.json`)
8+
## When to use
99

10-
| Goal | Command |
11-
|------|---------|
12-
| Lint | `npm run lint` |
13-
| Full test (includes build) | `npm test` — runs **`pretest`****`npm run build`**, then **`test:e2e`** + **`test:typescript`** |
14-
| JS Jest suite only | `npm run test:e2e` — config: **`jest.js.config.js`** |
15-
| TypeScript / Jest | `npm run test:typescript` — config: **`jest.config.js`** |
16-
| Build | `npm run build` — required before trusting **`dist/`** against updated `src/` |
10+
- Adding tests under **`test/`** or adjusting **`jest.js.config.js`** / **`jest.config.js`**
11+
- Debugging failures that only appear after **`pretest` / build**
1712

18-
## JS tests (`test/**/*.js`)
13+
## Instructions
1914

20-
- Wired from **`test/index.js`** via `require(...)`.
21-
- **`jest.js.config.js`** sets `testEnvironment: node`, HTML reporters, and **ignore patterns** for `test/index.js`, `test/config.js`, `test/sync_config.js`, and certain `utils.js` paths — check the config when adding files.
15+
### Suites
2216

23-
## Environment variables (live stack)
17+
- **`npm run test:e2e`** — Jest with **`jest.js.config.js`**.
18+
- **`npm run test:typescript`** — Jest with **`jest.config.js`**, limited to **`test/typescript`** paths.
2419

25-
**Authoritative validation:** **`test/config.js`** (uses **dotenv**).
20+
### Order
2621

27-
**Required** when importing `test/config.js` (used by tests that need stack credentials):
22+
- Full **`npm test`** runs e2e then TypeScript tests; both assume a fresh **`build`** (via **`pretest`**).
2823

29-
- **`HOST`** — delivery API host for your region/stack
30-
- **`API_KEY`**
31-
- **`DELIVERY_TOKEN`**
32-
- **`ENVIRONMENT`**
24+
### Hygiene
3325

34-
If any are missing, the process throws on import. Use a local **`.env`**; never commit real tokens.
35-
36-
## TypeScript tests (`test/typescript/`)
37-
38-
- **`jest.config.js`**: **ts-jest**, transforms for TS/JS; HTML report under **`typescript-html-report/`** per config.
39-
- Use for type-level and behavioral checks against the public SDK shape; keep assertions aligned with **`index.d.ts`**.
40-
41-
## Hygiene
42-
43-
- No committed **`only`** / **`skip`** for CI-mandatory tests.
44-
- Prefer stable ordering and avoid time-dependent assertions unless unavoidable.
45-
46-
## References
47-
48-
- `.cursor/rules/testing.mdc`
49-
- `test/README.md`
26+
- Do not commit stack secrets; use fixtures or env patterns documented for this repo.

0 commit comments

Comments
 (0)