( app: App | undefined, command: IUserScript, userScriptSettings: UserScriptSettingsDefinition | undefined, )
| 674 | } |
| 675 | |
| 676 | export async function resolveUserScriptSettings( |
| 677 | app: App | undefined, |
| 678 | command: IUserScript, |
| 679 | userScriptSettings: UserScriptSettingsDefinition | undefined, |
| 680 | ): Promise<Record<string, unknown>> { |
| 681 | const commandSettings = command.settings ?? {}; |
| 682 | const resolvedSettings = { ...commandSettings }; |
| 683 | const secretOptionNames = new Set(getSecretOptionNames(userScriptSettings)); |
| 684 | |
| 685 | for (const [name, value] of Object.entries(commandSettings)) { |
| 686 | if (isUserScriptSecretRef(value)) { |
| 687 | const secret = await readSecretStorageEntry(app, value.secretRef); |
| 688 | if (secret) { |
| 689 | resolvedSettings[name] = secret; |
| 690 | continue; |
| 691 | } |
| 692 | |
| 693 | throw new Error( |
| 694 | `Secret setting "${name}" for user script "${command.name}" is unavailable. Re-enter it on this device.`, |
| 695 | ); |
| 696 | } |
| 697 | |
| 698 | if (secretOptionNames.has(name)) { |
| 699 | resolvedSettings[name] = typeof value === "string" ? value : ""; |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | return resolvedSettings; |
| 704 | } |
| 705 | |
| 706 | export async function migrateUserScriptSecretSettings( |
| 707 | app: App | undefined, |
no test coverage detected