@bernierllc/contentful-suite 1.1.3 → 1.3.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.
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,424 +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 { ContentfulSuite } from '../ContentfulSuite';
10
- import { InMemoryContentStorage } from '../storage/InMemoryContentStorage';
11
- import { InMemorySyncStateStorage } from '../storage/InMemorySyncStateStorage';
12
- import { InMemoryMigrationStorage } from '../storage/InMemoryMigrationStorage';
13
- import type { ContentfulSuiteConfig } from '../types';
14
-
15
- // Mock all service dependencies
16
- jest.mock('@bernierllc/contentful-gateway-service');
17
- jest.mock('@bernierllc/contentful-sync-service');
18
- jest.mock('@bernierllc/contentful-webhook-service');
19
- jest.mock('@bernierllc/contentful-cache-service');
20
- jest.mock('@bernierllc/contentful-migration-service');
21
- jest.mock('@bernierllc/logger');
22
- jest.mock('@bernierllc/neverhub-adapter');
23
-
24
- describe('ContentfulSuite', () => {
25
- let config: ContentfulSuiteConfig;
26
- let contentStorage: InMemoryContentStorage;
27
- let syncStateStorage: InMemorySyncStateStorage;
28
- let migrationStorage: InMemoryMigrationStorage;
29
-
30
- beforeEach(() => {
31
- contentStorage = new InMemoryContentStorage();
32
- syncStateStorage = new InMemorySyncStateStorage();
33
- migrationStorage = new InMemoryMigrationStorage();
34
-
35
- config = {
36
- oauth: {
37
- clientId: 'test-client-id',
38
- clientSecret: 'test-client-secret',
39
- redirectUri: 'http://localhost:3000/oauth/callback'
40
- },
41
- gateway: {
42
- enabled: true,
43
- port: 3000,
44
- apiKeys: ['test-api-key']
45
- },
46
- sync: {
47
- enabled: true,
48
- interval: 60000,
49
- spaces: [
50
- {
51
- spaceId: 'test-space-1',
52
- environmentId: 'master',
53
- accessToken: 'test-token-1'
54
- }
55
- ]
56
- },
57
- webhooks: {
58
- enabled: true,
59
- port: 3001,
60
- secret: 'test-webhook-secret'
61
- },
62
- cache: {
63
- enabled: true,
64
- backend: 'memory',
65
- ttl: 300
66
- },
67
- migration: {
68
- enabled: true
69
- },
70
- storage: {
71
- contentStorage,
72
- syncStateStorage,
73
- migrationStorage
74
- }
75
- };
76
- });
77
-
78
- afterEach(() => {
79
- jest.clearAllMocks();
80
- });
81
-
82
- describe('constructor', () => {
83
- it('should create a ContentfulSuite instance', () => {
84
- const suite = new ContentfulSuite(config);
85
- expect(suite).toBeInstanceOf(ContentfulSuite);
86
- });
87
- });
88
-
89
- describe('initialize', () => {
90
- it('should initialize all enabled services', async () => {
91
- const suite = new ContentfulSuite(config);
92
- await suite.initialize();
93
-
94
- expect(suite.getGateway()).toBeDefined();
95
- expect(suite.getSyncService('test-space-1')).toBeDefined();
96
- expect(suite.getWebhookService()).toBeDefined();
97
- expect(suite.getCacheService()).toBeDefined();
98
- expect(suite.getMigrationService('test-space-1')).toBeDefined();
99
- });
100
-
101
- it('should not initialize disabled services', async () => {
102
- const minimalConfig: ContentfulSuiteConfig = {
103
- ...config,
104
- gateway: { ...config.gateway, enabled: false },
105
- sync: { ...config.sync, enabled: false },
106
- webhooks: { ...config.webhooks, enabled: false },
107
- cache: { ...config.cache, enabled: false },
108
- migration: { ...config.migration, enabled: false }
109
- };
110
-
111
- const suite = new ContentfulSuite(minimalConfig);
112
- await suite.initialize();
113
-
114
- expect(suite.getGateway()).toBeUndefined();
115
- expect(suite.getSyncService('test-space-1')).toBeUndefined();
116
- expect(suite.getWebhookService()).toBeUndefined();
117
- expect(suite.getCacheService()).toBeUndefined();
118
- expect(suite.getMigrationService('test-space-1')).toBeUndefined();
119
- });
120
-
121
- it('should throw error if sync enabled without storage', async () => {
122
- const invalidConfig: ContentfulSuiteConfig = {
123
- ...config,
124
- storage: {}
125
- };
126
-
127
- const suite = new ContentfulSuite(invalidConfig);
128
- await expect(suite.initialize()).rejects.toThrow(
129
- 'Content storage and sync state storage required for sync service'
130
- );
131
- });
132
-
133
- it('should throw error if migration enabled without storage', async () => {
134
- const invalidConfig: ContentfulSuiteConfig = {
135
- ...config,
136
- sync: { ...config.sync, enabled: false },
137
- storage: {
138
- contentStorage: undefined,
139
- syncStateStorage: undefined,
140
- migrationStorage: undefined
141
- }
142
- };
143
-
144
- const suite = new ContentfulSuite(invalidConfig);
145
- await expect(suite.initialize()).rejects.toThrow(
146
- 'Migration storage required for migration service'
147
- );
148
- });
149
-
150
- it('should initialize multiple sync services for multiple spaces', async () => {
151
- const multiSpaceConfig: ContentfulSuiteConfig = {
152
- ...config,
153
- sync: {
154
- enabled: true,
155
- spaces: [
156
- { spaceId: 'space-1', environmentId: 'master', accessToken: 'token-1' },
157
- { spaceId: 'space-2', environmentId: 'master', accessToken: 'token-2' }
158
- ]
159
- }
160
- };
161
-
162
- const suite = new ContentfulSuite(multiSpaceConfig);
163
- await suite.initialize();
164
-
165
- expect(suite.getSyncService('space-1')).toBeDefined();
166
- expect(suite.getSyncService('space-2')).toBeDefined();
167
- });
168
- });
169
-
170
- describe('start', () => {
171
- it('should start all initialized services', async () => {
172
- const suite = new ContentfulSuite(config);
173
- await suite.initialize();
174
-
175
- const gateway = suite.getGateway();
176
- const webhooks = suite.getWebhookService();
177
-
178
- await suite.start();
179
-
180
- expect(gateway?.start).toHaveBeenCalled();
181
- expect(webhooks?.start).toHaveBeenCalledWith(3001);
182
- });
183
-
184
- it('should start sync polling if interval configured', async () => {
185
- jest.useFakeTimers();
186
-
187
- const suite = new ContentfulSuite(config);
188
- await suite.initialize();
189
-
190
- const syncService = suite.getSyncService('test-space-1');
191
-
192
- await suite.start();
193
-
194
- // Fast-forward time
195
- jest.advanceTimersByTime(60000);
196
-
197
- expect(syncService?.incrementalSync).toHaveBeenCalled();
198
-
199
- jest.useRealTimers();
200
- });
201
- });
202
-
203
- describe('stop', () => {
204
- it('should stop all services gracefully', async () => {
205
- const suite = new ContentfulSuite(config);
206
- await suite.initialize();
207
- await suite.start();
208
-
209
- const webhooks = suite.getWebhookService();
210
-
211
- await suite.stop();
212
-
213
- expect(webhooks?.stop).toHaveBeenCalled();
214
- });
215
-
216
- it('should clear sync intervals', async () => {
217
- jest.useFakeTimers();
218
-
219
- const suite = new ContentfulSuite(config);
220
- await suite.initialize();
221
- await suite.start();
222
-
223
- const syncService = suite.getSyncService('test-space-1');
224
-
225
- await suite.stop();
226
-
227
- // Advance time - sync should NOT be called after stop
228
- jest.advanceTimersByTime(60000);
229
-
230
- expect(syncService?.incrementalSync).not.toHaveBeenCalled();
231
-
232
- jest.useRealTimers();
233
- });
234
- });
235
-
236
- describe('getMLTrainingData', () => {
237
- it('should return all entries from content storage', async () => {
238
- const suite = new ContentfulSuite(config);
239
- await suite.initialize();
240
-
241
- // Add test data
242
- await contentStorage.storeEntries([
243
- {
244
- sys: {
245
- id: 'entry-1',
246
- type: 'Entry',
247
- contentType: { sys: { id: 'article', type: 'Link', linkType: 'ContentType' } },
248
- createdAt: '2025-01-01T00:00:00Z',
249
- updatedAt: '2025-01-01T00:00:00Z',
250
- revision: 1,
251
- space: { sys: { id: 'test-space', type: 'Link', linkType: 'Space' } },
252
- environment: { sys: { id: 'master', type: 'Link', linkType: 'Environment' } }
253
- },
254
- fields: { title: { 'en-US': 'Test Article' } }
255
- } as any
256
- ]);
257
-
258
- const data = await suite.getMLTrainingData('test-space-1');
259
-
260
- expect(data).toHaveLength(1);
261
- expect(data[0]).toHaveProperty('sys.id', 'entry-1');
262
- });
263
-
264
- it('should filter by content type if specified', async () => {
265
- const suite = new ContentfulSuite(config);
266
- await suite.initialize();
267
-
268
- await contentStorage.storeEntries([
269
- {
270
- sys: {
271
- id: 'entry-1',
272
- type: 'Entry',
273
- contentType: { sys: { id: 'article', type: 'Link', linkType: 'ContentType' } },
274
- createdAt: '2025-01-01T00:00:00Z',
275
- updatedAt: '2025-01-01T00:00:00Z',
276
- revision: 1,
277
- space: { sys: { id: 'test-space', type: 'Link', linkType: 'Space' } },
278
- environment: { sys: { id: 'master', type: 'Link', linkType: 'Environment' } }
279
- },
280
- fields: { title: { 'en-US': 'Article' } }
281
- } as any,
282
- {
283
- sys: {
284
- id: 'entry-2',
285
- type: 'Entry',
286
- contentType: { sys: { id: 'page', type: 'Link', linkType: 'ContentType' } },
287
- createdAt: '2025-01-01T00:00:00Z',
288
- updatedAt: '2025-01-01T00:00:00Z',
289
- revision: 1,
290
- space: { sys: { id: 'test-space', type: 'Link', linkType: 'Space' } },
291
- environment: { sys: { id: 'master', type: 'Link', linkType: 'Environment' } }
292
- },
293
- fields: { title: { 'en-US': 'Page' } }
294
- } as any
295
- ]);
296
-
297
- const data = await suite.getMLTrainingData('test-space-1', 'article');
298
-
299
- expect(data).toHaveLength(1);
300
- expect(data[0]).toHaveProperty('sys.contentType.sys.id', 'article');
301
- });
302
-
303
- it('should throw error if content storage not configured', async () => {
304
- const noStorageConfig: ContentfulSuiteConfig = {
305
- ...config,
306
- sync: { ...config.sync, enabled: false },
307
- migration: { ...config.migration, enabled: false },
308
- storage: {}
309
- };
310
-
311
- const suite = new ContentfulSuite(noStorageConfig);
312
- await suite.initialize();
313
-
314
- await expect(suite.getMLTrainingData('test-space-1')).rejects.toThrow(
315
- 'Content storage not configured'
316
- );
317
- });
318
- });
319
-
320
- describe('runMigration', () => {
321
- it('should run migration on specified space', async () => {
322
- const suite = new ContentfulSuite(config);
323
- await suite.initialize();
324
-
325
- const migrationService = suite.getMigrationService('test-space-1');
326
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
327
- const migrationFunction = (migration: any) => {
328
- migration.createContentType('test');
329
- };
330
-
331
- await suite.runMigration('test-space-1', migrationFunction, {
332
- id: 'migration-1',
333
- name: 'Test Migration'
334
- });
335
-
336
- expect(migrationService?.runMigration).toHaveBeenCalledWith(migrationFunction, {
337
- id: 'migration-1',
338
- name: 'Test Migration'
339
- });
340
- });
341
-
342
- it('should throw error if no migration service for space', async () => {
343
- const suite = new ContentfulSuite(config);
344
- await suite.initialize();
345
-
346
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
347
- const migrationFunction = (migration: any) => {
348
- migration.createContentType('test');
349
- };
350
-
351
- await expect(
352
- suite.runMigration('unknown-space', migrationFunction, {
353
- id: 'migration-1',
354
- name: 'Test'
355
- })
356
- ).rejects.toThrow('No migration service for space unknown-space');
357
- });
358
- });
359
-
360
- describe('getHealth', () => {
361
- it('should return health status of all services', async () => {
362
- const suite = new ContentfulSuite(config);
363
- await suite.initialize();
364
-
365
- const health = suite.getHealth();
366
-
367
- expect(health).toEqual({
368
- status: 'ok',
369
- timestamp: expect.any(String),
370
- services: {
371
- gateway: true,
372
- sync: true,
373
- webhooks: true,
374
- cache: true,
375
- migration: true,
376
- neverhub: false // Mocked as not detected
377
- }
378
- });
379
- });
380
-
381
- it('should reflect disabled services in health status', async () => {
382
- const minimalConfig: ContentfulSuiteConfig = {
383
- ...config,
384
- gateway: { ...config.gateway, enabled: false },
385
- sync: { ...config.sync, enabled: false }
386
- };
387
-
388
- const suite = new ContentfulSuite(minimalConfig);
389
- await suite.initialize();
390
-
391
- const health = suite.getHealth();
392
-
393
- expect(health.services.gateway).toBe(false);
394
- expect(health.services.sync).toBe(false);
395
- });
396
- });
397
-
398
- describe('service getters', () => {
399
- it('should provide access to individual services', async () => {
400
- const suite = new ContentfulSuite(config);
401
- await suite.initialize();
402
-
403
- expect(suite.getGateway()).toBeDefined();
404
- expect(suite.getSyncService('test-space-1')).toBeDefined();
405
- expect(suite.getWebhookService()).toBeDefined();
406
- expect(suite.getCacheService()).toBeDefined();
407
- expect(suite.getMigrationService('test-space-1')).toBeDefined();
408
- });
409
-
410
- it('should return undefined for disabled services', async () => {
411
- const minimalConfig: ContentfulSuiteConfig = {
412
- ...config,
413
- gateway: { ...config.gateway, enabled: false },
414
- sync: { ...config.sync, enabled: false }
415
- };
416
-
417
- const suite = new ContentfulSuite(minimalConfig);
418
- await suite.initialize();
419
-
420
- expect(suite.getGateway()).toBeUndefined();
421
- expect(suite.getSyncService('test-space-1')).toBeUndefined();
422
- });
423
- });
424
- });