CWA 2.0 is in alpha: try it, build with it, give feedback. APIs can still change between releases; see Releases.
Cwa Api

cwa.orphanedResources

Read the API's orphaned resource and file reports, start a scan, and delete orphans.

cwa.orphanedResources calls the API's orphaned resource and file endpoints. It backs the admin's /_cwa/orphaned page and the scan buttons in site settings, which are described in Orphaned Resources. Use it only to build an admin screen of your own.

Every method needs a signed-in admin. The request code loads on first use, so it isn't in a visitor's entry bundle.

const cwa = useCwa()

const report = await cwa.orphanedResources.fetchReport()
await cwa.orphanedResources.requestScan()
const result = await cwa.orphanedResources.deleteOrphans({ iris: report.components })

Resources

MethodRequestReturns
fetchReport()GET /_/orphaned_resourcesThe last report: generatedAt, and the IRIs of orphaned componentGroups, componentPositions and components
requestScan()POST /_/orphaned_resources/scanNothing. Fetch the report again to see the result
deleteOrphans({ iris }) or deleteOrphans({ all: true })POST /_/orphaned_resources/deletedeleted, with the IRIs deleted for each kind, and rejected, each with an iri and a reason of not_orphaned or not_found

The API checks each IRI again before it deletes it. See Orphaned resource report and Deleting orphans for the report and the delete rules.

Files

MethodRequestReturns
fetchFileReport()GET /_/orphaned_filesThe last file report: generatedAt, orphanedFiles, unknownFiles, missingFiles and invalidFiles
requestFileScan()POST /_/orphaned_files/scanNothing. Fetch the report again to see the result
deleteOrphanedFiles({ paths }) or deleteOrphanedFiles({ all: true })POST /_/orphaned_files/deletedeleted, a list of { adapter, path }, and rejected, each with a path and a reason of not_orphaned, not_found, delete_failed or unknown

Each file has an adapter and a path. A missing file also has the resource that points at it. An invalid file has the resource, the upload field and its violations. invalidFiles needs api-components-bundle 2.0.0-alpha.11 or later; an older bundle doesn't send it. See Orphaned files report.

Caveats

  • An empty iris or paths list sends no request. The method returns an empty result.
  • Duplicate IRIs or paths are sent once.