@pnpm/registry-access.client 1100.0.1 → 1100.1.1
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/lib/setDistTag.d.ts +7 -0
- package/lib/setDistTag.js +25 -2
- package/package.json +9 -5
package/lib/setDistTag.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FetchFromRegistry } from '@pnpm/network.fetch';
|
|
2
|
+
export type AuthType = 'web' | 'legacy';
|
|
2
3
|
export interface SetDistTagOptions {
|
|
3
4
|
packageName: string;
|
|
4
5
|
version: string;
|
|
@@ -6,6 +7,12 @@ export interface SetDistTagOptions {
|
|
|
6
7
|
registryUrl: string;
|
|
7
8
|
fetchFromRegistry: FetchFromRegistry;
|
|
8
9
|
authHeader?: string;
|
|
10
|
+
/** Mirrors npm CLI's `auth-type` flat option: `'web'` (default) opts into the
|
|
11
|
+
* web-OTP challenge, `'legacy'` is set automatically when the user passes
|
|
12
|
+
* `--otp` so a classic 6-digit code can be sent. */
|
|
13
|
+
authType?: AuthType;
|
|
14
|
+
/** OTP token to send as `npm-otp`. May be a classic 6-digit code (legacy) or
|
|
15
|
+
* the 64-character token returned by the web flow. */
|
|
9
16
|
otp?: string;
|
|
10
17
|
}
|
|
11
18
|
export declare function setDistTag(opts: SetDistTagOptions): Promise<void>;
|
package/lib/setDistTag.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PnpmError } from '@pnpm/error';
|
|
2
|
+
import { SyntheticOtpError } from '@pnpm/network.web-auth';
|
|
2
3
|
import npa from '@pnpm/npm-package-arg';
|
|
3
4
|
export async function setDistTag(opts) {
|
|
4
5
|
const encodedName = npa(opts.packageName).escapedName;
|
|
@@ -8,6 +9,7 @@ export async function setDistTag(opts) {
|
|
|
8
9
|
method: 'PUT',
|
|
9
10
|
headers: {
|
|
10
11
|
'content-type': 'application/json',
|
|
12
|
+
'npm-auth-type': opts.authType ?? 'web',
|
|
11
13
|
...(opts.otp ? { 'npm-otp': opts.otp } : {}),
|
|
12
14
|
},
|
|
13
15
|
body: JSON.stringify(opts.version),
|
|
@@ -15,13 +17,34 @@ export async function setDistTag(opts) {
|
|
|
15
17
|
if (response.ok)
|
|
16
18
|
return;
|
|
17
19
|
const body = await response.text();
|
|
18
|
-
const action = `set dist-tag "${opts.distTag}" on`;
|
|
19
20
|
if (response.status === 401) {
|
|
20
|
-
throw
|
|
21
|
+
throw parseAuthError(body, opts.distTag);
|
|
21
22
|
}
|
|
23
|
+
const action = `set dist-tag "${opts.distTag}" on`;
|
|
22
24
|
if (response.status === 403) {
|
|
23
25
|
throw new PnpmError('FORBIDDEN', `You do not have permission to ${action} this package. ${body}`);
|
|
24
26
|
}
|
|
25
27
|
throw new PnpmError('REGISTRY_ERROR', `Failed to ${action} package: ${response.status} ${response.statusText}. ${body}`);
|
|
26
28
|
}
|
|
29
|
+
function parseAuthError(body, distTag) {
|
|
30
|
+
const parsed = tryParseJson(body);
|
|
31
|
+
if (parsed != null && typeof parsed === 'object' && 'authUrl' in parsed && 'doneUrl' in parsed) {
|
|
32
|
+
return new SyntheticOtpError({
|
|
33
|
+
authUrl: typeof parsed.authUrl === 'string' ? parsed.authUrl : undefined,
|
|
34
|
+
doneUrl: typeof parsed.doneUrl === 'string' ? parsed.doneUrl : undefined,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (/one-time pass/i.test(body)) {
|
|
38
|
+
return new SyntheticOtpError(undefined);
|
|
39
|
+
}
|
|
40
|
+
return new PnpmError('UNAUTHORIZED', `You must be logged in to set dist-tag "${distTag}" on packages. ${body}`);
|
|
41
|
+
}
|
|
42
|
+
function tryParseJson(body) {
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(body);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
27
50
|
//# sourceMappingURL=setDistTag.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/registry-access.client",
|
|
3
|
-
"version": "1100.
|
|
3
|
+
"version": "1100.1.1",
|
|
4
4
|
"description": "Low-level helpers for npm-registry HTTP endpoints (PUT dist-tag, PUT user, etc.)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"funding": "https://opencollective.com/pnpm",
|
|
11
|
-
"repository":
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/pnpm/pnpm/tree/main/registry-access/client"
|
|
14
|
+
},
|
|
12
15
|
"homepage": "https://github.com/pnpm/pnpm/tree/main/registry-access/client#readme",
|
|
13
16
|
"bugs": {
|
|
14
17
|
"url": "https://github.com/pnpm/pnpm/issues"
|
|
@@ -25,11 +28,12 @@
|
|
|
25
28
|
],
|
|
26
29
|
"dependencies": {
|
|
27
30
|
"@pnpm/npm-package-arg": "^2.0.0",
|
|
28
|
-
"@pnpm/
|
|
29
|
-
"@pnpm/
|
|
31
|
+
"@pnpm/error": "1100.0.0",
|
|
32
|
+
"@pnpm/network.fetch": "1100.1.0",
|
|
33
|
+
"@pnpm/network.web-auth": "1101.1.0"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
|
-
"@pnpm/registry-access.client": "1100.
|
|
36
|
+
"@pnpm/registry-access.client": "1100.1.1"
|
|
33
37
|
},
|
|
34
38
|
"engines": {
|
|
35
39
|
"node": ">=22.13"
|