|
2 | 2 | import { |
3 | 3 | collectNestedChannelFieldAssignments, |
4 | 4 | collectSimpleChannelFieldAssignments, |
5 | | - getChannelSurface, |
| 5 | + getChannelRecord, |
| 6 | + hasConfiguredSecretInputValue, |
6 | 7 | isBaseFieldActiveForChannelSurface, |
7 | 8 | isEnabledFlag, |
8 | 9 | isRecord, |
| 10 | + resolveChannelAccountSurface, |
| 11 | + type ChannelAccountSurface, |
9 | 12 | type ResolverContext, |
10 | 13 | type SecretDefaults, |
11 | 14 | type SecretTargetRegistryEntry, |
@@ -83,16 +86,47 @@ export const secretTargetRegistryEntries: SecretTargetRegistryEntry[] = [ |
83 | 86 | }, |
84 | 87 | ]; |
85 | 88 |
|
| 89 | +function withImplicitDefaultDiscordAccount(params: { |
| 90 | + discord: Record<string, unknown>; |
| 91 | + surface: ChannelAccountSurface; |
| 92 | + defaults?: SecretDefaults; |
| 93 | +}): ChannelAccountSurface { |
| 94 | + if ( |
| 95 | + !params.surface.hasExplicitAccounts || |
| 96 | + !hasConfiguredSecretInputValue(params.discord.token, params.defaults) || |
| 97 | + params.surface.accounts.some((entry) => entry.accountId.toLowerCase() === "default") |
| 98 | + ) { |
| 99 | + return params.surface; |
| 100 | + } |
| 101 | + // Discord account listing keeps a top-level token as an implicit default account. |
| 102 | + // Match that runtime contract so named accounts do not orphan the default SecretRef. |
| 103 | + return { |
| 104 | + ...params.surface, |
| 105 | + accounts: [ |
| 106 | + ...params.surface.accounts, |
| 107 | + { |
| 108 | + accountId: "default", |
| 109 | + account: {}, |
| 110 | + enabled: params.surface.channelEnabled, |
| 111 | + }, |
| 112 | + ], |
| 113 | + }; |
| 114 | +} |
| 115 | + |
86 | 116 | export function collectRuntimeConfigAssignments(params: { |
87 | 117 | config: { channels?: Record<string, unknown> }; |
88 | 118 | defaults?: SecretDefaults; |
89 | 119 | context: ResolverContext; |
90 | 120 | }): void { |
91 | | - const resolved = getChannelSurface(params.config, "discord"); |
92 | | - if (!resolved) { |
| 121 | + const discord = getChannelRecord(params.config, "discord"); |
| 122 | + if (!discord) { |
93 | 123 | return; |
94 | 124 | } |
95 | | - const { channel: discord, surface } = resolved; |
| 125 | + const surface = withImplicitDefaultDiscordAccount({ |
| 126 | + discord, |
| 127 | + surface: resolveChannelAccountSurface(discord), |
| 128 | + defaults: params.defaults, |
| 129 | + }); |
96 | 130 | collectSimpleChannelFieldAssignments({ |
97 | 131 | channelKey: "discord", |
98 | 132 | field: "token", |
|
0 commit comments