@bernierllc/content-workflow-schedule-step 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,366 @@
1
+ # @bernierllc/content-workflow-schedule-step
2
+
3
+ Scheduling workflow step for content publishing with immediate and scheduled execution support.
4
+
5
+ ## Features
6
+
7
+ - **Immediate Publishing**: Execute content publishing immediately
8
+ - **Scheduled Publishing**: Schedule content for future publishing
9
+ - **Constraint Validation**: Enforce minimum and maximum scheduling delays
10
+ - **Multi-Platform Support**: Schedule across multiple platforms
11
+ - **Timezone Support**: Handle timezone conversions
12
+ - **Job Management**: Cancel and reschedule jobs
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @bernierllc/content-workflow-schedule-step
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### Basic Setup
23
+
24
+ ```typescript
25
+ import { ScheduleStep } from '@bernierllc/content-workflow-schedule-step';
26
+ import { SchedulerService } from '@bernierllc/scheduler-service';
27
+ import { Logger } from '@bernierllc/logger';
28
+
29
+ // Initialize dependencies
30
+ const scheduler = new SchedulerService({
31
+ maxConcurrentJobs: 10,
32
+ defaultTimezone: 'UTC',
33
+ // ... other config
34
+ });
35
+
36
+ const logger = new Logger({ serviceName: 'workflow' });
37
+
38
+ // Create schedule step
39
+ const scheduleStep = new ScheduleStep(scheduler, logger);
40
+ ```
41
+
42
+ ### Immediate Publishing
43
+
44
+ ```typescript
45
+ import type { WorkflowStepConfig, WorkflowContext } from '@bernierllc/content-workflow-schedule-step';
46
+
47
+ const config: WorkflowStepConfig = {
48
+ id: 'schedule',
49
+ name: 'Schedule Step',
50
+ type: 'schedule',
51
+ scheduleConfig: {
52
+ allowImmediate: true
53
+ }
54
+ };
55
+
56
+ const context: WorkflowContext = {
57
+ content: {
58
+ id: 'article-123',
59
+ type: 'article',
60
+ title: 'My Article',
61
+ data: { body: 'Content here' }
62
+ },
63
+ variables: new Map(),
64
+ userId: 'user-123'
65
+ };
66
+
67
+ const result = await scheduleStep.execute(config, context);
68
+
69
+ if (result.success) {
70
+ console.log('Scheduled:', result.data);
71
+ // {
72
+ // scheduledFor: Date,
73
+ // jobId: 'job-123',
74
+ // immediate: true
75
+ // }
76
+ }
77
+ ```
78
+
79
+ ### Scheduled Publishing
80
+
81
+ ```typescript
82
+ const futureTime = new Date(Date.now() + 2 * 60 * 60 * 1000); // 2 hours from now
83
+
84
+ const config: WorkflowStepConfig = {
85
+ id: 'schedule',
86
+ name: 'Schedule Step',
87
+ type: 'schedule',
88
+ scheduleConfig: {
89
+ allowImmediate: false,
90
+ minDelayMinutes: 5,
91
+ maxDelayDays: 30,
92
+ timezone: 'America/New_York'
93
+ }
94
+ };
95
+
96
+ const context: WorkflowContext = {
97
+ content: {
98
+ id: 'article-123',
99
+ type: 'article',
100
+ data: { body: 'Content' }
101
+ },
102
+ variables: new Map([
103
+ ['scheduledTime', futureTime],
104
+ ['platforms', ['twitter', 'facebook']]
105
+ ]),
106
+ userId: 'user-123'
107
+ };
108
+
109
+ const result = await scheduleStep.execute(config, context);
110
+
111
+ if (result.success) {
112
+ console.log('Scheduled for:', result.data?.scheduledFor);
113
+ console.log('Job ID:', result.data?.jobId);
114
+ console.log('Platforms:', result.data?.platforms);
115
+ }
116
+ ```
117
+
118
+ ### Multi-Platform Scheduling
119
+
120
+ ```typescript
121
+ const context: WorkflowContext = {
122
+ content: {
123
+ id: 'article-123',
124
+ type: 'article',
125
+ data: {}
126
+ },
127
+ variables: new Map([
128
+ ['scheduledTime', new Date('2025-12-25T10:00:00Z')],
129
+ ['platforms', ['twitter', 'facebook', 'linkedin']]
130
+ ]),
131
+ userId: 'user-123'
132
+ };
133
+
134
+ const result = await scheduleStep.execute(config, context);
135
+ // Job will be created for all three platforms
136
+ ```
137
+
138
+ ### Configuration Validation
139
+
140
+ ```typescript
141
+ const config: WorkflowStepConfig = {
142
+ id: 'schedule',
143
+ name: 'Schedule Step',
144
+ type: 'schedule',
145
+ scheduleConfig: {
146
+ minDelayMinutes: 30,
147
+ maxDelayDays: 7,
148
+ timezone: 'Europe/London'
149
+ }
150
+ };
151
+
152
+ const validation = scheduleStep.validate(config);
153
+
154
+ if (!validation.valid) {
155
+ console.error('Configuration errors:', validation.errors);
156
+ }
157
+ ```
158
+
159
+ ### Job Management
160
+
161
+ #### Cancel a Scheduled Job
162
+
163
+ ```typescript
164
+ const cancelled = await scheduleStep.cancelScheduledJob('job-123');
165
+
166
+ if (cancelled) {
167
+ console.log('Job cancelled successfully');
168
+ } else {
169
+ console.error('Failed to cancel job');
170
+ }
171
+ ```
172
+
173
+ #### Reschedule a Job
174
+
175
+ ```typescript
176
+ const newTime = new Date(Date.now() + 4 * 60 * 60 * 1000); // 4 hours from now
177
+
178
+ const result = await scheduleStep.rescheduleJob('job-123', newTime, {
179
+ minDelayMinutes: 5,
180
+ timezone: 'America/New_York'
181
+ });
182
+
183
+ if (result.success) {
184
+ console.log('New job ID:', result.data?.jobId);
185
+ console.log('New scheduled time:', result.data?.scheduledFor);
186
+ }
187
+ ```
188
+
189
+ ## API Reference
190
+
191
+ ### ScheduleStep
192
+
193
+ Main workflow step class for scheduling content.
194
+
195
+ #### Properties
196
+
197
+ - `id: string` - Step identifier ('schedule-step')
198
+ - `type: string` - Step type ('schedule')
199
+
200
+ #### Methods
201
+
202
+ ##### execute(config, context)
203
+
204
+ Execute the schedule step.
205
+
206
+ **Parameters:**
207
+ - `config: WorkflowStepConfig` - Step configuration
208
+ - `context: WorkflowContext` - Workflow execution context
209
+
210
+ **Returns:** `Promise<WorkflowStepExecutionResult>`
211
+
212
+ ##### validate(config)
213
+
214
+ Validate step configuration.
215
+
216
+ **Parameters:**
217
+ - `config: WorkflowStepConfig` - Configuration to validate
218
+
219
+ **Returns:** `ValidationResult`
220
+
221
+ ##### cancelScheduledJob(jobId)
222
+
223
+ Cancel a scheduled job.
224
+
225
+ **Parameters:**
226
+ - `jobId: string` - Job identifier
227
+
228
+ **Returns:** `Promise<boolean>`
229
+
230
+ ##### rescheduleJob(jobId, newScheduledTime, scheduleConfig)
231
+
232
+ Reschedule an existing job.
233
+
234
+ **Parameters:**
235
+ - `jobId: string` - Job identifier
236
+ - `newScheduledTime: Date` - New scheduled time
237
+ - `scheduleConfig: ScheduleConfig` - Schedule constraints
238
+
239
+ **Returns:** `Promise<WorkflowStepExecutionResult>`
240
+
241
+ ### Types
242
+
243
+ #### ScheduleConfig
244
+
245
+ ```typescript
246
+ interface ScheduleConfig {
247
+ allowImmediate?: boolean;
248
+ minDelayMinutes?: number;
249
+ maxDelayDays?: number;
250
+ timezone?: string;
251
+ }
252
+ ```
253
+
254
+ #### ScheduleResult
255
+
256
+ ```typescript
257
+ interface ScheduleResult {
258
+ scheduledFor: Date;
259
+ jobId: string;
260
+ immediate: boolean;
261
+ platforms?: string[];
262
+ }
263
+ ```
264
+
265
+ #### WorkflowContext
266
+
267
+ ```typescript
268
+ interface WorkflowContext {
269
+ content: WorkflowContentItem;
270
+ variables: Map<string, any>;
271
+ userId?: string;
272
+ metadata?: Record<string, any>;
273
+ }
274
+ ```
275
+
276
+ ## Validation Functions
277
+
278
+ ### validateScheduleConfig(config)
279
+
280
+ Validate schedule configuration.
281
+
282
+ ```typescript
283
+ import { validateScheduleConfig } from '@bernierllc/content-workflow-schedule-step';
284
+
285
+ const result = validateScheduleConfig({
286
+ id: 'schedule',
287
+ name: 'Schedule',
288
+ type: 'schedule',
289
+ scheduleConfig: {
290
+ minDelayMinutes: 5,
291
+ maxDelayDays: 30
292
+ }
293
+ });
294
+ ```
295
+
296
+ ### validateScheduledTime(scheduledTime, config)
297
+
298
+ Validate scheduled time against constraints.
299
+
300
+ ```typescript
301
+ import { validateScheduledTime } from '@bernierllc/content-workflow-schedule-step';
302
+
303
+ const futureTime = new Date(Date.now() + 60 * 60 * 1000);
304
+
305
+ const result = validateScheduledTime(futureTime, {
306
+ minDelayMinutes: 5,
307
+ maxDelayDays: 7
308
+ });
309
+ ```
310
+
311
+ ### convertToTimezone(date, timezone)
312
+
313
+ Convert date to specific timezone.
314
+
315
+ ```typescript
316
+ import { convertToTimezone } from '@bernierllc/content-workflow-schedule-step';
317
+
318
+ const date = new Date('2025-12-25T10:00:00Z');
319
+ const converted = convertToTimezone(date, 'America/New_York');
320
+ ```
321
+
322
+ ## Error Handling
323
+
324
+ The schedule step returns errors in a structured format:
325
+
326
+ ```typescript
327
+ const result = await scheduleStep.execute(config, context);
328
+
329
+ if (!result.success) {
330
+ console.error('Error:', result.error);
331
+ // Possible errors:
332
+ // - "Scheduled time is required when immediate publishing is not allowed"
333
+ // - "Scheduled time cannot be in the past"
334
+ // - "Scheduled time must be at least X minutes in the future"
335
+ // - "Scheduled time cannot be more than X days in the future"
336
+ }
337
+ ```
338
+
339
+ ## Integration with Scheduler Service
340
+
341
+ The schedule step integrates with `@bernierllc/scheduler-service` to create jobs:
342
+
343
+ - Job type: `CONTENT_PUBLISH`
344
+ - Schedule type: `ONCE`
345
+ - Retry policy: 3 attempts with 5 second delay
346
+ - Tags: `['content-publish', 'workflow']`
347
+
348
+ ## Best Practices
349
+
350
+ 1. **Always validate configuration** before using in production
351
+ 2. **Set reasonable constraints** (min/max delays) based on your use case
352
+ 3. **Handle timezone conversions** explicitly for international audiences
353
+ 4. **Monitor scheduled jobs** using the scheduler service
354
+ 5. **Cancel jobs** when content is deleted or workflows are cancelled
355
+
356
+ ## Testing
357
+
358
+ ```bash
359
+ npm test # Run all tests
360
+ npm run test:coverage # Run with coverage
361
+ npm run test:watch # Watch mode
362
+ ```
363
+
364
+ ## License
365
+
366
+ Copyright (c) 2025 Bernier LLC. See LICENSE for details.
@@ -0,0 +1,4 @@
1
+ export { ScheduleStep } from './schedule-step';
2
+ export type { ScheduleConfig, WorkflowStepConfig, WorkflowContentItem, WorkflowContext, ScheduleResult, WorkflowStepExecutionResult, ValidationResult, IWorkflowStep } from './types';
3
+ export { validateScheduleConfig, validateScheduledTime, convertToTimezone } from './validation';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,2BAA2B,EAC3B,gBAAgB,EAChB,aAAa,EACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
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.convertToTimezone = exports.validateScheduledTime = exports.validateScheduleConfig = exports.ScheduleStep = void 0;
11
+ // Main exports
12
+ var schedule_step_1 = require("./schedule-step");
13
+ Object.defineProperty(exports, "ScheduleStep", { enumerable: true, get: function () { return schedule_step_1.ScheduleStep; } });
14
+ // Validation exports
15
+ var validation_1 = require("./validation");
16
+ Object.defineProperty(exports, "validateScheduleConfig", { enumerable: true, get: function () { return validation_1.validateScheduleConfig; } });
17
+ Object.defineProperty(exports, "validateScheduledTime", { enumerable: true, get: function () { return validation_1.validateScheduledTime; } });
18
+ Object.defineProperty(exports, "convertToTimezone", { enumerable: true, get: function () { return validation_1.convertToTimezone; } });
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;EAME;;;AAEF,eAAe;AACf,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AAcrB,qBAAqB;AACrB,2CAIsB;AAHpB,oHAAA,sBAAsB,OAAA;AACtB,mHAAA,qBAAqB,OAAA;AACrB,+GAAA,iBAAiB,OAAA"}
@@ -0,0 +1,35 @@
1
+ import { SchedulerService } from '@bernierllc/scheduler-service';
2
+ import { Logger } from '@bernierllc/logger';
3
+ import type { IWorkflowStep, WorkflowStepConfig, WorkflowContext, WorkflowStepExecutionResult, ValidationResult, ScheduleConfig } from './types';
4
+ /**
5
+ * Schedule step for content workflow
6
+ * Handles immediate and scheduled publishing
7
+ */
8
+ export declare class ScheduleStep implements IWorkflowStep {
9
+ readonly id = "schedule-step";
10
+ readonly type = "schedule";
11
+ private scheduler;
12
+ private logger;
13
+ constructor(scheduler: SchedulerService, logger?: Logger);
14
+ /**
15
+ * Execute the schedule step
16
+ */
17
+ execute(config: WorkflowStepConfig, context: WorkflowContext): Promise<WorkflowStepExecutionResult>;
18
+ /**
19
+ * Validate step configuration
20
+ */
21
+ validate(config: WorkflowStepConfig): ValidationResult;
22
+ /**
23
+ * Create scheduled job in scheduler service
24
+ */
25
+ private createScheduledJob;
26
+ /**
27
+ * Cancel a scheduled job
28
+ */
29
+ cancelScheduledJob(jobId: string): Promise<boolean>;
30
+ /**
31
+ * Reschedule an existing job
32
+ */
33
+ rescheduleJob(jobId: string, newScheduledTime: Date, scheduleConfig: ScheduleConfig): Promise<WorkflowStepExecutionResult>;
34
+ }
35
+ //# sourceMappingURL=schedule-step.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule-step.d.ts","sourceRoot":"","sources":["../src/schedule-step.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAoC,MAAM,+BAA+B,CAAC;AACnG,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,2BAA2B,EAC3B,gBAAgB,EAEhB,cAAc,EACf,MAAM,SAAS,CAAC;AAGjB;;;GAGG;AACH,qBAAa,YAAa,YAAW,aAAa;IAChD,QAAQ,CAAC,EAAE,mBAAmB;IAC9B,QAAQ,CAAC,IAAI,cAAc;IAE3B,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,MAAM,CAAS;gBAEX,SAAS,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,MAAM;IASxD;;OAEG;IACG,OAAO,CACX,MAAM,EAAE,kBAAkB,EAC1B,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,2BAA2B,CAAC;IA6EvC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,kBAAkB,GAAG,gBAAgB;IAItD;;OAEG;YACW,kBAAkB;IAgChC;;OAEG;IACG,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAYzD;;OAEG;IACG,aAAa,CACjB,KAAK,EAAE,MAAM,EACb,gBAAgB,EAAE,IAAI,EACtB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,2BAA2B,CAAC;CA+DxC"}
@@ -0,0 +1,196 @@
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.ScheduleStep = void 0;
11
+ const scheduler_service_1 = require("@bernierllc/scheduler-service");
12
+ const logger_1 = require("@bernierllc/logger");
13
+ const validation_1 = require("./validation");
14
+ /**
15
+ * Schedule step for content workflow
16
+ * Handles immediate and scheduled publishing
17
+ */
18
+ class ScheduleStep {
19
+ constructor(scheduler, logger) {
20
+ this.id = 'schedule-step';
21
+ this.type = 'schedule';
22
+ this.scheduler = scheduler;
23
+ this.logger = logger || new logger_1.Logger({
24
+ level: 0,
25
+ transports: [],
26
+ context: { service: 'schedule-step', version: '1.0.0', environment: 'production' }
27
+ });
28
+ }
29
+ /**
30
+ * Execute the schedule step
31
+ */
32
+ async execute(config, context) {
33
+ try {
34
+ this.logger.info('Executing schedule step', {
35
+ contentId: context.content.id,
36
+ stepConfig: config
37
+ });
38
+ const scheduleConfig = config.scheduleConfig || {};
39
+ const scheduledTime = context.variables.get('scheduledTime');
40
+ const platforms = context.variables.get('platforms');
41
+ // Validate scheduled time against constraints
42
+ const timeValidation = (0, validation_1.validateScheduledTime)(scheduledTime, scheduleConfig);
43
+ if (!timeValidation.valid) {
44
+ const errorMsg = `Invalid scheduled time: ${timeValidation.errors.join('; ')}`;
45
+ this.logger.error(errorMsg, undefined, {
46
+ contentId: context.content.id,
47
+ errors: timeValidation.errors
48
+ });
49
+ return {
50
+ success: false,
51
+ error: timeValidation.errors.join('; ')
52
+ };
53
+ }
54
+ // Determine if this is immediate execution
55
+ const now = new Date();
56
+ const immediate = !scheduledTime || scheduledTime <= now;
57
+ // Use scheduled time or current time
58
+ const executionTime = scheduledTime || now;
59
+ // Convert to timezone if specified
60
+ const timezone = scheduleConfig.timezone || 'UTC';
61
+ // Create job in scheduler service
62
+ const jobId = await this.createScheduledJob(context.content.id, executionTime, immediate, timezone, platforms);
63
+ const result = {
64
+ scheduledFor: executionTime,
65
+ jobId,
66
+ immediate,
67
+ ...(platforms && { platforms })
68
+ };
69
+ this.logger.info('Schedule step completed', {
70
+ contentId: context.content.id,
71
+ result
72
+ });
73
+ return {
74
+ success: true,
75
+ data: result,
76
+ metadata: {
77
+ timezone,
78
+ createdAt: new Date()
79
+ }
80
+ };
81
+ }
82
+ catch (error) {
83
+ const errorMsg = error instanceof Error ? error.message : String(error);
84
+ this.logger.error(`Schedule step execution failed: ${errorMsg}`, undefined, {
85
+ contentId: context.content.id
86
+ });
87
+ return {
88
+ success: false,
89
+ error: error instanceof Error ? error.message : 'Unknown error during scheduling'
90
+ };
91
+ }
92
+ }
93
+ /**
94
+ * Validate step configuration
95
+ */
96
+ validate(config) {
97
+ return (0, validation_1.validateScheduleConfig)(config);
98
+ }
99
+ /**
100
+ * Create scheduled job in scheduler service
101
+ */
102
+ async createScheduledJob(contentId, scheduledTime, immediate, timezone, platforms) {
103
+ const jobConfig = {
104
+ name: `content-publish-${contentId}`,
105
+ type: scheduler_service_1.JobType.CONTENT_PUBLISH,
106
+ schedule: {
107
+ type: scheduler_service_1.ScheduleType.ONCE,
108
+ publishAt: scheduledTime,
109
+ timezone
110
+ },
111
+ payload: {
112
+ contentId,
113
+ immediate,
114
+ platforms: platforms || [],
115
+ scheduledAt: new Date()
116
+ },
117
+ options: {
118
+ retryAttempts: 3,
119
+ retryDelay: 5000,
120
+ tags: ['content-publish', 'workflow']
121
+ }
122
+ };
123
+ const job = await this.scheduler.scheduleJob(jobConfig);
124
+ return job.id;
125
+ }
126
+ /**
127
+ * Cancel a scheduled job
128
+ */
129
+ async cancelScheduledJob(jobId) {
130
+ try {
131
+ await this.scheduler.cancelJob(jobId);
132
+ this.logger.info('Scheduled job cancelled', { jobId });
133
+ return true;
134
+ }
135
+ catch (error) {
136
+ const errorMsg = error instanceof Error ? error.message : String(error);
137
+ this.logger.error(`Failed to cancel scheduled job: ${errorMsg}`, undefined, { jobId });
138
+ return false;
139
+ }
140
+ }
141
+ /**
142
+ * Reschedule an existing job
143
+ */
144
+ async rescheduleJob(jobId, newScheduledTime, scheduleConfig) {
145
+ try {
146
+ // Validate new scheduled time
147
+ const timeValidation = (0, validation_1.validateScheduledTime)(newScheduledTime, scheduleConfig);
148
+ if (!timeValidation.valid) {
149
+ return {
150
+ success: false,
151
+ error: timeValidation.errors.join('; ')
152
+ };
153
+ }
154
+ // Get existing job
155
+ const existingJob = await this.scheduler.getJob(jobId);
156
+ if (!existingJob) {
157
+ return {
158
+ success: false,
159
+ error: `Job not found: ${jobId}`
160
+ };
161
+ }
162
+ // Cancel existing job
163
+ await this.scheduler.cancelJob(jobId);
164
+ // Create new job with updated schedule
165
+ const timezone = scheduleConfig.timezone || 'UTC';
166
+ const immediate = newScheduledTime <= new Date();
167
+ const newJobId = await this.createScheduledJob(existingJob.payload.contentId, newScheduledTime, immediate, timezone, existingJob.payload.platforms);
168
+ const existingPlatforms = existingJob.payload.platforms;
169
+ const result = {
170
+ scheduledFor: newScheduledTime,
171
+ jobId: newJobId,
172
+ immediate,
173
+ ...(existingPlatforms && { platforms: existingPlatforms })
174
+ };
175
+ this.logger.info('Job rescheduled', {
176
+ oldJobId: jobId,
177
+ newJobId,
178
+ newScheduledTime
179
+ });
180
+ return {
181
+ success: true,
182
+ data: result
183
+ };
184
+ }
185
+ catch (error) {
186
+ const errorMsg = error instanceof Error ? error.message : String(error);
187
+ this.logger.error(`Failed to reschedule job: ${errorMsg}`, undefined, { jobId });
188
+ return {
189
+ success: false,
190
+ error: `Failed to reschedule job: ${errorMsg}`
191
+ };
192
+ }
193
+ }
194
+ }
195
+ exports.ScheduleStep = ScheduleStep;
196
+ //# sourceMappingURL=schedule-step.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule-step.js","sourceRoot":"","sources":["../src/schedule-step.ts"],"names":[],"mappings":";AAAA;;;;;;EAME;;;AAEF,qEAAmG;AACnG,+CAA4C;AAU5C,6CAA6E;AAE7E;;;GAGG;AACH,MAAa,YAAY;IAOvB,YAAY,SAA2B,EAAE,MAAe;QAN/C,OAAE,GAAG,eAAe,CAAC;QACrB,SAAI,GAAG,UAAU,CAAC;QAMzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,eAAM,CAAC;YACjC,KAAK,EAAE,CAAC;YACR,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE;SACnF,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CACX,MAA0B,EAC1B,OAAwB;QAExB,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,yBAAyB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aACjB,CAAC,CAAC;YAEH,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,MAAM;aACb,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,QAAQ,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACxE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,QAAQ,EAAE,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YAEjF,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,6BAA6B,QAAQ,EAAE;aAC/C,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAlOD,oCAkOC"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Schedule configuration for workflow step
3
+ */
4
+ export interface ScheduleConfig {
5
+ /** Whether immediate publishing is allowed */
6
+ allowImmediate?: boolean;
7
+ /** Minimum delay in minutes before scheduling */
8
+ minDelayMinutes?: number;
9
+ /** Maximum delay in days before scheduling */
10
+ maxDelayDays?: number;
11
+ /** Default timezone for scheduling */
12
+ timezone?: string;
13
+ }
14
+ /**
15
+ * Workflow step configuration
16
+ */
17
+ export interface WorkflowStepConfig {
18
+ /** Step identifier */
19
+ id: string;
20
+ /** Step name */
21
+ name: string;
22
+ /** Step type */
23
+ type: string;
24
+ /** Schedule configuration */
25
+ scheduleConfig?: ScheduleConfig;
26
+ /** Additional configuration */
27
+ config?: Record<string, any>;
28
+ }
29
+ /**
30
+ * Content item in workflow context
31
+ */
32
+ export interface WorkflowContentItem {
33
+ /** Content identifier */
34
+ id: string;
35
+ /** Content type */
36
+ type: string;
37
+ /** Content title */
38
+ title?: string;
39
+ /** Content data */
40
+ data: Record<string, any>;
41
+ /** Content metadata */
42
+ metadata?: Record<string, any>;
43
+ }
44
+ /**
45
+ * Workflow execution context
46
+ */
47
+ export interface WorkflowContext {
48
+ /** Content being processed */
49
+ content: WorkflowContentItem;
50
+ /** Context variables */
51
+ variables: Map<string, any>;
52
+ /** User performing action */
53
+ userId?: string;
54
+ /** Additional metadata */
55
+ metadata?: Record<string, any>;
56
+ }
57
+ /**
58
+ * Result from schedule step execution
59
+ */
60
+ export interface ScheduleResult {
61
+ /** Scheduled execution time */
62
+ scheduledFor: Date;
63
+ /** Job identifier from scheduler service */
64
+ jobId: string;
65
+ /** Whether this is immediate execution */
66
+ immediate: boolean;
67
+ /** Target platforms (optional) */
68
+ platforms?: string[];
69
+ }
70
+ /**
71
+ * Workflow step execution result
72
+ */
73
+ export interface WorkflowStepExecutionResult {
74
+ /** Whether execution was successful */
75
+ success: boolean;
76
+ /** Result data */
77
+ data?: ScheduleResult;
78
+ /** Error message if failed */
79
+ error?: string;
80
+ /** Additional metadata */
81
+ metadata?: Record<string, any>;
82
+ }
83
+ /**
84
+ * Validation result
85
+ */
86
+ export interface ValidationResult {
87
+ /** Whether validation passed */
88
+ valid: boolean;
89
+ /** Validation errors */
90
+ errors: string[];
91
+ /** Validation warnings */
92
+ warnings?: string[];
93
+ }
94
+ /**
95
+ * Base workflow step interface
96
+ */
97
+ export interface IWorkflowStep {
98
+ /** Step identifier */
99
+ readonly id: string;
100
+ /** Step type */
101
+ readonly type: string;
102
+ /**
103
+ * Execute the workflow step
104
+ */
105
+ execute(_config: WorkflowStepConfig, _context: WorkflowContext): Promise<WorkflowStepExecutionResult>;
106
+ /**
107
+ * Validate step configuration
108
+ */
109
+ validate(_config: WorkflowStepConfig): ValidationResult;
110
+ }
111
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,8CAA8C;IAC9C,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iDAAiD;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC;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B,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,uCAAuC;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB;IAClB,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,wBAAwB;IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,sBAAsB;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,gBAAgB;IAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,OAAO,CACL,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAExC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,kBAAkB,GAAG,gBAAgB,CAAC;CACzD"}
package/dist/types.js ADDED
@@ -0,0 +1,10 @@
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
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;EAME"}
@@ -0,0 +1,14 @@
1
+ import type { ScheduleConfig, ValidationResult, WorkflowStepConfig } from './types';
2
+ /**
3
+ * Validate schedule configuration
4
+ */
5
+ export declare function validateScheduleConfig(config: WorkflowStepConfig): ValidationResult;
6
+ /**
7
+ * Validate scheduled time against constraints
8
+ */
9
+ export declare function validateScheduledTime(scheduledTime: Date | undefined, config: ScheduleConfig): ValidationResult;
10
+ /**
11
+ * Convert time to specific timezone
12
+ */
13
+ export declare function convertToTimezone(date: Date, timezone: string): Date;
14
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEpF;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,kBAAkB,GAAG,gBAAgB,CA4DnF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,IAAI,GAAG,SAAS,EAC/B,MAAM,EAAE,cAAc,GACrB,gBAAgB,CA6ClB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CA4BpE"}
@@ -0,0 +1,139 @@
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.validateScheduleConfig = validateScheduleConfig;
11
+ exports.validateScheduledTime = validateScheduledTime;
12
+ exports.convertToTimezone = convertToTimezone;
13
+ /**
14
+ * Validate schedule configuration
15
+ */
16
+ function validateScheduleConfig(config) {
17
+ const errors = [];
18
+ const warnings = [];
19
+ if (!config.scheduleConfig) {
20
+ return { valid: true, errors, warnings };
21
+ }
22
+ const scheduleConfig = config.scheduleConfig;
23
+ // Validate minDelayMinutes
24
+ if (scheduleConfig.minDelayMinutes !== undefined) {
25
+ if (typeof scheduleConfig.minDelayMinutes !== 'number') {
26
+ errors.push('minDelayMinutes must be a number');
27
+ }
28
+ else if (scheduleConfig.minDelayMinutes < 0) {
29
+ errors.push('minDelayMinutes must be >= 0');
30
+ }
31
+ }
32
+ // Validate maxDelayDays
33
+ if (scheduleConfig.maxDelayDays !== undefined) {
34
+ if (typeof scheduleConfig.maxDelayDays !== 'number') {
35
+ errors.push('maxDelayDays must be a number');
36
+ }
37
+ else if (scheduleConfig.maxDelayDays < 0) {
38
+ errors.push('maxDelayDays must be >= 0');
39
+ }
40
+ }
41
+ // Validate that min <= max if both are set
42
+ if (scheduleConfig.minDelayMinutes !== undefined &&
43
+ scheduleConfig.maxDelayDays !== undefined) {
44
+ const minMinutes = scheduleConfig.minDelayMinutes;
45
+ const maxMinutes = scheduleConfig.maxDelayDays * 24 * 60;
46
+ if (minMinutes > maxMinutes) {
47
+ errors.push('minDelayMinutes cannot exceed maxDelayDays');
48
+ }
49
+ }
50
+ // Validate timezone if provided
51
+ if (scheduleConfig.timezone) {
52
+ if (typeof scheduleConfig.timezone !== 'string') {
53
+ errors.push('timezone must be a string');
54
+ }
55
+ else {
56
+ try {
57
+ // Test if timezone is valid by creating a date formatter
58
+ new Intl.DateTimeFormat('en-US', { timeZone: scheduleConfig.timezone });
59
+ }
60
+ catch (error) {
61
+ errors.push(`Invalid timezone: ${scheduleConfig.timezone}`);
62
+ }
63
+ }
64
+ }
65
+ return {
66
+ valid: errors.length === 0,
67
+ errors,
68
+ warnings
69
+ };
70
+ }
71
+ /**
72
+ * Validate scheduled time against constraints
73
+ */
74
+ function validateScheduledTime(scheduledTime, config) {
75
+ const errors = [];
76
+ const warnings = [];
77
+ if (!scheduledTime) {
78
+ if (config.allowImmediate === false) {
79
+ errors.push('Scheduled time is required when immediate publishing is not allowed');
80
+ }
81
+ return { valid: errors.length === 0, errors, warnings };
82
+ }
83
+ const now = new Date();
84
+ const delayMs = scheduledTime.getTime() - now.getTime();
85
+ // Check if in the past
86
+ if (delayMs < 0) {
87
+ errors.push('Scheduled time cannot be in the past');
88
+ return { valid: false, errors, warnings };
89
+ }
90
+ // Check minimum delay
91
+ if (config.minDelayMinutes !== undefined) {
92
+ const minDelayMs = config.minDelayMinutes * 60 * 1000;
93
+ if (delayMs < minDelayMs) {
94
+ errors.push(`Scheduled time must be at least ${config.minDelayMinutes} minutes in the future`);
95
+ }
96
+ }
97
+ // Check maximum delay
98
+ if (config.maxDelayDays !== undefined) {
99
+ const maxDelayMs = config.maxDelayDays * 24 * 60 * 60 * 1000;
100
+ if (delayMs > maxDelayMs) {
101
+ errors.push(`Scheduled time cannot be more than ${config.maxDelayDays} days in the future`);
102
+ }
103
+ }
104
+ return {
105
+ valid: errors.length === 0,
106
+ errors,
107
+ warnings
108
+ };
109
+ }
110
+ /**
111
+ * Convert time to specific timezone
112
+ */
113
+ function convertToTimezone(date, timezone) {
114
+ try {
115
+ const formatter = new Intl.DateTimeFormat('en-US', {
116
+ timeZone: timezone,
117
+ year: 'numeric',
118
+ month: '2-digit',
119
+ day: '2-digit',
120
+ hour: '2-digit',
121
+ minute: '2-digit',
122
+ second: '2-digit',
123
+ hour12: false
124
+ });
125
+ const parts = formatter.formatToParts(date);
126
+ const get = (type) => parts.find(p => p.type === type)?.value || '';
127
+ const year = parseInt(get('year'), 10);
128
+ const month = parseInt(get('month'), 10) - 1; // JS months are 0-indexed
129
+ const day = parseInt(get('day'), 10);
130
+ const hour = parseInt(get('hour'), 10);
131
+ const minute = parseInt(get('minute'), 10);
132
+ const second = parseInt(get('second'), 10);
133
+ return new Date(year, month, day, hour, minute, second);
134
+ }
135
+ catch (error) {
136
+ throw new Error(`Failed to convert to timezone ${timezone}: ${error instanceof Error ? error.message : String(error)}`);
137
+ }
138
+ }
139
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1H,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@bernierllc/content-workflow-schedule-step",
3
+ "version": "1.0.0",
4
+ "description": "Scheduling workflow step for content publishing with immediate and scheduled execution support",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist/**/*",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "keywords": [
13
+ "workflow",
14
+ "scheduling",
15
+ "content",
16
+ "publishing",
17
+ "step",
18
+ "automation"
19
+ ],
20
+ "author": "Bernier LLC",
21
+ "license": "SEE LICENSE IN LICENSE",
22
+ "dependencies": {
23
+ "@bernierllc/scheduler-service": "1.0.1",
24
+ "@bernierllc/logger": "1.0.3"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^20.0.0",
28
+ "typescript": "^5.0.0",
29
+ "jest": "^29.0.0",
30
+ "ts-jest": "^29.0.0",
31
+ "@types/jest": "^29.0.0",
32
+ "eslint": "^8.0.0",
33
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
34
+ "@typescript-eslint/parser": "^6.0.0",
35
+ "rimraf": "^5.0.0"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/bernierllc/tools.git",
40
+ "directory": "packages/service/content-workflow-schedule-step"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/bernierllc/tools/issues"
44
+ },
45
+ "homepage": "https://github.com/bernierllc/tools/tree/main/packages/service/content-workflow-schedule-step#readme",
46
+ "publishConfig": {
47
+ "access": "restricted",
48
+ "registry": "https://registry.npmjs.org/"
49
+ },
50
+ "engines": {
51
+ "node": ">=16.0.0"
52
+ },
53
+ "scripts": {
54
+ "build": "tsc",
55
+ "prebuild": "npm run clean",
56
+ "clean": "rimraf dist",
57
+ "test": "jest",
58
+ "test:watch": "jest --watch",
59
+ "test:coverage": "jest --coverage",
60
+ "test:run": "jest --passWithNoTests",
61
+ "lint": "eslint src --ext .ts"
62
+ }
63
+ }