@pnpm/registry-access.client 1100.0.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
4
+ Copyright (c) 2016-2026 Zoltan Kochan and other contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,42 @@
1
+ export interface AddUserResponse {
2
+ ok: boolean;
3
+ status: number;
4
+ text: () => Promise<string>;
5
+ json: () => Promise<unknown>;
6
+ headers: {
7
+ get: (name: string) => string | null;
8
+ };
9
+ }
10
+ export interface AddUserFetch {
11
+ (url: string, init: {
12
+ method: 'PUT';
13
+ headers: Record<string, string>;
14
+ body: string;
15
+ }): Promise<AddUserResponse>;
16
+ }
17
+ export interface AddUserOptions {
18
+ username: string;
19
+ password: string;
20
+ email: string;
21
+ registryUrl: string;
22
+ fetch: AddUserFetch;
23
+ otp?: string;
24
+ }
25
+ export interface AddUserResult {
26
+ token: string;
27
+ }
28
+ export declare class AddUserHttpError extends Error {
29
+ readonly status: number;
30
+ readonly responseText: string;
31
+ readonly responseJson: unknown | undefined;
32
+ readonly responseHeaders: {
33
+ get: (name: string) => string | null;
34
+ };
35
+ constructor(status: number, responseText: string, responseHeaders: {
36
+ get: (name: string) => string | null;
37
+ });
38
+ }
39
+ export declare class AddUserNoTokenError extends Error {
40
+ constructor();
41
+ }
42
+ export declare function addUser(opts: AddUserOptions): Promise<AddUserResult>;
package/lib/addUser.js ADDED
@@ -0,0 +1,54 @@
1
+ export class AddUserHttpError extends Error {
2
+ status;
3
+ responseText;
4
+ responseJson;
5
+ responseHeaders;
6
+ constructor(status, responseText, responseHeaders) {
7
+ super(`addUser failed (HTTP ${status}): ${responseText}`);
8
+ this.name = 'AddUserHttpError';
9
+ this.status = status;
10
+ this.responseText = responseText;
11
+ this.responseHeaders = responseHeaders;
12
+ try {
13
+ this.responseJson = JSON.parse(responseText);
14
+ }
15
+ catch {
16
+ this.responseJson = undefined;
17
+ }
18
+ }
19
+ }
20
+ export class AddUserNoTokenError extends Error {
21
+ constructor() {
22
+ super('The registry returned a successful response but no token');
23
+ this.name = 'AddUserNoTokenError';
24
+ }
25
+ }
26
+ export async function addUser(opts) {
27
+ const url = new URL(`-/user/org.couchdb.user:${encodeURIComponent(opts.username)}`, opts.registryUrl).href;
28
+ const response = await opts.fetch(url, {
29
+ method: 'PUT',
30
+ headers: {
31
+ 'content-type': 'application/json',
32
+ accept: 'application/json',
33
+ 'npm-auth-type': 'web',
34
+ ...(opts.otp != null ? { 'npm-otp': opts.otp } : {}),
35
+ },
36
+ body: JSON.stringify({
37
+ _id: `org.couchdb.user:${opts.username}`,
38
+ name: opts.username,
39
+ password: opts.password,
40
+ email: opts.email,
41
+ type: 'user',
42
+ }),
43
+ });
44
+ if (!response.ok) {
45
+ const text = await response.text();
46
+ throw new AddUserHttpError(response.status, text, response.headers);
47
+ }
48
+ const body = await response.json();
49
+ if (!body?.token) {
50
+ throw new AddUserNoTokenError();
51
+ }
52
+ return { token: body.token };
53
+ }
54
+ //# sourceMappingURL=addUser.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './addUser.js';
2
+ export * from './setDistTag.js';
package/lib/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './addUser.js';
2
+ export * from './setDistTag.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,11 @@
1
+ import type { FetchFromRegistry } from '@pnpm/network.fetch';
2
+ export interface SetDistTagOptions {
3
+ packageName: string;
4
+ version: string;
5
+ distTag: string;
6
+ registryUrl: string;
7
+ fetchFromRegistry: FetchFromRegistry;
8
+ authHeader?: string;
9
+ otp?: string;
10
+ }
11
+ export declare function setDistTag(opts: SetDistTagOptions): Promise<void>;
@@ -0,0 +1,27 @@
1
+ import { PnpmError } from '@pnpm/error';
2
+ import npa from '@pnpm/npm-package-arg';
3
+ export async function setDistTag(opts) {
4
+ const encodedName = npa(opts.packageName).escapedName;
5
+ const url = new URL(`-/package/${encodedName}/dist-tags/${encodeURIComponent(opts.distTag)}`, opts.registryUrl).href;
6
+ const response = await opts.fetchFromRegistry(url, {
7
+ authHeaderValue: opts.authHeader,
8
+ method: 'PUT',
9
+ headers: {
10
+ 'content-type': 'application/json',
11
+ ...(opts.otp ? { 'npm-otp': opts.otp } : {}),
12
+ },
13
+ body: JSON.stringify(opts.version),
14
+ });
15
+ if (response.ok)
16
+ return;
17
+ const body = await response.text();
18
+ const action = `set dist-tag "${opts.distTag}" on`;
19
+ if (response.status === 401) {
20
+ throw new PnpmError('UNAUTHORIZED', `You must be logged in to ${action} packages. ${body}`);
21
+ }
22
+ if (response.status === 403) {
23
+ throw new PnpmError('FORBIDDEN', `You do not have permission to ${action} this package. ${body}`);
24
+ }
25
+ throw new PnpmError('REGISTRY_ERROR', `Failed to ${action} package: ${response.status} ${response.statusText}. ${body}`);
26
+ }
27
+ //# sourceMappingURL=setDistTag.js.map
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@pnpm/registry-access.client",
3
+ "version": "1100.0.1",
4
+ "description": "Low-level helpers for npm-registry HTTP endpoints (PUT dist-tag, PUT user, etc.)",
5
+ "keywords": [
6
+ "pnpm",
7
+ "pnpm11"
8
+ ],
9
+ "license": "MIT",
10
+ "funding": "https://opencollective.com/pnpm",
11
+ "repository": "https://github.com/pnpm/pnpm/tree/main/registry-access/client",
12
+ "homepage": "https://github.com/pnpm/pnpm/tree/main/registry-access/client#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/pnpm/pnpm/issues"
15
+ },
16
+ "type": "module",
17
+ "main": "lib/index.js",
18
+ "types": "lib/index.d.ts",
19
+ "exports": {
20
+ ".": "./lib/index.js"
21
+ },
22
+ "files": [
23
+ "lib",
24
+ "!*.map"
25
+ ],
26
+ "dependencies": {
27
+ "@pnpm/npm-package-arg": "^2.0.0",
28
+ "@pnpm/network.fetch": "1100.0.7",
29
+ "@pnpm/error": "1100.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "@pnpm/registry-access.client": "1100.0.1"
33
+ },
34
+ "engines": {
35
+ "node": ">=22.13"
36
+ },
37
+ "jest": {
38
+ "preset": "@pnpm/jest-config"
39
+ },
40
+ "scripts": {
41
+ "start": "tsgo --watch",
42
+ "lint": "eslint \"src/**/*.ts\"",
43
+ "compile": "tsgo --build && pn lint --fix",
44
+ "test": "pn compile"
45
+ }
46
+ }