Skip to content

Commit d173476

Browse files
Merge pull request #55 from contentstack/feat-dx-5395-cursor-rules-and-skills
Add AGENTS.md, skills README, and individual skill guides. Update .g…
2 parents 19ceb1f + 68b21a1 commit d173476

9 files changed

Lines changed: 245 additions & 1 deletion

File tree

.cursor/rules/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Cursor (optional)
2+
3+
**Cursor** users: start at **[AGENTS.md](../../AGENTS.md)**. All conventions live in **`skills/*/SKILL.md`**.
4+
5+
This folder only points contributors to **AGENTS.md** so editor-specific config does not duplicate the canonical docs.

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ example/logs
2121
!.npmignore
2222
!dist/**
2323
!.talismanrc
24-
!SECURITY.md
24+
!SECURITY.md
25+
!AGENTS.md
26+
!.cursor
27+
!.cursor/**
28+
!skills
29+
!skills/**

AGENTS.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Contentstack Webhook Listener – Agent guide
2+
3+
**Universal entry point** for contributors and AI agents. Detailed conventions live in **`skills/*/SKILL.md`**.
4+
5+
## What this repo is
6+
7+
| Field | Detail |
8+
| --- | --- |
9+
| **Name:** | [contentstack/webhook-listener](https://github.com/contentstack/webhook-listener) — npm `@contentstack/webhook-listener` |
10+
| **Purpose:** | TypeScript/Node HTTP server library that receives Contentstack webhooks and invokes a registered callback; part of Contentstack DataSync. |
11+
| **Out of scope (if any):** | Does not implement DataSync Manager, content/asset stores, or CMS configuration—only the webhook HTTP listener surface. |
12+
13+
## Tech stack (at a glance)
14+
15+
| Area | Details |
16+
| --- | --- |
17+
| Language | TypeScript (see `tsconfig.json`); Node.js **20+** (see README). |
18+
| Build | `tsc` → output in `dist/`; `package.json` `main` is `./dist`. |
19+
| Tests | Jest, `test/unit/*.test.js`; `npm test` runs with coverage (`jest.config.js`). |
20+
| Lint / coverage | No ESLint/Prettier in repo; coverage via Jest (`coverage/`). |
21+
| Other | Types under `typings/`; runnable example under `example/`. |
22+
23+
## Commands (quick reference)
24+
25+
| Command type | Command |
26+
| --- | --- |
27+
| Build | `npm run build-ts` (clean + `tsc`) or `npm run compile` (`tsc` only) |
28+
| Test | `npm test` (runs `pretest` → compile, then Jest with coverage) |
29+
| Lint | Not configured |
30+
31+
CI / automation: [.github/workflows/check-version-bump.yml](.github/workflows/check-version-bump.yml), [sca-scan.yml](.github/workflows/sca-scan.yml), [policy-scan.yml](.github/workflows/policy-scan.yml), [codeql-analysis.yml](.github/workflows/codeql-analysis.yml), [github-release.yml](.github/workflows/github-release.yml), [issues-jira.yml](.github/workflows/issues-jira.yml).
32+
33+
## Where the documentation lives: skills
34+
35+
| Skill | Path | What it covers |
36+
| --- | --- | --- |
37+
| Dev workflow & CI | `skills/dev-workflow/SKILL.md` | Branches, npm scripts, Husky, GitHub Actions, version bumps |
38+
| TypeScript style | `skills/typescript-style/SKILL.md` | `tsconfig`, `src/` vs `example/`, typings, module conventions |
39+
| Package API | `skills/webhook-listener/SKILL.md` | Public exports, config, integration with DataSync |
40+
| Testing | `skills/testing/SKILL.md` | Jest layout, compiled output, coverage |
41+
| Code review | `skills/code-review/SKILL.md` | PR expectations and checklist |
42+
43+
An index with “when to use” hints is in `skills/README.md`.
44+
45+
## Using Cursor (optional)
46+
47+
If you use **Cursor**, `.cursor/rules/README.md` only points to **`AGENTS.md`**—same docs as everyone else.

skills/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Skills – Contentstack Webhook Listener
2+
3+
Source of truth for detailed guidance: read **AGENTS.md** at the repo root, then open the skill that matches your task.
4+
5+
## When to use which skill
6+
7+
| Skill folder | Use when |
8+
| --- | --- |
9+
| `dev-workflow/` | Building, scripts, CI, releases, Husky hooks |
10+
| `typescript-style/` | TypeScript/`tsconfig`, typings, layout of `src/` vs `example/` |
11+
| `webhook-listener/` | Public API, configuration, how the listener fits DataSync |
12+
| `testing/` | Writing or running Jest tests, coverage |
13+
| `code-review/` | Preparing or reviewing a PR |
14+
15+
Each folder contains **SKILL.md** with YAML frontmatter (`name`, `description`).

skills/code-review/SKILL.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: code-review
3+
description: PR checklist and review expectations for this repository
4+
---
5+
6+
# Code review – Contentstack Webhook Listener
7+
8+
## When to use
9+
10+
- Opening a PR or reviewing someone else’s changes
11+
12+
## Instructions
13+
14+
### Before requesting review
15+
16+
- **`npm test`** passes (includes compile + Jest coverage).
17+
- **User-visible behavior** changes are reflected in **README** or typings if needed.
18+
- **Release-affecting** changes: **`package.json` version** bumped appropriately; GitHub **version-bump** workflow expectations are met (see [dev-workflow](../dev-workflow/SKILL.md)).
19+
20+
### Review focus
21+
22+
- **Correctness**: webhook handling, auth, error paths, and shutdown/reconnect behavior in `src/`.
23+
- **Compatibility**: public exports and config shape for `@contentstack/webhook-listener` consumers.
24+
- **Tests**: new behavior covered under `test/unit/` when it reduces regression risk.
25+
- **Security**: no secrets in code; dependencies align with org policy (SCA/policy workflows).
26+
27+
### Severity (optional labels)
28+
29+
- **Blocker**: breaks consumers, security issue, or CI consistently red.
30+
- **Major**: wrong behavior or missing tests for important paths.
31+
- **Minor**: style, docs nits, non-critical refactors.

skills/dev-workflow/SKILL.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: dev-workflow
3+
description: Branches, npm scripts, Husky, GitHub Actions, and version/release expectations for this repo
4+
---
5+
6+
# Dev workflow – Contentstack Webhook Listener
7+
8+
## When to use
9+
10+
- Changing build/test commands or CI
11+
- Cutting releases or bumping `package.json` version
12+
- Working with Git hooks
13+
14+
## Instructions
15+
16+
### Scripts (`package.json`)
17+
18+
- **`npm run build-ts`**: `rimraf dist` then full TypeScript compile (artifact: `dist/`).
19+
- **`npm run compile` / `npm run watch-ts`**: `tsc` with or without watch; no clean in `compile`.
20+
- **`npm test`**: `pretest` runs `compile`; then `jest --coverage`.
21+
- **`npm start`**: runs `node example/` for a local demo.
22+
23+
### Source layout
24+
25+
- Implement in **`src/`**; published entry is **`dist/`** (from `"main": "./dist"`).
26+
- Do not edit **`dist/`** by hand—regenerate via compile.
27+
28+
### Git hooks (Husky)
29+
30+
- **`npm run pre-commit`**: installs Husky and ensures `.husky/pre-commit` is executable—see repo for current hook behavior.
31+
32+
### CI (`.github/workflows`)
33+
34+
- **Version bump** ([check-version-bump.yml](../../.github/workflows/check-version-bump.yml)): on PRs, may require `package.json` version to increase vs latest git tag when certain paths change—confirm patterns match this repo’s layout (`src/`, `test/`, etc.) when troubleshooting.
35+
- **SCA / policy / CodeQL / release / Jira**: see workflow files for triggers and purposes.
36+
37+
### PR expectations
38+
39+
- Release-affecting changes typically need a **version bump** in `package.json` per org process; align with the version-bump workflow and [code-review](../code-review/SKILL.md).

skills/testing/SKILL.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: testing
3+
description: Jest tests, layout, coverage, and how they relate to the TypeScript build
4+
---
5+
6+
# Testing – Contentstack Webhook Listener
7+
8+
## When to use
9+
10+
- Adding or changing unit/integration tests
11+
- Debugging `npm test` or coverage output
12+
13+
## Instructions
14+
15+
### Runner and config
16+
17+
- **Jest** is configured in **`jest.config.js`**: Node environment, `testRegex: "./test/.*.js$"`, coverage under **`coverage/`** (json + html reporters).
18+
- **`npm test`** runs **`pretest`**`npm run compile` (runs `tsc`), then **`jest --coverage`**. Ensure **`dist/`** is up to date when tests import compiled code.
19+
20+
### Layout
21+
22+
- Tests live under **`test/unit/`** (e.g. `*.test.js`). **`test/unit/dummy/`** is ignored by Jest (`testPathIgnorePatterns`).
23+
24+
### Style and scope
25+
26+
- Tests are **JavaScript** (`.js`) against the compiled module graph; follow existing files (`index.test.js`, `core.test.js`, `logger.test.js`) for patterns.
27+
- Use **supertest** (devDependency) for HTTP-level assertions where applicable.
28+
29+
### Credentials and secrets
30+
31+
- Do not commit real webhook secrets or Basic Auth credentials; use test doubles or env only as needed in CI-safe ways.

skills/typescript-style/SKILL.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: typescript-style
3+
description: TypeScript and Node coding conventions for this repo—tsconfig, modules, typings
4+
---
5+
6+
# TypeScript style – Contentstack Webhook Listener
7+
8+
## When to use
9+
10+
- Editing or adding `.ts` under `src/` or `example/`
11+
- Adjusting compiler options or public type surface (`typings/`)
12+
13+
## Instructions
14+
15+
### Compiler (`tsconfig.json`)
16+
17+
- **`include`**: `src/**/*` only—library code lives under **`src/`**. **`example/`** is not in that include; demos use checked-in **`example/index.js`** with `npm start` (`node example/`). If you change **`example/index.ts`**, update the corresponding JS (or add a dedicated compile step—there is none in `package.json` today).
18+
- **Output**: CommonJS (`"module": "commonjs"`), **`outDir`: `dist`**, **`baseUrl`: `./src`**, **`sourceMap`: true**.
19+
- **`paths`**: resolves `*` via `node_modules/*` and `src/types/*`—follow that layout for new type-only modules.
20+
21+
### Source style
22+
23+
- Files use **`'use strict';`** and the existing import style (`import` / `export`); match surrounding modules when adding code.
24+
- Prefer explicit, conservative typing for **public** APIs; internal code may use `any` where the codebase already does—avoid widening surface area without need.
25+
26+
### Types shipped to consumers
27+
28+
- Package types are exposed via **`typings/`** (`package.json` `"types": "./typings"`). When you change exported symbols in **`src/`**, update typings (or generated hand-maintained defs) so they stay aligned.
29+
30+
### Build commands
31+
32+
- Compile and clean steps are in **[dev-workflow](../dev-workflow/SKILL.md)**—this skill does not repeat them.

skills/webhook-listener/SKILL.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: webhook-listener
3+
description: Public API, configuration, and boundaries of the @contentstack/webhook-listener package
4+
---
5+
6+
# Webhook listener package – Contentstack Webhook Listener
7+
8+
## When to use
9+
10+
- Integrating or extending the HTTP webhook server
11+
- Changing defaults, messages, logging, or webhook routing behavior
12+
- Documenting behavior for DataSync consumers
13+
14+
## Instructions
15+
16+
### Entry points
17+
18+
- **`src/index.ts`** (compiled to `dist/`): primary module consumers import from `@contentstack/webhook-listener`.
19+
- **Public exports** include: `register`, `start`, `shutdown`, `getEventEmitter`, `setConfig`, `getConfig`, `setLogger` (re-exported from logger). Consumers must call **`register(callback)`** before **`start(config, customLogger?)`** or `start` rejects.
20+
21+
### Core behavior
22+
23+
- **`src/core.ts`**: creates the HTTP listener (body parsing, basic auth if configured, webhook payload handling).
24+
- **`src/defaults.ts`**: default `listener.port`, `listener.endpoint`, allowed webhook **actions**, and **reconnection** defaults.
25+
- **`src/logger.ts`**: pluggable logger; optional **`customLogger`** passed to `start` must expose `info`, `debug`, `error`, `warn` (see `start` implementation).
26+
27+
### Configuration
28+
29+
- User config is merged with defaults (Lodash `merge`). Important keys under `listener`: `port`, `endpoint`, `basic_auth`, `actions`, `reconnection`—see **`src/defaults.ts`** and root **README** table for the subset documented for users.
30+
- **`PORT`** env var overrides `listener.port` when starting the server.
31+
32+
### Boundaries
33+
34+
- This package **notifies** a registered function when a valid webhook is received; it does **not** persist content or run DataSync Manager—that lives in other DataSync modules.
35+
- Broader product context: [Contentstack DataSync](https://www.contentstack.com/docs/guide/synchronization/contentstack-datasync).
36+
37+
### Types
38+
39+
- **`typings/`** and `"types": "./typings"` in `package.json`—keep public types consistent with `src/` exports.

0 commit comments

Comments
 (0)