Skip to content

Commit 402adba

Browse files
Merge pull request #381 from contentstack/enh/dx-5356
Added skills and cursor rules
2 parents 9be487a + 88d91d2 commit 402adba

File tree

12 files changed

+474
-0
lines changed

12 files changed

+474
-0
lines changed

.cursor/rules/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Cursor Rules Documentation
2+
3+
This directory contains **Cursor AI rules** for the **Contentstack JavaScript Content Delivery SDK** (`contentstack` on npm) — CDA client development in this repository.
4+
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`.

.cursor/rules/code-review.mdc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
description: "PR review themes — API docs, compatibility, errors, security, tests (CDA SDK)"
3+
alwaysApply: true
4+
---
5+
6+
# Code review checklist (CDA JavaScript SDK)
7+
8+
Apply when reviewing changes to the **`contentstack`** npm package (Content Delivery API client).
9+
10+
## Public API & documentation
11+
12+
- **JSDoc** updated for new or changed public methods/classes (params, return shape, examples), matching style in `src/core/contentstack.js` / `src/core/stack.js`.
13+
- **`index.d.ts`** updated when TypeScript consumers would see different signatures or new exports.
14+
15+
## Backward compatibility
16+
17+
- Avoid breaking changes to exported function signatures, option objects, or default behavior without a major version rationale.
18+
- If behavior changes, ensure **callers inside `src/`** and tests reflect the new contract.
19+
20+
## Errors & safety
21+
22+
- HTTP failures should continue to reject with a predictable shape from **`src/core/lib/request.js`** where applicable (**`error_message`**, **`error_code`**, **`errors`**, **`status`**, **`statusText`**).
23+
- Do not log full **delivery_token**, **preview_token**, **management_token**, or **api_key** values.
24+
- Respect **null/undefined** edge cases for optional API fields.
25+
26+
## Dependencies & supply chain
27+
28+
- New **dependencies** should be justified (size, maintenance, license).
29+
- Lockfile and **`package.json`** version bumps should be minimal and reviewable.
30+
31+
## Tests
32+
33+
- **Jest** tests for new logic or regressions under **`test/`** (JS and/or **`test/typescript/`** as appropriate).
34+
- Live stack tests must remain compatible with **`test/config.js`** env requirements; document new env needs in **`test/README.md`** or comments near the harness — never commit credentials.
35+
36+
## Security & privacy
37+
38+
- No hardcoded credentials; no accidental exposure of customer content in logs or error messages.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
description: "Contentstack CDA SDK patterns in src/core (Content Delivery API)"
3+
globs: ["src/**/*.js"]
4+
alwaysApply: false
5+
---
6+
7+
# Contentstack CDA SDK (`src/core/`)
8+
9+
This package implements the **Content Delivery API (CDA)** read client, not the Content Management API (CMA).
10+
11+
## Stack & config
12+
13+
- **`Contentstack.Stack(options)`** (`src/core/stack.js`) — **`api_key`**, **`delivery_token`**, **`environment`**; optional **`region`**, **`branch`**, **`host`**, **`live_preview`**, **`plugins`**, **`fetchOptions`** (timeout, retries, `retryCondition`, `logHandler`, etc.).
14+
- Default CDN paths and version come from **`config.js`** at the repo root; regional hosts follow existing `stack.js` logic (e.g. `{region}-cdn.contentstack.com`).
15+
16+
## HTTP & errors
17+
18+
- Requests are built in **`src/core/lib/request.js`**: query serialization, **`fetch`**, default retries on **408** / **429** (configurable), plugin hooks **`onRequest`** / **`onResponse`**.
19+
- Failed responses reject with objects carrying **`error_message`**, **`error_code`**, **`errors`**, **`status`**, **`statusText`** when JSON parsing succeeds — keep new code compatible with this shape.
20+
21+
## Modules
22+
23+
- **Entry, Query, Assets, Taxonomy, Result**, etc. live under **`src/core/modules/`** — follow neighboring patterns for chaining, parameters, and URL assembly.
24+
- **Cache**: policies and providers under **`src/core/cache.js`** and **`src/core/cache-provider/`**.
25+
26+
## Live preview
27+
28+
- When **`live_preview.enable`** is true, **`management_token`** vs **`preview_token`** affect host selection — mirror existing `stack.js` behavior and tests under **`test/live-preview/`**.
29+
30+
## Runtime targets
31+
32+
- **`src/runtime/node|web|react-native|nativescript/`** supply **`http`** and **`localstorage`** — changes that affect networking or storage must consider **all** bundled targets.
33+
34+
## Docs
35+
36+
- Align behavior with the official [Content Delivery API](https://www.contentstack.com/docs/developers/apis/content-delivery-api/) documentation.

.cursor/rules/dev-workflow.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
description: "Branches, tests, and PR expectations for contentstack-javascript (CDA SDK)"
3+
globs: ["**/*.js", "**/*.ts", "**/*.json"]
4+
alwaysApply: false
5+
---
6+
7+
# Development workflow — Contentstack JavaScript CDA SDK
8+
9+
## Branches
10+
11+
- Follow team Git conventions (e.g. feature branches off the repo’s default integration branch).
12+
- Do not commit permanent `test.only`, `it.only`, `describe.only`, or skipped tests meant for CI.
13+
14+
## Before opening a PR
15+
16+
1. **`npm run lint`** — ESLint must pass on `src` and `test`.
17+
2. **`npm test`** — Runs **`pretest`****`npm run build`**, then **`test:e2e`** and **`test:typescript`**. For live stack tests, set env vars (see **`test/config.js`**: `HOST`, `API_KEY`, `DELIVERY_TOKEN`, `ENVIRONMENT`). Never commit secrets or `.env` with real tokens.
18+
3. **Version bump** — When the PR introduces **user-visible or release-worthy** SDK behavior (new API, bug fix shipped to npm, or a **breaking** change), update **`version`** in `package.json` per **semver** (patch / minor / major). Docs-only or test-only changes may omit a bump per team practice; match sibling PRs when unsure.
19+
20+
## PR expectations (summary)
21+
22+
- **User-facing changes** — JSDoc on public methods; update **`index.d.ts`** when the public TypeScript surface changes.
23+
- **Behavior** — Preserve backward compatibility unless the change is explicitly breaking and documented.
24+
- **Errors** — Keep rejection shapes consistent with **`src/core/lib/request.js`** (`error_message`, `error_code`, `errors`, `status`, `statusText` where applicable). Do not log full **delivery_token** or **management_token** / **preview_token** values in new code.
25+
- **Tests** — Add or adjust Jest tests under **`test/`** for new behavior; live tests require the env contract in **`test/config.js`**.
26+
27+
## Quick links
28+
29+
- Agent overview: repo root `AGENTS.md`
30+
- CDA patterns: `skills/contentstack-javascript-cda/SKILL.md`
31+
- HTTP / retries / plugins: `skills/framework/SKILL.md`

.cursor/rules/javascript.mdc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
description: "JavaScript/TypeScript conventions for src, webpack, and index.d.ts"
3+
globs:
4+
- "src/**/*.js"
5+
- "webpack/**/*.js"
6+
- "index.d.ts"
7+
alwaysApply: false
8+
---
9+
10+
# JavaScript & types (this repo)
11+
12+
## Runtime & modules
13+
14+
- **Source** is **ES modules** under `src/` (`import` / `export`). Webpack resolves aliases such as **`runtime/http.js`** per target (`webpack/webpack.*.js`).
15+
- **`index.d.ts`** is the public TypeScript surface for npm consumers; keep it aligned with `src/core/` JSDoc and exports.
16+
17+
## Style & tooling
18+
19+
- **ESLint** uses **`eslint-config-standard`** and **`@babel/eslint-parser`**. This repo **requires semicolons** and related rules in **`.eslintrc.js`** — match existing `src/core/` style rather than semicolon-free Standard.
20+
- **Environment**: ESLint `es2020`, `node`, `browser`, `jest`.
21+
22+
## Patterns
23+
24+
- Use **JSDoc** (`@description`, `@param`, `@returns`, `@example`) on **public** API consistent with `src/core/contentstack.js` and `src/core/stack.js`.
25+
- **Dependencies**: **`@contentstack/utils`** is exposed on the main class; follow existing import paths (including `.js` suffixes where the codebase uses them in ESM files).
26+
27+
## Logging
28+
29+
- Avoid noisy logging in library code except via existing **`fetchOptions.logHandler`** / **`fetchOptions.debug`** patterns in `src/core/lib/request.js` and `stack.js`.
30+
- Never log full **delivery_token**, **preview_token**, **management_token**, or API keys.

.cursor/rules/testing.mdc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
description: "Jest e2e and TypeScript tests for the CDA SDK"
3+
globs:
4+
- "test/**/*.js"
5+
- "test/**/*.ts"
6+
alwaysApply: false
7+
---
8+
9+
# Testing — `contentstack` (CDA)
10+
11+
## Frameworks
12+
13+
| Suite | Runner | Notes |
14+
|-------|--------|--------|
15+
| **JS e2e / integration-style** | **Jest** (`jest.js.config.js`) | `testMatch`: `**/test/**/*.js`; ignores `test/index.js`, `test/config.js`, `test/sync_config.js`, some `utils.js` paths |
16+
| **TypeScript** | **Jest** + **ts-jest** (`jest.config.js`) | `npm run test:typescript`; `test/typescript/**/*.test.ts` |
17+
18+
## Env & live stack
19+
20+
- **Canonical required vars** for suites that `require('./config')` or `require('../config.js')`: **`HOST`**, **`API_KEY`**, **`DELIVERY_TOKEN`**, **`ENVIRONMENT`** — validated in **`test/config.js`** (loads **dotenv**). Missing any variable throws on import.
21+
- Use a **`.env`** file locally; do not commit secrets. **`HOST`** should match the delivery API host for your stack/region.
22+
- Built SDK: many tests **`require('../../dist/node/contentstack.js')`**. **`npm test`** runs **`pretest`** → **`npm run build`** first.
23+
24+
## Layout
25+
26+
- **Suite entry (JS):** `test/index.js` `require`s individual test files.
27+
- **TypeScript:** colocate under **`test/typescript/`** with `*.test.ts` naming.
28+
29+
## Hygiene
30+
31+
- No committed **`only`** / **`skip`** for tests that must run in CI.
32+
- Prefer deterministic assertions; mock or scope live tests when adding new cases so CI behavior stays predictable if env is absent.
33+
34+
## Coverage
35+
36+
- Jest / reporter config is in **`jest.js.config.js`** and **`jest.config.js`**; HTML reports paths are configured there.

AGENTS.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# AGENTS.md — AI / automation context
2+
3+
## Project
4+
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) |
10+
11+
## Tech stack
12+
13+
| Area | Details |
14+
|------|---------|
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/`.

skills/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Project skills
2+
3+
Short playbooks for agents and maintainers. Prefer these when you need depth beyond `.cursor/rules/*.mdc`.
4+
5+
| Skill | When to use |
6+
|-------|-------------|
7+
| [`code-review/`](code-review/SKILL.md) | Structured PR review, release readiness, API/doc alignment |
8+
| [`testing/`](testing/SKILL.md) | Jest e2e vs TypeScript tests, `test/config.js` env, dist build |
9+
| [`contentstack-javascript-cda/`](contentstack-javascript-cda/SKILL.md) | CDA usage: `Stack`, delivery token, regions, queries, sync, live preview |
10+
| [`framework/`](framework/SKILL.md) | Request layer: `fetch`, retries, plugins, runtime adapters |
11+
12+
**Repo overview:** see root [`AGENTS.md`](../AGENTS.md). **Rule index:** [`.cursor/rules/README.md`](../.cursor/rules/README.md).

skills/code-review/SKILL.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
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.
4+
---
5+
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).
9+
10+
## When to use
11+
12+
- Reviewing someone else’s PR.
13+
- Self-reviewing before submission.
14+
- Checking API, error, compatibility, tests, and security expectations.
15+
16+
## Instructions
17+
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
53+
54+
- **Blocker:** Must fix before merge.
55+
- **Major:** Should fix before or soon after merge.
56+
- **Minor:** Nice to fix.
57+
58+
## References
59+
60+
- `.cursor/rules/code-review.mdc`
61+
- `.cursor/rules/dev-workflow.md`
62+
- `skills/testing/SKILL.md`

0 commit comments

Comments
 (0)