|
1 | | -# AGENTS.md — AI / automation context |
| 1 | +# Contentstack JavaScript Delivery SDK – Agent guide |
2 | 2 |
|
3 | | -## Project |
| 3 | +**Universal entry point** for contributors and AI agents. Detailed conventions live in **`skills/*/SKILL.md`**. |
4 | 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) | |
| 5 | +## What this repo is |
10 | 6 |
|
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) |
12 | 14 |
|
13 | 15 | | Area | Details | |
14 | 16 | |------|---------| |
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. |
0 commit comments