teamclaws 2.0.14 → 2.0.16
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 +32 -0
- package/dist/app.js +87 -2
- package/dist/broker.js +128 -1
- package/dist/constants.js +1 -1
- package/dist/errors.js +2 -0
- package/dist/output.js +64 -1
- package/dist/users.js +56 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -209,6 +209,7 @@ npx teamclaws pair
|
|
|
209
209
|
npx teamclaws pair <server-identifier-or-canonical-workspace-address> [--no-open]
|
|
210
210
|
npx teamclaws shell <target> --command <text> [--json]
|
|
211
211
|
npx teamclaws users add <target> <email> [--sudo] [--json]
|
|
212
|
+
npx teamclaws users remove <target> <email> [--json]
|
|
212
213
|
npx teamclaws chat start <target> --message <text>
|
|
213
214
|
npx teamclaws chat send <target> --session-id <uuid> --message <text>
|
|
214
215
|
npx teamclaws chat watch <target> --session-id <uuid> --request-id <uuid>
|
|
@@ -281,6 +282,20 @@ requires the workspace to acknowledge the saved sudo selection before reporting
|
|
|
281
282
|
a new sudo invitation as successful. Existing members and pending invitations
|
|
282
283
|
remain unchanged even when the flag is supplied.
|
|
283
284
|
|
|
285
|
+
### Remove a workspace user
|
|
286
|
+
|
|
287
|
+
```text
|
|
288
|
+
teamclaws users remove <target> <email> --json
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Only the current machine owner can remove a member or revoke a pending
|
|
292
|
+
invitation. This removes access across all machines sharing the access group;
|
|
293
|
+
it does not delete the person's TeamClaws account. Machine and access-group
|
|
294
|
+
owners cannot be removed. No matching member or invitation returns an error.
|
|
295
|
+
The command uses the saved paired authorization without opening a browser or
|
|
296
|
+
starting a shell or chat. If the outcome is uncertain, inspect user and
|
|
297
|
+
invitation status before retrying; removal does not blindly retry.
|
|
298
|
+
|
|
284
299
|
### Inspect users and invitation status
|
|
285
300
|
|
|
286
301
|
```text
|
|
@@ -297,6 +312,23 @@ When supplied by the workspace, each entry includes its saved `sudo_enabled`
|
|
|
297
312
|
status. An accepted invitation's selection is historical; the current member's
|
|
298
313
|
status determines their current access.
|
|
299
314
|
|
|
315
|
+
## Manage GitHub repository permissions for a server
|
|
316
|
+
|
|
317
|
+
These commands manage server access to repositories you have already connected to TeamClaws.
|
|
318
|
+
|
|
319
|
+
```sh
|
|
320
|
+
teamclaws git repos
|
|
321
|
+
teamclaws git list <server-id>
|
|
322
|
+
teamclaws git set <server-id> <repository-id> --issues read --contents write --pull-requests read --workflows none
|
|
323
|
+
teamclaws git remove <server-id> <repository-id>
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Use `teamclaws servers list` to find the server ID and `teamclaws git repos` to find the repository ID. If you have no connected repositories or cannot find the repository you need, add it at [Connected GitHub](https://www.teamclaws.com/app/connected-github/).
|
|
327
|
+
|
|
328
|
+
Server owners can list, set, and remove permissions for their servers. `git set` requires all four flags. Issues, contents, and pull requests accept `none`, `read`, or `write`. Workflows accepts `none` or `write`. Setting all four to `none` removes the assignment. `git remove` also succeeds when the repository is already unassigned.
|
|
329
|
+
|
|
330
|
+
Each command supports `--json`. If a mutation returns an uncertain result, run `git list` to check the saved permissions before retrying.
|
|
331
|
+
|
|
300
332
|
## Read chat history without a browser
|
|
301
333
|
|
|
302
334
|
```text
|
package/dist/app.js
CHANGED
|
@@ -11,7 +11,7 @@ import { CredentialStore } from "./storage.js";
|
|
|
11
11
|
import { TargetAuthorization } from "./target-authorization.js";
|
|
12
12
|
import { installRelease } from "./update.js";
|
|
13
13
|
import { normalizeUuid, parsePairingTarget } from "./validation.js";
|
|
14
|
-
import { runUsersAdd, runUsersList } from "./users.js";
|
|
14
|
+
import { runUsersAdd, runUsersList, runUsersRemove } from "./users.js";
|
|
15
15
|
export async function run(arguments_, dependencies = {}, signal) {
|
|
16
16
|
let parsed;
|
|
17
17
|
try {
|
|
@@ -96,6 +96,18 @@ export async function run(arguments_, dependencies = {}, signal) {
|
|
|
96
96
|
return safe.exitCode;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
+
if (parsed.action === "users_remove") {
|
|
100
|
+
try {
|
|
101
|
+
await targetAuthorization.requireGrant();
|
|
102
|
+
output.usersRemoveResult(await runUsersRemove(store, dependencies.fetcher ?? fetch, parsed.target, parsed.email, targetAuthorization, signal));
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
const safe = safeError(error);
|
|
107
|
+
output.error(safe);
|
|
108
|
+
return safe.exitCode;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
99
111
|
const auth = new AuthService({
|
|
100
112
|
store,
|
|
101
113
|
output,
|
|
@@ -158,6 +170,18 @@ export async function run(arguments_, dependencies = {}, signal) {
|
|
|
158
170
|
output.serverMetadataUpdated(server);
|
|
159
171
|
return 0;
|
|
160
172
|
}
|
|
173
|
+
case "git_repos":
|
|
174
|
+
output.gitRepositories(await broker.gitRepositories(signal));
|
|
175
|
+
return 0;
|
|
176
|
+
case "git_list":
|
|
177
|
+
output.gitAssignments(await broker.gitAssignments(parsed.serverId, signal));
|
|
178
|
+
return 0;
|
|
179
|
+
case "git_set":
|
|
180
|
+
output.gitAssignmentResult(await broker.setGitAssignment(parsed.serverId, parsed.repositoryId, parsed.permissions, signal));
|
|
181
|
+
return 0;
|
|
182
|
+
case "git_remove":
|
|
183
|
+
output.gitAssignmentResult(await broker.removeGitAssignment(parsed.serverId, parsed.repositoryId, signal));
|
|
184
|
+
return 0;
|
|
161
185
|
case "pair": {
|
|
162
186
|
const target = parsed.target
|
|
163
187
|
? parsePairingTarget(parsed.target)
|
|
@@ -193,6 +217,55 @@ export async function run(arguments_, dependencies = {}, signal) {
|
|
|
193
217
|
}
|
|
194
218
|
}
|
|
195
219
|
export function parseArguments(arguments_) {
|
|
220
|
+
if (arguments_[0] === "git") {
|
|
221
|
+
const operation = arguments_[1];
|
|
222
|
+
if (operation === "repos") {
|
|
223
|
+
const { flags } = parseNamedOptions(arguments_.slice(2), {
|
|
224
|
+
values: [],
|
|
225
|
+
booleans: ["--json"],
|
|
226
|
+
});
|
|
227
|
+
return { action: "git_repos", json: flags.has("--json") };
|
|
228
|
+
}
|
|
229
|
+
if (operation !== "list" && operation !== "set" && operation !== "remove")
|
|
230
|
+
throw usageError();
|
|
231
|
+
const serverId = normalizeUuid(requiredPositional(arguments_, 2));
|
|
232
|
+
if (operation === "list") {
|
|
233
|
+
const { flags } = parseNamedOptions(arguments_.slice(3), {
|
|
234
|
+
values: [],
|
|
235
|
+
booleans: ["--json"],
|
|
236
|
+
});
|
|
237
|
+
return { action: "git_list", serverId, json: flags.has("--json") };
|
|
238
|
+
}
|
|
239
|
+
const rawRepositoryId = requiredPositional(arguments_, 3);
|
|
240
|
+
const repositoryId = Number(rawRepositoryId);
|
|
241
|
+
if (!/^[1-9][0-9]*$/.test(rawRepositoryId) ||
|
|
242
|
+
!Number.isSafeInteger(repositoryId))
|
|
243
|
+
throw usageError();
|
|
244
|
+
const { values, flags } = parseNamedOptions(arguments_.slice(4), {
|
|
245
|
+
values: operation === "set"
|
|
246
|
+
? ["--issues", "--contents", "--pull-requests", "--workflows"]
|
|
247
|
+
: [],
|
|
248
|
+
booleans: ["--json"],
|
|
249
|
+
});
|
|
250
|
+
const json = flags.has("--json");
|
|
251
|
+
if (operation === "remove")
|
|
252
|
+
return { action: "git_remove", serverId, repositoryId, json };
|
|
253
|
+
const workflows = values["--workflows"];
|
|
254
|
+
if (workflows !== "none" && workflows !== "write")
|
|
255
|
+
throw usageError();
|
|
256
|
+
return {
|
|
257
|
+
action: "git_set",
|
|
258
|
+
serverId,
|
|
259
|
+
repositoryId,
|
|
260
|
+
json,
|
|
261
|
+
permissions: {
|
|
262
|
+
issues: gitAccessLevel(values["--issues"]),
|
|
263
|
+
contents: gitAccessLevel(values["--contents"]),
|
|
264
|
+
pull_requests: gitAccessLevel(values["--pull-requests"]),
|
|
265
|
+
workflows,
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
}
|
|
196
269
|
if (arguments_[0] === "servers" && arguments_[1] === "update") {
|
|
197
270
|
const serverId = normalizeUuid(requiredPositional(arguments_, 2));
|
|
198
271
|
const updates = {};
|
|
@@ -249,6 +322,13 @@ export function parseArguments(arguments_) {
|
|
|
249
322
|
json,
|
|
250
323
|
target: parsePairingTarget(requiredPositional(args, 2)),
|
|
251
324
|
};
|
|
325
|
+
if (args[0] === "users" && args[1] === "remove" && args.length === 4) {
|
|
326
|
+
const target = parsePairingTarget(requiredPositional(args, 2));
|
|
327
|
+
const email = requiredPositional(args, 3).trim().toLowerCase();
|
|
328
|
+
if (!email || email.length > 254)
|
|
329
|
+
throw usageError();
|
|
330
|
+
return { action: "users_remove", json, target, email };
|
|
331
|
+
}
|
|
252
332
|
if (args[0] === "users" && args[1] === "add") {
|
|
253
333
|
const target = parsePairingTarget(requiredPositional(args, 2));
|
|
254
334
|
const email = requiredPositional(args, 3).trim().toLowerCase();
|
|
@@ -455,6 +535,11 @@ function parseNamedOptions(args, allowed) {
|
|
|
455
535
|
}
|
|
456
536
|
return { values, flags };
|
|
457
537
|
}
|
|
538
|
+
function gitAccessLevel(value) {
|
|
539
|
+
if (value === "none" || value === "read" || value === "write")
|
|
540
|
+
return value;
|
|
541
|
+
throw usageError();
|
|
542
|
+
}
|
|
458
543
|
function nonNegativeInteger(value) {
|
|
459
544
|
if (value === undefined)
|
|
460
545
|
return 0;
|
|
@@ -548,5 +633,5 @@ function usageError() {
|
|
|
548
633
|
});
|
|
549
634
|
}
|
|
550
635
|
export function helpText() {
|
|
551
|
-
return `TeamClaws ${PACKAGE_VERSION}\n\nUsage:\n teamclaws update [--json]\n teamclaws shell <target> --command <text> [--json]\n teamclaws users add <target> <email> [--sudo] [--json]\n teamclaws users list <target> [--json]\n teamclaws login <email> [--json]\n teamclaws auth status [--json]\n teamclaws logout [--revoke] [--json]\n teamclaws servers list [--json]\n teamclaws servers update <server-id> [--name <text>] [--description <text>] [--json]\n teamclaws pair status <server-identifier-or-canonical-workspace-address> [--json]\n teamclaws pair [server-identifier-or-canonical-workspace-address] [--no-open] [--json]\n teamclaws chat list <target> [--json]\n teamclaws chat history <target> [--json]\n teamclaws chat messages <target> --chat-id <uuid> [--after-message-id <n>] [--json]\n teamclaws chat capabilities <target> [--json]\n teamclaws chat start <target> --message <text> [selection options] [--json]\n teamclaws chat send <target> --session-id <uuid> --message <text> [--json]\n teamclaws chat watch <target> --session-id <uuid> --request-id <uuid> [resume cursors] [--json]\n\nPair status performs one bounded direct verification and stops. Pairing grants the standard host-issued credential. Chat commands use that credential directly against the selected workspace.\n`;
|
|
636
|
+
return `TeamClaws ${PACKAGE_VERSION}\n\nUsage:\n teamclaws update [--json]\n teamclaws shell <target> --command <text> [--json]\n teamclaws users add <target> <email> [--sudo] [--json]\n teamclaws users remove <target> <email> [--json]\n teamclaws users list <target> [--json]\n teamclaws login <email> [--json]\n teamclaws auth status [--json]\n teamclaws logout [--revoke] [--json]\n teamclaws servers list [--json]\n teamclaws servers update <server-id> [--name <text>] [--description <text>] [--json]\n teamclaws git repos [--json]\n teamclaws git list <server-id> [--json]\n teamclaws git set <server-id> <repository-id> --issues <none|read|write> --contents <none|read|write> --pull-requests <none|read|write> --workflows <none|write> [--json]\n teamclaws git remove <server-id> <repository-id> [--json]\n teamclaws pair status <server-identifier-or-canonical-workspace-address> [--json]\n teamclaws pair [server-identifier-or-canonical-workspace-address] [--no-open] [--json]\n teamclaws chat list <target> [--json]\n teamclaws chat history <target> [--json]\n teamclaws chat messages <target> --chat-id <uuid> [--after-message-id <n>] [--json]\n teamclaws chat capabilities <target> [--json]\n teamclaws chat start <target> --message <text> [selection options] [--json]\n teamclaws chat send <target> --session-id <uuid> --message <text> [--json]\n teamclaws chat watch <target> --session-id <uuid> --request-id <uuid> [resume cursors] [--json]\n\nPair status performs one bounded direct verification and stops. Pairing grants the standard host-issued credential. Chat commands use that credential directly against the selected workspace.\n`;
|
|
552
637
|
}
|
package/dist/broker.js
CHANGED
|
@@ -3,7 +3,14 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { API_BASE, CLIENT_NAME, CONTRACT_VERSION, MAX_CLIENT_LABEL_LENGTH, MAX_DEVICE_NAME_LENGTH, PACKAGE_VERSION, } from "./constants.js";
|
|
4
4
|
import { TeamClawsError } from "./errors.js";
|
|
5
5
|
import { errorFromResponse, requestJson } from "./http.js";
|
|
6
|
-
import { assertExactKeys, isObject, normalizeUuid, parsePendingPairing, parseWorkspaceInventory, requireString, } from "./validation.js";
|
|
6
|
+
import { assertExactKeys, isObject, normalizeUuid, parsePendingPairing, parseWorkspaceInventory, requireInteger, requireString, } from "./validation.js";
|
|
7
|
+
const CONNECTED_GITHUB_URL = "https://www.teamclaws.com/app/connected-github/";
|
|
8
|
+
const GIT_PERMISSION_KEYS = [
|
|
9
|
+
"issues",
|
|
10
|
+
"contents",
|
|
11
|
+
"pull_requests",
|
|
12
|
+
"workflows",
|
|
13
|
+
];
|
|
7
14
|
export class BrokerClient {
|
|
8
15
|
fetcher;
|
|
9
16
|
deviceName;
|
|
@@ -54,6 +61,94 @@ export class BrokerClient {
|
|
|
54
61
|
assertExactKeys(response.body, ["server"], [], "server metadata response");
|
|
55
62
|
return editableServer(response.body.server, id);
|
|
56
63
|
}
|
|
64
|
+
async gitRepositories(signal) {
|
|
65
|
+
const body = await this.gitRequest("GET", `${API_BASE}github-repositories/`, signal);
|
|
66
|
+
assertExactKeys(body, ["repositories", "connect_url"], [], "repository list");
|
|
67
|
+
if (!Array.isArray(body.repositories) ||
|
|
68
|
+
body.connect_url !== CONNECTED_GITHUB_URL)
|
|
69
|
+
throw invalidGitResponse();
|
|
70
|
+
return {
|
|
71
|
+
repositories: body.repositories.map((row) => {
|
|
72
|
+
if (!isObject(row))
|
|
73
|
+
throw invalidGitResponse();
|
|
74
|
+
assertExactKeys(row, ["repository_id", "full_name"], [], "repository");
|
|
75
|
+
return gitRepository(row);
|
|
76
|
+
}),
|
|
77
|
+
connect_url: body.connect_url,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async gitAssignments(serverId, signal) {
|
|
81
|
+
const id = normalizeUuid(serverId);
|
|
82
|
+
const body = await this.gitRequest("GET", `${API_BASE}servers/${id}/github-repositories/`, signal);
|
|
83
|
+
assertExactKeys(body, ["server_id", "repositories"], [], "repository assignment list");
|
|
84
|
+
if (body.server_id !== id || !Array.isArray(body.repositories))
|
|
85
|
+
throw invalidGitResponse();
|
|
86
|
+
return {
|
|
87
|
+
server_id: id,
|
|
88
|
+
repositories: body.repositories.map((row) => {
|
|
89
|
+
if (!isObject(row))
|
|
90
|
+
throw invalidGitResponse();
|
|
91
|
+
assertExactKeys(row, ["repository_id", "full_name", "permissions"], [], "repository assignment");
|
|
92
|
+
return {
|
|
93
|
+
...gitRepository(row),
|
|
94
|
+
permissions: gitPermissions(row.permissions),
|
|
95
|
+
};
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
setGitAssignment(serverId, repositoryId, permissions, signal) {
|
|
100
|
+
return this.changeGitAssignment(serverId, repositoryId, signal, permissions);
|
|
101
|
+
}
|
|
102
|
+
removeGitAssignment(serverId, repositoryId, signal) {
|
|
103
|
+
return this.changeGitAssignment(serverId, repositoryId, signal);
|
|
104
|
+
}
|
|
105
|
+
async changeGitAssignment(serverId, repositoryId, signal, permissions) {
|
|
106
|
+
const id = normalizeUuid(serverId);
|
|
107
|
+
const url = `${API_BASE}servers/${id}/github-repositories/${repositoryId}/`;
|
|
108
|
+
const body = await this.gitRequest(permissions ? "POST" : "DELETE", url, signal, permissions ? { permissions } : undefined);
|
|
109
|
+
assertExactKeys(body, ["server_id", "repository_id", "full_name", "permissions", "code"], [], "repository assignment result");
|
|
110
|
+
if (body.server_id !== id || body.repository_id !== repositoryId)
|
|
111
|
+
throw invalidGitResponse();
|
|
112
|
+
const effective = gitPermissions(body.permissions);
|
|
113
|
+
if (!GIT_PERMISSION_KEYS.every((key) => effective[key] === (permissions?.[key] ?? "none")))
|
|
114
|
+
throw invalidGitResponse();
|
|
115
|
+
const assigned = GIT_PERMISSION_KEYS.some((key) => effective[key] !== "none");
|
|
116
|
+
const code = body.code;
|
|
117
|
+
if (assigned
|
|
118
|
+
? code !== "permissions_set"
|
|
119
|
+
: code !== "removed" && code !== "already_unassigned")
|
|
120
|
+
throw invalidGitResponse();
|
|
121
|
+
return {
|
|
122
|
+
...gitRepository(body),
|
|
123
|
+
server_id: id,
|
|
124
|
+
permissions: effective,
|
|
125
|
+
code: code,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async gitRequest(method, url, signal, body) {
|
|
129
|
+
const response = await requestJson(this.fetcher, url, {
|
|
130
|
+
method,
|
|
131
|
+
headers: await this.issuerHeaders(method, url),
|
|
132
|
+
...(body === undefined ? {} : { body }),
|
|
133
|
+
...(signal ? { signal } : {}),
|
|
134
|
+
});
|
|
135
|
+
if (response.status !== 200) {
|
|
136
|
+
const error = errorFromResponse(response, "git_permissions_failed");
|
|
137
|
+
if (error.code === "repository_unavailable" &&
|
|
138
|
+
isObject(response.body) &&
|
|
139
|
+
isObject(response.body.error) &&
|
|
140
|
+
response.body.error.connect_url === CONNECTED_GITHUB_URL) {
|
|
141
|
+
throw new TeamClawsError(error.code, error.message, {
|
|
142
|
+
exitCode: error.exitCode,
|
|
143
|
+
connectUrl: CONNECTED_GITHUB_URL,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
if (!isObject(response.body))
|
|
149
|
+
throw invalidGitResponse();
|
|
150
|
+
return response.body;
|
|
151
|
+
}
|
|
57
152
|
async claimMetadataPrompt(serverId, signal) {
|
|
58
153
|
const id = normalizeUuid(serverId);
|
|
59
154
|
const url = `${API_BASE}servers/${id}/metadata-prompt/claim/`;
|
|
@@ -109,6 +204,38 @@ export class BrokerClient {
|
|
|
109
204
|
};
|
|
110
205
|
}
|
|
111
206
|
}
|
|
207
|
+
function invalidGitResponse() {
|
|
208
|
+
return new TeamClawsError("invalid_response", "TeamClaws returned an invalid Git permissions response.", { exitCode: 9 });
|
|
209
|
+
}
|
|
210
|
+
function gitRepository(value) {
|
|
211
|
+
const fullName = requireString(value.full_name, "repository name");
|
|
212
|
+
if (!/^[a-z0-9_.-]+\/[a-z0-9_.-]+$/i.test(fullName))
|
|
213
|
+
throw invalidGitResponse();
|
|
214
|
+
return {
|
|
215
|
+
repository_id: requireInteger(value.repository_id, "repository ID", 1, Number.MAX_SAFE_INTEGER),
|
|
216
|
+
full_name: fullName,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function gitPermissions(value) {
|
|
220
|
+
if (!isObject(value))
|
|
221
|
+
throw invalidGitResponse();
|
|
222
|
+
assertExactKeys(value, GIT_PERMISSION_KEYS, [], "Git permission map");
|
|
223
|
+
const access = (key) => {
|
|
224
|
+
const level = value[key];
|
|
225
|
+
if (level === "none" || level === "read" || level === "write")
|
|
226
|
+
return level;
|
|
227
|
+
throw invalidGitResponse();
|
|
228
|
+
};
|
|
229
|
+
const workflows = value.workflows;
|
|
230
|
+
if (workflows !== "none" && workflows !== "write")
|
|
231
|
+
throw invalidGitResponse();
|
|
232
|
+
return {
|
|
233
|
+
issues: access("issues"),
|
|
234
|
+
contents: access("contents"),
|
|
235
|
+
pull_requests: access("pull_requests"),
|
|
236
|
+
workflows,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
112
239
|
function invalidMetadataResponse() {
|
|
113
240
|
return new TeamClawsError("invalid_response", "TeamClaws returned invalid server metadata.", { exitCode: 9 });
|
|
114
241
|
}
|
package/dist/constants.js
CHANGED
package/dist/errors.js
CHANGED
|
@@ -3,6 +3,7 @@ export class TeamClawsError extends Error {
|
|
|
3
3
|
retryable;
|
|
4
4
|
retryAfterSeconds;
|
|
5
5
|
exitCode;
|
|
6
|
+
connectUrl;
|
|
6
7
|
constructor(code, message, details = {}) {
|
|
7
8
|
super(message);
|
|
8
9
|
this.name = "TeamClawsError";
|
|
@@ -10,6 +11,7 @@ export class TeamClawsError extends Error {
|
|
|
10
11
|
this.retryable = details.retryable ?? false;
|
|
11
12
|
this.retryAfterSeconds = details.retryAfterSeconds;
|
|
12
13
|
this.exitCode = details.exitCode ?? 1;
|
|
14
|
+
this.connectUrl = details.connectUrl;
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
export function safeError(error) {
|
package/dist/output.js
CHANGED
|
@@ -413,6 +413,50 @@ export class Output {
|
|
|
413
413
|
if (!this.json)
|
|
414
414
|
this.stderr.write(`Error: ${detail}\n`);
|
|
415
415
|
}
|
|
416
|
+
gitRepositories(result) {
|
|
417
|
+
this.event({
|
|
418
|
+
schema_version: OUTPUT_SCHEMA_VERSION,
|
|
419
|
+
event: "git_repositories",
|
|
420
|
+
...result,
|
|
421
|
+
});
|
|
422
|
+
if (this.json)
|
|
423
|
+
return;
|
|
424
|
+
if (!result.repositories.length) {
|
|
425
|
+
this.stdout.write(`You don't have any repositories connected. Go to ${result.connect_url} to add them.\n`);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
for (const repo of result.repositories)
|
|
429
|
+
this.stdout.write(`${repo.repository_id} ${repo.full_name}\n`);
|
|
430
|
+
this.stdout.write(`Missing a repository? Go to ${result.connect_url} to add or enable it.\n`);
|
|
431
|
+
}
|
|
432
|
+
gitAssignments(result) {
|
|
433
|
+
this.event({
|
|
434
|
+
schema_version: OUTPUT_SCHEMA_VERSION,
|
|
435
|
+
event: "git_assignments",
|
|
436
|
+
...result,
|
|
437
|
+
});
|
|
438
|
+
if (this.json)
|
|
439
|
+
return;
|
|
440
|
+
if (!result.repositories.length)
|
|
441
|
+
this.stdout.write(`No repositories assigned to ${result.server_id}.\n`);
|
|
442
|
+
for (const repo of result.repositories)
|
|
443
|
+
this.stdout.write(`${repo.repository_id} ${repo.full_name} ${gitPermissionsText(repo.permissions)}\n`);
|
|
444
|
+
}
|
|
445
|
+
gitAssignmentResult(result) {
|
|
446
|
+
this.event({
|
|
447
|
+
schema_version: OUTPUT_SCHEMA_VERSION,
|
|
448
|
+
event: "git_assignment_result",
|
|
449
|
+
...result,
|
|
450
|
+
});
|
|
451
|
+
if (this.json)
|
|
452
|
+
return;
|
|
453
|
+
const messages = {
|
|
454
|
+
permissions_set: `Set permissions on ${result.server_id}: ${gitPermissionsText(result.permissions)}`,
|
|
455
|
+
removed: `Removed access from ${result.server_id}.`,
|
|
456
|
+
already_unassigned: `Already unassigned from ${result.server_id}.`,
|
|
457
|
+
};
|
|
458
|
+
this.stdout.write(`${result.full_name} (${result.repository_id}): ${messages[result.code]}\n`);
|
|
459
|
+
}
|
|
416
460
|
error(error) {
|
|
417
461
|
const event = {
|
|
418
462
|
schema_version: OUTPUT_SCHEMA_VERSION,
|
|
@@ -425,10 +469,15 @@ export class Output {
|
|
|
425
469
|
if (error.retryAfterSeconds !== undefined) {
|
|
426
470
|
event.retry_after_seconds = error.retryAfterSeconds;
|
|
427
471
|
}
|
|
472
|
+
if (error.connectUrl !== undefined)
|
|
473
|
+
event.connect_url = error.connectUrl;
|
|
428
474
|
if (this.json)
|
|
429
475
|
this.stdout.write(`${JSON.stringify(event)}\n`);
|
|
430
|
-
else
|
|
476
|
+
else {
|
|
431
477
|
this.stderr.write(`Error: ${error.message}\n`);
|
|
478
|
+
if (error.connectUrl !== undefined)
|
|
479
|
+
this.stderr.write(`Go to ${error.connectUrl} to add or enable the repository.\n`);
|
|
480
|
+
}
|
|
432
481
|
}
|
|
433
482
|
usersAddResult(result) {
|
|
434
483
|
this.event({
|
|
@@ -446,6 +495,17 @@ export class Output {
|
|
|
446
495
|
this.stdout.write(`${messages[result.code]}\n`);
|
|
447
496
|
}
|
|
448
497
|
}
|
|
498
|
+
usersRemoveResult(result) {
|
|
499
|
+
this.event({
|
|
500
|
+
schema_version: OUTPUT_SCHEMA_VERSION,
|
|
501
|
+
event: "users_remove_result",
|
|
502
|
+
...result,
|
|
503
|
+
});
|
|
504
|
+
if (!this.json)
|
|
505
|
+
this.stdout.write(result.code === "removed"
|
|
506
|
+
? "User removed from the workspace access group.\n"
|
|
507
|
+
: "Pending invitation revoked.\n");
|
|
508
|
+
}
|
|
449
509
|
usersListResult(result) {
|
|
450
510
|
this.event({
|
|
451
511
|
schema_version: OUTPUT_SCHEMA_VERSION,
|
|
@@ -477,3 +537,6 @@ export class Output {
|
|
|
477
537
|
});
|
|
478
538
|
}
|
|
479
539
|
}
|
|
540
|
+
function gitPermissionsText(permissions) {
|
|
541
|
+
return `issues=${permissions.issues} contents=${permissions.contents} pull-requests=${permissions.pull_requests} workflows=${permissions.workflows}`;
|
|
542
|
+
}
|
package/dist/users.js
CHANGED
|
@@ -165,3 +165,59 @@ export async function runUsersAdd(store, fetcher, target, email, role, sudoEnabl
|
|
|
165
165
|
: {}),
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
|
+
export async function runUsersRemove(store, fetcher, target, email, authorization, signal) {
|
|
169
|
+
const credential = await store.findWorkspace(target);
|
|
170
|
+
if (!credential)
|
|
171
|
+
throw new TeamClawsError("re_pair_required", "No saved pairing was found for this workspace. Pair it first.", { exitCode: 3 });
|
|
172
|
+
const messages = {
|
|
173
|
+
...failureMessages,
|
|
174
|
+
owner_required: "Only the current machine owner can remove users.",
|
|
175
|
+
forbidden: "The paired identity is not authorized to remove users.",
|
|
176
|
+
mfa_required: "The owner must meet the existing MFA policy before removing users.",
|
|
177
|
+
target_proof_expired: "The request proof expired before user removal.",
|
|
178
|
+
owner_removal_forbidden: "The machine owner cannot be removed.",
|
|
179
|
+
member_not_removable: "The access-group owner cannot be removed.",
|
|
180
|
+
membership_not_found: "No matching membership or pending invitation was found.",
|
|
181
|
+
access_group_missing: "This machine has no access group to remove users from.",
|
|
182
|
+
invalid_request: "The workspace rejected the remove-user request.",
|
|
183
|
+
outcome_unverified: "The removal outcome could not be verified. Check user and invitation status before retrying.",
|
|
184
|
+
};
|
|
185
|
+
let response;
|
|
186
|
+
try {
|
|
187
|
+
response = await requestTargetJson(fetcher, authorization, `${credential.origin}/teamclaws-admin/api/device-users/v1/remove/`, credential, { method: "POST", body: { email }, ...(signal ? { signal } : {}) });
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
if (error instanceof TeamClawsError &&
|
|
191
|
+
["network_error", "network_timeout"].includes(error.code))
|
|
192
|
+
throw new TeamClawsError("outcome_unverified", messages.outcome_unverified);
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
const body = response.body;
|
|
196
|
+
if (response.status !== 200 || (isObject(body) && body.ok === false)) {
|
|
197
|
+
const rawCode = isObject(body)
|
|
198
|
+
? (body.code ?? (isObject(body.error) ? body.error.code : body.error))
|
|
199
|
+
: undefined;
|
|
200
|
+
const code = typeof rawCode === "string" && Object.hasOwn(messages, rawCode)
|
|
201
|
+
? rawCode
|
|
202
|
+
: [404, 405].includes(response.status)
|
|
203
|
+
? "users_remove_unavailable"
|
|
204
|
+
: "outcome_unverified";
|
|
205
|
+
throw new TeamClawsError(code, messages[code] ?? "Direct user removal is unavailable on this workspace.", {
|
|
206
|
+
exitCode: response.status === 401 ? 3 : response.status === 429 ? 5 : 1,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (!isObject(body) ||
|
|
210
|
+
body.ok !== true ||
|
|
211
|
+
body.action !== "remove" ||
|
|
212
|
+
body.scope !== "access_group" ||
|
|
213
|
+
body.email !== email ||
|
|
214
|
+
!["removed", "revoked"].includes(String(body.code)))
|
|
215
|
+
throw new TeamClawsError("invalid_response", "The workspace returned an invalid remove-user result. Check user and invitation status before retrying.", { exitCode: 9 });
|
|
216
|
+
return {
|
|
217
|
+
ok: true,
|
|
218
|
+
code: body.code,
|
|
219
|
+
action: "remove",
|
|
220
|
+
scope: "access_group",
|
|
221
|
+
email,
|
|
222
|
+
};
|
|
223
|
+
}
|