Skip to content
Zero byNNumbers

Examples

Five paths, from the terminal to the code.

Each example is a whole scenario: what you type, what to expect and why. All of them use only what the platform does today.

1From repository to address

The whole path in eight lines. projects create returns the identifier and already brings the production environment; services create records the intent; deploy publishes and returns an operation, which the CLI follows as a stream.

terminal
zero auth login
zero orgs list && zero orgs use acme
PROJ=$(zero projects create loja)          # production comes with it
zero source set "$PROJ" --provider bitbucket --repo acme/loja --ref main --token
zero flavors list                          # the size catalogue
SVC=$(zero services create web --env env_… --flavor small --subdir apps/web)
zero deploy "$SVC"                         # 202 + operation
zero status "$PROJ"; zero logs "$SVC" --build; zero releases "$SVC"
  • The origin token comes in through standard input: it shows up neither in the shell history nor in the process list.
  • logs --build is what answers “why didn't it go up”; the application log is another command.
  • releases shows the eligible rollback target — that is where the rel_… of example 3 comes from.

2Your own domain

Every project starts with a canonical address. To use the company domain, the path is to list, prove ownership and point the record at your DNS provider — or delegate the zone, if you prefer to centralise it in Zero.

terminal
zero domains list --project "$PROJ"                      # canonical and the project domains
zero domains canonical --project "$PROJ" app.example.com

Ownership verification runs at the edge and returns the state of the proof; delegation is optional.

3Promote and roll back

Promotion reuses the digest: the artifact that went through the test environment is what goes live in the other one. Rolling back does not erase history — it creates a new release over an earlier eligible one.

terminal
zero artifacts svc_staging                  # the published digest
zero promote svc_prod --from svc_staging
zero releases "$SVC"                        # the ROLLBACK column is the eligible target
zero rollback "$SVC" --to rel_… --reason "login regression"
  • artifacts shows the digest the promotion will reuse — promote does not rebuild.
  • --reason records why the return happened, so the history still reads clearly months later.

4Deploy through the SDK

The same path, without a terminal. Every call that creates something accepts an idempotency key: repeating the call with the same key does not create a second project. Progress comes as a stream of events, and the loop ends on the end event.

typescript
const project = await zero.createProject({ name: 'loja' }, { idempotencyKey: crypto.randomUUID() })
const environment = project.environments![0]          // production comes embedded
const service = await zero.createService(
  { environment_id: environment.id, name: 'web', type: 'web', source_path: 'apps/web' },
  { idempotencyKey: crypto.randomUUID() })
const pub = await zero.createDeployment(service.id, {}, { idempotencyKey: crypto.randomUUID() })
for await (const event of zero.streamDeploymentEvents(pub.resource_id!)) {
  if (event.evento === 'fim') break
}

The stream closes on its own: when the end event arrives, there is nothing left to poll.

5Organization login and data

The published application stops keeping its own accounts. Enabling organization-iam takes effect on the next deployment; enabling querymesh takes effect immediately. doctor is the command that answers “what is missing and who fixes it”.

terminal
zero services enable organization-iam svc_…   # takes effect on the next deployment
zero deploy svc_…
zero services enable querymesh svc_…          # takes effect immediately
zero services doctor querymesh svc_…          # what is missing, and who fixes it
typescript · @nnumbers/zero/app
import { NNumbers, UnauthenticatedError } from '@nnumbers/zero/app'

const nn = NNumbers.init()

app.get('/painel', async (req, res) => {
  try {
    const u = await nn.auth.requireUser(req, req.url)
    res.send(`Olá, ${u.name ?? u.username}`)
  } catch (e) {
    if (e instanceof UnauthenticatedError) return res.redirect(e.loginPath)
    throw e
  }
})

app.get('/api/countries', async (req, res) => {
  const r = await nn.querymesh.query(req, 'SELECT name, city FROM sales.customers LIMIT 10')
  res.json({ columns: r.columns, rows: r.rows })
})
  • With no person in the request, requireUser throws UnauthenticatedError carrying the login path — the application redirects, it does not invent a session.
  • The query leaves with the identity of whoever asked: what the person may not see, the query does not return.

Start from the console.

The first project takes one session. After that, the same steps fit in a script.