@zhafron/opencode-kiro-auth 1.2.7 → 1.3.0
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.
- package/README.md +31 -45
- package/dist/index.d.ts +1 -1
- package/dist/kiro/auth.js +15 -6
- package/dist/plugin/accounts.d.ts +2 -1
- package/dist/plugin/accounts.js +43 -20
- package/dist/plugin/cli.js +1 -1
- package/dist/plugin/config/index.d.ts +2 -2
- package/dist/plugin/config/index.js +2 -2
- package/dist/plugin/config/loader.js +3 -3
- package/dist/plugin/config/schema.d.ts +3 -0
- package/dist/plugin/config/schema.js +2 -0
- package/dist/plugin/request.d.ts +1 -1
- package/dist/plugin/request.js +77 -16
- package/dist/plugin/response.d.ts +1 -1
- package/dist/plugin/server.js +1 -1
- package/dist/plugin/storage/migration.d.ts +1 -0
- package/dist/plugin/storage/migration.js +53 -0
- package/dist/plugin/storage/sqlite.d.ts +16 -0
- package/dist/plugin/storage/sqlite.js +104 -0
- package/dist/plugin/sync/kiro-cli.d.ts +2 -0
- package/dist/plugin/sync/kiro-cli.js +96 -0
- package/dist/plugin/token.js +29 -17
- package/dist/plugin/types.d.ts +1 -27
- package/dist/plugin/usage.d.ts +1 -1
- package/dist/plugin.js +173 -249
- package/package.json +3 -2
- package/dist/plugin/storage.d.ts +0 -7
- package/dist/plugin/storage.js +0 -124
package/dist/plugin/storage.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
import { randomBytes } from 'node:crypto';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
5
|
-
import lockfile from 'proper-lockfile';
|
|
6
|
-
import * as logger from './logger';
|
|
7
|
-
const LOCK_OPTIONS = {
|
|
8
|
-
stale: 10000,
|
|
9
|
-
retries: { retries: 5, minTimeout: 100, maxTimeout: 1000, factor: 2 }
|
|
10
|
-
};
|
|
11
|
-
function getBaseDir() {
|
|
12
|
-
const platform = process.platform;
|
|
13
|
-
if (platform === 'win32') {
|
|
14
|
-
return join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), 'opencode');
|
|
15
|
-
}
|
|
16
|
-
const xdgConfig = process.env.XDG_CONFIG_HOME || join(homedir(), '.config');
|
|
17
|
-
return join(xdgConfig, 'opencode');
|
|
18
|
-
}
|
|
19
|
-
export function getStoragePath() {
|
|
20
|
-
return join(getBaseDir(), 'kiro-accounts.json');
|
|
21
|
-
}
|
|
22
|
-
export function getUsagePath() {
|
|
23
|
-
return join(getBaseDir(), 'kiro-usage.json');
|
|
24
|
-
}
|
|
25
|
-
async function withLock(path, fn) {
|
|
26
|
-
try {
|
|
27
|
-
await fs.mkdir(dirname(path), { recursive: true });
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
logger.error(`Failed to create directory ${dirname(path)}`, error);
|
|
31
|
-
throw error;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
await fs.access(path);
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
try {
|
|
38
|
-
await fs.writeFile(path, '{}');
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
logger.error(`Failed to initialize file ${path}`, error);
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
let release = null;
|
|
46
|
-
try {
|
|
47
|
-
release = await lockfile.lock(path, LOCK_OPTIONS);
|
|
48
|
-
return await fn();
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
logger.error(`File lock failed for ${path}`, error);
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
finally {
|
|
55
|
-
if (release) {
|
|
56
|
-
try {
|
|
57
|
-
await release();
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
logger.warn(`Failed to release lock for ${path}`, error);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export async function loadAccounts() {
|
|
66
|
-
const path = getStoragePath();
|
|
67
|
-
return withLock(path, async () => {
|
|
68
|
-
try {
|
|
69
|
-
const content = await fs.readFile(path, 'utf-8');
|
|
70
|
-
const parsed = JSON.parse(content);
|
|
71
|
-
if (!parsed || !Array.isArray(parsed.accounts)) {
|
|
72
|
-
return { version: 1, accounts: [], activeIndex: -1 };
|
|
73
|
-
}
|
|
74
|
-
return parsed;
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
return { version: 1, accounts: [], activeIndex: -1 };
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
export async function saveAccounts(storage) {
|
|
82
|
-
const path = getStoragePath();
|
|
83
|
-
try {
|
|
84
|
-
await withLock(path, async () => {
|
|
85
|
-
const tmp = `${path}.${randomBytes(6).toString('hex')}.tmp`;
|
|
86
|
-
await fs.writeFile(tmp, JSON.stringify(storage, null, 2));
|
|
87
|
-
await fs.rename(tmp, path);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
logger.error(`Failed to save accounts to ${path}`, error);
|
|
92
|
-
throw error;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
export async function loadUsage() {
|
|
96
|
-
const path = getUsagePath();
|
|
97
|
-
return withLock(path, async () => {
|
|
98
|
-
try {
|
|
99
|
-
const content = await fs.readFile(path, 'utf-8');
|
|
100
|
-
const parsed = JSON.parse(content);
|
|
101
|
-
if (!parsed || typeof parsed.usage !== 'object' || parsed.usage === null) {
|
|
102
|
-
return { version: 1, usage: {} };
|
|
103
|
-
}
|
|
104
|
-
return parsed;
|
|
105
|
-
}
|
|
106
|
-
catch {
|
|
107
|
-
return { version: 1, usage: {} };
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
export async function saveUsage(storage) {
|
|
112
|
-
const path = getUsagePath();
|
|
113
|
-
try {
|
|
114
|
-
await withLock(path, async () => {
|
|
115
|
-
const tmp = `${path}.${randomBytes(6).toString('hex')}.tmp`;
|
|
116
|
-
await fs.writeFile(tmp, JSON.stringify(storage, null, 2));
|
|
117
|
-
await fs.rename(tmp, path);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
logger.error(`Failed to save usage to ${path}`, error);
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
}
|