@bernierllc/contentful-suite 1.1.3 → 1.3.1

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.
Files changed (41) hide show
  1. package/dist/ContentfulSuite.js +9 -3
  2. package/dist/ContentfulSuite.js.map +1 -1
  3. package/dist/__tests__/errors.test.d.ts +2 -0
  4. package/dist/__tests__/errors.test.d.ts.map +1 -0
  5. package/dist/__tests__/errors.test.js +34 -0
  6. package/dist/__tests__/errors.test.js.map +1 -0
  7. package/dist/errors.d.ts +12 -0
  8. package/dist/errors.d.ts.map +1 -0
  9. package/dist/errors.js +25 -0
  10. package/dist/errors.js.map +1 -0
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +4 -1
  14. package/dist/index.js.map +1 -1
  15. package/dist/storage/InMemoryContentStorage.js +3 -5
  16. package/dist/storage/InMemoryContentStorage.js.map +1 -1
  17. package/dist/storage/InMemoryMigrationStorage.js +1 -3
  18. package/dist/storage/InMemoryMigrationStorage.js.map +1 -1
  19. package/dist/storage/InMemorySyncStateStorage.js +1 -3
  20. package/dist/storage/InMemorySyncStateStorage.js.map +1 -1
  21. package/package.json +22 -18
  22. package/.eslintrc.cjs +0 -16
  23. package/CHANGELOG.md +0 -170
  24. package/__mocks__/@bernierllc/contentful-cache-service.ts +0 -12
  25. package/__mocks__/@bernierllc/contentful-gateway-service.ts +0 -21
  26. package/__mocks__/@bernierllc/contentful-migration-service.ts +0 -13
  27. package/__mocks__/@bernierllc/contentful-sync-service.ts +0 -14
  28. package/__mocks__/@bernierllc/contentful-webhook-service.ts +0 -15
  29. package/__mocks__/@bernierllc/logger.ts +0 -27
  30. package/__mocks__/@bernierllc/neverhub-adapter.ts +0 -17
  31. package/jest.config.cjs +0 -44
  32. package/src/ContentfulSuite.ts +0 -415
  33. package/src/__tests__/ContentfulSuite.test.ts +0 -424
  34. package/src/__tests__/storage.test.ts +0 -405
  35. package/src/index.ts +0 -60
  36. package/src/storage/InMemoryContentStorage.ts +0 -103
  37. package/src/storage/InMemoryMigrationStorage.ts +0 -73
  38. package/src/storage/InMemorySyncStateStorage.ts +0 -42
  39. package/src/storage/index.ts +0 -11
  40. package/src/types.ts +0 -158
  41. package/tsconfig.json +0 -21
@@ -1,17 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- export class NeverHubAdapter {
10
- static async detect(): Promise<boolean> {
11
- return false;
12
- }
13
-
14
- async register(_config: Record<string, unknown>): Promise<void> {}
15
- async publishEvent(_event: Record<string, unknown>): Promise<void> {}
16
- async subscribe(_eventType: string, _handler: (event: unknown) => void): Promise<void> {}
17
- }
package/jest.config.cjs DELETED
@@ -1,44 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- module.exports = {
10
- preset: 'ts-jest',
11
- testEnvironment: '<rootDir>/../../../jest-environment-node-fixed.cjs',
12
- roots: ['<rootDir>/src'],
13
- testMatch: ['**/__tests__/**/*.test.ts'],
14
- collectCoverageFrom: [
15
- 'src/**/*.ts',
16
- '!src/**/*.d.ts',
17
- '!src/**/__tests__/**',
18
- '!src/**/index.ts'
19
- ],
20
- coverageThreshold: {
21
- global: {
22
- branches: 80,
23
- functions: 80,
24
- lines: 80,
25
- statements: 80
26
- }
27
- },
28
- moduleNameMapper: {
29
- '^@/(.*)$': '<rootDir>/src/$1',
30
- '^@bernierllc/neverhub-adapter$': '<rootDir>/__mocks__/@bernierllc/neverhub-adapter.ts',
31
- '^@bernierllc/logger$': '<rootDir>/__mocks__/@bernierllc/logger.ts',
32
- '^@bernierllc/contentful-gateway-service$': '<rootDir>/__mocks__/@bernierllc/contentful-gateway-service.ts',
33
- '^@bernierllc/contentful-sync-service$': '<rootDir>/__mocks__/@bernierllc/contentful-sync-service.ts',
34
- '^@bernierllc/contentful-webhook-service$': '<rootDir>/__mocks__/@bernierllc/contentful-webhook-service.ts',
35
- '^@bernierllc/contentful-cache-service$': '<rootDir>/__mocks__/@bernierllc/contentful-cache-service.ts',
36
- '^@bernierllc/contentful-migration-service$': '<rootDir>/__mocks__/@bernierllc/contentful-migration-service.ts'
37
- },
38
- transformIgnorePatterns: [
39
- 'node_modules/(?!(node-fetch|data-uri-to-buffer|fetch-blob|formdata-polyfill)/)'
40
- ],
41
- clearMocks: true,
42
- resetMocks: true,
43
- restoreMocks: true
44
- };
@@ -1,415 +0,0 @@
1
- /*
2
- Copyright (c) 2025 Bernier LLC
3
-
4
- This file is licensed to the client under a limited-use license.
5
- The client may use and modify this code *only within the scope of the project it was delivered for*.
6
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
- */
8
-
9
- import { ContentfulGatewayService } from '@bernierllc/contentful-gateway-service';
10
- import { InMemoryTokenStorage } from '@bernierllc/contentful-gateway-service';
11
- import { ContentfulSyncService } from '@bernierllc/contentful-sync-service';
12
- import { ContentfulWebhookService } from '@bernierllc/contentful-webhook-service';
13
- import { ContentfulCacheService } from '@bernierllc/contentful-cache-service';
14
- import { ContentfulMigrationService } from '@bernierllc/contentful-migration-service';
15
- import { Logger, LogLevel } from '@bernierllc/logger';
16
- import { NeverHubAdapter } from '@bernierllc/neverhub-adapter';
17
- import type {
18
- ContentfulSuiteConfig,
19
- ServiceStatus,
20
- SuiteHealth,
21
- SpaceConfig
22
- } from './types';
23
-
24
- /**
25
- * ContentfulSuite - Complete Contentful integration orchestrator
26
- *
27
- * Provides unified interface for:
28
- * - ML training pipeline (full content export + sync)
29
- * - Headless CMS proxy (API gateway + caching)
30
- * - Content syndication (real-time webhooks)
31
- * - Multi-space/organization management
32
- */
33
- export class ContentfulSuite {
34
- private gateway?: ContentfulGatewayService;
35
- private syncServices: Map<string, ContentfulSyncService> = new Map();
36
- private webhooks?: ContentfulWebhookService;
37
- private cache?: ContentfulCacheService;
38
- private migrationServices: Map<string, ContentfulMigrationService> = new Map();
39
- private config: ContentfulSuiteConfig;
40
- private logger: Logger;
41
- private neverhub?: NeverHubAdapter;
42
- private syncIntervals: ReturnType<typeof setInterval>[] = [];
43
-
44
- constructor(config: ContentfulSuiteConfig) {
45
- this.config = config;
46
- this.logger = new Logger({
47
- level: LogLevel.INFO,
48
- transports: [],
49
- context: { service: 'ContentfulSuite' }
50
- });
51
- }
52
-
53
- /**
54
- * Initialize all suite services
55
- */
56
- async initialize(): Promise<void> {
57
- this.logger.info('Initializing Contentful suite', {
58
- gateway: this.config.gateway.enabled,
59
- sync: this.config.sync.enabled,
60
- webhooks: this.config.webhooks.enabled,
61
- cache: this.config.cache.enabled,
62
- migration: this.config.migration.enabled
63
- });
64
-
65
- // Initialize NeverHub integration
66
- if (await NeverHubAdapter.detect()) {
67
- this.neverhub = new NeverHubAdapter();
68
- await this.neverhub.register({
69
- type: 'contentful-suite',
70
- name: '@bernierllc/contentful-suite',
71
- version: '1.0.0',
72
- dependencies: ['storage', 'cache', 'queue'],
73
- capabilities: [
74
- {
75
- type: 'cms',
76
- name: 'contentful-integration',
77
- version: '1.0.0',
78
- metadata: {
79
- apis: ['CMA', 'CDA', 'GraphQL'],
80
- features: ['sync', 'webhooks', 'caching', 'migrations']
81
- }
82
- }
83
- ],
84
- discoveryEnabled: true
85
- });
86
- this.logger.info('NeverHub integration initialized');
87
- }
88
-
89
- // Initialize gateway service
90
- if (this.config.gateway.enabled) {
91
- const tokenStorage = this.config.storage.tokenStorage || new InMemoryTokenStorage();
92
- this.gateway = new ContentfulGatewayService(
93
- {
94
- port: this.config.gateway.port,
95
- apiKeys: this.config.gateway.apiKeys,
96
- oauthConfig: this.config.oauth
97
- },
98
- tokenStorage
99
- );
100
- this.logger.info('Gateway service initialized', { port: this.config.gateway.port });
101
- }
102
-
103
- // Initialize sync services (one per space)
104
- if (this.config.sync.enabled) {
105
- if (!this.config.storage.contentStorage || !this.config.storage.syncStateStorage) {
106
- throw new Error('Content storage and sync state storage required for sync service');
107
- }
108
-
109
- for (const space of this.config.sync.spaces) {
110
- const syncService = new ContentfulSyncService({
111
- spaceId: space.spaceId,
112
- environmentId: space.environmentId,
113
- accessToken: space.accessToken,
114
- contentStorage: this.config.storage.contentStorage,
115
- syncStateStorage: this.config.storage.syncStateStorage,
116
- webhookSecret: this.config.webhooks.secret,
117
- syncInterval: this.config.sync.interval
118
- });
119
-
120
- this.syncServices.set(space.spaceId, syncService);
121
-
122
- // Perform initial sync if needed
123
- const needsSync = await this.checkNeedsInitialSync(space);
124
- if (needsSync) {
125
- this.logger.info('Performing initial sync', { spaceId: space.spaceId });
126
- // Initial sync requires CMA token - user must call it manually with their CMA token
127
- this.logger.info('Initial sync required - call getSyncService(spaceId).initialSync(cmaToken)');
128
- }
129
-
130
- this.logger.info('Sync service initialized', { spaceId: space.spaceId });
131
- }
132
- }
133
-
134
- // Initialize webhook service
135
- if (this.config.webhooks.enabled) {
136
- this.webhooks = new ContentfulWebhookService({
137
- webhookSecret: this.config.webhooks.secret
138
- });
139
-
140
- // Connect webhooks to sync services
141
- if (this.syncServices.size > 0) {
142
- this.webhooks.on('webhook.received', async (data: { body: string; headers: Record<string, string> }) => {
143
- // Route webhook to appropriate sync service based on space
144
- const syncServicesArray = Array.from(this.syncServices.values());
145
- for (const syncService of syncServicesArray) {
146
- try {
147
- await syncService.processWebhook(data.body, data.headers);
148
- } catch (error) {
149
- const err = error as Error;
150
- this.logger.error('Error processing webhook in sync service', err);
151
- }
152
- }
153
- });
154
- }
155
-
156
- // Connect webhooks to cache service for invalidation
157
- if (this.cache) {
158
- this.webhooks.on('webhook.received', async (data: { topic: string; payload: unknown }) => {
159
- try {
160
- // Cache service handles webhook internally via sync service
161
- this.logger.debug('Webhook received for cache invalidation', { topic: data.topic });
162
- } catch (error) {
163
- const err = error as Error;
164
- this.logger.error('Error processing webhook in cache service', err);
165
- }
166
- });
167
- }
168
-
169
- this.logger.info('Webhook service initialized', { port: this.config.webhooks.port });
170
- }
171
-
172
- // Initialize cache service
173
- if (this.config.cache.enabled && this.config.sync.spaces.length > 0) {
174
- const firstSpace = this.config.sync.spaces[0];
175
- this.cache = new ContentfulCacheService({
176
- contentful: {
177
- space: firstSpace.spaceId,
178
- accessToken: firstSpace.accessToken,
179
- environment: firstSpace.environmentId
180
- },
181
- cache: {
182
- ttl: this.config.cache.ttl,
183
- maxSize: 1000
184
- }
185
- });
186
- this.logger.info('Cache service initialized', { ttl: this.config.cache.ttl });
187
- }
188
-
189
- // Initialize migration services (one per space)
190
- if (this.config.migration.enabled) {
191
- if (!this.config.storage.migrationStorage) {
192
- throw new Error('Migration storage required for migration service');
193
- }
194
-
195
- for (const space of this.config.sync.spaces) {
196
- const migrationService = new ContentfulMigrationService({
197
- spaceId: space.spaceId,
198
- environmentId: space.environmentId,
199
- accessToken: space.accessToken,
200
- storage: this.config.storage.migrationStorage
201
- });
202
-
203
- this.migrationServices.set(space.spaceId, migrationService);
204
- this.logger.info('Migration service initialized', { spaceId: space.spaceId });
205
- }
206
- }
207
-
208
- this.logger.info('Contentful suite initialized successfully', this.getServiceStatus());
209
- }
210
-
211
- /**
212
- * Start all services
213
- */
214
- async start(): Promise<void> {
215
- this.logger.info('Starting Contentful suite');
216
-
217
- // Start gateway
218
- if (this.gateway) {
219
- await this.gateway.start();
220
- this.logger.info('Gateway service started');
221
- }
222
-
223
- // Start webhook server
224
- if (this.webhooks) {
225
- await this.webhooks.start(this.config.webhooks.port);
226
- this.logger.info('Webhook service started', { port: this.config.webhooks.port });
227
- }
228
-
229
- // Start incremental sync polling for each space
230
- if (this.config.sync.enabled && this.config.sync.interval) {
231
- const syncServicesEntries = Array.from(this.syncServices.entries());
232
- for (const [spaceId, syncService] of syncServicesEntries) {
233
- const interval = setInterval(async () => {
234
- try {
235
- this.logger.debug('Running incremental sync', { spaceId });
236
- await syncService.incrementalSync();
237
- } catch (error) {
238
- const err = error as Error;
239
- this.logger.error('Incremental sync error', err);
240
- }
241
- }, this.config.sync.interval);
242
-
243
- this.syncIntervals.push(interval);
244
- }
245
- this.logger.info('Sync polling started', {
246
- interval: this.config.sync.interval,
247
- spaces: this.config.sync.spaces.length
248
- });
249
- }
250
-
251
- // Publish started event to NeverHub
252
- if (this.neverhub) {
253
- await this.neverhub.publishEvent({
254
- type: 'contentful.suite.started',
255
- data: {
256
- timestamp: new Date().toISOString(),
257
- services: this.getServiceStatus()
258
- }
259
- });
260
- }
261
-
262
- this.logger.info('Contentful suite started successfully');
263
- }
264
-
265
- /**
266
- * Stop all services gracefully
267
- */
268
- async stop(): Promise<void> {
269
- this.logger.info('Stopping Contentful suite');
270
-
271
- // Clear sync intervals
272
- for (const interval of this.syncIntervals) {
273
- clearInterval(interval);
274
- }
275
- this.syncIntervals = [];
276
-
277
- // Stop webhook service
278
- if (this.webhooks) {
279
- await this.webhooks.stop();
280
- this.logger.info('Webhook service stopped');
281
- }
282
-
283
- // Gateway doesn't have explicit stop in current implementation
284
- // Future: Add graceful shutdown for gateway
285
-
286
- // Publish stopped event to NeverHub
287
- if (this.neverhub) {
288
- await this.neverhub.publishEvent({
289
- type: 'contentful.suite.stopped',
290
- data: {
291
- timestamp: new Date().toISOString()
292
- }
293
- });
294
- }
295
-
296
- this.logger.info('Contentful suite stopped');
297
- }
298
-
299
- /**
300
- * Get content for ML training
301
- * Queries local storage for all synced content
302
- */
303
- async getMLTrainingData(spaceId: string, contentType?: string): Promise<unknown[]> {
304
- if (!this.config.storage.contentStorage) {
305
- throw new Error('Content storage not configured');
306
- }
307
-
308
- const storage = this.config.storage.contentStorage;
309
-
310
- // In a real implementation, we'd query by space and content type
311
- // For now, assume InMemoryContentStorage with getAllEntries method
312
- if ('getAllEntries' in storage && typeof storage.getAllEntries === 'function') {
313
- const entries = storage.getAllEntries();
314
-
315
- if (contentType) {
316
- return entries.filter((e: { sys: { contentType: { sys: { id: string } } } }) =>
317
- e.sys.contentType.sys.id === contentType
318
- );
319
- }
320
-
321
- return entries;
322
- }
323
-
324
- this.logger.warn('Content storage does not support getAllEntries method');
325
- return [];
326
- }
327
-
328
- /**
329
- * Run migration on a specific space
330
- */
331
- async runMigration(
332
- spaceId: string,
333
- migrationFunction: (_migration: unknown) => void,
334
- options: { dryRun?: boolean; id: string; name: string }
335
- ): Promise<void> {
336
- const migrationService = this.migrationServices.get(spaceId);
337
- if (!migrationService) {
338
- throw new Error(`No migration service for space ${spaceId}`);
339
- }
340
-
341
- await migrationService.runMigration(migrationFunction, options);
342
- }
343
-
344
- /**
345
- * Get health status of all services
346
- */
347
- getHealth(): SuiteHealth {
348
- return {
349
- status: 'ok',
350
- timestamp: new Date().toISOString(),
351
- services: this.getServiceStatus()
352
- };
353
- }
354
-
355
- /**
356
- * Get service status
357
- */
358
- private getServiceStatus(): ServiceStatus {
359
- return {
360
- gateway: !!this.gateway,
361
- sync: this.syncServices.size > 0,
362
- webhooks: !!this.webhooks,
363
- cache: !!this.cache,
364
- migration: this.migrationServices.size > 0,
365
- neverhub: !!this.neverhub
366
- };
367
- }
368
-
369
- /**
370
- * Check if a space needs initial sync
371
- */
372
- private async checkNeedsInitialSync(space: SpaceConfig): Promise<boolean> {
373
- if (!this.config.storage.syncStateStorage) {
374
- return true;
375
- }
376
-
377
- const token = await this.config.storage.syncStateStorage.getSyncToken(space.spaceId);
378
- return token === null;
379
- }
380
-
381
- /**
382
- * Get gateway service (for advanced use)
383
- */
384
- getGateway(): ContentfulGatewayService | undefined {
385
- return this.gateway;
386
- }
387
-
388
- /**
389
- * Get sync service for a space (for advanced use)
390
- */
391
- getSyncService(spaceId: string): ContentfulSyncService | undefined {
392
- return this.syncServices.get(spaceId);
393
- }
394
-
395
- /**
396
- * Get webhook service (for advanced use)
397
- */
398
- getWebhookService(): ContentfulWebhookService | undefined {
399
- return this.webhooks;
400
- }
401
-
402
- /**
403
- * Get cache service (for advanced use)
404
- */
405
- getCacheService(): ContentfulCacheService | undefined {
406
- return this.cache;
407
- }
408
-
409
- /**
410
- * Get migration service for a space (for advanced use)
411
- */
412
- getMigrationService(spaceId: string): ContentfulMigrationService | undefined {
413
- return this.migrationServices.get(spaceId);
414
- }
415
- }