Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 122x 122x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 17x 17x 17x 17x 17x 17x 17x 17x 17x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 47x 47x 47x 47x 1x 1x 47x 47x 5x 1x 1x 1x 1x 5x 5x 1x 1x 1x 1x 5x 5x 3x 3x 3x 3x 3x 3x 3x 47x 47x 1x 1x 47x 47x 1x 1x 47x 47x 39x 39x 39x 39x 47x 33x 33x 47x 47x 6x 6x 6x 6x 6x 6x 47x 1x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 1x 1x 39x 39x 1x 1x 39x 39x 37x 37x 39x 1x 1x 39x 39x 36x 2x 39x 1x 1x 1x 1x 39x 39x 35x 35x 35x 35x 39x 1x 1x 39x 39x 1x 1x 39x 39x 1x 1x 39x 39x 1x 1x 39x 39x 31x 31x 31x 31x 7x 39x 39x 39x 30x 8x 5x 3x 39x 39x 39x 29x 29x 29x 39x 39x 28x 28x 28x 39x 39x 27x 5x 39x 39x 2x 2x 39x 39x 39x 24x 23x 39x 39x 39x 39x 22x 17x 39x 1x 1x 39x 39x 21x 21x 21x 39x 2x 2x 39x 39x 19x 19x 19x 39x 1x 1x 39x 39x 18x 18x 18x 39x 1x 1x 39x 39x 17x 17x 17x 39x 3x 3x 39x 39x 14x 14x 14x 39x 1x 1x 39x 39x 13x 13x 13x 39x 1x 1x 39x 39x 12x 12x 12x 39x 2x 2x 39x 39x 10x 10x 10x 39x 1x 1x 39x 39x 9x 9x 4x 39x 1x 1x 39x 39x 8x 8x 3x 39x 1x 1x 1x 1x 39x 39x 7x 7x 2x 39x 1x 1x 1x 1x 39x 39x 6x 6x 6x 6x 6x 6x 6x 6x 4x 2x 39x 4x 2x 39x 3x 3x 39x 1x 5x 39x 39x 1x 5x 39x 1x 5x 39x 1x 5x 39x 1x 5x 39x 1x 5x 39x 1x 5x 39x 1x 5x 39x 1x 5x 39x 39x 1x 5x 39x 1x 5x 39x 39x 39x 1x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 5x 5x 12x 12x 7x 7x 7x 7x 7x 6x 12x 2x 2x 12x 12x 5x 5x 5x 12x 1x 152x 152x 152x 152x 152x 152x 152x 152x 152x 152x 152x 152x 152x 78x 78x 152x 152x 9x 9x 152x 152x 65x 65x 65x 152x 1x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 5x 5x 17x 17x 12x 12x 10x 17x 3x 3x 17x 17x 9x 9x 9x 17x 1x 38x 38x 38x 38x 38x 38x 38x 38x 38x 1x 86x 86x 86x 1x 83x 83x 83x 83x 83x 83x | export const DISCORD_SNOWFLAKE_PATTERN = /^\d{17,20}$/
export const DISCORD_GUILD_RUNTIME_CONFIG_LOG_LEVELS = [
"none",
"minimal",
"medium",
"maximum",
] as const
export const DISCORD_GUILD_SUPPORT_TARGET_TYPES = [
"channel",
"thread",
"forum",
] as const
export const DISCORD_GUILD_SUPPORT_TRANSCRIPT_POLICIES = [
"metadata-only",
"explicit-messages",
] as const
export const DISCORD_GUILD_SUPPORT_ESCALATION_POLICIES = [
"none",
"jcn-product-only",
] as const
export const BACKEND_DISCORD_GUILD_RUNTIME_CONFIG_DISABLED_REASONS = [
"unknownGuild",
"botLeft",
"missingConfig",
] as const
export const LOCAL_DISCORD_GUILD_RUNTIME_CONFIG_DISABLED_REASONS = [
"invalidGuildId",
"convexUnavailable",
"invalidBackendResponse",
] as const
export const DISCORD_GUILD_RUNTIME_CONFIG_REQUIRED_FIELD_NAMES = [
"discordGuildId",
"moderationEnabled",
"welcomeEnabled",
"loggingEnabled",
"supportEnabled",
] as const
export const DISCORD_GUILD_RUNTIME_CONFIG_OPTIONAL_FIELD_NAMES = [
"liveNotificationsEnabled",
"liveNotificationChannelId",
"liveNotificationMentionMode",
"liveNotificationRoleId",
"logLevel",
"logChannelId",
"modLogChannelId",
"welcomeChannelId",
"welcomeSubtext",
"updatesChannelId",
"announcementChannelId",
"supportStaffRoleIds",
"supportTargetId",
"supportTargetType",
"supportTranscriptPolicy",
"supportEscalationPolicy",
] as const
export const DISCORD_GUILD_RUNTIME_CONFIG_FIELD_NAMES = [
...DISCORD_GUILD_RUNTIME_CONFIG_REQUIRED_FIELD_NAMES,
...DISCORD_GUILD_RUNTIME_CONFIG_OPTIONAL_FIELD_NAMES,
] as const
export type DiscordGuildRuntimeConfigLogLevel =
(typeof DISCORD_GUILD_RUNTIME_CONFIG_LOG_LEVELS)[number]
export type DiscordGuildSupportTargetType =
(typeof DISCORD_GUILD_SUPPORT_TARGET_TYPES)[number]
export type DiscordGuildSupportTranscriptPolicy =
(typeof DISCORD_GUILD_SUPPORT_TRANSCRIPT_POLICIES)[number]
export type DiscordGuildSupportEscalationPolicy =
(typeof DISCORD_GUILD_SUPPORT_ESCALATION_POLICIES)[number]
export type BackendDiscordGuildRuntimeConfigDisabledReason =
(typeof BACKEND_DISCORD_GUILD_RUNTIME_CONFIG_DISABLED_REASONS)[number]
export type LocalDiscordGuildRuntimeConfigDisabledReason =
(typeof LOCAL_DISCORD_GUILD_RUNTIME_CONFIG_DISABLED_REASONS)[number]
export type DiscordGuildRuntimeConfigDisabledReason =
| BackendDiscordGuildRuntimeConfigDisabledReason
| LocalDiscordGuildRuntimeConfigDisabledReason
export type DiscordGuildRuntimeConfig = {
liveNotificationsEnabled?: boolean
liveNotificationChannelId?: string
liveNotificationMentionMode?: "none" | "everyone" | "role"
liveNotificationRoleId?: string
discordGuildId: string
moderationEnabled: boolean
welcomeEnabled: boolean
loggingEnabled: boolean
supportEnabled: boolean
logLevel?: DiscordGuildRuntimeConfigLogLevel
logChannelId?: string
modLogChannelId?: string
welcomeChannelId?: string
welcomeSubtext?: string
updatesChannelId?: string
announcementChannelId?: string
supportStaffRoleIds?: string[]
supportTargetId?: string
supportTargetType?: DiscordGuildSupportTargetType
supportTranscriptPolicy?: DiscordGuildSupportTranscriptPolicy
supportEscalationPolicy?: DiscordGuildSupportEscalationPolicy
}
export type BackendDiscordGuildRuntimeConfigResult =
| {
status: "ready"
config: DiscordGuildRuntimeConfig
}
| {
status: "disabled"
reason: BackendDiscordGuildRuntimeConfigDisabledReason
}
export type DiscordGuildRuntimeConfigResult =
| {
status: "ready"
config: DiscordGuildRuntimeConfig
}
| {
status: "disabled"
reason: DiscordGuildRuntimeConfigDisabledReason
}
export type RuntimeConfigValidationResult =
| {
success: true
data: BackendDiscordGuildRuntimeConfigResult
}
| {
success: false
error: string
}
export function isDiscordSnowflake(value: string): boolean {
return DISCORD_SNOWFLAKE_PATTERN.test(value)
}
export function isBackendDiscordGuildRuntimeConfigDisabledReason(
value: unknown
): value is BackendDiscordGuildRuntimeConfigDisabledReason {
return (
typeof value === "string" &&
BACKEND_DISCORD_GUILD_RUNTIME_CONFIG_DISABLED_REASONS.includes(
value as BackendDiscordGuildRuntimeConfigDisabledReason
)
)
}
export function isDiscordGuildRuntimeConfigLogLevel(
value: unknown
): value is DiscordGuildRuntimeConfigLogLevel {
return (
typeof value === "string" &&
DISCORD_GUILD_RUNTIME_CONFIG_LOG_LEVELS.includes(
value as DiscordGuildRuntimeConfigLogLevel
)
)
}
export function isDiscordGuildSupportTargetType(
value: unknown
): value is DiscordGuildSupportTargetType {
return (
typeof value === "string" &&
DISCORD_GUILD_SUPPORT_TARGET_TYPES.includes(
value as DiscordGuildSupportTargetType
)
)
}
export function isDiscordGuildSupportTranscriptPolicy(
value: unknown
): value is DiscordGuildSupportTranscriptPolicy {
return (
typeof value === "string" &&
DISCORD_GUILD_SUPPORT_TRANSCRIPT_POLICIES.includes(
value as DiscordGuildSupportTranscriptPolicy
)
)
}
export function isDiscordGuildSupportEscalationPolicy(
value: unknown
): value is DiscordGuildSupportEscalationPolicy {
return (
typeof value === "string" &&
DISCORD_GUILD_SUPPORT_ESCALATION_POLICIES.includes(
value as DiscordGuildSupportEscalationPolicy
)
)
}
export function validateBackendDiscordGuildRuntimeConfigResult(
value: unknown,
expectedDiscordGuildId?: string
): RuntimeConfigValidationResult {
if (!isRecord(value)) {
return validationError("Runtime config result must be an object.")
}
if (value.status === "disabled") {
if (!hasOnlyKeys(value, ["status", "reason"])) {
return validationError(
"Disabled runtime config result has unknown fields."
)
}
if (!isBackendDiscordGuildRuntimeConfigDisabledReason(value.reason)) {
return validationError(
"Disabled runtime config result has invalid reason."
)
}
return {
success: true,
data: {
status: "disabled",
reason: value.reason,
},
}
}
if (value.status !== "ready") {
return validationError("Runtime config result has invalid status.")
}
if (!hasOnlyKeys(value, ["status", "config"])) {
return validationError("Ready runtime config result has unknown fields.")
}
const configResult = validateDiscordGuildRuntimeConfig(
value.config,
expectedDiscordGuildId
)
if (!configResult.success) {
return configResult
}
return {
success: true,
data: {
status: "ready",
config: configResult.data,
},
}
}
function validateDiscordGuildRuntimeConfig(
value: unknown,
expectedDiscordGuildId: string | undefined
):
| {
success: true
data: DiscordGuildRuntimeConfig
}
| {
success: false
error: string
} {
if (!isRecord(value)) {
return validationError("Runtime config must be an object.")
}
if (!hasOnlyKeys(value, DISCORD_GUILD_RUNTIME_CONFIG_FIELD_NAMES)) {
return validationError("Runtime config has unknown fields.")
}
if (
typeof value.discordGuildId !== "string" ||
!isDiscordSnowflake(value.discordGuildId)
) {
return validationError("Runtime config has invalid Discord guild ID.")
}
if (
expectedDiscordGuildId !== undefined &&
value.discordGuildId !== expectedDiscordGuildId
) {
return validationError(
"Runtime config returned a different Discord guild ID."
)
}
const moderationEnabled = value.moderationEnabled
const welcomeEnabled = value.welcomeEnabled
const loggingEnabled = value.loggingEnabled
const supportEnabled = value.supportEnabled
if (typeof moderationEnabled !== "boolean") {
return validationError("Runtime config has invalid moderationEnabled.")
}
if (typeof welcomeEnabled !== "boolean") {
return validationError("Runtime config has invalid welcomeEnabled.")
}
if (typeof loggingEnabled !== "boolean") {
return validationError("Runtime config has invalid loggingEnabled.")
}
if (typeof supportEnabled !== "boolean") {
return validationError("Runtime config has invalid supportEnabled.")
}
const logLevel = value.logLevel
const liveNotificationsEnabled = value.liveNotificationsEnabled
const liveNotificationMentionMode = value.liveNotificationMentionMode
if (
liveNotificationsEnabled !== undefined &&
typeof liveNotificationsEnabled !== "boolean"
)
return validationError("Invalid live notification enabled state.")
if (
liveNotificationMentionMode !== undefined &&
liveNotificationMentionMode !== "none" &&
liveNotificationMentionMode !== "everyone" &&
liveNotificationMentionMode !== "role"
)
return validationError("Invalid live notification mention mode.")
const liveNotificationChannelId = validateOptionalDiscordSnowflake(
"liveNotificationChannelId",
value.liveNotificationChannelId
)
if (!liveNotificationChannelId.success) return liveNotificationChannelId
const liveNotificationRoleId = validateOptionalDiscordSnowflake(
"liveNotificationRoleId",
value.liveNotificationRoleId
)
if (!liveNotificationRoleId.success) return liveNotificationRoleId
if (
liveNotificationsEnabled &&
(!liveNotificationChannelId.data || !liveNotificationMentionMode)
)
return validationError(
"Enabled live notifications need a channel and mention mode."
)
if (liveNotificationMentionMode === "role" && !liveNotificationRoleId.data)
return validationError("Live role notifications need a role.")
if (
liveNotificationMentionMode !== "role" &&
liveNotificationRoleId.data !== undefined
)
return validationError("Live notification role requires role mention mode.")
if (
logLevel !== undefined &&
!isDiscordGuildRuntimeConfigLogLevel(logLevel)
) {
return validationError("Runtime config has invalid log level.")
}
const logChannelId = validateOptionalDiscordSnowflake(
"logChannelId",
value.logChannelId
)
if (!logChannelId.success) {
return logChannelId
}
const modLogChannelId = validateOptionalDiscordSnowflake(
"modLogChannelId",
value.modLogChannelId
)
if (!modLogChannelId.success) {
return modLogChannelId
}
const welcomeChannelId = validateOptionalDiscordSnowflake(
"welcomeChannelId",
value.welcomeChannelId
)
if (!welcomeChannelId.success) {
return welcomeChannelId
}
const welcomeSubtext = validateOptionalText(
"welcomeSubtext",
value.welcomeSubtext
)
if (!welcomeSubtext.success) {
return welcomeSubtext
}
const updatesChannelId = validateOptionalDiscordSnowflake(
"updatesChannelId",
value.updatesChannelId
)
if (!updatesChannelId.success) {
return updatesChannelId
}
const announcementChannelId = validateOptionalDiscordSnowflake(
"announcementChannelId",
value.announcementChannelId
)
if (!announcementChannelId.success) {
return announcementChannelId
}
const supportStaffRoleIds = validateOptionalDiscordSnowflakeArray(
"supportStaffRoleIds",
value.supportStaffRoleIds
)
if (!supportStaffRoleIds.success) {
return supportStaffRoleIds
}
const supportTargetId = validateOptionalDiscordSnowflake(
"supportTargetId",
value.supportTargetId
)
if (!supportTargetId.success) {
return supportTargetId
}
const supportTargetType = value.supportTargetType
if (
supportTargetType !== undefined &&
!isDiscordGuildSupportTargetType(supportTargetType)
) {
return validationError("Runtime config has invalid support target type.")
}
const supportTranscriptPolicy = value.supportTranscriptPolicy
if (
supportTranscriptPolicy !== undefined &&
!isDiscordGuildSupportTranscriptPolicy(supportTranscriptPolicy)
) {
return validationError(
"Runtime config has invalid support transcript policy."
)
}
const supportEscalationPolicy = value.supportEscalationPolicy
if (
supportEscalationPolicy !== undefined &&
!isDiscordGuildSupportEscalationPolicy(supportEscalationPolicy)
) {
return validationError(
"Runtime config has invalid support escalation policy."
)
}
return {
success: true,
data: {
discordGuildId: value.discordGuildId,
moderationEnabled,
welcomeEnabled,
loggingEnabled,
supportEnabled,
...(liveNotificationsEnabled !== undefined
? { liveNotificationsEnabled }
: {}),
...(liveNotificationMentionMode !== undefined
? { liveNotificationMentionMode }
: {}),
...(liveNotificationChannelId.data !== undefined
? { liveNotificationChannelId: liveNotificationChannelId.data }
: {}),
...(liveNotificationRoleId.data !== undefined
? { liveNotificationRoleId: liveNotificationRoleId.data }
: {}),
...(logLevel !== undefined ? { logLevel } : {}),
...(logChannelId.data !== undefined
? { logChannelId: logChannelId.data }
: {}),
...(modLogChannelId.data !== undefined
? { modLogChannelId: modLogChannelId.data }
: {}),
...(welcomeChannelId.data !== undefined
? { welcomeChannelId: welcomeChannelId.data }
: {}),
...(welcomeSubtext.data !== undefined
? { welcomeSubtext: welcomeSubtext.data }
: {}),
...(updatesChannelId.data !== undefined
? { updatesChannelId: updatesChannelId.data }
: {}),
...(announcementChannelId.data !== undefined
? { announcementChannelId: announcementChannelId.data }
: {}),
...(supportStaffRoleIds.data !== undefined
? { supportStaffRoleIds: supportStaffRoleIds.data }
: {}),
...(supportTargetId.data !== undefined
? { supportTargetId: supportTargetId.data }
: {}),
...(supportTargetType !== undefined ? { supportTargetType } : {}),
...(supportTranscriptPolicy !== undefined
? { supportTranscriptPolicy }
: {}),
...(supportEscalationPolicy !== undefined
? { supportEscalationPolicy }
: {}),
},
}
}
function validateOptionalDiscordSnowflakeArray(
fieldName: string,
value: unknown
):
| {
success: true
data?: string[]
}
| {
success: false
error: string
} {
if (value === undefined) {
return { success: true }
}
if (
!Array.isArray(value) ||
value.length > 20 ||
value.some(
(item) => typeof item !== "string" || !isDiscordSnowflake(item)
) ||
new Set(value).size !== value.length
) {
return validationError(`Runtime config has invalid ${fieldName}.`)
}
return {
success: true,
data: value,
}
}
function validateOptionalDiscordSnowflake(
fieldName: string,
value: unknown
):
| {
success: true
data?: string
}
| {
success: false
error: string
} {
if (value === undefined) {
return { success: true }
}
if (typeof value !== "string" || !isDiscordSnowflake(value)) {
return validationError(`Runtime config has invalid ${fieldName}.`)
}
return {
success: true,
data: value,
}
}
function validateOptionalText(
fieldName: string,
value: unknown
):
| {
success: true
data?: string
}
| {
success: false
error: string
} {
if (value === undefined) {
return { success: true }
}
if (
typeof value !== "string" ||
value.trim().length === 0 ||
value.length > 120
) {
return validationError(`Runtime config has invalid ${fieldName}.`)
}
return {
success: true,
data: value,
}
}
function validationError(error: string): {
success: false
error: string
} {
return {
success: false,
error,
}
}
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value)
}
function hasOnlyKeys(
value: Record<string, unknown>,
allowedKeys: readonly string[]
): boolean {
return Object.keys(value).every((key) => allowedKeys.includes(key))
}
|