edilkamin 1.6.2 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,78 @@
1
+ import { promises as fs } from "fs";
2
+ import * as os from "os";
3
+ import * as path from "path";
4
+
5
+ const TOKEN_DIR = path.join(os.homedir(), ".edilkamin");
6
+ const TOKEN_FILE = path.join(TOKEN_DIR, "session.json");
7
+
8
+ interface StoredData {
9
+ [key: string]: string;
10
+ }
11
+
12
+ /**
13
+ * Custom storage adapter for AWS Amplify that persists to file system.
14
+ * Used for CLI to maintain sessions between invocations.
15
+ */
16
+ export const createFileStorage = () => {
17
+ let cache: StoredData = {};
18
+ let loaded = false;
19
+
20
+ const ensureDir = async (): Promise<void> => {
21
+ try {
22
+ await fs.mkdir(TOKEN_DIR, { recursive: true, mode: 0o700 });
23
+ } catch {
24
+ // Directory may already exist
25
+ }
26
+ };
27
+
28
+ const load = async (): Promise<void> => {
29
+ if (loaded) return;
30
+ try {
31
+ const data = await fs.readFile(TOKEN_FILE, "utf-8");
32
+ cache = JSON.parse(data);
33
+ } catch {
34
+ cache = {};
35
+ }
36
+ loaded = true;
37
+ };
38
+
39
+ const save = async (): Promise<void> => {
40
+ await ensureDir();
41
+ await fs.writeFile(TOKEN_FILE, JSON.stringify(cache), {
42
+ encoding: "utf-8",
43
+ mode: 0o600,
44
+ });
45
+ };
46
+
47
+ return {
48
+ setItem: async (key: string, value: string): Promise<void> => {
49
+ await load();
50
+ cache[key] = value;
51
+ await save();
52
+ },
53
+ getItem: async (key: string): Promise<string | null> => {
54
+ await load();
55
+ return cache[key] ?? null;
56
+ },
57
+ removeItem: async (key: string): Promise<void> => {
58
+ await load();
59
+ delete cache[key];
60
+ await save();
61
+ },
62
+ clear: async (): Promise<void> => {
63
+ cache = {};
64
+ await save();
65
+ },
66
+ };
67
+ };
68
+
69
+ /**
70
+ * Clears all stored session data.
71
+ */
72
+ export const clearSession = async (): Promise<void> => {
73
+ try {
74
+ await fs.unlink(TOKEN_FILE);
75
+ } catch {
76
+ // File may not exist
77
+ }
78
+ };