Skip to content

Commit c4b2ce9

Browse files
committed
Added cursor rules and skills
1 parent 01cb59c commit c4b2ce9

17 files changed

Lines changed: 700 additions & 8 deletions

File tree

.cursor/rules/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Cursor Rules – Contentstack Swift CDA SDK
2+
3+
This directory contains Cursor AI rules that apply when working in this repository. Rules provide persistent context so the AI follows project conventions and Contentstack CDA patterns.
4+
5+
## How rules are applied
6+
7+
- **File-specific rules** use the `globs` frontmatter: they apply when you open or edit files matching that pattern.
8+
- **Always-on rules** use `alwaysApply: true`: they are included in every conversation in this project.
9+
10+
## Rule index
11+
12+
| File | Applies when | Purpose |
13+
|------|--------------|---------|
14+
| **dev-workflow.md** | (Reference only; no glob) | Core development workflow: branches, running tests, PR expectations. Read for process guidance. |
15+
| **swift.mdc** | Editing any `**/*.swift` file | Swift standards: naming, `Sources`/`Tests` layout, module **ContentstackSwift**, logging, optionals and error style. |
16+
| **contentstack-swift-cda.mdc** | Editing `Sources/**/*.swift` | CDA-specific patterns: Stack/ContentstackConfig, host/version/region/branch, URLSession, `Result`/`ResultsHandler`, alignment with Content Delivery API. |
17+
| **testing.mdc** | Editing `Tests/**/*.swift` | Testing patterns: XCTest, unit vs integration tests, fixtures, DVR where used. |
18+
| **code-review.mdc** | Always | PR/review checklist: API stability, error handling, backward compatibility, dependencies and security (e.g. SCA). |
19+
20+
## Related
21+
22+
- **AGENTS.md** (repo root) – Main entry point for AI agents: project overview, entry points, and pointers to rules and skills.
23+
- **skills/** – Reusable skill docs (Contentstack Swift CDA, testing, code review, framework) for deeper guidance on specific tasks.

.cursor/rules/code-review.mdc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
description: PR and code review checklist – API stability, errors, compatibility, security
3+
alwaysApply: true
4+
---
5+
6+
# Code Review Checklist – Contentstack Swift CDA SDK
7+
8+
Use this checklist when reviewing pull requests or before opening a PR.
9+
10+
## API design and stability
11+
12+
- [ ] **Public API:** New or changed public types/methods/properties are necessary and clearly documented (Swift documentation comments where the project documents public API).
13+
- [ ] **Backward compatibility:** No breaking changes to public API unless explicitly called out and justified (e.g. major version).
14+
- [ ] **Naming:** Names are consistent with existing SDK style and CDA terminology.
15+
16+
## Error handling and robustness
17+
18+
- [ ] **Errors:** API failures surface through the SDK **`Error`** type and existing **`Result` / `ResultsHandler`** patterns (or `async`/`throws` where the API already uses them).
19+
- [ ] **Optionals:** No unintended force-unwraps; optional values are handled or documented; public contracts use optionals intentionally.
20+
- [ ] **Throws:** Thrown errors are appropriate for the API; callers can distinguish failure modes where the SDK promises it.
21+
22+
## Dependencies and security
23+
24+
- [ ] **Dependencies:** No new dependencies without justification; version bumps are intentional and do not introduce known vulnerabilities.
25+
- [ ] **SCA:** Address any security findings (e.g. from Snyk or similar) in the scope of the PR or in a follow-up.
26+
27+
## Testing
28+
29+
- [ ] **Coverage:** New or modified behavior is covered by unit and/or integration tests as appropriate.
30+
- [ ] **Test quality:** Tests are readable, stable (no flakiness), and follow project conventions (see **testing.mdc**).
31+
32+
## Severity (optional)
33+
34+
- **Blocker:** Must fix before merge (e.g. breaking public API without approval, security issue, no tests for new code).
35+
- **Major:** Should fix (e.g. inconsistent error handling, missing documentation on new public API).
36+
- **Minor:** Nice to fix (e.g. style, minor docs).
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
description: Contentstack CDA patterns – Stack/ContentstackConfig, URLSession, callbacks, Content Delivery API
3+
globs: "Sources/**/*.swift"
4+
---
5+
6+
# Contentstack Swift CDA – SDK Rules
7+
8+
Apply when editing the SDK core (`Sources/`). Keep behavior aligned with the [Content Delivery API](https://www.contentstack.com/docs/apis/content-delivery-api/).
9+
10+
## Stack and ContentstackConfig
11+
12+
- **Entry point:** `Contentstack.stack(apiKey:deliveryToken:environment:region:host:apiVersion:branch:config:)` returns a **`Stack`**. Pass **`ContentstackConfig`** for optional settings.
13+
- **Default host:** `Host.delivery` → **`cdn.contentstack.io`**; non-US regions adjust the host (see `Contentstack.stack` implementation).
14+
- **API version:** Default **`v3`** via the `apiVersion` parameter.
15+
- **Config:** `URLSessionConfiguration` (headers merged with SDK auth headers), `dateDecodingStrategy`, `timeZone`, `earlyAccess`, `urlSessionDelegate` for SSL pinning / session customization.
16+
- **Region / branch:** Use `ContentstackRegion` and optional `branch` on `stack(...)`; branch is sent as the `branch` header when set.
17+
18+
## HTTP layer
19+
20+
- **Requests** use **`URLSession`** created in **`Stack`** from `ContentstackConfig`. Do not bypass it for CDA calls.
21+
- **Headers:** Preserve `User-Agent` / `X-User-Agent` and authorization-related headers the SDK sets; additional headers may come from `sessionConfiguration.httpAdditionalHeaders`.
22+
- **Errors:** Map API failures to the SDK **`Error`** type and deliver them via **`Result`** / **`ResultsHandler`** (or existing async patterns).
23+
24+
## Retry and resilience
25+
26+
- The Swift SDK does not mirror the Java SDK’s **`RetryOptions` / interceptor** stack; resilience is primarily **`URLSession`** behavior and configuration. If adding retry or backoff, keep it configurable via **`ContentstackConfig`** / session and document defaults; align semantics with other CDA SDKs where practical.
27+
28+
## Callbacks and async
29+
30+
- Use existing completion types (**`ResultsHandler`**, `Result<..., Error>` closures) for async results. Do not introduce incompatible callback shapes without considering backward compatibility.
31+
- When adding `async` APIs, mirror existing naming and error mapping.
32+
33+
## CDA concepts
34+
35+
- **Entry, Query, Asset, Content Type, Sync, Taxonomy, Global Field** – follow existing types and method names and CDA semantics (query parameters, response models). When adding CDA features, align with the official Content Delivery API documentation.

.cursor/rules/dev-workflow.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Development Workflow – Contentstack Swift CDA SDK
2+
3+
Use this as the standard workflow when contributing to the Swift CDA SDK.
4+
5+
## Branches
6+
7+
- Use feature branches for changes (e.g. `feat/...`, `fix/...`).
8+
- Base work off the appropriate long-lived branch (e.g. `staging`, `development`, `main`) per team norms.
9+
10+
## Running tests
11+
12+
- **SPM (from repo root):** `swift test`
13+
- **SPM build only:** `swift build`
14+
- **Xcode:** Open `ContentstackSwift.xcodeproj`, select a scheme (e.g. **ContentstackSwift iOS Tests**), and run tests (⌘U).
15+
- **xcodebuild (example):**
16+
`xcodebuild -project ContentstackSwift.xcodeproj -scheme "ContentstackSwift iOS" -destination 'platform=iOS Simulator,name=iPhone 16' test`
17+
Adjust scheme and destination for macOS or tvOS as needed.
18+
19+
Run tests before opening a PR. Tests that call the live CDA may require stack credentials (e.g. `Tests/config.json` or environment-specific setup—do not commit real tokens).
20+
21+
## Pull requests
22+
23+
- Ensure the build passes: `swift test` and/or Xcode tests for affected platforms.
24+
- Follow the **code-review** rule (see `.cursor/rules/code-review.mdc`) for the PR checklist.
25+
- Keep changes backward-compatible for public API; call out any breaking changes clearly.
26+
27+
## Optional: TDD
28+
29+
If the team uses TDD, follow RED–GREEN–REFACTOR when adding behavior: write a failing test first, then implement to pass, then refactor. The **testing** rule and **skills/testing** skill describe test structure and naming.

.cursor/rules/swift.mdc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
description: Swift standards and ContentstackSwift module conventions for the CDA SDK
3+
globs: "**/*.swift"
4+
---
5+
6+
# Swift Standards – Contentstack Swift CDA SDK
7+
8+
Apply these conventions when editing Swift code in this repository.
9+
10+
## Language and tooling
11+
12+
- Match the **Swift** language version expected by `Package.swift` (swift-tools-version) and the Xcode project; avoid APIs that require a newer OS/SDK than declared platforms unless the change is intentional.
13+
- Prefer clear, idiomatic Swift over Objective-C patterns.
14+
15+
## Module and layout
16+
17+
- Library code lives under **`Sources/`** and builds the **`ContentstackSwift`** module.
18+
- Tests live under **`Tests/`** and depend on **ContentstackSwift** (see **testing.mdc** for test-specific rules).
19+
20+
## Naming
21+
22+
- **Types:** PascalCase (e.g. `Stack`, `ContentstackConfig`, `ContentstackResponse`).
23+
- **Methods and variables:** camelCase.
24+
- **Cases in enums:** lowerCamelCase unless matching external API raw values.
25+
26+
## SDK structure
27+
28+
- **`Contentstack`** is the factory; **`Stack`** owns networking and resource accessors (`contentType`, `asset`, `sync`, `taxonomy`, etc.).
29+
- Keep public surface area minimal; use `internal` for implementation details unless a wider API is required.
30+
31+
## Logging
32+
33+
- Use **`ContentstackLogger`** (or existing logging helpers in the SDK) consistently with current call sites.
34+
- Avoid `print` in library code unless that is already the established pattern for a specific diagnostic path.
35+
36+
## Optionals and errors
37+
38+
- Prefer **`Result<Success, Error>`** and **`ResultsHandler`** for async completion APIs where that is the existing pattern.
39+
- Avoid force unwraps (`!`); use `guard let` / `if let` or explicit error handling.
40+
- When adding `throws`, document which errors callers should handle.
41+
42+
## General
43+
44+
- Prefer value types where appropriate; reference types (`class`) are used where identity or inheritance is required (e.g. `Stack`).
45+
- Document public API with `///` comments where the project already documents symbols; keep examples aligned with real usage (`Contentstack.stack(...)`, `ContentstackConfig`).

.cursor/rules/testing.mdc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
description: XCTest patterns, unit vs integration, fixtures and config for Contentstack Swift tests
3+
globs: "Tests/**/*.swift"
4+
---
5+
6+
# Testing Rules – Contentstack Swift CDA SDK
7+
8+
Apply when writing or editing tests. The project uses **XCTest** via SPM (`Tests/`) and Xcode test bundles.
9+
10+
## Test naming and layout
11+
12+
- **Unit tests:** Prefer descriptive type names ending in **`Test`** or **`Tests`** (e.g. `EntryTest`, `StackTest`, `QueryTest`) matching existing files under `Tests/`.
13+
- **Integration / API tests:** Classes that perform live HTTP against Contentstack often end in **`APITest`** or **`Test`** with network setup—follow existing peers (`*APITest.swift`, sync/asset/entry API tests). Use shared helpers (e.g. stack builders, `Tests/config.json`) where the suite already does.
14+
15+
## XCTest usage
16+
17+
- Subclass **`XCTestCase`** (or use extensions on it where the project does).
18+
- Use **`XCTAssert*`** macros; prefer specific assertions over generic truth checks.
19+
- Use **`XCTestExpectation`** for asynchronous completion handlers when not using async test methods.
20+
21+
## Test data and credentials
22+
23+
- **Fixtures:** JSON and resources under `Tests/` (e.g. `*.json`) are copied into test bundles via the Xcode project; keep them in sync when changing test expectations.
24+
- **Live stack:** Do not commit real API keys or delivery tokens. Use local `Tests/config.json` or CI secrets per team practice. Document required keys for integration tests in README or internal docs.
25+
26+
## Unit vs integration
27+
28+
- **Unit:** Mocked or offline data, fast, no network dependency where possible (DVR-cassette tests may apply).
29+
- **Integration:** Real `Stack` and CDA calls—gate on credentials and use reasonable timeouts to avoid hanging CI.
30+
31+
## Quality
32+
33+
- Keep tests deterministic; avoid time- and order-dependent assumptions unless documented.
34+
- When changing production behavior, update or add tests in the same area (query, entry, asset, sync, etc.).

AGENTS.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Contentstack Swift CDA SDK – Agent Guide
2+
3+
This document is the main entry point for AI agents working in this repository.
4+
5+
## Project
6+
7+
- **Name:** Contentstack Swift CDA SDK (contentstack-swift)
8+
- **Purpose:** Swift client for the Contentstack **Content Delivery API (CDA)**. It fetches content (entries, assets, content types, sync, taxonomy, global fields) from Contentstack for iOS, macOS, tvOS, watchOS, and Swift Package Manager consumers.
9+
- **Repo:** [contentstack-swift](https://github.com/contentstack/contentstack-swift)
10+
11+
## Tech stack
12+
13+
- **Language:** Swift (SPM minimum **swift-tools-version 5.6**; align with Xcode requirements in README)
14+
- **Build:** Swift Package Manager (`Package.swift`), **Xcode** (`ContentstackSwift.xcodeproj`) for multi-platform frameworks and CocoaPods (`ContentstackSwift.podspec`)
15+
- **Testing:** **XCTest** (`Tests/`), optional **DVR** (HTTP recording) for some tests; integration-style tests may use `Tests/config.json` / stack credentials
16+
- **HTTP:** **URLSession** (configured via `ContentstackConfig.sessionConfiguration`), optional **`CSURLSessionDelegate`** (SSL pinning / customization)
17+
- **Other:** [contentstack-utils-swift](https://github.com/contentstack/contentstack-utils-swift) (Rich text rendering)
18+
19+
## Main entry points
20+
21+
- **`Contentstack`** – Static factory: `Contentstack.stack(apiKey:deliveryToken:environment:region:host:apiVersion:branch:config:)` returns a `Stack`.
22+
- **`Stack`** – Main API surface: content types, entries, assets, sync, taxonomy, queries, cache policy, JSON decoding.
23+
- **`ContentstackConfig`** – Optional configuration: `URLSessionConfiguration`, date/time zone decoding, early access headers, `urlSessionDelegate`, user agent.
24+
- **Paths:** `Sources/` (library target **ContentstackSwift**), `Tests/` (test target **ContentstackTests**).
25+
26+
## Commands
27+
28+
- **SPM build:** `swift build`
29+
- **SPM tests:** `swift test`
30+
- **Xcode:** Open `ContentstackSwift.xcodeproj`, then build/test schemes such as **ContentstackSwift iOS**, **ContentstackSwift macOS**, **ContentstackSwift tvOS** (and matching test targets).
31+
- **xcodebuild (example – adjust simulator/OS):**
32+
`xcodebuild -project ContentstackSwift.xcodeproj -scheme "ContentstackSwift iOS" -destination 'platform=iOS Simulator,name=iPhone 16' build test`
33+
34+
Run tests before opening a PR. API/integration tests that hit a live stack need valid credentials (see test helpers and `Tests/config.json` where applicable); do not commit secrets.
35+
36+
## Rules and skills
37+
38+
- **`.cursor/rules/`** – Cursor rules for this repo:
39+
- **README.md** – Index of all rules and when each applies (globs / always-on).
40+
- **dev-workflow.md** – Development workflow (branches, tests, PR expectations).
41+
- **swift.mdc** – Applies to `**/*.swift`: Swift style, module layout, logging, optionals.
42+
- **contentstack-swift-cda.mdc** – Applies to `Sources/**/*.swift`: CDA patterns, Stack/Config, host/version/region/branch, callbacks, alignment with Content Delivery API.
43+
- **testing.mdc** – Applies to `Tests/**/*.swift`: test naming, unit vs integration, XCTest.
44+
- **code-review.mdc** – Always applied: PR/review checklist (aligned with other Contentstack CDA SDKs).
45+
- **`skills/`** – Reusable skill docs:
46+
- Use **contentstack-swift-cda** when implementing or changing CDA API usage or SDK core behavior.
47+
- Use **testing** when adding or refactoring tests.
48+
- Use **code-review** when reviewing PRs or before opening one.
49+
- Use **framework** when changing config, URL session setup, or HTTP-related behavior (`ContentstackConfig`, `Stack` networking).
50+
51+
Refer to `.cursor/rules/README.md` for when each rule applies and to `skills/README.md` for skill details.

0 commit comments

Comments
 (0)