> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Bundle Version

> Publish a new marketplace bundle version with metadata fields and a JSON items array via the curator editor form.

The Create Bundle Version screen is the curator editor form for publishing a new marketplace bundle at route `/cl/marketplace/curator/new`.

## Overview

The page renders a form for curators to publish a new bundle row to `cl_marketplace_bundles` along with its `cl_marketplace_bundle_items` entries. The form collects `bundle_key`, `version` (integer), `name`, `description`, `accreditation_tags` (comma-separated), `clinical_area_tags` (comma-separated), and an `items` JSON textarea. The items JSON must be an array of objects each containing `item_type`, `item_key`, and `payload`. Supported `item_type` values are enumerated in `MARKETPLACE_ITEM_TYPES`: `assessment_template`, `note_template`, `cds_rule`, `pathway_definition`, `treatment_plan_template`, `goal_bank_entry`, `order_set`, `locus_instrument`, `group_curriculum`, `screening_instrument`. On submission, `usePublishMarketplaceBundleVersion` inserts the bundle row then the items in sequence — if the items insert fails after a successful bundle insert, an orphaned empty bundle row is left visible. On success, the user is navigated back to `/cl/marketplace/curator`. Authorization is enforced at the database layer via the `cl_can_curate_marketplace` SECURITY DEFINER helper.

## Who it's for

Requires permission `cl.marketplace.publish`.

## Before you start

You must hold the `cl.marketplace.publish` permission. A `bundle_key` identifies the bundle across versions — subsequent versions of the same bundle reuse the same `bundle_key` with a higher `version` integer. Prepare the items JSON array before submitting; a sample structure is pre-populated in the textarea.

## Steps

<Steps>
  <Step title="Navigate to the curator editor">
    Go to `/cl/marketplace/curator/new`, or click the create action from the curator list at `/cl/marketplace/curator`.
  </Step>

  <Step title="Enter bundle metadata">
    Fill in the required fields: Bundle key (e.g., `carf-sud-core`), Version (integer starting at 1), and Name (e.g., `CARF SUD Core Bundle`). Optionally add a Description, accreditation tags (comma-separated), and clinical area tags (comma-separated).
  </Step>

  <Step title="Author the items JSON array">
    Edit the Items textarea. Each element must be a JSON object with `item_type` (one of the supported types listed below the field), `item_key` (non-empty string), and `payload` (object). An optional `ordering` integer can be provided; items default to their array index order.
  </Step>

  <Step title="Submit the form">
    Click "Publish". The form validates the items JSON client-side. If the JSON is invalid or any item fails validation, a destructive alert displays the parse error and submission is blocked. On success a toast confirms the published bundle name and version, and the page navigates back to the curator list.
  </Step>

  <Step title="Cancel">
    Click Cancel or the "Back to curator" ghost button to discard and return to `/cl/marketplace/curator` without publishing.
  </Step>
</Steps>

## Key concepts

<AccordionGroup>
  <Accordion title="Supported item types">
    `MARKETPLACE_ITEM_TYPES` (from `src/cores/cl/types/marketplace.ts`): `assessment_template`, `note_template`, `cds_rule`, `pathway_definition`, `treatment_plan_template`, `goal_bank_entry`, `order_set`, `locus_instrument`, `group_curriculum`, `screening_instrument`. Any other value will cause a client-side parse error.
  </Accordion>

  <Accordion title="Non-transactional insert">
    The publish mutation inserts the bundle row first, then inserts the items in a second call. These are not wrapped in a database transaction. An items insert failure after a successful bundle insert leaves an empty bundle visible in the catalogue. A future iteration is noted in the code comment to move publish to an Edge Function.
  </Accordion>

  <Accordion title="Parse error state">
    If the items textarea contains invalid JSON or a validation error (wrong type, missing key, etc.), an alert with variant `destructive` appears below the form describing the error. Submission is blocked until the error is resolved.
  </Accordion>
</AccordionGroup>

## Related

<Columns cols={2}>
  <Card title="Clinical" icon="stethoscope" href="/cl/overview">
    Overview of the Clinical core.
  </Card>

  <Card title="Governance & parity" icon="scale-balanced" href="/governance/index">
    Documentation coverage and governance.
  </Card>
</Columns>

<Note>
  This page documents shipped product behavior. It is not medical, legal, or
  billing advice. Verify against your organization's policies and applicable
  regulations before using it for clinical, compliance, or billing decisions.
  Protected health information (PHI) shown in the product is governed by your
  tenant's access controls and is never exposed in this documentation.
</Note>

<Accordion title="Documentation sources">
  * src/routes/cl.tsx
  * src/cores/cl/pages/MarketplaceCuratorEditorPage.tsx
  * src/cores/cl/hooks/useMarketplaceCurator.ts
  * src/cores/cl/types/marketplace.ts
</Accordion>
