Working with Beams
Beams are how credentials are created using Cerebrum's API. Put simply, a Beam is a pipeline used for generating credentials. You set up a Beam to consume data objects of a specified shape, process the data objects using a processor, and use the results to produce credentials.
Input to a Beam can come from webforms, the vID app, or direct API calls.
Once you have created a Beam, you can attach input types to it using the /beam-input-type
endpoint and credential types using the credential-type
endpoint.
After you've attached input types and credential types, you can provide input to the beam by creating a BeamInput using the /beam-input
endpoint.
Beams have different processing functions that are used to generate credentials from inputs. By default, the processor is set to MANUAL
, which means that credentials are generated manually by an operator using the Cerebrum UI.
If you would like to automatically generate credentials, you can set the processor to AUTO
.
Note that for the AUTO
processor, your credential type schema must be the same as, or a subset of, the input type schema.
// Create a Beam
const { data: beamResp } = await axios.post("/v1/beam", {
name: `test-credential-beam`,
description: "For issuing test credentials",
processor: "AUTO",
});
// Attach a credential type to the Beam
await axios.post("/v1/credential-type", {
beamId: beamResp.beamId,
schema: {
type: "object",
properties: {
name: { type: "string" },
location: { type: "string" },
},
required: ["name", "location"],
},
});
// Attach an input type to the Beam
const { data: inputTypeResp } = await axios.post("/v1/beam-input-type", {
beamId: beamResp.beamId,
schema: {
type: "object",
properties: {
name: { type: "string" },
age: { type: "number" },
location: { type: "string" },
},
required: ["name", "location", "age"],
},
});
// Now the Beam is configured, you can create credentials using the input type
const { status, data: credentialResp } = await axios.post(
"/v1/credential",
{
inputTypeId: inputTypeResp.beamInputTypeId,
userId: ctx.user.id,
input: {
name: "John Doe",
age: "30",
location: "San Francisco, CA",
},
}
);
Updated 9 months ago