@almyty/credentials 1.5.1 → 1.5.2
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 +5 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +56 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ Every read command takes `--json` and writes undecorated JSON to stdout.
|
|
|
43
43
|
|
|
44
44
|
| Command | What it does |
|
|
45
45
|
|---|---|
|
|
46
|
-
| `add <service> [--method m] [--owner org\|user\|private] [--name n] [--headless] [--open]` | Add a credential |
|
|
46
|
+
| `add <service> [--method m] [--owner org\|team\|user\|private] [--team id\|slug] [--name n] [--headless] [--open]` | Add a credential |
|
|
47
47
|
| `complete <key> --state s --code c` | Finish a headless sign-in by pasting the code |
|
|
48
48
|
| `validate <id>` | Re-check against the provider; refreshes health and the account label |
|
|
49
49
|
| `rotate <id> [--headless] [--open]` | Replace the secret in place, so everything using the credential keeps working |
|
|
@@ -106,6 +106,10 @@ narrows that to a principal.
|
|
|
106
106
|
`--owner org` (the default) makes the credential the organization's: this is
|
|
107
107
|
what agents and deployments use, and it needs `connections:manage` (admin or
|
|
108
108
|
owner). `--owner user` makes it yours, and you can grant it to others.
|
|
109
|
+
`--owner team --team <id|slug>` makes it the organization's for one team:
|
|
110
|
+
only that team's members (and admins) see or use it. The slug is the team's
|
|
111
|
+
name in lowercase with dashes (`Customer Support` is `customer-support`); a
|
|
112
|
+
member can pick only a team they are on.
|
|
109
113
|
`--owner private` makes it yours alone: nobody else sees or uses it, org admins
|
|
110
114
|
included, and it cannot be granted. Free and personal organizations allow
|
|
111
115
|
personal and private credentials by default; paid organizations start with them off until
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,23 @@ export declare function parseArgs(argv: string[]): ParsedArgs;
|
|
|
10
10
|
* which came back as an opaque 400. Say what is missing instead.
|
|
11
11
|
*/
|
|
12
12
|
export declare function needArg(positional: string[], index: number, name: string, usage: string): string;
|
|
13
|
-
export declare function connectBody(flags: ParsedArgs['flags'], input?: Record<string, unknown
|
|
13
|
+
export declare function connectBody(flags: ParsedArgs['flags'], input?: Record<string, unknown>, teamId?: string): Record<string, unknown>;
|
|
14
|
+
/** A team's name as a slug: "Customer Support" is customer-support. */
|
|
15
|
+
export declare function teamSlug(name: string): string;
|
|
16
|
+
/** Whether --team is an id already (sent as is; the API checks it). */
|
|
17
|
+
export declare function isTeamId(ref: string): boolean;
|
|
18
|
+
/** The team --team <slug> names, out of the organization's teams. */
|
|
19
|
+
export declare function pickTeam(teams: Array<{
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
}>, ref: string): string;
|
|
23
|
+
/** The organization a slug is looked up in: the one the key acts in, or the only one. */
|
|
24
|
+
export declare function organizationOf(profile: {
|
|
25
|
+
currentOrganizationId?: string;
|
|
26
|
+
organizations?: Array<{
|
|
27
|
+
id: string;
|
|
28
|
+
}>;
|
|
29
|
+
}): string;
|
|
14
30
|
export declare function grantBody(flags: ParsedArgs['flags']): Record<string, unknown>;
|
|
15
31
|
/** A JSON object, or a message naming which flag was wrong. */
|
|
16
32
|
export declare function parseInputObject(raw: string, flag: string): Record<string, unknown>;
|
package/dist/index.js
CHANGED
|
@@ -92,7 +92,7 @@ Read:
|
|
|
92
92
|
grants <id> Who may use this credential
|
|
93
93
|
|
|
94
94
|
Add:
|
|
95
|
-
add <service> [--method m] [--owner org|user|private] [--name n] [--headless] [--open]
|
|
95
|
+
add <service> [--method m] [--owner org|team|user|private] [--team id|slug] [--name n] [--headless] [--open]
|
|
96
96
|
A sign-in prints an authorize URL (--open launches a
|
|
97
97
|
browser, --headless asks the service for a code to paste).
|
|
98
98
|
A key form prompts for each field, secrets not echoed.
|
|
@@ -146,10 +146,18 @@ export function needArg(positional, index, name, usage) {
|
|
|
146
146
|
throw new UsageError(`${name} is required\n usage: almyty credentials ${usage}`);
|
|
147
147
|
return v;
|
|
148
148
|
}
|
|
149
|
-
export function connectBody(flags, input) {
|
|
149
|
+
export function connectBody(flags, input, teamId) {
|
|
150
150
|
const body = { owner: str(flags, 'owner') ?? 'org' };
|
|
151
|
-
if (!['org', 'user', 'private'].includes(body.owner))
|
|
152
|
-
throw new UsageError('--owner must be org, user or private');
|
|
151
|
+
if (!['org', 'team', 'user', 'private'].includes(body.owner))
|
|
152
|
+
throw new UsageError('--owner must be org, team, user or private');
|
|
153
|
+
if (body.owner === 'team') {
|
|
154
|
+
if (!teamId)
|
|
155
|
+
throw new UsageError('--owner team needs the team: --team <id|slug>');
|
|
156
|
+
body.teamId = teamId;
|
|
157
|
+
}
|
|
158
|
+
else if (str(flags, 'team')) {
|
|
159
|
+
throw new UsageError('--team goes with --owner team');
|
|
160
|
+
}
|
|
153
161
|
if (str(flags, 'method'))
|
|
154
162
|
body.method = str(flags, 'method');
|
|
155
163
|
if (str(flags, 'name'))
|
|
@@ -158,6 +166,35 @@ export function connectBody(flags, input) {
|
|
|
158
166
|
body.input = input;
|
|
159
167
|
return body;
|
|
160
168
|
}
|
|
169
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
170
|
+
/** A team's name as a slug: "Customer Support" is customer-support. */
|
|
171
|
+
export function teamSlug(name) {
|
|
172
|
+
return name.trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
173
|
+
}
|
|
174
|
+
/** Whether --team is an id already (sent as is; the API checks it). */
|
|
175
|
+
export function isTeamId(ref) {
|
|
176
|
+
return UUID.test(ref);
|
|
177
|
+
}
|
|
178
|
+
/** The team --team <slug> names, out of the organization's teams. */
|
|
179
|
+
export function pickTeam(teams, ref) {
|
|
180
|
+
const wanted = teamSlug(ref);
|
|
181
|
+
const matches = teams.filter((t) => teamSlug(t.name) === wanted);
|
|
182
|
+
if (matches.length === 1)
|
|
183
|
+
return matches[0].id;
|
|
184
|
+
if (matches.length > 1)
|
|
185
|
+
throw new UsageError(`more than one team is called ${ref}; pass its id with --team`);
|
|
186
|
+
const known = teams.map((t) => teamSlug(t.name)).join(', ') || 'none';
|
|
187
|
+
throw new UsageError(`no team ${ref} in this organization (teams: ${known})`);
|
|
188
|
+
}
|
|
189
|
+
/** The organization a slug is looked up in: the one the key acts in, or the only one. */
|
|
190
|
+
export function organizationOf(profile) {
|
|
191
|
+
if (profile.currentOrganizationId)
|
|
192
|
+
return profile.currentOrganizationId;
|
|
193
|
+
const orgs = profile.organizations ?? [];
|
|
194
|
+
if (orgs.length === 1)
|
|
195
|
+
return orgs[0].id;
|
|
196
|
+
throw new UsageError('this login reaches more than one organization; pass the team id with --team');
|
|
197
|
+
}
|
|
161
198
|
export function grantBody(flags) {
|
|
162
199
|
const principalType = need(flags, 'principal');
|
|
163
200
|
if (!['user', 'team', 'role', 'agent', 'workspace'].includes(principalType))
|
|
@@ -270,7 +307,7 @@ export function formatConnectionDetail(c) {
|
|
|
270
307
|
`${c.name ?? c.connectorKey}`,
|
|
271
308
|
` id ${c.id}`,
|
|
272
309
|
` service ${c.connectorKey}${c.connectorDisplayName ? ` (${c.connectorDisplayName})` : ''}${c.kind ? ` [${c.kind}]` : ''}`,
|
|
273
|
-
` owner ${c.owner}${c.ownerUserId ? ` (${c.ownerUserId})` : ''}`,
|
|
310
|
+
` owner ${c.owner}${c.owner === 'team' && c.teamId ? ` (${c.teamId})` : c.ownerUserId ? ` (${c.ownerUserId})` : ''}`,
|
|
274
311
|
` method ${c.method ?? 'unknown'}`,
|
|
275
312
|
` account ${c.accountLabel ?? '(the provider named none)'}`,
|
|
276
313
|
` health ${c.health?.status ?? 'unknown'}${c.health?.checkedAt ? `, checked ${c.health.checkedAt}` : ', never checked'}`,
|
|
@@ -481,7 +518,20 @@ async function main() {
|
|
|
481
518
|
requireTty(`connect ${key} via ${method.type}`);
|
|
482
519
|
input = await promptForSchema(method.schema);
|
|
483
520
|
}
|
|
484
|
-
const
|
|
521
|
+
const teamRef = str(args.flags, 'team');
|
|
522
|
+
let teamId;
|
|
523
|
+
if (teamRef && str(args.flags, 'owner') === 'team') {
|
|
524
|
+
if (isTeamId(teamRef)) {
|
|
525
|
+
teamId = teamRef;
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
const profile = await q('/auth/profile');
|
|
529
|
+
const orgId = organizationOf(profile.data ?? {});
|
|
530
|
+
const teams = await q(`/organizations/${orgId}/teams`);
|
|
531
|
+
teamId = pickTeam(teams.data ?? [], teamRef);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
const body = connectBody({ ...args.flags, method: method.type }, input, teamId);
|
|
485
535
|
if (isRedirect)
|
|
486
536
|
body.mode = connectMode(args.flags);
|
|
487
537
|
const res = await post(`/credentials/connect/${key}`, body);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@almyty/credentials",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"author": "almyty",
|
|
29
29
|
"license": "Apache-2.0",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@almyty/client": "^1.5.
|
|
31
|
+
"@almyty/client": "^1.5.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "^25.4.0",
|