Skip to content
betterstack-alchemyUnofficial

Teams & members

Everything you create in any Better Stack product belongs to a team. A team’s id, like t123, is the teamId every other resource takes. A Team manages one team of your organization, and a TeamMember manages one person’s membership.

Team needs a global API token: a team-scoped token can’t list, create or delete teams. Team members are reached by a global token, or by an Incidents team token (see Teams, tokens & zones). Both are tested against the offline mock only, because creating teams and inviting people can’t be undone from a test; see Compatibility.

alchemy.run.ts
const team = yield* BetterStack.Account.Team("platform", {
name: "Platform team",
incidentGroupingPeriod: 600,
incidentGroupingMetadataScope: ["environment"],
});
yield* BetterStack.Errors.Application("api-errors", {
platform: "bun_errors",
teamId: team.id,
});

Every setting updates in place. An existing team with the same explicit name is adopted with --adopt.

Deleting a team deletes everything in it for good. So alchemy destroy, or removing the declaration, leaves the team in Better Stack and only forgets it. Opt into deletion with a removal policy:

alchemy.run.ts
yield* BetterStack.Account.Team("preview", { name: "Preview team" }).pipe(
RemovalPolicy.destroy(),
);

Creating a member e-mails an invitation; the person joins once they accept it. Someone already in another team of the organization joins at once:

alchemy.run.ts
yield* BetterStack.Account.TeamMember("ada", {
email: "ada@example.com",
role: "team_lead",
});

A member is identified by email: changing email or teamId replaces it. role or roleId change in place. With neither, the invitation gets the responder role. Destroying the resource removes the person from the team, or withdraws the invitation.

Account.teams(), Account.findTeam(name), Account.roles() and Account.findRole(nameOrKind) read what exists. Inside a stack, end them with Effect.orDie so a miss stops the plan:

alchemy.run.ts
const staging = yield* BetterStack.Account.findTeam("Staging").pipe(Effect.orDie);
const lead = yield* BetterStack.Account.findRole("team_lead").pipe(Effect.orDie);