Connector SDK
Това съдържание още не е налично на вашия език.
A connector is a file that says how to call a web API: where it is, how to sign
in, what each call takes and what it answers. Cascade turns each operation into
a step, with no code to write or run. The format is published (connector schema prints its JSON Schema) and versioned, so a connector written by anyone
runs the same on any Cascade that reads the same version, and the tools to
write, try, publish and install one are in the binary.
A connector can do what an HTTP step can: call one API with one login. What it adds is that the call is named, its inputs are a form in the editor, the login is a credential type of its own, and it can be shared as a file.
Where they live
Section titled “Where they live”Connector files are read once, at start, from HOTLOOP_CASCADE_CONNECTORS_DIR
(the connectors folder inside the data directory by default). A file that
doesn’t read is skipped with a warning in the log that says what is wrong with
it, and the rest load. Restart to pick up a change. hotloop-cascade connector list says what is in the folder. Each operation is a step type named
<connector>.<operation>, and the connector’s credential, if it has one, is a
credential type of its own in the Credentials screen.
Every call goes through the egress policy, so an API on your plant network has
to be allowed (HOTLOOP_CASCADE_EGRESS_ALLOW). A connector can only reach the
one base address it names, and a path can’t leave it.
The file
Section titled “The file”connector: 1 # the spec version; a build refuses one it doesn't readname: acme-erp # lowercase letters, digits, dashes; the steps are acme-erp.<operation>title: Acme ERPversion: 1.2.0description: Orders and parts from the Acme ERP.credential: # optional: the login the steps use title: Acme ERP login fields: - {name: baseUrl, title: Base URL, required: true} - {name: token, title: API token, secret: true, required: true}base: credential.baseUrl # an https:// address, or credential.<field>auth: {type: bearer, field: token}headers: {X-Client: cascade} # sent on every calloperations: - name: getOrder title: Get an order method: GET # GET, POST, PUT, PATCH or DELETE path: /orders/{id} params: - {name: id, title: Order id, in: path, required: true} - {name: expand, in: query, kind: boolean} - name: listOrders title: List orders method: GET path: /orders result: {path: data, each: true} paginate: {type: cursor, param: cursor, next: meta.next} - name: createOrder title: Create an order method: POST path: /orders params: - {name: customer, in: body, required: true} - {name: quantity, in: body, kind: integer} - {name: Idempotency-Key, in: header}auth is none, bearer (field holds the token), header (name and
field), query (name and field) or basic (username and password
name the credential’s fields). Secrets stay in the credential; the file never
holds one.
params are an operation’s inputs, and become the step’s form. in says
where one goes: path (fills {name} in the path, escaped, and has to be
required), query, header, or body (a field of the JSON object sent). kind is string
(the default), text, number, integer, boolean, object, list or
options (with options: [a, b]); an object or list goes in the body. A value
that doesn’t fit its kind, or a required one that is empty, stops the step
before anything is sent. Like any step input, a param can be an expression.
result says where the items are. With no result the answer is the
item (a bare value is {"value": ...}, text is {"body": ...}, an empty
answer is {"status": 204}). path is a dotted path into the answer, and with
each: true the list there becomes one item per element, which is how a step
puts out many items. An answer that is null where a list should be is an
empty list.
paginate walks a list for you, for a GET with result.each. type: cursor
sends the cursor in query parameter param and reads the next one from the
answer at next, and stops when it is empty or missing. type: page counts up
from start (1) and stops on a page with no items. Either stops at maxPages
(100).
A failed call is a failed step with what the API said, sorted the way the
built in connectors sort it: a 429 or a 5xx can be retried by the step’s retry
policy, a 4xx can’t, and a Retry-After is honored. The URL is never put in a
message, because it can carry a key.
Writing one
Section titled “Writing one”hotloop-cascade connector init acme -o acme.yaml # a starting pointhotloop-cascade connector validate acme.yaml # everything wrong with it, in one listhotloop-cascade connector call acme.yaml getOrder \ --param id=7 --credential baseUrl=https://erp.plant.lan --credential token=... \ --allow erp.plant.lan # try one operation against the real APIhotloop-cascade connector schema > connector.schema.json # for your editorcall runs the operation the way a step would, through the same code, and
prints one JSON line per item.
Publishing and installing
Section titled “Publishing and installing”An index is a static file anyone can host next to the connector files, with nothing running behind it:
hotloop-cascade connector index ./published -o ./published/index.yamlindex reads every connector file in the folder, checks each, and lists
them with a SHA-256 each. Put the folder on any web server. On a Cascade host:
hotloop-cascade connector install acme --index https://plant.example/connectors/index.yamlhotloop-cascade connector install acme --index ... --version 1.1.0install fetches the index, picks the version (the newest by default), fetches
the file from beside the index, refuses it if its hash isn’t the index’s or
its name and version aren’t the ones asked for, checks it against the spec, and
only then writes it to the connectors directory. Restart Cascade to load it.
Cascade doesn’t name an index for you and never fetches one on its own: you
say which, once, and only when you run install.