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.
Create a team
Section titled “Create a team”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.
A team is retained by default
Section titled “A team is retained by default”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:
yield* BetterStack.Account.Team("preview", { name: "Preview team" }).pipe( RemovalPolicy.destroy(),);Invite a member
Section titled “Invite a member”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:
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.
Look up teams and roles
Section titled “Look up teams and roles”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:
const staging = yield* BetterStack.Account.findTeam("Staging").pipe(Effect.orDie);const lead = yield* BetterStack.Account.findRole("team_lead").pipe(Effect.orDie);Where next
Section titled “Where next”- Teams, tokens & zones: which token reaches which team.
- Reference:
Team,TeamMember, lookups. - Better Stack: Teams (API), Team members (API).