( app: App | undefined, command: IUserScript, settingName: string, value: string, option?: UserScriptOptionDefinition, )
| 600 | } |
| 601 | |
| 602 | async function buildAvailableSecretRef( |
| 603 | app: App | undefined, |
| 604 | command: IUserScript, |
| 605 | settingName: string, |
| 606 | value: string, |
| 607 | option?: UserScriptOptionDefinition, |
| 608 | ): Promise<string> { |
| 609 | const commandId = command.id?.trim() || command.path || command.name || "script"; |
| 610 | const commandPart = normalizeSecretIdPart(commandId); |
| 611 | const settingPart = normalizeSecretIdPart(getSecretSettingId(settingName, option)); |
| 612 | let candidate = fitSecretId(commandPart, settingPart); |
| 613 | let suffix = 1; |
| 614 | |
| 615 | while (true) { |
| 616 | const existing = await readSecretStorageEntry(app, candidate); |
| 617 | if (!existing || existing === value) return candidate; |
| 618 | |
| 619 | suffix += 1; |
| 620 | candidate = fitSecretId(commandPart, settingPart, String(suffix)); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | export async function storeUserScriptSecret( |
| 625 | app: App | undefined, |
no test coverage detected