@bernierllc/contentful-sync-service 1.0.2
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/LICENSE.md +7 -0
- package/README.md +343 -0
- package/dist/contentful-sync-service.d.ts +51 -0
- package/dist/contentful-sync-service.js +277 -0
- package/dist/in-memory-storage.d.ts +37 -0
- package/dist/in-memory-storage.js +103 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +15 -0
- package/dist/types.d.ts +142 -0
- package/dist/types.js +9 -0
- package/package.json +52 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
This file is licensed to the client under a limited-use license.
|
|
6
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
7
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
package/README.md
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
# @bernierllc/contentful-sync-service
|
|
2
|
+
|
|
3
|
+
Full export + incremental webhook sync to local storage for Contentful content.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
ContentfulSyncService syncs Contentful content to local storage for ML training pipelines. It performs an initial full export using `contentful-export`, then maintains sync via CDA Sync API + webhook processing. Provides a structured content mirror for training without hitting Contentful APIs during training.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- 🔄 **Initial Full Export** - Complete space export to local storage
|
|
12
|
+
- 📦 **Incremental Sync** - Delta sync using CDA Sync API
|
|
13
|
+
- 🪝 **Webhook Processing** - Real-time updates via webhooks
|
|
14
|
+
- 💾 **Abstract Storage** - Pluggable storage adapters
|
|
15
|
+
- 📊 **Sync Statistics** - Track sync performance
|
|
16
|
+
- 🔌 **NeverHub Integration** - Optional integration with NeverHub
|
|
17
|
+
- 📝 **Comprehensive Logging** - Detailed operation logs
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @bernierllc/contentful-sync-service
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import {
|
|
29
|
+
ContentfulSyncService,
|
|
30
|
+
InMemoryContentStorage,
|
|
31
|
+
InMemorySyncStateStorage
|
|
32
|
+
} from '@bernierllc/contentful-sync-service';
|
|
33
|
+
|
|
34
|
+
// Create storage instances
|
|
35
|
+
const contentStorage = new InMemoryContentStorage();
|
|
36
|
+
const syncStateStorage = new InMemorySyncStateStorage();
|
|
37
|
+
|
|
38
|
+
// Create service
|
|
39
|
+
const service = new ContentfulSyncService({
|
|
40
|
+
spaceId: 'your-space-id',
|
|
41
|
+
environmentId: 'master',
|
|
42
|
+
accessToken: 'your-cda-token',
|
|
43
|
+
contentStorage,
|
|
44
|
+
syncStateStorage,
|
|
45
|
+
webhookSecret: 'your-webhook-secret' // Optional
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Initialize
|
|
49
|
+
await service.initialize();
|
|
50
|
+
|
|
51
|
+
// Perform initial sync
|
|
52
|
+
const result = await service.initialSync('your-management-token');
|
|
53
|
+
console.log(`Synced ${result.stats.entriesSynced} entries`);
|
|
54
|
+
|
|
55
|
+
// Start auto-sync
|
|
56
|
+
service.startAutoSync();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Storage Adapters
|
|
60
|
+
|
|
61
|
+
### Built-in Adapters
|
|
62
|
+
|
|
63
|
+
The package provides in-memory adapters for testing:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import {
|
|
67
|
+
InMemoryContentStorage,
|
|
68
|
+
InMemorySyncStateStorage
|
|
69
|
+
} from '@bernierllc/contentful-sync-service';
|
|
70
|
+
|
|
71
|
+
const contentStorage = new InMemoryContentStorage();
|
|
72
|
+
const syncStateStorage = new InMemorySyncStateStorage();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Custom Storage Adapters
|
|
76
|
+
|
|
77
|
+
Implement the storage interfaces for your database:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import type { ContentStorage, SyncStateStorage } from '@bernierllc/contentful-sync-service';
|
|
81
|
+
import type { Entry, Asset, ContentType } from '@bernierllc/contentful-types';
|
|
82
|
+
|
|
83
|
+
class PostgreSQLContentStorage implements ContentStorage {
|
|
84
|
+
async storeContentTypes(contentTypes: ContentType[]): Promise<void> {
|
|
85
|
+
// Store in PostgreSQL
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async storeEntries(entries: Entry[]): Promise<void> {
|
|
89
|
+
// Store in PostgreSQL
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async storeAssets(assets: Asset[]): Promise<void> {
|
|
93
|
+
// Store in PostgreSQL
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async updateEntry(entry: Entry): Promise<void> {
|
|
97
|
+
// Update in PostgreSQL
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async updateAsset(asset: Asset): Promise<void> {
|
|
101
|
+
// Update in PostgreSQL
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async deleteEntry(entryId: string): Promise<void> {
|
|
105
|
+
// Delete from PostgreSQL
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async deleteAsset(assetId: string): Promise<void> {
|
|
109
|
+
// Delete from PostgreSQL
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async getEntry(entryId: string): Promise<Entry | null> {
|
|
113
|
+
// Retrieve from PostgreSQL
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async getAsset(assetId: string): Promise<Asset | null> {
|
|
117
|
+
// Retrieve from PostgreSQL
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async clearSpace(spaceId: string): Promise<void> {
|
|
121
|
+
// Clear space data from PostgreSQL
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
class PostgreSQLSyncStateStorage implements SyncStateStorage {
|
|
126
|
+
async getSyncToken(spaceId: string): Promise<string | null> {
|
|
127
|
+
// Get from PostgreSQL
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async setSyncToken(spaceId: string, token: string): Promise<void> {
|
|
131
|
+
// Store in PostgreSQL
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async clearSyncToken(spaceId: string): Promise<void> {
|
|
135
|
+
// Clear from PostgreSQL
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## API Reference
|
|
141
|
+
|
|
142
|
+
### ContentfulSyncService
|
|
143
|
+
|
|
144
|
+
#### Constructor
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
new ContentfulSyncService(config: SyncServiceConfig)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Config Options:**
|
|
151
|
+
|
|
152
|
+
- `spaceId` (string) - Contentful space ID
|
|
153
|
+
- `environmentId` (string) - Contentful environment ID
|
|
154
|
+
- `accessToken` (string) - CDA access token
|
|
155
|
+
- `contentStorage` (ContentStorage) - Content storage implementation
|
|
156
|
+
- `syncStateStorage` (SyncStateStorage) - Sync state storage implementation
|
|
157
|
+
- `webhookSecret` (string, optional) - Webhook validation secret
|
|
158
|
+
- `syncInterval` (number, optional) - Auto-sync interval in ms (default: 300000)
|
|
159
|
+
- `neverhubEnabled` (boolean, optional) - Enable NeverHub integration
|
|
160
|
+
|
|
161
|
+
#### Methods
|
|
162
|
+
|
|
163
|
+
##### `initialize(): Promise<void>`
|
|
164
|
+
|
|
165
|
+
Initialize the service and optionally connect to NeverHub.
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
await service.initialize();
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
##### `initialSync(managementToken: string): Promise<SyncResult>`
|
|
172
|
+
|
|
173
|
+
Perform initial full export from Contentful.
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
const result = await service.initialSync('cma-token');
|
|
177
|
+
console.log(result.stats.entriesSynced); // Number of entries synced
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
##### `incrementalSync(): Promise<SyncResult>`
|
|
181
|
+
|
|
182
|
+
Perform incremental sync using the CDA Sync API.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
const result = await service.incrementalSync();
|
|
186
|
+
console.log(result.stats.itemsDeleted); // Number of items deleted
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
##### `processWebhook(body: string, headers: Record<string, string>): Promise<void>`
|
|
190
|
+
|
|
191
|
+
Process a webhook event from Contentful.
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
app.post('/webhook', async (req, res) => {
|
|
195
|
+
await service.processWebhook(
|
|
196
|
+
JSON.stringify(req.body),
|
|
197
|
+
req.headers
|
|
198
|
+
);
|
|
199
|
+
res.sendStatus(200);
|
|
200
|
+
});
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
##### `startAutoSync(): void`
|
|
204
|
+
|
|
205
|
+
Start automatic incremental sync at the configured interval.
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
service.startAutoSync();
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
##### `stopAutoSync(): void`
|
|
212
|
+
|
|
213
|
+
Stop automatic sync.
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
service.stopAutoSync();
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
##### `shutdown(): Promise<void>`
|
|
220
|
+
|
|
221
|
+
Shutdown the service cleanly.
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
await service.shutdown();
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Usage Examples
|
|
228
|
+
|
|
229
|
+
### Basic Sync
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import {
|
|
233
|
+
ContentfulSyncService,
|
|
234
|
+
InMemoryContentStorage,
|
|
235
|
+
InMemorySyncStateStorage
|
|
236
|
+
} from '@bernierllc/contentful-sync-service';
|
|
237
|
+
|
|
238
|
+
const service = new ContentfulSyncService({
|
|
239
|
+
spaceId: 'my-space',
|
|
240
|
+
environmentId: 'master',
|
|
241
|
+
accessToken: 'cda-token',
|
|
242
|
+
contentStorage: new InMemoryContentStorage(),
|
|
243
|
+
syncStateStorage: new InMemorySyncStateStorage()
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
await service.initialize();
|
|
247
|
+
await service.initialSync('cma-token');
|
|
248
|
+
await service.incrementalSync();
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Auto-Sync
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
// Start auto-sync every 5 minutes
|
|
255
|
+
service.startAutoSync();
|
|
256
|
+
|
|
257
|
+
// Later...
|
|
258
|
+
service.stopAutoSync();
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Webhook Processing
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import express from 'express';
|
|
265
|
+
|
|
266
|
+
const app = express();
|
|
267
|
+
|
|
268
|
+
const service = new ContentfulSyncService({
|
|
269
|
+
spaceId: 'my-space',
|
|
270
|
+
environmentId: 'master',
|
|
271
|
+
accessToken: 'cda-token',
|
|
272
|
+
contentStorage: new InMemoryContentStorage(),
|
|
273
|
+
syncStateStorage: new InMemorySyncStateStorage(),
|
|
274
|
+
webhookSecret: 'webhook-secret'
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
await service.initialize();
|
|
278
|
+
|
|
279
|
+
app.post('/contentful-webhook', express.json(), async (req, res) => {
|
|
280
|
+
try {
|
|
281
|
+
await service.processWebhook(
|
|
282
|
+
JSON.stringify(req.body),
|
|
283
|
+
req.headers as Record<string, string>
|
|
284
|
+
);
|
|
285
|
+
res.sendStatus(200);
|
|
286
|
+
} catch (error) {
|
|
287
|
+
console.error('Webhook processing failed:', error);
|
|
288
|
+
res.sendStatus(500);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
app.listen(3000);
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### NeverHub Integration
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
const service = new ContentfulSyncService({
|
|
299
|
+
spaceId: 'my-space',
|
|
300
|
+
environmentId: 'master',
|
|
301
|
+
accessToken: 'cda-token',
|
|
302
|
+
contentStorage: new InMemoryContentStorage(),
|
|
303
|
+
syncStateStorage: new InMemorySyncStateStorage(),
|
|
304
|
+
neverhubEnabled: true // Enable NeverHub
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
await service.initialize();
|
|
308
|
+
// NeverHub registration happens automatically if available
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## TypeScript Support
|
|
312
|
+
|
|
313
|
+
Full TypeScript support with comprehensive type definitions:
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
import type {
|
|
317
|
+
ContentStorage,
|
|
318
|
+
SyncStateStorage,
|
|
319
|
+
SyncServiceConfig,
|
|
320
|
+
SyncResult,
|
|
321
|
+
SyncStats
|
|
322
|
+
} from '@bernierllc/contentful-sync-service';
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Error Handling
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
const result = await service.initialSync('cma-token');
|
|
329
|
+
|
|
330
|
+
if (!result.success) {
|
|
331
|
+
console.error('Sync failed:', result.error);
|
|
332
|
+
} else {
|
|
333
|
+
console.log('Sync succeeded:', result.stats);
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## License
|
|
338
|
+
|
|
339
|
+
Copyright (c) 2025 Bernier LLC
|
|
340
|
+
|
|
341
|
+
This file is licensed to the client under a limited-use license.
|
|
342
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
343
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { SyncServiceConfig, SyncResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* ContentfulSyncService
|
|
4
|
+
*
|
|
5
|
+
* Syncs Contentful content to local storage for ML training pipelines.
|
|
6
|
+
* Performs initial full export, then maintains sync via CDA Sync API + webhook processing.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ContentfulSyncService {
|
|
9
|
+
private readonly config;
|
|
10
|
+
private readonly exportAdapter;
|
|
11
|
+
private readonly cdaClient;
|
|
12
|
+
private readonly webhookHandler?;
|
|
13
|
+
private readonly queue;
|
|
14
|
+
private readonly logger;
|
|
15
|
+
private neverhub?;
|
|
16
|
+
private syncIntervalId?;
|
|
17
|
+
constructor(config: SyncServiceConfig);
|
|
18
|
+
/**
|
|
19
|
+
* Initialize the service
|
|
20
|
+
*/
|
|
21
|
+
initialize(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Perform initial full sync
|
|
24
|
+
*
|
|
25
|
+
* @param managementToken - Contentful Management API token for export
|
|
26
|
+
*/
|
|
27
|
+
initialSync(managementToken: string): Promise<SyncResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Perform incremental sync using CDA Sync API
|
|
30
|
+
*/
|
|
31
|
+
incrementalSync(): Promise<SyncResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Process webhook event
|
|
34
|
+
*
|
|
35
|
+
* @param body - Webhook request body
|
|
36
|
+
* @param headers - Webhook request headers
|
|
37
|
+
*/
|
|
38
|
+
processWebhook(body: string, headers: Record<string, string>): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Start automatic sync at configured interval
|
|
41
|
+
*/
|
|
42
|
+
startAutoSync(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Stop automatic sync
|
|
45
|
+
*/
|
|
46
|
+
stopAutoSync(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Shutdown the service
|
|
49
|
+
*/
|
|
50
|
+
shutdown(): Promise<void>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
This file is licensed to the client under a limited-use license.
|
|
6
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
7
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ContentfulSyncService = void 0;
|
|
11
|
+
const contentful_export_adapter_1 = require("@bernierllc/contentful-export-adapter");
|
|
12
|
+
const contentful_cda_client_1 = require("@bernierllc/contentful-cda-client");
|
|
13
|
+
const contentful_webhook_handler_1 = require("@bernierllc/contentful-webhook-handler");
|
|
14
|
+
const message_queue_1 = require("@bernierllc/message-queue");
|
|
15
|
+
const logger_1 = require("@bernierllc/logger");
|
|
16
|
+
const neverhub_adapter_1 = require("@bernierllc/neverhub-adapter");
|
|
17
|
+
/**
|
|
18
|
+
* ContentfulSyncService
|
|
19
|
+
*
|
|
20
|
+
* Syncs Contentful content to local storage for ML training pipelines.
|
|
21
|
+
* Performs initial full export, then maintains sync via CDA Sync API + webhook processing.
|
|
22
|
+
*/
|
|
23
|
+
class ContentfulSyncService {
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.config = {
|
|
26
|
+
syncInterval: 300000, // 5 minutes default
|
|
27
|
+
...config
|
|
28
|
+
};
|
|
29
|
+
this.exportAdapter = new contentful_export_adapter_1.ContentfulExportAdapter();
|
|
30
|
+
this.cdaClient = new contentful_cda_client_1.ContentfulCDAClient({
|
|
31
|
+
space: config.spaceId,
|
|
32
|
+
accessToken: config.accessToken,
|
|
33
|
+
environment: config.environmentId
|
|
34
|
+
});
|
|
35
|
+
if (config.webhookSecret) {
|
|
36
|
+
this.webhookHandler = new contentful_webhook_handler_1.ContentfulWebhookHandler({ webhookSecret: config.webhookSecret });
|
|
37
|
+
}
|
|
38
|
+
this.queue = new message_queue_1.MessageQueue({ name: 'contentful-sync' });
|
|
39
|
+
this.logger = (0, logger_1.createLogger)({
|
|
40
|
+
context: {
|
|
41
|
+
service: 'ContentfulSyncService',
|
|
42
|
+
version: '1.0.0',
|
|
43
|
+
environment: process.env.NODE_ENV || 'development'
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Initialize the service
|
|
49
|
+
*/
|
|
50
|
+
async initialize() {
|
|
51
|
+
this.logger.info('Initializing ContentfulSyncService');
|
|
52
|
+
// Initialize NeverHub if enabled
|
|
53
|
+
if (this.config.neverhubEnabled) {
|
|
54
|
+
try {
|
|
55
|
+
if (await neverhub_adapter_1.NeverHubAdapter.detect()) {
|
|
56
|
+
this.neverhub = new neverhub_adapter_1.NeverHubAdapter();
|
|
57
|
+
await this.neverhub.register({
|
|
58
|
+
type: 'service',
|
|
59
|
+
name: '@bernierllc/contentful-sync-service',
|
|
60
|
+
version: '1.0.0',
|
|
61
|
+
dependencies: [
|
|
62
|
+
'@bernierllc/contentful-export-adapter',
|
|
63
|
+
'@bernierllc/contentful-cda-client',
|
|
64
|
+
'@bernierllc/contentful-webhook-handler'
|
|
65
|
+
],
|
|
66
|
+
capabilities: [
|
|
67
|
+
{ type: 'data', name: 'sync', version: '1.0.0' },
|
|
68
|
+
{ type: 'webhook', name: 'webhook-processing', version: '1.0.0' }
|
|
69
|
+
]
|
|
70
|
+
});
|
|
71
|
+
this.logger.info('NeverHub integration enabled');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
this.logger.warn('NeverHub initialization failed', { error });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
this.logger.info('ContentfulSyncService initialized');
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Perform initial full sync
|
|
82
|
+
*
|
|
83
|
+
* @param managementToken - Contentful Management API token for export
|
|
84
|
+
*/
|
|
85
|
+
async initialSync(managementToken) {
|
|
86
|
+
const startTime = Date.now();
|
|
87
|
+
this.logger.info('Starting initial full sync', { spaceId: this.config.spaceId });
|
|
88
|
+
try {
|
|
89
|
+
// Clear existing content
|
|
90
|
+
await this.config.contentStorage.clearSpace(this.config.spaceId);
|
|
91
|
+
await this.config.syncStateStorage.clearSyncToken(this.config.spaceId);
|
|
92
|
+
// Export space
|
|
93
|
+
const exportResult = await this.exportAdapter.exportSpace({
|
|
94
|
+
spaceId: this.config.spaceId,
|
|
95
|
+
managementToken,
|
|
96
|
+
downloadAssets: true
|
|
97
|
+
});
|
|
98
|
+
// Store content types
|
|
99
|
+
if (exportResult.contentTypes && exportResult.contentTypes.length > 0) {
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
101
|
+
await this.config.contentStorage.storeContentTypes(exportResult.contentTypes);
|
|
102
|
+
this.logger.info('Stored content types', { count: exportResult.contentTypes.length });
|
|
103
|
+
}
|
|
104
|
+
// Store entries
|
|
105
|
+
if (exportResult.entries && exportResult.entries.length > 0) {
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
+
await this.config.contentStorage.storeEntries(exportResult.entries);
|
|
108
|
+
this.logger.info('Stored entries', { count: exportResult.entries.length });
|
|
109
|
+
}
|
|
110
|
+
// Store assets
|
|
111
|
+
if (exportResult.assets && exportResult.assets.length > 0) {
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
113
|
+
await this.config.contentStorage.storeAssets(exportResult.assets);
|
|
114
|
+
this.logger.info('Stored assets', { count: exportResult.assets.length });
|
|
115
|
+
}
|
|
116
|
+
// Get initial sync token from CDA
|
|
117
|
+
const syncResult = await this.cdaClient.initialSync();
|
|
118
|
+
const syncToken = syncResult.nextSyncUrl || '';
|
|
119
|
+
await this.config.syncStateStorage.setSyncToken(this.config.spaceId, syncToken);
|
|
120
|
+
const duration = Date.now() - startTime;
|
|
121
|
+
const stats = {
|
|
122
|
+
entriesSynced: exportResult.entries?.length || 0,
|
|
123
|
+
assetsSynced: exportResult.assets?.length || 0,
|
|
124
|
+
itemsDeleted: 0,
|
|
125
|
+
duration,
|
|
126
|
+
timestamp: new Date()
|
|
127
|
+
};
|
|
128
|
+
this.logger.info('Initial sync completed', stats);
|
|
129
|
+
return {
|
|
130
|
+
success: true,
|
|
131
|
+
stats
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
const duration = Date.now() - startTime;
|
|
136
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
137
|
+
const errorObj = error instanceof Error ? error : new Error(errorMessage);
|
|
138
|
+
this.logger.error('Initial sync failed', errorObj);
|
|
139
|
+
return {
|
|
140
|
+
success: false,
|
|
141
|
+
stats: {
|
|
142
|
+
entriesSynced: 0,
|
|
143
|
+
assetsSynced: 0,
|
|
144
|
+
itemsDeleted: 0,
|
|
145
|
+
duration,
|
|
146
|
+
timestamp: new Date()
|
|
147
|
+
},
|
|
148
|
+
error: errorMessage
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Perform incremental sync using CDA Sync API
|
|
154
|
+
*/
|
|
155
|
+
async incrementalSync() {
|
|
156
|
+
const startTime = Date.now();
|
|
157
|
+
this.logger.info('Starting incremental sync', { spaceId: this.config.spaceId });
|
|
158
|
+
try {
|
|
159
|
+
const syncToken = await this.config.syncStateStorage.getSyncToken(this.config.spaceId);
|
|
160
|
+
if (!syncToken) {
|
|
161
|
+
throw new Error('No sync token found - run initialSync first');
|
|
162
|
+
}
|
|
163
|
+
const syncResult = await this.cdaClient.deltaSync(syncToken);
|
|
164
|
+
let entriesSynced = 0;
|
|
165
|
+
let assetsSynced = 0;
|
|
166
|
+
let itemsDeleted = 0;
|
|
167
|
+
// Process sync items
|
|
168
|
+
const items = syncResult.items || [];
|
|
169
|
+
for (const item of items) {
|
|
170
|
+
if (item.sys.type === 'Entry') {
|
|
171
|
+
await this.config.contentStorage.updateEntry(item);
|
|
172
|
+
entriesSynced++;
|
|
173
|
+
}
|
|
174
|
+
else if (item.sys.type === 'Asset') {
|
|
175
|
+
await this.config.contentStorage.updateAsset(item);
|
|
176
|
+
assetsSynced++;
|
|
177
|
+
}
|
|
178
|
+
else if (item.sys.type === 'DeletedEntry') {
|
|
179
|
+
await this.config.contentStorage.deleteEntry(item.sys.id);
|
|
180
|
+
itemsDeleted++;
|
|
181
|
+
}
|
|
182
|
+
else if (item.sys.type === 'DeletedAsset') {
|
|
183
|
+
await this.config.contentStorage.deleteAsset(item.sys.id);
|
|
184
|
+
itemsDeleted++;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Update sync token
|
|
188
|
+
const newSyncToken = syncResult.nextSyncUrl || '';
|
|
189
|
+
await this.config.syncStateStorage.setSyncToken(this.config.spaceId, newSyncToken);
|
|
190
|
+
const duration = Date.now() - startTime;
|
|
191
|
+
const stats = {
|
|
192
|
+
entriesSynced,
|
|
193
|
+
assetsSynced,
|
|
194
|
+
itemsDeleted,
|
|
195
|
+
duration,
|
|
196
|
+
timestamp: new Date()
|
|
197
|
+
};
|
|
198
|
+
this.logger.info('Incremental sync completed', stats);
|
|
199
|
+
return {
|
|
200
|
+
success: true,
|
|
201
|
+
stats
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
const duration = Date.now() - startTime;
|
|
206
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
207
|
+
const errorObj = error instanceof Error ? error : new Error(errorMessage);
|
|
208
|
+
this.logger.error('Incremental sync failed', errorObj);
|
|
209
|
+
return {
|
|
210
|
+
success: false,
|
|
211
|
+
stats: {
|
|
212
|
+
entriesSynced: 0,
|
|
213
|
+
assetsSynced: 0,
|
|
214
|
+
itemsDeleted: 0,
|
|
215
|
+
duration,
|
|
216
|
+
timestamp: new Date()
|
|
217
|
+
},
|
|
218
|
+
error: errorMessage
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Process webhook event
|
|
224
|
+
*
|
|
225
|
+
* @param body - Webhook request body
|
|
226
|
+
* @param headers - Webhook request headers
|
|
227
|
+
*/
|
|
228
|
+
async processWebhook(body, headers) {
|
|
229
|
+
if (!this.webhookHandler) {
|
|
230
|
+
throw new Error('Webhook handler not configured - provide webhookSecret in config');
|
|
231
|
+
}
|
|
232
|
+
this.logger.info('Processing webhook event');
|
|
233
|
+
const result = this.webhookHandler.parseWebhook(body, headers);
|
|
234
|
+
if (!result.valid || !result.payload) {
|
|
235
|
+
throw new Error('Invalid webhook signature or payload');
|
|
236
|
+
}
|
|
237
|
+
// Queue for processing
|
|
238
|
+
await this.queue.addMessage({
|
|
239
|
+
topic: result.topic,
|
|
240
|
+
payload: result.payload
|
|
241
|
+
});
|
|
242
|
+
this.logger.info('Webhook event queued', { topic: result.topic });
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Start automatic sync at configured interval
|
|
246
|
+
*/
|
|
247
|
+
startAutoSync() {
|
|
248
|
+
if (this.syncIntervalId) {
|
|
249
|
+
this.logger.warn('Auto-sync already running');
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
this.logger.info('Starting auto-sync', { interval: this.config.syncInterval });
|
|
253
|
+
this.syncIntervalId = setInterval(async () => {
|
|
254
|
+
await this.incrementalSync();
|
|
255
|
+
}, this.config.syncInterval);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Stop automatic sync
|
|
259
|
+
*/
|
|
260
|
+
stopAutoSync() {
|
|
261
|
+
if (this.syncIntervalId) {
|
|
262
|
+
clearInterval(this.syncIntervalId);
|
|
263
|
+
this.syncIntervalId = undefined;
|
|
264
|
+
this.logger.info('Auto-sync stopped');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Shutdown the service
|
|
269
|
+
*/
|
|
270
|
+
async shutdown() {
|
|
271
|
+
this.logger.info('Shutting down ContentfulSyncService');
|
|
272
|
+
this.stopAutoSync();
|
|
273
|
+
// Note: MessageQueue doesn't expose a close() method in current version
|
|
274
|
+
this.logger.info('ContentfulSyncService shutdown complete');
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.ContentfulSyncService = ContentfulSyncService;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ContentfulEntry as Entry, ContentfulAsset as Asset, ContentfulContentType as ContentType } from '@bernierllc/contentful-types';
|
|
2
|
+
import type { ContentStorage, SyncStateStorage } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* In-memory implementation of ContentStorage for testing
|
|
5
|
+
*/
|
|
6
|
+
export declare class InMemoryContentStorage implements ContentStorage {
|
|
7
|
+
private contentTypes;
|
|
8
|
+
private entries;
|
|
9
|
+
private assets;
|
|
10
|
+
storeContentTypes(contentTypes: ContentType[]): Promise<void>;
|
|
11
|
+
storeEntries(entries: Entry[]): Promise<void>;
|
|
12
|
+
storeAssets(assets: Asset[]): Promise<void>;
|
|
13
|
+
updateEntry(entry: Entry): Promise<void>;
|
|
14
|
+
updateAsset(asset: Asset): Promise<void>;
|
|
15
|
+
deleteEntry(entryId: string): Promise<void>;
|
|
16
|
+
deleteAsset(assetId: string): Promise<void>;
|
|
17
|
+
getEntry(entryId: string): Promise<Entry | null>;
|
|
18
|
+
getAsset(assetId: string): Promise<Asset | null>;
|
|
19
|
+
clearSpace(_spaceId: string): Promise<void>;
|
|
20
|
+
getContentTypeCount(): number;
|
|
21
|
+
getEntryCount(): number;
|
|
22
|
+
getAssetCount(): number;
|
|
23
|
+
getAllEntries(): Entry[];
|
|
24
|
+
getAllAssets(): Asset[];
|
|
25
|
+
getAllContentTypes(): ContentType[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* In-memory implementation of SyncStateStorage for testing
|
|
29
|
+
*/
|
|
30
|
+
export declare class InMemorySyncStateStorage implements SyncStateStorage {
|
|
31
|
+
private syncTokens;
|
|
32
|
+
getSyncToken(spaceId: string): Promise<string | null>;
|
|
33
|
+
setSyncToken(spaceId: string, token: string): Promise<void>;
|
|
34
|
+
clearSyncToken(spaceId: string): Promise<void>;
|
|
35
|
+
getAllTokens(): Map<string, string>;
|
|
36
|
+
clear(): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
This file is licensed to the client under a limited-use license.
|
|
6
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
7
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.InMemorySyncStateStorage = exports.InMemoryContentStorage = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* In-memory implementation of ContentStorage for testing
|
|
13
|
+
*/
|
|
14
|
+
class InMemoryContentStorage {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.contentTypes = new Map();
|
|
17
|
+
this.entries = new Map();
|
|
18
|
+
this.assets = new Map();
|
|
19
|
+
}
|
|
20
|
+
async storeContentTypes(contentTypes) {
|
|
21
|
+
for (const contentType of contentTypes) {
|
|
22
|
+
this.contentTypes.set(contentType.sys.id, contentType);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async storeEntries(entries) {
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
this.entries.set(entry.sys.id, entry);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async storeAssets(assets) {
|
|
31
|
+
for (const asset of assets) {
|
|
32
|
+
this.assets.set(asset.sys.id, asset);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async updateEntry(entry) {
|
|
36
|
+
this.entries.set(entry.sys.id, entry);
|
|
37
|
+
}
|
|
38
|
+
async updateAsset(asset) {
|
|
39
|
+
this.assets.set(asset.sys.id, asset);
|
|
40
|
+
}
|
|
41
|
+
async deleteEntry(entryId) {
|
|
42
|
+
this.entries.delete(entryId);
|
|
43
|
+
}
|
|
44
|
+
async deleteAsset(assetId) {
|
|
45
|
+
this.assets.delete(assetId);
|
|
46
|
+
}
|
|
47
|
+
async getEntry(entryId) {
|
|
48
|
+
return this.entries.get(entryId) || null;
|
|
49
|
+
}
|
|
50
|
+
async getAsset(assetId) {
|
|
51
|
+
return this.assets.get(assetId) || null;
|
|
52
|
+
}
|
|
53
|
+
async clearSpace(_spaceId) {
|
|
54
|
+
this.contentTypes.clear();
|
|
55
|
+
this.entries.clear();
|
|
56
|
+
this.assets.clear();
|
|
57
|
+
}
|
|
58
|
+
// Test helper methods
|
|
59
|
+
getContentTypeCount() {
|
|
60
|
+
return this.contentTypes.size;
|
|
61
|
+
}
|
|
62
|
+
getEntryCount() {
|
|
63
|
+
return this.entries.size;
|
|
64
|
+
}
|
|
65
|
+
getAssetCount() {
|
|
66
|
+
return this.assets.size;
|
|
67
|
+
}
|
|
68
|
+
getAllEntries() {
|
|
69
|
+
return Array.from(this.entries.values());
|
|
70
|
+
}
|
|
71
|
+
getAllAssets() {
|
|
72
|
+
return Array.from(this.assets.values());
|
|
73
|
+
}
|
|
74
|
+
getAllContentTypes() {
|
|
75
|
+
return Array.from(this.contentTypes.values());
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.InMemoryContentStorage = InMemoryContentStorage;
|
|
79
|
+
/**
|
|
80
|
+
* In-memory implementation of SyncStateStorage for testing
|
|
81
|
+
*/
|
|
82
|
+
class InMemorySyncStateStorage {
|
|
83
|
+
constructor() {
|
|
84
|
+
this.syncTokens = new Map();
|
|
85
|
+
}
|
|
86
|
+
async getSyncToken(spaceId) {
|
|
87
|
+
return this.syncTokens.get(spaceId) || null;
|
|
88
|
+
}
|
|
89
|
+
async setSyncToken(spaceId, token) {
|
|
90
|
+
this.syncTokens.set(spaceId, token);
|
|
91
|
+
}
|
|
92
|
+
async clearSyncToken(spaceId) {
|
|
93
|
+
this.syncTokens.delete(spaceId);
|
|
94
|
+
}
|
|
95
|
+
// Test helper methods
|
|
96
|
+
getAllTokens() {
|
|
97
|
+
return new Map(this.syncTokens);
|
|
98
|
+
}
|
|
99
|
+
clear() {
|
|
100
|
+
this.syncTokens.clear();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.InMemorySyncStateStorage = InMemorySyncStateStorage;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
This file is licensed to the client under a limited-use license.
|
|
6
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
7
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.InMemorySyncStateStorage = exports.InMemoryContentStorage = exports.ContentfulSyncService = void 0;
|
|
11
|
+
var contentful_sync_service_1 = require("./contentful-sync-service");
|
|
12
|
+
Object.defineProperty(exports, "ContentfulSyncService", { enumerable: true, get: function () { return contentful_sync_service_1.ContentfulSyncService; } });
|
|
13
|
+
var in_memory_storage_1 = require("./in-memory-storage");
|
|
14
|
+
Object.defineProperty(exports, "InMemoryContentStorage", { enumerable: true, get: function () { return in_memory_storage_1.InMemoryContentStorage; } });
|
|
15
|
+
Object.defineProperty(exports, "InMemorySyncStateStorage", { enumerable: true, get: function () { return in_memory_storage_1.InMemorySyncStateStorage; } });
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { ContentfulEntry as Entry, ContentfulAsset as Asset, ContentfulContentType as ContentType } from '@bernierllc/contentful-types';
|
|
2
|
+
/**
|
|
3
|
+
* Storage interface for synced content
|
|
4
|
+
*/
|
|
5
|
+
export interface ContentStorage {
|
|
6
|
+
/**
|
|
7
|
+
* Store content types
|
|
8
|
+
*/
|
|
9
|
+
storeContentTypes(contentTypes: ContentType[]): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Store entries
|
|
12
|
+
*/
|
|
13
|
+
storeEntries(entries: Entry[]): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Store assets
|
|
16
|
+
*/
|
|
17
|
+
storeAssets(assets: Asset[]): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Update a single entry
|
|
20
|
+
*/
|
|
21
|
+
updateEntry(entry: Entry): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Update a single asset
|
|
24
|
+
*/
|
|
25
|
+
updateAsset(asset: Asset): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Delete an entry by ID
|
|
28
|
+
*/
|
|
29
|
+
deleteEntry(entryId: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Delete an asset by ID
|
|
32
|
+
*/
|
|
33
|
+
deleteAsset(assetId: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Get an entry by ID
|
|
36
|
+
*/
|
|
37
|
+
getEntry(entryId: string): Promise<Entry | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Get an asset by ID
|
|
40
|
+
*/
|
|
41
|
+
getAsset(assetId: string): Promise<Asset | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Clear all content for a space
|
|
44
|
+
*/
|
|
45
|
+
clearSpace(spaceId: string): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Storage interface for sync state (tokens)
|
|
49
|
+
*/
|
|
50
|
+
export interface SyncStateStorage {
|
|
51
|
+
/**
|
|
52
|
+
* Get the sync token for a space
|
|
53
|
+
*/
|
|
54
|
+
getSyncToken(spaceId: string): Promise<string | null>;
|
|
55
|
+
/**
|
|
56
|
+
* Set the sync token for a space
|
|
57
|
+
*/
|
|
58
|
+
setSyncToken(spaceId: string, token: string): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Clear sync token for a space
|
|
61
|
+
*/
|
|
62
|
+
clearSyncToken(spaceId: string): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Configuration for ContentfulSyncService
|
|
66
|
+
*/
|
|
67
|
+
export interface SyncServiceConfig {
|
|
68
|
+
/**
|
|
69
|
+
* Contentful space ID
|
|
70
|
+
*/
|
|
71
|
+
spaceId: string;
|
|
72
|
+
/**
|
|
73
|
+
* Contentful environment ID
|
|
74
|
+
*/
|
|
75
|
+
environmentId: string;
|
|
76
|
+
/**
|
|
77
|
+
* Contentful CDA access token
|
|
78
|
+
*/
|
|
79
|
+
accessToken: string;
|
|
80
|
+
/**
|
|
81
|
+
* Content storage implementation
|
|
82
|
+
*/
|
|
83
|
+
contentStorage: ContentStorage;
|
|
84
|
+
/**
|
|
85
|
+
* Sync state storage implementation
|
|
86
|
+
*/
|
|
87
|
+
syncStateStorage: SyncStateStorage;
|
|
88
|
+
/**
|
|
89
|
+
* Webhook secret for validation (optional)
|
|
90
|
+
*/
|
|
91
|
+
webhookSecret?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Sync interval in milliseconds (default: 300000 = 5 minutes)
|
|
94
|
+
*/
|
|
95
|
+
syncInterval?: number;
|
|
96
|
+
/**
|
|
97
|
+
* Enable NeverHub integration (optional)
|
|
98
|
+
*/
|
|
99
|
+
neverhubEnabled?: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Sync statistics
|
|
103
|
+
*/
|
|
104
|
+
export interface SyncStats {
|
|
105
|
+
/**
|
|
106
|
+
* Total entries synced
|
|
107
|
+
*/
|
|
108
|
+
entriesSynced: number;
|
|
109
|
+
/**
|
|
110
|
+
* Total assets synced
|
|
111
|
+
*/
|
|
112
|
+
assetsSynced: number;
|
|
113
|
+
/**
|
|
114
|
+
* Total items deleted
|
|
115
|
+
*/
|
|
116
|
+
itemsDeleted: number;
|
|
117
|
+
/**
|
|
118
|
+
* Sync duration in milliseconds
|
|
119
|
+
*/
|
|
120
|
+
duration: number;
|
|
121
|
+
/**
|
|
122
|
+
* Sync timestamp
|
|
123
|
+
*/
|
|
124
|
+
timestamp: Date;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Sync result
|
|
128
|
+
*/
|
|
129
|
+
export interface SyncResult {
|
|
130
|
+
/**
|
|
131
|
+
* Whether the sync was successful
|
|
132
|
+
*/
|
|
133
|
+
success: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Sync statistics
|
|
136
|
+
*/
|
|
137
|
+
stats: SyncStats;
|
|
138
|
+
/**
|
|
139
|
+
* Error message if sync failed
|
|
140
|
+
*/
|
|
141
|
+
error?: string;
|
|
142
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
This file is licensed to the client under a limited-use license.
|
|
6
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
7
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bernierllc/contentful-sync-service",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Full export + incremental webhook sync to local storage for Contentful content",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"contentful",
|
|
7
|
+
"sync",
|
|
8
|
+
"service",
|
|
9
|
+
"ml-training",
|
|
10
|
+
"database",
|
|
11
|
+
"webhook"
|
|
12
|
+
],
|
|
13
|
+
"author": "Bernier LLC",
|
|
14
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"LICENSE.md",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@bernierllc/contentful-types": "^1.0.4",
|
|
24
|
+
"@bernierllc/contentful-export-adapter": "^1.0.2",
|
|
25
|
+
"@bernierllc/contentful-cda-client": "^1.0.2",
|
|
26
|
+
"@bernierllc/contentful-webhook-handler": "^1.0.4",
|
|
27
|
+
"@bernierllc/message-queue": "^1.0.2",
|
|
28
|
+
"@bernierllc/logger": "^1.0.1",
|
|
29
|
+
"@bernierllc/neverhub-adapter": "^0.1.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/jest": "^29.5.14",
|
|
33
|
+
"@types/node": "^22.10.1",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^8.15.0",
|
|
35
|
+
"@typescript-eslint/parser": "^8.15.0",
|
|
36
|
+
"eslint": "^9.15.0",
|
|
37
|
+
"jest": "^29.7.0",
|
|
38
|
+
"ts-jest": "^29.2.5",
|
|
39
|
+
"typescript": "^5.7.2"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"test": "jest --runInBand",
|
|
47
|
+
"test:run": "jest --runInBand",
|
|
48
|
+
"test:watch": "jest --watch",
|
|
49
|
+
"test:coverage": "jest --coverage --runInBand",
|
|
50
|
+
"lint": "eslint src --ext .ts"
|
|
51
|
+
}
|
|
52
|
+
}
|