reply-cli 0.2.0 → 0.4.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 +157 -135
- package/dist/api/headers.d.ts +4 -0
- package/dist/api/headers.js +13 -0
- package/dist/api/headers.js.map +1 -0
- package/dist/auth/oauth-flow.d.ts +38 -0
- package/dist/auth/oauth-flow.js +193 -0
- package/dist/auth/oauth-flow.js.map +1 -0
- package/dist/auth/pkce.d.ts +9 -0
- package/dist/auth/pkce.js +19 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/request-identity.d.ts +16 -0
- package/dist/auth/request-identity.js +67 -0
- package/dist/auth/request-identity.js.map +1 -0
- package/dist/auth/resolve.d.ts +23 -0
- package/dist/auth/resolve.js +55 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/status.d.ts +19 -0
- package/dist/auth/status.js +27 -0
- package/dist/auth/status.js.map +1 -0
- package/dist/auth/token.d.ts +29 -0
- package/dist/auth/token.js +39 -0
- package/dist/auth/token.js.map +1 -0
- package/dist/commands/api.d.ts +19 -0
- package/dist/commands/api.js +137 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/auth.d.ts +19 -3
- package/dist/commands/auth.js +251 -16
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/authed.d.ts +13 -0
- package/dist/commands/authed.js +20 -0
- package/dist/commands/authed.js.map +1 -0
- package/dist/commands/profile.d.ts +31 -0
- package/dist/commands/profile.js +348 -0
- package/dist/commands/profile.js.map +1 -0
- package/dist/commands/skills.d.ts +12 -0
- package/dist/commands/skills.js +138 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/commands/team.d.ts +17 -0
- package/dist/commands/team.js +146 -0
- package/dist/commands/team.js.map +1 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.js +83 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +15 -0
- package/dist/context.js +17 -0
- package/dist/context.js.map +1 -0
- package/dist/credentials/file-store.d.ts +13 -0
- package/dist/credentials/file-store.js +88 -0
- package/dist/credentials/file-store.js.map +1 -0
- package/dist/credentials/types.d.ts +25 -0
- package/dist/credentials/types.js +3 -0
- package/dist/credentials/types.js.map +1 -0
- package/dist/index.js +101 -69
- package/dist/index.js.map +1 -1
- package/dist/profile.d.ts +51 -0
- package/dist/profile.js +295 -0
- package/dist/profile.js.map +1 -0
- package/dist/skills/adapter-flat.d.ts +32 -0
- package/dist/skills/adapter-flat.js +480 -0
- package/dist/skills/adapter-flat.js.map +1 -0
- package/dist/skills/adapter-native.d.ts +22 -0
- package/dist/skills/adapter-native.js +335 -0
- package/dist/skills/adapter-native.js.map +1 -0
- package/dist/skills/detect.d.ts +21 -0
- package/dist/skills/detect.js +102 -0
- package/dist/skills/detect.js.map +1 -0
- package/dist/skills/hosts.d.ts +5 -0
- package/dist/skills/hosts.js +118 -0
- package/dist/skills/hosts.js.map +1 -0
- package/dist/skills/journal.d.ts +23 -0
- package/dist/skills/journal.js +91 -0
- package/dist/skills/journal.js.map +1 -0
- package/dist/skills/orchestrate.d.ts +27 -0
- package/dist/skills/orchestrate.js +124 -0
- package/dist/skills/orchestrate.js.map +1 -0
- package/dist/skills/packs.d.ts +16 -0
- package/dist/skills/packs.js +153 -0
- package/dist/skills/packs.js.map +1 -0
- package/dist/skills/report.d.ts +7 -0
- package/dist/skills/report.js +105 -0
- package/dist/skills/report.js.map +1 -0
- package/dist/skills/types.d.ts +80 -0
- package/dist/skills/types.js +5 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/teams.d.ts +14 -0
- package/dist/teams.js +103 -0
- package/dist/teams.js.map +1 -0
- package/dist/utils/client.d.ts +19 -34
- package/dist/utils/client.js +123 -94
- package/dist/utils/client.js.map +1 -1
- package/dist/utils/errors.d.ts +47 -0
- package/dist/utils/errors.js +86 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/output.d.ts +7 -19
- package/dist/utils/output.js +39 -81
- package/dist/utils/output.js.map +1 -1
- package/package.json +11 -25
- package/dist/commands/contacts.d.ts +0 -35
- package/dist/commands/contacts.js +0 -412
- package/dist/commands/contacts.js.map +0 -1
- package/dist/commands/email-accounts.d.ts +0 -11
- package/dist/commands/email-accounts.js +0 -97
- package/dist/commands/email-accounts.js.map +0 -1
- package/dist/commands/inbox.d.ts +0 -30
- package/dist/commands/inbox.js +0 -225
- package/dist/commands/inbox.js.map +0 -1
- package/dist/commands/lists.d.ts +0 -20
- package/dist/commands/lists.js +0 -137
- package/dist/commands/lists.js.map +0 -1
- package/dist/commands/reports.d.ts +0 -10
- package/dist/commands/reports.js +0 -70
- package/dist/commands/reports.js.map +0 -1
- package/dist/commands/schedules.d.ts +0 -6
- package/dist/commands/schedules.js +0 -59
- package/dist/commands/schedules.js.map +0 -1
- package/dist/commands/sequence-contacts.d.ts +0 -19
- package/dist/commands/sequence-contacts.js +0 -129
- package/dist/commands/sequence-contacts.js.map +0 -1
- package/dist/commands/sequences-stats.d.ts +0 -42
- package/dist/commands/sequences-stats.js +0 -99
- package/dist/commands/sequences-stats.js.map +0 -1
- package/dist/commands/sequences.d.ts +0 -22
- package/dist/commands/sequences.js +0 -211
- package/dist/commands/sequences.js.map +0 -1
- package/dist/utils/auth.d.ts +0 -2
- package/dist/utils/auth.js +0 -33
- package/dist/utils/auth.js.map +0 -1
- package/dist/utils/command.d.ts +0 -18
- package/dist/utils/command.js +0 -51
- package/dist/utils/command.js.map +0 -1
- package/dist/utils/csv.d.ts +0 -19
- package/dist/utils/csv.js +0 -118
- package/dist/utils/csv.js.map +0 -1
- package/dist/utils/pagination.d.ts +0 -22
- package/dist/utils/pagination.js +0 -37
- package/dist/utils/pagination.js.map +0 -1
- package/dist/utils/resolve.d.ts +0 -4
- package/dist/utils/resolve.js +0 -34
- package/dist/utils/resolve.js.map +0 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handle_team_clear = exports.handle_team_use = exports.handle_team_current = exports.handle_team_list = exports.team_command = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
const context_1 = require("../context");
|
|
7
|
+
const client_1 = require("../utils/client");
|
|
8
|
+
const teams_1 = require("../teams");
|
|
9
|
+
const profile_1 = require("../profile");
|
|
10
|
+
const auth_1 = require("./auth");
|
|
11
|
+
const authed_1 = require("./authed");
|
|
12
|
+
const errors_1 = require("../utils/errors");
|
|
13
|
+
const output_1 = require("../utils/output");
|
|
14
|
+
const read_globals = (cmd) => {
|
|
15
|
+
const o = cmd.optsWithGlobals();
|
|
16
|
+
return {
|
|
17
|
+
apiKey: o.apiKey, profile: o.profile,
|
|
18
|
+
teamId: o.teamId, userId: o.userId, userEmail: o.userEmail,
|
|
19
|
+
json: o.json, pretty: o.pretty,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const wants_json = (g) => Boolean(g.json || g.pretty);
|
|
23
|
+
const print_opts = (g) => ({ json: g.json, pretty: g.pretty });
|
|
24
|
+
const profile_note = (name) => name === 'default' ? '' : ` (profile: ${name})`;
|
|
25
|
+
const parse_positive_int = (v, label) => {
|
|
26
|
+
if (!/^\d+$/.test(v.trim())) {
|
|
27
|
+
throw new errors_1.UsageError(`${label} must be a positive integer.`, { code: 'usage.team', hint: `Got: ${v}` });
|
|
28
|
+
}
|
|
29
|
+
return parseInt(v.trim(), 10);
|
|
30
|
+
};
|
|
31
|
+
const handle_team_list = async (ctx, g) => {
|
|
32
|
+
const { token, headers } = await (0, authed_1.authed)(ctx, g);
|
|
33
|
+
const teams = await (0, teams_1.resolve_my_teams)({ api_base: ctx.api_base, token, headers });
|
|
34
|
+
if (wants_json(g)) {
|
|
35
|
+
(0, output_1.print)({ current_team_id: ctx.team_id ?? null, teams }, print_opts(g));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
console.log(`Teams you can act in${profile_note(ctx.profile)}`);
|
|
39
|
+
if (!teams.length) {
|
|
40
|
+
(0, output_1.info)(' (none returned)');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
for (const t of teams) {
|
|
44
|
+
const marker = t.team_id === ctx.team_id ? output_1.pc.green('*') : ' ';
|
|
45
|
+
console.log(` ${marker} ${t.team_id}${t.team_name ? ' ' + t.team_name : ''}`);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.handle_team_list = handle_team_list;
|
|
49
|
+
// Pinned team is the profile's team_id (offline). Effective team is what the
|
|
50
|
+
// server actually resolves — read from /whoami, best-effort: any failure becomes
|
|
51
|
+
// a "failed to retrieve" note rather than an error.
|
|
52
|
+
const handle_team_current = async (ctx, g) => {
|
|
53
|
+
const pinned = ctx.team_id ?? null;
|
|
54
|
+
let effective;
|
|
55
|
+
try {
|
|
56
|
+
const { token, headers } = await (0, authed_1.authed)(ctx, g);
|
|
57
|
+
const raw = await (0, client_1.create_client)(ctx.api_base, token, headers).get('/v3/whoami');
|
|
58
|
+
effective = { team_id: (0, auth_1.normalize_principal)(raw ?? {}).team_id };
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
effective = { error: e.message };
|
|
62
|
+
}
|
|
63
|
+
if (wants_json(g)) {
|
|
64
|
+
(0, output_1.print)({ profile: ctx.profile, pinned_team_id: pinned, effective }, print_opts(g));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const effective_str = effective.error
|
|
68
|
+
? `failed to retrieve (${effective.error})`
|
|
69
|
+
: (effective.team_id ?? '(none)');
|
|
70
|
+
console.log(`Profile '${ctx.profile}'`);
|
|
71
|
+
console.log(` pinned team : ${pinned ?? '(none)'}`);
|
|
72
|
+
console.log(` effective team : ${effective_str}`);
|
|
73
|
+
};
|
|
74
|
+
exports.handle_team_current = handle_team_current;
|
|
75
|
+
const handle_team_use = async (id_arg, ctx, g) => {
|
|
76
|
+
const id = parse_positive_int(id_arg, 'Team id');
|
|
77
|
+
const { token, headers } = await (0, authed_1.authed)(ctx, g);
|
|
78
|
+
const teams = await (0, teams_1.resolve_my_teams)({ api_base: ctx.api_base, token, headers });
|
|
79
|
+
const match = teams.find(t => t.team_id === id);
|
|
80
|
+
if (!match) {
|
|
81
|
+
throw new errors_1.UsageError(`Team ${id} isn't one you can act in.`, {
|
|
82
|
+
code: 'usage.team',
|
|
83
|
+
hint: teams.length
|
|
84
|
+
? `Your teams: ${teams.map(t => `${t.team_id} (${t.team_name})`).join(', ')}`
|
|
85
|
+
: 'Run `reply team list` to see your teams.',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
(0, profile_1.set_profile)(ctx.profile, { team_id: id });
|
|
89
|
+
if (wants_json(g)) {
|
|
90
|
+
(0, output_1.print)({ profile: ctx.profile, team_id: id, team_name: match.team_name }, print_opts(g));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const label = match.team_name ? ` (${match.team_name})` : '';
|
|
94
|
+
(0, output_1.success)(`Profile '${ctx.profile}' team set to ${id}${label}.`);
|
|
95
|
+
};
|
|
96
|
+
exports.handle_team_use = handle_team_use;
|
|
97
|
+
const handle_team_clear = (ctx, g) => {
|
|
98
|
+
const { changed } = (0, profile_1.unset_profile_field)(ctx.profile, 'team_id');
|
|
99
|
+
if (wants_json(g)) {
|
|
100
|
+
(0, output_1.print)({ profile: ctx.profile, cleared: changed }, print_opts(g));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (changed) {
|
|
104
|
+
(0, output_1.success)(`Cleared team on profile '${ctx.profile}'.`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
(0, output_1.info)(`No team was set on '${ctx.profile}'.`);
|
|
108
|
+
};
|
|
109
|
+
exports.handle_team_clear = handle_team_clear;
|
|
110
|
+
const team_command = new commander_1.Command('team')
|
|
111
|
+
.description('See and set the current profile\'s team');
|
|
112
|
+
exports.team_command = team_command;
|
|
113
|
+
team_command
|
|
114
|
+
.command('list')
|
|
115
|
+
.description('List the teams you can act in')
|
|
116
|
+
.addHelpText('after', `\nExamples:\n ${config_1.PROGRAM_NAME} team list\n\nCalls the API (needs a stored login or --api-key).`)
|
|
117
|
+
.action(async function () {
|
|
118
|
+
const g = read_globals(this);
|
|
119
|
+
await handle_team_list((0, context_1.build_context)({ profile: g.profile }), g);
|
|
120
|
+
});
|
|
121
|
+
team_command
|
|
122
|
+
.command('current')
|
|
123
|
+
.description('Show the current profile\'s pinned and effective team')
|
|
124
|
+
.addHelpText('after', `\nExamples:\n ${config_1.PROGRAM_NAME} team current\n\n`
|
|
125
|
+
+ 'Pinned team is read from the profile (offline); the effective team is fetched from the API.')
|
|
126
|
+
.action(async function () {
|
|
127
|
+
const g = read_globals(this);
|
|
128
|
+
await handle_team_current((0, context_1.build_context)({ profile: g.profile }), g);
|
|
129
|
+
});
|
|
130
|
+
team_command
|
|
131
|
+
.command('use')
|
|
132
|
+
.argument('<id>', 'Team id to pin on the current profile')
|
|
133
|
+
.description('Pin a team on the current profile (verified against your teams)')
|
|
134
|
+
.addHelpText('after', `\nExamples:\n ${config_1.PROGRAM_NAME} team use 1045`)
|
|
135
|
+
.action(async function (id) {
|
|
136
|
+
const g = read_globals(this);
|
|
137
|
+
await handle_team_use(id, (0, context_1.build_context)({ profile: g.profile }), g);
|
|
138
|
+
});
|
|
139
|
+
team_command
|
|
140
|
+
.command('clear')
|
|
141
|
+
.description('Remove the current profile\'s team pin')
|
|
142
|
+
.action(function () {
|
|
143
|
+
const g = read_globals(this);
|
|
144
|
+
handle_team_clear((0, context_1.build_context)({ profile: g.profile }), g);
|
|
145
|
+
});
|
|
146
|
+
//# sourceMappingURL=team.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"team.js","sourceRoot":"","sources":["../../src/commands/team.ts"],"names":[],"mappings":";;;AAAA,yCAAkC;AAClC,sCAAuC;AACvC,wCAA2D;AAC3D,4CAA8C;AAC9C,oCAA0C;AAC1C,wCAA4D;AAC5D,iCAA2C;AAC3C,qCA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3
|
+
type Env = Record<string, string | undefined>;
|
|
4
|
+
declare const env_prefix: (app?: string) => string;
|
|
5
|
+
declare const env_var: (suffix: string, app?: string) => string;
|
|
6
|
+
declare const get_env: (suffix: string, env?: Env) => string | undefined;
|
|
7
|
+
declare const cli_version: () => string;
|
|
8
|
+
declare const user_agent: () => string;
|
|
9
|
+
declare const default_config_dir: (platform: NodeJS.Platform, env: Env, homedir: string) => string;
|
|
10
|
+
declare const config_dir: (env?: Env) => string;
|
|
11
|
+
declare const credentials_file: (env?: Env) => string;
|
|
12
|
+
declare const config_file: (env?: Env) => string;
|
|
13
|
+
declare const skills_file: (env?: Env) => string;
|
|
14
|
+
export { PROGRAM_NAME, APP_NAME, env_prefix, env_var, get_env, cli_version, user_agent, default_config_dir, config_dir, credentials_file, config_file, skills_file, };
|
|
15
|
+
export type { Env };
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.skills_file = exports.config_file = exports.credentials_file = exports.config_dir = exports.default_config_dir = exports.user_agent = exports.cli_version = exports.get_env = exports.env_var = exports.env_prefix = exports.APP_NAME = exports.PROGRAM_NAME = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
// Single identity. The bin name, config dir, and env-var prefix all derive
|
|
11
|
+
// from APP_NAME. There is one build (`reply`); channels are handled by the
|
|
12
|
+
// registry/dist-tags, not by a second identity.
|
|
13
|
+
const APP_NAME = 'reply';
|
|
14
|
+
exports.APP_NAME = APP_NAME;
|
|
15
|
+
const PROGRAM_NAME = APP_NAME;
|
|
16
|
+
exports.PROGRAM_NAME = PROGRAM_NAME;
|
|
17
|
+
const env_prefix = (app = APP_NAME) => app.toUpperCase().replace(/-/g, '_');
|
|
18
|
+
exports.env_prefix = env_prefix;
|
|
19
|
+
// Build a full env var name, e.g. env_var('API_KEY') -> 'REPLY_API_KEY'.
|
|
20
|
+
const env_var = (suffix, app = APP_NAME) => `${env_prefix(app)}_${suffix}`;
|
|
21
|
+
exports.env_var = env_var;
|
|
22
|
+
const get_env = (suffix, env = process.env) => env[env_var(suffix)];
|
|
23
|
+
exports.get_env = get_env;
|
|
24
|
+
let cached_version;
|
|
25
|
+
// The CLI version, read once from package.json (same file for src and dist —
|
|
26
|
+
// ../package.json resolves to the repo root either way). Falls back to '0.0.0'
|
|
27
|
+
// if the file is missing or malformed.
|
|
28
|
+
const cli_version = () => {
|
|
29
|
+
if (cached_version !== undefined) {
|
|
30
|
+
return cached_version;
|
|
31
|
+
}
|
|
32
|
+
let version = '0.0.0';
|
|
33
|
+
try {
|
|
34
|
+
const pkg = JSON.parse(fs_1.default.readFileSync(path_1.default.join(__dirname, '../package.json'), 'utf8'));
|
|
35
|
+
if (typeof pkg.version === 'string' && pkg.version) {
|
|
36
|
+
version = pkg.version;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Unreadable/malformed package.json — keep the '0.0.0' fallback.
|
|
41
|
+
}
|
|
42
|
+
cached_version = version;
|
|
43
|
+
return version;
|
|
44
|
+
};
|
|
45
|
+
exports.cli_version = cli_version;
|
|
46
|
+
// Identifies CLI requests for telemetry (not security). Product token derives
|
|
47
|
+
// from APP_NAME to keep the single build identity, e.g. 'reply-cli/0.1.0'.
|
|
48
|
+
const user_agent = () => `${APP_NAME}-cli/${cli_version()}`;
|
|
49
|
+
exports.user_agent = user_agent;
|
|
50
|
+
// Default per-user config dir, mirroring gh/aws/az conventions.
|
|
51
|
+
// linux/mac: $XDG_CONFIG_HOME/<app> (fallback ~/.config/<app>)
|
|
52
|
+
// windows: %APPDATA%\<app> (fallback <home>\AppData\Roaming\<app>)
|
|
53
|
+
const default_config_dir = (platform, env, homedir) => {
|
|
54
|
+
if (platform === 'win32') {
|
|
55
|
+
const appdata = env.APPDATA && env.APPDATA.trim()
|
|
56
|
+
? env.APPDATA
|
|
57
|
+
: path_1.default.join(homedir, 'AppData', 'Roaming');
|
|
58
|
+
return path_1.default.join(appdata, APP_NAME);
|
|
59
|
+
}
|
|
60
|
+
const xdg = env.XDG_CONFIG_HOME;
|
|
61
|
+
const base = xdg && xdg.trim() ? xdg : path_1.default.join(homedir, '.config');
|
|
62
|
+
return path_1.default.join(base, APP_NAME);
|
|
63
|
+
};
|
|
64
|
+
exports.default_config_dir = default_config_dir;
|
|
65
|
+
// The active config dir. A <PREFIX>_CONFIG_DIR override wins outright.
|
|
66
|
+
const config_dir = (env = process.env) => {
|
|
67
|
+
const override = get_env('CONFIG_DIR', env);
|
|
68
|
+
if (override && override.trim()) {
|
|
69
|
+
return override;
|
|
70
|
+
}
|
|
71
|
+
return default_config_dir(process.platform, env, os_1.default.homedir());
|
|
72
|
+
};
|
|
73
|
+
exports.config_dir = config_dir;
|
|
74
|
+
// Stored credentials, keyed by profile name (see credentials/file-store.ts).
|
|
75
|
+
const credentials_file = (env = process.env) => path_1.default.join(config_dir(env), 'credentials.json');
|
|
76
|
+
exports.credentials_file = credentials_file;
|
|
77
|
+
// User profile definitions live here (see profile.ts).
|
|
78
|
+
const config_file = (env = process.env) => path_1.default.join(config_dir(env), 'config.json');
|
|
79
|
+
exports.config_file = config_file;
|
|
80
|
+
// What the installer wrote into flat-directory hosts (see skills/journal.ts).
|
|
81
|
+
const skills_file = (env = process.env) => path_1.default.join(config_dir(env), 'skills.json');
|
|
82
|
+
exports.skills_file = skills_file;
|
|
83
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,4CAAoB;AACpB,gD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AO,CAAC,QAAQ,EAAE,GAAG,EAAE,YAAE,CAAC,OAAO,EAAE,CAAC,CAAC;AACnE,CAAC,CAAC;AAiBsB,gCAAU;AAflC,6EAA6E;AAC7E,MAAM,gBAAgB,GAAG,CAAC,MAAW,OAAO,CAAC,GAAG,EAAS,EAAE,CACvD,cAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,kBAAkB,CAAC,CAAC;AAaf,4CAAgB;AAXpD,uDAAuD;AACvD,MAAM,WAAW,GAAG,CAAC,MAAW,OAAO,CAAC,GAAG,EAAS,EAAE,CAClD,cAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,CAAC;AASQ,kCAAW;AAPjE,8EAA8E;AAC9E,MAAM,WAAW,GAAG,CAAC,MAAW,OAAO,CAAC,GAAG,EAAS,EAAE,CAClD,cAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,CAAC;AAKqB,kCAAW"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CredentialStore, Oauth_record } from './credentials/types';
|
|
2
|
+
type Cli_context = {
|
|
3
|
+
profile: string;
|
|
4
|
+
authority: string;
|
|
5
|
+
api_base: string;
|
|
6
|
+
key: string;
|
|
7
|
+
team_id?: number;
|
|
8
|
+
store: CredentialStore;
|
|
9
|
+
refresh: (record: Oauth_record) => Promise<Oauth_record>;
|
|
10
|
+
};
|
|
11
|
+
declare const build_context: (opts?: {
|
|
12
|
+
profile?: string;
|
|
13
|
+
}) => Cli_context;
|
|
14
|
+
export { build_context };
|
|
15
|
+
export type { Cli_context };
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.build_context = void 0;
|
|
4
|
+
const profile_1 = require("./profile");
|
|
5
|
+
const file_store_1 = require("./credentials/file-store");
|
|
6
|
+
const oauth_flow_1 = require("./auth/oauth-flow");
|
|
7
|
+
const build_context = (opts = {}) => {
|
|
8
|
+
const p = (0, profile_1.resolve_profile)(opts.profile);
|
|
9
|
+
const store = (0, file_store_1.default_credential_store)();
|
|
10
|
+
const refresh = (record) => (0, oauth_flow_1.refresh_stored)({ authority: p.authority, record });
|
|
11
|
+
return {
|
|
12
|
+
profile: p.name, authority: p.authority, api_base: p.api_base,
|
|
13
|
+
key: p.name, team_id: p.team_id, store, refresh,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.build_context = build_context;
|
|
17
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAC1C,yDAAkE;AAClE,kDAAiD;AAgBjD,MAAM,aAAa,GAAG,CAAC,OAA2B,EAAE,EAAc,EAAE;IAChE,MAAM,CAAC,GAAG,IAAA,yBAAe,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,IAAA,qCAAwB,GAAE,CAAC;IACzC,MAAM,OAAO,GAAG,CAAC,MAAoB,EAAwB,EAAE,CAC3D,IAAA,2BAAc,EAAC,EAAC,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,MAAM,EAAC,CAAC,CAAC;IACrD,OAAO;QACH,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ;QAC7D,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO;KAClD,CAAC;AACN,CAAC,CAAC;AAEM,sCAAa"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Credential_record, CredentialStore } from './types';
|
|
2
|
+
declare class FileCredentialStore implements CredentialStore {
|
|
3
|
+
private readonly file;
|
|
4
|
+
constructor(file: string);
|
|
5
|
+
get(key: string): Promise<Credential_record | undefined>;
|
|
6
|
+
set(key: string, record: Credential_record): Promise<void>;
|
|
7
|
+
remove(key: string): Promise<boolean>;
|
|
8
|
+
keys(): Promise<string[]>;
|
|
9
|
+
private read;
|
|
10
|
+
private write;
|
|
11
|
+
}
|
|
12
|
+
declare const default_credential_store: () => CredentialStore;
|
|
13
|
+
export { FileCredentialStore, default_credential_store };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default_credential_store = exports.FileCredentialStore = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const config_1 = require("../config");
|
|
10
|
+
const errors_1 = require("../utils/errors");
|
|
11
|
+
// v1 credential backend: a single JSON file keyed by profile name, written
|
|
12
|
+
// with strict 0600 perms in a 0700 dir (the gh/aws/az plaintext-file model).
|
|
13
|
+
class FileCredentialStore {
|
|
14
|
+
file;
|
|
15
|
+
constructor(file) {
|
|
16
|
+
this.file = file;
|
|
17
|
+
}
|
|
18
|
+
async get(key) {
|
|
19
|
+
return this.read()[key];
|
|
20
|
+
}
|
|
21
|
+
async set(key, record) {
|
|
22
|
+
const map = this.read();
|
|
23
|
+
map[key] = record;
|
|
24
|
+
this.write(map);
|
|
25
|
+
}
|
|
26
|
+
async remove(key) {
|
|
27
|
+
const map = this.read();
|
|
28
|
+
if (!(key in map)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
delete map[key];
|
|
32
|
+
this.write(map);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
async keys() {
|
|
36
|
+
return Object.keys(this.read());
|
|
37
|
+
}
|
|
38
|
+
read() {
|
|
39
|
+
let raw;
|
|
40
|
+
try {
|
|
41
|
+
raw = fs_1.default.readFileSync(this.file, 'utf8');
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
if (e.code === 'ENOENT') {
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
throw new errors_1.RuntimeError('Could not read the credential store.', {
|
|
48
|
+
code: 'store.read', detail: this.file,
|
|
49
|
+
hint: e.message,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (!raw.trim()) {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
let parsed;
|
|
56
|
+
try {
|
|
57
|
+
parsed = JSON.parse(raw);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
throw new errors_1.RuntimeError('Credential store is corrupt (invalid JSON).', {
|
|
61
|
+
code: 'store.corrupt', detail: this.file,
|
|
62
|
+
hint: 'Delete the file and log in again.',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
66
|
+
throw new errors_1.RuntimeError('Credential store is corrupt (unexpected shape).', {
|
|
67
|
+
code: 'store.corrupt', detail: this.file,
|
|
68
|
+
hint: 'Delete the file and log in again.',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return parsed;
|
|
72
|
+
}
|
|
73
|
+
// Atomic write: temp file created 0600, then renamed into place so the
|
|
74
|
+
// final file is never briefly world-readable and rewrites keep 0600.
|
|
75
|
+
write(map) {
|
|
76
|
+
const dir = path_1.default.dirname(this.file);
|
|
77
|
+
fs_1.default.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
78
|
+
fs_1.default.chmodSync(dir, 0o700);
|
|
79
|
+
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
80
|
+
fs_1.default.writeFileSync(tmp, JSON.stringify(map, null, 2), { mode: 0o600 });
|
|
81
|
+
fs_1.default.chmodSync(tmp, 0o600);
|
|
82
|
+
fs_1.default.renameSync(tmp, this.file);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.FileCredentialStore = FileCredentialStore;
|
|
86
|
+
const default_credential_store = () => new FileCredentialStore((0, config_1.credentials_file)());
|
|
87
|
+
exports.default_credential_store = default_credential_store;
|
|
88
|
+
//# sourceMappingURL=file-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-store.js","sourceRoot":"","sources":["../../src/credentials/file-store.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,sCAA2C;AAC3C,4CAA6C;AAK7C,2EAA2E;AAC3E,6EAA6E;AAC7E,MAAM,mBAAmB;IACJ,IAAI,CAAS;IAE9B,YAAY,IAAY;QAEpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QAEjB,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,MAAyB;QAE5C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACxB,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;QAClB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QAEpB,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,EACjB,CAAC;YACG,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAChB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,IAAI;QAEN,OAAO,MAAM,CAAC,IAAI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AAK,CAAC,GAAY;QAEtB,MAAM,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,YAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC;QAClD,YAAE,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,MAAM,CAAC;QAC9C,YAAE,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC;QACnE,YAAE,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,YAAE,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACJ;AAKO,kDAAmB;AAH3B,MAAM,wBAAwB,GAAG,GAAmB,EAAE,CAClD,IAAI,mBAAmB,CAAC,IAAA,yBAAgB,GAAE,CAAC,CAAC;AAEnB,4DAAwB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type Principal = {
|
|
2
|
+
id?: number;
|
|
3
|
+
username?: string;
|
|
4
|
+
team_id?: number;
|
|
5
|
+
};
|
|
6
|
+
type Oauth_record = {
|
|
7
|
+
type: 'oauth';
|
|
8
|
+
access_token: string;
|
|
9
|
+
refresh_token?: string;
|
|
10
|
+
expires_at: number;
|
|
11
|
+
user?: Principal;
|
|
12
|
+
};
|
|
13
|
+
type Api_key_record = {
|
|
14
|
+
type: 'api_key';
|
|
15
|
+
key: string;
|
|
16
|
+
user?: Principal;
|
|
17
|
+
};
|
|
18
|
+
type Credential_record = Oauth_record | Api_key_record;
|
|
19
|
+
interface CredentialStore {
|
|
20
|
+
get(key: string): Promise<Credential_record | undefined>;
|
|
21
|
+
set(key: string, record: Credential_record): Promise<void>;
|
|
22
|
+
remove(key: string): Promise<boolean>;
|
|
23
|
+
keys(): Promise<string[]>;
|
|
24
|
+
}
|
|
25
|
+
export type { Principal, Oauth_record, Api_key_record, Credential_record, CredentialStore };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/credentials/types.ts"],"names":[],"mappings":""}
|