|
| 1 | +--- |
| 2 | +description: Marketplace / Developer Hub SDK — auth, host, HTTP behavior in lib/ |
| 3 | +globs: lib/** |
| 4 | +alwaysApply: false |
| 5 | +--- |
| 6 | + |
| 7 | +# Contentstack Marketplace SDK (`lib/`) |
| 8 | + |
| 9 | +This package is a **Marketplace (Developer Hub) management** client, not **CDA** and not generic **stack CMA content** APIs. Terminology and docs should say **Marketplace**, Developer Hub, apps, installations, hosting, OAuth as appropriate—avoid implying Delivery or stack entry CRUD unless adding a new surface that truly uses those APIs. |
| 10 | + |
| 11 | +## Client bootstrap |
| 12 | + |
| 13 | +- **`lib/contentstack.js` — `client(params)`:** Builds axios-based HTTP client via `contentstackHTTPClient`, merges `authtoken` / `authorization` into headers, sets `X-User-Agent` / `User-Agent` (includes `contentstack-marketplace-sdk/<version>`). Default hostname comes from `@contentstack/utils` `getContentstackEndpoint(region, 'developerHub', true)`. |
| 14 | +- **`Region`:** `lib/core/region.js` — `eu`, `na` (empty string), `azure-na`, `azure-eu`, `gcp-na`. Pass via `params.region` (lowercased internally). |
| 15 | + |
| 16 | +## Auth patterns (actual usage) |
| 17 | + |
| 18 | +- Headers: `authtoken` and/or `authorization` (e.g. OAuth bearer) on the axios instance. |
| 19 | +- **`contentstackClient.login`:** POST to `/v3/user-session` (host varies by `region` / `host`); stores returned `authtoken` on `http.defaults.headers.common`. |
| 20 | +- **`refreshToken`:** Optional callback in `client()` params (see JSDoc in `contentstack.js`) for token rotation. |
| 21 | +- **Marketplace calls:** `client.marketplace(orgUid)` → `lib/marketplace/**` (apps, installation, hosting, webhooks, OAuth helpers, authorization, app requests). |
| 22 | + |
| 23 | +## HTTP layer |
| 24 | + |
| 25 | +- **`lib/core/contentstackHTTPClient.js`:** Axios instance, default `timeout` 30000, `retryOnError` true, default `retryCondition` retries on **HTTP 429**. Uses `Qs` for `paramsSerializer` (including encoded `query` JSON). `versioningStrategy: 'path'`. |
| 26 | +- **Concurrency:** `lib/core/concurrency-queue.js` caps parallel requests (`maxRequests`). |
| 27 | +- **Errors:** Responses go through `lib/core/contentstackError.js` — enriches thrown `Error` with `status`, `errorMessage`, `errorCode`, `errors`, sanitized headers. |
| 28 | + |
| 29 | +## Official docs alignment |
| 30 | + |
| 31 | +Relate behavior to **Developer Hub / Marketplace** and **user session** documentation on [contentstack.com/docs](https://www.contentstack.com/docs), not to **CDA** delivery references unless the code explicitly integrates delivery tokens for a marketplace feature. |
0 commit comments