* The admin clause is resolved last and lazily: a global/userId/orgId match * short-circuits before any DB read, a rule without `admins` never queries, and a * missing `userId` resolves to `false` without a query.
( rule: FeatureFlagRule | undefined, ctx: FeatureFlagContext )
| 180 | * missing `userId` resolves to `false` without a query. |
| 181 | */ |
| 182 | async function evaluate( |
| 183 | rule: FeatureFlagRule | undefined, |
| 184 | ctx: FeatureFlagContext |
| 185 | ): Promise<boolean> { |
| 186 | if (!rule) return false |
| 187 | if (rule.enabled) return true |
| 188 | if (ctx.userId && rule.userIds?.includes(ctx.userId)) return true |
| 189 | if (ctx.orgId && rule.orgIds?.includes(ctx.orgId)) return true |
| 190 | if (rule.adminEnabled) { |
| 191 | const admin = ctx.isAdmin ?? (ctx.userId ? await resolveAdmin(ctx.userId) : false) |
| 192 | if (admin) return true |
| 193 | } |
| 194 | return false |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Resolve the full flag document. Reads from AWS AppConfig on hosted deployments |
no test coverage detected