Skip to content

The vendor's own setup

vendor.fields are the values an operator gives once per deployment for the vendor's client. When the vendor can create that client itself, vendor.setup says how, and Initiative runs it from the operator's browser and writes what the vendor answers into those fields. One kind exists, github_app_manifest (GitHub's app manifest flow):

vendor: {
  fields: [
    { key: "app_id", type: "string", required: true, label: { en: "App id" } },
    { key: "private_key", type: "secret", required: true, label: { en: "Private key" } },
    // …
  ],
  setup: {
    kind: "github_app_manifest",
    app: {
      name: "Acme Tracker",
      url: "https://tracker.acme.example",
      default_permissions: { issues: "write", metadata: "read" },
      default_events: ["issues"],
    },
    values: { app_id: "id", private_key: "pem" /* , … */ },
  },
},
  • app is what GitHub is asked to create: its name, its homepage (https), whether any account may install it (public, default false), and its permissions and events by GitHub's names. Initiative fills in the callback, setup, webhook and redirect URLs itself, so app names none.
  • values maps each of your vendor field keys to one field of GitHub's answer: id, slug, client_id, client_secret, pem or webhook_secret. Each key must be a vendor field, each answer is written at most once, and client_secret, pem and webhook_secret go to secret fields.

Checking the vendor values

An operator who types the values by hand can mix two clients' values, or mistype a name the vendor builds addresses from, and nothing says so until a community's connection fails. vendor.check is a call Initiative makes to the vendor when the values are saved, before they are written, and the rows that say what its answer must show:

check: {
  sign: { iss: "{vendor.app_id}", key: "{vendor.private_key}" },
  request: { method: "GET", url: "'https://api.tracker.example/app'" },
  expect: [
    {
      status: "4xx",
      holds: "false",
      fields: ["app_id", "private_key"],
      message: { en: "The vendor knows no client by this id and key." },
    },
    {
      holds: "response.body.name = vendor.app_name",
      fields: ["app_name"],
      message: { en: "The id and key belong to a client with another name." },
      shows: "response.body.name",
    },
  ],
},
  • request is the call, written as a declarative plug-in's requests are: https, and on one of your hosts when you name them. Its expressions read vendor, the non-secret values being saved, by key, and now; secrets are never readable.
  • sign has Initiative sign a JWT with one secret vendor value (key), issued by vendor values (iss), and put it on the request as auth says (default Authorization: Bearer <jwt>). Without sign the request carries no credential.
  • expect is tried in order. A row applies to the answers its status matches (default 2xx) and refuses one when holds does not answer true; holds also reads the answer as response. The first row that refuses keeps the values from being written, and the form marks its fields, shows its message, and shows what shows answers beside it. An answer no row refuses is accepted.
  • When the vendor cannot be reached, an expression fails, or a non-2xx answer has no row, the values are written and the form says the check could not run. A check never keeps an operator from saving because the vendor is down.

The check runs when a save sets a vendor value it reads, typed on the form or written by the vendor's setup. validateManifest refuses rows naming fields the vendor block does not declare, a key that is not one secret vendor value, an issuer naming anything but vendor values, a header that would replace the signed JWT's, and expressions that do not parse.

A token minted on demand

A static connection's token has Initiative mint its access token rather than store one: it signs a JWT with a vendor key, posts it to the vendor's exchange_url, and caches the answer until shortly before it expires. exchange_body is a JSON body posted with it, such as the narrower permissions a token is asked for:

token: {
  type: "jwt_bearer",
  exchange_url: "https://api.tracker.example/installations/{installation_id}/tokens",
  exchange_body: { permissions: { issues: "write", contents: "read" } },
  iss: "{vendor.app_id}",
  key: "{vendor.private_key}",
},

exchange_url, iss and every string in exchange_body may name a vendor value as {vendor.<key>} and one of the connection's own fields as {<key>}; validateManifest refuses a name that neither declares.

exchange_body may instead be an expression answering the body from connection alone, the connection's own non-secret fields, managed ones included, so the body can differ by connection: a vendor may refuse a token request naming a permission the installation does not hold. A body that names a vendor value stays an object. An answer that is not an object fails the token request, so the connection cannot be used until the expression answers one. runExchangeBody from initiative-plugin-sdk/testing answers the body Initiative posts for a connection's fields and vendor values.

// account_type is a managed field; only an organization's installation holds "members"
exchange_body:
  '{"permissions": $merge([{"issues": "write"}, connection.account_type = "organization" ? {"members": "read"} : {}])}',