@ekanos/cli 0.15.0 → 0.16.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 +41 -4
- package/dist/auth/ekanos-api.d.ts +23 -0
- package/dist/auth/ekanos-api.js +33 -6
- package/dist/auth/ekanos-api.js.map +1 -1
- package/dist/commands/agents.js +3 -2
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/apps.d.ts +11 -3
- package/dist/commands/apps.js +86 -28
- package/dist/commands/apps.js.map +1 -1
- package/dist/commands/catalog.d.ts +4 -2
- package/dist/commands/catalog.js +166 -35
- package/dist/commands/catalog.js.map +1 -1
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.js +17 -0
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/runs.d.ts +7 -3
- package/dist/commands/runs.js +21 -5
- package/dist/commands/runs.js.map +1 -1
- package/dist/commands/scope-notice.d.ts +7 -0
- package/dist/commands/scope-notice.js +4 -11
- package/dist/commands/scope-notice.js.map +1 -1
- package/dist/commands/sources-roles.d.ts +5 -0
- package/dist/commands/sources-roles.js +235 -0
- package/dist/commands/sources-roles.js.map +1 -0
- package/dist/commands/sources.d.ts +5 -0
- package/dist/commands/sources.js +6 -1
- package/dist/commands/sources.js.map +1 -1
- package/dist/commands/team-agent-readiness.d.ts +18 -2
- package/dist/commands/team-agent-readiness.js +39 -39
- package/dist/commands/team-agent-readiness.js.map +1 -1
- package/dist/commands/team-agents-agents.d.ts +5 -2
- package/dist/commands/team-agents-agents.js +152 -15
- package/dist/commands/team-agents-agents.js.map +1 -1
- package/dist/commands/team-agents-define.d.ts +31 -0
- package/dist/commands/team-agents-define.js +176 -0
- package/dist/commands/team-agents-define.js.map +1 -0
- package/dist/commands/team-agents-mcp.js +112 -10
- package/dist/commands/team-agents-mcp.js.map +1 -1
- package/dist/commands/team-agents-triggers.d.ts +1 -1
- package/dist/commands/team-agents-triggers.js +137 -5
- package/dist/commands/team-agents-triggers.js.map +1 -1
- package/dist/commands/team-agents.d.ts +4 -1
- package/dist/commands/team-agents.js +17 -4
- package/dist/commands/team-agents.js.map +1 -1
- package/dist/commands/team-llm-key.d.ts +14 -0
- package/dist/commands/team-llm-key.js +122 -0
- package/dist/commands/team-llm-key.js.map +1 -0
- package/dist/commands/teams-connect.js +123 -31
- package/dist/commands/teams-connect.js.map +1 -1
- package/dist/commands/teams-lifecycle.d.ts +90 -0
- package/dist/commands/teams-lifecycle.js +457 -0
- package/dist/commands/teams-lifecycle.js.map +1 -0
- package/dist/commands/teams-onboard.d.ts +14 -0
- package/dist/commands/teams-onboard.js +62 -13
- package/dist/commands/teams-onboard.js.map +1 -1
- package/dist/commands/teams-overview.js +6 -2
- package/dist/commands/teams-overview.js.map +1 -1
- package/dist/commands/teams.d.ts +25 -5
- package/dist/commands/teams.js +101 -39
- package/dist/commands/teams.js.map +1 -1
- package/dist/commands/workflows.d.ts +37 -0
- package/dist/commands/workflows.js +589 -0
- package/dist/commands/workflows.js.map +1 -0
- package/dist/connect-fields.d.ts +22 -0
- package/dist/connect-fields.js +115 -0
- package/dist/connect-fields.js.map +1 -0
- package/dist/context.d.ts +12 -0
- package/dist/context.js +32 -9
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.js +357 -122
- package/dist/index.js.map +1 -1
- package/dist/invocation.d.ts +31 -0
- package/dist/invocation.js +58 -0
- package/dist/invocation.js.map +1 -0
- package/dist/runs-api.js +8 -3
- package/dist/runs-api.js.map +1 -1
- package/dist/safe-fs.d.ts +18 -0
- package/dist/safe-fs.js +57 -0
- package/dist/safe-fs.js.map +1 -1
- package/dist/secret-form.d.ts +48 -0
- package/dist/secret-form.js +212 -0
- package/dist/secret-form.js.map +1 -0
- package/dist/secret-input.d.ts +96 -0
- package/dist/secret-input.js +299 -0
- package/dist/secret-input.js.map +1 -0
- package/dist/team-connect-api.d.ts +78 -3
- package/dist/team-connect-api.js +17 -2
- package/dist/team-connect-api.js.map +1 -1
- package/dist/team-lifecycle-api.d.ts +435 -0
- package/dist/team-lifecycle-api.js +301 -0
- package/dist/team-lifecycle-api.js.map +1 -0
- package/dist/teams-api.d.ts +13 -1
- package/dist/teams-api.js +88 -27
- package/dist/teams-api.js.map +1 -1
- package/dist/unknown-command.d.ts +18 -0
- package/dist/unknown-command.js +50 -0
- package/dist/unknown-command.js.map +1 -0
- package/dist/workflows-api.d.ts +69 -0
- package/dist/workflows-api.js +182 -0
- package/dist/workflows-api.js.map +1 -0
- package/package.json +3 -3
- package/templates/AGENTS.md.tmpl +6 -4
- package/templates/claude-skill.md.tmpl +4 -1
- package/templates/package.json.tmpl +4 -4
- package/templates/skills/build-agent/SKILL.md +43 -10
- package/templates/skills/build-agent/references/agent-json.md +4 -1
- package/templates/skills/build-agent/references/app-setup.md +14 -7
- package/templates/skills/build-agent/references/rollout.md +26 -2
- package/templates/skills/build-agent/references/set-up-an-integration.md +46 -29
- package/templates/skills/build-integration/references/widget-design.md +1 -1
- package/templates/skills/ekanos-platform/SKILL.md +66 -14
- package/templates/skills/polish-widgets/references/patterns.md +3 -3
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { requireSession, resolveAuthEnvironment } from '../auth/session.js';
|
|
2
|
+
import { invalidStateError, usageError } from '../errors.js';
|
|
3
|
+
import { cli } from '../invocation.js';
|
|
4
|
+
import { resolveSourceTarget } from '../source-target.js';
|
|
5
|
+
import { createSourceRole, deleteSourceRole, listSourcePeople, listSourceRoles, updateSourceRole, } from '../team-lifecycle-api.js';
|
|
6
|
+
import { pluralize } from '../ui.js';
|
|
7
|
+
import { promptYesNo } from './publish.js';
|
|
8
|
+
import { TeamsClient } from './teams.js';
|
|
9
|
+
/**
|
|
10
|
+
* `sources roles` and `sources people`, for the Source admin.
|
|
11
|
+
*
|
|
12
|
+
* `roles` are the Source's roles — the ones every team of the Source hands
|
|
13
|
+
* out — managed through the same database functions as the team Settings →
|
|
14
|
+
* Roles page, which only a Source admin (or a super-admin) may call. Owner,
|
|
15
|
+
* admin and member are system roles: listed, never changed or deleted. A
|
|
16
|
+
* custom role sits below the owner (a higher level number), and a role a
|
|
17
|
+
* member still holds cannot be deleted.
|
|
18
|
+
*
|
|
19
|
+
* `people` is the Source admin's People page: everyone with access, one row
|
|
20
|
+
* per person with the teams they are on and their role on each.
|
|
21
|
+
*/
|
|
22
|
+
const ROLES_USAGE = 'Run one of: ekanos sources roles list, ekanos sources roles create <name> [--display-name <text>] [--description <text>] [--level <n>] [--permission <p>]…, ekanos sources roles update <role> [--display-name <text>] [--description <text>] [--level <n>] [--permission <p>]… [--grant <p>]… [--revoke <p>]…, ekanos sources roles delete <role> --yes.';
|
|
23
|
+
const DEFAULT_LEVEL = 100;
|
|
24
|
+
/**
|
|
25
|
+
* Deleting a role is asked at a terminal; a script, an agent run or `--json`
|
|
26
|
+
* passes `--yes` instead. Asked before any request.
|
|
27
|
+
*/
|
|
28
|
+
async function confirmDelete(ctx, args, role) {
|
|
29
|
+
var _a;
|
|
30
|
+
const what = `Deleting the role ${role} removes it from every team of the Source; it can't be deleted while a member holds it.`;
|
|
31
|
+
if (ctx.jsonMode || !((_a = args.stdinIsTTY) !== null && _a !== void 0 ? _a : process.stdin.isTTY === true)) {
|
|
32
|
+
throw invalidStateError(what, `Re-run with --yes: ${cli()} sources roles delete ${role} --yes`);
|
|
33
|
+
}
|
|
34
|
+
const question = `Delete the role ${role}? [y/N]`;
|
|
35
|
+
const { ask } = args;
|
|
36
|
+
const confirmed = ask
|
|
37
|
+
? /^y(es)?$/i.test((await ask(question)).trim())
|
|
38
|
+
: await promptYesNo(question);
|
|
39
|
+
if (!confirmed) {
|
|
40
|
+
throw invalidStateError(`Not confirmed: ${what}`, 'Nothing was changed.');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export async function runSourceRoles(ctx, args, rest) {
|
|
44
|
+
var _a;
|
|
45
|
+
const [verb, rawRole, ...extra] = rest;
|
|
46
|
+
if (extra.length > 0) {
|
|
47
|
+
throw usageError(`Unexpected argument "${extra[0]}".`, ROLES_USAGE);
|
|
48
|
+
}
|
|
49
|
+
if (verb !== undefined &&
|
|
50
|
+
verb !== 'list' &&
|
|
51
|
+
verb !== 'create' &&
|
|
52
|
+
verb !== 'update' &&
|
|
53
|
+
verb !== 'delete') {
|
|
54
|
+
throw usageError(`Unknown sources roles subcommand "${verb}".`, ROLES_USAGE);
|
|
55
|
+
}
|
|
56
|
+
const flags = (_a = args.flags) !== null && _a !== void 0 ? _a : {};
|
|
57
|
+
const role = verb === undefined || verb === 'list' ? undefined : roleOf(rawRole, verb);
|
|
58
|
+
if (verb === 'list' && rawRole !== undefined) {
|
|
59
|
+
throw usageError(`Unexpected argument "${rawRole}".`, ROLES_USAGE);
|
|
60
|
+
}
|
|
61
|
+
const level = levelOf(flags.level);
|
|
62
|
+
const displayName = textFlag(flags['display-name']);
|
|
63
|
+
const description = textFlag(flags.description);
|
|
64
|
+
const permissions = listFlag(flags.permission);
|
|
65
|
+
const grant = listFlag(flags.grant);
|
|
66
|
+
const revoke = listFlag(flags.revoke);
|
|
67
|
+
if (verb === 'update' && role) {
|
|
68
|
+
const nothing = level === undefined &&
|
|
69
|
+
displayName === undefined &&
|
|
70
|
+
description === undefined &&
|
|
71
|
+
permissions === undefined &&
|
|
72
|
+
grant === undefined &&
|
|
73
|
+
revoke === undefined;
|
|
74
|
+
if (nothing) {
|
|
75
|
+
throw usageError('Nothing to change.', `Pass --display-name, --description, --level, --permission (replaces), --grant or --revoke, e.g. "${cli()} sources roles update ${role} --grant agents.review".`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (verb === 'delete' && role && !args.yes) {
|
|
79
|
+
await confirmDelete(ctx, args, role);
|
|
80
|
+
}
|
|
81
|
+
const env = resolveAuthEnvironment(ctx, args.host, args.env, {
|
|
82
|
+
projectDir: args.dir,
|
|
83
|
+
});
|
|
84
|
+
const resolved = await resolveSourceTarget(env, requireSession(env), {
|
|
85
|
+
source: args.source,
|
|
86
|
+
dir: args.dir,
|
|
87
|
+
});
|
|
88
|
+
const client = new TeamsClient(env, resolved.session);
|
|
89
|
+
const host = env.host;
|
|
90
|
+
const source = resolved.source;
|
|
91
|
+
if (verb === 'create' && role) {
|
|
92
|
+
const done = await client.call((token) => createSourceRole(host, token, source, Object.assign(Object.assign({ name: role, displayName: displayName !== null && displayName !== void 0 ? displayName : humanize(role) }, (description === undefined ? {} : { description })), { hierarchyLevel: level !== null && level !== void 0 ? level : DEFAULT_LEVEL, permissions: permissions !== null && permissions !== void 0 ? permissions : [] })));
|
|
93
|
+
return ctx.succeed(Object.assign({ host }, done), ctx.ui.result({
|
|
94
|
+
title: `Created role ${done.role.name} on ${done.source.slug}`,
|
|
95
|
+
rows: [roleRow(done.role)],
|
|
96
|
+
notes: [
|
|
97
|
+
`Give it to someone with "${cli()} teams members role <team> <email> ${done.role.name}".`,
|
|
98
|
+
],
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
if (verb === 'update' && role) {
|
|
102
|
+
const done = await client.call((token) => updateSourceRole(host, token, { source, role }, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (displayName === undefined ? {} : { displayName })), (description === undefined ? {} : { description })), (level === undefined ? {} : { hierarchyLevel: level })), (permissions === undefined ? {} : { permissions })), (grant === undefined ? {} : { grant })), (revoke === undefined ? {} : { revoke }))));
|
|
103
|
+
const added = done.role.permissions.filter((permission) => !done.previous.permissions.includes(permission));
|
|
104
|
+
const removed = done.previous.permissions.filter((permission) => !done.role.permissions.includes(permission));
|
|
105
|
+
return ctx.succeed(Object.assign({ host }, done), ctx.ui.result({
|
|
106
|
+
title: `Updated role ${done.role.name} on ${done.source.slug}`,
|
|
107
|
+
rows: [
|
|
108
|
+
roleRow(done.role),
|
|
109
|
+
...(added.length > 0 ? [['Granted', added]] : []),
|
|
110
|
+
...(removed.length > 0 ? [['Revoked', removed]] : []),
|
|
111
|
+
],
|
|
112
|
+
notes: [
|
|
113
|
+
`Every member holding ${done.role.name}, on every team of the Source, has these permissions now.`,
|
|
114
|
+
],
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
if (verb === 'delete' && role) {
|
|
118
|
+
const done = await client.call((token) => deleteSourceRole(host, token, { source, role }));
|
|
119
|
+
return ctx.succeed(Object.assign({ host }, done), ctx.ui.result({
|
|
120
|
+
title: `Deleted role ${done.role.name} from ${done.source.slug}`,
|
|
121
|
+
tone: 'warn',
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
const list = await client.call((token) => listSourceRoles(host, token, source));
|
|
125
|
+
return ctx.succeed(Object.assign({ host }, list), ctx.ui.result({
|
|
126
|
+
title: list.roles.length === 0
|
|
127
|
+
? `${list.source.slug} uses the default roles`
|
|
128
|
+
: `Roles on ${list.source.slug}`,
|
|
129
|
+
rows: list.roles.map(roleRow),
|
|
130
|
+
notes: [
|
|
131
|
+
list.roles.length === 0
|
|
132
|
+
? 'No customized roles: teams use owner, admin and member. "ekanos teams roles list <team>" shows their permissions.'
|
|
133
|
+
: 'Lower levels rank higher. Owner, admin and member are system roles and stay as they are.',
|
|
134
|
+
`Permissions: ${list.permissions.map((entry) => entry.permission).join(', ')}`,
|
|
135
|
+
],
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
export async function runSourcePeople(ctx, args, rest) {
|
|
139
|
+
var _a;
|
|
140
|
+
if (rest.length > 0) {
|
|
141
|
+
throw usageError(`Unexpected argument "${rest[0]}".`, 'Run "ekanos sources people [--search <text>] [--page <n>]".');
|
|
142
|
+
}
|
|
143
|
+
const flags = (_a = args.flags) !== null && _a !== void 0 ? _a : {};
|
|
144
|
+
const search = textFlag(flags.search);
|
|
145
|
+
const page = pageOf(flags.page);
|
|
146
|
+
const env = resolveAuthEnvironment(ctx, args.host, args.env, {
|
|
147
|
+
projectDir: args.dir,
|
|
148
|
+
});
|
|
149
|
+
const resolved = await resolveSourceTarget(env, requireSession(env), {
|
|
150
|
+
source: args.source,
|
|
151
|
+
dir: args.dir,
|
|
152
|
+
});
|
|
153
|
+
const client = new TeamsClient(env, resolved.session);
|
|
154
|
+
const list = await client.call((token) => listSourcePeople(env.host, token, resolved.source, Object.assign(Object.assign({}, (search ? { search } : {})), (page === undefined ? {} : { page }))));
|
|
155
|
+
const pages = Math.max(1, Math.ceil(list.total / list.pageSize));
|
|
156
|
+
return ctx.succeed(Object.assign({ host: env.host }, list), ctx.ui.result({
|
|
157
|
+
title: list.total === 0
|
|
158
|
+
? search
|
|
159
|
+
? `Nobody on ${list.source.slug} matches "${search}"`
|
|
160
|
+
: `Nobody has access to ${list.source.slug} yet`
|
|
161
|
+
: `${list.total} ${list.total === 1 ? 'person' : 'people'} on ${list.source.slug}${search ? ` matching "${search}"` : ''}`,
|
|
162
|
+
tone: list.total === 0 ? 'warn' : 'ok',
|
|
163
|
+
rows: list.people.map((person) => { var _a, _b; return [
|
|
164
|
+
(_b = (_a = person.email) !== null && _a !== void 0 ? _a : person.name) !== null && _b !== void 0 ? _b : person.userId,
|
|
165
|
+
[
|
|
166
|
+
[
|
|
167
|
+
...(person.name && person.email ? [person.name] : []),
|
|
168
|
+
...(person.status === 'active' ? [] : [person.status]),
|
|
169
|
+
].join(' · ') || 'active',
|
|
170
|
+
...person.teams.map((team) => `${team.accountName} · ${team.roleLabel}${team.status === 'active' ? '' : ` · ${team.status}`}`),
|
|
171
|
+
],
|
|
172
|
+
]; }),
|
|
173
|
+
notes: pages > 1
|
|
174
|
+
? [
|
|
175
|
+
`Page ${list.page} of ${pages}. "--page ${Math.min(list.page + 1, pages)}" shows the next.`,
|
|
176
|
+
]
|
|
177
|
+
: [],
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
function roleRow(role) {
|
|
181
|
+
return [
|
|
182
|
+
`${role.name} (${role.displayName})`,
|
|
183
|
+
[
|
|
184
|
+
`level ${role.hierarchyLevel}${role.isSystem ? ' · system' : ''} · ${pluralize(role.memberCount, 'member')}`,
|
|
185
|
+
role.permissions.length > 0
|
|
186
|
+
? role.permissions.join(', ')
|
|
187
|
+
: 'no permissions',
|
|
188
|
+
],
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
function roleOf(value, verb) {
|
|
192
|
+
const role = value === null || value === void 0 ? void 0 : value.trim().toLowerCase();
|
|
193
|
+
if (role && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(role))
|
|
194
|
+
return role;
|
|
195
|
+
throw usageError(value
|
|
196
|
+
? `"${value}" is not a role name (lowercase letters, digits and dashes, e.g. team-lead).`
|
|
197
|
+
: `sources roles ${verb} needs a role name.`, '"ekanos sources roles list" lists them.');
|
|
198
|
+
}
|
|
199
|
+
function levelOf(value) {
|
|
200
|
+
if (value === undefined)
|
|
201
|
+
return undefined;
|
|
202
|
+
const level = typeof value === 'string' ? Number(value) : Number.NaN;
|
|
203
|
+
if (Number.isInteger(level) && level >= 1 && level <= 1000)
|
|
204
|
+
return level;
|
|
205
|
+
throw usageError(`--level "${String(value)}" is not a whole number from 1 to 1000.`, 'Lower numbers rank higher; a custom role sits below the owner, e.g. --level 50.');
|
|
206
|
+
}
|
|
207
|
+
function pageOf(value) {
|
|
208
|
+
if (value === undefined)
|
|
209
|
+
return undefined;
|
|
210
|
+
const page = typeof value === 'string' ? Number(value) : Number.NaN;
|
|
211
|
+
if (Number.isInteger(page) && page >= 1)
|
|
212
|
+
return page;
|
|
213
|
+
throw usageError(`--page "${String(value)}" is not a page number.`, 'Pages start at 1, e.g. --page 2.');
|
|
214
|
+
}
|
|
215
|
+
function textFlag(value) {
|
|
216
|
+
return typeof value === 'string' ? value.trim() : undefined;
|
|
217
|
+
}
|
|
218
|
+
function listFlag(value) {
|
|
219
|
+
if (value === undefined || value === false)
|
|
220
|
+
return undefined;
|
|
221
|
+
const values = Array.isArray(value)
|
|
222
|
+
? value
|
|
223
|
+
: typeof value === 'string'
|
|
224
|
+
? [value]
|
|
225
|
+
: [];
|
|
226
|
+
return values
|
|
227
|
+
.flatMap((entry) => String(entry).split(','))
|
|
228
|
+
.map((entry) => entry.trim())
|
|
229
|
+
.filter(Boolean);
|
|
230
|
+
}
|
|
231
|
+
function humanize(name) {
|
|
232
|
+
const spaced = name.replace(/-+/g, ' ');
|
|
233
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=sources-roles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources-roles.js","sourceRoot":"","sources":["../../src/commands/sources-roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAEL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAkB,SAAS,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,GACf,2VAA2V,CAAC;AAC9V,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B;;;GAGG;AACH,KAAK,UAAU,aAAa,CAC1B,GAAe,EACf,IAAiB,EACjB,IAAY;;IAEZ,MAAM,IAAI,GAAG,qBAAqB,IAAI,yFAAyF,CAAC;IAChI,IAAI,GAAG,CAAC,QAAQ,IAAI,CAAC,OAAC,IAAI,CAAC,UAAU,mCAAI,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,EAAE,CAAC;QACvE,MAAM,iBAAiB,CACrB,IAAI,EACJ,sBAAsB,GAAG,EAAE,y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C;IACxC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import { requireSession, resolveAuthEnvironment } from '../auth/session';\nimport type { CliContext } from '../context';\nimport { invalidStateError, usageError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { cli } from '../invocation';\nimport { resolveSourceTarget } from '../source-target';\nimport {\n type SourceRole,\n createSourceRole,\n deleteSourceRole,\n listSourcePeople,\n listSourceRoles,\n updateSourceRole,\n} from '../team-lifecycle-api';\nimport { type ResultRow, pluralize } from '../ui';\nimport { promptYesNo } from './publish';\nimport type { SourcesArgs } from './sources';\nimport { TeamsClient } from './teams';\n\n/**\n * `sources roles` and `sources people`, for the Source admin.\n *\n * `roles` are the Source's roles — the ones every team of the Source hands\n * out — managed through the same database functions as the team Settings →\n * Roles page, which only a Source admin (or a super-admin) may call. Owner,\n * admin and member are system roles: listed, never changed or deleted. A\n * custom role sits below the owner (a higher level number), and a role a\n * member still holds cannot be deleted.\n *\n * `people` is the Source admin's People page: everyone with access, one row\n * per person with the teams they are on and their role on each.\n */\n\nconst ROLES_USAGE =\n 'Run one of: ekanos sources roles list, ekanos sources roles create <name> [--display-name <text>] [--description <text>] [--level <n>] [--permission <p>]…, ekanos sources roles update <role> [--display-name <text>] [--description <text>] [--level <n>] [--permission <p>]… [--grant <p>]… [--revoke <p>]…, ekanos sources roles delete <role> --yes.';\nconst DEFAULT_LEVEL = 100;\n\n/**\n * Deleting a role is asked at a terminal; a script, an agent run or `--json`\n * passes `--yes` instead. Asked before any request.\n */\nasync function confirmDelete(\n ctx: CliContext,\n args: SourcesArgs,\n role: string,\n): Promise<void> {\n const what = `Deleting the role ${role} removes it from every team of the Source; it can't be deleted while a member holds it.`;\n if (ctx.jsonMode || !(args.stdinIsTTY ?? process.stdin.isTTY === true)) {\n throw invalidStateError(\n what,\n `Re-run with --yes: ${cli()} sources roles delete ${role} --yes`,\n );\n }\n const question = `Delete the role ${role}? [y/N]`;\n const { ask } = args;\n const confirmed = ask\n ? /^y(es)?$/i.test((await ask(question)).trim())\n : await promptYesNo(question);\n if (!confirmed) {\n throw invalidStateError(`Not confirmed: ${what}`, 'Nothing was changed.');\n }\n}\n\nexport async function runSourceRoles(\n ctx: CliContext,\n args: SourcesArgs,\n rest: readonly string[],\n): Promise<ExitCode> {\n const [verb, rawRole, ...extra] = rest;\n if (extra.length > 0) {\n throw usageError(`Unexpected argument \"${extra[0]}\".`, ROLES_USAGE);\n }\n if (\n verb !== undefined &&\n verb !== 'list' &&\n verb !== 'create' &&\n verb !== 'update' &&\n verb !== 'delete'\n ) {\n throw usageError(\n `Unknown sources roles subcommand \"${verb}\".`,\n ROLES_USAGE,\n );\n }\n const flags = args.flags ?? {};\n const role =\n verb === undefined || verb === 'list' ? undefined : roleOf(rawRole, verb);\n if (verb === 'list' && rawRole !== undefined) {\n throw usageError(`Unexpected argument \"${rawRole}\".`, ROLES_USAGE);\n }\n const level = levelOf(flags.level);\n const displayName = textFlag(flags['display-name']);\n const description = textFlag(flags.description);\n const permissions = listFlag(flags.permission);\n const grant = listFlag(flags.grant);\n const revoke = listFlag(flags.revoke);\n\n if (verb === 'update' && role) {\n const nothing =\n level === undefined &&\n displayName === undefined &&\n description === undefined &&\n permissions === undefined &&\n grant === undefined &&\n revoke === undefined;\n if (nothing) {\n throw usageError(\n 'Nothing to change.',\n `Pass --display-name, --description, --level, --permission (replaces), --grant or --revoke, e.g. \"${cli()} sources roles update ${role} --grant agents.review\".`,\n );\n }\n }\n if (verb === 'delete' && role && !args.yes) {\n await confirmDelete(ctx, args, role);\n }\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const resolved = await resolveSourceTarget(env, requireSession(env), {\n source: args.source,\n dir: args.dir,\n });\n const client = new TeamsClient(env, resolved.session);\n const host = env.host;\n const source = resolved.source;\n\n if (verb === 'create' && role) {\n const done = await client.call((token) =>\n createSourceRole(host, token, source, {\n name: role,\n displayName: displayName ?? humanize(role),\n ...(description === undefined ? {} : { description }),\n hierarchyLevel: level ?? DEFAULT_LEVEL,\n permissions: permissions ?? [],\n }),\n );\n return ctx.succeed(\n { host, ...done },\n ctx.ui.result({\n title: `Created role ${done.role.name} on ${done.source.slug}`,\n rows: [roleRow(done.role)],\n notes: [\n `Give it to someone with \"${cli()} teams members role <team> <email> ${done.role.name}\".`,\n ],\n }),\n );\n }\n\n if (verb === 'update' && role) {\n const done = await client.call((token) =>\n updateSourceRole(\n host,\n token,\n { source, role },\n {\n ...(displayName === undefined ? {} : { displayName }),\n ...(description === undefined ? {} : { description }),\n ...(level === undefined ? {} : { hierarchyLevel: level }),\n ...(permissions === undefined ? {} : { permissions }),\n ...(grant === undefined ? {} : { grant }),\n ...(revoke === undefined ? {} : { revoke }),\n },\n ),\n );\n const added = done.role.permissions.filter(\n (permission) => !done.previous.permissions.includes(permission),\n );\n const removed = done.previous.permissions.filter(\n (permission) => !done.role.permissions.includes(permission),\n );\n return ctx.succeed(\n { host, ...done },\n ctx.ui.result({\n title: `Updated role ${done.role.name} on ${done.source.slug}`,\n rows: [\n roleRow(done.role),\n ...(added.length > 0 ? [['Granted', added] as const] : []),\n ...(removed.length > 0 ? [['Revoked', removed] as const] : []),\n ],\n notes: [\n `Every member holding ${done.role.name}, on every team of the Source, has these permissions now.`,\n ],\n }),\n );\n }\n\n if (verb === 'delete' && role) {\n const done = await client.call((token) =>\n deleteSourceRole(host, token, { source, role }),\n );\n return ctx.succeed(\n { host, ...done },\n ctx.ui.result({\n title: `Deleted role ${done.role.name} from ${done.source.slug}`,\n tone: 'warn',\n }),\n );\n }\n\n const list = await client.call((token) =>\n listSourceRoles(host, token, source),\n );\n return ctx.succeed(\n { host, ...list },\n ctx.ui.result({\n title:\n list.roles.length === 0\n ? `${list.source.slug} uses the default roles`\n : `Roles on ${list.source.slug}`,\n rows: list.roles.map(roleRow),\n notes: [\n list.roles.length === 0\n ? 'No customized roles: teams use owner, admin and member. \"ekanos teams roles list <team>\" shows their permissions.'\n : 'Lower levels rank higher. Owner, admin and member are system roles and stay as they are.',\n `Permissions: ${list.permissions.map((entry) => entry.permission).join(', ')}`,\n ],\n }),\n );\n}\n\nexport async function runSourcePeople(\n ctx: CliContext,\n args: SourcesArgs,\n rest: readonly string[],\n): Promise<ExitCode> {\n if (rest.length > 0) {\n throw usageError(\n `Unexpected argument \"${rest[0]}\".`,\n 'Run \"ekanos sources people [--search <text>] [--page <n>]\".',\n );\n }\n const flags = args.flags ?? {};\n const search = textFlag(flags.search);\n const page = pageOf(flags.page);\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const resolved = await resolveSourceTarget(env, requireSession(env), {\n source: args.source,\n dir: args.dir,\n });\n const client = new TeamsClient(env, resolved.session);\n const list = await client.call((token) =>\n listSourcePeople(env.host, token, resolved.source, {\n ...(search ? { search } : {}),\n ...(page === undefined ? {} : { page }),\n }),\n );\n\n const pages = Math.max(1, Math.ceil(list.total / list.pageSize));\n return ctx.succeed(\n { host: env.host, ...list },\n ctx.ui.result({\n title:\n list.total === 0\n ? search\n ? `Nobody on ${list.source.slug} matches \"${search}\"`\n : `Nobody has access to ${list.source.slug} yet`\n : `${list.total} ${list.total === 1 ? 'person' : 'people'} on ${list.source.slug}${search ? ` matching \"${search}\"` : ''}`,\n tone: list.total === 0 ? 'warn' : 'ok',\n rows: list.people.map((person): ResultRow => [\n person.email ?? person.name ?? person.userId,\n [\n [\n ...(person.name && person.email ? [person.name] : []),\n ...(person.status === 'active' ? [] : [person.status]),\n ].join(' · ') || 'active',\n ...person.teams.map(\n (team) =>\n `${team.accountName} · ${team.roleLabel}${team.status === 'active' ? '' : ` · ${team.status}`}`,\n ),\n ],\n ]),\n notes:\n pages > 1\n ? [\n `Page ${list.page} of ${pages}. \"--page ${Math.min(list.page + 1, pages)}\" shows the next.`,\n ]\n : [],\n }),\n );\n}\n\nfunction roleRow(role: SourceRole): ResultRow {\n return [\n `${role.name} (${role.displayName})`,\n [\n `level ${role.hierarchyLevel}${role.isSystem ? ' · system' : ''} · ${pluralize(role.memberCount, 'member')}`,\n role.permissions.length > 0\n ? role.permissions.join(', ')\n : 'no permissions',\n ],\n ];\n}\n\nfunction roleOf(value: string | undefined, verb: string): string {\n const role = value?.trim().toLowerCase();\n if (role && /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(role)) return role;\n throw usageError(\n value\n ? `\"${value}\" is not a role name (lowercase letters, digits and dashes, e.g. team-lead).`\n : `sources roles ${verb} needs a role name.`,\n '\"ekanos sources roles list\" lists them.',\n );\n}\n\nfunction levelOf(value: unknown): number | undefined {\n if (value === undefined) return undefined;\n const level = typeof value === 'string' ? Number(value) : Number.NaN;\n if (Number.isInteger(level) && level >= 1 && level <= 1000) return level;\n throw usageError(\n `--level \"${String(value)}\" is not a whole number from 1 to 1000.`,\n 'Lower numbers rank higher; a custom role sits below the owner, e.g. --level 50.',\n );\n}\n\nfunction pageOf(value: unknown): number | undefined {\n if (value === undefined) return undefined;\n const page = typeof value === 'string' ? Number(value) : Number.NaN;\n if (Number.isInteger(page) && page >= 1) return page;\n throw usageError(\n `--page \"${String(value)}\" is not a page number.`,\n 'Pages start at 1, e.g. --page 2.',\n );\n}\n\nfunction textFlag(value: unknown): string | undefined {\n return typeof value === 'string' ? value.trim() : undefined;\n}\n\nfunction listFlag(value: unknown): string[] | undefined {\n if (value === undefined || value === false) return undefined;\n const values = Array.isArray(value)\n ? value\n : typeof value === 'string'\n ? [value]\n : [];\n return values\n .flatMap((entry) => String(entry).split(','))\n .map((entry) => entry.trim())\n .filter(Boolean);\n}\n\nfunction humanize(name: string) {\n const spaced = name.replace(/-+/g, ' ');\n return spaced.charAt(0).toUpperCase() + spaced.slice(1);\n}\n"]}
|
|
@@ -6,6 +6,11 @@ export interface SourcesArgs {
|
|
|
6
6
|
positionals?: readonly string[];
|
|
7
7
|
source?: string;
|
|
8
8
|
yes?: boolean;
|
|
9
|
+
/** `roles` and `people`: their flags (`--level`, `--permission`, `--search` …). */
|
|
10
|
+
flags?: Record<string, string | boolean | string[]>;
|
|
11
|
+
/** `roles delete` asks at a terminal; the test seams for it. */
|
|
12
|
+
stdinIsTTY?: boolean;
|
|
13
|
+
ask?: (question: string) => Promise<string>;
|
|
9
14
|
/** Where a project's ekanos.json may sit — its `source` field, if any, is the marker. */
|
|
10
15
|
dir: string;
|
|
11
16
|
env: Record<string, string | undefined>;
|
package/dist/commands/sources.js
CHANGED
|
@@ -10,6 +10,7 @@ import { resolveSourceTarget } from '../source-target.js';
|
|
|
10
10
|
import { stillUnauthorizedSourceSeats } from '../sources-api.js';
|
|
11
11
|
import { listProductScopes, setScopeProduct } from '../teams-api.js';
|
|
12
12
|
import { pluralize, shortHost } from '../ui.js';
|
|
13
|
+
import { runSourcePeople, runSourceRoles } from './sources-roles.js';
|
|
13
14
|
/**
|
|
14
15
|
* `sources` — list every source the caller holds a developer or admin seat
|
|
15
16
|
* on, the read half of the publish-target-verification story.
|
|
@@ -24,8 +25,12 @@ export async function runSources(ctx, args) {
|
|
|
24
25
|
if (subcommand !== undefined) {
|
|
25
26
|
if (subcommand === 'scopes')
|
|
26
27
|
return runScopes(ctx, args, rest);
|
|
28
|
+
if (subcommand === 'roles')
|
|
29
|
+
return runSourceRoles(ctx, args, rest);
|
|
30
|
+
if (subcommand === 'people')
|
|
31
|
+
return runSourcePeople(ctx, args, rest);
|
|
27
32
|
if (subcommand !== 'products') {
|
|
28
|
-
throw usageError(`Unknown sources subcommand "${subcommand}".`, 'Run "ekanos sources" to list your sources, "ekanos sources products [enable|disable <product>]"
|
|
33
|
+
throw usageError(`Unknown sources subcommand "${subcommand}".`, 'Run "ekanos sources" to list your sources, "ekanos sources products [enable|disable <product>]", "ekanos sources scopes [add|remove <scope> <product>]", "ekanos sources roles [list|create|update|delete <role>]" or "ekanos sources people".');
|
|
29
34
|
}
|
|
30
35
|
return runProducts(ctx, args, rest);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,CAAC,WAAW,CAAC,CAAC;QAClD,IAAI,MAAM,CAAC,MAAM,KAAK,cAAc,EAAE,CAAC;YACrC,IAAI,CAAC,OAAO,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAClE,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC,IAAI,CAAC;QAC/C,MAAM,iBAAiB,CACrB,mBAAmB,IAAI,CAAC,GAAG,CAAC,IAAI,wCAAwC,EACxE,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CACpB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { StoredSession } from '../auth/credential-store';\nimport { loginHint } from '../auth/host-trust';\nimport {\n type AuthEnvironment,\n refreshStoredSession,\n requireSession,\n resolveAuthEnvironment,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport { authRequiredError, invalidStateError, usageError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { EKANOS_CONFIG_FILENAME } from '../project';\nimport { fetchSeatsWithOneRefresh } from '../seats';\nimport {\n type SourceProduct,\n type SourceProductsApiResult,\n listSourceProducts,\n setSourceProduct,\n} from '../source-products-api';\nimport { resolveSourceTarget } from '../source-target';\nimport { type SourceSeat, stillUnauthorizedSourceSeats } from '../sources-api';\nimport { listProductScopes, setScopeProduct } from '../teams-api';\nimport { type Ui, pluralize, shortHost } from '../ui';\n\nexport interface SourcesArgs {\n host?: string;\n /** `products [enable|disable <product>]`, `scopes [add|remove <scope> <product>]`; none lists the sources. */\n positionals?: readonly string[];\n source?: string;\n yes?: boolean;\n /** Where a project's ekanos.json may sit — its `source` field, if any, is the marker. */\n dir: string;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `sources` — list every source the caller holds a developer or admin seat\n * on, the read half of the publish-target-verification story.\n *\n * The list itself is the mechanism that makes `publish` safe: a partner (or\n * an agent acting for one) can always answer \"which sources can I possibly\n * publish to?\" before running `ekanos use` or passing `--source`.\n */\nexport async function runSources(\n ctx: CliContext,\n args: SourcesArgs,\n): Promise<ExitCode> {\n const [subcommand, ...rest] = args.positionals ?? [];\n if (subcommand !== undefined) {\n if (subcommand === 'scopes') return runScopes(ctx, args, rest);\n if (subcommand !== 'products') {\n throw usageError(\n `Unknown sources subcommand \"${subcommand}\".`,\n 'Run \"ekanos sources\" to list your sources, \"ekanos sources products [enable|disable <product>]\" or \"ekanos sources scopes [add|remove <scope> <product>]\".',\n );\n }\n return runProducts(ctx, args, rest);\n }\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const session = requireSession(env);\n\n const result = await fetchSeatsWithOneRefresh(env, session);\n\n if (result.status === 'unauthorized') {\n stillUnauthorizedSourceSeats(env);\n }\n\n const activeSource = readActiveSource(args.dir);\n\n return ctx.succeed(\n { host: env.host, sources: result.sources, activeSource },\n humanSummary(ctx.ui, env.host, result.sources, activeSource),\n );\n}\n\n/**\n * Best-effort, lenient read of ekanos.json's `source` field — mirrors\n * `readProjectHost` in `auth/session.ts`. A missing, unparseable, or\n * sourceless ekanos.json (or no project at all) simply means \"no active\n * source to mark\", never an error: `sources` must answer outside a project\n * too.\n */\nexport function readActiveSource(dir: string): string | null {\n const configPath = path.join(dir, EKANOS_CONFIG_FILENAME);\n\n let raw: string;\n try {\n raw = fs.readFileSync(configPath, 'utf8');\n } catch {\n return null;\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return null;\n }\n\n const source =\n typeof parsed === 'object' && parsed !== null\n ? (parsed as { source?: unknown }).source\n : undefined;\n\n return typeof source === 'string' && source.trim().length > 0\n ? source.trim()\n : null;\n}\n\n/** Why a product is not enabled, by the lever that would enable it — the words `catalog` uses. */\nconst NOT_ENABLED_BECAUSE: Record<SourceProduct['lever'], string> = {\n flag: 'its Flag is off',\n plan: 'no active plan',\n entitlement: 'not granted',\n};\n\nfunction humanSummary(\n ui: Ui,\n host: string,\n sources: SourceSeat[],\n activeSource: string | null,\n): string {\n if (sources.length === 0) {\n return ui.result({\n // Read by any signed-in account, a team member's too: no word here\n // may imply the host serves more than one customer.\n title: 'No partner seats',\n tone: 'warn',\n rows: [['Host', shortHost(host)]],\n notes: ['This account has no partner seats on this host.'],\n });\n }\n\n const orphaned =\n activeSource && !sources.some((s) => s.slug === activeSource);\n\n return ui.result({\n title: `${pluralize(sources.length, 'source')} on ${shortHost(host)}`,\n rows: sources.map((source): [string, string] => [\n source.slug,\n [\n source.name ?? '(unnamed)',\n source.roles.join(', '),\n ...(source.slug === activeSource ? [ui.accent('this project')] : []),\n ].join(' · '),\n ]),\n notes: orphaned\n ? [\n `This project's ekanos.json points at \"${activeSource}\", which is not in the list above.`,\n ]\n : [],\n });\n}\n\n/**\n * `sources products` — the catalog as one Source has it: every product, its\n * kind (Experience or Integration), and whether it is enabled for the Source.\n * `enable|disable <product>` switch one through the levers `/admin` uses\n * (`attachProductToSource` / `detachProductFromSource` for an Integration,\n * the Experience lever for an Experience). A Source admin switches the\n * integrations their Source built (`owned`); anything else is a super-admin\n * grant, which an `ekanos login` session never carries, so from the terminal\n * that write answers with where to do it.\n */\nasync function runProducts(\n ctx: CliContext,\n args: SourcesArgs,\n rest: readonly string[],\n): Promise<ExitCode> {\n const [verb, rawProduct, ...extra] = rest;\n if (extra.length > 0) {\n throw usageError(\n `Unexpected argument \"${extra[0]}\".`,\n 'Run \"ekanos sources products [enable|disable <product>] [--source <slug>]\".',\n );\n }\n if (verb !== undefined && verb !== 'enable' && verb !== 'disable') {\n throw usageError(\n `Unknown sources products subcommand \"${verb}\".`,\n 'Run \"ekanos sources products\", \"ekanos sources products enable <product>\" or \"ekanos sources products disable <product> --yes\".',\n );\n }\n const product = verb ? productSlug(rawProduct, verb) : null;\n if (verb === 'disable' && !args.yes) {\n throw invalidStateError(\n `Disabling ${product} removes it from the Source: its plans, widget settings, Source credentials and workspaces go with it.`,\n `Re-run with --yes: ekanos sources products disable ${product} --yes`,\n );\n }\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const resolved = await resolveSourceTarget(env, requireSession(env), {\n source: args.source,\n dir: args.dir,\n });\n const client = new ProductsClient(env, resolved.session);\n\n if (!verb || !product) {\n const list = await client.call((token) =>\n listSourceProducts(env.host, token, resolved.source),\n );\n const byKind = (kind: SourceProduct['kind']) =>\n list.products\n .filter((entry) => entry.kind === kind)\n .map((entry): [string, string] => [\n entry.slug,\n `${entry.enabled ? '✓ enabled' : `✗ not enabled (${NOT_ENABLED_BECAUSE[entry.lever]})`} · ${entry.name}${entry.owned ? ' · built by this Source' : ''}${entry.registered ? '' : ' · no package on this host'}`,\n ]);\n return ctx.succeed(\n { host: env.host, ...list },\n [\n ctx.ui.result({\n title: `Experiences on ${list.source.slug}`,\n rows: byKind('experience'),\n }),\n ctx.ui.result({\n title: `Integrations on ${list.source.slug}`,\n rows: byKind('integration'),\n notes: [\n list.canEnable\n ? '\"ekanos sources products enable|disable <product>\" switches one.'\n : list.canEnableOwned\n ? '\"ekanos sources products enable|disable <product>\" switches one built by this Source; any other is a super-admin grant, made in the browser at /admin/sources → the Source → Products.'\n : 'Enabling one is a super-admin grant, made in the browser at /admin/sources → the Source → Products.',\n '\"ekanos teams connect <team> <product>\" connects an enabled integration for a team.',\n ],\n }),\n ].join('\\n'),\n );\n }\n\n const enabled = verb === 'enable';\n const result = await client.call((token) =>\n setSourceProduct(env.host, token, {\n source: resolved.source,\n product,\n enabled,\n }),\n );\n return ctx.succeed(\n { host: env.host, ...result },\n ctx.ui.result({\n title: result.changed\n ? `${enabled ? 'Enabled' : 'Disabled'} ${result.product.name} for ${result.source.slug}`\n : `${result.product.name} was already ${enabled ? 'enabled' : 'off'} for ${result.source.slug}`,\n rows: [\n ['Kind', result.product.kind],\n [\n 'Switched by',\n result.product.lever === 'flag'\n ? 'its Flag'\n : result.product.lever === 'plan'\n ? 'its plan'\n : 'the entitlement',\n ],\n ],\n notes:\n enabled && result.product.kind === 'integration'\n ? [\n `Next: \"ekanos teams connect <team> ${result.product.slug}\" connects it for a team.`,\n ]\n : [],\n }),\n );\n}\n\n/**\n * `sources scopes` — the Source's product scopes, for its Source admin: each\n * scope's products and how many teams hold it. Once a Source has a scope,\n * each team sees in the app only its scopes' products. `add|remove <scope>\n * <product>` changes one scope (by name or id) through what\n * `/admin/sources/[id]/product-scopes` uses; a product can only be added if\n * the Source has it. Taking one out hides it from every team on the scope\n * that no other of its scopes shows it to, so that needs `--yes`.\n */\nasync function runScopes(\n ctx: CliContext,\n args: SourcesArgs,\n rest: readonly string[],\n): Promise<ExitCode> {\n const [verb, rawScope, rawProduct, ...extra] = rest;\n const usage =\n 'Run \"ekanos sources scopes\", \"ekanos sources scopes add <scope> <product>\" or \"ekanos sources scopes remove <scope> <product> --yes\".';\n if (verb !== undefined && verb !== 'add' && verb !== 'remove') {\n throw usageError(`Unknown sources scopes subcommand \"${verb}\".`, usage);\n }\n if (extra.length > 0) {\n throw usageError(`Unexpected argument \"${extra[0]}\".`, usage);\n }\n const scope = rawScope?.trim();\n if (verb && !scope) {\n throw usageError(\n `sources scopes ${verb} needs a scope and a product.`,\n usage,\n );\n }\n const product = verb ? scopeProductSlug(rawProduct, verb) : null;\n if (verb === 'remove' && !args.yes) {\n throw invalidStateError(\n `Taking ${product} out of ${scope} hides it, in the app, from every team on ${scope} that no other of its scopes shows it to.`,\n `Re-run with --yes: ekanos sources scopes remove ${quoteArg(scope!)} ${product} --yes`,\n );\n }\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const resolved = await resolveSourceTarget(env, requireSession(env), {\n source: args.source,\n dir: args.dir,\n });\n const client = new ProductsClient(env, resolved.session);\n\n if (!verb || !product || !scope) {\n const list = await client.call((token) =>\n listProductScopes(env.host, token, resolved.source),\n );\n if (list.scopes.length === 0) {\n return ctx.succeed(\n { host: env.host, ...list },\n ctx.ui.result({\n title: `No product scopes on ${list.source.slug}`,\n rows: [['Teams see', 'every product the Source has']],\n notes: [\n 'Scopes are created at /admin/sources → the Source → Product scopes.',\n ],\n }),\n );\n }\n return ctx.succeed(\n { host: env.host, ...list },\n ctx.ui.result({\n title: `Product scopes on ${list.source.slug}`,\n rows: list.scopes.map((entry): [string, string[]] => [\n entry.name,\n [\n `${pluralize(entry.teamCount, 'team')}${entry.isDefault ? ' · given to every new team' : ''}`,\n entry.products.length > 0\n ? entry.products.map((item) => item.slug).join(', ')\n : 'no products',\n ],\n ]),\n notes: [\n 'A team sees in the app only the products of the scopes it holds.',\n '\"ekanos sources scopes add <scope> <product>\" shows a product to every team on a scope; \"ekanos teams scope show|set <team>\" reads or changes which scopes a team holds.',\n ],\n }),\n );\n }\n\n const included = verb === 'add';\n const result = await client.call((token) =>\n setScopeProduct(\n env.host,\n token,\n { source: resolved.source, scope, product },\n included,\n ),\n );\n return ctx.succeed(\n { host: env.host, ...result },\n ctx.ui.result({\n title: result.changed\n ? `${included ? 'Added' : 'Took'} ${result.product.name} ${included ? 'to' : 'out of'} ${result.scope.name}`\n : `${result.product.name} was already ${included ? 'in' : 'not in'} ${result.scope.name}`,\n tone: !included && result.changed ? 'warn' : 'ok',\n rows: [\n ['Teams on it', String(result.scope.teamCount)],\n [\n 'Products',\n result.scope.products.length > 0\n ? result.scope.products.map((item) => item.slug).join(', ')\n : 'none',\n ],\n ],\n notes: [\n included\n ? `Every team on ${result.scope.name} sees ${result.product.slug} in the app now.`\n : `Teams on ${result.scope.name} see ${result.product.slug} only if another of their scopes has it.`,\n ],\n }),\n );\n}\n\nfunction scopeProductSlug(value: string | undefined, verb: string): string {\n const slug = value?.trim().toLowerCase();\n if (slug && /^[a-z0-9][a-z0-9-]*$/.test(slug)) return slug;\n throw usageError(\n value\n ? `\"${value}\" is not a product slug.`\n : `sources scopes ${verb} needs a product.`,\n '\"ekanos sources products\" lists them, e.g. \"ekanos sources scopes add Bronze linear\".',\n );\n}\n\nfunction quoteArg(value: string): string {\n return /^[A-Za-z0-9._-]+$/.test(value) ? value : `\"${value}\"`;\n}\n\nfunction productSlug(value: string | undefined, verb: string): string {\n const slug = value?.trim().toLowerCase();\n if (slug && /^[a-z0-9][a-z0-9-]*$/.test(slug)) return slug;\n throw usageError(\n value\n ? `\"${value}\" is not a product slug.`\n : `sources products ${verb} needs a product.`,\n '\"ekanos sources products\" lists them, e.g. \"ekanos sources products enable agents\".',\n );\n}\n\nclass ProductsClient {\n constructor(\n private readonly env: AuthEnvironment,\n private session: StoredSession,\n ) {}\n\n async call<T>(\n send: (accessToken: string) => Promise<SourceProductsApiResult<T>>,\n ): Promise<T> {\n let result = await send(this.session.accessToken);\n if (result.status === 'unauthorized') {\n this.session = await refreshStoredSession(this.env, this.session);\n result = await send(this.session.accessToken);\n }\n if (result.status === 'ok') return result.data;\n throw authRequiredError(\n `The session for ${this.env.host} could not authorize the sources call.`,\n loginHint(this.env),\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sources.js","sourceRoot":"","sources":["../../src/commands/sources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAEL,oBAAoB,EACpB,cAAc,EACd,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAGL,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,E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CAAC,IAAI,CAAC;QAC/C,MAAM,iBAAiB,CACrB,mBAAmB,IAAI,CAAC,GAAG,CAAC,IAAI,wCAAwC,EACxE,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CACpB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { StoredSession } from '../auth/credential-store';\nimport { loginHint } from '../auth/host-trust';\nimport {\n type AuthEnvironment,\n refreshStoredSession,\n requireSession,\n resolveAuthEnvironment,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport { authRequiredError, invalidStateError, usageError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { EKANOS_CONFIG_FILENAME } from '../project';\nimport { fetchSeatsWithOneRefresh } from '../seats';\nimport {\n type SourceProduct,\n type SourceProductsApiResult,\n listSourceProducts,\n setSourceProduct,\n} from '../source-products-api';\nimport { resolveSourceTarget } from '../source-target';\nimport { type SourceSeat, stillUnauthorizedSourceSeats } from '../sources-api';\nimport { listProductScopes, setScopeProduct } from '../teams-api';\nimport { type Ui, pluralize, shortHost } from '../ui';\nimport { runSourcePeople, runSourceRoles } from './sources-roles';\n\nexport interface SourcesArgs {\n host?: string;\n /** `products [enable|disable <product>]`, `scopes [add|remove <scope> <product>]`; none lists the sources. */\n positionals?: readonly string[];\n source?: string;\n yes?: boolean;\n /** `roles` and `people`: their flags (`--level`, `--permission`, `--search` …). */\n flags?: Record<string, string | boolean | string[]>;\n /** `roles delete` asks at a terminal; the test seams for it. */\n stdinIsTTY?: boolean;\n ask?: (question: string) => Promise<string>;\n /** Where a project's ekanos.json may sit — its `source` field, if any, is the marker. */\n dir: string;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `sources` — list every source the caller holds a developer or admin seat\n * on, the read half of the publish-target-verification story.\n *\n * The list itself is the mechanism that makes `publish` safe: a partner (or\n * an agent acting for one) can always answer \"which sources can I possibly\n * publish to?\" before running `ekanos use` or passing `--source`.\n */\nexport async function runSources(\n ctx: CliContext,\n args: SourcesArgs,\n): Promise<ExitCode> {\n const [subcommand, ...rest] = args.positionals ?? [];\n if (subcommand !== undefined) {\n if (subcommand === 'scopes') return runScopes(ctx, args, rest);\n if (subcommand === 'roles') return runSourceRoles(ctx, args, rest);\n if (subcommand === 'people') return runSourcePeople(ctx, args, rest);\n if (subcommand !== 'products') {\n throw usageError(\n `Unknown sources subcommand \"${subcommand}\".`,\n 'Run \"ekanos sources\" to list your sources, \"ekanos sources products [enable|disable <product>]\", \"ekanos sources scopes [add|remove <scope> <product>]\", \"ekanos sources roles [list|create|update|delete <role>]\" or \"ekanos sources people\".',\n );\n }\n return runProducts(ctx, args, rest);\n }\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const session = requireSession(env);\n\n const result = await fetchSeatsWithOneRefresh(env, session);\n\n if (result.status === 'unauthorized') {\n stillUnauthorizedSourceSeats(env);\n }\n\n const activeSource = readActiveSource(args.dir);\n\n return ctx.succeed(\n { host: env.host, sources: result.sources, activeSource },\n humanSummary(ctx.ui, env.host, result.sources, activeSource),\n );\n}\n\n/**\n * Best-effort, lenient read of ekanos.json's `source` field — mirrors\n * `readProjectHost` in `auth/session.ts`. A missing, unparseable, or\n * sourceless ekanos.json (or no project at all) simply means \"no active\n * source to mark\", never an error: `sources` must answer outside a project\n * too.\n */\nexport function readActiveSource(dir: string): string | null {\n const configPath = path.join(dir, EKANOS_CONFIG_FILENAME);\n\n let raw: string;\n try {\n raw = fs.readFileSync(configPath, 'utf8');\n } catch {\n return null;\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return null;\n }\n\n const source =\n typeof parsed === 'object' && parsed !== null\n ? (parsed as { source?: unknown }).source\n : undefined;\n\n return typeof source === 'string' && source.trim().length > 0\n ? source.trim()\n : null;\n}\n\n/** Why a product is not enabled, by the lever that would enable it — the words `catalog` uses. */\nconst NOT_ENABLED_BECAUSE: Record<SourceProduct['lever'], string> = {\n flag: 'its Flag is off',\n plan: 'no active plan',\n entitlement: 'not granted',\n};\n\nfunction humanSummary(\n ui: Ui,\n host: string,\n sources: SourceSeat[],\n activeSource: string | null,\n): string {\n if (sources.length === 0) {\n return ui.result({\n // Read by any signed-in account, a team member's too: no word here\n // may imply the host serves more than one customer.\n title: 'No partner seats',\n tone: 'warn',\n rows: [['Host', shortHost(host)]],\n notes: ['This account has no partner seats on this host.'],\n });\n }\n\n const orphaned =\n activeSource && !sources.some((s) => s.slug === activeSource);\n\n return ui.result({\n title: `${pluralize(sources.length, 'source')} on ${shortHost(host)}`,\n rows: sources.map((source): [string, string] => [\n source.slug,\n [\n source.name ?? '(unnamed)',\n source.roles.join(', '),\n ...(source.slug === activeSource ? [ui.accent('this project')] : []),\n ].join(' · '),\n ]),\n notes: orphaned\n ? [\n `This project's ekanos.json points at \"${activeSource}\", which is not in the list above.`,\n ]\n : [],\n });\n}\n\n/**\n * `sources products` — the catalog as one Source has it: every product, its\n * kind (Experience or Integration), and whether it is enabled for the Source.\n * `enable|disable <product>` switch one through the levers `/admin` uses\n * (`attachProductToSource` / `detachProductFromSource` for an Integration,\n * the Experience lever for an Experience). A Source admin switches the\n * integrations their Source built (`owned`); anything else is a super-admin\n * grant, which an `ekanos login` session never carries, so from the terminal\n * that write answers with where to do it.\n */\nasync function runProducts(\n ctx: CliContext,\n args: SourcesArgs,\n rest: readonly string[],\n): Promise<ExitCode> {\n const [verb, rawProduct, ...extra] = rest;\n if (extra.length > 0) {\n throw usageError(\n `Unexpected argument \"${extra[0]}\".`,\n 'Run \"ekanos sources products [enable|disable <product>] [--source <slug>]\".',\n );\n }\n if (verb !== undefined && verb !== 'enable' && verb !== 'disable') {\n throw usageError(\n `Unknown sources products subcommand \"${verb}\".`,\n 'Run \"ekanos sources products\", \"ekanos sources products enable <product>\" or \"ekanos sources products disable <product> --yes\".',\n );\n }\n const product = verb ? productSlug(rawProduct, verb) : null;\n if (verb === 'disable' && !args.yes) {\n throw invalidStateError(\n `Disabling ${product} removes it from the Source: its plans, widget settings, Source credentials and workspaces go with it.`,\n `Re-run with --yes: ekanos sources products disable ${product} --yes`,\n );\n }\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const resolved = await resolveSourceTarget(env, requireSession(env), {\n source: args.source,\n dir: args.dir,\n });\n const client = new ProductsClient(env, resolved.session);\n\n if (!verb || !product) {\n const list = await client.call((token) =>\n listSourceProducts(env.host, token, resolved.source),\n );\n const byKind = (kind: SourceProduct['kind']) =>\n list.products\n .filter((entry) => entry.kind === kind)\n .map((entry): [string, string] => [\n entry.slug,\n `${entry.enabled ? '✓ enabled' : `✗ not enabled (${NOT_ENABLED_BECAUSE[entry.lever]})`} · ${entry.name}${entry.owned ? ' · built by this Source' : ''}${entry.registered ? '' : ' · no package on this host'}`,\n ]);\n return ctx.succeed(\n { host: env.host, ...list },\n [\n ctx.ui.result({\n title: `Experiences on ${list.source.slug}`,\n rows: byKind('experience'),\n }),\n ctx.ui.result({\n title: `Integrations on ${list.source.slug}`,\n rows: byKind('integration'),\n notes: [\n list.canEnable\n ? '\"ekanos sources products enable|disable <product>\" switches one.'\n : list.canEnableOwned\n ? '\"ekanos sources products enable|disable <product>\" switches one built by this Source; any other is a super-admin grant, made in the browser at /admin/sources → the Source → Products.'\n : 'Enabling one is a super-admin grant, made in the browser at /admin/sources → the Source → Products.',\n '\"ekanos teams connect <team> <product>\" connects an enabled integration for a team.',\n ],\n }),\n ].join('\\n'),\n );\n }\n\n const enabled = verb === 'enable';\n const result = await client.call((token) =>\n setSourceProduct(env.host, token, {\n source: resolved.source,\n product,\n enabled,\n }),\n );\n return ctx.succeed(\n { host: env.host, ...result },\n ctx.ui.result({\n title: result.changed\n ? `${enabled ? 'Enabled' : 'Disabled'} ${result.product.name} for ${result.source.slug}`\n : `${result.product.name} was already ${enabled ? 'enabled' : 'off'} for ${result.source.slug}`,\n rows: [\n ['Kind', result.product.kind],\n [\n 'Switched by',\n result.product.lever === 'flag'\n ? 'its Flag'\n : result.product.lever === 'plan'\n ? 'its plan'\n : 'the entitlement',\n ],\n ],\n notes:\n enabled && result.product.kind === 'integration'\n ? [\n `Next: \"ekanos teams connect <team> ${result.product.slug}\" connects it for a team.`,\n ]\n : [],\n }),\n );\n}\n\n/**\n * `sources scopes` — the Source's product scopes, for its Source admin: each\n * scope's products and how many teams hold it. Once a Source has a scope,\n * each team sees in the app only its scopes' products. `add|remove <scope>\n * <product>` changes one scope (by name or id) through what\n * `/admin/sources/[id]/product-scopes` uses; a product can only be added if\n * the Source has it. Taking one out hides it from every team on the scope\n * that no other of its scopes shows it to, so that needs `--yes`.\n */\nasync function runScopes(\n ctx: CliContext,\n args: SourcesArgs,\n rest: readonly string[],\n): Promise<ExitCode> {\n const [verb, rawScope, rawProduct, ...extra] = rest;\n const usage =\n 'Run \"ekanos sources scopes\", \"ekanos sources scopes add <scope> <product>\" or \"ekanos sources scopes remove <scope> <product> --yes\".';\n if (verb !== undefined && verb !== 'add' && verb !== 'remove') {\n throw usageError(`Unknown sources scopes subcommand \"${verb}\".`, usage);\n }\n if (extra.length > 0) {\n throw usageError(`Unexpected argument \"${extra[0]}\".`, usage);\n }\n const scope = rawScope?.trim();\n if (verb && !scope) {\n throw usageError(\n `sources scopes ${verb} needs a scope and a product.`,\n usage,\n );\n }\n const product = verb ? scopeProductSlug(rawProduct, verb) : null;\n if (verb === 'remove' && !args.yes) {\n throw invalidStateError(\n `Taking ${product} out of ${scope} hides it, in the app, from every team on ${scope} that no other of its scopes shows it to.`,\n `Re-run with --yes: ekanos sources scopes remove ${quoteArg(scope!)} ${product} --yes`,\n );\n }\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const resolved = await resolveSourceTarget(env, requireSession(env), {\n source: args.source,\n dir: args.dir,\n });\n const client = new ProductsClient(env, resolved.session);\n\n if (!verb || !product || !scope) {\n const list = await client.call((token) =>\n listProductScopes(env.host, token, resolved.source),\n );\n if (list.scopes.length === 0) {\n return ctx.succeed(\n { host: env.host, ...list },\n ctx.ui.result({\n title: `No product scopes on ${list.source.slug}`,\n rows: [['Teams see', 'every product the Source has']],\n notes: [\n 'Scopes are created at /admin/sources → the Source → Product scopes.',\n ],\n }),\n );\n }\n return ctx.succeed(\n { host: env.host, ...list },\n ctx.ui.result({\n title: `Product scopes on ${list.source.slug}`,\n rows: list.scopes.map((entry): [string, string[]] => [\n entry.name,\n [\n `${pluralize(entry.teamCount, 'team')}${entry.isDefault ? ' · given to every new team' : ''}`,\n entry.products.length > 0\n ? entry.products.map((item) => item.slug).join(', ')\n : 'no products',\n ],\n ]),\n notes: [\n 'A team sees in the app only the products of the scopes it holds.',\n '\"ekanos sources scopes add <scope> <product>\" shows a product to every team on a scope; \"ekanos teams scope show|set <team>\" reads or changes which scopes a team holds.',\n ],\n }),\n );\n }\n\n const included = verb === 'add';\n const result = await client.call((token) =>\n setScopeProduct(\n env.host,\n token,\n { source: resolved.source, scope, product },\n included,\n ),\n );\n return ctx.succeed(\n { host: env.host, ...result },\n ctx.ui.result({\n title: result.changed\n ? `${included ? 'Added' : 'Took'} ${result.product.name} ${included ? 'to' : 'out of'} ${result.scope.name}`\n : `${result.product.name} was already ${included ? 'in' : 'not in'} ${result.scope.name}`,\n tone: !included && result.changed ? 'warn' : 'ok',\n rows: [\n ['Teams on it', String(result.scope.teamCount)],\n [\n 'Products',\n result.scope.products.length > 0\n ? result.scope.products.map((item) => item.slug).join(', ')\n : 'none',\n ],\n ],\n notes: [\n included\n ? `Every team on ${result.scope.name} sees ${result.product.slug} in the app now.`\n : `Teams on ${result.scope.name} see ${result.product.slug} only if another of their scopes has it.`,\n ],\n }),\n );\n}\n\nfunction scopeProductSlug(value: string | undefined, verb: string): string {\n const slug = value?.trim().toLowerCase();\n if (slug && /^[a-z0-9][a-z0-9-]*$/.test(slug)) return slug;\n throw usageError(\n value\n ? `\"${value}\" is not a product slug.`\n : `sources scopes ${verb} needs a product.`,\n '\"ekanos sources products\" lists them, e.g. \"ekanos sources scopes add Bronze linear\".',\n );\n}\n\nfunction quoteArg(value: string): string {\n return /^[A-Za-z0-9._-]+$/.test(value) ? value : `\"${value}\"`;\n}\n\nfunction productSlug(value: string | undefined, verb: string): string {\n const slug = value?.trim().toLowerCase();\n if (slug && /^[a-z0-9][a-z0-9-]*$/.test(slug)) return slug;\n throw usageError(\n value\n ? `\"${value}\" is not a product slug.`\n : `sources products ${verb} needs a product.`,\n '\"ekanos sources products\" lists them, e.g. \"ekanos sources products enable agents\".',\n );\n}\n\nclass ProductsClient {\n constructor(\n private readonly env: AuthEnvironment,\n private session: StoredSession,\n ) {}\n\n async call<T>(\n send: (accessToken: string) => Promise<SourceProductsApiResult<T>>,\n ): Promise<T> {\n let result = await send(this.session.accessToken);\n if (result.status === 'unauthorized') {\n this.session = await refreshStoredSession(this.env, this.session);\n result = await send(this.session.accessToken);\n }\n if (result.status === 'ok') return result.data;\n throw authRequiredError(\n `The session for ${this.env.host} could not authorize the sources call.`,\n loginHint(this.env),\n );\n }\n}\n"]}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import type { AgentRunSummary, ChannelRequirement, Requirement, TeamAgentEntry, TeamAgentHold, TeamIntegrationEvent } from '@ekanos/integration-schema';
|
|
2
2
|
import { type ScopeFacts } from './scope-notice.js';
|
|
3
|
+
/**
|
|
4
|
+
* "Is this agent live on this team, and if not, why?" — one answer for
|
|
5
|
+
* `teams agents show` and the summary line of `teams agents list`, built only
|
|
6
|
+
* from what the host already reports (CLI audit 2026-10-19, §3).
|
|
7
|
+
*
|
|
8
|
+
* Live is: on, on a published version, every connection it needs made,
|
|
9
|
+
* access confirmed by someone who sets it up (a team manager or the Source
|
|
10
|
+
* admin, plan 247.2), at least one trigger on, and every trigger's events
|
|
11
|
+
* able to reach it. Each gap is a step with one fix, in the order they have
|
|
12
|
+
* to be done; the first step's fix is "Next". A publish holds no team, so
|
|
13
|
+
* there is no update waiting.
|
|
14
|
+
*/
|
|
3
15
|
export interface ReadinessStep {
|
|
4
16
|
/** What is missing, in words. */
|
|
5
17
|
problem: string;
|
|
@@ -26,11 +38,15 @@ export declare function describeHold(hold: TeamAgentHold): string;
|
|
|
26
38
|
export declare const REASON_WORDS: Record<NonNullable<Requirement['reason']>, string>;
|
|
27
39
|
/** The one command that makes a requirement, or null when none can. */
|
|
28
40
|
export declare function requirementFix(item: Requirement, team: string, source: string): string | null;
|
|
29
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The one command that makes a channel ready. An older host sends no
|
|
43
|
+
* `arrival`: the channel's key (`<product>:webhook`, `<product>:route`,
|
|
44
|
+
* `<product>:<connection>`) still says which command it is.
|
|
45
|
+
*/
|
|
30
46
|
export declare function channelFix(channel: ChannelRequirement, team: string, source: string): string;
|
|
31
47
|
/** How the events of a ready channel reach the agent. */
|
|
32
48
|
export declare function reachedVia(channel: ChannelRequirement): string;
|
|
33
|
-
/** A fix as a line: a command is run in the terminal
|
|
49
|
+
/** A fix as a line: a command is run in the terminal; anything else is a person's step. */
|
|
34
50
|
export declare function fixLine(fix: string): string;
|
|
35
51
|
/** "Live: yes" or "Live: no — N steps left". */
|
|
36
52
|
export declare function liveLine(readiness: AgentReadiness): string;
|