@awsesh/core 1.0.0-alpha.202512240821 → 1.0.0-alpha.202601080928
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/credentials.d.ts +6 -0
- package/index.d.ts +19 -1
- package/index.js +125 -25
- package/package.json +1 -1
- package/types.d.ts +12 -0
package/credentials.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ export interface WriteCredentialsOptions {
|
|
|
5
5
|
credentials: RoleCredentials;
|
|
6
6
|
region?: string;
|
|
7
7
|
}
|
|
8
|
+
export interface RemoveProfileOptions {
|
|
9
|
+
awsDir: string;
|
|
10
|
+
profileName: string;
|
|
11
|
+
}
|
|
8
12
|
export declare namespace Credentials {
|
|
9
13
|
function write(options: WriteCredentialsOptions): Promise<void>;
|
|
14
|
+
function removeProfile(options: RemoveProfileOptions): Promise<void>;
|
|
15
|
+
function listProfiles(awsDir: string): Promise<string[]>;
|
|
10
16
|
}
|
package/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { AWSClient } from "./client";
|
|
|
3
3
|
export { Credentials } from "./credentials";
|
|
4
4
|
export { Sessions } from "./sessions";
|
|
5
5
|
export { Storage } from "./storage";
|
|
6
|
-
import type { AwseshOptions, SSOSession, SSOLoginInfo, TokenCache, AccountCache, RoleCredentials, LastSelected, ActiveCredential } from "./types";
|
|
6
|
+
import type { AwseshOptions, SSOSession, SSOLoginInfo, TokenCache, AccountCache, RoleCredentials, LastSelected, LastSelectedPerSession, ActiveCredential, LastSetCredential } from "./types";
|
|
7
7
|
export declare function createAwsesh(options: AwseshOptions): {
|
|
8
8
|
sessions: {
|
|
9
9
|
list: () => Promise<SSOSession[]>;
|
|
@@ -24,7 +24,9 @@ export declare function createAwsesh(options: AwseshOptions): {
|
|
|
24
24
|
};
|
|
25
25
|
tokens: {
|
|
26
26
|
get: (startUrl: string) => Promise<TokenCache | undefined>;
|
|
27
|
+
getWithExpired: (startUrl: string) => Promise<TokenCache | undefined>;
|
|
27
28
|
save: (startUrl: string, token: string, expiresAt: Date) => Promise<void>;
|
|
29
|
+
remove: (startUrl: string) => Promise<void>;
|
|
28
30
|
isValid: (cache: TokenCache) => boolean;
|
|
29
31
|
};
|
|
30
32
|
accounts: {
|
|
@@ -35,6 +37,15 @@ export declare function createAwsesh(options: AwseshOptions): {
|
|
|
35
37
|
get: () => Promise<LastSelected>;
|
|
36
38
|
save: (selected: Partial<LastSelected>) => Promise<void>;
|
|
37
39
|
};
|
|
40
|
+
lastSession: {
|
|
41
|
+
get: () => Promise<string | undefined>;
|
|
42
|
+
save: (sessionName: string) => Promise<void>;
|
|
43
|
+
};
|
|
44
|
+
lastAccountPerSession: {
|
|
45
|
+
get: (sessionName: string) => Promise<string | undefined>;
|
|
46
|
+
save: (sessionName: string, accountId: string) => Promise<void>;
|
|
47
|
+
getAll: () => Promise<LastSelectedPerSession>;
|
|
48
|
+
};
|
|
38
49
|
profileNames: {
|
|
39
50
|
get: (sessionName: string, accountName: string, roleName: string) => Promise<string | undefined>;
|
|
40
51
|
save: (sessionName: string, accountName: string, roleName: string, profileName: string) => Promise<void>;
|
|
@@ -48,6 +59,8 @@ export declare function createAwsesh(options: AwseshOptions): {
|
|
|
48
59
|
};
|
|
49
60
|
credentials: {
|
|
50
61
|
write: (profileName: string, creds: RoleCredentials, region?: string) => Promise<void>;
|
|
62
|
+
removeProfile: (profileName: string) => Promise<void>;
|
|
63
|
+
listProfiles: () => Promise<string[]>;
|
|
51
64
|
};
|
|
52
65
|
activeCredentials: {
|
|
53
66
|
list: () => Promise<ActiveCredential[]>;
|
|
@@ -56,5 +69,10 @@ export declare function createAwsesh(options: AwseshOptions): {
|
|
|
56
69
|
cleanup: () => Promise<void>;
|
|
57
70
|
remove: (accountId: string, roleName: string) => Promise<void>;
|
|
58
71
|
};
|
|
72
|
+
lastSetCredential: {
|
|
73
|
+
get: () => Promise<LastSetCredential | undefined>;
|
|
74
|
+
save: (credential: LastSetCredential) => Promise<void>;
|
|
75
|
+
clear: () => Promise<void>;
|
|
76
|
+
};
|
|
59
77
|
};
|
|
60
78
|
export type Awsesh = ReturnType<typeof createAwsesh>;
|
package/index.js
CHANGED
|
@@ -19971,6 +19971,36 @@ class AWSClient {
|
|
|
19971
19971
|
// src/credentials.ts
|
|
19972
19972
|
import path from "node:path";
|
|
19973
19973
|
import fs from "node:fs/promises";
|
|
19974
|
+
function parseCredentialsFile(content) {
|
|
19975
|
+
const lines = content.split(`
|
|
19976
|
+
`);
|
|
19977
|
+
const sections = {};
|
|
19978
|
+
let currentSection = "";
|
|
19979
|
+
for (const line of lines) {
|
|
19980
|
+
const trimmed = line.trim();
|
|
19981
|
+
if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
|
19982
|
+
currentSection = trimmed.slice(1, -1);
|
|
19983
|
+
sections[currentSection] = sections[currentSection] || {};
|
|
19984
|
+
} else if (trimmed && currentSection && trimmed.includes("=")) {
|
|
19985
|
+
const [key, ...valueParts] = trimmed.split("=");
|
|
19986
|
+
sections[currentSection][key.trim()] = valueParts.join("=").trim();
|
|
19987
|
+
}
|
|
19988
|
+
}
|
|
19989
|
+
return sections;
|
|
19990
|
+
}
|
|
19991
|
+
function serializeCredentialsFile(sections) {
|
|
19992
|
+
const content = Object.entries(sections).map(([section, values]) => {
|
|
19993
|
+
const header = `[${section}]`;
|
|
19994
|
+
const entries = Object.entries(values).map(([k, v]) => `${k} = ${v}`).join(`
|
|
19995
|
+
`);
|
|
19996
|
+
return `${header}
|
|
19997
|
+
${entries}`;
|
|
19998
|
+
}).join(`
|
|
19999
|
+
|
|
20000
|
+
`);
|
|
20001
|
+
return `${content}
|
|
20002
|
+
`;
|
|
20003
|
+
}
|
|
19974
20004
|
var Credentials;
|
|
19975
20005
|
((Credentials) => {
|
|
19976
20006
|
async function write(options) {
|
|
@@ -19981,20 +20011,7 @@ var Credentials;
|
|
|
19981
20011
|
try {
|
|
19982
20012
|
content = await fs.readFile(credentialsPath, "utf-8");
|
|
19983
20013
|
} catch {}
|
|
19984
|
-
const
|
|
19985
|
-
`);
|
|
19986
|
-
const sections = {};
|
|
19987
|
-
let currentSection = "";
|
|
19988
|
-
for (const line of lines) {
|
|
19989
|
-
const trimmed = line.trim();
|
|
19990
|
-
if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
|
19991
|
-
currentSection = trimmed.slice(1, -1);
|
|
19992
|
-
sections[currentSection] = sections[currentSection] || {};
|
|
19993
|
-
} else if (trimmed && currentSection && trimmed.includes("=")) {
|
|
19994
|
-
const [key, ...valueParts] = trimmed.split("=");
|
|
19995
|
-
sections[currentSection][key.trim()] = valueParts.join("=").trim();
|
|
19996
|
-
}
|
|
19997
|
-
}
|
|
20014
|
+
const sections = parseCredentialsFile(content);
|
|
19998
20015
|
sections[profileName] = {
|
|
19999
20016
|
aws_access_key_id: credentials.accessKeyId,
|
|
20000
20017
|
aws_secret_access_key: credentials.secretAccessKey,
|
|
@@ -20003,19 +20020,42 @@ var Credentials;
|
|
|
20003
20020
|
if (region) {
|
|
20004
20021
|
sections[profileName].region = region;
|
|
20005
20022
|
}
|
|
20006
|
-
|
|
20007
|
-
const header = `[${section}]`;
|
|
20008
|
-
const entries = Object.entries(values).map(([k, v]) => `${k} = ${v}`).join(`
|
|
20009
|
-
`);
|
|
20010
|
-
return `${header}
|
|
20011
|
-
${entries}`;
|
|
20012
|
-
}).join(`
|
|
20013
|
-
|
|
20014
|
-
`);
|
|
20015
|
-
await fs.writeFile(credentialsPath, `${newContent}
|
|
20016
|
-
`);
|
|
20023
|
+
await fs.writeFile(credentialsPath, serializeCredentialsFile(sections));
|
|
20017
20024
|
}
|
|
20018
20025
|
Credentials.write = write;
|
|
20026
|
+
async function removeProfile(options) {
|
|
20027
|
+
const { awsDir, profileName } = options;
|
|
20028
|
+
const credentialsPath = path.join(awsDir, "credentials");
|
|
20029
|
+
let content = "";
|
|
20030
|
+
try {
|
|
20031
|
+
content = await fs.readFile(credentialsPath, "utf-8");
|
|
20032
|
+
} catch {
|
|
20033
|
+
return;
|
|
20034
|
+
}
|
|
20035
|
+
const sections = parseCredentialsFile(content);
|
|
20036
|
+
if (!sections[profileName]) {
|
|
20037
|
+
return;
|
|
20038
|
+
}
|
|
20039
|
+
delete sections[profileName];
|
|
20040
|
+
if (Object.keys(sections).length === 0) {
|
|
20041
|
+
await fs.writeFile(credentialsPath, "");
|
|
20042
|
+
return;
|
|
20043
|
+
}
|
|
20044
|
+
await fs.writeFile(credentialsPath, serializeCredentialsFile(sections));
|
|
20045
|
+
}
|
|
20046
|
+
Credentials.removeProfile = removeProfile;
|
|
20047
|
+
async function listProfiles(awsDir) {
|
|
20048
|
+
const credentialsPath = path.join(awsDir, "credentials");
|
|
20049
|
+
let content = "";
|
|
20050
|
+
try {
|
|
20051
|
+
content = await fs.readFile(credentialsPath, "utf-8");
|
|
20052
|
+
} catch {
|
|
20053
|
+
return [];
|
|
20054
|
+
}
|
|
20055
|
+
const sections = parseCredentialsFile(content);
|
|
20056
|
+
return Object.keys(sections);
|
|
20057
|
+
}
|
|
20058
|
+
Credentials.listProfiles = listProfiles;
|
|
20019
20059
|
})(Credentials ||= {});
|
|
20020
20060
|
// src/sessions.ts
|
|
20021
20061
|
import path2 from "node:path";
|
|
@@ -20214,6 +20254,17 @@ function createAwsesh(options) {
|
|
|
20214
20254
|
startUrl: data.startUrl
|
|
20215
20255
|
};
|
|
20216
20256
|
},
|
|
20257
|
+
getWithExpired: async (startUrl) => {
|
|
20258
|
+
const hash = hashUrl(startUrl);
|
|
20259
|
+
const data = await storage.read(`token/${hash}`);
|
|
20260
|
+
if (!data)
|
|
20261
|
+
return;
|
|
20262
|
+
return {
|
|
20263
|
+
token: data.token,
|
|
20264
|
+
expiresAt: new Date(data.expiresAt),
|
|
20265
|
+
startUrl: data.startUrl
|
|
20266
|
+
};
|
|
20267
|
+
},
|
|
20217
20268
|
save: async (startUrl, token, expiresAt) => {
|
|
20218
20269
|
const hash = hashUrl(startUrl);
|
|
20219
20270
|
await storage.write(`token/${hash}`, {
|
|
@@ -20222,6 +20273,10 @@ function createAwsesh(options) {
|
|
|
20222
20273
|
startUrl
|
|
20223
20274
|
});
|
|
20224
20275
|
},
|
|
20276
|
+
remove: async (startUrl) => {
|
|
20277
|
+
const hash = hashUrl(startUrl);
|
|
20278
|
+
await storage.remove(`token/${hash}`);
|
|
20279
|
+
},
|
|
20225
20280
|
isValid: (cache) => {
|
|
20226
20281
|
return cache.expiresAt > new Date;
|
|
20227
20282
|
}
|
|
@@ -20242,6 +20297,31 @@ function createAwsesh(options) {
|
|
|
20242
20297
|
}));
|
|
20243
20298
|
}
|
|
20244
20299
|
},
|
|
20300
|
+
lastSession: {
|
|
20301
|
+
get: async () => {
|
|
20302
|
+
const data = await storage.read("preference/last-session");
|
|
20303
|
+
return data?.session;
|
|
20304
|
+
},
|
|
20305
|
+
save: async (sessionName) => {
|
|
20306
|
+
await storage.write("preference/last-session", { session: sessionName });
|
|
20307
|
+
}
|
|
20308
|
+
},
|
|
20309
|
+
lastAccountPerSession: {
|
|
20310
|
+
get: async (sessionName) => {
|
|
20311
|
+
const data = await storage.read("preference/last-accounts");
|
|
20312
|
+
return data?.[sessionName];
|
|
20313
|
+
},
|
|
20314
|
+
save: async (sessionName, accountId) => {
|
|
20315
|
+
await storage.update("preference/last-accounts", (draft) => {
|
|
20316
|
+
draft[sessionName] = accountId;
|
|
20317
|
+
return draft;
|
|
20318
|
+
});
|
|
20319
|
+
},
|
|
20320
|
+
getAll: async () => {
|
|
20321
|
+
const data = await storage.read("preference/last-accounts");
|
|
20322
|
+
return data ?? {};
|
|
20323
|
+
}
|
|
20324
|
+
},
|
|
20245
20325
|
profileNames: {
|
|
20246
20326
|
get: async (sessionName, accountName, roleName) => {
|
|
20247
20327
|
const data = await storage.read("preference/profile-names");
|
|
@@ -20302,6 +20382,15 @@ function createAwsesh(options) {
|
|
|
20302
20382
|
credentials: creds,
|
|
20303
20383
|
region
|
|
20304
20384
|
});
|
|
20385
|
+
},
|
|
20386
|
+
removeProfile: async (profileName) => {
|
|
20387
|
+
await Credentials.removeProfile({
|
|
20388
|
+
awsDir,
|
|
20389
|
+
profileName
|
|
20390
|
+
});
|
|
20391
|
+
},
|
|
20392
|
+
listProfiles: async () => {
|
|
20393
|
+
return Credentials.listProfiles(awsDir);
|
|
20305
20394
|
}
|
|
20306
20395
|
},
|
|
20307
20396
|
activeCredentials: {
|
|
@@ -20342,6 +20431,17 @@ function createAwsesh(options) {
|
|
|
20342
20431
|
return existing.filter((c) => !(c.accountId === accountId && c.roleName === roleName));
|
|
20343
20432
|
});
|
|
20344
20433
|
}
|
|
20434
|
+
},
|
|
20435
|
+
lastSetCredential: {
|
|
20436
|
+
get: async () => {
|
|
20437
|
+
return storage.read("credentials/last-set");
|
|
20438
|
+
},
|
|
20439
|
+
save: async (credential) => {
|
|
20440
|
+
await storage.write("credentials/last-set", credential);
|
|
20441
|
+
},
|
|
20442
|
+
clear: async () => {
|
|
20443
|
+
await storage.remove("credentials/last-set");
|
|
20444
|
+
}
|
|
20345
20445
|
}
|
|
20346
20446
|
};
|
|
20347
20447
|
}
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -52,6 +52,9 @@ export interface LastSelected {
|
|
|
52
52
|
account?: string;
|
|
53
53
|
role?: string;
|
|
54
54
|
}
|
|
55
|
+
export interface LastSelectedPerSession {
|
|
56
|
+
[sessionName: string]: string;
|
|
57
|
+
}
|
|
55
58
|
export interface ActiveCredential {
|
|
56
59
|
profileName: string;
|
|
57
60
|
accountId: string;
|
|
@@ -61,3 +64,12 @@ export interface ActiveCredential {
|
|
|
61
64
|
expiration: string;
|
|
62
65
|
isDefault: boolean;
|
|
63
66
|
}
|
|
67
|
+
export interface LastSetCredential {
|
|
68
|
+
profileName: string;
|
|
69
|
+
accountId: string;
|
|
70
|
+
accountName: string;
|
|
71
|
+
roleName: string;
|
|
72
|
+
sessionName: string;
|
|
73
|
+
region?: string;
|
|
74
|
+
setAt: string;
|
|
75
|
+
}
|