@bernierllc/contentful-migration-service 1.6.1 → 1.6.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bernierllc/contentful-migration-service",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "Content model migration management with version control, rollback support, and migration history tracking",
5
5
  "keywords": [
6
6
  "contentful",
@@ -21,10 +21,10 @@
21
21
  ],
22
22
  "dependencies": {
23
23
  "contentful-migration": "^4.0.0",
24
- "@bernierllc/logger": "1.7.1",
25
- "@bernierllc/contentful-types": "1.5.0",
26
- "@bernierllc/neverhub-adapter": "0.4.1",
27
- "@bernierllc/contentful-cma-client": "1.3.1"
24
+ "@bernierllc/contentful-cma-client": "^1.3.2",
25
+ "@bernierllc/contentful-types": "^1.5.0",
26
+ "@bernierllc/logger": "^2.0.0",
27
+ "@bernierllc/neverhub-adapter": "^0.4.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/jest": "^29.5.14",
@@ -1,49 +0,0 @@
1
- import { ContentfulCMAClient } from '@bernierllc/contentful-cma-client';
2
- import { MigrationServiceConfig, MigrationOptions, MigrationResult, MigrationRecord, MigrationFunction, ValidationResult } from './types';
3
- /**
4
- * ContentfulMigrationService manages content model migrations with version control,
5
- * rollback support, and migration history tracking.
6
- */
7
- export declare class ContentfulMigrationService {
8
- private logger;
9
- private cmaClient;
10
- private config;
11
- private neverhub?;
12
- constructor(config: MigrationServiceConfig);
13
- /**
14
- * Initialize NeverHub integration if available
15
- */
16
- private initializeNeverHub;
17
- /**
18
- * Run a migration function
19
- */
20
- runMigration(migrationFn: MigrationFunction, options: MigrationOptions): Promise<MigrationResult>;
21
- /**
22
- * Get migration history
23
- */
24
- getMigrationHistory(): Promise<MigrationRecord[]>;
25
- /**
26
- * Get a specific migration by ID
27
- */
28
- getMigration(id: string): Promise<MigrationRecord | null>;
29
- /**
30
- * Check if a migration has been executed
31
- */
32
- hasExecutedMigration(id: string): Promise<boolean>;
33
- /**
34
- * Validate a migration function without executing
35
- */
36
- validateMigration(migrationFn: MigrationFunction, options: Pick<MigrationOptions, 'id' | 'name' | 'description'>): Promise<ValidationResult>;
37
- /**
38
- * Get pending migrations (not yet executed)
39
- */
40
- getPendingMigrations(migrationIds: string[]): Promise<string[]>;
41
- /**
42
- * Get the Contentful CMA client (for advanced operations)
43
- */
44
- getCMAClient(): ContentfulCMAClient;
45
- /**
46
- * Close connections and cleanup
47
- */
48
- close(): Promise<void>;
49
- }
@@ -1,243 +0,0 @@
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.ContentfulMigrationService = void 0;
11
- const contentful_migration_1 = require("contentful-migration");
12
- const contentful_cma_client_1 = require("@bernierllc/contentful-cma-client");
13
- const logger_1 = require("@bernierllc/logger");
14
- const neverhub_adapter_1 = require("@bernierllc/neverhub-adapter");
15
- /**
16
- * ContentfulMigrationService manages content model migrations with version control,
17
- * rollback support, and migration history tracking.
18
- */
19
- class ContentfulMigrationService {
20
- logger;
21
- cmaClient;
22
- config;
23
- neverhub;
24
- constructor(config) {
25
- this.config = {
26
- ...config,
27
- environmentId: config.environmentId || 'master',
28
- };
29
- this.logger = new logger_1.Logger({
30
- level: 2, // INFO level
31
- transports: [],
32
- context: {
33
- service: 'ContentfulMigrationService',
34
- version: '1.0.0',
35
- environment: process.env.NODE_ENV || 'development',
36
- },
37
- });
38
- this.cmaClient = new contentful_cma_client_1.ContentfulCMAClient({
39
- accessToken: config.accessToken,
40
- spaceId: config.spaceId,
41
- environmentId: this.config.environmentId,
42
- });
43
- this.initializeNeverHub();
44
- }
45
- /**
46
- * Initialize NeverHub integration if available
47
- */
48
- async initializeNeverHub() {
49
- try {
50
- if (await neverhub_adapter_1.NeverHubAdapter.detect()) {
51
- this.neverhub = new neverhub_adapter_1.NeverHubAdapter();
52
- await this.neverhub.register({
53
- type: 'contentful-migration-service',
54
- name: '@bernierllc/contentful-migration-service',
55
- version: '1.0.0',
56
- dependencies: [
57
- '@bernierllc/contentful-cma-client',
58
- '@bernierllc/contentful-types',
59
- ],
60
- capabilities: [
61
- {
62
- type: 'migration',
63
- name: 'contentful-migrations',
64
- version: '1.0.0',
65
- },
66
- ],
67
- });
68
- this.logger.info('NeverHub integration initialized');
69
- }
70
- }
71
- catch (error) {
72
- this.logger.warn('NeverHub integration not available', { error });
73
- }
74
- }
75
- /**
76
- * Run a migration function
77
- */
78
- async runMigration(migrationFn, options) {
79
- const startTime = Date.now();
80
- const { id, name, description, dryRun = false } = options;
81
- this.logger.info(`Starting migration: ${name}`, { id, dryRun });
82
- // Check if migration already executed
83
- const alreadyExecuted = await this.config.storage.hasMigration(id, this.config.spaceId, this.config.environmentId);
84
- if (alreadyExecuted && !dryRun) {
85
- this.logger.warn(`Migration ${id} already executed, skipping`);
86
- return {
87
- success: true,
88
- migrationId: id,
89
- duration: 0,
90
- dryRun: false,
91
- error: 'Migration already executed',
92
- };
93
- }
94
- // Create migration record
95
- const record = {
96
- id,
97
- name,
98
- description,
99
- executedAt: new Date(),
100
- executedBy: this.config.executedBy,
101
- status: 'running',
102
- spaceId: this.config.spaceId,
103
- environmentId: this.config.environmentId,
104
- dryRun,
105
- };
106
- await this.config.storage.saveMigration(record);
107
- try {
108
- // Run migration using contentful-migration
109
- await (0, contentful_migration_1.runMigration)({
110
- spaceId: this.config.spaceId,
111
- environmentId: this.config.environmentId,
112
- accessToken: this.config.accessToken,
113
- yes: !dryRun,
114
- migrationFunction: migrationFn,
115
- });
116
- const duration = Date.now() - startTime;
117
- // Update status
118
- await this.config.storage.updateMigrationStatus(id, 'completed', undefined, duration);
119
- this.logger.info(`Migration completed: ${name}`, { id, duration, dryRun });
120
- if (this.neverhub) {
121
- await this.neverhub.publishEvent({
122
- type: 'migration.completed',
123
- data: {
124
- migrationId: id,
125
- name,
126
- duration,
127
- dryRun,
128
- },
129
- });
130
- }
131
- return {
132
- success: true,
133
- migrationId: id,
134
- duration,
135
- dryRun,
136
- };
137
- }
138
- catch (error) {
139
- const duration = Date.now() - startTime;
140
- const errorMessage = error instanceof Error ? error.message : String(error);
141
- const errorObj = error instanceof Error ? error : new Error(String(error));
142
- await this.config.storage.updateMigrationStatus(id, 'failed', errorMessage, duration);
143
- this.logger.error(`Migration failed: ${name}`, errorObj, { migrationId: id });
144
- if (this.neverhub) {
145
- await this.neverhub.publishEvent({
146
- type: 'migration.failed',
147
- data: {
148
- migrationId: id,
149
- name,
150
- error: errorMessage,
151
- duration,
152
- },
153
- });
154
- }
155
- return {
156
- success: false,
157
- migrationId: id,
158
- duration,
159
- dryRun,
160
- error: errorMessage,
161
- };
162
- }
163
- }
164
- /**
165
- * Get migration history
166
- */
167
- async getMigrationHistory() {
168
- this.logger.debug('Fetching migration history');
169
- return this.config.storage.getMigrations(this.config.spaceId, this.config.environmentId);
170
- }
171
- /**
172
- * Get a specific migration by ID
173
- */
174
- async getMigration(id) {
175
- return this.config.storage.getMigration(id);
176
- }
177
- /**
178
- * Check if a migration has been executed
179
- */
180
- async hasExecutedMigration(id) {
181
- return this.config.storage.hasMigration(id, this.config.spaceId, this.config.environmentId);
182
- }
183
- /**
184
- * Validate a migration function without executing
185
- */
186
- async validateMigration(migrationFn, options) {
187
- this.logger.info('Validating migration', { id: options.id });
188
- try {
189
- // Run in dry-run mode for validation
190
- const result = await this.runMigration(migrationFn, {
191
- ...options,
192
- dryRun: true,
193
- });
194
- if (result.success) {
195
- return {
196
- valid: true,
197
- errors: [],
198
- warnings: [],
199
- };
200
- }
201
- return {
202
- valid: false,
203
- errors: result.error ? [result.error] : ['Unknown validation error'],
204
- warnings: [],
205
- };
206
- }
207
- catch (error) {
208
- const errorMessage = error instanceof Error ? error.message : String(error);
209
- return {
210
- valid: false,
211
- errors: [errorMessage],
212
- warnings: [],
213
- };
214
- }
215
- }
216
- /**
217
- * Get pending migrations (not yet executed)
218
- */
219
- async getPendingMigrations(migrationIds) {
220
- const pending = [];
221
- for (const id of migrationIds) {
222
- const executed = await this.hasExecutedMigration(id);
223
- if (!executed) {
224
- pending.push(id);
225
- }
226
- }
227
- return pending;
228
- }
229
- /**
230
- * Get the Contentful CMA client (for advanced operations)
231
- */
232
- getCMAClient() {
233
- return this.cmaClient;
234
- }
235
- /**
236
- * Close connections and cleanup
237
- */
238
- async close() {
239
- this.logger.info('Closing ContentfulMigrationService');
240
- // No cleanup needed for current implementation
241
- }
242
- }
243
- exports.ContentfulMigrationService = ContentfulMigrationService;
@@ -1,5 +0,0 @@
1
- export declare class NeverHubAdapter {
2
- static detect(): Promise<boolean>;
3
- register(): Promise<void>;
4
- publishEvent(): Promise<void>;
5
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NeverHubAdapter = void 0;
4
- class NeverHubAdapter {
5
- static async detect() {
6
- return false;
7
- }
8
- async register() {
9
- return;
10
- }
11
- async publishEvent() {
12
- return;
13
- }
14
- }
15
- exports.NeverHubAdapter = NeverHubAdapter;
package/dist/errors.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export type ContentfulMigrationServiceErrorCode = 'CONTENTFUL_MIGRATION_SERVICE_ERROR' | 'INVALID_INPUT' | 'OPERATION_FAILED';
2
- export interface ContentfulMigrationServiceErrorOptions {
3
- cause?: Error;
4
- code?: ContentfulMigrationServiceErrorCode;
5
- context?: Record<string, unknown>;
6
- }
7
- export declare class ContentfulMigrationServiceError extends Error {
8
- readonly code: ContentfulMigrationServiceErrorCode;
9
- readonly context?: Record<string, unknown>;
10
- constructor(message: string, options?: ContentfulMigrationServiceErrorOptions);
11
- }
package/dist/errors.js DELETED
@@ -1,24 +0,0 @@
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.ContentfulMigrationServiceError = void 0;
11
- class ContentfulMigrationServiceError extends Error {
12
- code;
13
- context;
14
- constructor(message, options) {
15
- super(message, options?.cause ? { cause: options.cause } : undefined);
16
- this.name = 'ContentfulMigrationServiceError';
17
- this.code = options?.code ?? 'CONTENTFUL_MIGRATION_SERVICE_ERROR';
18
- if (options?.context !== undefined) {
19
- this.context = options.context;
20
- }
21
- Error.captureStackTrace?.(this, this.constructor);
22
- }
23
- }
24
- exports.ContentfulMigrationServiceError = ContentfulMigrationServiceError;
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export { ContentfulMigrationService } from './ContentfulMigrationService';
2
- export { ContentfulMigrationServiceError, type ContentfulMigrationServiceErrorCode, type ContentfulMigrationServiceErrorOptions } from './errors';
3
- export { InMemoryMigrationStorage } from './storage/InMemoryMigrationStorage';
4
- export type { MigrationRecord, MigrationStorage, MigrationServiceConfig, MigrationOptions, MigrationResult, MigrationFunction, ValidationResult, } from './types';
package/dist/index.js DELETED
@@ -1,16 +0,0 @@
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.InMemoryMigrationStorage = exports.ContentfulMigrationServiceError = exports.ContentfulMigrationService = void 0;
11
- var ContentfulMigrationService_1 = require("./ContentfulMigrationService");
12
- Object.defineProperty(exports, "ContentfulMigrationService", { enumerable: true, get: function () { return ContentfulMigrationService_1.ContentfulMigrationService; } });
13
- var errors_1 = require("./errors");
14
- Object.defineProperty(exports, "ContentfulMigrationServiceError", { enumerable: true, get: function () { return errors_1.ContentfulMigrationServiceError; } });
15
- var InMemoryMigrationStorage_1 = require("./storage/InMemoryMigrationStorage");
16
- Object.defineProperty(exports, "InMemoryMigrationStorage", { enumerable: true, get: function () { return InMemoryMigrationStorage_1.InMemoryMigrationStorage; } });
@@ -1,20 +0,0 @@
1
- import { MigrationStorage, MigrationRecord } from '../types';
2
- /**
3
- * In-memory implementation of MigrationStorage for testing and development
4
- */
5
- export declare class InMemoryMigrationStorage implements MigrationStorage {
6
- private migrations;
7
- saveMigration(record: MigrationRecord): Promise<void>;
8
- getMigration(id: string): Promise<MigrationRecord | null>;
9
- getMigrations(spaceId: string, environmentId: string): Promise<MigrationRecord[]>;
10
- hasMigration(id: string, spaceId: string, environmentId: string): Promise<boolean>;
11
- updateMigrationStatus(id: string, status: MigrationRecord['status'], error?: string, duration?: number): Promise<void>;
12
- /**
13
- * Clear all migrations (for testing)
14
- */
15
- clear(): void;
16
- /**
17
- * Get count of migrations (for testing)
18
- */
19
- count(): number;
20
- }
@@ -1,61 +0,0 @@
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.InMemoryMigrationStorage = void 0;
11
- /**
12
- * In-memory implementation of MigrationStorage for testing and development
13
- */
14
- class InMemoryMigrationStorage {
15
- migrations = new Map();
16
- async saveMigration(record) {
17
- this.migrations.set(record.id, { ...record });
18
- }
19
- async getMigration(id) {
20
- return this.migrations.get(id) || null;
21
- }
22
- async getMigrations(spaceId, environmentId) {
23
- return Array.from(this.migrations.values())
24
- .filter(m => m.spaceId === spaceId && m.environmentId === environmentId)
25
- .sort((a, b) => b.executedAt.getTime() - a.executedAt.getTime());
26
- }
27
- async hasMigration(id, spaceId, environmentId) {
28
- const migration = this.migrations.get(id);
29
- return !!(migration &&
30
- migration.spaceId === spaceId &&
31
- migration.environmentId === environmentId &&
32
- migration.status === 'completed');
33
- }
34
- async updateMigrationStatus(id, status, error, duration) {
35
- const migration = this.migrations.get(id);
36
- if (!migration) {
37
- throw new Error(`Migration ${id} not found`);
38
- }
39
- migration.status = status;
40
- if (error !== undefined) {
41
- migration.error = error;
42
- }
43
- if (duration !== undefined) {
44
- migration.duration = duration;
45
- }
46
- this.migrations.set(id, migration);
47
- }
48
- /**
49
- * Clear all migrations (for testing)
50
- */
51
- clear() {
52
- this.migrations.clear();
53
- }
54
- /**
55
- * Get count of migrations (for testing)
56
- */
57
- count() {
58
- return this.migrations.size;
59
- }
60
- }
61
- exports.InMemoryMigrationStorage = InMemoryMigrationStorage;
package/dist/types.d.ts DELETED
@@ -1,117 +0,0 @@
1
- /**
2
- * Migration record stored in persistent storage
3
- */
4
- export interface MigrationRecord {
5
- id: string;
6
- name: string;
7
- description?: string;
8
- executedAt: Date;
9
- executedBy?: string;
10
- status: 'pending' | 'running' | 'completed' | 'failed' | 'rolled_back';
11
- spaceId: string;
12
- environmentId: string;
13
- dryRun: boolean;
14
- duration?: number;
15
- error?: string;
16
- checksum?: string;
17
- }
18
- /**
19
- * Abstract storage interface for migration history tracking
20
- * Allows users to provide their own storage implementation
21
- */
22
- export interface MigrationStorage {
23
- /**
24
- * Save a migration record
25
- */
26
- saveMigration(record: MigrationRecord): Promise<void>;
27
- /**
28
- * Get a migration by ID
29
- */
30
- getMigration(id: string): Promise<MigrationRecord | null>;
31
- /**
32
- * Get all migrations for a space/environment
33
- */
34
- getMigrations(spaceId: string, environmentId: string): Promise<MigrationRecord[]>;
35
- /**
36
- * Check if a migration has been executed
37
- */
38
- hasMigration(id: string, spaceId: string, environmentId: string): Promise<boolean>;
39
- /**
40
- * Update migration status
41
- */
42
- updateMigrationStatus(id: string, status: MigrationRecord['status'], error?: string, duration?: number): Promise<void>;
43
- }
44
- /**
45
- * Configuration for ContentfulMigrationService
46
- */
47
- export interface MigrationServiceConfig {
48
- /**
49
- * Contentful space ID
50
- */
51
- spaceId: string;
52
- /**
53
- * Contentful environment ID (default: 'master')
54
- */
55
- environmentId?: string;
56
- /**
57
- * Contentful CMA access token
58
- */
59
- accessToken: string;
60
- /**
61
- * Storage implementation for migration history
62
- */
63
- storage: MigrationStorage;
64
- /**
65
- * Optional identifier for who is executing migrations
66
- */
67
- executedBy?: string;
68
- }
69
- /**
70
- * Options for running a migration
71
- */
72
- export interface MigrationOptions {
73
- /**
74
- * Migration ID (for tracking)
75
- */
76
- id: string;
77
- /**
78
- * Human-readable name
79
- */
80
- name: string;
81
- /**
82
- * Optional description
83
- */
84
- description?: string;
85
- /**
86
- * Run in dry-run mode (validation only)
87
- */
88
- dryRun?: boolean;
89
- /**
90
- * Timeout in milliseconds
91
- */
92
- timeout?: number;
93
- }
94
- /**
95
- * Result of migration execution
96
- */
97
- export interface MigrationResult {
98
- success: boolean;
99
- migrationId: string;
100
- duration: number;
101
- dryRun: boolean;
102
- error?: string;
103
- }
104
- /**
105
- * Migration function type
106
- * The migration parameter is the Contentful migration context object
107
- * from the contentful-migration library (typed as any due to external library)
108
- */
109
- export type MigrationFunction = (migration: any) => void;
110
- /**
111
- * Validation result for migration
112
- */
113
- export interface ValidationResult {
114
- valid: boolean;
115
- errors: string[];
116
- warnings: string[];
117
- }
package/dist/types.js DELETED
@@ -1,9 +0,0 @@
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 });