@pnpm/registry-access.commands 1100.4.1 → 1100.5.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/CHANGELOG.md +18 -0
- package/lib/access.js +1 -33
- package/lib/common.d.ts +6 -0
- package/lib/common.js +37 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/team.d.ts +17 -0
- package/lib/team.js +341 -0
- package/package.json +15 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @pnpm/registry-access.commands
|
|
2
2
|
|
|
3
|
+
## 1100.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added the `team` command for managing organization teams and team memberships on the registry, with create, destroy, add, rm, and ls subcommands and support for --otp, --parseable, and --json flags.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies:
|
|
12
|
+
- @pnpm/cli.utils@1101.0.14
|
|
13
|
+
- @pnpm/config.pick-registry-for-package@1100.0.10
|
|
14
|
+
- @pnpm/config.reader@1101.12.0
|
|
15
|
+
- @pnpm/network.auth-header@1101.1.4
|
|
16
|
+
- @pnpm/network.fetch@1100.1.5
|
|
17
|
+
- @pnpm/registry-access.client@1100.1.7
|
|
18
|
+
- @pnpm/resolving.registry.types@1100.1.4
|
|
19
|
+
- @pnpm/types@1101.4.0
|
|
20
|
+
|
|
3
21
|
## 1100.4.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/lib/access.js
CHANGED
|
@@ -5,10 +5,9 @@ import { createGetAuthHeaderByURI } from '@pnpm/network.auth-header';
|
|
|
5
5
|
import { createFetchFromRegistry } from '@pnpm/network.fetch';
|
|
6
6
|
import npa from '@pnpm/npm-package-arg';
|
|
7
7
|
import { renderHelp } from 'render-help';
|
|
8
|
-
import { normalizeRegistryUrl, rcOptionsTypes } from './common.js';
|
|
8
|
+
import { normalizeRegistryUrl, rcOptionsTypes, readErrorBody } from './common.js';
|
|
9
9
|
export { rcOptionsTypes };
|
|
10
10
|
const DEFAULT_REGISTRY_URL = 'https://registry.npmjs.org/';
|
|
11
|
-
const ERROR_BODY_LIMIT = 64 * 1024;
|
|
12
11
|
function getRegistries(opts) {
|
|
13
12
|
return opts.registries ?? { default: DEFAULT_REGISTRY_URL };
|
|
14
13
|
}
|
|
@@ -452,37 +451,6 @@ async function throwRegistryError(response, action) {
|
|
|
452
451
|
}
|
|
453
452
|
throw new PnpmError('REGISTRY_ERROR', `Failed to ${action} package: ${response.status} ${response.statusText}. ${errorBody}`);
|
|
454
453
|
}
|
|
455
|
-
async function readErrorBody(response) {
|
|
456
|
-
const reader = response.body?.getReader();
|
|
457
|
-
if (reader == null)
|
|
458
|
-
return '';
|
|
459
|
-
const chunks = [];
|
|
460
|
-
let total = 0;
|
|
461
|
-
let truncated = false;
|
|
462
|
-
while (total < ERROR_BODY_LIMIT) {
|
|
463
|
-
// eslint-disable-next-line no-await-in-loop
|
|
464
|
-
const { done, value } = await reader.read();
|
|
465
|
-
if (done)
|
|
466
|
-
break;
|
|
467
|
-
const need = ERROR_BODY_LIMIT - total;
|
|
468
|
-
if (value.length > need) {
|
|
469
|
-
chunks.push(value.subarray(0, need));
|
|
470
|
-
truncated = true;
|
|
471
|
-
break;
|
|
472
|
-
}
|
|
473
|
-
chunks.push(value);
|
|
474
|
-
total += value.length;
|
|
475
|
-
}
|
|
476
|
-
reader.cancel().catch(() => { });
|
|
477
|
-
let body = new TextDecoder().decode(Buffer.concat(chunks));
|
|
478
|
-
if (truncated) {
|
|
479
|
-
if (body.length > 0 && !body.endsWith(' ')) {
|
|
480
|
-
body += ' ';
|
|
481
|
-
}
|
|
482
|
-
body += '(response body truncated)';
|
|
483
|
-
}
|
|
484
|
-
return body;
|
|
485
|
-
}
|
|
486
454
|
function sanitize(text) {
|
|
487
455
|
let result = '';
|
|
488
456
|
for (let i = 0; i < text.length; i++) {
|
package/lib/common.d.ts
CHANGED
|
@@ -5,3 +5,9 @@ export declare function parsePackageSpec(spec: string): {
|
|
|
5
5
|
versionRange: string | undefined;
|
|
6
6
|
};
|
|
7
7
|
export declare function normalizeRegistryUrl(registryUrl: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Reads at most ERROR_BODY_LIMIT bytes of the response body. Registry
|
|
10
|
+
* responses are untrusted, so the read is bounded before decoding rather
|
|
11
|
+
* than truncated after buffering the whole body.
|
|
12
|
+
*/
|
|
13
|
+
export declare function readErrorBody(response: Response): Promise<string>;
|
package/lib/common.js
CHANGED
|
@@ -24,4 +24,41 @@ export function parsePackageSpec(spec) {
|
|
|
24
24
|
export function normalizeRegistryUrl(registryUrl) {
|
|
25
25
|
return registryUrl.endsWith('/') ? registryUrl : `${registryUrl}/`;
|
|
26
26
|
}
|
|
27
|
+
const ERROR_BODY_LIMIT = 64 * 1024;
|
|
28
|
+
/**
|
|
29
|
+
* Reads at most ERROR_BODY_LIMIT bytes of the response body. Registry
|
|
30
|
+
* responses are untrusted, so the read is bounded before decoding rather
|
|
31
|
+
* than truncated after buffering the whole body.
|
|
32
|
+
*/
|
|
33
|
+
export async function readErrorBody(response) {
|
|
34
|
+
const reader = response.body?.getReader();
|
|
35
|
+
if (reader == null)
|
|
36
|
+
return '';
|
|
37
|
+
const chunks = [];
|
|
38
|
+
let total = 0;
|
|
39
|
+
let truncated = false;
|
|
40
|
+
while (total < ERROR_BODY_LIMIT) {
|
|
41
|
+
// eslint-disable-next-line no-await-in-loop
|
|
42
|
+
const { done, value } = await reader.read();
|
|
43
|
+
if (done)
|
|
44
|
+
break;
|
|
45
|
+
const need = ERROR_BODY_LIMIT - total;
|
|
46
|
+
if (value.length > need) {
|
|
47
|
+
chunks.push(value.subarray(0, need));
|
|
48
|
+
truncated = true;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
chunks.push(value);
|
|
52
|
+
total += value.length;
|
|
53
|
+
}
|
|
54
|
+
reader.cancel().catch(() => { });
|
|
55
|
+
let body = new TextDecoder().decode(Buffer.concat(chunks));
|
|
56
|
+
if (truncated) {
|
|
57
|
+
if (body.length > 0 && !body.endsWith(' ')) {
|
|
58
|
+
body += ' ';
|
|
59
|
+
}
|
|
60
|
+
body += '(response body truncated)';
|
|
61
|
+
}
|
|
62
|
+
return body;
|
|
63
|
+
}
|
|
27
64
|
//# sourceMappingURL=common.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import * as search from './search.js';
|
|
|
8
8
|
import * as star from './star/star.js';
|
|
9
9
|
import * as stars from './star/stars.js';
|
|
10
10
|
import * as unstar from './star/unstar.js';
|
|
11
|
+
import * as team from './team.js';
|
|
11
12
|
import * as unpublish from './unpublish.js';
|
|
12
13
|
import * as whoami from './whoami.js';
|
|
13
|
-
export { access, deprecate, distTag, owner, ping, search, star, stars, undeprecate, unpublish, unstar, whoami };
|
|
14
|
+
export { access, deprecate, distTag, owner, ping, search, star, stars, team, undeprecate, unpublish, unstar, whoami };
|
package/lib/index.js
CHANGED
|
@@ -8,7 +8,8 @@ import * as search from './search.js';
|
|
|
8
8
|
import * as star from './star/star.js';
|
|
9
9
|
import * as stars from './star/stars.js';
|
|
10
10
|
import * as unstar from './star/unstar.js';
|
|
11
|
+
import * as team from './team.js';
|
|
11
12
|
import * as unpublish from './unpublish.js';
|
|
12
13
|
import * as whoami from './whoami.js';
|
|
13
|
-
export { access, deprecate, distTag, owner, ping, search, star, stars, undeprecate, unpublish, unstar, whoami };
|
|
14
|
+
export { access, deprecate, distTag, owner, ping, search, star, stars, team, undeprecate, unpublish, unstar, whoami };
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/lib/team.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type CreateFetchFromRegistryOptions } from '@pnpm/network.fetch';
|
|
2
|
+
import type { Registries, RegistryConfig } from '@pnpm/types';
|
|
3
|
+
import { rcOptionsTypes } from './common.js';
|
|
4
|
+
export { rcOptionsTypes };
|
|
5
|
+
export declare function cliOptionsTypes(): Record<string, unknown>;
|
|
6
|
+
export declare const commandNames: string[];
|
|
7
|
+
export declare function help(): string;
|
|
8
|
+
export interface TeamOptions extends CreateFetchFromRegistryOptions {
|
|
9
|
+
cliOptions?: {
|
|
10
|
+
otp?: string;
|
|
11
|
+
parseable?: boolean;
|
|
12
|
+
json?: boolean;
|
|
13
|
+
};
|
|
14
|
+
configByUri?: Record<string, RegistryConfig>;
|
|
15
|
+
registries?: Registries;
|
|
16
|
+
}
|
|
17
|
+
export declare function handler(opts: TeamOptions, params: string[]): Promise<string>;
|
package/lib/team.js
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { docsUrl } from '@pnpm/cli.utils';
|
|
2
|
+
import { pickRegistryForPackage } from '@pnpm/config.pick-registry-for-package';
|
|
3
|
+
import { PnpmError } from '@pnpm/error';
|
|
4
|
+
import { createGetAuthHeaderByURI } from '@pnpm/network.auth-header';
|
|
5
|
+
import { createFetchFromRegistry } from '@pnpm/network.fetch';
|
|
6
|
+
import { renderHelp } from 'render-help';
|
|
7
|
+
import { normalizeRegistryUrl, rcOptionsTypes, readErrorBody } from './common.js';
|
|
8
|
+
export { rcOptionsTypes };
|
|
9
|
+
export function cliOptionsTypes() {
|
|
10
|
+
return {
|
|
11
|
+
...rcOptionsTypes(),
|
|
12
|
+
otp: String,
|
|
13
|
+
parseable: Boolean,
|
|
14
|
+
json: Boolean,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export const commandNames = ['team'];
|
|
18
|
+
export function help() {
|
|
19
|
+
return renderHelp({
|
|
20
|
+
description: 'Manage organization teams and team memberships.',
|
|
21
|
+
descriptionLists: [
|
|
22
|
+
{
|
|
23
|
+
title: 'Commands',
|
|
24
|
+
list: [
|
|
25
|
+
{
|
|
26
|
+
description: 'Create a new team in an organization.',
|
|
27
|
+
name: 'create',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
description: 'Destroy an existing team.',
|
|
31
|
+
name: 'destroy',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
description: 'Add a user to an existing team.',
|
|
35
|
+
name: 'add',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
description: 'Remove a user from an existing team.',
|
|
39
|
+
name: 'rm',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
description: 'List teams in an organization or users in a team.',
|
|
43
|
+
name: 'ls',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
title: 'Options',
|
|
49
|
+
list: [
|
|
50
|
+
{
|
|
51
|
+
description: 'The base URL of the npm registry.',
|
|
52
|
+
name: '--registry <url>',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
description: 'One-time password for registries that require two-factor authentication.',
|
|
56
|
+
name: '--otp',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
description: 'Output parseable results.',
|
|
60
|
+
name: '--parseable',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
description: 'Output results as JSON.',
|
|
64
|
+
name: '--json',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
url: docsUrl('team'),
|
|
70
|
+
usages: [
|
|
71
|
+
'pnpm team create <scope:team> [--otp <code>]',
|
|
72
|
+
'pnpm team destroy <scope:team> [--otp <code>]',
|
|
73
|
+
'pnpm team add <scope:team> <user> [--otp <code>]',
|
|
74
|
+
'pnpm team rm <scope:team> <user> [--otp <code>]',
|
|
75
|
+
'pnpm team ls <scope|scope:team>',
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
export async function handler(opts, params) {
|
|
80
|
+
switch (params[0]) {
|
|
81
|
+
case 'create':
|
|
82
|
+
return teamCreate(opts, params.slice(1));
|
|
83
|
+
case 'destroy':
|
|
84
|
+
return teamDestroy(opts, params.slice(1));
|
|
85
|
+
case 'add':
|
|
86
|
+
return teamAdd(opts, params.slice(1));
|
|
87
|
+
case 'rm':
|
|
88
|
+
return teamRm(opts, params.slice(1));
|
|
89
|
+
case 'ls':
|
|
90
|
+
case 'list':
|
|
91
|
+
return teamLs(opts, params.slice(1));
|
|
92
|
+
default:
|
|
93
|
+
// When no subcommand is given, assume the first arg is a scope:team
|
|
94
|
+
// and list members, or a scope and list teams. This matches npm behavior
|
|
95
|
+
// where `npm team ls` is the default.
|
|
96
|
+
if (params.length > 0 && (params[0].startsWith('@') || params[0].startsWith(':'))) {
|
|
97
|
+
return teamLs(opts, params);
|
|
98
|
+
}
|
|
99
|
+
throw new PnpmError('TEAM_SUBCOMMAND_REQUIRED', 'Subcommand is required (create, destroy, add, rm, ls). Use `pnpm team ls <scope>` to list teams.');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function teamCreate(opts, params) {
|
|
103
|
+
if (params.length === 0) {
|
|
104
|
+
throw new PnpmError('TEAM_CREATE_SCOPE_REQUIRED', 'Team scope is required (e.g., pnpm team create @org:newteam)');
|
|
105
|
+
}
|
|
106
|
+
const { scope, team } = parseScopeTeam(params[0]);
|
|
107
|
+
if (!team) {
|
|
108
|
+
throw new PnpmError('TEAM_CREATE_NAME_REQUIRED', 'Team name is required (e.g., pnpm team create @org:newteam)');
|
|
109
|
+
}
|
|
110
|
+
const { registryUrl, authHeader } = getRegistryAndAuthForOrg(opts, scope);
|
|
111
|
+
const fetchFromRegistry = createFetchFromRegistry(opts);
|
|
112
|
+
const otp = opts.cliOptions?.otp;
|
|
113
|
+
const teamUrl = getOrgTeamsUrl(registryUrl, scope);
|
|
114
|
+
const response = await fetchFromRegistry(teamUrl, {
|
|
115
|
+
authHeaderValue: authHeader,
|
|
116
|
+
method: 'PUT',
|
|
117
|
+
headers: {
|
|
118
|
+
'content-type': 'application/json',
|
|
119
|
+
...(otp ? { 'npm-otp': otp } : {}),
|
|
120
|
+
},
|
|
121
|
+
body: JSON.stringify({ name: team }),
|
|
122
|
+
});
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
await throwRegistryError(response, `create team "${scope}:${team}"`);
|
|
125
|
+
}
|
|
126
|
+
return `+${scope}:${team}`;
|
|
127
|
+
}
|
|
128
|
+
async function teamDestroy(opts, params) {
|
|
129
|
+
if (params.length === 0) {
|
|
130
|
+
throw new PnpmError('TEAM_DESTROY_SCOPE_REQUIRED', 'Team scope is required (e.g., pnpm team destroy @org:newteam)');
|
|
131
|
+
}
|
|
132
|
+
const { scope, team } = parseScopeTeam(params[0]);
|
|
133
|
+
if (!team) {
|
|
134
|
+
throw new PnpmError('TEAM_DESTROY_NAME_REQUIRED', 'Team name is required (e.g., pnpm team destroy @org:newteam)');
|
|
135
|
+
}
|
|
136
|
+
const { registryUrl, authHeader } = getRegistryAndAuthForOrg(opts, scope);
|
|
137
|
+
const fetchFromRegistry = createFetchFromRegistry(opts);
|
|
138
|
+
const otp = opts.cliOptions?.otp;
|
|
139
|
+
const teamUrl = getTeamUrl(registryUrl, scope, team);
|
|
140
|
+
const response = await fetchFromRegistry(teamUrl, {
|
|
141
|
+
authHeaderValue: authHeader,
|
|
142
|
+
method: 'DELETE',
|
|
143
|
+
headers: {
|
|
144
|
+
...(otp ? { 'npm-otp': otp } : {}),
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
if (!response.ok) {
|
|
148
|
+
await throwRegistryError(response, `destroy team "${scope}:${team}"`);
|
|
149
|
+
}
|
|
150
|
+
return `-${scope}:${team}`;
|
|
151
|
+
}
|
|
152
|
+
async function teamAdd(opts, params) {
|
|
153
|
+
if (params.length < 2) {
|
|
154
|
+
throw new PnpmError('TEAM_ADD_ARGS_REQUIRED', 'Team scope and user are required (e.g., pnpm team add @org:team username)');
|
|
155
|
+
}
|
|
156
|
+
const { scope, team } = parseScopeTeam(params[0]);
|
|
157
|
+
if (!team) {
|
|
158
|
+
throw new PnpmError('TEAM_ADD_NAME_REQUIRED', 'Team name is required (e.g., pnpm team add @org:team username)');
|
|
159
|
+
}
|
|
160
|
+
const username = params[1];
|
|
161
|
+
const { registryUrl, authHeader } = getRegistryAndAuthForOrg(opts, scope);
|
|
162
|
+
const fetchFromRegistry = createFetchFromRegistry(opts);
|
|
163
|
+
const otp = opts.cliOptions?.otp;
|
|
164
|
+
const membersUrl = getTeamMembersUrl(registryUrl, scope, team);
|
|
165
|
+
const response = await fetchFromRegistry(membersUrl, {
|
|
166
|
+
authHeaderValue: authHeader,
|
|
167
|
+
method: 'PUT',
|
|
168
|
+
headers: {
|
|
169
|
+
'content-type': 'application/json',
|
|
170
|
+
...(otp ? { 'npm-otp': otp } : {}),
|
|
171
|
+
},
|
|
172
|
+
body: JSON.stringify({ user: username }),
|
|
173
|
+
});
|
|
174
|
+
if (!response.ok) {
|
|
175
|
+
await throwRegistryError(response, `add user "${username}" to team "${scope}:${team}"`);
|
|
176
|
+
}
|
|
177
|
+
return `+${username} added to @${scope}:${team}`;
|
|
178
|
+
}
|
|
179
|
+
async function teamRm(opts, params) {
|
|
180
|
+
if (params.length < 2) {
|
|
181
|
+
throw new PnpmError('TEAM_RM_ARGS_REQUIRED', 'Team scope and user are required (e.g., pnpm team rm @org:team username)');
|
|
182
|
+
}
|
|
183
|
+
const { scope, team } = parseScopeTeam(params[0]);
|
|
184
|
+
if (!team) {
|
|
185
|
+
throw new PnpmError('TEAM_RM_NAME_REQUIRED', 'Team name is required (e.g., pnpm team rm @org:team username)');
|
|
186
|
+
}
|
|
187
|
+
const username = params[1];
|
|
188
|
+
const { registryUrl, authHeader } = getRegistryAndAuthForOrg(opts, scope);
|
|
189
|
+
const fetchFromRegistry = createFetchFromRegistry(opts);
|
|
190
|
+
const otp = opts.cliOptions?.otp;
|
|
191
|
+
const membersUrl = getTeamMembersUrl(registryUrl, scope, team);
|
|
192
|
+
const response = await fetchFromRegistry(membersUrl, {
|
|
193
|
+
authHeaderValue: authHeader,
|
|
194
|
+
method: 'DELETE',
|
|
195
|
+
headers: {
|
|
196
|
+
'content-type': 'application/json',
|
|
197
|
+
...(otp ? { 'npm-otp': otp } : {}),
|
|
198
|
+
},
|
|
199
|
+
body: JSON.stringify({ user: username }),
|
|
200
|
+
});
|
|
201
|
+
if (!response.ok) {
|
|
202
|
+
await throwRegistryError(response, `remove user "${username}" from team "${scope}:${team}"`);
|
|
203
|
+
}
|
|
204
|
+
return `-${username} removed from @${scope}:${team}`;
|
|
205
|
+
}
|
|
206
|
+
async function teamLs(opts, params) {
|
|
207
|
+
if (params.length === 0) {
|
|
208
|
+
throw new PnpmError('TEAM_LS_SCOPE_REQUIRED', 'Organization scope is required (e.g., pnpm team ls @org or pnpm team ls @org:team)');
|
|
209
|
+
}
|
|
210
|
+
const { scope, team } = parseScopeTeam(params[0]);
|
|
211
|
+
const { registryUrl, authHeader } = getRegistryAndAuthForOrg(opts, scope);
|
|
212
|
+
const fetchFromRegistry = createFetchFromRegistry(opts);
|
|
213
|
+
const parseable = opts.cliOptions?.parseable ?? false;
|
|
214
|
+
const json = opts.cliOptions?.json ?? false;
|
|
215
|
+
if (team) {
|
|
216
|
+
return teamListMembers({ scope, team, registryUrl, fetchFromRegistry, authHeader, parseable, json });
|
|
217
|
+
}
|
|
218
|
+
return teamListTeams({ scope, registryUrl, fetchFromRegistry, authHeader, parseable, json });
|
|
219
|
+
}
|
|
220
|
+
async function teamListTeams(options) {
|
|
221
|
+
const { scope, registryUrl, fetchFromRegistry, authHeader, parseable, json } = options;
|
|
222
|
+
const teamsUrl = getOrgTeamsUrl(registryUrl, scope);
|
|
223
|
+
const response = await fetchFromRegistry(teamsUrl, {
|
|
224
|
+
authHeaderValue: authHeader,
|
|
225
|
+
});
|
|
226
|
+
if (!response.ok) {
|
|
227
|
+
if (response.status === 404) {
|
|
228
|
+
throw new PnpmError('ORG_NOT_FOUND', `Organization "@${scope}" not found in registry`);
|
|
229
|
+
}
|
|
230
|
+
await throwRegistryError(response, `fetch teams for "@${scope}"`);
|
|
231
|
+
}
|
|
232
|
+
const teams = await response.json();
|
|
233
|
+
if (json) {
|
|
234
|
+
return JSON.stringify(teams.map(t => t.name), null, 2);
|
|
235
|
+
}
|
|
236
|
+
if (parseable) {
|
|
237
|
+
return teams.map(t => t.name).join('\n');
|
|
238
|
+
}
|
|
239
|
+
if (teams.length === 0) {
|
|
240
|
+
return `@${scope} has no teams`;
|
|
241
|
+
}
|
|
242
|
+
const lines = [`@${scope} has the following teams:`];
|
|
243
|
+
for (const { name } of teams) {
|
|
244
|
+
lines.push(` @${scope}:${name}`);
|
|
245
|
+
}
|
|
246
|
+
return lines.join('\n');
|
|
247
|
+
}
|
|
248
|
+
async function teamListMembers(options) {
|
|
249
|
+
const { scope, team, registryUrl, fetchFromRegistry, authHeader, parseable, json } = options;
|
|
250
|
+
const membersUrl = getTeamMembersUrl(registryUrl, scope, team);
|
|
251
|
+
const response = await fetchFromRegistry(membersUrl, {
|
|
252
|
+
authHeaderValue: authHeader,
|
|
253
|
+
});
|
|
254
|
+
if (!response.ok) {
|
|
255
|
+
if (response.status === 404) {
|
|
256
|
+
throw new PnpmError('TEAM_NOT_FOUND', `Team "@${scope}:${team}" not found in registry`);
|
|
257
|
+
}
|
|
258
|
+
await throwRegistryError(response, `fetch team members for "@${scope}:${team}"`);
|
|
259
|
+
}
|
|
260
|
+
const members = await response.json();
|
|
261
|
+
if (json) {
|
|
262
|
+
return JSON.stringify(members.map(m => m.name), null, 2);
|
|
263
|
+
}
|
|
264
|
+
if (parseable) {
|
|
265
|
+
return members.map(m => m.name).join('\n');
|
|
266
|
+
}
|
|
267
|
+
if (members.length === 0) {
|
|
268
|
+
return `@${scope}:${team} has no members`;
|
|
269
|
+
}
|
|
270
|
+
const lines = [`@${scope}:${team} has the following members:`];
|
|
271
|
+
for (const { name } of members) {
|
|
272
|
+
lines.push(` ${name}`);
|
|
273
|
+
}
|
|
274
|
+
return lines.join('\n');
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Parse a scope:team string. Returns the scope (without @) and optional team name.
|
|
278
|
+
* Format: @scope or @scope:team
|
|
279
|
+
*/
|
|
280
|
+
function parseScopeTeam(spec) {
|
|
281
|
+
if (!spec.startsWith('@')) {
|
|
282
|
+
throw new PnpmError('TEAM_INVALID_SCOPE', `Team spec must start with @scope, got "${spec}". Use @scope or @scope:team format.`);
|
|
283
|
+
}
|
|
284
|
+
const inner = spec.slice(1);
|
|
285
|
+
if (!inner) {
|
|
286
|
+
throw new PnpmError('TEAM_INVALID_SCOPE', `Team spec must start with @scope, got "${spec}". Use @scope or @scope:team format.`);
|
|
287
|
+
}
|
|
288
|
+
const colonIndex = inner.indexOf(':');
|
|
289
|
+
if (colonIndex === -1) {
|
|
290
|
+
return { scope: inner };
|
|
291
|
+
}
|
|
292
|
+
const scope = inner.slice(0, colonIndex);
|
|
293
|
+
const team = inner.slice(colonIndex + 1);
|
|
294
|
+
if (!scope || !team) {
|
|
295
|
+
throw new PnpmError('TEAM_INVALID_SCOPE', `Team spec must start with @scope, got "${spec}". Use @scope or @scope:team format.`);
|
|
296
|
+
}
|
|
297
|
+
return { scope, team };
|
|
298
|
+
}
|
|
299
|
+
function getRegistryAndAuthForOrg(opts, scope) {
|
|
300
|
+
const pkgName = `@${scope}/__pnpm_team__`;
|
|
301
|
+
const registryUrl = pickRegistryForPackage(opts.registries ?? { default: 'https://registry.npmjs.org/' }, pkgName);
|
|
302
|
+
const authHeader = getAuthHeaderForRegistry(opts.configByUri, registryUrl, pkgName);
|
|
303
|
+
return { registryUrl, authHeader };
|
|
304
|
+
}
|
|
305
|
+
function getAuthHeaderForRegistry(configByUri, registryUrl, packageName) {
|
|
306
|
+
const getAuthHeader = createGetAuthHeaderByURI(configByUri ?? {});
|
|
307
|
+
return getAuthHeader(registryUrl, { pkgName: packageName });
|
|
308
|
+
}
|
|
309
|
+
function getOrgTeamsUrl(registryUrl, scope) {
|
|
310
|
+
return new URL(`-/org/${encodeURIComponent(scope)}/team`, normalizeRegistryUrl(registryUrl)).href;
|
|
311
|
+
}
|
|
312
|
+
function getTeamUrl(registryUrl, scope, team) {
|
|
313
|
+
return new URL(`-/team/${encodeURIComponent(scope)}/${encodeURIComponent(team)}`, normalizeRegistryUrl(registryUrl)).href;
|
|
314
|
+
}
|
|
315
|
+
function getTeamMembersUrl(registryUrl, scope, team) {
|
|
316
|
+
return new URL(`-/team/${encodeURIComponent(scope)}/${encodeURIComponent(team)}/user`, normalizeRegistryUrl(registryUrl)).href;
|
|
317
|
+
}
|
|
318
|
+
async function throwRegistryError(response, action) {
|
|
319
|
+
const errorBody = await readErrorBody(response);
|
|
320
|
+
const safeErrorBody = [...errorBody]
|
|
321
|
+
.filter(c => {
|
|
322
|
+
const code = c.charCodeAt(0);
|
|
323
|
+
return code > 0x1f && (code < 0x7f || code > 0x9f);
|
|
324
|
+
})
|
|
325
|
+
.join('')
|
|
326
|
+
.slice(0, 500);
|
|
327
|
+
if (response.status === 401) {
|
|
328
|
+
throw new PnpmError('UNAUTHORIZED', `You must be logged in to ${action}. ${safeErrorBody}`);
|
|
329
|
+
}
|
|
330
|
+
if (response.status === 403) {
|
|
331
|
+
throw new PnpmError('FORBIDDEN', `You do not have permission to ${action}. ${safeErrorBody}`);
|
|
332
|
+
}
|
|
333
|
+
if (response.status === 404) {
|
|
334
|
+
throw new PnpmError('NOT_FOUND', `Organization or team not found. ${safeErrorBody}`);
|
|
335
|
+
}
|
|
336
|
+
if (response.status === 409) {
|
|
337
|
+
throw new PnpmError('TEAM_CONFLICT', `Team operation failed due to conflict. ${safeErrorBody}`);
|
|
338
|
+
}
|
|
339
|
+
throw new PnpmError('REGISTRY_ERROR', `Failed to ${action}: ${response.status} ${response.statusText}. ${safeErrorBody}`);
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=team.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/registry-access.commands",
|
|
3
|
-
"version": "1100.
|
|
3
|
+
"version": "1100.5.0",
|
|
4
4
|
"description": "Commands for managing packages on the registry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -28,17 +28,17 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@inquirer/prompts": "^8.4.3",
|
|
31
|
-
"@pnpm/cli.utils": "1101.0.
|
|
32
|
-
"@pnpm/config.pick-registry-for-package": "1100.0.
|
|
33
|
-
"@pnpm/config.reader": "1101.
|
|
31
|
+
"@pnpm/cli.utils": "1101.0.14",
|
|
32
|
+
"@pnpm/config.pick-registry-for-package": "1100.0.10",
|
|
33
|
+
"@pnpm/config.reader": "1101.12.0",
|
|
34
34
|
"@pnpm/error": "1100.0.1",
|
|
35
|
-
"@pnpm/network.auth-header": "1101.1.
|
|
36
|
-
"@pnpm/network.fetch": "1100.1.
|
|
35
|
+
"@pnpm/network.auth-header": "1101.1.4",
|
|
36
|
+
"@pnpm/network.fetch": "1100.1.5",
|
|
37
37
|
"@pnpm/network.web-auth": "1101.2.0",
|
|
38
38
|
"@pnpm/npm-package-arg": "^2.0.0",
|
|
39
|
-
"@pnpm/registry-access.client": "1100.1.
|
|
40
|
-
"@pnpm/resolving.registry.types": "1100.1.
|
|
41
|
-
"@pnpm/types": "1101.
|
|
39
|
+
"@pnpm/registry-access.client": "1100.1.7",
|
|
40
|
+
"@pnpm/resolving.registry.types": "1100.1.4",
|
|
41
|
+
"@pnpm/types": "1101.4.0",
|
|
42
42
|
"chalk": "^5.6.2",
|
|
43
43
|
"ramda": "npm:@pnpm/ramda@0.28.1",
|
|
44
44
|
"render-help": "^2.0.0",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@jest/globals": "30.4.1",
|
|
52
52
|
"@pnpm/logger": "1100.0.0",
|
|
53
|
-
"@pnpm/prepare": "1100.0.
|
|
54
|
-
"@pnpm/registry-access.commands": "1100.
|
|
55
|
-
"@pnpm/releasing.commands": "1100.
|
|
56
|
-
"@pnpm/testing.command-defaults": "1100.0.
|
|
57
|
-
"@pnpm/testing.mock-agent": "1101.0.
|
|
58
|
-
"@pnpm/testing.registry-mock": "1100.0.
|
|
53
|
+
"@pnpm/prepare": "1100.0.19",
|
|
54
|
+
"@pnpm/registry-access.commands": "1100.5.0",
|
|
55
|
+
"@pnpm/releasing.commands": "1100.6.0",
|
|
56
|
+
"@pnpm/testing.command-defaults": "1100.0.9",
|
|
57
|
+
"@pnpm/testing.mock-agent": "1101.0.5",
|
|
58
|
+
"@pnpm/testing.registry-mock": "1100.0.9",
|
|
59
59
|
"@types/ramda": "0.31.1",
|
|
60
60
|
"@types/semver": "7.7.1",
|
|
61
61
|
"execa": "npm:safe-execa@0.3.0"
|