@goodandready/dsh-cron 0.2.49 → 0.2.51

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/lib/api.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { sanitizeValidators } from './validators.js';
1
2
  /**
2
3
  * REST surface of the plugin: the /dsh-cron/tasks and /dsh-cron/action route
3
4
  * families. Extracted from index.js and split into per-scope handlers so each
@@ -7,7 +8,7 @@
7
8
 
8
9
  import { randomUUID, createHash } from 'node:crypto';
9
10
  import { parseScheduleExpression } from './scheduler.js';
10
- import { normalizeTaskType, CODE_EXECUTING_TYPES } from './runtimes.js';
11
+ import { normalizeTaskType, CODE_EXECUTING_TYPES, EXTERNAL_RUNTIMES } from './runtimes.js';
11
12
  import { CHANNEL_IDS, unknownChannelIds } from './channels.js';
12
13
  import { applyTaskPatch } from './task-patch.js';
13
14
  import { MANAGED_BY_CONFIG, configOwnedMessage } from './config-jobs.js';
@@ -265,7 +266,8 @@ function buildTaskRecord(store, body, taskType, parsed) {
265
266
  misfirePolicy: ['skip', 'runOnce', 'catchUpAll'].includes(body.misfirePolicy) ? body.misfirePolicy : (current ? (current.misfirePolicy || 'skip') : 'skip'),
266
267
  maxRetries: body.maxRetries !== undefined ? Math.max(0, Number(body.maxRetries) || 0) : (current ? (Number(current.maxRetries) || 0) : 0),
267
268
  retryBackoffMs: body.retryBackoffMs !== undefined ? Math.max(1000, Number(body.retryBackoffMs) || 30000) : (current ? (Number(current.retryBackoffMs) || 30000) : 30000),
268
- permissionPreset: ['default', 'read-only', 'workspace-write', 'full'].includes(body.permissionPreset) ? body.permissionPreset : (current ? (current.permissionPreset || 'default') : 'default'),
269
+ permissionPreset: !EXTERNAL_RUNTIMES.includes(taskType) && ['default', 'read-only', 'workspace-write', 'full'].includes(body.permissionPreset) ? body.permissionPreset : (current && !EXTERNAL_RUNTIMES.includes(taskType) ? (current.permissionPreset || 'default') : 'default'),
270
+ validators: Array.isArray(body.validators) ? sanitizeValidators(body.validators) : (current ? current.validators : undefined),
269
271
  ...mergeExecutionFields(current, body, parsed),
270
272
  };
271
273
  }
@@ -341,6 +343,34 @@ async function handleTaskItem({ store, scheduler, req, res, url, id, action, api
341
343
 
342
344
  /** Task actions that are plain POSTs. Returns true when one matched. */
343
345
  async function handleItemPost({ store, scheduler, req, res, url, id, action }) {
346
+ if (action === 'retry-delivery') {
347
+ const task = store.get(id);
348
+ if (!task) {
349
+ sendJson(res, 404, NOT_FOUND);
350
+ return true;
351
+ }
352
+ const body = await readBodyJson(req).catch(() => ({}));
353
+ const runId = body.runId || url.searchParams.get('runId');
354
+ const runs = store.history.get(id) || [];
355
+ const run = runId ? runs.find(r => r.id === runId) : runs[0];
356
+ if (!run) {
357
+ sendJson(res, 404, { ok: false, error: 'Run not found' });
358
+ return true;
359
+ }
360
+ const delivery = await scheduler.deliverNotifications(task, run);
361
+ run.delivery = delivery;
362
+ if (Array.isArray(run.stages)) {
363
+ const deliveryStage = run.stages.find(s => s.name === 'delivery');
364
+ if (deliveryStage) {
365
+ deliveryStage.status = delivery?.status || 'delivered';
366
+ deliveryStage.delivered = delivery?.delivered;
367
+ deliveryStage.failures = delivery?.failures;
368
+ }
369
+ }
370
+ store.scheduleSave();
371
+ sendJson(res, 200, { ok: true, delivery, run });
372
+ return true;
373
+ }
344
374
  if (action === 'run') {
345
375
  if (!store.get(id)) {
346
376
  sendJson(res, 404, NOT_FOUND);
package/lib/channels.js CHANGED
@@ -15,7 +15,7 @@ export const CHANNEL_IDS = ['telegram', 'kanban', 'discord', 'slack', 'ntfy', 'b
15
15
 
16
16
  // CHANNEL_LABELS removed (#155) — localized via lib/client.js
17
17
 
18
- export const isFailureStatus = (status) => status === 'error' || status === 'timeout' || status === 'missed';
18
+ export const isFailureStatus = (status) => status === 'error' || status === 'timeout' || status === 'missed' || status === 'validation_failed' || status === 'validator_error';
19
19
  export const isFailed = (status) => isFailureStatus(status);
20
20
 
21
21
  /** The message text for a channel: task template -> channel template -> global template -> built-in defaults (#233). */
@@ -362,7 +362,9 @@ const CHANNEL_HANDLERS = {
362
362
  },
363
363
 
364
364
  async tts({ task, runInfo, settings, http, signal, timeoutMs }) {
365
- const base = String(settings.ttsBaseUrl || 'http://127.0.0.1:3080').replace(/\/+$/, '');
365
+ const defaultPort = settings._webServerPort || settings.webServerPort || (settings.webServer && settings.webServer.port) || 3080;
366
+ const rawBase = String(settings.ttsBaseUrl || '').trim();
367
+ const base = (rawBase ? rawBase : `http://127.0.0.1:${defaultPort}`).replace(/\/+$/, '');
366
368
  const payload = { text: truncateText(messageTextFor('tts', task, runInfo, settings), 600) };
367
369
  const data = await postJson(http, `${base}/dsh-tts/speak`, { 'Content-Type': 'application/json' }, JSON.stringify(payload), 'tts', signal, timeoutMs);
368
370
  return { provider: data.provider || 'dsh-tts', tookMs: data.tookMs || null };