@nacre.work/api 0.24.0 → 0.25.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/dist/server.js CHANGED
@@ -2405,6 +2405,49 @@ async function handle(req, res, options) {
2405
2405
  send(res, 204, null, requestId);
2406
2406
  return;
2407
2407
  }
2408
+ const retryMatch = pathMatch(/^\/v1\/documents\/([^/]+)\/retry$/, instance);
2409
+ if (req.method === 'POST' && retryMatch) {
2410
+ const id = retryMatch[1];
2411
+ if (options.documents.retry === undefined) {
2412
+ const problem = notFound(instance, requestId);
2413
+ send(res, problem.status, problem.toJSON(), requestId);
2414
+ return;
2415
+ }
2416
+ const outcome = await options.documents.retry(auth, id);
2417
+ await options.audit.write({
2418
+ orgId: auth.orgId,
2419
+ actor: `${auth.principal.type}:${auth.principal.id}`,
2420
+ action: 'retry_document',
2421
+ result: outcome === 'requeued' ? 'allow' : 'deny',
2422
+ target: { document_id: id },
2423
+ detail: { document_id: id, outcome },
2424
+ requestId,
2425
+ });
2426
+ if (outcome === 'unreachable') {
2427
+ const problem = notFound(instance, requestId);
2428
+ send(res, problem.status, problem.toJSON(), requestId);
2429
+ return;
2430
+ }
2431
+ if (outcome === 'not-failed') {
2432
+ const problem = new Problem({
2433
+ type: 'https://nacre.work/errors/conflict',
2434
+ title: 'Conflict',
2435
+ status: 409,
2436
+ detail: 'This document has not failed, so there is nothing to retry. ' +
2437
+ 'Only a document whose status is `failed` can be requeued this way; ' +
2438
+ 'send it again through POST /v1/documents to re-index one that has not.',
2439
+ instance,
2440
+ requestId,
2441
+ });
2442
+ send(res, problem.status, problem.toJSON(), requestId);
2443
+ return;
2444
+ }
2445
+ // `204`, and never the document, for the same reason the PATCH beside it
2446
+ // does: rule 6 means a caller may hold `write` without `read`, so a body
2447
+ // describing what was requeued would be a read this caller has not got.
2448
+ send(res, 204, null, requestId);
2449
+ return;
2450
+ }
2408
2451
  if (req.method === 'PATCH' && documentMatch) {
2409
2452
  const id = documentMatch[1];
2410
2453
  if (options.documents.updateMetadata === undefined) {