@tandem-language-exchange/content-store 1.0.21 → 1.1.0

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/README.md CHANGED
@@ -4,6 +4,11 @@ SDK for fetching CMS content bundles from S3 and querying them locally from the
4
4
 
5
5
  For the server, CLI, and deployment documentation, see the [Server & CLI README](src/server/README.md).
6
6
 
7
+ ### Package entry points
8
+
9
+ - **`@tandem-language-exchange/content-store`** (default) — **types only** at runtime. Safe to import from shared code that Next.js, Vite, or Turbopack may bundle for the browser.
10
+ - **`@tandem-language-exchange/content-store/node`** — `ContentStoreSDK`, `fetchBundles`, `queryBundle`, `ContentStore`, and `trimDepth`. Use only in Node (Route Handlers, Server Actions, scripts, CLI).
11
+
7
12
  ## Installation
8
13
 
9
14
  ```bash
@@ -13,7 +18,7 @@ npm install content-store
13
18
  ## Initialisation
14
19
 
15
20
  ```typescript
16
- import { ContentStoreSDK } from 'content-store';
21
+ import { ContentStoreSDK } from '@tandem-language-exchange/content-store/node';
17
22
 
18
23
  const sdk = new ContentStoreSDK({
19
24
  s3: {
@@ -225,7 +230,7 @@ Query options are applied in this order:
225
230
  The core `fetchBundles` and `queryBundle` functions are also available as standalone imports for use outside the SDK class:
226
231
 
227
232
  ```typescript
228
- import { fetchBundles, queryBundle, ContentStore } from 'content-store';
233
+ import { fetchBundles, queryBundle, ContentStore } from '@tandem-language-exchange/content-store/node';
229
234
 
230
235
  const store = new ContentStore({
231
236
  bucket: 'beta-content-store',
@@ -248,7 +253,7 @@ const results = await queryBundle('./content-cache', 'contentful', 'gridLayout',
248
253
  ## Full example
249
254
 
250
255
  ```typescript
251
- import { ContentStoreSDK } from 'content-store';
256
+ import { ContentStoreSDK } from '@tandem-language-exchange/content-store/node';
252
257
 
253
258
  const sdk = new ContentStoreSDK({
254
259
  s3: {
@@ -92,29 +92,40 @@ async function withRetry(fn, { maxRetries, baseDelayMs, maxDelayMs }) {
92
92
  }
93
93
 
94
94
  // src/server/adapters/contentful.ts
95
- function stripEnvelope(value, maxDepth, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
95
+ function stripEnvelope(value, maxDepth, depth = 0, path = /* @__PURE__ */ new WeakSet()) {
96
96
  if (value === null || typeof value !== "object") return value;
97
97
  const obj = value;
98
- if (seen.has(obj)) return void 0;
99
- seen.add(obj);
100
- if (Array.isArray(value)) {
101
- return value.map((item) => stripEnvelope(item, maxDepth, depth, seen));
102
- }
103
- const isEnvelope = "sys" in obj && "fields" in obj && typeof obj.fields === "object";
104
- if (isEnvelope) {
105
- if (depth >= maxDepth) return void 0;
106
- const fields = obj.fields;
107
- const result2 = {};
108
- for (const [k, v] of Object.entries(fields)) {
109
- result2[k] = stripEnvelope(v, maxDepth, depth + 1, seen);
98
+ if (path.has(obj)) return void 0;
99
+ path.add(obj);
100
+ try {
101
+ if (Array.isArray(value)) {
102
+ return value.map((item) => stripEnvelope(item, maxDepth, depth, path));
110
103
  }
111
- return result2;
112
- }
113
- const result = {};
114
- for (const [k, v] of Object.entries(obj)) {
115
- result[k] = stripEnvelope(v, maxDepth, depth, seen);
104
+ const isEnvelope = "sys" in obj && "fields" in obj && typeof obj.fields === "object";
105
+ if (isEnvelope) {
106
+ if (depth >= maxDepth) return void 0;
107
+ const fields = obj.fields;
108
+ const result2 = {};
109
+ for (const [k, v] of Object.entries(fields)) {
110
+ result2[k] = stripEnvelope(v, maxDepth, depth + 1, path);
111
+ }
112
+ const sys = obj.sys;
113
+ if (sys && typeof sys.id === "string") {
114
+ const existingMeta = result2.meta;
115
+ const metaBase = typeof existingMeta === "object" && existingMeta !== null && !Array.isArray(existingMeta) ? existingMeta : {};
116
+ const _contentType = sys.contentType ? sys.contentType.sys.id : "Asset";
117
+ result2.meta = { ...metaBase, _id: sys.id, _contentType, _updatedAt: sys.updatedAt };
118
+ }
119
+ return result2;
120
+ }
121
+ const result = {};
122
+ for (const [k, v] of Object.entries(obj)) {
123
+ result[k] = stripEnvelope(v, maxDepth, depth, path);
124
+ }
125
+ return result;
126
+ } finally {
127
+ path.delete(obj);
116
128
  }
117
- return result;
118
129
  }
119
130
  var ContentfulAdapter = class {
120
131
  name = "contentful";
@@ -150,20 +161,18 @@ var ContentfulAdapter = class {
150
161
  * Contentful caps `getEntries` at 1 000 items per call, so we page through
151
162
  * with `skip` until all items are collected.
152
163
  */
153
- async fetchAll(contentType) {
164
+ async fetchAll(contentType, includeLevels = 4) {
154
165
  const allItems = [];
155
166
  let skip = 0;
156
167
  let total = 0;
157
168
  do {
158
- const response = await withRetry(
159
- () => this.client.getEntries({
160
- content_type: contentType,
161
- limit: this.batchSize,
162
- skip,
163
- include: 2
164
- }),
165
- this.retryConfig
166
- );
169
+ const payload = {
170
+ content_type: contentType,
171
+ limit: this.batchSize,
172
+ skip,
173
+ include: includeLevels
174
+ };
175
+ const response = await this.client.getEntries(payload);
167
176
  total = response.total;
168
177
  allItems.push(...response.items);
169
178
  skip += response.items.length;
@@ -173,7 +182,11 @@ var ContentfulAdapter = class {
173
182
  );
174
183
  }
175
184
  } while (skip < total);
176
- return { contentType, items: allItems.map((item) => stripEnvelope(item, this.maxDepth)), total };
185
+ return {
186
+ contentType,
187
+ items: allItems.map((item) => stripEnvelope(item, this.maxDepth)),
188
+ total
189
+ };
177
190
  }
178
191
  };
179
192
 
@@ -225,7 +238,7 @@ function createAdapter(cms) {
225
238
  }
226
239
 
227
240
  // src/server/sync/engine.ts
228
- async function runSync(cms, contentTypes) {
241
+ async function runSync(cms, contentTypes, includeLevels) {
229
242
  const adapter = createAdapter(cms);
230
243
  const store = new ContentStore(config2.s3);
231
244
  const timestamp = Math.floor(Date.now() / 1e3);
@@ -238,7 +251,7 @@ Starting sync from ${cms} at ${new Date(timestamp * 1e3).toISOString()}`);
238
251
  const errors = [];
239
252
  for (const contentType of typesToSync) {
240
253
  try {
241
- const result = await adapter.fetchAll(contentType);
254
+ const result = await adapter.fetchAll(contentType, includeLevels);
242
255
  const versionedKey = store.buildVersionedKey(cms, contentType, timestamp);
243
256
  await store.upload(versionedKey, result.items);
244
257
  const latestKey = await store.copyToLatest(versionedKey, cms, contentType);
@@ -269,4 +282,4 @@ export {
269
282
  config2 as config,
270
283
  runSync
271
284
  };
272
- //# sourceMappingURL=chunk-ORHMX5UP.js.map
285
+ //# sourceMappingURL=chunk-EGDGHYGI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/config.ts","../src/server/adapters/contentful.ts","../src/server/sync/retry.ts","../src/server/adapters/sanity.ts","../src/server/adapters/index.ts","../src/server/sync/engine.ts"],"sourcesContent":["import dotenv from 'dotenv';\nimport type { S3Config, CMSProvider } from '../shared/types';\nimport {SharedConfig, config as sharedConfig} from '../shared/config';\n\ndotenv.config({ path: '.env.local' });\ndotenv.config();\n\nexport type { CMSProvider, S3Config };\n\nexport interface ContentfulConfig {\n spaceId: string;\n accessToken: string;\n host: string;\n batchSize: number;\n /** Content types to sync. When empty, all content types in the space are synced. */\n contentTypes: string[];\n /** Max nesting depth when unwrapping resolved entries. Deeper references are dropped. */\n maxDepth: number;\n}\n\nexport interface SanityConfig {\n projectId: string;\n dataset: string;\n token: string;\n apiVersion: string;\n}\n\nexport interface RetryConfig {\n maxRetries: number;\n baseDelayMs: number;\n maxDelayMs: number;\n}\n\nexport interface RestApiConfig {\n port: number;\n apiToken: string;\n}\n\nexport interface ServerConfig {\n contentful: ContentfulConfig;\n sanity: SanityConfig;\n retry: RetryConfig;\n api: RestApiConfig;\n}\n\nexport const config: ServerConfig & SharedConfig = {\n ...sharedConfig,\n contentful: {\n spaceId: process.env.CONTENTFUL_SPACE_ID ?? '',\n accessToken: process.env.CONTENTFUL_WEBSITE_TOKEN ?? '',\n host: process.env.CONTENTFUL_HOST ?? 'preview.contentful.com',\n batchSize: 1000,\n maxDepth: 4,\n contentTypes: [\n 'gridLayout','iconWithText','page'\n // Add Contentful content type IDs here to limit sync scope.\n // Leave empty to sync all content types in the space.\n ],\n },\n\n sanity: {\n projectId: process.env.SANITY_PROJECT_ID ?? '',\n dataset: process.env.SANITY_DATASET ?? 'main',\n token: process.env.SANITY_API_TOKEN ?? '',\n apiVersion: '2024-01-01',\n },\n\n retry: {\n maxRetries: parseInt(process.env.RETRY_MAX_RETRIES ?? '5', 10),\n baseDelayMs: parseInt(process.env.RETRY_BASE_DELAY_MS ?? '1000', 10),\n maxDelayMs: parseInt(process.env.RETRY_MAX_DELAY_MS ?? '60000', 10),\n },\n\n api: {\n port: parseInt(process.env.PORT ?? '3010'),\n apiToken: process.env.CONTENT_STORE_API_TOKEN ?? '',\n },\n};\n","import {\n createClient,\n type ContentfulClientApi,\n type ContentTypeCollection,\n type EntryCollection,\n type EntrySkeletonType,\n} from 'contentful';\nimport type { ContentfulConfig, RetryConfig } from '../config';\nimport type { CMSAdapter, FetchResult } from './types';\nimport { withRetry } from '../sync/retry';\n\ntype CfCollection = {\n items: CfItem[],\n total: number\n}\n\ntype CfItem = {\n metadata:{\n tags: string[],\n concepts: string[]\n }\n sys:{\n type: string,\n id: string\n space: {\n sys: {\n type: string\n linkType: string\n id: string\n }\n },\n environment: {\n sys: {\n id: string\n type: \"Link\",\n linkType: \"Environment\"\n }\n },\n contentType: {\n sys: {\n type: \"Link\",\n linkType: \"ContentType\",\n id: string\n }\n },\n createdBy: {\n sys: {\n type: \"Link\",\n linkType: \"User\",\n id: string,\n }\n },\n updatedBy: {\n sys: {\n type: \"Link\",\n linkType: \"User\",\n id: string\n }\n },\n \"revision\": 34,\n \"createdAt\": \"2025-07-24T15:57:06.033Z\",\n \"updatedAt\": \"2026-04-07T13:44:03.588Z\",\n \"publishedVersion\": 188\n },\n fields:{\n [key:string]: any\n }\n}\n\n\n/**\n * Recursively unwraps Contentful's { metadata, sys, fields } envelope.\n * `depth` tracks how many entry/asset envelopes deep we are — anything\n * beyond `maxDepth` is dropped to avoid blowing the call stack on\n * circular or extremely deep reference chains.\n *\n * `path` holds objects on the current recursion branch only. That way a\n * shared reference (e.g. the same asset on `image` and `mobileImage`) is\n * unwrapped for each sibling; only true cycles (an object recurring as a\n * descendant of itself) yield `undefined`.\n */\nfunction stripEnvelope(\n value: unknown,\n maxDepth: number,\n depth = 0,\n path = new WeakSet<object>(),\n): unknown {\n if (value === null || typeof value !== 'object') return value;\n\n const obj = value as CfItem;\n\n if (path.has(obj)) return undefined;\n path.add(obj);\n\n try {\n if (Array.isArray(value)) {\n return value.map((item) => stripEnvelope(item, maxDepth, depth, path));\n }\n\n const isEnvelope = 'sys' in obj && 'fields' in obj && typeof obj.fields === 'object';\n\n if (isEnvelope) {\n if (depth >= maxDepth) return undefined;\n\n const fields = obj.fields as Record<string, unknown>;\n const result: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(fields)) {\n result[k] = stripEnvelope(v, maxDepth, depth + 1, path);\n }\n\n const sys = obj.sys;\n if (sys && typeof sys.id === 'string') {\n const existingMeta = result.meta;\n const metaBase =\n typeof existingMeta === 'object' &&\n existingMeta !== null &&\n !Array.isArray(existingMeta)\n ? (existingMeta as Record<string, unknown>)\n : {};\n const _contentType = sys.contentType ? sys.contentType.sys.id : 'Asset'\n result.meta = { ...metaBase, _id: sys.id, _contentType, _updatedAt: sys.updatedAt };\n }\n\n return result;\n }\n\n const result: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n result[k] = stripEnvelope(v, maxDepth, depth, path);\n }\n return result;\n } finally {\n path.delete(obj);\n }\n}\n\nexport class ContentfulAdapter implements CMSAdapter {\n readonly name = 'contentful';\n private client: ContentfulClientApi<undefined>;\n private batchSize: number;\n private maxDepth: number;\n private allowedTypes: string[];\n private retryConfig: RetryConfig;\n\n constructor(cfg: ContentfulConfig, retryConfig: RetryConfig) {\n this.client = createClient({\n space: cfg.spaceId,\n accessToken: cfg.accessToken,\n host: cfg.host,\n });\n this.batchSize = cfg.batchSize;\n this.maxDepth = cfg.maxDepth;\n this.allowedTypes = cfg.contentTypes;\n this.retryConfig = retryConfig;\n }\n\n async getContentTypes(): Promise<string[]> {\n const response = await withRetry<ContentTypeCollection>(\n () => this.client.getContentTypes(),\n this.retryConfig,\n );\n\n const allTypes = response.items.map((ct) => ct.sys.id);\n\n if (this.allowedTypes.length > 0) {\n return allTypes.filter((t) => this.allowedTypes.includes(t));\n }\n return allTypes;\n }\n\n /**\n * Fetches every entry for a content type using batched pagination.\n * Contentful caps `getEntries` at 1 000 items per call, so we page through\n * with `skip` until all items are collected.\n */\n async fetchAll(contentType: string, includeLevels: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 = 4): Promise<FetchResult> {\n const allItems: unknown[] = [];\n let skip = 0;\n let total = 0;\n\n do {\n const payload = {\n content_type: contentType,\n limit: this.batchSize,\n skip,\n include: includeLevels,\n };\n const response = await this.client.getEntries(payload) as unknown as CfCollection;\n total = response.total;\n allItems.push(...response.items);\n skip += response.items.length;\n\n if (total > this.batchSize) {\n console.log(\n ` [contentful] ${contentType}: fetched ${allItems.length}/${total}`,\n );\n }\n } while (skip < total);\n\n return {\n contentType,\n items: allItems.map((item) => stripEnvelope(item, this.maxDepth)),\n total,\n };\n }\n}\n","import type { RetryConfig } from '../config';\n\n/**\n * Inspects an error to determine if it represents an API rate-limit (HTTP 429).\n * Returns the suggested wait time in ms when available, otherwise `0` to signal\n * that the caller should fall back to computed backoff. Returns `null` when the\n * error is *not* a rate-limit error.\n */\nfunction rateLimitDelayMs(err: unknown): number | null {\n const e = err as Record<string, unknown>;\n\n if (e?.status === 429 || e?.statusCode === 429) {\n const reset = (e?.headers as Record<string, string> | undefined)?.[\n 'x-contentful-ratelimit-reset'\n ];\n return reset ? parseFloat(reset) * 1000 : 0;\n }\n\n const resp = e?.response as Record<string, unknown> | undefined;\n if (resp?.status === 429) {\n const headers = resp?.headers as Record<string, string> | undefined;\n const reset = headers?.['x-contentful-ratelimit-reset'];\n return reset ? parseFloat(reset) * 1000 : 0;\n }\n\n return null;\n}\n\nfunction computeDelay(\n attempt: number,\n baseDelayMs: number,\n maxDelayMs: number,\n): number {\n const exponential = baseDelayMs * Math.pow(2, attempt);\n const jitter = Math.random() * baseDelayMs;\n return Math.min(exponential + jitter, maxDelayMs);\n}\n\n/**\n * Executes `fn` with automatic retry + exponential backoff.\n * Rate-limit (429) responses are handled specially: if the API provides a\n * Retry-After / reset header, that value is respected instead of computed backoff.\n */\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n { maxRetries, baseDelayMs, maxDelayMs }: RetryConfig,\n): Promise<T> {\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await fn();\n } catch (err) {\n if (attempt === maxRetries) throw err;\n\n const rlDelay = rateLimitDelayMs(err);\n let delay: number;\n\n if (rlDelay !== null) {\n delay =\n rlDelay > 0 ? rlDelay : computeDelay(attempt, baseDelayMs, maxDelayMs);\n console.warn(\n ` Rate limited (attempt ${attempt + 1}/${maxRetries}). ` +\n `Waiting ${Math.round(delay)}ms…`,\n );\n } else {\n delay = computeDelay(attempt, baseDelayMs, maxDelayMs);\n console.warn(\n ` Request failed (attempt ${attempt + 1}/${maxRetries}): ` +\n `${(err as Error).message}. Retrying in ${Math.round(delay)}ms…`,\n );\n }\n\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n\n throw new Error('withRetry: unreachable');\n}\n","import { createClient, type SanityClient } from '@sanity/client';\nimport type { SanityConfig, RetryConfig } from '../config';\nimport type { CMSAdapter, FetchResult } from './types';\nimport { withRetry } from '../sync/retry';\n\nexport class SanityAdapter implements CMSAdapter {\n readonly name = 'sanity';\n private client: SanityClient;\n private retryConfig: RetryConfig;\n\n constructor(cfg: SanityConfig, retryConfig: RetryConfig) {\n this.client = createClient({\n projectId: cfg.projectId,\n dataset: cfg.dataset,\n token: cfg.token,\n apiVersion: cfg.apiVersion,\n useCdn: false,\n });\n this.retryConfig = retryConfig;\n }\n\n async getContentTypes(): Promise<string[]> {\n const types: string[] = await withRetry(\n () => this.client.fetch(`array::unique(*[]._type)`),\n this.retryConfig,\n );\n return types.filter(\n (t) => !t.startsWith('system.') && !t.startsWith('sanity.'),\n );\n }\n\n async fetchAll(contentType: string): Promise<FetchResult> {\n const items: unknown[] = await withRetry(\n () => this.client.fetch(`*[_type == $type]`, { type: contentType }),\n this.retryConfig,\n );\n\n console.log(` [sanity] ${contentType}: fetched ${items.length} items`);\n return { contentType, items, total: items.length };\n }\n}\n","import { config, type CMSProvider } from '../config';\nimport type { CMSAdapter } from './types';\nimport { ContentfulAdapter } from './contentful';\nimport { SanityAdapter } from './sanity';\n\nexport function createAdapter(cms: CMSProvider): CMSAdapter {\n switch (cms) {\n case 'contentful':\n return new ContentfulAdapter(config.contentful, config.retry);\n case 'sanity':\n return new SanityAdapter(config.sanity, config.retry);\n default:\n throw new Error(`Unknown CMS provider: ${cms as string}`);\n }\n}\n\nexport type { CMSAdapter, FetchResult } from './types';\n","import type { CMSProvider } from '../config';\nimport { config } from '../config';\nimport { createAdapter } from '../adapters';\nimport { ContentStore } from '../../shared/s3';\n\nexport interface SyncResultEntry {\n contentType: string;\n itemCount: number;\n versionedKey: string;\n latestKey: string;\n}\n\nexport interface SyncResult {\n cms: CMSProvider;\n timestamp: number;\n entries: SyncResultEntry[];\n errors: Array<{ contentType: string; error: string }>;\n}\n\nexport async function runSync(\n cms: CMSProvider,\n contentTypes?: string[],\n includeLevels?: number\n): Promise<SyncResult> {\n const adapter = createAdapter(cms);\n const store = new ContentStore(config.s3);\n const timestamp = Math.floor(Date.now() / 1000);\n\n console.log(`\\nStarting sync from ${cms} at ${new Date(timestamp * 1000).toISOString()}`);\n\n const typesToSync =\n contentTypes && contentTypes.length > 0\n ? contentTypes\n : await adapter.getContentTypes();\n\n console.log(`Content types to sync: ${typesToSync.join(', ')}\\n`);\n\n const entries: SyncResultEntry[] = [];\n const errors: Array<{ contentType: string; error: string }> = [];\n\n for (const contentType of typesToSync) {\n try {\n const result = await adapter.fetchAll(contentType, includeLevels);\n const versionedKey = store.buildVersionedKey(cms, contentType, timestamp);\n await store.upload(versionedKey, result.items);\n\n const latestKey = await store.copyToLatest(versionedKey, cms, contentType);\n\n entries.push({\n contentType,\n itemCount: result.total,\n versionedKey,\n latestKey,\n });\n\n console.log(\n ` + ${contentType}: ${result.total} items -> ${versionedKey}`,\n );\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n errors.push({ contentType, error: message });\n console.error(` x ${contentType}: ${message}`);\n }\n }\n\n console.log(\n `\\nSync complete: ${entries.length} succeeded, ${errors.length} failed\\n`,\n );\n\n return { cms, timestamp, entries, errors };\n}\n"],"mappings":";;;;;;;AAAA,OAAO,YAAY;AAInB,OAAO,OAAO,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,OAAO;AAwCP,IAAMA,UAAsC;AAAA,EACjD,GAAG;AAAA,EACH,YAAY;AAAA,IACV,SAAS,QAAQ,IAAI,uBAAuB;AAAA,IAC5C,aAAa,QAAQ,IAAI,4BAA4B;AAAA,IACrD,MAAM,QAAQ,IAAI,mBAAmB;AAAA,IACrC,WAAW;AAAA,IACX,UAAU;AAAA,IACV,cAAc;AAAA,MACV;AAAA,MAAa;AAAA,MAAe;AAAA;AAAA;AAAA,IAGhC;AAAA,EACF;AAAA,EAEA,QAAQ;AAAA,IACN,WAAW,QAAQ,IAAI,qBAAqB;AAAA,IAC5C,SAAS,QAAQ,IAAI,kBAAkB;AAAA,IACvC,OAAO,QAAQ,IAAI,oBAAoB;AAAA,IACvC,YAAY;AAAA,EACd;AAAA,EAEA,OAAO;AAAA,IACL,YAAY,SAAS,QAAQ,IAAI,qBAAqB,KAAK,EAAE;AAAA,IAC7D,aAAa,SAAS,QAAQ,IAAI,uBAAuB,QAAQ,EAAE;AAAA,IACnE,YAAY,SAAS,QAAQ,IAAI,sBAAsB,SAAS,EAAE;AAAA,EACpE;AAAA,EAEA,KAAK;AAAA,IACH,MAAM,SAAS,QAAQ,IAAI,QAAQ,MAAM;AAAA,IACzC,UAAU,QAAQ,IAAI,2BAA2B;AAAA,EACnD;AACF;;;AC7EA;AAAA,EACE;AAAA,OAKK;;;ACEP,SAAS,iBAAiB,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QAAM,UAAU,cAAc,GAAG;AACjC,QAAM,QAAQ,IAAI,aAAaC,QAAO,EAAE;AACxC,QAAM,YAAY,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AAE9C,UAAQ,IAAI;AAAA,qBAAwB,GAAG,OAAO,IAAI,KAAK,YAAY,GAAI,EAAE,YAAY,CAAC,EAAE;AAExF,QAAM,cACJ,gBAAgB,aAAa,SAAS,IAClC,eACA,MAAM,QAAQ,gBAAgB;AAEpC,UAAQ,IAAI,0BAA0B,YAAY,KAAK,IAAI,CAAC;AAAA,CAAI;AAEhE,QAAM,UAA6B,CAAC;AACpC,QAAM,SAAwD,CAAC;AAE/D,aAAW,eAAe,aAAa;AACrC,QAAI;AACF,YAAM,SAAS,MAAM,QAAQ,SAAS,aAAa,aAAa;AAChE,YAAM,eAAe,MAAM,kBAAkB,KAAK,aAAa,SAAS;AACxE,YAAM,MAAM,OAAO,cAAc,OAAO,KAAK;AAE7C,YAAM,YAAY,MAAM,MAAM,aAAa,cAAc,KAAK,WAAW;AAEzE,cAAQ,KAAK;AAAA,QACX;AAAA,QACA,WAAW,OAAO;AAAA,QAClB;AAAA,QACA;AAAA,MACF,CAAC;AAED,cAAQ;AAAA,QACN,OAAO,WAAW,KAAK,OAAO,KAAK,aAAa,YAAY;AAAA,MAC9D;AAAA,IACF,SAAS,KAAK;AACZ,YAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC/D,aAAO,KAAK,EAAE,aAAa,OAAO,QAAQ,CAAC;AAC3C,cAAQ,MAAM,OAAO,WAAW,KAAK,OAAO,EAAE;AAAA,IAChD;AAAA,EACF;AAEA,UAAQ;AAAA,IACN;AAAA,iBAAoB,QAAQ,MAAM,eAAe,OAAO,MAAM;AAAA;AAAA,EAChE;AAEA,SAAO,EAAE,KAAK,WAAW,SAAS,OAAO;AAC3C;","names":["config","result","createClient","createClient","config","config"]}
@@ -41,6 +41,63 @@ function trimDepth(value, remaining) {
41
41
  }
42
42
  return result;
43
43
  }
44
+ function getAtPath(obj, dottedPath) {
45
+ const parts = dottedPath.split(".").filter((p) => p.length > 0);
46
+ if (parts.length === 0) return { found: false };
47
+ let cur = obj;
48
+ for (const p of parts) {
49
+ if (cur === null || typeof cur !== "object" || Array.isArray(cur)) {
50
+ return { found: false };
51
+ }
52
+ const rec = cur;
53
+ if (!(p in rec)) return { found: false };
54
+ cur = rec[p];
55
+ }
56
+ return { found: true, value: cur };
57
+ }
58
+ var FIELD_OP_KEY = /^(.+)\[([^\]]+)\]$/;
59
+ function parseFieldKey(key) {
60
+ const m = FIELD_OP_KEY.exec(key);
61
+ if (!m) return { path: key };
62
+ return { path: m[1], operator: m[2] };
63
+ }
64
+ function isEmptyValue(value) {
65
+ if (value === null || value === void 0) return true;
66
+ if (value === "") return true;
67
+ if (Array.isArray(value) && value.length === 0) return true;
68
+ if (typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0) {
69
+ return true;
70
+ }
71
+ return false;
72
+ }
73
+ function matchesFieldFilter(item, key, expected) {
74
+ const { path: path2, operator } = parseFieldKey(key);
75
+ const at = getAtPath(item, path2);
76
+ if (operator === "exists") {
77
+ if (expected !== true && expected !== false) return false;
78
+ const empty = !at.found || isEmptyValue(at.value);
79
+ return expected === false ? empty : !empty;
80
+ }
81
+ const actual = at.found ? at.value : void 0;
82
+ if (Array.isArray(expected)) return expected.includes(actual);
83
+ return actual === expected;
84
+ }
85
+ function setNestedAt(target, dottedPath, value) {
86
+ const parts = dottedPath.split(".").filter((p) => p.length > 0);
87
+ if (parts.length === 0) return;
88
+ if (parts.length === 1) {
89
+ target[parts[0]] = value;
90
+ return;
91
+ }
92
+ const head = parts[0];
93
+ const rest = parts.slice(1).join(".");
94
+ let nested = target[head];
95
+ if (nested === null || typeof nested !== "object" || Array.isArray(nested)) {
96
+ nested = {};
97
+ target[head] = nested;
98
+ }
99
+ setNestedAt(nested, rest, value);
100
+ }
44
101
  async function fetchBundles(store, outputDir, options) {
45
102
  const { cms, contentTypes } = options;
46
103
  await fs.mkdir(outputDir, { recursive: true });
@@ -69,11 +126,9 @@ async function queryBundle(outputDir, cms, contentType, options = {}) {
69
126
  if (options.fields) {
70
127
  const filters = options.fields;
71
128
  items = items.filter(
72
- (item) => Object.entries(filters).every(([key, expected]) => {
73
- const actual = item[key];
74
- if (Array.isArray(expected)) return expected.includes(actual);
75
- return actual === expected;
76
- })
129
+ (item) => Object.entries(filters).every(
130
+ ([key, expected]) => matchesFieldFilter(item, key, expected)
131
+ )
77
132
  );
78
133
  }
79
134
  if (options.limit !== void 0 && options.limit > 0) {
@@ -89,7 +144,8 @@ async function queryBundle(outputDir, cms, contentType, options = {}) {
89
144
  items = items.map((item) => {
90
145
  const picked = {};
91
146
  for (const k of keys) {
92
- if (k in item) picked[k] = item[k];
147
+ const at = getAtPath(item, k);
148
+ if (at.found) setNestedAt(picked, k, at.value);
93
149
  }
94
150
  return picked;
95
151
  });
@@ -102,4 +158,4 @@ export {
102
158
  fetchBundles,
103
159
  queryBundle
104
160
  };
105
- //# sourceMappingURL=chunk-A3NFNDO4.js.map
161
+ //# sourceMappingURL=chunk-JFI26IB3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client/config.ts","../src/shared/bundles.ts"],"sourcesContent":["import dotenv from 'dotenv';\nimport type { S3Config, CMSProvider } from '../shared/types';\nimport {SharedConfig, config as sharedConfig} from '../shared/config';\n\ndotenv.config({ path: '.env.local' });\ndotenv.config();\n\nexport type { CMSProvider, S3Config };\n\nexport interface ClientConfig {\n}\n\nexport const config: ClientConfig & SharedConfig = {\n ...sharedConfig\n};\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport type { CMSProvider } from './types';\nimport { ContentStore } from './s3';\n\nexport interface BundleInfo {\n [key: string]: string;\n}\n\nexport interface BundleItem {\n [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface FetchBundlesOptions {\n cms: CMSProvider;\n contentTypes: string[];\n}\n\nexport interface QueryOptions {\n /**\n * Filter items by matching property values (exact equality, or array for IN).\n * Keys may use dot notation for nested paths, e.g. `{ 'meta._id': 'abc' }` matches\n * `item.meta._id`.\n *\n * Contentful-style operators on the path (before `[`):\n * - `{ 'field[exists]': true }` — field is present and non-empty (not null, undefined,\n * `''`, `[]`, or `{}`).\n * - `{ 'field[exists]': false }` — field is missing or empty (same emptiness rules).\n * Nested paths work, e.g. `{ 'blocks.hero[exists]': false }`.\n */\n fields?: Record<string, unknown>;\n /**\n * Properties to include in each result object. Omit to return all properties.\n * Keys may use dot notation; nested segments become nested objects in the result,\n * e.g. `['slug', 'meta._updatedAt']` → `{ slug, meta: { _updatedAt } }`.\n */\n select?: string[];\n /** Maximum number of items to return. */\n limit?: number;\n /**\n * How many levels deep to return.\n * - 1 = the item's own scalar properties only; nested objects/refs are nulled.\n * - 2 = the item including its direct references; refs inside those are nulled.\n * - 3 = three levels deep, and so on.\n * - Omit to return the full depth.\n */\n include?: number;\n}\n\n/**\n * Trims nested object depth.\n *\n * `remaining` represents how many levels the current object is allowed.\n * - Scalar properties are always kept.\n * - Nested objects / arrays-of-objects consume one level. When `remaining`\n * drops to 1 they are replaced with `null` (no budget left for refs).\n */\nexport function trimDepth(value: unknown, remaining: number): unknown {\n if (value === null || value === undefined || typeof value !== 'object') {\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => trimDepth(item, remaining));\n }\n\n const obj = value as Record<string, unknown>;\n const result: Record<string, unknown> = {};\n\n for (const [k, v] of Object.entries(obj)) {\n if (v === null || v === undefined || typeof v !== 'object') {\n result[k] = v;\n } else if (remaining <= 1) {\n result[k] = null;\n } else if (Array.isArray(v)) {\n result[k] = v.map((item) => {\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n return trimDepth(item, remaining - 1);\n }\n return item;\n });\n } else {\n result[k] = trimDepth(v, remaining - 1);\n }\n }\n\n return result;\n}\n\n/** Read a value at a dotted path; returns whether every segment existed. */\nfunction getAtPath(\n obj: unknown,\n dottedPath: string,\n): { found: true; value: unknown } | { found: false } {\n const parts = dottedPath.split('.').filter((p) => p.length > 0);\n if (parts.length === 0) return { found: false };\n\n let cur: unknown = obj;\n for (const p of parts) {\n if (cur === null || typeof cur !== 'object' || Array.isArray(cur)) {\n return { found: false };\n }\n const rec = cur as Record<string, unknown>;\n if (!(p in rec)) return { found: false };\n cur = rec[p];\n }\n return { found: true, value: cur };\n}\n\nconst FIELD_OP_KEY = /^(.+)\\[([^\\]]+)\\]$/;\n\nfunction parseFieldKey(key: string): { path: string; operator?: string } {\n const m = FIELD_OP_KEY.exec(key);\n if (!m) return { path: key };\n return { path: m[1]!, operator: m[2]! };\n}\n\n/** True when a bundle value counts as “no content” (aligned with typical CMS “empty”). */\nfunction isEmptyValue(value: unknown): boolean {\n if (value === null || value === undefined) return true;\n if (value === '') return true;\n if (Array.isArray(value) && value.length === 0) return true;\n if (\n typeof value === 'object' &&\n !Array.isArray(value) &&\n Object.keys(value).length === 0\n ) {\n return true;\n }\n return false;\n}\n\nfunction matchesFieldFilter(\n item: BundleItem,\n key: string,\n expected: unknown,\n): boolean {\n const { path, operator } = parseFieldKey(key);\n const at = getAtPath(item, path);\n\n if (operator === 'exists') {\n if (expected !== true && expected !== false) return false;\n const empty = !at.found || isEmptyValue(at.value);\n return expected === false ? empty : !empty;\n }\n\n const actual = at.found ? at.value : undefined;\n if (Array.isArray(expected)) return expected.includes(actual);\n return actual === expected;\n}\n\n/** Set `value` on `target` at a dotted path, creating plain objects as needed. */\nfunction setNestedAt(\n target: Record<string, unknown>,\n dottedPath: string,\n value: unknown,\n): void {\n const parts = dottedPath.split('.').filter((p) => p.length > 0);\n if (parts.length === 0) return;\n\n if (parts.length === 1) {\n target[parts[0]!] = value;\n return;\n }\n\n const head = parts[0]!;\n const rest = parts.slice(1).join('.');\n let nested = target[head];\n if (\n nested === null ||\n typeof nested !== 'object' ||\n Array.isArray(nested)\n ) {\n nested = {};\n target[head] = nested;\n }\n setNestedAt(nested as Record<string, unknown>, rest, value);\n}\n\n/**\n * Downloads the latest bundles from S3 and writes them as JSON files to `outputDir`.\n *\n * @returns A map of contentType to absolute file path.\n */\nexport async function fetchBundles(\n store: ContentStore,\n outputDir: string,\n options: FetchBundlesOptions,\n): Promise<Record<string, string>> {\n const { cms, contentTypes } = options;\n await fs.mkdir(outputDir, { recursive: true });\n\n const result:BundleInfo = {};\n\n await Promise.all(\n contentTypes.map(async (contentType) => {\n const key = store.buildLatestKey(cms, contentType);\n const data = await store.download(key);\n const filePath = path.resolve(\n outputDir,\n `${cms}-${contentType}.json`,\n );\n await fs.writeFile(filePath, JSON.stringify(data, null, 2), 'utf-8');\n result[contentType] = filePath;\n }),\n );\n\n return result;\n}\n\n/**\n * Queries a previously fetched bundle from the local filesystem.\n */\nexport async function queryBundle(\n outputDir: string,\n cms: CMSProvider,\n contentType: string,\n options: QueryOptions = {},\n): Promise<unknown[]> {\n const filePath = path.resolve(\n outputDir,\n `${cms}-${contentType}.json`,\n );\n const raw = await fs.readFile(filePath, 'utf-8');\n let items:BundleItem[] = JSON.parse(raw) as Record<string, unknown>[];\n\n if (options.fields) {\n const filters = options.fields;\n items = items.filter((item) =>\n Object.entries(filters).every(([key, expected]) =>\n matchesFieldFilter(item, key, expected),\n ),\n );\n }\n\n if (options.limit !== undefined && options.limit > 0) {\n items = items.slice(0, options.limit);\n }\n\n if (options.include !== undefined) {\n items = items.map(\n (item) => trimDepth(item, options.include!) as Record<string, unknown>,\n );\n }\n\n if (options.select?.length) {\n const keys = options.select;\n items = items.map((item) => {\n const picked: Record<string, unknown> = {};\n for (const k of keys) {\n const at = getAtPath(item, k);\n if (at.found) setNestedAt(picked, k, at.value);\n }\n return picked;\n });\n }\n\n return items;\n}\n"],"mappings":";;;;;;AAAA,OAAO,YAAY;AAInB,OAAO,OAAO,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,OAAO;AAOP,IAAMA,UAAsC;AAAA,EAC/C,GAAG;AACP;;;ACdA,OAAO,QAAQ;AACf,OAAO,UA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U,UAAa,QAAQ,QAAQ,GAAG;AACpD,YAAQ,MAAM,MAAM,GAAG,QAAQ,KAAK;AAAA,EACtC;AAEA,MAAI,QAAQ,YAAY,QAAW;AACjC,YAAQ,MAAM;AAAA,MACZ,CAAC,SAAS,UAAU,MAAM,QAAQ,OAAQ;AAAA,IAC5C;AAAA,EACF;AAEA,MAAI,QAAQ,QAAQ,QAAQ;AAC1B,UAAM,OAAO,QAAQ;AACrB,YAAQ,MAAM,IAAI,CAAC,SAAS;AAC1B,YAAM,SAAkC,CAAC;AACzC,iBAAW,KAAK,MAAM;AACpB,cAAM,KAAK,UAAU,MAAM,CAAC;AAC5B,YAAI,GAAG,MAAO,aAAY,QAAQ,GAAG,GAAG,KAAK;AAAA,MAC/C;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":["config","path"]}
@@ -3,7 +3,7 @@ import {
3
3
  config,
4
4
  fetchBundles,
5
5
  queryBundle
6
- } from "../chunk-A3NFNDO4.js";
6
+ } from "../chunk-JFI26IB3.js";
7
7
  import {
8
8
  ContentStore
9
9
  } from "../chunk-UWGOF36L.js";
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  config,
4
4
  fetchBundles
5
- } from "../chunk-A3NFNDO4.js";
5
+ } from "../chunk-JFI26IB3.js";
6
6
  import {
7
7
  ContentStore
8
8
  } from "../chunk-UWGOF36L.js";
package/dist/index.d.ts CHANGED
@@ -1,94 +1 @@
1
- type CMSProvider = 'contentful' | 'sanity';
2
- interface S3Config {
3
- bucket: string;
4
- region: string;
5
- accessKeyId: string;
6
- secretAccessKey: string;
7
- }
8
-
9
- declare class ContentStore {
10
- private client;
11
- private bucket;
12
- constructor(cfg: S3Config);
13
- /** {cms}-{contentType}-{timestamp}.json */
14
- buildVersionedKey(cms: string, contentType: string, timestamp: number): string;
15
- /** {cms}-{contentType}.json (always points at the latest version) */
16
- buildLatestKey(cms: string, contentType: string): string;
17
- upload(key: string, data: unknown): Promise<string>;
18
- download(key: string): Promise<unknown>;
19
- /**
20
- * Copies a versioned object to the "latest" key so that it always reflects
21
- * the most recent sync while older timestamped versions are retained.
22
- */
23
- copyToLatest(sourceKey: string, cms: string, contentType: string): Promise<string>;
24
- }
25
-
26
- interface BundleInfo {
27
- [key: string]: string;
28
- }
29
- interface BundleItem {
30
- [key: string]: any;
31
- }
32
- interface FetchBundlesOptions {
33
- cms: CMSProvider;
34
- contentTypes: string[];
35
- }
36
- interface QueryOptions {
37
- /** Filter items by matching top-level property values (exact equality, or array for IN). */
38
- fields?: Record<string, unknown>;
39
- /** Properties to include in each result object. Omit to return all properties. */
40
- select?: string[];
41
- /** Maximum number of items to return. */
42
- limit?: number;
43
- /**
44
- * How many levels deep to return.
45
- * - 1 = the item's own scalar properties only; nested objects/refs are nulled.
46
- * - 2 = the item including its direct references; refs inside those are nulled.
47
- * - 3 = three levels deep, and so on.
48
- * - Omit to return the full depth.
49
- */
50
- include?: number;
51
- }
52
- /**
53
- * Trims nested object depth.
54
- *
55
- * `remaining` represents how many levels the current object is allowed.
56
- * - Scalar properties are always kept.
57
- * - Nested objects / arrays-of-objects consume one level. When `remaining`
58
- * drops to 1 they are replaced with `null` (no budget left for refs).
59
- */
60
- declare function trimDepth(value: unknown, remaining: number): unknown;
61
- /**
62
- * Downloads the latest bundles from S3 and writes them as JSON files to `outputDir`.
63
- *
64
- * @returns A map of contentType to absolute file path.
65
- */
66
- declare function fetchBundles(store: ContentStore, outputDir: string, options: FetchBundlesOptions): Promise<Record<string, string>>;
67
- /**
68
- * Queries a previously fetched bundle from the local filesystem.
69
- */
70
- declare function queryBundle(outputDir: string, cms: CMSProvider, contentType: string, options?: QueryOptions): Promise<unknown[]>;
71
-
72
- interface SDKConfig {
73
- s3: S3Config;
74
- /** Directory where bundle JSON files are saved on the local filesystem. */
75
- outputDir: string;
76
- }
77
- declare class ContentStoreSDK {
78
- private store;
79
- private outputDir;
80
- constructor(config: SDKConfig);
81
- /**
82
- * Downloads the latest bundles from S3 and writes them as JSON files
83
- * to `outputDir`.
84
- *
85
- * @returns A map of contentType to absolute file path.
86
- */
87
- fetchBundles(options: FetchBundlesOptions): Promise<Record<string, string>>;
88
- /**
89
- * Queries a previously fetched bundle from the local filesystem.
90
- */
91
- queryBundle(cms: CMSProvider, contentType: string, options?: QueryOptions): Promise<unknown[]>;
92
- }
93
-
94
- export { type BundleInfo, type BundleItem, type CMSProvider, ContentStore, ContentStoreSDK, type FetchBundlesOptions, type QueryOptions, type S3Config, type SDKConfig, fetchBundles, queryBundle, trimDepth };
1
+ export { B as BundleInfo, a as BundleItem, C as CMSProvider, F as FetchBundlesOptions, Q as QueryOptions, c as S3Config, S as SDKConfig } from './index-DxoMnE4K.js';
package/dist/index.js CHANGED
@@ -1,183 +1 @@
1
- // src/shared/s3.ts
2
- import {
3
- S3Client,
4
- PutObjectCommand,
5
- CopyObjectCommand,
6
- GetObjectCommand
7
- } from "@aws-sdk/client-s3";
8
- var ContentStore = class {
9
- client;
10
- bucket;
11
- constructor(cfg) {
12
- this.client = new S3Client({
13
- region: cfg.region,
14
- credentials: {
15
- accessKeyId: cfg.accessKeyId,
16
- secretAccessKey: cfg.secretAccessKey
17
- }
18
- });
19
- this.bucket = cfg.bucket;
20
- }
21
- /** {cms}-{contentType}-{timestamp}.json */
22
- buildVersionedKey(cms, contentType, timestamp) {
23
- return `${cms}-${contentType}-${timestamp}.json`;
24
- }
25
- /** {cms}-{contentType}.json (always points at the latest version) */
26
- buildLatestKey(cms, contentType) {
27
- return `${cms}-${contentType}.json`;
28
- }
29
- async upload(key, data) {
30
- await this.client.send(
31
- new PutObjectCommand({
32
- Bucket: this.bucket,
33
- Key: key,
34
- Body: JSON.stringify(data, null, 2),
35
- ContentType: "application/json"
36
- })
37
- );
38
- return key;
39
- }
40
- async download(key) {
41
- const response = await this.client.send(
42
- new GetObjectCommand({ Bucket: this.bucket, Key: key })
43
- );
44
- const body = await response.Body?.transformToString();
45
- if (!body) throw new Error(`Empty response for key: ${key}`);
46
- return JSON.parse(body);
47
- }
48
- /**
49
- * Copies a versioned object to the "latest" key so that it always reflects
50
- * the most recent sync while older timestamped versions are retained.
51
- */
52
- async copyToLatest(sourceKey, cms, contentType) {
53
- const latestKey = this.buildLatestKey(cms, contentType);
54
- await this.client.send(
55
- new CopyObjectCommand({
56
- Bucket: this.bucket,
57
- CopySource: `${this.bucket}/${sourceKey}`,
58
- Key: latestKey,
59
- ContentType: "application/json"
60
- })
61
- );
62
- return latestKey;
63
- }
64
- };
65
-
66
- // src/shared/bundles.ts
67
- import fs from "fs/promises";
68
- import path from "path";
69
- function trimDepth(value, remaining) {
70
- if (value === null || value === void 0 || typeof value !== "object") {
71
- return value;
72
- }
73
- if (Array.isArray(value)) {
74
- return value.map((item) => trimDepth(item, remaining));
75
- }
76
- const obj = value;
77
- const result = {};
78
- for (const [k, v] of Object.entries(obj)) {
79
- if (v === null || v === void 0 || typeof v !== "object") {
80
- result[k] = v;
81
- } else if (remaining <= 1) {
82
- result[k] = null;
83
- } else if (Array.isArray(v)) {
84
- result[k] = v.map((item) => {
85
- if (item !== null && typeof item === "object" && !Array.isArray(item)) {
86
- return trimDepth(item, remaining - 1);
87
- }
88
- return item;
89
- });
90
- } else {
91
- result[k] = trimDepth(v, remaining - 1);
92
- }
93
- }
94
- return result;
95
- }
96
- async function fetchBundles(store, outputDir, options) {
97
- const { cms, contentTypes } = options;
98
- await fs.mkdir(outputDir, { recursive: true });
99
- const result = {};
100
- await Promise.all(
101
- contentTypes.map(async (contentType) => {
102
- const key = store.buildLatestKey(cms, contentType);
103
- const data = await store.download(key);
104
- const filePath = path.resolve(
105
- outputDir,
106
- `${cms}-${contentType}.json`
107
- );
108
- await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
109
- result[contentType] = filePath;
110
- })
111
- );
112
- return result;
113
- }
114
- async function queryBundle(outputDir, cms, contentType, options = {}) {
115
- const filePath = path.resolve(
116
- outputDir,
117
- `${cms}-${contentType}.json`
118
- );
119
- const raw = await fs.readFile(filePath, "utf-8");
120
- let items = JSON.parse(raw);
121
- if (options.fields) {
122
- const filters = options.fields;
123
- items = items.filter(
124
- (item) => Object.entries(filters).every(([key, expected]) => {
125
- const actual = item[key];
126
- if (Array.isArray(expected)) return expected.includes(actual);
127
- return actual === expected;
128
- })
129
- );
130
- }
131
- if (options.limit !== void 0 && options.limit > 0) {
132
- items = items.slice(0, options.limit);
133
- }
134
- if (options.include !== void 0) {
135
- items = items.map(
136
- (item) => trimDepth(item, options.include)
137
- );
138
- }
139
- if (options.select?.length) {
140
- const keys = options.select;
141
- items = items.map((item) => {
142
- const picked = {};
143
- for (const k of keys) {
144
- if (k in item) picked[k] = item[k];
145
- }
146
- return picked;
147
- });
148
- }
149
- return items;
150
- }
151
-
152
- // src/sdk/client.ts
153
- var ContentStoreSDK = class {
154
- store;
155
- outputDir;
156
- constructor(config) {
157
- this.store = new ContentStore(config.s3);
158
- this.outputDir = config.outputDir;
159
- }
160
- /**
161
- * Downloads the latest bundles from S3 and writes them as JSON files
162
- * to `outputDir`.
163
- *
164
- * @returns A map of contentType to absolute file path.
165
- */
166
- async fetchBundles(options) {
167
- return fetchBundles(this.store, this.outputDir, options);
168
- }
169
- /**
170
- * Queries a previously fetched bundle from the local filesystem.
171
- */
172
- async queryBundle(cms, contentType, options = {}) {
173
- return queryBundle(this.outputDir, cms, contentType, options);
174
- }
175
- };
176
- export {
177
- ContentStore,
178
- ContentStoreSDK,
179
- fetchBundles,
180
- queryBundle,
181
- trimDepth
182
- };
183
1
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/shared/s3.ts","../src/shared/bundles.ts","../src/sdk/client.ts"],"sourcesContent":["import {\n S3Client,\n PutObjectCommand,\n CopyObjectCommand,\n GetObjectCommand,\n} from '@aws-sdk/client-s3';\nimport type { S3Config } from './types';\n\nexport class ContentStore {\n private client: S3Client;\n private bucket: string;\n\n constructor(cfg: S3Config) {\n this.client = new S3Client({\n region: cfg.region,\n credentials: {\n accessKeyId: cfg.accessKeyId,\n secretAccessKey: cfg.secretAccessKey,\n },\n });\n this.bucket = cfg.bucket;\n }\n\n /** {cms}-{contentType}-{timestamp}.json */\n buildVersionedKey(cms: string, contentType: string, timestamp: number): string {\n return `${cms}-${contentType}-${timestamp}.json`;\n }\n\n /** {cms}-{contentType}.json (always points at the latest version) */\n buildLatestKey(cms: string, contentType: string): string {\n return `${cms}-${contentType}.json`;\n }\n\n async upload(key: string, data: unknown): Promise<string> {\n await this.client.send(\n new PutObjectCommand({\n Bucket: this.bucket,\n Key: key,\n Body: JSON.stringify(data, null, 2),\n ContentType: 'application/json',\n }),\n );\n return key;\n }\n\n async download(key: string): Promise<unknown> {\n const response = await this.client.send(\n new GetObjectCommand({ Bucket: this.bucket, Key: key }),\n );\n const body = await response.Body?.transformToString();\n if (!body) throw new Error(`Empty response for key: ${key}`);\n return JSON.parse(body);\n }\n\n /**\n * Copies a versioned object to the \"latest\" key so that it always reflects\n * the most recent sync while older timestamped versions are retained.\n */\n async copyToLatest(\n sourceKey: string,\n cms: string,\n contentType: string,\n ): Promise<string> {\n const latestKey = this.buildLatestKey(cms, contentType);\n await this.client.send(\n new CopyObjectCommand({\n Bucket: this.bucket,\n CopySource: `${this.bucket}/${sourceKey}`,\n Key: latestKey,\n ContentType: 'application/json',\n }),\n );\n return latestKey;\n }\n}\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport type { CMSProvider } from './types';\nimport { ContentStore } from './s3';\n\nexport interface BundleInfo {\n [key: string]: string;\n}\n\nexport interface BundleItem {\n [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface FetchBundlesOptions {\n cms: CMSProvider;\n contentTypes: string[];\n}\n\nexport interface QueryOptions {\n /** Filter items by matching top-level property values (exact equality, or array for IN). */\n fields?: Record<string, unknown>;\n /** Properties to include in each result object. Omit to return all properties. */\n select?: string[];\n /** Maximum number of items to return. */\n limit?: number;\n /**\n * How many levels deep to return.\n * - 1 = the item's own scalar properties only; nested objects/refs are nulled.\n * - 2 = the item including its direct references; refs inside those are nulled.\n * - 3 = three levels deep, and so on.\n * - Omit to return the full depth.\n */\n include?: number;\n}\n\n/**\n * Trims nested object depth.\n *\n * `remaining` represents how many levels the current object is allowed.\n * - Scalar properties are always kept.\n * - Nested objects / arrays-of-objects consume one level. When `remaining`\n * drops to 1 they are replaced with `null` (no budget left for refs).\n */\nexport function trimDepth(value: unknown, remaining: number): unknown {\n if (value === null || value === undefined || typeof value !== 'object') {\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => trimDepth(item, remaining));\n }\n\n const obj = value as Record<string, unknown>;\n const result: Record<string, unknown> = {};\n\n for (const [k, v] of Object.entries(obj)) {\n if (v === null || v === undefined || typeof v !== 'object') {\n result[k] = v;\n } else if (remaining <= 1) {\n result[k] = null;\n } else if (Array.isArray(v)) {\n result[k] = v.map((item) => {\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n return trimDepth(item, remaining - 1);\n }\n return item;\n });\n } else {\n result[k] = trimDepth(v, remaining - 1);\n }\n }\n\n return result;\n}\n\n/**\n * Downloads the latest bundles from S3 and writes them as JSON files to `outputDir`.\n *\n * @returns A map of contentType to absolute file path.\n */\nexport async function fetchBundles(\n store: ContentStore,\n outputDir: string,\n options: FetchBundlesOptions,\n): Promise<Record<string, string>> {\n const { cms, contentTypes } = options;\n await fs.mkdir(outputDir, { recursive: true });\n\n const result:BundleInfo = {};\n\n await Promise.all(\n contentTypes.map(async (contentType) => {\n const key = store.buildLatestKey(cms, contentType);\n const data = await store.download(key);\n const filePath = path.resolve(\n outputDir,\n `${cms}-${contentType}.json`,\n );\n await fs.writeFile(filePath, JSON.stringify(data, null, 2), 'utf-8');\n result[contentType] = filePath;\n }),\n );\n\n return result;\n}\n\n/**\n * Queries a previously fetched bundle from the local filesystem.\n */\nexport async function queryBundle(\n outputDir: string,\n cms: CMSProvider,\n contentType: string,\n options: QueryOptions = {},\n): Promise<unknown[]> {\n const filePath = path.resolve(\n outputDir,\n `${cms}-${contentType}.json`,\n );\n const raw = await fs.readFile(filePath, 'utf-8');\n let items:BundleItem[] = JSON.parse(raw) as Record<string, unknown>[];\n\n if (options.fields) {\n const filters = options.fields;\n items = items.filter((item) =>\n Object.entries(filters).every(([key, expected]) => {\n const actual = item[key];\n if (Array.isArray(expected)) return expected.includes(actual);\n return actual === expected;\n }),\n );\n }\n\n if (options.limit !== undefined && options.limit > 0) {\n items = items.slice(0, options.limit);\n }\n\n if (options.include !== undefined) {\n items = items.map(\n (item) => trimDepth(item, options.include!) as Record<string, unknown>,\n );\n }\n\n if (options.select?.length) {\n const keys = options.select;\n items = items.map((item) => {\n const picked: Record<string, unknown> = {};\n for (const k of keys) {\n if (k in item) picked[k] = item[k];\n }\n return picked;\n });\n }\n\n return items;\n}\n","import type { S3Config, CMSProvider } from '../shared/types';\nimport { ContentStore } from '../shared/s3';\nimport {\n fetchBundles,\n queryBundle,\n type FetchBundlesOptions,\n type QueryOptions,\n type BundleInfo,\n type BundleItem\n} from '../shared/bundles';\n\nexport type { FetchBundlesOptions, QueryOptions, BundleInfo, BundleItem };\n\nexport interface SDKConfig {\n s3: S3Config;\n /** Directory where bundle JSON files are saved on the local filesystem. */\n outputDir: string;\n}\n\nexport class ContentStoreSDK {\n private store: ContentStore;\n private outputDir: string;\n\n constructor(config: SDKConfig) {\n this.store = new ContentStore(config.s3);\n this.outputDir = config.outputDir;\n }\n\n /**\n * Downloads the latest bundles from S3 and writes them as JSON files\n * to `outputDir`.\n *\n * @returns A map of contentType to absolute file path.\n */\n async fetchBundles(\n options: FetchBundlesOptions,\n ): Promise<Record<string, string>> {\n return fetchBundles(this.store, this.outputDir, options);\n }\n\n /**\n * Queries a previously fetched bundle from the local filesystem.\n */\n async queryBundle(\n cms: CMSProvider,\n contentType: string,\n options: QueryOptions = {},\n ): Promise<unknown[]> {\n return queryBundle(this.outputDir, cms, contentType, options);\n }\n}\n"],"mappings":";AAAA;AAAA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AAC;AAAA,MACnC;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO;AACT;;;ACxIO,IAAM,kBAAN,MAAsB;AAAA,EACnB;AAAA,EACA;AAAA,EAER,YAAY,QAAmB;AAC7B,SAAK,QAAQ,IAAI,aAAa,OAAO,EAAE;AACvC,SAAK,YAAY,OAAO;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,aACJ,SACiC;AACjC,WAAO,aAAa,KAAK,OAAO,KAAK,WAAW,OAAO;AAAA,EACzD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,YACJ,KACA,aACA,UAAwB,CAAC,GACL;AACpB,WAAO,YAAY,KAAK,WAAW,KAAK,aAAa,OAAO;AAAA,EAC9D;AACF;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/node.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { S as SDKConfig, F as FetchBundlesOptions, C as CMSProvider, Q as QueryOptions } from './index-DxoMnE4K.js';
2
+ export { B as BundleInfo, a as BundleItem, b as ContentStore, c as S3Config, f as fetchBundles, q as queryBundle, t as trimDepth } from './index-DxoMnE4K.js';
3
+
4
+ declare class ContentStoreSDK {
5
+ private store;
6
+ private outputDir;
7
+ constructor(config: SDKConfig);
8
+ /**
9
+ * Downloads the latest bundles from S3 and writes them as JSON files
10
+ * to `outputDir`.
11
+ *
12
+ * @returns A map of contentType to absolute file path.
13
+ */
14
+ fetchBundles(options: FetchBundlesOptions): Promise<Record<string, string>>;
15
+ /**
16
+ * Queries a previously fetched bundle from the local filesystem.
17
+ */
18
+ queryBundle(cms: CMSProvider, contentType: string, options?: QueryOptions): Promise<unknown[]>;
19
+ }
20
+
21
+ export { CMSProvider, ContentStoreSDK, FetchBundlesOptions, QueryOptions, SDKConfig };
package/dist/node.js ADDED
@@ -0,0 +1,239 @@
1
+ // src/shared/s3.ts
2
+ import {
3
+ S3Client,
4
+ PutObjectCommand,
5
+ CopyObjectCommand,
6
+ GetObjectCommand
7
+ } from "@aws-sdk/client-s3";
8
+ var ContentStore = class {
9
+ client;
10
+ bucket;
11
+ constructor(cfg) {
12
+ this.client = new S3Client({
13
+ region: cfg.region,
14
+ credentials: {
15
+ accessKeyId: cfg.accessKeyId,
16
+ secretAccessKey: cfg.secretAccessKey
17
+ }
18
+ });
19
+ this.bucket = cfg.bucket;
20
+ }
21
+ /** {cms}-{contentType}-{timestamp}.json */
22
+ buildVersionedKey(cms, contentType, timestamp) {
23
+ return `${cms}-${contentType}-${timestamp}.json`;
24
+ }
25
+ /** {cms}-{contentType}.json (always points at the latest version) */
26
+ buildLatestKey(cms, contentType) {
27
+ return `${cms}-${contentType}.json`;
28
+ }
29
+ async upload(key, data) {
30
+ await this.client.send(
31
+ new PutObjectCommand({
32
+ Bucket: this.bucket,
33
+ Key: key,
34
+ Body: JSON.stringify(data, null, 2),
35
+ ContentType: "application/json"
36
+ })
37
+ );
38
+ return key;
39
+ }
40
+ async download(key) {
41
+ const response = await this.client.send(
42
+ new GetObjectCommand({ Bucket: this.bucket, Key: key })
43
+ );
44
+ const body = await response.Body?.transformToString();
45
+ if (!body) throw new Error(`Empty response for key: ${key}`);
46
+ return JSON.parse(body);
47
+ }
48
+ /**
49
+ * Copies a versioned object to the "latest" key so that it always reflects
50
+ * the most recent sync while older timestamped versions are retained.
51
+ */
52
+ async copyToLatest(sourceKey, cms, contentType) {
53
+ const latestKey = this.buildLatestKey(cms, contentType);
54
+ await this.client.send(
55
+ new CopyObjectCommand({
56
+ Bucket: this.bucket,
57
+ CopySource: `${this.bucket}/${sourceKey}`,
58
+ Key: latestKey,
59
+ ContentType: "application/json"
60
+ })
61
+ );
62
+ return latestKey;
63
+ }
64
+ };
65
+
66
+ // src/shared/bundles.ts
67
+ import fs from "fs/promises";
68
+ import path from "path";
69
+ function trimDepth(value, remaining) {
70
+ if (value === null || value === void 0 || typeof value !== "object") {
71
+ return value;
72
+ }
73
+ if (Array.isArray(value)) {
74
+ return value.map((item) => trimDepth(item, remaining));
75
+ }
76
+ const obj = value;
77
+ const result = {};
78
+ for (const [k, v] of Object.entries(obj)) {
79
+ if (v === null || v === void 0 || typeof v !== "object") {
80
+ result[k] = v;
81
+ } else if (remaining <= 1) {
82
+ result[k] = null;
83
+ } else if (Array.isArray(v)) {
84
+ result[k] = v.map((item) => {
85
+ if (item !== null && typeof item === "object" && !Array.isArray(item)) {
86
+ return trimDepth(item, remaining - 1);
87
+ }
88
+ return item;
89
+ });
90
+ } else {
91
+ result[k] = trimDepth(v, remaining - 1);
92
+ }
93
+ }
94
+ return result;
95
+ }
96
+ function getAtPath(obj, dottedPath) {
97
+ const parts = dottedPath.split(".").filter((p) => p.length > 0);
98
+ if (parts.length === 0) return { found: false };
99
+ let cur = obj;
100
+ for (const p of parts) {
101
+ if (cur === null || typeof cur !== "object" || Array.isArray(cur)) {
102
+ return { found: false };
103
+ }
104
+ const rec = cur;
105
+ if (!(p in rec)) return { found: false };
106
+ cur = rec[p];
107
+ }
108
+ return { found: true, value: cur };
109
+ }
110
+ var FIELD_OP_KEY = /^(.+)\[([^\]]+)\]$/;
111
+ function parseFieldKey(key) {
112
+ const m = FIELD_OP_KEY.exec(key);
113
+ if (!m) return { path: key };
114
+ return { path: m[1], operator: m[2] };
115
+ }
116
+ function isEmptyValue(value) {
117
+ if (value === null || value === void 0) return true;
118
+ if (value === "") return true;
119
+ if (Array.isArray(value) && value.length === 0) return true;
120
+ if (typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0) {
121
+ return true;
122
+ }
123
+ return false;
124
+ }
125
+ function matchesFieldFilter(item, key, expected) {
126
+ const { path: path2, operator } = parseFieldKey(key);
127
+ const at = getAtPath(item, path2);
128
+ if (operator === "exists") {
129
+ if (expected !== true && expected !== false) return false;
130
+ const empty = !at.found || isEmptyValue(at.value);
131
+ return expected === false ? empty : !empty;
132
+ }
133
+ const actual = at.found ? at.value : void 0;
134
+ if (Array.isArray(expected)) return expected.includes(actual);
135
+ return actual === expected;
136
+ }
137
+ function setNestedAt(target, dottedPath, value) {
138
+ const parts = dottedPath.split(".").filter((p) => p.length > 0);
139
+ if (parts.length === 0) return;
140
+ if (parts.length === 1) {
141
+ target[parts[0]] = value;
142
+ return;
143
+ }
144
+ const head = parts[0];
145
+ const rest = parts.slice(1).join(".");
146
+ let nested = target[head];
147
+ if (nested === null || typeof nested !== "object" || Array.isArray(nested)) {
148
+ nested = {};
149
+ target[head] = nested;
150
+ }
151
+ setNestedAt(nested, rest, value);
152
+ }
153
+ async function fetchBundles(store, outputDir, options) {
154
+ const { cms, contentTypes } = options;
155
+ await fs.mkdir(outputDir, { recursive: true });
156
+ const result = {};
157
+ await Promise.all(
158
+ contentTypes.map(async (contentType) => {
159
+ const key = store.buildLatestKey(cms, contentType);
160
+ const data = await store.download(key);
161
+ const filePath = path.resolve(
162
+ outputDir,
163
+ `${cms}-${contentType}.json`
164
+ );
165
+ await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
166
+ result[contentType] = filePath;
167
+ })
168
+ );
169
+ return result;
170
+ }
171
+ async function queryBundle(outputDir, cms, contentType, options = {}) {
172
+ const filePath = path.resolve(
173
+ outputDir,
174
+ `${cms}-${contentType}.json`
175
+ );
176
+ const raw = await fs.readFile(filePath, "utf-8");
177
+ let items = JSON.parse(raw);
178
+ if (options.fields) {
179
+ const filters = options.fields;
180
+ items = items.filter(
181
+ (item) => Object.entries(filters).every(
182
+ ([key, expected]) => matchesFieldFilter(item, key, expected)
183
+ )
184
+ );
185
+ }
186
+ if (options.limit !== void 0 && options.limit > 0) {
187
+ items = items.slice(0, options.limit);
188
+ }
189
+ if (options.include !== void 0) {
190
+ items = items.map(
191
+ (item) => trimDepth(item, options.include)
192
+ );
193
+ }
194
+ if (options.select?.length) {
195
+ const keys = options.select;
196
+ items = items.map((item) => {
197
+ const picked = {};
198
+ for (const k of keys) {
199
+ const at = getAtPath(item, k);
200
+ if (at.found) setNestedAt(picked, k, at.value);
201
+ }
202
+ return picked;
203
+ });
204
+ }
205
+ return items;
206
+ }
207
+
208
+ // src/sdk/client.ts
209
+ var ContentStoreSDK = class {
210
+ store;
211
+ outputDir;
212
+ constructor(config) {
213
+ this.store = new ContentStore(config.s3);
214
+ this.outputDir = config.outputDir;
215
+ }
216
+ /**
217
+ * Downloads the latest bundles from S3 and writes them as JSON files
218
+ * to `outputDir`.
219
+ *
220
+ * @returns A map of contentType to absolute file path.
221
+ */
222
+ async fetchBundles(options) {
223
+ return fetchBundles(this.store, this.outputDir, options);
224
+ }
225
+ /**
226
+ * Queries a previously fetched bundle from the local filesystem.
227
+ */
228
+ async queryBundle(cms, contentType, options = {}) {
229
+ return queryBundle(this.outputDir, cms, contentType, options);
230
+ }
231
+ };
232
+ export {
233
+ ContentStore,
234
+ ContentStoreSDK,
235
+ fetchBundles,
236
+ queryBundle,
237
+ trimDepth
238
+ };
239
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/s3.ts","../src/shared/bundles.ts","../src/sdk/client.ts"],"sourcesContent":["import {\n S3Client,\n PutObjectCommand,\n CopyObjectCommand,\n GetObjectCommand,\n} from '@aws-sdk/client-s3';\nimport type { S3Config } from './types';\n\nexport class ContentStore {\n private client: S3Client;\n private bucket: string;\n\n constructor(cfg: S3Config) {\n this.client = new S3Client({\n region: cfg.region,\n credentials: {\n accessKeyId: cfg.accessKeyId,\n secretAccessKey: cfg.secretAccessKey,\n },\n });\n this.bucket = cfg.bucket;\n }\n\n /** {cms}-{contentType}-{timestamp}.json */\n buildVersionedKey(cms: string, contentType: string, timestamp: number): string {\n return `${cms}-${contentType}-${timestamp}.json`;\n }\n\n /** {cms}-{contentType}.json (always points at the latest version) */\n buildLatestKey(cms: string, contentType: string): string {\n return `${cms}-${contentType}.json`;\n }\n\n async upload(key: string, data: unknown): Promise<string> {\n await this.client.send(\n new PutObjectCommand({\n Bucket: this.bucket,\n Key: key,\n Body: JSON.stringify(data, null, 2),\n ContentType: 'application/json',\n }),\n );\n return key;\n }\n\n async download(key: string): Promise<unknown> {\n const response = await this.client.send(\n new GetObjectCommand({ Bucket: this.bucket, Key: key }),\n );\n const body = await response.Body?.transformToString();\n if (!body) throw new Error(`Empty response for key: ${key}`);\n return JSON.parse(body);\n }\n\n /**\n * Copies a versioned object to the \"latest\" key so that it always reflects\n * the most recent sync while older timestamped versions are retained.\n */\n async copyToLatest(\n sourceKey: string,\n cms: string,\n contentType: string,\n ): Promise<string> {\n const latestKey = this.buildLatestKey(cms, contentType);\n await this.client.send(\n new CopyObjectCommand({\n Bucket: this.bucket,\n CopySource: `${this.bucket}/${sourceKey}`,\n Key: latestKey,\n ContentType: 'application/json',\n }),\n );\n return latestKey;\n }\n}\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport type { CMSProvider } from './types';\nimport { ContentStore } from './s3';\n\nexport interface BundleInfo {\n [key: string]: string;\n}\n\nexport interface BundleItem {\n [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface FetchBundlesOptions {\n cms: CMSProvider;\n contentTypes: string[];\n}\n\nexport interface QueryOptions {\n /**\n * Filter items by matching property values (exact equality, or array for IN).\n * Keys may use dot notation for nested paths, e.g. `{ 'meta._id': 'abc' }` matches\n * `item.meta._id`.\n *\n * Contentful-style operators on the path (before `[`):\n * - `{ 'field[exists]': true }` — field is present and non-empty (not null, undefined,\n * `''`, `[]`, or `{}`).\n * - `{ 'field[exists]': false }` — field is missing or empty (same emptiness rules).\n * Nested paths work, e.g. `{ 'blocks.hero[exists]': false }`.\n */\n fields?: Record<string, unknown>;\n /**\n * Properties to include in each result object. Omit to return all properties.\n * Keys may use dot notation; nested segments become nested objects in the result,\n * e.g. `['slug', 'meta._updatedAt']` → `{ slug, meta: { _updatedAt } }`.\n */\n select?: string[];\n /** Maximum number of items to return. */\n limit?: number;\n /**\n * How many levels deep to return.\n * - 1 = the item's own scalar properties only; nested objects/refs are nulled.\n * - 2 = the item including its direct references; refs inside those are nulled.\n * - 3 = three levels deep, and so on.\n * - Omit to return the full depth.\n */\n include?: number;\n}\n\n/**\n * Trims nested object depth.\n *\n * `remaining` represents how many levels the current object is allowed.\n * - Scalar properties are always kept.\n * - Nested objects / arrays-of-objects consume one level. When `remaining`\n * drops to 1 they are replaced with `null` (no budget left for refs).\n */\nexport function trimDepth(value: unknown, remaining: number): unknown {\n if (value === null || value === undefined || typeof value !== 'object') {\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => trimDepth(item, remaining));\n }\n\n const obj = value as Record<string, unknown>;\n const result: Record<string, unknown> = {};\n\n for (const [k, v] of Object.entries(obj)) {\n if (v === null || v === undefined || typeof v !== 'object') {\n result[k] = v;\n } else if (remaining <= 1) {\n result[k] = null;\n } else if (Array.isArray(v)) {\n result[k] = v.map((item) => {\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n return trimDepth(item, remaining - 1);\n }\n return item;\n });\n } else {\n result[k] = trimDepth(v, remaining - 1);\n }\n }\n\n return result;\n}\n\n/** Read a value at a dotted path; returns whether every segment existed. */\nfunction getAtPath(\n obj: unknown,\n dottedPath: string,\n): { found: true; value: unknown } | { found: false } {\n const parts = dottedPath.split('.').filter((p) => p.length > 0);\n if (parts.length === 0) return { found: false };\n\n let cur: unknown = obj;\n for (const p of parts) {\n if (cur === null || typeof cur !== 'object' || Array.isArray(cur)) {\n return { found: false };\n }\n const rec = cur as Record<string, unknown>;\n if (!(p in rec)) return { found: false };\n cur = rec[p];\n }\n return { found: true, value: cur };\n}\n\nconst FIELD_OP_KEY = /^(.+)\\[([^\\]]+)\\]$/;\n\nfunction parseFieldKey(key: string): { path: string; operator?: string } {\n const m = FIELD_OP_KEY.exec(key);\n if (!m) return { path: key };\n return { path: m[1]!, operator: m[2]! };\n}\n\n/** True when a bundle value counts as “no content” (aligned with typical CMS “empty”). */\nfunction isEmptyValue(value: unknown): boolean {\n if (value === null || value === undefined) return true;\n if (value === '') return true;\n if (Array.isArray(value) && value.length === 0) return true;\n if (\n typeof value === 'object' &&\n !Array.isArray(value) &&\n Object.keys(value).length === 0\n ) {\n return true;\n }\n return false;\n}\n\nfunction matchesFieldFilter(\n item: BundleItem,\n key: string,\n expected: unknown,\n): boolean {\n const { path, operator } = parseFieldKey(key);\n const at = getAtPath(item, path);\n\n if (operator === 'exists') {\n if (expected !== true && expected !== false) return false;\n const empty = !at.found || isEmptyValue(at.value);\n return expected === false ? empty : !empty;\n }\n\n const actual = at.found ? at.value : undefined;\n if (Array.isArray(expected)) return expected.includes(actual);\n return actual === expected;\n}\n\n/** Set `value` on `target` at a dotted path, creating plain objects as needed. */\nfunction setNestedAt(\n target: Record<string, unknown>,\n dottedPath: string,\n value: unknown,\n): void {\n const parts = dottedPath.split('.').filter((p) => p.length > 0);\n if (parts.length === 0) return;\n\n if (parts.length === 1) {\n target[parts[0]!] = value;\n return;\n }\n\n const head = parts[0]!;\n const rest = parts.slice(1).join('.');\n let nested = target[head];\n if (\n nested === null ||\n typeof nested !== 'object' ||\n Array.isArray(nested)\n ) {\n nested = {};\n target[head] = nested;\n }\n setNestedAt(nested as Record<string, unknown>, rest, value);\n}\n\n/**\n * Downloads the latest bundles from S3 and writes them as JSON files to `outputDir`.\n *\n * @returns A map of contentType to absolute file path.\n */\nexport async function fetchBundles(\n store: ContentStore,\n outputDir: string,\n options: FetchBundlesOptions,\n): Promise<Record<string, string>> {\n const { cms, contentTypes } = options;\n await fs.mkdir(outputDir, { recursive: true });\n\n const result:BundleInfo = {};\n\n await Promise.all(\n contentTypes.map(async (contentType) => {\n const key = store.buildLatestKey(cms, contentType);\n const data = await store.download(key);\n const filePath = path.resolve(\n outputDir,\n `${cms}-${contentType}.json`,\n );\n await fs.writeFile(filePath, JSON.stringify(data, null, 2), 'utf-8');\n result[contentType] = filePath;\n }),\n );\n\n return result;\n}\n\n/**\n * Queries a previously fetched bundle from the local filesystem.\n */\nexport async function queryBundle(\n outputDir: string,\n cms: CMSProvider,\n contentType: string,\n options: QueryOptions = {},\n): Promise<unknown[]> {\n const filePath = path.resolve(\n outputDir,\n `${cms}-${contentType}.json`,\n );\n const raw = await fs.readFile(filePath, 'utf-8');\n let items:BundleItem[] = JSON.parse(raw) as Record<string, unknown>[];\n\n if (options.fields) {\n const filters = options.fields;\n items = items.filter((item) =>\n Object.entries(filters).every(([key, expected]) =>\n matchesFieldFilter(item, key, expected),\n ),\n );\n }\n\n if (options.limit !== undefined && options.limit > 0) {\n items = items.slice(0, options.limit);\n }\n\n if (options.include !== undefined) {\n items = items.map(\n (item) => trimDepth(item, options.include!) as Record<string, unknown>,\n );\n }\n\n if (options.select?.length) {\n const keys = options.select;\n items = items.map((item) => {\n const picked: Record<string, unknown> = {};\n for (const k of keys) {\n const at = getAtPath(item, k);\n if (at.found) setNestedAt(picked, k, at.value);\n }\n return picked;\n });\n }\n\n return items;\n}\n","import type { CMSProvider } from '../shared/types';\nimport { ContentStore } from '../shared/s3';\nimport {\n fetchBundles,\n queryBundle,\n type FetchBundlesOptions,\n type QueryOptions,\n} from '../shared/bundles';\nimport type { SDKConfig } from './client-types';\n\nexport type {\n FetchBundlesOptions,\n QueryOptions,\n BundleInfo,\n BundleItem,\n SDKConfig,\n} from './client-types';\n\nexport class ContentStoreSDK {\n private store: ContentStore;\n private outputDir: string;\n\n constructor(config: SDKConfig) {\n this.store = new ContentStore(config.s3);\n this.outputDir = config.outputDir;\n }\n\n /**\n * Downloads the latest bundles from S3 and writes them as JSON files\n * to `outputDir`.\n *\n * @returns A map of contentType to absolute file path.\n */\n async fetchBundles(\n options: FetchBundlesOptions,\n ): Promise<Record<string, string>> {\n return fetchBundles(this.store, this.outputDir, options);\n }\n\n /**\n * Queries a previously fetched bundle from the local filesystem.\n */\n async queryBundle(\n cms: CMSProvider,\n contentType: string,\n options: QueryOptions = {},\n ): Promise<unknown[]> {\n return queryBundle(this.outputDir, cms, contentType, options);\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,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,EAAE;AAAA,QAAM,CAAC,CAAC,KAAK,QAAQ,MAC3C,mBAAmB,MAAM,KAAK,QAAQ;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AAEA,MAAI,QAAQ,UAAU,UAAa,QAAQ,QAAQ,GAAG;AACpD,YAAQ,MAAM,MAAM,GAAG,QAAQ,KAAK;AAAA,EACtC;AAEA,MAAI,QAAQ,YAAY,QAAW;AACjC,YAAQ,MAAM;AAAA,MACZ,CAAC,SAAS,UAAU,MAAM,QAAQ,OAAQ;AAAA,IAC5C;AAAA,EACF;AAEA,MAAI,QAAQ,QAAQ,QAAQ;AAC1B,UAAM,OAAO,QAAQ;AACrB,YAAQ,MAAM,IAAI,CAAC,SAAS;AAC1B,YAAM,SAAkC,CAAC;AACzC,iBAAW,KAAK,MAAM;AACpB,cAAM,KAAK,UAAU,MAAM,CAAC;AAC5B,YAAI,GAAG,MAAO,aAAY,QAAQ,GAAG,GAAG,KAAK;AAAA,MAC/C;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO;AACT;;;AChPO,IAAM,kBAAN,MAAsB;AAAA,EACnB;AAAA,EACA;AAAA,EAER,YAAY,QAAmB;AAC7B,SAAK,QAAQ,IAAI,aAAa,OAAO,EAAE;AACvC,SAAK,YAAY,OAAO;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,aACJ,SACiC;AACjC,WAAO,aAAa,KAAK,OAAO,KAAK,WAAW,OAAO;AAAA,EACzD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,YACJ,KACA,aACA,UAAwB,CAAC,GACL;AACpB,WAAO,YAAY,KAAK,WAAW,KAAK,aAAa,OAAO;AAAA,EAC9D;AACF;","names":["path"]}
package/package.json CHANGED
@@ -1,17 +1,24 @@
1
1
  {
2
2
  "name": "@tandem-language-exchange/content-store",
3
- "version": "1.0.21",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
+ "types": "./dist/index.d.ts",
9
10
  "import": "./dist/index.js",
10
- "types": "./dist/index.d.ts"
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./node": {
14
+ "types": "./dist/node.d.ts",
15
+ "import": "./dist/node.js",
16
+ "default": "./dist/node.js"
11
17
  }
12
18
  },
13
19
  "files": [
14
20
  "dist/index.*",
21
+ "dist/node.*",
15
22
  "dist/sdk/",
16
23
  "dist/client/",
17
24
  "dist/shared/",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/client/config.ts","../src/shared/bundles.ts"],"sourcesContent":["import dotenv from 'dotenv';\nimport type { S3Config, CMSProvider } from '../shared/types';\nimport {SharedConfig, config as sharedConfig} from '../shared/config';\n\ndotenv.config({ path: '.env.local' });\ndotenv.config();\n\nexport type { CMSProvider, S3Config };\n\nexport interface ClientConfig {\n}\n\nexport const config: ClientConfig & SharedConfig = {\n ...sharedConfig\n};\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport type { CMSProvider } from './types';\nimport { ContentStore } from './s3';\n\nexport interface BundleInfo {\n [key: string]: string;\n}\n\nexport interface BundleItem {\n [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\nexport interface FetchBundlesOptions {\n cms: CMSProvider;\n contentTypes: string[];\n}\n\nexport interface QueryOptions {\n /** Filter items by matching top-level property values (exact equality, or array for IN). */\n fields?: Record<string, unknown>;\n /** Properties to include in each result object. Omit to return all properties. */\n select?: string[];\n /** Maximum number of items to return. */\n limit?: number;\n /**\n * How many levels deep to return.\n * - 1 = the item's own scalar properties only; nested objects/refs are nulled.\n * - 2 = the item including its direct references; refs inside those are nulled.\n * - 3 = three levels deep, and so on.\n * - Omit to return the full depth.\n */\n include?: number;\n}\n\n/**\n * Trims nested object depth.\n *\n * `remaining` represents how many levels the current object is allowed.\n * - Scalar properties are always kept.\n * - Nested objects / arrays-of-objects consume one level. When `remaining`\n * drops to 1 they are replaced with `null` (no budget left for refs).\n */\nexport function trimDepth(value: unknown, remaining: number): unknown {\n if (value === null || value === undefined || typeof value !== 'object') {\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => trimDepth(item, remaining));\n }\n\n const obj = value as Record<string, unknown>;\n const result: Record<string, unknown> = {};\n\n for (const [k, v] of Object.entries(obj)) {\n if (v === null || v === undefined || typeof v !== 'object') {\n result[k] = v;\n } else if (remaining <= 1) {\n result[k] = null;\n } else if (Array.isArray(v)) {\n result[k] = v.map((item) => {\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n return trimDepth(item, remaining - 1);\n }\n return item;\n });\n } else {\n result[k] = trimDepth(v, remaining - 1);\n }\n }\n\n return result;\n}\n\n/**\n * Downloads the latest bundles from S3 and writes them as JSON files to `outputDir`.\n *\n * @returns A map of contentType to absolute file path.\n */\nexport async function fetchBundles(\n store: ContentStore,\n outputDir: string,\n options: FetchBundlesOptions,\n): Promise<Record<string, string>> {\n const { cms, contentTypes } = options;\n await fs.mkdir(outputDir, { recursive: true });\n\n const result:BundleInfo = {};\n\n await Promise.all(\n contentTypes.map(async (contentType) => {\n const key = store.buildLatestKey(cms, contentType);\n const data = await store.download(key);\n const filePath = path.resolve(\n outputDir,\n `${cms}-${contentType}.json`,\n );\n await fs.writeFile(filePath, JSON.stringify(data, null, 2), 'utf-8');\n result[contentType] = filePath;\n }),\n );\n\n return result;\n}\n\n/**\n * Queries a previously fetched bundle from the local filesystem.\n */\nexport async function queryBundle(\n outputDir: string,\n cms: CMSProvider,\n contentType: string,\n options: QueryOptions = {},\n): Promise<unknown[]> {\n const filePath = path.resolve(\n outputDir,\n `${cms}-${contentType}.json`,\n );\n const raw = await fs.readFile(filePath, 'utf-8');\n let items:BundleItem[] = JSON.parse(raw) as Record<string, unknown>[];\n\n if (options.fields) {\n const filters = options.fields;\n items = items.filter((item) =>\n Object.entries(filters).every(([key, expected]) => {\n const actual = item[key];\n if (Array.isArray(expected)) return expected.includes(actual);\n return actual === expected;\n }),\n );\n }\n\n if (options.limit !== undefined && options.limit > 0) {\n items = items.slice(0, options.limit);\n }\n\n if (options.include !== undefined) {\n items = items.map(\n (item) => trimDepth(item, options.include!) as Record<string, unknown>,\n );\n }\n\n if (options.select?.length) {\n const keys = options.select;\n items = items.map((item) => {\n const picked: Record<string, unknown> = {};\n for (const k of keys) {\n if (k in item) picked[k] = item[k];\n }\n return picked;\n });\n }\n\n return items;\n}\n"],"mappings":";;;;;;AAAA,OAAO,YAAY;AAInB,OAAO,OAAO,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,OAAO;AAOP,IAAMA,UAAsC;AAAA,EAC/C,GAAG;AACP;;;ACdA,OAAO,QAAQ;AACf,OAAO,UAAU;AA0CV,SAAS,UAAU,OAAgB,WAA4B;AACpE,MAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU,UAAU;AACtE,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM,IAAI,CAAC,SAAS,UAAU,MAAM,SAAS,CAAC;AAAA,EACvD;AAEA,QAAM,MAAM;AACZ,QAAM,SAAkC,CAAC;AAEzC,aAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,GAAG,GAAG;AACxC,QAAI,MAAM,QAAQ,MAAM,UAAa,OAAO,MAAM,UAAU;AAC1D,aAAO,CAAC,IAAI;AAAA,IACd,WAAW,aAAa,GAAG;AACzB,aAAO,CAAC,IAAI;AAAA,IACd,WAAW,MAAM,QAAQ,CAAC,GAAG;AAC3B,aAAO,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS;AAC1B,YAAI,SAAS,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,IAAI,GAAG;AACrE,iBAAO,UAAU,MAAM,YAAY,CAAC;AAAA,QACtC;AACA,eAAO;AAAA,MACT,CAAC;AAAA,IACH,OAAO;AACL,aAAO,CAAC,IAAI,UAAU,GAAG,YAAY,CAAC;AAAA,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AQ,MAAM;AAAA,MACZ,CAAC,SAAS,UAAU,MAAM,QAAQ,OAAQ;AAAA,IAC5C;AAAA,EACF;AAEA,MAAI,QAAQ,QAAQ,QAAQ;AAC1B,UAAM,OAAO,QAAQ;AACrB,YAAQ,MAAM,IAAI,CAAC,SAAS;AAC1B,YAAM,SAAkC,CAAC;AACzC,iBAAW,KAAK,MAAM;AACpB,YAAI,KAAK,KAAM,QAAO,CAAC,IAAI,KAAK,CAAC;AAAA,MACnC;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":["config"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/server/config.ts","../src/server/adapters/contentful.ts","../src/server/sync/retry.ts","../src/server/adapters/sanity.ts","../src/server/adapters/index.ts","../src/server/sync/engine.ts"],"sourcesContent":["import dotenv from 'dotenv';\nimport type { S3Config, CMSProvider } from '../shared/types';\nimport {SharedConfig, config as sharedConfig} from '../shared/config';\n\ndotenv.config({ path: '.env.local' });\ndotenv.config();\n\nexport type { CMSProvider, S3Config };\n\nexport interface ContentfulConfig {\n spaceId: string;\n accessToken: string;\n host: string;\n batchSize: number;\n /** Content types to sync. When empty, all content types in the space are synced. */\n contentTypes: string[];\n /** Max nesting depth when unwrapping resolved entries. Deeper references are dropped. */\n maxDepth: number;\n}\n\nexport interface SanityConfig {\n projectId: string;\n dataset: string;\n token: string;\n apiVersion: string;\n}\n\nexport interface RetryConfig {\n maxRetries: number;\n baseDelayMs: number;\n maxDelayMs: number;\n}\n\nexport interface RestApiConfig {\n port: number;\n apiToken: string;\n}\n\nexport interface ServerConfig {\n contentful: ContentfulConfig;\n sanity: SanityConfig;\n retry: RetryConfig;\n api: RestApiConfig;\n}\n\nexport const config: ServerConfig & SharedConfig = {\n ...sharedConfig,\n contentful: {\n spaceId: process.env.CONTENTFUL_SPACE_ID ?? '',\n accessToken: process.env.CONTENTFUL_WEBSITE_TOKEN ?? '',\n host: process.env.CONTENTFUL_HOST ?? 'preview.contentful.com',\n batchSize: 1000,\n maxDepth: 4,\n contentTypes: [\n 'gridLayout','iconWithText','page'\n // Add Contentful content type IDs here to limit sync scope.\n // Leave empty to sync all content types in the space.\n ],\n },\n\n sanity: {\n projectId: process.env.SANITY_PROJECT_ID ?? '',\n dataset: process.env.SANITY_DATASET ?? 'main',\n token: process.env.SANITY_API_TOKEN ?? '',\n apiVersion: '2024-01-01',\n },\n\n retry: {\n maxRetries: parseInt(process.env.RETRY_MAX_RETRIES ?? '5', 10),\n baseDelayMs: parseInt(process.env.RETRY_BASE_DELAY_MS ?? '1000', 10),\n maxDelayMs: parseInt(process.env.RETRY_MAX_DELAY_MS ?? '60000', 10),\n },\n\n api: {\n port: parseInt(process.env.PORT ?? '3010'),\n apiToken: process.env.CONTENT_STORE_API_TOKEN ?? '',\n },\n};\n","import {\n createClient,\n type ContentfulClientApi,\n type ContentTypeCollection,\n type EntryCollection,\n type EntrySkeletonType,\n} from 'contentful';\nimport type { ContentfulConfig, RetryConfig } from '../config';\nimport type { CMSAdapter, FetchResult } from './types';\nimport { withRetry } from '../sync/retry';\n\n/**\n * Recursively unwraps Contentful's { metadata, sys, fields } envelope.\n * `depth` tracks how many entry/asset envelopes deep we are — anything\n * beyond `maxDepth` is dropped to avoid blowing the call stack on\n * circular or extremely deep reference chains.\n */\nfunction stripEnvelope(\n value: unknown,\n maxDepth: number,\n depth = 0,\n seen = new WeakSet<object>(),\n): unknown {\n if (value === null || typeof value !== 'object') return value;\n\n const obj = value as Record<string, unknown>;\n\n if (seen.has(obj)) return undefined;\n seen.add(obj);\n\n if (Array.isArray(value)) {\n return value.map((item) => stripEnvelope(item, maxDepth, depth, seen));\n }\n\n const isEnvelope = 'sys' in obj && 'fields' in obj && typeof obj.fields === 'object';\n\n if (isEnvelope) {\n if (depth >= maxDepth) return undefined;\n\n const fields = obj.fields as Record<string, unknown>;\n const result: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(fields)) {\n result[k] = stripEnvelope(v, maxDepth, depth + 1, seen);\n }\n return result;\n }\n\n const result: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n result[k] = stripEnvelope(v, maxDepth, depth, seen);\n }\n return result;\n}\n\nexport class ContentfulAdapter implements CMSAdapter {\n readonly name = 'contentful';\n private client: ContentfulClientApi<undefined>;\n private batchSize: number;\n private maxDepth: number;\n private allowedTypes: string[];\n private retryConfig: RetryConfig;\n\n constructor(cfg: ContentfulConfig, retryConfig: RetryConfig) {\n this.client = createClient({\n space: cfg.spaceId,\n accessToken: cfg.accessToken,\n host: cfg.host,\n });\n this.batchSize = cfg.batchSize;\n this.maxDepth = cfg.maxDepth;\n this.allowedTypes = cfg.contentTypes;\n this.retryConfig = retryConfig;\n }\n\n async getContentTypes(): Promise<string[]> {\n const response = await withRetry<ContentTypeCollection>(\n () => this.client.getContentTypes(),\n this.retryConfig,\n );\n\n const allTypes = response.items.map((ct) => ct.sys.id);\n\n if (this.allowedTypes.length > 0) {\n return allTypes.filter((t) => this.allowedTypes.includes(t));\n }\n return allTypes;\n }\n\n /**\n * Fetches every entry for a content type using batched pagination.\n * Contentful caps `getEntries` at 1 000 items per call, so we page through\n * with `skip` until all items are collected.\n */\n async fetchAll(contentType: string): Promise<FetchResult> {\n const allItems: unknown[] = [];\n let skip = 0;\n let total = 0;\n\n do {\n const response = await withRetry<EntryCollection<EntrySkeletonType>>(\n () =>\n this.client.getEntries({\n content_type: contentType,\n limit: this.batchSize,\n skip,\n include: 2,\n }),\n this.retryConfig,\n );\n\n total = response.total;\n allItems.push(...response.items);\n skip += response.items.length;\n\n if (total > this.batchSize) {\n console.log(\n ` [contentful] ${contentType}: fetched ${allItems.length}/${total}`,\n );\n }\n } while (skip < total);\n\n return { contentType, items: allItems.map((item) => stripEnvelope(item, this.maxDepth)), total };\n }\n}\n","import type { RetryConfig } from '../config';\n\n/**\n * Inspects an error to determine if it represents an API rate-limit (HTTP 429).\n * Returns the suggested wait time in ms when available, otherwise `0` to signal\n * that the caller should fall back to computed backoff. Returns `null` when the\n * error is *not* a rate-limit error.\n */\nfunction rateLimitDelayMs(err: unknown): number | null {\n const e = err as Record<string, unknown>;\n\n if (e?.status === 429 || e?.statusCode === 429) {\n const reset = (e?.headers as Record<string, string> | undefined)?.[\n 'x-contentful-ratelimit-reset'\n ];\n return reset ? parseFloat(reset) * 1000 : 0;\n }\n\n const resp = e?.response as Record<string, unknown> | undefined;\n if (resp?.status === 429) {\n const headers = resp?.headers as Record<string, string> | undefined;\n const reset = headers?.['x-contentful-ratelimit-reset'];\n return reset ? parseFloat(reset) * 1000 : 0;\n }\n\n return null;\n}\n\nfunction computeDelay(\n attempt: number,\n baseDelayMs: number,\n maxDelayMs: number,\n): number {\n const exponential = baseDelayMs * Math.pow(2, attempt);\n const jitter = Math.random() * baseDelayMs;\n return Math.min(exponential + jitter, maxDelayMs);\n}\n\n/**\n * Executes `fn` with automatic retry + exponential backoff.\n * Rate-limit (429) responses are handled specially: if the API provides a\n * Retry-After / reset header, that value is respected instead of computed backoff.\n */\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n { maxRetries, baseDelayMs, maxDelayMs }: RetryConfig,\n): Promise<T> {\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await fn();\n } catch (err) {\n if (attempt === maxRetries) throw err;\n\n const rlDelay = rateLimitDelayMs(err);\n let delay: number;\n\n if (rlDelay !== null) {\n delay =\n rlDelay > 0 ? rlDelay : computeDelay(attempt, baseDelayMs, maxDelayMs);\n console.warn(\n ` Rate limited (attempt ${attempt + 1}/${maxRetries}). ` +\n `Waiting ${Math.round(delay)}ms…`,\n );\n } else {\n delay = computeDelay(attempt, baseDelayMs, maxDelayMs);\n console.warn(\n ` Request failed (attempt ${attempt + 1}/${maxRetries}): ` +\n `${(err as Error).message}. Retrying in ${Math.round(delay)}ms…`,\n );\n }\n\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n\n throw new Error('withRetry: unreachable');\n}\n","import { createClient, type SanityClient } from '@sanity/client';\nimport type { SanityConfig, RetryConfig } from '../config';\nimport type { CMSAdapter, FetchResult } from './types';\nimport { withRetry } from '../sync/retry';\n\nexport class SanityAdapter implements CMSAdapter {\n readonly name = 'sanity';\n private client: SanityClient;\n private retryConfig: RetryConfig;\n\n constructor(cfg: SanityConfig, retryConfig: RetryConfig) {\n this.client = createClient({\n projectId: cfg.projectId,\n dataset: cfg.dataset,\n token: cfg.token,\n apiVersion: cfg.apiVersion,\n useCdn: false,\n });\n this.retryConfig = retryConfig;\n }\n\n async getContentTypes(): Promise<string[]> {\n const types: string[] = await withRetry(\n () => this.client.fetch(`array::unique(*[]._type)`),\n this.retryConfig,\n );\n return types.filter(\n (t) => !t.startsWith('system.') && !t.startsWith('sanity.'),\n );\n }\n\n async fetchAll(contentType: string): Promise<FetchResult> {\n const items: unknown[] = await withRetry(\n () => this.client.fetch(`*[_type == $type]`, { type: contentType }),\n this.retryConfig,\n );\n\n console.log(` [sanity] ${contentType}: fetched ${items.length} items`);\n return { contentType, items, total: items.length };\n }\n}\n","import { config, type CMSProvider } from '../config';\nimport type { CMSAdapter } from './types';\nimport { ContentfulAdapter } from './contentful';\nimport { SanityAdapter } from './sanity';\n\nexport function createAdapter(cms: CMSProvider): CMSAdapter {\n switch (cms) {\n case 'contentful':\n return new ContentfulAdapter(config.contentful, config.retry);\n case 'sanity':\n return new SanityAdapter(config.sanity, config.retry);\n default:\n throw new Error(`Unknown CMS provider: ${cms as string}`);\n }\n}\n\nexport type { CMSAdapter, FetchResult } from './types';\n","import type { CMSProvider } from '../config';\nimport { config } from '../config';\nimport { createAdapter } from '../adapters';\nimport { ContentStore } from '../../shared/s3';\n\nexport interface SyncResultEntry {\n contentType: string;\n itemCount: number;\n versionedKey: string;\n latestKey: string;\n}\n\nexport interface SyncResult {\n cms: CMSProvider;\n timestamp: number;\n entries: SyncResultEntry[];\n errors: Array<{ contentType: string; error: string }>;\n}\n\nexport async function runSync(\n cms: CMSProvider,\n contentTypes?: string[],\n): Promise<SyncResult> {\n const adapter = createAdapter(cms);\n const store = new ContentStore(config.s3);\n const timestamp = Math.floor(Date.now() / 1000);\n\n console.log(`\\nStarting sync from ${cms} at ${new Date(timestamp * 1000).toISOString()}`);\n\n const typesToSync =\n contentTypes && contentTypes.length > 0\n ? contentTypes\n : await adapter.getContentTypes();\n\n console.log(`Content types to sync: ${typesToSync.join(', ')}\\n`);\n\n const entries: SyncResultEntry[] = [];\n const errors: Array<{ contentType: string; error: string }> = [];\n\n for (const contentType of typesToSync) {\n try {\n const result = await adapter.fetchAll(contentType);\n\n const versionedKey = store.buildVersionedKey(cms, contentType, timestamp);\n await store.upload(versionedKey, result.items);\n\n const latestKey = await store.copyToLatest(versionedKey, cms, contentType);\n\n entries.push({\n contentType,\n itemCount: result.total,\n versionedKey,\n latestKey,\n });\n\n console.log(\n ` + ${contentType}: ${result.total} items -> ${versionedKey}`,\n );\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n errors.push({ contentType, error: message });\n console.error(` x ${contentType}: ${message}`);\n }\n }\n\n console.log(\n `\\nSync complete: ${entries.length} succeeded, ${errors.length} failed\\n`,\n );\n\n return { cms, timestamp, entries, errors };\n}\n"],"mappings":";;;;;;;AAAA,OAAO,YAAY;AAInB,OAAO,OAAO,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,OAAO;AAwCP,IAAMA,UAAsC;AAAA,EACjD,GAAG;AAAA,EACH,YAAY;AAAA,IACV,SAAS,QAAQ,IAAI,uBAAuB;AAAA,IAC5C,aAAa,QAAQ,IAAI,4BAA4B;AAAA,IACrD,MAAM,QAAQ,IAAI,mBAAmB;AAAA,IACrC,WAAW;AAAA,IACX,UAAU;AAAA,IACV,cAAc;AAAA,MACV;AAAA,MAAa;AAAA,MAAe;AAAA;AAAA;AAAA,IAGhC;AAAA,EACF;AAAA,EAEA,QAAQ;AAAA,IACN,WAAW,QAAQ,IAAI,qBAAqB;AAAA,IAC5C,SAAS,QAAQ,IAAI,kBAAkB;AAAA,IACvC,OAAO,QAA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