bearer
Function, in @jr2/orchestrator/src/http-effect.ts. It is an export of @jr2/orchestrator, on the Authoring surface page, in Effects.
ts
function bearer<const S extends Secret>(s: S): MarkedIf<S, { readonly bearer: Secret }>Make the auth of an http Effect that sends Authorization: Bearer <value>, with the value of an Effect secret. In a packaged Machine, the secret can be secret(open).
It refuses a value that is not a secret: bearer(…) takes a secret("name").
Parameters
s(Secret): The secret:secret("name"), orsecret(open).
Returns: The auth of an http Effect.
Example
ts
import { bearer, http, jr2Setup, secret } from "@jr2/orchestrator";
export const machine = jr2Setup({
actors: {
status: http({
method: "GET",
url: "https://api.github.com/repos/you/app",
auth: bearer(secret("github")),
}),
},
}).createMachine({
id: "status",
initial: "reading",
states: {
reading: { invoke: { src: "status", onDone: "done" } },
done: { type: "final" },
},
});See also