@contentstack/datasync-mongodb-sdk 1.0.13 → 1.0.15
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/.cursor/rules/README.md +5 -0
- package/.github/workflows/check-version-bump.yml +79 -0
- package/.github/workflows/release.yml +4 -26
- package/.github/workflows/sca-scan.yml +3 -0
- package/.husky/post-checkout +40 -0
- package/AGENTS.md +92 -0
- package/contentstack-datasync-mongodb-sdk-1.0.15.tgz +0 -0
- package/package.json +2 -2
- package/skills/README.md +18 -0
- package/skills/code-review/SKILL.md +59 -0
- package/skills/datasync-mongodb/SKILL.md +68 -0
- package/skills/dev-workflow/SKILL.md +60 -0
- package/skills/testing/SKILL.md +53 -0
- package/skills/typescript/SKILL.md +46 -0
- package/contentstack-datasync-mongodb-sdk-1.0.13.tgz +0 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Cursor (optional)
|
|
2
|
+
|
|
3
|
+
**Cursor** users: start at the repo root **[`AGENTS.md`](../../AGENTS.md)**. All conventions live in **`skills/*/SKILL.md`** (universal for any editor or tool).
|
|
4
|
+
|
|
5
|
+
This folder **only** contains this **README** — no `.mdc` or other rule files — so nothing editor-specific duplicates the canonical docs.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Catches when developers forget to bump package.json for release-affecting changes.
|
|
2
|
+
# App code changes (app.js, bin/, config/, routes/, views/, etc.) require a version bump vs latest tag.
|
|
3
|
+
# Skips for: test-only, docs, .github (workflows/config), dependency-only bumps without app edits.
|
|
4
|
+
name: Check Version Bump
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
version-bump:
|
|
11
|
+
name: Version bump
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout
|
|
15
|
+
uses: actions/checkout@v4
|
|
16
|
+
with:
|
|
17
|
+
fetch-depth: 0
|
|
18
|
+
|
|
19
|
+
- name: Detect changed files and version bump
|
|
20
|
+
id: detect
|
|
21
|
+
run: |
|
|
22
|
+
if git rev-parse HEAD^2 >/dev/null 2>&1; then
|
|
23
|
+
FILES=$(git diff --name-only HEAD^1 HEAD^2)
|
|
24
|
+
else
|
|
25
|
+
FILES=$(git diff --name-only HEAD~1 HEAD)
|
|
26
|
+
fi
|
|
27
|
+
VERSION_FILES_CHANGED=false
|
|
28
|
+
echo "$FILES" | grep -qx 'package.json' && VERSION_FILES_CHANGED=true
|
|
29
|
+
echo "version_files_changed=$VERSION_FILES_CHANGED" >> $GITHUB_OUTPUT
|
|
30
|
+
# App source paths for this boilerplate (no lib/webpack/dist); .github/ and test/ do not count
|
|
31
|
+
CODE_CHANGED=false
|
|
32
|
+
echo "$FILES" | grep -qE '^app\.js$|^bin/|^config/|^middlewares/|^models/|^public/|^routes/|^views/|^schemaNentries/' && CODE_CHANGED=true
|
|
33
|
+
echo "$FILES" | grep -qx 'package.json' && CODE_CHANGED=true
|
|
34
|
+
echo "code_changed=$CODE_CHANGED" >> $GITHUB_OUTPUT
|
|
35
|
+
|
|
36
|
+
- name: Skip when only test/docs/.github changed
|
|
37
|
+
if: steps.detect.outputs.code_changed != 'true'
|
|
38
|
+
run: |
|
|
39
|
+
echo "No release-affecting files changed (e.g. only test/docs/.github). Skipping version-bump check."
|
|
40
|
+
exit 0
|
|
41
|
+
|
|
42
|
+
- name: Fail when version bump was missed
|
|
43
|
+
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed != 'true'
|
|
44
|
+
run: |
|
|
45
|
+
echo "::error::This PR has code changes but no version bump. Please bump the version in package.json."
|
|
46
|
+
exit 1
|
|
47
|
+
|
|
48
|
+
- name: Setup Node
|
|
49
|
+
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
|
|
50
|
+
uses: actions/setup-node@v4
|
|
51
|
+
with:
|
|
52
|
+
node-version: '22.x'
|
|
53
|
+
|
|
54
|
+
- name: Check version bump
|
|
55
|
+
if: steps.detect.outputs.code_changed == 'true' && steps.detect.outputs.version_files_changed == 'true'
|
|
56
|
+
run: |
|
|
57
|
+
set -e
|
|
58
|
+
PKG_VERSION=$(node -p "require('./package.json').version.replace(/^v/, '')")
|
|
59
|
+
if [ -z "$PKG_VERSION" ]; then
|
|
60
|
+
echo "::error::Could not read version from package.json"
|
|
61
|
+
exit 1
|
|
62
|
+
fi
|
|
63
|
+
git fetch --tags --force 2>/dev/null || true
|
|
64
|
+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || true)
|
|
65
|
+
if [ -z "$LATEST_TAG" ]; then
|
|
66
|
+
echo "No existing tags found. Skipping version-bump check (first release)."
|
|
67
|
+
exit 0
|
|
68
|
+
fi
|
|
69
|
+
LATEST_VERSION="${LATEST_TAG#v}"
|
|
70
|
+
LATEST_VERSION="${LATEST_VERSION%%-*}"
|
|
71
|
+
if [ "$(printf '%s\n' "$LATEST_VERSION" "$PKG_VERSION" | sort -V | tail -1)" != "$PKG_VERSION" ]; then
|
|
72
|
+
echo "::error::Version bump required: package.json version ($PKG_VERSION) is not greater than latest tag ($LATEST_TAG). Please bump the version in package.json."
|
|
73
|
+
exit 1
|
|
74
|
+
fi
|
|
75
|
+
if [ "$PKG_VERSION" = "$LATEST_VERSION" ]; then
|
|
76
|
+
echo "::error::Version bump required: package.json version ($PKG_VERSION) equals latest tag ($LATEST_TAG). Please bump the version in package.json."
|
|
77
|
+
exit 1
|
|
78
|
+
fi
|
|
79
|
+
echo "Version bump check passed: package.json is at $PKG_VERSION (latest tag: $LATEST_TAG)."
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
name: Release
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
release:
|
|
5
|
+
types: [created]
|
|
6
6
|
|
|
7
7
|
jobs:
|
|
8
8
|
build:
|
|
@@ -43,35 +43,13 @@ jobs:
|
|
|
43
43
|
token: ${{ secrets.NPM_TOKEN }}
|
|
44
44
|
# access: public # Uncomment this line if you want to publish the package as public for first time
|
|
45
45
|
|
|
46
|
-
#
|
|
47
|
-
- name: Auto-tag new version
|
|
48
|
-
id: update_tag
|
|
49
|
-
uses: Klemensas/action-autotag@stable
|
|
50
|
-
with:
|
|
51
|
-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
|
52
|
-
tag_prefix: "v"
|
|
53
|
-
|
|
54
|
-
# Create a new GitHub Release
|
|
55
|
-
- name: Create GitHub Release
|
|
56
|
-
if: steps.update_tag.outputs.tagname != ''
|
|
57
|
-
uses: actions/create-release@v1
|
|
58
|
-
id: create_release
|
|
59
|
-
env:
|
|
60
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
61
|
-
with:
|
|
62
|
-
tag_name: ${{ steps.update_tag.outputs.tagname }}
|
|
63
|
-
release_name: Release ${{ steps.update_tag.outputs.tagname }}
|
|
64
|
-
draft: false
|
|
65
|
-
prerelease: false
|
|
66
|
-
|
|
67
|
-
# Upload the packaged .tgz file as a release asset
|
|
46
|
+
# Upload the packaged .tgz to the release that triggered this workflow
|
|
68
47
|
- name: Upload Release Asset
|
|
69
|
-
if: steps.update_tag.outputs.tagname != ''
|
|
70
48
|
uses: actions/upload-release-asset@v1
|
|
71
49
|
env:
|
|
72
50
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
73
51
|
with:
|
|
74
|
-
upload_url: ${{
|
|
52
|
+
upload_url: ${{ github.event.release.upload_url }}
|
|
75
53
|
asset_path: "./contentstack-datasync-mongodb-sdk-${{ steps.package.outputs.version }}.tgz"
|
|
76
54
|
asset_name: "contentstack-datasync-mongodb-sdk-${{ steps.package.outputs.version }}.tgz"
|
|
77
55
|
asset_content_type: application/tgz
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
# When switching to a branch that doesn't exist on remote (e.g. newly created),
|
|
3
|
+
# pull and merge origin/main or origin/master into current branch. Does not push.
|
|
4
|
+
|
|
5
|
+
# Only run on branch checkout (not file checkout)
|
|
6
|
+
if [ "$3" != "1" ]; then
|
|
7
|
+
exit 0
|
|
8
|
+
fi
|
|
9
|
+
|
|
10
|
+
# Skip if we don't have a remote
|
|
11
|
+
if ! git rev-parse --verify origin 2>/dev/null; then
|
|
12
|
+
exit 0
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
16
|
+
|
|
17
|
+
# Skip main/master - no need to merge base into these
|
|
18
|
+
case "$CURRENT_BRANCH" in
|
|
19
|
+
main|master) exit 0 ;;
|
|
20
|
+
esac
|
|
21
|
+
|
|
22
|
+
# Only run when current branch does not exist on origin (treat as new local branch)
|
|
23
|
+
if git ls-remote --heads origin "$CURRENT_BRANCH" 2>/dev/null | grep -q .; then
|
|
24
|
+
echo "post-checkout: $CURRENT_BRANCH exists on origin, skipping merge."
|
|
25
|
+
exit 0
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
# Prefer main, fallback to master
|
|
29
|
+
if git rev-parse --verify origin/main 2>/dev/null; then
|
|
30
|
+
BASE=origin/main
|
|
31
|
+
elif git rev-parse --verify origin/master 2>/dev/null; then
|
|
32
|
+
BASE=origin/master
|
|
33
|
+
else
|
|
34
|
+
exit 0
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
echo "New branch detected: merging latest $BASE into $CURRENT_BRANCH (local only, not pushing)..."
|
|
38
|
+
git fetch origin
|
|
39
|
+
git merge "$BASE" --no-edit --no-ff
|
|
40
|
+
echo "Done. Merge is local only; push when ready."
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# AI agent docs — `@contentstack/datasync-mongodb-sdk`
|
|
2
|
+
|
|
3
|
+
You are working on the **Contentstack DataSync MongoDB SDK** — a library that queries **MongoDB** (or a Mongo-compatible store) holding content synced via **Contentstack DataSync**, **not** the Content **Delivery** (CDA) or **Management** (CMA) HTTP SDKs. Core behavior uses the **MongoDB driver** and queries against **persisted sync data**, not live stack REST calls for normal reads.
|
|
4
|
+
|
|
5
|
+
## Single source of truth
|
|
6
|
+
|
|
7
|
+
| Layer | Role |
|
|
8
|
+
|-------|------|
|
|
9
|
+
| **[`.cursor/rules/README.md`](.cursor/rules/README.md)** | Optional Cursor pointer (the **only** file under `.cursor/rules/`); links to **`AGENTS.md`** and **`skills/`** |
|
|
10
|
+
| **`AGENTS.md`** (this file) | Universal entry: identity, out-of-scope, links, tech stack, commands, skills index |
|
|
11
|
+
| **`skills/<name>/SKILL.md`** | Full conventions and checklists (source of truth for depth) |
|
|
12
|
+
|
|
13
|
+
**Flow:** [`.cursor/rules/README.md`](.cursor/rules/README.md) → **`AGENTS.md`** → **`skills/<name>/SKILL.md`**
|
|
14
|
+
|
|
15
|
+
## Out of scope (unless comparing or documenting migration)
|
|
16
|
+
|
|
17
|
+
- **Not** the CDA or CMA **HTTP** client SDKs.
|
|
18
|
+
- **Not** live Contentstack **REST** reads for normal query paths — this SDK targets **synced data in MongoDB**.
|
|
19
|
+
|
|
20
|
+
## Repository
|
|
21
|
+
|
|
22
|
+
| | |
|
|
23
|
+
|--|--|
|
|
24
|
+
| **npm** | `@contentstack/datasync-mongodb-sdk` |
|
|
25
|
+
| **Git** | [https://github.com/contentstack/datasync-mongodb-sdk](https://github.com/contentstack/datasync-mongodb-sdk) |
|
|
26
|
+
| **Product docs** | [Contentstack DataSync](https://www.contentstack.com/docs/guide/synchronization/contentstack-datasync) |
|
|
27
|
+
|
|
28
|
+
## Tech stack
|
|
29
|
+
|
|
30
|
+
| Area | Details |
|
|
31
|
+
|------|---------|
|
|
32
|
+
| Language | TypeScript `^4.9.5` (`package.json`); `tsc` → `dist/`, declarations `typings/` (`tsconfig.json`) |
|
|
33
|
+
| Runtime | Node `>=8` (`engines`); README may suggest a newer Node for local dev |
|
|
34
|
+
| Build | `npm run compile` (`tsc`); `npm run build-ts` (`clean` + `tsc`) |
|
|
35
|
+
| Test | Jest `^29` + ts-jest, Node env, coverage on (`jest.config.js`). **`npm test` is `jest` only** — no `pretest` in `package.json` |
|
|
36
|
+
| Lint | **TSLint** — `npm run tslint` + `tslint.json` on `src/**/*.ts`. **No ESLint** / no `npm run lint` in this repo |
|
|
37
|
+
| Runtime deps | `mongodb`, `lodash`, `sift` |
|
|
38
|
+
| Docs | `npm run build-doc` (builds then JSDoc → `docs/`) |
|
|
39
|
+
|
|
40
|
+
## Source layout and public entry points
|
|
41
|
+
|
|
42
|
+
| Role | Path |
|
|
43
|
+
|------|------|
|
|
44
|
+
| Package entry | `dist/index.js` (`main`) |
|
|
45
|
+
| Public API | `src/index.ts` — `Contentstack`, `Contentstack.Stack(config, db?)` |
|
|
46
|
+
| Query / connection | `src/stack.ts` |
|
|
47
|
+
| Defaults + validation | `src/config.ts`, `src/util.ts` |
|
|
48
|
+
| Messages | `src/messages.ts` |
|
|
49
|
+
| Tests + fixtures | `test/`, `test/data/` |
|
|
50
|
+
| Declarations | `typings/*.d.ts` |
|
|
51
|
+
| Example | `example/index.js` |
|
|
52
|
+
|
|
53
|
+
## Commands
|
|
54
|
+
|
|
55
|
+
| Command | Purpose |
|
|
56
|
+
|---------|---------|
|
|
57
|
+
| `npm run build-ts` | Clean `dist/`, `typings/`, `coverage/`, then `tsc` |
|
|
58
|
+
| `npm run compile` | `tsc` only |
|
|
59
|
+
| `npm test` | Jest (coverage per `jest.config.js`) |
|
|
60
|
+
| `npm run tslint` | TSLint `src/**/*.ts` |
|
|
61
|
+
| `npm run clean` | Rimraf `dist`, `typings`, `coverage` |
|
|
62
|
+
| `npm run build-doc` | Full build + JSDoc to `docs/` |
|
|
63
|
+
|
|
64
|
+
## Test model and credentials
|
|
65
|
+
|
|
66
|
+
- **Integration-style** tests against a **real MongoDB** (`Stack.connect()`, inserts, queries, teardown). **Not** live Contentstack HTTP API calls.
|
|
67
|
+
- Default URI from merged **`src/config.ts`** (e.g. `mongodb://localhost:27017`); tests often use **`test/config.ts`** (`dbName` e.g. `sync-test`).
|
|
68
|
+
- **No** committed `.env` for tests; override via **`contentStore`** (including `url`) in code. **Do not** commit production Mongo URIs or secrets.
|
|
69
|
+
- **No** Testcontainers or CI Mongo service defined in-repo — local MongoDB is the documented path for developers running tests.
|
|
70
|
+
|
|
71
|
+
## Skills index
|
|
72
|
+
|
|
73
|
+
Canonical detail lives under **`skills/<kebab-case>/SKILL.md`**. See **[`skills/README.md`](skills/README.md)**.
|
|
74
|
+
|
|
75
|
+
| Skill | `SKILL.md` |
|
|
76
|
+
|-------|------------|
|
|
77
|
+
| Dev workflow, hooks, CI | [`skills/dev-workflow/SKILL.md`](skills/dev-workflow/SKILL.md) |
|
|
78
|
+
| TypeScript / TSLint / `src/` layout | [`skills/typescript/SKILL.md`](skills/typescript/SKILL.md) |
|
|
79
|
+
| DataSync MongoDB SDK behavior | [`skills/datasync-mongodb/SKILL.md`](skills/datasync-mongodb/SKILL.md) |
|
|
80
|
+
| Testing | [`skills/testing/SKILL.md`](skills/testing/SKILL.md) |
|
|
81
|
+
| Code review | [`skills/code-review/SKILL.md`](skills/code-review/SKILL.md) |
|
|
82
|
+
|
|
83
|
+
## Using Cursor
|
|
84
|
+
|
|
85
|
+
- Open **[`.cursor/rules/README.md`](.cursor/rules/README.md)** — the sole file in **`.cursor/rules/`** — for pointers to **`AGENTS.md`** and **`skills/`**.
|
|
86
|
+
- Full guidance: **`skills/<name>/SKILL.md`** (attach or `@`-reference those paths in chat per your Cursor setup); there are **no** `.cursor/rules/*.mdc` files in this repo.
|
|
87
|
+
|
|
88
|
+
## Contributor workflow (concise)
|
|
89
|
+
|
|
90
|
+
- **`.husky/pre-commit`:** **Snyk** + **Talisman** when installed; `SKIP_HOOK=1` only if your team allows.
|
|
91
|
+
- **CI:** `.github/workflows/` includes CodeQL, SCA, policy scans, **check-version-bump** — see each file for triggers.
|
|
92
|
+
- **Version bump workflow** path filters may **not** list `src/`; maintainers may need to align the workflow with this layout (see [`skills/dev-workflow/SKILL.md`](skills/dev-workflow/SKILL.md)).
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Contentstack Ecosystem <ecosystem@contentstack.com>",
|
|
3
3
|
"name": "@contentstack/datasync-mongodb-sdk",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.15",
|
|
5
5
|
"description": "Mongodb query wrapper around contents synced via @contentstack/content-store-mongodb",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"lodash": "^4.
|
|
21
|
+
"lodash": "^4.18.1",
|
|
22
22
|
"mongodb": "^6.21.0",
|
|
23
23
|
"npm-pack": "^1.0.0",
|
|
24
24
|
"sift": "^17.1.3"
|
package/skills/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Skills — `@contentstack/datasync-mongodb-sdk`
|
|
2
|
+
|
|
3
|
+
**This directory is the source of truth** for detailed conventions (workflow, TypeScript/TSLint, DataSync MongoDB SDK behavior, tests, code review). Read **[`AGENTS.md`](../AGENTS.md)** at the repo root for the index, identity, and command tables; each skill is a folder with **`SKILL.md`** (YAML frontmatter: `name`, `description`).
|
|
4
|
+
|
|
5
|
+
## When to use which skill
|
|
6
|
+
|
|
7
|
+
| Skill folder | Use when |
|
|
8
|
+
|--------------|----------|
|
|
9
|
+
| [`dev-workflow/`](dev-workflow/SKILL.md) | Branches, `npm` scripts, Husky, CI, version bumps |
|
|
10
|
+
| [`typescript/`](typescript/SKILL.md) | `tsconfig`, TSLint, `src/` layout, JSDoc |
|
|
11
|
+
| [`datasync-mongodb/`](datasync-mongodb/SKILL.md) | `Stack`, MongoDB config, queries — DataSync vs CDA/CMA |
|
|
12
|
+
| [`testing/`](testing/SKILL.md) | Jest, MongoDB test setup, fixtures, `jest.config.js` |
|
|
13
|
+
| [`code-review/`](code-review/SKILL.md) | PR checklist, semver, terminology |
|
|
14
|
+
|
|
15
|
+
## How to use these docs
|
|
16
|
+
|
|
17
|
+
- **Humans / any tool:** Start at **`AGENTS.md`**, then open the relevant **`skills/<name>/SKILL.md`**.
|
|
18
|
+
- **Cursor users:** **[`.cursor/rules/README.md`](../.cursor/rules/README.md)** (the only file under **`.cursor/rules/`**) points at **`AGENTS.md`** and **`skills/`**.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-review
|
|
3
|
+
description: PR review for DataSync MongoDB SDK — JSDoc, compatibility, errors, tests, deps/SCA; terminology DataSync MongoDB SDK not CDA/CMA HTTP
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Code review — `@contentstack/datasync-mongodb-sdk`
|
|
7
|
+
|
|
8
|
+
## When to use
|
|
9
|
+
|
|
10
|
+
- Reviewing a PR that touches `src/`, `test/`, or public docs
|
|
11
|
+
- Self-checking before request for review
|
|
12
|
+
- Judging semver impact for Stack / config / query behavior
|
|
13
|
+
|
|
14
|
+
## Instructions
|
|
15
|
+
|
|
16
|
+
### Scope and terminology
|
|
17
|
+
|
|
18
|
+
- This package is the **DataSync MongoDB SDK** (MongoDB over **synced** content). Do **not** call it the **CDA** or **CMA** **HTTP** SDK unless the change explicitly compares or documents migration.
|
|
19
|
+
- Behavior should be validated with **MongoDB + Jest** tests, not live stack REST calls, unless the PR is explicitly about integration docs.
|
|
20
|
+
|
|
21
|
+
### Public API and docs
|
|
22
|
+
|
|
23
|
+
- **`Contentstack` / `Stack`** public surface should have accurate **JSDoc** consistent with `src/stack.ts`.
|
|
24
|
+
- **README** / **`example/`** must match **`Stack.connect()`** and **`contentStore`** keys from **`src/config.ts`** and real usage.
|
|
25
|
+
|
|
26
|
+
### Backward compatibility
|
|
27
|
+
|
|
28
|
+
- Avoid breaking query result shape, **config** schema, or public method signatures without a **semver-major** plan.
|
|
29
|
+
- Watch **locale**, **collection naming**, **reference depth**, **limit/skip** defaults.
|
|
30
|
+
|
|
31
|
+
### Errors and messages
|
|
32
|
+
|
|
33
|
+
- Prefer centralized strings in **`src/messages.ts`** where the codebase already does.
|
|
34
|
+
|
|
35
|
+
### Correctness and null safety
|
|
36
|
+
|
|
37
|
+
- Align with MongoDB driver and existing null checks in query chains.
|
|
38
|
+
|
|
39
|
+
### Dependencies and security
|
|
40
|
+
|
|
41
|
+
- New dependencies need justification; align with **`lodash` / `mongodb` / `sift`** patterns and **Snyk**/SCA expectations.
|
|
42
|
+
|
|
43
|
+
### Tests
|
|
44
|
+
|
|
45
|
+
- Behavioral changes in **`src/`** need matching **`test/`** updates and **`test/data/`** fixtures when document shapes change.
|
|
46
|
+
|
|
47
|
+
### Optional severity
|
|
48
|
+
|
|
49
|
+
| Level | Examples |
|
|
50
|
+
|-------|----------|
|
|
51
|
+
| Blocker | Wrong query results, data corruption risk, security issue, broken public API contract |
|
|
52
|
+
| Major | Missing tests for core behavior, breaking change without version/docs strategy |
|
|
53
|
+
| Minor | Style, non-user-facing refactors, doc nits |
|
|
54
|
+
|
|
55
|
+
## References
|
|
56
|
+
|
|
57
|
+
- [`../testing/SKILL.md`](../testing/SKILL.md)
|
|
58
|
+
- [`../datasync-mongodb/SKILL.md`](../datasync-mongodb/SKILL.md)
|
|
59
|
+
- [`../../AGENTS.md`](../../AGENTS.md)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: datasync-mongodb
|
|
3
|
+
description: DataSync MongoDB SDK — Stack, MongoDB connection, contentStore config, queries; not CDA/CMA HTTP
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# SDK core and queries — `@contentstack/datasync-mongodb-sdk`
|
|
7
|
+
|
|
8
|
+
## When to use
|
|
9
|
+
|
|
10
|
+
- Implementing or changing query behavior, filters, or references in `src/stack.ts`
|
|
11
|
+
- Adjusting defaults, URI validation, or locale/collection behavior (`src/config.ts`, `src/util.ts`)
|
|
12
|
+
- Adding exports or user-facing errors (`src/index.ts`, `src/messages.ts`)
|
|
13
|
+
|
|
14
|
+
## Instructions
|
|
15
|
+
|
|
16
|
+
### Product model
|
|
17
|
+
|
|
18
|
+
- **`@contentstack/datasync-mongodb-sdk`** queries **MongoDB** filled by Contentstack **DataSync** and stores such as **`@contentstack/content-store-mongodb`** (`package.json` description). It does **not** call Contentstack **Delivery** or **Management** REST APIs for normal reads.
|
|
19
|
+
- **Stack** here is the query facade over **persisted sync data**, not an HTTP API stack or region endpoint.
|
|
20
|
+
|
|
21
|
+
### Entry flow
|
|
22
|
+
|
|
23
|
+
1. **`Contentstack.Stack(config, existingDb?)`** (`src/index.ts`) constructs **`Stack`** (`src/stack.ts`).
|
|
24
|
+
2. **`Stack.connect()`** establishes the MongoDB client / database — call before queries (see README).
|
|
25
|
+
3. Fluent API: **`contentType(uid)`**, **`entries()`**, **`assets()`**, filters, **`language()`**, **`includeReferences()`**, pagination, projections — see **`src/stack.ts`**.
|
|
26
|
+
|
|
27
|
+
### Configuration
|
|
28
|
+
|
|
29
|
+
- Config merges with **`src/config.ts`** defaults: e.g. **`contentStore.url`**, **`dbName`**, **`collection`** (asset / entry / schema names), **`locale`**, **`limit`**, **`skip`**, **`projections`**, **`options`** (MongoClient options), **`referenceDepth`**, **`indexes`**, internal type keys.
|
|
30
|
+
- Optional second argument to **`Stack`**: an **existing** MongoDB connection for advanced scenarios.
|
|
31
|
+
- **Indexes:** README recommends indexes on keys such as `_content_type_uid`, `uid`, `locale`, `updated_at` — align with ops for performance.
|
|
32
|
+
|
|
33
|
+
### Query execution
|
|
34
|
+
|
|
35
|
+
- **Driver:** **`mongodb`** (`MongoClient`, `Db`, collections).
|
|
36
|
+
- **Filtering:** **`sift`** where used; **merge/sort:** **`lodash`** patterns in `stack.ts`.
|
|
37
|
+
- **Validation:** **`validateConfig`**, **`validateURI`**, **`getCollectionName`** in **`src/util.ts`**.
|
|
38
|
+
- **Errors:** prefer **`src/messages.ts`** for user-facing strings.
|
|
39
|
+
|
|
40
|
+
### Async patterns
|
|
41
|
+
|
|
42
|
+
- **`connect()`** / query methods follow existing **Promise** / `.then()` patterns in the codebase; match surrounding style when extending.
|
|
43
|
+
|
|
44
|
+
### Retries
|
|
45
|
+
|
|
46
|
+
- Document **MongoClient** / driver options under **`contentStore.options`** in config; **no** separate retry framework is defined in-repo — only what **`mongodb`** and merged config provide.
|
|
47
|
+
|
|
48
|
+
### Scope
|
|
49
|
+
|
|
50
|
+
- **`src/`** is the SDK core; **`example/`** is illustrative.
|
|
51
|
+
|
|
52
|
+
### Where to change code
|
|
53
|
+
|
|
54
|
+
| Concern | Start here |
|
|
55
|
+
|---------|------------|
|
|
56
|
+
| New operator or query path | `src/stack.ts` |
|
|
57
|
+
| Defaults, merge behavior | `src/config.ts` |
|
|
58
|
+
| URI / config validation | `src/util.ts` |
|
|
59
|
+
| User-visible messages | `src/messages.ts` |
|
|
60
|
+
| Public exports | `src/index.ts` |
|
|
61
|
+
|
|
62
|
+
## References
|
|
63
|
+
|
|
64
|
+
- [DataSync guide](https://www.contentstack.com/docs/guide/synchronization/contentstack-datasync)
|
|
65
|
+
- [SDK docs](https://contentstack.github.io/datasync-mongodb-sdk/) (when linked from repo README)
|
|
66
|
+
- [`../typescript/SKILL.md`](../typescript/SKILL.md)
|
|
67
|
+
- [`../testing/SKILL.md`](../testing/SKILL.md)
|
|
68
|
+
- [`../../AGENTS.md`](../../AGENTS.md)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dev-workflow
|
|
3
|
+
description: Branches, npm scripts, Husky, CI, and version-bump expectations for @contentstack/datasync-mongodb-sdk
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Dev workflow — Contentstack DataSync MongoDB SDK
|
|
7
|
+
|
|
8
|
+
## When to use
|
|
9
|
+
|
|
10
|
+
- Onboarding or setting up locally
|
|
11
|
+
- Before opening or updating a PR
|
|
12
|
+
- Planning a release or editing `package.json` version
|
|
13
|
+
|
|
14
|
+
## Instructions
|
|
15
|
+
|
|
16
|
+
### Branches
|
|
17
|
+
|
|
18
|
+
- No `development` / `master` policy is **encoded in this repo** — use your team’s Git flow (feature branches, PR merge targets).
|
|
19
|
+
|
|
20
|
+
### Install and build
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install
|
|
24
|
+
npm run build-ts
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`npm run build-ts` runs `clean` (rimraf `dist`, `typings`, `coverage`) then `tsc` (`package.json`).
|
|
28
|
+
|
|
29
|
+
### Quality gates
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm run tslint # TSLint — src/**/*.ts, tslint.json
|
|
33
|
+
npm test # Jest — no pretest script; ensure MongoDB available for integration tests
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- **`npm run compile`** — `tsc` without clean (faster incremental builds).
|
|
37
|
+
|
|
38
|
+
### PR expectations
|
|
39
|
+
|
|
40
|
+
- Run **build** (`build-ts` or `compile` as appropriate), **tslint**, and **tests** when touching `src/` or query behavior.
|
|
41
|
+
- **`.husky/pre-commit`** runs **Snyk** and **Talisman** when installed; use **`SKIP_HOOK=1`** only when your team allows bypassing checks.
|
|
42
|
+
|
|
43
|
+
### Version bumps and CI
|
|
44
|
+
|
|
45
|
+
- Version lives in **`package.json`**. Coordinate semver with maintainers for breaking **Stack** API or **contentStore** config shape changes.
|
|
46
|
+
- **`.github/workflows/check-version-bump.yml`** flags missing `package.json` bumps for some “code changed” paths — its **`grep` patterns currently reference paths like `app.js`, `bin/`, `routes/`, not `src/`**. **Placeholder for maintainers:** align this workflow with **`src/`** / **`test/`** or confirm it is intentionally narrow.
|
|
47
|
+
|
|
48
|
+
### Other workflows
|
|
49
|
+
|
|
50
|
+
- **`.github/workflows/`** also includes **CodeQL**, **SCA**, **policy** scans — read each YAML for triggers.
|
|
51
|
+
|
|
52
|
+
### Docs
|
|
53
|
+
|
|
54
|
+
- **`npm run build-doc`** — requires successful TS output then JSDoc into **`docs/`**.
|
|
55
|
+
|
|
56
|
+
## References
|
|
57
|
+
|
|
58
|
+
- [`../testing/SKILL.md`](../testing/SKILL.md)
|
|
59
|
+
- [`../typescript/SKILL.md`](../typescript/SKILL.md)
|
|
60
|
+
- [`../../AGENTS.md`](../../AGENTS.md)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: testing
|
|
3
|
+
description: Jest + ts-jest for DataSync MongoDB SDK — real MongoDB integration tests, fixtures, jest.config.js, no live Contentstack HTTP
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Testing — `@contentstack/datasync-mongodb-sdk`
|
|
7
|
+
|
|
8
|
+
## When to use
|
|
9
|
+
|
|
10
|
+
- Adding or changing tests under `test/`
|
|
11
|
+
- Debugging failures after `src/` changes
|
|
12
|
+
- Understanding Jest ignores, coverage, or fixture layout
|
|
13
|
+
|
|
14
|
+
## Instructions
|
|
15
|
+
|
|
16
|
+
### Commands
|
|
17
|
+
|
|
18
|
+
- **`npm test`** — runs **`jest`** only (`package.json`). **No `pretest`** — run **`npm run build-ts`** or **`npm run compile`** first if `dist/` / imports require it.
|
|
19
|
+
- **`npm run build-ts`** — use when you need a clean compile before debugging.
|
|
20
|
+
|
|
21
|
+
### Runner and config
|
|
22
|
+
|
|
23
|
+
- **Jest** + **ts-jest**, **Node** environment (`jest.config.js`).
|
|
24
|
+
- **`collectCoverage: true`** — reports under **`coverage/`** (JSON + HTML).
|
|
25
|
+
- **`testMatch`:** `**/test/**/*.ts` (and `.js`).
|
|
26
|
+
- **`testPathIgnorePatterns`:** `/test/data/*`, `/test/.*config.ts` — fixture/config paths are not treated as test files.
|
|
27
|
+
- **`notify: true`** — may use `node-notifier` locally; optional in headless CI.
|
|
28
|
+
|
|
29
|
+
### Layout
|
|
30
|
+
|
|
31
|
+
| Path | Role |
|
|
32
|
+
|------|------|
|
|
33
|
+
| `test/**/*.ts` | Topic suites (`core.ts`, `queries.ts`, …) |
|
|
34
|
+
| `test/data/*.ts` | Fixture documents imported into collections |
|
|
35
|
+
| `test/config.ts` | Shared stack test config (e.g. `dbName`) |
|
|
36
|
+
| `jest.config.js` | Match, ignore, coverage, transform |
|
|
37
|
+
|
|
38
|
+
### Patterns
|
|
39
|
+
|
|
40
|
+
- Tests typically **`Stack.connect()`**, insert fixtures via MongoDB driver, run Stack queries, assert, drop collections / **`Stack.close()`** in `afterAll` where used.
|
|
41
|
+
- File names are **topic-based** (not required `*.test.ts`).
|
|
42
|
+
|
|
43
|
+
### Environment and credentials
|
|
44
|
+
|
|
45
|
+
- **Real MongoDB** at URL from merged config — default **`mongodb://localhost:27017`** in **`src/config.ts`** unless tests override **`contentStore.url`**.
|
|
46
|
+
- **No** Delivery/Management API keys for core tests.
|
|
47
|
+
- **No** `.env` contract in-repo; pass **`contentStore`** in code. **Do not** put production URIs in tests or CI secrets in the repo.
|
|
48
|
+
- **No** Testcontainers / dockerized Mongo in this repo’s scripts — document **local MongoDB** for developers unless CI is extended.
|
|
49
|
+
|
|
50
|
+
## References
|
|
51
|
+
|
|
52
|
+
- [`../datasync-mongodb/SKILL.md`](../datasync-mongodb/SKILL.md)
|
|
53
|
+
- [`../../AGENTS.md`](../../AGENTS.md)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: typescript
|
|
3
|
+
description: TypeScript and TSLint for src/ — tsconfig, tslint.json, layout, JSDoc; no ESLint in this repo
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# TypeScript (`src/`) — `@contentstack/datasync-mongodb-sdk`
|
|
7
|
+
|
|
8
|
+
## When to use
|
|
9
|
+
|
|
10
|
+
- Editing or adding files under `src/` or generated `typings/`
|
|
11
|
+
- Aligning with compiler and TSLint settings
|
|
12
|
+
- Choosing where new code belongs (`index.ts`, `stack.ts`, `config.ts`, `util.ts`, `messages.ts`)
|
|
13
|
+
|
|
14
|
+
## Instructions
|
|
15
|
+
|
|
16
|
+
### Tooling
|
|
17
|
+
|
|
18
|
+
- **Compiler:** `tsconfig.json` — CommonJS, ES6 target, `noImplicitReturns`, `noUnusedLocals` / `noUnusedParameters`, declarations to **`typings/`**, output **`dist/`**.
|
|
19
|
+
- **Lint:** **`npm run tslint`** with **`tslint.json`** on **`src/**/*.ts`**. This repo has **no ESLint** and **no `npm run lint`** script.
|
|
20
|
+
|
|
21
|
+
### Style (TSLint)
|
|
22
|
+
|
|
23
|
+
- Match `tslint.json`: e.g. 2-space indent, single quotes, no semicolons (`semicolon: never`), max line length 120, `ordered-imports`, `no-default-export` (entry composes via `src/index.ts`), `interface-name` with `I` prefix where used.
|
|
24
|
+
|
|
25
|
+
### Layout
|
|
26
|
+
|
|
27
|
+
- Public exports: **`src/index.ts`** (`Contentstack`, `Contentstack.Stack`).
|
|
28
|
+
- Core query/connection logic: **`src/stack.ts`**.
|
|
29
|
+
- Defaults: **`src/config.ts`**; validation/helpers: **`src/util.ts`**; copy: **`src/messages.ts`**.
|
|
30
|
+
|
|
31
|
+
### JSDoc
|
|
32
|
+
|
|
33
|
+
- Follow existing **`@public` / `@description`** patterns for symbols documented for **`npm run build-doc`**.
|
|
34
|
+
|
|
35
|
+
### Logging
|
|
36
|
+
|
|
37
|
+
- TSLint warns on several **`console`** methods in library code — avoid noisy logging in `src/`.
|
|
38
|
+
|
|
39
|
+
### Dependencies
|
|
40
|
+
|
|
41
|
+
- Do not assume HTTP/REST clients for core behavior — this SDK uses **MongoDB** + **lodash** + **sift** per **`package.json`**.
|
|
42
|
+
|
|
43
|
+
## References
|
|
44
|
+
|
|
45
|
+
- [`../datasync-mongodb/SKILL.md`](../datasync-mongodb/SKILL.md)
|
|
46
|
+
- [`../../AGENTS.md`](../../AGENTS.md)
|
|
Binary file
|