# Commands for making and publishing packages

These commands start a package in its own repository, confirm it against
its API, hold it to the publishing bar and release it on the registry
([Developing and publishing a
package](/docs/developing-and-publishing-a-package.md)). Using
the packages an app installs is [Commands for
packages](/docs/commands-for-packages.md). Each takes `--json`.

| Command | Does |
|---|---|
| `jadpo package new <Name> --library` or `--provider` `[--publisher <handle>]` | Starts a package in its own repository |
| `jadpo package record <connection> <operation>` | Confirms an operation against the sandbox and saves the recording |
| `jadpo package conform <package> <capability>` | Runs a capability's conformance suite |
| `jadpo package protocol <document>` | Checks a registry's OpenAPI document against the registry protocol |
| `jadpo package check` | Runs the publishing bar on a package |
| `jadpo package publish [--dry-run]` | Asks the registry to release the package from a tag |
| `jadpo package preview [<folder>]` | Serves the package's registry page locally |
| `jadpo package verify <folder> [--previous <folder>] [--publisher <handle>] [--no-run]`, `jadpo package verify --serve` | The registry's verifier: the bar, facts, change record and fingerprints, and the service that answers the registry |

## `jadpo package new`

Starts a package in its own repository ([Developing and publishing a
package](/docs/developing-and-publishing-a-package.md)): `new <Name>
--library` for code an app calls, or `--provider` for a package that describes
an API. `<Name>` is its name in code, in UpperCamelCase and without a version,
since it starts at `v1`. The folder is made where the command runs and named as
the registry writes the name: `AcmeCouriers` goes in `acme-couriers/`.

It writes the package format, `recipes/`, a `sample/` app and `GUIDE.md`, with
a small example of each kind of file to replace, and the `CHANGELOG.md` and
`surface.jadpo_record` of its first release, so it passes `jadpo package check`
as written and that command has nothing to change. A library starts with the
`starter` library, a recipe and a test. A provider starts with the `account`
resource, its two types listed in `reviewed:`, a recipe and hosts ending
`.example`, and no recording, so its contract says nothing is confirmed until
`jadpo package record` has called the API. A type you add goes in `reviewed:`
once you have gone through it against the API's documentation.
`.gitignore` and `.gitattributes` sit beside them, and git isn't run: making the
repository is yours.

- `--publisher <handle>` writes the index's `publisher:`. Without it the command
  asks on a terminal, where enter leaves the key out, and leaves it out
  everywhere else, `--json` included.
- The licence is `Licence.proprietary` until you choose another, because which
  rights to give others is yours to say. `check` passes it, and `verify` and
  `publish` refuse it (`publish.licence_proprietary`).
- A name that isn't one, or that a package can't compile under, is
  `cli.package_arguments`. A folder that holds anything, or a file of that name,
  is refused as `jadpo new` refuses it, and if a write fails partway the command
  removes what it wrote.

The screen is one status line, then the command to run next:

```text
Created acme-couriers
    package    AcmeCouriers.v1, provider
    publisher  @acme
    licence    proprietary, publishing needs an open one
    jadpo      X.Y
    files      15 written

next: cd acme-couriers && jadpo package check  runs the publishing bar on it
```

With `--json`, `data` holds the `path`, the `root`, the `package`, its `kind`,
`publisher` and `licence`, the `jadpo` line and the `files` it wrote.

## `jadpo package record`

Confirms an operation against the provider's sandbox and saves the
answer as a recording, for tests ([Provenance and
confirmation](/docs/where-packages-come-from.md#provenance-and-confirmation)).

`--input` gives the operation's input as JSON, written as a route's body
is. It calls the sandbox once through the connection, never the live
service and never with a stand-in credential (`recording.refused`). It
checks the answer against the operation's output type and keeps it as
`recordings/<resource>.<operation>.json`, in the app's own integration or
a linked checkout, its plain values replaced by placeholders, and writes
when it was made, `recorded <resource>.<operation> <instant>`, in
`recordings/recorded.jadpo_record`, which the package's facts read as
its last contract run. An operation with no `output:` gets its output
type from the answer first, as the importer reads one, with its guesses
listed to check
([Recordings](/docs/recordings.md)). A refusal,
no answer, or an answer that doesn't decode or yield a type keeps
nothing (`recording.failed`). A missing or wrong
`--input` is `cli.package_arguments`.

## `jadpo package conform`

`conform <package> <capability>` runs a capability's conformance suite
([Proving a package works](/docs/capabilities.md#proving-a-package-works))
in a scratch app holding the package as installed. By default it uses the
package's recordings and a local fake, so nothing leaves your machine. `ai` runs six cases ([AI](/docs/ai.md)), `email` four
and `receiving` three.

`--live` runs them against the provider's API through the app's
connection to the package, and is refused without it, its credential or
address, or `ai:` or `email:` through it (`conform.refused`). `receiving`
has no live run. A case that fails is `conform.failed`.

## `jadpo package protocol`

`protocol <document>` is [the registry protocol](/docs/the-registry-protocol.md)'s
conformance test: it checks a registry application's OpenAPI document against
the protocol's table, so that application's CI needs only `jadpo`, at the
release it targets. The document is a file, such as `jadpo check`'s
`build/openapi/main.json`, an `https://` address, or a local `http://` one. It needs no project.

A document that conforms is one line:

```text
✓ Conforms to the registry protocol  build/openapi/main.json · 13 requests
```

Outside a terminal, as in CI, it is plain text:

```text
Conforms to the registry protocol: build/openapi/main.json, 13 requests
```

One that differs is `protocol.mismatch` with each difference under its request,
and exits 1; `--json` gives `document`, `conforms`, `requests` and
`mismatches`, each with its `operation` and `problem`. An unreadable document is
`protocol.unreadable`, not a difference.

## `jadpo package check`

Runs the publishing bar, the checks a package passes before it is
released, in a package's own repository or the folder given ([Developing
and publishing a package](/docs/developing-and-publishing-a-package.md)).

- The package is checked as the app's own integration, each problem shown
  at its place in the package.
- The examples in its descriptions run as tests (`publish.example_missing`,
  `publish.example_failed`).
- The new version's section of `CHANGELOG.md` is written, and needs your
  reason for the release (`publish.changelog_missing`).
- The version is worked out from the surface at the last `v<version>` tag,
  and a breaking change is refused (`publish.breaking_change`). The
  registry counts the releases it published, and a tag can name one it never
  took, such as a release its verifier refused: `--previous <version>`
  compares with that tagged release instead, and `--previous none` checks a
  first release whatever the tags say, as `verify --previous` names the
  release before. A version no tag the checkout grew from holds is
  `cli.package_arguments`. `check` stays offline, so a package's CI gets the
  same answer with or without a network, and the flag says what only the
  registry knows.
- A `recipes` row compiles each recipe in the one domain of the package's
  `sample/` app (`publish.sample_missing` without one).
- A `publisher` row shows who `package.jadpo` names, and says `left out` when
  it names no one: a package only used by path or from git may, and only `verify`
  and `publish` refuse it.
- A `licence` row shows the licence and the lowest Jadpo version it declares. A
  `Licence.proprietary` package passes it, as a private package may, and the row
  says the registry refuses it; only `verify` and `publish` do.

- A `behaviour` row runs the last release's examples and tests against the
  new code. One that fails is a change the types don't show, refused within
  a major version unless the new version's section marks it a fix
  (`publish.behaviour_changed`).
- Each capability the package fills runs its conformance suite on its
  recordings, shown as a fact that refuses nothing (`conformance  email:
  conforms, 4 passed`; [Proving a package
  works](/docs/capabilities.md#proving-a-package-works)); `--json` has
  `conformance`, `null` where nothing ran.

The bar is shown a row per item: passed, failed or not checked yet. When
the package compiles and its version is allowed, `surface.jadpo_record` is
written, to be compared with the previous tag's.

Above the bar, once the package compiles, come the release's
[facts](/docs/the-public-registry.md#what-a-release-shows) and its [change
record](/docs/the-public-registry.md#the-changelog), exactly as the registry will show
them. `--json` gives the same as `facts` and `change_record`, and what the
last release's examples and tests gave as `previous`:

```text
Facts
  kind      library, pure
  storable  OutwardCode, UkPostcode, WrittenPostcode
  failures  uk.tidy: InvalidPostcode

Changes since 2.0.0
  + added  type OutwardCode
```

When the package compiles and sends personal data, a section before the bar
says where: each host, then each operation with what it sends and its
category ([Where personal data goes](/docs/the-personal-data-report.md#where-personal-data-goes)).
`--json` gives the same as `personal_data`, `null` for a package with errors:

```text
Personal data sent
  to https://api.acme-pay.example
  to https://sandbox.acme-pay.example
  customers.create  CustomerRequest.notes  health, sensitive
```

## `jadpo package publish`

Asks the registry to release the package in this repository from its tag,
sending the repository, the tag and the publisher `package.jadpo` names, with
no sign-in. Once the registry has checked it, the command ends with the
release's page on jadpo.dev, where a releaser publishes it with a passkey
([Releasing](/docs/the-public-registry.md#releasing)). The
tag has to be pushed and the checkout that commit, unchanged
(`publish.not_at_tag`), and the repository reached over HTTPS
(`publish.repository_refused`). It holds the package to the bar here first, then
shows what the registry's verifier found; a refusal is `publish.failed`. A
package whose index names no publisher stops at the bar, having asked nothing
(`publish.publisher_missing`), and a release that isn't its publisher's to make
is `publish.publisher_mismatch` ([Names and
publishers](/docs/the-public-registry.md#names-and-publishers)). So does a package whose licence is `Licence.proprietary`
(`publish.licence_proprietary`). `--dry-run` runs the
verifier and publishes nothing.

A release that passes is pending: it ends `release pending: <package>
<version>, a releaser confirms it with a passkey on jadpo.dev`. It is listed
under "Ready to publish" on your account page there, and goes live once you
publish it with your passkey ([Publish a
package](/guides/guide-publish-a-package.md)).

## `jadpo package preview`

Serves the package's registry page on this machine, read-only, until it is
stopped: `preview [<folder>]`. It runs the bar as `verify` does and writes
nothing ([Developing for the registry](/docs/the-public-registry.md#developing-for-the-registry)).

## `jadpo package verify`

The registry's verifier, which you can run yourself ([The
verifier](/docs/the-verifier.md)). `verify <folder> --previous
<folder>` runs `check`'s bar on a package as it stands, against the release
in the second folder, and writes nothing. With no `--previous` it is a first
release.

The commit has to carry what its code gives: its `surface.jadpo_record` and
the new version's list in `CHANGELOG.md` are compared rather than written
(`publish.stale_files`).

`--json` writes everything a release shows: the bar's rows, the surface,
facts, change record, each public declaration's fingerprints, what the
previous release's examples and tests gave, `conformance`, and the Jadpo release it was
checked with and the one its `jadpo:` declares ([How they are worked
out](/docs/how-a-releases-facts-change-record-and-fingerprints-are-worked-out.md)).

Its first row, `files`, holds a commit to what a release may hold: only Jadpo
source and the package's text files, within the size limit
(`publish.file_not_allowed`, `publish.too_large`).

Its `publisher` row needs `package.jadpo` to name one
(`publish.publisher_missing`); `check`'s only says `left out`, since a package
used by path or from git may. `--publisher <handle>` says who the release is
for, and a package naming anyone else fails it (`publish.publisher_mismatch`).

Its `licence` row refuses `Licence.proprietary`, which the public registry
doesn't carry (`publish.licence_proprietary`); `check`'s passes it, since a
private package may be.

`--no-run` runs none of the package's code: the rows that need it say
`not run`, and everything worked out from its source is as it would be. It is
how the verifier gets a release's facts from a process the package's code
never ran in.

`--serve` is that verifier, answering the registry: `--listen` says where,
`127.0.0.1:8080` unless given, and `--registry` where previous releases'
archives come from. It needs `JADPO_VERIFIER_TOKEN` and a sandbox, and serves
only on Linux, from its container image (`cli.verifier_start_failed`; [The
verifier](/docs/the-verifier.md)).

Not built yet: `jadpo package conform` for a capability whose mapping isn't
read yet (`toolchain.not_built_yet`).
