Skip to content

Commit 9dc669c

Browse files
committed
unify encrypted storage under getItem/setItem
1 parent 7c911d6 commit 9dc669c

1 file changed

Lines changed: 25 additions & 41 deletions

File tree

src/index.ts

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -211,45 +211,6 @@ export async function openExternal(link: string): Promise<void> {
211211
return await request({ name: "openExternal", args: { link } });
212212
}
213213

214-
/** @since Beekeeper Studio 5.3.0 */
215-
export async function getEncryptedData<T>(key: string): Promise<T> {
216-
return await request({ name: "getEncryptedData", args: { key } });
217-
}
218-
219-
/**
220-
* Store encrypted data that can be retrieved later.
221-
*
222-
* @example
223-
* // Store with custom key
224-
* await setEncryptedData("secretKey", { token: "abc123" });
225-
*
226-
* // Store with default key (equivalent to setEncryptedData("default", value))
227-
* await setEncryptedData({ token: "abc123" });
228-
*
229-
* @since Beekeeper Studio 5.3.0
230-
*/
231-
export async function setEncryptedData<T = unknown>(
232-
key: string,
233-
value: T,
234-
): Promise<void>;
235-
export async function setEncryptedData<T = unknown>(value: T): Promise<void>;
236-
export async function setEncryptedData<T = unknown>(
237-
keyOrValue: string | T,
238-
value?: T,
239-
): Promise<void> {
240-
if (value !== undefined) {
241-
return await request({
242-
name: "setEncryptedData",
243-
args: { key: keyOrValue as string, value },
244-
});
245-
} else {
246-
return await request({
247-
name: "setEncryptedData",
248-
args: { key: "default", value: keyOrValue as T },
249-
});
250-
}
251-
}
252-
253214
/** @since Beekeeper Studio 5.4.0 */
254215
export async function openTab(
255216
type: "query",
@@ -375,10 +336,33 @@ export const clipboard = {
375336
* @since Beekeeper Studio 5.3.0
376337
**/
377338
export const appStorage = {
378-
async getItem<T = unknown>(key: string): Promise<T | null> {
339+
async getItem<T = unknown>(
340+
key: string,
341+
options?: {
342+
encrypted: boolean;
343+
},
344+
): Promise<T | null> {
345+
if (options?.encrypted) {
346+
return await request({
347+
name: "getEncryptedData",
348+
args: { key },
349+
});
350+
}
379351
return await request({ name: "getData", args: { key } });
380352
},
381-
async setItem<T = unknown>(key: string, value: T): Promise<void> {
353+
async setItem<T = unknown>(
354+
key: string,
355+
value: T,
356+
options?: {
357+
encrypted: boolean;
358+
},
359+
): Promise<void> {
360+
if (options?.encrypted) {
361+
return await request({
362+
name: "setEncryptedData",
363+
args: { key, value },
364+
});
365+
}
382366
return await request({ name: "setData", args: { key, value } });
383367
},
384368
// TODO

0 commit comments

Comments
 (0)